From 2b4b1cc157bc4950afc70df566b6f70c4f7dce4f Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Thu, 4 Jun 2009 23:25:39 +0000 Subject: [PATCH 0001/1160] Added support for template double brackets for C++0x. Added test cases. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11245 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 2 + .../test-suite/template_double_brackets.i | 26 +++++ .../template_double_brackets_broke.i | 26 +++++ Source/Swig/scanner.c | 94 ++++++++++++++++++- 4 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 Examples/test-suite/template_double_brackets.i create mode 100644 Examples/test-suite/template_double_brackets_broke.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 5c6a332a4..d2a06c94a 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -82,6 +82,7 @@ CPP_TEST_BROKEN += \ nested_struct \ overload_complicated \ template_default_pointer \ + template_double_brackets_broke \ template_expr @@ -311,6 +312,7 @@ CPP_TEST_CASES += \ template_default_inherit \ template_default_qualify \ template_default_vw \ + template_double_brackets \ template_enum \ template_enum_ns_inherit \ template_enum_typedef \ diff --git a/Examples/test-suite/template_double_brackets.i b/Examples/test-suite/template_double_brackets.i new file mode 100644 index 000000000..3a8ccd47f --- /dev/null +++ b/Examples/test-suite/template_double_brackets.i @@ -0,0 +1,26 @@ +%module foo +#include +std::map> m; +std::map > n; +std::map< std::map<(6>>1), double>, double> o; +//std::map< std::map<6>>1, double>, double> p; // fails as it should + +class ABC { +public: + int a; + int operator>>(ABC &); + int operator<<(ABC &); +}; + +template +class ABC2 { +public: + int a; + + template + int operator>>(ABC &, U); + + template + int operator<<(ABC &, U); +}; + diff --git a/Examples/test-suite/template_double_brackets_broke.i b/Examples/test-suite/template_double_brackets_broke.i new file mode 100644 index 000000000..987f9d269 --- /dev/null +++ b/Examples/test-suite/template_double_brackets_broke.i @@ -0,0 +1,26 @@ +%module foo +#include +std::map> m; +std::map > n; +std::map< std::map<(6>>1), double>, double> o; +std::map< std::map<6>>1, double>, double> p; // fails as it should + +class ABC { +public: + int a; + int operator>>(ABC &); + int operator<<(ABC &); +}; + +template +class ABC2 { +public: + int a; + + template + int operator>>(ABC &, U); + + template + int operator<<(ABC &, U); +}; + diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index 53f1ad4a0..f5b0d5155 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -31,8 +31,12 @@ struct Scanner { String *error; /* Last error message (if any) */ int error_line; /* Error line number */ int freeze_line; /* Suspend line number updates */ + List *brackets; /* Current level of < > brackets on each level */ }; +void Scanner_push_brackets(Scanner*); +void Scanner_clear_brackets(Scanner*); + /* ----------------------------------------------------------------------------- * NewScanner() * @@ -53,6 +57,8 @@ Scanner *NewScanner(void) { s->str = 0; s->error = 0; s->freeze_line = 0; + s->brackets = NewList(); + Scanner_push_brackets(s); return s; } @@ -65,6 +71,7 @@ Scanner *NewScanner(void) { void DelScanner(Scanner * s) { assert(s); Delete(s->scanobjs); + Delete(s->brackets); Delete(s->text); Delete(s->file); Delete(s->error); @@ -84,6 +91,7 @@ void Scanner_clear(Scanner * s) { Delete(s->str); Clear(s->text); Clear(s->scanobjs); + Scanner_clear_brackets(s); Delete(s->error); s->error = 0; s->line = 1; @@ -245,6 +253,74 @@ Scanner_freeze_line(Scanner *s, int val) { s->freeze_line = val; } +/* ----------------------------------------------------------------------------- + * Scanner_brackets() + * + * Returns the number of brackets at the current depth. + * ----------------------------------------------------------------------------- */ +int* +Scanner_brackets(Scanner *s) { + return (int*)(**((void***)Getitem(s->brackets, 0))); /* TODO: Use VoidObj*->ptr instead of void** */ +} + +/* ----------------------------------------------------------------------------- + * Scanner_clear_brackets() + * + * Resets the current depth and clears all brackets. + * Usually called at the end of statements; + * ----------------------------------------------------------------------------- */ +void +Scanner_clear_brackets(Scanner *s) { + Clear(s->brackets); + Scanner_push_brackets(s); /* base bracket count should always be created */ +} + +/* ----------------------------------------------------------------------------- + * Scanner_inc_brackets() + * + * Increases the number of brackets at the current depth. + * Usually called when '<' was found. + * ----------------------------------------------------------------------------- */ +void +Scanner_inc_brackets(Scanner *s) { + (*Scanner_brackets(s))++; +} + +/* ----------------------------------------------------------------------------- + * Scanner_dec_brackets() + * + * Decreases the number of brackets at the current depth. + * Usually called when '>' was found. + * ----------------------------------------------------------------------------- */ +void +Scanner_dec_brackets(Scanner *s) { + (*Scanner_brackets(s))--; +} + +/* ----------------------------------------------------------------------------- + * Scanner_push_brackets() + * + * Increases the depth of brackets. + * Usually called when '(' was found. + * ----------------------------------------------------------------------------- */ +void +Scanner_push_brackets(Scanner *s) { + int *newInt = malloc(sizeof(int)); + *newInt = 0; + Push(s->brackets, NewVoid(newInt, free)); +} + +/* ----------------------------------------------------------------------------- + * Scanner_pop_brackets() + * + * Decreases the depth of brackets. + * Usually called when ')' was found. + * ----------------------------------------------------------------------------- */ +void +Scanner_pop_brackets(Scanner *s) { + Delitem(s->brackets, 0); +} + /* ----------------------------------------------------------------------------- * retract() * @@ -432,12 +508,18 @@ static int look(Scanner * s) { /* Look for single character symbols */ - else if (c == '(') + else if (c == '(') { + Scanner_push_brackets(s); return SWIG_TOKEN_LPAREN; - else if (c == ')') + } + else if (c == ')') { + Scanner_pop_brackets(s); return SWIG_TOKEN_RPAREN; - else if (c == ';') + } + else if (c == ';') { + Scanner_clear_brackets(s); return SWIG_TOKEN_SEMI; + } else if (c == ',') return SWIG_TOKEN_COMMA; else if (c == '*') @@ -704,6 +786,7 @@ static int look(Scanner * s) { break; case 60: /* shift operators */ + Scanner_inc_brackets(s); if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LESSTHAN; if (c == '<') @@ -716,9 +799,10 @@ static int look(Scanner * s) { } break; case 61: + Scanner_dec_brackets(s); if ((c = nextchar(s)) == 0) return SWIG_TOKEN_GREATERTHAN; - if (c == '>') + if (c == '>' && ((*Scanner_brackets(s))<0)) /* go to double >> only, if no template < has been used */ state = 250; else if (c == '=') return SWIG_TOKEN_GTEQUAL; @@ -1024,6 +1108,7 @@ static int look(Scanner * s) { break; case 240: /* LSHIFT, LSEQUAL */ + Scanner_inc_brackets(s); if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LSHIFT; else if (c == '=') @@ -1035,6 +1120,7 @@ static int look(Scanner * s) { break; case 250: /* RSHIFT, RSEQUAL */ + Scanner_dec_brackets(s); if ((c = nextchar(s)) == 0) return SWIG_TOKEN_RSHIFT; else if (c == '=') From 1af6d8a1b00fb05091ac0ffe0b2f4e30fc656cd8 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Sat, 6 Jun 2009 16:25:24 +0000 Subject: [PATCH 0002/1160] Renamed template_double_brackets -> cpp0x_template_double_brackets. Added CPP0X_TEST_CASES and CPP0X_TEST_BROKEN in common.mk. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11248 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 16 ++++++++++++---- ...ackets.i => cpp0x_template_double_brackets.i} | 0 ...i => cpp0x_template_double_brackets_broken.i} | 0 3 files changed, 12 insertions(+), 4 deletions(-) rename Examples/test-suite/{template_double_brackets.i => cpp0x_template_double_brackets.i} (100%) rename Examples/test-suite/{template_double_brackets_broke.i => cpp0x_template_double_brackets_broken.i} (100%) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index d2a06c94a..8615a47c3 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -82,8 +82,8 @@ CPP_TEST_BROKEN += \ nested_struct \ overload_complicated \ template_default_pointer \ - template_double_brackets_broke \ - template_expr + template_expr \ + $(CPP0X_TEST_BROKEN) # Broken C test cases. (Can be run individually using make testcase.ctest.) @@ -312,7 +312,6 @@ CPP_TEST_CASES += \ template_default_inherit \ template_default_qualify \ template_default_vw \ - template_double_brackets \ template_enum \ template_enum_ns_inherit \ template_enum_typedef \ @@ -396,7 +395,16 @@ CPP_TEST_CASES += \ virtual_destructor \ virtual_poly \ voidtest \ - wrapmacro + wrapmacro \ + $(CPP0X_TEST_CASES) + +# C++0x test cases. +CPP0X_TEST_CASES = \ + cpp0x_template_double_brackets + +# Broken C++0x test cases. +CPP0X_TEST_BROKEN = \ + cpp0x_template_double_brackets_broken # # Put all the heavy STD/STL cases here, where they can be skipped if needed diff --git a/Examples/test-suite/template_double_brackets.i b/Examples/test-suite/cpp0x_template_double_brackets.i similarity index 100% rename from Examples/test-suite/template_double_brackets.i rename to Examples/test-suite/cpp0x_template_double_brackets.i diff --git a/Examples/test-suite/template_double_brackets_broke.i b/Examples/test-suite/cpp0x_template_double_brackets_broken.i similarity index 100% rename from Examples/test-suite/template_double_brackets_broke.i rename to Examples/test-suite/cpp0x_template_double_brackets_broken.i From 5fd3ccae1857546886673cec36bd61bd8c2eaa3f Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Fri, 26 Jun 2009 20:24:22 +0000 Subject: [PATCH 0003/1160] Introduced new CXXFLAGS symbol for the compilation of test suite. Added -std=c++0x to g++ compiler to enable compilation of the new C++0x tests. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11321 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/Makefile.in | 95 ++++++++++++++++++++++---------------------- configure.in | 7 ++++ 2 files changed, 55 insertions(+), 47 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index d6dbfdeeb..37a02c59f 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -25,6 +25,7 @@ TARGET = CC = @CC@ CXX = @CXX@ CFLAGS = @PLATFLAGS@ +CXXFLAGS = @PLATCXXFLAGS@ prefix = @prefix@ exec_prefix= @exec_prefix@ SRCS = @@ -113,7 +114,7 @@ tclsh: $(SRCS) tclsh_cpp: $(SRCS) $(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) -ltclsh.i $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE) \ + $(CXX) $(CXXFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE) \ $(TCL_LIB) $(TCL_OPTS) $(LIBS) $(SYSLIBS) -o $(TARGET) # ----------------------------------------------------------- @@ -128,7 +129,7 @@ wish: $(SRCS) wish_cpp: $(SRCS) $(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) -lwish.i $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE) \ + $(CXX) $(CXXFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE) \ $(XINCLUDE) $(TCL_LIB) $(TK_OPTS) $(XLIB) $(LIBS) $(SYSLIBS) -o $(TARGET) # ----------------------------------------------------------- @@ -146,8 +147,8 @@ tcl: $(SRCS) tcl_cpp: $(SRCS) $(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE) - $(TCLCXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(TCL_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(TCL_SO) + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE) + $(TCLCXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(TCL_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(TCL_SO) # ----------------------------------------------------------------- # Cleaning the Tcl examples @@ -187,8 +188,8 @@ perl5: $(SRCS) perl5_cpp: $(SRCS) $(SWIG) -perl5 -c++ $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PERL5_CCFLAGS) -I$(PERL5_INCLUDE) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(PERL5_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PERL5_CCFLAGS) -I$(PERL5_INCLUDE) + $(CXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(PERL5_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) # ---------------------------------------------------------------- # Build a module from existing XS C source code. (ie. from xsubpp). @@ -209,7 +210,7 @@ perl5_static: $(SRCS) perl5_static_cpp: $(SRCS) $(SWIG) -perl5 -c++ -static -lperlmain.i $(SWIGOPT) $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET) + $(CXX) $(CXXFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET) # ----------------------------------------------------------------- # Cleaning the Perl5 examples @@ -267,8 +268,8 @@ python: $(SRCS) python_cpp: $(SRCS) $(SWIGPYTHON) -c++ $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(PYTHON_INCLUDE) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(PYTHON_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)_$(TARGET)$(PYTHON_SO) + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(PYTHON_INCLUDE) + $(CXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(PYTHON_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)_$(TARGET)$(PYTHON_SO) # ----------------------------------------------------------------- # Build statically linked Python interpreter @@ -288,7 +289,7 @@ python_static: $(SRCS) python_static_cpp: $(SRCS) $(SWIGPYTHON) -c++ -lembed.i $(SWIGOPT) $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ + $(CXX) $(CXXFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ $(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET) # ----------------------------------------------------------------- @@ -339,7 +340,7 @@ OCTAVE_SO = @OCTAVE_SO@ octave: $(SRCS) $(SWIG) -octave $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -g -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(CXXSRCS) $(INCLUDES) -I$(OCTAVE_INCLUDE) + $(CXX) -g -c $(CCSHARED) $(CXXFLAGS) $(ICXXSRCS) $(CXXSRCS) $(INCLUDES) -I$(OCTAVE_INCLUDE) $(CC) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(INCLUDES) $(OCTAVE_INCLUDE) $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(OCTAVE_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(OCTAVE_SO) @@ -349,8 +350,8 @@ octave: $(SRCS) octave_cpp: $(SRCS) $(SWIG) -c++ -octave $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -g -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) -I$(OCTAVE_INCLUDE) - $(CXXSHARED) -g $(CFLAGS) $(OBJS) $(IOBJS) $(OCTAVE_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(OCTAVE_SO) + $(CXX) -g -c $(CCSHARED) $(CXXFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) -I$(OCTAVE_INCLUDE) + $(CXXSHARED) -g $(CXXFLAGS) $(OBJS) $(IOBJS) $(OCTAVE_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(OCTAVE_SO) # ----------------------------------------------------------------- # Cleaning the octave examples @@ -381,8 +382,8 @@ guile: $(SRCS) guile_cpp: $(SRCS) $(SWIG) -c++ -guile -scm -Linkage passive $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_INCLUDE) $(ICXXSRCS) $(SRCS) $(CXXSRCS) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(INCLUDES) $(GUILE_INCLUDE) $(ICXXSRCS) $(SRCS) $(CXXSRCS) + $(CXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) guile_externalhdr: $(SWIG) -guile -external-runtime $(TARGET) @@ -397,8 +398,8 @@ guile_gh: $(SRCS) guile_gh_cpp: $(SRCS) $(SWIG) -c++ -guile -gh -Linkage passive $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_INCLUDE) $(ICXXSRCS) $(SRCS) $(CXXSRCS) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(INCLUDES) $(GUILE_INCLUDE) $(ICXXSRCS) $(SRCS) $(CXXSRCS) + $(CXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) # ----------------------------------------------------------------- # Build a dynamically loadable module with passive linkage @@ -411,8 +412,8 @@ guile_passive: $(SRCS) guile_passive_cpp: $(SRCS) $(SWIG) -c++ -guile -Linkage passive $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_INCLUDE) $(ICXXSRCS) $(SRCS) $(CXXSRCS) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(INCLUDES) $(GUILE_INCLUDE) $(ICXXSRCS) $(SRCS) $(CXXSRCS) + $(CXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) # ----------------------------------------------------------------- # Build statically linked Guile interpreter @@ -428,7 +429,7 @@ guile_static: $(SRCS) guile_static_cpp: $(SRCS) $(SWIG) -c++ -guile -lguilemain.i -Linkage ltdlmod $(SWIGOPT) $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ + $(CXX) $(CXXFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ -DSWIGINIT="SCM scm_init_$(TARGET)_module(void); scm_init_$(TARGET)_module();" \ $(GUILE_INCLUDE) $(LIBS) -L$(GUILE_LIB) $(GUILE_LIBOPTS) -o $(TARGET)-guile @@ -439,7 +440,7 @@ guile_simple: $(SRCS) guile_simple_cpp: $(SRCS) $(SWIG) -c++ -guile -lguilemain.i -Linkage simple $(SWIGOPT) $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ + $(CXX) $(CXXFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ $(GUILE_INCLUDE) $(LIBS) -L$(GUILE_LIB) $(GUILE_LIBOPTS) -o $(TARGET)-guile # ----------------------------------------------------------------- @@ -483,8 +484,8 @@ java: $(SRCS) java_cpp: $(SRCS) $(SWIG) -java -c++ $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(JAVACFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(JAVA_INCLUDE) - $(JAVACXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JAVA_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(JAVA_LIBPREFIX)$(TARGET)$(JAVASO) + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(JAVACFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(JAVA_INCLUDE) + $(JAVACXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(JAVA_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(JAVA_LIBPREFIX)$(TARGET)$(JAVASO) # ----------------------------------------------------------------- # Cleaning the java examples @@ -542,7 +543,7 @@ mzscheme: $(SRCS) mzscheme_cpp: $(SRCS) $(SWIG) -mzscheme -c++ $(SWIGOPT) $(INTERFACEPATH) $(COMPILETOOL) $(MZC) `echo $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ICXXSRCS) $(SRCS) $(CXXSRCS) - $(CXXSHARED) $(CFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS) + $(CXXSHARED) $(CXXFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS) # ----------------------------------------------------------------- # Cleaning the mzscheme examples @@ -592,7 +593,7 @@ ocaml_dynamic: $(SRCS) $(OCAMLCORE) $(SWIG) -ocaml $(SWIGOPT) $(INTERFACEPATH) $(OCC) -g -c -ccopt -g -ccopt "$(INCLUDES)" $(ISRCS) $(SRCS) - $(CXXSHARED) $(CFLAGS) $(CCSHARED) $(CFLAGS) -o $(INTERFACE:%.i=%@SO@) \ + $(CXXSHARED) $(CXXFLAGS) $(CCSHARED) $(CFLAGS) -o $(INTERFACE:%.i=%@SO@) \ $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) $(LIBS) $(OCAMLDLGEN) $(INTERFACE:%.i=%.ml) $(INTERFACE:%.i=%@SO@) > \ $(INTERFACE:%.i=%_dynamic.ml) @@ -663,7 +664,7 @@ ocaml_dynamic_cpp: $(SRCS) cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c) $(OCC) -cc '$(CXX)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \ $(ICXXSRCS:%.cxx=%.c) $(SRCS) $(CXXSRCS) -ccopt -fPIC - $(CXXSHARED) $(CFLAGS) -o $(INTERFACE:%.i=%@SO@) \ + $(CXXSHARED) $(CXXFLAGS) -o $(INTERFACE:%.i=%@SO@) \ $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \ $(CPP_DLLIBS) $(LIBS) $(OCAMLDLGEN) $(INTERFACE:%.i=%.ml) $(INTERFACE:%.i=%@SO@) > \ @@ -710,8 +711,8 @@ ruby: $(SRCS) ruby_cpp: $(SRCS) $(SWIG) -c++ -ruby $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(RUBY_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(RUBY_INCLUDE) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(RUBY_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(RUBY_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(RUBY_INCLUDE) + $(CXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(RUBY_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) # ----------------------------------------------------------------- # Build statically linked Ruby interpreter @@ -729,7 +730,7 @@ ruby_static: $(SRCS) ruby_cpp_static: $(SRCS) $(SWIG) -c++ -ruby -lembed.i $(SWIGOPT) $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(RUBY_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ + $(CXX) $(CXXFLAGS) $(RUBY_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ $(RUBY_INCLUDE) $(LIBS) -L$(RUBY_LIB) $(RUBY_LIBOPTS) -o $(TARGET) @@ -764,8 +765,8 @@ php: $(SRCS) php_cpp: $(SRCS) $(SWIG) -php -cppext cxx -c++ $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PHP_INCLUDE) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO) + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PHP_INCLUDE) + $(CXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO) # ----------------------------------------------------------------- # Running a PHP example @@ -811,7 +812,7 @@ pike: $(SRCS) pike_cpp: $(SRCS) $(SWIG) -c++ -pike $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(PIKE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(PIKE_INCLUDE) + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(PIKE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(PIKE_INCLUDE) $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(PIKE_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) # ----------------------------------------------------------------- @@ -830,7 +831,7 @@ pike_static: $(SRCS) pike_cpp_static: $(SRCS) $(SWIG) -c++ -pike -lembed.i $(SWIGOPT) $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(PIKE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ + $(CXX) $(CXXFLAGS) $(PIKE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ $(PIKE_INCLUDE) $(LIBS) -L$(PIKE_LIB) $(PIKE_LIBOPTS) -o $(TARGET) # ----------------------------------------------------------------- @@ -885,9 +886,9 @@ chicken_direct_cpp: $(CXXSRCS) $(CHICKSRCS) $(CHICKEN) $(CHICKEN_GENERATED_SCHEME) $(CHICKENOPTS) \ -dynamic -feature chicken-compile-shared \ -output-file $(CHICKEN_COMPILED_SCHEME) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(CHICKEN_CFLAGS) \ + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(CHICKEN_CFLAGS) \ $(INCLUDES) $(CHICKEN_INCLUDE) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(CHICKEN_COMPILED_SCHEME) - $(CXXSHARED) $(CFLAGS) $(CHICKEN_COMPILED_OBJECT) $(OBJS) $(IOBJS) \ + $(CXXSHARED) $(CXXFLAGS) $(CHICKEN_COMPILED_OBJECT) $(OBJS) $(IOBJS) \ $(LIBS) $(CPP_DLLIBS) $(CHICKEN_SHAREDLIBOPTS) -o $(LIBPREFIX)$(TARGET)$(SO) # ----------------------------------------------------------------- @@ -913,7 +914,7 @@ chicken_static_cpp: $(CXXSRCS) $(CHICKSRCS) -output-file $(CHICKEN_COMPILED_SCHEME) $(CHICKEN) $(CHICKEN_MAIN) $(CHICKENOPTS) \ -output-file $(CHICKEN_MAIN:.scm=_chicken.c) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(CHICKEN_CFLAGS) \ + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(CHICKEN_CFLAGS) \ $(INCLUDES) $(CHICKEN_INCLUDE) $(ICXXSRCS) $(SRCS) $(CXXSRCS) \ $(CHICKEN_COMPILED_SCHEME) $(CHICKEN_COMPILED_MAIN) $(CXX) $(CHICKEN_COMPILED_OBJECT) $(CHICKEN_COMPILED_MAIN_OBJECT) \ @@ -966,8 +967,8 @@ csharp: $(SRCS) csharp_cpp: $(SRCS) $(SWIG) -csharp -c++ $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(CSHARPCFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(CSHARP_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(CSHARP_LIBPREFIX)$(TARGET)$(CSHARPSO) + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(CSHARPCFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) + $(CXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(CSHARP_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(CSHARP_LIBPREFIX)$(TARGET)$(CSHARPSO) # ---------------------------------------------------------------- # Compile CSharp files @@ -1015,8 +1016,8 @@ lua: $(SRCS) lua_cpp: $(SRCS) $(SWIG) -c++ -lua $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(LUA_INCLUDE) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(LUA_LIB) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(LUA_SO) + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(LUA_INCLUDE) + $(CXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(LUA_LIB) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(LUA_SO) # ----------------------------------------------------------------- # Build statically linked Lua interpreter @@ -1029,7 +1030,7 @@ lua_static: $(SRCS) lua_static_cpp: $(SRCS) $(SWIG) -c++ -lua -module example $(SWIGOPT) $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(LUA_INTERP) $(INCLUDES) \ + $(CXX) $(CXXFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(LUA_INTERP) $(INCLUDES) \ $(LUA_INCLUDE) $(LIBS) $(LUA_LIB) -o $(TARGET) # ----------------------------------------------------------------- @@ -1052,8 +1053,8 @@ allegrocl: $(SRCS) allegrocl_cpp: $(SRCS) $(SWIG) -c++ -allegrocl $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) + $(CXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) allegrocl_clean: rm -f *_wrap* *~ .~* @@ -1086,8 +1087,8 @@ cffi: $(SRCS) cffi_cpp: $(SRCS) $(SWIG) -c++ -cffi $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) + $(CXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) cffi_clean: rm -f *_wrap* *~ .~* @@ -1105,8 +1106,8 @@ uffi: $(SRCS) uffi_cpp: $(SRCS) $(SWIG) -c++ -uffi $(SWIGOPT) $(INTERFACEPATH) -# $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) -# $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +# $(CXX) -c $(CCSHARED) $(CXXFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) +# $(CXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) uffi_clean: rm -f *_wrap* *~ .~* diff --git a/configure.in b/configure.in index 4edc8e1ae..b64bc860a 100644 --- a/configure.in +++ b/configure.in @@ -321,6 +321,13 @@ case $host in *) PLATFLAGS="";; esac +# Add switch to enable C++0x support +AC_SUBST(PLATCXXFLAGS) +if test "$GCC" = yes; then + PLATCXXFLAGS=$PLATFLAGS" -std=c++0x " +else + PLATCXXFLAGS=$PLATFLAGS +fi # Check for specific libraries. Used for SWIG examples AC_CHECK_LIB(dl, dlopen) # Dynamic linking for SunOS/Solaris and SYSV From d8012716edf99362fd1d6abd5f8834aba7cdcd97 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Fri, 26 Jun 2009 21:48:48 +0000 Subject: [PATCH 0004/1160] Added constexpr keywords and CONSTEXPR terminal to Swig parser. Added cpp0x_constexpr.i testcase. Fixed compilation bug of cpp0x_template_double_brackets.i testcase. Removed obsolete cpp0x_template_double_brackets_broken. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11322 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 10 +++---- Examples/test-suite/cpp0x_constexpr.i | 8 ++++++ .../cpp0x_template_double_brackets.i | 10 +++---- .../cpp0x_template_double_brackets_broken.i | 26 ------------------- Source/CParse/cscanner.c | 2 ++ Source/CParse/parser.y | 3 ++- 6 files changed, 22 insertions(+), 37 deletions(-) create mode 100644 Examples/test-suite/cpp0x_constexpr.i delete mode 100644 Examples/test-suite/cpp0x_template_double_brackets_broken.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 8615a47c3..d7ef3e889 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -93,6 +93,7 @@ C_TEST_BROKEN += \ # C++ test cases. (Can be run individually using make testcase.cpptest.) CPP_TEST_CASES += \ + $(CPP0X_TEST_CASES) \ abstract_access \ abstract_inherit \ abstract_inherit_ok \ @@ -395,16 +396,15 @@ CPP_TEST_CASES += \ virtual_destructor \ virtual_poly \ voidtest \ - wrapmacro \ - $(CPP0X_TEST_CASES) + wrapmacro # C++0x test cases. CPP0X_TEST_CASES = \ cpp0x_template_double_brackets +# cpp0x_constexpr # not supported by any compilers yet # Broken C++0x test cases. -CPP0X_TEST_BROKEN = \ - cpp0x_template_double_brackets_broken +CPP0X_TEST_BROKEN = # # Put all the heavy STD/STL cases here, where they can be skipped if needed @@ -497,7 +497,7 @@ ALL_CLEAN = $(CPP_TEST_CASES:=.clean) \ ####################################################################### # The following applies for all module languages ####################################################################### -all: $(BROKEN_TEST_CASES) $(NOT_BROKEN_TEST_CASES) +all: $(NOT_BROKEN_TEST_CASES) $(BROKEN_TEST_CASES) check: $(NOT_BROKEN_TEST_CASES) diff --git a/Examples/test-suite/cpp0x_constexpr.i b/Examples/test-suite/cpp0x_constexpr.i new file mode 100644 index 000000000..6314d20c0 --- /dev/null +++ b/Examples/test-suite/cpp0x_constexpr.i @@ -0,0 +1,8 @@ +%module foo + +%inline %{ +class TestClass { + constexpr int func() { return 10; } +}; +%} + diff --git a/Examples/test-suite/cpp0x_template_double_brackets.i b/Examples/test-suite/cpp0x_template_double_brackets.i index 3a8ccd47f..1a12e0457 100644 --- a/Examples/test-suite/cpp0x_template_double_brackets.i +++ b/Examples/test-suite/cpp0x_template_double_brackets.i @@ -1,9 +1,8 @@ %module foo +%inline %{ #include std::map> m; -std::map > n; -std::map< std::map<(6>>1), double>, double> o; -//std::map< std::map<6>>1, double>, double> p; // fails as it should +std::map< int,std::map > n; class ABC { public: @@ -18,9 +17,10 @@ public: int a; template - int operator>>(ABC &, U); + U operator>>(ABC &); template - int operator<<(ABC &, U); + U operator<<(ABC &); }; +%} diff --git a/Examples/test-suite/cpp0x_template_double_brackets_broken.i b/Examples/test-suite/cpp0x_template_double_brackets_broken.i deleted file mode 100644 index 987f9d269..000000000 --- a/Examples/test-suite/cpp0x_template_double_brackets_broken.i +++ /dev/null @@ -1,26 +0,0 @@ -%module foo -#include -std::map> m; -std::map > n; -std::map< std::map<(6>>1), double>, double> o; -std::map< std::map<6>>1, double>, double> p; // fails as it should - -class ABC { -public: - int a; - int operator>>(ABC &); - int operator<<(ABC &); -}; - -template -class ABC2 { -public: - int a; - - template - int operator>>(ABC &, U); - - template - int operator<<(ABC &, U); -}; - diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index 8734c7d0e..a2a0631c1 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -630,6 +630,8 @@ int yylex(void) { return (PROTECTED); if (strcmp(yytext, "friend") == 0) return (FRIEND); + if (strcmp(yytext, "constexpr") == 0) + return (CONSTEXPR); if (strcmp(yytext, "virtual") == 0) return (VIRTUAL); if (strcmp(yytext, "operator") == 0) { diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 0babfbbb8..b4c2b4fb4 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1492,7 +1492,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %token ILLEGAL CONSTANT %token NAME RENAME NAMEWARN EXTEND PRAGMA FEATURE VARARGS %token ENUM -%token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT +%token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT CONSTEXPR %token USING %token NAMESPACE %token NATIVE INLINE @@ -4490,6 +4490,7 @@ storage_class : EXTERN { $$ = "extern"; } | VIRTUAL { $$ = "virtual"; } | FRIEND { $$ = "friend"; } | EXPLICIT { $$ = "explicit"; } + | CONSTEXPR { $$ = "constexpr"; } | empty { $$ = 0; } ; From 49467481641861e1bb4299f14c59c0720b04e868 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Fri, 26 Jun 2009 22:23:07 +0000 Subject: [PATCH 0005/1160] Added test case for explicit conversion operators. Some cosmetic fixes. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11323 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 +- Examples/test-suite/cpp0x_constexpr.i | 3 ++ .../cpp0x_explicit_conversion_operators.i | 28 +++++++++++++++++++ .../cpp0x_template_double_brackets.i | 4 +++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/cpp0x_explicit_conversion_operators.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index d7ef3e889..a95830f3f 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -400,7 +400,8 @@ CPP_TEST_CASES += \ # C++0x test cases. CPP0X_TEST_CASES = \ - cpp0x_template_double_brackets + cpp0x_template_double_brackets \ + cpp0x_explicit_conversion_operators # cpp0x_constexpr # not supported by any compilers yet # Broken C++0x test cases. diff --git a/Examples/test-suite/cpp0x_constexpr.i b/Examples/test-suite/cpp0x_constexpr.i index 6314d20c0..4345ec0af 100644 --- a/Examples/test-suite/cpp0x_constexpr.i +++ b/Examples/test-suite/cpp0x_constexpr.i @@ -1,3 +1,6 @@ +/* This interface tests whether Swig supports the new "constexpr" keyword + introduced by C++0x. +*/ %module foo %inline %{ diff --git a/Examples/test-suite/cpp0x_explicit_conversion_operators.i b/Examples/test-suite/cpp0x_explicit_conversion_operators.i new file mode 100644 index 000000000..ae97ec185 --- /dev/null +++ b/Examples/test-suite/cpp0x_explicit_conversion_operators.i @@ -0,0 +1,28 @@ +/* This interface checks whether Swig correctly compiles the new + explicit conversion operators feature introduced in C++0x. +*/ +%module foo + +%inline %{ + +class U { +public: + int u; +}; + +class V { +public: + int v; +}; + +class TestClass { +public: + //implicit converting constructor + TestClass( U const &val ) { t=val.u; } + // explicit constructor + explicit TestClass( V const &val ) { t=val.v; } + + int t; +}; +%} + diff --git a/Examples/test-suite/cpp0x_template_double_brackets.i b/Examples/test-suite/cpp0x_template_double_brackets.i index 1a12e0457..31c9c7248 100644 --- a/Examples/test-suite/cpp0x_template_double_brackets.i +++ b/Examples/test-suite/cpp0x_template_double_brackets.i @@ -1,3 +1,7 @@ +/* This interface checks whether Swig supports the new double angled brackets + in the template syntax without having a space inbetween. This feature was + introduced in new C++0x standard. +*/ %module foo %inline %{ #include From 0f2786aa540e509a5d74fc9be2f8ca297b6f501c Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Sun, 28 Jun 2009 14:51:10 +0000 Subject: [PATCH 0006/1160] Added support for unicode strings and fixed support for wstrings. Added test case cpp0x_raw_string_literals.i. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11327 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 +- .../test-suite/cpp0x_raw_string_literals.i | 30 ++++++++ Source/Swig/scanner.c | 73 +++++++++++++++---- 3 files changed, 92 insertions(+), 14 deletions(-) create mode 100644 Examples/test-suite/cpp0x_raw_string_literals.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index a95830f3f..fc00c1243 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -401,7 +401,8 @@ CPP_TEST_CASES += \ # C++0x test cases. CPP0X_TEST_CASES = \ cpp0x_template_double_brackets \ - cpp0x_explicit_conversion_operators + cpp0x_explicit_conversion_operators \ + cpp0x_raw_string_literals # cpp0x_constexpr # not supported by any compilers yet # Broken C++0x test cases. diff --git a/Examples/test-suite/cpp0x_raw_string_literals.i b/Examples/test-suite/cpp0x_raw_string_literals.i new file mode 100644 index 000000000..0b7ba244b --- /dev/null +++ b/Examples/test-suite/cpp0x_raw_string_literals.i @@ -0,0 +1,30 @@ +/* This module tests whether Swig correctly parses: + - ordinary strings (char_t) + - L wide strings (wchar_t) + - u8 unicode8 strings (char_t) + - u unicode16 strings (char16_t) + - U unicode32 strings (char32_t) + + This module also tests whether Swig correctly parses custom string delimiters. +*/ + +%module raw_string_literals + +%inline %{ +#include +#include + +using namespace std; + +string a="ABC"; +wstring wide=L"ABC"; +string c=u8"ABC"; +string b=u"ABC"; +string d=U"ABC"; + +/*string e=R"XXX[ABC"blah]XXX"; +string g=u8R"XXX[ABC"blah]XXX"; +string f=uR"XXX[ABC"blah]XXX"; +string h=UR"XXX[ABC"blah]XXX"; +*/ +%} diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index f5b0d5155..a4ac36ac4 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -32,6 +32,8 @@ struct Scanner { int error_line; /* Error line number */ int freeze_line; /* Suspend line number updates */ List *brackets; /* Current level of < > brackets on each level */ + int str_delimiter; /* Custom string delimiter: true, false */ + String *str_delimiter_val; /* Custom string delimiter. eg. R"XXX[my custom string "value"]XXX" */ }; void Scanner_push_brackets(Scanner*); @@ -58,6 +60,8 @@ Scanner *NewScanner(void) { s->error = 0; s->freeze_line = 0; s->brackets = NewList(); + s->str_delimiter = 0; + s->str_delimiter_val = NewStringEmpty(); Scanner_push_brackets(s); return s; } @@ -76,8 +80,9 @@ void DelScanner(Scanner * s) { Delete(s->file); Delete(s->error); Delete(s->str); + Delete(s->str_delimiter_val); free(s->idstart); - free(s); + free(s); } /* ----------------------------------------------------------------------------- @@ -93,6 +98,8 @@ void Scanner_clear(Scanner * s) { Clear(s->scanobjs); Scanner_clear_brackets(s); Delete(s->error); + Clear(s->str_delimiter_val); + s->str_delimiter = 0; s->error = 0; s->line = 1; s->nexttoken = -1; @@ -496,15 +503,16 @@ static int look(Scanner * s) { case 1000: if ((c = nextchar(s)) == 0) - return (0); + return (0); if (c == '%') state = 4; /* Possibly a SWIG directive */ - - /* Look for possible identifiers */ + + /* Look for possible identifiers or unicode strings */ else if ((isalpha(c)) || (c == '_') || - (s->idstart && strchr(s->idstart, c))) + (s->idstart && strchr(s->idstart, c))) { state = 7; + } /* Look for single character symbols */ @@ -569,16 +577,16 @@ static int look(Scanner * s) { state = 1; /* Comment (maybe) */ s->start_line = s->line; } - else if (c == '\"') { - state = 2; /* Possibly a string */ - s->start_line = s->line; - Clear(s->text); - } else if (c == ':') state = 5; /* maybe double colon */ else if (c == '0') state = 83; /* An octal or hex value */ + else if (c == '\"') { + state = 2; /* A string or Unicode string constant */ + s->start_line = s->line; + Clear(s->text); + } else if (c == '\'') { s->start_line = s->line; Clear(s->text); @@ -811,22 +819,61 @@ static int look(Scanner * s) { return SWIG_TOKEN_GREATERTHAN; } break; - case 7: /* Identifier */ + case 7: /* Identifier or unicode string */ + if (c!='u' && c!='U' && c!='L') { /* Definitely an identifier */ + state = 70; + break; + } + + if ((c = nextchar(s)) == 0) { + return SWIG_TOKEN_ID; + } + else if (c=='\"') { /* u or U string */ + retract(s, 1); + state = 1000; + } + else if (c=='8') { /* Possibly u8 string */ + state = 71; + break; + } + else { + retract(s, 1); /* Definitely an identifier */ + state = 70; + break; + } + break; + + case 70: /* Identifier */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_ID; if (isalnum(c) || (c == '_') || (c == '$')) { - state = 7; + state = 70; } else { retract(s, 1); return SWIG_TOKEN_ID; } break; + + case 71: /* Possibly u8 string */ + if ((c = nextchar(s)) == 0) { + return SWIG_TOKEN_ID; + } + if (c=='\"') { + retract(s, 1); + state = 1000; + } + else { + retract(s, 2); /* Definitely an identifier. Retract 8" */ + state = 70; + } + + break; case 75: /* Special identifier $ */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_DOLLAR; if (isalnum(c) || (c == '_') || (c == '*') || (c == '&')) { - state = 7; + state = 70; } else { retract(s,1); if (Len(s->text) == 1) return SWIG_TOKEN_DOLLAR; From ee8bebb668f780943d3a29fdd1219dc16971627c Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Sun, 28 Jun 2009 19:35:05 +0000 Subject: [PATCH 0007/1160] Added support for custom string delimiters. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11328 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/cpp0x_raw_string_literals.i | 32 +++-- Source/Swig/scanner.c | 125 ++++++++++++++---- 2 files changed, 122 insertions(+), 35 deletions(-) diff --git a/Examples/test-suite/cpp0x_raw_string_literals.i b/Examples/test-suite/cpp0x_raw_string_literals.i index 0b7ba244b..7e0814768 100644 --- a/Examples/test-suite/cpp0x_raw_string_literals.i +++ b/Examples/test-suite/cpp0x_raw_string_literals.i @@ -16,15 +16,27 @@ using namespace std; -string a="ABC"; -wstring wide=L"ABC"; -string c=u8"ABC"; -string b=u"ABC"; -string d=U"ABC"; +int L = 100; +int u8 = 100; +int u = 100; +int U = 100; + +int R = 100; +int LR = 100; +int u8R = 100; +int uR = 100; +int UR = 100; + +string a ="ABC"; +wstring wide =L"ABC"; +string b =u8"ABC"; +string c =u"ABC"; +string d =U"ABC"; + +string e =R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; +wstring wide2 =LR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; +string f =u8R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; +string g =uR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; +string h =UR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; -/*string e=R"XXX[ABC"blah]XXX"; -string g=u8R"XXX[ABC"blah]XXX"; -string f=uR"XXX[ABC"blah]XXX"; -string h=UR"XXX[ABC"blah]XXX"; -*/ %} diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index a4ac36ac4..5dc2a091b 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -32,8 +32,6 @@ struct Scanner { int error_line; /* Error line number */ int freeze_line; /* Suspend line number updates */ List *brackets; /* Current level of < > brackets on each level */ - int str_delimiter; /* Custom string delimiter: true, false */ - String *str_delimiter_val; /* Custom string delimiter. eg. R"XXX[my custom string "value"]XXX" */ }; void Scanner_push_brackets(Scanner*); @@ -60,8 +58,6 @@ Scanner *NewScanner(void) { s->error = 0; s->freeze_line = 0; s->brackets = NewList(); - s->str_delimiter = 0; - s->str_delimiter_val = NewStringEmpty(); Scanner_push_brackets(s); return s; } @@ -80,7 +76,6 @@ void DelScanner(Scanner * s) { Delete(s->file); Delete(s->error); Delete(s->str); - Delete(s->str_delimiter_val); free(s->idstart); free(s); } @@ -98,8 +93,6 @@ void Scanner_clear(Scanner * s) { Clear(s->scanobjs); Scanner_clear_brackets(s); Delete(s->error); - Clear(s->str_delimiter_val); - s->str_delimiter = 0; s->error = 0; s->line = 1; s->nexttoken = -1; @@ -475,13 +468,15 @@ static void get_escape(Scanner *s) { * ----------------------------------------------------------------------------- */ static int look(Scanner * s) { - int state; + int state = 0; int c = 0; + String *str_delimiter = 0; - state = 0; Clear(s->text); s->start_line = s->line; Setfile(s->text, Getfile(s->str)); + + while (1) { switch (state) { case 0: @@ -507,7 +502,7 @@ static int look(Scanner * s) { if (c == '%') state = 4; /* Possibly a SWIG directive */ - /* Look for possible identifiers or unicode strings */ + /* Look for possible identifiers or unicode/delimiter strings */ else if ((isalpha(c)) || (c == '_') || (s->idstart && strchr(s->idstart, c))) { @@ -583,7 +578,7 @@ static int look(Scanner * s) { else if (c == '0') state = 83; /* An octal or hex value */ else if (c == '\"') { - state = 2; /* A string or Unicode string constant */ + state = 2; /* A string constant */ s->start_line = s->line; Clear(s->text); } @@ -665,18 +660,63 @@ static int look(Scanner * s) { break; case 2: /* Processing a string */ + if (!str_delimiter) { + state=20; + break; + } + if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated string\n"); return SWIG_TOKEN_ERROR; } - if (c == '\"') { - Delitem(s->text, DOH_END); - return SWIG_TOKEN_STRING; - } else if (c == '\\') { - Delitem(s->text, DOH_END); - get_escape(s); - } else - state = 2; + else if (c == '[') { + state = 20; + } + else { + char temp[2] = { 0, 0 }; + temp[0] = c; + Append( str_delimiter, temp ); + } + + break; + + case 20: /* Inside the string */ + if ((c = nextchar(s)) == 0) { + Swig_error(cparse_file, cparse_start_line, "Unterminated string\n"); + return SWIG_TOKEN_ERROR; + } + + if (!str_delimiter) { /* Ordinary string: "value" */ + if (c == '\"') { + Delitem(s->text, DOH_END); + return SWIG_TOKEN_STRING; + } else if (c == '\\') { + Delitem(s->text, DOH_END); + get_escape(s); + } + } else { /* Custom delimiter string: R"XXXX[value]XXXX" */ + if (c==']') { + int i=0; + String *end_delimiter = NewStringEmpty(); + while ((c = nextchar(s)) != 0 && c!='\"') { + char temp[2] = { 0, 0 }; + temp[0] = c; + Append( end_delimiter, temp ); + i++; + } + + if (Strcmp( str_delimiter, end_delimiter )==0) { + Delete( end_delimiter ); /* Correct end delimiter ]XXXX" occured */ + Delete( str_delimiter ); + str_delimiter = 0; + return SWIG_TOKEN_STRING; + } else { /* Incorrect end delimiter occured */ + retract( s, i ); + Delete( end_delimiter ); + } + } + } + break; case 3: /* Maybe a not equals */ @@ -819,8 +859,13 @@ static int look(Scanner * s) { return SWIG_TOKEN_GREATERTHAN; } break; - case 7: /* Identifier or unicode string */ - if (c!='u' && c!='U' && c!='L') { /* Definitely an identifier */ + + case 7: /* Identifier or unicode/custom delimiter string */ + if (c=='R') { /* Possibly CUSTOM DELIMITER string */ + state = 72; + break; + } + else if (c!='u' && c!='U' && c!='L') { /* Definitely an identifier */ state = 70; break; } @@ -828,18 +873,19 @@ static int look(Scanner * s) { if ((c = nextchar(s)) == 0) { return SWIG_TOKEN_ID; } - else if (c=='\"') { /* u or U string */ + else if (c=='\"') { /* Definitely u, U or L string */ retract(s, 1); state = 1000; } + else if (c=='R') { /* Possibly CUSTOM DELIMITER u, U, L string */ + state = 73; + } else if (c=='8') { /* Possibly u8 string */ state = 71; - break; } else { retract(s, 1); /* Definitely an identifier */ state = 70; - break; } break; @@ -859,9 +905,12 @@ static int look(Scanner * s) { return SWIG_TOKEN_ID; } if (c=='\"') { - retract(s, 1); + retract(s, 1); /* Definitely u8 string */ state = 1000; } + else if (c=='R') { + state = 74; /* Possibly CUSTOM DELIMITER u8 string */ + } else { retract(s, 2); /* Definitely an identifier. Retract 8" */ state = 70; @@ -869,6 +918,32 @@ static int look(Scanner * s) { break; + case 72: /* Possibly CUSTOM DELIMITER string */ + case 73: + case 74: + if ((c = nextchar(s)) == 0) { + return SWIG_TOKEN_ID; + } + if (c=='\"') { + retract(s, 1); /* Definitely custom delimiter u, U or L string */ + str_delimiter = NewStringEmpty(); + state = 1000; + } + else { + if (state==72) { + retract(s, 1); /* Definitely an identifier. Retract ? */ + } + else if (state==73) { + retract(s, 2); /* Definitely an identifier. Retract R? */ + } + else if (state==74) { + retract(s, 3); /* Definitely an identifier. Retract 8R? */ + } + state = 70; + } + + break; + case 75: /* Special identifier $ */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_DOLLAR; From 72708ea1732df4b09adcb3151257c4f9eb31d503 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Sun, 5 Jul 2009 14:33:40 +0000 Subject: [PATCH 0008/1160] Added support for C++0x static_assert(). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11369 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 ++- Examples/test-suite/cpp0x_static_assert.i | 17 +++++++++++++++++ Source/CParse/cscanner.c | 2 ++ Source/CParse/parser.y | 14 +++++++++++++- 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/cpp0x_static_assert.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index fc00c1243..c0fdd0d96 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -402,7 +402,8 @@ CPP_TEST_CASES += \ CPP0X_TEST_CASES = \ cpp0x_template_double_brackets \ cpp0x_explicit_conversion_operators \ - cpp0x_raw_string_literals + cpp0x_raw_string_literals \ + cpp0x_static_assert # cpp0x_constexpr # not supported by any compilers yet # Broken C++0x test cases. diff --git a/Examples/test-suite/cpp0x_static_assert.i b/Examples/test-suite/cpp0x_static_assert.i new file mode 100644 index 000000000..112168f5e --- /dev/null +++ b/Examples/test-suite/cpp0x_static_assert.i @@ -0,0 +1,17 @@ +/* This test case checks whether swig correctly parses and ignores the + keywords "static_assert()" inside the class or struct. +*/ +%module static_assert + +%inline %{ +template +struct Check1 { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); +}; + +template +class Check2 { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); +}; +%} + diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index a2a0631c1..e4f16bf1c 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -634,6 +634,8 @@ int yylex(void) { return (CONSTEXPR); if (strcmp(yytext, "virtual") == 0) return (VIRTUAL); + if (strcmp(yytext, "static_assert") == 0) + return (STATIC_ASSERT); if (strcmp(yytext, "operator") == 0) { int nexttok; String *s = NewString("operator "); diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index b4c2b4fb4..47dc091f4 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1493,6 +1493,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %token NAME RENAME NAMEWARN EXTEND PRAGMA FEATURE VARARGS %token ENUM %token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT CONSTEXPR +%token STATIC_ASSERT %token USING %token NAMESPACE %token NATIVE INLINE @@ -1539,7 +1540,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { /* C++ declarations */ %type cpp_declaration cpp_class_decl cpp_forward_class_decl cpp_template_decl; %type cpp_members cpp_member; -%type cpp_constructor_decl cpp_destructor_decl cpp_protection_decl cpp_conversion_operator; +%type cpp_constructor_decl cpp_destructor_decl cpp_protection_decl cpp_conversion_operator cpp_static_assert; %type cpp_swig_directive cpp_temp_possible cpp_nested cpp_opt_declarators ; %type cpp_using_decl cpp_namespace_decl cpp_catch_decl ; %type kwargs options; @@ -3864,6 +3865,9 @@ cpp_temp_possible: c_decl { | cpp_constructor_decl { $$ = $1; } + | cpp_static_assert { + $$ = $1; + } | cpp_template_decl { $$ = 0; } @@ -4110,6 +4114,7 @@ cpp_member : c_declaration { $$ = $1; } default_arguments($$); } | cpp_destructor_decl { $$ = $1; } + | cpp_static_assert { $$ = $1; } | cpp_protection_decl { $$ = $1; } | cpp_swig_directive { $$ = $1; } | cpp_conversion_operator { $$ = $1; } @@ -4281,6 +4286,13 @@ cpp_catch_decl : CATCH LPAREN parms RPAREN LBRACE { } ; +/* static_assert(bool, const char*); */ +cpp_static_assert : STATIC_ASSERT LPAREN { + skip_balanced('(',')'); + $$ = 0; + } + ; + /* public: */ cpp_protection_decl : PUBLIC COLON { $$ = new_node("access"); From e1b5d43cd8e3cf899fa771333d337dff59d00a4f Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Sat, 11 Jul 2009 20:13:36 +0000 Subject: [PATCH 0009/1160] Added C++0x support for 'extern' explicit template instantiation without the translation unit. Added test cases. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11385 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 ++- Examples/test-suite/cpp0x_constexpr.i | 3 ++- Examples/test-suite/cpp0x_explicit_conversion_operators.i | 2 +- Examples/test-suite/cpp0x_raw_string_literals.i | 3 +-- Examples/test-suite/cpp0x_static_assert.i | 2 +- Examples/test-suite/cpp0x_template_double_brackets.i | 2 +- Source/CParse/parser.y | 8 ++++++-- 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index c0fdd0d96..bd5f7b983 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -403,7 +403,8 @@ CPP0X_TEST_CASES = \ cpp0x_template_double_brackets \ cpp0x_explicit_conversion_operators \ cpp0x_raw_string_literals \ - cpp0x_static_assert + cpp0x_static_assert \ + cpp0x_template_explicit # cpp0x_constexpr # not supported by any compilers yet # Broken C++0x test cases. diff --git a/Examples/test-suite/cpp0x_constexpr.i b/Examples/test-suite/cpp0x_constexpr.i index 4345ec0af..6cae41825 100644 --- a/Examples/test-suite/cpp0x_constexpr.i +++ b/Examples/test-suite/cpp0x_constexpr.i @@ -1,10 +1,11 @@ /* This interface tests whether Swig supports the new "constexpr" keyword introduced by C++0x. */ -%module foo +%module cpp0x_constexpr %inline %{ class TestClass { +public: constexpr int func() { return 10; } }; %} diff --git a/Examples/test-suite/cpp0x_explicit_conversion_operators.i b/Examples/test-suite/cpp0x_explicit_conversion_operators.i index ae97ec185..6532efb23 100644 --- a/Examples/test-suite/cpp0x_explicit_conversion_operators.i +++ b/Examples/test-suite/cpp0x_explicit_conversion_operators.i @@ -1,7 +1,7 @@ /* This interface checks whether Swig correctly compiles the new explicit conversion operators feature introduced in C++0x. */ -%module foo +%module cpp0x_explicit_conversion_operators %inline %{ diff --git a/Examples/test-suite/cpp0x_raw_string_literals.i b/Examples/test-suite/cpp0x_raw_string_literals.i index 7e0814768..4da565264 100644 --- a/Examples/test-suite/cpp0x_raw_string_literals.i +++ b/Examples/test-suite/cpp0x_raw_string_literals.i @@ -7,8 +7,7 @@ This module also tests whether Swig correctly parses custom string delimiters. */ - -%module raw_string_literals +%module cpp0x_raw_string_literals %inline %{ #include diff --git a/Examples/test-suite/cpp0x_static_assert.i b/Examples/test-suite/cpp0x_static_assert.i index 112168f5e..28c244c87 100644 --- a/Examples/test-suite/cpp0x_static_assert.i +++ b/Examples/test-suite/cpp0x_static_assert.i @@ -1,7 +1,7 @@ /* This test case checks whether swig correctly parses and ignores the keywords "static_assert()" inside the class or struct. */ -%module static_assert +%module cpp0x_static_assert %inline %{ template diff --git a/Examples/test-suite/cpp0x_template_double_brackets.i b/Examples/test-suite/cpp0x_template_double_brackets.i index 31c9c7248..74d2fc768 100644 --- a/Examples/test-suite/cpp0x_template_double_brackets.i +++ b/Examples/test-suite/cpp0x_template_double_brackets.i @@ -2,7 +2,7 @@ in the template syntax without having a space inbetween. This feature was introduced in new C++0x standard. */ -%module foo +%module cpp0x_template_double_brackets %inline %{ #include std::map> m; diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 47dc091f4..67cf2dd53 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3850,10 +3850,14 @@ cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN { template_para Namespaceprefix = Swig_symbol_qualifiedscopename(0); if (error) $$ = 0; } - | TEMPLATE cpptype idcolon { + | TEMPLATE cpptype idcolon { /* Explicit template instantiation */ Swig_warning(WARN_PARSE_EXPLICIT_TEMPLATE, cparse_file, cparse_line, "Explicit template instantiation ignored.\n"); $$ = 0; - } + } + | EXTERN TEMPLATE cpptype idcolon { /* Explicit template instantiation without the translation unit */ + Swig_warning(WARN_PARSE_EXPLICIT_TEMPLATE, cparse_file, cparse_line, "Explicit template instantiation ignored.\n"); + $$ = 0; + } ; cpp_temp_possible: c_decl { From 31436be60f7242f88add85dc1eae0be9f245a3a5 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Sat, 11 Jul 2009 20:14:35 +0000 Subject: [PATCH 0010/1160] Added test case. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11386 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/cpp0x_template_explicit.i | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Examples/test-suite/cpp0x_template_explicit.i diff --git a/Examples/test-suite/cpp0x_template_explicit.i b/Examples/test-suite/cpp0x_template_explicit.i new file mode 100644 index 000000000..e0ff71073 --- /dev/null +++ b/Examples/test-suite/cpp0x_template_explicit.i @@ -0,0 +1,22 @@ +/* This unit tests whether Swig correctly parses the code and makes wrappers + for the new C++0x extern templates (explicit template instantiation without + using the translation unit). +*/ +%module cpp0x_template_explicit + +%inline %{ +#include + +class A { +public: + int member; + int memberFunction() { return 100; } +}; + +template class std::vector; +extern template class std::vector; + +template class std::vector; +extern template class std::vector; +%} + From 74d8325cdfb8cd8bddb92ed97e66ef00e858158b Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Tue, 14 Jul 2009 12:05:05 +0000 Subject: [PATCH 0011/1160] Added keyword 'thread_local' to Swig. Added testcase. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11393 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 ++- Examples/test-suite/cpp0x_thread_local.i | 11 +++++++++++ Source/CParse/cscanner.c | 2 ++ Source/CParse/parser.y | 5 +++-- 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 Examples/test-suite/cpp0x_thread_local.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index bd5f7b983..f81c00f36 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -404,7 +404,8 @@ CPP0X_TEST_CASES = \ cpp0x_explicit_conversion_operators \ cpp0x_raw_string_literals \ cpp0x_static_assert \ - cpp0x_template_explicit + cpp0x_template_explicit \ + cpp0x_thread_local # cpp0x_constexpr # not supported by any compilers yet # Broken C++0x test cases. diff --git a/Examples/test-suite/cpp0x_thread_local.i b/Examples/test-suite/cpp0x_thread_local.i new file mode 100644 index 000000000..35ad970e7 --- /dev/null +++ b/Examples/test-suite/cpp0x_thread_local.i @@ -0,0 +1,11 @@ +/* This testcase checks whether Swig correctly parses the 'thread_local' + keyword before the member type and name. */ + +%module cpp0x_thread_local + +%inline %{ +struct A { + thread_local int val; +}; +%} + diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index e4f16bf1c..6ad3b2c5a 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -632,6 +632,8 @@ int yylex(void) { return (FRIEND); if (strcmp(yytext, "constexpr") == 0) return (CONSTEXPR); + if (strcmp(yytext, "thread_local") == 0) + return (THREAD_LOCAL); if (strcmp(yytext, "virtual") == 0) return (VIRTUAL); if (strcmp(yytext, "static_assert") == 0) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 67cf2dd53..61dc79a4e 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1492,8 +1492,8 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %token ILLEGAL CONSTANT %token NAME RENAME NAMEWARN EXTEND PRAGMA FEATURE VARARGS %token ENUM -%token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT CONSTEXPR -%token STATIC_ASSERT +%token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT +%token STATIC_ASSERT CONSTEXPR THREAD_LOCAL /* C++0x keywords */ %token USING %token NAMESPACE %token NATIVE INLINE @@ -4507,6 +4507,7 @@ storage_class : EXTERN { $$ = "extern"; } | FRIEND { $$ = "friend"; } | EXPLICIT { $$ = "explicit"; } | CONSTEXPR { $$ = "constexpr"; } + | THREAD_LOCAL { $$ = "thread_local"; } | empty { $$ = 0; } ; From 55268bbc2d44af219af1a658cbe394374791046f Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Tue, 14 Jul 2009 12:26:26 +0000 Subject: [PATCH 0012/1160] Added testcase for shared_ptr, unique_ptr and weak_ptr. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11394 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 1 + Examples/test-suite/cpp0x_smart_pointers.i | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 Examples/test-suite/cpp0x_smart_pointers.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index f81c00f36..fce242e70 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -406,6 +406,7 @@ CPP0X_TEST_CASES = \ cpp0x_static_assert \ cpp0x_template_explicit \ cpp0x_thread_local +# cpp0x_smart_pointers # not supported by standard library yet # cpp0x_constexpr # not supported by any compilers yet # Broken C++0x test cases. diff --git a/Examples/test-suite/cpp0x_smart_pointers.i b/Examples/test-suite/cpp0x_smart_pointers.i new file mode 100644 index 000000000..4f04e1941 --- /dev/null +++ b/Examples/test-suite/cpp0x_smart_pointers.i @@ -0,0 +1,19 @@ +/* This testcase checks whether Swig correctly uses the new general-purpose + smart pointers introduced in C++0x: + - shared_ptr + - weak_ptr + - unique_ptr +*/ +%module cpp0x_smart_pointers + +%inline %{ +#include +#include +#include + +struct A { + std::shared_ptr a1(new double); + std::unique_ptr a2(new double); + std::weak_ptr a3(a1); +}; +%} From 9fe598cd971d2986af6b7b74b4325c0f8895fb36 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Wed, 15 Jul 2009 21:03:04 +0000 Subject: [PATCH 0013/1160] Fixed cpp0x_raw_string_literals.i test case. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11402 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/cpp0x_raw_string_literals.i | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Examples/test-suite/cpp0x_raw_string_literals.i b/Examples/test-suite/cpp0x_raw_string_literals.i index 4da565264..12c68cd63 100644 --- a/Examples/test-suite/cpp0x_raw_string_literals.i +++ b/Examples/test-suite/cpp0x_raw_string_literals.i @@ -26,16 +26,17 @@ int u8R = 100; int uR = 100; int UR = 100; -string a ="ABC"; -wstring wide =L"ABC"; -string b =u8"ABC"; -string c =u"ABC"; -string d =U"ABC"; - -string e =R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; -wstring wide2 =LR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; -string f =u8R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; -string g =uR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; -string h =UR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; +char *a = "ABC"; +wstring wide = L"ABC"; +//char *b = u8"ABC"; // not supported by GCC +char16_t *c = u"ABC"; +char32_t *d = U"ABC"; +/* Raw string literals are not supported by GCC yet */ +/*char *e = R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; +wstring wide2 = LR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; +char *f = u8R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; +char16_t *g = uR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; +char32_t *h = UR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; +*/ %} From 63a7f06afbf546c091b7695186ac85a579d5787e Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Fri, 17 Jul 2009 10:21:25 +0000 Subject: [PATCH 0014/1160] Added support for cpp0x uniform initialization. Added testcases. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11413 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 ++- .../test-suite/cpp0x_uniform_initialization.i | 20 +++++++++++++++++++ Source/CParse/parser.y | 11 ++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/cpp0x_uniform_initialization.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index fce242e70..f9f0de807 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -405,7 +405,8 @@ CPP0X_TEST_CASES = \ cpp0x_raw_string_literals \ cpp0x_static_assert \ cpp0x_template_explicit \ - cpp0x_thread_local + cpp0x_thread_local \ + cpp0x_uniform_initialization # cpp0x_smart_pointers # not supported by standard library yet # cpp0x_constexpr # not supported by any compilers yet diff --git a/Examples/test-suite/cpp0x_uniform_initialization.i b/Examples/test-suite/cpp0x_uniform_initialization.i new file mode 100644 index 000000000..a56178930 --- /dev/null +++ b/Examples/test-suite/cpp0x_uniform_initialization.i @@ -0,0 +1,20 @@ +%module cpp0x_uniform_initialization + +%inline %{ +struct BasicStruct { + int x; + double y; +}; + +struct AltStruct { + AltStruct(int x, double y) : x_{x}, y_{y} {} + +private: + int x_; + double y_; +}; + +BasicStruct var1{5, 3.2}; // only fills the struct components +AltStruct var2{2, 4.3}; // calls the constructor + +%} diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 61dc79a4e..35b625b0c 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -5846,6 +5846,17 @@ mem_initializer : idcolon LPAREN { skip_balanced('(',')'); Clear(scanner_ccode); } + | idcolon LBRACE { + /* Uniform initialization. eg. + struct MyStruct { + MyStruct(int x, double y) : x_{x}, y_{y} {} + int x_; + double y_; + }; + */ + skip_balanced('{','}'); + Clear(scanner_ccode); + } ; template_decl : LESSTHAN valparms GREATERTHAN { From 03db5b499151aa9c544cd97f5cbe3a3027045a8a Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Fri, 17 Jul 2009 11:17:01 +0000 Subject: [PATCH 0015/1160] Added support for C++0x alternate function syntax. Added testcase. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11414 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 +- .../cpp0x_alternate_function_syntax.i | 11 +++++ Source/CParse/cscanner.c | 6 +++ Source/CParse/parser.y | 43 ++++++++++++------- Source/Swig/stype.c | 3 ++ Source/Swig/swig.h | 1 + Source/Swig/typesys.c | 2 + 7 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 Examples/test-suite/cpp0x_alternate_function_syntax.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index f9f0de807..4ab20575a 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -406,7 +406,8 @@ CPP0X_TEST_CASES = \ cpp0x_static_assert \ cpp0x_template_explicit \ cpp0x_thread_local \ - cpp0x_uniform_initialization + cpp0x_uniform_initialization \ + cpp0x_alternate_function_syntax # cpp0x_smart_pointers # not supported by standard library yet # cpp0x_constexpr # not supported by any compilers yet diff --git a/Examples/test-suite/cpp0x_alternate_function_syntax.i b/Examples/test-suite/cpp0x_alternate_function_syntax.i new file mode 100644 index 000000000..ed3cb6729 --- /dev/null +++ b/Examples/test-suite/cpp0x_alternate_function_syntax.i @@ -0,0 +1,11 @@ +%module cpp0x_alternate_function_syntax + +%inline %{ +struct SomeStruct { + auto FuncName(int x, int y) -> int; +}; + +auto SomeStruct::FuncName(int x, int y) -> int { + return x + y; +} +%} diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index 6ad3b2c5a..1fe0735db 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -340,6 +340,8 @@ int yylook(void) { return GREATERTHANOREQUALTO; case SWIG_TOKEN_RSHIFT: return RSHIFT; + case SWIG_TOKEN_ARROW: + return ARROW; case SWIG_TOKEN_PERIOD: return PERIOD; case SWIG_TOKEN_MODULO: @@ -593,6 +595,10 @@ int yylex(void) { yylval.type = NewSwigType(T_BOOL); return (TYPE_BOOL); } + if (strcmp(yytext, "auto") == 0) { + yylval.type = NewSwigType(T_AUTO); + return (TYPE_AUTO); + } /* Non ISO (Windows) C extensions */ if (strcmp(yytext, "__int8") == 0) { diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 35b625b0c..093c4d315 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1486,7 +1486,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %token CHARCONST %token NUM_INT NUM_FLOAT NUM_UNSIGNED NUM_LONG NUM_ULONG NUM_LONGLONG NUM_ULONGLONG %token TYPEDEF -%token TYPE_INT TYPE_UNSIGNED TYPE_SHORT TYPE_LONG TYPE_FLOAT TYPE_DOUBLE TYPE_CHAR TYPE_WCHAR TYPE_VOID TYPE_SIGNED TYPE_BOOL TYPE_COMPLEX TYPE_TYPEDEF TYPE_RAW TYPE_NON_ISO_INT8 TYPE_NON_ISO_INT16 TYPE_NON_ISO_INT32 TYPE_NON_ISO_INT64 +%token TYPE_INT TYPE_UNSIGNED TYPE_SHORT TYPE_LONG TYPE_FLOAT TYPE_DOUBLE TYPE_CHAR TYPE_WCHAR TYPE_VOID TYPE_SIGNED TYPE_BOOL TYPE_COMPLEX TYPE_TYPEDEF TYPE_RAW TYPE_NON_ISO_INT8 TYPE_NON_ISO_INT16 TYPE_NON_ISO_INT32 TYPE_NON_ISO_INT64 TYPE_AUTO %token LPAREN RPAREN COMMA SEMI EXTERN INIT LBRACE RBRACE PERIOD %token CONST_QUAL VOLATILE REGISTER STRUCT UNION EQUAL SIZEOF MODULE LBRACKET RBRACKET %token ILLEGAL CONSTANT @@ -1501,6 +1501,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %token WARN %token LESSTHAN GREATERTHAN MODULO DELETE_KW %token LESSTHANOREQUALTO GREATERTHANOREQUALTO EQUALTO NOTEQUALTO +%token ARROW %token QUESTIONMARK %token TYPES PARMS %token NONID DSTAR DCNOT @@ -1534,7 +1535,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type types_directive template_directive warn_directive ; /* C declarations */ -%type c_declaration c_decl c_decl_tail c_enum_decl c_enum_forward_decl c_constructor_decl ; +%type c_declaration c_decl c_decl_tail c_enum_decl c_enum_forward_decl c_constructor_decl c_rettype ; %type enumlist edecl; /* C++ declarations */ @@ -2939,25 +2940,25 @@ c_declaration : c_decl { A C global declaration of some kind (may be variable, function, typedef, etc.) ------------------------------------------------------------ */ -c_decl : storage_class type declarator initializer c_decl_tail { +c_decl : storage_class type declarator c_rettype initializer c_decl_tail { $$ = new_node("cdecl"); - if ($4.qualifier) SwigType_push($3.type,$4.qualifier); + if ($5.qualifier) SwigType_push($3.type,$5.qualifier); Setattr($$,"type",$2); Setattr($$,"storage",$1); Setattr($$,"name",$3.id); Setattr($$,"decl",$3.type); Setattr($$,"parms",$3.parms); - Setattr($$,"value",$4.val); - Setattr($$,"throws",$4.throws); - Setattr($$,"throw",$4.throwf); - if (!$5) { + Setattr($$,"value",$5.val); + Setattr($$,"throws",$5.throws); + Setattr($$,"throw",$5.throwf); + if (!$6) { if (Len(scanner_ccode)) { String *code = Copy(scanner_ccode); Setattr($$,"code",code); Delete(code); } } else { - Node *n = $5; + Node *n = $6; /* Inherit attributes */ while (n) { String *type = Copy($2); @@ -2967,8 +2968,8 @@ c_decl : storage_class type declarator initializer c_decl_tail { Delete(type); } } - if ($4.bitfield) { - Setattr($$,"bitfield", $4.bitfield); + if ($5.bitfield) { + Setattr($$,"bitfield", $5.bitfield); } /* Look for "::" declarations (ignored) */ @@ -2982,22 +2983,33 @@ c_decl : storage_class type declarator initializer c_decl_tail { String *lstr = Swig_scopename_last($3.id); Setattr($$,"name",lstr); Delete(lstr); - set_nextSibling($$,$5); + set_nextSibling($$,$6); } else { Delete($$); - $$ = $5; + $$ = $6; } Delete(p); } else { Delete($$); - $$ = $5; + $$ = $6; } } else { - set_nextSibling($$,$5); + set_nextSibling($$,$6); } } ; +/* Alternate function syntax: + auto funcName(int x, int y) -> int; */ + +c_rettype : ARROW type { + $$ = new_node("rettype"); + Setattr($$,"type",$2); + } + | empty { + $$ = 0; + } + ; /* Allow lists of variables and functions to be built up */ c_decl_tail : SEMI { @@ -5209,6 +5221,7 @@ type_right : primitive_type { $$ = $1; } | TYPE_BOOL { $$ = $1; } | TYPE_VOID { $$ = $1; } + | TYPE_AUTO { $$ = $1; } | TYPE_TYPEDEF template_decl { $$ = NewStringf("%s%s",$1,$2); } | ENUM idcolon { $$ = NewStringf("enum %s", $2); } | TYPE_RAW { $$ = $1; } diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index 8a7700bec..3b56e98cb 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -141,6 +141,9 @@ SwigType *NewSwigType(int t) { case T_VOID: return NewString("void"); break; + case T_AUTO: + return NewString("auto"); + break; default: break; } diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 2b2c797c9..7eb9ef210 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -73,6 +73,7 @@ extern "C" { #define T_FLTCPLX 23 #define T_DBLCPLX 24 #define T_NUMERIC 25 +#define T_AUTO 26 #define T_COMPLEX T_DBLCPLX diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index 2562e12f8..9b11a08e5 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -1257,6 +1257,8 @@ int SwigType_type(SwigType *t) { return T_ULONGLONG; if (strncmp(c, "enum ", 5) == 0) return T_INT; + if (strcmp(c, "auto") == 0) + return T_AUTO; if (strcmp(c, "v(...)") == 0) return T_VARARGS; From 048fa1253344676671f44d0c836a1f8776d84a84 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Sat, 18 Jul 2009 19:15:36 +0000 Subject: [PATCH 0016/1160] Added C++0x test case for the hash_tables. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11417 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/cpp0x_hash_tables.i | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Examples/test-suite/cpp0x_hash_tables.i diff --git a/Examples/test-suite/cpp0x_hash_tables.i b/Examples/test-suite/cpp0x_hash_tables.i new file mode 100644 index 000000000..0888590cd --- /dev/null +++ b/Examples/test-suite/cpp0x_hash_tables.i @@ -0,0 +1,39 @@ +%module cpp0x_hash_tables + +%inline %{ +#include +#include +#include +#include +%} + +%include "std_set.i" +%include "std_map.i" +%template (SetInt) std::set; +%template (MapIntInt) std::map; +%template (UnorderedSetInt) std::unordered_set; +%template (UnorderedMapIntInt) std::unordered_map; + +%inline %{ +using namespace std; + +class MyClass { +public: + set getSet() { return _set; } + void addSet(int elt) { _set.insert(_set.begin(), elt); } + map getMap() { return _map; } + void addMap(int elt1, int elt2) { _map.insert(make_pair(elt1, elt2)); } + + unordered_set getUnorderedSet() { return _unordered_set; } + void addUnorderedSet(int elt) { _unordered_set.insert(_unordered_set.begin(), elt); } + unordered_map getUnorderedMap() { return _unordered_map; } + void addUnorderedMap(int elt1, int elt2) { _unordered_map.insert(make_pair(elt1, elt2)); } +private: + set _set; + map _map; + + unordered_set _unordered_set; + unordered_map _unordered_map; +}; +%} + From 523817e4ee33fd5495030285222bc66e1419facd Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Sat, 18 Jul 2009 21:34:53 +0000 Subject: [PATCH 0017/1160] Added initial support for hash tables unordered_ types. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11418 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/cpp0x_hash_tables.i | 24 +-- Lib/python/std_unordered_map.i | 251 ++++++++++++++++++++++++ Lib/python/std_unordered_multimap.i | 79 ++++++++ Lib/python/std_unordered_multiset.i | 41 ++++ Lib/python/std_unordered_set.i | 55 ++++++ Lib/std/std_multimap.i | 2 +- Lib/std/std_multiset.i | 2 +- Lib/std/std_unordered_map.i | 124 ++++++++++++ Lib/std/std_unordered_multimap.i | 87 ++++++++ Lib/std/std_unordered_multiset.i | 83 ++++++++ Lib/std/std_unordered_set.i | 116 +++++++++++ 11 files changed, 851 insertions(+), 13 deletions(-) create mode 100644 Lib/python/std_unordered_map.i create mode 100644 Lib/python/std_unordered_multimap.i create mode 100644 Lib/python/std_unordered_multiset.i create mode 100644 Lib/python/std_unordered_set.i create mode 100644 Lib/std/std_unordered_map.i create mode 100644 Lib/std/std_unordered_multimap.i create mode 100644 Lib/std/std_unordered_multiset.i create mode 100644 Lib/std/std_unordered_set.i diff --git a/Examples/test-suite/cpp0x_hash_tables.i b/Examples/test-suite/cpp0x_hash_tables.i index 0888590cd..a4829ce1f 100644 --- a/Examples/test-suite/cpp0x_hash_tables.i +++ b/Examples/test-suite/cpp0x_hash_tables.i @@ -2,17 +2,19 @@ %inline %{ #include -#include +//#include #include -#include +//#include %} %include "std_set.i" -%include "std_map.i" +//%include "std_map.i" +%include "std_unordered_set.i" +//%include "std_unordered_map.i" %template (SetInt) std::set; -%template (MapIntInt) std::map; +//%template (MapIntInt) std::map; %template (UnorderedSetInt) std::unordered_set; -%template (UnorderedMapIntInt) std::unordered_map; +//%template (UnorderedMapIntInt) std::unordered_map; %inline %{ using namespace std; @@ -21,19 +23,19 @@ class MyClass { public: set getSet() { return _set; } void addSet(int elt) { _set.insert(_set.begin(), elt); } - map getMap() { return _map; } - void addMap(int elt1, int elt2) { _map.insert(make_pair(elt1, elt2)); } +// map getMap() { return _map; } +// void addMap(int elt1, int elt2) { _map.insert(make_pair(elt1, elt2)); } unordered_set getUnorderedSet() { return _unordered_set; } void addUnorderedSet(int elt) { _unordered_set.insert(_unordered_set.begin(), elt); } - unordered_map getUnorderedMap() { return _unordered_map; } - void addUnorderedMap(int elt1, int elt2) { _unordered_map.insert(make_pair(elt1, elt2)); } +// unordered_map getUnorderedMap() { return _unordered_map; } +// void addUnorderedMap(int elt1, int elt2) { _unordered_map.insert(make_pair(elt1, elt2)); } private: set _set; - map _map; +// map _map; unordered_set _unordered_set; - unordered_map _unordered_map; +// unordered_map _unordered_map; }; %} diff --git a/Lib/python/std_unordered_map.i b/Lib/python/std_unordered_map.i new file mode 100644 index 000000000..b456035e2 --- /dev/null +++ b/Lib/python/std_unordered_map.i @@ -0,0 +1,251 @@ +/* + Unordered Maps +*/ + +%fragment("StdMapTraits","header",fragment="StdSequenceTraits") +{ + namespace swig { + template + inline void + assign(const SwigPySeq& swigpyseq, std::unordered_map *unordered_map) { + typedef typename std::unordered_map::value_type value_type; + typename SwigPySeq::const_iterator it = swigpyseq.begin(); + for (;it != swigpyseq.end(); ++it) { + unordered_map->insert(value_type(it->first, it->second)); + } + } + + template + struct traits_asptr > { + typedef std::unordered_map unordered_map_type; + static int asptr(PyObject *obj, unordered_map_type **val) { + int res = SWIG_ERROR; + if (PyDict_Check(obj)) { + SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL); +%#if PY_VERSION_HEX >= 0x03000000 + /* In Python 3.x the ".items()" method return a dict_items object */ + items = PySequence_Fast(items, ".items() havn't returned a sequence!"); +%#endif + res = traits_asptr_stdseq, std::pair >::asptr(items, val); + } else { + unordered_map_type *p; + res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info(),0); + if (SWIG_IsOK(res) && val) *val = p; + } + return res; + } + }; + + template + struct traits_from > { + typedef std::unordered_map unordered_map_type; + typedef typename unordered_map_type::const_iterator const_iterator; + typedef typename unordered_map_type::size_type size_type; + + static PyObject *from(const unordered_map_type& unordered_map) { + swig_type_info *desc = swig::type_info(); + if (desc && desc->clientdata) { + return SWIG_NewPointerObj(new unordered_map_type(unordered_map), desc, SWIG_POINTER_OWN); + } else { + size_type size = unordered_map.size(); + int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1; + if (pysize < 0) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(PyExc_OverflowError, + "unordered_map size not valid in python"); + SWIG_PYTHON_THREAD_END_BLOCK; + return NULL; + } + PyObject *obj = PyDict_New(); + for (const_iterator i= unordered_map.begin(); i!= unordered_map.end(); ++i) { + swig::SwigVar_PyObject key = swig::from(i->first); + swig::SwigVar_PyObject val = swig::from(i->second); + PyDict_SetItem(obj, key, val); + } + return obj; + } + } + }; + + template + struct from_key_oper + { + typedef const ValueType& argument_type; + typedef PyObject *result_type; + result_type operator()(argument_type v) const + { + return swig::from(v.first); + } + }; + + template + struct from_value_oper + { + typedef const ValueType& argument_type; + typedef PyObject *result_type; + result_type operator()(argument_type v) const + { + return swig::from(v.second); + } + }; + + template + struct SwigPyMapIterator_T : SwigPyIteratorClosed_T + { + SwigPyMapIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) + : SwigPyIteratorClosed_T(curr, first, last, seq) + { + } + }; + + + template > + struct SwigPyMapKeyIterator_T : SwigPyMapIterator_T + { + SwigPyMapKeyIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) + : SwigPyMapIterator_T(curr, first, last, seq) + { + } + }; + + template + inline SwigPyIterator* + make_output_key_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0) + { + return new SwigPyMapKeyIterator_T(current, begin, end, seq); + } + + template > + struct SwigPyMapValueITerator_T : SwigPyMapIterator_T + { + SwigPyMapValueITerator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) + : SwigPyMapIterator_T(curr, first, last, seq) + { + } + }; + + + template + inline SwigPyIterator* + make_output_value_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0) + { + return new SwigPyMapValueITerator_T(current, begin, end, seq); + } + } +} + +%define %swig_unordered_map_common(Map...) + %swig_sequence_iterator(Map); + %swig_container_methods(Map) + + %extend { + mapped_type __getitem__(const key_type& key) const throw (std::out_of_range) { + Map::const_iterator i = self->find(key); + if (i != self->end()) + return i->second; + else + throw std::out_of_range("key not found"); + } + + void __delitem__(const key_type& key) throw (std::out_of_range) { + 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 key_type& key) const { + Map::const_iterator i = self->find(key); + return i != self->end(); + } + + PyObject* keys() { + Map::size_type size = self->size(); + int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1; + if (pysize < 0) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(PyExc_OverflowError, + "unordered_map size not valid in python"); + SWIG_PYTHON_THREAD_END_BLOCK; + return NULL; + } + PyObject* keyList = PyList_New(pysize); + Map::const_iterator i = self->begin(); + for (int j = 0; j < pysize; ++i, ++j) { + PyList_SET_ITEM(keyList, j, swig::from(i->first)); + } + return keyList; + } + + PyObject* values() { + Map::size_type size = self->size(); + int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1; + if (pysize < 0) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(PyExc_OverflowError, + "unordered_map size not valid in python"); + SWIG_PYTHON_THREAD_END_BLOCK; + return NULL; + } + PyObject* valList = PyList_New(pysize); + Map::const_iterator i = self->begin(); + for (int j = 0; j < pysize; ++i, ++j) { + PyList_SET_ITEM(valList, j, swig::from(i->second)); + } + return valList; + } + + PyObject* items() { + Map::size_type size = self->size(); + int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1; + if (pysize < 0) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(PyExc_OverflowError, + "unordered_map size not valid in python"); + SWIG_PYTHON_THREAD_END_BLOCK; + return NULL; + } + PyObject* itemList = PyList_New(pysize); + Map::const_iterator i = self->begin(); + for (int j = 0; j < pysize; ++i, ++j) { + PyList_SET_ITEM(itemList, j, swig::from(*i)); + } + return itemList; + } + + // Python 2.2 methods + bool __contains__(const key_type& key) { + return self->find(key) != self->end(); + } + + %newobject key_iterator(PyObject **PYTHON_SELF); + swig::SwigPyIterator* key_iterator(PyObject **PYTHON_SELF) { + return swig::make_output_key_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF); + } + + %newobject value_iterator(PyObject **PYTHON_SELF); + swig::SwigPyIterator* value_iterator(PyObject **PYTHON_SELF) { + return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF); + } + + %pythoncode {def __iter__(self): return self.key_iterator()} + %pythoncode {def iterkeys(self): return self.key_iterator()} + %pythoncode {def itervalues(self): return self.value_iterator()} + %pythoncode {def iteritems(self): return self.iterator()} + } +%enddef + +%define %swig_unordered_map_methods(Map...) + %swig_unordered_map_common(Map) + %extend { + void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) { + (*self)[key] = x; + } + } +%enddef + + +%include diff --git a/Lib/python/std_unordered_multimap.i b/Lib/python/std_unordered_multimap.i new file mode 100644 index 000000000..adf86f251 --- /dev/null +++ b/Lib/python/std_unordered_multimap.i @@ -0,0 +1,79 @@ +/* + Unordered Multimaps +*/ +%include + +%fragment("StdUnorderedMultimapTraits","header",fragment="StdSequenceTraits") +{ + namespace swig { + template + inline void + assign(const SwigPySeq& swigpyseq, std::unordered_multimap *unordered_multimap) { + typedef typename std::unordered_multimap::value_type value_type; + typename SwigPySeq::const_iterator it = swigpyseq.begin(); + for (;it != swigpyseq.end(); ++it) { + unordered_multimap->insert(value_type(it->first, it->second)); + } + } + + template + struct traits_asptr > { + typedef std::unordered_multimap unordered_multimap_type; + static int asptr(PyObject *obj, std::unordered_multimap **val) { + int res = SWIG_ERROR; + if (PyDict_Check(obj)) { + SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL); + return traits_asptr_stdseq, std::pair >::asptr(items, val); + } else { + unordered_multimap_type *p; + res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info(),0); + if (SWIG_IsOK(res) && val) *val = p; + } + return res; + } + }; + + template + struct traits_from > { + typedef std::unordered_multimap unordered_multimap_type; + typedef typename unordered_multimap_type::const_iterator const_iterator; + typedef typename unordered_multimap_type::size_type size_type; + + static PyObject *from(const unordered_multimap_type& unordered_multimap) { + swig_type_info *desc = swig::type_info(); + if (desc && desc->clientdata) { + return SWIG_NewPointerObj(new unordered_multimap_type(unordered_multimap), desc, SWIG_POINTER_OWN); + } else { + size_type size = unordered_multimap.size(); + int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1; + if (pysize < 0) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(PyExc_OverflowError, + "unordered_multimap size not valid in python"); + SWIG_PYTHON_THREAD_END_BLOCK; + return NULL; + } + PyObject *obj = PyDict_New(); + for (const_iterator i= unordered_multimap.begin(); i!= unordered_multimap.end(); ++i) { + swig::SwigVar_PyObject key = swig::from(i->first); + swig::SwigVar_PyObject val = swig::from(i->second); + PyDict_SetItem(obj, key, val); + } + return obj; + } + } + }; + } +} + +%define %swig_unordered_multimap_methods(Type...) + %swig_map_common(Type); + %extend { + void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) { + self->insert(Type::value_type(key,x)); + } + } +%enddef + +%include + diff --git a/Lib/python/std_unordered_multiset.i b/Lib/python/std_unordered_multiset.i new file mode 100644 index 000000000..d5b9ff61c --- /dev/null +++ b/Lib/python/std_unordered_multiset.i @@ -0,0 +1,41 @@ +/* + Unordered Multisets +*/ + +%include + +%fragment("StdUnorderedMultisetTraits","header",fragment="StdSequenceTraits") +%{ + namespace swig { + template + inline void + assign(const SwigPySeq& swigpyseq, std::unordered_multiset* seq) { + // seq->insert(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented + typedef typename SwigPySeq::value_type value_type; + typename SwigPySeq::const_iterator it = swigpyseq.begin(); + for (;it != swigpyseq.end(); ++it) { + seq->insert(seq->end(),(value_type)(*it)); + } + } + + template + struct traits_asptr > { + static int asptr(PyObject *obj, std::unordered_multiset **m) { + return traits_asptr_stdseq >::asptr(obj, m); + } + }; + + template + struct traits_from > { + static PyObject *from(const std::unordered_multiset& vec) { + return traits_from_stdseq >::from(vec); + } + }; + } +%} + +#define %swig_unordered_multiset_methods(Set...) %swig_set_methods(Set) + + + +%include diff --git a/Lib/python/std_unordered_set.i b/Lib/python/std_unordered_set.i new file mode 100644 index 000000000..a021cb4ed --- /dev/null +++ b/Lib/python/std_unordered_set.i @@ -0,0 +1,55 @@ +/* + Unordered Sets +*/ + +%fragment("StdUnorderedSetTraits","header",fragment="StdSequenceTraits") +%{ + namespace swig { + template + inline void + assign(const SwigPySeq& swigpyseq, std::unordered_set* seq) { + // seq->insert(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented + typedef typename SwigPySeq::value_type value_type; + typename SwigPySeq::const_iterator it = swigpyseq.begin(); + for (;it != swigpyseq.end(); ++it) { + seq->insert(seq->end(),(value_type)(*it)); + } + } + + template + struct traits_asptr > { + static int asptr(PyObject *obj, std::unordered_set **s) { + return traits_asptr_stdseq >::asptr(obj, s); + } + }; + + template + struct traits_from > { + static PyObject *from(const std::unordered_set& vec) { + return traits_from_stdseq >::from(vec); + } + }; + } +%} + +%define %swig_unordered_set_methods(unordered_set...) + %swig_sequence_iterator(unordered_set); + %swig_container_methods(unordered_set); + + %extend { + void append(value_type x) { + self->insert(x); + } + + bool __contains__(value_type x) { + return self->find(x) != self->end(); + } + + value_type __getitem__(difference_type i) const throw (std::out_of_range) { + return *(swig::cgetpos(self, i)); + } + + }; +%enddef + +%include diff --git a/Lib/std/std_multimap.i b/Lib/std/std_multimap.i index f165e5f33..829d1b9de 100644 --- a/Lib/std/std_multimap.i +++ b/Lib/std/std_multimap.i @@ -1,5 +1,5 @@ // -// std::map +// std::multimap // %include diff --git a/Lib/std/std_multiset.i b/Lib/std/std_multiset.i index 98a7fb9d7..b63fb92b9 100644 --- a/Lib/std/std_multiset.i +++ b/Lib/std/std_multiset.i @@ -1,5 +1,5 @@ // -// std::set +// std::multiset // %include diff --git a/Lib/std/std_unordered_map.i b/Lib/std/std_unordered_map.i new file mode 100644 index 000000000..f205bd573 --- /dev/null +++ b/Lib/std/std_unordered_map.i @@ -0,0 +1,124 @@ +// +// std::unordered_map +// + +%include +%include + +%define %std_unordered_map_methods_common(unordered_map...) + %std_container_methods(unordered_map); + + size_type erase(const key_type& x); + size_type count(const key_type& x) const; + +#ifdef SWIG_EXPORT_ITERATOR_METHODS +// iterator insert(iterator position, const value_type& x); + void erase(iterator position); + void erase(iterator first, iterator last); + + iterator find(const key_type& x); + iterator lower_bound(const key_type& x); + iterator upper_bound(const key_type& x); +#endif +%enddef + +%define %std_unordered_map_methods(unordered_map...) + %std_unordered_map_methods_common(unordered_map); + + #ifdef SWIG_EXPORT_ITERATOR_METHODS +// iterator insert(const value_type& x); + #endif +%enddef + + +// ------------------------------------------------------------------------ +// std::unordered_map +// +// const declarations are used to guess the intent of the function being +// exported; therefore, the following rationale is applied: +// +// -- f(std::unordered_map), f(const std::unordered_map&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::unordered_map can be passed. +// -- f(std::unordered_map&), f(std::unordered_map*): +// the parameter may be modified; therefore, only a wrapped std::unordered_map +// can be passed. +// -- std::unordered_map f(), const std::unordered_map& f(): +// the unordered_map is returned by copy; therefore, a sequence of T:s +// is returned which is most easily used in other functions +// -- std::unordered_map& f(), std::unordered_map* f(): +// the unordered_map is returned by reference; therefore, a wrapped std::unordered_map +// is returned +// -- const std::unordered_map* f(), f(const std::unordered_map*): +// for consistency, they expect and return a plain unordered_map pointer. +// ------------------------------------------------------------------------ + +%{ +#include +#include +#include +%} + +// exported class + +namespace std { + + template, + class _Alloc = allocator > > + class unordered_map { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Key key_type; + typedef _Tp mapped_type; + typedef std::pair value_type; + + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef _Alloc allocator_type; + + %traits_swigtype(_Key); + %traits_swigtype(_Tp); + + %fragment(SWIG_Traits_frag(std::pair< _Key, _Tp >), "header", + fragment=SWIG_Traits_frag(_Key), + fragment=SWIG_Traits_frag(_Tp), + fragment="StdPairTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::pair<" #_Key "," #_Tp " >"; + } + }; + } + } + + %fragment(SWIG_Traits_frag(std::unordered_map<_Key, _Tp, _Compare, _Alloc >), "header", + fragment=SWIG_Traits_frag(std::pair<_Key, _Tp >), + fragment="StdMapTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::unordered_map<" #_Key "," #_Tp "," #_Compare "," #_Alloc " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_MAP, std::unordered_map<_Key, _Tp, _Compare, _Alloc >); + + unordered_map( const _Compare& ); + +#ifdef %swig_unordered_map_methods + // Add swig/language extra methods + %swig_unordered_map_methods(std::unordered_map<_Key, _Tp, _Compare, _Alloc >); +#endif + + %std_unordered_map_methods(unordered_map); + }; + +} diff --git a/Lib/std/std_unordered_multimap.i b/Lib/std/std_unordered_multimap.i new file mode 100644 index 000000000..bbdfeb82d --- /dev/null +++ b/Lib/std/std_unordered_multimap.i @@ -0,0 +1,87 @@ +// +// std::unordered_multimap +// + +%include + + +%define %std_unordered_multimap_methods(mmap...) + %std_map_methods_common(mmap); + +#ifdef SWIG_EXPORT_ITERATOR_METHODS + std::pair equal_range(const key_type& x); + std::pair equal_range(const key_type& x) const; +#endif +%enddef + +// ------------------------------------------------------------------------ +// std::unordered_multimap +// +// const declarations are used to guess the intent of the function being +// exported; therefore, the following rationale is applied: +// +// -- f(std::unordered_multimap), f(const std::unordered_multimap&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::unordered_multimap can be passed. +// -- f(std::unordered_multimap&), f(std::unordered_multimap*): +// the parameter may be modified; therefore, only a wrapped std::unordered_multimap +// can be passed. +// -- std::unordered_multimap f(), const std::unordered_multimap& f(): +// the map is returned by copy; therefore, a sequence of T:s +// is returned which is most easily used in other functions +// -- std::unordered_multimap& f(), std::unordered_multimap* f(): +// the map is returned by reference; therefore, a wrapped std::unordered_multimap +// is returned +// -- const std::unordered_multimap* f(), f(const std::unordered_multimap*): +// for consistency, they expect and return a plain map pointer. +// ------------------------------------------------------------------------ + + +// exported class + + +namespace std { + template, + class _Alloc = allocator > > + class unordered_multimap { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Key key_type; + typedef _Tp mapped_type; + typedef std::pair value_type; + + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef _Alloc allocator_type; + + %traits_swigtype(_Key); + %traits_swigtype(_Tp); + + %fragment(SWIG_Traits_frag(std::unordered_multimap<_Key, _Tp, _Compare, _Alloc >), "header", + fragment=SWIG_Traits_frag(std::pair<_Key, _Tp >), + fragment="StdMultimapTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::unordered_multimap<" #_Key "," #_Tp "," #_Compare "," #_Alloc " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_MULTIMAP, std::unordered_multimap<_Key, _Tp, _Compare, _Alloc >); + + unordered_multimap( const _Compare& ); + +#ifdef %swig_unordered_multimap_methods + // Add swig/language extra methods + %swig_unordered_multimap_methods(std::unordered_multimap<_Key, _Tp, _Compare, _Alloc >); +#endif + + %std_unordered_multimap_methods(unordered_multimap); + }; +} diff --git a/Lib/std/std_unordered_multiset.i b/Lib/std/std_unordered_multiset.i new file mode 100644 index 000000000..5ef76612d --- /dev/null +++ b/Lib/std/std_unordered_multiset.i @@ -0,0 +1,83 @@ +// +// std::unordered_multiset +// + +%include + +// Unordered Multiset + +%define %std_unordered_multiset_methods(unordered_multiset...) + %std_unordered_set_methods_common(unordered_multiset); +%enddef + + +// ------------------------------------------------------------------------ +// std::unordered_multiset +// +// const declarations are used to guess the intent of the function being +// exported; therefore, the following rationale is applied: +// +// -- f(std::unordered_multiset), f(const std::unordered_multiset&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::unordered_multiset can be passed. +// -- f(std::unordered_multiset&), f(std::unordered_multiset*): +// the parameter may be modified; therefore, only a wrapped std::unordered_multiset +// can be passed. +// -- std::unordered_multiset f(), const std::unordered_multiset& f(): +// the set is returned by copy; therefore, a sequence of T:s +// is returned which is most easily used in other functions +// -- std::unordered_multiset& f(), std::unordered_multiset* f(): +// the set is returned by reference; therefore, a wrapped std::unordered_multiset +// is returned +// -- const std::unordered_multiset* f(), f(const std::unordered_multiset*): +// for consistency, they expect and return a plain set pointer. +// ------------------------------------------------------------------------ + + +// exported classes + +namespace std { + + //unordered_multiset + + template , + class _Alloc = allocator<_Key> > + class unordered_multiset { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Key value_type; + typedef _Key key_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef _Alloc allocator_type; + + %traits_swigtype(_Key); + + %fragment(SWIG_Traits_frag(std::unordered_multiset<_Key, _Compare, _Alloc >), "header", + fragment=SWIG_Traits_frag(_Key), + fragment="StdMultisetTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::unordered_multiset<" #_Key "," #_Compare "," #_Alloc " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_MULTISET, std::unordered_multiset<_Key, _Compare, _Alloc >); + + unordered_multiset( const _Compare& ); + +#ifdef %swig_unordered_multiset_methods + // Add swig/language extra methods + %swig_unordered_multiset_methods(std::unordered_multiset<_Key, _Compare, _Alloc >); +#endif + + %std_unordered_multiset_methods(unordered_multiset); + }; +} diff --git a/Lib/std/std_unordered_set.i b/Lib/std/std_unordered_set.i new file mode 100644 index 000000000..0eac339e0 --- /dev/null +++ b/Lib/std/std_unordered_set.i @@ -0,0 +1,116 @@ +// +// std::unordered_set +// + +%include +%include + +// Unordered Set +%define %std_unordered_set_methods_common(unordered_set...) + unordered_set(); + unordered_set( const unordered_set& ); + + bool empty() const; + size_type size() const; + void clear(); + + void swap(unordered_set& v); + + + size_type erase(const key_type& x); + size_type count(const key_type& x) const; + +#ifdef SWIG_EXPORT_ITERATOR_METHODS + class iterator; + + iterator begin(); + iterator end(); + + void erase(iterator pos); + void erase(iterator first, iterator last); + + iterator find(const key_type& x); + std::pair equal_range(const key_type& x); +#endif +%enddef + +%define %std_unordered_set_methods(unordered_set...) + %std_unordered_set_methods_common(unordered_set); +#ifdef SWIG_EXPORT_ITERATOR_METHODS + std::pair insert(const value_type& __x); +#endif +%enddef + +// ------------------------------------------------------------------------ +// std::unordered_set +// +// const declarations are used to guess the intent of the function being +// exported; therefore, the following rationale is applied: +// +// -- f(std::unordered_set), f(const std::unordered_set&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::unordered_set can be passed. +// -- f(std::unordered_set&), f(std::unordered_set*): +// the parameter may be modified; therefore, only a wrapped std::unordered_set +// can be passed. +// -- std::unordered_set f(), const std::unordered_set& f(): +// the unordered_set is returned by copy; therefore, a sequence of T:s +// is returned which is most easily used in other functions +// -- std::unordered_set& f(), std::unordered_set* f(): +// the unordered_set is returned by reference; therefore, a wrapped std::unordered_set +// is returned +// -- const std::unordered_set* f(), f(const std::unordered_set*): +// for consistency, they expect and return a plain unordered_set pointer. +// ------------------------------------------------------------------------ + +%{ +#include +%} + +// exported classes + +namespace std { + + template , + class _Compare = std::equal_to<_Key>, + class _Alloc = allocator<_Key> > + class unordered_set { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Hash hasher; + typedef _Key value_type; + typedef _Key key_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef _Alloc allocator_type; + + %traits_swigtype(_Key); + + %fragment(SWIG_Traits_frag(std::unordered_set<_Key, _Hash, _Compare, _Alloc >), "header", + fragment=SWIG_Traits_frag(_Key), + fragment="StdUnorderedSetTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::unordered_set<" #_Key "," #_Hash "," #_Compare "," #_Alloc " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_SET, std::unordered_set<_Key, _Hash, _Compare, _Alloc >); + + unordered_set( const _Compare& ); + +#ifdef %swig_unordered_set_methods + // Add swig/language extra methods + %swig_unordered_set_methods(std::unordered_set<_Key, _Hash, _Compare, _Alloc >); +#endif + + %std_unordered_set_methods(unordered_set); + }; +} From e949fa3cc7924f75c31b459ded4dc1d3c91b3a4c Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Sat, 18 Jul 2009 22:13:40 +0000 Subject: [PATCH 0018/1160] Added testcase for function objects. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11419 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 6 ++++-- Examples/test-suite/cpp0x_function_objects.i | 18 ++++++++++++++++++ .../python/cpp0x_function_objects_runme.py | 12 ++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/cpp0x_function_objects.i create mode 100644 Examples/test-suite/python/cpp0x_function_objects_runme.py diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 4ab20575a..76504dd0f 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -405,11 +405,13 @@ CPP0X_TEST_CASES = \ cpp0x_raw_string_literals \ cpp0x_static_assert \ cpp0x_template_explicit \ - cpp0x_thread_local \ cpp0x_uniform_initialization \ - cpp0x_alternate_function_syntax + cpp0x_alternate_function_syntax \ + cpp0x_function_objects +# cpp0x_hash_types # not fully implemented yet # cpp0x_smart_pointers # not supported by standard library yet # cpp0x_constexpr # not supported by any compilers yet +# cpp0x_thread_local # not supported by any compilers yet # Broken C++0x test cases. CPP0X_TEST_BROKEN = diff --git a/Examples/test-suite/cpp0x_function_objects.i b/Examples/test-suite/cpp0x_function_objects.i new file mode 100644 index 000000000..f480addc7 --- /dev/null +++ b/Examples/test-suite/cpp0x_function_objects.i @@ -0,0 +1,18 @@ +/* This testcase checks whether Swig correctly parses function objects + and the templates for the functions (signature). + Function objects are objects which overload the operator() function. */ +%module cpp0x_function_objects + +%inline %{ +//function pF; // not supported yet by the compiler + +struct Test { + int value; + + void operator()(short x, short y) { + value=10; + } + +} test; +%} + diff --git a/Examples/test-suite/python/cpp0x_function_objects_runme.py b/Examples/test-suite/python/cpp0x_function_objects_runme.py new file mode 100644 index 000000000..edbd88e1c --- /dev/null +++ b/Examples/test-suite/python/cpp0x_function_objects_runme.py @@ -0,0 +1,12 @@ +import cpp0x_function_objects +import sys + +t = cpp0x_function_objects.Test() +if t.value != 0: + raise RuntimeError,"Runtime cpp0x_function_objects failed. t.value should be 0, but is", t.value + +t(1,2) # sets value + +if t.value != 10: + raise RuntimeError,"Runtime cpp0x_function_objects failed. t.value not changed - should be 10, but is", t.value + From 54e6910631bfb2f2bbd23f25fe40aebae9686e74 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Sat, 18 Jul 2009 22:35:03 +0000 Subject: [PATCH 0019/1160] Disabled alternate function syntax testcase. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11422 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 76504dd0f..add8a2422 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -406,8 +406,8 @@ CPP0X_TEST_CASES = \ cpp0x_static_assert \ cpp0x_template_explicit \ cpp0x_uniform_initialization \ - cpp0x_alternate_function_syntax \ cpp0x_function_objects +# cpp0x_alternate_function_syntax # not fully implemented yet # cpp0x_hash_types # not fully implemented yet # cpp0x_smart_pointers # not supported by standard library yet # cpp0x_constexpr # not supported by any compilers yet From f9a385c6a6bb60757fa4a83e00cb7ee7382579c1 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Wed, 22 Jul 2009 17:48:38 +0000 Subject: [PATCH 0020/1160] Added testcase for cpp0x unrestricted unions. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11435 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 1 + Examples/test-suite/cpp0x_unrestricted_unions.i | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 Examples/test-suite/cpp0x_unrestricted_unions.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index add8a2422..627847d83 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -409,6 +409,7 @@ CPP0X_TEST_CASES = \ cpp0x_function_objects # cpp0x_alternate_function_syntax # not fully implemented yet # cpp0x_hash_types # not fully implemented yet +# cpp0x_unrestricted_unions # not supported by any compilers yet # cpp0x_smart_pointers # not supported by standard library yet # cpp0x_constexpr # not supported by any compilers yet # cpp0x_thread_local # not supported by any compilers yet diff --git a/Examples/test-suite/cpp0x_unrestricted_unions.i b/Examples/test-suite/cpp0x_unrestricted_unions.i new file mode 100644 index 000000000..87d7af9a9 --- /dev/null +++ b/Examples/test-suite/cpp0x_unrestricted_unions.i @@ -0,0 +1,16 @@ +%module cpp0x_unrestricted_unions + +%inline %{ +struct point { +// point() {} +// point(int x, int y) : x_(x), y_(y) {} + int x_, y_; +}; + +union P { + int z; + double w; + point p; +} p1; +%} + From fd981a58ddc445532641f83172b979087204b841 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Fri, 24 Jul 2009 08:52:35 +0000 Subject: [PATCH 0021/1160] Fixed bug in cpp0x testcase. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11447 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/cpp0x_unrestricted_unions.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/cpp0x_unrestricted_unions.i b/Examples/test-suite/cpp0x_unrestricted_unions.i index 87d7af9a9..d3364ef83 100644 --- a/Examples/test-suite/cpp0x_unrestricted_unions.i +++ b/Examples/test-suite/cpp0x_unrestricted_unions.i @@ -2,8 +2,8 @@ %inline %{ struct point { -// point() {} -// point(int x, int y) : x_(x), y_(y) {} + point() {} + point(int x, int y) : x_(x), y_(y) {} int x_, y_; }; From 29004c3fcf42ca07d63a5249ed9a41a944a4a8b6 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Sat, 25 Jul 2009 16:48:30 +0000 Subject: [PATCH 0022/1160] Added initial support for parsing C++0x strongly typed enumerations. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11449 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 +- .../cpp0x_strongly_typed_enumerations.i | 36 ++++++++ Source/CParse/parser.y | 83 +++++++++++++------ 3 files changed, 95 insertions(+), 27 deletions(-) create mode 100644 Examples/test-suite/cpp0x_strongly_typed_enumerations.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 627847d83..cd97ae245 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -406,7 +406,8 @@ CPP0X_TEST_CASES = \ cpp0x_static_assert \ cpp0x_template_explicit \ cpp0x_uniform_initialization \ - cpp0x_function_objects + cpp0x_function_objects \ + cpp0x_strongly_typed_enumerations # cpp0x_alternate_function_syntax # not fully implemented yet # cpp0x_hash_types # not fully implemented yet # cpp0x_unrestricted_unions # not supported by any compilers yet diff --git a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i new file mode 100644 index 000000000..0f281a195 --- /dev/null +++ b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i @@ -0,0 +1,36 @@ +%module cpp0x_strongly_typed_enumerations + +%inline %{ +enum class Enum1 { + Val1, + Val2, + Val3 = 100, + Val4 /* = 101 */ +}; + +enum class Enum2 : short { + Val1, + Val2, + Val3 = 100, + Val4 +}; + +/* Forward declarations. GCC doesn't support them */ +//enum Enum3; // Illegal in C++ and C++0x; no size is explicitly specified. +//enum Enum4 : unsigned int; // Legal in C++0x. +//enum class Enum5; // Legal in C++0x, because enum class declarations have a default type of "int". +//enum class Enum6 : unsigned int; // Legal C++0x. +//enum Enum2 : unsigned short; // Illegal in C++0x, because Enum2 was previously declared with a different type. + +enum Enum4 : unsigned int { + Val1, Val2, Val3 = 100, Val4 +}; + +enum class Enum5 { + Val1, Val2, Val3 = 100, Val4 +}; + +enum class Enum6 : unsigned int { + Val1, Val2, Val3 = 300, Val4 +}; +%} diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 093c4d315..1469efe20 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1,4 +1,4 @@ -/* ----------------------------------------------------------------------------- + /* ----------------------------------------------------------------------------- * 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. * @@ -1535,7 +1535,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type types_directive template_directive warn_directive ; /* C declarations */ -%type c_declaration c_decl c_decl_tail c_enum_decl c_enum_forward_decl c_constructor_decl c_rettype ; +%type c_declaration c_decl c_decl_tail c_enum_keyword c_enum_inherit c_enum_decl c_enum_forward_decl c_constructor_decl c_rettype ; %type enumlist edecl; /* C++ declarations */ @@ -3071,15 +3071,40 @@ initializer : def_args { ; + /* ------------------------------------------------------------ - enum Name; + enum + or + enum class ------------------------------------------------------------ */ -c_enum_forward_decl : storage_class ENUM ID SEMI { +c_enum_keyword : ENUM { + $$ = (char*)"enumkeyword"; + } + | ENUM CLASS { + $$ = (char*)"enumclasskeyword"; + } + ; + +/* ------------------------------------------------------------ + base enum type (eg. unsigned short) + ------------------------------------------------------------ */ + +c_enum_inherit : COLON primitive_type { + $$ = $2; + } + | empty { $$ = 0; } + ; +/* ------------------------------------------------------------ + enum [class] Name; + ------------------------------------------------------------ */ + +c_enum_forward_decl : storage_class c_enum_keyword c_enum_inherit ID SEMI { SwigType *ty = 0; $$ = new_node("enumforward"); - ty = NewStringf("enum %s", $3); - Setattr($$,"name",$3); + ty = NewStringf("enum %s", $4); + Setattr($$,"enumkeyword",$2); + Setattr($$,"name",$4); Setattr($$,"type",ty); Setattr($$,"sym:weak", "1"); add_symbols($$); @@ -3087,52 +3112,58 @@ c_enum_forward_decl : storage_class ENUM ID SEMI { ; /* ------------------------------------------------------------ - enum { ... } + enum [class] Name [: base_type] { ... }; + or + enum [class] Name [: base_type] { ... } MyEnum [= ...]; * ------------------------------------------------------------ */ -c_enum_decl : storage_class ENUM ename LBRACE enumlist RBRACE SEMI { +c_enum_decl : storage_class c_enum_keyword ename c_enum_inherit LBRACE enumlist RBRACE SEMI { SwigType *ty = 0; $$ = new_node("enum"); ty = NewStringf("enum %s", $3); + Setattr($$,"enumkeyword",$2); Setattr($$,"name",$3); + Setattr($$,"inherit",$4); Setattr($$,"type",ty); - appendChild($$,$5); - add_symbols($$); /* Add to tag space */ - add_symbols($5); /* Add enum values to id space */ + appendChild($$,$6); + add_symbols($$); /* Add to tag space */ + add_symbols($6); /* Add enum values to id space */ } - | storage_class ENUM ename LBRACE enumlist RBRACE declarator c_decl_tail { + | storage_class c_enum_keyword ename c_enum_inherit LBRACE enumlist RBRACE declarator c_decl_tail { Node *n; SwigType *ty = 0; String *unnamed = 0; int unnamedinstance = 0; $$ = new_node("enum"); + Setattr($$,"enumkeyword",$2); + Setattr($$,"inherit",$4); if ($3) { Setattr($$,"name",$3); ty = NewStringf("enum %s", $3); - } else if ($7.id) { + } else if ($8.id) { unnamed = make_unnamed(); ty = NewStringf("enum %s", unnamed); Setattr($$,"unnamed",unnamed); /* name is not set for unnamed enum instances, e.g. enum { foo } Instance; */ if ($1 && Cmp($1,"typedef") == 0) { - Setattr($$,"name",$7.id); + Setattr($$,"name",$8.id); } else { unnamedinstance = 1; } Setattr($$,"storage",$1); } - if ($7.id && Cmp($1,"typedef") == 0) { - Setattr($$,"tdname",$7.id); + if ($8.id && Cmp($1,"typedef") == 0) { + Setattr($$,"tdname",$8.id); Setattr($$,"allows_typedef","1"); } - appendChild($$,$5); + appendChild($$,$6); n = new_node("cdecl"); Setattr(n,"type",ty); - Setattr(n,"name",$7.id); + Setattr(n,"name",$8.id); Setattr(n,"storage",$1); - Setattr(n,"decl",$7.type); - Setattr(n,"parms",$7.parms); + Setattr(n,"decl",$8.type); + Setattr(n,"parms",$8.parms); Setattr(n,"unnamed",unnamed); if (unnamedinstance) { @@ -3142,8 +3173,8 @@ c_enum_decl : storage_class ENUM ename LBRACE enumlist RBRACE SEMI { Setattr(n,"unnamedinstance","1"); Delete(cty); } - if ($8) { - Node *p = $8; + if ($9) { + Node *p = $9; set_nextSibling(n,p); while (p) { SwigType *cty = Copy(ty); @@ -3163,8 +3194,8 @@ c_enum_decl : storage_class ENUM ename LBRACE enumlist RBRACE SEMI { /* Ensure that typedef enum ABC {foo} XYZ; uses XYZ for sym:name, like structs. * Note that class_rename/yyrename are bit of a mess so used this simple approach to change the name. */ - if ($7.id && $3 && Cmp($1,"typedef") == 0) { - String *name = NewString($7.id); + if ($8.id && $3 && Cmp($1,"typedef") == 0) { + String *name = NewString($8.id); Setattr($$, "parser:makename", name); Delete(name); } @@ -3172,7 +3203,7 @@ c_enum_decl : storage_class ENUM ename LBRACE enumlist RBRACE SEMI { add_symbols($$); /* Add enum to tag space */ set_nextSibling($$,n); Delete(n); - add_symbols($5); /* Add enum values to id space */ + add_symbols($6); /* Add enum values to id space */ add_symbols(n); Delete(unnamed); } @@ -5223,7 +5254,7 @@ type_right : primitive_type { $$ = $1; | TYPE_VOID { $$ = $1; } | TYPE_AUTO { $$ = $1; } | TYPE_TYPEDEF template_decl { $$ = NewStringf("%s%s",$1,$2); } - | ENUM idcolon { $$ = NewStringf("enum %s", $2); } + | c_enum_keyword idcolon { $$ = NewStringf("enum %s", $2); } | TYPE_RAW { $$ = $1; } | idcolon { From a8209bfd68e9e6f4a952b77f26e44167cddcc3d1 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Sat, 25 Jul 2009 18:51:37 +0000 Subject: [PATCH 0023/1160] Added support for C++0x rvalue and move semantics. Added testcase. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11450 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 ++- Examples/test-suite/cpp0x_rvalue_reference.i | 23 +++++++++++++++++++ .../python/cpp0x_rvalue_reference_runme.py | 22 ++++++++++++++++++ Source/CParse/parser.y | 13 +++++++++-- 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 Examples/test-suite/cpp0x_rvalue_reference.i create mode 100644 Examples/test-suite/python/cpp0x_rvalue_reference_runme.py diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index cd97ae245..2d5082398 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -407,7 +407,8 @@ CPP0X_TEST_CASES = \ cpp0x_template_explicit \ cpp0x_uniform_initialization \ cpp0x_function_objects \ - cpp0x_strongly_typed_enumerations + cpp0x_strongly_typed_enumerations \ + cpp0x_rvalue_reference # cpp0x_alternate_function_syntax # not fully implemented yet # cpp0x_hash_types # not fully implemented yet # cpp0x_unrestricted_unions # not supported by any compilers yet diff --git a/Examples/test-suite/cpp0x_rvalue_reference.i b/Examples/test-suite/cpp0x_rvalue_reference.i new file mode 100644 index 000000000..0a7fa9147 --- /dev/null +++ b/Examples/test-suite/cpp0x_rvalue_reference.i @@ -0,0 +1,23 @@ +%module cpp0x_rvalue_reference + +%inline %{ +class A { +public: + int getAcopy() { return _a; } + int *getAptr() { return &_a; } + int &getAref() { return _a; } + int &&getAmove() { return _a; } + + void setAcopy(int a) { _a = a; } + void setAptr(int *a) { _a = *a; } + void setAref(int &a) { _a = a; } + void setAmove(int &&a) { _a = a; } + + void arg(int a); + void arg(int *a); + void arg(int &a); +// void arg(int &&a); // redefinition not allowed +private: + int _a; +}; +%} diff --git a/Examples/test-suite/python/cpp0x_rvalue_reference_runme.py b/Examples/test-suite/python/cpp0x_rvalue_reference_runme.py new file mode 100644 index 000000000..1f74cfaa8 --- /dev/null +++ b/Examples/test-suite/python/cpp0x_rvalue_reference_runme.py @@ -0,0 +1,22 @@ +import cpp0x_rvalue_reference + +a = cpp0x_rvalue_reference.A() + +a.setAcopy(5) +if a.getAcopy() != 5: + raise RunTimeError, "int A::getAcopy() value is ", a.getAcopy(), " should be 5" + +ptr = a.getAptr() + +a.setAptr(ptr) +if a.getAcopy() != 5: + raise RunTimeError, "after A::setAptr(): int A::getAcopy() value is ", a.getAcopy(), " should be 5" + +a.setAref(ptr) +if a.getAcopy() != 5: + raise RunTimeError, "after A::setAref(): int A::getAcopy() value is ", a.getAcopy(), " should be 5" + +a.setAmove(ptr) +if a.getAcopy() != 5: + raise RunTimeError, "after A::setAmove(): int A::getAcopy() value is ", a.getAcopy(), " should be 5" + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 1469efe20..f42e9657a 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -4804,7 +4804,16 @@ declarator : pointer notso_direct_declarator { $$ = $1; if (!$$.type) $$.type = NewStringEmpty(); } - | AND notso_direct_declarator { + | AND notso_direct_declarator { + $$ = $2; + $$.type = NewStringEmpty(); + SwigType_add_reference($$.type); + if ($2.type) { + SwigType_push($$.type,$2.type); + Delete($2.type); + } + } + | LAND notso_direct_declarator { $$ = $2; $$.type = NewStringEmpty(); SwigType_add_reference($$.type); @@ -5082,7 +5091,7 @@ abstract_declarator : pointer { Delete($2.type); } } - | AND { + | AND { $$.id = 0; $$.parms = 0; $$.have_parms = 0; From 94e94dce02c1dfc14f38211e18b1c6aa8b0a6e00 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Sat, 25 Jul 2009 19:14:17 +0000 Subject: [PATCH 0024/1160] Added partial support for unordered_ STL types. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11451 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyiterators.swg | 10 ---------- Lib/python/pystdcommon.swg | 2 ++ 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Lib/python/pyiterators.swg b/Lib/python/pyiterators.swg index 8719f73ce..1d7f415be 100644 --- a/Lib/python/pyiterators.swg +++ b/Lib/python/pyiterators.swg @@ -226,9 +226,6 @@ namespace swig { SwigPyIterator *decr(size_t n = 1) { - while (n--) { - --base::current; - } return this; } }; @@ -277,13 +274,6 @@ namespace swig { SwigPyIterator *decr(size_t n = 1) { - while (n--) { - if (base::current == begin) { - throw stop_iteration(); - } else { - --base::current; - } - } return this; } diff --git a/Lib/python/pystdcommon.swg b/Lib/python/pystdcommon.swg index 7e9720cc0..f71425616 100644 --- a/Lib/python/pystdcommon.swg +++ b/Lib/python/pystdcommon.swg @@ -257,3 +257,5 @@ namespace swig { #define specialize_std_deque(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) #define specialize_std_set(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) #define specialize_std_multiset(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) +#define specialize_std_unordered_set(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) +#define specialize_std_unordered_multiset(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) From 85ae38cceefb94c52e36431e42f23c815bb6f41f Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Mon, 27 Jul 2009 19:07:38 +0000 Subject: [PATCH 0025/1160] Added initial support for variadic templates. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11458 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 ++- Examples/test-suite/cpp0x_variadic_templates.i | 8 ++++++++ Source/CParse/parser.y | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/cpp0x_variadic_templates.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 2d5082398..24dd4f6e3 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -408,7 +408,8 @@ CPP0X_TEST_CASES = \ cpp0x_uniform_initialization \ cpp0x_function_objects \ cpp0x_strongly_typed_enumerations \ - cpp0x_rvalue_reference + cpp0x_rvalue_reference \ + cpp0x_variadic_templates # cpp0x_alternate_function_syntax # not fully implemented yet # cpp0x_hash_types # not fully implemented yet # cpp0x_unrestricted_unions # not supported by any compilers yet diff --git a/Examples/test-suite/cpp0x_variadic_templates.i b/Examples/test-suite/cpp0x_variadic_templates.i new file mode 100644 index 000000000..51314c2a2 --- /dev/null +++ b/Examples/test-suite/cpp0x_variadic_templates.i @@ -0,0 +1,8 @@ +%module cpp0x_variadic_templates + +%inline %{ +template +class tuple { +}; + +%} diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index f42e9657a..02493a280 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -5808,6 +5808,14 @@ templcpptype : CLASS { $$ = (char *)"typename"; if (!inherit_list) last_cpptype = $$; } + | CLASS PERIOD PERIOD PERIOD { + $$ = (char*)"class"; + if (!inherit_list) last_cpptype = $$; + } + | TYPENAME PERIOD PERIOD PERIOD { + $$ = (char *)"typename"; + if (!inherit_list) last_cpptype = $$; + } ; cpptype : templcpptype { From 2e01562965208de1c08c00077918e85aed1ca026 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Wed, 29 Jul 2009 13:38:22 +0000 Subject: [PATCH 0026/1160] Added variadic '...' syntax for inheritance introduced in C++0x. Added sizeof... syntax introduced in C++0x. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11467 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/cpp0x_variadic_templates.i | 61 ++++++++++++++++++- Source/CParse/parser.y | 57 ++++++++++++++--- 2 files changed, 107 insertions(+), 11 deletions(-) diff --git a/Examples/test-suite/cpp0x_variadic_templates.i b/Examples/test-suite/cpp0x_variadic_templates.i index 51314c2a2..090645966 100644 --- a/Examples/test-suite/cpp0x_variadic_templates.i +++ b/Examples/test-suite/cpp0x_variadic_templates.i @@ -1,8 +1,67 @@ +/* This testcase checks whether Swig correctly parses and generates the code + for variadic templates. This covers the variadic number of arguments inside + the template brackets, new functions sizeof... and multiple inheritance + using variadic number of classes. +*/ %module cpp0x_variadic_templates +//////////////////////// +// Variadic templates // +//////////////////////// %inline %{ +#include +#include +#include + template -class tuple { +class MultiArgs { }; +class MultiArgs, std::map>> multiArgs; + %} + +// TODO +//%template (MultiArgs) MultiArgs, std::map>>; + +//////////////////////// +// Variadic sizeof... // +//////////////////////// +%inline %{ +template struct SizeOf { + static const int size = sizeof...(Args); +}; +%} + +// TODO +//%template (SizeOf) SizeOf; + +////////////////////////// +// Variadic inheritance // +////////////////////////// +%inline %{ +class A { +public: + A() { + a = 100; + } + + int a; +}; + +class B { +public: + B() { + b = 200; + } + int b; +}; + +template class MultiInherit : public BaseClasses... { +public: + MultiInherit(BaseClasses&&... baseClasses) : BaseClasses(baseClasses)... {} +}; +%} + +// TODO +//%template (MultiInherit) MultiInherit; diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 02493a280..60ac7c3d2 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1,4 +1,4 @@ - /* ----------------------------------------------------------------------------- +/* ----------------------------------------------------------------------------- * 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. * @@ -1549,7 +1549,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { /* Misc */ %type initializer cpp_const ; %type storage_class; -%type parms ptail rawparms varargs_parms; +%type parms ptail rawparms varargs_parms ; %type templateparameters templateparameterstail; %type

parm valparm rawvalparms valparms valptail ; %type

typemap_parm tm_list tm_tail ; @@ -4814,6 +4814,7 @@ declarator : pointer notso_direct_declarator { } } | LAND notso_direct_declarator { + /* Introduced in C++0x, move operator && */ $$ = $2; $$.type = NewStringEmpty(); SwigType_add_reference($$.type); @@ -5538,6 +5539,11 @@ valexpr : exprnum { $$ = $1; } $$.val = NewStringf("sizeof(%s)",SwigType_str($3,0)); $$.type = T_ULONG; } + | SIZEOF PERIOD PERIOD PERIOD LPAREN type parameter_declarator RPAREN { + SwigType_push($6,$7.type); + $$.val = NewStringf("sizeof...(%s)",SwigType_str($6,0)); + $$.type = T_ULONG; + } | exprcompound { $$ = $1; } | CHARCONST { $$.val = NewString($1); @@ -5792,6 +5798,30 @@ base_specifier : opt_virtual idcolon { cparse_line,"%s inheritance ignored.\n", $2); } } + | opt_virtual idcolon PERIOD PERIOD PERIOD { /* Variadic inheritance */ + $$ = NewHash(); + Setfile($$,cparse_file); + Setline($$,cparse_line); + Setattr($$,"name",$2); + if (last_cpptype && (Strcmp(last_cpptype,"struct") != 0)) { + Setattr($$,"access","private"); + Swig_warning(WARN_PARSE_NO_ACCESS,cparse_file,cparse_line, + "No access specifier given for base class %s (ignored).\n",$2); + } else { + Setattr($$,"access","public"); + } + } + | opt_virtual access_specifier opt_virtual idcolon PERIOD PERIOD PERIOD { /* Variadic inheritance */ + $$ = NewHash(); + Setfile($$,cparse_file); + Setline($$,cparse_line); + Setattr($$,"name",$4); + Setattr($$,"access",$2); + if (Strcmp($2,"public") != 0) { + Swig_warning(WARN_PARSE_PRIVATE_INHERIT, cparse_file, + cparse_line,"%s inheritance ignored.\n", $2); + } + } ; access_specifier : PUBLIC { $$ = (char*)"public"; } @@ -5903,21 +5933,24 @@ mem_initializer_list : mem_initializer | mem_initializer_list COMMA mem_initializer ; -mem_initializer : idcolon LPAREN { - skip_balanced('(',')'); +mem_initializer : idcolon LPAREN parms RPAREN { +/* skip_balanced('(',')'); Clear(scanner_ccode); - } - | idcolon LBRACE { - /* Uniform initialization. eg. +*/ } + | idcolon LBRACE parms RBRACE { + /* Uniform initialization in C++0x. + Example: struct MyStruct { MyStruct(int x, double y) : x_{x}, y_{y} {} int x_; double y_; }; */ - skip_balanced('{','}'); +/* skip_balanced('{','}'); Clear(scanner_ccode); - } +*/ } + | idcolon LPAREN parms RPAREN PERIOD PERIOD PERIOD { } + | idcolon LBRACE parms RBRACE PERIOD PERIOD PERIOD { } ; template_decl : LESSTHAN valparms GREATERTHAN { @@ -5936,7 +5969,7 @@ idstring : ID { $$ = $1; } idstringopt : idstring { $$ = $1; } | empty { $$ = 0; } ; - + idcolon : idtemplate idcolontail { $$ = 0; if (!$$) $$ = NewStringf("%s%s", $1,$2); @@ -5946,6 +5979,10 @@ idcolon : idtemplate idcolontail { $$ = NewStringf("::%s%s",$3,$4); Delete($4); } + | PERIOD PERIOD PERIOD idtemplate { + /* Introduced in C++0x, variadic constructor args */ + $$ = NewString($4); + } | idtemplate { $$ = NewString($1); } From e7fd659ae50fbe1b90f59bdde6bdc7d92470953a Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Thu, 30 Jul 2009 19:18:37 +0000 Subject: [PATCH 0027/1160] Fixed S/R and R/R conflicts. Fixed testcase for rvalue reference. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11483 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/cpp0x_rvalue_reference.i | 4 - .../python/cpp0x_rvalue_reference_runme.py | 8 +- Source/CParse/cscanner.c | 6 +- Source/CParse/parser.y | 157 ++++++++++++------ 4 files changed, 110 insertions(+), 65 deletions(-) diff --git a/Examples/test-suite/cpp0x_rvalue_reference.i b/Examples/test-suite/cpp0x_rvalue_reference.i index 0a7fa9147..e45d91e27 100644 --- a/Examples/test-suite/cpp0x_rvalue_reference.i +++ b/Examples/test-suite/cpp0x_rvalue_reference.i @@ -13,10 +13,6 @@ public: void setAref(int &a) { _a = a; } void setAmove(int &&a) { _a = a; } - void arg(int a); - void arg(int *a); - void arg(int &a); -// void arg(int &&a); // redefinition not allowed private: int _a; }; diff --git a/Examples/test-suite/python/cpp0x_rvalue_reference_runme.py b/Examples/test-suite/python/cpp0x_rvalue_reference_runme.py index 1f74cfaa8..acf296716 100644 --- a/Examples/test-suite/python/cpp0x_rvalue_reference_runme.py +++ b/Examples/test-suite/python/cpp0x_rvalue_reference_runme.py @@ -4,19 +4,19 @@ a = cpp0x_rvalue_reference.A() a.setAcopy(5) if a.getAcopy() != 5: - raise RunTimeError, "int A::getAcopy() value is ", a.getAcopy(), " should be 5" + raise RunTimeError, ("int A::getAcopy() value is ", a.getAcopy(), " should be 5") ptr = a.getAptr() a.setAptr(ptr) if a.getAcopy() != 5: - raise RunTimeError, "after A::setAptr(): int A::getAcopy() value is ", a.getAcopy(), " should be 5" + raise RunTimeError, ("after A::setAptr(): int A::getAcopy() value is ", a.getAcopy(), " should be 5") a.setAref(ptr) if a.getAcopy() != 5: - raise RunTimeError, "after A::setAref(): int A::getAcopy() value is ", a.getAcopy(), " should be 5" + raise RunTimeError, ("after A::setAref(): int A::getAcopy() value is ", a.getAcopy(), " should be 5") a.setAmove(ptr) if a.getAcopy() != 5: - raise RunTimeError, "after A::setAmove(): int A::getAcopy() value is ", a.getAcopy(), " should be 5" + raise RunTimeError, ("after A::setAmove(): int A::getAcopy() value is ", a.getAcopy(), " should be 5") diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index 1fe0735db..f923bc3b6 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -595,10 +595,6 @@ int yylex(void) { yylval.type = NewSwigType(T_BOOL); return (TYPE_BOOL); } - if (strcmp(yytext, "auto") == 0) { - yylval.type = NewSwigType(T_AUTO); - return (TYPE_AUTO); - } /* Non ISO (Windows) C extensions */ if (strcmp(yytext, "__int8") == 0) { @@ -788,6 +784,8 @@ int yylex(void) { return (yylex()); if (strcmp(yytext, "explicit") == 0) return (EXPLICIT); + if (strcmp(yytext, "auto") == 0) + return (AUTO); if (strcmp(yytext, "export") == 0) return (yylex()); if (strcmp(yytext, "typename") == 0) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 60ac7c3d2..c8e7e284d 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1486,13 +1486,13 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %token CHARCONST %token NUM_INT NUM_FLOAT NUM_UNSIGNED NUM_LONG NUM_ULONG NUM_LONGLONG NUM_ULONGLONG %token TYPEDEF -%token TYPE_INT TYPE_UNSIGNED TYPE_SHORT TYPE_LONG TYPE_FLOAT TYPE_DOUBLE TYPE_CHAR TYPE_WCHAR TYPE_VOID TYPE_SIGNED TYPE_BOOL TYPE_COMPLEX TYPE_TYPEDEF TYPE_RAW TYPE_NON_ISO_INT8 TYPE_NON_ISO_INT16 TYPE_NON_ISO_INT32 TYPE_NON_ISO_INT64 TYPE_AUTO +%token TYPE_INT TYPE_UNSIGNED TYPE_SHORT TYPE_LONG TYPE_FLOAT TYPE_DOUBLE TYPE_CHAR TYPE_WCHAR TYPE_VOID TYPE_SIGNED TYPE_BOOL TYPE_COMPLEX TYPE_TYPEDEF TYPE_RAW TYPE_NON_ISO_INT8 TYPE_NON_ISO_INT16 TYPE_NON_ISO_INT32 TYPE_NON_ISO_INT64 %token LPAREN RPAREN COMMA SEMI EXTERN INIT LBRACE RBRACE PERIOD %token CONST_QUAL VOLATILE REGISTER STRUCT UNION EQUAL SIZEOF MODULE LBRACKET RBRACKET %token ILLEGAL CONSTANT %token NAME RENAME NAMEWARN EXTEND PRAGMA FEATURE VARARGS %token ENUM -%token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT +%token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT AUTO %token STATIC_ASSERT CONSTEXPR THREAD_LOCAL /* C++0x keywords */ %token USING %token NAMESPACE @@ -1509,6 +1509,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %token OPERATOR %token COPERATOR %token PARSETYPE PARSEPARM PARSEPARMS +%token TEST1 TEST2 TEST3 %left CAST %left QUESTIONMARK @@ -1535,11 +1536,11 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type types_directive template_directive warn_directive ; /* C declarations */ -%type c_declaration c_decl c_decl_tail c_enum_keyword c_enum_inherit c_enum_decl c_enum_forward_decl c_constructor_decl c_rettype ; +%type c_declaration c_decl c_decl_tail c_enum_keyword c_enum_inherit c_enum_decl c_enum_forward_decl c_constructor_decl ; %type enumlist edecl; /* C++ declarations */ -%type cpp_declaration cpp_class_decl cpp_forward_class_decl cpp_template_decl; +%type cpp_declaration cpp_class_decl cpp_forward_class_decl cpp_template_decl cpp_alternate_rettype; %type cpp_members cpp_member; %type cpp_constructor_decl cpp_destructor_decl cpp_protection_decl cpp_conversion_operator cpp_static_assert; %type cpp_swig_directive cpp_temp_possible cpp_nested cpp_opt_declarators ; @@ -1556,7 +1557,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type

templateparameter ; %type templcpptype cpptype access_specifier; %type base_specifier -%type type rawtype type_right ; +%type type rawtype type_right anon_bitfield_type ; %type base_list inherit raw_inherit; %type definetype def_args etype; %type expr exprnum exprcompound valexpr; @@ -2940,25 +2941,25 @@ c_declaration : c_decl { A C global declaration of some kind (may be variable, function, typedef, etc.) ------------------------------------------------------------ */ -c_decl : storage_class type declarator c_rettype initializer c_decl_tail { +c_decl : storage_class type declarator initializer c_decl_tail { $$ = new_node("cdecl"); - if ($5.qualifier) SwigType_push($3.type,$5.qualifier); + if ($4.qualifier) SwigType_push($3.type,$4.qualifier); Setattr($$,"type",$2); Setattr($$,"storage",$1); Setattr($$,"name",$3.id); Setattr($$,"decl",$3.type); Setattr($$,"parms",$3.parms); - Setattr($$,"value",$5.val); - Setattr($$,"throws",$5.throws); - Setattr($$,"throw",$5.throwf); - if (!$6) { + Setattr($$,"value",$4.val); + Setattr($$,"throws",$4.throws); + Setattr($$,"throw",$4.throwf); + if (!$5) { if (Len(scanner_ccode)) { String *code = Copy(scanner_ccode); Setattr($$,"code",code); Delete(code); } } else { - Node *n = $6; + Node *n = $5; /* Inherit attributes */ while (n) { String *type = Copy($2); @@ -2968,8 +2969,8 @@ c_decl : storage_class type declarator c_rettype initializer c_decl_tail { Delete(type); } } - if ($5.bitfield) { - Setattr($$,"bitfield", $5.bitfield); + if ($4.bitfield) { + Setattr($$,"bitfield", $4.bitfield); } /* Look for "::" declarations (ignored) */ @@ -2983,33 +2984,77 @@ c_decl : storage_class type declarator c_rettype initializer c_decl_tail { String *lstr = Swig_scopename_last($3.id); Setattr($$,"name",lstr); Delete(lstr); - set_nextSibling($$,$6); + set_nextSibling($$,$5); } else { Delete($$); - $$ = $6; + $$ = $5; } Delete(p); } else { Delete($$); - $$ = $6; + $$ = $5; } } else { - set_nextSibling($$,$6); + set_nextSibling($$,$5); } } + /* Alternate function syntax introduced in C++0x: + auto funcName(int x, int y) -> int; */ + | storage_class AUTO declarator ARROW cpp_alternate_rettype initializer c_decl_tail { +/* $$ = new_node("cdecl"); + if ($6.qualifier) SwigType_push($3.type,$6.qualifier); + Setattr($$,"type",$5); + Setattr($$,"storage",$1); + Setattr($$,"name",$3.id); + Setattr($$,"decl",$3.type); + Setattr($$,"parms",$3.parms); + Setattr($$,"value",$6.val); + Setattr($$,"throws",$6.throws); + Setattr($$,"throw",$6.throwf); + if (!$7) { + if (Len(scanner_ccode)) { + String *code = Copy(scanner_ccode); + Setattr($$,"code",code); + Delete(code); + } + } else { + Node *n = $7; + while (n) { + String *type = Copy($5); + Setattr(n,"type",type); + Setattr(n,"storage",$1); + n = nextSibling(n); + Delete(type); + } + } + if ($6.bitfield) { + Setattr($$,"bitfield", $6.bitfield); + } + + if (Strstr($3.id,"::")) { + String *p = Swig_scopename_prefix($3.id); + if (p) { + if ((Namespaceprefix && Strcmp(p,Namespaceprefix) == 0) || + (inclass && Strcmp(p,Classprefix) == 0)) { + String *lstr = Swig_scopename_last($3.id); + Setattr($$,"name",lstr); + Delete(lstr); + set_nextSibling($$,$7); + } else { + Delete($$); + $$ = $7; + } + Delete(p); + } else { + Delete($$); + $$ = $7; + } + } else { + set_nextSibling($$,$7); + } */ + } ; -/* Alternate function syntax: - auto funcName(int x, int y) -> int; */ - -c_rettype : ARROW type { - $$ = new_node("rettype"); - Setattr($$,"type",$2); - } - | empty { - $$ = 0; - } - ; /* Allow lists of variables and functions to be built up */ c_decl_tail : SEMI { @@ -3070,7 +3115,13 @@ initializer : def_args { } ; - +cpp_alternate_rettype : primitive_type { $$ = $1; } + | TYPE_BOOL { $$ = $1; } + | TYPE_VOID { $$ = $1; } + | TYPE_TYPEDEF template_decl { $$ = NewStringf("%s%s",$1,$2); } + | TYPE_RAW { $$ = $1; } + | idcolon { $$ = $1; } + ; /* ------------------------------------------------------------ enum @@ -4529,7 +4580,21 @@ cpp_vend : cpp_const SEMI { ; -anonymous_bitfield : storage_class type COLON expr SEMI { }; +anonymous_bitfield : storage_class anon_bitfield_type COLON expr SEMI { }; + +/* Equals type_right without the ENUM keyword and cpptype (templates etc.): */ +anon_bitfield_type : primitive_type { $$ = $1; + /* Printf(stdout,"primitive = '%s'\n", $$);*/ + } + | TYPE_BOOL { $$ = $1; } + | TYPE_VOID { $$ = $1; } + | TYPE_TYPEDEF template_decl { $$ = NewStringf("%s%s",$1,$2); } + | TYPE_RAW { $$ = $1; } + + | idcolon { + $$ = $1; + } + ; /* ====================================================================== * PRIMITIVES @@ -4815,6 +4880,7 @@ declarator : pointer notso_direct_declarator { } | LAND notso_direct_declarator { /* Introduced in C++0x, move operator && */ + /* Adds one S/R conflict */ $$ = $2; $$.type = NewStringEmpty(); SwigType_add_reference($$.type); @@ -5262,7 +5328,6 @@ type_right : primitive_type { $$ = $1; } | TYPE_BOOL { $$ = $1; } | TYPE_VOID { $$ = $1; } - | TYPE_AUTO { $$ = $1; } | TYPE_TYPEDEF template_decl { $$ = NewStringf("%s%s",$1,$2); } | c_enum_keyword idcolon { $$ = NewStringf("enum %s", $2); } | TYPE_RAW { $$ = $1; } @@ -5838,14 +5903,6 @@ templcpptype : CLASS { $$ = (char *)"typename"; if (!inherit_list) last_cpptype = $$; } - | CLASS PERIOD PERIOD PERIOD { - $$ = (char*)"class"; - if (!inherit_list) last_cpptype = $$; - } - | TYPENAME PERIOD PERIOD PERIOD { - $$ = (char *)"typename"; - if (!inherit_list) last_cpptype = $$; - } ; cpptype : templcpptype { @@ -5931,13 +5988,11 @@ ctor_initializer : COLON mem_initializer_list mem_initializer_list : mem_initializer | mem_initializer_list COMMA mem_initializer + | mem_initializer PERIOD PERIOD PERIOD + | mem_initializer_list COMMA mem_initializer PERIOD PERIOD PERIOD ; -mem_initializer : idcolon LPAREN parms RPAREN { -/* skip_balanced('(',')'); - Clear(scanner_ccode); -*/ } - | idcolon LBRACE parms RBRACE { +mem_initializer : idcolon LPAREN { skip_balanced('(',')'); Clear(scanner_ccode); } /* Uniform initialization in C++0x. Example: struct MyStruct { @@ -5946,11 +6001,7 @@ mem_initializer : idcolon LPAREN parms RPAREN { double y_; }; */ -/* skip_balanced('{','}'); - Clear(scanner_ccode); -*/ } - | idcolon LPAREN parms RPAREN PERIOD PERIOD PERIOD { } - | idcolon LBRACE parms RBRACE PERIOD PERIOD PERIOD { } + | idcolon LBRACE { skip_balanced('{','}'); Clear(scanner_ccode); } ; template_decl : LESSTHAN valparms GREATERTHAN { @@ -5980,12 +6031,12 @@ idcolon : idtemplate idcolontail { Delete($4); } | PERIOD PERIOD PERIOD idtemplate { - /* Introduced in C++0x, variadic constructor args */ + /* Introduced in C++0x, variadic constructor args or inside template<> block */ $$ = NewString($4); - } + } | idtemplate { $$ = NewString($1); - } + } | NONID DCOLON idtemplate { $$ = NewStringf("::%s",$3); } From a7e9a105d9449c6f2853a8869c13d7c5230cf660 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Fri, 31 Jul 2009 10:13:31 +0000 Subject: [PATCH 0028/1160] Enabled alternate function syntax and added runtime testcases. Added support for null pointer constant introduced in C++0x. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11484 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 13 +++++++------ .../test-suite/cpp0x_alternate_function_syntax.i | 9 +++++++-- .../test-suite/cpp0x_null_pointer_constant.i | 16 ++++++++++++++++ .../cpp0x_alternate_function_syntax_runme.py | 13 +++++++++++++ .../python/cpp0x_null_pointer_constant_runme.py | 15 +++++++++++++++ Source/CParse/parser.y | 4 ++-- 6 files changed, 60 insertions(+), 10 deletions(-) create mode 100644 Examples/test-suite/cpp0x_null_pointer_constant.i create mode 100644 Examples/test-suite/python/cpp0x_alternate_function_syntax_runme.py create mode 100644 Examples/test-suite/python/cpp0x_null_pointer_constant_runme.py diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 24dd4f6e3..1e27b54b0 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -409,13 +409,14 @@ CPP0X_TEST_CASES = \ cpp0x_function_objects \ cpp0x_strongly_typed_enumerations \ cpp0x_rvalue_reference \ - cpp0x_variadic_templates -# cpp0x_alternate_function_syntax # not fully implemented yet + cpp0x_variadic_templates \ + cpp0x_alternate_function_syntax # cpp0x_hash_types # not fully implemented yet -# cpp0x_unrestricted_unions # not supported by any compilers yet -# cpp0x_smart_pointers # not supported by standard library yet -# cpp0x_constexpr # not supported by any compilers yet -# cpp0x_thread_local # not supported by any compilers yet +# cpp0x_null_pointer_constant # not supported by any compilers yet +# cpp0x_unrestricted_unions # not supported by any compilers yet +# cpp0x_smart_pointers # not supported by standard library yet +# cpp0x_constexpr # not supported by any compilers yet +# cpp0x_thread_local # not supported by any compilers yet # Broken C++0x test cases. CPP0X_TEST_BROKEN = diff --git a/Examples/test-suite/cpp0x_alternate_function_syntax.i b/Examples/test-suite/cpp0x_alternate_function_syntax.i index ed3cb6729..b17223626 100644 --- a/Examples/test-suite/cpp0x_alternate_function_syntax.i +++ b/Examples/test-suite/cpp0x_alternate_function_syntax.i @@ -2,10 +2,15 @@ %inline %{ struct SomeStruct { - auto FuncName(int x, int y) -> int; + int addNormal(int x, int y); + auto addAlternate(int x, int y) -> int; }; -auto SomeStruct::FuncName(int x, int y) -> int { +auto SomeStruct::addAlternate(int x, int y) -> int { + return x + y; +} + +int SomeStruct::addNormal(int x, int y) { return x + y; } %} diff --git a/Examples/test-suite/cpp0x_null_pointer_constant.i b/Examples/test-suite/cpp0x_null_pointer_constant.i new file mode 100644 index 000000000..9057f04be --- /dev/null +++ b/Examples/test-suite/cpp0x_null_pointer_constant.i @@ -0,0 +1,16 @@ +/* This testcase checks whether Swig correctly treats the new nullptr_t + constant introduced in C++0x. +*/ + +%module cpp0x_null_pointer_constant + +%inline %{ +#include + +class A { +public: + A() : _myA(std::nullptr) { } + + A *_myA; +}; +%} diff --git a/Examples/test-suite/python/cpp0x_alternate_function_syntax_runme.py b/Examples/test-suite/python/cpp0x_alternate_function_syntax_runme.py new file mode 100644 index 000000000..8005cfab7 --- /dev/null +++ b/Examples/test-suite/python/cpp0x_alternate_function_syntax_runme.py @@ -0,0 +1,13 @@ +import cpp0x_alternate_function_syntax + +a = cpp0x_alternate_function_syntax.SomeStruct() + +res = a.addNormal(4,5) +if res != 9: + raise RuntimeError, ("SomeStruct::addNormal(4,5) returns ", res, " should be 9.") + + +res = a.addAlternate(4,5) +if res != 9: + raise RuntimeError, ("SomeStruct::addAlternate(4,5) returns ", res, " should be 9.") + diff --git a/Examples/test-suite/python/cpp0x_null_pointer_constant_runme.py b/Examples/test-suite/python/cpp0x_null_pointer_constant_runme.py new file mode 100644 index 000000000..b80dcaf2f --- /dev/null +++ b/Examples/test-suite/python/cpp0x_null_pointer_constant_runme.py @@ -0,0 +1,15 @@ +import cpp0x_null_pointer_constant + +a = cpp0x_null_pointer_constant.A() + +if a._myA != None: + raise RuntimeError, ("cpp0x_null_pointer_constant: _myA should be None, but is ", a._myA) + +b = cpp0x_null_pointer_constant.A() +if a._myA != b._myA: + raise RuntimeError, ("cpp0x_null_pointer_constant: a._myA should be the same as b._myA, but ", a._myA, "!=", b._myA) + +a._myA = cpp0x_null_pointer_constant.A() +if a._myA == None: + raise RuntimeError, ("cpp0x_null_pointer_constant: _myA should be object, but is None") + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index c8e7e284d..f3a73f38a 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3001,7 +3001,7 @@ c_decl : storage_class type declarator initializer c_decl_tail { /* Alternate function syntax introduced in C++0x: auto funcName(int x, int y) -> int; */ | storage_class AUTO declarator ARROW cpp_alternate_rettype initializer c_decl_tail { -/* $$ = new_node("cdecl"); + $$ = new_node("cdecl"); if ($6.qualifier) SwigType_push($3.type,$6.qualifier); Setattr($$,"type",$5); Setattr($$,"storage",$1); @@ -3051,7 +3051,7 @@ c_decl : storage_class type declarator initializer c_decl_tail { } } else { set_nextSibling($$,$7); - } */ + } } ; From 24402abf7d174d0e126fbdd8808afe1973a5bd83 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Sat, 1 Aug 2009 22:00:36 +0000 Subject: [PATCH 0029/1160] Enabled support for variadic %template directive. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11487 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/cpp0x_variadic_templates.i | 10 +- Source/CParse/parser.y | 118 ++++++++++++++++-- 2 files changed, 116 insertions(+), 12 deletions(-) diff --git a/Examples/test-suite/cpp0x_variadic_templates.i b/Examples/test-suite/cpp0x_variadic_templates.i index 090645966..6317b1340 100644 --- a/Examples/test-suite/cpp0x_variadic_templates.i +++ b/Examples/test-suite/cpp0x_variadic_templates.i @@ -22,19 +22,19 @@ class MultiArgs, std::map>> %} // TODO -//%template (MultiArgs) MultiArgs, std::map>>; +%template (MultiArgs1) MultiArgs, std::map>>; //////////////////////// // Variadic sizeof... // //////////////////////// %inline %{ -template struct SizeOf { +template struct SizeOf { static const int size = sizeof...(Args); }; %} // TODO -//%template (SizeOf) SizeOf; +%template (SizeOf1) SizeOf; ////////////////////////// // Variadic inheritance // @@ -59,9 +59,9 @@ public: template class MultiInherit : public BaseClasses... { public: - MultiInherit(BaseClasses&&... baseClasses) : BaseClasses(baseClasses)... {} + MultiInherit(BaseClasses&... baseClasses) : BaseClasses(baseClasses)... {} }; %} // TODO -//%template (MultiInherit) MultiInherit; +%template (MultiInherit1) MultiInherit; diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index f3a73f38a..000958387 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2621,6 +2621,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va Node *tnode = 0; Symtab *tscope = 0; int specialized = 0; + int variadic = 0; $$ = 0; @@ -2678,11 +2679,13 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va Parm *tparms = Getattr(nn,"templateparms"); if (!tparms) { specialized = 1; + } else if (Getattr(tparms,"variadic") && strncmp(Char(Getattr(tparms,"variadic")), "1", 1)==0) { + variadic = 1; } - if (nnisclass && !specialized && ((ParmList_len($7) > ParmList_len(tparms)))) { + if (nnisclass && !variadic && !specialized && (ParmList_len($7) > ParmList_len(tparms))) { Swig_error(cparse_file, cparse_line, "Too many template parameters. Maximum of %d.\n", ParmList_len(tparms)); - } else if (nnisclass && !specialized && ((ParmList_len($7) < ParmList_numrequired(tparms)))) { - Swig_error(cparse_file, cparse_line, "Not enough template parameters specified. %d required.\n", ParmList_numrequired(tparms)); + } else if (nnisclass && !specialized && ((ParmList_len($7) < (ParmList_numrequired(tparms) - (variadic?1:0))))) { /* Variadic parameter is optional */ + Swig_error(cparse_file, cparse_line, "Not enough template parameters specified. %d required.\n", (ParmList_numrequired(tparms)-(variadic?1:0)) ); } else if (!nnisclass && ((ParmList_len($7) != ParmList_len(tparms)))) { /* must be an overloaded templated method - ignore it as it is overloaded with a different number of template parameters */ nn = Getattr(nn,"sym:nextSibling"); /* repeat for overloaded templated functions */ @@ -2741,6 +2744,9 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va if (!p && tp) { p = tp; def_supplied = 1; + } else if (!tp) { /* Variadic tempalte - tp < p */ + Swig_warning(0,cparse_file, cparse_line,"Variadic templates not fully supported by Swig.\n"); + break; } } @@ -3994,6 +4000,12 @@ template_parms : templateparameters { if ((strncmp(type,"class ",6) == 0) || (strncmp(type,"typename ", 9) == 0)) { char *t = strchr(type,' '); Setattr(p,"name", t+1); + } else + /* Variadic template args */ + if ((strncmp(type,"class... ",9) == 0) || (strncmp(type,"typename... ", 12) == 0)) { + char *t = strchr(type,' '); + Setattr(p,"name", t+1); + Setattr(p,"variadic", "1"); } else { /* Swig_error(cparse_file, cparse_line, "Missing template parameter name\n"); @@ -4933,6 +4945,94 @@ declarator : pointer notso_direct_declarator { } $$.type = t; } + + /* Variadic versions eg. MyClasses&... myIds */ + + | pointer PERIOD PERIOD PERIOD notso_direct_declarator { + $$ = $5; + if ($$.type) { + SwigType_push($1,$$.type); + Delete($$.type); + } + $$.type = $1; + } + | pointer AND PERIOD PERIOD PERIOD notso_direct_declarator { + $$ = $6; + SwigType_add_reference($1); + if ($$.type) { + SwigType_push($1,$$.type); + Delete($$.type); + } + $$.type = $1; + } + | PERIOD PERIOD PERIOD direct_declarator { + $$ = $4; + if (!$$.type) $$.type = NewStringEmpty(); + } + | AND PERIOD PERIOD PERIOD notso_direct_declarator { + $$ = $5; + $$.type = NewStringEmpty(); + SwigType_add_reference($$.type); + if ($5.type) { + SwigType_push($$.type,$5.type); + Delete($5.type); + } + } + | LAND PERIOD PERIOD PERIOD notso_direct_declarator { + /* Introduced in C++0x, move operator && */ + /* Adds one S/R conflict */ + $$ = $5; + $$.type = NewStringEmpty(); + SwigType_add_reference($$.type); + if ($5.type) { + SwigType_push($$.type,$5.type); + Delete($5.type); + } + } + | idcolon DSTAR PERIOD PERIOD PERIOD notso_direct_declarator { + SwigType *t = NewStringEmpty(); + + $$ = $6; + SwigType_add_memberpointer(t,$1); + if ($$.type) { + SwigType_push(t,$$.type); + Delete($$.type); + } + $$.type = t; + } + | pointer idcolon DSTAR PERIOD PERIOD PERIOD notso_direct_declarator { + SwigType *t = NewStringEmpty(); + $$ = $7; + SwigType_add_memberpointer(t,$2); + SwigType_push($1,t); + if ($$.type) { + SwigType_push($1,$$.type); + Delete($$.type); + } + $$.type = $1; + Delete(t); + } + | pointer idcolon DSTAR AND PERIOD PERIOD PERIOD notso_direct_declarator { + $$ = $8; + SwigType_add_memberpointer($1,$2); + SwigType_add_reference($1); + if ($$.type) { + SwigType_push($1,$$.type); + Delete($$.type); + } + $$.type = $1; + } + | idcolon DSTAR AND PERIOD PERIOD PERIOD notso_direct_declarator { + SwigType *t = NewStringEmpty(); + $$ = $7; + SwigType_add_memberpointer(t,$1); + SwigType_add_reference(t); + if ($$.type) { + SwigType_push(t,$$.type); + Delete($$.type); + } + $$.type = t; + } ; notso_direct_declarator : idcolon { @@ -5903,6 +6003,14 @@ templcpptype : CLASS { $$ = (char *)"typename"; if (!inherit_list) last_cpptype = $$; } + | CLASS PERIOD PERIOD PERIOD { + $$ = (char *)"class..."; + if (!inherit_list) last_cpptype = $$; + } + | TYPENAME PERIOD PERIOD PERIOD { + $$ = (char *)"typename..."; + if (!inherit_list) last_cpptype = $$; + } ; cpptype : templcpptype { @@ -6030,10 +6138,6 @@ idcolon : idtemplate idcolontail { $$ = NewStringf("::%s%s",$3,$4); Delete($4); } - | PERIOD PERIOD PERIOD idtemplate { - /* Introduced in C++0x, variadic constructor args or inside template<> block */ - $$ = NewString($4); - } | idtemplate { $$ = NewString($1); } From 1993f926246f8e00e8fda5842f2a5f112302dbfc Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Sat, 1 Aug 2009 22:31:38 +0000 Subject: [PATCH 0030/1160] Fixed variadic template argument warning. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11488 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/CParse/parser.y | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 000958387..01ed40350 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2744,8 +2744,8 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va if (!p && tp) { p = tp; def_supplied = 1; - } else if (!tp) { /* Variadic tempalte - tp < p */ - Swig_warning(0,cparse_file, cparse_line,"Variadic templates not fully supported by Swig.\n"); + } else if (p && !tp) { /* Variadic template - tp < p */ + Swig_warning(0,cparse_file, cparse_line,"Only the first variadic argument is currently supported by Swig.\n"); break; } } From ba2c8cff409890fa38aec7d0f4b4fa2e82a167bf Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Mon, 3 Aug 2009 15:03:41 +0000 Subject: [PATCH 0031/1160] Added syntax for lambda expressions and closures introduced in C++0x. Added testcase cpp0x_lambda_functions.i. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11491 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 1 + Examples/test-suite/cpp0x_lambda_functions.i | 34 ++++++++++++++++++++ Source/CParse/parser.y | 14 +++++++- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/cpp0x_lambda_functions.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 1e27b54b0..22bf646c3 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -412,6 +412,7 @@ CPP0X_TEST_CASES = \ cpp0x_variadic_templates \ cpp0x_alternate_function_syntax # cpp0x_hash_types # not fully implemented yet +# cpp0x_lambda_functions # not supported by GCC or MSVC yet # cpp0x_null_pointer_constant # not supported by any compilers yet # cpp0x_unrestricted_unions # not supported by any compilers yet # cpp0x_smart_pointers # not supported by standard library yet diff --git a/Examples/test-suite/cpp0x_lambda_functions.i b/Examples/test-suite/cpp0x_lambda_functions.i new file mode 100644 index 000000000..7719b59f4 --- /dev/null +++ b/Examples/test-suite/cpp0x_lambda_functions.i @@ -0,0 +1,34 @@ +/* This testcase checks whether Swig correctly parses the lambda expressions + and closure syntax introduced in C++0x. + Swig supports only lambda syntax and doesn't produce any wrapper code for + this. +*/ +%module cpp0x_lambda_functions + +%inline %{ +struct A { + /* Defined lambda function with return value. */ + auto lambda1 = [](int x, int y) -> int { return x+y; }; + + /* Defined lambda function without return value. + Return value is calculated by compiler, if the function contains a + single statement "return expr;". */ + auto lambda2 = [](int x, int y) { return x+y; }; +}; + +int runLambda1() { + A myA; + return myA.lambda1(5,6); +} + +int runLambda2() { + A myA; + return myA.lambda2(5,6); +} + +/* Inline defined lambda function. */ +int runLambda3() { + auto myLambda = [](int x, int y) { return x+y; }; + return myLambda(5,6); +} +%} diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 01ed40350..6335b03f9 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1536,7 +1536,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type types_directive template_directive warn_directive ; /* C declarations */ -%type c_declaration c_decl c_decl_tail c_enum_keyword c_enum_inherit c_enum_decl c_enum_forward_decl c_constructor_decl ; +%type c_declaration c_decl c_decl_tail c_enum_keyword c_enum_inherit c_enum_decl c_enum_forward_decl c_constructor_decl c_lambda_decl c_lambda_decl_front ; %type enumlist edecl; /* C++ declarations */ @@ -2941,6 +2941,7 @@ c_declaration : c_decl { appendChild($$,firstChild($5)); } } + | c_lambda_decl { Swig_warning("Swig doesn't produce wrapper code for lambda expressions and closures yet.") $$ = $1; } ; /* ------------------------------------------------------------ @@ -3129,6 +3130,17 @@ cpp_alternate_rettype : primitive_type { $$ = $1; } | idcolon { $$ = $1; } ; +/* Lambda function syntax introduced in C++0x. + auto myFunc = [](int x, int y) -> int { return x+y; } + OR + auto myFunc = [](int x, int y) { return x+y; } +*/ +c_lambda_decl : c_lambda_decl_front LPAREN parms RPAREN LBRACE { skip_balanced('{','}'); } SEMI { $$ = 0; } + | c_lambda_decl_front LPAREN parms RPAREN ARROW type LBRACE { skip_balanced('{','}'); } SEMI { $$ = 0; } + +c_lambda_decl_front : storage_class AUTO idcolon EQUAL LBRACKET { skip_balanced('[',']'); $$ = 0; } + + /* ------------------------------------------------------------ enum or From c2f9904abe59fb0e08685dca555e4e1d6591bfc1 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Mon, 3 Aug 2009 15:42:54 +0000 Subject: [PATCH 0032/1160] Fixed compilation error. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11492 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 6335b03f9..29d821ea5 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2941,7 +2941,7 @@ c_declaration : c_decl { appendChild($$,firstChild($5)); } } - | c_lambda_decl { Swig_warning("Swig doesn't produce wrapper code for lambda expressions and closures yet.") $$ = $1; } + | c_lambda_decl { Swig_warning(WARN_LANG_NATIVE_UNIMPL, cparse_file, cparse_line,"Swig doesn't produce wrapper code for lambda expressions and closures yet.\n"); $$ = $1; } ; /* ------------------------------------------------------------ From 8a4efbc6d35134ed4aed1a622ef8183e44580155 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Tue, 4 Aug 2009 00:51:21 +0000 Subject: [PATCH 0033/1160] Added support for user-defined string literals. Added testcase cpp0x_userdefined_literals.i git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11494 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 ++- .../test-suite/cpp0x_userdefined_literals.i | 24 +++++++++++++++++++ Source/CParse/cscanner.c | 5 ++++ Source/CParse/parser.y | 23 +++++++++++++++++- 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/cpp0x_userdefined_literals.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 22bf646c3..1001b8ac8 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -410,7 +410,8 @@ CPP0X_TEST_CASES = \ cpp0x_strongly_typed_enumerations \ cpp0x_rvalue_reference \ cpp0x_variadic_templates \ - cpp0x_alternate_function_syntax + cpp0x_alternate_function_syntax \ + cpp0x_userdefined_literals # cpp0x_hash_types # not fully implemented yet # cpp0x_lambda_functions # not supported by GCC or MSVC yet # cpp0x_null_pointer_constant # not supported by any compilers yet diff --git a/Examples/test-suite/cpp0x_userdefined_literals.i b/Examples/test-suite/cpp0x_userdefined_literals.i new file mode 100644 index 000000000..f41823488 --- /dev/null +++ b/Examples/test-suite/cpp0x_userdefined_literals.i @@ -0,0 +1,24 @@ +/* This testcase checks whether Swig correctly parses the user-defined literals + for the string introduced in C++0x. */ +%module cpp0x_userdefined_literals + +%inline %{ +#include + +struct OutputType { + int val; + + OutputType(int v) { v=val; } +}; + +struct TT { +OutputType operator << (const char * string_values, size_t num_chars) { return OutputType(100); } +OutputType operator "" (const char * string_values, size_t num_chars) { return OutputType(100); } +OutputType operator "" _mySuffix1(const char * string_values, size_t num_chars) { return OutputType(100); } +OutputType operator "" _mySuffix2(const wchar_t * string_values, size_t num_chars) { return OutputType(200); } +OutputType operator "" _mySuffix3(const char16_t * string_values, size_t num_chars) { return OutputType(300); } +OutputType operator "" _mySuffix4(const char32_t * string_values, size_t num_chars) { return OutputType(400); } +OutputType operator "" _mySuffix5(int value) /* cooked version - ie. atoi() of string */ { return OutputType(500); } +}; + +%} diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index f923bc3b6..369c962e9 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -688,6 +688,11 @@ int yylex(void) { yylval.str = s; return OPERATOR; } + } else if (nexttok == SWIG_TOKEN_STRING) { + /* Operator "" or user-defined string literal ""_suffix */ + Append(s,"\"\""); + yylval.str = s; + return OPERATOR; } else if (nexttok == SWIG_TOKEN_ID) { /* We have an identifier. This could be any number of things. It could be a named version of an operator (e.g., 'and_eq') or it could be a conversion operator. To deal with this, we're diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 29d821ea5..b164690e1 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -5145,7 +5145,7 @@ direct_declarator : idcolon { $$.parms = 0; $$.have_parms = 0; } - + | NOT idcolon { $$.id = Char(NewStringf("~%s",$2)); $$.type = 0; @@ -5227,6 +5227,27 @@ direct_declarator : idcolon { Delete($$.type); $$.type = t; } + } + /* User-defined string literals. eg. + int operator""_mySuffix(const char* val, int length) {...} */ + /* This produces one S/R conflict. */ + | OPERATOR ID LPAREN parms RPAREN { + SwigType *t; + Append($1, Char($2)); + $$.id = Char($1); + t = NewStringEmpty(); + SwigType_add_function(t,$4); + if (!$$.have_parms) { + $$.parms = $4; + $$.have_parms = 1; + } + if (!$$.type) { + $$.type = t; + } else { + SwigType_push(t, $$.type); + Delete($$.type); + $$.type = t; + } } ; From e2e9b04b3d80de377a6accf2cdb761ce2d8cb4d0 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Mon, 10 Aug 2009 10:46:07 +0000 Subject: [PATCH 0034/1160] Added initial support for C++0x decltype(). Added testcase cpp0x_decltype. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11525 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 ++- Examples/test-suite/cpp0x_decltype.i | 19 +++++++++++++++++++ .../test-suite/python/cpp0x_decltype_runme.py | 19 +++++++++++++++++++ Source/CParse/cscanner.c | 2 ++ Source/CParse/parser.y | 18 ++++++++++++++++-- 5 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 Examples/test-suite/cpp0x_decltype.i create mode 100644 Examples/test-suite/python/cpp0x_decltype_runme.py diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 1001b8ac8..d8fb30936 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -411,7 +411,8 @@ CPP0X_TEST_CASES = \ cpp0x_rvalue_reference \ cpp0x_variadic_templates \ cpp0x_alternate_function_syntax \ - cpp0x_userdefined_literals + cpp0x_userdefined_literals \ + cpp0x_decltype # cpp0x_hash_types # not fully implemented yet # cpp0x_lambda_functions # not supported by GCC or MSVC yet # cpp0x_null_pointer_constant # not supported by any compilers yet diff --git a/Examples/test-suite/cpp0x_decltype.i b/Examples/test-suite/cpp0x_decltype.i new file mode 100644 index 000000000..316c38962 --- /dev/null +++ b/Examples/test-suite/cpp0x_decltype.i @@ -0,0 +1,19 @@ +/* This testcase checks whether Swig correctly uses the new 'decltype()' + introduced in C++0x. +*/ +%module cpp0x_decltype + +%inline %{ +class A { +public: + int i; + decltype(i) j; + + auto foo( decltype(i) a ) -> decltype(i) { + if (a==5) + return 10; + else + return 0; + } +}; +%} diff --git a/Examples/test-suite/python/cpp0x_decltype_runme.py b/Examples/test-suite/python/cpp0x_decltype_runme.py new file mode 100644 index 000000000..ce742e6b2 --- /dev/null +++ b/Examples/test-suite/python/cpp0x_decltype_runme.py @@ -0,0 +1,19 @@ +import cpp0x_decltype + +a = cpp0x_decltype.A() +a.i = 5 +if a.i != 5: + raise RuntimeError, "Assignment to a.i failed." + +a.j = 10 +if a.j != 10: + raise RuntimeError, "Assignment to a.j failed." + +b = a.foo(5) +if b != 10: + raise RuntimeError, "foo(5) should return 10." + +b = a.foo(6) +if b != 0: + raise RuntimeError, "foo(6) should return 0." + diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index 369c962e9..626958169 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -636,6 +636,8 @@ int yylex(void) { return (CONSTEXPR); if (strcmp(yytext, "thread_local") == 0) return (THREAD_LOCAL); + if (strcmp(yytext, "decltype") == 0) + return (DECLTYPE); if (strcmp(yytext, "virtual") == 0) return (VIRTUAL); if (strcmp(yytext, "static_assert") == 0) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index b164690e1..2392e7705 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1493,7 +1493,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %token NAME RENAME NAMEWARN EXTEND PRAGMA FEATURE VARARGS %token ENUM %token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT AUTO -%token STATIC_ASSERT CONSTEXPR THREAD_LOCAL /* C++0x keywords */ +%token STATIC_ASSERT CONSTEXPR THREAD_LOCAL DECLTYPE /* C++0x keywords */ %token USING %token NAMESPACE %token NATIVE INLINE @@ -1557,7 +1557,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type

templateparameter ; %type templcpptype cpptype access_specifier; %type base_specifier -%type type rawtype type_right anon_bitfield_type ; +%type type rawtype type_right anon_bitfield_type decltype ; %type base_list inherit raw_inherit; %type definetype def_args etype; %type expr exprnum exprcompound valexpr; @@ -3128,6 +3128,7 @@ cpp_alternate_rettype : primitive_type { $$ = $1; } | TYPE_TYPEDEF template_decl { $$ = NewStringf("%s%s",$1,$2); } | TYPE_RAW { $$ = $1; } | idcolon { $$ = $1; } + | decltype { $$ = $1; } ; /* Lambda function syntax introduced in C++0x. @@ -5471,6 +5472,19 @@ type_right : primitive_type { $$ = $1; | cpptype idcolon { $$ = NewStringf("%s %s", $1, $2); } + | decltype { + $$ = $1; + } + ; + +decltype : DECLTYPE LPAREN idcolon RPAREN { + Node *n = Swig_symbol_clookup($3,0); + if (!n) { + Swig_error(cparse_file, cparse_line, "Identifier %s not defined.\n", $3); + } else { + $$ = Getattr(n, "type"); + } + } ; primitive_type : primitive_type_list { From 41a565dd5f73d9f45b5619f0939f3c208c74240f Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Tue, 11 Aug 2009 15:20:38 +0000 Subject: [PATCH 0035/1160] Added testcase cpp0x_constructors for delegating constructors and constructor inheritance. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11532 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 11 +++++---- Examples/test-suite/cpp0x_constructors.i | 30 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 Examples/test-suite/cpp0x_constructors.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index d8fb30936..b29b65162 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -413,13 +413,14 @@ CPP0X_TEST_CASES = \ cpp0x_alternate_function_syntax \ cpp0x_userdefined_literals \ cpp0x_decltype -# cpp0x_hash_types # not fully implemented yet +# cpp0x_hash_types # not fully implemented yet +# cpp0x_constructors # not supported by any compiler yet # cpp0x_lambda_functions # not supported by GCC or MSVC yet -# cpp0x_null_pointer_constant # not supported by any compilers yet -# cpp0x_unrestricted_unions # not supported by any compilers yet +# cpp0x_null_pointer_constant # not supported by any compiler yet +# cpp0x_unrestricted_unions # not supported by any compiler yet # cpp0x_smart_pointers # not supported by standard library yet -# cpp0x_constexpr # not supported by any compilers yet -# cpp0x_thread_local # not supported by any compilers yet +# cpp0x_constexpr # not supported by any compiler yet +# cpp0x_thread_local # not supported by any compiler yet # Broken C++0x test cases. CPP0X_TEST_BROKEN = diff --git a/Examples/test-suite/cpp0x_constructors.i b/Examples/test-suite/cpp0x_constructors.i new file mode 100644 index 000000000..47f030a95 --- /dev/null +++ b/Examples/test-suite/cpp0x_constructors.i @@ -0,0 +1,30 @@ +/* This test checks whether Swig correctly parses the new delegating + constructors and constructor inheritance. +*/ +%module cpp0x_constructors + +%inline %{ +class BaseClass { +private: + int _val; +public: + BaseClass(int iValue) { _val = iValue; } +}; + +class DerivedClass: public BaseClass { +public: + using BaseClass::BaseClass; // Adds DerivedClass(int) constructor +}; + +class A { +public: + int a; + int b; + int c; + + A() : A( 10 ) {} + A(int aa) : A(aa, 20) {} + A(int aa, int bb) : A(aa, bb, 30) {} + A(int aa, int bb, int cc) { a=aa; b=bb; c=cc; } +}; +%} From 65c09323fcf12fa02f7426e49116ba392df6c43f Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Tue, 11 Aug 2009 18:27:33 +0000 Subject: [PATCH 0036/1160] Added syntax support for template aliasing and new 'using' syntax for typedefs introduced in C++0x. Added testcase cpp0x_template_typedefs. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11533 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 1 + Examples/test-suite/cpp0x_template_typedefs.i | 18 ++++++++++++++++++ Source/CParse/parser.y | 2 ++ 3 files changed, 21 insertions(+) create mode 100644 Examples/test-suite/cpp0x_template_typedefs.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index b29b65162..aa569bdea 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -413,6 +413,7 @@ CPP0X_TEST_CASES = \ cpp0x_alternate_function_syntax \ cpp0x_userdefined_literals \ cpp0x_decltype +# cpp0x_template_typedefs # not supported by any compiler yet # cpp0x_hash_types # not fully implemented yet # cpp0x_constructors # not supported by any compiler yet # cpp0x_lambda_functions # not supported by GCC or MSVC yet diff --git a/Examples/test-suite/cpp0x_template_typedefs.i b/Examples/test-suite/cpp0x_template_typedefs.i new file mode 100644 index 000000000..3164b86ae --- /dev/null +++ b/Examples/test-suite/cpp0x_template_typedefs.i @@ -0,0 +1,18 @@ +/* This testcase checks whether Swig correctly parses the template aliasing. */ +%module cpp0x_template_typedefs + +%inline %{ +template< typename T1, typename T2, int > +class SomeType { + T1 a; + T2 b; + int c; +}; + +template< typename T2 > +using TypedefName = SomeType; + +typedef void (*PFD)(double); // Old style +using PF = void (*)(double); // New introduced syntax +%} + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 2392e7705..25731ee35 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2942,6 +2942,8 @@ c_declaration : c_decl { } } | c_lambda_decl { Swig_warning(WARN_LANG_NATIVE_UNIMPL, cparse_file, cparse_line,"Swig doesn't produce wrapper code for lambda expressions and closures yet.\n"); $$ = $1; } + | USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_LANG_NATIVE_UNIMPL, cparse_file, cparse_line,"Swig doesn't support 'using' typedefs yet.\n"); $$ = 0; } + | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_LANG_NATIVE_UNIMPL, cparse_file, cparse_line,"Swig doesn't support template aliasing yet.\n"); $$ = 0; } ; /* ------------------------------------------------------------ From 2f3a18e49b04bed6f25b9cf7ae6ca7228519df6c Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Tue, 11 Aug 2009 19:44:03 +0000 Subject: [PATCH 0037/1160] Added cpp0x_result_of testcase. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11534 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 ++- Examples/test-suite/cpp0x_result_of.i | 19 +++++++++++++++++++ .../python/cpp0x_result_of_runme.py | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/cpp0x_result_of.i create mode 100644 Examples/test-suite/python/cpp0x_result_of_runme.py diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index aa569bdea..8415197f4 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -412,7 +412,8 @@ CPP0X_TEST_CASES = \ cpp0x_variadic_templates \ cpp0x_alternate_function_syntax \ cpp0x_userdefined_literals \ - cpp0x_decltype + cpp0x_decltype \ + cpp0x_result_of # cpp0x_template_typedefs # not supported by any compiler yet # cpp0x_hash_types # not fully implemented yet # cpp0x_constructors # not supported by any compiler yet diff --git a/Examples/test-suite/cpp0x_result_of.i b/Examples/test-suite/cpp0x_result_of.i new file mode 100644 index 000000000..fb8586ba7 --- /dev/null +++ b/Examples/test-suite/cpp0x_result_of.i @@ -0,0 +1,19 @@ +/* This testcase checks whether Swig correctly uses the new result_of class + and its templating capabilities introduced in C++0x. */ +%module cpp0x_result_of + +%inline %{ +#include +#include + +double square(double x) { + return (x * x); +} + +template +typename std::result_of::type test_result_impl(Fun fun, Arg arg) { + return fun(arg); +} +%} + +%template(test_result) test_result_impl; diff --git a/Examples/test-suite/python/cpp0x_result_of_runme.py b/Examples/test-suite/python/cpp0x_result_of_runme.py new file mode 100644 index 000000000..5411cd1ce --- /dev/null +++ b/Examples/test-suite/python/cpp0x_result_of_runme.py @@ -0,0 +1,3 @@ +import cpp0x_result_of +if cpp0x_result_of.test_result(cpp0x_result_of.square, 3.0) != 9.0: + raise RuntimeError, "test_result(square, 3.0) is not 9.0." From 955c736164cadd0ec5a0482c2bf26712708e8d22 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Tue, 11 Aug 2009 20:06:23 +0000 Subject: [PATCH 0038/1160] Added testcase for default/delete arguments introduced in C++0x. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11535 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 ++- Examples/test-suite/cpp0x_default_delete.i | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/cpp0x_default_delete.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 8415197f4..bfc1a4cb9 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -413,7 +413,8 @@ CPP0X_TEST_CASES = \ cpp0x_alternate_function_syntax \ cpp0x_userdefined_literals \ cpp0x_decltype \ - cpp0x_result_of + cpp0x_result_of \ + cpp0x_default_delete # cpp0x_template_typedefs # not supported by any compiler yet # cpp0x_hash_types # not fully implemented yet # cpp0x_constructors # not supported by any compiler yet diff --git a/Examples/test-suite/cpp0x_default_delete.i b/Examples/test-suite/cpp0x_default_delete.i new file mode 100644 index 000000000..2e2108494 --- /dev/null +++ b/Examples/test-suite/cpp0x_default_delete.i @@ -0,0 +1,22 @@ +%module cpp0x_default_delete + +%{ +#include + +class NonCopyable { +public: + NonCopyable & operator=(const NonCopyable&) = delete; /* Removes operator= */ + NonCopyable(const NonCopyable&) = delete; /* Removed copy constructor */ + NonCopyable() = default; /* Explicitly allows the empty constructor */ + void *operator new(size_t) = delete; /* Removes new NonCopyable */ +}; + +struct A1 { + void f(int i); + void f(double i) = delete; /* Don't cast double to int. Compiler returns an error */ +}; +struct A2 { + void f(int i); + template void f(T) = delete; /* Only accept int */ +}; +%} From bc8f86b6ec1b144147a74afe236002600250d687 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Wed, 12 Aug 2009 10:18:18 +0000 Subject: [PATCH 0039/1160] Fixed cpp0x_result_of testcase. Added testcase cpp0x_sizeof_object. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11538 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 ++- Examples/test-suite/cpp0x_result_of.i | 1 + Examples/test-suite/cpp0x_sizeof_object.i | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/cpp0x_sizeof_object.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index bfc1a4cb9..268296f3c 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -414,7 +414,8 @@ CPP0X_TEST_CASES = \ cpp0x_userdefined_literals \ cpp0x_decltype \ cpp0x_result_of \ - cpp0x_default_delete + cpp0x_default_delete \ + cpp0x_sizeof_object # cpp0x_template_typedefs # not supported by any compiler yet # cpp0x_hash_types # not fully implemented yet # cpp0x_constructors # not supported by any compiler yet diff --git a/Examples/test-suite/cpp0x_result_of.i b/Examples/test-suite/cpp0x_result_of.i index fb8586ba7..4def13a38 100644 --- a/Examples/test-suite/cpp0x_result_of.i +++ b/Examples/test-suite/cpp0x_result_of.i @@ -17,3 +17,4 @@ typename std::result_of::type test_result_impl(Fun fun, Arg arg) { %} %template(test_result) test_result_impl; +%constant double (*SQUARE)(double) = square; diff --git a/Examples/test-suite/cpp0x_sizeof_object.i b/Examples/test-suite/cpp0x_sizeof_object.i new file mode 100644 index 000000000..89e659e81 --- /dev/null +++ b/Examples/test-suite/cpp0x_sizeof_object.i @@ -0,0 +1,17 @@ +/* This testcase checks whether Swig correctly uses the sizeof() on the + concrete objects and not only types introduced in C++0x. */ +%module cpp0x_sizeof_object + +%inline %{ +struct B { + unsigned long member1; + long long member2; + char member3; +}; + +struct A { + B member; +}; + +const int a = sizeof(A::member); +%} From dccbc68c70e43b3af063777cd0d3cf87d5770df7 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Wed, 12 Aug 2009 16:50:17 +0000 Subject: [PATCH 0040/1160] Added warning for initializer_list introduced in C++0x. Added testcase cpp0x_initializer_list. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11540 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 +- Examples/test-suite/cpp0x_initializer_list.i | 13 +++++++ Source/CParse/parser.y | 36 ++++++++++++-------- Source/Include/swigwarn.h | 1 + 4 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 Examples/test-suite/cpp0x_initializer_list.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 268296f3c..992406535 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -415,7 +415,8 @@ CPP0X_TEST_CASES = \ cpp0x_decltype \ cpp0x_result_of \ cpp0x_default_delete \ - cpp0x_sizeof_object + cpp0x_sizeof_object \ + cpp0x_initializer_list # cpp0x_template_typedefs # not supported by any compiler yet # cpp0x_hash_types # not fully implemented yet # cpp0x_constructors # not supported by any compiler yet diff --git a/Examples/test-suite/cpp0x_initializer_list.i b/Examples/test-suite/cpp0x_initializer_list.i new file mode 100644 index 000000000..76bc741f5 --- /dev/null +++ b/Examples/test-suite/cpp0x_initializer_list.i @@ -0,0 +1,13 @@ +/* This testcase checks whether Swig correctly uses the new initializer_list + introduced in C++0x. */ +%module cpp0x_initializer_list + +%inline %{ +#include + +class A { +public: + A( std::initializer_list ) {} +}; +%} + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 25731ee35..e12455197 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -4265,21 +4265,27 @@ cpp_member : c_declaration { $$ = $1; } cpp_constructor_decl : storage_class type LPAREN parms RPAREN ctor_end { if (Classprefix) { - SwigType *decl = NewStringEmpty(); - $$ = new_node("constructor"); - Setattr($$,"storage",$1); - Setattr($$,"name",$2); - Setattr($$,"parms",$4); - SwigType_add_function(decl,$4); - Setattr($$,"decl",decl); - Setattr($$,"throws",$6.throws); - Setattr($$,"throw",$6.throwf); - if (Len(scanner_ccode)) { - String *code = Copy(scanner_ccode); - Setattr($$,"code",code); - Delete(code); - } - SetFlag($$,"feature:new"); + if (Getattr($4,"type") && strstr(Char(Getattr($4,"type")), "initializer_list<")) { + /* Ignore constructors containing initializer_list<> introduced in C++0x */ + Swig_warning(WARN_LANG_INITIALIZER_LIST, cparse_file, cparse_line, "Constructor with std::initializer_list<> argument ignored.\n"); + $$ = 0; + } else { + SwigType *decl = NewStringEmpty(); + $$ = new_node("constructor"); + Setattr($$,"storage",$1); + Setattr($$,"name",$2); + Setattr($$,"parms",$4); + SwigType_add_function(decl,$4); + Setattr($$,"decl",decl); + Setattr($$,"throws",$6.throws); + Setattr($$,"throw",$6.throwf); + if (Len(scanner_ccode)) { + String *code = Copy(scanner_ccode); + Setattr($$,"code",code); + Delete(code); + } + SetFlag($$,"feature:new"); + } } else { $$ = 0; } diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index e25e4408b..292aa0ba6 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -189,6 +189,7 @@ #define WARN_LANG_DIRECTOR_ABSTRACT 517 #define WARN_LANG_PORTABILITY_FILENAME 518 #define WARN_LANG_TEMPLATE_METHOD_IGNORE 519 +#define WARN_LANG_INITIALIZER_LIST 520 /* -- Reserved (600-799) -- */ From a3e59636ce3875f77483e67f0889892f7790cc86 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Fri, 14 Aug 2009 16:14:48 +0000 Subject: [PATCH 0041/1160] Added draft user documentation for the C++0x. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11568 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Cpp0x.html | 303 ++++++++++++++++++++++++++++++++++++++++++ Doc/Manual/chapters | 1 + 2 files changed, 304 insertions(+) create mode 100644 Doc/Manual/Cpp0x.html diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html new file mode 100644 index 000000000..8ecb5f52a --- /dev/null +++ b/Doc/Manual/Cpp0x.html @@ -0,0 +1,303 @@ + + + + + SWIG and C++ + + + + + + + + + + +

7 Swig and C++0x

+ + + + + + + +

This chapter gives you a brief overview about the Swig +implementation of the C++0x standard. This area of Swig is a work in +progress. Initial C++0x support for Swig was written during the +Google Summer of Code 2009 period.

+

Swig supports all the new C++ syntax changes with some limitations +(decltype expressions, variadic templates number). Wrappers for the +new types (unordered_ types, result_of, tuples) are not supported +yet.

+

Rvalue +reference and move semantics

+

Swig correctly parses the new operator && the same as the +reference operator &.

+

Generalized +constant expressions

+

Swig correctly parses the keyword „constexpr“, but ignores its +functionality. Constant functions cannot be used as constants yet.

+

7.1 Extern template

+ + +

Swig correctly parses the keywords „extern template“. The +explicit template instantiation is disabled in Swig.

+

7.2 Initializer lists

+ + +

Constructors using the std::initializer_list class are removed +from the wrapped class, because the only way to acess such a +constructor is at the compile time using the „= {}“ assignment.

+

User should add another constructor with specific arguments +filling the class members manually.

+

Uniform +initialization

+

The curly brackets {} for memeber initialization are fully +supported by Swig.

+

7.3 Type inference

+ + +

Swig supports „decltype()“ with some limitations. Single +variable is allowed, however expressions are not supported yet. For +example:

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

+will result in an error.

+

7.4 Range-based for-loop

+ + +

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

+

Lambda +functions and expressions

+

Swig correctly parses the Lambda functions syntax. The functions +are removed from the wrapper class, because of the lack of support +for closures in target languages (scope of the lambda functions).

+

Alternate +function syntax

+

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

+
float square(float, float);

+can now be written as

+
auto square(float, float) -> float;

+User can also use the type inference for the return type. For +example:

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

+Object +construction improvement

+

Swig correctly parses and includes the external functions +(constructor delegation and constructor inheritance) into the class +using the „using“ keyword.

+

7.5 Null pointer constant

+ + +

Swig correctly maps the std::nullptr constant to the null pointer +constant in the target language.

+

Strongly typed +enumerations

+

Swig parses the new „enum class“ syntax, but does not support +nested classes yet. The strongly typed enumerations are treated the +same as the ordinary and anonymous enums for now.

+

7.6 Double angle brackets

+ + +

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

+

User can force the bit shifting operator using the parenthesis +around the expressions. For example

+
template<(5>>3)>
class A {};

+Explicit +conversion operators

+

Swig correctly uses the keyword „explicit“ for function +objects.

+

7.7 Template typedefs

+ + +

Swig currently parses the new „using name =“ syntax, but +ignores the definition.

+

User should still define the typedefs using the old syntax.

+

7.8 Unrestricted unions

+ + +

Swig fully supports any type inside the union even if it does not +define the trivial constructor.

+

7.9 Variadic templates

+ + +

Swig fully supports the variadic templates syntax (inside the <> +block, variadic class inheritance and variadic constructor and +initializers) with some limitations.

+

The %template statement however, accepts only the amount of +arguments as defined in the original template<> block.

+

7.10 New string literals

+ + +

Swig fully supports custom delimiters and unicode string +constants.

+

Swig currently incorrectly parses the odd number of double quotes +inside the string. Other symbols are correctly parsed.

+

7.11 User-defined literals

+ + +

Swig correctly parses the new operator““_mysuffix() functions.

+

The %rename currently doesn't parse the double quotes so the user +should rename the functions in the code using the #define.

+

7.12 Thread-local storage

+ + +

Swig correctly parses the „thread_local“ keyword. The new +C++0x thread functionalities are currently ignored.

+

+Defaulting/deleting of standard functions on C++ objects

+

Swig correctly parses the „= delete“ and „= default“ +keywords. Swig overrides the standard C++ functions anyway (copy +constructor, operator= etc.).

+

7.13 Type long long int

+ + +

Swig correctly parses and uses the new „long long“ type.

+

7.14 Static assertions

+ + +

Swig correctly parses and calls the new „static_assert“ +function.

+

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

+

Swig correctly calls the sizeof() on types as well as on the +objects.

+

7.15 Threading facilities

+ + +

Swig does not currently wrap or use any of the new threading +classes introduced (thread, mutex, locks, condition variable, task).

+

7.16 Tuple types

+ + +

Swig does not wrap tuple types yet.

+

7.17 Hash tables

+ + +

Swig does not wrap the new unordered_ classes yet.

+

7.18 Regular expressions

+ + +

Swig does not wrap the new C++0x regular expressions classes, +because the target language uses its own facilities for this.

+

General-purpose +smart pointers

+

Swig ignores the new shared, weak and unique smart pointers.

+

Extensible +random number facility

+

This feature extends the standard library core only and does not +effect the C++ language.

+

7.19 Wrapper reference

+ + +

Swig does not wrap the new ref() function.

+

Polymorphous +wrappers for function objects

+

Swig fully supports the function templates and function objects.

+

Type traits +for metaprogramming

+

Swig explicitly requires concrete types when using the %template +directive.

+

+Uniform method for computing return type of function objects

+

Swig does not wrap the new result_of type.

+ + diff --git a/Doc/Manual/chapters b/Doc/Manual/chapters index bf180f1b4..af1c07773 100644 --- a/Doc/Manual/chapters +++ b/Doc/Manual/chapters @@ -4,6 +4,7 @@ Windows.html Scripting.html SWIG.html SWIGPlus.html +Cpp0x.html Preprocessor.html Library.html Arguments.html From 52149e219df7b790d3f8682d7e475695fbcc1019 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Fri, 14 Aug 2009 16:15:36 +0000 Subject: [PATCH 0042/1160] Removed decr-- Hash tables feature. Added some comments. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11569 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyiterators.swg | 10 ++++++++++ Lib/std/std_unordered_map.i | 3 +++ Lib/std/std_unordered_multimap.i | 3 +++ Lib/std/std_unordered_multiset.i | 3 +++ Lib/std/std_unordered_set.i | 3 +++ 5 files changed, 22 insertions(+) diff --git a/Lib/python/pyiterators.swg b/Lib/python/pyiterators.swg index 1d7f415be..301ae4cd9 100644 --- a/Lib/python/pyiterators.swg +++ b/Lib/python/pyiterators.swg @@ -226,6 +226,9 @@ namespace swig { SwigPyIterator *decr(size_t n = 1) { + while (n--) { + --base::current; + } return this; } }; @@ -274,6 +277,13 @@ namespace swig { SwigPyIterator *decr(size_t n = 1) { + while (n--) { + if (base::current == begin) { + throw stop_iteration(); + } else { + --base::current; + } + } return this; } diff --git a/Lib/std/std_unordered_map.i b/Lib/std/std_unordered_map.i index f205bd573..3c36d78e3 100644 --- a/Lib/std/std_unordered_map.i +++ b/Lib/std/std_unordered_map.i @@ -1,5 +1,8 @@ // // std::unordered_map +// Work in progress - the code is not compilable yet: +// operator--() and constructor(compare function) not available for unordered_ +// types // %include diff --git a/Lib/std/std_unordered_multimap.i b/Lib/std/std_unordered_multimap.i index bbdfeb82d..74efb2896 100644 --- a/Lib/std/std_unordered_multimap.i +++ b/Lib/std/std_unordered_multimap.i @@ -1,5 +1,8 @@ // // std::unordered_multimap +// Work in progress - the code is not compilable yet: +// operator--() and constructor(compare function) not available for unordered_ +// types // %include diff --git a/Lib/std/std_unordered_multiset.i b/Lib/std/std_unordered_multiset.i index 5ef76612d..56b971011 100644 --- a/Lib/std/std_unordered_multiset.i +++ b/Lib/std/std_unordered_multiset.i @@ -1,5 +1,8 @@ // // std::unordered_multiset +// Work in progress - the code is not compilable yet: +// operator--() and constructor(compare function) not available for unordered_ +// types // %include diff --git a/Lib/std/std_unordered_set.i b/Lib/std/std_unordered_set.i index 0eac339e0..4cdfd65a5 100644 --- a/Lib/std/std_unordered_set.i +++ b/Lib/std/std_unordered_set.i @@ -1,5 +1,8 @@ // // std::unordered_set +// Work in progress - the code is not compilable yet: +// operator--() and constructor(compare function) not available for unordered_ +// types // %include From b8198a51bbbabdf9046417ad7b020af7bd196610 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Mon, 17 Aug 2009 14:17:42 +0000 Subject: [PATCH 0043/1160] Updated C++0x User's manual. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11622 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Cpp0x.html | 881 ++++++++++++++++++++++++++++++------------ 1 file changed, 636 insertions(+), 245 deletions(-) diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index 8ecb5f52a..9ec67861b 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -1,303 +1,694 @@ - - - - SWIG and C++ - - - - - - - - - - -

7 Swig and C++0x

+ + +SWIG and Python + + + + +

7 SWIG and C++0x

- -

This chapter gives you a brief overview about the Swig -implementation of the C++0x standard. This area of Swig is a work in +

7.1 Introduction

+ + +

This chapter gives you a brief overview about the Swig +implementation of the C++0x standard. This part of Swig is still a work in progress. Initial C++0x support for Swig was written during the -Google Summer of Code 2009 period.

-

Swig supports all the new C++ syntax changes with some limitations +Google Summer of Code 2009 period.

+

Swig supports all the new C++ syntax changes with some limitations (decltype expressions, variadic templates number). Wrappers for the new types (unordered_ types, result_of, tuples) are not supported -yet.

-

Rvalue -reference and move semantics

-

Swig correctly parses the new operator && the same as the -reference operator &.

-

Generalized -constant expressions

-

Swig correctly parses the keyword „constexpr“, but ignores its -functionality. Constant functions cannot be used as constants yet.

-

7.1 Extern template

+yet.

+ +

7.2 Core language changes

-

Swig correctly parses the keywords „extern template“. The -explicit template instantiation is disabled in Swig.

-

7.2 Initializer lists

+

7.2.1 Rvalue reference and move semantics

-

Constructors using the std::initializer_list class are removed +

Swig correctly parses the new operator && the same as the reference operator &.

+ +

The wrapper for the following code is correctly produced:

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

7.2.2 Generalized constant expressions

+ + +

Swig correctly parses the keyword "constexpr", but ignores its functionality. Constant functions cannot be used as constants yet.

+ +
+constexpr int myConstFunc() { return 10; }
+const int a = myConstFunc(); // reslults in error
+
+ +

User needs to use values or predefined constants when defining the new constant value:

+ +
+#define MY_CONST 10
+constexpr int myConstFunc() { return MY_CONST; }
+const int a = MY_CONST; // ok
+
+ +

7.2.3 Extern template

+ + +

Swig correctly parses the keywords "extern template". However, the explicit template instantiation is not usable for Swig.

+ + +
+extern template class std::vector<MyClass>; // explicit instantiation
+
+...
+
+class MyClass {
+public:
+  int a;
+  int b;
+};
+
+ +

7.2.4 Initializer lists

+ + +

Constructors using the std::initializer_list class are removed from the wrapped class, because the only way to acess such a -constructor is at the compile time using the „= {}“ assignment.

-

User should add another constructor with specific arguments -filling the class members manually.

-

Uniform -initialization

-

The curly brackets {} for memeber initialization are fully -supported by Swig.

-

7.3 Type inference

+constructor is at the compile time using the "= {}" assignment.

+

User should add another constructor with specific arguments +filling the class members manually.

+ +

For now, if a user wants to fill the class components like this:

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

He should add another constructor using the std::vector for example:

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

And call it in target language:

+
+>>> a2 = A( [1,2,3,4] )
+
+ +

7.2.5 Uniform initialization

-

Swig supports „decltype()“ with some limitations. Single +

The curly brackets {} for memeber initialization are fully +supported by Swig:

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

Usage in the target language is the same:

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

7.2.6 Type inference

+ + +

Swig supports "decltype()" with some limitations. Single variable is allowed, however expressions are not supported yet. For -example:

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

-will result in an error.

-

7.4 Range-based for-loop

+example, the following code will work:

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

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

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

7.2.7 Range-based for-loop

-

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

-

Lambda -functions and expressions

-

Swig correctly parses the Lambda functions syntax. The functions -are removed from the wrapper class, because of the lack of support -for closures in target languages (scope of the lambda functions).

-

Alternate -function syntax

-

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

-
float square(float, float);

-can now be written as

-
auto square(float, float) -> float;

-User can also use the type inference for the return type. For -example:

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

-Object -construction improvement

-

Swig correctly parses and includes the external functions +

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

+ +

7.2.8 Lambda functions and expressions

+ + +

Swig correctly parses the Lambda functions syntax. For example:

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

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

+ +

7.2.9 Alternate function syntax

+ + +

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

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

can now be written as:

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

The usage in the target languages remains the same:

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

User can also use the type inference for the return type. For example:

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

7.2.10 Object construction improvement

+ + +

Swig correctly parses and includes the external functions (constructor delegation and constructor inheritance) into the class -using the „using“ keyword.

-

7.5 Null pointer constant

+using the "using" keyword.

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

7.2.11 Null pointer constant

-

Swig correctly maps the std::nullptr constant to the null pointer -constant in the target language.

-

Strongly typed -enumerations

-

Swig parses the new „enum class“ syntax, but does not support -nested classes yet. The strongly typed enumerations are treated the -same as the ordinary and anonymous enums for now.

-

7.6 Double angle brackets

+

Swig correctly maps the std::nullptr constant to the null pointer +constant in the target language.

+ +

7.2.12 Strongly typed enumerations

-

Swig correctly parses the symbols >> as the closure of the +

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

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

The strongly typed enumerations are treated the same as the ordinary and anonymous enums for now, +because Swig doesn't support the nested classes. For example, the following code:

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

should be written as a series of separated classes containing anonymous enums:

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

7.2.13 Double angle brackets

+ + +

Swig correctly parses the symbols >> as the closure of the template block, if found inside it at the top level, or as the right -shift operator >> otherwise.

-

User can force the bit shifting operator using the parenthesis -around the expressions. For example

-
template<(5>>3)>
class A {};

-Explicit -conversion operators

-

Swig correctly uses the keyword „explicit“ for function -objects.

-

7.7 Template typedefs

+shift operator >> otherwise.

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

User can force the bit shifting operator using the parenthesis +around the expressions. For example

+ +
+template<(5>>3)>
+class A {};
+
+ +

7.2.14 Explicit conversion operators

-

Swig currently parses the new „using name =“ syntax, but -ignores the definition.

-

User should still define the typedefs using the old syntax.

-

7.8 Unrestricted unions

+

Swig correctly parses the keyword "explicit" both for operators and constructors. +For example:

+ +
+class U {
+public:
+        int u;
+};
+
+class V {
+public:
+        int v;
+};
+
+class TestClass {
+public:
+        //implicit converting constructor
+        TestClass( U const &val ) { t=val.u; }
+        // explicit constructor
+        explicit TestClass( V const &val ) { t=val.v; }
+
+        int t;
+};
+
+ +

+The usage of explicit constructors and operators is somehow specific to C++ when assigning the value +of one object to another one of different type or translating one type to another. It requires both operator and function overloading features, +which are not supported by majority of Swig target languages. Also the constructors and operators are not particulary useful in any +Swig target languages, because all use their own faclities (eg. classes Cloneable and Comparable in Java) +to achieve particular copy and compare behaviours. +

+ +

7.2.15 Template typedefs

-

Swig fully supports any type inside the union even if it does not -define the trivial constructor.

-

7.9 Variadic templates

+

Swig currently parses the new "using name =" syntax, but +ignores the definition:

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

User should still define the typedefs using the old syntax:

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

7.2.16 Unrestricted unions

-

Swig fully supports the variadic templates syntax (inside the <> +

Swig fully supports any type inside the union even if it does not +define the trivial constructor. For example, the wrapper for the following +code is correctly produced:

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

7.2.17 Variadic templates

+ + +

Swig fully supports the variadic templates syntax (inside the <> block, variadic class inheritance and variadic constructor and -initializers) with some limitations.

-

The %template statement however, accepts only the amount of -arguments as defined in the original template<> block.

-

7.10 New string literals

+initializers) with some limitations. The following code is correctly parsed:

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

Support for the variadic sizeof() function was also introduced:

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

The %template statement however, accepts only at most as the amount of +arguments defined in the original template<> block for now:

+ +
+%template(MyVariant1) ClassName<>         // ok
+%template(MyVariant2) ClassName<int>      // ok
+%template(MyVariant3) ClassName<int, int> // too much arguments
+
+ +

7.2.18 New string literals

-

Swig fully supports custom delimiters and unicode string -constants.

-

Swig currently incorrectly parses the odd number of double quotes -inside the string. Other symbols are correctly parsed.

-

7.11 User-defined literals

+

Swig fully supports custom delimiters and unicode string +constants.

+ +
+// New string literals
+char      *a = "ABC";
+wstring wide = L"ABC";
+char      *b = u8"ABC";
+char16_t  *c = u"ABC";
+char32_t  *d = U"ABC";
+
+// Custom String delimiter
+char       *e = R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX";
+wstring wide2 = LR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX";
+char       *f = u8R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX";
+char16_t   *g = uR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX";
+char32_t   *h = UR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX";
+
+ +

Note: Swig currently incorrectly parses the odd number of double quotes +inside the string due to Swig's C++ preprocessor.

+ +

7.2.19 User-defined literals

-

Swig correctly parses the new operator““_mysuffix() functions.

-

The %rename currently doesn't parse the double quotes so the user -should rename the functions in the code using the #define.

-

7.12 Thread-local storage

+

Swig correctly parses the new operator""_mysuffix() functions.

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

The %rename currently doesn't parse the double quotes so the user +should rename the functions in the code using the #define preprocessor directive.

+ +

7.2.20 Thread-local storage

-

Swig correctly parses the „thread_local“ keyword. The new -C++0x thread functionalities are currently ignored.

-

-Defaulting/deleting of standard functions on C++ objects

-

Swig correctly parses the „= delete“ and „= default“ -keywords. Swig overrides the standard C++ functions anyway (copy -constructor, operator= etc.).

-

7.13 Type long long int

+

Swig correctly parses the "thread_local" keyword. For example, a variable +reachable by the current thread can be defined as:

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

The new C++0x threading libraries are ignored because each Swig target language offers +its own threading facilities.

+ +

7.2.21 Defaulting/deleting of standard functions on C++ objects

-

Swig correctly parses and uses the new „long long“ type.

-

7.14 Static assertions

+

Swig correctly parses the "= delete" and "= default" +keywords. For example:

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

This feature is somehow specific to the C++ only. The defaulting/deleting is currently ignored, because Swig +automatically produces wrappers for special constructors and operators specific to the target language.

+ +

7.2.22 Type long long int

-

Swig correctly parses and calls the new „static_assert“ -function.

-

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

-

Swig correctly calls the sizeof() on types as well as on the -objects.

-

7.15 Threading facilities

+

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

+ +

7.2.23 Static assertions

-

Swig does not currently wrap or use any of the new threading -classes introduced (thread, mutex, locks, condition variable, task).

-

7.16 Tuple types

+

Swig correctly parses and calls the new "static_assert" function.

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

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

-

Swig does not wrap tuple types yet.

-

7.17 Hash tables

+

Swig correctly calls the sizeof() on types as well as on the +objects. For example:

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

In Python:

+
+>>> SIZE
+8
+
+ +

7.3 Standard library changes

-

Swig does not wrap the new unordered_ classes yet.

-

7.18 Regular expressions

+

7.3.1 Threading facilities

-

Swig does not wrap the new C++0x regular expressions classes, -because the target language uses its own facilities for this.

-

General-purpose -smart pointers

-

Swig ignores the new shared, weak and unique smart pointers.

-

Extensible -random number facility

-

This feature extends the standard library core only and does not -effect the C++ language.

-

7.19 Wrapper reference

+

Swig does not currently wrap or use any of the new threading +classes introduced (thread, mutex, locks, condition variable, task). The main reason is that +Swig target languages offer their own threading facilities that do not rely on the C++.

+ +

7.3.2 Tuple types and hash tables

-

Swig does not wrap the new ref() function.

-

Polymorphous -wrappers for function objects

-

Swig fully supports the function templates and function objects.

-

Type traits -for metaprogramming

-

Swig explicitly requires concrete types when using the %template -directive.

-

-Uniform method for computing return type of function objects

-

Swig does not wrap the new result_of type.

+

Swig does not wrap the new tuple types and the unordered_ classes yet. Variadic support is there so the user can +include the tuple header file and is parsed without any problems.

+ +

7.3.3 Regular expressions

+ + +

Swig does not wrap the new C++0x regular expressions classes, because the Swig target languages use their own facilities for this.

+ +

7.3.4 General-purpose smart pointers

+ + +

Swig does not wrap the new shared, weak and unique smart pointers, because the Swig target languages offer their own garbage collectors.

+ +

7.3.5 Extensible random number facility

+ + +

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

+ +

7.3.6 Wrapper reference

+ + +

The new ref and cref classes are used to instantiate a parameter as a reference of a template function. For example:

+ +
+void f( int &r )  { r++ ; }
+ 
+// Template function.
+template< class F, class P > void g( F f, P t )  { f(t); }
+ 
+int main() {
+  int i = 0 ;
+  g( f, i ) ;  // 'g<void ( int &r ), int>' is instantiated
+               // then 'i' will not be modified.
+  cout << i << endl ;  // Output -> 0
+ 
+  g( f, ref(i) ) ;  // 'g<void(int &r),reference_wrapper<int>>' is instanced
+                    // then 'i' will be modified.
+  cout << i << endl ;  // Output -> 1
+}
+
+ +

The ref and cref classes are not wrapped by Swig because the Swig target languages do not support referencing.

+ +

7.3.7 Polymorphous wrappers for function objects

+ + +

Swig fully supports the function template wrappers and function objects:

+ +
+function<int ( int, int )> pF;   // function template wrapper
+
+struct Test {
+  bool operator()( short x, short y ); // function object
+};
+
+ +

7.3.8 Type traits for metaprogramming

+ + +

The new C++ metaprogramming is useful at compile time and is aimed specifically for the C++ development:

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

Swig correctly parses the template specialization, template types and values inside the <> block and the new helper functions is_convertible, is_integral, is_const etc. +However, Swig still explicitly requires concrete types when using the %template directive, so the C++ metaprogramming features are not really interesting at runtime in Swig target languages.

+ +

7.3.9 Uniform method for computing return type of function objects

+ + +

Swig does not wrap the new result_of class introduced in the <functional> header and map the result_of::type to the concrete type yet. For example:

+
+%inline %{
+#include <functional>
+double square(double x) {
+        return (x * x);
+}
+
+template<class Fun, class Arg>
+typename std::result_of<Fun(Arg)>::type test_result_impl(Fun fun, Arg arg) {
+        return fun(arg);
+}
+%}
+
+%template(test_result) test_result_impl<double(*)(double), double>;
+%constant double (*SQUARE)(double) = square;
+
+ +

will result in:

+ +
+>>> test_result_impl(SQUARE, 5.0)
+<Swig Object of type 'std::result_of< Fun(Arg) >::type *' at 0x7faf99ed8a50>
+
+ +

User should use decltype() where possible for now.

From 67b4ad70849e529945b1dcd265074a84d81840d3 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Mon, 17 Aug 2009 14:42:34 +0000 Subject: [PATCH 0044/1160] Documented C++0x testcases. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11623 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/cpp0x_alternate_function_syntax.i | 2 ++ Examples/test-suite/cpp0x_default_delete.i | 4 +++- Examples/test-suite/cpp0x_hash_tables.i | 2 ++ Examples/test-suite/cpp0x_rvalue_reference.i | 2 ++ Examples/test-suite/cpp0x_strongly_typed_enumerations.i | 3 +++ Examples/test-suite/cpp0x_uniform_initialization.i | 2 ++ Examples/test-suite/cpp0x_unrestricted_unions.i | 2 ++ 7 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/cpp0x_alternate_function_syntax.i b/Examples/test-suite/cpp0x_alternate_function_syntax.i index b17223626..d8d0ec6c4 100644 --- a/Examples/test-suite/cpp0x_alternate_function_syntax.i +++ b/Examples/test-suite/cpp0x_alternate_function_syntax.i @@ -1,3 +1,5 @@ +/* This testcase checks whether Swig correctly uses the new alternate functions + declarations and definitions introduced in C++0x. */ %module cpp0x_alternate_function_syntax %inline %{ diff --git a/Examples/test-suite/cpp0x_default_delete.i b/Examples/test-suite/cpp0x_default_delete.i index 2e2108494..affcea58e 100644 --- a/Examples/test-suite/cpp0x_default_delete.i +++ b/Examples/test-suite/cpp0x_default_delete.i @@ -1,3 +1,5 @@ +/* This testcase checks whether Swig correctly parses the default and delete + keywords which keep or remove default C++ object construction functions. */ %module cpp0x_default_delete %{ @@ -5,7 +7,7 @@ class NonCopyable { public: - NonCopyable & operator=(const NonCopyable&) = delete; /* Removes operator= */ + NonCopyable& operator=(const NonCopyable&) = delete; /* Removes operator= */ NonCopyable(const NonCopyable&) = delete; /* Removed copy constructor */ NonCopyable() = default; /* Explicitly allows the empty constructor */ void *operator new(size_t) = delete; /* Removes new NonCopyable */ diff --git a/Examples/test-suite/cpp0x_hash_tables.i b/Examples/test-suite/cpp0x_hash_tables.i index a4829ce1f..b5eb505a4 100644 --- a/Examples/test-suite/cpp0x_hash_tables.i +++ b/Examples/test-suite/cpp0x_hash_tables.i @@ -1,3 +1,5 @@ +/* This testcase checks the new wrappers for the new unordered_ STL types + introduced in C++0x. */ %module cpp0x_hash_tables %inline %{ diff --git a/Examples/test-suite/cpp0x_rvalue_reference.i b/Examples/test-suite/cpp0x_rvalue_reference.i index e45d91e27..f6c764aca 100644 --- a/Examples/test-suite/cpp0x_rvalue_reference.i +++ b/Examples/test-suite/cpp0x_rvalue_reference.i @@ -1,3 +1,5 @@ +/* This testcase checks whether Swig correctly parses the double ampersand && + move operator which is currently mapped to the reference & operator. */ %module cpp0x_rvalue_reference %inline %{ diff --git a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i index 0f281a195..78925c1c8 100644 --- a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i +++ b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i @@ -1,3 +1,6 @@ +/* This testcase checks whether Swig produces the correct wrapper for the + strongly typed enums. Enums with the same type are comparable. Enum classes + require support for nested classes. */ %module cpp0x_strongly_typed_enumerations %inline %{ diff --git a/Examples/test-suite/cpp0x_uniform_initialization.i b/Examples/test-suite/cpp0x_uniform_initialization.i index a56178930..39ed73180 100644 --- a/Examples/test-suite/cpp0x_uniform_initialization.i +++ b/Examples/test-suite/cpp0x_uniform_initialization.i @@ -1,3 +1,5 @@ +/* This testcase checks whether Swig syntactically correctly parses the curly + brackets {} for uniform member initialization. */ %module cpp0x_uniform_initialization %inline %{ diff --git a/Examples/test-suite/cpp0x_unrestricted_unions.i b/Examples/test-suite/cpp0x_unrestricted_unions.i index d3364ef83..a534df466 100644 --- a/Examples/test-suite/cpp0x_unrestricted_unions.i +++ b/Examples/test-suite/cpp0x_unrestricted_unions.i @@ -1,3 +1,5 @@ +/* This testcase checks whether Swig correctly parses the support for types + without the defined trivial constructor in the unions. */ %module cpp0x_unrestricted_unions %inline %{ From c9fcb01943110340ed980b7865409432fa377b45 Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Mon, 17 Aug 2009 15:27:48 +0000 Subject: [PATCH 0045/1160] Fixed testcase warnings. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11625 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/cpp0x_initializer_list.i | 4 +++- Examples/test-suite/cpp0x_raw_string_literals.i | 2 ++ Examples/test-suite/cpp0x_strongly_typed_enumerations.i | 4 ++++ Examples/test-suite/cpp0x_template_explicit.i | 2 ++ Examples/test-suite/cpp0x_userdefined_literals.i | 2 +- Examples/test-suite/cpp0x_variadic_templates.i | 3 +++ Source/CParse/parser.y | 4 ++-- 7 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/cpp0x_initializer_list.i b/Examples/test-suite/cpp0x_initializer_list.i index 76bc741f5..3d6893033 100644 --- a/Examples/test-suite/cpp0x_initializer_list.i +++ b/Examples/test-suite/cpp0x_initializer_list.i @@ -1,13 +1,15 @@ /* This testcase checks whether Swig correctly uses the new initializer_list introduced in C++0x. */ %module cpp0x_initializer_list +%warnfilter(520) A; %inline %{ #include class A { public: - A( std::initializer_list ) {} + A( std::initializer_list ) {} + A() {} }; %} diff --git a/Examples/test-suite/cpp0x_raw_string_literals.i b/Examples/test-suite/cpp0x_raw_string_literals.i index 12c68cd63..1e8515504 100644 --- a/Examples/test-suite/cpp0x_raw_string_literals.i +++ b/Examples/test-suite/cpp0x_raw_string_literals.i @@ -8,6 +8,8 @@ This module also tests whether Swig correctly parses custom string delimiters. */ %module cpp0x_raw_string_literals +%warnfilter(454) c; +%warnfilter(454) d; %inline %{ #include diff --git a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i index 78925c1c8..4476122fe 100644 --- a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i +++ b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i @@ -2,6 +2,10 @@ strongly typed enums. Enums with the same type are comparable. Enum classes require support for nested classes. */ %module cpp0x_strongly_typed_enumerations +%warnfilter(302) Val1; +%warnfilter(302) Val2; +%warnfilter(302) Val3; +%warnfilter(302) Val4; %inline %{ enum class Enum1 { diff --git a/Examples/test-suite/cpp0x_template_explicit.i b/Examples/test-suite/cpp0x_template_explicit.i index e0ff71073..f05bcf850 100644 --- a/Examples/test-suite/cpp0x_template_explicit.i +++ b/Examples/test-suite/cpp0x_template_explicit.i @@ -3,6 +3,8 @@ using the translation unit). */ %module cpp0x_template_explicit +%warnfilter(320) std::vector; +%warnfilter(320) std::vector; %inline %{ #include diff --git a/Examples/test-suite/cpp0x_userdefined_literals.i b/Examples/test-suite/cpp0x_userdefined_literals.i index f41823488..4488a573b 100644 --- a/Examples/test-suite/cpp0x_userdefined_literals.i +++ b/Examples/test-suite/cpp0x_userdefined_literals.i @@ -11,8 +11,8 @@ struct OutputType { OutputType(int v) { v=val; } }; +/* Note: GCC doesn't support user-defined literals yet! */ struct TT { -OutputType operator << (const char * string_values, size_t num_chars) { return OutputType(100); } OutputType operator "" (const char * string_values, size_t num_chars) { return OutputType(100); } OutputType operator "" _mySuffix1(const char * string_values, size_t num_chars) { return OutputType(100); } OutputType operator "" _mySuffix2(const wchar_t * string_values, size_t num_chars) { return OutputType(200); } diff --git a/Examples/test-suite/cpp0x_variadic_templates.i b/Examples/test-suite/cpp0x_variadic_templates.i index 6317b1340..b9320a0d1 100644 --- a/Examples/test-suite/cpp0x_variadic_templates.i +++ b/Examples/test-suite/cpp0x_variadic_templates.i @@ -4,6 +4,9 @@ using variadic number of classes. */ %module cpp0x_variadic_templates +%warnfilter(507) MultiArgs1; +%warnfilter(507) SizeOf1; +%warnfilter(507) MultiInherit1; //////////////////////// // Variadic templates // diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index e12455197..5645d7a8b 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2745,7 +2745,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va p = tp; def_supplied = 1; } else if (p && !tp) { /* Variadic template - tp < p */ - Swig_warning(0,cparse_file, cparse_line,"Only the first variadic argument is currently supported by Swig.\n"); + Swig_warning(WARN_LANG_NATIVE_UNIMPL,cparse_file, cparse_line,"Only the first variadic argument is currently supported by Swig.\n"); break; } } @@ -4265,7 +4265,7 @@ cpp_member : c_declaration { $$ = $1; } cpp_constructor_decl : storage_class type LPAREN parms RPAREN ctor_end { if (Classprefix) { - if (Getattr($4,"type") && strstr(Char(Getattr($4,"type")), "initializer_list<")) { + if ($4 && Getattr($4,"type") && strstr(Char(Getattr($4,"type")), "initializer_list<")) { /* Ignore constructors containing initializer_list<> introduced in C++0x */ Swig_warning(WARN_LANG_INITIALIZER_LIST, cparse_file, cparse_line, "Constructor with std::initializer_list<> argument ignored.\n"); $$ = 0; From 8be21781e7140d290141e7fbc9f1b73876557b3a Mon Sep 17 00:00:00 2001 From: Matevz Jekovec Date: Mon, 17 Aug 2009 15:35:09 +0000 Subject: [PATCH 0046/1160] Added developer documentation for C++0x. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11626 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Devel/cpp0x.html | 788 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 788 insertions(+) create mode 100644 Doc/Devel/cpp0x.html diff --git a/Doc/Devel/cpp0x.html b/Doc/Devel/cpp0x.html new file mode 100644 index 000000000..4afc5ffe4 --- /dev/null +++ b/Doc/Devel/cpp0x.html @@ -0,0 +1,788 @@ + + + + + + + + + + + + + + + +

C++0x support for SWIG

+

Summary

+

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

+

SVN branch

+

branches/gsoc2009-matevz

+

New C++0x features status

+

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

+

Rvalue reference and move semantics [done]

+

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

+

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

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

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

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

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

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

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

+

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

+

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

+

Generalized constant expressions [done]

+

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

+

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

+

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

+

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

+

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

+

Extern template [done]

+

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

+

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

+

Initializer lists [done]

+

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

+

One can now use: +

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

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

+

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

+

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

+

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

+

Uniform initialization [done]

+

The new C++0x standard will allow the following:

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

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

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

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

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

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

+

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

+

Type inference [partially done]

+

A new keyword 'auto' is introduced in C++0x:

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

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

+

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

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

+Calling operators are allowed as well:

+
decltype(i+j) k = 300;

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

+

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

+

Range-based for-loop [ignored]

+

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

+

Lambda functions and expressions [done]

+

C++0x introduces lambda functions defined as:

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

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

+

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

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

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

+

Lambda functions can be stored using:

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

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

+

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

+

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

+

Alternate function syntax [done]

+

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

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

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

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

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

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

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

+

Concepts, Axioms [ignored]

+

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

+

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

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

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

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

+Definition of the concepts: +

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

+Concept maps allow usage of a specific type: +

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

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

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

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

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

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

+

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

+

Object construction improvement [done]

+

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

+

The syntax is as follows: +

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

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

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

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

+

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

+

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

+

Null pointer constant [done]

+

nullptr is part of the standard library. +

+

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

+

nullptr_t is defined in <cstddef>. +

+

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

+

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

+

Strongly typed enumerations [partially done]

+

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

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

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

+

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

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

+And it can be forward declared as well: +

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

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

+

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

+

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

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

+should be mapped to

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

+Angle bracket [done]

+

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

+

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

+

Explicit conversion operators [done]

+

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

+

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

+

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

+

Template typedefs [partially done]

+

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

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

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

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

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

+

The same goes for the following example:

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

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

+
typedef List<int> intList;

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

+

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

+

Unrestricted unions [done]

+

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

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

+Swig already parses the given syntax.

+

Done: Added testcase cpp0x_unrestricted_unions. R11435, R11447

+

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

+

Variadic templates [partially done]

+

The new C++0x offers the following syntax:

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

+This can be used for example:

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

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

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

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

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

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

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

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

+

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

+

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

+

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

+

New string literals [partially done]

+

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

+

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

+

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

+

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

+

User-defined literals [partially done]

+

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

+

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

+

The syntax is similar to other operator overloading functions: +

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

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

+

Other forms are: +

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

+Another possibility is to use variadic templates: +

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

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

+

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

+

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

+

TODO: %rename doesn't parse operatorâ€â€ yet.

+

Thread-local storage [done] +

+

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

+

Syntax: +

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

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

+

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

+

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

+

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

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

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

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

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

+

Done: Added testcase cpp0x_default_delete. R11535

+

Type long long int [done]

+

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

+

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

+

Static assertions [done]

+

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

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

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

+

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

+

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

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

+This kind of syntax is already supported by Swig.

+

Done: Added testcase cpp0x_sizeof_objects. R11538 +

+

Threading facilities [ignored]

+

C++0x will add the following classes to the standard library: +

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

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

+

Tuple types [TODO]

+

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

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

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

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

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

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

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

+

Hash tables [TODO]

+

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

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

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

+

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

+

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

+

Regular expressions [ignored]

+

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

+

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

+

General-purpose smart pointers [done]

+

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

+

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

+

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

+

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

+

Extensible random number facility [ignored]

+

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

+

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

+

Wrapper reference [ignored]

+

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

+

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

+

Polymorphous wrappers for function objects [done]

+

Two features are introduced: +

+
    +
  • The function template wrapper: +

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

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

+Swig already supports the two.

+

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

+

Type traits for metaprogramming [ignored]

+

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

+

Swig already supports the following code: +

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

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

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

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

+

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

+

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

+

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

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

+Swig correctly parses the result_of class.

+

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

+

Done: Added testcase cpp0x_result_of. R11534

+ + \ No newline at end of file From fc6c84554b8ca497a9e2ee0cc40d3c8ef285b5be Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 20 Aug 2009 00:26:26 +0000 Subject: [PATCH 0047/1160] Grammar and formatting improvements git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11655 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Cpp0x.html | 171 +++++++++++++++++++++--------------------- 1 file changed, 86 insertions(+), 85 deletions(-) diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index 9ec67861b..4466e6cfd 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -1,7 +1,7 @@ -SWIG and Python +SWIG and C++0x @@ -59,13 +59,13 @@

7.1 Introduction

-

This chapter gives you a brief overview about the Swig -implementation of the C++0x standard. This part of Swig is still a work in -progress. Initial C++0x support for Swig was written during the +

This chapter gives you a brief overview about the SWIG +implementation of the C++0x standard. This part of SWIG is still a work in +progress. Initial C++0x support for SWIG was written during the Google Summer of Code 2009 period.

-

Swig supports all the new C++ syntax changes with some limitations +

SWIG supports all the new C++ syntax changes with some minor limitations (decltype expressions, variadic templates number). Wrappers for the -new types (unordered_ types, result_of, tuples) are not supported +new STL types (unordered_ containers, result_of, tuples) are not supported yet.

7.2 Core language changes

@@ -74,7 +74,7 @@ yet.

7.2.1 Rvalue reference and move semantics

-

Swig correctly parses the new operator && the same as the reference operator &.

+

SWIG correctly parses the new operator && the same as the reference operator &.

The wrapper for the following code is correctly produced:

@@ -90,14 +90,14 @@ class MyClass {
 

7.2.2 Generalized constant expressions

-

Swig correctly parses the keyword "constexpr", but ignores its functionality. Constant functions cannot be used as constants yet.

+

SWIG correctly parses the keyword constexpr, but ignores its functionality. Constant functions cannot be used as constants.

 constexpr int myConstFunc() { return 10; }
-const int a = myConstFunc(); // reslults in error
+const int a = myConstFunc(); // results in error
 
-

User needs to use values or predefined constants when defining the new constant value:

+

Users needs to use values or predefined constants when defining the new constant value:

 #define MY_CONST 10
@@ -108,7 +108,7 @@ const int a = MY_CONST; // ok
 

7.2.3 Extern template

-

Swig correctly parses the keywords "extern template". However, the explicit template instantiation is not usable for Swig.

+

SWIG correctly parses the keywords extern template. However, the explicit template instantiation is not used by SWIG, a %template is still required.

@@ -127,8 +127,8 @@ public:
 
 
 

Constructors using the std::initializer_list class are removed -from the wrapped class, because the only way to acess such a -constructor is at the compile time using the "= {}" assignment.

+from the wrapped class, because the only way to access such a +constructor is at compile time using the "= {}" assignment.

User should add another constructor with specific arguments filling the class members manually.

@@ -142,7 +142,7 @@ public: A a1 = {1,2,3,4};
-

He should add another constructor using the std::vector for example:

+

You should add another constructor using the std::vector for example:

 class A {
@@ -153,7 +153,7 @@ public:
 A a1 = {1,2,3,4};
 
-

And call it in target language:

+

And call it from your target language, for example, in Python:

 >>> a2 = A( [1,2,3,4] )
 
@@ -161,8 +161,8 @@ A a1 = {1,2,3,4};

7.2.5 Uniform initialization

-

The curly brackets {} for memeber initialization are fully -supported by Swig:

+

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

 struct BasicStruct {
@@ -181,7 +181,7 @@ BasicStruct var1{5, 3.2}; // only fills the struct components
 AltStruct var2{2, 4.3};   // calls the constructor
 
-

Usage in the target language is the same:

+

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

 >>> a = AltStruct(10, 142.15)
@@ -194,8 +194,8 @@ AltStruct var2{2, 4.3};   // calls the constructor
 

7.2.6 Type inference

-

Swig supports "decltype()" with some limitations. Single -variable is allowed, however expressions are not supported yet. For +

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

 int i;
@@ -208,34 +208,34 @@ int i; int j;
 decltype(i+j) k;  // syntax error
 
-

7.2.7 Range-based for-loop

+

7.2.7 Range-based for-loop

-

This feature is part of the implementation block only. Swig +

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

7.2.8 Lambda functions and expressions

-

Swig correctly parses the Lambda functions syntax. For example:

+

SWIG correctly parses the Lambda functions syntax. For example:

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

The lambda functions are removed from the wrapper class for now, because of the lack of support -for closures (scope of the lambda functions) in target languages though.

+for closures (scope of the lambda functions) in the target languages.

7.2.9 Alternate function syntax

-

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

+

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

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

can now be written as:

+

can now be written as in C++0x:

 struct SomeStruct {
@@ -247,7 +247,7 @@ auto SomeStruct::FuncName(int x, int y) -> int {
 }
 
-

The usage in the target languages remains the same:

+

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

 >>> a = SomeStruct()
@@ -255,7 +255,7 @@ auto SomeStruct::FuncName(int x, int y) -> int {
 15
 
-

User can also use the type inference for the return type. For example:

+

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

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

7.2.10 Object construction improvement

-

Swig correctly parses and includes the external functions +

SWIG correctly parses and includes the external functions (constructor delegation and constructor inheritance) into the class -using the "using" keyword.

+using the using keyword.

 class BaseClass {
@@ -282,19 +282,20 @@ class DerivedClass: public BaseClass {
 

7.2.11 Null pointer constant

-

Swig correctly maps the std::nullptr constant to the null pointer +

SWIG correctly maps the std::nullptr constant to the null pointer constant in the target language.

7.2.12 Strongly typed enumerations

-

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

+

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

 enum class MyEnum : unsigned int;
 
-

The strongly typed enumerations are treated the same as the ordinary and anonymous enums for now, -because Swig doesn't support the nested classes. For example, the following code:

+

The strongly typed enumerations are treated the same as the ordinary and anonymous enums. +This is because SWIG doesn't support nested classes. This is usually not a problem, however, +there may be some name clashes. For example, the following code:

 class Color {
@@ -313,7 +314,7 @@ class Color {
 };
 
-

should be written as a series of separated classes containing anonymous enums:

+

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

 class PrintingColors {
@@ -338,7 +339,7 @@ class AllColors {
 

7.2.13 Double angle brackets

-

Swig correctly parses the symbols >> as the closure of the +

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

@@ -346,8 +347,8 @@ shift operator >> otherwise.

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

User can force the bit shifting operator using the parenthesis -around the expressions. For example

+

The bit shifting operator using the parenthesis +around the expressions can be forced. For example

 template<(5>>3)>
@@ -357,7 +358,7 @@ class A {};
 

7.2.14 Explicit conversion operators

-

Swig correctly parses the keyword "explicit" both for operators and constructors. +

SWIG correctly parses the keyword explicit both for operators and constructors. For example:

@@ -385,22 +386,22 @@ public:
 

The usage of explicit constructors and operators is somehow specific to C++ when assigning the value of one object to another one of different type or translating one type to another. It requires both operator and function overloading features, -which are not supported by majority of Swig target languages. Also the constructors and operators are not particulary useful in any -Swig target languages, because all use their own faclities (eg. classes Cloneable and Comparable in Java) +which are not supported by the majority of SWIG target languages. Also the constructors and operators are not particulary useful in any +SWIG target languages, because all use their own facilities (eg. classes Cloneable and Comparable in Java) to achieve particular copy and compare behaviours.

7.2.15 Template typedefs

-

Swig currently parses the new "using name =" syntax, but +

SWIG currently parses the new using name = syntax, but ignores the definition:

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

User should still define the typedefs using the old syntax:

+

You should still define the typedefs using the old syntax:

 typedef void (*PFD)(double);  // The old style
@@ -409,7 +410,7 @@ typedef void (*PFD)(double);  // The old style
 

7.2.16 Unrestricted unions

-

Swig fully supports any type inside the union even if it does not +

SWIG fully supports any type inside a union even if it does not define the trivial constructor. For example, the wrapper for the following code is correctly produced:

@@ -430,7 +431,7 @@ union P {

7.2.17 Variadic templates

-

Swig fully supports the variadic templates syntax (inside the <> +

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

@@ -447,19 +448,19 @@ public: const int SIZE = sizeof...(ClassName<int, int>);
-

The %template statement however, accepts only at most as the amount of -arguments defined in the original template<> block for now:

+

For now however, the %template directive only accepts at most the number of +arguments defined in the original template<> block:

 %template(MyVariant1) ClassName<>         // ok
 %template(MyVariant2) ClassName<int>      // ok
-%template(MyVariant3) ClassName<int, int> // too much arguments
+%template(MyVariant3) ClassName<int, int> // too many arguments
 

7.2.18 New string literals

-

Swig fully supports custom delimiters and unicode string +

SWIG fully supports custom delimiters and unicode string constants.

@@ -478,13 +479,13 @@ char16_t   *g = uR"XXX[to be or "not" to be [these are parenthesis], this is the
 char32_t   *h = UR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX";
 
-

Note: Swig currently incorrectly parses the odd number of double quotes -inside the string due to Swig's C++ preprocessor.

+

Note: SWIG currently incorrectly parses the odd number of double quotes +inside the string due to SWIG's C++ preprocessor.

-

7.2.19 User-defined literals

+

7.2.19 User-defined literals

-

Swig correctly parses the new operator""_mysuffix() functions.

+

SWIG correctly parses the new operator""_mysuffix() functions.

 OutputType operator "" _mySuffix(const char * string_values, size_t num_chars);
@@ -494,13 +495,13 @@ OutputType operator "" _mySuffix(const char32_t * string_values, size_t num_char
 OutputType operator "" _mySuffix(int value);
 
-

The %rename currently doesn't parse the double quotes so the user -should rename the functions in the code using the #define preprocessor directive.

+

The %rename currently doesn't parse the double quotes. Please +rename the functions in the code using the #define preprocessor directive.

-

7.2.20 Thread-local storage

+

7.2.20 Thread-local storage

-

Swig correctly parses the "thread_local" keyword. For example, a variable +

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

@@ -509,36 +510,36 @@ struct A {
 };
 
-

The new C++0x threading libraries are ignored because each Swig target language offers +

The new C++0x threading libraries are ignored because each SWIG target language offers its own threading facilities.

7.2.21 Defaulting/deleting of standard functions on C++ objects

-

Swig correctly parses the "= delete" and "= default" +

SWIG correctly parses the = delete and = default keywords. For example:

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

This feature is somehow specific to the C++ only. The defaulting/deleting is currently ignored, because Swig +

This feature is specific to C++ only. The defaulting/deleting is currently ignored, because SWIG automatically produces wrappers for special constructors and operators specific to the target language.

7.2.22 Type long long int

-

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

+

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

7.2.23 Static assertions

-

Swig correctly parses and calls the new "static_assert" function.

+

SWIG correctly parses and calls the new static_assert function.

 template <typename T>
@@ -550,7 +551,7 @@ struct Check {
 

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

-

Swig correctly calls the sizeof() on types as well as on the +

SWIG correctly calls the sizeof() on types as well as on the objects. For example:

@@ -573,30 +574,30 @@ const int SIZE = sizeof(A::member); // does not work with C++03. Okay with C++0x
 

7.3.1 Threading facilities

-

Swig does not currently wrap or use any of the new threading -classes introduced (thread, mutex, locks, condition variable, task). The main reason is that -Swig target languages offer their own threading facilities that do not rely on the C++.

+

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

7.3.2 Tuple types and hash tables

-

Swig does not wrap the new tuple types and the unordered_ classes yet. Variadic support is there so the user can -include the tuple header file and is parsed without any problems.

+

SWIG does not wrap the new tuple types and the unordered_ container classes yet. Variadic template support is working so it is possible to +include the tuple header file; it is parsed without any problems.

7.3.3 Regular expressions

-

Swig does not wrap the new C++0x regular expressions classes, because the Swig target languages use their own facilities for this.

+

SWIG does not wrap the new C++0x regular expressions classes, because the SWIG target languages use their own facilities for this.

-

7.3.4 General-purpose smart pointers

+

7.3.4 General-purpose smart pointers

-

Swig does not wrap the new shared, weak and unique smart pointers, because the Swig target languages offer their own garbage collectors.

+

SWIG does not wrap the new shared, weak and unique smart pointers, because the SWIG target languages offer their own garbage collectors.

7.3.5 Extensible random number facility

-

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

+

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

7.3.6 Wrapper reference

@@ -604,7 +605,7 @@ include the tuple header file and is parsed without any problems.

The new ref and cref classes are used to instantiate a parameter as a reference of a template function. For example:

-void f( int &r )  { r++ ; }
+void f( int &r )  { r++; }
  
 // Template function.
 template< class F, class P > void g( F f, P t )  { f(t); }
@@ -615,18 +616,18 @@ int main() {
                // then 'i' will not be modified.
   cout << i << endl ;  // Output -> 0
  
-  g( f, ref(i) ) ;  // 'g<void(int &r),reference_wrapper<int>>' is instanced
+  g( f, ref(i) ) ;  // 'g<void(int &r),reference_wrapper<int>>' is instantiated
                     // then 'i' will be modified.
   cout << i << endl ;  // Output -> 1
 }
 
-

The ref and cref classes are not wrapped by Swig because the Swig target languages do not support referencing.

+

The ref and cref classes are not wrapped by SWIG because the SWIG target languages do not support referencing.

7.3.7 Polymorphous wrappers for function objects

-

Swig fully supports the function template wrappers and function objects:

+

SWIG fully supports function template wrappers and function objects:

 function<int ( int, int )> pF;   // function template wrapper
@@ -639,7 +640,7 @@ struct Test {
 

7.3.8 Type traits for metaprogramming

-

The new C++ metaprogramming is useful at compile time and is aimed specifically for the C++ development:

+

The new C++ metaprogramming is useful at compile time and is aimed specifically for C++ development:

 // First way of operating.
@@ -658,13 +659,13 @@ template< class T1, class T2 > int elaborate( T1 A, T2 B ) {
 }
 
-

Swig correctly parses the template specialization, template types and values inside the <> block and the new helper functions is_convertible, is_integral, is_const etc. -However, Swig still explicitly requires concrete types when using the %template directive, so the C++ metaprogramming features are not really interesting at runtime in Swig target languages.

+

SWIG correctly parses the template specialization, template types and values inside the <> block and the new helper functions: is_convertible, is_integral, is_const etc. +However, SWIG still explicitly requires concrete types when using the %template directive, so the C++ metaprogramming features are not really of interest at runtime in the target languages.

7.3.9 Uniform method for computing return type of function objects

-

Swig does not wrap the new result_of class introduced in the <functional> header and map the result_of::type to the concrete type yet. For example:

+

SWIG does not wrap the new result_of class introduced in the <functional> header and map the result_of::type to the concrete type yet. For example:

 %inline %{
 #include <functional>
@@ -686,9 +687,9 @@ typename std::result_of<Fun(Arg)>::type test_result_impl(Fun fun, Arg arg)
 
 
 >>> test_result_impl(SQUARE, 5.0)
-<Swig Object of type 'std::result_of< Fun(Arg) >::type *' at 0x7faf99ed8a50>
+<SWIG Object of type 'std::result_of< Fun(Arg) >::type *' at 0x7faf99ed8a50>
 
-

User should use decltype() where possible for now.

+

Instead, please use decltype() where possible for now.

From 7f5326020352e7df3d953f2cafbee734a79ab815 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 6 Mar 2010 00:51:54 +0000 Subject: [PATCH 0048/1160] merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11905 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- ANNOUNCE | 10 +- COPYRIGHT | 63 + Doc/Manual/Sections.html | 2 +- Examples/GIFPlot/Chicken/check.list | 3 - Examples/GIFPlot/Chicken/full/Makefile | 28 - Examples/GIFPlot/Chicken/full/README | 6 - Examples/GIFPlot/Chicken/full/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Chicken/full/gifplot.i | 26 - .../GIFPlot/Chicken/full/test-gifplot.scm | 66 - Examples/GIFPlot/Chicken/simple/Makefile | 28 - Examples/GIFPlot/Chicken/simple/README | 5 - Examples/GIFPlot/Chicken/simple/simple.i | 34 - .../GIFPlot/Chicken/simple/test-simple.scm | 29 - Examples/GIFPlot/Common-Lisp/full/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Common-Lisp/full/gifplot.i | 21 - Examples/GIFPlot/Common-Lisp/full/runme.lisp | 59 - Examples/GIFPlot/Guile/check.list | 3 - Examples/GIFPlot/Guile/full/Makefile | 28 - Examples/GIFPlot/Guile/full/README | 8 - Examples/GIFPlot/Guile/full/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Guile/full/gifplot.i | 21 - Examples/GIFPlot/Guile/full/runme.scm | 66 - Examples/GIFPlot/Guile/simple/Makefile | 28 - Examples/GIFPlot/Guile/simple/README | 11 - Examples/GIFPlot/Guile/simple/runme.scm | 30 - Examples/GIFPlot/Guile/simple/simple.i | 34 - Examples/GIFPlot/Include/gifplot.h | 333 --- Examples/GIFPlot/Interface/gifplot.i | 264 -- Examples/GIFPlot/Java/check.list | 4 - Examples/GIFPlot/Java/full/Makefile | 20 - Examples/GIFPlot/Java/full/README | 8 - Examples/GIFPlot/Java/full/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Java/full/gifplot.i | 15 - Examples/GIFPlot/Java/full/runme.java | 75 - Examples/GIFPlot/Java/shadow/Makefile | 21 - Examples/GIFPlot/Java/shadow/README | 5 - Examples/GIFPlot/Java/shadow/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Java/shadow/runme.java | 76 - Examples/GIFPlot/Java/simple/Makefile | 21 - Examples/GIFPlot/Java/simple/README | 5 - Examples/GIFPlot/Java/simple/runme.java | 41 - Examples/GIFPlot/Java/simple/simple.i | 38 - Examples/GIFPlot/Lib/Makefile.in | 22 - Examples/GIFPlot/Lib/color.c | 143 -- Examples/GIFPlot/Lib/font.c | 705 ------ Examples/GIFPlot/Lib/frame.c | 924 ------- Examples/GIFPlot/Lib/gif.c | 672 ----- Examples/GIFPlot/Lib/matrix.c | 343 --- Examples/GIFPlot/Lib/pixmap.c | 159 -- Examples/GIFPlot/Lib/plot2d.c | 445 ---- Examples/GIFPlot/Lib/plot3d.c | 2181 ----------------- Examples/GIFPlot/Makefile.in | 23 - Examples/GIFPlot/Ocaml/check.list | 3 - Examples/GIFPlot/Ocaml/full/Makefile | 33 - Examples/GIFPlot/Ocaml/full/README | 8 - Examples/GIFPlot/Ocaml/full/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Ocaml/full/gifplot.i | 15 - Examples/GIFPlot/Ocaml/full/runme.ml | 87 - Examples/GIFPlot/Ocaml/simple/Makefile | 33 - Examples/GIFPlot/Ocaml/simple/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Ocaml/simple/runme.ml | 35 - Examples/GIFPlot/Ocaml/simple/simple.i | 33 - Examples/GIFPlot/Perl5/check.list | 4 - Examples/GIFPlot/Perl5/full/Makefile | 24 - Examples/GIFPlot/Perl5/full/README | 8 - Examples/GIFPlot/Perl5/full/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Perl5/full/gifplot.i | 15 - Examples/GIFPlot/Perl5/full/runme.pl | 68 - Examples/GIFPlot/Perl5/shadow/Makefile | 25 - Examples/GIFPlot/Perl5/shadow/README | 2 - Examples/GIFPlot/Perl5/shadow/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Perl5/shadow/runme.pl | 68 - Examples/GIFPlot/Perl5/simple/Makefile | 24 - Examples/GIFPlot/Perl5/simple/README | 5 - Examples/GIFPlot/Perl5/simple/runme.pl | 28 - Examples/GIFPlot/Perl5/simple/simple.i | 38 - Examples/GIFPlot/Php/check.list | 3 - Examples/GIFPlot/Php/full/Makefile | 20 - Examples/GIFPlot/Php/full/README | 4 - Examples/GIFPlot/Php/full/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Php/full/gifplot.i | 15 - Examples/GIFPlot/Php/full/runme.php | 78 - Examples/GIFPlot/Php/shadow/Makefile | 19 - Examples/GIFPlot/Php/shadow/README | 2 - Examples/GIFPlot/Php/shadow/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Php/shadow/runme.php | 79 - Examples/GIFPlot/Php/simple/Makefile | 20 - Examples/GIFPlot/Php/simple/README | 5 - Examples/GIFPlot/Php/simple/runme.php | 32 - Examples/GIFPlot/Php/simple/simple.i | 38 - Examples/GIFPlot/Pike/check.list | 2 - Examples/GIFPlot/Pike/simple/Makefile | 24 - Examples/GIFPlot/Pike/simple/README | 5 - Examples/GIFPlot/Pike/simple/runme.pike | 30 - Examples/GIFPlot/Pike/simple/simple.i | 38 - Examples/GIFPlot/Python/check.list | 4 - Examples/GIFPlot/Python/full/Makefile | 26 - Examples/GIFPlot/Python/full/README | 8 - Examples/GIFPlot/Python/full/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Python/full/gifplot.i | 15 - Examples/GIFPlot/Python/full/runme.py | 64 - Examples/GIFPlot/Python/shadow/Makefile | 27 - Examples/GIFPlot/Python/shadow/README | 8 - Examples/GIFPlot/Python/shadow/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Python/shadow/runme.py | 62 - Examples/GIFPlot/Python/simple/Makefile | 26 - Examples/GIFPlot/Python/simple/README | 5 - Examples/GIFPlot/Python/simple/runme.py | 27 - Examples/GIFPlot/Python/simple/simple.i | 38 - Examples/GIFPlot/README | 59 - Examples/GIFPlot/Ruby/check.list | 4 - Examples/GIFPlot/Ruby/full/Makefile | 24 - Examples/GIFPlot/Ruby/full/README | 8 - Examples/GIFPlot/Ruby/full/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Ruby/full/gifplot.i | 15 - Examples/GIFPlot/Ruby/full/runme.rb | 66 - Examples/GIFPlot/Ruby/shadow/Makefile | 25 - Examples/GIFPlot/Ruby/shadow/README | 5 - Examples/GIFPlot/Ruby/shadow/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Ruby/shadow/runme.rb | 66 - Examples/GIFPlot/Ruby/simple/Makefile | 24 - Examples/GIFPlot/Ruby/simple/README | 5 - Examples/GIFPlot/Ruby/simple/runme.rb | 27 - Examples/GIFPlot/Ruby/simple/simple.i | 38 - Examples/GIFPlot/Tcl/check.list | 4 - Examples/GIFPlot/Tcl/full/Makefile | 24 - Examples/GIFPlot/Tcl/full/README | 8 - Examples/GIFPlot/Tcl/full/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Tcl/full/gifplot.i | 15 - Examples/GIFPlot/Tcl/full/runme.tcl | 67 - Examples/GIFPlot/Tcl/mandel/Makefile | 24 - Examples/GIFPlot/Tcl/mandel/README | 6 - Examples/GIFPlot/Tcl/mandel/cmap | Bin 768 -> 0 bytes Examples/GIFPlot/Tcl/mandel/display.tcl | 68 - Examples/GIFPlot/Tcl/mandel/mandel.i | 47 - Examples/GIFPlot/Tcl/mandel/mandel.tcl | 170 -- Examples/GIFPlot/Tcl/simple/Makefile | 24 - Examples/GIFPlot/Tcl/simple/README | 5 - Examples/GIFPlot/Tcl/simple/runme.tcl | 27 - Examples/GIFPlot/Tcl/simple/simple.i | 38 - Examples/chicken/zlib/Makefile | 28 - Examples/chicken/zlib/README.html | 1666 ------------- Examples/chicken/zlib/example.i | 76 - Examples/chicken/zlib/test-zlib.scm | 41 - Examples/guile/check.list | 1 - Examples/lua/lua.c | 1 - .../test-suite/csharp/li_std_map_runme.cs | 5 - Examples/test-suite/li_std_queue.i | 11 +- Examples/test-suite/li_std_set.i | 22 +- Examples/test-suite/li_std_stack.i | 11 +- .../ruby/ruby_li_std_speed_runme.rb | 3 - Examples/test-suite/ruby_li_std_speed.i | 11 +- Examples/xml/example_gif.i | 329 --- LICENSE | 109 +- LICENSE-GPL | 674 +++++ LICENSE-UNIVERSITIES | 95 + Lib/allegrocl/allegrocl.swg | 2 - Lib/allegrocl/longlongs.i | 3 - Lib/allegrocl/std_list.i | 3 - Lib/allegrocl/std_string.i | 3 - Lib/attribute.i | 3 - Lib/carrays.i | 3 - Lib/cdata.i | 3 - Lib/chicken/chicken.swg | 3 - Lib/chicken/chickenrun.swg | 4 - Lib/chicken/multi-generic.scm | 2 +- Lib/chicken/std_string.i | 3 - Lib/chicken/typemaps.i | 3 - Lib/clisp/clisp.swg | 3 - Lib/cmalloc.i | 3 - Lib/constraints.i | 3 - Lib/cpointer.i | 3 - Lib/csharp/arrays_csharp.i | 3 - Lib/csharp/csharp.swg | 3 - Lib/csharp/csharphead.swg | 3 - Lib/csharp/director.swg | 3 - Lib/csharp/enums.swg | 3 - Lib/csharp/enumsimple.swg | 3 - Lib/csharp/enumtypesafe.swg | 3 - Lib/csharp/std_except.i | 3 - Lib/csharp/std_map.i | 3 - Lib/csharp/std_pair.i | 3 - Lib/csharp/std_string.i | 3 - Lib/csharp/std_vector.i | 3 - Lib/csharp/std_wstring.i | 3 - Lib/csharp/stl.i | 3 - Lib/csharp/typemaps.i | 3 - Lib/csharp/wchar.i | 3 - Lib/cstring.i | 3 - Lib/cwstring.i | 3 - Lib/exception.i | 3 - Lib/gcj/cni.swg | 3 - Lib/guile/common.scm | 6 - Lib/guile/cplusplus.i | 3 - Lib/guile/guile.i | 3 - Lib/guile/guile_gh.swg | 3 - Lib/guile/guile_gh_run.swg | 3 - Lib/guile/guile_scm.swg | 3 - Lib/guile/guile_scm_run.swg | 3 - Lib/guile/guilemain.i | 3 - Lib/guile/interpreter.i | 3 - Lib/guile/list-vector.i | 3 - Lib/guile/pointer-in-out.i | 3 - Lib/guile/ports.i | 3 - Lib/guile/std_common.i | 3 - Lib/guile/std_map.i | 3 - Lib/guile/std_pair.i | 3 - Lib/guile/std_string.i | 3 - Lib/guile/std_vector.i | 3 - Lib/guile/stl.i | 3 - Lib/guile/typemaps.i | 3 - Lib/inttypes.i | 3 - Lib/java/arrays_java.i | 3 - Lib/java/director.swg | 3 - Lib/java/enums.swg | 3 - Lib/java/enumsimple.swg | 3 - Lib/java/enumtypesafe.swg | 3 - Lib/java/enumtypeunsafe.swg | 3 - Lib/java/java.swg | 3 - Lib/java/javahead.swg | 3 - Lib/java/std_except.i | 3 - Lib/java/std_map.i | 3 - Lib/java/std_pair.i | 3 - Lib/java/std_string.i | 3 - Lib/java/std_vector.i | 3 - Lib/java/std_wstring.i | 3 - Lib/java/stl.i | 3 - Lib/java/typemaps.i | 3 - Lib/java/various.i | 3 - Lib/lua/_std_common.i | 3 - Lib/lua/lua.swg | 3 - Lib/lua/lua_fnptr.i | 3 - Lib/lua/luarun.swg | 3 - Lib/lua/luaruntime.swg | 3 - Lib/lua/luatypemaps.swg | 3 - Lib/lua/std_except.i | 3 - Lib/lua/std_map.i | 3 - Lib/lua/std_pair.i | 3 - Lib/lua/std_string.i | 3 - Lib/lua/std_vector.i | 3 - Lib/lua/stl.i | 3 - Lib/lua/typemaps.i | 3 - Lib/lua/wchar.i | 6 +- Lib/math.i | 3 - Lib/modula3/modula3.swg | 3 - Lib/modula3/modula3head.swg | 3 - Lib/modula3/typemaps.i | 3 - Lib/mzscheme/mzrun.swg | 3 - Lib/mzscheme/mzscheme.swg | 3 - Lib/mzscheme/std_common.i | 3 - Lib/mzscheme/std_map.i | 3 - Lib/mzscheme/std_pair.i | 3 - Lib/mzscheme/std_string.i | 3 - Lib/mzscheme/std_vector.i | 3 - Lib/mzscheme/stl.i | 3 - Lib/mzscheme/typemaps.i | 3 - Lib/ocaml/cstring.i | 3 - Lib/ocaml/director.swg | 3 - Lib/ocaml/ocaml.i | 3 - Lib/ocaml/ocamldec.swg | 3 - Lib/ocaml/std_common.i | 3 - Lib/ocaml/std_deque.i | 3 - Lib/ocaml/std_list.i | 3 - Lib/ocaml/std_map.i | 3 - Lib/ocaml/std_pair.i | 3 - Lib/ocaml/std_string.i | 3 - Lib/ocaml/std_vector.i | 3 - Lib/ocaml/stl.i | 3 - Lib/ocaml/typecheck.i | 3 - Lib/ocaml/typemaps.i | 3 - Lib/octave/octcontainer.swg | 3 - Lib/octave/octiterators.swg | 3 - Lib/perl5/perlmain.i | 3 - Lib/perl5/reference.i | 3 - Lib/perl5/std_common.i | 3 - Lib/perl5/std_list.i | 3 - Lib/perl5/std_map.i | 3 - Lib/perl5/std_pair.i | 3 - Lib/perl5/std_vector.i | 3 - Lib/perl5/stl.i | 3 - Lib/perl5/typemaps.i | 3 - Lib/php/const.i | 3 - Lib/php/globalvar.i | 3 - Lib/php/php.swg | 3 - Lib/php/phpkw.swg | 3 - Lib/php/phprun.swg | 3 - Lib/php/std_common.i | 3 - Lib/php/std_map.i | 3 - Lib/php/std_pair.i | 3 - Lib/php/std_string.i | 3 - Lib/php/std_vector.i | 3 - Lib/php/stl.i | 3 - Lib/php/typemaps.i | 3 - Lib/pike/pike.swg | 3 - Lib/pike/pikerun.swg | 3 - Lib/pike/std_string.i | 3 - Lib/pointer.i | 3 - Lib/python/ccomplex.i | 3 - Lib/python/director.swg | 3 - Lib/python/embed15.i | 3 - Lib/python/file.i | 4 - Lib/python/pycontainer.swg | 3 - Lib/python/pyiterators.swg | 3 - Lib/python/pyrun.swg | 3 - Lib/python/typemaps.i | 3 - Lib/ruby/director.swg | 3 - Lib/ruby/rubyautodoc.swg | 15 +- Lib/ruby/rubycontainer.swg | 3 - Lib/ruby/rubycontainer_extended.swg | 24 +- Lib/ruby/rubyiterators.swg | 3 - Lib/ruby/rubyprimtypes.swg | 4 - Lib/ruby/rubyrun.swg | 3 - Lib/ruby/rubystdautodoc.swg | 12 +- Lib/ruby/rubytracking.swg | 3 - Lib/ruby/rubywstrings.swg | 20 +- Lib/ruby/stl.i | 3 - Lib/ruby/typemaps.i | 3 - Lib/std/_std_deque.i | 3 - Lib/std_except.i | 3 - Lib/stdint.i | 3 - Lib/stl.i | 3 - Lib/swigarch.i | 3 - Lib/swigrun.i | 3 - Lib/tcl/mactclinit.c | 93 - Lib/tcl/mactkinit.c | 3 - Lib/tcl/std_common.i | 3 - Lib/tcl/std_pair.i | 3 - Lib/tcl/std_vector.i | 3 - Lib/tcl/stl.i | 3 - Lib/tcl/tcl8.swg | 3 - Lib/tcl/tclinterp.i | 3 - Lib/tcl/tclopers.swg | 3 - Lib/tcl/tclresult.i | 3 - Lib/tcl/tclrun.swg | 3 - Lib/tcl/tclsh.i | 3 - Lib/tcl/tclwstrings.swg | 3 - Lib/tcl/typemaps.i | 3 - Lib/tcl/wish.i | 3 - Lib/typemaps/attribute.swg | 3 - Lib/typemaps/carrays.swg | 3 - Lib/typemaps/cdata.swg | 3 - Lib/typemaps/cmalloc.swg | 3 - Lib/typemaps/cpointer.swg | 3 - Lib/typemaps/cstrings.swg | 3 - Lib/typemaps/exception.swg | 3 - Lib/typemaps/ptrtypes.swg | 3 - Lib/typemaps/swigtypemaps.swg | 3 - Lib/typemaps/typemaps.swg | 3 - Lib/uffi/uffi.swg | 2 - Lib/wchar.i | 3 - Lib/windows.i | 3 - Makefile.in | 56 +- README | 57 +- Source/CParse/cparse.h | 8 +- Source/CParse/cscanner.c | 8 +- Source/CParse/parser.y | 8 +- Source/CParse/templ.c | 8 +- Source/CParse/util.c | 8 +- Source/DOH/base.c | 12 +- Source/DOH/doh.h | 14 +- Source/DOH/dohint.h | 15 +- Source/DOH/file.c | 12 +- Source/DOH/fio.c | 12 +- Source/DOH/hash.c | 12 +- Source/DOH/list.c | 12 +- Source/DOH/memory.c | 12 +- Source/DOH/string.c | 12 +- Source/DOH/void.c | 12 +- Source/Include/swigwarn.h | 10 +- Source/Modules/allegrocl.cxx | 8 +- Source/Modules/allocate.cxx | 8 +- Source/Modules/browser.cxx | 8 +- Source/Modules/cffi.cxx | 8 +- Source/Modules/chicken.cxx | 8 +- Source/Modules/clisp.cxx | 8 +- Source/Modules/contract.cxx | 8 +- Source/Modules/csharp.cxx | 8 +- Source/Modules/directors.cxx | 8 +- Source/Modules/emit.cxx | 8 +- Source/Modules/guile.cxx | 8 +- Source/Modules/java.cxx | 8 +- Source/Modules/lang.cxx | 8 +- Source/Modules/lua.cxx | 8 +- Source/Modules/main.cxx | 8 +- Source/Modules/modula3.cxx | 8 +- Source/Modules/module.cxx | 8 +- Source/Modules/mzscheme.cxx | 8 +- Source/Modules/ocaml.cxx | 8 +- Source/Modules/octave.cxx | 8 +- Source/Modules/overload.cxx | 8 +- Source/Modules/perl5.cxx | 12 +- Source/Modules/php.cxx | 8 +- Source/Modules/pike.cxx | 8 +- Source/Modules/python.cxx | 8 +- Source/Modules/r.cxx | 8 +- Source/Modules/ruby.cxx | 8 +- Source/Modules/s-exp.cxx | 8 +- Source/Modules/swigmain.cxx | 12 +- Source/Modules/swigmod.h | 8 +- Source/Modules/tcl8.cxx | 8 +- Source/Modules/typepass.cxx | 8 +- Source/Modules/uffi.cxx | 8 +- Source/Modules/utils.cxx | 8 +- Source/Modules/xml.cxx | 8 +- Source/Preprocessor/cpp.c | 8 +- Source/Preprocessor/expr.c | 8 +- Source/Preprocessor/preprocessor.h | 8 +- Source/Swig/cwrap.c | 8 +- Source/Swig/deprecate.c | 8 +- Source/Swig/error.c | 8 +- Source/Swig/fragment.c | 8 +- Source/Swig/getopt.c | 8 +- Source/Swig/include.c | 8 +- Source/Swig/misc.c | 8 +- Source/Swig/naming.c | 8 +- Source/Swig/parms.c | 8 +- Source/Swig/scanner.c | 8 +- Source/Swig/stype.c | 8 +- Source/Swig/swig.h | 8 +- Source/Swig/swigfile.h | 8 +- Source/Swig/swigopt.h | 8 +- Source/Swig/swigparm.h | 8 +- Source/Swig/swigscan.h | 8 +- Source/Swig/swigtree.h | 8 +- Source/Swig/swigwrap.h | 8 +- Source/Swig/symbol.c | 8 +- Source/Swig/tree.c | 8 +- Source/Swig/typemap.c | 8 +- Source/Swig/typeobj.c | 8 +- Source/Swig/typesys.c | 8 +- Source/Swig/wrapfunc.c | 8 +- configure.in | 4 +- 432 files changed, 1381 insertions(+), 12563 deletions(-) create mode 100644 COPYRIGHT delete mode 100644 Examples/GIFPlot/Chicken/check.list delete mode 100644 Examples/GIFPlot/Chicken/full/Makefile delete mode 100644 Examples/GIFPlot/Chicken/full/README delete mode 100644 Examples/GIFPlot/Chicken/full/cmap delete mode 100644 Examples/GIFPlot/Chicken/full/gifplot.i delete mode 100644 Examples/GIFPlot/Chicken/full/test-gifplot.scm delete mode 100644 Examples/GIFPlot/Chicken/simple/Makefile delete mode 100644 Examples/GIFPlot/Chicken/simple/README delete mode 100644 Examples/GIFPlot/Chicken/simple/simple.i delete mode 100644 Examples/GIFPlot/Chicken/simple/test-simple.scm delete mode 100644 Examples/GIFPlot/Common-Lisp/full/cmap delete mode 100644 Examples/GIFPlot/Common-Lisp/full/gifplot.i delete mode 100644 Examples/GIFPlot/Common-Lisp/full/runme.lisp delete mode 100644 Examples/GIFPlot/Guile/check.list delete mode 100644 Examples/GIFPlot/Guile/full/Makefile delete mode 100644 Examples/GIFPlot/Guile/full/README delete mode 100644 Examples/GIFPlot/Guile/full/cmap delete mode 100644 Examples/GIFPlot/Guile/full/gifplot.i delete mode 100644 Examples/GIFPlot/Guile/full/runme.scm delete mode 100644 Examples/GIFPlot/Guile/simple/Makefile delete mode 100644 Examples/GIFPlot/Guile/simple/README delete mode 100644 Examples/GIFPlot/Guile/simple/runme.scm delete mode 100644 Examples/GIFPlot/Guile/simple/simple.i delete mode 100644 Examples/GIFPlot/Include/gifplot.h delete mode 100644 Examples/GIFPlot/Interface/gifplot.i delete mode 100644 Examples/GIFPlot/Java/check.list delete mode 100644 Examples/GIFPlot/Java/full/Makefile delete mode 100644 Examples/GIFPlot/Java/full/README delete mode 100644 Examples/GIFPlot/Java/full/cmap delete mode 100644 Examples/GIFPlot/Java/full/gifplot.i delete mode 100644 Examples/GIFPlot/Java/full/runme.java delete mode 100644 Examples/GIFPlot/Java/shadow/Makefile delete mode 100644 Examples/GIFPlot/Java/shadow/README delete mode 100644 Examples/GIFPlot/Java/shadow/cmap delete mode 100644 Examples/GIFPlot/Java/shadow/runme.java delete mode 100644 Examples/GIFPlot/Java/simple/Makefile delete mode 100644 Examples/GIFPlot/Java/simple/README delete mode 100644 Examples/GIFPlot/Java/simple/runme.java delete mode 100644 Examples/GIFPlot/Java/simple/simple.i delete mode 100644 Examples/GIFPlot/Lib/Makefile.in delete mode 100644 Examples/GIFPlot/Lib/color.c delete mode 100644 Examples/GIFPlot/Lib/font.c delete mode 100644 Examples/GIFPlot/Lib/frame.c delete mode 100644 Examples/GIFPlot/Lib/gif.c delete mode 100644 Examples/GIFPlot/Lib/matrix.c delete mode 100644 Examples/GIFPlot/Lib/pixmap.c delete mode 100644 Examples/GIFPlot/Lib/plot2d.c delete mode 100644 Examples/GIFPlot/Lib/plot3d.c delete mode 100644 Examples/GIFPlot/Makefile.in delete mode 100644 Examples/GIFPlot/Ocaml/check.list delete mode 100644 Examples/GIFPlot/Ocaml/full/Makefile delete mode 100644 Examples/GIFPlot/Ocaml/full/README delete mode 100644 Examples/GIFPlot/Ocaml/full/cmap delete mode 100644 Examples/GIFPlot/Ocaml/full/gifplot.i delete mode 100644 Examples/GIFPlot/Ocaml/full/runme.ml delete mode 100644 Examples/GIFPlot/Ocaml/simple/Makefile delete mode 100644 Examples/GIFPlot/Ocaml/simple/cmap delete mode 100644 Examples/GIFPlot/Ocaml/simple/runme.ml delete mode 100644 Examples/GIFPlot/Ocaml/simple/simple.i delete mode 100644 Examples/GIFPlot/Perl5/check.list delete mode 100644 Examples/GIFPlot/Perl5/full/Makefile delete mode 100644 Examples/GIFPlot/Perl5/full/README delete mode 100644 Examples/GIFPlot/Perl5/full/cmap delete mode 100644 Examples/GIFPlot/Perl5/full/gifplot.i delete mode 100644 Examples/GIFPlot/Perl5/full/runme.pl delete mode 100644 Examples/GIFPlot/Perl5/shadow/Makefile delete mode 100644 Examples/GIFPlot/Perl5/shadow/README delete mode 100644 Examples/GIFPlot/Perl5/shadow/cmap delete mode 100644 Examples/GIFPlot/Perl5/shadow/runme.pl delete mode 100644 Examples/GIFPlot/Perl5/simple/Makefile delete mode 100644 Examples/GIFPlot/Perl5/simple/README delete mode 100644 Examples/GIFPlot/Perl5/simple/runme.pl delete mode 100644 Examples/GIFPlot/Perl5/simple/simple.i delete mode 100644 Examples/GIFPlot/Php/check.list delete mode 100644 Examples/GIFPlot/Php/full/Makefile delete mode 100644 Examples/GIFPlot/Php/full/README delete mode 100644 Examples/GIFPlot/Php/full/cmap delete mode 100644 Examples/GIFPlot/Php/full/gifplot.i delete mode 100644 Examples/GIFPlot/Php/full/runme.php delete mode 100644 Examples/GIFPlot/Php/shadow/Makefile delete mode 100644 Examples/GIFPlot/Php/shadow/README delete mode 100644 Examples/GIFPlot/Php/shadow/cmap delete mode 100644 Examples/GIFPlot/Php/shadow/runme.php delete mode 100644 Examples/GIFPlot/Php/simple/Makefile delete mode 100644 Examples/GIFPlot/Php/simple/README delete mode 100644 Examples/GIFPlot/Php/simple/runme.php delete mode 100644 Examples/GIFPlot/Php/simple/simple.i delete mode 100644 Examples/GIFPlot/Pike/check.list delete mode 100644 Examples/GIFPlot/Pike/simple/Makefile delete mode 100644 Examples/GIFPlot/Pike/simple/README delete mode 100644 Examples/GIFPlot/Pike/simple/runme.pike delete mode 100644 Examples/GIFPlot/Pike/simple/simple.i delete mode 100644 Examples/GIFPlot/Python/check.list delete mode 100644 Examples/GIFPlot/Python/full/Makefile delete mode 100644 Examples/GIFPlot/Python/full/README delete mode 100644 Examples/GIFPlot/Python/full/cmap delete mode 100644 Examples/GIFPlot/Python/full/gifplot.i delete mode 100644 Examples/GIFPlot/Python/full/runme.py delete mode 100644 Examples/GIFPlot/Python/shadow/Makefile delete mode 100644 Examples/GIFPlot/Python/shadow/README delete mode 100644 Examples/GIFPlot/Python/shadow/cmap delete mode 100644 Examples/GIFPlot/Python/shadow/runme.py delete mode 100644 Examples/GIFPlot/Python/simple/Makefile delete mode 100644 Examples/GIFPlot/Python/simple/README delete mode 100644 Examples/GIFPlot/Python/simple/runme.py delete mode 100644 Examples/GIFPlot/Python/simple/simple.i delete mode 100644 Examples/GIFPlot/README delete mode 100644 Examples/GIFPlot/Ruby/check.list delete mode 100644 Examples/GIFPlot/Ruby/full/Makefile delete mode 100644 Examples/GIFPlot/Ruby/full/README delete mode 100644 Examples/GIFPlot/Ruby/full/cmap delete mode 100644 Examples/GIFPlot/Ruby/full/gifplot.i delete mode 100644 Examples/GIFPlot/Ruby/full/runme.rb delete mode 100644 Examples/GIFPlot/Ruby/shadow/Makefile delete mode 100644 Examples/GIFPlot/Ruby/shadow/README delete mode 100644 Examples/GIFPlot/Ruby/shadow/cmap delete mode 100644 Examples/GIFPlot/Ruby/shadow/runme.rb delete mode 100644 Examples/GIFPlot/Ruby/simple/Makefile delete mode 100644 Examples/GIFPlot/Ruby/simple/README delete mode 100644 Examples/GIFPlot/Ruby/simple/runme.rb delete mode 100644 Examples/GIFPlot/Ruby/simple/simple.i delete mode 100644 Examples/GIFPlot/Tcl/check.list delete mode 100644 Examples/GIFPlot/Tcl/full/Makefile delete mode 100644 Examples/GIFPlot/Tcl/full/README delete mode 100644 Examples/GIFPlot/Tcl/full/cmap delete mode 100644 Examples/GIFPlot/Tcl/full/gifplot.i delete mode 100644 Examples/GIFPlot/Tcl/full/runme.tcl delete mode 100644 Examples/GIFPlot/Tcl/mandel/Makefile delete mode 100644 Examples/GIFPlot/Tcl/mandel/README delete mode 100644 Examples/GIFPlot/Tcl/mandel/cmap delete mode 100644 Examples/GIFPlot/Tcl/mandel/display.tcl delete mode 100644 Examples/GIFPlot/Tcl/mandel/mandel.i delete mode 100644 Examples/GIFPlot/Tcl/mandel/mandel.tcl delete mode 100644 Examples/GIFPlot/Tcl/simple/Makefile delete mode 100644 Examples/GIFPlot/Tcl/simple/README delete mode 100644 Examples/GIFPlot/Tcl/simple/runme.tcl delete mode 100644 Examples/GIFPlot/Tcl/simple/simple.i delete mode 100644 Examples/chicken/zlib/Makefile delete mode 100644 Examples/chicken/zlib/README.html delete mode 100644 Examples/chicken/zlib/example.i delete mode 100644 Examples/chicken/zlib/test-zlib.scm delete mode 100644 Examples/xml/example_gif.i create mode 100644 LICENSE-GPL create mode 100644 LICENSE-UNIVERSITIES delete mode 100644 Lib/tcl/mactclinit.c diff --git a/ANNOUNCE b/ANNOUNCE index 9ef41142a..2595f7a55 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,10 +1,10 @@ -*** ANNOUNCE: SWIG 1.3.40 (in progress) *** +*** ANNOUNCE: SWIG 2.0.0 (in progress) *** http://www.swig.org -We're pleased to announce SWIG-1.3.40, the latest installment in the -SWIG development effort. SWIG-1.3.40 includes a number of bug fixes +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. What is SWIG? @@ -24,11 +24,11 @@ Availability: ------------- The release is available for download on Sourceforge at - http://prdownloads.sourceforge.net/swig/swig-1.3.40.tar.gz + http://prdownloads.sourceforge.net/swig/swig-2.0.0.tar.gz A Windows version is also available at - http://prdownloads.sourceforge.net/swig/swigwin-1.3.40.zip + http://prdownloads.sourceforge.net/swig/swigwin-2.0.0.zip Please report problems with this release to the swig-dev mailing list, details at http://www.swig.org/mail.html. diff --git a/COPYRIGHT b/COPYRIGHT new file mode 100644 index 000000000..45f9d6b45 --- /dev/null +++ b/COPYRIGHT @@ -0,0 +1,63 @@ +SWIG Copyright and Authors +-------------------------- + +Copyright (c) 1995-2010 The SWIG Developers +Copyright (c) 2005-2006 Arizona Board of Regents (University of Arizona). +Copyright (c) 1998-2005 University of Chicago. +Copyright (c) 1995-1998 The University of Utah and the Regents of the University of California + +Portions also copyrighted by: + Network Applied Communication Laboratory, Inc + Information-technology Promotion Agency, Japan + +Active SWIG Developers: + William Fulton (wsf@fultondesigns.co.uk) (SWIG core, Java, C#, Windows, Cygwin) + Olly Betts (olly@survex.com) (PHP) + Joseph Wang (joequant@gmail.com) (R) + Xavier Delacour (xavier.delacour@gmail.com) (Octave) + +Past SWIG developers and major contributors include: + Dave Beazley (dave-swig@dabeaz.com) (SWIG core, Python, Tcl, Perl) + Henning Thielemann (swig@henning-thielemann.de) (Modula3) + Matthias Köppe (mkoeppe@mail.math.uni-magdeburg.de) (Guile, MzScheme) + Luigi Ballabio (luigi.ballabio@fastwebnet.it) (STL wrapping) + Mikel Bancroft (mikel@franz.com) (Allegro CL) + Surendra Singhi (efuzzyone@netscape.net) (CLISP, CFFI) + Marcelo Matus (mmatus@acms.arizona.edu) (SWIG core, Python, UTL[python,perl,tcl,ruby]) + Art Yerkes (ayerkes@speakeasy.net) (Ocaml) + Lyle Johnson (lyle@users.sourceforge.net) (Ruby) + Charlie Savage (cfis@interserv.com) (Ruby) + Thien-Thi Nguyen (ttn@glug.org) (build/test/misc) + Richard Palmer (richard@magicality.org) (PHP) + Sam Liddicott - Anonova Ltd (saml@liddicott.com) (PHP) + Tim Hockin - Sun Microsystems (thockin@sun.com) (PHP) + Kevin Ruland (PHP) + Shibukawa Yoshiki (Japanese Translation) + Jason Stewart (jason@openinformatics.com) (Perl5) + Loic Dachary (Perl5) + David Fletcher (Perl5) + Gary Holt (Perl5) + Masaki Fukushima (Ruby) + Scott Michel (scottm@cs.ucla.edu) (Java directors) + Tiger Feng (songyanf@cs.uchicago.edu) (SWIG core) + Mark Rose (mrose@stm.lbl.gov) (Directors) + Jonah Beckford (beckford@usermail.com) (CHICKEN) + Ahmon Dancy (dancy@franz.com) (Allegro CL) + Dirk Gerrits (Allegro CL) + Neil Cawse (C#) + Harco de Hilster (Java) + Alexey Dyachenko (dyachenko@fromru.com) (Tcl) + Bob Techentin (Tcl) + Martin Froehlich (Guile) + Marcio Luis Teixeira (Guile) + Duncan Temple Lang (R) + Miklos Vajna (PHP directors) + Mark Gossage (mark@gossage.cjb.net) (Lua) + Gonzalo Garramuno (ggarra@advancedsl.com.ar) (Ruby, Ruby's UTL) + John Lenz (Guile, MzScheme updates, Chicken module, runtime system) + +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). + diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 789efc129..ab47ed8ee 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

SWIG-1.3 Development Documentation

-Last update : SWIG-1.3.40 (in progress) +Last update : SWIG-2.0.0 (in progress)

Sections

diff --git a/Examples/GIFPlot/Chicken/check.list b/Examples/GIFPlot/Chicken/check.list deleted file mode 100644 index e75ee586a..000000000 --- a/Examples/GIFPlot/Chicken/check.list +++ /dev/null @@ -1,3 +0,0 @@ -# see top-level Makefile.in -full -simple diff --git a/Examples/GIFPlot/Chicken/full/Makefile b/Examples/GIFPlot/Chicken/full/Makefile deleted file mode 100644 index 2ae4fd7ea..000000000 --- a/Examples/GIFPlot/Chicken/full/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -INTERFACE = gifplot.i -SRCS = -CXXSRCS = -TARGET = gifplot -INCLUDE = -I. -I../../Include -SWIGOPT = -I../../Include -CFLAGS = -VARIANT = -LIBS = -L../.. -lgifplot -lm - -# comment the following two lines to build a dynamic so file -CHICKEN_MAIN = test-gifplot.scm -VARIANT = _static - -all:: $(TARGET) - -$(TARGET): $(INTERFACE) $(SRCS) - $(MAKE) -f $(TOP)/Makefile \ - SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ - INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='$(TARGET)' \ - SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) - -clean:: - $(MAKE) -f $(TOP)/Makefile chicken_clean - rm -f gifplot.scm image.gif - rm -f $(TARGET) diff --git a/Examples/GIFPlot/Chicken/full/README b/Examples/GIFPlot/Chicken/full/README deleted file mode 100644 index e5ddd7af1..000000000 --- a/Examples/GIFPlot/Chicken/full/README +++ /dev/null @@ -1,6 +0,0 @@ -This example runs the entire gifplot.h header file through SWIG without -any changes. The Scheme program 'test-gifplot.scm' does something a -little more interesting. You'll have to go look at the header file to -get a complete listing of the functions. - -`make' will build a static binary. Run ./gifplot to test it. diff --git a/Examples/GIFPlot/Chicken/full/cmap b/Examples/GIFPlot/Chicken/full/cmap deleted file mode 100644 index a20c331a9573dd8443380680bfe2cc428780d8a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9ICexact (round (max (min cc 239) 0))))) - (gifplot:Plot3D-solidquad p3 x y z1 (+ x dx) y z2 (+ x dx) (+ y dy) - z3 x (+ y dy) z4 - (gifplot:int->Pixel (+ c 16)))) - (y-loop (+ y dy) (+ j 1))))) - (x-loop (+ x dx) (+ i 1))))))) - -(display "Making a nice 3D plot...\n") -(drawsolid) - -(gifplot:FrameBuffer-writeGIF frame cmap "image.gif") -(display "Wrote image.gif\n") diff --git a/Examples/GIFPlot/Chicken/simple/Makefile b/Examples/GIFPlot/Chicken/simple/Makefile deleted file mode 100644 index 484e58390..000000000 --- a/Examples/GIFPlot/Chicken/simple/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -INTERFACE = simple.i -SRCS = -CXXSRCS = -TARGET = simple -INCLUDE = -I. -I../../Include -SWIGOPT = -I../../Include -CFLAGS = -VARIANT = -LIBS = -L../.. -lgifplot -lm - -# comment the following two lines to build a dynamic so file -CHICKEN_MAIN = test-simple.scm -VARIANT = _static - -all:: $(TARGET) - -$(TARGET): $(INTERFACE) $(SRCS) - $(MAKE) -f $(TOP)/Makefile \ - SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ - INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='$(TARGET)' \ - SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) - -clean:: - $(MAKE) -f $(TOP)/Makefile chicken_clean - rm -f simple.scm image.gif - rm -f $(TARGET) diff --git a/Examples/GIFPlot/Chicken/simple/README b/Examples/GIFPlot/Chicken/simple/README deleted file mode 100644 index 3b138f381..000000000 --- a/Examples/GIFPlot/Chicken/simple/README +++ /dev/null @@ -1,5 +0,0 @@ -This is a very minimalistic example in which just a few functions -and constants from library are wrapped and used to draw some simple -shapes. - -`make' will build an exe. Run ./simple to test it. diff --git a/Examples/GIFPlot/Chicken/simple/simple.i b/Examples/GIFPlot/Chicken/simple/simple.i deleted file mode 100644 index 23ac8a856..000000000 --- a/Examples/GIFPlot/Chicken/simple/simple.i +++ /dev/null @@ -1,34 +0,0 @@ -/* This example shows a very simple interface wrapping a few - primitive declarations */ - -%module simple -%{ -#include "gifplot.h" -%} - -typedef unsigned int Pixel; - -/* Here are a few useful functions */ - -ColorMap *new_ColorMap(char *filename = 0); -void delete_ColorMap(ColorMap *cmap); - -FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height); -void delete_FrameBuffer(FrameBuffer *frame); -void FrameBuffer_clear(FrameBuffer *frame, Pixel color); -void FrameBuffer_line(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_box(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_circle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color); -int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename); - -/* And some useful constants, which we redefine (from gifplot.h) so - that SWIG sees them */ -#define BLACK 0 -#define WHITE 1 -#define RED 2 -#define GREEN 3 -#define BLUE 4 -#define YELLOW 5 -#define CYAN 6 -#define MAGENTA 7 - diff --git a/Examples/GIFPlot/Chicken/simple/test-simple.scm b/Examples/GIFPlot/Chicken/simple/test-simple.scm deleted file mode 100644 index 43250d8e9..000000000 --- a/Examples/GIFPlot/Chicken/simple/test-simple.scm +++ /dev/null @@ -1,29 +0,0 @@ -;;; Draw some simple shapes - -(declare (uses simple)) - -(display "Drawing some basic shapes\n") - -(define cmap (simple:new-ColorMap #f)) -(define f (simple:new-FrameBuffer 400 400)) - -;; Clear the picture -(simple:FrameBuffer-clear f (simple:BLACK)) - -;; Make a red box -(simple:FrameBuffer-box f 40 40 200 200 (simple:RED)) - -;; Make a blue circle -(simple:FrameBuffer-circle f 200 200 40 (simple:BLUE)) - -;; Make green line -(simple:FrameBuffer-line f 10 390 390 200 (simple:GREEN)) - -;; Write an image out to disk - -(simple:FrameBuffer-writeGIF f cmap "image.gif") -(display "Wrote image.gif\n") - -(simple:delete-FrameBuffer f) -(simple:delete-ColorMap cmap) - diff --git a/Examples/GIFPlot/Common-Lisp/full/cmap b/Examples/GIFPlot/Common-Lisp/full/cmap deleted file mode 100644 index a20c331a9573dd8443380680bfe2cc428780d8a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9IC&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9IC -#include -#include -#include -#include -#include - -#ifndef GIFPLOT_H - -#ifdef SWIG -%nodefault; -#endif - -/* Pixel is 8-bits */ - -typedef unsigned char Pixel; -typedef float Zvalue; - -/* ------------------------------------------------------------------------ - ColorMap - - Definition and methods for colormaps - ------------------------------------------------------------------------ */ - -typedef struct ColorMap { - unsigned char *cmap; - char *name; -} ColorMap; - -extern ColorMap *new_ColorMap(char *filename); -extern void delete_ColorMap(ColorMap *c); -extern void ColorMap_default(ColorMap *c); -extern void ColorMap_assign(ColorMap *c, int index, int r, int g, int b); -extern int ColorMap_getitem(ColorMap *c, int index); -extern void ColorMap_setitem(ColorMap *c, int index, int value); -extern int ColorMap_write(ColorMap *c, char *filename); - -/* Some default colors */ - -#define BLACK 0 -#define WHITE 1 -#define RED 2 -#define GREEN 3 -#define BLUE 4 -#define YELLOW 5 -#define CYAN 6 -#define MAGENTA 7 - -/*------------------------------------------------------------------------- - FrameBuffer - - This structure defines a simple 8 bit framebuffer. - ------------------------------------------------------------------------- */ - -typedef struct FrameBuffer { - Pixel **pixels; - Zvalue **zbuffer; - unsigned int height; - unsigned int width; - int xmin; /* These are used for clipping */ - int ymin; - int xmax; - int ymax; -} FrameBuffer; - -#define ZMIN 1e+36 - -/* FrameBuffer Methods */ - -extern FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height); -extern void delete_FrameBuffer(FrameBuffer *frame); -extern int FrameBuffer_resize(FrameBuffer *frame, int width, int height); -extern void FrameBuffer_clear(FrameBuffer *frame, Pixel color); -extern void FrameBuffer_plot(FrameBuffer *frame, int x, int y, Pixel color); -extern void FrameBuffer_horizontal(FrameBuffer *frame, int xmin, int xmax, int y, Pixel color); -extern void FrameBuffer_horizontalinterp(FrameBuffer *f, int xmin, int xmax, int y, Pixel c1, Pixel c2); -extern void FrameBuffer_vertical(FrameBuffer *frame, int ymin, int ymax, int x, Pixel color); -extern void FrameBuffer_box(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -extern void FrameBuffer_solidbox(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -extern void FrameBuffer_interpbox(FrameBuffer *f, int x1, int y1, int x2, int y2, Pixel c1, Pixel c2, Pixel c3, Pixel c4); -extern void FrameBuffer_circle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color); -extern void FrameBuffer_solidcircle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color); -extern void FrameBuffer_line(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -extern void FrameBuffer_setclip(FrameBuffer *frame, int xmin, int ymin, int xmax, int ymax); -extern void FrameBuffer_noclip(FrameBuffer *frame); -extern int FrameBuffer_makeGIF(FrameBuffer *frame, ColorMap *cmap, void *buffer, unsigned int maxsize); -extern int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename); -extern void FrameBuffer_zresize(FrameBuffer *f, int width, int height); -extern void FrameBuffer_zclear(FrameBuffer *f); -extern void FrameBuffer_solidtriangle(FrameBuffer *f, int x1, int y1, int x2, int y2, int x3, int y3, Pixel c); -extern void FrameBuffer_interptriangle(FrameBuffer *f, int tx1, int ty1, Pixel c1, - int tx2, int ty2, Pixel c2, int tx3, int ty3, Pixel c3); - -#define HORIZONTAL 1 -#define VERTICAL 2 - -extern void FrameBuffer_drawchar(FrameBuffer *frame, int x, int y, int fgcolor, int bgcolor, char chr, int orientation); -extern void FrameBuffer_drawstring(FrameBuffer *f, int x, int y, int fgcolor, int bgcolor, char *text, int orientation); - -/* ------------------------------------------------------------------------ - PixMap - - The equivalent of "bit-maps". - ------------------------------------------------------------------------ */ - -typedef struct PixMap { - int width; - int height; - int centerx; - int centery; - int *map; -} PixMap; - -/* PIXMAP methods */ - -extern PixMap *new_PixMap(int width, int height, int centerx, int centery); -extern void delete_PixMap(PixMap *pm); -extern void PixMap_set(PixMap *pm, int x, int y, int pix); -extern void FrameBuffer_drawpixmap(FrameBuffer *f, PixMap *pm, int x, int y, int fgcolor, int bgcolor); - -#define GIFPLOT_TRANSPARENT 0 -#define GIFPLOT_FOREGROUND 1 -#define GIFPLOT_BACKGROUND 2 - -/* ------------------------------------------------------------------------ - Plot2D - - Definition and methods for 2D plots. - ------------------------------------------------------------------------ */ - -typedef struct Plot2D { - FrameBuffer *frame; /* what frame buffer are we using */ - int view_xmin; /* Minimum coordinates of view region */ - int view_ymin; - int view_xmax; /* Maximum coordinates of view region */ - int view_ymax; - double xmin; /* Minimum coordinates of plot region */ - double ymin; - double xmax; /* Maximum coordinates of plot region */ - double ymax; - int xscale; /* Type of scaling (LINEAR, LOG, etc..) */ - int yscale; - double dx; /* Private scaling parameters */ - double dy; -} Plot2D; - -/* 2D Plot methods */ - -extern Plot2D *new_Plot2D(FrameBuffer *frame,double xmin,double ymin, double xmax, double ymax); -extern void delete_Plot2D(Plot2D *p2); -extern Plot2D *Plot2D_copy(Plot2D *p2); -extern void Plot2D_clear(Plot2D *p2, Pixel c); -extern void Plot2D_setview(Plot2D *p2, int vxmin, int vymin, int vxmax, int vymax); -extern void Plot2D_setrange(Plot2D *p2, double xmin, double ymin, double xmax, double ymax); -extern void Plot2D_setscale(Plot2D *p2, int xscale, int yscale); -extern void Plot2D_plot(Plot2D *p2, double x, double y, Pixel color); -extern void Plot2D_box(Plot2D *p2, double x1, double y1, double x2, double y2, Pixel color); -extern void Plot2D_solidbox(Plot2D *p2, double x1, double y1,double x2, double y2, Pixel color); -extern void Plot2D_interpbox(Plot2D *p2, double x1, double y1, double x2, double y2, Pixel c1, Pixel c2, Pixel c3, Pixel c4); -extern void Plot2D_circle(Plot2D *p2, double x, double y, double radius, Pixel color); -extern void Plot2D_solidcircle(Plot2D *p2, double x, double y, double radius, Pixel color); -extern void Plot2D_line(Plot2D *p2, double x1, double y1, double x2, double y2, Pixel color); -extern void Plot2D_start(Plot2D *p2); -extern void Plot2D_drawpixmap(Plot2D *p2, PixMap *pm, double x, double y, Pixel color, Pixel bgcolor); -extern void Plot2D_xaxis(Plot2D *p2, double x, double y, double xtick, int ticklength, Pixel c); -extern void Plot2D_yaxis(Plot2D *p2, double x, double y, double ytick, int ticklength, Pixel c); -extern void Plot2D_triangle(Plot2D *p2, double x1, double y1, double x2, double y2, double x3, double y3, Pixel c); -extern void Plot2D_solidtriangle(Plot2D *p2, double x1, double y1, double x2, double y2, double x3, double y3, Pixel c); -extern void Plot2D_interptriangle(Plot2D *p2, double x1, double y1, Pixel c1, - double x2, double y2, Pixel c2, - double x3, double y3, Pixel c3); - -#define LINEAR 10 -#define LOG 11 - -/* ----------------------------------------------------------------------- - Matrix - - Operations on 4x4 transformation matrices and vectors. - Matrices are represented as a double array of 16 elements - ----------------------------------------------------------------------- */ - -typedef double *Matrix; -typedef struct GL_Vector { - double x; - double y; - double z; - double w; -} GL_Vector; - -extern Matrix new_Matrix(); -extern void delete_Matrix(Matrix a); -extern Matrix Matrix_copy(Matrix a); -extern void Matrix_multiply(Matrix a, Matrix b, Matrix c); -extern void Matrix_identity(Matrix a); -extern void Matrix_zero(Matrix a); -extern void Matrix_transpose(Matrix a, Matrix result); -extern void Matrix_invert(Matrix a, Matrix inva); -extern void Matrix_transform(Matrix a, GL_Vector *r, GL_Vector *t); -extern void Matrix_transform4(Matrix a, double rx, double ry, double rz, - double rw, GL_Vector *t); - -extern void Matrix_print(Matrix a); -extern void Matrix_translate(Matrix a, double tx, double ty, double tz); -extern void Matrix_rotatex(Matrix a, double deg); -extern void Matrix_rotatey(Matrix a, double deg); -extern void Matrix_rotatez(Matrix a, double deg); - -/* ----------------------------------------------------------------------- - Plot3D - - Data Structure for 3-D plots - ------------------------------------------------------------------------ */ - -typedef struct Plot3D { - FrameBuffer *frame; /* Frame buffer being used */ - int view_xmin; /* Viewing region */ - int view_ymin; - int view_xmax; - int view_ymax; - double xmin; /* Bounding box */ - double ymin; - double zmin; - double xmax; - double ymax; - double zmax; - double xcenter; /* Center point */ - double ycenter; - double zcenter; - double fovy; /* Field of view */ - double aspect; /* Aspect ratio */ - double znear; /* near "clipping" plane */ - double zfar; /* far "clipping" plane */ - Matrix center_mat; /* Matrix used for centering the model */ - Matrix model_mat; /* Model rotation matrix */ - Matrix view_mat; /* Viewing matrix */ - Matrix fullmodel_mat; /* Full model matrix. Used by sphere plot */ - Matrix trans_mat; /* Total transformation matrix */ - double lookatz; /* Where is the z-lookat point */ - double xshift; /* Used for translation and stuff */ - double yshift; - double zoom; - int width; - int height; - int pers_mode; /* Perspective mode (private) */ - double ortho_left,ortho_right,ortho_bottom,ortho_top; -} Plot3D; - -extern Plot3D *new_Plot3D(FrameBuffer *frame, double xmin, double ymin, double zmin, - double xmax, double ymax, double zmax); -extern void delete_Plot3D(Plot3D *p3); -extern Plot3D *Plot3D_copy(Plot3D *p3); -extern void Plot3D_clear(Plot3D *p3, Pixel Color); -extern void Plot3D_perspective(Plot3D *p3, double fovy, double znear, double zfar); -extern void Plot3D_ortho(Plot3D *p3, double left, double right, double top, double bottom); -extern void Plot3D_lookat(Plot3D *p3, double z); -extern void Plot3D_autoperspective(Plot3D *p3, double fovy); -extern void Plot3D_autoortho(Plot3D *p3); -extern void Plot3D_rotx(Plot3D *p3, double deg); -extern void Plot3D_roty(Plot3D *p3, double deg); -extern void Plot3D_rotz(Plot3D *p3, double deg); -extern void Plot3D_rotl(Plot3D *p3, double deg); -extern void Plot3D_rotr(Plot3D *p3, double deg); -extern void Plot3D_rotd(Plot3D *p3, double deg); -extern void Plot3D_rotu(Plot3D *p3, double deg); -extern void Plot3D_rotc(Plot3D *p3, double deg); -extern void Plot3D_zoom(Plot3D *p3, double percent); -extern void Plot3D_left(Plot3D *p3, double percent); -extern void Plot3D_right(Plot3D *p3, double percent); -extern void Plot3D_down(Plot3D *p3, double percent); -extern void Plot3D_up(Plot3D *p3, double percent); -extern void Plot3D_center(Plot3D *p3, double cx, double cy); - -extern void Plot3D_plot(Plot3D *p3, double x, double y, double z, Pixel Color); - -extern void Plot3D_setview(Plot3D *p3, int vxmin, int vymin, int vxmax, int vymax); -extern void Plot3D_start(Plot3D *p3); -extern void Plot3D_line(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, Pixel color); -extern void Plot3D_triangle(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, Pixel color); -extern void Plot3D_solidtriangle(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, Pixel color); - -extern void Plot3D_interptriangle(Plot3D *p3, - double x1, double y1, double z1, Pixel c1, - double x2, double y2, double z2, Pixel c2, - double x3, double y3, double z3, Pixel c3); - -extern void Plot3D_quad(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, - double x4, double y4, double z4, - Pixel color); - -extern void Plot3D_solidquad(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, - double x4, double y4, double z4, - Pixel color); - -extern void Plot3D_interpquad(Plot3D *p3, double x1, double y1, double z1, Pixel c1, - double x2, double y2, double z2, Pixel c2, - double x3, double y3, double z3, Pixel c3, - double x4, double y4, double z4, Pixel c4); - - -extern void Plot3D_solidsphere(Plot3D *p3, double x, double y, double z, double radius,Pixel c); - -extern void Plot3D_outlinesphere(Plot3D *p3, double x, double y, double z, double radius,Pixel c, Pixel bc); - -extern PixMap PixMap_SQUARE; -extern PixMap PixMap_TRIANGLE; -extern PixMap PixMap_CROSS; - -#endif -#define GIFPLOT_H - - - diff --git a/Examples/GIFPlot/Interface/gifplot.i b/Examples/GIFPlot/Interface/gifplot.i deleted file mode 100644 index fdf661c5e..000000000 --- a/Examples/GIFPlot/Interface/gifplot.i +++ /dev/null @@ -1,264 +0,0 @@ -// -// Graphics module -// -%module gifplot -%{ -#include "gifplot.h" -%} - -#if defined(SWIGJAVA ) || defined(SWIGPHP) - %rename(make_default) ColorMap::default(); -#endif - -%rename(__getitem__) ColorMap::getitem(int index); -%rename(__setitem__) ColorMap::setitem(int index, int value); - -/* Pixel is 8-bits */ - -typedef unsigned char Pixel; -typedef float Zvalue; - -/* ------------------------------------------------------------------------ - ColorMap - - Definition and methods for colormaps - ------------------------------------------------------------------------ */ - -typedef struct ColorMap { - char *name; - -// -// %extend adds some C methods to this structure to make it -// look like a C++ class in Python. -// These are really named things like ColorMap_default, ColorMap_assign, etc... - - %extend { - ColorMap(char *filename); - ~ColorMap(); - void default(); - void assign(int index,int r, int g, int b); - int getitem(int index); - void setitem(int index, int value); - int write(char *filename); - } -} ColorMap; - -/* Some default colors */ - -#define BLACK 0 -#define WHITE 1 -#define RED 2 -#define GREEN 3 -#define BLUE 4 -#define YELLOW 5 -#define CYAN 6 -#define MAGENTA 7 - -/*------------------------------------------------------------------------- - FrameBuffer - - This structure defines a simple 8 bit framebuffer. - ------------------------------------------------------------------------- */ - -typedef struct FrameBuffer { - unsigned int height; - unsigned int width; - int xmin; /* These are used for clipping */ - int ymin; - int xmax; - int ymax; - %extend { - FrameBuffer(unsigned int width, unsigned int height); - ~FrameBuffer(); - void resize(int width, int height); - void clear(Pixel color); - void plot(int x, int y, Pixel color); - void horizontal(int xmin, int xmax, int y, Pixel color); - void horizontalinterp(int xmin, int xmax, int y, Pixel c1, Pixel c2); - void vertical(int ymin, int ymax, int x, Pixel color); - void box(int x1, int y1, int x2, int y2, Pixel color); - void solidbox(int x1, int y1, int x2, int y2, Pixel color); - void interpbox(int x1, int y1, int x2, int y2, Pixel c1, Pixel c2, Pixel c3, Pixel c4); - void circle(int x1, int y1, int radius, Pixel color); - void solidcircle(int x1, int y1, int radius, Pixel color); - void line(int x1, int y1, int x2, int y2, Pixel color); - void setclip(int xmin, int ymin, int xmax, int ymax); - void noclip(); - int makeGIF(ColorMap *cmap, void *buffer, unsigned int maxsize); - void zresize(int width, int height); - void zclear(); - void drawchar(int x, int y, int fgcolor, int bgcolor, char chr, int orientation); - void drawstring(int x, int y, int fgcolor, int bgcolor, char *text, int orientation); - void drawpixmap(PixMap *pm, int x, int y, int fgcolor, int bgcolor); - int writeGIF(ColorMap *cmap, char *filename); - } -} FrameBuffer; - -#define HORIZONTAL 1 -#define VERTICAL 2 - -/* -------------------------------------------------------------------------- - PixMap - - The equivalent of "bit-maps". - -------------------------------------------------------------------------- */ - -/* PIXMAP methods */ - -extern PixMap *new_PixMap(int width, int height, int centerx, int centery); -extern void delete_PixMap(PixMap *pm); -extern void PixMap_set(PixMap *pm, int x, int y, int pix); - -#define GIFPLOT_TRANSPARENT 0 -#define GIFPLOT_FOREGROUND 1 -#define GIFPLOT_BACKGROUND 2 - -/* -------------------------------------------------------------------------- - Plot2D - - Definition and methods for 2D plots. - --------------------------------------------------------------------------- */ - -typedef struct Plot2D { - FrameBuffer *frame; - int view_xmin; /* Minimum coordinates of view region */ - int view_ymin; - int view_xmax; /* Maximum coordinates of view region */ - int view_ymax; - double xmin; /* Minimum coordinates of plot region */ - double ymin; - double xmax; /* Maximum coordinates of plot region */ - double ymax; - int xscale; /* Type of scaling (LINEAR, LOG, etc..) */ - int yscale; - %extend { - Plot2D(FrameBuffer *frame,double xmin,double ymin, double xmax, double ymax); - ~Plot2D(); - Plot2D *copy(); - void clear(Pixel c); - void setview(int vxmin, int vymin, int vxmax, int vymax); - void setrange(double xmin, double ymin, double xmax, double ymax); - void setscale(int xscale, int yscale); - void plot(double x, double y, Pixel color); - void box(double x1, double y1, double x2, double y2, Pixel color); - void solidbox(double x1, double y1, double x2, double y2, Pixel color); - void interpbox(double x1, double y1, double x2, double y2, Pixel c1, Pixel c2, Pixel c3, Pixel c4); - - void circle(double x, double y, double radius, Pixel color); - void solidcircle(double x, double y, double radius, Pixel color); - void line(double x1, double y1, double x2, double y2, Pixel color); - void start(); - void drawpixmap(PixMap *pm, double x, double y, Pixel color, Pixel bgcolor); - void xaxis(double x, double y, double xtick, int ticklength, Pixel color); - void yaxis(double x, double y, double ytick, int ticklength, Pixel color); - void triangle(double x1, double y1, double x2, double y2, double x3, double y3, Pixel c); - - void solidtriangle(double x1, double y1, double x2, double y2, double x3, double y3, Pixel c); - - void interptriangle(double x1, double y1, Pixel c1, - double x2, double y2, Pixel c2, - double x3, double y3, Pixel c3); - - } -} Plot2D; - -#define LINEAR 10 -#define LOG 11 - -/* ------------------------------------------------------------------------------ - Plot3D - - Data Structure for 3-D plots - ------------------------------------------------------------------------------ */ - -typedef struct Plot3D { - FrameBuffer *frame; - int view_xmin; /* Viewing region */ - int view_ymin; - int view_xmax; - int view_ymax; - double xmin; /* Bounding box */ - double ymin; - double zmin; - double xmax; - double ymax; - double zmax; - double xcenter; /* Center point */ - double ycenter; - double zcenter; - double fovy; /* Field of view */ - double aspect; /* Aspect ratio */ - double znear; /* near "clipping" plane */ - double zfar; /* far "clipping" plane */ - double lookatz; /* Where is the z-lookat point */ - double xshift; /* Used for translation and stuff */ - double yshift; - %extend { - Plot3D(FrameBuffer *frame, double xmin, double ymin, double zmin, double xmax, double ymax, double zmax); - ~Plot3D(); - Plot3D *copy(); - void clear(Pixel bgcolor); - void perspective( double fovy, double znear, double zfar); - void lookat( double z); - void autoperspective( double fovy); - void ortho(double left, double right, double bottom, double top); - void autoortho(); - void rotx( double deg); - void roty( double deg); - void rotz( double deg); - void rotl( double deg); - void rotr( double deg); - void rotd( double deg); - void rotu( double deg); - void rotc( double deg); - void zoom( double percent); - void left( double percent); - void right( double percent); - void down( double percent); - void up( double percent); - void center( double cx, double cy); - void plot( double x, double y, double z, Pixel Color); - void setview( int vxmin, int vymin, int vxmax, int vymax); - void start(); - void line( double x1, double y1, double z1, - double x2, double y2, double z2, Pixel color); - void triangle( double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, Pixel color); - void solidtriangle( double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, Pixel color); - void interptriangle(double x1, double y1, double z1, Pixel c1, - double x2, double y2, double z2, Pixel c2, - double x3, double y3, double z3, Pixel c3); - void quad( double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, - double x4, double y4, double z4, - Pixel color); - void solidquad( double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, - double x4, double y4, double z4, - Pixel color); - void interpquad( double x1, double y1, double z1, Pixel c1, - double x2, double y2, double z2, Pixel c2, - double x3, double y3, double z3, Pixel c3, - double x4, double y4, double z4, Pixel c4); - void solidsphere( double x, double y, double z, double radius,Pixel c); - void outlinesphere( double x, double y, double z, double radius,Pixel c, Pixel bc); - } -} Plot3D; - -#ifndef SWIGJAVA -/* These directives create constants of a specific type. They - do not correspond to any C variable or declared constant in the - header file */ -%constant PixMap * SQUARE = &PixMap_SQUARE; -%constant PixMap * TRIANGLE = &PixMap_TRIANGLE; -%constant PixMap * CROSS = &PixMap_CROSS; -#endif - - - - diff --git a/Examples/GIFPlot/Java/check.list b/Examples/GIFPlot/Java/check.list deleted file mode 100644 index 13de977af..000000000 --- a/Examples/GIFPlot/Java/check.list +++ /dev/null @@ -1,4 +0,0 @@ -# see top-level Makefile.in -full -shadow -simple diff --git a/Examples/GIFPlot/Java/full/Makefile b/Examples/GIFPlot/Java/full/Makefile deleted file mode 100644 index 8f167237d..000000000 --- a/Examples/GIFPlot/Java/full/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -I../../Include -noproxy -SRCS = -TARGET = gifplot -INTERFACE = gifplot.i -LIBS = -L../.. -lgifplot -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - javac *.java - -clean:: - $(MAKE) -f $(TOP)/Makefile java_clean - rm -f *.gif - -check: all diff --git a/Examples/GIFPlot/Java/full/README b/Examples/GIFPlot/Java/full/README deleted file mode 100644 index 93463ea30..000000000 --- a/Examples/GIFPlot/Java/full/README +++ /dev/null @@ -1,8 +0,0 @@ -This example runs the entire gifplot.h header file through SWIG without -any changes. The program 'runme.java' does something a little more -interesting. After doing a make, run it using 'java runme'. You'll have to go -look at the header file to get a complete listing of the functions. - -Note the differences in the runme.java files between this example and the -'full' example. This example does not use shadow classes. - diff --git a/Examples/GIFPlot/Java/full/cmap b/Examples/GIFPlot/Java/full/cmap deleted file mode 100644 index a20c331a9573dd8443380680bfe2cc428780d8a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9IC 239) c = 239; - gifplot.Plot3D_solidquad(p3,x,y,z1,x+dx,y,z2,x+dx,y+dy,z3,x,y+dy,z4,(short)(c+16)); - y = y + dy; - } - x = x + dx; - } - - gifplot.FrameBuffer_writeGIF(frame,cmap,"image.gif"); - System.out.println( "Wrote image.gif" ); - } - - // Here is the function to plot - public static double func(double x, double y) { - return 5*java.lang.Math.cos(2*java.lang.Math.sqrt(x*x+y*y))*java.lang.Math.exp(-0.3*java.lang.Math.sqrt(x*x+y*y)); - } -} diff --git a/Examples/GIFPlot/Java/shadow/Makefile b/Examples/GIFPlot/Java/shadow/Makefile deleted file mode 100644 index 8062c2700..000000000 --- a/Examples/GIFPlot/Java/shadow/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -outcurrentdir -SRCS = -TARGET = gifplot -INTERFACEDIR = ../../Interface/ -INTERFACE = gifplot.i -LIBS = -L../.. -lgifplot -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' java - javac *.java - -clean:: - $(MAKE) -f $(TOP)/Makefile java_clean - rm -f *.gif - -check: all diff --git a/Examples/GIFPlot/Java/shadow/README b/Examples/GIFPlot/Java/shadow/README deleted file mode 100644 index b06c5a8f1..000000000 --- a/Examples/GIFPlot/Java/shadow/README +++ /dev/null @@ -1,5 +0,0 @@ -This example uses the file in ../../Interface/gifplot.i to build -an interface with shadow classes. After doing a make, run the program runme, ie: 'java runme'. - -Note the differences in the runme.java files between this example and the -'full' example. This example uses the shadow classes. diff --git a/Examples/GIFPlot/Java/shadow/cmap b/Examples/GIFPlot/Java/shadow/cmap deleted file mode 100644 index a20c331a9573dd8443380680bfe2cc428780d8a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9IC 239) c = 239; - p3.solidquad(x,y,z1,x+dx,y,z2,x+dx,y+dy,z3,x,y+dy,z4,(short)(c+16)); - y = y + dy; - } - x = x + dx; - } - - frame.writeGIF(cmap,"image.gif"); - System.out.println( "Wrote image.gif" ); - } - - // Here is the function to plot - public static double func(double x, double y) { - return 5*java.lang.Math.cos(2*java.lang.Math.sqrt(x*x+y*y))*java.lang.Math.exp(-0.3*java.lang.Math.sqrt(x*x+y*y)); - } -} diff --git a/Examples/GIFPlot/Java/simple/Makefile b/Examples/GIFPlot/Java/simple/Makefile deleted file mode 100644 index d707fd458..000000000 --- a/Examples/GIFPlot/Java/simple/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -noproxy -SRCS = -TARGET = simple -INTERFACE = simple.i -LIBS = -L../.. -lgifplot -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - javac *.java - - -clean:: - $(MAKE) -f $(TOP)/Makefile java_clean - rm -f *.gif - -check: all diff --git a/Examples/GIFPlot/Java/simple/README b/Examples/GIFPlot/Java/simple/README deleted file mode 100644 index 13ff49611..000000000 --- a/Examples/GIFPlot/Java/simple/README +++ /dev/null @@ -1,5 +0,0 @@ -This is a very minimalistic example in which just a few functions -and constants from library are wrapped and used to draw some simple -shapes. After doing a make, run the java program, ie 'java runme'. - - diff --git a/Examples/GIFPlot/Java/simple/runme.java b/Examples/GIFPlot/Java/simple/runme.java deleted file mode 100644 index 2d8d2bb48..000000000 --- a/Examples/GIFPlot/Java/simple/runme.java +++ /dev/null @@ -1,41 +0,0 @@ - -public class runme { - - static { - try { - System.loadLibrary("simple"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); - System.exit(1); - } - } - - public static void main(String argv[]) { - - // Draw some simple shapes - System.out.println( "Drawing some basic shapes" ); - - SWIGTYPE_p_ColorMap cmap = simple.new_ColorMap(null); - SWIGTYPE_p_FrameBuffer f = simple.new_FrameBuffer(400,400); - - // Clear the picture - simple.FrameBuffer_clear(f,(short)simple.BLACK); - - // Make a red box - simple.FrameBuffer_box(f,40,40,200,200,(short)simple.RED); - - // Make a blue circle - simple.FrameBuffer_circle(f,200,200,40,(short)simple.BLUE); - - // Make green line - simple.FrameBuffer_line(f,10,390,390,200, (short)simple.GREEN); - - // Write an image out to disk - - simple.FrameBuffer_writeGIF(f,cmap,"image.gif"); - System.out.println( "Wrote image.gif" ); - - simple.delete_FrameBuffer(f); - simple.delete_ColorMap(cmap); - } -} diff --git a/Examples/GIFPlot/Java/simple/simple.i b/Examples/GIFPlot/Java/simple/simple.i deleted file mode 100644 index 457bc4c09..000000000 --- a/Examples/GIFPlot/Java/simple/simple.i +++ /dev/null @@ -1,38 +0,0 @@ -/* This example shows a very simple interface wrapping a few - primitive declarations */ - -%module simple -%{ -#include "gifplot.h" -%} - -typedef unsigned char Pixel; - -/* Here are a few useful functions */ - -ColorMap *new_ColorMap(char *filename = 0); -void delete_ColorMap(ColorMap *cmap); - -FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height); -void delete_FrameBuffer(FrameBuffer *frame); -void FrameBuffer_clear(FrameBuffer *frame, Pixel color); -void FrameBuffer_line(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_box(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_circle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color); -int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename); - -/* And some useful constants */ - -#define BLACK 0 -#define WHITE 1 -#define RED 2 -#define GREEN 3 -#define BLUE 4 -#define YELLOW 5 -#define CYAN 6 -#define MAGENTA 7 - - - - - diff --git a/Examples/GIFPlot/Lib/Makefile.in b/Examples/GIFPlot/Lib/Makefile.in deleted file mode 100644 index 9db828eb2..000000000 --- a/Examples/GIFPlot/Lib/Makefile.in +++ /dev/null @@ -1,22 +0,0 @@ -CC = @CC@ -CCSHARED= @CCSHARED@ -INCLUDES= -I../Include -CFLAGS = -O -SRCS = frame.c color.c plot2d.c plot3d.c font.c pixmap.c matrix.c gif.c -OBJS = $(SRCS:.c=.@OBJEXT@) -AR = @AR@ -RANLIB = @RANLIB@ -TARGET = ../libgifplot.a - -.c.@OBJEXT@: - $(CC) $(CCSHARED) $(INCLUDES) $(CFLAGS) -c -o $*.@OBJEXT@ $< - -all: $(OBJS) - @rm -f ../libgifplot.a - $(AR) cr $(TARGET) $(OBJS) - $(RANLIB) $(TARGET) - -clean: - rm -f *.@OBJEXT@ *~ $(TARGET) - -check: all diff --git a/Examples/GIFPlot/Lib/color.c b/Examples/GIFPlot/Lib/color.c deleted file mode 100644 index 7d79baca9..000000000 --- a/Examples/GIFPlot/Lib/color.c +++ /dev/null @@ -1,143 +0,0 @@ -/* ----------------------------------------------------------------------------- - * color.c - * - * Colormaps - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * Copyright (C) 1995-1996 - * - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -#define COLORMAP -#include "gifplot.h" -#include - -/* ------------------------------------------------------------------------ - ColorMap *new_ColorMap(char *filename) - - Read a colormap from a file. - ------------------------------------------------------------------------ */ - -ColorMap *new_ColorMap(char *filename) { - ColorMap *c; - FILE *cm; - void ColorMap_default(ColorMap *); - - if (!filename) { - c = (ColorMap *) malloc(sizeof(ColorMap)); - c->cmap = (unsigned char *) malloc(768*sizeof(char)); - c->name = 0; - ColorMap_default(c); - return c; - } - if (strlen(filename) == 0) { - c = (ColorMap *) malloc(sizeof(ColorMap)); - c->cmap = (unsigned char *) malloc(768*sizeof(char)); - ColorMap_default(c); - return c; - } - if ((cm = fopen(filename,"rb")) == NULL) { - return (ColorMap *) 0; - } - c = (ColorMap *) malloc(sizeof(ColorMap)); - c->cmap = (unsigned char *) malloc(768*sizeof(char)); - if (fread(c->cmap, 768, 1, cm) != 1) { - free((char *)c->cmap); - free((char *)c); - fclose(cm); - return (ColorMap *) 0; - } - fclose(cm); - c->name = (char *) malloc(strlen(filename)+1); - strcpy(c->name, filename); - ColorMap_default(c); - return c; -} - -/* -------------------------------------------------------------------------- - delete_ColorMap(ColorMap *cm) - - Destroy a ColorMap - -------------------------------------------------------------------------- */ - -void delete_ColorMap(ColorMap *cm) { - if (cm) { - free((char *)cm->cmap); - if (cm->name) - free((char *)cm->name); - free((char *)cm); - } -} - -/* -------------------------------------------------------------------------- - ColorMap_default(ColorMap *cm) - - This function fills in default values for the first 8 entries of the - colormap. These are *fixed* values---used internally. - -------------------------------------------------------------------------- */ - -void ColorMap_default(ColorMap *cm) { - unsigned char *r,*g,*b; - if (cm) { - r = cm->cmap; - g = cm->cmap+256; - b = cm->cmap+512; - - r[0] = 0; g[0] = 0; b[0] = 0; /* BLACK */ - r[1] = 255; g[1] = 255; b[1] = 255; /* WHITE */ - r[2] = 255; g[2] = 0; b[2] = 0; /* RED */ - r[3] = 0; g[3] = 255; b[3] = 0; /* GREEN */ - r[4] = 0; g[4] = 0; b[4] = 255; /* BLUE */ - r[5] = 255; g[5] = 255; b[5] = 0; /* YELLOW */ - r[6] = 0; g[6] = 255; b[6] = 255; /* CYAN */ - r[7] = 255; g[7] = 0; b[7] = 255; /* MAGENTA */ - } -} - -void ColorMap_assign(ColorMap *cm, int index, int r, int g, int b) { - unsigned char *rb,*gb,*bb; - - rb = cm->cmap; - gb = cm->cmap+256; - bb = cm->cmap+512; - - rb[index] = r; - gb[index] = g; - bb[index] = b; -} - -int ColorMap_getitem(ColorMap *cm, int index) { - if ((index < 0) && (index >= 768)) return -1; - return cm->cmap[index]; -} - -void ColorMap_setitem(ColorMap *cm, int index, int value) { - if ((index < 0) && (index >= 768)) return; - cm->cmap[index]=value; -} - -/* -------------------------------------------------------------------- - ColorMap_write(ColorMap *cm, char *filename) - - Write out a colormap to disk. - -------------------------------------------------------------------- */ - -int ColorMap_write(ColorMap *cm, char *filename) { - - FILE *f; - if (!cm) return -1; - if (!filename) return -1; - if (strlen(filename) == 0) return -1; - - f = fopen(filename,"w"); - - if (fwrite(cm->cmap,768,1,f) != 1) { - fclose(f); - return -1; - } - fclose(f); - return 0; -} - -#undef COLORMAP diff --git a/Examples/GIFPlot/Lib/font.c b/Examples/GIFPlot/Lib/font.c deleted file mode 100644 index b30ee9b14..000000000 --- a/Examples/GIFPlot/Lib/font.c +++ /dev/null @@ -1,705 +0,0 @@ -/* ----------------------------------------------------------------------------- - * font.c - * - * Some basic fonts. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * Copyright (C) 1995-1996 - * - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -#define FONT -#include "gifplot.h" - -static char Char_A[80] = "\ -...x....\ -...x....\ -..x.x...\ -..x.x...\ -.x...x..\ -.xxxxx..\ -x.....x.\ -x.....x.\ -x.....x.\ -........"; - -static char Char_B[80] = "\ -xxxxxx..\ -x.....x.\ -x.....x.\ -x.....x.\ -xxxxxx..\ -x.....x.\ -x.....x.\ -x.....x.\ -xxxxxx..\ -........"; - -static char Char_C[80] = "\ -..xxxx..\ -.x....x.\ -x.......\ -x.......\ -x.......\ -x.......\ -x.......\ -.x....x.\ -..xxxx..\ -........"; - -static char Char_D[80] = "\ -xxxxx...\ -x....x..\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -x....x..\ -xxxxx...\ -........"; -static char Char_E[80] = "\ -xxxxxxx.\ -x.......\ -x.......\ -x.......\ -xxxxx...\ -x.......\ -x.......\ -x.......\ -xxxxxxx.\ -........"; -static char Char_F[80] = "\ -xxxxxxx.\ -x.......\ -x.......\ -x.......\ -xxxxx...\ -x.......\ -x.......\ -x.......\ -x.......\ -........"; -static char Char_G[80] = "\ -.xxxxx..\ -x.....x.\ -x.......\ -x.......\ -x...xxx.\ -x.....x.\ -x.....x.\ -x.....x.\ -.xxxxx..\ -........"; -static char Char_H[80] = "\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -xxxxxxx.\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -........"; -static char Char_I[80] = "\ -xxxxxxx.\ -...x....\ -...x....\ -...x....\ -...x....\ -...x....\ -...x....\ -...x....\ -xxxxxxx.\ -........"; -static char Char_J[80] = "\ -......x.\ -......x.\ -......x.\ -......x.\ -......x.\ -......x.\ -x.....x.\ -.x...x..\ -..xxx...\ -........"; -static char Char_K[80] = "\ -x.....x.\ -x....x..\ -x...x...\ -x..x....\ -xxx.....\ -x..x....\ -x...x...\ -x....x..\ -x.....x.\ -........"; -static char Char_L[80] = "\ -x.......\ -x.......\ -x.......\ -x.......\ -x.......\ -x.......\ -x.......\ -x.......\ -xxxxxxx.\ -........"; -static char Char_M[80] = "\ -x.....x.\ -xx...xx.\ -xx...xx.\ -x.x.x.x.\ -x.x.x.x.\ -x..x..x.\ -x..x..x.\ -x.....x.\ -x.....x.\ -........"; -static char Char_N[80] = "\ -x.....x.\ -xx....x.\ -x.x...x.\ -x.x...x.\ -x..x..x.\ -x...x.x.\ -x...x.x.\ -x....xx.\ -x.....x.\ -........"; -static char Char_O[80] = "\ -.xxxxx..\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -.xxxxx..\ -........"; -static char Char_P[80] = "\ -xxxxxx..\ -x.....x.\ -x.....x.\ -x.....x.\ -xxxxxx..\ -x.......\ -x.......\ -x.......\ -x.......\ -........"; -static char Char_Q[80] = "\ -.xxxxx..\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -x...x.x.\ -x....x..\ -.xxxx.x.\ -........"; -static char Char_R[80] = "\ -xxxxxx..\ -x.....x.\ -x.....x.\ -x.....x.\ -xxxxxx..\ -x..x....\ -x...x...\ -x....x..\ -x.....x.\ -........"; -static char Char_S[80] = "\ -.xxxxx..\ -x.....x.\ -x.......\ -x.......\ -.xxxxx..\ -......x.\ -......x.\ -x.....x.\ -.xxxxx..\ -........"; -static char Char_T[80] = "\ -xxxxxxx.\ -...x....\ -...x....\ -...x....\ -...x....\ -...x....\ -...x....\ -...x....\ -...x....\ -........"; -static char Char_U[80] = "\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -.xxxxx..\ -........"; -static char Char_V[80] = "\ -x.....x.\ -x.....x.\ -.x...x..\ -.x...x..\ -..x.x...\ -..x.x...\ -...x....\ -...x....\ -...x....\ -........"; -static char Char_W[80] = "\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -x.....x.\ -x..x..x.\ -x..x..x.\ -x.x.x.x.\ -.x...x..\ -........"; -static char Char_X[80] = "\ -x.....x.\ -x.....x.\ -.x...x..\ -..x.x...\ -...x....\ -..x.x...\ -.x...x..\ -x.....x.\ -x.....x.\ -........"; -static char Char_Y[80] = "\ -x.....x.\ -x.....x.\ -.x...x..\ -..x.x...\ -...x....\ -...x....\ -...x....\ -...x....\ -...x....\ -........"; -static char Char_Z[80] = "\ -xxxxxxx.\ -......x.\ -.....x..\ -....x...\ -...x....\ -..x.....\ -.x......\ -x.......\ -xxxxxxx.\ -........"; -static char Char_0[80] = "\ -.xxxxx..\ -x....xx.\ -x...x.x.\ -x..x..x.\ -x..x..x.\ -x.x...x.\ -x.x...x.\ -xx....x.\ -.xxxxx..\ -........"; -static char Char_1[80] = "\ -...x....\ -..xx....\ -...x....\ -...x....\ -...x....\ -...x....\ -...x....\ -...x....\ -..xxx...\ -........"; -static char Char_2[80] = "\ -..xxxx..\ -.x....x.\ -x.....x.\ -.....x..\ -....x...\ -...x....\ -..x.....\ -.x......\ -xxxxxxx.\ -........"; -static char Char_3[80] = "\ -.xxxxx..\ -x.....x.\ -......x.\ -......x.\ -...xxx..\ -......x.\ -......x.\ -x.....x.\ -.xxxxx..\ -........"; -static char Char_4[80] = "\ -....xx..\ -...x.x..\ -..x..x..\ -.x...x..\ -xxxxxxx.\ -.....x..\ -.....x..\ -.....x..\ -.....x..\ -........"; -static char Char_5[80] = "\ -xxxxxxx.\ -x.......\ -x.......\ -x.......\ -xxxxxx..\ -......x.\ -......x.\ -x.....x.\ -.xxxxx..\ -........"; -static char Char_6[80] = "\ -....xxx.\ -..xx....\ -.x......\ -x.......\ -x.xxx...\ -xx...x..\ -x.....x.\ -.x...x..\ -..xxx...\ -........"; -static char Char_7[80] = "\ -xxxxxxx.\ -x.....x.\ -.....x..\ -....x...\ -...x....\ -..x.....\ -.x......\ -x.......\ -x.......\ -........"; -static char Char_8[80] = "\ -.xxxxx..\ -x.....x.\ -x.....x.\ -x.....x.\ -.xxxxx..\ -x.....x.\ -x.....x.\ -x.....x.\ -.xxxxx..\ -........"; -static char Char_9[80] = "\ -..xxxx..\ -.x....x.\ -x.....x.\ -x....xx.\ -.xxxx.x.\ -......x.\ -......x.\ -....xx..\ -.xxx....\ -........"; -static char Char_MINUS[80] = "\ -........\ -........\ -........\ -........\ -.xxxxxx.\ -........\ -........\ -........\ -........\ -........"; -static char Char_PLUS[80] = "\ -........\ -........\ -...x....\ -...x....\ -.xxxxx..\ -...x....\ -...x....\ -........\ -........\ -........"; -static char Char_EQUAL[80] = "\ -........\ -........\ -........\ -.xxxxx..\ -........\ -.xxxxx..\ -........\ -........\ -........\ -........"; -static char Char_LPAREN[80] = "\ -....x...\ -...x....\ -..x.....\ -.x......\ -.x......\ -.x......\ -..x.....\ -...x....\ -....x...\ -........"; -static char Char_RPAREN[80] = "\ -...x....\ -....x...\ -.....x..\ -......x.\ -......x.\ -......x.\ -.....x..\ -....x...\ -...x....\ -........"; -static char Char_QUOTE[80] = "\ -..x.x...\ -..x.x...\ -........\ -........\ -........\ -........\ -........\ -........\ -........\ -........"; -static char Char_COLON[80] = "\ -........\ -........\ -...xx...\ -...xx...\ -........\ -...xx...\ -...xx...\ -........\ -........\ -........"; -static char Char_PERIOD[80] = "\ -........\ -........\ -........\ -........\ -........\ -........\ -........\ -...xx...\ -...xx...\ -........"; -static char Char_COMMA[80] = "\ -........\ -........\ -........\ -........\ -........\ -........\ -...xx...\ -...xx...\ -....x...\ -...x...."; - -static char Char_SLASH[80] = "\ -........\ -......x.\ -.....x..\ -....x...\ -...x....\ -..x.....\ -.x......\ -x.......\ -........\ -........"; - -static char Char_SPACE[80] = "\ -........\ -........\ -........\ -........\ -........\ -........\ -........\ -........\ -........\ -........"; - -static char *GP_Font[128]; -static int InitGP_Font = 0; - -static void initGP_Fonts(void) { - - int i; - for (i = 0; i < 128; i++) - GP_Font[i] = (char *) 0; - - GP_Font['A'] = GP_Font['a'] = Char_A; - GP_Font['B'] = GP_Font['b'] = Char_B; - GP_Font['C'] = GP_Font['c'] = Char_C; - GP_Font['D'] = GP_Font['d'] = Char_D; - GP_Font['E'] = GP_Font['e'] = Char_E; - GP_Font['F'] = GP_Font['f'] = Char_F; - GP_Font['G'] = GP_Font['g'] = Char_G; - GP_Font['H'] = GP_Font['h'] = Char_H; - GP_Font['I'] = GP_Font['i'] = Char_I; - GP_Font['J'] = GP_Font['j'] = Char_J; - GP_Font['K'] = GP_Font['k'] = Char_K; - GP_Font['L'] = GP_Font['l'] = Char_L; - GP_Font['M'] = GP_Font['m'] = Char_M; - GP_Font['N'] = GP_Font['n'] = Char_N; - GP_Font['O'] = GP_Font['o'] = Char_O; - GP_Font['P'] = GP_Font['p'] = Char_P; - GP_Font['Q'] = GP_Font['q'] = Char_Q; - GP_Font['R'] = GP_Font['r'] = Char_R; - GP_Font['S'] = GP_Font['s'] = Char_S; - GP_Font['T'] = GP_Font['t'] = Char_T; - GP_Font['U'] = GP_Font['u'] = Char_U; - GP_Font['V'] = GP_Font['v'] = Char_V; - GP_Font['W'] = GP_Font['w'] = Char_W; - GP_Font['X'] = GP_Font['x'] = Char_X; - GP_Font['Y'] = GP_Font['y'] = Char_Y; - GP_Font['Z'] = GP_Font['z'] = Char_Z; - GP_Font['0'] = Char_0; - GP_Font['1'] = Char_1; - GP_Font['2'] = Char_2; - GP_Font['3'] = Char_3; - GP_Font['4'] = Char_4; - GP_Font['5'] = Char_5; - GP_Font['6'] = Char_6; - GP_Font['7'] = Char_7; - GP_Font['8'] = Char_8; - GP_Font['9'] = Char_9; - GP_Font['.'] = Char_PERIOD; - GP_Font[','] = Char_COMMA; - GP_Font['='] = Char_EQUAL; - GP_Font['-'] = Char_MINUS; - GP_Font['+'] = Char_PLUS; - GP_Font['\"'] = Char_QUOTE; - GP_Font['('] = Char_LPAREN; - GP_Font[')'] = Char_RPAREN; - GP_Font[':'] = Char_COLON; - GP_Font['/'] = Char_SLASH; - GP_Font[' '] = Char_SPACE; - InitGP_Font = 1; -} - -/* ----------------------------------------------------------------------- - void FrameBuffer_drawchar(FrameBuffer *f, int x, int y, Pixel fgcolor, Pixel bgcolor, char chr, int orientation) - - Draws a character at location x, y with given color and orientation parameters. - Orientation can either be HORIZONTAL or VERTICAL - ----------------------------------------------------------------------- */ -void FrameBuffer_drawchar(FrameBuffer *f, int x, int y, int fgcolor, - int bgcolor, char chr, int orientation) { - - Pixel c, bc,*p,*p1; - char *ch; - int i,j; - int xpixels,ypixels; - - if (!InitGP_Font) initGP_Fonts(); - - c = (Pixel) fgcolor; - bc = (Pixel) bgcolor; - xpixels = f->width; - ypixels = f->height; - - if (orientation == HORIZONTAL) { - if ((x < f->xmin) || (x > f->xmax-8) || - (y < f->ymin) || (y > f->ymax-10)) return; - - ch = GP_Font[(int) chr]; - if (!ch) return; - p = &f->pixels[y+9][x]; - for (i = 0; i < 10; i++) { - p1 = p; - for (j = 0; j< 8; j++) { - if (*(ch++) == 'x') *p= c; - else if (bgcolor >= 0) - *p = bc; - p++; - } - p = (p1 - xpixels); - } - } else { - if ((x < f->xmin+10) || (x >= f->xmax) || - (y < f->ymin) || (y > f->ymax-8)) return; - - ch = GP_Font[(int) chr]; - if (!ch) return; - p = &f->pixels[y][x-9]; - for (i = 0; i < 10; i++) { - p1 = p; - for (j = 0; j< 8; j++) { - if (*(ch++) == 'x') *p= c; - else if (bgcolor >= 0) - *p = bc; - p+=xpixels; - } - p = p1 + 1; - } - } -} - -/* ---------------------------------------------------------------------- - void FrameBuffer_drawstring(FrameBuffer *f, int x, int y, int fgcolor, - int bgcolor, char *text, int orientation) - - Draws an ASCII string on the framebuffer. Can be oriented either horizontally - or vertically. - ---------------------------------------------------------------------- */ - -void FrameBuffer_drawstring(FrameBuffer *f, int x, int y, int fgcolor, int bgcolor, char *text, int orientation) { - - char *c; - int x1, y1; - int xpixels, ypixels; - - x1 = x; - y1 = y; - xpixels = f->width; - ypixels = f->height; - c = text; - while (*c) { - if (*c == '\n') { - if (orientation == HORIZONTAL) { - x1 = x; y1= y1- 10*xpixels; - } else { - y1 = y; x1= x1 + 10*ypixels; - } - } else { - FrameBuffer_drawchar(f, x1,y1,fgcolor, bgcolor,*c, orientation); - if (orientation == HORIZONTAL) { - x1+=8; - if (x1 >= (xpixels-8)) { - x1 = x; y1= y1- 10;} - if (y1 < 0) return; - } else { - y1 += 8; - if (y1 >= (ypixels-8)) { - y1 = y; x1 = x1 + 10;} - if (x1 > (xpixels-10)) return; - } - } - c++; - } -} - - - - - - - - diff --git a/Examples/GIFPlot/Lib/frame.c b/Examples/GIFPlot/Lib/frame.c deleted file mode 100644 index e006f0daf..000000000 --- a/Examples/GIFPlot/Lib/frame.c +++ /dev/null @@ -1,924 +0,0 @@ -/* ----------------------------------------------------------------------------- - * frame.c - * - * Frame buffer management - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * Copyright (C) 1995-1996 - * - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -#define FRAME -#include "gifplot.h" -#include - -/* ------------------------------------------------------------------------ - FrameBuffer *new_FrameBuffer(int width, int height) - - Creates a new framebuffer for storing data. - ------------------------------------------------------------------------ */ - -FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height) { - - FrameBuffer *f; - int FrameBuffer_resize(FrameBuffer *f, int width, int height); - - /* Create a new frame buffer */ - - f = (FrameBuffer *) malloc(sizeof(FrameBuffer)); - f->pixels = (Pixel **) 0; - f->zbuffer = (Zvalue **) 0; - /* Set its size */ - - if (FrameBuffer_resize(f, width, height) == -1) { - free((char *) f); - return (FrameBuffer *) 0; - } - - f->xmin = 0; - f->ymin = 0; - f->xmax = width; - f->ymax = height; - return f; -} - -/* ------------------------------------------------------------------------ - void delete_FrameBuffer(FrameBuffer *f) - - Destroys the given framebuffer - ------------------------------------------------------------------------ */ - -void delete_FrameBuffer(FrameBuffer *f) { - - if (f) { - if (f->pixels) { - free((char *) f->pixels[0]); - free((char *) f->pixels); - } - if (f->zbuffer) { - free((char *) f->zbuffer[0]); - free((char *) f->zbuffer); - } - free((char *)f); - } -} - -/* ------------------------------------------------------------------------ - int *FrameBuffer_resize(FrameBuffer *f, int width, int height) - - Resize the given framebuffer. Returns 0 on success, -1 on failure. - ------------------------------------------------------------------------ */ - -int FrameBuffer_resize(FrameBuffer *f, int width, int height) { - int i; - if ((f) && (width > 0) && (height > 0)) { - if (f->pixels) { - free((char *)f->pixels[0]); - free((char *)f->pixels); - } - f->pixels = (Pixel **) malloc (height*sizeof(Pixel *)); - if (!f->pixels) return -1; - f->pixels[0] = (Pixel *) malloc(height*width*sizeof(Pixel)); - if (!f->pixels[0]) { - free((char *)f->pixels); - return -1; - } - for (i = 0; i < height; i++) - f->pixels[i] = f->pixels[0] + i*width; - f->width = width; - f->height = height; - if (f->zbuffer) { - FrameBuffer_zresize(f,width,height); - } - return 0; - } else { - return -1; - } -} - -/* ------------------------------------------------------------------------ - void FrameBuffer_clear(FrameBuffer *f, Pixel color) - - Clears the current FrameBuffer - ------------------------------------------------------------------------ */ - -void FrameBuffer_clear(FrameBuffer *f, Pixel color) { - Pixel *p; - unsigned int i; - p = &f->pixels[0][0]; - - for (i = 0; i < f->width*f->height; i++, p++) - *p = color; -} - -/* ------------------------------------------------------------------------ - void FrameBuffer_plot(FrameBuffer *f, int x1, int y1, Pixel color) - - Plots a point and does a bounds check. - ------------------------------------------------------------------------ */ - -void FrameBuffer_plot(FrameBuffer *f, int x1, int y1, Pixel color) { - - if ((x1 < f->xmin) || (x1 >= f->xmax) || (y1 < f->ymin) || (y1 >= f->ymax)) - return; - f->pixels[y1][x1] = color; - -} - -/* ------------------------------------------------------------------------ - FrameBuffer_horizontal(Framebuffer *f, int xmin, int xmax, int y, Pixel color) - - Draw a horizontal line (clipped) - ------------------------------------------------------------------------ */ - -void FrameBuffer_horizontal(FrameBuffer *f, int xmin, int xmax, int y, Pixel color) { - - Pixel *p; - int i; - - if ((y < f->ymin) || (y >= f->ymax)) return; - if (xmin < f->xmin) xmin = f->xmin; - if (xmax >= f->xmax) xmax = f->xmax - 1; - - p = &f->pixels[y][xmin]; - for (i = xmin; i <= xmax; i++, p++) - *p = color; - -} - -/* ------------------------------------------------------------------------ - FrameBuffer_horizontalinterp(Framebuffer *f, int xmin, int xmax, int y, - Pixel c1, Pixel c2) - - Draw a horizontal line (clipped) with color interpolation. - ------------------------------------------------------------------------ */ - -void FrameBuffer_horizontalinterp(FrameBuffer *f, int xmin, int xmax, int y, - Pixel c1, Pixel c2) { - - Pixel *p; - int i; - double mc; - int x1; - if ((y < f->ymin) || (y >= f->ymax)) return; - - x1 = xmin; - if (xmin < f->xmin) xmin = f->xmin; - if (xmax >= f->xmax) xmax = f->xmax - 1; - if (xmax < f->xmin) return; - if (xmin >= f->xmax) return; - - if (xmin != xmax) - mc = (double)(c2 - c1)/(double) (xmax - xmin); - else - mc = 0.0; - - p = &f->pixels[y][xmin]; - for (i = xmin; i <= xmax; i++, p++) - *p = (Pixel) (mc*(i-x1) + c1); - -} - - -/* ------------------------------------------------------------------------ - FrameBuffer_vertical(Framebuffer *f, int xmin, int xmax, int y, Pixel color) - - Draw a Vertical line (clipped) - ------------------------------------------------------------------------ */ - -void FrameBuffer_vertical(FrameBuffer *f, int ymin, int ymax, int x, Pixel color) { - - Pixel *p; - int i; - - if ((x < f->xmin) || (x >= f->xmax)) return; - if (ymax < f->ymin) return; - if (ymin > f->ymax) return; - if (ymin < f->ymin) ymin = f->ymin; - if (ymax >= f->ymax) ymax = f->ymax - 1; - - p = &f->pixels[ymin][x]; - for (i = 0; i <= (ymax - ymin); i++, p+=f->width) - *p = color; - -} - -/* ------------------------------------------------------------------------ - void FrameBuffer_box(FrameBuffer *f, int x1, int y1, int x2, int y2, Pixel color) - - Makes an outline box. - ------------------------------------------------------------------------ */ - -void FrameBuffer_box(FrameBuffer *f, int x1, int y1, int x2, int y2, Pixel color) { - - int xt, yt; - - /* Make sure points are in correct order */ - - if (x2 < x1) { - xt = x2; - x2 = x1; - x1 = xt; - } - if (y2 < y1) { - yt = y2; - y2 = y1; - y1 = yt; - } - - /* Draw lower edge */ - - FrameBuffer_horizontal(f,x1,x2,y1,color); - - /* Draw upper edge */ - - FrameBuffer_horizontal(f,x1,x2,y2,color); - - /* Draw left side */ - - FrameBuffer_vertical(f,y1,y2,x1,color); - - /* Draw right side */ - - FrameBuffer_vertical(f,y1,y2,x2,color); - -} - -/* ------------------------------------------------------------------------ - void FrameBuffer_solidbox(FrameBuffer *f, int x1, int y1, int x2, int y2, Pixel color) - - Makes an solid box. - ------------------------------------------------------------------------ */ - -void FrameBuffer_solidbox(FrameBuffer *f, int x1, int y1, int x2, int y2, Pixel color) { - - int xt, yt; - - /* Make sure points are in correct order */ - - if (x2 < x1) { - xt = x2; - x2 = x1; - x1 = xt; - } - if (y2 < y1) { - yt = y2; - y2 = y1; - y1 = yt; - } - - /* Now perform some clipping */ - - if (y1 < f->ymin) y1 = f->ymin; - if (y2 >= f->ymax) y2 = f->ymax - 1; - - /* Fill it in using horizontal lines */ - - for (yt = y1; yt <= y2; yt++) - FrameBuffer_horizontal(f,x1,x2,yt,color); - -} - -/* ------------------------------------------------------------------------ - void FrameBuffer_interpbox(FrameBuffer *f, int x1, int y1, int x2, int y2 - Pixel c1, Pixel c2, Pixel c3, Pixel c4) - - Makes a box with interpolated color. Colors are assigned as follows : - (x1,y1) = c1 - (x1,y2) = c2 - (x2,y1) = c3 - (x2,y2) = c4 - ------------------------------------------------------------------------ */ - -void FrameBuffer_interpbox(FrameBuffer *f, int x1, int y1, int x2, int y2, - Pixel c1, Pixel c2, Pixel c3, Pixel c4) { - - int xt, yt; - Pixel ct; - double mc1,mc2; - int ystart; - /* Make sure points are in correct order */ - - if (x2 < x1) { - xt = x2; - x2 = x1; - x1 = xt; - ct = c1; - c1 = c3; - c3 = ct; - ct = c2; - c2 = c4; - c4 = ct; - } - if (y2 < y1) { - yt = y2; - y2 = y1; - y1 = yt; - ct = c1; - c1 = c2; - c2 = ct; - ct = c3; - c3 = c4; - c4 = ct; - } - - /* Now perform some clipping */ - - ystart = y1; - mc1 = (double) (c2 - c1)/(double) (y2 - y1); - mc2 = (double) (c4 - c3)/(double) (y2 - y1); - if (y1 < f->ymin) y1 = f->ymin; - if (y2 >= f->ymax) y2 = f->ymax - 1; - - /* Fill it in using horizontal lines */ - - for (yt = y1; yt <= y2; yt++) - FrameBuffer_horizontalinterp(f,x1,x2,yt,(Pixel) ((mc1*(yt - ystart)) + c1), - (Pixel) ((mc2*(yt-ystart))+c3)); - -} - -/* --------------------------------------------------------------------------- - FrameBuffer_line(FrameBuffer *f, int x1, int y1, int x2, int y2, color) - - Draws a line on the framebuffer using the Bresenham line algorithm. The - line is clipped to fit within the current view window. - ---------------------------------------------------------------------------- */ - -void FrameBuffer_line(FrameBuffer *f, int x1, int y1, int x2, int y2, Pixel c) { - - int dx,dy,dxneg,dyneg, inc1,inc2,di; - int x, y, xpixels, ypixels, xt, yt; - Pixel *p; - double m; - int end1 = 0, end2 = 0; - - /* Need to figure out where in the heck this line is */ - - dx = x2 - x1; - dy = y2 - y1; - - if (dx == 0) { - /* Draw a Vertical Line */ - if (y1 < y2) - FrameBuffer_vertical(f,y1,y2,x1,c); - else - FrameBuffer_vertical(f,y2,y1,x1,c); - return; - } - if (dy == 0) { - /* Draw a Horizontal Line */ - if (x1 < x2) - FrameBuffer_horizontal(f,x1,x2,y1,c); - else - FrameBuffer_horizontal(f,x2,x1,y1,c); - return; - } - - /* Figure out where in the heck these lines are using the - Cohen-Sutherland Line Clipping Scheme. */ - - end1 = ((x1 - f->xmin) < 0) | - (((f->xmax- 1 - x1) < 0) << 1) | - (((y1 - f->ymin) < 0) << 2) | - (((f->ymax-1 - y1) < 0) << 3); - - end2 = ((x2 - f->xmin) < 0) | - (((f->xmax-1 - x2) < 0) << 1) | - (((y2 - f->ymin) < 0) << 2) | - (((f->ymax-1 - y2) < 0) << 3); - - if (end1 & end2) return; /* Nope : Not visible */ - - /* Make sure points have a favorable orientation */ - - if (x1 > x2) { - xt = x1; - x1 = x2; - x2 = xt; - yt = y1; - y1 = y2; - y2 = yt; - } - - /* Clip against the boundaries */ - m = (y2 - y1)/(double) (x2-x1); - if (x1 < f->xmin) { - y1 = (int) ((f->xmin - x1)*m + y1); - x1 = (int) f->xmin; - } - if (x2 >= f->xmax) { - y2 = (int) ((f->xmax -1 -x1)*m + y1); - x2 = (int) (f->xmax - 1); - } - - if (y1 > y2) { - xt = x1; - x1 = x2; - x2 = xt; - yt = y1; - y1 = y2; - y2 = yt; - } - - m = 1/m; - if (y1 < f->ymin) { - x1 = (int) ((f->ymin - y1)*m + x1); - y1 = (int) f->ymin; - } - if (y2 >= f->ymax) { - x2 = (int) ((f->ymax-1-y1)*m + x1); - y2 = (int) (f->ymax-1); - } - - if ((x1 < f->xmin) || (x1 >= f->xmax) || (y1 < f->ymin) || (y1 >= f->ymax) || - (x2 < f->xmin) || (x2 >= f->xmax) || (y2 < f->ymin) || (y2 >= f->ymax)) return; - - dx = x2 - x1; - dy = y2 - y1; - xpixels = f->width; - ypixels = f->height; - - dxneg = (dx < 0) ? 1 : 0; - dyneg = (dy < 0) ? 1 : 0; - - dx = abs(dx); - dy = abs(dy); - if (dx >= dy) { - /* Slope between -1 and 1. */ - if (dxneg) { - x = x1; - y = y1; - x1 = x2; - y1 = y2; - x2 = x; - y2 = y; - dyneg = !dyneg; - } - inc1 = 2*dy; - inc2 = 2*(dy-dx); - di = 2*dy-dx; - - /* Draw a line using x as independent variable */ - - p = &f->pixels[y1][x1]; - x = x1; - while (x <= x2) { - *(p++) = c; - if (di < 0) { - di = di + inc1; - } else { - if (dyneg) { - p = p - xpixels; - di = di + inc2; - } else { - p = p + xpixels; - di = di + inc2; - } - } - x++; - } - } else { - /* Slope < -1 or > 1 */ - if (dyneg) { - x = x1; - y = y1; - x1 = x2; - y1 = y2; - x2 = x; - y2 = y; - dxneg = !dxneg; - } - inc1 = 2*dx; - inc2 = 2*(dx-dy); - di = 2*dx-dy; - - /* Draw a line using y as independent variable */ - - p = &f->pixels[y1][x1]; - y = y1; - while (y <= y2) { - *p = c; - p = p + xpixels; - if (di < 0) { - di = di + inc1; - } else { - if (dxneg) { - p = p - 1; - di = di + inc2; - } else { - p = p + 1; - di = di + inc2; - } - } - y++; - } - } -} - - -/* ------------------------------------------------------------------------- - FrameBuffer_circle(FrameBuffer f, int xc, int yc, int radius, Pixel c) - - Create an outline circle - ------------------------------------------------------------------------- */ - -#define plot_circle(x,y,c) \ - if ((x >= xmin) && (x < xmax) && \ - (y >= ymin) && (y < ymax)) \ - pixels[y][x] = c; - -void FrameBuffer_circle(FrameBuffer *f, int xc, int yc, int radius, Pixel c) { - - int xpixels, ypixels, x, y, p; - int xmin, ymin, xmax, ymax; - Pixel **pixels; - - if (radius <= 0) return; - xpixels = f->width; - ypixels = f->height; - pixels = f->pixels; - xmin = f->xmin; - ymin = f->ymin; - xmax = f->xmax; - ymax = f->ymax; - x = 0; - y = radius; - p = 3-2*radius; - while (x <= y) { - plot_circle(xc+x,yc+y,c); - plot_circle(xc-x,yc+y,c); - plot_circle(xc+x,yc-y,c); - plot_circle(xc-x,yc-y,c); - plot_circle(xc+y,yc+x,c); - plot_circle(xc-y,yc+x,c); - plot_circle(xc+y,yc-x,c); - plot_circle(xc-y,yc-x,c); - if (p < 0) p = p + 4*x + 6; - else { - p = p + 4*(x-y) + 10; - y = y -1; - } - x++; - } -} - - -/* ------------------------------------------------------------------------- - FrameBuffer_solidcircle(FrameBuffer f, int xc, int yc, int radius, Pixel c) - - Create an filled circle - ------------------------------------------------------------------------- */ - - -#define fill_circle(x,y,c) \ - x1 = xc - x; \ - x2 = xc + x; \ - FrameBuffer_horizontal(f,x1,x2,y,c); - -void FrameBuffer_solidcircle(FrameBuffer *f, int xc, int yc, int radius, Pixel c) { - - int xpixels, ypixels, x, y, p; - int x1,x2; - int xmin, ymin, xmax, ymax; - Pixel **pixels; - - if (radius <= 0) return; - xpixels = f->width; - ypixels = f->height; - pixels = f->pixels; - xmin = f->xmin; - ymin = f->ymin; - xmax = f->xmax; - ymax = f->ymax; - x = 0; - y = radius; - p = 3-2*radius; - while (x <= y) { - fill_circle(x,yc+y,c); - fill_circle(x,yc-y,c); - fill_circle(y,yc+x,c); - fill_circle(y,yc-x,c); - if (p < 0) p = p + 4*x + 6; - else { - p = p + 4*(x-y) + 10; - y = y -1; - } - x++; - } -} - -/* ------------------------------------------------------------------------ - void FrameBuffer_setclip(f,xmin,ymin,xmax,ymax) - - Set clipping region for plotting - ------------------------------------------------------------------------ */ - -void FrameBuffer_setclip(FrameBuffer *f, int xmin, int ymin, int xmax, int ymax) { - - if (xmin >= xmax) return; - if (ymin >= ymax) return; - - if (xmin < 0) xmin = 0; - if (ymin < 0) ymin = 0; - if (xmax > (int) f->width) xmax = f->width; - if (ymax > (int) f->height) ymax = f->height; - - f->xmin = xmin; - f->ymin = ymin; - f->xmax = xmax; - f->ymax = ymax; -} - -/* ------------------------------------------------------------------------ - void FrameBuffer_noclip(f) - - Disable clipping region - ------------------------------------------------------------------------ */ - -void FrameBuffer_noclip(FrameBuffer *f) { - f->xmin = 0; - f->ymin = 0; - f->xmax = f->width; - f->ymax = f->height; -} - - -/* ------------------------------------------------------------------------ - FrameBuffer_zresize(FrameBuffer *f, int width, int height) - - This function resizes the framebuffer's zbuffer. If none exist, it - creates a new one. - ------------------------------------------------------------------------ */ - -void FrameBuffer_zresize(FrameBuffer *f, int width, int height) { - int i; - - if (f->zbuffer) { - free((char *)f->zbuffer[0]); - free((char *)f->zbuffer); - } - f->zbuffer = (Zvalue **) malloc(height*sizeof(Zvalue *)); - f->zbuffer[0] = (Zvalue *) malloc(height*width*sizeof(Zvalue)); - for (i = 0; i < height; i++) - f->zbuffer[i] = f->zbuffer[0]+i*width; -} - -/* ------------------------------------------------------------------------ - FrameBuffer_zclear(FrameBuffer *f) - - Clears the z-buffer for a particular frame. Sets all of the z-values to - ZMIN. - ------------------------------------------------------------------------- */ - -void FrameBuffer_zclear(FrameBuffer *f) { - unsigned int i,j; - if (f) { - if (f->zbuffer) { - for (i = 0; i < f->width; i++) - for (j = 0; j < f->height; j++) - f->zbuffer[j][i] = ZMIN; - } - } -} - - - -/* ------------------------------------------------------------------------- - FrameBuffer_solidtriangle(FrameBuffer *f, int tx1, int ty2, - int tx2, int ty2, - int tx3, int ty3, Pixel color) - - This function draws a 2D filled triangle. - - General idea : - 1. Transform the three points into screen coordinates - 2. Order three points vertically on screen. - 3. Check for degenerate cases (where 3 points are colinear). - 4. Fill in the resulting triangle using horizontal lines. - -------------------------------------------------------------------------- */ - -void FrameBuffer_solidtriangle(FrameBuffer *f, int tx1, int ty1, - int tx2, int ty2, - int tx3, int ty3, Pixel color) { - int tempx, tempy; - double m1,m2,m3; - int y; - int ix1, ix2; - - /* Figure out which point has the greatest "y" value */ - - if (ty2 > ty1) { /* Swap points 1 and 2 if 2 is higher */ - tempx = tx1; - tempy = ty1; - tx1 = tx2; - ty1 = ty2; - tx2 = tempx; - ty2 = tempy; - } - if (ty3 > ty1) { /* Swap points 1 and 3 if 3 is higher */ - tempx = tx1; - tempy = ty1; - tx1 = tx3; - ty1 = ty3; - tx3 = tempx; - ty3 = tempy; - } - if (ty3 > ty2) { /* Swap points 2 and 3 if 3 is higher */ - tempx = tx2; - tempy = ty2; - tx2 = tx3; - ty2 = ty3; - tx3 = tempx; - ty3 = tempy; - } - - /* Points are now order so that t_1 is the highest point, t_2 is the - middle point, and t_3 is the lowest point */ - - /* Check for degenerate cases here */ - - if ((ty1 == ty2) && (ty2 == ty3)) { - - /* Points are aligned horizontally. Handle as a special case */ - /* Just draw three lines using the outline color */ - - FrameBuffer_line(f,tx1,ty1,tx2,ty2,color); - FrameBuffer_line(f,tx1,ty1,tx3,ty3,color); - FrameBuffer_line(f,tx2,ty2,tx3,ty3,color); - - } else { - - if (ty2 < ty1) { - /* First process line segments between (x1,y1)-(x2,y2) - And between (x1,y1),(x3,y3) */ - - m1 = (double) (tx2 - tx1)/(double) (ty2 - ty1); - m2 = (double) (tx3 - tx1)/(double) (ty3 - ty1); - - y = ty1; - while (y >= ty2) { - /* Calculate x values from slope */ - ix1 = (int) (m1*(y-ty1)+0.5) + tx1; - ix2 = (int) (m2*(y-ty1)+0.5) + tx1; - if (ix1 > ix2) - FrameBuffer_horizontal(f,ix2,ix1,y,color); - else - FrameBuffer_horizontal(f,ix1,ix2,y,color); - y--; - } - } - if (ty3 < ty2) { - /* Draw lower half of the triangle */ - m2 = (double) (tx3 - tx1)/(double) (ty3 - ty1); - m3 = (double) (tx3 - tx2)/(double)(ty3 - ty2); - y = ty2; - while (y >= ty3) { - ix1 = (int) (m3*(y-ty2)+0.5)+tx2; - ix2 = (int) (m2*(y-ty1)+0.5)+tx1; - if (ix1 > ix2) - FrameBuffer_horizontal(f,ix2,ix1,y,color); - else - FrameBuffer_horizontal(f,ix1,ix2,y,color); - y--; - } - } - } -} - -/* ------------------------------------------------------------------------- - FrameBuffer_interptriangle(FrameBuffer *f, - int tx1, int ty2, Pixel c1, - int tx2, int ty2, Pixel c2, - int tx3, int ty3, Pixel c3) - - This function draws a filled triangle with color - interpolation. - - General idea : - 1. Transform the three points into screen coordinates - 2. Order three points vertically on screen. - 3. Check for degenerate cases (where 3 points are colinear). - 4. Fill in the resulting triangle using horizontal lines. - 5. Colors are interpolated between end points - -------------------------------------------------------------------------- */ - -void FrameBuffer_interptriangle(FrameBuffer *f, - int tx1, int ty1, Pixel c1, - int tx2, int ty2, Pixel c2, - int tx3, int ty3, Pixel c3) { - int tempx, tempy; - double m1,m2,m3; - double mc1,mc2,mc3; - Pixel ic1,ic2,tempc; - int y; - int ix1, ix2; - - /* Figure out which point has the greatest "y" value */ - - if (ty2 > ty1) { /* Swap points 1 and 2 if 2 is higher */ - tempx = tx1; - tempy = ty1; - tempc = c1; - tx1 = tx2; - ty1 = ty2; - c1 = c2; - tx2 = tempx; - ty2 = tempy; - c2 = tempc; - } - if (ty3 > ty1) { /* Swap points 1 and 3 if 3 is higher */ - tempx = tx1; - tempy = ty1; - tempc = c1; - tx1 = tx3; - ty1 = ty3; - c1 = c3; - tx3 = tempx; - ty3 = tempy; - c3 = tempc; - } - if (ty3 > ty2) { /* Swap points 2 and 3 if 3 is higher */ - tempx = tx2; - tempy = ty2; - tempc = c2; - tx2 = tx3; - ty2 = ty3; - c2 = c3; - tx3 = tempx; - ty3 = tempy; - c3 = tempc; - } - - /* Points are now order so that t_1 is the highest point, t_2 is the - middle point, and t_3 is the lowest point */ - - /* Check for degenerate cases here */ - - if ((ty1 == ty2) && (ty2 == ty3)) { - - /* Points are aligned horizontally. Handle as a special case */ - /* Just draw three lines using the outline color */ - - if (tx2 > tx1) - FrameBuffer_horizontalinterp(f,tx1,tx2,ty1,c1,c2); - else - FrameBuffer_horizontalinterp(f,tx2,tx1,ty1,c2,c1); - if (tx3 > tx1) - FrameBuffer_horizontalinterp(f,tx1,tx3,ty1,c1,c3); - else - FrameBuffer_horizontalinterp(f,tx3,tx1,ty1,c3,c1); - if (tx3 > tx2) - FrameBuffer_horizontalinterp(f,tx2,tx3,ty2,c2,c3); - else - FrameBuffer_horizontalinterp(f,tx3,tx2,ty2,c3,c2); - - } else { - - /* First process line segments between (x1,y1)-(x2,y2) - And between (x1,y1),(x3,y3) */ - - if (ty2 < ty1) { - m1 = (double) (tx2 - tx1)/(double) (ty2 - ty1); - m2 = (double) (tx3 - tx1)/(double) (ty3 - ty1); - mc1 = (c2 - c1)/(double) (ty2 - ty1); - mc2 = (c3 - c1)/(double) (ty3 - ty1); - - y = ty1; - while (y >= ty2) { - /* Calculate x values from slope */ - ix1 = (int) (m1*(y-ty1)+0.5) + tx1; - ix2 = (int) (m2*(y-ty1)+0.5) + tx1; - ic1 = (int) (mc1*(y-ty1) + c1); - ic2 = (int) (mc2*(y-ty1) + c1); - if (ix1 > ix2) - FrameBuffer_horizontalinterp(f,ix2,ix1,y,ic2,ic1); - else - FrameBuffer_horizontalinterp(f,ix1,ix2,y,ic1,ic2); - y--; - } - } - if (ty3 < ty2) { - /* Draw lower half of the triangle */ - m2 = (double) (tx3 - tx1)/(double) (ty3 - ty1); - mc2 = (c3 - c1)/(double) (ty3 - ty1); - m3 = (double) (tx3 - tx2)/(double)(ty3 - ty2); - mc3 = (c3 - c2)/(double) (ty3 - ty2); - y = ty2; - while (y >= ty3) { - ix1 = (int) (m3*(y-ty2)+0.5)+tx2; - ix2 = (int) (m2*(y-ty1)+0.5)+tx1; - ic1 = (int) (mc3*(y-ty2)+c2); - ic2 = (int) (mc2*(y-ty1)+c1); - if (ix1 > ix2) - FrameBuffer_horizontalinterp(f,ix2,ix1,y,ic2,ic1); - else - FrameBuffer_horizontalinterp(f,ix1,ix2,y,ic1,ic2); - y--; - } - } - } -} - - diff --git a/Examples/GIFPlot/Lib/gif.c b/Examples/GIFPlot/Lib/gif.c deleted file mode 100644 index 7953e5ce9..000000000 --- a/Examples/GIFPlot/Lib/gif.c +++ /dev/null @@ -1,672 +0,0 @@ - -/********************************************************************** - * GIFPlot 0.0 - * - * Dave Beazley - * - * Department of Computer Science Theoretical Division (T-11) - * University of Utah Los Alamos National Laboratory - * Salt Lake City, Utah 84112 Los Alamos, New Mexico 87545 - * beazley@cs.utah.edu beazley@lanl.gov - * - * Copyright (c) 1996 - * The Regents of the University of California and the University of Utah - * 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 - * 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 - * described here, provided that the new terms are clearly indicated in - * all files where they apply. - * - * IN NO EVENT SHALL THE AUTHOR, THE UNIVERSITY OF CALIFORNIA, THE - * UNIVERSITY OF UTAH OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY - * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL - * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, - * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - * THE AUTHOR, THE UNIVERSITY OF CALIFORNIA, AND THE UNIVERSITY OF UTAH - * SPECIFICALLY DISCLAIM ANY WARRANTIES,INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND - * THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, - * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - **************************************************************************/ - -/******************************************************************* - * Creates a GIF format file. - * - * Dave Beazley (T-11) - * August 11, 1995 - * - * Rather than writing directly to files, this module fills out - * output buffer. - * - * Note : To save memory, this routine uses approximately 50K of the - * output buffer as temporary storage (for hash tables and compression codes). - * The remainder of the output buffer is used to store the final image. - * This feature allows GIF images to be created with no additional - * memory overhead. - * - * -- Revision History - * $Log$ - * Revision 1.2 2003/09/01 16:23:31 beazley - * Restored the 'mojo'. - * - * Revision 1.2 1996/09/25 22:39:30 dmb - * Fixed prototypes and use of void pointers for compatibility with the Cray T3D - * - * Revision 1.1 1996/09/10 17:44:00 dmb - * Initial revision - * - * Revision 1.2 1995/08/31 14:46:07 beazley - * Minor changes to support comments and a few bug fixes. - * - * - ******************************************************************/ - - -/* - * xvgifwr.c - handles writing of GIF files. based on flgife.c and - * flgifc.c from the FBM Library, by Michael Maudlin - * - * Contains: - * WriteGIF(fp, pic, ptype, w, h, rmap, gmap, bmap, numcols, colorstyle, - * comment) - * - * Note: slightly brain-damaged, in that it'll only write non-interlaced - * GIF files (in the interests of speed, or something) - * - */ - - - -/***************************************************************** - * Portions of this code Copyright (C) 1989 by Michael Mauldin. - * Permission is granted to use this file in whole or in - * part for any purpose, educational, recreational or commercial, - * provided that this copyright notice is retained unchanged. - * This software is available to all free of charge by anonymous - * FTP and in the UUNET archives. - * - * - * Authors: Michael Mauldin (mlm@cs.cmu.edu) - * David Rowley (mgardi@watdcsu.waterloo.edu) - * - * Based on: compress.c - File compression ala IEEE Computer, June 1984. - * - * Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas) - * Jim McKie (decvax!mcvax!jim) - * Steve Davies (decvax!vax135!petsd!peora!srd) - * Ken Turkowski (decvax!decwrl!turtlevax!ken) - * James A. Woods (decvax!ihnp4!ames!jaw) - * Joe Orost (decvax!vax135!petsd!joe) - *****************************************************************/ - -#include "gifplot.h" -#include -typedef long int count_int; -typedef unsigned char byte; - -static int gif_error; -static unsigned char *op; -static int Width, Height; -static int curx, cury; -static int Interlace; - -static void putgifword(int); -static void compress(int, byte **, int); -static void output_GIF(int); -static void cl_block(void); -static void cl_hash(count_int); -static void char_init(void); -static void char_out(int); -static void flush_char(void); -static void *OutBuffer; -static int OutBufSize; -static FrameBuffer *GIF_frame; - -static unsigned char pc2nc[256],r1[256],g1[256],b1[256]; - -/*************************************************************/ -int FrameBuffer_makeGIF(FrameBuffer *f, ColorMap *c, void *outbuffer, unsigned int outbufsize) -{ - int RWidth, RHeight; - int LeftOfs, TopOfs; - int ColorMapSize, InitCodeSize, Background, BitsPerPixel; - int i,j,nc; - char *rmap, *gmap, *bmap; - char *cmap; - int count; - - Interlace = 0; - Background = 0; - OutBuffer = outbuffer; - OutBufSize = outbufsize; - GIF_frame = f; - cmap = (char *) c->cmap; - - op = (unsigned char *) outbuffer; - gif_error = 0; - for (i=0; i<256; i++) { pc2nc[i] = r1[i] = g1[i] = b1[i] = 0; } - - /* compute number of unique colors */ - nc = 0; - rmap = &cmap[0]; - gmap = &cmap[256]; - bmap = &cmap[512]; - - for (i=0; i<256; i++) { - /* see if color #i is already used */ - for (j=0; j= nc) break; - - BitsPerPixel = i; - - ColorMapSize = 1 << BitsPerPixel; - - RWidth = Width = f->width; - RHeight = Height = f->height; - LeftOfs = TopOfs = 0; - - if (BitsPerPixel <= 1) InitCodeSize = 2; - else InitCodeSize = BitsPerPixel; - - curx = 0; - cury = f->height - 1; - - strcpy((char *) op,"GIF89a"); /* Put in GIF magic number */ - op+=6; - putgifword(RWidth); /* screen descriptor */ - putgifword(RHeight); - - i = 0x80; /* Yes, there is a color map */ - i |= (8-1)<<4; /* OR in the color resolution (hardwired 8) */ - i |= (BitsPerPixel - 1); /* OR in the # of bits per pixel */ - *(op++) = i; - *(op++) = Background; /* background color */ - *(op++) = 0; - for (i=0; ipixels, f->width*f->height); - - *(op++) = 0; - *(op++) = ';'; - - count = (op - (unsigned char *) OutBuffer); - if (gif_error) return -1; - else return count; -} - -/******************************/ -static void putgifword(w) -int w; -{ - /* writes a 16-bit integer in GIF order (LSB first) */ - *(op++) = w & 0xff; - *(op++) = (w>>8)&0xff; -} - -/***********************************************************************/ - - -static unsigned long cur_accum = 0; -static int cur_bits = 0; - - - - -#define GP_BITS 12 /* BITS was already defined on some systems */ - -#define HSIZE 5003 /* 80% occupancy */ - -typedef unsigned char char_type; - -static int n_bits; /* number of bits/code */ -static int maxbits = GP_BITS; /* user settable max # bits/code */ -static int maxcode; /* maximum code, given n_bits */ -static int maxmaxcode = 1 << GP_BITS; /* NEVER generate this */ - -#define MAXCODE(n_bits) ( (1 << (n_bits)) - 1) - -static count_int *htab; -static unsigned short *codetab; -static int GIFOutBufSize; - -/* static count_int htab [HSIZE]; -static unsigned short codetab [HSIZE]; */ - -#define HashTabOf(i) htab[i] -#define CodeTabOf(i) codetab[i] - -static int hsize = HSIZE; /* for dynamic table sizing */ - -/* - * To save much memory, we overlay the table used by compress() with those - * used by decompress(). The tab_prefix table is the same size and type - * as the codetab. The tab_suffix table needs 2**BITS characters. We - * get this from the beginning of htab. The output stack uses the rest - * of htab, and contains characters. There is plenty of room for any - * possible stack (stack used to be 8000 characters). - */ - -#define tab_prefixof(i) CodeTabOf(i) -#define tab_suffixof(i) ((char_type *)(htab))[i] -#define de_stack ((char_type *)&tab_suffixof(1<= GIF_frame->width) { - curx = 0; - cury--; - } - len--; - - hshift = 0; - for ( fcode = (long) hsize; fcode < 65536L; fcode *= 2L ) - hshift++; - hshift = 8 - hshift; /* set hash code range bound */ - - hsize_reg = hsize; - cl_hash( (count_int) hsize_reg); /* clear hash table */ - - output_GIF(ClearCode); - while (len) { - c = pc2nc[data[cury][curx]]; - curx++; - if (curx >= GIF_frame->width) { - curx = 0; - cury--; - } - len--; - - fcode = (long) ( ( (long) c << maxbits) + ent); - i = (((int) c << hshift) ^ ent); /* xor hashing */ - - if ( HashTabOf (i) == fcode ) { - ent = CodeTabOf (i); - continue; - } - - if ( (long)HashTabOf (i) < 0 ) /* empty slot */ - goto nomatch; - - disp = hsize_reg - i; /* secondary hash (after G. Knott) */ - if ( i == 0 ) - disp = 1; - -probe: - if ( (i -= disp) < 0 ) - i += hsize_reg; - - if ( HashTabOf (i) == fcode ) { - ent = CodeTabOf (i); - continue; - } - - if ( (long)HashTabOf (i) >= 0 ) - goto probe; - -nomatch: - output_GIF(ent); - out_count++; - ent = c; - - if ( free_ent < maxmaxcode ) { - CodeTabOf (i) = free_ent++; /* code -> hashtable */ - HashTabOf (i) = fcode; - } - else - cl_block(); - - } - /* Put out the final code */ - output_GIF(ent); - output_GIF(EOFCode); -} - - -/***************************************************************** - * TAG( output_GIF ) - * - * Output the given code. - * Inputs: - * code: A n_bits-bit integer. If == -1, then EOF. This assumes - * that n_bits =< (long)wordsize - 1. - * Outputs: - * Outputs code to the file. - * Assumptions: - * Chars are 8 bits long. - * Algorithm: - * Maintain a BITS character long buffer (so that 8 codes will - * fit in it exactly). Use the VAX insv instruction to insert each - * code in turn. When the buffer fills up empty it and start over. - */ - -static -unsigned long masks[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, - 0x001F, 0x003F, 0x007F, 0x00FF, - 0x01FF, 0x03FF, 0x07FF, 0x0FFF, - 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF }; - -static void output_GIF(code) -int code; -{ - cur_accum &= masks[cur_bits]; - - if (cur_bits > 0) - cur_accum |= ((long)code << cur_bits); - else - cur_accum = code; - - cur_bits += n_bits; - - while( cur_bits >= 8 ) { - char_out( (int) (cur_accum & 0xff) ); - cur_accum >>= 8; - cur_bits -= 8; - } - - /* - * If the next entry is going to be too big for the code size, - * then increase it, if possible. - */ - - if (free_ent > maxcode || clear_flg) { - - if( clear_flg ) { - maxcode = MAXCODE (n_bits = g_init_bits); - clear_flg = 0; - } - else { - n_bits++; - if ( n_bits == maxbits ) - maxcode = maxmaxcode; - else - maxcode = MAXCODE(n_bits); - } - } - - if( code == EOFCode ) { - /* At EOF, write the rest of the buffer */ - while( cur_bits > 0 ) { - char_out( (int)(cur_accum & 0xff) ); - cur_accum >>= 8; - cur_bits -= 8; - } - - flush_char(); - } -} - - -/********************************/ -static void cl_block () /* table clear for block compress */ -{ - /* Clear out the hash table */ - - cl_hash ( (count_int) hsize ); - free_ent = ClearCode + 2; - clear_flg = 1; - - output_GIF(ClearCode); -} - - -/********************************/ -static void cl_hash(hsize) /* reset code table */ -register count_int hsize; -{ - register count_int *htab_p = htab+hsize; - register long i; - register long m1 = -1; - - i = hsize - 16; - do { /* might use Sys V memset(3) here */ - *(htab_p-16) = m1; - *(htab_p-15) = m1; - *(htab_p-14) = m1; - *(htab_p-13) = m1; - *(htab_p-12) = m1; - *(htab_p-11) = m1; - *(htab_p-10) = m1; - *(htab_p-9) = m1; - *(htab_p-8) = m1; - *(htab_p-7) = m1; - *(htab_p-6) = m1; - *(htab_p-5) = m1; - *(htab_p-4) = m1; - *(htab_p-3) = m1; - *(htab_p-2) = m1; - *(htab_p-1) = m1; - htab_p -= 16; - } while ((i -= 16) >= 0); - - for ( i += 16; i > 0; i-- ) - *--htab_p = m1; -} - - -/****************************************************************************** - * - * GIF Specific routines - * - ******************************************************************************/ - -/* - * Number of characters so far in this 'packet' - */ -static int a_count; - -/* - * Set up the 'byte output' routine - */ -static void char_init() -{ - a_count = 0; -} - -/* - * Define the storage for the packet accumulator - */ -static char accum[ 256 ]; - -/* - * Add a character to the end of the current packet, and if it is 254 - * characters, flush the packet to disk. - */ -static void char_out(c) -int c; -{ - accum[ a_count++ ] = c; - if( a_count >= 254 ) - flush_char(); -} - -/* - * Flush the packet to disk, and reset the accumulator - */ -static void flush_char() -{ - if (gif_error) return; - if( a_count > 0 ) { - *(op++) = a_count; - memcpy(op,accum,a_count); - op+=a_count; - a_count = 0; - - if (op > (unsigned char *) ((char *) OutBuffer + (GIFOutBufSize - 2048))) { - gif_error = 1; - } - } -} - - -/* ---------------------------------------------------------------------- - int FrameBuffer_writeGIF(char *filename) - - Write a GIF file to filename - ----------------------------------------------------------------------- */ - -int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename) { - - FILE *file; - void *buffer; - int nbytes; - int bufsize; - - file = fopen(filename,"wb"); - if (file == NULL) return -1; - - bufsize = (f->width*f->height*3)/2; - buffer = (void *) malloc(bufsize); - nbytes = FrameBuffer_makeGIF(f,c,buffer,bufsize); - if (nbytes == -1) { - free(buffer); - fclose(file); - return -1; - } - if (fwrite(buffer,nbytes,1,file) != 1) { - free(buffer); - fclose(file); - return -1; - } - fclose(file); - free(buffer); - return 0; -} - - - - - diff --git a/Examples/GIFPlot/Lib/matrix.c b/Examples/GIFPlot/Lib/matrix.c deleted file mode 100644 index ef0cf3aab..000000000 --- a/Examples/GIFPlot/Lib/matrix.c +++ /dev/null @@ -1,343 +0,0 @@ -/* ----------------------------------------------------------------------------- - * matrix.c - * - * Some 4x4 matrix operations - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * Copyright (C) 1995-1996 - * - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -#define MATRIX -#include "gifplot.h" -#include - -/* ------------------------------------------------------------------------ - Matrix new_Matrix() - - Create a new 4x4 matrix. - ------------------------------------------------------------------------ */ -Matrix -new_Matrix() { - Matrix m; - m = (Matrix) malloc(16*sizeof(double)); - return m; -} - -/* ------------------------------------------------------------------------ - delete_Matrix(Matrix *m); - - Destroy a matrix - ------------------------------------------------------------------------ */ - -void -delete_Matrix(Matrix m) { - if (m) - free((char *) m); -} - -/* ------------------------------------------------------------------------ - Matrix Matrix_copy(Matrix a) - - Makes a copy of matrix a and returns it. - ------------------------------------------------------------------------ */ - -Matrix Matrix_copy(Matrix a) { - int i; - Matrix r = 0; - if (a) { - r = new_Matrix(); - if (r) { - for (i = 0; i < 16; i++) - r[i] = a[i]; - } - } - return r; -} - -/* ------------------------------------------------------------------------ - Matrix_multiply(Matrix a, Matrix b, Matrix c) - - Multiplies a*b = c - c may be one of the source matrices - ------------------------------------------------------------------------ */ -void -Matrix_multiply(Matrix a, Matrix b, Matrix c) { - double temp[16]; - int i,j,k; - - for (i =0; i < 4; i++) - for (j = 0; j < 4; j++) { - temp[i*4+j] = 0.0; - for (k = 0; k < 4; k++) - temp[i*4+j] += a[i*4+k]*b[k*4+j]; - } - for (i = 0; i < 16; i++) - c[i] = temp[i]; -} - -/* ------------------------------------------------------------------------ - Matrix_identity(Matrix a) - - Puts an identity matrix in matrix a - ------------------------------------------------------------------------ */ - -void -Matrix_identity(Matrix a) { - int i; - for (i = 0; i < 16; i++) a[i] = 0; - a[0] = 1; - a[5] = 1; - a[10] = 1; - a[15] = 1; -} - -/* ------------------------------------------------------------------------ - Matrix_zero(Matrix a) - - Puts a zero matrix in matrix a - ------------------------------------------------------------------------ */ -void -Matrix_zero(Matrix a) { - int i; - for (i = 0; i < 16; i++) a[i] = 0; -} - -/* ------------------------------------------------------------------------ - Matrix_transpose(Matrix a, Matrix result) - - Transposes matrix a and puts it in result. - ------------------------------------------------------------------------ */ -void -Matrix_transpose(Matrix a, Matrix result) { - double temp[16]; - int i,j; - - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) - temp[4*i+j] = a[4*j+i]; - - for (i = 0; i < 16; i++) - result[i] = temp[i]; -} - - -/* ------------------------------------------------------------------------ - Matrix_gauss(Matrix a, Matrix b) - - Solves ax=b for x, using Gaussian elimination. Destroys a. - Really only used for calculating inverses of 4x4 transformation - matrices. - ------------------------------------------------------------------------ */ - -void Matrix_gauss(Matrix a, Matrix b) { - int ipiv[4], indxr[4], indxc[4]; - int i,j,k,l,ll; - int irow=0, icol=0; - double big, pivinv; - double dum; - for (j = 0; j < 4; j++) - ipiv[j] = 0; - for (i = 0; i < 4; i++) { - big = 0; - for (j = 0; j < 4; j++) { - if (ipiv[j] != 1) { - for (k = 0; k < 4; k++) { - if (ipiv[k] == 0) { - if (fabs(a[4*j+k]) >= big) { - big = fabs(a[4*j+k]); - irow = j; - icol = k; - } - } else if (ipiv[k] > 1) - return; /* Singular matrix */ - } - } - } - ipiv[icol] = ipiv[icol]+1; - if (irow != icol) { - for (l = 0; l < 4; l++) { - dum = a[4*irow+l]; - a[4*irow+l] = a[4*icol+l]; - a[4*icol+l] = dum; - } - for (l = 0; l < 4; l++) { - dum = b[4*irow+l]; - b[4*irow+l] = b[4*icol+l]; - b[4*icol+l] = dum; - } - } - indxr[i] = irow; - indxc[i] = icol; - if (a[4*icol+icol] == 0) return; - pivinv = 1.0/a[4*icol+icol]; - a[4*icol+icol] = 1.0; - for (l = 0; l < 4; l++) - a[4*icol+l] = a[4*icol+l]*pivinv; - for (l = 0; l < 4; l++) - b[4*icol+l] = b[4*icol+l]*pivinv; - for (ll = 0; ll < 4; ll++) { - if (ll != icol) { - dum = a[4*ll+icol]; - a[4*ll+icol] = 0; - for (l = 0; l < 4; l++) - a[4*ll+l] = a[4*ll+l] - a[4*icol+l]*dum; - for (l = 0; l < 4; l++) - b[4*ll+l] = b[4*ll+l] - b[4*icol+l]*dum; - } - } - } - for (l = 3; l >= 0; l--) { - if (indxr[l] != indxc[l]) { - for (k = 0; k < 4; k++) { - dum = a[4*k+indxr[l]]; - a[4*k+indxr[l]] = a[4*k+indxc[l]]; - a[4*k+indxc[l]] = dum; - } - } - } -} - -/* ------------------------------------------------------------------------ - Matrix_invert(Matrix a, Matrix inva) - - Inverts Matrix a and places the result in inva. - Relies on the Gaussian Elimination code above. (See Numerical recipes). - ------------------------------------------------------------------------ */ -void -Matrix_invert(Matrix a, Matrix inva) { - - double temp[16]; - int i; - - for (i = 0; i < 16; i++) - temp[i] = a[i]; - Matrix_identity(inva); - Matrix_gauss(temp,inva); -} - -/* ------------------------------------------------------------------------ - Matrix_transform(Matrix a, GL_Vector *r, GL_Vector *t) - - Transform a vector. a*r ----> t - ------------------------------------------------------------------------ */ - -void Matrix_transform(Matrix a, GL_Vector *r, GL_Vector *t) { - - double rx, ry, rz, rw; - - rx = r->x; - ry = r->y; - rz = r->z; - rw = r->w; - t->x = a[0]*rx + a[1]*ry + a[2]*rz + a[3]*rw; - t->y = a[4]*rx + a[5]*ry + a[6]*rz + a[7]*rw; - t->z = a[8]*rx + a[9]*ry + a[10]*rz + a[11]*rw; - t->w = a[12]*rx + a[13]*ry + a[14]*rz + a[15]*rw; -} - -/* ------------------------------------------------------------------------ - Matrix_transform4(Matrix a, double x, double y, double z, double w, GL_Vector *t) - - Transform a vector from a point specified as 4 doubles - ------------------------------------------------------------------------ */ - -void Matrix_transform4(Matrix a, double rx, double ry, double rz, double rw, - GL_Vector *t) { - - t->x = a[0]*rx + a[1]*ry + a[2]*rz + a[3]*rw; - t->y = a[4]*rx + a[5]*ry + a[6]*rz + a[7]*rw; - t->z = a[8]*rx + a[9]*ry + a[10]*rz + a[11]*rw; - t->w = a[12]*rx + a[13]*ry + a[14]*rz + a[15]*rw; -} - -/* --------------------------------------------------------------------- - Matrix_translate(Matrix a, double tx, double ty, double tz) - - Put a translation matrix in Matrix a - ---------------------------------------------------------------------- */ - -void Matrix_translate(Matrix a, double tx, double ty, double tz) { - Matrix_identity(a); - a[3] = tx; - a[7] = ty; - a[11] = tz; - a[15] = 1; -} - -/* ----------------------------------------------------------------------- - Matrix_rotatex(Matrix a, double deg) - - Produce an x-rotation matrix for given angle in degrees. - ----------------------------------------------------------------------- */ -void -Matrix_rotatex(Matrix a, double deg) { - double r; - - r = 3.1415926*deg/180.0; - Matrix_zero(a); - a[0] = 1.0; - a[5] = cos(r); - a[6] = -sin(r); - a[9] = sin(r); - a[10] = cos(r); - a[15] = 1.0; -} - -/* ----------------------------------------------------------------------- - Matrix_rotatey(Matrix a, double deg) - - Produce an y-rotation matrix for given angle in degrees. - ----------------------------------------------------------------------- */ -void -Matrix_rotatey(Matrix a, double deg) { - double r; - - r = 3.1415926*deg/180.0; - Matrix_zero(a); - a[0] = cos(r); - a[2] = sin(r); - a[5] = 1.0; - a[8] = -sin(r); - a[10] = cos(r); - a[15] = 1; - -} -/* ----------------------------------------------------------------------- - Matrix_RotateZ(Matrix a, double deg) - - Produce an z-rotation matrix for given angle in degrees. - ----------------------------------------------------------------------- */ -void -Matrix_rotatez(Matrix a, double deg) { - double r; - - r = 3.1415926*deg/180.0; - Matrix_zero(a); - a[0] = cos(r); - a[1] = -sin(r); - a[4] = sin(r); - a[5] = cos(r); - a[10] = 1.0; - a[15] = 1.0; -} - - -/* A debugging routine */ - -void Matrix_set(Matrix a, int i, int j, double val) { - a[4*j+i] = val; -} - -void Matrix_print(Matrix a) { - int i,j; - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - fprintf(stdout,"%10f ",a[4*i+j]); - } - fprintf(stdout,"\n"); - } - fprintf(stdout,"\n"); -} - diff --git a/Examples/GIFPlot/Lib/pixmap.c b/Examples/GIFPlot/Lib/pixmap.c deleted file mode 100644 index a55cf041f..000000000 --- a/Examples/GIFPlot/Lib/pixmap.c +++ /dev/null @@ -1,159 +0,0 @@ -/* ----------------------------------------------------------------------------- - * pixmap.c - * - * Pixel maps (i.e., bitmaps) - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * Copyright (C) 1995-1996 - * - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -#define PIXMAP -#include "gifplot.h" - -/* ----------------------------------------------------------------------- - PixMap *new_PixMap(int width, int height, int centerx, int centery) - - Create a new pixmap of given size - ----------------------------------------------------------------------- */ -PixMap *new_PixMap(int width, int height, int centerx, int centery) { - PixMap *pm; - if ((width > 0) && (height > 0)) { - pm = (PixMap *) malloc(sizeof(PixMap)); - pm->width = width; - pm->height = height; - pm->centerx = centerx; - pm->centery = centery; - pm->map = (int *) malloc(height*width*sizeof(int)); - return pm; - } - return (PixMap *) 0; -} - -/* -------------------------------------------------------------------------- - void delete_PixMap(PixMap *pm) - - Destroy a pixmap - -------------------------------------------------------------------------- */ - -void delete_PixMap(PixMap *pm) { - if (pm) { - free((char *) pm->map); - free((char *) pm); - } -} - -/* --------------------------------------------------------------------------- - void PixMap_set(PixMap *pm, int x, int y, int pix) - - Set a pixel in the bitmap - --------------------------------------------------------------------------- */ -void -PixMap_set(PixMap *pm, int x, int y, int pix) { - if ((x < 0) || (x>=pm->width)) return; - if ((y < 0) || (y>=pm->height)) return; - - pm->map[pm->width*y + x] = pix; -} - -/* ----------------------------------------------------------------------------- - void FrameBuffer_drawpixmap(FrameBuffer *f, PixMap *pm, int x, int y, int fgcolor, int bgcolor) - - Draw a pixmap onto the framebuffer. This is somewhat optimized for speed. - ------------------------------------------------------------------------------ */ - -void -FrameBuffer_drawpixmap(FrameBuffer *f, PixMap *pm, int x, int y, int fgcolor, int bgcolor) { - - int startx, starty; /* Starting location on framebuffer */ - int startpixx = 0, startpixy = 0; /* Starting location in pixmap */ - int endx, endy; /* Ending location on framebuffer */ - int i,j, px, py; - int c; - - startx = x - pm->centerx; - starty = y + pm->centery; - endx = startx + pm->width; - endy = starty - pm->height; - - /* Figure out if we need to clip */ - - if (startx < f->xmin) { - startpixx = f->xmin - startx; - startx = f->xmin; - } - if (starty >= f->ymax) { - startpixy = starty - f->ymax; - starty = f->ymax-1; - } - if (endx >= f->xmax) { - endx = f->xmax-1; - } - if (endy < f->ymin) { - endy = f->ymin; - } - py = startpixy; - for (j = starty; j >= endy; j--) { - px = startpixx; - for (i = startx; i < endx; i++) { - c = pm->map[py*pm->width + px]; - switch (c) { - case GIFPLOT_FOREGROUND: - f->pixels[j][i] = fgcolor; - break; - case GIFPLOT_BACKGROUND: - f->pixels[j][i] = bgcolor; - break; - default: - break; - } - px++; - } - py++; - } -} - -/************************************************************************** - * Some common PixMaps (for plotting) - * - **************************************************************************/ - -int _SQUARE_MAP[] = { - 0,1,1,1,1,1,1,1, - 0,1,1,1,1,1,1,1, - 0,1,1,1,1,1,1,1, - 0,1,1,1,1,1,1,1, - 0,1,1,1,1,1,1,1, - 0,1,1,1,1,1,1,1, - 0,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0 }; - -PixMap PixMap_SQUARE = { 8,8,4,4, _SQUARE_MAP}; - -int _TRIANGLE_MAP[] = { - 0,0,0,1,0,0,0,0, - 0,0,0,1,0,0,0,0, - 0,0,1,1,1,0,0,0, - 0,0,1,1,1,0,0,0, - 0,1,1,1,1,1,0,0, - 0,1,1,1,1,1,0,0, - 1,1,1,1,1,1,1,0, - 0,0,0,0,0,0,0,0 }; - -PixMap PixMap_TRIANGLE = { 8,8,4,4,_TRIANGLE_MAP}; - -int _CROSS_MAP[] = { - 0,0,0,1,0,0,0,0, - 0,0,0,1,0,0,0,0, - 0,0,0,1,0,0,0,0, - 1,1,1,1,1,1,1,0, - 0,0,0,1,0,0,0,0, - 0,0,0,1,0,0,0,0, - 0,0,0,1,0,0,0,0, - 0,0,0,0,0,0,0,0 }; - -PixMap PixMap_CROSS = { 8,8,4,4,_CROSS_MAP}; - - - diff --git a/Examples/GIFPlot/Lib/plot2d.c b/Examples/GIFPlot/Lib/plot2d.c deleted file mode 100644 index e78107bf1..000000000 --- a/Examples/GIFPlot/Lib/plot2d.c +++ /dev/null @@ -1,445 +0,0 @@ -/* ----------------------------------------------------------------------------- - * plot2d.c - * - * 2-Dimensional plotting - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * Copyright (C) 1995-1996 - * - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -#define PLOT2D - -#include "gifplot.h" - -/* ------------------------------------------------------------------------ - Plot2D *new_Plot2D(FrameBuffer *frame, xmin, ymin, xmax, ymax) - - Create a new 2D plot with given minimum and maximum coordinates. - ------------------------------------------------------------------------ */ -Plot2D *new_Plot2D(FrameBuffer *frame,double xmin,double ymin,double xmax,double ymax) { - Plot2D *p2; - if (frame) { - if (xmax <= xmin) return (Plot2D *) 0; - if (ymax <= ymin) return (Plot2D *) 0; - p2 = (Plot2D *) malloc(sizeof(Plot2D)); - p2->frame = frame; - p2->xmin = xmin; - p2->ymin = ymin; - p2->xmax = xmax; - p2->ymax = ymax; - p2->view_xmin = 0; - p2->view_xmax = frame->width; - p2->view_ymin = 0; - p2->view_ymax = frame->height; - p2->xscale = LINEAR; - p2->yscale = LINEAR; - p2->dx = (p2->view_xmax - p2->view_xmin)/(p2->xmax - p2->xmin); - p2->dy = (p2->view_ymax - p2->view_ymin)/(p2->ymax - p2->ymin); - return p2; - } - return (Plot2D *) 0; -} - -/* ---------------------------------------------------------------------------- - delete_Plot2D(Plot2D *p2) - - Delete a 2D plot - ---------------------------------------------------------------------------- */ -void -delete_Plot2D(Plot2D *p2) { - if (p2) - free((char *) p2); -} - -/* ----------------------------------------------------------------------------- - Plot2D *Plot2D_copy(Plot2D *p2) - - Makes a copy of the Plot2D data structure. - ----------------------------------------------------------------------------- */ - -Plot2D *Plot2D_copy(Plot2D *p2) { - Plot2D *c2; - if (p2) { - c2 = (Plot2D *) malloc(sizeof(Plot2D)); - if (c2) { - c2->frame = p2->frame; - c2->view_xmin = p2->view_xmin; - c2->view_ymin = p2->view_ymin; - c2->view_xmax = p2->view_xmax; - c2->view_ymax = p2->view_ymax; - c2->xmin = p2->xmin; - c2->ymin = p2->ymin; - c2->xmax = p2->xmax; - c2->ymax = p2->ymax; - c2->xscale = p2->xscale; - c2->yscale = p2->yscale; - c2->dx = p2->dx; - c2->dy = p2->dy; - } - return c2; - } else { - return (Plot2D *) 0; - } -} - -/* ----------------------------------------------------------------------------- - Plot2D_clear(Plot2D *p2, Pixel c) - - Clear the region assigned to this plot to the given color. - -------------------------------------------------------------------------- */ - -void Plot2D_clear(Plot2D *p2, Pixel c) { - int i,j; - for (i = p2->view_xmin; i < p2->view_xmax; i++) - for (j = p2->view_ymin; j < p2->view_ymax; j++) { - p2->frame->pixels[j][i] = c; - } -} - -/* ------------------------------------------------------------------------------ - Plot2D_setview - - Sets the plot region on the framebuffer - ------------------------------------------------------------------------------ */ - -void -Plot2D_setview(Plot2D *p2, int vxmin, int vymin, int vxmax, int vymax) { - if (p2) { - p2->view_xmin = vxmin; - p2->view_ymin = vymin; - p2->view_xmax = vxmax; - p2->view_ymax = vymax; - p2->dx = (p2->view_xmax - p2->view_xmin)/(p2->xmax - p2->xmin); - p2->dy = (p2->view_ymax - p2->view_ymin)/(p2->ymax - p2->ymin); - FrameBuffer_setclip(p2->frame,vxmin,vymin,vxmax,vymax); - } -} - -/* ------------------------------------------------------------------------------- - Plot2D_setrange(Plot2D *p2, double xmin, double ymin, double xmax, double ymax) - - Sets the plotting range. - ------------------------------------------------------------------------------- */ - -void -Plot2D_setrange(Plot2D *p2, double xmin, double ymin, double xmax, double ymax) { - if (p2) { - p2->xmin = xmin; - p2->ymin = ymin; - p2->xmax = xmax; - p2->ymax = ymax; - p2->dx = (p2->view_xmax - p2->view_xmin)/(p2->xmax - p2->xmin); - p2->dy = (p2->view_ymax - p2->view_ymin)/(p2->ymax - p2->ymin); - } -} - -/* ------------------------------------------------------------------------------- - Plot2D_setscale(Plot2D *p2, int xscale, int yscale) - - Sets the plotting scaling method - ------------------------------------------------------------------------------- */ - -void -Plot2D_setscale(Plot2D *p2, int xscale, int yscale) { - if (p2) { - p2->xscale = xscale; - p2->yscale = yscale; - } -} - -/* ---------------------------------------------------------------------------- - Plot2D_transform(Plot2D *p2, double x, double y, int *px, int *py) - - Transforms x,y into screen coordinates px and py. Result is returned - in px and py. Rounds to the nearest pixel instead of truncating. - ----------------------------------------------------------------------------- */ - -void -Plot2D_transform(Plot2D *p2, double x, double y, int *px, int *py) { - if (p2) { - *px = p2->view_xmin + (int) (p2->dx*(x-p2->xmin) + 0.5); - *py = p2->view_ymin + (int) (p2->dy*(y-p2->ymin) + 0.5); - } -} - -/* ------------------------------------------------------------------------------- - Plot2D_plot(Plot2D *p2, double x, double y, Pixel color) - - Plot a 2D Point of a given color - ------------------------------------------------------------------------------- */ -void -Plot2D_plot(Plot2D *p2, double x, double y, Pixel color) { - int px, py; - - Plot2D_transform(p2,x,y,&px,&py); - FrameBuffer_plot(p2->frame, px, py, color); -} - -/* ------------------------------------------------------------------------------- - Plot2D_box(Plot2D *p2, double x1, double y1, double x2, double y2, Pixel Color) - - Plot an outline box on the 2D plot - ------------------------------------------------------------------------------- */ -void -Plot2D_box(Plot2D *p2, double x1, double y1,double x2, double y2, Pixel color) { - int ix1, ix2,iy1, iy2; - - Plot2D_transform(p2,x1,y1,&ix1,&iy1); - Plot2D_transform(p2,x2,y2,&ix2,&iy2); - FrameBuffer_box(p2->frame,ix1,iy1,ix2,iy2,color); -} - -/* ------------------------------------------------------------------------------- - Plot2D_solidbox(Plot2D *p2, double x1, double y1, double x2, double y2, Pixel Color) - - Plot a solid box box on the 2D plot - ------------------------------------------------------------------------------- */ -void -Plot2D_solidbox(Plot2D *p2, double x1, double y1,double x2, double y2, Pixel color) { - int ix1, ix2,iy1, iy2; - - Plot2D_transform(p2,x1,y1,&ix1,&iy1); - Plot2D_transform(p2,x2,y2,&ix2,&iy2); - FrameBuffer_solidbox(p2->frame,ix1,iy1,ix2,iy2,color); -} - -/* ------------------------------------------------------------------------------- - Plot2D_interpbox(Plot2D *p2, double x1, double y1, double x2, double y2, - Pixel c1, Pixel c2, Pixel c3, Pixel c4) - - Plot a color-interpolated box on the 2D plot - ------------------------------------------------------------------------------- */ -void -Plot2D_interpbox(Plot2D *p2, double x1, double y1,double x2, double y2, - Pixel c1, Pixel c2, Pixel c3, Pixel c4) { - int ix1, ix2,iy1, iy2; - - Plot2D_transform(p2,x1,y1,&ix1,&iy1); - Plot2D_transform(p2,x2,y2,&ix2,&iy2); - FrameBuffer_interpbox(p2->frame,ix1,iy1,ix2,iy2,c1,c2,c3,c4); -} - -/* ------------------------------------------------------------------------------- - Plot2D_circle(Plot2D *p2, double x, double y, double radius, Pixel color) - - Make an outline circle on the 2D plot. - ------------------------------------------------------------------------------- */ -void -Plot2D_circle(Plot2D *p2, double x, double y, double radius, Pixel color) { - int ix, iy, ir; - - Plot2D_transform(p2,x,y,&ix,&iy); - ir = p2->dx * radius; /* This is really incorrect. Will need ellipse */ - if (ir > 1) - FrameBuffer_circle(p2->frame,ix,iy,ir,color); - else - FrameBuffer_plot(p2->frame,ix,iy,color); - -} - -/* ------------------------------------------------------------------------------- - Plot2D_solidcircle(Plot2D *p2, double x, double y, double radius, Pixel color) - - Make an solid circle on the 2D plot. - ------------------------------------------------------------------------------- */ -void -Plot2D_solidcircle(Plot2D *p2, double x, double y, double radius, Pixel color) { - int ix, iy, ir; - - Plot2D_transform(p2,x,y,&ix,&iy); - ir = p2->dx * radius; /* This is really incorrect. Will need ellipse */ - if (ir > 1) - FrameBuffer_solidcircle(p2->frame,ix,iy,ir,color); - else - FrameBuffer_plot(p2->frame,ix,iy,color); -} - -/* ------------------------------------------------------------------------------- - Plot2D_line(Plot2D *p2, double x1, double y1, double x2, double y2, Pixel color) - - Draw a line - ------------------------------------------------------------------------------- */ - -void -Plot2D_line(Plot2D *p2, double x1, double y1, double x2, double y2, Pixel color) { - int ix1, ix2, iy1, iy2; - - Plot2D_transform(p2,x1,y1,&ix1,&iy1); - Plot2D_transform(p2,x2,y2,&ix2,&iy2); - FrameBuffer_line(p2->frame,ix1,iy1,ix2,iy2,color); -} - - - -/* ------------------------------------------------------------------------------- - Plot2D_start(Plot2D *p2) - - This should be called before starting to make a 2D plot. It will change - the viewport coordinates for the framebuffer and do other stuff. - ------------------------------------------------------------------------------- */ - -void Plot2D_start(Plot2D *p2) { - if (p2) { - FrameBuffer_setclip(p2->frame, p2->view_xmin,p2->view_ymin,p2->view_xmax, p2->view_ymax); - p2->dx = (p2->view_xmax - p2->view_xmin)/(p2->xmax - p2->xmin); - p2->dy = (p2->view_ymax - p2->view_ymin)/(p2->ymax - p2->ymin); - } -} - -/* -------------------------------------------------------------------------- - void Plot2D_drawpixmap(Plot2D *p2, PixMap *pm, double x, double y, Pixel color, Pixel bgcolor) - - Draw a pixel map at the given coordinates. (Used for putting symbols on 2D - plots). - -------------------------------------------------------------------------- */ -void -Plot2D_drawpixmap(Plot2D *p2, PixMap *pm, double x, double y, Pixel color, Pixel bgcolor) { - int ix, iy; - - Plot2D_transform(p2,x,y,&ix,&iy); - FrameBuffer_drawpixmap(p2->frame,pm,ix,iy,color,bgcolor); -} - -/* ---------------------------------------------------------------------------- - void Plot2D_xaxis(Plot2D *p2, double x, double y, double xtick, int ticklength, Pixel color) - - Draw an X axis bar at location x,y with ticks spaced every xtick units. - Ticks are spaced starting at "x" - ----------------------------------------------------------------------------- */ - -void Plot2D_xaxis(Plot2D *p2, double x, double y, double xtick, int ticklength, Pixel color) { - int ix, iy,iy2; - double xt; - - /* Draw a line fox the axis */ - - Plot2D_line(p2,p2->xmin,y,p2->xmax,y,color); - xt = x; - while (xt >= p2->xmin) { - Plot2D_transform(p2,xt,y,&ix,&iy); - iy2 = iy+ticklength; - iy = iy-ticklength; - FrameBuffer_line(p2->frame,ix,iy,ix,iy2,color); - xt = xt - xtick; - } - xt = x + xtick; - while (xt < p2->xmax) { - Plot2D_transform(p2,xt,y,&ix,&iy); - iy2 = iy+ticklength; - iy = iy-ticklength; - FrameBuffer_line(p2->frame,ix,iy,ix,iy2,color); - xt = xt + xtick; - } -} - - -/* ---------------------------------------------------------------------------- - void Plot2D_yaxis(Plot2D *p2, double x, double y, double ytick, int ticklength, Pixel c) - - Draw an Y axis bar at location x,y with ticks spaced every xtick units. - Ticks are spaced starting at "y" - ----------------------------------------------------------------------------- */ - -void Plot2D_yaxis(Plot2D *p2, double x, double y, double ytick, int ticklength, Pixel color) { - int ix, iy, ix2; - double yt; - - /* Draw a line fox the axis */ - - Plot2D_line(p2,x,p2->ymin,x,p2->ymax,color); - yt = y; - while (yt >= p2->ymin) { - Plot2D_transform(p2,x,yt,&ix,&iy); - ix2 = ix+ticklength; - ix = ix-ticklength; - FrameBuffer_line(p2->frame,ix,iy,ix2,iy,color); - yt = yt - ytick; - } - yt = y + ytick; - while (yt < p2->ymax) { - Plot2D_transform(p2,x,yt,&ix,&iy); - ix2 = ix+ticklength; - ix = ix-ticklength; - FrameBuffer_line(p2->frame,ix,iy,ix2,iy,color); - yt = yt + ytick; - } -} - - -/* ------------------------------------------------------------------------- - Plot2D_triangle(Plot2D *p2, double x1, double y1, - double x2, double y2, - double x3, double y3, - Pixel fillcolor) - - This function draws a 2D outline triangle. - -------------------------------------------------------------------------- */ - -void Plot2D_triangle(Plot2D *p2, double x1, double y1, - double x2, double y2, - double x3, double y3, Pixel color) { - - Plot2D_line(p2,x1,y1,x2,y2,color); - Plot2D_line(p2,x2,y2,x3,y3,color); - Plot2D_line(p2,x3,y3,x1,y1,color); - -} - - -/* ------------------------------------------------------------------------- - Plot2D_solidtriangle(Plot2D *p2, double x1, double y1, - double x2, double y2, - double x3, double y3, - Pixel color) - - This function draws a 2D filled triangle. Can be used to - draw other primitives such as quadralaterals, etc... - - -------------------------------------------------------------------------- */ - -void Plot2D_solidtriangle(Plot2D *p2, double x1, double y1, - - double x2, double y2, - double x3, double y3, Pixel color) { - - int tx1, tx2, tx3, ty1, ty2, ty3; - - /* Transform the three points into screen coordinates */ - - Plot2D_transform(p2,x1,y1,&tx1,&ty1); - Plot2D_transform(p2,x2,y2,&tx2,&ty2); - Plot2D_transform(p2,x3,y3,&tx3,&ty3); - - FrameBuffer_solidtriangle(p2->frame,tx1,ty1,tx2,ty2,tx3,ty3,color); - -} - -/* ------------------------------------------------------------------------- - Plot2D_interptriangle(Plot2D *p2, double x1, double y1, Pixel c1, - double x2, double y2, Pixel c2, - double x3, double y3, Pixel c3); - - This function draws a 2D filled triangle with color interpolation. - Can be used to draw other primitives such as quadralaterals, etc... - -------------------------------------------------------------------------- */ - -void Plot2D_interptriangle(Plot2D *p2, double x1, double y1, Pixel c1, - double x2, double y2, Pixel c2, - double x3, double y3, Pixel c3) { - - int tx1, tx2, tx3, ty1, ty2, ty3; - - /* Transform the three points into screen coordinates */ - - Plot2D_transform(p2,x1,y1,&tx1,&ty1); - Plot2D_transform(p2,x2,y2,&tx2,&ty2); - Plot2D_transform(p2,x3,y3,&tx3,&ty3); - - FrameBuffer_interptriangle(p2->frame,tx1,ty1,c1,tx2,ty2,c2,tx3,ty3,c3); - -} - - - diff --git a/Examples/GIFPlot/Lib/plot3d.c b/Examples/GIFPlot/Lib/plot3d.c deleted file mode 100644 index 387e420e2..000000000 --- a/Examples/GIFPlot/Lib/plot3d.c +++ /dev/null @@ -1,2181 +0,0 @@ -/* ----------------------------------------------------------------------------- - * plot3d.c - * - * Three-dimensional plotting. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * Copyright (C) 1995-1996 - * - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -#define PLOT3D -#include "gifplot.h" -#include -#include - -#define ORTHO 1 -#define PERSPECTIVE 2 -/* ------------------------------------------------------------------------ - Plot3D *new_Plot3D(FrameBuffer *f, double xmin, double ymin, double zmin, - double xmax, double ymax, double zmax) - - Creates a new 3D plot. Min and max coordinates are primarily used to - pick some default parameters. Returns NULL on failure - ------------------------------------------------------------------------- */ - -Plot3D *new_Plot3D(FrameBuffer *f, double xmin, double ymin, double zmin, - double xmax, double ymax, double zmax) { - - Plot3D *p3; - void Plot3D_maketransform(Plot3D *p3); - - /* Check to make sure the framebuffer and min/max parameters are valid */ - - if (!f) return (Plot3D *) 0; - if ((xmin > xmax) || (ymin > ymax) || (zmin > zmax)) return (Plot3D *) 0; - - p3 = (Plot3D *) malloc(sizeof(Plot3D)); - p3->frame = f; - p3->xmin = xmin; - p3->ymin = ymin; - p3->zmin = zmin; - p3->xmax = xmax; - p3->ymax = ymax; - p3->zmax = zmax; - - /* Set view region to the entire size of the framebuffer */ - - p3->view_xmin = 0; - p3->view_ymin = 0; - p3->view_xmax = f->width; - p3->view_ymax = f->height; - p3->width = f->width; - p3->height = f->height; - - /* Calculate a center point based off the min and max coordinates given */ - - p3->xcenter = (xmax - xmin)/2.0 + xmin; - p3->ycenter = (ymax - ymin)/2.0 + ymin; - p3->zcenter = (zmax - zmin)/2.0 + zmin; - - /* Calculate the aspect ratio of the viewing region */ - - p3->aspect = (double) f->width/(double) f->height; - - /* Set default view parameters */ - p3->xshift = 1.0; - p3->yshift = 1.0; - p3->zoom = 0.5; - p3->fovy = 40.0; /* 40 degree field of view */ - - /* Create matrices */ - - p3->model_mat = new_Matrix(); - p3->view_mat = new_Matrix(); - p3->center_mat = new_Matrix(); - p3->fullmodel_mat = new_Matrix(); - p3->trans_mat = new_Matrix(); - p3->pers_mode = ORTHO; - - FrameBuffer_zresize(p3->frame,p3->width, p3->height); - Matrix_identity(p3->view_mat); - Matrix_identity(p3->model_mat); - Matrix_translate(p3->center_mat, -p3->xcenter,-p3->ycenter,-p3->zcenter); - Plot3D_maketransform(p3); - return p3; -} - -/* --------------------------------------------------------------------- - delete_Plot3D(Plot3D *p3) - - Deletes a 3D plot - --------------------------------------------------------------------- */ - -void delete_Plot3D(Plot3D *p3) { - if (p3) { - delete_Matrix(p3->view_mat); - delete_Matrix(p3->model_mat); - delete_Matrix(p3->trans_mat); - free((char *) p3); - } -} - -/* --------------------------------------------------------------------- - Plot3D *Plot3D_copy(Plot3D *p3) - - This makes a copy of the 3D plot structure and returns a pointer to it. - --------------------------------------------------------------------- */ - -Plot3D *Plot3D_copy(Plot3D *p3) { - Plot3D *c3; - if (p3) { - c3 = (Plot3D *) malloc(sizeof(Plot3D)); - if (c3) { - c3->frame = p3->frame; - c3->view_xmin = p3->view_xmin; - c3->view_ymin = p3->view_ymin; - c3->view_xmax = p3->view_xmax; - c3->view_ymax = p3->view_ymax; - c3->xmin = p3->xmin; - c3->ymin = p3->ymin; - c3->zmin = p3->zmin; - c3->xmax = p3->xmax; - c3->ymax = p3->ymax; - c3->zmax = p3->zmax; - c3->xcenter = p3->xcenter; - c3->ycenter = p3->ycenter; - c3->zcenter = p3->zcenter; - c3->fovy = p3->fovy; - c3->aspect = p3->aspect; - c3->znear = p3->znear; - c3->zfar = p3->zfar; - c3->center_mat = Matrix_copy(p3->center_mat); - c3->model_mat = Matrix_copy(p3->model_mat); - c3->view_mat = Matrix_copy(p3->view_mat); - c3->fullmodel_mat = Matrix_copy(p3->fullmodel_mat); - c3->trans_mat = Matrix_copy(p3->trans_mat); - c3->lookatz = p3->lookatz; - c3->xshift = p3->xshift; - c3->yshift = p3->yshift; - c3->zoom = p3->zoom; - c3->width = p3->width; - c3->height = p3->height; - c3->pers_mode = p3->pers_mode; - } - return c3; - } else { - return (Plot3D *) 0; - } -} - -/* ---------------------------------------------------------------------- - Plot3D_clear(Plot3D *p3, Pixel bgcolor) - - Clear the pixel and zbuffer only for the view region of this image. - ---------------------------------------------------------------------- */ -void -Plot3D_clear(Plot3D *p3, Pixel bgcolor) { - int i,j; - - for (i = p3->view_xmin; i < p3->view_xmax; i++) - for (j = p3->view_ymin; j < p3->view_ymax; j++) { - p3->frame->pixels[j][i] = bgcolor; - p3->frame->zbuffer[j][i] = ZMIN; - } -} - -/* --------------------------------------------------------------------- - Plot3D_maketransform(Plot3D *p3) - - This function builds the total 3D transformation matrix from a - collection of components. - - Trans = View * Rotation * Center - - Where View is the viewing transformation matrix, Rotation is the - model rotation matrix, Center is the translation matrix used to - center the Model at the origin. - --------------------------------------------------------------------- */ - -void -Plot3D_maketransform(Plot3D *p3) { - - Matrix_multiply(p3->model_mat,p3->center_mat, p3->fullmodel_mat); - Matrix_multiply(p3->view_mat,p3->fullmodel_mat, p3->trans_mat); -} - -/* --------------------------------------------------------------------- - Plot3D_perspective(Plot3D *p3, double fovy, double znear, double zfar) - - Sets up the perspective viewing transformation. Assumes "lookat" - has already been called. - --------------------------------------------------------------------- */ - -void -Plot3D_perspective(Plot3D *p3, double fovy, double znear, double zfar) { - double theta; - double mat[16]; - - p3->fovy = fovy; - p3->znear = znear; - p3->zfar = zfar; - - theta = 3.1415926*fovy/180.0; - - Matrix_identity(mat); - mat[0] = cos(theta/2.0)/(sin(theta/2.0)*p3->aspect); - mat[5] = cos(theta/2.0)/(sin(theta/2.0)); - mat[10] = -(zfar + znear)/(zfar-znear); - mat[14] = -1.0; - mat[11] = -(2*zfar*znear)/(zfar - znear); - mat[15] = 0.0; - - /* Update the view transformation matrix */ - - Matrix_multiply(mat,p3->view_mat,p3->view_mat); - - /* Update the global transformation matrix */ - - Plot3D_maketransform(p3); - p3->pers_mode = PERSPECTIVE; - -} - -/* --------------------------------------------------------------------- - Plot3D_lookat(Plot3D *p3, double z) - - A greatly simplified version of (lookat). Specifies the position - of the viewpoint. (can be used for moving image in or out). - - Destroys the current viewing transformation matrix, so it will have - to be recalculated. - --------------------------------------------------------------------- */ - -void -Plot3D_lookat(Plot3D *p3, double z) { - if (p3) { - Matrix_translate(p3->view_mat, 0,0,-z); - p3->lookatz = z; - Plot3D_maketransform(p3); - } -} - -/* ------------------------------------------------------------------------- - Plot3D_autoperspective(Plot3D *p3, double fovy) - - Automatically figures out a semi-decent viewpoint given the - min,max parameters currently set for this image - ------------------------------------------------------------------------- */ - -void -Plot3D_autoperspective(Plot3D *p3, double fovy) { - - /* Make a perspective transformation matrix for this system */ - - double zfar; - double znear; - double d, dmax; - double cx,cy,cz; - double xmin,xmax,ymin,ymax,zmin,zmax; - - xmin = p3->xmin; - ymin = p3->ymin; - zmin = p3->zmin; - xmax = p3->xmax; - ymax = p3->ymax; - zmax = p3->zmax; - cx = p3->xcenter; - cy = p3->ycenter; - cz = p3->zcenter; - - /* Calculate longest point from center point */ - - dmax = (xmin-cx)*(xmin-cx) + (ymin-cy)*(ymin-cy) + (zmin-cz)*(zmin-cz); - d = (xmax-cx)*(xmax-cx) + (ymin-cy)*(ymin-cy) + (zmin-cz)*(zmin-cz); - if (d > dmax) dmax = d; - d = (xmin-cx)*(xmin-cx) + (ymax-cy)*(ymax-cy) + (zmin-cz)*(zmin-cz); - if (d > dmax) dmax = d; - d = (xmax-cx)*(xmax-cx) + (ymax-cy)*(ymax-cy) + (zmin-cz)*(zmin-cz); - if (d > dmax) dmax = d; - d = (xmin-cx)*(xmin-cx) + (ymin-cy)*(ymin-cy) + (zmax-cz)*(zmax-cz); - if (d > dmax) dmax = d; - d = (xmax-cx)*(xmax-cx) + (ymin-cy)*(ymin-cy) + (zmax-cz)*(zmax-cz); - if (d > dmax) dmax = d; - d = (xmin-cx)*(xmin-cx) + (ymax-cy)*(ymax-cy) + (zmax-cz)*(zmax-cz); - if (d > dmax) dmax = d; - d = (xmax-cx)*(xmax-cx) + (ymax-cy)*(ymax-cy) + (zmax-cz)*(zmax-cz); - if (d > dmax) dmax = d; - - dmax = sqrt(dmax); - d = p3->lookatz; - - znear = d - dmax; - zfar = znear+1.5*dmax; - Plot3D_perspective(p3, fovy,znear,zfar); - -} - - -/* --------------------------------------------------------------------- - Plot3D_ortho(Plot3D *p3, double left, double right, double bottom, double top) - - Sets up an orthographic viewing transformation. - --------------------------------------------------------------------- */ - -void -Plot3D_ortho(Plot3D *p3, double left, double right, double bottom, double top) { - - - Matrix_identity(p3->view_mat); - p3->view_mat[0] = (2.0/(right - left))/p3->aspect; - p3->view_mat[5] = 2.0/(top - bottom); - p3->view_mat[10] = -1; - p3->view_mat[15] = 1.0; - p3->view_mat[3] = -(right+left)/(right-left); - p3->view_mat[7] = -(top+bottom)/(top-bottom); - - /* Update the global transformation matrix */ - - Plot3D_maketransform(p3); - p3->pers_mode = ORTHO; - p3->ortho_left = left; - p3->ortho_right = right; - p3->ortho_bottom = bottom; - p3->ortho_top = top; - -} - -/* --------------------------------------------------------------------- - Plot3D_autoortho(Plot3D *p3) - - Automatically pick an orthographic projection that's probably - pretty good. - --------------------------------------------------------------------- */ - -void -Plot3D_autoortho(Plot3D *p3) { - - /* Make a perspective transformation matrix for this system */ - - double d, dmax; - double cx,cy,cz; - double xmin,xmax,ymin,ymax,zmin,zmax; - - xmin = p3->xmin; - ymin = p3->ymin; - zmin = p3->zmin; - xmax = p3->xmax; - ymax = p3->ymax; - zmax = p3->zmax; - cx = p3->xcenter; - cy = p3->ycenter; - cz = p3->zcenter; - - /* Calculate longest point from center point */ - - dmax = (xmin-cx)*(xmin-cx) + (ymin-cy)*(ymin-cy) + (zmin-cz)*(zmin-cz); - d = (xmax-cx)*(xmax-cx) + (ymin-cy)*(ymin-cy) + (zmin-cz)*(zmin-cz); - if (d > dmax) dmax = d; - d = (xmin-cx)*(xmin-cx) + (ymax-cy)*(ymax-cy) + (zmin-cz)*(zmin-cz); - if (d > dmax) dmax = d; - d = (xmax-cx)*(xmax-cx) + (ymax-cy)*(ymax-cy) + (zmin-cz)*(zmin-cz); - if (d > dmax) dmax = d; - d = (xmin-cx)*(xmin-cx) + (ymin-cy)*(ymin-cy) + (zmax-cz)*(zmax-cz); - if (d > dmax) dmax = d; - d = (xmax-cx)*(xmax-cx) + (ymin-cy)*(ymin-cy) + (zmax-cz)*(zmax-cz); - if (d > dmax) dmax = d; - d = (xmin-cx)*(xmin-cx) + (ymax-cy)*(ymax-cy) + (zmax-cz)*(zmax-cz); - if (d > dmax) dmax = d; - d = (xmax-cx)*(xmax-cx) + (ymax-cy)*(ymax-cy) + (zmax-cz)*(zmax-cz); - if (d > dmax) dmax = d; - - dmax = sqrt(dmax); - - Plot3D_ortho(p3,-dmax,dmax,-dmax,dmax); - -} - - - -/* ------------------------------------------------------------------------- - Plot3D_setview(Plot3D *p3, int vxmin, int vymin, int vxmax, int vymax) - - Sets the viewport for this 3D graph. Will recalculate all of the - local viewing transformation matrices accordingly. - ------------------------------------------------------------------------- */ -void -Plot3D_setview(Plot3D *p3, int vxmin, int vymin, int vxmax, int vymax) { - if (p3) { - if ((vxmin > vxmax) || (vymin >vymax)) return; - p3->view_xmin = vxmin; - p3->view_ymin = vymin; - p3->view_xmax = vxmax; - p3->view_ymax = vymax; - p3->width = (vxmax - vxmin); - p3->height = (vymax - vymin); - p3->aspect = (double) p3->width/(double) p3->height; - - /* Fix up the viewing transformation matrix */ - - if (p3->pers_mode == PERSPECTIVE) { - Plot3D_lookat(p3,p3->lookatz); - Plot3D_perspective(p3,p3->fovy,p3->znear,p3->zfar); - } else { - Plot3D_ortho(p3,p3->ortho_left,p3->ortho_right,p3->ortho_bottom, p3->ortho_top); - } - FrameBuffer_setclip(p3->frame,vxmin,vymin,vxmax,vymax); - } -} - -/* --------------------------------------------------------------------------- - Plot2D_start(Plot2D *p3) - - Set up viewing region and other parameters for this image. - --------------------------------------------------------------------------- */ - -void -Plot3D_start(Plot3D *p3) { - if (p3) - FrameBuffer_setclip(p3->frame, p3->view_xmin,p3->view_ymin,p3->view_xmax, p3->view_ymax); - -} - -/* ------------------------------------------------------------------------- - Plot3D_plot(Plot3D *p3, double x, double y, double z, Pixel Color) - - Plot a 3D point - ------------------------------------------------------------------------- */ - -void -Plot3D_plot(Plot3D *p3, double x, double y, double z, Pixel color) { - - GL_Vector t; - int ix, iy; - double invw; - FrameBuffer *f; - - /* Perform a transformation */ - - Matrix_transform4(p3->trans_mat,x,y,z,1,&t); - - /* Scale the coordinates into unit cube */ - - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; -#ifdef GL_DEBUG - fprintf(stdout,"t.x = %g, t.y = %g, t.z = %g\n", t.x,t.y,t.z); -#endif - /* Calculate the x and y coordinates */ - - ix = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5); - iy = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5); - - if ((ix >= 0) && (ix < p3->width) && - (iy >= 0) && (ix < p3->height)) { - ix += p3->view_xmin; - iy += p3->view_ymin; - f = p3->frame; - if (t.z <= f->zbuffer[iy][ix]) { - f->pixels[iy][ix] = color; - f->zbuffer[iy][ix] = t.z; - } - } -} - -/* ---------------------------------------------------------------------- - Plot3D_rotx(Plot3D *p3, double deg) - - Rotate the model around its x axis. - ---------------------------------------------------------------------- */ - -void -Plot3D_rotx(Plot3D *p3, double deg) { - double temp[16]; - - Matrix_rotatex(temp,deg); /* Construct a x rotation matrix */ - Matrix_multiply(p3->model_mat,temp,p3->model_mat); - Plot3D_maketransform(p3); - -} - -/* ---------------------------------------------------------------------- - Plot3D_roty(Plot3D *p3, double deg) - - Rotate the model around its y axis. - ---------------------------------------------------------------------- */ - -void -Plot3D_roty(Plot3D *p3, double deg) { - double temp[16]; - - Matrix_rotatey(temp,deg); /* Construct a y rotation matrix */ - Matrix_multiply(p3->model_mat,temp,p3->model_mat); - Plot3D_maketransform(p3); - -} - -/* ---------------------------------------------------------------------- - Plot3D_rotz(Plot3D *p3, double deg) - - Rotate the model around its z axis. - ---------------------------------------------------------------------- */ - -void -Plot3D_rotz(Plot3D *p3, double deg) { - double temp[16]; - - Matrix_rotatez(temp,deg); /* Construct a z rotation matrix */ - Matrix_multiply(p3->model_mat,temp,p3->model_mat); - Plot3D_maketransform(p3); - -} - - -/* ---------------------------------------------------------------------- - Plot3D_rotd(Plot3D *p3, double deg) - - Rotate the model down - ---------------------------------------------------------------------- */ - -void -Plot3D_rotd(Plot3D *p3, double deg) { - double temp[16]; - - Matrix_rotatex(temp,deg); /* Construct a x rotation matrix */ - Matrix_multiply(temp, p3->model_mat,p3->model_mat); - Plot3D_maketransform(p3); - -} - - -/* ---------------------------------------------------------------------- - Plot3D_rotu(Plot3D *p3, double deg) - - Rotate the model up - ---------------------------------------------------------------------- */ - -void -Plot3D_rotu(Plot3D *p3, double deg) { - double temp[16]; - - Matrix_rotatex(temp,-deg); /* Construct a x rotation matrix */ - Matrix_multiply(temp,p3->model_mat,p3->model_mat); - Plot3D_maketransform(p3); - -} - - -/* ---------------------------------------------------------------------- - Plot3D_rotr(Plot3D *p3, double deg) - - Rotate the model down - ---------------------------------------------------------------------- */ - -void -Plot3D_rotr(Plot3D *p3, double deg) { - double temp[16]; - - Matrix_rotatey(temp,deg); /* Construct a y rotation matrix */ - Matrix_multiply(temp, p3->model_mat,p3->model_mat); - Plot3D_maketransform(p3); - -} - - -/* ---------------------------------------------------------------------- - Plot3D_rotl(Plot3D *p3, double deg) - - Rotate the model left - ---------------------------------------------------------------------- */ - -void -Plot3D_rotl(Plot3D *p3, double deg) { - double temp[16]; - - Matrix_rotatey(temp,-deg); /* Construct a y rotation matrix */ - Matrix_multiply(temp,p3->model_mat,p3->model_mat); - Plot3D_maketransform(p3); - -} - - -/* ---------------------------------------------------------------------- - Plot3D_rotc(Plot3D *p3, double deg) - - Rotate the model around center point - ---------------------------------------------------------------------- */ - -void -Plot3D_rotc(Plot3D *p3, double deg) { - double temp[16]; - - Matrix_rotatez(temp,-deg); /* Construct a z rotation matrix */ - Matrix_multiply(temp,p3->model_mat,p3->model_mat); - Plot3D_maketransform(p3); -} - -/* ------------------------------------------------------------------------- - Plot3D_zoom(Plot3D *p3, double percent) - - Zooms in or out the current image. percent defines a percentage of - zoom. - - Zooming is actually done by adjusting the perspective field of view - instead of scaling the model or moving in the viewpoint. This - seems to work the best. - ------------------------------------------------------------------------- */ - -void -Plot3D_zoom(Plot3D *p3, double percent) { - - double scale; - double dx; - if (percent <= 0) return; - scale = percent/100.0; - - dx = (1.0/scale - 1.0)/(2*p3->zoom); /* Don't even ask where this came from */ - p3->xshift += dx; - p3->yshift += dx; - p3->zoom = p3->zoom*scale; - -#ifdef OLD - p3->fovy = p3->fovy*scale; - if (p3->fovy > 170.0) p3->fovy = 170.0; - if (p3->fovy == 0) p3->fovy = 0.0001; - Plot3D_lookat(p3,p3->lookatz); - Plot3D_perspective(p3,p3->fovy,p3->znear,p3->zfar); -#endif -} - -/* -------------------------------------------------------------------------- - Plot3D_left(Plot3D *p3, double s) - - Shifts the image to the left by s units. This is a little funky. - - s is scaled so that s = 100 equals one full screen. - -------------------------------------------------------------------------- */ -void -Plot3D_left(Plot3D *p3, double s) { - p3->xshift -= (s/100.0)/p3->zoom; -} - -/* -------------------------------------------------------------------------- - Plot3D_right(Plot3D *p3, double s) - - Shifts the image to the right by s units. - - s is scaled so that s = 100 equals one full screen. - -------------------------------------------------------------------------- */ -void -Plot3D_right(Plot3D *p3, double s) { - p3->xshift += (s/100.0)/p3->zoom; -} - -/* -------------------------------------------------------------------------- - Plot3D_up(Plot3D *p3, double s) - - Shifts the image up left by s units. - - s is scaled so that s = 100 equals one full screen. - -------------------------------------------------------------------------- */ -void -Plot3D_up(Plot3D *p3, double s) { - p3->yshift += (s/100.0)/p3->zoom; -} - -/* -------------------------------------------------------------------------- - Plot3D_down(Plot3D *p3, double s) - - Shifts the image down by s units. - - s is scaled so that s = 100 equals one full screen. - -------------------------------------------------------------------------- */ -void -Plot3D_down(Plot3D *p3, double s) { - p3->yshift -= (s/100.0)/p3->zoom; -} - -/* ------------------------------------------------------------------------- - Plot3D_center(Plot3D *p3, double cx, double cy) - - Centers the image on a point in the range (0,0) - (100,100) - ------------------------------------------------------------------------- */ -void -Plot3D_center(Plot3D *p3, double cx, double cy) { - Plot3D_left(p3,cx-50); - Plot3D_down(p3,cy-50); -} - - - -/*************************************************************************** - * 3d Primitives * - ***************************************************************************/ - -/* ------------------------------------------------------------------------- - Plot3D_horizontal(Plot3D *p3, int xmin, int xmax, int y, double z1, double z2, Pixel color) - - Draws a "Horizontal" line on the framebuffer between two screen coordinates, - but also supplies z-values and zbuffering. This function probably isn't - too useful by itself, but will be used by a number of other primitives. - -------------------------------------------------------------------------- */ - -void Plot3D_horizontal(Plot3D *p3, int xmin, int xmax, int y, Zvalue z1, Zvalue z2, Pixel color) { - Pixel *p; - FrameBuffer *f; - int i; - Zvalue *zbuf,z,mz; - int startx, endx; - - f = p3->frame; - if ((y < f->ymin) || (y >= f->ymax)) return; - if (xmin > f->xmax) return; - if (xmin < f->xmin) startx = f->xmin; - else startx = xmin; - if (xmax < f->xmin) return; - if (xmax >= f->xmax) endx = f->xmax - 1; - else endx = xmax; - - /* Calculate z slope */ - - if (xmax != xmin) { - mz = (Zvalue) ((double) (z2 - z1)/(double) (xmax - xmin)); - } else { - mz = 0; - } - - /* Draw it */ - - p = &f->pixels[y][startx]; - zbuf = &f->zbuffer[y][startx]; - z = (Zvalue) (mz*(startx-xmin) + z1); - for (i = startx; i <= endx; i++, p++, zbuf++,z+=mz) { - if (z <= *zbuf) { - *p = color; - *zbuf = z; - } - } -} - - -/* ------------------------------------------------------------------------- - Plot3D_vertical(Plot3D *p3, int ymin, int ymax, int x, double z1, double z2, Pixel color) - - Draws a "Vertical" line on the framebuffer between two screen coordinates, - but also supplies z-values and zbuffering. This function probably isn't - too useful by itself, but will be used by a number of other primitives. - -------------------------------------------------------------------------- */ - -void Plot3D_vertical(Plot3D *p3, int ymin, int ymax, int x, Zvalue z1, Zvalue z2, Pixel color) { - Pixel *p; - FrameBuffer *f; - int i; - Zvalue *zbuf,z,mz; - int starty, endy; - - f = p3->frame; - if ((x < f->xmin) || (x >= f->xmax)) return; - if (ymin >= f->ymax) return; - if (ymin < f->ymin) starty = f->ymin; - else starty = ymin; - if (ymax < f->ymin) return; - if (ymax >= f->ymax) endy = f->ymax - 1; - else endy = ymax; - - /* Calculate z slope */ - - mz = (double) (z2 - z1)/(double) (ymax - ymin); - - /* Draw it */ - - p = &f->pixels[starty][x]; - zbuf = &f->zbuffer[starty][x]; - for (i = starty; i <= endy; i++, p+=f->width, zbuf+=f->width) { - z = (Zvalue) (mz*(i-ymin) + z1); - if (z <= *zbuf) { - *p = color; - *zbuf = z; - } - } -} - -/* ------------------------------------------------------------------------------- - Plot3D_linetransform(Plot3D *p3, int x1, int y1, Zvalue z1, - int x2, int y2, Zvalue z2, Pixel c) - - Draw a 3D line between points that have already been transformed into - 3D space. - - Uses a Bresenham line algorithm, but with linear interpolation between - Zvalues. - ------------------------------------------------------------------------------- */ - -void -Plot3D_linetransform(Plot3D *p3, int x1, int y1, Zvalue z1, int x2, int y2, Zvalue z2, Pixel c) { - - int orig_x1, orig_y1, orig_x2,orig_y2; - Zvalue zt; - - /* Bresenham line drawing parameters */ - FrameBuffer *f; - int dx,dy,dxneg,dyneg, inc1,inc2,di; - int x, y, xpixels, ypixels, xt, yt; - Pixel *p; - double m; - int end1 = 0, end2 = 0; - Zvalue *zbuf,mz,z; - - f = p3->frame; - - /* Need to figure out where in the heck this line is */ - - dx = x2 - x1; - dy = y2 - y1; - - if ((dx == 0) && (dy == 0)) { - if ((x1 < f->xmin) || (x1 >= f->xmax) || - (y1 < f->ymin) || (y1 >= f->ymax)) return; - if (z1 <= f->zbuffer[y1][x1]) { - f->pixels[y1][x1] = c; - } - return; - } - if (dx == 0) { - /* Draw a Vertical Line */ - if (y1 < y2) - Plot3D_vertical(p3,y1,y2,x1,z1,z2,c); - else - Plot3D_vertical(p3,y2,y1,x1,z2,z1,c); - return; - } - if (dy == 0) { - /* Draw a Horizontal Line */ - if (x1 < x2) - Plot3D_horizontal(p3,x1,x2,y1,z1,z2,c); - else - Plot3D_horizontal(p3,x2,x1,y1,z2,z1,c); - return; - } - - /* Figure out where in the heck these lines are using the - Cohen-Sutherland Line Clipping Scheme. */ - - end1 = ((x1 - f->xmin) < 0) | - (((f->xmax- 1 - x1) < 0) << 1) | - (((y1 - f->ymin) < 0) << 2) | - (((f->ymax-1 - y1) < 0) << 3); - - end2 = ((x2 - f->xmin) < 0) | - (((f->xmax-1 - x2) < 0) << 1) | - (((y2 - f->ymin) < 0) << 2) | - (((f->ymax-1 - y2) < 0) << 3); - - if (end1 & end2) return; /* Nope : Not visible */ - - /* Make sure points have a favorable orientation */ - - if (x1 > x2) { - xt = x1; - x1 = x2; - x2 = xt; - yt = y1; - y1 = y2; - y2 = yt; - zt = z1; - z1 = z2; - z2 = zt; - } - - /* Save original points before we clip them off */ - orig_x1 = x1; - orig_y1 = y1; - orig_x2 = x2; - orig_y2 = y2; - - /* Clip against the boundaries */ - m = (y2 - y1)/(double) (x2-x1); - if (x1 < f->xmin) { - y1 = (f->xmin - x1)*m + y1; - x1 = f->xmin; - } - if (x2 >= f->xmax) { - y2 = (f->xmax -1 -x1)*m + y1; - x2 = f->xmax - 1; - } - - if (y1 > y2) { - xt = x1; - x1 = x2; - x2 = xt; - yt = y1; - y1 = y2; - y2 = yt; - zt = z1; - z1 = z2; - z2 = zt; - - /* Swap original points */ - - xt = orig_x1; - orig_x1 = orig_x2; - orig_x2 = xt; - yt = orig_y1; - orig_y1 = orig_y2; - orig_y2 = yt; - } - - m = 1/m; - if (y1 < f->ymin) { - x1 = (f->ymin - y1)*m + x1; - y1 = f->ymin; - } - if (y2 >= f->ymax) { - x2 = (f->ymax-1-y1)*m + x1; - y2 = f->ymax-1; - } - - if ((x1 < f->xmin) || (x1 >= f->xmax) || (y1 < f->ymin) || (y1 >= f->ymax) || - (x2 < f->xmin) || (x2 >= f->xmax) || (y2 < f->ymin) || (y2 >= f->ymax)) return; - - dx = x2 - x1; - dy = y2 - y1; - xpixels = f->width; - ypixels = f->height; - - dxneg = (dx < 0) ? 1 : 0; - dyneg = (dy < 0) ? 1 : 0; - - dx = abs(dx); - dy = abs(dy); - if (dx >= dy) { - /* Slope between -1 and 1. */ - mz = (z2 - z1)/(orig_x2 - orig_x1); /* Z interpolation slope */ - if (dxneg) { - x = x1; - y = y1; - x1 = x2; - y1 = y2; - x2 = x; - y2 = y; - dyneg = !dyneg; - } - inc1 = 2*dy; - inc2 = 2*(dy-dx); - di = 2*dy-dx; - - /* Draw a line using x as independent variable */ - - p = &f->pixels[y1][x1]; - zbuf = &f->zbuffer[y1][x1]; - x = x1; - while (x <= x2) { - /* Do a z-buffer check */ - z = mz*(x-orig_x1)+z1; - if (z <= *zbuf){ - *p = c; - *zbuf = z; - } - p++; - zbuf++; - if (di < 0) { - di = di + inc1; - } else { - if (dyneg) { - p = p - xpixels; - zbuf = zbuf - xpixels; - di = di + inc2; - } else { - p = p + xpixels; - zbuf = zbuf + xpixels; - di = di + inc2; - } - } - x++; - } - } else { - /* Slope < -1 or > 1 */ - mz = (z2 - z1)/(double) (orig_y2 - orig_y1); - if (dyneg) { - x = x1; - y = y1; - x1 = x2; - y1 = y2; - x2 = x; - y2 = y; - dxneg = !dxneg; - } - inc1 = 2*dx; - inc2 = 2*(dx-dy); - di = 2*dx-dy; - - /* Draw a line using y as independent variable */ - - p = &f->pixels[y1][x1]; - zbuf = &f->zbuffer[y1][x1]; - y = y1; - while (y <= y2) { - /* Do a z-buffer check */ - z = mz*(y-orig_y1)+z1; - if (z <= *zbuf) { - *p = c; - *zbuf = z; - } - p = p + xpixels; - zbuf = zbuf + xpixels; - if (di < 0) { - di = di + inc1; - } else { - if (dxneg) { - p = p - 1; - zbuf = zbuf - 1; - di = di + inc2; - } else { - p = p + 1; - zbuf = zbuf + 1; - di = di + inc2; - } - } - y++; - } - } -} - -/* --------------------------------------------------------------------------- - Plot3D_line(Plot3D *p3, double x1, double y1, double z1, double x2, double y2, double z2,int color) - - Draws a line in 3D space. This is done as follows (for lack of a better - method). - - 1. The points (x1,y1,z1) and (x2,y2,z2) are transformed into screen coordinates - 2. We draw the line using a modified Bresenham line algorithm. - 3. Zbuffer values are linearly interpolated between the two points. - ---------------------------------------------------------------------------- */ - -void -Plot3D_line(Plot3D *p3, double fx1, double fy1, double fz1, double fx2, double fy2, - double fz2, Pixel c) { - - /* 3D Transformation parameters */ - GL_Vector t; - double invw; - int x1,y1,x2,y2; - Zvalue z1,z2; - - /* Transform the two points into screen coordinates */ - - Matrix_transform4(p3->trans_mat,fx1,fy1,fz1,1,&t); /* Point 1 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - x1 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - y1 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - z1 = t.z; - - Matrix_transform4(p3->trans_mat,fx2,fy2,fz2,1,&t); /* Point 2 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - x2 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - y2 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - z2 = t.z; - Plot3D_linetransform(p3,x1,y1,z1,x2,y2,z2,c); -} - - -/* ------------------------------------------------------------------------- - Plot3D_triangle(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, - Pixel fillcolor) - - This function draws a 3D z-buffered outline triangle. - -------------------------------------------------------------------------- */ - -void Plot3D_triangle(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, Pixel color) { - - int tx1, tx2, tx3, ty1, ty2, ty3; - Zvalue tz1, tz2, tz3; - GL_Vector t; - double invw; - - /* Transform the three points into screen coordinates */ - - Matrix_transform4(p3->trans_mat,x1,y1,z1,1,&t); /* Point 1 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx1 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty1 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz1 = (Zvalue) t.z; - - Matrix_transform4(p3->trans_mat,x2,y2,z2,1,&t); /* Point 2 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx2 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty2 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz2 = (Zvalue) t.z; - - Matrix_transform4(p3->trans_mat,x3,y3,z3,1,&t); /* Point 3 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx3 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty3 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz3 = (Zvalue) t.z; - - - Plot3D_linetransform(p3,tx1,ty1,tz1,tx2,ty2,tz2,color); - Plot3D_linetransform(p3,tx1,ty1,tz1,tx3,ty3,tz3,color); - Plot3D_linetransform(p3,tx2,ty2,tz2,tx3,ty3,tz3,color); -} - - -/* ------------------------------------------------------------------------- - Plot3D_solidtriangletransform(Plot3D *p3, int tx1, int ty2, Zvalue tz1, - int tx2, int ty2, Zvalue tz2, - int tx3, int ty3, Zvalue tz3, Pixel color) - - This function draws a 3D z-buffered filled triangle. Assumes three - points have already been transformed into screen coordinates. - - General idea : - 1. Transform the three points into screen coordinates - 2. Order three points vertically on screen. - 3. Check for degenerate cases (where 3 points are colinear). - 4. Fill in the resulting triangle using horizontal lines. - -------------------------------------------------------------------------- */ - -void Plot3D_solidtriangletransform(Plot3D *p3, int tx1, int ty1, Zvalue tz1, - int tx2, int ty2, Zvalue tz2, - int tx3, int ty3, Zvalue tz3, Pixel color) { - int tempx, tempy; - Zvalue tempz; - double m1,m2,m3, mz1, mz2, mz3; - int y; - int ix1, ix2; - Zvalue zz1, zz2; - FrameBuffer *f; - register double fy1,fy2; - register Zvalue fz1,fz2; - - f = p3->frame; - - /* Check for degenerate cases here */ - - if ((ty1 == ty2) && (ty2 == ty3)) { - if (tx2 < tx1) { /* Swap points 1 and 2 if 2 is higher */ - tempx = tx1; - tempz = tz1; - tx1 = tx2; - tz1 = tz2; - tx2 = tempx; - tz2 = tempz; - } - if (tx3 < tx1) { /* Swap points 1 and 3 if 3 is higher */ - tempx = tx1; - tempz = tz1; - tx1 = tx3; - tz1 = tz3; - tx3 = tempx; - tz3 = tempz; - } - if (tx3 < tx2) { /* Swap points 2 and 3 if 3 is higher */ - tempx = tx2; - tempz = tz2; - tx2 = tx3; - tz2 = tz3; - tx3 = tempx; - tz3 = tempz; - } - - /* Points are aligned horizontally. Handle as a special case */ - /* Just draw three lines using the outline color */ - - Plot3D_horizontal(p3,tx1,tx2,ty1,tz1,tz3,color); - - /* Plot3D_linetransform(p3,tx1,ty1,tz1,tx2,ty2,tz2,color); - Plot3D_linetransform(p3,tx1,ty1,tz1,tx3,ty3,tz3,color); - Plot3D_linetransform(p3,tx2,ty2,tz2,tx3,ty3,tz3,color); - */ - - return; - } - - /* Figure out which point has the greatest "y" value */ - - if (ty2 > ty1) { /* Swap points 1 and 2 if 2 is higher */ - tempx = tx1; - tempy = ty1; - tempz = tz1; - tx1 = tx2; - ty1 = ty2; - tz1 = tz2; - tx2 = tempx; - ty2 = tempy; - tz2 = tempz; - } - if (ty3 > ty1) { /* Swap points 1 and 3 if 3 is higher */ - tempx = tx1; - tempy = ty1; - tempz = tz1; - tx1 = tx3; - ty1 = ty3; - tz1 = tz3; - tx3 = tempx; - ty3 = tempy; - tz3 = tempz; - } - if (ty3 > ty2) { /* Swap points 2 and 3 if 3 is higher */ - tempx = tx2; - tempy = ty2; - tempz = tz2; - tx2 = tx3; - ty2 = ty3; - tz2 = tz3; - tx3 = tempx; - ty3 = tempy; - tz3 = tempz; - } - - /* Points are now order so that t_1 is the highest point, t_2 is the - middle point, and t_3 is the lowest point */ - - if (ty2 < ty1) { - /* First process line segments between (x1,y1)-(x2,y2) - And between (x1,y1),(x3,y3) */ - - m1 = (double) (tx2 - tx1)/(double) (ty2 - ty1); - m2 = (double) (tx3 - tx1)/(double) (ty3 - ty1); - mz1 = (tz2 - tz1)/(double) (ty2 - ty1); - mz2 = (tz3 - tz1)/(double) (ty3 - ty1); - - y = ty1; - fy1 = m1*(y-ty1)+0.5 + tx1; - fy2 = m2*(y-ty1)+0.5 + tx1; - fz1 = mz1*(y-ty1) + tz1; - fz2 = mz2*(y-ty1) + tz1; - while (y >= ty2) { - /* Replace with bresenham scheme */ - /* Calculate x values from slope */ - ix1 = (int) fy1; - ix2 = (int) fy2; - zz1 = fz1; - zz2 = fz2; - fy1-= m1; - fy2-= m2; - fz1-= mz1; - fz2-= mz2; - if (ix1 > ix2) - Plot3D_horizontal(p3,ix2,ix1,y,zz2,zz1,color); - else - Plot3D_horizontal(p3,ix1,ix2,y,zz1,zz2,color); - y--; - } - } - if (ty3 < ty2) { - /* Draw lower half of the triangle */ - m2 = (double) (tx3 - tx1)/(double) (ty3 - ty1); - m3 = (double) (tx3 - tx2)/(double)(ty3 - ty2); - mz2 = (tz3 - tz1)/(double) (ty3 - ty1); - mz3 = (tz3 - tz2)/(double) (ty3 - ty2); - y = ty2; - while (y >= ty3) { - ix1 = (int) (m3*(y-ty2)+0.5)+tx2; - ix2 = (int) (m2*(y-ty1)+0.5)+tx1; - zz1 = mz3*(y-ty2)+tz2; - zz2 = mz2*(y-ty1)+tz1; - if (ix1 > ix2) - Plot3D_horizontal(p3,ix2,ix1,y,zz2,zz1,color); - else - Plot3D_horizontal(p3,ix1,ix2,y,zz1,zz2,color); - y--; - } - } -} - -/* ------------------------------------------------------------------------- - Plot3D_solidtriangle(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, - Pixel color) - - This function draws a 3D z-buffered filled triangle. Can be used to - draw other primitives such as quadralaterals, etc... - - This function simply transforms the given points and calls - Plot3D_SolidTriangleTransform(). - -------------------------------------------------------------------------- */ - -void Plot3D_solidtriangle(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, Pixel color) { - - int tx1, tx2, tx3, ty1, ty2, ty3; - Zvalue tz1, tz2, tz3; - GL_Vector t; - double invw; - Matrix a; - register double xshift, yshift, zoom, width, height, view_xmin, view_ymin; - - a = p3->trans_mat; - xshift = p3->xshift; - yshift = p3->yshift; - zoom = p3->zoom; - height = p3->height; - width = p3->width; - view_xmin = p3->view_xmin; - view_ymin = p3->view_ymin; - - /* Transform the three points into screen coordinates */ - - t.w = a[12]*x1 + a[13]*y1 + a[14]*z1 + a[15]; - invw = 1.0/t.w; - t.x = (a[0]*x1 + a[1]*y1 + a[2]*z1 + a[3])*invw; - t.y = (a[4]*x1 + a[5]*y1 + a[6]*z1 + a[7])*invw; - t.z = (a[8]*x1 + a[9]*y1 + a[10]*z1 + a[11])*invw; - - tx1 = (int) ((t.x +xshift)*zoom*width + 0.5) + view_xmin; - ty1 = (int) ((t.y +yshift)*zoom*height + 0.5) + view_ymin; - tz1 = (Zvalue) t.z; - - - t.w = a[12]*x2 + a[13]*y2 + a[14]*z2 + a[15]; - invw = 1.0/t.w; - t.x = (a[0]*x2 + a[1]*y2 + a[2]*z2 + a[3])*invw; - t.y = (a[4]*x2 + a[5]*y2 + a[6]*z2 + a[7])*invw; - t.z = (a[8]*x2 + a[9]*y2 + a[10]*z2 + a[11])*invw; - tx2 = (int) ((t.x +xshift)*zoom*width + 0.5) + view_xmin; - ty2 = (int) ((t.y +yshift)*zoom*height + 0.5) + view_ymin; - tz2 = (Zvalue) t.z; - - t.w = a[12]*x3 + a[13]*y3 + a[14]*z3 + a[15]; - invw = 1.0/t.w; - t.x = (a[0]*x3 + a[1]*y3 + a[2]*z3 + a[3])*invw; - t.y = (a[4]*x3 + a[5]*y3 + a[6]*z3 + a[7])*invw; - t.z = (a[8]*x3 + a[9]*y3 + a[10]*z3 + a[11])*invw; - tx3 = (int) ((t.x +xshift)*zoom*width + 0.5) + view_xmin; - ty3 = (int) ((t.y +yshift)*zoom*height + 0.5) + view_ymin; - tz3 = (Zvalue) t.z; - - Plot3D_solidtriangletransform(p3,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,color); - -} - - -/* ------------------------------------------------------------------------- - Plot3D_horizontalinterp(Plot3D *p3, int xmin, int xmax, int y, - double z1, double z2, Pixel c1, Pixel c2) - - Draws a "Horizontal" line on the framebuffer between two screen coordinates, - but also supplies z-values and zbuffering. Performs a color interpolation - between c1 and c2. This is primarily used by the SolidTriangleInterp() - function to give the illusion of smooth surfaces. - -------------------------------------------------------------------------- */ - -void Plot3D_horizontalinterp(Plot3D *p3, int xmin, int xmax, int y, - Zvalue z1, Zvalue z2, Pixel c1, Pixel c2) { - Pixel *p; - FrameBuffer *f; - int i; - Zvalue *zbuf,z,mz; - double mc; - int startx, endx; - double invdx; - - f = p3->frame; - if ((y < f->ymin) || (y >= f->ymax)) return; - if (xmin >= f->xmax) return; - if (xmin < f->xmin) startx = f->xmin; - else startx = xmin; - if (xmax < f->xmin) return; - if (xmax >= f->xmax) endx = f->xmax - 1; - else endx = xmax; - - /* Calculate z slope */ - if (xmax != xmin) { - invdx = 1.0/(double) (xmax-xmin); - } else { - invdx = 0; - } - - mz = (Zvalue) (z2 - z1)*invdx; - - /* Calculate c slope */ - - mc = (double) (c2 - c1)*invdx; - - /* Draw it */ - - p = &f->pixels[y][startx]; - zbuf = &f->zbuffer[y][startx]; - for (i = startx; i <= endx; i++, p++, zbuf++) { - z = (Zvalue) (mz*(i-xmin) + z1); - if (z <= *zbuf) { - *p = (Pixel) (mc*(i-xmin)+c1); - *zbuf = z; - } - } -} - -/* ------------------------------------------------------------------------- - Plot3D_interptriangletransform(Plot3D *p3, - int tx1, int ty2, Zvalue tz1, Pixel c1, - int tx2, int ty2, Zvalue tz2, Pixel c2, - int tx3, int ty3, Zvalue tz3, Pixel c3) - - This function draws a 3D z-buffered filled triangle with color - interpolation. Assumes three points have already been transformed - into screen coordinates. - - General idea : - 1. Transform the three points into screen coordinates - 2. Order three points vertically on screen. - 3. Check for degenerate cases (where 3 points are colinear). - 4. Fill in the resulting triangle using horizontal lines. - 5. Colors are interpolated between end points - -------------------------------------------------------------------------- */ - -void Plot3D_interptriangletransform(Plot3D *p3, - int tx1, int ty1, Zvalue tz1, Pixel c1, - int tx2, int ty2, Zvalue tz2, Pixel c2, - int tx3, int ty3, Zvalue tz3, Pixel c3) { - int tempx, tempy; - Zvalue tempz; - double m1,m2,m3, mz1, mz2, mz3; - double mc1,mc2,mc3; - Pixel ic1,ic2,tempc; - int y; - int ix1, ix2; - Zvalue zz1, zz2; - FrameBuffer *f; - - f = p3->frame; - - /* Figure out which point has the greatest "y" value */ - - if (ty2 > ty1) { /* Swap points 1 and 2 if 2 is higher */ - tempx = tx1; - tempy = ty1; - tempz = tz1; - tempc = c1; - tx1 = tx2; - ty1 = ty2; - tz1 = tz2; - c1 = c2; - tx2 = tempx; - ty2 = tempy; - tz2 = tempz; - c2 = tempc; - } - if (ty3 > ty1) { /* Swap points 1 and 3 if 3 is higher */ - tempx = tx1; - tempy = ty1; - tempz = tz1; - tempc = c1; - tx1 = tx3; - ty1 = ty3; - tz1 = tz3; - c1 = c3; - tx3 = tempx; - ty3 = tempy; - tz3 = tempz; - c3 = tempc; - } - if (ty3 > ty2) { /* Swap points 2 and 3 if 3 is higher */ - tempx = tx2; - tempy = ty2; - tempz = tz2; - tempc = c2; - tx2 = tx3; - ty2 = ty3; - tz2 = tz3; - c2 = c3; - tx3 = tempx; - ty3 = tempy; - tz3 = tempz; - c3 = tempc; - } - - /* Points are now order so that t_1 is the highest point, t_2 is the - middle point, and t_3 is the lowest point */ - - /* Check for degenerate cases here */ - - if ((ty1 == ty2) && (ty2 == ty3)) { - - /* Points are aligned horizontally. Handle as a special case */ - /* Just draw three lines using the outline color */ - - if (tx2 > tx1) - Plot3D_horizontalinterp(p3,tx1,tx2,ty1,tz1,tz2,c1,c2); - else - Plot3D_horizontalinterp(p3,tx2,tx1,ty1,tz2,tz1,c2,c1); - if (tx3 > tx1) - Plot3D_horizontalinterp(p3,tx1,tx3,ty1,tz1,tz3,c1,c3); - else - Plot3D_horizontalinterp(p3,tx3,tx1,ty1,tz3,tz1,c3,c1); - if (tx3 > tx2) - Plot3D_horizontalinterp(p3,tx2,tx3,ty2,tz2,tz3,c2,c3); - else - Plot3D_horizontalinterp(p3,tx3,tx2,ty2,tz3,tz2,c3,c2); - - } else { - - /* First process line segments between (x1,y1)-(x2,y2) - And between (x1,y1),(x3,y3) */ - - if (ty2 < ty1) { - m1 = (double) (tx2 - tx1)/(double) (ty2 - ty1); - m2 = (double) (tx3 - tx1)/(double) (ty3 - ty1); - mz1 = (tz2 - tz1)/(double) (ty2 - ty1); - mz2 = (tz3 - tz1)/(double) (ty3 - ty1); - mc1 = (c2 - c1)/(double) (ty2 - ty1); - mc2 = (c3 - c1)/(double) (ty3 - ty1); - - y = ty1; - while (y >= ty2) { - /* Calculate x values from slope */ - ix1 = (int) (m1*(y-ty1)+0.5) + tx1; - ix2 = (int) (m2*(y-ty1)+0.5) + tx1; - zz1 = mz1*(y-ty1) + tz1; - zz2 = mz2*(y-ty1) + tz1; - ic1 = mc1*(y-ty1) + c1; - ic2 = mc2*(y-ty1) + c1; - if (ix1 > ix2) - Plot3D_horizontalinterp(p3,ix2,ix1,y,zz2,zz1,ic2,ic1); - else - Plot3D_horizontalinterp(p3,ix1,ix2,y,zz1,zz2,ic1,ic2); - y--; - } - } - if (ty3 < ty2) { - /* Draw lower half of the triangle */ - m2 = (double) (tx3 - tx1)/(double) (ty3 - ty1); - mz2 = (tz3 - tz1)/(double) (ty3 - ty1); - mc2 = (c3 - c1)/(double) (ty3 - ty1); - m3 = (double) (tx3 - tx2)/(double)(ty3 - ty2); - mz3 = (tz3 - tz2)/(double) (ty3 - ty2); - mc3 = (c3 - c2)/(double) (ty3 - ty2); - y = ty2; - while (y >= ty3) { - ix1 = (int) (m3*(y-ty2)+0.5)+tx2; - ix2 = (int) (m2*(y-ty1)+0.5)+tx1; - zz1 = mz3*(y-ty2)+tz2; - zz2 = mz2*(y-ty1)+tz1; - ic1 = mc3*(y-ty2)+c2; - ic2 = mc2*(y-ty1)+c1; - if (ix1 > ix2) - Plot3D_horizontalinterp(p3,ix2,ix1,y,zz2,zz1,ic2,ic1); - else - Plot3D_horizontalinterp(p3,ix1,ix2,y,zz1,zz2,ic1,ic2); - y--; - } - } - } -} - -/* ------------------------------------------------------------------------- - Plot3D_interptriangle(Plot3D *p3, - double x1, double y1, double z1, Pixel c1, - double x2, double y2, double z2, Pixel c2, - double x3, double y3, double z3, Pixel c3) - - This function draws a 3D z-buffered filled triangle with color - interpolation. - - This function simply transforms the given points and calls - Plot3D_InterpTriangleTransform(). - -------------------------------------------------------------------------- */ - -void Plot3D_interptriangle(Plot3D *p3, - double x1, double y1, double z1, Pixel c1, - double x2, double y2, double z2, Pixel c2, - double x3, double y3, double z3, Pixel c3) { - - int tx1, tx2, tx3, ty1, ty2, ty3; - Zvalue tz1, tz2, tz3; - GL_Vector t; - double invw; - - /* Transform the three points into screen coordinates */ - - Matrix_transform4(p3->trans_mat,x1,y1,z1,1,&t); /* Point 1 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx1 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty1 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz1 = (Zvalue) t.z; - - Matrix_transform4(p3->trans_mat,x2,y2,z2,1,&t); /* Point 2 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx2 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty2 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz2 = (Zvalue) t.z; - - Matrix_transform4(p3->trans_mat,x3,y3,z3,1,&t); /* Point 3 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx3 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty3 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz3 = (Zvalue) t.z; - - Plot3D_interptriangletransform(p3,tx1,ty1,tz1,c1,tx2,ty2,tz2,c2,tx3,ty3,tz3,c3); -} - -/* ------------------------------------------------------------------------- - Plot3D_quad(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, - double x4, double y4, double z4, - Pixel fillcolor) - - This function draws a 3D outlined Quadralateral. Used primarily for - drawing meshes and other things. - - Plotting is done in the following order : - (x1,y1,z1) --> (x2,y2,z2) - (x2,y2,z2) --> (x3,y3,z3) - (x3,y3,z3) --> (x4,y4,z4) - (x4,y4,z4) --> (x1,y1,z1) - -------------------------------------------------------------------------- */ - -void Plot3D_quad(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, - double x4, double y4, double z4, - Pixel color) { - - int tx1, tx2, tx3, tx4, ty1, ty2, ty3, ty4; - Zvalue tz1, tz2, tz3, tz4; - GL_Vector t; - double invw; - - /* Transform the three points into screen coordinates */ - - Matrix_transform4(p3->trans_mat,x1,y1,z1,1,&t); /* Point 1 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx1 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty1 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz1 = (Zvalue) t.z; - - Matrix_transform4(p3->trans_mat,x2,y2,z2,1,&t); /* Point 2 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx2 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty2 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz2 = (Zvalue) t.z; - - Matrix_transform4(p3->trans_mat,x3,y3,z3,1,&t); /* Point 3 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx3 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty3 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz3 = (Zvalue) t.z; - - Matrix_transform4(p3->trans_mat,x4,y4,z4,1,&t); /* Point 3 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx4 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty4 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz4 = (Zvalue) t.z; - - Plot3D_linetransform(p3,tx1,ty1,tz1,tx2,ty2,tz2,color); - Plot3D_linetransform(p3,tx2,ty2,tz2,tx3,ty3,tz3,color); - Plot3D_linetransform(p3,tx3,ty3,tz3,tx4,ty4,tz4,color); - Plot3D_linetransform(p3,tx4,ty4,tz4,tx1,ty1,tz1,color); - -} - - -/* ------------------------------------------------------------------------- - Plot3D_solidquad(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, - double x4, double y4, double z4, - Pixel fillcolor) - - This function draws a 3D solid Quadralateral. Uses the function - Plot3D_SolidTriangleTransform() to fill in the region. - - Plotting is done in the following order : - (x1,y1,z1) --> (x2,y2,z2) - (x2,y2,z2) --> (x3,y3,z3) - (x3,y3,z3) --> (x4,y4,z4) - (x4,y4,z4) --> (x1,y1,z1) - -------------------------------------------------------------------------- */ - -void Plot3D_solidquad(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, - double x4, double y4, double z4, - Pixel color) { - - int tx1, tx2, tx3, tx4, ty1, ty2, ty3, ty4; - Zvalue tz1, tz2, tz3, tz4; - GL_Vector t; - double invw; - - /* Transform the three points into screen coordinates */ - - Matrix_transform4(p3->trans_mat,x1,y1,z1,1,&t); /* Point 1 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx1 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty1 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz1 = (Zvalue) t.z; - - Matrix_transform4(p3->trans_mat,x2,y2,z2,1,&t); /* Point 2 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx2 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty2 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz2 = (Zvalue) t.z; - - Matrix_transform4(p3->trans_mat,x3,y3,z3,1,&t); /* Point 3 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx3 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty3 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz3 = (Zvalue) t.z; - - Matrix_transform4(p3->trans_mat,x4,y4,z4,1,&t); /* Point 3 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx4 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty4 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz4 = (Zvalue) t.z; - - Plot3D_solidtriangletransform(p3,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,color); - Plot3D_solidtriangletransform(p3,tx1,ty1,tz1,tx4,ty4,tz4,tx3,ty3,tz3,color); -} - -/* ------------------------------------------------------------------------- - Plot3D_interpquad(Plot3D *p3, double x1, double y1, double z1, Pixel c1, - double x2, double y2, double z2, Pixel c2, - double x3, double y3, double z3, Pixel c3, - double x4, double y4, double z4, Pixel c4) - - This function draws a 3D color-interpolated Quadralateral. Uses the function - Plot3D_InterpTriangleTransform() to fill in the region. - - Plotting is done in the following order : - (x1,y1,z1) --> (x2,y2,z2) - (x2,y2,z2) --> (x3,y3,z3) - (x3,y3,z3) --> (x4,y4,z4) - (x4,y4,z4) --> (x1,y1,z1) - -------------------------------------------------------------------------- */ - -void Plot3D_interpquad(Plot3D *p3, double x1, double y1, double z1, Pixel c1, - double x2, double y2, double z2, Pixel c2, - double x3, double y3, double z3, Pixel c3, - double x4, double y4, double z4, Pixel c4) { - - - int tx1, tx2, tx3, tx4, ty1, ty2, ty3, ty4; - Zvalue tz1, tz2, tz3, tz4; - GL_Vector t; - double invw; - - /* Transform the three points into screen coordinates */ - - Matrix_transform4(p3->trans_mat,x1,y1,z1,1,&t); /* Point 1 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx1 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty1 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz1 = (Zvalue) t.z; - - Matrix_transform4(p3->trans_mat,x2,y2,z2,1,&t); /* Point 2 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx2 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty2 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz2 = (Zvalue) t.z; - - Matrix_transform4(p3->trans_mat,x3,y3,z3,1,&t); /* Point 3 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx3 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty3 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz3 = (Zvalue) t.z; - - Matrix_transform4(p3->trans_mat,x4,y4,z4,1,&t); /* Point 3 */ - invw = 1.0/t.w; - t.x = t.x *invw; - t.y = t.y *invw; - t.z = t.z *invw; - tx4 = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty4 = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz4 = (Zvalue) t.z; - - Plot3D_interptriangletransform(p3,tx1,ty1,tz1,c1,tx2,ty2,tz2,c2,tx3,ty3,tz3,c3); - Plot3D_interptriangletransform(p3,tx1,ty1,tz1,c1,tx4,ty4,tz4,c4,tx3,ty3,tz3,c3); - -} - -/* -------------------------------------------------------------------------- - Plot3D_solidsphere(Plot3 *p3, double x, double y, double z, double radius, - Pixel c) - - Makes a 3D sphere at x,y,z with given radius and color. - - Basic strategy : - 1. Transform point to screen coordinates - 2. Figure out what the radius is in screen coordinates - 3. Use bresenham algorithm for large spheres - 4. Use bitmaps for small spheres - -------------------------------------------------------------------------- */ - -/* This is used to fill in spheres */ -static int s_xmin; -static int s_ymin; -static int s_xmax; -static int s_ymax; -static Pixel **s_pixels; -static Zvalue **s_zbuffer; - -void Plot3D_spherehorizontal(int xmin, int xmax, int y, Zvalue z, Pixel color) { - int i; - int startx, endx; - Pixel *p; - Zvalue *zbuf; - - if ((y < s_ymin) || (y >= s_ymax)) return; - if (xmin < s_xmin) startx = s_xmin; - else startx = xmin; - if (xmax >= s_xmax) endx = s_xmax - 1; - else endx = xmax; - - /* Draw it */ - - p = &s_pixels[y][xmin]; - zbuf = &s_zbuffer[y][xmin]; - for (i = startx; i <= endx; i++, p++, zbuf++) { - if (z <= *zbuf) { - *p = color; - *zbuf = z; - } - } -} - -void Plot3D_solidsphere(Plot3D *p3, double x, double y, double z, double radius, - Pixel c) { - - GL_Vector t,r; - double rad; - int tx,ty, irad; - Zvalue tz; - double invw; - int ix, iy, ix1,ix2,p; - FrameBuffer *f; - - /* First transform the point into model coordinates */ - - Matrix_transform4(p3->fullmodel_mat,x,y,z,1,&t); - - /* Now transform two points in order to find proper sphere radius */ - - Matrix_transform4(p3->view_mat,t.x+radius,t.y,t.z,t.w,&r); /* transform radius */ - Matrix_transform4(p3->view_mat,t.x,t.y,t.z,t.w,&t); - - invw = 1.0/t.w; - t.x = t.x*invw; - t.y = t.y*invw; - t.z = t.z*invw; - invw = 1.0/r.w; - r.x = r.x*invw; - r.y = r.y*invw; - r.z = r.z*invw; - invw = 1.0/r.w; - - rad = fabs(t.x - r.x); - - /* Transform everything into screen coordinates */ - - tx = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz = (Zvalue) t.z; - irad = (int) (p3->zoom*(rad*p3->width + 0.5)); - - /* This is only a temporary solution (maybe). */ - -#define fill_zcircle(x,y,c) \ - ix1 = tx - x; \ - ix2 = tx + x; \ - if (ix1 < s_xmin) ix1 = s_xmin; \ - if (ix2 >= s_xmax) ix2 = s_xmax; \ - Plot3D_spherehorizontal(ix1,ix2,y,tz,c); - - f = p3->frame; - s_xmin = f->xmin; - s_ymin = f->ymin; - s_xmax = f->xmax; - s_ymax = f->ymax; - s_pixels = f->pixels; - s_zbuffer = f->zbuffer; - if (irad <= 1) { - /* Plot a single pixel */ - if ((tx >= f->xmin) && (tx < f->xmax)) { - if ((ty >= f->ymin) && (ty ymax)) { - if (tz <= f->zbuffer[ty][tx]) { - f->pixels[ty][tx] = c; - f->zbuffer[ty][tx] = tz; - } - } - } - return; - } - ix = 0; - iy = irad; - p = 3-2*irad; - while (ix <= iy) { - fill_zcircle(ix,ty+iy,c); - fill_zcircle(ix,ty-iy,c); - fill_zcircle(iy,ty+ix,c); - fill_zcircle(iy,ty-ix,c); - if (p < 0) p = p + 4*ix + 6; - else { - p = p + 4*(ix-iy) + 10; - iy = iy -1; - } - ix++; - } -} - - -/* -------------------------------------------------------------------- - Plot3D_outlinesphere(Plot3D *p3, double x, double y, double z, - double radius, Pixel color, Pixel bc) - - Draws an outlined sphere. - -------------------------------------------------------------------- */ - -void Plot3D_outlinesphere(Plot3D *p3, double x, double y, double z, - double radius, Pixel c, Pixel bc) -{ - GL_Vector t,r; - double rad; - int tx,ty, irad; - Zvalue tz; - double invw; - int ix, iy, ix1,ix2,p; - - FrameBuffer *f; - - /* First transform the point into model coordinates */ - - Matrix_transform4(p3->fullmodel_mat,x,y,z,1,&t); - - /* Now transform two points in order to find proper sphere radius */ - - Matrix_transform4(p3->view_mat,t.x+radius,t.y,t.z,t.w,&r); /* transform radius */ - Matrix_transform4(p3->view_mat,t.x,t.y,t.z,t.w,&t); - - invw = 1.0/t.w; - t.x = t.x*invw; - t.y = t.y*invw; - t.z = t.z*invw; - invw = 1.0/r.w; - r.x = r.x*invw; - r.y = r.y*invw; - r.z = r.z*invw; - invw = 1.0/r.w; - - rad = fabs(t.x - r.x); - - /* Transform everything into screen coordinates */ - - tx = (int) ((t.x +p3->xshift)*p3->zoom*p3->width + 0.5) + p3->view_xmin; - ty = (int) ((t.y +p3->yshift)*p3->zoom*p3->height + 0.5) + p3->view_ymin; - tz = (Zvalue) t.z; - irad = (int) (p3->zoom*(rad*p3->width + 0.5)); - - /* This is only a temporary solution (maybe). */ -#define plot_zcircle(x,y,c) \ - if ((x >= s_xmin) && (x < s_xmax) && \ - (y >= s_ymin) && (y < s_ymax)) {\ - if (tz <= s_zbuffer[y][x]) { \ - s_pixels[y][x] = c; \ - s_zbuffer[y][x] = tz; } \ - } - - f = p3->frame; - s_xmin = f->xmin; - s_ymin = f->ymin; - s_xmax = f->xmax; - s_ymax = f->ymax; - s_pixels = f->pixels; - s_zbuffer = f->zbuffer; - - if (irad <= 1) { - /* Plot a single pixel */ - if ((tx >= f->xmin) && (tx < f->xmax)) { - if ((ty >= f->ymin) && (ty ymax)) { - if (tz <= f->zbuffer[ty][tx]) { - f->pixels[ty][tx] = c; - f->zbuffer[ty][tx] = tz; - } - } - } - return; - } - ix = 0; - iy = irad; - p = 3-2*irad; - while (ix <= iy) { - fill_zcircle(ix,ty+iy,c); - fill_zcircle(ix,ty-iy,c); - fill_zcircle(iy,ty+ix,c); - fill_zcircle(iy,ty-ix,c); - - plot_zcircle(tx+ix,ty+iy,bc); - plot_zcircle(tx-ix,ty+iy,bc); - plot_zcircle(tx+ix,ty-iy,bc); - plot_zcircle(tx-ix,ty-iy,bc); - plot_zcircle(tx+iy,ty+ix,bc); - plot_zcircle(tx-iy,ty+ix,bc); - plot_zcircle(tx+iy,ty-ix,bc); - plot_zcircle(tx-iy,ty-ix,bc); - if (p < 0) p = p + 4*ix + 6; - else { - p = p + 4*(ix-iy) + 10; - iy = iy -1; - } - ix++; - } -} - -/* QUAD Test - Test out quad functions for graphing */ - -double zf(double x, double y) { - return cos(sqrt(x*x + y*y)*10.0)/(sqrt(x*x+y*y)+1); -} - -void Quad_Test(Plot3D *p3, int npoints) { - int i,j; - double dx; - double x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,za; - int c; - dx = 2.0/npoints; - - - for (i = 0; i < npoints; i++) - for (j = 0; j < npoints; j++) { - x1 = i*dx + -1.0; - y1 = j*dx + -1.0; - x2 = x1 + dx; - x3 = x1 + dx; - x4 = x1; - y2 = y1; - y3 = y1 + dx; - y4 = y1 + dx; - z1 = zf(x1,y1); - z2 = zf(x2,y2); - z3 = zf(x3,y3); - z4 = zf(x4,y4); - za = 0.25*(z1+z2+z3+z4); - c = 16+((za + 1)*120); - if (c > 254) c = 254; - Plot3D_quad(p3,x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,(Pixel) c); - } -} - - -void Quad_SolidTest(Plot3D *p3, int npoints) { - int i,j; - double dx; - double x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,za; - int c; - dx = 2.0/npoints; - - - for (i = 0; i < npoints; i++) - for (j = 0; j < npoints; j++) { - x1 = i*dx + -1.0; - y1 = j*dx + -1.0; - x2 = x1 + dx; - x3 = x1 + dx; - x4 = x1; - y2 = y1; - y3 = y1 + dx; - y4 = y1 + dx; - z1 = zf(x1,y1); - z2 = zf(x2,y2); - z3 = zf(x3,y3); - z4 = zf(x4,y4); - za = 0.25*(z1+z2+z3+z4); - c = 16+((za + 1)*120); - if (c > 254) c = 254; - Plot3D_solidquad(p3,x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,(Pixel) c); - } -} - - - -void Quad_InterpTest(Plot3D *p3, int npoints) { - int i,j; - double dx; - double x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4; - int c1,c2,c3,c4; - dx = 2.0/npoints; - - - for (i = 0; i < npoints; i++) - for (j = 0; j < npoints; j++) { - x1 = i*dx + -1.0; - y1 = j*dx + -1.0; - x2 = x1 + dx; - x3 = x1 + dx; - x4 = x1; - y2 = y1; - y3 = y1 + dx; - y4 = y1 + dx; - z1 = zf(x1,y1); - z2 = zf(x2,y2); - z3 = zf(x3,y3); - z4 = zf(x4,y4); - c1 = 16+((z1 + 1)*120); - c2 = 16+((z2 + 1)*120); - c3 = 16+((z3 + 1)*120); - c4 = 16+((z4 + 1)*120); - if (c1 > 254) c1 = 254; - if (c2 > 254) c2 = 254; - if (c3 > 254) c3 = 254; - if (c4 > 254) c4 = 254; - Plot3D_interpquad(p3,x1,y1,z1,(Pixel) c1,x2,y2,z2,(Pixel) c2,x3,y3,z3,(Pixel) c3,x4,y4,z4,(Pixel) c4); - } -} - - - - - - - - - - - - diff --git a/Examples/GIFPlot/Makefile.in b/Examples/GIFPlot/Makefile.in deleted file mode 100644 index 4e51360c8..000000000 --- a/Examples/GIFPlot/Makefile.in +++ /dev/null @@ -1,23 +0,0 @@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ -RANLIB = @RANLIB@ -OPT = - -INSTALL = ../install-sh -c -INSTALL_DATA = ${INSTALL} -m 644 -SHELL = /bin/sh - -all: - cd Lib && $(MAKE) OPT="$(OPT)" - -install: - $(INSTALL_DATA) Include/gifplot.h $(prefix)/include/gifplot.h - $(INSTALL_DATA) libgifplot.a $(exec_prefix)/lib/libgifplot.a - $(RANLIB) $(exec_prefix)/lib/libgifplot.a - -clean:: - rm -f *.@OBJEXT@ *~ libgifplot.a *_wrap* *_man* - cd Lib && $(MAKE) clean - rm -f config.log config.status config.cache - -check: all diff --git a/Examples/GIFPlot/Ocaml/check.list b/Examples/GIFPlot/Ocaml/check.list deleted file mode 100644 index e75ee586a..000000000 --- a/Examples/GIFPlot/Ocaml/check.list +++ /dev/null @@ -1,3 +0,0 @@ -# see top-level Makefile.in -full -simple diff --git a/Examples/GIFPlot/Ocaml/full/Makefile b/Examples/GIFPlot/Ocaml/full/Makefile deleted file mode 100644 index 4f35c43f9..000000000 --- a/Examples/GIFPlot/Ocaml/full/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -I../../Include -SRCS = -TARGET = gifcaml -INTERFACE = gifplot.i -LIBS = -L../.. -lgifplot -lm -INCLUDES = -I../../Include -MLFILE = gifplot.ml -IOBJS = runme.cmo -PROGFILE = runme.ml - -all:: static - -static:: - $(MAKE) -f $(TOP)/Makefile TOP='$(TOP)' \ - IOBJS='$(IOBJS)' PROGFILE='$(PROGFILE)' \ - SRCS='$(SRCS)' SWIG='$(SWIG)' MLFILE='$(MLFILE)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ocaml_static - -dynamic:: - $(MAKE) -f $(TOP)/Makefile TOP='$(TOP)' \ - IOBJS='$(IOBJS)' PROGFILE='$(PROGFILE)' \ - SRCS='$(SRCS)' SWIG='$(SWIG)' MLFILE='$(MLFILE)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ocaml_dynamic - -clean:: - $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean - rm -f *.gif - -check: all diff --git a/Examples/GIFPlot/Ocaml/full/README b/Examples/GIFPlot/Ocaml/full/README deleted file mode 100644 index 4a2b400b5..000000000 --- a/Examples/GIFPlot/Ocaml/full/README +++ /dev/null @@ -1,8 +0,0 @@ -This example runs the entire gifplot.h header file through SWIG without -any changes. The ocaml program 'runme.ml' does something a little more -interesting. You'll have to go look at the header file to get a complete -listing of the functions. - - - - diff --git a/Examples/GIFPlot/Ocaml/full/cmap b/Examples/GIFPlot/Ocaml/full/cmap deleted file mode 100644 index a20c331a9573dd8443380680bfe2cc428780d8a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9IC C_float x) - [ x ; y ; z1 ; - (x +. dx) ; y ; z2 ; - (x +. dx) ; (y +. dy) ; z3 ; - x ; (y +. dx) ; z4 ; - (float_of_int (c + 16)) ]))) ; - y_loop (y +. dy) (j + 1) - end in - begin - y_loop ymin 0 ; - x_loop (x +. dx) (i + 1) - end - end in - x_loop xmin 0 - end - -let _ = print_endline "Making a nice 3D plot..." -let _ = drawsolid () - -let _ = _FrameBuffer_writeGIF (C_list [ frame ; cmap ; C_string "image.gif" ]) -let _ = print_endline "Write image.gif" diff --git a/Examples/GIFPlot/Ocaml/simple/Makefile b/Examples/GIFPlot/Ocaml/simple/Makefile deleted file mode 100644 index 50492efc7..000000000 --- a/Examples/GIFPlot/Ocaml/simple/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -I../../Include -SRCS = -TARGET = gifsimple -INTERFACE = simple.i -LIBS = -L../.. -lgifplot -lm -INCLUDES = -I../../Include -MLFILE = simple.ml -IOBJS = simple_wrap.o simple.cmo runme.cmo -PROGFILE = runme.ml - -all:: static - -static:: - $(MAKE) -f $(TOP)/Makefile TOP='$(TOP)' \ - IOBJS='$(IOBJS)' PROGFILE='$(PROGFILE)' \ - SRCS='$(SRCS)' SWIG='$(SWIG)' MLFILE='$(MLFILE)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ocaml_static - -dynamic:: - $(MAKE) -f $(TOP)/Makefile TOP='$(TOP)' \ - IOBJS='$(IOBJS)' PROGFILE='$(PROGFILE)' \ - SRCS='$(SRCS)' SWIG='$(SWIG)' MLFILE='$(MLFILE)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ocaml_static - -clean:: - $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean - rm -f *.gif - -check: all diff --git a/Examples/GIFPlot/Ocaml/simple/cmap b/Examples/GIFPlot/Ocaml/simple/cmap deleted file mode 100644 index a20c331a9573dd8443380680bfe2cc428780d8a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9IC&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9IC 239) { $c = 239; } - Plot3D_solidquad($p3,$x,$y,$z1,$x+$dx,$y,$z2,$x+$dx,$y+$dy,$z3,$x,$y+$dy,$z4,$c+16); - $y = $y + $dy; - } - $x = $x + $dx; - } -} - -print "Making a nice 3D plot...\n"; -drawsolid(); - -FrameBuffer_writeGIF($frame,$cmap,"image.gif"); -print "Wrote image.gif\n"; - diff --git a/Examples/GIFPlot/Perl5/shadow/Makefile b/Examples/GIFPlot/Perl5/shadow/Makefile deleted file mode 100644 index c39eac52c..000000000 --- a/Examples/GIFPlot/Perl5/shadow/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -outcurrentdir -SRCS = -TARGET = gifplot -INTERFACEDIR = ../../Interface/ -INTERFACE = gifplot.i -LIBS = -L../.. -lgifplot -lm -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' perl5 - -static:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='myperl' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' perl5_static - -clean:: - $(MAKE) -f $(TOP)/Makefile perl5_clean - rm -f *.gif - -check: all diff --git a/Examples/GIFPlot/Perl5/shadow/README b/Examples/GIFPlot/Perl5/shadow/README deleted file mode 100644 index ab12e344e..000000000 --- a/Examples/GIFPlot/Perl5/shadow/README +++ /dev/null @@ -1,2 +0,0 @@ -This example use the file in ../../Interface/gifplot.i to build -an interface with shadow classes. Run the script 'runme.pl'. diff --git a/Examples/GIFPlot/Perl5/shadow/cmap b/Examples/GIFPlot/Perl5/shadow/cmap deleted file mode 100644 index a20c331a9573dd8443380680bfe2cc428780d8a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9ICclear($BLACK); - -$p3 = new gifplot::Plot3D($frame,$xmin,$ymin,$zmin,$xmax,$ymax,$zmax); -$p3->lookat(2*($zmax-$zmin)); -$p3->autoperspective(40); -$p3->rotu(60); -$p3->rotr(30); -$p3->rotd(10); - -sub drawsolid { - $p3->clear($BLACK); - $p3->start(); - my $dx = 1.0*($xmax-$xmin)/$nxpoints; - my $dy = 1.0*($ymax-$ymin)/$nypoints; - my $cscale = 240.0/($zmax-$zmin); - my $x = $xmin; - for ($i = 0; $i < $nxpoints; $i++) { - my $y = $ymin; - for ($j = 0; $j < $nypoints; $j++) { - my $z1 = func($x,$y); - my $z2 = func($x+$dx,$y); - my $z3 = func($x+$dx,$y+$dy); - my $z4 = func($x,$y+$dy); - my $c1 = $cscale*($z1-$zmin); - my $c2 = $cscale*($z2-$zmin); - my $c3 = $cscale*($z3-$zmin); - my $c4 = $cscale*($z4-$zmin); - my $c = ($c1+$c2+$c3+$c4)/4; - if ($c < 0) { $c = 0; } - if ($c > 239) { $c = 239; } - $p3->solidquad($x,$y,$z1,$x+$dx,$y,$z2,$x+$dx,$y+$dy,$z3,$x,$y+$dy,$z4,$c+16); - $y = $y + $dy; - } - $x = $x + $dx; - } -} - -print "Making a nice 3D plot...\n"; -drawsolid(); - -$frame->writeGIF($cmap,"image.gif"); -print "Wrote image.gif\n"; - diff --git a/Examples/GIFPlot/Perl5/simple/Makefile b/Examples/GIFPlot/Perl5/simple/Makefile deleted file mode 100644 index 36a8fa938..000000000 --- a/Examples/GIFPlot/Perl5/simple/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -SRCS = -TARGET = simple -INTERFACE = simple.i -LIBS = -L../.. -lgifplot -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 - -static:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static - -clean:: - $(MAKE) -f $(TOP)/Makefile perl5_clean - rm -f *.gif - -check: all diff --git a/Examples/GIFPlot/Perl5/simple/README b/Examples/GIFPlot/Perl5/simple/README deleted file mode 100644 index c2c799a70..000000000 --- a/Examples/GIFPlot/Perl5/simple/README +++ /dev/null @@ -1,5 +0,0 @@ -This is a very minimalistic example in which just a few functions -and constants from library are wrapped and used to draw some simple -shapes. The script 'runme.pl' runs the example. - - diff --git a/Examples/GIFPlot/Perl5/simple/runme.pl b/Examples/GIFPlot/Perl5/simple/runme.pl deleted file mode 100644 index f28255e7c..000000000 --- a/Examples/GIFPlot/Perl5/simple/runme.pl +++ /dev/null @@ -1,28 +0,0 @@ -# Draw some simple shapes -print "Drawing some basic shapes\n"; - -use simple; - -$cmap = simple::new_ColorMap(); -$f = simple::new_FrameBuffer(400,400); - -# Clear the picture -simple::FrameBuffer_clear($f,$simple::BLACK); - -# Make a red box -simple::FrameBuffer_box($f,40,40,200,200,$simple::RED); - -# Make a blue circle -simple::FrameBuffer_circle($f,200,200,40,$simple::BLUE); - -# Make green line -simple::FrameBuffer_line($f,10,390,390,200, $simple::GREEN); - -# Write an image out to disk - -simple::FrameBuffer_writeGIF($f,$cmap,"image.gif"); -print "Wrote image.gif\n"; - -simple::delete_FrameBuffer($f); -simple::delete_ColorMap($cmap); - diff --git a/Examples/GIFPlot/Perl5/simple/simple.i b/Examples/GIFPlot/Perl5/simple/simple.i deleted file mode 100644 index 457bc4c09..000000000 --- a/Examples/GIFPlot/Perl5/simple/simple.i +++ /dev/null @@ -1,38 +0,0 @@ -/* This example shows a very simple interface wrapping a few - primitive declarations */ - -%module simple -%{ -#include "gifplot.h" -%} - -typedef unsigned char Pixel; - -/* Here are a few useful functions */ - -ColorMap *new_ColorMap(char *filename = 0); -void delete_ColorMap(ColorMap *cmap); - -FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height); -void delete_FrameBuffer(FrameBuffer *frame); -void FrameBuffer_clear(FrameBuffer *frame, Pixel color); -void FrameBuffer_line(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_box(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_circle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color); -int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename); - -/* And some useful constants */ - -#define BLACK 0 -#define WHITE 1 -#define RED 2 -#define GREEN 3 -#define BLUE 4 -#define YELLOW 5 -#define CYAN 6 -#define MAGENTA 7 - - - - - diff --git a/Examples/GIFPlot/Php/check.list b/Examples/GIFPlot/Php/check.list deleted file mode 100644 index e75ee586a..000000000 --- a/Examples/GIFPlot/Php/check.list +++ /dev/null @@ -1,3 +0,0 @@ -# see top-level Makefile.in -full -simple diff --git a/Examples/GIFPlot/Php/full/Makefile b/Examples/GIFPlot/Php/full/Makefile deleted file mode 100644 index e33e7a730..000000000 --- a/Examples/GIFPlot/Php/full/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -I../../Include -noproxy -SRCS = -TARGET = php_gifplot -INTERFACE = gifplot.i -LIBS = -L../.. -lgifplot -lm -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php - -clean:: - $(MAKE) -f $(TOP)/Makefile php_clean - rm -f *.gif - rm -f php_gifplot.h - -check: all diff --git a/Examples/GIFPlot/Php/full/README b/Examples/GIFPlot/Php/full/README deleted file mode 100644 index f8d38d9af..000000000 --- a/Examples/GIFPlot/Php/full/README +++ /dev/null @@ -1,4 +0,0 @@ -This example runs the entire gifplot.h header file through SWIG without -any changes. The script 'runme.php3' does something a little more -interesting. You'll have to go look at the header file to get a complete -listing of the functions. diff --git a/Examples/GIFPlot/Php/full/cmap b/Examples/GIFPlot/Php/full/cmap deleted file mode 100644 index a20c331a9573dd8443380680bfe2cc428780d8a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9IC 239) { $c = 239; } - Plot3D_solidquad($p3, $x,$y,$z1,$x+$dx,$y,$z2,$x+$dx,$y+$dy,$z3,$x,$y+$dy,$z4,$c+16); - $y = $y + $dy; - } - $x = $x + $dx; - } -} - -print "Making a nice 3D plot...\n"; -drawsolid(); - -FrameBuffer_writeGIF($frame, $cmap,"image.gif"); -print "Wrote image.gif\n"; - -?> diff --git a/Examples/GIFPlot/Php/shadow/Makefile b/Examples/GIFPlot/Php/shadow/Makefile deleted file mode 100644 index df8ee30c0..000000000 --- a/Examples/GIFPlot/Php/shadow/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -I../../Interface -SRCS = -TARGET = php_gifplot -INTERFACE = gifplot.i -LIBS = -L../.. -lgifplot -lm -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php - -clean:: - $(MAKE) -f $(TOP)/Makefile php_clean - rm -f *.gif - -check: all diff --git a/Examples/GIFPlot/Php/shadow/README b/Examples/GIFPlot/Php/shadow/README deleted file mode 100644 index 3e91f7d59..000000000 --- a/Examples/GIFPlot/Php/shadow/README +++ /dev/null @@ -1,2 +0,0 @@ -This example use the file in ../../Interface/gifplot.i to build -an interface with shadow classes. Run the script 'runme.php3'. diff --git a/Examples/GIFPlot/Php/shadow/cmap b/Examples/GIFPlot/Php/shadow/cmap deleted file mode 100644 index a20c331a9573dd8443380680bfe2cc428780d8a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9ICclear(BLACK); - - -$p3 = new Plot3D($frame,$xmin,$ymin,$zmin,$xmax,$ymax,$zmax); -$p3->lookat(2*($zmax-$zmin)); -$p3->autoperspective(40); -$p3->rotu(60); -$p3->rotr(30); -$p3->rotd(10); - -function drawsolid() { - global $xmax; - global $xmin; - global $ymax; - global $ymin; - global $zmin; - global $zmax; - global $nxpoints; - global $nypoints; - global $p3; - - $p3->clear(BLACK); - $p3->start(); - $dx = 1.0*($xmax-$xmin)/$nxpoints; - $dy = 1.0*($ymax-$ymin)/$nypoints; - $cscale = 240.0/($zmax-$zmin); - $x = $xmin; - for ($i = 0; $i < $nxpoints; $i++) { - $y = $ymin; - for ($j = 0; $j < $nypoints; $j++) { - $z1 = func($x,$y); - $z2 = func($x+$dx,$y); - $z3 = func($x+$dx,$y+$dy); - $z4 = func($x,$y+$dy); - $c1 = $cscale*($z1-$zmin); - $c2 = $cscale*($z2-$zmin); - $c3 = $cscale*($z3-$zmin); - $c4 = $cscale*($z4-$zmin); - $c = ($c1+$c2+$c3+$c4)/4; - if ($c < 0) { $c = 0; } - if ($c > 239) { $c = 239; } - $p3->solidquad($x,$y,$z1,$x+$dx,$y,$z2,$x+$dx,$y+$dy,$z3,$x,$y+$dy,$z4,$c+16); - $y = $y + $dy; - } - $x = $x + $dx; - } -} - -print "Making a nice 3D plot...\n"; -drawsolid(); - -$frame->writeGIF($cmap,"image.gif"); -print "Wrote image.gif\n"; - -?> diff --git a/Examples/GIFPlot/Php/simple/Makefile b/Examples/GIFPlot/Php/simple/Makefile deleted file mode 100644 index e60b641fa..000000000 --- a/Examples/GIFPlot/Php/simple/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -noproxy -SRCS = -TARGET = php_simple -INTERFACE = simple.i -LIBS = -L../.. -lgifplot -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php - -clean:: - $(MAKE) -f $(TOP)/Makefile php_clean - rm -f *.gif - rm -f php_simple.h - -check: all diff --git a/Examples/GIFPlot/Php/simple/README b/Examples/GIFPlot/Php/simple/README deleted file mode 100644 index c2c799a70..000000000 --- a/Examples/GIFPlot/Php/simple/README +++ /dev/null @@ -1,5 +0,0 @@ -This is a very minimalistic example in which just a few functions -and constants from library are wrapped and used to draw some simple -shapes. The script 'runme.pl' runs the example. - - diff --git a/Examples/GIFPlot/Php/simple/runme.php b/Examples/GIFPlot/Php/simple/runme.php deleted file mode 100644 index cf21a0927..000000000 --- a/Examples/GIFPlot/Php/simple/runme.php +++ /dev/null @@ -1,32 +0,0 @@ - - diff --git a/Examples/GIFPlot/Php/simple/simple.i b/Examples/GIFPlot/Php/simple/simple.i deleted file mode 100644 index 457bc4c09..000000000 --- a/Examples/GIFPlot/Php/simple/simple.i +++ /dev/null @@ -1,38 +0,0 @@ -/* This example shows a very simple interface wrapping a few - primitive declarations */ - -%module simple -%{ -#include "gifplot.h" -%} - -typedef unsigned char Pixel; - -/* Here are a few useful functions */ - -ColorMap *new_ColorMap(char *filename = 0); -void delete_ColorMap(ColorMap *cmap); - -FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height); -void delete_FrameBuffer(FrameBuffer *frame); -void FrameBuffer_clear(FrameBuffer *frame, Pixel color); -void FrameBuffer_line(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_box(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_circle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color); -int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename); - -/* And some useful constants */ - -#define BLACK 0 -#define WHITE 1 -#define RED 2 -#define GREEN 3 -#define BLUE 4 -#define YELLOW 5 -#define CYAN 6 -#define MAGENTA 7 - - - - - diff --git a/Examples/GIFPlot/Pike/check.list b/Examples/GIFPlot/Pike/check.list deleted file mode 100644 index d38998cab..000000000 --- a/Examples/GIFPlot/Pike/check.list +++ /dev/null @@ -1,2 +0,0 @@ -# see top-level Makefile.in -simple diff --git a/Examples/GIFPlot/Pike/simple/Makefile b/Examples/GIFPlot/Pike/simple/Makefile deleted file mode 100644 index d339e0333..000000000 --- a/Examples/GIFPlot/Pike/simple/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -SRCS = -TARGET = simple -INTERFACE = simple.i -LIBS = -L../.. -lgifplot -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike - -static:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='mypike' INTERFACE='$(INTERFACE)' pike_static - -clean:: - $(MAKE) -f $(TOP)/Makefile pike_clean - rm -f *.gif - -check: all diff --git a/Examples/GIFPlot/Pike/simple/README b/Examples/GIFPlot/Pike/simple/README deleted file mode 100644 index 177b3633b..000000000 --- a/Examples/GIFPlot/Pike/simple/README +++ /dev/null @@ -1,5 +0,0 @@ -This is a very minimalistic example in which just a few functions -and constants from library are wrapped and used to draw some simple -shapes. The script 'runme.pike' runs the example. - - diff --git a/Examples/GIFPlot/Pike/simple/runme.pike b/Examples/GIFPlot/Pike/simple/runme.pike deleted file mode 100644 index 0e70235f1..000000000 --- a/Examples/GIFPlot/Pike/simple/runme.pike +++ /dev/null @@ -1,30 +0,0 @@ -int main() -{ - // Draw some simple shapes - write("Drawing some basic shapes\n"); - - .simple.ColorMap cmap = .simple.new_ColorMap(); - .simple.FrameBuffer f = .simple.new_FrameBuffer(400, 400); - - // Clear the picture - .simple.FrameBuffer_clear(f, .simple.BLACK); - - // Make a red box - .simple.FrameBuffer_box(f, 40, 40, 200, 200, .simple.RED); - - // Make a blue circle - .simple.FrameBuffer_circle(f, 200, 200, 40, .simple.BLUE); - - // Make green line - .simple.FrameBuffer_line(f, 10, 390, 390, 200, .simple.GREEN); - - // Write an image out to disk - .simple.FrameBuffer_writeGIF(f, cmap, "image.gif"); - write("Wrote image.gif\n"); - - .simple.delete_FrameBuffer(f); - .simple.delete_ColorMap(cmap); - - return 0; -} - diff --git a/Examples/GIFPlot/Pike/simple/simple.i b/Examples/GIFPlot/Pike/simple/simple.i deleted file mode 100644 index 457bc4c09..000000000 --- a/Examples/GIFPlot/Pike/simple/simple.i +++ /dev/null @@ -1,38 +0,0 @@ -/* This example shows a very simple interface wrapping a few - primitive declarations */ - -%module simple -%{ -#include "gifplot.h" -%} - -typedef unsigned char Pixel; - -/* Here are a few useful functions */ - -ColorMap *new_ColorMap(char *filename = 0); -void delete_ColorMap(ColorMap *cmap); - -FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height); -void delete_FrameBuffer(FrameBuffer *frame); -void FrameBuffer_clear(FrameBuffer *frame, Pixel color); -void FrameBuffer_line(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_box(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_circle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color); -int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename); - -/* And some useful constants */ - -#define BLACK 0 -#define WHITE 1 -#define RED 2 -#define GREEN 3 -#define BLUE 4 -#define YELLOW 5 -#define CYAN 6 -#define MAGENTA 7 - - - - - diff --git a/Examples/GIFPlot/Python/check.list b/Examples/GIFPlot/Python/check.list deleted file mode 100644 index 13de977af..000000000 --- a/Examples/GIFPlot/Python/check.list +++ /dev/null @@ -1,4 +0,0 @@ -# see top-level Makefile.in -full -shadow -simple diff --git a/Examples/GIFPlot/Python/full/Makefile b/Examples/GIFPlot/Python/full/Makefile deleted file mode 100644 index 83a7c864b..000000000 --- a/Examples/GIFPlot/Python/full/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -SWIGOPT = -I../../Include -SRCS = -TARGET = gifplot -INTERFACE = gifplot.i -LIBS = -L../.. -lgifplot -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python - -static:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='mypython' INTERFACE='$(INTERFACE)' python_static - -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py - rm -f *.gif - -check: all - $(MAKE) -f $(TOP)/Makefile python_run diff --git a/Examples/GIFPlot/Python/full/README b/Examples/GIFPlot/Python/full/README deleted file mode 100644 index 52971e40a..000000000 --- a/Examples/GIFPlot/Python/full/README +++ /dev/null @@ -1,8 +0,0 @@ -This example runs the entire gifplot.h header file through SWIG without -any changes. The script 'runme.py' does something a little more -interesting. You'll have to go look at the header file to get a complete -listing of the functions. - - - - diff --git a/Examples/GIFPlot/Python/full/cmap b/Examples/GIFPlot/Python/full/cmap deleted file mode 100644 index a20c331a9573dd8443380680bfe2cc428780d8a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9IC 239 : c = 239 - Plot3D_solidquad(p3,x,y,z1,x+dx,y,z2,x+dx,y+dy,z3,x,y+dy,z4,c+16) - y = y + dy - x = x + dx - -print "Making a nice 3D plot..." -drawsolid() - -FrameBuffer_writeGIF(frame,cmap,"image.gif") -print "Wrote image.gif" - diff --git a/Examples/GIFPlot/Python/shadow/Makefile b/Examples/GIFPlot/Python/shadow/Makefile deleted file mode 100644 index 3ae9a9897..000000000 --- a/Examples/GIFPlot/Python/shadow/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -SWIGOPT = -outcurrentdir -SRCS = -TARGET = gifplot -INTERFACEDIR = ../../Interface/ -INTERFACE = gifplot.i -LIBS = -L../.. -lgifplot -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' python - -static:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='mypython' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' python_static - -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py - rm -f *.gif - -check: all - $(MAKE) -f $(TOP)/Makefile python_run diff --git a/Examples/GIFPlot/Python/shadow/README b/Examples/GIFPlot/Python/shadow/README deleted file mode 100644 index aa761e240..000000000 --- a/Examples/GIFPlot/Python/shadow/README +++ /dev/null @@ -1,8 +0,0 @@ -This example illustrates Python shadow classes. Take a look at -the file GIFPlot/Interface/gifplot.i - - - - - - diff --git a/Examples/GIFPlot/Python/shadow/cmap b/Examples/GIFPlot/Python/shadow/cmap deleted file mode 100644 index a20c331a9573dd8443380680bfe2cc428780d8a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9IC 239 : c = 239 - p3.solidquad(x,y,z1,x+dx,y,z2,x+dx,y+dy,z3,x,y+dy,z4,c+16) - y = y + dy - x = x + dx - -print "Making a nice 3D plot..." -drawsolid() - -frame.writeGIF(cmap,"image.gif") -print "Wrote image.gif" - diff --git a/Examples/GIFPlot/Python/simple/Makefile b/Examples/GIFPlot/Python/simple/Makefile deleted file mode 100644 index 9fc9a6c72..000000000 --- a/Examples/GIFPlot/Python/simple/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -SWIGOPT = -SRCS = -TARGET = simple -INTERFACE = simple.i -LIBS = -L../.. -lgifplot -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python - -static:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='mypython' INTERFACE='$(INTERFACE)' python_static - -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py - rm -f *.gif - -check: all - $(MAKE) -f $(TOP)/Makefile python_run diff --git a/Examples/GIFPlot/Python/simple/README b/Examples/GIFPlot/Python/simple/README deleted file mode 100644 index 22152c665..000000000 --- a/Examples/GIFPlot/Python/simple/README +++ /dev/null @@ -1,5 +0,0 @@ -This is a very minimalistic example in which just a few functions -and constants from library are wrapped and used to draw some simple -shapes. The script 'runme.py' runs the example. - - diff --git a/Examples/GIFPlot/Python/simple/runme.py b/Examples/GIFPlot/Python/simple/runme.py deleted file mode 100644 index dade67767..000000000 --- a/Examples/GIFPlot/Python/simple/runme.py +++ /dev/null @@ -1,27 +0,0 @@ -# Draw some simple shapes -print "Drawing some basic shapes" -import simple - -cmap = simple.new_ColorMap() -f = simple.new_FrameBuffer(400,400) - -# Clear the picture -simple.FrameBuffer_clear(f,simple.BLACK) - -# Make a red box -simple.FrameBuffer_box(f,40,40,200,200,simple.RED) - -# Make a blue circle -simple.FrameBuffer_circle(f,200,200,40,simple.BLUE) - -# Make green line -simple.FrameBuffer_line(f,10,390,390,200, simple.GREEN) - -# Write an image out to disk - -simple.FrameBuffer_writeGIF(f,cmap,"image.gif") -print "Wrote image.gif" - -simple.delete_FrameBuffer(f) -simple.delete_ColorMap(cmap) - diff --git a/Examples/GIFPlot/Python/simple/simple.i b/Examples/GIFPlot/Python/simple/simple.i deleted file mode 100644 index 457bc4c09..000000000 --- a/Examples/GIFPlot/Python/simple/simple.i +++ /dev/null @@ -1,38 +0,0 @@ -/* This example shows a very simple interface wrapping a few - primitive declarations */ - -%module simple -%{ -#include "gifplot.h" -%} - -typedef unsigned char Pixel; - -/* Here are a few useful functions */ - -ColorMap *new_ColorMap(char *filename = 0); -void delete_ColorMap(ColorMap *cmap); - -FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height); -void delete_FrameBuffer(FrameBuffer *frame); -void FrameBuffer_clear(FrameBuffer *frame, Pixel color); -void FrameBuffer_line(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_box(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_circle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color); -int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename); - -/* And some useful constants */ - -#define BLACK 0 -#define WHITE 1 -#define RED 2 -#define GREEN 3 -#define BLUE 4 -#define YELLOW 5 -#define CYAN 6 -#define MAGENTA 7 - - - - - diff --git a/Examples/GIFPlot/README b/Examples/GIFPlot/README deleted file mode 100644 index ac1025a42..000000000 --- a/Examples/GIFPlot/README +++ /dev/null @@ -1,59 +0,0 @@ -GIFPlot -======= - -To illustrate various SWIG features, the following examples involve -building an interface to a small, but somewhat useful graphics library -for creating 2D and 3D images in the form of GIF files. The Perl, -Python, Tcl, Java, Ruby etc. directories contain various examples specific to -those languages. - -This library was originally developed as part of the SPaSM molecular -dynamics project at Los Alamos National Laboratory. However, due to -patent enforcement issues related to LZW encoding and a general lack -of time on the part of the author, the library was never officially -released. On the plus side, a number of people have found it to be a -useful easter egg within the SWIG distribution :-). - - -DUE TO PATENT RESTRICTIONS ON THE LZW COMPRESSION ALGORITHM, THIS -LIBRARY ONLY PRODUCES UNCOMPRESSED GIF FILES. SO THERE. - - -Building the Library -==================== - -In order to run the examples, it is first necessary to build the GIFPlot -C library. To do this, simply run make: - - make - -Running the Examples -==================== - -Once the library has been built, go to your chosen language directory, -that is, Perl, Python, Tcl, Java, Ruby etc. Each example should have a -README file with a description. - -Each example can be compiled using the makefile in each example directory. This -makefile uses the top level makefile in the "Examples" directory of the distribution. -If the example doesn't compile, you will need to adjust the settings in this file. - -Documentation -============= - -Read the source Luke. The examples should be pretty much self-explanatory. -The header file Include/gifplot.h contains the full API. - -The original documentation for the library can be found online at: - - http://www.dabeaz.com/gifplot/index.html - - -Let me know what you think! -=========================== -If you found this example to be useful, confusing, or otherwise, I would like to know -about it. Suggestions for improvement are welcome. - --- Dave (dave@dabeaz.com) - - diff --git a/Examples/GIFPlot/Ruby/check.list b/Examples/GIFPlot/Ruby/check.list deleted file mode 100644 index 13de977af..000000000 --- a/Examples/GIFPlot/Ruby/check.list +++ /dev/null @@ -1,4 +0,0 @@ -# see top-level Makefile.in -full -shadow -simple diff --git a/Examples/GIFPlot/Ruby/full/Makefile b/Examples/GIFPlot/Ruby/full/Makefile deleted file mode 100644 index 5af8bc832..000000000 --- a/Examples/GIFPlot/Ruby/full/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -I../../Include -SRCS = -TARGET = gifplot -INTERFACE = gifplot.i -LIBS = -L../.. -lgifplot -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby - -static:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static - -clean:: - $(MAKE) -f $(TOP)/Makefile ruby_clean - rm -f *.gif - -check: all diff --git a/Examples/GIFPlot/Ruby/full/README b/Examples/GIFPlot/Ruby/full/README deleted file mode 100644 index 22af6cb06..000000000 --- a/Examples/GIFPlot/Ruby/full/README +++ /dev/null @@ -1,8 +0,0 @@ -This example runs the entire gifplot.h header file through SWIG without -any changes. The script 'runme.rb' does something a little more -interesting. You'll have to go look at the header file to get a complete -listing of the functions. - - - - diff --git a/Examples/GIFPlot/Ruby/full/cmap b/Examples/GIFPlot/Ruby/full/cmap deleted file mode 100644 index a20c331a9573dd8443380680bfe2cc428780d8a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9IC 239 - Plot3D_solidquad(P3,x,y,z1,x+dx,y,z2,x+dx,y+dy,z3,x,y+dy,z4,c+16) - y = y + dy - end - x = x + dx - end -end - -puts "Making a nice 3D plot..." -drawsolid() - -FrameBuffer_writeGIF(frame,cmap,"image.gif") -puts "Wrote image.gif" diff --git a/Examples/GIFPlot/Ruby/shadow/Makefile b/Examples/GIFPlot/Ruby/shadow/Makefile deleted file mode 100644 index 8cbea2a57..000000000 --- a/Examples/GIFPlot/Ruby/shadow/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -outcurrentdir -SRCS = -TARGET = gifplot -INTERFACEDIR = ../../Interface/ -INTERFACE = gifplot.i -LIBS = -L../.. -lgifplot -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' ruby - -static:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='myruby' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' ruby_static - -clean:: - $(MAKE) -f $(TOP)/Makefile ruby_clean - rm -f *.gif - -check: all diff --git a/Examples/GIFPlot/Ruby/shadow/README b/Examples/GIFPlot/Ruby/shadow/README deleted file mode 100644 index 7a33e137f..000000000 --- a/Examples/GIFPlot/Ruby/shadow/README +++ /dev/null @@ -1,5 +0,0 @@ -This example illustrates Ruby shadow classes. Take a look at -the file GIFPlot/Interface/gifplot.i - -Actually Ruby module of SWIG needs no shadow class. But this example -is named "shadow" in order to be consistent with other languages. diff --git a/Examples/GIFPlot/Ruby/shadow/cmap b/Examples/GIFPlot/Ruby/shadow/cmap deleted file mode 100644 index a20c331a9573dd8443380680bfe2cc428780d8a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9IC 239 - P3.solidquad(x,y,z1,x+dx,y,z2,x+dx,y+dy,z3,x,y+dy,z4,c+16) - y = y + dy - end - x = x + dx - end -end - -puts "Making a nice 3D plot..." -drawsolid() - -frame.writeGIF(cmap,"image.gif") -puts "Wrote image.gif" - diff --git a/Examples/GIFPlot/Ruby/simple/Makefile b/Examples/GIFPlot/Ruby/simple/Makefile deleted file mode 100644 index f7ca1a7d8..000000000 --- a/Examples/GIFPlot/Ruby/simple/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -SRCS = -TARGET = simple -INTERFACE = simple.i -LIBS = -L../.. -lgifplot -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby - -static:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static - -clean:: - $(MAKE) -f $(TOP)/Makefile ruby_clean - rm -f *.gif - -check: all diff --git a/Examples/GIFPlot/Ruby/simple/README b/Examples/GIFPlot/Ruby/simple/README deleted file mode 100644 index 9b51038bf..000000000 --- a/Examples/GIFPlot/Ruby/simple/README +++ /dev/null @@ -1,5 +0,0 @@ -This is a very minimalistic example in which just a few functions -and constants from library are wrapped and used to draw some simple -shapes. The script 'runme.rb' runs the example. - - diff --git a/Examples/GIFPlot/Ruby/simple/runme.rb b/Examples/GIFPlot/Ruby/simple/runme.rb deleted file mode 100644 index e8bf5a40f..000000000 --- a/Examples/GIFPlot/Ruby/simple/runme.rb +++ /dev/null @@ -1,27 +0,0 @@ -# Draw some simple shapes -puts "Drawing some basic shapes" -require 'simple' - -cmap = Simple.new_ColorMap() -f = Simple.new_FrameBuffer(400,400) - -# Clear the picture -Simple.FrameBuffer_clear(f,Simple::BLACK) - -# Make a red box -Simple.FrameBuffer_box(f,40,40,200,200,Simple::RED) - -# Make a blue circle -Simple.FrameBuffer_circle(f,200,200,40,Simple::BLUE) - -# Make green line -Simple.FrameBuffer_line(f,10,390,390,200, Simple::GREEN) - -# Write an image out to disk - -Simple.FrameBuffer_writeGIF(f,cmap,"image.gif") -puts "Wrote image.gif" - -Simple.delete_FrameBuffer(f) -Simple.delete_ColorMap(cmap) - diff --git a/Examples/GIFPlot/Ruby/simple/simple.i b/Examples/GIFPlot/Ruby/simple/simple.i deleted file mode 100644 index 457bc4c09..000000000 --- a/Examples/GIFPlot/Ruby/simple/simple.i +++ /dev/null @@ -1,38 +0,0 @@ -/* This example shows a very simple interface wrapping a few - primitive declarations */ - -%module simple -%{ -#include "gifplot.h" -%} - -typedef unsigned char Pixel; - -/* Here are a few useful functions */ - -ColorMap *new_ColorMap(char *filename = 0); -void delete_ColorMap(ColorMap *cmap); - -FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height); -void delete_FrameBuffer(FrameBuffer *frame); -void FrameBuffer_clear(FrameBuffer *frame, Pixel color); -void FrameBuffer_line(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_box(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_circle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color); -int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename); - -/* And some useful constants */ - -#define BLACK 0 -#define WHITE 1 -#define RED 2 -#define GREEN 3 -#define BLUE 4 -#define YELLOW 5 -#define CYAN 6 -#define MAGENTA 7 - - - - - diff --git a/Examples/GIFPlot/Tcl/check.list b/Examples/GIFPlot/Tcl/check.list deleted file mode 100644 index 2b6e3d28a..000000000 --- a/Examples/GIFPlot/Tcl/check.list +++ /dev/null @@ -1,4 +0,0 @@ -# see top-level Makefile.in -full -mandel -simple diff --git a/Examples/GIFPlot/Tcl/full/Makefile b/Examples/GIFPlot/Tcl/full/Makefile deleted file mode 100644 index 0c016e364..000000000 --- a/Examples/GIFPlot/Tcl/full/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -I../../Include -SRCS = -TARGET = gifplot -INTERFACE = gifplot.i -LIBS = -L../.. -lgifplot -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tcl - -static:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='mytclsh' INTERFACE='$(INTERFACE)' tclsh - -clean:: - $(MAKE) -f $(TOP)/Makefile tcl_clean - rm -f *.gif - -check: all diff --git a/Examples/GIFPlot/Tcl/full/README b/Examples/GIFPlot/Tcl/full/README deleted file mode 100644 index bdba4e8b0..000000000 --- a/Examples/GIFPlot/Tcl/full/README +++ /dev/null @@ -1,8 +0,0 @@ -This example runs the entire gifplot.h header file through SWIG without -any changes. The script 'runme.tcl' does something a little more -interesting. You'll have to go look at the header file to get a complete -listing of the functions. - - - - diff --git a/Examples/GIFPlot/Tcl/full/cmap b/Examples/GIFPlot/Tcl/full/cmap deleted file mode 100644 index a20c331a9573dd8443380680bfe2cc428780d8a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9IC 239} { set c 239 } - Plot3D_solidquad $p3 $x $y $z1 [expr {$x+$dx}] $y $z2 [expr {$x+$dx}] [expr {$y+$dy}] $z3 $x [expr {$y+$dy}] $z4 [expr {$c+16}] - set y [expr {$y + $dy}] - } - set x [expr {$x + $dx}] - } -} - -puts "Making a nice 3D plot..." -drawsolid - -FrameBuffer_writeGIF $frame $cmap "image.gif" -puts "Wrote image.gif" - diff --git a/Examples/GIFPlot/Tcl/mandel/Makefile b/Examples/GIFPlot/Tcl/mandel/Makefile deleted file mode 100644 index 9280d7bb2..000000000 --- a/Examples/GIFPlot/Tcl/mandel/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -I../../Interface -SRCS = -TARGET = gifplot -INTERFACE = mandel.i -LIBS = -L../.. -lgifplot -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tcl - -static:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='mywish' INTERFACE='$(INTERFACE)' wish - -clean:: - $(MAKE) -f $(TOP)/Makefile tcl_clean - rm -f *.gif - -check: all diff --git a/Examples/GIFPlot/Tcl/mandel/README b/Examples/GIFPlot/Tcl/mandel/README deleted file mode 100644 index a533d09b8..000000000 --- a/Examples/GIFPlot/Tcl/mandel/README +++ /dev/null @@ -1,6 +0,0 @@ -Kill lots of time exploring the Mandelbrot set. This example uses -the full SWIG interface file located in ../../Interface. To run -the program, type 'wish mandel.tcl'. - - - diff --git a/Examples/GIFPlot/Tcl/mandel/cmap b/Examples/GIFPlot/Tcl/mandel/cmap deleted file mode 100644 index a20c331a9573dd8443380680bfe2cc428780d8a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9IC {BoxBegin %W %x %y} - bind $c {BoxDrag %W %x %y} - bind $c "BoxFinish %W %x %y $p2 $mxmin $mymin $mxmax $mymax $func" -} - -proc BoxBegin {w x y} { - global box - set box(anchor) [list $x $y] - catch {unset box(last)} -} - -proc BoxDrag { w x y} { - global box - catch {$w delete $box(last)} - set box(last) [eval {$w create rect} $box(anchor) {$x $y -tag box -outline white}] -} - -proc BoxFinish {w x y p2 mxmin mymin mxmax mymax func } { - global box - set start $box(anchor) - set x1 [lrange $start 0 0] - set y1 [lrange $start 1 1] - catch {$w delete $box(last)} -# Call the handler function - $func $p2 $mxmin $mymin $mxmax $mymax $x1 $y1 $x $y -} - -proc display_image {filename p2 handler} { - global __imageno __images - set i [image create photo -file $filename] - set tl .image$__imageno - toplevel $tl - frame $tl.img - frame $tl.button - - set width [image width $i] - set height [image height $i] - canvas $tl.img.c -width [expr {$width+0}] -height [expr {$height+0}] - pack $tl.img.c - $tl.img.c create image 0 0 -image $i -anchor nw - label $tl.button.label -text $filename - pack $tl.button.label -side left - button $tl.button.dismiss -text "Dismiss" -command "dismiss $tl $i" -width 10 - pack $tl.button.dismiss -side right - pack $tl.img $tl.button -side top -fill x - BoxInit $tl.img.c $p2 [$p2 cget -xmin] [$p2 cget -ymin] [$p2 cget -xmax] [$p2 cget -ymax] $handler - bind $tl "dismiss $tl $i" - bind $tl "dismiss $tl $i" - - # Bind some actions to the canvas - - incr __imageno 1 -} - -proc test {} { - puts "hello" -} - diff --git a/Examples/GIFPlot/Tcl/mandel/mandel.i b/Examples/GIFPlot/Tcl/mandel/mandel.i deleted file mode 100644 index 0b19f4727..000000000 --- a/Examples/GIFPlot/Tcl/mandel/mandel.i +++ /dev/null @@ -1,47 +0,0 @@ -// Special module to run the mandlebrot set -%module gifplot -%include gifplot.i - -%inline %{ - -void mandel(Plot2D *p2, int tol) { - double scalingx; - double scalingy; - double zr,zi,ztr,zti,cr,ci; - double cscale; - int i,j,n; - FrameBuffer *f; - - f = p2->frame; - scalingx = (p2->xmax-p2->xmin)/f->width; - scalingy = (p2->ymax-p2->ymin)/f->height; - - cscale = 239.0/tol; - printf("working...\n"); - for (i = 0; i < f->width; i++) { - for (j = 0; j < f->height; j++) { - zr = scalingx*i + p2->xmin; - zi = scalingy*j + p2->ymin; - cr = zr; - ci = zi; - n = 0; - while (n < tol) { - ztr = zr*zr-zi*zi + cr; - zti = 2*zr*zi + ci; - zr = ztr; - zi = zti; - if (ztr*ztr + zti*zti > 20) break; - n = n + 1; - } - - if (n >= tol) FrameBuffer_plot(f,i,j,BLACK); - else FrameBuffer_plot(f,i,j,16+(int) (n*cscale)); - } - if ((i % 10) == 0) printf("%d\n",i); - } - -} - -%} - - diff --git a/Examples/GIFPlot/Tcl/mandel/mandel.tcl b/Examples/GIFPlot/Tcl/mandel/mandel.tcl deleted file mode 100644 index 3e1600bc1..000000000 --- a/Examples/GIFPlot/Tcl/mandel/mandel.tcl +++ /dev/null @@ -1,170 +0,0 @@ -catch { load ./gifplot[info sharedlibextension] } -source display.tcl -set tcl_precision 17 -set f [FrameBuffer -args 400 400] -set cmap [ColorMap -args cmap] -set p2 [Plot2D -args $f -3 -2 1 2] - -set xmin -3 -set xmax 1 -set ymin -2.0 -set ymax 2.0 -set tolerance 240 -set filename mandel.gif - -# Make a plot from the above parms - -proc make_plot {} { - global p2 cmap tolerance - global xmin ymin xmax ymax filename - $p2 setrange $xmin $ymin $xmax $ymax - $p2 start - . config -cursor watch - update - mandel $p2 $tolerance - . config -cursor arrow - [$p2 cget -frame] writeGIF $cmap $filename - display_image $filename $p2 set_zoom -} - - -# Take some screen coordinates and set global min and max values - -proc set_zoom {p2 mxmin mymin mxmax mymax x1 y1 x2 y2} { - global xmin ymin xmax ymax - - set frame [$p2 cget -frame] - set width [$frame cget -width] - set height [$frame cget -height] - - if {$x1 < 0} {set x1 0} - if {$x1 > ($width)} {set x1 $width} - if {$x2 < 0} {set x2 0} - if {$x2 > ($width)} {set x2 $width} - if {$x1 < $x2} {set ixmin $x1; set ixmax $x2} {set ixmin $x2; set ixmax $x1} - - if {$y1 < 0} {set y1 0} - if {$y1 > ($height)} {set y1 $height} - if {$y2 < 0} {set y2 0} - if {$y2 > ($height)} {set y2 $height} - if {$y1 < $y2} {set iymin $y1; set iymax $y2} {set iymin $y2; set iymax $y1} - - # Now determine new min and max values based on screen location - - set xmin [expr {$mxmin + ($mxmax-$mxmin)*($ixmin)/($width)}] - set xmax [expr {$mxmin + ($mxmax-$mxmin)*($ixmax)/($width)}] - set ymin [expr {$mymin + ($mymax-$mymin)*(($height)-($iymax))/($height)}] - set ymax [expr {$mymin + ($mymax-$mymin)*(($height)-($iymin))/($height)}] - - catch {make_plot} -} - -# Box drag constrained to a square -proc BoxDrag { w x y} { - global box - catch {$w delete $box(last)} - set x1 [lrange $box(anchor) 0 0] - set y1 [lrange $box(anchor) 1 1] - set dx [expr {$x - $x1}] - set dy [expr {$y - $y1}] - if {abs($dy) > abs($dx)} {set dx $dy} - set newx [expr {$x1 + $dx}] - set newy [expr {$y1 + $dx}] - set box(last) [eval {$w create rect} $box(anchor) {$newx $newy -tag box -outline white}] -} - - -proc BoxFinish {w x y p2 mxmin mymin mxmax mymax func } { - global box - set start $box(anchor) - set x1 [lrange $box(anchor) 0 0] - set y1 [lrange $box(anchor) 1 1] - set dx [expr {$x - $x1}] - set dy [expr {$y - $y1}] - if {($dx == 0) || ($dy == 0)} { - catch {$w delete $box(last)} - return - } - if {abs($dy) > abs($dx)} {set dx $dy} - set newx [expr {$x1 + $dx}] - set newy [expr {$y1 + $dx}] - $w config -cursor watch - update -# Call the handler function - $func $p2 $mxmin $mymin $mxmax $mymax $x1 $y1 $newx $newy - catch {$w delete $box(last)} - $w config -cursor arrow -} - - -# Create a few frames - -wm title . Mandelbrot -frame .title -relief groove -borderwidth 1 -label .title.name -text "Mandelbrot Set" -button .title.quit -text "Quit" -command "exit" -button .title.about -text "About" -command "about" -pack .title.name -side left -pack .title.quit .title.about -side right - -frame .func -relief groove -borderwidth 1 - -frame .func.xrange -label .func.xrange.xrlabel -text "X range" -width 12 -entry .func.xrange.xmin -textvar xmin -width 8 -label .func.xrange.xtolabel -text "to" -entry .func.xrange.xmax -textvar xmax -width 8 -pack .func.xrange.xrlabel .func.xrange.xmin .func.xrange.xtolabel .func.xrange.xmax -side left - -frame .func.yrange -label .func.yrange.yrlabel -text "Y range" -width 12 -entry .func.yrange.ymin -textvar ymin -width 8 -label .func.yrange.ytolabel -text "to" -entry .func.yrange.ymax -textvar ymax -width 8 -pack .func.yrange.yrlabel .func.yrange.ymin .func.yrange.ytolabel .func.yrange.ymax -side left - -frame .func.npoints -label .func.npoints.label -text "Tolerance " -width 12 -entry .func.npoints.npoints -textvar tolerance -width 8 -scale .func.npoints.scale -from 0 -to 2500 -variable tolerance -orient horizontal -showvalue false \ - -sliderlength 13 -bigincrement 10 -resolution 10 -pack .func.npoints.label .func.npoints.npoints .func.npoints.scale -side left - -pack .func.xrange .func.yrange .func.npoints -side top -fill x - -# Filename dialog - -frame .save -relief groove -borderwidth 1 - -frame .save.file -label .save.file.label -text "Save as" -width 12 -entry .save.file.filename -textvar filename -width 20 -pack .save.file.label .save.file.filename -side left -pack .save.file -side left -fill x -button .save.go -text "Plot" -command "make_plot" -pack .save.go -side right - -bind .save.file.filename {make_plot} - -pack .title .func .save -side top -fill both - -proc about { } { - toplevel .about -width 350 - - message .about.m -text "\ -Mandelbrot Set\n\n\ -Copyright (c) 1997\n\ -Dave Beazley\n\ -University of Utah\n\n\ -Creates a plot of the Mandelbrot set. Any displayed image can be zoomed by clicking and \ -dragging. Although the main calculation is written in C, it may take awhile for each \ -image to be calculated (be patient). Image quality can be improved at the expense of speed \ -by increasing the tolerance value.\n" - -button .about.okay -text "Ok" -command {destroy .about} - -pack .about.m .about.okay -side top -focus .about.okay -} - -make_plot diff --git a/Examples/GIFPlot/Tcl/simple/Makefile b/Examples/GIFPlot/Tcl/simple/Makefile deleted file mode 100644 index 752d79c10..000000000 --- a/Examples/GIFPlot/Tcl/simple/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../swig -SWIGOPT = -SRCS = -TARGET = simple -INTERFACE = simple.i -LIBS = -L../.. -lgifplot -INCLUDES = -I../../Include - -all:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tcl - -static:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ - TARGET='mytclsh' INTERFACE='$(INTERFACE)' tclsh - -clean:: - $(MAKE) -f $(TOP)/Makefile tcl_clean - rm -f *.gif - -check: all diff --git a/Examples/GIFPlot/Tcl/simple/README b/Examples/GIFPlot/Tcl/simple/README deleted file mode 100644 index d6b291c92..000000000 --- a/Examples/GIFPlot/Tcl/simple/README +++ /dev/null @@ -1,5 +0,0 @@ -This is a very minimalistic example in which just a few functions -and constants from library are wrapped and used to draw some simple -shapes. The script 'runme.tcl' runs the example. - - diff --git a/Examples/GIFPlot/Tcl/simple/runme.tcl b/Examples/GIFPlot/Tcl/simple/runme.tcl deleted file mode 100644 index e3f41266c..000000000 --- a/Examples/GIFPlot/Tcl/simple/runme.tcl +++ /dev/null @@ -1,27 +0,0 @@ -# Draw some simple shapes -puts "Drawing some basic shapes" - -catch { load ./simple[info sharedlibextension] simple} - -set cmap [new_ColorMap] -set f [new_FrameBuffer 400 400] - -# Clear the picture -FrameBuffer_clear $f $BLACK - -# Make a red box -FrameBuffer_box $f 40 40 200 200 $RED - -# Make a blue circle -FrameBuffer_circle $f 200 200 40 $BLUE - -# Make green line -FrameBuffer_line $f 10 390 390 200 $GREEN - -# Write an image out to disk -FrameBuffer_writeGIF $f $cmap image.gif -puts "Wrote image.gif" - -delete_FrameBuffer $f -delete_ColorMap $cmap - diff --git a/Examples/GIFPlot/Tcl/simple/simple.i b/Examples/GIFPlot/Tcl/simple/simple.i deleted file mode 100644 index 457bc4c09..000000000 --- a/Examples/GIFPlot/Tcl/simple/simple.i +++ /dev/null @@ -1,38 +0,0 @@ -/* This example shows a very simple interface wrapping a few - primitive declarations */ - -%module simple -%{ -#include "gifplot.h" -%} - -typedef unsigned char Pixel; - -/* Here are a few useful functions */ - -ColorMap *new_ColorMap(char *filename = 0); -void delete_ColorMap(ColorMap *cmap); - -FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height); -void delete_FrameBuffer(FrameBuffer *frame); -void FrameBuffer_clear(FrameBuffer *frame, Pixel color); -void FrameBuffer_line(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_box(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -void FrameBuffer_circle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color); -int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename); - -/* And some useful constants */ - -#define BLACK 0 -#define WHITE 1 -#define RED 2 -#define GREEN 3 -#define BLUE 4 -#define YELLOW 5 -#define CYAN 6 -#define MAGENTA 7 - - - - - diff --git a/Examples/chicken/zlib/Makefile b/Examples/chicken/zlib/Makefile deleted file mode 100644 index 720701444..000000000 --- a/Examples/chicken/zlib/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -INTERFACE = example.i -SRCS = -CXXSRCS = -TARGET = zlib -INCLUDE = -SWIGOPT = -I/usr/include -CFLAGS = -VARIANT = -LIBS = -lz -VARIANT = _direct - -all:: $(TARGET) - -$(TARGET): $(INTERFACE) $(SRCS) - $(MAKE) -f $(TOP)/Makefile \ - SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' \ - INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='$(TARGET)' \ - SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) - -clean:: - $(MAKE) -f $(TOP)/Makefile chicken_clean - rm -f example.scm - rm -f $(TARGET) - -check:: - csi test-zlib.scm diff --git a/Examples/chicken/zlib/README.html b/Examples/chicken/zlib/README.html deleted file mode 100644 index b082a310c..000000000 --- a/Examples/chicken/zlib/README.html +++ /dev/null @@ -1,1666 +0,0 @@ - - - - zlib - Chicken - SWIG example - - -

zlib - Chicken - SWIG

- -

Table of Contents

- Building the example
- zlib.h
- How the zlib wrapper was developed
- -

Building the example

- - zlib must be installed for this example to work.
- - Just type make to build this example.
- - If zlib is not installed in /usr/lib and /usr/include, then do - something similar to the following: - -
-
make SWIGOPT="-I/usr/local/include" LIBS="-L/usr/local/lib -lz"
-
- -

zlib.h

-
-
-001: /* zlib.h -- interface of the 'zlib' general purpose compression library
-002:   version 1.1.4, March 11th, 2002
-003: 
-004:   Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
-005: 
-006:   This software is provided 'as-is', without any express or implied
-007:   warranty.  In no event will the authors be held liable for any damages
-008:   arising from the use of this software.
-009: 
-010:   Permission is granted to anyone to use this software for any purpose,
-011:   including commercial applications, and to alter it and redistribute it
-012:   freely, subject to the following restrictions:
-013: 
-014:   1. The origin of this software must not be misrepresented; you must not
-015:      claim that you wrote the original software. If you use this software
-016:      in a product, an acknowledgment in the product documentation would be
-017:      appreciated but is not required.
-018:   2. Altered source versions must be plainly marked as such, and must not be
-019:      misrepresented as being the original software.
-020:   3. This notice may not be removed or altered from any source distribution.
-021: 
-022:   Jean-loup Gailly        Mark Adler
-023:   jloup@gzip.org          madler@alumni.caltech.edu
-024: 
-025: 
-026:   The data format used by the zlib library is described by RFCs (Request for
-027:   Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
-028:   (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
-029: */
-030: 
-031: #ifndef _ZLIB_H
-032: #define _ZLIB_H
-033: 
-034: #include "zconf.h"
-035: 
-036: #ifdef __cplusplus
-037: extern "C" {
-038: #endif
-039: 
-040: #define ZLIB_VERSION "1.1.4"
-041: 
-042: /* 
-043:      The 'zlib' compression library provides in-memory compression and
-044:   decompression functions, including integrity checks of the uncompressed
-045:   data.  This version of the library supports only one compression method
-046:   (deflation) but other algorithms will be added later and will have the same
-047:   stream interface.
-048: 
-049:      Compression can be done in a single step if the buffers are large
-050:   enough (for example if an input file is mmap'ed), or can be done by
-051:   repeated calls of the compression function.  In the latter case, the
-052:   application must provide more input and/or consume the output
-053:   (providing more output space) before each call.
-054: 
-055:      The library also supports reading and writing files in gzip (.gz) format
-056:   with an interface similar to that of stdio.
-057: 
-058:      The library does not install any signal handler. The decoder checks
-059:   the consistency of the compressed data, so the library should never
-060:   crash even in case of corrupted input.
-061: */
-062: 
-063: typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
-064: typedef void   (*free_func)  OF((voidpf opaque, voidpf address));
-065: 
-066: struct internal_state;
-067: 
-068: typedef struct z_stream_s {
-069:     Bytef    *next_in;  /* next input byte */
-070:     uInt     avail_in;  /* number of bytes available at next_in */
-071:     uLong    total_in;  /* total nb of input bytes read so far */
-072: 
-073:     Bytef    *next_out; /* next output byte should be put there */
-074:     uInt     avail_out; /* remaining free space at next_out */
-075:     uLong    total_out; /* total nb of bytes output so far */
-076: 
-077:     char     *msg;      /* last error message, NULL if no error */
-078:     struct internal_state FAR *state; /* not visible by applications */
-079: 
-080:     alloc_func zalloc;  /* used to allocate the internal state */
-081:     free_func  zfree;   /* used to free the internal state */
-082:     voidpf     opaque;  /* private data object passed to zalloc and zfree */
-083: 
-084:     int     data_type;  /* best guess about the data type: ascii or binary */
-085:     uLong   adler;      /* adler32 value of the uncompressed data */
-086:     uLong   reserved;   /* reserved for future use */
-087: } z_stream;
-088: 
-089: typedef z_stream FAR *z_streamp;
-090: 
-091: /*
-092:    The application must update next_in and avail_in when avail_in has
-093:    dropped to zero. It must update next_out and avail_out when avail_out
-094:    has dropped to zero. The application must initialize zalloc, zfree and
-095:    opaque before calling the init function. All other fields are set by the
-096:    compression library and must not be updated by the application.
-097: 
-098:    The opaque value provided by the application will be passed as the first
-099:    parameter for calls of zalloc and zfree. This can be useful for custom
-100:    memory management. The compression library attaches no meaning to the
-101:    opaque value.
-102: 
-103:    zalloc must return Z_NULL if there is not enough memory for the object.
-104:    If zlib is used in a multi-threaded application, zalloc and zfree must be
-105:    thread safe.
-106: 
-107:    On 16-bit systems, the functions zalloc and zfree must be able to allocate
-108:    exactly 65536 bytes, but will not be required to allocate more than this
-109:    if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
-110:    pointers returned by zalloc for objects of exactly 65536 bytes *must*
-111:    have their offset normalized to zero. The default allocation function
-112:    provided by this library ensures this (see zutil.c). To reduce memory
-113:    requirements and avoid any allocation of 64K objects, at the expense of
-114:    compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
-115: 
-116:    The fields total_in and total_out can be used for statistics or
-117:    progress reports. After compression, total_in holds the total size of
-118:    the uncompressed data and may be saved for use in the decompressor
-119:    (particularly if the decompressor wants to decompress everything in
-120:    a single step).
-121: */
-122: 
-123:                         /* constants */
-124: 
-125: #define Z_NO_FLUSH      0
-126: #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
-127: #define Z_SYNC_FLUSH    2
-128: #define Z_FULL_FLUSH    3
-129: #define Z_FINISH        4
-130: /* Allowed flush values; see deflate() below for details */
-131: 
-132: #define Z_OK            0
-133: #define Z_STREAM_END    1
-134: #define Z_NEED_DICT     2
-135: #define Z_ERRNO        (-1)
-136: #define Z_STREAM_ERROR (-2)
-137: #define Z_DATA_ERROR   (-3)
-138: #define Z_MEM_ERROR    (-4)
-139: #define Z_BUF_ERROR    (-5)
-140: #define Z_VERSION_ERROR (-6)
-141: /* Return codes for the compression/decompression functions. Negative
-142:  * values are errors, positive values are used for special but normal events.
-143:  */
-144: 
-145: #define Z_NO_COMPRESSION         0
-146: #define Z_BEST_SPEED             1
-147: #define Z_BEST_COMPRESSION       9
-148: #define Z_DEFAULT_COMPRESSION  (-1)
-149: /* compression levels */
-150: 
-151: #define Z_FILTERED            1
-152: #define Z_HUFFMAN_ONLY        2
-153: #define Z_DEFAULT_STRATEGY    0
-154: /* compression strategy; see deflateInit2() below for details */
-155: 
-156: #define Z_BINARY   0
-157: #define Z_ASCII    1
-158: #define Z_UNKNOWN  2
-159: /* Possible values of the data_type field */
-160: 
-161: #define Z_DEFLATED   8
-162: /* The deflate compression method (the only one supported in this version) */
-163: 
-164: #define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
-165: 
-166: #define zlib_version zlibVersion()
-167: /* for compatibility with versions < 1.0.2 */
-168: 
-169:                         /* basic functions */
-170: 
-171: ZEXTERN const char * ZEXPORT zlibVersion OF((void));
-172: /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
-173:    If the first character differs, the library code actually used is
-174:    not compatible with the zlib.h header file used by the application.
-175:    This check is automatically made by deflateInit and inflateInit.
-176:  */
-177: 
-178: /* 
-179: ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
-180: 
-181:      Initializes the internal stream state for compression. The fields
-182:    zalloc, zfree and opaque must be initialized before by the caller.
-183:    If zalloc and zfree are set to Z_NULL, deflateInit updates them to
-184:    use default allocation functions.
-185: 
-186:      The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
-187:    1 gives best speed, 9 gives best compression, 0 gives no compression at
-188:    all (the input data is simply copied a block at a time).
-189:    Z_DEFAULT_COMPRESSION requests a default compromise between speed and
-190:    compression (currently equivalent to level 6).
-191: 
-192:      deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
-193:    enough memory, Z_STREAM_ERROR if level is not a valid compression level,
-194:    Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
-195:    with the version assumed by the caller (ZLIB_VERSION).
-196:    msg is set to null if there is no error message.  deflateInit does not
-197:    perform any compression: this will be done by deflate().
-198: */
-199: 
-200: 
-201: ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
-202: /*
-203:     deflate compresses as much data as possible, and stops when the input
-204:   buffer becomes empty or the output buffer becomes full. It may introduce some
-205:   output latency (reading input without producing any output) except when
-206:   forced to flush.
-207: 
-208:     The detailed semantics are as follows. deflate performs one or both of the
-209:   following actions:
-210: 
-211:   - Compress more input starting at next_in and update next_in and avail_in
-212:     accordingly. If not all input can be processed (because there is not
-213:     enough room in the output buffer), next_in and avail_in are updated and
-214:     processing will resume at this point for the next call of deflate().
-215: 
-216:   - Provide more output starting at next_out and update next_out and avail_out
-217:     accordingly. This action is forced if the parameter flush is non zero.
-218:     Forcing flush frequently degrades the compression ratio, so this parameter
-219:     should be set only when necessary (in interactive applications).
-220:     Some output may be provided even if flush is not set.
-221: 
-222:   Before the call of deflate(), the application should ensure that at least
-223:   one of the actions is possible, by providing more input and/or consuming
-224:   more output, and updating avail_in or avail_out accordingly; avail_out
-225:   should never be zero before the call. The application can consume the
-226:   compressed output when it wants, for example when the output buffer is full
-227:   (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
-228:   and with zero avail_out, it must be called again after making room in the
-229:   output buffer because there might be more output pending.
-230: 
-231:     If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
-232:   flushed to the output buffer and the output is aligned on a byte boundary, so
-233:   that the decompressor can get all input data available so far. (In particular
-234:   avail_in is zero after the call if enough output space has been provided
-235:   before the call.)  Flushing may degrade compression for some compression
-236:   algorithms and so it should be used only when necessary.
-237: 
-238:     If flush is set to Z_FULL_FLUSH, all output is flushed as with
-239:   Z_SYNC_FLUSH, and the compression state is reset so that decompression can
-240:   restart from this point if previous compressed data has been damaged or if
-241:   random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
-242:   the compression.
-243: 
-244:     If deflate returns with avail_out == 0, this function must be called again
-245:   with the same value of the flush parameter and more output space (updated
-246:   avail_out), until the flush is complete (deflate returns with non-zero
-247:   avail_out).
-248: 
-249:     If the parameter flush is set to Z_FINISH, pending input is processed,
-250:   pending output is flushed and deflate returns with Z_STREAM_END if there
-251:   was enough output space; if deflate returns with Z_OK, this function must be
-252:   called again with Z_FINISH and more output space (updated avail_out) but no
-253:   more input data, until it returns with Z_STREAM_END or an error. After
-254:   deflate has returned Z_STREAM_END, the only possible operations on the
-255:   stream are deflateReset or deflateEnd.
-256:   
-257:     Z_FINISH can be used immediately after deflateInit if all the compression
-258:   is to be done in a single step. In this case, avail_out must be at least
-259:   0.1% larger than avail_in plus 12 bytes.  If deflate does not return
-260:   Z_STREAM_END, then it must be called again as described above.
-261: 
-262:     deflate() sets strm->adler to the adler32 checksum of all input read
-263:   so far (that is, total_in bytes).
-264: 
-265:     deflate() may update data_type if it can make a good guess about
-266:   the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
-267:   binary. This field is only for information purposes and does not affect
-268:   the compression algorithm in any manner.
-269: 
-270:     deflate() returns Z_OK if some progress has been made (more input
-271:   processed or more output produced), Z_STREAM_END if all input has been
-272:   consumed and all output has been produced (only when flush is set to
-273:   Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
-274:   if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
-275:   (for example avail_in or avail_out was zero).
-276: */
-277: 
-278: 
-279: ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
-280: /*
-281:      All dynamically allocated data structures for this stream are freed.
-282:    This function discards any unprocessed input and does not flush any
-283:    pending output.
-284: 
-285:      deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
-286:    stream state was inconsistent, Z_DATA_ERROR if the stream was freed
-287:    prematurely (some input or output was discarded). In the error case,
-288:    msg may be set but then points to a static string (which must not be
-289:    deallocated).
-290: */
-291: 
-292: 
-293: /* 
-294: ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
-295: 
-296:      Initializes the internal stream state for decompression. The fields
-297:    next_in, avail_in, zalloc, zfree and opaque must be initialized before by
-298:    the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
-299:    value depends on the compression method), inflateInit determines the
-300:    compression method from the zlib header and allocates all data structures
-301:    accordingly; otherwise the allocation will be deferred to the first call of
-302:    inflate.  If zalloc and zfree are set to Z_NULL, inflateInit updates them to
-303:    use default allocation functions.
-304: 
-305:      inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
-306:    memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
-307:    version assumed by the caller.  msg is set to null if there is no error
-308:    message. inflateInit does not perform any decompression apart from reading
-309:    the zlib header if present: this will be done by inflate().  (So next_in and
-310:    avail_in may be modified, but next_out and avail_out are unchanged.)
-311: */
-312: 
-313: 
-314: ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
-315: /*
-316:     inflate decompresses as much data as possible, and stops when the input
-317:   buffer becomes empty or the output buffer becomes full. It may some
-318:   introduce some output latency (reading input without producing any output)
-319:   except when forced to flush.
-320: 
-321:   The detailed semantics are as follows. inflate performs one or both of the
-322:   following actions:
-323: 
-324:   - Decompress more input starting at next_in and update next_in and avail_in
-325:     accordingly. If not all input can be processed (because there is not
-326:     enough room in the output buffer), next_in is updated and processing
-327:     will resume at this point for the next call of inflate().
-328: 
-329:   - Provide more output starting at next_out and update next_out and avail_out
-330:     accordingly.  inflate() provides as much output as possible, until there
-331:     is no more input data or no more space in the output buffer (see below
-332:     about the flush parameter).
-333: 
-334:   Before the call of inflate(), the application should ensure that at least
-335:   one of the actions is possible, by providing more input and/or consuming
-336:   more output, and updating the next_* and avail_* values accordingly.
-337:   The application can consume the uncompressed output when it wants, for
-338:   example when the output buffer is full (avail_out == 0), or after each
-339:   call of inflate(). If inflate returns Z_OK and with zero avail_out, it
-340:   must be called again after making room in the output buffer because there
-341:   might be more output pending.
-342: 
-343:     If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
-344:   output as possible to the output buffer. The flushing behavior of inflate is
-345:   not specified for values of the flush parameter other than Z_SYNC_FLUSH
-346:   and Z_FINISH, but the current implementation actually flushes as much output
-347:   as possible anyway.
-348: 
-349:     inflate() should normally be called until it returns Z_STREAM_END or an
-350:   error. However if all decompression is to be performed in a single step
-351:   (a single call of inflate), the parameter flush should be set to
-352:   Z_FINISH. In this case all pending input is processed and all pending
-353:   output is flushed; avail_out must be large enough to hold all the
-354:   uncompressed data. (The size of the uncompressed data may have been saved
-355:   by the compressor for this purpose.) The next operation on this stream must
-356:   be inflateEnd to deallocate the decompression state. The use of Z_FINISH
-357:   is never required, but can be used to inform inflate that a faster routine
-358:   may be used for the single inflate() call.
-359: 
-360:      If a preset dictionary is needed at this point (see inflateSetDictionary
-361:   below), inflate sets strm-adler to the adler32 checksum of the
-362:   dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise 
-363:   it sets strm->adler to the adler32 checksum of all output produced
-364:   so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
-365:   an error code as described below. At the end of the stream, inflate()
-366:   checks that its computed adler32 checksum is equal to that saved by the
-367:   compressor and returns Z_STREAM_END only if the checksum is correct.
-368: 
-369:     inflate() returns Z_OK if some progress has been made (more input processed
-370:   or more output produced), Z_STREAM_END if the end of the compressed data has
-371:   been reached and all uncompressed output has been produced, Z_NEED_DICT if a
-372:   preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
-373:   corrupted (input stream not conforming to the zlib format or incorrect
-374:   adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
-375:   (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
-376:   enough memory, Z_BUF_ERROR if no progress is possible or if there was not
-377:   enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
-378:   case, the application may then call inflateSync to look for a good
-379:   compression block.
-380: */
-381: 
-382: 
-383: ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
-384: /*
-385:      All dynamically allocated data structures for this stream are freed.
-386:    This function discards any unprocessed input and does not flush any
-387:    pending output.
-388: 
-389:      inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
-390:    was inconsistent. In the error case, msg may be set but then points to a
-391:    static string (which must not be deallocated).
-392: */
-393: 
-394:                         /* Advanced functions */
-395: 
-396: /*
-397:     The following functions are needed only in some special applications.
-398: */
-399: 
-400: /*   
-401: ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
-402:                                      int  level,
-403:                                      int  method,
-404:                                      int  windowBits,
-405:                                      int  memLevel,
-406:                                      int  strategy));
-407: 
-408:      This is another version of deflateInit with more compression options. The
-409:    fields next_in, zalloc, zfree and opaque must be initialized before by
-410:    the caller.
-411: 
-412:      The method parameter is the compression method. It must be Z_DEFLATED in
-413:    this version of the library.
-414: 
-415:      The windowBits parameter is the base two logarithm of the window size
-416:    (the size of the history buffer).  It should be in the range 8..15 for this
-417:    version of the library. Larger values of this parameter result in better
-418:    compression at the expense of memory usage. The default value is 15 if
-419:    deflateInit is used instead.
-420: 
-421:      The memLevel parameter specifies how much memory should be allocated
-422:    for the internal compression state. memLevel=1 uses minimum memory but
-423:    is slow and reduces compression ratio; memLevel=9 uses maximum memory
-424:    for optimal speed. The default value is 8. See zconf.h for total memory
-425:    usage as a function of windowBits and memLevel.
-426: 
-427:      The strategy parameter is used to tune the compression algorithm. Use the
-428:    value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
-429:    filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
-430:    string match).  Filtered data consists mostly of small values with a
-431:    somewhat random distribution. In this case, the compression algorithm is
-432:    tuned to compress them better. The effect of Z_FILTERED is to force more
-433:    Huffman coding and less string matching; it is somewhat intermediate
-434:    between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
-435:    the compression ratio but not the correctness of the compressed output even
-436:    if it is not set appropriately.
-437: 
-438:       deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
-439:    memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
-440:    method). msg is set to null if there is no error message.  deflateInit2 does
-441:    not perform any compression: this will be done by deflate().
-442: */
-443:                             
-444: ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
-445:                                              const Bytef *dictionary,
-446:                                              uInt  dictLength));
-447: /*
-448:      Initializes the compression dictionary from the given byte sequence
-449:    without producing any compressed output. This function must be called
-450:    immediately after deflateInit, deflateInit2 or deflateReset, before any
-451:    call of deflate. The compressor and decompressor must use exactly the same
-452:    dictionary (see inflateSetDictionary).
-453: 
-454:      The dictionary should consist of strings (byte sequences) that are likely
-455:    to be encountered later in the data to be compressed, with the most commonly
-456:    used strings preferably put towards the end of the dictionary. Using a
-457:    dictionary is most useful when the data to be compressed is short and can be
-458:    predicted with good accuracy; the data can then be compressed better than
-459:    with the default empty dictionary.
-460: 
-461:      Depending on the size of the compression data structures selected by
-462:    deflateInit or deflateInit2, a part of the dictionary may in effect be
-463:    discarded, for example if the dictionary is larger than the window size in
-464:    deflate or deflate2. Thus the strings most likely to be useful should be
-465:    put at the end of the dictionary, not at the front.
-466: 
-467:      Upon return of this function, strm->adler is set to the Adler32 value
-468:    of the dictionary; the decompressor may later use this value to determine
-469:    which dictionary has been used by the compressor. (The Adler32 value
-470:    applies to the whole dictionary even if only a subset of the dictionary is
-471:    actually used by the compressor.)
-472: 
-473:      deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
-474:    parameter is invalid (such as NULL dictionary) or the stream state is
-475:    inconsistent (for example if deflate has already been called for this stream
-476:    or if the compression method is bsort). deflateSetDictionary does not
-477:    perform any compression: this will be done by deflate().
-478: */
-479: 
-480: ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
-481:                                     z_streamp source));
-482: /*
-483:      Sets the destination stream as a complete copy of the source stream.
-484: 
-485:      This function can be useful when several compression strategies will be
-486:    tried, for example when there are several ways of pre-processing the input
-487:    data with a filter. The streams that will be discarded should then be freed
-488:    by calling deflateEnd.  Note that deflateCopy duplicates the internal
-489:    compression state which can be quite large, so this strategy is slow and
-490:    can consume lots of memory.
-491: 
-492:      deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
-493:    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
-494:    (such as zalloc being NULL). msg is left unchanged in both source and
-495:    destination.
-496: */
-497: 
-498: ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
-499: /*
-500:      This function is equivalent to deflateEnd followed by deflateInit,
-501:    but does not free and reallocate all the internal compression state.
-502:    The stream will keep the same compression level and any other attributes
-503:    that may have been set by deflateInit2.
-504: 
-505:       deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
-506:    stream state was inconsistent (such as zalloc or state being NULL).
-507: */
-508: 
-509: ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
-510: 				      int level,
-511: 				      int strategy));
-512: /*
-513:      Dynamically update the compression level and compression strategy.  The
-514:    interpretation of level and strategy is as in deflateInit2.  This can be
-515:    used to switch between compression and straight copy of the input data, or
-516:    to switch to a different kind of input data requiring a different
-517:    strategy. If the compression level is changed, the input available so far
-518:    is compressed with the old level (and may be flushed); the new level will
-519:    take effect only at the next call of deflate().
-520: 
-521:      Before the call of deflateParams, the stream state must be set as for
-522:    a call of deflate(), since the currently available input may have to
-523:    be compressed and flushed. In particular, strm->avail_out must be non-zero.
-524: 
-525:      deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
-526:    stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
-527:    if strm->avail_out was zero.
-528: */
-529: 
-530: /*   
-531: ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
-532:                                      int  windowBits));
-533: 
-534:      This is another version of inflateInit with an extra parameter. The
-535:    fields next_in, avail_in, zalloc, zfree and opaque must be initialized
-536:    before by the caller.
-537: 
-538:      The windowBits parameter is the base two logarithm of the maximum window
-539:    size (the size of the history buffer).  It should be in the range 8..15 for
-540:    this version of the library. The default value is 15 if inflateInit is used
-541:    instead. If a compressed stream with a larger window size is given as
-542:    input, inflate() will return with the error code Z_DATA_ERROR instead of
-543:    trying to allocate a larger window.
-544: 
-545:       inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
-546:    memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
-547:    memLevel). msg is set to null if there is no error message.  inflateInit2
-548:    does not perform any decompression apart from reading the zlib header if
-549:    present: this will be done by inflate(). (So next_in and avail_in may be
-550:    modified, but next_out and avail_out are unchanged.)
-551: */
-552: 
-553: ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
-554:                                              const Bytef *dictionary,
-555:                                              uInt  dictLength));
-556: /*
-557:      Initializes the decompression dictionary from the given uncompressed byte
-558:    sequence. This function must be called immediately after a call of inflate
-559:    if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
-560:    can be determined from the Adler32 value returned by this call of
-561:    inflate. The compressor and decompressor must use exactly the same
-562:    dictionary (see deflateSetDictionary).
-563: 
-564:      inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
-565:    parameter is invalid (such as NULL dictionary) or the stream state is
-566:    inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
-567:    expected one (incorrect Adler32 value). inflateSetDictionary does not
-568:    perform any decompression: this will be done by subsequent calls of
-569:    inflate().
-570: */
-571: 
-572: ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
-573: /* 
-574:     Skips invalid compressed data until a full flush point (see above the
-575:   description of deflate with Z_FULL_FLUSH) can be found, or until all
-576:   available input is skipped. No output is provided.
-577: 
-578:     inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
-579:   if no more input was provided, Z_DATA_ERROR if no flush point has been found,
-580:   or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
-581:   case, the application may save the current current value of total_in which
-582:   indicates where valid compressed data was found. In the error case, the
-583:   application may repeatedly call inflateSync, providing more input each time,
-584:   until success or end of the input data.
-585: */
-586: 
-587: ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
-588: /*
-589:      This function is equivalent to inflateEnd followed by inflateInit,
-590:    but does not free and reallocate all the internal decompression state.
-591:    The stream will keep attributes that may have been set by inflateInit2.
-592: 
-593:       inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
-594:    stream state was inconsistent (such as zalloc or state being NULL).
-595: */
-596: 
-597: 
-598:                         /* utility functions */
-599: 
-600: /*
-601:      The following utility functions are implemented on top of the
-602:    basic stream-oriented functions. To simplify the interface, some
-603:    default options are assumed (compression level and memory usage,
-604:    standard memory allocation functions). The source code of these
-605:    utility functions can easily be modified if you need special options.
-606: */
-607: 
-608: ZEXTERN int ZEXPORT compress OF((Bytef *dest,   uLongf *destLen,
-609:                                  const Bytef *source, uLong sourceLen));
-610: /*
-611:      Compresses the source buffer into the destination buffer.  sourceLen is
-612:    the byte length of the source buffer. Upon entry, destLen is the total
-613:    size of the destination buffer, which must be at least 0.1% larger than
-614:    sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
-615:    compressed buffer.
-616:      This function can be used to compress a whole file at once if the
-617:    input file is mmap'ed.
-618:      compress returns Z_OK if success, Z_MEM_ERROR if there was not
-619:    enough memory, Z_BUF_ERROR if there was not enough room in the output
-620:    buffer.
-621: */
-622: 
-623: ZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,
-624:                                   const Bytef *source, uLong sourceLen,
-625:                                   int level));
-626: /*
-627:      Compresses the source buffer into the destination buffer. The level
-628:    parameter has the same meaning as in deflateInit.  sourceLen is the byte
-629:    length of the source buffer. Upon entry, destLen is the total size of the
-630:    destination buffer, which must be at least 0.1% larger than sourceLen plus
-631:    12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
-632: 
-633:      compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
-634:    memory, Z_BUF_ERROR if there was not enough room in the output buffer,
-635:    Z_STREAM_ERROR if the level parameter is invalid.
-636: */
-637: 
-638: ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
-639:                                    const Bytef *source, uLong sourceLen));
-640: /*
-641:      Decompresses the source buffer into the destination buffer.  sourceLen is
-642:    the byte length of the source buffer. Upon entry, destLen is the total
-643:    size of the destination buffer, which must be large enough to hold the
-644:    entire uncompressed data. (The size of the uncompressed data must have
-645:    been saved previously by the compressor and transmitted to the decompressor
-646:    by some mechanism outside the scope of this compression library.)
-647:    Upon exit, destLen is the actual size of the compressed buffer.
-648:      This function can be used to decompress a whole file at once if the
-649:    input file is mmap'ed.
-650: 
-651:      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
-652:    enough memory, Z_BUF_ERROR if there was not enough room in the output
-653:    buffer, or Z_DATA_ERROR if the input data was corrupted.
-654: */
-655: 
-656: 
-657: typedef voidp gzFile;
-658: 
-659: ZEXTERN gzFile ZEXPORT gzopen  OF((const char *path, const char *mode));
-660: /*
-661:      Opens a gzip (.gz) file for reading or writing. The mode parameter
-662:    is as in fopen ("rb" or "wb") but can also include a compression level
-663:    ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
-664:    Huffman only compression as in "wb1h". (See the description
-665:    of deflateInit2 for more information about the strategy parameter.)
-666: 
-667:      gzopen can be used to read a file which is not in gzip format; in this
-668:    case gzread will directly read from the file without decompression.
-669: 
-670:      gzopen returns NULL if the file could not be opened or if there was
-671:    insufficient memory to allocate the (de)compression state; errno
-672:    can be checked to distinguish the two cases (if errno is zero, the
-673:    zlib error is Z_MEM_ERROR).  */
-674: 
-675: ZEXTERN gzFile ZEXPORT gzdopen  OF((int fd, const char *mode));
-676: /*
-677:      gzdopen() associates a gzFile with the file descriptor fd.  File
-678:    descriptors are obtained from calls like open, dup, creat, pipe or
-679:    fileno (in the file has been previously opened with fopen).
-680:    The mode parameter is as in gzopen.
-681:      The next call of gzclose on the returned gzFile will also close the
-682:    file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
-683:    descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
-684:      gzdopen returns NULL if there was insufficient memory to allocate
-685:    the (de)compression state.
-686: */
-687: 
-688: ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
-689: /*
-690:      Dynamically update the compression level or strategy. See the description
-691:    of deflateInit2 for the meaning of these parameters.
-692:      gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
-693:    opened for writing.
-694: */
-695: 
-696: ZEXTERN int ZEXPORT    gzread  OF((gzFile file, voidp buf, unsigned len));
-697: /*
-698:      Reads the given number of uncompressed bytes from the compressed file.
-699:    If the input file was not in gzip format, gzread copies the given number
-700:    of bytes into the buffer.
-701:      gzread returns the number of uncompressed bytes actually read (0 for
-702:    end of file, -1 for error). */
-703: 
-704: ZEXTERN int ZEXPORT    gzwrite OF((gzFile file, 
-705: 				   const voidp buf, unsigned len));
-706: /*
-707:      Writes the given number of uncompressed bytes into the compressed file.
-708:    gzwrite returns the number of uncompressed bytes actually written
-709:    (0 in case of error).
-710: */
-711: 
-712: ZEXTERN int ZEXPORTVA   gzprintf OF((gzFile file, const char *format, ...));
-713: /*
-714:      Converts, formats, and writes the args to the compressed file under
-715:    control of the format string, as in fprintf. gzprintf returns the number of
-716:    uncompressed bytes actually written (0 in case of error).
-717: */
-718: 
-719: ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
-720: /*
-721:       Writes the given null-terminated string to the compressed file, excluding
-722:    the terminating null character.
-723:       gzputs returns the number of characters written, or -1 in case of error.
-724: */
-725: 
-726: ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
-727: /*
-728:       Reads bytes from the compressed file until len-1 characters are read, or
-729:    a newline character is read and transferred to buf, or an end-of-file
-730:    condition is encountered.  The string is then terminated with a null
-731:    character.
-732:       gzgets returns buf, or Z_NULL in case of error.
-733: */
-734: 
-735: ZEXTERN int ZEXPORT    gzputc OF((gzFile file, int c));
-736: /*
-737:       Writes c, converted to an unsigned char, into the compressed file.
-738:    gzputc returns the value that was written, or -1 in case of error.
-739: */
-740: 
-741: ZEXTERN int ZEXPORT    gzgetc OF((gzFile file));
-742: /*
-743:       Reads one byte from the compressed file. gzgetc returns this byte
-744:    or -1 in case of end of file or error.
-745: */
-746: 
-747: ZEXTERN int ZEXPORT    gzflush OF((gzFile file, int flush));
-748: /*
-749:      Flushes all pending output into the compressed file. The parameter
-750:    flush is as in the deflate() function. The return value is the zlib
-751:    error number (see function gzerror below). gzflush returns Z_OK if
-752:    the flush parameter is Z_FINISH and all output could be flushed.
-753:      gzflush should be called only when strictly necessary because it can
-754:    degrade compression.
-755: */
-756: 
-757: ZEXTERN z_off_t ZEXPORT    gzseek OF((gzFile file,
-758: 				      z_off_t offset, int whence));
-759: /* 
-760:       Sets the starting position for the next gzread or gzwrite on the
-761:    given compressed file. The offset represents a number of bytes in the
-762:    uncompressed data stream. The whence parameter is defined as in lseek(2);
-763:    the value SEEK_END is not supported.
-764:      If the file is opened for reading, this function is emulated but can be
-765:    extremely slow. If the file is opened for writing, only forward seeks are
-766:    supported; gzseek then compresses a sequence of zeroes up to the new
-767:    starting position.
-768: 
-769:       gzseek returns the resulting offset location as measured in bytes from
-770:    the beginning of the uncompressed stream, or -1 in case of error, in
-771:    particular if the file is opened for writing and the new starting position
-772:    would be before the current position.
-773: */
-774: 
-775: ZEXTERN int ZEXPORT    gzrewind OF((gzFile file));
-776: /*
-777:      Rewinds the given file. This function is supported only for reading.
-778: 
-779:    gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
-780: */
-781: 
-782: ZEXTERN z_off_t ZEXPORT    gztell OF((gzFile file));
-783: /*
-784:      Returns the starting position for the next gzread or gzwrite on the
-785:    given compressed file. This position represents a number of bytes in the
-786:    uncompressed data stream.
-787: 
-788:    gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
-789: */
-790: 
-791: ZEXTERN int ZEXPORT gzeof OF((gzFile file));
-792: /*
-793:      Returns 1 when EOF has previously been detected reading the given
-794:    input stream, otherwise zero.
-795: */
-796: 
-797: ZEXTERN int ZEXPORT    gzclose OF((gzFile file));
-798: /*
-799:      Flushes all pending output if necessary, closes the compressed file
-800:    and deallocates all the (de)compression state. The return value is the zlib
-801:    error number (see function gzerror below).
-802: */
-803: 
-804: ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
-805: /*
-806:      Returns the error message for the last error which occurred on the
-807:    given compressed file. errnum is set to zlib error number. If an
-808:    error occurred in the file system and not in the compression library,
-809:    errnum is set to Z_ERRNO and the application may consult errno
-810:    to get the exact error code.
-811: */
-812: 
-813:                         /* checksum functions */
-814: 
-815: /*
-816:      These functions are not related to compression but are exported
-817:    anyway because they might be useful in applications using the
-818:    compression library.
-819: */
-820: 
-821: ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
-822: 
-823: /*
-824:      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
-825:    return the updated checksum. If buf is NULL, this function returns
-826:    the required initial value for the checksum.
-827:    An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
-828:    much faster. Usage example:
-829: 
-830:      uLong adler = adler32(0L, Z_NULL, 0);
-831: 
-832:      while (read_buffer(buffer, length) != EOF) {
-833:        adler = adler32(adler, buffer, length);
-834:      }
-835:      if (adler != original_adler) error();
-836: */
-837: 
-838: ZEXTERN uLong ZEXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));
-839: /*
-840:      Update a running crc with the bytes buf[0..len-1] and return the updated
-841:    crc. If buf is NULL, this function returns the required initial value
-842:    for the crc. Pre- and post-conditioning (one's complement) is performed
-843:    within this function so it shouldn't be done by the application.
-844:    Usage example:
-845: 
-846:      uLong crc = crc32(0L, Z_NULL, 0);
-847: 
-848:      while (read_buffer(buffer, length) != EOF) {
-849:        crc = crc32(crc, buffer, length);
-850:      }
-851:      if (crc != original_crc) error();
-852: */
-853: 
-854: 
-855:                         /* various hacks, don't look :) */
-856: 
-857: /* deflateInit and inflateInit are macros to allow checking the zlib version
-858:  * and the compiler's view of z_stream:
-859:  */
-860: ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
-861:                                      const char *version, int stream_size));
-862: ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
-863:                                      const char *version, int stream_size));
-864: ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int  level, int  method,
-865:                                       int windowBits, int memLevel,
-866:                                       int strategy, const char *version,
-867:                                       int stream_size));
-868: ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,
-869:                                       const char *version, int stream_size));
-870: #define deflateInit(strm, level) \
-871:         deflateInit_((strm), (level),       ZLIB_VERSION, sizeof(z_stream))
-872: #define inflateInit(strm) \
-873:         inflateInit_((strm),                ZLIB_VERSION, sizeof(z_stream))
-874: #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
-875:         deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
-876:                       (strategy),           ZLIB_VERSION, sizeof(z_stream))
-877: #define inflateInit2(strm, windowBits) \
-878:         inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
-879: 
-880: 
-881: #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
-882:     struct internal_state {int dummy;}; /* hack for buggy compilers */
-883: #endif
-884: 
-885: ZEXTERN const char   * ZEXPORT zError           OF((int err));
-886: ZEXTERN int            ZEXPORT inflateSyncPoint OF((z_streamp z));
-887: ZEXTERN const uLongf * ZEXPORT get_crc_table    OF((void));
-888: 
-889: #ifdef __cplusplus
-890: }
-891: #endif
-892: 
-893: #endif /* _ZLIB_H */
-      
-
- -

How the zlib wrapper was developed

- -

Attempt #1

-
-
-/* File : example.i */
-%module example
-%{
-/* Put headers and other declarations here */
-#include "zlib.h"
-%}
-
-%include typemaps.i
-
-%include "zlib.h"
-      
-
- - The result is: - -
-
-% swig -chicken -I/usr/include example.i
-/usr/include/zlib.h:63: Syntax error in input.
-/usr/include/zlib.h:78: Syntax error in input.
-/usr/include/zlib.h:80: Syntax error in input.
-      
-
- - The first problem we see is that the macro OF(...) is - not defined. - -

Attempt #2

- - We make sure to include zconf.h so that SWIG can see the - definition of OF(...). We try again. - -
-
-/* File : example.i */
-%module example
-%{
-/* Put headers and other declarations here */
-#include "zlib.h"
-%}
-
-%include typemaps.i
-
-%include "zconf.h"
-%include "zlib.h"
-      
-
- - The result is: - -
-
-% swig -chicken -I/usr/include example.i
-      
-
- - This seems to work! But we should take a peek inside the generated - example_wrap.c to see what the names of the Scheme - procedures will be. - -
-
-% grep C_intern example_wrap.c
-  C_word err = C_intern2 (&a, errorhook);
-    sym = C_intern (&a, 21, "example:max-mem-level");
-    sym = C_intern (&a, 17, "example:max-wbits");
-    sym = C_intern (&a, 16, "example:seek-set");
-    sym = C_intern (&a, 16, "example:seek-cur");
-    sym = C_intern (&a, 16, "example:seek-end");
-    sym = C_intern (&a, 20, "example:zlib-version");
-    sym = C_intern (&a, 28, "example:z-stream-next-in-set");
-    sym = C_intern (&a, 28, "example:z-stream-next-in-get");
-    sym = C_intern (&a, 29, "example:z-stream-avail-in-set");
-    sym = C_intern (&a, 29, "example:z-stream-avail-in-get");
-    sym = C_intern (&a, 29, "example:z-stream-total-in-set");
-    sym = C_intern (&a, 29, "example:z-stream-total-in-get");
-    sym = C_intern (&a, 29, "example:z-stream-next-out-set");
-    sym = C_intern (&a, 29, "example:z-stream-next-out-get");
-    sym = C_intern (&a, 30, "example:z-stream-avail-out-set");
-    sym = C_intern (&a, 30, "example:z-stream-avail-out-get");
-    sym = C_intern (&a, 30, "example:z-stream-total-out-set");
-    sym = C_intern (&a, 30, "example:z-stream-total-out-get");
-    sym = C_intern (&a, 24, "example:z-stream-msg-set");
-    sym = C_intern (&a, 24, "example:z-stream-msg-get");
-    sym = C_intern (&a, 26, "example:z-stream-state-set");
-    sym = C_intern (&a, 26, "example:z-stream-state-get");
-    sym = C_intern (&a, 27, "example:z-stream-zalloc-set");
-    sym = C_intern (&a, 27, "example:z-stream-zalloc-get");
-    sym = C_intern (&a, 26, "example:z-stream-zfree-set");
-    sym = C_intern (&a, 26, "example:z-stream-zfree-get");
-    sym = C_intern (&a, 27, "example:z-stream-opaque-set");
-    sym = C_intern (&a, 27, "example:z-stream-opaque-get");
-    sym = C_intern (&a, 30, "example:z-stream-data-type-set");
-    sym = C_intern (&a, 30, "example:z-stream-data-type-get");
-    sym = C_intern (&a, 26, "example:z-stream-adler-set");
-    sym = C_intern (&a, 26, "example:z-stream-adler-get");
-    sym = C_intern (&a, 29, "example:z-stream-reserved-set");
-    sym = C_intern (&a, 29, "example:z-stream-reserved-get");
-    sym = C_intern (&a, 20, "example:new-z-stream");
-    sym = C_intern (&a, 23, "example:delete-z-stream");
-    sym = C_intern (&a, 18, "example:z-no-flush");
-    sym = C_intern (&a, 23, "example:z-partial-flush");
-    sym = C_intern (&a, 20, "example:z-sync-flush");
-    sym = C_intern (&a, 20, "example:z-full-flush");
-    sym = C_intern (&a, 16, "example:z-finish");
-    sym = C_intern (&a, 12, "example:z-ok");
-    sym = C_intern (&a, 20, "example:z-stream-end");
-    sym = C_intern (&a, 19, "example:z-need-dict");
-    sym = C_intern (&a, 15, "example:z-errno");
-    sym = C_intern (&a, 22, "example:z-stream-error");
-    sym = C_intern (&a, 20, "example:z-data-error");
-    sym = C_intern (&a, 19, "example:z-mem-error");
-    sym = C_intern (&a, 19, "example:z-buf-error");
-    sym = C_intern (&a, 23, "example:z-version-error");
-    sym = C_intern (&a, 24, "example:z-no-compression");
-    sym = C_intern (&a, 20, "example:z-best-speed");
-    sym = C_intern (&a, 26, "example:z-best-compression");
-    sym = C_intern (&a, 29, "example:z-default-compression");
-    sym = C_intern (&a, 18, "example:z-filtered");
-    sym = C_intern (&a, 22, "example:z-huffman-only");
-    sym = C_intern (&a, 26, "example:z-default-strategy");
-    sym = C_intern (&a, 16, "example:z-binary");
-    sym = C_intern (&a, 15, "example:z-ascii");
-    sym = C_intern (&a, 17, "example:z-unknown");
-    sym = C_intern (&a, 18, "example:z-deflated");
-    sym = C_intern (&a, 14, "example:z-null");
-    sym = C_intern (&a, 19, "example:zlibversion");
-    sym = C_intern (&a, 15, "example:deflate");
-    sym = C_intern (&a, 18, "example:deflateend");
-    sym = C_intern (&a, 15, "example:inflate");
-    sym = C_intern (&a, 18, "example:inflateend");
-    sym = C_intern (&a, 28, "example:deflatesetdictionary");
-    sym = C_intern (&a, 19, "example:deflatecopy");
-    sym = C_intern (&a, 20, "example:deflatereset");
-    sym = C_intern (&a, 21, "example:deflateparams");
-    sym = C_intern (&a, 28, "example:inflatesetdictionary");
-    sym = C_intern (&a, 19, "example:inflatesync");
-    sym = C_intern (&a, 20, "example:inflatereset");
-    sym = C_intern (&a, 16, "example:compress");
-    sym = C_intern (&a, 17, "example:compress2");
-    sym = C_intern (&a, 18, "example:uncompress");
-    sym = C_intern (&a, 14, "example:gzopen");
-    sym = C_intern (&a, 15, "example:gzdopen");
-    sym = C_intern (&a, 19, "example:gzsetparams");
-    sym = C_intern (&a, 14, "example:gzread");
-    sym = C_intern (&a, 15, "example:gzwrite");
-    sym = C_intern (&a, 16, "example:gzprintf");
-    sym = C_intern (&a, 14, "example:gzputs");
-    sym = C_intern (&a, 14, "example:gzgets");
-    sym = C_intern (&a, 14, "example:gzputc");
-    sym = C_intern (&a, 14, "example:gzgetc");
-    sym = C_intern (&a, 15, "example:gzflush");
-    sym = C_intern (&a, 14, "example:gzseek");
-    sym = C_intern (&a, 16, "example:gzrewind");
-    sym = C_intern (&a, 14, "example:gztell");
-    sym = C_intern (&a, 13, "example:gzeof");
-    sym = C_intern (&a, 15, "example:gzclose");
-    sym = C_intern (&a, 15, "example:gzerror");
-    sym = C_intern (&a, 15, "example:adler32");
-    sym = C_intern (&a, 13, "example:crc32");
-    sym = C_intern (&a, 20, "example:deflateinit-");
-    sym = C_intern (&a, 20, "example:inflateinit-");
-    sym = C_intern (&a, 21, "example:deflateinit2-");
-    sym = C_intern (&a, 21, "example:inflateinit2-");
-    sym = C_intern (&a, 32, "example:internal-state-dummy-set");
-    sym = C_intern (&a, 32, "example:internal-state-dummy-get");
-    sym = C_intern (&a, 26, "example:new-internal-state");
-    sym = C_intern (&a, 29, "example:delete-internal-state");
-    sym = C_intern (&a, 14, "example:zerror");
-    sym = C_intern (&a, 24, "example:inflatesyncpoint");
-    sym = C_intern (&a, 21, "example:get-crc-table");
-      
-
- - In fact, we want the Scheme procedure names to begin with - zlib instead of example. For - example:zlib-version, we want - zlib-version. And we want dashes when the case - switches to/from upper/lowercase; ex. the function - deflateEnd() should be the Scheme procedure - zlib-deflate-end. - -

Attempt #3

- - We make sure to add -prefix zlib -mixed to the - swig command line, and we rename - ZLIB_VERSION to VERSION. We try again. - -
-
-/* File : example.i */
-%module example
-%{
-/* Put headers and other declarations here */
-#include "zlib.h"
-%}
-
-%include typemaps.i
-
-%rename(VERSION) ZLIB_VERSION;
-
-%include "zconf.h"
-%include "zlib.h"
-      
-
- - The result is: - -
-
-% swig -chicken -prefix zlib -mixed -I/usr/include example.i
-% grep C_intern example_wrap.c
-  C_word err = C_intern2 (&a, errorhook);
-    sym = C_intern (&a, 18, "zlib:max-mem-level");
-    sym = C_intern (&a, 14, "zlib:max-wbits");
-    sym = C_intern (&a, 13, "zlib:seek-set");
-    sym = C_intern (&a, 13, "zlib:seek-cur");
-    sym = C_intern (&a, 13, "zlib:seek-end");
-    sym = C_intern (&a, 12, "zlib:version");
-    sym = C_intern (&a, 25, "zlib:z-stream-next-in-set");
-    sym = C_intern (&a, 25, "zlib:z-stream-next-in-get");
-    sym = C_intern (&a, 26, "zlib:z-stream-avail-in-set");
-    sym = C_intern (&a, 26, "zlib:z-stream-avail-in-get");
-    sym = C_intern (&a, 26, "zlib:z-stream-total-in-set");
-    sym = C_intern (&a, 26, "zlib:z-stream-total-in-get");
-    sym = C_intern (&a, 26, "zlib:z-stream-next-out-set");
-    sym = C_intern (&a, 26, "zlib:z-stream-next-out-get");
-    sym = C_intern (&a, 27, "zlib:z-stream-avail-out-set");
-    sym = C_intern (&a, 27, "zlib:z-stream-avail-out-get");
-    sym = C_intern (&a, 27, "zlib:z-stream-total-out-set");
-    sym = C_intern (&a, 27, "zlib:z-stream-total-out-get");
-    sym = C_intern (&a, 21, "zlib:z-stream-msg-set");
-    sym = C_intern (&a, 21, "zlib:z-stream-msg-get");
-    sym = C_intern (&a, 23, "zlib:z-stream-state-set");
-    sym = C_intern (&a, 23, "zlib:z-stream-state-get");
-    sym = C_intern (&a, 24, "zlib:z-stream-zalloc-set");
-    sym = C_intern (&a, 24, "zlib:z-stream-zalloc-get");
-    sym = C_intern (&a, 23, "zlib:z-stream-zfree-set");
-    sym = C_intern (&a, 23, "zlib:z-stream-zfree-get");
-    sym = C_intern (&a, 24, "zlib:z-stream-opaque-set");
-    sym = C_intern (&a, 24, "zlib:z-stream-opaque-get");
-    sym = C_intern (&a, 27, "zlib:z-stream-data-type-set");
-    sym = C_intern (&a, 27, "zlib:z-stream-data-type-get");
-    sym = C_intern (&a, 23, "zlib:z-stream-adler-set");
-    sym = C_intern (&a, 23, "zlib:z-stream-adler-get");
-    sym = C_intern (&a, 26, "zlib:z-stream-reserved-set");
-    sym = C_intern (&a, 26, "zlib:z-stream-reserved-get");
-    sym = C_intern (&a, 17, "zlib:new-z-stream");
-    sym = C_intern (&a, 20, "zlib:delete-z-stream");
-    sym = C_intern (&a, 15, "zlib:z-no-flush");
-    sym = C_intern (&a, 20, "zlib:z-partial-flush");
-    sym = C_intern (&a, 17, "zlib:z-sync-flush");
-    sym = C_intern (&a, 17, "zlib:z-full-flush");
-    sym = C_intern (&a, 13, "zlib:z-finish");
-    sym = C_intern (&a, 9, "zlib:z-ok");
-    sym = C_intern (&a, 17, "zlib:z-stream-end");
-    sym = C_intern (&a, 16, "zlib:z-need-dict");
-    sym = C_intern (&a, 12, "zlib:z-errno");
-    sym = C_intern (&a, 19, "zlib:z-stream-error");
-    sym = C_intern (&a, 17, "zlib:z-data-error");
-    sym = C_intern (&a, 16, "zlib:z-mem-error");
-    sym = C_intern (&a, 16, "zlib:z-buf-error");
-    sym = C_intern (&a, 20, "zlib:z-version-error");
-    sym = C_intern (&a, 21, "zlib:z-no-compression");
-    sym = C_intern (&a, 17, "zlib:z-best-speed");
-    sym = C_intern (&a, 23, "zlib:z-best-compression");
-    sym = C_intern (&a, 26, "zlib:z-default-compression");
-    sym = C_intern (&a, 15, "zlib:z-filtered");
-    sym = C_intern (&a, 19, "zlib:z-huffman-only");
-    sym = C_intern (&a, 23, "zlib:z-default-strategy");
-    sym = C_intern (&a, 13, "zlib:z-binary");
-    sym = C_intern (&a, 12, "zlib:z-ascii");
-    sym = C_intern (&a, 14, "zlib:z-unknown");
-    sym = C_intern (&a, 15, "zlib:z-deflated");
-    sym = C_intern (&a, 11, "zlib:z-null");
-    sym = C_intern (&a, 17, "zlib:zlib-version");
-    sym = C_intern (&a, 12, "zlib:deflate");
-    sym = C_intern (&a, 16, "zlib:deflate-end");
-    sym = C_intern (&a, 12, "zlib:inflate");
-    sym = C_intern (&a, 16, "zlib:inflate-end");
-    sym = C_intern (&a, 27, "zlib:deflate-set-dictionary");
-    sym = C_intern (&a, 17, "zlib:deflate-copy");
-    sym = C_intern (&a, 18, "zlib:deflate-reset");
-    sym = C_intern (&a, 19, "zlib:deflate-params");
-    sym = C_intern (&a, 27, "zlib:inflate-set-dictionary");
-    sym = C_intern (&a, 17, "zlib:inflate-sync");
-    sym = C_intern (&a, 18, "zlib:inflate-reset");
-    sym = C_intern (&a, 13, "zlib:compress");
-    sym = C_intern (&a, 14, "zlib:compress2");
-    sym = C_intern (&a, 15, "zlib:uncompress");
-    sym = C_intern (&a, 11, "zlib:gzopen");
-    sym = C_intern (&a, 12, "zlib:gzdopen");
-    sym = C_intern (&a, 16, "zlib:gzsetparams");
-    sym = C_intern (&a, 11, "zlib:gzread");
-    sym = C_intern (&a, 12, "zlib:gzwrite");
-    sym = C_intern (&a, 13, "zlib:gzprintf");
-    sym = C_intern (&a, 11, "zlib:gzputs");
-    sym = C_intern (&a, 11, "zlib:gzgets");
-    sym = C_intern (&a, 11, "zlib:gzputc");
-    sym = C_intern (&a, 11, "zlib:gzgetc");
-    sym = C_intern (&a, 12, "zlib:gzflush");
-    sym = C_intern (&a, 11, "zlib:gzseek");
-    sym = C_intern (&a, 13, "zlib:gzrewind");
-    sym = C_intern (&a, 11, "zlib:gztell");
-    sym = C_intern (&a, 10, "zlib:gzeof");
-    sym = C_intern (&a, 12, "zlib:gzclose");
-    sym = C_intern (&a, 12, "zlib:gzerror");
-    sym = C_intern (&a, 12, "zlib:adler32");
-    sym = C_intern (&a, 10, "zlib:crc32");
-    sym = C_intern (&a, 18, "zlib:deflate-init-");
-    sym = C_intern (&a, 18, "zlib:inflate-init-");
-    sym = C_intern (&a, 19, "zlib:deflate-init2-");
-    sym = C_intern (&a, 19, "zlib:inflate-init2-");
-    sym = C_intern (&a, 29, "zlib:internal-state-dummy-set");
-    sym = C_intern (&a, 29, "zlib:internal-state-dummy-get");
-    sym = C_intern (&a, 23, "zlib:new-internal-state");
-    sym = C_intern (&a, 26, "zlib:delete-internal-state");
-    sym = C_intern (&a, 12, "zlib:ze-rror");
-    sym = C_intern (&a, 23, "zlib:inflate-sync-point");
-    sym = C_intern (&a, 18, "zlib:get-crc-table");
-      
-
- - Much better. The only problem is the identifier - zlib:ze-rror, and we are missing - zlib:deflate-init and zlib:inflate-init - because they are defined as macros (see macro definitions). - -

Attempt #4

- - We make sure to rename zError to - z_error, and we inline some helper functions for the - zlib:...-init macros. We try again. - -
-
-/* File : example.i */
-%module example
-%{
-/* Put headers and other declarations here */
-#include "zlib.h"
-%}
-
-%include typemaps.i
-
-%rename(VERSION) ZLIB_VERSION;
-%rename(z_error) zError;
-
-%include "zconf.h"
-%include "zlib.h"
-
-%inline %{
-/* %inline blocks are seen by SWIG and are inserted into the header
-   portion of example_wrap.c, so that they are also seen by the C
-   compiler. */
-int deflate_init(z_streamp strm, int level) {
-  return deflateInit(strm,level); /* call macro */
-}
-int inflate_init(z_streamp strm) {
-  return inflateInit(strm); /* call macro */
-}
-%}
-
-
-      
-
- - The result is: - -
-
-% swig -chicken -prefix zlib -mixed -I/usr/include example.i
-% grep C_intern example_wrap.c
-  C_word err = C_intern2 (&a, errorhook);
-    sym = C_intern (&a, 18, "zlib:max-mem-level");
-    sym = C_intern (&a, 14, "zlib:max-wbits");
-    sym = C_intern (&a, 13, "zlib:seek-set");
-    sym = C_intern (&a, 13, "zlib:seek-cur");
-    sym = C_intern (&a, 13, "zlib:seek-end");
-    sym = C_intern (&a, 12, "zlib:version");
-    sym = C_intern (&a, 25, "zlib:z-stream-next-in-set");
-    sym = C_intern (&a, 25, "zlib:z-stream-next-in-get");
-    sym = C_intern (&a, 26, "zlib:z-stream-avail-in-set");
-    sym = C_intern (&a, 26, "zlib:z-stream-avail-in-get");
-    sym = C_intern (&a, 26, "zlib:z-stream-total-in-set");
-    sym = C_intern (&a, 26, "zlib:z-stream-total-in-get");
-    sym = C_intern (&a, 26, "zlib:z-stream-next-out-set");
-    sym = C_intern (&a, 26, "zlib:z-stream-next-out-get");
-    sym = C_intern (&a, 27, "zlib:z-stream-avail-out-set");
-    sym = C_intern (&a, 27, "zlib:z-stream-avail-out-get");
-    sym = C_intern (&a, 27, "zlib:z-stream-total-out-set");
-    sym = C_intern (&a, 27, "zlib:z-stream-total-out-get");
-    sym = C_intern (&a, 21, "zlib:z-stream-msg-set");
-    sym = C_intern (&a, 21, "zlib:z-stream-msg-get");
-    sym = C_intern (&a, 23, "zlib:z-stream-state-set");
-    sym = C_intern (&a, 23, "zlib:z-stream-state-get");
-    sym = C_intern (&a, 24, "zlib:z-stream-zalloc-set");
-    sym = C_intern (&a, 24, "zlib:z-stream-zalloc-get");
-    sym = C_intern (&a, 23, "zlib:z-stream-zfree-set");
-    sym = C_intern (&a, 23, "zlib:z-stream-zfree-get");
-    sym = C_intern (&a, 24, "zlib:z-stream-opaque-set");
-    sym = C_intern (&a, 24, "zlib:z-stream-opaque-get");
-    sym = C_intern (&a, 27, "zlib:z-stream-data-type-set");
-    sym = C_intern (&a, 27, "zlib:z-stream-data-type-get");
-    sym = C_intern (&a, 23, "zlib:z-stream-adler-set");
-    sym = C_intern (&a, 23, "zlib:z-stream-adler-get");
-    sym = C_intern (&a, 26, "zlib:z-stream-reserved-set");
-    sym = C_intern (&a, 26, "zlib:z-stream-reserved-get");
-    sym = C_intern (&a, 17, "zlib:new-z-stream");
-    sym = C_intern (&a, 20, "zlib:delete-z-stream");
-    sym = C_intern (&a, 15, "zlib:z-no-flush");
-    sym = C_intern (&a, 20, "zlib:z-partial-flush");
-    sym = C_intern (&a, 17, "zlib:z-sync-flush");
-    sym = C_intern (&a, 17, "zlib:z-full-flush");
-    sym = C_intern (&a, 13, "zlib:z-finish");
-    sym = C_intern (&a, 9, "zlib:z-ok");
-    sym = C_intern (&a, 17, "zlib:z-stream-end");
-    sym = C_intern (&a, 16, "zlib:z-need-dict");
-    sym = C_intern (&a, 12, "zlib:z-errno");
-    sym = C_intern (&a, 19, "zlib:z-stream-error");
-    sym = C_intern (&a, 17, "zlib:z-data-error");
-    sym = C_intern (&a, 16, "zlib:z-mem-error");
-    sym = C_intern (&a, 16, "zlib:z-buf-error");
-    sym = C_intern (&a, 20, "zlib:z-version-error");
-    sym = C_intern (&a, 21, "zlib:z-no-compression");
-    sym = C_intern (&a, 17, "zlib:z-best-speed");
-    sym = C_intern (&a, 23, "zlib:z-best-compression");
-    sym = C_intern (&a, 26, "zlib:z-default-compression");
-    sym = C_intern (&a, 15, "zlib:z-filtered");
-    sym = C_intern (&a, 19, "zlib:z-huffman-only");
-    sym = C_intern (&a, 23, "zlib:z-default-strategy");
-    sym = C_intern (&a, 13, "zlib:z-binary");
-    sym = C_intern (&a, 12, "zlib:z-ascii");
-    sym = C_intern (&a, 14, "zlib:z-unknown");
-    sym = C_intern (&a, 15, "zlib:z-deflated");
-    sym = C_intern (&a, 11, "zlib:z-null");
-    sym = C_intern (&a, 17, "zlib:zlib-version");
-    sym = C_intern (&a, 12, "zlib:deflate");
-    sym = C_intern (&a, 16, "zlib:deflate-end");
-    sym = C_intern (&a, 12, "zlib:inflate");
-    sym = C_intern (&a, 16, "zlib:inflate-end");
-    sym = C_intern (&a, 27, "zlib:deflate-set-dictionary");
-    sym = C_intern (&a, 17, "zlib:deflate-copy");
-    sym = C_intern (&a, 18, "zlib:deflate-reset");
-    sym = C_intern (&a, 19, "zlib:deflate-params");
-    sym = C_intern (&a, 27, "zlib:inflate-set-dictionary");
-    sym = C_intern (&a, 17, "zlib:inflate-sync");
-    sym = C_intern (&a, 18, "zlib:inflate-reset");
-    sym = C_intern (&a, 13, "zlib:compress");
-    sym = C_intern (&a, 14, "zlib:compress2");
-    sym = C_intern (&a, 15, "zlib:uncompress");
-    sym = C_intern (&a, 11, "zlib:gzopen");
-    sym = C_intern (&a, 12, "zlib:gzdopen");
-    sym = C_intern (&a, 16, "zlib:gzsetparams");
-    sym = C_intern (&a, 11, "zlib:gzread");
-    sym = C_intern (&a, 12, "zlib:gzwrite");
-    sym = C_intern (&a, 13, "zlib:gzprintf");
-    sym = C_intern (&a, 11, "zlib:gzputs");
-    sym = C_intern (&a, 11, "zlib:gzgets");
-    sym = C_intern (&a, 11, "zlib:gzputc");
-    sym = C_intern (&a, 11, "zlib:gzgetc");
-    sym = C_intern (&a, 12, "zlib:gzflush");
-    sym = C_intern (&a, 11, "zlib:gzseek");
-    sym = C_intern (&a, 13, "zlib:gzrewind");
-    sym = C_intern (&a, 11, "zlib:gztell");
-    sym = C_intern (&a, 10, "zlib:gzeof");
-    sym = C_intern (&a, 12, "zlib:gzclose");
-    sym = C_intern (&a, 12, "zlib:gzerror");
-    sym = C_intern (&a, 12, "zlib:adler32");
-    sym = C_intern (&a, 10, "zlib:crc32");
-    sym = C_intern (&a, 18, "zlib:deflate-init-");
-    sym = C_intern (&a, 18, "zlib:inflate-init-");
-    sym = C_intern (&a, 19, "zlib:deflate-init2-");
-    sym = C_intern (&a, 19, "zlib:inflate-init2-");
-    sym = C_intern (&a, 29, "zlib:internal-state-dummy-set");
-    sym = C_intern (&a, 29, "zlib:internal-state-dummy-get");
-    sym = C_intern (&a, 23, "zlib:new-internal-state");
-    sym = C_intern (&a, 26, "zlib:delete-internal-state");
-    sym = C_intern (&a, 12, "zlib:z-error");
-    sym = C_intern (&a, 23, "zlib:inflate-sync-point");
-    sym = C_intern (&a, 18, "zlib:get-crc-table");
-    sym = C_intern (&a, 17, "zlib:deflate-init");
-    sym = C_intern (&a, 17, "zlib:inflate-init");
-      
-
- - Perfect! Now let's integrate this zlib extension into a - CHICKEN interpreter. To save some time, in this - Examples/chicken/zlib directory: -
    -
  1. Backup the original example.i.
  2. -
  3. Copy and paste the example.i text from above and - put it into the file called example.i
  4. -
  5. Run 'make' as per Building the - example.
  6. -
  7. Run the resultant executable zlib.
  8. -
- - The interpreter interaction is as follows: - -
-
-% ./zlib
-zlib
-
-  A SWIG example for the CHICKEN compiler
-  Author: Jonah Beckford, February 2003
-
-Scheme Procedures:
-
-zlib:max-mem-level
-zlib:max-wbits
-zlib:seek-set
-zlib:seek-cur
-zlib:seek-end
-zlib:version
-zlib:z-stream-next-in-set
-zlib:z-stream-next-in-get
-zlib:z-stream-avail-in-set
-...
-zlib:get-crc-table
-zlib:deflate-init
-zlib:inflate-init
-; This is the CHICKEN interpreter - Version 0, Build 1095 - windows-cygwin-x86
-; (c)2000-2003 Felix L. Winkelmann
->>> (define s (zlib:new-z-stream))
->>> s
-#<tagged pointer #<c++ "z_stream *">(#<pointer 6d9290>)>
->>> (zlib:z-stream-next-in-get s)
-#f
->>> (zlib:z-stream-next-in-set s "some dummy stream data")
-Error: Type error. Expected _p_Bytef: "bad argument type"
->>> (exit)
-      
-
- - Apparently we cannot use Scheme strings as Bytef *. The SWIG - manual shows many ways how to handle strings and byte arrays, but - to be simplistic, let's just make the Bytef * look - like a char *, which is automatically handled as a - string by SWIG CHICKEN. - -

Attempt #5

- - We make sure to add an %apply construct so that Bytef - * is handled the same as char * to SWIG. We - try again. - -
-
-/* File : example.i */
-%module example
-%{
-/* Put headers and other declarations here */
-#include "zlib.h"
-%}
-
-%include typemaps.i
-
-%rename(VERSION) ZLIB_VERSION;
-%rename(z_error) zError;
-%apply char * { Bytef * };
-
-%include "zconf.h"
-%include "zlib.h"
-
-%inline %{
-/* %inline blocks are seen by SWIG and are inserted into the header
-   portion of example_wrap.c, so that they are also seen by the C
-   compiler. */
-int deflate_init(z_streamp strm, int level) {
-  return deflateInit(strm,level); /* call macro */
-}
-int inflate_init(z_streamp strm) {
-  return inflateInit(strm); /* call macro */
-}
-%}
-      
-
- - Build the example once more.
- - The interpreter interaction is as follows: - -
-
-% ./zlib
-zlib
-
-  A SWIG example for the CHICKEN compiler
-  Author: Jonah Beckford, February 2003
-
-Scheme Procedures:
-
-zlib:max-mem-level
-zlib:max-wbits
-zlib:seek-set
-zlib:seek-cur
-zlib:seek-end
-zlib:version
-zlib:z-stream-next-in-set
-zlib:z-stream-next-in-get
-zlib:z-stream-avail-in-set
-...
-zlib:get-crc-table
-zlib:deflate-init
-zlib:inflate-init
-; This is the CHICKEN interpreter - Version 0, Build 1095 - windows-cygwin-x86
-; (c)2000-2003 Felix L. Winkelmann
->>> (define s (zlib:new-z-stream))
-Init zstream
->>> (zlib:z-stream-zalloc-set s #f) 
->>> (zlib:z-stream-zfree-set s #f)
->>> (zlib:z-stream-opaque-set s #f)
->>> (zlib:deflate-init s (zlib:z-default-compression))
-0
-Deflate something small so we don't need to loop/stream data
->>> (define in "some dummy data")
->>> (define out (make-string 1000))
->>> (zlib:z-stream-next-in-set s in)
->>> (zlib:z-stream-avail-in-set s (string-length in))
->>> (zlib:z-stream-next-out-set s out)
->>> (zlib:z-stream-avail-out-set s (string-length out))
->>> (zlib:deflate s (zlib:z-finish))
-1 ;; (zlib:z-stream-end) == 1, which is good
->>> (zlib:z-stream-total-out-get s)
-23.
->>> out
-"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        "
-      
-
- - We see the problem ... the compression is occurring as it should, - but we cannot see any of the compressed output. This is because - when SWIG CHICKEN passes a Scheme string to a C function, it - duplicates the string before calling the C function. We want to - save the memory address that - zlib:z-stream-next-out-set is using, so we can - display this later. While we are at it, we can foresee that - compress, compress2 and - uncompress will all need some finessing to work with - mutating strings. - -

Attempt #6

- - When we have to finesse strings, we must use typemaps. As well, - we define some functions to save and restore the - next_out element. We try again. - -
-
-/* File : example.i */
-%module example
-%{
-/* Put headers and other declarations here */
-#include "zlib.h"
-%}
-
-%include typemaps.i
-
-%rename(VERSION) ZLIB_VERSION;
-%rename(z_error) zError;
-%apply char * { Bytef * };
-	
-/* Allow the sourceLen to be automatically filled in from the length
-   of the 'source' string */
-%typemap(in) (const Bytef *source, uLong sourceLen)
-%{  if (!C_swig_is_string ($input)) {
-    swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument $input is not a string");
-  }
-  $2 = (uLong) C_header_size ($input);
-  $1 = C_c_string ($input);
-%}
-
-/* Allocate space the size of which is determined by the Scheme
-   integer argument, and make a temporary integer so we can set
-   destLen. */
-%typemap(in) (Bytef *dest, uLongf *destLen) (uLong len)
-%{  if (!C_swig_is_fixnum ($input)) {
-    swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument $input is not a integer");
-  }
-  len = (uLong) C_unfix ($input);
-  $2 = &len;
-  $1 = (char *) malloc (*$2);
-%}
-
-/* Return the mutated string as a new object. */
-%typemap(argout) (Bytef *dest, uLongf *destLen) 
-(C_word *scmstr) 
-%{  scmstr = C_alloc (C_SIZEOF_STRING (*$2));
-  SWIG_APPEND_VALUE(C_string (&scmstr, *$2, $1));
-  free ($1);
-%}
-	
-%include "zconf.h"
-%include "zlib.h"
-	
-/* Ignore destLen as an input argument, and make a temporary integer so
-   we can set destLen. */
-%typemap(in, numinputs=0) uLongf *destLen (uLong len)
-"$1 = &len;";
-
-/* Return a sized string as a new object. */
-%typemap(argout)
-(void *outstr, uLongf *destLen) (C_word *scmstr) 
-%{  scmstr = C_alloc (C_SIZEOF_STRING (*$2));
-  SWIG_APPEND_VALUE(C_string (&scmstr, *$2, $1));
-%}
-	
-%inline %{
-/* %inline blocks are seen by SWIG and are inserted into the header
-   portion of example_wrap.c, so that they are also seen by the C
-   compiler. */
-int deflate_init(z_streamp strm, int level) {
-  return deflateInit(strm,level); /* call macro */
-}
-int inflate_init(z_streamp strm) {
-  return inflateInit(strm); /* call macro */
-}
-void* z_stream_save_next_out(z_streamp strm) {
-  return (void*) strm->next_out;
-}
-void z_stream_get_next_chunk(z_streamp strm, void *outstr, uLongf *destLen) {
-  *destLen = strm->next_out - (Bytef*)outstr;
-}
-%}
-      
-
- - And that's it. Try building the entire example from the - Makefile. Run ./zlib test-zlib.scm to test it out. - - - diff --git a/Examples/chicken/zlib/example.i b/Examples/chicken/zlib/example.i deleted file mode 100644 index dd962ad56..000000000 --- a/Examples/chicken/zlib/example.i +++ /dev/null @@ -1,76 +0,0 @@ -/* File : example.i */ -%module example -%{ -/* Put headers and other declarations here */ -#include "zlib.h" -%} - -%include typemaps.i - -%rename(VERSION) ZLIB_VERSION; -%rename(z_error) zError; -%apply char * { Bytef * }; - -/* Allow the sourceLen to be automatically filled in from the length - of the 'source' string */ -%typemap(in) (const Bytef *source, uLong sourceLen) -%{ if (!C_swig_is_string ($input)) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument $input is not a string"); - } - $2 = (uLong) C_header_size ($input); - $1 = C_c_string ($input); -%} - -/* Allocate space the size of which is determined by the Scheme - integer argument, and make a temporary integer so we can set - destLen. */ -%typemap(in) (Bytef *dest, uLongf *destLen) (uLong len) -%{ if (!C_swig_is_fixnum ($input)) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument $input is not a integer"); - } - len = (uLong) C_unfix ($input); - $2 = &len; - $1 = (char *) malloc (*$2); -%} - -/* Return the mutated string as a new object. */ -%typemap(argout) (Bytef *dest, uLongf *destLen) -(C_word *scmstr) -%{ scmstr = C_alloc (C_SIZEOF_STRING (*$2)); - SWIG_APPEND_VALUE(C_string (&scmstr, *$2, $1)); - free ($1); -%} - -%include "zconf.h" -%include "zlib.h" - -/* Ignore destLen as an input argument, and make a temporary integer so - we can set destLen. */ -%typemap(numinputs=0) uLongf *destLen (uLong len) -"$1 = &len;"; - -/* Return a sized string as a new object. */ -%typemap(argout) -(void *outstr, uLongf *destLen) (C_word *scmstr) -%{ scmstr = C_alloc (C_SIZEOF_STRING (*$2)); - SWIG_APPEND_VALUE(C_string (&scmstr, *$2, $1)); -%} - -%inline %{ -/* %inline blocks are seen by SWIG and are inserted into the header - portion of example_wrap.c, so that they are also seen by the C - compiler. */ -int deflate_init(z_streamp strm, int level) { - return deflateInit(strm,level); /* call macro */ -} -int inflate_init(z_streamp strm) { - return inflateInit(strm); /* call macro */ -} -void* z_stream_save_next_out(z_streamp strm) { - return (void*) strm->next_out; -} -void z_stream_get_next_chunk(z_streamp strm, void *outstr, uLongf *destLen) { - *destLen = strm->next_out - (Bytef*)outstr; -} -%} - diff --git a/Examples/chicken/zlib/test-zlib.scm b/Examples/chicken/zlib/test-zlib.scm deleted file mode 100644 index a13d801b8..000000000 --- a/Examples/chicken/zlib/test-zlib.scm +++ /dev/null @@ -1,41 +0,0 @@ -(load-library 'example "./zlib.so") - -;; Init zstream -(define s (new-z-stream)) -(z-stream-zalloc-set s #f) -(z-stream-zfree-set s #f) -(z-stream-opaque-set s #f) -(deflate-init s (Z-DEFAULT-COMPRESSION)) - -;; Deflate something small so we don't need to loop/stream data -(define in "some pony et jumping et jack et flash et had a jack pony") -(define out (make-string 1000)) -(printf "to be compressed: ~A~%to be compressed bytes: ~A~%~%" in (string-length in)) -(z-stream-next-in-set s in) -(z-stream-avail-in-set s (string-length in)) -(z-stream-next-out-set s out) -(z-stream-avail-out-set s (string-length out)) -(let* - ((saved-out (z-stream-save-next-out s)) - (ret (deflate s (Z-FINISH)))) - (cond - ((= ret (Z-STREAM-END)) - (printf "deflated properly!~%compressed bytes: ~A~%compressed stream: ~A~%" - (z-stream-total-out-get s) (z-stream-get-next-chunk s saved-out))) - ((= ret (Z-OK)) - (display "only partial deflation ... not enough output space\n")) - (else - (printf "deflate error(~D): ~A ~%" ret (z-stream-msg-get s))))) - -;; Use simple compress routine, and set max output size to 100 -(newline) -(call-with-values (lambda () (compress 100 in)) - (lambda (ret compressed) - (cond - ((= ret (Z-OK)) - (printf "compressed properly!~%compressed bytes: ~A~%compressed stream: ~A~%" - (string-length compressed) compressed)) - (else - (printf "compress error(~D): ~A ~%" ret (z-error ret)))))) - -(exit 0) diff --git a/Examples/guile/check.list b/Examples/guile/check.list index d35b2d693..7ccd0730a 100644 --- a/Examples/guile/check.list +++ b/Examples/guile/check.list @@ -1,6 +1,5 @@ # see top-level Makefile.in constants -matrix simple port multimap diff --git a/Examples/lua/lua.c b/Examples/lua/lua.c index e06e2c5fc..8cffaa503 100644 --- a/Examples/lua/lua.c +++ b/Examples/lua/lua.c @@ -1,5 +1,4 @@ /* -** $Id$ ** Lua stand-alone interpreter ** See Copyright Notice in lua.h */ diff --git a/Examples/test-suite/csharp/li_std_map_runme.cs b/Examples/test-suite/csharp/li_std_map_runme.cs index 685b20e47..ef5314dc7 100644 --- a/Examples/test-suite/csharp/li_std_map_runme.cs +++ b/Examples/test-suite/csharp/li_std_map_runme.cs @@ -1,12 +1,7 @@ /* ----------------------------------------------------------------------------- - * 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. - * * li_std_map_runme.cs * * SWIG C# tester for std_map.i - * Implementation by Yuval Baror (http://yuval.bar-or.org) - * * This class tests all the functionality of the std_map.i wrapper. * Upon successful testing, the main function doesn't print out anything. * If any error is found - it will be printed on the screen. diff --git a/Examples/test-suite/li_std_queue.i b/Examples/test-suite/li_std_queue.i index 2d322b4d9..6bf71afca 100644 --- a/Examples/test-suite/li_std_queue.i +++ b/Examples/test-suite/li_std_queue.i @@ -1,13 +1,4 @@ -/** - * @file std_queue.i - * @author gga - * @date Sun May 6 01:52:44 2007 - * - * @brief test of std::queue - * - * - */ - +// test of std::queue %module li_std_queue %include std_queue.i diff --git a/Examples/test-suite/li_std_set.i b/Examples/test-suite/li_std_set.i index 8c335b24c..2dcc2f17c 100644 --- a/Examples/test-suite/li_std_set.i +++ b/Examples/test-suite/li_std_set.i @@ -1,18 +1,12 @@ -/** - * @file li_std_set.i - * @author gga - * @date Tue May 1 02:52:47 2007 - * - * @brief a test of set containers. - * Languages should define swig::LANGUAGE_OBJ to be - * an entity of their native pointer type which can be - * included in a STL container. +/* + * a test of set containers. + * Languages should define swig::LANGUAGE_OBJ to be + * an entity of their native pointer type which can be + * included in a STL container. * - * For example: - * swig::LANGUAGE_OBJ is GC_VALUE in Ruby - * swig::LANGUAGE_OBJ is SwigPtr_PyObject in python - * - * + * For example: + * swig::LANGUAGE_OBJ is GC_VALUE in Ruby + * swig::LANGUAGE_OBJ is SwigPtr_PyObject in python */ %module li_std_set diff --git a/Examples/test-suite/li_std_stack.i b/Examples/test-suite/li_std_stack.i index d29254089..19b45d46f 100644 --- a/Examples/test-suite/li_std_stack.i +++ b/Examples/test-suite/li_std_stack.i @@ -1,13 +1,4 @@ -/** - * @file std_stack.i - * @author gga - * @date Sun May 6 01:52:44 2007 - * - * @brief test of std::stack - * - * - */ - +// test of std::stack %module li_std_stack %include std_stack.i diff --git a/Examples/test-suite/ruby/ruby_li_std_speed_runme.rb b/Examples/test-suite/ruby/ruby_li_std_speed_runme.rb index 825f3c593..e79cb46a8 100755 --- a/Examples/test-suite/ruby/ruby_li_std_speed_runme.rb +++ b/Examples/test-suite/ruby/ruby_li_std_speed_runme.rb @@ -3,9 +3,6 @@ # This is a simple speed benchmark suite for std containers, # to verify their O(n) performance. # It is not part of the standard tests. -# -# License:: SWIG -# require 'benchmark' diff --git a/Examples/test-suite/ruby_li_std_speed.i b/Examples/test-suite/ruby_li_std_speed.i index 3c8e60643..bfb0b2776 100644 --- a/Examples/test-suite/ruby_li_std_speed.i +++ b/Examples/test-suite/ruby_li_std_speed.i @@ -1,13 +1,4 @@ -/** - * @file ruby_li_std_speed.i - * @author gga - * @date Fri May 18 18:03:15 2007 - * - * @brief A speed test of the ruby stl - * - * - */ - +// A speed test of the ruby stl %module ruby_li_std_speed %include diff --git a/Examples/xml/example_gif.i b/Examples/xml/example_gif.i deleted file mode 100644 index f0fb3b183..000000000 --- a/Examples/xml/example_gif.i +++ /dev/null @@ -1,329 +0,0 @@ -/* ----------------------------------------------------------------------------- - * gifplot.h - * - * Main header file for the GIFPlot library. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * Copyright (C) 1995-1996 - * - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -#include -#include -#include -#include -#include -#include - -#ifndef GIFPLOT_H - -/* Pixel is 8-bits */ - -typedef unsigned char Pixel; -typedef float Zvalue; - -/* ------------------------------------------------------------------------ - ColorMap - - Definition and methods for colormaps - ------------------------------------------------------------------------ */ - -typedef struct ColorMap { - unsigned char *cmap; - char *name; -} ColorMap; - -extern ColorMap *new_ColorMap(char *filename); -extern void delete_ColorMap(ColorMap *c); -extern void ColorMap_default(ColorMap *c); -extern void ColorMap_assign(ColorMap *c, int index, int r, int g, int b); -extern int ColorMap_getitem(ColorMap *c, int index); -extern void ColorMap_setitem(ColorMap *c, int index, int value); -extern int ColorMap_write(ColorMap *c, char *filename); - -/* Some default colors */ - -#define BLACK 0 -#define WHITE 1 -#define RED 2 -#define GREEN 3 -#define BLUE 4 -#define YELLOW 5 -#define CYAN 6 -#define MAGENTA 7 - -/*------------------------------------------------------------------------- - FrameBuffer - - This structure defines a simple 8 bit framebuffer. - ------------------------------------------------------------------------- */ - -typedef struct FrameBuffer { - Pixel **pixels; - Zvalue **zbuffer; - unsigned int height; - unsigned int width; - int xmin; /* These are used for clipping */ - int ymin; - int xmax; - int ymax; -} FrameBuffer; - -#define ZMIN 1e+36 - -/* FrameBuffer Methods */ - -extern FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height); -extern void delete_FrameBuffer(FrameBuffer *frame); -extern int FrameBuffer_resize(FrameBuffer *frame, int width, int height); -extern void FrameBuffer_clear(FrameBuffer *frame, Pixel color); -extern void FrameBuffer_plot(FrameBuffer *frame, int x, int y, Pixel color); -extern void FrameBuffer_horizontal(FrameBuffer *frame, int xmin, int xmax, int y, Pixel color); -extern void FrameBuffer_horizontalinterp(FrameBuffer *f, int xmin, int xmax, int y, Pixel c1, Pixel c2); -extern void FrameBuffer_vertical(FrameBuffer *frame, int ymin, int ymax, int x, Pixel color); -extern void FrameBuffer_box(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -extern void FrameBuffer_solidbox(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -extern void FrameBuffer_interpbox(FrameBuffer *f, int x1, int y1, int x2, int y2, Pixel c1, Pixel c2, Pixel c3, Pixel c4); -extern void FrameBuffer_circle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color); -extern void FrameBuffer_solidcircle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color); -extern void FrameBuffer_line(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); -extern void FrameBuffer_setclip(FrameBuffer *frame, int xmin, int ymin, int xmax, int ymax); -extern void FrameBuffer_noclip(FrameBuffer *frame); -extern int FrameBuffer_makeGIF(FrameBuffer *frame, ColorMap *cmap, void *buffer, unsigned int maxsize); -extern int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename); -extern void FrameBuffer_zresize(FrameBuffer *f, int width, int height); -extern void FrameBuffer_zclear(FrameBuffer *f); -extern void FrameBuffer_solidtriangle(FrameBuffer *f, int x1, int y1, int x2, int y2, int x3, int y3, Pixel c); -extern void FrameBuffer_interptriangle(FrameBuffer *f, int tx1, int ty1, Pixel c1, - int tx2, int ty2, Pixel c2, int tx3, int ty3, Pixel c3); - -#define HORIZONTAL 1 -#define VERTICAL 2 - -extern void FrameBuffer_drawchar(FrameBuffer *frame, int x, int y, int fgcolor, int bgcolor, char chr, int orientation); -extern void FrameBuffer_drawstring(FrameBuffer *f, int x, int y, int fgcolor, int bgcolor, char *text, int orientation); - -/* ------------------------------------------------------------------------ - PixMap - - The equivalent of "bit-maps". - ------------------------------------------------------------------------ */ - -typedef struct PixMap { - int width; - int height; - int centerx; - int centery; - int *map; -} PixMap; - -/* PIXMAP methods */ - -extern PixMap *new_PixMap(int width, int height, int centerx, int centery); -extern void delete_PixMap(PixMap *pm); -extern void PixMap_set(PixMap *pm, int x, int y, int pix); -extern void FrameBuffer_drawpixmap(FrameBuffer *f, PixMap *pm, int x, int y, int fgcolor, int bgcolor); - -#define TRANSPARENT 0 -#define FOREGROUND 1 -#define BACKGROUND 2 - -/* ------------------------------------------------------------------------ - Plot2D - - Definition and methods for 2D plots. - ------------------------------------------------------------------------ */ - -typedef struct Plot2D { - FrameBuffer *frame; /* what frame buffer are we using */ - int view_xmin; /* Minimum coordinates of view region */ - int view_ymin; - int view_xmax; /* Maximum coordinates of view region */ - int view_ymax; - double xmin; /* Minimum coordinates of plot region */ - double ymin; - double xmax; /* Maximum coordinates of plot region */ - double ymax; - int xscale; /* Type of scaling (LINEAR, LOG, etc..) */ - int yscale; - double dx; /* Private scaling parameters */ - double dy; -} Plot2D; - -/* 2D Plot methods */ - -extern Plot2D *new_Plot2D(FrameBuffer *frame,double xmin,double ymin, double xmax, double ymax); -extern void delete_Plot2D(Plot2D *p2); -extern Plot2D *Plot2D_copy(Plot2D *p2); -extern void Plot2D_clear(Plot2D *p2, Pixel c); -extern void Plot2D_setview(Plot2D *p2, int vxmin, int vymin, int vxmax, int vymax); -extern void Plot2D_setrange(Plot2D *p2, double xmin, double ymin, double xmax, double ymax); -extern void Plot2D_setscale(Plot2D *p2, int xscale, int yscale); -extern void Plot2D_plot(Plot2D *p2, double x, double y, Pixel color); -extern void Plot2D_box(Plot2D *p2, double x1, double y1, double x2, double y2, Pixel color); -extern void Plot2D_solidbox(Plot2D *p2, double x1, double y1,double x2, double y2, Pixel color); -extern void Plot2D_interpbox(Plot2D *p2, double x1, double y1, double x2, double y2, Pixel c1, Pixel c2, Pixel c3, Pixel c4); -extern void Plot2D_circle(Plot2D *p2, double x, double y, double radius, Pixel color); -extern void Plot2D_solidcircle(Plot2D *p2, double x, double y, double radius, Pixel color); -extern void Plot2D_line(Plot2D *p2, double x1, double y1, double x2, double y2, Pixel color); -extern void Plot2D_start(Plot2D *p2); -extern void Plot2D_drawpixmap(Plot2D *p2, PixMap *pm, double x, double y, Pixel color, Pixel bgcolor); -extern void Plot2D_xaxis(Plot2D *p2, double x, double y, double xtick, int ticklength, Pixel c); -extern void Plot2D_yaxis(Plot2D *p2, double x, double y, double ytick, int ticklength, Pixel c); -extern void Plot2D_triangle(Plot2D *p2, double x1, double y1, double x2, double y2, double x3, double y3, Pixel c); -extern void Plot2D_solidtriangle(Plot2D *p2, double x1, double y1, double x2, double y2, double x3, double y3, Pixel c); -extern void Plot2D_interptriangle(Plot2D *p2, double x1, double y1, Pixel c1, - double x2, double y2, Pixel c2, - double x3, double y3, Pixel c3); - -#define LINEAR 10 -#define LOG 11 - -/* ----------------------------------------------------------------------- - Matrix - - Operations on 4x4 transformation matrices and vectors. - Matrices are represented as a double array of 16 elements - ----------------------------------------------------------------------- */ - -typedef double *Matrix; -typedef struct GL_Vector { - double x; - double y; - double z; - double w; -} GL_Vector; - -extern Matrix new_Matrix(); -extern void delete_Matrix(Matrix a); -extern Matrix Matrix_copy(Matrix a); -extern void Matrix_multiply(Matrix a, Matrix b, Matrix c); -extern void Matrix_identity(Matrix a); -extern void Matrix_zero(Matrix a); -extern void Matrix_transpose(Matrix a, Matrix result); -extern void Matrix_invert(Matrix a, Matrix inva); -extern void Matrix_transform(Matrix a, GL_Vector *r, GL_Vector *t); -extern void Matrix_transform4(Matrix a, double rx, double ry, double rz, - double rw, GL_Vector *t); - -extern void Matrix_print(Matrix a); -extern void Matrix_translate(Matrix a, double tx, double ty, double tz); -extern void Matrix_rotatex(Matrix a, double deg); -extern void Matrix_rotatey(Matrix a, double deg); -extern void Matrix_rotatez(Matrix a, double deg); - -/* ----------------------------------------------------------------------- - Plot3D - - Data Structure for 3-D plots - ------------------------------------------------------------------------ */ - -typedef struct Plot3D { - FrameBuffer *frame; /* Frame buffer being used */ - int view_xmin; /* Viewing region */ - int view_ymin; - int view_xmax; - int view_ymax; - double xmin; /* Bounding box */ - double ymin; - double zmin; - double xmax; - double ymax; - double zmax; - double xcenter; /* Center point */ - double ycenter; - double zcenter; - double fovy; /* Field of view */ - double aspect; /* Aspect ratio */ - double znear; /* near "clipping" plane */ - double zfar; /* far "clipping" plane */ - Matrix center_mat; /* Matrix used for centering the model */ - Matrix model_mat; /* Model rotation matrix */ - Matrix view_mat; /* Viewing matrix */ - Matrix fullmodel_mat; /* Full model matrix. Used by sphere plot */ - Matrix trans_mat; /* Total transformation matrix */ - double lookatz; /* Where is the z-lookat point */ - double xshift; /* Used for translation and stuff */ - double yshift; - double zoom; - int width; - int height; - int pers_mode; /* Perspective mode (private) */ - double ortho_left,ortho_right,ortho_bottom,ortho_top; -} Plot3D; - -extern Plot3D *new_Plot3D(FrameBuffer *frame, double xmin, double ymin, double zmin, - double xmax, double ymax, double zmax); -extern void delete_Plot3D(Plot3D *p3); -extern Plot3D *Plot3D_copy(Plot3D *p3); -extern void Plot3D_clear(Plot3D *p3, Pixel Color); -extern void Plot3D_perspective(Plot3D *p3, double fovy, double znear, double zfar); -extern void Plot3D_ortho(Plot3D *p3, double left, double right, double top, double bottom); -extern void Plot3D_lookat(Plot3D *p3, double z); -extern void Plot3D_autoperspective(Plot3D *p3, double fovy); -extern void Plot3D_autoortho(Plot3D *p3); -extern void Plot3D_rotx(Plot3D *p3, double deg); -extern void Plot3D_roty(Plot3D *p3, double deg); -extern void Plot3D_rotz(Plot3D *p3, double deg); -extern void Plot3D_rotl(Plot3D *p3, double deg); -extern void Plot3D_rotr(Plot3D *p3, double deg); -extern void Plot3D_rotd(Plot3D *p3, double deg); -extern void Plot3D_rotu(Plot3D *p3, double deg); -extern void Plot3D_rotc(Plot3D *p3, double deg); -extern void Plot3D_zoom(Plot3D *p3, double percent); -extern void Plot3D_left(Plot3D *p3, double percent); -extern void Plot3D_right(Plot3D *p3, double percent); -extern void Plot3D_down(Plot3D *p3, double percent); -extern void Plot3D_up(Plot3D *p3, double percent); -extern void Plot3D_center(Plot3D *p3, double cx, double cy); - -extern void Plot3D_plot(Plot3D *p3, double x, double y, double z, Pixel Color); - -extern void Plot3D_setview(Plot3D *p3, int vxmin, int vymin, int vxmax, int vymax); -extern void Plot3D_start(Plot3D *p3); -extern void Plot3D_line(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, Pixel color); -extern void Plot3D_triangle(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, Pixel color); -extern void Plot3D_solidtriangle(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, Pixel color); - -extern void Plot3D_interptriangle(Plot3D *p3, - double x1, double y1, double z1, Pixel c1, - double x2, double y2, double z2, Pixel c2, - double x3, double y3, double z3, Pixel c3); - -extern void Plot3D_quad(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, - double x4, double y4, double z4, - Pixel color); - -extern void Plot3D_solidquad(Plot3D *p3, double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3, - double x4, double y4, double z4, - Pixel color); - -extern void Plot3D_interpquad(Plot3D *p3, double x1, double y1, double z1, Pixel c1, - double x2, double y2, double z2, Pixel c2, - double x3, double y3, double z3, Pixel c3, - double x4, double y4, double z4, Pixel c4); - - -extern void Plot3D_solidsphere(Plot3D *p3, double x, double y, double z, double radius,Pixel c); - -extern void Plot3D_outlinesphere(Plot3D *p3, double x, double y, double z, double radius,Pixel c, Pixel bc); - -extern PixMap PixMap_SQUARE; -extern PixMap PixMap_TRIANGLE; -extern PixMap PixMap_CROSS; - -#endif -#define GIFPLOT_H - - - diff --git a/LICENSE b/LICENSE index fdb73d916..d7a422fda 100644 --- a/LICENSE +++ b/LICENSE @@ -1,95 +1,22 @@ -SWIG is distributed under the following terms: +SWIG is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. See the LICENSE-GPL file for +the full terms of the GNU General Public license version 3. -I. +Portions of SWIG are also licensed under the terms of the licenses +in the file LICENSE-UNIVERSITIES. You must observe the terms of +these licenses, as well as the terms of the GNU General Public License, +when you distribute SWIG. -Copyright (c) 1995-1998 -The University of Utah and the Regents of the University of California -All Rights Reserved +The SWIG library and examples, under the Lib and Examples top level +directories, are distributed under the following terms: -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 -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 -described here, provided that the new terms are clearly indicated in -all files where they apply. - -IN NO EVENT SHALL THE AUTHOR, THE UNIVERSITY OF CALIFORNIA, THE -UNIVERSITY OF UTAH OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY -PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, -EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. - -THE AUTHOR, THE UNIVERSITY OF CALIFORNIA, AND THE UNIVERSITY OF UTAH -SPECIFICALLY DISCLAIM ANY WARRANTIES,INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND -THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, -SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - - -II. - -This software includes contributions that are Copyright (c) 1998-2005 -University of Chicago. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. Redistributions -in binary form must reproduce the above copyright notice, this list of -conditions and the following disclaimer in the documentation and/or -other materials provided with the distribution. Neither the name of -the University of Chicago nor the names of its contributors may be -used to endorse or promote products derived from this software without -specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF CHICAGO AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF -CHICAGO OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -III. - -This software includes contributions that are Copyright (c) 2005-2006 -Arizona Board of Regents (University of Arizona). -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 -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 -described here, provided that the new terms are clearly indicated in -all files where they apply. - -THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF ARIZONA AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF -ARIZONA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + You may copy, modify, distribute, and make derivative works based on + this software, in source code or object code form, without + restriction. If you distribute the software to others, you may do + so according to the terms of your choice. This software is offered as + is, without warranty of any kind. +See the COPYRIGHT file for a list of contributors to SWIG and their +copyright notices. diff --git a/LICENSE-GPL b/LICENSE-GPL new file mode 100644 index 000000000..94a9ed024 --- /dev/null +++ b/LICENSE-GPL @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, 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 +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If 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 convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU 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 +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state 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 program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/LICENSE-UNIVERSITIES b/LICENSE-UNIVERSITIES new file mode 100644 index 000000000..fdb73d916 --- /dev/null +++ b/LICENSE-UNIVERSITIES @@ -0,0 +1,95 @@ +SWIG is distributed under the following terms: + +I. + +Copyright (c) 1995-1998 +The University of Utah and the Regents of the University of California +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 +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 +described here, provided that the new terms are clearly indicated in +all files where they apply. + +IN NO EVENT SHALL THE AUTHOR, THE UNIVERSITY OF CALIFORNIA, THE +UNIVERSITY OF UTAH OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY +PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, +EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF +THE POSSIBILITY OF SUCH DAMAGE. + +THE AUTHOR, THE UNIVERSITY OF CALIFORNIA, AND THE UNIVERSITY OF UTAH +SPECIFICALLY DISCLAIM ANY WARRANTIES,INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND +THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, +SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + + +II. + +This software includes contributions that are Copyright (c) 1998-2005 +University of Chicago. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. Redistributions +in binary form must reproduce the above copyright notice, this list of +conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. Neither the name of +the University of Chicago nor the names of its contributors may be +used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF CHICAGO AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF +CHICAGO OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +III. + +This software includes contributions that are Copyright (c) 2005-2006 +Arizona Board of Regents (University of Arizona). +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 +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 +described here, provided that the new terms are clearly indicated in +all files where they apply. + +THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF ARIZONA AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF +ARIZONA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/Lib/allegrocl/allegrocl.swg b/Lib/allegrocl/allegrocl.swg index 4479f6ac2..266303113 100644 --- a/Lib/allegrocl/allegrocl.swg +++ b/Lib/allegrocl/allegrocl.swg @@ -289,8 +289,6 @@ $body)" #endif %insert("lisphead") %{ -;; $Id$ - (eval-when (:compile-toplevel :load-toplevel :execute) ;; avoid compiling ef-templates at runtime diff --git a/Lib/allegrocl/longlongs.i b/Lib/allegrocl/longlongs.i index b887a8a0a..4aa54660b 100644 --- a/Lib/allegrocl/longlongs.i +++ b/Lib/allegrocl/longlongs.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * longlongs.i * * Typemap addition for support of 'long long' type and 'unsigned long long diff --git a/Lib/allegrocl/std_list.i b/Lib/allegrocl/std_list.i index c8ab45649..4e260897f 100644 --- a/Lib/allegrocl/std_list.i +++ b/Lib/allegrocl/std_list.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_list.i * * SWIG typemaps for std::list types diff --git a/Lib/allegrocl/std_string.i b/Lib/allegrocl/std_string.i index 4da0148fe..becc322e9 100644 --- a/Lib/allegrocl/std_string.i +++ b/Lib/allegrocl/std_string.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_string.i * * SWIG typemaps for std::string diff --git a/Lib/attribute.i b/Lib/attribute.i index 45c3c5b64..0cc3ff1a3 100644 --- a/Lib/attribute.i +++ b/Lib/attribute.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * attribute.i * * SWIG library file for implementing attributes. diff --git a/Lib/carrays.i b/Lib/carrays.i index 738b4577a..5fc78877c 100644 --- a/Lib/carrays.i +++ b/Lib/carrays.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * carrays.i * * SWIG library file containing macros that can be used to manipulate simple diff --git a/Lib/cdata.i b/Lib/cdata.i index 67601f737..41e8f86ce 100644 --- a/Lib/cdata.i +++ b/Lib/cdata.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * cdata.i * * SWIG library file containing macros for manipulating raw C data as strings. diff --git a/Lib/chicken/chicken.swg b/Lib/chicken/chicken.swg index a8d1b5a57..68f022570 100644 --- a/Lib/chicken/chicken.swg +++ b/Lib/chicken/chicken.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * chicken.swg * * CHICKEN configuration module. diff --git a/Lib/chicken/chickenrun.swg b/Lib/chicken/chickenrun.swg index 8703ea65a..f4e94d6f6 100644 --- a/Lib/chicken/chickenrun.swg +++ b/Lib/chicken/chickenrun.swg @@ -1,9 +1,5 @@ /* ----------------------------------------------------------------------------- - * 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. - * * chickenrun.swg - * * ----------------------------------------------------------------------------- */ #include diff --git a/Lib/chicken/multi-generic.scm b/Lib/chicken/multi-generic.scm index ae822f37b..9d2e31d34 100644 --- a/Lib/chicken/multi-generic.scm +++ b/Lib/chicken/multi-generic.scm @@ -21,7 +21,7 @@ ;; which functions are used when. ;; Comments, bugs, suggestions: send either to chicken-users@nongnu.org or to -;; Author: John Lenz , most code copied from TinyCLOS +;; Most code copied from TinyCLOS (define (make 'name "multi-generic" diff --git a/Lib/chicken/std_string.i b/Lib/chicken/std_string.i index 2955d0e2f..ce24cba32 100644 --- a/Lib/chicken/std_string.i +++ b/Lib/chicken/std_string.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_string.i * * SWIG typemaps for std::string diff --git a/Lib/chicken/typemaps.i b/Lib/chicken/typemaps.i index d79e20184..56cd18a5d 100644 --- a/Lib/chicken/typemaps.i +++ b/Lib/chicken/typemaps.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * typemaps.i * * Pointer handling diff --git a/Lib/clisp/clisp.swg b/Lib/clisp/clisp.swg index fb6cdbf2a..e1d330cb3 100644 --- a/Lib/clisp/clisp.swg +++ b/Lib/clisp/clisp.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * clisp.swg * ----------------------------------------------------------------------------- */ diff --git a/Lib/cmalloc.i b/Lib/cmalloc.i index 03a61351c..9f58bc03c 100644 --- a/Lib/cmalloc.i +++ b/Lib/cmalloc.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * cmalloc.i * * SWIG library file containing macros that can be used to create objects using diff --git a/Lib/constraints.i b/Lib/constraints.i index 2deb1168a..8bc7f9159 100644 --- a/Lib/constraints.i +++ b/Lib/constraints.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * constraints.i * * SWIG constraints library. diff --git a/Lib/cpointer.i b/Lib/cpointer.i index 1a6e51741..6b15a8417 100644 --- a/Lib/cpointer.i +++ b/Lib/cpointer.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * cpointer.i * * SWIG library file containing macros that can be used to manipulate simple diff --git a/Lib/csharp/arrays_csharp.i b/Lib/csharp/arrays_csharp.i index ea22da584..513330e4e 100644 --- a/Lib/csharp/arrays_csharp.i +++ b/Lib/csharp/arrays_csharp.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * arrays_csharp.i * * This file contains a two approaches to marshaling arrays. The first uses diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index fe459547c..204cf4b2f 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * csharp.swg * * C# typemaps diff --git a/Lib/csharp/csharphead.swg b/Lib/csharp/csharphead.swg index 927a54b3b..9b144d6a5 100644 --- a/Lib/csharp/csharphead.swg +++ b/Lib/csharp/csharphead.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * csharphead.swg * * Support code for exceptions if the SWIG_CSHARP_NO_EXCEPTION_HELPER is not defined diff --git a/Lib/csharp/director.swg b/Lib/csharp/director.swg index 8957ecf42..7768d8c02 100644 --- a/Lib/csharp/director.swg +++ b/Lib/csharp/director.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * director.swg * * This file contains support for director classes so that C# proxy diff --git a/Lib/csharp/enums.swg b/Lib/csharp/enums.swg index be2a6063b..6605da8c8 100644 --- a/Lib/csharp/enums.swg +++ b/Lib/csharp/enums.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * enums.swg * * Include this file in order for C/C++ enums to be wrapped by proper C# enums. diff --git a/Lib/csharp/enumsimple.swg b/Lib/csharp/enumsimple.swg index f50849892..2b1cb182b 100644 --- a/Lib/csharp/enumsimple.swg +++ b/Lib/csharp/enumsimple.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * enumsimple.swg * * This file provides backwards compatible enum wrapping. SWIG versions 1.3.21 diff --git a/Lib/csharp/enumtypesafe.swg b/Lib/csharp/enumtypesafe.swg index 8ba7838ef..a6bf64b9a 100644 --- a/Lib/csharp/enumtypesafe.swg +++ b/Lib/csharp/enumtypesafe.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * enumtypesafe.swg * * Include this file in order for C/C++ enums to be wrapped by the so called diff --git a/Lib/csharp/std_except.i b/Lib/csharp/std_except.i index c86e97a54..27eb84bc2 100644 --- a/Lib/csharp/std_except.i +++ b/Lib/csharp/std_except.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_except.i * * Typemaps used by the STL wrappers that throw exceptions. These typemaps are diff --git a/Lib/csharp/std_map.i b/Lib/csharp/std_map.i index 3b09861a2..a30b6fa70 100644 --- a/Lib/csharp/std_map.i +++ b/Lib/csharp/std_map.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_map.i * * SWIG typemaps for std::map diff --git a/Lib/csharp/std_pair.i b/Lib/csharp/std_pair.i index 78142ffa6..0712ad762 100644 --- a/Lib/csharp/std_pair.i +++ b/Lib/csharp/std_pair.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_pair.i * * SWIG typemaps for std::pair diff --git a/Lib/csharp/std_string.i b/Lib/csharp/std_string.i index d29692717..0d804518b 100644 --- a/Lib/csharp/std_string.i +++ b/Lib/csharp/std_string.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_string.i * * Typemaps for std::string and const std::string& diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index d3a4a5541..673cced89 100644 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_vector.i * * SWIG typemaps for std::vector diff --git a/Lib/csharp/std_wstring.i b/Lib/csharp/std_wstring.i index 938070e4b..9142d36a5 100644 --- a/Lib/csharp/std_wstring.i +++ b/Lib/csharp/std_wstring.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_wstring.i * * Typemaps for std::wstring and const std::wstring& diff --git a/Lib/csharp/stl.i b/Lib/csharp/stl.i index 66b72e073..9d2e91eee 100644 --- a/Lib/csharp/stl.i +++ b/Lib/csharp/stl.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * stl.i * * Initial STL definition. extended as needed in each language diff --git a/Lib/csharp/typemaps.i b/Lib/csharp/typemaps.i index 56cc6cb61..d50e5c46d 100644 --- a/Lib/csharp/typemaps.i +++ b/Lib/csharp/typemaps.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * typemaps.i * * Pointer and reference handling typemap library diff --git a/Lib/csharp/wchar.i b/Lib/csharp/wchar.i index be87560c3..f02c09a53 100644 --- a/Lib/csharp/wchar.i +++ b/Lib/csharp/wchar.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * wchar.i * * Typemaps for the wchar_t type diff --git a/Lib/cstring.i b/Lib/cstring.i index 4ebdf6857..6829f7597 100644 --- a/Lib/cstring.i +++ b/Lib/cstring.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * cstring.i * ----------------------------------------------------------------------------- */ diff --git a/Lib/cwstring.i b/Lib/cwstring.i index a6b08ae40..f0631d328 100644 --- a/Lib/cwstring.i +++ b/Lib/cwstring.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * cwstring.i * ----------------------------------------------------------------------------- */ diff --git a/Lib/exception.i b/Lib/exception.i index e30ac1a5d..7297a77f5 100644 --- a/Lib/exception.i +++ b/Lib/exception.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * exception.i * * SWIG library file providing language independent exception handling diff --git a/Lib/gcj/cni.swg b/Lib/gcj/cni.swg index 247909a4a..4bd07df06 100644 --- a/Lib/gcj/cni.swg +++ b/Lib/gcj/cni.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * cni.swg * ----------------------------------------------------------------------------- */ diff --git a/Lib/guile/common.scm b/Lib/guile/common.scm index a51d3a71d..17c9ab580 100644 --- a/Lib/guile/common.scm +++ b/Lib/guile/common.scm @@ -3,12 +3,6 @@ ;;;* ;;;* This file contains generic SWIG GOOPS classes for generated ;;;* GOOPS file support -;;;* -;;;* Copyright (C) 2003 John Lenz (jelenz@wisc.edu) -;;;* Copyright (C) 2004 Matthias Koeppe (mkoeppe@mail.math.uni-magdeburg.de) -;;;* -;;;* This file may be freely redistributed without license or fee provided -;;;* this copyright message remains intact. ;;;************************************************************************ (define-module (Swig swigrun)) diff --git a/Lib/guile/cplusplus.i b/Lib/guile/cplusplus.i index cb4cf7434..0dfe71754 100644 --- a/Lib/guile/cplusplus.i +++ b/Lib/guile/cplusplus.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * cplusplus.i * * SWIG typemaps for C++ diff --git a/Lib/guile/guile.i b/Lib/guile/guile.i index 1bf28d6f3..ef270d74b 100644 --- a/Lib/guile/guile.i +++ b/Lib/guile/guile.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * guile.i * * SWIG Configuration File for Guile. diff --git a/Lib/guile/guile_gh.swg b/Lib/guile/guile_gh.swg index 6412a4c61..3b65af897 100644 --- a/Lib/guile/guile_gh.swg +++ b/Lib/guile/guile_gh.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * guile_gh.swg * * This SWIG interface file is processed if the Guile module is run diff --git a/Lib/guile/guile_gh_run.swg b/Lib/guile/guile_gh_run.swg index 5b1fca0aa..0eba1f97e 100644 --- a/Lib/guile/guile_gh_run.swg +++ b/Lib/guile/guile_gh_run.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * guile_gh_run.swg * * Guile GH runtime file diff --git a/Lib/guile/guile_scm.swg b/Lib/guile/guile_scm.swg index caded728d..d12401451 100644 --- a/Lib/guile/guile_scm.swg +++ b/Lib/guile/guile_scm.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * guile_scm.swg * * This SWIG interface file is processed if the Guile module is run diff --git a/Lib/guile/guile_scm_run.swg b/Lib/guile/guile_scm_run.swg index 5da8558fc..91b74095d 100644 --- a/Lib/guile/guile_scm_run.swg +++ b/Lib/guile/guile_scm_run.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * guile_scm_run.swg * ----------------------------------------------------------------------------- */ diff --git a/Lib/guile/guilemain.i b/Lib/guile/guilemain.i index 6f4e4d94d..925b81fee 100644 --- a/Lib/guile/guilemain.i +++ b/Lib/guile/guilemain.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * guilemain.i * * The main functions for a user augmented guile diff --git a/Lib/guile/interpreter.i b/Lib/guile/interpreter.i index 7e8f0777a..524e0694a 100644 --- a/Lib/guile/interpreter.i +++ b/Lib/guile/interpreter.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * interpreter.i * * SWIG file for a simple Guile interpreter diff --git a/Lib/guile/list-vector.i b/Lib/guile/list-vector.i index d98cae59a..c2cd1aea2 100644 --- a/Lib/guile/list-vector.i +++ b/Lib/guile/list-vector.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * list_vector.i * * Guile typemaps for converting between arrays and Scheme lists or vectors diff --git a/Lib/guile/pointer-in-out.i b/Lib/guile/pointer-in-out.i index bc6438759..d8a631ca9 100644 --- a/Lib/guile/pointer-in-out.i +++ b/Lib/guile/pointer-in-out.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * pointer-in-out.i * * Guile typemaps for passing pointers indirectly diff --git a/Lib/guile/ports.i b/Lib/guile/ports.i index 0d0e142e1..5940b4d3b 100644 --- a/Lib/guile/ports.i +++ b/Lib/guile/ports.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * ports.i * * Guile typemaps for handling ports diff --git a/Lib/guile/std_common.i b/Lib/guile/std_common.i index ace5d65a8..a46c42c69 100644 --- a/Lib/guile/std_common.i +++ b/Lib/guile/std_common.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_common.i * * SWIG typemaps for STL - common utilities diff --git a/Lib/guile/std_map.i b/Lib/guile/std_map.i index cc53e1560..19c863096 100644 --- a/Lib/guile/std_map.i +++ b/Lib/guile/std_map.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_map.i * * SWIG typemaps for std::map diff --git a/Lib/guile/std_pair.i b/Lib/guile/std_pair.i index f8c2ea688..35f0cfad5 100644 --- a/Lib/guile/std_pair.i +++ b/Lib/guile/std_pair.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_pair.i * * SWIG typemaps for std::pair diff --git a/Lib/guile/std_string.i b/Lib/guile/std_string.i index f80a65ca5..c10806e98 100644 --- a/Lib/guile/std_string.i +++ b/Lib/guile/std_string.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_string.i * * SWIG typemaps for std::string diff --git a/Lib/guile/std_vector.i b/Lib/guile/std_vector.i index 145db945b..6801daee8 100644 --- a/Lib/guile/std_vector.i +++ b/Lib/guile/std_vector.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_vector.i * * SWIG typemaps for std::vector diff --git a/Lib/guile/stl.i b/Lib/guile/stl.i index 66b72e073..9d2e91eee 100644 --- a/Lib/guile/stl.i +++ b/Lib/guile/stl.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * stl.i * * Initial STL definition. extended as needed in each language diff --git a/Lib/guile/typemaps.i b/Lib/guile/typemaps.i index d9f972850..4f306f7f8 100644 --- a/Lib/guile/typemaps.i +++ b/Lib/guile/typemaps.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * typemaps.i * * Guile-specific typemaps diff --git a/Lib/inttypes.i b/Lib/inttypes.i index 0cc81948e..8450cb840 100644 --- a/Lib/inttypes.i +++ b/Lib/inttypes.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * inttypes.i * * SWIG library file for ISO C99 types: 7.8 Format conversion of integer types diff --git a/Lib/java/arrays_java.i b/Lib/java/arrays_java.i index 95510c3f9..ddaf7408c 100644 --- a/Lib/java/arrays_java.i +++ b/Lib/java/arrays_java.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * arrays_java.i * * These typemaps give more natural support for arrays. The typemaps are not efficient diff --git a/Lib/java/director.swg b/Lib/java/director.swg index fa588671d..07e5a1af1 100644 --- a/Lib/java/director.swg +++ b/Lib/java/director.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * director.swg * * This file contains support for director classes that proxy diff --git a/Lib/java/enums.swg b/Lib/java/enums.swg index 1a8f89b3a..edb67c417 100644 --- a/Lib/java/enums.swg +++ b/Lib/java/enums.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * enums.swg * * Include this file in order for C/C++ enums to be wrapped by proper Java enums. diff --git a/Lib/java/enumsimple.swg b/Lib/java/enumsimple.swg index f45774d0c..e08401869 100644 --- a/Lib/java/enumsimple.swg +++ b/Lib/java/enumsimple.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * enumsimple.swg * * This file provides backwards compatible enum wrapping. SWIG versions 1.3.21 diff --git a/Lib/java/enumtypesafe.swg b/Lib/java/enumtypesafe.swg index a49a9d134..d6c6e5190 100644 --- a/Lib/java/enumtypesafe.swg +++ b/Lib/java/enumtypesafe.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * enumtypesafe.swg * * Include this file in order for C/C++ enums to be wrapped by the so called diff --git a/Lib/java/enumtypeunsafe.swg b/Lib/java/enumtypeunsafe.swg index bda055113..d9a7c4d29 100644 --- a/Lib/java/enumtypeunsafe.swg +++ b/Lib/java/enumtypeunsafe.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * enumtypeunsafe.swg * * Include this file in order for C/C++ enums to be wrapped by integers values. diff --git a/Lib/java/java.swg b/Lib/java/java.swg index bd2357a86..6173502ca 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * java.swg * * Java typemaps diff --git a/Lib/java/javahead.swg b/Lib/java/javahead.swg index 7626bf50d..685bba198 100644 --- a/Lib/java/javahead.swg +++ b/Lib/java/javahead.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * javahead.swg * * Java support code diff --git a/Lib/java/std_except.i b/Lib/java/std_except.i index 15be1deb8..9e23d50e6 100644 --- a/Lib/java/std_except.i +++ b/Lib/java/std_except.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_except.i * * Typemaps used by the STL wrappers that throw exceptions. diff --git a/Lib/java/std_map.i b/Lib/java/std_map.i index 00967d3f9..a7020532c 100644 --- a/Lib/java/std_map.i +++ b/Lib/java/std_map.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_map.i * * SWIG typemaps for std::map diff --git a/Lib/java/std_pair.i b/Lib/java/std_pair.i index dc0604dc5..fe45ee676 100644 --- a/Lib/java/std_pair.i +++ b/Lib/java/std_pair.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_pair.i * * SWIG typemaps for std::pair diff --git a/Lib/java/std_string.i b/Lib/java/std_string.i index 789e17a65..f0d837696 100644 --- a/Lib/java/std_string.i +++ b/Lib/java/std_string.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_string.i * * Typemaps for std::string and const std::string& diff --git a/Lib/java/std_vector.i b/Lib/java/std_vector.i index 29439606b..3f29b19c7 100644 --- a/Lib/java/std_vector.i +++ b/Lib/java/std_vector.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_vector.i * ----------------------------------------------------------------------------- */ diff --git a/Lib/java/std_wstring.i b/Lib/java/std_wstring.i index 989176500..12d8fc14f 100644 --- a/Lib/java/std_wstring.i +++ b/Lib/java/std_wstring.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_wstring.i * * Typemaps for std::wstring and const std::wstring& diff --git a/Lib/java/stl.i b/Lib/java/stl.i index b8d7a654c..04f86014f 100644 --- a/Lib/java/stl.i +++ b/Lib/java/stl.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * stl.i * ----------------------------------------------------------------------------- */ diff --git a/Lib/java/typemaps.i b/Lib/java/typemaps.i index 59f7af99a..74ed99374 100644 --- a/Lib/java/typemaps.i +++ b/Lib/java/typemaps.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * typemaps.i * * Pointer and reference handling typemap library diff --git a/Lib/java/various.i b/Lib/java/various.i index 733b8fa79..7c396de3e 100644 --- a/Lib/java/various.i +++ b/Lib/java/various.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * various.i * * SWIG Typemap library for Java. diff --git a/Lib/lua/_std_common.i b/Lib/lua/_std_common.i index 33cc513c3..e552d0c8f 100644 --- a/Lib/lua/_std_common.i +++ b/Lib/lua/_std_common.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * _std_common.i * * std::helpers for LUA diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg index b6d888670..c3f5cecc5 100644 --- a/Lib/lua/lua.swg +++ b/Lib/lua/lua.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * lua.swg * * SWIG Configuration File for Lua. diff --git a/Lib/lua/lua_fnptr.i b/Lib/lua/lua_fnptr.i index c7df6f5a3..7e9facdf3 100644 --- a/Lib/lua/lua_fnptr.i +++ b/Lib/lua/lua_fnptr.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * lua_fnptr.i * * SWIG Library file containing the main typemap code to support Lua modules. diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 32e1b1617..4c9aa5144 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * luarun.swg * * This file contains the runtime support for Lua modules diff --git a/Lib/lua/luaruntime.swg b/Lib/lua/luaruntime.swg index b82cd56d7..5823d4fcf 100644 --- a/Lib/lua/luaruntime.swg +++ b/Lib/lua/luaruntime.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * luaruntime.swg * * all the runtime code for . diff --git a/Lib/lua/luatypemaps.swg b/Lib/lua/luatypemaps.swg index caa2a6ce1..401541267 100644 --- a/Lib/lua/luatypemaps.swg +++ b/Lib/lua/luatypemaps.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * luatypemaps.swg * * basic typemaps for Lua. diff --git a/Lib/lua/std_except.i b/Lib/lua/std_except.i index ce148ef63..9c736b9ef 100644 --- a/Lib/lua/std_except.i +++ b/Lib/lua/std_except.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * Typemaps used by the STL wrappers that throw exceptions. * These typemaps are used when methods are declared with an STL exception * specification, such as: diff --git a/Lib/lua/std_map.i b/Lib/lua/std_map.i index dd22443d5..84b0c74ff 100644 --- a/Lib/lua/std_map.i +++ b/Lib/lua/std_map.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_map.i * * SWIG typemaps for std::map diff --git a/Lib/lua/std_pair.i b/Lib/lua/std_pair.i index 1b20f74e0..c76361554 100644 --- a/Lib/lua/std_pair.i +++ b/Lib/lua/std_pair.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_pair.i * * std::pair typemaps for LUA diff --git a/Lib/lua/std_string.i b/Lib/lua/std_string.i index fa58f10bb..92f27d738 100644 --- a/Lib/lua/std_string.i +++ b/Lib/lua/std_string.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_string.i * * std::string typemaps for LUA diff --git a/Lib/lua/std_vector.i b/Lib/lua/std_vector.i index c6778087f..f248f0340 100644 --- a/Lib/lua/std_vector.i +++ b/Lib/lua/std_vector.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_vector.i * * std::vector typemaps for LUA diff --git a/Lib/lua/stl.i b/Lib/lua/stl.i index b8d7a654c..04f86014f 100644 --- a/Lib/lua/stl.i +++ b/Lib/lua/stl.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * stl.i * ----------------------------------------------------------------------------- */ diff --git a/Lib/lua/typemaps.i b/Lib/lua/typemaps.i index fa0c0d0e5..084726e58 100644 --- a/Lib/lua/typemaps.i +++ b/Lib/lua/typemaps.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * typemaps.swg * * SWIG Library file containing the main typemap code to support Lua modules. diff --git a/Lib/lua/wchar.i b/Lib/lua/wchar.i index 5b206eb71..5021c1604 100644 --- a/Lib/lua/wchar.i +++ b/Lib/lua/wchar.i @@ -1,12 +1,8 @@ /* ----------------------------------------------------------------------------- - * 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. - * * wchar.i * * Typemaps for the wchar_t type * These are mapped to a Lua string and are passed around by value. - * * ----------------------------------------------------------------------------- */ // note: only support for pointer right now, not fixed length strings @@ -43,4 +39,4 @@ if ($1==0) {lua_pushfstring(L,"Error in converting to wchar (arg %d)",$input);go free($1); %} -%typemap(typecheck) wchar_t * = char *; \ No newline at end of file +%typemap(typecheck) wchar_t * = char *; diff --git a/Lib/math.i b/Lib/math.i index be931d71b..a37c92d19 100644 --- a/Lib/math.i +++ b/Lib/math.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * math.i * * SWIG library file for floating point operations. diff --git a/Lib/modula3/modula3.swg b/Lib/modula3/modula3.swg index 6a1b4d94d..599a12e5a 100644 --- a/Lib/modula3/modula3.swg +++ b/Lib/modula3/modula3.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * modula3.swg * * Modula3 typemaps diff --git a/Lib/modula3/modula3head.swg b/Lib/modula3/modula3head.swg index b2426be5f..af96a78d1 100644 --- a/Lib/modula3/modula3head.swg +++ b/Lib/modula3/modula3head.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * modula3head.swg * * Modula3 support code diff --git a/Lib/modula3/typemaps.i b/Lib/modula3/typemaps.i index 79ddfda0f..1d76ab5e0 100644 --- a/Lib/modula3/typemaps.i +++ b/Lib/modula3/typemaps.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * typemaps.i * * Pointer and reference handling typemap library diff --git a/Lib/mzscheme/mzrun.swg b/Lib/mzscheme/mzrun.swg index 3b05d2406..a5128da56 100644 --- a/Lib/mzscheme/mzrun.swg +++ b/Lib/mzscheme/mzrun.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * mzrun.swg * ----------------------------------------------------------------------------- */ diff --git a/Lib/mzscheme/mzscheme.swg b/Lib/mzscheme/mzscheme.swg index ed4b2ec9d..9ae242845 100644 --- a/Lib/mzscheme/mzscheme.swg +++ b/Lib/mzscheme/mzscheme.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * mzscheme.swg * * SWIG Configuration File for MzScheme. diff --git a/Lib/mzscheme/std_common.i b/Lib/mzscheme/std_common.i index 8732f811c..1f1ae1ab7 100644 --- a/Lib/mzscheme/std_common.i +++ b/Lib/mzscheme/std_common.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_common.i * * SWIG typemaps for STL - common utilities diff --git a/Lib/mzscheme/std_map.i b/Lib/mzscheme/std_map.i index aff720db6..b2c894509 100644 --- a/Lib/mzscheme/std_map.i +++ b/Lib/mzscheme/std_map.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_map.i * * SWIG typemaps for std::map diff --git a/Lib/mzscheme/std_pair.i b/Lib/mzscheme/std_pair.i index 2ac331e71..d5a65470d 100644 --- a/Lib/mzscheme/std_pair.i +++ b/Lib/mzscheme/std_pair.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_pair.i * * SWIG typemaps for std::pair diff --git a/Lib/mzscheme/std_string.i b/Lib/mzscheme/std_string.i index c9a82efe4..b8b99d9ad 100644 --- a/Lib/mzscheme/std_string.i +++ b/Lib/mzscheme/std_string.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_string.i * * SWIG typemaps for std::string types diff --git a/Lib/mzscheme/std_vector.i b/Lib/mzscheme/std_vector.i index 90a52fc0a..22e1fa96b 100644 --- a/Lib/mzscheme/std_vector.i +++ b/Lib/mzscheme/std_vector.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_vector.i * * SWIG typemaps for std::vector diff --git a/Lib/mzscheme/stl.i b/Lib/mzscheme/stl.i index 946e4b7f0..b19eae58b 100644 --- a/Lib/mzscheme/stl.i +++ b/Lib/mzscheme/stl.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * stl.i * * Initial STL definition. extended as needed in each language diff --git a/Lib/mzscheme/typemaps.i b/Lib/mzscheme/typemaps.i index 334893242..b9f22440c 100644 --- a/Lib/mzscheme/typemaps.i +++ b/Lib/mzscheme/typemaps.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * typemaps.i * ----------------------------------------------------------------------------- */ diff --git a/Lib/ocaml/cstring.i b/Lib/ocaml/cstring.i index e56258264..0d6aa4b69 100644 --- a/Lib/ocaml/cstring.i +++ b/Lib/ocaml/cstring.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * cstring.i * * This file provides typemaps and macros for dealing with various forms diff --git a/Lib/ocaml/director.swg b/Lib/ocaml/director.swg index 87333168f..a21f62102 100644 --- a/Lib/ocaml/director.swg +++ b/Lib/ocaml/director.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * director.swg * * This file contains support for director classes that proxy diff --git a/Lib/ocaml/ocaml.i b/Lib/ocaml/ocaml.i index a46e239d1..e099f7c10 100644 --- a/Lib/ocaml/ocaml.i +++ b/Lib/ocaml/ocaml.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * ocaml.i * * SWIG Configuration File for Ocaml diff --git a/Lib/ocaml/ocamldec.swg b/Lib/ocaml/ocamldec.swg index 3b5290fa1..8e452d3f9 100644 --- a/Lib/ocaml/ocamldec.swg +++ b/Lib/ocaml/ocamldec.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * ocamldec.swg * * Ocaml runtime code -- declarations diff --git a/Lib/ocaml/std_common.i b/Lib/ocaml/std_common.i index b2dff61d2..1c397050c 100644 --- a/Lib/ocaml/std_common.i +++ b/Lib/ocaml/std_common.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_common.i * * SWIG typemaps for STL - common utilities diff --git a/Lib/ocaml/std_deque.i b/Lib/ocaml/std_deque.i index baadb4e53..5b38962bf 100644 --- a/Lib/ocaml/std_deque.i +++ b/Lib/ocaml/std_deque.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_deque.i * * Default std_deque wrapper diff --git a/Lib/ocaml/std_list.i b/Lib/ocaml/std_list.i index 0aea90767..06181cca8 100644 --- a/Lib/ocaml/std_list.i +++ b/Lib/ocaml/std_list.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_list.i * * SWIG typemaps for std::list types diff --git a/Lib/ocaml/std_map.i b/Lib/ocaml/std_map.i index f174f2872..f202e74ed 100644 --- a/Lib/ocaml/std_map.i +++ b/Lib/ocaml/std_map.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_map.i * * SWIG typemaps for std::map diff --git a/Lib/ocaml/std_pair.i b/Lib/ocaml/std_pair.i index dc0604dc5..fe45ee676 100644 --- a/Lib/ocaml/std_pair.i +++ b/Lib/ocaml/std_pair.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_pair.i * * SWIG typemaps for std::pair diff --git a/Lib/ocaml/std_string.i b/Lib/ocaml/std_string.i index 7add3a070..e75e95304 100644 --- a/Lib/ocaml/std_string.i +++ b/Lib/ocaml/std_string.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_string.i * * SWIG typemaps for std::string diff --git a/Lib/ocaml/std_vector.i b/Lib/ocaml/std_vector.i index 91c335562..53d107447 100644 --- a/Lib/ocaml/std_vector.i +++ b/Lib/ocaml/std_vector.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_vector.i * * SWIG typemaps for std::vector types diff --git a/Lib/ocaml/stl.i b/Lib/ocaml/stl.i index 66b72e073..9d2e91eee 100644 --- a/Lib/ocaml/stl.i +++ b/Lib/ocaml/stl.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * stl.i * * Initial STL definition. extended as needed in each language diff --git a/Lib/ocaml/typecheck.i b/Lib/ocaml/typecheck.i index 51e66061b..4c3500690 100644 --- a/Lib/ocaml/typecheck.i +++ b/Lib/ocaml/typecheck.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * typecheck.i * * Typechecking rules diff --git a/Lib/ocaml/typemaps.i b/Lib/ocaml/typemaps.i index 7f978bf7f..39544de94 100644 --- a/Lib/ocaml/typemaps.i +++ b/Lib/ocaml/typemaps.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * typemaps.i * * The Ocaml module handles all types uniformly via typemaps. Here diff --git a/Lib/octave/octcontainer.swg b/Lib/octave/octcontainer.swg index afc3ed147..6613fcfff 100644 --- a/Lib/octave/octcontainer.swg +++ b/Lib/octave/octcontainer.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * octcontainer.swg * * Octave cell <-> C++ container wrapper diff --git a/Lib/octave/octiterators.swg b/Lib/octave/octiterators.swg index 926361e10..0e3fe7033 100644 --- a/Lib/octave/octiterators.swg +++ b/Lib/octave/octiterators.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * octiterators.swg * * Users can derive form the OctSwigIterator to implemet their diff --git a/Lib/perl5/perlmain.i b/Lib/perl5/perlmain.i index f224b9c75..18ecb7eb5 100644 --- a/Lib/perl5/perlmain.i +++ b/Lib/perl5/perlmain.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * perlmain.i * * Code to statically rebuild perl5. diff --git a/Lib/perl5/reference.i b/Lib/perl5/reference.i index d3d745cfc..06712bbd5 100644 --- a/Lib/perl5/reference.i +++ b/Lib/perl5/reference.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * reference.i * * Accept Perl references as pointers diff --git a/Lib/perl5/std_common.i b/Lib/perl5/std_common.i index bc25b353f..c36513912 100644 --- a/Lib/perl5/std_common.i +++ b/Lib/perl5/std_common.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_common.i * * SWIG typemaps for STL - common utilities diff --git a/Lib/perl5/std_list.i b/Lib/perl5/std_list.i index 633e40d9a..c6bca18f6 100644 --- a/Lib/perl5/std_list.i +++ b/Lib/perl5/std_list.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_list.i * * SWIG typemaps for std::list types diff --git a/Lib/perl5/std_map.i b/Lib/perl5/std_map.i index c35f21dc7..b19414597 100644 --- a/Lib/perl5/std_map.i +++ b/Lib/perl5/std_map.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_map.i * * SWIG typemaps for std::map diff --git a/Lib/perl5/std_pair.i b/Lib/perl5/std_pair.i index 78142ffa6..0712ad762 100644 --- a/Lib/perl5/std_pair.i +++ b/Lib/perl5/std_pair.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_pair.i * * SWIG typemaps for std::pair diff --git a/Lib/perl5/std_vector.i b/Lib/perl5/std_vector.i index 7c4f72919..0a61c31e0 100644 --- a/Lib/perl5/std_vector.i +++ b/Lib/perl5/std_vector.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_vector.i * * SWIG typemaps for std::vector types diff --git a/Lib/perl5/stl.i b/Lib/perl5/stl.i index 946e4b7f0..b19eae58b 100644 --- a/Lib/perl5/stl.i +++ b/Lib/perl5/stl.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * stl.i * * Initial STL definition. extended as needed in each language diff --git a/Lib/perl5/typemaps.i b/Lib/perl5/typemaps.i index fc6d8f874..7d96f2ace 100644 --- a/Lib/perl5/typemaps.i +++ b/Lib/perl5/typemaps.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * typemaps.i * * The SWIG typemap library provides a language independent mechanism for diff --git a/Lib/php/const.i b/Lib/php/const.i index 6ddd403d0..08096c98b 100644 --- a/Lib/php/const.i +++ b/Lib/php/const.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * const.i * * Typemaps for constants diff --git a/Lib/php/globalvar.i b/Lib/php/globalvar.i index df8cfade7..34bd5f994 100644 --- a/Lib/php/globalvar.i +++ b/Lib/php/globalvar.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * globalvar.i * * Global variables - add the variable to PHP diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 087525be4..99181472d 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * php.swg * * PHP configuration file diff --git a/Lib/php/phpkw.swg b/Lib/php/phpkw.swg index 3d1a62511..e7d4f2fda 100644 --- a/Lib/php/phpkw.swg +++ b/Lib/php/phpkw.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * phpkw.swg * * The 'keywords' in PHP are global, ie, the following names are fine diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 5196b95b4..22f23f729 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * phprun.swg * * PHP runtime library diff --git a/Lib/php/std_common.i b/Lib/php/std_common.i index a779649dd..092bf012b 100644 --- a/Lib/php/std_common.i +++ b/Lib/php/std_common.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_common.i * * SWIG typemaps for STL - common utilities diff --git a/Lib/php/std_map.i b/Lib/php/std_map.i index c6721806b..ede5fbe30 100644 --- a/Lib/php/std_map.i +++ b/Lib/php/std_map.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_map.i * * SWIG typemaps for std::map diff --git a/Lib/php/std_pair.i b/Lib/php/std_pair.i index dc0604dc5..fe45ee676 100644 --- a/Lib/php/std_pair.i +++ b/Lib/php/std_pair.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_pair.i * * SWIG typemaps for std::pair diff --git a/Lib/php/std_string.i b/Lib/php/std_string.i index 08a7cdac9..22c953bf5 100644 --- a/Lib/php/std_string.i +++ b/Lib/php/std_string.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_string.i * * SWIG typemaps for std::string types diff --git a/Lib/php/std_vector.i b/Lib/php/std_vector.i index b54181618..4cfc94f74 100644 --- a/Lib/php/std_vector.i +++ b/Lib/php/std_vector.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_vector.i * * SWIG typemaps for std::vector types diff --git a/Lib/php/stl.i b/Lib/php/stl.i index 66b72e073..9d2e91eee 100644 --- a/Lib/php/stl.i +++ b/Lib/php/stl.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * stl.i * * Initial STL definition. extended as needed in each language diff --git a/Lib/php/typemaps.i b/Lib/php/typemaps.i index 7af301d0d..7bb8c9fa3 100644 --- a/Lib/php/typemaps.i +++ b/Lib/php/typemaps.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * typemaps.i. * * SWIG Typemap library for PHP. diff --git a/Lib/pike/pike.swg b/Lib/pike/pike.swg index e72da8fba..2ba27671e 100644 --- a/Lib/pike/pike.swg +++ b/Lib/pike/pike.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * pike.swg * * Pike configuration module. diff --git a/Lib/pike/pikerun.swg b/Lib/pike/pikerun.swg index 875fcf4e2..451a4e092 100644 --- a/Lib/pike/pikerun.swg +++ b/Lib/pike/pikerun.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * pikerun.swg * * This file contains the runtime support for Pike modules diff --git a/Lib/pike/std_string.i b/Lib/pike/std_string.i index ca1fad822..0694035bf 100644 --- a/Lib/pike/std_string.i +++ b/Lib/pike/std_string.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_string.i * * SWIG typemaps for std::string diff --git a/Lib/pointer.i b/Lib/pointer.i index 16e11b7d1..8015317d7 100644 --- a/Lib/pointer.i +++ b/Lib/pointer.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * pointer.i * ----------------------------------------------------------------------------- */ diff --git a/Lib/python/ccomplex.i b/Lib/python/ccomplex.i index 30f797d74..28872b985 100644 --- a/Lib/python/ccomplex.i +++ b/Lib/python/ccomplex.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * ccomplex.i * * C complex typemaps diff --git a/Lib/python/director.swg b/Lib/python/director.swg index ba9144539..82309dbda 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * director.swg * * This file contains support for director classes that proxy diff --git a/Lib/python/embed15.i b/Lib/python/embed15.i index 32808b1aa..3c419b9a3 100644 --- a/Lib/python/embed15.i +++ b/Lib/python/embed15.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * embed15.i * * SWIG file embedding the Python interpreter in something else. diff --git a/Lib/python/file.i b/Lib/python/file.i index 294ab9178..359c34d2c 100644 --- a/Lib/python/file.i +++ b/Lib/python/file.i @@ -1,11 +1,7 @@ /* ----------------------------------------------------------------------------- - * 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. - * * file.i * * Typemaps for FILE* - * From the ideas of Luigi Ballabio * ----------------------------------------------------------------------------- */ %types(FILE *); diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index 7d7fdfc72..efca86cf1 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * pycontainer.swg * * Python sequence <-> C++ container wrapper diff --git a/Lib/python/pyiterators.swg b/Lib/python/pyiterators.swg index 301ae4cd9..966f17279 100644 --- a/Lib/python/pyiterators.swg +++ b/Lib/python/pyiterators.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * pyiterators.swg * * Implement a python 'output' iterator for Python 2.2 or higher. diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 38632e1ab..68f5e4b48 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * pyrun.swg * * This file contains the runtime support for Python modules diff --git a/Lib/python/typemaps.i b/Lib/python/typemaps.i index 1c87de61d..5d438ecab 100644 --- a/Lib/python/typemaps.i +++ b/Lib/python/typemaps.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * typemaps.i * * Pointer handling diff --git a/Lib/ruby/director.swg b/Lib/ruby/director.swg index 9a6371ad9..60c086f5b 100644 --- a/Lib/ruby/director.swg +++ b/Lib/ruby/director.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * director.swg * * This file contains support for director classes that proxy diff --git a/Lib/ruby/rubyautodoc.swg b/Lib/ruby/rubyautodoc.swg index ade4bde1d..1e6b0d9dc 100644 --- a/Lib/ruby/rubyautodoc.swg +++ b/Lib/ruby/rubyautodoc.swg @@ -1,13 +1,8 @@ -/** - * @file rubyautodoc.swg - * @author gga - * @date Wed May 2 16:41:59 2007 - * - * @brief This file implements autodoc typemaps for some common - * ruby methods. - * - * - */ +/* ----------------------------------------------------------------------------- + * rubyautodoc.swg + * + * This file implements autodoc typemaps for some common ruby methods. + * ----------------------------------------------------------------------------- */ %define AUTODOC(func, str) %feature("autodoc", str) func; diff --git a/Lib/ruby/rubycontainer.swg b/Lib/ruby/rubycontainer.swg index 919695ec2..c93094aeb 100644 --- a/Lib/ruby/rubycontainer.swg +++ b/Lib/ruby/rubycontainer.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * rubycontainer.swg * * Ruby sequence <-> C++ container wrapper diff --git a/Lib/ruby/rubycontainer_extended.swg b/Lib/ruby/rubycontainer_extended.swg index 360e399ce..09be64aee 100644 --- a/Lib/ruby/rubycontainer_extended.swg +++ b/Lib/ruby/rubycontainer_extended.swg @@ -1,17 +1,13 @@ -/** - * @file rubycontainer_extended.swg - * @author gga - * @date Sat May 5 05:36:01 2007 - * - * @brief This file contains additional functions that make containers - * behave closer to ruby primitive types. - * However, some of these functions place some restrictions on - * the underlying object inside of the container and the iterator - * (that it has to have an == comparison function, that it has to have - * an = assignment operator, etc). - * - */ - +/* ----------------------------------------------------------------------------- + * rubycontainer_extended.swg + * + * This file contains additional functions that make containers + * behave closer to ruby primitive types. + * However, some of these functions place some restrictions on + * the underlying object inside of the container and the iterator + * (that it has to have an == comparison function, that it has to have + * an = assignment operator, etc). + * ----------------------------------------------------------------------------- */ /** * Macro used to add extend functions that require operator== in object. diff --git a/Lib/ruby/rubyiterators.swg b/Lib/ruby/rubyiterators.swg index 466ae221b..aba156a2b 100644 --- a/Lib/ruby/rubyiterators.swg +++ b/Lib/ruby/rubyiterators.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * rubyiterators.swg * * Implement a C++ 'output' iterator for Ruby. diff --git a/Lib/ruby/rubyprimtypes.swg b/Lib/ruby/rubyprimtypes.swg index c2d577995..aff35dcf1 100644 --- a/Lib/ruby/rubyprimtypes.swg +++ b/Lib/ruby/rubyprimtypes.swg @@ -1,9 +1,5 @@ /* ----------------------------------------------------------------------------- - * 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. - * * rubyprimtypes.swg - * * ----------------------------------------------------------------------------- */ /* ------------------------------------------------------------ * Primitive Types diff --git a/Lib/ruby/rubyrun.swg b/Lib/ruby/rubyrun.swg index 24d861d5a..ccc997a71 100644 --- a/Lib/ruby/rubyrun.swg +++ b/Lib/ruby/rubyrun.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * rubyrun.swg * * This file contains the runtime support for Ruby modules diff --git a/Lib/ruby/rubystdautodoc.swg b/Lib/ruby/rubystdautodoc.swg index ad70f7f8b..e14f65902 100644 --- a/Lib/ruby/rubystdautodoc.swg +++ b/Lib/ruby/rubystdautodoc.swg @@ -1,12 +1,8 @@ -/** - * @file rubystdautodoc.swg - * @author gga - * @date Wed May 2 17:20:39 2007 +/* ----------------------------------------------------------------------------- + * rubystdautodoc.swg * - * @brief This file contains autodocs for standard STL functions. - * - * - */ + * This file contains autodocs for standard STL functions. + * ----------------------------------------------------------------------------- */ // // For STL autodocumentation diff --git a/Lib/ruby/rubytracking.swg b/Lib/ruby/rubytracking.swg index 959d2087e..0a36f4a05 100644 --- a/Lib/ruby/rubytracking.swg +++ b/Lib/ruby/rubytracking.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * rubytracking.swg * * This file contains support for tracking mappings from diff --git a/Lib/ruby/rubywstrings.swg b/Lib/ruby/rubywstrings.swg index 862928c95..bb44fbc6e 100644 --- a/Lib/ruby/rubywstrings.swg +++ b/Lib/ruby/rubywstrings.swg @@ -1,15 +1,11 @@ -/** - * @file rubywstrings.swg - * @author - * @date Fri May 4 17:49:40 2007 - * - * @brief Currently, Ruby does not support Unicode or WChar properly, so these - * are still treated as char arrays for now. - * There are other libraries available that add support to this in - * ruby including WString, FXString, etc. - * - * - */ +/* ----------------------------------------------------------------------------- + * rubywstrings.swg + * + * Currently, Ruby does not support Unicode or WChar properly, so these + * are still treated as char arrays for now. + * There are other libraries available that add support to this in + * ruby including WString, FXString, etc. + * ----------------------------------------------------------------------------- */ /* ------------------------------------------------------------ * utility methods for wchar_t strings diff --git a/Lib/ruby/stl.i b/Lib/ruby/stl.i index 66b72e073..9d2e91eee 100644 --- a/Lib/ruby/stl.i +++ b/Lib/ruby/stl.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * stl.i * * Initial STL definition. extended as needed in each language diff --git a/Lib/ruby/typemaps.i b/Lib/ruby/typemaps.i index 2492e2e03..c4db82161 100644 --- a/Lib/ruby/typemaps.i +++ b/Lib/ruby/typemaps.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * typemaps.i * * Pointer handling diff --git a/Lib/std/_std_deque.i b/Lib/std/_std_deque.i index 026f373d6..c30523c0d 100644 --- a/Lib/std/_std_deque.i +++ b/Lib/std/_std_deque.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * _std_deque.i * * This file contains a generic definition of std::deque along with diff --git a/Lib/std_except.i b/Lib/std_except.i index af9803a62..769a68995 100644 --- a/Lib/std_except.i +++ b/Lib/std_except.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_except.i * * SWIG library file with typemaps to handle and throw STD exceptions in a diff --git a/Lib/stdint.i b/Lib/stdint.i index 7b48ca388..14fe6195e 100644 --- a/Lib/stdint.i +++ b/Lib/stdint.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * stdint.i * * SWIG library file for ISO C99 types: 7.18 Integer types diff --git a/Lib/stl.i b/Lib/stl.i index c3ade01ea..0b236afda 100644 --- a/Lib/stl.i +++ b/Lib/stl.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * stl.i * ----------------------------------------------------------------------------- */ diff --git a/Lib/swigarch.i b/Lib/swigarch.i index 260b60880..f5aea4678 100644 --- a/Lib/swigarch.i +++ b/Lib/swigarch.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * swigarch.i * * SWIG library file for 32bit/64bit code specialization and checking. diff --git a/Lib/swigrun.i b/Lib/swigrun.i index 17a140968..6026a9151 100644 --- a/Lib/swigrun.i +++ b/Lib/swigrun.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * swigrun.i * * Empty module (for now). Placeholder for runtime libs diff --git a/Lib/tcl/mactclinit.c b/Lib/tcl/mactclinit.c deleted file mode 100644 index 5dcf8e7f3..000000000 --- a/Lib/tcl/mactclinit.c +++ /dev/null @@ -1,93 +0,0 @@ -/* ----------------------------------------------------------------------------- - * 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. - * - * mactclinit.c - * ----------------------------------------------------------------------------- */ - -/* - * tclMacAppInit.c -- - * - * Provides a version of the Tcl_AppInit procedure for the example shell. - * - * Copyright (c) 1993-1994 Lockheed Missle & Space Company, AI Center - * Copyright (c) 1995-1997 Sun Microsystems, Inc. - * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. - * - * SCCS: @(#) tclMacAppInit.c 1.17 97/01/21 18:13:34 - */ - -#include "tcl.h" -#include "tclInt.h" -#include "tclMacInt.h" - -#if defined(THINK_C) -# include -#elif defined(__MWERKS__) -# include -short InstallConsole _ANSI_ARGS_((short fd)); -#endif - - - -/* - *---------------------------------------------------------------------- - * - * MacintoshInit -- - * - * This procedure calls initalization routines to set up a simple - * console on a Macintosh. This is necessary as the Mac doesn't - * have a stdout & stderr by default. - * - * Results: - * Returns TCL_OK if everything went fine. If it didn't the - * application should probably fail. - * - * Side effects: - * Inits the appropiate console package. - * - *---------------------------------------------------------------------- - */ - -#ifdef __cplusplus -extern "C" -#endif -extern int -MacintoshInit() -{ -#if defined(THINK_C) - - /* Set options for Think C console package */ - /* The console package calls the Mac init calls */ - console_options.pause_atexit = 0; - console_options.title = "\pTcl Interpreter"; - -#elif defined(__MWERKS__) - - /* Set options for CodeWarrior SIOUX package */ - SIOUXSettings.autocloseonquit = true; - SIOUXSettings.showstatusline = true; - SIOUXSettings.asktosaveonclose = false; - InstallConsole(0); - SIOUXSetTitle("\pTcl Interpreter"); - -#elif defined(applec) - - /* Init packages used by MPW SIOW package */ - InitGraf((Ptr)&qd.thePort); - InitFonts(); - InitWindows(); - InitMenus(); - TEInit(); - InitDialogs(nil); - InitCursor(); - -#endif - - TclMacSetEventProc((TclMacConvertEventPtr) SIOUXHandleOneEvent); - - /* No problems with initialization */ - return TCL_OK; -} diff --git a/Lib/tcl/mactkinit.c b/Lib/tcl/mactkinit.c index bfe74029c..78391d445 100644 --- a/Lib/tcl/mactkinit.c +++ b/Lib/tcl/mactkinit.c @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * mactkinit.c * * This is a support file needed to build a new version of Wish. diff --git a/Lib/tcl/std_common.i b/Lib/tcl/std_common.i index 3a6f47042..0718facb8 100644 --- a/Lib/tcl/std_common.i +++ b/Lib/tcl/std_common.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_common.i * * SWIG typemaps for STL - common utilities diff --git a/Lib/tcl/std_pair.i b/Lib/tcl/std_pair.i index 52e96674f..1448d6524 100644 --- a/Lib/tcl/std_pair.i +++ b/Lib/tcl/std_pair.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_pair.i * * Typemaps for std::pair diff --git a/Lib/tcl/std_vector.i b/Lib/tcl/std_vector.i index d913f00cc..3c8dd24b7 100644 --- a/Lib/tcl/std_vector.i +++ b/Lib/tcl/std_vector.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * std_vector.i * ----------------------------------------------------------------------------- */ diff --git a/Lib/tcl/stl.i b/Lib/tcl/stl.i index afd121341..40c7584ec 100644 --- a/Lib/tcl/stl.i +++ b/Lib/tcl/stl.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * stl.i * ----------------------------------------------------------------------------- */ diff --git a/Lib/tcl/tcl8.swg b/Lib/tcl/tcl8.swg index c33cc7681..5da1bc07c 100644 --- a/Lib/tcl/tcl8.swg +++ b/Lib/tcl/tcl8.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * tcl8.swg * * Tcl configuration module. diff --git a/Lib/tcl/tclinterp.i b/Lib/tcl/tclinterp.i index 48cdb6066..3b45b6d4b 100644 --- a/Lib/tcl/tclinterp.i +++ b/Lib/tcl/tclinterp.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * tclinterp.i * * Tcl_Interp *interp diff --git a/Lib/tcl/tclopers.swg b/Lib/tcl/tclopers.swg index 26b74203d..f113ccd19 100644 --- a/Lib/tcl/tclopers.swg +++ b/Lib/tcl/tclopers.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * tclopers.swg * * C++ overloaded operators. diff --git a/Lib/tcl/tclresult.i b/Lib/tcl/tclresult.i index ca0106432..c63b3ee19 100644 --- a/Lib/tcl/tclresult.i +++ b/Lib/tcl/tclresult.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * tclresult.i * ----------------------------------------------------------------------------- */ diff --git a/Lib/tcl/tclrun.swg b/Lib/tcl/tclrun.swg index 6387fb008..eb8bd253c 100644 --- a/Lib/tcl/tclrun.swg +++ b/Lib/tcl/tclrun.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * tclrun.swg * * This file contains the runtime support for Tcl modules and includes diff --git a/Lib/tcl/tclsh.i b/Lib/tcl/tclsh.i index 2e8ed3316..160ba8d8f 100644 --- a/Lib/tcl/tclsh.i +++ b/Lib/tcl/tclsh.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * tclsh.i * * SWIG File for building new tclsh program diff --git a/Lib/tcl/tclwstrings.swg b/Lib/tcl/tclwstrings.swg index 2d344c20f..b3b682e30 100644 --- a/Lib/tcl/tclwstrings.swg +++ b/Lib/tcl/tclwstrings.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * tclwstrings.wg * * Utility methods for wchar strings diff --git a/Lib/tcl/typemaps.i b/Lib/tcl/typemaps.i index 7c9e04a8b..8bee672cc 100644 --- a/Lib/tcl/typemaps.i +++ b/Lib/tcl/typemaps.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * typemaps.i * * Swig typemap library for Tcl8. This file contains various sorts diff --git a/Lib/tcl/wish.i b/Lib/tcl/wish.i index 077ded61f..260032a81 100644 --- a/Lib/tcl/wish.i +++ b/Lib/tcl/wish.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * wish.i * * SWIG File for making wish diff --git a/Lib/typemaps/attribute.swg b/Lib/typemaps/attribute.swg index 4bc6315b7..4dcf15e2d 100644 --- a/Lib/typemaps/attribute.swg +++ b/Lib/typemaps/attribute.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * attribute.swg * * Attribute implementation diff --git a/Lib/typemaps/carrays.swg b/Lib/typemaps/carrays.swg index 27ca11779..cdeab36b7 100644 --- a/Lib/typemaps/carrays.swg +++ b/Lib/typemaps/carrays.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * carrays.swg * * This library file contains macros that can be used to manipulate simple diff --git a/Lib/typemaps/cdata.swg b/Lib/typemaps/cdata.swg index 32b3f5a77..5baf7904c 100644 --- a/Lib/typemaps/cdata.swg +++ b/Lib/typemaps/cdata.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * cdata.swg * * This library file contains macros for manipulating raw C data as strings. diff --git a/Lib/typemaps/cmalloc.swg b/Lib/typemaps/cmalloc.swg index 15f962930..45a6ab990 100644 --- a/Lib/typemaps/cmalloc.swg +++ b/Lib/typemaps/cmalloc.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * cmalloc.swg * * This library file contains macros that can be used to create objects using diff --git a/Lib/typemaps/cpointer.swg b/Lib/typemaps/cpointer.swg index ce1af169e..f797a6895 100644 --- a/Lib/typemaps/cpointer.swg +++ b/Lib/typemaps/cpointer.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * cpointer.swg * * This library file contains macros that can be used to manipulate simple diff --git a/Lib/typemaps/cstrings.swg b/Lib/typemaps/cstrings.swg index 9144da790..c60ef6496 100644 --- a/Lib/typemaps/cstrings.swg +++ b/Lib/typemaps/cstrings.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * cstrings.swg * * This file provides typemaps and macros for dealing with various forms diff --git a/Lib/typemaps/exception.swg b/Lib/typemaps/exception.swg index 17a819cd7..12c4ea658 100644 --- a/Lib/typemaps/exception.swg +++ b/Lib/typemaps/exception.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * exceptions.swg * * This SWIG library file provides language independent exception handling diff --git a/Lib/typemaps/ptrtypes.swg b/Lib/typemaps/ptrtypes.swg index 803377afe..e1bc476ed 100644 --- a/Lib/typemaps/ptrtypes.swg +++ b/Lib/typemaps/ptrtypes.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * ptrtypes.swg * * Value typemaps (Type, const Type&) for "Ptr" types, such as swig diff --git a/Lib/typemaps/swigtypemaps.swg b/Lib/typemaps/swigtypemaps.swg index 08abab028..0e39afe4c 100644 --- a/Lib/typemaps/swigtypemaps.swg +++ b/Lib/typemaps/swigtypemaps.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * swigtypemaps.swg * * Unified Typemap Library frontend diff --git a/Lib/typemaps/typemaps.swg b/Lib/typemaps/typemaps.swg index 6e7505765..4629e8dfa 100644 --- a/Lib/typemaps/typemaps.swg +++ b/Lib/typemaps/typemaps.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * typemaps.swg * * Tcl Pointer handling diff --git a/Lib/uffi/uffi.swg b/Lib/uffi/uffi.swg index 78bd23534..41b085998 100644 --- a/Lib/uffi/uffi.swg +++ b/Lib/uffi/uffi.swg @@ -27,8 +27,6 @@ typedef long size_t; %wrapper %{ -;; $Id$ - (eval-when (compile eval) ;;; You can define your own identifier converter if you want. diff --git a/Lib/wchar.i b/Lib/wchar.i index f106a3529..14de34634 100644 --- a/Lib/wchar.i +++ b/Lib/wchar.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * wchar.i * ----------------------------------------------------------------------------- */ diff --git a/Lib/windows.i b/Lib/windows.i index 08ddc2b22..2c093dacc 100644 --- a/Lib/windows.i +++ b/Lib/windows.i @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * windows.i * * SWIG library file to support types found in windows.h as well as Microsoft diff --git a/Makefile.in b/Makefile.in index 42fa935d6..cd79e1498 100644 --- a/Makefile.in +++ b/Makefile.in @@ -184,50 +184,6 @@ java.actionexample: (cd Examples/$(LANGUAGE)/java && $(MAKE) -s $(chk-set-env) $(ACTION)) \ fi; \ -gifplot-library: - @echo $(ACTION)ing Examples/GIFPlot/Lib - @cd Examples/GIFPlot/Lib && $(MAKE) -k -s $(ACTION) - -check-gifplot: \ - check-tcl-gifplot \ - check-perl5-gifplot \ - check-python-gifplot \ - check-java-gifplot \ - check-guile-gifplot \ - check-mzscheme-gifplot \ - check-ruby-gifplot \ - check-ocaml-gifplot \ - check-octave-gifplot \ - check-php-gifplot \ - check-pike-gifplot \ - check-chicken-gifplot \ -# check-lua-gifplot \ -# check-csharp-gifplot \ -# check-modula3-gifplot - -check-%-gifplot: gifplot-library - @if test -z "$(skip-$*)"; then \ - echo $* unknown; \ - exit 1; \ - fi - @passed=true; \ - up=`$(srcdir)/Tools/capitalize $*`; \ - dir="Examples/GIFPlot/$$up"; \ - if $(skip-$*); then \ - echo skipping $$up $(ACTION); \ - elif [ ! -f $$dir/check.list ]; then \ - echo skipping $$up $(ACTION) "(no $$dir/check.list)"; \ - else \ - all=`sed '/^#/d' $$dir/check.list`; \ - for a in $$all; do \ - echo $(ACTION)ing $$dir/$$a; \ - (cd $$dir/$$a && \ - $(MAKE) -k -s $(chk-set-env) $(ACTION)) \ - || passed=false; \ - done; \ - fi; \ - test $$passed = true - # Checks testcases in the test-suite excluding those which are known to be broken check-test-suite: \ check-tcl-test-suite \ @@ -277,7 +233,7 @@ partialcheck-test-suite: partialcheck-%-test-suite: @$(MAKE) -k -s check-$*-test-suite ACTION=partialcheck NOSKIP=1 -check: check-aliveness check-ccache check-examples check-gifplot check-test-suite +check: check-aliveness check-ccache check-examples check-test-suite # Run known-to-be-broken as well as not broken testcases in the test-suite all-test-suite: \ @@ -337,7 +293,7 @@ broken-%-test-suite: # CLEAN ##################################################################### -clean: clean-objects clean-libfiles clean-examples clean-gifplot clean-test-suite clean-docs +clean: clean-objects clean-libfiles clean-examples clean-test-suite clean-docs clean-objects: clean-source clean-ccache @@ -352,9 +308,6 @@ clean-libfiles: clean-examples: @$(MAKE) -k -s check-examples ACTION=clean -clean-gifplot: - @$(MAKE) -k -s check-gifplot ACTION=clean - clean-test-suite: @$(MAKE) -k -s check-test-suite ACTION=clean NOSKIP=1 @@ -364,9 +317,6 @@ clean-%-examples: clean-%-test-suite: @$(MAKE) -k -s check-$*-test-suite ACTION=clean NOSKIP=1 -clean-%-gifplot: - @$(MAKE) -k -s check-$*-gifplot ACTION=clean - clean-ccache: test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) -s clean) @@ -388,7 +338,7 @@ maintainer-clean: clean-libfiles DISTCLEAN-DEAD = config.status config.log config.cache swig.spec Makefile mkmf.log libtool -distclean: distclean-objects clean-examples clean-gifplot distclean-test-suite clean-docs distclean-dead distclean-ccache +distclean: distclean-objects clean-examples distclean-test-suite clean-docs distclean-dead distclean-ccache distclean-objects: distclean-source diff --git a/README b/README index 3df9e506a..e7b79d2d2 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 1.3.40 (in progress) +Version: 2.0.0 (in progress) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, Ocaml, Lua, @@ -13,61 +13,6 @@ the listed languages, or to extend C/C++ programs with a scripting language. This distribution represents the latest development release of SWIG. -The guilty parties working on this are: - -Active Developers: - William Fulton (wsf@fultondesigns.co.uk) (SWIG core, Java, C#, Windows, Cygwin) - Olly Betts (olly@survex.com) (PHP) - John Lenz (Guile, MzScheme updates, Chicken module, runtime system) - Mark Gossage (mark@gossage.cjb.net) (Lua) - Joseph Wang (joe@gnacademy.org) (R) - Gonzalo Garramuno (ggarra@advancedsl.com.ar) (Ruby, Ruby's UTL) - Xavier Delacour (xavier.delacour@gmail.com) (Octave) - -Major contributors include: - Dave Beazley (dave-swig@dabeaz.com) (SWIG core, Python, Tcl, Perl) - Henning Thielemann (swig@henning-thielemann.de) (Modula3) - Matthias Köppe (mkoeppe@mail.math.uni-magdeburg.de) (Guile, MzScheme) - Luigi Ballabio (luigi.ballabio@fastwebnet.it) (STL wrapping) - Mikel Bancroft (mikel@franz.com) (Allegro CL) - Surendra Singhi (efuzzyone@netscape.net) (CLISP, CFFI) - Marcelo Matus (mmatus@acms.arizona.edu) (SWIG core, Python, UTL[python,perl,tcl,ruby]) - Art Yerkes (ayerkes@speakeasy.net) (Ocaml) - Lyle Johnson (lyle@users.sourceforge.net) (Ruby) - Charlie Savage (cfis@interserv.com) (Ruby) - Thien-Thi Nguyen (ttn@glug.org) (build/test/misc) - Richard Palmer (richard@magicality.org) (PHP) - Sam Liddicott - Anonova Ltd (saml@liddicott.com) (PHP) - Tim Hockin - Sun Microsystems (thockin@sun.com) (PHP) - Kevin Ruland (PHP) - Shibukawa Yoshiki (Japanese Translation) - Jason Stewart (jason@openinformatics.com) (Perl5) - Loic Dachary (Perl5) - David Fletcher (Perl5) - Gary Holt (Perl5) - Masaki Fukushima (Ruby) - Scott Michel (scottm@cs.ucla.edu) (Java directors) - Tiger Feng (songyanf@cs.uchicago.edu) (SWIG core) - Mark Rose (mrose@stm.lbl.gov) (Directors) - Jonah Beckford (beckford@usermail.com) (CHICKEN) - Ahmon Dancy (dancy@franz.com) (Allegro CL) - Dirk Gerrits (Allegro CL) - Neil Cawse (C#) - Harco de Hilster (Java) - Alexey Dyachenko (dyachenko@fromru.com) (Tcl) - Bob Techentin (Tcl) - Martin Froehlich (Guile) - Marcio Luis Teixeira (Guile) - Duncan Temple Lang (R) - -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 for a more complete list). - -Portions also copyrighted by companies/corporations; - Network Applied Communication Laboratory, Inc - Information-technology Promotion Agency, Japan Up-to-date SWIG related information can be found at diff --git a/Source/CParse/cparse.h b/Source/CParse/cparse.h index 9be41c60e..c17577d8c 100644 --- a/Source/CParse/cparse.h +++ b/Source/CParse/cparse.h @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * cparse.h * diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index 626958169..c5ad7b908 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * scanner.c * diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 5645d7a8b..5b6e5511a 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * parser.y * diff --git a/Source/CParse/templ.c b/Source/CParse/templ.c index 14886605f..d3b9b3d99 100644 --- a/Source/CParse/templ.c +++ b/Source/CParse/templ.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * templ.c * diff --git a/Source/CParse/util.c b/Source/CParse/util.c index efae41051..fa934ffc0 100644 --- a/Source/CParse/util.c +++ b/Source/CParse/util.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * util.c * diff --git a/Source/DOH/base.c b/Source/DOH/base.c index 15827f328..245004f87 100644 --- a/Source/DOH/base.c +++ b/Source/DOH/base.c @@ -1,13 +1,15 @@ /* ----------------------------------------------------------------------------- + * 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. + * * base.c * * This file contains the function entry points for dispatching methods on * DOH objects. A number of small utility functions are also included. - * - * 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. * ----------------------------------------------------------------------------- */ char cvsroot_base_c[] = "$Id$"; diff --git a/Source/DOH/doh.h b/Source/DOH/doh.h index 766e12a34..1ed196058 100644 --- a/Source/DOH/doh.h +++ b/Source/DOH/doh.h @@ -1,14 +1,14 @@ /* ----------------------------------------------------------------------------- + * 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. + * * doh.h * * This file describes of the externally visible functions in DOH. - * - * 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. - * - * $Id$ * ----------------------------------------------------------------------------- */ #ifndef _DOH_H diff --git a/Source/DOH/dohint.h b/Source/DOH/dohint.h index 1fc5eb7c9..661bed075 100644 --- a/Source/DOH/dohint.h +++ b/Source/DOH/dohint.h @@ -1,15 +1,14 @@ - /* ----------------------------------------------------------------------------- + * 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. + * * dohint.h * * This file describes internally managed objects. - * - * 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. - * - * $Id$ * ----------------------------------------------------------------------------- */ #ifndef _DOHINT_H diff --git a/Source/DOH/file.c b/Source/DOH/file.c index 65c2336a4..a9ee332bf 100644 --- a/Source/DOH/file.c +++ b/Source/DOH/file.c @@ -1,13 +1,15 @@ /* ----------------------------------------------------------------------------- + * 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. + * * file.c * * This file implements a file-like object that can be built around an * ordinary FILE * or integer file descriptor. - * - * 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. * ----------------------------------------------------------------------------- */ char cvsroot_file_c[] = "$Id$"; diff --git a/Source/DOH/fio.c b/Source/DOH/fio.c index f544cee64..2ef605c32 100644 --- a/Source/DOH/fio.c +++ b/Source/DOH/fio.c @@ -1,13 +1,15 @@ /* ----------------------------------------------------------------------------- + * 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. + * * fio.c * * This file implements a number of standard I/O operations included * formatted output, readline, and splitting. - * - * 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. * ----------------------------------------------------------------------------- */ char cvsroot_fio_c[] = "$Id$"; diff --git a/Source/DOH/hash.c b/Source/DOH/hash.c index 045de8b5b..87f8e3c40 100644 --- a/Source/DOH/hash.c +++ b/Source/DOH/hash.c @@ -1,12 +1,14 @@ /* ----------------------------------------------------------------------------- + * 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. + * * hash.c * * Implements a simple hash table object. - * - * 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. * ----------------------------------------------------------------------------- */ char cvsroot_hash_c[] = "$Id$"; diff --git a/Source/DOH/list.c b/Source/DOH/list.c index 7a1786299..a08cadb5a 100644 --- a/Source/DOH/list.c +++ b/Source/DOH/list.c @@ -1,12 +1,14 @@ /* ----------------------------------------------------------------------------- + * 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. + * * list.c * * Implements a simple list object. - * - * 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. * ----------------------------------------------------------------------------- */ char cvsroot_list_c[] = "$Id$"; diff --git a/Source/DOH/memory.c b/Source/DOH/memory.c index 1c6063ef3..fcacd6170 100644 --- a/Source/DOH/memory.c +++ b/Source/DOH/memory.c @@ -1,13 +1,15 @@ /* ----------------------------------------------------------------------------- + * 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. + * * memory.c * * This file implements all of DOH's memory management including allocation * of objects and checking of objects. - * - * 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. * ----------------------------------------------------------------------------- */ char cvsroot_memory_c[] = "$Id$"; diff --git a/Source/DOH/string.c b/Source/DOH/string.c index 141cd58e8..bd36c4094 100644 --- a/Source/DOH/string.c +++ b/Source/DOH/string.c @@ -1,13 +1,15 @@ /* ----------------------------------------------------------------------------- + * 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. + * * string.c * * Implements a string object that supports both sequence operations and * file semantics. - * - * 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. * ----------------------------------------------------------------------------- */ char cvsroot_string_c[] = "$Id$"; diff --git a/Source/DOH/void.c b/Source/DOH/void.c index 0be01561a..2d684b9cd 100644 --- a/Source/DOH/void.c +++ b/Source/DOH/void.c @@ -1,13 +1,15 @@ /* ----------------------------------------------------------------------------- + * 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. + * * void.c * * Implements a "void" object that is really just a DOH container around * an arbitrary C object represented as a void *. - * - * 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. * ----------------------------------------------------------------------------- */ char cvsroot_void_c[] = "$Id$"; diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index 292aa0ba6..222fb1484 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * swigwarn.h * @@ -16,8 +20,6 @@ * numbers in this file. * ----------------------------------------------------------------------------- */ -/* $Id$ */ - #ifndef SWIGWARN_H_ #define SWIGWARN_H_ diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index 1eb12630c..034799567 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * allegrocl.cxx * diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index e8397e6a6..31f27e1eb 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * allocate.cxx * diff --git a/Source/Modules/browser.cxx b/Source/Modules/browser.cxx index b1bc7349c..592e12783 100644 --- a/Source/Modules/browser.cxx +++ b/Source/Modules/browser.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * browser.cxx * diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx index 0aa933c56..c8c431e47 100644 --- a/Source/Modules/cffi.cxx +++ b/Source/Modules/cffi.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * cffi.cxx * diff --git a/Source/Modules/chicken.cxx b/Source/Modules/chicken.cxx index 12ef4b454..1d9e9c620 100644 --- a/Source/Modules/chicken.cxx +++ b/Source/Modules/chicken.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * chicken.cxx * diff --git a/Source/Modules/clisp.cxx b/Source/Modules/clisp.cxx index fa73b3a0b..95ee66bc9 100644 --- a/Source/Modules/clisp.cxx +++ b/Source/Modules/clisp.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * clisp.cxx * diff --git a/Source/Modules/contract.cxx b/Source/Modules/contract.cxx index 518dc2997..7a8543928 100644 --- a/Source/Modules/contract.cxx +++ b/Source/Modules/contract.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * contract.cxx * diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 05d5c72e1..34f4d69f3 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * csharp.cxx * diff --git a/Source/Modules/directors.cxx b/Source/Modules/directors.cxx index 158b53502..6064e1758 100644 --- a/Source/Modules/directors.cxx +++ b/Source/Modules/directors.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * directors.cxx * diff --git a/Source/Modules/emit.cxx b/Source/Modules/emit.cxx index a4cf8cebc..fde3b2457 100644 --- a/Source/Modules/emit.cxx +++ b/Source/Modules/emit.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * emit.cxx * diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index 0c72de8d0..05ceced22 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * guile.cxx * diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 72556a04b..5135fd74e 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * java.cxx * diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 38658ce9c..479615908 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * lang.cxx * diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 78cd7ce96..4640d9ed7 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * lua.cxx * diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index c824db6f9..2437b35c7 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * main.cxx * diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index b3568c0bf..e650edcb2 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * modula3.cxx * diff --git a/Source/Modules/module.cxx b/Source/Modules/module.cxx index 6a0d6bbb9..f4ab560dd 100644 --- a/Source/Modules/module.cxx +++ b/Source/Modules/module.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * module.cxx * diff --git a/Source/Modules/mzscheme.cxx b/Source/Modules/mzscheme.cxx index 28dd8ecd2..d17ccd33c 100644 --- a/Source/Modules/mzscheme.cxx +++ b/Source/Modules/mzscheme.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * mzscheme.cxx * diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index b925328a3..7108484b3 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * ocaml.cxx * diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 39b61e93b..7646da47d 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * octave.cxx * diff --git a/Source/Modules/overload.cxx b/Source/Modules/overload.cxx index 511e55004..57d7fac90 100644 --- a/Source/Modules/overload.cxx +++ b/Source/Modules/overload.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * overload.cxx * diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index eace179a7..d0c019195 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -1,10 +1,10 @@ -/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=2:tabstop=8:smarttab: - */ - /* ---------------------------------------------------------------------------- - * 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. * * perl5.cxx * diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index ee69c1864..9f91f12d4 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * php.cxx * diff --git a/Source/Modules/pike.cxx b/Source/Modules/pike.cxx index 98f63056c..e59248e95 100644 --- a/Source/Modules/pike.cxx +++ b/Source/Modules/pike.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * pike.cxx * diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index bd22e79a6..546ab9ec5 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * python.cxx * diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 8e9aa557d..f1fdff662 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * r.cxx * diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 1c13747e5..9badc0d0a 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * ruby.cxx * diff --git a/Source/Modules/s-exp.cxx b/Source/Modules/s-exp.cxx index 90791ec70..62b93f7c7 100644 --- a/Source/Modules/s-exp.cxx +++ b/Source/Modules/s-exp.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * s-exp.cxx * diff --git a/Source/Modules/swigmain.cxx b/Source/Modules/swigmain.cxx index 4208a8c6f..374d08e5a 100644 --- a/Source/Modules/swigmain.cxx +++ b/Source/Modules/swigmain.cxx @@ -1,11 +1,15 @@ /* ----------------------------------------------------------------------------- - * 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. - * - * Simplified Wrapper and Interface Generator (SWIG) + * 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. * * swigmain.cxx * + * Simplified Wrapper and Interface Generator (SWIG) + * * This file is the main entry point to SWIG. It collects the command * line options, registers built-in language modules, and instantiates * a module for code generation. If adding new language modules diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 8dec8d0af..075a209d2 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * swigmod.h * diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx index 015ac5e45..efbe28c50 100644 --- a/Source/Modules/tcl8.cxx +++ b/Source/Modules/tcl8.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * tcl8.cxx * diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index d663aed6e..e972cea05 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * typepass.cxx * diff --git a/Source/Modules/uffi.cxx b/Source/Modules/uffi.cxx index d3f8401f0..f793b5643 100644 --- a/Source/Modules/uffi.cxx +++ b/Source/Modules/uffi.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * uffi.cxx * diff --git a/Source/Modules/utils.cxx b/Source/Modules/utils.cxx index bf8211903..3fe7a2709 100644 --- a/Source/Modules/utils.cxx +++ b/Source/Modules/utils.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * utils.cxx * diff --git a/Source/Modules/xml.cxx b/Source/Modules/xml.cxx index 2edd01cf0..bcfac1acc 100644 --- a/Source/Modules/xml.cxx +++ b/Source/Modules/xml.cxx @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * xml.cxx * diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 81646171a..bcb1061c8 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * cpp.c * diff --git a/Source/Preprocessor/expr.c b/Source/Preprocessor/expr.c index 4da24a774..3e3f39480 100644 --- a/Source/Preprocessor/expr.c +++ b/Source/Preprocessor/expr.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * expr.c * diff --git a/Source/Preprocessor/preprocessor.h b/Source/Preprocessor/preprocessor.h index 3579eede2..8f98dae15 100644 --- a/Source/Preprocessor/preprocessor.h +++ b/Source/Preprocessor/preprocessor.h @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * preprocessor.h * diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 7c6837a2b..208842121 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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 * diff --git a/Source/Swig/deprecate.c b/Source/Swig/deprecate.c index 475d2c6cf..f25b9a650 100644 --- a/Source/Swig/deprecate.c +++ b/Source/Swig/deprecate.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * deprecate.c * diff --git a/Source/Swig/error.c b/Source/Swig/error.c index 156fe06a7..80eede4e3 100644 --- a/Source/Swig/error.c +++ b/Source/Swig/error.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * error.c * diff --git a/Source/Swig/fragment.c b/Source/Swig/fragment.c index 510a01875..896461b30 100644 --- a/Source/Swig/fragment.c +++ b/Source/Swig/fragment.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * fragment.c * diff --git a/Source/Swig/getopt.c b/Source/Swig/getopt.c index cbd051d9f..f6f196bfd 100644 --- a/Source/Swig/getopt.c +++ b/Source/Swig/getopt.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * getopt.c * diff --git a/Source/Swig/include.c b/Source/Swig/include.c index f42eb5d45..710a7ad71 100644 --- a/Source/Swig/include.c +++ b/Source/Swig/include.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * include.c * diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 050e5357a..3a78fe7ab 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * misc.c * diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index 013ce5929..9af0354e2 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * naming.c * diff --git a/Source/Swig/parms.c b/Source/Swig/parms.c index 9b58f5fcb..cb8176377 100644 --- a/Source/Swig/parms.c +++ b/Source/Swig/parms.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * parms.c * diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index 5dc2a091b..3f9f63a0f 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * scanner.c * diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index 3b56e98cb..69919ad55 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * stype.c * diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 7eb9ef210..428bcf06d 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * swig.h * diff --git a/Source/Swig/swigfile.h b/Source/Swig/swigfile.h index 92c7945e6..632e821e2 100644 --- a/Source/Swig/swigfile.h +++ b/Source/Swig/swigfile.h @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * swigfile.h * diff --git a/Source/Swig/swigopt.h b/Source/Swig/swigopt.h index 11eb5ba99..586f8bbc4 100644 --- a/Source/Swig/swigopt.h +++ b/Source/Swig/swigopt.h @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * swigopt.h * diff --git a/Source/Swig/swigparm.h b/Source/Swig/swigparm.h index 49ae7992e..3e6269eae 100644 --- a/Source/Swig/swigparm.h +++ b/Source/Swig/swigparm.h @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * swigparm.h * diff --git a/Source/Swig/swigscan.h b/Source/Swig/swigscan.h index 3403098df..faec4fe48 100644 --- a/Source/Swig/swigscan.h +++ b/Source/Swig/swigscan.h @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * swigscan.h * diff --git a/Source/Swig/swigtree.h b/Source/Swig/swigtree.h index 5b43006a9..6799398c9 100644 --- a/Source/Swig/swigtree.h +++ b/Source/Swig/swigtree.h @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * swigtree.h * diff --git a/Source/Swig/swigwrap.h b/Source/Swig/swigwrap.h index 0dcf88059..b1f596f72 100644 --- a/Source/Swig/swigwrap.h +++ b/Source/Swig/swigwrap.h @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * swigwrap.h * diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index 055af854f..50dde9159 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * symbol.c * diff --git a/Source/Swig/tree.c b/Source/Swig/tree.c index 14d231afa..c80c61081 100644 --- a/Source/Swig/tree.c +++ b/Source/Swig/tree.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * tree.c * diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index 401a99801..a44ecdf6d 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * typemap.c * diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index 8ff31bc0b..cafecb9a6 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * typeobj.c * diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index 9b11a08e5..19f14a2a0 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * typesys.c * diff --git a/Source/Swig/wrapfunc.c b/Source/Swig/wrapfunc.c index 11518bfc2..2c9f7c86a 100644 --- a/Source/Swig/wrapfunc.c +++ b/Source/Swig/wrapfunc.c @@ -1,6 +1,10 @@ /* ----------------------------------------------------------------------------- - * 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. * * wrapfunc.c * diff --git a/configure.in b/configure.in index b64bc860a..cf0418220 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],[1.3.40],[http://www.swig.org]) +AC_INIT([swig],[2.0.0],[http://www.swig.org]) AC_PREREQ(2.58) AC_CONFIG_SRCDIR([Source/Swig/swig.h]) AC_CONFIG_AUX_DIR([Tools/config]) @@ -2169,8 +2169,6 @@ AC_CONFIG_FILES([ \ Examples/Makefile \ Examples/guile/Makefile \ Examples/xml/Makefile \ - Examples/GIFPlot/Makefile \ - Examples/GIFPlot/Lib/Makefile \ Examples/test-suite/chicken/Makefile \ Examples/test-suite/csharp/Makefile \ Examples/test-suite/guile/Makefile \ From 30afaae7df8756f1bc3a398e685b7ff2625c4e25 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 6 Mar 2010 12:06:22 +0000 Subject: [PATCH 0049/1160] Add new GPL license headers to all source files in this branch git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11914 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/warn.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/Swig/warn.c b/Source/Swig/warn.c index a8dadc70b..dfb2e4af4 100644 --- a/Source/Swig/warn.c +++ b/Source/Swig/warn.c @@ -1,6 +1,10 @@ -/* ----------------------------------------------------------------------------- - * 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. * * warn.c * From 1f0cb53d5bb3f018d4f5393c63a225faed918da7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 4 Jun 2010 21:57:58 +0000 Subject: [PATCH 0050/1160] minor warning message changes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@12101 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/CParse/parser.y | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 5b6e5511a..b9749bf01 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2749,7 +2749,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va p = tp; def_supplied = 1; } else if (p && !tp) { /* Variadic template - tp < p */ - Swig_warning(WARN_LANG_NATIVE_UNIMPL,cparse_file, cparse_line,"Only the first variadic argument is currently supported by Swig.\n"); + Swig_warning(WARN_LANG_NATIVE_UNIMPL,cparse_file, cparse_line,"Only the first variadic template argument is currently supported.\n"); break; } } @@ -2945,9 +2945,9 @@ c_declaration : c_decl { appendChild($$,firstChild($5)); } } - | c_lambda_decl { Swig_warning(WARN_LANG_NATIVE_UNIMPL, cparse_file, cparse_line,"Swig doesn't produce wrapper code for lambda expressions and closures yet.\n"); $$ = $1; } - | USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_LANG_NATIVE_UNIMPL, cparse_file, cparse_line,"Swig doesn't support 'using' typedefs yet.\n"); $$ = 0; } - | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_LANG_NATIVE_UNIMPL, cparse_file, cparse_line,"Swig doesn't support template aliasing yet.\n"); $$ = 0; } + | c_lambda_decl { Swig_warning(WARN_LANG_NATIVE_UNIMPL, cparse_file, cparse_line,"SWIG doesn't produce wrapper code for lambda expressions and closures yet.\n"); $$ = $1; } + | USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_LANG_NATIVE_UNIMPL, cparse_file, cparse_line,"SWIG doesn't support 'using' typedefs yet.\n"); $$ = 0; } + | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_LANG_NATIVE_UNIMPL, cparse_file, cparse_line,"SWIG doesn't support template aliasing yet.\n"); $$ = 0; } ; /* ------------------------------------------------------------ From d52ef3191132cc933a7f2d46e244c7ab83ade8c9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 25 Jun 2010 21:46:57 +0000 Subject: [PATCH 0051/1160] typo fix git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@12150 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Cpp0x.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index 4466e6cfd..83b54414b 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -129,7 +129,7 @@ public:

Constructors using the std::initializer_list class are removed from the wrapped class, because the only way to access such a constructor is at compile time using the "= {}" assignment.

-

User should add another constructor with specific arguments +

Users should add another constructor with specific arguments filling the class members manually.

For now, if a user wants to fill the class components like this:

From da182a09f5f40108cd02e8d44490f315bd58b683 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 25 Jun 2010 21:48:07 +0000 Subject: [PATCH 0052/1160] add in more raw string literals for gcc-4.5 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@12151 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/cpp0x_raw_string_literals.i | 54 +++++++++++++------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/Examples/test-suite/cpp0x_raw_string_literals.i b/Examples/test-suite/cpp0x_raw_string_literals.i index 1e8515504..f5e804b78 100644 --- a/Examples/test-suite/cpp0x_raw_string_literals.i +++ b/Examples/test-suite/cpp0x_raw_string_literals.i @@ -8,8 +8,14 @@ This module also tests whether Swig correctly parses custom string delimiters. */ %module cpp0x_raw_string_literals -%warnfilter(454) c; -%warnfilter(454) d; +%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) aa; +%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) bb; +%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) ee; +%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) ff; +%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc; +%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) dd; +%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) gg; +%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) hh; %inline %{ #include @@ -20,25 +26,39 @@ using namespace std; int L = 100; int u8 = 100; int u = 100; -int U = 100; +struct UStruct { + static const int U = 100; +}; int R = 100; int LR = 100; int u8R = 100; int uR = 100; -int UR = 100; +struct URStruct { + static const int UR = 100; +}; -char *a = "ABC"; -wstring wide = L"ABC"; -//char *b = u8"ABC"; // not supported by GCC -char16_t *c = u"ABC"; -char32_t *d = U"ABC"; - -/* Raw string literals are not supported by GCC yet */ -/*char *e = R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; -wstring wide2 = LR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; -char *f = u8R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; -char16_t *g = uR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; -char32_t *h = UR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; -*/ +const char *aa = "ABC"; +wstring wide = L"ABC"; +const char *bb = u8"ABC"; +const char16_t *cc = u"ABC"; +const char32_t *dd = U"ABC"; %} + +/* Raw string literals */ + +#warning TODO: change SWIG support from old R"[ ... ]" to new R"( ... )" + +const char *ee = R"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; +wstring wide2 = LR"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; +const char *ff = u8R"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; +const char16_t *gg = uR"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; +const char32_t *hh = UR"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; +%{ +const char *ee = R"XXX(to be or "not" to be [square parenthesis] (round parenthesis), that is the question!)XXX"; +wstring wide2 = LR"XXX(to be or "not" to be [square parenthesis] (round parenthesis), that is the question!)XXX"; +const char *ff = u8R"XXX(to be or "not" to be [square parenthesis] (round parenthesis), that is the question!)XXX"; +const char16_t *gg = uR"XXX(to be or "not" to be [square parenthesis] (round parenthesis), that is the question!)XXX"; +const char32_t *hh = UR"XXX(to be or "not" to be [square parenthesis] (round parenthesis), that is the question!)XXX"; +%} + From adffcd60e1dae33d6d4ff36998eaf0412cbd80e1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 25 Jun 2010 22:54:45 +0000 Subject: [PATCH 0053/1160] Raw string literal changes in paper N3077 changes delimiters to use round brackets instead of square brackets git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@12152 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Cpp0x.html | 25 +++++----- .../test-suite/cpp0x_raw_string_literals.i | 39 +++++++-------- .../python/cpp0x_raw_string_literals_runme.py | 50 +++++++++++++++++++ Source/Swig/scanner.c | 8 +-- 4 files changed, 83 insertions(+), 39 deletions(-) create mode 100644 Examples/test-suite/python/cpp0x_raw_string_literals_runme.py diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index 83b54414b..b89b74ad0 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -460,23 +460,22 @@ arguments defined in the original template<> block:

7.2.18 New string literals

-

SWIG fully supports custom delimiters and unicode string -constants.

+

SWIG fully supports unicode string constants and raw string literals.

 // New string literals
-char      *a = "ABC";
-wstring wide = L"ABC";
-char      *b = u8"ABC";
-char16_t  *c = u"ABC";
-char32_t  *d = U"ABC";
+wstring         aa =  L"Wide string";
+const char     *bb = u8"UTF-8 string";
+const char16_t *cc =  u"UTF-16 string";
+const char32_t *dd =  U"UTF-32 string";
 
-// Custom String delimiter
-char       *e = R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX";
-wstring wide2 = LR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX";
-char       *f = u8R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX";
-char16_t   *g = uR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX";
-char32_t   *h = UR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX";
+// Raw string literals
+const char      *xx =        ")I'm an \"ascii\" \\ string.";
+const char      *ee =   R"XXX()I'm an "ascii" \ string.)XXX"; // same as xx
+wstring          ff =  LR"XXX(I'm a "raw wide" \ string.)XXX";
+const char      *gg = u8R"XXX(I'm a "raw UTF-8" \ string.)XXX";
+const char16_t  *hh =  uR"XXX(I'm a "raw UTF-16" \ string.)XXX";
+const char32_t  *ii =  UR"XXX(I'm a "raw UTF-32" \ string.)XXX";
 

Note: SWIG currently incorrectly parses the odd number of double quotes diff --git a/Examples/test-suite/cpp0x_raw_string_literals.i b/Examples/test-suite/cpp0x_raw_string_literals.i index f5e804b78..612b2baea 100644 --- a/Examples/test-suite/cpp0x_raw_string_literals.i +++ b/Examples/test-suite/cpp0x_raw_string_literals.i @@ -8,14 +8,16 @@ This module also tests whether Swig correctly parses custom string delimiters. */ %module cpp0x_raw_string_literals -%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) aa; %warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) bb; %warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) ee; -%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) ff; +%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) gg; +%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) xx; %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc; %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) dd; -%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) gg; %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) hh; +%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ii; + +%include %inline %{ #include @@ -38,27 +40,20 @@ struct URStruct { static const int UR = 100; }; -const char *aa = "ABC"; -wstring wide = L"ABC"; -const char *bb = u8"ABC"; -const char16_t *cc = u"ABC"; -const char32_t *dd = U"ABC"; +// New string literals +wstring aa = L"Wide string"; +const char *bb = u8"UTF-8 string"; +const char16_t *cc = u"UTF-16 string"; +const char32_t *dd = U"UTF-32 string"; %} /* Raw string literals */ - -#warning TODO: change SWIG support from old R"[ ... ]" to new R"( ... )" - -const char *ee = R"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; -wstring wide2 = LR"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; -const char *ff = u8R"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; -const char16_t *gg = uR"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; -const char32_t *hh = UR"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; -%{ -const char *ee = R"XXX(to be or "not" to be [square parenthesis] (round parenthesis), that is the question!)XXX"; -wstring wide2 = LR"XXX(to be or "not" to be [square parenthesis] (round parenthesis), that is the question!)XXX"; -const char *ff = u8R"XXX(to be or "not" to be [square parenthesis] (round parenthesis), that is the question!)XXX"; -const char16_t *gg = uR"XXX(to be or "not" to be [square parenthesis] (round parenthesis), that is the question!)XXX"; -const char32_t *hh = UR"XXX(to be or "not" to be [square parenthesis] (round parenthesis), that is the question!)XXX"; +%inline %{ +const char *xx = ")I'm an \"ascii\" \\ string."; +const char *ee = R"XXX()I'm an "ascii" \ string.)XXX"; +wstring ff = LR"XXX(I'm a "raw wide" \ string.)XXX"; +const char *gg = u8R"XXX(I'm a "raw UTF-8" \ string.)XXX"; +const char16_t *hh = uR"XXX(I'm a "raw UTF-16" \ string.)XXX"; +const char32_t *ii = UR"XXX(I'm a "raw UTF-32" \ string.)XXX"; %} diff --git a/Examples/test-suite/python/cpp0x_raw_string_literals_runme.py b/Examples/test-suite/python/cpp0x_raw_string_literals_runme.py new file mode 100644 index 000000000..ea7d16550 --- /dev/null +++ b/Examples/test-suite/python/cpp0x_raw_string_literals_runme.py @@ -0,0 +1,50 @@ +from cpp0x_raw_string_literals import * + +if cvar.L != 100: + raise RuntimeError + +if cvar.u8 != 100: + raise RuntimeError + +if cvar.u != 100: + raise RuntimeError + +if UStruct.U != 100: + raise RuntimeError + + +if cvar.R != 100: + raise RuntimeError + +if cvar.LR != 100: + raise RuntimeError + +if cvar.u8R != 100: + raise RuntimeError + +if cvar.uR != 100: + raise RuntimeError + +if URStruct.UR != 100: + raise RuntimeError + + +if cvar.aa != "Wide string": + raise RuntimeError + +if cvar.bb != "UTF-8 string": + raise RuntimeError, cvar.wide + +if cvar.xx != ")I'm an \"ascii\" \\ string.": + raise RuntimeError, cvar.xx + +if cvar.ee != ")I'm an \"ascii\" \\ string.": + raise RuntimeError, cvar.ee + +if cvar.ff != "I'm a \"raw wide\" \\ string.": + raise RuntimeError, cvar.ff + +if cvar.gg != "I'm a \"raw UTF-8\" \\ string.": + raise RuntimeError, cvar.gg + + diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index 3f9f63a0f..ed849bf4d 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -673,7 +673,7 @@ static int look(Scanner * s) { Swig_error(cparse_file, cparse_start_line, "Unterminated string\n"); return SWIG_TOKEN_ERROR; } - else if (c == '[') { + else if (c == '(') { state = 20; } else { @@ -698,8 +698,8 @@ static int look(Scanner * s) { Delitem(s->text, DOH_END); get_escape(s); } - } else { /* Custom delimiter string: R"XXXX[value]XXXX" */ - if (c==']') { + } else { /* Custom delimiter string: R"XXXX(value)XXXX" */ + if (c==')') { int i=0; String *end_delimiter = NewStringEmpty(); while ((c = nextchar(s)) != 0 && c!='\"') { @@ -710,7 +710,7 @@ static int look(Scanner * s) { } if (Strcmp( str_delimiter, end_delimiter )==0) { - Delete( end_delimiter ); /* Correct end delimiter ]XXXX" occured */ + Delete( end_delimiter ); /* Correct end delimiter )XXXX" occured */ Delete( str_delimiter ); str_delimiter = 0; return SWIG_TOKEN_STRING; From 8e779193bf8723b5c19a1aacbac6054ddcb7bacc Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 26 Jun 2010 22:43:21 +0000 Subject: [PATCH 0054/1160] Warning suppression for explicit template instantiations git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@12153 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/cpp0x_template_explicit.i | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/cpp0x_template_explicit.i b/Examples/test-suite/cpp0x_template_explicit.i index f05bcf850..644a03e89 100644 --- a/Examples/test-suite/cpp0x_template_explicit.i +++ b/Examples/test-suite/cpp0x_template_explicit.i @@ -3,16 +3,16 @@ using the translation unit). */ %module cpp0x_template_explicit -%warnfilter(320) std::vector; -%warnfilter(320) std::vector; + +#pragma SWIG nowarn=SWIGWARN_PARSE_EXPLICIT_TEMPLATE %inline %{ #include class A { public: - int member; - int memberFunction() { return 100; } + int member; + int memberFunction() { return 100; } }; template class std::vector; From c3b48505e2920d0b3b0c6235af4db66e5668fa39 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 26 Jun 2010 22:48:49 +0000 Subject: [PATCH 0055/1160] simple formatting changes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@12154 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../cpp0x_alternate_function_syntax.i | 2 +- Examples/test-suite/cpp0x_constexpr.i | 4 +-- Examples/test-suite/cpp0x_constructors.i | 24 +++++++-------- Examples/test-suite/cpp0x_decltype.i | 28 ++++++++--------- Examples/test-suite/cpp0x_default_delete.i | 10 +++---- .../cpp0x_explicit_conversion_operators.i | 18 +++++------ Examples/test-suite/cpp0x_function_objects.i | 2 +- Examples/test-suite/cpp0x_hash_tables.i | 24 +++++++-------- Examples/test-suite/cpp0x_initializer_list.i | 6 ++-- Examples/test-suite/cpp0x_lambda_functions.i | 30 +++++++++---------- .../test-suite/cpp0x_null_pointer_constant.i | 8 ++--- .../test-suite/cpp0x_raw_string_literals.i | 4 +-- Examples/test-suite/cpp0x_result_of.i | 6 ++-- Examples/test-suite/cpp0x_rvalue_reference.i | 20 ++++++------- Examples/test-suite/cpp0x_sizeof_object.i | 10 +++---- Examples/test-suite/cpp0x_smart_pointers.i | 2 +- Examples/test-suite/cpp0x_static_assert.i | 6 ++-- .../cpp0x_strongly_typed_enumerations.i | 2 +- .../cpp0x_template_double_brackets.i | 18 +++++------ Examples/test-suite/cpp0x_template_explicit.i | 2 +- Examples/test-suite/cpp0x_template_typedefs.i | 8 ++--- Examples/test-suite/cpp0x_thread_local.i | 4 +-- .../test-suite/cpp0x_uniform_initialization.i | 2 +- .../test-suite/cpp0x_unrestricted_unions.i | 2 +- .../test-suite/cpp0x_userdefined_literals.i | 6 ++-- .../test-suite/cpp0x_variadic_templates.i | 20 ++++++------- 26 files changed, 134 insertions(+), 134 deletions(-) diff --git a/Examples/test-suite/cpp0x_alternate_function_syntax.i b/Examples/test-suite/cpp0x_alternate_function_syntax.i index d8d0ec6c4..6726dad7c 100644 --- a/Examples/test-suite/cpp0x_alternate_function_syntax.i +++ b/Examples/test-suite/cpp0x_alternate_function_syntax.i @@ -1,4 +1,4 @@ -/* This testcase checks whether Swig correctly uses the new alternate functions +/* This testcase checks whether SWIG correctly uses the new alternate functions declarations and definitions introduced in C++0x. */ %module cpp0x_alternate_function_syntax diff --git a/Examples/test-suite/cpp0x_constexpr.i b/Examples/test-suite/cpp0x_constexpr.i index 6cae41825..ae1d292b4 100644 --- a/Examples/test-suite/cpp0x_constexpr.i +++ b/Examples/test-suite/cpp0x_constexpr.i @@ -1,4 +1,4 @@ -/* This interface tests whether Swig supports the new "constexpr" keyword +/* This interface tests whether SWIG supports the new "constexpr" keyword introduced by C++0x. */ %module cpp0x_constexpr @@ -6,7 +6,7 @@ %inline %{ class TestClass { public: - constexpr int func() { return 10; } + constexpr int func() { return 10; } }; %} diff --git a/Examples/test-suite/cpp0x_constructors.i b/Examples/test-suite/cpp0x_constructors.i index 47f030a95..2077efe0c 100644 --- a/Examples/test-suite/cpp0x_constructors.i +++ b/Examples/test-suite/cpp0x_constructors.i @@ -1,4 +1,4 @@ -/* This test checks whether Swig correctly parses the new delegating +/* This test checks whether SWIG correctly parses the new delegating constructors and constructor inheritance. */ %module cpp0x_constructors @@ -6,25 +6,25 @@ %inline %{ class BaseClass { private: - int _val; + int _val; public: - BaseClass(int iValue) { _val = iValue; } + BaseClass(int iValue) { _val = iValue; } }; class DerivedClass: public BaseClass { public: - using BaseClass::BaseClass; // Adds DerivedClass(int) constructor + using BaseClass::BaseClass; // Adds DerivedClass(int) constructor }; class A { public: - int a; - int b; - int c; - - A() : A( 10 ) {} - A(int aa) : A(aa, 20) {} - A(int aa, int bb) : A(aa, bb, 30) {} - A(int aa, int bb, int cc) { a=aa; b=bb; c=cc; } + int a; + int b; + int c; + + A() : A( 10 ) {} + A(int aa) : A(aa, 20) {} + A(int aa, int bb) : A(aa, bb, 30) {} + A(int aa, int bb, int cc) { a=aa; b=bb; c=cc; } }; %} diff --git a/Examples/test-suite/cpp0x_decltype.i b/Examples/test-suite/cpp0x_decltype.i index 316c38962..5a4292454 100644 --- a/Examples/test-suite/cpp0x_decltype.i +++ b/Examples/test-suite/cpp0x_decltype.i @@ -1,19 +1,19 @@ -/* This testcase checks whether Swig correctly uses the new 'decltype()' +/* This testcase checks whether SWIG correctly uses the new 'decltype()' introduced in C++0x. */ %module cpp0x_decltype %inline %{ -class A { -public: - int i; - decltype(i) j; - - auto foo( decltype(i) a ) -> decltype(i) { - if (a==5) - return 10; - else - return 0; - } -}; -%} + class A { + public: + int i; + decltype(i) j; + + auto foo( decltype(i) a ) -> decltype(i) { + if (a==5) + return 10; + else + return 0; + } + }; + %} diff --git a/Examples/test-suite/cpp0x_default_delete.i b/Examples/test-suite/cpp0x_default_delete.i index affcea58e..bdb74ffb1 100644 --- a/Examples/test-suite/cpp0x_default_delete.i +++ b/Examples/test-suite/cpp0x_default_delete.i @@ -1,4 +1,4 @@ -/* This testcase checks whether Swig correctly parses the default and delete +/* This testcase checks whether SWIG correctly parses the default and delete keywords which keep or remove default C++ object construction functions. */ %module cpp0x_default_delete @@ -14,11 +14,11 @@ public: }; struct A1 { - void f(int i); - void f(double i) = delete; /* Don't cast double to int. Compiler returns an error */ + void f(int i); + void f(double i) = delete; /* Don't cast double to int. Compiler returns an error */ }; struct A2 { - void f(int i); - template void f(T) = delete; /* Only accept int */ + void f(int i); + template void f(T) = delete; /* Only accept int */ }; %} diff --git a/Examples/test-suite/cpp0x_explicit_conversion_operators.i b/Examples/test-suite/cpp0x_explicit_conversion_operators.i index 6532efb23..313b5e878 100644 --- a/Examples/test-suite/cpp0x_explicit_conversion_operators.i +++ b/Examples/test-suite/cpp0x_explicit_conversion_operators.i @@ -1,4 +1,4 @@ -/* This interface checks whether Swig correctly compiles the new +/* This interface checks whether SWIG correctly compiles the new explicit conversion operators feature introduced in C++0x. */ %module cpp0x_explicit_conversion_operators @@ -7,22 +7,22 @@ class U { public: - int u; + int u; }; class V { public: - int v; + int v; }; class TestClass { public: - //implicit converting constructor - TestClass( U const &val ) { t=val.u; } - // explicit constructor - explicit TestClass( V const &val ) { t=val.v; } - - int t; + //implicit converting constructor + TestClass( U const &val ) { t=val.u; } + // explicit constructor + explicit TestClass( V const &val ) { t=val.v; } + + int t; }; %} diff --git a/Examples/test-suite/cpp0x_function_objects.i b/Examples/test-suite/cpp0x_function_objects.i index f480addc7..e864137c7 100644 --- a/Examples/test-suite/cpp0x_function_objects.i +++ b/Examples/test-suite/cpp0x_function_objects.i @@ -1,4 +1,4 @@ -/* This testcase checks whether Swig correctly parses function objects +/* This testcase checks whether SWIG correctly parses function objects and the templates for the functions (signature). Function objects are objects which overload the operator() function. */ %module cpp0x_function_objects diff --git a/Examples/test-suite/cpp0x_hash_tables.i b/Examples/test-suite/cpp0x_hash_tables.i index b5eb505a4..fff630ca0 100644 --- a/Examples/test-suite/cpp0x_hash_tables.i +++ b/Examples/test-suite/cpp0x_hash_tables.i @@ -23,21 +23,21 @@ using namespace std; class MyClass { public: - set getSet() { return _set; } - void addSet(int elt) { _set.insert(_set.begin(), elt); } -// map getMap() { return _map; } -// void addMap(int elt1, int elt2) { _map.insert(make_pair(elt1, elt2)); } + set getSet() { return _set; } + void addSet(int elt) { _set.insert(_set.begin(), elt); } +// map getMap() { return _map; } +// void addMap(int elt1, int elt2) { _map.insert(make_pair(elt1, elt2)); } - unordered_set getUnorderedSet() { return _unordered_set; } - void addUnorderedSet(int elt) { _unordered_set.insert(_unordered_set.begin(), elt); } -// unordered_map getUnorderedMap() { return _unordered_map; } -// void addUnorderedMap(int elt1, int elt2) { _unordered_map.insert(make_pair(elt1, elt2)); } + unordered_set getUnorderedSet() { return _unordered_set; } + void addUnorderedSet(int elt) { _unordered_set.insert(_unordered_set.begin(), elt); } +// unordered_map getUnorderedMap() { return _unordered_map; } +// void addUnorderedMap(int elt1, int elt2) { _unordered_map.insert(make_pair(elt1, elt2)); } private: - set _set; -// map _map; + set _set; +// map _map; - unordered_set _unordered_set; -// unordered_map _unordered_map; + unordered_set _unordered_set; +// unordered_map _unordered_map; }; %} diff --git a/Examples/test-suite/cpp0x_initializer_list.i b/Examples/test-suite/cpp0x_initializer_list.i index 3d6893033..aa2791833 100644 --- a/Examples/test-suite/cpp0x_initializer_list.i +++ b/Examples/test-suite/cpp0x_initializer_list.i @@ -1,4 +1,4 @@ -/* This testcase checks whether Swig correctly uses the new initializer_list +/* This testcase checks whether SWIG correctly uses the new initializer_list introduced in C++0x. */ %module cpp0x_initializer_list %warnfilter(520) A; @@ -8,8 +8,8 @@ class A { public: - A( std::initializer_list ) {} - A() {} + A( std::initializer_list ) {} + A() {} }; %} diff --git a/Examples/test-suite/cpp0x_lambda_functions.i b/Examples/test-suite/cpp0x_lambda_functions.i index 7719b59f4..7ca4c08d8 100644 --- a/Examples/test-suite/cpp0x_lambda_functions.i +++ b/Examples/test-suite/cpp0x_lambda_functions.i @@ -1,34 +1,34 @@ -/* This testcase checks whether Swig correctly parses the lambda expressions +/* This testcase checks whether SWIG correctly parses the lambda expressions and closure syntax introduced in C++0x. - Swig supports only lambda syntax and doesn't produce any wrapper code for + SWIG supports only lambda syntax and doesn't produce any wrapper code for this. */ %module cpp0x_lambda_functions %inline %{ struct A { - /* Defined lambda function with return value. */ - auto lambda1 = [](int x, int y) -> int { return x+y; }; - - /* Defined lambda function without return value. - Return value is calculated by compiler, if the function contains a - single statement "return expr;". */ - auto lambda2 = [](int x, int y) { return x+y; }; + /* Defined lambda function with return value. */ + auto lambda1 = [](int x, int y) -> int { return x+y; }; + + /* Defined lambda function without return value. + Return value is calculated by compiler, if the function contains a + single statement "return expr;". */ + auto lambda2 = [](int x, int y) { return x+y; }; }; int runLambda1() { - A myA; - return myA.lambda1(5,6); + A myA; + return myA.lambda1(5,6); } int runLambda2() { - A myA; - return myA.lambda2(5,6); + A myA; + return myA.lambda2(5,6); } /* Inline defined lambda function. */ int runLambda3() { - auto myLambda = [](int x, int y) { return x+y; }; - return myLambda(5,6); + auto myLambda = [](int x, int y) { return x+y; }; + return myLambda(5,6); } %} diff --git a/Examples/test-suite/cpp0x_null_pointer_constant.i b/Examples/test-suite/cpp0x_null_pointer_constant.i index 9057f04be..7069f3f25 100644 --- a/Examples/test-suite/cpp0x_null_pointer_constant.i +++ b/Examples/test-suite/cpp0x_null_pointer_constant.i @@ -1,4 +1,4 @@ -/* This testcase checks whether Swig correctly treats the new nullptr_t +/* This testcase checks whether SWIG correctly treats the new nullptr_t constant introduced in C++0x. */ @@ -9,8 +9,8 @@ class A { public: - A() : _myA(std::nullptr) { } - - A *_myA; + A() : _myA(std::nullptr) { } + + A *_myA; }; %} diff --git a/Examples/test-suite/cpp0x_raw_string_literals.i b/Examples/test-suite/cpp0x_raw_string_literals.i index 612b2baea..39a8bb641 100644 --- a/Examples/test-suite/cpp0x_raw_string_literals.i +++ b/Examples/test-suite/cpp0x_raw_string_literals.i @@ -1,11 +1,11 @@ -/* This module tests whether Swig correctly parses: +/* This module tests whether SWIG correctly parses: - ordinary strings (char_t) - L wide strings (wchar_t) - u8 unicode8 strings (char_t) - u unicode16 strings (char16_t) - U unicode32 strings (char32_t) - This module also tests whether Swig correctly parses custom string delimiters. + This module also tests whether SWIG correctly parses custom string delimiters. */ %module cpp0x_raw_string_literals %warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) bb; diff --git a/Examples/test-suite/cpp0x_result_of.i b/Examples/test-suite/cpp0x_result_of.i index 4def13a38..42ff6c068 100644 --- a/Examples/test-suite/cpp0x_result_of.i +++ b/Examples/test-suite/cpp0x_result_of.i @@ -1,4 +1,4 @@ -/* This testcase checks whether Swig correctly uses the new result_of class +/* This testcase checks whether SWIG correctly uses the new result_of class and its templating capabilities introduced in C++0x. */ %module cpp0x_result_of @@ -7,12 +7,12 @@ #include double square(double x) { - return (x * x); + return (x * x); } template typename std::result_of::type test_result_impl(Fun fun, Arg arg) { - return fun(arg); + return fun(arg); } %} diff --git a/Examples/test-suite/cpp0x_rvalue_reference.i b/Examples/test-suite/cpp0x_rvalue_reference.i index f6c764aca..5821c5ccf 100644 --- a/Examples/test-suite/cpp0x_rvalue_reference.i +++ b/Examples/test-suite/cpp0x_rvalue_reference.i @@ -1,21 +1,21 @@ -/* This testcase checks whether Swig correctly parses the double ampersand && +/* This testcase checks whether SWIG correctly parses the double ampersand && move operator which is currently mapped to the reference & operator. */ %module cpp0x_rvalue_reference %inline %{ class A { public: - int getAcopy() { return _a; } - int *getAptr() { return &_a; } - int &getAref() { return _a; } - int &&getAmove() { return _a; } + int getAcopy() { return _a; } + int *getAptr() { return &_a; } + int &getAref() { return _a; } + int &&getAmove() { return _a; } - void setAcopy(int a) { _a = a; } - void setAptr(int *a) { _a = *a; } - void setAref(int &a) { _a = a; } - void setAmove(int &&a) { _a = a; } + void setAcopy(int a) { _a = a; } + void setAptr(int *a) { _a = *a; } + void setAref(int &a) { _a = a; } + void setAmove(int &&a) { _a = a; } private: - int _a; + int _a; }; %} diff --git a/Examples/test-suite/cpp0x_sizeof_object.i b/Examples/test-suite/cpp0x_sizeof_object.i index 89e659e81..72299786d 100644 --- a/Examples/test-suite/cpp0x_sizeof_object.i +++ b/Examples/test-suite/cpp0x_sizeof_object.i @@ -1,16 +1,16 @@ -/* This testcase checks whether Swig correctly uses the sizeof() on the +/* This testcase checks whether SWIG correctly uses the sizeof() on the concrete objects and not only types introduced in C++0x. */ %module cpp0x_sizeof_object %inline %{ struct B { - unsigned long member1; - long long member2; - char member3; + unsigned long member1; + long long member2; + char member3; }; struct A { - B member; + B member; }; const int a = sizeof(A::member); diff --git a/Examples/test-suite/cpp0x_smart_pointers.i b/Examples/test-suite/cpp0x_smart_pointers.i index 4f04e1941..400f7ebae 100644 --- a/Examples/test-suite/cpp0x_smart_pointers.i +++ b/Examples/test-suite/cpp0x_smart_pointers.i @@ -1,4 +1,4 @@ -/* This testcase checks whether Swig correctly uses the new general-purpose +/* This testcase checks whether SWIG correctly uses the new general-purpose smart pointers introduced in C++0x: - shared_ptr - weak_ptr diff --git a/Examples/test-suite/cpp0x_static_assert.i b/Examples/test-suite/cpp0x_static_assert.i index 28c244c87..d6413a1e5 100644 --- a/Examples/test-suite/cpp0x_static_assert.i +++ b/Examples/test-suite/cpp0x_static_assert.i @@ -1,4 +1,4 @@ -/* This test case checks whether swig correctly parses and ignores the +/* This test case checks whether SWIG correctly parses and ignores the keywords "static_assert()" inside the class or struct. */ %module cpp0x_static_assert @@ -6,12 +6,12 @@ %inline %{ template struct Check1 { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); + static_assert(sizeof(int) <= sizeof(T), "not big enough"); }; template class Check2 { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); + static_assert(sizeof(int) <= sizeof(T), "not big enough"); }; %} diff --git a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i index 4476122fe..776af5822 100644 --- a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i +++ b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i @@ -1,4 +1,4 @@ -/* This testcase checks whether Swig produces the correct wrapper for the +/* This testcase checks whether SWIG produces the correct wrapper for the strongly typed enums. Enums with the same type are comparable. Enum classes require support for nested classes. */ %module cpp0x_strongly_typed_enumerations diff --git a/Examples/test-suite/cpp0x_template_double_brackets.i b/Examples/test-suite/cpp0x_template_double_brackets.i index 74d2fc768..79d77e704 100644 --- a/Examples/test-suite/cpp0x_template_double_brackets.i +++ b/Examples/test-suite/cpp0x_template_double_brackets.i @@ -1,4 +1,4 @@ -/* This interface checks whether Swig supports the new double angled brackets +/* This interface checks whether SWIG supports the new double angled brackets in the template syntax without having a space inbetween. This feature was introduced in new C++0x standard. */ @@ -10,21 +10,21 @@ std::map< int,std::map > n; class ABC { public: - int a; - int operator>>(ABC &); - int operator<<(ABC &); + int a; + int operator>>(ABC &); + int operator<<(ABC &); }; template class ABC2 { public: - int a; + int a; - template - U operator>>(ABC &); + template + U operator>>(ABC &); - template - U operator<<(ABC &); + template + U operator<<(ABC &); }; %} diff --git a/Examples/test-suite/cpp0x_template_explicit.i b/Examples/test-suite/cpp0x_template_explicit.i index 644a03e89..bbc216ba0 100644 --- a/Examples/test-suite/cpp0x_template_explicit.i +++ b/Examples/test-suite/cpp0x_template_explicit.i @@ -1,4 +1,4 @@ -/* This unit tests whether Swig correctly parses the code and makes wrappers +/* This unit tests whether SWIG correctly parses the code and makes wrappers for the new C++0x extern templates (explicit template instantiation without using the translation unit). */ diff --git a/Examples/test-suite/cpp0x_template_typedefs.i b/Examples/test-suite/cpp0x_template_typedefs.i index 3164b86ae..877539bfb 100644 --- a/Examples/test-suite/cpp0x_template_typedefs.i +++ b/Examples/test-suite/cpp0x_template_typedefs.i @@ -1,12 +1,12 @@ -/* This testcase checks whether Swig correctly parses the template aliasing. */ +/* This testcase checks whether SWIG correctly parses the template aliasing. */ %module cpp0x_template_typedefs %inline %{ template< typename T1, typename T2, int > class SomeType { - T1 a; - T2 b; - int c; + T1 a; + T2 b; + int c; }; template< typename T2 > diff --git a/Examples/test-suite/cpp0x_thread_local.i b/Examples/test-suite/cpp0x_thread_local.i index 35ad970e7..2ec633319 100644 --- a/Examples/test-suite/cpp0x_thread_local.i +++ b/Examples/test-suite/cpp0x_thread_local.i @@ -1,11 +1,11 @@ -/* This testcase checks whether Swig correctly parses the 'thread_local' +/* This testcase checks whether SWIG correctly parses the 'thread_local' keyword before the member type and name. */ %module cpp0x_thread_local %inline %{ struct A { - thread_local int val; + thread_local int val; }; %} diff --git a/Examples/test-suite/cpp0x_uniform_initialization.i b/Examples/test-suite/cpp0x_uniform_initialization.i index 39ed73180..083fac377 100644 --- a/Examples/test-suite/cpp0x_uniform_initialization.i +++ b/Examples/test-suite/cpp0x_uniform_initialization.i @@ -1,4 +1,4 @@ -/* This testcase checks whether Swig syntactically correctly parses the curly +/* This testcase checks whether SWIG syntactically correctly parses the curly brackets {} for uniform member initialization. */ %module cpp0x_uniform_initialization diff --git a/Examples/test-suite/cpp0x_unrestricted_unions.i b/Examples/test-suite/cpp0x_unrestricted_unions.i index a534df466..1cadd7f7c 100644 --- a/Examples/test-suite/cpp0x_unrestricted_unions.i +++ b/Examples/test-suite/cpp0x_unrestricted_unions.i @@ -1,4 +1,4 @@ -/* This testcase checks whether Swig correctly parses the support for types +/* This testcase checks whether SWIG correctly parses the support for types without the defined trivial constructor in the unions. */ %module cpp0x_unrestricted_unions diff --git a/Examples/test-suite/cpp0x_userdefined_literals.i b/Examples/test-suite/cpp0x_userdefined_literals.i index 4488a573b..6604a4293 100644 --- a/Examples/test-suite/cpp0x_userdefined_literals.i +++ b/Examples/test-suite/cpp0x_userdefined_literals.i @@ -1,4 +1,4 @@ -/* This testcase checks whether Swig correctly parses the user-defined literals +/* This testcase checks whether SWIG correctly parses the user-defined literals for the string introduced in C++0x. */ %module cpp0x_userdefined_literals @@ -6,9 +6,9 @@ #include struct OutputType { - int val; + int val; - OutputType(int v) { v=val; } + OutputType(int v) { v=val; } }; /* Note: GCC doesn't support user-defined literals yet! */ diff --git a/Examples/test-suite/cpp0x_variadic_templates.i b/Examples/test-suite/cpp0x_variadic_templates.i index b9320a0d1..c287194d4 100644 --- a/Examples/test-suite/cpp0x_variadic_templates.i +++ b/Examples/test-suite/cpp0x_variadic_templates.i @@ -1,4 +1,4 @@ -/* This testcase checks whether Swig correctly parses and generates the code +/* This testcase checks whether SWIG correctly parses and generates the code for variadic templates. This covers the variadic number of arguments inside the template brackets, new functions sizeof... and multiple inheritance using variadic number of classes. @@ -45,19 +45,19 @@ template struct SizeOf { %inline %{ class A { public: - A() { - a = 100; - } - - int a; + A() { + a = 100; + } + + int a; }; class B { public: - B() { - b = 200; - } - int b; + B() { + b = 200; + } + int b; }; template class MultiInherit : public BaseClasses... { From d8cc75946b236f08f9561a82867997e1021f96ab Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 18 Jul 2010 00:19:22 +0000 Subject: [PATCH 0056/1160] Improved C++0x rvalue reference implementation differentiating lvalue and rvalue references. The previous implementation treated rvalue references as lvalue references which leads to a number of different wrapping issues. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@12160 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 1 + Examples/test-suite/cpp0x_rvalue_reference.i | 3 +- Examples/test-suite/cpp0x_rvalue_reference2.i | 83 +++++++++++ .../python/cpp0x_rvalue_reference_runme.py | 4 +- Lib/csharp/csharp.swg | 40 ++++-- Source/CParse/parser.y | 136 ++++++++++++++++-- Source/Modules/php.cxx | 2 + Source/Swig/cwrap.c | 48 +++++++ Source/Swig/stype.c | 58 ++++++-- Source/Swig/swig.h | 4 + Source/Swig/typemap.c | 6 +- Source/Swig/typeobj.c | 39 +++++ Source/Swig/typesys.c | 7 + 13 files changed, 399 insertions(+), 32 deletions(-) create mode 100644 Examples/test-suite/cpp0x_rvalue_reference2.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 992406535..443cf2256 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -409,6 +409,7 @@ CPP0X_TEST_CASES = \ cpp0x_function_objects \ cpp0x_strongly_typed_enumerations \ cpp0x_rvalue_reference \ + cpp0x_rvalue_reference2 \ cpp0x_variadic_templates \ cpp0x_alternate_function_syntax \ cpp0x_userdefined_literals \ diff --git a/Examples/test-suite/cpp0x_rvalue_reference.i b/Examples/test-suite/cpp0x_rvalue_reference.i index 5821c5ccf..67686bc0f 100644 --- a/Examples/test-suite/cpp0x_rvalue_reference.i +++ b/Examples/test-suite/cpp0x_rvalue_reference.i @@ -3,12 +3,13 @@ %module cpp0x_rvalue_reference %inline %{ +#include class A { public: int getAcopy() { return _a; } int *getAptr() { return &_a; } int &getAref() { return _a; } - int &&getAmove() { return _a; } + int &&getAmove() { return std::move(_a); } void setAcopy(int a) { _a = a; } void setAptr(int *a) { _a = *a; } diff --git a/Examples/test-suite/cpp0x_rvalue_reference2.i b/Examples/test-suite/cpp0x_rvalue_reference2.i new file mode 100644 index 000000000..a3e9d1784 --- /dev/null +++ b/Examples/test-suite/cpp0x_rvalue_reference2.i @@ -0,0 +1,83 @@ +%module cpp0x_rvalue_reference2 + +// This testcase tests lots of different places that rvalue reference syntax can be used + +%typemap(in) Something && "/*in Something && typemap*/" +%rename(OperatorRValue) Thingy::operator int&&; +%rename(memberFnRenamed) memberFn(short &&i); +%feature("compactdefaultargs") Thingy::compactDefaultArgs(const bool &&b = (const bool &&)PublicGlobalTrue, const UserDef &&u = (const UserDef &&)PublicUserDef); +%feature("exception") Thingy::privateDefaultArgs(const bool &&b = (const bool &&)PrivateTrue); +%ignore Thingy::operator=; + +%inline %{ +#include +struct UserDef { + int a; +}; +static const bool PublicGlobalTrue = true; +static const UserDef PublicUserDef = UserDef(); +struct Thingy { + typedef int Integer; + int val; + int &lvalref; + int &&rvalref; + Thingy(int v) : val(v), lvalref(val), rvalref(22) {} + void refIn(long &i) {} + void rvalueIn(long &&i) {} + short && rvalueInOut(short &&i) { return std::move(i); } + static short && staticRvalueInOut(short &&i) { return std::move(i); } + // test both primitive and user defined rvalue reference default arguments and compactdefaultargs + void compactDefaultArgs(const bool &&b = (const bool &&)PublicGlobalTrue, const UserDef &&u = (const UserDef &&)PublicUserDef) {} + void privateDefaultArgs(const bool &&b = (const bool &&)PrivateTrue) {} + operator int &&() {} + Thingy& operator=(const Thingy& rhs) { + val = rhs.val; + lvalref = rhs.lvalref; + rvalref = rhs.rvalref; + } +private: + static const bool PrivateTrue = true; + Thingy(); +}; + +short && globalRvalueInOut(short &&i) { return std::move(i); } + +Thingy &&globalrrval = Thingy(55); + +short && func(short &&i) { return std::move(i); } +Thingy getit() { return Thingy(22); } + +void rvalrefFunction1(int &&v = (int &&)5) {} +void rvalrefFunctionBYVAL(short (Thingy::*memFunc)(short)) {} +void rvalrefFunctionLVALUE(short &(Thingy::*memFunc)(short &)) {} +void rvalrefFunction2(short && (Thingy::*memFunc)(short &&)) {} +void rvalrefFunction3(short && (*memFunc)(short &&)) {} + +template struct RemoveReference { + typedef T type; +}; + +template struct RemoveReference { + typedef T type; +}; + +template struct RemoveReference { + typedef T type; +}; + +template <> struct RemoveReference { + typedef short type; +}; + +// like std::move +template typename RemoveReference::type&& Move(T&& t) { + return static_cast::type&&>(t); +} +%} + +%template(RemoveReferenceDouble) RemoveReference; +%template(RemoveReferenceFloat) RemoveReference; +%template(RemoveReferenceShort) RemoveReference; +%template(MoveFloat) Move; + + diff --git a/Examples/test-suite/python/cpp0x_rvalue_reference_runme.py b/Examples/test-suite/python/cpp0x_rvalue_reference_runme.py index acf296716..43fbc997e 100644 --- a/Examples/test-suite/python/cpp0x_rvalue_reference_runme.py +++ b/Examples/test-suite/python/cpp0x_rvalue_reference_runme.py @@ -16,7 +16,9 @@ a.setAref(ptr) if a.getAcopy() != 5: raise RunTimeError, ("after A::setAref(): int A::getAcopy() value is ", a.getAcopy(), " should be 5") -a.setAmove(ptr) +rvalueref = a.getAmove() + +a.setAmove(rvalueref) if a.getAcopy() != 5: raise RunTimeError, ("after A::setAmove(): int A::getAcopy() value is ", a.getAcopy(), " should be 5") diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index 204cf4b2f..ecdf88b25 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -125,6 +125,10 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %typemap(imtype, out="IntPtr") SWIGTYPE & "HandleRef" %typemap(cstype) SWIGTYPE & "$csclassname" +%typemap(ctype) SWIGTYPE && "void *" +%typemap(imtype, out="IntPtr") SWIGTYPE && "HandleRef" +%typemap(cstype) SWIGTYPE && "$csclassname" + /* pointer to a class member */ %typemap(ctype) SWIGTYPE (CLASS::*) "char *" %typemap(imtype) SWIGTYPE (CLASS::*) "string" @@ -397,6 +401,11 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type type is null", 0); return $null; } %} +%typemap(in, canthrow=1) SWIGTYPE && %{ $1 = ($1_ltype)$input; + if (!$1) { + SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type type is null", 0); + return $null; + } %} %typemap(out) SWIGTYPE * %{ $result = (void *)$1; %} %typemap(out, fragment="SWIG_PackData") SWIGTYPE (CLASS::*) %{ char buf[128]; @@ -405,6 +414,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { $result = SWIG_csharp_string_callback(buf); %} %typemap(out) SWIGTYPE & %{ $result = (void *)$1; %} +%typemap(out) SWIGTYPE && %{ $result = (void *)$1; %} %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE * %{ $result = ($1_ltype)$input; %} @@ -522,6 +532,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { SWIGTYPE, SWIGTYPE *, SWIGTYPE &, + SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" @@ -539,7 +550,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, error_msg); return $null; %} -%typemap(throws, canthrow=1) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [ANY] +%typemap(throws, canthrow=1) SWIGTYPE, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE *, SWIGTYPE [ANY] %{ (void)$1; SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "C++ $1_type exception thrown"); return $null; %} @@ -570,7 +581,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { "$csinput" %typemap(csin) char *, char *&, char[ANY], char[] "$csinput" %typemap(csin) SWIGTYPE "$&csclassname.getCPtr($csinput)" -%typemap(csin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] "$csclassname.getCPtr($csinput)" +%typemap(csin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] "$csclassname.getCPtr($csinput)" %typemap(csin) SWIGTYPE (CLASS::*) "$csclassname.getCMemberPtr($csinput)" /* The csout typemap is used for converting function return types from the return type @@ -653,6 +664,10 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { $csclassname ret = new $csclassname($imcall, $owner);$excode return ret; } +%typemap(csout, excode=SWIGEXCODE) SWIGTYPE && { + $csclassname ret = new $csclassname($imcall, $owner);$excode + return ret; + } %typemap(csout, excode=SWIGEXCODE) SWIGTYPE *, SWIGTYPE [] { IntPtr cPtr = $imcall; $csclassname ret = (cPtr == IntPtr.Zero) ? null : new $csclassname(cPtr, $owner);$excode @@ -666,7 +681,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { /* Properties */ -%typemap(csvarin, excode=SWIGEXCODE2) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ +%typemap(csvarin, excode=SWIGEXCODE2) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ set { $imcall;$excode } %} @@ -767,6 +782,11 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { $csclassname ret = new $csclassname($imcall, $owner);$excode return ret; } %} +%typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE && %{ + get { + $csclassname ret = new $csclassname($imcall, $owner);$excode + return ret; + } %} %typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE *, SWIGTYPE [] %{ get { IntPtr cPtr = $imcall; @@ -814,13 +834,13 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { /* Typemaps used for the generation of proxy and type wrapper class code */ -%typemap(csbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" -%typemap(csclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "public class" -%typemap(cscode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" -%typemap(csimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "\nusing System;\nusing System.Runtime.InteropServices;\n" +%typemap(csbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" +%typemap(csclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "public class" +%typemap(cscode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" +%typemap(csimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "\nusing System;\nusing System.Runtime.InteropServices;\n" %typemap(csinterfaces) SWIGTYPE "IDisposable" -%typemap(csinterfaces) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" -%typemap(csinterfaces_derived) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" +%typemap(csinterfaces) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" +%typemap(csinterfaces_derived) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" // Proxy classes (base classes, ie, not derived classes) %typemap(csbody) SWIGTYPE %{ @@ -851,7 +871,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %} // Typewrapper classes -%typemap(csbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] %{ +%typemap(csbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] %{ private HandleRef swigCPtr; internal $csclassname(IntPtr cPtr, bool futureUse) { diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index b9749bf01..bb644f9db 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3968,15 +3968,19 @@ cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN { template_para Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); if (error) $$ = 0; - } - | TEMPLATE cpptype idcolon { /* Explicit template instantiation */ + } + + /* Explicit template instantiation */ + | TEMPLATE cpptype idcolon { Swig_warning(WARN_PARSE_EXPLICIT_TEMPLATE, cparse_file, cparse_line, "Explicit template instantiation ignored.\n"); - $$ = 0; - } - | EXTERN TEMPLATE cpptype idcolon { /* Explicit template instantiation without the translation unit */ + $$ = 0; + } + + /* Explicit template instantiation without the translation unit */ + | EXTERN TEMPLATE cpptype idcolon { Swig_warning(WARN_PARSE_EXPLICIT_TEMPLATE, cparse_file, cparse_line, "Explicit template instantiation ignored.\n"); - $$ = 0; - } + $$ = 0; + } ; cpp_temp_possible: c_decl { @@ -4395,6 +4399,23 @@ cpp_conversion_operator : storage_class COPERATOR type pointer LPAREN parms RPAR Setattr($$,"conversion_operator","1"); add_symbols($$); } + | storage_class COPERATOR type LAND LPAREN parms RPAREN cpp_vend { + SwigType *decl; + $$ = new_node("cdecl"); + Setattr($$,"type",$3); + Setattr($$,"name",$2); + Setattr($$,"storage",$1); + decl = NewStringEmpty(); + SwigType_add_rvalue_reference(decl); + SwigType_add_function(decl,$6); + if ($8.qualifier) { + SwigType_push(decl,$8.qualifier); + } + Setattr($$,"decl",decl); + Setattr($$,"parms",$6); + Setattr($$,"conversion_operator","1"); + add_symbols($$); + } | storage_class COPERATOR type LPAREN parms RPAREN cpp_vend { String *t = NewStringEmpty(); @@ -4902,6 +4923,15 @@ declarator : pointer notso_direct_declarator { } $$.type = $1; } + | pointer LAND notso_direct_declarator { + $$ = $3; + SwigType_add_rvalue_reference($1); + if ($$.type) { + SwigType_push($1,$$.type); + Delete($$.type); + } + $$.type = $1; + } | direct_declarator { $$ = $1; if (!$$.type) $$.type = NewStringEmpty(); @@ -4920,7 +4950,7 @@ declarator : pointer notso_direct_declarator { /* Adds one S/R conflict */ $$ = $2; $$.type = NewStringEmpty(); - SwigType_add_reference($$.type); + SwigType_add_rvalue_reference($$.type); if ($2.type) { SwigType_push($$.type,$2.type); Delete($2.type); @@ -4990,6 +5020,15 @@ declarator : pointer notso_direct_declarator { } $$.type = $1; } + | pointer LAND PERIOD PERIOD PERIOD notso_direct_declarator { + $$ = $6; + SwigType_add_rvalue_reference($1); + if ($$.type) { + SwigType_push($1,$$.type); + Delete($$.type); + } + $$.type = $1; + } | PERIOD PERIOD PERIOD direct_declarator { $$ = $4; if (!$$.type) $$.type = NewStringEmpty(); @@ -5008,7 +5047,7 @@ declarator : pointer notso_direct_declarator { /* Adds one S/R conflict */ $$ = $5; $$.type = NewStringEmpty(); - SwigType_add_reference($$.type); + SwigType_add_rvalue_reference($$.type); if ($5.type) { SwigType_push($$.type,$5.type); Delete($5.type); @@ -5047,6 +5086,16 @@ declarator : pointer notso_direct_declarator { } $$.type = $1; } + | pointer idcolon DSTAR LAND PERIOD PERIOD PERIOD notso_direct_declarator { + $$ = $8; + SwigType_add_memberpointer($1,$2); + SwigType_add_rvalue_reference($1); + if ($$.type) { + SwigType_push($1,$$.type); + Delete($$.type); + } + $$.type = $1; + } | idcolon DSTAR AND PERIOD PERIOD PERIOD notso_direct_declarator { SwigType *t = NewStringEmpty(); $$ = $7; @@ -5058,6 +5107,17 @@ declarator : pointer notso_direct_declarator { } $$.type = t; } + | idcolon DSTAR LAND PERIOD PERIOD PERIOD notso_direct_declarator { + SwigType *t = NewStringEmpty(); + $$ = $7; + SwigType_add_memberpointer(t,$1); + SwigType_add_rvalue_reference(t); + if ($$.type) { + SwigType_push(t,$$.type); + Delete($$.type); + } + $$.type = t; + } ; notso_direct_declarator : idcolon { @@ -5191,6 +5251,13 @@ direct_declarator : idcolon { } SwigType_add_reference($$.type); } + | LPAREN LAND direct_declarator RPAREN { + $$ = $3; + if (!$$.type) { + $$.type = NewStringEmpty(); + } + SwigType_add_rvalue_reference($$.type); + } | LPAREN idcolon DSTAR direct_declarator RPAREN { SwigType *t; $$ = $4; @@ -5283,6 +5350,13 @@ abstract_declarator : pointer { $$.parms = 0; $$.have_parms = 0; } + | pointer LAND { + $$.type = $1; + SwigType_add_rvalue_reference($$.type); + $$.id = 0; + $$.parms = 0; + $$.have_parms = 0; + } | pointer AND direct_abstract_declarator { $$ = $3; SwigType_add_reference($1); @@ -5292,6 +5366,15 @@ abstract_declarator : pointer { } $$.type = $1; } + | pointer LAND direct_abstract_declarator { + $$ = $3; + SwigType_add_rvalue_reference($1); + if ($$.type) { + SwigType_push($1,$$.type); + Delete($$.type); + } + $$.type = $1; + } | direct_abstract_declarator { $$ = $1; } @@ -5304,6 +5387,15 @@ abstract_declarator : pointer { Delete($2.type); } } + | LAND direct_abstract_declarator { + $$ = $2; + $$.type = NewStringEmpty(); + SwigType_add_rvalue_reference($$.type); + if ($2.type) { + SwigType_push($$.type,$2.type); + Delete($2.type); + } + } | AND { $$.id = 0; $$.parms = 0; @@ -5311,6 +5403,13 @@ abstract_declarator : pointer { $$.type = NewStringEmpty(); SwigType_add_reference($$.type); } + | LAND { + $$.id = 0; + $$.parms = 0; + $$.have_parms = 0; + $$.type = NewStringEmpty(); + SwigType_add_rvalue_reference($$.type); + } | idcolon DSTAR { $$.type = NewStringEmpty(); SwigType_add_memberpointer($$.type,$1); @@ -5821,6 +5920,13 @@ valexpr : exprnum { $$ = $1; } $$.val = NewStringf("(%s) %s", SwigType_str($2.val,0), $5.val); } } + | LPAREN expr LAND RPAREN expr %prec CAST { + $$ = $5; + if ($5.type != T_STRING) { + SwigType_add_rvalue_reference($2.val); + $$.val = NewStringf("(%s) %s", SwigType_str($2.val,0), $5.val); + } + } | LPAREN expr pointer AND RPAREN expr %prec CAST { $$ = $6; if ($6.type != T_STRING) { @@ -5829,10 +5935,22 @@ valexpr : exprnum { $$ = $1; } $$.val = NewStringf("(%s) %s", SwigType_str($2.val,0), $6.val); } } + | LPAREN expr pointer LAND RPAREN expr %prec CAST { + $$ = $6; + if ($6.type != T_STRING) { + SwigType_push($2.val,$3); + SwigType_add_rvalue_reference($2.val); + $$.val = NewStringf("(%s) %s", SwigType_str($2.val,0), $6.val); + } + } | AND expr { $$ = $2; $$.val = NewStringf("&%s",$2.val); } + | LAND expr { + $$ = $2; + $$.val = NewStringf("&&%s",$2.val); + } | STAR expr { $$ = $2; $$.val = NewStringf("*%s",$2.val); diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 9f91f12d4..94abf58da 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1160,6 +1160,7 @@ public: break; } case T_REFERENCE: + case T_RVALUE_REFERENCE: case T_USER: case T_ARRAY: Clear(value); @@ -1930,6 +1931,7 @@ public: break; case T_POINTER: case T_REFERENCE: + case T_RVALUE_REFERENCE: case T_USER: if (is_shadow(t)) { return NewString(Char(is_shadow(t))); diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 208842121..25dfaea14 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -68,6 +68,19 @@ static String *Swig_clocal(SwigType *t, const_String_or_char_ptr name, const_Str Delete(lstrname); } break; + case T_RVALUE_REFERENCE: + if (value) { + String *lstrname = SwigType_lstr(t, name); + String *lstr = SwigType_lstr(t, 0); + Printf(decl, "%s = (%s) &%s_defrvalue", lstrname, lstr, name); + Delete(lstrname); + Delete(lstr); + } else { + String *lstrname = SwigType_lstr(t, name); + Printf(decl, "%s = 0", lstrname); + Delete(lstrname); + } + break; case T_VOID: break; case T_VARARGS: @@ -229,6 +242,34 @@ int Swig_cargs(Wrapper *w, ParmList *p) { Delete(defname); Delete(defvalue); } + } else if (tycode == T_RVALUE_REFERENCE) { + if (pvalue) { + SwigType *tvalue; + String *defname, *defvalue, *rvalue, *qvalue; + rvalue = SwigType_typedef_resolve_all(pvalue); + qvalue = SwigType_typedef_qualified(rvalue); + defname = NewStringf("%s_defrvalue", lname); + tvalue = Copy(type); + SwigType_del_rvalue_reference(tvalue); + tycode = SwigType_type(tvalue); + if (tycode != T_USER) { + /* plain primitive type, we copy the the def value */ + String *lstr = SwigType_lstr(tvalue, defname); + defvalue = NewStringf("%s = %s", lstr, qvalue); + Delete(lstr); + } else { + /* user type, we copy the reference value */ + String *str = SwigType_str(type, defname); + defvalue = NewStringf("%s = %s", str, qvalue); + Delete(str); + } + Wrapper_add_localv(w, defname, defvalue, NIL); + Delete(tvalue); + Delete(rvalue); + Delete(qvalue); + Delete(defname); + Delete(defvalue); + } } else if (!pvalue && ((tycode == T_POINTER) || (tycode == T_STRING))) { pvalue = (String *) "0"; } @@ -269,6 +310,13 @@ String *Swig_cresult(SwigType *t, const_String_or_char_ptr name, const_String_or Delete(lstr); } break; + case T_RVALUE_REFERENCE: + { + String *lstr = SwigType_lstr(t, 0); + Printf(fcall, "%s = (%s) &", name, lstr); + Delete(lstr); + } + break; case T_USER: Printf(fcall, "%s = ", name); break; diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index 69919ad55..a8abf88fe 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -43,6 +43,7 @@ char cvsroot_stype_c[] = "$Id$"; * * 'p.' = Pointer (*) * 'r.' = Reference (&) + * 'z.' = Rvalue reference (&&) * 'a(n).' = Array of size n [n] * 'f(..,..).' = Function with arguments (args) * 'q(str).' = Qualifier (such as const or volatile) (const, volatile) @@ -235,7 +236,7 @@ int SwigType_isconst(SwigType *t) { int SwigType_ismutable(SwigType *t) { int r; SwigType *qt = SwigType_typedef_resolve_all(t); - if (SwigType_isreference(qt) || SwigType_isarray(qt)) { + if (SwigType_isreference(qt) || SwigType_isrvalue_reference(qt) || SwigType_isarray(qt)) { Delete(SwigType_pop(qt)); } r = SwigType_isconst(qt); @@ -423,6 +424,16 @@ SwigType *SwigType_default(SwigType *t) { Delete(nr); #else def = NewString("r.SWIGTYPE"); +#endif + } else if (SwigType_isrvalue_reference(r)) { +#ifdef SWIG_NEW_TYPE_DEFAULT + SwigType *nr = Copy(r); + SwigType_del_rvalue_reference(nr); + def = NewString("z."); + SwigType_add_default(def, nr); + Delete(nr); +#else + def = NewString("z.SWIGTYPE"); #endif } else if (SwigType_isarray(r)) { if (strcmp(cr, "a().SWIGTYPE") == 0) { @@ -597,6 +608,12 @@ String *SwigType_str(SwigType *s, const_String_or_char_ptr id) { Insert(result, 0, "("); Append(result, ")"); } + } else if (SwigType_isrvalue_reference(element)) { + Insert(result, 0, "&&"); + if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { + Insert(result, 0, "("); + Append(result, ")"); + } } else if (SwigType_isarray(element)) { DOH *size; Append(result, "["); @@ -661,7 +678,7 @@ SwigType *SwigType_ltype(SwigType *s) { SwigType *tt = Copy(tc); td = 0; while ((td = SwigType_typedef_resolve(tt))) { - if (td && (SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td))) { + if (td && (SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td) || SwigType_isrvalue_reference(td))) { /* We need to use the typedef type */ Delete(tt); tt = td; @@ -701,6 +718,13 @@ SwigType *SwigType_ltype(SwigType *s) { Append(result, "p."); } firstarray = 0; + } else if (SwigType_isrvalue_reference(element)) { + if (notypeconv) { + Append(result, element); + } else { + Append(result, "p."); + } + firstarray = 0; } else if (SwigType_isarray(element) && firstarray) { if (notypeconv) { Append(result, element); @@ -765,6 +789,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(); @@ -777,14 +802,14 @@ String *SwigType_rcaststr(SwigType *s, const_String_or_char_ptr name) { rs = s; } - if ((SwigType_isconst(rs) || SwigType_isarray(rs) || SwigType_isreference(rs))) { + if ((SwigType_isconst(rs) || SwigType_isarray(rs) || SwigType_isreference(rs) || SwigType_isrvalue_reference(rs))) { td = 0; } else { td = SwigType_typedef_resolve(rs); } if (td) { - if ((SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td))) { + if ((SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td) || SwigType_isrvalue_reference(td))) { elements = SwigType_split(td); } else { elements = SwigType_split(rs); @@ -836,6 +861,14 @@ String *SwigType_rcaststr(SwigType *s, const_String_or_char_ptr name) { Append(result, ")"); } isreference = 1; + } else if (SwigType_isrvalue_reference(element)) { + Insert(result, 0, "&&"); + if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { + Insert(result, 0, "("); + Append(result, ")"); + } + isreference = 1; + clear = 0; } else if (SwigType_isarray(element)) { DOH *size; if (firstarray && !isreference) { @@ -865,6 +898,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, " "); @@ -880,10 +914,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); } @@ -914,6 +950,12 @@ String *SwigType_lcaststr(SwigType *s, const_String_or_char_ptr name) { Delete(str); if (name) Append(result, name); + } else if (SwigType_isrvalue_reference(s)) { + String *str = SwigType_str(s, 0); + Printf(result, "(%s)", str); + Delete(str); + if (name) + Append(result, name); } else if (SwigType_isqualifier(s)) { String *lstr = SwigType_lstr(s, 0); Printf(result, "(%s)%s", lstr, name); diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 428bcf06d..07f27774d 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -94,6 +94,7 @@ extern "C" { #define T_FUNCTION 37 #define T_MPOINTER 38 #define T_VARARGS 39 +#define T_RVALUE_REFERENCE 40 #define T_SYMBOL 98 #define T_ERROR 99 @@ -123,6 +124,8 @@ extern "C" { extern SwigType *SwigType_pop_arrays(SwigType *t); extern SwigType *SwigType_add_reference(SwigType *t); extern SwigType *SwigType_del_reference(SwigType *t); + extern SwigType *SwigType_add_rvalue_reference(SwigType *t); + extern SwigType *SwigType_del_rvalue_reference(SwigType *t); extern SwigType *SwigType_add_qualifier(SwigType *t, const_String_or_char_ptr qual); extern SwigType *SwigType_del_qualifier(SwigType *t); extern SwigType *SwigType_add_function(SwigType *t, ParmList *parms); @@ -146,6 +149,7 @@ extern "C" { extern int SwigType_ismemberpointer(SwigType *t); extern int SwigType_isreference(SwigType *t); extern int SwigType_isreference_return(SwigType *t); + extern int SwigType_isrvalue_reference(SwigType *t); extern int SwigType_isarray(SwigType *t); extern int SwigType_prefix_is_simple_1D_array(SwigType *t); extern int SwigType_isfunction(SwigType *t); diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index a44ecdf6d..6595944a0 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -942,13 +942,13 @@ int typemap_replace_vars(String *s, ParmList *locals, SwigType *type, SwigType * $*n_ltype */ - if (SwigType_ispointer(ftype) || (SwigType_isarray(ftype)) || (SwigType_isreference(ftype))) { - if (!(SwigType_isarray(type) || SwigType_ispointer(type) || SwigType_isreference(type))) { + if (SwigType_ispointer(ftype) || (SwigType_isarray(ftype)) || (SwigType_isreference(ftype)) || (SwigType_isrvalue_reference(ftype))) { + if (!(SwigType_isarray(type) || SwigType_ispointer(type) || SwigType_isreference(type) || SwigType_isrvalue_reference(type))) { star_type = Copy(ftype); } else { star_type = Copy(type); } - if (!SwigType_isreference(star_type)) { + if (!(SwigType_isreference(star_type) || SwigType_isrvalue_reference(star_type))) { if (SwigType_isarray(star_type)) { SwigType_del_element(star_type); } else { diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index cafecb9a6..a72a102aa 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -45,6 +45,7 @@ char cvsroot_typeobj_c[] = "$Id$"; * * 'p.' = Pointer (*) * 'r.' = Reference (&) + * 'z.' = Rvalue reference (&&) * 'a(n).' = Array of size n [n] * 'f(..,..).' = Function with arguments (args) * 'q(str).' = Qualifier (such as const or volatile) (const, volatile) @@ -75,6 +76,7 @@ char cvsroot_typeobj_c[] = "$Id$"; * * SwigType_add_pointer() * SwigType_add_reference() + * SwigType_add_rvalue_reference() * SwigType_add_array() * * These are used to build new types. There are also functions to undo these @@ -82,12 +84,14 @@ char cvsroot_typeobj_c[] = "$Id$"; * * SwigType_del_pointer() * SwigType_del_reference() + * SwigType_del_rvalue_reference() * SwigType_del_array() * * In addition, there are query functions * * SwigType_ispointer() * SwigType_isreference() + * SwigType_isrvalue_reference() * SwigType_isarray() * * Finally, there are some data extraction functions that can be used to @@ -409,6 +413,41 @@ int SwigType_isreference(SwigType *t) { return 0; } +/* ----------------------------------------------------------------------------- + * Rvalue References + * + * SwigType_add_rvalue_reference() + * SwigType_del_rvalue_reference() + * SwigType_isrvalue_reference() + * + * Add, remove, and test if a type is a rvalue reference. The deletion and query + * functions take into account qualifiers (if any). + * ----------------------------------------------------------------------------- */ + +SwigType *SwigType_add_rvalue_reference(SwigType *t) { + Insert(t, 0, "z."); + return t; +} + +SwigType *SwigType_del_rvalue_reference(SwigType *t) { + char *c = Char(t); + int check = strncmp(c, "z.", 2); + assert(check == 0); + Delslice(t, 0, 2); + return t; +} + +int SwigType_isrvalue_reference(SwigType *t) { + char *c; + if (!t) + return 0; + c = Char(t); + if (strncmp(c, "z.", 2) == 0) { + return 1; + } + return 0; +} + /* ----------------------------------------------------------------------------- * Qualifiers * diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index 19f14a2a0..f6baa5a83 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -1206,6 +1206,8 @@ int SwigType_type(SwigType *t) { return T_ARRAY; if (strncmp(c, "r.", 2) == 0) return T_REFERENCE; + if (strncmp(c, "z.", 2) == 0) + return T_RVALUE_REFERENCE; if (strncmp(c, "m(", 2) == 0) return T_MPOINTER; if (strncmp(c, "q(", 2) == 0) { @@ -1540,6 +1542,11 @@ void SwigType_remember_clientdata(SwigType *t, const_String_or_char_ptr clientda SwigType_del_reference(tt); SwigType_add_pointer(tt); SwigType_remember_clientdata(tt, clientdata); + } else if (SwigType_isrvalue_reference(t)) { + SwigType *tt = Copy(t); + SwigType_del_rvalue_reference(tt); + SwigType_add_pointer(tt); + SwigType_remember_clientdata(tt, clientdata); } } From 996455b50e5bbfff54b274538c856034b0c55515 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 24 Jul 2010 00:20:11 +0000 Subject: [PATCH 0057/1160] sort out c++0x lambda tests and reorder cpp0x tests git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@12182 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 45 ++++++++++--------- Examples/test-suite/cpp0x_lambda_functions.i | 45 +++++++++++++------ .../java/cpp0x_lambda_functions_runme.java | 28 ++++++++++++ 3 files changed, 82 insertions(+), 36 deletions(-) create mode 100644 Examples/test-suite/java/cpp0x_lambda_functions_runme.java diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index f3414f931..5ee7df02f 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -430,33 +430,34 @@ CPP_TEST_CASES += \ # C++0x test cases. CPP0X_TEST_CASES = \ - cpp0x_template_double_brackets \ + cpp0x_alternate_function_syntax \ + cpp0x_constexpr \ + cpp0x_decltype \ + cpp0x_default_delete \ cpp0x_explicit_conversion_operators \ - cpp0x_raw_string_literals \ - cpp0x_static_assert \ - cpp0x_template_explicit \ - cpp0x_uniform_initialization \ cpp0x_function_objects \ - cpp0x_strongly_typed_enumerations \ + cpp0x_initializer_list \ + cpp0x_raw_string_literals \ + cpp0x_result_of \ cpp0x_rvalue_reference \ cpp0x_rvalue_reference2 \ - cpp0x_variadic_templates \ - cpp0x_alternate_function_syntax \ - cpp0x_userdefined_literals \ - cpp0x_decltype \ - cpp0x_result_of \ - cpp0x_default_delete \ cpp0x_sizeof_object \ - cpp0x_initializer_list -# cpp0x_template_typedefs # not supported by any compiler yet -# cpp0x_hash_types # not fully implemented yet -# cpp0x_constructors # not supported by any compiler yet -# cpp0x_lambda_functions # not supported by GCC or MSVC yet -# cpp0x_null_pointer_constant # not supported by any compiler yet -# cpp0x_unrestricted_unions # not supported by any compiler yet -# cpp0x_smart_pointers # not supported by standard library yet -# cpp0x_constexpr # not supported by any compiler yet -# cpp0x_thread_local # not supported by any compiler yet + cpp0x_static_assert \ + cpp0x_strongly_typed_enumerations \ + cpp0x_template_double_brackets \ + cpp0x_template_explicit \ + cpp0x_uniform_initialization \ + cpp0x_userdefined_literals \ + cpp0x_variadic_templates + +# cpp0x_constructors \ # not supported by any compiler yet +# cpp0x_hash_tables \ # not fully implemented yet +# cpp0x_lambda_functions \ # not supported by GCC or MSVC yet +# cpp0x_null_pointer_constant \ # not supported by any compiler yet +# cpp0x_smart_pointers \ # not supported by standard library yet +# cpp0x_template_typedefs \ # not supported by any compiler yet +# cpp0x_thread_local \ # not supported by any compiler yet +# cpp0x_unrestricted_unions \ # not supported by any compiler yet # Broken C++0x test cases. CPP0X_TEST_BROKEN = diff --git a/Examples/test-suite/cpp0x_lambda_functions.i b/Examples/test-suite/cpp0x_lambda_functions.i index 7ca4c08d8..56235e9a6 100644 --- a/Examples/test-suite/cpp0x_lambda_functions.i +++ b/Examples/test-suite/cpp0x_lambda_functions.i @@ -5,30 +5,47 @@ */ %module cpp0x_lambda_functions -%inline %{ -struct A { - /* Defined lambda function with return value. */ - auto lambda1 = [](int x, int y) -> int { return x+y; }; +#pragma SWIG nowarn=SWIGWARN_LANG_NATIVE_UNIMPL - /* Defined lambda function without return value. - Return value is calculated by compiler, if the function contains a - single statement "return expr;". */ - auto lambda2 = [](int x, int y) { return x+y; }; -}; +%inline %{ +/* Defined lambda function with return value. */ +auto lambda1 = [](int x, int y) -> int { return x+y; }; + +/* Defined lambda function without return value. + Return value is calculated by compiler, if the function contains a + single statement "return expr;". */ +auto lambda2 = [](int x, int y) { return x+y; }; + +auto lambda3 = [&](int x, int y) { return x+y; }; +auto lambda4 = [=](int x, int y) { return x+y; }; +int thing = 0; +auto lambda5 = [=,&thing]() { return thing;}; int runLambda1() { - A myA; - return myA.lambda1(5,6); + return lambda1(5,6); } int runLambda2() { - A myA; - return myA.lambda2(5,6); + return lambda2(5,6); +} + +int runLambda3() { + return lambda3(5,6); +} + +int runLambda4() { + return lambda4(5,6); +} + +int runLambda5() { + thing++; + return lambda5(); } /* Inline defined lambda function. */ -int runLambda3() { +int runLambdaInline() { auto myLambda = [](int x, int y) { return x+y; }; return myLambda(5,6); } %} + diff --git a/Examples/test-suite/java/cpp0x_lambda_functions_runme.java b/Examples/test-suite/java/cpp0x_lambda_functions_runme.java new file mode 100644 index 000000000..79545f87e --- /dev/null +++ b/Examples/test-suite/java/cpp0x_lambda_functions_runme.java @@ -0,0 +1,28 @@ +import cpp0x_lambda_functions.*; + +public class cpp0x_lambda_functions_runme { + + static { + try { + System.loadLibrary("cpp0x_lambda_functions"); + } 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); + } + } + + private static void check(int received, int expected) { + if (expected != received) + throw new RuntimeException("check failed, expected: " + expected + " received: " + received); + } + + public static void main(String argv[]) + { + check(cpp0x_lambda_functions.runLambda1(), 11); + check(cpp0x_lambda_functions.runLambda2(), 11); + check(cpp0x_lambda_functions.runLambda3(), 11); + check(cpp0x_lambda_functions.runLambda4(), 11); + check(cpp0x_lambda_functions.runLambda5(), 1); + check(cpp0x_lambda_functions.runLambda5(), 2); + } +} From 368f442508a3a22d1153622bf7d4e685134c9985 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 24 Jul 2010 00:31:10 +0000 Subject: [PATCH 0058/1160] html fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@12183 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Cpp0x.html | 182 +++++++++++++++++++++--------------------- 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index b89b74ad0..f983de165 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -19,7 +19,7 @@

  • Initializer lists
  • Uniform initialization
  • Type inference -
  • Range-based for-loop +
  • Range-based for-loop
  • Lambda functions and expressions
  • Alternate function syntax
  • Object construction improvement @@ -31,8 +31,8 @@
  • Unrestricted unions
  • Variadic templates
  • New string literals -
  • User-defined literals -
  • Thread-local storage +
  • User-defined literals +
  • Thread-local storage
  • Defaulting/deleting of standard functions on C++ objects
  • Type long long int
  • Static assertions @@ -43,7 +43,7 @@
  • Threading facilities
  • Tuple types and hash tables
  • Regular expressions -
  • General-purpose smart pointers +
  • General-purpose smart pointers
  • Extensible random number facility
  • Wrapper reference
  • Polymorphous wrappers for function objects @@ -77,7 +77,7 @@ yet.

    SWIG correctly parses the new operator && the same as the reference operator &.

    The wrapper for the following code is correctly produced:

    -
    +
     class MyClass {
       MyClass(MyClass&& p) : ptr(p.ptr) {p.ptr = 0;}
       MyClass& operator=(MyClass&& p) {
    @@ -85,25 +85,25 @@ class MyClass {
         return *this;
       }
     };
    -
    +

    7.2.2 Generalized constant expressions

    SWIG correctly parses the keyword constexpr, but ignores its functionality. Constant functions cannot be used as constants.

    -
    +
     constexpr int myConstFunc() { return 10; }
     const int a = myConstFunc(); // results in error
    -
    +

    Users needs to use values or predefined constants when defining the new constant value:

    -
    +
     #define MY_CONST 10
     constexpr int myConstFunc() { return MY_CONST; }
     const int a = MY_CONST; // ok
    -
    +

    7.2.3 Extern template

    @@ -111,7 +111,7 @@ const int a = MY_CONST; // ok

    SWIG correctly parses the keywords extern template. However, the explicit template instantiation is not used by SWIG, a %template is still required.

    -
    +
     extern template class std::vector<MyClass>; // explicit instantiation
     
     ...
    @@ -121,7 +121,7 @@ public:
       int a;
       int b;
     };
    -
    +

    7.2.4 Initializer lists

    @@ -134,29 +134,29 @@ filling the class members manually.

    For now, if a user wants to fill the class components like this:

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

    You should add another constructor using the std::vector for example:

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

    And call it from your target language, for example, in Python:

    -
    +
     >>> a2 = A( [1,2,3,4] )
    -
    +

    7.2.5 Uniform initialization

    @@ -164,7 +164,7 @@ A a1 = {1,2,3,4};

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

    -
    +
     struct BasicStruct {
      int x;
      double y;
    @@ -179,17 +179,17 @@ struct AltStruct {
     
     BasicStruct var1{5, 3.2}; // only fills the struct components
     AltStruct var2{2, 4.3};   // calls the constructor
    -
    +

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

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

    7.2.6 Type inference

    @@ -197,16 +197,16 @@ AltStruct var2{2, 4.3}; // calls the constructor

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

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

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

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

    7.2.7 Range-based for-loop

    @@ -218,9 +218,9 @@ ignores it.

    SWIG correctly parses the Lambda functions syntax. For example:

    -
    -auto myLambdaFunc = [this]() { this->SomePrivateMemberFunction() };
    -
    +
    +auto sum = [](int x, int y) -> int { return x+y; };
    +

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

    @@ -229,36 +229,36 @@ for closures (scope of the lambda functions) in the target languages.

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

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

    can now be written as in C++0x:

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

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

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

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

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

    7.2.10 Object construction improvement

    @@ -267,7 +267,7 @@ auto square(float a, float b) -> decltype(a); (constructor delegation and constructor inheritance) into the class using the using keyword.

    -
    +
     class BaseClass {
     public:
       BaseClass(int iValue);
    @@ -277,7 +277,7 @@ class DerivedClass: public BaseClass {
       public:
       using BaseClass::BaseClass; // Adds DerivedClass(int) constructor
     };
    -
    +

    7.2.11 Null pointer constant

    @@ -289,15 +289,15 @@ constant in the target language.

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

    -
    +
     enum class MyEnum : unsigned int;
    -
    +

    The strongly typed enumerations are treated the same as the ordinary and anonymous enums. This is because SWIG doesn't support nested classes. This is usually not a problem, however, there may be some name clashes. For example, the following code:

    -
    +
     class Color {
       enum class PrintingColors : unsigned int {
         Cyan, Magenta, Yellow, Black
    @@ -312,11 +312,11 @@ class Color {
         Yellow, Orange, Red, Magenta, Blue, Cyan, Green, Pink, Black, White
       };
     };
    -
    +

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

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

    7.2.13 Double angle brackets

    @@ -343,17 +343,17 @@ class AllColors { template block, if found inside it at the top level, or as the right shift operator >> otherwise.

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

    The bit shifting operator using the parenthesis around the expressions can be forced. For example

    -
    +
     template<(5>>3)>
     class A {};
    -
    +

    7.2.14 Explicit conversion operators

    @@ -361,7 +361,7 @@ class A {};

    SWIG correctly parses the keyword explicit both for operators and constructors. For example:

    -
    +
     class U {
     public:
             int u;
    @@ -381,7 +381,7 @@ public:
     
             int t;
     };
    -
    +

    The usage of explicit constructors and operators is somehow specific to C++ when assigning the value @@ -397,15 +397,15 @@ to achieve particular copy and compare behaviours.

    SWIG currently parses the new using name = syntax, but ignores the definition:

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

    You should still define the typedefs using the old syntax:

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

    7.2.16 Unrestricted unions

    @@ -414,7 +414,7 @@ typedef void (*PFD)(double); // The old style define the trivial constructor. For example, the wrapper for the following code is correctly produced:

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

    7.2.17 Variadic templates

    @@ -435,34 +435,34 @@ union P { block, variadic class inheritance and variadic constructor and initializers) with some limitations. The following code is correctly parsed:

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

    Support for the variadic sizeof() function was also introduced:

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

    For now however, the %template directive only accepts at most the number of arguments defined in the original template<> block:

    -
    +
     %template(MyVariant1) ClassName<>         // ok
     %template(MyVariant2) ClassName<int>      // ok
     %template(MyVariant3) ClassName<int, int> // too many arguments
    -
    +

    7.2.18 New string literals

    SWIG fully supports unicode string constants and raw string literals.

    -
    +
     // New string literals
     wstring         aa =  L"Wide string";
     const char     *bb = u8"UTF-8 string";
    @@ -476,7 +476,7 @@ wstring          ff =  LR"XXX(I'm a "raw wide" \ string.)XXX";
     const char      *gg = u8R"XXX(I'm a "raw UTF-8" \ string.)XXX";
     const char16_t  *hh =  uR"XXX(I'm a "raw UTF-16" \ string.)XXX";
     const char32_t  *ii =  UR"XXX(I'm a "raw UTF-32" \ string.)XXX";
    -
    +

    Note: SWIG currently incorrectly parses the odd number of double quotes inside the string due to SWIG's C++ preprocessor.

    @@ -486,13 +486,13 @@ inside the string due to SWIG's C++ preprocessor.

    SWIG correctly parses the new operator""_mysuffix() functions.

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

    The %rename currently doesn't parse the double quotes. Please rename the functions in the code using the #define preprocessor directive.

    @@ -503,11 +503,11 @@ rename the functions in the code using the #define preprocessor directive.

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

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

    The new C++0x threading libraries are ignored because each SWIG target language offers its own threading facilities.

    @@ -518,14 +518,14 @@ its own threading facilities.

    SWIG correctly parses the = delete and = default keywords. For example:

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

    This feature is specific to C++ only. The defaulting/deleting is currently ignored, because SWIG automatically produces wrappers for special constructors and operators specific to the target language.

    @@ -540,12 +540,12 @@ automatically produces wrappers for special constructors and operators specific

    SWIG correctly parses and calls the new static_assert function.

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

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

    @@ -553,19 +553,19 @@ struct Check {

    SWIG correctly calls the sizeof() on types as well as on the objects. For example:

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

    In Python:

    -
    +
     >>> SIZE
     8
    -
    +

    7.3 Standard library changes

    @@ -603,7 +603,7 @@ include the tuple header file; it is parsed without any problems.

    The new ref and cref classes are used to instantiate a parameter as a reference of a template function. For example:

    -
    +
     void f( int &r )  { r++; }
      
     // Template function.
    @@ -619,7 +619,7 @@ int main() {
                         // then 'i' will be modified.
       cout << i << endl ;  // Output -> 1
     }
    -
    +

    The ref and cref classes are not wrapped by SWIG because the SWIG target languages do not support referencing.

    @@ -628,20 +628,20 @@ int main() {

    SWIG fully supports function template wrappers and function objects:

    -
    +
     function<int ( int, int )> pF;   // function template wrapper
     
     struct Test {
       bool operator()( short x, short y ); // function object
     };
    -
    +

    7.3.8 Type traits for metaprogramming

    The new C++ metaprogramming is useful at compile time and is aimed specifically for C++ development:

    -
    +
     // First way of operating.
     template< bool B > struct algorithm {
       template< class T1, class T2 > int do_it( T1&, T2& )  { /*...*/ }
    @@ -656,7 +656,7 @@ template< class T1, class T2 > int elaborate( T1 A, T2 B ) {
       // in floating point, otherwise use the first way.
       return algorithm< is_integral<T1>::value && is_floating_point<T2>::value >::do_it( A, B );
     }
    -
    +

    SWIG correctly parses the template specialization, template types and values inside the <> block and the new helper functions: is_convertible, is_integral, is_const etc. However, SWIG still explicitly requires concrete types when using the %template directive, so the C++ metaprogramming features are not really of interest at runtime in the target languages.

    @@ -665,7 +665,7 @@ However, SWIG still explicitly requires concrete types when using the %templ

    SWIG does not wrap the new result_of class introduced in the <functional> header and map the result_of::type to the concrete type yet. For example:

    -
    +
     %inline %{
     #include <functional>
     double square(double x) {
    @@ -680,15 +680,15 @@ typename std::result_of<Fun(Arg)>::type test_result_impl(Fun fun, Arg arg)
     
     %template(test_result) test_result_impl<double(*)(double), double>;
     %constant double (*SQUARE)(double) = square;
    -
    +

    will result in:

    -
    +
     >>> test_result_impl(SQUARE, 5.0)
     <SWIG Object of type 'std::result_of< Fun(Arg) >::type *' at 0x7faf99ed8a50>
    -
    +

    Instead, please use decltype() where possible for now.

    - - + + From fdb9f072a7495f8a0a782032fdf7d9218c8ae16e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 20 Apr 2012 20:26:13 +0000 Subject: [PATCH 0059/1160] Fix parsing of forward declaration of C++0x enums git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13010 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../cpp0x_strongly_typed_enumerations.i | 21 +++++++++++++------ Source/CParse/parser.y | 7 ++++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i index 776af5822..2532d8c6e 100644 --- a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i +++ b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i @@ -7,6 +7,12 @@ %warnfilter(302) Val3; %warnfilter(302) Val4; +/* Forward declarations (illegally accepted by SWIG - oh well!) */ +enum Enum1 : short; +enum Enum3; +enum ; +enum : unsigned short; + %inline %{ enum class Enum1 { Val1, @@ -21,13 +27,16 @@ enum class Enum2 : short { Val3 = 100, Val4 }; +%} -/* Forward declarations. GCC doesn't support them */ -//enum Enum3; // Illegal in C++ and C++0x; no size is explicitly specified. -//enum Enum4 : unsigned int; // Legal in C++0x. -//enum class Enum5; // Legal in C++0x, because enum class declarations have a default type of "int". -//enum class Enum6 : unsigned int; // Legal C++0x. -//enum Enum2 : unsigned short; // Illegal in C++0x, because Enum2 was previously declared with a different type. +// SWIG should fail this one +enum Enum2 : unsigned short; // Illegal in C++0x, because Enum2 was previously declared with a different type. + +%inline %{ +/* Forward declarations. */ +enum Enum4 : unsigned int; // Legal in C++0x. +enum class Enum5; // Legal in C++0x, because enum class declarations have a default type of "int". +enum class Enum6 : unsigned int; // Legal C++0x. enum Enum4 : unsigned int { Val1, Val2, Val3 = 100, Val4 diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 38bb29392..562d69d50 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3326,14 +3326,15 @@ c_enum_inherit : COLON primitive_type { ; /* ------------------------------------------------------------ enum [class] Name; + enum [class] Name [: base_type]; ------------------------------------------------------------ */ -c_enum_forward_decl : storage_class c_enum_keyword c_enum_inherit ID SEMI { +c_enum_forward_decl : storage_class c_enum_keyword ename c_enum_inherit SEMI { SwigType *ty = 0; $$ = new_node("enumforward"); - ty = NewStringf("enum %s", $4); + ty = NewStringf("enum %s", $3); Setattr($$,"enumkeyword",$2); - Setattr($$,"name",$4); + Setattr($$,"name",$3); Setattr($$,"type",ty); Setattr($$,"sym:weak", "1"); add_symbols($$); From 6f9312d1c1e80ac56560cdc4c2842f14049cd5e5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 21 Apr 2012 10:06:43 +0000 Subject: [PATCH 0060/1160] Add support for c++11 strongly typed enums inheriting from non standard primitive types git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13012 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../cpp0x_strongly_typed_enumerations.i | 29 +++++++++++++++++++ Source/CParse/parser.y | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i index 2532d8c6e..2ce676227 100644 --- a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i +++ b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i @@ -49,4 +49,33 @@ enum class Enum5 { enum class Enum6 : unsigned int { Val1, Val2, Val3 = 300, Val4 }; + +typedef enum class Enum7 : unsigned int { + Val1, Val2, Val3 = 300, Val4 +} Enum7td; + +// enum inherits from non-primitive type +enum class Enum8 : size_t { + Val1, Val2, Val3 = 300, Val4 +}; + +template struct TType { + typedef T type_name; +}; + +enum class Enum10 : TType::type_name { + Val1, Val2, Val3 = 300, Val4 +}; + +/* +TODO +enum class MyClass {AAA, BBB, CCC}; +namespace Space { +enum MyEnum {XXX, YYY, ZZZ}; +} +struct SSS { + MyClass m; +}; +*/ %} + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 562d69d50..1aefcbd08 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3319,7 +3319,7 @@ c_enum_keyword : ENUM { base enum type (eg. unsigned short) ------------------------------------------------------------ */ -c_enum_inherit : COLON primitive_type { +c_enum_inherit : COLON type_right { $$ = $2; } | empty { $$ = 0; } From 38f6156a93c83765ae871c04f6e762bd257ad7ae Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 23 Apr 2012 22:15:37 +0000 Subject: [PATCH 0061/1160] Using C++11 enum classes with just a forward reference. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13013 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../cpp0x_strongly_typed_enumerations.i | 6 ++++++ Lib/csharp/enums.swg | 8 +++---- Lib/csharp/enumsimple.swg | 8 +++---- Lib/csharp/enumtypesafe.swg | 8 +++---- Lib/php/php.swg | 21 +++++++++++++++---- 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i index 2ce676227..dbe6d44bc 100644 --- a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i +++ b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i @@ -67,6 +67,12 @@ enum class Enum10 : TType::type_name { Val1, Val2, Val3 = 300, Val4 }; +// forward declaration, no definition of enum +enum class Enum11 : int; +struct UseEnum11 { + Enum11 myenum11; +}; + /* TODO enum class MyClass {AAA, BBB, CCC}; diff --git a/Lib/csharp/enums.swg b/Lib/csharp/enums.swg index 6605da8c8..65a0c38f8 100644 --- a/Lib/csharp/enums.swg +++ b/Lib/csharp/enums.swg @@ -13,12 +13,12 @@ %typemap(in) const enum SWIGTYPE & ($*1_ltype temp) %{ temp = ($*1_ltype)$input; $1 = &temp; %} -%typemap(out) const enum SWIGTYPE & %{ $result = *$1; %} +%typemap(out) const enum SWIGTYPE & %{ $result = (int)*$1; %} %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE & %{ static $*1_ltype temp = ($*1_ltype)$input; $result = &temp; %} -%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;" +%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;" %typemap(csdirectorin) const enum SWIGTYPE & "($*csclassname)$iminput" %typemap(csdirectorout) const enum SWIGTYPE & "(int)$cscall" @@ -48,10 +48,10 @@ %typemap(cstype) enum SWIGTYPE "$csclassname" %typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %} -%typemap(out) enum SWIGTYPE %{ $result = $1; %} +%typemap(out) enum SWIGTYPE %{ $result = (int)$1; %} %typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %} -%typemap(directorin) enum SWIGTYPE "$input = $1;" +%typemap(directorin) enum SWIGTYPE "$input = $1;" %typemap(csdirectorin) enum SWIGTYPE "($csclassname)$iminput" %typemap(csdirectorout) enum SWIGTYPE "(int)$cscall" diff --git a/Lib/csharp/enumsimple.swg b/Lib/csharp/enumsimple.swg index 2b1cb182b..e838ad978 100644 --- a/Lib/csharp/enumsimple.swg +++ b/Lib/csharp/enumsimple.swg @@ -15,12 +15,12 @@ %typemap(in) const enum SWIGTYPE & ($*1_ltype temp) %{ temp = ($*1_ltype)$input; $1 = &temp; %} -%typemap(out) const enum SWIGTYPE & %{ $result = *$1; %} +%typemap(out) const enum SWIGTYPE & %{ $result = (int)*$1; %} %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE & %{ static $*1_ltype temp = ($*1_ltype)$input; $result = &temp; %} -%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;" +%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;" %typemap(csdirectorin) const enum SWIGTYPE & "$iminput" %typemap(csdirectorout) const enum SWIGTYPE & "$cscall" @@ -50,10 +50,10 @@ %typemap(cstype) enum SWIGTYPE "int" %typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %} -%typemap(out) enum SWIGTYPE %{ $result = $1; %} +%typemap(out) enum SWIGTYPE %{ $result = (int)$1; %} %typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %} -%typemap(directorin) enum SWIGTYPE "$input = $1;" +%typemap(directorin) enum SWIGTYPE "$input = $1;" %typemap(csdirectorin) enum SWIGTYPE "$iminput" %typemap(csdirectorout) enum SWIGTYPE "$cscall" diff --git a/Lib/csharp/enumtypesafe.swg b/Lib/csharp/enumtypesafe.swg index a6bf64b9a..e3a22570c 100644 --- a/Lib/csharp/enumtypesafe.swg +++ b/Lib/csharp/enumtypesafe.swg @@ -14,12 +14,12 @@ %typemap(in) const enum SWIGTYPE & ($*1_ltype temp) %{ temp = ($*1_ltype)$input; $1 = &temp; %} -%typemap(out) const enum SWIGTYPE & %{ $result = *$1; %} +%typemap(out) const enum SWIGTYPE & %{ $result = (int)*$1; %} %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE & %{ static $*1_ltype temp = ($*1_ltype)$input; $result = &temp; %} -%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;" +%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;" %typemap(csdirectorin) const enum SWIGTYPE & "$*csclassname.swigToEnum($iminput)" %typemap(csdirectorout) const enum SWIGTYPE & "$cscall.swigValue" @@ -49,10 +49,10 @@ %typemap(cstype) enum SWIGTYPE "$csclassname" %typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %} -%typemap(out) enum SWIGTYPE %{ $result = $1; %} +%typemap(out) enum SWIGTYPE %{ $result = (int)$1; %} %typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %} -%typemap(directorin) enum SWIGTYPE "$input = $1;" +%typemap(directorin) enum SWIGTYPE "$input = $1;" %typemap(csdirectorin) enum SWIGTYPE "$csclassname.swigToEnum($iminput)" %typemap(csdirectorout) enum SWIGTYPE "$cscall.swigValue" diff --git a/Lib/php/php.swg b/Lib/php/php.swg index f4cc8d2b2..99edcddf5 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -189,12 +189,16 @@ signed char, unsigned char, bool, - size_t, - enum SWIGTYPE + size_t { ZVAL_LONG(return_value,$1); } +%typemap(out) enum SWIGTYPE +{ + ZVAL_LONG(return_value, (long)$1); +} + %typemap(out) long long %{ if ((long long)LONG_MIN <= $1 && $1 <= (long long)LONG_MAX) { @@ -227,12 +231,16 @@ const signed char &, const unsigned char &, const bool &, - const size_t &, - const enum SWIGTYPE & + const size_t & { ZVAL_LONG(return_value,*$1); } +%typemap(out) const enum SWIGTYPE & +{ + ZVAL_LONG(return_value, (long)*$1); +} + %typemap(out) const long long & %{ if ((long long)LONG_MIN <= *$1 && *$1 <= (long long)LONG_MAX) { @@ -270,6 +278,11 @@ ZVAL_LONG($input,$1_name); } +%typemap(directorin) enum SWIGTYPE +{ + ZVAL_LONG($input, (long)$1_name); +} + %typemap(out) bool { ZVAL_BOOL(return_value,($1)?1:0); From d6cef9337f044f9482995d10ed05fc5c1a4e2c21 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 30 Apr 2012 05:27:09 +0000 Subject: [PATCH 0062/1160] Bump version to 2.0.7 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13029 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- ANNOUNCE | 8 ++++---- CHANGES | 13 +++++++++++++ CHANGES.current | 14 ++------------ Doc/Manual/Sections.html | 2 +- README | 2 +- configure.in | 2 +- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 825837614..46c570cb1 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,8 +1,8 @@ -*** ANNOUNCE: SWIG 2.0.6 (30 April 2012) *** +*** ANNOUNCE: SWIG 2.0.7 (in progress) *** http://www.swig.org -We're pleased to announce SWIG-2.0.6, the latest SWIG release. +We're pleased to announce SWIG-2.0.7, 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.6.tar.gz + http://prdownloads.sourceforge.net/swig/swig-2.0.7.tar.gz A Windows version is also available at - http://prdownloads.sourceforge.net/swig/swigwin-2.0.6.zip + http://prdownloads.sourceforge.net/swig/swigwin-2.0.7.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 70af78333..534d9cb71 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,19 @@ SWIG (Simplified Wrapper and Interface Generator) See the CHANGES.current file for changes in the current version. See the RELEASENOTES file for a summary of changes in each release. +Version 2.0.6 (30 April 2012) +============================= + +2012-04-25: wsfulton + [Lua] Fix uninitialised variable in SWIGTYPE **OUTPUT typemaps as reported by Jim Anderson. + +2012-04-28: wsfulton + [Python] Fix compilation errors when wrapping STL containers on Mac OSX and possibly other systems. + +2012-04-28: wsfulton + [Java] Patch 3521811 from Leo Davis - char **STRING_ARRAY typemaps fixed to handle + null pointers. + Version 2.0.5 (19 April 2012) ============================= diff --git a/CHANGES.current b/CHANGES.current index cb64a7937..12e378ed8 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,16 +2,6 @@ Below are the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.6 (30 April 2012) -============================= - -2012-04-25: wsfulton - [Lua] Fix uninitialised variable in SWIGTYPE **OUTPUT typemaps as reported by Jim Anderson. - -2012-04-28: wsfulton - [Python] Fix compilation errors when wrapping STL containers on Mac OSX and possibly other systems. - -2012-04-28: wsfulton - [Java] Patch 3521811 from Leo Davis - char **STRING_ARRAY typemaps fixed to handle - null pointers. +Version 2.0.7 (in progress) +=========================== diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 1151de1d5..61c94544e 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

    SWIG-2.0 Documentation

    -Last update : SWIG-2.0.6 (30 April 2012) +Last update : SWIG-2.0.7 (in progress)

    Sections

    diff --git a/README b/README index d846665e3..a683745ae 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.6 (30 April 2012) +Version: 2.0.7 (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/configure.in b/configure.in index 77791bd02..79f780b67 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.6],[http://www.swig.org]) +AC_INIT([swig],[2.0.7],[http://www.swig.org]) dnl NB: When this requirement is increased to 2.60 or later, AC_PROG_SED dnl definition below can be removed From 73b0431fbc29e34833f7fc4d8dbcc7b6a64b0f1b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 1 May 2012 18:44:22 +0000 Subject: [PATCH 0063/1160] Fix C enum forward declarations in some target languages (notably Java) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13030 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 ++ Examples/test-suite/common.mk | 1 + .../test-suite/csharp/enum_forward_runme.cs | 16 +++++++++ Examples/test-suite/enum_forward.i | 35 +++++++++++++++++++ .../test-suite/java/enum_forward_runme.java | 33 +++++++++++++++++ .../test-suite/python/enum_forward_runme.py | 10 ++++++ Source/Modules/lang.cxx | 6 +++- Source/Modules/typepass.cxx | 17 ++++++++- 8 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/csharp/enum_forward_runme.cs create mode 100644 Examples/test-suite/enum_forward.i create mode 100644 Examples/test-suite/java/enum_forward_runme.java create mode 100644 Examples/test-suite/python/enum_forward_runme.py diff --git a/CHANGES.current b/CHANGES.current index 12e378ed8..682ae47a2 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.7 (in progress) =========================== +2012-05-01: wsfulton + Fix generated code for C forward enum declarations in some languages. + diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 7cc410e7a..84a81b08f 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -495,6 +495,7 @@ C_TEST_CASES += \ constant_expr \ empty \ enums \ + enum_forward \ extern_declaration \ funcptr \ function_typedef \ diff --git a/Examples/test-suite/csharp/enum_forward_runme.cs b/Examples/test-suite/csharp/enum_forward_runme.cs new file mode 100644 index 000000000..3ae714ff0 --- /dev/null +++ b/Examples/test-suite/csharp/enum_forward_runme.cs @@ -0,0 +1,16 @@ +using System; +using enum_forwardNamespace; + +public class runme { + static void Main() { + ForwardEnum1 f1 = enum_forward.get_enum1(); + f1 = enum_forward.test_function1(f1); + + ForwardEnum2 f2 = enum_forward.get_enum2(); + f2 = enum_forward.test_function2(f2); + + ForwardEnum3 f3 = enum_forward.get_enum3(); + f3 = enum_forward.test_function3(f3); + } +} + diff --git a/Examples/test-suite/enum_forward.i b/Examples/test-suite/enum_forward.i new file mode 100644 index 000000000..4540aecb6 --- /dev/null +++ b/Examples/test-suite/enum_forward.i @@ -0,0 +1,35 @@ +%module enum_forward + +%{ +enum ForwardEnum1 { AAA, BBB }; +enum ForwardEnum2 { CCC, DDD }; +%} + +%inline %{ +enum ForwardEnum1; +enum ForwardEnum1 get_enum1() { return AAA; } +enum ForwardEnum1 test_function1(enum ForwardEnum1 e) { + return e; +} +%} + +%inline %{ +enum ForwardEnum2; +enum ForwardEnum2; +enum ForwardEnum2 get_enum2() { return CCC; } +enum ForwardEnum2 test_function2(enum ForwardEnum2 e) { + return e; +} +enum ForwardEnum2; +%} + +%inline %{ +enum ForwardEnum3; +enum ForwardEnum3 { EEE, FFF }; +enum ForwardEnum3 get_enum3() { return EEE; } +enum ForwardEnum3 test_function3(enum ForwardEnum3 e) { + return e; +} +enum ForwardEnum3; +%} + diff --git a/Examples/test-suite/java/enum_forward_runme.java b/Examples/test-suite/java/enum_forward_runme.java new file mode 100644 index 000000000..3827e8320 --- /dev/null +++ b/Examples/test-suite/java/enum_forward_runme.java @@ -0,0 +1,33 @@ + +import enum_forward.*; + +public class enum_forward_runme { + + static { + try { + System.loadLibrary("enum_forward"); + } 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[]) + { + try { + ForwardEnum1 f1 = enum_forward.get_enum1(); + f1 = enum_forward.test_function1(f1); + } catch (IllegalArgumentException e) { + } + + try { + ForwardEnum2 f2 = enum_forward.get_enum2(); + f2 = enum_forward.test_function2(f2); + } catch (IllegalArgumentException e) { + } + + ForwardEnum3 f3 = enum_forward.get_enum3(); + f3 = enum_forward.test_function3(f3); + } +} + diff --git a/Examples/test-suite/python/enum_forward_runme.py b/Examples/test-suite/python/enum_forward_runme.py new file mode 100644 index 000000000..9af476f97 --- /dev/null +++ b/Examples/test-suite/python/enum_forward_runme.py @@ -0,0 +1,10 @@ +import enum_forward + +f1 = enum_forward.get_enum1(); +f1 = enum_forward.test_function1(f1); + +f2 = enum_forward.get_enum2(); +f2 = enum_forward.test_function2(f2); + +f3 = enum_forward.get_enum3(); +f3 = enum_forward.test_function3(f3); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index c797a101e..c90ebeb73 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1664,6 +1664,8 @@ int Language::enumvalueDeclaration(Node *n) { int Language::enumforwardDeclaration(Node *n) { (void) n; + if (GetFlag(n, "enumMissing")) + enumDeclaration(n); // Generate an empty enum in target language return SWIG_OK; } @@ -3156,7 +3158,9 @@ Node *Language::enumLookup(SwigType *s) { n = Swig_symbol_clookup(base, stab); if (!n) break; - if (Strcmp(nodeType(n), "enum") == 0) + if (Equal(nodeType(n), "enum")) + break; + if (Equal(nodeType(n), "enumforward") && GetFlag(n, "enumMissing")) break; n = parentNode(n); if (!n) diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index 15768f203..d757d53a7 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -886,7 +886,22 @@ class TypePass:private Dispatcher { // Use enumDeclaration() to do all the hard work. // Note that no children can be emitted in a forward declaration as there aren't any. - return enumDeclaration(n); + int result = enumDeclaration(n); + if (result == SWIG_OK) { + // Detect when the real enum matching the forward enum declaration has not been parsed/declared + SwigType *ty = SwigType_typedef_resolve_all(Getattr(n, "type")); + Replaceall(ty, "enum ", ""); + Node *nn = Swig_symbol_clookup(ty, 0); + + String *nodetype = nn ? nodeType(nn) : 0; + if (nodetype) { + if (Equal(nodetype, "enumforward")) { + SetFlag(nn, "enumMissing"); + } // if a real enum was declared this would be an "enum" node type + } + Delete(ty); + } + return result; } #ifdef DEBUG_OVERLOADED From c9d8e6720bf0721dce06cc7417a890443456f58e Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 2 May 2012 18:10:45 +0000 Subject: [PATCH 0064/1160] Remove support for using gccgo 4.6 as the Go compiler. Gccgo 4.7 works, as does the more commonly used gc compiler. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13031 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES | 5 ++++ Doc/Manual/Go.html | 13 ----------- Source/Modules/go.cxx | 53 ++++++++----------------------------------- configure.in | 5 +++- 4 files changed, 19 insertions(+), 57 deletions(-) diff --git a/CHANGES b/CHANGES index 534d9cb71..dd0224b67 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,11 @@ SWIG (Simplified Wrapper and Interface Generator) See the CHANGES.current file for changes in the current version. See the RELEASENOTES file for a summary of changes in each release. +2012-05-02: ianlancetaylor + [Go] Remove compatibility support for gccgo 4.6. Using + SWIG with gccgo will now require gccgo 4.7. Using SWIG + with the more commonly used gc compiler is unaffected. + Version 2.0.6 (30 April 2012) ============================= diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 8abeada81..cd39d1fa1 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -99,19 +99,6 @@ swig -go -help 6g/8g/5g. - --gccgo-46 -Generate code for gccgo 4.6. The default is set by the configure - script. This generates code that does not use some facilities - that are only available in gccgo 4.7 and later. - - - --no-gccgo-46 -Turn off -gccgo-46, whether set by default or earlier - on the command line. - - -package <name> Set the name of the Go package to <name>. The default diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 668cb66df..e7a21d1bd 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -13,12 +13,6 @@ char cvsroot_go_cxx[] = "$Id"; #include "cparse.h" #include -#ifdef HAVE_GCCGO_46 - #define GCCGO_46_DEFAULT true -#else - #define GCCGO_46_DEFAULT false -#endif - class GO:public Language { static const char *const usage; @@ -26,8 +20,6 @@ class GO:public Language { String *package; // Flag for generating gccgo output. bool gccgo_flag; - // Flag for generating gccgo 4.6 output. - bool gccgo_46_flag; // Prefix to use with gccgo. String *go_prefix; // Name of shared library to import. @@ -90,7 +82,6 @@ class GO:public Language { public: GO():package(NULL), gccgo_flag(false), - gccgo_46_flag(GCCGO_46_DEFAULT), go_prefix(NULL), soname(NULL), long_type_size(32), @@ -148,12 +139,6 @@ private: } else if (strcmp(argv[i], "-gccgo") == 0) { Swig_mark_arg(i); gccgo_flag = true; - } else if (strcmp(argv[i], "-gccgo-46") == 0) { - Swig_mark_arg(i); - gccgo_46_flag = true; - } else if (strcmp(argv[i], "-no-gccgo-46") == 0) { - Swig_mark_arg(i); - gccgo_46_flag = false; } else if (strcmp(argv[i], "-go-prefix") == 0) { if (argv[i + 1]) { go_prefix = NewString(argv[i + 1]); @@ -794,7 +779,7 @@ private: if (needs_wrapper) { wrapper_name = buildGoWrapperName(name, overname); - if (gccgo_flag && !gccgo_46_flag) { + if (gccgo_flag) { Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL); } @@ -845,16 +830,12 @@ private: } } - if (gccgo_flag && gccgo_46_flag) { - Printv(f_go_wrappers, " __asm__ (\"", go_prefix, "_", wname, "\")", NULL); - } - Printv(f_go_wrappers, "\n\n", NULL); } // Start defining the Go function. - if (!needs_wrapper && gccgo_flag && !gccgo_46_flag) { + if (!needs_wrapper && gccgo_flag) { Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL); } @@ -959,7 +940,7 @@ private: } } - if (gccgo_flag && !gccgo_46_flag) { + if (gccgo_flag) { Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL); Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\n", NULL); } @@ -1003,10 +984,6 @@ private: } Printv(f_go_wrappers, ")\n", NULL); Printv(f_go_wrappers, "}\n", NULL); - } else { - if (gccgo_flag && gccgo_46_flag) { - Printv(f_go_wrappers, " __asm__ (\"", go_prefix, "_", wname, "\")\n", NULL); - } } Printv(f_go_wrappers, "\n", NULL); @@ -2522,7 +2499,7 @@ private: if (!is_ignored) { // Declare the C++ wrapper. - if (gccgo_flag && !gccgo_46_flag) { + if (gccgo_flag) { Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL); } @@ -2541,13 +2518,7 @@ private: p = nextParm(p); } - Printv(f_go_wrappers, ") ", go_type_name, NULL); - - if (gccgo_flag && gccgo_46_flag) { - Printv(f_go_wrappers, " __asm__(\"", go_prefix, "_", wname, "\")", NULL); - } - - Printv(f_go_wrappers, "\n\n", NULL); + Printv(f_go_wrappers, ") ", go_type_name, "\n\n", NULL); Printv(f_go_wrappers, "func ", func_with_over_name, "(v interface{}", NULL); @@ -2566,7 +2537,7 @@ private: Printv(f_go_wrappers, "\tp := &", director_struct_name, "{0, v}\n", NULL); - if (gccgo_flag && !gccgo_46_flag) { + if (gccgo_flag) { Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL); Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\n", NULL); } @@ -3026,7 +2997,7 @@ private: String *upcall_gc_name = buildGoWrapperName(upcall_name, overname); - if (gccgo_flag && !gccgo_46_flag) { + if (gccgo_flag) { Printv(f_go_wrappers, "//extern ", go_prefix, "_", upcall_wname, "\n", NULL); } @@ -3049,10 +3020,6 @@ private: Delete(tm); } - if (gccgo_flag && gccgo_46_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. @@ -3082,7 +3049,7 @@ private: Printv(f_go_wrappers, " {\n", NULL); - if (gccgo_flag && !gccgo_46_flag) { + if (gccgo_flag) { Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL); Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\n", NULL); } @@ -3254,7 +3221,7 @@ private: Printv(f_go_wrappers, " {\n", NULL); - if (gccgo_flag && !gccgo_46_flag) { + if (gccgo_flag) { Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL); Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\n", NULL); } @@ -3301,7 +3268,7 @@ private: } Printv(f_go_wrappers, "{\n", NULL); - if (gccgo_flag && !gccgo_46_flag) { + if (gccgo_flag) { Printv(f_go_wrappers, "\tsyscall.Exitsyscall()\n", NULL); Printv(f_go_wrappers, "\tdefer syscall.Entersyscall()\n", NULL); } diff --git a/configure.in b/configure.in index 79f780b67..4b2525b34 100644 --- a/configure.in +++ b/configure.in @@ -2082,9 +2082,12 @@ else if test -n "$GO" ; then if $GO --help 2>/dev/null | grep gccgo >/dev/null 2>&1 ; then GOGCC=true + AC_MSG_CHECKING([whether gccgo version is too old]) go_version=`$GO --version | sed -e 's/[^0-9]* \([0-9.]*\) .*$/\1/' -e 's/[.]//g'` if test "$go_version" -lt 470; then - AC_DEFINE(HAVE_GCCGO_46, 1, [Define if using gccgo before 4.7.0]) + AC_MSG_RESULT([yes - minimum version is 4.7.0]) + else + AC_MSG_RESULT([no]) fi elif test "`echo $GO | sed -e 's|.*/||'`" = "go"; then GO1=true From e3b79abcdca9a183e4ba14b0a98e3c066ba4eceb Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 9 May 2012 07:23:07 +0000 Subject: [PATCH 0065/1160] Fix comment typo git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13051 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/lua/luaruntime.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/lua/luaruntime.swg b/Lib/lua/luaruntime.swg index 0f59b0476..eea394308 100644 --- a/Lib/lua/luaruntime.swg +++ b/Lib/lua/luaruntime.swg @@ -19,7 +19,7 @@ extern "C" { #endif /* this is the initialization function added at the very end of the code - the function is always called SWIG_init, but an eariler #define will rename it + the function is always called SWIG_init, but an earlier #define will rename it */ #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)) LUALIB_API int SWIG_init(lua_State* L) From a6d005f78b933d566d1df607e9be27e58538ccf9 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 9 May 2012 07:28:46 +0000 Subject: [PATCH 0066/1160] Fix another comment typo git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13052 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/lua/luaruntime.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/lua/luaruntime.swg b/Lib/lua/luaruntime.swg index eea394308..423c7190b 100644 --- a/Lib/lua/luaruntime.swg +++ b/Lib/lua/luaruntime.swg @@ -53,7 +53,7 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */ #endif #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) - /* set up base class pointers (the hierachy) */ + /* set up base class pointers (the hierarchy) */ for (i = 0; swig_types[i]; i++){ if (swig_types[i]->clientdata){ SWIG_Lua_init_base_class(L,(swig_lua_class*)(swig_types[i]->clientdata)); From af079aa439c4fed624b273799a29fe7b147e52fe Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 10 May 2012 05:43:23 +0000 Subject: [PATCH 0067/1160] Disable enum_forward test for Octave as this is a C only code test which does not compile as C++ git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13058 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/enum_forward.i | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/enum_forward.i b/Examples/test-suite/enum_forward.i index 4540aecb6..1609fa8e9 100644 --- a/Examples/test-suite/enum_forward.i +++ b/Examples/test-suite/enum_forward.i @@ -1,5 +1,7 @@ %module enum_forward +/* This contains C code that is not valid C++03 and Octave wrappers are always compiled as C++ */ +#if !defined(SWIGOCTAVE) %{ enum ForwardEnum1 { AAA, BBB }; enum ForwardEnum2 { CCC, DDD }; @@ -32,4 +34,4 @@ enum ForwardEnum3 test_function3(enum ForwardEnum3 e) { } enum ForwardEnum3; %} - +#endif From dba3dc5148531b5747999a6e2bb5b888ab94b186 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 10 May 2012 06:09:15 +0000 Subject: [PATCH 0068/1160] Minor improvements to the text. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13059 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Php.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 19ace7192..659fb0a89 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -146,7 +146,7 @@ least work for Linux though):

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

    @@ -156,7 +156,7 @@ can load it for every script by adding this line the [PHP] section of

    Alternatively, you can load it explicitly only for scripts which need it -by adding this line: +by adding this line to the start of each such PHP script::

    @@ -164,7 +164,7 @@ by adding this line:
     

    -to the start of each PHP file. SWIG also generates a php module, which +SWIG also generates a php module, which attempts to do the dl() call for you:

    @@ -705,7 +705,7 @@ would be accessed in PHP as,
     include("example.php");
     
    -echo "There has now been " . Ko::threats() . " threats\n";
    +echo "There have now been " . Ko::threats() . " threats\n";
     
     
    @@ -718,7 +718,7 @@ function, e.g. Ko::threats(10); -echo "There has now been " . Ko::threats() . " threats\n"; +echo "There have now been " . Ko::threats() . " threats\n";
  • 32.2.6.4 Static Member Functions

    From 70a134872a9d3fdd1fa824167429cc7d8290e4a8 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 10 May 2012 10:37:42 +0000 Subject: [PATCH 0069/1160] Remove two instances of call-time pass by reference, which has been removed in PHP 5.4, and isn't needed for these tests anyway. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13060 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/php/argout_runme.php | 2 +- Examples/test-suite/php/template_arg_typename_runme.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/php/argout_runme.php b/Examples/test-suite/php/argout_runme.php index 1c9026b6c..08524e214 100644 --- a/Examples/test-suite/php/argout_runme.php +++ b/Examples/test-suite/php/argout_runme.php @@ -23,7 +23,7 @@ check::equal(5,intp_value($tr),"5==$tr"); # Check the voidhandle call, first with null unset($handle); -voidhandle(&$handle); +voidhandle($handle); check::resource($handle,"_p_void",'$handle is not _p_void'); $handledata=handle($handle); check::equal($handledata,"Here it is","\$handledata != \"Here it is\""); diff --git a/Examples/test-suite/php/template_arg_typename_runme.php b/Examples/test-suite/php/template_arg_typename_runme.php index 87d07de03..7d60285e3 100644 --- a/Examples/test-suite/php/template_arg_typename_runme.php +++ b/Examples/test-suite/php/template_arg_typename_runme.php @@ -11,7 +11,7 @@ $ufbb=new unaryfunction_bool_bool(); check::is_a($ufbb,"unaryfunction_bool_bool"); unset($whatisthis); -$bufb=new boolunaryfunction_bool(&$whatisthis); +$bufb=new boolunaryfunction_bool($whatisthis); check::is_a($bufb,"boolunaryfunction_bool"); check::done(); From 61829195113349542615617097c1840af94a8bc9 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 10 May 2012 11:35:39 +0000 Subject: [PATCH 0070/1160] Relocate entry incorrectly added to CHANGES git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13061 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES | 5 ----- CHANGES.current | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index dd0224b67..534d9cb71 100644 --- a/CHANGES +++ b/CHANGES @@ -3,11 +3,6 @@ SWIG (Simplified Wrapper and Interface Generator) See the CHANGES.current file for changes in the current version. See the RELEASENOTES file for a summary of changes in each release. -2012-05-02: ianlancetaylor - [Go] Remove compatibility support for gccgo 4.6. Using - SWIG with gccgo will now require gccgo 4.7. Using SWIG - with the more commonly used gc compiler is unaffected. - Version 2.0.6 (30 April 2012) ============================= diff --git a/CHANGES.current b/CHANGES.current index 682ae47a2..730f56228 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.7 (in progress) =========================== +2012-05-02: ianlancetaylor + [Go] Remove compatibility support for gccgo 4.6. Using + SWIG with gccgo will now require gccgo 4.7. Using SWIG + with the more commonly used gc compiler is unaffected. + 2012-05-01: wsfulton Fix generated code for C forward enum declarations in some languages. From fcb46fe2fa2383c8ef2f1f0844a2d4e5038c204b Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 10 May 2012 11:41:19 +0000 Subject: [PATCH 0071/1160] [PHP] Fix the constant typemaps for SWIGTYPE, etc - previously these used the wrong name for renamed constants. Add autodoc_runme.php to the testsuite as a regression test for this. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13062 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 +++++ Examples/test-suite/php/autodoc_runme.php | 9 +++++++++ Lib/php/const.i | 7 ++----- 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 Examples/test-suite/php/autodoc_runme.php diff --git a/CHANGES.current b/CHANGES.current index 730f56228..9834ce2ea 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.7 (in progress) =========================== +2012-05-10: olly + [PHP] Fix the constant typemaps for SWIGTYPE, etc - previously + these used the wrong name for renamed constants. Add + autodoc_runme.php to the testsuite as a regression test for this. + 2012-05-02: ianlancetaylor [Go] Remove compatibility support for gccgo 4.6. Using SWIG with gccgo will now require gccgo 4.7. Using SWIG diff --git a/Examples/test-suite/php/autodoc_runme.php b/Examples/test-suite/php/autodoc_runme.php new file mode 100644 index 000000000..f2e19d3cb --- /dev/null +++ b/Examples/test-suite/php/autodoc_runme.php @@ -0,0 +1,9 @@ + diff --git a/Lib/php/const.i b/Lib/php/const.i index afd7d02b9..78f3a8a08 100644 --- a/Lib/php/const.i +++ b/Lib/php/const.i @@ -32,17 +32,14 @@ %typemap(consttab) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { - /* This actually registers it as a global variable and constant. I don't - * like it, but I can't figure out the zend_constant code... */ zval *z_var; MAKE_STD_ZVAL(z_var); SWIG_SetPointerZval(z_var, (void*)$value, $1_descriptor, 0); - /* zend_hash_add(&EG(symbol_table), "$1", sizeof("$1"), (void *)&z_var,sizeof(zval *), NULL); */ zend_constant c; c.value = *z_var; zval_copy_ctor(&c.value); - size_t len = sizeof("$1") - 1; - c.name = zend_strndup("$1", len); + size_t len = sizeof("$symname") - 1; + c.name = zend_strndup("$symname", len); c.name_len = len+1; c.flags = CONST_CS | CONST_PERSISTENT; c.module_number = module_number; From 43b3e20d2f3c66ae2e65896ba6f59502db8f26c5 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 11 May 2012 05:58:18 +0000 Subject: [PATCH 0072/1160] Add wrapmacro_runme.php git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13065 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/php/wrapmacro_runme.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Examples/test-suite/php/wrapmacro_runme.php diff --git a/Examples/test-suite/php/wrapmacro_runme.php b/Examples/test-suite/php/wrapmacro_runme.php new file mode 100644 index 000000000..f32da990e --- /dev/null +++ b/Examples/test-suite/php/wrapmacro_runme.php @@ -0,0 +1,12 @@ + From ef7a8a82533ce13aba1cd89c0dc04319654fc097 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 May 2012 21:23:37 +0000 Subject: [PATCH 0073/1160] Fix typemap method hiding regression introduced in swig-2.0.5 - rev 12764 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13071 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES | 8 ++-- CHANGES.current | 6 +++ Examples/test-suite/common.mk | 1 + .../typemap_template_parm_typedef.i | 48 +++++++++++++++++++ Source/Swig/typemap.c | 22 +++++---- 5 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 Examples/test-suite/typemap_template_parm_typedef.i diff --git a/CHANGES b/CHANGES index 534d9cb71..625ed3d24 100644 --- a/CHANGES +++ b/CHANGES @@ -362,7 +362,7 @@ Version 2.0.5 (19 April 2012) namespace std { template struct map { class iterator; - } + }; } iterator was scoped as std::iterator, but now it is correctly std::map::iterator; @@ -374,10 +374,10 @@ Version 2.0.5 (19 April 2012) template struct Map { typedef Key key_type; typedef T mapped_type; - } + }; } - tyepdef double DOUBLE; - %typemap(MM) Std::Map; + typedef double DOUBLE; + %template(MM) Std::Map; All symbols within Map will be resolved correctly, eg key_type and mapped_type no matter if the wrapped code uses Std::Map or std::Map or Std::Map diff --git a/CHANGES.current b/CHANGES.current index 9834ce2ea..902e62d47 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,12 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.7 (in progress) =========================== +2012-05-11: wsfulton + SF bug #3525050 - Fix regression introduced in swig-2.0.5 whereby defining one typemap + method such as an 'out' typemap may hide another typemap method such as an 'in' typemap - + only occurs when the type is a template type where the template parameters are the same + via a typedef. + 2012-05-10: olly [PHP] Fix the constant typemaps for SWIGTYPE, etc - previously these used the wrong name for renamed constants. Add diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 84a81b08f..9e7e21ac4 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -430,6 +430,7 @@ CPP_TEST_CASES += \ typemap_ns_using \ typemap_numinputs \ typemap_template \ + typemap_template_parm_typedef \ typemap_out_optimal \ typemap_qualifier_strip \ typemap_variables \ diff --git a/Examples/test-suite/typemap_template_parm_typedef.i b/Examples/test-suite/typemap_template_parm_typedef.i new file mode 100644 index 000000000..6eab66c9c --- /dev/null +++ b/Examples/test-suite/typemap_template_parm_typedef.i @@ -0,0 +1,48 @@ +%module typemap_template_parm_typedef + +%typemap(in) SWIGTYPE " _in_will_not_compile_ " +%typemap(in) SWIGTYPE * " _in_will_not_compile_ " + +%typemap(out) SWIGTYPE " _out_will_not_compile_ " +%typemap(out) SWIGTYPE * " _out_will_not_compile_ " + +%{ +#include +#include +#include + + namespace jada { + typedef unsigned int uint; + void test_no_typedef(std::list bada) {} + void test_typedef(std::vector bada) {} + std::deque no_typedef_out() {} + } +%} + +%typemap(in) std::list (std::list tmp) { + $1 = tmp; +} + +%typemap(in) std::vector (std::vector tmp) { + $1 = tmp; +} + +%typemap(out) std::list { +} + +// The presennce of this 'out' typemap was hiding the std::vector 'in' typemap in swig-2.0.5 and swig-2.0.6 +%typemap(out) std::vector { +} + +// This typemap was not used for no_typedef_out in 2.0.4 and earlier +%typemap(out) std::deque { + $result = 0; +} + +namespace jada { + typedef unsigned int uint; + void test_no_typedef(std::list bada); + void test_typedef(std::vector bada); + std::deque no_typedef_out(); +} + diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index 1b2150c3c..0488b1b62 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -89,13 +89,16 @@ static Hash *get_typemap(int tm_scope, const SwigType *type) { return tm; } -static void set_typemap(int tm_scope, const SwigType *type, Hash *tm) { +static void set_typemap(int tm_scope, const SwigType *type, Hash **tmhash) { SwigType *hashtype = 0; + Hash *new_tm = 0; + assert(*tmhash == 0); if (SwigType_istemplate(type)) { SwigType *rty = SwigType_typedef_resolve_all(type); String *ty = Swig_symbol_template_deftype(rty, 0); String *tyq = Swig_symbol_type_qualify(ty, 0); hashtype = SwigType_remove_global_scope_prefix(tyq); + *tmhash = Getattr(typemaps[tm_scope], hashtype); Delete(rty); Delete(tyq); Delete(ty); @@ -103,10 +106,17 @@ static void set_typemap(int tm_scope, const SwigType *type, Hash *tm) { hashtype = SwigType_remove_global_scope_prefix(type); } + if (!*tmhash) { + /* this type has not been seen before even after resolving template parameter types */ + new_tm = NewHash(); + *tmhash = new_tm; + } + /* note that the unary scope operator (::) prefix indicating global scope has been removed from the type */ - Setattr(typemaps[tm_scope], hashtype, tm); + Setattr(typemaps[tm_scope], hashtype, *tmhash); Delete(hashtype); + Delete(new_tm); } @@ -210,9 +220,7 @@ static void typemap_register(const_String_or_char_ptr tmap_method, ParmList *par /* See if this type has been seen before */ tm = get_typemap(tm_scope, type); if (!tm) { - tm = NewHash(); - set_typemap(tm_scope, type, tm); - Delete(tm); + set_typemap(tm_scope, type, &tm); } if (pname) { /* See if parameter has been seen before */ @@ -476,9 +484,7 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) { type = Getattr(lastdp, "type"); tm = get_typemap(tm_scope, type); if (!tm) { - tm = NewHash(); - set_typemap(tm_scope, type, tm); - Delete(tm); + set_typemap(tm_scope, type, &tm); } name = Getattr(lastdp, "name"); if (name) { From 0ebcf0563722eb587ae276c7a4bdf90a7068883b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 May 2012 23:13:35 +0000 Subject: [PATCH 0074/1160] Fix uninitialised size variable in char **STRING_ARRAY regression git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13072 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Lib/java/various.i | 1 + 2 files changed, 5 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 902e62d47..66d449471 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.7 (in progress) =========================== +2012-05-11: wsfulton + [Java] SF patch #3522611 Fix uninitialised size regression in char **STRING_ARRAY + introduced in swig-2.0.6. + 2012-05-11: wsfulton SF bug #3525050 - Fix regression introduced in swig-2.0.5 whereby defining one typemap method such as an 'out' typemap may hide another typemap method such as an 'in' typemap - diff --git a/Lib/java/various.i b/Lib/java/various.i index 71569ca32..d87c0cea1 100644 --- a/Lib/java/various.i +++ b/Lib/java/various.i @@ -46,6 +46,7 @@ $1[i] = 0; } else { $1 = 0; + size = 0; } } From d9393bc22ad179e00850438ea08fb2c1b116caf6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 May 2012 23:13:55 +0000 Subject: [PATCH 0075/1160] Fix possible uninitialised memory access in char **STRING_OUT typemap git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13073 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Lib/java/various.i | 1 + 2 files changed, 5 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 66d449471..387a26e07 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.7 (in progress) =========================== +2012-05-11: wsfulton + [Java] SF patch #3522674 Fix possible uninitialised memory access in char **STRING_OUT + typemap. + 2012-05-11: wsfulton [Java] SF patch #3522611 Fix uninitialised size regression in char **STRING_ARRAY introduced in swig-2.0.6. diff --git a/Lib/java/various.i b/Lib/java/various.i index d87c0cea1..f589bf714 100644 --- a/Lib/java/various.i +++ b/Lib/java/various.i @@ -114,6 +114,7 @@ return $null; } $1 = &temp; + *$1 = 0; } %typemap(argout) char **STRING_OUT { From 4dfe13120748810cd8d833bf5f88e036c03e4c1d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 May 2012 23:55:54 +0000 Subject: [PATCH 0076/1160] Fix unintended uninitialised memory access in OUTPUT typemaps git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13074 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Lib/java/typemaps.i | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 387a26e07..f3247cba7 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.7 (in progress) =========================== +2012-05-11: wsfulton + [Java] SF patch #3522855 Fix unintended uninitialised memory access in OUTPUT typemaps. + 2012-05-11: wsfulton [Java] SF patch #3522674 Fix possible uninitialised memory access in char **STRING_OUT typemap. diff --git a/Lib/java/typemaps.i b/Lib/java/typemaps.i index 6ada29e52..ae2377b70 100644 --- a/Lib/java/typemaps.i +++ b/Lib/java/typemaps.i @@ -195,6 +195,7 @@ There are no char *OUTPUT typemaps, however you can apply the signed char * type SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element"); return $null; } + temp = ($*1_ltype)0; $1 = &temp; } @@ -226,6 +227,20 @@ OUTPUT_TYPEMAP(double, jdouble, double, Double, "[Ljava/lang/Double;", jdoubleAr #undef OUTPUT_TYPEMAP +%typemap(in) bool *OUTPUT($*1_ltype temp), bool &OUTPUT($*1_ltype temp) +{ + if (!$input) { + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array null"); + return $null; + } + if (JCALL1(GetArrayLength, jenv, $input) == 0) { + SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element"); + return $null; + } + temp = false; + $1 = &temp; +} + /* Convert to BigInteger - byte array holds number in 2's complement big endian format */ /* Use first element in BigInteger array for output */ /* Overrides the typemap in the OUTPUT_TYPEMAP macro */ From d96db667f745d1e6c272e9d2d43e9aa754f64962 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 12 May 2012 13:26:16 +0000 Subject: [PATCH 0077/1160] [PHP] Avoid using zend_error_noreturn() as it doesn't work with all builds of PHP (SF bug #3166423). Instead we now wrap it in a SWIG_FAIL() function which we annotate as "noreturn" for GCC to avoids warnings. This also reduces the size of the compiled wrapper (e.g. the stripped size is 6% for Xapian's PHP bindings). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13077 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 7 +++++++ Lib/php/phprun.swg | 1 + Source/Modules/php.cxx | 42 +++++++++++++++++------------------------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index f3247cba7..da9606e19 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,13 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.7 (in progress) =========================== +2012-05-12: olly + [PHP] Avoid using zend_error_noreturn() as it doesn't work with all + builds of PHP (SF bug #3166423). Instead we now wrap it in a + SWIG_FAIL() function which we annotate as "noreturn" for GCC to + avoids warnings. This also reduces the size of the compiled + wrapper (e.g. the stripped size is 6% for Xapian's PHP bindings). + 2012-05-11: wsfulton [Java] SF patch #3522855 Fix unintended uninitialised memory access in OUTPUT typemaps. diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 623b33705..1404955e0 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -12,6 +12,7 @@ extern "C" { #include "zend_exceptions.h" #include "php.h" #include "ext/standard/php_string.h" +#include /* for abort(), used in generated code. */ #ifdef ZEND_RAW_FENTRY /* ZEND_RAW_FENTRY was added somewhere between 5.2.0 and 5.2.3 */ diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 6bcb2d457..57105ac91 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -409,11 +409,19 @@ public: Printf(s_header, "#define SWIG_ErrorCode() (%s_globals.error_code)\n", module); Printf(s_header, "#endif\n\n"); - Printf(s_header, "// Allow the user to workaround a PHP bug on some platforms/architectures by\n"); - Printf(s_header, "// compiling with -DSWIG_ZEND_ERROR_NORETURN=zend_error\n"); - Printf(s_header, "#ifndef SWIG_ZEND_ERROR_NORETURN\n"); - Printf(s_header, "# define SWIG_ZEND_ERROR_NORETURN zend_error_noreturn\n"); - Printf(s_header, "#endif\n\n"); + /* The following can't go in Lib/php/phprun.swg as it uses SWIG_ErrorMsg(), etc + * which has to be dynamically generated as it depends on the module name. + */ + Append(s_header, "#ifdef __GNUC__\n"); + Append(s_header, "static void SWIG_FAIL() __attribute__ ((__noreturn__));\n"); + Append(s_header, "#endif\n\n"); + Append(s_header, "static void SWIG_FAIL() {\n"); + Append(s_header, " zend_error(SWIG_ErrorCode(), \"%s\", SWIG_ErrorMsg());\n"); + // zend_error() should never return with the parameters we pass, but if it + // does, we really don't want to let SWIG_FAIL() return. This also avoids + // a warning about returning from a function marked as "__noreturn__". + Append(s_header, " abort();\n"); + Append(s_header, "}\n\n"); Printf(s_header, "static void %s_init_globals(zend_%s_globals *globals ) {\n", module, module); Printf(s_header, " globals->error_msg = default_error_msg;\n"); @@ -716,7 +724,7 @@ public: Printf(f->code, "SWIG_ErrorCode() = E_ERROR;\n"); Printf(f->code, "SWIG_ErrorMsg() = \"No matching function for overloaded '%s'\";\n", symname); - Printv(f->code, "zend_error(SWIG_ErrorCode(),\"%s\",SWIG_ErrorMsg());\n", NIL); + Printv(f->code, "SWIG_FAIL();\n", NIL); Printv(f->code, "}\n", NIL); Wrapper_print(f, s_wrappers); @@ -1000,11 +1008,7 @@ public: /* Error handling code */ Printf(f->code, "fail:\n"); Printv(f->code, cleanup, NIL); - /* This could be zend_error_noreturn(), but that's buggy in PHP ~5.3 and - * using zend_error() here shouldn't generate a warning, so just use that. - * At worst this may result in slightly less good code. - */ - Printv(f->code, "zend_error(SWIG_ErrorCode(),\"%s\",SWIG_ErrorMsg());", NIL); + Append(f->code, "SWIG_FAIL();\n"); Printf(f->code, "}\n"); @@ -2320,11 +2324,7 @@ done: Append(f->code, "return;\n"); Append(f->code, "fail:\n"); - /* This could be zend_error_noreturn(), but that's buggy in PHP ~5.3 and - * using zend_error() here shouldn't generate a warning, so just use that. - * At worst this may result in slightly less good code. - */ - Append(f->code, "zend_error(SWIG_ErrorCode(),\"%s\",SWIG_ErrorMsg());\n"); + Append(f->code, "SWIG_FAIL();\n"); Printf(f->code, "}\n"); Wrapper_print(f, s_wrappers); @@ -2715,15 +2715,7 @@ done: } Append(w->code, "fail:\n"); - if (!is_void) { - Append(w->code, "SWIG_ZEND_ERROR_NORETURN(SWIG_ErrorCode(),\"%s\",SWIG_ErrorMsg());\n"); - } else { - /* This could be zend_error_noreturn(), but that's buggy in PHP ~5.3 and - * using zend_error() here shouldn't generate a warning, so just use that. - * At worst this may result in slightly less good code. - */ - Append(w->code, "zend_error(SWIG_ErrorCode(),\"%s\",SWIG_ErrorMsg());\n"); - } + Append(w->code, "SWIG_FAIL();\n"); Append(w->code, "}\n"); // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method From 9d8d50f034747e1346d7e67001645e0c193941a2 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 12 May 2012 13:31:49 +0000 Subject: [PATCH 0078/1160] Fix typo git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13078 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index da9606e19..e123a0b2d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -10,7 +10,8 @@ Version 2.0.7 (in progress) builds of PHP (SF bug #3166423). Instead we now wrap it in a SWIG_FAIL() function which we annotate as "noreturn" for GCC to avoids warnings. This also reduces the size of the compiled - wrapper (e.g. the stripped size is 6% for Xapian's PHP bindings). + wrapper (e.g. the stripped size is reduced by 6% for Xapian's PHP + bindings). 2012-05-11: wsfulton [Java] SF patch #3522855 Fix unintended uninitialised memory access in OUTPUT typemaps. From d81770dd93b7bb978351545a1d80491372211cf1 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 12 May 2012 13:52:00 +0000 Subject: [PATCH 0079/1160] [PHP] Fix memory leak in code generated for a callback. Patch from SF bug #3510806. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13079 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Source/Modules/php.cxx | 1 + 2 files changed, 5 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index e123a0b2d..96d6c6300 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.7 (in progress) =========================== +2012-05-12: olly + [PHP] Fix memory leak in code generated for a callback. Patch from + SF bug #3510806. + 2012-05-12: olly [PHP] Avoid using zend_error_noreturn() as it doesn't work with all builds of PHP (SF bug #3166423). Instead we now wrap it in a diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 57105ac91..76b1bffe7 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2575,6 +2575,7 @@ done: Replaceall(tm, "$owner", "0"); Printv(wrap_args, "zval ", source, ";\n", NIL); Printf(wrap_args, "args[%d] = &%s;\n", idx - 1, source); + Printv(wrap_args, "INIT_ZVAL(", source, ");\n", NIL); Printv(wrap_args, tm, "\n", NIL); Putc('O', parse_args); From 4f11fd51ab855fd0455d80275c801e9ae2bf9207 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 14 May 2012 03:31:04 +0000 Subject: [PATCH 0080/1160] Drop check for "ZEND_MODULE_API_NO > 20010900". We only support PHP5 now, and 5.0.0 was released in 2004. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13080 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 76b1bffe7..106a2e9ba 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -536,7 +536,8 @@ public: Append(s_init, "#undef ZEND_MODULE_BUILD_ID\n"); Append(s_init, "#define ZEND_MODULE_BUILD_ID (char*)\"API\" ZEND_TOSTR(ZEND_MODULE_API_NO) ZEND_BUILD_TS ZEND_BUILD_DEBUG ZEND_BUILD_SYSTEM ZEND_BUILD_EXTRA\n"); Append(s_init, "#endif\n"); - Printv(s_init, "zend_module_entry ", module, "_module_entry = {\n" "#if ZEND_MODULE_API_NO > 20010900\n" " STANDARD_MODULE_HEADER,\n" "#endif\n", NIL); + Printv(s_init, "zend_module_entry ", module, "_module_entry = {\n"); + Printf(s_init, " STANDARD_MODULE_HEADER,\n"); Printf(s_init, " (char*)\"%s\",\n", module); Printf(s_init, " %s_functions,\n", module); Printf(s_init, " PHP_MINIT(%s),\n", module); @@ -544,9 +545,7 @@ public: Printf(s_init, " PHP_RINIT(%s),\n", module); Printf(s_init, " PHP_RSHUTDOWN(%s),\n", module); Printf(s_init, " PHP_MINFO(%s),\n", module); - Printf(s_init, "#if ZEND_MODULE_API_NO > 20010900\n"); Printf(s_init, " NO_VERSION_YET,\n"); - Printf(s_init, "#endif\n"); Printf(s_init, " STANDARD_MODULE_PROPERTIES\n"); Printf(s_init, "};\n"); Printf(s_init, "zend_module_entry* SWIG_module_entry = &%s_module_entry;\n\n", module); From e4763231bef2eb3179f4cf330a006e24c8efd743 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 14 May 2012 04:58:08 +0000 Subject: [PATCH 0081/1160] Remove some commented out code git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13081 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 106a2e9ba..b7e7478f6 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -471,10 +471,6 @@ public: Append(s_header, "}\n"); Printf(s_header, "#define SWIG_name \"%s\"\n", module); - /* Printf(s_header,"#ifdef HAVE_CONFIG_H\n"); - Printf(s_header,"#include \"config.h\"\n"); - Printf(s_header,"#endif\n\n"); - */ Printf(s_header, "#ifdef __cplusplus\n"); Printf(s_header, "extern \"C\" {\n"); Printf(s_header, "#endif\n"); From a2a42c70383999fe51ed8f19a0f5c43207fee03b Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 14 May 2012 05:11:02 +0000 Subject: [PATCH 0082/1160] Add back 'NIL', dropped by mistake in change before last. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13082 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 b7e7478f6..1ac9e8b24 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -532,7 +532,7 @@ public: Append(s_init, "#undef ZEND_MODULE_BUILD_ID\n"); Append(s_init, "#define ZEND_MODULE_BUILD_ID (char*)\"API\" ZEND_TOSTR(ZEND_MODULE_API_NO) ZEND_BUILD_TS ZEND_BUILD_DEBUG ZEND_BUILD_SYSTEM ZEND_BUILD_EXTRA\n"); Append(s_init, "#endif\n"); - Printv(s_init, "zend_module_entry ", module, "_module_entry = {\n"); + Printv(s_init, "zend_module_entry ", module, "_module_entry = {\n", NIL); Printf(s_init, " STANDARD_MODULE_HEADER,\n"); Printf(s_init, " (char*)\"%s\",\n", module); Printf(s_init, " %s_functions,\n", module); From e4a92ee692b7f2d7f37aaeb5a253f91a995bc228 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 14 May 2012 09:23:06 +0000 Subject: [PATCH 0083/1160] Link Octave tests and examples against Octave libraries - Tests for bugs associated with loading .oct modules git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13083 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/Makefile.in | 9 +++--- configure.in | 76 ++++++++++++++++++++------------------------ 2 files changed, 38 insertions(+), 47 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index e6c0d2f33..8d63d02b5 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -331,12 +331,11 @@ python_clean: ################################################################## # Make sure these locate your Octave installation -OCTAVE_INCLUDE= $(DEFS) @OCTAVEEXT@ -OCTAVE_LIB = OCTAVE = @OCTAVE@ -qf +OCTAVE_CXX = $(DEFS) @OCTAVE_CPPFLAGS@ @OCTAVE_CXXFLAGS@ # Extra Octave specific dynamic linking options -OCTAVE_DLNK = @OCTAVEDYNAMICLINKING@ +OCTAVE_DLNK = @OCTAVE_LDFLAGS@ OCTAVE_SO = @OCTAVE_SO@ # ---------------------------------------------------------------- @@ -346,7 +345,7 @@ OCTAVE_SO = @OCTAVE_SO@ octave: $(SRCS) $(SWIG) -octave $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -g -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(INCLUDES) -I$(OCTAVE_INCLUDE) + $(CXX) -g -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(INCLUDES) $(OCTAVE_CXX) $(CC) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CSRCS) $(INCLUDES) $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(OCTAVE_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(OCTAVE_SO) @@ -356,7 +355,7 @@ octave: $(SRCS) octave_cpp: $(SRCS) $(SWIG) -c++ -octave $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -g -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) -I$(OCTAVE_INCLUDE) + $(CXX) -g -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(OCTAVE_CXX) $(CXXSHARED) -g $(CFLAGS) $(OBJS) $(IOBJS) $(OCTAVE_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(OCTAVE_SO) # ----------------------------------------------------------------- diff --git a/configure.in b/configure.in index 4b2525b34..94fd61e08 100644 --- a/configure.in +++ b/configure.in @@ -900,7 +900,6 @@ AC_SUBST(PERL5CCFLAGS) #---------------------------------------------------------------- OCTAVEBIN= -OCTAVEDYNAMICLINKING= OCTAVE_SO=.oct AC_ARG_WITH(octave, AS_HELP_STRING([--without-octave], [Disable Octave]) @@ -908,58 +907,51 @@ AS_HELP_STRING([--with-octave=path], [Set location of Octave executable]),[OCTAV # First, check for "--without-octave" or "--with-octave=no". if test x"${OCTAVEBIN}" = xno -o x"${with_alllang}" = xno ; then -AC_MSG_NOTICE([Disabling Octave]) -OCTAVE= -else + AC_MSG_NOTICE([Disabling Octave]) + OCTAVE= # First figure out what the name of Octave is +elif test "x$OCTAVEBIN" = xyes; then + AC_CHECK_PROGS(OCTAVE, octave) -if test "x$OCTAVEBIN" = xyes; then -AC_CHECK_PROGS(OCTAVE, octave) else -OCTAVE="$OCTAVEBIN" + OCTAVE="$OCTAVEBIN" fi - -AC_MSG_CHECKING(for Octave header files) if test -n "$OCTAVE"; then - OCTAVECONFIG=[`echo $OCTAVEBIN | sed 's|octave\([^/]*\)$|octave-config\1|'`] - if test -r "$OCTAVECONFIG"; then - OCTAVEDIR=`$OCTAVECONFIG -p OCTINCLUDEDIR | sed 's|/octave$||'` - else - OCTAVEDIR="/usr/include" - fi - if test "$OCTAVEDIR" != ""; then - dirs="$OCTAVEDIR/octave $OCTAVEDIR" - OCTAVEEXT="" - for i in $dirs; do - if test -r $i/octave/oct.h; then - OCTAVEEXT="$i" - break; - fi - done - if test "$OCTAVEEXT" = "" ; then - AC_MSG_RESULT(not found) - else - AC_MSG_RESULT($OCTAVEEXT) - fi - - AC_MSG_CHECKING(for Octave compiler options) - OCTAVECCFLAGS="" - AC_MSG_RESULT($OCTAVECCFLAGS) - fi + AC_MSG_CHECKING([for mkoctfile]) + AS_IF([test "x`${OCTAVE} -qfH --eval 'mkoctfile -p CXX' 2>/dev/null`" != x],[ + AC_MSG_RESULT([yes]) + ],[ + AC_MSG_ERROR([mkoctfile is not installed]) + ]) + AC_MSG_CHECKING([for Octave preprocessor flags]) + OCTAVE_CPPFLAGS= + for n in CPPFLAGS INCFLAGS; do + OCTAVE_CPPFLAGS="${OCTAVE_CPPFLAGS} "`$OCTAVE -qfH --eval "mkoctfile -p $n"` + done + AC_MSG_RESULT($OCTAVE_CPPFLAGS) + AC_MSG_CHECKING([for Octave compiler flags]) + OCTAVE_CXXFLAGS= + for n in ALL_CXXFLAGS; do + OCTAVE_CXXFLAGS="${OCTAVE_CXXFLAGS} "`$OCTAVE -qfH --eval "mkoctfile -p $n"` + done + AC_MSG_RESULT($OCTAVE_CXXFLAGS) + AC_MSG_CHECKING([for Octave linker flags]) + OCTAVE_LDFLAGS= + for n in RDYNAMIC_FLAG LFLAGS RLD_FLAG OCTAVE_LIBS LIBS; do + OCTAVE_LDFLAGS="${OCTAVE_LDFLAGS} "`$OCTAVE -qfH --eval "mkoctfile -p $n"` + done + AC_MSG_RESULT($OCTAVE_LDFLAGS) else - AC_MSG_RESULT(could not figure out how to run octave) -fi - + AC_MSG_RESULT(could not figure out how to run octave) fi AC_SUBST(OCTAVE) -AC_SUBST(OCTAVEEXT) AC_SUBST(OCTAVE_SO) -AC_SUBST(OCTAVEDYNAMICLINKING) -AC_SUBST(OCTAVELIB) -AC_SUBST(OCTAVECCFLAGS) +AC_SUBST(OCTAVE_CPPFLAGS) +AC_SUBST(OCTAVE_CXXFLAGS) +AC_SUBST(OCTAVE_LDFLAGS) #---------------------------------------------------------------- # Look for java @@ -2215,7 +2207,7 @@ AC_SUBST(SKIP_PERL5) SKIP_OCTAVE= -if test -z "$OCTAVE" || test -z "$OCTAVEEXT" ; then +if test -z "$OCTAVE" ; then SKIP_OCTAVE="1" fi AC_SUBST(SKIP_OCTAVE) From de49578c31c7092ba9667969e1a830235f9a1aad Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 14 May 2012 09:23:20 +0000 Subject: [PATCH 0084/1160] Move Octave director-related code into Lib/octave/director.swg git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13084 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/director.swg | 123 ++++++++++++++++++++++++++- Lib/octave/octrun.swg | 178 ++++++++++------------------------------ 2 files changed, 164 insertions(+), 137 deletions(-) diff --git a/Lib/octave/director.swg b/Lib/octave/director.swg index 0d7e6c1b3..5e5d6f1f4 100644 --- a/Lib/octave/director.swg +++ b/Lib/octave/director.swg @@ -1,3 +1,124 @@ -// ***** move the director stuff from octrun.swg here... +# define SWIG_DIRECTOR_CAST(ARG) dynamic_cast(ARG) +namespace Swig { + + class Director { + octave_swig_type *self; + bool swig_disowned; + + Director(const Director &x); + Director &operator=(const Director &rhs); + public: + + Director(void *vptr):self(0), swig_disowned(false) { + set_rtdir(vptr, this); + } + + ~Director() { + swig_director_destroyed(self, this); + if (swig_disowned) + self->decref(); + } + + void swig_set_self(octave_swig_type *new_self) { + assert(!swig_disowned); + self = new_self; + } + + octave_swig_type *swig_get_self() const { + return self; + } + + void swig_disown() { + if (swig_disowned) + return; + swig_disowned = true; + self->incref(); + } + }; + + struct DirectorTypeMismatchException { + static void raise(const char *msg) { + // ... todo + throw(DirectorTypeMismatchException()); + } + + static void raise(const octave_value &ov, const char *msg) { + // ... todo + raise(msg); + } + }; + + struct DirectorPureVirtualException { + static void raise(const char *msg) { + // ... todo + throw(DirectorPureVirtualException()); + } + + static void raise(const octave_value &ov, const char *msg) { + // ... todo + raise(msg); + } + }; + + SWIGINTERN rtdir_map* get_rtdir_map() { + static swig_module_info *module = 0; + if (!module) + module = SWIG_GetModule(0); + if (!module) + return 0; + if (!module->clientdata) + module->clientdata = new rtdir_map; + return (rtdir_map *) module->clientdata; + } + + SWIGINTERNINLINE void set_rtdir(void *vptr, Director *d) { + rtdir_map* rm = get_rtdir_map(); + if (rm) + (*rm)[vptr] = d; + } + + SWIGINTERNINLINE void erase_rtdir(void *vptr) { + rtdir_map* rm = get_rtdir_map(); + if (rm) + (*rm).erase(vptr); + } + + SWIGINTERNINLINE Director *get_rtdir(void *vptr) { + rtdir_map* rm = get_rtdir_map(); + if (!rm) + return 0; + rtdir_map::const_iterator pos = rm->find(vptr); + Director *rtdir = (pos != rm->end())? pos->second : 0; + return rtdir; + } + + SWIGRUNTIME void swig_director_destroyed(octave_swig_type *self, Director *d) { + self->director_destroyed(d); + } + + SWIGRUNTIME octave_swig_type *swig_director_get_self(Director *d) { + return d->swig_get_self(); + } + + SWIGRUNTIME void swig_director_set_self(Director *d, octave_swig_type *self) { + d->swig_set_self(self); + } + +} + +SWIGRUNTIME void swig_acquire_ownership(void *vptr) { + // assert(0); + // ... todo +} + +SWIGRUNTIME void swig_acquire_ownership_array(void *vptr) { + // assert(0); + // ... todo +} + +SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own) { + // assert(0); + // ... todo +} diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index b006bfabe..cece12928 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -106,54 +106,33 @@ 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 { + +#ifdef SWIG_DIRECTORS + class Director; - //SWIGRUNTIME void swig_register_director(octave_swig_type *self, void *ptr, Director *d); + typedef std::map < void *, Director * > rtdir_map; + SWIGINTERN rtdir_map* get_rtdir_map(); + SWIGINTERNINLINE void set_rtdir(void *vptr, Director *d); + SWIGINTERNINLINE void erase_rtdir(void *vptr); + SWIGINTERNINLINE Director *get_rtdir(void *vptr); + SWIGRUNTIME void swig_director_destroyed(octave_swig_type *self, Director *d); + SWIGRUNTIME octave_swig_type *swig_director_get_self(Director *d); SWIGRUNTIME void swig_director_set_self(Director *d, octave_swig_type *self); +#endif + SWIGRUNTIME octave_base_value *swig_value_ref(octave_swig_type *ost); SWIGRUNTIME octave_swig_type *swig_value_deref(octave_value ov); SWIGRUNTIME octave_swig_type *swig_value_deref(const octave_base_value &ov); - - typedef std::map < void *, Director * > rtdir_map; - - SWIGINTERN rtdir_map* get_rtdir_map() { - static swig_module_info *module = 0; - if (!module) - module = SWIG_GetModule(0); - if (!module) - return 0; - if (!module->clientdata) - module->clientdata = new rtdir_map; - return (rtdir_map *) module->clientdata; - } - - SWIGINTERNINLINE void set_rtdir(void *vptr, Director *d) { - rtdir_map* rm = get_rtdir_map(); - if (rm) - (*rm)[vptr] = d; - } - - SWIGINTERNINLINE void erase_rtdir(void *vptr) { - rtdir_map* rm = get_rtdir_map(); - if (rm) - (*rm).erase(vptr); - } - - SWIGINTERNINLINE Director *get_rtdir(void *vptr) { - rtdir_map* rm = get_rtdir_map(); - if (!rm) - return 0; - rtdir_map::const_iterator pos = rm->find(vptr); - Director *rtdir = (pos != rm->end())? pos->second : 0; - return rtdir; - } } +SWIGRUNTIME void swig_acquire_ownership(void *vptr); +SWIGRUNTIME void swig_acquire_ownership_array(void *vptr); +SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); + struct swig_octave_member { const char *name; octave_func method; @@ -376,11 +355,13 @@ namespace Swig { always_static(_always_static) { if (_type || _ptr) types.push_back(std::make_pair(_type, _ptr)); +#ifdef SWIG_DIRECTORS if (_ptr) { Swig::Director *d = Swig::get_rtdir(_ptr); if (d) Swig::swig_director_set_self(d, this); } +#endif } ~octave_swig_type() { @@ -395,8 +376,10 @@ namespace Swig { } } } +#ifdef SWIG_DIRECTORS for (unsigned int j = 0; j < types.size(); ++j) Swig::erase_rtdir(types[j].second.ptr); +#endif } dim_vector dims(void) const { @@ -503,9 +486,11 @@ namespace Swig { rhs.own = 0; for (unsigned int j = 0; j < rhs.types.size(); ++j) { assert(!rhs.types[j].second.destroyed); +#ifdef SWIG_DIRECTORS Swig::Director *d = Swig::get_rtdir(rhs.types[j].second.ptr); if (d) Swig::swig_director_set_self(d, this); +#endif } types.insert(types.end(), rhs.types.begin(), rhs.types.end()); members.insert(rhs.members.begin(), rhs.members.end()); @@ -571,6 +556,7 @@ namespace Swig { return own; } +#ifdef SWIG_DIRECTORS void director_destroyed(Swig::Director *d) { bool found = false; for (unsigned int j = 0; j < types.size(); ++j) { @@ -582,6 +568,7 @@ namespace Swig { } assert(found); } +#endif void assign(const std::string &name, const octave_value &ov) { members[name] = std::make_pair((const swig_octave_member *) 0, ov); @@ -1225,111 +1212,28 @@ namespace Swig { return octave_value(octave_uint64((unsigned long long) ost->swig_this())); } -#define SWIG_DIRECTORS namespace Swig { - class Director { - octave_swig_type *self; - bool swig_disowned; - Director(const Director &x); - Director &operator=(const Director &rhs); - public: + SWIGRUNTIME octave_base_value *swig_value_ref(octave_swig_type *ost) { + return new octave_swig_ref(ost); + } - Director(void *vptr):self(0), swig_disowned(false) { - set_rtdir(vptr, this); - } + SWIGRUNTIME octave_swig_type *swig_value_deref(octave_value ov) { + if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1) + ov = ov.cell_value()(0); + return swig_value_deref(*ov.internal_rep()); + } - ~Director() { - swig_director_destroyed(self, this); - if (swig_disowned) - self->decref(); - } - - void swig_set_self(octave_swig_type *new_self) { - assert(!swig_disowned); - self = new_self; - } - - octave_swig_type *swig_get_self() const { - return self; - } - - void swig_disown() { - if (swig_disowned) - return; - swig_disowned = true; - self->incref(); - } - }; - - struct DirectorTypeMismatchException { - static void raise(const char *msg) { - // ... todo - throw(DirectorTypeMismatchException()); - } - - static void raise(const octave_value &ov, const char *msg) { - // ... todo - raise(msg); - } - }; - struct DirectorPureVirtualException { - static void raise(const char *msg) { - // ... todo - throw(DirectorPureVirtualException()); - } - - static void raise(const octave_value &ov, const char *msg) { - // ... todo - raise(msg); - } - }; + SWIGRUNTIME octave_swig_type *swig_value_deref(const octave_base_value &ov) { + if (ov.type_id() != octave_swig_ref::static_type_id()) + return 0; + const octave_swig_ref *osr = static_cast < const octave_swig_ref *>(&ov); + return osr->get_ptr(); + } } - SWIGRUNTIME void swig_acquire_ownership(void *vptr) { - // assert(0); - // ... todo - } - - SWIGRUNTIME void swig_acquire_ownership_array(void *vptr) { - // assert(0); - // ... todo - } - - SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own) { - // assert(0); - // ... todo - } - - namespace Swig { - SWIGRUNTIME void swig_director_destroyed(octave_swig_type *self, Director *d) { - self->director_destroyed(d); - } - - SWIGRUNTIME void swig_director_set_self(Director *d, octave_swig_type *self) { - d->swig_set_self(self); - } - - SWIGRUNTIME octave_base_value *swig_value_ref(octave_swig_type *ost) { - return new octave_swig_ref(ost); - } - - SWIGRUNTIME octave_swig_type *swig_value_deref(octave_value ov) { - if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1) - ov = ov.cell_value()(0); - return swig_value_deref(*ov.internal_rep()); - } - - SWIGRUNTIME octave_swig_type *swig_value_deref(const octave_base_value &ov) { - if (ov.type_id() != octave_swig_ref::static_type_id()) - return 0; - const octave_swig_ref *osr = static_cast < const octave_swig_ref *>(&ov); - return osr->get_ptr(); - } - - } #define swig_unary_op(name) \ SWIGRUNTIME octave_value swig_unary_op_##name(const octave_base_value &x) { \ @@ -1422,9 +1326,11 @@ octave_value_typeinfo::register_binary_op(octave_value::op_##name,tid1,tid2,swig SWIGRUNTIME octave_value SWIG_Octave_NewPointerObj(void *ptr, swig_type_info *type, int flags) { int own = (flags &SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; +#ifdef SWIG_DIRECTORS Swig::Director *d = Swig::get_rtdir(ptr); - if (d && d->swig_get_self()) - return d->swig_get_self()->as_value(); + if (d && Swig::swig_director_get_self(d)) + return Swig::swig_director_get_self(d)->as_value(); +#endif return Swig::swig_value_ref(new octave_swig_type(ptr, type, own)); } From a0dbe43c73a0fae5a7c0b1189bd901c29f21468a Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 14 May 2012 09:23:33 +0000 Subject: [PATCH 0085/1160] Move Octave SWIG runtime functions to Lib/octave/octruntime.swg - Add documentation strings for runtime functions git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13085 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/octrun.swg | 68 ---------------------------- Lib/octave/octruntime.swg | 94 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 93 insertions(+), 69 deletions(-) diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index cece12928..99e022e89 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -1144,74 +1144,6 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); } }; - octave_value_list swig_subclass(const octave_value_list &args, int nargout) { - octave_swig_type *top = new octave_swig_type; - for (int j = 0; j < args.length(); ++j) { - if (args(j).type_id() == octave_swig_ref::static_type_id()) { - octave_swig_ref *osr = static_cast < octave_swig_ref *>(args(j).internal_rep()); - octave_swig_type *ost = osr->get_ptr(); - if (!ost->is_owned()) { - error("cannot subclass object not constructed on octave side"); - return octave_value_list(); - } - top->merge(*ost); - } else if (args(j).is_function_handle()) { - top->assign(args(j).fcn_handle_value()->fcn_name(), args(j)); - } else if (args(j).is_string()) { - if (j + 1 >= args.length()) { - error("member assignments must be of string,value form"); - return octave_value_list(); - } - top->assign(args(j).string_value(), args(j + 1)); - ++j; - } else { - error("invalid arguments to subclass"); - return octave_value_list(); - } - } - return octave_value(Swig::swig_value_ref(top)); - } - - octave_value_list swig_type(const octave_value_list &args, int nargout) { - if (args.length() != 1) { - error("swig_typeinfo must be called with only a single object"); - return octave_value_list(); - } - octave_swig_type *ost = Swig::swig_value_deref(args(0)); - if (!ost) { - error("object is not a swig_ref"); - return octave_value_list(); - } - return octave_value(ost->swig_type_name()); - } - - octave_value_list swig_typequery(const octave_value_list &args, int nargout) { - if (args.length() != 1 || !args(0).is_string()) { - error("swig_typeinfo must be called with single string argument"); - return octave_value_list(); - } - swig_module_info *module = SWIG_GetModule(0); - swig_type_info *type = SWIG_TypeQueryModule(module, module, args(0).string_value().c_str()); - if (!type) - return octave_value(""); - return octave_value(type->name); - } - - octave_value_list swig_this(const octave_value_list &args, int nargout) { - if (args.length() != 1) { - error("swig_typeinfo must be called with only a single object"); - return octave_value_list(); - } - if (args(0).is_matrix_type() && args(0).rows() == 0 && args(0).columns() == 0) - return octave_value(octave_uint64(0)); - octave_swig_type *ost = Swig::swig_value_deref(args(0)); - if (!ost) { - error("object is not a swig_ref"); - return octave_value_list(); - } - return octave_value(octave_uint64((unsigned long long) ost->swig_this())); - } - namespace Swig { diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index 650298d5c..3aa866264 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -22,6 +22,98 @@ static void SWIG_init_user(octave_swig_type* module_ns); octave_value_list SWIG_atexit_func(const octave_value_list &args, int nargout); #endif +static const char *const subclass_usage = "-*- texinfo -*- \n\ +@deftypefn {Loadable Function} {} subclass()\n\ +@deftypefnx{Loadable Function} {} subclass(@var{swigclass}, @var{name}, @var{fcn}, @dots{})\n\ +Subclass a C++ class from within Octave, and provide implementations of its virtual methods.\n\ +\n\ +See the SWIG manual for usage examples.\n\ +@end deftypefn"; + +DEFUN_DLD( subclass, args, nargout, subclass_usage ) { + octave_swig_type *top = new octave_swig_type; + for (int j = 0; j < args.length(); ++j) { + if (args(j).type_id() == octave_swig_ref::static_type_id()) { + octave_swig_ref *osr = static_cast < octave_swig_ref *>(args(j).internal_rep()); + octave_swig_type *ost = osr->get_ptr(); + if (!ost->is_owned()) { + error("cannot subclass object not constructed on octave side"); + return octave_value_list(); + } + top->merge(*ost); + } else if (args(j).is_function_handle()) { + top->assign(args(j).fcn_handle_value()->fcn_name(), args(j)); + } else if (args(j).is_string()) { + if (j + 1 >= args.length()) { + error("member assignments must be of string,value form"); + return octave_value_list(); + } + top->assign(args(j).string_value(), args(j + 1)); + ++j; + } else { + error("invalid arguments to subclass()"); + return octave_value_list(); + } + } + return octave_value(Swig::swig_value_ref(top)); +} + +static const char *const swig_type_usage = "-*- texinfo -*- \n\ +@deftypefn {Loadable Function} {} swig_type(@var{swigref})\n\ +Return the underlying C/C++ type name of a SWIG-wrapped object.\n\ +@end deftypefn"; + +DEFUN_DLD( swig_type, args, nargout, swig_type_usage ) { + if (args.length() != 1) { + error("swig_type() must be called with only a single object"); + return octave_value_list(); + } + octave_swig_type *ost = Swig::swig_value_deref(args(0)); + if (!ost) { + error("object is not a swig_ref"); + return octave_value_list(); + } + return octave_value(ost->swig_type_name()); +} + +static const char *const swig_typequery_usage = "-*- texinfo -*- \n\ +@deftypefn {Loadable Function} {} swig_typequery(@var{string})\n\ +Return @var{string} if it is a recognised SWIG-wrapped C/C++ type name;\n\ +otherwise return `'.\n\ +@end deftypefn"; + +DEFUN_DLD( swig_typequery, args, nargout, swig_typequery_usage ) { + if (args.length() != 1 || !args(0).is_string()) { + error("swig_typequery() must be called with single string argument"); + return octave_value_list(); + } + swig_module_info *module = SWIG_GetModule(0); + swig_type_info *type = SWIG_TypeQueryModule(module, module, args(0).string_value().c_str()); + if (!type) + return octave_value(""); + return octave_value(type->name); +} + +static const char *const swig_this_usage = "-*- texinfo -*- \n\ +@deftypefn {Loadable Function} {} swig_this(@var{swigref})\n\ +Return the underlying C/C++ pointer of a SWIG-wrapped object.\n\ +@end deftypefn"; + +DEFUN_DLD( swig_this, args, nargout, swig_this_usage ) { + if (args.length() != 1) { + error("swig_this() must be called with only a single object"); + return octave_value_list(); + } + if (args(0).is_matrix_type() && args(0).rows() == 0 && args(0).columns() == 0) + return octave_value(octave_uint64(0)); + octave_swig_type *ost = Swig::swig_value_deref(args(0)); + if (!ost) { + error("object is not a swig_ref"); + return octave_value_list(); + } + return octave_value(octave_uint64((unsigned long long) ost->swig_this())); +} + DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) { // determine if module is already loaded @@ -90,7 +182,7 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) { install_builtin_function(swig_type,"swig_type",std::string()); install_builtin_function(swig_typequery,"swig_typequery",std::string()); install_builtin_function(swig_this,"swig_this",std::string()); - install_builtin_function(swig_subclass,"subclass",std::string()); + install_builtin_function(subclass,"subclass",std::string()); octave_swig_type* cvar_ns=0; if (global_name != ".") { From bf0fe8346254d8bb0d0135d943965903b74ee968 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 14 May 2012 09:23:45 +0000 Subject: [PATCH 0086/1160] New functions for handling Octave global variables - Creates a copy of the variable to be assigned to the symbol table, so it can be safely deallocated on exit git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13086 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/octrun.swg | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 99e022e89..a9ee5380f 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -1304,8 +1304,34 @@ void SWIG_Octave_SetConstant(octave_swig_type *module_ns, const std::string &nam module_ns->assign(name, ov); } +SWIGRUNTIMEINLINE octave_value SWIG_Octave_GetGlobalValue(std::string name) { + return get_global_value(name, true); +} + +SWIGRUNTIME void SWIG_Octave_SetGlobalValue(std::string name, const octave_value& value) { + // It is critical that a newly-allocated octave_value is passed to set_global_value(), + // since it and the Octave symbol table take references to the values assigned to it. + // If we were to pass a reference to 'value' to set_global_value(), then the Octave + // symbol table would hold a reference to a variable owned by the SWIG .oct module. + // Both will think that they own the reference (since the .oct module is dynamically + // loaded, it appears to have its own C++ runtime), and so they will both try to + // de-allocate the octave_value on exit, resulting in a double-free or seg-fault. + // This is prevented by giving Octave its own heap-allocated copy of 'value'. + octave_value *pov = new octave_value(value); + set_global_value(name, *pov); +} + +SWIGRUNTIME void SWIG_Octave_LinkGlobalValue(std::string name) { +#if OCTAVE_API_VERSION_NUMBER < 37 + link_to_global_variable(curr_sym_tab->lookup(name, true)); +#else + symbol_table::varref(name); + symbol_table::mark_global(name); +#endif +} + SWIGRUNTIME swig_module_info *SWIG_Octave_GetModule(void *clientdata) { - octave_value ov = get_global_value("__SWIG_MODULE__" SWIG_TYPE_TABLE_NAME SWIG_RUNTIME_VERSION, true); + octave_value ov = SWIG_Octave_GetGlobalValue("__SWIG_MODULE__" SWIG_TYPE_TABLE_NAME SWIG_RUNTIME_VERSION); if (!ov.is_defined() || ov.type_id() != octave_swig_packed::static_type_id()) return 0; @@ -1318,12 +1344,5 @@ SWIGRUNTIME swig_module_info *SWIG_Octave_GetModule(void *clientdata) { SWIGRUNTIME void SWIG_Octave_SetModule(void *clientdata, swig_module_info *pointer) { octave_value ov = new octave_swig_packed(0, &pointer, sizeof(swig_module_info *)); - const char *module_var = "__SWIG_MODULE__" SWIG_TYPE_TABLE_NAME SWIG_RUNTIME_VERSION; -#if OCTAVE_API_VERSION_NUMBER<37 - link_to_global_variable(curr_sym_tab->lookup(module_var, true)); -#else - symbol_table::varref(module_var); - symbol_table::mark_global(module_var); -#endif - set_global_value(module_var, ov); + SWIG_Octave_SetGlobalValue("__SWIG_MODULE__" SWIG_TYPE_TABLE_NAME SWIG_RUNTIME_VERSION, ov); } From 4f11aaa8492b176ee15f5b3d9055585f46746351 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 14 May 2012 09:24:00 +0000 Subject: [PATCH 0087/1160] Declare Octave public wrapping functions with DEFUNX_DLD - New helper function Octave_begin_function writes function declaration and installer function definition using SWIG_DEFUN macro, which in turn uses Octave DEFUNX_DLD macro - Can now use Octave's dynamic module loader to load functions safely - Link documentation of public wrapping functions through DEFUNX_DLD git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13087 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/octrun.swg | 6 +++ Source/Modules/octave.cxx | 81 +++++++++++++++++++++++++-------------- 2 files changed, 59 insertions(+), 28 deletions(-) diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index a9ee5380f..3ab6c7525 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -14,6 +14,12 @@ #endif +#if OCTAVE_API_VERSION_NUMBER < 37 +#define SWIG_DEFUN(cname, wname, doc) DEFUNX_DLD(#cname, wname, FS ## cname, args, nargout, doc) +#else +#define SWIG_DEFUN(cname, wname, doc) DEFUNX_DLD(#cname, wname, G ## cname, args, nargout, doc) +#endif + SWIGRUNTIME bool SWIG_check_num_args(const char *func_name, int num_args, int max_args, int min_args, int varargs) { if (num_args > max_args && !varargs) error("function %s takes at most %i arguments", func_name, max_args); diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 296920000..aa28dc54c 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -50,6 +50,16 @@ private: Hash *docs; + void Octave_begin_function(Node *n, File *f, const_String_or_char_ptr cname, const_String_or_char_ptr wname, bool dld) { + if (dld) { + String *tname = texinfo_name(n, "std::string()"); + Printf(f, "SWIG_DEFUN( %s, %s, %s ) {", cname, wname, tname); + } + else { + Printf(f, "static octave_value_list %s (const octave_value_list& args, int nargout) {", wname); + } + } + public: OCTAVE():f_begin(0), f_runtime(0), f_header(0), f_doc(0), f_wrappers(0), f_init(0), f_initbeforefunc(0), f_directors(0), f_directors_h(0), @@ -293,14 +303,14 @@ public: return !Len(synopsis) && !Len(decl_info) && !Len(cdecl_info) && !Len(args_info); } - String *texinfo_name(Node* n) { + String *texinfo_name(Node* n, const char* defval = "0") { String *tname = NewString(""); String *iname = Getattr(n, "sym:name"); String *wname = Swig_name_wrapper(iname); Node* d = Getattr(docs, wname); if (is_empty_doc_node(d)) - Printf(tname, "0"); + Printf(tname, defval); else Printf(tname, "%s_texinfo", wname); @@ -543,7 +553,10 @@ public: if (overloaded) Append(overname, Getattr(n, "sym:overname")); - Printv(f->def, "static octave_value_list ", overname, " (const octave_value_list& args, int nargout) {", NIL); + if (!overloaded || last_overload) + process_autodoc(n); + + Octave_begin_function(n, f->def, iname, overname, !overloaded); emit_parameter_variables(l, f); emit_attach_parmmaps(l, f); @@ -743,7 +756,6 @@ public: dispatchFunction(n); if (!overloaded || last_overload) { - process_autodoc(n); String *tname = texinfo_name(n); Printf(s_global_tab, "{\"%s\",%s,0,0,2,%s},\n", iname, wname, tname); Delete(tname); @@ -766,7 +778,7 @@ public: String *dispatch = Swig_overload_dispatch(n, "return %s(args, nargout);", &maxargs); String *tmp = NewString(""); - Printv(f->def, "static octave_value_list ", wname, " (const octave_value_list& args, int nargout) {", NIL); + Octave_begin_function(n, f->def, iname, wname, true); Wrapper_add_local(f, "argc", "int argc = args.length()"); Printf(tmp, "octave_value_ref argv[%d]={", maxargs); for (int j = 0; j < maxargs; ++j) @@ -800,7 +812,10 @@ public: 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); + String *getwname = Swig_name_wrapper(getname); + String *setwname = Swig_name_wrapper(setname); + + Octave_begin_function(n, setf->def, setname, setwname, true); Printf(setf->def, "if (!SWIG_check_num_args(\"%s_set\",args.length(),1,1,0)) return octave_value_list();", iname); if (is_assignable(n)) { Setattr(n, "wrap:name", setname); @@ -826,7 +841,7 @@ public: Setattr(n, "wrap:name", getname); int addfail = 0; - Printf(getf->def, "static octave_value_list _wrap_%s(const octave_value_list& args,int nargout) {", getname); + Octave_begin_function(n, getf->def, getname, getwname, true); Wrapper_add_local(getf, "obj", "octave_value obj"); if ((tm = Swig_typemap_lookup("varout", n, name, 0))) { Replaceall(tm, "$source", name); @@ -845,7 +860,10 @@ public: Append(getf->code, "}\n"); Wrapper_print(getf, f_wrappers); - Printf(s_global_tab, "{\"%s\",0,_wrap_%s,_wrap_%s,2,0},\n", iname, getname, setname); + Printf(s_global_tab, "{\"%s\",0,%s,%s,2,0},\n", iname, getwname, setwname); + + Delete(getwname); + Delete(setwname); return SWIG_OK; } @@ -937,20 +955,21 @@ public: String *nspace = Getattr(n, "sym:nspace"); String *cname = Swig_name_disown(nspace, class_name); String *wcname = Swig_name_wrapper(cname); - String *disown_shadow = NewString(""); - Printf(disown_shadow, "static octave_value_list %s_shadow " "(const octave_value_list& args, int nargout) {\n", wcname); - Printf(disown_shadow, " if (args.length()!=1) {\n"); - Printf(disown_shadow, " error(\"disown takes no arguments\");\n"); - Printf(disown_shadow, " return octave_value_list();\n"); - Printf(disown_shadow, " }\n"); - Printf(disown_shadow, " %s (args, nargout);\n", wcname); - Printf(disown_shadow, " return args;\n"); - Printf(disown_shadow, "}\n"); - Printv(f_wrappers, disown_shadow, NIL); - Delete(disown_shadow); - Printf(s_members_tab, "{\"__disown\",%s_shadow,0,0,0,0},\n", wcname); + String *cnameshdw = NewStringf("%s_shadow", cname); + String *wcnameshdw = Swig_name_wrapper(cnameshdw); + Octave_begin_function(n, f_wrappers, cnameshdw, wcnameshdw, true); + Printf(f_wrappers, " if (args.length()!=1) {\n"); + Printf(f_wrappers, " error(\"disown takes no arguments\");\n"); + Printf(f_wrappers, " return octave_value_list();\n"); + Printf(f_wrappers, " }\n"); + Printf(f_wrappers, " %s (args, nargout);\n", wcname); + Printf(f_wrappers, " return args;\n"); + Printf(f_wrappers, "}\n"); + Printf(s_members_tab, "{\"__disown\",%s,0,0,0,0},\n", wcnameshdw); Delete(wcname); Delete(cname); + Delete(wcnameshdw); + Delete(cnameshdw); } Printf(s_members_tab, "{0,0,0,0}\n};\n"); @@ -1049,15 +1068,18 @@ public: assert(s_members_tab); assert(class_name); String *symname = Getattr(n, "sym:name"); - 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(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname))); + String *getname = Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname)); + String *setname = Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname)); + String *getwname = Swig_name_wrapper(getname); + String *setwname = GetFlag(n, "feature:immutable") ? NewString("octave_set_immutable") : Swig_name_wrapper(setname); assert(s_members_tab); - Printf(s_members_tab, "{\"%s\",0,%s,%s,0,0},\n", symname, getname, setname); + Printf(s_members_tab, "{\"%s\",0,%s,%s,0,0},\n", symname, getwname, setwname); Delete(getname); Delete(setname); + Delete(getwname); + Delete(setwname); return SWIG_OK; } @@ -1132,15 +1154,18 @@ public: assert(s_members_tab); assert(class_name); String *symname = Getattr(n, "sym:name"); - 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(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname))); + String *getname = Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname)); + String *setname = Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname)); + String *getwname = Swig_name_wrapper(getname); + String *setwname = GetFlag(n, "feature:immutable") ? NewString("octave_set_immutable") : Swig_name_wrapper(setname); assert(s_members_tab); - Printf(s_members_tab, "{\"%s\",0,%s,%s,1,0},\n", symname, getname, setname); + Printf(s_members_tab, "{\"%s\",0,%s,%s,1,0},\n", symname, getwname, setwname); Delete(getname); Delete(setname); + Delete(getwname); + Delete(setwname); } return SWIG_OK; } From bc2a78fbab956fc87212da06f9dd5ef423aeeb40 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 14 May 2012 09:24:15 +0000 Subject: [PATCH 0088/1160] New Octave module loading behaviour - Use call syntax instead of cmdline to choose global/noglobal load: global: 'example;', noglobal: 'example = example;' - All functions loaded with Octave 'autoload' command; correctly loads .oct module and prevents segfault in Octave 3.0.5 - Functions no longer installed as global variables as well, so global operator dispatch now only looks for functions - Octave at-exit function created from string, not function, so no dependence on loaded .oct files at cleanup time - C at-exit function now immediately exits Octave (with correct status) to prevent seg-fault due to dodgy memory cleanup in some Octave versions - Documentation string for module loading function git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13088 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/octrun.swg | 40 +----- Lib/octave/octruntime.swg | 258 +++++++++++++++++++------------------- Source/Modules/octave.cxx | 22 ++-- 3 files changed, 146 insertions(+), 174 deletions(-) diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 3ab6c7525..24dae705a 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -504,37 +504,9 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); rhs.members.clear(); } - void install_global(bool global_load) { - for (member_map::const_iterator it = members.begin(); it != members.end(); ++it) { - bool is_global_op = (it->first.substr(0, strlen(SWIG_op_prefix)) == SWIG_op_prefix); - bool is_func_defined = (it->second.first && it->second.first->method); - if (is_func_defined && (is_global_op || global_load)) { - install_builtin_function(it->second.first->method, it->first, - it->second.first->doc ? it->second.first->doc : std::string()); - } - octave_value global_val = is_global_op ? make_fcn_handle(it->first) : it->second.second; - if (global_val.is_defined() && (is_global_op || global_load)) { -#if OCTAVE_API_VERSION_NUMBER<37 - link_to_global_variable(curr_sym_tab->lookup(it->first, true)); -#else - symbol_table::varref(it->first); - symbol_table::mark_global(it->first); -#endif - set_global_value(it->first, global_val); - -#if OCTAVE_API_VERSION_NUMBER<37 - octave_swig_type *ost = Swig::swig_value_deref(global_val); - if (ost) { - const char* h = ost->help_text(); - if (h) { - symbol_record *sr = global_sym_tab->lookup (it->first, true); - sr->document(h); - } - } -#endif - } - } - } + typedef member_map::const_iterator swig_member_const_iterator; + swig_member_const_iterator swig_members_begin() { return members.begin(); } + swig_member_const_iterator swig_members_end() { return members.end(); } void *cast(swig_type_info *type, int *_own, int flags) { if (_own) @@ -835,10 +807,10 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); // we assume that SWIG_op_prefix-prefixed functions are installed in global namespace // (rather than any module namespace). - octave_value fcn = get_global_value(symbol, true); - if (!fcn.is_function() && !fcn.is_function_handle()) + octave_function *fcn = is_valid_function(symbol, std::string(), false); + if (!fcn) return false; - ret = fcn.subsref("(", std::list < octave_value_list > (1, args), 1); + ret = fcn->do_multi_index_op(1, args)(0); return true; } diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index 3aa866264..e23068438 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -1,11 +1,14 @@ %insert(runtime) %{ #include #include -#include -#include #include +#include +#include #include +#include +#include #include +#include %} %insert(runtime) "swigrun.swg"; @@ -18,9 +21,12 @@ static void SWIG_init_user(octave_swig_type* module_ns); -#if OCTAVE_API_VERSION_NUMBER>=37 -octave_value_list SWIG_atexit_func(const octave_value_list &args, int nargout); -#endif +SWIGINTERN void SWIG_Octave_InstallFunction(octave_function *octloadfcn, std::string name) { + octave_value_list args; + args.append(name); + args.append(octloadfcn->fcn_file_name()); + feval("autoload", args, 0); +} static const char *const subclass_usage = "-*- texinfo -*- \n\ @deftypefn {Loadable Function} {} subclass()\n\ @@ -114,87 +120,94 @@ DEFUN_DLD( swig_this, args, nargout, swig_this_usage ) { return octave_value(octave_uint64((unsigned long long) ost->swig_this())); } -DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) { - - // determine if module is already loaded - bool already_load; -#if OCTAVE_API_VERSION_NUMBER<37 - { - symbol_record *rec = curr_sym_tab->lookup(SWIG_name_d); - already_load = (rec && rec->is_linked_to_global()); - } -#else - already_load = symbol_table::is_global(SWIG_name_d); +// workaround to prevent octave seg-faulting on exit: register at-exit +// function which exits octave immediately without trying to cleanup memory. +// definitely affects version 3.2.*, not sure about 3.3.*, seems to be +// fixed in version 3.4.* and above. can be turned on/off with macros. +#ifndef SWIG_OCTAVE_NO_SEGFAULT_HACK +#if 36 < OCTAVE_API_VERSION_NUMBER && OCTAVE_API_VERSION_NUMBER < 45 +#define SWIG_OCTAVE_SEGFAULT_HACK #endif - if (!already_load) { - - // parse command line - const char* usage="usage: " SWIG_name_d " [-global|-noglobal] [-globals {|.}]"; - bool global_load=SWIG_global_load; - std::string global_name=SWIG_global_name; - for (int j=0;j= 37 + octave_value_list eval_args; + eval_args.append("base"); + eval_args.append("function __swig_atexit__; " + " if mislocked() " + " clear -all; " + " else " + " mlock(); " + " endif; " + "endfunction; " + "__swig_atexit__; " + "atexit(\"__swig_atexit__\", false); " + "atexit(\"__swig_atexit__\")"); + feval("evalin", eval_args, 0); +#endif + octave_swig_ref::register_type(); octave_swig_packed::register_type(); SWIG_InitializeModule(0); SWIG_PropagateClientData(); - - install_builtin_function(swig_type,"swig_type",std::string()); - install_builtin_function(swig_typequery,"swig_typequery",std::string()); - install_builtin_function(swig_this,"swig_this",std::string()); - install_builtin_function(subclass,"subclass",std::string()); - + + octave_function *me = octave_call_stack::current(); + + SWIG_Octave_InstallFunction(me, "swig_type"); + SWIG_Octave_InstallFunction(me, "swig_typequery"); + SWIG_Octave_InstallFunction(me, "swig_this"); + SWIG_Octave_InstallFunction(me, "subclass"); + octave_swig_type* cvar_ns=0; - if (global_name != ".") { + if (SWIG_global_name != ".") { cvar_ns=new octave_swig_type; for (int j=0;swig_globals[j].name;++j) if (swig_globals[j].get_method) cvar_ns->assign(swig_globals[j].name,&swig_globals[j]); } - - octave_swig_type* module_ns=new octave_swig_type(0, 0, 0, true); - if (global_name != ".") { - module_ns->assign(global_name,Swig::swig_value_ref(cvar_ns)); + + module_ns=new octave_swig_type(0, 0, 0, true); + if (SWIG_global_name != ".") { + module_ns->assign(SWIG_global_name,Swig::swig_value_ref(cvar_ns)); } else { for (int j=0;swig_globals[j].name;++j) @@ -204,72 +217,63 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) { for (int j=0;swig_globals[j].name;++j) if (swig_globals[j].method) module_ns->assign(swig_globals[j].name,&swig_globals[j]); - - // * need better solution here; swig_type -> octave_class mapping is - // * really n-to-1, in some cases such as template partial spec, etc. + + // * need better solution here; swig_type -> octave_class mapping is + // * really n-to-1, in some cases such as template partial spec, etc. // * see failing tests. for (int j=0;swig_types[j];++j) if (swig_types[j]->clientdata) { swig_octave_class* c=(swig_octave_class*)swig_types[j]->clientdata; module_ns->assign(c->name, - Swig::swig_value_ref - (new octave_swig_type(0,swig_types[j]))); + Swig::swig_value_ref + (new octave_swig_type(0,swig_types[j]))); } - - SWIG_init_user(module_ns); - - SWIG_InstallOps(octave_swig_ref::static_type_id()); - - // the incref is necessary so install_global doesn't destroy module_ns, - // as it would if it installed something with the same name as the module. - module_ns->incref(); - module_ns->install_global(global_load); - module_ns->decref(); - - // create global variable containing module - set_global_value(SWIG_name_d,Swig::swig_value_ref(module_ns)); - -#if OCTAVE_API_VERSION_NUMBER>=37 - install_builtin_function(SWIG_atexit_func,"__swig_atexit_" SWIG_name_d "__",std::string()); - octave_add_atexit_function("__swig_atexit_" SWIG_name_d "__"); - octave_remove_atexit_function("__finish__"); -#endif - // return from base frame -#if OCTAVE_API_VERSION_NUMBER<37 - curr_sym_tab = prev_sym_tab; + SWIG_init_user(module_ns); + + SWIG_InstallOps(octave_swig_ref::static_type_id()); + +#if OCTAVE_API_VERSION_NUMBER < 37 + mlock(me->name()); #else - octave_call_stack::pop(); -#endif - -#if OCTAVE_API_VERSION_NUMBER>=37 mlock(); #endif - } // !already_load - - // link variable to module in current context -#if OCTAVE_API_VERSION_NUMBER<37 - link_to_global_variable(curr_sym_tab->lookup(SWIG_name_d,true)); -#else - symbol_table::varref(SWIG_name_d); - symbol_table::mark_global(SWIG_name_d); -#endif + } - return octave_value_list(); -} + // return module if asked for + if (args.length() == 0 && nargout == 1) { + retval = octave_value(module_ns->as_value()); + } + + // if call with not output arguments, load globally + else if (args.length() == 0 && nargout == 0) { + + octave_function *me = octave_call_stack::current(); + + octave_swig_type::swig_member_const_iterator mb; + for (mb = module_ns->swig_members_begin(); mb != module_ns->swig_members_end(); ++mb) { + if (mb->second.first && mb->second.first->method) { + SWIG_Octave_InstallFunction(me, mb->first); + } + else if (mb->second.second.is_defined()) { + SWIG_Octave_SetGlobalValue(mb->first, mb->second.second); + SWIG_Octave_LinkGlobalValue(mb->first); + } + } + + SWIG_Octave_SetGlobalValue(SWIG_name_d, module_ns->as_value()); + SWIG_Octave_LinkGlobalValue(SWIG_name_d); + + } + + // otherwise print usage + else { + print_usage(); + } + + return retval; -// workaround bug in octave where installing global variable of custom type and then -// exiting without explicitly clearing the variable causes octave to segfault. -#if OCTAVE_API_VERSION_NUMBER>=37 -octave_value_list SWIG_atexit_func(const octave_value_list &args, int nargout) { - string_vector vars = symbol_table::global_variable_names(); - for (int i = 0; i < vars.length(); i++) - symbol_table::clear_global(vars[i]); - symbol_table::clear_functions(); - return octave_value(); } -#endif %} - diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index aa28dc54c..1b8156b33 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -15,16 +15,13 @@ char cvsroot_octave_cxx[] = "$Id$"; #include "swigmod.h" -static bool global_load = true; static String *global_name = 0; static String *op_prefix = 0; static const char *usage = (char *) "\ Octave Options (available with -octave)\n\ - -global - Load all symbols into the global namespace [default]\n\ -globals - Set used to access C global variables [default: 'cvar']\n\ - - Use '.' to load C global variables into module namespace\n\ - -noglobal - Do not load all symbols into the global namespace\n\ + Use '.' to load C global variables into module namespace\n\ -opprefix - Prefix for global operator functions [default: 'op_']\n\ \n"; @@ -83,12 +80,13 @@ public: if (argv[i]) { if (strcmp(argv[i], "-help") == 0) { fputs(usage, stdout); - } else if (strcmp(argv[i], "-global") == 0) { - global_load = true; - Swig_mark_arg(i); - } else if (strcmp(argv[i], "-noglobal") == 0) { - global_load = false; - Swig_mark_arg(i); + } else if (strcmp(argv[i], "-global") == 0 || + strcmp(argv[i], "-noglobal") == 0) { + Printv(stderr, + "*** -global/-noglobal are no longer supported\n" + "*** global load behaviour is now determined at module load\n" + "*** see the Perl section in the manual for details.\n", NIL); + SWIG_exit(EXIT_FAILURE); } else if (strcmp(argv[i], "-globals") == 0) { if (argv[i + 1]) { global_name = NewString(argv[i + 1]); @@ -179,10 +177,8 @@ public: Printf(f_runtime, "#define SWIG_name %s\n", module); Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIG_global_load %s\n", global_load ? "true" : "false"); Printf(f_runtime, "#define SWIG_global_name \"%s\"\n", global_name); Printf(f_runtime, "#define SWIG_op_prefix \"%s\"\n", op_prefix); - Printf(f_runtime, "#define SWIG_atexit_func swig_atexit_%s\n", module); if (directorsEnabled()) { Printf(f_runtime, "#define SWIG_DIRECTORS\n"); @@ -383,7 +379,7 @@ public: virtual int importDirective(Node *n) { String *modname = Getattr(n, "module"); if (modname) - Printf(f_init, "feval(\"%s\",octave_value_list(),0);\n", modname); + Printf(f_init, "feval(\"%s\",octave_value_list(),1);\n", modname); return Language::importDirective(n); } From daffde6c2814a145cb0658a3c8dff440fb9f0dbd Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 14 May 2012 09:24:34 +0000 Subject: [PATCH 0089/1160] Updated Octave module_load examples for new module loading - Module compiled twice to check '-globals .' behaviour - Only one runme.m needed since clearing modules should now be safe for all Octave versions. - Tests new module loading syntax and behaviour git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13089 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/Makefile.in | 4 +- Examples/octave/module_load/Makefile | 12 +- Examples/octave/module_load/example.i | 2 +- Examples/octave/module_load/runme.m | 112 ++++++++++++++++++ Examples/octave/module_load/runme_args.m | 48 -------- Examples/octave/module_load/runme_gl_func.m | 59 --------- .../octave/module_load/runme_gl_func_base.m | 59 --------- Examples/octave/module_load/runme_nogl_func.m | 55 --------- .../octave/module_load/runme_nogl_func_base.m | 55 --------- 9 files changed, 118 insertions(+), 288 deletions(-) create mode 100644 Examples/octave/module_load/runme.m delete mode 100644 Examples/octave/module_load/runme_args.m delete mode 100644 Examples/octave/module_load/runme_gl_func.m delete mode 100644 Examples/octave/module_load/runme_gl_func_base.m delete mode 100644 Examples/octave/module_load/runme_nogl_func.m delete mode 100644 Examples/octave/module_load/runme_nogl_func_base.m diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 8d63d02b5..04f794f61 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -365,9 +365,7 @@ octave_cpp: $(SRCS) OCTSCRIPT = runme.m octave_run: $(OCTSCRIPT) - for file in $(OCTSCRIPT); do \ - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH OCTAVE_PATH=$(srcdir):$$OCTAVE_PATH $(OCTAVE) $$file >/dev/null || break; \ - done + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH OCTAVE_PATH=$(srcdir):$$OCTAVE_PATH $(OCTAVE) $(OCTSCRIPT) >/dev/null # ----------------------------------------------------------------- # Cleaning the octave examples diff --git a/Examples/octave/module_load/Makefile b/Examples/octave/module_load/Makefile index 4266ec184..da2c704e0 100644 --- a/Examples/octave/module_load/Makefile +++ b/Examples/octave/module_load/Makefile @@ -3,16 +3,12 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -OCTSCRIPTS = \ - runme_args.m \ - runme_gl_func.m \ - runme_gl_func_base.m \ - runme_nogl_func.m \ - runme_nogl_func_base.m all:: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave + TARGET='$(TARGET)' SWIGOPT='-module $$(TARGET)' INTERFACE='$(INTERFACE)' octave + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)2' SWIGOPT='-module $$(TARGET) -globals .' INTERFACE='$(INTERFACE)' octave static:: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ @@ -23,4 +19,4 @@ clean:: rm -f $(TARGET).m check: all - $(MAKE) -f $(TOP)/Makefile OCTSCRIPT="$(OCTSCRIPTS)" octave_run + $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/module_load/example.i b/Examples/octave/module_load/example.i index f5a50444d..fd074d4f2 100644 --- a/Examples/octave/module_load/example.i +++ b/Examples/octave/module_load/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module example +/* module name given on cmdline */ %{ #include "example.h" %} diff --git a/Examples/octave/module_load/runme.m b/Examples/octave/module_load/runme.m new file mode 100644 index 000000000..4942a02de --- /dev/null +++ b/Examples/octave/module_load/runme.m @@ -0,0 +1,112 @@ +# file: runme_args.m + +# test module loading with arguments +clear all + +# access module, no global load +example = example; +assert(example.cvar.ivar == example.ifunc()); +clear all +example = example; +assert(example.cvar.ivar == example.ifunc()); +clear all + +# load module globally +example; +assert(cvar.ivar == ifunc); +assert(exist("example","var")); +clear all +example; +assert(cvar.ivar == ifunc); +assert(exist("example","var")); +clear all + +# access module in a function, no global load +function testme + example = example; + assert(example.cvar.ivar == example.ifunc()); +endfunction +testme +testme +example = example; +assert(example.cvar.ivar == example.ifunc()); +clear all +function testme + example = example; + assert(example.cvar.ivar == example.ifunc()); +endfunction +testme +testme +example = example; +assert(example.cvar.ivar == example.ifunc()); +clear all + +# load module in a function globally before base context +function testme + example; + assert(cvar.ivar == ifunc); + assert(exist("example","var")); +endfunction +testme +testme +example; +assert(cvar.ivar == ifunc); +assert(exist("example","var")); +clear all +function testme + example; + assert(cvar.ivar == ifunc); + assert(exist("example","var")); +endfunction +testme +testme +example; +assert(cvar.ivar == ifunc); +assert(exist("example","var")); +clear all + +# load module in a function globally after base context +example; +assert(cvar.ivar == ifunc); +assert(exist("example","var")); +function testme + example; + assert(cvar.ivar == ifunc); + assert(exist("example","var")); +endfunction +testme +testme +clear all +example; +assert(cvar.ivar == ifunc); +assert(exist("example","var")); +function testme + example; + assert(cvar.ivar == ifunc); + assert(exist("example","var")); +endfunction +testme +testme +clear all + +# access module with no cvar, no global load +example2 = example2; +assert(example2.ivar == example2.ifunc()); +assert(!isglobal("cvar")) +clear all +example2 = example2; +assert(example2.ivar == example2.ifunc()); +assert(!isglobal("cvar")) +clear all + +# load module with no cvar globally +example2; +assert(example2.ivar == ifunc); +assert(exist("example2","var")); +assert(!isglobal("cvar")) +clear all +example2; +assert(example2.ivar == ifunc); +assert(exist("example2","var")); +assert(!isglobal("cvar")) +clear all diff --git a/Examples/octave/module_load/runme_args.m b/Examples/octave/module_load/runme_args.m deleted file mode 100644 index 716ee31f9..000000000 --- a/Examples/octave/module_load/runme_args.m +++ /dev/null @@ -1,48 +0,0 @@ -# file: runme_args.m - -# test module loading with arguments - -##### BEGIN TEST ##### -# test help -example -help -assert(!isglobal("example")) - -# load module with custom cvar -example -globals mycvar -assert(!isglobal("cvar")) -assert(mycvar.ivar == example.ifunc()) -##### END TEST ##### - -# clearing a module results in a segfault for Octave <= 3.0.* -# (tested on Octave 3.0.5), so skip the following test -try - vers = cellfun("str2num", strsplit(OCTAVE_VERSION, ".")); -catch - vers = cellfun("str2num", cellstr(split(OCTAVE_VERSION, "."))); -end_try_catch -assert(length(vers) >= 2); -if vers(1) < 3 || (vers(1) == 3 && vers(2) == 0) - disp("skipping 'clear all' test"); - return -endif - -clear all; - -##### BEGIN TEST ##### -# test help -example -help -assert(!isglobal("example")) - -# load module with custom cvar -example -globals mycvar -assert(!isglobal("cvar")) -assert(mycvar.ivar == example.ifunc()) -##### END TEST ##### - -clear all; - -##### BEGIN TEST ##### -# load module with root-level cvar -example -globals . -assert(example.ivar == example.ifunc()) -##### END TEST ##### diff --git a/Examples/octave/module_load/runme_gl_func.m b/Examples/octave/module_load/runme_gl_func.m deleted file mode 100644 index 1624cdd9a..000000000 --- a/Examples/octave/module_load/runme_gl_func.m +++ /dev/null @@ -1,59 +0,0 @@ -# file: runme_gl_func.m - -# test whether module can be loaded -# in a function (global cvar) - -1; - -##### BEGIN TEST ##### -function func - example - global cvar - assert(cvar.ivar == example.ifunc()) -endfunction - -# test that everything works from the base context -example -global cvar -assert(cvar.ivar == example.ifunc()) - -# test loading in a function -func - -# test a second time to check everything works -func -##### END TEST ##### - -# clearing a module results in a segfault for Octave <= 3.0.* -# (tested on Octave 3.0.5), so skip the following test -try - vers = cellfun("str2num", strsplit(OCTAVE_VERSION, ".")); -catch - vers = cellfun("str2num", cellstr(split(OCTAVE_VERSION, "."))); -end_try_catch -assert(length(vers) >= 2); -if vers(1) < 3 || (vers(1) == 3 && vers(2) == 0) - disp("skipping 'clear all' test"); - return -endif - -clear all; - -##### BEGIN TEST ##### -function func - example - global cvar - assert(cvar.ivar == example.ifunc()) -endfunction - -# test that everything works from the base context -example -global cvar -assert(cvar.ivar == example.ifunc()) - -# test loading in a function -func - -# test a second time to check everything works -func -##### END TEST ##### diff --git a/Examples/octave/module_load/runme_gl_func_base.m b/Examples/octave/module_load/runme_gl_func_base.m deleted file mode 100644 index 0e3eb6112..000000000 --- a/Examples/octave/module_load/runme_gl_func_base.m +++ /dev/null @@ -1,59 +0,0 @@ -# file: runme_gl_func_base.m - -# test whether module can be loaded in a function -# before the base context (global cvar) - -1; - -##### BEGIN TEST ##### -function func - example - global cvar - assert(cvar.ivar == example.ifunc()) -endfunction - -# test loading in a function -func - -# test a second time to check everything works -func - -# test that everything works from the base context -example -global cvar -assert(cvar.ivar == example.ifunc()) -##### END TEST ##### - -# clearing a module results in a segfault for Octave <= 3.0.* -# (tested on Octave 3.0.5), so skip the following test -try - vers = cellfun("str2num", strsplit(OCTAVE_VERSION, ".")); -catch - vers = cellfun("str2num", cellstr(split(OCTAVE_VERSION, "."))); -end_try_catch -assert(length(vers) >= 2); -if vers(1) < 3 || (vers(1) == 3 && vers(2) == 0) - disp("skipping 'clear all' test"); - return -endif - -clear all; - -##### BEGIN TEST ##### -function func - example - global cvar - assert(cvar.ivar == example.ifunc()) -endfunction - -# test loading in a function -func - -# test a second time to check everything works -func - -# test that everything works from the base context -example -global cvar -assert(cvar.ivar == example.ifunc()) -##### END TEST ##### diff --git a/Examples/octave/module_load/runme_nogl_func.m b/Examples/octave/module_load/runme_nogl_func.m deleted file mode 100644 index fd8e19f37..000000000 --- a/Examples/octave/module_load/runme_nogl_func.m +++ /dev/null @@ -1,55 +0,0 @@ -# file: runme_nogl_func.m - -# test whether module can be loaded -# in a function (no global cvar) - -1; - -##### BEGIN TEST ##### -function func - example -noglobal - assert(example.cvar.ivar == example.ifunc()) -endfunction - -# test that everything works from the base context -example -noglobal -assert(example.cvar.ivar == example.ifunc()) - -# test loading in a function -func - -# test a second time to check everything works -func -##### END TEST ##### - -# clearing a module results in a segfault for Octave <= 3.0.* -# (tested on Octave 3.0.5), so skip the following test -try - vers = cellfun("str2num", strsplit(OCTAVE_VERSION, ".")); -catch - vers = cellfun("str2num", cellstr(split(OCTAVE_VERSION, "."))); -end_try_catch -assert(length(vers) >= 2); -if vers(1) < 3 || (vers(1) == 3 && vers(2) == 0) - disp("skipping 'clear all' test"); - return -endif - -clear all; - -##### BEGIN TEST ##### -function func - example -noglobal - assert(example.cvar.ivar == example.ifunc()) -endfunction - -# test that everything works from the base context -example -noglobal -assert(example.cvar.ivar == example.ifunc()) - -# test loading in a function -func - -# test a second time to check everything works -func -##### END TEST ##### diff --git a/Examples/octave/module_load/runme_nogl_func_base.m b/Examples/octave/module_load/runme_nogl_func_base.m deleted file mode 100644 index bb8da9328..000000000 --- a/Examples/octave/module_load/runme_nogl_func_base.m +++ /dev/null @@ -1,55 +0,0 @@ -# file: runme_nogl_func_base.m - -# test whether module can be loaded in a function -# before the base context (no global cvar) - -1; - -##### BEGIN TEST ##### -function func - example -noglobal - assert(example.cvar.ivar == example.ifunc()) -endfunction - -# test loading in a function -func - -# test a second time to check everything works -func - -# test that everything works from the base context -example -noglobal -assert(example.cvar.ivar == example.ifunc()) -##### END TEST ##### - -# clearing a module results in a segfault for Octave <= 3.0.* -# (tested on Octave 3.0.5), so skip the following test -try - vers = cellfun("str2num", strsplit(OCTAVE_VERSION, ".")); -catch - vers = cellfun("str2num", cellstr(split(OCTAVE_VERSION, "."))); -end_try_catch -assert(length(vers) >= 2); -if vers(1) < 3 || (vers(1) == 3 && vers(2) == 0) - disp("skipping 'clear all' test"); - return -endif - -clear all; - -##### BEGIN TEST ##### -function func - example -noglobal - assert(example.cvar.ivar == example.ifunc()) -endfunction - -# test loading in a function -func - -# test a second time to check everything works -func - -# test that everything works from the base context -example -noglobal -assert(example.cvar.ivar == example.ifunc()) -##### END TEST ##### From 6329b81ab40d46dec201ac90edcd59eb85b109ac Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 14 May 2012 09:24:45 +0000 Subject: [PATCH 0090/1160] Updated Octave documentation on module load behaviour git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13090 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Octave.html | 88 ++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 3229299d5..b8cf02a77 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -63,7 +63,7 @@ The SWIG implemention was first based on Octave 2.9.12, so this is the minimum v

    -As of SWIG 2.0.5, the Octave module should work with Octave versions 3.0.5, 3.2.4, and 3.4.0. +As of SWIG 2.0.7, the Octave module has been tested with Octave versions 3.0.5, 3.2.4, 3.4.3, and 3.6.1.

    30.2 Running SWIG

    @@ -95,7 +95,7 @@ The -c++ option is also required when wrapping C++ code:
    $ swig -octave -c++ -o example_wrap.cpp example.i 

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

    30.2.1 Command-line options

    @@ -110,15 +110,12 @@ Options specific to the Octave module are:
    $ swig -octave -help
     ...
     Octave Options (available with -octave)
    -     -global       - Load all symbols into the global namespace [default]
          -globals name - Set name used to access C global variables [default: 'cvar']
    -                         - Use '.' to load C global variables into module namespace
    -     -noglobal     - Do not load all symbols into the global namespace
    +                     Use '.' to load C global variables into module namespace
          -opprefix str - Prefix str for global operator functions [default: 'op_']
     

    -The -global and -noglobal options determine whether the Octave module will load all symbols into the global namespace in addition to the global namespace. The -globals option sets the name of the variable which is the namespace for C global variables exported by the module. The special name "." loads C global variables into the module namespace, i.e. alongside C functions and structs exported by the module. The -opprefix options sets the prefix of the names of global/friend operator functions. @@ -138,7 +135,7 @@ $ mkoctfile example_wrap.cpp example.c

    - where example.c is the file containing the gcd() implementation. + where "example.c" is the file containing the gcd() implementation.

    @@ -146,7 +143,7 @@ $ mkoctfile example_wrap.cpp example.c

    - mkoctfile will produce example.oct, which contains the compiled extension module. Loading it into Octave is then a matter of invoking + mkoctfile will produce "example.oct", which contains the compiled extension module. Loading it into Octave is then a matter of invoking

    octave:1> example
    @@ -176,58 +173,67 @@ ans = 4

    -The SWIG module directive specifies the name of the Octave module. If you specify `module example', then in Octave everything in the module will be accessible under "example", as in the above example. When choosing a module name, make sure you don't use the same name as a built-in Octave command or standard module name. +The SWIG module directive specifies the name of the Octave module. If you specify "module example", then in Octave everything in the module will be accessible under "example", as in the above example. When choosing a module name, make sure you don't use the same name as a built-in Octave command or standard module name.

    -When Octave is asked to invoke example, it will try to find the .m or .oct file that defines the function "example". It will thusly find example.oct, that upon loading will register all of the module's symbols. +When Octave is asked to invoke example, it will try to find the ".m" or ".oct" file that defines the function "example". You therefore need to make sure that "example.oct" is in Octave's search path, which can be specified with the environment variable "OCTAVE_PATH".

    -An Octave module takes three options, -global, -noglobal, and -globals, which behave the same as the corresponding swig command-line options. -Here are some example usages: +An Octave module can either load its symbols into the global namespace, so that they can be accessed directly without having to type the module name. +Alternatively, an Octave module can be accessed through a local variable, without being loaded globally.

    -
    -octave:1> example -help
    -usage: example [-global|-noglobal] [-globals <name>]
    -octave:2> example -global
    -octave:3> gcd(4,6)
    +

    +To load an Octave module globally, simply type its name: +

    + +
    +octave:1> example;
    +octave:2> gcd(4,6)
     ans =  2
    -octave:4> cvar.Foo
    +octave:3> cvar.Foo
     ans =  3
    -octave:5> cvar.Foo=4;
    -octave:6> cvar.Foo
    +octave:4> cvar.Foo=4;
    +octave:5> cvar.Foo
     ans =  4
     
    -
    -
    -octave:1> example -noglobal
    -octave:2> gcd(6,9)
    +
    +

    +To access an Octave module through a local variable, without loading it globally, simply assign the module name (e.g. "example") to the desired local variable: +

    + +
    +octave:1> example = example;
    +octave:2> example.gcd(6,9)
     ans =  3
    -octave:3> cvar.Foo
    -error: `cvar' undefined near line 3 column 1
     octave:3> example.cvar.Foo
     ans =  3
     
    -
    -
    -octave:1> example -globals mycvar
    -octave:2> cvar.Foo
    -error: `cvar' undefined near line 2 column 1
    -octave:2> mycvar.Foo
    +
    +

    +The variable may have the same name as the module, or a shorter one: +

    + +
    +octave:1> ex = example;
    +octave:2> ex.gcd(6,9)
    +ans =  3
    +octave:3> ex.cvar.Foo
     ans =  3
     

    - It is also possible to rename the module / global variables namespaces with an assignment, as in:
    -

    -octave:1> example
    -octave:2> c=example;
    -octave:3> c.gcd(10,4)
    +It is also possible to rename the global variables namespaces with an assignment, as in:
    +

    + +
    +octave:1> example;
    +octave:2> cvar.gcd(10,4)
     ans =  2
    -octave:4> some_vars = cvar;
    -octave:5> some_vars.Foo
    +octave:3> some_vars = cvar;
    +octave:4> some_vars.Foo
     ans =  3
     
    @@ -274,9 +280,9 @@ int fact(int n);
    Global variables are a little special in Octave. Given a global variable:

    -
    %module example
    +
    %module example
     extern double Foo;
    -      
    +

    To expose variables, SWIG actually generates two functions, to get and set the value. In this case, Foo_set and Foo_set would be generated. SWIG then automatically calls these functions when you get and set the variable-- in the former case creating a local copy in the interpreter of the C variables, and in the latter case copying an interpreter variables onto the C variable. From 71cdda6a55e0bec77a87b77a6859aee136043f4d Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 14 May 2012 09:24:53 +0000 Subject: [PATCH 0091/1160] Documented recent Octave changes in CHANGELOG.current git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13091 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 96d6c6300..9e7824664 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,36 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.7 (in progress) =========================== +2012-05-14: kwwette (signed off by xavier98) + [Octave] Prevent Octave from seg-faulting at exit when SWIG + modules are loaded, due to bugs in Octave's cleanup code: + * Wrapping functions now declared with Octave DEFUN_DLD macro, + and loaded through Octave's dynamic module loader + * Global variables of swigref type are now assigned a new() + copy of the swigref class, to prevent double-free errors + * SWIG module at-exit cleanup function now created in Octave + through eval(), so not dependent on loaded .oct library + * For Octave versions 3.1.* to 3.3.*, register C-level at-exit + function which terminates Octave immediately (with correct + status code) without performing memory cleanup. This function + can be controlled with macros in Lib/octave/octruntime.swg + + [Octave] New syntax for determing whether SWIG module should be + loaded globally or non-globally. To load module "example" globally, + type the module name + $ example; + as before; to load module non-globally, assign it to a variable: + $ example = example; + or + $ ex = example; + for a shorter (local) module name. -global/-noglobal command-line + options and module command line are deprecated. Added usage info + to module, so typing + $ help example + or incorrect usage should display proper usage, with examples. + + *** POTENTIAL INCOMPATIBILITY *** + 2012-05-12: olly [PHP] Fix memory leak in code generated for a callback. Patch from SF bug #3510806. From 142f1e72bb1e2606d7afc11770f0d4dad98a7c9c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 15 May 2012 19:51:06 +0000 Subject: [PATCH 0092/1160] Fix some language's std::map wrappers to recognise difference_type, size_type, key_type and mapped_type. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13092 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Lib/csharp/std_map.i | 9 +++++---- Lib/guile/std_map.i | 4 ++++ Lib/mzscheme/std_map.i | 4 ++++ Lib/ocaml/std_map.i | 4 ++++ Lib/perl5/std_map.i | 4 ++++ Lib/php/std_map.i | 4 ++++ Lib/tcl/std_map.i | 4 ++++ 8 files changed, 33 insertions(+), 4 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 9e7824664..2092bd6e4 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.7 (in progress) =========================== +2012-05-14: wsfulton + Fix some language's std::map wrappers to recognise difference_type, size_type, key_type + and mapped_type. + 2012-05-14: kwwette (signed off by xavier98) [Octave] Prevent Octave from seg-faulting at exit when SWIG modules are loaded, due to bugs in Octave's cleanup code: diff --git a/Lib/csharp/std_map.i b/Lib/csharp/std_map.i index 0fd95725b..6a7da16b6 100644 --- a/Lib/csharp/std_map.i +++ b/Lib/csharp/std_map.i @@ -215,12 +215,13 @@ %} public: - map(); - map(const map< K, T > &other); - + typedef size_t size_type; + typedef ptrdiff_t difference_type; typedef K key_type; typedef T mapped_type; - typedef size_t size_type; + + map(); + map(const map< K, T > &other); size_type size() const; bool empty() const; %rename(Clear) clear; diff --git a/Lib/guile/std_map.i b/Lib/guile/std_map.i index 600075ebe..eb28c2831 100644 --- a/Lib/guile/std_map.i +++ b/Lib/guile/std_map.i @@ -217,6 +217,10 @@ namespace std { %rename("delete!") __delitem__; %rename("has-key?") has_key; public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef K key_type; + typedef T mapped_type; map(); map(const map &); diff --git a/Lib/mzscheme/std_map.i b/Lib/mzscheme/std_map.i index ffd76d213..849f8baf5 100644 --- a/Lib/mzscheme/std_map.i +++ b/Lib/mzscheme/std_map.i @@ -217,6 +217,10 @@ namespace std { %rename("delete!") __delitem__; %rename("has-key?") has_key; public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef K key_type; + typedef T mapped_type; map(); map(const map &); diff --git a/Lib/ocaml/std_map.i b/Lib/ocaml/std_map.i index 924120f24..5656b7fa2 100644 --- a/Lib/ocaml/std_map.i +++ b/Lib/ocaml/std_map.i @@ -22,6 +22,10 @@ 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 &); diff --git a/Lib/perl5/std_map.i b/Lib/perl5/std_map.i index 898c84484..e7812f38a 100644 --- a/Lib/perl5/std_map.i +++ b/Lib/perl5/std_map.i @@ -23,6 +23,10 @@ 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 &); diff --git a/Lib/php/std_map.i b/Lib/php/std_map.i index ff74b7b0b..6d5e3db13 100644 --- a/Lib/php/std_map.i +++ b/Lib/php/std_map.i @@ -23,6 +23,10 @@ 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 &); diff --git a/Lib/tcl/std_map.i b/Lib/tcl/std_map.i index e36cc96f2..1b7e7696c 100644 --- a/Lib/tcl/std_map.i +++ b/Lib/tcl/std_map.i @@ -24,6 +24,10 @@ 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 &); From 9e624db5bf464dd4b90f6eb0108af867da7ed5a1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 15 May 2012 19:51:41 +0000 Subject: [PATCH 0093/1160] Better display of parms when using -debug-module and -debug-top git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13093 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Swig/tree.c b/Source/Swig/tree.c index e66670c7c..265f5a12e 100644 --- a/Source/Swig/tree.c +++ b/Source/Swig/tree.c @@ -77,9 +77,9 @@ void Swig_print_node(Node *obj) { if ((Cmp(k, "nodeType") == 0) || (Cmp(k, "firstChild") == 0) || (Cmp(k, "lastChild") == 0) || (Cmp(k, "parentNode") == 0) || (Cmp(k, "nextSibling") == 0) || (Cmp(k, "previousSibling") == 0) || (*(Char(k)) == '$')) { /* Do nothing */ - } else if (Cmp(k, "parms") == 0) { + } else if (Cmp(k, "parms") == 0 || Cmp(k, "wrap:parms") == 0) { print_indent(2); - Printf(stdout, "%-12s - %s\n", k, ParmList_protostr(Getattr(obj, k))); + Printf(stdout, "%-12s - %s\n", k, ParmList_str_defaultargs(Getattr(obj, k))); } else { DOH *o; char *trunc = ""; From 95821b7a04f60ea70be6b997139f31dbaeee75f6 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 18 May 2012 02:19:46 +0000 Subject: [PATCH 0094/1160] Note that technique relying on call-time pass by reference won't work with PHP 5.4. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13094 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Php.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 659fb0a89..76031d07e 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -506,6 +506,12 @@ this, one needs to include phppointers.i which defines the named typemap REFERENCE.

    +

    +However, this relies on call-time pass-by-reference, which has been +deprecated in PHP for some time, and was finally removed in PHP 5.4. +So you should avoid creating new wrappers which rely on this approach. +

    +
     %module example
     %include "phppointers.i"
    
    From b32c70e244c1e4284f077017fcba186513991e40 Mon Sep 17 00:00:00 2001
    From: Olly Betts 
    Date: Fri, 18 May 2012 02:42:23 +0000
    Subject: [PATCH 0095/1160] Comment out use of call-time pass by reference,
     which has been deprecated for ages, and is no longer supported by PHP 5.4.
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13095 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Examples/test-suite/php/argout_runme.php | 15 ++++++++-------
     1 file changed, 8 insertions(+), 7 deletions(-)
    
    diff --git a/Examples/test-suite/php/argout_runme.php b/Examples/test-suite/php/argout_runme.php
    index 08524e214..33fbd8129 100644
    --- a/Examples/test-suite/php/argout_runme.php
    +++ b/Examples/test-suite/php/argout_runme.php
    @@ -23,15 +23,16 @@ check::equal(5,intp_value($tr),"5==$tr");
     
     # Check the voidhandle call, first with null
     unset($handle);
    -voidhandle($handle);
    -check::resource($handle,"_p_void",'$handle is not _p_void');
    -$handledata=handle($handle);
    -check::equal($handledata,"Here it is","\$handledata != \"Here it is\"");
    +# FIXME: Call-time pass-by-reference has been deprecated for ages, and was
    +# removed in PHP 5.4.  We need to rework 
    +#voidhandle(&$handle);
    +#check::resource($handle,"_p_void",'$handle is not _p_void');
    +#$handledata=handle($handle);
    +#check::equal($handledata,"Here it is","\$handledata != \"Here it is\"");
     
     unset($handle);
    -// without reference, should fatal error so can't test here
    -//voidhandle($handle);
    -//check::isnull($handle,'$handle not null');
    +voidhandle($handle);
    +check::isnull($handle,'$handle not null');
     
     check::done();
     ?>
    
    From de9d01dbcdc3128e74ad290093dbf57e6df31bd5 Mon Sep 17 00:00:00 2001
    From: Olly Betts 
    Date: Fri, 18 May 2012 02:43:52 +0000
    Subject: [PATCH 0096/1160] [PHP] Fix getters for template members.
     (SF#3428833)
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13096 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current                               |  3 ++
     Examples/test-suite/common.mk                 |  1 +
     .../test-suite/li_std_vector_member_var.i     | 23 +++++++++
     .../php/li_std_vector_member_var_runme.php    | 24 ++++++++++
     Source/Modules/php.cxx                        | 47 +++++++++++--------
     5 files changed, 78 insertions(+), 20 deletions(-)
     create mode 100644 Examples/test-suite/li_std_vector_member_var.i
     create mode 100644 Examples/test-suite/php/li_std_vector_member_var_runme.php
    
    diff --git a/CHANGES.current b/CHANGES.current
    index 2092bd6e4..dd5132efa 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
     Version 2.0.7 (in progress)
     ===========================
     
    +2012-05-18: olly
    +	    [PHP] Fix getters for template members. (SF#3428833)
    +
     2012-05-14: wsfulton
                 Fix some language's std::map wrappers to recognise difference_type, size_type, key_type
                 and mapped_type.
    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
    index 9e7e21ac4..73c0c4254 100644
    --- a/Examples/test-suite/common.mk
    +++ b/Examples/test-suite/common.mk
    @@ -475,6 +475,7 @@ CPP_STD_TEST_CASES += \
     	li_std_string \
     	li_std_vector \
     	li_std_vector_enum \
    +	li_std_vector_member_var\
     	naturalvar \
     	smart_pointer_inherit \
     	template_typedef_fnc \
    diff --git a/Examples/test-suite/li_std_vector_member_var.i b/Examples/test-suite/li_std_vector_member_var.i
    new file mode 100644
    index 000000000..b6e0727db
    --- /dev/null
    +++ b/Examples/test-suite/li_std_vector_member_var.i
    @@ -0,0 +1,23 @@
    +%module li_std_vector_member_var
    +
    +%include "std_vector.i"
    +
    +%template(vectorDbl) std::vector;
    +
    +%inline %{
    +#include 
    +
    +typedef std::vector DblVector;
    +
    +struct Test {
    +    DblVector v;
    +    int x;
    +
    +    Test() : x(0) { }
    +
    +    void f(int n) {
    +        x += n;
    +        v.push_back(1.0 / n);
    +    }
    +};
    +%}
    diff --git a/Examples/test-suite/php/li_std_vector_member_var_runme.php b/Examples/test-suite/php/li_std_vector_member_var_runme.php
    new file mode 100644
    index 000000000..96accf39f
    --- /dev/null
    +++ b/Examples/test-suite/php/li_std_vector_member_var_runme.php
    @@ -0,0 +1,24 @@
    +x, 0, "Test::x != 0");
    +check::equal($t->v->size(), 0, "Test::v.size() != 0");
    +
    +$t->f(1);
    +check::equal($t->x, 1, "Test::x != 1");
    +check::equal($t->v->size(), 1, "Test::v.size() != 1");
    +
    +$t->f(2);
    +check::equal($t->x, 3, "Test::x != 3");
    +check::equal($t->v->size(), 2, "Test::v.size() != 2");
    +
    +$t->f(3);
    +check::equal($t->x, 6, "Test::x != 6");
    +check::equal($t->v->size(), 3, "Test::v.size() != 3");
    +
    +check::done();
    +?>
    diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx
    index 1ac9e8b24..c5391a2e0 100644
    --- a/Source/Modules/php.cxx
    +++ b/Source/Modules/php.cxx
    @@ -1032,7 +1032,7 @@ public:
     	p += strlen(p) - 4;
     	String *varname = Getattr(n, "membervariableHandler:sym:name");
     	if (strcmp(p, "_get") == 0) {
    -	  Setattr(shadow_get_vars, varname, iname);
    +	  Setattr(shadow_get_vars, varname, Getattr(n, "type"));
     	} else if (strcmp(p, "_set") == 0) {
     	  Setattr(shadow_set_vars, varname, iname);
     	}
    @@ -2012,7 +2012,6 @@ done:
         classnode = 0;
     
         if (shadow) {
    -      DOH *key;
           List *baselist = Getattr(n, "bases");
           Iterator ki, base;
     
    @@ -2055,10 +2054,10 @@ done:
     	// FIXME: tune this threshold...
     	if (Len(shadow_set_vars) <= 2) {
     	  // Not many setters, so avoid call_user_func.
    -	  while (ki.key) {
    -	    key = ki.key;
    -	    Printf(s_phpclasses, "\t\tif ($var === '%s') return %s($this->%s,$value);\n", key, ki.item, SWIG_PTR);
    -	    ki = Next(ki);
    +	  for (; ki.key; ki = Next(ki)) {
    +	    DOH *key = ki.key;
    +	    String *iname = ki.item;
    +	    Printf(s_phpclasses, "\t\tif ($var === '%s') return %s($this->%s,$value);\n", key, iname, SWIG_PTR);
     	  }
     	} else {
     	  Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_set';\n", shadow_classname);
    @@ -2106,21 +2105,29 @@ done:
           if (ki.key) {
     	// This class has getters.
     	Printf(s_phpclasses, "\n\tfunction __get($var) {\n");
    -	// FIXME: Currently we always use call_user_func for __get, so we can
    -	// check and wrap the result.  This is needless if all the properties
    -	// are primitive types.  Also this doesn't handle all the cases which
    -	// a method returning an object does.
    -	Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_get';\n", shadow_classname);
    -	Printf(s_phpclasses, "\t\tif (function_exists($func)) {\n");
    -	Printf(s_phpclasses, "\t\t\t$r = call_user_func($func,$this->%s);\n", SWIG_PTR);
    -	Printf(s_phpclasses, "\t\t\tif (!is_resource($r)) return $r;\n");
    -	if (Len(prefix) == 0) {
    -	  Printf(s_phpclasses, "\t\t\t$c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n");
    -	} else {
    -	  Printf(s_phpclasses, "\t\t\t$c='%s'.substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n", prefix);
    +	int non_class_getters = 0;
    +	for (; ki.key; ki = Next(ki)) {
    +	  DOH *key = ki.key;
    +	  SwigType *d = ki.item;
    +	  if (!is_class(d)) {
    +	    ++non_class_getters;
    +	    continue;
    +	  }
    +	  Printv(s_phpclasses, "\t\tif ($var === '", key, "') return new ", prefix, Getattr(classLookup(d), "sym:name"), "(", shadow_classname, "_", key, "_get($this->", SWIG_PTR, "));\n", NIL);
    +	}
    +	// FIXME: tune this threshold...
    +	if (non_class_getters <= 2) {
    +	  // Not many non-class getters, so avoid call_user_func.
    +	  for (ki = First(shadow_get_vars); non_class_getters && ki.key; --non_class_getters, ki = Next(ki)) {
    +	    DOH *key = ki.key;
    +	    SwigType *d = ki.item;
    +	    if (is_class(d)) continue;
    +	    Printv(s_phpclasses, "\t\tif ($var === '", key, "') return ", shadow_classname, "_", key, "_get($this->", SWIG_PTR, ");\n", NIL);
    +	  }
    +	} else {
    +	  Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_get';\n", shadow_classname);
    +	  Printf(s_phpclasses, "\t\tif (function_exists($func)) return call_user_func($func,$this->%s);\n", SWIG_PTR);
     	}
    -	Printf(s_phpclasses, "\t\t\treturn new $c($r);\n");
    -	Printf(s_phpclasses, "\t\t}\n");
     	Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_get_newobject($this->%s);\n", module, SWIG_PTR);
     	if (baseclass) {
     	  Printf(s_phpclasses, "\t\treturn %s%s::__get($var);\n", prefix, baseclass);
    
    From b665377ad5ecc14b6e622f5bad787ed26f291921 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Mon, 21 May 2012 18:13:58 +0000
    Subject: [PATCH 0097/1160] Autoconf to check for a few more later versions of
     Python 3.x - can anyone think of a better way to do this?
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13097 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     configure.in | 6 +++---
     1 file changed, 3 insertions(+), 3 deletions(-)
    
    diff --git a/configure.in b/configure.in
    index 94fd61e08..c78ab16c8 100644
    --- a/configure.in
    +++ b/configure.in
    @@ -737,16 +737,16 @@ else
     # First figure out the name of the Python3 executable 
     
     if test "x$PY3BIN" = xyes; then
    -  AC_CHECK_PROGS(PYTHON3, [python3 python3.0 python3.1])
    +  AC_CHECK_PROGS(PYTHON3, [python3 python3.0 python3.1 python3.2 python3.3 python3.4 python3.5 python3.6])
     else
       PYTHON3="$PY3BIN"
     fi
     
     # Check for Python 3.x development tools (header files, static library and python3-config)
     if test "x$PYTHON3" = x; then
    -  AC_CHECK_PROGS(PY3CONFIG, [python3-config python3.0-config python3.1-config])
    +  AC_CHECK_PROGS(PY3CONFIG, [python3-config python3.0-config python3.1-config python3.2-config python3.3-config python3.4-config python3.5-config python3.6-config])
     else
    -  AC_CHECK_PROGS(PY3CONFIG, [$PYTHON3-config python3-config python3.0-config python3.1-config])
    +  AC_CHECK_PROGS(PY3CONFIG, [$PYTHON3-config python3-config python3.0-config python3.1-config python3.2-config python3.3-config python3.4-config python3.5-config python3.6-config])
     fi
     
     if test -n "$PYTHON3" -a -n "$PY3CONFIG"; then
    
    From 7196e556a58c6b8adfa13027b129309b3954e92c Mon Sep 17 00:00:00 2001
    From: Olly Betts 
    Date: Wed, 23 May 2012 02:58:24 +0000
    Subject: [PATCH 0098/1160] Fix SF#3528035, a regression introduced by the fix
     for SF#3428833.
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13105 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current                                       |  2 +-
     Examples/test-suite/li_std_vector_member_var.i        | 11 +++++++++++
     .../test-suite/php/li_std_vector_member_var_runme.php |  6 ++++++
     Source/Modules/php.cxx                                |  3 ++-
     4 files changed, 20 insertions(+), 2 deletions(-)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index dd5132efa..f1809e184 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -6,7 +6,7 @@ Version 2.0.7 (in progress)
     ===========================
     
     2012-05-18: olly
    -	    [PHP] Fix getters for template members. (SF#3428833)
    +	    [PHP] Fix getters for template members. (SF#3428833, SF#3528035)
     
     2012-05-14: wsfulton
                 Fix some language's std::map wrappers to recognise difference_type, size_type, key_type
    diff --git a/Examples/test-suite/li_std_vector_member_var.i b/Examples/test-suite/li_std_vector_member_var.i
    index b6e0727db..90de905c4 100644
    --- a/Examples/test-suite/li_std_vector_member_var.i
    +++ b/Examples/test-suite/li_std_vector_member_var.i
    @@ -20,4 +20,15 @@ struct Test {
             v.push_back(1.0 / n);
         }
     };
    +
    +// Regression test for SF#3528035:
    +struct S {
    +    int x;
    +    S() : x(4) { }
    +};
    +
    +struct T {
    +    S start_t;
    +    unsigned length;
    +};
     %}
    diff --git a/Examples/test-suite/php/li_std_vector_member_var_runme.php b/Examples/test-suite/php/li_std_vector_member_var_runme.php
    index 96accf39f..238350352 100644
    --- a/Examples/test-suite/php/li_std_vector_member_var_runme.php
    +++ b/Examples/test-suite/php/li_std_vector_member_var_runme.php
    @@ -20,5 +20,11 @@ $t->f(3);
     check::equal($t->x, 6, "Test::x != 6");
     check::equal($t->v->size(), 3, "Test::v.size() != 3");
     
    +$T = new T();
    +$T->start_t = new S();
    +$T->length = 7;
    +check::equal($T->start_t->x, 4, "S::x != 4");
    +check::equal($T->length, 7, "T::length != 7");
    +
     check::done();
     ?>
    diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx
    index c5391a2e0..70b6e41ef 100644
    --- a/Source/Modules/php.cxx
    +++ b/Source/Modules/php.cxx
    @@ -2118,11 +2118,12 @@ done:
     	// FIXME: tune this threshold...
     	if (non_class_getters <= 2) {
     	  // Not many non-class getters, so avoid call_user_func.
    -	  for (ki = First(shadow_get_vars); non_class_getters && ki.key; --non_class_getters, ki = Next(ki)) {
    +	  for (ki = First(shadow_get_vars); non_class_getters && ki.key;  ki = Next(ki)) {
     	    DOH *key = ki.key;
     	    SwigType *d = ki.item;
     	    if (is_class(d)) continue;
     	    Printv(s_phpclasses, "\t\tif ($var === '", key, "') return ", shadow_classname, "_", key, "_get($this->", SWIG_PTR, ");\n", NIL);
    +	    --non_class_getters;
     	  }
     	} else {
     	  Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_get';\n", shadow_classname);
    
    From 00328ccdb31a1e219c559a6f53e9bac598d5eaed Mon Sep 17 00:00:00 2001
    From: Stefan Zager 
    Date: Wed, 23 May 2012 04:05:11 +0000
    Subject: [PATCH 0099/1160] python: disambiguate SWIG_From_unsigned_SS_int and
     SWIG_From_unsigned_SS_long.
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13106 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current            |  2 ++
     Lib/python/pyprimtypes.swg | 10 ++++++++++
     2 files changed, 12 insertions(+)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index f1809e184..b94133ac6 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -4,6 +4,8 @@ See the RELEASENOTES file for a summary of changes in each release.
     
     Version 2.0.7 (in progress)
     ===========================
    +2012-05-22: szager
    +	    [python] Disambiguate SWIG_From_unsigned_SS_int and SWIG_From_unsigned_SS_long.
     
     2012-05-18: olly
     	    [PHP] Fix getters for template members. (SF#3428833, SF#3528035)
    diff --git a/Lib/python/pyprimtypes.swg b/Lib/python/pyprimtypes.swg
    index aa5ddaf62..290f9312f 100644
    --- a/Lib/python/pyprimtypes.swg
    +++ b/Lib/python/pyprimtypes.swg
    @@ -35,6 +35,16 @@ SWIGINTERNINLINE PyObject*
     }
     }
     
    +/* unsigned int */
    +
    +%fragment(SWIG_From_frag(unsigned int),"header") {
    +SWIGINTERNINLINE PyObject*
    +  SWIG_From_dec(unsigned int)(unsigned int value)
    +{
    +  return PyInt_FromSize_t((size_t) value);
    +}
    +}
    +
     /* long */
     
     %fragment(SWIG_From_frag(long),"header") {
    
    From f8135379a1ba43f2c63f3a4a768aeadbffeef3ee Mon Sep 17 00:00:00 2001
    From: Karl Wette 
    Date: Wed, 23 May 2012 09:32:38 +0000
    Subject: [PATCH 0100/1160] [octave] Make sure SWIG_global_name is a
     std::string for comparison
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13107 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Lib/octave/octruntime.swg | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg
    index e23068438..8c14bedfe 100644
    --- a/Lib/octave/octruntime.swg
    +++ b/Lib/octave/octruntime.swg
    @@ -198,7 +198,7 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) {
         SWIG_Octave_InstallFunction(me, "subclass");
     
         octave_swig_type* cvar_ns=0;
    -    if (SWIG_global_name != ".") {
    +    if (std::string(SWIG_global_name) != ".") {
           cvar_ns=new octave_swig_type;
           for (int j=0;swig_globals[j].name;++j)
             if (swig_globals[j].get_method)
    @@ -206,7 +206,7 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) {
         }
     
         module_ns=new octave_swig_type(0, 0, 0, true);
    -    if (SWIG_global_name != ".") {
    +    if (std::string(SWIG_global_name) != ".") {
           module_ns->assign(SWIG_global_name,Swig::swig_value_ref(cvar_ns));
         }
         else {
    
    From f76d63419f611c0b4526415f7883d6e5ec4df3b6 Mon Sep 17 00:00:00 2001
    From: Karl Wette 
    Date: Wed, 23 May 2012 09:32:51 +0000
    Subject: [PATCH 0101/1160] [octave] Declare these functions only if directors
     are used
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13108 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Lib/octave/octrun.swg | 2 ++
     1 file changed, 2 insertions(+)
    
    diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg
    index 24dae705a..dfb4a7702 100644
    --- a/Lib/octave/octrun.swg
    +++ b/Lib/octave/octrun.swg
    @@ -135,9 +135,11 @@ namespace Swig {
       SWIGRUNTIME octave_swig_type *swig_value_deref(const octave_base_value &ov);
     }
     
    +#ifdef SWIG_DIRECTORS
     SWIGRUNTIME void swig_acquire_ownership(void *vptr);
     SWIGRUNTIME void swig_acquire_ownership_array(void *vptr);
     SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
    +#endif
     
       struct swig_octave_member {
         const char *name;
    
    From 1d000ef6a6b4bf531a61df3f12d9a7f77e49604e Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Wed, 23 May 2012 19:09:18 +0000
    Subject: [PATCH 0102/1160] Cosmetic - reformat python3 detection code
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13109 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     configure.in | 113 +++++++++++++++++++++++++--------------------------
     1 file changed, 56 insertions(+), 57 deletions(-)
    
    diff --git a/configure.in b/configure.in
    index c78ab16c8..2524b9cb2 100644
    --- a/configure.in
    +++ b/configure.in
    @@ -626,17 +626,16 @@ AS_HELP_STRING([--with-python=path], [Set location of Python executable]),[ PYBI
     
     # First, check for "--without-python" or "--with-python=no".
     if test x"${PYBIN}" = xno -o x"${with_alllang}" = xno ; then 
    -AC_MSG_NOTICE([Disabling Python])
    +  AC_MSG_NOTICE([Disabling Python])
     else
    -# First figure out the name of the Python executable
    +  # First figure out the name of the Python executable
    +  if test "x$PYBIN" = xyes; then
    +    AC_CHECK_PROGS(PYTHON, [python python2.8 python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5 python1.4 python])
    +  else
    +    PYTHON="$PYBIN"
    +  fi
     
    -if test "x$PYBIN" = xyes; then
    -AC_CHECK_PROGS(PYTHON, [python python2.8 python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5 python1.4 python])
    -else
    -PYTHON="$PYBIN"
    -fi
    -
    -if test -n "$PYTHON"; then
    +  if test -n "$PYTHON"; then
         AC_MSG_CHECKING(for Python prefix)
         PYPREFIX=`($PYTHON -c "import sys; print sys.prefix") 2>/dev/null`
         AC_MSG_RESULT($PYPREFIX)
    @@ -669,12 +668,12 @@ if test -n "$PYTHON"; then
     
         AC_MSG_CHECKING(for Python header files)
         if test -r $PYPREFIX/include/$PYVERSION/Python.h; then
    -        PYINCLUDE="-I$PYPREFIX/include/$PYVERSION -I$PYEPREFIX/$PYLIBDIR/$PYVERSION/config"
    +      PYINCLUDE="-I$PYPREFIX/include/$PYVERSION -I$PYEPREFIX/$PYLIBDIR/$PYVERSION/config"
         fi
         if test -z "$PYINCLUDE"; then
    -        if test -r $PYPREFIX/include/Py/Python.h; then
    -            PYINCLUDE="-I$PYPREFIX/include/Py -I$PYEPREFIX/$PYLIBDIR/python/lib"
    -        fi
    +      if test -r $PYPREFIX/include/Py/Python.h; then
    +        PYINCLUDE="-I$PYPREFIX/include/Py -I$PYEPREFIX/$PYLIBDIR/python/lib"
    +      fi
         fi
         AC_MSG_RESULT($PYINCLUDE)
     
    @@ -682,32 +681,32 @@ if test -n "$PYTHON"; then
         AC_MSG_CHECKING(for Python library)
         dirs="$PYVERSION/config $PYVERSION/$PYLIBDIR python/$PYLIBDIR"
         for i in $dirs; do
    -        if test -d $PYEPREFIX/$PYLIBDIR/$i; then
    -           PYLIB="$PYEPREFIX/$PYLIBDIR/$i"
    -           break
    -        fi
    +      if test -d $PYEPREFIX/$PYLIBDIR/$i; then
    +        PYLIB="$PYEPREFIX/$PYLIBDIR/$i"
    +        break
    +      fi
         done
         if test -z "$PYLIB"; then
    -        AC_MSG_RESULT(Not found)
    +      AC_MSG_RESULT(Not found)
         else
    -        AC_MSG_RESULT($PYLIB)
    +      AC_MSG_RESULT($PYLIB)
         fi
     
         # Check for really old versions
         if test -r $PYLIB/libPython.a; then
    -         PYLINK="-lModules -lPython -lObjects -lParser"
    +      PYLINK="-lModules -lPython -lObjects -lParser"
         else
    -         PYLINK="-l$PYVERSION"
    +      PYLINK="-l$PYVERSION"
         fi
    -fi
    +  fi
     
    -# Cygwin (Windows) needs the library for dynamic linking
    -case $host in
    -*-*-cygwin* | *-*-mingw*) PYTHONDYNAMICLINKING="-L$PYLIB $PYLINK"
    -         DEFS="-DUSE_DL_IMPORT $DEFS" PYINCLUDE="$PYINCLUDE"
    -         ;;
    -*)PYTHONDYNAMICLINKING="";;
    -esac
    +  # Cygwin (Windows) needs the library for dynamic linking
    +  case $host in
    +  *-*-cygwin* | *-*-mingw*) PYTHONDYNAMICLINKING="-L$PYLIB $PYLINK"
    +    DEFS="-DUSE_DL_IMPORT $DEFS" PYINCLUDE="$PYINCLUDE"
    +    ;;
    +  *)PYTHONDYNAMICLINKING="";;
    +  esac
     fi
     
     AC_SUBST(PYINCLUDE)
    @@ -732,24 +731,24 @@ AS_HELP_STRING([--with-python3=path], [Set location of Python 3.x executable]),[
     
     # First, check for "--without-python3" or "--with-python3=no".
     if test x"${PY3BIN}" = xno -o x"${with_alllang}" = xno ; then 
    -AC_MSG_NOTICE([Disabling Python 3.x support])
    +  AC_MSG_NOTICE([Disabling Python 3.x support])
     else
    -# First figure out the name of the Python3 executable 
    +  # First figure out the name of the Python3 executable 
     
    -if test "x$PY3BIN" = xyes; then
    -  AC_CHECK_PROGS(PYTHON3, [python3 python3.0 python3.1 python3.2 python3.3 python3.4 python3.5 python3.6])
    -else
    -  PYTHON3="$PY3BIN"
    -fi
    +  if test "x$PY3BIN" = xyes; then
    +    AC_CHECK_PROGS(PYTHON3, [python3 python3.0 python3.1 python3.2 python3.3 python3.4 python3.5 python3.6])
    +  else
    +    PYTHON3="$PY3BIN"
    +  fi
     
    -# Check for Python 3.x development tools (header files, static library and python3-config)
    -if test "x$PYTHON3" = x; then
    -  AC_CHECK_PROGS(PY3CONFIG, [python3-config python3.0-config python3.1-config python3.2-config python3.3-config python3.4-config python3.5-config python3.6-config])
    -else
    -  AC_CHECK_PROGS(PY3CONFIG, [$PYTHON3-config python3-config python3.0-config python3.1-config python3.2-config python3.3-config python3.4-config python3.5-config python3.6-config])
    -fi
    +  # Check for Python 3.x development tools (header files, static library and python3-config)
    +  if test "x$PYTHON3" = x; then
    +    AC_CHECK_PROGS(PY3CONFIG, [python3-config python3.0-config python3.1-config python3.2-config python3.3-config python3.4-config python3.5-config python3.6-config])
    +  else
    +    AC_CHECK_PROGS(PY3CONFIG, [$PYTHON3-config python3-config python3.0-config python3.1-config python3.2-config python3.3-config python3.4-config python3.5-config python3.6-config])
    +  fi
     
    -if test -n "$PYTHON3" -a -n "$PY3CONFIG"; then
    +  if test -n "$PYTHON3" -a -n "$PY3CONFIG"; then
         AC_MSG_CHECKING([for Python 3.x prefix])
         PY3PREFIX=`($PY3CONFIG --prefix) 2>/dev/null`
         AC_MSG_RESULT($PY3PREFIX)
    @@ -787,27 +786,27 @@ if test -n "$PYTHON3" -a -n "$PY3CONFIG"; then
         AC_MSG_CHECKING([for Python 3.x library])
         dirs="$PY3VERSION/config $PY3VERSION/$PY3LIBDIR python/$PY3LIBDIR"
         for i in $dirs; do
    -        if test -d $PY3EPREFIX/$PY3LIBDIR/$i; then
    -           PY3LIB="$PY3EPREFIX/$PY3LIBDIR/$i"
    -           break
    -        fi
    +      if test -d $PY3EPREFIX/$PY3LIBDIR/$i; then
    +        PY3LIB="$PY3EPREFIX/$PY3LIBDIR/$i"
    +        break
    +      fi
         done
         if test -z "$PY3LIB"; then
    -        AC_MSG_RESULT([Not found])
    +      AC_MSG_RESULT([Not found])
         else
    -        AC_MSG_RESULT($PY3LIB)
    +      AC_MSG_RESULT($PY3LIB)
         fi
     
         PY3LINK="-l$PY3VERSION"
    -fi
    +  fi
     
    -# Cygwin (Windows) needs the library for dynamic linking
    -case $host in
    -*-*-cygwin* | *-*-mingw*) PYTHON3DYNAMICLINKING="-L$PYLIB $PY3LINK"
    -         DEFS="-DUSE_DL_IMPORT $DEFS" PY3INCLUDE="$PY3INCLUDE"
    -         ;;
    -*)PYTHON3DYNAMICLINKING="";;
    -esac
    +  # Cygwin (Windows) needs the library for dynamic linking
    +  case $host in
    +  *-*-cygwin* | *-*-mingw*) PYTHON3DYNAMICLINKING="-L$PYLIB $PY3LINK"
    +    DEFS="-DUSE_DL_IMPORT $DEFS" PY3INCLUDE="$PY3INCLUDE"
    +    ;;
    +  *)PYTHON3DYNAMICLINKING="";;
    +  esac
     fi
     
     AC_SUBST(PY3INCLUDE)
    
    From 6f8e77d7b05a0e6c4bddbcf1e7fddc242aada236 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Wed, 23 May 2012 19:10:44 +0000
    Subject: [PATCH 0103/1160] Better search for python3 based on code from Vadim
     Zeitlin
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13110 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     configure.in | 25 ++++++++++---------------
     1 file changed, 10 insertions(+), 15 deletions(-)
    
    diff --git a/configure.in b/configure.in
    index 2524b9cb2..eedc5b110 100644
    --- a/configure.in
    +++ b/configure.in
    @@ -630,7 +630,7 @@ if test x"${PYBIN}" = xno -o x"${with_alllang}" = xno ; then
     else
       # First figure out the name of the Python executable
       if test "x$PYBIN" = xyes; then
    -    AC_CHECK_PROGS(PYTHON, [python python2.8 python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5 python1.4 python])
    +    AC_CHECK_PROGS(PYTHON, [python python2.8 python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5 python1.4])
       else
         PYTHON="$PYBIN"
       fi
    @@ -733,20 +733,15 @@ AS_HELP_STRING([--with-python3=path], [Set location of Python 3.x executable]),[
     if test x"${PY3BIN}" = xno -o x"${with_alllang}" = xno ; then 
       AC_MSG_NOTICE([Disabling Python 3.x support])
     else
    -  # First figure out the name of the Python3 executable 
    -
    -  if test "x$PY3BIN" = xyes; then
    -    AC_CHECK_PROGS(PYTHON3, [python3 python3.0 python3.1 python3.2 python3.3 python3.4 python3.5 python3.6])
    -  else
    -    PYTHON3="$PY3BIN"
    -  fi
    -
    -  # Check for Python 3.x development tools (header files, static library and python3-config)
    -  if test "x$PYTHON3" = x; then
    -    AC_CHECK_PROGS(PY3CONFIG, [python3-config python3.0-config python3.1-config python3.2-config python3.3-config python3.4-config python3.5-config python3.6-config])
    -  else
    -    AC_CHECK_PROGS(PY3CONFIG, [$PYTHON3-config python3-config python3.0-config python3.1-config python3.2-config python3.3-config python3.4-config python3.5-config python3.6-config])
    -  fi
    +  for py_ver in 3 3.6 3.5 3.4 3.3 3.2 3.1 3.0; do
    +    AC_CHECK_PROGS(PYTHON3, [python$py_ver])
    +    if test -n "$PYTHON3"; then
    +      AC_CHECK_PROGS(PY3CONFIG, [$PYTHON3-config])
    +      if test -n "$PY3CONFIG"; then
    +        break
    +      fi
    +    fi
    +  done
     
       if test -n "$PYTHON3" -a -n "$PY3CONFIG"; then
         AC_MSG_CHECKING([for Python 3.x prefix])
    
    From 706736a73d5b282d67d4fa53b3197065b6ae3558 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Wed, 23 May 2012 20:24:21 +0000
    Subject: [PATCH 0104/1160] Fix some warning messages to correctly show class
     names.
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13111 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Source/Modules/lang.cxx | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx
    index c90ebeb73..9999fd3fe 100644
    --- a/Source/Modules/lang.cxx
    +++ b/Source/Modules/lang.cxx
    @@ -2623,7 +2623,7 @@ int Language::constructorDeclaration(Node *n) {
     	  Delete(expected_name_resolved);
     	}
     	if (illegal_name) {
    -	  Swig_warning(WARN_LANG_RETURN_TYPE, input_file, line_number, "Function %s must have a return type. Ignored.\n", SwigType_namestr(name));
    +	  Swig_warning(WARN_LANG_RETURN_TYPE, input_file, line_number, "Function %s must have a return type. Ignored.\n", Swig_name_decl(name));
     	  Swig_restore(n);
     	  return SWIG_NOWRAP;
     	}
    @@ -2760,7 +2760,7 @@ int Language::destructorDeclaration(Node *n) {
         }
     
         if (illegal_name) {
    -      Swig_warning(WARN_LANG_ILLEGAL_DESTRUCTOR, input_file, line_number, "Illegal destructor name %s. Ignored.\n", SwigType_namestr(name));
    +      Swig_warning(WARN_LANG_ILLEGAL_DESTRUCTOR, input_file, line_number, "Illegal destructor name %s. Ignored.\n", Swig_name_decl(name));
           Swig_restore(n);
           Delete(expected_name);
           return SWIG_NOWRAP;
    
    From 8de02343134700ebc055d3c355743504b7c743e8 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Thu, 24 May 2012 06:29:58 +0000
    Subject: [PATCH 0105/1160] Release notes for swig-2.0.7
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13112 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     RELEASENOTES | 5 +++++
     1 file changed, 5 insertions(+)
    
    diff --git a/RELEASENOTES b/RELEASENOTES
    index faa57bf63..a69631a85 100644
    --- a/RELEASENOTES
    +++ b/RELEASENOTES
    @@ -4,6 +4,11 @@ and CHANGES files.
     
     Release Notes
     =============
    +SWIG-2.0.7 summary:
    +- Important regression fixes since 2.0.5 for typemaps in general and
    +  in Python.
    +- Fixes and enhancements for Go, Java, Octave and PHP.
    +
     SWIG-2.0.6 summary:
     - Regression fix for Python STL wrappers on some systems.
     
    
    From 76a115ea41d1320e1243003cf119bdacc6c5425e Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Thu, 24 May 2012 18:42:32 +0000
    Subject: [PATCH 0106/1160] Test fix
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13114 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Examples/test-suite/typemap_template_parm_typedef.i | 5 ++++-
     1 file changed, 4 insertions(+), 1 deletion(-)
    
    diff --git a/Examples/test-suite/typemap_template_parm_typedef.i b/Examples/test-suite/typemap_template_parm_typedef.i
    index 6eab66c9c..95ec98d4a 100644
    --- a/Examples/test-suite/typemap_template_parm_typedef.i
    +++ b/Examples/test-suite/typemap_template_parm_typedef.i
    @@ -15,7 +15,10 @@
         typedef unsigned int uint;
         void test_no_typedef(std::list bada) {}
         void test_typedef(std::vector bada) {}
    -    std::deque no_typedef_out() {}
    +    std::deque no_typedef_out() {
    +      std::deque x;
    +      return x;
    +    }
       }
     %}
     
    
    From a276c0b45ab4afc113666b7e491a1e5be903e3ff Mon Sep 17 00:00:00 2001
    From: Karl Wette 
    Date: Thu, 24 May 2012 21:18:50 +0000
    Subject: [PATCH 0107/1160] [octave] skip part of module_load test for older
     Octaves
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13115 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Examples/octave/module_load/runme.m | 6 ++++++
     1 file changed, 6 insertions(+)
    
    diff --git a/Examples/octave/module_load/runme.m b/Examples/octave/module_load/runme.m
    index 4942a02de..16b437ee8 100644
    --- a/Examples/octave/module_load/runme.m
    +++ b/Examples/octave/module_load/runme.m
    @@ -89,6 +89,12 @@ testme
     testme
     clear all
     
    +# octave 3.0.5 randomly crashes on the remaining tests, so skip them
    +api_version = sscanf(octave_config_info("api_version"), "api-v%i");
    +if api_version < 37
    +  exit
    +endif
    +
     # access module with no cvar, no global load
     example2 = example2;
     assert(example2.ivar == example2.ifunc());
    
    From 522382c05e3bc90365ee7f5738af67f69b22f5cc Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Thu, 24 May 2012 22:20:22 +0000
    Subject: [PATCH 0108/1160] test fix
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13116 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Examples/test-suite/typemap_template_parm_typedef.i | 1 -
     1 file changed, 1 deletion(-)
    
    diff --git a/Examples/test-suite/typemap_template_parm_typedef.i b/Examples/test-suite/typemap_template_parm_typedef.i
    index 95ec98d4a..a27b9afea 100644
    --- a/Examples/test-suite/typemap_template_parm_typedef.i
    +++ b/Examples/test-suite/typemap_template_parm_typedef.i
    @@ -39,7 +39,6 @@
     
     // This typemap was not used for no_typedef_out in 2.0.4 and earlier
     %typemap(out) std::deque {
    -  $result = 0;
     }
     
     namespace jada {
    
    From 020e1373471e57e341cc70bd536da9c1d07c00b0 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Thu, 24 May 2012 22:37:57 +0000
    Subject: [PATCH 0109/1160] test fix again
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13117 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Examples/test-suite/typemap_template_parm_typedef.i | 6 ++++++
     1 file changed, 6 insertions(+)
    
    diff --git a/Examples/test-suite/typemap_template_parm_typedef.i b/Examples/test-suite/typemap_template_parm_typedef.i
    index a27b9afea..9718db2cd 100644
    --- a/Examples/test-suite/typemap_template_parm_typedef.i
    +++ b/Examples/test-suite/typemap_template_parm_typedef.i
    @@ -38,8 +38,14 @@
     }
     
     // This typemap was not used for no_typedef_out in 2.0.4 and earlier
    +#ifdef SWIGTCL
     %typemap(out) std::deque {
     }
    +#else
    +%typemap(out) std::deque {
    +  $result = 0;
    +}
    +#endif
     
     namespace jada {
       typedef unsigned int uint;
    
    From 184519b6a6e967c57563e8a8a8a9a09e8214785b Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Thu, 24 May 2012 23:01:28 +0000
    Subject: [PATCH 0110/1160] attempt to fix test again
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13118 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Examples/test-suite/typemap_template_parm_typedef.i | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/Examples/test-suite/typemap_template_parm_typedef.i b/Examples/test-suite/typemap_template_parm_typedef.i
    index 9718db2cd..3bec7aa49 100644
    --- a/Examples/test-suite/typemap_template_parm_typedef.i
    +++ b/Examples/test-suite/typemap_template_parm_typedef.i
    @@ -38,12 +38,12 @@
     }
     
     // This typemap was not used for no_typedef_out in 2.0.4 and earlier
    -#ifdef SWIGTCL
    +#if defined(SWIGJAVA) || defined(SWIGCSHARP)
     %typemap(out) std::deque {
    +  $result = 0;
     }
     #else
     %typemap(out) std::deque {
    -  $result = 0;
     }
     #endif
     
    
    From 49b6c39d98967c5bad997bf1490deab0161b18a5 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Thu, 24 May 2012 23:05:07 +0000
    Subject: [PATCH 0111/1160] Lua fix for -external-runtime
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13119 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current        |  3 +++
     Lib/lua/lua.swg        | 24 ------------------------
     Lib/lua/luarun.swg     | 29 +++++++++++++++++++++++++++++
     Source/Modules/lua.cxx | 21 +++++++++++++++------
     4 files changed, 47 insertions(+), 30 deletions(-)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index b94133ac6..acbd8b642 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -4,6 +4,9 @@ See the RELEASENOTES file for a summary of changes in each release.
     
     Version 2.0.7 (in progress)
     ===========================
    +2012-05-25: wsfulton
    +            [Lua] Fixes for -external-runtime to work again.
    +
     2012-05-22: szager
     	    [python] Disambiguate SWIG_From_unsigned_SS_int and SWIG_From_unsigned_SS_long.
     
    diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg
    index 1cd7201c2..39ea1fea7 100644
    --- a/Lib/lua/lua.swg
    +++ b/Lib/lua/lua.swg
    @@ -5,30 +5,6 @@
      * This file is parsed by SWIG before reading any other interface file.
      * ----------------------------------------------------------------------------- */
     
    -%insert("runtime") %{
    -/* Lua flavors */
    -#define SWIG_LUA_FLAVOR_LUA 1
    -#define SWIG_LUA_FLAVOR_ELUA 2
    -#define SWIG_LUA_FLAVOR_ELUAC 3
    -
    -#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
    -#  define SWIG_LUA_CONSTTAB_INT(B, C) LSTRKEY(B), LNUMVAL(C)
    -#  define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C)
    -#  define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C)
    -#  define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C)
    -# else /* SWIG_LUA_FLAVOR_LUA */
    -#  define SWIG_LUA_CONSTTAB_INT(B, C) SWIG_LUA_INT, (char *)B, (long)C, 0, 0, 0
    -#  define SWIG_LUA_CONSTTAB_FLOAT(B, C) SWIG_LUA_FLOAT, (char *)B, 0, (double)C, 0, 0
    -#  define SWIG_LUA_CONSTTAB_STRING(B, C) SWIG_LUA_STRING, (char *)B, 0, 0, (void *)C, 0
    -#  define SWIG_LUA_CONSTTAB_CHAR(B, C) SWIG_LUA_CHAR, (char *)B, (long)C, 0, 0, 0
    -#endif
    -
    -#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
    -#  define LRO_STRVAL(v) {{.p = (char *) v}, LUA_TSTRING}
    -#  define LSTRVAL LRO_STRVAL
    -#endif
    -%}
    -
     /* -----------------------------------------------------------------------------
      *                          includes
      * ----------------------------------------------------------------------------- */
    diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg
    index af3e7a3af..9b94e1efa 100644
    --- a/Lib/lua/luarun.swg
    +++ b/Lib/lua/luarun.swg
    @@ -15,6 +15,35 @@ extern "C" {
     #include   /* for malloc */
     #include   /* for a few sanity tests */
     
    +/* -----------------------------------------------------------------------------
    + * Lua flavors
    + * ----------------------------------------------------------------------------- */
    +
    +#define SWIG_LUA_FLAVOR_LUA 1
    +#define SWIG_LUA_FLAVOR_ELUA 2
    +#define SWIG_LUA_FLAVOR_ELUAC 3
    +
    +#if !defined(SWIG_LUA_TARGET)
    +# error SWIG_LUA_TARGET not defined
    +#endif
    +
    +#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
    +#  define SWIG_LUA_CONSTTAB_INT(B, C) LSTRKEY(B), LNUMVAL(C)
    +#  define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C)
    +#  define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C)
    +#  define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C)
    +#else /* SWIG_LUA_FLAVOR_LUA */
    +#  define SWIG_LUA_CONSTTAB_INT(B, C) SWIG_LUA_INT, (char *)B, (long)C, 0, 0, 0
    +#  define SWIG_LUA_CONSTTAB_FLOAT(B, C) SWIG_LUA_FLOAT, (char *)B, 0, (double)C, 0, 0
    +#  define SWIG_LUA_CONSTTAB_STRING(B, C) SWIG_LUA_STRING, (char *)B, 0, 0, (void *)C, 0
    +#  define SWIG_LUA_CONSTTAB_CHAR(B, C) SWIG_LUA_CHAR, (char *)B, (long)C, 0, 0, 0
    +#endif
    +
    +#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
    +#  define LRO_STRVAL(v) {{.p = (char *) v}, LUA_TSTRING}
    +#  define LSTRVAL LRO_STRVAL
    +#endif
    +
     /* -----------------------------------------------------------------------------
      * compatibility defines
      * ----------------------------------------------------------------------------- */
    diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx
    index ba121d28c..a6076a230 100644
    --- a/Source/Modules/lua.cxx
    +++ b/Source/Modules/lua.cxx
    @@ -284,12 +284,7 @@ public:
         Printf(f_runtime, "\n");
         Printf(f_runtime, "#define SWIGLUA\n");
     
    -    if (elua_ltr)
    -      Printf(f_runtime, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_ELUA\n");
    -    else if (eluac_ltr)
    -      Printf(f_runtime, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_ELUAC\n");
    -    else
    -      Printf(f_runtime, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_LUA\n");
    +    emitLuaFlavor(f_runtime);
     
         if (nomoduleglobal) {
           Printf(f_runtime, "#define SWIG_LUA_NO_MODULE_GLOBAL\n");
    @@ -1269,6 +1264,9 @@ public:
       String *runtimeCode() {
         String *s = NewString("");
         const char *filenames[] = { "luarun.swg", 0 } ; // must be 0 terminated
    +
    +    emitLuaFlavor(s);
    +
         String *sfile;
         for (int i = 0; filenames[i] != 0; i++) {
           sfile = Swig_include_sys(filenames[i]);
    @@ -1279,6 +1277,7 @@ public:
             Delete(sfile);
           }
         }
    +
         return s;
       }
     
    @@ -1290,6 +1289,16 @@ public:
        * helpers
        * --------------------------------------------------------------------- */
     
    +  void emitLuaFlavor(String *s) {
    +    if (elua_ltr)
    +      Printf(s, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_ELUA\n");
    +    else if (eluac_ltr)
    +      Printf(s, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_ELUAC\n");
    +    else
    +      Printf(s, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_LUA\n");
    +  }
    +  
    +
       /* This is to convert the string of Lua code into a proper string, which can then be
          emitted into the C/C++ code.
          Basically is is a lot of search & replacing of odd sequences
    
    From 12a9671440e9408a07d59a8936e75da096fea5fc Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Sat, 26 May 2012 06:33:49 +0000
    Subject: [PATCH 0112/1160] std::string typemap modifications so they can be
     used with %apply for other string classes
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13120 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current            |  4 ++++
     Lib/allegrocl/std_string.i | 10 +++++-----
     Lib/chicken/std_string.i   |  2 +-
     Lib/csharp/std_string.i    |  4 ++--
     Lib/d/std_string.i         |  4 ++--
     Lib/go/std_string.i        |  4 ++--
     Lib/guile/std_string.i     |  4 ++--
     Lib/java/std_string.i      | 12 ++++++------
     Lib/lua/std_string.i       |  4 ++--
     Lib/mzscheme/std_string.i  |  2 +-
     Lib/ocaml/std_string.i     | 10 +++++-----
     Lib/php/std_string.i       |  6 +++---
     Lib/pike/std_string.i      |  4 ++--
     13 files changed, 37 insertions(+), 33 deletions(-)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index acbd8b642..d6de00200 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -4,6 +4,10 @@ See the RELEASENOTES file for a summary of changes in each release.
     
     Version 2.0.7 (in progress)
     ===========================
    +2012-05-26: wsfulton
    +            std::string typemap modifications so they can be used with %apply for other string
    +            classes.
    +
     2012-05-25: wsfulton
                 [Lua] Fixes for -external-runtime to work again.
     
    diff --git a/Lib/allegrocl/std_string.i b/Lib/allegrocl/std_string.i
    index 372758dee..cbcd250a9 100644
    --- a/Lib/allegrocl/std_string.i
    +++ b/Lib/allegrocl/std_string.i
    @@ -121,7 +121,7 @@ namespace std {
     //             SWIG_exception(SWIG_TypeError, "string expected");
     //     }
     
    -//     %typemap(in) const string & (std::string temp) {
    +//     %typemap(in) const string & ($*1_ltype temp) {
     //         if (caml_ptr_check($input)) {
     //             temp.assign((char *)caml_ptr_val($input,0),
     // 			   caml_string_len($input));
    @@ -131,7 +131,7 @@ namespace std {
     //         }
     //     }
     
    -//     %typemap(in) string & (std::string temp) {
    +//     %typemap(in) string & ($*1_ltype temp) {
     //         if (caml_ptr_check($input)) {
     //             temp.assign((char *)caml_ptr_val($input,0),
     // 			   caml_string_len($input));
    @@ -141,9 +141,9 @@ namespace std {
     //         }
     //     }
     
    -//     %typemap(in) string * (std::string *temp) {
    +//     %typemap(in) string * ($*1_ltype *temp) {
     //         if (caml_ptr_check($input)) {
    -//             temp = new std::string((char *)caml_ptr_val($input,0),
    +//             temp = new $*1_ltype((char *)caml_ptr_val($input,0),
     // 				   caml_string_len($input));
     //             $1 = temp;
     //         } else {
    @@ -151,7 +151,7 @@ namespace std {
     //         }
     //     }
     
    -//     %typemap(free) string * (std::string *temp) {
    +//     %typemap(free) string * ($*1_ltype *temp) {
     // 	delete temp;
     //     }
     
    diff --git a/Lib/chicken/std_string.i b/Lib/chicken/std_string.i
    index 9907a58bc..fa77c1533 100644
    --- a/Lib/chicken/std_string.i
    +++ b/Lib/chicken/std_string.i
    @@ -44,7 +44,7 @@ namespace std {
           }
         }
     
    -    %typemap(in) const string& (std::string temp, char *tempptr) {
    +    %typemap(in) const string& ($*1_ltype temp, char *tempptr) {
     
           if ($input == C_SCHEME_FALSE) {
     	temp.resize(0);
    diff --git a/Lib/csharp/std_string.i b/Lib/csharp/std_string.i
    index 0d804518b..5f8fa44cb 100644
    --- a/Lib/csharp/std_string.i
    +++ b/Lib/csharp/std_string.i
    @@ -69,7 +69,7 @@ class string;
         SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
         return $null;
        }
    -   std::string $1_str($input);
    +   $*1_ltype $1_str($input);
        $1 = &$1_str; %}
     %typemap(out) const string & %{ $result = SWIG_csharp_string_callback($1->c_str()); %}
     
    @@ -85,7 +85,7 @@ class string;
         return $null;
        }
        /* possible thread/reentrant code problem */
    -   static std::string $1_str;
    +   static $*1_ltype $1_str;
        $1_str = $input;
        $result = &$1_str; %}
     
    diff --git a/Lib/d/std_string.i b/Lib/d/std_string.i
    index 7a4accf18..8d75d23e4 100644
    --- a/Lib/d/std_string.i
    +++ b/Lib/d/std_string.i
    @@ -36,7 +36,7 @@ class string;
         SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
         return $null;
        }
    -   std::string $1_str($input);
    +   $*1_ltype $1_str($input);
        $1 = &$1_str; %}
     
     %typemap(out) string %{ $result = SWIG_d_string_callback($1.c_str()); %}
    @@ -63,7 +63,7 @@ class string;
         return $null;
       }
       /* possible thread/reentrant code problem */
    -  static std::string $1_str;
    +  static $*1_ltype $1_str;
       $1_str = $input;
       $result = &$1_str; %}
     
    diff --git a/Lib/go/std_string.i b/Lib/go/std_string.i
    index e7c964263..9922fbe13 100644
    --- a/Lib/go/std_string.i
    +++ b/Lib/go/std_string.i
    @@ -35,13 +35,13 @@ class string;
     
     %typemap(in) const string &
     %{
    -  std::string $1_str($input.p, $input.n);
    +  $*1_ltype $1_str($input.p, $input.n);
       $1 = &$1_str;
     %}
     
     %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string &
     %{
    -  static std::string $1_str;
    +  static $*1_ltype $1_str;
       $1_str.assign($input.p, $input.n);
       $result = &$1_str;
     %}
    diff --git a/Lib/guile/std_string.i b/Lib/guile/std_string.i
    index 65ab6efbf..83e0dd26d 100644
    --- a/Lib/guile/std_string.i
    +++ b/Lib/guile/std_string.i
    @@ -36,7 +36,7 @@ namespace std {
             }
         }
     
    -    %typemap(in) const string & (std::string temp, char *tempptr) {
    +    %typemap(in) const string & ($*1_ltype temp, char *tempptr) {
             if (gh_string_p($input)) {
                 tempptr = SWIG_scm2str($input);
                 temp.assign(tempptr);
    @@ -50,7 +50,7 @@ namespace std {
         %typemap(in) string * (char *tempptr) {
             if (gh_string_p($input)) {
                 tempptr = SWIG_scm2str($input);
    -            $1 = new std::string(tempptr);
    +            $1 = new $*1_ltype(tempptr);
                 if (tempptr) SWIG_free(tempptr);
             } else {
                 SWIG_exception(SWIG_TypeError, "string expected");
    diff --git a/Lib/java/std_string.i b/Lib/java/std_string.i
    index f0d837696..f178e6d43 100644
    --- a/Lib/java/std_string.i
    +++ b/Lib/java/std_string.i
    @@ -28,7 +28,7 @@ class string;
     
     %typemap(in) string 
     %{ if(!$input) {
    -     SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
    +     SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string");
          return $null;
         } 
         const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0); 
    @@ -38,7 +38,7 @@ class string;
     
     %typemap(directorout) string 
     %{ if(!$input) {
    -     SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
    +     SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string");
          return $null;
        } 
        const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0); 
    @@ -73,24 +73,24 @@ class string;
     
     %typemap(in) const string &
     %{ if(!$input) {
    -     SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
    +     SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string");
          return $null;
        }
        const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0); 
        if (!$1_pstr) return $null;
    -   std::string $1_str($1_pstr);
    +   $*1_ltype $1_str($1_pstr);
        $1 = &$1_str;
        jenv->ReleaseStringUTFChars($input, $1_pstr); %}
     
     %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string &
     %{ if(!$input) {
    -     SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
    +     SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string");
          return $null;
        }
        const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0); 
        if (!$1_pstr) return $null;
        /* possible thread/reentrant code problem */
    -   static std::string $1_str;
    +   static $*1_ltype $1_str;
        $1_str = $1_pstr;
        $result = &$1_str;
        jenv->ReleaseStringUTFChars($input, $1_pstr); %}
    diff --git a/Lib/lua/std_string.i b/Lib/lua/std_string.i
    index 64c0957b1..b754eaf1c 100644
    --- a/Lib/lua/std_string.i
    +++ b/Lib/lua/std_string.i
    @@ -51,7 +51,7 @@ Not using: lua_tolstring() as this is only found in Lua 5.1 & not 5.0.2
     %typemap(out) std::string
     %{ lua_pushlstring(L,$1.data(),$1.size()); SWIG_arg++;%}
     
    -%typemap(in,checkfn="lua_isstring")	const std::string& (std::string temp)
    +%typemap(in,checkfn="lua_isstring")	const std::string& ($*1_ltype temp)
     %{temp.assign(lua_tostring(L,$input),lua_rawlen(L,$input)); $1=&temp;%}
     
     %typemap(out) const std::string&
    @@ -84,7 +84,7 @@ typemaps to tell SWIG what to do.
     */
     
     %typemap(in) std::string &INPUT=const std::string &;
    -%typemap(in, numinputs=0) std::string &OUTPUT (std::string temp)
    +%typemap(in, numinputs=0) std::string &OUTPUT ($*1_ltype temp)
     %{ $1 = &temp; %}
     %typemap(argout) std::string &OUTPUT
     %{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%}
    diff --git a/Lib/mzscheme/std_string.i b/Lib/mzscheme/std_string.i
    index b8b99d9ad..b19e8567a 100644
    --- a/Lib/mzscheme/std_string.i
    +++ b/Lib/mzscheme/std_string.i
    @@ -35,7 +35,7 @@ namespace std {
                 SWIG_exception(SWIG_TypeError, "string expected");
         }
     
    -    %typemap(in) const string & (std::string temp) {
    +    %typemap(in) const string & ($*1_ltype temp) {
             if (SCHEME_STRINGP($input)) {
                 temp.assign(SCHEME_STR_VAL($input));
                 $1 = &temp;
    diff --git a/Lib/ocaml/std_string.i b/Lib/ocaml/std_string.i
    index 5b6966dec..bd5be0da2 100644
    --- a/Lib/ocaml/std_string.i
    +++ b/Lib/ocaml/std_string.i
    @@ -36,7 +36,7 @@ class wstring;
         SWIG_exception(SWIG_TypeError, "string expected");
     }
     
    -%typemap(in) const string & (std::string temp) {
    +%typemap(in) const string & ($*1_ltype temp) {
       /* %typemap(in) const string & */
       if (caml_ptr_check($input)) {
         temp.assign((char *)caml_ptr_val($input,0), caml_string_len($input));
    @@ -46,7 +46,7 @@ class wstring;
       }
     }
     
    -%typemap(in) string & (std::string temp) {
    +%typemap(in) string & ($*1_ltype temp) {
       /* %typemap(in) string & */
       if (caml_ptr_check($input)) {
         temp.assign((char *)caml_ptr_val($input,0), caml_string_len($input));
    @@ -56,17 +56,17 @@ class wstring;
       }
     }
     
    -%typemap(in) string * (std::string *temp) {
    +%typemap(in) string * ($*1_ltype *temp) {
       /* %typemap(in) string * */
       if (caml_ptr_check($input)) {
    -    temp = new std::string((char *)caml_ptr_val($input,0), caml_string_len($input));
    +    temp = new $*1_ltype((char *)caml_ptr_val($input,0), caml_string_len($input));
         $1 = temp;
       } else {
         SWIG_exception(SWIG_TypeError, "string expected");
       }
     }
     
    -%typemap(free) string * (std::string *temp) {
    +%typemap(free) string * ($*1_ltype *temp) {
       delete temp;
     }
     
    diff --git a/Lib/php/std_string.i b/Lib/php/std_string.i
    index ff70bc83c..10d7fdd31 100644
    --- a/Lib/php/std_string.i
    +++ b/Lib/php/std_string.i
    @@ -56,15 +56,15 @@ namespace std {
     
         /* These next two handle a function which takes a non-const reference to
          * a std::string and modifies the string. */
    -    %typemap(in) string & (std::string temp) %{
    +    %typemap(in) string & ($*1_ltype temp) %{
             convert_to_string_ex($input);
             temp.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
             $1 = &temp;
         %}
     
    -    %typemap(directorout) string & (std::string *temp) %{
    +    %typemap(directorout) string & ($*1_ltype *temp) %{
             convert_to_string_ex($input);
    -        temp = new std::string(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
    +        temp = new $*1_ltype(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
             swig_acquire_ownership(temp);
             $result = temp;
         %}
    diff --git a/Lib/pike/std_string.i b/Lib/pike/std_string.i
    index c6fc48c8d..b32b3c112 100644
    --- a/Lib/pike/std_string.i
    +++ b/Lib/pike/std_string.i
    @@ -25,7 +25,7 @@ namespace std {
           $1.assign(STR0($input.u.string));
         }
     
    -    %typemap(in, pikedesc="tStr") const string & (std::string temp) {
    +    %typemap(in, pikedesc="tStr") const string & ($*1_ltype temp) {
           if ($input.type != T_STRING)
             Pike_error("Bad argument: Expected a string.\n");
           temp.assign(STR0($input.u.string));
    @@ -47,7 +47,7 @@ namespace std {
             throw Swig::DirectorTypeMismatchException("string expected");
         }
         
    -    %typemap(directorout) const string & (std::string temp) {
    +    %typemap(directorout) const string & ($*1_ltype temp) {
           if ($input.type == T_STRING) {
             temp.assign(STR0($input.u.string));
             $result = &temp;
    
    From e62dc28f16fb239dec341dcb34e2e199f7e4b816 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Sat, 26 May 2012 07:07:00 +0000
    Subject: [PATCH 0113/1160] Clean up Lua std::string typemaps
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13121 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Lib/lua/std_string.i | 103 ++++++++++++++++---------------------------
     1 file changed, 39 insertions(+), 64 deletions(-)
    
    diff --git a/Lib/lua/std_string.i b/Lib/lua/std_string.i
    index b754eaf1c..64f17dd88 100644
    --- a/Lib/lua/std_string.i
    +++ b/Lib/lua/std_string.i
    @@ -5,8 +5,9 @@
      * ----------------------------------------------------------------------------- */
     
     %{
    -	#include 
    +#include 
     %}
    +
     /*
     Only std::string and const std::string& are typemaped
     they are converted to the Lua strings automatically
    @@ -25,13 +26,14 @@ can be used as
     s="hello world"
     s2=test_value(s)
     assert(s==s2)
    -
     */
     
    -%naturalvar std::string;
    +namespace std {
    +
    +%naturalvar string;
     
     /*
    -Bug report #1526022 by neomantra
    +Bug report #1526022:
     Lua strings and std::string can contain embeded zero's
     Therefore a standard out typemap should not be:
       lua_pushstring(L,$1.c_str());
    @@ -46,26 +48,27 @@ becomes
     Not using: lua_tolstring() as this is only found in Lua 5.1 & not 5.0.2
     */
     
    -%typemap(in,checkfn="lua_isstring") std::string
    +%typemap(in,checkfn="lua_isstring") string
     %{$1.assign(lua_tostring(L,$input),lua_rawlen(L,$input));%}
    -%typemap(out) std::string
    +
    +%typemap(out) string
     %{ lua_pushlstring(L,$1.data(),$1.size()); SWIG_arg++;%}
     
    -%typemap(in,checkfn="lua_isstring")	const std::string& ($*1_ltype temp)
    +%typemap(in,checkfn="lua_isstring") const string& ($*1_ltype temp)
     %{temp.assign(lua_tostring(L,$input),lua_rawlen(L,$input)); $1=&temp;%}
     
    -%typemap(out) const std::string&
    +%typemap(out) const string&
     %{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%}
     
     // for throwing of any kind of string, string ref's and string pointers
     // we convert all to lua strings
    -%typemap(throws) std::string,std::string&,const std::string&
    +%typemap(throws) string, string&, const string&
     %{ lua_pushlstring(L,$1.data(),$1.size()); SWIG_fail;%}
    -%typemap(throws) std::string*,const std::string*
    +
    +%typemap(throws) string*, const string*
     %{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_fail;%}
     
    -// and the typechecks
    -%typecheck(SWIG_TYPECHECK_STRING) std::string,const std::string& {
    +%typecheck(SWIG_TYPECHECK_STRING) string, const string& {
       $1 = lua_isstring(L,$input);
     }
     
    @@ -77,46 +80,19 @@ void fn(std::string& str);
     Is this an in/out/inout value?
     
     Therefore you need the usual
    -%apply (std::string& INOUT) {(std::string& str)};
    +%apply (std::string& INOUT) {std::string& str};
     or
     %apply std::string& INOUT {std::string& str};
     typemaps to tell SWIG what to do.
     */
     
    -%typemap(in) std::string &INPUT=const std::string &;
    -%typemap(in, numinputs=0) std::string &OUTPUT ($*1_ltype temp)
    +%typemap(in) string &INPUT=const string &;
    +%typemap(in, numinputs=0) string &OUTPUT ($*1_ltype temp)
     %{ $1 = &temp; %}
    -%typemap(argout) std::string &OUTPUT
    +%typemap(argout) string &OUTPUT
     %{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%}
    -%typemap(in) std::string &INOUT =const std::string &;
    -%typemap(argout) std::string &INOUT = std::string &OUTPUT;
    -
    -/*
    -For const std::string* and std::string* is not clear
    -is this a pointer or an array?
    -
    -Therefore just leaving it as is
    -(there is some rough code below which could be used if needed
    -
    -// SWIG wraps const ref's as pointer
    -// typemaps to deal with this and const ptrs
    -%typemap(in,checkfn="lua_isstring")
    -	const std::string& INPUT(std::string temp),
    -	const std::string* INPUT(std::string temp)
    -%{temp=(char*)lua_tostring(L, $input); $1=&temp;%}
    -%typemap(out) const std::string&, const std::string*
    -%{  lua_pushstring(L,$1->c_str()); SWIG_arg++;%}
    -
    -// the non-const pointer version
    -%typemap(in) std::string *INPUT=const std::string *INPUT;
    -%typemap(in, numinputs=0) std::string *OUTPUT (std::string temp)
    -%{ $1 = &temp; %}
    -%typemap(argout) std::string *OUTPUT
    -%{  lua_pushstring(L,$1->c_str()); SWIG_arg++;%}
    -%typemap(in) std::string *INOUT = std::string *INPUT;
    -%typemap(argout) std::string *INOUT = std::string *OUTPUT;
    -
    -*/
    +%typemap(in) string &INOUT =const string &;
    +%typemap(argout) string &INOUT = string &OUTPUT;
     
     /*
     A really cut down version of the string class
    @@ -128,25 +104,24 @@ and little else
     note: no fn's taking the const string&
     as this is overloaded by the const char* version
     */
    -namespace std {
     
    -    class string {
    -      public:
    -        string();
    -        string(const char*);
    -        //string(const string&);
    -        unsigned int size() const;
    -        unsigned int length() const;
    -        bool empty() const;
    -        // no support for operator[]
    -        const char* c_str()const;
    -        const char* data()const;
    -        // assign does not return a copy of this object
    -        // (no point in a scripting language)
    -        void assign(const char*);
    -        //void assign(const string&);
    -        // no support for all the other features
    -        // its probably better to do it in lua
    -    };
    +  class string {
    +    public:
    +      string();
    +      string(const char*);
    +      //string(const string&);
    +      unsigned int size() const;
    +      unsigned int length() const;
    +      bool empty() const;
    +      // no support for operator[]
    +      const char* c_str()const;
    +      const char* data()const;
    +      // assign does not return a copy of this object
    +      // (no point in a scripting language)
    +      void assign(const char*);
    +      //void assign(const string&);
    +      // no support for all the other features
    +      // its probably better to do it in lua
    +  };
     }
     
    
    From 1b4e3280461115c2b59b8313969b9647f8d7874b Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Sat, 26 May 2012 07:09:54 +0000
    Subject: [PATCH 0114/1160] swig-2.0.7 release date
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13122 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     ANNOUNCE                 | 2 +-
     CHANGES.current          | 2 +-
     Doc/Manual/Sections.html | 2 +-
     README                   | 2 +-
     4 files changed, 4 insertions(+), 4 deletions(-)
    
    diff --git a/ANNOUNCE b/ANNOUNCE
    index 46c570cb1..a58858306 100644
    --- a/ANNOUNCE
    +++ b/ANNOUNCE
    @@ -1,4 +1,4 @@
    -*** ANNOUNCE: SWIG 2.0.7 (in progress) ***
    +*** ANNOUNCE: SWIG 2.0.7 (26 May 2012) ***
     
     http://www.swig.org
     
    diff --git a/CHANGES.current b/CHANGES.current
    index d6de00200..84afba381 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -2,7 +2,7 @@ Below are the changes for the current release.
     See the CHANGES file for changes in older releases.
     See the RELEASENOTES file for a summary of changes in each release.
     
    -Version 2.0.7 (in progress)
    +Version 2.0.7 (26 May 2012)
     ===========================
     2012-05-26: wsfulton
                 std::string typemap modifications so they can be used with %apply for other string
    diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html
    index 61c94544e..b891a903e 100644
    --- a/Doc/Manual/Sections.html
    +++ b/Doc/Manual/Sections.html
    @@ -6,7 +6,7 @@
     
     

    SWIG-2.0 Documentation

    -Last update : SWIG-2.0.7 (in progress) +Last update : SWIG-2.0.7 (26 May 2012)

    Sections

    diff --git a/README b/README index a683745ae..0ec8bdd11 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.7 (in progress) +Version: 2.0.7 (26 May 2012) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, Ocaml, Lua, From 3a55dd3df1021f1230868cfee5aee95627010985 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 26 May 2012 08:05:16 +0000 Subject: [PATCH 0115/1160] Bump version to 2.0.8 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13125 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- ANNOUNCE | 8 ++-- CHANGES | 91 ++++++++++++++++++++++++++++++++++++++++ CHANGES.current | 91 +--------------------------------------- Doc/Manual/Sections.html | 2 +- README | 2 +- configure.in | 2 +- 6 files changed, 99 insertions(+), 97 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index a58858306..32b6c4fe5 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,8 +1,8 @@ -*** ANNOUNCE: SWIG 2.0.7 (26 May 2012) *** +*** ANNOUNCE: SWIG 2.0.8 (in progress) *** http://www.swig.org -We're pleased to announce SWIG-2.0.7, the latest SWIG release. +We're pleased to announce SWIG-2.0.8, 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.7.tar.gz + http://prdownloads.sourceforge.net/swig/swig-2.0.8.tar.gz A Windows version is also available at - http://prdownloads.sourceforge.net/swig/swigwin-2.0.7.zip + http://prdownloads.sourceforge.net/swig/swigwin-2.0.8.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 625ed3d24..7afa119ad 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,97 @@ SWIG (Simplified Wrapper and Interface Generator) See the CHANGES.current file for changes in the current version. See the RELEASENOTES file for a summary of changes in each release. +Version 2.0.7 (26 May 2012) +=========================== +2012-05-26: wsfulton + std::string typemap modifications so they can be used with %apply for other string + classes. + +2012-05-25: wsfulton + [Lua] Fixes for -external-runtime to work again. + +2012-05-22: szager + [python] Disambiguate SWIG_From_unsigned_SS_int and SWIG_From_unsigned_SS_long. + +2012-05-18: olly + [PHP] Fix getters for template members. (SF#3428833, SF#3528035) + +2012-05-14: wsfulton + Fix some language's std::map wrappers to recognise difference_type, size_type, key_type + and mapped_type. + +2012-05-14: kwwette (signed off by xavier98) + [Octave] Prevent Octave from seg-faulting at exit when SWIG + modules are loaded, due to bugs in Octave's cleanup code: + * Wrapping functions now declared with Octave DEFUN_DLD macro, + and loaded through Octave's dynamic module loader + * Global variables of swigref type are now assigned a new() + copy of the swigref class, to prevent double-free errors + * SWIG module at-exit cleanup function now created in Octave + through eval(), so not dependent on loaded .oct library + * For Octave versions 3.1.* to 3.3.*, register C-level at-exit + function which terminates Octave immediately (with correct + status code) without performing memory cleanup. This function + can be controlled with macros in Lib/octave/octruntime.swg + + [Octave] New syntax for determing whether SWIG module should be + loaded globally or non-globally. To load module "example" globally, + type the module name + $ example; + as before; to load module non-globally, assign it to a variable: + $ example = example; + or + $ ex = example; + for a shorter (local) module name. -global/-noglobal command-line + options and module command line are deprecated. Added usage info + to module, so typing + $ help example + or incorrect usage should display proper usage, with examples. + + *** POTENTIAL INCOMPATIBILITY *** + +2012-05-12: olly + [PHP] Fix memory leak in code generated for a callback. Patch from + SF bug #3510806. + +2012-05-12: olly + [PHP] Avoid using zend_error_noreturn() as it doesn't work with all + builds of PHP (SF bug #3166423). Instead we now wrap it in a + SWIG_FAIL() function which we annotate as "noreturn" for GCC to + avoids warnings. This also reduces the size of the compiled + wrapper (e.g. the stripped size is reduced by 6% for Xapian's PHP + bindings). + +2012-05-11: wsfulton + [Java] SF patch #3522855 Fix unintended uninitialised memory access in OUTPUT typemaps. + +2012-05-11: wsfulton + [Java] SF patch #3522674 Fix possible uninitialised memory access in char **STRING_OUT + typemap. + +2012-05-11: wsfulton + [Java] SF patch #3522611 Fix uninitialised size regression in char **STRING_ARRAY + introduced in swig-2.0.6. + +2012-05-11: wsfulton + SF bug #3525050 - Fix regression introduced in swig-2.0.5 whereby defining one typemap + method such as an 'out' typemap may hide another typemap method such as an 'in' typemap - + only occurs when the type is a template type where the template parameters are the same + via a typedef. + +2012-05-10: olly + [PHP] Fix the constant typemaps for SWIGTYPE, etc - previously + these used the wrong name for renamed constants. Add + autodoc_runme.php to the testsuite as a regression test for this. + +2012-05-02: ianlancetaylor + [Go] Remove compatibility support for gccgo 4.6. Using + SWIG with gccgo will now require gccgo 4.7. Using SWIG + with the more commonly used gc compiler is unaffected. + +2012-05-01: wsfulton + Fix generated code for C forward enum declarations in some languages. + Version 2.0.6 (30 April 2012) ============================= diff --git a/CHANGES.current b/CHANGES.current index 84afba381..34b13439c 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,94 +2,5 @@ Below are the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.7 (26 May 2012) +Version 2.0.8 (in progress) =========================== -2012-05-26: wsfulton - std::string typemap modifications so they can be used with %apply for other string - classes. - -2012-05-25: wsfulton - [Lua] Fixes for -external-runtime to work again. - -2012-05-22: szager - [python] Disambiguate SWIG_From_unsigned_SS_int and SWIG_From_unsigned_SS_long. - -2012-05-18: olly - [PHP] Fix getters for template members. (SF#3428833, SF#3528035) - -2012-05-14: wsfulton - Fix some language's std::map wrappers to recognise difference_type, size_type, key_type - and mapped_type. - -2012-05-14: kwwette (signed off by xavier98) - [Octave] Prevent Octave from seg-faulting at exit when SWIG - modules are loaded, due to bugs in Octave's cleanup code: - * Wrapping functions now declared with Octave DEFUN_DLD macro, - and loaded through Octave's dynamic module loader - * Global variables of swigref type are now assigned a new() - copy of the swigref class, to prevent double-free errors - * SWIG module at-exit cleanup function now created in Octave - through eval(), so not dependent on loaded .oct library - * For Octave versions 3.1.* to 3.3.*, register C-level at-exit - function which terminates Octave immediately (with correct - status code) without performing memory cleanup. This function - can be controlled with macros in Lib/octave/octruntime.swg - - [Octave] New syntax for determing whether SWIG module should be - loaded globally or non-globally. To load module "example" globally, - type the module name - $ example; - as before; to load module non-globally, assign it to a variable: - $ example = example; - or - $ ex = example; - for a shorter (local) module name. -global/-noglobal command-line - options and module command line are deprecated. Added usage info - to module, so typing - $ help example - or incorrect usage should display proper usage, with examples. - - *** POTENTIAL INCOMPATIBILITY *** - -2012-05-12: olly - [PHP] Fix memory leak in code generated for a callback. Patch from - SF bug #3510806. - -2012-05-12: olly - [PHP] Avoid using zend_error_noreturn() as it doesn't work with all - builds of PHP (SF bug #3166423). Instead we now wrap it in a - SWIG_FAIL() function which we annotate as "noreturn" for GCC to - avoids warnings. This also reduces the size of the compiled - wrapper (e.g. the stripped size is reduced by 6% for Xapian's PHP - bindings). - -2012-05-11: wsfulton - [Java] SF patch #3522855 Fix unintended uninitialised memory access in OUTPUT typemaps. - -2012-05-11: wsfulton - [Java] SF patch #3522674 Fix possible uninitialised memory access in char **STRING_OUT - typemap. - -2012-05-11: wsfulton - [Java] SF patch #3522611 Fix uninitialised size regression in char **STRING_ARRAY - introduced in swig-2.0.6. - -2012-05-11: wsfulton - SF bug #3525050 - Fix regression introduced in swig-2.0.5 whereby defining one typemap - method such as an 'out' typemap may hide another typemap method such as an 'in' typemap - - only occurs when the type is a template type where the template parameters are the same - via a typedef. - -2012-05-10: olly - [PHP] Fix the constant typemaps for SWIGTYPE, etc - previously - these used the wrong name for renamed constants. Add - autodoc_runme.php to the testsuite as a regression test for this. - -2012-05-02: ianlancetaylor - [Go] Remove compatibility support for gccgo 4.6. Using - SWIG with gccgo will now require gccgo 4.7. Using SWIG - with the more commonly used gc compiler is unaffected. - -2012-05-01: wsfulton - Fix generated code for C forward enum declarations in some languages. - diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index b891a903e..0e78de84a 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

    SWIG-2.0 Documentation

    -Last update : SWIG-2.0.7 (26 May 2012) +Last update : SWIG-2.0.8 (in progress)

    Sections

    diff --git a/README b/README index 0ec8bdd11..154efc013 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.7 (26 May 2012) +Version: 2.0.8 (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/configure.in b/configure.in index eedc5b110..69685e0ed 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.7],[http://www.swig.org]) +AC_INIT([swig],[2.0.8],[http://www.swig.org]) dnl NB: When this requirement is increased to 2.60 or later, AC_PROG_SED dnl definition below can be removed From 290c43b9e5c3d5438831200d7b4a9fbf26de893f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 26 May 2012 08:14:37 +0000 Subject: [PATCH 0116/1160] Update list of languages git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13126 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- ANNOUNCE | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 32b6c4fe5..4fa6694f4 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -9,13 +9,13 @@ What is SWIG? SWIG is a software development tool that reads C/C++ header files and generates the wrapper code needed to make C and C++ code accessible -from other languages including Perl, Python, Tcl, Ruby, PHP, Java, -Scheme (Guile, MzScheme, CHICKEN), D, Ocaml, Lua, Pike, C#, Modula-3, -Octave, R, Common Lisp (CLISP, Allegro CL, CFFI, UFFI). SWIG can also -export its parse tree in the form of XML and Lisp s-expressions. Major -applications of SWIG include generation of scripting language extension -modules, rapid prototyping, testing, and user interface development for -large C/C++ systems. +from other programming languages including Perl, Python, Tcl, Ruby, +PHP, C#, Go, Java, Lua, Scheme (Guile, MzScheme, CHICKEN), D, Ocaml, +Pike, Modula-3, Octave, R, Common Lisp (CLISP, Allegro CL, CFFI, UFFI). +SWIG can also export its parse tree in the form of XML and Lisp +s-expressions. Major applications of SWIG include generation of +scripting language extension modules, rapid prototyping, testing, +and user interface development for large C/C++ systems. Availability ============ From eb5837b69775e169f69ddbc2d18810a119cdf88f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 26 May 2012 08:20:20 +0000 Subject: [PATCH 0117/1160] cosmetic wording in release script git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13127 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Tools/mkrelease.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/mkrelease.py b/Tools/mkrelease.py index af97a189f..9ca96bc6f 100755 --- a/Tools/mkrelease.py +++ b/Tools/mkrelease.py @@ -48,4 +48,4 @@ os.system("svn copy -m \"rel-" + version + "\" https://swig.svn.sourceforge.net/ print "Finished" -print "Now log in to SourceForge and set the operating system and link the release notes to each of the tarball and zip file in the File Manager." +print "Now log in to SourceForge and set the operating systems applicable to the newly uploaded tarball and zip file." From 55bda8f9f24262f323022584ae280a05caf5a337 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 28 May 2012 06:20:45 +0000 Subject: [PATCH 0118/1160] Fix seg fault attempting to warn about illegal destructors - introduced in rev 13111 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13128 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Examples/test-suite/errors/expected.log | 26 ++++++++++++------------- Source/Modules/lang.cxx | 4 ++-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 34b13439c..d71372167 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,3 +4,6 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.8 (in progress) =========================== +2012-05-28: wsfulton + Fix seg fault when attempting to warn about an illegal destructor - #3530055 and #3530118. + diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log index b7883c403..bcaf4efd8 100644 --- a/Examples/test-suite/errors/expected.log +++ b/Examples/test-suite/errors/expected.log @@ -227,17 +227,17 @@ cpp_extend_destructors.i:87: Warning 302: Identifier '~JStruct' redefined (ignor cpp_extend_destructors.i:85: Warning 302: previous definition of '~JStruct'. cpp_extend_destructors.i:100: Warning 302: Identifier '~LStruct' redefined (ignored), cpp_extend_destructors.i:98: Warning 302: previous definition of '~LStruct'. -cpp_extend_destructors.i:24: Warning 521: Illegal destructor name ~NOT_CStruct. Ignored. -cpp_extend_destructors.i:30: Warning 521: Illegal destructor name ~NOT_DStruct. Ignored. -cpp_extend_destructors.i:44: Warning 521: Illegal destructor name ~NOT_EStruct. Ignored. -cpp_extend_destructors.i:50: Warning 521: Illegal destructor name ~NOT_FStruct. Ignored. -cpp_extend_destructors.i:65: Warning 521: Illegal destructor name ~NOT_GStruct. Ignored. -cpp_extend_destructors.i:72: Warning 521: Illegal destructor name ~NOT_HStruct. Ignored. -cpp_extend_destructors.i:81: Warning 521: Illegal destructor name ~NOT_IStruct. Ignored. -cpp_extend_destructors.i:86: Warning 521: Illegal destructor name ~NOT_JStruct. Ignored. -cpp_extend_destructors.i:92: Warning 521: Illegal destructor name ~NOT_KStruct. Ignored. -cpp_extend_destructors.i:99: Warning 521: Illegal destructor name ~NOT_LStruct< int >. Ignored. -cpp_extend_destructors.i:99: Warning 521: Illegal destructor name ~NOT_LStruct< short >. Ignored. +cpp_extend_destructors.i:24: Warning 521: Illegal destructor name CStruct::~NOT_CStruct(). Ignored. +cpp_extend_destructors.i:30: Warning 521: Illegal destructor name DStruct::~NOT_DStruct(). Ignored. +cpp_extend_destructors.i:44: Warning 521: Illegal destructor name EStruct::~NOT_EStruct(). Ignored. +cpp_extend_destructors.i:50: Warning 521: Illegal destructor name FStruct::~NOT_FStruct(). Ignored. +cpp_extend_destructors.i:65: Warning 521: Illegal destructor name GStruct::~NOT_GStruct(). Ignored. +cpp_extend_destructors.i:72: Warning 521: Illegal destructor name HStruct::~NOT_HStruct(). Ignored. +cpp_extend_destructors.i:81: Warning 521: Illegal destructor name IStruct::~NOT_IStruct(). Ignored. +cpp_extend_destructors.i:86: Warning 521: Illegal destructor name JStruct::~NOT_JStruct(). Ignored. +cpp_extend_destructors.i:92: Warning 521: Illegal destructor name KStruct::~NOT_KStruct(). Ignored. +cpp_extend_destructors.i:99: Warning 521: Illegal destructor name LStruct< int >::~NOT_LStruct(). Ignored. +cpp_extend_destructors.i:99: Warning 521: Illegal destructor name LStruct< short >::~NOT_LStruct(). Ignored. :::::::::::::::::::::::::::::::: cpp_extend_redefine.i ::::::::::::::::::::::::::::::::::: cpp_extend_redefine.i:9: Warning 302: Identifier 'bar' redefined by %extend (ignored), @@ -312,8 +312,8 @@ cpp_nested.i:12: Warning 325: Nested class not currently supported (Grok ignored cpp_no_access.i:3: Warning 319: No access specifier given for base class 'foo' (ignored). :::::::::::::::::::::::::::::::: cpp_no_return_type.i ::::::::::::::::::::::::::::::::::: -cpp_no_return_type.i:6: Warning 504: Function R must have a return type. Ignored. -cpp_no_return_type.i:10: Warning 504: Function UU must have a return type. Ignored. +cpp_no_return_type.i:6: Warning 504: Function S::R() must have a return type. Ignored. +cpp_no_return_type.i:10: Warning 504: Function U::UU() must have a return type. Ignored. :::::::::::::::::::::::::::::::: cpp_nobase.i ::::::::::::::::::::::::::::::::::: cpp_nobase.i:3: Warning 401: Nothing known about base class 'Bar'. Ignored. diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 9999fd3fe..3c7b1f5a0 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2623,7 +2623,7 @@ int Language::constructorDeclaration(Node *n) { Delete(expected_name_resolved); } if (illegal_name) { - Swig_warning(WARN_LANG_RETURN_TYPE, input_file, line_number, "Function %s must have a return type. Ignored.\n", Swig_name_decl(name)); + Swig_warning(WARN_LANG_RETURN_TYPE, input_file, line_number, "Function %s must have a return type. Ignored.\n", Swig_name_decl(n)); Swig_restore(n); return SWIG_NOWRAP; } @@ -2760,7 +2760,7 @@ int Language::destructorDeclaration(Node *n) { } if (illegal_name) { - Swig_warning(WARN_LANG_ILLEGAL_DESTRUCTOR, input_file, line_number, "Illegal destructor name %s. Ignored.\n", Swig_name_decl(name)); + Swig_warning(WARN_LANG_ILLEGAL_DESTRUCTOR, input_file, line_number, "Illegal destructor name %s. Ignored.\n", Swig_name_decl(n)); Swig_restore(n); Delete(expected_name); return SWIG_NOWRAP; From 9a758998c98e2a69619dccf0f4a4a8123139bfab Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 28 May 2012 06:27:35 +0000 Subject: [PATCH 0119/1160] Add in another SF bug reference git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13129 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index d71372167..96f1d881d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,5 +5,5 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.8 (in progress) =========================== 2012-05-28: wsfulton - Fix seg fault when attempting to warn about an illegal destructor - #3530055 and #3530118. + Fix seg fault when attempting to warn about an illegal destructor - #3530055, 3530078 and #3530118. From 5b2f38101f83b01096ae1947fb499eac21dc8cca Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 28 May 2012 18:32:24 +0000 Subject: [PATCH 0120/1160] Fix comment typos in Lua typemaps git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13132 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/lua/_std_common.i | 6 +++--- Lib/lua/carrays.i | 2 +- Lib/lua/lua.swg | 6 +++--- Lib/lua/lua_fnptr.i | 10 +++++----- Lib/lua/luarun.swg | 12 ++++++------ Lib/lua/luatypemaps.swg | 16 ++++++++-------- Lib/lua/std_except.i | 4 ++-- Lib/lua/std_pair.i | 2 +- Lib/lua/std_string.i | 8 ++++---- Lib/lua/std_vector.i | 2 +- Lib/lua/typemaps.i | 16 ++++++++-------- 11 files changed, 42 insertions(+), 42 deletions(-) diff --git a/Lib/lua/_std_common.i b/Lib/lua/_std_common.i index e552d0c8f..567e68b7b 100644 --- a/Lib/lua/_std_common.i +++ b/Lib/lua/_std_common.i @@ -4,7 +4,7 @@ * std::helpers for LUA * ----------------------------------------------------------------------------- */ -%include // the general exepctions +%include // the general exceptions /* The basic idea here, is instead of trying to feed SWIG all the @@ -16,9 +16,9 @@ so the class declarations become just a set of %defines */ /* #define for basic container features -note: I allow front(), back() & pop_back() to throw execptions +note: I allow front(), back() & pop_back() to throw exceptions upon empty containers, rather than coredump -(as we have'nt defined the methods, we can use %extend to add with +(as we haven't defined the methods, we can use %extend to add with new features) */ diff --git a/Lib/lua/carrays.i b/Lib/lua/carrays.i index 9a210d243..1bc45d81f 100644 --- a/Lib/lua/carrays.i +++ b/Lib/lua/carrays.i @@ -1,5 +1,5 @@ /* Small change to the standard carrays.i -renaming the field to __getitem__ & __setitem__ +renaming the field to __getitem & __setitem for operator[] access */ %rename(__getitem) *::getitem; // the v=X[i] (get operator) diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg index 39ea1fea7..d3b335129 100644 --- a/Lib/lua/lua.swg +++ b/Lib/lua/lua.swg @@ -142,8 +142,8 @@ /* ------------------------------------------------------------ * Exceptions * ------------------------------------------------------------ */ -/* Confession: I dont really like C++ exceptions -The python/lua ones are great, but C++ ones I dont like +/* Confession: I don't really like C++ exceptions +The python/lua ones are great, but C++ ones I don't like (mainly because I cannot get the stack trace out of it) Therefore I have not bothered to try doing much in this @@ -191,7 +191,7 @@ There are a few options: - return a copy of it: but not all objects are copyable (see exception_partial_info in the test suite for a case where you cannot do this) - convert to a string & throw that - its not so useful, but it works (this is more lua like). + it's not so useful, but it works (this is more lua like). The third option (though not nice) is used For a more useful solution: see std_except for more details */ diff --git a/Lib/lua/lua_fnptr.i b/Lib/lua/lua_fnptr.i index 7e9facdf3..4e2c8dc6a 100644 --- a/Lib/lua/lua_fnptr.i +++ b/Lib/lua/lua_fnptr.i @@ -8,7 +8,7 @@ * Basic function pointer support * ----------------------------------------------------------------------------- */ /* -The structure: SWIGLUA_FN provides a simple (local only) wrappering for a function. +The structure: SWIGLUA_FN provides a simple (local only) wrapping for a function. For example if you wanted to have a C/C++ function take a lua function as a parameter. You could declare it as: @@ -29,7 +29,7 @@ just push the parameters, call the function and return the result. return luaL_checknumber(fn.L,-1); } -SWIG will automatically performs the wrappering of the arguments in and out. +SWIG will automatically performs the wrapping of the arguments in and out. However: if you wish to store the function between calls, look to the SWIGLUA_REF below. @@ -64,8 +64,8 @@ Then call it later, You could declare it as: note: it should be passed by value, not byref or as a pointer. The SWIGLUA_REF holds a pointer to the lua_State, and an integer reference to the object. -Because it holds a permenet ref to an object, the SWIGLUA_REF must be handled with a bit more care. -It should be initalised to {0,0}. The function swiglua_ref_set() should be used to set it. +Because it holds a permanent ref to an object, the SWIGLUA_REF must be handled with a bit more care. +It should be initialised to {0,0}. The function swiglua_ref_set() should be used to set it. swiglua_ref_clear() should be used to clear it when not in use, and swiglua_ref_get() to get the data back. @@ -82,7 +82,7 @@ if you need that you must add it yourself. return luaL_checknumber(fn.L,-1); } -SWIG will automatically performs the wrappering of the arguments in and out. +SWIG will automatically performs the wrapping of the arguments in and out. However: if you wish to store the function between calls, look to the SWIGLUA_REF below. diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 9b94e1efa..e4f39e07f 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -121,7 +121,7 @@ typedef struct swig_lua_class { const char **base_names; } swig_lua_class; -/* this is the struct for wrappering all pointers in SwigLua +/* this is the struct for wrapping all pointers in SwigLua */ typedef struct { swig_type_info *type; @@ -129,7 +129,7 @@ typedef struct { void *ptr; } swig_lua_userdata; -/* this is the struct for wrapping arbitary packed binary data +/* this is the struct for wrapping arbitrary packed binary data (currently it is only used for member function pointers) the data ordering is similar to swig_lua_userdata, but it is currently not possible to tell the two structures apart within SWIG, other than by looking at the type @@ -213,7 +213,7 @@ SWIG_Lua_SetModule(lua_State* L, swig_module_info *module) { * ----------------------------------------------------------------------------- */ /* this function is called when trying to set an immutable. -default value is to print an error. +default action is to print an error. This can removed with a compile flag SWIGLUA_IGNORE_SET_IMMUTABLE */ SWIGINTERN int SWIG_Lua_set_immutable(lua_State* L) { @@ -634,7 +634,7 @@ SWIGINTERN void SWIG_Lua_init_base_class(lua_State* L,swig_lua_class* clss) swig_type_info *info = SWIG_TypeQueryModule(module,module,clss->base_names[i]); if (info) clss->bases[i] = (swig_lua_class *) info->clientdata; } - } + } } /* performs the entire class registration process */ @@ -882,8 +882,8 @@ SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]) { #ifndef SWIG_DOSTRING_FAIL /* Allows redefining of error function */ #define SWIG_DOSTRING_FAIL(S) fprintf(stderr,"%s\n",S) #endif -/* Executes a C string in Lua a really simple way of calling lua from C -Unfortunately lua keeps changing its API's, so we need a conditional compile +/* Executes a C string in Lua which is a really simple way of calling lua from C +Unfortunately lua keeps changing its APIs, so we need a conditional compile In lua 5.0.X its lua_dostring() In lua 5.1.X its luaL_dostring() */ diff --git a/Lib/lua/luatypemaps.swg b/Lib/lua/luatypemaps.swg index f3ea6f14c..f6791a224 100644 --- a/Lib/lua/luatypemaps.swg +++ b/Lib/lua/luatypemaps.swg @@ -13,7 +13,7 @@ the fn call must be of the form int checkfn(lua_State *L, int index); and return 1/0 depending upon if this is the correct type - For the typemap(out), an additional SWIG_arg parmeter must be incremented + For the typemap(out), an additional SWIG_arg parameter must be incremented to reflect the number of values returned (normally SWIG_arg++; will do) */ // numbers @@ -33,7 +33,7 @@ $1 = ($type)lua_tonumber(L, $input);%} float,double %{ lua_pushnumber(L, (lua_Number) $1); SWIG_arg++;%} -// we must also provide typemaps for privitives by const reference: +// we must also provide typemaps for primitives by const reference: // given a function: // int intbyref(const int& i); // SWIG assumes that this code will need a pointer to int to be passed in @@ -132,7 +132,7 @@ SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) { // it should be converted to a SWIG NULL. // This will only be allowed for pointers & arrays, not refs or by value // the checkfn lua_isuserdata will only work for userdata -// the checkfn SWIG_isptrtype will work for both userdata and nil's +// the checkfn SWIG_isptrtype will work for both userdata and nil %typemap(in,checkfn="SWIG_isptrtype") SWIGTYPE*,SWIGTYPE[] %{ if (!SWIG_IsOK(SWIG_ConvertPtr(L,$input,(void**)&$1,$descriptor,$disown))){ @@ -219,9 +219,9 @@ $1=($1_ltype)&temp;%} // member function pointer // a member fn ptr is not 4 bytes like a normal pointer, but 8 bytes (at least on mingw) -// so the standard wrappering cannot be done +// so the standard wrapping cannot be done // nor can you cast a member function pointer to a void* (obviously) -// therefore a special wrappering functions SWIG_ConvertMember() & SWIG_NewMemberObj() were written +// therefore a special wrapping functions SWIG_ConvertMember() & SWIG_NewMemberObj() were written #ifdef __cplusplus %typemap(in,checkfn="lua_isuserdata") SWIGTYPE (CLASS::*) %{ @@ -241,7 +241,7 @@ $1=($1_ltype)&temp;%} /* void* is a special case A function void fn(void*) should take any kind of pointer as a parameter (just like C/C++ does) -but if its an output, then it should be wrappered like any other SWIG object (using default typemap) +but if its an output, then it should be wrapped like any other SWIG object (using default typemap) */ %typemap(in,checkfn="SWIG_isptrtype") void* %{$1=($1_ltype)SWIG_MustGetPtr(L,$input,0,0,$argnum,"$symname");%} @@ -269,7 +269,7 @@ void fn(int a, float b, lua_State* s) is wrappable as * ----------------------------------------------------------------------------- */ /* These are needed for the overloaded functions These define the detection routines which will spot what -parmeters match which function +parameters match which function */ // unfortunately lua only considers one type of number @@ -341,7 +341,7 @@ parmeters match which function } } -// Also needed for object ptrs by const ref +// Also needed for object pointers by const ref // eg const A* ref_pointer(A* const& a); // found in mixed_types.i %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const& diff --git a/Lib/lua/std_except.i b/Lib/lua/std_except.i index 9c736b9ef..160828723 100644 --- a/Lib/lua/std_except.i +++ b/Lib/lua/std_except.i @@ -24,8 +24,8 @@ namespace std }; } -// normally object which are thrown are returned to interpreter as errors -// (which potentally may have problems if they are not copied) +// normally objects which are thrown are returned to the interpreter as errors +// (which potentially may have problems if they are not copied) // therefore all classes based upon std::exception are converted to their strings & returned as errors %typemap(throws) std::bad_exception "SWIG_exception(SWIG_RuntimeError, $1.what());" %typemap(throws) std::domain_error "SWIG_exception(SWIG_ValueError, $1.what());" diff --git a/Lib/lua/std_pair.i b/Lib/lua/std_pair.i index c76361554..06728533b 100644 --- a/Lib/lua/std_pair.i +++ b/Lib/lua/std_pair.i @@ -10,7 +10,7 @@ /* A really cut down version of the pair class. -this is not useful on its owns is it needs a %template definition with it +this is not useful on its own - it needs a %template definition with it eg. namespace std { diff --git a/Lib/lua/std_string.i b/Lib/lua/std_string.i index 64f17dd88..e9f326b52 100644 --- a/Lib/lua/std_string.i +++ b/Lib/lua/std_string.i @@ -9,7 +9,7 @@ %} /* -Only std::string and const std::string& are typemaped +Only std::string and const std::string& are typemapped they are converted to the Lua strings automatically std::string& and std::string* are not @@ -34,7 +34,7 @@ namespace std { /* Bug report #1526022: -Lua strings and std::string can contain embeded zero's +Lua strings and std::string can contain embedded zero bytes Therefore a standard out typemap should not be: lua_pushstring(L,$1.c_str()); but @@ -73,7 +73,7 @@ Not using: lua_tolstring() as this is only found in Lua 5.1 & not 5.0.2 } /* -std::string& can be wrappered, but you must inform SWIG if it is in or out +std::string& can be wrapped, but you must inform SWIG if it is in or out eg: void fn(std::string& str); @@ -121,7 +121,7 @@ as this is overloaded by the const char* version void assign(const char*); //void assign(const string&); // no support for all the other features - // its probably better to do it in lua + // it's probably better to do it in lua }; } diff --git a/Lib/lua/std_vector.i b/Lib/lua/std_vector.i index f248f0340..a4ea978db 100644 --- a/Lib/lua/std_vector.i +++ b/Lib/lua/std_vector.i @@ -7,7 +7,7 @@ %{ #include %} -%include // the general exepctions +%include // the general exceptions /* A really cut down version of the vector class. diff --git a/Lib/lua/typemaps.i b/Lib/lua/typemaps.i index 63cb49a0d..a7ecec528 100644 --- a/Lib/lua/typemaps.i +++ b/Lib/lua/typemaps.i @@ -140,21 +140,21 @@ a few things of note: so for the above mentioned return_array_5() would look like arr=return_array_5() -- no parameters passed in * for INOUT arrays, a table must be passed in, and a new table will be returned - (this is consistant with the way that numbers are processed) + (this is consistent with the way that numbers are processed) if you want just use arr={...} arr=process_var_array_inout(arr) -- arr is replaced by the new version The following are not yet supported: -* variable length output only array (inout's work ok) -* multidimentional arrays +* variable length output only array (inout works ok) +* multidimensional arrays * arrays of objects/structs * arrays of pointers */ /* -The internals of the array managment stuff +The internals of the array management stuff helper fns/macros SWIG_ALLOC_ARRAY(TYPE,LEN) // returns a typed array TYPE[LEN] SWIG_FREE_ARRAY(PTR) // delete the ptr (if not zero) @@ -367,7 +367,7 @@ SWIG_TYPEMAP_NUM_ARR(double,double); %typemap(freearg) enum SWIGTYPE INPUT[ANY] %{ SWIG_FREE_ARRAY($1);%} -// variable size array's +// variable size arrays %typemap(in) (enum SWIGTYPE *INPUT,int) %{ $1 = ($ltype)SWIG_get_int_num_array_var(L,$input,&$2); if (!$1) SWIG_fail;%} @@ -414,7 +414,7 @@ void** SWIG_get_ptr_array_var(lua_State* L, int index, int* size,swig_type_info // all pointers have the ownership value 'own' (normally 0) void SWIG_write_ptr_array(lua_State* L,void **array,int size,int own); // read the specified table, and fills the array with ptrs - // returns 1 of ok (only fails if it doesnt find correct type of ptrs) + // returns 1 of ok (only fails if it doesn't find correct type of ptrs) // helper fn (called by SWIG_get_ptr_array_*() fns) int SWIG_read_ptr_array(lua_State* L,int index,void **array,int size,swig_type_info *type); @@ -424,7 +424,7 @@ modification of pointers ownership in the arrays eg A fn: void pointers_in(TYPE* arr[],int len); will make copies of the pointer into a temp array and then pass it into the fn -Lua does not remeber that this fn held the pointers, so it is not safe to keep +Lua does not remember that this fn held the pointers, so it is not safe to keep these pointers until later eg A fn: @@ -551,7 +551,7 @@ free(ptr); With the following SWIG code %apply SWIGTYPE** OUTPUT{iMath **pptr }; -You can get natural wrappering in Lua as follows: +You can get natural wrapping in Lua as follows: ok,ptr=Create_Math() -- ptr is a iMath* which is returned with the int ptr=nil -- the iMath* will be GC'ed as normal */ From 7ec1e11604abfe0bdf444a8fbda75b4eed72de45 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 29 May 2012 22:02:43 +0000 Subject: [PATCH 0121/1160] Fix bug 3529601 - seg fault when a protected method has the director feature but the parent class does not. Also fix similar problems with the allprotected feature. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13135 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 +++++ Examples/test-suite/allprotected_not.i | 27 +++++++++++++++++++++++ Examples/test-suite/common.mk | 1 + Source/Modules/go.cxx | 2 +- Source/Modules/lang.cxx | 30 +++++++++++++++++--------- Source/Modules/swigmod.h | 4 ++++ 6 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 Examples/test-suite/allprotected_not.i diff --git a/CHANGES.current b/CHANGES.current index 96f1d881d..8458e45e0 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.8 (in progress) =========================== +2012-05-29: wsfulton + Fix #3529601 - seg fault when a protected method has the "director" + feature but the parent class does not. Also fix similar problems with + the allprotected feature. + 2012-05-28: wsfulton Fix seg fault when attempting to warn about an illegal destructor - #3530055, 3530078 and #3530118. diff --git a/Examples/test-suite/allprotected_not.i b/Examples/test-suite/allprotected_not.i new file mode 100644 index 000000000..61ed78954 --- /dev/null +++ b/Examples/test-suite/allprotected_not.i @@ -0,0 +1,27 @@ +// Tests directors and allprotected option when the class does not have the "director" feature +// Was previously crashing and/or generating uncompilable code. + +%module(directors="1", allprotected="1") allprotected_not + +//%feature("director") AllProtectedNot; +%feature("director") AllProtectedNot::ProtectedMethod; +%feature("director") AllProtectedNot::StaticNonVirtualProtectedMethod; +%feature("director") AllProtectedNot::NonVirtualProtectedMethod; +%feature("director") AllProtectedNot::ProtectedVariable; +%feature("director") AllProtectedNot::StaticProtectedVariable; +%feature("director") AllProtectedNot::PublicMethod; + +%inline %{ +class AllProtectedNot { +public: + virtual ~AllProtectedNot() {} + virtual void PublicMethod() {} +protected: + virtual void ProtectedMethod() {} + static void StaticNonVirtualProtectedMethod() {} + void NonVirtualProtectedMethod() {} + int ProtectedVariable; + static int StaticProtectedVariable; +}; +int AllProtectedNot::StaticProtectedVariable = 0; +%} diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 73c0c4254..5660ec99e 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -108,6 +108,7 @@ CPP_TEST_CASES += \ aggregate \ allowexcept \ allprotected \ + allprotected_not \ anonymous_bitfield \ apply_signed_char \ apply_strings \ diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index e7a21d1bd..9966efb64 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -2088,7 +2088,7 @@ private: } int flags = Extend | SmartPointer | use_naturalvar_mode(var); - if (is_non_virtual_protected_access(var)) { + if (isNonVirtualProtectedAccess(var)) { flags |= CWRAP_ALL_PROTECTED_ACCESS; } diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 3c7b1f5a0..75254d69f 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -841,7 +841,7 @@ int Language::cDeclaration(Node *n) { if (!isfriend) { /* Check what the director needs. If the method is pure virtual, it is always needed. * Also wrap non-virtual protected members if asked for (allprotected mode). */ - if (!(directorsEnabled() && ((is_member_director(CurrentClass, n) && need_nonpublic_member(n)) || is_non_virtual_protected_access(n)))) { + if (!(directorsEnabled() && ((is_member_director(CurrentClass, n) && need_nonpublic_member(n)) || isNonVirtualProtectedAccess(n)))) { return SWIG_NOWRAP; } // Prevent wrapping protected overloaded director methods more than once - @@ -1224,7 +1224,7 @@ int Language::memberfunctionHandler(Node *n) { // Set up the type for the cast to this class for use when wrapping const director (virtual) methods. // Note: protected director methods or when allprotected mode turned on. String *director_type = 0; - if (!is_public(n) && (is_member_director(CurrentClass, n) || GetFlag(n, "explicitcall") || is_non_virtual_protected_access(n))) { + if (!is_public(n) && (is_member_director(CurrentClass, n) || GetFlag(n, "explicitcall") || isNonVirtualProtectedAccess(n))) { director_type = Copy(DirectorClassName); String *qualifier = Getattr(n, "qualifier"); if (qualifier) @@ -1270,7 +1270,7 @@ int Language::staticmemberfunctionHandler(Node *n) { if (!Extend) { Node *sb = Getattr(n, "cplus:staticbase"); String *sname = Getattr(sb, "name"); - if (is_non_virtual_protected_access(n)) + if (isNonVirtualProtectedAccess(n)) cname = NewStringf("%s::%s", DirectorClassName, name); else cname = NewStringf("%s::%s", sname, name); @@ -1415,14 +1415,14 @@ int Language::membervariableHandler(Node *n) { Delete(pname); } } else { - String *pname = is_non_virtual_protected_access(n) ? NewString("darg") : Swig_cparm_name(0, 0); + String *pname = isNonVirtualProtectedAccess(n) ? NewString("darg") : Swig_cparm_name(0, 0); target = NewStringf("%s->%s", pname, name); Delete(pname); } tm = Swig_typemap_lookup("memberin", n, target, 0); } int flags = Extend | SmartPointer | use_naturalvar_mode(n); - if (is_non_virtual_protected_access(n)) + if (isNonVirtualProtectedAccess(n)) flags = flags | CWRAP_ALL_PROTECTED_ACCESS; Swig_MembersetToFunction(n, ClassType, flags); @@ -1470,7 +1470,7 @@ int Language::membervariableHandler(Node *n) { /* Emit get function */ { int flags = Extend | SmartPointer | use_naturalvar_mode(n); - if (is_non_virtual_protected_access(n)) + if (isNonVirtualProtectedAccess(n)) flags = flags | CWRAP_ALL_PROTECTED_ACCESS; Swig_MembergetToFunction(n, ClassType, flags); Setattr(n, "sym:name", mrename_get); @@ -1530,7 +1530,7 @@ int Language::membervariableHandler(Node *n) { int Language::staticmembervariableHandler(Node *n) { Swig_require("staticmembervariableHandler", n, "*name", "*sym:name", "*type", "?value", NIL); String *value = Getattr(n, "value"); - String *classname = !SmartPointer ? (is_non_virtual_protected_access(n) ? DirectorClassName : ClassName) : Getattr(CurrentClass, "allocate:smartpointerbase"); + String *classname = !SmartPointer ? (isNonVirtualProtectedAccess(n) ? DirectorClassName : ClassName) : Getattr(CurrentClass, "allocate:smartpointerbase"); if (!value || !Getattr(n, "hasconsttype")) { String *name = Getattr(n, "name"); @@ -1695,7 +1695,7 @@ int Language::memberconstantHandler(Node *n) { if (Extend) new_name = Copy(value); else - new_name = NewStringf("%s::%s", is_non_virtual_protected_access(n) ? DirectorClassName : ClassName, name); + new_name = NewStringf("%s::%s", isNonVirtualProtectedAccess(n) ? DirectorClassName : ClassName, name); Setattr(n, "name", new_name); constantWrapper(n); @@ -2116,7 +2116,7 @@ int Language::classDirector(Node *n) { Node *nodeType = Getattr(ni, "nodeType"); bool cdeclaration = (Cmp(nodeType, "cdecl") == 0); if (cdeclaration && !GetFlag(ni, "feature:ignore")) { - if (is_non_virtual_protected_access(ni)) { + if (isNonVirtualProtectedAccess(ni)) { Node *overloaded = Getattr(ni, "sym:overloaded"); // emit the using base::member statement (but only once if the method is overloaded) if (!overloaded || (overloaded && (overloaded == ni))) @@ -3331,7 +3331,7 @@ int Language::need_nonpublic_ctor(Node *n) { * Language::need_nonpublic_member() * ----------------------------------------------------------------------------- */ int Language::need_nonpublic_member(Node *n) { - if (directorsEnabled()) { + if (directorsEnabled() && DirectorClassName) { if (is_protected(n)) { if (dirprot_mode()) { /* when using dirprot mode, the protected members are always needed. */ @@ -3355,6 +3355,16 @@ int Language::is_smart_pointer() const { return SmartPointer; } +/* ----------------------------------------------------------------------------- + * Language::() + * ----------------------------------------------------------------------------- */ + +bool Language::isNonVirtualProtectedAccess(Node *n) const { + // Ideally is_non_virtual_protected_access() would contain all this logic, see + // comments therein about vtable. + return DirectorClassName && is_non_virtual_protected_access(n); +} + /* ----------------------------------------------------------------------------- * Language::extraDirectorProtectedCPPMethodsRequired() * ----------------------------------------------------------------------------- */ diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 7733391fc..4a65444fc 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -294,6 +294,10 @@ protected: /* Some language modules require additional wrappers for virtual methods not declared in sub-classes */ virtual bool extraDirectorProtectedCPPMethodsRequired() const; + /* Identifies if a protected members that are generated when the allprotected option is used. + This does not include protected virtual methods as they are turned on with the dirprot option. */ + bool isNonVirtualProtectedAccess(Node *n) const; + /* Director subclass comparison test */ String *none_comparison; From c47fd5fdd5763ae85d05c6c49bf781a2ad24dceb Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 30 May 2012 05:59:46 +0000 Subject: [PATCH 0122/1160] Director documentation corrections to match reality. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13136 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Java.html | 3 --- Doc/Manual/Php.html | 3 --- Doc/Manual/Python.html | 3 --- 3 files changed, 9 deletions(-) diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 76e147be5..2473e7cd1 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -3354,9 +3354,6 @@ The %feature directive can be applied globally, to specific classes, and to spec // generate directors for all virtual methods in class Foo %feature("director") Foo; - -// generate a director for just Foo::bar() -%feature("director") Foo::bar;
    diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 76031d07e..78ee6ea7f 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -901,9 +901,6 @@ globally, to specific classes, and to specific methods, like this: // generate directors for all virtual methods in class Foo %feature("director") Foo; - -// generate a director for just Foo::bar() -%feature("director") Foo::bar;
    diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index a9a9bc44e..f718f981f 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -2782,9 +2782,6 @@ globally, to specific classes, and to specific methods, like this: // generate directors for all virtual methods in class Foo %feature("director") Foo; - -// generate a director for just Foo::bar() -%feature("director") Foo::bar;
    From 8fe63be0517ed21a8545bbe21b62d461830ceff6 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 31 May 2012 04:12:17 +0000 Subject: [PATCH 0123/1160] Fix doc typo git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13137 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index f718f981f..bd48a37f2 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -2345,7 +2345,7 @@ doesn't know how to add an instance of MyString to itself.
  • If you have multiple SWIG modules that share type information (more info), -the -builtin option requiress a bit of extra discipline to ensure that base classes are initialized before derived classes. Specifically:

    +the -builtin option requires a bit of extra discipline to ensure that base classes are initialized before derived classes. Specifically:

    • There must be an unambiguous dependency graph for the modules.

    • Module dependencies must be explicitly stated with %import statements in the SWIG interface file.

      From 7ec208da05defb990593940c06bf13d6f6fcfc55 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 4 Jun 2012 05:37:10 +0000 Subject: [PATCH 0124/1160] Fix Go support to use appropriate interface for entering and leaving C/C++ code, depending on GCC version. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13146 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/go/goruntime.swg | 51 +++++++++++++++++++++++++++++++++++++++++++ Source/Modules/go.cxx | 38 +++++++++++++++++++++----------- 2 files changed, 76 insertions(+), 13 deletions(-) diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index ef23d1211..f5f1f6e73 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -84,6 +84,57 @@ extern "C" { #endif extern void *_cgo_allocate(size_t); extern void _cgo_panic(const char *); + +/* Implementations of SwigCgocall and friends for different versions + of gccgo. The Go code will call these functions using C names with + a prefix of the module name. The implementations here call the + routine in libgo. The routines to call vary depending on the gccgo + version. We assume that the version of gcc used to compile this + file is the same as the version of gccgo. */ + +#define SWIGCONCAT2(s1, s2) s1 ## s2 +#define SWIGCONCAT1(s1, s2) SWIGCONCAT2(s1, s2) +#define SwigCgocall SWIGCONCAT1(SWIGMODULE, SwigCgocall) +#define SwigCgocallDone SWIGCONCAT1(SWIGMODULE, SwigCgocallDone) +#define SwigCgocallBack SWIGCONCAT1(SWIGMODULE, SwigCgocallBack) +#define SwigCgocallBackDone SWIGCONCAT1(SWIGMODULE, SwigCgocallBackDone) + +#define SWIG_GCC_VERSION \ + (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC__PATH_LEVEL__) + +#if SWIG_GCC_VERSION < 40700 +#define SwigDoCgocall() +#define SwigDoCgocalldone() +#define SwigDoCgocallBack() +#define SwigDoCgocallBackDone() +#elif SWIG_GCC_VERSION == 40700 +void SwigDoCgocall(void) __asm__("libgo_syscall.syscall.Entersyscall"); +void SwigDoCgocallDone(void) __asm__("libgo_syscall.syscall.Exitsyscall"); +void SwigDoCgocallBack(void) __asm__("libgo_syscall.syscall.Exitsyscall"); +void SwigDoCgocallBackDone(void) __asm__("libgo_syscall.syscall.Entersyscall"); +#else +void SwigDoCgocall(void) __asm__("syscall.Cgocall"); +void SwigDoCgocallDone(void) __asm__("syscall.CgocallDone"); +void SwigDoCgocallBack(void) __asm__("syscall.CgocallBack"); +void SwigDoCgocallBackDone(void) __asm__("syscall.CgocallBackDone"); +#endif + +void SwigCgocall() { + SwigDoCgocall(); +} + +void SwigCgocallDone() { + SwigDoCgocallDone(); +} + +void SwigCgocallBack() { + SwigDoCgocallBack(); +} + +void SwigCgocallBackDone() { + SwigDoCgocallBackDone(); +} + #ifdef __cplusplus } #endif diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 9966efb64..d76ae82a3 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -326,6 +326,8 @@ private: Swig_banner(f_c_begin); + Printf(f_c_runtime, "#define SWIGMODULE %s\n", module); + if (directorsEnabled()) { Printf(f_c_runtime, "#define SWIG_DIRECTORS\n"); @@ -349,6 +351,15 @@ private: Printf(f_go_begin, "\npackage %s\n\n", package); + Printf(f_go_runtime, "//extern %sSwigCgocall\n", module); + Printf(f_go_runtime, "func SwigCgocall()\n"); + Printf(f_go_runtime, "//extern %sSwigCgocallDone\n", module); + Printf(f_go_runtime, "func SwigCgocallDone()\n"); + Printf(f_go_runtime, "//extern %sSwigCgocallBack\n", module); + Printf(f_go_runtime, "func SwigCgocallBack()\n"); + Printf(f_go_runtime, "//extern %sSwigCgocallBackDone\n", module); + Printf(f_go_runtime, "func SwigCgocallBackDone()\n\n"); + // All the C++ wrappers should be extern "C". Printv(f_c_wrappers, "#ifdef __cplusplus\n", "extern \"C\" {\n", "#endif\n\n", NULL); @@ -941,8 +952,8 @@ private: } if (gccgo_flag) { - Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL); - Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\n", NULL); + Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); + Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); } Printv(f_go_wrappers, "\t", NULL); @@ -2538,8 +2549,8 @@ private: Printv(f_go_wrappers, "\tp := &", director_struct_name, "{0, v}\n", NULL); if (gccgo_flag) { - Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL); - Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\n", NULL); + Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); + Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); } Printv(f_go_wrappers, "\tp.", class_receiver, " = ", fn_name, NULL); @@ -3049,11 +3060,6 @@ private: Printv(f_go_wrappers, " {\n", NULL); - if (gccgo_flag) { - Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL); - Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\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) { @@ -3076,6 +3082,12 @@ private: Printv(f_go_wrappers, "\t\treturn\n", NULL); } Printv(f_go_wrappers, "\t}\n", NULL); + + if (gccgo_flag) { + Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); + Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); + } + Printv(f_go_wrappers, "\t", NULL); if (SwigType_type(result) != T_VOID) { Printv(f_go_wrappers, "return ", NULL); @@ -3222,8 +3234,8 @@ private: Printv(f_go_wrappers, " {\n", NULL); if (gccgo_flag) { - Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL); - Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\n", NULL); + Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); + Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); } Printv(f_go_wrappers, "\t", NULL); @@ -3269,8 +3281,8 @@ private: Printv(f_go_wrappers, "{\n", NULL); if (gccgo_flag) { - Printv(f_go_wrappers, "\tsyscall.Exitsyscall()\n", NULL); - Printv(f_go_wrappers, "\tdefer syscall.Entersyscall()\n", NULL); + Printv(f_go_wrappers, "\tSwigCgocallBack()\n", NULL); + Printv(f_go_wrappers, "\tdefer SwigCgocallBackDone()\n", NULL); } Printv(f_go_wrappers, "\t", NULL); From 9a6dc5ac408567f3501e07344099c904d8bbb3ea Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 5 Jun 2012 13:32:28 +0000 Subject: [PATCH 0125/1160] Fix typo in name of SwigDoCgocallDone for GCC < 4.7. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13151 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/go/goruntime.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index f5f1f6e73..ad044f8ba 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -104,7 +104,7 @@ extern void _cgo_panic(const char *); #if SWIG_GCC_VERSION < 40700 #define SwigDoCgocall() -#define SwigDoCgocalldone() +#define SwigDoCgocallDone() #define SwigDoCgocallBack() #define SwigDoCgocallBackDone() #elif SWIG_GCC_VERSION == 40700 From 5a191134329a0cc53fd8b7568d10bd808727300a Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 5 Jun 2012 20:54:08 +0000 Subject: [PATCH 0126/1160] Import unsafe in generated Go code, so that pointers stored as type uintptr do not get garbage collected. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13153 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/go/goruntime.swg | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index ad044f8ba..ff33c3b41 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -165,6 +165,9 @@ static _gostring_ _swig_makegostring(const char *p, size_t l) { %insert(go_header) %{ import _ "runtime/cgo" +import "unsafe" + +type _ unsafe.Pointer %} @@ -173,9 +176,12 @@ import _ "runtime/cgo" %insert(go_header) %{ import "syscall" +import "unsafe" type _ syscall.Sockaddr +type _ unsafe.Pointer + %} #endif From 6a20df2bb8885d8bf2b7cfcac0c22a882a98caad Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 5 Jun 2012 23:02:42 +0000 Subject: [PATCH 0127/1160] Don't convert uintptr to interface type while not connected to Go scheduler. Likewise with calls to defer. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13154 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/go.cxx | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index d76ae82a3..47bfc4ea1 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -952,13 +952,32 @@ private: } if (gccgo_flag) { - Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); - Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); + if (!is_constructor) { + Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); + Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); + } else { + // For a constructor the wrapper function will return a + // uintptr but we will return an interface. We want to + // convert the uintptr to the interface after calling + // SwigCgocallDone, so that we don't try to allocate memory + // while the Go scheduler can't see us. + Printv(f_go_wrappers, "\tvar done bool\n", NULL); + Printv(f_go_wrappers, "\tdefer func() {\n", NULL); + Printv(f_go_wrappers, "\t\tif !done {\n", NULL); + Printv(f_go_wrappers, "\t\t\tSwigCgocallDone()\n", NULL); + Printv(f_go_wrappers, "\t\t}\n", NULL); + Printv(f_go_wrappers, "\t}()\n", NULL); + Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); + } } Printv(f_go_wrappers, "\t", NULL); if (SwigType_type(result) != T_VOID) { - Printv(f_go_wrappers, "return ", NULL); + if (gccgo_flag && is_constructor) { + Printv(f_go_wrappers, "swig_r := ", NULL); + } else { + Printv(f_go_wrappers, "return ", NULL); + } } Printv(f_go_wrappers, wrapper_name, "(", NULL); @@ -994,6 +1013,13 @@ private: p = nextParm(p); } Printv(f_go_wrappers, ")\n", NULL); + + if (gccgo_flag && is_constructor) { + Printv(f_go_wrappers, "\tSwigCgocallDone()\n", NULL); + Printv(f_go_wrappers, "\tdone = true\n", NULL); + Printv(f_go_wrappers, "\treturn swig_r\n", NULL); + } + Printv(f_go_wrappers, "}\n", NULL); } @@ -2549,8 +2575,8 @@ private: Printv(f_go_wrappers, "\tp := &", director_struct_name, "{0, v}\n", NULL); if (gccgo_flag) { - Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); + Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); } Printv(f_go_wrappers, "\tp.", class_receiver, " = ", fn_name, NULL); @@ -3084,8 +3110,8 @@ private: Printv(f_go_wrappers, "\t}\n", NULL); if (gccgo_flag) { - Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); + Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); } Printv(f_go_wrappers, "\t", NULL); @@ -3234,8 +3260,8 @@ private: Printv(f_go_wrappers, " {\n", NULL); if (gccgo_flag) { - Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); + Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); } Printv(f_go_wrappers, "\t", NULL); From cf16f43e511761217782295dc7c548c749512d4a Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Sun, 10 Jun 2012 13:54:27 +0000 Subject: [PATCH 0128/1160] add std_vector items` git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13159 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/r/std_vector.i | 518 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 428 insertions(+), 90 deletions(-) diff --git a/Lib/r/std_vector.i b/Lib/r/std_vector.i index 9fb95c597..155626aa5 100644 --- a/Lib/r/std_vector.i +++ b/Lib/r/std_vector.i @@ -2,7 +2,7 @@ /* Vectors Thanks to Richard Beare - richard.beare@ieee.org for StdVectorTraits -*/ +*/ %fragment("StdVectorTraits","header",fragment="StdSequenceTraits") %{ @@ -11,86 +11,87 @@ template <> struct traits_from_ptr > { static SEXP from (std::vector *val, int owner = 0) { - SEXP result; - PROTECT(result = Rf_allocVector(REALSXP, val->size())); - for (unsigned pos = 0; pos < val->size(); pos++) - { - NUMERIC_POINTER(result)[pos] = ((*val)[pos]); - } - UNPROTECT(1); - return(result); + SEXP result; + PROTECT(result = Rf_allocVector(REALSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + NUMERIC_POINTER(result)[pos] = ((*val)[pos]); + } + UNPROTECT(1); + return(result); } }; // vectors of floats template <> struct traits_from_ptr > { static SEXP from (std::vector *val, int owner = 0) { - SEXP result; - PROTECT(result = Rf_allocVector(REALSXP, val->size())); - for (unsigned pos = 0; pos < val->size(); pos++) - { - NUMERIC_POINTER(result)[pos] = ((*val)[pos]); - } - UNPROTECT(1); - return(result); + SEXP result; + PROTECT(result = Rf_allocVector(REALSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + NUMERIC_POINTER(result)[pos] = ((*val)[pos]); + } + UNPROTECT(1); + return(result); } }; // vectors of unsigned int template <> struct traits_from_ptr > { static SEXP from (std::vector *val, int owner = 0) { - SEXP result; - PROTECT(result = Rf_allocVector(INTSXP, val->size())); - for (unsigned pos = 0; pos < val->size(); pos++) - { - INTEGER_POINTER(result)[pos] = ((*val)[pos]); - } - UNPROTECT(1); - return(result); + SEXP result; + PROTECT(result = Rf_allocVector(INTSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + INTEGER_POINTER(result)[pos] = ((*val)[pos]); + } + UNPROTECT(1); + return(result); } }; // vectors of int template <> struct traits_from_ptr > { static SEXP from (std::vector *val, int owner = 0) { - SEXP result; - PROTECT(result = Rf_allocVector(INTSXP, val->size())); - for (unsigned pos = 0; pos < val->size(); pos++) - { - INTEGER_POINTER(result)[pos] = ((*val)[pos]); - } - UNPROTECT(1); - return(result); + SEXP result; + PROTECT(result = Rf_allocVector(INTSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + INTEGER_POINTER(result)[pos] = ((*val)[pos]); + } + UNPROTECT(1); + return(result); } }; + // vectors of bool template <> struct traits_from_ptr > { static SEXP from (std::vector *val, int owner = 0) { - SEXP result; - PROTECT(result = Rf_allocVector(LGLSXP, val->size())); - for (unsigned pos = 0; pos < val->size(); pos++) - { - LOGICAL_POINTER(result)[pos] = ((*val)[pos]); - } - UNPROTECT(1); - return(result); - //return SWIG_R_NewPointerObj(val, type_info< std::vector >(), owner); + SEXP result; + PROTECT(result = Rf_allocVector(LGLSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + LOGICAL_POINTER(result)[pos] = ((*val)[pos]); + } + UNPROTECT(1); + return(result); + //return SWIG_R_NewPointerObj(val, type_info< std::vector >(), owner); } }; // vectors of strings template <> struct traits_from_ptr > > { static SEXP from (std::vector > *val, int owner = 0) { - SEXP result; - PROTECT(result = Rf_allocVector(STRSXP, val->size())); - for (unsigned pos = 0; pos < val->size(); pos++) - { - CHARACTER_POINTER(result)[pos] = Rf_mkChar(((*val)[pos]).c_str()); - } - UNPROTECT(1); - return(result); - //return SWIG_R_NewPointerObj(val, type_info< std::vector >(), owner); + SEXP result; + PROTECT(result = Rf_allocVector(STRSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + CHARACTER_POINTER(result)[pos] = Rf_mkChar(((*val)[pos]).c_str()); + } + UNPROTECT(1); + return(result); + //return SWIG_R_NewPointerObj(val, type_info< std::vector >(), owner); } }; @@ -98,12 +99,12 @@ template struct traits_from_ptr< std::vector< T > > { static SEXP from (std::vector< T > *val, int owner = 0) { - return SWIG_R_NewPointerObj(val, type_info< std::vector< T > >(), owner); + return SWIG_R_NewPointerObj(val, type_info< std::vector< T > >(), owner); } }; template <> - struct traits_asptr < std::vector > { + struct traits_asptr < std::vector > { static int asptr(SEXP obj, std::vector **val) { std::vector *p; // not sure how to check the size of the SEXP obj is correct @@ -111,19 +112,19 @@ p = new std::vector(sexpsz); double *S = NUMERIC_POINTER(obj); for (unsigned pos = 0; pos < p->size(); pos++) - { - (*p)[pos] = static_cast(S[pos]); - } + { + (*p)[pos] = static_cast(S[pos]); + } int res = SWIG_OK; if (SWIG_IsOK(res)) { - if (val) *val = p; + if (val) *val = p; } return res; } - }; + }; template <> - struct traits_asptr < std::vector > { + struct traits_asptr < std::vector > { static int asptr(SEXP obj, std::vector **val) { std::vector *p; // not sure how to check the size of the SEXP obj is correct @@ -131,19 +132,19 @@ p = new std::vector(sexpsz); double *S = NUMERIC_POINTER(obj); for (unsigned pos = 0; pos < p->size(); pos++) - { - (*p)[pos] = static_cast(S[pos]); - } + { + (*p)[pos] = static_cast(S[pos]); + } int res = SWIG_OK; if (SWIG_IsOK(res)) { - if (val) *val = p; + if (val) *val = p; } return res; } - }; - + }; + template <> - struct traits_asptr < std::vector > { + struct traits_asptr < std::vector > { static int asptr(SEXP obj, std::vector **val) { std::vector *p; unsigned int sexpsz = Rf_length(obj); @@ -152,20 +153,20 @@ PROTECT(coerced = Rf_coerceVector(obj, INTSXP)); int *S = INTEGER_POINTER(coerced); for (unsigned pos = 0; pos < p->size(); pos++) - { - (*p)[pos] = static_cast(S[pos]); - } + { + (*p)[pos] = static_cast(S[pos]); + } int res = SWIG_OK; if (SWIG_IsOK(res)) { - if (val) *val = p; + if (val) *val = p; } UNPROTECT(1); return res; } - }; + }; template <> - struct traits_asptr < std::vector > { + struct traits_asptr < std::vector > { static int asptr(SEXP obj, std::vector **val) { std::vector *p; // not sure how to check the size of the SEXP obj is correct @@ -175,31 +176,313 @@ PROTECT(coerced = Rf_coerceVector(obj, INTSXP)); int *S = INTEGER_POINTER(coerced); for (unsigned pos = 0; pos < p->size(); pos++) - { - (*p)[pos] = static_cast(S[pos]); - } + { + (*p)[pos] = static_cast(S[pos]); + } int res = SWIG_OK; if (SWIG_IsOK(res)) { - if (val) *val = p; + if (val) *val = p; } UNPROTECT(1); return res; } - }; + }; + + template <> + struct traits_asptr < std::vector > { + static int asptr(SEXP obj, std::vector **val) { + std::vector *p; + // not sure how to check the size of the SEXP obj is correct + int sexpsz = Rf_length(obj); + p = new std::vector(sexpsz); + SEXP coerced; + PROTECT(coerced = Rf_coerceVector(obj, LGLSXP)); + int *S = LOGICAL_POINTER(coerced); + for (unsigned pos = 0; pos < p->size(); pos++) + { + (*p)[pos] = static_cast(S[pos]); + } + int res = SWIG_OK; + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + UNPROTECT(1); + return res; + } + }; // catchall for R to vector conversion template - struct traits_asptr < std::vector > { + struct traits_asptr < std::vector > { static int asptr(SEXP obj, std::vector **val) { std::vector *p; + Rprintf("my asptr\n"); int res = SWIG_R_ConvertPtr(obj, (void**)&p, type_info< std::vector >(), 0); if (SWIG_IsOK(res)) { - if (val) *val = p; + if (val) *val = p; } return res; } - }; + }; + // now for vectors of vectors. These will be represented as lists of vectors on the + // catch all that does everything with vectors + template <> + struct traits_from_ptr > > { + static SEXP from (std::vector< std::vector > *val, int owner = 0) { + SEXP result; + // allocate the R list + PROTECT(result = Rf_allocVector(VECSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + // allocate the R vector + SET_VECTOR_ELT(result, pos, Rf_allocVector(INTSXP, val->at(pos).size())); + // Fill the R vector + for (unsigned vpos = 0; vpos < val->at(pos).size(); ++vpos) + { + INTEGER_POINTER(VECTOR_ELT(result, pos))[vpos] = static_cast(val->at(pos).at(vpos)); + } + } + UNPROTECT(1); + return(result); + } + }; + + template <> + struct traits_from_ptr > > { + static SEXP from (std::vector< std::vector > *val, int owner = 0) { + SEXP result; + // allocate the R list + PROTECT(result = Rf_allocVector(VECSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + // allocate the R vector + SET_VECTOR_ELT(result, pos, Rf_allocVector(INTSXP, val->at(pos).size())); + // Fill the R vector + for (unsigned vpos = 0; vpos < val->at(pos).size(); ++vpos) + { + INTEGER_POINTER(VECTOR_ELT(result, pos))[vpos] = static_cast(val->at(pos).at(vpos)); + } + } + UNPROTECT(1); + return(result); + } + }; + + template <> + struct traits_from_ptr > > { + static SEXP from (std::vector< std::vector > *val, int owner = 0) { + SEXP result; + // allocate the R list + PROTECT(result = Rf_allocVector(VECSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + // allocate the R vector + SET_VECTOR_ELT(result, pos, Rf_allocVector(REALSXP, val->at(pos).size())); + // Fill the R vector + for (unsigned vpos = 0; vpos < val->at(pos).size(); ++vpos) + { + NUMERIC_POINTER(VECTOR_ELT(result, pos))[vpos] = static_cast(val->at(pos).at(vpos)); + } + } + UNPROTECT(1); + return(result); + } + }; + + template <> + struct traits_from_ptr > > { + static SEXP from (std::vector< std::vector > *val, int owner = 0) { + SEXP result; + // allocate the R list + PROTECT(result = Rf_allocVector(VECSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + // allocate the R vector + SET_VECTOR_ELT(result, pos, Rf_allocVector(REALSXP, val->at(pos).size())); + // Fill the R vector + for (unsigned vpos = 0; vpos < val->at(pos).size(); ++vpos) + { + NUMERIC_POINTER(VECTOR_ELT(result, pos))[vpos] = static_cast(val->at(pos).at(vpos)); + } + } + UNPROTECT(1); + return(result); + } + }; + + template <> + struct traits_from_ptr > > { + static SEXP from (std::vector< std::vector > *val, int owner = 0) { + SEXP result; + // allocate the R list + PROTECT(result = Rf_allocVector(VECSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + // allocate the R vector + SET_VECTOR_ELT(result, pos, Rf_allocVector(LGLSXP, val->at(pos).size())); + // Fill the R vector + for (unsigned vpos = 0; vpos < val->at(pos).size(); ++vpos) + { + LOGICAL_POINTER(VECTOR_ELT(result, pos))[vpos] = (val->at(pos).at(vpos)); + } + } + UNPROTECT(1); + return(result); + } + }; + + template + struct traits_from_ptr< std::vector < std::vector< T > > > { + static SEXP from (std::vector < std::vector< T > > *val, int owner = 0) { + return SWIG_R_NewPointerObj(val, type_info< std::vector < std::vector< T > > >(), owner); + } + }; + + // R side + template <> + struct traits_asptr < std::vector< std::vector > > { + static int asptr(SEXP obj, std::vector< std::vector > **val) { + std::vector > *p; + // this is the length of the list + unsigned int sexpsz = Rf_length(obj); + p = new std::vector< std::vector > (sexpsz); + + for (unsigned listpos = 0; listpos < sexpsz; ++listpos) + { + unsigned vecsize = Rf_length(VECTOR_ELT(obj, listpos)); + for (unsigned vpos = 0; vpos < vecsize; ++vpos) + { + (*p)[listpos].push_back(static_cast(INTEGER_POINTER(VECTOR_ELT(obj, listpos))[vpos])); + } + } + + int res = SWIG_OK; + + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + template <> + struct traits_asptr < std::vector< std::vector< int> > > { + static int asptr(SEXP obj, std::vector< std::vector< int> > **val) { + std::vector > *p; + // this is the length of the list + unsigned int sexpsz = Rf_length(obj); + p = new std::vector< std::vector< int> > (sexpsz); + + for (unsigned listpos = 0; listpos < sexpsz; ++listpos) + { + unsigned vecsize = Rf_length(VECTOR_ELT(obj, listpos)); + for (unsigned vpos = 0; vpos < vecsize; ++vpos) + { + (*p)[listpos].push_back(static_cast(INTEGER_POINTER(VECTOR_ELT(obj, listpos))[vpos])); + } + } + + int res = SWIG_OK; + + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + template <> + struct traits_asptr < std::vector< std::vector< float> > > { + static int asptr(SEXP obj, std::vector< std::vector< float> > **val) { + std::vector > *p; + // this is the length of the list + unsigned int sexpsz = Rf_length(obj); + p = new std::vector< std::vector< float> > (sexpsz); + + for (unsigned listpos = 0; listpos < sexpsz; ++listpos) + { + unsigned vecsize = Rf_length(VECTOR_ELT(obj, listpos)); + for (unsigned vpos = 0; vpos < vecsize; ++vpos) + { + (*p)[listpos].push_back(static_cast(NUMERIC_POINTER(VECTOR_ELT(obj, listpos))[vpos])); + } + } + + int res = SWIG_OK; + + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + template <> + struct traits_asptr < std::vector< std::vector< double> > > { + static int asptr(SEXP obj, std::vector< std::vector< double> > **val) { + std::vector > *p; + // this is the length of the list + unsigned int sexpsz = Rf_length(obj); + p = new std::vector< std::vector< double> > (sexpsz); + + for (unsigned listpos = 0; listpos < sexpsz; ++listpos) + { + unsigned vecsize = Rf_length(VECTOR_ELT(obj, listpos)); + for (unsigned vpos = 0; vpos < vecsize; ++vpos) + { + (*p)[listpos].push_back(static_cast(NUMERIC_POINTER(VECTOR_ELT(obj, listpos))[vpos])); + } + } + + int res = SWIG_OK; + + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + template <> + struct traits_asptr < std::vector< std::vector< bool > > > { + static int asptr(SEXP obj, std::vector< std::vector< bool> > **val) { + std::vector > *p; + // this is the length of the list + unsigned int sexpsz = Rf_length(obj); + p = new std::vector< std::vector< bool > > (sexpsz); + + for (unsigned listpos = 0; listpos < sexpsz; ++listpos) + { + unsigned vecsize = Rf_length(VECTOR_ELT(obj, listpos)); + for (unsigned vpos = 0; vpos < vecsize; ++vpos) + { + (*p)[listpos].push_back(static_cast(LOGICAL_POINTER(VECTOR_ELT(obj, listpos))[vpos])); + } + } + + int res = SWIG_OK; + + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + // catchall + template + struct traits_asptr < std::vector< std::vector > > { + static int asptr(SEXP obj, std::vector< std::vector > **val) { + std::vector< std::vector > *p; + Rprintf("vector of vectors - unsupported content\n"); + int res = SWIG_R_ConvertPtr(obj, (void**)&p, type_info< std::vector< std::vector > > (), 0); + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; } %} @@ -209,12 +492,12 @@ %define %traits_type_name(Type...) %fragment(SWIG_Traits_frag(Type), "header", - fragment="StdTraits",fragment="StdVectorTraits") { + fragment="StdTraits",fragment="StdVectorTraits") { namespace swig { template <> struct traits< Type > { typedef pointer_category category; static const char* type_name() { - return #Type; + return #Type; } }; } @@ -225,33 +508,72 @@ %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector) %traits_type_name(std::vector) -%typemap("rtypecheck") std::vector %{ is.numeric($arg) %} +%typemap("rtypecheck") std::vector, std::vector const, std::vector const& + %{ is.numeric($arg) %} %typemap("rtype") std::vector "numeric" %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector) %traits_type_name(std::vector) -%typemap("rtypecheck") std::vector %{ is.numeric($arg) %} +%typemap("rtypecheck") std::vector, std::vector const, std::vector const& + %{ is.numeric($arg) %} %typemap("rtype") std::vector "numeric" %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector); %traits_type_name(std::vector); -%typemap("rtypecheck") std::vector %{ is.logical($arg) %} +%typemap("rtypecheck") std::vector , std::vector const, std::vector const& + %{ is.logical($arg) %} %typemap("rtype") std::vector "logical" +%typemap("scoercein") std::vector "$input = as.logical($input);"; %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector); %traits_type_name(std::vector); -%typemap("rtypecheck") std::vector +%typemap("rtypecheck") std::vector , std::vector const, std::vector const& %{ is.integer($arg) || is.numeric($arg) %} %typemap("rtype") std::vector "integer" %typemap("scoercein") std::vector "$input = as.integer($input);"; %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector); %traits_type_name(std::vector); -%typemap("rtypecheck") std::vector +%typemap("rtypecheck") std::vector, std::vector const, std::vector const& %{ is.integer($arg) || is.numeric($arg) %} %typemap("rtype") std::vector "integer" %typemap("scoercein") std::vector "$input = as.integer($input);"; +%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector >); +%traits_type_name(std::vector< std::vector >); +%typemap("rtypecheck") std::vector >, std::vector > const, std::vector >const& + %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} +%typemap("rtype") std::vector > "list" +%typemap("scoercein") std::vector< std::vector > "$input = lapply($input, as.integer);"; + +%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector >); +%traits_type_name(std::vector< std::vector >); +%typemap("rtypecheck") std::vector >, std::vector > const, std::vector >const& + %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} +%typemap("rtype") std::vector > "list" +%typemap("scoercein") std::vector< std::vector > "$input = lapply($input, as.integer);"; + +%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector >); +%traits_type_name(std::vector< std::vector >); +%typemap("rtypecheck") std::vector >, std::vector > const, std::vector >const& + %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} +%typemap("rtype") std::vector > "list" +%typemap("scoercein") std::vector< std::vector > "$input = lapply($input, as.numeric);"; + +%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector >); +%traits_type_name(std::vector< std::vector >); +%typemap("rtypecheck") std::vector >, std::vector > const, std::vector >const& + %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} +%typemap("rtype") std::vector > "list" +%typemap("scoercein") std::vector< std::vector > "$input = lapply($input, as.numeric);"; + +%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector >); +%traits_type_name(std::vector< std::vector >); +%typemap("rtypecheck") std::vector >, std::vector > const, std::vector >const& + %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} +%typemap("rtype") std::vector > "list" +%typemap("scoercein") std::vector< std::vector > "$input = lapply($input, as.logical);"; + // we don't want these to be given R classes as they // have already been turned into R vectors. %typemap(scoerceout) std::vector, @@ -262,7 +584,23 @@ std::vector &, std::vector, std::vector *, - std::vector & + std::vector &, + // vectors of vectors + std::vector< std::vector >, + std::vector< std::vector >*, + std::vector< std::vector >&, + std::vector< std::vector >, + std::vector< std::vector >*, + std::vector< std::vector >&, + std::vector< std::vector >, + std::vector< std::vector >*, + std::vector< std::vector >&, + std::vector< std::vector >, + std::vector< std::vector >*, + std::vector< std::vector >&, + std::vector< std::vector >, + std::vector< std::vector >*, + std::vector< std::vector >& + + %{ %} - - From e4a3a004ae0bd23c22e70e4d93f5a46d3e05199e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 11 Jun 2012 18:05:56 +0000 Subject: [PATCH 0129/1160] Move contributor names to where they belong git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13160 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- COPYRIGHT | 2 +- Lib/r/std_vector.i | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/COPYRIGHT b/COPYRIGHT index 2fe0099b8..d2b87770a 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -65,7 +65,7 @@ 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, Edward Zimmermann, David Ascher, Dominique Dumont, Pier Giorgio Esposito, Hasan Baran Kovuk, - Klaus Wiederänders + Klaus Wiederänders, Richard Beare (See CHANGES and CHANGES.current and the bug tracker for a more complete list). Past students: diff --git a/Lib/r/std_vector.i b/Lib/r/std_vector.i index 155626aa5..f7ad94aac 100644 --- a/Lib/r/std_vector.i +++ b/Lib/r/std_vector.i @@ -1,7 +1,6 @@ // R specific swig components /* Vectors - Thanks to Richard Beare - richard.beare@ieee.org for StdVectorTraits */ %fragment("StdVectorTraits","header",fragment="StdSequenceTraits") From 1ce005825696c33b2040ae703e12c3698daa3815 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 25 Jun 2012 06:36:29 +0000 Subject: [PATCH 0130/1160] Fix symbol table bug with combinations of using directives and using declarations git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13190 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 13 +++ Examples/test-suite/common.mk | 1 + ...using_directive_and_declaration_runme.java | 28 ++++++ .../using_directive_and_declaration.i | 85 +++++++++++++++++++ Source/Swig/symbol.c | 19 +++++ 5 files changed, 146 insertions(+) create mode 100644 Examples/test-suite/java/using_directive_and_declaration_runme.java create mode 100644 Examples/test-suite/using_directive_and_declaration.i diff --git a/CHANGES.current b/CHANGES.current index 8458e45e0..ccf7a1e18 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,19 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.8 (in progress) =========================== +2012-06-25: wsfulton + Fix using declarations combined with using directives so that types are correctly found in scope. + Example: + + namespace Outer2 { + namespace Space2 { + class Thing2 {}; + } + } + using namespace Outer2; // using directive + using Space2::Thing2; // using declaration + void useit2(Thing2 t) {} + 2012-05-29: wsfulton Fix #3529601 - seg fault when a protected method has the "director" feature but the parent class does not. Also fix similar problems with diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 5660ec99e..fd7ecb1f3 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -442,6 +442,7 @@ CPP_TEST_CASES += \ using1 \ using2 \ using_composition \ + using_directive_and_declaration \ using_extend \ using_inherit \ using_namespace \ diff --git a/Examples/test-suite/java/using_directive_and_declaration_runme.java b/Examples/test-suite/java/using_directive_and_declaration_runme.java new file mode 100644 index 000000000..2be189dd5 --- /dev/null +++ b/Examples/test-suite/java/using_directive_and_declaration_runme.java @@ -0,0 +1,28 @@ + +import using_directive_and_declaration.*; + +public class using_directive_and_declaration_runme { + + static { + try { + System.loadLibrary("using_directive_and_declaration"); + } 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[]) + { + using_directive_and_declaration.useit1(new Thing1()); + using_directive_and_declaration.useit2(new Thing2()); + using_directive_and_declaration.useit3(new Thing3()); + using_directive_and_declaration.useit4(new Thing4()); + using_directive_and_declaration.useit5(new Thing5()); + Thing6a t6a = new Thing6a(); + t6a.a(); + Thing6 t6b = new Thing6(); + t6b.b(); + using_directive_and_declaration.useit6(t6a, t6b); + } +} diff --git a/Examples/test-suite/using_directive_and_declaration.i b/Examples/test-suite/using_directive_and_declaration.i new file mode 100644 index 000000000..7196d39f1 --- /dev/null +++ b/Examples/test-suite/using_directive_and_declaration.i @@ -0,0 +1,85 @@ +%module using_directive_and_declaration +// Test using directives combined with using declarations + +%inline %{ +namespace Outer1 { + namespace Space1 { + class Thing1 {}; + } +} +using namespace Outer1::Space1; +using Outer1::Space1::Thing1; +void useit1(Thing1 t) {} + + +namespace Outer2 { + namespace Space2 { + class Thing2 {}; + } +} +using namespace Outer2; +using Space2::Thing2; +void useit2(Thing2 t) {} + + +namespace Outer3 { + namespace Space3 { + namespace Middle3 { + class Thing3 {}; + } + } +} +using namespace Outer3; +using namespace Space3; +using Middle3::Thing3; +void useit3(Thing3 t) {} + + +namespace Outer4 { + namespace Space4 { + namespace Middle4 { + class Thing4 {}; + } + } +} +using namespace Outer4::Space4; +using Middle4::Thing4; +void useit4(Thing4 t) {} + + +namespace Outer5 { + namespace Space5 { + namespace Middle5 { + namespace More5 { + class Thing5 {}; + } + } + } +} +using namespace ::Outer5::Space5; +using namespace Middle5; +using More5::Thing5; +void useit5(Thing5 t) {} + +%} + +// Same symbol name in different namespaces +%rename(Thing6a) Outer6::Space6a::Thing6; + +%inline %{ +namespace Outer6 { + namespace Space6a { + struct Thing6 { + void a() {} + }; + } + namespace Space6b { + struct Thing6 { + void b() {} + }; + } +} +using namespace Outer6::Space6b; +void useit6(Outer6::Space6a::Thing6 ta, Thing6 tb) {} +%} + diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index 5ee6c3ec0..af0c7d015 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -1053,6 +1053,25 @@ static Node *symbol_lookup_qualified(const_String_or_char_ptr name, Symtab *symt Node *pn = Getattr(symtab, "parentNode"); if (pn) n = symbol_lookup_qualified(name, pn, prefix, local, checkfunc); + + /* Check inherited scopes */ + if (!n) { + List *inherit = Getattr(symtab, "inherit"); + if (inherit) { + int i, len; + len = Len(inherit); + for (i = 0; i < len; i++) { + Node *prefix_node = symbol_lookup(prefix, Getitem(inherit, i), checkfunc); + if (prefix_node) { + Node *prefix_symtab = Getattr(prefix_node, "symtab"); + if (prefix_symtab) { + n = symbol_lookup(name, prefix_symtab, checkfunc); + break; + } + } + } + } + } } else { n = 0; } From b6c76bcd949c354dc2ea3bd2dee43f29651c5f6e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 25 Jun 2012 18:22:17 +0000 Subject: [PATCH 0131/1160] Cosmetic changes and some docs on some symbol functions git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13192 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/symbol.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index af0c7d015..739767558 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -463,6 +463,7 @@ Symtab *Swig_symbol_current(void) { * Swig_symbol_alias() * * Makes an alias for a symbol in the global symbol table. + * Primarily for namespace aliases such as 'namespace X = Y;'. * ----------------------------------------------------------------------------- */ void Swig_symbol_alias(const_String_or_char_ptr aliasname, Symtab *s) { @@ -482,6 +483,8 @@ void Swig_symbol_alias(const_String_or_char_ptr aliasname, Symtab *s) { * Swig_symbol_inherit() * * Inherit symbols from another scope. + * Primarily for using directives, such as 'using namespace X;'. + * Not for using declarations, such as 'using A;'. * ----------------------------------------------------------------------------- */ void Swig_symbol_inherit(Symtab *s) { @@ -535,6 +538,7 @@ void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) { if (!name) return; + if (SwigType_istemplate(name)) { String *cname = NewString(name); String *dname = Swig_symbol_template_deftype(cname, 0); @@ -880,7 +884,7 @@ Node *Swig_symbol_add(const_String_or_char_ptr symname, Node *n) { /* Well, we made it this far. Guess we can drop the symbol in place */ Setattr(n, "sym:symtab", current_symtab); Setattr(n, "sym:name", symname); - /* Printf(stdout,"%s %x\n", Getattr(n,"sym:overname"), current_symtab); */ + /* Printf(stdout,"%s %p\n", Getattr(n,"sym:overname"), current_symtab); */ assert(!Getattr(n, "sym:overname")); overname = NewStringf("__SWIG_%d", pn); Setattr(n, "sym:overname", overname); @@ -927,7 +931,6 @@ static Node *_symbol_lookup(const String *name, Symtab *symtab, int (*check) (No return 0; Setmark(symtab, 1); - n = Getattr(sym, name); #ifdef SWIG_DEBUG @@ -1084,8 +1087,9 @@ static Node *symbol_lookup_qualified(const_String_or_char_ptr name, Symtab *symt * Swig_symbol_clookup() * * Look up a symbol in the symbol table. This uses the C name, not scripting - * names. Note: If we come across a using a directive, we follow it to - * to get the real node. + * names. Note: If we come across a using declaration, we follow it to + * to get the real node. Any using directives are also followed (but this is + * implemented in symbol_lookup()). * ----------------------------------------------------------------------------- */ Node *Swig_symbol_clookup(const_String_or_char_ptr name, Symtab *n) { @@ -1226,6 +1230,9 @@ Node *Swig_symbol_clookup_check(const_String_or_char_ptr name, Symtab *n, int (* /* ----------------------------------------------------------------------------- * Swig_symbol_clookup_local() + * + * Same as Swig_symbol_clookup but parent nodes are not searched, that is, just + * this symbol table is searched. * ----------------------------------------------------------------------------- */ Node *Swig_symbol_clookup_local(const_String_or_char_ptr name, Symtab *n) { @@ -1446,14 +1453,14 @@ Node *Swig_symbol_isoverloaded(Node *n) { } /* ----------------------------------------------------------------------------- - * Swig_symbol_type_qualify() + * symbol_template_qualify() * - * Create a fully qualified type name + * Internal function to create a fully qualified type name for templates * ----------------------------------------------------------------------------- */ /* This cache produces problems with OSS, don't active it */ /* #define SWIG_TEMPLATE_QUALIFY_CACHE */ -static SwigType *Swig_symbol_template_qualify(const SwigType *e, Symtab *st) { +static SwigType *symbol_template_qualify(const SwigType *e, Symtab *st) { String *tprefix, *tsuffix; SwigType *qprefix; List *targs; @@ -1518,10 +1525,16 @@ static SwigType *Swig_symbol_template_qualify(const SwigType *e, Symtab *st) { } -static int no_constructor(Node *n) { +static int symbol_no_constructor(Node *n) { return !Checkattr(n, "nodeType", "constructor"); } +/* ----------------------------------------------------------------------------- + * Swig_symbol_type_qualify() + * + * Create a fully qualified type name + * ----------------------------------------------------------------------------- */ + SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) { List *elements; String *result = NewStringEmpty(); @@ -1538,7 +1551,7 @@ SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) { for (i = 0; i < len; i++) { String *e = Getitem(elements, i); if (SwigType_issimple(e)) { - Node *n = Swig_symbol_clookup_check(e, st, no_constructor); + Node *n = Swig_symbol_clookup_check(e, st, symbol_no_constructor); if (n) { String *name = Getattr(n, "name"); Clear(e); @@ -1558,7 +1571,7 @@ SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) { Delete(qname); } } else if (SwigType_istemplate(e)) { - SwigType *ty = Swig_symbol_template_qualify(e, st); + SwigType *ty = symbol_template_qualify(e, st); Clear(e); Append(e, ty); Delete(ty); From 33926f12013336ba285a52e84802319abe283186 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 9 Jul 2012 20:06:09 +0000 Subject: [PATCH 0132/1160] Note lack of support for %shared_ptr and directors git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13308 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Library.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html index dcec21c90..1c7b84a1a 100644 --- a/Doc/Manual/Library.html +++ b/Doc/Manual/Library.html @@ -1871,6 +1871,8 @@ Adding the missing %shared_ptr macros will fix this:
  • +Note: There is currently no support for %shared_ptr and the director feature. +

    8.5 Utility Libraries

    From d1ae77bdc20845144b0cf9038cd7687ba270603f Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Thu, 12 Jul 2012 17:53:02 +0000 Subject: [PATCH 0133/1160] octave: use _Exit instead of _exit - _exit is a POSIX function (unistd.h), whereas _Exit is in C99 (stdlib.h) and is therefore more likely to be supported by C++ compilers (cstdlib) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13318 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/octruntime.swg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index 8c14bedfe..fbb1157b5 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -132,8 +132,9 @@ DEFUN_DLD( swig_this, args, nargout, swig_this_usage ) { #ifdef SWIG_OCTAVE_SEGFAULT_HACK #define _SWIG_OCT_SEGF_HACK_ATEXIT_FCN(NAME) SWIG_OCT_SEGF_HACK_ATEXIT_FCN_##NAME #define SWIG_OCT_SEGF_HACK_ATEXIT_FCN(NAME) _SWIG_OCT_SEGF_HACK_ATEXIT_FCN(NAME) +#include void SWIG_OCT_SEGF_HACK_ATEXIT_FCN(SWIG_name)(void) { - _exit(exit_status); + _Exit(exit_status); } #endif From ae0c4d37b9a91581f0fc56354c8a616325fac1ce Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Fri, 20 Jul 2012 07:31:32 +0000 Subject: [PATCH 0134/1160] octave: improved segfault-on-exit prevention hack - Now simply set exit function pointer "octave_exit" to _Exit. This correctly preserves exit status when error() is called. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13336 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/octruntime.swg | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index fbb1157b5..16ad3f7c9 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -1,4 +1,5 @@ %insert(runtime) %{ +#include #include #include #include @@ -120,24 +121,6 @@ DEFUN_DLD( swig_this, args, nargout, swig_this_usage ) { return octave_value(octave_uint64((unsigned long long) ost->swig_this())); } -// workaround to prevent octave seg-faulting on exit: register at-exit -// function which exits octave immediately without trying to cleanup memory. -// definitely affects version 3.2.*, not sure about 3.3.*, seems to be -// fixed in version 3.4.* and above. can be turned on/off with macros. -#ifndef SWIG_OCTAVE_NO_SEGFAULT_HACK -#if 36 < OCTAVE_API_VERSION_NUMBER && OCTAVE_API_VERSION_NUMBER < 45 -#define SWIG_OCTAVE_SEGFAULT_HACK -#endif -#endif -#ifdef SWIG_OCTAVE_SEGFAULT_HACK -#define _SWIG_OCT_SEGF_HACK_ATEXIT_FCN(NAME) SWIG_OCT_SEGF_HACK_ATEXIT_FCN_##NAME -#define SWIG_OCT_SEGF_HACK_ATEXIT_FCN(NAME) _SWIG_OCT_SEGF_HACK_ATEXIT_FCN(NAME) -#include -void SWIG_OCT_SEGF_HACK_ATEXIT_FCN(SWIG_name)(void) { - _Exit(exit_status); -} -#endif - static const char *const SWIG_name_usage = "-*- texinfo -*- \n\ @deftypefn {Loadable Module} {} " SWIG_name_d "\n\ Loads the SWIG-generated module `" SWIG_name_d "'.\n\ @@ -164,8 +147,14 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { // create module on first function call if (!module_ns) { -#ifdef SWIG_OCTAVE_SEGFAULT_HACK - atexit(SWIG_OCT_SEGF_HACK_ATEXIT_FCN(SWIG_name)); + // workaround to prevent octave seg-faulting on exit: set Octave exit function + // octave_exit to _Exit, which exits immediately without trying to cleanup memory. + // definitely affects version 3.2.*, not sure about 3.3.*, seems to be + // fixed in version 3.4.* and above. can be turned off with macro def. +#ifndef SWIG_OCTAVE_NO_SEGFAULT_HACK +#if 36 < OCTAVE_API_VERSION_NUMBER && OCTAVE_API_VERSION_NUMBER < 45 + octave_exit = ::_Exit; +#endif #endif // workaround bug in octave where installing global variable of custom type and then From 4ef525c713c81306bc3853331f175797d03b8850 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Fri, 20 Jul 2012 08:53:51 +0000 Subject: [PATCH 0135/1160] Updated changelog for previous 2 octave commits git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13337 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index ccf7a1e18..51dd78e10 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.8 (in progress) =========================== +2012-07-20: kwwette + [Octave] segfault-on-exit prevention hack now preserves exit status, and uses C99 _Exit(). + 2012-06-25: wsfulton Fix using declarations combined with using directives so that types are correctly found in scope. Example: From 4241dd1e93f21eccd531f3a53b90fa6f98368011 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 21 Jul 2012 06:58:28 +0000 Subject: [PATCH 0136/1160] Warning removal for autoconf 2.66 and later git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13338 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- configure.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.in b/configure.in index 69685e0ed..d04c76f6f 100644 --- a/configure.in +++ b/configure.in @@ -1236,16 +1236,16 @@ CFLAGS="`echo $CFLAGS | sed 's/-ansi//g;s/-pedantic//g;'` $GUILEINCLUDE" LIBS="$LIBS $GUILELINK" AC_MSG_CHECKING(whether Guile's gh_ API works) -AC_LINK_IFELSE([#include - int main() { SCM s; return gh_scm2int(s); }], GUILE_GH_INTERFACE=1, ) +AC_LINK_IFELSE([AC_LANG_SOURCE([#include + int main() { SCM s; return gh_scm2int(s); }])], GUILE_GH_INTERFACE=1, ) if test -n "$GUILE_GH_INTERFACE" ; then AC_MSG_RESULT(yes) else AC_MSG_RESULT(no) fi AC_MSG_CHECKING(whether Guile's SCM_ API works) -AC_LINK_IFELSE([#include - int main() { SCM s; scm_slot_exists_p(SCM_BOOL_F, SCM_BOOL_F); return SCM_STRING_LENGTH(s); }], GUILE_SCM_INTERFACE=1, ) +AC_LINK_IFELSE([AC_LANG_SOURCE([#include + int main() { SCM s; scm_slot_exists_p(SCM_BOOL_F, SCM_BOOL_F); return SCM_STRING_LENGTH(s); }])], GUILE_SCM_INTERFACE=1, ) if test -n "$GUILE_SCM_INTERFACE" ; then AC_MSG_RESULT(yes) else From 594fd2b41095ca1a22e809a0285d68a7fc9bdb38 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 21 Jul 2012 14:04:37 +0000 Subject: [PATCH 0137/1160] Fix gdb debugger functions to display to the gdb output window rather than stdout. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13339 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 +++++ Tools/swig.gdb | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 51dd78e10..143efc7eb 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.8 (in progress) =========================== +2012-06-27: wsfulton + Fix gdb debugger functions 'swigprint' and 'locswigprint' to display to the gdb output window + rather than stdout. This fixes display problems in gdbtui and the ensures the output + appears where expected in other gdb based debuggers such as Eclipse CDT. + 2012-07-20: kwwette [Octave] segfault-on-exit prevention hack now preserves exit status, and uses C99 _Exit(). diff --git a/Tools/swig.gdb b/Tools/swig.gdb index 195032955..61872c5d6 100644 --- a/Tools/swig.gdb +++ b/Tools/swig.gdb @@ -15,7 +15,7 @@ define swigprint else set $expand_count = -1 end - call Swig_print($arg0, $expand_count) + Printf "%s\n", Swig_to_string($arg0, $expand_count) end document swigprint Displays any SWIG DOH object @@ -31,7 +31,7 @@ define locswigprint else set $expand_count = -1 end - call Swig_print_with_location($arg0, $expand_count) + Printf "%s\n", Swig_to_string_with_location($arg0, $expand_count) end document locswigprint Displays any SWIG DOH object prefixed with file and line location From 7b58300cbdc98fa52c42572cffd3f31f10728864 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 21 Jul 2012 22:52:30 +0000 Subject: [PATCH 0138/1160] Fix display of pointers on 64 bit systems, only 32 bit values were being shown. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13340 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 ++ Source/CParse/parser.y | 2 +- Source/DOH/hash.c | 6 ++-- Source/DOH/list.c | 2 +- Source/Modules/allegrocl.cxx | 64 ++++++++++++++++++------------------ Source/Modules/browser.cxx | 32 +++++++++--------- Source/Modules/cffi.cxx | 2 +- Source/Modules/modula3.cxx | 2 +- Source/Modules/perl5.cxx | 2 +- Source/Modules/python.cxx | 2 +- Source/Modules/s-exp.cxx | 2 +- Source/Modules/xml.cxx | 20 +++++------ Source/Swig/symbol.c | 12 +++---- Source/Swig/tree.c | 2 +- Source/Swig/typesys.c | 14 ++++---- 15 files changed, 85 insertions(+), 82 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 143efc7eb..4b3a2679c 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.8 (in progress) =========================== +2012-06-27: wsfulton + Fix display of pointers in various places on 64 bit systems - only 32 bits were being shown. + 2012-06-27: wsfulton Fix gdb debugger functions 'swigprint' and 'locswigprint' to display to the gdb output window rather than stdout. This fixes display problems in gdbtui and the ensures the output diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index e2033f01b..27344598a 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2988,7 +2988,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va if (am) { Symtab *st = Swig_symbol_current(); Swig_symbol_setscope(Getattr(templnode,"symtab")); - /* Printf(stdout,"%s: %s %x %x\n", Getattr(templnode,"name"), clsname, Swig_symbol_current(), Getattr(templnode,"symtab")); */ + /* Printf(stdout,"%s: %s %p %p\n", Getattr(templnode,"name"), clsname, Swig_symbol_current(), Getattr(templnode,"symtab")); */ merge_extensions(templnode,am); Swig_symbol_setscope(st); append_previous_extension(templnode,am); diff --git a/Source/DOH/hash.c b/Source/DOH/hash.c index 241383327..566cb349a 100644 --- a/Source/DOH/hash.c +++ b/Source/DOH/hash.c @@ -415,12 +415,12 @@ static DOH *Hash_str(DOH *ho) { s = NewStringEmpty(); if (ObjGetMark(ho)) { - Printf(s, "Hash(0x%x)", ho); + Printf(s, "Hash(%p)", ho); return s; } if (expanded >= max_expand) { /* replace each hash attribute with a '.' */ - Printf(s, "Hash(0x%x) {", ho); + Printf(s, "Hash(%p) {", ho); for (i = 0; i < h->hashsize; i++) { n = h->hashtable[i]; while (n) { @@ -432,7 +432,7 @@ static DOH *Hash_str(DOH *ho) { return s; } ObjSetMark(ho, 1); - Printf(s, "Hash(0x%x) {\n", ho); + Printf(s, "Hash(%p) {\n", ho); for (i = 0; i < h->hashsize; i++) { n = h->hashtable[i]; while (n) { diff --git a/Source/DOH/list.c b/Source/DOH/list.c index d5b532409..d20311150 100644 --- a/Source/DOH/list.c +++ b/Source/DOH/list.c @@ -242,7 +242,7 @@ static DOH *List_str(DOH *lo) { List *l = (List *) ObjData(lo); s = NewStringEmpty(); if (ObjGetMark(lo)) { - Printf(s, "List(%x)", lo); + Printf(s, "List(%p)", lo); return s; } ObjSetMark(lo, 1); diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index 84644a61c..b6c5385fb 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -206,7 +206,7 @@ static String *namespace_of(String *str) { void add_linked_type(Node *n) { #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr, "Adding linked node of type: %s(%s) %s(%x)\n\n", nodeType(n), Getattr(n, "storage"), Getattr(n, "name"), n); + Printf(stderr, "Adding linked node of type: %s(%s) %s(%p)\n\n", nodeType(n), Getattr(n, "storage"), Getattr(n, "name"), n); // Swig_print_node(n); #endif if (!first_linked_type) { @@ -300,13 +300,13 @@ Node *get_primary_synonym_of(Node *n) { Node *p = Getattr(n, "allegrocl:synonym-of"); Node *prim = n; - // Printf(stderr, "getting primary synonym of %x\n", n); + // Printf(stderr, "getting primary synonym of %p\n", n); while (p) { - // Printf(stderr, " found one! %x\n", p); + // Printf(stderr, " found one! %p\n", p); prim = p; p = Getattr(p, "allegrocl:synonym-of"); } - // Printf(stderr,"get_primary_syn: DONE. returning %s(%x)\n", Getattr(prim,"name"),prim); + // Printf(stderr,"get_primary_syn: DONE. returning %s(%p)\n", Getattr(prim,"name"),prim); return prim; } @@ -331,7 +331,7 @@ void add_forward_referenced_type(Node *n, int overwrite = 0) { // , name); #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr, "Linking forward reference type = %s(%x)\n", k, n); + Printf(stderr, "Linking forward reference type = %s(%p)\n", k, n); #endif add_linked_type(n); } @@ -346,8 +346,8 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0, String *cDeclName = n ? Getattr(n, "name") : 0; #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr, "IN A-D-F-T. (n=%x, ow=%d, k=%s, name=%s, ns=%s\n", n, overwrite, k, name, ns); - Printf(stderr, " templated = '%x', classDecl = '%x'\n", templated, cDeclName); + Printf(stderr, "IN A-D-F-T. (n=%p, ow=%d, k=%s, name=%s, ns=%s\n", n, overwrite, k, name, ns); + Printf(stderr, " templated = '%p', classDecl = '%p'\n", templated, cDeclName); #endif if (n) { if (!name) @@ -456,7 +456,7 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0, } } #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr, "looking to add %s/%s(%x) to linked_type_list...\n", k, name, n); + Printf(stderr, "looking to add %s/%s(%p) to linked_type_list...\n", k, name, n); #endif if (is_fwd_ref) { // Printf(stderr,"*** 1\n"); @@ -509,7 +509,7 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0, Setattr(new_node, "allegrocl:synonym:is-primary", "1"); } else { // a synonym type was found (held in variable 'match') - // Printf(stderr, "setting primary synonym of %x to %x\n", new_node, match); + // Printf(stderr, "setting primary synonym of %p to %p\n", new_node, match); if (new_node == match) Printf(stderr, "Hey-4 * - '%s' is a synonym of iteself!\n", Getattr(new_node, "name")); Setattr(new_node, "allegrocl:synonym-of", match); @@ -556,8 +556,8 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0, Setattr(n, "allegrocl:synonym-of", match); Setattr(n, "real-name", Copy(lookup_type)); - // Printf(stderr, "*** pre-5: found match of '%s'(%x)\n", Getattr(match,"name"),match); - // if(n == match) Printf(stderr, "Hey-5 *** setting synonym of %x to %x\n", n, match); + // Printf(stderr, "*** pre-5: found match of '%s'(%p)\n", Getattr(match,"name"),match); + // if(n == match) Printf(stderr, "Hey-5 *** setting synonym of %p to %p\n", n, match); // Printf(stderr,"*** 5\n"); add_linked_type(n); } else { @@ -615,7 +615,7 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0, match = find_linked_type_by_name(resolved); if (!match) { #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr, "found no implicit instantiation of %%template node %s(%x)\n", Getattr(n, "name"), n); + Printf(stderr, "found no implicit instantiation of %%template node %s(%p)\n", Getattr(n, "name"), n); #endif add_linked_type(n); } else { @@ -624,14 +624,14 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0, Setattr(n, "allegrocl:synonym:is-primary", "1"); Delattr(primary, "allegrocl:synonym:is-primary"); if (n == match) - Printf(stderr, "Hey-7 * setting synonym of %x to %x\n (match = %x)", primary, n, match); + Printf(stderr, "Hey-7 * setting synonym of %p to %p\n (match = %p)", primary, n, match); Setattr(primary, "allegrocl:synonym-of", n); // Printf(stderr,"*** 7\n"); add_linked_type(n); } } else { #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr, "linking type '%s'(%x)\n", k, n); + Printf(stderr, "linking type '%s'(%p)\n", k, n); #endif // Printf(stderr,"*** 8\n"); add_linked_type(n); @@ -821,7 +821,7 @@ String *compose_foreign_type(Node *n, SwigType *ty, String * /*id*/ = 0) { Printf(stderr, "compose_foreign_type: ENTER (%s)...\n ", ty); // Printf(stderr, "compose_foreign_type: ENTER (%s)(%s)...\n ", ty, (id ? id : 0)); /* String *id_ref = SwigType_str(ty, id); - Printf(stderr, "looking up typemap for %s, found '%s'(%x)\n", + Printf(stderr, "looking up typemap for %s, found '%s'(%p)\n", id_ref, lookup_res ? Getattr(lookup_res, "code") : 0, lookup_res); if (lookup_res) Swig_print_node(lookup_res); */ @@ -860,7 +860,7 @@ void update_package_if_needed(Node *n, File *f = f_clwrap) { Printf(stderr, "update_package: ENTER... \n"); Printf(stderr, " current_package = '%s'\n", current_package); Printf(stderr, " node_package = '%s'\n", Getattr(n, "allegrocl:package")); - Printf(stderr, " node(%x) = '%s'\n", n, Getattr(n, "name")); + Printf(stderr, " node(%p) = '%s'\n", n, Getattr(n, "name")); #endif String *node_package = Getattr(n, "allegrocl:package"); if (Strcmp(current_package, node_package)) { @@ -1119,7 +1119,7 @@ String *convert_literal(String *literal, String *type, bool try_to_split) { void emit_stub_class(Node *n) { #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr, "emit_stub_class: ENTER... '%s'(%x)\n", Getattr(n, "sym:name"), n); + Printf(stderr, "emit_stub_class: ENTER... '%s'(%p)\n", Getattr(n, "sym:name"), n); Swig_print_node(n); #endif @@ -1157,7 +1157,7 @@ void emit_synonym(Node *synonym) { Printf(stderr, "emit_synonym: ENTER... \n"); #endif - // Printf(stderr,"in emit_synonym for %s(%x)\n", Getattr(synonym,"name"),synonym); + // Printf(stderr,"in emit_synonym for %s(%p)\n", Getattr(synonym,"name"),synonym); int is_tempInst = !Strcmp(nodeType(synonym), "templateInst"); String *synonym_type; @@ -1214,7 +1214,7 @@ void emit_full_class(Node *n) { String *name = Getattr(n, "sym:name"); String *kind = Getattr(n, "kind"); - // Printf(stderr,"in emit_full_class: '%s'(%x).", Getattr(n,"name"),n); + // Printf(stderr,"in emit_full_class: '%s'(%p).", Getattr(n,"name"),n); if (Getattr(n, "allegrocl:synonym-of")) { // Printf(stderr,"but it's a synonym of something.\n"); update_package_if_needed(n, f_clhead); @@ -1314,7 +1314,7 @@ void emit_full_class(Node *n) { void emit_class(Node *n) { #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr, "emit_class: ENTER... '%s'(%x)\n", Getattr(n, "sym:name"), n); + Printf(stderr, "emit_class: ENTER... '%s'(%p)\n", Getattr(n, "sym:name"), n); #endif int is_tempInst = !Strcmp(nodeType(n), "templateInst"); @@ -1373,7 +1373,7 @@ void emit_typedef(Node *n) { Delete(type); Node *in_class = Getattr(n, "allegrocl:typedef:in-class"); - // Printf(stderr,"in emit_typedef: '%s'(%x).",Getattr(n,"name"),n); + // Printf(stderr,"in emit_typedef: '%s'(%p).",Getattr(n,"name"),n); if (Getattr(n, "allegrocl:synonym-of")) { // Printf(stderr," but it's a synonym of something.\n"); emit_synonym(n); @@ -1536,11 +1536,11 @@ void dump_linked_types(File *f) { Node *n = first_linked_type; int i = 0; while (n) { - Printf(f, "%d: (%x) node '%s' name '%s'\n", i++, n, nodeType(n), Getattr(n, "sym:name")); + Printf(f, "%d: (%p) node '%s' name '%s'\n", i++, n, nodeType(n), Getattr(n, "sym:name")); Node *t = Getattr(n, "allegrocl:synonym-of"); if (t) - Printf(f, " synonym-of %s(%x)\n", Getattr(t, "name"), t); + Printf(f, " synonym-of %s(%p)\n", Getattr(t, "name"), t); n = Getattr(n, "allegrocl:next_linked_type"); } } @@ -1556,7 +1556,7 @@ void emit_linked_types() { while (n) { String *node_type = nodeType(n); - // Printf(stderr,"emitting node %s(%x) of type %s.", Getattr(n,"name"),n, nodeType(n)); + // Printf(stderr,"emitting node %s(%p) of type %s.", Getattr(n,"name"),n, nodeType(n)); if (!Strcmp(node_type, "class") || !Strcmp(node_type, "templateInst")) { // may need to emit a stub, so it will update the package itself. // Printf(stderr," Passing to emit_class."); @@ -2049,7 +2049,7 @@ int emit_num_lin_arguments(ParmList *parms) { int nargs = 0; while (p) { - // Printf(stderr,"enla: '%s' lin='%x' numinputs='%s'\n", Getattr(p,"name"), Getattr(p,"tmap:lin"), Getattr(p,"tmap:lin:numinputs")); + // Printf(stderr,"enla: '%s' lin='%p' numinputs='%s'\n", Getattr(p,"name"), Getattr(p,"tmap:lin"), Getattr(p,"tmap:lin:numinputs")); if (Getattr(p, "tmap:lin")) { nargs += GetInt(p, "tmap:lin:numinputs"); p = Getattr(p, "tmap:lin:next"); @@ -2283,7 +2283,7 @@ IDargs *id_converter_arguments(Node *n) { result->arity = NewStringf("%d", // emit_num_arguments(Getattr(n, "wrap:parms"))); emit_num_lin_arguments(Getattr(n, "wrap:parms"))); - // Printf(stderr, "got arity of '%s' node '%s' '%x'\n", result->arity, Getattr(n,"name"), Getattr(n,"wrap:parms")); + // Printf(stderr, "got arity of '%s' node '%s' '%p'\n", result->arity, Getattr(n,"name"), Getattr(n,"wrap:parms")); } SetVoid(n, "allegrocl:id-converter-args", result); @@ -2361,7 +2361,7 @@ int ALLEGROCL::emit_dispatch_defun(Node *n) { #endif List *overloads = Swig_overload_rank(n, true); - // Printf(stderr,"\ndispatch node=%x\n\n", n); + // Printf(stderr,"\ndispatch node=%p\n\n", n); // Swig_print_node(n); Node *overloaded_from = Getattr(n,"sym:overloaded"); @@ -2669,7 +2669,7 @@ int ALLEGROCL::functionWrapper(Node *n) { if (Getattr(n, "overload:ignore")) { // if we're the last overload, make sure to force the emit // of the rest of the overloads before we leave. - // Printf(stderr, "ignored overload %s(%x)\n", name, Getattr(n, "sym:nextSibling")); + // Printf(stderr, "ignored overload %s(%p)\n", name, Getattr(n, "sym:nextSibling")); if (!Getattr(n, "sym:nextSibling")) { update_package_if_needed(n); emit_buffered_defuns(n); @@ -2798,7 +2798,7 @@ int ALLEGROCL::functionWrapper(Node *n) { int ALLEGROCL::namespaceDeclaration(Node *n) { #ifdef ALLEGROCL_DEBUG - Printf(stderr, "namespaceDecl: '%s'(0x%x) (fc=0x%x)\n", Getattr(n, "sym:name"), n, firstChild(n)); + Printf(stderr, "namespaceDecl: '%s'(%p) (fc=%p)\n", Getattr(n, "sym:name"), n, firstChild(n)); #endif /* don't wrap a namespace with no contents. package bloat. @@ -3018,7 +3018,7 @@ int ALLEGROCL::typedefHandler(Node *n) { if (in_class) { #ifdef ALLEGROCL_TYPE_DEBUG - Printf(stderr, " typedef in class '%s'(%x)\n", Getattr(in_class, "sym:name"), in_class); + Printf(stderr, " typedef in class '%s'(%p)\n", Getattr(in_class, "sym:name"), in_class); #endif Setattr(n, "allegrocl:typedef:in-class", in_class); @@ -3036,7 +3036,7 @@ int ALLEGROCL::typedefHandler(Node *n) { String *lookup = lookup_defined_foreign_type(typedef_type); #ifdef ALLEGROCL_TYPE_DEBUG - Printf(stderr, "** lookup='%s'(%x), typedef_type='%s', strcmp = '%d' strstr = '%d'\n", lookup, lookup, typedef_type, Strcmp(typedef_type,"void"), Strstr(ff_type,"__SWIGACL_FwdReference")); + Printf(stderr, "** lookup='%s'(%p), typedef_type='%s', strcmp = '%d' strstr = '%d'\n", lookup, lookup, typedef_type, Strcmp(typedef_type,"void"), Strstr(ff_type,"__SWIGACL_FwdReference")); #endif if(lookup || (!lookup && Strcmp(typedef_type,"void")) || @@ -3162,7 +3162,7 @@ int ALLEGROCL::cppClassHandler(Node *n) { SwigType *childType = NewStringf("%s%s", Getattr(c, "decl"), Getattr(c, "type")); #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr, "looking at child '%x' of type '%s' '%d'\n", c, childType, SwigType_isfunction(childType)); + Printf(stderr, "looking at child '%p' of type '%s' '%d'\n", c, childType, SwigType_isfunction(childType)); // Swig_print_node(c); #endif if (!SwigType_isfunction(childType)) diff --git a/Source/Modules/browser.cxx b/Source/Modules/browser.cxx index 592e12783..b1365c0b4 100644 --- a/Source/Modules/browser.cxx +++ b/Source/Modules/browser.cxx @@ -29,9 +29,9 @@ class Browser:public Dispatcher { v = 1; } if (v) { - Printf(out, "[-] ", n, t, n, n); + Printf(out, "[-] ", n, t, n, n); } else { - Printf(out, "[+] ", n, t, n, n); + Printf(out, "[+] ", n, t, n, n); } } void show_attributes(Node *obj) { @@ -52,7 +52,7 @@ class Browser:public Dispatcher { Replaceall(o, "&", "&"); Replaceall(o, "<", "<"); Replaceall(o, ">", ">"); - Printf(os, "? %-12s - %s\n", Getattr(obj, k), k, o); + Printf(os, "? %-12s - %s\n", Getattr(obj, k), k, o); Delete(o); } else { DOH *o; @@ -64,10 +64,10 @@ class Browser:public Dispatcher { } Replaceall(o, "&", "&"); Replaceall(o, "<", "<"); - Printf(os, "? %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc); + Printf(os, "? %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc); Delete(o); } else { - Printf(os, "? %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k)); + Printf(os, "? %-12s - %p\n", Getattr(obj, k), k, Getattr(obj, k)); } } ki = Next(ki); @@ -84,7 +84,7 @@ public: char *name = GetChar(n, "name"); show_checkbox(view_top, n); - Printf(out, "%s", n, tag); + Printf(out, "%s", n, tag); if (name) { Printf(out, " (%s)", name); } @@ -184,9 +184,9 @@ static void display(FILE *f, Node *n) { Printf(f, "SWIG-%s\n", Swig_package_version()); Printf(f, "SWIG-%s
    \n", Swig_package_version()); Printf(f, "[ Exit ]"); - Printf(f, " [ Top ]", tree_top); + Printf(f, " [ Top ]", tree_top); if (n != tree_top) { - Printf(f, " [ Up ]", parentNode(n)); + Printf(f, " [ Up ]", parentNode(n)); } Printf(f, " [ Symbols ]"); Printf(f, "

    \n"); @@ -255,10 +255,10 @@ void raw_data(FILE *out, Node *obj) { trunc = "..."; } Replaceall(o, "<", "<"); - Printf(os, " ? %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc); + Printf(os, " ? %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc); Delete(o); } else { - Printf(os, " ? %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k)); + Printf(os, " ? %-12s - %p\n", Getattr(obj, k), k, Getattr(obj, k)); } ki = Next(ki); } @@ -283,10 +283,10 @@ void raw_data(FILE *out, Node *obj) { trunc = "..."; } Replaceall(o, "<", "<"); - Printf(os, " ? [%d] - \"%(escape)-0.70s%s\"\n", o, i, s, trunc); + Printf(os, " ? [%d] - \"%(escape)-0.70s%s\"\n", o, i, s, trunc); Delete(s); } else { - Printf(os, " ? [%d] - 0x%x\n", o, i, o); + Printf(os, " ? [%d] - %p\n", o, i, o); } } Printf(os, "\n]\n"); @@ -303,7 +303,7 @@ void data_handler(FILE *f) { Printf(f, "SWIG-%s\n", Swig_package_version()); Printf(f, "SWIG-%s
    \n", Swig_package_version()); Printf(f, "[ Exit ]"); - Printf(f, " [ Top ]", tree_top); + Printf(f, " [ Top ]", tree_top); Printf(f, "


    \n"); if (n) { raw_data(f, n); @@ -319,7 +319,7 @@ void symbol_handler(FILE *f) { Printf(f, "SWIG-%s\n", Swig_package_version()); Printf(f, "SWIG-%s
    \n", Swig_package_version()); Printf(f, "[ Exit ]"); - Printf(f, " [ Top ]", tree_top); + Printf(f, " [ Top ]", tree_top); Printf(f, " [ Symbols ]"); Printf(f, "


    \n"); @@ -343,7 +343,7 @@ void symbol_handler(FILE *f) { fprintf(f, "

    \n"); fprintf(f, "Symbol lookup:
    \n"); - fprintf(f, "\n", sym); + fprintf(f, "\n", sym); fprintf(f, "Submit : \n"); fprintf(f, "
    "); @@ -365,7 +365,7 @@ void symbol_handler(FILE *f) { Hash *h; h = firstChild(sym); while (h) { - Printf(f, "%s\n", h, Getattr(h, "name")); + Printf(f, "%s\n", h, Getattr(h, "name")); h = nextSibling(h); } } diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx index f2cce4fef..2bb95188b 100644 --- a/Source/Modules/cffi.cxx +++ b/Source/Modules/cffi.cxx @@ -671,7 +671,7 @@ int CFFI::enumDeclaration(Node *n) { void CFFI::emit_class(Node *n) { #ifdef CFFI_WRAP_DEBUG - Printf(stderr, "emit_class: ENTER... '%s'(%x)\n", Getattr(n, "sym:name"), n); + Printf(stderr, "emit_class: ENTER... '%s'(%p)\n", Getattr(n, "sym:name"), n); #endif String *name = Getattr(n, "sym:name"); diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index 19a02cbbc..bcb99e46a 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -2030,7 +2030,7 @@ MODULA3(): if (oldname != NIL) { Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "The value <%s> is already assigned to <%s>.\n", value, oldname); } -//printf("items %lx, set %s = %s\n", (long) items, Char(newvalue), Char(m3name)); +//printf("items %p, set %s = %s\n", items, Char(newvalue), Char(m3name)); Setattr(items, newvalue, m3name); if (max < numvalue) { max = numvalue; diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 00a66b801..077b5fe83 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -132,7 +132,7 @@ public: Node *is_shadow(SwigType *t) { Node *n; n = classLookup(t); - /* Printf(stdout,"'%s' --> '%x'\n", t, n); */ + /* Printf(stdout,"'%s' --> '%p'\n", t, n); */ if (n) { if (!Getattr(n, "perl5:proxy")) { setclassname(n); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index c762fb93c..c180b4a79 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -3809,7 +3809,7 @@ public: if (new_repr) { Printv(f_shadow_file, tab4, "__repr__ = _swig_repr\n", NIL); } else { - Printv(f_shadow_file, tab4, "def __repr__(self):\n", tab8, "return \"\" % (self.this,)\n", NIL); + Printv(f_shadow_file, tab4, "def __repr__(self):\n", tab8, "return \"\" % (self.this,)\n", NIL); } Delete(rname); } diff --git a/Source/Modules/s-exp.cxx b/Source/Modules/s-exp.cxx index 62b93f7c7..9f2cda2f2 100644 --- a/Source/Modules/s-exp.cxx +++ b/Source/Modules/s-exp.cxx @@ -310,7 +310,7 @@ public: close_paren(); } else { // What is it? - Printf(out, "#", ObjType(obj)->objname, obj); + Printf(out, "#", ObjType(obj)->objname, obj); } } } diff --git a/Source/Modules/xml.cxx b/Source/Modules/xml.cxx index 438205f68..4bd524815 100644 --- a/Source/Modules/xml.cxx +++ b/Source/Modules/xml.cxx @@ -118,7 +118,7 @@ public: String *k; indent_level += 4; print_indent(0); - Printf(out, "\n", ++id, obj); + Printf(out, "\n", ++id, obj); indent_level += 4; Iterator ki; ki = First(obj); @@ -160,14 +160,14 @@ public: Replaceall(o, "\"", """); Replaceall(o, "\\", "\\\\"); Replaceall(o, "\n", " "); - Printf(out, "\n", ck, o, ++id, o); + Printf(out, "\n", ck, o, ++id, o); Delete(o); Delete(ck); } else { o = Getattr(obj, k); String *ck = NewString(k); Replaceall(ck, ":", "_"); - Printf(out, "\n", ck, o, ++id, o); + Printf(out, "\n", ck, o, ++id, o); Delete(ck); } } @@ -183,7 +183,7 @@ public: Node *cobj; print_indent(0); - Printf(out, "<%s id=\"%ld\" addr=\"%x\" >\n", nodeType(obj), ++id, obj); + Printf(out, "<%s id=\"%ld\" addr=\"%p\" >\n", nodeType(obj), ++id, obj); Xml_print_attributes(obj); cobj = firstChild(obj); if (cobj) { @@ -203,7 +203,7 @@ public: void Xml_print_parmlist(ParmList *p, const char* markup = "parmlist") { print_indent(0); - Printf(out, "<%s id=\"%ld\" addr=\"%x\" >\n", markup, ++id, p); + Printf(out, "<%s id=\"%ld\" addr=\"%p\" >\n", markup, ++id, p); indent_level += 4; while (p) { print_indent(0); @@ -221,13 +221,13 @@ public: void Xml_print_baselist(List *p) { print_indent(0); - Printf(out, "\n", ++id, p); + Printf(out, "\n", ++id, p); indent_level += 4; Iterator s; for (s = First(p); s.item; s = Next(s)) { print_indent(0); String *item_name = Xml_escape_string(s.item); - Printf(out, "\n", item_name, ++id, s.item); + Printf(out, "\n", item_name, ++id, s.item); Delete(item_name); } indent_level -= 4; @@ -251,7 +251,7 @@ public: void Xml_print_module(Node *p) { print_indent(0); - Printf(out, "\n", Getattr(p, "name"), ++id, p); + Printf(out, "\n", Getattr(p, "name"), ++id, p); } void Xml_print_kwargs(Hash *p) { @@ -272,13 +272,13 @@ public: void Xml_print_hash(Hash *p, const char *markup) { print_indent(0); - Printf(out, "<%s id=\"%ld\" addr=\"%x\" >\n", markup, ++id, p); + Printf(out, "<%s id=\"%ld\" addr=\"%p\" >\n", markup, ++id, p); Xml_print_attributes(p); indent_level += 4; Iterator n = First(p); while (n.key) { print_indent(0); - Printf(out, "<%ssitem id=\"%ld\" addr=\"%x\" >\n", markup, ++id, n.item); + Printf(out, "<%ssitem id=\"%ld\" addr=\"%p\" >\n", markup, ++id, n.item); Xml_print_attributes(n.item); print_indent(0); Printf(out, "\n", markup); diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index 739767558..0cf6cdb53 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -549,7 +549,7 @@ void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) { Delete(cname); } #ifdef SWIG_DEBUG - Printf(stderr, "symbol_cadd %s %x\n", name, n); + Printf(stderr, "symbol_cadd %s %p\n", name, n); #endif cn = Getattr(ccurrent, name); @@ -934,7 +934,7 @@ static Node *_symbol_lookup(const String *name, Symtab *symtab, int (*check) (No n = Getattr(sym, name); #ifdef SWIG_DEBUG - Printf(stderr, "symbol_look %s %x %x %s\n", name, n, symtab, Getattr(symtab, "name")); + Printf(stderr, "symbol_look %s %p %p %s\n", name, n, symtab, Getattr(symtab, "name")); #endif if (n) { @@ -1437,7 +1437,7 @@ String *Swig_symbol_qualified(Node *n) { if (!symtab) return NewStringEmpty(); #ifdef SWIG_DEBUG - Printf(stderr, "symbol_qscope %s %x %s\n", Getattr(n, "name"), symtab, Getattr(symtab, "name")); + Printf(stderr, "symbol_qscope %s %p %s\n", Getattr(n, "name"), symtab, Getattr(symtab, "name")); #endif return Swig_symbol_qualifiedscopename(symtab); } @@ -1557,7 +1557,7 @@ SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) { Clear(e); Append(e, name); #ifdef SWIG_DEBUG - Printf(stderr, "symbol_qual_ei %d %s %s %x\n", i, name, e, st); + Printf(stderr, "symbol_qual_ei %d %s %s %p\n", i, name, e, st); #endif if (!Swig_scopename_check(name)) { String *qname = Swig_symbol_qualified(n); @@ -1566,7 +1566,7 @@ SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) { Insert(e, 0, qname); } #ifdef SWIG_DEBUG - Printf(stderr, "symbol_qual_sc %d %s %s %x\n", i, qname, e, st); + Printf(stderr, "symbol_qual_sc %d %s %s %p\n", i, qname, e, st); #endif Delete(qname); } @@ -1604,7 +1604,7 @@ SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) { } Delete(elements); #ifdef SWIG_DEBUG - Printf(stderr, "symbol_qualify %s %s %x %s\n", t, result, st, st ? Getattr(st, "name") : 0); + Printf(stderr, "symbol_qualify %s %s %p %s\n", t, result, st, st ? Getattr(st, "name") : 0); #endif return result; diff --git a/Source/Swig/tree.c b/Source/Swig/tree.c index 265f5a12e..af22da156 100644 --- a/Source/Swig/tree.c +++ b/Source/Swig/tree.c @@ -92,7 +92,7 @@ void Swig_print_node(Node *obj) { Printf(stdout, "%-12s - \"%(escape)-0.80s%s\"\n", k, o, trunc); Delete(o); } else { - Printf(stdout, "%-12s - 0x%x\n", k, Getattr(obj, k)); + Printf(stdout, "%-12s - %p\n", k, Getattr(obj, k)); } } ki = Next(ki); diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index a6b23a225..ab6475b9c 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -297,7 +297,7 @@ void SwigType_inherit_scope(Typetab *scope) { void SwigType_scope_alias(String *aliasname, Typetab *ttab) { String *q; - /* Printf(stdout,"alias: '%s' '%x'\n", aliasname, ttab); */ + /* Printf(stdout,"alias: '%s' '%p'\n", aliasname, ttab); */ q = SwigType_scope_name(current_scope); if (Len(q)) { Append(q, "::"); @@ -398,13 +398,13 @@ void SwigType_print_scope(void) { Printf(stdout, "-------------------------------------------------------------\n"); ttab = Getattr(i.item, "typetab"); - Printf(stdout, "Type scope '%s' (%x)\n", i.key, i.item); + Printf(stdout, "Type scope '%s' (%p)\n", i.key, i.item); { List *inherit = Getattr(i.item, "inherit"); if (inherit) { Iterator j; for (j = First(inherit); j.item; j = Next(j)) { - Printf(stdout, " Inherits from '%s' (%x)\n", Getattr(j.item, "qname"), j.item); + Printf(stdout, " Inherits from '%s' (%p)\n", Getattr(j.item, "qname"), j.item); } } } @@ -1114,14 +1114,14 @@ int SwigType_typedef_using(const_String_or_char_ptr name) { /* See if the using name is a scope */ /* tt = SwigType_find_scope(current_scope,name); - Printf(stdout,"tt = %x, name = '%s'\n", tt, name); */ + Printf(stdout,"tt = %p, name = '%s'\n", tt, name); */ /* We set up a typedef B --> A::B */ Setattr(current_typetab, base, name); /* Find the scope name where the symbol is defined */ td = SwigType_typedef_resolve(name); - /* Printf(stdout,"td = '%s' %x\n", td, resolved_scope); */ + /* Printf(stdout,"td = '%s' %p\n", td, resolved_scope); */ if (resolved_scope) { defined_name = Getattr(resolved_scope, "qname"); if (defined_name) { @@ -1803,13 +1803,13 @@ void SwigType_inherit_equiv(File *out) { Append(rlist, ck.key); } /* Printf(stdout,"rk.key = '%s'\n", rk.key); - Printf(stdout,"rh = %x '%s'\n", rh,rh); */ + Printf(stdout,"rh = %p '%s'\n", rh,rh); */ bk = First(sub); while (bk.key) { prefix = SwigType_prefix(rk.key); Append(prefix, bk.key); - /* Printf(stdout,"set %x = '%s' : '%s'\n", rh, SwigType_manglestr(prefix),prefix); */ + /* Printf(stdout,"set %p = '%s' : '%s'\n", rh, SwigType_manglestr(prefix),prefix); */ mprefix = SwigType_manglestr(prefix); Setattr(rh, mprefix, prefix); mkey = SwigType_manglestr(rk.key); From 1e1c0ad951588872404853b1742d0e69f2eb504a Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 24 Jul 2012 05:43:39 +0000 Subject: [PATCH 0139/1160] Fix Go -package option. Previously SWIG could get confused if the module name was not the same as the package name, as is the default. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13395 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/go.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 47bfc4ea1..39b4d261a 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -18,6 +18,8 @@ class GO:public Language { // Go package name. String *package; + // SWIG module name. + String *module; // Flag for generating gccgo output. bool gccgo_flag; // Prefix to use with gccgo. @@ -81,6 +83,7 @@ class GO:public Language { public: GO():package(NULL), + module(NULL), gccgo_flag(false), go_prefix(NULL), soname(NULL), @@ -235,7 +238,7 @@ private: allow_allprotected(GetFlag(optionsnode, "allprotected")); } - String *module = Getattr(n, "name"); + module = Getattr(n, "name"); if (!package) { package = Copy(module); } @@ -4397,7 +4400,7 @@ private: ret = exportedName(ret); Node *cnmod = Getattr(cn, "module"); - if (!cnmod || Strcmp(Getattr(cnmod, "name"), package) == 0) { + if (!cnmod || Strcmp(Getattr(cnmod, "name"), module) == 0) { Setattr(undefined_types, t, t); } else { String *nw = NewString(""); @@ -4579,7 +4582,7 @@ private: } ex = exportedName(cname); Node *cnmod = Getattr(cn, "module"); - if (!cnmod || Strcmp(Getattr(cnmod, "name"), package) == 0) { + if (!cnmod || Strcmp(Getattr(cnmod, "name"), module) == 0) { if (add_to_hash) { Setattr(undefined_types, ty, ty); } From 6e6ce16e4e08bae2b03d4fef30605cfc0337d65c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 4 Aug 2012 20:23:07 +0000 Subject: [PATCH 0140/1160] Fix using declarations combined with using directives with forward class references. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13502 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 42 ++++++ Examples/test-suite/common.mk | 2 + .../namespace_forward_declaration_runme.java | 26 ++++ ...rective_and_declaration_forward_runme.java | 53 ++++++++ ...using_directive_and_declaration_runme.java | 1 + .../namespace_forward_declaration.i | 35 +++++ .../using_directive_and_declaration.i | 21 +++ .../using_directive_and_declaration_forward.i | 124 ++++++++++++++++++ Source/CParse/parser.y | 82 ++++++++++-- Source/Swig/swig.h | 1 + Source/Swig/symbol.c | 17 ++- 11 files changed, 388 insertions(+), 16 deletions(-) create mode 100644 Examples/test-suite/java/namespace_forward_declaration_runme.java create mode 100644 Examples/test-suite/java/using_directive_and_declaration_forward_runme.java create mode 100644 Examples/test-suite/namespace_forward_declaration.i create mode 100644 Examples/test-suite/using_directive_and_declaration_forward.i diff --git a/CHANGES.current b/CHANGES.current index 4b3a2679c..663f2c451 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,7 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.8 (in progress) =========================== + 2012-06-27: wsfulton Fix display of pointers in various places on 64 bit systems - only 32 bits were being shown. @@ -15,6 +16,45 @@ Version 2.0.8 (in progress) 2012-07-20: kwwette [Octave] segfault-on-exit prevention hack now preserves exit status, and uses C99 _Exit(). +2012-06-30: wsfulton + Fix namespace problems for symbols declared with a forward class declarations, such as: + + namespace Space1 { + namespace Space2 { + struct XXX; + struct YYY; + } + + struct Space2::YYY {}; + struct Space1::Space2::XXX {}; + + void testXXX2(Space2::XXX xx) {} + void testYYY2(Space2::YYY yy) {} + } + + where xx and yy were not recognised as the proxy classes XXX and YYY. + +2012-06-30: wsfulton + Fix using declarations combined with using directives with forward class declarations so that + types are correctly found in scope. + + namespace Outer2 { + namespace Space2 { + class Thing2; + } + } + using namespace Outer2; + using Space2::Thing2; + class Thing2 {}; + // None of the methods below correctly used the Thing2 proxy class + void useit2(Thing2 t) {} + void useit2a(Outer2::Space2::Thing2 t) {} + void useit2b(::Outer2::Space2::Thing2 t) {} + void useit2c(Space2::Thing2 t) {} + namespace Outer2 { + void useit2d(Space2::Thing2 t) {} + } + 2012-06-25: wsfulton Fix using declarations combined with using directives so that types are correctly found in scope. Example: @@ -28,6 +68,8 @@ Version 2.0.8 (in progress) using Space2::Thing2; // using declaration void useit2(Thing2 t) {} + Similarly for templated classes. + 2012-05-29: wsfulton Fix #3529601 - seg fault when a protected method has the "director" feature but the parent class does not. Also fix similar problems with diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index fd7ecb1f3..db13a9fbe 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -257,6 +257,7 @@ CPP_TEST_CASES += \ namespace_class \ namespace_enum \ namespace_extend \ + namespace_forward_declaration \ namespace_nested \ namespace_spaces \ namespace_template \ @@ -443,6 +444,7 @@ CPP_TEST_CASES += \ using2 \ using_composition \ using_directive_and_declaration \ + using_directive_and_declaration_forward \ using_extend \ using_inherit \ using_namespace \ diff --git a/Examples/test-suite/java/namespace_forward_declaration_runme.java b/Examples/test-suite/java/namespace_forward_declaration_runme.java new file mode 100644 index 000000000..c603ebacf --- /dev/null +++ b/Examples/test-suite/java/namespace_forward_declaration_runme.java @@ -0,0 +1,26 @@ + +import namespace_forward_declaration.*; + +public class namespace_forward_declaration_runme { + + static { + try { + System.loadLibrary("namespace_forward_declaration"); + } 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[]) { + XXX xxx = new XXX(); + namespace_forward_declaration.testXXX1(xxx); + namespace_forward_declaration.testXXX2(xxx); + namespace_forward_declaration.testXXX3(xxx); + YYY yyy = new YYY(); + namespace_forward_declaration.testYYY1(yyy); + namespace_forward_declaration.testYYY2(yyy); + namespace_forward_declaration.testYYY3(yyy); + } +} + diff --git a/Examples/test-suite/java/using_directive_and_declaration_forward_runme.java b/Examples/test-suite/java/using_directive_and_declaration_forward_runme.java new file mode 100644 index 000000000..916aeb703 --- /dev/null +++ b/Examples/test-suite/java/using_directive_and_declaration_forward_runme.java @@ -0,0 +1,53 @@ + +import using_directive_and_declaration_forward.*; + +public class using_directive_and_declaration_forward_runme { + + static { + try { + System.loadLibrary("using_directive_and_declaration_forward"); + } 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[]) + { + using_directive_and_declaration_forward.useit1(new Thing1()); + using_directive_and_declaration_forward.useit1a(new Thing1()); + using_directive_and_declaration_forward.useit1b(new Thing1()); + using_directive_and_declaration_forward.useit1c(new Thing1()); + + using_directive_and_declaration_forward.useit2(new Thing2()); + using_directive_and_declaration_forward.useit2a(new Thing2()); + using_directive_and_declaration_forward.useit2b(new Thing2()); + using_directive_and_declaration_forward.useit2c(new Thing2()); + using_directive_and_declaration_forward.useit2d(new Thing2()); + + using_directive_and_declaration_forward.useit3(new Thing3()); + using_directive_and_declaration_forward.useit3a(new Thing3()); + using_directive_and_declaration_forward.useit3b(new Thing3()); + using_directive_and_declaration_forward.useit3c(new Thing3()); + using_directive_and_declaration_forward.useit3d(new Thing3()); + + using_directive_and_declaration_forward.useit4(new Thing4()); + using_directive_and_declaration_forward.useit4a(new Thing4()); + using_directive_and_declaration_forward.useit4b(new Thing4()); + using_directive_and_declaration_forward.useit4c(new Thing4()); + using_directive_and_declaration_forward.useit4d(new Thing4()); + + using_directive_and_declaration_forward.useit5(new Thing5()); + using_directive_and_declaration_forward.useit5a(new Thing5()); + using_directive_and_declaration_forward.useit5b(new Thing5()); + using_directive_and_declaration_forward.useit5c(new Thing5()); + using_directive_and_declaration_forward.useit5d(new Thing5()); + + + using_directive_and_declaration_forward.useit7(new Thing7()); + using_directive_and_declaration_forward.useit7a(new Thing7()); + using_directive_and_declaration_forward.useit7b(new Thing7()); + using_directive_and_declaration_forward.useit7c(new Thing7()); + using_directive_and_declaration_forward.useit7d(new Thing7()); + } +} diff --git a/Examples/test-suite/java/using_directive_and_declaration_runme.java b/Examples/test-suite/java/using_directive_and_declaration_runme.java index 2be189dd5..29e0fd2c9 100644 --- a/Examples/test-suite/java/using_directive_and_declaration_runme.java +++ b/Examples/test-suite/java/using_directive_and_declaration_runme.java @@ -24,5 +24,6 @@ public class using_directive_and_declaration_runme { Thing6 t6b = new Thing6(); t6b.b(); using_directive_and_declaration.useit6(t6a, t6b); + using_directive_and_declaration.useit7(new Thing7()); } } diff --git a/Examples/test-suite/namespace_forward_declaration.i b/Examples/test-suite/namespace_forward_declaration.i new file mode 100644 index 000000000..ad7c48d86 --- /dev/null +++ b/Examples/test-suite/namespace_forward_declaration.i @@ -0,0 +1,35 @@ +%module namespace_forward_declaration + +%inline %{ + namespace Space1 { + namespace Space2 { + struct XXX; + struct YYY; + } + + struct Space2::YYY { + int yyy(int h) { + return h; + } + }; + struct Space1::Space2::XXX { + int xxx(int h) { + return h; + } + }; + + void testXXX1(Space1::Space2::XXX xx) { + } + void testXXX2(Space2::XXX xx) { + } + void testXXX3(::Space1::Space2::XXX xx) { + } + void testYYY1(Space1::Space2::YYY yy) { + } + void testYYY2(Space2::YYY yy) { + } + void testYYY3(::Space1::Space2::YYY yy) { + } + } +%} + diff --git a/Examples/test-suite/using_directive_and_declaration.i b/Examples/test-suite/using_directive_and_declaration.i index 7196d39f1..27c7f199c 100644 --- a/Examples/test-suite/using_directive_and_declaration.i +++ b/Examples/test-suite/using_directive_and_declaration.i @@ -81,5 +81,26 @@ namespace Outer6 { } using namespace Outer6::Space6b; void useit6(Outer6::Space6a::Thing6 ta, Thing6 tb) {} + +namespace Outer7 { + namespace Space7 { + namespace Middle7 { + class Thing7; + } + } +} +using namespace Outer7::Space7; +class Middle7::Thing7 {}; +using Middle7::Thing7; +void useit7(Thing7 t) {} +void useit7a(Outer7::Space7::Middle7::Thing7 t) {} +void useit7b(::Outer7::Space7::Middle7::Thing7 t) {} +void useit7c(Middle7::Thing7 t) {} +namespace Outer7 { + namespace Space7 { + void useit7d(Middle7::Thing7 t) {} + } +} + %} diff --git a/Examples/test-suite/using_directive_and_declaration_forward.i b/Examples/test-suite/using_directive_and_declaration_forward.i new file mode 100644 index 000000000..238b3b77f --- /dev/null +++ b/Examples/test-suite/using_directive_and_declaration_forward.i @@ -0,0 +1,124 @@ +%module using_directive_and_declaration_forward +// Test using directives combined with using declarations and forward declarations + +%inline %{ +namespace Outer1 { + namespace Space1 { + class Thing1; + } +} +using namespace Outer1::Space1; +using Outer1::Space1::Thing1; +class Thing1 {}; +void useit1(Thing1 t) {} +void useit1a(Outer1::Space1::Thing1 t) {} +void useit1b(::Outer1::Space1::Thing1 t) {} +namespace Outer1 { + void useit1c(Space1::Thing1 t) {} +} + + +namespace Outer2 { + namespace Space2 { + class Thing2; + } +} +using namespace Outer2; +using Space2::Thing2; +class Thing2 {}; +void useit2(Thing2 t) {} +void useit2a(Outer2::Space2::Thing2 t) {} +void useit2b(::Outer2::Space2::Thing2 t) {} +void useit2c(Space2::Thing2 t) {} +namespace Outer2 { + void useit2d(Space2::Thing2 t) {} +} + + +namespace Outer3 { + namespace Space3 { + namespace Middle3 { + class Thing3; + } + } +} +using namespace Outer3; +using namespace Space3; +using Middle3::Thing3; +class Thing3 {}; +void useit3(Thing3 t) {} +void useit3a(Outer3::Space3::Middle3::Thing3 t) {} +void useit3b(::Outer3::Space3::Middle3::Thing3 t) {} +void useit3c(Middle3::Thing3 t) {} +namespace Outer3 { + namespace Space3 { + void useit3d(Middle3::Thing3 t) {} + } +} + + +namespace Outer4 { + namespace Space4 { + namespace Middle4 { + class Thing4; + } + } +} +using namespace Outer4::Space4; +using Middle4::Thing4; +class Thing4 {}; +void useit4(Thing4 t) {} +void useit4a(Outer4::Space4::Middle4::Thing4 t) {} +void useit4b(::Outer4::Space4::Middle4::Thing4 t) {} +void useit4c(Middle4::Thing4 t) {} +namespace Outer4 { + namespace Space4 { + void useit4d(Middle4::Thing4 t) {} + } +} + + +namespace Outer5 { + namespace Space5 { + namespace Middle5 { + namespace More5 { + class Thing5; + } + } + } +} +using namespace ::Outer5::Space5; +using namespace Middle5; +using More5::Thing5; +class Thing5 {}; +void useit5(Thing5 t) {} +void useit5a(Outer5::Space5::Middle5::More5::Thing5 t) {} +void useit5b(::Outer5::Space5::Middle5::More5::Thing5 t) {} +void useit5c(Middle5::More5::Thing5 t) {} +namespace Outer5 { + namespace Space5 { + void useit5d(Middle5::More5::Thing5 t) {} + } +} + +namespace Outer7 { + namespace Space7 { + namespace Middle7 { + class Thing7; + } + } +} +using namespace Outer7::Space7; +class Middle7::Thing7 {}; +using Middle7::Thing7; +void useit7(Thing7 t) {} +void useit7a(Outer7::Space7::Middle7::Thing7 t) {} +void useit7b(::Outer7::Space7::Middle7::Thing7 t) {} +void useit7c(Middle7::Thing7 t) {} +namespace Outer7 { + namespace Space7 { + void useit7d(Middle7::Thing7 t) {} + } +} + +%} diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 27344598a..b400efa3a 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -205,7 +205,7 @@ static String *yyrename = 0; /* Forward renaming operator */ -static String *resolve_node_scope(String *cname); +static String *resolve_create_node_scope(String *cname); Hash *Swig_cparse_features(void) { @@ -867,26 +867,86 @@ static Node *nscope = 0; static Node *nscope_inner = 0; /* Remove the scope prefix from cname and return the base name without the prefix. - * The scopes specified in the prefix are found, or created in the current namespace. - * So ultimately the scope is changed to that required for the base name. + * The scopes required for the symbol name are resolved and/or created, if required. * For example AA::BB::CC as input returns CC and creates the namespace AA then inner - * namespace BB in the current scope. If no scope separator (::) in the input, then nothing happens! */ -static String *resolve_node_scope(String *cname) { + * namespace BB in the current scope. If cname is found to already exist as a weak symbol + * (forward reference) then the scope might be changed to match, such as when a symbol match + * is made via a using reference. */ +static String *resolve_create_node_scope(String *cname) { Symtab *gscope = 0; + Node *cname_node = 0; + int skip_lookup = 0; nscope = 0; nscope_inner = 0; + + if (Swig_scopename_check(cname)) { + String *prefix = Swig_scopename_prefix(cname); + if (prefix && (Strncmp(prefix,"::",2) == 0)) + skip_lookup = 1; + } + cname_node = skip_lookup ? 0 : Swig_symbol_clookup_no_inherit(cname, 0); + + if (cname_node) { + /* The symbol has been defined already or is in another scope. + If it is a weak symbol, it needs replacing and if it was brought into the current scope + via a using declaration, the scope needs adjusting appropriately for the new symbol. */ + Symtab *symtab = Getattr(cname_node, "sym:symtab"); + Node *sym_weak = Getattr(cname_node, "sym:weak"); + if (symtab && sym_weak) { + /* Check if the scope is the current scope */ + String *current_scopename = Swig_symbol_qualifiedscopename(0); + String *found_scopename = Swig_symbol_qualifiedscopename(symtab); + int len; + if (!current_scopename) + current_scopename = NewString(""); + if (!found_scopename) + found_scopename = NewString(""); + len = Len(current_scopename); + if ((len > 0) && (Strncmp(current_scopename, found_scopename, len) == 0)) { + if (Len(found_scopename) > len + 2) { + /* A matching weak symbol was found in non-global scope, some scope adjustment may be required */ + String *new_cname = NewString(Char(found_scopename) + len + 2); /* skip over "::" prefix */ + String *base = Swig_scopename_last(cname); + Printf(new_cname, "::%s", base); + cname = new_cname; + Delete(base); + } else { + /* A matching weak symbol was found in the same non-global local scope, no scope adjustment required */ + assert(len == Len(found_scopename)); + } + } else { + String *base = Swig_scopename_last(cname); + if (Len(found_scopename) > 0) { + /* A matching weak symbol was found in a different scope to the local scope - probably via a using declaration */ + cname = NewStringf("%s::%s", found_scopename, base); + } else { + /* Either: + 1) A matching weak symbol was found in a different scope to the local scope - this is actually a + symbol with the same name in a different scope which we don't want, so no adjustment required. + 2) A matching weak symbol was found in the global scope - no adjustment required. + */ + cname = Copy(base); + } + Delete(base); + } + Delete(current_scopename); + Delete(found_scopename); + } + } + if (Swig_scopename_check(cname)) { Node *ns; String *prefix = Swig_scopename_prefix(cname); String *base = Swig_scopename_last(cname); if (prefix && (Strncmp(prefix,"::",2) == 0)) { +/* I don't think we can use :: global scope to declare classes and hence neither %template. - consider reporting error instead - wsfulton. */ /* Use the global scope */ String *nprefix = NewString(Char(prefix)+2); Delete(prefix); prefix= nprefix; gscope = set_scope_to_global(); - } - if (!prefix || (Len(prefix) == 0)) { + } + if (Len(prefix) == 0) { /* Use the global scope, but we need to add a 'global' namespace. */ if (!gscope) gscope = set_scope_to_global(); /* note that this namespace is not the "unnamed" one, @@ -904,8 +964,7 @@ static String *resolve_node_scope(String *cname) { } else { Symtab *nstab = Getattr(ns,"symtab"); if (!nstab) { - Swig_error(cparse_file,cparse_line, - "'%s' is not defined as a valid scope.\n", prefix); + Swig_error(cparse_file,cparse_line, "'%s' is not defined as a valid scope.\n", prefix); ns = 0; } else { /* Check if the node scope is the current scope */ @@ -986,6 +1045,7 @@ static String *resolve_node_scope(String *cname) { } Delete(prefix); } + return cname; } @@ -2784,7 +2844,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va /* If the class name is qualified, we need to create or lookup namespace entries */ if (!inclass) { - $5 = resolve_node_scope($5); + $5 = resolve_create_node_scope($5); } /* @@ -3406,7 +3466,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { prev_symtab = Swig_symbol_current(); /* If the class name is qualified. We need to create or lookup namespace/scope entries */ - scope = resolve_node_scope($3); + scope = resolve_create_node_scope($3); Setfile(scope,cparse_file); Setline(scope,cparse_line); $3 = scope; diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 97b730508..a85334e55 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -227,6 +227,7 @@ extern "C" { extern void Swig_symbol_cadd(const_String_or_char_ptr symname, Node *node); extern Node *Swig_symbol_clookup(const_String_or_char_ptr symname, Symtab *tab); extern Node *Swig_symbol_clookup_check(const_String_or_char_ptr symname, Symtab *tab, int (*check) (Node *)); + extern Node *Swig_symbol_clookup_no_inherit(const_String_or_char_ptr name, Symtab *n); extern Symtab *Swig_symbol_cscope(const_String_or_char_ptr symname, Symtab *tab); extern Node *Swig_symbol_clookup_local(const_String_or_char_ptr symname, Symtab *tab); extern Node *Swig_symbol_clookup_local_check(const_String_or_char_ptr symname, Symtab *tab, int (*check) (Node *)); diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index 0cf6cdb53..e9565c9da 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -176,6 +176,8 @@ static Hash *current_symtab = 0; /* Current symbol table node */ static Hash *symtabs = 0; /* Hash of all symbol tables by fully-qualified name */ static Hash *global_scope = 0; /* Global scope */ +static int use_inherit = 1; + /* common attribute keys, to avoid calling find_key all the times */ @@ -482,9 +484,9 @@ void Swig_symbol_alias(const_String_or_char_ptr aliasname, Symtab *s) { /* ----------------------------------------------------------------------------- * Swig_symbol_inherit() * - * Inherit symbols from another scope. - * Primarily for using directives, such as 'using namespace X;'. - * Not for using declarations, such as 'using A;'. + * Inherit symbols from another scope. Primarily for C++ inheritance and + * for using directives, such as 'using namespace X;' + * but not for using declarations, such as 'using A;'. * ----------------------------------------------------------------------------- */ void Swig_symbol_inherit(Symtab *s) { @@ -970,7 +972,7 @@ static Node *_symbol_lookup(const String *name, Symtab *symtab, int (*check) (No } inherit = Getattr(symtab, "inherit"); - if (inherit) { + if (inherit && use_inherit) { int i, len; len = Len(inherit); for (i = 0; i < len; i++) { @@ -1060,7 +1062,7 @@ static Node *symbol_lookup_qualified(const_String_or_char_ptr name, Symtab *symt /* Check inherited scopes */ if (!n) { List *inherit = Getattr(symtab, "inherit"); - if (inherit) { + if (inherit && use_inherit) { int i, len; len = Len(inherit); for (i = 0; i < len; i++) { @@ -1327,6 +1329,11 @@ Node *Swig_symbol_clookup_local_check(const_String_or_char_ptr name, Symtab *n, return s; } +Node *Swig_symbol_clookup_no_inherit(const_String_or_char_ptr name, Symtab *n) { + use_inherit = 0; + Swig_symbol_clookup(name, n); + use_inherit = 1; +} /* ----------------------------------------------------------------------------- * Swig_symbol_cscope() From 3e33774c8ca8f4f23e572179a45d3729fa4869aa Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 4 Aug 2012 20:23:31 +0000 Subject: [PATCH 0141/1160] Show symbol type in symbol debug functions such as -debug-csymbols git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13503 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/symbol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index e9565c9da..b9d6bdbdd 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -224,7 +224,7 @@ static void symbol_print_symbols(const char *symboltabletype) { Iterator it = First(symtab); while (it.key) { String *symname = it.key; - Printf(stdout, " %s\n", symname); + Printf(stdout, " %s (%s)\n", symname, nodeType(it.item)); /* Printf(stdout, " %s - %p (%s)\n", symname, it.item, Getattr(it.item, "name")); */ From 54726b9d0967d3cb7d3f2e93fa7e7400cc281307 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 4 Aug 2012 20:24:22 +0000 Subject: [PATCH 0142/1160] Fix using declarations and templates. %template was putting the instantiated template into the global namespace instead of the namespace of the template definition. This fixes regression in swig-2.0.5 copying the std::pair typemaps which occurs with a 'using std::pair' declaration. This also fixes lots of other using declarations of template problems (template forward declarations. combinations using directives). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13504 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 49 +++++++ Examples/test-suite/common.mk | 3 + ...e_namespace_forward_declaration_runme.java | 26 ++++ ...rective_and_declaration_forward_runme.java | 53 +++++++ Examples/test-suite/li_std_pair_using.i | 21 +++ .../python/li_std_pair_using_runme.py | 10 ++ .../template_namespace_forward_declaration.i | 38 +++++ ..._using_directive_and_declaration_forward.i | 133 ++++++++++++++++++ Source/CParse/parser.y | 13 +- 9 files changed, 339 insertions(+), 7 deletions(-) create mode 100644 Examples/test-suite/java/template_namespace_forward_declaration_runme.java create mode 100644 Examples/test-suite/java/template_using_directive_and_declaration_forward_runme.java create mode 100644 Examples/test-suite/li_std_pair_using.i create mode 100644 Examples/test-suite/python/li_std_pair_using_runme.py create mode 100644 Examples/test-suite/template_namespace_forward_declaration.i create mode 100644 Examples/test-suite/template_using_directive_and_declaration_forward.i diff --git a/CHANGES.current b/CHANGES.current index 663f2c451..011556b57 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -16,6 +16,55 @@ Version 2.0.8 (in progress) 2012-07-20: kwwette [Octave] segfault-on-exit prevention hack now preserves exit status, and uses C99 _Exit(). +2012-07-02: wsfulton + Fix Debian bug http://bugs.debian.org/672035, typemap copy failure - regression introduced + in swig-2.0.5: + %include + using std::pair; + %template(StrPair) pair; + +2012-07-02: wsfulton + Fix using declarations combined with using directives with forward class declarations so that + types are correctly found in scope for templates. Example: + + namespace Outer2 { + namespace Space2 { + template class Thing2; + } + } + using namespace Outer2; + using Space2::Thing2; + template class Thing2 {}; + // STILL BROKEN void useit2(Thing2 t) {} + void useit2a(Outer2::Space2::Thing2 t) {} + void useit2b(::Outer2::Space2::Thing2 t) {} + void useit2c(Space2::Thing2 t) {} + namespace Outer2 { + void useit2d(Space2::Thing2 t) {} + } + + %template(Thing2Int) Thing2; + + +2012-06-30: wsfulton + Fix template namespace problems for symbols declared with a forward class declarations, such as: + + namespace Space1 { + namespace Space2 { + template struct YYY; + } + template struct Space2::YYY { + T yyy(T h) { + return h; + } + }; + void testYYY1(Space1::Space2::YYY yy) {} + void testYYY2(Space2::YYY yy) {} + void testYYY3(::Space1::Space2::YYY yy) {} + } + + %template(YYYInt) Space1::Space2::YYY; + 2012-06-30: wsfulton Fix namespace problems for symbols declared with a forward class declarations, such as: diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index db13a9fbe..f6a8056e5 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -370,6 +370,8 @@ CPP_TEST_CASES += \ template_inherit_abstract \ template_int_const \ template_methods \ + template_namespace_forward_declaration \ + template_using_directive_and_declaration_forward \ template_nested \ template_nested_typemaps \ template_ns \ @@ -476,6 +478,7 @@ CPP_STD_TEST_CASES += \ li_std_except \ li_std_map \ li_std_pair \ + li_std_pair_using \ li_std_string \ li_std_vector \ li_std_vector_enum \ diff --git a/Examples/test-suite/java/template_namespace_forward_declaration_runme.java b/Examples/test-suite/java/template_namespace_forward_declaration_runme.java new file mode 100644 index 000000000..dadb4dbcb --- /dev/null +++ b/Examples/test-suite/java/template_namespace_forward_declaration_runme.java @@ -0,0 +1,26 @@ + +import template_namespace_forward_declaration.*; + +public class template_namespace_forward_declaration_runme { + + static { + try { + System.loadLibrary("template_namespace_forward_declaration"); + } 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[]) { + XXXInt xxx = new XXXInt(); + template_namespace_forward_declaration.testXXX1(xxx); + template_namespace_forward_declaration.testXXX2(xxx); + template_namespace_forward_declaration.testXXX3(xxx); + YYYInt yyy = new YYYInt(); + template_namespace_forward_declaration.testYYY1(yyy); + template_namespace_forward_declaration.testYYY2(yyy); + template_namespace_forward_declaration.testYYY3(yyy); + } +} + diff --git a/Examples/test-suite/java/template_using_directive_and_declaration_forward_runme.java b/Examples/test-suite/java/template_using_directive_and_declaration_forward_runme.java new file mode 100644 index 000000000..080945e02 --- /dev/null +++ b/Examples/test-suite/java/template_using_directive_and_declaration_forward_runme.java @@ -0,0 +1,53 @@ + +import template_using_directive_and_declaration_forward.*; + +public class template_using_directive_and_declaration_forward_runme { + + static { + try { + System.loadLibrary("template_using_directive_and_declaration_forward"); + } 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[]) + { + template_using_directive_and_declaration_forward.useit1(new Thing1Int()); + template_using_directive_and_declaration_forward.useit1a(new Thing1Int()); + template_using_directive_and_declaration_forward.useit1b(new Thing1Int()); + template_using_directive_and_declaration_forward.useit1c(new Thing1Int()); + +//BROKEN template_using_directive_and_declaration_forward.useit2(new Thing2Int()); + template_using_directive_and_declaration_forward.useit2a(new Thing2Int()); + template_using_directive_and_declaration_forward.useit2b(new Thing2Int()); + template_using_directive_and_declaration_forward.useit2c(new Thing2Int()); + template_using_directive_and_declaration_forward.useit2d(new Thing2Int()); + +//BROKEN template_using_directive_and_declaration_forward.useit3(new Thing3Int()); + template_using_directive_and_declaration_forward.useit3a(new Thing3Int()); + template_using_directive_and_declaration_forward.useit3b(new Thing3Int()); + template_using_directive_and_declaration_forward.useit3c(new Thing3Int()); + template_using_directive_and_declaration_forward.useit3d(new Thing3Int()); + +//BROKEN template_using_directive_and_declaration_forward.useit4(new Thing4Int()); + template_using_directive_and_declaration_forward.useit4a(new Thing4Int()); + template_using_directive_and_declaration_forward.useit4b(new Thing4Int()); + template_using_directive_and_declaration_forward.useit4c(new Thing4Int()); + template_using_directive_and_declaration_forward.useit4d(new Thing4Int()); + +//BROKEN template_using_directive_and_declaration_forward.useit5(new Thing5Int()); + template_using_directive_and_declaration_forward.useit5a(new Thing5Int()); + template_using_directive_and_declaration_forward.useit5b(new Thing5Int()); + template_using_directive_and_declaration_forward.useit5c(new Thing5Int()); + template_using_directive_and_declaration_forward.useit5d(new Thing5Int()); + + +//BROKEN template_using_directive_and_declaration_forward.useit7(new Thing7Int()); + template_using_directive_and_declaration_forward.useit7a(new Thing7Int()); + template_using_directive_and_declaration_forward.useit7b(new Thing7Int()); + template_using_directive_and_declaration_forward.useit7c(new Thing7Int()); + template_using_directive_and_declaration_forward.useit7d(new Thing7Int()); + } +} diff --git a/Examples/test-suite/li_std_pair_using.i b/Examples/test-suite/li_std_pair_using.i new file mode 100644 index 000000000..7f90c9c33 --- /dev/null +++ b/Examples/test-suite/li_std_pair_using.i @@ -0,0 +1,21 @@ +%module li_std_pair_using + +%include +using std::pair; + +%template(StringStringPair) pair; + +%inline %{ +typedef int Integer; +using std::string; +%} + +%template(StringIntPair) pair; + +%inline %{ +typedef std::string String; +typedef string Streeng; +std::pair bounce(std::pair p) { + return p; +} +%} diff --git a/Examples/test-suite/python/li_std_pair_using_runme.py b/Examples/test-suite/python/li_std_pair_using_runme.py new file mode 100644 index 000000000..a8b261035 --- /dev/null +++ b/Examples/test-suite/python/li_std_pair_using_runme.py @@ -0,0 +1,10 @@ +from li_std_pair_using import * + +one_tuple = ("one", "numero uno") +one = StringStringPair(one_tuple) +two_tuple = ("two", 2) +two = StringIntPair(two_tuple) + +if bounce(one) != one_tuple: + raise RuntimeError + diff --git a/Examples/test-suite/template_namespace_forward_declaration.i b/Examples/test-suite/template_namespace_forward_declaration.i new file mode 100644 index 000000000..8bc098724 --- /dev/null +++ b/Examples/test-suite/template_namespace_forward_declaration.i @@ -0,0 +1,38 @@ +%module template_namespace_forward_declaration + +%inline %{ + namespace Space1 { + namespace Space2 { + template struct XXX; + template struct YYY; + } + + template struct Space2::YYY { + T yyy(T h) { + return h; + } + }; + template struct Space1::Space2::XXX { + T xxx(T h) { + return h; + } + }; + + void testXXX1(Space1::Space2::XXX xx) { + } + void testXXX2(Space2::XXX xx) { + } + void testXXX3(::Space1::Space2::XXX xx) { + } + void testYYY1(Space1::Space2::YYY yy) { + } + void testYYY2(Space2::YYY yy) { + } + void testYYY3(::Space1::Space2::YYY yy) { + } + } +%} + +%template(XXXInt) Space1::Space2::XXX; +%template(YYYInt) Space1::Space2::YYY; + diff --git a/Examples/test-suite/template_using_directive_and_declaration_forward.i b/Examples/test-suite/template_using_directive_and_declaration_forward.i new file mode 100644 index 000000000..0137e0ad7 --- /dev/null +++ b/Examples/test-suite/template_using_directive_and_declaration_forward.i @@ -0,0 +1,133 @@ +%module template_using_directive_and_declaration_forward +// Test using directives combined with using declarations and forward declarations (templates) + +%inline %{ +namespace Outer1 { + namespace Space1 { + template class Thing1; + } +} +using namespace Outer1::Space1; +using Outer1::Space1::Thing1; +template class Thing1 {}; +void useit1(Thing1 t) {} +void useit1a(Outer1::Space1::Thing1 t) {} +void useit1b(::Outer1::Space1::Thing1 t) {} +namespace Outer1 { + void useit1c(Space1::Thing1 t) {} +} + + +namespace Outer2 { + namespace Space2 { + template class Thing2; + } +} +using namespace Outer2; +using Space2::Thing2; +template class Thing2 {}; +// BROKEN void useit2(Thing2 t) {} +void useit2a(Outer2::Space2::Thing2 t) {} +void useit2b(::Outer2::Space2::Thing2 t) {} +void useit2c(Space2::Thing2 t) {} +namespace Outer2 { + void useit2d(Space2::Thing2 t) {} +} + + +namespace Outer3 { + namespace Space3 { + namespace Middle3 { + template class Thing3; + } + } +} +using namespace Outer3; +using namespace Space3; +using Middle3::Thing3; +template class Thing3 {}; +// BROKEN void useit3(Thing3 t) {} +void useit3a(Outer3::Space3::Middle3::Thing3 t) {} +void useit3b(::Outer3::Space3::Middle3::Thing3 t) {} +void useit3c(Middle3::Thing3 t) {} +namespace Outer3 { + namespace Space3 { + void useit3d(Middle3::Thing3 t) {} + } +} + + +namespace Outer4 { + namespace Space4 { + namespace Middle4 { + template class Thing4; + } + } +} +using namespace Outer4::Space4; +using Middle4::Thing4; +template class Thing4 {}; +// BROKEN void useit4(Thing4 t) {} +void useit4a(Outer4::Space4::Middle4::Thing4 t) {} +void useit4b(::Outer4::Space4::Middle4::Thing4 t) {} +void useit4c(Middle4::Thing4 t) {} +namespace Outer4 { + namespace Space4 { + void useit4d(Middle4::Thing4 t) {} + } +} + + +namespace Outer5 { + namespace Space5 { + namespace Middle5 { + namespace More5 { + template class Thing5; + } + } + } +} +using namespace ::Outer5::Space5; +using namespace Middle5; +using More5::Thing5; +template class Thing5 {}; +// BROKEN void useit5(Thing5 t) {} +void useit5a(Outer5::Space5::Middle5::More5::Thing5 t) {} +void useit5b(::Outer5::Space5::Middle5::More5::Thing5 t) {} +void useit5c(Middle5::More5::Thing5 t) {} +namespace Outer5 { + namespace Space5 { + void useit5d(Middle5::More5::Thing5 t) {} + } +} + +namespace Outer7 { + namespace Space7 { + namespace Middle7 { + template class Thing7; + } + } +} +using namespace Outer7::Space7; +template class Middle7::Thing7 {}; +using Middle7::Thing7; +// BROKEN void useit7(Thing7 t) {} +void useit7a(Outer7::Space7::Middle7::Thing7 t) {} +void useit7b(::Outer7::Space7::Middle7::Thing7 t) {} +void useit7c(Middle7::Thing7 t) {} +namespace Outer7 { + namespace Space7 { + void useit7d(Middle7::Thing7 t) {} + } +} + +%} + +%template(Thing1Int) Thing1; +%template(Thing2Int) Thing2; +%template(Thing3Int) Thing3; +%template(Thing4Int) Thing4; +%template(Thing5Int) Thing5; +%template(Thing7Int) Thing7; + + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index b400efa3a..724b2ef69 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -879,20 +879,19 @@ static String *resolve_create_node_scope(String *cname) { nscope = 0; nscope_inner = 0; - if (Swig_scopename_check(cname)) { - String *prefix = Swig_scopename_prefix(cname); - if (prefix && (Strncmp(prefix,"::",2) == 0)) - skip_lookup = 1; - } + if (Strncmp(cname,"::",2) == 0) + skip_lookup = 1; + cname_node = skip_lookup ? 0 : Swig_symbol_clookup_no_inherit(cname, 0); if (cname_node) { /* The symbol has been defined already or is in another scope. If it is a weak symbol, it needs replacing and if it was brought into the current scope - via a using declaration, the scope needs adjusting appropriately for the new symbol. */ + via a using declaration, the scope needs adjusting appropriately for the new symbol. + Similarly for defined templates. */ Symtab *symtab = Getattr(cname_node, "sym:symtab"); Node *sym_weak = Getattr(cname_node, "sym:weak"); - if (symtab && sym_weak) { + if ((symtab && sym_weak) || Equal(nodeType(cname_node), "template")) { /* Check if the scope is the current scope */ String *current_scopename = Swig_symbol_qualifiedscopename(0); String *found_scopename = Swig_symbol_qualifiedscopename(symtab); From 0559f1f52164e071998de6452349bd57c71e0250 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 4 Aug 2012 20:24:47 +0000 Subject: [PATCH 0143/1160] Fix Swig_symbol_clookup_no_inherit return value git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13505 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/symbol.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index b9d6bdbdd..e39f826eb 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -1329,10 +1329,19 @@ Node *Swig_symbol_clookup_local_check(const_String_or_char_ptr name, Symtab *n, return s; } +/* ----------------------------------------------------------------------------- + * Swig_symbol_clookup_no_inherit() + * + * Symbol lookup like Swig_symbol_clookup but does not follow using declarations. + * ----------------------------------------------------------------------------- */ + Node *Swig_symbol_clookup_no_inherit(const_String_or_char_ptr name, Symtab *n) { + Node *s = 0; + assert(use_inherit==1); use_inherit = 0; - Swig_symbol_clookup(name, n); + s = Swig_symbol_clookup(name, n); use_inherit = 1; + return s; } /* ----------------------------------------------------------------------------- @@ -1558,6 +1567,7 @@ SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) { for (i = 0; i < len; i++) { String *e = Getitem(elements, i); if (SwigType_issimple(e)) { + /* Note: the unary scope operator (::) is being removed from the template parameters here. */ Node *n = Swig_symbol_clookup_check(e, st, symbol_no_constructor); if (n) { String *name = Getattr(n, "name"); From 32071e86909c9979d605b1190e751ac93e0229b3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 4 Aug 2012 20:25:16 +0000 Subject: [PATCH 0144/1160] Restore previously broken tests git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13506 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../template_using_directive_and_declaration_forward.i | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Examples/test-suite/template_using_directive_and_declaration_forward.i b/Examples/test-suite/template_using_directive_and_declaration_forward.i index 0137e0ad7..a5a7fbf31 100644 --- a/Examples/test-suite/template_using_directive_and_declaration_forward.i +++ b/Examples/test-suite/template_using_directive_and_declaration_forward.i @@ -26,7 +26,7 @@ namespace Outer2 { using namespace Outer2; using Space2::Thing2; template class Thing2 {}; -// BROKEN void useit2(Thing2 t) {} +void useit2(Thing2 t) {} void useit2a(Outer2::Space2::Thing2 t) {} void useit2b(::Outer2::Space2::Thing2 t) {} void useit2c(Space2::Thing2 t) {} @@ -46,7 +46,7 @@ using namespace Outer3; using namespace Space3; using Middle3::Thing3; template class Thing3 {}; -// BROKEN void useit3(Thing3 t) {} +void useit3(Thing3 t) {} void useit3a(Outer3::Space3::Middle3::Thing3 t) {} void useit3b(::Outer3::Space3::Middle3::Thing3 t) {} void useit3c(Middle3::Thing3 t) {} @@ -67,7 +67,7 @@ namespace Outer4 { using namespace Outer4::Space4; using Middle4::Thing4; template class Thing4 {}; -// BROKEN void useit4(Thing4 t) {} +void useit4(Thing4 t) {} void useit4a(Outer4::Space4::Middle4::Thing4 t) {} void useit4b(::Outer4::Space4::Middle4::Thing4 t) {} void useit4c(Middle4::Thing4 t) {} @@ -91,7 +91,7 @@ using namespace ::Outer5::Space5; using namespace Middle5; using More5::Thing5; template class Thing5 {}; -// BROKEN void useit5(Thing5 t) {} +void useit5(Thing5 t) {} void useit5a(Outer5::Space5::Middle5::More5::Thing5 t) {} void useit5b(::Outer5::Space5::Middle5::More5::Thing5 t) {} void useit5c(Middle5::More5::Thing5 t) {} @@ -111,7 +111,7 @@ namespace Outer7 { using namespace Outer7::Space7; template class Middle7::Thing7 {}; using Middle7::Thing7; -// BROKEN void useit7(Thing7 t) {} +void useit7(Thing7 t) {} void useit7a(Outer7::Space7::Middle7::Thing7 t) {} void useit7b(::Outer7::Space7::Middle7::Thing7 t) {} void useit7c(Middle7::Thing7 t) {} From e21bd464204fa52a6a697651c057cb0c5560aa49 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 4 Aug 2012 20:25:43 +0000 Subject: [PATCH 0145/1160] Resolve template parameters git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13507 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/typepass.cxx | 5 +++++ Source/Swig/typesys.c | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index d757d53a7..3284a669a 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -1159,6 +1159,11 @@ class TypePass:private Dispatcher { SwigType_typedef_using(uname); } else if (Strcmp(ntype, "enum") == 0) { SwigType_typedef_using(Getattr(n, "uname")); + } else if (Strcmp(ntype, "template") == 0) { + /* + Printf(stdout, "usingDeclaration template %s --- %s\n", Getattr(n, "name"), Getattr(n, "uname")); + SwigType_typedef_using(Getattr(n, "uname")); + */ } } } diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index ab6475b9c..4d6dea60f 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -954,7 +954,12 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) { Iterator pi; Parm *p; List *parms; + /* ty = Swig_symbol_template_deftype(e, current_symtab); + */ + String *dt = Swig_symbol_template_deftype(e, current_symtab); + ty = Swig_symbol_type_qualify(dt, 0); + Printf(stdout, "extra code: %s => %s\n", dt, ty); e = ty; parms = SwigType_parmlist(e); tprefix = SwigType_templateprefix(e); @@ -1021,6 +1026,9 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) { Delete(tprefix); Delete(qprefix); Delete(parms); + /* + Delete(dt); + */ } Append(result, e); Delete(ty); From 05839e646c8cc2b10a42ff57c435906b4cc76483 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 4 Aug 2012 20:26:08 +0000 Subject: [PATCH 0146/1160] Revert resolving template parameters git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13508 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/typesys.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index 4d6dea60f..73c2fbd50 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -954,12 +954,11 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) { Iterator pi; Parm *p; List *parms; - /* ty = Swig_symbol_template_deftype(e, current_symtab); - */ + /* String *dt = Swig_symbol_template_deftype(e, current_symtab); ty = Swig_symbol_type_qualify(dt, 0); - Printf(stdout, "extra code: %s => %s\n", dt, ty); + */ e = ty; parms = SwigType_parmlist(e); tprefix = SwigType_templateprefix(e); From 33098764b73ca8e7dcf5c168a12017350b387aaf Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 4 Aug 2012 22:38:44 +0000 Subject: [PATCH 0147/1160] Remove unnecessary keyword warning when parsing 'using' git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13509 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 10 ++++++++-- Source/Swig/naming.c | 7 +++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 011556b57..f10ab79d0 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,10 +5,16 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.8 (in progress) =========================== -2012-06-27: wsfulton +2012-08-04: wsfulton + Remove incorrect warning (314) about target language keywords which were triggered + by using declarations and using directives. For example 'string' is a keyword in C#: + namespace std { class string; } + using std::string; + +2012-07-21: wsfulton Fix display of pointers in various places on 64 bit systems - only 32 bits were being shown. -2012-06-27: wsfulton +2012-07-21: wsfulton Fix gdb debugger functions 'swigprint' and 'locswigprint' to display to the gdb output window rather than stdout. This fixes display problems in gdbtui and the ensures the output appears where expected in other gdb based debuggers such as Eclipse CDT. diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index 1be1405a3..e96dbd14e 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -883,13 +883,16 @@ List *Swig_name_rename_list() { int Swig_need_name_warning(Node *n) { int need = 1; /* - we don't use name warnings for: + We don't use name warnings for: - class forwards, no symbol is generated at the target language. - template declarations, only for real instances using %template(name). - - typedefs, they have no effect at the target language. + - typedefs, have no effect at the target language. + - using declarations and using directives, have no effect at the target language. */ if (checkAttribute(n, "nodeType", "classforward")) { need = 0; + } else if (checkAttribute(n, "nodeType", "using")) { + need = 0; } else if (checkAttribute(n, "storage", "typedef")) { need = 0; } else if (Getattr(n, "hidden")) { From 196f9b31ed278593f947ca8c6c0d42fb3bf141a7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 4 Aug 2012 23:20:07 +0000 Subject: [PATCH 0148/1160] Remove unused temp variable in C# intrusive_ptr wrappers git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13510 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/csharp/boost_intrusive_ptr.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/csharp/boost_intrusive_ptr.i b/Lib/csharp/boost_intrusive_ptr.i index 9884ccc44..09a164729 100644 --- a/Lib/csharp/boost_intrusive_ptr.i +++ b/Lib/csharp/boost_intrusive_ptr.i @@ -97,7 +97,7 @@ #endif %} -%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > ($&1_type argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{ +%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{ // intrusive_ptr by value smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input; if (smartarg) { From 18aa801bd0bf59a7296dd0e045d70bb9c6bbbb6b Mon Sep 17 00:00:00 2001 From: Oliver Buchtala Date: Sun, 5 Aug 2012 08:37:59 +0000 Subject: [PATCH 0149/1160] Fix bug in emit_action. Before, it was possible that two catch(...) blocks were generated (for varargs and undefined typemap). From: Oliver Buchtala git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13511 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/emit.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/Modules/emit.cxx b/Source/Modules/emit.cxx index efcf9a352..7d7f66eaf 100644 --- a/Source/Modules/emit.cxx +++ b/Source/Modules/emit.cxx @@ -470,6 +470,7 @@ String *emit_action(Node *n) { if (catchlist) { int unknown_catch = 0; + int has_varargs = 0; Printf(eaction, "}\n"); for (Parm *ep = catchlist; ep; ep = nextSibling(ep)) { String *em = Swig_typemap_lookup("throws", ep, "_e", 0); @@ -480,6 +481,7 @@ String *emit_action(Node *n) { Printf(eaction, "catch(%s) {", SwigType_str(et, "_e")); } else if (SwigType_isvarargs(etr)) { Printf(eaction, "catch(...) {"); + has_varargs = 1; } else { Printf(eaction, "catch(%s) {", SwigType_str(et, "&_e")); } @@ -490,8 +492,8 @@ String *emit_action(Node *n) { unknown_catch = 1; } } - if (unknown_catch) { - Printf(eaction, "catch(...) { throw; }\n"); + if (unknown_catch && !has_varargs) { + Printf(eaction, "catch(...) { throw; }\n"); } } From db0f2d7a8e2d3be72b39fa5a1487af1615cdfabb Mon Sep 17 00:00:00 2001 From: Oliver Buchtala Date: Sun, 5 Aug 2012 08:38:16 +0000 Subject: [PATCH 0150/1160] Fix pedantic warnings in fio.c methods. From: Oliver Buchtala git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13512 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/DOH/fio.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/DOH/fio.c b/Source/DOH/fio.c index 2ef605c32..4e91a1b51 100644 --- a/Source/DOH/fio.c +++ b/Source/DOH/fio.c @@ -490,6 +490,7 @@ int DohCopyto(DOH *in, DOH *out) { return nbytes; } } + return nbytes; } @@ -588,4 +589,5 @@ DOH *DohReadline(DOH *in) { Putc(c, s); n++; } + return s; } From 4305a3cef9b210541c3b88ab2fd03d787c3bca66 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 5 Aug 2012 10:15:08 +0000 Subject: [PATCH 0151/1160] #3545877 - Don't undefine bool if defined by C99 stdbool.h - problem using Perl 5.16 and later. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13513 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Lib/perl5/noembed.h | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index f10ab79d0..ada7461ac 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.8 (in progress) =========================== +2012-08-05: wsfulton + [Perl] #3545877 - Don't undefine bool if defined by C99 stdbool.h - problem using + Perl 5.16 and later. + 2012-08-04: wsfulton Remove incorrect warning (314) about target language keywords which were triggered by using declarations and using directives. For example 'string' is a keyword in C#: diff --git a/Lib/perl5/noembed.h b/Lib/perl5/noembed.h index 27e510df1..936d50ba6 100644 --- a/Lib/perl5/noembed.h +++ b/Lib/perl5/noembed.h @@ -64,9 +64,6 @@ #ifdef eof #undef eof #endif -#ifdef bool - #undef bool -#endif #ifdef close #undef close #endif @@ -106,3 +103,11 @@ #ifdef stat #undef stat #endif + +#ifdef bool + /* Leave if macro is from C99 stdbool.h */ + #ifndef __bool_true_false_are_defined + #undef bool + #endif +#endif + From a358958e727d2e0507e75e309a8bcdeeceaf0eb1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 5 Aug 2012 11:02:49 +0000 Subject: [PATCH 0152/1160] Update docs with missing example.c compilation - Bug 3545858 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13514 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Java.html | 5 +++-- Doc/Manual/Lua.html | 2 +- Doc/Manual/Perl5.html | 4 ++-- Doc/Manual/Ruby.html | 3 ++- Doc/Manual/Tcl.html | 3 ++- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 2473e7cd1..8a081f46d 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -326,12 +326,13 @@ The exact location may vary on your machine, but the above locations are typical

    The JNI code exists in a dynamic module or shared library (DLL on Windows) and gets loaded by the JVM. -To build a shared library file, you need to compile your module in a manner similar to the following (shown for Solaris):

    +Assuming you have code you need to link to in a file called example.c, in order to build a shared library file, you need to compile your module in a manner similar to the following (shown for Solaris):

     $ swig -java example.i
     $ gcc -c example_wrap.c  -I/usr/java/include -I/usr/java/include/solaris
    -$ ld -G example_wrap.o  -o libexample.so
    +$ gcc -c example.c
    +$ ld -G example_wrap.o example.o -o libexample.so
     

    diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index ec32c4449..1fd41f907 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -236,7 +236,7 @@ More information on building and configuring eLua can be found here:

     $ swig -lua example.i -o example_wrap.c
    diff --git a/Doc/Manual/Perl5.html b/Doc/Manual/Perl5.html
    index 0a4b61bd5..49e8965fa 100644
    --- a/Doc/Manual/Perl5.html
    +++ b/Doc/Manual/Perl5.html
    @@ -170,8 +170,8 @@ $ perl -e 'use Config; print "$Config{archlib}\n";'
     
     

    The preferred approach to building an extension module is to compile it into -a shared object file or DLL. To do this, you will need to compile your program -using commands like this (shown for Linux): +a shared object file or DLL. Assuming you have code you need to link to in a file called example.c, +you will need to compile your program using commands like this (shown for Linux):

    diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html
    index 69005c731..969de7a3d 100644
    --- a/Doc/Manual/Ruby.html
    +++ b/Doc/Manual/Ruby.html
    @@ -398,7 +398,8 @@ can add this: 

    to the end of the extconf.rb file. If for some reason you don't want to use the standard approach, you'll need to determine the correct compiler and linker flags for your build -platform. For example, a typical sequence of commands for the Linux +platform. For example, assuming you have code you need to link to in a file +called example.c, a typical sequence of commands for the Linux operating system would look something like this:

    diff --git a/Doc/Manual/Tcl.html b/Doc/Manual/Tcl.html index f55a7f139..e6b3b4a43 100644 --- a/Doc/Manual/Tcl.html +++ b/Doc/Manual/Tcl.html @@ -132,7 +132,8 @@ header file.

    The preferred approach to building an extension module is to compile it into -a shared object file or DLL. To do this, you will need to compile your program +a shared object file or DLL. Assuming you have code you need to link to in a file +called example.c, you will need to compile your program using commands like this (shown for Linux):

    From 2d24ca37d17b1cccdf13383f32b97ce9a888f928 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 5 Aug 2012 15:49:43 +0000 Subject: [PATCH 0153/1160] Fix invalid code sometimes being generated for C# director methods with many arguments git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13519 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Examples/test-suite/director_classes.i | 17 +++++++++++++++++ Source/Modules/csharp.cxx | 1 - 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index ada7461ac..e69c7d1dc 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.8 (in progress) =========================== +2012-08-05: wsfulton + [C#] Fix #3536360 - Invalid code sometimes being generated for director methods + with many arguments. + 2012-08-05: wsfulton [Perl] #3545877 - Don't undefine bool if defined by C99 stdbool.h - problem using Perl 5.16 and later. diff --git a/Examples/test-suite/director_classes.i b/Examples/test-suite/director_classes.i index 5581c755f..7183e3d0a 100644 --- a/Examples/test-suite/director_classes.i +++ b/Examples/test-suite/director_classes.i @@ -108,3 +108,20 @@ public: %} + +%feature(director) BaseClass; +%feature(director) DerivedClass; + +%inline %{ +class BaseClass +{ +public: +virtual ~BaseClass() {}; +virtual int dofoo(int& one, int& two, int& three) {return 0;} +}; + +class DerivedClass : public BaseClass +{ +}; +%} + diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 57d050cde..18b8892cf 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3728,7 +3728,6 @@ public: Delete(ln); Delete(arg); Delete(c_decl); - Delete(c_param_type); } /* header declaration, start wrapper definition */ From cdfa81e5726b4171035b5090317bde5bc53de729 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 5 Aug 2012 15:53:56 +0000 Subject: [PATCH 0154/1160] Add some error checking for stale DOH object use git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13520 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/DOH/memory.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Source/DOH/memory.c b/Source/DOH/memory.c index fcacd6170..5197c34d8 100644 --- a/Source/DOH/memory.c +++ b/Source/DOH/memory.c @@ -20,6 +20,11 @@ char cvsroot_memory_c[] = "$Id$"; #define DOH_POOL_SIZE 16384 #endif +/* Checks stale DOH object use - will use a lot more memory as pool memory is not re-used. */ +/* +#define DEBUG_MEMORY_POOLS +*/ + static int PoolSize = DOH_POOL_SIZE; DOH *DohNone = 0; /* The DOH None object */ @@ -81,8 +86,14 @@ int DohCheck(const DOH *ptr) { register Pool *p = Pools; register char *cptr = (char *) ptr; while (p) { - if ((cptr >= p->pbeg) && (cptr < p->pend)) + if ((cptr >= p->pbeg) && (cptr < p->pend)) { +#ifdef DEBUG_MEMORY_POOLS + DohBase *b = (DohBase *) ptr; + int already_deleted = b->type == 0; + assert(!already_deleted); +#endif return 1; + } /* pptr = (char *) p->ptr; if ((cptr >= pptr) && (cptr < (pptr+(p->current*sizeof(DohBase))))) return 1; */ @@ -110,16 +121,20 @@ DOH *DohObjMalloc(DohObjInfo *type, void *data) { DohBase *obj; if (!pools_initialized) InitPools(); +#ifndef DEBUG_MEMORY_POOLS if (FreeList) { obj = FreeList; FreeList = (DohBase *) obj->data; } else { +#endif while (Pools->current == Pools->len) { CreatePool(); } obj = Pools->ptr + Pools->current; ++Pools->current; +#ifndef DEBUG_MEMORY_POOLS } +#endif obj->type = type; obj->data = data; obj->meta = 0; @@ -144,6 +159,7 @@ void DohObjFree(DOH *ptr) { b->data = (void *) FreeList; b->meta = 0; b->type = 0; + b->refcount = 0; FreeList = b; if (meta) { Delete(meta); From 766128065f887361622a56950f2ff60551118570 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 5 Aug 2012 16:16:23 +0000 Subject: [PATCH 0155/1160] Error checking for stale DOH object use - also with documentation. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13521 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Devel/internals.html | 29 +++++++++++++++++++++++++++++ Source/DOH/memory.c | 14 ++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Doc/Devel/internals.html b/Doc/Devel/internals.html index d24869d10..94a82519d 100644 --- a/Doc/Devel/internals.html +++ b/Doc/Devel/internals.html @@ -42,6 +42,7 @@
  • 7. Debugging SWIG @@ -1179,6 +1180,34 @@ Either
    + +

    7.2 Debugging DOH memory allocation problems

    +
    + +

    +The DOH objects are reference counted and use pools for memory allocation. +The implementation is in memory.c. When there are memory corruption problems, +various memory allocator tools are normally used to diagnose problems. These can be used +on SWIG and can be very useful. However, they won't necessarily find use of stale DOH objects, +that is, DOH objects +that are used after they have been deleted. This is because the DOH memory allocator +grabs a chunk of memory from the C memory allocator and manages the usage internally. +Stale DOH object usage can be checked for by defining DOH_DEBUG_MEMORY_POOLS in +memory.c. If an attempt to use an object is made after the reference count is +zero, an assertion is triggered instead of quietly re-using the stale object... +

    + +
    +
    +swig: DOH/memory.c:91: DohCheck: Assertion `!DOH_object_already_deleted' failed.
    +
    +
    + +

    +This can be memory intensive as previously used memory in the pool is not re-used so is +only recommended for diagnosing memory corruption problems. +

    +
    Copyright (C) 1999-2010 SWIG Development Team. diff --git a/Source/DOH/memory.c b/Source/DOH/memory.c index 5197c34d8..e366f88e7 100644 --- a/Source/DOH/memory.c +++ b/Source/DOH/memory.c @@ -21,9 +21,7 @@ char cvsroot_memory_c[] = "$Id$"; #endif /* Checks stale DOH object use - will use a lot more memory as pool memory is not re-used. */ -/* -#define DEBUG_MEMORY_POOLS -*/ +#define DOH_DEBUG_MEMORY_POOLS static int PoolSize = DOH_POOL_SIZE; @@ -87,10 +85,10 @@ int DohCheck(const DOH *ptr) { register char *cptr = (char *) ptr; while (p) { if ((cptr >= p->pbeg) && (cptr < p->pend)) { -#ifdef DEBUG_MEMORY_POOLS +#ifdef DOH_DEBUG_MEMORY_POOLS DohBase *b = (DohBase *) ptr; - int already_deleted = b->type == 0; - assert(!already_deleted); + int DOH_object_already_deleted = b->type == 0; + assert(!DOH_object_already_deleted); #endif return 1; } @@ -121,7 +119,7 @@ DOH *DohObjMalloc(DohObjInfo *type, void *data) { DohBase *obj; if (!pools_initialized) InitPools(); -#ifndef DEBUG_MEMORY_POOLS +#ifndef DOH_DEBUG_MEMORY_POOLS if (FreeList) { obj = FreeList; FreeList = (DohBase *) obj->data; @@ -132,7 +130,7 @@ DOH *DohObjMalloc(DohObjInfo *type, void *data) { } obj = Pools->ptr + Pools->current; ++Pools->current; -#ifndef DEBUG_MEMORY_POOLS +#ifndef DOH_DEBUG_MEMORY_POOLS } #endif obj->type = type; From b989e43922a0e803c9aa3f466edec5509a74d621 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 5 Aug 2012 16:17:32 +0000 Subject: [PATCH 0156/1160] Fix incorrect object deletion in C# module git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13522 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/csharp.cxx | 3 --- 1 file changed, 3 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 18b8892cf..cc7c905ef 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3655,8 +3655,6 @@ public: if (!ignored_method) Printf(w->code, "%s\n", tm); - Delete(tm); - /* Add C type to callback typedef */ if (i > 0) Printf(callback_typedef_parms, ", "); @@ -3788,7 +3786,6 @@ public: Printf(callback_code, " return %s;\n", tm); } - Delete(tm); Delete(tp); } else Printf(callback_code, " %s;\n", upcall); From 315dc5a87979b9c961b7c3d299b5b432da20b5a4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 5 Aug 2012 22:17:32 +0000 Subject: [PATCH 0157/1160] Fix some memory issues - use of deleted memory highlighted by DOH_DEBUG_MEMORY_POOLS git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13524 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/csharp.cxx | 3 ++- Source/Modules/java.cxx | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index cc7c905ef..1d6748ae3 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3493,6 +3493,7 @@ public: if (returntype) { + Delete(qualified_return); qualified_return = SwigType_rcaststr(returntype, "c_result"); if (!is_void && !ignored_method) { @@ -3786,6 +3787,7 @@ public: Printf(callback_code, " return %s;\n", tm); } + Delete(tm); Delete(tp); } else Printf(callback_code, " %s;\n", upcall); @@ -3894,7 +3896,6 @@ public: } Delete(qualified_return); - Delete(c_ret_type); Delete(declaration); Delete(callback_typedef_parms); Delete(delegate_parms); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index b04812d05..ffc4d8d97 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3565,6 +3565,7 @@ public: if (returntype) { + Delete(qualified_return); qualified_return = SwigType_rcaststr(returntype, "c_result"); if (!is_void && (!ignored_method || pure_virtual)) { @@ -3814,8 +3815,6 @@ public: if (!ignored_method) Printf(w->code, "%s\n", tm); - Delete(tm); - /* Add parameter to the intermediate class code if generating the * intermediate's upcall code */ if ((tm = Getattr(p, "tmap:jtype"))) { @@ -3890,7 +3889,6 @@ public: Delete(arg); Delete(c_decl); - Delete(c_param_type); Delete(ln); } From 45a259d27443d11f9e29b3517e22a3bfe00824be Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 5 Aug 2012 22:18:39 +0000 Subject: [PATCH 0158/1160] Correct accidental turning on of DOH_DEBUG_MEMORY_POOLS git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13525 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/DOH/memory.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/DOH/memory.c b/Source/DOH/memory.c index e366f88e7..5ad11019d 100644 --- a/Source/DOH/memory.c +++ b/Source/DOH/memory.c @@ -21,7 +21,9 @@ char cvsroot_memory_c[] = "$Id$"; #endif /* Checks stale DOH object use - will use a lot more memory as pool memory is not re-used. */ +/* #define DOH_DEBUG_MEMORY_POOLS +*/ static int PoolSize = DOH_POOL_SIZE; From b6f6fcd6d82619b6744410490431b9d235f56006 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 7 Aug 2012 21:58:52 +0000 Subject: [PATCH 0159/1160] Memory corruption fixes highlighted by DOH_MEMORY_DEBUG_POOL in Python director tests. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13554 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/lang.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 75254d69f..e81ab21dd 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2652,9 +2652,11 @@ static String *get_director_ctor_code(Node *n, String *director_ctor_code, Strin int is_abstract = abstract && !is_notabstract; if (is_protected(n) || is_abstract) { director_ctor = director_prot_ctor_code; + abstract = Copy(abstract); Delattr(pn, "abstract"); } else { if (is_notabstract) { + abstract = Copy(abstract); Delattr(pn, "abstract"); } else { abstract = 0; From 5f294a14049db6b41d307ed44199226e94054c56 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 8 Aug 2012 06:05:30 +0000 Subject: [PATCH 0160/1160] Fix use of deleted memory in Go - note changes director_enum and director_basic tests output. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13555 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/go.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 39b4d261a..91f706ad3 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -3742,9 +3742,9 @@ private: if (is_constructor) { assert(!is_upcall); if (!is_director) { - all_result = Getattr(class_node, "classtypeobj"); + all_result = Copy(Getattr(class_node, "classtypeobj")); } else { - all_result = director_struct; + all_result = Copy(director_struct); } mismatch = false; } else { From cad26e49fec194b3db18908b0c20f40497f0a2b6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 8 Aug 2012 06:06:31 +0000 Subject: [PATCH 0161/1160] Fix use of deleted memory in D module git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13556 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/d.cxx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index bc51cf5ed..7fca68df7 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -1440,7 +1440,7 @@ public: // The type in the out attribute of the typemap overrides the type // in the dtype typemap. tm = dtypeout; - replaceClassname(tm, t); + replaceClassname(tm, t); } Printf(return_type, "%s", tm); } else { @@ -2132,8 +2132,6 @@ public: if (!ignored_method) Printf(w->code, "%s\n", tm); - Delete(tm); - // Add parameter type to the C typedef for the D callback function. Printf(callback_typedef_parms, ", %s", c_param_type); @@ -2270,7 +2268,6 @@ public: Printf(callback_code, " return %s;\n", tm); } - Delete(tm); Delete(tp); } else { Printf(callback_code, " %s;\n", upcall); @@ -3971,7 +3968,7 @@ private: if (attached) { String *attr_name = NewStringf("tmap:%s", method); - result = Getattr(n, attr_name); + result = Copy(Getattr(n, attr_name)); Delete(attr_name); } else { // FIXME: As a workaround for a bug so far only surfacing in the From 19a29c32128087362212b26cbcf2ae949aebaefb Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 8 Aug 2012 06:07:34 +0000 Subject: [PATCH 0162/1160] Fix use of deleted memory in R module git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13557 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/r.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index c2a47ed24..f163c8b30 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -2451,7 +2451,6 @@ int R::generateCopyRoutines(Node *n) { } String *elKind = Getattr(c, "kind"); if (Strcmp(elKind, "variable") != 0) { - Delete(elKind); continue; } From 8a94438c7d69acae840d5abe3fe0c887a8668a21 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 8 Aug 2012 06:08:36 +0000 Subject: [PATCH 0163/1160] Fix segfault in Allegrocl - a proper fix is still needed git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13558 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/allegrocl.cxx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index b6c5385fb..41d481e9d 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -1181,13 +1181,14 @@ void emit_synonym(Node *synonym) { String *of_name = namespaced_name(of, of_ns); if (CPlusPlus && !Strcmp(nodeType(synonym), "cdecl")) { - syn_ltype = NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", - strip_namespaces(Getattr(synonym, "real-name")), synonym_ns); - syn_type = NewStringf("#.(swig-insert-id \"%s\" %s :type :type)", - strip_namespaces(Getattr(synonym, "real-name")), synonym_ns); + String *real_name = Getattr(synonym, "real-name"); + if (!real_name) + real_name = NewString("Unknown"); // TODO: fix + syn_ltype = NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", strip_namespaces(real_name), synonym_ns); + syn_type = NewStringf("#.(swig-insert-id \"%s\" %s :type :type)", strip_namespaces(real_name), synonym_ns); } else { - syn_ltype = lookup_defined_foreign_ltype(synonym_type); - syn_type = lookup_defined_foreign_type(synonym_type); + syn_ltype = lookup_defined_foreign_ltype(synonym_type); + syn_type = lookup_defined_foreign_type(synonym_type); } of_ltype = lookup_defined_foreign_ltype(of_name); From 7dac1bc5242424d8c9c5610f782aa19a6e07a934 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 8 Aug 2012 09:19:26 +0000 Subject: [PATCH 0164/1160] Fix somes typos git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13559 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES | 10 +++++----- Doc/Manual/Android.html | 2 +- Examples/xml/example_apply.expected-xml | 12 ++++++------ Examples/xml/example_xml.expected-xml | 12 ++++++------ Lib/perl5/reference.i | 18 +++++++++--------- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CHANGES b/CHANGES index 7afa119ad..a63a66312 100644 --- a/CHANGES +++ b/CHANGES @@ -3303,7 +3303,7 @@ Version 1.3.32 (November 15, 2007) [C#] Added missing support for C++ class member pointers. 08/09/2007: wsfulton - [C#, Java] Add support for $owner in the "out" typemaps like in the the scripting + [C#, Java] Add support for $owner in the "out" typemaps like in the scripting language modules. Note that $owner has always been supported in the "javaout" / "csout" typemaps. @@ -4003,7 +4003,7 @@ Version 1.3.30 (November 13, 2006) 10/12/2006: wsfulton [Java] Remove potential race condition on the proxy class' delete() method (it is now a synchronized method, but is now customisable by changing the - methodmodifiers attribute in the the javadestruct or javadestruct_derived typemap) + methodmodifiers attribute in the javadestruct or javadestruct_derived typemap) [C#] Remove potential race condition on the proxy class' Dispose() method, similar to Java's delete() above. @@ -4811,7 +4811,7 @@ Version 1.3.28 (February 12, 2006) %naturalvar std::string; %include - that will tell swig to use the the 'natural' wrapping + that will tell swig to use the 'natural' wrapping mechanism to all std::string global and member variables. @@ -8318,7 +8318,7 @@ Version 1.3.23 (November 11, 2004) b = B() b.bar(1) - note the the methods are emitted inside the classes, + note the methods are emitted inside the classes, and hence, the %template name refers to the 'member' method name, not a global namespace name. @@ -16266,7 +16266,7 @@ Version 1.3.12 (June 2, 2002) %feature, %rename, %ignore, %exception, and related directives: - Namespaces are fully integrated into the the renaming and declaration + Namespaces are fully integrated into the renaming and declaration matcher. For example: %rename(display) Foo::print; // Rename in namespace Foo diff --git a/Doc/Manual/Android.html b/Doc/Manual/Android.html index 443d77691..85df94a99 100644 --- a/Doc/Manual/Android.html +++ b/Doc/Manual/Android.html @@ -45,7 +45,7 @@ This chapter contains a few Android specific notes and examples.

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

    diff --git a/Examples/xml/example_apply.expected-xml b/Examples/xml/example_apply.expected-xml index 50a6509ee..6118ef1f2 100644 --- a/Examples/xml/example_apply.expected-xml +++ b/Examples/xml/example_apply.expected-xml @@ -1225,7 +1225,7 @@ void _ptrfree(SV *_PTRVALUE) { } tempsv = SvRV($source); if (!SvIOK(tempsv)) { - croak("expected a integer reference"); + croak("expected an integer reference"); } dvalue = SvIV(tempsv); $target = &dvalue; @@ -1248,7 +1248,7 @@ void _ptrfree(SV *_PTRVALUE) { } tempsv = SvRV($source); if (!SvIOK(tempsv)) { - croak("expected a integer reference"); + croak("expected an integer reference"); } dvalue = (short) SvIV(tempsv); $target = &dvalue; @@ -1271,7 +1271,7 @@ void _ptrfree(SV *_PTRVALUE) { } tempsv = SvRV($source); if (!SvIOK(tempsv)) { - croak("expected a integer reference"); + croak("expected an integer reference"); } dvalue = (long) SvIV(tempsv); $target = &dvalue; @@ -1294,7 +1294,7 @@ void _ptrfree(SV *_PTRVALUE) { } tempsv = SvRV($source); if (!SvIOK(tempsv)) { - croak("expected a integer reference"); + croak("expected an integer reference"); } dvalue = (unsigned int) SvIV(tempsv); $target = &dvalue; @@ -1317,7 +1317,7 @@ void _ptrfree(SV *_PTRVALUE) { } tempsv = SvRV($source); if (!SvIOK(tempsv)) { - croak("expected a integer reference"); + croak("expected an integer reference"); } dvalue = (unsigned short) SvIV(tempsv); $target = &dvalue; @@ -1340,7 +1340,7 @@ void _ptrfree(SV *_PTRVALUE) { } tempsv = SvRV($source); if (!SvIOK(tempsv)) { - croak("expected a integer reference"); + croak("expected an integer reference"); } dvalue = (unsigned long) SvIV(tempsv); $target = &dvalue; diff --git a/Examples/xml/example_xml.expected-xml b/Examples/xml/example_xml.expected-xml index 584e468f6..4d08b206a 100644 --- a/Examples/xml/example_xml.expected-xml +++ b/Examples/xml/example_xml.expected-xml @@ -1257,7 +1257,7 @@ void _ptrfree(SV *_PTRVALUE) { } tempsv = SvRV($source); if (!SvIOK(tempsv)) { - croak("expected a integer reference"); + croak("expected an integer reference"); } dvalue = SvIV(tempsv); $target = &dvalue; @@ -1280,7 +1280,7 @@ void _ptrfree(SV *_PTRVALUE) { } tempsv = SvRV($source); if (!SvIOK(tempsv)) { - croak("expected a integer reference"); + croak("expected an integer reference"); } dvalue = (short) SvIV(tempsv); $target = &dvalue; @@ -1303,7 +1303,7 @@ void _ptrfree(SV *_PTRVALUE) { } tempsv = SvRV($source); if (!SvIOK(tempsv)) { - croak("expected a integer reference"); + croak("expected an integer reference"); } dvalue = (long) SvIV(tempsv); $target = &dvalue; @@ -1326,7 +1326,7 @@ void _ptrfree(SV *_PTRVALUE) { } tempsv = SvRV($source); if (!SvIOK(tempsv)) { - croak("expected a integer reference"); + croak("expected an integer reference"); } dvalue = (unsigned int) SvIV(tempsv); $target = &dvalue; @@ -1349,7 +1349,7 @@ void _ptrfree(SV *_PTRVALUE) { } tempsv = SvRV($source); if (!SvIOK(tempsv)) { - croak("expected a integer reference"); + croak("expected an integer reference"); } dvalue = (unsigned short) SvIV(tempsv); $target = &dvalue; @@ -1372,7 +1372,7 @@ void _ptrfree(SV *_PTRVALUE) { } tempsv = SvRV($source); if (!SvIOK(tempsv)) { - croak("expected a integer reference"); + croak("expected an integer reference"); } dvalue = (unsigned long) SvIV(tempsv); $target = &dvalue; diff --git a/Lib/perl5/reference.i b/Lib/perl5/reference.i index 2836c25c4..b424c533b 100644 --- a/Lib/perl5/reference.i +++ b/Lib/perl5/reference.i @@ -85,7 +85,7 @@ as follows : } tempsv = SvRV($input); if (!SvIOK(tempsv)) { - SWIG_croak("expected a integer reference"); + SWIG_croak("expected an integer reference"); } dvalue = SvIV(tempsv); $1 = &dvalue; @@ -99,7 +99,7 @@ as follows : } tempsv = SvRV($input); if (!SvIOK(tempsv)) { - SWIG_croak("expected a integer reference"); + SWIG_croak("expected an integer reference"); } dvalue = (short) SvIV(tempsv); $1 = &dvalue; @@ -112,7 +112,7 @@ as follows : } tempsv = SvRV($input); if (!SvIOK(tempsv)) { - SWIG_croak("expected a integer reference"); + SWIG_croak("expected an integer reference"); } dvalue = (long) SvIV(tempsv); $1 = &dvalue; @@ -125,7 +125,7 @@ as follows : } tempsv = SvRV($input); if (!SvIOK(tempsv)) { - SWIG_croak("expected a integer reference"); + SWIG_croak("expected an integer reference"); } dvalue = (unsigned int) SvUV(tempsv); $1 = &dvalue; @@ -138,7 +138,7 @@ as follows : } tempsv = SvRV($input); if (!SvIOK(tempsv)) { - SWIG_croak("expected a integer reference"); + SWIG_croak("expected an integer reference"); } dvalue = (unsigned short) SvUV(tempsv); $1 = &dvalue; @@ -151,7 +151,7 @@ as follows : } tempsv = SvRV($input); if (!SvIOK(tempsv)) { - SWIG_croak("expected a integer reference"); + SWIG_croak("expected an integer reference"); } dvalue = (unsigned long) SvUV(tempsv); $1 = &dvalue; @@ -165,7 +165,7 @@ as follows : } tempsv = SvRV($input); if (!SvIOK(tempsv)) { - SWIG_croak("expected a integer reference"); + SWIG_croak("expected an integer reference"); } dvalue = (unsigned char) SvUV(tempsv); $1 = &dvalue; @@ -179,7 +179,7 @@ as follows : } tempsv = SvRV($input); if (!SvIOK(tempsv)) { - SWIG_croak("expected a integer reference"); + SWIG_croak("expected an integer reference"); } dvalue = (signed char) SvIV(tempsv); $1 = &dvalue; @@ -193,7 +193,7 @@ as follows : } tempsv = SvRV($input); if (!SvIOK(tempsv)) { - SWIG_croak("expected a integer reference"); + SWIG_croak("expected an integer reference"); } dvalue = SvIV(tempsv) ? true : false; $1 = &dvalue; From ff2df5b288d2cff0953f3836d46106741f3e7bd1 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 8 Aug 2012 09:30:08 +0000 Subject: [PATCH 0165/1160] Fix some minor typos in the doc git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13560 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Go.html | 2 +- Doc/Manual/Ocaml.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index cd39d1fa1..78a58df28 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -498,7 +498,7 @@ into Go types.

    Because of limitations in the way output arguments are processed in swig, a function with output arguments will not have multiple return values. Instead, you must pass a pointer into the C++ function to tell it where to -store the ouput value. In go, you supply a slice in the place of the output +store the output value. In go, you supply a slice in the place of the output argument.

    For example, suppose you were trying to wrap the modf() function in the diff --git a/Doc/Manual/Ocaml.html b/Doc/Manual/Ocaml.html index ba8aa5fa9..127be904d 100644 --- a/Doc/Manual/Ocaml.html +++ b/Doc/Manual/Ocaml.html @@ -126,7 +126,7 @@ the resulting .ml and .mli files as well, and do the final link with -custom

    -The O'Caml SWIG module now requires you to compile a module (Swig) +The OCaml SWIG module now requires you to compile a module (Swig) separately. In addition to aggregating common SWIG functionality, the Swig module contains the data structure that represents C/C++ values. This allows easier data sharing between modules if two or more are combined, because From c8b8d4f50dbf29856a4d87f1887792b78530d643 Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Wed, 8 Aug 2012 14:13:37 +0000 Subject: [PATCH 0166/1160] add pair to stl.i git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13562 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/r/stl.i | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/r/stl.i b/Lib/r/stl.i index 9656ee6d4..37e2ccbf4 100644 --- a/Lib/r/stl.i +++ b/Lib/r/stl.i @@ -1,8 +1,10 @@ /* initial STL definition. extended as needed in each language */ %include std_common.i %include std_vector.i +%include std_pair.i %include std_string.i + From 3b8bc08be706743746fff4f18e51d521ad5bc1e2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 8 Aug 2012 22:24:46 +0000 Subject: [PATCH 0167/1160] Suppress -Werror=unused-but-set-variable gcc warning in Python wrappers git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13571 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Lib/python/pyinit.swg | 1 + 2 files changed, 4 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index e69c7d1dc..b8a80cfed 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.8 (in progress) =========================== +2012-08-05: wsfulton + [Python] #3530021 Fix unused variable warning. + 2012-08-05: wsfulton [C#] Fix #3536360 - Invalid code sometimes being generated for director methods with many arguments. diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 7a32a5046..6a6de0963 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -398,6 +398,7 @@ SWIG_init(void) { m = Py_InitModule((char *) SWIG_name, SwigMethods); #endif md = d = PyModule_GetDict(m); + (void)md; SWIG_InitializeModule(0); From fad95da7f5b3ee609d54d4f65981fe27879bde9a Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Sun, 12 Aug 2012 15:21:39 +0000 Subject: [PATCH 0168/1160] change R components so that pointers are visible through ref git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13601 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/r/rtype.swg | 46 +++++++++++++++++++++++++++++--------------- Source/Modules/r.cxx | 6 +++++- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg index 6af45cf40..007eaf140 100644 --- a/Lib/r/rtype.swg +++ b/Lib/r/rtype.swg @@ -12,6 +12,8 @@ %apply int {unsigned int} %apply int {short} %apply int {unsigned short} +%apply int {signed char} +%apply int {unsigned char} %typemap("rtype") long, long *, long & "integer"; %apply long {long long} @@ -36,10 +38,9 @@ %typemap("rtype") SWIGTYPE & "$R_class"; %typemap("rtype") SWIGTYPE "$&R_class"; -%typemap("rtypecheck") int, int &, long, long &, - unsigned char, unsigned char & +%typemap("rtypecheck") int, int &, long, long & %{ (is.integer($arg) || is.numeric($arg)) && length($arg) == 1 %} -%typemap("rtypecheck") int *, long *, unsigned char * +%typemap("rtypecheck") int *, long * %{ is.integer($arg) || is.numeric($arg) %} @@ -107,9 +108,8 @@ %typemap(scoercein) enum SWIGTYPE *const %{ $input = enumToInteger($input, "$R_class"); %} - %typemap(scoercein) SWIGTYPE, SWIGTYPE *, SWIGTYPE *const, SWIGTYPE & - %{ %} + %{ if (.hasSlot($input, "ref")) $input = slot($input,"ref") %} /* %typemap(scoercein) SWIGTYPE *, SWIGTYPE *const @@ -141,7 +141,7 @@ long *, long &, long[ANY] - "$input = as.integer($input); "; + "$input = as.integer($input);"; %typemap(scoercein) char *, string, std::string, string &, std::string & @@ -159,18 +159,30 @@ string &, std::string & %typemap(scoerceout) enum SWIGTYPE *const %{ $result = enumToInteger($result, "$R_class"); %} +#%typemap(scoerceout) SWIGTYPE +# %{ class($result) <- "$&R_class"; %} -%typemap(scoerceout) SWIGTYPE - %{ class($result) <- "$&R_class"; %} +#%typemap(scoerceout) SWIGTYPE & +# %{ class($result) <- "$R_class"; %} -%typemap(scoerceout) SWIGTYPE & - %{ class($result) <- "$R_class"; %} +#%typemap(scoerceout) SWIGTYPE * +# %{ class($result) <- "$R_class"; %} -%typemap(scoerceout) SWIGTYPE * - %{ class($result) <- "$R_class"; %} +#%typemap(scoerceout) SWIGTYPE *const +# %{ class($result) <- "$R_class"; %} + + %typemap(scoerceout) SWIGTYPE + %{ $result <- new("$&R_class", ref=$result); %} + + %typemap(scoerceout) SWIGTYPE & + %{ $result <- new("$R_class", ref=$result) ; %} + + %typemap(scoerceout) SWIGTYPE * + %{ $result <- new("$R_class", ref=$result) ; %} + + %typemap(scoerceout) SWIGTYPE *const + %{ $result <- new("$R_class", ref=$result) ; %} -%typemap(scoerceout) SWIGTYPE *const - %{ class($result) <- "$R_class"; %} /* Override the SWIGTYPE * above. */ %typemap(scoerceout) char, @@ -208,8 +220,10 @@ string &, std::string & signed long &, unsigned long, unsigned long &, - unsigned char *, - unsigned char & + signed char, + signed char &, + unsigned char, + unsigned char & %{ %} #if 0 diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index f163c8b30..b589bfda7 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1891,6 +1891,9 @@ int R::functionWrapper(Node *n) { if(nargs == -1) nargs = getFunctionPointerNumArgs(p, tt); + Printv(sfun->code, "if (.hasSlot(", name, ", \"ref\")) {\n", + name, " = slot(", name, ", \"ref\");\n", + "}\n", NIL); String *snargs = NewStringf("%d", nargs); Printv(sfun->code, "if(is.function(", name, ")) {", "\n", "assert('...' %in% names(formals(", name, @@ -2112,7 +2115,8 @@ int R::functionWrapper(Node *n) { { String *finalizer = NewString(iname); Replace(finalizer, "new_", "", DOH_REPLACE_FIRST); - Printf(sfun->code, "reg.finalizer(ans, delete_%s)\n", finalizer); + Printf(sfun->code, "if (.hasSlot(ans, \"ref\")) {\n" + "reg.finalizer(ans@ref, delete_%s); }\n", finalizer); } Printf(sfun->code, "ans\n"); } From 009c191430d2e87e19ce33ed1bce43f3939f8c1b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 13 Aug 2012 21:41:08 +0000 Subject: [PATCH 0169/1160] Add assumeoverride feature option for Java directors to improve performance when it can be assumed that all methods are overridden by the Java derived classes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13606 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 +++ Doc/Manual/Java.html | 23 +++++++++++++- Examples/test-suite/common.mk | 1 + .../java_director_assumeoverride_runme.java | 27 +++++++++++++++++ .../test-suite/java_director_assumeoverride.i | 30 +++++++++++++++++++ Source/Modules/java.cxx | 30 +++++++++++++++---- 6 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 Examples/test-suite/java/java_director_assumeoverride_runme.java create mode 100644 Examples/test-suite/java_director_assumeoverride.i diff --git a/CHANGES.current b/CHANGES.current index b8a80cfed..78e39dbc1 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.8 (in progress) =========================== +2012-08-13: wsfulton + [Java] Patch from David Baum to add the assumeoverride feature for Java directors to + improve performance when all overridden methods can be assumed to be overridden. + 2012-08-05: wsfulton [Python] #3530021 Fix unused variable warning. diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 8a081f46d..cfee64fa0 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -86,6 +86,7 @@

  • Overhead and code bloat
  • Simple directors example
  • Director threading issues +
  • Director performance tuning
  • Accessing protected members
  • Common customization features @@ -3525,6 +3526,27 @@ Macros can be defined on the commandline when compiling your C++ code, or altern
  • +

    24.5.6 Director performance tuning

    + +

    +When a new instance of a director (or subclass) is created in Java, the C++ side of the director performs a runtime check per director method to determine if that particular method is overridden in Java or if it should invoke the C++ base implementation directly. Although this makes initialization slightly more expensive, it is generally a good overall tradeoff. +

    + +

    +However, if all director methods are expected to usually be overridden by Java subclasses, then initialization can be made faster by avoiding these checks via the assumeoverride attribute. For example: +

    + +
    +
    +%feature("director", assumeoverride=1) Foo;
    +
    +
    + +

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

    + +

    24.6 Accessing protected members

    @@ -7862,4 +7884,3 @@ Many of these have runtime tests in the java subdirectory. - diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index f6a8056e5..ef65fbb1b 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -161,6 +161,7 @@ CPP_TEST_CASES += \ destructor_reprotected \ director_abstract \ director_alternating \ + director_assumeoverride \ director_basic \ director_binary_string \ director_classes \ diff --git a/Examples/test-suite/java/java_director_assumeoverride_runme.java b/Examples/test-suite/java/java_director_assumeoverride_runme.java new file mode 100644 index 000000000..e876a79c9 --- /dev/null +++ b/Examples/test-suite/java/java_director_assumeoverride_runme.java @@ -0,0 +1,27 @@ + +import java_director_assumeoverride.*; + +public class java_director_assumeoverride_runme { + + static { + try { + System.loadLibrary("java_director_assumeoverride"); + } 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); + } + } + + static class MyOverrideMe extends OverrideMe { + } + + public static void main(String argv[]) { + OverrideMe overrideMe = new MyOverrideMe(); + + // MyOverrideMe doesn't actually override func(), but because assumeoverride + // was set to true, the C++ side will believe it was overridden. + if (!java_director_assumeoverride.isFuncOverridden(overrideMe)) { + throw new RuntimeException ( "isFuncOverridden()" ); + } + } +} diff --git a/Examples/test-suite/java_director_assumeoverride.i b/Examples/test-suite/java_director_assumeoverride.i new file mode 100644 index 000000000..7364a3d58 --- /dev/null +++ b/Examples/test-suite/java_director_assumeoverride.i @@ -0,0 +1,30 @@ +%module(directors="1") java_director_assumeoverride +#pragma SWIG nowarn=SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR + +%{ +class OverrideMe { +public: + virtual ~OverrideMe() {} + virtual void func() {}; +}; + +#include "java_director_assumeoverride_wrap.h" +bool isFuncOverridden(OverrideMe* f) { + SwigDirector_OverrideMe* director = dynamic_cast(f); + if (!director) { + return false; + } + return director->swig_overrides(0); +} + +%} + +%feature("director", assumeoverride=1) OverrideMe; + +class OverrideMe { +public: + virtual ~OverrideMe(); + virtual void func(); +}; + +bool isFuncOverridden(OverrideMe* f); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index ffc4d8d97..1c39aec11 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -4318,12 +4318,30 @@ public: Printf(w->code, " methods[i].base_methid = jenv->GetMethodID(baseclass, methods[i].mname, methods[i].mdesc);\n"); Printf(w->code, " if (!methods[i].base_methid) return;\n"); Printf(w->code, " }\n"); - Printf(w->code, " swig_override[i] = false;\n"); - Printf(w->code, " if (derived) {\n"); - Printf(w->code, " jmethodID methid = jenv->GetMethodID(jcls, methods[i].mname, methods[i].mdesc);\n"); - Printf(w->code, " swig_override[i] = (methid != methods[i].base_methid);\n"); - Printf(w->code, " jenv->ExceptionClear();\n"); - Printf(w->code, " }\n"); + // Generally, derived classes have a mix of overridden and + // non-overridden methods and it is worth making a GetMethodID + // check during initialization to determine if each method is + // overridden, thus avoiding unnecessary calls into Java. + // + // On the other hand, when derived classes are + // expected to override all director methods then the + // GetMethodID calls are inefficient, and it is better to let + // the director unconditionally call up into Java. The resulting code + // will still behave correctly (though less efficiently) when Java + // code doesn't override a given method. + // + // The assumeoverride feature on a director controls whether or not + // overrides are assumed. + if (GetFlag(n, "feature:director:assumeoverride")) { + Printf(w->code, " swig_override[i] = derived;\n"); + } else { + Printf(w->code, " swig_override[i] = false;\n"); + Printf(w->code, " if (derived) {\n"); + Printf(w->code, " jmethodID methid = jenv->GetMethodID(jcls, methods[i].mname, methods[i].mdesc);\n"); + Printf(w->code, " swig_override[i] = (methid != methods[i].base_methid);\n"); + Printf(w->code, " jenv->ExceptionClear();\n"); + Printf(w->code, " }\n"); + } Printf(w->code, "}\n"); } else { Printf(f_directors_h, "public:\n"); From 289b8bb269f29cca766b61cab12ee4c883749e7d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 13 Aug 2012 21:59:14 +0000 Subject: [PATCH 0170/1160] Fix additio of assumeoverride testcase git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13607 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 1 - Examples/test-suite/java/Makefile.in | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index ef65fbb1b..f6a8056e5 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -161,7 +161,6 @@ CPP_TEST_CASES += \ destructor_reprotected \ director_abstract \ director_alternating \ - director_assumeoverride \ director_basic \ director_binary_string \ director_classes \ diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index ef3c981a4..0b3f7babb 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -23,6 +23,7 @@ CPP_TEST_CASES = \ intermediary_classname \ java_constants \ java_director \ + java_director_assumeoverride \ java_enums \ java_lib_arrays_dimensionless \ java_lib_various \ From 68862691e6229237301ae7af10a5c894e94353c6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 15 Aug 2012 07:48:57 +0000 Subject: [PATCH 0171/1160] Fix #3541744 - Missing PyInt_FromSize_t calls for Python 3 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13608 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Lib/python/pyhead.swg | 1 + 2 files changed, 4 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 78e39dbc1..eb109a6b0 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.8 (in progress) =========================== +2012-08-15: wsfulton + [Python] Fix #3541744 - Missing PyInt_FromSize_t calls for Python 3. + 2012-08-13: wsfulton [Java] Patch from David Baum to add the assumeoverride feature for Java directors to improve performance when all overridden methods can be assumed to be overridden. diff --git a/Lib/python/pyhead.swg b/Lib/python/pyhead.swg index 803cd0745..c333e9d89 100644 --- a/Lib/python/pyhead.swg +++ b/Lib/python/pyhead.swg @@ -5,6 +5,7 @@ #define PyInt_Check(x) PyLong_Check(x) #define PyInt_AsLong(x) PyLong_AsLong(x) #define PyInt_FromLong(x) PyLong_FromLong(x) +#define PyInt_FromSize_t(x) PyLong_FromSize_t(x) #define PyString_Check(name) PyBytes_Check(name) #define PyString_FromString(x) PyUnicode_FromString(x) #define PyString_Format(fmt, args) PyUnicode_Format(fmt, args) From 81b755dadcdd8fdfa8b6ff99ce98d141bf518f53 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 15 Aug 2012 22:35:24 +0000 Subject: [PATCH 0172/1160] Better error handling in SWIG_Python_NewShadowInstance and SWIG_Python_NewPointerObj to fix seg fault as mentioned on swig-devel mailing list email thread - 'Fix python3 abc set' git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13618 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyrun.swg | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index e1924a1a4..d621f4dee 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1331,23 +1331,29 @@ SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this) } else { #if PY_VERSION_HEX >= 0x03000000 inst = PyBaseObject_Type.tp_new((PyTypeObject*) data->newargs, Py_None, Py_None); - PyObject_SetAttr(inst, SWIG_This(), swig_this); - Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG; + if (inst) { + PyObject_SetAttr(inst, SWIG_This(), swig_this); + Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG; + } #else PyObject *dict = PyDict_New(); - PyDict_SetItem(dict, SWIG_This(), swig_this); - inst = PyInstance_NewRaw(data->newargs, dict); - Py_DECREF(dict); + if (dict) { + PyDict_SetItem(dict, SWIG_This(), swig_this); + inst = PyInstance_NewRaw(data->newargs, dict); + Py_DECREF(dict); + } #endif } return inst; #else #if (PY_VERSION_HEX >= 0x02010000) - PyObject *inst; + PyObject *inst = 0; PyObject *dict = PyDict_New(); - PyDict_SetItem(dict, SWIG_This(), swig_this); - inst = PyInstance_NewRaw(data->newargs, dict); - Py_DECREF(dict); + if (dict) { + PyDict_SetItem(dict, SWIG_This(), swig_this); + inst = PyInstance_NewRaw(data->newargs, dict); + Py_DECREF(dict); + } return (PyObject *) inst; #else PyInstanceObject *inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type); @@ -1454,12 +1460,10 @@ SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int f assert(!(flags & SWIG_BUILTIN_TP_INIT)); robj = SwigPyObject_New(ptr, type, own); - if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { + if (robj && clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); - if (inst) { - Py_DECREF(robj); - robj = inst; - } + Py_DECREF(robj); + robj = inst; } return robj; } From 049035ff3ec8152b74ebad640f6127b432434090 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 15 Aug 2012 22:36:15 +0000 Subject: [PATCH 0173/1160] Add discard and add methods to std::set and std::multiset wrappers so that pyabc.i can be used ensuring MutableSet is a valid abstract base class git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13619 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 +++++ Examples/test-suite/python/python_abstractbase_runme3.py | 8 ++++++++ Lib/python/std_set.i | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index eb109a6b0..651df4e2e 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.8 (in progress) =========================== +2012-08-15: wsfulton + [Python] Add discard and add methods to std::set wrappers so that pyabc.i can be used ensuring + MutableSet is a valid abstract base class for std::set. As reported by Alexey Sokolov. + Similarly for std::multiset. + 2012-08-15: wsfulton [Python] Fix #3541744 - Missing PyInt_FromSize_t calls for Python 3. diff --git a/Examples/test-suite/python/python_abstractbase_runme3.py b/Examples/test-suite/python/python_abstractbase_runme3.py index b7593f109..94dee3ff7 100644 --- a/Examples/test-suite/python/python_abstractbase_runme3.py +++ b/Examples/test-suite/python/python_abstractbase_runme3.py @@ -10,3 +10,11 @@ assert issubclass(IntSet, MutableSet) assert issubclass(IntMultiset, MutableSet) assert issubclass(IntVector, MutableSequence) assert issubclass(IntList, MutableSequence) + +mapii = Mapii() +multimapii = Multimapii() +intset = IntSet() +intmultiset = IntMultiset() +intvector = IntVector() +intlist = IntList() + diff --git a/Lib/python/std_set.i b/Lib/python/std_set.i index 59f69cdc9..53f97e475 100644 --- a/Lib/python/std_set.i +++ b/Lib/python/std_set.i @@ -49,6 +49,14 @@ return *(swig::cgetpos(self, i)); } + void add(value_type x) { + self->insert(x); + } + + void discard(value_type x) { + self->erase(x); + } + }; %enddef From c20cacad8731454b2125ba224b48d606e915d966 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 15 Aug 2012 23:04:26 +0000 Subject: [PATCH 0174/1160] Add some missing STL container typedefs for Perl git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13620 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Lib/perl5/std_list.i | 8 ++++++++ Lib/perl5/std_vector.i | 9 +++++++++ Lib/std/_std_deque.i | 9 +++++++-- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 651df4e2e..a6fe5815d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.8 (in progress) =========================== +2012-08-15: wsfulton + [Perl] Add size_type, value_type, const_reference to the STL containers. + 2012-08-15: wsfulton [Python] Add discard and add methods to std::set wrappers so that pyabc.i can be used ensuring MutableSet is a valid abstract base class for std::set. As reported by Alexey Sokolov. diff --git a/Lib/perl5/std_list.i b/Lib/perl5/std_list.i index c6bca18f6..ea264d6a1 100644 --- a/Lib/perl5/std_list.i +++ b/Lib/perl5/std_list.i @@ -188,6 +188,10 @@ namespace std { } } public: + typedef size_t size_type; + typedef T value_type; + typedef const value_type& const_reference; + list(); list(const list &); @@ -337,6 +341,10 @@ namespace std { } } public: + typedef size_t size_type; + typedef T value_type; + typedef const value_type& const_reference; + list(); list(const list &); diff --git a/Lib/perl5/std_vector.i b/Lib/perl5/std_vector.i index 0a61c31e0..a3998ff92 100644 --- a/Lib/perl5/std_vector.i +++ b/Lib/perl5/std_vector.i @@ -180,6 +180,9 @@ namespace std { } } public: + typedef size_t size_type; + typedef T value_type; + typedef const value_type& const_reference; vector(unsigned int size = 0); vector(unsigned int size, const T& value); vector(const vector &); @@ -349,6 +352,9 @@ namespace std { } } public: + typedef size_t size_type; + typedef T value_type; + typedef const value_type& const_reference; vector(unsigned int size = 0); vector(unsigned int size, T *value); vector(const vector &); @@ -517,6 +523,9 @@ namespace std { } } public: + typedef size_t size_type; + typedef T value_type; + typedef const value_type& const_reference; vector(unsigned int size = 0); vector(unsigned int size, T value); vector(const vector &); diff --git a/Lib/std/_std_deque.i b/Lib/std/_std_deque.i index 4234789a8..7dd3552db 100644 --- a/Lib/std/_std_deque.i +++ b/Lib/std/_std_deque.i @@ -25,8 +25,13 @@ */ %define %std_deque_methods_noempty(T) - typedef T &reference; - typedef const T& const_reference; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; deque(); deque(unsigned int size, const T& value=T()); From a0d15a7e03c29d9138f90eb0e5c4fc7f460183df Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 15 Aug 2012 23:36:28 +0000 Subject: [PATCH 0175/1160] Better fix than r6987 to silence warning git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13621 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/swiginit.swg | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Lib/swiginit.swg b/Lib/swiginit.swg index 903ac548f..42c160483 100644 --- a/Lib/swiginit.swg +++ b/Lib/swiginit.swg @@ -52,13 +52,11 @@ extern "C" { SWIGRUNTIME void -SWIG_InitializeModule(void *clientdata) { +SWIG_InitializeModule(void *SWIGUNUSEDPARM(clientdata)) { size_t i; swig_module_info *module_head, *iter; int found, init; - clientdata = clientdata; - /* check to see if the circular list has been setup, if not, set it up */ if (swig_module.next==0) { /* Initialize the swig_module */ From 11323af905a3ff8d6fadc4f2fe017d54a2ea964e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 16 Aug 2012 22:35:36 +0000 Subject: [PATCH 0176/1160] A working fix to silence unused warnings - fixes r13621 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13637 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/swiginit.swg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/swiginit.swg b/Lib/swiginit.swg index 42c160483..d160cfaf1 100644 --- a/Lib/swiginit.swg +++ b/Lib/swiginit.swg @@ -52,10 +52,11 @@ extern "C" { SWIGRUNTIME void -SWIG_InitializeModule(void *SWIGUNUSEDPARM(clientdata)) { +SWIG_InitializeModule(void *clientdata) { size_t i; swig_module_info *module_head, *iter; int found, init; + (void *)clientdata; /* check to see if the circular list has been setup, if not, set it up */ if (swig_module.next==0) { From a6764a156cca21300cc4ae6ed756114af4728e3e Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Sat, 18 Aug 2012 13:53:47 +0000 Subject: [PATCH 0177/1160] use print to output sprintf git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13650 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/r/class/runme.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/r/class/runme.R b/Examples/r/class/runme.R index 4a2028553..f4f8f35de 100644 --- a/Examples/r/class/runme.R +++ b/Examples/r/class/runme.R @@ -28,8 +28,8 @@ square$x <- -10 square$y <- 5 print("Here is their current position:") -sprintf(" Circle = (%f, %f)", circle$x,circle$y) -sprintf(" Square = (%f, %f)", square$x,square$y) +print(sprintf(" Circle = (%f, %f)", circle$x,circle$y)) +print(sprintf(" Square = (%f, %f)", square$x,square$y)) # ----- Call some methods ----- @@ -37,7 +37,7 @@ print ("Here are some properties of the shapes:") sapply(c(circle, square), function(o) { -sprintf(" area = %f perimeter = %f", o$area(), o$perimeter()) +print(sprintf(" area = %f perimeter = %f", o$area(), o$perimeter())) }) print("Guess I'll clean up now") From e216963630221c568f9ef933f190826c09d85539 Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Mon, 20 Aug 2012 15:54:36 +0000 Subject: [PATCH 0178/1160] back out of previous change. There seem to be version dependent changes in what gets printed out and previous change causes double printing in earlier versions of R git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13685 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/r/class/runme.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/r/class/runme.R b/Examples/r/class/runme.R index f4f8f35de..4a2028553 100644 --- a/Examples/r/class/runme.R +++ b/Examples/r/class/runme.R @@ -28,8 +28,8 @@ square$x <- -10 square$y <- 5 print("Here is their current position:") -print(sprintf(" Circle = (%f, %f)", circle$x,circle$y)) -print(sprintf(" Square = (%f, %f)", square$x,square$y)) +sprintf(" Circle = (%f, %f)", circle$x,circle$y) +sprintf(" Square = (%f, %f)", square$x,square$y) # ----- Call some methods ----- @@ -37,7 +37,7 @@ print ("Here are some properties of the shapes:") sapply(c(circle, square), function(o) { -print(sprintf(" area = %f perimeter = %f", o$area(), o$perimeter())) +sprintf(" area = %f perimeter = %f", o$area(), o$perimeter()) }) print("Guess I'll clean up now") From 9ceb42ea6821a37e65edfea24789ce1b943fabda Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 20 Aug 2012 21:12:42 +0000 Subject: [PATCH 0179/1160] Section numbering update git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13711 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Contents.html | 1 + Doc/Manual/Java.html | 1 + 2 files changed, 2 insertions(+) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 4af66298c..bdb3aa9f5 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -912,6 +912,7 @@
  • Overhead and code bloat
  • Simple directors example
  • Director threading issues +
  • Director performance tuning
  • Accessing protected members
  • Common customization features diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index cfee64fa0..ed99549b0 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -3528,6 +3528,7 @@ Macros can be defined on the commandline when compiling your C++ code, or altern

    24.5.6 Director performance tuning

    +

    When a new instance of a director (or subclass) is created in Java, the C++ side of the director performs a runtime check per director method to determine if that particular method is overridden in Java or if it should invoke the C++ base implementation directly. Although this makes initialization slightly more expensive, it is generally a good overall tradeoff.

    From 9da9df9ee8b01bc5cefc6739b0186ecaec50b6d3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 20 Aug 2012 21:14:24 +0000 Subject: [PATCH 0180/1160] Release notes for 2.0.8 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13712 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- RELEASENOTES | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RELEASENOTES b/RELEASENOTES index a69631a85..e09e2cad0 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -4,6 +4,11 @@ and CHANGES files. Release Notes ============= +SWIG-2.0.8 summary: +- Fix a couple of regressions introduced in 2.0.5 and 2.0.7. +- Improved using declarations and using directives support. +- Minor fixes/enhancements for C#, Java, Octave, Perl and Python. + SWIG-2.0.7 summary: - Important regression fixes since 2.0.5 for typemaps in general and in Python. From be1c4d2e68ccdef00648e745db432114b4614d91 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 20 Aug 2012 21:20:19 +0000 Subject: [PATCH 0181/1160] Revert r13601 as it breaks older versions of R git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13713 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/r/rtype.swg | 46 +++++++++++++++----------------------------- Source/Modules/r.cxx | 6 +----- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg index 007eaf140..6af45cf40 100644 --- a/Lib/r/rtype.swg +++ b/Lib/r/rtype.swg @@ -12,8 +12,6 @@ %apply int {unsigned int} %apply int {short} %apply int {unsigned short} -%apply int {signed char} -%apply int {unsigned char} %typemap("rtype") long, long *, long & "integer"; %apply long {long long} @@ -38,9 +36,10 @@ %typemap("rtype") SWIGTYPE & "$R_class"; %typemap("rtype") SWIGTYPE "$&R_class"; -%typemap("rtypecheck") int, int &, long, long & +%typemap("rtypecheck") int, int &, long, long &, + unsigned char, unsigned char & %{ (is.integer($arg) || is.numeric($arg)) && length($arg) == 1 %} -%typemap("rtypecheck") int *, long * +%typemap("rtypecheck") int *, long *, unsigned char * %{ is.integer($arg) || is.numeric($arg) %} @@ -108,8 +107,9 @@ %typemap(scoercein) enum SWIGTYPE *const %{ $input = enumToInteger($input, "$R_class"); %} + %typemap(scoercein) SWIGTYPE, SWIGTYPE *, SWIGTYPE *const, SWIGTYPE & - %{ if (.hasSlot($input, "ref")) $input = slot($input,"ref") %} + %{ %} /* %typemap(scoercein) SWIGTYPE *, SWIGTYPE *const @@ -141,7 +141,7 @@ long *, long &, long[ANY] - "$input = as.integer($input);"; + "$input = as.integer($input); "; %typemap(scoercein) char *, string, std::string, string &, std::string & @@ -159,30 +159,18 @@ string &, std::string & %typemap(scoerceout) enum SWIGTYPE *const %{ $result = enumToInteger($result, "$R_class"); %} -#%typemap(scoerceout) SWIGTYPE -# %{ class($result) <- "$&R_class"; %} -#%typemap(scoerceout) SWIGTYPE & -# %{ class($result) <- "$R_class"; %} +%typemap(scoerceout) SWIGTYPE + %{ class($result) <- "$&R_class"; %} -#%typemap(scoerceout) SWIGTYPE * -# %{ class($result) <- "$R_class"; %} +%typemap(scoerceout) SWIGTYPE & + %{ class($result) <- "$R_class"; %} -#%typemap(scoerceout) SWIGTYPE *const -# %{ class($result) <- "$R_class"; %} - - %typemap(scoerceout) SWIGTYPE - %{ $result <- new("$&R_class", ref=$result); %} - - %typemap(scoerceout) SWIGTYPE & - %{ $result <- new("$R_class", ref=$result) ; %} - - %typemap(scoerceout) SWIGTYPE * - %{ $result <- new("$R_class", ref=$result) ; %} - - %typemap(scoerceout) SWIGTYPE *const - %{ $result <- new("$R_class", ref=$result) ; %} +%typemap(scoerceout) SWIGTYPE * + %{ class($result) <- "$R_class"; %} +%typemap(scoerceout) SWIGTYPE *const + %{ class($result) <- "$R_class"; %} /* Override the SWIGTYPE * above. */ %typemap(scoerceout) char, @@ -220,10 +208,8 @@ string &, std::string & signed long &, unsigned long, unsigned long &, - signed char, - signed char &, - unsigned char, - unsigned char & + unsigned char *, + unsigned char & %{ %} #if 0 diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index b589bfda7..f163c8b30 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1891,9 +1891,6 @@ int R::functionWrapper(Node *n) { if(nargs == -1) nargs = getFunctionPointerNumArgs(p, tt); - Printv(sfun->code, "if (.hasSlot(", name, ", \"ref\")) {\n", - name, " = slot(", name, ", \"ref\");\n", - "}\n", NIL); String *snargs = NewStringf("%d", nargs); Printv(sfun->code, "if(is.function(", name, ")) {", "\n", "assert('...' %in% names(formals(", name, @@ -2115,8 +2112,7 @@ int R::functionWrapper(Node *n) { { String *finalizer = NewString(iname); Replace(finalizer, "new_", "", DOH_REPLACE_FIRST); - Printf(sfun->code, "if (.hasSlot(ans, \"ref\")) {\n" - "reg.finalizer(ans@ref, delete_%s); }\n", finalizer); + Printf(sfun->code, "reg.finalizer(ans, delete_%s)\n", finalizer); } Printf(sfun->code, "ans\n"); } From 8f16b81a4fb03bb66fb96e030559afdc852629c1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 20 Aug 2012 21:21:24 +0000 Subject: [PATCH 0182/1160] 2.0.8 release date added git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13714 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- ANNOUNCE | 2 +- CHANGES.current | 4 ++-- Doc/Manual/Sections.html | 2 +- README | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 4fa6694f4..b3a6e48fc 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,4 +1,4 @@ -*** ANNOUNCE: SWIG 2.0.8 (in progress) *** +*** ANNOUNCE: SWIG 2.0.8 (20 August 2012) *** http://www.swig.org diff --git a/CHANGES.current b/CHANGES.current index a6fe5815d..3c610d0b9 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,8 +2,8 @@ Below are the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.8 (in progress) -=========================== +Version 2.0.8 (20 August 2012) +============================== 2012-08-15: wsfulton [Perl] Add size_type, value_type, const_reference to the STL containers. diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 0e78de84a..6dd4d3683 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

    SWIG-2.0 Documentation

    -Last update : SWIG-2.0.8 (in progress) +Last update : SWIG-2.0.8 (20 August 2012)

    Sections

    diff --git a/README b/README index 154efc013..45a9b047f 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.8 (in progress) +Version: 2.0.8 (20 August 2012) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, Ocaml, Lua, From 0e4e0672e09be1caa20102f11115c250266a2785 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 21 Aug 2012 22:11:07 +0000 Subject: [PATCH 0183/1160] Bump version to 2.0.9 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13718 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- ANNOUNCE | 8 +- CHANGES | 157 ++++++++++++++++++++++++++++++++++++++ CHANGES.current | 158 +-------------------------------------- Doc/Manual/Sections.html | 2 +- README | 2 +- configure.in | 2 +- 6 files changed, 166 insertions(+), 163 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index b3a6e48fc..f6a24967a 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,8 +1,8 @@ -*** ANNOUNCE: SWIG 2.0.8 (20 August 2012) *** +*** ANNOUNCE: SWIG 2.0.9 (in progress) *** http://www.swig.org -We're pleased to announce SWIG-2.0.8, the latest SWIG release. +We're pleased to announce SWIG-2.0.9, 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.8.tar.gz + http://prdownloads.sourceforge.net/swig/swig-2.0.9.tar.gz A Windows version is also available at - http://prdownloads.sourceforge.net/swig/swigwin-2.0.8.zip + http://prdownloads.sourceforge.net/swig/swigwin-2.0.9.zip Please report problems with this release to the swig-devel mailing list, details at http://www.swig.org/mail.html. diff --git a/CHANGES b/CHANGES index a63a66312..b485badd9 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,163 @@ SWIG (Simplified Wrapper and Interface Generator) See the CHANGES.current file for changes in the current version. See the RELEASENOTES file for a summary of changes in each release. +Version 2.0.8 (20 August 2012) +============================== + +2012-08-15: wsfulton + [Perl] Add size_type, value_type, const_reference to the STL containers. + +2012-08-15: wsfulton + [Python] Add discard and add methods to std::set wrappers so that pyabc.i can be used ensuring + MutableSet is a valid abstract base class for std::set. As reported by Alexey Sokolov. + Similarly for std::multiset. + +2012-08-15: wsfulton + [Python] Fix #3541744 - Missing PyInt_FromSize_t calls for Python 3. + +2012-08-13: wsfulton + [Java] Patch from David Baum to add the assumeoverride feature for Java directors to + improve performance when all overridden methods can be assumed to be overridden. + +2012-08-05: wsfulton + [Python] #3530021 Fix unused variable warning. + +2012-08-05: wsfulton + [C#] Fix #3536360 - Invalid code sometimes being generated for director methods + with many arguments. + +2012-08-05: wsfulton + [Perl] #3545877 - Don't undefine bool if defined by C99 stdbool.h - problem using + Perl 5.16 and later. + +2012-08-04: wsfulton + Remove incorrect warning (314) about target language keywords which were triggered + by using declarations and using directives. For example 'string' is a keyword in C#: + namespace std { class string; } + using std::string; + +2012-07-21: wsfulton + Fix display of pointers in various places on 64 bit systems - only 32 bits were being shown. + +2012-07-21: wsfulton + Fix gdb debugger functions 'swigprint' and 'locswigprint' to display to the gdb output window + rather than stdout. This fixes display problems in gdbtui and the ensures the output + appears where expected in other gdb based debuggers such as Eclipse CDT. + +2012-07-20: kwwette + [Octave] segfault-on-exit prevention hack now preserves exit status, and uses C99 _Exit(). + +2012-07-02: wsfulton + Fix Debian bug http://bugs.debian.org/672035, typemap copy failure - regression introduced + in swig-2.0.5: + %include + using std::pair; + %template(StrPair) pair; + +2012-07-02: wsfulton + Fix using declarations combined with using directives with forward class declarations so that + types are correctly found in scope for templates. Example: + + namespace Outer2 { + namespace Space2 { + template class Thing2; + } + } + using namespace Outer2; + using Space2::Thing2; + template class Thing2 {}; + // STILL BROKEN void useit2(Thing2 t) {} + void useit2a(Outer2::Space2::Thing2 t) {} + void useit2b(::Outer2::Space2::Thing2 t) {} + void useit2c(Space2::Thing2 t) {} + namespace Outer2 { + void useit2d(Space2::Thing2 t) {} + } + + %template(Thing2Int) Thing2; + + +2012-06-30: wsfulton + Fix template namespace problems for symbols declared with a forward class declarations, such as: + + namespace Space1 { + namespace Space2 { + template struct YYY; + } + template struct Space2::YYY { + T yyy(T h) { + return h; + } + }; + void testYYY1(Space1::Space2::YYY yy) {} + void testYYY2(Space2::YYY yy) {} + void testYYY3(::Space1::Space2::YYY yy) {} + } + + %template(YYYInt) Space1::Space2::YYY; + +2012-06-30: wsfulton + Fix namespace problems for symbols declared with a forward class declarations, such as: + + namespace Space1 { + namespace Space2 { + struct XXX; + struct YYY; + } + + struct Space2::YYY {}; + struct Space1::Space2::XXX {}; + + void testXXX2(Space2::XXX xx) {} + void testYYY2(Space2::YYY yy) {} + } + + where xx and yy were not recognised as the proxy classes XXX and YYY. + +2012-06-30: wsfulton + Fix using declarations combined with using directives with forward class declarations so that + types are correctly found in scope. + + namespace Outer2 { + namespace Space2 { + class Thing2; + } + } + using namespace Outer2; + using Space2::Thing2; + class Thing2 {}; + // None of the methods below correctly used the Thing2 proxy class + void useit2(Thing2 t) {} + void useit2a(Outer2::Space2::Thing2 t) {} + void useit2b(::Outer2::Space2::Thing2 t) {} + void useit2c(Space2::Thing2 t) {} + namespace Outer2 { + void useit2d(Space2::Thing2 t) {} + } + +2012-06-25: wsfulton + Fix using declarations combined with using directives so that types are correctly found in scope. + Example: + + namespace Outer2 { + namespace Space2 { + class Thing2 {}; + } + } + using namespace Outer2; // using directive + using Space2::Thing2; // using declaration + void useit2(Thing2 t) {} + + Similarly for templated classes. + +2012-05-29: wsfulton + Fix #3529601 - seg fault when a protected method has the "director" + feature but the parent class does not. Also fix similar problems with + the allprotected feature. + +2012-05-28: wsfulton + Fix seg fault when attempting to warn about an illegal destructor - #3530055, 3530078 and #3530118. + Version 2.0.7 (26 May 2012) =========================== 2012-05-26: wsfulton diff --git a/CHANGES.current b/CHANGES.current index 3c610d0b9..05b7f1a0d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,160 +2,6 @@ Below are the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.8 (20 August 2012) -============================== - -2012-08-15: wsfulton - [Perl] Add size_type, value_type, const_reference to the STL containers. - -2012-08-15: wsfulton - [Python] Add discard and add methods to std::set wrappers so that pyabc.i can be used ensuring - MutableSet is a valid abstract base class for std::set. As reported by Alexey Sokolov. - Similarly for std::multiset. - -2012-08-15: wsfulton - [Python] Fix #3541744 - Missing PyInt_FromSize_t calls for Python 3. - -2012-08-13: wsfulton - [Java] Patch from David Baum to add the assumeoverride feature for Java directors to - improve performance when all overridden methods can be assumed to be overridden. - -2012-08-05: wsfulton - [Python] #3530021 Fix unused variable warning. - -2012-08-05: wsfulton - [C#] Fix #3536360 - Invalid code sometimes being generated for director methods - with many arguments. - -2012-08-05: wsfulton - [Perl] #3545877 - Don't undefine bool if defined by C99 stdbool.h - problem using - Perl 5.16 and later. - -2012-08-04: wsfulton - Remove incorrect warning (314) about target language keywords which were triggered - by using declarations and using directives. For example 'string' is a keyword in C#: - namespace std { class string; } - using std::string; - -2012-07-21: wsfulton - Fix display of pointers in various places on 64 bit systems - only 32 bits were being shown. - -2012-07-21: wsfulton - Fix gdb debugger functions 'swigprint' and 'locswigprint' to display to the gdb output window - rather than stdout. This fixes display problems in gdbtui and the ensures the output - appears where expected in other gdb based debuggers such as Eclipse CDT. - -2012-07-20: kwwette - [Octave] segfault-on-exit prevention hack now preserves exit status, and uses C99 _Exit(). - -2012-07-02: wsfulton - Fix Debian bug http://bugs.debian.org/672035, typemap copy failure - regression introduced - in swig-2.0.5: - %include - using std::pair; - %template(StrPair) pair; - -2012-07-02: wsfulton - Fix using declarations combined with using directives with forward class declarations so that - types are correctly found in scope for templates. Example: - - namespace Outer2 { - namespace Space2 { - template class Thing2; - } - } - using namespace Outer2; - using Space2::Thing2; - template class Thing2 {}; - // STILL BROKEN void useit2(Thing2 t) {} - void useit2a(Outer2::Space2::Thing2 t) {} - void useit2b(::Outer2::Space2::Thing2 t) {} - void useit2c(Space2::Thing2 t) {} - namespace Outer2 { - void useit2d(Space2::Thing2 t) {} - } - - %template(Thing2Int) Thing2; - - -2012-06-30: wsfulton - Fix template namespace problems for symbols declared with a forward class declarations, such as: - - namespace Space1 { - namespace Space2 { - template struct YYY; - } - template struct Space2::YYY { - T yyy(T h) { - return h; - } - }; - void testYYY1(Space1::Space2::YYY yy) {} - void testYYY2(Space2::YYY yy) {} - void testYYY3(::Space1::Space2::YYY yy) {} - } - - %template(YYYInt) Space1::Space2::YYY; - -2012-06-30: wsfulton - Fix namespace problems for symbols declared with a forward class declarations, such as: - - namespace Space1 { - namespace Space2 { - struct XXX; - struct YYY; - } - - struct Space2::YYY {}; - struct Space1::Space2::XXX {}; - - void testXXX2(Space2::XXX xx) {} - void testYYY2(Space2::YYY yy) {} - } - - where xx and yy were not recognised as the proxy classes XXX and YYY. - -2012-06-30: wsfulton - Fix using declarations combined with using directives with forward class declarations so that - types are correctly found in scope. - - namespace Outer2 { - namespace Space2 { - class Thing2; - } - } - using namespace Outer2; - using Space2::Thing2; - class Thing2 {}; - // None of the methods below correctly used the Thing2 proxy class - void useit2(Thing2 t) {} - void useit2a(Outer2::Space2::Thing2 t) {} - void useit2b(::Outer2::Space2::Thing2 t) {} - void useit2c(Space2::Thing2 t) {} - namespace Outer2 { - void useit2d(Space2::Thing2 t) {} - } - -2012-06-25: wsfulton - Fix using declarations combined with using directives so that types are correctly found in scope. - Example: - - namespace Outer2 { - namespace Space2 { - class Thing2 {}; - } - } - using namespace Outer2; // using directive - using Space2::Thing2; // using declaration - void useit2(Thing2 t) {} - - Similarly for templated classes. - -2012-05-29: wsfulton - Fix #3529601 - seg fault when a protected method has the "director" - feature but the parent class does not. Also fix similar problems with - the allprotected feature. - -2012-05-28: wsfulton - Fix seg fault when attempting to warn about an illegal destructor - #3530055, 3530078 and #3530118. +Version 2.0.9 (in progress) +=========================== diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 6dd4d3683..483d64463 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

    SWIG-2.0 Documentation

    -Last update : SWIG-2.0.8 (20 August 2012) +Last update : SWIG-2.0.9 (in progress)

    Sections

    diff --git a/README b/README index 45a9b047f..c9abef486 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.8 (20 August 2012) +Version: 2.0.9 (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/configure.in b/configure.in index d04c76f6f..1ef54d8d1 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.8],[http://www.swig.org]) +AC_INIT([swig],[2.0.9],[http://www.swig.org]) dnl NB: When this requirement is increased to 2.60 or later, AC_PROG_SED dnl definition below can be removed From b9570501aa6c2e05aa1e97371fbed8575a4c41ee Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Sun, 26 Aug 2012 02:09:53 +0000 Subject: [PATCH 0184/1160] Call gcc for C in R git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13720 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 04f794f61..bd31bff1f 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1144,7 +1144,7 @@ R_CFLAGS=-fPIC r: $(SRCS) $(SWIG) -r $(SWIGOPT) $(INTERFACEPATH) ifneq ($(SRCS),) - $(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(SRCS) $(INCLUDES) + $(CC) -g -c $(CFLAGS) $(R_CFLAGS) $(SRCS) $(INCLUDES) endif +( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(OBJS) > /dev/null ) From 33bb317b61126f3c0f377d735044d391b87b715f Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Sun, 26 Aug 2012 03:35:04 +0000 Subject: [PATCH 0185/1160] make ExternalReference slot ref to contain reference git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13721 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++ Lib/r/rtype.swg | 162 ++++++++++++++++++++++++++++++++----------- Source/Modules/r.cxx | 2 + 3 files changed, 126 insertions(+), 42 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 05b7f1a0d..503abf732 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,4 +4,8 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.9 (in progress) =========================== +2012-08-26: drjoe + [R] make ExternalReference slot ref to contain reference +2012-08-26: drjoe + [R] fix Examples/Makefile to use C in $(CC) rather than $(CXX) diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg index 6af45cf40..92f9b4f3d 100644 --- a/Lib/r/rtype.swg +++ b/Lib/r/rtype.swg @@ -4,24 +4,9 @@ */ %typemap("rtype") int, int *, int & "integer"; -%apply int {size_t} -%apply int {std::size_t} -%apply int {ptrdiff_t} -%apply int {std::ptrdiff_t} -%apply int {signed int} -%apply int {unsigned int} -%apply int {short} -%apply int {unsigned short} - %typemap("rtype") long, long *, long & "integer"; -%apply long {long long} -%apply long {signed long long} -%apply long {unsigned long long} -%apply long {signed long} -%apply long {unsigned long} - +%typemap("rtype") float, float*, float & "numeric"; %typemap("rtype") double, double*, double & "numeric"; -%typemap("rtype") float, float *, float & "numeric"; %typemap("rtype") char *, char ** "character"; %typemap("rtype") char "character"; %typemap("rtype") string, string *, string & "character"; @@ -36,16 +21,15 @@ %typemap("rtype") SWIGTYPE & "$R_class"; %typemap("rtype") SWIGTYPE "$&R_class"; -%typemap("rtypecheck") int, int &, long, long &, - unsigned char, unsigned char & +%typemap("rtypecheck") int, int &, long, long & %{ (is.integer($arg) || is.numeric($arg)) && length($arg) == 1 %} -%typemap("rtypecheck") int *, long *, unsigned char * +%typemap("rtypecheck") int *, long * %{ is.integer($arg) || is.numeric($arg) %} -%typemap("rtypecheck") double, double &, float, float & +%typemap("rtypecheck") float, double %{ is.numeric($arg) && length($arg) == 1 %} -%typemap("rtypecheck") double*, float * +%typemap("rtypecheck") float *, double * %{ is.numeric($arg) %} %typemap("rtypecheck") bool, bool & @@ -88,9 +72,8 @@ %{ $input = as.integer($input); %} %typemap(scoercein) long, long *, long & %{ $input = as.integer($input); %} -%typemap(scoercein) double, double *, double & - %{ %} -%typemap(scoercein) float, float *, float & +%typemap(scoercein) float, float*, float &, + double, double *, double & %{ %} %typemap(scoercein) char, char *, char & %{ $input = as($input, "character"); %} @@ -107,9 +90,8 @@ %typemap(scoercein) enum SWIGTYPE *const %{ $input = enumToInteger($input, "$R_class"); %} - %typemap(scoercein) SWIGTYPE, SWIGTYPE *, SWIGTYPE *const, SWIGTYPE & - %{ %} + %{ $input = slot($input,"ref") %} /* %typemap(scoercein) SWIGTYPE *, SWIGTYPE *const @@ -136,12 +118,10 @@ %typemap(scoercein) int, int *, int &, - int[ANY], long, long *, - long &, - long[ANY] - "$input = as.integer($input); "; + long & + "$input = as.integer($input);"; %typemap(scoercein) char *, string, std::string, string &, std::string & @@ -159,27 +139,41 @@ string &, std::string & %typemap(scoerceout) enum SWIGTYPE *const %{ $result = enumToInteger($result, "$R_class"); %} +#%typemap(scoerceout) SWIGTYPE +# %{ class($result) <- "$&R_class"; %} -%typemap(scoerceout) SWIGTYPE - %{ class($result) <- "$&R_class"; %} +#%typemap(scoerceout) SWIGTYPE & +# %{ class($result) <- "$R_class"; %} -%typemap(scoerceout) SWIGTYPE & - %{ class($result) <- "$R_class"; %} +#%typemap(scoerceout) SWIGTYPE * +# %{ class($result) <- "$R_class"; %} -%typemap(scoerceout) SWIGTYPE * - %{ class($result) <- "$R_class"; %} +#%typemap(scoerceout) SWIGTYPE *const +# %{ class($result) <- "$R_class"; %} + + %typemap(scoerceout) SWIGTYPE + %{ $result <- new("$&R_class", ref=$result); %} + + %typemap(scoerceout) SWIGTYPE & + %{ $result <- new("$R_class", ref=$result) ; %} + + %typemap(scoerceout) SWIGTYPE * + %{ $result <- new("$R_class", ref=$result) ; %} + + %typemap(scoerceout) SWIGTYPE *const + %{ $result <- new("$R_class", ref=$result) ; %} -%typemap(scoerceout) SWIGTYPE *const - %{ class($result) <- "$R_class"; %} /* Override the SWIGTYPE * above. */ %typemap(scoerceout) char, char *, char &, - double, - double &, float, + double, + float*, + double*, float &, + double &, int, int &, long, @@ -208,10 +202,94 @@ string &, std::string & signed long &, unsigned long, unsigned long &, - unsigned char *, - unsigned char & + signed char, + signed char &, + unsigned char, + unsigned char & %{ %} +%apply int {size_t, +std::size_t, +ptrdiff_t, +std::ptrdiff_t, +signed int, +unsigned int, +short, +unsigned short, +signed char, +unsigned char} + +%apply int* {size_t[], +std::size_t[], +ptrdiff_t[], +std::ptrdiff_t[], +signed int[], +unsigned int[], +short[], +unsigned short[], +signed char[], +unsigned char[]} + +%apply int* {size_t[ANY], +std::size_t[ANY], +ptrdiff_t[ANY], +std::ptrdiff_t[ANY], +signed int[ANY], +unsigned int[ANY], +short[ANY], +unsigned short[ANY], +signed char[ANY], +unsigned char[ANY]} + +%apply int* {size_t*, +std::size_t*, +ptrdiff_t*, +std::ptrdiff_t*, +signed int*, +unsigned int*, +short*, +unsigned short*, +signed char*, +unsigned char*} + +%apply long { + long long, + signed long long, + unsigned long long, + signed long, + unsigned long} + +%apply long* { + long long*, + signed long long*, + unsigned long long*, + signed long*, + unsigned long*, + long long[], + signed long long[], + unsigned long long[], + signed long[], + unsigned long[], + long long[ANY], + signed long long[ANY], + unsigned long long[ANY], + signed long[ANY], + unsigned long[ANY]} + +%apply float* { + float[], + float[ANY] +} +%apply double * { + double[], + double[ANY] +} + +%apply bool* { + bool[], + bool[ANY] +} + #if 0 Just examining the values for a SWIGTYPE. diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index f163c8b30..14da3a975 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1903,6 +1903,8 @@ int R::functionWrapper(Node *n) { "\n};\n", "if(is(", name, ", \"NativeSymbolInfo\")) {\n", name, " = ", name, "$address", ";\n}\n", + "if(is(", name, ", \"ExternalReference\")) {\n", + name, " = ", name, "@ref;\n}\n", "}; \n", NIL); } else { From 2a28514b2702e527d5a55bb4fa93e9f5f0153500 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 4 Sep 2012 17:54:19 +0000 Subject: [PATCH 0186/1160] Improve javafinalize docs, patch from Marvin Greenberg git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13732 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Java.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index ed99549b0..858342c43 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -5489,6 +5489,22 @@ interfaces (implements) for Java class: empty default

    %typemap(javafinalize)

    the finalize() method (proxy classes only): default calls the delete() method + +

    +Note that the default javafinalize typemap must contain the full implementation of the finalize method. +Any customization to this typemap must still declare a java finalize method with the correct signature. +Note also that the name of the generated "delete" method may be affected by javadestruct and javadestruct_derived typemaps. +Below shows an example modifying the finalizer, assuming the delete method has been renamed to swig_delete. +

    + +
    +%typemap(javafinalize) SWIGTYPE %{
    +   protected void finalize() {
    +     swig_delete();  // renamed to prevent conflict with existing delete method
    +   }
    +]%
    +
    +

    From d496352805b806a103c4de1bce367c99f9814f2a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 7 Sep 2012 06:03:20 +0000 Subject: [PATCH 0187/1160] Move contributors to COPYRIGHT file. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13734 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- COPYRIGHT | 2 +- Lib/chicken/typemaps.i | 1 - Lib/mzscheme/mzrun.swg | 9 --------- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/COPYRIGHT b/COPYRIGHT index d2b87770a..3f4711a47 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -65,7 +65,7 @@ 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, Edward Zimmermann, David Ascher, Dominique Dumont, Pier Giorgio Esposito, Hasan Baran Kovuk, - Klaus Wiederänders, Richard Beare + Klaus Wiederänders, Richard Beare, Hans Oesterholt. (See CHANGES and CHANGES.current and the bug tracker for a more complete list). Past students: diff --git a/Lib/chicken/typemaps.i b/Lib/chicken/typemaps.i index 56cd18a5d..fd587fd68 100644 --- a/Lib/chicken/typemaps.i +++ b/Lib/chicken/typemaps.i @@ -93,7 +93,6 @@ or you can use the %apply directive : */ -// These typemaps contributed by Robin Dunn //---------------------------------------------------------------------- // // T_OUTPUT typemap (and helper function) to return multiple argouts as diff --git a/Lib/mzscheme/mzrun.swg b/Lib/mzscheme/mzrun.swg index a5128da56..06447d78d 100644 --- a/Lib/mzscheme/mzrun.swg +++ b/Lib/mzscheme/mzrun.swg @@ -91,7 +91,6 @@ SWIG_is_unsigned_integer(Scheme_Object *o) /* ----------------------------------------------------------------------- * mzscheme 30X support code - * Contributed by Hans Oesterholt * ----------------------------------------------------------------------- */ #ifndef SCHEME_STR_VAL @@ -252,10 +251,6 @@ SWIG_MzScheme_new_scheme_struct (Scheme_Env* env, const char* basename, return new_type; } -/*** DLOPEN PATCH ****************************************************** - * Contributed by Hans Oesterholt-Dijkema (jan. 2006) - ***********************************************************************/ - #if defined(_WIN32) || defined(__WIN32__) #define __OS_WIN32 #endif @@ -442,10 +437,6 @@ SWIG_MzScheme_new_scheme_struct (Scheme_Env* env, const char* basename, } } -/*** DLOPEN PATCH ****************************************************** - * Contributed by Hans Oesterholt-Dijkema (jan. 2006) - ***********************************************************************/ - /* The interpreter will store a pointer to this structure in a global variable called swig-runtime-data-type-pointer. The instance of this struct is only used if no other module has yet been loaded */ From 2c74c90430fe83529c68de84daacf01c949e5f36 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 7 Sep 2012 06:06:00 +0000 Subject: [PATCH 0188/1160] Fix for gcc warning -Wunused-value without triggering -Wunused-parameter git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13735 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/chicken/chickenrun.swg | 4 ++-- Lib/guile/guile_gh_run.swg | 6 +++--- Lib/guile/guile_scm_run.swg | 8 ++++---- Lib/ocaml/ocaml.swg | 2 +- Lib/ocaml/ocamldec.swg | 2 +- Lib/perl5/perlrun.swg | 4 ++-- Lib/php/phprun.swg | 4 ++-- Lib/pike/pikerun.swg | 4 ++-- Lib/python/pyrun.swg | 6 +++--- Lib/r/rrun.swg | 2 +- Lib/ruby/rubyrun.swg | 4 ++-- Lib/swiginit.swg | 1 - 12 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Lib/chicken/chickenrun.swg b/Lib/chicken/chickenrun.swg index f4e94d6f6..07db41945 100644 --- a/Lib/chicken/chickenrun.swg +++ b/Lib/chicken/chickenrun.swg @@ -36,7 +36,7 @@ extern "C" { SWIG_Chicken_Barf(SWIG_BARF1_CONTRACT_ASSERT, C_text(message)); } else /* Runtime API */ -#define SWIG_GetModule(clientdata) SWIG_Chicken_GetModule() +#define SWIG_GetModule(clientdata) SWIG_Chicken_GetModule(clientdata) #define SWIG_SetModule(clientdata, pointer) SWIG_Chicken_SetModule(pointer) #define C_swig_is_bool(x) C_truep (C_booleanp (x)) @@ -309,7 +309,7 @@ SWIG_Chicken_MustGetPtr (C_word s, swig_type_info *type, int argnum, int flags) static char *chicken_runtimevar_name = "type_pointer" SWIG_TYPE_TABLE_NAME; static swig_module_info * -SWIG_Chicken_GetModule() { +SWIG_Chicken_GetModule(void *SWIGUNUSEDPARM(clientdata)) { swig_module_info *ret = 0; C_word sym; diff --git a/Lib/guile/guile_gh_run.swg b/Lib/guile/guile_gh_run.swg index 0eba1f97e..d8cc56b91 100644 --- a/Lib/guile/guile_gh_run.swg +++ b/Lib/guile/guile_gh_run.swg @@ -27,7 +27,7 @@ typedef SCM (*swig_guile_proc)(); SWIG_Guile_MustGetPtr(&swig_module, s, type, argnum, flags, FUNC_NAME) #define SWIG_NewPointerObj(ptr, type, owner) \ SWIG_Guile_NewPointerObj(&swig_module, (void*)ptr, type, owner) -#define SWIG_GetModule(clientdata) SWIG_Guile_GetModule() +#define SWIG_GetModule(clientdata) SWIG_Guile_GetModule(clientdata) #define SWIG_SetModule(clientdata, pointer) SWIG_Guile_SetModule(pointer) /* Ignore object-ownership changes in gh mode */ @@ -114,14 +114,14 @@ SWIG_Guile_LookupType(swig_module_info *module, SCM s, int normal) #ifdef SWIG_GUILE_MODULE_STATIC static swig_module_info *swig_guile_module = 0; -SWIG_GUILE_MODULE_STATIC swig_module_info *SWIG_Guile_GetModule(void) { +SWIG_GUILE_MODULE_STATIC swig_module_info *SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata)) { return swig_guile_module; } SWIG_GUILE_MODULE_STATIC void SWIG_Guile_SetModule(swig_module_info *pointer) { swig_guile_module = pointer; } #else -SWIGEXPORT swig_module_info * SWIG_Guile_GetModule(void); +SWIGEXPORT swig_module_info * SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata)); SWIGEXPORT void SWIG_Guile_SetModule(swig_module_info *pointer); #endif diff --git a/Lib/guile/guile_scm_run.swg b/Lib/guile/guile_scm_run.swg index 91b74095d..925aaadb4 100644 --- a/Lib/guile/guile_scm_run.swg +++ b/Lib/guile/guile_scm_run.swg @@ -53,8 +53,8 @@ typedef struct swig_guile_clientdata { SWIG_Guile_NewMemberObj(ptr, sz, type, FUNC_NAME) /* Runtime API */ -static swig_module_info *SWIG_Guile_GetModule(void); -#define SWIG_GetModule(clientdata) SWIG_Guile_GetModule() +static swig_module_info *SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata)); +#define SWIG_GetModule(clientdata) SWIG_Guile_GetModule(clientdata) #define SWIG_SetModule(clientdata, pointer) SWIG_Guile_SetModule(pointer) SWIGINTERN char * @@ -204,7 +204,7 @@ SWIGINTERNINLINE int SWIG_Guile_IsPointer (SCM s) { /* module might not be initialized yet, so initialize it */ - SWIG_Guile_GetModule(); + SWIG_GetModule(0); return SWIG_Guile_IsPointerOfType (s, NULL); } @@ -419,7 +419,7 @@ SWIG_Guile_Init () } SWIGINTERN swig_module_info * -SWIG_Guile_GetModule(void) +SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata)) { SCM module; SCM variable; diff --git a/Lib/ocaml/ocaml.swg b/Lib/ocaml/ocaml.swg index 5f8f929e2..a00252b28 100644 --- a/Lib/ocaml/ocaml.swg +++ b/Lib/ocaml/ocaml.swg @@ -578,7 +578,7 @@ extern "C" { } } - static swig_module_info *SWIG_Ocaml_GetModule() { + static swig_module_info *SWIG_Ocaml_GetModule(void *SWIGUNUSEDPARM(clientdata)) { CAML_VALUE pointer; pointer = callback(*caml_named_value("swig_find_type_info"), caml_val_int(0)); diff --git a/Lib/ocaml/ocamldec.swg b/Lib/ocaml/ocamldec.swg index 8e452d3f9..e6b8939fb 100644 --- a/Lib/ocaml/ocamldec.swg +++ b/Lib/ocaml/ocamldec.swg @@ -108,7 +108,7 @@ CAMLextern int64 Int64_val(caml_value_t v); #endif #define SWIG_NewPointerObj(p,type,flags) caml_val_ptr(p,type) -#define SWIG_GetModule(clientdata) SWIG_Ocaml_GetModule() +#define SWIG_GetModule(clientdata) SWIG_Ocaml_GetModule(clientdata) #define SWIG_SetModule(clientdata, pointer) SWIG_Ocaml_SetModule(pointer) #define SWIG_contract_assert(expr, msg) if(!(expr)) {failwith(msg);} else diff --git a/Lib/perl5/perlrun.swg b/Lib/perl5/perlrun.swg index 5c1b586b4..ebc4fecd5 100644 --- a/Lib/perl5/perlrun.swg +++ b/Lib/perl5/perlrun.swg @@ -40,7 +40,7 @@ /* Runtime API */ -#define SWIG_GetModule(clientdata) SWIG_Perl_GetModule() +#define SWIG_GetModule(clientdata) SWIG_Perl_GetModule(clientdata) #define SWIG_SetModule(clientdata, pointer) SWIG_Perl_SetModule(pointer) @@ -477,7 +477,7 @@ SWIGRUNTIME void _swig_create_magic(CPerlObj *pPerl, SV *sv, const char *name, i SWIGRUNTIME swig_module_info * -SWIG_Perl_GetModule(void) { +SWIG_Perl_GetModule(void *SWIGUNUSEDPARM(clientdata)) { static void *type_pointer = (void *)0; SV *pointer; diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 1404955e0..92f2f3fe5 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -79,7 +79,7 @@ static int default_error_code = E_ERROR; if (!(expr) ) { zend_printf("Contract Assert Failed %s\n",msg ); } else /* Standard SWIG API */ -#define SWIG_GetModule(clientdata) SWIG_Php_GetModule() +#define SWIG_GetModule(clientdata) SWIG_Php_GetModule(clientdata) #define SWIG_SetModule(clientdata, pointer) SWIG_Php_SetModule(pointer) /* used to wrap returned objects in so we know whether they are newobject @@ -252,7 +252,7 @@ SWIG_ZTS_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags TSRMLS_DC } static char const_name[] = "swig_runtime_data_type_pointer"; -static swig_module_info *SWIG_Php_GetModule() { +static swig_module_info *SWIG_Php_GetModule(void *SWIGUNUSEDPARM(clientdata)) { zval *pointer; swig_module_info *ret = 0; diff --git a/Lib/pike/pikerun.swg b/Lib/pike/pikerun.swg index 451a4e092..70d40fac9 100644 --- a/Lib/pike/pikerun.swg +++ b/Lib/pike/pikerun.swg @@ -28,11 +28,11 @@ typedef struct swig_object_wrapper { #define SWIG_ConvertPtr SWIG_Pike_ConvertPtr #define SWIG_NewPointerObj SWIG_Pike_NewPointerObj -#define SWIG_GetModule(clientdata) SWIG_Pike_GetModule() +#define SWIG_GetModule(clientdata) SWIG_Pike_GetModule(clientdata) #define SWIG_SetModule(clientdata, pointer) SWIG_Pike_SetModule(pointer) /* These need to be filled in before type sharing between modules will work */ -static swig_module_info *SWIG_Pike_GetModule() { +static swig_module_info *SWIG_Pike_GetModule(void *SWIGUNUSEDPARM(clientdata)) { return 0; } diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index d621f4dee..3585e7a3f 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -45,7 +45,7 @@ /* Runtime API */ -#define SWIG_GetModule(clientdata) SWIG_Python_GetModule() +#define SWIG_GetModule(clientdata) SWIG_Python_GetModule(clientdata) #define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer) #define SWIG_NewClientData(obj) SwigPyClientData_New(obj) @@ -1484,7 +1484,7 @@ void *SWIG_ReturnGlobalTypeList(void *); #endif SWIGRUNTIME swig_module_info * -SWIG_Python_GetModule(void) { +SWIG_Python_GetModule(void *SWIGUNUSEDPARM(clientdata)) { static void *type_pointer = (void *)0; /* first check if module already created */ if (!type_pointer) { @@ -1610,7 +1610,7 @@ SWIG_Python_TypeQuery(const char *type) descriptor = (swig_type_info *) PyCObject_AsVoidPtr(obj); #endif } else { - swig_module_info *swig_module = SWIG_Python_GetModule(); + swig_module_info *swig_module = SWIG_GetModule(0); descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); if (descriptor) { #ifdef SWIGPY_USE_CAPSULE diff --git a/Lib/r/rrun.swg b/Lib/r/rrun.swg index 1c9a22d4c..c441a5222 100644 --- a/Lib/r/rrun.swg +++ b/Lib/r/rrun.swg @@ -293,7 +293,7 @@ SWIG_R_ConvertPtr(SEXP obj, void **ptr, swig_type_info *ty, int flags) { } SWIGRUNTIME swig_module_info * -SWIG_GetModule(void *v) { +SWIG_GetModule(void *SWIGUNUSEDPARM(clientdata)) { static void *type_pointer = (void *)0; return (swig_module_info *) type_pointer; } diff --git a/Lib/ruby/rubyrun.swg b/Lib/ruby/rubyrun.swg index a2d246e97..00fb11f39 100644 --- a/Lib/ruby/rubyrun.swg +++ b/Lib/ruby/rubyrun.swg @@ -35,7 +35,7 @@ /* Runtime API */ -#define SWIG_GetModule(clientdata) SWIG_Ruby_GetModule() +#define SWIG_GetModule(clientdata) SWIG_Ruby_GetModule(clientdata) #define SWIG_SetModule(clientdata, pointer) SWIG_Ruby_SetModule(pointer) @@ -371,7 +371,7 @@ SWIG_Ruby_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty) { } SWIGRUNTIME swig_module_info * -SWIG_Ruby_GetModule(void) +SWIG_Ruby_GetModule(void *SWIGUNUSEDPARM(clientdata)) { VALUE pointer; swig_module_info *ret = 0; diff --git a/Lib/swiginit.swg b/Lib/swiginit.swg index d160cfaf1..f747bccdf 100644 --- a/Lib/swiginit.swg +++ b/Lib/swiginit.swg @@ -56,7 +56,6 @@ SWIG_InitializeModule(void *clientdata) { size_t i; swig_module_info *module_head, *iter; int found, init; - (void *)clientdata; /* check to see if the circular list has been setup, if not, set it up */ if (swig_module.next==0) { From 593c708a78230bdb2fdfe2bd0ed59e39aa14423b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 7 Sep 2012 06:07:20 +0000 Subject: [PATCH 0189/1160] Fix (char *STRING, size_t LENGTH) typemaps to accept NULL string git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13736 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Examples/test-suite/director_binary_string.i | 9 +++++++-- .../java/director_binary_string_runme.java | 15 +++++++++++---- Lib/java/java.swg | 9 +++++++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 503abf732..7295ec8e5 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.9 (in progress) =========================== +2012-09-06: wsfulton + [Java] Fix (char *STRING, size_t LENGTH) typemaps to accept NULL string. + 2012-08-26: drjoe [R] make ExternalReference slot ref to contain reference diff --git a/Examples/test-suite/director_binary_string.i b/Examples/test-suite/director_binary_string.i index 96c835959..f842dc2c7 100644 --- a/Examples/test-suite/director_binary_string.i +++ b/Examples/test-suite/director_binary_string.i @@ -15,8 +15,10 @@ class Callback { public: virtual ~Callback() {} virtual void run(char* dataBufferAA, int sizeAA, char* dataBufferBB, int sizeBB) { - memset(dataBufferAA, -1, sizeAA); - memset(dataBufferBB, -1, sizeBB); + if (dataBufferAA) + memset(dataBufferAA, -1, sizeAA); + if (dataBufferBB) + memset(dataBufferBB, -1, sizeBB); } }; @@ -45,6 +47,9 @@ public: } return sum; } + void call_null() { + _callback->run(NULL, 0, NULL, 0); + } }; %} diff --git a/Examples/test-suite/java/director_binary_string_runme.java b/Examples/test-suite/java/director_binary_string_runme.java index e2bf4da40..962073367 100644 --- a/Examples/test-suite/java/director_binary_string_runme.java +++ b/Examples/test-suite/java/director_binary_string_runme.java @@ -21,6 +21,11 @@ public class director_binary_string_runme { if (sum != 9*2*8 + 13*3*5) throw new RuntimeException("Unexpected sum: " + sum); + + new Callback().run(null, null); + callback = new DirectorBinaryStringCallback(); + caller.setCallback(callback); + caller.call_null(); } } @@ -32,11 +37,13 @@ class DirectorBinaryStringCallback extends Callback { @Override public void run(byte[] dataBufferAA, byte[] dataBufferBB) { - for (int i = 0; i < dataBufferAA.length; i++) - dataBufferAA[i] = (byte)(dataBufferAA[i] * 2); + if (dataBufferAA != null) + for (int i = 0; i < dataBufferAA.length; i++) + dataBufferAA[i] = (byte)(dataBufferAA[i] * 2); - for (int i = 0; i < dataBufferBB.length; i++) - dataBufferBB[i] = (byte)(dataBufferBB[i] * 3); + if (dataBufferBB != null) + for (int i = 0; i < dataBufferBB.length; i++) + dataBufferBB[i] = (byte)(dataBufferBB[i] * 3); } } diff --git a/Lib/java/java.swg b/Lib/java/java.swg index 794b58d88..6126a55e5 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -1301,11 +1301,16 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE) %typemap(javain) (char *STRING, size_t LENGTH) "$javainput" %typemap(freearg) (char *STRING, size_t LENGTH) "" %typemap(in) (char *STRING, size_t LENGTH) { + if ($input) { $1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0); - $2 = (size_t) JCALL1(GetArrayLength, jenv, $input); + $2 = (size_t) JCALL1(GetArrayLength, jenv, $input); + } else { + $1 = 0; + $2 = 0; + } } %typemap(argout) (char *STRING, size_t LENGTH) { - JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); + if ($input) JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); } %typemap(directorin, descriptor="[B") (char *STRING, size_t LENGTH) { jbyteArray jb = (jenv)->NewByteArray($2); From 72fc742f88ef0ddac592be527172ae5a52f6e445 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 13 Sep 2012 18:52:56 +0000 Subject: [PATCH 0190/1160] Add extend example for Android git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13831 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/android/extend/AndroidManifest.xml | 15 +++ Examples/android/extend/Makefile | 29 +++++ Examples/android/extend/ant.properties | 17 +++ Examples/android/extend/build.xml | 85 ++++++++++++++ Examples/android/extend/jni/Android.mk | 10 ++ Examples/android/extend/jni/Application.mk | 1 + Examples/android/extend/jni/example.cpp | 4 + Examples/android/extend/jni/example.h | 56 +++++++++ Examples/android/extend/jni/example.i | 15 +++ Examples/android/extend/local.properties | 10 ++ Examples/android/extend/proguard.cfg | 40 +++++++ Examples/android/extend/project.properties | 11 ++ Examples/android/extend/res/layout/main.xml | 25 ++++ .../android/extend/res/values/strings.xml | 4 + .../org/swig/extendexample/SwigExtend.java | 108 ++++++++++++++++++ 15 files changed, 430 insertions(+) create mode 100644 Examples/android/extend/AndroidManifest.xml create mode 100644 Examples/android/extend/Makefile create mode 100644 Examples/android/extend/ant.properties create mode 100644 Examples/android/extend/build.xml create mode 100644 Examples/android/extend/jni/Android.mk create mode 100644 Examples/android/extend/jni/Application.mk create mode 100644 Examples/android/extend/jni/example.cpp create mode 100644 Examples/android/extend/jni/example.h create mode 100644 Examples/android/extend/jni/example.i create mode 100644 Examples/android/extend/local.properties create mode 100644 Examples/android/extend/proguard.cfg create mode 100644 Examples/android/extend/project.properties create mode 100644 Examples/android/extend/res/layout/main.xml create mode 100644 Examples/android/extend/res/values/strings.xml create mode 100644 Examples/android/extend/src/org/swig/extendexample/SwigExtend.java diff --git a/Examples/android/extend/AndroidManifest.xml b/Examples/android/extend/AndroidManifest.xml new file mode 100644 index 000000000..66d2469fa --- /dev/null +++ b/Examples/android/extend/AndroidManifest.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/Examples/android/extend/Makefile b/Examples/android/extend/Makefile new file mode 100644 index 000000000..98a0372dd --- /dev/null +++ b/Examples/android/extend/Makefile @@ -0,0 +1,29 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +TARGET = example +INTERFACE = example.i +PACKAGEDIR = src/org/swig +PACKAGENAME= org.swig.extendexample +SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/extendexample +PROJECTNAME= SwigExtend +TARGETID = 1 + +all:: android + +android:: + android update project --target $(TARGETID) --name $(PROJECTNAME) --path . + $(SWIG) -c++ -java $(SWIGOPT) -o jni/$(TARGET)_wrap.cpp jni/$(INTERFACE) + ndk-build + ant debug + +install:: + -adb uninstall $(PACKAGENAME) + adb install bin/$(PROJECTNAME)-debug.apk + +clean:: + ant clean + rm -f jni/$(TARGET)_wrap.cpp + rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java` + + +check: all diff --git a/Examples/android/extend/ant.properties b/Examples/android/extend/ant.properties new file mode 100644 index 000000000..ee52d86d9 --- /dev/null +++ b/Examples/android/extend/ant.properties @@ -0,0 +1,17 @@ +# This file is used to override default values used by the Ant build system. +# +# This file must be checked in Version Control Systems, as it is +# integral to the build system of your project. + +# This file is only used by the Ant script. + +# You can use this to override default values such as +# 'source.dir' for the location of your java source folder and +# 'out.dir' for the location of your output folder. + +# You can also use it define how the release builds are signed by declaring +# the following properties: +# 'key.store' for the location of your keystore and +# 'key.alias' for the name of the key to use. +# The password will be asked during the build when you use the 'release' target. + diff --git a/Examples/android/extend/build.xml b/Examples/android/extend/build.xml new file mode 100644 index 000000000..94fe847b7 --- /dev/null +++ b/Examples/android/extend/build.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Examples/android/extend/jni/Android.mk b/Examples/android/extend/jni/Android.mk new file mode 100644 index 000000000..25d42b541 --- /dev/null +++ b/Examples/android/extend/jni/Android.mk @@ -0,0 +1,10 @@ +# File: Android.mk +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := example +LOCAL_SRC_FILES := example_wrap.cpp example.cpp +LOCAL_CFLAGS := -frtti + +include $(BUILD_SHARED_LIBRARY) diff --git a/Examples/android/extend/jni/Application.mk b/Examples/android/extend/jni/Application.mk new file mode 100644 index 000000000..87124dd88 --- /dev/null +++ b/Examples/android/extend/jni/Application.mk @@ -0,0 +1 @@ +APP_STL := gnustl_static diff --git a/Examples/android/extend/jni/example.cpp b/Examples/android/extend/jni/example.cpp new file mode 100644 index 000000000..450d75608 --- /dev/null +++ b/Examples/android/extend/jni/example.cpp @@ -0,0 +1,4 @@ +/* File : example.cxx */ + +#include "example.h" + diff --git a/Examples/android/extend/jni/example.h b/Examples/android/extend/jni/example.h new file mode 100644 index 000000000..b27ab9711 --- /dev/null +++ b/Examples/android/extend/jni/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/android/extend/jni/example.i b/Examples/android/extend/jni/example.i new file mode 100644 index 000000000..c8ec32e09 --- /dev/null +++ b/Examples/android/extend/jni/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/android/extend/local.properties b/Examples/android/extend/local.properties new file mode 100644 index 000000000..14b8d63b4 --- /dev/null +++ b/Examples/android/extend/local.properties @@ -0,0 +1,10 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must *NOT* be checked in Version Control Systems, +# as it contains information specific to your local configuration. + +# location of the SDK. This is only used by Ant +# For customization when using a Version Control System, please read the +# header note. +sdk.dir=/home/william/android/android-sdk-linux_x86 diff --git a/Examples/android/extend/proguard.cfg b/Examples/android/extend/proguard.cfg new file mode 100644 index 000000000..b1cdf17b5 --- /dev/null +++ b/Examples/android/extend/proguard.cfg @@ -0,0 +1,40 @@ +-optimizationpasses 5 +-dontusemixedcaseclassnames +-dontskipnonpubliclibraryclasses +-dontpreverify +-verbose +-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* + +-keep public class * extends android.app.Activity +-keep public class * extends android.app.Application +-keep public class * extends android.app.Service +-keep public class * extends android.content.BroadcastReceiver +-keep public class * extends android.content.ContentProvider +-keep public class * extends android.app.backup.BackupAgentHelper +-keep public class * extends android.preference.Preference +-keep public class com.android.vending.licensing.ILicensingService + +-keepclasseswithmembernames class * { + native ; +} + +-keepclasseswithmembers class * { + public (android.content.Context, android.util.AttributeSet); +} + +-keepclasseswithmembers class * { + public (android.content.Context, android.util.AttributeSet, int); +} + +-keepclassmembers class * extends android.app.Activity { + public void *(android.view.View); +} + +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +-keep class * implements android.os.Parcelable { + public static final android.os.Parcelable$Creator *; +} diff --git a/Examples/android/extend/project.properties b/Examples/android/extend/project.properties new file mode 100644 index 000000000..ea89160e0 --- /dev/null +++ b/Examples/android/extend/project.properties @@ -0,0 +1,11 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "ant.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-8 diff --git a/Examples/android/extend/res/layout/main.xml b/Examples/android/extend/res/layout/main.xml new file mode 100644 index 000000000..d4e5d7fe8 --- /dev/null +++ b/Examples/android/extend/res/layout/main.xml @@ -0,0 +1,25 @@ + + +

  • @@ -744,6 +745,13 @@ Run the app to see the result of calling the C++ code from Java:
    Android screenshot of SwigClass example
    +

    18.2.4 Other examples

    + + +

    +The Examples/android directory contains further examples which can be run and installed in a similar manner to the previous two examples. +

    + diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index bdb3aa9f5..eeb059598 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -645,6 +645,7 @@
  • Examples introduction
  • Simple C example
  • C++ class example +
  • Other examples
  • diff --git a/Examples/android/extend/jni/Application.mk b/Examples/android/extend/jni/Application.mk index 87124dd88..45d13be4e 100644 --- a/Examples/android/extend/jni/Application.mk +++ b/Examples/android/extend/jni/Application.mk @@ -1 +1,2 @@ +# File: Application.mk APP_STL := gnustl_static From 236b007c931ea0a7aa2134f3bdea8b7d98a3d69c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 13 Sep 2012 19:04:29 +0000 Subject: [PATCH 0195/1160] More Android docs about the STL and the new extend example git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13836 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Android.html | 24 ++++++++++++++++++++++++ Doc/Manual/Contents.html | 1 + 2 files changed, 25 insertions(+) diff --git a/Doc/Manual/Android.html b/Doc/Manual/Android.html index eb87ea162..4d1be3944 100644 --- a/Doc/Manual/Android.html +++ b/Doc/Manual/Android.html @@ -17,6 +17,7 @@
  • C++ class example
  • Other examples +
  • C++ STL
  • @@ -752,6 +753,29 @@ Run the app to see the result of calling the C++ code from Java: The Examples/android directory contains further examples which can be run and installed in a similar manner to the previous two examples.

    +

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

    + +

    18.3 C++ STL

    + + +

    +Should the C++ Standard Template Library (STL) be required, an Application.mk file needs to be created +in the same directory as the Android.mk directory containing information about the STL to use. +See the NDK documentation in the $NDKROOT/docs folder especially CPLUSPLUS-SUPPORT.html. +Below is an example of the Application.mk file to make the STLport static library available for use: +

    + +
    +
    +# File: Application.mk
    +APP_STL := gnustl_static
    +
    +
    + + diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index eeb059598..74040ff0e 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -647,6 +647,7 @@
  • C++ class example
  • Other examples +
  • C++ STL
  • From 863c25f9b894ed7e0fff3e1e869211585f5d819a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 13 Sep 2012 19:05:25 +0000 Subject: [PATCH 0196/1160] Possibly incorrect DeleteGlobalRef call on a weak global reference in Java directors - patch from Marvin Greenberg git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13837 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/java/director.swg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/java/director.swg b/Lib/java/director.swg index f4effc303..dbceab57c 100644 --- a/Lib/java/director.swg +++ b/Lib/java/director.swg @@ -25,9 +25,9 @@ namespace Swig { bool set(JNIEnv *jenv, jobject jobj, bool mem_own, bool weak_global) { if (!jthis_) { - weak_global_ = weak_global; + weak_global_ = weak_global || !mem_own; // hold as weak global if explicitly requested or not owned if (jobj) - jthis_ = ((weak_global_ || !mem_own) ? jenv->NewWeakGlobalRef(jobj) : jenv->NewGlobalRef(jobj)); + jthis_ = weak_global_ ? jenv->NewWeakGlobalRef(jobj) : jenv->NewGlobalRef(jobj); #if defined(DEBUG_DIRECTOR_OWNED) std::cout << "JObjectWrapper::set(" << jobj << ", " << (weak_global ? "weak_global" : "global_ref") << ") -> " << jthis_ << std::endl; #endif From d1bc8b5b21e7cb0e8abcfebe84ebfa748a76e836 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 13 Sep 2012 19:18:25 +0000 Subject: [PATCH 0197/1160] Add caveat emptor for peek method in Java directors git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13838 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/java/director.swg | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/java/director.swg b/Lib/java/director.swg index dbceab57c..f32fda350 100644 --- a/Lib/java/director.swg +++ b/Lib/java/director.swg @@ -68,6 +68,7 @@ namespace Swig { weak_global_ = true; } + /* Only call peek if you know what you are doing wrt to weak/global references */ jobject peek() { return jthis_; } From 323f841d933c5a11b592767fbadf76a0dcb2b3c2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 13 Sep 2012 20:15:03 +0000 Subject: [PATCH 0198/1160] Add a testcase for the Curiously Recurring Template Pattern - CRTP git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13839 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 1 + .../curiously_recurring_template_pattern.i | 55 +++++++++++++++++++ ...usly_recurring_template_pattern_runme.java | 29 ++++++++++ 3 files changed, 85 insertions(+) create mode 100644 Examples/test-suite/curiously_recurring_template_pattern.i create mode 100644 Examples/test-suite/java/curiously_recurring_template_pattern_runme.java diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index f6a8056e5..eaef4980b 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -152,6 +152,7 @@ CPP_TEST_CASES += \ cpp_nodefault \ cpp_static \ cpp_typedef \ + curiously_recurring_template_pattern \ default_args \ default_arg_values \ default_constructor \ diff --git a/Examples/test-suite/curiously_recurring_template_pattern.i b/Examples/test-suite/curiously_recurring_template_pattern.i new file mode 100644 index 000000000..96b30fc3d --- /dev/null +++ b/Examples/test-suite/curiously_recurring_template_pattern.i @@ -0,0 +1,55 @@ +%module curiously_recurring_template_pattern + +// Test Curiously Recurring Template Pattern - CRTP + +%inline %{ +template class Base { + int base1Param; + int base2Param; +public: + Base() : base1Param(0) {} + int getBase1Param() { + return base1Param; + } + T& setBase1Param(int value) { + base1Param = value; + return *static_cast(this); + } + int getBase2Param() { + return base2Param; + } + T& setBase2Param(int value) { + base2Param = value; + return *static_cast(this); + } + virtual ~Base() {} +}; +%} + +%template(basederived) Base; + +%inline %{ +class Derived : public Base { + int derived1Param; + int derived2Param; +public: + Derived() : derived1Param(0), derived2Param(0) {} + int getDerived1Param() { + return derived1Param; + } + Derived& setDerived1Param(int value) { + derived1Param = value; + return *this; + } + int getDerived2Param() { + return derived2Param; + } + Derived& setDerived2Param(int value) { + derived2Param = value; + return *this; + } +}; +%} + + + diff --git a/Examples/test-suite/java/curiously_recurring_template_pattern_runme.java b/Examples/test-suite/java/curiously_recurring_template_pattern_runme.java new file mode 100644 index 000000000..ac7e78ba5 --- /dev/null +++ b/Examples/test-suite/java/curiously_recurring_template_pattern_runme.java @@ -0,0 +1,29 @@ + +import curiously_recurring_template_pattern.*; + +public class curiously_recurring_template_pattern_runme { + + static { + try { + System.loadLibrary("curiously_recurring_template_pattern"); + } 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[]) { + Derived d = new Derived(); + d.setBase1Param(1).setDerived1Param(10).setDerived2Param(20).setBase2Param(2); + + if (d.getBase1Param() != 1) + throw new RuntimeException("fail"); + if (d.getDerived1Param() != 10) + throw new RuntimeException("fail"); + if (d.getBase2Param() != 2) + throw new RuntimeException("fail"); + if (d.getDerived2Param() != 20) + throw new RuntimeException("fail"); + } +} + From bc43673a86e8f8fa63dcc822e3357dca6518e01d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 14 Sep 2012 22:25:35 +0000 Subject: [PATCH 0199/1160] Add new warning if an empty template declaration is used on a base class, minor docs improvement for empty template declarations. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13840 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 13 +++++++++++++ Doc/Manual/SWIGPlus.html | 6 +++--- Examples/test-suite/errors/cpp_inherit.i | 8 ++++++++ Examples/test-suite/errors/expected.log | 4 ++++ Source/Modules/lang.cxx | 2 +- Source/Modules/typepass.cxx | 11 ++++++++--- 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index cd8ad4e87..a4a049b1d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,19 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.9 (in progress) =========================== +2012-09-14: wsfulton + Add new warning if the empty template instantiation is used as a base class, for example: + + template class Base {}; + %template() Base; + class Derived : public Base {}; + + gives the following warning instead of silently ignoring the base: + + cpp_inherit.i:52: Warning 401: Base class 'Base< int >' has no name as it is an empty template instantiated with '%template()'. Ignored. + cpp_inherit.i:51: Warning 401: The %template directive must be written before 'Base< int >' is used as a base class and be declared with a name. + + 2012-09-11: wsfulton [Java] Fix #3535304 - Direct use of a weak global reference in directors sometimes causing seg faults especially on Android. diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index b4baca6ae..9ecf0aa5a 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -3121,8 +3121,8 @@ nothing is known about List<int>, you will get a warning message
    -example.h:42. Nothing known about class 'List<int >' (ignored). 
    -example.h:42. Maybe you forgot to instantiate 'List<int >' using %template. 
    +example.h:42: Warning 401. Nothing known about class 'List<int >'. Ignored. 
    +example.h:42: Warning 401. Maybe you forgot to instantiate 'List<int >' using %template. 
     
    @@ -3163,7 +3163,7 @@ Don't worry--if you get the order wrong, SWIG should generate a warning message. Occasionally, you may need to tell SWIG about base classes that are defined by templates, but which aren't supposed to be wrapped. Since SWIG is not able to automatically instantiate templates for this purpose, you must do it manually. To do this, simply -use %template with no name. For example: +use the empty template instantiation, that is, %template with no name. For example:

    diff --git a/Examples/test-suite/errors/cpp_inherit.i b/Examples/test-suite/errors/cpp_inherit.i index fdc77d1d5..1155715e5 100644 --- a/Examples/test-suite/errors/cpp_inherit.i +++ b/Examples/test-suite/errors/cpp_inherit.i @@ -45,3 +45,11 @@ struct Recursive : Recursive { }; %} + + +template class Base {}; +%template() Base; +class Derived : public Base {}; +class Derived2 : public Base {}; +%template(BaseDouble) Base; + diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log index bcaf4efd8..4f56e7146 100644 --- a/Examples/test-suite/errors/expected.log +++ b/Examples/test-suite/errors/expected.log @@ -268,6 +268,10 @@ cpp_inherit.i:24: Warning 401: Nothing known about base class 'A6'. Ignored. cpp_inherit.i:26: Warning 401: Nothing known about base class 'A7< int >'. Ignored. cpp_inherit.i:26: Warning 401: Maybe you forgot to instantiate 'A7< int >' using %template. cpp_inherit.i:45: Warning 323: Recursive scope inheritance of 'Recursive'. +cpp_inherit.i:52: Warning 401: Base class 'Base< int >' has no name as it is an empty template instantiated with '%template()'. Ignored. +cpp_inherit.i:51: Warning 401: The %template directive must be written before 'Base< int >' is used as a base class and be declared with a name. +cpp_inherit.i:53: Warning 401: Base class 'Base< double >' undefined. +cpp_inherit.i:54: Warning 401: 'Base< double >' must be defined before it is used as a base class. :::::::::::::::::::::::::::::::: cpp_macro_locator.i ::::::::::::::::::::::::::::::::::: cpp_macro_locator.i:66: Warning 204: CPP #warning, "inline warning message one". diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index e81ab21dd..d15d650a2 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -965,7 +965,7 @@ int Language::cDeclaration(Node *n) { DohIncref(type); Setattr(n, "type", ty); if (GetFlag(n, "feature:onlychildren") && !GetFlag(n, "feature:ignore")) { - // Found an unignored templated method that has a an empty template instantiation (%template()) + // Found an unignored templated method that has an empty template instantiation (%template()) // Ignore it unless it has been %rename'd if (Strncmp(symname, "__dummy_", 8) == 0) { SetFlag(n, "feature:ignore"); diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index 3284a669a..a134e0ac6 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -185,9 +185,14 @@ class TypePass:private Dispatcher { bcls = 0; } else { if (Getattr(bcls, "typepass:visit")) { - if (!ilist) - ilist = alist = NewList(); - Append(ilist, bcls); + if (!Getattr(bcls, "feature:onlychildren")) { + if (!ilist) + ilist = alist = NewList(); + Append(ilist, bcls); + } else { + Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' has no name as it is an empty template instantiated with '%%template()'. Ignored.\n", SwigType_namestr(bname)); + Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "The %%template directive must be written before '%s' is used as a base class and be declared with a name.\n", SwigType_namestr(bname)); + } } else { Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' undefined.\n", SwigType_namestr(bname)); Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "'%s' must be defined before it is used as a base class.\n", SwigType_namestr(bname)); From 6d655a7f417a41562d42e3345a34b0d73e821644 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 20 Sep 2012 18:17:52 +0000 Subject: [PATCH 0200/1160] Add scoped enums into correct correct scope in type system. Note that cpp0x_strongly_typed_enumerations.i still shows further language symbol table problems which need fixing. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13841 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/CParse/parser.y | 68 ++++++++++++++++++++++++++++++------- Source/Modules/typepass.cxx | 5 +-- 2 files changed, 58 insertions(+), 15 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 1aefcbd08..9b7a89a0e 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1690,7 +1690,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type types_directive template_directive warn_directive ; /* C declarations */ -%type c_declaration c_decl c_decl_tail c_enum_keyword c_enum_inherit c_enum_decl c_enum_forward_decl c_constructor_decl c_lambda_decl c_lambda_decl_front ; +%type c_declaration c_decl c_decl_tail c_enum_key c_enum_inherit c_enum_decl c_enum_forward_decl c_constructor_decl c_lambda_decl c_lambda_decl_front ; %type enumlist edecl; /* C++ declarations */ @@ -3307,11 +3307,14 @@ c_lambda_decl_front : storage_class AUTO idcolon EQUAL LBRACKET { skip_balanced( enum class ------------------------------------------------------------ */ -c_enum_keyword : ENUM { - $$ = (char*)"enumkeyword"; +c_enum_key : ENUM { + $$ = (char *)"enum"; } | ENUM CLASS { - $$ = (char*)"enumclasskeyword"; + $$ = (char *)"enum class"; + } + | ENUM STRUCT { + $$ = (char *)"enum struct"; } ; @@ -3329,12 +3332,16 @@ c_enum_inherit : COLON type_right { enum [class] Name [: base_type]; ------------------------------------------------------------ */ -c_enum_forward_decl : storage_class c_enum_keyword ename c_enum_inherit SEMI { +c_enum_forward_decl : storage_class c_enum_key ename c_enum_inherit SEMI { SwigType *ty = 0; + int scopedenum = $3 && !Equal($2, "enum"); $$ = new_node("enumforward"); ty = NewStringf("enum %s", $3); - Setattr($$,"enumkeyword",$2); + Setattr($$,"enumkey",$2); + if (scopedenum) + SetFlag($$, "scopedenum"); Setattr($$,"name",$3); + Setattr($$,"inherit",$4); Setattr($$,"type",ty); Setattr($$,"sym:weak", "1"); add_symbols($$); @@ -3347,26 +3354,46 @@ c_enum_forward_decl : storage_class c_enum_keyword ename c_enum_inherit SEMI { enum [class] Name [: base_type] { ... } MyEnum [= ...]; * ------------------------------------------------------------ */ -c_enum_decl : storage_class c_enum_keyword ename c_enum_inherit LBRACE enumlist RBRACE SEMI { +c_enum_decl : storage_class c_enum_key ename c_enum_inherit LBRACE enumlist RBRACE SEMI { SwigType *ty = 0; + int scopedenum = $3 && !Equal($2, "enum"); $$ = new_node("enum"); ty = NewStringf("enum %s", $3); - Setattr($$,"enumkeyword",$2); + Setattr($$,"enumkey",$2); + if (scopedenum) + SetFlag($$, "scopedenum"); Setattr($$,"name",$3); Setattr($$,"inherit",$4); Setattr($$,"type",ty); appendChild($$,$6); add_symbols($$); /* Add to tag space */ - add_symbols($6); /* Add enum values to id space */ + + if (scopedenum) { + Swig_symbol_newscope(); + Swig_symbol_setscopename($3); + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); + } + + add_symbols($6); /* Add enum values to appropriate enum or enum class scope */ + + if (scopedenum) { + Setattr($$,"symtab", Swig_symbol_popscope()); + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); + } } - | storage_class c_enum_keyword ename c_enum_inherit LBRACE enumlist RBRACE declarator initializer c_decl_tail { + | storage_class c_enum_key ename c_enum_inherit LBRACE enumlist RBRACE declarator initializer c_decl_tail { Node *n; SwigType *ty = 0; String *unnamed = 0; int unnamedinstance = 0; + int scopedenum = $3 && !Equal($2, "enum"); $$ = new_node("enum"); - Setattr($$,"enumkeyword",$2); + Setattr($$,"enumkey",$2); + if (scopedenum) + SetFlag($$, "scopedenum"); Setattr($$,"inherit",$4); if ($3) { Setattr($$,"name",$3); @@ -3433,7 +3460,22 @@ c_enum_decl : storage_class c_enum_keyword ename c_enum_inherit LBRACE enumlist add_symbols($$); /* Add enum to tag space */ set_nextSibling($$,n); Delete(n); - add_symbols($6); /* Add enum values to id space */ + + if (scopedenum) { + Swig_symbol_newscope(); + Swig_symbol_setscopename($3); + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); + } + + add_symbols($6); /* Add enum values to appropriate enum or enum class scope */ + + if (scopedenum) { + Setattr($$,"symtab", Swig_symbol_popscope()); + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); + } + add_symbols(n); Delete(unnamed); } @@ -5760,7 +5802,7 @@ type_right : primitive_type { $$ = $1; | TYPE_BOOL { $$ = $1; } | TYPE_VOID { $$ = $1; } | TYPE_TYPEDEF template_decl { $$ = NewStringf("%s%s",$1,$2); } - | c_enum_keyword idcolon { $$ = NewStringf("enum %s", $2); } + | c_enum_key idcolon { $$ = NewStringf("enum %s", $2); } | TYPE_RAW { $$ = $1; } | idcolon { diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index e0e06d54e..9e05a2f14 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -834,16 +834,17 @@ class TypePass:private Dispatcher { virtual int enumvalueDeclaration(Node *n) { String *name = Getattr(n, "name"); String *value = Getattr(n, "value"); + String *scopedenum = Getattr(parentNode(n), "scopedenum"); if (!value) value = name; if (Strcmp(value, name) == 0) { String *new_value; - if ((nsname || inclass) && cparse_cplusplus) { + if ((nsname || inclass || scopedenum) && cparse_cplusplus) { new_value = NewStringf("%s::%s", SwigType_namestr(Swig_symbol_qualified(n)), value); } else { new_value = NewString(value); } - if ((nsname || inclass) && !cparse_cplusplus) { + if ((nsname || inclass || scopedenum) && !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 */ } From ecac2d2a68d59a873e63d43a60b09b2eb61e4b9d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 20 Sep 2012 19:09:38 +0000 Subject: [PATCH 0201/1160] Improve nullptr constant wrapping git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13842 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Cpp0x.html | 3 +-- Examples/test-suite/cpp0x_null_pointer_constant.i | 10 ++++++++-- Source/Modules/octave.cxx | 2 +- Source/Modules/php.cxx | 1 + Source/Modules/python.cxx | 2 +- Source/Modules/ruby.cxx | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index f983de165..f34d188ca 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -282,8 +282,7 @@ class DerivedClass: public BaseClass {

    7.2.11 Null pointer constant

    -

    SWIG correctly maps the std::nullptr constant to the null pointer -constant in the target language.

    +

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

    7.2.12 Strongly typed enumerations

    diff --git a/Examples/test-suite/cpp0x_null_pointer_constant.i b/Examples/test-suite/cpp0x_null_pointer_constant.i index 7069f3f25..dcb5e61bd 100644 --- a/Examples/test-suite/cpp0x_null_pointer_constant.i +++ b/Examples/test-suite/cpp0x_null_pointer_constant.i @@ -4,13 +4,19 @@ %module cpp0x_null_pointer_constant +%feature("autodoc") A::NullPtrMethod; // Triggers conversion of nullptr to None, nil etc in target language +%feature("compactdefaultargs") A::NullPtrMethod; + %inline %{ -#include + +const int *const MyIntegerPtr = nullptr; class A { public: - A() : _myA(std::nullptr) { } + A() : _myA(nullptr) { } A *_myA; + + void NullPtrMethod(double *ptr = nullptr) {} }; %} diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index ad425e3c8..d4e0ad57c 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -390,7 +390,7 @@ public: Append(decl_str, tex_name); if (value) { - if (Strcmp(value, "NULL") == 0) + if (Strcmp(value, "NULL") == 0 || Strcmp(value, "nullptr") == 0) value = NewString("nil"); else if (Strcmp(value, "true") == 0 || Strcmp(value, "TRUE") == 0) value = NewString("true"); diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index e53009aaa..2a1eda53c 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1345,6 +1345,7 @@ public: } } if (Strcmp(value, "NULL") == 0 || + Strcmp(value, "nullptr") == 0 || Strcmp(value, "0") == 0 || Strcmp(value, "0L") == 0) { Clear(value); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index fed5205e1..bc5138c25 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -1444,7 +1444,7 @@ public: return NewString("True"); if (Strcmp(v, "false")==0 || Strcmp(v, "FALSE")==0) return NewString("False"); - if (Strcmp(v, "NULL")==0) + if (Strcmp(v, "NULL")==0 || Strcmp(v, "nullptr")==0) return NewString("None"); } return 0; diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index bcdfd69d3..a0580b97d 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -384,7 +384,7 @@ private: } if (value) { - if (Strcmp(value, "NULL") == 0) + if (Strcmp(value, "NULL") == 0 || Strcmp(value, "nullptr") == 0) value = NewString("nil"); else if (Strcmp(value, "true") == 0 || Strcmp(value, "TRUE") == 0) value = NewString("true"); From 744659345e68ac7b65f9733302c3e11e68b12948 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 20 Sep 2012 19:14:27 +0000 Subject: [PATCH 0202/1160] Update c++0x tests run by default for g++-4.6 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13843 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 5ee7df02f..48453d809 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -437,6 +437,7 @@ CPP0X_TEST_CASES = \ cpp0x_explicit_conversion_operators \ cpp0x_function_objects \ cpp0x_initializer_list \ + cpp0x_null_pointer_constant \ cpp0x_raw_string_literals \ cpp0x_result_of \ cpp0x_rvalue_reference \ @@ -453,11 +454,10 @@ CPP0X_TEST_CASES = \ # cpp0x_constructors \ # not supported by any compiler yet # cpp0x_hash_tables \ # not fully implemented yet # cpp0x_lambda_functions \ # not supported by GCC or MSVC yet -# cpp0x_null_pointer_constant \ # not supported by any compiler yet # cpp0x_smart_pointers \ # not supported by standard library yet # cpp0x_template_typedefs \ # not supported by any compiler yet # cpp0x_thread_local \ # not supported by any compiler yet -# cpp0x_unrestricted_unions \ # not supported by any compiler yet +# cpp0x_unrestricted_unions \ # not supported by any compiler yet (now in gcc-4.6) # Broken C++0x test cases. CPP0X_TEST_BROKEN = From 3578be5753cac54aa9ec904c4cbf5025189c6345 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 20 Sep 2012 19:28:20 +0000 Subject: [PATCH 0203/1160] Better clarify C++11 smart pointer support git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13844 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Cpp0x.html | 5 ++++- Examples/test-suite/common.mk | 1 - Examples/test-suite/cpp0x_smart_pointers.i | 19 ------------------- 3 files changed, 4 insertions(+), 21 deletions(-) delete mode 100644 Examples/test-suite/cpp0x_smart_pointers.i diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index f34d188ca..c46bfd67c 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -590,7 +590,10 @@ include the tuple header file; it is parsed without any problems.

    7.3.4 General-purpose smart pointers

    -

    SWIG does not wrap the new shared, weak and unique smart pointers, because the SWIG target languages offer their own garbage collectors.

    +

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

    7.3.5 Extensible random number facility

    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 48453d809..b496fe3c4 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -454,7 +454,6 @@ CPP0X_TEST_CASES = \ # cpp0x_constructors \ # not supported by any compiler yet # cpp0x_hash_tables \ # not fully implemented yet # cpp0x_lambda_functions \ # not supported by GCC or MSVC yet -# cpp0x_smart_pointers \ # not supported by standard library yet # cpp0x_template_typedefs \ # not supported by any compiler yet # cpp0x_thread_local \ # not supported by any compiler yet # cpp0x_unrestricted_unions \ # not supported by any compiler yet (now in gcc-4.6) diff --git a/Examples/test-suite/cpp0x_smart_pointers.i b/Examples/test-suite/cpp0x_smart_pointers.i deleted file mode 100644 index 400f7ebae..000000000 --- a/Examples/test-suite/cpp0x_smart_pointers.i +++ /dev/null @@ -1,19 +0,0 @@ -/* This testcase checks whether SWIG correctly uses the new general-purpose - smart pointers introduced in C++0x: - - shared_ptr - - weak_ptr - - unique_ptr -*/ -%module cpp0x_smart_pointers - -%inline %{ -#include -#include -#include - -struct A { - std::shared_ptr a1(new double); - std::unique_ptr a2(new double); - std::weak_ptr a3(a1); -}; -%} From e8deb880c2cadda79d179fea74444ffed2ac58a1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 21 Sep 2012 05:53:44 +0000 Subject: [PATCH 0204/1160] Tidy up test and docs on template double brackets git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13845 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Cpp0x.html | 8 -------- .../test-suite/cpp0x_template_double_brackets.i | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index c46bfd67c..c93121200 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -346,14 +346,6 @@ shift operator >> otherwise.

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

    The bit shifting operator using the parenthesis -around the expressions can be forced. For example

    - -
    -template<(5>>3)>
    -class A {};
    -
    -

    7.2.14 Explicit conversion operators

    diff --git a/Examples/test-suite/cpp0x_template_double_brackets.i b/Examples/test-suite/cpp0x_template_double_brackets.i index 79d77e704..6b2230362 100644 --- a/Examples/test-suite/cpp0x_template_double_brackets.i +++ b/Examples/test-suite/cpp0x_template_double_brackets.i @@ -5,14 +5,23 @@ %module cpp0x_template_double_brackets %inline %{ #include -std::map> m; -std::map< int,std::map > n; +std::map> map1; +std::map< int,std::map > map2; +std::map>> map3; +std::map>>> map4; +%} + +// Check streaming operators are still okay +%rename(ExtractionOperator) operator>>; +%rename(InsertionOperator) operator<<; + +%inline %{ class ABC { public: int a; - int operator>>(ABC &); - int operator<<(ABC &); + int operator>>(ABC &) { return 0; } + int operator<<(ABC &) { return 0; } }; template From 171435f9895e59c66c7fc26af695f87302dd6e73 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 21 Sep 2012 06:37:30 +0000 Subject: [PATCH 0205/1160] Provide unique c++11 warnings which were previously hijacking another warning git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13846 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/CParse/parser.y | 8 ++++---- Source/Include/swigwarn.h | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 9b7a89a0e..effe11ccc 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2899,7 +2899,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va p = tp; def_supplied = 1; } else if (p && !tp) { /* Variadic template - tp < p */ - Swig_warning(WARN_LANG_NATIVE_UNIMPL,cparse_file, cparse_line,"Only the first variadic template argument is currently supported.\n"); + Swig_warning(WARN_CPP11_VARIADIC_TEMPLATE,cparse_file, cparse_line,"Only the first variadic template argument is currently supported.\n"); break; } } @@ -3098,9 +3098,9 @@ c_declaration : c_decl { appendChild($$,firstChild($5)); } } - | c_lambda_decl { Swig_warning(WARN_LANG_NATIVE_UNIMPL, cparse_file, cparse_line,"SWIG doesn't produce wrapper code for lambda expressions and closures yet.\n"); $$ = $1; } - | USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_LANG_NATIVE_UNIMPL, cparse_file, cparse_line,"SWIG doesn't support 'using' typedefs yet.\n"); $$ = 0; } - | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_LANG_NATIVE_UNIMPL, cparse_file, cparse_line,"SWIG doesn't support template aliasing yet.\n"); $$ = 0; } + | c_lambda_decl { Swig_warning(WARN_CPP11_LAMBDA, cparse_file, cparse_line,"SWIG doesn't produce wrapper code for lambda expressions and closures yet.\n"); $$ = $1; } + | USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_CPP11_ALIAS_DECLARATION, cparse_file, cparse_line,"SWIG doesn't support the 'using' keyword in type aliasing yet.\n"); $$ = 0; } + | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_CPP11_ALIAS_TEMPLATE, cparse_file, cparse_line,"SWIG doesn't support the 'using' keyword in template aliasing yet.\n"); $$ = 0; } ; /* ------------------------------------------------------------ diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index 729764e51..c5e4b8e54 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -89,6 +89,11 @@ #define WARN_PARSE_NESTED_TEMPLATE 324 #define WARN_PARSE_NAMED_NESTED_CLASS 325 +#define WARN_CPP11_LAMBDA 340 +#define WARN_CPP11_ALIAS_DECLARATION 341 +#define WARN_CPP11_ALIAS_TEMPLATE 342 +#define WARN_CPP11_VARIADIC_TEMPLATE 343 + #define WARN_IGNORE_OPERATOR_NEW 350 /* new */ #define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */ #define WARN_IGNORE_OPERATOR_PLUS 352 /* + */ From dbdbdd94aa44da8e3213c08cd252549578db17a4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 21 Sep 2012 18:04:15 +0000 Subject: [PATCH 0206/1160] Some updates to c++11 warning messages and update docs on alias templates git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13847 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Cpp0x.html | 46 +++++++++++++++++-- Examples/test-suite/common.mk | 2 +- Examples/test-suite/cpp0x_template_typedefs.i | 3 +- Source/CParse/parser.y | 6 +-- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index c93121200..ef64fecc1 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -27,7 +27,7 @@
  • Strongly typed enumerations
  • Double angle brackets
  • Explicit conversion operators -
  • Template typedefs +
  • Alias templates
  • Unrestricted unions
  • Variadic templates
  • New string literals @@ -382,17 +382,53 @@ SWIG target languages, because all use their own facilities (eg. classes Cloneab to achieve particular copy and compare behaviours.

    -

    7.2.15 Template typedefs

    +

    7.2.15 Alias templates

    +

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

    SWIG currently parses the new using name = syntax, but -ignores the definition:

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

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

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

    +Similarly for non-template type aliasing: +

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

    You should still define the typedefs using the old syntax:

    +

    +A warning will be issued: +

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

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

     typedef void (*PFD)(double);  // The old style
    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
    index b496fe3c4..3e5b7789c 100644
    --- a/Examples/test-suite/common.mk
    +++ b/Examples/test-suite/common.mk
    @@ -454,7 +454,7 @@ CPP0X_TEST_CASES = \
     #	cpp0x_constructors \          # not supported by any compiler yet
     #	cpp0x_hash_tables \           # not fully implemented yet
     #	cpp0x_lambda_functions \      # not supported by GCC or MSVC yet
    -#	cpp0x_template_typedefs \     # not supported by any compiler yet
    +#	cpp0x_template_typedefs \     # not supported by any compiler yet (now in gcc-4.7)
     #	cpp0x_thread_local \          # not supported by any compiler yet
     #	cpp0x_unrestricted_unions \   # not supported by any compiler yet (now in gcc-4.6)
     
    diff --git a/Examples/test-suite/cpp0x_template_typedefs.i b/Examples/test-suite/cpp0x_template_typedefs.i
    index 877539bfb..bd7e2b220 100644
    --- a/Examples/test-suite/cpp0x_template_typedefs.i
    +++ b/Examples/test-suite/cpp0x_template_typedefs.i
    @@ -1,4 +1,4 @@
    -/* This testcase checks whether SWIG correctly parses the template aliasing. */
    +/* This testcase checks whether SWIG correctly parses alias templates. */
     %module cpp0x_template_typedefs
     
     %inline %{
    @@ -12,6 +12,7 @@ class SomeType {
     template< typename T2 >
     using TypedefName = SomeType;
     
    +// type aliasing
     typedef void (*PFD)(double);            // Old style
     using PF = void (*)(double);            // New introduced syntax
     %}
    diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
    index effe11ccc..f601aab9f 100644
    --- a/Source/CParse/parser.y
    +++ b/Source/CParse/parser.y
    @@ -3098,9 +3098,9 @@ c_declaration   : c_decl {
     		    appendChild($$,firstChild($5));
     		  }
                     }
    -                | c_lambda_decl { Swig_warning(WARN_CPP11_LAMBDA, cparse_file, cparse_line,"SWIG doesn't produce wrapper code for lambda expressions and closures yet.\n"); $$ = $1; }
    -                | USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_CPP11_ALIAS_DECLARATION, cparse_file, cparse_line,"SWIG doesn't support the 'using' keyword in type aliasing yet.\n"); $$ = 0; }
    -                | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_CPP11_ALIAS_TEMPLATE, cparse_file, cparse_line,"SWIG doesn't support the 'using' keyword in template aliasing yet.\n"); $$ = 0; }
    +                | c_lambda_decl { Swig_warning(WARN_CPP11_LAMBDA, cparse_file, cparse_line,"Lambda expressions and closures are not fully supported yet.\n"); $$ = $1; }
    +                | USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_CPP11_ALIAS_DECLARATION, cparse_file, cparse_line,"The 'using' keyword in type aliasing is not fully supported yet.\n"); $$ = 0; }
    +                | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_CPP11_ALIAS_TEMPLATE, cparse_file, cparse_line,"The 'using' keyword in template aliasing is not fully supported yet.\n"); $$ = 0; }
                     ;
     
     /* ------------------------------------------------------------
    
    From 4c2a1abd6b69d69cdc816daa7d3980167ab6286d Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Fri, 21 Sep 2012 18:21:15 +0000
    Subject: [PATCH 0207/1160] Minor doc tweaks for unrestricted unions
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13848 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Doc/Manual/Cpp0x.html         | 2 +-
     Examples/test-suite/common.mk | 2 +-
     2 files changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html
    index ef64fecc1..09e2b2f47 100644
    --- a/Doc/Manual/Cpp0x.html
    +++ b/Doc/Manual/Cpp0x.html
    @@ -438,7 +438,7 @@ typedef void (*PFD)(double);  // The old style
     
     
     

    SWIG fully supports any type inside a union even if it does not -define the trivial constructor. For example, the wrapper for the following +define a trivial constructor. For example, the wrapper for the following code is correctly produced:

    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
    index 3e5b7789c..9755a29e7 100644
    --- a/Examples/test-suite/common.mk
    +++ b/Examples/test-suite/common.mk
    @@ -456,7 +456,7 @@ CPP0X_TEST_CASES = \
     #	cpp0x_lambda_functions \      # not supported by GCC or MSVC yet
     #	cpp0x_template_typedefs \     # not supported by any compiler yet (now in gcc-4.7)
     #	cpp0x_thread_local \          # not supported by any compiler yet
    -#	cpp0x_unrestricted_unions \   # not supported by any compiler yet (now in gcc-4.6)
    +#	cpp0x_unrestricted_unions \   # not supported by any compiler yet (now in gcc-4.6 but generates internal compiler error)
     
     # Broken C++0x test cases.
     CPP0X_TEST_BROKEN = 
    
    From e25da884cb39ad7b11c97214a2b2dd26a7cb2a2f Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Fri, 21 Sep 2012 19:15:44 +0000
    Subject: [PATCH 0208/1160] Fix unrestricted unions testcase and add runtime
     example
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13849 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Doc/Manual/Cpp0x.html                         |   11 +-
     Examples/test-suite/common.mk                 |    2 +-
     .../test-suite/cpp0x_unrestricted_unions.i    |    7 +-
     .../python/cpp0x_unrestricted_unions_wrap.cxx | 4046 +++++++++++++++++
     4 files changed, 4061 insertions(+), 5 deletions(-)
     create mode 100644 Examples/test-suite/python/cpp0x_unrestricted_unions_wrap.cxx
    
    diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html
    index 09e2b2f47..a93df57ca 100644
    --- a/Doc/Manual/Cpp0x.html
    +++ b/Doc/Manual/Cpp0x.html
    @@ -439,19 +439,24 @@ typedef void (*PFD)(double);  // The old style
     
     

    SWIG fully supports any type inside a union even if it does not define a trivial constructor. For example, the wrapper for the following -code is correctly produced:

    +code correctly provides access to all members in the union:

     struct point {
       point() {}
    -  point(int x, int y): x_(x), y_(y) {}
    +  point(int x, int y) : x_(x), y_(y) {}
       int x_, y_;
     };
     
    +#include  // For placement 'new' in the constructor below
     union P {
       int z;
       double w;
    -  point p;  // Illegal in C++; point has a non-trivial constructor.  However, this is legal in C++0x.
    +  point p; // Illegal in C++03; legal in C++11.
    +  // Due to the point member, a constructor definition is required.
    +  P() {
    +    new(&p) point();
    +  }
     } p1;
     
    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 9755a29e7..1dfe35f38 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -448,6 +448,7 @@ CPP0X_TEST_CASES = \ cpp0x_template_double_brackets \ cpp0x_template_explicit \ cpp0x_uniform_initialization \ + cpp0x_unrestricted_unions \ cpp0x_userdefined_literals \ cpp0x_variadic_templates @@ -456,7 +457,6 @@ CPP0X_TEST_CASES = \ # cpp0x_lambda_functions \ # not supported by GCC or MSVC yet # cpp0x_template_typedefs \ # not supported by any compiler yet (now in gcc-4.7) # cpp0x_thread_local \ # not supported by any compiler yet -# cpp0x_unrestricted_unions \ # not supported by any compiler yet (now in gcc-4.6 but generates internal compiler error) # Broken C++0x test cases. CPP0X_TEST_BROKEN = diff --git a/Examples/test-suite/cpp0x_unrestricted_unions.i b/Examples/test-suite/cpp0x_unrestricted_unions.i index 1cadd7f7c..be65fd83d 100644 --- a/Examples/test-suite/cpp0x_unrestricted_unions.i +++ b/Examples/test-suite/cpp0x_unrestricted_unions.i @@ -9,10 +9,15 @@ struct point { int x_, y_; }; +#include // For placement 'new' in the constructor below union P { int z; double w; - point p; + point p; // Illegal in C++03; legal in C++11. + // Due to the point member, a constructor definition is required. + P() { + new(&p) point(); + } } p1; %} diff --git a/Examples/test-suite/python/cpp0x_unrestricted_unions_wrap.cxx b/Examples/test-suite/python/cpp0x_unrestricted_unions_wrap.cxx new file mode 100644 index 000000000..071bb660d --- /dev/null +++ b/Examples/test-suite/python/cpp0x_unrestricted_unions_wrap.cxx @@ -0,0 +1,4046 @@ +/* ---------------------------------------------------------------------------- + * 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. + * ----------------------------------------------------------------------------- */ + +#define SWIGPYTHON +#define SWIG_PYTHON_DIRECTOR_NO_VTABLE + + +#ifdef __cplusplus +/* SwigValueWrapper is described in swig.swg */ +template class SwigValueWrapper { + struct SwigMovePointer { + T *ptr; + SwigMovePointer(T *p) : ptr(p) { } + ~SwigMovePointer() { delete ptr; } + SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; } + } pointer; + SwigValueWrapper& operator=(const SwigValueWrapper& rhs); + SwigValueWrapper(const SwigValueWrapper& rhs); +public: + SwigValueWrapper() : pointer(0) { } + SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; } + operator T&() const { return *pointer.ptr; } + T *operator&() { return pointer.ptr; } +}; + +template T SwigValueInit() { + return T(); +} +#endif + +/* ----------------------------------------------------------------------------- + * 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) && (__SUNPRO_CC <= 0x560) +# define SWIGTEMPLATEDISAMBIGUATOR template +# elif defined(__HP_aCC) +/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ +/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ +# define SWIGTEMPLATEDISAMBIGUATOR template +# 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 SWIG_MSC_UNSUPPRESS_4505 +# if defined(_MSC_VER) +# pragma warning(disable : 4505) /* unreferenced local function has been removed */ +# 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 */ +#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +# ifndef GCC_HASCLASSVISIBILITY +# define GCC_HASCLASSVISIBILITY +# endif +#endif + +#ifndef SWIGEXPORT +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# if defined(STATIC_LINKED) +# define SWIGEXPORT +# else +# define SWIGEXPORT __declspec(dllexport) +# endif +# else +# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) +# define SWIGEXPORT __attribute__ ((visibility("default"))) +# else +# define SWIGEXPORT +# endif +# endif +#endif + +/* calling conventions for Windows */ +#ifndef SWIGSTDCALL +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# define SWIGSTDCALL __stdcall +# else +# define SWIGSTDCALL +# endif +#endif + +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ +#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) +# define _CRT_SECURE_NO_DEPRECATE +#endif + +/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ +#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) +# define _SCL_SECURE_NO_DEPRECATE +#endif + + + +/* Python.h has to appear first */ +#include + +/* ----------------------------------------------------------------------------- + * swigrun.swg + * + * This file contains generic C API 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 "4" + +/* 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 strictly necessary, ie, if you have problems + with your compiler or suchlike. +*/ + +#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 +#define SWIG_CAST_NEW_MEMORY 0x2 + +/* Flags for new pointer objects */ +#define SWIG_POINTER_OWN 0x1 + + +/* + Flags/methods for returning states. + + 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). + + Use the following macros/flags to set or process the returning + states. + + In old versions of SWIG, code such as the following was usually written: + + if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { + // success code + } else { + //fail code + } + + Now you can be more explicit: + + int res = SWIG_ConvertPtr(obj,vptr,ty.flags); + if (SWIG_IsOK(res)) { + // success code + } else { + // fail code + } + + which is the same really, 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 + also requires SWIG_ConvertPtr to return new result values, such 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) +#define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) + +/* 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 *, int *); +typedef struct swig_type_info *(*swig_dycast_func)(void **); + +/* Structure to store information 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 (*f1 > *f2) ? 1 : -1; + } + return (int)((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; +} + + +/* + Check the typename +*/ +SWIGRUNTIME swig_cast_info * +SWIG_TypeCheck(const char *c, swig_type_info *ty) { + if (ty) { + swig_cast_info *iter = ty->cast; + while (iter) { + if (strcmp(iter->type->name, c) == 0) { + 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; +} + +/* + Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison +*/ +SWIGRUNTIME swig_cast_info * +SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) { + if (ty) { + swig_cast_info *iter = ty->cast; + while (iter) { + if (iter->type == from) { + 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; +} + +/* + Cast a pointer up an inheritance hierarchy +*/ +SWIGRUNTIMEINLINE void * +SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { + return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); +} + +/* + 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 + +/* 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 + + + +/* Compatibility macros for Python 3 */ +#if PY_VERSION_HEX >= 0x03000000 + +#define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type) +#define PyInt_Check(x) PyLong_Check(x) +#define PyInt_AsLong(x) PyLong_AsLong(x) +#define PyInt_FromLong(x) PyLong_FromLong(x) +#define PyString_Format(fmt, args) PyUnicode_Format(fmt, args) + +#endif + +#ifndef Py_TYPE +# define Py_TYPE(op) ((op)->ob_type) +#endif + +/* SWIG APIs for compatibility of both Python 2 & 3 */ + +#if PY_VERSION_HEX >= 0x03000000 +# define SWIG_Python_str_FromFormat PyUnicode_FromFormat +#else +# define SWIG_Python_str_FromFormat PyString_FromFormat +#endif + + +/* Warning: This function will allocate a new string in Python 3, + * so please call SWIG_Python_str_DelForPy3(x) to free the space. + */ +SWIGINTERN char* +SWIG_Python_str_AsChar(PyObject *str) +{ +#if PY_VERSION_HEX >= 0x03000000 + char *cstr; + char *newstr; + Py_ssize_t len; + str = PyUnicode_AsUTF8String(str); + PyBytes_AsStringAndSize(str, &cstr, &len); + newstr = (char *) malloc(len+1); + memcpy(newstr, cstr, len+1); + Py_XDECREF(str); + return newstr; +#else + return PyString_AsString(str); +#endif +} + +#if PY_VERSION_HEX >= 0x03000000 +# define SWIG_Python_str_DelForPy3(x) free( (void*) (x) ) +#else +# define SWIG_Python_str_DelForPy3(x) +#endif + + +SWIGINTERN PyObject* +SWIG_Python_str_FromChar(const char *c) +{ +#if PY_VERSION_HEX >= 0x03000000 + return PyUnicode_FromString(c); +#else + return PyString_FromString(c); +#endif +} + +/* Add PyOS_snprintf for old Pythons */ +#if PY_VERSION_HEX < 0x02020000 +# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) +# define PyOS_snprintf _snprintf +# else +# define PyOS_snprintf snprintf +# endif +#endif + +/* A crude PyString_FromFormat implementation for old Pythons */ +#if PY_VERSION_HEX < 0x02020000 + +#ifndef SWIG_PYBUFFER_SIZE +# define SWIG_PYBUFFER_SIZE 1024 +#endif + +static PyObject * +PyString_FromFormat(const char *fmt, ...) { + va_list ap; + char buf[SWIG_PYBUFFER_SIZE * 2]; + int res; + va_start(ap, fmt); + res = vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf); +} +#endif + +/* Add PyObject_Del for old Pythons */ +#if PY_VERSION_HEX < 0x01060000 +# define PyObject_Del(op) PyMem_DEL((op)) +#endif +#ifndef PyObject_DEL +# define PyObject_DEL PyObject_Del +#endif + +/* A crude PyExc_StopIteration exception for old Pythons */ +#if PY_VERSION_HEX < 0x02020000 +# ifndef PyExc_StopIteration +# define PyExc_StopIteration PyExc_RuntimeError +# endif +# ifndef PyObject_GenericGetAttr +# define PyObject_GenericGetAttr 0 +# endif +#endif + +/* Py_NotImplemented is defined in 2.1 and up. */ +#if PY_VERSION_HEX < 0x02010000 +# ifndef Py_NotImplemented +# define Py_NotImplemented PyExc_RuntimeError +# endif +#endif + +/* A crude PyString_AsStringAndSize implementation for old Pythons */ +#if PY_VERSION_HEX < 0x02010000 +# ifndef PyString_AsStringAndSize +# define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;} +# endif +#endif + +/* PySequence_Size for old Pythons */ +#if PY_VERSION_HEX < 0x02000000 +# ifndef PySequence_Size +# define PySequence_Size PySequence_Length +# endif +#endif + +/* PyBool_FromLong for old Pythons */ +#if PY_VERSION_HEX < 0x02030000 +static +PyObject *PyBool_FromLong(long ok) +{ + PyObject *result = ok ? Py_True : Py_False; + Py_INCREF(result); + return result; +} +#endif + +/* Py_ssize_t for old Pythons */ +/* This code is as recommended by: */ +/* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */ +#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) +typedef int Py_ssize_t; +# define PY_SSIZE_T_MAX INT_MAX +# define PY_SSIZE_T_MIN INT_MIN +#endif + +/* ----------------------------------------------------------------------------- + * error manipulation + * ----------------------------------------------------------------------------- */ + +SWIGRUNTIME PyObject* +SWIG_Python_ErrorType(int code) { + PyObject* type = 0; + switch(code) { + case SWIG_MemoryError: + type = PyExc_MemoryError; + break; + case SWIG_IOError: + type = PyExc_IOError; + break; + case SWIG_RuntimeError: + type = PyExc_RuntimeError; + break; + case SWIG_IndexError: + type = PyExc_IndexError; + break; + case SWIG_TypeError: + type = PyExc_TypeError; + break; + case SWIG_DivisionByZero: + type = PyExc_ZeroDivisionError; + break; + case SWIG_OverflowError: + type = PyExc_OverflowError; + break; + case SWIG_SyntaxError: + type = PyExc_SyntaxError; + break; + case SWIG_ValueError: + type = PyExc_ValueError; + break; + case SWIG_SystemError: + type = PyExc_SystemError; + break; + case SWIG_AttributeError: + type = PyExc_AttributeError; + break; + default: + type = PyExc_RuntimeError; + } + return type; +} + + +SWIGRUNTIME void +SWIG_Python_AddErrorMsg(const char* mesg) +{ + PyObject *type = 0; + PyObject *value = 0; + PyObject *traceback = 0; + + if (PyErr_Occurred()) PyErr_Fetch(&type, &value, &traceback); + if (value) { + char *tmp; + PyObject *old_str = PyObject_Str(value); + PyErr_Clear(); + Py_XINCREF(type); + + PyErr_Format(type, "%s %s", tmp = SWIG_Python_str_AsChar(old_str), mesg); + SWIG_Python_str_DelForPy3(tmp); + Py_DECREF(old_str); + Py_DECREF(value); + } else { + PyErr_SetString(PyExc_RuntimeError, mesg); + } +} + +#if defined(SWIG_PYTHON_NO_THREADS) +# if defined(SWIG_PYTHON_THREADS) +# undef SWIG_PYTHON_THREADS +# endif +#endif +#if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */ +# if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL) +# if (PY_VERSION_HEX >= 0x02030000) /* For 2.3 or later, use the PyGILState calls */ +# define SWIG_PYTHON_USE_GIL +# endif +# endif +# if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */ +# ifndef SWIG_PYTHON_INITIALIZE_THREADS +# define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads() +# endif +# ifdef __cplusplus /* C++ code */ + class SWIG_Python_Thread_Block { + bool status; + PyGILState_STATE state; + public: + void end() { if (status) { PyGILState_Release(state); status = false;} } + SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {} + ~SWIG_Python_Thread_Block() { end(); } + }; + class SWIG_Python_Thread_Allow { + bool status; + PyThreadState *save; + public: + void end() { if (status) { PyEval_RestoreThread(save); status = false; }} + SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} + ~SWIG_Python_Thread_Allow() { end(); } + }; +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block +# define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow +# define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end() +# else /* C code */ +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure() +# define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block) +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread() +# define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow) +# endif +# else /* Old thread way, not implemented, user must provide it */ +# if !defined(SWIG_PYTHON_INITIALIZE_THREADS) +# define SWIG_PYTHON_INITIALIZE_THREADS +# endif +# if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK) +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK +# endif +# if !defined(SWIG_PYTHON_THREAD_END_BLOCK) +# define SWIG_PYTHON_THREAD_END_BLOCK +# endif +# if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW) +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW +# endif +# if !defined(SWIG_PYTHON_THREAD_END_ALLOW) +# define SWIG_PYTHON_THREAD_END_ALLOW +# endif +# endif +#else /* No thread support */ +# define SWIG_PYTHON_INITIALIZE_THREADS +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK +# define SWIG_PYTHON_THREAD_END_BLOCK +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW +# define SWIG_PYTHON_THREAD_END_ALLOW +#endif + +/* ----------------------------------------------------------------------------- + * Python API portion that goes into the runtime + * ----------------------------------------------------------------------------- */ + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* cc-mode */ +#endif +#endif + +/* ----------------------------------------------------------------------------- + * Constant declarations + * ----------------------------------------------------------------------------- */ + +/* Constant Types */ +#define SWIG_PY_POINTER 4 +#define SWIG_PY_BINARY 5 + +/* 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; + + +/* ----------------------------------------------------------------------------- + * Wrapper of PyInstanceMethod_New() used in Python 3 + * It is exported to the generated module, used for -fastproxy + * ----------------------------------------------------------------------------- */ +SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *self, PyObject *func) +{ +#if PY_VERSION_HEX >= 0x03000000 + return PyInstanceMethod_New(func); +#else + return NULL; +#endif +} + +#ifdef __cplusplus +#if 0 +{ /* cc-mode */ +#endif +} +#endif + + +/* ----------------------------------------------------------------------------- + * pyrun.swg + * + * This file contains the runtime support for Python modules + * and includes code for managing global variables and pointer + * type checking. + * + * ----------------------------------------------------------------------------- */ + +/* 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) SwigPyClientData_New(obj) + +#define SWIG_SetErrorObj SWIG_Python_SetErrorObj +#define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg +#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) +#define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) +#define SWIG_fail goto fail + + +/* Runtime API implementation */ + +/* Error manipulation */ + +SWIGINTERN void +SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetObject(errtype, obj); + Py_DECREF(obj); + SWIG_PYTHON_THREAD_END_BLOCK; +} + +SWIGINTERN void +SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(errtype, (char *) msg); + SWIG_PYTHON_THREAD_END_BLOCK; +} + +#define SWIG_Python_Raise(obj, type, desc) SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj) + +/* Set a constant value */ + +SWIGINTERN void +SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { + PyDict_SetItemString(d, (char*) name, obj); + Py_DECREF(obj); +} + +/* Append a value to the result obj */ + +SWIGINTERN PyObject* +SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { +#if !defined(SWIG_PYTHON_OUTPUT_TUPLE) + 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; +#else + PyObject* o2; + PyObject* o3; + if (!result) { + result = obj; + } else if (result == Py_None) { + Py_DECREF(result); + result = obj; + } else { + if (!PyTuple_Check(result)) { + o2 = result; + result = PyTuple_New(1); + PyTuple_SET_ITEM(result, 0, o2); + } + o3 = PyTuple_New(1); + PyTuple_SET_ITEM(o3, 0, obj); + o2 = result; + result = PySequence_Concat(o2, o3); + Py_DECREF(o2); + Py_DECREF(o3); + } + return result; +#endif +} + +/* Unpack the argument tuple */ + +SWIGINTERN int +SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs) +{ + if (!args) { + if (!min && !max) { + return 1; + } else { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", + name, (min == max ? "" : "at least "), (int)min); + return 0; + } + } + if (!PyTuple_Check(args)) { + PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); + return 0; + } else { + register Py_ssize_t l = PyTuple_GET_SIZE(args); + if (l < min) { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", + name, (min == max ? "" : "at least "), (int)min, (int)l); + return 0; + } else if (l > max) { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", + name, (min == max ? "" : "at most "), (int)max, (int)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; + } + } +} + +/* 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 + +/* + 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) + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* cc-mode */ +#endif +#endif + +/* How to access Py_None */ +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# ifndef SWIG_PYTHON_NO_BUILD_NONE +# ifndef SWIG_PYTHON_BUILD_NONE +# define SWIG_PYTHON_BUILD_NONE +# endif +# endif +#endif + +#ifdef SWIG_PYTHON_BUILD_NONE +# ifdef Py_None +# undef Py_None +# define Py_None SWIG_Py_None() +# endif +SWIGRUNTIMEINLINE PyObject * +_SWIG_Py_None(void) +{ + PyObject *none = Py_BuildValue((char*)""); + Py_DECREF(none); + return none; +} +SWIGRUNTIME PyObject * +SWIG_Py_None(void) +{ + static PyObject *SWIG_STATIC_POINTER(none) = _SWIG_Py_None(); + return none; +} +#endif + +/* The python void return value */ + +SWIGRUNTIMEINLINE PyObject * +SWIG_Py_Void(void) +{ + PyObject *none = Py_None; + Py_INCREF(none); + return none; +} + +/* SwigPyClientData */ + +typedef struct { + PyObject *klass; + PyObject *newraw; + PyObject *newargs; + PyObject *destroy; + int delargs; + int implicitconv; +} SwigPyClientData; + +SWIGRUNTIMEINLINE int +SWIG_Python_CheckImplicit(swig_type_info *ty) +{ + SwigPyClientData *data = (SwigPyClientData *)ty->clientdata; + return data ? data->implicitconv : 0; +} + +SWIGRUNTIMEINLINE PyObject * +SWIG_Python_ExceptionType(swig_type_info *desc) { + SwigPyClientData *data = desc ? (SwigPyClientData *) desc->clientdata : 0; + PyObject *klass = data ? data->klass : 0; + return (klass ? klass : PyExc_RuntimeError); +} + + +SWIGRUNTIME SwigPyClientData * +SwigPyClientData_New(PyObject* obj) +{ + if (!obj) { + return 0; + } else { + SwigPyClientData *data = (SwigPyClientData *)malloc(sizeof(SwigPyClientData)); + /* the klass element */ + data->klass = obj; + Py_INCREF(data->klass); + /* 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; +#else + data->newraw = PyObject_GetAttrString(data->klass, (char *)"__new__"); +#endif + if (data->newraw) { + Py_INCREF(data->newraw); + data->newargs = PyTuple_New(1); + PyTuple_SetItem(data->newargs, 0, obj); + } else { + data->newargs = obj; + } + Py_INCREF(data->newargs); + } + /* the destroy method, aka as the C++ delete method */ + data->destroy = PyObject_GetAttrString(data->klass, (char *)"__swig_destroy__"); + if (PyErr_Occurred()) { + PyErr_Clear(); + data->destroy = 0; + } + if (data->destroy) { + int flags; + Py_INCREF(data->destroy); + 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 +SwigPyClientData_Del(SwigPyClientData* data) +{ + Py_XDECREF(data->newraw); + Py_XDECREF(data->newargs); + Py_XDECREF(data->destroy); +} + +/* =============== SwigPyObject =====================*/ + +typedef struct { + PyObject_HEAD + void *ptr; + swig_type_info *ty; + int own; + PyObject *next; +} SwigPyObject; + +SWIGRUNTIME PyObject * +SwigPyObject_long(SwigPyObject *v) +{ + return PyLong_FromVoidPtr(v->ptr); +} + +SWIGRUNTIME PyObject * +SwigPyObject_format(const char* fmt, SwigPyObject *v) +{ + PyObject *res = NULL; + PyObject *args = PyTuple_New(1); + if (args) { + if (PyTuple_SetItem(args, 0, SwigPyObject_long(v)) == 0) { + PyObject *ofmt = SWIG_Python_str_FromChar(fmt); + if (ofmt) { +#if PY_VERSION_HEX >= 0x03000000 + res = PyUnicode_Format(ofmt,args); +#else + res = PyString_Format(ofmt,args); +#endif + Py_DECREF(ofmt); + } + Py_DECREF(args); + } + } + return res; +} + +SWIGRUNTIME PyObject * +SwigPyObject_oct(SwigPyObject *v) +{ + return SwigPyObject_format("%o",v); +} + +SWIGRUNTIME PyObject * +SwigPyObject_hex(SwigPyObject *v) +{ + return SwigPyObject_format("%x",v); +} + +SWIGRUNTIME PyObject * +#ifdef METH_NOARGS +SwigPyObject_repr(SwigPyObject *v) +#else +SwigPyObject_repr(SwigPyObject *v, PyObject *args) +#endif +{ + const char *name = SWIG_TypePrettyName(v->ty); + PyObject *repr = SWIG_Python_str_FromFormat("", name, v); + if (v->next) { +#ifdef METH_NOARGS + PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next); +#else + PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next, args); +#endif +#if PY_VERSION_HEX >= 0x03000000 + PyObject *joined = PyUnicode_Concat(repr, nrep); + Py_DecRef(repr); + Py_DecRef(nrep); + repr = joined; +#else + PyString_ConcatAndDel(&repr,nrep); +#endif + } + return repr; +} + +SWIGRUNTIME int +SwigPyObject_print(SwigPyObject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) +{ + char *str; +#ifdef METH_NOARGS + PyObject *repr = SwigPyObject_repr(v); +#else + PyObject *repr = SwigPyObject_repr(v, NULL); +#endif + if (repr) { + str = SWIG_Python_str_AsChar(repr); + fputs(str, fp); + SWIG_Python_str_DelForPy3(str); + Py_DECREF(repr); + return 0; + } else { + return 1; + } +} + +SWIGRUNTIME PyObject * +SwigPyObject_str(SwigPyObject *v) +{ + char result[SWIG_BUFFER_SIZE]; + return SWIG_PackVoidPtr(result, v->ptr, v->ty->name, sizeof(result)) ? + SWIG_Python_str_FromChar(result) : 0; +} + +SWIGRUNTIME int +SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w) +{ + void *i = v->ptr; + void *j = w->ptr; + return (i < j) ? -1 : ((i > j) ? 1 : 0); +} + +/* Added for Python 3.x, would it also be useful for Python 2.x? */ +SWIGRUNTIME PyObject* +SwigPyObject_richcompare(SwigPyObject *v, SwigPyObject *w, int op) +{ + PyObject* res; + if( op != Py_EQ && op != Py_NE ) { + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; + } + if( (SwigPyObject_compare(v, w)==0) == (op == Py_EQ) ) + res = Py_True; + else + res = Py_False; + Py_INCREF(res); + return res; +} + + +SWIGRUNTIME PyTypeObject* _PySwigObject_type(void); + +SWIGRUNTIME PyTypeObject* +SwigPyObject_type(void) { + static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigObject_type(); + return type; +} + +SWIGRUNTIMEINLINE int +SwigPyObject_Check(PyObject *op) { + return (Py_TYPE(op) == SwigPyObject_type()) + || (strcmp(Py_TYPE(op)->tp_name,"SwigPyObject") == 0); +} + +SWIGRUNTIME PyObject * +SwigPyObject_New(void *ptr, swig_type_info *ty, int own); + +SWIGRUNTIME void +SwigPyObject_dealloc(PyObject *v) +{ + SwigPyObject *sobj = (SwigPyObject *) v; + PyObject *next = sobj->next; + if (sobj->own == SWIG_POINTER_OWN) { + swig_type_info *ty = sobj->ty; + SwigPyClientData *data = ty ? (SwigPyClientData *) 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 temporary object to carry the destroy operation */ + PyObject *tmp = SwigPyObject_New(sobj->ptr, ty, 0); + res = SWIG_Python_CallFunctor(destroy, tmp); + Py_DECREF(tmp); + } else { + PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); + PyObject *mself = PyCFunction_GET_SELF(destroy); + res = ((*meth)(mself, v)); + } + Py_XDECREF(res); + } +#if !defined(SWIG_PYTHON_SILENT_MEMLEAK) + else { + const char *name = SWIG_TypePrettyName(ty); + printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); + } +#endif + } + Py_XDECREF(next); + PyObject_DEL(v); +} + +SWIGRUNTIME PyObject* +SwigPyObject_append(PyObject* v, PyObject* next) +{ + SwigPyObject *sobj = (SwigPyObject *) v; +#ifndef METH_O + PyObject *tmp = 0; + if (!PyArg_ParseTuple(next,(char *)"O:append", &tmp)) return NULL; + next = tmp; +#endif + if (!SwigPyObject_Check(next)) { + return NULL; + } + sobj->next = next; + Py_INCREF(next); + return SWIG_Py_Void(); +} + +SWIGRUNTIME PyObject* +#ifdef METH_NOARGS +SwigPyObject_next(PyObject* v) +#else +SwigPyObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) +#endif +{ + SwigPyObject *sobj = (SwigPyObject *) v; + if (sobj->next) { + Py_INCREF(sobj->next); + return sobj->next; + } else { + return SWIG_Py_Void(); + } +} + +SWIGINTERN PyObject* +#ifdef METH_NOARGS +SwigPyObject_disown(PyObject *v) +#else +SwigPyObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) +#endif +{ + SwigPyObject *sobj = (SwigPyObject *)v; + sobj->own = 0; + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject* +#ifdef METH_NOARGS +SwigPyObject_acquire(PyObject *v) +#else +SwigPyObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) +#endif +{ + SwigPyObject *sobj = (SwigPyObject *)v; + sobj->own = SWIG_POINTER_OWN; + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject* +SwigPyObject_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 + { + SwigPyObject *sobj = (SwigPyObject *)v; + PyObject *obj = PyBool_FromLong(sobj->own); + if (val) { +#ifdef METH_NOARGS + if (PyObject_IsTrue(val)) { + SwigPyObject_acquire(v); + } else { + SwigPyObject_disown(v); + } +#else + if (PyObject_IsTrue(val)) { + SwigPyObject_acquire(v,args); + } else { + SwigPyObject_disown(v,args); + } +#endif + } + return obj; + } +} + +#ifdef METH_O +static PyMethodDef +swigobject_methods[] = { + {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, + {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_NOARGS, (char *)"aquires ownership of the pointer"}, + {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, + {(char *)"append", (PyCFunction)SwigPyObject_append, METH_O, (char *)"appends another 'this' object"}, + {(char *)"next", (PyCFunction)SwigPyObject_next, METH_NOARGS, (char *)"returns the next 'this' object"}, + {(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_NOARGS, (char *)"returns object representation"}, + {0, 0, 0, 0} +}; +#else +static PyMethodDef +swigobject_methods[] = { + {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_VARARGS, (char *)"releases ownership of the pointer"}, + {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_VARARGS, (char *)"aquires ownership of the pointer"}, + {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, + {(char *)"append", (PyCFunction)SwigPyObject_append, METH_VARARGS, (char *)"appends another 'this' object"}, + {(char *)"next", (PyCFunction)SwigPyObject_next, METH_VARARGS, (char *)"returns the next 'this' object"}, + {(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_VARARGS, (char *)"returns object representation"}, + {0, 0, 0, 0} +}; +#endif + +#if PY_VERSION_HEX < 0x02020000 +SWIGINTERN PyObject * +SwigPyObject_getattr(SwigPyObject *sobj,char *name) +{ + return Py_FindMethod(swigobject_methods, (PyObject *)sobj, name); +} +#endif + +SWIGRUNTIME PyTypeObject* +_PySwigObject_type(void) { + static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; + + static PyNumberMethods SwigPyObject_as_number = { + (binaryfunc)0, /*nb_add*/ + (binaryfunc)0, /*nb_subtract*/ + (binaryfunc)0, /*nb_multiply*/ + /* nb_divide removed in Python 3 */ +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc)0, /*nb_divide*/ +#endif + (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*/ +#if PY_VERSION_HEX < 0x03000000 + 0, /*nb_coerce*/ +#endif + (unaryfunc)SwigPyObject_long, /*nb_int*/ +#if PY_VERSION_HEX < 0x03000000 + (unaryfunc)SwigPyObject_long, /*nb_long*/ +#else + 0, /*nb_reserved*/ +#endif + (unaryfunc)0, /*nb_float*/ +#if PY_VERSION_HEX < 0x03000000 + (unaryfunc)SwigPyObject_oct, /*nb_oct*/ + (unaryfunc)SwigPyObject_hex, /*nb_hex*/ +#endif +#if PY_VERSION_HEX >= 0x03000000 /* 3.0 */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index, nb_inplace_divide removed */ +#elif PY_VERSION_HEX >= 0x02050000 /* 2.5.0 */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */ +#elif PY_VERSION_HEX >= 0x02020000 /* 2.2.0 */ + 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 /* 2.0.0 */ + 0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_or */ +#endif + }; + + static PyTypeObject swigpyobject_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp + = { + /* PyObject header changed in Python 3 */ +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ +#endif + (char *)"SwigPyObject", /* tp_name */ + sizeof(SwigPyObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)SwigPyObject_dealloc, /* tp_dealloc */ + (printfunc)SwigPyObject_print, /* tp_print */ +#if PY_VERSION_HEX < 0x02020000 + (getattrfunc)SwigPyObject_getattr, /* tp_getattr */ +#else + (getattrfunc)0, /* tp_getattr */ +#endif + (setattrfunc)0, /* tp_setattr */ +#if PY_VERSION_HEX >= 0x03000000 + 0, /* tp_reserved in 3.0.1, tp_compare in 3.0.0 but not used */ +#else + (cmpfunc)SwigPyObject_compare, /* tp_compare */ +#endif + (reprfunc)SwigPyObject_repr, /* tp_repr */ + &SwigPyObject_as_number, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)0, /* tp_hash */ + (ternaryfunc)0, /* tp_call */ + (reprfunc)SwigPyObject_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 */ + (richcmpfunc)SwigPyObject_richcompare, /* 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 */ + 0, /* 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 + }; + swigpyobject_type = tmp; + /* for Python 3 we already assigned ob_type in PyVarObject_HEAD_INIT() */ +#if PY_VERSION_HEX < 0x03000000 + swigpyobject_type.ob_type = &PyType_Type; +#endif + type_init = 1; + } + return &swigpyobject_type; +} + +SWIGRUNTIME PyObject * +SwigPyObject_New(void *ptr, swig_type_info *ty, int own) +{ + SwigPyObject *sobj = PyObject_NEW(SwigPyObject, SwigPyObject_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; +} SwigPyPacked; + +SWIGRUNTIME int +SwigPyPacked_print(SwigPyPacked *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 * +SwigPyPacked_repr(SwigPyPacked *v) +{ + char result[SWIG_BUFFER_SIZE]; + if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { + return SWIG_Python_str_FromFormat("", result, v->ty->name); + } else { + return SWIG_Python_str_FromFormat("", v->ty->name); + } +} + +SWIGRUNTIME PyObject * +SwigPyPacked_str(SwigPyPacked *v) +{ + char result[SWIG_BUFFER_SIZE]; + if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ + return SWIG_Python_str_FromFormat("%s%s", result, v->ty->name); + } else { + return SWIG_Python_str_FromChar(v->ty->name); + } +} + +SWIGRUNTIME int +SwigPyPacked_compare(SwigPyPacked *v, SwigPyPacked *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* +SwigPyPacked_type(void) { + static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigPacked_type(); + return type; +} + +SWIGRUNTIMEINLINE int +SwigPyPacked_Check(PyObject *op) { + return ((op)->ob_type == _PySwigPacked_type()) + || (strcmp((op)->ob_type->tp_name,"SwigPyPacked") == 0); +} + +SWIGRUNTIME void +SwigPyPacked_dealloc(PyObject *v) +{ + if (SwigPyPacked_Check(v)) { + SwigPyPacked *sobj = (SwigPyPacked *) 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 swigpypacked_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp + = { + /* PyObject header changed in Python 3 */ +#if PY_VERSION_HEX>=0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ +#endif + (char *)"SwigPyPacked", /* tp_name */ + sizeof(SwigPyPacked), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)SwigPyPacked_dealloc, /* tp_dealloc */ + (printfunc)SwigPyPacked_print, /* tp_print */ + (getattrfunc)0, /* tp_getattr */ + (setattrfunc)0, /* tp_setattr */ +#if PY_VERSION_HEX>=0x03000000 + 0, /* tp_reserved in 3.0.1 */ +#else + (cmpfunc)SwigPyPacked_compare, /* tp_compare */ +#endif + (reprfunc)SwigPyPacked_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)0, /* tp_hash */ + (ternaryfunc)0, /* tp_call */ + (reprfunc)SwigPyPacked_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 */ + 0, /* 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 + }; + swigpypacked_type = tmp; + /* for Python 3 the ob_type already assigned in PyVarObject_HEAD_INIT() */ +#if PY_VERSION_HEX < 0x03000000 + swigpypacked_type.ob_type = &PyType_Type; +#endif + type_init = 1; + } + return &swigpypacked_type; +} + +SWIGRUNTIME PyObject * +SwigPyPacked_New(void *ptr, size_t size, swig_type_info *ty) +{ + SwigPyPacked *sobj = PyObject_NEW(SwigPyPacked, SwigPyPacked_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 * +SwigPyPacked_UnpackData(PyObject *obj, void *ptr, size_t size) +{ + if (SwigPyPacked_Check(obj)) { + SwigPyPacked *sobj = (SwigPyPacked *)obj; + if (sobj->size != size) return 0; + memcpy(ptr, sobj->pack, size); + return sobj->ty; + } else { + return 0; + } +} + +/* ----------------------------------------------------------------------------- + * pointers/data manipulation + * ----------------------------------------------------------------------------- */ + +SWIGRUNTIMEINLINE PyObject * +_SWIG_This(void) +{ + return SWIG_Python_str_FromChar("this"); +} + +SWIGRUNTIME PyObject * +SWIG_This(void) +{ + static PyObject *SWIG_STATIC_POINTER(swig_this) = _SWIG_This(); + return swig_this; +} + +/* #define SWIG_PYTHON_SLOW_GETSET_THIS */ + +/* TODO: I don't know how to implement the fast getset in Python 3 right now */ +#if PY_VERSION_HEX>=0x03000000 +#define SWIG_PYTHON_SLOW_GETSET_THIS +#endif + +SWIGRUNTIME SwigPyObject * +SWIG_Python_GetSwigThis(PyObject *pyobj) +{ + if (SwigPyObject_Check(pyobj)) { + return (SwigPyObject *) pyobj; + } else { + PyObject *obj = 0; +#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000)) + 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; + } else { +#ifdef PyWeakref_CheckProxy + if (PyWeakref_CheckProxy(pyobj)) { + PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); + return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; + } +#endif + 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 + if (obj && !SwigPyObject_Check(obj)) { + /* a PyObject is called 'this', try to get the 'real this' + SwigPyObject from it */ + return SWIG_Python_GetSwigThis(obj); + } + return (SwigPyObject *)obj; + } +} + +/* Acquire a pointer value */ + +SWIGRUNTIME int +SWIG_Python_AcquirePtr(PyObject *obj, int own) { + if (own == SWIG_POINTER_OWN) { + SwigPyObject *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 { + SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); + if (own) + *own = 0; + 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 = (SwigPyObject *)sobj->next; + } else { + if (ptr) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + if (newmemory == SWIG_CAST_NEW_MEMORY) { + assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ + if (own) + *own = *own | SWIG_CAST_NEW_MEMORY; + } + } + break; + } + } + } else { + if (ptr) *ptr = vptr; + break; + } + } + if (sobj) { + if (own) + *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) { + SwigPyClientData *data = ty ? (SwigPyClientData *) 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) { + SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv); + if (iobj) { + void *vptr; + res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0); + if (SWIG_IsOK(res)) { + if (ptr) { + *ptr = vptr; + /* transfer the ownership to 'ptr' */ + iobj->own = 0; + res = SWIG_AddCast(res); + res = SWIG_AddNewMask(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 */ + const 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) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ + } else { + return SWIG_ERROR; + } + } 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 = SwigPyPacked_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, without calling __init__, and set the + 'this' attribute. +*/ + +SWIGRUNTIME PyObject* +SWIG_Python_NewShadowInstance(SwigPyClientData *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 { +#if PY_VERSION_HEX >= 0x03000000 + inst = PyBaseObject_Type.tp_new((PyTypeObject*) data->newargs, Py_None, Py_None); + PyObject_SetAttr(inst, SWIG_This(), swig_this); + Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG; +#else + PyObject *dict = PyDict_New(); + PyDict_SetItem(dict, SWIG_This(), swig_this); + inst = PyInstance_NewRaw(data->newargs, dict); + Py_DECREF(dict); +#endif + } + return inst; +#else +#if (PY_VERSION_HEX >= 0x02010000) + PyObject *inst; + PyObject *dict = PyDict_New(); + PyDict_SetItem(dict, SWIG_This(), swig_this); + inst = PyInstance_NewRaw(data->newargs, dict); + Py_DECREF(dict); + return (PyObject *) 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; + } +#ifdef Py_TPFLAGS_HAVE_WEAKREFS + inst->in_weakreflist = NULL; +#endif +#ifdef Py_TPFLAGS_GC + PyObject_GC_Init(inst); +#endif + PyDict_SetItem(inst->in_dict, SWIG_This(), swig_this); + return (PyObject *) inst; +#endif +#endif +} + +SWIGRUNTIME void +SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) +{ + PyObject *dict; +#if (PY_VERSION_HEX >= 0x02020000) && !defined(SWIG_PYTHON_SLOW_GETSET_THIS) + PyObject **dictptr = _PyObject_GetDictPtr(inst); + if (dictptr != NULL) { + dict = *dictptr; + if (dict == NULL) { + dict = PyDict_New(); + *dictptr = dict; + } + PyDict_SetItem(dict, SWIG_This(), swig_this); + return; + } +#endif + dict = PyObject_GetAttrString(inst, (char*)"__dict__"); + PyDict_SetItem(dict, SWIG_This(), swig_this); + Py_DECREF(dict); +} + + +SWIGINTERN PyObject * +SWIG_Python_InitShadowInstance(PyObject *args) { + PyObject *obj[2]; + if (!SWIG_Python_UnpackTuple(args,(char*)"swiginit", 2, 2, obj)) { + return NULL; + } else { + SwigPyObject *sthis = SWIG_Python_GetSwigThis(obj[0]); + if (sthis) { + SwigPyObject_append((PyObject*) sthis, obj[1]); + } else { + SWIG_Python_SetSwigThis(obj[0], obj[1]); + } + return SWIG_Py_Void(); + } +} + +/* 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 = SwigPyObject_New(ptr, type, own); + SwigPyClientData *clientdata = type ? (SwigPyClientData *)(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 ? SwigPyPacked_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) { + SwigPyClientData *data = (SwigPyClientData *) ty->clientdata; + if (data) SwigPyClientData_Del(data); + } + } + 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 */ + +#if PY_VERSION_HEX >= 0x03000000 + /* Add a dummy module object into sys.modules */ + PyObject *module = PyImport_AddModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION); +#else + PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, + swig_empty_runtime_method_table); +#endif + 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); + } +} + +/* The python cached type query */ +SWIGRUNTIME PyObject * +SWIG_Python_TypeCache(void) { + static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); + return cache; +} + +SWIGRUNTIME swig_type_info * +SWIG_Python_TypeQuery(const char *type) +{ + PyObject *cache = SWIG_Python_TypeCache(); + PyObject *key = SWIG_Python_str_FromChar(type); + PyObject *obj = PyDict_GetItem(cache, key); + swig_type_info *descriptor; + if (obj) { + descriptor = (swig_type_info *) PyCObject_AsVoidPtr(obj); + } else { + swig_module_info *swig_module = SWIG_Python_GetModule(); + descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); + if (descriptor) { + obj = PyCObject_FromVoidPtr(descriptor, NULL); + PyDict_SetItem(cache, key, obj); + Py_DECREF(obj); + } + } + Py_DECREF(key); + return descriptor; +} + +/* + For backward compatibility only +*/ +#define SWIG_POINTER_EXCEPTION 0 +#define SWIG_arg_fail(arg) SWIG_Python_ArgFail(arg) +#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) + +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) { + char *tmp; + PyObject *old_str = PyObject_Str(value); + Py_XINCREF(type); + PyErr_Clear(); + if (infront) { + PyErr_Format(type, "%s %s", mesg, tmp = SWIG_Python_str_AsChar(old_str)); + } else { + PyErr_Format(type, "%s %s", tmp = SWIG_Python_str_AsChar(old_str), mesg); + } + SWIG_Python_str_DelForPy3(tmp); + 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]; + PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); + return SWIG_Python_AddErrMesg(mesg, 1); + } else { + return 0; + } +} + +SWIGRUNTIMEINLINE const char * +SwigPyObject_GetDesc(PyObject *self) +{ + SwigPyObject *v = (SwigPyObject *)self; + swig_type_info *ty = v ? v->ty : 0; + return ty ? ty->str : (char*)""; +} + +SWIGRUNTIME void +SWIG_Python_TypeError(const char *type, PyObject *obj) +{ + if (type) { +#if defined(SWIG_COBJECT_TYPES) + if (obj && SwigPyObject_Check(obj)) { + const char *otype = (const char *) SwigPyObject_GetDesc(obj); + if (otype) { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'SwigPyObject(%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 ? SWIG_Python_str_AsChar(str) : 0; + if (cstr) { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", + type, otype, cstr); + SWIG_Python_str_DelForPy3(cstr); + } else { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", + type, otype); + } + Py_XDECREF(str); + return; + } + } + PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); + } else { + PyErr_Format(PyExc_TypeError, "unexpected type is received"); + } +} + + +/* 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 SWIG_POINTER_EXCEPTION + if (flags) { + SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); + SWIG_Python_ArgFail(argnum); + } +#endif + } + return result; +} + + +#ifdef __cplusplus +#if 0 +{ /* cc-mode */ +#endif +} +#endif + + + +#define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) + +#define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else + + + +/* -------- TYPES TABLE (BEGIN) -------- */ + +#define SWIGTYPE_p_P swig_types[0] +#define SWIGTYPE_p_char swig_types[1] +#define SWIGTYPE_p_point swig_types[2] +static swig_type_info *swig_types[4]; +static swig_module_info swig_module = {swig_types, 3, 0, 0, 0, 0}; +#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) +#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) + +/* -------- TYPES TABLE (END) -------- */ + +#if (PY_VERSION_HEX <= 0x02000000) +# if !defined(SWIG_PYTHON_CLASSIC) +# error "This python version requires swig to be run with the '-classic' option" +# endif +#endif + +/*----------------------------------------------- + @(target):= _cpp0x_unrestricted_unions.so + ------------------------------------------------*/ +#if PY_VERSION_HEX >= 0x03000000 +# define SWIG_init PyInit__cpp0x_unrestricted_unions + +#else +# define SWIG_init init_cpp0x_unrestricted_unions + +#endif +#define SWIG_name "_cpp0x_unrestricted_unions" + +#define SWIGVERSION 0x020001 +#define SWIG_VERSION SWIGVERSION + + +#define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a)) +#define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),reinterpret_cast< void** >(a)) + + +#include + + +namespace swig { + class SwigPtr_PyObject { + protected: + PyObject *_obj; + + public: + SwigPtr_PyObject() :_obj(0) + { + } + + SwigPtr_PyObject(const SwigPtr_PyObject& item) : _obj(item._obj) + { + Py_XINCREF(_obj); + } + + SwigPtr_PyObject(PyObject *obj, bool initial_ref = true) :_obj(obj) + { + if (initial_ref) { + Py_XINCREF(_obj); + } + } + + SwigPtr_PyObject & operator=(const SwigPtr_PyObject& item) + { + Py_XINCREF(item._obj); + Py_XDECREF(_obj); + _obj = item._obj; + return *this; + } + + ~SwigPtr_PyObject() + { + Py_XDECREF(_obj); + } + + operator PyObject *() const + { + return _obj; + } + + PyObject *operator->() const + { + return _obj; + } + }; +} + + +namespace swig { + struct SwigVar_PyObject : SwigPtr_PyObject { + SwigVar_PyObject(PyObject* obj = 0) : SwigPtr_PyObject(obj, false) { } + + SwigVar_PyObject & operator = (PyObject* obj) + { + Py_XDECREF(_obj); + _obj = obj; + return *this; + } + }; +} + + +struct point { + point() {} + point(int x, int y) : x_(x), y_(y) {} + int x_, y_; +}; + +#include // For placement 'new' in the constructor below +union P { + int z; + double w; + point p; // Illegal in C++03; legal in C++11. + // Due to the point member, a constructor definition is required. + P() { + new(&p) point(); + } +} p1; + + +#include +#if !defined(SWIG_NO_LLONG_MAX) +# if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__) +# define LLONG_MAX __LONG_LONG_MAX__ +# define LLONG_MIN (-LLONG_MAX - 1LL) +# define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) +# endif +#endif + + +SWIGINTERN int +SWIG_AsVal_double (PyObject *obj, double *val) +{ + int res = SWIG_TypeError; + if (PyFloat_Check(obj)) { + if (val) *val = PyFloat_AsDouble(obj); + return SWIG_OK; + } else if (PyInt_Check(obj)) { + if (val) *val = PyInt_AsLong(obj); + return SWIG_OK; + } else if (PyLong_Check(obj)) { + double v = PyLong_AsDouble(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_OK; + } else { + PyErr_Clear(); + } + } +#ifdef SWIG_PYTHON_CAST_MODE + { + int dispatch = 0; + double d = PyFloat_AsDouble(obj); + if (!PyErr_Occurred()) { + if (val) *val = d; + return SWIG_AddCast(SWIG_OK); + } else { + PyErr_Clear(); + } + if (!dispatch) { + long v = PyLong_AsLong(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_AddCast(SWIG_AddCast(SWIG_OK)); + } else { + PyErr_Clear(); + } + } + } +#endif + return res; +} + + +#include + + +#include + + +SWIGINTERNINLINE int +SWIG_CanCastAsInteger(double *d, double min, double max) { + double x = *d; + if ((min <= x && x <= max)) { + double fx = floor(x); + double cx = ceil(x); + double rd = ((x - fx) < 0.5) ? fx : cx; /* simple rint */ + if ((errno == EDOM) || (errno == ERANGE)) { + errno = 0; + } else { + double summ, reps, diff; + if (rd < x) { + diff = x - rd; + } else if (rd > x) { + diff = rd - x; + } else { + return 1; + } + summ = rd + x; + reps = diff/summ; + if (reps < 8*DBL_EPSILON) { + *d = rd; + return 1; + } + } + } + return 0; +} + + +SWIGINTERN int +SWIG_AsVal_long (PyObject *obj, long* val) +{ + if (PyInt_Check(obj)) { + if (val) *val = PyInt_AsLong(obj); + return SWIG_OK; + } else if (PyLong_Check(obj)) { + long v = PyLong_AsLong(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_OK; + } else { + PyErr_Clear(); + } + } +#ifdef SWIG_PYTHON_CAST_MODE + { + int dispatch = 0; + long v = PyInt_AsLong(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_AddCast(SWIG_OK); + } else { + PyErr_Clear(); + } + if (!dispatch) { + double d; + int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d)); + if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) { + if (val) *val = (long)(d); + return res; + } + } + } +#endif + return SWIG_TypeError; +} + + +SWIGINTERN int +SWIG_AsVal_int (PyObject * obj, int *val) +{ + long v; + int res = SWIG_AsVal_long (obj, &v); + if (SWIG_IsOK(res)) { + if ((v < INT_MIN || v > INT_MAX)) { + return SWIG_OverflowError; + } else { + if (val) *val = static_cast< int >(v); + } + } + return res; +} + + + #define SWIG_From_long PyInt_FromLong + + +SWIGINTERNINLINE PyObject * +SWIG_From_int (int value) +{ + return SWIG_From_long (value); +} + + + #define SWIG_From_double PyFloat_FromDouble + +#ifdef __cplusplus +extern "C" { +#endif +SWIGINTERN PyObject *_wrap_new_point__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + point *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)":new_point")) SWIG_fail; + result = (point *)new point(); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_point, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_new_point__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + int arg1 ; + int arg2 ; + int val1 ; + int ecode1 = 0 ; + int val2 ; + int ecode2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + point *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OO:new_point",&obj0,&obj1)) SWIG_fail; + ecode1 = SWIG_AsVal_int(obj0, &val1); + if (!SWIG_IsOK(ecode1)) { + SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "new_point" "', argument " "1"" of type '" "int""'"); + } + arg1 = static_cast< int >(val1); + ecode2 = SWIG_AsVal_int(obj1, &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "new_point" "', argument " "2"" of type '" "int""'"); + } + arg2 = static_cast< int >(val2); + result = (point *)new point(arg1,arg2); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_point, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_new_point(PyObject *self, PyObject *args) { + int argc; + PyObject *argv[3]; + int ii; + + if (!PyTuple_Check(args)) SWIG_fail; + argc = (int)PyObject_Length(args); + for (ii = 0; (ii < argc) && (ii < 2); ii++) { + argv[ii] = PyTuple_GET_ITEM(args,ii); + } + if (argc == 0) { + return _wrap_new_point__SWIG_0(self, args); + } + if (argc == 2) { + int _v; + { + int res = SWIG_AsVal_int(argv[0], NULL); + _v = SWIG_CheckState(res); + } + if (_v) { + { + int res = SWIG_AsVal_int(argv[1], NULL); + _v = SWIG_CheckState(res); + } + if (_v) { + return _wrap_new_point__SWIG_1(self, args); + } + } + } + +fail: + SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number of arguments for overloaded function 'new_point'.\n" + " Possible C/C++ prototypes are:\n" + " point()\n" + " point(int,int)\n"); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_point_x__set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + point *arg1 = (point *) 0 ; + int arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + int val2 ; + int ecode2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OO:point_x__set",&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_point, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "point_x__set" "', argument " "1"" of type '" "point *""'"); + } + arg1 = reinterpret_cast< point * >(argp1); + ecode2 = SWIG_AsVal_int(obj1, &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "point_x__set" "', argument " "2"" of type '" "int""'"); + } + arg2 = static_cast< int >(val2); + if (arg1) (arg1)->x_ = arg2; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_point_x__get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + point *arg1 = (point *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + int result; + + if (!PyArg_ParseTuple(args,(char *)"O:point_x__get",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_point, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "point_x__get" "', argument " "1"" of type '" "point *""'"); + } + arg1 = reinterpret_cast< point * >(argp1); + result = (int) ((arg1)->x_); + resultobj = SWIG_From_int(static_cast< int >(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_point_y__set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + point *arg1 = (point *) 0 ; + int arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + int val2 ; + int ecode2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OO:point_y__set",&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_point, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "point_y__set" "', argument " "1"" of type '" "point *""'"); + } + arg1 = reinterpret_cast< point * >(argp1); + ecode2 = SWIG_AsVal_int(obj1, &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "point_y__set" "', argument " "2"" of type '" "int""'"); + } + arg2 = static_cast< int >(val2); + if (arg1) (arg1)->y_ = arg2; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_point_y__get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + point *arg1 = (point *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + int result; + + if (!PyArg_ParseTuple(args,(char *)"O:point_y__get",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_point, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "point_y__get" "', argument " "1"" of type '" "point *""'"); + } + arg1 = reinterpret_cast< point * >(argp1); + result = (int) ((arg1)->y_); + resultobj = SWIG_From_int(static_cast< int >(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_delete_point(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + point *arg1 = (point *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:delete_point",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_point, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_point" "', argument " "1"" of type '" "point *""'"); + } + arg1 = reinterpret_cast< point * >(argp1); + delete arg1; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *point_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *obj; + if (!PyArg_ParseTuple(args,(char*)"O:swigregister", &obj)) return NULL; + SWIG_TypeNewClientData(SWIGTYPE_p_point, SWIG_NewClientData(obj)); + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject *_wrap_P_z_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + P *arg1 = (P *) 0 ; + int arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + int val2 ; + int ecode2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OO:P_z_set",&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_P, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "P_z_set" "', argument " "1"" of type '" "P *""'"); + } + arg1 = reinterpret_cast< P * >(argp1); + ecode2 = SWIG_AsVal_int(obj1, &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "P_z_set" "', argument " "2"" of type '" "int""'"); + } + arg2 = static_cast< int >(val2); + if (arg1) (arg1)->z = arg2; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_P_z_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + P *arg1 = (P *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + int result; + + if (!PyArg_ParseTuple(args,(char *)"O:P_z_get",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_P, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "P_z_get" "', argument " "1"" of type '" "P *""'"); + } + arg1 = reinterpret_cast< P * >(argp1); + result = (int) ((arg1)->z); + resultobj = SWIG_From_int(static_cast< int >(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_P_w_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + P *arg1 = (P *) 0 ; + double arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + double val2 ; + int ecode2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OO:P_w_set",&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_P, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "P_w_set" "', argument " "1"" of type '" "P *""'"); + } + arg1 = reinterpret_cast< P * >(argp1); + ecode2 = SWIG_AsVal_double(obj1, &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "P_w_set" "', argument " "2"" of type '" "double""'"); + } + arg2 = static_cast< double >(val2); + if (arg1) (arg1)->w = arg2; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_P_w_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + P *arg1 = (P *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + double result; + + if (!PyArg_ParseTuple(args,(char *)"O:P_w_get",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_P, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "P_w_get" "', argument " "1"" of type '" "P *""'"); + } + arg1 = reinterpret_cast< P * >(argp1); + result = (double) ((arg1)->w); + resultobj = SWIG_From_double(static_cast< double >(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_P_p_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + P *arg1 = (P *) 0 ; + point *arg2 = (point *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OO:P_p_set",&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_P, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "P_p_set" "', argument " "1"" of type '" "P *""'"); + } + arg1 = reinterpret_cast< P * >(argp1); + res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_point, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "P_p_set" "', argument " "2"" of type '" "point *""'"); + } + arg2 = reinterpret_cast< point * >(argp2); + if (arg1) (arg1)->p = *arg2; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_P_p_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + P *arg1 = (P *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + point *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:P_p_get",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_P, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "P_p_get" "', argument " "1"" of type '" "P *""'"); + } + arg1 = reinterpret_cast< P * >(argp1); + result = (point *)& ((arg1)->p); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_point, 0 | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_new_P(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + P *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)":new_P")) SWIG_fail; + result = (P *)new P(); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_P, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_delete_P(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + P *arg1 = (P *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:delete_P",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_P, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_P" "', argument " "1"" of type '" "P *""'"); + } + arg1 = reinterpret_cast< P * >(argp1); + delete arg1; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *P_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *obj; + if (!PyArg_ParseTuple(args,(char*)"O:swigregister", &obj)) return NULL; + SWIG_TypeNewClientData(SWIGTYPE_p_P, SWIG_NewClientData(obj)); + return SWIG_Py_Void(); +} + +SWIGINTERN int Swig_var_p1_set(PyObject *_val) { + { + void *argp = 0; + int res = SWIG_ConvertPtr(_val, &argp, SWIGTYPE_p_P, 0 | 0); + if (!SWIG_IsOK(res)) { + SWIG_exception_fail(SWIG_ArgError(res), "in variable '""p1""' of type '""P""'"); + } + if (!argp) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in variable '""p1""' of type '""P""'"); + } else { + P * temp; + temp = reinterpret_cast< P * >(argp); + p1 = *temp; + if (SWIG_IsNewObj(res)) delete temp; + } + } + return 0; +fail: + return 1; +} + + +SWIGINTERN PyObject *Swig_var_p1_get(void) { + PyObject *pyobj = 0; + + pyobj = SWIG_NewPointerObj(SWIG_as_voidptr(&p1), SWIGTYPE_p_P, 0 ); + return pyobj; +} + + +static PyMethodDef SwigMethods[] = { + { (char *)"SWIG_PyInstanceMethod_New", (PyCFunction)SWIG_PyInstanceMethod_New, METH_O, NULL}, + { (char *)"new_point", _wrap_new_point, METH_VARARGS, NULL}, + { (char *)"point_x__set", _wrap_point_x__set, METH_VARARGS, NULL}, + { (char *)"point_x__get", _wrap_point_x__get, METH_VARARGS, NULL}, + { (char *)"point_y__set", _wrap_point_y__set, METH_VARARGS, NULL}, + { (char *)"point_y__get", _wrap_point_y__get, METH_VARARGS, NULL}, + { (char *)"delete_point", _wrap_delete_point, METH_VARARGS, NULL}, + { (char *)"point_swigregister", point_swigregister, METH_VARARGS, NULL}, + { (char *)"P_z_set", _wrap_P_z_set, METH_VARARGS, NULL}, + { (char *)"P_z_get", _wrap_P_z_get, METH_VARARGS, NULL}, + { (char *)"P_w_set", _wrap_P_w_set, METH_VARARGS, NULL}, + { (char *)"P_w_get", _wrap_P_w_get, METH_VARARGS, NULL}, + { (char *)"P_p_set", _wrap_P_p_set, METH_VARARGS, NULL}, + { (char *)"P_p_get", _wrap_P_p_get, METH_VARARGS, NULL}, + { (char *)"new_P", _wrap_new_P, METH_VARARGS, NULL}, + { (char *)"delete_P", _wrap_delete_P, METH_VARARGS, NULL}, + { (char *)"P_swigregister", P_swigregister, METH_VARARGS, NULL}, + { NULL, NULL, 0, NULL } +}; + + +/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ + +static swig_type_info _swigt__p_P = {"_p_P", "P *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_point = {"_p_point", "point *", 0, 0, (void*)0, 0}; + +static swig_type_info *swig_type_initial[] = { + &_swigt__p_P, + &_swigt__p_char, + &_swigt__p_point, +}; + +static swig_cast_info _swigc__p_P[] = { {&_swigt__p_P, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_point[] = { {&_swigt__p_point, 0, 0, 0},{0, 0, 0, 0}}; + +static swig_cast_info *swig_cast_initial[] = { + _swigc__p_P, + _swigc__p_char, + _swigc__p_point, +}; + + +/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ + +static swig_const_info swig_const_table[] = { +{0, 0, 0, 0.0, 0, 0}}; + +#ifdef __cplusplus +} +#endif +/* ----------------------------------------------------------------------------- + * Type initialization: + * This problem is tough by the requirement that no dynamic + * memory is used. Also, since swig_type_info structures store pointers to + * swig_cast_info structures and swig_cast_info structures store pointers back + * to swig_type_info structures, we need some lookup code at initialization. + * The idea is that swig generates all the structures that are needed. + * The runtime then collects these partially filled structures. + * The SWIG_InitializeModule function takes these initial arrays out of + * swig_module, and does all the lookup, filling in the swig_module.types + * array with the correct data and linking the correct swig_cast_info + * structures together. + * + * The generated swig_type_info structures are assigned staticly to an initial + * array. We just loop through that array, and handle each type individually. + * First we lookup if this type has been already loaded, and if so, use the + * loaded structure instead of the generated one. Then we have to fill in the + * cast linked list. The cast data is initially stored in something like a + * two-dimensional array. Each row corresponds to a type (there are the same + * number of rows as there are in the swig_type_initial array). Each entry in + * a column is one of the swig_cast_info structures for that type. + * The cast_initial array is actually an array of arrays, because each row has + * a variable number of columns. So to actually build the cast linked list, + * we find the array of casts associated with the type, and loop through it + * adding the casts to the list. The one last trick we need to do is making + * sure the type pointer in the swig_cast_info struct is correct. + * + * First off, we lookup the cast->type name to see if it is already loaded. + * There are three cases to handle: + * 1) If the cast->type has already been loaded AND the type we are adding + * casting info to has not been loaded (it is in this module), THEN we + * replace the cast->type pointer with the type pointer that has already + * been loaded. + * 2) If BOTH types (the one we are adding casting info to, and the + * cast->type) are loaded, THEN the cast info has already been loaded by + * the previous module so we just ignore it. + * 3) Finally, if cast->type has not already been loaded, then we add that + * swig_cast_info to the linked list (because the cast->type) pointer will + * be correct. + * ----------------------------------------------------------------------------- */ + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* c-mode */ +#endif +#endif + +#if 0 +#define SWIGRUNTIME_DEBUG +#endif + + +SWIGRUNTIME void +SWIG_InitializeModule(void *clientdata) { + size_t i; + swig_module_info *module_head, *iter; + int found, init; + + clientdata = clientdata; + + /* check to see if the circular list has been setup, if not, set it up */ + if (swig_module.next==0) { + /* Initialize the swig_module */ + swig_module.type_initial = swig_type_initial; + swig_module.cast_initial = swig_cast_initial; + swig_module.next = &swig_module; + init = 1; + } else { + init = 0; + } + + /* Try and load any already created modules */ + module_head = SWIG_GetModule(clientdata); + if (!module_head) { + /* This is the first module loaded for this interpreter */ + /* so set the swig module into the interpreter */ + SWIG_SetModule(clientdata, &swig_module); + module_head = &swig_module; + } else { + /* the interpreter has loaded a SWIG module, but has it loaded this one? */ + found=0; + iter=module_head; + do { + if (iter==&swig_module) { + found=1; + break; + } + iter=iter->next; + } while (iter!= module_head); + + /* if the is found in the list, then all is done and we may leave */ + if (found) return; + /* otherwise we must add out module into the list */ + swig_module.next = module_head->next; + module_head->next = &swig_module; + } + + /* When multiple interpeters are used, a module could have already been initialized in + a different interpreter, but not yet have a pointer in this interpreter. + In this case, we do not want to continue adding types... everything should be + set up already */ + if (init == 0) return; + + /* Now work on filling in swig_module.types */ +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: size %d\n", swig_module.size); +#endif + for (i = 0; i < swig_module.size; ++i) { + swig_type_info *type = 0; + swig_type_info *ret; + swig_cast_info *cast; + +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); +#endif + + /* if there is another module already loaded */ + if (swig_module.next != &swig_module) { + type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); + } + if (type) { + /* Overwrite clientdata field */ +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: found type %s\n", type->name); +#endif + if (swig_module.type_initial[i]->clientdata) { + type->clientdata = swig_module.type_initial[i]->clientdata; +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); +#endif + } + } else { + type = swig_module.type_initial[i]; + } + + /* Insert casting types */ + cast = swig_module.cast_initial[i]; + while (cast->type) { + /* Don't need to add information already in the list */ + ret = 0; +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); +#endif + if (swig_module.next != &swig_module) { + ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); +#ifdef SWIGRUNTIME_DEBUG + if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); +#endif + } + if (ret) { + if (type == swig_module.type_initial[i]) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: skip old type %s\n", ret->name); +#endif + cast->type = ret; + ret = 0; + } else { + /* Check for casting already in the list */ + swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); +#ifdef SWIGRUNTIME_DEBUG + if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); +#endif + if (!ocast) ret = 0; + } + } + + if (!ret) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); +#endif + if (type->cast) { + type->cast->prev = cast; + cast->next = type->cast; + } + type->cast = cast; + } + cast++; + } + /* Set entry in modules->types array equal to the type */ + swig_module.types[i] = type; + } + swig_module.types[i] = 0; + +#ifdef SWIGRUNTIME_DEBUG + printf("**** SWIG_InitializeModule: Cast List ******\n"); + for (i = 0; i < swig_module.size; ++i) { + int j = 0; + swig_cast_info *cast = swig_module.cast_initial[i]; + printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); + while (cast->type) { + printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); + cast++; + ++j; + } + printf("---- Total casts: %d\n",j); + } + printf("**** SWIG_InitializeModule: Cast List ******\n"); +#endif +} + +/* 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_PropagateClientData(void) { + size_t i; + swig_cast_info *equiv; + static int init_run = 0; + + if (init_run) return; + init_run = 1; + + for (i = 0; i < swig_module.size; i++) { + if (swig_module.types[i]->clientdata) { + equiv = swig_module.types[i]->cast; + while (equiv) { + if (!equiv->converter) { + if (equiv->type && !equiv->type->clientdata) + SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); + } + equiv = equiv->next; + } + } + } +} + +#ifdef __cplusplus +#if 0 +{ + /* c-mode */ +#endif +} +#endif + + + +#ifdef __cplusplus +extern "C" { +#endif + + /* Python-specific SWIG API */ +#define SWIG_newvarlink() SWIG_Python_newvarlink() +#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) +#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) + + /* ----------------------------------------------------------------------------- + * global variable support code. + * ----------------------------------------------------------------------------- */ + + typedef struct swig_globalvar { + char *name; /* Name of global variable */ + PyObject *(*get_attr)(void); /* Return the current value */ + int (*set_attr)(PyObject *); /* Set the value */ + struct swig_globalvar *next; + } swig_globalvar; + + typedef struct swig_varlinkobject { + PyObject_HEAD + swig_globalvar *vars; + } swig_varlinkobject; + + SWIGINTERN PyObject * + swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { +#if PY_VERSION_HEX >= 0x03000000 + return PyUnicode_InternFromString(""); +#else + return PyString_FromString(""); +#endif + } + + SWIGINTERN PyObject * + swig_varlink_str(swig_varlinkobject *v) { +#if PY_VERSION_HEX >= 0x03000000 + PyObject *str = PyUnicode_InternFromString("("); + PyObject *tail; + PyObject *joined; + swig_globalvar *var; + for (var = v->vars; var; var=var->next) { + tail = PyUnicode_FromString(var->name); + joined = PyUnicode_Concat(str, tail); + Py_DecRef(str); + Py_DecRef(tail); + str = joined; + if (var->next) { + tail = PyUnicode_InternFromString(", "); + joined = PyUnicode_Concat(str, tail); + Py_DecRef(str); + Py_DecRef(tail); + str = joined; + } + } + tail = PyUnicode_InternFromString(")"); + joined = PyUnicode_Concat(str, tail); + Py_DecRef(str); + Py_DecRef(tail); + str = joined; +#else + PyObject *str = PyString_FromString("("); + swig_globalvar *var; + for (var = v->vars; var; var=var->next) { + PyString_ConcatAndDel(&str,PyString_FromString(var->name)); + if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); + } + PyString_ConcatAndDel(&str,PyString_FromString(")")); +#endif + return str; + } + + SWIGINTERN int + swig_varlink_print(swig_varlinkobject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) { + char *tmp; + PyObject *str = swig_varlink_str(v); + fprintf(fp,"Swig global variables "); + fprintf(fp,"%s\n", tmp = SWIG_Python_str_AsChar(str)); + SWIG_Python_str_DelForPy3(tmp); + Py_DECREF(str); + return 0; + } + + SWIGINTERN void + swig_varlink_dealloc(swig_varlinkobject *v) { + swig_globalvar *var = v->vars; + while (var) { + swig_globalvar *n = var->next; + free(var->name); + free(var); + var = n; + } + } + + SWIGINTERN PyObject * + swig_varlink_getattr(swig_varlinkobject *v, char *n) { + PyObject *res = NULL; + swig_globalvar *var = v->vars; + while (var) { + if (strcmp(var->name,n) == 0) { + res = (*var->get_attr)(); + break; + } + var = var->next; + } + if (res == NULL && !PyErr_Occurred()) { + PyErr_SetString(PyExc_NameError,"Unknown C global variable"); + } + return res; + } + + SWIGINTERN int + swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { + int res = 1; + swig_globalvar *var = v->vars; + while (var) { + if (strcmp(var->name,n) == 0) { + res = (*var->set_attr)(p); + break; + } + var = var->next; + } + if (res == 1 && !PyErr_Occurred()) { + PyErr_SetString(PyExc_NameError,"Unknown C global variable"); + } + return res; + } + + SWIGINTERN PyTypeObject* + swig_varlink_type(void) { + static char varlink__doc__[] = "Swig var link object"; + static PyTypeObject varlink_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp + = { + /* PyObject header changed in Python 3 */ +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /* Number of items in variable part (ob_size) */ +#endif + (char *)"swigvarlink", /* Type name (tp_name) */ + sizeof(swig_varlinkobject), /* Basic size (tp_basicsize) */ + 0, /* Itemsize (tp_itemsize) */ + (destructor) swig_varlink_dealloc, /* Deallocator (tp_dealloc) */ + (printfunc) swig_varlink_print, /* Print (tp_print) */ + (getattrfunc) swig_varlink_getattr, /* get attr (tp_getattr) */ + (setattrfunc) swig_varlink_setattr, /* Set attr (tp_setattr) */ + 0, /* tp_compare */ + (reprfunc) swig_varlink_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + (reprfunc) swig_varlink_str, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + 0, /* tp_flags */ + varlink__doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ +#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 + }; + varlink_type = tmp; + /* for Python 3 we already assigned ob_type in PyVarObject_HEAD_INIT() */ +#if PY_VERSION_HEX < 0x03000000 + varlink_type.ob_type = &PyType_Type; +#endif + type_init = 1; + } + return &varlink_type; + } + + /* Create a variable linking object for use later */ + SWIGINTERN PyObject * + SWIG_Python_newvarlink(void) { + swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type()); + if (result) { + result->vars = 0; + } + return ((PyObject*) result); + } + + SWIGINTERN void + SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { + swig_varlinkobject *v = (swig_varlinkobject *) p; + swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); + if (gv) { + size_t size = strlen(name)+1; + gv->name = (char *)malloc(size); + if (gv->name) { + strncpy(gv->name,name,size); + gv->get_attr = get_attr; + gv->set_attr = set_attr; + gv->next = v->vars; + } + } + v->vars = gv; + } + + SWIGINTERN PyObject * + SWIG_globals(void) { + static PyObject *_SWIG_globals = 0; + if (!_SWIG_globals) _SWIG_globals = SWIG_newvarlink(); + return _SWIG_globals; + } + + /* ----------------------------------------------------------------------------- + * constants/methods manipulation + * ----------------------------------------------------------------------------- */ + + /* Install Constants */ + SWIGINTERN void + SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { + PyObject *obj = 0; + size_t i; + for (i = 0; constants[i].type; ++i) { + switch(constants[i].type) { + case SWIG_PY_POINTER: + obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); + break; + case SWIG_PY_BINARY: + obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); + break; + default: + obj = 0; + break; + } + if (obj) { + PyDict_SetItemString(d, constants[i].name, obj); + Py_DECREF(obj); + } + } + } + + /* -----------------------------------------------------------------------------*/ + /* Fix SwigMethods to carry the callback ptrs when needed */ + /* -----------------------------------------------------------------------------*/ + + SWIGINTERN void + SWIG_Python_FixMethods(PyMethodDef *methods, + swig_const_info *const_table, + swig_type_info **types, + swig_type_info **types_initial) { + size_t i; + for (i = 0; methods[i].ml_name; ++i) { + const char *c = methods[i].ml_doc; + if (c && (c = strstr(c, "swig_ptr: "))) { + int j; + swig_const_info *ci = 0; + const char *name = c + 10; + for (j = 0; const_table[j].type; ++j) { + if (strncmp(const_table[j].name, name, + strlen(const_table[j].name)) == 0) { + ci = &(const_table[j]); + break; + } + } + if (ci) { + void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; + if (ptr) { + size_t shift = (ci->ptype) - types; + swig_type_info *ty = types_initial[shift]; + size_t ldoc = (c - methods[i].ml_doc); + size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; + char *ndoc = (char*)malloc(ldoc + lptr + 10); + if (ndoc) { + char *buff = ndoc; + strncpy(buff, methods[i].ml_doc, ldoc); + buff += ldoc; + strncpy(buff, "swig_ptr: ", 10); + buff += 10; + SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); + methods[i].ml_doc = ndoc; + } + } + } + } + } + } + +#ifdef __cplusplus +} +#endif + +/* -----------------------------------------------------------------------------* + * Partial Init method + * -----------------------------------------------------------------------------*/ + +#ifdef __cplusplus +extern "C" +#endif + +SWIGEXPORT +#if PY_VERSION_HEX >= 0x03000000 +PyObject* +#else +void +#endif +SWIG_init(void) { + PyObject *m, *d; +#if PY_VERSION_HEX >= 0x03000000 + static struct PyModuleDef SWIG_module = { + PyModuleDef_HEAD_INIT, + (char *) SWIG_name, + NULL, + -1, + SwigMethods, + NULL, + NULL, + NULL, + NULL + }; +#endif + + /* Fix SwigMethods to carry the callback ptrs when needed */ + SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); + +#if PY_VERSION_HEX >= 0x03000000 + m = PyModule_Create(&SWIG_module); +#else + m = Py_InitModule((char *) SWIG_name, SwigMethods); +#endif + d = PyModule_GetDict(m); + + SWIG_InitializeModule(0); + SWIG_InstallConstants(d,swig_const_table); + + + PyDict_SetItemString(d,(char*)"cvar", SWIG_globals()); + SWIG_addvarlink(SWIG_globals(),(char*)"p1",Swig_var_p1_get, Swig_var_p1_set); +#if PY_VERSION_HEX >= 0x03000000 + return m; +#else + return; +#endif +} + From dd18423e768804618967463299e08eedb00868f4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 25 Sep 2012 19:25:14 +0000 Subject: [PATCH 0209/1160] Update on C++11 user-defined literal status git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13850 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Cpp0x.html | 39 +++++++++++++++++-- .../test-suite/cpp0x_userdefined_literals.i | 18 +++++---- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index a93df57ca..d150cbddf 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -516,18 +516,49 @@ inside the string due to SWIG's C++ preprocessor.

    7.2.19 User-defined literals

    -

    SWIG correctly parses the new operator""_mysuffix() functions.

    +

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

    +

    +Some examples are the raw literal: +

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

    +numeric cooked literals: +

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

    +and cooked string literals: +

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

    The %rename currently doesn't parse the double quotes. Please -rename the functions in the code using the #define preprocessor directive.

    +

    +Note that the %rename directive currently does not parse the double quotes, so these can't be easily accessed from +target languages. +

    + +

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

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

    7.2.20 Thread-local storage

    diff --git a/Examples/test-suite/cpp0x_userdefined_literals.i b/Examples/test-suite/cpp0x_userdefined_literals.i index 6604a4293..b21ff762d 100644 --- a/Examples/test-suite/cpp0x_userdefined_literals.i +++ b/Examples/test-suite/cpp0x_userdefined_literals.i @@ -1,5 +1,5 @@ /* This testcase checks whether SWIG correctly parses the user-defined literals - for the string introduced in C++0x. */ + introduced in C++0x. */ %module cpp0x_userdefined_literals %inline %{ @@ -7,18 +7,20 @@ struct OutputType { int val; - - OutputType(int v) { v=val; } + OutputType(int v) : val(v) {} }; -/* Note: GCC doesn't support user-defined literals yet! */ -struct TT { -OutputType operator "" (const char * string_values, size_t num_chars) { return OutputType(100); } +// Raw literal +OutputType operator "" _myRawLiteral(const char * value) { return OutputType(10); } + +// Cooked numeric literals +OutputType operator "" _mySuffixIntegral(unsigned long long) { return OutputType(20); } +OutputType operator "" _mySuffixFloat(long double) { return OutputType(30); } + +// Cooked string literals OutputType operator "" _mySuffix1(const char * string_values, size_t num_chars) { return OutputType(100); } OutputType operator "" _mySuffix2(const wchar_t * string_values, size_t num_chars) { return OutputType(200); } OutputType operator "" _mySuffix3(const char16_t * string_values, size_t num_chars) { return OutputType(300); } OutputType operator "" _mySuffix4(const char32_t * string_values, size_t num_chars) { return OutputType(400); } -OutputType operator "" _mySuffix5(int value) /* cooked version - ie. atoi() of string */ { return OutputType(500); } -}; %} From 070bf3cc9ea8cbce5abcb142b2e4ba61d66be52e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 25 Sep 2012 19:29:13 +0000 Subject: [PATCH 0210/1160] gcc-4.7 now supports alias templates git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13851 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 1dfe35f38..0a637dcd1 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -447,6 +447,7 @@ CPP0X_TEST_CASES = \ cpp0x_strongly_typed_enumerations \ cpp0x_template_double_brackets \ cpp0x_template_explicit \ + cpp0x_template_typedefs \ cpp0x_uniform_initialization \ cpp0x_unrestricted_unions \ cpp0x_userdefined_literals \ @@ -455,7 +456,6 @@ CPP0X_TEST_CASES = \ # cpp0x_constructors \ # not supported by any compiler yet # cpp0x_hash_tables \ # not fully implemented yet # cpp0x_lambda_functions \ # not supported by GCC or MSVC yet -# cpp0x_template_typedefs \ # not supported by any compiler yet (now in gcc-4.7) # cpp0x_thread_local \ # not supported by any compiler yet # Broken C++0x test cases. From 4db087d81fc287bcc41f9455b31d9ba44e704352 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 25 Sep 2012 20:22:15 +0000 Subject: [PATCH 0211/1160] Delegating constructors and inheriting constructors clarification and split of tests git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13852 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Cpp0x.html | 28 +++++++++++++++-- Examples/test-suite/common.mk | 3 +- Examples/test-suite/cpp0x_constructors.i | 30 ------------------- .../cpp0x_delegating_constructors.i | 18 +++++++++++ .../cpp0x_inheriting_constructors.i | 18 +++++++++++ 5 files changed, 63 insertions(+), 34 deletions(-) delete mode 100644 Examples/test-suite/cpp0x_constructors.i create mode 100644 Examples/test-suite/cpp0x_delegating_constructors.i create mode 100644 Examples/test-suite/cpp0x_inheriting_constructors.i diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index d150cbddf..fa18b67f1 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -263,9 +263,31 @@ auto square(float a, float b) -> decltype(a);

    7.2.10 Object construction improvement

    -

    SWIG correctly parses and includes the external functions -(constructor delegation and constructor inheritance) into the class -using the using keyword.

    +

    +SWIG is able to handle constructor delegation, such as: +

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

    +Constructor inheritance is parsed correctly, but the additional constructors are not currently added to the derived proxy class in the target language. Example is shown below: + +

     class BaseClass {
    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
    index 0a637dcd1..0b5e368f9 100644
    --- a/Examples/test-suite/common.mk
    +++ b/Examples/test-suite/common.mk
    @@ -434,6 +434,7 @@ CPP0X_TEST_CASES = \
     	cpp0x_constexpr \
     	cpp0x_decltype \
     	cpp0x_default_delete \
    +	cpp0x_delegating_constructors \
     	cpp0x_explicit_conversion_operators \
     	cpp0x_function_objects \
     	cpp0x_initializer_list \
    @@ -453,7 +454,7 @@ CPP0X_TEST_CASES = \
     	cpp0x_userdefined_literals \
     	cpp0x_variadic_templates
     
    -#	cpp0x_constructors \          # not supported by any compiler yet
    +#	cpp0x_inheriting_constructors \ # not supported by gcc-4.7
     #	cpp0x_hash_tables \           # not fully implemented yet
     #	cpp0x_lambda_functions \      # not supported by GCC or MSVC yet
     #	cpp0x_thread_local \          # not supported by any compiler yet
    diff --git a/Examples/test-suite/cpp0x_constructors.i b/Examples/test-suite/cpp0x_constructors.i
    deleted file mode 100644
    index 2077efe0c..000000000
    --- a/Examples/test-suite/cpp0x_constructors.i
    +++ /dev/null
    @@ -1,30 +0,0 @@
    -/* This test checks whether SWIG correctly parses the new delegating
    -   constructors and constructor inheritance.
    -*/
    -%module cpp0x_constructors
    -
    -%inline %{
    -class BaseClass {
    -private:
    -  int _val;
    -public:
    -  BaseClass(int iValue) { _val = iValue; }
    -};
    -
    -class DerivedClass: public BaseClass {
    -public:
    -  using BaseClass::BaseClass; // Adds DerivedClass(int) constructor
    -};
    -
    -class A {
    -public:
    -  int a;
    -  int b;
    -  int c;
    -
    -  A() : A( 10 ) {}
    -  A(int aa) : A(aa, 20) {}
    -  A(int aa, int bb) : A(aa, bb, 30) {}
    -  A(int aa, int bb, int cc) { a=aa; b=bb; c=cc; }
    -};
    -%}
    diff --git a/Examples/test-suite/cpp0x_delegating_constructors.i b/Examples/test-suite/cpp0x_delegating_constructors.i
    new file mode 100644
    index 000000000..679dce242
    --- /dev/null
    +++ b/Examples/test-suite/cpp0x_delegating_constructors.i
    @@ -0,0 +1,18 @@
    +/* This test checks whether SWIG correctly parses the new delegating
    +   constructors.
    +*/
    +%module cpp0x_delegating_constructors
    +
    +%inline %{
    +class A {
    +public:
    +  int a;
    +  int b;
    +  int c;
    +
    +  A() : A( 10 ) {}
    +  A(int aa) : A(aa, 20) {}
    +  A(int aa, int bb) : A(aa, bb, 30) {}
    +  A(int aa, int bb, int cc) { a=aa; b=bb; c=cc; }
    +};
    +%}
    diff --git a/Examples/test-suite/cpp0x_inheriting_constructors.i b/Examples/test-suite/cpp0x_inheriting_constructors.i
    new file mode 100644
    index 000000000..452598360
    --- /dev/null
    +++ b/Examples/test-suite/cpp0x_inheriting_constructors.i
    @@ -0,0 +1,18 @@
    +/* This test checks whether SWIG correctly parses the new constructor
    +   inheritance.
    +*/
    +%module cpp0x_inheriting_constructors
    +
    +%inline %{
    +class BaseClass {
    +private:
    +  int _val;
    +public:
    +  BaseClass(int iValue) { _val = iValue; }
    +};
    +
    +class DerivedClass: public BaseClass {
    +public:
    +  using BaseClass::BaseClass; // Adds DerivedClass(int) constructor
    +};
    +%}
    
    From 8af91dcc754ae002e815d20a5acc80452a6e9500 Mon Sep 17 00:00:00 2001
    From: Ian Lance Taylor 
    Date: Mon, 1 Oct 2012 17:18:27 +0000
    Subject: [PATCH 0212/1160] If the user explicitly directs that the Go type be
     a slice, don't use a pointer to a slice even if the actual type is reference.
      from John Admanski.
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13853 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Source/Modules/go.cxx | 4 ++++
     1 file changed, 4 insertions(+)
    
    diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx
    index 91f706ad3..6ec106df4 100644
    --- a/Source/Modules/go.cxx
    +++ b/Source/Modules/go.cxx
    @@ -4638,7 +4638,11 @@ private:
           Append(ret, name);
           return ret;
         } else if (is_slice) {
    +      // Slices are always passed as a _goslice_, whether or not references
    +      // are involved.
           ret = NewString("_goslice_ ");
    +      Append(ret, name);
    +      return ret;
         } else if (is_function || is_member) {
           ret = NewString("void *");
           Append(ret, name);
    
    From e68d8024f5d02532f3519a9651d5eec3db653c59 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Mon, 1 Oct 2012 18:53:12 +0000
    Subject: [PATCH 0213/1160] Lambda expressions: parse exception specification
     in lambda functions. Fix lambda testcase for gcc-4.7.
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13854 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Examples/test-suite/cpp0x_lambda_functions.i | 29 ++++++++++++++++++++
     Source/CParse/parser.y                       |  5 ++--
     2 files changed, 32 insertions(+), 2 deletions(-)
    
    diff --git a/Examples/test-suite/cpp0x_lambda_functions.i b/Examples/test-suite/cpp0x_lambda_functions.i
    index 56235e9a6..0f10af471 100644
    --- a/Examples/test-suite/cpp0x_lambda_functions.i
    +++ b/Examples/test-suite/cpp0x_lambda_functions.i
    @@ -19,7 +19,23 @@ auto lambda2 = [](int x, int y) { return x+y; };
     auto lambda3 = [&](int x, int y) { return x+y; };
     auto lambda4 = [=](int x, int y) { return x+y; };
     int thing = 0;
    +#ifdef SWIG
    +// Not strictly correct as captured variables should have non-automatic storage duration, ie shouldn't capture globals. gcc-4.7 warns about this, but we check that SWIG can parse this anyway.
     auto lambda5 = [=,&thing]() { return thing;};
    +#else
    +auto lambda5 = [=]() { return thing;};
    +#endif
    +
    +void fn() {
    +  int stuff = 0;
    +  auto lambdaxxxx = [=,&stuff]() { return thing;};
    +}
    +auto lambda6 = [] (int a, int b) mutable { return a + b; };
    +auto lambda7 = [] (int x, int y) -> int { return x+y; };
    +auto lambda8 = [] (int x, int y) throw() -> int { return x+y; };
    +auto lambda9 = [] (int x, int y) mutable throw() -> int { return x+y; };
    +auto lambda10 = [] (int x, int y) throw(int) { return x+y; };
    +auto lambda11 = [] (int x, int y) mutable throw(int) { return x+y; };
     
     int runLambda1() {
       return lambda1(5,6);
    @@ -49,3 +65,16 @@ int runLambdaInline() {
     }
     %}
     
    +%{
    +// TODO
    +struct LambdaStruct {
    +  static constexpr auto lambda_struct1 = [=]() { return thing;};
    +};
    +auto lambda100 = [] { return thing;};
    +int lambda101 = [] (int a, int b) { return a + b; }(1, 2);
    +int lambda102 = [] (int a, int b) mutable { return a + b; }(1, 2);
    +auto lambda103 = [] () throw () { /* does not throw */ };
    +auto lambda104 = [] () mutable throw () { /* does not throw */ };
    +void lambda_init(int = ([=]{ return 0; })());
    +%}
    +
    diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
    index f601aab9f..04b69fbc6 100644
    --- a/Source/CParse/parser.y
    +++ b/Source/CParse/parser.y
    @@ -3295,8 +3295,9 @@ cpp_alternate_rettype : primitive_type { $$ = $1; }
        OR
        auto myFunc = [](int x, int y) { return x+y; }
     */
    -c_lambda_decl  : c_lambda_decl_front LPAREN parms RPAREN LBRACE { skip_balanced('{','}'); } SEMI { $$ = 0; }
    -               | c_lambda_decl_front LPAREN parms RPAREN ARROW type LBRACE { skip_balanced('{','}'); } SEMI { $$ = 0; }
    +c_lambda_decl  : c_lambda_decl_front LPAREN parms RPAREN cpp_const LBRACE { skip_balanced('{','}'); } SEMI { $$ = 0; }
    +               | c_lambda_decl_front LPAREN parms RPAREN cpp_const ARROW type LBRACE { skip_balanced('{','}'); } SEMI { $$ = 0; }
    +               ;
     
     c_lambda_decl_front : storage_class AUTO idcolon EQUAL LBRACKET { skip_balanced('[',']'); $$ = 0; }
     
    
    From 5e30ec58e83c95c48879fe21c63f7dfffe2b4edd Mon Sep 17 00:00:00 2001
    From: Ian Lance Taylor 
    Date: Tue, 2 Oct 2012 14:53:13 +0000
    Subject: [PATCH 0214/1160] Adjust typemaps.i for change in handling of
     reference to slice.
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13856 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Lib/go/typemaps.i | 32 ++++----------------------------
     1 file changed, 4 insertions(+), 28 deletions(-)
    
    diff --git a/Lib/go/typemaps.i b/Lib/go/typemaps.i
    index 89b29fb96..c339fb37e 100644
    --- a/Lib/go/typemaps.i
    +++ b/Lib/go/typemaps.i
    @@ -62,12 +62,9 @@ char * typemaps instead:
     %define INPUT_TYPEMAP(TYPE, GOTYPE)
     %typemap(gotype) TYPE *INPUT, TYPE &INPUT "GOTYPE"
     
    -%typemap(in) TYPE *INPUT
    + %typemap(in) TYPE *INPUT, TYPE &INPUT
     %{ $1 = ($1_ltype)&$input; %}
     
    -%typemap(in) TYPE &INPUT
    -%{ $1 = ($1_ltype)$input; %}
    -
     %typemap(out) TYPE *INPUT, TYPE &INPUT ""
     
     %typemap(freearg) TYPE *INPUT, TYPE &INPUT ""
    @@ -160,7 +157,7 @@ char * typemaps instead:
     %define OUTPUT_TYPEMAP(TYPE, GOTYPE)
     %typemap(gotype) TYPE *OUTPUT, TYPE &OUTPUT %{[]GOTYPE%}
     
    -%typemap(in) TYPE *OUTPUT($*1_ltype temp)
    +%typemap(in) TYPE *OUTPUT($*1_ltype temp), TYPE &OUTPUT($*1_ltype temp)
     {
       if ($input.len == 0) {
         _swig_gopanic("array must contain at least 1 element");
    @@ -168,30 +165,16 @@ char * typemaps instead:
       $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(out) TYPE *OUTPUT, TYPE &OUTPUT ""
     
     %typemap(freearg) TYPE *OUTPUT, TYPE &OUTPUT ""
     
    -%typemap(argout) TYPE *OUTPUT
    +%typemap(argout) TYPE *OUTPUT, TYPE &OUTPUT
     {
       TYPE* a = (TYPE *) $input.array;
       a[0] = temp$argnum;
     }
     
    -%typemap(argout) TYPE &OUTPUT 
    -{
    -  TYPE* a = (TYPE *) $input->array;
    -  a[0] = temp$argnum;
    -}
    -
     %enddef
     
     OUTPUT_TYPEMAP(bool, bool);
    @@ -276,20 +259,13 @@ char * typemaps instead:
     %define INOUT_TYPEMAP(TYPE, GOTYPE)
     %typemap(gotype) TYPE *INOUT, TYPE &INOUT %{[]GOTYPE%}
     
    -%typemap(in) TYPE *INOUT {
    +%typemap(in) TYPE *INOUT, 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(out) TYPE *INOUT, TYPE &INOUT ""
     
     %typemap(freearg) TYPE *INOUT, TYPE &INOUT ""
    
    From fad2bd5e1e1f6723d66f61275a51b74c8fcd9eb2 Mon Sep 17 00:00:00 2001
    From: Ian Lance Taylor 
    Date: Tue, 2 Oct 2012 14:54:28 +0000
    Subject: [PATCH 0215/1160] Ignore templatized methods in base classes. From
     Nigel Choi. Fixes issue 3573098.
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13857 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Source/Modules/go.cxx | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx
    index 6ec106df4..5be846171 100644
    --- a/Source/Modules/go.cxx
    +++ b/Source/Modules/go.cxx
    @@ -1958,7 +1958,7 @@ private:
           }
     
           String *type = Getattr(ni, "nodeType");
    -      if (Strcmp(type, "constructor") == 0 || Strcmp(type, "destructor") == 0 || Strcmp(type, "enum") == 0 || Strcmp(type, "using") == 0 || Strcmp(type, "classforward") == 0) {
    +      if (Strcmp(type, "constructor") == 0 || Strcmp(type, "destructor") == 0 || Strcmp(type, "enum") == 0 || Strcmp(type, "using") == 0 || Strcmp(type, "classforward") == 0 || Strcmp(type, "template") == 0) {
     	continue;
           }
           String *storage = Getattr(ni, "storage");
    
    From 7ca8f025ad6d18ffc4dc63f6b5c980b25915137a Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Tue, 2 Oct 2012 21:12:36 +0000
    Subject: [PATCH 0216/1160] Add in support for initialising auto variables from
     lambda expressions
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13858 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Examples/test-suite/cpp0x_lambda_functions.i |  8 ++--
     Source/CParse/parser.y                       | 47 +++++++++++++++-----
     2 files changed, 41 insertions(+), 14 deletions(-)
    
    diff --git a/Examples/test-suite/cpp0x_lambda_functions.i b/Examples/test-suite/cpp0x_lambda_functions.i
    index 0f10af471..f0e863ad0 100644
    --- a/Examples/test-suite/cpp0x_lambda_functions.i
    +++ b/Examples/test-suite/cpp0x_lambda_functions.i
    @@ -36,6 +36,10 @@ auto lambda8 = [] (int x, int y) throw() -> int { return x+y; };
     auto lambda9 = [] (int x, int y) mutable throw() -> int { return x+y; };
     auto lambda10 = [] (int x, int y) throw(int) { return x+y; };
     auto lambda11 = [] (int x, int y) mutable throw(int) { return x+y; };
    +auto lambda12 = [] (int a, int b) { return a + b; }(1, 2);
    +auto lambda13 = [] (int a, int b) mutable { return a + b; }(1, 2);
    +auto lambda14 = [] () throw () {};
    +auto lambda15 = [] () mutable throw () {};
     
     int runLambda1() {
       return lambda1(5,6);
    @@ -70,11 +74,9 @@ int runLambdaInline() {
     struct LambdaStruct {
       static constexpr auto lambda_struct1 = [=]() { return thing;};
     };
    +int(*lambda101notauto)(int, int) = [] (int a, int b) { return a + b; };
     auto lambda100 = [] { return thing;};
    -int lambda101 = [] (int a, int b) { return a + b; }(1, 2);
     int lambda102 = [] (int a, int b) mutable { return a + b; }(1, 2);
    -auto lambda103 = [] () throw () { /* does not throw */ };
    -auto lambda104 = [] () mutable throw () { /* does not throw */ };
     void lambda_init(int = ([=]{ return 0; })());
     %}
     
    diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
    index 04b69fbc6..5681fa721 100644
    --- a/Source/CParse/parser.y
    +++ b/Source/CParse/parser.y
    @@ -1690,7 +1690,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) {
     %type      types_directive template_directive warn_directive ;
     
     /* C declarations */
    -%type      c_declaration c_decl c_decl_tail c_enum_key c_enum_inherit c_enum_decl c_enum_forward_decl c_constructor_decl c_lambda_decl c_lambda_decl_front ;
    +%type      c_declaration c_decl c_decl_tail c_enum_key c_enum_inherit c_enum_decl c_enum_forward_decl c_constructor_decl;
     %type      enumlist edecl;
     
     /* C++ declarations */
    @@ -1698,7 +1698,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) {
     %type      cpp_members cpp_member;
     %type      cpp_constructor_decl cpp_destructor_decl cpp_protection_decl cpp_conversion_operator cpp_static_assert;
     %type      cpp_swig_directive cpp_temp_possible cpp_nested cpp_opt_declarators ;
    -%type      cpp_using_decl cpp_namespace_decl cpp_catch_decl ;
    +%type      cpp_using_decl cpp_namespace_decl cpp_catch_decl cpp_lambda_decl;
     %type      kwargs options;
     
     /* Misc */
    @@ -1735,6 +1735,8 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) {
     %type     type_specifier primitive_type_list ;
     %type      fname stringtype;
     %type      featattr;
    +%type      lambda_introducer lambda_body;
    +%type        lambda_tail;
     
     %%
     
    @@ -3098,7 +3100,7 @@ c_declaration   : c_decl {
     		    appendChild($$,firstChild($5));
     		  }
                     }
    -                | c_lambda_decl { Swig_warning(WARN_CPP11_LAMBDA, cparse_file, cparse_line,"Lambda expressions and closures are not fully supported yet.\n"); $$ = $1; }
    +                | cpp_lambda_decl { Swig_warning(WARN_CPP11_LAMBDA, cparse_file, cparse_line,"Lambda expressions and closures are not fully supported yet.\n"); $$ = $1; }
                     | USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_CPP11_ALIAS_DECLARATION, cparse_file, cparse_line,"The 'using' keyword in type aliasing is not fully supported yet.\n"); $$ = 0; }
                     | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_CPP11_ALIAS_TEMPLATE, cparse_file, cparse_line,"The 'using' keyword in template aliasing is not fully supported yet.\n"); $$ = 0; }
                     ;
    @@ -3290,17 +3292,40 @@ cpp_alternate_rettype : primitive_type { $$ = $1; }
                   | decltype { $$ = $1; }
                   ;
     
    -/* Lambda function syntax introduced in C++0x.
    -   auto myFunc = [](int x, int y) -> int { return x+y; }
    -   OR
    -   auto myFunc = [](int x, int y) { return x+y; }
    +/* 
    +  Lambda functions and expressions, such as:
    +  auto myFunc = [](int x, int y) -> int { return x+y; };
    +  auto myFunc = [](int x, int y) { return x+y; };
    +  auto myFunc = [](int x, int y) { return x+y; }(1, 2);
     */
    -c_lambda_decl  : c_lambda_decl_front LPAREN parms RPAREN cpp_const LBRACE { skip_balanced('{','}'); } SEMI { $$ = 0; }
    -               | c_lambda_decl_front LPAREN parms RPAREN cpp_const ARROW type LBRACE { skip_balanced('{','}'); } SEMI { $$ = 0; }
    -               ;
    +cpp_lambda_decl : storage_class AUTO idcolon EQUAL lambda_introducer LPAREN parms RPAREN cpp_const lambda_body lambda_tail {
    +		  $$ = 0;
    +	        }
    +                | storage_class AUTO idcolon EQUAL lambda_introducer LPAREN parms RPAREN cpp_const ARROW type lambda_body lambda_tail {
    +		  $$ = 0;
    +		}
    +                ;
     
    -c_lambda_decl_front : storage_class AUTO idcolon EQUAL LBRACKET { skip_balanced('[',']'); $$ = 0; }
    +lambda_introducer : LBRACKET {
    +		  skip_balanced('[',']');
    +		  $$ = 0;
    +	        }
    +		;
     
    +lambda_body : LBRACE {
    +		  skip_balanced('{','}');
    +		  $$ = 0;
    +		}
    +
    +lambda_tail :	SEMI {
    +		  $$ = 0;
    +		}
    +		| LPAREN {
    +		  skip_balanced('(',')');
    +		} SEMI {
    +		  $$ = 0;
    +		}
    +		;
     
     /* ------------------------------------------------------------
        enum
    
    From 35458b4a5dc73a340961a378c62e8d98a2f90321 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Thu, 4 Oct 2012 06:01:38 +0000
    Subject: [PATCH 0217/1160] More lambda support - for optional lambda
     declarators
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13859 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Doc/Manual/Cpp0x.html                        | 17 ++++++++++++++++-
     Examples/test-suite/cpp0x_lambda_functions.i | 11 ++++++-----
     Source/CParse/parser.y                       | 17 +++++++++++------
     3 files changed, 33 insertions(+), 12 deletions(-)
    
    diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html
    index fa18b67f1..d6dce1d18 100644
    --- a/Doc/Manual/Cpp0x.html
    +++ b/Doc/Manual/Cpp0x.html
    @@ -217,14 +217,29 @@ ignores it.

    7.2.8 Lambda functions and expressions

    -

    SWIG correctly parses the Lambda functions syntax. For example:

    +

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

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

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

    +

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

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

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

    +

    7.2.9 Alternate function syntax

    diff --git a/Examples/test-suite/cpp0x_lambda_functions.i b/Examples/test-suite/cpp0x_lambda_functions.i index f0e863ad0..fabc89079 100644 --- a/Examples/test-suite/cpp0x_lambda_functions.i +++ b/Examples/test-suite/cpp0x_lambda_functions.i @@ -21,14 +21,14 @@ auto lambda4 = [=](int x, int y) { return x+y; }; int thing = 0; #ifdef SWIG // Not strictly correct as captured variables should have non-automatic storage duration, ie shouldn't capture globals. gcc-4.7 warns about this, but we check that SWIG can parse this anyway. -auto lambda5 = [=,&thing]() { return thing;}; +auto lambda5 = [=,&thing]() { return thing; }; #else -auto lambda5 = [=]() { return thing;}; +auto lambda5 = [=]() { return thing; }; #endif void fn() { int stuff = 0; - auto lambdaxxxx = [=,&stuff]() { return thing;}; + auto lambdaxxxx = [=,&stuff]() { return thing; }; } auto lambda6 = [] (int a, int b) mutable { return a + b; }; auto lambda7 = [] (int x, int y) -> int { return x+y; }; @@ -40,6 +40,8 @@ auto lambda12 = [] (int a, int b) { return a + b; }(1, 2); auto lambda13 = [] (int a, int b) mutable { return a + b; }(1, 2); auto lambda14 = [] () throw () {}; auto lambda15 = [] () mutable throw () {}; +auto lambda16 = [] { return thing; }; +auto lambda17 = [] { return thing; }(); int runLambda1() { return lambda1(5,6); @@ -72,10 +74,9 @@ int runLambdaInline() { %{ // TODO struct LambdaStruct { - static constexpr auto lambda_struct1 = [=]() { return thing;}; + static constexpr auto lambda_struct1 = [=]() { return thing; }; }; int(*lambda101notauto)(int, int) = [] (int a, int b) { return a + b; }; -auto lambda100 = [] { return thing;}; int lambda102 = [] (int a, int b) mutable { return a + b; }(1, 2); void lambda_init(int = ([=]{ return 0; })()); %} diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 5681fa721..d91b7adce 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3292,18 +3292,23 @@ cpp_alternate_rettype : primitive_type { $$ = $1; } | decltype { $$ = $1; } ; -/* - Lambda functions and expressions, such as: - auto myFunc = [](int x, int y) -> int { return x+y; }; - auto myFunc = [](int x, int y) { return x+y; }; - auto myFunc = [](int x, int y) { return x+y; }(1, 2); -*/ +/* ------------------------------------------------------------ + Lambda functions and expressions, such as: + auto myFunc = [] { return something; }; + auto myFunc = [](int x, int y) { return x+y; }; + auto myFunc = [](int x, int y) -> int { return x+y; }; + auto myFunc = [](int x, int y) throw() -> int { return x+y; }; + auto six = [](int x, int y) { return x+y; }(4, 2); + ------------------------------------------------------------ */ cpp_lambda_decl : storage_class AUTO idcolon EQUAL lambda_introducer LPAREN parms RPAREN cpp_const lambda_body lambda_tail { $$ = 0; } | storage_class AUTO idcolon EQUAL lambda_introducer LPAREN parms RPAREN cpp_const ARROW type lambda_body lambda_tail { $$ = 0; } + | storage_class AUTO idcolon EQUAL lambda_introducer lambda_body lambda_tail { + $$ = 0; + } ; lambda_introducer : LBRACKET { From 5ada4e35d133d62e7f65734a81274daa56866c9f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 4 Oct 2012 06:05:28 +0000 Subject: [PATCH 0218/1160] One more lambda test using constexpr git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13860 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/cpp0x_lambda_functions.i | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/test-suite/cpp0x_lambda_functions.i b/Examples/test-suite/cpp0x_lambda_functions.i index fabc89079..0f11f9e63 100644 --- a/Examples/test-suite/cpp0x_lambda_functions.i +++ b/Examples/test-suite/cpp0x_lambda_functions.i @@ -42,6 +42,7 @@ auto lambda14 = [] () throw () {}; auto lambda15 = [] () mutable throw () {}; auto lambda16 = [] { return thing; }; auto lambda17 = [] { return thing; }(); +constexpr auto lambda18 = [] (int x, int y) mutable throw(int) { return x+y; }; int runLambda1() { return lambda1(5,6); From e81b6eccdbd33860aca3079ca782844f4fdeeaea Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 4 Oct 2012 06:12:44 +0000 Subject: [PATCH 0219/1160] Add lambda tests to test-suite - gcc-4.7 supports these git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13861 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 0b5e368f9..8d39e6369 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -438,6 +438,7 @@ CPP0X_TEST_CASES = \ cpp0x_explicit_conversion_operators \ cpp0x_function_objects \ cpp0x_initializer_list \ + cpp0x_lambda_functions \ cpp0x_null_pointer_constant \ cpp0x_raw_string_literals \ cpp0x_result_of \ @@ -456,7 +457,6 @@ CPP0X_TEST_CASES = \ # cpp0x_inheriting_constructors \ # not supported by gcc-4.7 # cpp0x_hash_tables \ # not fully implemented yet -# cpp0x_lambda_functions \ # not supported by GCC or MSVC yet # cpp0x_thread_local \ # not supported by any compiler yet # Broken C++0x test cases. From b9fd49858dd52786ecd42284fbc8d050587e25b1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 4 Oct 2012 20:31:40 +0000 Subject: [PATCH 0220/1160] result_of not working git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13862 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 8d39e6369..a0f91655e 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -441,7 +441,6 @@ CPP0X_TEST_CASES = \ cpp0x_lambda_functions \ cpp0x_null_pointer_constant \ cpp0x_raw_string_literals \ - cpp0x_result_of \ cpp0x_rvalue_reference \ cpp0x_rvalue_reference2 \ cpp0x_sizeof_object \ @@ -457,6 +456,7 @@ CPP0X_TEST_CASES = \ # cpp0x_inheriting_constructors \ # not supported by gcc-4.7 # cpp0x_hash_tables \ # not fully implemented yet +# cpp0x_result_of \ # SWIG does not support # cpp0x_thread_local \ # not supported by any compiler yet # Broken C++0x test cases. From 6a43934ece479789b8e84a533d3db25456fe1dff Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 4 Oct 2012 20:52:51 +0000 Subject: [PATCH 0221/1160] Update variadic templates git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13863 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Cpp0x.html | 10 +++++---- .../test-suite/cpp0x_variadic_templates.i | 21 ++++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index d6dce1d18..fa895cc6b 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -500,7 +500,7 @@ union P {

    7.2.17 Variadic templates

    -

    SWIG fully supports the variadic templates syntax (inside the <> +

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

    @@ -517,11 +517,13 @@ public: const int SIZE = sizeof...(ClassName<int, int>);
    -

    For now however, the %template directive only accepts at most the number of -arguments defined in the original template<> block:

    +

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

    -%template(MyVariant1) ClassName<>         // ok
    +%template(MyVariant1) ClassName<>         // zero argument not supported
     %template(MyVariant2) ClassName<int>      // ok
     %template(MyVariant3) ClassName<int, int> // too many arguments
     
    diff --git a/Examples/test-suite/cpp0x_variadic_templates.i b/Examples/test-suite/cpp0x_variadic_templates.i index c287194d4..2c0b2eac8 100644 --- a/Examples/test-suite/cpp0x_variadic_templates.i +++ b/Examples/test-suite/cpp0x_variadic_templates.i @@ -4,9 +4,9 @@ using variadic number of classes. */ %module cpp0x_variadic_templates -%warnfilter(507) MultiArgs1; -%warnfilter(507) SizeOf1; -%warnfilter(507) MultiInherit1; +%warnfilter(SWIGWARN_CPP11_VARIADIC_TEMPLATE) MultiArgs; +%warnfilter(SWIGWARN_CPP11_VARIADIC_TEMPLATE) SizeOf; +%warnfilter(SWIGWARN_CPP11_VARIADIC_TEMPLATE) MultiInherit; //////////////////////// // Variadic templates // @@ -36,7 +36,6 @@ template struct SizeOf { }; %} -// TODO %template (SizeOf1) SizeOf; ////////////////////////// @@ -48,7 +47,7 @@ public: A() { a = 100; } - + virtual ~A() {} int a; }; @@ -57,14 +56,22 @@ public: B() { b = 200; } + virtual ~B() {} int b; }; template class MultiInherit : public BaseClasses... { public: - MultiInherit(BaseClasses&... baseClasses) : BaseClasses(baseClasses)... {} + MultiInherit(BaseClasses&... baseClasses) : BaseClasses(baseClasses)... {} + int InstanceMethod() { return 123; } + static int StaticMethod() { return 456; } }; %} + // TODO -%template (MultiInherit1) MultiInherit; +//%template (MultiInherit0) MultiInherit<>; +%template (MultiInherit1) MultiInherit; +// TODO +%template (MultiInherit2) MultiInherit; + From a42882dcee7df96f1a0d67a23b416bbc99f5af73 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 5 Oct 2012 04:58:00 +0000 Subject: [PATCH 0222/1160] Adjust for change in the size of the Go type int. Until some time in the future, require a -intgosize option when invoking SWIG. Otherwise there is no reliable way for us to know the size of int, and we need to know. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13864 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Go.html | 12 ++++++ Examples/Makefile.in | 5 ++- Lib/go/goruntime.swg | 24 +++++++++++- Source/Modules/go.cxx | 86 +++++++++++++++++++++++++++++++------------ configure.in | 24 ++++++++++++ 5 files changed, 124 insertions(+), 27 deletions(-) diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 78a58df28..7a55a4364 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -93,6 +93,18 @@ swig -go -help Go specific options + +-intgo-type-size %lt;s%gt; +Set the size for the Go type int. This controls the size + that the C/C++ code expects to see. The %lt;s%gt; argument should + be 32 or 64. This option is currently required during the + transition from Go 1.0 to Go 1.1, as the size of int on + 64-bit x86 systems changes between those releases (from 32 bits to + 64 bits). In the future the option may become optional, and SWIG + will assume that the size of int is the size of a C + pointer. + + -gccgo Generate code for gccgo. The default is to generate code for diff --git a/Examples/Makefile.in b/Examples/Makefile.in index bd31bff1f..1e90a01ca 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1169,6 +1169,7 @@ GO = @GO@ GOGCC = @GOGCC@ GO1 = @GO1@ GOC = @GOC@ +GOOPT = @GOOPT@ GOSWIGARG = `if $(GOGCC) ; then echo -gccgo; fi` GOCOMPILEARG = `if $(GOGCC) ; then echo -c -g; elif $(GO1) ; then echo tool $(GOC:c=g) ; fi` @@ -1191,7 +1192,7 @@ GOGCCOBJS = $(GOSRCS:.go=.@OBJEXT@) # ---------------------------------------------------------------- go: $(SRCS) - $(SWIG) -go $(GOSWIGARG) $(SWIGOPT) $(INTERFACEPATH) + $(SWIG) -go $(GOOPT) $(GOSWIGARG) $(SWIGOPT) $(INTERFACEPATH) $(CC) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(GOSRCS) @@ -1205,7 +1206,7 @@ go: $(SRCS) # ---------------------------------------------------------------- go_cpp: $(SRCS) - $(SWIG) -go -c++ $(GOSWIGARG) $(SWIGOPT) $(INTERFACEPATH) + $(SWIG) -go -c++ $(GOOPT) $(GOSWIGARG) $(SWIGOPT) $(INTERFACEPATH) $(CXX) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(GOSRCS) diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index ff33c3b41..f27bbae5e 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -5,12 +5,32 @@ * ------------------------------------------------------------ */ %insert(runtime) %{ +#include #include #include #include +#include -typedef struct { char *p; int n; } _gostring_; -typedef struct { void* array; unsigned int len; unsigned int cap; } _goslice_; +%} + +#if SWIGGO_INTGO_SIZE == 32 +%insert(runtime) %{ +typedef int intgo; +%} +#elif SWIGGO_INTGO_SIZE == 64 +%insert(runtime) %{ +typedef long long intgo; +%} +#else +%insert(runtime) %{ +typedef ptrdiff_t intgo; +%} +#endif + +%insert(runtime) %{ + +typedef struct { char *p; intgo n; } _gostring_; +typedef struct { void* array; intgo len; intgo cap; } _goslice_; %} diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 5be846171..0b5622dcd 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -28,6 +28,8 @@ class GO:public Language { String *soname; // Size in bits of the C type "long". int long_type_size; + // Size in bits of the Go type "int". 0 if not specified. + int intgo_type_size; /* Output files */ File *f_c_begin; @@ -88,6 +90,7 @@ public: go_prefix(NULL), soname(NULL), long_type_size(32), + intgo_type_size(0), f_c_begin(NULL), f_go_begin(NULL), f_gc_begin(NULL), @@ -173,6 +176,19 @@ private: } else { Swig_arg_error(); } + } else if (strcmp(argv[i], "-intgosize") == 0) { + if (argv[i + 1]) { + intgo_type_size = atoi(argv[i + 1]); + if (intgo_type_size != 32 && intgo_type_size != 64) { + Printf(stderr, "-intgosize 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], "-help") == 0) { Printf(stdout, "%s\n", usage); } @@ -196,6 +212,22 @@ private: Preprocessor_define("SWIGGO_LONG_TYPE_SIZE 64", 0); } + // This test may be removed in the future, when we can assume that + // everybody has upgraded to Go 1.1. The code below is prepared + // for this test to simply be taken out. + if (intgo_type_size == 0) { + Printf(stderr, "SWIG -go: -intgosize option required but not specified\n"); + SWIG_exit(EXIT_FAILURE); + } + + if (intgo_type_size == 32) { + Preprocessor_define("SWIGGO_INTGO_SIZE 32", 0); + } else if (intgo_type_size == 64) { + Preprocessor_define("SWIGGO_INTGO_SIZE 64", 0); + } else { + Preprocessor_define("SWIGGO_INTGO_SIZE 0", 0); + } + // Add typemap definitions. SWIG_typemap_lang("go"); SWIG_config_file("go.swg"); @@ -1130,9 +1162,8 @@ private: // 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)"); + // A slice has a pointer, a length, and a capacity. + Append(orig, "(3 * SWIG_PARM_SIZE)"); } else if (Strcmp(go, "float64") == 0) { Append(orig, "8"); } else if (Strcmp(go, "complex64") == 0) { @@ -1186,7 +1217,7 @@ private: Printv(f->code, "\tstruct swigargs {\n", NULL); if (parm_count > required_count) { - Printv(f->code, "\t\tint _swig_optargc;\n", NULL); + Printv(f->code, "\t\tintgo _swig_optargc;\n", NULL); } Parm *p = parms; @@ -1298,7 +1329,7 @@ private: Printv(fnname, go_prefix, "_", wname, "(", NULL); if (parm_count > required_count) { - Printv(fnname, "int _swig_optargc", NULL); + Printv(fnname, "intgo _swig_optargc", NULL); } Parm *p = parms; @@ -4614,19 +4645,20 @@ private: bool is_member = Strcmp(gt, "_swig_memberptr") == 0; bool is_complex64 = Strcmp(gt, "complex64") == 0; bool is_complex128 = Strcmp(gt, "complex128") == 0; - bool is_char = false; - bool is_short = false; - bool is_int = false; - bool is_long = false; - bool is_float = false; - bool is_double = false; + bool is_int8 = false; + bool is_int16 = false; + bool is_int = Strcmp(gt, "int") == 0 || Strcmp(gt, "uint") == 0; + bool is_int32 = false; + bool is_int64 = false; + bool is_float32 = false; + bool is_float64 = false; if ((n != NULL && Getattr(n, "tmap:gotype") != NULL) || hasGoTypemap(n, type)) { - is_char = Strcmp(gt, "int8") == 0 || Strcmp(gt, "uint8") == 0 || Strcmp(gt, "byte") == 0; - is_short = Strcmp(gt, "int16") == 0 || Strcmp(gt, "uint16") == 0; - is_int = Strcmp(gt, "int") == 0 || Strcmp(gt, "int32") == 0 || Strcmp(gt, "uint32") == 0; - is_long = Strcmp(gt, "int64") == 0 || Strcmp(gt, "uint64") == 0; - is_float = Strcmp(gt, "float32") == 0; - is_double = Strcmp(gt, "float64") == 0; + is_int8 = Strcmp(gt, "int8") == 0 || Strcmp(gt, "uint8") == 0 || Strcmp(gt, "byte") == 0; + is_int16 = Strcmp(gt, "int16") == 0 || Strcmp(gt, "uint16") == 0; + is_int32 = Strcmp(gt, "int32") == 0 || Strcmp(gt, "uint32") == 0; + is_int64 = Strcmp(gt, "int64") == 0 || Strcmp(gt, "uint64") == 0; + is_float32 = Strcmp(gt, "float32") == 0; + is_float64 = Strcmp(gt, "float64") == 0; } Delete(gt); @@ -4677,7 +4709,12 @@ private: if (Strcmp(q, "const") == 0) { SwigType_del_qualifier(t); if (hasGoTypemap(n, t) || SwigType_ispointer(t)) { - ret = SwigType_lstr(t, name); + if (is_int) { + ret = NewString("intgo "); + Append(ret, name); + } else { + ret = SwigType_lstr(t, name); + } Delete(q); Delete(t); return ret; @@ -4687,17 +4724,19 @@ private: } } Delete(t); - if (is_char) { + if (is_int8) { ret = NewString("char "); - } else if (is_short) { + } else if (is_int16) { ret = NewString("short "); } else if (is_int) { + ret = NewString("intgo "); + } else if (is_int32) { ret = NewString("int "); - } else if (is_long) { + } else if (is_int64) { ret = NewString("long long "); - } else if (is_float) { + } else if (is_float32) { ret = NewString("float "); - } else if (is_double) { + } else if (is_float64) { ret = NewString("double "); } else { return SwigType_lstr(type, name); @@ -4871,6 +4910,7 @@ Go Options (available with -go)\n\ -gccgo - Generate code for gccgo rather than 6g/8g\n\ -go-prefix

    - Like gccgo -fgo-prefix option\n\ -longsize - Set size of C/C++ long type--32 or 64 bits\n\ + -intgosize - Set size of Go int type--32 or 64 bits\n\ -package - Set name of the Go package to \n\ -soname - Set shared library holding C/C++ code to \n\ \n"; diff --git a/configure.in b/configure.in index 1ef54d8d1..ef7c2d0b7 100644 --- a/configure.in +++ b/configure.in @@ -2055,6 +2055,7 @@ if test x"${GOBIN}" = xno -o x"${with_alllang}" = xno ; then GOC= GO1=false GOGCC=false + GOOPT= else if test "x$GOBIN" = xyes; then @@ -2065,6 +2066,7 @@ else GOGCC=false GO1=false + GOOPT= if test -n "$GO" ; then if $GO --help 2>/dev/null | grep gccgo >/dev/null 2>&1 ; then GOGCC=true @@ -2074,10 +2076,30 @@ else AC_MSG_RESULT([yes - minimum version is 4.7.0]) else AC_MSG_RESULT([no]) + if test "$go_version" -lt 480; then + GOOPT="-intgosize 32" + else + AC_CHECK_SIZEOF([void *], [4]) + if test "$ac_cv_sizeof_void_p" = "8"; then + GOOPT="-intgosize 64" + else + GOOPT="-intgosize 32" + fi + fi fi elif test "`echo $GO | sed -e 's|.*/||'`" = "go"; then GO1=true GOC=$(sh -c "$(go env) && echo \$GOCHAR")c + go_version=$($GO version | sed -e 's/go version //') + case $go_version in + go1.0*) GOOPT="-intgosize 32" ;; + *) if test "$GOC" = "6c"; then + GOOPT="-intgosize 64" + else + GOOPT="-intgosize 32" + fi + ;; + esac else GOC=`echo $GO | sed -e 's/g/c/'` AC_MSG_CHECKING([whether Go ($GO) version is too old]) @@ -2089,6 +2111,7 @@ else else AC_MSG_RESULT([no]) fi + GOOPT="-intgosize 32" fi fi fi @@ -2097,6 +2120,7 @@ AC_SUBST(GOGCC) AC_SUBST(GO) AC_SUBST(GOC) AC_SUBST(GO1) +AC_SUBST(GOOPT) #---------------------------------------------------------------- # Look for D From 81d0168e51817fbb4f3fa57dd782793677b89525 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 5 Oct 2012 19:19:56 +0000 Subject: [PATCH 0223/1160] Autoconf archive macro to detect c++11 - as downloaded from archive git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13865 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Tools/config/ax_cxx_compile_stdcxx_11.m4 | 107 +++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 Tools/config/ax_cxx_compile_stdcxx_11.m4 diff --git a/Tools/config/ax_cxx_compile_stdcxx_11.m4 b/Tools/config/ax_cxx_compile_stdcxx_11.m4 new file mode 100644 index 000000000..0d96c073a --- /dev/null +++ b/Tools/config/ax_cxx_compile_stdcxx_11.m4 @@ -0,0 +1,107 @@ +# ============================================================================ +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html +# ============================================================================ +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_11([ext|noext]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++11 +# standard; if necessary, add switches to CXXFLAGS to enable support. +# Errors out if no mode that supports C++11 baseline syntax can be found. +# The argument, if specified, indicates whether you insist on an extended +# mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. -std=c++11). +# If neither is specified, you get whatever works, with preference for an +# extended mode. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# Copyright (c) 2012 Zack Weinberg +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 1 + +m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [ + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c); +]) + +AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl + m4_if([$1], [], [], + [$1], [ext], [], + [$1], [noext], [], + [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl + AC_LANG_ASSERT([C++])dnl + ac_success=no + AC_CACHE_CHECK(whether $CXX supports C++11 features by default, + ax_cv_cxx_compile_cxx11, + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], + [ax_cv_cxx_compile_cxx11=yes], + [ax_cv_cxx_compile_cxx11=no])]) + if test x$ax_cv_cxx_compile_cxx11 = xyes; then + ac_success=yes + fi + + m4_if([$1], [noext], [], [dnl + if test x$ac_success = xno; then + for switch in -std=gnu++11 -std=gnu++0x; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, + $cachevar, + [ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXXFLAGS="$ac_save_CXXFLAGS"]) + if eval test x\$$cachevar = xyes; then + CXXFLAGS="$CXXFLAGS $switch" + ac_success=yes + break + fi + done + fi]) + + m4_if([$1], [ext], [], [dnl + if test x$ac_success = xno; then + for switch in -std=c++11 -std=c++0x; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, + $cachevar, + [ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXXFLAGS="$ac_save_CXXFLAGS"]) + if eval test x\$$cachevar = xyes; then + CXXFLAGS="$CXXFLAGS $switch" + ac_success=yes + break + fi + done + fi]) + + if test x$ac_success = xno; then + AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.]) + fi +]) From 77ccb6f21ce62b9d19d40d7160bdbb7762ec2490 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 7 Oct 2012 18:50:41 +0000 Subject: [PATCH 0224/1160] Modify autoconf macro to be more flexible about how it is used - sets CXX11FLAGS, HAVE_CXX11_COMPILER and option to not error out git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13866 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Tools/config/ax_cxx_compile_stdcxx_11.m4 | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Tools/config/ax_cxx_compile_stdcxx_11.m4 b/Tools/config/ax_cxx_compile_stdcxx_11.m4 index 0d96c073a..138ca2aca 100644 --- a/Tools/config/ax_cxx_compile_stdcxx_11.m4 +++ b/Tools/config/ax_cxx_compile_stdcxx_11.m4 @@ -4,15 +4,18 @@ # # SYNOPSIS # -# AX_CXX_COMPILE_STDCXX_11([ext|noext]) +# AX_CXX_COMPILE_STDCXX_11([ext|noext], [nostop]) # # DESCRIPTION # # Check for baseline language coverage in the compiler for the C++11 # standard; if necessary, add switches to CXXFLAGS to enable support. -# Errors out if no mode that supports C++11 baseline syntax can be found. -# The argument, if specified, indicates whether you insist on an extended -# mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. -std=c++11). +# CXX11FLAGS will also contain any necessary switches to enable support. +# HAVE_CXX11_COMPILER will additionally be set to yes if there is support. +# If the second argument is not specified, errors out if no mode that +# supports C++11 baseline syntax can be found. The first argument, if +# specified, indicates whether you insist on an extended mode +# (e.g. -std=gnu++11) or a strict conformance mode (e.g. -std=c++11). # If neither is specified, you get whatever works, with preference for an # extended mode. # @@ -20,6 +23,7 @@ # # Copyright (c) 2008 Benjamin Kosnik # Copyright (c) 2012 Zack Weinberg +# Copyright (c) 2012 William Fulton # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice @@ -50,8 +54,12 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl [$1], [ext], [], [$1], [noext], [], [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl + m4_if([$2], [], [], + [$2], [nostop], [], + [m4_fatal([invalid argument `$2' to AX_CXX_COMPILE_STDCXX_11])])dnl AC_LANG_ASSERT([C++])dnl ac_success=no + CXX11FLAGS= AC_CACHE_CHECK(whether $CXX supports C++11 features by default, ax_cv_cxx_compile_cxx11, [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], @@ -75,6 +83,7 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl CXXFLAGS="$ac_save_CXXFLAGS"]) if eval test x\$$cachevar = xyes; then CXXFLAGS="$CXXFLAGS $switch" + CXX11FLAGS=$switch ac_success=yes break fi @@ -95,6 +104,7 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl CXXFLAGS="$ac_save_CXXFLAGS"]) if eval test x\$$cachevar = xyes; then CXXFLAGS="$CXXFLAGS $switch" + CXX11FLAGS=$switch ac_success=yes break fi @@ -102,6 +112,10 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl fi]) if test x$ac_success = xno; then - AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.]) + if test x$2 != xnostop; then + AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.]) + fi + else + HAVE_CXX11_COMPILER=yes fi ]) From c94418b603a77c15d44162206c4373a4bd0f5d43 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 7 Oct 2012 18:56:48 +0000 Subject: [PATCH 0225/1160] Improve detection of C++11 compiler and set appropriate flags to use C++11/C++0x features git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13867 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/Makefile.in | 2 +- Examples/guile/Makefile.in | 2 +- configure.in | 19 ++++++++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 7fe78f359..4b5142267 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -24,7 +24,7 @@ TARGET = CC = @CC@ CXX = @CXX@ -CFLAGS = @PLATFLAGS@ +CFLAGS = @PLATCFLAGS@ CXXFLAGS = @PLATCXXFLAGS@ prefix = @prefix@ exec_prefix= @exec_prefix@ diff --git a/Examples/guile/Makefile.in b/Examples/guile/Makefile.in index a11095599..ec99f5fcd 100644 --- a/Examples/guile/Makefile.in +++ b/Examples/guile/Makefile.in @@ -6,7 +6,7 @@ top_srcdir = @top_srcdir@ SWIG = ../$(top_srcdir)/preinst-swig CC = @CC@ CXX = @CXX@ -CFLAGS = @PLATFLAGS@ +CFLAGS = @PLATCFLAGS@ GUILEINCLUDE = @GUILEINCLUDE@ GUILELINK = @GUILELINK@ SWIGOPT = diff --git a/configure.in b/configure.in index 3e2f2beae..4dda250d2 100644 --- a/configure.in +++ b/configure.in @@ -314,16 +314,21 @@ case $host in esac # Optional CFLAGS used to silence compiler warnings on some platforms. +AC_SUBST(PLATCFLAGS) +PLATCFLAGS= -AC_SUBST(PLATFLAGS) -PLATFLAGS= - -# Add switch to enable C++0x support +# Add switch if necessary to enable C++11 support - just for tests +AC_LANG_PUSH([C++]) +CXXFLAGS_SAVED=$CXXFLAGS +AX_CXX_COMPILE_STDCXX_11([noext], [nostop]) +CXXFLAGS=$CXXFLAGS_SAVED +AC_LANG_POP([C++]) AC_SUBST(PLATCXXFLAGS) -if test "$GCC" = yes; then - PLATCXXFLAGS=$PLATFLAGS" -std=c++0x " +AC_SUBST(HAVE_CXX11_COMPILER) +if test x"$CXX11FLAGS" = x; then + PLATCXXFLAGS="$PLATCFLAGS" else - PLATCXXFLAGS=$PLATFLAGS + PLATCXXFLAGS="$CXX11FLAGS $PLATCFLAGS" fi # Check for specific libraries. Used for SWIG examples From 6f0d565241af0b29e09e8d50b14ed96798e1a920 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 8 Oct 2012 18:20:08 +0000 Subject: [PATCH 0226/1160] Add note about requiring -intgosize option for Go. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13868 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index a4a049b1d..b864b2aa2 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.9 (in progress) =========================== +2012-10-08: iant + [Go] Generating Go code now requires using the -intgosize option to + indicate the size of the 'int' type in Go. This is because the + size of the type is changing from Go 1.0 to Go 1.1 for x86_64. + 2012-09-14: wsfulton Add new warning if the empty template instantiation is used as a base class, for example: From 77d9ad53544b568880aea9c335ea478e5717c3a6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 11 Oct 2012 19:22:13 +0000 Subject: [PATCH 0227/1160] Fix multiply defined symbol in target language scope git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13869 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/lang.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index d15d650a2..6fa9defd9 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2991,8 +2991,8 @@ int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr } else { Node *c = Getattr(symbols, s); if (c && (c != n)) { - if (scope) - Swig_error(input_file, line_number, "'%s' is multiply defined in the generated target language module in scope %s.\n", s, scope); + if (scope && Len(scope) > 0) + 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); From 2598a1daf251f5c9c0d92feb44efb393499ce59f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 11 Oct 2012 19:24:24 +0000 Subject: [PATCH 0228/1160] Two additional special variable are expanded in %exception - $parentname and $parentsymname git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13870 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 +++ Doc/Manual/Customization.html | 10 +++++ .../java/special_variables_runme.java | 6 +-- Examples/test-suite/special_variables.i | 37 ++++++++++++++++++- Source/Modules/emit.cxx | 15 ++++++++ 5 files changed, 68 insertions(+), 5 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index b864b2aa2..08603bd5d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -9,6 +9,11 @@ Version 2.0.9 (in progress) indicate the size of the 'int' type in Go. This is because the size of the type is changing from Go 1.0 to Go 1.1 for x86_64. +2012-09-14: wsfulton + Additional new special variables in %exception are expanded as follows: + $parentname - The parent class name (if any) for a method. + $parentsymname - The target language parent class name (if any) for a method. + 2012-09-14: wsfulton Add new warning if the empty template instantiation is used as a base class, for example: diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html index b98fbfc88..c903f24fa 100644 --- a/Doc/Manual/Customization.html +++ b/Doc/Manual/Customization.html @@ -479,6 +479,16 @@ variables are replaced with. The fully qualified C/C++ declaration of the method being wrapped including the return type + +$parentname +The parent class name (if any) for a method. + + + +$parentsymname +The target language parent class name (if any) for a method. + +

    diff --git a/Examples/test-suite/java/special_variables_runme.java b/Examples/test-suite/java/special_variables_runme.java index eb9f093bd..703e6fb0d 100644 --- a/Examples/test-suite/java/special_variables_runme.java +++ b/Examples/test-suite/java/special_variables_runme.java @@ -15,13 +15,13 @@ public class special_variables_runme { public static void main(String argv[]) { verify(special_variables.ExceptionVars(1.0, 2.0), - "result = Space::exceptionvars(arg1,arg2); Space::exceptionvars ExceptionVars Java_special_1variables_special_1variablesJNI_ExceptionVars"); + "result = Space::exceptionvars(arg1,arg2); Space::exceptionvars ExceptionVars Java_special_1variables_special_1variablesJNI_ExceptionVars "); verify(special_variables.overloadedmethod(), - "result = Space::overloadedmethod(); Space::overloadedmethod overloadedmethod __SWIG_1 Java_special_1variables_special_1variablesJNI_overloadedmethod_1_1SWIG_11"); + "result = Space::overloadedmethod(); Space::overloadedmethod overloadedmethod __SWIG_1 Java_special_1variables_special_1variablesJNI_overloadedmethod_1_1SWIG_11 "); verify(special_variables.overloadedmethod(10.0), - "result = Space::overloadedmethod(arg1); Space::overloadedmethod overloadedmethod __SWIG_0 Java_special_1variables_special_1variablesJNI_overloadedmethod_1_1SWIG_10"); + "result = Space::overloadedmethod(arg1); Space::overloadedmethod overloadedmethod __SWIG_0 Java_special_1variables_special_1variablesJNI_overloadedmethod_1_1SWIG_10 "); ABC a = new ABC(0, 0.0); verify(special_variables.getDeclaration(), "SpaceNamespace::ABC::ABC(int,double) SpaceNamespace::ABC::ABC(int,double)"); diff --git a/Examples/test-suite/special_variables.i b/Examples/test-suite/special_variables.i index 071365710..aa1db0461 100644 --- a/Examples/test-suite/special_variables.i +++ b/Examples/test-suite/special_variables.i @@ -32,7 +32,7 @@ std::string ExceptionVars(double i, double j) { result = $symname(1.0,2.0); // Should expand to ExceptionVars result = $name(3.0,4.0); // Should expand to Space::exceptionvars // above will not compile if the variables are not expanded properly - result = "$action $name $symname $overname $wrapname"; + result = "$action $name $symname $overname $wrapname $parentclassname $parentclasssymname"; %} %inline %{ namespace Space { @@ -49,7 +49,7 @@ std::string exceptionvars(double i, double j) { result = $name(); result = $name(2.0); // above will not compile if the variables are not expanded properly - result = "$action $name $symname $overname $wrapname"; + result = "$action $name $symname $overname $wrapname $parentclassname $parentclasssymname"; // $decl %} @@ -104,3 +104,36 @@ struct DirectorTest { virtual ~DirectorTest() {} }; %} + + +/////////////////////////////////// parentclasssymname parentclassname ///////////////////////////////// +%exception instance_def { + $action + $parentclasssymname_aaa(); + $parentclassname_bbb(); + // above will not compile if the variables are not expanded properly +} +%exception static_def { + $action + $parentclasssymname_aaa(); + $parentclassname_bbb(); + // above will not compile if the variables are not expanded properly +} + +%{ +void DEFNewName_aaa() {} +namespace SpaceNamespace { + void DEF_bbb() {} +} +%} + +%rename(DEFNewName) DEF; +%inline %{ +namespace SpaceNamespace { + struct DEF : ABC { + void instance_def() {} + static void static_def() {} + }; +} +%} + diff --git a/Source/Modules/emit.cxx b/Source/Modules/emit.cxx index 7d7f66eaf..5c81a17cd 100644 --- a/Source/Modules/emit.cxx +++ b/Source/Modules/emit.cxx @@ -381,6 +381,21 @@ int emit_action_code(Node *n, String *wrappercode, String *eaction) { Replaceall(tm, "$fulldecl", fulldecl); Delete(fulldecl); } + + Node *parentnode = parentNode(n); + Node *parentclass = (parentnode && Equal(nodeType(parentnode), "class")) ? parentnode : 0; + if (Strstr(tm, "$parentclasssymname")) { + String *parentclasssymname = 0; + if (parentclass) + parentclasssymname = Getattr(parentclass, "sym:name"); + Replaceall(tm, "$parentclasssymname", parentclasssymname ? parentclasssymname : ""); + } + if (Strstr(tm, "$parentclassname")) { + String *parentclassname = 0; + if (parentclass) + parentclassname = Getattr(parentclass, "name"); + Replaceall(tm, "$parentclassname", parentclassname ? parentclassname : ""); + } } Printv(wrappercode, tm, "\n", NIL); Delete(tm); From b17a77c6ea34cb022d1206111bd7e40d7b292ce2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 11 Oct 2012 19:28:02 +0000 Subject: [PATCH 0229/1160] Support special variable expansion in %extend. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13871 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 15 ++++-- Doc/Manual/Customization.html | 5 ++ Doc/Manual/SWIGPlus.html | 6 +++ Examples/test-suite/common.mk | 1 + .../test-suite/extend_special_variables.i | 21 ++++++++ .../java/extend_special_variables_runme.java | 25 +++++++++ Source/Modules/emit.cxx | 32 +----------- Source/Swig/cwrap.c | 51 +++++++++++++++++-- Source/Swig/swig.h | 1 + 9 files changed, 117 insertions(+), 40 deletions(-) create mode 100644 Examples/test-suite/extend_special_variables.i create mode 100644 Examples/test-suite/java/extend_special_variables_runme.java diff --git a/CHANGES.current b/CHANGES.current index 08603bd5d..fac0897cb 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,16 +4,21 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.9 (in progress) =========================== +2012-10-11: wsfulton + Most of the special variables available for use in %exception are now also available for expansion in + %extend blocks. These are: $name $symname $overname $decl $fulldecl $parentname $parentsymname, see docs + on "Class extension" in SWIGPlus.html. Patch based on submission from Kris Thielemans. + +2012-10-10: wsfulton + Additional new special variables in %exception are expanded as follows: + $parentname - The parent class name (if any) for a method. + $parentsymname - The target language parent class name (if any) for a method. + 2012-10-08: iant [Go] Generating Go code now requires using the -intgosize option to indicate the size of the 'int' type in Go. This is because the size of the type is changing from Go 1.0 to Go 1.1 for x86_64. -2012-09-14: wsfulton - Additional new special variables in %exception are expanded as follows: - $parentname - The parent class name (if any) for a method. - $parentsymname - The target language parent class name (if any) for a method. - 2012-09-14: wsfulton Add new warning if the empty template instantiation is used as a base class, for example: diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html index c903f24fa..b75eda9c4 100644 --- a/Doc/Manual/Customization.html +++ b/Doc/Manual/Customization.html @@ -454,6 +454,11 @@ variables are replaced with. The actual operation to be performed (a function call, method invocation, variable access, etc.) + +$name +The C/C++ symbol name for the function. + + $symname The symbol name used internally by SWIG diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index 9ecf0aa5a..716882f53 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -2838,6 +2838,12 @@ struct Derived : Base { }

    +

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

    +

    The %extend directive follows all of the same conventions as its use with C structures. Please refer to the Adding member functions to C structures diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index eaef4980b..bf318d304 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -204,6 +204,7 @@ CPP_TEST_CASES += \ extend_constructor_destructor \ extend_default \ extend_placement \ + extend_special_variables \ extend_template \ extend_template_ns \ extend_typedef_class \ diff --git a/Examples/test-suite/extend_special_variables.i b/Examples/test-suite/extend_special_variables.i new file mode 100644 index 000000000..dd68e7531 --- /dev/null +++ b/Examples/test-suite/extend_special_variables.i @@ -0,0 +1,21 @@ +%module extend_special_variables + +%rename(ForExtensionNewName) ForExtension; +%rename(extended_renamed) ForExtension::extended; + +%extend ForExtension { + ForExtension() { + return new ForExtension(); + } + const char* extended() { + return "name:$name symname:$symname wrapname:$wrapname overname:$overname decl:$decl fulldecl:$fulldecl parentclasssymname:$parentclasssymname parentclassname:$parentclassname"; + } + const char* extended(int) { + return "name:$name symname:$symname wrapname:$wrapname overname:$overname decl:$decl fulldecl:$fulldecl parentclasssymname:$parentclasssymname parentclassname:$parentclassname"; + } +} + +%inline %{ +struct ForExtension { +}; +%} diff --git a/Examples/test-suite/java/extend_special_variables_runme.java b/Examples/test-suite/java/extend_special_variables_runme.java new file mode 100644 index 000000000..cf2304e6a --- /dev/null +++ b/Examples/test-suite/java/extend_special_variables_runme.java @@ -0,0 +1,25 @@ + +import extend_special_variables.*; + +public class extend_special_variables_runme { + + static { + try { + System.loadLibrary("extend_special_variables"); + } 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[]) + { + ForExtensionNewName f = new ForExtensionNewName(); + verify(f.extended_renamed(), "name:extended symname:extended_renamed wrapname: overname:__SWIG_0 decl:ForExtension::extended() fulldecl:char const * ForExtension::extended() parentclasssymname:ForExtensionNewName parentclassname:ForExtension"); + verify(f.extended_renamed(10), "name:extended symname:extended_renamed wrapname: overname:__SWIG_1 decl:ForExtension::extended(int) fulldecl:char const * ForExtension::extended(int) parentclasssymname:ForExtensionNewName parentclassname:ForExtension"); + } + static void verify(String received, String expected) { + if (!received.equals(expected)) + throw new RuntimeException("Incorrect, received: " + received); + } +} diff --git a/Source/Modules/emit.cxx b/Source/Modules/emit.cxx index 5c81a17cd..c16eaac0f 100644 --- a/Source/Modules/emit.cxx +++ b/Source/Modules/emit.cxx @@ -363,39 +363,9 @@ int emit_action_code(Node *n, String *wrappercode, String *eaction) { tm = Copy(tm); if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { if (Strstr(tm, "$")) { - Replaceall(tm, "$name", Getattr(n, "name")); - Replaceall(tm, "$symname", Getattr(n, "sym:name")); + Swig_replace_special_variables(n, parentNode(n), tm); Replaceall(tm, "$function", eaction); // deprecated Replaceall(tm, "$action", eaction); - Replaceall(tm, "$wrapname", Getattr(n, "wrap:name")); - String *overloaded = Getattr(n, "sym:overloaded"); - Replaceall(tm, "$overname", overloaded ? Char(Getattr(n, "sym:overname")) : ""); - - if (Strstr(tm, "$decl")) { - String *decl = Swig_name_decl(n); - Replaceall(tm, "$decl", decl); - Delete(decl); - } - if (Strstr(tm, "$fulldecl")) { - String *fulldecl = Swig_name_fulldecl(n); - Replaceall(tm, "$fulldecl", fulldecl); - Delete(fulldecl); - } - - Node *parentnode = parentNode(n); - Node *parentclass = (parentnode && Equal(nodeType(parentnode), "class")) ? parentnode : 0; - if (Strstr(tm, "$parentclasssymname")) { - String *parentclasssymname = 0; - if (parentclass) - parentclasssymname = Getattr(parentclass, "sym:name"); - Replaceall(tm, "$parentclasssymname", parentclasssymname ? parentclasssymname : ""); - } - if (Strstr(tm, "$parentclassname")) { - String *parentclassname = 0; - if (parentclass) - parentclassname = Getattr(parentclass, "name"); - Replaceall(tm, "$parentclassname", parentclassname ? parentclassname : ""); - } } Printv(wrappercode, tm, "\n", NIL); Delete(tm); diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 5e2e6367d..a032de746 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -759,6 +759,46 @@ String *Swig_cmemberget_call(const_String_or_char_ptr name, SwigType *t, String return func; } +/* ----------------------------------------------------------------------------- + * Swig_replace_special_variables() + * + * Replaces special variables with a value from the supplied node + * ----------------------------------------------------------------------------- */ +void Swig_replace_special_variables(Node *n, Node *parentnode, String *code) { + Node *parentclass = parentnode; + String *overloaded = Getattr(n, "sym:overloaded"); + Replaceall(code, "$name", Getattr(n, "name")); + Replaceall(code, "$symname", Getattr(n, "sym:name")); + Replaceall(code, "$wrapname", Getattr(n, "wrap:name")); + Replaceall(code, "$overname", overloaded ? Char(Getattr(n, "sym:overname")) : ""); + + if (Strstr(code, "$decl")) { + String *decl = Swig_name_decl(n); + Replaceall(code, "$decl", decl); + Delete(decl); + } + if (Strstr(code, "$fulldecl")) { + String *fulldecl = Swig_name_fulldecl(n); + Replaceall(code, "$fulldecl", fulldecl); + Delete(fulldecl); + } + + if (parentclass && !Equal(nodeType(parentclass), "class")) + parentclass = 0; + if (Strstr(code, "$parentclasssymname")) { + String *parentclasssymname = 0; + if (parentclass) + parentclasssymname = Getattr(parentclass, "sym:name"); + Replaceall(code, "$parentclasssymname", parentclasssymname ? parentclasssymname : ""); + } + if (Strstr(code, "$parentclassname")) { + String *parentclassname = 0; + if (parentclass) + parentclassname = Getattr(parentclass, "name"); + Replaceall(code, "$parentclassname", parentclassname ? parentclassname : ""); + } +} + /* ----------------------------------------------------------------------------- * extension_code() * @@ -767,14 +807,17 @@ String *Swig_cmemberget_call(const_String_or_char_ptr name, SwigType *t, String * return_type function_name(parms) code * * ----------------------------------------------------------------------------- */ -static String *extension_code(const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self) { +static String *extension_code(Node *n, const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self) { String *parms_str = cplusplus ? ParmList_str_defaultargs(parms) : ParmList_str(parms); String *sig = NewStringf("%s(%s)", function_name, parms_str); String *rt_sig = SwigType_str(return_type, sig); String *body = NewStringf("SWIGINTERN %s", rt_sig); Printv(body, code, "\n", NIL); - if (self) - Replaceall(body, "$self", self); + if (Strstr(body, "$")) { + Swig_replace_special_variables(n, parentNode(parentNode(n)), body); + if (self) + Replaceall(body, "$self", self); + } Delete(parms_str); Delete(sig); Delete(rt_sig); @@ -791,7 +834,7 @@ static String *extension_code(const String *function_name, ParmList *parms, Swig * * ----------------------------------------------------------------------------- */ int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self) { - String *body = extension_code(function_name, parms, return_type, code, cplusplus, self); + String *body = extension_code(n, function_name, parms, return_type, code, cplusplus, self); Setattr(n, "wrap:code", body); Delete(body); return SWIG_OK; diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index a85334e55..42fd9238e 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -354,6 +354,7 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern String *Swig_cmemberget_call(const_String_or_char_ptr name, SwigType *t, String *self, int varcref); extern int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self); + extern void Swig_replace_special_variables(Node *n, Node *parentnode, String *code); /* --- Transformations --- */ From c4e4b4b6100f49028f5791073f74a49895b409f4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 26 Oct 2012 19:32:19 +0000 Subject: [PATCH 0230/1160] New director test highlighting a proble in Go git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13872 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 1 + Examples/test-suite/director_overload2.i | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 Examples/test-suite/director_overload2.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index bf318d304..7f3cd771a 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -180,6 +180,7 @@ CPP_TEST_CASES += \ director_nspace \ director_nested \ director_overload \ + director_overload2 \ director_primitives \ director_protected \ director_protected_overloaded \ diff --git a/Examples/test-suite/director_overload2.i b/Examples/test-suite/director_overload2.i new file mode 100644 index 000000000..0f3238149 --- /dev/null +++ b/Examples/test-suite/director_overload2.i @@ -0,0 +1,22 @@ +%module(directors="1") director_overload2 + +%feature("director"); + + +%inline %{ +struct OverloadBase { + virtual ~OverloadBase() {} + virtual void mmm() {} + virtual void nnn(int vvv) {} + virtual void nnn() {} +}; +struct OverloadDerived1 : OverloadBase { + virtual void nnn(int vvv) {} +// virtual void nnn() {} +}; +struct OverloadDerived2 : OverloadBase { +// virtual void nnn(int vvv) {} + virtual void nnn() {} +}; +%} + From f6229d4b731986746488724f022b75469f41aba2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 27 Oct 2012 17:37:34 +0000 Subject: [PATCH 0231/1160] Fix director typemap searching so that a typemap specified with a name will be correctly matched. Previously the name was ignored during the typemap search. Implemented by ensuring the 'type' attribute in the Node is set up correctly and using the usual Swig_typemap_lookup on the Node. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13873 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 + Examples/test-suite/typemap_directorout.i | 48 ++++++++ Source/Modules/csharp.cxx | 30 ++--- Source/Modules/d.cxx | 36 ++---- Source/Modules/go.cxx | 143 ++++++++++------------ Source/Modules/java.cxx | 38 ++---- Source/Modules/lang.cxx | 9 +- Source/Modules/ocaml.cxx | 54 ++------ Source/Modules/octave.cxx | 42 ++----- Source/Modules/php.cxx | 48 ++------ Source/Modules/python.cxx | 49 ++------ Source/Modules/ruby.cxx | 47 ++----- 12 files changed, 201 insertions(+), 348 deletions(-) create mode 100644 Examples/test-suite/typemap_directorout.i diff --git a/CHANGES.current b/CHANGES.current index fac0897cb..d36e76d62 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.9 (in progress) =========================== +2012-10-26: wsfulton + Fix director typemap searching so that a typemap specified with a name will be correctly matched. Previously + the name was ignored during the typemap search. Applies to the following list of typemaps: + directorout, csdirectorout, cstype, imtype, ctype, ddirectorout, dtype, gotype, jtype, jni, javadirectorout. + 2012-10-11: wsfulton Most of the special variables available for use in %exception are now also available for expansion in %extend blocks. These are: $name $symname $overname $decl $fulldecl $parentname $parentsymname, see docs diff --git a/Examples/test-suite/typemap_directorout.i b/Examples/test-suite/typemap_directorout.i new file mode 100644 index 000000000..4a85bd47c --- /dev/null +++ b/Examples/test-suite/typemap_directorout.i @@ -0,0 +1,48 @@ +// Test named output typemaps used in directors are found during the typematch search +%module(directors="1") typemap_directorout + +%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Class1; + +%feature("director"); + +%typemap(out) MyType & %{ WILL_NOT_COMPILE %} +%typemap(out) MyType &USEME = SWIGTYPE &; +%typemap(out) MyType &Class1::foo2, MyType &foo1 %{ /* special start */ $typemap(out, MyType &USEME) /* special end */ %} + +%typemap(directorout) MyType & %{ WILL_NOT_COMPILE %} +// Can't use the %typemap(directorout) MyType & = SWIGTYPE & approach as non-director languages don't define any directorout typemaps +%typemap(directorout) MyType &Class1::foo2, MyType &foo1 %{ /* special start */ $input = 0; /* special end */ %} + + +#ifdef SWIGCSHARP +%typemap(csdirectorout) MyType & %{ WILL_NOT_COMPILE %} +%typemap(csdirectorout) MyType &USEME = SWIGTYPE &; +%typemap(csdirectorout) MyType &Class1::foo2, MyType &foo1 %{ /* special start */ $typemap(csdirectorout, MyType &USEME) /* special end */ %} +#endif + +#ifdef SWIGD +%typemap(ddirectorout) MyType & %{ WILL_NOT_COMPILE %} +%typemap(ddirectorout) MyType &USEME = SWIGTYPE &; +%typemap(ddirectorout) MyType &Class1::foo2, MyType &foo1 %{ /* special start */ $typemap(ddirectorout, MyType &USEME) /* special end */ %} +#endif + +#ifdef SWIGJAVA +%typemap(javadirectorout) MyType & %{ WILL_NOT_COMPILE %} +%typemap(javadirectorout) MyType &USEME = SWIGTYPE &; +%typemap(javadirectorout) MyType &Class1::foo2, MyType &foo1 %{ /* special start */ $typemap(javadirectorout, MyType &USEME) /* special end */ %} +#endif + +%inline %{ +typedef int MyType; +class Class1 +{ + MyType mt; +public: + Class1() : mt() {} + virtual MyType & foo1() { return mt; } + virtual MyType & foo2(int parm1) { return mt; } + virtual MyType & foo2() { return mt; } + virtual ~Class1() {} +}; +%} + diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 1d6748ae3..db8a65a27 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3449,13 +3449,11 @@ public: * --------------------------------------------------------------- */ int classDirectorMethod(Node *n, Node *parent, String *super) { - String *empty_str = NewString(""); String *classname = Getattr(parent, "sym:name"); String *c_classname = Getattr(parent, "name"); String *name = Getattr(n, "name"); String *symname = Getattr(n, "sym:name"); - SwigType *type = Getattr(n, "type"); - SwigType *returntype = Getattr(n, "returntype"); + SwigType *returntype = Getattr(n, "type"); String *overloaded_name = getOverloadedName(n); String *storage = Getattr(n, "storage"); String *value = Getattr(n, "value"); @@ -3544,14 +3542,12 @@ public: } /* Create the intermediate class wrapper */ - Parm *tp = NewParm(returntype, empty_str, n); - - tm = Swig_typemap_lookup("imtype", tp, "", 0); + tm = Swig_typemap_lookup("imtype", n, "", 0); if (tm) { - String *imtypeout = Getattr(tp, "tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap + String *imtypeout = Getattr(n, "tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap if (imtypeout) tm = imtypeout; - const String *im_directoroutattributes = Getattr(tp, "tmap:imtype:directoroutattributes"); + const String *im_directoroutattributes = Getattr(n, "tmap:imtype:directoroutattributes"); if (im_directoroutattributes) { Printf(callback_def, " %s\n", im_directoroutattributes); Printf(director_delegate_definitions, " %s\n", im_directoroutattributes); @@ -3564,10 +3560,7 @@ public: Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(returntype, 0)); } - Parm *retpm = NewParm(returntype, empty_str, n); - - if ((c_ret_type = Swig_typemap_lookup("ctype", retpm, "", 0))) { - + if ((c_ret_type = Swig_typemap_lookup("ctype", n, "", 0))) { if (!is_void && !ignored_method) { String *jretval_decl = NewStringf("%s jresult", c_ret_type); Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL); @@ -3578,8 +3571,6 @@ public: SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); output_director = false; } - - Delete(retpm); } Swig_director_parms_fixup(l); @@ -3731,7 +3722,7 @@ public: /* header declaration, start wrapper definition */ String *target; - SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type"); target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); Printf(w->def, "%s", target); Delete(qualified_name); @@ -3778,9 +3769,7 @@ public: String *upcall = NewStringf("%s(%s)", symname, imcall_args); if (!is_void) { - Parm *tp = NewParm(returntype, empty_str, n); - - if ((tm = Swig_typemap_lookup("csdirectorout", tp, "", 0))) { + if ((tm = Swig_typemap_lookup("csdirectorout", n, "", 0))) { substituteClassname(returntype, tm); Replaceall(tm, "$cscall", upcall); @@ -3788,7 +3777,6 @@ public: } Delete(tm); - Delete(tp); } else Printf(callback_code, " %s;\n", upcall); @@ -3804,10 +3792,9 @@ public: if (!is_void) { String *jresult_str = NewString("jresult"); String *result_str = NewString("c_result"); - Parm *tp = NewParm(returntype, result_str, n); /* Copy jresult into c_result... */ - if ((tm = Swig_typemap_lookup("directorout", tp, result_str, w))) { + if ((tm = Swig_typemap_lookup("directorout", n, result_str, w))) { Replaceall(tm, "$input", jresult_str); Replaceall(tm, "$result", result_str); Printf(w->code, "%s\n", tm); @@ -3818,7 +3805,6 @@ public: output_director = false; } - Delete(tp); Delete(jresult_str); Delete(result_str); } diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 7fca68df7..879a4acd8 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -1927,13 +1927,11 @@ public: * underlying D object. * --------------------------------------------------------------------------- */ virtual int classDirectorMethod(Node *n, Node *parent, String *super) { - String *empty_str = NewString(""); String *classname = Getattr(parent, "sym:name"); String *c_classname = Getattr(parent, "name"); String *name = Getattr(n, "name"); String *symname = Getattr(n, "sym:name"); - SwigType *type = Getattr(n, "type"); - SwigType *returntype = Getattr(n, "returntype"); + SwigType *returntype = Getattr(n, "type"); String *overloaded_name = getOverloadedName(n); String *storage = Getattr(n, "storage"); String *value = Getattr(n, "value"); @@ -2022,11 +2020,9 @@ public: } /* Create the intermediate class wrapper */ - Parm *tp = NewParm(returntype, empty_str, n); - - tm = lookupDTypemap(tp, "imtype"); + tm = lookupDTypemap(n, "imtype"); if (tm) { - String *imtypeout = Getattr(tp, "tmap:imtype:out"); + String *imtypeout = Getattr(n, "tmap:imtype:out"); if (imtypeout) { // The type in the imtype typemap's out attribute overrides the type // in the typemap. @@ -2039,9 +2035,7 @@ public: "No imtype typemap defined for %s\n", SwigType_str(returntype, 0)); } - Parm *retpm = NewParm(returntype, empty_str, n); - - if ((c_ret_type = Swig_typemap_lookup("ctype", retpm, "", 0))) { + if ((c_ret_type = Swig_typemap_lookup("ctype", n, "", 0))) { if (!is_void && !ignored_method) { String *jretval_decl = NewStringf("%s jresult", c_ret_type); Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL); @@ -2053,8 +2047,6 @@ public: SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); output_director = false; } - - Delete(retpm); } Swig_director_parms_fixup(l); @@ -2213,7 +2205,7 @@ public: /* header declaration, start wrapper definition */ String *target; - SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type"); target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); Printf(w->def, "%s", target); Delete(qualified_name); @@ -2259,16 +2251,10 @@ public: String *upcall = NewStringf("(cast(%s)dObject).%s(%s)", classname, symname, imcall_args); if (!is_void) { - Parm *tp = NewParm(returntype, empty_str, n); - - // RESEARCH: What happens if there is no ddirectorout typemap? - if ((tm = lookupDTypemap(tp, "ddirectorout"))) { + if ((tm = lookupDTypemap(n, "ddirectorout"))) { Replaceall(tm, "$dcall", upcall); - Printf(callback_code, " return %s;\n", tm); } - - Delete(tp); } else { Printf(callback_code, " %s;\n", upcall); } @@ -2285,11 +2271,9 @@ public: if (!is_void) { String *jresult_str = NewString("jresult"); String *result_str = NewString("c_result"); - Parm *tp = NewParm(returntype, result_str, n); /* Copy jresult into c_result... */ - // FIXME: lookupDTypemap? - if ((tm = Swig_typemap_lookup("directorout", tp, result_str, w))) { + if ((tm = Swig_typemap_lookup("directorout", n, result_str, w))) { Replaceall(tm, "$input", jresult_str); Replaceall(tm, "$result", result_str); Printf(w->code, "%s\n", tm); @@ -2300,7 +2284,6 @@ public: output_director = false; } - Delete(tp); Delete(jresult_str); Delete(result_str); } @@ -2365,8 +2348,7 @@ public: // We cannot directly use n here because its »type« attribute does not // the full return type any longer after Language::functionHandler has // returned. - Parm *tp = NewParm(returntype, empty_str, n); - String *dp_return_type = lookupDTypemap(tp, "dtype"); + String *dp_return_type = lookupDTypemap(n, "dtype"); if (dp_return_type) { String *dtypeout = Getattr(n, "tmap:dtype:out"); if (dtypeout) { @@ -2377,7 +2359,7 @@ public: } } else { Swig_warning(WARN_D_TYPEMAP_DTYPE_UNDEF, input_file, line_number, - "No dtype typemap defined for %s\n", SwigType_str(type, 0)); + "No dtype typemap defined for %s\n", SwigType_str(returntype, 0)); dp_return_type = NewString(""); } diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 0b5622dcd..2b67283f6 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -2853,7 +2853,6 @@ private: int classDirectorMethod(Node *n, Node *parent, String *super) { bool is_ignored = GetFlag(n, "feature:ignore") ? true : false; - 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")) { @@ -2866,18 +2865,8 @@ private: name = Getattr(n, "name"); } - 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")) { - return SWIG_OK; - } - } - Setattr(class_methods, name, NewString("")); - - if (!Getattr(n, "sym:overloaded")) { + bool overloaded = Getattr(n, "sym:overloaded") && !Getattr(n, "explicitcallnode"); + if (!overloaded) { int r = oneClassDirectorMethod(n, parent, super); if (r != SWIG_OK) { return r; @@ -2888,47 +2877,54 @@ 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; on = Getattr(on, "sym:nextSibling")) { - int r = oneClassDirectorMethod(on, parent, super); + if (!Getattr(class_methods, name)) { + for (Node *on = Getattr(n, "sym:overloaded"); on; on = Getattr(on, "sym:nextSibling")) { + // 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")); + } + } + + int r = oneClassDirectorMethod(n, parent, super); + if (r != SWIG_OK) { + return r; + } + + if (!Getattr(n, "sym:nextSibling")) + { + // Last overloaded function + Node *on = Getattr(n, "sym:overloaded"); + bool is_static = isStatic(on); + + 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(on, go_name, director_struct_name, is_static, director_struct_name, false); 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")); + String *go_upcall = NewString("Director"); + Append(go_upcall, cn); + Append(go_upcall, go_name); + r = makeDispatchFunction(on, 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); } - - 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); } + Setattr(class_methods, name, NewString("")); return SWIG_OK; } @@ -2980,17 +2976,8 @@ private: Swig_typemap_attach_parms("gotype", parms, NULL); int parm_count = emit_num_arguments(parms); - SwigType *result = Getattr(n, "returntype"); - if (!result) { - // 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); - } + SwigType *result = Getattr(n, "type"); + SwigType *returntype = result; // Save the type for overload processing. Setattr(n, "go:type", result); @@ -3177,7 +3164,8 @@ private: 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); + SwigType *rtype = Getattr(n, "classDirectorMethods:type"); + String *upcall_decl = Swig_method_decl(rtype, Getattr(n, "decl"), upcall_method_name, parms, 0, 0); Printv(f_c_directors_h, " ", upcall_decl, " {\n", NULL); Delete(upcall_decl); @@ -3450,7 +3438,7 @@ private: if (!is_ignored || is_pure_virtual) { // Declare the method for the director class. - SwigType *rtype = (Getattr(n, "conversion_operator") ? NULL : Getattr(n, "type")); + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type"); String *decl = Swig_method_decl(rtype, Getattr(n, "decl"), Getattr(n, "name"), parms, 0, 0); Printv(f_c_directors_h, " virtual ", decl, NULL); Delete(decl); @@ -3474,7 +3462,7 @@ private: Printv(w->def, " {\n", NULL); if (SwigType_type(result) != T_VOID) { - Wrapper_add_local(w, "c_result", SwigType_lstr(Getattr(n, "returntype"), "c_result")); + Wrapper_add_local(w, "c_result", SwigType_lstr(returntype, "c_result")); } if (!is_ignored) { @@ -3530,9 +3518,8 @@ private: Printv(w->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); + String *result_str = NewString("c_result"); + String *tm = Swig_typemap_lookup("directorout", n, result_str, NULL); if (!tm) { Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, "Unable to use type %s as director method result\n", SwigType_str(result, 0)); @@ -3541,13 +3528,12 @@ private: Replaceall(tm, "$input", swig_a_result); Replaceall(tm, "$result", "c_result"); Printv(w->code, " ", tm, "\n", NULL); - String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), "c_result"); + String *retstr = SwigType_rcaststr(returntype, "c_result"); Printv(w->code, " return ", retstr, ";\n", NULL); Delete(retstr); Delete(tm); } - Delete(rp); - Delete(rname); + Delete(result_str); } // The C wrapper code which calls the Go function. @@ -3605,9 +3591,8 @@ private: Printv(w->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); + String *result_str = NewString("c_result"); + String *tm = Swig_typemap_lookup("directorout", n, result_str, NULL); if (!tm) { Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, "Unable to use type %s as director method result\n", SwigType_str(result, 0)); @@ -3615,13 +3600,12 @@ private: Replaceall(tm, "$input", Swig_cresult_name()); Replaceall(tm, "$result", "c_result"); Printv(w->code, " ", tm, "\n", NULL); - String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), "c_result"); + String *retstr = SwigType_rcaststr(returntype, "c_result"); Printv(w->code, " return ", retstr, ";\n", NULL); Delete(retstr); Delete(tm); } - Delete(rp); - Delete(rname); + Delete(result_str); } } @@ -3641,7 +3625,7 @@ private: assert(is_pure_virtual); Printv(w->code, " _swig_gopanic(\"call to pure virtual function ", Getattr(parent, "sym:name"), name, "\");\n", NULL); if (SwigType_type(result) != T_VOID) { - String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), "c_result"); + String *retstr = SwigType_rcaststr(returntype, "c_result"); Printv(w->code, " return ", retstr, ";\n", NULL); Delete(retstr); } @@ -3783,7 +3767,8 @@ private: mismatch = false; bool any_void = false; for (int i = 0; i < nfunc; ++i) { - Node *ni = Getitem(dispatch, i); + Node *nn = Getitem(dispatch, i); + Node *ni = Getattr(nn, "directorNode") ? Getattr(nn, "directorNode") : nn; SwigType *result = Getattr(ni, "go:type"); assert(result); @@ -3862,7 +3847,8 @@ private: for (int i = 0; i < nfunc; ++i) { int fn = 0; - Node *ni = Getitem(dispatch, i); + Node *nn = Getitem(dispatch, i); + Node *ni = Getattr(nn, "directorNode") ? Getattr(nn, "directorNode") : nn; Parm *pi = Getattr(ni, "wrap:parms"); // If we are using a receiver, we want to ignore a leading self @@ -3892,7 +3878,8 @@ private: // 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); + Node *nnk = Getitem(dispatch, k); + Node *nk = Getattr(nnk, "directorNode") ? Getattr(nnk, "directorNode") : nnk; Parm *pk = Getattr(nk, "wrap:parms"); if (use_receiver && pk && Getattr(pk, "self")) { pk = getParm(pk); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 1c39aec11..b089a779d 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3519,7 +3519,6 @@ public: String *c_classname = Getattr(parent, "name"); String *name = Getattr(n, "name"); String *symname = Getattr(n, "sym:name"); - SwigType *type = Getattr(n, "type"); SwigType *returntype = Getattr(n, "returntype"); String *overloaded_name = getOverloadedName(n); String *storage = Getattr(n, "storage"); @@ -3616,9 +3615,7 @@ public: } /* Create the intermediate class wrapper */ - Parm *tp = NewParm(returntype, empty_str, n); - - tm = Swig_typemap_lookup("jtype", tp, "", 0); + tm = Swig_typemap_lookup("jtype", n, "", 0); if (tm) { Printf(callback_def, " public static %s %s(%s self", tm, imclass_dmethod, qualified_classname); } else { @@ -3628,7 +3625,8 @@ public: String *cdesc = NULL; SwigType *covariant = Getattr(n, "covariant"); SwigType *adjustedreturntype = covariant ? covariant : returntype; - Parm *adjustedreturntypeparm = NewParm(adjustedreturntype, empty_str, n); + Parm *adjustedreturntypeparm = NewParm(adjustedreturntype, name, n); +// Setattr(adjustedreturntypeparm, "sym:symtab", Getattr(n, "sym:symtab")); if ((tm = Swig_typemap_lookup("directorin", adjustedreturntypeparm, "", 0)) && (cdesc = Getattr(adjustedreturntypeparm, "tmap:directorin:descriptor"))) { @@ -3647,11 +3645,8 @@ public: /* Get the JNI field descriptor for this return type, add the JNI field descriptor to jniret_desc */ - - Parm *retpm = NewParm(returntype, empty_str, n); - - if ((c_ret_type = Swig_typemap_lookup("jni", retpm, "", 0))) { - Parm *tp = NewParm(c_ret_type, empty_str, n); + if ((c_ret_type = Swig_typemap_lookup("jni", n, "", 0))) { + Parm *tp = NewParm(c_ret_type, name, n); if (!is_void && !ignored_method) { String *jretval_decl = NewStringf("%s jresult", c_ret_type); @@ -3685,7 +3680,6 @@ public: } Delete(adjustedreturntypeparm); - Delete(retpm); Delete(qualified_classname); } @@ -3755,7 +3749,7 @@ public: } else { Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, "No or improper directorin typemap for type %s for use in %s::%s (skipping director method)\n", - SwigType_str(type, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); + SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); output_director = false; } @@ -3879,7 +3873,6 @@ public: output_director = false; } - Delete(tp); } else { Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s for use in %s::%s (skipping director method)\n", SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); @@ -3894,7 +3887,7 @@ public: /* header declaration, start wrapper definition */ String *target; - SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type"); target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); Printf(w->def, "%s", target); Delete(qualified_name); @@ -3944,21 +3937,18 @@ public: addThrows(n, "feature:except", n); if (!is_void) { - Parm *tp = NewParm(returntype, empty_str, n); - - if ((tm = Swig_typemap_lookup("javadirectorout", tp, "", 0))) { - addThrows(n, "tmap:javadirectorout", tp); + if ((tm = Swig_typemap_lookup("javadirectorout", n, "", 0))) { + addThrows(n, "tmap:javadirectorout", n); substituteClassname(returntype, tm); Replaceall(tm, "$javacall", upcall); Printf(callback_code, " return %s;\n", tm); } - if ((tm = Swig_typemap_lookup("out", tp, "", 0))) - addThrows(n, "tmap:out", tp); + if ((tm = Swig_typemap_lookup("out", n, "", 0))) + addThrows(n, "tmap:out", n); Delete(tm); - Delete(tp); } else Printf(callback_code, " %s;\n", upcall); @@ -3988,11 +3978,10 @@ public: if (!is_void) { String *jresult_str = NewString("jresult"); String *result_str = NewString("c_result"); - Parm *tp = NewParm(returntype, result_str, n); /* Copy jresult into c_result... */ - if ((tm = Swig_typemap_lookup("directorout", tp, result_str, w))) { - addThrows(n, "tmap:directorout", tp); + if ((tm = Swig_typemap_lookup("directorout", n, result_str, w))) { + addThrows(n, "tmap:directorout", n); Replaceall(tm, "$input", jresult_str); Replaceall(tm, "$result", result_str); Printf(w->code, "%s\n", tm); @@ -4003,7 +3992,6 @@ public: output_director = false; } - Delete(tp); Delete(jresult_str); Delete(result_str); } diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 6fa9defd9..ff1dc08d0 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2041,9 +2041,12 @@ int Language::classDirectorMethods(Node *n) { if (!Cmp(type, "destructor")) { classDirectorDestructor(method); } else { - if (classDirectorMethod(method, n, fqdname) == SWIG_OK) { - Setattr(item, "director", "1"); - } + Swig_require("classDirectorMethods", method, "*type", NIL); + assert(Getattr(method, "returntype")); + Setattr(method, "type", Getattr(method, "returntype")); + if (classDirectorMethod(method, n, fqdname) == SWIG_OK) + SetFlag(item, "director"); + Swig_restore(method); } } diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index 8f314c964..0ced94e83 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -1380,63 +1380,41 @@ public: int classDirectorMethod(Node *n, Node *parent, String *super) { int is_void = 0; int is_pointer = 0; - String *storage; - String *value; - String *decl; - String *type; - String *name; - String *classname; + String *storage = Getattr(n, "storage"); + String *value = Getattr(n, "value"); + String *decl = Getattr(n, "decl"); + String *return_type = Getattr(n, "type"); + String *name = Getattr(n, "name"); + String *classname = Getattr(parent, "sym:name"); String *c_classname = Getattr(parent, "name"); String *symname = Getattr(n, "sym:name"); - String *declaration; - ParmList *l; - Wrapper *w; + String *declaration = NewString(""); + ParmList *l = Getattr(n, "parms"); + Wrapper *w = NewWrapper(); String *tm; String *wrap_args = NewString(""); - String *return_type; int status = SWIG_OK; int idx; bool pure_virtual = false; bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; - storage = Getattr(n, "storage"); - value = Getattr(n, "value"); - classname = Getattr(parent, "sym:name"); - type = Getattr(n, "type"); - name = Getattr(n, "name"); - if (Cmp(storage, "virtual") == 0) { if (Cmp(value, "0") == 0) { pure_virtual = true; } } - w = NewWrapper(); - declaration = NewString(""); Wrapper_add_local(w, "swig_result", "CAMLparam0();\n" "SWIG_CAMLlocal2(swig_result,args)"); /* determine if the method returns a pointer */ - decl = Getattr(n, "decl"); is_pointer = SwigType_ispointer_return(decl); - is_void = (!Cmp(type, "void") && !is_pointer); - - /* form complete return type */ - return_type = Copy(type); - { - SwigType *t = Copy(decl); - SwigType *f = 0; - f = SwigType_pop_function(t); - SwigType_push(return_type, t); - Delete(f); - Delete(t); - } + is_void = (!Cmp(return_type, "void") && !is_pointer); /* virtual method definition */ - l = Getattr(n, "parms"); String *target; String *pclassname = NewStringf("SwigDirector_%s", classname); String *qualified_name = NewStringf("%s::%s", pclassname, name); - SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type"); target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); Printf(w->def, "%s {", target); Delete(qualified_name); @@ -1616,16 +1594,7 @@ public: idx = 0; - /* this seems really silly. the node's type excludes - * qualifier/pointer/reference markers, which have to be retrieved - * from the decl field to construct return_type. but the typemap - * lookup routine uses the node's type, so we have to swap in and - * out the correct type. it's not just me, similar silliness also - * occurs in Language::cDeclaration(). - */ - Setattr(n, "type", return_type); tm = Swig_typemap_lookup("directorout", n, "c_result", w); - Setattr(n, "type", type); if (tm != 0) { Replaceall(tm, "$input", "swig_result"); /* TODO check this */ @@ -1704,7 +1673,6 @@ public: /* clean up */ Delete(wrap_args); - Delete(return_type); Delete(pclassname); DelWrapper(w); return status; diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 1b8156b33..2b4d16db2 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -1247,18 +1247,17 @@ public: int classDirectorMethod(Node *n, Node *parent, String *super) { int is_void = 0; int is_pointer = 0; - String *decl; - String *type; - String *name; - String *classname; + String *decl = Getattr(n, "decl"); + String *return_type = Getattr(n, "type"); + String *name = Getattr(n, "name"); + String *classname = Getattr(parent, "sym:name"); String *c_classname = Getattr(parent, "name"); String *symname = Getattr(n, "sym:name"); - String *declaration; - ParmList *l; - Wrapper *w; + String *declaration = NewString(""); + ParmList *l = Getattr(n, "parms"); + Wrapper *w = NewWrapper(); String *tm; String *wrap_args = NewString(""); - String *return_type; String *value = Getattr(n, "value"); String *storage = Getattr(n, "storage"); bool pure_virtual = false; @@ -1272,35 +1271,15 @@ public: } } - classname = Getattr(parent, "sym:name"); - type = Getattr(n, "type"); - name = Getattr(n, "name"); - - w = NewWrapper(); - declaration = NewString(""); - // determine if the method returns a pointer - decl = Getattr(n, "decl"); is_pointer = SwigType_ispointer_return(decl); - is_void = (!Cmp(type, "void") && !is_pointer); - - // form complete return type - return_type = Copy(type); - { - SwigType *t = Copy(decl); - SwigType *f = 0; - f = SwigType_pop_function(t); - SwigType_push(return_type, t); - Delete(f); - Delete(t); - } + is_void = (!Cmp(return_type, "void") && !is_pointer); // virtual method definition - l = Getattr(n, "parms"); String *target; String *pclassname = NewStringf("SwigDirector_%s", classname); String *qualified_name = NewStringf("%s::%s", pclassname, name); - SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type"); target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); Printf(w->def, "%s", target); Delete(qualified_name); @@ -1449,9 +1428,7 @@ public: "method %s.%s failed to return the required number " "of arguments.\");\n", classname, method_name); Printf(w->code, "}\n"); - Setattr(n, "type", return_type); tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); - Setattr(n, "type", type); if (tm != 0) { char temp[24]; sprintf(temp, "out(%d)", idx); @@ -1531,7 +1508,6 @@ public: } // clean up Delete(wrap_args); - Delete(return_type); Delete(pclassname); DelWrapper(w); return status; diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 70b6e41ef..f47c878af 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2415,18 +2415,17 @@ done: int classDirectorMethod(Node *n, Node *parent, String *super) { int is_void = 0; int is_pointer = 0; - String *decl; - String *type; - String *name; - String *classname; + String *decl = Getattr(n, "decl"); + String *return_type = Getattr(n, "type"); + String *name = Getattr(n, "name"); + String *classname = Getattr(parent, "sym:name"); String *c_classname = Getattr(parent, "name"); String *symname = Getattr(n, "sym:name"); - String *declaration; - ParmList *l; - Wrapper *w; + String *declaration = NewStringEmpty(); + ParmList *l = Getattr(n, "parms"); + Wrapper *w = NewWrapper(); String *tm; String *wrap_args = NewStringEmpty(); - String *return_type; String *value = Getattr(n, "value"); String *storage = Getattr(n, "storage"); bool pure_virtual = false; @@ -2440,34 +2439,15 @@ done: } } - classname = Getattr(parent, "sym:name"); - type = Getattr(n, "type"); - name = Getattr(n, "name"); - - w = NewWrapper(); - declaration = NewStringEmpty(); - /* determine if the method returns a pointer */ - decl = Getattr(n, "decl"); is_pointer = SwigType_ispointer_return(decl); - is_void = (Cmp(type, "void") == 0 && !is_pointer); - - /* form complete return type */ - return_type = Copy(type); - { - SwigType *t = Copy(decl); - SwigType *f = SwigType_pop_function(t); - SwigType_push(return_type, t); - Delete(f); - Delete(t); - } + is_void = (Cmp(return_type, "void") == 0 && !is_pointer); /* virtual method definition */ - l = Getattr(n, "parms"); String *target; String *pclassname = NewStringf("SwigDirector_%s", classname); String *qualified_name = NewStringf("%s::%s", pclassname, name); - SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type"); target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); Printf(w->def, "%s", target); Delete(qualified_name); @@ -2651,16 +2631,7 @@ done: /* marshal return value */ if (!is_void) { - /* this seems really silly. the node's type excludes - * qualifier/pointer/reference markers, which have to be retrieved - * from the decl field to construct return_type. but the typemap - * lookup routine uses the node's type, so we have to swap in and - * out the correct type. it's not just me, similar silliness also - * occurs in Language::cDeclaration(). - */ - Setattr(n, "type", return_type); tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); - Setattr(n, "type", type); if (tm != 0) { static const String *amp_result = NewStringf("&%s", Swig_cresult_name()); Replaceall(tm, "$input", amp_result); @@ -2749,7 +2720,6 @@ done: /* clean up */ Delete(wrap_args); - Delete(return_type); Delete(pclassname); DelWrapper(w); return status; diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index c180b4a79..0cc843c74 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -4528,18 +4528,17 @@ int PYTHON::classDirectorMethods(Node *n) { int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { int is_void = 0; int is_pointer = 0; - String *decl; - String *type; - String *name; - String *classname; + String *decl = Getattr(n, "decl"); + String *name = Getattr(n, "name"); + String *classname = Getattr(parent, "sym:name"); String *c_classname = Getattr(parent, "name"); String *symname = Getattr(n, "sym:name"); - String *declaration; - ParmList *l; - Wrapper *w; + String *declaration = NewString(""); + ParmList *l = Getattr(n, "parms"); + Wrapper *w = NewWrapper(); String *tm; String *wrap_args = NewString(""); - String *return_type; + String *return_type = Getattr(n, "type"); String *value = Getattr(n, "value"); String *storage = Getattr(n, "storage"); bool pure_virtual = false; @@ -4553,35 +4552,15 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { } } - classname = Getattr(parent, "sym:name"); - type = Getattr(n, "type"); - name = Getattr(n, "name"); - - w = NewWrapper(); - declaration = NewString(""); - /* determine if the method returns a pointer */ - decl = Getattr(n, "decl"); is_pointer = SwigType_ispointer_return(decl); - is_void = (!Cmp(type, "void") && !is_pointer); - - /* form complete return type */ - return_type = Copy(type); - { - SwigType *t = Copy(decl); - SwigType *f = 0; - f = SwigType_pop_function(t); - SwigType_push(return_type, t); - Delete(f); - Delete(t); - } + is_void = (!Cmp(return_type, "void") && !is_pointer); /* virtual method definition */ - l = Getattr(n, "parms"); String *target; String *pclassname = NewStringf("SwigDirector_%s", classname); String *qualified_name = NewStringf("%s::%s", pclassname, name); - SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type"); target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); Printf(w->def, "%s", target); Delete(qualified_name); @@ -4898,16 +4877,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { /* marshal return value */ if (!is_void) { - /* this seems really silly. the node's type excludes - * qualifier/pointer/reference markers, which have to be retrieved - * from the decl field to construct return_type. but the typemap - * lookup routine uses the node's type, so we have to swap in and - * out the correct type. it's not just me, similar silliness also - * occurs in Language::cDeclaration(). - */ - Setattr(n, "type", return_type); tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); - Setattr(n, "type", type); if (tm != 0) { if (outputs > 1) { Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++); @@ -5009,7 +4979,6 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { /* clean up */ Delete(wrap_args); - Delete(return_type); Delete(pclassname); DelWrapper(w); return status; diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index f778b0af5..bc4e785e6 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -3017,18 +3017,17 @@ public: virtual int classDirectorMethod(Node *n, Node *parent, String *super) { int is_void = 0; int is_pointer = 0; - String *decl; - String *type; - String *name; - String *classname; + String *decl = Getattr(n, "decl"); + String *name = Getattr(n, "name"); + String *classname = Getattr(parent, "sym:name"); String *c_classname = Getattr(parent, "name"); String *symname = Getattr(n, "sym:name"); - String *declaration; - ParmList *l; - Wrapper *w; + String *declaration = NewString(""); + ParmList *l = Getattr(n, "parms"); + Wrapper *w = NewWrapper(); String *tm; String *wrap_args = NewString(""); - String *return_type; + String *return_type = Getattr(n, "type"); Parm *p; String *value = Getattr(n, "value"); String *storage = Getattr(n, "storage"); @@ -3049,35 +3048,15 @@ public: Printf(overnametmp, "::%s", Getattr(n, "sym:overname")); } - classname = Getattr(parent, "sym:name"); - type = Getattr(n, "type"); - name = Getattr(n, "name"); - - w = NewWrapper(); - declaration = NewString(""); - /* determine if the method returns a pointer */ - decl = Getattr(n, "decl"); is_pointer = SwigType_ispointer_return(decl); - is_void = (!Cmp(type, "void") && !is_pointer); - - /* form complete return type */ - return_type = Copy(type); - { - SwigType *t = Copy(decl); - SwigType *f = 0; - f = SwigType_pop_function(t); - SwigType_push(return_type, t); - Delete(f); - Delete(t); - } + is_void = (!Cmp(return_type, "void") && !is_pointer); /* virtual method definition */ - l = Getattr(n, "parms"); String *target; String *pclassname = NewStringf("SwigDirector_%s", classname); String *qualified_name = NewStringf("%s::%s", pclassname, name); - SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type"); target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); Printf(w->def, "%s", target); Delete(qualified_name); @@ -3295,14 +3274,7 @@ public: /* Marshal return value */ if (!is_void) { - /* This seems really silly. The node's type excludes qualifier/pointer/reference markers, - * which have to be retrieved from the decl field to construct return_type. But the typemap - * lookup routine uses the node's type, so we have to swap in and out the correct type. - * It's not just me, similar silliness also occurs in Language::cDeclaration(). - */ - Setattr(n, "type", return_type); tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); - Setattr(n, "type", type); if (tm != 0) { if (outputs > 1 && !asvoid ) { Printf(w->code, "output = rb_ary_entry(%s, %d);\n", Swig_cresult_name(), idx++); @@ -3390,7 +3362,6 @@ public: /* clean up */ Delete(wrap_args); - Delete(return_type); Delete(pclassname); DelWrapper(w); return status; From b1ee062d2a62e29a5d71ea1cb6bf2371f4c8656e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 27 Oct 2012 17:38:05 +0000 Subject: [PATCH 0232/1160] Cosmetic variable renaming for consistency across language modules git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13874 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/directors.cxx | 8 ++++---- Source/Modules/go.cxx | 9 ++++----- Source/Modules/java.cxx | 2 +- Source/Modules/ocaml.cxx | 12 ++++++------ Source/Modules/octave.cxx | 12 ++++++------ Source/Modules/php.cxx | 12 ++++++------ Source/Modules/python.cxx | 12 ++++++------ Source/Modules/ruby.cxx | 12 ++++++------ 8 files changed, 39 insertions(+), 40 deletions(-) diff --git a/Source/Modules/directors.cxx b/Source/Modules/directors.cxx index af1798b8b..7f4c8d9d1 100644 --- a/Source/Modules/directors.cxx +++ b/Source/Modules/directors.cxx @@ -132,7 +132,7 @@ String *Swig_method_call(const_String_or_char_ptr name, ParmList *parms) { * */ -String *Swig_method_decl(SwigType *returntype, SwigType *decl, const_String_or_char_ptr id, List *args, int strip, int values) { +String *Swig_method_decl(SwigType *rettype, SwigType *decl, const_String_or_char_ptr id, List *args, int strip, int values) { String *result; List *elements; String *element = 0, *nextelement; @@ -203,7 +203,7 @@ String *Swig_method_decl(SwigType *returntype, SwigType *decl, const_String_or_c Append(result, ", "); } Append(result, ")"); - } else if (returntype) { // This check is intended for conversion operators to a pointer/reference which needs the pointer/reference ignoring in the declaration + } else if (rettype) { // This check is intended for conversion operators to a pointer/reference which needs the pointer/reference ignoring in the declaration if (SwigType_ispointer(element)) { Insert(result, 0, "*"); if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { @@ -256,9 +256,9 @@ String *Swig_method_decl(SwigType *returntype, SwigType *decl, const_String_or_c Chop(result); - if (returntype) { + if (rettype) { Insert(result, 0, " "); - String *rtype = SwigType_str(returntype, 0); + String *rtype = SwigType_str(rettype, 0); Insert(result, 0, rtype); Delete(rtype); } diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 2b67283f6..23fd6f560 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -2977,7 +2977,6 @@ private: int parm_count = emit_num_arguments(parms); SwigType *result = Getattr(n, "type"); - SwigType *returntype = result; // Save the type for overload processing. Setattr(n, "go:type", result); @@ -3462,7 +3461,7 @@ private: Printv(w->def, " {\n", NULL); if (SwigType_type(result) != T_VOID) { - Wrapper_add_local(w, "c_result", SwigType_lstr(returntype, "c_result")); + Wrapper_add_local(w, "c_result", SwigType_lstr(result, "c_result")); } if (!is_ignored) { @@ -3528,7 +3527,7 @@ private: Replaceall(tm, "$input", swig_a_result); Replaceall(tm, "$result", "c_result"); Printv(w->code, " ", tm, "\n", NULL); - String *retstr = SwigType_rcaststr(returntype, "c_result"); + String *retstr = SwigType_rcaststr(result, "c_result"); Printv(w->code, " return ", retstr, ";\n", NULL); Delete(retstr); Delete(tm); @@ -3600,7 +3599,7 @@ private: Replaceall(tm, "$input", Swig_cresult_name()); Replaceall(tm, "$result", "c_result"); Printv(w->code, " ", tm, "\n", NULL); - String *retstr = SwigType_rcaststr(returntype, "c_result"); + String *retstr = SwigType_rcaststr(result, "c_result"); Printv(w->code, " return ", retstr, ";\n", NULL); Delete(retstr); Delete(tm); @@ -3625,7 +3624,7 @@ private: assert(is_pure_virtual); Printv(w->code, " _swig_gopanic(\"call to pure virtual function ", Getattr(parent, "sym:name"), name, "\");\n", NULL); if (SwigType_type(result) != T_VOID) { - String *retstr = SwigType_rcaststr(returntype, "c_result"); + String *retstr = SwigType_rcaststr(result, "c_result"); Printv(w->code, " return ", retstr, ";\n", NULL); Delete(retstr); } diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index b089a779d..d9964edd8 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3519,7 +3519,7 @@ public: String *c_classname = Getattr(parent, "name"); String *name = Getattr(n, "name"); String *symname = Getattr(n, "sym:name"); - SwigType *returntype = Getattr(n, "returntype"); + SwigType *returntype = Getattr(n, "type"); String *overloaded_name = getOverloadedName(n); String *storage = Getattr(n, "storage"); String *value = Getattr(n, "value"); diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index 0ced94e83..4a2071e32 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -1383,7 +1383,7 @@ public: String *storage = Getattr(n, "storage"); String *value = Getattr(n, "value"); String *decl = Getattr(n, "decl"); - String *return_type = Getattr(n, "type"); + String *returntype = Getattr(n, "type"); String *name = Getattr(n, "name"); String *classname = Getattr(parent, "sym:name"); String *c_classname = Getattr(parent, "name"); @@ -1408,7 +1408,7 @@ public: /* determine if the method returns a pointer */ is_pointer = SwigType_ispointer_return(decl); - is_void = (!Cmp(return_type, "void") && !is_pointer); + is_void = (!Cmp(returntype, "void") && !is_pointer); /* virtual method definition */ String *target; @@ -1430,7 +1430,7 @@ public: */ if (!is_void) { if (!(ignored_method && !pure_virtual)) { - Wrapper_add_localv(w, "c_result", SwigType_lstr(return_type, "c_result"), NIL); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); } } @@ -1629,15 +1629,15 @@ public: if (!(ignored_method && !pure_virtual)) { /* A little explanation: * The director_enum test case makes a method whose return type - * is an enum type. return_type here is "int". gcc complains + * is an enum type. returntype here is "int". gcc complains * about an implicit enum conversion, and although i don't strictly * agree with it, I'm working on fixing the error: * * Below is what I came up with. It's not great but it should * always essentially work. */ - if (!SwigType_isreference(return_type)) { - Printf(w->code, "CAMLreturn_type((%s)c_result);\n", SwigType_lstr(return_type, "")); + if (!SwigType_isreference(returntype)) { + Printf(w->code, "CAMLreturn_type((%s)c_result);\n", SwigType_lstr(returntype, "")); } else { Printf(w->code, "CAMLreturn_type(*c_result);\n"); } diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 2b4d16db2..ef1629324 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -1248,7 +1248,7 @@ public: int is_void = 0; int is_pointer = 0; String *decl = Getattr(n, "decl"); - String *return_type = Getattr(n, "type"); + String *returntype = Getattr(n, "type"); String *name = Getattr(n, "name"); String *classname = Getattr(parent, "sym:name"); String *c_classname = Getattr(parent, "name"); @@ -1273,7 +1273,7 @@ public: // determine if the method returns a pointer is_pointer = SwigType_ispointer_return(decl); - is_void = (!Cmp(return_type, "void") && !is_pointer); + is_void = (!Cmp(returntype, "void") && !is_pointer); // virtual method definition String *target; @@ -1327,7 +1327,7 @@ public: // handle it, including declaration of c_result ($result). if (!is_void) { if (!(ignored_method && !pure_virtual)) { - String *cres = SwigType_lstr(return_type, "c_result"); + String *cres = SwigType_lstr(returntype, "c_result"); Printf(w->code, "%s;\n", cres); Delete(cres); } @@ -1444,7 +1444,7 @@ public: } else { Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, "Unable to use return type %s in director method %s::%s (skipping method).\n", - SwigType_str(return_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); + SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); status = SWIG_ERROR; } } @@ -1471,8 +1471,8 @@ public: if (!is_void) { if (!(ignored_method && !pure_virtual)) { - String *rettype = SwigType_str(return_type, 0); - if (!SwigType_isreference(return_type)) { + String *rettype = SwigType_str(returntype, 0); + if (!SwigType_isreference(returntype)) { Printf(w->code, "return (%s) c_result;\n", rettype); } else { Printf(w->code, "return (%s) *c_result;\n", rettype); diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index f47c878af..d89d61da4 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2416,7 +2416,7 @@ done: int is_void = 0; int is_pointer = 0; String *decl = Getattr(n, "decl"); - String *return_type = Getattr(n, "type"); + String *returntype = Getattr(n, "type"); String *name = Getattr(n, "name"); String *classname = Getattr(parent, "sym:name"); String *c_classname = Getattr(parent, "name"); @@ -2441,7 +2441,7 @@ done: /* determine if the method returns a pointer */ is_pointer = SwigType_ispointer_return(decl); - is_void = (Cmp(return_type, "void") == 0 && !is_pointer); + is_void = (Cmp(returntype, "void") == 0 && !is_pointer); /* virtual method definition */ String *target; @@ -2497,7 +2497,7 @@ done: */ if (!is_void) { if (!(ignored_method && !pure_virtual)) { - String *cres = SwigType_lstr(return_type, "c_result"); + String *cres = SwigType_lstr(returntype, "c_result"); Printf(w->code, "%s;\n", cres); Delete(cres); } @@ -2650,7 +2650,7 @@ done: Delete(tm); } else { Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname), + "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); status = SWIG_ERROR; } @@ -2677,8 +2677,8 @@ done: if (!is_void) { if (!(ignored_method && !pure_virtual)) { - String *rettype = SwigType_str(return_type, 0); - if (!SwigType_isreference(return_type)) { + String *rettype = SwigType_str(returntype, 0); + if (!SwigType_isreference(returntype)) { Printf(w->code, "return (%s) c_result;\n", rettype); } else { Printf(w->code, "return (%s) *c_result;\n", rettype); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 0cc843c74..97b0c4f8d 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -4538,7 +4538,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { Wrapper *w = NewWrapper(); String *tm; String *wrap_args = NewString(""); - String *return_type = Getattr(n, "type"); + String *returntype = Getattr(n, "type"); String *value = Getattr(n, "value"); String *storage = Getattr(n, "storage"); bool pure_virtual = false; @@ -4554,7 +4554,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { /* determine if the method returns a pointer */ is_pointer = SwigType_ispointer_return(decl); - is_void = (!Cmp(return_type, "void") && !is_pointer); + is_void = (!Cmp(returntype, "void") && !is_pointer); /* virtual method definition */ String *target; @@ -4608,7 +4608,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { */ if (!is_void) { if (!(ignored_method && !pure_virtual)) { - String *cres = SwigType_lstr(return_type, "c_result"); + String *cres = SwigType_lstr(returntype, "c_result"); Printf(w->code, "%s;\n", cres); Delete(cres); } @@ -4903,7 +4903,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { Delete(tm); } else { Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname), + "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); status = SWIG_ERROR; } @@ -4940,8 +4940,8 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { if (!is_void) { if (!(ignored_method && !pure_virtual)) { - String *rettype = SwigType_str(return_type, 0); - if (!SwigType_isreference(return_type)) { + String *rettype = SwigType_str(returntype, 0); + if (!SwigType_isreference(returntype)) { Printf(w->code, "return (%s) c_result;\n", rettype); } else { Printf(w->code, "return (%s) *c_result;\n", rettype); diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index bc4e785e6..276b967f3 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -3027,7 +3027,7 @@ public: Wrapper *w = NewWrapper(); String *tm; String *wrap_args = NewString(""); - String *return_type = Getattr(n, "type"); + String *returntype = Getattr(n, "type"); Parm *p; String *value = Getattr(n, "value"); String *storage = Getattr(n, "storage"); @@ -3050,7 +3050,7 @@ public: /* determine if the method returns a pointer */ is_pointer = SwigType_ispointer_return(decl); - is_void = (!Cmp(return_type, "void") && !is_pointer); + is_void = (!Cmp(returntype, "void") && !is_pointer); /* virtual method definition */ String *target; @@ -3107,7 +3107,7 @@ public: */ if (!is_void) { if (!(ignored_method && !pure_virtual)) { - Wrapper_add_localv(w, "c_result", SwigType_lstr(return_type, "c_result"), NIL); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); } } @@ -3292,7 +3292,7 @@ public: Printv(w->code, tm, "\n", NIL); } else { Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), + "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); status = SWIG_ERROR; } @@ -3323,8 +3323,8 @@ public: /* any existing helper functions to handle this? */ if (!is_void) { if (!(ignored_method && !pure_virtual)) { - String *rettype = SwigType_str(return_type, 0); - if (!SwigType_isreference(return_type)) { + String *rettype = SwigType_str(returntype, 0); + if (!SwigType_isreference(returntype)) { Printf(w->code, "return (%s) c_result;\n", rettype); } else { Printf(w->code, "return (%s) *c_result;\n", rettype); From 786d883d45c68a3feb2f3d69cce0845069533c7f Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 30 Oct 2012 23:38:57 +0000 Subject: [PATCH 0233/1160] Fix Go support for enums to work correctly when Go int type is 64 bits. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13875 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/go/go.swg | 14 +++++++++++++- Source/Modules/go.cxx | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Lib/go/go.swg b/Lib/go/go.swg index 82f0b91f6..cc3beef7d 100644 --- a/Lib/go/go.swg +++ b/Lib/go/go.swg @@ -366,7 +366,7 @@ %{ $1 = ($1_ltype)$input; %} %typemap(out) enum SWIGTYPE -%{ $result = $1; %} +%{ $result = (intgo)$1; %} %typemap(directorin) enum SWIGTYPE %{ $input = ($1_ltype)$1; %} @@ -374,6 +374,18 @@ %typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %} +%typemap(directorin) enum SWIGTYPE & (intgo e) +%{ + e = (intgo)$1; + $input = &e; +%} + +%typemap(directorout) enum SWIGTYPE & +%{ + $*1_ltype f = ($*1_ltype)*$input; + $result = ($1_ltype)&f; +%} + /* 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. */ diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 23fd6f560..127e7c239 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -4709,6 +4709,11 @@ private: Delete(q); } } + + if (Language::enumLookup(t) != NULL || Strcmp(t, "enum ") == 0) { + is_int = true; + } + Delete(t); if (is_int8) { ret = NewString("char "); From ab7da898ef4fead8e6914c786a48223fe145f764 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 31 Oct 2012 03:41:10 +0000 Subject: [PATCH 0234/1160] Define uintgo for the benefit of Go .swig files. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13876 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/go/goruntime.swg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index f27bbae5e..4b7daf41f 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -16,14 +16,17 @@ #if SWIGGO_INTGO_SIZE == 32 %insert(runtime) %{ typedef int intgo; +typedef unsigned int uintgo; %} #elif SWIGGO_INTGO_SIZE == 64 %insert(runtime) %{ typedef long long intgo; +typedef unsigned long long uintgo; %} #else %insert(runtime) %{ typedef ptrdiff_t intgo; +typedef size_t uintgo; %} #endif From 0ca11c8b6fce3d974a53b2e4aa86b84157ff0ef5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 9 Nov 2012 17:57:42 +0000 Subject: [PATCH 0235/1160] Fix overflow with parameters > LONG_MAX with Python 3. The typemap incorrectly called PyInt_AsLong() if PyInt_Check() passed, but this check is the same as PyLong_Check() for Python 3 and so the correct PyLong_AsUnsignedLong() function was never called. As a consequence, passing any value greater than LONG_MAX (e.g. 0x87654321 on 32 bit architectures) to a function taking unsigned int, unsigned long or size_t parameter failed with an overflow error being generated. Fix this by simply disabling the part of the code dealing with PyInts for Python 3 as there is no distinction between PyInt and PyLong there any more. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13877 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Lib/python/pyprimtypes.swg | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index d36e76d62..913951fec 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.9 (in progress) =========================== + +2012-11-09: vzeitlin + [Python] Fix overflow when passing values greater than LONG_MAX from Python 3 for parameters with unsigned long C type. + 2012-10-26: wsfulton Fix director typemap searching so that a typemap specified with a name will be correctly matched. Previously the name was ignored during the typemap search. Applies to the following list of typemaps: diff --git a/Lib/python/pyprimtypes.swg b/Lib/python/pyprimtypes.swg index 290f9312f..3fbd86a21 100644 --- a/Lib/python/pyprimtypes.swg +++ b/Lib/python/pyprimtypes.swg @@ -109,6 +109,7 @@ SWIG_From_dec(unsigned long)(unsigned long value) SWIGINTERN int SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val) { +%#if PY_VERSION_HEX < 0x03000000 if (PyInt_Check(obj)) { long v = PyInt_AsLong(obj); if (v >= 0) { @@ -117,7 +118,9 @@ SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val) } else { return SWIG_OverflowError; } - } else if (PyLong_Check(obj)) { + } else +%#endif + if (PyLong_Check(obj)) { unsigned long v = PyLong_AsUnsignedLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; From 421139a5feb500e6d74a457801df55a67fe96802 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 13 Nov 2012 22:16:28 +0000 Subject: [PATCH 0236/1160] Fix some subtle named output typemap lookup misses, the fully qualified name was not always being in all cases such as member variables git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13878 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 21 +++++++++++++++++++++ Source/Modules/java.cxx | 10 ++++------ Source/Modules/lang.cxx | 7 ++++++- Source/Modules/r.cxx | 2 +- Source/Swig/parms.c | 22 ++++++++++++++++++---- Source/Swig/swigparm.h | 3 ++- Source/Swig/typemap.c | 10 ++++++++++ 7 files changed, 62 insertions(+), 13 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 913951fec..17e4f76e4 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -8,6 +8,27 @@ Version 2.0.9 (in progress) 2012-11-09: vzeitlin [Python] Fix overflow when passing values greater than LONG_MAX from Python 3 for parameters with unsigned long C type. +2012-11-02: wsfulton + Fix some subtle named output typemap lookup misses, the fully qualified name was not always being + used for variables, for example: + + struct Glob { + int MyVar; + }; + + Previously the search rules (as shown by -debug-tmsearch) for the getter wrapper were: + + example.i:44: Searching for a suitable 'out' typemap for: int MyVar + Looking for: int MyVar + Looking for: int + + Now the scope is named correctly: + + example.i:44: Searching for a suitable 'out' typemap for: int Glob::MyVar + Looking for: int Glob::MyVar + Looking for: int MyVar + Looking for: int + 2012-10-26: wsfulton Fix director typemap searching so that a typemap specified with a name will be correctly matched. Previously the name was ignored during the typemap search. Applies to the following list of typemaps: diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index d9964edd8..6e9ee54b2 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3514,7 +3514,6 @@ public: * --------------------------------------------------------------- */ int classDirectorMethod(Node *n, Node *parent, String *super) { - String *empty_str = NewString(""); String *classname = Getattr(parent, "sym:name"); String *c_classname = Getattr(parent, "name"); String *name = Getattr(n, "name"); @@ -3625,8 +3624,7 @@ public: String *cdesc = NULL; SwigType *covariant = Getattr(n, "covariant"); SwigType *adjustedreturntype = covariant ? covariant : returntype; - Parm *adjustedreturntypeparm = NewParm(adjustedreturntype, name, n); -// Setattr(adjustedreturntypeparm, "sym:symtab", Getattr(n, "sym:symtab")); + Parm *adjustedreturntypeparm = NewParmNode(adjustedreturntype, n); if ((tm = Swig_typemap_lookup("directorin", adjustedreturntypeparm, "", 0)) && (cdesc = Getattr(adjustedreturntypeparm, "tmap:directorin:descriptor"))) { @@ -3646,7 +3644,7 @@ public: /* Get the JNI field descriptor for this return type, add the JNI field descriptor to jniret_desc */ if ((c_ret_type = Swig_typemap_lookup("jni", n, "", 0))) { - Parm *tp = NewParm(c_ret_type, name, n); + Parm *tp = NewParmNode(c_ret_type, n); if (!is_void && !ignored_method) { String *jretval_decl = NewStringf("%s jresult", c_ret_type); @@ -3737,7 +3735,7 @@ public: } /* Start the Java field descriptor for the intermediate class's upcall (insert self object) */ - Parm *tp = NewParm(c_classname, empty_str, n); + Parm *tp = NewParmNode(c_classname, n); String *jdesc; if ((tm = Swig_typemap_lookup("directorin", tp, "", 0)) @@ -3779,7 +3777,7 @@ public: /* Get parameter's intermediary C type */ if ((c_param_type = Getattr(p, "tmap:jni"))) { - Parm *tp = NewParm(c_param_type, empty_str, n); + Parm *tp = NewParm(c_param_type, Getattr(p, "name"), n); String *desc_tm = NULL, *jdesc = NULL, *cdesc = NULL; /* Add to local variables */ diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index ff1dc08d0..297e245f3 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1419,7 +1419,12 @@ int Language::membervariableHandler(Node *n) { target = NewStringf("%s->%s", pname, name); Delete(pname); } - tm = Swig_typemap_lookup("memberin", n, target, 0); + + // This is an input type typemap lookup and so it should not use Node n + // otherwise qualification is done on the parameter name for the setter function + Parm *nin = NewParm(type, name, n); + tm = Swig_typemap_lookup("memberin", nin, target, 0); + Delete(nin); } int flags = Extend | SmartPointer | use_naturalvar_mode(n); if (isNonVirtualProtectedAccess(n)) diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 14da3a975..94e6ed4bd 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -682,7 +682,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) { XXX Have to be a little more clever so that we can deal with struct A * - the * is getting lost. Is this still true? If so, will a SwigType_push() solve things? */ - Parm *bbase = NewParm(rettype, Swig_cresult_name(), n); + Parm *bbase = NewParmNode(rettype, n); String *returnTM = Swig_typemap_lookup("in", bbase, Swig_cresult_name(), f); if(returnTM) { String *tm = returnTM; diff --git a/Source/Swig/parms.c b/Source/Swig/parms.c index 283a2f5c2..0f4d17b73 100644 --- a/Source/Swig/parms.c +++ b/Source/Swig/parms.c @@ -19,13 +19,13 @@ char cvsroot_parms_c[] = "$Id$"; * NewParm() * * Create a new parameter from datatype 'type' and name 'name' copying - * the file and line number from the Node file_line_node. + * the file and line number from the Node from_node. * ------------------------------------------------------------------------ */ -Parm *NewParm(SwigType *type, const_String_or_char_ptr name, Node *file_line_node) { +Parm *NewParm(SwigType *type, const_String_or_char_ptr name, Node *from_node) { Parm *p = NewParmWithoutFileLineInfo(type, name); - Setfile(p, Getfile(file_line_node)); - Setline(p, Getline(file_line_node)); + Setfile(p, Getfile(from_node)); + Setline(p, Getline(from_node)); return p; } @@ -48,6 +48,20 @@ Parm *NewParmWithoutFileLineInfo(SwigType *type, const_String_or_char_ptr name) return p; } +/* ------------------------------------------------------------------------ + * NewParmNode() + * + * Create a new parameter from datatype 'type' and name and symbol table as + * well as file and line number from the 'from_node'. + * The resulting Parm will be similar to a Node used for typemap lookups. + * ------------------------------------------------------------------------ */ + +Parm *NewParmNode(SwigType *type, Node *from_node) { + Parm *p = NewParm(type, Getattr(from_node, "name"), from_node); + Setattr(p, "sym:symtab", Getattr(from_node, "sym:symtab")); + return p; +} + /* ------------------------------------------------------------------------ * CopyParm() * ------------------------------------------------------------------------ */ diff --git a/Source/Swig/swigparm.h b/Source/Swig/swigparm.h index 70a39390e..368b4d26b 100644 --- a/Source/Swig/swigparm.h +++ b/Source/Swig/swigparm.h @@ -13,8 +13,9 @@ * ----------------------------------------------------------------------------- */ /* Individual parameters */ -extern Parm *NewParm(SwigType *type, const_String_or_char_ptr name, Node *file_line_node); +extern Parm *NewParm(SwigType *type, const_String_or_char_ptr name, Node *from_node); extern Parm *NewParmWithoutFileLineInfo(SwigType *type, const_String_or_char_ptr name); +extern Parm *NewParmNode(SwigType *type, Node *from_node); extern Parm *CopyParm(Parm *p); /* Parameter lists */ diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index 0488b1b62..fc7728084 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -1339,7 +1339,17 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No pname = Getattr(node, "name"); +/* + if (pname && node && Getattr(node, "sym:symtab")) { + if (!checkAttribute(node, "kind", "function")) { + Printf(stdout, "New check: %s %s %s\n", Getattr(node, "name"), nodeType(node), Getattr(node, "kind")); + } + } +*/ + if (pname && node && Getattr(node, "sym:symtab")) { + /* if (pname && node && checkAttribute(node, "kind", "function")) { + */ /* For functions, add on a qualified name search, for example struct Foo { From 7aa339cb3f975ed5bc8ddae81224a7febe24a83f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 13 Nov 2012 22:17:10 +0000 Subject: [PATCH 0237/1160] Swig_symbol_string_qualify for destructors - bug exposed after last commit when fully qualifying destructor names during typemap searches git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13879 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/symbol.c | 2 +- Source/Swig/typemap.c | 19 ++++--------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index e39f826eb..0c589f027 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -1800,7 +1800,7 @@ String *Swig_symbol_string_qualify(String *s, Symtab *st) { char *c = Char(s); int first_char = 1; while (*c) { - if (isalpha((int) *c) || (*c == '_') || (*c == ':') || (isdigit((int) *c) && !first_char)) { + if (isalpha((int) *c) || (*c == '_') || (*c == ':') || (*c == '~' && first_char) || (isdigit((int) *c) && !first_char)) { Putc(*c, id); have_id = 1; } else { diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index fc7728084..b7208737a 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -1339,22 +1339,11 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No pname = Getattr(node, "name"); -/* if (pname && node && Getattr(node, "sym:symtab")) { - if (!checkAttribute(node, "kind", "function")) { - Printf(stdout, "New check: %s %s %s\n", Getattr(node, "name"), nodeType(node), Getattr(node, "kind")); - } - } -*/ - if (pname && node && Getattr(node, "sym:symtab")) { - /* - if (pname && node && checkAttribute(node, "kind", "function")) { - */ - /* - For functions, add on a qualified name search, for example - struct Foo { - int *foo(int bar) -> Foo::foo - }; + /* Add on a qualified name search for any symbol, for example: + * struct Foo { + * int *foo(int bar) -> Foo::foo + * }; */ Symtab *st = Getattr(node, "sym:symtab"); String *qsn = st ? Swig_symbol_string_qualify(pname, st) : 0; From b40f6781158958352c33c1e0044777470026d359 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 13 Nov 2012 22:17:55 +0000 Subject: [PATCH 0238/1160] Tweak test so it works if test-suite is run using -copyctor git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13880 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/java/java_prepost_runme.java | 2 +- Examples/test-suite/java_prepost.i | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/java/java_prepost_runme.java b/Examples/test-suite/java/java_prepost_runme.java index 6eeb60393..3bfec8fad 100644 --- a/Examples/test-suite/java/java_prepost_runme.java +++ b/Examples/test-suite/java/java_prepost_runme.java @@ -16,7 +16,7 @@ public class java_prepost_runme { { // ensure checked exception is generated try { - PrePostThrows ppt = new PrePostThrows(null); + PrePostThrows ppt = new PrePostThrows(null, true); } catch (InstantiationException e) { } } diff --git a/Examples/test-suite/java_prepost.i b/Examples/test-suite/java_prepost.i index 3e3839248..e8e4a9d43 100644 --- a/Examples/test-suite/java_prepost.i +++ b/Examples/test-suite/java_prepost.i @@ -83,7 +83,7 @@ struct PrePost2 { %inline %{ struct PrePostThrows { - PrePostThrows(PrePostTest *ppt) { + PrePostThrows(PrePostTest *ppt, bool) { } }; %} From d4b7275f511dd79e530417e63a75e57580199602 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 13 Nov 2012 22:18:52 +0000 Subject: [PATCH 0239/1160] Fix Swig_scopename_last. It was truncating the first two letters of a symbol if the symbol did not contain any qualifiers. Does not seem to change much currently except some generated error messages in overloaded templated methods in classes. However the fix is needed for some commits shortly forthcoming. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13881 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 6d0297b05..a9aacc02e 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -880,8 +880,8 @@ String *Swig_scopename_last(const String *s) { while (*c) { if ((*c == ':') && (*(c + 1) == ':')) { - cc = c; c += 2; + cc = c; } else { if (*c == '<') { int level = 1; @@ -898,7 +898,7 @@ String *Swig_scopename_last(const String *s) { } } } - return NewString(cc + 2); + return NewString(cc); } /* ----------------------------------------------------------------------------- From aeebd394f335234d6ca1b8845fb9dd9dd580c027 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 13 Nov 2012 22:19:47 +0000 Subject: [PATCH 0240/1160] Fix incorrect implicit constructor and destructor names in the symbol tables. Fix some feature matching issues for implicit destructors and implicit constructors and impliciti copy constructors added with %copyctor. Also improves consistency in named typemap lookup rules. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13882 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 24 ++++++++++++++++++++++++ Source/Modules/lang.cxx | 27 ++++++++++----------------- Source/Swig/symbol.c | 1 + Source/Swig/typemap.c | 27 +++++++++++++++++++++------ 4 files changed, 56 insertions(+), 23 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 17e4f76e4..15337ca00 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -8,6 +8,30 @@ Version 2.0.9 (in progress) 2012-11-09: vzeitlin [Python] Fix overflow when passing values greater than LONG_MAX from Python 3 for parameters with unsigned long C type. +2012-11-09: wsfulton + Fix some feature matching issues for implicit destructors and implicit constructors and implicit + copy constructors added with %copyctor. Previously a feature for these had to be fully qualified + in order to match. Now the following will also match: + + %feature("xyz") ~XXX(); + struct XXX {}; + +2012-11-09: wsfulton + Further consistency in named output typemap lookups for implicit constructors and destructors and + implicit copy constructors added with %copyctor. Previously only the fully qualified name was being + used, now the unqualified name will also be used. For example, previously: + + example.i:38: Searching for a suitable 'out' typemap for: void Space::More::~More + Looking for: void Space::More::~More + Looking for: void + + Now the unqualified name is also used: + + example.i:38: Searching for a suitable 'out' typemap for: void Space::More::~More + Looking for: void Space::More::~More + Looking for: void ~More + Looking for: void + 2012-11-02: wsfulton Fix some subtle named output typemap lookup misses, the fully qualified name was not always being used for variables, for example: diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 297e245f3..47dbdeb2b 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2170,8 +2170,7 @@ static void addCopyConstructor(Node *n) { String *cname = Getattr(n, "name"); SwigType *type = Copy(cname); - String *last = Swig_scopename_last(cname); - String *name = NewStringf("%s::%s", cname, last); + String *name = Swig_scopename_last(cname); String *cc = NewStringf("r.q(const).%s", type); String *decl = NewStringf("f(%s).", cc); String *csymname = Getattr(n, "sym:name"); @@ -2196,7 +2195,7 @@ static void addCopyConstructor(Node *n) { } } - String *symname = Swig_name_make(cn, cname, last, decl, oldname); + String *symname = Swig_name_make(cn, cname, name, decl, oldname); if (Strcmp(symname, "$ignore") != 0) { if (!symname) { symname = Copy(csymname); @@ -2213,8 +2212,8 @@ static void addCopyConstructor(Node *n) { Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab")); Node *on = Swig_symbol_add(symname, cn); + Swig_features_get(Swig_cparse_features(), Swig_symbol_qualifiedscopename(0), name, decl, cn); Swig_symbol_setscope(oldscope); - Swig_features_get(Swig_cparse_features(), 0, name, decl, cn); if (on == cn) { Node *access = NewHash(); @@ -2229,7 +2228,6 @@ static void addCopyConstructor(Node *n) { } } Delete(cn); - Delete(last); Delete(name); Delete(decl); Delete(symname); @@ -2243,12 +2241,11 @@ static void addDefaultConstructor(Node *n) { Setline(cn, Getline(n)); String *cname = Getattr(n, "name"); - String *last = Swig_scopename_last(cname); - String *name = NewStringf("%s::%s", cname, last); + String *name = Swig_scopename_last(cname); String *decl = NewString("f()."); String *csymname = Getattr(n, "sym:name"); String *oldname = csymname; - String *symname = Swig_name_make(cn, cname, last, decl, oldname); + String *symname = Swig_name_make(cn, cname, name, decl, oldname); if (Strcmp(symname, "$ignore") != 0) { if (!symname) { symname = Copy(csymname); @@ -2260,11 +2257,10 @@ static void addDefaultConstructor(Node *n) { Setattr(cn, "decl", decl); Setattr(cn, "parentNode", n); Setattr(cn, "default_constructor", "1"); - Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab")); Node *on = Swig_symbol_add(symname, cn); + Swig_features_get(Swig_cparse_features(), Swig_symbol_qualifiedscopename(0), name, decl, cn); Swig_symbol_setscope(oldscope); - Swig_features_get(Swig_cparse_features(), 0, name, decl, cn); if (on == cn) { Node *access = NewHash(); @@ -2278,7 +2274,6 @@ static void addDefaultConstructor(Node *n) { } } Delete(cn); - Delete(last); Delete(name); Delete(decl); Delete(symname); @@ -2292,11 +2287,10 @@ static void addDestructor(Node *n) { Setline(cn, Getline(n)); String *cname = Getattr(n, "name"); - String *last = Swig_scopename_last(cname); - Insert(last, 0, "~"); - String *name = NewStringf("%s::%s", cname, last); + String *name = Swig_scopename_last(cname); + Insert(name, 0, "~"); String *decl = NewString("f()."); - String *symname = Swig_name_make(cn, cname, last, decl, 0); + String *symname = Swig_name_make(cn, cname, name, decl, 0); if (Strcmp(symname, "$ignore") != 0) { String *possible_nonstandard_symname = NewStringf("~%s", Getattr(n, "sym:name")); @@ -2308,8 +2302,8 @@ static void addDestructor(Node *n) { Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab")); Node *nonstandard_destructor = Equal(possible_nonstandard_symname, symname) ? 0 : Swig_symbol_clookup(possible_nonstandard_symname, 0); Node *on = Swig_symbol_add(symname, cn); + Swig_features_get(Swig_cparse_features(), Swig_symbol_qualifiedscopename(0), name, decl, cn); Swig_symbol_setscope(oldscope); - Swig_features_get(Swig_cparse_features(), 0, name, decl, cn); if (on == cn) { // SWIG accepts a non-standard named destructor in %extend that uses a typedef for the destructor name @@ -2329,7 +2323,6 @@ static void addDestructor(Node *n) { Delete(possible_nonstandard_symname); } Delete(cn); - Delete(last); Delete(name); Delete(decl); Delete(symname); diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index 0c589f027..6b54eac08 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -1549,6 +1549,7 @@ static int symbol_no_constructor(Node *n) { * Swig_symbol_type_qualify() * * Create a fully qualified type name + * Note: Does not resolve a constructor if passed in as the 'type'. * ----------------------------------------------------------------------------- */ SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) { diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index b7208737a..5007d76a8 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -1306,6 +1306,7 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No SwigType *mtype = 0; String *pname; String *qpname = 0; + String *noscope_pname = 0; Hash *tm = 0; String *s = 0; String *sdef = 0; @@ -1338,20 +1339,32 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No } pname = Getattr(node, "name"); + noscope_pname = Copy(pname); if (pname && node && Getattr(node, "sym:symtab")) { - /* Add on a qualified name search for any symbol, for example: + /* Add on a qualified name search for any symbol in the symbol table, for example: * struct Foo { * int *foo(int bar) -> Foo::foo * }; + * Note that if node is a parameter (Parm *) then there will be no symbol table attached to the Parm *. */ - Symtab *st = Getattr(node, "sym:symtab"); - String *qsn = st ? Swig_symbol_string_qualify(pname, st) : 0; - if (qsn && Len(qsn) && !Equal(qsn, pname)) - qpname = qsn; + String *qsn; + if (Swig_scopename_check(pname)) { + /* sometimes pname is qualified, so we remove all the scope for the lookup */ + Delete(noscope_pname); + noscope_pname = Swig_scopename_last(pname); + /* + Printf(stdout, "Removed scope: %s => %s\n", pname, noscope_pname); + */ + } + qsn = Swig_symbol_qualified(node); + if (qsn && Len(qsn)) { + qpname = NewStringf("%s::%s", qsn, noscope_pname); + Delete(qsn); + } } - tm = typemap_search(tmap_method, type, pname, qpname, &mtype, node); + tm = typemap_search(tmap_method, type, noscope_pname, qpname, &mtype, node); if (typemap_search_debug) debug_search_result_display(tm); if (typemaps_used_debug && tm) { @@ -1364,6 +1377,8 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No Delete(qpname); qpname = 0; + Delete(noscope_pname); + noscope_pname = 0; if (!tm) return sdef; From 4e8d81750db964c1b49f4f82a2153ad750db4a5c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 13 Nov 2012 22:20:47 +0000 Subject: [PATCH 0241/1160] Add test added a short while back git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13883 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 7f3cd771a..0c790caf6 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -431,6 +431,7 @@ CPP_TEST_CASES += \ typedef_struct \ typemap_arrays \ typemap_delete \ + typemap_directorout \ typemap_global_scope \ typemap_manyargs \ typemap_namespace \ From 61b4c1cbcd386ef7854f9b32494f2a804d7ddc17 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 13 Nov 2012 22:21:51 +0000 Subject: [PATCH 0242/1160] Fix 'name' attribute for explicitly defined constructors and destructors if the associated class was in a namespace, eg a correct fully qualified name might be Space::Klass::~Klass, but it was Space::~Klass, now it is simply ~Klass (names are now consistent with implicitly added constructors/destructors). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13884 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/lang.cxx | 20 +++++++++++--------- Source/Modules/typepass.cxx | 10 ---------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 47dbdeb2b..0a8415120 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2613,11 +2613,14 @@ int Language::constructorDeclaration(Node *n) { } } else { String *expected_name = ClassName; - if (name && (!Equal(Swig_scopename_last(name), Swig_scopename_last(expected_name))) && !(Getattr(n, "template"))) { + String *scope = Swig_scopename_check(ClassName) ? Swig_scopename_prefix(ClassName) : 0; + String *actual_name = scope ? NewStringf("%s::%s", scope, name) : NewString(name); + Delete(scope); + if (!Equal(actual_name, expected_name) && !(Getattr(n, "template"))) { bool illegal_name = true; if (Extend) { - // SWIG extension - allow typedef names as constructor name in %extend - an unnamed struct declared with a typedef can thus be given a 'constructor'. - SwigType *name_resolved = SwigType_typedef_resolve_all(name); + // SWIG extension - allow typedef names as destructor name in %extend - an unnamed struct declared with a typedef can thus be given a 'destructor'. + SwigType *name_resolved = SwigType_typedef_resolve_all(actual_name); SwigType *expected_name_resolved = SwigType_typedef_resolve_all(expected_name); illegal_name = !Equal(name_resolved, expected_name_resolved); Delete(name_resolved); @@ -2747,11 +2750,12 @@ int Language::destructorDeclaration(Node *n) { Setattr(n, "sym:name", ClassPrefix); } - String *expected_name = NewString(ClassName); - Replace(expected_name, "~", "", DOH_REPLACE_FIRST); - String *actual_name = NewString(name); + String *expected_name = ClassName; + String *scope = Swig_scopename_check(ClassName) ? Swig_scopename_prefix(ClassName) : 0; + String *actual_name = scope ? NewStringf("%s::%s", scope, name) : NewString(name); + Delete(scope); Replace(actual_name, "~", "", DOH_REPLACE_FIRST); - if (name && (!Equal(Swig_scopename_last(actual_name), Swig_scopename_last(expected_name))) && !(Getattr(n, "template"))) { + if (!Equal(actual_name, expected_name) && !(Getattr(n, "template"))) { bool illegal_name = true; if (Extend) { // SWIG extension - allow typedef names as destructor name in %extend - an unnamed struct declared with a typedef can thus be given a 'destructor'. @@ -2765,7 +2769,6 @@ int Language::destructorDeclaration(Node *n) { if (illegal_name) { Swig_warning(WARN_LANG_ILLEGAL_DESTRUCTOR, input_file, line_number, "Illegal destructor name %s. Ignored.\n", Swig_name_decl(n)); Swig_restore(n); - Delete(expected_name); return SWIG_NOWRAP; } } @@ -2773,7 +2776,6 @@ int Language::destructorDeclaration(Node *n) { Setattr(CurrentClass, "has_destructor", "1"); Swig_restore(n); - Delete(expected_name); return SWIG_OK; } diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index a134e0ac6..a6012c0bf 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -702,11 +702,6 @@ class TypePass:private Dispatcher { normalize_parms(Getattr(n, "parms")); normalize_parms(Getattr(n, "throws")); - /* If in a namespace, patch the class name */ - if (nsname) { - String *nname = NewStringf("%s::%s", nsname, Getattr(n, "name")); - Setattr(n, "name", nname); - } clean_overloaded(n); return SWIG_OK; } @@ -716,11 +711,6 @@ class TypePass:private Dispatcher { * ------------------------------------------------------------ */ virtual int destructorDeclaration(Node *n) { - /* If in a namespace, patch the class name */ - if (nsname) { - String *nname = NewStringf("%s::%s", nsname, Getattr(n, "name")); - Setattr(n, "name", nname); - } return SWIG_OK; } From 5a1e82a2f407566f78e9d5f1acd32d1ee9eb7f73 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 14 Nov 2012 22:16:07 +0000 Subject: [PATCH 0243/1160] Remove DohClose (Close) and replace with calls to DohDelete (Delete) to fix some minor memory leaks in most uses of NewFile. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13885 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/DOH/base.c | 2 ++ Source/DOH/doh.h | 3 +++ Source/Modules/allegrocl.cxx | 5 +---- Source/Modules/cffi.cxx | 6 +----- Source/Modules/chicken.cxx | 3 --- Source/Modules/clisp.cxx | 3 +-- Source/Modules/csharp.cxx | 12 +++++------- Source/Modules/d.cxx | 11 +++-------- Source/Modules/go.cxx | 5 ----- Source/Modules/guile.cxx | 1 - Source/Modules/java.cxx | 14 ++++++-------- Source/Modules/lua.cxx | 1 - Source/Modules/main.cxx | 15 +++++++-------- Source/Modules/modula3.cxx | 21 ++++++++++----------- Source/Modules/mzscheme.cxx | 1 - Source/Modules/ocaml.cxx | 3 --- Source/Modules/octave.cxx | 1 - Source/Modules/perl5.cxx | 2 -- Source/Modules/php.cxx | 7 +++---- Source/Modules/pike.cxx | 2 -- Source/Modules/python.cxx | 5 +---- Source/Modules/r.cxx | 6 +----- Source/Modules/ruby.cxx | 3 +-- Source/Modules/tcl8.cxx | 2 -- Source/Modules/uffi.cxx | 2 -- 25 files changed, 45 insertions(+), 91 deletions(-) diff --git a/Source/DOH/base.c b/Source/DOH/base.c index db37e147b..e64b0f561 100644 --- a/Source/DOH/base.c +++ b/Source/DOH/base.c @@ -761,6 +761,7 @@ int DohUngetc(int ch, DOH *obj) { * DohClose() * ----------------------------------------------------------------------------- */ +/* int DohClose(DOH *obj) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; @@ -773,6 +774,7 @@ int DohClose(DOH *obj) { } return fclose((FILE *) obj); } +*/ /* ----------------------------------------------------------------------------- * DohIsString() diff --git a/Source/DOH/doh.h b/Source/DOH/doh.h index 621d0957c..a0bd1817c 100644 --- a/Source/DOH/doh.h +++ b/Source/DOH/doh.h @@ -307,7 +307,10 @@ extern DOHFile *DohNewFile(DOH *filename, const char *mode, DOHList *outfiles); extern DOHFile *DohNewFileFromFile(FILE *f); extern DOHFile *DohNewFileFromFd(int fd); extern void DohFileErrorDisplay(DOHString * filename); +/* + Deprecated, just use DohDelete extern int DohClose(DOH *file); +*/ extern int DohCopyto(DOHFile * input, DOHFile * output); diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index 41d481e9d..56a3116fe 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -1654,7 +1654,6 @@ int ALLEGROCL::top(Node *n) { if (Generate_Wrapper) { f_begin = NewFile(cxx_filename, "w", SWIG_output_files()); if (!f_begin) { - Close(f_cl); Delete(f_cl); Printf(stderr, "Unable to open %s for writing\n", cxx_filename); SWIG_exit(EXIT_FAILURE); @@ -1711,15 +1710,13 @@ int ALLEGROCL::top(Node *n) { Printf(f_cl, "%s\n", f_clhead); Printf(f_cl, "%s\n", f_clwrap); - Close(f_cl); - Delete(f_cl); // Delete the handle, not the file + Delete(f_cl); Delete(f_clhead); Delete(f_clwrap); Dump(f_runtime, f_begin); Printf(f_begin, "%s\n", f_cxx_wrapper); - Close(f_begin); Delete(f_runtime); Delete(f_begin); Delete(f_cxx_wrapper); diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx index 2bb95188b..6fd915bf5 100644 --- a/Source/Modules/cffi.cxx +++ b/Source/Modules/cffi.cxx @@ -137,7 +137,6 @@ int CFFI::top(Node *n) { if (CPlusPlus || CWrap) { f_begin = NewFile(cxx_filename, "w", SWIG_output_files()); if (!f_begin) { - Close(f_lisp); Delete(f_lisp); Printf(stderr, "Unable to open %s for writing\n", cxx_filename); SWIG_exit(EXIT_FAILURE); @@ -147,7 +146,6 @@ int CFFI::top(Node *n) { Printf(clos_filename, "%s%s-clos.lisp", SWIG_output_directory(), module); f_clos = NewFile(clos_filename, "w", SWIG_output_files()); if (!f_clos) { - Close(f_lisp); Delete(f_lisp); Printf(stderr, "Unable to open %s for writing\n", cxx_filename); SWIG_exit(EXIT_FAILURE); @@ -184,13 +182,11 @@ int CFFI::top(Node *n) { Printf(f_lisp, "%s\n", f_cl); Printf(f_lisp, "%s\n", f_clwrap); - Close(f_lisp); - Delete(f_lisp); // Deletes the handle, not the file + Delete(f_lisp); Delete(f_cl); Delete(f_clhead); Delete(f_clwrap); Dump(f_runtime, f_begin); - Close(f_begin); Delete(f_runtime); Delete(f_begin); Delete(f_cxx_wrapper); diff --git a/Source/Modules/chicken.cxx b/Source/Modules/chicken.cxx index a807d1487..8ff154f82 100644 --- a/Source/Modules/chicken.cxx +++ b/Source/Modules/chicken.cxx @@ -290,8 +290,6 @@ int CHICKEN::top(Node *n) { Printf(f_scm, "%s\n", chickentext); - - Close(f_scm); Delete(f_scm); char buftmp[20]; @@ -324,7 +322,6 @@ int CHICKEN::top(Node *n) { Delete(f_wrappers); Delete(f_sym_size); Delete(f_init); - Close(f_begin); Delete(f_runtime); Delete(f_begin); return SWIG_OK; diff --git a/Source/Modules/clisp.cxx b/Source/Modules/clisp.cxx index 05363a54d..a322cb2de 100644 --- a/Source/Modules/clisp.cxx +++ b/Source/Modules/clisp.cxx @@ -141,8 +141,7 @@ int CLISP::top(Node *n) { Seek(f_cl, 0, SEEK_SET); Write(f_cl, Char(header), Len(header)); - Close(f_cl); - Delete(f_cl); // Deletes the handle, not the file + Delete(f_cl); return SWIG_OK; } diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index db8a65a27..41c0da516 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -467,7 +467,7 @@ public: Printf(f_im, "}\n"); addCloseNamespace(0, f_im); - Close(f_im); + Delete(f_im); } // Generate the C# module class @@ -519,7 +519,7 @@ public: Printf(f_module, "}\n"); addCloseNamespace(0, f_module); - Close(f_module); + Delete(f_module); } if (upcasts_code) @@ -610,7 +610,6 @@ public: Printf(f_runtime_h, "\n"); Printf(f_runtime_h, "#endif\n"); - Close(f_runtime_h); Delete(f_runtime_h); f_runtime_h = NULL; Delete(f_directors); @@ -624,7 +623,6 @@ public: Delete(f_header); Delete(f_wrappers); Delete(f_init); - Close(f_begin); Delete(f_runtime); Delete(f_begin); return SWIG_OK; @@ -1225,7 +1223,7 @@ public: "\n", enum_code, "\n", NIL); addCloseNamespace(nspace, f_enum); - Close(f_enum); + Delete(f_enum); Delete(output_directory); } } else { @@ -1955,7 +1953,7 @@ public: Printf(f_proxy, "}\n"); addCloseNamespace(nspace, f_proxy); - Close(f_proxy); + Delete(f_proxy); f_proxy = NULL; /* Output the downcast method, if necessary. Note: There's no other really @@ -3227,7 +3225,7 @@ public: addCloseNamespace(0, f_swigtype); - Close(f_swigtype); + Delete(f_swigtype); Delete(swigtype); Delete(n); } diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 879a4acd8..fc8e579b4 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -538,7 +538,7 @@ public: replaceModuleVariables(im_dmodule_code); Printv(im_d_file, im_dmodule_code, NIL); - Close(im_d_file); + Delete(im_d_file); } // Generate the main D proxy module. @@ -571,7 +571,7 @@ public: replaceModuleVariables(proxy_dmodule_code); Printv(proxy_d_file, proxy_dmodule_code, NIL); - Close(proxy_d_file); + Delete(proxy_d_file); } // Generate the additional proxy modules for nspace support. @@ -598,7 +598,7 @@ public: replaceModuleVariables(code); Printv(file, code, NIL); - Close(file); + Delete(file); Delete(module_name); } @@ -693,7 +693,6 @@ public: Printf(f_runtime_h, "\n"); Printf(f_runtime_h, "#endif\n"); - Close(f_runtime_h); Delete(f_runtime_h); f_runtime_h = NULL; Delete(f_directors); @@ -707,7 +706,6 @@ public: Delete(f_header); Delete(f_wrappers); Delete(f_init); - Close(f_begin); Delete(f_runtime); Delete(f_begin); @@ -868,7 +866,6 @@ public: Printv(class_file, proxy_enum_code, NIL); - Close(class_file); Delete(class_file); } else { String *nspace = Getattr(n, "sym:nspace"); @@ -1363,7 +1360,6 @@ public: replaceModuleVariables(proxy_class_code); Printv(class_file, proxy_class_code, NIL); - Close(class_file); Delete(class_file); } else { Printv(proxyImportsBuffer(getNSpace()), proxy_class_imports, NIL); @@ -3469,7 +3465,6 @@ private: Printv(class_file, code_target, NIL); Delete(code_target); - Close(class_file); Delete(class_file); } diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 127e7c239..9f086f01c 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -437,12 +437,10 @@ private: 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; } @@ -475,12 +473,9 @@ private: 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); } diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index 90feb366b..50c9e7e0d 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -409,7 +409,6 @@ public: Delete(f_header); Delete(f_wrappers); Delete(f_init); - Close(f_begin); Delete(f_runtime); Delete(f_begin); return SWIG_OK; diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 6e9ee54b2..b64626087 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -502,7 +502,7 @@ public: } // Finish off the class Printf(f_im, "}\n"); - Close(f_im); + Delete(f_im); } // Generate the Java module class @@ -554,7 +554,7 @@ public: // Finish off the class Printf(f_module, "}\n"); - Close(f_module); + Delete(f_module); } // Generate the Java constants interface @@ -585,7 +585,7 @@ public: // Finish off the Java interface Printf(f_module, "}\n"); - Close(f_module); + Delete(f_module); } if (upcasts_code) @@ -685,7 +685,6 @@ public: Printf(f_runtime_h, "\n"); Printf(f_runtime_h, "#endif\n"); - Close(f_runtime_h); Delete(f_runtime_h); f_runtime_h = NULL; Delete(f_directors); @@ -701,7 +700,6 @@ public: Delete(f_init); Dump(f_runtime, f_begin); Delete(f_runtime); - Close(f_begin); Delete(f_begin); return SWIG_OK; } @@ -1300,7 +1298,7 @@ public: "\n", enum_code, "\n", NIL); Printf(f_enum, "\n"); - Close(f_enum); + Delete(f_enum); Delete(output_directory); } } else { @@ -1977,7 +1975,7 @@ public: Printv(f_proxy, proxy_class_constants_code, NIL); Printf(f_proxy, "}\n"); - Close(f_proxy); + Delete(f_proxy); f_proxy = NULL; /* Output the downcast method, if necessary. Note: There's no other really @@ -3069,7 +3067,7 @@ public: Replaceall(swigtype, "$imclassname", imclass_name); Printv(f_swigtype, swigtype, NIL); - Close(f_swigtype); + Delete(f_swigtype); Delete(swigtype); Delete(n); } diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index a6076a230..66ba8ea6f 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -396,7 +396,6 @@ public: Delete(f_wrappers); Delete(f_init); Delete(f_initbeforefunc); - Close(f_begin); Delete(f_runtime); Delete(f_begin); Delete(s_dot_get); diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index d2f5d3bc0..8e2b428f4 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -403,7 +403,7 @@ static void SWIG_dump_runtime() { s = Swig_include_sys("swiglabels.swg"); if (!s) { Printf(stderr, "*** Unable to open 'swiglabels.swg'\n"); - Close(runtime); + Delete(runtime); SWIG_exit(EXIT_FAILURE); } Printf(runtime, "%s", s); @@ -412,7 +412,7 @@ static void SWIG_dump_runtime() { s = Swig_include_sys("swigerrors.swg"); if (!s) { Printf(stderr, "*** Unable to open 'swigerrors.swg'\n"); - Close(runtime); + Delete(runtime); SWIG_exit(EXIT_FAILURE); } Printf(runtime, "%s", s); @@ -421,7 +421,7 @@ static void SWIG_dump_runtime() { s = Swig_include_sys("swigrun.swg"); if (!s) { Printf(stderr, "*** Unable to open 'swigrun.swg'\n"); - Close(runtime); + Delete(runtime); SWIG_exit(EXIT_FAILURE); } Printf(runtime, "%s", s); @@ -434,13 +434,12 @@ static void SWIG_dump_runtime() { s = Swig_include_sys("runtime.swg"); if (!s) { Printf(stderr, "*** Unable to open 'runtime.swg'\n"); - Close(runtime); + Delete(runtime); SWIG_exit(EXIT_FAILURE); } Printf(runtime, "%s", s); Delete(s); - Close(runtime); Delete(runtime); SWIG_exit(EXIT_SUCCESS); } @@ -1009,7 +1008,7 @@ int SWIG_main(int argc, char *argv[], Language *l) { if (Verbose) Printf(stdout, "'%s' checked out from the SWIG library.\n", outfile); Printv(f_outfile, s, NIL); - Close(f_outfile); + Delete(f_outfile); } } } @@ -1111,7 +1110,7 @@ int SWIG_main(int argc, char *argv[], Language *l) { } Printf(f_dependencies_file, "\n"); if (f_dependencies_file != stdout) - Close(f_dependencies_file); + Delete(f_dependencies_file); if (depend_only) SWIG_exit(EXIT_SUCCESS); } else { @@ -1285,7 +1284,7 @@ int SWIG_main(int argc, char *argv[], Language *l) { int i; for (i = 0; i < Len(all_output_files); i++) Printf(f_outfiles, "%s\n", Getitem(all_output_files, i)); - Close(f_outfiles); + Delete(f_outfiles); } } diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index bcb99e46a..78af35506 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -835,7 +835,7 @@ MODULA3(): scanConstant(file, n); Printf(file, " return 0;\n"); Printf(file, "}\n"); - Close(file); + Delete(file); return SWIG_OK; } @@ -870,7 +870,7 @@ MODULA3(): by SWIG with option -generaterename. */\n\ \n", input_file); scanRename(file, n); - Close(file); + Delete(file); return SWIG_OK; } @@ -900,7 +900,7 @@ MODULA3(): by SWIG with option -generatetypemap. */\n\ \n", input_file); scanTypemap(file, n); - Close(file); + Delete(file); return SWIG_OK; } @@ -1009,7 +1009,7 @@ MODULA3(): } else { Printf(file, "library(\"m3%s\")\n", name); } - Close(file); + Delete(file); } // Generate the raw interface @@ -1027,7 +1027,7 @@ MODULA3(): Printv(file, m3raw_intf.f, NIL); Printf(file, "\nEND %s.\n", m3raw_name); - Close(file); + Delete(file); } // Generate the raw module @@ -1045,7 +1045,7 @@ MODULA3(): Printv(file, m3raw_impl.f, NIL); Printf(file, "BEGIN\nEND %s.\n", m3raw_name); - Close(file); + Delete(file); } // Generate the interface for the comfort wrappers @@ -1075,7 +1075,7 @@ MODULA3(): // Finish off the class Printf(file, "\nEND %s.\n", m3wrap_name); - Close(file); + Delete(file); } // Generate the wrapper routines implemented in Modula 3 @@ -1096,7 +1096,7 @@ MODULA3(): Printv(file, m3wrap_impl.f, NIL); Printf(file, "\nBEGIN\nEND %s.\n", m3wrap_name); - Close(file); + Delete(file); } if (upcasts_code) @@ -1162,7 +1162,6 @@ MODULA3(): Delete(f_header); Delete(f_wrappers); Delete(f_init); - Close(f_begin); Delete(f_runtime); Delete(f_begin); return SWIG_OK; @@ -2555,7 +2554,7 @@ MODULA3(): Printv(f_proxy, proxy_class_def, proxy_class_code, NIL); Printf(f_proxy, "}\n"); - Close(f_proxy); + Delete(f_proxy); f_proxy = NULL; Delete(proxy_class_name); @@ -3811,7 +3810,7 @@ MODULA3(): Replaceall(swigtype, "$m3classname", classname); Printv(f_swigtype, swigtype, NIL); - Close(f_swigtype); + Delete(f_swigtype); Delete(filen); Delete(swigtype); } diff --git a/Source/Modules/mzscheme.cxx b/Source/Modules/mzscheme.cxx index c8d758bb9..99513dae3 100644 --- a/Source/Modules/mzscheme.cxx +++ b/Source/Modules/mzscheme.cxx @@ -203,7 +203,6 @@ public: Delete(f_header); Delete(f_wrappers); Delete(f_init); - Close(f_begin); Delete(f_runtime); Delete(f_begin); return SWIG_OK; diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index 4a2071e32..6204fd2ec 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -343,7 +343,6 @@ public: Delete(f_header); Delete(f_wrappers); Delete(f_init); - Close(f_begin); Delete(f_runtime); Delete(f_begin); @@ -357,14 +356,12 @@ public: Dump(f_class_ctors, f_mlout); Dump(f_class_ctors_end, f_mlout); Dump(f_mltail, f_mlout); - Close(f_mlout); Delete(f_mlout); Dump(f_enumtypes_type, f_mliout); Dump(f_enumtypes_value, f_mliout); Dump(f_mlibody, f_mliout); Dump(f_mlitail, f_mliout); - Close(f_mliout); Delete(f_mliout); return SWIG_OK; diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index ef1629324..4b42abae5 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -232,7 +232,6 @@ public: Delete(f_header); Delete(f_directors); Delete(f_directors_h); - Close(f_begin); Delete(f_runtime); Delete(f_begin); diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 077b5fe83..cd91a807c 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -520,7 +520,6 @@ public: Printf(f_pm, "%s", additional_perl_code); Printf(f_pm, "1;\n"); - Close(f_pm); Delete(f_pm); Delete(base); Delete(dest_package); @@ -534,7 +533,6 @@ public: Delete(f_header); Delete(f_wrappers); Delete(f_init); - Close(f_begin); Delete(f_runtime); Delete(f_begin); return SWIG_OK; diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index d89d61da4..a0e8b3223 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -615,7 +615,7 @@ public: Printf(f_h, "#endif /* PHP_%s_H */\n", cap_module); - Close(f_h); + Delete(f_h); String *type_table = NewStringEmpty(); SwigType_emit_type_table(f_runtime, type_table); @@ -630,7 +630,7 @@ public: Dump(f_directors_h, f_runtime_h); Printf(f_runtime_h, "\n"); Printf(f_runtime_h, "#endif\n"); - Close(f_runtime_h); + Delete(f_runtime_h); } Printf(s_header, "/* end header section */\n"); @@ -654,7 +654,6 @@ public: Delete(s_vdecl); Delete(all_cs_entry); Delete(s_entry); - Close(f_begin); Delete(f_runtime); Delete(f_begin); @@ -667,7 +666,7 @@ public: s_fakeoowrappers = NULL; } Printf(f_phpcode, "%s\n?>\n", s_phpclasses); - Close(f_phpcode); + Delete(f_phpcode); return SWIG_OK; } diff --git a/Source/Modules/pike.cxx b/Source/Modules/pike.cxx index 9fba5d5b0..6749989f2 100644 --- a/Source/Modules/pike.cxx +++ b/Source/Modules/pike.cxx @@ -182,8 +182,6 @@ public: Delete(f_wrappers); Delete(f_init); Delete(f_classInit); - - Close(f_begin); Delete(f_runtime); Delete(f_begin); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 97b0c4f8d..9d1b3a772 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -979,7 +979,6 @@ public: Printv(f_shadow_py, "\n", f_shadow_builtin_imports, "\n", NIL); Printv(f_shadow_py, f_shadow, "\n", NIL); Printv(f_shadow_py, f_shadow_stubs, "\n", NIL); - Close(f_shadow_py); Delete(f_shadow_py); } @@ -992,7 +991,7 @@ public: Printf(f_runtime_h, "\n"); Printf(f_runtime_h, "#endif\n"); if (f_runtime_h != f_begin) - Close(f_runtime_h); + Delete(f_runtime_h); Dump(f_directors, f_begin); } @@ -1007,8 +1006,6 @@ public: Delete(f_init); Delete(f_directors); Delete(f_directors_h); - - Close(f_begin); Delete(f_runtime); Delete(f_begin); diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 94e6ed4bd..a8cdc1cc8 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -837,7 +837,6 @@ int R::top(Node *n) { Delete(f_init); Delete(s_header); - Close(f_begin); Delete(f_runtime); Delete(f_begin); @@ -871,8 +870,7 @@ int R::DumpCode(Node *n) { Printf(scode, "%s\n\n", s_classes); Printf(scode, "%s\n", sfile); - Close(scode); - // Delete(scode); + Delete(scode); String *outfile = Getattr(n,"outfile"); File *runtime = NewFile(outfile,"w", SWIG_output_files()); if (!runtime) { @@ -886,7 +884,6 @@ int R::DumpCode(Node *n) { Printf(runtime, "%s\n", f_wrapper); Printf(runtime, "%s\n", f_init); - Close(runtime); Delete(runtime); if(outputNamespaceInfo) { @@ -907,7 +904,6 @@ int R::DumpCode(Node *n) { Printf(ns, "\nexportMethods(\n"); writeListByLine(namespaceFunctions, ns, 1); Printf(ns, ")\n"); - Close(ns); Delete(ns); Delete(s_namespace); } diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 276b967f3..a1523a7ad 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -1185,7 +1185,7 @@ public: Dump(f_directors_h, f_runtime_h); Printf(f_runtime_h, "\n"); Printf(f_runtime_h, "#endif\n"); - Close(f_runtime_h); + Delete(f_runtime_h); } Dump(f_wrappers, f_begin); @@ -1196,7 +1196,6 @@ public: Delete(f_wrappers); Delete(f_init); Delete(f_initbeforefunc); - Close(f_begin); Delete(f_runtime); Delete(f_begin); diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx index 3913392c4..4f4bdd1b2 100644 --- a/Source/Modules/tcl8.cxx +++ b/Source/Modules/tcl8.cxx @@ -248,7 +248,6 @@ public: if (itcl) { Printv(f_shadow, f_shadow_stubs, "\n", NIL); - Close(f_shadow); Delete(f_shadow); } @@ -259,7 +258,6 @@ public: Delete(f_header); Delete(f_wrappers); Delete(f_init); - Close(f_begin); Delete(f_runtime); Delete(f_begin); return SWIG_OK; diff --git a/Source/Modules/uffi.cxx b/Source/Modules/uffi.cxx index 3fcb4dcd1..9e317f8bc 100644 --- a/Source/Modules/uffi.cxx +++ b/Source/Modules/uffi.cxx @@ -266,9 +266,7 @@ int UFFI::top(Node *n) { Language::top(n); - Close(f_cl); Delete(f_cl); // Delete the handle, not the file - Close(f_null); Delete(f_null); return SWIG_OK; From 46d24861153b5afffcecebfda822da8d2603c4ec Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 14 Nov 2012 22:16:54 +0000 Subject: [PATCH 0244/1160] Resource leak fixes (or hiding them from Coverity static analysis tool by using String instead of char *) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13886 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/allegrocl.cxx | 13 +++++------ Source/Modules/csharp.cxx | 4 +++- Source/Modules/d.cxx | 4 +++- Source/Modules/go.cxx | 1 + Source/Modules/guile.cxx | 22 +++++++++---------- Source/Modules/java.cxx | 4 +++- Source/Modules/mzscheme.cxx | 42 ++++++++++++++---------------------- Source/Modules/ocaml.cxx | 16 ++++++-------- Source/Modules/octave.cxx | 4 +++- Source/Modules/php.cxx | 1 + Source/Modules/r.cxx | 1 + Source/Modules/uffi.cxx | 13 +++++------ 12 files changed, 62 insertions(+), 63 deletions(-) diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index 56a3116fe..ffd96ca9c 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -48,7 +48,7 @@ static File *f_cxx_wrapper = 0; static String *module_name = 0; static String *swig_package = 0; -const char *identifier_converter = "identifier-convert-null"; +static String *identifier_converter = NewString("identifier-convert-null"); static bool CWrap = true; // generate wrapper file for C code by default. most correct. static bool Generate_Wrapper = false; @@ -1605,14 +1605,15 @@ void ALLEGROCL::main(int argc, char *argv[]) { /* check for built-ins */ if (!strcmp(conv, "lispify")) { - identifier_converter = "identifier-convert-lispify"; + Delete(identifier_converter); + identifier_converter = NewString("identifier-convert-lispify"); } else if (!strcmp(conv, "null")) { - identifier_converter = "identifier-convert-null"; + Delete(identifier_converter); + identifier_converter = NewString("identifier-convert-null"); } else { /* Must be user defined */ - char *idconv = new char[strlen(conv) + 1]; - strcpy(idconv, conv); - identifier_converter = idconv; + Delete(identifier_converter); + identifier_converter = NewString(conv); } } else if (!strcmp(argv[i], "-cwrap")) { CWrap = true; diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 41c0da516..13c132a76 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -792,8 +792,10 @@ public: if (Getattr(n, "sym:overloaded")) { // Emit warnings for the few cases that can't be overloaded in C# and give up on generating wrapper Swig_overload_check(n); - if (Getattr(n, "overload:ignore")) + if (Getattr(n, "overload:ignore")) { + DelWrapper(f); return SWIG_OK; + } } Printv(imclass_class_code, "\n [DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL); diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index fc8e579b4..b21562c1d 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -1579,8 +1579,10 @@ public: if (Getattr(n, "sym:overloaded")) { // Emit warnings for the few cases that can't be overloaded in D and give up on generating wrapper Swig_overload_check(n); - if (Getattr(n, "overload:ignore")) + if (Getattr(n, "overload:ignore")) { + DelWrapper(f); return SWIG_OK; + } } // Collect the parameter list for the intermediary D module declaration of diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 9f086f01c..7c34f8b9a 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -3640,6 +3640,7 @@ private: Delete(upcall_name); Delete(callback_wname); Delete(go_name); + DelWrapper(w); return SWIG_OK; } diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index 50c9e7e0d..c7e8fe7e4 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -59,9 +59,9 @@ static File *f_wrappers = 0; static File *f_init = 0; -static char *prefix = (char *) "gswig_"; +static String *prefix = NewString("gswig_"); static char *module = 0; -static char *package = 0; +static String *package = 0; static enum { GUILE_LSTYLE_SIMPLE, // call `SWIG_init()' GUILE_LSTYLE_PASSIVE, // passive linking (no module code) @@ -127,7 +127,7 @@ public: * ------------------------------------------------------------ */ virtual void main(int argc, char *argv[]) { - int i, orig_len; + int i; SWIG_library_directory("guile"); SWIG_typemap_lang("guile"); @@ -140,8 +140,7 @@ public: SWIG_exit(EXIT_SUCCESS); } else if (strcmp(argv[i], "-prefix") == 0) { if (argv[i + 1]) { - prefix = new char[strlen(argv[i + 1]) + 2]; - strcpy(prefix, argv[i + 1]); + prefix = NewString(argv[i + 1]); Swig_mark_arg(i); Swig_mark_arg(i + 1); i++; @@ -150,8 +149,7 @@ public: } } else if (strcmp(argv[i], "-package") == 0) { if (argv[i + 1]) { - package = new char[strlen(argv[i + 1]) + 2]; - strcpy(package, argv[i + 1]); + package = NewString(argv[i + 1]); Swig_mark_arg(i); Swig_mark_arg(i + 1); i++; @@ -278,12 +276,12 @@ public: // should use Swig_warning() ? Printf(stderr, "guile: Warning: -exportprimitive only makes sense with passive linkage without a scmstub.\n"); } - // Make sure `prefix' ends in an underscore - orig_len = strlen(prefix); - if (prefix[orig_len - 1] != '_') { - prefix[1 + orig_len] = 0; - prefix[orig_len] = '_'; + // Make sure `prefix' ends in an underscore + if (prefix) { + const char *px = Char(prefix); + if (px[Len(prefix)] != '_') + Printf(prefix, "_"); } /* Add a symbol for this module */ diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index b64626087..472740d48 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -876,8 +876,10 @@ public: if (Getattr(n, "sym:overloaded")) { // Emit warnings for the few cases that can't be overloaded in Java and give up on generating wrapper Swig_overload_check(n); - if (Getattr(n, "overload:ignore")) + if (Getattr(n, "overload:ignore")) { + DelWrapper(f); return SWIG_OK; + } } Printf(imclass_class_code, " public final static native %s %s(", im_return_type, overloaded_name); diff --git a/Source/Modules/mzscheme.cxx b/Source/Modules/mzscheme.cxx index 99513dae3..c2abd7ec4 100644 --- a/Source/Modules/mzscheme.cxx +++ b/Source/Modules/mzscheme.cxx @@ -33,12 +33,10 @@ static String *convert_proto_tab = 0; static String *struct_name = 0; static String *mangled_struct_name = 0; -static char *prefix = 0; +static String *prefix = 0; static bool declaremodule = false; static bool noinit = false; -//DLOPEN PATCH -static char *load_libraries = NULL; -//DLOPEN PATCH +static String *load_libraries = NULL; static String *module = 0; static char *mzscheme_path = (char *) "mzscheme"; static String *init_func_def = 0; @@ -75,8 +73,7 @@ public: SWIG_exit(0); } else if (strcmp(argv[i], "-prefix") == 0) { if (argv[i + 1]) { - prefix = new char[strlen(argv[i + 1]) + 2]; - strcpy(prefix, argv[i + 1]); + prefix = NewString(argv[i + 1]); Swig_mark_arg(i); Swig_mark_arg(i + 1); i++; @@ -90,26 +87,27 @@ public: noinit = true; Swig_mark_arg(i); } -// DLOPEN PATCH else if (strcmp(argv[i], "-dynamic-load") == 0) { - load_libraries = new char[strlen(argv[i + 1]) + 2]; - strcpy(load_libraries, argv[i + 1]); - Swig_mark_arg(i++); - Swig_mark_arg(i); + if (argv[i + 1]) { + Delete(load_libraries); + load_libraries = NewString(argv[i + 1]); + Swig_mark_arg(i++); + Swig_mark_arg(i); + } else { + Swig_arg_error(); + } } -// DLOPEN PATCH } } - // If a prefix has been specified make sure it ends in a '_' + // If a prefix has been specified make sure it ends in a '_' (not actually used!) if (prefix) { - if (prefix[strlen(prefix)] != '_') { - prefix[strlen(prefix) + 1] = 0; - prefix[strlen(prefix)] = '_'; - } + const char *px = Char(prefix); + if (px[Len(prefix)] != '_') + Printf(prefix, "_"); } else - prefix = (char *) "swig_"; + prefix = NewString("swig_"); // Add a symbol for this module @@ -177,11 +175,9 @@ public: Printf(f_init, "\treturn scheme_void;\n}\n"); Printf(f_init, "Scheme_Object *scheme_initialize(Scheme_Env *env) {\n"); - // DLOPEN PATCH if (load_libraries) { Printf(f_init, "mz_set_dlopen_libraries(\"%s\");\n", load_libraries); } - // DLOPEN PATCH Printf(f_init, "\treturn scheme_reload(env);\n"); Printf(f_init, "}\n"); @@ -244,14 +240,12 @@ public: int numreq; String *overname = 0; - // PATCH DLOPEN if (load_libraries) { ParmList *parms = Getattr(n, "parms"); SwigType *type = Getattr(n, "type"); String *name = NewString("caller"); Setattr(n, "wrap:action", Swig_cresult(type, Swig_cresult_name(), Swig_cfunction_call(name, parms))); } - // PATCH DLOPEN // Make a wrapper name for this String *wname = Swig_name_wrapper(iname); @@ -291,7 +285,6 @@ public: numargs = emit_num_arguments(l); numreq = emit_num_required(l); - // DLOPEN PATCH /* Add the holder for the pointer to the function to be opened */ if (load_libraries) { Wrapper_add_local(f, "_function_loaded", "static int _function_loaded=(1==0)"); @@ -302,19 +295,16 @@ public: Wrapper_add_local(f, "caller", SwigType_lstr(d, func)); /*"(*caller)()")); */ } } - // DLOPEN PATCH // adds local variables Wrapper_add_local(f, "lenv", "int lenv = 1"); Wrapper_add_local(f, "values", "Scheme_Object *values[MAXVALUES]"); - // DLOPEN PATCH if (load_libraries) { Printf(f->code, "if (!_function_loaded) { _the_function=mz_load_function(\"%s\");_function_loaded=(1==1); }\n", iname); Printf(f->code, "if (!_the_function) { scheme_signal_error(\"Cannot load C function '%s'\"); }\n", iname); Printf(f->code, "caller=_the_function;\n"); } - // DLOPEN PATCH // Now write code to extract the parameters (this is super ugly) diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index 6204fd2ec..135cc89dc 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -30,7 +30,7 @@ static int in_constructor = 0, in_destructor = 0, in_copyconst = 0; static int const_enum = 0; static int static_member_function = 0; static int generate_sizeof = 0; -static char *prefix = 0; +static String *prefix = 0; static char *ocaml_path = (char *) "ocaml"; static bool old_variable_names = false; static String *classname = 0; @@ -107,8 +107,7 @@ public: SWIG_exit(0); } else if (strcmp(argv[i], "-prefix") == 0) { if (argv[i + 1]) { - prefix = new char[strlen(argv[i + 1]) + 2]; - strcpy(prefix, argv[i + 1]); + prefix = NewString(argv[i + 1]); Swig_mark_arg(i); Swig_mark_arg(i + 1); i++; @@ -130,15 +129,14 @@ public: } } - // If a prefix has been specified make sure it ends in a '_' + // If a prefix has been specified make sure it ends in a '_' (not actually used!) if (prefix) { - if (prefix[strlen(prefix)] != '_') { - prefix[strlen(prefix) + 1] = 0; - prefix[strlen(prefix)] = '_'; - } + const char *px = Char(prefix); + if (px[Len(prefix)] != '_') + Printf(prefix, "_"); } else - prefix = (char *) "swig_"; + prefix = NewString("swig_"); // Add a symbol for this module diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 4b42abae5..8a2ba7627 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -524,7 +524,6 @@ public: } virtual int functionWrapper(Node *n) { - Wrapper *f = NewWrapper(); Parm *p; String *tm; int j; @@ -551,6 +550,7 @@ public: if (!overloaded || last_overload) process_autodoc(n); + Wrapper *f = NewWrapper(); Octave_begin_function(n, f->def, iname, overname, !overloaded); emit_parameter_variables(l, f); @@ -859,6 +859,8 @@ public: Delete(getwname); Delete(setwname); + DelWrapper(setf); + DelWrapper(getf); return SWIG_OK; } diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index a0e8b3223..ab0d0e6b3 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2330,6 +2330,7 @@ done: Printf(f->code, "}\n"); Wrapper_print(f, s_wrappers); + DelWrapper(f); return SWIG_OK; } diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index a8cdc1cc8..9e931a38d 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -726,6 +726,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) { Delete(rtype); Delete(rettype); Delete(funcparams); + DelWrapper(f); return funName; } diff --git a/Source/Modules/uffi.cxx b/Source/Modules/uffi.cxx index 9e317f8bc..3b9a0abaa 100644 --- a/Source/Modules/uffi.cxx +++ b/Source/Modules/uffi.cxx @@ -47,7 +47,7 @@ static struct { String **entries; } defined_foreign_types; -static const char *identifier_converter = "identifier-convert-null"; +static String *identifier_converter = NewString("identifier-convert-null"); static int any_varargs(ParmList *pl) { Parm *p; @@ -221,14 +221,15 @@ void UFFI::main(int argc, char *argv[]) { /* check for built-ins */ if (!strcmp(conv, "lispify")) { - identifier_converter = "identifier-convert-lispify"; + Delete(identifier_converter); + identifier_converter = NewString("identifier-convert-lispify"); } else if (!strcmp(conv, "null")) { - identifier_converter = "identifier-convert-null"; + Delete(identifier_converter); + identifier_converter = NewString("identifier-convert-null"); } else { /* Must be user defined */ - char *idconv = new char[strlen(conv) + 1]; - strcpy(idconv, conv); - identifier_converter = idconv; + Delete(identifier_converter); + identifier_converter = NewString(conv); } } From fd24b188e24cdc9446413edf1d34635ab33f6ff7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 14 Nov 2012 22:17:28 +0000 Subject: [PATCH 0245/1160] Fix Coverity 'Uninitialized pointer fields' - member variables are now initialized git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13887 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/csharp.cxx | 4 ++- Source/Modules/d.cxx | 5 ++-- Source/Modules/java.cxx | 5 +++- Source/Modules/lua.cxx | 34 +++++++++++++++------- Source/Modules/octave.cxx | 21 ++++++++++++-- Source/Modules/ruby.cxx | 58 ++++++++++++++++++++----------------- Source/Modules/s-exp.cxx | 22 +++++++++----- Source/Modules/typepass.cxx | 9 +++++- 8 files changed, 104 insertions(+), 54 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 13c132a76..b8133b74a 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -156,7 +156,9 @@ public: dmethods_seq(NULL), dmethods_table(NULL), n_dmethods(0), - n_directors(0) { + n_directors(0), + first_class_dmethod(0), + curr_class_dmethod(0) { /* for now, multiple inheritance in directors is disabled, this should be easy to implement though */ director_multiple_inheritance = 0; diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index b21562c1d..17cb8babd 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -25,7 +25,6 @@ class D : public Language { const String *empty_string; const String *public_string; const String *protected_string; - const String *static_string; /* * Files and file sections containing C/C++ code. @@ -274,7 +273,9 @@ public: dmethods_seq(NULL), dmethods_table(NULL), n_dmethods(0), - unknown_types(NULL) { + unknown_types(NULL), + first_class_dmethod(0), + curr_class_dmethod(0) { // For now, multiple inheritance with directors is not possible. It should be // easy to implement though. diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 472740d48..1ee7a97e3 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -132,6 +132,7 @@ public: variable_name(NULL), proxy_class_constants_code(NULL), module_class_constants_code(NULL), + enum_code(NULL), package(NULL), jnipackage(NULL), package_path(NULL), @@ -151,7 +152,9 @@ public: dmethods_seq(NULL), dmethods_table(NULL), n_dmethods(0), - n_directors(0) { + n_directors(0), + first_class_dmethod(0), + curr_class_dmethod(0) { /* for now, multiple inheritance in directors is disabled, this should be easy to implement though */ director_multiple_inheritance = 0; diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 66ba8ea6f..3d1530331 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -145,17 +145,29 @@ public: * Initialize member data * --------------------------------------------------------------------- */ - LUA() { - f_begin = 0; - f_runtime = 0; - f_header = 0; - f_wrappers = 0; - f_init = 0; - f_initbeforefunc = 0; - PrefixPlusUnderscore = 0; - - s_cmd_tab = s_var_tab = s_const_tab = s_luacode = 0; - current=NO_CPP; + LUA() : + f_begin(0), + f_runtime(0), + f_header(0), + f_wrappers(0), + f_init(0), + f_initbeforefunc(0), + PrefixPlusUnderscore(0), + s_cmd_tab(0), + s_var_tab(0), + s_const_tab(0), + s_methods_tab(0), + s_attr_tab(0), + s_luacode(0), + s_dot_get(0), + s_dot_set(0), + s_vars_meta_tab(0), + have_constructor(0), + have_destructor(0), + destructor_action(0), + class_name(0), + constructor_name(0), + current(NO_CPP) { } /* NEW LANGUAGE NOTE:*********************************************** diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 8a2ba7627..f78c71fd3 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -58,9 +58,24 @@ private: } public: - OCTAVE():f_begin(0), f_runtime(0), f_header(0), f_doc(0), f_wrappers(0), - f_init(0), f_initbeforefunc(0), f_directors(0), f_directors_h(0), - s_global_tab(0), s_members_tab(0), class_name(0) { + OCTAVE(): + f_begin(0), + f_runtime(0), + f_header(0), + f_doc(0), + f_wrappers(0), + f_init(0), + f_initbeforefunc(0), + f_directors(0), + f_directors_h(0), + s_global_tab(0), + s_members_tab(0), + class_name(0), + have_constructor(0), + have_destructor(0), + constructor_name(0), + docs(0) + { /* Add code to manage protected constructors and directors */ director_prot_ctor_code = NewString(""); Printv(director_prot_ctor_code, diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index a1523a7ad..053143899 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -810,33 +810,37 @@ public: * * Initialize member data * --------------------------------------------------------------------- */ - - RUBY() { - module = 0; - modvar = 0; - feature = 0; - prefix = 0; - last_autodoc = NewString(""); - current = NO_CPP; - classes = 0; - klass = 0; - special_methods = 0; - f_begin = 0; - f_runtime = 0; - f_header = 0; - f_wrappers = 0; - f_init = 0; - f_initbeforefunc = 0; - useGlobalModule = false; - multipleInheritance = false; - director_prot_ctor_code = NewString(""); - Printv(director_prot_ctor_code, - "if ( $comparison ) { /* subclassed */\n", - " $director_new \n", - "} else {\n", " rb_raise(rb_eRuntimeError,\"accessing abstract class or protected constructor\"); \n", " return Qnil;\n", "}\n", NIL); - director_multiple_inheritance = 0; - director_language = 1; - } + RUBY() : + module(0), + modvar(0), + feature(0), + prefix(0), + current(0), + classes(0), + klass(0), + special_methods(0), + f_directors(0), + f_directors_h(0), + f_directors_helpers(0), + f_begin(0), + f_runtime(0), + f_runtime_h(0), + f_header(0), + f_wrappers(0), + f_init(0), + f_initbeforefunc(0), + useGlobalModule(false), + multipleInheritance(false) { + last_autodoc = NewString(""); + current = NO_CPP; + director_prot_ctor_code = NewString(""); + Printv(director_prot_ctor_code, + "if ( $comparison ) { /* subclassed */\n", + " $director_new \n", + "} else {\n", " rb_raise(rb_eRuntimeError,\"accessing abstract class or protected constructor\"); \n", " return Qnil;\n", "}\n", NIL); + director_multiple_inheritance = 0; + director_language = 1; + } /* --------------------------------------------------------------------- * main() diff --git a/Source/Modules/s-exp.cxx b/Source/Modules/s-exp.cxx index 9f2cda2f2..3c50f3076 100644 --- a/Source/Modules/s-exp.cxx +++ b/Source/Modules/s-exp.cxx @@ -24,9 +24,21 @@ S-Exp Options (available with -sexp)\n\ static File *out = 0; class Sexp:public Language { -public: int indent_level; - Sexp():indent_level(0) { + DOHHash *print_circle_hash; + int print_circle_count; + int hanging_parens; + bool need_whitespace; + bool need_newline; + +public: + Sexp(): + indent_level(0), + print_circle_hash(0), + print_circle_count(0), + hanging_parens(0), + need_whitespace(0), + need_newline(0) { } virtual ~ Sexp() { @@ -51,12 +63,6 @@ public: } } - DOHHash *print_circle_hash; - int print_circle_count; - int hanging_parens; - bool need_whitespace; - bool need_newline; - /* Top of the parse tree */ virtual int top(Node *n) { if (out == 0) { diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index a6012c0bf..90318b122 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -40,7 +40,14 @@ class TypePass:private Dispatcher { Hash *classhash; List *normalize; - TypePass() { + TypePass() : + inclass(0), + module(0), + importmode(0), + nsname(0), + nssymname(0), + classhash(0), + normalize(0) { } /* Normalize a type. Replaces type with fully qualified version */ From bee563e788b534e9eb3a3575112a578aaf05a052 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 14 Nov 2012 22:17:52 +0000 Subject: [PATCH 0246/1160] ccache-swig: apply patch #3586392 from Frederik Deweerdt to fix some error cases - incorrectly using memory after it has been deleted git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13888 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CCache/ccache.c | 3 ++- CHANGES.current | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CCache/ccache.c b/CCache/ccache.c index d1696da88..e7dd1d30a 100644 --- a/CCache/ccache.c +++ b/CCache/ccache.c @@ -712,12 +712,13 @@ static void from_cache(int first) passfail = retrieve_from_cache(hashname, output_file, hardlink); } - free(stderr_file); if (passfail == -1) { close(fd_stderr); unlink(stderr_file); + free(stderr_file); return; } + free(stderr_file); } /* get rid of the intermediate preprocessor file */ diff --git a/CHANGES.current b/CHANGES.current index 15337ca00..2932b5003 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.9 (in progress) =========================== +2012-11-14: [ccache-swig] Apply patch #3586392 from Frederik Deweerdt to fix some error cases - incorrectly using + memory after it has been deleted. + 2012-11-09: vzeitlin [Python] Fix overflow when passing values greater than LONG_MAX from Python 3 for parameters with unsigned long C type. From 684bd8e472ab2b045d153a584eac9345363a4e7a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 14 Nov 2012 22:48:09 +0000 Subject: [PATCH 0247/1160] Minor warning fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13889 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/d.cxx | 4 ++-- Source/Modules/typepass.cxx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 17cb8babd..4f110fb8d 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -273,9 +273,9 @@ public: dmethods_seq(NULL), dmethods_table(NULL), n_dmethods(0), - unknown_types(NULL), first_class_dmethod(0), - curr_class_dmethod(0) { + curr_class_dmethod(0), + unknown_types(NULL) { // For now, multiple inheritance with directors is not possible. It should be // easy to implement though. diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index 90318b122..192c85ba6 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -717,7 +717,7 @@ class TypePass:private Dispatcher { * destructorDeclaration() * ------------------------------------------------------------ */ - virtual int destructorDeclaration(Node *n) { + virtual int destructorDeclaration(Node *) { return SWIG_OK; } From 51a1aa5b1aad1985e10b35a57127944f665d24f9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 14 Nov 2012 22:51:39 +0000 Subject: [PATCH 0248/1160] Add coverity target to build coverity analysis and upload to coverity server for online analysis git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13890 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Makefile.in | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Makefile.in b/Makefile.in index 644275773..0e79a77da 100644 --- a/Makefile.in +++ b/Makefile.in @@ -523,4 +523,18 @@ $(srcdir)/configure: $(srcdir)/configure.in cd $(srcdir) && ./autogen.sh $(SHELL) ./config.status --recheck +############################################################################ +# Tools +############################################################################ + +# Coverity static code analyser build and submit - EMAIL and PASSWORD need specifying +# See http://scan.coverity.com/start/ +EMAIL=wsf@fultondesigns.co.uk +PASSWORD= +coverity: + $(MAKE) clean-source + cov-build --dir cov-int $(MAKE) + tar czvf swig-coverity.tgz cov-int + curl --form file=@swig-coverity.tgz --form project=swig --form password=$(PASSWORD) --form email=$(EMAIL) http://scan5.coverity.com/cgi-bin/upload.py + # Makefile ends here From e475ce1d6be882219e335865c825f14c76c8de22 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 16 Nov 2012 19:32:40 +0000 Subject: [PATCH 0249/1160] Fix race condition 'time of check time of use' - TOCTOU - when creating subdirectories. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13891 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/misc.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index a9aacc02e..9881717ee 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -172,7 +172,6 @@ static int is_directory(String *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 || is_directory(basedirectory)) { @@ -181,30 +180,23 @@ String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) { List *subdirs = Split(subdirectory, SWIG_FILE_DELIMITER[0], INT_MAX); for (it = First(subdirs); it.item; it = Next(it)) { - int statdir; + int result; 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)); + result = _mkdir(Char(dir)); #else - int result = mkdir(Char(dir), 0777); + result = mkdir(Char(dir), 0777); #endif - Printf(dir, SWIG_FILE_DELIMITER); - if (result != 0 && errno != EEXIST) { - error = NewStringf("Cannot create directory %s", dir); - break; - } + if (result != 0 && errno != EEXIST) { + error = NewStringf("Cannot create directory %s: %s", dir, strerror(errno)); + break; } + if (!is_directory(dir)) { + error = NewStringf("Cannot create directory %s: it may already exist but not be a directory", dir); + break; + } + Printf(dir, SWIG_FILE_DELIMITER); } } else { 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); From e87e94572e71ea4f307858dd6f5c3c24546cda35 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 16 Nov 2012 19:33:43 +0000 Subject: [PATCH 0250/1160] Fix unused variables found by Coverity checker git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13892 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/CParse/parser.y | 1 - Source/Preprocessor/cpp.c | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 724b2ef69..2774014ab 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1004,7 +1004,6 @@ static String *resolve_create_node_scope(String *cname) { } else { /* now this last part is a class */ si = Next(si); - ns1 = Swig_symbol_clookup(sname,0); /* or a nested class tree, which is unrolled here */ for (; si.item; si = Next(si)) { if (si.item) { diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index b3e0549f5..d68658eb6 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -1213,13 +1213,10 @@ static DOH *Preprocessor_replace(DOH *s) { Replaceall(fn, "\\", "\\\\"); Printf(ns, "\"%s\"", fn); Delete(fn); - } else if ((m = Getattr(symbols, id))) { + } else if (Getattr(symbols, id)) { DOH *e; /* Yes. There is a macro here */ /* See if the macro expects arguments */ - /* if (Getattr(m,"args")) { - Swig_error(Getfile(id),Getline(id),"Macro arguments expected.\n"); - } */ e = expand_macro(id, 0, s); if (e) Append(ns, e); From ec08824561398fe41033e2970147507a3b6ba741 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 16 Nov 2012 19:35:33 +0000 Subject: [PATCH 0251/1160] Remove pointless null pointer check - Coverity REVERSE_INULL. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13893 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/typemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index 5007d76a8..c36eef679 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -1330,7 +1330,7 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No /* Special hook (hack!). Check for the 'ref' feature and add code it contains to any 'newfree' typemap code. * We could choose to put this hook into a number of different typemaps, not necessarily 'newfree'... * Rather confusingly 'newfree' is used to release memory and the 'ref' feature is used to add in memory references - yuck! */ - if (node && Cmp(tmap_method, "newfree") == 0) { + if (Cmp(tmap_method, "newfree") == 0) { String *base = SwigType_base(type); Node *typenode = Swig_symbol_clookup(base, 0); if (typenode) From 5e13cd3475b71433e8bf954a38d33096cc0e5f50 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 16 Nov 2012 19:36:46 +0000 Subject: [PATCH 0252/1160] Consider strchr failing in a few places git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13894 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/typeobj.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index b8ecf6e6a..07234f3b4 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -627,8 +627,8 @@ int SwigType_prefix_is_simple_1D_array(const SwigType *t) { if (c && (strncmp(c, "a(", 2) == 0)) { c = strchr(c, '.'); - c++; - return (*c == 0); + if (c) + return (*(++c) == 0); } return 0; } @@ -654,8 +654,10 @@ int SwigType_array_ndim(const SwigType *t) { while (c && (strncmp(c, "a(", 2) == 0)) { c = strchr(c, '.'); - c++; - ndim++; + if (c) { + c++; + ndim++; + } } return ndim; } @@ -665,8 +667,10 @@ String *SwigType_array_getdim(const SwigType *t, int n) { char *c = Char(t); while (c && (strncmp(c, "a(", 2) == 0) && (n > 0)) { c = strchr(c, '.'); - c++; - n--; + if (c) { + c++; + n--; + } } if (n == 0) { String *dim = SwigType_parm(c); @@ -695,8 +699,10 @@ void SwigType_array_setdim(SwigType *t, int n, const_String_or_char_ptr rep) { while (c && (strncmp(c, "a(", 2) == 0) && (n > 0)) { c = strchr(c, '.'); - c++; - n--; + if (c) { + c++; + n--; + } } if (n == 0) { temp = *c; From c0919870f84a4666677c7f4e760f13bbcac7c579 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 16 Nov 2012 19:37:40 +0000 Subject: [PATCH 0253/1160] Add assertion for possible failure displaying warning git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13895 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/CParse/templ.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/CParse/templ.c b/Source/CParse/templ.c index 503f725cb..b14cd1e4d 100644 --- a/Source/CParse/templ.c +++ b/Source/CParse/templ.c @@ -766,6 +766,7 @@ static Node *template_locate(String *name, Parm *tparms, Symtab *tscope) { for (i = 1; i < posslen; i++) { String *templcsymname = Getattr(Getitem(possiblepartials, i), "templcsymname"); Node *ignored_node = Swig_symbol_clookup_local(templcsymname, primary_scope); + assert(ignored_node); Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, Getfile(ignored_node), Getline(ignored_node), " instantiation '%s' ignored.\n", SwigType_namestr(Getattr(ignored_node, "name"))); } } From 3d6b068b8c7db307dda236b8bd1ebec5ffdcce50 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 16 Nov 2012 19:38:48 +0000 Subject: [PATCH 0254/1160] Add some assertions around use of Tell git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13896 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/DOH/fio.c | 1 + Source/Preprocessor/cpp.c | 1 + 2 files changed, 2 insertions(+) diff --git a/Source/DOH/fio.c b/Source/DOH/fio.c index 4e91a1b51..43f6dc3cf 100644 --- a/Source/DOH/fio.c +++ b/Source/DOH/fio.c @@ -76,6 +76,7 @@ static DOH *encode(char *name, DOH *s) { Seek(s, 0, SEEK_SET); fn = (DOH *(*)(DOH *)) Data(handle); ns = (*fn) (s); + assert(pos != -1); Seek(s, pos, SEEK_SET); if (tmp) Delete(tmp); diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index d68658eb6..5a7634f91 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -583,6 +583,7 @@ static List *find_args(String *s, int ismacro, String *macro_name) { c = Getc(s); if (c != '(') { /* Not a macro, bail out now! */ + assert(pos != -1); Seek(s, pos, SEEK_SET); Delete(args); return 0; From b107f57e591147f262f613f61730827e3c7d71fd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 16 Nov 2012 19:39:50 +0000 Subject: [PATCH 0255/1160] NULL pointer clarification in Swig_new_subdirectory git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13897 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/misc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 9881717ee..ca471b72a 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -167,16 +167,16 @@ static int is_directory(String *directory) { * 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. + * basedirectory can be empty to indicate current directory but not NULL. * ----------------------------------------------------------------------------- */ String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) { String *error = 0; - int current_directory = basedirectory ? (Len(basedirectory) == 0 ? 1 : 0) : 0; + int current_directory = Len(basedirectory) == 0; if (current_directory || is_directory(basedirectory)) { Iterator it; - String *dir = basedirectory ? NewString(basedirectory) : NewString(""); + String *dir = NewString(basedirectory); List *subdirs = Split(subdirectory, SWIG_FILE_DELIMITER[0], INT_MAX); for (it = First(subdirs); it.item; it = Next(it)) { From 69b32d921f9a2a257c5efb4a1694ff0e8526e0c5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 18 Nov 2012 00:43:09 +0000 Subject: [PATCH 0256/1160] Remove pointless null check git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13899 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/typemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index c36eef679..2570e8090 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -1341,7 +1341,7 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No pname = Getattr(node, "name"); noscope_pname = Copy(pname); - if (pname && node && Getattr(node, "sym:symtab")) { + if (pname && Getattr(node, "sym:symtab")) { /* Add on a qualified name search for any symbol in the symbol table, for example: * struct Foo { * int *foo(int bar) -> Foo::foo From 111b517372e840979e78064b22888c1539bb5ec7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 18 Nov 2012 00:43:31 +0000 Subject: [PATCH 0257/1160] Fix possible null dereferences git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13900 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/typesys.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index 73c2fbd50..76d84c960 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -668,7 +668,7 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) { Printf(stdout, "namebase = '%s'\n", namebase); #endif type = typedef_resolve(s, namebase); - if (type) { + if (type && resolved_scope) { /* we need to look for the resolved type, this will also fix the resolved_scope if 'type' and 'namebase' are declared in different scopes */ @@ -680,7 +680,7 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) { #ifdef SWIG_DEBUG Printf(stdout, "%s type = '%s'\n", Getattr(s, "name"), type); #endif - if ((type) && (!Swig_scopename_check(type)) && resolved_scope) { + if (type && (!Swig_scopename_check(type)) && resolved_scope) { Typetab *rtab = resolved_scope; String *qname = Getattr(resolved_scope, "qname"); /* If qualified *and* the typename is defined from the resolved scope, we qualify */ @@ -898,7 +898,7 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) { e = ty; } resolved_scope = 0; - if (typedef_resolve(current_scope, e)) { + if (typedef_resolve(current_scope, e) && resolved_scope) { /* resolved_scope contains the scope that actually resolved the symbol */ String *qname = Getattr(resolved_scope, "qname"); if (qname) { From 0baa87809febb1e7a751507bbce88cc47bbc90c0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 18 Nov 2012 00:43:53 +0000 Subject: [PATCH 0258/1160] Remove unnecessary non-null check git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13901 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/scanner.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index 31dc7522f..eec2201a1 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -209,10 +209,8 @@ static char nextchar(Scanner * s) { if (Len(s->scanobjs) == 0) return 0; s->str = Getitem(s->scanobjs, 0); - if (s->str) { - s->line = Getline(s->str); - DohIncref(s->str); - } + s->line = Getline(s->str); + DohIncref(s->str); } if ((nc == '\n') && (!s->freeze_line)) s->line++; From 475c6c6ce0146406d70d36dfe92deb42b8fa10e4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 18 Nov 2012 00:44:19 +0000 Subject: [PATCH 0259/1160] Suppress some unchecked return value warnings for Coverity git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13902 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/DOH/fio.c | 2 +- Source/Preprocessor/cpp.c | 2 +- Source/Swig/scanner.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/DOH/fio.c b/Source/DOH/fio.c index 43f6dc3cf..3557b3c37 100644 --- a/Source/DOH/fio.c +++ b/Source/DOH/fio.c @@ -77,7 +77,7 @@ static DOH *encode(char *name, DOH *s) { fn = (DOH *(*)(DOH *)) Data(handle); ns = (*fn) (s); assert(pos != -1); - Seek(s, pos, SEEK_SET); + (void)Seek(s, pos, SEEK_SET); if (tmp) Delete(tmp); return ns; diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 5a7634f91..b6426f5ab 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -584,7 +584,7 @@ static List *find_args(String *s, int ismacro, String *macro_name) { if (c != '(') { /* Not a macro, bail out now! */ assert(pos != -1); - Seek(s, pos, SEEK_SET); + (void)Seek(s, pos, SEEK_SET); Delete(args); return 0; } diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index eec2201a1..8b1c6183e 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -271,7 +271,7 @@ static void retract(Scanner * s, int n) { if (str[l - 1] == '\n') { if (!s->freeze_line) s->line--; } - Seek(s->str, -1, SEEK_CUR); + (void)Seek(s->str, -1, SEEK_CUR); Delitem(s->text, DOH_END); } } @@ -1317,7 +1317,7 @@ void Scanner_locator(Scanner *s, String *loc) { } else { int c; Locator *l; - Seek(loc, 7, SEEK_SET); + (void)Seek(loc, 7, SEEK_SET); c = Getc(loc); if (c == '@') { /* Empty locator. We pop the last location off */ From e450d4ebaca658c752dc8e5c9dd02e726cd064c5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 18 Nov 2012 00:44:39 +0000 Subject: [PATCH 0260/1160] Remove some possible buffer overflows git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13903 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/typeobj.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index 07234f3b4..2e8d08f10 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -430,7 +430,7 @@ int SwigType_isreference(const SwigType *t) { * ----------------------------------------------------------------------------- */ SwigType *SwigType_add_qualifier(SwigType *t, const_String_or_char_ptr qual) { - char temp[256], newq[256]; + String *newq; int sz, added = 0; char *q, *cqual; @@ -438,8 +438,9 @@ SwigType *SwigType_add_qualifier(SwigType *t, const_String_or_char_ptr qual) { cqual = Char(qual); if (!(strncmp(c, "q(", 2) == 0)) { - sprintf(temp, "q(%s).", cqual); + String *temp = NewStringf("q(%s).", cqual); Insert(t, 0, temp); + Delete(temp); return t; } @@ -449,40 +450,40 @@ SwigType *SwigType_add_qualifier(SwigType *t, const_String_or_char_ptr qual) { order */ sz = element_size(c); - strncpy(temp, c, (sz < 256) ? sz : 256); - if (strstr(temp, cqual)) { + if (strstr(c, cqual)) { /* Qualifier already added */ return t; } /* Add the qualifier to the existing list. */ - strcpy(newq, "q("); - q = temp + 2; + newq = NewString("q("); + q = c + 2; q = strtok(q, " )."); while (q) { if (strcmp(cqual, q) < 0) { /* New qualifier is less that current qualifier. We need to insert it */ - strcat(newq, cqual); - strcat(newq, " "); - strcat(newq, q); + Append(newq, cqual); + Append(newq, " "); + Append(newq, q); added = 1; } else { - strcat(newq, q); + Append(newq, q); } q = strtok(NULL, " )."); if (q) { - strcat(newq, " "); + Append(newq, " "); } } if (!added) { - strcat(newq, " "); - strcat(newq, cqual); + Append(newq, " "); + Append(newq, cqual); } - strcat(newq, ")."); + Append(newq, ")."); Delslice(t, 0, sz); Insert(t, 0, newq); + Delete(newq); return t; } @@ -590,11 +591,11 @@ int SwigType_ismemberpointer(const SwigType *t) { * ----------------------------------------------------------------------------- */ SwigType *SwigType_add_array(SwigType *t, const_String_or_char_ptr size) { - char temp[512]; - strcpy(temp, "a("); - strcat(temp, Char(size)); - strcat(temp, ")."); + String *temp = NewString("a("); + Append(temp, size); + Append(temp, ")."); Insert(t, 0, temp); + Delete(temp); return t; } From d918bddfc09c8f59fa45b1772cba106b663003b3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 18 Nov 2012 00:45:18 +0000 Subject: [PATCH 0261/1160] Fix segfaults when using filename paths greater than 1024 characters in length - use String * and heap instead of fixed size static char array buffers. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13904 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 6 +++- Source/Modules/csharp.cxx | 7 +++-- Source/Modules/d.cxx | 7 +++-- Source/Modules/go.cxx | 4 ++- Source/Modules/java.cxx | 7 +++-- Source/Modules/main.cxx | 41 +++++++++++++++----------- Source/Modules/php.cxx | 4 ++- Source/Modules/python.cxx | 7 +++-- Source/Modules/ruby.cxx | 7 +++-- Source/Preprocessor/cpp.c | 20 +++++++++---- Source/Swig/include.c | 60 ++++++++++++++------------------------- Source/Swig/swigfile.h | 8 +++--- 12 files changed, 100 insertions(+), 78 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 2932b5003..39da2bb4f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,7 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.9 (in progress) =========================== -2012-11-14: [ccache-swig] Apply patch #3586392 from Frederik Deweerdt to fix some error cases - incorrectly using +2012-11-17: wsfulton + Fix segfaults when using filename paths greater than 1024 characters in length. + +2012-11-14: wsfulton + [ccache-swig] Apply patch #3586392 from Frederik Deweerdt to fix some error cases - incorrectly using memory after it has been deleted. 2012-11-09: vzeitlin diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index b8133b74a..9f902b76d 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -405,8 +405,11 @@ public: Printf(f_directors, "/* ---------------------------------------------------\n"); Printf(f_directors, " * C++ director class methods\n"); Printf(f_directors, " * --------------------------------------------------- */\n\n"); - if (outfile_h) - Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h)); + if (outfile_h) { + String *filename = Swig_file_filename(outfile_h); + Printf(f_directors, "#include \"%s\"\n\n", filename); + Delete(filename); + } } Printf(f_runtime, "\n"); diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 4f110fb8d..503f90069 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -490,8 +490,11 @@ public: Printf(f_directors, "/* ---------------------------------------------------\n"); Printf(f_directors, " * C++ director class methods\n"); Printf(f_directors, " * --------------------------------------------------- */\n\n"); - if (outfile_h) - Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h)); + if (outfile_h) { + String *filename = Swig_file_filename(outfile_h); + Printf(f_directors, "#include \"%s\"\n\n", filename); + Delete(filename); + } } Printf(f_runtime, "\n"); diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 7c34f8b9a..347cf33a4 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -371,7 +371,9 @@ private: 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)); + String *filename = Swig_file_filename(c_filename_h); + Printf(f_c_directors, "#include \"%s\"\n\n", filename); + Delete(filename); } Swig_banner(f_go_begin); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 1ee7a97e3..14cfeaf20 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -417,8 +417,11 @@ public: Printf(f_directors, "/* ---------------------------------------------------\n"); Printf(f_directors, " * C++ director class methods\n"); Printf(f_directors, " * --------------------------------------------------- */\n\n"); - if (outfile_h) - Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h)); + if (outfile_h) { + String *filename = Swig_file_filename(outfile_h); + Printf(f_directors, "#include \"%s\"\n\n", filename); + Delete(filename); + } } Printf(f_runtime, "\n"); diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index 8e2b428f4..d2876c16f 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -199,22 +199,24 @@ static List *libfiles = 0; static List *all_output_files = 0; /* ----------------------------------------------------------------------------- - * check_suffix() + * check_extension() * - * Checks the suffix of a file to see if we should emit extern declarations. + * Checks the extension of a file to see if we should emit extern declarations. * ----------------------------------------------------------------------------- */ -static int check_suffix(String *filename) { +static bool check_extension(String *filename) { + bool wanted = false; const char *name = Char(filename); - const char *c; if (!name) return 0; - c = Swig_file_suffix(name); + String *extension = Swig_file_extension(name); + const char *c = Char(extension); if ((strcmp(c, ".c") == 0) || (strcmp(c, ".C") == 0) || (strcmp(c, ".cc") == 0) || (strcmp(c, ".cxx") == 0) || (strcmp(c, ".c++") == 0) || (strcmp(c, ".cpp") == 0)) { - return 1; + wanted = true; } - return 0; + Delete(extension); + return wanted; } /* ----------------------------------------------------------------------------- @@ -283,15 +285,16 @@ static unsigned int decode_numbers_list(String *numlist) { } /* ----------------------------------------------------------------------------- - * 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 from the + * C wrapper file if not set and corrects the directory name and adds a trailing + * file separator if necessary. * ----------------------------------------------------------------------------- */ -static void configure_outdir(const String *c_wrapper_file_dir) { +static void configure_outdir(const String *c_wrapper_outfile) { // 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); + outdir = Swig_file_dirname(c_wrapper_outfile); Swig_filename_correct(outdir); @@ -1068,7 +1071,8 @@ int SWIG_main(int argc, char *argv[], Language *l) { String *outfile; File *f_dependencies_file = 0; - char *basename = Swig_file_basename(outcurrentdir ? Swig_file_filename(input_file): Char(input_file)); + String *inputfile_filename = outcurrentdir ? Swig_file_filename(input_file): Copy(input_file); + String *basename = Swig_file_basename(inputfile_filename); if (!outfile_name) { if (CPlusPlus || lang->cplus_runtime_mode()) { outfile = NewStringf("%s_wrap.%s", basename, cpp_extension); @@ -1113,6 +1117,8 @@ int SWIG_main(int argc, char *argv[], Language *l) { Delete(f_dependencies_file); if (depend_only) SWIG_exit(EXIT_SUCCESS); + Delete(inputfile_filename); + Delete(basename); } else { Printf(stderr, "Cannot generate dependencies with -nopreprocess\n"); // Actually we could but it would be inefficient when just generating dependencies, as it would be done after Swig_cparse @@ -1220,7 +1226,8 @@ int SWIG_main(int argc, char *argv[], Language *l) { Setattr(top, "infile", infile); // Note: if nopreprocess then infile is the original input file, otherwise input_file Setattr(top, "inputfile", input_file); - char *basename = Swig_file_basename(outcurrentdir ? Swig_file_filename(infile): Char(infile)); + String *infile_filename = outcurrentdir ? Swig_file_filename(infile): Copy(infile); + String *basename = Swig_file_basename(infile_filename); if (!outfile_name) { if (CPlusPlus || lang->cplus_runtime_mode()) { Setattr(top, "outfile", NewStringf("%s_wrap.%s", basename, cpp_extension)); @@ -1235,19 +1242,21 @@ int SWIG_main(int argc, char *argv[], Language *l) { } else { Setattr(top, "outfile_h", outfile_name_h); } - configure_outdir(Swig_file_dirname(Getattr(top, "outfile"))); + configure_outdir(Getattr(top, "outfile")); if (Swig_contract_mode_get()) { Swig_contracts(top); } - // Check the suffix for a c/c++ file. If so, we're going to declare everything we see as "extern" - ForceExtern = check_suffix(input_file); + // Check the extension for a c/c++ file. If so, we're going to declare everything we see as "extern" + ForceExtern = check_extension(input_file); lang->top(top); if (browse) { Swig_browser(top, 0); } + Delete(infile_filename); + Delete(basename); } } if (dump_lang_symbols) { diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index ab0d0e6b3..1f2078a1e 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -354,7 +354,9 @@ public: Printf(f_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", cap_module); Printf(f_directors_h, "#define SWIG_%s_WRAP_H_\n\n", cap_module); - Printf(f_directors, "\n#include \"%s\"\n\n", Swig_file_filename(outfile_h)); + String *filename = Swig_file_filename(outfile_h); + Printf(f_directors, "\n#include \"%s\"\n\n", filename); + Delete(filename); } /* PHP module file */ diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 9d1b3a772..dcf6699b1 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -763,8 +763,11 @@ public: Printf(f_directors, "/* ---------------------------------------------------\n"); Printf(f_directors, " * C++ director class methods\n"); Printf(f_directors, " * --------------------------------------------------- */\n\n"); - if (outfile_h) - Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h)); + if (outfile_h) { + String *filename = Swig_file_filename(outfile_h); + Printf(f_directors, "#include \"%s\"\n\n", filename); + Delete(filename); + } } /* If shadow classing is enabled, we're going to change the module name to "_module" */ diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 053143899..e31d3b72c 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -1142,8 +1142,11 @@ public: Printf(f_directors, "/* ---------------------------------------------------\n"); Printf(f_directors, " * C++ director class methods\n"); Printf(f_directors, " * --------------------------------------------------- */\n\n"); - if (outfile_h) - Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h)); + if (outfile_h) { + String *filename = Swig_file_filename(outfile_h); + Printf(f_directors, "#include \"%s\"\n\n", filename); + Delete(filename); + } Delete(module_macro); } diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index b6426f5ab..4366a8434 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -1706,7 +1706,7 @@ String *Preprocessor_parse(String *s) { } else if (Equal(id, kpp_include)) { if (((include_all) || (import_all)) && (allow)) { String *s1, *s2, *fn; - char *dirname; + String *dirname; int sysfile = 0; if (include_all && import_all) { Swig_warning(WARN_PP_INCLUDEALL_IMPORTALL, Getfile(s), Getline(id), "Both includeall and importall are defined: using includeall.\n"); @@ -1725,10 +1725,13 @@ String *Preprocessor_parse(String *s) { /* See if the filename has a directory component */ dirname = Swig_file_dirname(Swig_last_file()); - if (sysfile || !strlen(dirname)) + if (sysfile || !Len(dirname)) { + Delete(dirname); dirname = 0; + } if (dirname) { - dirname[strlen(dirname) - 1] = 0; /* Kill trailing directory delimiter */ + int len = Len(dirname); + Delslice(dirname, len - 1, len); /* Kill trailing directory delimiter */ Swig_push_directory(dirname); } s2 = Preprocessor_parse(s1); @@ -1741,6 +1744,7 @@ String *Preprocessor_parse(String *s) { pop_imported(); } Delete(s2); + Delete(dirname); Delete(s1); } Delete(fn); @@ -1858,7 +1862,7 @@ String *Preprocessor_parse(String *s) { fn = get_filename(s, &sysfile); s1 = cpp_include(fn, sysfile); if (s1) { - char *dirname; + String *dirname; copy_location(s, chunk); add_chunk(ns, chunk, allow); Printf(ns, "%sfile%s%s%s\"%s\" %%beginfile\n", decl, options_whitespace, opt, filename_whitespace, Swig_filename_escape(Swig_last_file())); @@ -1866,10 +1870,13 @@ String *Preprocessor_parse(String *s) { push_imported(); } dirname = Swig_file_dirname(Swig_last_file()); - if (sysfile || !strlen(dirname)) + if (sysfile || !strlen(dirname)) { + Delete(dirname); dirname = 0; + } if (dirname) { - dirname[strlen(dirname) - 1] = 0; /* Kill trailing directory delimiter */ + int len = Len(dirname); + Delslice(dirname, len - 1, len); /* Kill trailing directory delimiter */ Swig_push_directory(dirname); } s2 = Preprocessor_parse(s1); @@ -1882,6 +1889,7 @@ String *Preprocessor_parse(String *s) { addline(ns, s2, allow); Append(ns, "%endoffile"); Delete(s2); + Delete(dirname); Delete(s1); } Delete(fn); diff --git a/Source/Swig/include.c b/Source/Swig/include.c index 3766894ae..6e76f86ba 100644 --- a/Source/Swig/include.c +++ b/Source/Swig/include.c @@ -317,58 +317,49 @@ File *Swig_filebyname(const_String_or_char_ptr filename) { } /* ----------------------------------------------------------------------------- - * Swig_file_suffix() + * Swig_file_extension() * - * Returns the suffix of a file + * Returns the extension of a file * ----------------------------------------------------------------------------- */ -char *Swig_file_suffix(const_String_or_char_ptr filename) { - char *d; - char *c = Char(filename); +String *Swig_file_extension(const_String_or_char_ptr filename) { + const char *d; + const char *c = Char(filename); int len = Len(filename); if (strlen(c)) { d = c + len - 1; while (d != c) { if (*d == '.') - return d; + return NewString(d); d--; } - return c + len; + return NewString(c + len); } - return c; + return NewString(c); } /* ----------------------------------------------------------------------------- * Swig_file_basename() * - * Returns the filename with no suffix attached. + * Returns the filename with the extension removed. * ----------------------------------------------------------------------------- */ -char *Swig_file_basename(const_String_or_char_ptr filename) { - static char tmp[1024]; - char *c; - strcpy(tmp, Char(filename)); - c = Swig_file_suffix(tmp); - *c = 0; - return tmp; +String *Swig_file_basename(const_String_or_char_ptr filename) { + String *extension = Swig_file_extension(filename); + String *basename = DohNewStringWithSize(filename, Len(filename) - Len(extension)); + Delete(extension); + return basename; } /* ----------------------------------------------------------------------------- * Swig_file_filename() * - * Return the file with any leading path stripped off + * Return the file name with any leading path stripped off * ----------------------------------------------------------------------------- */ -char *Swig_file_filename(const_String_or_char_ptr filename) { - static char tmp[1024]; +String *Swig_file_filename(const_String_or_char_ptr filename) { const char *delim = SWIG_FILE_DELIMITER; - char *c; - - strcpy(tmp, Char(filename)); - c = strrchr(tmp, *delim); - if (c) - return c + 1; - else - return tmp; + const char *c = strrchr(Char(filename), *delim); + return c ? NewString(c + 1) : NewString(filename); } /* ----------------------------------------------------------------------------- @@ -376,19 +367,10 @@ char *Swig_file_filename(const_String_or_char_ptr filename) { * * Return the name of the directory associated with a file * ----------------------------------------------------------------------------- */ -char *Swig_file_dirname(const_String_or_char_ptr filename) { - static char tmp[1024]; +String *Swig_file_dirname(const_String_or_char_ptr filename) { const char *delim = SWIG_FILE_DELIMITER; - char *c; - strcpy(tmp, Char(filename)); - if (!strstr(tmp, delim)) { - return ""; - } - c = tmp + strlen(tmp) - 1; - while (*c != *delim) - c--; - *(++c) = 0; - return tmp; + const char *c = strrchr(Char(filename), *delim); + return c ? NewStringWithSize(filename, c - Char(filename) + 1) : NewString(""); } /* diff --git a/Source/Swig/swigfile.h b/Source/Swig/swigfile.h index 158243c04..f12b33081 100644 --- a/Source/Swig/swigfile.h +++ b/Source/Swig/swigfile.h @@ -26,10 +26,10 @@ extern void Swig_set_push_dir(int dopush); extern int Swig_get_push_dir(void); extern void Swig_register_filebyname(const_String_or_char_ptr filename, File *outfile); extern File *Swig_filebyname(const_String_or_char_ptr filename); -extern char *Swig_file_suffix(const_String_or_char_ptr filename); -extern char *Swig_file_basename(const_String_or_char_ptr filename); -extern char *Swig_file_filename(const_String_or_char_ptr filename); -extern char *Swig_file_dirname(const_String_or_char_ptr filename); +extern String *Swig_file_extension(const_String_or_char_ptr filename); +extern String *Swig_file_basename(const_String_or_char_ptr filename); +extern String *Swig_file_filename(const_String_or_char_ptr filename); +extern String *Swig_file_dirname(const_String_or_char_ptr filename); extern void Swig_file_debug_set(); /* Delimiter used in accessing files and directories */ From 41fed461fa1c04e501cbda49a368751d93b73195 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 18 Nov 2012 00:45:39 +0000 Subject: [PATCH 0262/1160] Fix Swig_file_extension when the path has a . and there is no extension in the filename git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13905 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/include.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/Source/Swig/include.c b/Source/Swig/include.c index 6e76f86ba..5d37dad7e 100644 --- a/Source/Swig/include.c +++ b/Source/Swig/include.c @@ -323,19 +323,11 @@ File *Swig_filebyname(const_String_or_char_ptr filename) { * ----------------------------------------------------------------------------- */ String *Swig_file_extension(const_String_or_char_ptr filename) { - const char *d; - const char *c = Char(filename); - int len = Len(filename); - if (strlen(c)) { - d = c + len - 1; - while (d != c) { - if (*d == '.') - return NewString(d); - d--; - } - return NewString(c + len); - } - return NewString(c); + String *name = Swig_file_filename(filename); + const char *c = strrchr(Char(name), '.'); + String *extension = c ? NewString(c) : NewString(""); + Delete(name); + return extension; } /* ----------------------------------------------------------------------------- From 138af71cfdea5020d96a3b10972d8a20353118d7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 18 Nov 2012 00:46:07 +0000 Subject: [PATCH 0263/1160] Add missing support for -outdir for -tcl -itcl and -modula3 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13906 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Source/Modules/modula3.cxx | 14 +++++++------- Source/Modules/tcl8.cxx | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 39da2bb4f..19912fde6 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.9 (in progress) =========================== +2012-11-17: wsfulton + [Tcl, Modula3] Add missing support for -outdir. + 2012-11-17: wsfulton Fix segfaults when using filename paths greater than 1024 characters in length. diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index 78af35506..ede2f39db 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -991,7 +991,7 @@ MODULA3(): // Generate m3makefile // This will be unnecessary if SWIG is invoked from Quake. { - File *file = openWriteFile(NewStringf("%sm3makefile", Swig_file_dirname(outfile))); + File *file = openWriteFile(NewStringf("%sm3makefile", SWIG_output_directory())); Printf(file, "%% automatically generated quake file for %s\n\n", name); @@ -1014,7 +1014,7 @@ MODULA3(): // Generate the raw interface { - File *file = openWriteFile(NewStringf("%s%s.i3", Swig_file_dirname(outfile), m3raw_name)); + File *file = openWriteFile(NewStringf("%s%s.i3", SWIG_output_directory(), m3raw_name)); emitBanner(file); @@ -1032,7 +1032,7 @@ MODULA3(): // Generate the raw module { - File *file = openWriteFile(NewStringf("%s%s.m3", Swig_file_dirname(outfile), m3raw_name)); + File *file = openWriteFile(NewStringf("%s%s.m3", SWIG_output_directory(), m3raw_name)); emitBanner(file); @@ -1050,7 +1050,7 @@ MODULA3(): // Generate the interface for the comfort wrappers { - File *file = openWriteFile(NewStringf("%s%s.i3", Swig_file_dirname(outfile), m3wrap_name)); + File *file = openWriteFile(NewStringf("%s%s.i3", SWIG_output_directory(), m3wrap_name)); emitBanner(file); @@ -1080,7 +1080,7 @@ MODULA3(): // Generate the wrapper routines implemented in Modula 3 { - File *file = openWriteFile(NewStringf("%s%s.m3", Swig_file_dirname(outfile), m3wrap_name)); + File *file = openWriteFile(NewStringf("%s%s.m3", SWIG_output_directory(), m3wrap_name)); emitBanner(file); @@ -2387,7 +2387,7 @@ MODULA3(): SWIG_exit(EXIT_FAILURE); } - String *filen = NewStringf("%s%s.m3", Swig_file_dirname(outfile), proxy_class_name); + String *filen = NewStringf("%s%s.m3", SWIG_output_directory(), proxy_class_name); f_proxy = NewFile(filen, "w", SWIG_output_files()); if (!f_proxy) { FileErrorDisplay(filen); @@ -3780,7 +3780,7 @@ MODULA3(): Setfile(n, input_file); Setline(n, line_number); - String *filen = NewStringf("%s%s.m3", Swig_file_dirname(outfile), classname); + String *filen = NewStringf("%s%s.m3", SWIG_output_directory(), classname); File *f_swigtype = NewFile(filen, "w", SWIG_output_files()); if (!f_swigtype) { FileErrorDisplay(filen); diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx index 4f4bdd1b2..a4f29183c 100644 --- a/Source/Modules/tcl8.cxx +++ b/Source/Modules/tcl8.cxx @@ -185,7 +185,7 @@ public: /* If shadow classing is enabled, we're going to change the module name to "_module" */ if (itcl) { String *filen; - filen = NewStringf("%s%s.itcl", Swig_file_dirname(outfile), module); + filen = NewStringf("%s%s.itcl", SWIG_output_directory(), module); Insert(module, 0, "_"); From 032f477d7f8a03ca88fe02b6b1284dc1522bc636 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 19 Nov 2012 19:39:20 +0000 Subject: [PATCH 0264/1160] Fix double delete git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13907 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/go.cxx | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 347cf33a4..0a8798444 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -3631,8 +3631,6 @@ private: Replaceall(w->code, "$symname", symname); Wrapper_print(w, f_c_directors); - - DelWrapper(w); } Delete(cn); From d14a88a6bd78ef9b39a1cdf1b04f4481037d912c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 19 Nov 2012 19:40:31 +0000 Subject: [PATCH 0265/1160] Fix memory leak git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13908 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/perl5.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index cd91a807c..242db1df1 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -868,6 +868,8 @@ public: emit_action_code(n, setf->code, tm); } else { Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(t, 0)); + DelWrapper(setf); + DelWrapper(getf); return SWIG_NOWRAP; } Printf(setf->code, "fail:\n"); From 0b0d5b1124762f25c272076857b1f5a2596f3574 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 19 Nov 2012 19:41:12 +0000 Subject: [PATCH 0266/1160] Fix uninitialised member var git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13909 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/ruby.cxx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index e31d3b72c..0d7de537c 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -128,7 +128,8 @@ enum autodoc_t { AUTODOC_FUNC, AUTODOC_METHOD, AUTODOC_GETTER, - AUTODOC_SETTER + AUTODOC_SETTER, + AUTODOC_NONE }; static const char *usage = (char *) "\ @@ -203,8 +204,6 @@ private: autodoc_t last_mode; String* last_autodoc; - - autodoc_l autodoc_level(String *autodoc) { autodoc_l dlevel = NO_AUTODOC; if (autodoc) { @@ -602,6 +601,8 @@ private: case AUTODOC_SETTER: Printf(doc, " Document-method: %s.%s=\n\n", full_name, symname); break; + case AUTODOC_NONE: + break; } } @@ -689,6 +690,8 @@ private: Printf(doc, " -> %s", type_str); break; } + case AUTODOC_NONE: + break; } } @@ -723,6 +726,8 @@ private: case AUTODOC_SETTER: Printf(doc, "Set new value for attribute.\n"); break; + case AUTODOC_NONE: + break; } } @@ -830,8 +835,9 @@ public: f_init(0), f_initbeforefunc(0), useGlobalModule(false), - multipleInheritance(false) { - last_autodoc = NewString(""); + multipleInheritance(false), + last_mode(AUTODOC_NONE), + last_autodoc(NewString("")) { current = NO_CPP; director_prot_ctor_code = NewString(""); Printv(director_prot_ctor_code, From 288e45cb15764253d07ea30214e191da803b4430 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 19 Nov 2012 19:42:17 +0000 Subject: [PATCH 0267/1160] Add some assertions to ensure NULL pointer is not used git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13910 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/csharp.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 9f902b76d..43831348b 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -2328,6 +2328,7 @@ public: // Get the C# variable type - obtained differently depending on whether a setter is required. String *variable_type = return_type; if (setter_flag) { + assert(last_parm); p = last_parm; // (last parameter is the only parameter for properties) SwigType *pt = Getattr(p, "type"); if ((tm = Getattr(p, "tmap:cstype"))) { @@ -2350,6 +2351,7 @@ public: if (setter_flag) { // Setter method + assert(last_parm); p = last_parm; // (last parameter is the only parameter for properties) SwigType *pt = Getattr(p, "type"); if ((tm = Getattr(p, "tmap:csvarin"))) { From 7299392ebbc31dba92b0ea37df647b63c0418e06 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 19 Nov 2012 19:43:24 +0000 Subject: [PATCH 0268/1160] Possible fix for global variable setters in modula3 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13911 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/modula3.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index ede2f39db..b473e3087 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -3527,6 +3527,7 @@ MODULA3(): m3wrap_impl.enterBlock(no_block); if (proxy_flag && global_variable_flag) { + setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(NSPACE_TODO, variable_name)) == 0); // Properties if (setter_flag) { // Setter method From e0967f3e134d5174b5d87253703e4bcf01f63dc8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 19 Nov 2012 19:44:48 +0000 Subject: [PATCH 0269/1160] Fix unnecessary and inconsistent null pointer checks git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13912 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/csharp.cxx | 144 +++++++++++++-------------- Source/Modules/d.cxx | 141 +++++++++++++------------- Source/Modules/java.cxx | 202 +++++++++++++++++++------------------- 3 files changed, 238 insertions(+), 249 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 43831348b..24bc48f0a 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3472,7 +3472,7 @@ public: Wrapper *w = NewWrapper(); ParmList *l = Getattr(n, "parms"); bool is_void = !(Cmp(returntype, "void")); - String *qualified_return = NewString(""); + String *qualified_return = 0; bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0"))); int status = SWIG_OK; bool output_director = true; @@ -3496,90 +3496,86 @@ public: imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(getNSpace(), classname, overloaded_name)); - if (returntype) { + qualified_return = SwigType_rcaststr(returntype, "c_result"); - Delete(qualified_return); - qualified_return = SwigType_rcaststr(returntype, "c_result"); - - if (!is_void && !ignored_method) { - if (!SwigType_isclass(returntype)) { - if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { - String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0)); - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL); - Delete(construct_result); - } else { - String *base_typename = SwigType_base(returntype); - String *resolved_typename = SwigType_typedef_resolve_all(base_typename); - Symtab *symtab = Getattr(n, "sym:symtab"); - Node *typenode = Swig_symbol_clookup(resolved_typename, symtab); - - if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) { - /* initialize pointers to something sane. Same for abstract - classes when a reference is returned. */ - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); - } else { - /* If returning a reference, initialize the pointer to a sane - default - if a C# exception occurs, then the pointer returns - something other than a NULL-initialized reference. */ - String *non_ref_type = Copy(returntype); - - /* Remove reference and const qualifiers */ - Replaceall(non_ref_type, "r.", ""); - Replaceall(non_ref_type, "q(const).", ""); - Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL); - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL); - - Delete(non_ref_type); - } - - Delete(base_typename); - Delete(resolved_typename); - } + if (!is_void && !ignored_method) { + if (!SwigType_isclass(returntype)) { + if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { + String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0)); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL); + Delete(construct_result); } else { - SwigType *vt; + String *base_typename = SwigType_base(returntype); + String *resolved_typename = SwigType_typedef_resolve_all(base_typename); + Symtab *symtab = Getattr(n, "sym:symtab"); + Node *typenode = Swig_symbol_clookup(resolved_typename, symtab); - vt = cplus_value_type(returntype); - if (!vt) { - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); + if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) { + /* initialize pointers to something sane. Same for abstract + classes when a reference is returned. */ + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); } else { - Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL); - Delete(vt); + /* If returning a reference, initialize the pointer to a sane + default - if a C# exception occurs, then the pointer returns + something other than a NULL-initialized reference. */ + String *non_ref_type = Copy(returntype); + + /* Remove reference and const qualifiers */ + Replaceall(non_ref_type, "r.", ""); + Replaceall(non_ref_type, "q(const).", ""); + Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL); + + Delete(non_ref_type); } - } - } - /* Create the intermediate class wrapper */ - tm = Swig_typemap_lookup("imtype", n, "", 0); - if (tm) { - String *imtypeout = Getattr(n, "tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap - if (imtypeout) - tm = imtypeout; - const String *im_directoroutattributes = Getattr(n, "tmap:imtype:directoroutattributes"); - if (im_directoroutattributes) { - Printf(callback_def, " %s\n", im_directoroutattributes); - Printf(director_delegate_definitions, " %s\n", im_directoroutattributes); - } - - Printf(callback_def, " private %s SwigDirector%s(", tm, overloaded_name); - if (!ignored_method) - Printf(director_delegate_definitions, " public delegate %s", tm); - } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(returntype, 0)); - } - - if ((c_ret_type = Swig_typemap_lookup("ctype", n, "", 0))) { - if (!is_void && !ignored_method) { - String *jretval_decl = NewStringf("%s jresult", c_ret_type); - Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL); - Delete(jretval_decl); + Delete(base_typename); + Delete(resolved_typename); } } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s for use in %s::%s (skipping director method)\n", - SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); - output_director = false; + SwigType *vt; + + vt = cplus_value_type(returntype); + if (!vt) { + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); + } else { + Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL); + Delete(vt); + } } } + /* Create the intermediate class wrapper */ + tm = Swig_typemap_lookup("imtype", n, "", 0); + if (tm) { + String *imtypeout = Getattr(n, "tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap + if (imtypeout) + tm = imtypeout; + const String *im_directoroutattributes = Getattr(n, "tmap:imtype:directoroutattributes"); + if (im_directoroutattributes) { + Printf(callback_def, " %s\n", im_directoroutattributes); + Printf(director_delegate_definitions, " %s\n", im_directoroutattributes); + } + + Printf(callback_def, " private %s SwigDirector%s(", tm, overloaded_name); + if (!ignored_method) + Printf(director_delegate_definitions, " public delegate %s", tm); + } else { + Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(returntype, 0)); + } + + if ((c_ret_type = Swig_typemap_lookup("ctype", n, "", 0))) { + if (!is_void && !ignored_method) { + String *jretval_decl = NewStringf("%s jresult", c_ret_type); + Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL); + Delete(jretval_decl); + } + } else { + Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s for use in %s::%s (skipping director method)\n", + SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); + output_director = false; + } + Swig_director_parms_fixup(l); /* Attach the standard typemaps */ diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 503f90069..5ce60016f 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -1945,7 +1945,7 @@ public: Wrapper *w = NewWrapper(); ParmList *l = Getattr(n, "parms"); bool is_void = !(Cmp(returntype, "void")); - String *qualified_return = NewString(""); + String *qualified_return = 0; bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0"))); int status = SWIG_OK; bool output_director = true; @@ -1968,89 +1968,86 @@ 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(getNSpace(), classname, overloaded_name)); + imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(getNSpace(), classname, overloaded_name)); - if (returntype) { - qualified_return = SwigType_rcaststr(returntype, "c_result"); + qualified_return = SwigType_rcaststr(returntype, "c_result"); - if (!is_void && !ignored_method) { - if (!SwigType_isclass(returntype)) { - if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { - String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0)); - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL); - Delete(construct_result); - } else { - String *base_typename = SwigType_base(returntype); - String *resolved_typename = SwigType_typedef_resolve_all(base_typename); - Symtab *symtab = Getattr(n, "sym:symtab"); - Node *typenode = Swig_symbol_clookup(resolved_typename, symtab); - - if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) { - /* initialize pointers to something sane. Same for abstract - classes when a reference is returned. */ - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); - } else { - /* If returning a reference, initialize the pointer to a sane - default - if a D exception occurs, then the pointer returns - something other than a NULL-initialized reference. */ - String *non_ref_type = Copy(returntype); - - /* Remove reference and const qualifiers */ - Replaceall(non_ref_type, "r.", ""); - Replaceall(non_ref_type, "q(const).", ""); - Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL); - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL); - - Delete(non_ref_type); - } - - Delete(base_typename); - Delete(resolved_typename); - } + if (!is_void && !ignored_method) { + if (!SwigType_isclass(returntype)) { + if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { + String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0)); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL); + Delete(construct_result); } else { - SwigType *vt; + String *base_typename = SwigType_base(returntype); + String *resolved_typename = SwigType_typedef_resolve_all(base_typename); + Symtab *symtab = Getattr(n, "sym:symtab"); + Node *typenode = Swig_symbol_clookup(resolved_typename, symtab); - vt = cplus_value_type(returntype); - if (!vt) { - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); + if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) { + /* initialize pointers to something sane. Same for abstract + classes when a reference is returned. */ + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); } else { - Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL); - Delete(vt); + /* If returning a reference, initialize the pointer to a sane + default - if a D exception occurs, then the pointer returns + something other than a NULL-initialized reference. */ + String *non_ref_type = Copy(returntype); + + /* Remove reference and const qualifiers */ + Replaceall(non_ref_type, "r.", ""); + Replaceall(non_ref_type, "q(const).", ""); + Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL); + + Delete(non_ref_type); } - } - } - /* Create the intermediate class wrapper */ - tm = lookupDTypemap(n, "imtype"); - if (tm) { - String *imtypeout = Getattr(n, "tmap:imtype:out"); - if (imtypeout) { - // The type in the imtype typemap's out attribute overrides the type - // in the typemap. - tm = imtypeout; - } - Printf(callback_def, "\nprivate extern(C) %s swigDirectorCallback_%s_%s(void* dObject", tm, classname, overloaded_name); - Printv(proxy_callback_return_type, tm, NIL); - } else { - Swig_warning(WARN_D_TYPEMAP_IMTYPE_UNDEF, input_file, line_number, - "No imtype typemap defined for %s\n", SwigType_str(returntype, 0)); - } - - if ((c_ret_type = Swig_typemap_lookup("ctype", n, "", 0))) { - if (!is_void && !ignored_method) { - String *jretval_decl = NewStringf("%s jresult", c_ret_type); - Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL); - Delete(jretval_decl); + Delete(base_typename); + Delete(resolved_typename); } } else { - Swig_warning(WARN_D_TYPEMAP_CTYPE_UNDEF, input_file, line_number, - "No ctype typemap defined for %s for use in %s::%s (skipping director method)\n", - SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); - output_director = false; + SwigType *vt; + + vt = cplus_value_type(returntype); + if (!vt) { + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); + } else { + Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL); + Delete(vt); + } } } + /* Create the intermediate class wrapper */ + tm = lookupDTypemap(n, "imtype"); + if (tm) { + String *imtypeout = Getattr(n, "tmap:imtype:out"); + if (imtypeout) { + // The type in the imtype typemap's out attribute overrides the type + // in the typemap. + tm = imtypeout; + } + Printf(callback_def, "\nprivate extern(C) %s swigDirectorCallback_%s_%s(void* dObject", tm, classname, overloaded_name); + Printv(proxy_callback_return_type, tm, NIL); + } else { + Swig_warning(WARN_D_TYPEMAP_IMTYPE_UNDEF, input_file, line_number, + "No imtype typemap defined for %s\n", SwigType_str(returntype, 0)); + } + + if ((c_ret_type = Swig_typemap_lookup("ctype", n, "", 0))) { + if (!is_void && !ignored_method) { + String *jretval_decl = NewStringf("%s jresult", c_ret_type); + Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL); + Delete(jretval_decl); + } + } else { + Swig_warning(WARN_D_TYPEMAP_CTYPE_UNDEF, input_file, line_number, + "No ctype typemap defined for %s for use in %s::%s (skipping director method)\n", + SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); + output_director = false; + } + Swig_director_parms_fixup(l); // Attach the standard typemaps. diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 14cfeaf20..591ed2e84 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3536,7 +3536,7 @@ public: Wrapper *w = NewWrapper(); ParmList *l = Getattr(n, "parms"); bool is_void = !(Cmp(returntype, "void")); - String *qualified_return = NewString(""); + String *qualified_return = 0; bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0"))); int status = SWIG_OK; bool output_director = true; @@ -3567,126 +3567,122 @@ public: imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(getNSpace(), classname, overloaded_name)); - if (returntype) { + qualified_return = SwigType_rcaststr(returntype, "c_result"); - Delete(qualified_return); - qualified_return = SwigType_rcaststr(returntype, "c_result"); - - if (!is_void && (!ignored_method || pure_virtual)) { - if (!SwigType_isclass(returntype)) { - if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { - String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0)); - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL); - Delete(construct_result); - } else { - String *base_typename = SwigType_base(returntype); - String *resolved_typename = SwigType_typedef_resolve_all(base_typename); - Symtab *symtab = Getattr(n, "sym:symtab"); - Node *typenode = Swig_symbol_clookup(resolved_typename, symtab); - - if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) { - /* initialize pointers to something sane. Same for abstract - classes when a reference is returned. */ - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); - } else { - /* If returning a reference, initialize the pointer to a sane - default - if a Java exception occurs, then the pointer returns - something other than a NULL-initialized reference. */ - String *non_ref_type = Copy(returntype); - - /* Remove reference and const qualifiers */ - Replaceall(non_ref_type, "r.", ""); - Replaceall(non_ref_type, "q(const).", ""); - Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL); - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL); - - Delete(non_ref_type); - } - - Delete(base_typename); - Delete(resolved_typename); - } + if (!is_void && (!ignored_method || pure_virtual)) { + if (!SwigType_isclass(returntype)) { + if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { + String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0)); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL); + Delete(construct_result); } else { - SwigType *vt; + String *base_typename = SwigType_base(returntype); + String *resolved_typename = SwigType_typedef_resolve_all(base_typename); + Symtab *symtab = Getattr(n, "sym:symtab"); + Node *typenode = Swig_symbol_clookup(resolved_typename, symtab); - vt = cplus_value_type(returntype); - if (!vt) { - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); + if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) { + /* initialize pointers to something sane. Same for abstract + classes when a reference is returned. */ + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); } else { - Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL); - Delete(vt); + /* If returning a reference, initialize the pointer to a sane + default - if a Java exception occurs, then the pointer returns + something other than a NULL-initialized reference. */ + String *non_ref_type = Copy(returntype); + + /* Remove reference and const qualifiers */ + Replaceall(non_ref_type, "r.", ""); + Replaceall(non_ref_type, "q(const).", ""); + Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL); + + Delete(non_ref_type); } + + Delete(base_typename); + Delete(resolved_typename); + } + } else { + SwigType *vt; + + vt = cplus_value_type(returntype); + if (!vt) { + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); + } else { + Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL); + Delete(vt); } } + } - /* Create the intermediate class wrapper */ - tm = Swig_typemap_lookup("jtype", n, "", 0); - if (tm) { - Printf(callback_def, " public static %s %s(%s self", tm, imclass_dmethod, qualified_classname); - } else { - Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(returntype, 0)); + /* Create the intermediate class wrapper */ + tm = Swig_typemap_lookup("jtype", n, "", 0); + if (tm) { + Printf(callback_def, " public static %s %s(%s self", tm, imclass_dmethod, qualified_classname); + } else { + Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(returntype, 0)); + } + + String *cdesc = NULL; + SwigType *covariant = Getattr(n, "covariant"); + SwigType *adjustedreturntype = covariant ? covariant : returntype; + Parm *adjustedreturntypeparm = NewParmNode(adjustedreturntype, n); + + if ((tm = Swig_typemap_lookup("directorin", adjustedreturntypeparm, "", 0)) + && (cdesc = Getattr(adjustedreturntypeparm, "tmap:directorin:descriptor"))) { + + // Note that in the case of polymorphic (covariant) return types, the + // method's return type is changed to be the base of the C++ return + // type + String *jnidesc_canon = canonicalizeJNIDescriptor(cdesc, adjustedreturntypeparm); + Append(classret_desc, jnidesc_canon); + Delete(jnidesc_canon); + } else { + Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, "No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n", + SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); + output_director = false; + } + + /* Get the JNI field descriptor for this return type, add the JNI field descriptor + to jniret_desc */ + if ((c_ret_type = Swig_typemap_lookup("jni", n, "", 0))) { + Parm *tp = NewParmNode(c_ret_type, n); + + if (!is_void && !ignored_method) { + String *jretval_decl = NewStringf("%s jresult", c_ret_type); + Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL); + Delete(jretval_decl); } - String *cdesc = NULL; - SwigType *covariant = Getattr(n, "covariant"); - SwigType *adjustedreturntype = covariant ? covariant : returntype; - Parm *adjustedreturntypeparm = NewParmNode(adjustedreturntype, n); + String *jdesc = NULL; + if ((tm = Swig_typemap_lookup("directorin", tp, "", 0)) + && (jdesc = Getattr(tp, "tmap:directorin:descriptor"))) { - if ((tm = Swig_typemap_lookup("directorin", adjustedreturntypeparm, "", 0)) - && (cdesc = Getattr(adjustedreturntypeparm, "tmap:directorin:descriptor"))) { - - // Note that in the case of polymorphic (covariant) return types, the - // method's return type is changed to be the base of the C++ return - // type - String *jnidesc_canon = canonicalizeJNIDescriptor(cdesc, adjustedreturntypeparm); - Append(classret_desc, jnidesc_canon); + // Objects marshalled passing a Java class across JNI boundary use jobject - the nouse flag indicates this + // We need the specific Java class name instead of the generic 'Ljava/lang/Object;' + if (GetFlag(tp, "tmap:directorin:nouse")) + jdesc = cdesc; + String *jnidesc_canon = canonicalizeJNIDescriptor(jdesc, tp); + Append(jniret_desc, jnidesc_canon); Delete(jnidesc_canon); } else { - Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, "No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n", - SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); + Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, + "No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n", + SwigType_str(c_ret_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); output_director = false; } - /* Get the JNI field descriptor for this return type, add the JNI field descriptor - to jniret_desc */ - if ((c_ret_type = Swig_typemap_lookup("jni", n, "", 0))) { - Parm *tp = NewParmNode(c_ret_type, n); - - if (!is_void && !ignored_method) { - String *jretval_decl = NewStringf("%s jresult", c_ret_type); - Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL); - Delete(jretval_decl); - } - - String *jdesc = NULL; - if ((tm = Swig_typemap_lookup("directorin", tp, "", 0)) - && (jdesc = Getattr(tp, "tmap:directorin:descriptor"))) { - - // Objects marshalled passing a Java class across JNI boundary use jobject - the nouse flag indicates this - // We need the specific Java class name instead of the generic 'Ljava/lang/Object;' - if (GetFlag(tp, "tmap:directorin:nouse")) - jdesc = cdesc; - String *jnidesc_canon = canonicalizeJNIDescriptor(jdesc, tp); - Append(jniret_desc, jnidesc_canon); - Delete(jnidesc_canon); - } else { - Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, - "No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n", - SwigType_str(c_ret_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); - output_director = false; - } - - Delete(tp); - } else { - Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s for use in %s::%s (skipping director method)\n", - SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); - output_director = false; - } - - Delete(adjustedreturntypeparm); - Delete(qualified_classname); + Delete(tp); + } else { + Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s for use in %s::%s (skipping director method)\n", + SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); + output_director = false; } + Delete(adjustedreturntypeparm); + Delete(qualified_classname); + Swig_director_parms_fixup(l); /* Attach the standard typemaps */ From 660b15ea5ac434f9a66b6d501c2702c185c59deb Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 19 Nov 2012 19:46:21 +0000 Subject: [PATCH 0270/1160] Correctly handle errors if language symbol already exists git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13913 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/csharp.cxx | 6 ++++-- Source/Modules/java.cxx | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 24bc48f0a..6b0ad6edc 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -361,8 +361,10 @@ public: } // module class and intermediary classes are always created - addSymbol(imclass_name, n); - addSymbol(module_class_name, n); + if (!addSymbol(imclass_name, n)) + return SWIG_ERROR; + if (!addSymbol(module_class_name, n)) + return SWIG_ERROR; imclass_class_code = NewString(""); proxy_class_def = NewString(""); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 591ed2e84..bfa02d7e2 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -374,8 +374,10 @@ public: constants_interface_name = NewStringf("%sConstants", module_class_name); // module class and intermediary classes are always created - addSymbol(imclass_name, n); - addSymbol(module_class_name, n); + if (!addSymbol(imclass_name, n)) + return SWIG_ERROR; + if (!addSymbol(module_class_name, n)) + return SWIG_ERROR; imclass_class_code = NewString(""); proxy_class_def = NewString(""); From 0c7bc3612232db036cf8b099eebf7007fd377c21 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 19 Nov 2012 19:47:48 +0000 Subject: [PATCH 0271/1160] Fix obvious copy/paste errors in some director code git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13914 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/csharp.cxx | 2 +- Source/Modules/d.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 6b0ad6edc..d715aadb2 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -4070,7 +4070,7 @@ public: Printf(w->def, ") {"); - if (Len(director_callback_typedefs) > 0) { + if (Len(director_callbacks) > 0) { Printf(f_directors_h, "\nprivate:\n%s", director_callbacks); } Printf(f_directors_h, " void swig_init_callbacks();\n"); diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 5ce60016f..0f6a75255 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -2528,7 +2528,7 @@ public: Printf(f_directors_h, "\nprivate:\n"); Printf(f_directors_h, " void swig_init_callbacks();\n"); Printf(f_directors_h, " void *d_object;\n"); - if (Len(director_callback_typedefs) > 0) { + if (Len(director_callback_pointers) > 0) { Printf(f_directors_h, "%s", director_callback_pointers); } Printf(f_directors_h, "};\n\n"); From 0f0172bc0d5a789cc9dd6a5bf0f9a44298fe53e8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 19 Nov 2012 19:48:50 +0000 Subject: [PATCH 0272/1160] Fix possible NULL dereference git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13915 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/d.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 0f6a75255..2c8524dfe 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -3669,7 +3669,9 @@ private: bool inProxyModule(const String *type_name) const { if (!split_proxy_dmodule) { String *nspace = createOuterNamespaceNames(type_name); - bool result = (getNSpace() || !nspace) && (Strcmp(nspace, getNSpace()) == 0); + bool result = false; + if (getNSpace() && nspace) + result = (Strcmp(nspace, getNSpace()) == 0); Delete(nspace); return result; } From 558ee74967131871fd24e7c55c05539fc494d3b1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 19 Nov 2012 19:49:43 +0000 Subject: [PATCH 0273/1160] Fix missing out typemap warning git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13916 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/allegrocl.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index ffd96ca9c..6b501dfd4 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -2748,7 +2748,7 @@ int ALLEGROCL::functionWrapper(Node *n) { String *actioncode = emit_action(n); String *tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode); - if (!is_void_return && tm) { + if (!is_void_return) { if (tm) { Replaceall(tm, "$result", "lresult"); Printf(f->code, "%s\n", tm); From 8162f3c0a59f8229156860d8f1e8dbf7e4ec27f2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 19 Nov 2012 19:51:13 +0000 Subject: [PATCH 0274/1160] Fix buggy namespace_of and strip_namespaces functions replacing with equivalents from misc.c git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13917 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/allegrocl.cxx | 43 ++---------------------------------- 1 file changed, 2 insertions(+), 41 deletions(-) diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index 6b501dfd4..d67053ab9 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -162,46 +162,7 @@ String *namespaced_name(Node *n, String *ns = current_namespace) { // "Namespace::Nested::Class2::Baz" -> "Baz" static String *strip_namespaces(String *str) { - SwigType *new_type = Copy(str); - SwigType *leading_type = SwigType_pop(new_type); - char *result = Char(leading_type); - - if(SwigType_istemplate(leading_type)) { - result = Char(SwigType_templateprefix(leading_type)); - } else { - if (!SwigType_issimple(leading_type)) - return NewString(str); - } - - String *stripped_one; - while ((stripped_one = Strstr(result, "::"))) - result = Char(stripped_one) + 2; - - if(SwigType_istemplate(leading_type)) { - SwigType_push(new_type, NewStringf("%s%s%s", result, SwigType_templateargs(leading_type), - SwigType_templatesuffix(leading_type))); - return new_type; - } - - return NewString(result); -} - -static String *namespace_of(String *str) { - char *p = Char(str); - char *start = Char(str); - char *result = 0; - String *stripped_one; - - while ((stripped_one = Strstr(p, "::"))) { - p = Char(stripped_one) + 2; - } - if (p > start) { - int len = p - start - 1; - result = (char *) malloc(len); - strncpy(result, start, len - 1); - result[len - 1] = 0; - } - return Char(result); + return Swig_scopename_last(str); } void add_linked_type(Node *n) { @@ -663,7 +624,7 @@ void note_implicit_template_instantiation(SwigType *t) { #endif SwigType *type = Copy(t); SwigType *tok = SwigType_pop(type); - String *implicit_ns = SwigType_istemplate(tok) ? namespace_of(SwigType_templateprefix(tok)) : 0; + String *implicit_ns = SwigType_istemplate(tok) ? Swig_scopename_prefix(SwigType_templateprefix(tok)) : 0; add_defined_foreign_type(0, 0, t, t, implicit_ns ? implicit_ns : current_namespace); Delete(type); From 4a25c4695d4bcf0673fd52a0bb7fe0722fe3815c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 19 Nov 2012 19:52:44 +0000 Subject: [PATCH 0275/1160] Fix possible null dereference git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13918 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/allegrocl.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index d67053ab9..95022752f 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -421,7 +421,8 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0, #endif if (is_fwd_ref) { // Printf(stderr,"*** 1\n"); - add_linked_type(n); + if (n) + add_linked_type(n); } else { // Printf(stderr,"*** 1-a\n"); if (SwigType_istemplate(k)) { From c8620e478245db235a5d1e11750f07a92e4e10a9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 19 Nov 2012 19:53:29 +0000 Subject: [PATCH 0276/1160] Fix some Coverity submission failures git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13919 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Makefile.in | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.in b/Makefile.in index 0e79a77da..eb3ec02b2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -533,6 +533,7 @@ EMAIL=wsf@fultondesigns.co.uk PASSWORD= coverity: $(MAKE) clean-source + rm -rf cov-int cov-build --dir cov-int $(MAKE) tar czvf swig-coverity.tgz cov-int curl --form file=@swig-coverity.tgz --form project=swig --form password=$(PASSWORD) --form email=$(EMAIL) http://scan5.coverity.com/cgi-bin/upload.py From 1752b62156ce7de8f3bc636ba81854d7a7a21997 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Tue, 20 Nov 2012 20:06:21 +0000 Subject: [PATCH 0277/1160] [D] Fixed namespace handling bug introduced in r13915. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13920 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/d.cxx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 2c8524dfe..29f96e548 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -3669,9 +3669,15 @@ private: bool inProxyModule(const String *type_name) const { if (!split_proxy_dmodule) { String *nspace = createOuterNamespaceNames(type_name); - bool result = false; - if (getNSpace() && nspace) + + // Check if strings are either both null (no namespace) or are both + // non-null and have the same contents. Cannot use Strcmp for this + // directly because of its strange way of handling the case where only + // one argument is 0 ("<"). + bool result = !nspace && !getNSpace(); + if (nspace && getNSpace()) result = (Strcmp(nspace, getNSpace()) == 0); + Delete(nspace); return result; } From 681c6c6231c87878065b58bce0887fe295abb53c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 20 Nov 2012 23:27:54 +0000 Subject: [PATCH 0278/1160] Fix possible null dereferences in CFFI git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13921 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/cffi.cxx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx index 6fd915bf5..ceb1bad67 100644 --- a/Source/Modules/cffi.cxx +++ b/Source/Modules/cffi.cxx @@ -322,7 +322,7 @@ void CFFI::emit_initialize_instance(Node *n) { else Printf(args_placeholder, " %s", argname); - if (Strcmp(ffitype, lispify_name(parent, lispy_name(Char(Getattr(parent, "sym:name"))), "'classname")) == 0) + if (ffitype && Strcmp(ffitype, lispify_name(parent, lispy_name(Char(Getattr(parent, "sym:name"))), "'classname")) == 0) Printf(args_call, " (ff-pointer %s)", argname); else Printf(args_call, " %s", argname); @@ -458,10 +458,12 @@ int CFFI::functionWrapper(Node *n) { String *actioncode = emit_action(n); String *result_convert = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode); - Replaceall(result_convert, "$result", "lresult"); - Printf(f->code, "%s\n", result_convert); - if(!is_void_return) Printf(f->code, " return lresult;\n"); - Delete(result_convert); + if (result_convert) { + Replaceall(result_convert, "$result", "lresult"); + Printf(f->code, "%s\n", result_convert); + if(!is_void_return) Printf(f->code, " return lresult;\n"); + Delete(result_convert); + } emit_return_variable(n, Getattr(n, "type"), f); Printf(f->code, " } catch (...) {\n"); From 158a00b591156184d2fe5fcf3b0f442077ae1b8b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 20 Nov 2012 23:28:43 +0000 Subject: [PATCH 0279/1160] Fix potential crash in clisp git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13922 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/clisp.cxx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Modules/clisp.cxx b/Source/Modules/clisp.cxx index a322cb2de..3a4a5648c 100644 --- a/Source/Modules/clisp.cxx +++ b/Source/Modules/clisp.cxx @@ -78,13 +78,13 @@ int CLISP::top(Node *n) { /* Get the output file name */ String *outfile = Getattr(n, "outfile"); - if (!outfile) - output_filename = outfile; - else { - output_filename = NewString(""); - Printf(output_filename, "%s%s.lisp", SWIG_output_directory(), module); + if (!outfile) { + Printf(stderr, "Unable to determine outfile\n"); + SWIG_exit(EXIT_FAILURE); } + output_filename = NewStringf("%s%s.lisp", SWIG_output_directory(), module); + f_cl = NewFile(output_filename, "w+", SWIG_output_files()); if (!f_cl) { FileErrorDisplay(output_filename); From f267e08b5b454190d268be7f42a32a2998eafc09 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 20 Nov 2012 23:29:07 +0000 Subject: [PATCH 0280/1160] Fix potential null pointer dereferences git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13923 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/go.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 0a8798444..86171d28b 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -2375,14 +2375,14 @@ private: Iterator b = First(baselist); if (is_base_first) { + if (!b.item) { + return; + } if (!GetFlag(b.item, "feature:ignore")) { addParentExtraBaseInterfaces(n, parents, b.item, true, sf); } b = Next(b); - if (!b.item) { - return; - } } String *go_name = buildGoName(Getattr(n, "sym:name"), false, false); @@ -4384,7 +4384,7 @@ private: Delete(p); } - if (Strstr(ret, "$gotypename") != 0) { + if (ret && Strstr(ret, "$gotypename") != 0) { ret = NULL; } From 2b8bfe410e52ce06378cafcb7c2842dc7cd7c284 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 20 Nov 2012 23:29:35 +0000 Subject: [PATCH 0281/1160] Remove unnecessary null checks or fix potential null dereferences git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13924 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/modula3.cxx | 38 ++++++++++++----------- Source/Modules/ocaml.cxx | 5 ++- Source/Modules/perl5.cxx | 2 +- Source/Modules/python.cxx | 6 ++-- Source/Modules/r.cxx | 62 ++++++++++++++++++++------------------ 5 files changed, 60 insertions(+), 53 deletions(-) diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index b473e3087..f7b60825d 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -2096,7 +2096,7 @@ MODULA3(): stem += Len(pat.prefix); } String *newname; - if (Strcmp(srcstyle, "underscore") == 0) { + if (srcstyle && Strcmp(srcstyle, "underscore") == 0) { if (newprefix != NIL) { String *newstem = nameToModula3(stem, true); newname = NewStringf("%s%s", newprefix, newstem); @@ -2214,16 +2214,18 @@ MODULA3(): List *baselist = Getattr(n, "bases"); if (baselist != NIL) { Iterator base = First(baselist); - c_baseclassname = Getattr(base.item, "name"); - baseclass = Copy(getProxyName(c_baseclassname)); - if (baseclass) { - c_baseclass = SwigType_namestr(Getattr(base.item, "name")); - } - base = Next(base); - if (base.item != NIL) { - Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", - name, Getattr(base.item, "name")); + if (base.item) { + c_baseclassname = Getattr(base.item, "name"); + baseclass = Copy(getProxyName(c_baseclassname)); + if (baseclass) { + c_baseclass = SwigType_namestr(Getattr(base.item, "name")); + } + base = Next(base); + if (base.item != NIL) { + Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", + name, Getattr(base.item, "name")); + } } } @@ -2460,12 +2462,14 @@ MODULA3(): /* Look for the first (principal?) base class - Modula 3 does not support multiple inheritance */ Iterator base = First(baselist); - Append(baseclassname, Getattr(base.item, "sym:name")); - base = Next(base); - if (base.item != NIL) { - Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", - proxy_class_name, Getattr(base.item, "name")); + if (base.item) { + Append(baseclassname, Getattr(base.item, "sym:name")); + base = Next(base); + if (base.item) { + Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", + proxy_class_name, Getattr(base.item, "name")); + } } } } diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index 135cc89dc..9fc5e9c71 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -1256,13 +1256,12 @@ public: Printv(qtype, name, NIL); } - if (const_enum && name && !Getattr(seen_enumvalues, name)) { + if (const_enum && qtype && name && !Getattr(seen_enumvalues, name)) { Setattr(seen_enumvalues, name, "true"); SetFlag(n, "feature:immutable"); Setattr(n, "feature:enumvalue", "1"); // this does not appear to be used - if (qtype) - Setattr(n, "qualified:name", SwigType_namestr(qtype)); + Setattr(n, "qualified:name", SwigType_namestr(qtype)); String *evname = SwigType_manglestr(qtype); Insert(evname, 0, "SWIG_ENUM_"); diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 242db1df1..1662f3b55 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -1638,8 +1638,8 @@ public: while (fgets(buffer, 4095, f)) { Printf(pragma_include, "%s", buffer); } + fclose(f); } - fclose(f); } } else { Swig_error(input_file, line_number, "Unrecognized pragma.\n"); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index dcf6699b1..56107e0c0 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -1163,9 +1163,9 @@ public: autodoc_l autodoc_level(String *autodoc) { autodoc_l dlevel = NO_AUTODOC; - if (autodoc) { - char *c = Char(autodoc); - if (c && isdigit(c[0])) { + char *c = Char(autodoc); + if (c) { + if (isdigit(c[0])) { dlevel = (autodoc_l) atoi(c); } else { if (strcmp(c, "extended") == 0) { diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 9e931a38d..ab13cb7fc 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1609,7 +1609,6 @@ void R::dispatchFunction(Node *n) { String *tmcheck = Swig_typemap_lookup("rtypecheck", p, "", 0); if (tmcheck) { - String *tmp = NewString(""); Printf(tmp, "argv[[%d]]", j+1); Replaceall(tmcheck, "$arg", tmp); @@ -1626,32 +1625,34 @@ void R::dispatchFunction(Node *n) { tmcheck); p = Getattr(p, "tmap:in:next"); continue; - } - if (DohStrcmp(tm,"numeric")==0) { + } + if (tm) { + if (Strcmp(tm,"numeric")==0) { Printf(f->code, "%sis.numeric(argv[[%d]])", - j == 0 ? "" : " && ", - j+1); + j == 0 ? "" : " && ", + j+1); } - else if (DohStrcmp(tm,"integer")==0) { + else if (Strcmp(tm,"integer")==0) { Printf(f->code, "%s(is.integer(argv[[%d]]) || is.numeric(argv[[%d]]))", - j == 0 ? "" : " && ", - j+1, j+1); + j == 0 ? "" : " && ", + j+1, j+1); } - else if (DohStrcmp(tm,"character")==0) { + else if (Strcmp(tm,"character")==0) { Printf(f->code, "%sis.character(argv[[%d]])", - j == 0 ? "" : " && ", - j+1); + j == 0 ? "" : " && ", + j+1); } else { Printf(f->code, "%sextends(argtypes[%d], '%s')", - j == 0 ? "" : " && ", - j+1, - tm); - } - if (!SwigType_ispointer(Getattr(p, "type"))) { - Printf(f->code, " && length(argv[[%d]]) == 1", - j+1); + j == 0 ? "" : " && ", + j+1, + tm); } + } + if (!SwigType_ispointer(Getattr(p, "type"))) { + Printf(f->code, " && length(argv[[%d]]) == 1", + j+1); + } p = Getattr(p, "tmap:in:next"); } Printf(f->code, ") { f <- %s%s; }\n", sfname, overname); @@ -1845,18 +1846,21 @@ int R::functionWrapper(Node *n) { String *lname = Getattr(p,"lname"); // R keyword renaming - if (name && Swig_name_warning(p, 0, name, 0)) - name = 0; - - /* If we have a :: in the parameter name because we are accessing a static member of a class, say, then - we need to remove that prefix. */ - while (Strstr(name, "::")) { - //XXX need to free. - name = NewStringf("%s", Strchr(name, ':') + 2); - if (debugMode) - Printf(stdout, "+++ parameter name with :: in it %s\n", name); + if (name) { + if (Swig_name_warning(p, 0, name, 0)) { + name = 0; + } else { + /* If we have a :: in the parameter name because we are accessing a static member of a class, say, then + we need to remove that prefix. */ + while (Strstr(name, "::")) { + //XXX need to free. + name = NewStringf("%s", Strchr(name, ':') + 2); + if (debugMode) + Printf(stdout, "+++ parameter name with :: in it %s\n", name); + } + } } - if (Len(name) == 0) + if (!name || Len(name) == 0) name = NewStringf("s_arg%d", i+1); name = replaceInitialDash(name); From 5b4ba0b0d692b85d02eeee161cd585dbc0df2caf Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 20 Nov 2012 23:29:57 +0000 Subject: [PATCH 0282/1160] Remove unnecessary null checks or fix potential null dereferences git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13925 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/ruby.cxx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 0d7de537c..e16bbc9ba 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -206,9 +206,9 @@ private: autodoc_l autodoc_level(String *autodoc) { autodoc_l dlevel = NO_AUTODOC; - if (autodoc) { - char *c = Char(autodoc); - if (c && isdigit(c[0])) { + char *c = Char(autodoc); + if (c) { + if (isdigit(c[0])) { dlevel = (autodoc_l) atoi(c); } else { if (strcmp(c, "extended") == 0) { @@ -495,7 +495,7 @@ private: String* full_name; if ( module ) { full_name = NewString(module); - if (class_name && Len(class_name) > 0) + if (Len(class_name) > 0) Append(full_name, "::"); } else @@ -1283,13 +1283,15 @@ public: } m = Next(m); } - if (feature == 0) { - feature = Copy(last); + if (last) { + if (feature == 0) { + feature = Copy(last); + } + (Char(last))[0] = (char)toupper((Char(last))[0]); + modvar = NewStringf("m%s", last); } - (Char(last))[0] = (char)toupper((Char(last))[0]); - modvar = NewStringf("m%s", last); - Delete(modules); } + Delete(modules); } Delete(mod_name); } From 7d610dbd62750bdb2a427ec73f29355252e0f99f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 22 Nov 2012 23:20:57 +0000 Subject: [PATCH 0283/1160] Remove unnecessary null check git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13926 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/typepass.cxx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index 192c85ba6..cda56aecf 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -572,12 +572,9 @@ class TypePass:private Dispatcher { if (alias) { Typetab *ts = Getattr(n, "typescope"); if (!ts) { - Node *ns; - /* Create a empty scope for the alias */ - ns = Getattr(n, "namespace"); - if (ns) { - SwigType_scope_alias(name, Getattr(ns, "typescope")); - } + /* Create an empty scope for the alias */ + Node *ns = Getattr(n, "namespace"); + SwigType_scope_alias(name, Getattr(ns, "typescope")); ts = Getattr(ns, "typescope"); Setattr(n, "typescope", ts); } From be3236cb678b9e00e42ae2579455f2c5a068019e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 22 Nov 2012 23:21:19 +0000 Subject: [PATCH 0284/1160] Better handling of null sym:name git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13927 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/lang.cxx | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 0a8415120..6e9afbad3 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -834,10 +834,25 @@ int Language::cDeclaration(Node *n) { File *f_header = 0; SwigType *ty, *fullty; + if (Getattr(n, "feature:onlychildren")) { + if (GetFlag(n, "feature:ignore")) { + return SWIG_NOWRAP; + } else { + // Found an unignored templated method that has an empty template instantiation (%template()) + // Ignore it unless it has been %rename'd + if (Strncmp(symname, "__dummy_", 8) == 0) { + SetFlag(n, "feature:ignore"); + Swig_warning(WARN_LANG_TEMPLATE_METHOD_IGNORE, input_file, line_number, + "%%template() contains no name. Template method ignored: %s\n", Swig_name_decl(n)); + return SWIG_NOWRAP; + } + } + } + /* discards nodes following the access control rules */ if (cplus_mode != PUBLIC || !is_public(n)) { /* except for friends, they are not affected by access control */ - int isfriend = storage && (Cmp(storage, "friend") == 0); + int isfriend = Cmp(storage, "friend") == 0; if (!isfriend) { /* Check what the director needs. If the method is pure virtual, it is always needed. * Also wrap non-virtual protected members if asked for (allprotected mode). */ @@ -894,7 +909,7 @@ int Language::cDeclaration(Node *n) { } } - if (symname && !validIdentifier(symname)) { + if (!validIdentifier(symname)) { Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap '%s' unless renamed to a valid identifier.\n", symname); return SWIG_NOWRAP; } @@ -964,17 +979,9 @@ int Language::cDeclaration(Node *n) { Delete(SwigType_pop_function(ty)); DohIncref(type); Setattr(n, "type", ty); - if (GetFlag(n, "feature:onlychildren") && !GetFlag(n, "feature:ignore")) { - // Found an unignored templated method that has an empty template instantiation (%template()) - // Ignore it unless it has been %rename'd - if (Strncmp(symname, "__dummy_", 8) == 0) { - SetFlag(n, "feature:ignore"); - Swig_warning(WARN_LANG_TEMPLATE_METHOD_IGNORE, input_file, line_number, - "%%template() contains no name. Template method ignored: %s\n", Swig_name_decl(n)); - } - } - if (!GetFlag(n, "feature:ignore")) - functionHandler(n); + + functionHandler(n); + Setattr(n, "type", type); Delete(ty); Delete(type); @@ -2790,7 +2797,7 @@ int Language::destructorHandler(Node *n) { String *symname = Getattr(n, "sym:name"); String *mrename; char *csymname = Char(symname); - if (csymname && (*csymname == '~')) + if (*csymname == '~') csymname += 1; mrename = Swig_name_destroy(NSpace, csymname); From dad24760917fc186e06aac764414c844947a608f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 22 Nov 2012 23:21:54 +0000 Subject: [PATCH 0285/1160] Minor logic fix. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13928 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/lang.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 6e9afbad3..ff6226efc 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -3503,7 +3503,7 @@ int Language::abstractClassTest(Node *n) { } else { return 1; } - return dirabstract ? 1 : 0; + return 0; } void Language::setSubclassInstanceCheck(String *nc) { From afec99c64fdbcda407fee49a2a21cd048e61eea7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 22 Nov 2012 23:22:34 +0000 Subject: [PATCH 0286/1160] Remove some useless code git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13929 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/lang.cxx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index ff6226efc..144638366 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1138,18 +1138,12 @@ int Language::callbackfunctionHandler(Node *n) { String *type = Getattr(n, "type"); String *name = Getattr(n, "name"); String *parms = Getattr(n, "parms"); - String *cb = GetFlagAttr(n, "feature:callback"); String *cbname = Getattr(n, "feature:callback:name"); String *calltype = NewStringf("(%s (*)(%s))(%s)", SwigType_str(type, 0), ParmList_str(parms), SwigType_namestr(name)); SwigType *cbty = Copy(type); SwigType_add_function(cbty, parms); SwigType_add_pointer(cbty); - if (!cbname) { - cbname = NewStringf(cb, symname); - Setattr(n, "feature:callback:name", cbname); - } - Setattr(n, "sym:name", cbname); Setattr(n, "type", cbty); Setattr(n, "value", calltype); @@ -1158,7 +1152,6 @@ int Language::callbackfunctionHandler(Node *n) { if (!ns) constantWrapper(n); - Delete(cbname); Delete(cbty); Swig_restore(n); From 14446c365b031147e1a6606218a4e2cb853d219e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 22 Nov 2012 23:23:15 +0000 Subject: [PATCH 0287/1160] Minor logic and memory leak fix. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13930 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/lang.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 144638366..b701d9354 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -3470,6 +3470,7 @@ int Language::abstractClassTest(Node *n) { String *check_item = Getattr(item, "vmid"); if (Strcmp(method_id, check_item) == 0) { exists_item = true; + Delete(method_id); break; } } From f3e253771c57b2dea0bdb96c32a08772218b5b5d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 23 Nov 2012 07:36:10 +0000 Subject: [PATCH 0288/1160] Remove incorrect Delete git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13931 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/lang.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index b701d9354..144638366 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -3470,7 +3470,6 @@ int Language::abstractClassTest(Node *n) { String *check_item = Getattr(item, "vmid"); if (Strcmp(method_id, check_item) == 0) { exists_item = true; - Delete(method_id); break; } } From 0d2c4590462d222ccd6481fcf0db85f97eedb769 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 23 Nov 2012 07:38:00 +0000 Subject: [PATCH 0289/1160] Remove some unused code and pointless variable assignments git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13932 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/csharp.cxx | 4 ++-- Source/Modules/d.cxx | 4 ++-- Source/Modules/java.cxx | 8 ++++---- Source/Modules/lang.cxx | 1 - Source/Modules/octave.cxx | 2 +- Source/Modules/php.cxx | 7 +------ Source/Modules/python.cxx | 2 +- Source/Modules/r.cxx | 2 +- Source/Modules/ruby.cxx | 6 +----- 9 files changed, 13 insertions(+), 23 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index d715aadb2..619fb7ebd 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -925,7 +925,7 @@ public: if ((throw_parm_list = Getattr(n, "catchlist"))) { Swig_typemap_attach_parms("throws", throw_parm_list, f); for (p = throw_parm_list; p; p = nextSibling(p)) { - if ((tm = Getattr(p, "tmap:throws"))) { + if (Getattr(p, "tmap:throws")) { canThrow(n, "throws", p); } } @@ -3747,7 +3747,7 @@ public: if (throw_parm_list) Swig_typemap_attach_parms("throws", throw_parm_list, 0); for (p = throw_parm_list; p; p = nextSibling(p)) { - if ((tm = Getattr(p, "tmap:throws"))) { + if (Getattr(p, "tmap:throws")) { if (gencomma++) { Append(w->def, ", "); Append(declaration, ", "); diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 29f96e548..a1a454bd0 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -1695,7 +1695,7 @@ public: if ((throw_parm_list = Getattr(n, "catchlist"))) { Swig_typemap_attach_parms("throws", throw_parm_list, f); for (p = throw_parm_list; p; p = nextSibling(p)) { - if ((tm = Getattr(p, "tmap:throws"))) { + if (Getattr(p, "tmap:throws")) { canThrow(n, "throws", p); } } @@ -2224,7 +2224,7 @@ public: if (throw_parm_list) Swig_typemap_attach_parms("throws", throw_parm_list, 0); for (p = throw_parm_list; p; p = nextSibling(p)) { - if ((tm = Getattr(p, "tmap:throws"))) { + if (Getattr(p, "tmap:throws")) { if (gencomma++) { Append(w->def, ", "); Append(declaration, ", "); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index bfa02d7e2..d59ca8bd6 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1016,7 +1016,7 @@ public: if ((throw_parm_list = Getattr(n, "catchlist"))) { Swig_typemap_attach_parms("throws", throw_parm_list, f); for (p = throw_parm_list; p; p = nextSibling(p)) { - if ((tm = Getattr(p, "tmap:throws"))) { + if (Getattr(p, "tmap:throws")) { addThrows(n, "tmap:throws", p); } } @@ -3631,7 +3631,7 @@ public: SwigType *adjustedreturntype = covariant ? covariant : returntype; Parm *adjustedreturntypeparm = NewParmNode(adjustedreturntype, n); - if ((tm = Swig_typemap_lookup("directorin", adjustedreturntypeparm, "", 0)) + if (Swig_typemap_lookup("directorin", adjustedreturntypeparm, "", 0) && (cdesc = Getattr(adjustedreturntypeparm, "tmap:directorin:descriptor"))) { // Note that in the case of polymorphic (covariant) return types, the @@ -3658,7 +3658,7 @@ public: } String *jdesc = NULL; - if ((tm = Swig_typemap_lookup("directorin", tp, "", 0)) + if (Swig_typemap_lookup("directorin", tp, "", 0) && (jdesc = Getattr(tp, "tmap:directorin:descriptor"))) { // Objects marshalled passing a Java class across JNI boundary use jobject - the nouse flag indicates this @@ -3911,7 +3911,7 @@ public: if (throw_parm_list) Swig_typemap_attach_parms("throws", throw_parm_list, 0); for (p = throw_parm_list; p; p = nextSibling(p)) { - if ((tm = Getattr(p, "tmap:throws"))) { + if (Getattr(p, "tmap:throws")) { addThrows(n, "tmap:throws", p); if (gencomma++) { diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 144638366..002a1fdd7 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1134,7 +1134,6 @@ int Language::globalfunctionHandler(Node *n) { int Language::callbackfunctionHandler(Node *n) { Swig_require("callbackfunctionHandler", n, "name", "*sym:name", "*type", "?value", NIL); - String *symname = Getattr(n, "sym:name"); String *type = Getattr(n, "type"); String *name = Getattr(n, "name"); String *parms = Getattr(n, "parms"); diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index f78c71fd3..7d27c1095 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -1319,7 +1319,7 @@ public: if (throw_parm_list) Swig_typemap_attach_parms("throws", throw_parm_list, 0); for (p = throw_parm_list; p; p = nextSibling(p)) { - if ((tm = Getattr(p, "tmap:throws"))) { + if (Getattr(p, "tmap:throws")) { if (gencomma++) { Append(w->def, ", "); Append(declaration, ", "); diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 1f2078a1e..986911a12 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1177,11 +1177,6 @@ public: if (!o) { // This "overloaded method" is really just one with default args. really_overloaded = false; - if (l != full_parmlist) { - l = full_parmlist; - if (wrapperType == memberfn) - l = nextSibling(l); - } } } @@ -2472,7 +2467,7 @@ done: if (throw_parm_list) Swig_typemap_attach_parms("throws", throw_parm_list, 0); for (p = throw_parm_list; p; p = nextSibling(p)) { - if ((tm = Getattr(p, "tmap:throws"))) { + if (Getattr(p, "tmap:throws")) { if (gencomma++) { Append(w->def, ", "); Append(declaration, ", "); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 56107e0c0..5dc2cb8be 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -4583,7 +4583,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { if (throw_parm_list) Swig_typemap_attach_parms("throws", throw_parm_list, 0); for (p = throw_parm_list; p; p = nextSibling(p)) { - if ((tm = Getattr(p, "tmap:throws"))) { + if (Getattr(p, "tmap:throws")) { if (gencomma++) { Append(w->def, ", "); Append(declaration, ", "); diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index ab13cb7fc..078b2576c 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -572,7 +572,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) { Parm *p = parms; for (i = 0; p; p = nextSibling(p), ++i) { String *arg = Getattr(p, "name"); - String *lname = NewString(""); + String *lname; if (!arg && Cmp(Getattr(p, "type"), "void")) { lname = NewStringf("s_arg%d", i+1); diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index e16bbc9ba..ff8d70d46 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -737,10 +737,6 @@ private: String *autodoc = Getattr(n, "feature:autodoc"); autodoc_l dlevel = autodoc_level(autodoc); - symname = Getattr(n, "sym:name"); - if ( Getattr( special_methods, symname ) ) - symname = Getattr( special_methods, symname ); - switch (dlevel) { case NO_AUTODOC: case NAMES_AUTODOC: @@ -3093,7 +3089,7 @@ public: if (throw_parm_list) Swig_typemap_attach_parms("throws", throw_parm_list, 0); for (p = throw_parm_list; p; p = nextSibling(p)) { - if ((tm = Getattr(p, "tmap:throws"))) { + if (Getattr(p, "tmap:throws")) { if (gencomma++) { Append(w->def, ", "); Append(declaration, ", "); From 7a89f71f3632512bb2de90b0e263dfacbdc0c05b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 24 Nov 2012 14:12:25 +0000 Subject: [PATCH 0290/1160] Coverity defect suppression git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13933 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/clisp.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/clisp.cxx b/Source/Modules/clisp.cxx index 3a4a5648c..7bfb6298c 100644 --- a/Source/Modules/clisp.cxx +++ b/Source/Modules/clisp.cxx @@ -132,9 +132,9 @@ int CLISP::top(Node *n) { for (len--; len >= 0; len--) { end--; - Seek(f_cl, len, SEEK_SET); + (void)Seek(f_cl, len, SEEK_SET); int ch = Getc(f_cl); - Seek(f_cl, end, SEEK_SET); + (void)Seek(f_cl, end, SEEK_SET); Putc(ch, f_cl); } From 709d683926f8446c79eadfcd23fa677bd715b1de Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 24 Nov 2012 14:12:57 +0000 Subject: [PATCH 0291/1160] Minor code optimisation git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13934 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/allocate.cxx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index 81a732638..8c8450312 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -336,15 +336,13 @@ class Allocate:public Dispatcher { String *name = Getattr(nn, "name"); if (!name) continue; + if (Strchr(name, '~')) + continue; /* Don't care about destructors */ String *base_decl = Getattr(nn, "decl"); if (base_decl) base_decl = SwigType_typedef_resolve_all(base_decl); - if (Strchr(name, '~')) - continue; /* Don't care about destructors */ - - if (SwigType_isfunction(base_decl)) { + if (SwigType_isfunction(base_decl)) search_decl = SwigType_pop_function(base_decl); - } Node *dn = Swig_symbol_clookup_local_check(name, 0, check_implemented); Delete(search_decl); Delete(base_decl); @@ -415,7 +413,7 @@ class Allocate:public Dispatcher { match = 1; break; } - if ((!symname || (!Getattr(e, "sym:name"))) && (Cmp(name, Getattr(e, "name")) == 0)) { + if (!Getattr(e, "sym:name") && (Cmp(name, Getattr(e, "name")) == 0)) { match = 1; break; } From d93dc0f8e23eb9fb18841bf50b2b505e61ff5a94 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 24 Nov 2012 14:13:58 +0000 Subject: [PATCH 0292/1160] Distinguish between an "abstract" attribute on a class containing a list of abstract members and an "abstract" flag on pure virtual methods - renamed former to "abstracts" git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13935 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/CParse/parser.y | 10 +++++----- Source/Modules/allocate.cxx | 24 ++++++++++++------------ Source/Modules/csharp.cxx | 2 +- Source/Modules/d.cxx | 2 +- Source/Modules/java.cxx | 2 +- Source/Modules/lang.cxx | 12 ++++++------ Source/Modules/php.cxx | 6 +++--- Source/Modules/python.cxx | 2 +- Source/Modules/tcl8.cxx | 2 +- Source/Swig/cwrap.c | 2 +- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 2774014ab..cd3d73eca 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -740,7 +740,7 @@ static List *pure_abstract(Node *n) { abs = NewList(); } Append(abs,n); - Setattr(n,"abstract","1"); + SetFlag(n,"abstract"); } } } else if (Cmp(nodeType(n),"destructor") == 0) { @@ -749,7 +749,7 @@ static List *pure_abstract(Node *n) { abs = NewList(); } Append(abs,n); - Setattr(n,"abstract","1"); + SetFlag(n,"abstract"); } } n = nextSibling(n); @@ -3002,7 +3002,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va if (Strcmp(nodeType(templnode),"class") == 0) { /* Identify pure abstract methods */ - Setattr(templnode,"abstract", pure_abstract(firstChild(templnode))); + Setattr(templnode,"abstracts", pure_abstract(firstChild(templnode))); /* Set up inheritance in symbol table */ { @@ -3574,7 +3574,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { inclass = 0; /* Check for pure-abstract class */ - Setattr($$,"abstract", pure_abstract($7)); + Setattr($$,"abstracts", pure_abstract($7)); /* This bit of code merges in a previously defined %extend directive (if any) */ @@ -3737,7 +3737,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { unnamed = Getattr($$,"unnamed"); /* Check for pure-abstract class */ - Setattr($$,"abstract", pure_abstract($5)); + Setattr($$,"abstracts", pure_abstract($5)); n = new_node("cdecl"); Setattr(n,"name",$7.id); diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index 8c8450312..91fad132f 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -43,7 +43,7 @@ extern "C" { SwigType *decl1 = SwigType_typedef_resolve_all(decl); SwigType *decl2 = SwigType_pop_function(decl1); if (Strcmp(decl2, search_decl) == 0) { - if (!Getattr(n, "abstract")) { + if (!GetFlag(n, "abstract")) { Delete(decl1); Delete(decl2); return 1; @@ -327,7 +327,7 @@ class Allocate:public Dispatcher { Swig_symbol_setscope(oldtab); return ret; } - List *abstract = Getattr(base, "abstract"); + List *abstract = Getattr(base, "abstracts"); if (abstract) { int dabstract = 0; int len = Len(abstract); @@ -348,15 +348,15 @@ class Allocate:public Dispatcher { Delete(base_decl); if (!dn) { - List *nabstract = Getattr(n, "abstract"); + List *nabstract = Getattr(n, "abstracts"); if (!nabstract) { nabstract = NewList(); - Setattr(n, "abstract", nabstract); + Setattr(n, "abstracts", nabstract); Delete(nabstract); } Append(nabstract, nn); - if (!Getattr(n, "abstract:firstnode")) { - Setattr(n, "abstract:firstnode", nn); + if (!Getattr(n, "abstracts:firstnode")) { + Setattr(n, "abstracts:firstnode", nn); } dabstract = base != n; } @@ -596,18 +596,18 @@ Allocate(): /* Check if the class is abstract via inheritance. This might occur if a class didn't have any pure virtual methods of its own, but it didn't implement all of the pure methods in a base class */ - if (!Getattr(n, "abstract") && is_abstract_inherit(n)) { + if (!Getattr(n, "abstracts") && is_abstract_inherit(n)) { if (((Getattr(n, "allocate:public_constructor") || (!GetFlag(n, "feature:nodefault") && !Getattr(n, "allocate:has_constructor"))))) { if (!GetFlag(n, "feature:notabstract")) { - Node *na = Getattr(n, "abstract:firstnode"); + Node *na = Getattr(n, "abstracts:firstnode"); if (na) { Swig_warning(WARN_TYPE_ABSTRACT, Getfile(n), Getline(n), "Class '%s' might be abstract, " "no constructors generated,\n", SwigType_namestr(Getattr(n, "name"))); Swig_warning(WARN_TYPE_ABSTRACT, Getfile(na), Getline(na), "Method %s might not be implemented.\n", Swig_name_decl(na)); - if (!Getattr(n, "abstract")) { + if (!Getattr(n, "abstracts")) { List *abstract = NewList(); Append(abstract, na); - Setattr(n, "abstract", abstract); + Setattr(n, "abstracts", abstract); Delete(abstract); } } @@ -618,7 +618,7 @@ Allocate(): if (!Getattr(n, "allocate:has_constructor")) { /* No constructor is defined. We need to check a few things */ /* If class is abstract. No default constructor. Sorry */ - if (Getattr(n, "abstract")) { + if (Getattr(n, "abstracts")) { Delattr(n, "allocate:default_constructor"); } if (!Getattr(n, "allocate:default_constructor")) { @@ -639,7 +639,7 @@ Allocate(): } } if (!Getattr(n, "allocate:has_copy_constructor")) { - if (Getattr(n, "abstract")) { + if (Getattr(n, "abstracts")) { Delattr(n, "allocate:copy_constructor"); } if (!Getattr(n, "allocate:copy_constructor")) { diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 619fb7ebd..c54475029 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3512,7 +3512,7 @@ public: Symtab *symtab = Getattr(n, "sym:symtab"); Node *typenode = Swig_symbol_clookup(resolved_typename, symtab); - if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) { + if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstracts"))) { /* initialize pointers to something sane. Same for abstract classes when a reference is returned. */ Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index a1a454bd0..1ea74eb6b 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -1984,7 +1984,7 @@ public: Symtab *symtab = Getattr(n, "sym:symtab"); Node *typenode = Swig_symbol_clookup(resolved_typename, symtab); - if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) { + if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstracts"))) { /* initialize pointers to something sane. Same for abstract classes when a reference is returned. */ Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index d59ca8bd6..cd8cfe543 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3583,7 +3583,7 @@ public: Symtab *symtab = Getattr(n, "sym:symtab"); Node *typenode = Swig_symbol_clookup(resolved_typename, symtab); - if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) { + if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstracts"))) { /* initialize pointers to something sane. Same for abstract classes when a reference is returned. */ Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 002a1fdd7..043473bc6 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2649,18 +2649,18 @@ static String *get_director_ctor_code(Node *n, String *director_ctor_code, Strin int use_director = Swig_directorclass(n); if (use_director) { Node *pn = Swig_methodclass(n); - abstract = Getattr(pn, "abstract"); + abstract = Getattr(pn, "abstracts"); if (director_prot_ctor_code) { int is_notabstract = GetFlag(pn, "feature:notabstract"); int is_abstract = abstract && !is_notabstract; if (is_protected(n) || is_abstract) { director_ctor = director_prot_ctor_code; abstract = Copy(abstract); - Delattr(pn, "abstract"); + Delattr(pn, "abstracts"); } else { if (is_notabstract) { abstract = Copy(abstract); - Delattr(pn, "abstract"); + Delattr(pn, "abstracts"); } else { abstract = 0; } @@ -2696,7 +2696,7 @@ int Language::constructorHandler(Node *n) { Delete(mrename); Swig_restore(n); if (abstract) - Setattr(Swig_methodclass(n), "abstract", abstract); + Setattr(Swig_methodclass(n), "abstracts", abstract); return SWIG_OK; } @@ -2718,7 +2718,7 @@ int Language::copyconstructorHandler(Node *n) { Delete(mrename); Swig_restore(n); if (abstract) - Setattr(Swig_methodclass(n), "abstract", abstract); + Setattr(Swig_methodclass(n), "abstracts", abstract); return SWIG_OK; } @@ -3436,7 +3436,7 @@ int Language::abstractClassTest(Node *n) { if (Getattr(n, "allocate:nonew")) return 1; /* now check for the rest */ - List *abstract = Getattr(n, "abstract"); + List *abstract = Getattr(n, "abstracts"); if (!abstract) return 0; int labs = Len(abstract); diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 986911a12..149b3cd83 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1698,9 +1698,9 @@ public: Printf(output, "\t\t$r=%s;\n", invoke); if (Len(ret_types) == 1) { /* If d is abstract we can't create a new wrapper type d. */ - Node * d_class = classLookup(d); + Node *d_class = classLookup(d); int is_abstract = 0; - if (Getattr(d_class, "abstract")) { + if (Getattr(d_class, "abstracts")) { is_abstract = 1; } if (newobject || !is_abstract) { @@ -2020,7 +2020,7 @@ done: base.item = NULL; } - if (Getattr(n, "abstract") && !GetFlag(n, "feature:notabstract")) { + if (Getattr(n, "abstracts") && !GetFlag(n, "feature:notabstract")) { Printf(s_phpclasses, "abstract "); } diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 5dc2cb8be..43d306b09 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -3794,7 +3794,7 @@ public: if (!have_constructor) { if (!builtin) Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", - (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL); + (Getattr(n, "abstracts") ? " - class is abstract" : ""), "\")\n", NIL); } else if (fastinit && !builtin) { Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx index a4f29183c..91e74f4ca 100644 --- a/Source/Modules/tcl8.cxx +++ b/Source/Modules/tcl8.cxx @@ -942,7 +942,7 @@ public: Printv(f_shadow, " constructor { } {\n", NIL); Printv(f_shadow, " # This constructor will fail if called directly\n", NIL); Printv(f_shadow, " if { [info class] == \"::", class_name, "\" } {\n", NIL); - Printv(f_shadow, " error \"No constructor for class ", class_name, (Getattr(n, "abstract") ? " - class is abstract" : ""), "\"\n", NIL); + Printv(f_shadow, " error \"No constructor for class ", class_name, (Getattr(n, "abstracts") ? " - class is abstract" : ""), "\"\n", NIL); Printv(f_shadow, " }\n", NIL); Printv(f_shadow, " }\n", NIL); } diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index a032de746..063ab9858 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -1165,7 +1165,7 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String /* if a C++ director class exists, create it rather than the original class */ if (use_director) { Node *parent = Swig_methodclass(n); - int abstract = Getattr(parent, "abstract") != 0; + int abstract = Getattr(parent, "abstracts") != 0; String *name = Getattr(parent, "sym:name"); String *directorname = NewStringf("SwigDirector_%s", name); String *action = NewStringEmpty(); From 9b40eb58e3c7c50f1f9012aa03f7f97630e3340b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 24 Nov 2012 14:15:20 +0000 Subject: [PATCH 0293/1160] cosmetic variable name changes for abstracts to match previous commit git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13936 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/CParse/parser.y | 24 +++++++++++------------ Source/Modules/allocate.cxx | 28 +++++++++++++-------------- Source/Modules/lang.cxx | 38 ++++++++++++++++++------------------- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index cd3d73eca..b758316e4 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -728,33 +728,33 @@ static void check_extensions() { /* Check a set of declarations to see if any are pure-abstract */ -static List *pure_abstract(Node *n) { - List *abs = 0; +static List *pure_abstracts(Node *n) { + List *abstracts = 0; while (n) { if (Cmp(nodeType(n),"cdecl") == 0) { String *decl = Getattr(n,"decl"); if (SwigType_isfunction(decl)) { String *init = Getattr(n,"value"); if (Cmp(init,"0") == 0) { - if (!abs) { - abs = NewList(); + if (!abstracts) { + abstracts = NewList(); } - Append(abs,n); + Append(abstracts,n); SetFlag(n,"abstract"); } } } else if (Cmp(nodeType(n),"destructor") == 0) { if (Cmp(Getattr(n,"value"),"0") == 0) { - if (!abs) { - abs = NewList(); + if (!abstracts) { + abstracts = NewList(); } - Append(abs,n); + Append(abstracts,n); SetFlag(n,"abstract"); } } n = nextSibling(n); } - return abs; + return abstracts; } /* Make a classname */ @@ -3002,7 +3002,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va if (Strcmp(nodeType(templnode),"class") == 0) { /* Identify pure abstract methods */ - Setattr(templnode,"abstracts", pure_abstract(firstChild(templnode))); + Setattr(templnode,"abstracts", pure_abstracts(firstChild(templnode))); /* Set up inheritance in symbol table */ { @@ -3574,7 +3574,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { inclass = 0; /* Check for pure-abstract class */ - Setattr($$,"abstracts", pure_abstract($7)); + Setattr($$,"abstracts", pure_abstracts($7)); /* This bit of code merges in a previously defined %extend directive (if any) */ @@ -3737,7 +3737,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { unnamed = Getattr($$,"unnamed"); /* Check for pure-abstract class */ - Setattr($$,"abstracts", pure_abstract($5)); + Setattr($$,"abstracts", pure_abstracts($5)); n = new_node("cdecl"); Setattr(n,"name",$7.id); diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index 91fad132f..4c884caca 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -327,12 +327,12 @@ class Allocate:public Dispatcher { Swig_symbol_setscope(oldtab); return ret; } - List *abstract = Getattr(base, "abstracts"); - if (abstract) { + List *abstracts = Getattr(base, "abstracts"); + if (abstracts) { int dabstract = 0; - int len = Len(abstract); + int len = Len(abstracts); for (int i = 0; i < len; i++) { - Node *nn = Getitem(abstract, i); + Node *nn = Getitem(abstracts, i); String *name = Getattr(nn, "name"); if (!name) continue; @@ -348,13 +348,13 @@ class Allocate:public Dispatcher { Delete(base_decl); if (!dn) { - List *nabstract = Getattr(n, "abstracts"); - if (!nabstract) { - nabstract = NewList(); - Setattr(n, "abstracts", nabstract); - Delete(nabstract); + List *nabstracts = Getattr(n, "abstracts"); + if (!nabstracts) { + nabstracts = NewList(); + Setattr(n, "abstracts", nabstracts); + Delete(nabstracts); } - Append(nabstract, nn); + Append(nabstracts, nn); if (!Getattr(n, "abstracts:firstnode")) { Setattr(n, "abstracts:firstnode", nn); } @@ -605,10 +605,10 @@ Allocate(): "Class '%s' might be abstract, " "no constructors generated,\n", SwigType_namestr(Getattr(n, "name"))); Swig_warning(WARN_TYPE_ABSTRACT, Getfile(na), Getline(na), "Method %s might not be implemented.\n", Swig_name_decl(na)); if (!Getattr(n, "abstracts")) { - List *abstract = NewList(); - Append(abstract, na); - Setattr(n, "abstracts", abstract); - Delete(abstract); + List *abstracts = NewList(); + Append(abstracts, na); + Setattr(n, "abstracts", abstracts); + Delete(abstracts); } } } diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 043473bc6..ad2a0d6b8 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2644,25 +2644,25 @@ int Language::constructorDeclaration(Node *n) { * get_director_ctor_code() * ---------------------------------------------------------------------- */ -static String *get_director_ctor_code(Node *n, String *director_ctor_code, String *director_prot_ctor_code, List *&abstract) { +static String *get_director_ctor_code(Node *n, String *director_ctor_code, String *director_prot_ctor_code, List *&abstracts) { String *director_ctor = director_ctor_code; int use_director = Swig_directorclass(n); if (use_director) { Node *pn = Swig_methodclass(n); - abstract = Getattr(pn, "abstracts"); + abstracts = Getattr(pn, "abstracts"); if (director_prot_ctor_code) { int is_notabstract = GetFlag(pn, "feature:notabstract"); - int is_abstract = abstract && !is_notabstract; + int is_abstract = abstracts && !is_notabstract; if (is_protected(n) || is_abstract) { director_ctor = director_prot_ctor_code; - abstract = Copy(abstract); + abstracts = Copy(abstracts); Delattr(pn, "abstracts"); } else { if (is_notabstract) { - abstract = Copy(abstract); + abstracts = Copy(abstracts); Delattr(pn, "abstracts"); } else { - abstract = 0; + abstracts = 0; } } } @@ -2681,10 +2681,10 @@ int Language::constructorHandler(Node *n) { String *mrename = Swig_name_construct(NSpace, symname); String *nodeType = Getattr(n, "nodeType"); int constructor = (!Cmp(nodeType, "constructor")); - List *abstract = 0; + List *abstracts = 0; String *director_ctor = get_director_ctor_code(n, director_ctor_code, director_prot_ctor_code, - abstract); + abstracts); if (!constructor) { /* if not originally a constructor, still handle it as one */ Setattr(n, "handled_as_constructor", "1"); @@ -2695,8 +2695,8 @@ int Language::constructorHandler(Node *n) { functionWrapper(n); Delete(mrename); Swig_restore(n); - if (abstract) - Setattr(Swig_methodclass(n), "abstracts", abstract); + if (abstracts) + Setattr(Swig_methodclass(n), "abstracts", abstracts); return SWIG_OK; } @@ -2708,17 +2708,17 @@ 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(NSpace, symname); - List *abstract = 0; + List *abstracts = 0; String *director_ctor = get_director_ctor_code(n, director_ctor_code, director_prot_ctor_code, - abstract); + abstracts); Swig_ConstructorToFunction(n, NSpace, ClassType, none_comparison, director_ctor, CPlusPlus, Getattr(n, "template") ? 0 : Extend); Setattr(n, "sym:name", mrename); functionWrapper(n); Delete(mrename); Swig_restore(n); - if (abstract) - Setattr(Swig_methodclass(n), "abstracts", abstract); + if (abstracts) + Setattr(Swig_methodclass(n), "abstracts", abstracts); return SWIG_OK; } @@ -3436,17 +3436,17 @@ int Language::abstractClassTest(Node *n) { if (Getattr(n, "allocate:nonew")) return 1; /* now check for the rest */ - List *abstract = Getattr(n, "abstracts"); - if (!abstract) + List *abstracts = Getattr(n, "abstracts"); + if (!abstracts) return 0; - int labs = Len(abstract); + int labs = Len(abstracts); #ifdef SWIG_DEBUG List *bases = Getattr(n, "allbases"); Printf(stderr, "testing %s %d %d\n", Getattr(n, "name"), labs, Len(bases)); #endif if (!labs) return 0; /*strange, but need to be fixed */ - if (abstract && !directorsEnabled()) + if (abstracts && !directorsEnabled()) return 1; if (!GetFlag(n, "feature:director")) return 1; @@ -3458,7 +3458,7 @@ int Language::abstractClassTest(Node *n) { Printf(stderr, "vtable %s %d %d\n", Getattr(n, "name"), Len(vtable), labs); #endif for (int i = 0; i < labs; i++) { - Node *ni = Getitem(abstract, i); + Node *ni = Getitem(abstracts, i); Node *method_id = vtable_method_id(ni); if (!method_id) continue; From b596ddbbc134246d8af254966652a9c12d5e668d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 26 Nov 2012 20:28:09 +0000 Subject: [PATCH 0294/1160] Correct type change from char * to String introduced in rev 13904 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13937 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Preprocessor/cpp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 4366a8434..7e45c5bd4 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -1870,7 +1870,7 @@ String *Preprocessor_parse(String *s) { push_imported(); } dirname = Swig_file_dirname(Swig_last_file()); - if (sysfile || !strlen(dirname)) { + if (sysfile || !Len(dirname)) { Delete(dirname); dirname = 0; } From c7df90e6752444340ac5a6760c7fe0f7b89641e9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 26 Nov 2012 20:29:00 +0000 Subject: [PATCH 0295/1160] Fix String */ char * mismatch git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13938 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/CParse/parser.y | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index b758316e4..03fc329d8 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1153,7 +1153,7 @@ static void nested_new_struct(const char *kind, String *struct_code, Node *cpp_o * nested class solution is implemented. * ----------------------------------------------------------------------------- */ -static Node *nested_forward_declaration(const char *storage, const char *kind, String *sname, const char *name, Node *cpp_opt_declarators) { +static Node *nested_forward_declaration(const char *storage, const char *kind, String *sname, String *name, Node *cpp_opt_declarators) { Node *nn = 0; int warned = 0; @@ -1178,7 +1178,7 @@ static Node *nested_forward_declaration(const char *storage, const char *kind, S if (!variable_of_anonymous_type) { int anonymous_typedef = !sname && (storage && (strcmp(storage, "typedef") == 0)); Node *n = cpp_opt_declarators; - SwigType *type = NewString(name); + SwigType *type = name; while (n) { Setattr(n, "type", type); Setattr(n, "storage", storage); @@ -1188,7 +1188,6 @@ static Node *nested_forward_declaration(const char *storage, const char *kind, S } n = nextSibling(n); } - Delete(type); add_symbols(cpp_opt_declarators); if (nn) { @@ -4660,7 +4659,7 @@ cpp_nested : storage_class cpptype idcolon inherit LBRACE { $$ = 0; if (cplus_mode == CPLUS_PUBLIC) { if (cparse_cplusplus) { - const char *name = $6 ? Getattr($6, "name") : 0; + String *name = $6 ? Getattr($6, "name") : 0; $$ = nested_forward_declaration($1, $2, 0, name, $6); } else { if ($6) { From dac89e16d479366c5e79da4de29898af97262d23 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 26 Nov 2012 20:30:37 +0000 Subject: [PATCH 0296/1160] const char * correctness fixes (in C code) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13939 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/DOH/doh.h | 2 +- Source/DOH/dohint.h | 2 +- Source/DOH/fio.c | 4 ++-- Source/Preprocessor/cpp.c | 4 ++-- Source/Preprocessor/expr.c | 4 ++-- Source/Preprocessor/preprocessor.h | 2 +- Source/Swig/tree.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/DOH/doh.h b/Source/DOH/doh.h index a0bd1817c..8071edd4d 100644 --- a/Source/DOH/doh.h +++ b/Source/DOH/doh.h @@ -254,7 +254,7 @@ extern int DohDelmeta(DOH *, const DOH *); /* Utility functions */ -extern void DohEncoding(char *name, DOH *(*fn) (DOH *s)); +extern void DohEncoding(const char *name, DOH *(*fn) (DOH *s)); extern int DohPrintf(DOHFile * obj, const char *format, ...); extern int DohvPrintf(DOHFile * obj, const char *format, va_list ap); extern int DohPrintv(DOHFile * obj, ...); diff --git a/Source/DOH/dohint.h b/Source/DOH/dohint.h index 9f5c06272..c073bd95b 100644 --- a/Source/DOH/dohint.h +++ b/Source/DOH/dohint.h @@ -63,7 +63,7 @@ typedef struct { * ----------------------------------------------------------------------------- */ typedef struct DohObjInfo { - char *objname; /* Object name */ + const char *objname; /* Object name */ /* Basic object methods */ void (*doh_del) (DOH *obj); /* Delete object */ diff --git a/Source/DOH/fio.c b/Source/DOH/fio.c index 3557b3c37..c4fbb1e8f 100644 --- a/Source/DOH/fio.c +++ b/Source/DOH/fio.c @@ -47,7 +47,7 @@ static int Writen(DOH *out, void *buffer, int len) { * two file-like objects and operate as a filter. * ----------------------------------------------------------------------------- */ -void DohEncoding(char *name, DOH *(*fn) (DOH *s)) { +void DohEncoding(const char *name, DOH *(*fn) (DOH *s)) { if (!encodings) encodings = NewHash(); Setattr(encodings, (void *) name, NewVoid((void *) fn, 0)); @@ -102,7 +102,7 @@ static DOH *encode(char *name, DOH *s) { * ----------------------------------------------------------------------------- */ int DohvPrintf(DOH *so, const char *format, va_list ap) { - static char *fmt_codes = "dioxXucsSfeEgGpn"; + static const char *fmt_codes = "dioxXucsSfeEgGpn"; int state = 0; const char *p = format; char newformat[256]; diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 7e45c5bd4..c16fbe7e5 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -1637,7 +1637,7 @@ String *Preprocessor_parse(String *s) { if (Len(sval) > 0) { val = Preprocessor_expr(sval, &e); if (e) { - char *msg = Preprocessor_expr_error(); + const char *msg = Preprocessor_expr_error(); Seek(value, 0, SEEK_SET); Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Could not evaluate expression '%s'\n", value); if (msg) @@ -1671,7 +1671,7 @@ String *Preprocessor_parse(String *s) { if (Len(sval) > 0) { val = Preprocessor_expr(sval, &e); if (e) { - char *msg = Preprocessor_expr_error(); + const char *msg = Preprocessor_expr_error(); Seek(value, 0, SEEK_SET); Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Could not evaluate expression '%s'\n", value); if (msg) diff --git a/Source/Preprocessor/expr.c b/Source/Preprocessor/expr.c index e7470378d..b32665d4a 100644 --- a/Source/Preprocessor/expr.c +++ b/Source/Preprocessor/expr.c @@ -35,7 +35,7 @@ static exprval stack[256]; /* Parsing stack */ static int sp = 0; /* Stack pointer */ static int prec[256]; /* Precedence rules */ static int expr_init = 0; /* Initialization flag */ -static char *errmsg = 0; /* Parsing error */ +static const char *errmsg = 0; /* Parsing error */ /* Initialize the precedence table for various operators. Low values have higher precedence */ static void init_precedence() { @@ -435,6 +435,6 @@ extra_rparen: * Return error message set by the evaluator (if any) * ----------------------------------------------------------------------------- */ -char *Preprocessor_expr_error() { +const char *Preprocessor_expr_error() { return errmsg; } diff --git a/Source/Preprocessor/preprocessor.h b/Source/Preprocessor/preprocessor.h index b08ff31b9..4c24f48d0 100644 --- a/Source/Preprocessor/preprocessor.h +++ b/Source/Preprocessor/preprocessor.h @@ -20,7 +20,7 @@ extern "C" { #endif extern int Preprocessor_expr(String *s, int *error); - extern char *Preprocessor_expr_error(void); + extern const char *Preprocessor_expr_error(void); extern Hash *Preprocessor_define(const_String_or_char_ptr str, int swigmacro); extern void Preprocessor_undef(const_String_or_char_ptr name); extern void Preprocessor_init(void); diff --git a/Source/Swig/tree.c b/Source/Swig/tree.c index af22da156..b5c9d26dc 100644 --- a/Source/Swig/tree.c +++ b/Source/Swig/tree.c @@ -82,7 +82,7 @@ void Swig_print_node(Node *obj) { Printf(stdout, "%-12s - %s\n", k, ParmList_str_defaultargs(Getattr(obj, k))); } else { DOH *o; - char *trunc = ""; + const char *trunc = ""; print_indent(2); if (DohIsString(Getattr(obj, k))) { o = Str(Getattr(obj, k)); From 092e2104c7ed49ec967742799cfa7bf7053c7cda Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 26 Nov 2012 20:31:54 +0000 Subject: [PATCH 0297/1160] More consistent use of DOH namespace git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13940 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/cffi.cxx | 4 ++-- Source/Modules/lua.cxx | 2 +- Source/Modules/perl5.cxx | 2 +- Source/Modules/python.cxx | 2 +- Source/Modules/s-exp.cxx | 2 +- Source/Swig/include.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx index ceb1bad67..dcc8ef93e 100644 --- a/Source/Modules/cffi.cxx +++ b/Source/Modules/cffi.cxx @@ -1051,10 +1051,10 @@ String *CFFI::convert_literal(String *literal, String *type, bool try_to_split) if (Len(num) >= 2 && s[0] == '0') { /* octal or hex */ if (s[1] == 'x'){ - DohReplace(num,"0","#",DOH_REPLACE_FIRST); + Replace(num,"0","#",DOH_REPLACE_FIRST); } else{ - DohReplace(num,"0","#o",DOH_REPLACE_FIRST); + Replace(num,"0","#o",DOH_REPLACE_FIRST); } } return num; diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 3d1530331..ef2fa96de 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -62,7 +62,7 @@ char cvsroot_lua_cxx[] = "$Id$"; void display_mapping(DOH *d) { if (d == 0 || !DohIsMapping(d)) return; - for (DohIterator it = DohFirst(d); it.item; it = DohNext(it)) { + for (Iterator it = First(d); it.item; it = Next(it)) { if (DohIsString(it.item)) Printf(stdout, " %s = %s\n", it.key, it.item); else if (DohIsMapping(it.item)) diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 1662f3b55..f786a7607 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -1669,7 +1669,7 @@ public: } /* Split the input text into lines */ - List *clist = DohSplitLines(temp); + List *clist = SplitLines(temp); Delete(temp); int initial = 0; String *s = 0; diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 43d306b09..2295f7801 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -1107,7 +1107,7 @@ public: } /* Split the input text into lines */ - List *clist = DohSplitLines(temp); + List *clist = SplitLines(temp); Delete(temp); int initial = 0; String *s = 0; diff --git a/Source/Modules/s-exp.cxx b/Source/Modules/s-exp.cxx index 3c50f3076..2c9a0cc99 100644 --- a/Source/Modules/s-exp.cxx +++ b/Source/Modules/s-exp.cxx @@ -87,7 +87,7 @@ public: Language::top(n); Printf(out, "\n"); Printf(out, ";;; Lisp parse tree produced by SWIG\n"); - print_circle_hash = DohNewHash(); + print_circle_hash = NewHash(); print_circle_count = 0; hanging_parens = 0; need_whitespace = 0; diff --git a/Source/Swig/include.c b/Source/Swig/include.c index 5d37dad7e..5796416a4 100644 --- a/Source/Swig/include.c +++ b/Source/Swig/include.c @@ -338,7 +338,7 @@ String *Swig_file_extension(const_String_or_char_ptr filename) { String *Swig_file_basename(const_String_or_char_ptr filename) { String *extension = Swig_file_extension(filename); - String *basename = DohNewStringWithSize(filename, Len(filename) - Len(extension)); + String *basename = NewStringWithSize(filename, Len(filename) - Len(extension)); Delete(extension); return basename; } From e60ae2d81dfc6eb68e082552deeab368818c3575 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Wed, 28 Nov 2012 20:22:56 +0000 Subject: [PATCH 0298/1160] octave: Simplified module loading. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13941 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 9 ++ Doc/Manual/Octave.html | 44 +------ Examples/octave/module_load/runme.m | 49 +------ Lib/octave/octruntime.swg | 192 ++++++++++++++++++---------- Source/Modules/octave.cxx | 6 +- 5 files changed, 141 insertions(+), 159 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 19912fde6..1675f878b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,15 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.9 (in progress) =========================== +2012-11-28: kwwette + [Octave] Simplified module loading: now just the syntax + $ example; + is accepted, which loads functions globally but constants and variables relative to the current scope. + This make module loading behaviour reliably consistent, and reduces problems when loading modules which + depend on other modules which may not have been previously loaded. + + *** POTENTIAL INCOMPATIBILITY *** + 2012-11-17: wsfulton [Tcl, Modula3] Add missing support for -outdir. diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index b8cf02a77..0340c2fd5 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -181,12 +181,7 @@ When Octave is asked to invoke example, it will try to find the ".m" or

    -An Octave module can either load its symbols into the global namespace, so that they can be accessed directly without having to type the module name. -Alternatively, an Octave module can be accessed through a local variable, without being loaded globally. -

    - -

    -To load an Octave module globally, simply type its name: +To load an Octave module, simply type its name:

    @@ -200,43 +195,6 @@ octave:5> cvar.Foo
     ans =  4
     
    -

    -To access an Octave module through a local variable, without loading it globally, simply assign the module name (e.g. "example") to the desired local variable: -

    - -
    -octave:1> example = example;
    -octave:2> example.gcd(6,9)
    -ans =  3
    -octave:3> example.cvar.Foo
    -ans =  3
    -
    - -

    -The variable may have the same name as the module, or a shorter one: -

    - -
    -octave:1> ex = example;
    -octave:2> ex.gcd(6,9)
    -ans =  3
    -octave:3> ex.cvar.Foo
    -ans =  3
    -
    - -

    -It is also possible to rename the global variables namespaces with an assignment, as in: -

    - -
    -octave:1> example;
    -octave:2> cvar.gcd(10,4)
    -ans =  2
    -octave:3> some_vars = cvar;
    -octave:4> some_vars.Foo
    -ans =  3
    -
    -

    Modules can also be loaded from within functions, even before being loaded in the base context. If the module is also used in the base context, however, it must first be loaded again: diff --git a/Examples/octave/module_load/runme.m b/Examples/octave/module_load/runme.m index 16b437ee8..0fda218cd 100644 --- a/Examples/octave/module_load/runme.m +++ b/Examples/octave/module_load/runme.m @@ -1,17 +1,7 @@ # file: runme_args.m -# test module loading with arguments -clear all - -# access module, no global load -example = example; -assert(example.cvar.ivar == example.ifunc()); -clear all -example = example; -assert(example.cvar.ivar == example.ifunc()); -clear all - -# load module globally +# load module +clear all; example; assert(cvar.ivar == ifunc); assert(exist("example","var")); @@ -21,27 +11,8 @@ assert(cvar.ivar == ifunc); assert(exist("example","var")); clear all -# access module in a function, no global load -function testme - example = example; - assert(example.cvar.ivar == example.ifunc()); -endfunction -testme -testme -example = example; -assert(example.cvar.ivar == example.ifunc()); -clear all -function testme - example = example; - assert(example.cvar.ivar == example.ifunc()); -endfunction -testme -testme -example = example; -assert(example.cvar.ivar == example.ifunc()); -clear all - # load module in a function globally before base context +clear all; function testme example; assert(cvar.ivar == ifunc); @@ -66,6 +37,7 @@ assert(exist("example","var")); clear all # load module in a function globally after base context +clear all; example; assert(cvar.ivar == ifunc); assert(exist("example","var")); @@ -95,17 +67,8 @@ if api_version < 37 exit endif -# access module with no cvar, no global load -example2 = example2; -assert(example2.ivar == example2.ifunc()); -assert(!isglobal("cvar")) -clear all -example2 = example2; -assert(example2.ivar == example2.ifunc()); -assert(!isglobal("cvar")) -clear all - -# load module with no cvar globally +# load module with no cvar +clear all; example2; assert(example2.ivar == ifunc); assert(exist("example2","var")); diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index 16ad3f7c9..66b6e265a 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -20,13 +20,74 @@ %insert(initbeforefunc) %{ -static void SWIG_init_user(octave_swig_type* module_ns); +static bool SWIG_init_user(octave_swig_type* module_ns); -SWIGINTERN void SWIG_Octave_InstallFunction(octave_function *octloadfcn, std::string name) { - octave_value_list args; - args.append(name); - args.append(octloadfcn->fcn_file_name()); - feval("autoload", args, 0); +SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) { + bool retn; + { +#if OCTAVE_API_VERSION_NUMBER < 38 + unwind_protect::begin_frame("SWIG_Octave_LoadModule"); + unwind_protect_int(error_state); + unwind_protect_int(warning_state); + unwind_protect_bool(discard_error_messages); + unwind_protect_bool(discard_warning_messages); +#else + unwind_protect frame; + frame.protect_var(error_state); + frame.protect_var(warning_state); + frame.protect_var(discard_error_messages); + frame.protect_var(discard_warning_messages); +#endif + error_state = 0; + warning_state = 0; + discard_error_messages = true; + discard_warning_messages = true; + feval(name, octave_value_list(), 0); + retn = (error_state == 0); +#if OCTAVE_API_VERSION_NUMBER < 38 + unwind_protect::run_frame("SWIG_Octave_LoadModule"); +#endif + } + if (!retn) { + error(SWIG_name_d ": could not load module `%s'", name.c_str()); + } + return retn; +} + +SWIGINTERN bool SWIG_Octave_InstallFunction(octave_function *octloadfcn, std::string name) { + bool retn; + { +#if OCTAVE_API_VERSION_NUMBER < 38 + unwind_protect::begin_frame("SWIG_Octave_InstallFunction"); + unwind_protect_int(error_state); + unwind_protect_int(warning_state); + unwind_protect_bool(discard_error_messages); + unwind_protect_bool(discard_warning_messages); +#else + unwind_protect frame; + frame.protect_var(error_state); + frame.protect_var(warning_state); + frame.protect_var(discard_error_messages); + frame.protect_var(discard_warning_messages); +#endif + error_state = 0; + warning_state = 0; + discard_error_messages = true; + discard_warning_messages = true; + octave_value_list args; + args.append(name); + args.append(octloadfcn->fcn_file_name()); + error_state = 0; + feval("autoload", args, 0); + retn = (error_state == 0); +#if OCTAVE_API_VERSION_NUMBER < 38 + unwind_protect::run_frame("SWIG_Octave_InstallFunction"); +#endif + } + if (!retn) { + error(SWIG_name_d ": could not load function `%s'", name.c_str()); + } + return retn; } static const char *const subclass_usage = "-*- texinfo -*- \n\ @@ -44,7 +105,7 @@ DEFUN_DLD( subclass, args, nargout, subclass_usage ) { octave_swig_ref *osr = static_cast < octave_swig_ref *>(args(j).internal_rep()); octave_swig_type *ost = osr->get_ptr(); if (!ost->is_owned()) { - error("cannot subclass object not constructed on octave side"); + error("subclass: cannot subclass object not constructed on octave side"); return octave_value_list(); } top->merge(*ost); @@ -52,13 +113,13 @@ DEFUN_DLD( subclass, args, nargout, subclass_usage ) { top->assign(args(j).fcn_handle_value()->fcn_name(), args(j)); } else if (args(j).is_string()) { if (j + 1 >= args.length()) { - error("member assignments must be of string,value form"); + error("subclass: member assignments must be of string,value form"); return octave_value_list(); } top->assign(args(j).string_value(), args(j + 1)); ++j; } else { - error("invalid arguments to subclass()"); + error("subclass: invalid arguments to subclass()"); return octave_value_list(); } } @@ -72,12 +133,12 @@ Return the underlying C/C++ type name of a SWIG-wrapped object.\n\ DEFUN_DLD( swig_type, args, nargout, swig_type_usage ) { if (args.length() != 1) { - error("swig_type() must be called with only a single object"); + error("swig_type: must be called with only a single object"); return octave_value_list(); } octave_swig_type *ost = Swig::swig_value_deref(args(0)); if (!ost) { - error("object is not a swig_ref"); + error("swig_type: object is not a swig_ref"); return octave_value_list(); } return octave_value(ost->swig_type_name()); @@ -91,7 +152,7 @@ otherwise return `'.\n\ DEFUN_DLD( swig_typequery, args, nargout, swig_typequery_usage ) { if (args.length() != 1 || !args(0).is_string()) { - error("swig_typequery() must be called with single string argument"); + error("swig_typequery: must be called with single string argument"); return octave_value_list(); } swig_module_info *module = SWIG_GetModule(0); @@ -108,14 +169,14 @@ Return the underlying C/C++ pointer of a SWIG-wrapped object.\n\ DEFUN_DLD( swig_this, args, nargout, swig_this_usage ) { if (args.length() != 1) { - error("swig_this() must be called with only a single object"); + error("swig_this: must be called with only a single object"); return octave_value_list(); } if (args(0).is_matrix_type() && args(0).rows() == 0 && args(0).columns() == 0) return octave_value(octave_uint64(0)); octave_swig_type *ost = Swig::swig_value_deref(args(0)); if (!ost) { - error("object is not a swig_ref"); + error("swig_this: object is not a swig_ref"); return octave_value_list(); } return octave_value(octave_uint64((unsigned long long) ost->swig_this())); @@ -124,42 +185,34 @@ DEFUN_DLD( swig_this, args, nargout, swig_this_usage ) { static const char *const SWIG_name_usage = "-*- texinfo -*- \n\ @deftypefn {Loadable Module} {} " SWIG_name_d "\n\ Loads the SWIG-generated module `" SWIG_name_d "'.\n\ -\n\ -To load the module into the global namespace:\n\ -@example\n\ -" SWIG_name_d ";\n\ -@end example\n\ -To access the module through a local variable, without loading it globally:\n\ -@example\n\ -" SWIG_name_d " = " SWIG_name_d ";\n\ -@end example\n\ -To access the module locally through a variable named, e.g. @var{modl}:\n\ -@example\n\ -@var{modl} = " SWIG_name_d ";\n\ -@end example\n\ @end deftypefn"; DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { static octave_swig_type* module_ns = 0; - octave_value_list retval; + + // workaround to prevent octave seg-faulting on exit: set Octave exit function + // octave_exit to _Exit, which exits immediately without trying to cleanup memory. + // definitely affects version 3.2.*, not sure about 3.3.*, seems to be fixed in + // version 3.4.* and above. can be turned off with macro definition. +#ifndef SWIG_OCTAVE_NO_SEGFAULT_HACK +#if 36 < OCTAVE_API_VERSION_NUMBER && OCTAVE_API_VERSION_NUMBER < 45 + octave_exit = ::_Exit; +#endif +#endif + + // check for no input and output args + if (args.length() != 0 || nargout != 0) { + print_usage(); + return octave_value_list(); + } // create module on first function call if (!module_ns) { - // workaround to prevent octave seg-faulting on exit: set Octave exit function - // octave_exit to _Exit, which exits immediately without trying to cleanup memory. - // definitely affects version 3.2.*, not sure about 3.3.*, seems to be - // fixed in version 3.4.* and above. can be turned off with macro def. -#ifndef SWIG_OCTAVE_NO_SEGFAULT_HACK -#if 36 < OCTAVE_API_VERSION_NUMBER && OCTAVE_API_VERSION_NUMBER < 45 - octave_exit = ::_Exit; -#endif -#endif - // workaround bug in octave where installing global variable of custom type and then // exiting without explicitly clearing the variable causes octave to segfault. -#if OCTAVE_API_VERSION_NUMBER >= 37 +#if OCTAVE_API_VERSION_NUMBER > 36 octave_value_list eval_args; eval_args.append("base"); eval_args.append("function __swig_atexit__; " @@ -182,10 +235,18 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { octave_function *me = octave_call_stack::current(); - SWIG_Octave_InstallFunction(me, "swig_type"); - SWIG_Octave_InstallFunction(me, "swig_typequery"); - SWIG_Octave_InstallFunction(me, "swig_this"); - SWIG_Octave_InstallFunction(me, "subclass"); + if (!SWIG_Octave_InstallFunction(me, "swig_type")) { + return octave_value_list(); + } + if (!SWIG_Octave_InstallFunction(me, "swig_typequery")) { + return octave_value_list(); + } + if (!SWIG_Octave_InstallFunction(me, "swig_this")) { + return octave_value_list(); + } + if (!SWIG_Octave_InstallFunction(me, "subclass")) { + return octave_value_list(); + } octave_swig_type* cvar_ns=0; if (std::string(SWIG_global_name) != ".") { @@ -219,7 +280,11 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { (new octave_swig_type(0,swig_types[j]))); } - SWIG_init_user(module_ns); + if (!SWIG_init_user(module_ns)) { + delete module_ns; + module_ns=0; + return octave_value_list(); + } SWIG_InstallOps(octave_swig_ref::static_type_id()); @@ -231,38 +296,25 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { } - // return module if asked for - if (args.length() == 0 && nargout == 1) { - retval = octave_value(module_ns->as_value()); - } + octave_function *me = octave_call_stack::current(); - // if call with not output arguments, load globally - else if (args.length() == 0 && nargout == 0) { - - octave_function *me = octave_call_stack::current(); - - octave_swig_type::swig_member_const_iterator mb; - for (mb = module_ns->swig_members_begin(); mb != module_ns->swig_members_end(); ++mb) { - if (mb->second.first && mb->second.first->method) { - SWIG_Octave_InstallFunction(me, mb->first); - } - else if (mb->second.second.is_defined()) { - SWIG_Octave_SetGlobalValue(mb->first, mb->second.second); - SWIG_Octave_LinkGlobalValue(mb->first); + octave_swig_type::swig_member_const_iterator mb; + for (mb = module_ns->swig_members_begin(); mb != module_ns->swig_members_end(); ++mb) { + if (mb->second.first && mb->second.first->method) { + if (!SWIG_Octave_InstallFunction(me, mb->first)) { + return octave_value_list(); } } - - SWIG_Octave_SetGlobalValue(SWIG_name_d, module_ns->as_value()); - SWIG_Octave_LinkGlobalValue(SWIG_name_d); - + else if (mb->second.second.is_defined()) { + SWIG_Octave_SetGlobalValue(mb->first, mb->second.second); + SWIG_Octave_LinkGlobalValue(mb->first); + } } - // otherwise print usage - else { - print_usage(); - } + SWIG_Octave_SetGlobalValue(SWIG_name_d, module_ns->as_value()); + SWIG_Octave_LinkGlobalValue(SWIG_name_d); - return retval; + return octave_value_list(); } diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 7d27c1095..5758e38c3 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -207,7 +207,7 @@ public: Printf(f_runtime, "\n"); Printf(s_global_tab, "\nstatic const struct swig_octave_member swig_globals[] = {\n"); - Printf(f_init, "static void SWIG_init_user(octave_swig_type* module_ns)\n{\n"); + Printf(f_init, "static bool SWIG_init_user(octave_swig_type* module_ns)\n{\n"); if (!CPlusPlus) Printf(f_header,"extern \"C\" {\n"); @@ -223,7 +223,7 @@ public: if (directorsEnabled()) Swig_insert_file("director.swg", f_runtime); - Printf(f_init, "}\n"); + Printf(f_init, "return true;\n}\n"); Printf(s_global_tab, "{0,0,0,0,0}\n};\n"); Printv(f_wrappers, s_global_tab, NIL); @@ -393,7 +393,7 @@ public: virtual int importDirective(Node *n) { String *modname = Getattr(n, "module"); if (modname) - Printf(f_init, "feval(\"%s\",octave_value_list(),1);\n", modname); + Printf(f_init, "if (!SWIG_Octave_LoadModule(\"%s\")) return false;\n", modname); return Language::importDirective(n); } From 18ef95083d159da9cc4f9df8af5e036b777e6e97 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Wed, 28 Nov 2012 20:23:17 +0000 Subject: [PATCH 0299/1160] octave: prevent writing to history file when running tests git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13942 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 1e90a01ca..6458512e9 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -331,7 +331,7 @@ python_clean: ################################################################## # Make sure these locate your Octave installation -OCTAVE = @OCTAVE@ -qf +OCTAVE = OCTAVE_HISTFILE=/dev/null @OCTAVE@ -qfH OCTAVE_CXX = $(DEFS) @OCTAVE_CPPFLAGS@ @OCTAVE_CXXFLAGS@ # Extra Octave specific dynamic linking options From 89052f3b0ac26c3cd5b787a0f2ad608f29b6b5ad Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 2 Dec 2012 13:36:13 +0000 Subject: [PATCH 0300/1160] Fix Strcmp - it didn't have consistent null pointer handling - revert to what it used to be - a lightweight wrapper around strcmp which means functions once again must not pass in null to it. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13943 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/CParse/parser.y | 2 +- Source/DOH/string.c | 6 +----- Source/Modules/allegrocl.cxx | 2 +- Source/Modules/cffi.cxx | 2 +- Source/Modules/d.cxx | 12 ++++++++---- Source/Modules/go.cxx | 4 ++-- Source/Modules/php.cxx | 3 ++- Source/Modules/r.cxx | 4 ++-- 8 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 03fc329d8..5c84c6e69 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3138,7 +3138,7 @@ c_declaration : c_decl { appendChild($$,n); while (n) { SwigType *decl = Getattr(n,"decl"); - if (SwigType_isfunction(decl) && Strcmp(Getattr(n, "storage"), "typedef") != 0) { + if (SwigType_isfunction(decl) && !Equal(Getattr(n, "storage"), "typedef")) { Setattr(n,"storage","externc"); } n = nextSibling(n); diff --git a/Source/DOH/string.c b/Source/DOH/string.c index e94a2bdb2..d34301691 100644 --- a/Source/DOH/string.c +++ b/Source/DOH/string.c @@ -1153,11 +1153,7 @@ DOHString *DohNewStringf(const DOHString_or_char *fmt, ...) { int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2) { const char *c1 = Char(s1); const char *c2 = Char(s2); - if (c1 && c2) { - return strcmp(c1, c2); - } else { - return c1 < c2; - } + return strcmp(c1, c2); } int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n) { diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index 95022752f..1e0c6c98b 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -1225,7 +1225,7 @@ void emit_full_class(Node *n) { // hack. why would decl have a value of "variableHandler" and now "0"? String *childDecl = Getattr(c, "decl"); // Printf(stderr,"childDecl = '%s' (%s)\n", childDecl, Getattr(c,"view")); - if (!Strcmp(childDecl, "0")) + if (!childDecl || !Strcmp(childDecl, "0")) childDecl = NewString(""); SwigType *childType; diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx index dcc8ef93e..017b959a3 100644 --- a/Source/Modules/cffi.cxx +++ b/Source/Modules/cffi.cxx @@ -835,7 +835,7 @@ void CFFI::emit_struct_union(Node *n, bool un = false) { String *typespec = tm ? NewString(tm) : NewString(""); String *slot_name = lispify_name(c, Getattr(c, "sym:name"), "'slotname"); - if (Strcmp(slot_name, "t") == 0 || Strcmp(slot_name, "T") == 0) + if (slot_name && (Strcmp(slot_name, "t") == 0 || Strcmp(slot_name, "T") == 0)) slot_name = NewStringf("t_var"); Printf(f_cl, "\n\t(%s %s)", slot_name, typespec); diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 1ea74eb6b..b8e30d50c 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -4418,10 +4418,14 @@ private: // so we can progress up the inheritance hierachy even if there have been // new overloads introduced after the topmost class. Node *base_function = NULL; - for (Node *tmp = firstChild(base_class); tmp; tmp = nextSibling(tmp)) { - if (Strcmp(Getattr(tmp, "sym:name"), Getattr(n, "sym:name")) == 0) { - base_function = tmp; - break; + String *symname = Getattr(n, "sym:name"); + if (symname) { + for (Node *tmp = firstChild(base_class); tmp; tmp = nextSibling(tmp)) { + String *child_symname = Getattr(tmp, "sym:name"); + if (child_symname && (Strcmp(child_symname, symname) == 0)) { + base_function = tmp; + break; + } } } diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 86171d28b..a16f710fd 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -1990,7 +1990,7 @@ private: continue; } String *storage = Getattr(ni, "storage"); - if (Strcmp(storage, "typedef") == 0 || Strcmp(storage, "friend") == 0) { + if (storage && (Strcmp(storage, "typedef") == 0 || Strcmp(storage, "friend") == 0)) { continue; } @@ -4792,7 +4792,7 @@ private: return Copy(ret); } - if (Strcmp(Getattr(n, "type"), "enum ") == 0) { + if (Equal(Getattr(n, "type"), "enum ")) { return NewString("int"); } diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 149b3cd83..01622f4ce 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1577,7 +1577,8 @@ public: while (i.item) { Node *j = firstChild(i.item); while (j) { - if (Strcmp(Getattr(j, "name"), Getattr(n, "name")) != 0) { + String *jname = Getattr(j, "name"); + if (!jname || Strcmp(jname, Getattr(n, "name")) != 0) { j = nextSibling(j); continue; } diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 078b2576c..6258e327d 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -2351,7 +2351,7 @@ int R::classDeclaration(Node *n) { elName = Getattr(c, "name"); String *elKind = Getattr(c, "kind"); - if (Strcmp(elKind, "variable") != 0) { + if (!Equal(elKind, "variable")) { c = nextSibling(c); continue; } @@ -2453,7 +2453,7 @@ int R::generateCopyRoutines(Node *n) { continue; } String *elKind = Getattr(c, "kind"); - if (Strcmp(elKind, "variable") != 0) { + if (!Equal(elKind, "variable")) { continue; } From 7ca04976477a35af8138d471244edfcb55e3ae08 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 2 Dec 2012 13:36:40 +0000 Subject: [PATCH 0301/1160] CFFI - fix junk output when wrapping single character constants git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13944 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 ++- Source/Modules/cffi.cxx | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 1675f878b..8b5ed3a6a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -12,7 +12,8 @@ Version 2.0.9 (in progress) This make module loading behaviour reliably consistent, and reduces problems when loading modules which depend on other modules which may not have been previously loaded. - *** POTENTIAL INCOMPATIBILITY *** +2012-11-27: wsfulton + [cffi] Fix junk output when wrapping single character literal constants. 2012-11-17: wsfulton [Tcl, Modula3] Add missing support for -outdir. diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx index 017b959a3..c2c79b007 100644 --- a/Source/Modules/cffi.cxx +++ b/Source/Modules/cffi.cxx @@ -1021,9 +1021,8 @@ String *CFFI::convert_literal(String *literal, String *type, bool try_to_split) return num; } else if (SwigType_type(type) == T_CHAR) { /* Use CL syntax for character literals */ - String* result = NewStringf("#\\%c", s[2]); + String* result = NewStringf("#\\%c", s[0]); Delete(num); - // Printf(stderr, "%s %c %d", s, s[2], s); return result; } else if (SwigType_type(type) == T_STRING) { /* Use CL syntax for string literals */ From 6cd247d6533fa4b994f44ef25e30fb2d3c105e53 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 2 Dec 2012 13:37:10 +0000 Subject: [PATCH 0302/1160] Correct prefix handling - bug introduced in rev 13886 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13945 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/guile.cxx | 2 +- Source/Modules/mzscheme.cxx | 3 +-- Source/Modules/ocaml.cxx | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index c7e8fe7e4..0777b316f 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -280,7 +280,7 @@ public: // Make sure `prefix' ends in an underscore if (prefix) { const char *px = Char(prefix); - if (px[Len(prefix)] != '_') + if (px[Len(prefix) - 1] != '_') Printf(prefix, "_"); } diff --git a/Source/Modules/mzscheme.cxx b/Source/Modules/mzscheme.cxx index c2abd7ec4..e2f44deef 100644 --- a/Source/Modules/mzscheme.cxx +++ b/Source/Modules/mzscheme.cxx @@ -101,10 +101,9 @@ public: } // If a prefix has been specified make sure it ends in a '_' (not actually used!) - if (prefix) { const char *px = Char(prefix); - if (px[Len(prefix)] != '_') + if (px[Len(prefix) - 1] != '_') Printf(prefix, "_"); } else prefix = NewString("swig_"); diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index 9fc5e9c71..beac03237 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -130,10 +130,9 @@ public: } // If a prefix has been specified make sure it ends in a '_' (not actually used!) - if (prefix) { const char *px = Char(prefix); - if (px[Len(prefix)] != '_') + if (px[Len(prefix) - 1] != '_') Printf(prefix, "_"); } else prefix = NewString("swig_"); From 00d969d7fd20220518e1e4b6c893f8ba87af4191 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 2 Dec 2012 14:11:19 +0000 Subject: [PATCH 0303/1160] Makefile tweaks for Coverity builds git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13946 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Makefile.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index eb3ec02b2..d3c4b8c47 100644 --- a/Makefile.in +++ b/Makefile.in @@ -532,9 +532,10 @@ $(srcdir)/configure: $(srcdir)/configure.in EMAIL=wsf@fultondesigns.co.uk PASSWORD= coverity: + test -n "$(PASSWORD)" || (echo "PASSWORD not set" && false) $(MAKE) clean-source rm -rf cov-int - cov-build --dir cov-int $(MAKE) + cov-build --dir cov-int $(MAKE) source tar czvf swig-coverity.tgz cov-int curl --form file=@swig-coverity.tgz --form project=swig --form password=$(PASSWORD) --form email=$(EMAIL) http://scan5.coverity.com/cgi-bin/upload.py From 8b24933842a85aeccfc9775a5eca307875c36594 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 2 Dec 2012 14:33:41 +0000 Subject: [PATCH 0304/1160] Fix nested classes symbol table problem due to lack of string copy - due to changes in rev 13938 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13947 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/CParse/parser.y | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 5c84c6e69..0d7c65f85 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -4633,7 +4633,8 @@ cpp_nested : storage_class cpptype idcolon inherit LBRACE { $$ = 0; if (cplus_mode == CPLUS_PUBLIC) { if (cparse_cplusplus) { - $$ = nested_forward_declaration($1, $2, $3, $3, $7); + String *name = Copy($3); + $$ = nested_forward_declaration($1, $2, $3, name, $7); } else if ($7) { nested_new_struct($2, $6, $7); } @@ -4659,7 +4660,7 @@ cpp_nested : storage_class cpptype idcolon inherit LBRACE { $$ = 0; if (cplus_mode == CPLUS_PUBLIC) { if (cparse_cplusplus) { - String *name = $6 ? Getattr($6, "name") : 0; + String *name = $6 ? Copy(Getattr($6, "name")) : 0; $$ = nested_forward_declaration($1, $2, 0, name, $6); } else { if ($6) { From f38147c154e84dea7e61cf581fdd51a76d24f1a4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 2 Dec 2012 18:11:56 +0000 Subject: [PATCH 0305/1160] Remove some pointless code creating implicit constructors git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13948 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/lang.cxx | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index ad2a0d6b8..8e5a91dbe 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2172,8 +2172,7 @@ static void addCopyConstructor(Node *n) { String *name = Swig_scopename_last(cname); String *cc = NewStringf("r.q(const).%s", type); String *decl = NewStringf("f(%s).", cc); - String *csymname = Getattr(n, "sym:name"); - String *oldname = csymname; + String *oldname = Getattr(n, "sym:name"); if (Getattr(n, "allocate:has_constructor")) { // to work properly with '%rename Class', we must look @@ -2196,9 +2195,6 @@ static void addCopyConstructor(Node *n) { String *symname = Swig_name_make(cn, cname, name, decl, oldname); if (Strcmp(symname, "$ignore") != 0) { - if (!symname) { - symname = Copy(csymname); - } Parm *p = NewParm(cc, "other", n); Setattr(cn, "name", name); @@ -2242,14 +2238,9 @@ static void addDefaultConstructor(Node *n) { String *cname = Getattr(n, "name"); String *name = Swig_scopename_last(cname); String *decl = NewString("f()."); - String *csymname = Getattr(n, "sym:name"); - String *oldname = csymname; + String *oldname = Getattr(n, "sym:name"); String *symname = Swig_name_make(cn, cname, name, decl, oldname); if (Strcmp(symname, "$ignore") != 0) { - if (!symname) { - symname = Copy(csymname); - } - Setattr(cn, "name", name); Setattr(cn, "sym:name", symname); SetFlag(cn, "feature:new"); From 8be65ec8e7d571a67715129298cfb9871232fd6f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 7 Dec 2012 07:38:24 +0000 Subject: [PATCH 0306/1160] Add in va_list varargs workaround suggested by Antoine Mathys git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13949 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Varargs.html | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/Doc/Manual/Varargs.html b/Doc/Manual/Varargs.html index c27db603d..13abc8cee 100644 --- a/Doc/Manual/Varargs.html +++ b/Doc/Manual/Varargs.html @@ -839,13 +839,13 @@ of type va_list. For example:

    -int vfprintf(FILE *f, const char *fmt, va_list ap);
    +int vprintf(const char *fmt, va_list ap);
     

    -As far as we know, there is no obvious way to wrap these functions -with SWIG. This is because there is no documented way to assemble the +As far as we know, there is no obvious way to wrap these functions with +SWIG. This is because there is no documented way to assemble the proper va_list structure (there are no C library functions to do it and the contents of va_list are opaque). Not only that, the contents of a va_list structure are closely tied to the underlying @@ -853,6 +853,36 @@ call-stack. It's not clear that exporting a va_list would have any use or that it would work at all.

    +

    +A workaround can be implemented by writing a simple varargs C wrapper and then using the techniques +discussed earlier in this chapter for varargs. Below is a simple wrapper for vprintf renamed so that +it can still be called as vprintf from your target language. The %varargs +used in the example restricts the function to taking one string argument. +

    + +
    +
    +%{
    +int vprintf(const char *fmt, va_list ap);
    +%}
    +
    +%varargs(const char *) my_vprintf;
    +%rename(vprintf) my_vprintf;
    +
    +%inline %{
    +int my_vprintf(const char *fmt, ...) {
    +  va_list ap;
    +  int result;
    +
    +  va_start(ap, fmt);
    +  result = vprintf(fmt, ap);
    +  va_end(ap);
    +  return result;
    +}
    +%}
    +
    +
    +

    13.8 C++ Issues

    From ba575159f6ae78a5353bd1408fed843ea8089e98 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Dec 2012 10:37:04 +0000 Subject: [PATCH 0307/1160] Add runtime test for %implicitconv git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13950 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/implicittest.i | 3 +- .../test-suite/python/implicittest_runme.py | 73 +++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/python/implicittest_runme.py diff --git a/Examples/test-suite/implicittest.i b/Examples/test-suite/implicittest.i index 91205aafa..e07adc5cc 100644 --- a/Examples/test-suite/implicittest.i +++ b/Examples/test-suite/implicittest.i @@ -18,7 +18,6 @@ explicit A(char *s) { ii = 4; } int get() const { return ii; } - }; int get(const A& a) { return a.ii; } @@ -33,7 +32,7 @@ explicit A_T(char *s) { ii = 4; } int get() const { return ii; } - + static int sget(const A_T& a) { return a.ii; } }; } diff --git a/Examples/test-suite/python/implicittest_runme.py b/Examples/test-suite/python/implicittest_runme.py new file mode 100644 index 000000000..4200543c4 --- /dev/null +++ b/Examples/test-suite/python/implicittest_runme.py @@ -0,0 +1,73 @@ +from implicittest import * + +def check(a, b): + if a != b: + raise RuntimeError(str(a) + " does not equal " + str(b)) + +#### Class #### + +# No implicit conversion +check(1, A(1).get()) +check(2, A(1.0).get()) +check(3, A(B()).get()) +check(4, A("hello").get()) + +check(1, get(1)) +check(2, get(1.0)) +check(3, get(B())) + +# Explicit constructor: +try: + check(4, get("hello")) + raise RuntimeError +except TypeError: + pass + +#### Template Class #### + +# No implicit conversion +check(1, A_int(1).get()) +check(2, A_int(1.0).get()) +check(3, A_int(B()).get()) +check(4, A_int("hello").get()) + +check(1, A_int.sget(1)) +check(2, A_int.sget(1.0)) +check(3, A_int.sget(B())) + +# explicit constructor: +try: + check(4, A_int.sget("hello")) + raise RuntimeError +except TypeError: + pass + +#### Global variable assignment #### + +cvar.foo = Foo(1); check(cvar.foo.ii, 1) +cvar.foo = 1; check(cvar.foo.ii, 1) +cvar.foo = 1.0; check(cvar.foo.ii, 2) +cvar.foo = Foo("hello"); check(cvar.foo.ii, 3) + +# explicit constructor: +try: + cvar.foo = "hello" + raise RuntimeError +except TypeError: + pass + +#### Member variable assignment #### +# Note: also needs naturalvar + +b = Bar(); check(b.f.ii, 0) +b.f = Foo("hello"); check(b.f.ii, 3) +b.f = 1; check(b.f.ii, 1) +b.f = 1.0; check(b.f.ii, 2) + +# explicit constructor: +try: + b.f = "hello" + raise RuntimeError +except TypeError: + pass + From 73757314318cbade1c38d06e75efd36d0357c500 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 9 Dec 2012 17:47:12 +0000 Subject: [PATCH 0308/1160] Perl - Fix C++ comment in C wrappers. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13951 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Lib/perl5/perlinit.swg | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 8b5ed3a6a..b0aee7e75 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.9 (in progress) =========================== +2012-12-08: wsfulton + [Perl] Fix bug #3571361 - C++ comment in C wrappers. + 2012-11-28: kwwette [Octave] Simplified module loading: now just the syntax $ example; diff --git a/Lib/perl5/perlinit.swg b/Lib/perl5/perlinit.swg index af9a35a98..d9ffa9bf8 100644 --- a/Lib/perl5/perlinit.swg +++ b/Lib/perl5/perlinit.swg @@ -33,7 +33,7 @@ XS(SWIG_init) { /* Install commands */ for (i = 0; swig_commands[i].name; i++) { - // Casts only needed for Perl < 5.10. + /* Casts only needed for Perl < 5.10. */ #ifdef __cplusplus newXS(const_cast(swig_commands[i].name), swig_commands[i].wrapper, const_cast(__FILE__)); #else From 5e507b82f1c32ffce40882a930e3894cceb7a4ab Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 9 Dec 2012 20:49:28 +0000 Subject: [PATCH 0309/1160] Apply patch #3571029 which adds missing director support for const unsigned long long &. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13952 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Lib/csharp/csharp.swg | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index b0aee7e75..72398e2e9 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -8,6 +8,9 @@ Version 2.0.9 (in progress) 2012-12-08: wsfulton [Perl] Fix bug #3571361 - C++ comment in C wrappers. +2012-12-07: wsfulton + [C#] Apply patch #3571029 which adds missing director support for const unsigned long long &. + 2012-11-28: kwwette [Octave] Simplified module loading: now just the syntax $ example; diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index 107695da1..c0b896e16 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -291,6 +291,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { const long &, const unsigned long &, const long long &, + const unsigned long long &, const float &, const double & %{ static $*1_ltype temp; @@ -308,6 +309,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %typemap(directorin) const long & "$input = $1;" %typemap(directorin) const unsigned long & "$input = $1;" %typemap(directorin) const long long & "$input = $1;" +%typemap(directorin) const unsigned long long & "$input = $1;" %typemap(directorin) const float & "$input = $1;" %typemap(directorin) const double & "$input = $1;" @@ -321,6 +323,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { const long & ($*1_ltype temp), const unsigned long & ($*1_ltype temp), const long long & ($*1_ltype temp), + const unsigned long long & ($*1_ltype temp), const float & ($*1_ltype temp), const double & ($*1_ltype temp) "$iminput" @@ -335,6 +338,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { const long & ($*1_ltype temp), const unsigned long & ($*1_ltype temp), const long long & ($*1_ltype temp), + const unsigned long long & ($*1_ltype temp), const float & ($*1_ltype temp), const double & ($*1_ltype temp) "$cscall" From 16481c999e4c02c65e74f0207b0760899bc4b74a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 9 Dec 2012 20:49:52 +0000 Subject: [PATCH 0310/1160] Bug #3563647 - PyInt_FromSize_t unavailable prior to Python 2.5 for unsigned int types git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13953 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Lib/python/pyhead.swg | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 72398e2e9..0775e31e3 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.9 (in progress) =========================== +2012-12-08: wsfulton + [Python] Bug #3563647 - PyInt_FromSize_t unavailable prior to Python 2.5 for unsigned int types. + 2012-12-08: wsfulton [Perl] Fix bug #3571361 - C++ comment in C wrappers. diff --git a/Lib/python/pyhead.swg b/Lib/python/pyhead.swg index c333e9d89..cedd017a7 100644 --- a/Lib/python/pyhead.swg +++ b/Lib/python/pyhead.swg @@ -175,6 +175,10 @@ static long PyNumber_AsSsize_t (PyObject *x, void *SWIGUNUSEDPARM(exc)) } #endif +#if PY_VERSION_HEX < 0x02050000 +#define PyInt_FromSize_t(x) PyInt_FromLong((long)x) +#endif + #if PY_VERSION_HEX < 0x02040000 #define Py_VISIT(op) \ do { \ From 1ac275790de43d59ca45b3e07d72020cad83aefa Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 10 Dec 2012 19:45:04 +0000 Subject: [PATCH 0311/1160] Clarify pythonprepend and pythonappend features when used on overloaded methods/constructors git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13954 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index bd48a37f2..762abebba 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -3386,7 +3386,39 @@ public:
    +

    +Note that when the underlying C++ method is overloaded, there is only one proxy Python method +for multiple C++ methods. In this case, only one of parsed methods is examined +for the feature. You are better off specifying the feature without the argument list to ensure it will get used, +as it will then get attached to all the overloaded C++ methods. For example: +

    +
    +
    +%module example
    +
    +// Add python code to bar()
    +
    +%pythonprepend Foo::bar %{
    +   #do something before C++ call
    +%}
    +
    +%pythonappend Foo::bar %{
    +   #do something after C++ call
    +%}
    +
    +
    +class Foo {
    +public:
    +    int bar(int x);
    +    int bar();
    +}
    +
    +
    + +

    +The same applies for overloaded constructors. +

    34.6.3 Class extension with %extend

    From 4c1b566f621f854274892af1def2f3589d2eb934 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 11 Dec 2012 18:42:58 +0000 Subject: [PATCH 0312/1160] Fix fully qualified package paths for Python 3 even if a module is in the same package git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13955 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Source/Modules/python.cxx | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 0775e31e3..448cf2ef0 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.9 (in progress) =========================== +2012-12-11: wsfulton + [Python] Apply patch #3590522 - fully qualified package paths for Python 3 even if a module is in the + same package. + 2012-12-08: wsfulton [Python] Bug #3563647 - PyInt_FromSize_t unavailable prior to Python 2.5 for unsigned int types. diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 2295f7801..bd897636f 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -1049,7 +1049,7 @@ public: // of this module.) Node *options = Getattr(mod, "options"); String *pkg = options ? Getattr(options, "package") : 0; - if (pkg && (!package || Strcmp(pkg, package) != 0)) { + if (pkg) { Printf(import, "%s.", pkg); } // finally, output the name of the imported module @@ -1057,7 +1057,7 @@ public: if (!options || (!Getattr(options, "noshadow") && !Getattr(options, "noproxy"))) { Printf(import, "_%s\n", modname); if (!GetFlagAttr(f_shadow_imports, import)) { - if (pkg && (!package || Strcmp(pkg, package) != 0)) { + if (pkg) { Printf(builtin ? f_shadow_builtin_imports : f_shadow, "import %s.%s\n", pkg, modname); } else { Printf(builtin ? f_shadow_builtin_imports : f_shadow, "import %s\n", modname); @@ -3168,7 +3168,7 @@ public: // check if the module has a package option Node *options = Getattr(mod, "options"); String *pkg = options ? Getattr(options, "package") : 0; - if (pkg && (!package || Strcmp(pkg, package) != 0)) { + if (pkg) { Printf(importname, "%s.", pkg); } Printf(importname, "%s.", modname); From f26c7b0ac2baf66f105cea6c797a4deaa524866e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 11 Dec 2012 18:43:56 +0000 Subject: [PATCH 0313/1160] Document null attribute for out typemap for C# git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13956 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/CSharp.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index b511dc126..a5394eb37 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -190,6 +190,21 @@ csattributes C# attributes for attaching to proxy classes/enums
  • +
  • +

    Additional typemap attributes:

    + +

    +The "null" attribute in the "out" typemap can be specified to provide a value for $null to expand into for wrapped functions that return non-void. Normally the default value of 0 is used. +For example this is needed if you change the return type to void: +

    + +
    +%typemap(ctype) Status "void"
    +%typemap(out, null="") Status { ... }
    +
    + +
  • +
  • Feature equivalent names:

    
    From 413a485ac1990534ac740e05f32e51e15dbc7685 Mon Sep 17 00:00:00 2001
    From: Joseph Wang 
    Date: Wed, 12 Dec 2012 12:41:07 +0000
    Subject: [PATCH 0314/1160] add finalizer for class fix.  It was missing from
     earlier additions
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13957 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Source/Modules/r.cxx | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx
    index 6258e327d..4724ca3a7 100644
    --- a/Source/Modules/r.cxx
    +++ b/Source/Modules/r.cxx
    @@ -2115,7 +2115,7 @@ int R::functionWrapper(Node *n) {
     	{ 
     	  String *finalizer = NewString(iname);
     	  Replace(finalizer, "new_", "", DOH_REPLACE_FIRST);
    -	  Printf(sfun->code, "reg.finalizer(ans, delete_%s)\n", finalizer);
    +	  Printf(sfun->code, "reg.finalizer(ans@ref, delete_%s)\n", finalizer);
     	}                                                                      
           Printf(sfun->code, "ans\n");
         }
    
    From 600b598f67e86c98e95285dba813e29f0566a127 Mon Sep 17 00:00:00 2001
    From: Joseph Wang 
    Date: Wed, 12 Dec 2012 12:42:42 +0000
    Subject: [PATCH 0315/1160] fix current changes
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13958 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current | 3 +++
     1 file changed, 3 insertions(+)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index 448cf2ef0..b1107dada 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
     Version 2.0.9 (in progress)
     ===========================
     
    +2012-12-12: drjoe
    +	    [R] add fix to finalizer that was missed earlier
    +
     2012-12-11: wsfulton
                 [Python] Apply patch #3590522 - fully qualified package paths for Python 3 even if a module is in the
                 same package.
    
    From d994d4702855cc3c19a3ed0beafbb7a79d8a34cc Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Thu, 13 Dec 2012 22:37:09 +0000
    Subject: [PATCH 0316/1160] Check for yodl >= 2.02. 1.31.18 is known not to
     work and 2.01.00 to 2.01.03 gave an error message
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13959 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     configure.in | 15 +++++++++++++--
     1 file changed, 13 insertions(+), 2 deletions(-)
    
    diff --git a/configure.in b/configure.in
    index ef7c2d0b7..1c31b74a0 100644
    --- a/configure.in
    +++ b/configure.in
    @@ -118,7 +118,7 @@ AC_SUBST(ENABLE_CCACHE)
     
     echo ""
     echo "Checking packages required for SWIG developers."
    -echo "Note : None of the following packages are required for users to compile and install SWIG"
    +echo "Note : None of the following packages are required for users to compile and install SWIG from the distributed tarball"
     echo ""
     
     AC_PROG_YACC
    @@ -128,11 +128,22 @@ AC_SUBST(AR)
     AC_CHECK_PROGS(YODL2MAN, yodl2man)
     AC_CHECK_PROGS(YODL2HTML, yodl2html)
     
    +if test -n "$YODL2MAN"; then
    +  AC_MSG_CHECKING([yodl2man version >= 2.02])
    +  yodl_version=`$YODL2MAN --version 2>&1 | grep 'yodl version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.*[0-9]*\).*/\1/g'`
    +  AX_COMPARE_VERSION([$yodl_version],[ge],[2.02], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no - $yodl_version found])])
    +fi
    +
    +if test -n "$YODL2HTML"; then
    +  AC_MSG_CHECKING([yodl2html version >= 2.02])
    +  yodl_version=`$YODL2HTML --version 2>&1 | grep 'yodl version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`
    +  AX_COMPARE_VERSION([$yodl_version],[ge],[2.02], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no - $yodl_version found])])
    +fi
     
     echo ""
     echo "Checking for installed target languages and other information in order to compile and run"
     echo "the examples and test-suite invoked by 'make check'."
    -echo "Note : None of the following packages are required for users to compile and install SWIG"
    +echo "Note : None of the following packages are required for users to compile and install SWIG from the distributed tarball"
     echo ""
     
     dnl Some test cases require Boost
    
    From 4714b9b897cdc70671edb3249d68180bbbf3d3f9 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Thu, 13 Dec 2012 23:39:25 +0000
    Subject: [PATCH 0317/1160] Fix bad exit running 'swig -go -help'
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13960 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Source/Modules/go.cxx | 4 +++-
     1 file changed, 3 insertions(+), 1 deletion(-)
    
    diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx
    index a16f710fd..9784ba125 100644
    --- a/Source/Modules/go.cxx
    +++ b/Source/Modules/go.cxx
    @@ -129,6 +129,7 @@ private:
       virtual void main(int argc, char *argv[]) {
     
         SWIG_library_directory("go");
    +    bool display_help = false;
     
         // Process command line options.
         for (int i = 1; i < argc; i++) {
    @@ -190,6 +191,7 @@ private:
     	    Swig_arg_error();
     	  }
     	} else if (strcmp(argv[i], "-help") == 0) {
    +	  display_help = true;
     	  Printf(stdout, "%s\n", usage);
     	}
           }
    @@ -215,7 +217,7 @@ private:
         // This test may be removed in the future, when we can assume that
         // everybody has upgraded to Go 1.1.  The code below is prepared
         // for this test to simply be taken out.
    -    if (intgo_type_size == 0) {
    +    if (intgo_type_size == 0 && !display_help) {
           Printf(stderr, "SWIG -go: -intgosize option required but not specified\n");
           SWIG_exit(EXIT_FAILURE);
         }
    
    From 2939f181f138671d2a3ff60b054e7e4bd81820e4 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Fri, 14 Dec 2012 07:12:35 +0000
    Subject: [PATCH 0318/1160] Add Android install options for optional storage to
     SD Card
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13961 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Examples/android/class/Makefile  | 3 ++-
     Examples/android/extend/Makefile | 3 ++-
     Examples/android/simple/Makefile | 3 ++-
     3 files changed, 6 insertions(+), 3 deletions(-)
    
    diff --git a/Examples/android/class/Makefile b/Examples/android/class/Makefile
    index 7de95f559..2a3f0ec2d 100644
    --- a/Examples/android/class/Makefile
    +++ b/Examples/android/class/Makefile
    @@ -7,6 +7,7 @@ PACKAGENAME= org.swig.classexample
     SWIGOPT    = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/classexample 
     PROJECTNAME= SwigClass
     TARGETID  = 1
    +#INSTALLOPTIONS = -s # To install on SD Card
     
     all::	android
     
    @@ -18,7 +19,7 @@ android::
     
     install::
     	-adb uninstall $(PACKAGENAME)
    -	adb install bin/$(PROJECTNAME)-debug.apk
    +	adb install $(INSTALLOPTIONS) bin/$(PROJECTNAME)-debug.apk
     
     clean::
     	ant clean
    diff --git a/Examples/android/extend/Makefile b/Examples/android/extend/Makefile
    index 98a0372dd..e8c1b5e16 100644
    --- a/Examples/android/extend/Makefile
    +++ b/Examples/android/extend/Makefile
    @@ -7,6 +7,7 @@ PACKAGENAME= org.swig.extendexample
     SWIGOPT    = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/extendexample 
     PROJECTNAME= SwigExtend
     TARGETID  = 1
    +#INSTALLOPTIONS = -s # To install on SD Card
     
     all::	android
     
    @@ -18,7 +19,7 @@ android::
     
     install::
     	-adb uninstall $(PACKAGENAME)
    -	adb install bin/$(PROJECTNAME)-debug.apk
    +	adb install $(INSTALLOPTIONS) bin/$(PROJECTNAME)-debug.apk
     
     clean::
     	ant clean
    diff --git a/Examples/android/simple/Makefile b/Examples/android/simple/Makefile
    index 1e95de6e3..9aeb0c80d 100644
    --- a/Examples/android/simple/Makefile
    +++ b/Examples/android/simple/Makefile
    @@ -7,6 +7,7 @@ PACKAGENAME= org.swig.simple
     SWIGOPT    = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/simple
     PROJECTNAME= SwigSimple
     TARGETID  = 1
    +#INSTALLOPTIONS = -s # To install on SD Card
     
     all::	android
     
    @@ -18,7 +19,7 @@ android::
     
     install::
     	-adb uninstall $(PACKAGENAME)
    -	adb install bin/$(PROJECTNAME)-debug.apk
    +	adb install $(INSTALLOPTIONS) bin/$(PROJECTNAME)-debug.apk
     
     clean::
     	ant clean
    
    From 1ab67f5bed7e10f4f67dda4d2d161e3e881bbbce Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Fri, 14 Dec 2012 07:38:44 +0000
    Subject: [PATCH 0319/1160] Fix CFFI incorrect constant names
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13962 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current         |  4 ++++
     Source/Modules/cffi.cxx | 12 ++++++++----
     2 files changed, 12 insertions(+), 4 deletions(-)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index b1107dada..a1e1e1a62 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.9 (in progress)
     ===========================
     
    +
    +2012-12-13: wsfulton
    +            [CFFI] Fix #3529690 - Fix incorrect constant names.
    +
     2012-12-12: drjoe
     	    [R] add fix to finalizer that was missed earlier
     
    diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx
    index c2c79b007..d3f0391d0 100644
    --- a/Source/Modules/cffi.cxx
    +++ b/Source/Modules/cffi.cxx
    @@ -1031,10 +1031,14 @@ String *CFFI::convert_literal(String *literal, String *type, bool try_to_split)
         return result;
       } else if (SwigType_type(type) == T_INT || SwigType_type(type) == T_UINT) {
         // Printf(stderr, "Is a T_INT or T_UINT %s, before replaceall\n", s);
    -    Replaceall(num, "u", "");
    -    Replaceall(num, "U", "");
    -    Replaceall(num, "l", "");
    -    Replaceall(num, "L", "");
    +    const char *num_start = Char(num);
    +    bool is_literal = isdigit(*num_start) || (*num_start == '.') || (*num_start == '+') || (*num_start == '-');
    +    if (is_literal) {
    +      Replaceall(num, "u", "");
    +      Replaceall(num, "U", "");
    +      Replaceall(num, "l", "");
    +      Replaceall(num, "L", "");
    +    }
     
         int i, j;
         if (sscanf(s, "%d >> %d", &i, &j) == 2) {
    
    From 04b60a150865fa10b6ebabd60882c7b56681ce7e Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Fri, 14 Dec 2012 08:00:22 +0000
    Subject: [PATCH 0320/1160] CFFI - Fix some string constants are incorrect
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13963 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current                         | 3 +++
     Examples/test-suite/preproc_constants.i | 1 +
     Source/Modules/cffi.cxx                 | 8 +++++++-
     3 files changed, 11 insertions(+), 1 deletion(-)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index a1e1e1a62..e49b61a78 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -6,6 +6,9 @@ Version 2.0.9 (in progress)
     ===========================
     
     
    +2012-12-14: wsfulton
    +            [CFFI] Fix #3161614 - Some string constants are incorrect
    +
     2012-12-13: wsfulton
                 [CFFI] Fix #3529690 - Fix incorrect constant names.
     
    diff --git a/Examples/test-suite/preproc_constants.i b/Examples/test-suite/preproc_constants.i
    index 1bf84a91a..7507d632c 100644
    --- a/Examples/test-suite/preproc_constants.i
    +++ b/Examples/test-suite/preproc_constants.i
    @@ -39,6 +39,7 @@
     #define CONST_CHAR      'x'
     #define CONST_STRING1   "const string"
     #define CONST_STRING2   "const" " string"
    +#define CONST_STRING3   "log-revprops"
     
     // Expressions - runtime tests check the type for any necessary type promotions of the expressions
     
    diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx
    index d3f0391d0..88f82b647 100644
    --- a/Source/Modules/cffi.cxx
    +++ b/Source/Modules/cffi.cxx
    @@ -565,7 +565,13 @@ void CFFI::emit_defun(Node *n, String *name) {
     
     int CFFI::constantWrapper(Node *n) {
       String *type = Getattr(n, "type");
    -  String *converted_value = convert_literal(Getattr(n, "value"), type);
    +  String *converted_value;
    +  if (SwigType_type(type) == T_STRING) {
    +    converted_value = NewString(Getattr(n, "rawval"));
    +  } else {
    +    converted_value = convert_literal(Getattr(n, "value"), type);
    +  }
    +
       String *name = lispify_name(n, Getattr(n, "sym:name"), "'constant");
     
       if (Strcmp(name, "t") == 0 || Strcmp(name, "T") == 0)
    
    From ff95b17588bcbb9e0e6ee660e65951009e49c46e Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= 
    Date: Fri, 14 Dec 2012 13:33:37 +0000
    Subject: [PATCH 0321/1160] Adapt configure.in to detect ruby.h in Ruby1.9+
     canonical include pathes
    
    Fixes issue 3595945
    
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13964 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     configure.in | 9 +++++++++
     1 file changed, 9 insertions(+)
    
    diff --git a/configure.in b/configure.in
    index 1c31b74a0..07a78fb11 100644
    --- a/configure.in
    +++ b/configure.in
    @@ -1340,7 +1340,13 @@ fi
     
     AC_MSG_CHECKING(for Ruby header files)
     if test -n "$RUBY"; then
    +        # Try Ruby1.9 first
    +        RUBYDIR=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["rubyhdrdir"]] || $rubyhdrdir') 2>/dev/null`
    +	if test x"$RUBYDIR" == x""; then
     	RUBYDIR=`($RUBY -rmkmf -e 'print Config::CONFIG[["archdir"]] || $archdir') 2>/dev/null`
    +        else
    +                RUBYARCH=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["arch"]] || $arch') 2>/dev/null`
    +        fi
     	if test x"$RUBYDIR" != x""; then
     		dirs="$RUBYDIR"
     		RUBYINCLUDE=none
    @@ -1351,6 +1357,9 @@ if test -n "$RUBY"; then
     				break;
     			fi
     		done
    +                if test x"$RUBYARCH" != x""; then
    +			RUBYINCLUDE="-I$RUBYDIR -I$RUBYDIR/$RUBYARCH"
    +                fi
     		if test "$RUBYINCLUDE" = none; then
     			RUBYINCLUDE="-I$RUBYDIR"
     			AC_MSG_RESULT(could not locate ruby.h...using $RUBYINCLUDE)
    
    From eab417a3a1900a543e4916b17dd4b7d891db80f3 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= 
    Date: Fri, 14 Dec 2012 14:07:32 +0000
    Subject: [PATCH 0322/1160] Ruby 1.9: Add current dir to load path when running
     Ruby
    
    Ruby 1.9 changes the default load path to _not_ include the current
    directory. This breaks running the test cases.
    
    
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13965 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Examples/test-suite/ruby/Makefile.in | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/Examples/test-suite/ruby/Makefile.in b/Examples/test-suite/ruby/Makefile.in
    index e157e72ca..3354acfd8 100644
    --- a/Examples/test-suite/ruby/Makefile.in
    +++ b/Examples/test-suite/ruby/Makefile.in
    @@ -61,7 +61,7 @@ ruby_naming.cpptest: SWIGOPT += -autorename
     # a file is found which has _runme.rb appended after the testcase name.
     run_testcase = \
     	if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
    -	  env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(RUBY) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
    +	  env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(RUBY) -I. $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
     	fi
     
     # Clean
    
    From 5a2f1139c3962a3d8e392283604c8b9c607af28e Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= 
    Date: Fri, 14 Dec 2012 14:13:12 +0000
    Subject: [PATCH 0323/1160] document Ruby fixes
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13966 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current | 3 +++
     1 file changed, 3 insertions(+)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index e49b61a78..bdb9c682c 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
     Version 2.0.9 (in progress)
     ===========================
     
    +2012-12-14: kkaempf
    +            [Ruby] Applied patches #3530442 and 3530443 to adapt compile and runtime include
    +            pathes to match Ruby 1.9+
     
     2012-12-14: wsfulton
                 [CFFI] Fix #3161614 - Some string constants are incorrect
    
    From 23771ef027e6cf72f12e464ccd3b58abaac1607d Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= 
    Date: Fri, 14 Dec 2012 15:48:31 +0000
    Subject: [PATCH 0324/1160] Ruby: Replace all occurences of STR2CSTR macro with
     calls to StringValuePtr
    
    STR2CSTR was deprecated in Ruby since years and got finally removed
    in Ruby 1.9
    
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13967 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current                         | 4 ++++
     Doc/Manual/Ruby.html                    | 8 ++++----
     Examples/ruby/hashargs/example.i        | 2 +-
     Examples/ruby/multimap/example.i        | 6 +++---
     Examples/test-suite/memberin1.i         | 2 +-
     Examples/test-suite/namespace_typemap.i | 2 +-
     Lib/ruby/argcargv.i                     | 2 +-
     Lib/ruby/rubystrings.swg                | 4 ----
     8 files changed, 15 insertions(+), 15 deletions(-)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index bdb9c682c..6256f0469 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.9 (in progress)
     ===========================
     
    +2012-12-14: kkaempf
    +            [Ruby] Apply patch 3530439 and finally replace all occurences of the STR2CSTR() macro
    +            with StringValuePtr(). STR2CSTR was deprecated since years and got removed in Ruby 1.9
    +
     2012-12-14: kkaempf
                 [Ruby] Applied patches #3530442 and 3530443 to adapt compile and runtime include
                 pathes to match Ruby 1.9+
    diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html
    index 969de7a3d..47cf4f303 100644
    --- a/Doc/Manual/Ruby.html
    +++ b/Doc/Manual/Ruby.html
    @@ -4926,7 +4926,7 @@ arguments. For example: 

    -
    %typemap(in) (char *str, int len) {
    $1 = STR2CSTR($input);
    $2 = (int) RSTRING($input)->len;
    };

    int count(char c, char *str, int len);
    +
    %typemap(in) (char *str, int len) {
    $1 = StringValuePtr($input);
    $2 = (int) RSTRING($input)->len;
    };

    int count(char c, char *str, int len);
    @@ -7135,7 +7135,7 @@ Ruby_Format_TypeError( "$1_name", "$1_type","$symname", $argnum, $input - char * STR2CSTR(String) + char * StringValuePtr(String) SWIG_AsCharPtrAndSize(VALUE, char*, size_t, int* alloc) @@ -7518,7 +7518,7 @@ Array instance to be used as a char ** object.

    -
    %module argv

    // This tells SWIG to treat char ** as a special case
    %typemap(in) char ** {
    /* Get the length of the array */
    int size = RARRAY($input)->len;
    int i;
    $1 = (char **) malloc((size+1)*sizeof(char *));
    /* Get the first element in memory */
    VALUE *ptr = RARRAY($input)->ptr;
    for (i=0; i < size; i++, ptr++)
    /* Convert Ruby Object String to char* */
    $1[i]= STR2CSTR(*ptr);
    $1[i]=NULL; /* End of list */
    }

    // This cleans up the char ** array created before
    // the function call

    %typemap(freearg) char ** {
    free((char *) $1);
    }

    // Now a test function
    %inline %{
    int print_args(char **argv) {
    int i = 0;
    while (argv[i]) {
    printf("argv[%d] = %s\n", i,argv[i]);
    i++;
    }
    return i;
    }
    %}

    +
    %module argv

    // This tells SWIG to treat char ** as a special case
    %typemap(in) char ** {
    /* Get the length of the array */
    int size = RARRAY($input)->len;
    int i;
    $1 = (char **) malloc((size+1)*sizeof(char *));
    /* Get the first element in memory */
    VALUE *ptr = RARRAY($input)->ptr;
    for (i=0; i < size; i++, ptr++)
    /* Convert Ruby Object String to char* */
    $1[i]= StringValuePtr(*ptr);
    $1[i]=NULL; /* End of list */
    }

    // This cleans up the char ** array created before
    // the function call

    %typemap(freearg) char ** {
    free((char *) $1);
    }

    // Now a test function
    %inline %{
    int print_args(char **argv) {
    int i = 0;
    while (argv[i]) {
    printf("argv[%d] = %s\n", i,argv[i]);
    i++;
    }
    return i;
    }
    %}

    @@ -7796,7 +7796,7 @@ equivalents and store them in our local C arrays:

    -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    $2 = NULL;
    $3 = NULL;
    if ($1 > 0) {
    $2 = (char **) malloc($1*sizeof(char *));
    $3 = (int *) malloc($1*sizeof(int));
    keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
    for (i = 0; i < $1; i++) {
    key = rb_ary_entry(keys_arr, i);
    val = rb_hash_aref($input, key);
    Check_Type(key, T_STRING);
    Check_Type(val, T_FIXNUM);
    $2[i] = STR2CSTR(key);
    $3[i] = NUM2INT(val);

    }
    }
    }
    +
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    $2 = NULL;
    $3 = NULL;
    if ($1 > 0) {
    $2 = (char **) malloc($1*sizeof(char *));
    $3 = (int *) malloc($1*sizeof(int));
    keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
    for (i = 0; i < $1; i++) {
    key = rb_ary_entry(keys_arr, i);
    val = rb_hash_aref($input, key);
    Check_Type(key, T_STRING);
    Check_Type(val, T_FIXNUM);
    $2[i] = StringValuePtr(key);
    $3[i] = NUM2INT(val);

    }
    }
    }
    diff --git a/Examples/ruby/hashargs/example.i b/Examples/ruby/hashargs/example.i index 159bbd32a..10e209e5f 100644 --- a/Examples/ruby/hashargs/example.i +++ b/Examples/ruby/hashargs/example.i @@ -14,7 +14,7 @@ val = rb_hash_aref($input, key); Check_Type(key, T_STRING); Check_Type(val, T_FIXNUM); - $2[i] = STR2CSTR(key); + $2[i] = StringValuePtr(key); $3[i] = NUM2INT(val); } } diff --git a/Examples/ruby/multimap/example.i b/Examples/ruby/multimap/example.i index f68422a18..34f0b899b 100644 --- a/Examples/ruby/multimap/example.i +++ b/Examples/ruby/multimap/example.i @@ -31,7 +31,7 @@ extern int gcd(int x, int y); free($2); SWIG_exception(SWIG_ValueError, "List items must be strings"); } - $2[i] = STR2CSTR(s); + $2[i] = StringValuePtr(s); } $2[i] = 0; } @@ -46,7 +46,7 @@ extern int gcdmain(int argc, char *argv[]); if (TYPE($input) != T_STRING) { SWIG_exception(SWIG_ValueError, "Expected a string"); } - $1 = STR2CSTR($input); + $1 = StringValuePtr($input); $2 = RSTRING_LEN($input); } @@ -60,7 +60,7 @@ extern int count(char *bytes, int len, char c); if (TYPE($input) != T_STRING) { SWIG_exception(SWIG_ValueError,"Expected a string"); } - temp = STR2CSTR($input); + temp = StringValuePtr($input); $2 = RSTRING_LEN($input); $1 = (char *) malloc($2+1); memmove($1,temp,$2); diff --git a/Examples/test-suite/memberin1.i b/Examples/test-suite/memberin1.i index 920323044..ece489e3d 100644 --- a/Examples/test-suite/memberin1.i +++ b/Examples/test-suite/memberin1.i @@ -47,7 +47,7 @@ public: #ifdef SWIGRUBY %typemap(in) String { Check_Type($input, T_STRING); - $1 = String(STR2CSTR($input)); + $1 = String(StringValuePtr($input)); } #endif diff --git a/Examples/test-suite/namespace_typemap.i b/Examples/test-suite/namespace_typemap.i index f25f88574..8ead78c6c 100644 --- a/Examples/test-suite/namespace_typemap.i +++ b/Examples/test-suite/namespace_typemap.i @@ -100,7 +100,7 @@ namespace test { #endif #ifdef SWIGRUBY %typemap(in) string_class * { - $1 = new string_class(STR2CSTR($input)); + $1 = new string_class(StringValuePtr($input)); } %typemap(freearg) string_class * { delete $1; diff --git a/Lib/ruby/argcargv.i b/Lib/ruby/argcargv.i index ae1f6bbd3..fc0bc406a 100644 --- a/Lib/ruby/argcargv.i +++ b/Lib/ruby/argcargv.i @@ -30,7 +30,7 @@ $2 = (char **) malloc((size+1)*sizeof(char *)); VALUE *ptr = RARRAY_PTR($input); for (i=0; i < size; i++, ptr++) { - $2[i]= STR2CSTR(*ptr); + $2[i]= StringValuePtr(*ptr); } $2[i]=NULL; } else { diff --git a/Lib/ruby/rubystrings.swg b/Lib/ruby/rubystrings.swg index e6b92ef58..3adf0008b 100644 --- a/Lib/ruby/rubystrings.swg +++ b/Lib/ruby/rubystrings.swg @@ -7,11 +7,7 @@ SWIGINTERN int SWIG_AsCharPtrAndSize(VALUE obj, char** cptr, size_t* psize, int *alloc) { if (TYPE(obj) == T_STRING) { - %#if defined(StringValuePtr) char *cstr = StringValuePtr(obj); - %#else - char *cstr = STR2CSTR(obj); - %#endif size_t size = RSTRING_LEN(obj) + 1; if (cptr) { if (alloc) { From ca61d10d9b6a57d294671731944acf23ee1e66a8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Dec 2012 12:46:04 +0000 Subject: [PATCH 0325/1160] Temporary workaround for testcase failing in PHP git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13968 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/typemap_directorout.i | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Examples/test-suite/typemap_directorout.i b/Examples/test-suite/typemap_directorout.i index 4a85bd47c..fb0a6ab81 100644 --- a/Examples/test-suite/typemap_directorout.i +++ b/Examples/test-suite/typemap_directorout.i @@ -13,6 +13,24 @@ // Can't use the %typemap(directorout) MyType & = SWIGTYPE & approach as non-director languages don't define any directorout typemaps %typemap(directorout) MyType &Class1::foo2, MyType &foo1 %{ /* special start */ $input = 0; /* special end */ %} +#ifdef SWIGPHP +%typemap(directorout, warning="PHP directorout typemaps need fixing") MyType &Class1::foo2, MyType &foo1 %{ /* special start */ /*$input = 0;*/ /* special end */ %} +/* Patch to make $input work same as other languages. Then $input needs changing to &$input in most (maybe all) typemaps. +--- a/Source/Modules/php.cxx ++++ b/Source/Modules/php.cxx +@@ -2631,8 +2631,7 @@ done: + if (!is_void) { + tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); + if (tm != 0) { +- static const String *amp_result = NewStringf("&%s", Swig_cresult_name()); +- Replaceall(tm, "$input", amp_result); ++ Replaceall(tm, "$input", Swig_cresult_name()); + char temp[24]; + sprintf(temp, "%d", idx); + Replaceall(tm, "$argnum", temp); +*/ +#endif + #ifdef SWIGCSHARP %typemap(csdirectorout) MyType & %{ WILL_NOT_COMPILE %} From 6679f5dcd0c17e35558a107a5d0e9df0a203787b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Dec 2012 14:55:54 +0000 Subject: [PATCH 0326/1160] Rework warning fixes in rev 13512 as it introduces dead code flagged by sun studio git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13969 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/DOH/fio.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Source/DOH/fio.c b/Source/DOH/fio.c index c4fbb1e8f..573bebe7b 100644 --- a/Source/DOH/fio.c +++ b/Source/DOH/fio.c @@ -481,14 +481,16 @@ int DohCopyto(DOH *in, DOH *out) { cw = buffer; while (nwrite) { wret = Write(out, cw, nwrite); - if (wret < 0) - return -1; + if (wret < 0) { + nbytes = -1; + break; + } nwrite = nwrite - wret; cw += wret; } nbytes += ret; } else { - return nbytes; + break; } } return nbytes; @@ -579,12 +581,12 @@ DOH *DohReadline(DOH *in) { if (Read(in, &c, 1) < 0) { if (n == 0) { Delete(s); - return 0; + s = 0; } - return s; + break; } if (c == '\n') - return s; + break; if (c == '\r') continue; Putc(c, s); From 94fb7629f4b11b19481ec577250304e09716bec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= Date: Sat, 15 Dec 2012 16:16:40 +0000 Subject: [PATCH 0327/1160] Apply patch 3530444 Class#methods and Class#constants returns array of symbols from Ruby 1.9 on git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13970 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Examples/test-suite/ruby/ruby_naming_runme.rb | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 6256f0469..5a7c98e9c 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.9 (in progress) =========================== +2012-12-15: kkaempf + [Ruby] Apply patch 3530444, Class#methods and Class#constants returns array of + symbols in Ruby 1.9+ + 2012-12-14: kkaempf [Ruby] Apply patch 3530439 and finally replace all occurences of the STR2CSTR() macro with StringValuePtr(). STR2CSTR was deprecated since years and got removed in Ruby 1.9 diff --git a/Examples/test-suite/ruby/ruby_naming_runme.rb b/Examples/test-suite/ruby/ruby_naming_runme.rb index 8ea5f13d3..d5525bca8 100644 --- a/Examples/test-suite/ruby/ruby_naming_runme.rb +++ b/Examples/test-suite/ruby/ruby_naming_runme.rb @@ -35,23 +35,23 @@ if Ruby_naming::CONSTANT3 != 3 raise RuntimeError, "Incorrect value for CONSTANT3" end -if not Ruby_naming::methods.include?("constant4") +if not (Ruby_naming::methods.include?("constant4") || Ruby_naming::methods.include?(:constant4)) raise RuntimeError, "Incorrect mapping for constant4" end -if not Ruby_naming::methods.include?("constant5") +if not (Ruby_naming::methods.include?("constant5") || Ruby_naming::methods.include?(:constant5)) raise RuntimeError, "Incorrect mapping for constant5" end -if not Ruby_naming::methods.include?("constant6") +if not (Ruby_naming::methods.include?("constant6") || Ruby_naming::methods.include?(:constant6)) raise RuntimeError, "Incorrect mapping for constant6" end -if not Ruby_naming::TestConstants.instance_methods.include?("constant7") +if not (Ruby_naming::TestConstants.instance_methods.include?("constant7") || Ruby_naming::TestConstants.instance_methods.include?(:constant7)) raise RuntimeError, "Incorrect mapping for constant7" end -if not Ruby_naming::TestConstants.methods.include?("constant8") +if not (Ruby_naming::TestConstants.methods.include?("constant8") || Ruby_naming::TestConstants.methods.include?(:constant8)) raise RuntimeError, "Incorrect mapping for constant8" end @@ -64,7 +64,7 @@ if Ruby_naming::TestConstants::CONSTANT10 != 10 raise RuntimeError, "Incorrect value for CONSTANT10" end -if not Ruby_naming::methods.include?("constant11") +if not (Ruby_naming::methods.include?("constant11") || Ruby_naming::methods.include?(:constant11)) raise RuntimeError, "Incorrect mapping for constant11" end From e39a16c92a7d564e8ed55d46feee3f6590764b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= Date: Sat, 15 Dec 2012 16:20:19 +0000 Subject: [PATCH 0328/1160] Fix detection of Ruby include files for Ruby 1.8.7 svn rev r13964 broke it for Ruby 1.8.7 :-/ git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13971 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- configure.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.in b/configure.in index 07a78fb11..455f86fd1 100644 --- a/configure.in +++ b/configure.in @@ -1342,8 +1342,8 @@ AC_MSG_CHECKING(for Ruby header files) if test -n "$RUBY"; then # Try Ruby1.9 first RUBYDIR=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["rubyhdrdir"]] || $rubyhdrdir') 2>/dev/null` - if test x"$RUBYDIR" == x""; then - RUBYDIR=`($RUBY -rmkmf -e 'print Config::CONFIG[["archdir"]] || $archdir') 2>/dev/null` + if test x"$RUBYDIR" == x"" || test x"$RUBYDIR" == x"nil"; then + RUBYDIR=`($RUBY -rmkmf -e 'print Config::CONFIG[["archdir"]] || $archdir') 2>/dev/null` else RUBYARCH=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["arch"]] || $arch') 2>/dev/null` fi @@ -1357,9 +1357,9 @@ if test -n "$RUBY"; then break; fi done - if test x"$RUBYARCH" != x""; then + if test x"$RUBYARCH" != x""; then RUBYINCLUDE="-I$RUBYDIR -I$RUBYDIR/$RUBYARCH" - fi + fi if test "$RUBYINCLUDE" = none; then RUBYINCLUDE="-I$RUBYDIR" AC_MSG_RESULT(could not locate ruby.h...using $RUBYINCLUDE) From 8a8c8e377b114192f4f024b698bdfe758e52a91b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Dec 2012 18:33:02 +0000 Subject: [PATCH 0329/1160] gcc-4.6 warning fix git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13972 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 01622f4ce..5c3ce283e 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1091,9 +1091,6 @@ public: int min_num_of_arguments = emit_num_required(l); int max_num_of_arguments = emit_num_arguments(l); - // For a function with default arguments, we end up with the fullest - // parmlist in full_parmlist. - ParmList *full_parmlist = l; Hash *ret_types = NewHash(); Setattr(ret_types, d, d); @@ -1126,7 +1123,6 @@ public: if (num_arguments > max_num_of_arguments) { max_num_of_arguments = num_arguments; - full_parmlist = l2; } o = Getattr(o, "sym:nextSibling"); } From 6f819d1cd1f0fbc050d1484ae29266683c51f8dd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Dec 2012 23:41:01 +0000 Subject: [PATCH 0330/1160] Detect mono C# compiler on newer linux distributions git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13973 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/csharp/Makefile.in | 2 +- configure.in | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index b89b50eb2..4fd8052c6 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -72,7 +72,7 @@ run_testcase = \ $(MAKE) -f $*/$(top_builddir)/$(EXAMPLES)/Makefile \ CSHARPFLAGS='-nologo -debug+ $(CSHARPFLAGSSPECIAL) -out:$*_runme.exe' \ 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" DYLD_FALLBACK_LIBRARY_PATH= $(RUNTOOL) $(INTERPRETER) $(INTERPRETER_FLAGS) $*_runme.exe; \ + env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" DYLD_FALLBACK_LIBRARY_PATH= $(RUNTOOL) $(INTERPRETER) $(INTERPRETER_FLAGS) ./$*_runme.exe; \ else \ cd $* && \ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ diff --git a/configure.in b/configure.in index 455f86fd1..0ead9b606 100644 --- a/configure.in +++ b/configure.in @@ -1771,19 +1771,19 @@ if test -z "$CSHARPCOMPILERBIN" ; then case $host in *-*-cygwin* | *-*-mingw*) # prefer Mono gmcs (.NET 2.0) over mcs (.NET 1.1) - note mcs-1.2.3 has major pinvoke bug - AC_CHECK_PROGS(CSHARPCOMPILER, csc gmcs mcs cscc) + AC_CHECK_PROGS(CSHARPCOMPILER, csc mono-csc gmcs mcs cscc) if test -n "$CSHARPCOMPILER" && test "$CSHARPCOMPILER" = "csc" ; then AC_MSG_CHECKING(whether csc is the Microsoft CSharp compiler) csc 2>/dev/null | grep "C#" > /dev/null || CSHARPCOMPILER="" if test -z "$CSHARPCOMPILER" ; then AC_MSG_RESULT(no) - AC_CHECK_PROGS(CSHARPCOMPILER, gmcs mcs cscc) + AC_CHECK_PROGS(CSHARPCOMPILER, mono-csc gmcs mcs cscc) else AC_MSG_RESULT(yes) fi fi ;; - *)AC_CHECK_PROGS(CSHARPCOMPILER, gmcs mcs cscc);; + *)AC_CHECK_PROGS(CSHARPCOMPILER, mono-csc gmcs mcs cscc);; esac else CSHARPCOMPILER="$CSHARPCOMPILERBIN" From 87ee6da3659ec29400ad245fa7eac6a39457e316 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Dec 2012 23:56:27 +0000 Subject: [PATCH 0331/1160] Make php example C90 compliant git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13974 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/php/cpointer/example.i | 5 +++++ Examples/php/pointer/example.i | 6 ++++++ Examples/php/simple/example.i | 8 +++----- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Examples/php/cpointer/example.i b/Examples/php/cpointer/example.i index 52e6df190..c61d92858 100644 --- a/Examples/php/cpointer/example.i +++ b/Examples/php/cpointer/example.i @@ -1,6 +1,11 @@ /* File : example.i */ %module example +%{ +extern void add(int *, int *, int *); +extern void sub(int *, int *, int *); +%} + /* This example illustrates a couple of different techniques for manipulating C pointers */ diff --git a/Examples/php/pointer/example.i b/Examples/php/pointer/example.i index c14b94189..1f0059406 100644 --- a/Examples/php/pointer/example.i +++ b/Examples/php/pointer/example.i @@ -1,6 +1,12 @@ /* File : example.i */ %module example +%{ +extern void add(double *, double *, double *); +extern void sub(int *, int *, int *); +extern int divide(int, int, int *); +%} + /* This example illustrates a couple of different techniques for manipulating C pointers */ diff --git a/Examples/php/simple/example.i b/Examples/php/simple/example.i index af4ff08a7..9d4e22aa9 100644 --- a/Examples/php/simple/example.i +++ b/Examples/php/simple/example.i @@ -1,10 +1,8 @@ /* File : example.i */ %module example -%{ - extern double Foo; -%} - +%inline %{ +extern int gcd(int x, int y); extern double Foo; void print_Foo(); -int gcd(int x, int y); +%} From 6dd4f362b35e19d5d4db7c728bc3accb678bf0ad Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Dec 2012 08:38:22 +0000 Subject: [PATCH 0332/1160] Testcase correction for missing virtual destructor git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13975 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/virtual_vs_nonvirtual_base.i | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/test-suite/virtual_vs_nonvirtual_base.i b/Examples/test-suite/virtual_vs_nonvirtual_base.i index 9e8bc5eab..009461835 100644 --- a/Examples/test-suite/virtual_vs_nonvirtual_base.i +++ b/Examples/test-suite/virtual_vs_nonvirtual_base.i @@ -6,6 +6,7 @@ class SimpleVirtual { public: virtual int implementMe() = 0; + virtual ~SimpleVirtual() {} }; class SimpleNonVirtual From 093dc60d2deb9ee180a3e998ad89c314470b0804 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Dec 2012 13:56:50 +0000 Subject: [PATCH 0333/1160] Fix garbage line number and empty file name reporting for some '}' or ')' error messages git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13976 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ .../test-suite/errors/cpp_missing_rparenthesis.i | 13 +++++++++++++ Examples/test-suite/errors/expected.log | 6 +++++- Examples/test-suite/errors/make.sh | 1 + Source/CParse/cscanner.c | 3 ++- Source/Swig/scanner.c | 7 +++++++ 6 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/errors/cpp_missing_rparenthesis.i diff --git a/CHANGES.current b/CHANGES.current index 5a7c98e9c..22c9a3301 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.9 (in progress) =========================== +2012-12-16: wsfulton + Fix garbage line number / empty file name reporting for some missing + '}' or ')' error messages. + 2012-12-15: kkaempf [Ruby] Apply patch 3530444, Class#methods and Class#constants returns array of symbols in Ruby 1.9+ diff --git a/Examples/test-suite/errors/cpp_missing_rparenthesis.i b/Examples/test-suite/errors/cpp_missing_rparenthesis.i new file mode 100644 index 000000000..5d0627e86 --- /dev/null +++ b/Examples/test-suite/errors/cpp_missing_rparenthesis.i @@ -0,0 +1,13 @@ +%module xxx + +%inline %{ +class Klass { +Klass(int i) : m_i( +{ +} +}; +%} + +void something() { +} + diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log index 4f56e7146..9d4e5db77 100644 --- a/Examples/test-suite/errors/expected.log +++ b/Examples/test-suite/errors/expected.log @@ -46,7 +46,7 @@ c_long_short.i:5: Error: Extra long specifier. c_long_short.i:6: Error: Extra short specifier. :::::::::::::::::::::::::::::::: c_missing_rbrace.i ::::::::::::::::::::::::::::::::::: -:168430090: Error: Missing '}'. Reached end of input. +c_missing_rbrace.i:3: Error: Missing '}'. Reached end of input. c_missing_rbrace.i:3: Error: Syntax error in input(1). :::::::::::::::::::::::::::::::: c_missing_semi.i ::::::::::::::::::::::::::::::::::: @@ -296,6 +296,10 @@ cpp_macro_locator.i:97: Warning 509: as it is shadowed by overloadinline2(int *) cpp_macro_locator.i:101: Warning 509: Overloaded method overload5(int const *) effectively ignored, cpp_macro_locator.i:100: Warning 509: as it is shadowed by overload5(int *). +:::::::::::::::::::::::::::::::: cpp_missing_rparenthesis.i ::::::::::::::::::::::::::::::::::: +cpp_missing_rparenthesis.i:5: Error: Missing ')'. Reached end of input. +cpp_missing_rparenthesis.i:5: Error: Syntax error in input(3). + :::::::::::::::::::::::::::::::: cpp_missing_rtemplate.i ::::::::::::::::::::::::::::::::::: cpp_missing_rtemplate.i:4: Error: Syntax error in input(1). diff --git a/Examples/test-suite/errors/make.sh b/Examples/test-suite/errors/make.sh index e243315ec..90f17a92a 100755 --- a/Examples/test-suite/errors/make.sh +++ b/Examples/test-suite/errors/make.sh @@ -70,6 +70,7 @@ cpp_extend_undefined cpp_inline_namespace cpp_inherit cpp_macro_locator +cpp_missing_rparenthesis cpp_missing_rtemplate cpp_namespace_alias cpp_namespace_aliasnot diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index d4678ffdf..64875a4d1 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -103,10 +103,11 @@ void start_inline(char *text, int line) { * ----------------------------------------------------------------------------- */ void skip_balanced(int startchar, int endchar) { + int start_line = Scanner_line(scan); Clear(scanner_ccode); if (Scanner_skip_balanced(scan,startchar,endchar) < 0) { - Swig_error(Scanner_file(scan),Scanner_errline(scan), "Missing '%c'. Reached end of input.\n", endchar); + Swig_error(cparse_file, start_line, "Missing '%c'. Reached end of input.\n", endchar); return; } diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index 8b1c6183e..8c4bf26a2 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -65,6 +65,7 @@ Scanner *NewScanner(void) { s->text = NewStringEmpty(); s->str = 0; s->error = 0; + s->error_line = 0; s->freeze_line = 0; return s; } @@ -104,6 +105,12 @@ void Scanner_clear(Scanner * s) { s->nexttoken = -1; s->start_line = 0; s->yylen = 0; + /* Should these be cleared too? + s->idstart; + s->file; + s->error_line; + s->freeze_line; + */ } /* ----------------------------------------------------------------------------- From ac75e4ae53b1813f5791798ac5b679b52889a81a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Dec 2012 14:39:37 +0000 Subject: [PATCH 0334/1160] 2.0.9 release notes and date git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13977 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- ANNOUNCE | 2 +- CHANGES.current | 8 ++++---- Doc/Manual/Sections.html | 2 +- README | 2 +- RELEASENOTES | 6 ++++++ 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index f6a24967a..8ac224247 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,4 +1,4 @@ -*** ANNOUNCE: SWIG 2.0.9 (in progress) *** +*** ANNOUNCE: SWIG 2.0.9 (16 December 2012) *** http://www.swig.org diff --git a/CHANGES.current b/CHANGES.current index 22c9a3301..c88bed34d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,11 +2,11 @@ Below are the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.9 (in progress) -=========================== +Version 2.0.9 (16 December 2012) +================================ 2012-12-16: wsfulton - Fix garbage line number / empty file name reporting for some missing + Fix garbage line number / empty file name reporting for some missing '}' or ')' error messages. 2012-12-15: kkaempf @@ -19,7 +19,7 @@ Version 2.0.9 (in progress) 2012-12-14: kkaempf [Ruby] Applied patches #3530442 and 3530443 to adapt compile and runtime include - pathes to match Ruby 1.9+ + paths to match Ruby 1.9+ 2012-12-14: wsfulton [CFFI] Fix #3161614 - Some string constants are incorrect diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 483d64463..faff95298 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

    SWIG-2.0 Documentation

    -Last update : SWIG-2.0.9 (in progress) +Last update : SWIG-2.0.9 (16 December 2012)

    Sections

    diff --git a/README b/README index c9abef486..68a55e862 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.9 (in progress) +Version: 2.0.9 (16 December 2012) 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 e09e2cad0..af9f4fb6b 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -4,6 +4,12 @@ and CHANGES files. Release Notes ============= +SWIG-2.0.9 summary: +- Improved typemap matching. +- Ruby 1.9 support is much improved. +- Various bug fixes and minor improvements in C#, CFFI, Go, Java, + Modula3, Octave, Perl, Python, R, Ruby, Tcl and in ccache-swig. + SWIG-2.0.8 summary: - Fix a couple of regressions introduced in 2.0.5 and 2.0.7. - Improved using declarations and using directives support. From 7ff0dfe426327db14bbc2922dc90408bd17ecf13 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Wed, 2 Jan 2013 15:07:56 -0600 Subject: [PATCH 0335/1160] Fix for SourceForge Bug #1278 * Modify test-suite to test Java directors with multi-level namespaces. * Path java module to correctly generate method descriptors when multilevel namespaces are used. --- .gitignore | 7 ++ Examples/test-suite/director_nspace.i | 96 ++++++++++--------- .../java/director_nspace_runme.java | 12 +-- Source/Modules/java.cxx | 7 +- 4 files changed, 70 insertions(+), 52 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..d4ac5207b --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +# Compiled Source +*.o +*.class + +# Local PCRE +prce +*.gz diff --git a/Examples/test-suite/director_nspace.i b/Examples/test-suite/director_nspace.i index 6814a43a3..121a06f1f 100644 --- a/Examples/test-suite/director_nspace.i +++ b/Examples/test-suite/director_nspace.i @@ -8,28 +8,31 @@ SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE) %{ #include -namespace Bar +namespace TopLevel { - class FooBar { - public: - FooBar() {} - FooBar(const FooBar&) {} - virtual ~FooBar() {} + namespace Bar + { + class FooBar { + public: + FooBar() {} + FooBar(const FooBar&) {} + virtual ~FooBar() {} + + std::string FooBarDo() { return "Bar::Foo2::Foo2Bar()"; } + }; - std::string FooBarDo() { return "Bar::Foo2::Foo2Bar()"; } - }; + class Foo { + public: + virtual ~Foo() {} + virtual std::string ping() { return "Bar::Foo::ping()"; } + virtual std::string pong() { return "Bar::Foo::pong();" + ping(); } + virtual std::string fooBar(FooBar* fb) { return fb->FooBarDo(); } + virtual Foo makeFoo() { return Foo(); } + virtual FooBar makeFooBar() { return FooBar(); } - class Foo { - public: - virtual ~Foo() {} - virtual std::string ping() { return "Bar::Foo::ping()"; } - virtual std::string pong() { return "Bar::Foo::pong();" + ping(); } - virtual std::string fooBar(FooBar* fb) { return fb->FooBarDo(); } - virtual Foo makeFoo() { return Foo(); } - virtual FooBar makeFooBar() { return FooBar(); } - - static Foo* get_self(Foo *self_) {return self_;} - }; + static Foo* get_self(Foo *self_) {return self_;} + }; + } } %} @@ -38,36 +41,39 @@ namespace Bar // nspace feature only supported by these languages #if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) -%nspace Bar::Foo; -%nspace Bar::FooBar; +%nspace TopLevel::Bar::Foo; +%nspace TopLevel::Bar::FooBar; #else #warning nspace feature not yet supported in this target language #endif -%feature("director") Bar::Foo; +%feature("director") TopLevel::Bar::Foo; -namespace Bar -{ - class FooBar { - public: - FooBar(); - FooBar(const FooBar&); - virtual ~FooBar(); +namespace TopLevel +{ + namespace Bar + { + class FooBar { + public: + FooBar(); + FooBar(const FooBar&); + virtual ~FooBar(); + + std::string FooBarDo(); + + }; - std::string FooBarDo(); - - }; - - class Foo - { - public: - virtual ~Foo(); - virtual std::string ping(); - virtual std::string pong(); - virtual std::string fooBar(FooBar* fb); - virtual Foo makeFoo(); - virtual FooBar makeFooBar(); - - static Foo* get_self(Foo *self_); - }; + class Foo + { + public: + virtual ~Foo(); + virtual std::string ping(); + virtual std::string pong(); + virtual std::string fooBar(FooBar* fb); + virtual Foo makeFoo(); + virtual FooBar makeFooBar(); + + static Foo* get_self(Foo *self_); + }; + } } diff --git a/Examples/test-suite/java/director_nspace_runme.java b/Examples/test-suite/java/director_nspace_runme.java index 4e56f91c2..53a6131a7 100644 --- a/Examples/test-suite/java/director_nspace_runme.java +++ b/Examples/test-suite/java/director_nspace_runme.java @@ -19,7 +19,7 @@ public class director_nspace_runme { } -class director_nspace_MyBarFoo extends director_nspacePackage.Bar.Foo { +class director_nspace_MyBarFoo extends director_nspacePackage.TopLevel.Bar.Foo { @Override public String ping() { @@ -32,17 +32,17 @@ class director_nspace_MyBarFoo extends director_nspacePackage.Bar.Foo { } @Override - public String fooBar(director_nspacePackage.Bar.FooBar fooBar) { + public String fooBar(director_nspacePackage.TopLevel.Bar.FooBar fooBar) { return fooBar.FooBarDo(); } @Override - public director_nspacePackage.Bar.Foo makeFoo() { - return new director_nspacePackage.Bar.Foo(); + public director_nspacePackage.TopLevel.Bar.Foo makeFoo() { + return new director_nspacePackage.TopLevel.Bar.Foo(); } @Override - public director_nspacePackage.Bar.FooBar makeFooBar() { - return new director_nspacePackage.Bar.FooBar(); + public director_nspacePackage.TopLevel.Bar.FooBar makeFooBar() { + return new director_nspacePackage.TopLevel.Bar.FooBar(); } } diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index cd8cfe543..971e60659 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -4253,8 +4253,13 @@ public: Wrapper *w = NewWrapper(); if (Len(package_path) > 0) - if (Len(getNSpace()) > 0) + if (Len(getNSpace()) > 0) { internal_classname = NewStringf("%s/%s/%s", package_path, getNSpace(), classname); + + // If the namespace is multiple levels, the result of getNSpace() will have inserted + // .'s to delimit namespaces, so we need to replace those with /'s + Replace(internal_classname, ".", "/", DOH_REPLACE_ANY); + } else internal_classname = NewStringf("%s/%s", package_path, classname); else From 981684fc1e1f5a21fd65fe2d07df2daf05a98a64 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 3 Jan 2013 07:17:09 +0000 Subject: [PATCH 0336/1160] Update Windows instructions for using Github instead of svn --- Doc/Manual/Windows.html | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Doc/Manual/Windows.html b/Doc/Manual/Windows.html index 6349f355a..c94a3da3b 100644 --- a/Doc/Manual/Windows.html +++ b/Doc/Manual/Windows.html @@ -236,8 +236,8 @@ The short abbreviated instructions follow...

    -The step by step instructions to download and install MinGW and MSYS, then download and build the latest version of SWIG from SVN follow... -Note that the instructions for obtaining SWIG from SVN are also online at SWIG SVN. +The step by step instructions to download and install MinGW and MSYS, then download and build the latest version of SWIG from Github follow... +Note that the instructions for obtaining SWIG from Github are also online at SWIG Bleeding Edge.

    @@ -300,15 +300,19 @@ tar -zxf bison-2.0-MSYS.tar.gz

  • - To get the latest SWIG SVN (version from Subversion source control), type in the following: + The very latest development version of SWIG is available from SWIG on Github + and can be downloaded as a zip file or if you have Git installed, via Git. + Either download the latest Zip file snapshot and unzip and rename the top level folder to /usr/src/swig. + + Otherwise if using Git, type in the following:
     mkdir /usr/src
     cd /usr/src
    -svn co https://swig.svn.sourceforge.net/svnroot/swig/trunk swig
    +git clone https://github.com/swig/swig.git
     
    Pitfall note: -If you want to check out SWIG to a different folder to the proposed +If you want to place SWIG in a different folder to the proposed /usr/src/swig, do not use MSYS emulated windows drive letters, because the autotools will fail miserably on those.
  • From 382326bfbc65f90b2fef37884d2e5bf171c7400f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 3 Jan 2013 06:49:51 +0000 Subject: [PATCH 0337/1160] Bump version to 2.0.10 --- ANNOUNCE | 8 +- CHANGES | 155 +++++++++++++++++++++++++++++++++++++++ CHANGES.current | 155 +-------------------------------------- Doc/Manual/Sections.html | 2 +- README | 2 +- configure.in | 2 +- 6 files changed, 164 insertions(+), 160 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 8ac224247..1c3297a5c 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,8 +1,8 @@ -*** ANNOUNCE: SWIG 2.0.9 (16 December 2012) *** +*** ANNOUNCE: SWIG 2.0.10 (in progress) *** http://www.swig.org -We're pleased to announce SWIG-2.0.9, the latest SWIG release. +We're pleased to announce SWIG-2.0.10, 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.9.tar.gz + http://prdownloads.sourceforge.net/swig/swig-2.0.10.tar.gz A Windows version is also available at - http://prdownloads.sourceforge.net/swig/swigwin-2.0.9.zip + http://prdownloads.sourceforge.net/swig/swigwin-2.0.10.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 b485badd9..d6006a91a 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,161 @@ SWIG (Simplified Wrapper and Interface Generator) See the CHANGES.current file for changes in the current version. See the RELEASENOTES file for a summary of changes in each release. +Version 2.0.9 (16 December 2012) +================================ + +2012-12-16: wsfulton + Fix garbage line number / empty file name reporting for some missing + '}' or ')' error messages. + +2012-12-15: kkaempf + [Ruby] Apply patch 3530444, Class#methods and Class#constants returns array of + symbols in Ruby 1.9+ + +2012-12-14: kkaempf + [Ruby] Apply patch 3530439 and finally replace all occurences of the STR2CSTR() macro + with StringValuePtr(). STR2CSTR was deprecated since years and got removed in Ruby 1.9 + +2012-12-14: kkaempf + [Ruby] Applied patches #3530442 and 3530443 to adapt compile and runtime include + paths to match Ruby 1.9+ + +2012-12-14: wsfulton + [CFFI] Fix #3161614 - Some string constants are incorrect + +2012-12-13: wsfulton + [CFFI] Fix #3529690 - Fix incorrect constant names. + +2012-12-12: drjoe + [R] add fix to finalizer that was missed earlier + +2012-12-11: wsfulton + [Python] Apply patch #3590522 - fully qualified package paths for Python 3 even if a module is in the + same package. + +2012-12-08: wsfulton + [Python] Bug #3563647 - PyInt_FromSize_t unavailable prior to Python 2.5 for unsigned int types. + +2012-12-08: wsfulton + [Perl] Fix bug #3571361 - C++ comment in C wrappers. + +2012-12-07: wsfulton + [C#] Apply patch #3571029 which adds missing director support for const unsigned long long &. + +2012-11-28: kwwette + [Octave] Simplified module loading: now just the syntax + $ example; + is accepted, which loads functions globally but constants and variables relative to the current scope. + This make module loading behaviour reliably consistent, and reduces problems when loading modules which + depend on other modules which may not have been previously loaded. + +2012-11-27: wsfulton + [cffi] Fix junk output when wrapping single character literal constants. + +2012-11-17: wsfulton + [Tcl, Modula3] Add missing support for -outdir. + +2012-11-17: wsfulton + Fix segfaults when using filename paths greater than 1024 characters in length. + +2012-11-14: wsfulton + [ccache-swig] Apply patch #3586392 from Frederik Deweerdt to fix some error cases - incorrectly using + memory after it has been deleted. + +2012-11-09: vzeitlin + [Python] Fix overflow when passing values greater than LONG_MAX from Python 3 for parameters with unsigned long C type. + +2012-11-09: wsfulton + Fix some feature matching issues for implicit destructors and implicit constructors and implicit + copy constructors added with %copyctor. Previously a feature for these had to be fully qualified + in order to match. Now the following will also match: + + %feature("xyz") ~XXX(); + struct XXX {}; + +2012-11-09: wsfulton + Further consistency in named output typemap lookups for implicit constructors and destructors and + implicit copy constructors added with %copyctor. Previously only the fully qualified name was being + used, now the unqualified name will also be used. For example, previously: + + example.i:38: Searching for a suitable 'out' typemap for: void Space::More::~More + Looking for: void Space::More::~More + Looking for: void + + Now the unqualified name is also used: + + example.i:38: Searching for a suitable 'out' typemap for: void Space::More::~More + Looking for: void Space::More::~More + Looking for: void ~More + Looking for: void + +2012-11-02: wsfulton + Fix some subtle named output typemap lookup misses, the fully qualified name was not always being + used for variables, for example: + + struct Glob { + int MyVar; + }; + + Previously the search rules (as shown by -debug-tmsearch) for the getter wrapper were: + + example.i:44: Searching for a suitable 'out' typemap for: int MyVar + Looking for: int MyVar + Looking for: int + + Now the scope is named correctly: + + example.i:44: Searching for a suitable 'out' typemap for: int Glob::MyVar + Looking for: int Glob::MyVar + Looking for: int MyVar + Looking for: int + +2012-10-26: wsfulton + Fix director typemap searching so that a typemap specified with a name will be correctly matched. Previously + the name was ignored during the typemap search. Applies to the following list of typemaps: + directorout, csdirectorout, cstype, imtype, ctype, ddirectorout, dtype, gotype, jtype, jni, javadirectorout. + +2012-10-11: wsfulton + Most of the special variables available for use in %exception are now also available for expansion in + %extend blocks. These are: $name $symname $overname $decl $fulldecl $parentname $parentsymname, see docs + on "Class extension" in SWIGPlus.html. Patch based on submission from Kris Thielemans. + +2012-10-10: wsfulton + Additional new special variables in %exception are expanded as follows: + $parentname - The parent class name (if any) for a method. + $parentsymname - The target language parent class name (if any) for a method. + +2012-10-08: iant + [Go] Generating Go code now requires using the -intgosize option to + indicate the size of the 'int' type in Go. This is because the + size of the type is changing from Go 1.0 to Go 1.1 for x86_64. + +2012-09-14: wsfulton + Add new warning if the empty template instantiation is used as a base class, for example: + + template class Base {}; + %template() Base; + class Derived : public Base {}; + + gives the following warning instead of silently ignoring the base: + + cpp_inherit.i:52: Warning 401: Base class 'Base< int >' has no name as it is an empty template instantiated with '%template()'. Ignored. + cpp_inherit.i:51: Warning 401: The %template directive must be written before 'Base< int >' is used as a base class and be declared with a name. + + +2012-09-11: wsfulton + [Java] Fix #3535304 - Direct use of a weak global reference in directors + sometimes causing seg faults especially on Android. + +2012-09-06: wsfulton + [Java] Fix (char *STRING, size_t LENGTH) typemaps to accept NULL string. + +2012-08-26: drjoe + [R] make ExternalReference slot ref to contain reference + +2012-08-26: drjoe + [R] fix Examples/Makefile to use C in $(CC) rather than $(CXX) + Version 2.0.8 (20 August 2012) ============================== diff --git a/CHANGES.current b/CHANGES.current index c88bed34d..60e8235bb 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,157 +2,6 @@ Below are the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.9 (16 December 2012) -================================ +Version 2.0.10 (in progress) +============================ -2012-12-16: wsfulton - Fix garbage line number / empty file name reporting for some missing - '}' or ')' error messages. - -2012-12-15: kkaempf - [Ruby] Apply patch 3530444, Class#methods and Class#constants returns array of - symbols in Ruby 1.9+ - -2012-12-14: kkaempf - [Ruby] Apply patch 3530439 and finally replace all occurences of the STR2CSTR() macro - with StringValuePtr(). STR2CSTR was deprecated since years and got removed in Ruby 1.9 - -2012-12-14: kkaempf - [Ruby] Applied patches #3530442 and 3530443 to adapt compile and runtime include - paths to match Ruby 1.9+ - -2012-12-14: wsfulton - [CFFI] Fix #3161614 - Some string constants are incorrect - -2012-12-13: wsfulton - [CFFI] Fix #3529690 - Fix incorrect constant names. - -2012-12-12: drjoe - [R] add fix to finalizer that was missed earlier - -2012-12-11: wsfulton - [Python] Apply patch #3590522 - fully qualified package paths for Python 3 even if a module is in the - same package. - -2012-12-08: wsfulton - [Python] Bug #3563647 - PyInt_FromSize_t unavailable prior to Python 2.5 for unsigned int types. - -2012-12-08: wsfulton - [Perl] Fix bug #3571361 - C++ comment in C wrappers. - -2012-12-07: wsfulton - [C#] Apply patch #3571029 which adds missing director support for const unsigned long long &. - -2012-11-28: kwwette - [Octave] Simplified module loading: now just the syntax - $ example; - is accepted, which loads functions globally but constants and variables relative to the current scope. - This make module loading behaviour reliably consistent, and reduces problems when loading modules which - depend on other modules which may not have been previously loaded. - -2012-11-27: wsfulton - [cffi] Fix junk output when wrapping single character literal constants. - -2012-11-17: wsfulton - [Tcl, Modula3] Add missing support for -outdir. - -2012-11-17: wsfulton - Fix segfaults when using filename paths greater than 1024 characters in length. - -2012-11-14: wsfulton - [ccache-swig] Apply patch #3586392 from Frederik Deweerdt to fix some error cases - incorrectly using - memory after it has been deleted. - -2012-11-09: vzeitlin - [Python] Fix overflow when passing values greater than LONG_MAX from Python 3 for parameters with unsigned long C type. - -2012-11-09: wsfulton - Fix some feature matching issues for implicit destructors and implicit constructors and implicit - copy constructors added with %copyctor. Previously a feature for these had to be fully qualified - in order to match. Now the following will also match: - - %feature("xyz") ~XXX(); - struct XXX {}; - -2012-11-09: wsfulton - Further consistency in named output typemap lookups for implicit constructors and destructors and - implicit copy constructors added with %copyctor. Previously only the fully qualified name was being - used, now the unqualified name will also be used. For example, previously: - - example.i:38: Searching for a suitable 'out' typemap for: void Space::More::~More - Looking for: void Space::More::~More - Looking for: void - - Now the unqualified name is also used: - - example.i:38: Searching for a suitable 'out' typemap for: void Space::More::~More - Looking for: void Space::More::~More - Looking for: void ~More - Looking for: void - -2012-11-02: wsfulton - Fix some subtle named output typemap lookup misses, the fully qualified name was not always being - used for variables, for example: - - struct Glob { - int MyVar; - }; - - Previously the search rules (as shown by -debug-tmsearch) for the getter wrapper were: - - example.i:44: Searching for a suitable 'out' typemap for: int MyVar - Looking for: int MyVar - Looking for: int - - Now the scope is named correctly: - - example.i:44: Searching for a suitable 'out' typemap for: int Glob::MyVar - Looking for: int Glob::MyVar - Looking for: int MyVar - Looking for: int - -2012-10-26: wsfulton - Fix director typemap searching so that a typemap specified with a name will be correctly matched. Previously - the name was ignored during the typemap search. Applies to the following list of typemaps: - directorout, csdirectorout, cstype, imtype, ctype, ddirectorout, dtype, gotype, jtype, jni, javadirectorout. - -2012-10-11: wsfulton - Most of the special variables available for use in %exception are now also available for expansion in - %extend blocks. These are: $name $symname $overname $decl $fulldecl $parentname $parentsymname, see docs - on "Class extension" in SWIGPlus.html. Patch based on submission from Kris Thielemans. - -2012-10-10: wsfulton - Additional new special variables in %exception are expanded as follows: - $parentname - The parent class name (if any) for a method. - $parentsymname - The target language parent class name (if any) for a method. - -2012-10-08: iant - [Go] Generating Go code now requires using the -intgosize option to - indicate the size of the 'int' type in Go. This is because the - size of the type is changing from Go 1.0 to Go 1.1 for x86_64. - -2012-09-14: wsfulton - Add new warning if the empty template instantiation is used as a base class, for example: - - template class Base {}; - %template() Base; - class Derived : public Base {}; - - gives the following warning instead of silently ignoring the base: - - cpp_inherit.i:52: Warning 401: Base class 'Base< int >' has no name as it is an empty template instantiated with '%template()'. Ignored. - cpp_inherit.i:51: Warning 401: The %template directive must be written before 'Base< int >' is used as a base class and be declared with a name. - - -2012-09-11: wsfulton - [Java] Fix #3535304 - Direct use of a weak global reference in directors - sometimes causing seg faults especially on Android. - -2012-09-06: wsfulton - [Java] Fix (char *STRING, size_t LENGTH) typemaps to accept NULL string. - -2012-08-26: drjoe - [R] make ExternalReference slot ref to contain reference - -2012-08-26: drjoe - [R] fix Examples/Makefile to use C in $(CC) rather than $(CXX) diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index faff95298..9e4a3dd17 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

    SWIG-2.0 Documentation

    -Last update : SWIG-2.0.9 (16 December 2012) +Last update : SWIG-2.0.10 (in progress)

    Sections

    diff --git a/README b/README index 68a55e862..305edf078 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.9 (16 December 2012) +Version: 2.0.10 (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/configure.in b/configure.in index 0ead9b606..3927a102a 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.9],[http://www.swig.org]) +AC_INIT([swig],[2.0.10],[http://www.swig.org]) dnl NB: When this requirement is increased to 2.60 or later, AC_PROG_SED dnl definition below can be removed From c9174b3a166a0b123f0e6a3e69341d616d803eb6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 3 Jan 2013 07:25:07 +0000 Subject: [PATCH 0338/1160] More SVN->Git changes --- Doc/Manual/Extending.html | 4 ++-- Doc/Manual/Preface.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index c3b2740f4..ce205abf5 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -3536,7 +3536,7 @@ If you wish for a new language module to be distributed with SWIG, which we encourage for all popular languages, there are a few requirements. While we appreciate that getting all aspects of a new language working won't happen at the outset, there are a set of minimum requirements before -a module can be committed into the SVN repository for distribution with future +a module can be committed into the official Github repository for distribution with future versions of SWIG. The following are really a summary of this whole section with details being outlined earlier on.

    @@ -3578,7 +3578,7 @@ details being outlined earlier on.

    -Once accepted into SVN, development efforts should concentrate on +Once accepted into the official Git repository, development efforts should concentrate on getting the entire test-suite to work with plenty of runtime tests. Runtime tests should be for existing testcases and new test cases should be added should there be an area not already covered by diff --git a/Doc/Manual/Preface.html b/Doc/Manual/Preface.html index 2d0aa093e..58ab9dcb5 100644 --- a/Doc/Manual/Preface.html +++ b/Doc/Manual/Preface.html @@ -98,7 +98,7 @@ about this can be obtained at:

    From 60525e800d5ddcdbd41a859b23c9c7271b3d3a30 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 3 Jan 2013 14:09:14 -0600 Subject: [PATCH 0339/1160] Added a test case for SourceForge Bug #1283. This test case exercise directors used in conjunction with smart pointers. --- Examples/test-suite/common.mk | 1 + Examples/test-suite/director_smartptr.i | 63 +++++++++++++++++++ .../java/director_smartptr_runme.java | 48 ++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 Examples/test-suite/director_smartptr.i create mode 100644 Examples/test-suite/java/director_smartptr_runme.java diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 0c790caf6..1cda06140 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -185,6 +185,7 @@ CPP_TEST_CASES += \ director_protected \ director_protected_overloaded \ director_redefined \ + director_smartptr \ director_thread \ director_unroll \ director_using \ diff --git a/Examples/test-suite/director_smartptr.i b/Examples/test-suite/director_smartptr.i new file mode 100644 index 000000000..0d78c2775 --- /dev/null +++ b/Examples/test-suite/director_smartptr.i @@ -0,0 +1,63 @@ +%module(directors="1") director_smartptr + +#ifdef SWIGJAVA +SWIG_JAVABODY_PROXY(public, public, SWIGTYPE) +SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE) +#endif + +%{ +#include +#include + +class FooBar { +public: + FooBar() {} + FooBar(const FooBar&) {} + virtual ~FooBar() {} + + std::string FooBarDo() { return "Bar::Foo2::Foo2Bar()"; } +}; + +class Foo { +public: + virtual ~Foo() {} + virtual std::string ping() { return "Foo::ping()"; } + virtual std::string pong() { return "Foo::pong();" + ping(); } + virtual std::string fooBar(FooBar* fooBarPtr) { return fooBarPtr->FooBarDo(); } + virtual Foo makeFoo() { return Foo(); } + virtual FooBar makeFooBar() { return FooBar(); } + + static Foo* get_self(Foo *self_) {return self_;} +}; + +%} + +%include +%include + +%shared_ptr(Foo) + +%feature("director") Foo; + +class FooBar { +public: + FooBar(); + FooBar(const FooBar&); + virtual ~FooBar(); + + std::string FooBarDo(); + +}; + +class Foo +{ +public: + virtual ~Foo(); + virtual std::string ping(); + virtual std::string pong(); + virtual std::string fooBar(FooBar* fooBarPtr); + virtual Foo makeFoo(); + virtual FooBar makeFooBar(); + + static Foo* get_self(Foo *self_); +}; \ No newline at end of file diff --git a/Examples/test-suite/java/director_smartptr_runme.java b/Examples/test-suite/java/director_smartptr_runme.java new file mode 100644 index 000000000..8c4ddc5d3 --- /dev/null +++ b/Examples/test-suite/java/director_smartptr_runme.java @@ -0,0 +1,48 @@ +// Make sure that directors are connected and disconnected when used inconjunction with +// being a smart pointer + +public class director_smartptr_runme { + + static { + try { + System.loadLibrary("director_smartptr"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + director_smartptr_MyBarFoo myBarFoo = + new director_smartptr_MyBarFoo(); + } + +} + +class director_smartptr_MyBarFoo extends director_smartptr.Foo { + + @Override + public String ping() { + return "director_smartptr_MyBarFoo.ping();"; + } + + @Override + public String pong() { + return "director_smartptr_MyBarFoo.pong();" + ping(); + } + + @Override + public String fooBar(director_smartptr.FooBar fooBar) { + return fooBar.FooBarDo(); + } + + @Override + public director_smartptr.Foo makeFoo() { + return new director_smartptr.Foo(); + } + + @Override + public director_smartptr.FooBar makeFooBar() { + return new director_smartptr.FooBar(); + } +} \ No newline at end of file From 3e2c6bb03d07a7cbe004be91d29f711339a61e9e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 3 Jan 2013 20:49:10 +0000 Subject: [PATCH 0340/1160] director_nspace fixes for C# for previous commit --- CHANGES.current | 3 +++ Examples/test-suite/csharp/director_nspace_runme.cs | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 60e8235bb..a043d3348 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.10 (in progress) ============================ +2013-01-03: wsfulton + Pull patch from BrantKyser to fix directors and nspace feature when multilevel namespaces are used. + diff --git a/Examples/test-suite/csharp/director_nspace_runme.cs b/Examples/test-suite/csharp/director_nspace_runme.cs index 8126535eb..b1e2b47f5 100644 --- a/Examples/test-suite/csharp/director_nspace_runme.cs +++ b/Examples/test-suite/csharp/director_nspace_runme.cs @@ -8,7 +8,7 @@ public class bools_runme { } } -class director_nspace_MyBarFoo : director_nspaceNamespace.Bar.Foo { +class director_nspace_MyBarFoo : director_nspaceNamespace.TopLevel.Bar.Foo { public override String ping() { return "director_nspace_MyBarFoo.ping();"; @@ -18,15 +18,15 @@ class director_nspace_MyBarFoo : director_nspaceNamespace.Bar.Foo { return "director_nspace_MyBarFoo.pong();" + ping(); } - public override String fooBar(director_nspaceNamespace.Bar.FooBar fooBar) { + public override String fooBar(director_nspaceNamespace.TopLevel.Bar.FooBar fooBar) { return fooBar.FooBarDo(); } - public override director_nspaceNamespace.Bar.Foo makeFoo() { - return new director_nspaceNamespace.Bar.Foo(); + public override director_nspaceNamespace.TopLevel.Bar.Foo makeFoo() { + return new director_nspaceNamespace.TopLevel.Bar.Foo(); } - public override director_nspaceNamespace.Bar.FooBar makeFooBar() { - return new director_nspaceNamespace.Bar.FooBar(); + public override director_nspaceNamespace.TopLevel.Bar.FooBar makeFooBar() { + return new director_nspaceNamespace.TopLevel.Bar.FooBar(); } } From 3e70da14c96072618a58a169a4ccb2f7d799d98e Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 3 Jan 2013 14:54:06 -0600 Subject: [PATCH 0341/1160] Fix for SourceForge Bug #1283. * Change the name of the memory own variable for base java director classes to match that expected by the director code * Add conditional to appropriately dynamically cast director classes wrapped in smart pointers. --- Lib/java/boost_shared_ptr.i | 8 ++++---- Source/Modules/java.cxx | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Lib/java/boost_shared_ptr.i b/Lib/java/boost_shared_ptr.i index 31d7efdf9..e75236993 100644 --- a/Lib/java/boost_shared_ptr.i +++ b/Lib/java/boost_shared_ptr.i @@ -146,10 +146,10 @@ // Base proxy classes %typemap(javabody) TYPE %{ private long swigCPtr; - private boolean swigCMemOwnBase; + private boolean swigCMemOwn; PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { - swigCMemOwnBase = cMemoryOwn; + swigCMemOwn = cMemoryOwn; swigCPtr = cPtr; } @@ -176,8 +176,8 @@ %typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE { if (swigCPtr != 0) { - if (swigCMemOwnBase) { - swigCMemOwnBase = false; + if (swigCMemOwn) { + swigCMemOwn = false; $jnicall; } swigCPtr = 0; diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index cd8cfe543..1f7fa29ce 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3381,6 +3381,7 @@ public: 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"); + String *smartptr_feature = Getattr(n, "feature:smartptr"); Wrapper *code_wrap; Printf(imclass_class_code, " public final static native void %s(%s obj, long cptr, boolean mem_own, boolean weak_global);\n", @@ -3390,9 +3391,24 @@ public: Printf(code_wrap->def, "SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jswig_mem_own, " "jboolean jweak_global) {\n", jnipackage, jni_imclass_name, swig_director_connect_jni); - Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name); - Printf(code_wrap->code, " (void)jcls;\n"); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name); + + if (Len(smartptr_feature)) { + Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", smartptr_feature, smartptr_feature); + Printf(code_wrap->code, " (void)jcls;\n"); + Printf(code_wrap->code, " // NOTE: Pulling the raw pointer out of the smart pointer as the following code does\n"); + Printf(code_wrap->code, " // is generally a bad idea. However, in this case we keep a local instance of the\n"); + Printf(code_wrap->code, " // smart pointer around while we are using the raw pointer, which should keep the\n"); + Printf(code_wrap->code, " // raw pointer alive. This is done instead of using the smart pointer's dynamic cast\n"); + Printf(code_wrap->code, " // feature since different smart pointer implementations have differently named dynamic\n"); + Printf(code_wrap->code, " // cast mechanisms.\n"); + Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast< SwigDirector_%s *>(obj->operator->());\n", sym_name, sym_name); + } + else { + Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name); + Printf(code_wrap->code, " (void)jcls;\n"); + Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name); + } + Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_connect_director(jenv, jself, jenv->GetObjectClass(jself), " "(jswig_mem_own == JNI_TRUE), (jweak_global == JNI_TRUE));\n"); From f0e47b81d69b36eb741acbe8e71a440937515b85 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 3 Jan 2013 14:09:14 -0600 Subject: [PATCH 0342/1160] Added a test case for SourceForge Bug #1283. This test case exercise directors used in conjunction with smart pointers. --- Examples/test-suite/common.mk | 1 + Examples/test-suite/director_smartptr.i | 63 +++++++++++++++++++ .../java/director_smartptr_runme.java | 48 ++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 Examples/test-suite/director_smartptr.i create mode 100644 Examples/test-suite/java/director_smartptr_runme.java diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 0c790caf6..1cda06140 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -185,6 +185,7 @@ CPP_TEST_CASES += \ director_protected \ director_protected_overloaded \ director_redefined \ + director_smartptr \ director_thread \ director_unroll \ director_using \ diff --git a/Examples/test-suite/director_smartptr.i b/Examples/test-suite/director_smartptr.i new file mode 100644 index 000000000..0d78c2775 --- /dev/null +++ b/Examples/test-suite/director_smartptr.i @@ -0,0 +1,63 @@ +%module(directors="1") director_smartptr + +#ifdef SWIGJAVA +SWIG_JAVABODY_PROXY(public, public, SWIGTYPE) +SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE) +#endif + +%{ +#include +#include + +class FooBar { +public: + FooBar() {} + FooBar(const FooBar&) {} + virtual ~FooBar() {} + + std::string FooBarDo() { return "Bar::Foo2::Foo2Bar()"; } +}; + +class Foo { +public: + virtual ~Foo() {} + virtual std::string ping() { return "Foo::ping()"; } + virtual std::string pong() { return "Foo::pong();" + ping(); } + virtual std::string fooBar(FooBar* fooBarPtr) { return fooBarPtr->FooBarDo(); } + virtual Foo makeFoo() { return Foo(); } + virtual FooBar makeFooBar() { return FooBar(); } + + static Foo* get_self(Foo *self_) {return self_;} +}; + +%} + +%include +%include + +%shared_ptr(Foo) + +%feature("director") Foo; + +class FooBar { +public: + FooBar(); + FooBar(const FooBar&); + virtual ~FooBar(); + + std::string FooBarDo(); + +}; + +class Foo +{ +public: + virtual ~Foo(); + virtual std::string ping(); + virtual std::string pong(); + virtual std::string fooBar(FooBar* fooBarPtr); + virtual Foo makeFoo(); + virtual FooBar makeFooBar(); + + static Foo* get_self(Foo *self_); +}; \ No newline at end of file diff --git a/Examples/test-suite/java/director_smartptr_runme.java b/Examples/test-suite/java/director_smartptr_runme.java new file mode 100644 index 000000000..8c4ddc5d3 --- /dev/null +++ b/Examples/test-suite/java/director_smartptr_runme.java @@ -0,0 +1,48 @@ +// Make sure that directors are connected and disconnected when used inconjunction with +// being a smart pointer + +public class director_smartptr_runme { + + static { + try { + System.loadLibrary("director_smartptr"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + director_smartptr_MyBarFoo myBarFoo = + new director_smartptr_MyBarFoo(); + } + +} + +class director_smartptr_MyBarFoo extends director_smartptr.Foo { + + @Override + public String ping() { + return "director_smartptr_MyBarFoo.ping();"; + } + + @Override + public String pong() { + return "director_smartptr_MyBarFoo.pong();" + ping(); + } + + @Override + public String fooBar(director_smartptr.FooBar fooBar) { + return fooBar.FooBarDo(); + } + + @Override + public director_smartptr.Foo makeFoo() { + return new director_smartptr.Foo(); + } + + @Override + public director_smartptr.FooBar makeFooBar() { + return new director_smartptr.FooBar(); + } +} \ No newline at end of file From 540ede0dd36896f0c26ee0f1cbd7ba705db8eacc Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 3 Jan 2013 14:54:06 -0600 Subject: [PATCH 0343/1160] Fix for SourceForge Bug #1283. * Change the name of the memory own variable for base java director classes to match that expected by the director code * Add conditional to appropriately dynamically cast director classes wrapped in smart pointers. --- Lib/java/boost_shared_ptr.i | 8 ++++---- Source/Modules/java.cxx | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Lib/java/boost_shared_ptr.i b/Lib/java/boost_shared_ptr.i index 31d7efdf9..e75236993 100644 --- a/Lib/java/boost_shared_ptr.i +++ b/Lib/java/boost_shared_ptr.i @@ -146,10 +146,10 @@ // Base proxy classes %typemap(javabody) TYPE %{ private long swigCPtr; - private boolean swigCMemOwnBase; + private boolean swigCMemOwn; PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { - swigCMemOwnBase = cMemoryOwn; + swigCMemOwn = cMemoryOwn; swigCPtr = cPtr; } @@ -176,8 +176,8 @@ %typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE { if (swigCPtr != 0) { - if (swigCMemOwnBase) { - swigCMemOwnBase = false; + if (swigCMemOwn) { + swigCMemOwn = false; $jnicall; } swigCPtr = 0; diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 971e60659..dbe569643 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3381,6 +3381,7 @@ public: 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"); + String *smartptr_feature = Getattr(n, "feature:smartptr"); Wrapper *code_wrap; Printf(imclass_class_code, " public final static native void %s(%s obj, long cptr, boolean mem_own, boolean weak_global);\n", @@ -3390,9 +3391,24 @@ public: Printf(code_wrap->def, "SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jswig_mem_own, " "jboolean jweak_global) {\n", jnipackage, jni_imclass_name, swig_director_connect_jni); - Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name); - Printf(code_wrap->code, " (void)jcls;\n"); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name); + + if (Len(smartptr_feature)) { + Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", smartptr_feature, smartptr_feature); + Printf(code_wrap->code, " (void)jcls;\n"); + Printf(code_wrap->code, " // NOTE: Pulling the raw pointer out of the smart pointer as the following code does\n"); + Printf(code_wrap->code, " // is generally a bad idea. However, in this case we keep a local instance of the\n"); + Printf(code_wrap->code, " // smart pointer around while we are using the raw pointer, which should keep the\n"); + Printf(code_wrap->code, " // raw pointer alive. This is done instead of using the smart pointer's dynamic cast\n"); + Printf(code_wrap->code, " // feature since different smart pointer implementations have differently named dynamic\n"); + Printf(code_wrap->code, " // cast mechanisms.\n"); + Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast< SwigDirector_%s *>(obj->operator->());\n", sym_name, sym_name); + } + else { + Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name); + Printf(code_wrap->code, " (void)jcls;\n"); + Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name); + } + Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_connect_director(jenv, jself, jenv->GetObjectClass(jself), " "(jswig_mem_own == JNI_TRUE), (jweak_global == JNI_TRUE));\n"); From f6ce5f089f2f782a0987876737c47c7adb69ab3f Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 3 Jan 2013 21:26:08 -0600 Subject: [PATCH 0344/1160] Qualify generated SwigDirector class names with namespaces --- Source/Modules/directors.cxx | 9 ++++--- Source/Modules/java.cxx | 50 +++++++++++++----------------------- Source/Modules/lang.cxx | 20 ++++++++++++++- Source/Modules/swigmod.h | 2 ++ Source/Swig/cwrap.c | 12 +++++++-- 5 files changed, 55 insertions(+), 38 deletions(-) diff --git a/Source/Modules/directors.cxx b/Source/Modules/directors.cxx index 7f4c8d9d1..5d88b6306 100644 --- a/Source/Modules/directors.cxx +++ b/Source/Modules/directors.cxx @@ -78,9 +78,10 @@ String *Swig_class_name(Node *n) { String *Swig_director_declaration(Node *n) { String *classname = Swig_class_name(n); - String *directorname = NewStringf("SwigDirector_%s", classname); + String *directorname = Language::instance()->directorClassName(n); String *base = Getattr(n, "classtype"); String *declaration = Swig_class_declaration(n, directorname); + Printf(declaration, " : public %s, public Swig::Director {\n", base); Delete(classname); Delete(directorname); @@ -281,8 +282,10 @@ void Swig_director_emit_dynamic_cast(Node *n, Wrapper *f) { && !Equal(nodeType(n), "constructor"))) { Node *parent = Getattr(n, "parentNode"); String *symname = Getattr(parent, "sym:name"); - String *dirname = NewStringf("SwigDirector_%s", symname); - String *dirdecl = NewStringf("%s *darg = 0", dirname); + String *dirname; + String *dirdecl; + dirname = Language::instance()->directorClassName(parent); + dirdecl = NewStringf("%s *darg = 0", dirname); Wrapper_add_local(f, "darg", dirdecl); Printf(f->code, "darg = dynamic_cast<%s *>(arg1);\n", dirname); Delete(dirname); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 1f7fa29ce..c642387dc 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -204,24 +204,6 @@ public: return valid_jni_name; } - /* ----------------------------------------------------------------------------- - * directorClassName() - * ----------------------------------------------------------------------------- */ - - String *directorClassName(Node *n) { - String *dirclassname; - const char *attrib = "director:classname"; - - if (!(dirclassname = Getattr(n, attrib))) { - String *classname = Getattr(n, "sym:name"); - - dirclassname = NewStringf("SwigDirector_%s", classname); - Setattr(n, attrib, dirclassname); - } - - return dirclassname; - } - /* ------------------------------------------------------------ * main() * ------------------------------------------------------------ */ @@ -2008,7 +1990,7 @@ public: Printf(dcast_wrap->code, " jobject jresult = (jobject) 0;\n"); Printf(dcast_wrap->code, " %s *obj = *((%s **)&jCPtrBase);\n", norm_name, norm_name); Printf(dcast_wrap->code, " if (obj) director = dynamic_cast(obj);\n"); - Printf(dcast_wrap->code, " if (director) jresult = director->swig_get_self(jenv);\n"); + Printf(dcast_wrap->code, " if (director) jresult = director->swig_get_self);\n"); Printf(dcast_wrap->code, " return jresult;\n"); Printf(dcast_wrap->code, "}\n"); @@ -3380,8 +3362,8 @@ public: String *norm_name = SwigType_namestr(Getattr(n, "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"); String *smartptr_feature = Getattr(n, "feature:smartptr"); + String *dirClassName = directorClassName(n); Wrapper *code_wrap; Printf(imclass_class_code, " public final static native void %s(%s obj, long cptr, boolean mem_own, boolean weak_global);\n", @@ -3401,12 +3383,12 @@ public: Printf(code_wrap->code, " // raw pointer alive. This is done instead of using the smart pointer's dynamic cast\n"); Printf(code_wrap->code, " // feature since different smart pointer implementations have differently named dynamic\n"); Printf(code_wrap->code, " // cast mechanisms.\n"); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast< SwigDirector_%s *>(obj->operator->());\n", sym_name, sym_name); + Printf(code_wrap->code, " %s *director = dynamic_cast< %s *>(obj->operator->());\n", dirClassName, dirClassName); } else { Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name); Printf(code_wrap->code, " (void)jcls;\n"); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name); + Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName); } Printf(code_wrap->code, " if (director) {\n"); @@ -3432,7 +3414,7 @@ public: "SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jtake_or_release) {\n", jnipackage, jni_imclass_name, changeown_jnimethod_name); 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); + Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName); Printf(code_wrap->code, " (void)jcls;\n"); Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_java_change_ownership(jenv, jself, jtake_or_release ? true : false);\n"); @@ -3445,6 +3427,7 @@ public: Delete(changeown_method_name); Delete(changeown_jnimethod_name); Delete(norm_name); + Delete(dirClassName); Delete(jni_imclass_name); } @@ -3583,7 +3566,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(getNSpace(), classname, overloaded_name)); + imclass_dmethod = NewStringf("%s", Swig_name_member(getNSpace(), dirclassname, overloaded_name)); qualified_return = SwigType_rcaststr(returntype, "c_result"); @@ -4182,16 +4165,18 @@ public: int classDirectorDefaultConstructor(Node *n) { String *classname = Swig_class_name(n); String *classtype = SwigType_namestr(Getattr(n, "name")); + String *dirClassName = directorClassName(n); Wrapper *w = NewWrapper(); - Printf(w->def, "SwigDirector_%s::SwigDirector_%s(JNIEnv *jenv) : %s {", classname, classname, Getattr(n, "director:ctor")); + Printf(w->def, "%s::%s(JNIEnv *jenv) : %s {", dirClassName, dirClassName, Getattr(n, "director:ctor")); Printf(w->code, "}\n"); Wrapper_print(w, f_directors); - Printf(f_directors_h, " SwigDirector_%s(JNIEnv *jenv);\n", classname); + Printf(f_directors_h, " %s(JNIEnv *jenv);\n", dirClassName); DelWrapper(w); Delete(classtype); Delete(classname); + Delete(dirClassName); directorPrefixArgs(n); return Language::classDirectorDefaultConstructor(n); } @@ -4228,14 +4213,15 @@ public: Node *current_class = getCurrentClass(); String *full_classname = Getattr(current_class, "name"); String *classname = Swig_class_name(current_class); + String *dirClassName = directorClassName(current_class); Wrapper *w = NewWrapper(); if (Getattr(n, "throw")) { - Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s() throw ();\n", dirClassName); + Printf(w->def, "%s::~%s() throw () {\n", dirClassName, dirClassName); } else { - Printf(f_directors_h, " virtual ~SwigDirector_%s();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s();\n", dirClassName); + Printf(w->def, "%s::~%s() {\n", dirClassName, dirClassName); } /* Ensure that correct directordisconnect typemap's method name is called @@ -4254,6 +4240,7 @@ public: DelWrapper(w); Delete(disconn_attr); Delete(classname); + Delete(dirClassName); return SWIG_OK; } @@ -4395,8 +4382,7 @@ public: String *base = Getattr(n, "classtype"); String *class_ctor = NewString("Swig::Director(jenv)"); - String *classname = Swig_class_name(n); - String *directorname = NewStringf("SwigDirector_%s", classname); + String *directorname = directorClassName(n); String *declaration = Swig_class_declaration(n, directorname); Printf(declaration, " : public %s, public Swig::Director", base); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 8e5a91dbe..410945592 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -347,6 +347,24 @@ Language::~Language() { this_ = 0; } + /* ----------------------------------------------------------------------------- + * directorClassName() + * ----------------------------------------------------------------------------- */ + + String *Language::directorClassName(Node *n) { + String *dirclassname; + String *nspace = Getattr(n, "sym:nspace"); + const char *attrib = "director:classname"; + String *classname = Getattr(n, "sym:name"); + + Replace(nspace, ".", "_", DOH_REPLACE_ANY); + dirclassname = NewStringf("SwigDirector_%s_%s", nspace, classname); + Setattr(n, attrib, dirclassname); + + Delete(nspace); + return dirclassname; + } + /* ---------------------------------------------------------------------- emit_one() ---------------------------------------------------------------------- */ @@ -2405,7 +2423,7 @@ int Language::classDeclaration(Node *n) { } if (dir) { - DirectorClassName = NewStringf("SwigDirector_%s", symname); + DirectorClassName = directorClassName(n); classDirector(n); } /* check for abstract after resolving directors */ diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 4a65444fc..b3722af40 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -120,6 +120,8 @@ public: virtual ~Language(); virtual int emit_one(Node *n); + String *directorClassName(Node *n); + /* Parse command line options */ virtual void main(int argc, char *argv[]); diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 063ab9858..d47f072e7 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -855,6 +855,9 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas String *self = 0; int is_smart_pointer_overload = 0; String *qualifier = Getattr(n, "qualifier"); + String *directorScope = NewString(nspace); + + Replace(directorScope, ".", "_", DOH_REPLACE_ANY); /* If smart pointer without const overload or mutable method, change self dereferencing */ if (flags & CWRAP_SMART_POINTER) { @@ -937,7 +940,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas /* If protected access (can only be if a director method) then call the extra public accessor method (language module must provide this) */ String *explicit_qualifier_tmp = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname")); explicitcall_name = NewStringf("%sSwigPublic", name); - explicit_qualifier = NewStringf("SwigDirector_%s", explicit_qualifier_tmp); + explicit_qualifier = NewStringf("SwigDirector_%s_%s", directorScope, explicit_qualifier_tmp); Delete(explicit_qualifier_tmp); } else { explicit_qualifier = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname")); @@ -1057,6 +1060,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas Delete(p); Delete(self); Delete(parms); + Delete(directorScope); return SWIG_OK; } @@ -1107,6 +1111,9 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String ParmList *directorparms; SwigType *type; int use_director; + String *directorScope = NewString(nspace); + + Replace(directorScope, ".", "_", DOH_REPLACE_ANY); use_director = Swig_directorclass(n); @@ -1167,7 +1174,7 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String Node *parent = Swig_methodclass(n); int abstract = Getattr(parent, "abstracts") != 0; String *name = Getattr(parent, "sym:name"); - String *directorname = NewStringf("SwigDirector_%s", name); + String *directorname = NewStringf("SwigDirector_%s_%s", directorScope, name); String *action = NewStringEmpty(); String *tmp_none_comparison = Copy(none_comparison); String *director_call; @@ -1233,6 +1240,7 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String if (directorparms != parms) Delete(directorparms); Delete(parms); + Delete(directorScope); return SWIG_OK; } From 00c71edbedc8412c90daec57a59936b79acd626c Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 3 Jan 2013 23:09:29 -0600 Subject: [PATCH 0345/1160] Change test to reflect new director class naming convention. --- Examples/test-suite/java_director_assumeoverride.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/java_director_assumeoverride.i b/Examples/test-suite/java_director_assumeoverride.i index 7364a3d58..310a20e0c 100644 --- a/Examples/test-suite/java_director_assumeoverride.i +++ b/Examples/test-suite/java_director_assumeoverride.i @@ -10,7 +10,7 @@ public: #include "java_director_assumeoverride_wrap.h" bool isFuncOverridden(OverrideMe* f) { - SwigDirector_OverrideMe* director = dynamic_cast(f); + SwigDirector__OverrideMe* director = dynamic_cast(f); if (!director) { return false; } From 747b50e2d7f43c73214867c9821dccef786b3107 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 3 Jan 2013 23:10:28 -0600 Subject: [PATCH 0346/1160] Clean up fix for SourceForge Bug #1299. --- Source/Modules/directors.cxx | 1 - Source/Modules/lang.cxx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Modules/directors.cxx b/Source/Modules/directors.cxx index 5d88b6306..4b23a52bb 100644 --- a/Source/Modules/directors.cxx +++ b/Source/Modules/directors.cxx @@ -281,7 +281,6 @@ void Swig_director_emit_dynamic_cast(Node *n, Wrapper *f) { checkAttribute(n, "storage", "static")) && !Equal(nodeType(n), "constructor"))) { Node *parent = Getattr(n, "parentNode"); - String *symname = Getattr(parent, "sym:name"); String *dirname; String *dirdecl; dirname = Language::instance()->directorClassName(parent); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 410945592..b7ce2c4a8 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -353,7 +353,7 @@ Language::~Language() { String *Language::directorClassName(Node *n) { String *dirclassname; - String *nspace = Getattr(n, "sym:nspace"); + String *nspace = NewString(Getattr(n, "sym:nspace")); const char *attrib = "director:classname"; String *classname = Getattr(n, "sym:name"); From da00bdb12dba1383983a62a385da6aa1036d12e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Fri, 4 Jan 2013 15:43:44 +0100 Subject: [PATCH 0347/1160] added python test case li_std_except_as_class for SF bug 1295 --- Examples/test-suite/common.mk | 1 + Examples/test-suite/li_std_except_as_class.i | 19 +++++++++++++++++++ .../python/li_std_except_as_class_runme.py | 9 +++++++++ 3 files changed, 29 insertions(+) create mode 100644 Examples/test-suite/li_std_except_as_class.i create mode 100644 Examples/test-suite/python/li_std_except_as_class_runme.py diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 0c790caf6..4ba669497 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -480,6 +480,7 @@ CPP_STD_TEST_CASES += \ li_std_combinations \ li_std_deque \ li_std_except \ + li_std_except_as_class \ li_std_map \ li_std_pair \ li_std_pair_using \ diff --git a/Examples/test-suite/li_std_except_as_class.i b/Examples/test-suite/li_std_except_as_class.i new file mode 100644 index 000000000..00de76eac --- /dev/null +++ b/Examples/test-suite/li_std_except_as_class.i @@ -0,0 +1,19 @@ +/* File : li_std_except_as_class.i */ +%module li_std_except_as_class + +/* NOTE: SF bug 1295: + * if there were also functions throwing 'std::logic_error' and + * 'std::exception' then the bug would not be fully replicated */ + +%{ +#include +#include +void test_domain_error() throw(std::domain_error) +{ throw std::domain_error("std::domain_error"); } +%} + +%include +#define SWIG_STD_EXCEPTIONS_AS_CLASSES +%include +void test_domain_error() throw(std::domain_error) +{ throw std::domain_error("std::domain_error"); } diff --git a/Examples/test-suite/python/li_std_except_as_class_runme.py b/Examples/test-suite/python/li_std_except_as_class_runme.py new file mode 100644 index 000000000..386a878bf --- /dev/null +++ b/Examples/test-suite/python/li_std_except_as_class_runme.py @@ -0,0 +1,9 @@ +from li_std_except_as_class import * + +# std::domain_error hierarchy +try: test_domain_error() +except domain_error: pass +try: test_domain_error() +except logic_error: pass +try: test_domain_error() +except exception: pass From a6f733602e56a00f91deedb86d0b5a02b37a99a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Fri, 4 Jan 2013 16:57:04 +0100 Subject: [PATCH 0348/1160] added patch for SF bug #1295 --- Lib/typemaps/std_except.swg | 62 +------------------------------------ 1 file changed, 1 insertion(+), 61 deletions(-) diff --git a/Lib/typemaps/std_except.swg b/Lib/typemaps/std_except.swg index 3ce479a50..cb5ed3050 100644 --- a/Lib/typemaps/std_except.swg +++ b/Lib/typemaps/std_except.swg @@ -1,5 +1,4 @@ %include -%include /* Mark all of std exception classes as "exception classes" via @@ -34,63 +33,4 @@ namespace std { %std_exception_map(underflow_error, SWIG_OverflowError); } -#if defined(SWIG_STD_EXCEPTIONS_AS_CLASSES) - -namespace std { - struct exception - { - virtual ~exception() throw(); - virtual const char* what() const throw(); - }; - - struct bad_exception : exception - { - }; - - struct logic_error : exception - { - logic_error(const string& msg); - }; - - struct domain_error : logic_error - { - domain_error(const string& msg); - }; - - struct invalid_argument : logic_error - { - invalid_argument(const string& msg); - }; - - struct length_error : logic_error - { - length_error(const string& msg); - }; - - struct out_of_range : logic_error - { - out_of_range(const string& msg); - }; - - struct runtime_error : exception - { - runtime_error(const string& msg); - }; - - struct range_error : runtime_error - { - range_error(const string& msg); - }; - - struct overflow_error : runtime_error - { - overflow_error(const string& msg); - }; - - struct underflow_error : runtime_error - { - underflow_error(const string& msg); - }; -} - -#endif +%include From 2bb6a8c4a82670a590d45ba0555ac073100459e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Fri, 4 Jan 2013 18:20:19 +0100 Subject: [PATCH 0349/1160] added test case for SF bug #1296 --- Examples/test-suite/common.mk | 1 + .../template_default_arg_virtual_destructor.i | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 Examples/test-suite/template_default_arg_virtual_destructor.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 0c790caf6..f29374df6 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -355,6 +355,7 @@ CPP_TEST_CASES += \ template_default \ template_default2 \ template_default_arg \ + template_default_arg_virtual_destructor \ template_default_class_parms \ template_default_class_parms_typedef \ template_default_inherit \ diff --git a/Examples/test-suite/template_default_arg_virtual_destructor.i b/Examples/test-suite/template_default_arg_virtual_destructor.i new file mode 100644 index 000000000..c56c29bc6 --- /dev/null +++ b/Examples/test-suite/template_default_arg_virtual_destructor.i @@ -0,0 +1,24 @@ +%module template_default_arg_virtual_destructor + +// SF bug #1296: +// virtual destructor in template class (template specification having +// default parameter(s)) triggers the warnint "illegal destructor name" + +%inline %{ +struct A {}; + +template + struct B + { + B(T const&) {} + virtual ~B() {} + }; +template + struct B + { + B(int,int) {} // constructor specific to this partial specialization + virtual ~B() {} // "illegal destructor name" when ~B() is virtual + }; +%} +%template(B_AF) B; +%template(B_A) B; // this instantiation triggert the warning From 02246d7294fb7d20f5b42e3cbec9719f3d918039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Fri, 4 Jan 2013 18:24:57 +0100 Subject: [PATCH 0350/1160] applied patch for SF bug #1296 --- Source/CParse/parser.y | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 0d7c65f85..e4f3d67b2 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -4472,17 +4472,7 @@ cpp_destructor_decl : NOT idtemplate LPAREN parms RPAREN cpp_end { | VIRTUAL NOT idtemplate LPAREN parms RPAREN cpp_vend { String *name; - char *c = 0; $$ = new_node("destructor"); - /* Check for template names. If the class is a template - and the constructor is missing the template part, we - add it */ - if (Classprefix) { - c = strchr(Char(Classprefix),'<'); - if (c && !Strchr($3,'<')) { - $3 = NewStringf("%s%s",$3,c); - } - } Setattr($$,"storage","virtual"); name = NewStringf("%s",$3); if (*(Char(name)) != '~') Insert(name,0,"~"); From 8e418d61e6414fe2659b647d609515e15c5fe495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Fri, 4 Jan 2013 18:41:10 +0100 Subject: [PATCH 0351/1160] corrected some typos --- Examples/test-suite/common.mk | 2 +- Examples/test-suite/template_default_arg_virtual_destructor.i | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index f29374df6..b39416ac9 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -355,7 +355,7 @@ CPP_TEST_CASES += \ template_default \ template_default2 \ template_default_arg \ - template_default_arg_virtual_destructor \ + template_default_arg_virtual_destructor \ template_default_class_parms \ template_default_class_parms_typedef \ template_default_inherit \ diff --git a/Examples/test-suite/template_default_arg_virtual_destructor.i b/Examples/test-suite/template_default_arg_virtual_destructor.i index c56c29bc6..319d5b837 100644 --- a/Examples/test-suite/template_default_arg_virtual_destructor.i +++ b/Examples/test-suite/template_default_arg_virtual_destructor.i @@ -2,7 +2,7 @@ // SF bug #1296: // virtual destructor in template class (template specification having -// default parameter(s)) triggers the warnint "illegal destructor name" +// default parameter(s)) triggers the warning "illegal destructor name" %inline %{ struct A {}; From 328d6d01bb3011fc0f414e681fc76f9e2e830453 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 4 Jan 2013 20:35:13 +0000 Subject: [PATCH 0352/1160] Cosmetic whitespace change --- Source/Modules/java.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index dbe569643..0b34d10e7 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3401,7 +3401,7 @@ public: Printf(code_wrap->code, " // raw pointer alive. This is done instead of using the smart pointer's dynamic cast\n"); Printf(code_wrap->code, " // feature since different smart pointer implementations have differently named dynamic\n"); Printf(code_wrap->code, " // cast mechanisms.\n"); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast< SwigDirector_%s *>(obj->operator->());\n", sym_name, sym_name); + Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj->operator->());\n", sym_name, sym_name); } else { Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name); From 078daa5b57a4c92a8d49614716aaede389a08995 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 4 Jan 2013 20:35:43 +0000 Subject: [PATCH 0353/1160] Change note updates for last two pull requests --- CHANGES.current | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index a043d3348..515387120 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.10 (in progress) ============================ -2013-01-03: wsfulton - Pull patch from BrantKyser to fix directors and nspace feature when multilevel namespaces are used. +2013-01-04: wsfulton + [Java] Pull patch #2 from BrantKyser to fix SF Bug #1283 - fix smart pointers in conjuction + with directors. + +2013-01-03: wsfulton + [Java] Pull patch #1 from BrantKyser to fix SF Bug #1278 - fix directors and nspace feature when + multilevel namespaces are used. From fade4f1b943b17ba454dfe12d4b407ed5e0f7efe Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 4 Jan 2013 20:48:58 +0000 Subject: [PATCH 0354/1160] .gitignore additions/fixes --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d4ac5207b..6f2af0b00 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,9 @@ *.o *.class +# Editor junk +*.sw? + # Local PCRE -prce +pcre *.gz From c786781e9273f341183fe927c9061cc1979b2769 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Sat, 5 Jan 2013 03:14:42 -0600 Subject: [PATCH 0355/1160] Add test case for SourceForge Bug #1299 --- Examples/test-suite/common.mk | 1 + .../director_nspace_director_name_collision.i | 66 +++++++++++++++++++ Examples/test-suite/java/Makefile.in | 1 + 3 files changed, 68 insertions(+) create mode 100644 Examples/test-suite/director_nspace_director_name_collision.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 1cda06140..09112c316 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -178,6 +178,7 @@ CPP_TEST_CASES += \ director_keywords \ director_namespace_clash \ director_nspace \ + director_nspace_director_name_collision \ director_nested \ director_overload \ director_overload2 \ diff --git a/Examples/test-suite/director_nspace_director_name_collision.i b/Examples/test-suite/director_nspace_director_name_collision.i new file mode 100644 index 000000000..5ef2509f8 --- /dev/null +++ b/Examples/test-suite/director_nspace_director_name_collision.i @@ -0,0 +1,66 @@ +%module(directors="1") director_nspace_director_name_collision + +#ifdef SWIGJAVA +SWIG_JAVABODY_PROXY(public, public, SWIGTYPE) +SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE) +#endif + +%{ +#include + +namespace TopLevel +{ + namespace A + { + class Foo { + public: + virtual ~Foo() {} + virtual std::string ping() { return "TopLevel::A::Foo::ping()"; } + }; + } + + namespace B + { + class Foo { + public: + virtual ~Foo() {} + virtual std::string ping() { return "TopLevel::B:Foo::ping()"; } + }; + } +} + +%} + +%include + +// nspace feature only supported by these languages +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) +%nspace TopLevel::A::Foo; +%nspace TopLevel::B::Foo; +#else +#warning nspace feature not yet supported in this target language +#endif + +%feature("director") TopLevel::A::Foo; +%feature("director") TopLevel::B::Foo; + +namespace TopLevel +{ + namespace A + { + class Foo { + public: + virtual ~Foo(); + virtual std::string ping(); + }; + } + + namespace B + { + class Foo { + public: + virtual ~Foo(); + virtual std::string ping(); + }; + } +} diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 0b3f7babb..f8da8e6cc 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -46,6 +46,7 @@ SWIGOPT += -package $(JAVA_PACKAGE) nspace.%: JAVA_PACKAGE = $*Package nspace_extend.%: JAVA_PACKAGE = $*Package director_nspace.%: JAVA_PACKAGE = $*Package +director_nspace_director_name_collision.%: JAVA_PACKAGE = $*Package # Rules for the different types of tests %.cpptest: From 3c12306b2146a00c27080d43f60e8e29d7b94cd9 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Sat, 5 Jan 2013 03:40:06 -0600 Subject: [PATCH 0356/1160] Remove extra underscore from generated director names to maintain prevent breaking languages that do not support nspace. --- Examples/test-suite/java_director_assumeoverride.i | 2 +- Source/Modules/lang.cxx | 5 ++++- Source/Swig/cwrap.c | 12 ++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/java_director_assumeoverride.i b/Examples/test-suite/java_director_assumeoverride.i index 310a20e0c..7364a3d58 100644 --- a/Examples/test-suite/java_director_assumeoverride.i +++ b/Examples/test-suite/java_director_assumeoverride.i @@ -10,7 +10,7 @@ public: #include "java_director_assumeoverride_wrap.h" bool isFuncOverridden(OverrideMe* f) { - SwigDirector__OverrideMe* director = dynamic_cast(f); + SwigDirector_OverrideMe* director = dynamic_cast(f); if (!director) { return false; } diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index b7ce2c4a8..7468774a3 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -358,7 +358,10 @@ Language::~Language() { String *classname = Getattr(n, "sym:name"); Replace(nspace, ".", "_", DOH_REPLACE_ANY); - dirclassname = NewStringf("SwigDirector_%s_%s", nspace, classname); + if (Len(nspace) > 0) + dirclassname = NewStringf("SwigDirector_%s_%s", nspace, classname); + else + dirclassname = NewStringf("SwigDirector_%s", classname); Setattr(n, attrib, dirclassname); Delete(nspace); diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index d47f072e7..c4c4621a1 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -940,7 +940,10 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas /* If protected access (can only be if a director method) then call the extra public accessor method (language module must provide this) */ String *explicit_qualifier_tmp = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname")); explicitcall_name = NewStringf("%sSwigPublic", name); - explicit_qualifier = NewStringf("SwigDirector_%s_%s", directorScope, explicit_qualifier_tmp); + if (Len(directorScope) > 0) + explicit_qualifier = NewStringf("SwigDirector_%s_%s", directorScope, explicit_qualifier_tmp); + else + explicit_qualifier = NewStringf("SwigDirector_%s", explicit_qualifier_tmp); Delete(explicit_qualifier_tmp); } else { explicit_qualifier = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname")); @@ -1174,12 +1177,17 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String Node *parent = Swig_methodclass(n); int abstract = Getattr(parent, "abstracts") != 0; String *name = Getattr(parent, "sym:name"); - String *directorname = NewStringf("SwigDirector_%s_%s", directorScope, name); + String *directorname; String *action = NewStringEmpty(); String *tmp_none_comparison = Copy(none_comparison); String *director_call; String *nodirector_call; + if (Len(directorScope) > 0) + directorname = NewStringf("SwigDirector_%s_%s", directorScope, name); + else + directorname = NewStringf("SwigDirector_%s", name); + Replaceall(tmp_none_comparison, "$arg", "arg1"); director_call = Swig_cppconstructor_director_call(directorname, directorparms); From b005c68009b51f521f2d469eb557164cb657bc8f Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Sat, 5 Jan 2013 04:54:02 -0600 Subject: [PATCH 0357/1160] Patch for SourceForge Bug #1299 broke D and C#. Update D module to reflect these changes NOTE: There are several test failures in the D test suite, so it is difficult to be entirely sure this does not break something. --- Source/Modules/d.cxx | 71 +++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index b8e30d50c..b66f8d2be 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -1897,7 +1897,7 @@ public: // Write C++ director class declaration, for example: // class SwigDirector_myclass : public myclass, public Swig::Director { String *classname = Swig_class_name(n); - String *directorname = NewStringf("SwigDirector_%s", classname); + String *directorname = directorClassName(n); String *declaration = Swig_class_declaration(n, directorname); const String *base = Getattr(n, "classtype"); @@ -1949,7 +1949,7 @@ public: bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0"))); int status = SWIG_OK; bool output_director = true; - String *dirclassname = getDirectorClassName(parent); + String *dirclassname = directorClassName(parent); String *qualified_name = NewStringf("%s::%s", dirclassname, name); SwigType *c_ret_type = NULL; String *dcallback_call_args = NewString(""); @@ -2373,10 +2373,12 @@ public: Printf(director_callback_pointers, " SWIG_Callback%s_t swig_callback_%s;\n", methid, overloaded_name); // Write the type alias for the callback to the intermediary D module. - String* proxy_callback_type = NewString(""); - Printf(proxy_callback_type, "SwigDirector_%s_Callback%s", classname, methid); + String *proxy_callback_type = NewString(""); + String *dirClassName = directorClassName(parent); + Printf(proxy_callback_type, "%s_Callback%s", dirClassName, methid); Printf(im_dmodule_code, "alias extern(C) %s function(void*%s) %s;\n", proxy_callback_return_type, delegate_parms, proxy_callback_type); Delete(proxy_callback_type); + Delete(dirClassName); } Delete(qualified_return); @@ -2399,7 +2401,7 @@ public: Node *parent = parentNode(n); String *decl = Getattr(n, "decl");; String *supername = Swig_class_name(parent); - String *classname = getDirectorClassName(parent); + String *classname = directorClassName(parent); String *sub = NewString(""); Parm *p; ParmList *superparms = Getattr(n, "parms"); @@ -2454,15 +2456,15 @@ public: * D::classDirectorDefaultConstructor() * --------------------------------------------------------------------------- */ virtual int classDirectorDefaultConstructor(Node *n) { - String *classname = Swig_class_name(n); + String *classname = directorClassName(n); String *classtype = SwigType_namestr(Getattr(n, "name")); Wrapper *w = NewWrapper(); - Printf(w->def, "SwigDirector_%s::SwigDirector_%s() : %s {", classname, classname, Getattr(n, "director:ctor")); + Printf(w->def, "%s::%s() : %s {", classname, classname, Getattr(n, "director:ctor")); Printf(w->code, "}\n"); Wrapper_print(w, f_directors); - Printf(f_directors_h, " SwigDirector_%s();\n", classname); + Printf(f_directors_h, " %s();\n", classname); DelWrapper(w); Delete(classtype); Delete(classname); @@ -2474,15 +2476,15 @@ public: * --------------------------------------------------------------------------- */ virtual int classDirectorDestructor(Node *n) { Node *current_class = getCurrentClass(); - String *classname = Swig_class_name(current_class); + String *classname = directorClassName(current_class); Wrapper *w = NewWrapper(); if (Getattr(n, "throw")) { - Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s() throw ();\n", classname); + Printf(w->def, "%s::~%s() throw () {\n", classname, classname); } else { - Printf(f_directors_h, " virtual ~SwigDirector_%s();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s();\n", classname); + Printf(w->def, "%s::~%s() {\n", classname, classname); } Printv(w->code, "}\n", NIL); @@ -2499,7 +2501,7 @@ public: * --------------------------------------------------------------------------- */ virtual int classDirectorEnd(Node *n) { int i; - String *director_classname = getDirectorClassName(n); + String *director_classname = directorClassName(n); Wrapper *w = NewWrapper(); @@ -3308,7 +3310,7 @@ private: // If directors are enabled for the current class, generate the // director connect helper function which is called from the constructor // and write it to the class body. - writeDirectorConnectProxy(); + writeDirectorConnectProxy(n); } // Write all constants and enumerations first to prevent forward reference @@ -3475,12 +3477,15 @@ private: } /* --------------------------------------------------------------------------- - * D::writeDirectorConnectProxy() + * D::writeDirectorConnectProxy(Node *classNode) * * Writes the helper method which registers the director callbacks by calling * the director connect function from the D side to the proxy class. * --------------------------------------------------------------------------- */ - void writeDirectorConnectProxy() { + void writeDirectorConnectProxy(Node* classNode) { + String *dirClassName = directorClassName(classNode); + String *connect_name = Swig_name_member(getNSpace(), + proxy_class_name, "director_connect"); Printf(proxy_class_body_code, "\nprivate void swigDirectorConnect() {\n"); int i; @@ -3491,12 +3496,12 @@ private: String *return_type = Getattr(udata, "return_type"); String *param_list = Getattr(udata, "param_list"); String *methid = Getattr(udata, "class_methodidx"); - Printf(proxy_class_body_code, " %s.SwigDirector_%s_Callback%s callback%s;\n", im_dmodule_fq_name, proxy_class_name, methid, methid); + Printf(proxy_class_body_code, " %s.%s_Callback%s callback%s;\n", im_dmodule_fq_name, dirClassName, methid, methid); Printf(proxy_class_body_code, " if (swigIsMethodOverridden!(%s delegate(%s), %s function(%s), %s)()) {\n", return_type, param_list, return_type, param_list, method); Printf(proxy_class_body_code, " callback%s = &swigDirectorCallback_%s_%s;\n", methid, proxy_class_name, overloaded_name); Printf(proxy_class_body_code, " }\n\n"); } - Printf(proxy_class_body_code, " %s.%s_director_connect(cast(void*)swigCPtr, cast(void*)this", im_dmodule_fq_name, proxy_class_name); + Printf(proxy_class_body_code, " %s.%s(cast(void*)swigCPtr, cast(void*)this", im_dmodule_fq_name, connect_name); for (i = first_class_dmethod; i < curr_class_dmethod; ++i) { UpcallData *udata = Getitem(dmethods_seq, i); String *methid = Getattr(udata, "class_methodidx"); @@ -3532,6 +3537,8 @@ private: director_callback_pointers = NULL; Delete(director_dcallbacks_code); director_dcallbacks_code = NULL; + Delete(dirClassName); + Delete(connect_name); } /* --------------------------------------------------------------------------- @@ -3548,7 +3555,7 @@ private: String *norm_name = SwigType_namestr(Getattr(n, "name")); String *connect_name = Swig_name_member(getNSpace(), proxy_class_name, "director_connect"); - String *sym_name = Getattr(n, "sym:name"); + String *dirClassName = directorClassName(n); Wrapper *code_wrap; Printv(wrapper_loader_bind_code, wrapper_loader_bind_command, NIL); @@ -3561,7 +3568,7 @@ private: Printf(code_wrap->def, "SWIGEXPORT void D_%s(void *objarg, void *dobj", connect_name); 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); + Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName); Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_connect_director(dobj"); @@ -3570,9 +3577,9 @@ private: UpcallData *udata = Getitem(dmethods_seq, i); String *methid = Getattr(udata, "class_methodidx"); - Printf(code_wrap->def, ", SwigDirector_%s::SWIG_Callback%s_t callback%s", sym_name, methid, methid); + Printf(code_wrap->def, ", %s::SWIG_Callback%s_t callback%s", dirClassName, methid, methid); Printf(code_wrap->code, ", callback%s", methid); - Printf(im_dmodule_code, ", SwigDirector_%s_Callback%s callback%s", sym_name, methid, methid); + Printf(im_dmodule_code, ", %s_Callback%s callback%s", dirClassName, methid, methid); } Printf(code_wrap->def, ") {\n"); @@ -3585,6 +3592,7 @@ private: DelWrapper(code_wrap); Delete(connect_name); + Delete(dirClassName); } /* --------------------------------------------------------------------------- @@ -4298,23 +4306,6 @@ private: return proxyname; } - /* --------------------------------------------------------------------------- - * D::directorClassName() - * --------------------------------------------------------------------------- */ - String *getDirectorClassName(Node *n) const { - String *dirclassname; - const char *attrib = "director:classname"; - - if (!(dirclassname = Getattr(n, attrib))) { - String *classname = Getattr(n, "sym:name"); - - dirclassname = NewStringf("SwigDirector_%s", classname); - Setattr(n, attrib, dirclassname); - } - - return dirclassname; - } - /* --------------------------------------------------------------------------- * D::makeParameterName() * From c62cd63f713aeeda9dd938a3dc1311f8d2f14e06 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Sat, 5 Jan 2013 05:25:33 -0600 Subject: [PATCH 0358/1160] Patch for SourceForge Bug #1299 broke D and C#. Update C# module to reflect these changes. --- Source/Modules/csharp.cxx | 45 +++++++++++++-------------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index c54475029..d78253f1a 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -198,24 +198,6 @@ public: return proxyname; } - /* ----------------------------------------------------------------------------- - * directorClassName() - * ----------------------------------------------------------------------------- */ - - String *directorClassName(Node *n) { - String *dirclassname; - const char *attrib = "director:classname"; - - if (!(dirclassname = Getattr(n, attrib))) { - String *classname = Getattr(n, "sym:name"); - - dirclassname = NewStringf("SwigDirector_%s", classname); - Setattr(n, attrib, dirclassname); - } - - return dirclassname; - } - /* ------------------------------------------------------------ * main() * ------------------------------------------------------------ */ @@ -3407,6 +3389,7 @@ public: String *sym_name = Getattr(n, "sym:name"); String *qualified_classname = Copy(sym_name); String *nspace = getNSpace(); + String *dirClassName = directorClassName(n); if (nspace) Insert(qualified_classname, 0, NewStringf("%s.", nspace)); @@ -3418,7 +3401,7 @@ public: 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); + Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName); // TODO: if statement not needed?? - Java too Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_connect_director("); @@ -3430,7 +3413,7 @@ public: Printf(code_wrap->def, ", "); if (i != first_class_dmethod) Printf(code_wrap->code, ", "); - Printf(code_wrap->def, "SwigDirector_%s::SWIG_Callback%s_t callback%s", sym_name, methid, methid); + Printf(code_wrap->def, "%s::SWIG_Callback%s_t callback%s", dirClassName, methid, methid); Printf(code_wrap->code, "callback%s", methid); Printf(imclass_class_code, ", %s.SwigDelegate%s_%s delegate%s", qualified_classname, sym_name, methid, methid); } @@ -3447,6 +3430,7 @@ public: Delete(wname); Delete(swig_director_connect); Delete(qualified_classname); + Delete(dirClassName); } /* --------------------------------------------------------------- @@ -3962,15 +3946,15 @@ public: * ------------------------------------------------------------ */ int classDirectorDefaultConstructor(Node *n) { - String *classname = Swig_class_name(n); + String *classname = directorClassName(n); String *classtype = SwigType_namestr(Getattr(n, "name")); Wrapper *w = NewWrapper(); - Printf(w->def, "SwigDirector_%s::SwigDirector_%s() : %s {", classname, classname, Getattr(n, "director:ctor")); + Printf(w->def, "%s::%s() : %s {", classname, classname, Getattr(n, "director:ctor")); Printf(w->code, "}\n"); Wrapper_print(w, f_directors); - Printf(f_directors_h, " SwigDirector_%s();\n", classname); + Printf(f_directors_h, " %s();\n", classname); DelWrapper(w); Delete(classtype); Delete(classname); @@ -4014,15 +3998,15 @@ public: int classDirectorDestructor(Node *n) { Node *current_class = getCurrentClass(); - String *classname = Swig_class_name(current_class); + String *classname = directorClassName(current_class); Wrapper *w = NewWrapper(); if (Getattr(n, "throw")) { - Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s() throw ();\n", classname); + Printf(w->def, "%s::~%s() throw () {\n", classname, classname); } else { - Printf(f_directors_h, " virtual ~SwigDirector_%s();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s();\n", classname); + Printf(w->def, "%s::~%s() {\n", classname, classname); } Printv(w->code, "}\n", NIL); @@ -4120,8 +4104,7 @@ public: String *base = Getattr(n, "classtype"); String *class_ctor = NewString("Swig::Director()"); - String *classname = Swig_class_name(n); - String *directorname = NewStringf("SwigDirector_%s", classname); + String *directorname = directorClassName(n); String *declaration = Swig_class_declaration(n, directorname); Printf(declaration, " : public %s, public Swig::Director", base); @@ -4129,6 +4112,8 @@ public: // Stash stuff for later. Setattr(n, "director:decl", declaration); Setattr(n, "director:ctor", class_ctor); + + Delete(directorname); } }; /* class CSHARP */ From 0fa284019acc83ccfbf054040b120fe4e702b3e0 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Sat, 5 Jan 2013 05:58:46 -0600 Subject: [PATCH 0359/1160] Add generated files to .gitignore. --- .gitignore | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d4ac5207b..5d2c7ce4e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,79 @@ *.o *.class +# Editor junk +*.sw? + # Local PCRE -prce +pcre *.gz + +# Generated by autogen.sh +CCache/autom4te.cache/ +CCache/config.h.in +CCache/configure +Source/Include/swigconfig.h.in +Source/Makefile.in +Tools/config/compile +Tools/config/config.guess +Tools/config/config.sub +Tools/config/depcomp +Tools/config/install-sh +Tools/config/missing +Tools/config/ylwrap +aclocal.m4 +autom4te.cache/ +configure + +# Generated by ./configure +CCache/Makefile +CCache/ccache_swig_config.h +CCache/config.h +CCache/config.log +CCache/config.status +Examples/Makefile +Examples/guile/Makefile +Examples/test-suite/*/Makefile +Examples/xml/Makefile +Lib/ocaml/swigp4.ml +/Makefile +Source/Include/stamp-h1 +Source/Include/swigconfig.h +Source/Makefile +.deps +config.log +config.status +preinst-swig +swig.spec + +# Build Artifacts +.dirstamp +CCache/ccache-swig +Source/CParse/parser.c +Source/CParse/parser.h +Source/eswig +swig + +# Test Suite Generated Files +Examples/test-suite/allegrocl/*/ +Examples/test-suite/cffi/*/ +Examples/test-suite/chicken/*/ +Examples/test-suite/clisp/*/ +Examples/test-suite/csharp/*/ +Examples/test-suite/d/*/ +Examples/test-suite/go/*/ +Examples/test-suite/guile/*/ +Examples/test-suite/guilescm/*/ +Examples/test-suite/java/*/ +Examples/test-suite/lua/*/ +Examples/test-suite/mzscheme/*/ +Examples/test-suite/ocaml/*/ +Examples/test-suite/octave/*/ +Examples/test-suite/perl5/*/ +Examples/test-suite/php/*/ +Examples/test-suite/pike/*/ +Examples/test-suite/python/*/ +Examples/test-suite/r/*/ +Examples/test-suite/ruby/*/ +Examples/test-suite/tcl/*/ +Examples/test-suite/uffi/*/ \ No newline at end of file From 41ddc7b240e4357c372c0b4992562d8a795a8e3a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 5 Jan 2013 19:31:10 +0000 Subject: [PATCH 0360/1160] Add change notes for last commit --- CHANGES.current | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 515387120..21978e1d9 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.10 (in progress) ============================ +2013-01-05: wsfulton + [Python] Pull patch #3 from ptomulik to fix SF Bug #1295 - standard exceptions as + classes using the SWIG_STD_EXCEPTIONS_AS_CLASSES macro. + 2013-01-04: wsfulton [Java] Pull patch #2 from BrantKyser to fix SF Bug #1283 - fix smart pointers in conjuction with directors. From 0207a9b24f128aacd80627decb4c561dc2f83708 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 6 Jan 2013 01:49:25 +0000 Subject: [PATCH 0361/1160] Add CHANGES note for virtual destructor in templates bug in prev commit --- CHANGES.current | 5 +++++ .../test-suite/template_default_arg_virtual_destructor.i | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 21978e1d9..6be460a1e 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.10 (in progress) ============================ +2013-01-06: wsfulton + Pull patch #4 from ptomulik to fix SF Bug #1296 - Fix incorrect warning for virtual destructors + in templates, such as: + Warning 521: Illegal destructor name B< A >::~B(). Ignored. + 2013-01-05: wsfulton [Python] Pull patch #3 from ptomulik to fix SF Bug #1295 - standard exceptions as classes using the SWIG_STD_EXCEPTIONS_AS_CLASSES macro. diff --git a/Examples/test-suite/template_default_arg_virtual_destructor.i b/Examples/test-suite/template_default_arg_virtual_destructor.i index 319d5b837..844e9225b 100644 --- a/Examples/test-suite/template_default_arg_virtual_destructor.i +++ b/Examples/test-suite/template_default_arg_virtual_destructor.i @@ -21,4 +21,4 @@ template }; %} %template(B_AF) B; -%template(B_A) B; // this instantiation triggert the warning +%template(B_A) B; // this instantiation triggers the warning From 308b5dab3f363dcb02cdc3f4853fcd409c00cab9 Mon Sep 17 00:00:00 2001 From: joequant Date: Sun, 6 Jan 2013 19:42:12 +0800 Subject: [PATCH 0362/1160] r changes to handle external pointers --- Lib/r/rtype.swg | 2 +- Lib/r/std_vector.i | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg index 92f9b4f3d..b4571af46 100644 --- a/Lib/r/rtype.swg +++ b/Lib/r/rtype.swg @@ -91,7 +91,7 @@ %{ $input = enumToInteger($input, "$R_class"); %} %typemap(scoercein) SWIGTYPE, SWIGTYPE *, SWIGTYPE *const, SWIGTYPE & - %{ $input = slot($input,"ref") %} + %{ if (inherits($input, "ExternalReference")) $input = slot($input,"ref") %} /* %typemap(scoercein) SWIGTYPE *, SWIGTYPE *const diff --git a/Lib/r/std_vector.i b/Lib/r/std_vector.i index f7ad94aac..836c95b53 100644 --- a/Lib/r/std_vector.i +++ b/Lib/r/std_vector.i @@ -510,68 +510,71 @@ %typemap("rtypecheck") std::vector, std::vector const, std::vector const& %{ is.numeric($arg) %} %typemap("rtype") std::vector "numeric" +%typemap("scoercein") std::vector, std::vector const, std::vector const& ""; %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector) %traits_type_name(std::vector) %typemap("rtypecheck") std::vector, std::vector const, std::vector const& %{ is.numeric($arg) %} %typemap("rtype") std::vector "numeric" +%typemap("scoercein") std::vector, std::vector const, std::vector const& ""; %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector); %traits_type_name(std::vector); %typemap("rtypecheck") std::vector , std::vector const, std::vector const& %{ is.logical($arg) %} %typemap("rtype") std::vector "logical" -%typemap("scoercein") std::vector "$input = as.logical($input);"; +%typemap("scoercein") std::vector , std::vector const, std::vector const& "$input = as.logical($input);"; %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector); %traits_type_name(std::vector); %typemap("rtypecheck") std::vector , std::vector const, std::vector const& %{ is.integer($arg) || is.numeric($arg) %} %typemap("rtype") std::vector "integer" -%typemap("scoercein") std::vector "$input = as.integer($input);"; +%typemap("scoercein") std::vector , std::vector const, std::vector const& "$input = as.integer($input);"; %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector); %traits_type_name(std::vector); %typemap("rtypecheck") std::vector, std::vector const, std::vector const& %{ is.integer($arg) || is.numeric($arg) %} %typemap("rtype") std::vector "integer" -%typemap("scoercein") std::vector "$input = as.integer($input);"; +%typemap("scoercein") std::vector, std::vector const, std::vector const& "$input = as.integer($input);"; %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector >); %traits_type_name(std::vector< std::vector >); %typemap("rtypecheck") std::vector >, std::vector > const, std::vector >const& %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} %typemap("rtype") std::vector > "list" -%typemap("scoercein") std::vector< std::vector > "$input = lapply($input, as.integer);"; +%typemap("scoercein") std::vector< std::vector >, std::vector > const, std::vector >const& "$input = lapply($input, as.integer);"; %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector >); %traits_type_name(std::vector< std::vector >); %typemap("rtypecheck") std::vector >, std::vector > const, std::vector >const& %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} %typemap("rtype") std::vector > "list" -%typemap("scoercein") std::vector< std::vector > "$input = lapply($input, as.integer);"; +%typemap("scoercein") std::vector< std::vector >, std::vector > const, std::vector >const& "$input = lapply($input, as.integer);"; %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector >); %traits_type_name(std::vector< std::vector >); %typemap("rtypecheck") std::vector >, std::vector > const, std::vector >const& %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} %typemap("rtype") std::vector > "list" -%typemap("scoercein") std::vector< std::vector > "$input = lapply($input, as.numeric);"; +%typemap("scoercein") std::vector< std::vector >, std::vector > const, std::vector >const& "$input = lapply($input, as.numeric);"; %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector >); %traits_type_name(std::vector< std::vector >); %typemap("rtypecheck") std::vector >, std::vector > const, std::vector >const& %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} %typemap("rtype") std::vector > "list" -%typemap("scoercein") std::vector< std::vector > "$input = lapply($input, as.numeric);"; +%typemap("scoercein") std::vector< std::vector >, std::vector > const, std::vector >const& + "$input = lapply($input, as.numeric);"; %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector >); %traits_type_name(std::vector< std::vector >); %typemap("rtypecheck") std::vector >, std::vector > const, std::vector >const& %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} %typemap("rtype") std::vector > "list" -%typemap("scoercein") std::vector< std::vector > "$input = lapply($input, as.logical);"; +%typemap("scoercein") std::vector< std::vector >, std::vector > const, std::vector >const& "$input = lapply($input, as.logical);"; // we don't want these to be given R classes as they // have already been turned into R vectors. From 9d0d59ead7b133eca06e3792a19306d1470b485a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Sun, 6 Jan 2013 16:55:38 +0100 Subject: [PATCH 0363/1160] remove __pycache__ directories when cleaning python test cases --- Examples/Makefile.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 6458512e9..6e1731f6b 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -320,6 +320,7 @@ runme3.py: runme.py # ----------------------------------------------------------------- python_clean: + rm -rf __pycache__ rm -f *_wrap* *~ .~* mypython@EXEEXT@ *.pyc rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@SO@ *@PYTHON_SO@ @@ -372,6 +373,7 @@ octave_run: $(OCTSCRIPT) # ----------------------------------------------------------------- octave_clean: + rm -rf __pycache__ rm -f *_wrap* *~ .~* myoctave@EXEEXT@ *.pyc rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@SO@ *@OCTAVE_SO@ From 2928bde7777a00411209938f3d2af8de0309fcff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Sun, 6 Jan 2013 17:33:17 +0100 Subject: [PATCH 0364/1160] some patterns added to .gitignore --- .gitignore | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/.gitignore b/.gitignore index 7d6db8f9a..8509eebd3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,41 @@ pcre *.gz +# Python generated files, based on: +# https://github.com/github/gitignore/blob/master/Python.gitignore +*.py[cod] +*/__pycache__/ +/__pycache__/ + +# C/C++ object files, based on: +# https://github.com/github/gitignore/blob/master/C.gitignore +# https://github.com/github/gitignore/blob/master/C%2B%2B.gitignore +*.slo +*.lo + +# C/C++ dynamic libraries, based on: +# https://github.com/github/gitignore/blob/master/C.gitignore +# https://github.com/github/gitignore/blob/master/C%2B%2B.gitignore +*.dll +*.so +*.so.* +*.dylib + +# C/C++ static libraries, based on: +# https://github.com/github/gitignore/blob/master/C.gitignore +# https://github.com/github/gitignore/blob/master/C%2B%2B.gitignore +*.lib +*.lai +*.la +*.a + +# C/C++ executables, based on: +# https://github.com/github/gitignore/blob/master/C.gitignore +# https://github.com/github/gitignore/blob/master/C%2B%2B.gitignore +*.exe +*.out +*.app + # Generated by autogen.sh CCache/autom4te.cache/ CCache/config.h.in From beb40008b1091d75f776dc0d3e1077a8e049e129 Mon Sep 17 00:00:00 2001 From: joequant Date: Mon, 7 Jan 2013 06:03:37 +0800 Subject: [PATCH 0365/1160] add boost_shared_ptr for R --- Lib/r/boost_shared_ptr.i | 307 +++++++++++++++++++++++++++++++++++++++ Lib/r/rrun.swg | 7 + 2 files changed, 314 insertions(+) create mode 100644 Lib/r/boost_shared_ptr.i diff --git a/Lib/r/boost_shared_ptr.i b/Lib/r/boost_shared_ptr.i new file mode 100644 index 000000000..17e9cfe8a --- /dev/null +++ b/Lib/r/boost_shared_ptr.i @@ -0,0 +1,307 @@ +%include + +// Language specific macro implementing all the customisations for handling the smart pointer +%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...) + +// %naturalvar is as documented for member variables +%naturalvar TYPE; +%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; + +// destructor wrapper customisation +%feature("unref") TYPE +//"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ( (*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\") )) << \"]\" << endl << flush; }\n" + "(void)arg1; delete smartarg1;" + +// Typemap customisations... + +// plain value +%typemap(in) CONST TYPE (void *argp, int res = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (!argp) { + %argument_nullref("$type", $symname, $argnum); + } else { + $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + } +} +%typemap(out) CONST TYPE { + %set_output(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) CONST TYPE { + void *argp = 0; + int newmem = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + if (!argp) { + %argument_nullref("$type", $symname, $argnum); + } else { + $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + } +} +%typemap(varout) CONST TYPE { + %set_varoutput(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// plain pointer +// 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, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast(tempshared.get(), $1_ltype); + } else { + smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); + } +} +%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), $owner | SWIG_POINTER_OWN)); +} + +%typemap(varin) CONST TYPE * { + void *argp = 0; + int newmem = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0; + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast(tempshared.get(), $1_ltype); + } else { + smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); + } +} +%typemap(varout, fragment="SWIG_null_deleter") CONST TYPE * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// plain reference +%typemap(in) CONST TYPE & (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (!argp) { %argument_nullref("$type", $symname, $argnum); } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast(tempshared.get(), $1_ltype); + } else { + $1 = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype); + } +} +%typemap(out, fragment="SWIG_null_deleter") CONST TYPE & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) CONST TYPE & { + void *argp = 0; + int newmem = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; + if (!argp) { %argument_nullref("$type", $symname, $argnum); } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = *%const_cast(tempshared.get(), $1_ltype); + } else { + $1 = *%const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype); + } +} +%typemap(varout, fragment="SWIG_null_deleter") CONST TYPE & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(&$1 SWIG_NO_NULL_DELETER_0); + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// plain pointer by reference +// Note: $disown not implemented as it will lead to a memory leak of the shared_ptr instance +%typemap(in) TYPE *CONST& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + temp = %const_cast(tempshared.get(), $*1_ltype); + } else { + temp = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $*1_ltype); + } + $1 = &temp; +} +%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) TYPE *CONST& %{ +#error "varin typemap not implemented" +%} +%typemap(varout) TYPE *CONST& %{ +#error "varout typemap not implemented" +%} + +// shared_ptr by value +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (void *argp, int res = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (argp) $1 = *(%reinterpret_cast(argp, $<ype)); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $<ype); +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + int newmem = 0; + void *argp = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + $1 = argp ? *(%reinterpret_cast(argp, $<ype)) : SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE >(); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $<ype); +} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// shared_ptr by reference +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & (void *argp, int res = 0, $*1_ltype tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + if (argp) tempshared = *%reinterpret_cast(argp, $ltype); + delete %reinterpret_cast(argp, $ltype); + $1 = &tempshared; + } else { + $1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared; + } +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{ +#error "varin typemap not implemented" +%} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{ +#error "varout typemap not implemented" +%} + +// shared_ptr by pointer +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * (void *argp, int res = 0, $*1_ltype tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + if (argp) tempshared = *%reinterpret_cast(argp, $ltype); + delete %reinterpret_cast(argp, $ltype); + $1 = &tempshared; + } else { + $1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared; + } +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 && *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); + if ($owner) delete $1; +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{ +#error "varin typemap not implemented" +%} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{ +#error "varout typemap not implemented" +%} + +// shared_ptr by pointer reference +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (void *argp, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, $*1_ltype temp = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (argp) tempshared = *%reinterpret_cast(argp, $*ltype); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $*ltype); + temp = &tempshared; + $1 = &temp; +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 && **$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{ +#error "varin typemap not implemented" +%} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{ +#error "varout typemap not implemented" +%} + +// Typecheck typemaps +// Note: SWIG_ConvertPtr with void ** parameter set to 0 instead of using SWIG_ConvertPtrAndOwn, so that the casting +// function is not called thereby avoiding a possible smart pointer copy constructor call when casting up the inheritance chain. +%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) + TYPE CONST, + TYPE CONST &, + TYPE CONST *, + TYPE *CONST&, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { + int res = SWIG_ConvertPtr($input, 0, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), 0); + $1 = SWIG_CheckState(res); +} + + +// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug +%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} +%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} + + +%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; +%enddef + diff --git a/Lib/r/rrun.swg b/Lib/r/rrun.swg index c441a5222..f8bc9f497 100644 --- a/Lib/r/rrun.swg +++ b/Lib/r/rrun.swg @@ -3,6 +3,12 @@ extern "C" { #endif +/* for raw pointer */ +#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_R_ConvertPtr(obj, pptr, type, flags) +#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_R_ConvertPtr(obj, pptr, type, flags) +#define SWIG_NewPointerObj(ptr, type, flags) SWIG_R_NewPointerObj(ptr, type, flags) + + /* Remove global namespace pollution */ #if !defined(SWIG_NO_R_NO_REMAP) # define R_NO_REMAP @@ -264,6 +270,7 @@ SWIG_R_NewPointerObj(void *ptr, swig_type_info *type, int flags) { return rptr; } + /* Convert a pointer value */ SWIGRUNTIMEINLINE int SWIG_R_ConvertPtr(SEXP obj, void **ptr, swig_type_info *ty, int flags) { From cec9faf6885ed7d994d08f1494b1b94e88910c47 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 7 Jan 2013 16:47:32 +1300 Subject: [PATCH 0366/1160] Fix bashism in configure, introduced in 2.0.9. --- CHANGES.current | 3 +++ configure.in | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 6be460a1e..0b1d7ccc7 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-01-07: olly + Fix bashism in configure, introduced in 2.0.9. + 2013-01-06: wsfulton Pull patch #4 from ptomulik to fix SF Bug #1296 - Fix incorrect warning for virtual destructors in templates, such as: diff --git a/configure.in b/configure.in index 3927a102a..0e8ad5bb1 100644 --- a/configure.in +++ b/configure.in @@ -1342,7 +1342,7 @@ AC_MSG_CHECKING(for Ruby header files) if test -n "$RUBY"; then # Try Ruby1.9 first RUBYDIR=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["rubyhdrdir"]] || $rubyhdrdir') 2>/dev/null` - if test x"$RUBYDIR" == x"" || test x"$RUBYDIR" == x"nil"; then + if test x"$RUBYDIR" = x"" || test x"$RUBYDIR" = x"nil"; then RUBYDIR=`($RUBY -rmkmf -e 'print Config::CONFIG[["archdir"]] || $archdir') 2>/dev/null` else RUBYARCH=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["arch"]] || $arch') 2>/dev/null` From 0dd11cdd8daa120f24f196f5dc6b02507f3292ee Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 8 Jan 2013 18:33:47 +1300 Subject: [PATCH 0367/1160] Fix to work with a ZTS build of PHP (broken in 2.0.7) --- CHANGES.current | 3 +++ Source/Modules/php.cxx | 1 + 2 files changed, 4 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 0b1d7ccc7..05d533c17 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-01-08: olly + [PHP] Fix to work with a ZTS build of PHP (broken in 2.0.7). + 2013-01-07: olly Fix bashism in configure, introduced in 2.0.9. diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 5c3ce283e..9b68d072c 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -418,6 +418,7 @@ public: Append(s_header, "static void SWIG_FAIL() __attribute__ ((__noreturn__));\n"); Append(s_header, "#endif\n\n"); Append(s_header, "static void SWIG_FAIL() {\n"); + Append(s_header, " TSRMLS_FETCH();\n"); Append(s_header, " zend_error(SWIG_ErrorCode(), \"%s\", SWIG_ErrorMsg());\n"); // zend_error() should never return with the parameters we pass, but if it // does, we really don't want to let SWIG_FAIL() return. This also avoids From f9566ad2df496e3447857962f55cb959dab3ac8a Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 8 Jan 2013 18:47:40 +1300 Subject: [PATCH 0368/1160] Fix assorted typos. From https://sourceforge.net/p/swig/patches/332/ and some others too. --- CHANGES | 14 +++++++------- Doc/Manual/Allegrocl.html | 2 +- Doc/Manual/Extending.html | 2 +- Examples/test-suite/chicken/README | 4 ++-- Examples/test-suite/perl5/default_args_runme.pl | 2 +- Lib/std/std_pair.i | 2 +- Lib/std/std_vector.i | 2 +- Source/CParse/cscanner.c | 4 ++-- Source/DOH/README | 2 +- Source/Modules/d.cxx | 2 +- Source/Modules/lua.cxx | 2 +- Tools/pyname_patch.py | 2 +- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/CHANGES b/CHANGES index d6006a91a..8b1945ad9 100644 --- a/CHANGES +++ b/CHANGES @@ -15,7 +15,7 @@ Version 2.0.9 (16 December 2012) symbols in Ruby 1.9+ 2012-12-14: kkaempf - [Ruby] Apply patch 3530439 and finally replace all occurences of the STR2CSTR() macro + [Ruby] Apply patch 3530439 and finally replace all occurrences of the STR2CSTR() macro with StringValuePtr(). STR2CSTR was deprecated since years and got removed in Ruby 1.9 2012-12-14: kkaempf @@ -12144,7 +12144,7 @@ Version 1.3.20 (December 17, 2003) 06/25/2003: mrose (Mark Rose) [Python] Director typemap marshalling checks for null pointers when walking the parameter list instead of relying soley on the parameter - count. Cures a segfault that occured for multiple argument inv typemaps. + count. Cures a segfault that occurred for multiple argument inv typemaps. Someone with more Swig experience should probably review this code. 06/24/2003: mkoeppe (Matthias Koeppe) @@ -17619,7 +17619,7 @@ Version 1.3.10 (December 10, 2001) shadow classes. In early implementations, shadow classes were merely Python wrappers around typed pointer objects. However, some users actually wanted to receive the shadow class object in C. - To accomodate this, the dereferencing of the "this" pointer in + To accommodate this, the dereferencing of the "this" pointer in a shadow class was moved to C as described in CHANGES [8/8/99]. However, the process of returning pointers to Python was still somewhat problematic. Specifically, shadow classes never worked @@ -19533,7 +19533,7 @@ Version 1.3.6 (July 9, 2001) [Java] destructor (_delete()) was not aware of %name renaming [Java] extends baseclass did not know about %name renaming [Java] extends baseclass did extend even when the baseclass was not known to swig - [Java] sometimes enum-declarations occured before the Java class declaration + [Java] sometimes enum-declarations occurred before the Java class declaration [Java] unrelated enum initialisations no longer appear in Java class [Java] if module ends in '_' correct JNI names are now produced @@ -20686,7 +20686,7 @@ Version 1.3 Alpha 1 (February 11, 2000) names or use %apply to map typemaps to alternate names. 8/8/99 : Handling of the 'this' pointer has been changed in Python shadow - classes. Previously, dereferencing of '.this' occured in the + classes. Previously, dereferencing of '.this' occurred in the Python shadow class itself. Now, this step occurs in the C wrappers using the following function: @@ -21243,7 +21243,7 @@ Version 1.1 Patch 1 (August 27, 1997) Would generate completely bogus code with garbage replacing the '%d'. Caused by one faulty use of printf (wasn't able to find - any other occurences). + any other occurrences). 7/7/97 : Fixed bug in Python shadow class generation with non-member functions that are returning more than one value. @@ -21359,7 +21359,7 @@ Version 1.1 (June 24, 1997) .... later ... int OldName(int); - Unlike %name, %rename will rename any occurence of the old name. + Unlike %name, %rename will rename any occurrence of the old name. This applies to functions, variables, class members and so forth. There is no way to disable %rename once set, but you can change the name by redeclaring it to something else. diff --git a/Doc/Manual/Allegrocl.html b/Doc/Manual/Allegrocl.html index 5d00c4cd0..283ff7e2c 100644 --- a/Doc/Manual/Allegrocl.html +++ b/Doc/Manual/Allegrocl.html @@ -1118,7 +1118,7 @@ namespace BAR { function that returns an object (or pointer/reference) of C/C++ type X, the wrapping defun (or defmethod) on the Lisp side will automatically wrap the pointer returned in an instance - of the apropriate class. This makes it much easier to write and + of the appropriate class. This makes it much easier to write and debug code than if pointers were passed around as a jumble of integer values.

    diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index ce205abf5..059388717 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -2975,7 +2975,7 @@ There are a lot of issues to address.
     virtual int functionWrapper(Node *n) {
    -  /* get useful atributes */
    +  /* get useful attributes */
       String   *name   = Getattr(n,"sym:name");
       SwigType *type   = Getattr(n,"type");
       ParmList *parms  = Getattr(n,"parms");
    diff --git a/Examples/test-suite/chicken/README b/Examples/test-suite/chicken/README
    index ba32bb464..aad730ec4 100644
    --- a/Examples/test-suite/chicken/README
    +++ b/Examples/test-suite/chicken/README
    @@ -1,10 +1,10 @@
     See ../README for common README file.
     
     Any testcases which have _runme.ss appended after the testcase name will be detected and run.
    -NOTE: I had to use _runme.ss becuase otherwise it would be hard to implement make clean
    +NOTE: I had to use _runme.ss because otherwise it would be hard to implement make clean
     Since when SWIG runs it generates an example.scm file for every test, to clean those files
     I needed to add a rm -f *.scm to make clean.  But we don't want the runme scripts to
    -dissappear as well!
    +disappear as well!
     
     Any testcases which have _runme_proxy.ss appended after the testcase name will be detected
     and run with the -proxy argument passed to SWIG.  SWIG will not be run with the -unhide-primitive
    diff --git a/Examples/test-suite/perl5/default_args_runme.pl b/Examples/test-suite/perl5/default_args_runme.pl
    index 45f10b37e..20f0c9bc6 100644
    --- a/Examples/test-suite/perl5/default_args_runme.pl
    +++ b/Examples/test-suite/perl5/default_args_runme.pl
    @@ -51,7 +51,7 @@ my $ex = new default_args::Except($false);
     
     my $hit = 0;
     eval { $ex->exspec(); $hit = 1; };
    -# a zero was thrown, an exception occured, but $@ is false
    +# a zero was thrown, an exception occurred, but $@ is false
     is($hit, 0, "exspec 1");
     eval { $ex->exspec(-1) };
     like($@, qr/^ciao/, "exspec 2");
    diff --git a/Lib/std/std_pair.i b/Lib/std/std_pair.i
    index 7c8327795..2743430e9 100644
    --- a/Lib/std/std_pair.i
    +++ b/Lib/std/std_pair.i
    @@ -49,7 +49,7 @@ namespace std {
       };
     
       // ***
    -  // The following specializations should dissapear or get 
    +  // The following specializations should disappear or get
       // simplified when a 'const SWIGTYPE*&' can be defined
       // ***
       template  struct pair {      
    diff --git a/Lib/std/std_vector.i b/Lib/std/std_vector.i
    index e4f9f140d..baecf8507 100644
    --- a/Lib/std/std_vector.i
    +++ b/Lib/std/std_vector.i
    @@ -95,7 +95,7 @@ namespace std {
       };
     
       // ***
    -  // This specialization should dissapear or get simplified when
    +  // This specialization should disappear or get simplified when
       // a 'const SWIGTYPE*&' can be defined
       // ***
       template
    diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c
    index 64875a4d1..b52618606 100644
    --- a/Source/CParse/cscanner.c
    +++ b/Source/CParse/cscanner.c
    @@ -9,7 +9,7 @@
      * scanner.c
      *
      * SWIG tokenizer.  This file is a wrapper around the generic C scanner
    - * found in Swig/scanner.c.   Extra logic is added both to accomodate the
    + * found in Swig/scanner.c.   Extra logic is added both to accommodate the
      * bison-based grammar and certain peculiarities of C++ parsing (e.g.,
      * operator overloading, typedef resolution, etc.).  This code also splits
      * C identifiers up into keywords and SWIG directives.
    @@ -373,7 +373,7 @@ void scanner_clear_rename() {
       rename_active = 0;
     }
     
    -/* Used to push a ficticious token into the scanner */
    +/* Used to push a fictitious token into the scanner */
     static int next_token = 0;
     void scanner_next_token(int tok) {
       next_token = tok;
    diff --git a/Source/DOH/README b/Source/DOH/README
    index 9a42e8b8b..9baaabc8a 100644
    --- a/Source/DOH/README
    +++ b/Source/DOH/README
    @@ -69,7 +69,7 @@ Close(obj)                      Close
     
     String Operations
     -----------------
    -Replace(obj, orig, rep, flags)  Replace occurences of orig with rep.
    +Replace(obj, orig, rep, flags)  Replace occurrences of orig with rep.
     Chop(obj)                       Remove trailing whitespace
     
     flags is one of the following:
    diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx
    index b8e30d50c..560835751 100644
    --- a/Source/Modules/d.cxx
    +++ b/Source/Modules/d.cxx
    @@ -3625,7 +3625,7 @@ private:
           // If the import statement has been found in the target string, we have to
           // check if the previous import was static, which would lead to problems
           // if this import is not.
    -      // Thus, we check if the seven characters in front of the occurence are
    +      // Thus, we check if the seven characters in front of the occurrence are
           // »static «. If the import string passed is also static, the checks fail
           // even if the found statement is also static because the last seven
           // characters would be part of the previous import statement then.
    diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx
    index ef2fa96de..34763290f 100644
    --- a/Source/Modules/lua.cxx
    +++ b/Source/Modules/lua.cxx
    @@ -113,7 +113,7 @@ private:
       String *s_var_tab;		// table of global variables
       String *s_const_tab;		// table of global constants
       String *s_methods_tab;	// table of class methods
    -  String *s_attr_tab;		// table of class atributes
    +  String *s_attr_tab;		// table of class attributes
       String *s_luacode;		// luacode to be called during init
       String *s_dot_get;            // table of variable 'get' functions
       String *s_dot_set;            // table of variable 'set' functions
    diff --git a/Tools/pyname_patch.py b/Tools/pyname_patch.py
    index 5931269f9..f8f436c38 100644
    --- a/Tools/pyname_patch.py
    +++ b/Tools/pyname_patch.py
    @@ -109,7 +109,7 @@ def main(fns):
                 if patch_file(fn):
                     print "Patched file", fn
             except IOError:
    -            print "Error occured during patching", fn
    +            print "Error occurred during patching", fn
         return
     
     if __name__=="__main__":
    
    From 2b407f4b2728b03a5b143adf8c842a3eaad99c7e Mon Sep 17 00:00:00 2001
    From: Vladimir Kalinin 
    Date: Tue, 8 Jan 2013 18:20:01 +0400
    Subject: [PATCH 0369/1160] SF Patch#268 - Add 'pre', 'post' and 'terminator'
     attributes to the csdirectorin typemap
    
    "csdirectorin" "pre:" and "post" code attributes in C# module. Without them it is
    not trivial to marshal strings and smart-pointers back and forth
    between user callback code and native code. (especially by reference)
    
    Also fixes 2 minor issues in director code generation that are
    difficult to come by until "csdirectorin" attribute is extended.
    The first is that "ref" types used in directors lead to invalid
    signature generation (the type array used to match methods possibly
    overloaded by user). typeof(ref T) is used instead of
    typeof().MakeByRefType()
    The second is that ignored director methods are not completely ignored
    - if there was a %typemap(imtype, "directorinattributes") it is not
    skipped for ignored method.
    ---
     .../test-suite/csharp/csharp_prepost_runme.cs | 22 +++++
     Examples/test-suite/csharp_prepost.i          | 39 +++++++-
     Examples/test-suite/director_ignore.i         |  7 ++
     Source/Modules/csharp.cxx                     | 88 +++++++++++++++++--
     4 files changed, 147 insertions(+), 9 deletions(-)
    
    diff --git a/Examples/test-suite/csharp/csharp_prepost_runme.cs b/Examples/test-suite/csharp/csharp_prepost_runme.cs
    index f76dae38e..8842a79b3 100644
    --- a/Examples/test-suite/csharp/csharp_prepost_runme.cs
    +++ b/Examples/test-suite/csharp/csharp_prepost_runme.cs
    @@ -5,6 +5,17 @@ using csharp_prepostNamespace;
     
     public class csharp_prepost_runme {
     
    +  class PrePost3_Derived : PrePost3
    +  {
    +    public PrePost3_Derived(){}
    +    public override void method(ref double[] vpre, DoubleVector vpost)
    +    {
    +      Assert(vpre[0], 1.0);
    +      vpre[0] = 2.0;
    +      Assert(vpost.Count, 2);
    +      vpost.Add(1.0);
    +    }
    +  }
       public static void Main() {
         {
           double[] v;
    @@ -37,6 +48,17 @@ public class csharp_prepost_runme {
           Assert(v[1], 8.8);
         }
     
    +    {
    +      PrePost3_Derived p = new PrePost3_Derived();
    +      double[] vpre = new double[] { 1.0 };
    +      DoubleVector vpost = new DoubleVector();
    +      vpost.Add(3.0);
    +      vpost.Add(4.0);
    +      p.method(ref vpre, vpost);
    +      Assert(vpre[0], 2.0);
    +      Assert(vpost.Count, 3);
    +    }
    +
         // Check attributes are generated for the constructor helper function
         {
           CsinAttributes c = new CsinAttributes(5);
    diff --git a/Examples/test-suite/csharp_prepost.i b/Examples/test-suite/csharp_prepost.i
    index 31e6ec753..4f5a49362 100644
    --- a/Examples/test-suite/csharp_prepost.i
    +++ b/Examples/test-suite/csharp_prepost.i
    @@ -1,4 +1,4 @@
    -%module csharp_prepost
    +%module (directors="1") csharp_prepost
     
     // Test the pre, post, terminate and cshin attributes for csin typemaps
     
    @@ -64,9 +64,11 @@ bool globalfunction2(std::vector & v, std::vector &v2, std::vect
     struct PrePost2 {
       PrePost2() {
       }
    +  virtual ~PrePost2() {
    +  }
       PrePost2(std::vector & v, std::vector &v2, std::vector & vpre, std::vector & vpost) {
       }
    -  bool method(std::vector & v, std::vector &v2, std::vector & vpre, std::vector & vpost) {
    +  virtual bool method(std::vector & v, std::vector &v2, std::vector & vpre, std::vector & vpost) {
         return true;
       }
       static bool staticmethod(std::vector & v, std::vector &v2, std::vector & vpre, std::vector & vpost) {
    @@ -75,6 +77,39 @@ struct PrePost2 {
     };
     %}
     
    +// Check csdirectorin pre and post attributes
    +// ref param
    +%typemap(csdirectorin,
    +   pre="      DoubleVector d$iminput = new DoubleVector($iminput, false);\n"
    +       "      int count$iminput = d$iminput.Count;\n"
    +       "      double[] v$iminput = new double[count$iminput];\n"
    +       "      for (int i=0; i &vpre
    +  "ref v$iminput"
    +// post only in csdirectorin typemap
    +%typemap(csdirectorin, post="      DoubleVector d$iminput = new DoubleVector($iminput, false);\n"
    +                            "      int size = d$iminput.Count;\n"
    +                            "      for (int i=0; i &vpost
    +  "new $csclassname($iminput, false)"
    +
    +%feature("director") PrePost3;
    +%inline %{
    +struct PrePost3 {
    +  PrePost3() {
    +  }
    +  virtual ~PrePost3(){}
    +  virtual void method(std::vector & vpre, std::vector & vpost) {}
    +};
    +%}
    +
    +
     %template(DoubleVector) std::vector;
     
     // Check attributes in the typemaps
    diff --git a/Examples/test-suite/director_ignore.i b/Examples/test-suite/director_ignore.i
    index 51317fbe0..05ba17ce1 100644
    --- a/Examples/test-suite/director_ignore.i
    +++ b/Examples/test-suite/director_ignore.i
    @@ -21,6 +21,13 @@
     %ignore ProtectedPureVirtualMethod1;
     %ignore ProtectedPureVirtualMethod2;
     
    +%typemap(imtype,
    +  inattributes="[inattributes should not be used]",
    +  outattributes="[outattributes should not be used]",
    +  directorinattributes="[directorinattributes should not be used]",
    +  directoroutattributes="[directoroutattributes should not be used]"
    + ) int& "imtype should not be used"
    +
     %inline %{
     
     #include 
    diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx
    index c54475029..f559d23aa 100644
    --- a/Source/Modules/csharp.cxx
    +++ b/Source/Modules/csharp.cxx
    @@ -3468,6 +3468,9 @@ public:
         String *value = Getattr(n, "value");
         String *decl = Getattr(n, "decl");
         String *declaration = NewString("");
    +    String *pre_code = NewString("");
    +    String *post_code = NewString("");
    +    String *terminator_code = NewString("");
         String *tm;
         Parm *p;
         int i;
    @@ -3556,7 +3559,8 @@ public:
           const String *im_directoroutattributes = Getattr(n, "tmap:imtype:directoroutattributes");
           if (im_directoroutattributes) {
     	Printf(callback_def, "  %s\n", im_directoroutattributes);
    -	Printf(director_delegate_definitions, "  %s\n", im_directoroutattributes);
    +	if (!ignored_method)
    +	  Printf(director_delegate_definitions, "  %s\n", im_directoroutattributes);
           }
     
           Printf(callback_def, "  private %s SwigDirector%s(", tm, overloaded_name);
    @@ -3674,6 +3678,33 @@ public:
     	      substituteClassname(pt, din);
     	      Replaceall(din, "$iminput", ln);
     
    +	      // :pre and :post attribute support
    +	      String *pre = Getattr(p, "tmap:csdirectorin:pre");
    +	      if (pre) {
    +		substituteClassname(pt, pre);
    +		Replaceall(pre, "$iminput", ln);
    +		if (Len(pre_code) > 0)
    +		  Printf(pre_code, "\n");
    +		  Printv(pre_code, pre, NIL);
    +	      }
    +	      String *post = Getattr(p, "tmap:csdirectorin:post");
    +	      if (post) {
    +		substituteClassname(pt, post);
    +		Replaceall(post, "$iminput", ln);
    +		if (Len(post_code) > 0)
    +		  Printf(post_code, "\n");
    +		Printv(post_code, post, NIL);
    +	      }
    +	      String *terminator = Getattr(p, "tmap:csdirectorin:terminator");
    +	      if (terminator) {
    +		substituteClassname(pt, terminator);
    +		Replaceall(terminator, "$iminput", ln);
    +		if (Len(terminator_code) > 0)
    +		Insert(terminator_code, 0, "\n");
    +		Insert(terminator_code, 0, terminator);
    +	      }
    +	      // end :pre and :post attribute support
    +
     	      if (i > 0) {
     		Printf(delegate_parms, ", ");
     		Printf(proxy_method_types, ", ");
    @@ -3689,7 +3720,15 @@ public:
     	      /* Get the C# parameter type */
     	      if ((tm = Getattr(p, "tmap:cstype"))) {
     		substituteClassname(pt, tm);
    -		Printf(proxy_method_types, "typeof(%s)", tm);
    +		if (Strncmp(tm, "ref ", 4) == 0) {
    +		  DohReplace(tm, "ref ", "", DOH_REPLACE_FIRST);
    +		  Printf(proxy_method_types, "typeof(%s).MakeByRefType()", tm);
    +		} else if (Strncmp(tm, "out ", 4) == 0) {
    +		  DohReplace(tm, "out ", "", DOH_REPLACE_FIRST);
    +		  Printf(proxy_method_types, "typeof(%s).MakeByRefType()", tm);
    +		} else {
    +		  Printf(proxy_method_types, "typeof(%s)", tm);
    +		}
     	      } else {
     		Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(pt, 0));
     	      }
    @@ -3777,13 +3816,45 @@ public:
           if ((tm = Swig_typemap_lookup("csdirectorout", n, "", 0))) {
     	substituteClassname(returntype, tm);
     	Replaceall(tm, "$cscall", upcall);
    -
    -	Printf(callback_code, "    return %s;\n", tm);
    +	// pre: and post: attribute support
    +	bool is_pre_code = Len(pre_code) > 0;
    +	bool is_post_code = Len(post_code) > 0;
    +	bool is_terminator_code = Len(terminator_code) > 0;
    +	if (is_pre_code || is_post_code || is_terminator_code) {
    +	  Insert(tm, 0, "      return ");
    +	  Printf(tm, ";");
    +	  if (is_post_code) {
    +	    Insert(tm, 0, "\n    try {\n ");
    +	    Printv(tm, "\n    }\n    finally {\n", post_code, "\n    }", NIL);
    +	  } else {
    +	    Insert(tm, 0, "\n    ");
    +	  }
    +	  if (is_pre_code) {
    +	    Insert(tm, 0, pre_code);
    +	    Insert(tm, 0, "\n");
    +	  }
    +	  if (is_terminator_code)
    +	    Printv(tm, "\n", terminator_code, NIL);
    +	  Printf(callback_code, "       %s\n", tm);
    +	} else {
    +	  Printf(callback_code, "    return %s;\n", tm);
    +	}
           }
    -
           Delete(tm);
    -    } else
    -      Printf(callback_code, "    %s;\n", upcall);
    +    } else {
    +      bool is_pre_code = Len(pre_code) > 0;
    +      bool is_post_code = Len(post_code) > 0;
    +      if (is_pre_code && is_post_code)
    +	Printf(callback_code, "    %s\n    try {\n    %s;\n    }\n    finally {\n    %s\n    }\n", pre_code, upcall, post_code);
    +      else if (is_pre_code)
    +	Printf(callback_code, "    %s\n    %s;\n", pre_code, upcall);
    +      else if (is_post_code)
    +	Printf(callback_code, "    try {\n    %s;\n    }\n    finally {\n    %s\n    }\n", upcall, post_code);
    +      else
    +	Printf(callback_code, "    %s;\n", upcall);
    +      if (Len(terminator_code) > 0)
    +	Printv(callback_code, "\n", terminator_code, NIL);
    +    }
     
         Printf(callback_code, "  }\n");
         Delete(upcall);
    @@ -3886,6 +3957,9 @@ public:
           Printf(director_connect_parms, "SwigDirector%s%s delegate%s", classname, methid, methid);
         }
     
    +    Delete(pre_code);
    +    Delete(post_code);
    +    Delete(terminator_code);
         Delete(qualified_return);
         Delete(declaration);
         Delete(callback_typedef_parms);
    
    From 6cb5b5487f414fb20524e557210669fbb0609a4b Mon Sep 17 00:00:00 2001
    From: "Brant K. Kyser" 
    Date: Tue, 8 Jan 2013 21:28:13 -0600
    Subject: [PATCH 0370/1160] Use NSPACE_SEPARATOR rather than liter string for
     package seperator.
    
    ---
     Source/Modules/lang.cxx | 2 +-
     Source/Swig/cwrap.c     | 4 ++--
     2 files changed, 3 insertions(+), 3 deletions(-)
    
    diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx
    index 7468774a3..dc21d7f96 100644
    --- a/Source/Modules/lang.cxx
    +++ b/Source/Modules/lang.cxx
    @@ -357,7 +357,7 @@ Language::~Language() {
         const char *attrib = "director:classname";
         String *classname = Getattr(n, "sym:name");
     
    -    Replace(nspace, ".", "_", DOH_REPLACE_ANY);
    +    Replace(nspace, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY);
         if (Len(nspace) > 0)
           dirclassname = NewStringf("SwigDirector_%s_%s", nspace, classname);
         else
    diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c
    index c4c4621a1..38787fc63 100644
    --- a/Source/Swig/cwrap.c
    +++ b/Source/Swig/cwrap.c
    @@ -857,7 +857,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
       String *qualifier = Getattr(n, "qualifier");
       String *directorScope = NewString(nspace);
     
    -  Replace(directorScope, ".", "_", DOH_REPLACE_ANY);
    +  Replace(directorScope, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY);
       
       /* If smart pointer without const overload or mutable method, change self dereferencing */
       if (flags & CWRAP_SMART_POINTER) {
    @@ -1116,7 +1116,7 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String
       int use_director;
       String *directorScope = NewString(nspace);
      
    -  Replace(directorScope, ".", "_", DOH_REPLACE_ANY);
    +  Replace(directorScope, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY);
     
       use_director = Swig_directorclass(n);
     
    
    From e1a59ae2c78e46d2593cdbe965da3330e3914494 Mon Sep 17 00:00:00 2001
    From: "Brant K. Kyser" 
    Date: Tue, 8 Jan 2013 21:38:57 -0600
    Subject: [PATCH 0371/1160] Clean up local variable name that store the
     director class's name to prevent confusion with the class name.
    
    ---
     Source/Modules/csharp.cxx | 29 +++++++++++++++--------------
     Source/Modules/d.cxx      | 29 +++++++++++++++--------------
     Source/Modules/java.cxx   |  9 +++++----
     3 files changed, 35 insertions(+), 32 deletions(-)
    
    diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx
    index d78253f1a..5010c6cee 100644
    --- a/Source/Modules/csharp.cxx
    +++ b/Source/Modules/csharp.cxx
    @@ -3890,7 +3890,7 @@ public:
         Node *parent = parentNode(n);
         String *decl = Getattr(n, "decl");
         String *supername = Swig_class_name(parent);
    -    String *classname = directorClassName(parent);
    +    String *dirclassname = directorClassName(parent);
         String *sub = NewString("");
         Parm *p;
         ParmList *superparms = Getattr(n, "parms");
    @@ -3914,11 +3914,11 @@ public:
           /* constructor */
           {
     	String *basetype = Getattr(parent, "classtype");
    -	String *target = Swig_method_decl(0, decl, classname, parms, 0, 0);
    +	String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 0);
     	String *call = Swig_csuperclass_call(0, basetype, superparms);
     	String *classtype = SwigType_namestr(Getattr(n, "name"));
     
    -	Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor"));
    +	Printf(f_directors, "%s::%s : %s, %s {\n", dirclassname, target, call, Getattr(parent, "director:ctor"));
     	Printf(f_directors, "  swig_init_callbacks();\n");
     	Printf(f_directors, "}\n\n");
     
    @@ -3929,7 +3929,7 @@ public:
     
           /* constructor header */
           {
    -	String *target = Swig_method_decl(0, decl, classname, parms, 0, 1);
    +	String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 1);
     	Printf(f_directors_h, "    %s;\n", target);
     	Delete(target);
           }
    @@ -3938,6 +3938,7 @@ public:
         Delete(sub);
         Delete(supername);
         Delete(parms);
    +    Delete(dirclassname);
         return Language::classDirectorConstructor(n);
       }
     
    @@ -3946,18 +3947,18 @@ public:
        * ------------------------------------------------------------ */
     
       int classDirectorDefaultConstructor(Node *n) {
    -    String *classname = directorClassName(n);
    +    String *dirclassname = directorClassName(n);
         String *classtype = SwigType_namestr(Getattr(n, "name"));
         Wrapper *w = NewWrapper();
     
    -    Printf(w->def, "%s::%s() : %s {", classname, classname, Getattr(n, "director:ctor"));
    +    Printf(w->def, "%s::%s() : %s {", dirclassname, dirclassname, Getattr(n, "director:ctor"));
         Printf(w->code, "}\n");
         Wrapper_print(w, f_directors);
     
    -    Printf(f_directors_h, "    %s();\n", classname);
    +    Printf(f_directors_h, "    %s();\n", dirclassname);
         DelWrapper(w);
         Delete(classtype);
    -    Delete(classname);
    +    Delete(dirclassname);
         return Language::classDirectorDefaultConstructor(n);
       }
     
    @@ -3998,15 +3999,15 @@ public:
     
       int classDirectorDestructor(Node *n) {
         Node *current_class = getCurrentClass();
    -    String *classname = directorClassName(current_class);
    +    String *dirclassname = directorClassName(current_class);
         Wrapper *w = NewWrapper();
     
         if (Getattr(n, "throw")) {
    -      Printf(f_directors_h, "    virtual ~%s() throw ();\n", classname);
    -      Printf(w->def, "%s::~%s() throw () {\n", classname, classname);
    +      Printf(f_directors_h, "    virtual ~%s() throw ();\n", dirclassname);
    +      Printf(w->def, "%s::~%s() throw () {\n", dirclassname, dirclassname);
         } else {
    -      Printf(f_directors_h, "    virtual ~%s();\n", classname);
    -      Printf(w->def, "%s::~%s() {\n", classname, classname);
    +      Printf(f_directors_h, "    virtual ~%s();\n", dirclassname);
    +      Printf(w->def, "%s::~%s() {\n", dirclassname, dirclassname);
         }
     
         Printv(w->code, "}\n", NIL);
    @@ -4014,7 +4015,7 @@ public:
         Wrapper_print(w, f_directors);
     
         DelWrapper(w);
    -    Delete(classname);
    +    Delete(dirclassname);
         return SWIG_OK;
       }
     
    diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx
    index b66f8d2be..46a6a2b07 100644
    --- a/Source/Modules/d.cxx
    +++ b/Source/Modules/d.cxx
    @@ -2401,7 +2401,7 @@ public:
         Node *parent = parentNode(n);
         String *decl = Getattr(n, "decl");;
         String *supername = Swig_class_name(parent);
    -    String *classname = directorClassName(parent);
    +    String *dirclassname = directorClassName(parent);
         String *sub = NewString("");
         Parm *p;
         ParmList *superparms = Getattr(n, "parms");
    @@ -2425,11 +2425,11 @@ public:
           /* constructor */
           {
     	String *basetype = Getattr(parent, "classtype");
    -	String *target = Swig_method_decl(0, decl, classname, parms, 0, 0);
    +	String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 0);
     	String *call = Swig_csuperclass_call(0, basetype, superparms);
     	String *classtype = SwigType_namestr(Getattr(n, "name"));
     
    -	Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor"));
    +	Printf(f_directors, "%s::%s : %s, %s {\n", dirclassname, target, call, Getattr(parent, "director:ctor"));
     	Printf(f_directors, "  swig_init_callbacks();\n");
     	Printf(f_directors, "}\n\n");
     
    @@ -2440,7 +2440,7 @@ public:
     
           /* constructor header */
           {
    -	String *target = Swig_method_decl(0, decl, classname, parms, 0, 1);
    +	String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 1);
     	Printf(f_directors_h, "    %s;\n", target);
     	Delete(target);
           }
    @@ -2449,6 +2449,7 @@ public:
         Delete(sub);
         Delete(supername);
         Delete(parms);
    +    Delete(dirclassname);
         return Language::classDirectorConstructor(n);
       }
     
    @@ -2456,18 +2457,18 @@ public:
        * D::classDirectorDefaultConstructor()
        * --------------------------------------------------------------------------- */
       virtual int classDirectorDefaultConstructor(Node *n) {
    -    String *classname = directorClassName(n);
    +    String *dirclassname = directorClassName(n);
         String *classtype = SwigType_namestr(Getattr(n, "name"));
         Wrapper *w = NewWrapper();
     
    -    Printf(w->def, "%s::%s() : %s {", classname, classname, Getattr(n, "director:ctor"));
    +    Printf(w->def, "%s::%s() : %s {", dirclassname, dirclassname, Getattr(n, "director:ctor"));
         Printf(w->code, "}\n");
         Wrapper_print(w, f_directors);
     
    -    Printf(f_directors_h, "    %s();\n", classname);
    +    Printf(f_directors_h, "    %s();\n", dirclassname);
         DelWrapper(w);
         Delete(classtype);
    -    Delete(classname);
    +    Delete(dirclassname);
         return Language::classDirectorDefaultConstructor(n);
       }
     
    @@ -2476,15 +2477,15 @@ public:
        * --------------------------------------------------------------------------- */
       virtual int classDirectorDestructor(Node *n) {
         Node *current_class = getCurrentClass();
    -    String *classname = directorClassName(current_class);
    +    String *dirclassname = directorClassName(current_class);
         Wrapper *w = NewWrapper();
     
         if (Getattr(n, "throw")) {
    -      Printf(f_directors_h, "    virtual ~%s() throw ();\n", classname);
    -      Printf(w->def, "%s::~%s() throw () {\n", classname, classname);
    +      Printf(f_directors_h, "    virtual ~%s() throw ();\n", dirclassname);
    +      Printf(w->def, "%s::~%s() throw () {\n", dirclassname, dirclassname);
         } else {
    -      Printf(f_directors_h, "    virtual ~%s();\n", classname);
    -      Printf(w->def, "%s::~%s() {\n", classname, classname);
    +      Printf(f_directors_h, "    virtual ~%s();\n", dirclassname);
    +      Printf(w->def, "%s::~%s() {\n", dirclassname, dirclassname);
         }
     
         Printv(w->code, "}\n", NIL);
    @@ -2492,7 +2493,7 @@ public:
         Wrapper_print(w, f_directors);
     
         DelWrapper(w);
    -    Delete(classname);
    +    Delete(dirclassname);
         return SWIG_OK;
       }
     
    diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx
    index 28d8b88aa..b4703bd3e 100644
    --- a/Source/Modules/java.cxx
    +++ b/Source/Modules/java.cxx
    @@ -4099,7 +4099,7 @@ public:
         Node *parent = parentNode(n);
         String *decl = Getattr(n, "decl");
         String *supername = Swig_class_name(parent);
    -    String *classname = directorClassName(parent);
    +    String *dirclassname = directorClassName(parent);
         String *sub = NewString("");
         Parm *p;
         ParmList *superparms = Getattr(n, "parms");
    @@ -4131,11 +4131,11 @@ public:
           /* constructor */
           {
     	String *basetype = Getattr(parent, "classtype");
    -	String *target = Swig_method_decl(0, decl, classname, parms, 0, 0);
    +	String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 0);
     	String *call = Swig_csuperclass_call(0, basetype, superparms);
     	String *classtype = SwigType_namestr(Getattr(n, "name"));
     
    -	Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor"));
    +	Printf(f_directors, "%s::%s : %s, %s {\n", dirclassname, target, call, Getattr(parent, "director:ctor"));
     	Printf(f_directors, "}\n\n");
     
     	Delete(classtype);
    @@ -4145,7 +4145,7 @@ public:
     
           /* constructor header */
           {
    -	String *target = Swig_method_decl(0, decl, classname, parms, 0, 1);
    +	String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 1);
     	Printf(f_directors_h, "    %s;\n", target);
     	Delete(target);
           }
    @@ -4155,6 +4155,7 @@ public:
         Delete(supername);
         Delete(jenv_type);
         Delete(parms);
    +    Delete(dirclassname);
         return Language::classDirectorConstructor(n);
       }
     
    
    From 13d9e19cdbb9c3dc6d89fc0a44a97d66051d0068 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Fri, 11 Jan 2013 06:19:24 +0000
    Subject: [PATCH 0372/1160] Fix spacing in generated code for csdirectorin
     'pre', 'post' and 'terminator' attributes. Add some more tests for these
     attributes.
    
    ---
     .../test-suite/csharp/csharp_prepost_runme.cs | 16 ++++++
     Examples/test-suite/csharp_prepost.i          | 15 ++---
     Source/Modules/csharp.cxx                     | 56 ++++++-------------
     3 files changed, 41 insertions(+), 46 deletions(-)
    
    diff --git a/Examples/test-suite/csharp/csharp_prepost_runme.cs b/Examples/test-suite/csharp/csharp_prepost_runme.cs
    index 8842a79b3..ca3979065 100644
    --- a/Examples/test-suite/csharp/csharp_prepost_runme.cs
    +++ b/Examples/test-suite/csharp/csharp_prepost_runme.cs
    @@ -15,6 +15,11 @@ public class csharp_prepost_runme {
           Assert(vpost.Count, 2);
           vpost.Add(1.0);
         }
    +    public override int methodint(ref double[] vpre, DoubleVector vpost)
    +    {
    +      method(ref vpre, vpost);
    +      return vpost.Count;
    +    }
       }
       public static void Main() {
         {
    @@ -58,6 +63,17 @@ public class csharp_prepost_runme {
           Assert(vpre[0], 2.0);
           Assert(vpost.Count, 3);
         }
    +    {
    +      PrePost3_Derived p = new PrePost3_Derived();
    +      double[] vpre = new double[] { 1.0 };
    +      DoubleVector vpost = new DoubleVector();
    +      vpost.Add(3.0);
    +      vpost.Add(4.0);
    +      int size = p.methodint(ref vpre, vpost);
    +      Assert(vpre[0], 2.0);
    +      Assert(vpost.Count, 3);
    +      Assert(size, 3);
    +    }
     
         // Check attributes are generated for the constructor helper function
         {
    diff --git a/Examples/test-suite/csharp_prepost.i b/Examples/test-suite/csharp_prepost.i
    index 4f5a49362..32ee10677 100644
    --- a/Examples/test-suite/csharp_prepost.i
    +++ b/Examples/test-suite/csharp_prepost.i
    @@ -80,14 +80,14 @@ struct PrePost2 {
     // Check csdirectorin pre and post attributes
     // ref param
     %typemap(csdirectorin,
    -   pre="      DoubleVector d$iminput = new DoubleVector($iminput, false);\n"
    -       "      int count$iminput = d$iminput.Count;\n"
    -       "      double[] v$iminput = new double[count$iminput];\n"
    -       "      for (int i=0; i &vpre
       "ref v$iminput"
    @@ -106,6 +106,7 @@ struct PrePost3 {
       }
       virtual ~PrePost3(){}
       virtual void method(std::vector & vpre, std::vector & vpost) {}
    +  virtual int methodint(std::vector & vpre, std::vector & vpost) { return 0; }
     };
     %}
     
    diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx
    index f559d23aa..81b3b3f8b 100644
    --- a/Source/Modules/csharp.cxx
    +++ b/Source/Modules/csharp.cxx
    @@ -3678,7 +3678,7 @@ public:
     	      substituteClassname(pt, din);
     	      Replaceall(din, "$iminput", ln);
     
    -	      // :pre and :post attribute support
    +	      // pre and post attribute support
     	      String *pre = Getattr(p, "tmap:csdirectorin:pre");
     	      if (pre) {
     		substituteClassname(pt, pre);
    @@ -3703,7 +3703,6 @@ public:
     		Insert(terminator_code, 0, "\n");
     		Insert(terminator_code, 0, terminator);
     	      }
    -	      // end :pre and :post attribute support
     
     	      if (i > 0) {
     		Printf(delegate_parms, ", ");
    @@ -3721,10 +3720,10 @@ public:
     	      if ((tm = Getattr(p, "tmap:cstype"))) {
     		substituteClassname(pt, tm);
     		if (Strncmp(tm, "ref ", 4) == 0) {
    -		  DohReplace(tm, "ref ", "", DOH_REPLACE_FIRST);
    +		  Replace(tm, "ref ", "", DOH_REPLACE_FIRST);
     		  Printf(proxy_method_types, "typeof(%s).MakeByRefType()", tm);
     		} else if (Strncmp(tm, "out ", 4) == 0) {
    -		  DohReplace(tm, "out ", "", DOH_REPLACE_FIRST);
    +		  Replace(tm, "out ", "", DOH_REPLACE_FIRST);
     		  Printf(proxy_method_types, "typeof(%s).MakeByRefType()", tm);
     		} else {
     		  Printf(proxy_method_types, "typeof(%s)", tm);
    @@ -3812,47 +3811,26 @@ public:
     
         String *upcall = NewStringf("%s(%s)", symname, imcall_args);
     
    -    if (!is_void) {
    -      if ((tm = Swig_typemap_lookup("csdirectorout", n, "", 0))) {
    -	substituteClassname(returntype, tm);
    -	Replaceall(tm, "$cscall", upcall);
    -	// pre: and post: attribute support
    -	bool is_pre_code = Len(pre_code) > 0;
    -	bool is_post_code = Len(post_code) > 0;
    -	bool is_terminator_code = Len(terminator_code) > 0;
    -	if (is_pre_code || is_post_code || is_terminator_code) {
    -	  Insert(tm, 0, "      return ");
    -	  Printf(tm, ";");
    -	  if (is_post_code) {
    -	    Insert(tm, 0, "\n    try {\n ");
    -	    Printv(tm, "\n    }\n    finally {\n", post_code, "\n    }", NIL);
    -	  } else {
    -	    Insert(tm, 0, "\n    ");
    -	  }
    -	  if (is_pre_code) {
    -	    Insert(tm, 0, pre_code);
    -	    Insert(tm, 0, "\n");
    -	  }
    -	  if (is_terminator_code)
    -	    Printv(tm, "\n", terminator_code, NIL);
    -	  Printf(callback_code, "       %s\n", tm);
    -	} else {
    -	  Printf(callback_code, "    return %s;\n", tm);
    -	}
    -      }
    -      Delete(tm);
    -    } else {
    +    if ((tm = Swig_typemap_lookup("csdirectorout", n, "", 0))) {
    +      substituteClassname(returntype, tm);
    +      Replaceall(tm, "$cscall", upcall);
    +      if (!is_void)
    +	Insert(tm, 0, "return ");
    +      Replaceall(tm, "\n ", "\n   "); // add extra indentation to code in typemap
    +
    +      // pre and post attribute support
           bool is_pre_code = Len(pre_code) > 0;
           bool is_post_code = Len(post_code) > 0;
    +      bool is_terminator_code = Len(terminator_code) > 0;
           if (is_pre_code && is_post_code)
    -	Printf(callback_code, "    %s\n    try {\n    %s;\n    }\n    finally {\n    %s\n    }\n", pre_code, upcall, post_code);
    +	Printf(callback_code, "%s\n    try {\n      %s;\n    } finally {\n%s\n    }\n", pre_code, tm, post_code);
           else if (is_pre_code)
    -	Printf(callback_code, "    %s\n    %s;\n", pre_code, upcall);
    +	Printf(callback_code, "%s\n    %s;\n", pre_code, tm);
           else if (is_post_code)
    -	Printf(callback_code, "    try {\n    %s;\n    }\n    finally {\n    %s\n    }\n", upcall, post_code);
    +	Printf(callback_code, "    try {\n      %s;\n    } finally {\n%s\n    }\n", tm, post_code);
           else
    -	Printf(callback_code, "    %s;\n", upcall);
    -      if (Len(terminator_code) > 0)
    +	Printf(callback_code, "    %s;\n", tm);
    +      if (is_terminator_code)
     	Printv(callback_code, "\n", terminator_code, NIL);
         }
     
    
    From 245b8a0b344dce99e24c13a01da56fd9fafea9b6 Mon Sep 17 00:00:00 2001
    From: Vladimir Kalinin 
    Date: Fri, 11 Jan 2013 21:46:40 +0400
    Subject: [PATCH 0373/1160] Documentation for csdirectorin 'pre', 'post' and
     'terminator' support.
    
    ---
     Doc/Manual/CSharp.html | 47 +++++++++++++++++++++++++++++++++++++++++-
     1 file changed, 46 insertions(+), 1 deletion(-)
    
    diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html
    index a5394eb37..1281f7973 100644
    --- a/Doc/Manual/CSharp.html
    +++ b/Doc/Manual/CSharp.html
    @@ -197,11 +197,56 @@ csattributes                C# attributes for attaching to proxy classes/enums
     The "null" attribute in the "out" typemap can be specified to provide a value for $null to expand into for wrapped functions that return non-void. Normally the default value of 0 is used.
     For example this is needed if you change the return type to void:
     

    -
     %typemap(ctype) Status "void"
     %typemap(out, null="") Status { ... }
     
    +

    +The "pre" and "post" attributes in "csdirectorin" typemap act like the same attributes in "csin" typemap. + For example if we modify Date marshalling example like this: +

    +class CDate {
    +...
    +  void setYear(int);
    +  void setMonth(int);
    +  void setDay(int);
    +};
    +struct Action {
    +virtual void someCallback(CDate& date);
    +...
    +};
    +
    +and declare %feature ("director") for the Action class, we would have to define additional +marshaling rules for CDate. Director typemap may look like this: +
    +%typemap(csdirectorin,
    +         pre="System.DateTime temp$iminput = new System.DateTime();",
    +         post="CDate temp2$iminput = new CDate($iminput, false);\n"
    +              "temp2$iminput.setYear(tempdate.Year);\n"
    +              "temp2$iminput.setMonth(tempdate.Month);\n"
    +              "temp2$iminput.setDay(tempdate.Day);"
    +         ) CDate& date "out temp$iminput"
    +
    +The generated proxy class code will then contain the following wrapper for calling user-overloaded someCallback(): +
    +...
    +  private void SwigDirectorsomeCallback(IntPtr date) {
    +    System.DateTime tempdate = new System.DateTime();
    +    try {
    +      someCallback(out tempdate);
    +    }
    +    finally {
    +    // we create managed wrapper around existing C reference, just for convenience
    +      CDate temp2date = new CDate(date, false);
    +      temp2date.setYear(tempdate.Year);
    +      temp2date.setMonth(tempdate.Month);
    +      temp2date.setDay(tempdate.Day);
    +    }
    +  }
    +...
    +
    +Pay special attention to the memory management issues, using these attributes. +

    From a1c3e54ab4bd6e2258aaecc7cf2d78af1a5bba29 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 Jan 2013 21:59:38 +0000 Subject: [PATCH 0374/1160] Improvements to documentation for csdirectorin 'pre', 'post' and 'terminator' support. --- CHANGES.current | 3 + Doc/Manual/CSharp.html | 122 ++++++++++++++++++++++----------------- Doc/Manual/Contents.html | 1 + 3 files changed, 74 insertions(+), 52 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 05d533c17..e75e04dac 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-01-11: Vladimir Kalinin + [C#] Add support for csdirectorin 'pre', 'post' and 'terminator' attributes. + 2013-01-08: olly [PHP] Fix to work with a ZTS build of PHP (broken in 2.0.7). diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index 1281f7973..6df2594c4 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -38,6 +38,7 @@
  • Memory management for objects passed to the C++ layer
  • Date marshalling using the csin typemap and associated attributes
  • A date example demonstrating marshalling of C# properties +
  • Date example demonstrating the 'pre' and 'post' typemap attributes for directors
  • Turning wrapped classes into partial classes
  • Extending proxy classes with additional C# code
  • Underlying type for enums @@ -201,52 +202,6 @@ For example this is needed if you change the return type to void: %typemap(ctype) Status "void" %typemap(out, null="") Status { ... }
  • -

    -The "pre" and "post" attributes in "csdirectorin" typemap act like the same attributes in "csin" typemap. - For example if we modify Date marshalling example like this: -

    -class CDate {
    -...
    -  void setYear(int);
    -  void setMonth(int);
    -  void setDay(int);
    -};
    -struct Action {
    -virtual void someCallback(CDate& date);
    -...
    -};
    -
    -and declare %feature ("director") for the Action class, we would have to define additional -marshaling rules for CDate. Director typemap may look like this: -
    -%typemap(csdirectorin,
    -         pre="System.DateTime temp$iminput = new System.DateTime();",
    -         post="CDate temp2$iminput = new CDate($iminput, false);\n"
    -              "temp2$iminput.setYear(tempdate.Year);\n"
    -              "temp2$iminput.setMonth(tempdate.Month);\n"
    -              "temp2$iminput.setDay(tempdate.Day);"
    -         ) CDate& date "out temp$iminput"
    -
    -The generated proxy class code will then contain the following wrapper for calling user-overloaded someCallback(): -
    -...
    -  private void SwigDirectorsomeCallback(IntPtr date) {
    -    System.DateTime tempdate = new System.DateTime();
    -    try {
    -      someCallback(out tempdate);
    -    }
    -    finally {
    -    // we create managed wrapper around existing C reference, just for convenience
    -      CDate temp2date = new CDate(date, false);
    -      temp2date.setYear(tempdate.Year);
    -      temp2date.setMonth(tempdate.Month);
    -      temp2date.setDay(tempdate.Day);
    -    }
    -  }
    -...
    -
    -Pay special attention to the memory management issues, using these attributes. -

    @@ -287,10 +242,12 @@ $jnicall -> $imcall

    Unlike the "javain" typemap, the "csin" typemap does not support the 'pgcpp' attribute as the C# module does not have a premature garbage collection prevention parameter. The "csin" typemap supports additional optional attributes called 'cshin' and 'terminator'. +The "csdirectorin" typemap supports additional optional attributes called 'terminator'. The 'cshin' attribute should contain the parameter type and name whenever a constructor helper function is generated due to the 'pre' or 'post' attributes. The 'terminator' attribute normally just contains a closing brace for when the 'pre' attribute contains an opening brace, such as when a C# using or fixed block is started. Note that 'pre', 'post', 'terminator' and 'cshin' attributes are not used for marshalling the property set. Please see the Date marshalling example and Date marshalling of properties example for further understanding of these "csin" applicable attributes. +Please see the Date marshalling director example for further understanding of the "csdirectorin" attributes.

    @@ -2100,13 +2057,13 @@ The typemaps to achieve this are shown below.
    -%typemap(cstype) const CDate& "System.DateTime"
    +%typemap(cstype) const CDate & "System.DateTime"
     %typemap(csin, 
              pre="    CDate temp$csinput = new CDate($csinput.Year, $csinput.Month, $csinput.Day);"
             ) const CDate &
              "$csclassname.getCPtr(temp$csinput)"
     
    -%typemap(cstype) CDate& "out System.DateTime"
    +%typemap(cstype) CDate & "out System.DateTime"
     %typemap(csin, 
              pre="    CDate temp$csinput = new CDate();", 
              post="      $csinput = new System.DateTime(temp$csinput.getYear(),"
    @@ -2317,7 +2274,7 @@ Console.WriteLine("Important date: " + importantDate);
     

    -When SWIG wraps a variable that is a class/struct/union, it is wrapped using a pointer to the type for the reasons given in Stucture data members. +When SWIG wraps a variable that is a class/struct/union, it is wrapped using a pointer to the type for the reasons given in Structure data members. The typemap type required is thus CDate *. Given that the previous section already designed CDate * typemaps, we'll use those same typemaps plus the 'csvarin' and 'csvarout' typemaps.

    @@ -2389,8 +2346,69 @@ Some points to note:
  • The 'csin' typemap has 'pre', 'post' and 'cshin' attributes, and these are all ignored in the property set. The code in these attributes must instead be replicated within the 'csvarin' typemap. The line creating the temp$csinput variable is such an example; it is identical to what is in the 'pre' attribute. +

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

    -

    19.8.5 Turning wrapped classes into partial classes

    + +

    +The 'pre' and 'post' attributes in the "csdirectorin" typemap act like the attributes of the same name in the "csin" typemap. +For example if we modify the Date marshalling example like this: +

    + +
    +class CDate {
    +  ...
    +  void setYear(int);
    +  void setMonth(int);
    +  void setDay(int);
    +};
    +struct Action {
    +  virtual void someCallback(CDate &date);
    +  virtual ~Action();
    +  ...
    +};
    +
    + +

    +and declare %feature ("director") for the Action class, we would have to define additional +marshalling rules for CDate & parameter. The typemap may look like this: +

    + +
    +%typemap(csdirectorin,
    +         pre="System.DateTime temp$iminput = new System.DateTime();",
    +         post="CDate temp2$iminput = new CDate($iminput, false);\n"
    +              "temp2$iminput.setYear(tempdate.Year);\n"
    +              "temp2$iminput.setMonth(tempdate.Month);\n"
    +              "temp2$iminput.setDay(tempdate.Day);"
    +         ) CDate &date "out temp$iminput"
    +
    + +

    +The generated proxy class code will then contain the following wrapper for calling user-overloaded someCallback(): +

    + +
    +...
    +  private void SwigDirectorsomeCallback(IntPtr date) {
    +    System.DateTime tempdate = new System.DateTime();
    +    try {
    +      someCallback(out tempdate);
    +    } finally {
    +      // we create a managed wrapper around the existing C reference, just for convenience
    +      CDate temp2date = new CDate(date, false);
    +      temp2date.setYear(tempdate.Year);
    +      temp2date.setMonth(tempdate.Month);
    +      temp2date.setDay(tempdate.Day);
    +    }
    +  }
    +...
    +
    +

    +Pay special attention to the memory management issues, using these attributes. +

    + + +

    19.8.6 Turning wrapped classes into partial classes

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

    -

    19.8.6 Extending proxy classes with additional C# code

    +

    19.8.7 Extending proxy classes with additional C# code

    @@ -2529,7 +2547,7 @@ public class ExtendMe : IDisposable {

  • -

    19.8.7 Underlying type for enums

    +

    19.8.8 Underlying type for enums

    diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 74040ff0e..42e135140 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -686,6 +686,7 @@

  • Memory management for objects passed to the C++ layer
  • Date marshalling using the csin typemap and associated attributes
  • A date example demonstrating marshalling of C# properties +
  • Date example demonstrating the 'pre' and 'post' typemap attributes for directors
  • Turning wrapped classes into partial classes
  • Extending proxy classes with additional C# code
  • Underlying type for enums From 62d2ec5a12aa7db6cb4a4b36ef9536fe4c77077c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 Jan 2013 19:41:26 +0000 Subject: [PATCH 0375/1160] Update .gitignore for C# test-suite --- .gitignore | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 8509eebd3..928b0ac07 100644 --- a/.gitignore +++ b/.gitignore @@ -9,12 +9,6 @@ pcre *.gz -# Python generated files, based on: -# https://github.com/github/gitignore/blob/master/Python.gitignore -*.py[cod] -*/__pycache__/ -/__pycache__/ - # C/C++ object files, based on: # https://github.com/github/gitignore/blob/master/C.gitignore # https://github.com/github/gitignore/blob/master/C%2B%2B.gitignore @@ -113,3 +107,14 @@ Examples/test-suite/r/*/ Examples/test-suite/ruby/*/ Examples/test-suite/tcl/*/ Examples/test-suite/uffi/*/ + +# Python generated files, based on: +# https://github.com/github/gitignore/blob/master/Python.gitignore +*.py[cod] +*/__pycache__/ +/__pycache__/ + +# C# generated files +*_runme.exe.mdb +*_runme.exe + From 1fe1bb254373ef324408eb08ddad92e020988625 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 Jan 2013 21:57:43 +0000 Subject: [PATCH 0376/1160] Update .gitignore for generated documentation --- .gitignore | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 928b0ac07..800ac4669 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,9 @@ *.o *.class -# Editor junk +# Editor files and various other junk *.sw? +*.bak # Local PCRE pcre @@ -84,6 +85,12 @@ Source/CParse/parser.h Source/eswig swig +# Generated documentation +Doc/Manual/CCache.html +Doc/Manual/SWIGDocumentation.html +Doc/Manual/SWIGDocumentation.pdf +Doc/Manual/*.book + # Test Suite Generated Files Examples/test-suite/allegrocl/*/ Examples/test-suite/cffi/*/ From 7408332eb59f5c852331eead60a8f7b460272980 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 Jan 2013 23:46:32 +0000 Subject: [PATCH 0377/1160] Add notes on SF Bug #1299 - nspace and class name collisions --- CHANGES.current | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index e75e04dac..0d6a69959 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.10 (in progress) ============================ +2013-01-11: Brant Kyser + [Java, C#, D] SF Bug #1299 - Fix generated names for when %nspace is used on + classes with the same name in two different namespaces. + 2013-01-11: Vladimir Kalinin [C#] Add support for csdirectorin 'pre', 'post' and 'terminator' attributes. From acfc4cad3b0e01280520cff6bb10e9e7f6ffa0c4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 12 Jan 2013 00:23:16 +0000 Subject: [PATCH 0378/1160] Update README file --- README | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/README b/README index 305edf078..d69e7c6d8 100644 --- a/README +++ b/README @@ -3,9 +3,11 @@ SWIG (Simplified Wrapper and Interface Generator) Version: 2.0.10 (in progress) Tagline: SWIG is a compiler that integrates C and C++ with languages - including Perl, Python, Tcl, Ruby, PHP, Java, Ocaml, Lua, - Scheme (Guile, MzScheme, CHICKEN), Pike, C#, Modula-3, - Common Lisp (CLISP, Allegro CL, CFFI, UFFI), Octave and R. + including Perl, Python, Tcl, Ruby, PHP, Java, C#, D, Go, Lua, + Octave, R, Scheme (Guile, MzScheme/Racket, CHICKEN), Ocaml, + Modula-3, Common Lisp (CLISP, Allegro CL, CFFI, UFFI) and Pike. + SWIG can also export its parse tree into Lisp s-expressions and + XML. SWIG reads annotated C/C++ header files and creates wrapper code (glue code) in order to make the corresponding C/C++ libraries available to @@ -31,6 +33,22 @@ new features for the current release. The CHANGES file contains bug fixes and new features for older versions. A summary of changes in each release can be found in the RELEASENOTES file. +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 (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. + +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. + +Documentation is also online at http://www.swig.org/doc.html. + Backwards Compatibility ======================= The developers strive their best to preserve backwards compatibility @@ -97,9 +115,6 @@ minimal effect. All they do is reduce the amount of testing done with 'make check'. The SWIG executable and library files installed cannot currently be configured with a subset of target languages. -Please see the Documentation section below on installing documentation as -none is installed by default. - SWIG used to include a set of runtime libraries for some languages for working with multiple modules. These are no longer built during the installation stage. However, users can build them just like any wrapper module as described in @@ -108,7 +123,7 @@ examples which build the runtime library. Notes: -(1) If you checked the code out via SVN, you will have to run ./autogen.sh +(1) If you checked the code out via Git, you will have to run ./autogen.sh 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 @@ -175,8 +190,9 @@ The Examples directory contains a variety of examples of using SWIG and it has some browsable documentation. Simply point your browser to the file "Example/index.html". -The Examples directory also includes Visual C++ project (.dsp) files for -building some of the examples on Windows. +The Examples directory also includes Visual C++ project 6 (.dsp) files for +building some of the examples on Windows. Later versions of Visual Studio +will convert these old style project files into a current solution file. Known Issues ============ @@ -215,20 +231,6 @@ installed. To fix this: If you are having other troubles, you might look at the SWIG Wiki at http://www.dabeaz.com/cgi-bin/wiki.pl. -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 (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. - -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. - Participate! ============ Please report any errors and submit patches (if possible)! We only From 5b108acab6595d1d52d6a4b42e93b8a1317c5d53 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 12 Jan 2013 00:27:17 +0000 Subject: [PATCH 0379/1160] Remove seemingly useless .project file --- .project | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 .project diff --git a/.project b/.project deleted file mode 100644 index 86af75213..000000000 --- a/.project +++ /dev/null @@ -1,11 +0,0 @@ - - - SWIG - - - - - - - - From e2a0b892484590ce8b5a742fbea0dc781154ad94 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 12 Jan 2013 00:57:17 +0000 Subject: [PATCH 0380/1160] Rename configure.in files to expected modern name configure.ac --- CCache/{configure.in => configure.ac} | 0 configure.in => configure.ac | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename CCache/{configure.in => configure.ac} (100%) rename configure.in => configure.ac (100%) diff --git a/CCache/configure.in b/CCache/configure.ac similarity index 100% rename from CCache/configure.in rename to CCache/configure.ac diff --git a/configure.in b/configure.ac similarity index 100% rename from configure.in rename to configure.ac From 7841a0d097e679baafe06c29539b686b50eb144b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 12 Jan 2013 01:21:16 +0000 Subject: [PATCH 0381/1160] Remove cvs/svn Id strings --- Source/CParse/cscanner.c | 2 -- Source/CParse/parser.y | 2 -- Source/CParse/templ.c | 2 -- Source/CParse/util.c | 2 -- Source/DOH/base.c | 2 -- Source/DOH/file.c | 2 -- Source/DOH/fio.c | 2 -- Source/DOH/hash.c | 2 -- Source/DOH/list.c | 2 -- Source/DOH/memory.c | 2 -- Source/DOH/string.c | 2 -- Source/DOH/void.c | 2 -- Source/Modules/allegrocl.cxx | 2 -- Source/Modules/allocate.cxx | 2 -- Source/Modules/browser.cxx | 2 -- Source/Modules/cffi.cxx | 2 -- Source/Modules/chicken.cxx | 2 -- Source/Modules/clisp.cxx | 2 -- Source/Modules/contract.cxx | 2 -- Source/Modules/csharp.cxx | 2 -- Source/Modules/d.cxx | 2 -- Source/Modules/directors.cxx | 2 -- Source/Modules/emit.cxx | 2 -- Source/Modules/go.cxx | 2 -- Source/Modules/guile.cxx | 2 -- Source/Modules/java.cxx | 2 -- Source/Modules/lang.cxx | 2 -- Source/Modules/lua.cxx | 2 -- Source/Modules/main.cxx | 2 -- Source/Modules/modula3.cxx | 2 -- Source/Modules/module.cxx | 2 -- Source/Modules/mzscheme.cxx | 2 -- Source/Modules/ocaml.cxx | 2 -- Source/Modules/octave.cxx | 2 -- Source/Modules/overload.cxx | 2 -- Source/Modules/perl5.cxx | 2 -- Source/Modules/php.cxx | 2 -- Source/Modules/pike.cxx | 2 -- Source/Modules/python.cxx | 2 -- Source/Modules/r.cxx | 2 -- Source/Modules/ruby.cxx | 2 -- Source/Modules/s-exp.cxx | 2 -- Source/Modules/swigmain.cxx | 2 -- Source/Modules/tcl8.cxx | 2 -- Source/Modules/typepass.cxx | 2 -- Source/Modules/uffi.cxx | 2 -- Source/Modules/utils.cxx | 2 -- Source/Modules/xml.cxx | 2 -- Source/Preprocessor/cpp.c | 2 -- Source/Preprocessor/expr.c | 2 -- Source/Swig/cwrap.c | 2 -- Source/Swig/deprecate.c | 2 -- Source/Swig/error.c | 2 -- Source/Swig/fragment.c | 2 -- Source/Swig/getopt.c | 2 -- Source/Swig/include.c | 2 -- Source/Swig/misc.c | 2 -- Source/Swig/naming.c | 2 -- Source/Swig/parms.c | 2 -- Source/Swig/scanner.c | 2 -- Source/Swig/stype.c | 2 -- Source/Swig/symbol.c | 2 -- Source/Swig/tree.c | 2 -- Source/Swig/typemap.c | 2 -- Source/Swig/typeobj.c | 2 -- Source/Swig/typesys.c | 2 -- Source/Swig/wrapfunc.c | 2 -- 67 files changed, 134 deletions(-) diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index b52618606..791cf5949 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -15,8 +15,6 @@ * C identifiers up into keywords and SWIG directives. * ----------------------------------------------------------------------------- */ -char cvsroot_cscanner_c[] = "$Id$"; - #include "cparse.h" #include "parser.h" #include diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index e4f3d67b2..c93f44cd0 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -17,8 +17,6 @@ #define yylex yylex -char cvsroot_parser_y[] = "$Id$"; - #include "swig.h" #include "cparse.h" #include "preprocessor.h" diff --git a/Source/CParse/templ.c b/Source/CParse/templ.c index b14cd1e4d..ed6acfc8c 100644 --- a/Source/CParse/templ.c +++ b/Source/CParse/templ.c @@ -11,8 +11,6 @@ * Expands a template into a specialized version. * ----------------------------------------------------------------------------- */ -char cvsroot_templ_c[] = "$Id$"; - #include "swig.h" #include "cparse.h" diff --git a/Source/CParse/util.c b/Source/CParse/util.c index fa934ffc0..7572dff10 100644 --- a/Source/CParse/util.c +++ b/Source/CParse/util.c @@ -11,8 +11,6 @@ * Parsing utilities. * ----------------------------------------------------------------------------- */ -char cvsroot_util_c[] = "$Id$"; - #include "swig.h" #include "cparse.h" diff --git a/Source/DOH/base.c b/Source/DOH/base.c index e64b0f561..1f92b6542 100644 --- a/Source/DOH/base.c +++ b/Source/DOH/base.c @@ -12,8 +12,6 @@ * DOH objects. A number of small utility functions are also included. * ----------------------------------------------------------------------------- */ -char cvsroot_base_c[] = "$Id$"; - #include "dohint.h" /* ----------------------------------------------------------------------------- diff --git a/Source/DOH/file.c b/Source/DOH/file.c index 11482fa7f..7409ebbfb 100644 --- a/Source/DOH/file.c +++ b/Source/DOH/file.c @@ -12,8 +12,6 @@ * ordinary FILE * or integer file descriptor. * ----------------------------------------------------------------------------- */ -char cvsroot_file_c[] = "$Id$"; - #include "dohint.h" #ifdef DOH_INTFILE diff --git a/Source/DOH/fio.c b/Source/DOH/fio.c index 573bebe7b..5693deeb5 100644 --- a/Source/DOH/fio.c +++ b/Source/DOH/fio.c @@ -12,8 +12,6 @@ * formatted output, readline, and splitting. * ----------------------------------------------------------------------------- */ -char cvsroot_fio_c[] = "$Id$"; - #include "dohint.h" #define OBUFLEN 512 diff --git a/Source/DOH/hash.c b/Source/DOH/hash.c index 566cb349a..c2bc3dd95 100644 --- a/Source/DOH/hash.c +++ b/Source/DOH/hash.c @@ -11,8 +11,6 @@ * Implements a simple hash table object. * ----------------------------------------------------------------------------- */ -char cvsroot_hash_c[] = "$Id$"; - #include "dohint.h" extern DohObjInfo DohHashType; diff --git a/Source/DOH/list.c b/Source/DOH/list.c index d20311150..8a96a9a60 100644 --- a/Source/DOH/list.c +++ b/Source/DOH/list.c @@ -11,8 +11,6 @@ * Implements a simple list object. * ----------------------------------------------------------------------------- */ -char cvsroot_list_c[] = "$Id$"; - #include "dohint.h" typedef struct List { diff --git a/Source/DOH/memory.c b/Source/DOH/memory.c index 5ad11019d..b916870d7 100644 --- a/Source/DOH/memory.c +++ b/Source/DOH/memory.c @@ -12,8 +12,6 @@ * of objects and checking of objects. * ----------------------------------------------------------------------------- */ -char cvsroot_memory_c[] = "$Id$"; - #include "dohint.h" #ifndef DOH_POOL_SIZE diff --git a/Source/DOH/string.c b/Source/DOH/string.c index d34301691..50676c7c3 100644 --- a/Source/DOH/string.c +++ b/Source/DOH/string.c @@ -12,8 +12,6 @@ * file semantics. * ----------------------------------------------------------------------------- */ -char cvsroot_string_c[] = "$Id$"; - #include "dohint.h" extern DohObjInfo DohStringType; diff --git a/Source/DOH/void.c b/Source/DOH/void.c index 2d684b9cd..6111a8c49 100644 --- a/Source/DOH/void.c +++ b/Source/DOH/void.c @@ -12,8 +12,6 @@ * an arbitrary C object represented as a void *. * ----------------------------------------------------------------------------- */ -char cvsroot_void_c[] = "$Id$"; - #include "dohint.h" typedef struct { diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index 1e0c6c98b..93477057f 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -11,8 +11,6 @@ * ALLEGROCL language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_allegrocl_cxx[] = "$Id$"; - #include "swigmod.h" #include "cparse.h" #include diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index 4c884caca..5320d9689 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -15,8 +15,6 @@ * Doc/Manual/SWIGPlus.html for details. * ----------------------------------------------------------------------------- */ -char cvsroot_allocate_cxx[] = "$Id$"; - #include "swigmod.h" #include "cparse.h" diff --git a/Source/Modules/browser.cxx b/Source/Modules/browser.cxx index b1365c0b4..f5ceae5b1 100644 --- a/Source/Modules/browser.cxx +++ b/Source/Modules/browser.cxx @@ -12,8 +12,6 @@ * feature that's normally disabled. * ----------------------------------------------------------------------------- */ -char cvsroot_browser_cxx[] = "$Id$"; - #include "swigmod.h" #ifdef SWIG_SWILL diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx index 88f82b647..29de9f9ed 100644 --- a/Source/Modules/cffi.cxx +++ b/Source/Modules/cffi.cxx @@ -11,8 +11,6 @@ * cffi language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_cffi_cxx[] = "$Id$"; - #include "swigmod.h" #include "cparse.h" #include diff --git a/Source/Modules/chicken.cxx b/Source/Modules/chicken.cxx index 8ff154f82..89e583d18 100644 --- a/Source/Modules/chicken.cxx +++ b/Source/Modules/chicken.cxx @@ -11,8 +11,6 @@ * CHICKEN language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_chicken_cxx[] = "$Id$"; - #include "swigmod.h" #include diff --git a/Source/Modules/clisp.cxx b/Source/Modules/clisp.cxx index 7bfb6298c..4290b5452 100644 --- a/Source/Modules/clisp.cxx +++ b/Source/Modules/clisp.cxx @@ -11,8 +11,6 @@ * clisp language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_clisp_cxx[] = "$Id$"; - #include "swigmod.h" static const char *usage = (char *) "\ diff --git a/Source/Modules/contract.cxx b/Source/Modules/contract.cxx index 4240945b0..5fa5bcad5 100644 --- a/Source/Modules/contract.cxx +++ b/Source/Modules/contract.cxx @@ -11,8 +11,6 @@ * Support for Wrap by Contract in SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_contract_cxx[] = "$Id$"; - #include "swigmod.h" /* Contract structure. This holds rules about the different kinds of contract sections diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index c31d070be..88cd679b9 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -11,8 +11,6 @@ * C# language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_csharp_cxx[] = "$Id$"; - #include "swigmod.h" #include // for INT_MAX #include "cparse.h" diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 3fffd8e33..88c3ccfff 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -11,8 +11,6 @@ * D language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_d_cxx[] = "$Id$"; - #include "swigmod.h" #include "cparse.h" #include diff --git a/Source/Modules/directors.cxx b/Source/Modules/directors.cxx index 4b23a52bb..4cb38d0aa 100644 --- a/Source/Modules/directors.cxx +++ b/Source/Modules/directors.cxx @@ -13,8 +13,6 @@ * in SWIG. --MR * ----------------------------------------------------------------------------- */ -char cvsroot_directors_cxx[] = "$Id"; - #include "swigmod.h" /* Swig_csuperclass_call() diff --git a/Source/Modules/emit.cxx b/Source/Modules/emit.cxx index c16eaac0f..7c2607fc8 100644 --- a/Source/Modules/emit.cxx +++ b/Source/Modules/emit.cxx @@ -11,8 +11,6 @@ * Useful functions for emitting various pieces of code. * ----------------------------------------------------------------------------- */ -char cvsroot_emit_cxx[] = "$Id$"; - #include "swigmod.h" /* ----------------------------------------------------------------------------- diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 9784ba125..fa706cb62 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -7,8 +7,6 @@ * Go language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_go_cxx[] = "$Id"; - #include "swigmod.h" #include "cparse.h" #include diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index 0777b316f..211b11baf 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -11,8 +11,6 @@ * Guile language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_guile_cxx[] = "$Id$"; - #include "swigmod.h" #include diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index b4703bd3e..57ac7ca52 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -11,8 +11,6 @@ * Java language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_java_cxx[] = "$Id$"; - #include "swigmod.h" #include // for INT_MAX #include "cparse.h" diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index dc21d7f96..4f1657825 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -11,8 +11,6 @@ * Language base class functions. Default C++ handling is also implemented here. * ----------------------------------------------------------------------------- */ -char cvsroot_lang_cxx[] = "$Id$"; - #include "swigmod.h" #include "cparse.h" #include diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 34763290f..cfb3a3f5b 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -44,8 +44,6 @@ Added support for embedded Lua. Try swig -lua -help for more information */ -char cvsroot_lua_cxx[] = "$Id$"; - #include "swigmod.h" /**** Diagnostics: diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index d2876c16f..d1f3ab274 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -11,8 +11,6 @@ * Main entry point to the SWIG core. * ----------------------------------------------------------------------------- */ -char cvsroot_main_cxx[] = "$Id$"; - #include "swigconfig.h" #if defined(_WIN32) diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index f7b60825d..ffb172f8f 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -11,8 +11,6 @@ * Modula3 language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_modula3_cxx[] = "$Id$"; - /* Text formatted with indent -sob -br -ce -nut -npsl diff --git a/Source/Modules/module.cxx b/Source/Modules/module.cxx index f4ab560dd..aa48689ab 100644 --- a/Source/Modules/module.cxx +++ b/Source/Modules/module.cxx @@ -11,8 +11,6 @@ * This file is responsible for the module system. * ----------------------------------------------------------------------------- */ -char cvsroot_module_cxx[] = "$Id$"; - #include "swigmod.h" struct Module { diff --git a/Source/Modules/mzscheme.cxx b/Source/Modules/mzscheme.cxx index e2f44deef..a147dd9c4 100644 --- a/Source/Modules/mzscheme.cxx +++ b/Source/Modules/mzscheme.cxx @@ -11,8 +11,6 @@ * Mzscheme language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_mzscheme_cxx[] = "$Id$"; - #include "swigmod.h" #include diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index beac03237..34c8975c5 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -11,8 +11,6 @@ * Ocaml language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_ocaml_cxx[] = "$Id$"; - #include "swigmod.h" #include diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 5758e38c3..5584176a1 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -11,8 +11,6 @@ * Octave language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_octave_cxx[] = "$Id$"; - #include "swigmod.h" static String *global_name = 0; diff --git a/Source/Modules/overload.cxx b/Source/Modules/overload.cxx index 6a574fdbe..0112d2d9e 100644 --- a/Source/Modules/overload.cxx +++ b/Source/Modules/overload.cxx @@ -13,8 +13,6 @@ * building a dispatch function. * ----------------------------------------------------------------------------- */ -char cvsroot_overload_cxx[] = "$Id$"; - #include "swigmod.h" #define MAX_OVERLOAD 4096 diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index f786a7607..7147e67c1 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -11,8 +11,6 @@ * Perl5 language module for SWIG. * ------------------------------------------------------------------------- */ -char cvsroot_perl5_cxx[] = "$Id$"; - #include "swigmod.h" #include "cparse.h" static int treduce = SWIG_cparse_template_reduce(0); diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 9b68d072c..292f979ba 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -37,8 +37,6 @@ * (may need to add more WARN_PHP_xxx codes...) */ -char cvsroot_php_cxx[] = "$Id$"; - #include "swigmod.h" #include diff --git a/Source/Modules/pike.cxx b/Source/Modules/pike.cxx index 6749989f2..cdbddc15d 100644 --- a/Source/Modules/pike.cxx +++ b/Source/Modules/pike.cxx @@ -29,8 +29,6 @@ * */ -char cvsroot_pike_cxx[] = "$Id$"; - #include "swigmod.h" #include // for isalnum() diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index bd897636f..280a36923 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -11,8 +11,6 @@ * Python language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_python_cxx[] = "$Id$"; - #include "swigmod.h" #include "cparse.h" diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 4724ca3a7..8b3bc20bb 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -11,8 +11,6 @@ * R language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_r_cxx[] = "$Id$"; - #include "swigmod.h" static const double DEFAULT_NUMBER = .0000123456712312312323; diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index ff8d70d46..eaec0e185 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -11,8 +11,6 @@ * Ruby language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_ruby_cxx[] = "$Id$"; - #include "swigmod.h" #include "cparse.h" static int treduce = SWIG_cparse_template_reduce(0); diff --git a/Source/Modules/s-exp.cxx b/Source/Modules/s-exp.cxx index 2c9a0cc99..fe3b1facc 100644 --- a/Source/Modules/s-exp.cxx +++ b/Source/Modules/s-exp.cxx @@ -11,8 +11,6 @@ * A parse tree represented as Lisp s-expressions. * ----------------------------------------------------------------------------- */ -char cvsroot_s_exp_cxx[] = "$Id$"; - #include "swigmod.h" #include "dohint.h" diff --git a/Source/Modules/swigmain.cxx b/Source/Modules/swigmain.cxx index 01ab1b79f..7c9cded70 100644 --- a/Source/Modules/swigmain.cxx +++ b/Source/Modules/swigmain.cxx @@ -16,8 +16,6 @@ * to SWIG, you would modify this file. * ----------------------------------------------------------------------------- */ -char cvsroot_swigmain_cxx[] = "$Id$"; - #include "swigmod.h" #include diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx index 91e74f4ca..9ef1b8706 100644 --- a/Source/Modules/tcl8.cxx +++ b/Source/Modules/tcl8.cxx @@ -11,8 +11,6 @@ * Tcl8 language module for SWIG. * ----------------------------------------------------------------------------- */ -char cvsroot_tcl8_cxx[] = "$Id$"; - #include "swigmod.h" #include "cparse.h" static int treduce = SWIG_cparse_template_reduce(0); diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index cda56aecf..2346c94e1 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -16,8 +16,6 @@ * and other information needed for compilation. * ----------------------------------------------------------------------------- */ -char cvsroot_typepass_cxx[] = "$Id$"; - #include "swigmod.h" #include "cparse.h" diff --git a/Source/Modules/uffi.cxx b/Source/Modules/uffi.cxx index 3b9a0abaa..b0136a361 100644 --- a/Source/Modules/uffi.cxx +++ b/Source/Modules/uffi.cxx @@ -13,8 +13,6 @@ // TODO: remove remnants of lisptype -char cvsroot_uffi_cxx[] = "$Id$"; - #include "swigmod.h" static const char *usage = (char *) "\ diff --git a/Source/Modules/utils.cxx b/Source/Modules/utils.cxx index 6e868eec7..a91ebe098 100644 --- a/Source/Modules/utils.cxx +++ b/Source/Modules/utils.cxx @@ -11,8 +11,6 @@ * Various utility functions. * ----------------------------------------------------------------------------- */ -char cvsroot_utils_cxx[] = "$Id$"; - #include int is_public(Node *n) { diff --git a/Source/Modules/xml.cxx b/Source/Modules/xml.cxx index 4bd524815..45b7f7a89 100644 --- a/Source/Modules/xml.cxx +++ b/Source/Modules/xml.cxx @@ -11,8 +11,6 @@ * An Xml parse tree generator. * ----------------------------------------------------------------------------- */ -char cvsroot_xml_cxx[] = "$Id$"; - #include "swigmod.h" static const char *usage = "\ diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index c16fbe7e5..baadf7132 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -17,8 +17,6 @@ * - Lines beginning with %# are stripped down to #... and passed through. * ----------------------------------------------------------------------------- */ -char cvsroot_cpp_c[] = "$Id$"; - #include "swig.h" #include "preprocessor.h" #include diff --git a/Source/Preprocessor/expr.c b/Source/Preprocessor/expr.c index b32665d4a..6d22c8c5e 100644 --- a/Source/Preprocessor/expr.c +++ b/Source/Preprocessor/expr.c @@ -12,8 +12,6 @@ * encountered during preprocessing. * ----------------------------------------------------------------------------- */ -char cvsroot_expr_c[] = "$Id$"; - #include "swig.h" #include "preprocessor.h" diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 38787fc63..8cd48e94e 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -12,8 +12,6 @@ * the naming of local variables, calling conventions, and so forth. * ----------------------------------------------------------------------------- */ -char cvsroot_cwrap_c[] = "$Id$"; - #include "swig.h" extern int cparse_cplusplus; diff --git a/Source/Swig/deprecate.c b/Source/Swig/deprecate.c index ead4d5bd6..08dc06a66 100644 --- a/Source/Swig/deprecate.c +++ b/Source/Swig/deprecate.c @@ -13,8 +13,6 @@ * that the function and/or API needs to be changed in some future release. * ----------------------------------------------------------------------------- */ -char cvsroot_deprecate_c[] = "$Id: parms.c 9630 2007-01-02 21:17:19Z beazley $"; - #include "swig.h" /* --------------------------------------------------------------------- diff --git a/Source/Swig/error.c b/Source/Swig/error.c index 5dfcf605b..2c93cfb21 100644 --- a/Source/Swig/error.c +++ b/Source/Swig/error.c @@ -12,8 +12,6 @@ * error messages. * ----------------------------------------------------------------------------- */ -char cvsroot_error_c[] = "$Id$"; - #include "swig.h" #include #include diff --git a/Source/Swig/fragment.c b/Source/Swig/fragment.c index 4a3fea5a2..15f701ae4 100644 --- a/Source/Swig/fragment.c +++ b/Source/Swig/fragment.c @@ -16,8 +16,6 @@ * wrapper code and to generate cleaner wrapper files. * ----------------------------------------------------------------------------- */ -char cvsroot_fragment_c[] = "$Id$"; - #include "swig.h" #include "swigwarn.h" diff --git a/Source/Swig/getopt.c b/Source/Swig/getopt.c index f6f196bfd..74076a5f0 100644 --- a/Source/Swig/getopt.c +++ b/Source/Swig/getopt.c @@ -20,8 +20,6 @@ * Should have cleaner error handling in general. * ----------------------------------------------------------------------------- */ -char cvsroot_getopt_c[] = "$Id$"; - #include "swig.h" static char **args; diff --git a/Source/Swig/include.c b/Source/Swig/include.c index 5796416a4..13afb21ae 100644 --- a/Source/Swig/include.c +++ b/Source/Swig/include.c @@ -13,8 +13,6 @@ * are provided. * ----------------------------------------------------------------------------- */ -char cvsroot_include_c[] = "$Id$"; - #include "swig.h" static List *directories = 0; /* List of include directories */ diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index ca471b72a..05dd0c480 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -11,8 +11,6 @@ * Miscellaneous functions that don't really fit anywhere else. * ----------------------------------------------------------------------------- */ -char cvsroot_misc_c[] = "$Id$"; - #include "swig.h" #include #include diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index e96dbd14e..a4bff35af 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -20,8 +20,6 @@ * %v - variable name is substituted * ----------------------------------------------------------------------------- */ -char cvsroot_naming_c[] = "$Id$"; - #include "swig.h" #include "cparse.h" #include diff --git a/Source/Swig/parms.c b/Source/Swig/parms.c index 0f4d17b73..bec1e63fa 100644 --- a/Source/Swig/parms.c +++ b/Source/Swig/parms.c @@ -11,8 +11,6 @@ * Parameter list class. * ----------------------------------------------------------------------------- */ -char cvsroot_parms_c[] = "$Id$"; - #include "swig.h" /* ------------------------------------------------------------------------ diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index 8c4bf26a2..52e21dc0a 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -14,8 +14,6 @@ * to easily construct yacc-compatible scanners. * ----------------------------------------------------------------------------- */ -char cvsroot_scanner_c[] = "$Id$"; - #include "swig.h" #include diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index 5b9708b9a..8dc189725 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -12,8 +12,6 @@ * the form of simple strings. * ----------------------------------------------------------------------------- */ -char cvsroot_stype_c[] = "$Id$"; - #include "swig.h" #include "cparse.h" #include diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index 6b54eac08..e77f818de 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -11,8 +11,6 @@ * This file implements the SWIG symbol table. See details below. * ----------------------------------------------------------------------------- */ -char cvsroot_symbol_c[] = "$Id$"; - #include "swig.h" #include "swigwarn.h" #include diff --git a/Source/Swig/tree.c b/Source/Swig/tree.c index b5c9d26dc..784d3ab84 100644 --- a/Source/Swig/tree.c +++ b/Source/Swig/tree.c @@ -12,8 +12,6 @@ * parse trees. * ----------------------------------------------------------------------------- */ -char cvsroot_tree_c[] = "$Id$"; - #include "swig.h" #include #include diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index 2570e8090..a607e92b8 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -11,8 +11,6 @@ * A somewhat generalized implementation of SWIG1.1 typemaps. * ----------------------------------------------------------------------------- */ -char cvsroot_typemap_c[] = "$Id$"; - #include "swig.h" #include "cparse.h" #include diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index 2e8d08f10..20caa9ec9 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -14,8 +14,6 @@ * like typedef, namespaces, etc. * ----------------------------------------------------------------------------- */ -char cvsroot_typeobj_c[] = "$Id$"; - #include "swig.h" #include diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index 76d84c960..d12d70543 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -14,8 +14,6 @@ * run-time type checker is also handled here. * ----------------------------------------------------------------------------- */ -char cvsroot_typesys_c[] = "$Id$"; - #include "swig.h" #include "cparse.h" diff --git a/Source/Swig/wrapfunc.c b/Source/Swig/wrapfunc.c index 2c9f7c86a..29a59cc49 100644 --- a/Source/Swig/wrapfunc.c +++ b/Source/Swig/wrapfunc.c @@ -13,8 +13,6 @@ * to be created in a piecemeal manner. * ----------------------------------------------------------------------------- */ -char cvsroot_wrapfunc_c[] = "$Id$"; - #include "swig.h" #include From a6d456a15eb509719aece348c5717f76c68b9e71 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 12 Jan 2013 01:24:22 +0000 Subject: [PATCH 0382/1160] Replace references to Subversion with Git --- Doc/Devel/engineering.html | 28 +++++++++------------------- Doc/Manual/Preface.html | 2 +- Lib/python/pyname_compat.i | 4 ++-- Makefile.in | 4 ++-- swig.spec.in | 4 ++-- 5 files changed, 16 insertions(+), 26 deletions(-) diff --git a/Doc/Devel/engineering.html b/Doc/Devel/engineering.html index 2e78fbe35..c12eb1328 100644 --- a/Doc/Devel/engineering.html +++ b/Doc/Devel/engineering.html @@ -25,7 +25,7 @@
  • 8. Naming Conventions
  • 9. Visibility
  • 10. Miscellaneous Coding Guidelines -
  • 11. SVN Tagging Conventions +
  • 11. Git Tagging Conventions @@ -119,8 +119,8 @@ 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, license information and -a SVN revision tag like this: +Each file should include a short abstract and license information +like this:

    @@ -137,8 +137,6 @@ a SVN revision tag like this:
      * This file defines ...
      * ----------------------------------------------------------------------------- */
     
    -static char cvs[] = "$Id$";
    -
     #include "swig.h"
     
     /* Declarations */
    @@ -159,12 +157,6 @@ static int  avariable;
     
    -The SVN revision tag should be placed into a static string as shown -above mangled with the name of the file. -This adds the revision information to the SWIG executable and -makes it possible to extract version information from a raw binary -(sometimes useful in debugging). -

    As a general rule, files start to get unmanageable once they exceed about 2000 lines. Files larger than this should be broken up into @@ -379,10 +371,10 @@ making your changes. These are largely covered in the main documentation in the Extending.html file. -

    11. SVN Tagging Conventions

    +

    11. Git Tagging Conventions

    -Use svn tag to declare some set of file revisions as related in some +Use git tag to declare some set of file revisions as related in some symbolic way. This eases reference, retrieval and manipulation of these files later. At the moment (2001/01/16 14:02:53), the conventions are very simple; let's hope they stay that way! @@ -390,10 +382,10 @@ let's hope they stay that way!

    There are two types of tags, internal (aka personal) and external. Internal tags are used by SWIG developers primarily, whereas external -tags are used when communicating with people w/ anonymous svn access. +tags are used when communicating with people w/ anonymous git access.

    • Internal tags should start with the developer name and a hyphen. -
    • External tags should start with "v-". +
    • External tags should start with "rel-".
    That's all there is to it. Some example tags: @@ -402,10 +394,8 @@ That's all there is to it. Some example tags:
  • ttn-pre-xml-patch
  • ttn-post-xml-patch
  • ttn-going-on-vacation-so-dutifully-tagging-now -
  • v-1-3-a37-fixes-bug-2432 -
  • v-1-3-a37-fixes-bug-2433 -
  • v-1-3-a37-fixes-bug-2432-again -
  • v-1-3-a37-release +
  • rel-1.3.40 +
  • rel-2.0.9
    diff --git a/Doc/Manual/Preface.html b/Doc/Manual/Preface.html index 58ab9dcb5..e1fcfbbd8 100644 --- a/Doc/Manual/Preface.html +++ b/Doc/Manual/Preface.html @@ -93,7 +93,7 @@ SWIG along with information about beta releases and future work.

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

    diff --git a/Lib/python/pyname_compat.i b/Lib/python/pyname_compat.i index b5acca955..4026805ba 100644 --- a/Lib/python/pyname_compat.i +++ b/Lib/python/pyname_compat.i @@ -20,8 +20,8 @@ * However, this file may be removed in future release of SWIG, so using this file to * keep these inappropriate names in your SWIG interface file is also not recommended. * Instead, we provide a simple tool for converting your interface files to -* the new naming convention. You can download the tool here: -* https://swig.svn.sourceforge.net/svnroot/swig/trunk/Tools/pyname_patch.py +* the new naming convention. You can get the tool from the SWIG distribution: +* Tools/pyname_patch.py */ %fragment("PySequence_Base", "header", fragment="SwigPySequence_Base") {} diff --git a/Makefile.in b/Makefile.in index d3c4b8c47..c6259916b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -494,7 +494,7 @@ dist: srcrpm: rm -fr $(srpm) $(srpm).src.rpm - echo "TODO: update to use svn instead of cvs" + echo "TODO: update to use git instead of cvs" cvs export -d $(srpm) -r HEAD SWIG cp swig.spec $(srpm) tar -cf - $(srpm) | gzip --best > $(srpm).tar.gz @@ -503,7 +503,7 @@ srcrpm: # Update the autoconf files for detecting host/targets. Automake will do this in # version 1.10 for our case of not having a top level Makefile.am. Until then we -# can fetch them manually and will have to commit them to SVN. +# can fetch them manually and will have to commit them to Git. configfiles: wget ftp://ftp.gnu.org/pub/gnu/config/config.guess -O Tools/config/config.guess chmod a+x Tools/config/config.guess diff --git a/swig.spec.in b/swig.spec.in index 0f64235fb..9229274c2 100644 --- a/swig.spec.in +++ b/swig.spec.in @@ -1,4 +1,4 @@ -# You can build the package from SVN using something like: +# You can build the package from Git using something like: # tar -czf swig-@PACKAGE_VERSION@.tar.gz swig-@PACKAGE_VERSION@ && rpmbuild -tb swig-@PACKAGE_VERSION@.tar.gz # @configure_input@ @@ -36,7 +36,7 @@ its parse tree in the form of XML and Lisp s-expressions. %setup -q -n %{name}-%{version} %build -# so we can build package from SVN source too +# so we can build package from Git source too [ ! -r configure ] && ./autogen.sh %configure make From bd67f57921245470317e54403d78922d4d8258d1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 12 Jan 2013 16:54:37 +0000 Subject: [PATCH 0383/1160] Convert to unix fileformat --- Lib/intrusive_ptr.i | 164 +++--- Lib/java/boost_intrusive_ptr.i | 946 ++++++++++++++++----------------- 2 files changed, 555 insertions(+), 555 deletions(-) diff --git a/Lib/intrusive_ptr.i b/Lib/intrusive_ptr.i index eed750c79..ceaeaf0bb 100644 --- a/Lib/intrusive_ptr.i +++ b/Lib/intrusive_ptr.i @@ -1,82 +1,82 @@ -// Allow for different namespaces for shared_ptr / intrusive_ptr - they could be boost or std or std::tr1 -// For example for std::tr1, use: -// #define SWIG_SHARED_PTR_NAMESPACE std -// #define SWIG_SHARED_PTR_SUBNAMESPACE tr1 -// #define SWIG_INTRUSIVE_PTR_NAMESPACE boost -// #define SWIG_INTRUSIVE_PTR_SUBNAMESPACE - -#if !defined(SWIG_INTRUSIVE_PTR_NAMESPACE) -# define SWIG_INTRUSIVE_PTR_NAMESPACE boost -#endif - -#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE) -# define SWIG_INTRUSIVE_PTR_QNAMESPACE SWIG_INTRUSIVE_PTR_NAMESPACE::SWIG_INTRUSIVE_PTR_SUBNAMESPACE -#else -# define SWIG_INTRUSIVE_PTR_QNAMESPACE SWIG_INTRUSIVE_PTR_NAMESPACE -#endif - -namespace SWIG_INTRUSIVE_PTR_NAMESPACE { -#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE) - namespace SWIG_INTRUSIVE_PTR_SUBNAMESPACE { -#endif - template class intrusive_ptr { - }; -#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE) - } -#endif -} - -%fragment("SWIG_intrusive_deleter", "header") { -template struct SWIG_intrusive_deleter { - void operator()(T *p) { - if (p) - intrusive_ptr_release(p); - } -}; -} - -%fragment("SWIG_null_deleter", "header") { -struct SWIG_null_deleter { - void operator() (void const *) const { - } -}; -%#define SWIG_NO_NULL_DELETER_0 , 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...) -#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 - -%define SWIG_INTRUSIVE_PTR_NO_WRAP(PROXYCLASS, 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 - +// Allow for different namespaces for shared_ptr / intrusive_ptr - they could be boost or std or std::tr1 +// For example for std::tr1, use: +// #define SWIG_SHARED_PTR_NAMESPACE std +// #define SWIG_SHARED_PTR_SUBNAMESPACE tr1 +// #define SWIG_INTRUSIVE_PTR_NAMESPACE boost +// #define SWIG_INTRUSIVE_PTR_SUBNAMESPACE + +#if !defined(SWIG_INTRUSIVE_PTR_NAMESPACE) +# define SWIG_INTRUSIVE_PTR_NAMESPACE boost +#endif + +#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE) +# define SWIG_INTRUSIVE_PTR_QNAMESPACE SWIG_INTRUSIVE_PTR_NAMESPACE::SWIG_INTRUSIVE_PTR_SUBNAMESPACE +#else +# define SWIG_INTRUSIVE_PTR_QNAMESPACE SWIG_INTRUSIVE_PTR_NAMESPACE +#endif + +namespace SWIG_INTRUSIVE_PTR_NAMESPACE { +#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE) + namespace SWIG_INTRUSIVE_PTR_SUBNAMESPACE { +#endif + template class intrusive_ptr { + }; +#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE) + } +#endif +} + +%fragment("SWIG_intrusive_deleter", "header") { +template struct SWIG_intrusive_deleter { + void operator()(T *p) { + if (p) + intrusive_ptr_release(p); + } +}; +} + +%fragment("SWIG_null_deleter", "header") { +struct SWIG_null_deleter { + void operator() (void const *) const { + } +}; +%#define SWIG_NO_NULL_DELETER_0 , 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...) +#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 + +%define SWIG_INTRUSIVE_PTR_NO_WRAP(PROXYCLASS, 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 3ae3ed886..f9525894f 100644 --- a/Lib/java/boost_intrusive_ptr.i +++ b/Lib/java/boost_intrusive_ptr.i @@ -1,473 +1,473 @@ -// Users can provide their own SWIG_INTRUSIVE_PTR_TYPEMAPS or SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP macros before including this file to change the -// visibility of the constructor and getCPtr method if desired to public if using multiple modules. -#ifndef SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP -#define SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(CONST, TYPE...) SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP_IMPLEMENTATION(protected, protected, CONST, TYPE) -#endif -#ifndef SWIG_INTRUSIVE_PTR_TYPEMAPS -#define SWIG_INTRUSIVE_PTR_TYPEMAPS(CONST, TYPE...) SWIG_INTRUSIVE_PTR_TYPEMAPS_IMPLEMENTATION(protected, protected, CONST, TYPE) -#endif - - -%include - -// Language specific macro implementing all the customisations for handling the smart pointer -%define SWIG_INTRUSIVE_PTR_TYPEMAPS_IMPLEMENTATION(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, CONST, TYPE...) - -// %naturalvar is as documented for member variables -%naturalvar TYPE; -%naturalvar SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >; - -// destructor wrapper customisation -%feature("unref") TYPE "(void)arg1; delete smartarg1;" - -// Typemap customisations... - -%typemap(in) CONST TYPE ($&1_type argp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ - // plain value - argp = (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0; - if (!argp) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type"); - return $null; - } - $1 = *argp; -%} -%typemap(out, fragment="SWIG_intrusive_deleter") CONST TYPE %{ - //plain value(out) - $1_ltype* resultp = new $1_ltype(($1_ltype &)$1); - intrusive_ptr_add_ref(resultp); - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(resultp, SWIG_intrusive_deleter< CONST TYPE >()); -%} - -%typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ - // plain pointer - smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input; - $1 = (TYPE *)(smartarg ? smartarg->get() : 0); -%} -%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE * %{ - //plain pointer(out) - #if ($owner) - if ($1) { - intrusive_ptr_add_ref($1); - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1, SWIG_intrusive_deleter< CONST TYPE >()); - } else { - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; - } - #else - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; - #endif -%} - -%typemap(in) CONST TYPE & (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ - // plain reference - $1 = ($1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); - if(!$1) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null"); - return $null; - } -%} -%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE & %{ - //plain reference(out) - #if ($owner) - if ($1) { - intrusive_ptr_add_ref($1); - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1, SWIG_intrusive_deleter< CONST TYPE >()); - } else { - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; - } - #else - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; - #endif -%} - -%typemap(in) TYPE *CONST& ($*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ - // plain pointer by reference - 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") TYPE *CONST& %{ - // plain pointer by reference(out) - #if ($owner) - if (*$1) { - intrusive_ptr_add_ref(*$1); - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1, SWIG_intrusive_deleter< CONST TYPE >()); - } else { - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; - } - #else - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_0); - #endif -%} - -%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > ($&1_type argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{ - // intrusive_ptr by value - smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input; - if (smartarg) { - $1 = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true); - } -%} -%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > %{ - if ($1) { - intrusive_ptr_add_ref(result.get()); - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(result.get(), SWIG_intrusive_deleter< CONST TYPE >()); - } else { - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; - } -%} - -%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast ($&1_type smartarg) %{ - // shared_ptr by value - smartarg = *($&1_ltype*)&$input; - if (smartarg) $1 = *smartarg; -%} -%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ANY_TYPE_SWIGSharedPtrUpcast %{ - *($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0; -%} - -%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & ($*1_ltype tempnull, $*1_ltype temp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{ - // intrusive_ptr by reference - if ( $input ) { - smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input; - temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true); - $1 = &temp; - } else { - $1 = &tempnull; - } -%} -%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & %{ - delete &($1); - if ($self) { - SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * temp = new SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(*$input); - $1 = *temp; - } -%} -%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & %{ - if (*$1) { - intrusive_ptr_add_ref($1->get()); - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1->get(), SWIG_intrusive_deleter< CONST TYPE >()); - } else { - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; - } -%} - -%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * ($*1_ltype tempnull, $*1_ltype temp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{ - // intrusive_ptr by pointer - if ( $input ) { - smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input; - temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true); - $1 = &temp; - } else { - $1 = &tempnull; - } -%} -%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * %{ - delete $1; - if ($self) $1 = new SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(*$input); -%} -%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * %{ - if ($1 && *$1) { - intrusive_ptr_add_ref($1->get()); - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1->get(), SWIG_intrusive_deleter< CONST TYPE >()); - } else { - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; - } - if ($owner) delete $1; -%} - -%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& (SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > temp, $*1_ltype tempp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{ - // intrusive_ptr by pointer reference - smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input; - if ($input) { - temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true); - } - tempp = &temp; - $1 = &tempp; -%} -%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& %{ - if ($self) $1 = *$input; -%} -%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& %{ - if (*$1 && **$1) { - intrusive_ptr_add_ref((*$1)->get()); - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >((*$1)->get(), SWIG_intrusive_deleter< CONST TYPE >()); - } else { - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; - } -%} - -// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug -%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ -#error "typemaps for $1_type not available" -%} -%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ -#error "typemaps for $1_type not available" -%} - - -%typemap (jni) 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 > *& "jlong" -%typemap (jtype) 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 > *& "long" -%typemap (jstype) 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 > *& "$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 > *& "$typemap(jstype, TYPE).getCPtr($javainput)" - -%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > { - long cPtr = $jnicall; - 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 $typemap(jstype, TYPE)(cPtr, true); - } -%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & { - long cPtr = $jnicall; - 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 $typemap(jstype, TYPE)(cPtr, true); - } -%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& { - long cPtr = $jnicall; - return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); - } - - -%typemap(javaout) CONST TYPE { - return new $typemap(jstype, TYPE)($jnicall, true); - } -%typemap(javaout) CONST TYPE & { - return new $typemap(jstype, TYPE)($jnicall, true); - } -%typemap(javaout) CONST TYPE * { - long cPtr = $jnicall; - return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); - } -%typemap(javaout) TYPE *CONST& { - long cPtr = $jnicall; - return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); - } - -// Base proxy classes -%typemap(javabody) TYPE %{ - private long swigCPtr; - private boolean swigCMemOwnBase; - - PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { - swigCMemOwnBase = cMemoryOwn; - swigCPtr = cPtr; - } - - CPTR_VISIBILITY static long getCPtr($javaclassname obj) { - return (obj == null) ? 0 : obj.swigCPtr; - } -%} - -// Derived proxy classes -%typemap(javabody_derived) TYPE %{ - private long swigCPtr; - private boolean swigCMemOwnDerived; - - PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { - super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true); - swigCMemOwnDerived = cMemoryOwn; - swigCPtr = cPtr; - } - - CPTR_VISIBILITY static long getCPtr($javaclassname obj) { - return (obj == null) ? 0 : obj.swigCPtr; - } -%} - -%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE { - if(swigCPtr != 0 && swigCMemOwnBase) { - swigCMemOwnBase = false; - $jnicall; - } - swigCPtr = 0; - } - -%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") TYPE { - if(swigCPtr != 0 && swigCMemOwnDerived) { - swigCMemOwnDerived = false; - $jnicall; - } - swigCPtr = 0; - 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 >; -%template() SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >; -%enddef - - -///////////////////////////////////////////////////////////////////// - - -%include - -%define SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP_IMPLEMENTATION(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, CONST, TYPE...) - -%naturalvar TYPE; -%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; - -// destructor mods -%feature("unref") TYPE "(void)arg1; delete smartarg1;" - - -// plain value -%typemap(in) CONST TYPE ($&1_type argp = 0) %{ - argp = (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0; - if (!argp) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type"); - return $null; - } - $1 = *argp; %} -%typemap(out) CONST TYPE -%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %} - -// plain pointer -%typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ - smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input; - $1 = (TYPE *)(smartarg ? smartarg->get() : 0); %} -%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * %{ - *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0; -%} - -// plain reference -%typemap(in) CONST TYPE & %{ - $1 = ($1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); - if (!$1) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null"); - return $null; - } %} -%typemap(out, fragment="SWIG_null_deleter") CONST TYPE & -%{ *(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) 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") 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) %{ - // shared_ptr by value - smartarg = *($&1_ltype*)&$input; - if (smartarg) $1 = *smartarg; -%} -%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ANY_TYPE_SWIGSharedPtrUpcast %{ - *($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0; -%} - -// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug -%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ -#error "typemaps for $1_type not available" -%} -%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ -#error "typemaps for $1_type not available" -%} - - -%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 > "$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 $typemap(jstype, TYPE)(cPtr, true); - } - -%typemap(javaout) CONST TYPE { - return new $typemap(jstype, TYPE)($jnicall, true); - } -%typemap(javaout) CONST TYPE & { - return new $typemap(jstype, TYPE)($jnicall, true); - } -%typemap(javaout) CONST TYPE * { - long cPtr = $jnicall; - return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); - } -%typemap(javaout) TYPE *CONST& { - long cPtr = $jnicall; - return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); - } - -// Base proxy classes -%typemap(javabody) TYPE %{ - private long swigCPtr; - private boolean swigCMemOwnBase; - - PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { - swigCMemOwnBase = cMemoryOwn; - swigCPtr = cPtr; - } - - CPTR_VISIBILITY static long getCPtr($javaclassname obj) { - return (obj == null) ? 0 : obj.swigCPtr; - } -%} - -// Derived proxy classes -%typemap(javabody_derived) TYPE %{ - private long swigCPtr; - private boolean swigCMemOwnDerived; - - PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { - super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true); - swigCMemOwnDerived = cMemoryOwn; - swigCPtr = cPtr; - } - - CPTR_VISIBILITY static long getCPtr($javaclassname obj) { - return (obj == null) ? 0 : obj.swigCPtr; - } -%} - -%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE { - if (swigCPtr != 0) { - if (swigCMemOwnBase) { - swigCMemOwnBase = false; - $jnicall; - } - swigCPtr = 0; - } - } - -%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") TYPE { - if (swigCPtr != 0) { - if (swigCMemOwnDerived) { - swigCMemOwnDerived = false; - $jnicall; - } - swigCPtr = 0; - } - 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 - +// Users can provide their own SWIG_INTRUSIVE_PTR_TYPEMAPS or SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP macros before including this file to change the +// visibility of the constructor and getCPtr method if desired to public if using multiple modules. +#ifndef SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP +#define SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(CONST, TYPE...) SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP_IMPLEMENTATION(protected, protected, CONST, TYPE) +#endif +#ifndef SWIG_INTRUSIVE_PTR_TYPEMAPS +#define SWIG_INTRUSIVE_PTR_TYPEMAPS(CONST, TYPE...) SWIG_INTRUSIVE_PTR_TYPEMAPS_IMPLEMENTATION(protected, protected, CONST, TYPE) +#endif + + +%include + +// Language specific macro implementing all the customisations for handling the smart pointer +%define SWIG_INTRUSIVE_PTR_TYPEMAPS_IMPLEMENTATION(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, CONST, TYPE...) + +// %naturalvar is as documented for member variables +%naturalvar TYPE; +%naturalvar SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >; + +// destructor wrapper customisation +%feature("unref") TYPE "(void)arg1; delete smartarg1;" + +// Typemap customisations... + +%typemap(in) CONST TYPE ($&1_type argp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ + // plain value + argp = (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0; + if (!argp) { + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type"); + return $null; + } + $1 = *argp; +%} +%typemap(out, fragment="SWIG_intrusive_deleter") CONST TYPE %{ + //plain value(out) + $1_ltype* resultp = new $1_ltype(($1_ltype &)$1); + intrusive_ptr_add_ref(resultp); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(resultp, SWIG_intrusive_deleter< CONST TYPE >()); +%} + +%typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ + // plain pointer + smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input; + $1 = (TYPE *)(smartarg ? smartarg->get() : 0); +%} +%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE * %{ + //plain pointer(out) + #if ($owner) + if ($1) { + intrusive_ptr_add_ref($1); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1, SWIG_intrusive_deleter< CONST TYPE >()); + } else { + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; + } + #else + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; + #endif +%} + +%typemap(in) CONST TYPE & (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ + // plain reference + $1 = ($1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); + if(!$1) { + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null"); + return $null; + } +%} +%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE & %{ + //plain reference(out) + #if ($owner) + if ($1) { + intrusive_ptr_add_ref($1); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1, SWIG_intrusive_deleter< CONST TYPE >()); + } else { + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; + } + #else + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; + #endif +%} + +%typemap(in) TYPE *CONST& ($*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ + // plain pointer by reference + 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") TYPE *CONST& %{ + // plain pointer by reference(out) + #if ($owner) + if (*$1) { + intrusive_ptr_add_ref(*$1); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1, SWIG_intrusive_deleter< CONST TYPE >()); + } else { + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; + } + #else + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_0); + #endif +%} + +%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > ($&1_type argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{ + // intrusive_ptr by value + smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input; + if (smartarg) { + $1 = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true); + } +%} +%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > %{ + if ($1) { + intrusive_ptr_add_ref(result.get()); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(result.get(), SWIG_intrusive_deleter< CONST TYPE >()); + } else { + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; + } +%} + +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast ($&1_type smartarg) %{ + // shared_ptr by value + smartarg = *($&1_ltype*)&$input; + if (smartarg) $1 = *smartarg; +%} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ANY_TYPE_SWIGSharedPtrUpcast %{ + *($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0; +%} + +%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & ($*1_ltype tempnull, $*1_ltype temp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{ + // intrusive_ptr by reference + if ( $input ) { + smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input; + temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true); + $1 = &temp; + } else { + $1 = &tempnull; + } +%} +%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & %{ + delete &($1); + if ($self) { + SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * temp = new SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(*$input); + $1 = *temp; + } +%} +%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & %{ + if (*$1) { + intrusive_ptr_add_ref($1->get()); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1->get(), SWIG_intrusive_deleter< CONST TYPE >()); + } else { + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; + } +%} + +%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * ($*1_ltype tempnull, $*1_ltype temp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{ + // intrusive_ptr by pointer + if ( $input ) { + smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input; + temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true); + $1 = &temp; + } else { + $1 = &tempnull; + } +%} +%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * %{ + delete $1; + if ($self) $1 = new SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(*$input); +%} +%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * %{ + if ($1 && *$1) { + intrusive_ptr_add_ref($1->get()); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1->get(), SWIG_intrusive_deleter< CONST TYPE >()); + } else { + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; + } + if ($owner) delete $1; +%} + +%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& (SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > temp, $*1_ltype tempp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{ + // intrusive_ptr by pointer reference + smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input; + if ($input) { + temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true); + } + tempp = &temp; + $1 = &tempp; +%} +%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& %{ + if ($self) $1 = *$input; +%} +%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& %{ + if (*$1 && **$1) { + intrusive_ptr_add_ref((*$1)->get()); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >((*$1)->get(), SWIG_intrusive_deleter< CONST TYPE >()); + } else { + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; + } +%} + +// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug +%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} +%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} + + +%typemap (jni) 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 > *& "jlong" +%typemap (jtype) 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 > *& "long" +%typemap (jstype) 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 > *& "$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 > *& "$typemap(jstype, TYPE).getCPtr($javainput)" + +%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > { + long cPtr = $jnicall; + 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 $typemap(jstype, TYPE)(cPtr, true); + } +%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & { + long cPtr = $jnicall; + 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 $typemap(jstype, TYPE)(cPtr, true); + } +%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& { + long cPtr = $jnicall; + return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); + } + + +%typemap(javaout) CONST TYPE { + return new $typemap(jstype, TYPE)($jnicall, true); + } +%typemap(javaout) CONST TYPE & { + return new $typemap(jstype, TYPE)($jnicall, true); + } +%typemap(javaout) CONST TYPE * { + long cPtr = $jnicall; + return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); + } +%typemap(javaout) TYPE *CONST& { + long cPtr = $jnicall; + return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); + } + +// Base proxy classes +%typemap(javabody) TYPE %{ + private long swigCPtr; + private boolean swigCMemOwnBase; + + PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { + swigCMemOwnBase = cMemoryOwn; + swigCPtr = cPtr; + } + + CPTR_VISIBILITY static long getCPtr($javaclassname obj) { + return (obj == null) ? 0 : obj.swigCPtr; + } +%} + +// Derived proxy classes +%typemap(javabody_derived) TYPE %{ + private long swigCPtr; + private boolean swigCMemOwnDerived; + + PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { + super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true); + swigCMemOwnDerived = cMemoryOwn; + swigCPtr = cPtr; + } + + CPTR_VISIBILITY static long getCPtr($javaclassname obj) { + return (obj == null) ? 0 : obj.swigCPtr; + } +%} + +%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE { + if(swigCPtr != 0 && swigCMemOwnBase) { + swigCMemOwnBase = false; + $jnicall; + } + swigCPtr = 0; + } + +%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") TYPE { + if(swigCPtr != 0 && swigCMemOwnDerived) { + swigCMemOwnDerived = false; + $jnicall; + } + swigCPtr = 0; + 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 >; +%template() SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >; +%enddef + + +///////////////////////////////////////////////////////////////////// + + +%include + +%define SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP_IMPLEMENTATION(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, CONST, TYPE...) + +%naturalvar TYPE; +%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; + +// destructor mods +%feature("unref") TYPE "(void)arg1; delete smartarg1;" + + +// plain value +%typemap(in) CONST TYPE ($&1_type argp = 0) %{ + argp = (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0; + if (!argp) { + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type"); + return $null; + } + $1 = *argp; %} +%typemap(out) CONST TYPE +%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %} + +// plain pointer +%typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ + smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input; + $1 = (TYPE *)(smartarg ? smartarg->get() : 0); %} +%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * %{ + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0; +%} + +// plain reference +%typemap(in) CONST TYPE & %{ + $1 = ($1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); + if (!$1) { + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null"); + return $null; + } %} +%typemap(out, fragment="SWIG_null_deleter") CONST TYPE & +%{ *(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) 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") 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) %{ + // shared_ptr by value + smartarg = *($&1_ltype*)&$input; + if (smartarg) $1 = *smartarg; +%} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ANY_TYPE_SWIGSharedPtrUpcast %{ + *($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0; +%} + +// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug +%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} +%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} + + +%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 > "$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 $typemap(jstype, TYPE)(cPtr, true); + } + +%typemap(javaout) CONST TYPE { + return new $typemap(jstype, TYPE)($jnicall, true); + } +%typemap(javaout) CONST TYPE & { + return new $typemap(jstype, TYPE)($jnicall, true); + } +%typemap(javaout) CONST TYPE * { + long cPtr = $jnicall; + return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); + } +%typemap(javaout) TYPE *CONST& { + long cPtr = $jnicall; + return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); + } + +// Base proxy classes +%typemap(javabody) TYPE %{ + private long swigCPtr; + private boolean swigCMemOwnBase; + + PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { + swigCMemOwnBase = cMemoryOwn; + swigCPtr = cPtr; + } + + CPTR_VISIBILITY static long getCPtr($javaclassname obj) { + return (obj == null) ? 0 : obj.swigCPtr; + } +%} + +// Derived proxy classes +%typemap(javabody_derived) TYPE %{ + private long swigCPtr; + private boolean swigCMemOwnDerived; + + PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { + super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true); + swigCMemOwnDerived = cMemoryOwn; + swigCPtr = cPtr; + } + + CPTR_VISIBILITY static long getCPtr($javaclassname obj) { + return (obj == null) ? 0 : obj.swigCPtr; + } +%} + +%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE { + if (swigCPtr != 0) { + if (swigCMemOwnBase) { + swigCMemOwnBase = false; + $jnicall; + } + swigCPtr = 0; + } + } + +%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") TYPE { + if (swigCPtr != 0) { + if (swigCMemOwnDerived) { + swigCMemOwnDerived = false; + $jnicall; + } + swigCPtr = 0; + } + 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 + From 079165abe2b10a8f10633a2e16d50006e3a1bc2e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 12 Jan 2013 16:54:45 +0000 Subject: [PATCH 0384/1160] Convert to unix fileformat --- Examples/lua/arrays/Makefile | 36 +- Examples/lua/arrays/example.c | 50 +- Examples/lua/arrays/example.i | 84 +- Examples/lua/arrays/runme.lua | 148 +- Examples/lua/embed/embed.c | 170 +- Examples/lua/embed/example.c | 44 +- Examples/lua/embed2/embed2.c | 466 +++--- Examples/lua/embed2/example.c | 44 +- Examples/lua/embed3/example.i | 16 +- Examples/lua/exception/Makefile | 38 +- Examples/lua/exception/example.h | 106 +- Examples/lua/exception/example.i | 34 +- Examples/lua/exception/runme.lua | 192 +-- Examples/lua/owner/Makefile | 38 +- Examples/lua/owner/example.cxx | 138 +- Examples/lua/owner/example.h | 108 +- Examples/lua/owner/example.i | 64 +- Examples/lua/owner/runme.lua | 208 +-- .../test-suite/csharp/li_std_map_runme.cs | 492 +++--- .../java/li_boost_intrusive_ptr_runme.java | 1402 ++++++++--------- Examples/test-suite/li_boost_intrusive_ptr.i | 996 ++++++------ Examples/test-suite/lua/li_typemaps_runme.lua | 84 +- 22 files changed, 2479 insertions(+), 2479 deletions(-) diff --git a/Examples/lua/arrays/Makefile b/Examples/lua/arrays/Makefile index bb9cf0b3b..f181818a6 100644 --- a/Examples/lua/arrays/Makefile +++ b/Examples/lua/arrays/Makefile @@ -1,18 +1,18 @@ -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)' lua - -static:: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static - -clean:: - $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all +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)' lua + +static:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static + +clean:: + $(MAKE) -f $(TOP)/Makefile lua_clean + +check: all diff --git a/Examples/lua/arrays/example.c b/Examples/lua/arrays/example.c index 56c7b19d9..ed23738c8 100644 --- a/Examples/lua/arrays/example.c +++ b/Examples/lua/arrays/example.c @@ -1,25 +1,25 @@ -/* File : example.c */ - -#include - -/* we are using the qsort function, which needs a helper function to sort */ -int compare_int(const void * a, const void * b) -{ - return ( *(int*)a - *(int*)b ); -} - -void sort_int(int* arr, int len) -{ - qsort(arr, len, sizeof(int), compare_int); -} - -// ditto doubles -int compare_double(const void * a, const void * b) -{ - return (int)( *(double*)a - *(double*)b ); -} - -void sort_double(double* arr, int len) -{ - qsort(arr, len, sizeof(double), compare_double); -} +/* File : example.c */ + +#include + +/* we are using the qsort function, which needs a helper function to sort */ +int compare_int(const void * a, const void * b) +{ + return ( *(int*)a - *(int*)b ); +} + +void sort_int(int* arr, int len) +{ + qsort(arr, len, sizeof(int), compare_int); +} + +// ditto doubles +int compare_double(const void * a, const void * b) +{ + return (int)( *(double*)a - *(double*)b ); +} + +void sort_double(double* arr, int len) +{ + qsort(arr, len, sizeof(double), compare_double); +} diff --git a/Examples/lua/arrays/example.i b/Examples/lua/arrays/example.i index 197a5a21b..3d5b60dc6 100644 --- a/Examples/lua/arrays/example.i +++ b/Examples/lua/arrays/example.i @@ -1,42 +1,42 @@ -/* File : example.i */ -%module example - -/* in this file there are two sorting functions -and three different ways to wrap them. - -See the lua code for how they are called -*/ - -%include // array helpers - -// this declares a batch of function for manipulating C integer arrays -%array_functions(int,int) - -// this adds some lua code directly into the module -// warning: you need the example. prefix if you want it added into the module -// addmittedly this code is a bit tedious, but its a one off effort -%luacode { -function example.sort_int2(t) - local len=table.maxn(t) -- the len - local arr=example.new_int(len) - for i=1,len do - example.int_setitem(arr,i-1,t[i]) -- note: C index is one less then lua indea - end - example.sort_int(arr,len) -- call the fn - -- copy back - for i=1,len do - t[i]=example.int_getitem(arr,i-1) -- note: C index is one less then lua indea - end - example.delete_int(arr) -- must delete it -end -} - -// this way uses the SWIG-Lua typemaps to do the conversion for us -// the %apply command states to apply this wherever the argument signature matches -%include -%apply (double *INOUT,int) {(double* arr,int len)}; - -%inline %{ -extern void sort_int(int* arr, int len); -extern void sort_double(double* arr, int len); -%} \ No newline at end of file +/* File : example.i */ +%module example + +/* in this file there are two sorting functions +and three different ways to wrap them. + +See the lua code for how they are called +*/ + +%include // array helpers + +// this declares a batch of function for manipulating C integer arrays +%array_functions(int,int) + +// this adds some lua code directly into the module +// warning: you need the example. prefix if you want it added into the module +// addmittedly this code is a bit tedious, but its a one off effort +%luacode { +function example.sort_int2(t) + local len=table.maxn(t) -- the len + local arr=example.new_int(len) + for i=1,len do + example.int_setitem(arr,i-1,t[i]) -- note: C index is one less then lua indea + end + example.sort_int(arr,len) -- call the fn + -- copy back + for i=1,len do + t[i]=example.int_getitem(arr,i-1) -- note: C index is one less then lua indea + end + example.delete_int(arr) -- must delete it +end +} + +// this way uses the SWIG-Lua typemaps to do the conversion for us +// the %apply command states to apply this wherever the argument signature matches +%include +%apply (double *INOUT,int) {(double* arr,int len)}; + +%inline %{ +extern void sort_int(int* arr, int len); +extern void sort_double(double* arr, int len); +%} diff --git a/Examples/lua/arrays/runme.lua b/Examples/lua/arrays/runme.lua index b0f5cfc96..7ab6dc42b 100644 --- a/Examples/lua/arrays/runme.lua +++ b/Examples/lua/arrays/runme.lua @@ -1,74 +1,74 @@ ----- importing ---- -if string.sub(_VERSION,1,7)=='Lua 5.0' then - -- lua5.0 doesnt have a nice way to do this - lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example') - assert(lib)() -else - -- lua 5.1 does - require('example') -end - --- a helper to print a Lua table -function print_table(t) - print(table.concat(t,",")) -end - --- a helper to print a C array -function print_array(arr,len) - for i=0,len-1 do - io.write(example.int_getitem(arr,i),",") - end - io.write("\n") -end - -math.randomseed(0) -- init random - - ---[[ version 1: passing a C array to the code -lets test call sort_int() -this requires a C array, so is the hardest to use]] -ARRAY_SIZE=10 -arr=example.new_int(ARRAY_SIZE) -for i=0,ARRAY_SIZE-1 do - example.int_setitem(arr,i,math.random(1000)) -end -print "unsorted" -print_array(arr,ARRAY_SIZE) -example.sort_int(arr,ARRAY_SIZE) -print "sorted" -print_array(arr,ARRAY_SIZE) -example.delete_int(arr) -- must delete it -print "" - ---[[ version 2: using %luacode to write a helper -a simpler way is to use a %luacode -which is a lua function added into the module -this can do the conversion for us -so we can just add a lua table directly -(what we do is move the lua code into the module instead) -]] -t={} -for i=1,ARRAY_SIZE do - t[i]=math.random(1000) -end -print "unsorted" -print_table(t) -example.sort_int2(t) -- calls lua helper which then calls C -print "sorted" -print_table(t) -print "" - ---[[ version 3: use a typemap -this is the best way -it uses the SWIG-Lua typemaps to do the work -one item of note: the typemap creates a copy, rather than edit-in-place]] -t={} -for i=1,ARRAY_SIZE do - t[i]=math.random(1000)/10 -end -print "unsorted" -print_table(t) -t=example.sort_double(t) -- replace t with the result -print "sorted" -print_table(t) - +---- importing ---- +if string.sub(_VERSION,1,7)=='Lua 5.0' then + -- lua5.0 doesnt have a nice way to do this + lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example') + assert(lib)() +else + -- lua 5.1 does + require('example') +end + +-- a helper to print a Lua table +function print_table(t) + print(table.concat(t,",")) +end + +-- a helper to print a C array +function print_array(arr,len) + for i=0,len-1 do + io.write(example.int_getitem(arr,i),",") + end + io.write("\n") +end + +math.randomseed(0) -- init random + + +--[[ version 1: passing a C array to the code +lets test call sort_int() +this requires a C array, so is the hardest to use]] +ARRAY_SIZE=10 +arr=example.new_int(ARRAY_SIZE) +for i=0,ARRAY_SIZE-1 do + example.int_setitem(arr,i,math.random(1000)) +end +print "unsorted" +print_array(arr,ARRAY_SIZE) +example.sort_int(arr,ARRAY_SIZE) +print "sorted" +print_array(arr,ARRAY_SIZE) +example.delete_int(arr) -- must delete it +print "" + +--[[ version 2: using %luacode to write a helper +a simpler way is to use a %luacode +which is a lua function added into the module +this can do the conversion for us +so we can just add a lua table directly +(what we do is move the lua code into the module instead) +]] +t={} +for i=1,ARRAY_SIZE do + t[i]=math.random(1000) +end +print "unsorted" +print_table(t) +example.sort_int2(t) -- calls lua helper which then calls C +print "sorted" +print_table(t) +print "" + +--[[ version 3: use a typemap +this is the best way +it uses the SWIG-Lua typemaps to do the work +one item of note: the typemap creates a copy, rather than edit-in-place]] +t={} +for i=1,ARRAY_SIZE do + t[i]=math.random(1000)/10 +end +print "unsorted" +print_table(t) +t=example.sort_double(t) -- replace t with the result +print "sorted" +print_table(t) + diff --git a/Examples/lua/embed/embed.c b/Examples/lua/embed/embed.c index 55ea099be..9df168f94 100644 --- a/Examples/lua/embed/embed.c +++ b/Examples/lua/embed/embed.c @@ -1,85 +1,85 @@ -/* embed.c a simple test for an embeded interpreter - -The idea is that we wrapper a few simple function (example.c) -and write our own app to call it. - -What it will do is load the wrappered lib, load runme.lua and then call some functions. -To make life easier, all the printf's have either [C] or [Lua] at the start -so you can see where they are coming from. - -We will be using the luaL_dostring()/lua_dostring() function to call into lua - -*/ - -#include -#include - -#include -#include -#include - -/* the SWIG wrappered library */ -extern int luaopen_example(lua_State*L); - -/* a really simple way of calling lua from C - just give it a lua state & a string to execute -Unfortunately lua keeps changing its API's. -In lua 5.0.X its lua_dostring() -In lua 5.1.X its luaL_dostring() -so we have a few extra compiles -*/ -int dostring(lua_State *L, char* str) { - int ok; -#if (defined(LUA_VERSION_NUM) && (LUA_VERSION_NUM>=501)) - - ok=luaL_dostring(L,str); /* looks like this is lua 5.1.X or later, good */ -#else - - ok=lua_dostring(L,str); /* might be lua 5.0.x, using lua_dostring */ -#endif - - if (ok!=0) - printf("[C] ERROR in dostring: %s\n",lua_tostring(L,-1)); - return ok; -} - - -int main(int argc,char* argv[]) { - lua_State *L; - int ok; - printf("[C] Welcome to the simple embedded lua example\n"); - printf("[C] We are in C\n"); - printf("[C] opening a lua state & loading the libraries\n"); - L=lua_open(); - luaopen_base(L); - luaopen_string(L); - luaopen_math(L); - printf("[C] now loading the SWIG wrappered library\n"); - luaopen_example(L); - printf("[C] all looks ok\n"); - printf("\n"); - printf("[C] lets load the file 'runme.lua'\n"); - printf("[C] any lua code in this file will be executed\n"); - if (luaL_loadfile(L, "runme.lua") || lua_pcall(L, 0, 0, 0)) { - printf("[C] ERROR: cannot run lua file: %s",lua_tostring(L, -1)); - exit(3); - } - printf("[C] We are now back in C, all looks ok\n"); - printf("\n"); - printf("[C] lets call the function 'do_tests()'\n"); - ok=dostring(L,"do_tests()"); - printf("[C] We are back in C, the dostring() function returned %d\n",ok); - printf("\n"); - printf("[C] Lets call lua again, but create an error\n"); - ok=dostring(L,"no_such_function()"); - printf("[C] We are back in C, the dostring() function returned %d\n",ok); - printf("[C] it should also have returned 1 and printed an error message\n"); - printf("\n"); - printf("[C] Lets call lua again, calling the greeting function\n"); - ok=dostring(L,"call_greeting()"); - printf("[C] This was C=>Lua=>C (getting a bit complex)\n"); - printf("\n"); - printf("[C] all finished, closing the lua state\n"); - lua_close(L); - return 0; -} +/* embed.c a simple test for an embeded interpreter + +The idea is that we wrapper a few simple function (example.c) +and write our own app to call it. + +What it will do is load the wrappered lib, load runme.lua and then call some functions. +To make life easier, all the printf's have either [C] or [Lua] at the start +so you can see where they are coming from. + +We will be using the luaL_dostring()/lua_dostring() function to call into lua + +*/ + +#include +#include + +#include +#include +#include + +/* the SWIG wrappered library */ +extern int luaopen_example(lua_State*L); + +/* a really simple way of calling lua from C + just give it a lua state & a string to execute +Unfortunately lua keeps changing its API's. +In lua 5.0.X its lua_dostring() +In lua 5.1.X its luaL_dostring() +so we have a few extra compiles +*/ +int dostring(lua_State *L, char* str) { + int ok; +#if (defined(LUA_VERSION_NUM) && (LUA_VERSION_NUM>=501)) + + ok=luaL_dostring(L,str); /* looks like this is lua 5.1.X or later, good */ +#else + + ok=lua_dostring(L,str); /* might be lua 5.0.x, using lua_dostring */ +#endif + + if (ok!=0) + printf("[C] ERROR in dostring: %s\n",lua_tostring(L,-1)); + return ok; +} + + +int main(int argc,char* argv[]) { + lua_State *L; + int ok; + printf("[C] Welcome to the simple embedded lua example\n"); + printf("[C] We are in C\n"); + printf("[C] opening a lua state & loading the libraries\n"); + L=lua_open(); + luaopen_base(L); + luaopen_string(L); + luaopen_math(L); + printf("[C] now loading the SWIG wrappered library\n"); + luaopen_example(L); + printf("[C] all looks ok\n"); + printf("\n"); + printf("[C] lets load the file 'runme.lua'\n"); + printf("[C] any lua code in this file will be executed\n"); + if (luaL_loadfile(L, "runme.lua") || lua_pcall(L, 0, 0, 0)) { + printf("[C] ERROR: cannot run lua file: %s",lua_tostring(L, -1)); + exit(3); + } + printf("[C] We are now back in C, all looks ok\n"); + printf("\n"); + printf("[C] lets call the function 'do_tests()'\n"); + ok=dostring(L,"do_tests()"); + printf("[C] We are back in C, the dostring() function returned %d\n",ok); + printf("\n"); + printf("[C] Lets call lua again, but create an error\n"); + ok=dostring(L,"no_such_function()"); + printf("[C] We are back in C, the dostring() function returned %d\n",ok); + printf("[C] it should also have returned 1 and printed an error message\n"); + printf("\n"); + printf("[C] Lets call lua again, calling the greeting function\n"); + ok=dostring(L,"call_greeting()"); + printf("[C] This was C=>Lua=>C (getting a bit complex)\n"); + printf("\n"); + printf("[C] all finished, closing the lua state\n"); + lua_close(L); + return 0; +} diff --git a/Examples/lua/embed/example.c b/Examples/lua/embed/example.c index c6c6d7ba1..efd13f662 100644 --- a/Examples/lua/embed/example.c +++ b/Examples/lua/embed/example.c @@ -1,22 +1,22 @@ -/* File : example.c */ - -#include - -/* 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; -} - -void greeting() { - printf("Hello from the C function 'greeting'\n"); -} +/* File : example.c */ + +#include + +/* 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; +} + +void greeting() { + printf("Hello from the C function 'greeting'\n"); +} diff --git a/Examples/lua/embed2/embed2.c b/Examples/lua/embed2/embed2.c index dac527eb4..8d28ee6ea 100644 --- a/Examples/lua/embed2/embed2.c +++ b/Examples/lua/embed2/embed2.c @@ -1,233 +1,233 @@ -/* embed2.c some more test for an embeded interpreter - -This will go a bit further as it will pass values to and from the lua code. -It uses less of the SWIG code, and more of the raw lua API's - -What it will do is load the wrappered lib, load runme.lua and then call some functions. -To make life easier, all the printf's have either [C] or [Lua] at the start -so you can see where they are coming from. - -We will be using the luaL_dostring()/lua_dostring() function to call into lua - -*/ - -/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ -#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) -# define _CRT_SECURE_NO_DEPRECATE -#endif - -/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ -#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) -# define _SCL_SECURE_NO_DEPRECATE -#endif - - -#include -#include - -#include -#include -#include -#include -#include - - -/* the SWIG wrappered library */ -extern int luaopen_example(lua_State*L); - -/* This is an example of how to call the Lua function - int add(int,int) - its very tedious, but gives you an idea of the issues involded. - (look below for a better idea) -*/ -int call_add(lua_State *L,int a,int b,int* res) { - int top; - /* ok, here we go: - push a, push b, call 'add' check & return res - */ - top=lua_gettop(L); /* for later */ - lua_pushstring(L, "add"); /* function name */ - lua_gettable(L, LUA_GLOBALSINDEX); /* function to be called */ - if (!lua_isfunction(L,-1)) { - printf("[C] error: cannot find function 'add'\n"); - lua_settop(L,top); // reset - return 0; - } - lua_pushnumber(L,a); - lua_pushnumber(L,b); - if (lua_pcall(L, 2, 1, 0) != 0) /* call function with 2 arguments and 1 result */ - { - printf("[C] error running function `add': %s\n",lua_tostring(L, -1)); - lua_settop(L,top); // reset - return 0; - } - // check results - if (!lua_isnumber(L,-1)) { - printf("[C] error: returned value is not a number\n"); - lua_settop(L,top); // reset - return 0; - } - *res=(int)lua_tonumber(L,-1); - lua_settop(L,top); /* reset stack */ - return 1; // ok -} - -/* This is a variargs call function for calling from C into Lua. -Original Code from Programming in Lua (PIL) by Roberto Ierusalimschy -ISBN 85-903798-1-7 -http://www.lua.org/pil/25.3.html -This has been modified slightly to make it compile, and its still a bit rough. -But it gives the idea of how to make it work. -*/ -int call_va (lua_State *L,const char *func, const char *sig, ...) { - va_list vl; - int narg, nres; /* number of arguments and results */ - int top; - top=lua_gettop(L); /* for later */ - - va_start(vl, sig); - lua_getglobal(L, func); /* get function */ - - /* push arguments */ - narg = 0; - while (*sig) { /* push arguments */ - switch (*sig++) { - - case 'd': /* double argument */ - lua_pushnumber(L, va_arg(vl, double)); - break; - - case 'i': /* int argument */ - lua_pushnumber(L, va_arg(vl, int)); - break; - - case 's': /* string argument */ - lua_pushstring(L, va_arg(vl, char *)); - break; - - case '>': - goto endwhile; - - default: - printf("invalid option (%c)\n", *(sig - 1)); - goto fail; - } - narg++; - /* do we need this?*/ - /* luaL_checkstack(L, 1, "too many arguments"); */ - } -endwhile: - - /* do the call */ - nres = (int)strlen(sig); /* number of expected results */ - if (lua_pcall(L, narg, nres, 0) != 0) /* do the call */ - { - printf("error running function `%s': %s\n",func, lua_tostring(L, -1)); - goto fail; - } - - /* retrieve results */ - nres = -nres; /* stack index of first result */ - while (*sig) { /* get results */ - switch (*sig++) { - - case 'd': /* double result */ - if (!lua_isnumber(L, nres)) { - printf("wrong result type\n"); - goto fail; - } - *va_arg(vl, double *) = lua_tonumber(L, nres); - break; - - case 'i': /* int result */ - if (!lua_isnumber(L, nres)) { - printf("wrong result type\n"); - goto fail; - } - *va_arg(vl, int *) = (int)lua_tonumber(L, nres); - break; - - case 's': /* string result */ - if (!lua_isstring(L, nres)) { - printf("wrong result type\n"); - goto fail; - } - strcpy(va_arg(vl, char *),lua_tostring(L, nres));/* WARNING possible buffer overflow */ - break; - - default: { - printf("invalid option (%c)", *(sig - 1)); - goto fail; - } - } - nres++; - } - va_end(vl); - - lua_settop(L,top); /* reset stack */ - return 1; /* ok */ -fail: - lua_settop(L,top); /* reset stack */ - return 0; /* error */ -} - -int main(int argc,char* argv[]) { - lua_State *L; - int ok; - int res; - char str[80]; - printf("[C] Welcome to the simple embedded Lua example v2\n"); - printf("[C] We are in C\n"); - printf("[C] opening a Lua state & loading the libraries\n"); - L=lua_open(); - luaopen_base(L); - luaopen_string(L); - luaopen_math(L); - printf("[C] now loading the SWIG wrappered library\n"); - luaopen_example(L); - printf("[C] all looks ok\n"); - printf("\n"); - printf("[C] lets load the file 'runme.lua'\n"); - printf("[C] any lua code in this file will be executed\n"); - if (luaL_loadfile(L, "runme.lua") || lua_pcall(L, 0, 0, 0)) { - printf("[C] ERROR: cannot run lua file: %s",lua_tostring(L, -1)); - exit(3); - } - printf("[C] We are now back in C, all looks ok\n"); - printf("\n"); - printf("[C] lets call the Lua function 'add(1,1)'\n"); - printf("[C] using the C function 'call_add'\n"); - ok=call_add(L,1,1,&res); - printf("[C] the function returned %d with value %d\n",ok,res); - printf("\n"); - printf("[C] lets do this rather easier\n"); - printf("[C] we will call the same Lua function using a generic C function 'call_va'\n"); - ok=call_va(L,"add","ii>i",1,1,&res); - printf("[C] the function returned %d with value %d\n",ok,res); - printf("\n"); - printf("[C] we will now use the same generic C function to call 'append(\"cat\",\"dog\")'\n"); - ok=call_va(L,"append","ss>s","cat","dog",str); - printf("[C] the function returned %d with value %s\n",ok,str); - printf("\n"); - printf("[C] we can also make some bad calls to ensure the code doesn't fail\n"); - printf("[C] calling adds(1,2)\n"); - ok=call_va(L,"adds","ii>i",1,2,&res); - printf("[C] the function returned %d with value %d\n",ok,res); - printf("[C] calling add(1,'fred')\n"); - ok=call_va(L,"add","is>i",1,"fred",&res); - printf("[C] the function returned %d with value %d\n",ok,res); - printf("\n"); - printf("[C] Note: no protection if you mess up the va-args, this is C\n"); - printf("\n"); - printf("[C] Finally we will call the wrappered gcd function gdc(6,9):\n"); - printf("[C] This will pass the values to Lua, then call the wrappered function\n"); - printf(" Which will get the values from Lua, call the C code \n"); - printf(" and return the value to Lua and eventually back to C\n"); - printf("[C] Certainly not the best way to do it :-)\n"); - ok=call_va(L,"gcd","ii>i",6,9,&res); - printf("[C] the function returned %d with value %d\n",ok,res); - printf("\n"); - printf("[C] all finished, closing the lua state\n"); - lua_close(L); - return 0; -} +/* embed2.c some more test for an embeded interpreter + +This will go a bit further as it will pass values to and from the lua code. +It uses less of the SWIG code, and more of the raw lua API's + +What it will do is load the wrappered lib, load runme.lua and then call some functions. +To make life easier, all the printf's have either [C] or [Lua] at the start +so you can see where they are coming from. + +We will be using the luaL_dostring()/lua_dostring() function to call into lua + +*/ + +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ +#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) +# define _CRT_SECURE_NO_DEPRECATE +#endif + +/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ +#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) +# define _SCL_SECURE_NO_DEPRECATE +#endif + + +#include +#include + +#include +#include +#include +#include +#include + + +/* the SWIG wrappered library */ +extern int luaopen_example(lua_State*L); + +/* This is an example of how to call the Lua function + int add(int,int) + its very tedious, but gives you an idea of the issues involded. + (look below for a better idea) +*/ +int call_add(lua_State *L,int a,int b,int* res) { + int top; + /* ok, here we go: + push a, push b, call 'add' check & return res + */ + top=lua_gettop(L); /* for later */ + lua_pushstring(L, "add"); /* function name */ + lua_gettable(L, LUA_GLOBALSINDEX); /* function to be called */ + if (!lua_isfunction(L,-1)) { + printf("[C] error: cannot find function 'add'\n"); + lua_settop(L,top); // reset + return 0; + } + lua_pushnumber(L,a); + lua_pushnumber(L,b); + if (lua_pcall(L, 2, 1, 0) != 0) /* call function with 2 arguments and 1 result */ + { + printf("[C] error running function `add': %s\n",lua_tostring(L, -1)); + lua_settop(L,top); // reset + return 0; + } + // check results + if (!lua_isnumber(L,-1)) { + printf("[C] error: returned value is not a number\n"); + lua_settop(L,top); // reset + return 0; + } + *res=(int)lua_tonumber(L,-1); + lua_settop(L,top); /* reset stack */ + return 1; // ok +} + +/* This is a variargs call function for calling from C into Lua. +Original Code from Programming in Lua (PIL) by Roberto Ierusalimschy +ISBN 85-903798-1-7 +http://www.lua.org/pil/25.3.html +This has been modified slightly to make it compile, and its still a bit rough. +But it gives the idea of how to make it work. +*/ +int call_va (lua_State *L,const char *func, const char *sig, ...) { + va_list vl; + int narg, nres; /* number of arguments and results */ + int top; + top=lua_gettop(L); /* for later */ + + va_start(vl, sig); + lua_getglobal(L, func); /* get function */ + + /* push arguments */ + narg = 0; + while (*sig) { /* push arguments */ + switch (*sig++) { + + case 'd': /* double argument */ + lua_pushnumber(L, va_arg(vl, double)); + break; + + case 'i': /* int argument */ + lua_pushnumber(L, va_arg(vl, int)); + break; + + case 's': /* string argument */ + lua_pushstring(L, va_arg(vl, char *)); + break; + + case '>': + goto endwhile; + + default: + printf("invalid option (%c)\n", *(sig - 1)); + goto fail; + } + narg++; + /* do we need this?*/ + /* luaL_checkstack(L, 1, "too many arguments"); */ + } +endwhile: + + /* do the call */ + nres = (int)strlen(sig); /* number of expected results */ + if (lua_pcall(L, narg, nres, 0) != 0) /* do the call */ + { + printf("error running function `%s': %s\n",func, lua_tostring(L, -1)); + goto fail; + } + + /* retrieve results */ + nres = -nres; /* stack index of first result */ + while (*sig) { /* get results */ + switch (*sig++) { + + case 'd': /* double result */ + if (!lua_isnumber(L, nres)) { + printf("wrong result type\n"); + goto fail; + } + *va_arg(vl, double *) = lua_tonumber(L, nres); + break; + + case 'i': /* int result */ + if (!lua_isnumber(L, nres)) { + printf("wrong result type\n"); + goto fail; + } + *va_arg(vl, int *) = (int)lua_tonumber(L, nres); + break; + + case 's': /* string result */ + if (!lua_isstring(L, nres)) { + printf("wrong result type\n"); + goto fail; + } + strcpy(va_arg(vl, char *),lua_tostring(L, nres));/* WARNING possible buffer overflow */ + break; + + default: { + printf("invalid option (%c)", *(sig - 1)); + goto fail; + } + } + nres++; + } + va_end(vl); + + lua_settop(L,top); /* reset stack */ + return 1; /* ok */ +fail: + lua_settop(L,top); /* reset stack */ + return 0; /* error */ +} + +int main(int argc,char* argv[]) { + lua_State *L; + int ok; + int res; + char str[80]; + printf("[C] Welcome to the simple embedded Lua example v2\n"); + printf("[C] We are in C\n"); + printf("[C] opening a Lua state & loading the libraries\n"); + L=lua_open(); + luaopen_base(L); + luaopen_string(L); + luaopen_math(L); + printf("[C] now loading the SWIG wrappered library\n"); + luaopen_example(L); + printf("[C] all looks ok\n"); + printf("\n"); + printf("[C] lets load the file 'runme.lua'\n"); + printf("[C] any lua code in this file will be executed\n"); + if (luaL_loadfile(L, "runme.lua") || lua_pcall(L, 0, 0, 0)) { + printf("[C] ERROR: cannot run lua file: %s",lua_tostring(L, -1)); + exit(3); + } + printf("[C] We are now back in C, all looks ok\n"); + printf("\n"); + printf("[C] lets call the Lua function 'add(1,1)'\n"); + printf("[C] using the C function 'call_add'\n"); + ok=call_add(L,1,1,&res); + printf("[C] the function returned %d with value %d\n",ok,res); + printf("\n"); + printf("[C] lets do this rather easier\n"); + printf("[C] we will call the same Lua function using a generic C function 'call_va'\n"); + ok=call_va(L,"add","ii>i",1,1,&res); + printf("[C] the function returned %d with value %d\n",ok,res); + printf("\n"); + printf("[C] we will now use the same generic C function to call 'append(\"cat\",\"dog\")'\n"); + ok=call_va(L,"append","ss>s","cat","dog",str); + printf("[C] the function returned %d with value %s\n",ok,str); + printf("\n"); + printf("[C] we can also make some bad calls to ensure the code doesn't fail\n"); + printf("[C] calling adds(1,2)\n"); + ok=call_va(L,"adds","ii>i",1,2,&res); + printf("[C] the function returned %d with value %d\n",ok,res); + printf("[C] calling add(1,'fred')\n"); + ok=call_va(L,"add","is>i",1,"fred",&res); + printf("[C] the function returned %d with value %d\n",ok,res); + printf("\n"); + printf("[C] Note: no protection if you mess up the va-args, this is C\n"); + printf("\n"); + printf("[C] Finally we will call the wrappered gcd function gdc(6,9):\n"); + printf("[C] This will pass the values to Lua, then call the wrappered function\n"); + printf(" Which will get the values from Lua, call the C code \n"); + printf(" and return the value to Lua and eventually back to C\n"); + printf("[C] Certainly not the best way to do it :-)\n"); + ok=call_va(L,"gcd","ii>i",6,9,&res); + printf("[C] the function returned %d with value %d\n",ok,res); + printf("\n"); + printf("[C] all finished, closing the lua state\n"); + lua_close(L); + return 0; +} diff --git a/Examples/lua/embed2/example.c b/Examples/lua/embed2/example.c index c6c6d7ba1..efd13f662 100644 --- a/Examples/lua/embed2/example.c +++ b/Examples/lua/embed2/example.c @@ -1,22 +1,22 @@ -/* File : example.c */ - -#include - -/* 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; -} - -void greeting() { - printf("Hello from the C function 'greeting'\n"); -} +/* File : example.c */ + +#include + +/* 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; +} + +void greeting() { + printf("Hello from the C function 'greeting'\n"); +} diff --git a/Examples/lua/embed3/example.i b/Examples/lua/embed3/example.i index 032805c0e..950d2549d 100644 --- a/Examples/lua/embed3/example.i +++ b/Examples/lua/embed3/example.i @@ -1,8 +1,8 @@ -/* File : example.i */ -%module example - -%{ -#include "example.h" -%} - -%include "example.h" +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +%include "example.h" diff --git a/Examples/lua/exception/Makefile b/Examples/lua/exception/Makefile index 8657f1922..0feee14dd 100644 --- a/Examples/lua/exception/Makefile +++ b/Examples/lua/exception/Makefile @@ -1,19 +1,19 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = -TARGET = example -INTERFACE = example.i -LIBS = -lm - -all:: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp - -static:: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static - -clean:: - $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = +TARGET = example +INTERFACE = example.i +LIBS = -lm + +all:: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp + +static:: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static + +clean:: + $(MAKE) -f $(TOP)/Makefile lua_clean + +check: all diff --git a/Examples/lua/exception/example.h b/Examples/lua/exception/example.h index 5148a5962..251ef1132 100644 --- a/Examples/lua/exception/example.h +++ b/Examples/lua/exception/example.h @@ -1,53 +1,53 @@ -/* File : example.h */ - -#include -#ifndef SWIG -struct A { -}; -#endif - -class Exc { -public: - Exc(int c, const char *m) { - code = c; - strncpy(msg,m,256); - } - int code; - char msg[256]; -}; - -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif - -class Test { -public: - int simple() throw(int&) { - throw(37); - return 1; - } - int message() throw(const char *) { - throw("I died."); - return 1; - } - int hosed() throw(Exc) { - throw(Exc(42,"Hosed")); - return 1; - } - int unknown() throw(A*) { - static A a; - throw &a; - return 1; - } - int multi(int x) throw(int, const char *, Exc) { - if (x == 1) throw(37); - if (x == 2) throw("Bleah!"); - if (x == 3) throw(Exc(42,"No-go-diggy-die")); - return 1; - } -}; - -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif - +/* File : example.h */ + +#include +#ifndef SWIG +struct A { +}; +#endif + +class Exc { +public: + Exc(int c, const char *m) { + code = c; + strncpy(msg,m,256); + } + int code; + char msg[256]; +}; + +#if defined(_MSC_VER) + #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) +#endif + +class Test { +public: + int simple() throw(int&) { + throw(37); + return 1; + } + int message() throw(const char *) { + throw("I died."); + return 1; + } + int hosed() throw(Exc) { + throw(Exc(42,"Hosed")); + return 1; + } + int unknown() throw(A*) { + static A a; + throw &a; + return 1; + } + int multi(int x) throw(int, const char *, Exc) { + if (x == 1) throw(37); + if (x == 2) throw("Bleah!"); + if (x == 3) throw(Exc(42,"No-go-diggy-die")); + return 1; + } +}; + +#if defined(_MSC_VER) + #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) +#endif + diff --git a/Examples/lua/exception/example.i b/Examples/lua/exception/example.i index 09cd9e812..6187f8eff 100644 --- a/Examples/lua/exception/example.i +++ b/Examples/lua/exception/example.i @@ -1,17 +1,17 @@ -/* File : example.i */ -%module example - -%{ -#include "example.h" -%} - -%include "std_string.i" - -// we want to return Exc objects to the interpreter -// therefore we add this typemap -// note: only works if Exc is copyable -%apply SWIGTYPE EXCEPTION_BY_VAL {Exc}; - -/* Let's just grab the original header file here */ -%include "example.h" - +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +%include "std_string.i" + +// we want to return Exc objects to the interpreter +// therefore we add this typemap +// note: only works if Exc is copyable +%apply SWIGTYPE EXCEPTION_BY_VAL {Exc}; + +/* Let's just grab the original header file here */ +%include "example.h" + diff --git a/Examples/lua/exception/runme.lua b/Examples/lua/exception/runme.lua index 39b2d6da8..d8125caec 100644 --- a/Examples/lua/exception/runme.lua +++ b/Examples/lua/exception/runme.lua @@ -1,96 +1,96 @@ --- file: example.lua - ----- importing ---- -if string.sub(_VERSION,1,7)=='Lua 5.0' then - -- lua5.0 doesnt have a nice way to do this - lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example') - assert(lib)() -else - -- lua 5.1 does - require('example') -end - --- throw a lot of exceptions: --- you must catch exceptions using pcall and then checking the result - -t = example.Test() - -print "calling t:unknown()" -ok,res=pcall(function() t:unknown() end) -if ok then - print " that worked! Funny" -else - print(" call failed with error:",res) -end - -print "calling t:simple()" -ok,res=pcall(function() t:simple() end) -if ok then - print " that worked! Funny" -else - print(" call failed with error:",res) -end - -print "calling t:message()" -ok,res=pcall(function() t:message() end) -if ok then - print " that worked! Funny" -else - print(" call failed with error:",res) -end - -print "calling t:hosed()" -ok,res=pcall(function() t:hosed() end) -if ok then - print " that worked! Funny" -else - print(" call failed with error:",res.code,res.msg) -end - --- this is a rather strange way to perform the multiple catch of exceptions -print "calling t:mutli()" -for i=1,3 do - ok,res=pcall(function() t:multi(i) end) - if ok then - print " that worked! Funny" - else - if swig_type(res)=="Exc *" then - print(" call failed with Exc exception:",res.code,res.msg) - else - print(" call failed with error:",res) - end - end -end - --- this is a bit crazy, but it shows obtaining of the stacktrace -function a() - b() -end -function b() - t:message() -end -print [[ -Now lets call function a() - which calls b() - which calls into C++ - which will throw an exception!]] -ok,res=pcall(a) -if ok then - print " that worked! Funny" -else - print(" call failed with error:",res) -end -print "Now lets do the same using xpcall(a,debug.traceback)" -ok,res=xpcall(a,debug.traceback) -if ok then - print " that worked! Funny" -else - print(" call failed with error:",res) -end -print "As you can see, the xpcall gives a nice stacktrace to work with" - - -ok,res=pcall(a) -print(ok,res) -ok,res=xpcall(a,debug.traceback) -print(ok,res) +-- file: example.lua + +---- importing ---- +if string.sub(_VERSION,1,7)=='Lua 5.0' then + -- lua5.0 doesnt have a nice way to do this + lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example') + assert(lib)() +else + -- lua 5.1 does + require('example') +end + +-- throw a lot of exceptions: +-- you must catch exceptions using pcall and then checking the result + +t = example.Test() + +print "calling t:unknown()" +ok,res=pcall(function() t:unknown() end) +if ok then + print " that worked! Funny" +else + print(" call failed with error:",res) +end + +print "calling t:simple()" +ok,res=pcall(function() t:simple() end) +if ok then + print " that worked! Funny" +else + print(" call failed with error:",res) +end + +print "calling t:message()" +ok,res=pcall(function() t:message() end) +if ok then + print " that worked! Funny" +else + print(" call failed with error:",res) +end + +print "calling t:hosed()" +ok,res=pcall(function() t:hosed() end) +if ok then + print " that worked! Funny" +else + print(" call failed with error:",res.code,res.msg) +end + +-- this is a rather strange way to perform the multiple catch of exceptions +print "calling t:mutli()" +for i=1,3 do + ok,res=pcall(function() t:multi(i) end) + if ok then + print " that worked! Funny" + else + if swig_type(res)=="Exc *" then + print(" call failed with Exc exception:",res.code,res.msg) + else + print(" call failed with error:",res) + end + end +end + +-- this is a bit crazy, but it shows obtaining of the stacktrace +function a() + b() +end +function b() + t:message() +end +print [[ +Now lets call function a() + which calls b() + which calls into C++ + which will throw an exception!]] +ok,res=pcall(a) +if ok then + print " that worked! Funny" +else + print(" call failed with error:",res) +end +print "Now lets do the same using xpcall(a,debug.traceback)" +ok,res=xpcall(a,debug.traceback) +if ok then + print " that worked! Funny" +else + print(" call failed with error:",res) +end +print "As you can see, the xpcall gives a nice stacktrace to work with" + + +ok,res=pcall(a) +print(ok,res) +ok,res=xpcall(a,debug.traceback) +print(ok,res) diff --git a/Examples/lua/owner/Makefile b/Examples/lua/owner/Makefile index 1fe68ec7f..44888f66f 100644 --- a/Examples/lua/owner/Makefile +++ b/Examples/lua/owner/Makefile @@ -1,19 +1,19 @@ -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)' lua_cpp - -static:: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static - -clean:: - $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all +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)' lua_cpp + +static:: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static + +clean:: + $(MAKE) -f $(TOP)/Makefile lua_clean + +check: all diff --git a/Examples/lua/owner/example.cxx b/Examples/lua/owner/example.cxx index d6caeef15..bce484aea 100644 --- a/Examples/lua/owner/example.cxx +++ b/Examples/lua/owner/example.cxx @@ -1,69 +1,69 @@ -/* File : example.c */ - -#include "example.h" -#include - -#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; -} - -Circle* createCircle(double w) -{ - return new Circle(w); -} - -Square* createSquare(double w) -{ - return new Square(w); -} - -ShapeOwner::ShapeOwner() {printf(" ShapeOwner(%p)\n",this);} -ShapeOwner::~ShapeOwner() -{ - printf(" ~ShapeOwner(%p)\n",this); - for(unsigned i=0;i= static_cast(shapes.size())) - return NULL; - return shapes[idx]; -} - -Shape* ShapeOwner::remove(int idx) // this method returns memory which must be deleted -{ - if (idx < 0 || idx >= static_cast(shapes.size())) - return NULL; - Shape* ptr=shapes[idx]; - shapes.erase(shapes.begin()+idx); - return ptr; -} +/* File : example.c */ + +#include "example.h" +#include + +#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; +} + +Circle* createCircle(double w) +{ + return new Circle(w); +} + +Square* createSquare(double w) +{ + return new Square(w); +} + +ShapeOwner::ShapeOwner() {printf(" ShapeOwner(%p)\n",this);} +ShapeOwner::~ShapeOwner() +{ + printf(" ~ShapeOwner(%p)\n",this); + for(unsigned i=0;i= static_cast(shapes.size())) + return NULL; + return shapes[idx]; +} + +Shape* ShapeOwner::remove(int idx) // this method returns memory which must be deleted +{ + if (idx < 0 || idx >= static_cast(shapes.size())) + return NULL; + Shape* ptr=shapes[idx]; + shapes.erase(shapes.begin()+idx); + return ptr; +} diff --git a/Examples/lua/owner/example.h b/Examples/lua/owner/example.h index b00568025..320bb2569 100644 --- a/Examples/lua/owner/example.h +++ b/Examples/lua/owner/example.h @@ -1,54 +1,54 @@ -/* File : example.h */ -#include - -class Shape { -public: - Shape() { - nshapes++; - } - virtual ~Shape() { - nshapes--; - }; - double x, y; - void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; - static int nshapes; -}; - -class Circle : public Shape { -private: - double radius; -public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); -}; - -class Square : public Shape { -private: - double width; -public: - Square(double w) : width(w) { }; - virtual double area(void); - virtual double perimeter(void); -}; - - -Circle* createCircle(double w); // this method creates a new object -Square* createSquare(double w); // this method creates a new object - -class ShapeOwner { -private: - std::vector shapes; - ShapeOwner(const ShapeOwner&); // no copying - ShapeOwner& operator=(const ShapeOwner&); // no copying -public: - ShapeOwner(); - ~ShapeOwner(); - void add(Shape* ptr); // this method takes ownership of the object - Shape* get(int idx); // this pointer is still owned by the class (assessor) - Shape* remove(int idx); // this method returns memory which must be deleted -}; - - +/* File : example.h */ +#include + +class Shape { +public: + Shape() { + nshapes++; + } + virtual ~Shape() { + nshapes--; + }; + double x, y; + void move(double dx, double dy); + virtual double area(void) = 0; + virtual double perimeter(void) = 0; + static int nshapes; +}; + +class Circle : public Shape { +private: + double radius; +public: + Circle(double r) : radius(r) { }; + virtual double area(void); + virtual double perimeter(void); +}; + +class Square : public Shape { +private: + double width; +public: + Square(double w) : width(w) { }; + virtual double area(void); + virtual double perimeter(void); +}; + + +Circle* createCircle(double w); // this method creates a new object +Square* createSquare(double w); // this method creates a new object + +class ShapeOwner { +private: + std::vector shapes; + ShapeOwner(const ShapeOwner&); // no copying + ShapeOwner& operator=(const ShapeOwner&); // no copying +public: + ShapeOwner(); + ~ShapeOwner(); + void add(Shape* ptr); // this method takes ownership of the object + Shape* get(int idx); // this pointer is still owned by the class (assessor) + Shape* remove(int idx); // this method returns memory which must be deleted +}; + + diff --git a/Examples/lua/owner/example.i b/Examples/lua/owner/example.i index 4e7c331bc..1dfac4a09 100644 --- a/Examples/lua/owner/example.i +++ b/Examples/lua/owner/example.i @@ -1,32 +1,32 @@ -/* File : example.i */ -%module example - -%{ -#include "example.h" -%} - -// before we grab the header file, we must warn SWIG about some of these functions. - -// these functions create data, so must be managed -%newobject createCircle; -%newobject createSquare; - -// this method returns as pointer which must be managed -%newobject ShapeOwner::remove; - -// you cannot use %delobject on ShapeOwner::add() -// as this disowns the ShapeOwner, not the Shape (oops) -//%delobject ShapeOwner::add(Shape*); DO NOT USE - -// either you can use a new function (such as this) -/*%delobject add_Shape; -%inline %{ -void add_Shape(Shape* s,ShapeOwner* own){own->add(s);} -%}*/ - -// or a better solution is a typemap -%apply SWIGTYPE *DISOWN {Shape* ptr}; - -// now we can grab the header file -%include "example.h" - +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +// before we grab the header file, we must warn SWIG about some of these functions. + +// these functions create data, so must be managed +%newobject createCircle; +%newobject createSquare; + +// this method returns as pointer which must be managed +%newobject ShapeOwner::remove; + +// you cannot use %delobject on ShapeOwner::add() +// as this disowns the ShapeOwner, not the Shape (oops) +//%delobject ShapeOwner::add(Shape*); DO NOT USE + +// either you can use a new function (such as this) +/*%delobject add_Shape; +%inline %{ +void add_Shape(Shape* s,ShapeOwner* own){own->add(s);} +%}*/ + +// or a better solution is a typemap +%apply SWIGTYPE *DISOWN {Shape* ptr}; + +// now we can grab the header file +%include "example.h" + diff --git a/Examples/lua/owner/runme.lua b/Examples/lua/owner/runme.lua index d2d8a9c6f..ed745f7b2 100644 --- a/Examples/lua/owner/runme.lua +++ b/Examples/lua/owner/runme.lua @@ -1,104 +1,104 @@ --- Operator overloading example ----- importing ---- -if string.sub(_VERSION,1,7)=='Lua 5.0' then - -- lua5.0 doesnt have a nice way to do this - lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example') - assert(lib)() -else - -- lua 5.1 does - require('example') -end - -print "ok, lets test Lua's ownership of C++ objects" -print("Currently there are",example.Shape_nshapes,"shapes (there should be 0)") - -print "\nLets make a couple" -a=example.Square(10) -b=example.Circle(1) -print("Currently there are",example.Shape_nshapes,"shapes (there should be 2)") - -print "\nNote lets use the createX functions" -c=example.createCircle(5) -d=example.createSquare(3) -print("Currently there are",example.Shape_nshapes,"shapes (there should be 4)") - -print "\nWe will run the garbage collector & see if they are till here" -collectgarbage() -print("Currently there are",example.Shape_nshapes,"shapes (there should be 4)") - -print "\nLets get rid of them all, collect garbage & see if they are till here" -a,b,c,d=nil,nil,nil,nil -collectgarbage() -print("Currently there are",example.Shape_nshapes,"shapes (there should be 0)") - -print "\nLets start putting stuff into the ShapeOwner" -print "The ShapeOwner now owns the shapes, but Lua still has pointers to them" -o=example.ShapeOwner() -a=example.Square(10) -b=example.Circle(1) -o:add(a) -o:add(b) -o:add(example.createSquare(5)) -print("Currently there are",example.Shape_nshapes,"shapes (there should be 3)") - -print "\nWe will nil our references,run the garbage collector & see if they are till here" -print "they should be, as the ShapeOwner owns them" -a,b=nil,nil -collectgarbage() -print("Currently there are",example.Shape_nshapes,"shapes (there should be 3)") - -print "\nWe will access them and check that they are still valid" -a=o:get(0) -b=o:get(1) -print(" Area's are",a:area(),b:area(),o:get(2):area()) -collectgarbage() -print("Currently there are",example.Shape_nshapes,"shapes (there should be 3)") - -print "\nWe will remove one from the C++ owner & pass its ownership to Lua," -print " then check that they are still unchanged" -a,b=nil,nil -a=o:remove(0) -- a now owns it -collectgarbage() -print("Currently there are",example.Shape_nshapes,"shapes (there should be 3)") - -print "\nDelete the ShapeOwner (this should destroy two shapes)," -print " but we have one left in Lua" -o=nil -collectgarbage() -print("Currently there are",example.Shape_nshapes,"shapes (there should be 1)") - -print "\nFinal tidy up " -a=nil -collectgarbage() -print("Currently there are",example.Shape_nshapes,"shapes (there should be 0)") - - -print "Final test, we will create some Shapes & pass them around like mad" -print "If there is any memory leak, you will see it in the memory usage" -io.flush() -sh={} --- make some objects -for i=0,10 do - a=example.Circle(i) - b=example.Square(i) - sh[a]=true - sh[b]=true -end -o=example.ShapeOwner() -for i=0,10000 do - for k,_ in pairs(sh) do - o:add(k) - end - sh={} -- clear it - while true do - a=o:remove(0) - if a==nil then break end - sh[a]=true - end - if i%100==0 then collectgarbage() end -end -print "done" -o,sh=nil,nil -collectgarbage() -print("Currently there are",example.Shape_nshapes,"shapes (there should be 0)") -print "thats all folks!" \ No newline at end of file +-- Operator overloading example +---- importing ---- +if string.sub(_VERSION,1,7)=='Lua 5.0' then + -- lua5.0 doesnt have a nice way to do this + lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example') + assert(lib)() +else + -- lua 5.1 does + require('example') +end + +print "ok, lets test Lua's ownership of C++ objects" +print("Currently there are",example.Shape_nshapes,"shapes (there should be 0)") + +print "\nLets make a couple" +a=example.Square(10) +b=example.Circle(1) +print("Currently there are",example.Shape_nshapes,"shapes (there should be 2)") + +print "\nNote lets use the createX functions" +c=example.createCircle(5) +d=example.createSquare(3) +print("Currently there are",example.Shape_nshapes,"shapes (there should be 4)") + +print "\nWe will run the garbage collector & see if they are till here" +collectgarbage() +print("Currently there are",example.Shape_nshapes,"shapes (there should be 4)") + +print "\nLets get rid of them all, collect garbage & see if they are till here" +a,b,c,d=nil,nil,nil,nil +collectgarbage() +print("Currently there are",example.Shape_nshapes,"shapes (there should be 0)") + +print "\nLets start putting stuff into the ShapeOwner" +print "The ShapeOwner now owns the shapes, but Lua still has pointers to them" +o=example.ShapeOwner() +a=example.Square(10) +b=example.Circle(1) +o:add(a) +o:add(b) +o:add(example.createSquare(5)) +print("Currently there are",example.Shape_nshapes,"shapes (there should be 3)") + +print "\nWe will nil our references,run the garbage collector & see if they are till here" +print "they should be, as the ShapeOwner owns them" +a,b=nil,nil +collectgarbage() +print("Currently there are",example.Shape_nshapes,"shapes (there should be 3)") + +print "\nWe will access them and check that they are still valid" +a=o:get(0) +b=o:get(1) +print(" Area's are",a:area(),b:area(),o:get(2):area()) +collectgarbage() +print("Currently there are",example.Shape_nshapes,"shapes (there should be 3)") + +print "\nWe will remove one from the C++ owner & pass its ownership to Lua," +print " then check that they are still unchanged" +a,b=nil,nil +a=o:remove(0) -- a now owns it +collectgarbage() +print("Currently there are",example.Shape_nshapes,"shapes (there should be 3)") + +print "\nDelete the ShapeOwner (this should destroy two shapes)," +print " but we have one left in Lua" +o=nil +collectgarbage() +print("Currently there are",example.Shape_nshapes,"shapes (there should be 1)") + +print "\nFinal tidy up " +a=nil +collectgarbage() +print("Currently there are",example.Shape_nshapes,"shapes (there should be 0)") + + +print "Final test, we will create some Shapes & pass them around like mad" +print "If there is any memory leak, you will see it in the memory usage" +io.flush() +sh={} +-- make some objects +for i=0,10 do + a=example.Circle(i) + b=example.Square(i) + sh[a]=true + sh[b]=true +end +o=example.ShapeOwner() +for i=0,10000 do + for k,_ in pairs(sh) do + o:add(k) + end + sh={} -- clear it + while true do + a=o:remove(0) + if a==nil then break end + sh[a]=true + end + if i%100==0 then collectgarbage() end +end +print "done" +o,sh=nil,nil +collectgarbage() +print("Currently there are",example.Shape_nshapes,"shapes (there should be 0)") +print "thats all folks!" diff --git a/Examples/test-suite/csharp/li_std_map_runme.cs b/Examples/test-suite/csharp/li_std_map_runme.cs index 551cf2dc1..0fe1ab5cd 100644 --- a/Examples/test-suite/csharp/li_std_map_runme.cs +++ b/Examples/test-suite/csharp/li_std_map_runme.cs @@ -1,246 +1,246 @@ -/* ----------------------------------------------------------------------------- - * li_std_map_runme.cs - * - * SWIG C# tester for std_map.i - * This class tests all the functionality of the std_map.i wrapper. - * Upon successful testing, the main function doesn't print out anything. - * If any error is found - it will be printed on the screen. - * ----------------------------------------------------------------------------- */ - -using System; -using System.Collections.Generic; -using li_std_mapNamespace; - -public class li_std_map_runme { - - private static readonly int collectionSize = 20; - private static readonly int midCollection = collectionSize / 2; - - public static void Main() - { - // Set up an int int map - StringIntMap simap = new StringIntMap(); - for (int i = 0; i < collectionSize; i++) - { - int val = i * 18; - simap.Add(i.ToString(), val); - } - - // Count property test - if (simap.Count != collectionSize) - throw new Exception("Count test failed"); - - // IsReadOnly property test - if (simap.IsReadOnly) - throw new Exception("IsReadOnly test failed"); - - // Item indexing test - simap["0"] = 200; - if (simap["0"] != 200) - throw new Exception("Item property test failed"); - simap["0"] = 0 * 18; - - // ContainsKey() test - for (int i = 0; i < collectionSize; i++) - { - if (!simap.ContainsKey(i.ToString())) - throw new Exception("ContainsKey test " + i + " failed"); - } - - // ContainsKey() test - for (int i = 0; i < collectionSize; i++) - { - if (!simap.Contains(new KeyValuePair(i.ToString(), i * 18))) - throw new Exception("Contains test " + i + " failed"); - } - - // TryGetValue() test - int value; - bool rc = simap.TryGetValue("3", out value); - if (rc != true || value != (3 * 18)) - throw new Exception("TryGetValue test 1 failed"); - - rc = simap.TryGetValue("-1", out value); - if (rc != false) - throw new Exception("TryGetValue test 2 failed"); - - // Keys and Values test - { - IList keys = new List(simap.Keys); - IList values = new List(simap.Values); - Dictionary check = new Dictionary(); - if (keys.Count != collectionSize) - throw new Exception("Keys count test failed"); - - if (values.Count != collectionSize) - throw new Exception("Values count test failed"); - - for (int i = 0; i < keys.Count; i++) - { - if (simap[keys[i]] != values[i]) - throw new Exception("Keys and values test failed for index " + i); - check.Add(keys[i], values[i]); - } - - for (int i = 0; i < collectionSize; i++) - { - if (!check.ContainsKey(i.ToString())) - throw new Exception("Keys and Values ContainsKey test " + i + " failed"); - } - } - - // Add and Remove test - for (int i = 100; i < 103; i++) - { - simap.Add(i.ToString(), i * 18); - if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18)) - throw new Exception("Add test failed for index " + i); - - simap.Remove(i.ToString()); - if (simap.ContainsKey(i.ToString())) - throw new Exception("Remove test failed for index " + i); - } - - for (int i = 200; i < 203; i++) - { - simap.Add(new KeyValuePair(i.ToString(), i * 18)); - if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18)) - throw new Exception("Add explicit test failed for index " + i); - - simap.Remove(new KeyValuePair(i.ToString(), i * 18)); - if (simap.ContainsKey(i.ToString())) - throw new Exception("Remove explicit test failed for index " + i); - } - - // Duplicate key test - try - { - simap.Add("3", 0); - throw new Exception("Adding duplicate key test failed"); - } - catch (ArgumentException) - { - } - - // CopyTo() test - { - KeyValuePair[] outputarray = new KeyValuePair[collectionSize]; - simap.CopyTo(outputarray); - foreach (KeyValuePair val in outputarray) - { - if (simap[val.Key] != val.Value) - throw new Exception("CopyTo (1) test failed, index:" + val.Key); - } - } - { - KeyValuePair[] outputarray = new KeyValuePair[midCollection + collectionSize]; - simap.CopyTo(outputarray, midCollection); - for (int i = midCollection; i < midCollection + collectionSize; i++) - { - KeyValuePair val = outputarray[i]; - if (simap[val.Key] != val.Value) - throw new Exception("CopyTo (2) test failed, index:" + val.Key); - } - } - { - KeyValuePair[] outputarray = new KeyValuePair[collectionSize - 1]; - try - { - simap.CopyTo(outputarray); - throw new Exception("CopyTo (4) test failed"); - } - catch (ArgumentException) - { - } - } - - // Clear test - simap.Clear(); - if (simap.Count != 0) - throw new Exception("Clear test failed"); - - // Test wrapped methods - for (int i = 1; i <= 5; i++) - { - simap[i.ToString()] = i; - } - double avg = li_std_map.valueAverage(simap); - if (avg != 3.0) - throw new Exception("Wrapped method valueAverage test failed. Got " + avg); - - string keyStringified = li_std_map.stringifyKeys(simap); - if (keyStringified != " 1 2 3 4 5") - throw new Exception("Wrapped method stringifyKeys test failed. Got " + keyStringified); - - // Test a map with a new complex type (Struct) - { - IntStructMap ismap = new IntStructMap(); - for (int i = 0; i < 10; i++) - { - ismap.Add(i, new Struct(i * 10.1)); - } - - if (ismap.Count != 10) - throw new Exception("Count test on complex type map failed"); - - foreach (KeyValuePair p in ismap) - { - if ((p.Key * 10.1) != p.Value.num) - throw new Exception("Iteration test on complex type map failed for index " + p.Key); - } - } - - // Test a map of pointers - { - IntStructPtrMap ispmap = new IntStructPtrMap(); - for (int i = 0; i < 10; i++) - { - ispmap.Add(i, new Struct(i * 10.1)); - } - - if (ispmap.Count != 10) - throw new Exception("Count test on complex type pointer map failed"); - - foreach (KeyValuePair p in ispmap) - { - if ((p.Key * 10.1) != p.Value.num) - throw new Exception("Iteration test on complex type pointer map failed for index " + p.Key); - } - } - { - IntStructConstPtrMap iscpmap = new IntStructConstPtrMap(); - for (int i = 0; i < 10; i++) - { - iscpmap.Add(i, new Struct(i * 10.1)); - } - - if (iscpmap.Count != 10) - throw new Exception("Count test on complex type const pointer map failed"); - - foreach (KeyValuePair p in iscpmap) - { - if ((p.Key * 10.1) != p.Value.num) - throw new Exception("Iteration test on complex type const pointer map failed for index " + p.Key); - } - } - - // Test complex type as key (Struct) - { - StructIntMap limap = new StructIntMap(); - Struct s7 = new Struct(7); - Struct s8 = new Struct(8); - limap[s7] = 8; - if (limap[s7] != 8) - throw new Exception("Assignment test on complex key map failed"); - - if (!limap.ContainsKey(s7)) - throw new Exception("Key test (1) on complex key map failed"); - - if (limap.ContainsKey(s8)) - throw new Exception("Key test (2) on complex key map failed"); - } - - // All done - } -} - +/* ----------------------------------------------------------------------------- + * li_std_map_runme.cs + * + * SWIG C# tester for std_map.i + * This class tests all the functionality of the std_map.i wrapper. + * Upon successful testing, the main function doesn't print out anything. + * If any error is found - it will be printed on the screen. + * ----------------------------------------------------------------------------- */ + +using System; +using System.Collections.Generic; +using li_std_mapNamespace; + +public class li_std_map_runme { + + private static readonly int collectionSize = 20; + private static readonly int midCollection = collectionSize / 2; + + public static void Main() + { + // Set up an int int map + StringIntMap simap = new StringIntMap(); + for (int i = 0; i < collectionSize; i++) + { + int val = i * 18; + simap.Add(i.ToString(), val); + } + + // Count property test + if (simap.Count != collectionSize) + throw new Exception("Count test failed"); + + // IsReadOnly property test + if (simap.IsReadOnly) + throw new Exception("IsReadOnly test failed"); + + // Item indexing test + simap["0"] = 200; + if (simap["0"] != 200) + throw new Exception("Item property test failed"); + simap["0"] = 0 * 18; + + // ContainsKey() test + for (int i = 0; i < collectionSize; i++) + { + if (!simap.ContainsKey(i.ToString())) + throw new Exception("ContainsKey test " + i + " failed"); + } + + // ContainsKey() test + for (int i = 0; i < collectionSize; i++) + { + if (!simap.Contains(new KeyValuePair(i.ToString(), i * 18))) + throw new Exception("Contains test " + i + " failed"); + } + + // TryGetValue() test + int value; + bool rc = simap.TryGetValue("3", out value); + if (rc != true || value != (3 * 18)) + throw new Exception("TryGetValue test 1 failed"); + + rc = simap.TryGetValue("-1", out value); + if (rc != false) + throw new Exception("TryGetValue test 2 failed"); + + // Keys and Values test + { + IList keys = new List(simap.Keys); + IList values = new List(simap.Values); + Dictionary check = new Dictionary(); + if (keys.Count != collectionSize) + throw new Exception("Keys count test failed"); + + if (values.Count != collectionSize) + throw new Exception("Values count test failed"); + + for (int i = 0; i < keys.Count; i++) + { + if (simap[keys[i]] != values[i]) + throw new Exception("Keys and values test failed for index " + i); + check.Add(keys[i], values[i]); + } + + for (int i = 0; i < collectionSize; i++) + { + if (!check.ContainsKey(i.ToString())) + throw new Exception("Keys and Values ContainsKey test " + i + " failed"); + } + } + + // Add and Remove test + for (int i = 100; i < 103; i++) + { + simap.Add(i.ToString(), i * 18); + if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18)) + throw new Exception("Add test failed for index " + i); + + simap.Remove(i.ToString()); + if (simap.ContainsKey(i.ToString())) + throw new Exception("Remove test failed for index " + i); + } + + for (int i = 200; i < 203; i++) + { + simap.Add(new KeyValuePair(i.ToString(), i * 18)); + if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18)) + throw new Exception("Add explicit test failed for index " + i); + + simap.Remove(new KeyValuePair(i.ToString(), i * 18)); + if (simap.ContainsKey(i.ToString())) + throw new Exception("Remove explicit test failed for index " + i); + } + + // Duplicate key test + try + { + simap.Add("3", 0); + throw new Exception("Adding duplicate key test failed"); + } + catch (ArgumentException) + { + } + + // CopyTo() test + { + KeyValuePair[] outputarray = new KeyValuePair[collectionSize]; + simap.CopyTo(outputarray); + foreach (KeyValuePair val in outputarray) + { + if (simap[val.Key] != val.Value) + throw new Exception("CopyTo (1) test failed, index:" + val.Key); + } + } + { + KeyValuePair[] outputarray = new KeyValuePair[midCollection + collectionSize]; + simap.CopyTo(outputarray, midCollection); + for (int i = midCollection; i < midCollection + collectionSize; i++) + { + KeyValuePair val = outputarray[i]; + if (simap[val.Key] != val.Value) + throw new Exception("CopyTo (2) test failed, index:" + val.Key); + } + } + { + KeyValuePair[] outputarray = new KeyValuePair[collectionSize - 1]; + try + { + simap.CopyTo(outputarray); + throw new Exception("CopyTo (4) test failed"); + } + catch (ArgumentException) + { + } + } + + // Clear test + simap.Clear(); + if (simap.Count != 0) + throw new Exception("Clear test failed"); + + // Test wrapped methods + for (int i = 1; i <= 5; i++) + { + simap[i.ToString()] = i; + } + double avg = li_std_map.valueAverage(simap); + if (avg != 3.0) + throw new Exception("Wrapped method valueAverage test failed. Got " + avg); + + string keyStringified = li_std_map.stringifyKeys(simap); + if (keyStringified != " 1 2 3 4 5") + throw new Exception("Wrapped method stringifyKeys test failed. Got " + keyStringified); + + // Test a map with a new complex type (Struct) + { + IntStructMap ismap = new IntStructMap(); + for (int i = 0; i < 10; i++) + { + ismap.Add(i, new Struct(i * 10.1)); + } + + if (ismap.Count != 10) + throw new Exception("Count test on complex type map failed"); + + foreach (KeyValuePair p in ismap) + { + if ((p.Key * 10.1) != p.Value.num) + throw new Exception("Iteration test on complex type map failed for index " + p.Key); + } + } + + // Test a map of pointers + { + IntStructPtrMap ispmap = new IntStructPtrMap(); + for (int i = 0; i < 10; i++) + { + ispmap.Add(i, new Struct(i * 10.1)); + } + + if (ispmap.Count != 10) + throw new Exception("Count test on complex type pointer map failed"); + + foreach (KeyValuePair p in ispmap) + { + if ((p.Key * 10.1) != p.Value.num) + throw new Exception("Iteration test on complex type pointer map failed for index " + p.Key); + } + } + { + IntStructConstPtrMap iscpmap = new IntStructConstPtrMap(); + for (int i = 0; i < 10; i++) + { + iscpmap.Add(i, new Struct(i * 10.1)); + } + + if (iscpmap.Count != 10) + throw new Exception("Count test on complex type const pointer map failed"); + + foreach (KeyValuePair p in iscpmap) + { + if ((p.Key * 10.1) != p.Value.num) + throw new Exception("Iteration test on complex type const pointer map failed for index " + p.Key); + } + } + + // Test complex type as key (Struct) + { + StructIntMap limap = new StructIntMap(); + Struct s7 = new Struct(7); + Struct s8 = new Struct(8); + limap[s7] = 8; + if (limap[s7] != 8) + throw new Exception("Assignment test on complex key map failed"); + + if (!limap.ContainsKey(s7)) + throw new Exception("Key test (1) on complex key map failed"); + + if (limap.ContainsKey(s8)) + throw new Exception("Key test (2) on complex key map failed"); + } + + // All done + } +} + diff --git a/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java b/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java index f40c28e9e..9b480e7e0 100644 --- a/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java +++ b/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java @@ -1,701 +1,701 @@ -import li_boost_intrusive_ptr.*; - -public class li_boost_intrusive_ptr_runme { - static { - try { - System.loadLibrary("li_boost_intrusive_ptr"); - } 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); - } - } - - // Debugging flag - public final static boolean debug = false; - - public static void main(String argv[]) - { - if (debug) - System.out.println("Started"); - - li_boost_intrusive_ptr.setDebug_shared(debug); - - // Change loop count to run for a long time to monitor memory - final int loopCount = 5000; //5000; - for (int i=0; i - -// Uncomment macro below to turn on intrusive_ptr memory leak checking as described above -//#define INTRUSIVE_PTR_WRAPPER - -#ifdef INTRUSIVE_PTR_WRAPPER -# include "intrusive_ptr_wrapper.h" -# include "shared_ptr_wrapper.h" -#endif -%} - -%{ -#ifndef INTRUSIVE_PTR_WRAPPER -# define SwigBoost boost -#endif -%} - -%include "std_string.i" -#ifndef INTRUSIVE_PTR_WRAPPER -# define SWIG_INTRUSIVE_PTR_NAMESPACE SwigBoost -# define SWIG_SHARED_PTR_NAMESPACE SwigBoost -#endif - -#if defined(SWIGJAVA) || defined(SWIGCSHARP) -#define INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED -#endif - -#if defined(INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED) - -%include -%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 -#if defined(SWIGJAVA) -%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & ($*1_ltype tempnull) %{ - $1 = $input ? *($&1_ltype)&$input : &tempnull; -%} -%typemap (jni) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & "jlong" -%typemap (jtype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & "long" -%typemap (jstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & "Klass" -%typemap(javain) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & "Klass.getCPtr($javainput)" - -%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerived > & ($*1_ltype tempnull) %{ - $1 = $input ? *($&1_ltype)&$input : &tempnull; -%} -%typemap (jni) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerived > & "jlong" -%typemap (jtype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerived > & "long" -%typemap (jstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerived > & "KlassDerived" -%typemap(javain) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerived > & "KlassDerived.getCPtr($javainput)" - -%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & ($*1_ltype tempnull) %{ - $1 = $input ? *($&1_ltype)&$input : &tempnull; -%} -%typemap (jni) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & "jlong" -%typemap (jtype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & "long" -%typemap (jstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & "KlassDerivedDerived" -%typemap(javain) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & "KlassDerivedDerived.getCPtr($javainput)" - -#elif defined(SWIGCSHARP) -// TODO! -#endif - -#endif - -// TODO: -// const intrusive_ptr -// std::vector -// Add in generic %extend for the Upcast function for derived classes -// Remove proxy upcast method - implement %feature("shadow") ??? which replaces the proxy method - -%exception { - if (debug_shared) { - cout << "++++++" << endl << flush; - cout << "calling $name" << endl << flush; - } - $action - if (debug_shared) { - cout << "------" << endl << flush; - } -} - -%ignore IgnoredRefCountingBase; -%ignore *::operator=; -%ignore intrusive_ptr_add_ref; -%ignore intrusive_ptr_release; -%newobject pointerownertest(); -%newobject smartpointerpointerownertest(); - -%inline %{ -#include -using namespace std; - -static bool debug_shared = false; - -namespace Space { - -struct Klass { - Klass() : value("EMPTY"), count(0) { if (debug_shared) cout << "Klass() [" << value << "]" << endl << flush; increment(); } - - Klass(const std::string &val) : value(val), count(0) { if (debug_shared) cout << "Klass(string) [" << value << "]" << endl << flush; increment(); } - - virtual ~Klass() { if (debug_shared) cout << "~Klass() [" << value << "]" << endl << flush; decrement(); } - virtual std::string getValue() const { return value; } - void append(const std::string &s) { value += s; } - Klass(const Klass &other) : value(other.value), count(0) { if (debug_shared) cout << "Klass(const Klass&) [" << value << "]" << endl << flush; increment(); } - - Klass &operator=(const Klass &other) { value = other.value; return *this; } - - void addref(void) const { ++count; } - void release(void) const { if (--count == 0) delete this; } - int use_count(void) const { return count; } - static long getTotal_count() { return total_count; } - -private: - static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx Klass::increment tot: " << total_count << endl;} - static void decrement() { --total_count; if (debug_shared) cout << " --xxxxx Klass::decrement tot: " << total_count << endl;} - static boost::detail::atomic_count total_count; - std::string value; - int array[1024]; - mutable boost::detail::atomic_count count; -}; - -struct KlassWithoutRefCount { - KlassWithoutRefCount() : value("EMPTY") { if (debug_shared) cout << "KlassWithoutRefCount() [" << value << "]" << endl << flush; increment(); } - - KlassWithoutRefCount(const std::string &val) : value(val) { if (debug_shared) cout << "KlassWithoutRefCount(string) [" << value << "]" << endl << flush; increment(); } - - virtual ~KlassWithoutRefCount() { if (debug_shared) cout << "~KlassWithoutRefCount() [" << value << "]" << endl << flush; decrement(); } - virtual std::string getValue() const { return value; } - void append(const std::string &s) { value += s; } - KlassWithoutRefCount(const KlassWithoutRefCount &other) : value(other.value) { if (debug_shared) cout << "KlassWithoutRefCount(const KlassWithoutRefCount&) [" << value << "]" << endl << flush; increment(); } - std::string getSpecialValueFromUnwrappableClass() { return "this class cannot be wrapped by intrusive_ptrs but we can still use it"; } - KlassWithoutRefCount &operator=(const KlassWithoutRefCount &other) { value = other.value; return *this; } - static long getTotal_count() { return total_count; } - -private: - static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx KlassWithoutRefCount::increment tot: " << total_count << endl;} - static void decrement() { --total_count; if (debug_shared) cout << " --xxxxx KlassWithoutRefCount::decrement tot: " << total_count << endl;} - static boost::detail::atomic_count total_count; - std::string value; - int array[1024]; -}; - -struct IgnoredRefCountingBase { - IgnoredRefCountingBase() : count(0) { if (debug_shared) cout << "IgnoredRefCountingBase()" << endl << flush; increment(); } - - IgnoredRefCountingBase(const IgnoredRefCountingBase &other) : count(0) { if (debug_shared) cout << "IgnoredRefCountingBase(const IgnoredRefCountingBase&)" << endl << flush; increment(); } - - IgnoredRefCountingBase &operator=(const IgnoredRefCountingBase& other) { - return *this; - } - - virtual ~IgnoredRefCountingBase() { if (debug_shared) cout << "~IgnoredRefCountingBase()" << endl << flush; decrement(); } - - void addref(void) const { ++count; } - void release(void) const { if (--count == 0) delete this; } - int use_count(void) const { return count; } - static long getTotal_count() { return total_count; } - - private: - static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx IgnoredRefCountingBase::increment tot: " << total_count << endl;} - static void decrement() { --total_count; if (debug_shared) cout << " --xxxxx IgnoredRefCountingBase::decrement tot: " << total_count << endl;} - static boost::detail::atomic_count total_count; - double d; - double e; - mutable boost::detail::atomic_count count; -}; - -long getTotal_IgnoredRefCountingBase_count() { - return IgnoredRefCountingBase::getTotal_count(); -} - -// For most compilers, this use of multiple inheritance results in different derived and base class -// pointer values ... for some more challenging tests :) -struct KlassDerived : IgnoredRefCountingBase, KlassWithoutRefCount { - KlassDerived() : KlassWithoutRefCount() { if (debug_shared) cout << "KlassDerived()" << endl << flush; increment(); } - KlassDerived(const std::string &val) : KlassWithoutRefCount(val) { if (debug_shared) cout << "KlassDerived(string) [" << val << "]" << endl << flush; increment(); } - KlassDerived(const KlassDerived &other) : KlassWithoutRefCount(other) { if (debug_shared) cout << "KlassDerived(const KlassDerived&))" << endl << flush; increment(); } - virtual ~KlassDerived() { if (debug_shared) cout << "~KlassDerived()" << endl << flush; decrement(); } - virtual std::string getValue() const { return KlassWithoutRefCount::getValue() + "-Derived"; } - int use_count(void) const { return IgnoredRefCountingBase::use_count(); } - static long getTotal_count() { return total_count; } - - private: - static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx KlassDerived::increment tot: " << total_count << endl;} - static void decrement() { --total_count; if (debug_shared) cout << " --xxxxx KlassDerived::decrement tot: " << total_count << endl;} - static boost::detail::atomic_count total_count; -}; -struct KlassDerivedDerived : KlassDerived { - KlassDerivedDerived() : KlassDerived() { if (debug_shared) cout << "KlassDerivedDerived()" << endl << flush; increment(); } - KlassDerivedDerived(const std::string &val) : KlassDerived(val) { if (debug_shared) cout << "KlassDerivedDerived(string) [" << val << "]" << endl << flush; increment(); } - KlassDerivedDerived(const KlassDerived &other) : KlassDerived(other) { if (debug_shared) cout << "KlassDerivedDerived(const KlassDerivedDerived&))" << endl << flush; increment(); } - virtual ~KlassDerivedDerived() { if (debug_shared) cout << "~KlassDerivedDerived()" << endl << flush; decrement(); } - virtual std::string getValue() const { return KlassWithoutRefCount::getValue() + "-DerivedDerived"; } - static long getTotal_count() { return total_count; } - - private: - static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx KlassDerivedDerived::increment tot: " << total_count << endl;} - static void decrement() { --total_count; if (debug_shared) cout << " --xxxxx KlassDerivedDerived::decrement tot: " << total_count << endl;} - static boost::detail::atomic_count total_count; -}; -KlassDerived* derivedpointertest(KlassDerived* kd) { - if (kd) - kd->append(" derivedpointertest"); - return kd; -} -KlassDerived derivedvaluetest(KlassDerived kd) { - kd.append(" derivedvaluetest"); - return kd; -} -KlassDerived& derivedreftest(KlassDerived& kd) { - kd.append(" derivedreftest"); - return kd; -} -SwigBoost::intrusive_ptr derivedsmartptrtest(SwigBoost::intrusive_ptr kd) { - if (kd) - kd->append(" derivedsmartptrtest"); - return kd; -} -SwigBoost::intrusive_ptr* derivedsmartptrpointertest(SwigBoost::intrusive_ptr* kd) { - if (kd && *kd) - (*kd)->append(" derivedsmartptrpointertest"); - return kd; -} -SwigBoost::intrusive_ptr* derivedsmartptrreftest(SwigBoost::intrusive_ptr* kd) { - if (kd && *kd) - (*kd)->append(" derivedsmartptrreftest"); - return kd; -} -SwigBoost::intrusive_ptr*& derivedsmartptrpointerreftest(SwigBoost::intrusive_ptr*& kd) { - if (kd && *kd) - (*kd)->append(" derivedsmartptrpointerreftest"); - return kd; -} - -SwigBoost::intrusive_ptr factorycreate() { - return SwigBoost::intrusive_ptr(new Klass("factorycreate")); -} -// smart pointer -SwigBoost::intrusive_ptr smartpointertest(SwigBoost::intrusive_ptr k) { - if (k) - k->append(" smartpointertest"); - return SwigBoost::intrusive_ptr(k); -} -SwigBoost::intrusive_ptr* smartpointerpointertest(SwigBoost::intrusive_ptr* k) { - if (k && *k) - (*k)->append(" smartpointerpointertest"); - return k; -} -SwigBoost::intrusive_ptr& smartpointerreftest(SwigBoost::intrusive_ptr& k) { - if (k) - k->append(" smartpointerreftest"); - return k; -} -SwigBoost::intrusive_ptr*& smartpointerpointerreftest(SwigBoost::intrusive_ptr*& k) { - if (k && *k) - (*k)->append(" smartpointerpointerreftest"); - return k; -} -// const -SwigBoost::intrusive_ptr constsmartpointertest(SwigBoost::intrusive_ptr k) { - return SwigBoost::intrusive_ptr(k); -} -SwigBoost::intrusive_ptr* constsmartpointerpointertest(SwigBoost::intrusive_ptr* k) { - return k; -} -SwigBoost::intrusive_ptr& constsmartpointerreftest(SwigBoost::intrusive_ptr& k) { - return k; -} -// plain pointer -Klass valuetest(Klass k) { - k.append(" valuetest"); - return k; -} -Klass *pointertest(Klass *k) { - if (k) - k->append(" pointertest"); - return k; -} -Klass& reftest(Klass& k) { - k.append(" reftest"); - return k; -} -Klass *const& pointerreftest(Klass *const& k) { - k->append(" pointerreftest"); - return k; -} -// null -std::string nullsmartpointerpointertest(SwigBoost::intrusive_ptr* k) { - if (k && *k) - return "not null"; - else if (!k) - return "null smartpointer pointer"; - else if (!*k) - return "null pointer"; - else - return "also not null"; -} -// $owner -Klass *pointerownertest() { - return new Klass("pointerownertest"); -} -SwigBoost::intrusive_ptr* smartpointerpointerownertest() { - return new SwigBoost::intrusive_ptr(new Klass("smartpointerpointerownertest")); -} - -const SwigBoost::intrusive_ptr& ref_1() { - static SwigBoost::intrusive_ptr sptr; - return sptr; -} - -// overloading tests -std::string overload_rawbyval(int i) { return "int"; } -std::string overload_rawbyval(Klass k) { return "rawbyval"; } - -std::string overload_rawbyref(int i) { return "int"; } -std::string overload_rawbyref(Klass &k) { return "rawbyref"; } - -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 *const&k) { return "rawbyptrref"; } - - - -std::string overload_smartbyval(int i) { return "int"; } -std::string overload_smartbyval(SwigBoost::intrusive_ptr k) { return "smartbyval"; } - -std::string overload_smartbyref(int i) { return "int"; } -std::string overload_smartbyref(SwigBoost::intrusive_ptr &k) { return "smartbyref"; } - -std::string overload_smartbyptr(int i) { return "int"; } -std::string overload_smartbyptr(SwigBoost::intrusive_ptr *k) { return "smartbyptr"; } - -std::string overload_smartbyptrref(int i) { return "int"; } -std::string overload_smartbyptrref(SwigBoost::intrusive_ptr *&k) { return "smartbyptrref"; } - -} // namespace Space - -%} -%{ - boost::detail::atomic_count Space::Klass::total_count(0); - boost::detail::atomic_count Space::KlassWithoutRefCount::total_count(0); - boost::detail::atomic_count Space::IgnoredRefCountingBase::total_count(0); - boost::detail::atomic_count Space::KlassDerived::total_count(0); - boost::detail::atomic_count Space::KlassDerivedDerived::total_count(0); -%} - -// Member variables - -%inline %{ -struct MemberVariables { - MemberVariables() : SmartMemberPointer(new SwigBoost::intrusive_ptr()), SmartMemberReference(*(new SwigBoost::intrusive_ptr())), MemberPointer(0), MemberReference(MemberValue) {} - virtual ~MemberVariables() { - delete SmartMemberPointer; - delete &SmartMemberReference; - } - SwigBoost::intrusive_ptr SmartMemberValue; - SwigBoost::intrusive_ptr * SmartMemberPointer; - SwigBoost::intrusive_ptr & SmartMemberReference; - Space::Klass MemberValue; - Space::Klass * MemberPointer; - Space::Klass & MemberReference; -}; - -// Global variables -SwigBoost::intrusive_ptr GlobalSmartValue; -Space::Klass GlobalValue; -Space::Klass * GlobalPointer = 0; -Space::Klass & GlobalReference = GlobalValue; - -%} - -#if defined(INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED) - -// Note: %template after the intrusive_ptr typemaps -%intrusive_ptr(Base) -%intrusive_ptr(Pair) - -#endif - -// Templates -%inline %{ -template struct Base { - Space::Klass klassBase; - T1 baseVal1; - T2 baseVal2; - Base(T1 t1, T2 t2) : baseVal1(t1*2), baseVal2(t2*2) {} - virtual std::string getValue() const { return "Base<>"; }; - mutable int count; - void addref(void) const { count++; } - void release(void) const { if (--count == 0) delete this; } - int use_count(void) const { return count; } -}; -%} - -%template(BaseIntDouble) Base; - -%inline %{ -template struct Pair : Base { - Space::Klass klassPair; - T1 val1; - T2 val2; - Pair(T1 t1, T2 t2) : Base(t1, t2), val1(t1), val2(t2) {} - virtual std::string getValue() const { return "Pair<>"; }; -}; - -Pair pair_id2(Pair p) { return p; } -SwigBoost::intrusive_ptr< Pair > pair_id1(SwigBoost::intrusive_ptr< Pair > p) { return p; } - -template void intrusive_ptr_add_ref(const T* r) { r->addref(); } - -template void intrusive_ptr_release(const T* r) { r->release(); } - -long use_count(const SwigBoost::shared_ptr& sptr) { - return sptr.use_count(); -} -long use_count(const SwigBoost::shared_ptr& sptr) { - return sptr.use_count(); -} -long use_count(const SwigBoost::shared_ptr& sptr) { - return sptr.use_count(); -} -%} - -%template(PairIntDouble) Pair; - -// For counting the instances of intrusive_ptr (all of which are created on the heap) -// intrusive_ptr_wrapper_count() gives overall count -%inline %{ -namespace SwigBoost { - const int NOT_COUNTING = -123456; - int intrusive_ptr_wrapper_count() { - #ifdef INTRUSIVE_PTR_WRAPPER - return SwigBoost::IntrusivePtrWrapper::getTotalCount(); - #else - return NOT_COUNTING; - #endif - } - #ifdef INTRUSIVE_PTR_WRAPPER - template<> std::string show_message(boost::intrusive_ptr*t) { - if (!t) - return "null intrusive_ptr!!!"; - if (*t) - return "Klass: " + (*t)->getValue(); - else - return "Klass: NULL"; - } - template<> std::string show_message(boost::intrusive_ptr*t) { - if (!t) - return "null intrusive_ptr!!!"; - if (*t) - return "Klass: " + (*t)->getValue(); - else - return "Klass: NULL"; - } - template<> std::string show_message(boost::intrusive_ptr*t) { - if (!t) - return "null intrusive_ptr!!!"; - if (*t) - return "KlassDerived: " + (*t)->getValue(); - else - return "KlassDerived: NULL"; - } - template<> std::string show_message(boost::intrusive_ptr*t) { - if (!t) - return "null intrusive_ptr!!!"; - if (*t) - return "KlassDerived: " + (*t)->getValue(); - else - return "KlassDerived: NULL"; - } - #endif -} -%} - +// This tests intrusive_ptr is working okay. It also checks that there are no memory leaks in the +// class that intrusive_ptr is pointing via a counting mechanism in the constructors and destructor of Klass. +// In order to test that there are no leaks of the intrusive_ptr class itself (as it is created on the heap) +// the runtime tests can be run for a long time to monitor memory leaks using memory monitor tools +// like 'top'. There is a wrapper for intrusive_ptr in intrusive_ptr_wrapper.h which enables one to +// count the instances of intrusive_ptr. Uncomment the INTRUSIVE_PTR_WRAPPER macro to turn this on. +// +// Also note the debug_shared flag which can be set from the target language. + +%module li_boost_intrusive_ptr + +%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); +%warnfilter(SWIGWARN_LANG_SMARTPTR_MISSING) KlassDerived; +%warnfilter(SWIGWARN_LANG_SMARTPTR_MISSING) KlassDerivedDerived; + +%inline %{ +#include "boost/shared_ptr.hpp" +#include "boost/intrusive_ptr.hpp" +#include + +// Uncomment macro below to turn on intrusive_ptr memory leak checking as described above +//#define INTRUSIVE_PTR_WRAPPER + +#ifdef INTRUSIVE_PTR_WRAPPER +# include "intrusive_ptr_wrapper.h" +# include "shared_ptr_wrapper.h" +#endif +%} + +%{ +#ifndef INTRUSIVE_PTR_WRAPPER +# define SwigBoost boost +#endif +%} + +%include "std_string.i" +#ifndef INTRUSIVE_PTR_WRAPPER +# define SWIG_INTRUSIVE_PTR_NAMESPACE SwigBoost +# define SWIG_SHARED_PTR_NAMESPACE SwigBoost +#endif + +#if defined(SWIGJAVA) || defined(SWIGCSHARP) +#define INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED +#endif + +#if defined(INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED) + +%include +%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 +#if defined(SWIGJAVA) +%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & ($*1_ltype tempnull) %{ + $1 = $input ? *($&1_ltype)&$input : &tempnull; +%} +%typemap (jni) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & "jlong" +%typemap (jtype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & "long" +%typemap (jstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & "Klass" +%typemap(javain) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & "Klass.getCPtr($javainput)" + +%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerived > & ($*1_ltype tempnull) %{ + $1 = $input ? *($&1_ltype)&$input : &tempnull; +%} +%typemap (jni) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerived > & "jlong" +%typemap (jtype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerived > & "long" +%typemap (jstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerived > & "KlassDerived" +%typemap(javain) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerived > & "KlassDerived.getCPtr($javainput)" + +%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & ($*1_ltype tempnull) %{ + $1 = $input ? *($&1_ltype)&$input : &tempnull; +%} +%typemap (jni) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & "jlong" +%typemap (jtype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & "long" +%typemap (jstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & "KlassDerivedDerived" +%typemap(javain) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & "KlassDerivedDerived.getCPtr($javainput)" + +#elif defined(SWIGCSHARP) +// TODO! +#endif + +#endif + +// TODO: +// const intrusive_ptr +// std::vector +// Add in generic %extend for the Upcast function for derived classes +// Remove proxy upcast method - implement %feature("shadow") ??? which replaces the proxy method + +%exception { + if (debug_shared) { + cout << "++++++" << endl << flush; + cout << "calling $name" << endl << flush; + } + $action + if (debug_shared) { + cout << "------" << endl << flush; + } +} + +%ignore IgnoredRefCountingBase; +%ignore *::operator=; +%ignore intrusive_ptr_add_ref; +%ignore intrusive_ptr_release; +%newobject pointerownertest(); +%newobject smartpointerpointerownertest(); + +%inline %{ +#include +using namespace std; + +static bool debug_shared = false; + +namespace Space { + +struct Klass { + Klass() : value("EMPTY"), count(0) { if (debug_shared) cout << "Klass() [" << value << "]" << endl << flush; increment(); } + + Klass(const std::string &val) : value(val), count(0) { if (debug_shared) cout << "Klass(string) [" << value << "]" << endl << flush; increment(); } + + virtual ~Klass() { if (debug_shared) cout << "~Klass() [" << value << "]" << endl << flush; decrement(); } + virtual std::string getValue() const { return value; } + void append(const std::string &s) { value += s; } + Klass(const Klass &other) : value(other.value), count(0) { if (debug_shared) cout << "Klass(const Klass&) [" << value << "]" << endl << flush; increment(); } + + Klass &operator=(const Klass &other) { value = other.value; return *this; } + + void addref(void) const { ++count; } + void release(void) const { if (--count == 0) delete this; } + int use_count(void) const { return count; } + static long getTotal_count() { return total_count; } + +private: + static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx Klass::increment tot: " << total_count << endl;} + static void decrement() { --total_count; if (debug_shared) cout << " --xxxxx Klass::decrement tot: " << total_count << endl;} + static boost::detail::atomic_count total_count; + std::string value; + int array[1024]; + mutable boost::detail::atomic_count count; +}; + +struct KlassWithoutRefCount { + KlassWithoutRefCount() : value("EMPTY") { if (debug_shared) cout << "KlassWithoutRefCount() [" << value << "]" << endl << flush; increment(); } + + KlassWithoutRefCount(const std::string &val) : value(val) { if (debug_shared) cout << "KlassWithoutRefCount(string) [" << value << "]" << endl << flush; increment(); } + + virtual ~KlassWithoutRefCount() { if (debug_shared) cout << "~KlassWithoutRefCount() [" << value << "]" << endl << flush; decrement(); } + virtual std::string getValue() const { return value; } + void append(const std::string &s) { value += s; } + KlassWithoutRefCount(const KlassWithoutRefCount &other) : value(other.value) { if (debug_shared) cout << "KlassWithoutRefCount(const KlassWithoutRefCount&) [" << value << "]" << endl << flush; increment(); } + std::string getSpecialValueFromUnwrappableClass() { return "this class cannot be wrapped by intrusive_ptrs but we can still use it"; } + KlassWithoutRefCount &operator=(const KlassWithoutRefCount &other) { value = other.value; return *this; } + static long getTotal_count() { return total_count; } + +private: + static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx KlassWithoutRefCount::increment tot: " << total_count << endl;} + static void decrement() { --total_count; if (debug_shared) cout << " --xxxxx KlassWithoutRefCount::decrement tot: " << total_count << endl;} + static boost::detail::atomic_count total_count; + std::string value; + int array[1024]; +}; + +struct IgnoredRefCountingBase { + IgnoredRefCountingBase() : count(0) { if (debug_shared) cout << "IgnoredRefCountingBase()" << endl << flush; increment(); } + + IgnoredRefCountingBase(const IgnoredRefCountingBase &other) : count(0) { if (debug_shared) cout << "IgnoredRefCountingBase(const IgnoredRefCountingBase&)" << endl << flush; increment(); } + + IgnoredRefCountingBase &operator=(const IgnoredRefCountingBase& other) { + return *this; + } + + virtual ~IgnoredRefCountingBase() { if (debug_shared) cout << "~IgnoredRefCountingBase()" << endl << flush; decrement(); } + + void addref(void) const { ++count; } + void release(void) const { if (--count == 0) delete this; } + int use_count(void) const { return count; } + static long getTotal_count() { return total_count; } + + private: + static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx IgnoredRefCountingBase::increment tot: " << total_count << endl;} + static void decrement() { --total_count; if (debug_shared) cout << " --xxxxx IgnoredRefCountingBase::decrement tot: " << total_count << endl;} + static boost::detail::atomic_count total_count; + double d; + double e; + mutable boost::detail::atomic_count count; +}; + +long getTotal_IgnoredRefCountingBase_count() { + return IgnoredRefCountingBase::getTotal_count(); +} + +// For most compilers, this use of multiple inheritance results in different derived and base class +// pointer values ... for some more challenging tests :) +struct KlassDerived : IgnoredRefCountingBase, KlassWithoutRefCount { + KlassDerived() : KlassWithoutRefCount() { if (debug_shared) cout << "KlassDerived()" << endl << flush; increment(); } + KlassDerived(const std::string &val) : KlassWithoutRefCount(val) { if (debug_shared) cout << "KlassDerived(string) [" << val << "]" << endl << flush; increment(); } + KlassDerived(const KlassDerived &other) : KlassWithoutRefCount(other) { if (debug_shared) cout << "KlassDerived(const KlassDerived&))" << endl << flush; increment(); } + virtual ~KlassDerived() { if (debug_shared) cout << "~KlassDerived()" << endl << flush; decrement(); } + virtual std::string getValue() const { return KlassWithoutRefCount::getValue() + "-Derived"; } + int use_count(void) const { return IgnoredRefCountingBase::use_count(); } + static long getTotal_count() { return total_count; } + + private: + static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx KlassDerived::increment tot: " << total_count << endl;} + static void decrement() { --total_count; if (debug_shared) cout << " --xxxxx KlassDerived::decrement tot: " << total_count << endl;} + static boost::detail::atomic_count total_count; +}; +struct KlassDerivedDerived : KlassDerived { + KlassDerivedDerived() : KlassDerived() { if (debug_shared) cout << "KlassDerivedDerived()" << endl << flush; increment(); } + KlassDerivedDerived(const std::string &val) : KlassDerived(val) { if (debug_shared) cout << "KlassDerivedDerived(string) [" << val << "]" << endl << flush; increment(); } + KlassDerivedDerived(const KlassDerived &other) : KlassDerived(other) { if (debug_shared) cout << "KlassDerivedDerived(const KlassDerivedDerived&))" << endl << flush; increment(); } + virtual ~KlassDerivedDerived() { if (debug_shared) cout << "~KlassDerivedDerived()" << endl << flush; decrement(); } + virtual std::string getValue() const { return KlassWithoutRefCount::getValue() + "-DerivedDerived"; } + static long getTotal_count() { return total_count; } + + private: + static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx KlassDerivedDerived::increment tot: " << total_count << endl;} + static void decrement() { --total_count; if (debug_shared) cout << " --xxxxx KlassDerivedDerived::decrement tot: " << total_count << endl;} + static boost::detail::atomic_count total_count; +}; +KlassDerived* derivedpointertest(KlassDerived* kd) { + if (kd) + kd->append(" derivedpointertest"); + return kd; +} +KlassDerived derivedvaluetest(KlassDerived kd) { + kd.append(" derivedvaluetest"); + return kd; +} +KlassDerived& derivedreftest(KlassDerived& kd) { + kd.append(" derivedreftest"); + return kd; +} +SwigBoost::intrusive_ptr derivedsmartptrtest(SwigBoost::intrusive_ptr kd) { + if (kd) + kd->append(" derivedsmartptrtest"); + return kd; +} +SwigBoost::intrusive_ptr* derivedsmartptrpointertest(SwigBoost::intrusive_ptr* kd) { + if (kd && *kd) + (*kd)->append(" derivedsmartptrpointertest"); + return kd; +} +SwigBoost::intrusive_ptr* derivedsmartptrreftest(SwigBoost::intrusive_ptr* kd) { + if (kd && *kd) + (*kd)->append(" derivedsmartptrreftest"); + return kd; +} +SwigBoost::intrusive_ptr*& derivedsmartptrpointerreftest(SwigBoost::intrusive_ptr*& kd) { + if (kd && *kd) + (*kd)->append(" derivedsmartptrpointerreftest"); + return kd; +} + +SwigBoost::intrusive_ptr factorycreate() { + return SwigBoost::intrusive_ptr(new Klass("factorycreate")); +} +// smart pointer +SwigBoost::intrusive_ptr smartpointertest(SwigBoost::intrusive_ptr k) { + if (k) + k->append(" smartpointertest"); + return SwigBoost::intrusive_ptr(k); +} +SwigBoost::intrusive_ptr* smartpointerpointertest(SwigBoost::intrusive_ptr* k) { + if (k && *k) + (*k)->append(" smartpointerpointertest"); + return k; +} +SwigBoost::intrusive_ptr& smartpointerreftest(SwigBoost::intrusive_ptr& k) { + if (k) + k->append(" smartpointerreftest"); + return k; +} +SwigBoost::intrusive_ptr*& smartpointerpointerreftest(SwigBoost::intrusive_ptr*& k) { + if (k && *k) + (*k)->append(" smartpointerpointerreftest"); + return k; +} +// const +SwigBoost::intrusive_ptr constsmartpointertest(SwigBoost::intrusive_ptr k) { + return SwigBoost::intrusive_ptr(k); +} +SwigBoost::intrusive_ptr* constsmartpointerpointertest(SwigBoost::intrusive_ptr* k) { + return k; +} +SwigBoost::intrusive_ptr& constsmartpointerreftest(SwigBoost::intrusive_ptr& k) { + return k; +} +// plain pointer +Klass valuetest(Klass k) { + k.append(" valuetest"); + return k; +} +Klass *pointertest(Klass *k) { + if (k) + k->append(" pointertest"); + return k; +} +Klass& reftest(Klass& k) { + k.append(" reftest"); + return k; +} +Klass *const& pointerreftest(Klass *const& k) { + k->append(" pointerreftest"); + return k; +} +// null +std::string nullsmartpointerpointertest(SwigBoost::intrusive_ptr* k) { + if (k && *k) + return "not null"; + else if (!k) + return "null smartpointer pointer"; + else if (!*k) + return "null pointer"; + else + return "also not null"; +} +// $owner +Klass *pointerownertest() { + return new Klass("pointerownertest"); +} +SwigBoost::intrusive_ptr* smartpointerpointerownertest() { + return new SwigBoost::intrusive_ptr(new Klass("smartpointerpointerownertest")); +} + +const SwigBoost::intrusive_ptr& ref_1() { + static SwigBoost::intrusive_ptr sptr; + return sptr; +} + +// overloading tests +std::string overload_rawbyval(int i) { return "int"; } +std::string overload_rawbyval(Klass k) { return "rawbyval"; } + +std::string overload_rawbyref(int i) { return "int"; } +std::string overload_rawbyref(Klass &k) { return "rawbyref"; } + +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 *const&k) { return "rawbyptrref"; } + + + +std::string overload_smartbyval(int i) { return "int"; } +std::string overload_smartbyval(SwigBoost::intrusive_ptr k) { return "smartbyval"; } + +std::string overload_smartbyref(int i) { return "int"; } +std::string overload_smartbyref(SwigBoost::intrusive_ptr &k) { return "smartbyref"; } + +std::string overload_smartbyptr(int i) { return "int"; } +std::string overload_smartbyptr(SwigBoost::intrusive_ptr *k) { return "smartbyptr"; } + +std::string overload_smartbyptrref(int i) { return "int"; } +std::string overload_smartbyptrref(SwigBoost::intrusive_ptr *&k) { return "smartbyptrref"; } + +} // namespace Space + +%} +%{ + boost::detail::atomic_count Space::Klass::total_count(0); + boost::detail::atomic_count Space::KlassWithoutRefCount::total_count(0); + boost::detail::atomic_count Space::IgnoredRefCountingBase::total_count(0); + boost::detail::atomic_count Space::KlassDerived::total_count(0); + boost::detail::atomic_count Space::KlassDerivedDerived::total_count(0); +%} + +// Member variables + +%inline %{ +struct MemberVariables { + MemberVariables() : SmartMemberPointer(new SwigBoost::intrusive_ptr()), SmartMemberReference(*(new SwigBoost::intrusive_ptr())), MemberPointer(0), MemberReference(MemberValue) {} + virtual ~MemberVariables() { + delete SmartMemberPointer; + delete &SmartMemberReference; + } + SwigBoost::intrusive_ptr SmartMemberValue; + SwigBoost::intrusive_ptr * SmartMemberPointer; + SwigBoost::intrusive_ptr & SmartMemberReference; + Space::Klass MemberValue; + Space::Klass * MemberPointer; + Space::Klass & MemberReference; +}; + +// Global variables +SwigBoost::intrusive_ptr GlobalSmartValue; +Space::Klass GlobalValue; +Space::Klass * GlobalPointer = 0; +Space::Klass & GlobalReference = GlobalValue; + +%} + +#if defined(INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED) + +// Note: %template after the intrusive_ptr typemaps +%intrusive_ptr(Base) +%intrusive_ptr(Pair) + +#endif + +// Templates +%inline %{ +template struct Base { + Space::Klass klassBase; + T1 baseVal1; + T2 baseVal2; + Base(T1 t1, T2 t2) : baseVal1(t1*2), baseVal2(t2*2) {} + virtual std::string getValue() const { return "Base<>"; }; + mutable int count; + void addref(void) const { count++; } + void release(void) const { if (--count == 0) delete this; } + int use_count(void) const { return count; } +}; +%} + +%template(BaseIntDouble) Base; + +%inline %{ +template struct Pair : Base { + Space::Klass klassPair; + T1 val1; + T2 val2; + Pair(T1 t1, T2 t2) : Base(t1, t2), val1(t1), val2(t2) {} + virtual std::string getValue() const { return "Pair<>"; }; +}; + +Pair pair_id2(Pair p) { return p; } +SwigBoost::intrusive_ptr< Pair > pair_id1(SwigBoost::intrusive_ptr< Pair > p) { return p; } + +template void intrusive_ptr_add_ref(const T* r) { r->addref(); } + +template void intrusive_ptr_release(const T* r) { r->release(); } + +long use_count(const SwigBoost::shared_ptr& sptr) { + return sptr.use_count(); +} +long use_count(const SwigBoost::shared_ptr& sptr) { + return sptr.use_count(); +} +long use_count(const SwigBoost::shared_ptr& sptr) { + return sptr.use_count(); +} +%} + +%template(PairIntDouble) Pair; + +// For counting the instances of intrusive_ptr (all of which are created on the heap) +// intrusive_ptr_wrapper_count() gives overall count +%inline %{ +namespace SwigBoost { + const int NOT_COUNTING = -123456; + int intrusive_ptr_wrapper_count() { + #ifdef INTRUSIVE_PTR_WRAPPER + return SwigBoost::IntrusivePtrWrapper::getTotalCount(); + #else + return NOT_COUNTING; + #endif + } + #ifdef INTRUSIVE_PTR_WRAPPER + template<> std::string show_message(boost::intrusive_ptr*t) { + if (!t) + return "null intrusive_ptr!!!"; + if (*t) + return "Klass: " + (*t)->getValue(); + else + return "Klass: NULL"; + } + template<> std::string show_message(boost::intrusive_ptr*t) { + if (!t) + return "null intrusive_ptr!!!"; + if (*t) + return "Klass: " + (*t)->getValue(); + else + return "Klass: NULL"; + } + template<> std::string show_message(boost::intrusive_ptr*t) { + if (!t) + return "null intrusive_ptr!!!"; + if (*t) + return "KlassDerived: " + (*t)->getValue(); + else + return "KlassDerived: NULL"; + } + template<> std::string show_message(boost::intrusive_ptr*t) { + if (!t) + return "null intrusive_ptr!!!"; + if (*t) + return "KlassDerived: " + (*t)->getValue(); + else + return "KlassDerived: NULL"; + } + #endif +} +%} + diff --git a/Examples/test-suite/lua/li_typemaps_runme.lua b/Examples/test-suite/lua/li_typemaps_runme.lua index fd7764cf3..7456d8245 100644 --- a/Examples/test-suite/lua/li_typemaps_runme.lua +++ b/Examples/test-suite/lua/li_typemaps_runme.lua @@ -1,42 +1,42 @@ -require("import") -- the import fn -import("li_typemaps") -- import code - --- catch "undefined" global variables -local env = _ENV -- Lua 5.2 -if not env then env = getfenv () end -- Lua 5.1 -setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) - --- Check double INPUT typemaps -assert(li_typemaps.in_double(22.22) == 22.22) -assert(li_typemaps.inr_double(22.22) == 22.22) - --- Check double OUTPUT typemaps -assert(li_typemaps.out_double(22.22) == 22.22) -assert(li_typemaps.outr_double(22.22) == 22.22) - --- Check double INOUT typemaps -assert(li_typemaps.inout_double(22.22) == 22.22) -assert(li_typemaps.inoutr_double(22.22) == 22.22) - --- check long long -assert(li_typemaps.in_ulonglong(20)==20) -assert(li_typemaps.inr_ulonglong(20)==20) -assert(li_typemaps.out_ulonglong(20)==20) -assert(li_typemaps.outr_ulonglong(20)==20) -assert(li_typemaps.inout_ulonglong(20)==20) -assert(li_typemaps.inoutr_ulonglong(20)==20) - --- check bools -assert(li_typemaps.in_bool(true)==true) -assert(li_typemaps.inr_bool(false)==false) -assert(li_typemaps.out_bool(true)==true) -assert(li_typemaps.outr_bool(false)==false) -assert(li_typemaps.inout_bool(true)==true) -assert(li_typemaps.inoutr_bool(false)==false) - --- the others -a,b=li_typemaps.inoutr_int2(1,2) -assert(a==1 and b==2) - -f,i=li_typemaps.out_foo(10) -assert(f.a==10 and i==20) +require("import") -- the import fn +import("li_typemaps") -- import code + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +-- Check double INPUT typemaps +assert(li_typemaps.in_double(22.22) == 22.22) +assert(li_typemaps.inr_double(22.22) == 22.22) + +-- Check double OUTPUT typemaps +assert(li_typemaps.out_double(22.22) == 22.22) +assert(li_typemaps.outr_double(22.22) == 22.22) + +-- Check double INOUT typemaps +assert(li_typemaps.inout_double(22.22) == 22.22) +assert(li_typemaps.inoutr_double(22.22) == 22.22) + +-- check long long +assert(li_typemaps.in_ulonglong(20)==20) +assert(li_typemaps.inr_ulonglong(20)==20) +assert(li_typemaps.out_ulonglong(20)==20) +assert(li_typemaps.outr_ulonglong(20)==20) +assert(li_typemaps.inout_ulonglong(20)==20) +assert(li_typemaps.inoutr_ulonglong(20)==20) + +-- check bools +assert(li_typemaps.in_bool(true)==true) +assert(li_typemaps.inr_bool(false)==false) +assert(li_typemaps.out_bool(true)==true) +assert(li_typemaps.outr_bool(false)==false) +assert(li_typemaps.inout_bool(true)==true) +assert(li_typemaps.inoutr_bool(false)==false) + +-- the others +a,b=li_typemaps.inoutr_int2(1,2) +assert(a==1 and b==2) + +f,i=li_typemaps.out_foo(10) +assert(f.a==10 and i==20) From 1f0db4fb9e0a3e6dbd916b7e69eb551ca2bb2f5d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 13 Jan 2013 00:06:09 +0000 Subject: [PATCH 0385/1160] Add check-cpp11 target for testing c++11 only tests --- Examples/test-suite/common.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index a0f91655e..c19755018 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -566,6 +566,8 @@ all: $(NOT_BROKEN_TEST_CASES) $(BROKEN_TEST_CASES) check: $(NOT_BROKEN_TEST_CASES) +check-cpp11: $(CPP0X_TEST_CASES:=.cpptest) + # partialcheck target runs SWIG only, ie no compilation or running of tests (for a subset of languages) partialcheck: $(MAKE) check CC=true CXX=true LDSHARED=true CXXSHARED=true RUNTOOL=true COMPILETOOL=true From 0afbb357d05e64b5fb9deace5c3dd9960aff8a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Sun, 13 Jan 2013 23:14:46 +0100 Subject: [PATCH 0386/1160] moved testdir/* to testdir/inctest/* under Examples/test-suite/ --- Examples/test-suite/common.mk | 10 +++++----- Examples/test-suite/inctest.i | 6 +++--- .../test-suite/testdir/{ => inctest}/subdir1/hello.i | 0 .../test-suite/testdir/{ => inctest}/subdir1/imports.i | 0 .../test-suite/testdir/{ => inctest}/subdir1/subinc1.i | 0 .../test-suite/testdir/{ => inctest}/subdir2/hello.i | 0 .../test-suite/testdir/{ => inctest}/subdir2/imports.i | 0 .../test-suite/testdir/{ => inctest}/subdir2/subinc2.i | 0 Examples/test-suite/testdir/{ => inctest}/test.i | 0 9 files changed, 8 insertions(+), 8 deletions(-) rename Examples/test-suite/testdir/{ => inctest}/subdir1/hello.i (100%) rename Examples/test-suite/testdir/{ => inctest}/subdir1/imports.i (100%) rename Examples/test-suite/testdir/{ => inctest}/subdir1/subinc1.i (100%) rename Examples/test-suite/testdir/{ => inctest}/subdir2/hello.i (100%) rename Examples/test-suite/testdir/{ => inctest}/subdir2/imports.i (100%) rename Examples/test-suite/testdir/{ => inctest}/subdir2/subinc2.i (100%) rename Examples/test-suite/testdir/{ => inctest}/test.i (100%) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 23988404d..173e9b287 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -234,7 +234,7 @@ CPP_TEST_CASES += \ inherit_void_arg \ inline_initializer \ insert_directive \ - keyword_rename \ + keyword_rename \ kind \ langobj \ li_attribute \ @@ -281,7 +281,7 @@ CPP_TEST_CASES += \ operator_overload \ operator_overload_break \ operator_pointer_ref \ - operbool \ + operbool \ ordering \ overload_copy \ overload_method \ @@ -485,8 +485,8 @@ CPP_STD_TEST_CASES += \ li_std_except \ li_std_except_as_class \ li_std_map \ - li_std_pair \ - li_std_pair_using \ + li_std_pair \ + li_std_pair_using \ li_std_string \ li_std_vector \ li_std_vector_enum \ @@ -519,7 +519,7 @@ C_TEST_CASES += \ immutable_values \ inctest \ integers \ - keyword_rename \ + keyword_rename \ lextype \ li_carrays \ li_cdata \ diff --git a/Examples/test-suite/inctest.i b/Examples/test-suite/inctest.i index f33304284..0b01ef4bb 100644 --- a/Examples/test-suite/inctest.i +++ b/Examples/test-suite/inctest.i @@ -4,8 +4,8 @@ // This test fails if swig is not able to include // the following two files: // - // 'testdir/subdir1/hello.i' - // 'testdir/subdir2/hello.i' + // 'testdir/inctest/subdir1/hello.i' + // 'testdir/inctest/subdir2/hello.i' // // since they have the same basename 'hello', swig is only // including one. This is not right, it must include both, @@ -13,7 +13,7 @@ // // Also repeats the test for the import directive in subdirectories -%include "testdir/test.i" +%include "testdir/inctest/test.i" // Bug #1162194 diff --git a/Examples/test-suite/testdir/subdir1/hello.i b/Examples/test-suite/testdir/inctest/subdir1/hello.i similarity index 100% rename from Examples/test-suite/testdir/subdir1/hello.i rename to Examples/test-suite/testdir/inctest/subdir1/hello.i diff --git a/Examples/test-suite/testdir/subdir1/imports.i b/Examples/test-suite/testdir/inctest/subdir1/imports.i similarity index 100% rename from Examples/test-suite/testdir/subdir1/imports.i rename to Examples/test-suite/testdir/inctest/subdir1/imports.i diff --git a/Examples/test-suite/testdir/subdir1/subinc1.i b/Examples/test-suite/testdir/inctest/subdir1/subinc1.i similarity index 100% rename from Examples/test-suite/testdir/subdir1/subinc1.i rename to Examples/test-suite/testdir/inctest/subdir1/subinc1.i diff --git a/Examples/test-suite/testdir/subdir2/hello.i b/Examples/test-suite/testdir/inctest/subdir2/hello.i similarity index 100% rename from Examples/test-suite/testdir/subdir2/hello.i rename to Examples/test-suite/testdir/inctest/subdir2/hello.i diff --git a/Examples/test-suite/testdir/subdir2/imports.i b/Examples/test-suite/testdir/inctest/subdir2/imports.i similarity index 100% rename from Examples/test-suite/testdir/subdir2/imports.i rename to Examples/test-suite/testdir/inctest/subdir2/imports.i diff --git a/Examples/test-suite/testdir/subdir2/subinc2.i b/Examples/test-suite/testdir/inctest/subdir2/subinc2.i similarity index 100% rename from Examples/test-suite/testdir/subdir2/subinc2.i rename to Examples/test-suite/testdir/inctest/subdir2/subinc2.i diff --git a/Examples/test-suite/testdir/test.i b/Examples/test-suite/testdir/inctest/test.i similarity index 100% rename from Examples/test-suite/testdir/test.i rename to Examples/test-suite/testdir/inctest/test.i From bdd5dac21e779b2d43c0cd0bebaf473442d4fd2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Sun, 13 Jan 2013 23:40:46 +0100 Subject: [PATCH 0387/1160] updated info on lang-specific subdirs in Doc/Manual/Library.html --- Doc/Manual/Library.html | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html index 1c7b84a1a..1ae3c77a3 100644 --- a/Doc/Manual/Library.html +++ b/Doc/Manual/Library.html @@ -66,18 +66,19 @@ Library files are included using the %include directive. When searching for files, directories are searched in the following order:

    -
      +
      1. The current directory
      2. Directories specified with the -I command line option
      3. ./swig_lib
      4. SWIG library install location as reported by swig -swiglib, for example /usr/local/share/swig/1.3.30
      5. On Windows, a directory Lib relative to the location of swig.exe is also searched. -
    +

    -Within each directory, SWIG first looks for a subdirectory corresponding to a target language (e.g., python, -tcl, etc.). If found, SWIG will search the language specific directory first. This allows -for language-specific implementations of library files. +Within directories mentioned in points 3-5, SWIG first looks for a subdirectory +corresponding to a target language (e.g., python, tcl, etc.). +If found, SWIG will search the language specific directory first. This allows +for language-specific implementations of library files.

    From 0e6af5c0ea6db5a69e047274b029fb937c1adebc Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 15 Jan 2013 06:45:47 +0000 Subject: [PATCH 0388/1160] Fix cstype typemap lookup for member variables so that a fully qualified variable name matches --- CHANGES.current | 8 +++++++ Examples/test-suite/csharp_typemaps.i | 19 +++++++++++++++ Source/Modules/csharp.cxx | 33 +++++++++++++++------------ 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 0d6a69959..8e17e2d44 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,14 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-01-15: wsfulton + [C#] Fix cstype typemap lookup for member variables so that a fully qualified variable name + matches. For example: + %typemap(cstype) bool MVar::mvar "MyBool" + struct MVar { + bool mvar; + }; + 2013-01-11: Brant Kyser [Java, C#, D] SF Bug #1299 - Fix generated names for when %nspace is used on classes with the same name in two different namespaces. diff --git a/Examples/test-suite/csharp_typemaps.i b/Examples/test-suite/csharp_typemaps.i index 18896456e..83097f663 100644 --- a/Examples/test-suite/csharp_typemaps.i +++ b/Examples/test-suite/csharp_typemaps.i @@ -117,3 +117,22 @@ void hoop(WasCrashing was) {} enum BigNumbers { big=0x80000000, bigger }; %} +// Member variable qualification +%typemap(cstype) bool "badtype1" +%typemap(cstype) bool mvar "badtype2" +%typemap(cstype) bool svar "badtype4" +%typemap(cstype) bool gvar "badtype5" +%typemap(cstype) bool MVar::mvar "bool" +%typemap(cstype) bool MVar::svar "bool" +%typemap(cstype) bool Glob::gvar "bool" +%inline %{ +struct MVar { + bool mvar; + static bool svar; +}; +namespace Glob { + bool gvar; +} +bool MVar::svar = false; +%} + diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 88cd679b9..0d15a9c1d 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -2310,15 +2310,18 @@ public: // Get the C# variable type - obtained differently depending on whether a setter is required. String *variable_type = return_type; if (setter_flag) { - assert(last_parm); - p = last_parm; // (last parameter is the only parameter for properties) - SwigType *pt = Getattr(p, "type"); - if ((tm = Getattr(p, "tmap:cstype"))) { - substituteClassname(pt, tm); - String *cstypeout = Getattr(p, "tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap - variable_type = cstypeout ? cstypeout : tm; + assert(last_parm); // (last parameter is the only parameter for properties) + /* Get variable type - ensure the variable name is fully resolved during typemap lookup via the symbol table set in NewParmNode */ + SwigType *cvariable_type = Getattr(last_parm, "type"); + Parm *variable_parm = NewParmNode(cvariable_type, n); + if ((tm = Swig_typemap_lookup("cstype", variable_parm, "", 0))) { + String *cstypeout = Getattr(variable_parm, "tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap + if (cstypeout) + tm = cstypeout; + substituteClassname(cvariable_type, tm); + variable_type = tm; } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(cvariable_type, 0)); } } const String *csattributes = Getattr(n, "feature:cs:attributes"); @@ -2333,17 +2336,17 @@ public: if (setter_flag) { // Setter method - assert(last_parm); - p = last_parm; // (last parameter is the only parameter for properties) - SwigType *pt = Getattr(p, "type"); - if ((tm = Getattr(p, "tmap:csvarin"))) { - substituteClassname(pt, tm); + assert(last_parm); // (last parameter is the only parameter for properties) + SwigType *cvariable_type = Getattr(last_parm, "type"); + Parm *variable_parm = NewParmNode(cvariable_type, n); + if ((tm = Swig_typemap_lookup("csvarin", variable_parm, "", 0))) { + substituteClassname(cvariable_type, tm); Replaceall(tm, "$csinput", "value"); Replaceall(tm, "$imcall", imcall); - excodeSubstitute(n, tm, "csvarin", p); + excodeSubstitute(n, tm, "csvarin", variable_parm); Printf(proxy_class_code, "%s", tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(cvariable_type, 0)); } } else { // Getter method From 78cd350fe98581d1353425eb9898a1e0a1d5ef6e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 15 Jan 2013 07:18:20 +0000 Subject: [PATCH 0389/1160] Fix Visual Studio examples to work when SWIG is unzipped into a directory containing spaces. --- CHANGES.current | 3 +++ Examples/java/class/example.dsp | 4 ++-- Examples/java/multimap/example.dsp | 4 ++-- Examples/java/simple/example.dsp | 4 ++-- Examples/perl5/class/example.dsp | 4 ++-- Examples/perl5/import/bar.dsp | 4 ++-- Examples/perl5/import/base.dsp | 4 ++-- Examples/perl5/import/foo.dsp | 4 ++-- Examples/perl5/import/spam.dsp | 4 ++-- Examples/perl5/multimap/example.dsp | 4 ++-- Examples/perl5/simple/example.dsp | 4 ++-- Examples/python/class/example.dsp | 4 ++-- Examples/python/contract/example.dsp | 4 ++-- Examples/python/import/bar.dsp | 4 ++-- Examples/python/import/base.dsp | 4 ++-- Examples/python/import/foo.dsp | 4 ++-- Examples/python/import/spam.dsp | 4 ++-- Examples/python/multimap/example.dsp | 4 ++-- Examples/python/simple/example.dsp | 4 ++-- Examples/r/class/example.dsp | 4 ++-- Examples/r/simple/example.dsp | 4 ++-- Examples/ruby/class/example.dsp | 4 ++-- Examples/ruby/free_function/example.dsp | 4 ++-- Examples/ruby/import/bar.dsp | 4 ++-- Examples/ruby/import/base.dsp | 4 ++-- Examples/ruby/import/foo.dsp | 4 ++-- Examples/ruby/import/spam.dsp | 4 ++-- Examples/ruby/mark_function/example.dsp | 4 ++-- Examples/ruby/multimap/example.dsp | 4 ++-- Examples/ruby/simple/example.dsp | 4 ++-- Examples/tcl/class/example.dsp | 4 ++-- Examples/tcl/contract/example.dsp | 4 ++-- Examples/tcl/import/bar.dsp | 4 ++-- Examples/tcl/import/base.dsp | 4 ++-- Examples/tcl/import/foo.dsp | 4 ++-- Examples/tcl/import/spam.dsp | 4 ++-- Examples/tcl/multimap/example.dsp | 4 ++-- Examples/tcl/simple/example.dsp | 4 ++-- 38 files changed, 77 insertions(+), 74 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 8e17e2d44..f8391a635 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-01-15: wsfulton + Fix Visual Studio examples to work when SWIG is unzipped into a directory containing spaces. + 2013-01-15: wsfulton [C#] Fix cstype typemap lookup for member variables so that a fully qualified variable name matches. For example: diff --git a/Examples/java/class/example.dsp b/Examples/java/class/example.dsp index fbe87e7a4..f52544b95 100644 --- a/Examples/java/class/example.dsp +++ b/Examples/java/class/example.dsp @@ -136,7 +136,7 @@ InputName=example echo JAVA_INCLUDE: %JAVA_INCLUDE% echo JAVA_BIN: %JAVA_BIN% echo on - ..\..\..\swig.exe -c++ -java $(InputPath) + ..\..\..\swig.exe -c++ -java "$(InputPath)" # End Custom Build @@ -151,7 +151,7 @@ InputName=example echo JAVA_INCLUDE: %JAVA_INCLUDE% echo JAVA_BIN: %JAVA_BIN% echo on - ..\..\..\swig.exe -c++ -java $(InputPath) + ..\..\..\swig.exe -c++ -java "$(InputPath)" # End Custom Build diff --git a/Examples/java/multimap/example.dsp b/Examples/java/multimap/example.dsp index 8e1f8415e..551866fd6 100644 --- a/Examples/java/multimap/example.dsp +++ b/Examples/java/multimap/example.dsp @@ -132,7 +132,7 @@ InputName=example echo JAVA_INCLUDE: %JAVA_INCLUDE% echo JAVA_BIN: %JAVA_BIN% echo on - ..\..\..\swig.exe -java $(InputPath) + ..\..\..\swig.exe -java "$(InputPath)" # End Custom Build @@ -147,7 +147,7 @@ InputName=example echo JAVA_INCLUDE: %JAVA_INCLUDE% echo JAVA_BIN: %JAVA_BIN% echo on - ..\..\..\swig.exe -java $(InputPath) + ..\..\..\swig.exe -java "$(InputPath)" # End Custom Build diff --git a/Examples/java/simple/example.dsp b/Examples/java/simple/example.dsp index 8e1f8415e..551866fd6 100644 --- a/Examples/java/simple/example.dsp +++ b/Examples/java/simple/example.dsp @@ -132,7 +132,7 @@ InputName=example echo JAVA_INCLUDE: %JAVA_INCLUDE% echo JAVA_BIN: %JAVA_BIN% echo on - ..\..\..\swig.exe -java $(InputPath) + ..\..\..\swig.exe -java "$(InputPath)" # End Custom Build @@ -147,7 +147,7 @@ InputName=example echo JAVA_INCLUDE: %JAVA_INCLUDE% echo JAVA_BIN: %JAVA_BIN% echo on - ..\..\..\swig.exe -java $(InputPath) + ..\..\..\swig.exe -java "$(InputPath)" # End Custom Build diff --git a/Examples/perl5/class/example.dsp b/Examples/perl5/class/example.dsp index b5ccd1928..3aef4e24e 100644 --- a/Examples/perl5/class/example.dsp +++ b/Examples/perl5/class/example.dsp @@ -126,7 +126,7 @@ InputName=example echo PERL5_INCLUDE: %PERL5_INCLUDE% echo PERL5_LIB: %PERL5_LIB% echo on - ..\..\..\swig.exe -c++ -perl5 $(InputPath) + ..\..\..\swig.exe -c++ -perl5 "$(InputPath)" # End Custom Build @@ -141,7 +141,7 @@ InputName=example echo PERL5_INCLUDE: %PERL5_INCLUDE% echo PERL5_LIB: %PERL5_LIB% echo on - ..\..\..\swig.exe -c++ -perl5 $(InputPath) + ..\..\..\swig.exe -c++ -perl5 "$(InputPath)" # End Custom Build diff --git a/Examples/perl5/import/bar.dsp b/Examples/perl5/import/bar.dsp index 64786b8f6..a329898ee 100644 --- a/Examples/perl5/import/bar.dsp +++ b/Examples/perl5/import/bar.dsp @@ -118,7 +118,7 @@ InputName=bar echo PERL5_INCLUDE: %PERL5_INCLUDE% echo PERL5_LIB: %PERL5_LIB% echo on - ..\..\..\swig.exe -c++ -perl5 $(InputPath) + ..\..\..\swig.exe -c++ -perl5 "$(InputPath)" # End Custom Build @@ -133,7 +133,7 @@ InputName=bar echo PERL5_INCLUDE: %PERL5_INCLUDE% echo PERL5_LIB: %PERL5_LIB% echo on - ..\..\..\swig.exe -c++ -perl5 $(InputPath) + ..\..\..\swig.exe -c++ -perl5 "$(InputPath)" # End Custom Build diff --git a/Examples/perl5/import/base.dsp b/Examples/perl5/import/base.dsp index 920891cbf..f52f1e956 100644 --- a/Examples/perl5/import/base.dsp +++ b/Examples/perl5/import/base.dsp @@ -118,7 +118,7 @@ InputName=base echo PERL5_INCLUDE: %PERL5_INCLUDE% echo PERL5_LIB: %PERL5_LIB% echo on - ..\..\..\swig.exe -c++ -perl5 $(InputPath) + ..\..\..\swig.exe -c++ -perl5 "$(InputPath)" # End Custom Build @@ -133,7 +133,7 @@ InputName=base echo PERL5_INCLUDE: %PERL5_INCLUDE% echo PERL5_LIB: %PERL5_LIB% echo on - ..\..\..\swig.exe -c++ -perl5 $(InputPath) + ..\..\..\swig.exe -c++ -perl5 "$(InputPath)" # End Custom Build diff --git a/Examples/perl5/import/foo.dsp b/Examples/perl5/import/foo.dsp index d519a5316..e959e9f92 100644 --- a/Examples/perl5/import/foo.dsp +++ b/Examples/perl5/import/foo.dsp @@ -118,7 +118,7 @@ InputName=foo echo PERL5_INCLUDE: %PERL5_INCLUDE% echo PERL5_LIB: %PERL5_LIB% echo on - ..\..\..\swig.exe -c++ -perl5 $(InputPath) + ..\..\..\swig.exe -c++ -perl5 "$(InputPath)" # End Custom Build @@ -133,7 +133,7 @@ InputName=foo echo PERL5_INCLUDE: %PERL5_INCLUDE% echo PERL5_LIB: %PERL5_LIB% echo on - ..\..\..\swig.exe -c++ -perl5 $(InputPath) + ..\..\..\swig.exe -c++ -perl5 "$(InputPath)" # End Custom Build diff --git a/Examples/perl5/import/spam.dsp b/Examples/perl5/import/spam.dsp index e5c8046eb..875efac89 100644 --- a/Examples/perl5/import/spam.dsp +++ b/Examples/perl5/import/spam.dsp @@ -118,7 +118,7 @@ InputName=spam echo PERL5_INCLUDE: %PERL5_INCLUDE% echo PERL5_LIB: %PERL5_LIB% echo on - ..\..\..\swig.exe -c++ -perl5 $(InputPath) + ..\..\..\swig.exe -c++ -perl5 "$(InputPath)" # End Custom Build @@ -133,7 +133,7 @@ InputName=spam echo PERL5_INCLUDE: %PERL5_INCLUDE% echo PERL5_LIB: %PERL5_LIB% echo on - ..\..\..\swig.exe -c++ -perl5 $(InputPath) + ..\..\..\swig.exe -c++ -perl5 "$(InputPath)" # End Custom Build diff --git a/Examples/perl5/multimap/example.dsp b/Examples/perl5/multimap/example.dsp index be8a0070e..21bdf8dca 100644 --- a/Examples/perl5/multimap/example.dsp +++ b/Examples/perl5/multimap/example.dsp @@ -122,7 +122,7 @@ InputName=example echo PERL5_INCLUDE: %PERL5_INCLUDE% echo PERL5_LIB: %PERL5_LIB% echo on - ..\..\..\swig.exe -perl5 $(InputPath) + ..\..\..\swig.exe -perl5 "$(InputPath)" # End Custom Build @@ -137,7 +137,7 @@ InputName=example echo PERL5_INCLUDE: %PERL5_INCLUDE% echo PERL5_LIB: %PERL5_LIB% echo on - ..\..\..\swig.exe -perl5 $(InputPath) + ..\..\..\swig.exe -perl5 "$(InputPath)" # End Custom Build diff --git a/Examples/perl5/simple/example.dsp b/Examples/perl5/simple/example.dsp index be8a0070e..21bdf8dca 100644 --- a/Examples/perl5/simple/example.dsp +++ b/Examples/perl5/simple/example.dsp @@ -122,7 +122,7 @@ InputName=example echo PERL5_INCLUDE: %PERL5_INCLUDE% echo PERL5_LIB: %PERL5_LIB% echo on - ..\..\..\swig.exe -perl5 $(InputPath) + ..\..\..\swig.exe -perl5 "$(InputPath)" # End Custom Build @@ -137,7 +137,7 @@ InputName=example echo PERL5_INCLUDE: %PERL5_INCLUDE% echo PERL5_LIB: %PERL5_LIB% echo on - ..\..\..\swig.exe -perl5 $(InputPath) + ..\..\..\swig.exe -perl5 "$(InputPath)" # End Custom Build diff --git a/Examples/python/class/example.dsp b/Examples/python/class/example.dsp index fd7bf8c06..b75bd9ee2 100644 --- a/Examples/python/class/example.dsp +++ b/Examples/python/class/example.dsp @@ -126,7 +126,7 @@ InputName=example echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -c++ -python $(InputPath) + ..\..\..\swig.exe -c++ -python "$(InputPath)" # End Custom Build @@ -141,7 +141,7 @@ InputName=example echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -c++ -python $(InputPath) + ..\..\..\swig.exe -c++ -python "$(InputPath)" # End Custom Build diff --git a/Examples/python/contract/example.dsp b/Examples/python/contract/example.dsp index 32845e0e8..68f79c7a6 100644 --- a/Examples/python/contract/example.dsp +++ b/Examples/python/contract/example.dsp @@ -122,7 +122,7 @@ InputName=example echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -python $(InputPath) + ..\..\..\swig.exe -python "$(InputPath)" # End Custom Build @@ -137,7 +137,7 @@ InputName=example echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -python $(InputPath) + ..\..\..\swig.exe -python "$(InputPath)" # End Custom Build diff --git a/Examples/python/import/bar.dsp b/Examples/python/import/bar.dsp index 17b05cc39..df4d03e1c 100644 --- a/Examples/python/import/bar.dsp +++ b/Examples/python/import/bar.dsp @@ -118,7 +118,7 @@ InputName=bar echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -c++ -python $(InputPath) + ..\..\..\swig.exe -c++ -python "$(InputPath)" # End Custom Build @@ -133,7 +133,7 @@ InputName=bar echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -c++ -python $(InputPath) + ..\..\..\swig.exe -c++ -python "$(InputPath)" # End Custom Build diff --git a/Examples/python/import/base.dsp b/Examples/python/import/base.dsp index 2bc9736d1..5f2c4c503 100644 --- a/Examples/python/import/base.dsp +++ b/Examples/python/import/base.dsp @@ -118,7 +118,7 @@ InputName=base echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -c++ -python $(InputPath) + ..\..\..\swig.exe -c++ -python "$(InputPath)" # End Custom Build @@ -133,7 +133,7 @@ InputName=base echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -c++ -python $(InputPath) + ..\..\..\swig.exe -c++ -python "$(InputPath)" # End Custom Build diff --git a/Examples/python/import/foo.dsp b/Examples/python/import/foo.dsp index 9a92c4b85..fc7a94b14 100644 --- a/Examples/python/import/foo.dsp +++ b/Examples/python/import/foo.dsp @@ -118,7 +118,7 @@ InputName=foo echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -c++ -python $(InputPath) + ..\..\..\swig.exe -c++ -python "$(InputPath)" # End Custom Build @@ -133,7 +133,7 @@ InputName=foo echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -c++ -python $(InputPath) + ..\..\..\swig.exe -c++ -python "$(InputPath)" # End Custom Build diff --git a/Examples/python/import/spam.dsp b/Examples/python/import/spam.dsp index 0a6595bfe..6fa4713ee 100644 --- a/Examples/python/import/spam.dsp +++ b/Examples/python/import/spam.dsp @@ -118,7 +118,7 @@ InputName=spam echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -c++ -python $(InputPath) + ..\..\..\swig.exe -c++ -python "$(InputPath)" # End Custom Build @@ -133,7 +133,7 @@ InputName=spam echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -c++ -python $(InputPath) + ..\..\..\swig.exe -c++ -python "$(InputPath)" # End Custom Build diff --git a/Examples/python/multimap/example.dsp b/Examples/python/multimap/example.dsp index 32845e0e8..68f79c7a6 100644 --- a/Examples/python/multimap/example.dsp +++ b/Examples/python/multimap/example.dsp @@ -122,7 +122,7 @@ InputName=example echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -python $(InputPath) + ..\..\..\swig.exe -python "$(InputPath)" # End Custom Build @@ -137,7 +137,7 @@ InputName=example echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -python $(InputPath) + ..\..\..\swig.exe -python "$(InputPath)" # End Custom Build diff --git a/Examples/python/simple/example.dsp b/Examples/python/simple/example.dsp index 32845e0e8..68f79c7a6 100644 --- a/Examples/python/simple/example.dsp +++ b/Examples/python/simple/example.dsp @@ -122,7 +122,7 @@ InputName=example echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -python $(InputPath) + ..\..\..\swig.exe -python "$(InputPath)" # End Custom Build @@ -137,7 +137,7 @@ InputName=example echo PYTHON_INCLUDE: %PYTHON_INCLUDE% echo PYTHON_LIB: %PYTHON_LIB% echo on - ..\..\..\swig.exe -python $(InputPath) + ..\..\..\swig.exe -python "$(InputPath)" # End Custom Build diff --git a/Examples/r/class/example.dsp b/Examples/r/class/example.dsp index b831989cc..aea02b2fa 100644 --- a/Examples/r/class/example.dsp +++ b/Examples/r/class/example.dsp @@ -126,7 +126,7 @@ InputName=example echo R_INCLUDE: %R_INCLUDE% echo R_LIB: %R_LIB% echo on - ..\..\..\swig.exe -c++ -r -o example_wrap.cpp $(InputPath) + ..\..\..\swig.exe -c++ -r -o example_wrap.cpp "$(InputPath)" # End Custom Build @@ -141,7 +141,7 @@ InputName=example echo R_INCLUDE: %R_INCLUDE% echo R_LIB: %R_LIB% echo on - ..\..\..\swig.exe -c++ -r -o example_wrap.cpp $(InputPath) + ..\..\..\swig.exe -c++ -r -o example_wrap.cpp "$(InputPath)" # End Custom Build diff --git a/Examples/r/simple/example.dsp b/Examples/r/simple/example.dsp index 356815d19..105392bbd 100644 --- a/Examples/r/simple/example.dsp +++ b/Examples/r/simple/example.dsp @@ -122,7 +122,7 @@ InputName=example echo R_INCLUDE: %R_INCLUDE% echo R_LIB: %R_LIB% echo on - ..\..\..\swig.exe -r $(InputPath) + ..\..\..\swig.exe -r "$(InputPath)" # End Custom Build @@ -137,7 +137,7 @@ InputName=example echo R_INCLUDE: %R_INCLUDE% echo R_LIB: %R_LIB% echo on - ..\..\..\swig.exe -r $(InputPath) + ..\..\..\swig.exe -r "$(InputPath)" # End Custom Build diff --git a/Examples/ruby/class/example.dsp b/Examples/ruby/class/example.dsp index 2adab787a..8c1786c10 100644 --- a/Examples/ruby/class/example.dsp +++ b/Examples/ruby/class/example.dsp @@ -128,7 +128,7 @@ InputName=example echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -c++ -ruby $(InputPath) + ..\..\..\swig.exe -c++ -ruby "$(InputPath)" # End Custom Build @@ -143,7 +143,7 @@ InputName=example echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -c++ -ruby $(InputPath) + ..\..\..\swig.exe -c++ -ruby "$(InputPath)" # End Custom Build diff --git a/Examples/ruby/free_function/example.dsp b/Examples/ruby/free_function/example.dsp index 2adab787a..8c1786c10 100644 --- a/Examples/ruby/free_function/example.dsp +++ b/Examples/ruby/free_function/example.dsp @@ -128,7 +128,7 @@ InputName=example echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -c++ -ruby $(InputPath) + ..\..\..\swig.exe -c++ -ruby "$(InputPath)" # End Custom Build @@ -143,7 +143,7 @@ InputName=example echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -c++ -ruby $(InputPath) + ..\..\..\swig.exe -c++ -ruby "$(InputPath)" # End Custom Build diff --git a/Examples/ruby/import/bar.dsp b/Examples/ruby/import/bar.dsp index 29d9abf2f..678dd3792 100644 --- a/Examples/ruby/import/bar.dsp +++ b/Examples/ruby/import/bar.dsp @@ -120,7 +120,7 @@ InputName=bar echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -c++ -ruby $(InputPath) + ..\..\..\swig.exe -c++ -ruby "$(InputPath)" # End Custom Build @@ -135,7 +135,7 @@ InputName=bar echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -c++ -ruby $(InputPath) + ..\..\..\swig.exe -c++ -ruby "$(InputPath)" # End Custom Build diff --git a/Examples/ruby/import/base.dsp b/Examples/ruby/import/base.dsp index 174afef3e..4b9e2ea3f 100644 --- a/Examples/ruby/import/base.dsp +++ b/Examples/ruby/import/base.dsp @@ -120,7 +120,7 @@ InputName=base echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -c++ -ruby $(InputPath) + ..\..\..\swig.exe -c++ -ruby "$(InputPath)" # End Custom Build @@ -135,7 +135,7 @@ InputName=base echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -c++ -ruby $(InputPath) + ..\..\..\swig.exe -c++ -ruby "$(InputPath)" # End Custom Build diff --git a/Examples/ruby/import/foo.dsp b/Examples/ruby/import/foo.dsp index 7f4754915..1d56ec375 100644 --- a/Examples/ruby/import/foo.dsp +++ b/Examples/ruby/import/foo.dsp @@ -120,7 +120,7 @@ InputName=foo echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -c++ -ruby $(InputPath) + ..\..\..\swig.exe -c++ -ruby "$(InputPath)" # End Custom Build @@ -135,7 +135,7 @@ InputName=foo echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -c++ -ruby $(InputPath) + ..\..\..\swig.exe -c++ -ruby "$(InputPath)" # End Custom Build diff --git a/Examples/ruby/import/spam.dsp b/Examples/ruby/import/spam.dsp index 72729f290..3cc700864 100644 --- a/Examples/ruby/import/spam.dsp +++ b/Examples/ruby/import/spam.dsp @@ -120,7 +120,7 @@ InputName=spam echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -c++ -ruby $(InputPath) + ..\..\..\swig.exe -c++ -ruby "$(InputPath)" # End Custom Build @@ -135,7 +135,7 @@ InputName=spam echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -c++ -ruby $(InputPath) + ..\..\..\swig.exe -c++ -ruby "$(InputPath)" # End Custom Build diff --git a/Examples/ruby/mark_function/example.dsp b/Examples/ruby/mark_function/example.dsp index 2adab787a..8c1786c10 100644 --- a/Examples/ruby/mark_function/example.dsp +++ b/Examples/ruby/mark_function/example.dsp @@ -128,7 +128,7 @@ InputName=example echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -c++ -ruby $(InputPath) + ..\..\..\swig.exe -c++ -ruby "$(InputPath)" # End Custom Build @@ -143,7 +143,7 @@ InputName=example echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -c++ -ruby $(InputPath) + ..\..\..\swig.exe -c++ -ruby "$(InputPath)" # End Custom Build diff --git a/Examples/ruby/multimap/example.dsp b/Examples/ruby/multimap/example.dsp index 4888299f5..de66ca0cf 100644 --- a/Examples/ruby/multimap/example.dsp +++ b/Examples/ruby/multimap/example.dsp @@ -124,7 +124,7 @@ InputName=example echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -ruby $(InputPath) + ..\..\..\swig.exe -ruby "$(InputPath)" # End Custom Build @@ -139,7 +139,7 @@ InputName=example echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -ruby $(InputPath) + ..\..\..\swig.exe -ruby "$(InputPath)" # End Custom Build diff --git a/Examples/ruby/simple/example.dsp b/Examples/ruby/simple/example.dsp index 4888299f5..de66ca0cf 100644 --- a/Examples/ruby/simple/example.dsp +++ b/Examples/ruby/simple/example.dsp @@ -124,7 +124,7 @@ InputName=example echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -ruby $(InputPath) + ..\..\..\swig.exe -ruby "$(InputPath)" # End Custom Build @@ -139,7 +139,7 @@ InputName=example echo RUBY_INCLUDE: %RUBY_INCLUDE% echo RUBY_LIB: %RUBY_LIB% echo on - ..\..\..\swig.exe -ruby $(InputPath) + ..\..\..\swig.exe -ruby "$(InputPath)" # End Custom Build diff --git a/Examples/tcl/class/example.dsp b/Examples/tcl/class/example.dsp index 0ff54829f..5a8c6a0bb 100644 --- a/Examples/tcl/class/example.dsp +++ b/Examples/tcl/class/example.dsp @@ -126,7 +126,7 @@ InputName=example echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -c++ -tcl8 $(InputPath) + ..\..\..\swig.exe -c++ -tcl8 "$(InputPath)" # End Custom Build @@ -141,7 +141,7 @@ InputName=example echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -c++ -tcl8 $(InputPath) + ..\..\..\swig.exe -c++ -tcl8 "$(InputPath)" # End Custom Build diff --git a/Examples/tcl/contract/example.dsp b/Examples/tcl/contract/example.dsp index c1568f2c5..e7b293579 100644 --- a/Examples/tcl/contract/example.dsp +++ b/Examples/tcl/contract/example.dsp @@ -122,7 +122,7 @@ InputName=example echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -tcl8 $(InputPath) + ..\..\..\swig.exe -tcl8 "$(InputPath)" # End Custom Build @@ -137,7 +137,7 @@ InputName=example echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -tcl8 $(InputPath) + ..\..\..\swig.exe -tcl8 "$(InputPath)" # End Custom Build diff --git a/Examples/tcl/import/bar.dsp b/Examples/tcl/import/bar.dsp index d22b6a6fa..a06b54a8c 100644 --- a/Examples/tcl/import/bar.dsp +++ b/Examples/tcl/import/bar.dsp @@ -118,7 +118,7 @@ InputName=bar echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -c++ -tcl8 $(InputPath) + ..\..\..\swig.exe -c++ -tcl8 "$(InputPath)" # End Custom Build @@ -133,7 +133,7 @@ InputName=bar echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -c++ -tcl8 $(InputPath) + ..\..\..\swig.exe -c++ -tcl8 "$(InputPath)" # End Custom Build diff --git a/Examples/tcl/import/base.dsp b/Examples/tcl/import/base.dsp index b27bbfdb6..6c4b40c9e 100644 --- a/Examples/tcl/import/base.dsp +++ b/Examples/tcl/import/base.dsp @@ -118,7 +118,7 @@ InputName=base echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -c++ -tcl8 $(InputPath) + ..\..\..\swig.exe -c++ -tcl8 "$(InputPath)" # End Custom Build @@ -133,7 +133,7 @@ InputName=base echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -c++ -tcl8 $(InputPath) + ..\..\..\swig.exe -c++ -tcl8 "$(InputPath)" # End Custom Build diff --git a/Examples/tcl/import/foo.dsp b/Examples/tcl/import/foo.dsp index 4d3765bd7..44bfa945c 100644 --- a/Examples/tcl/import/foo.dsp +++ b/Examples/tcl/import/foo.dsp @@ -118,7 +118,7 @@ InputName=foo echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -c++ -tcl8 $(InputPath) + ..\..\..\swig.exe -c++ -tcl8 "$(InputPath)" # End Custom Build @@ -133,7 +133,7 @@ InputName=foo echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -c++ -tcl8 $(InputPath) + ..\..\..\swig.exe -c++ -tcl8 "$(InputPath)" # End Custom Build diff --git a/Examples/tcl/import/spam.dsp b/Examples/tcl/import/spam.dsp index 5674c4373..4735d1469 100644 --- a/Examples/tcl/import/spam.dsp +++ b/Examples/tcl/import/spam.dsp @@ -118,7 +118,7 @@ InputName=spam echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -c++ -tcl8 $(InputPath) + ..\..\..\swig.exe -c++ -tcl8 "$(InputPath)" # End Custom Build @@ -133,7 +133,7 @@ InputName=spam echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -c++ -tcl8 $(InputPath) + ..\..\..\swig.exe -c++ -tcl8 "$(InputPath)" # End Custom Build diff --git a/Examples/tcl/multimap/example.dsp b/Examples/tcl/multimap/example.dsp index c1568f2c5..e7b293579 100644 --- a/Examples/tcl/multimap/example.dsp +++ b/Examples/tcl/multimap/example.dsp @@ -122,7 +122,7 @@ InputName=example echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -tcl8 $(InputPath) + ..\..\..\swig.exe -tcl8 "$(InputPath)" # End Custom Build @@ -137,7 +137,7 @@ InputName=example echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -tcl8 $(InputPath) + ..\..\..\swig.exe -tcl8 "$(InputPath)" # End Custom Build diff --git a/Examples/tcl/simple/example.dsp b/Examples/tcl/simple/example.dsp index c1568f2c5..e7b293579 100644 --- a/Examples/tcl/simple/example.dsp +++ b/Examples/tcl/simple/example.dsp @@ -122,7 +122,7 @@ InputName=example echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -tcl8 $(InputPath) + ..\..\..\swig.exe -tcl8 "$(InputPath)" # End Custom Build @@ -137,7 +137,7 @@ InputName=example echo TCL_INCLUDE: %TCL_INCLUDE% echo TCL_LIB: %TCL_LIB% echo on - ..\..\..\swig.exe -tcl8 $(InputPath) + ..\..\..\swig.exe -tcl8 "$(InputPath)" # End Custom Build From dba0adce71def7257f6acdc1cb790be5f18c5c39 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 17 Jan 2013 07:48:16 +0000 Subject: [PATCH 0390/1160] Minor update to test-suite README help files --- Examples/test-suite/README | 10 ++++++++++ Examples/test-suite/testdir/README | 3 +++ 2 files changed, 13 insertions(+) create mode 100644 Examples/test-suite/testdir/README diff --git a/Examples/test-suite/README b/Examples/test-suite/README index 96dea942c..aac7636c6 100644 --- a/Examples/test-suite/README +++ b/Examples/test-suite/README @@ -40,3 +40,13 @@ is an error in which case stderr is suggested. Please set the name of the module to the same name as the testcase, otherwise modules will not be found. +There is a special directory called testdir for testcases requiring +inputs from subdirectories or multiple directories. See the +testdir/README file. + +Further Documentation +--------------------- + +There is documentation about the test-suite and how to use use it in +the SWIG documentation - Doc/Manual/Extending.html#Extending_test_suite. + diff --git a/Examples/test-suite/testdir/README b/Examples/test-suite/testdir/README new file mode 100644 index 000000000..2aaabf377 --- /dev/null +++ b/Examples/test-suite/testdir/README @@ -0,0 +1,3 @@ +This is a special directory for testcases that require inputs using subdirectories. +Each subdirectory should be named after the testcase. Any desired subdirectory +structure can be put under the testcase subdirectory. From 3bdcb14117eec448bf2f77897d5706ebe0b555d3 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 10 Jan 2013 13:28:37 -0600 Subject: [PATCH 0391/1160] Add jniclasspackage pragma & change error regarding use of nspace without -package to warning. --- Source/Include/swigwarn.h | 1 + Source/Modules/java.cxx | 41 ++++++++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index 1aae86fdd..76f61ea93 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -241,6 +241,7 @@ #define WARN_JAVA_TYPEMAP_JAVACONSTRUCT_UNDEF 823 #define WARN_JAVA_TYPEMAP_DIRECTORIN_NODESC 824 #define WARN_JAVA_NO_DIRECTORCONNECT_ATTR 825 +#define WARN_JAVA_NSPACE_WITHOUT_PACKAGE 826 /* please leave 810-829 free for Java */ diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 57ac7ca52..e9b6f813c 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -67,6 +67,7 @@ class JAVA:public Language { String *imclass_imports; //intermediary class imports from %pragma String *module_imports; //module imports from %pragma String *imclass_baseclass; //inheritance for intermediary class class from %pragma + String *imclass_class_package; //package in which to generate the jni class String *module_baseclass; //inheritance for module class from %pragma String *imclass_interfaces; //interfaces for intermediary class class from %pragma String *module_interfaces; //interfaces for module class from %pragma @@ -364,6 +365,7 @@ public: proxy_class_code = NewString(""); module_class_constants_code = NewString(""); imclass_baseclass = NewString(""); + imclass_class_package = NewString(""); imclass_interfaces = NewString(""); imclass_class_modifiers = NewString(""); module_class_code = NewString(""); @@ -444,7 +446,7 @@ public: } // Generate the intermediary class { - String *filen = NewStringf("%s%s.java", SWIG_output_directory(), imclass_name); + String *filen = NewStringf("%s%s/%s.java", SWIG_output_directory(), imclass_class_package, imclass_name); File *f_im = NewFile(filen, "w", SWIG_output_files()); if (!f_im) { FileErrorDisplay(filen); @@ -457,8 +459,10 @@ public: // Start writing out the intermediary class file emitBanner(f_im); - if (package) - Printf(f_im, "package %s;\n", package); + if (Len(imclass_class_package)) + Printf(f_im, "package %s;", imclass_class_package); + else if (package) + Printf(f_im, "package %s;\n", package); if (imclass_imports) Printf(f_im, "%s\n", imclass_imports); @@ -625,6 +629,8 @@ public: module_class_constants_code = NULL; Delete(imclass_baseclass); imclass_baseclass = NULL; + Delete(imclass_class_package); + imclass_class_package = NULL; Delete(imclass_interfaces); imclass_interfaces = NULL; Delete(imclass_class_modifiers); @@ -1186,8 +1192,7 @@ public: full_imclass_name = NewStringf("%s.%s", package, imclass_name); } else { 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); + Swig_warning(WARN_JAVA_NSPACE_WITHOUT_PACKAGE, Getfile(n), Getline(n), "The nspace feature is used on '%s' without a package is specified with -package - This may result in generated code that does not compile as Java does not support types declared in a named package accessing types declared in an unnamed package.\n", name); } } } @@ -1574,7 +1579,8 @@ public: * pragmaDirective() * * Valid Pragmas: - * jniclassbase - base (extends) for the intermediary class + * jniclassbase - base (extends) for the intermediary + * jniclasspackage - package in which to generate the jni class * jniclassclassmodifiers - class modifiers for the intermediary class * jniclasscode - text (java code) is copied verbatim to the intermediary class * jniclassimports - import statements for the intermediary class @@ -1602,7 +1608,25 @@ public: if (Strcmp(code, "jniclassbase") == 0) { Delete(imclass_baseclass); imclass_baseclass = Copy(strvalue); - } else if (Strcmp(code, "jniclassclassmodifiers") == 0) { + } else if (Strcmp(code, "jniclasspackage") == 0) { + Delete(imclass_class_package); + imclass_class_package = Copy(strvalue); + String *imclass_class_package_jniname = makeValidJniName(imclass_class_package); + Printv(jnipackage, imclass_class_package_jniname, NIL); + Delete(imclass_class_package_jniname); + Replaceall(jnipackage, NSPACE_SEPARATOR, "_"); + Append(jnipackage, "_"); + + String *wrapper_name = NewString(""); + String *imclass_class_jniname = makeValidJniName(imclass_name); + Printf(wrapper_name, "Java_%s%s_%%f", jnipackage, imclass_class_jniname); + Delete(imclass_class_jniname); + + Swig_name_unregister("wrapper"); + Swig_name_register("wrapper", Char(wrapper_name)); + + Delete(wrapper_name); + } else if (Strcmp(code, "jniclassclassmodifiers") == 0) { Delete(imclass_class_modifiers); imclass_class_modifiers = Copy(strvalue); } else if (Strcmp(code, "jniclasscode") == 0) { @@ -1894,8 +1918,7 @@ public: full_imclass_name = NewStringf("%s.%s", package, imclass_name); } else { 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); + Swig_warning(WARN_JAVA_NSPACE_WITHOUT_PACKAGE, Getfile(n), Getline(n), "The nspace feature is used on '%s' without a package is specified with -package - This may result in generated code that does not compile as Java does not support types declared in a named package accessing types declared in an unnamed package.\n", name); } } From 9855e4d0644845474f78385c59fdbafeaab4476e Mon Sep 17 00:00:00 2001 From: marvingreenberg Date: Fri, 11 Jan 2013 10:08:09 -0500 Subject: [PATCH 0392/1160] Allow certain tests to compile without -package option --- Examples/test-suite/java/Makefile.in | 52 ++++++++++++++++++---------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index f8da8e6cc..a69c65ff6 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -15,7 +15,16 @@ C_TEST_CASES = \ java_lib_arrays \ java_lib_various -CPP_TEST_CASES = \ +# Use a different JAVA_PACKAGE set internally in the testcase. This must match +# what is internally in the test .i files (does swig support multiple package levels?) +# Make sure that the pragma dir DOES NOT exist (since test should create) +PRAGMATEST_PACKAGE = pragmajavapackage +PRAGMATEST_DIRSETUP = rm -rf $(PACKAGE_DIR) + +CPP_TEST_CASES_PKGPRAGMA = \ + java_test_of_package_pragma + +CPP_TEST_CASES_PKGOPT = \ enum_thorough_proper \ enum_thorough_simple \ enum_thorough_typeunsafe \ @@ -36,11 +45,20 @@ CPP_TEST_CASES = \ java_typemaps_typewrapper # li_boost_intrusive_ptr +CPP_TEST_CASES = $(CPP_TEST_CASES_PKGOPT) $(CPP_TEST_CASES_PKGPRAGMA) include $(srcdir)/../common.mk # Overridden variables here JAVA_PACKAGE = $* -SWIGOPT += -package $(JAVA_PACKAGE) +PKGDIRSETUP = [ -d "$(JAVA_PACKAGE) ] || mkdir -p $(JAVA_PACKAGE); + +# Add '-package' swigopt for ALL tests except for CPP_TEST_CASES_PKGPRAGMA +TEST_CASES_WITH_PKGOPT := $(filterout $(CPP_TEST_CASES_PKGPRAGMA:=.cpptest),$(NOT_BROKEN_TEST_CASES)) +$(TEST_CASES_WITH_PKGOPT): SWIGOPT += -package $(JAVA_PACKAGE) + +# Set JAVA_PACKAGE differently for the one test using a pragma javapackage +$(CPP_TEST_CASES_PKGPRAGMA:=.cpptest): JAVA_PACKAGE=$(PKGPRAGMA_PACKAGE) +$(CPP_TEST_CASES_PKGPRAGMA:=.cpptest): PKGDIRSETUP=$(PKGPRAGMA_DIRSETUP) # Custom tests - tests with additional commandline options nspace.%: JAVA_PACKAGE = $*Package @@ -51,31 +69,27 @@ director_nspace_director_name_collision.%: JAVA_PACKAGE = $*Package # Rules for the different types of tests %.cpptest: $(setup) - +(cd $(JAVA_PACKAGE) && $(swig_and_compile_cpp)) - $(run_testcase) + $(PKGDIRSETUP) + +echo $@ (cd $(JAVA_PACKAGE) && $(swig_and_compile_cpp)) + $echo $@ (run_testcase) %.ctest: $(setup) - +(cd $(JAVA_PACKAGE) && $(swig_and_compile_c)) - $(run_testcase) + $(PKGDIRSETUP) + +echo $@ (cd $(JAVA_PACKAGE) && $(swig_and_compile_c)) + $echo $@ (run_testcase) %.multicpptest: $(setup) - +(cd $(JAVA_PACKAGE) && $(swig_and_compile_multi_cpp)) - $(run_testcase) + $(PKGDIRSETUP) + +echo $@ (cd $(JAVA_PACKAGE) && $(swig_and_compile_multi_cpp)) + $echo $@ (run_testcase) -# Makes a directory for the testcase if it does not exist -setup = \ - if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \ - else \ - echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \ - fi; \ - if [ ! -d $(JAVA_PACKAGE) ]; then \ - mkdir $(JAVA_PACKAGE); \ - fi +# don't duplicate $(setup), just add explicit $(PKGDIRSETUP) +# This doesn't work yet since for PKGPRAGMA test, PKGDIRSETUP deletes +# JAVA_PACKAGE, but next line tries to cd there. -# Compiles java files then runs the testcase. A testcase is only run if +# 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 = \ From 30b1eafd96f50174ab20159f2a233d5f1758fc39 Mon Sep 17 00:00:00 2001 From: marvingreenberg Date: Fri, 11 Jan 2013 17:40:18 -0500 Subject: [PATCH 0393/1160] fix variable names and makefile logic to correctly set PKGDIRSETUP and SWIGOPT for different cases --- Examples/test-suite/java/Makefile.in | 46 +++++++++++++--------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index a69c65ff6..11d7fd3ef 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -15,14 +15,9 @@ C_TEST_CASES = \ java_lib_arrays \ java_lib_various -# Use a different JAVA_PACKAGE set internally in the testcase. This must match -# what is internally in the test .i files (does swig support multiple package levels?) -# Make sure that the pragma dir DOES NOT exist (since test should create) -PRAGMATEST_PACKAGE = pragmajavapackage -PRAGMATEST_DIRSETUP = rm -rf $(PACKAGE_DIR) - CPP_TEST_CASES_PKGPRAGMA = \ - java_test_of_package_pragma + internal_pkgpragma_test + CPP_TEST_CASES_PKGOPT = \ enum_thorough_proper \ @@ -50,15 +45,21 @@ include $(srcdir)/../common.mk # Overridden variables here JAVA_PACKAGE = $* -PKGDIRSETUP = [ -d "$(JAVA_PACKAGE) ] || mkdir -p $(JAVA_PACKAGE); + +ALL_PKGOPT := $(filter-out $(CPP_TEST_CASES_PKGPRAGMA:=.cpptest),$(NOT_BROKEN_TEST_CASES)) +ALL_PKGPRAGMA := $(filter $(CPP_TEST_CASES_PKGPRAGMA:=.cpptest),$(NOT_BROKEN_TEST_CASES)) # Add '-package' swigopt for ALL tests except for CPP_TEST_CASES_PKGPRAGMA -TEST_CASES_WITH_PKGOPT := $(filterout $(CPP_TEST_CASES_PKGPRAGMA:=.cpptest),$(NOT_BROKEN_TEST_CASES)) -$(TEST_CASES_WITH_PKGOPT): SWIGOPT += -package $(JAVA_PACKAGE) +# PKGDIRSETUP should leave 0 exitcode when successful +$(ALL_PKGOPT): SWIGOPT += -package $(JAVA_PACKAGE) +$(ALL_PKGOPT): PKGDIRSETUP = [ -d "$(JAVA_PACKAGE)" ] || mkdir -p "$(JAVA_PACKAGE)" && cd "$(JAVA_PACKAGE)" -# Set JAVA_PACKAGE differently for the one test using a pragma javapackage -$(CPP_TEST_CASES_PKGPRAGMA:=.cpptest): JAVA_PACKAGE=$(PKGPRAGMA_PACKAGE) -$(CPP_TEST_CASES_PKGPRAGMA:=.cpptest): PKGDIRSETUP=$(PKGPRAGMA_DIRSETUP) +# Set JAVA_PACKAGE differently for the tests using internally coded pragma javapackage +# (and must match what is in the test .i file) +# Make sure that the pragma dir DOES NOT exist (since test should create) +# This may not find all the generated java to compile... +$(ALL_PKGPRAGMA): JAVA_PACKAGE = MyExplicitPragmaJavaPackage +$(ALL_PKGPRAGMA): PKGDIRSETUP = rm -rf $(JAVA_PACKAGE) # Custom tests - tests with additional commandline options nspace.%: JAVA_PACKAGE = $*Package @@ -67,23 +68,20 @@ director_nspace.%: JAVA_PACKAGE = $*Package director_nspace_director_name_collision.%: JAVA_PACKAGE = $*Package # Rules for the different types of tests -%.cpptest: +%.cpptest: $(setup) - $(PKGDIRSETUP) - +echo $@ (cd $(JAVA_PACKAGE) && $(swig_and_compile_cpp)) - $echo $@ (run_testcase) + +echo "$@ ($(PKGDIRSETUP) && $(swig_and_compile_cpp))" + echo "$@ $(run_testcase)" %.ctest: $(setup) - $(PKGDIRSETUP) - +echo $@ (cd $(JAVA_PACKAGE) && $(swig_and_compile_c)) - $echo $@ (run_testcase) + +echo "$@ ($(PKGDIRSETUP) && $(swig_and_compile_c))" + echo "$@ $(run_testcase)" -%.multicpptest: +%.multicpptest: $(setup) - $(PKGDIRSETUP) - +echo $@ (cd $(JAVA_PACKAGE) && $(swig_and_compile_multi_cpp)) - $echo $@ (run_testcase) + +echo "$@ ($(PKGDIRSETUP) && $(swig_and_compile_multi_cpp))" + echo "$@ $(run_testcase)" # don't duplicate $(setup), just add explicit $(PKGDIRSETUP) # This doesn't work yet since for PKGPRAGMA test, PKGDIRSETUP deletes From 988952af6526c0ca8fa2fb20fc49d3155466e1fc Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Sat, 12 Jan 2013 00:48:49 -0600 Subject: [PATCH 0394/1160] Add test case for using nspace without -package. TODO: Fix Makefile.in to actually not use -package when invoking swig. --- Examples/test-suite/java/Makefile.in | 1 + .../test-suite/java_nspacewithoutpackage.i | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 Examples/test-suite/java_nspacewithoutpackage.i diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 11d7fd3ef..df097c61b 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -32,6 +32,7 @@ CPP_TEST_CASES_PKGOPT = \ java_lib_arrays_dimensionless \ java_lib_various \ java_jnitypes \ + java_nspacewithoutpackage \ java_pgcpp \ java_pragmas \ java_prepost \ diff --git a/Examples/test-suite/java_nspacewithoutpackage.i b/Examples/test-suite/java_nspacewithoutpackage.i new file mode 100644 index 000000000..4fa1a951f --- /dev/null +++ b/Examples/test-suite/java_nspacewithoutpackage.i @@ -0,0 +1,34 @@ +%module java_nspacewithoutpackage + +%pragma(java) jniclasspackage="PragmaDefinedPackage" + +SWIG_JAVABODY_PROXY(public, public, SWIGTYPE) +SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE) + +%include + +%nspace TopLevel::Foo; +%nspace TopLevel::Bar; + +%{ + #include +%} + +%inline %{ + +namespace TopLevel +{ + class Foo { + public: + virtual ~Foo() {} + virtual std::string ping() { return "TopLevel::Foo::ping()"; } + }; + + class Bar { + public: + virtual ~Bar() {} + virtual std::string pong() { return "TopLevel::Bar::pong()"; } + }; +} + +%} \ No newline at end of file From 862d27f05a6b768ed37203bd7447b02e419d834c Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Sat, 12 Jan 2013 00:50:23 -0600 Subject: [PATCH 0395/1160] Fix issue of package directory not being created when using jniclasspackage pragma. General cleanup of implementation. --- Source/Modules/java.cxx | 85 ++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index e9b6f813c..f5deecb27 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -160,6 +160,30 @@ public: director_language = 1; } + /* ----------------------------------------------------------------------------- + * constructIntermediateClassName() + * + * Construct the fully qualified name of the intermidiate class and set + * the full_imclass_name attribute accordingly. + * ----------------------------------------------------------------------------- */ + void constructIntermediateClassName(Node *n) { + String *nspace = Getattr(n, "sym:nspace"); + + if (imclass_class_package && package) + full_imclass_name = NewStringf("%s.%s.%s", package, imclass_class_package, imclass_name); + else if (package && nspace) + full_imclass_name = NewStringf("%s.%s", package, imclass_name); + else if (imclass_class_package) + full_imclass_name = NewStringf("%s.%s", imclass_class_package, imclass_name); + else + full_imclass_name = NewStringf("%s", imclass_name); + + if (nspace && !package) { + String *name = Getattr(n, "name") ? Getattr(n, "name") : NewString(""); + Swig_warning(WARN_JAVA_NSPACE_WITHOUT_PACKAGE, Getfile(n), Getline(n), "The nspace feature is used on '%s' without a package is specified with -package - This may result in generated code that does not compile as Java does not support types declared in a named package accessing types declared in an unnamed package.\n", name); + } + } + /* ----------------------------------------------------------------------------- * getProxyName() * @@ -365,7 +389,7 @@ public: proxy_class_code = NewString(""); module_class_constants_code = NewString(""); imclass_baseclass = NewString(""); - imclass_class_package = NewString(""); + imclass_class_package = NULL; imclass_interfaces = NewString(""); imclass_class_modifiers = NewString(""); module_class_code = NewString(""); @@ -446,7 +470,7 @@ public: } // Generate the intermediary class { - String *filen = NewStringf("%s%s/%s.java", SWIG_output_directory(), imclass_class_package, imclass_name); + String *filen = NewStringf("%s%s.java", outputDirectory(imclass_class_package), imclass_name); File *f_im = NewFile(filen, "w", SWIG_output_files()); if (!f_im) { FileErrorDisplay(filen); @@ -459,7 +483,9 @@ public: // Start writing out the intermediary class file emitBanner(f_im); - if (Len(imclass_class_package)) + if (imclass_class_package && package) + Printf(f_im, "package %s.%s;", package, imclass_class_package); + else if (imclass_class_package) Printf(f_im, "package %s;", imclass_class_package); else if (package) Printf(f_im, "package %s;\n", package); @@ -1182,19 +1208,9 @@ public: 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 - assert(!full_imclass_name); - - if (!nspace) { - full_imclass_name = NewStringf("%s", imclass_name); - } else { - if (package) { - full_imclass_name = NewStringf("%s.%s", package, imclass_name); - } else { - String *name = Getattr(n, "name") ? Getattr(n, "name") : NewString(""); - Swig_warning(WARN_JAVA_NSPACE_WITHOUT_PACKAGE, Getfile(n), Getline(n), "The nspace feature is used on '%s' without a package is specified with -package - This may result in generated code that does not compile as Java does not support types declared in a named package accessing types declared in an unnamed package.\n", name); - } - } + // Global enums / enums in a namespace + assert(!full_imclass_name); + constructIntermediateClassName(n); } enum_code = NewString(""); @@ -1899,38 +1915,35 @@ public: if (proxy_flag) { proxy_class_name = NewString(Getattr(n, "sym:name")); String *nspace = getNSpace(); + constructIntermediateClassName(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); - } + full_proxy_class_name = NewStringf("%s", proxy_class_name); - 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); - } + 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 (package) { - full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name); - full_imclass_name = NewStringf("%s.%s", package, imclass_name); - } else { - String *name = Getattr(n, "name") ? Getattr(n, "name") : NewString(""); - Swig_warning(WARN_JAVA_NSPACE_WITHOUT_PACKAGE, Getfile(n), Getline(n), "The nspace feature is used on '%s' without a package is specified with -package - This may result in generated code that does not compile as Java does not support types declared in a named package accessing types declared in an unnamed package.\n", name); - } + if (package) { + full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name); + } } if (!addSymbol(proxy_class_name, n, nspace)) - return SWIG_ERROR; + return SWIG_ERROR; 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); - SWIG_exit(EXIT_FAILURE); + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); } Append(filenames_list, Copy(filen)); Delete(filen); From 28da117186d198d699d399bedfbb7f49198f6280 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Sat, 12 Jan 2013 01:48:13 -0600 Subject: [PATCH 0396/1160] Modify java test-suite Makefile to run the java_nspacewithoutpackage test without the -package option. --- Examples/test-suite/java/Makefile.in | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index df097c61b..29ba2f36b 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -16,7 +16,7 @@ C_TEST_CASES = \ java_lib_various CPP_TEST_CASES_PKGPRAGMA = \ - internal_pkgpragma_test + java_nspacewithoutpackage CPP_TEST_CASES_PKGOPT = \ @@ -32,7 +32,6 @@ CPP_TEST_CASES_PKGOPT = \ java_lib_arrays_dimensionless \ java_lib_various \ java_jnitypes \ - java_nspacewithoutpackage \ java_pgcpp \ java_pragmas \ java_prepost \ @@ -55,12 +54,14 @@ ALL_PKGPRAGMA := $(filter $(CPP_TEST_CASES_PKGPRAGMA:=.cpptest),$(NOT_BROKEN_TES $(ALL_PKGOPT): SWIGOPT += -package $(JAVA_PACKAGE) $(ALL_PKGOPT): PKGDIRSETUP = [ -d "$(JAVA_PACKAGE)" ] || mkdir -p "$(JAVA_PACKAGE)" && cd "$(JAVA_PACKAGE)" -# Set JAVA_PACKAGE differently for the tests using internally coded pragma javapackage +# Set JNI_PACKAGE for the tests using internally coded pragma javapackage # (and must match what is in the test .i file) # Make sure that the pragma dir DOES NOT exist (since test should create) # This may not find all the generated java to compile... -$(ALL_PKGPRAGMA): JAVA_PACKAGE = MyExplicitPragmaJavaPackage -$(ALL_PKGPRAGMA): PKGDIRSETUP = rm -rf $(JAVA_PACKAGE) +# NOTE: The variable JAVA_PACKAGE has nothing to do wih a package in this case, but +# needs to remain named the same so other targets work +$(ALL_PKGPRAGMA): JNI_PACKAGE = PragmaDefinedPackage +$(ALL_PKGPRAGMA): PKGDIRSETUP = [ -d "$(JAVA_PACKAGE)" ] || mkdir -p "$(JAVA_PACKAGE)" && cd "$(JAVA_PACKAGE)" &&rm -rf $(JAVA_PACKAGE)/$(JNI_PACKAGE) # Custom tests - tests with additional commandline options nspace.%: JAVA_PACKAGE = $*Package @@ -71,18 +72,18 @@ director_nspace_director_name_collision.%: JAVA_PACKAGE = $*Package # Rules for the different types of tests %.cpptest: $(setup) - +echo "$@ ($(PKGDIRSETUP) && $(swig_and_compile_cpp))" - echo "$@ $(run_testcase)" + +($(PKGDIRSETUP) && $(swig_and_compile_cpp)) + $(run_testcase) %.ctest: $(setup) - +echo "$@ ($(PKGDIRSETUP) && $(swig_and_compile_c))" - echo "$@ $(run_testcase)" + +($(PKGDIRSETUP) && $(swig_and_compile_c)) + $(run_testcase) %.multicpptest: $(setup) - +echo "$@ ($(PKGDIRSETUP) && $(swig_and_compile_multi_cpp))" - echo "$@ $(run_testcase)" + +($(PKGDIRSETUP) && $(swig_and_compile_multi_cpp)) + $(run_testcase) # don't duplicate $(setup), just add explicit $(PKGDIRSETUP) # This doesn't work yet since for PKGPRAGMA test, PKGDIRSETUP deletes From 43ad8e611aca7364d4c37ce2dc24fcfd65fdcbf3 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Sat, 12 Jan 2013 01:55:11 -0600 Subject: [PATCH 0397/1160] Remove comment about previously outstanding TODO that has been cleaned up. --- Examples/test-suite/java/Makefile.in | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 29ba2f36b..72fad777d 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -85,10 +85,6 @@ director_nspace_director_name_collision.%: JAVA_PACKAGE = $*Package +($(PKGDIRSETUP) && $(swig_and_compile_multi_cpp)) $(run_testcase) -# don't duplicate $(setup), just add explicit $(PKGDIRSETUP) -# This doesn't work yet since for PKGPRAGMA test, PKGDIRSETUP deletes -# JAVA_PACKAGE, but next line tries to cd there. - # 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. From 7104b20d0d805972d59c5acc89dfb6d42b2e7ffa Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Sat, 12 Jan 2013 02:10:27 -0600 Subject: [PATCH 0398/1160] imclass_class_package variable names seems to have class in it one too many times... renamed to imclass_package. --- Source/Modules/java.cxx | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index f5deecb27..df1f6dd78 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -67,7 +67,7 @@ class JAVA:public Language { String *imclass_imports; //intermediary class imports from %pragma String *module_imports; //module imports from %pragma String *imclass_baseclass; //inheritance for intermediary class class from %pragma - String *imclass_class_package; //package in which to generate the jni class + String *imclass_package; //package in which to generate the jni class String *module_baseclass; //inheritance for module class from %pragma String *imclass_interfaces; //interfaces for intermediary class class from %pragma String *module_interfaces; //interfaces for module class from %pragma @@ -169,12 +169,12 @@ public: void constructIntermediateClassName(Node *n) { String *nspace = Getattr(n, "sym:nspace"); - if (imclass_class_package && package) - full_imclass_name = NewStringf("%s.%s.%s", package, imclass_class_package, imclass_name); + if (imclass_package && package) + full_imclass_name = NewStringf("%s.%s.%s", package, imclass_package, imclass_name); else if (package && nspace) full_imclass_name = NewStringf("%s.%s", package, imclass_name); - else if (imclass_class_package) - full_imclass_name = NewStringf("%s.%s", imclass_class_package, imclass_name); + else if (imclass_package) + full_imclass_name = NewStringf("%s.%s", imclass_package, imclass_name); else full_imclass_name = NewStringf("%s", imclass_name); @@ -389,7 +389,7 @@ public: proxy_class_code = NewString(""); module_class_constants_code = NewString(""); imclass_baseclass = NewString(""); - imclass_class_package = NULL; + imclass_package = NULL; imclass_interfaces = NewString(""); imclass_class_modifiers = NewString(""); module_class_code = NewString(""); @@ -470,7 +470,7 @@ public: } // Generate the intermediary class { - String *filen = NewStringf("%s%s.java", outputDirectory(imclass_class_package), imclass_name); + String *filen = NewStringf("%s%s.java", outputDirectory(imclass_package), imclass_name); File *f_im = NewFile(filen, "w", SWIG_output_files()); if (!f_im) { FileErrorDisplay(filen); @@ -483,10 +483,10 @@ public: // Start writing out the intermediary class file emitBanner(f_im); - if (imclass_class_package && package) - Printf(f_im, "package %s.%s;", package, imclass_class_package); - else if (imclass_class_package) - Printf(f_im, "package %s;", imclass_class_package); + if (imclass_package && package) + Printf(f_im, "package %s.%s;", package, imclass_package); + else if (imclass_package) + Printf(f_im, "package %s;", imclass_package); else if (package) Printf(f_im, "package %s;\n", package); @@ -655,8 +655,8 @@ public: module_class_constants_code = NULL; Delete(imclass_baseclass); imclass_baseclass = NULL; - Delete(imclass_class_package); - imclass_class_package = NULL; + Delete(imclass_package); + imclass_package = NULL; Delete(imclass_interfaces); imclass_interfaces = NULL; Delete(imclass_class_modifiers); @@ -1625,9 +1625,9 @@ public: Delete(imclass_baseclass); imclass_baseclass = Copy(strvalue); } else if (Strcmp(code, "jniclasspackage") == 0) { - Delete(imclass_class_package); - imclass_class_package = Copy(strvalue); - String *imclass_class_package_jniname = makeValidJniName(imclass_class_package); + Delete(imclass_package); + imclass_package = Copy(strvalue); + String *imclass_class_package_jniname = makeValidJniName(imclass_package); Printv(jnipackage, imclass_class_package_jniname, NIL); Delete(imclass_class_package_jniname); Replaceall(jnipackage, NSPACE_SEPARATOR, "_"); From 20ce05f9548e1bc69bdd2a45f3032e45288f8075 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Mon, 14 Jan 2013 13:11:42 -0600 Subject: [PATCH 0399/1160] Update documentation regarding the use of the nspace feature in java without the -package commandline option. --- Doc/Manual/Java.html | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 858342c43..e8777fbe3 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -1923,19 +1923,10 @@ The default behaviour described above can be improved via the -

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

    If the resulting use of the nspace feature and hence packages results in a proxy class in one package deriving or using a proxy class from another package, you will need to open up the visibility for the pointer constructor and getCPtr method from the default 'protected' to 'public' with the SWIG_JAVABODY_PROXY macro. See Java code typemaps. @@ -2225,6 +2216,9 @@ The intermediary JNI class can be tailored through the use of pragmas, but is no jniclassbase Base class for the intermediary JNI class + + jniclasspackage Package in which to place the intermediary JNI class + jniclassclassmodifiers Class modifiers and class type for the intermediary JNI class From ace33bbf41e3cd40bf252fefb236883af6d8be2e Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Mon, 14 Jan 2013 16:31:53 -0600 Subject: [PATCH 0400/1160] Fix issue with using directors with the nspace feature without the -package commandline argument. --- Source/Modules/java.cxx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index df1f6dd78..18043e1a4 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1930,9 +1930,10 @@ public: SWIG_exit(EXIT_FAILURE); } } else { - if (package) { + if (package) full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name); - } + else + full_proxy_class_name = NewStringf("%s.%s", nspace, proxy_class_name); } if (!addSymbol(proxy_class_name, n, nspace)) @@ -3592,8 +3593,11 @@ public: String *qualified_classname = Copy(classname); String *nspace = getNSpace(); - if (nspace) + if (nspace && package) Insert(qualified_classname, 0, NewStringf("%s.%s.", package, nspace)); + else if(nspace) + Insert(qualified_classname, 0, NewStringf("%s.", nspace)); + // Kludge Alert: functionWrapper sets sym:overload properly, but it // isn't at this point, so we have to manufacture it ourselves. At least From f7e27ec7a966e05c6f8bc4336f0270f61c12b0d7 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Tue, 15 Jan 2013 13:09:01 -0600 Subject: [PATCH 0401/1160] Fix issue with using directors with the nspace feature without the -package commandline argument. --- Source/Modules/java.cxx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 18043e1a4..5cb194605 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -4294,19 +4294,19 @@ public: Wrapper *w = NewWrapper(); - if (Len(package_path) > 0) - if (Len(getNSpace()) > 0) { - internal_classname = NewStringf("%s/%s/%s", package_path, getNSpace(), classname); - - // If the namespace is multiple levels, the result of getNSpace() will have inserted - // .'s to delimit namespaces, so we need to replace those with /'s - Replace(internal_classname, ".", "/", DOH_REPLACE_ANY); - } - else - internal_classname = NewStringf("%s/%s", package_path, classname); + if (Len(package_path) > 0 && Len(getNSpace()) > 0) + internal_classname = NewStringf("%s/%s/%s", package_path, getNSpace(), classname); + else if (Len(package_path) > 0) + internal_classname = NewStringf("%s/%s", package_path, classname); + else if (Len(getNSpace()) > 0) + internal_classname = NewStringf("%s/%s", getNSpace(), classname); else internal_classname = NewStringf("%s", classname); + // If the namespace is multiple levels, the result of getNSpace() will have inserted + // .'s to delimit namespaces, so we need to replace those with /'s + Replace(internal_classname, ".", "/", DOH_REPLACE_ANY); + Wrapper_add_localv(w, "baseclass", "static jclass baseclass", "= 0", NIL); Printf(w->def, "void %s::swig_connect_director(JNIEnv *jenv, jobject jself, jclass jcls, bool swig_mem_own, bool weak_global) {", director_classname); From 9318ece01ffa6d1de64e5930217ef42de24cc411 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Tue, 15 Jan 2013 13:11:21 -0600 Subject: [PATCH 0402/1160] Use NSPACE_SEPARATOR rather than literal. --- Source/Modules/java.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 5cb194605..03dae577d 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -4305,7 +4305,7 @@ public: // If the namespace is multiple levels, the result of getNSpace() will have inserted // .'s to delimit namespaces, so we need to replace those with /'s - Replace(internal_classname, ".", "/", DOH_REPLACE_ANY); + Replace(internal_classname, NSPACE_SEPARATOR, "/", DOH_REPLACE_ANY); Wrapper_add_localv(w, "baseclass", "static jclass baseclass", "= 0", NIL); Printf(w->def, "void %s::swig_connect_director(JNIEnv *jenv, jobject jself, jclass jcls, bool swig_mem_own, bool weak_global) {", director_classname); From 0e32be246500e78089327f323794f1e5d7af879b Mon Sep 17 00:00:00 2001 From: Tristan Carel Date: Thu, 17 Jan 2013 16:54:54 +0100 Subject: [PATCH 0403/1160] Prefer $MAKE if specified in environment Sometimes gmake is the only one available. --- Tools/pcre-build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tools/pcre-build.sh b/Tools/pcre-build.sh index 68ffe0b03..4af7deca3 100755 --- a/Tools/pcre-build.sh +++ b/Tools/pcre-build.sh @@ -48,8 +48,8 @@ echo "Configuring PCRE in directory: pcre" mv $pcre_dir pcre || bail "Could not create pcre directory" cd pcre && ./configure --prefix=$pcre_install_dir --disable-shared $* || bail "PCRE configure failed" echo "Building PCRE..." -make -s || bail "Could not build PCRE" +${MAKE:make} -s || bail "Could not build PCRE" echo "Installing PCRE locally to $pcre_install_dir..." -make -s install || bail "Could not install PCRE" +${MAKE:make} -s install || bail "Could not install PCRE" echo "" echo "The SWIG configure script can now be run, whereupon PCRE will automatically be detected and used from $pcre_install_dir/bin/pcre-config." From 219555ebea24513fd1385805cb4a7d7546595c7b Mon Sep 17 00:00:00 2001 From: Tristan Carel Date: Thu, 17 Jan 2013 19:07:30 +0100 Subject: [PATCH 0404/1160] use executables path set at ./configure time --- Examples/test-suite/java/Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index f8da8e6cc..24f6a213c 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -3,8 +3,8 @@ ####################################################################### LANGUAGE = java -JAVA = java -JAVAC = javac +JAVA = @JAVA@ +JAVAC = @JAVAC@ JAVAFLAGS = -Xcheck:jni SCRIPTSUFFIX = _runme.java srcdir = @srcdir@ From 55f4bfec8e3ce00207c5d1e8bec2ac48b8ac62f8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 18 Jan 2013 23:47:23 +0000 Subject: [PATCH 0405/1160] Revert Java test-suite makefile to adf51b5249e6b1a7a11fc3adcc01ed196d6c9135 --- Examples/test-suite/java/Makefile.in | 48 +++++++++++----------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 72fad777d..f8da8e6cc 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -15,11 +15,7 @@ C_TEST_CASES = \ java_lib_arrays \ java_lib_various -CPP_TEST_CASES_PKGPRAGMA = \ - java_nspacewithoutpackage - - -CPP_TEST_CASES_PKGOPT = \ +CPP_TEST_CASES = \ enum_thorough_proper \ enum_thorough_simple \ enum_thorough_typeunsafe \ @@ -40,28 +36,11 @@ CPP_TEST_CASES_PKGOPT = \ java_typemaps_typewrapper # li_boost_intrusive_ptr -CPP_TEST_CASES = $(CPP_TEST_CASES_PKGOPT) $(CPP_TEST_CASES_PKGPRAGMA) include $(srcdir)/../common.mk # Overridden variables here JAVA_PACKAGE = $* - -ALL_PKGOPT := $(filter-out $(CPP_TEST_CASES_PKGPRAGMA:=.cpptest),$(NOT_BROKEN_TEST_CASES)) -ALL_PKGPRAGMA := $(filter $(CPP_TEST_CASES_PKGPRAGMA:=.cpptest),$(NOT_BROKEN_TEST_CASES)) - -# Add '-package' swigopt for ALL tests except for CPP_TEST_CASES_PKGPRAGMA -# PKGDIRSETUP should leave 0 exitcode when successful -$(ALL_PKGOPT): SWIGOPT += -package $(JAVA_PACKAGE) -$(ALL_PKGOPT): PKGDIRSETUP = [ -d "$(JAVA_PACKAGE)" ] || mkdir -p "$(JAVA_PACKAGE)" && cd "$(JAVA_PACKAGE)" - -# Set JNI_PACKAGE for the tests using internally coded pragma javapackage -# (and must match what is in the test .i file) -# Make sure that the pragma dir DOES NOT exist (since test should create) -# This may not find all the generated java to compile... -# NOTE: The variable JAVA_PACKAGE has nothing to do wih a package in this case, but -# needs to remain named the same so other targets work -$(ALL_PKGPRAGMA): JNI_PACKAGE = PragmaDefinedPackage -$(ALL_PKGPRAGMA): PKGDIRSETUP = [ -d "$(JAVA_PACKAGE)" ] || mkdir -p "$(JAVA_PACKAGE)" && cd "$(JAVA_PACKAGE)" &&rm -rf $(JAVA_PACKAGE)/$(JNI_PACKAGE) +SWIGOPT += -package $(JAVA_PACKAGE) # Custom tests - tests with additional commandline options nspace.%: JAVA_PACKAGE = $*Package @@ -70,22 +49,33 @@ director_nspace.%: JAVA_PACKAGE = $*Package director_nspace_director_name_collision.%: JAVA_PACKAGE = $*Package # Rules for the different types of tests -%.cpptest: +%.cpptest: $(setup) - +($(PKGDIRSETUP) && $(swig_and_compile_cpp)) + +(cd $(JAVA_PACKAGE) && $(swig_and_compile_cpp)) $(run_testcase) %.ctest: $(setup) - +($(PKGDIRSETUP) && $(swig_and_compile_c)) + +(cd $(JAVA_PACKAGE) && $(swig_and_compile_c)) $(run_testcase) -%.multicpptest: +%.multicpptest: $(setup) - +($(PKGDIRSETUP) && $(swig_and_compile_multi_cpp)) + +(cd $(JAVA_PACKAGE) && $(swig_and_compile_multi_cpp)) $(run_testcase) -# COMPILES java files then runs the testcase. A testcase is only run if +# Makes a directory for the testcase if it does not exist +setup = \ + if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ + echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \ + else \ + echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \ + fi; \ + 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 = \ From 95b176b6b300114abd2514599d8fc71de40e3ac7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 18 Jan 2013 23:52:48 +0000 Subject: [PATCH 0406/1160] Java test-suite change to make it possible to not specify a namespace. Re-add java_nspacewithoutpackage testcase --- Examples/test-suite/java/Makefile.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index f8da8e6cc..1ada28e84 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -28,6 +28,7 @@ CPP_TEST_CASES = \ java_lib_arrays_dimensionless \ java_lib_various \ java_jnitypes \ + java_nspacewithoutpackage \ java_pgcpp \ java_pragmas \ java_prepost \ @@ -40,9 +41,11 @@ include $(srcdir)/../common.mk # Overridden variables here JAVA_PACKAGE = $* -SWIGOPT += -package $(JAVA_PACKAGE) +JAVA_PACKAGEOPT = -package $(JAVA_PACKAGE) +SWIGOPT += $(JAVA_PACKAGEOPT) # Custom tests - tests with additional commandline options +java_nspacewithoutpackage.%: JAVA_PACKAGEOPT = nspace.%: JAVA_PACKAGE = $*Package nspace_extend.%: JAVA_PACKAGE = $*Package director_nspace.%: JAVA_PACKAGE = $*Package From 36ce54da8d46b340947940c202dd87a343153b63 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 19 Jan 2013 00:34:05 +0000 Subject: [PATCH 0407/1160] Whitespace fixup --- Source/Modules/java.cxx | 68 ++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 03dae577d..b86dd3259 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -67,7 +67,7 @@ class JAVA:public Language { String *imclass_imports; //intermediary class imports from %pragma String *module_imports; //module imports from %pragma String *imclass_baseclass; //inheritance for intermediary class class from %pragma - String *imclass_package; //package in which to generate the jni class + String *imclass_package; //package in which to generate the jni class String *module_baseclass; //inheritance for module class from %pragma String *imclass_interfaces; //interfaces for intermediary class class from %pragma String *module_interfaces; //interfaces for module class from %pragma @@ -1208,9 +1208,9 @@ public: 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 - assert(!full_imclass_name); - constructIntermediateClassName(n); + // Global enums / enums in a namespace + assert(!full_imclass_name); + constructIntermediateClassName(n); } enum_code = NewString(""); @@ -1625,24 +1625,24 @@ public: Delete(imclass_baseclass); imclass_baseclass = Copy(strvalue); } else if (Strcmp(code, "jniclasspackage") == 0) { - Delete(imclass_package); - imclass_package = Copy(strvalue); - String *imclass_class_package_jniname = makeValidJniName(imclass_package); - Printv(jnipackage, imclass_class_package_jniname, NIL); - Delete(imclass_class_package_jniname); - Replaceall(jnipackage, NSPACE_SEPARATOR, "_"); - Append(jnipackage, "_"); + Delete(imclass_package); + imclass_package = Copy(strvalue); + String *imclass_class_package_jniname = makeValidJniName(imclass_package); + Printv(jnipackage, imclass_class_package_jniname, NIL); + Delete(imclass_class_package_jniname); + Replaceall(jnipackage, NSPACE_SEPARATOR, "_"); + Append(jnipackage, "_"); - String *wrapper_name = NewString(""); - String *imclass_class_jniname = makeValidJniName(imclass_name); - Printf(wrapper_name, "Java_%s%s_%%f", jnipackage, imclass_class_jniname); - Delete(imclass_class_jniname); + String *wrapper_name = NewString(""); + String *imclass_class_jniname = makeValidJniName(imclass_name); + Printf(wrapper_name, "Java_%s%s_%%f", jnipackage, imclass_class_jniname); + Delete(imclass_class_jniname); - Swig_name_unregister("wrapper"); - Swig_name_register("wrapper", Char(wrapper_name)); + Swig_name_unregister("wrapper"); + Swig_name_register("wrapper", Char(wrapper_name)); - Delete(wrapper_name); - } else if (Strcmp(code, "jniclassclassmodifiers") == 0) { + Delete(wrapper_name); + } else if (Strcmp(code, "jniclassclassmodifiers") == 0) { Delete(imclass_class_modifiers); imclass_class_modifiers = Copy(strvalue); } else if (Strcmp(code, "jniclasscode") == 0) { @@ -1918,22 +1918,22 @@ public: constructIntermediateClassName(n); if (!nspace) { - full_proxy_class_name = NewStringf("%s", proxy_class_name); + full_proxy_class_name = NewStringf("%s", proxy_class_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, 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); - } + 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 (package) - full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name); - else - full_proxy_class_name = NewStringf("%s.%s", nspace, proxy_class_name); + if (package) + full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name); + else + full_proxy_class_name = NewStringf("%s.%s", nspace, proxy_class_name); } if (!addSymbol(proxy_class_name, n, nspace)) @@ -1943,8 +1943,8 @@ public: String *filen = NewStringf("%s%s.java", output_directory, proxy_class_name); f_proxy = NewFile(filen, "w", SWIG_output_files()); if (!f_proxy) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); } Append(filenames_list, Copy(filen)); Delete(filen); From bd3e93ae61fb74d5a338eac884c1e61eb64d6234 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 19 Jan 2013 00:58:56 +0000 Subject: [PATCH 0408/1160] Tidy up last few commits for Java new jniclasspackage pragma --- CHANGES.current | 5 +++++ Doc/Manual/Java.html | 16 +++++++++++++++- Doc/Manual/Warnings.html | 2 ++ Source/Modules/java.cxx | 12 +++++++----- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index f8391a635..ad2f1e764 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.10 (in progress) ============================ +2013-01-18: Brant Kyser + [Java] Patch #15 - Allow the use of the nspace feature without the -package commandline option. + This works as long and the new jniclasspackage pragma is used to place the JNI intermediate class + into a package and the nspace feature is used to place all exposed types into a package. + 2013-01-15: wsfulton Fix Visual Studio examples to work when SWIG is unzipped into a directory containing spaces. diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index e8777fbe3..8245d46eb 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -1924,7 +1924,21 @@ 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 generally should 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. If you don't specify a package, you will get a warning 186. If it is undesirable to have a single top level package, the nspace feature may be used without the -package commandline option (and the resulting warning ignored) if all of the types exposed using Swig are placed in a package using the nspace feature and the jniclasspackage pragma is used to specify a package for the JNI intermediate class. +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 warning: +

    + +
    +
    +example.i:16: Warning 826: The nspace feature is used on 'MyWorld::Material::Color' without -package. The generated code 
    +may not compile as Java does not support types declared in a named package accessing types declared in an unnamed package.
    +
    +
    + +

    +If it is undesirable to have a single top level package, the nspace feature may be used without the -package commandline option +(and the resulting warning ignored) if all of the types exposed using SWIG are placed in a package using the nspace feature and the +'jniclasspackage' pragma is used to specify a package for the JNI intermediary class.

    diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index 2a3ce560d..1571146f1 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -551,6 +551,8 @@ example.i(4) : Syntax error in input.

  • 822. Covariant return types not supported in Java. Proxy method will return basetype (Java).
  • 823. No javaconstruct typemap defined for type (Java).
  • 824. Missing JNI descriptor in directorin typemap defined for type (Java). +
  • 825. "directorconnect" attribute missing in type "javaconstruct" typemap. (Java). +
  • 826. The nspace feature is used on 'type' without -package. The generated code may not compile as Java does not support types declared in a named package accessing types declared in an unnamed package. (Java).
      diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index b86dd3259..5b861ee0f 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -67,7 +67,7 @@ class JAVA:public Language { String *imclass_imports; //intermediary class imports from %pragma String *module_imports; //module imports from %pragma String *imclass_baseclass; //inheritance for intermediary class class from %pragma - String *imclass_package; //package in which to generate the jni class + String *imclass_package; //package in which to generate the intermediary class String *module_baseclass; //inheritance for module class from %pragma String *imclass_interfaces; //interfaces for intermediary class class from %pragma String *module_interfaces; //interfaces for module class from %pragma @@ -180,7 +180,9 @@ public: if (nspace && !package) { String *name = Getattr(n, "name") ? Getattr(n, "name") : NewString(""); - Swig_warning(WARN_JAVA_NSPACE_WITHOUT_PACKAGE, Getfile(n), Getline(n), "The nspace feature is used on '%s' without a package is specified with -package - This may result in generated code that does not compile as Java does not support types declared in a named package accessing types declared in an unnamed package.\n", name); + Swig_warning(WARN_JAVA_NSPACE_WITHOUT_PACKAGE, Getfile(n), Getline(n), + "The nspace feature is used on '%s' without -package. " + "The generated code may not compile as Java does not support types declared in a named package accessing types declared in an unnamed package.\n", name); } } @@ -1595,8 +1597,8 @@ public: * pragmaDirective() * * Valid Pragmas: - * jniclassbase - base (extends) for the intermediary - * jniclasspackage - package in which to generate the jni class + * jniclassbase - base (extends) for the intermediary class + * jniclasspackage - package in which to generate the intermediary class * jniclassclassmodifiers - class modifiers for the intermediary class * jniclasscode - text (java code) is copied verbatim to the intermediary class * jniclassimports - import statements for the intermediary class @@ -1937,7 +1939,7 @@ public: } if (!addSymbol(proxy_class_name, n, nspace)) - return SWIG_ERROR; + return SWIG_ERROR; String *output_directory = outputDirectory(nspace); String *filen = NewStringf("%s%s.java", output_directory, proxy_class_name); From bda67e1d780b1d4363db058c294b5eb714f7bedd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 19 Jan 2013 01:06:01 +0000 Subject: [PATCH 0409/1160] Cosmetic makefile change --- Examples/test-suite/java/Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 1ada28e84..c62dfa595 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -25,10 +25,10 @@ CPP_TEST_CASES = \ java_director \ java_director_assumeoverride \ java_enums \ + java_jnitypes \ java_lib_arrays_dimensionless \ java_lib_various \ - java_jnitypes \ - java_nspacewithoutpackage \ + java_nspacewithoutpackage \ java_pgcpp \ java_pragmas \ java_prepost \ From 3654031d4f273caf5cb0338192b7563318b5236b Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Fri, 18 Jan 2013 15:06:15 -0600 Subject: [PATCH 0410/1160] Repair typo from previous commit. --- Source/Modules/java.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 5b861ee0f..987b6ddf6 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -2027,7 +2027,7 @@ public: Printf(dcast_wrap->code, " jobject jresult = (jobject) 0;\n"); Printf(dcast_wrap->code, " %s *obj = *((%s **)&jCPtrBase);\n", norm_name, norm_name); Printf(dcast_wrap->code, " if (obj) director = dynamic_cast(obj);\n"); - Printf(dcast_wrap->code, " if (director) jresult = director->swig_get_self);\n"); + Printf(dcast_wrap->code, " if (director) jresult = director->swig_get_self(jenv);\n"); Printf(dcast_wrap->code, " return jresult;\n"); Printf(dcast_wrap->code, "}\n"); From 751bedf5e5a95b104ca37a7baef71e188127016d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 19 Jan 2013 01:28:55 +0000 Subject: [PATCH 0411/1160] Suppress warning in testcase --- Examples/test-suite/java_nspacewithoutpackage.i | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/java_nspacewithoutpackage.i b/Examples/test-suite/java_nspacewithoutpackage.i index 4fa1a951f..24458ec36 100644 --- a/Examples/test-suite/java_nspacewithoutpackage.i +++ b/Examples/test-suite/java_nspacewithoutpackage.i @@ -1,5 +1,8 @@ %module java_nspacewithoutpackage +%warnfilter(SWIGWARN_JAVA_NSPACE_WITHOUT_PACKAGE) TopLevel::Foo; +%warnfilter(SWIGWARN_JAVA_NSPACE_WITHOUT_PACKAGE) TopLevel::Bar; + %pragma(java) jniclasspackage="PragmaDefinedPackage" SWIG_JAVABODY_PROXY(public, public, SWIGTYPE) @@ -31,4 +34,4 @@ namespace TopLevel }; } -%} \ No newline at end of file +%} From 7d800a655de565826fd2404fd11d85dccd9c11d1 Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Wed, 16 Jan 2013 08:01:27 +0400 Subject: [PATCH 0412/1160] Unicode literals --- Examples/test-suite/csharp_features.i | 4 ++ Source/CParse/cscanner.c | 14 +++++- Source/CParse/parser.y | 42 +++++++++++++++-- Source/Swig/cwrap.c | 2 +- Source/Swig/scanner.c | 68 ++++++++++++++++++++++++--- Source/Swig/stype.c | 11 ++++- Source/Swig/swig.h | 3 ++ Source/Swig/swigscan.h | 3 ++ Source/Swig/typesys.c | 4 ++ 9 files changed, 137 insertions(+), 14 deletions(-) diff --git a/Examples/test-suite/csharp_features.i b/Examples/test-suite/csharp_features.i index 578a56a10..f77e3fc9c 100644 --- a/Examples/test-suite/csharp_features.i +++ b/Examples/test-suite/csharp_features.i @@ -1,4 +1,5 @@ %module csharp_features +%include "wchar.i" // SWIG gets the method modifiers wrong occasionally, like with private inheritance, %csmethodmodifiers can fix this %csmethodmodifiers Derived::VirtualMethod() "public virtual" @@ -19,6 +20,9 @@ public: class MoreDerived : public Derived { public: int variable; + // test wide char literals support for C# module + void methodWithDefault1(const wchar_t* s = L"literal with escapes \x1234"){} + void methodWithDefault2(wchar_t c = L'\x1234'){} }; %} diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index 23152e884..14a4f4bd0 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -383,6 +383,10 @@ static int yylook(void) { case SWIG_TOKEN_STRING: yylval.id = Swig_copy_string(Char(Scanner_text(scan))); return STRING; + + case SWIG_TOKEN_WSTRING: + yylval.id = Swig_copy_string(Char(Scanner_text(scan))); + return WSTRING; case SWIG_TOKEN_CHAR: yylval.str = NewString(Scanner_text(scan)); @@ -391,7 +395,15 @@ static int yylook(void) { Printf(stdout,"%d\n", Len(Scanner_text(scan))); } return CHARCONST; - + + case SWIG_TOKEN_WCHAR: + yylval.str = NewString(Scanner_text(scan)); + if (Len(yylval.str) == 0) { + Swig_error(cparse_file, cparse_line, "Empty character constant\n"); + Printf(stdout,"%d\n", Len(Scanner_text(scan))); + } + return WCHARCONST; + /* Numbers */ case SWIG_TOKEN_INT: diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index d91b7adce..cd032eb00 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -13,8 +13,8 @@ * some point. Beware. * ----------------------------------------------------------------------------- */ +%expect 6 %{ - #define yylex yylex char cvsroot_parser_y[] = "$Id$"; @@ -1635,9 +1635,9 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %token ID %token HBLOCK %token POUND -%token STRING +%token STRING WSTRING %token INCLUDE IMPORT INSERT -%token CHARCONST +%token CHARCONST WCHARCONST %token NUM_INT NUM_FLOAT NUM_UNSIGNED NUM_LONG NUM_ULONG NUM_LONGLONG NUM_ULONGLONG NUM_BOOL %token TYPEDEF %token TYPE_INT TYPE_UNSIGNED TYPE_SHORT TYPE_LONG TYPE_FLOAT TYPE_DOUBLE TYPE_CHAR TYPE_WCHAR TYPE_VOID TYPE_SIGNED TYPE_BOOL TYPE_COMPLEX TYPE_TYPEDEF TYPE_RAW TYPE_NON_ISO_INT8 TYPE_NON_ISO_INT16 TYPE_NON_ISO_INT32 TYPE_NON_ISO_INT64 @@ -1728,7 +1728,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type abstract_declarator direct_abstract_declarator ctor_end; %type typemap_type; %type idcolon idcolontail idcolonnt idcolontailnt idtemplate stringbrace stringbracesemi; -%type string stringnum ; +%type string stringnum wstring; %type template_parms; %type cpp_end cpp_vend; %type rename_namewarn; @@ -6001,7 +6001,7 @@ definetype : { /* scanner_check_typedef(); */ } expr { $$ = $2; if ($$.type == T_STRING) { $$.rawval = NewStringf("\"%(escape)s\"",$$.val); - } else if ($$.type != T_CHAR) { + } else if ($$.type != T_CHAR && $$.type != T_WSTRING && $$.type != T_WCHAR) { $$.rawval = 0; } $$.bitfield = 0; @@ -6127,6 +6127,11 @@ valexpr : exprnum { $$ = $1; } $$.type = T_ULONG; } | exprcompound { $$ = $1; } + | wstring { + $$.val = NewString($1); + $$.rawval = NewStringf("L\"%s\"", $$.val); + $$.type = T_WSTRING; + } | CHARCONST { $$.val = NewString($1); if (Len($$.val)) { @@ -6139,6 +6144,18 @@ valexpr : exprnum { $$ = $1; } $$.throws = 0; $$.throwf = 0; } + | WCHARCONST { + $$.val = NewString($1); + if (Len($$.val)) { + $$.rawval = NewStringf("L\'%s\'", $$.val); + } else { + $$.rawval = NewString("L'\\0'"); + } + $$.type = T_WCHAR; + $$.bitfield = 0; + $$.throws = 0; + $$.throwf = 0; + } /* grouping */ | LPAREN expr RPAREN %prec CAST { @@ -6661,6 +6678,21 @@ string : string STRING { } | STRING { $$ = $1;} ; +/* Concatenated wide strings: L"str1" L"str2" */ +wstring : wstring WSTRING { + $$ = (char *) malloc(strlen($1)+strlen($2)+1); + strcpy($$,$1); + strcat($$,$2); + } +/* Concatenated wide string and normal string literal: L"str1" "str2" */ +/*not all the compilers support this concatenation mode, so perhaps better to postpone it*/ + /*| wstring STRING { here $2 comes unescaped, we have to escape it back first via NewStringf("%(escape)s)" + $$ = (char *) malloc(strlen($1)+strlen($2)+1); + strcpy($$,$1); + strcat($$,$2); + }*/ + | WSTRING { $$ = $1;} + ; stringbrace : string { $$ = NewString($1); diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 4a461fce8..d335bb0e9 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -274,7 +274,7 @@ int Swig_cargs(Wrapper *w, ParmList *p) { Delete(defname); Delete(defvalue); } - } else if (!pvalue && ((tycode == T_POINTER) || (tycode == T_STRING))) { + } else if (!pvalue && ((tycode == T_POINTER) || (tycode == T_STRING) || (tycode == T_WSTRING))) { pvalue = (String *) "0"; } if (!altty) { diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index 446a68eb7..c3562c7cc 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -509,7 +509,6 @@ static int look(Scanner * s) { state = 4; /* Possibly a SWIG directive */ /* Look for possible identifiers or unicode/delimiter strings */ - else if ((isalpha(c)) || (c == '_') || (s->idstart && strchr(s->idstart, c))) { state = 7; @@ -867,11 +866,15 @@ static int look(Scanner * s) { break; case 7: /* Identifier or true/false or unicode/custom delimiter string */ - if (c=='R') { /* Possibly CUSTOM DELIMITER string */ + if (c == 'R') { /* Possibly CUSTOM DELIMITER string */ state = 72; break; } - else if (c!='u' && c!='U' && c!='L') { /* Definitely an identifier */ + else if (c == 'L') { /* Probably identifier but may be a wide string literal */ + state = 77; + break; + } + else if (c != 'u' && c != 'U') { /* Definitely an identifier */ state = 70; break; } @@ -879,14 +882,14 @@ static int look(Scanner * s) { if ((c = nextchar(s)) == 0) { state = 76; } - else if (c=='\"') { /* Definitely u, U or L string */ + else if (c == '\"') { /* Definitely u, U or L string */ retract(s, 1); state = 1000; } - else if (c=='R') { /* Possibly CUSTOM DELIMITER u, U, L string */ + else if (c == 'R') { /* Possibly CUSTOM DELIMITER u, U, L string */ state = 73; } - else if (c=='8') { /* Possibly u8 string */ + else if (c == '8') { /* Possibly u8 string */ state = 71; } else { @@ -950,6 +953,59 @@ static int look(Scanner * s) { break; + case 77: /*identifier or wide string literal*/ + if ((c = nextchar(s)) == 0) + return SWIG_TOKEN_ID; + else if (c == '\"') { + s->start_line = s->line; + Clear(s->text); + state = 78; + } + else if (c == '\'') { + s->start_line = s->line; + Clear(s->text); + state = 79; + } + else if (isalnum(c) || (c == '_') || (c == '$')) + state = 7; + else { + retract(s, 1); + return SWIG_TOKEN_ID; + } + break; + + case 78: /* Processing a wide string literal*/ + if ((c = nextchar(s)) == 0) { + Swig_error(cparse_file, cparse_start_line, "Unterminated wide string\n"); + return SWIG_TOKEN_ERROR; + } + if (c == '\"') { + Delitem(s->text, DOH_END); + return SWIG_TOKEN_WSTRING; + } else if (c == '\\') { + if ((c = nextchar(s)) == 0) { + Swig_error(cparse_file, cparse_start_line, "Unterminated wide string\n"); + return SWIG_TOKEN_ERROR; + } + } + break; + + case 79: /* Processing a wide char literal */ + if ((c = nextchar(s)) == 0) { + Swig_error(cparse_file, cparse_start_line, "Unterminated character constant\n"); + return SWIG_TOKEN_ERROR; + } + if (c == '\'') { + Delitem(s->text, DOH_END); + return (SWIG_TOKEN_WCHAR); + } else if (c == '\\') { + if ((c = nextchar(s)) == 0) { + Swig_error(cparse_file, cparse_start_line, "Unterminated wide char literal\n"); + return SWIG_TOKEN_ERROR; + } + } + break; + case 75: /* Special identifier $ */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_DOLLAR; diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index 32946ead5..b63530b53 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -131,12 +131,21 @@ SwigType *NewSwigType(int t) { case T_UCHAR: return NewString("unsigned char"); break; - case T_STRING:{ + case T_STRING: { SwigType *t = NewString("char"); SwigType_add_pointer(t); return t; break; } + case T_WCHAR: + return NewString("wchar_t"); + break; + case T_WSTRING: { + SwigType *t = NewString("wchar_t"); + SwigType_add_pointer(t); + return t; + break; + } case T_LONGLONG: return NewString("long long"); break; diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index dc65d9b0d..dceb73753 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -100,6 +100,9 @@ extern "C" { #define T_SYMBOL 98 #define T_ERROR 99 +/* wide string literal, may contain escaped wide chars like \x1234 as well as normal escape sequences */ +#define T_WSTRING 39 + /* --- File interface --- */ diff --git a/Source/Swig/swigscan.h b/Source/Swig/swigscan.h index b07812fbe..ae2e9ea4d 100644 --- a/Source/Swig/swigscan.h +++ b/Source/Swig/swigscan.h @@ -67,6 +67,9 @@ extern void Scanner_freeze_line(Scanner *s, int val); #define SWIG_TOKEN_QUESTION 30 /* ? */ #define SWIG_TOKEN_COMMENT 31 /* C or C++ comment */ #define SWIG_TOKEN_BOOL 32 /* true or false */ +#define SWIG_TOKEN_WSTRING 33 /* L"str" */ +#define SWIG_TOKEN_WCHAR 34 /* L'c' */ + #define SWIG_TOKEN_ILLEGAL 99 #define SWIG_TOKEN_ERROR -1 diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index a72ce5198..2de9bcb1d 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -1194,6 +1194,8 @@ int SwigType_type(SwigType *t) { if (strncmp(c, "p.", 2) == 0) { if (SwigType_type(c + 2) == T_CHAR) return T_STRING; + else if (SwigType_type(c + 2) == T_WCHAR) + return T_WSTRING; else return T_POINTER; } @@ -1236,6 +1238,8 @@ int SwigType_type(SwigType *t) { return T_SCHAR; if (strcmp(c, "unsigned char") == 0) return T_UCHAR; + if (strcmp(c, "wchar_t") == 0) + return T_WCHAR; if (strcmp(c, "float") == 0) return T_FLOAT; if (strcmp(c, "double") == 0) From 144e2ab7b4ea8fb243ae8fb38c6e1aa7ee89cadc Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 21 Jan 2013 19:42:44 +0000 Subject: [PATCH 0413/1160] Fixes to previous (unicode literals) commit --- Source/Swig/swig.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index dceb73753..0b3edf17e 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -97,11 +97,11 @@ extern "C" { #define T_MPOINTER 38 #define T_VARARGS 39 #define T_RVALUE_REFERENCE 40 +#define T_WSTRING 41 + #define T_SYMBOL 98 #define T_ERROR 99 -/* wide string literal, may contain escaped wide chars like \x1234 as well as normal escape sequences */ -#define T_WSTRING 39 /* --- File interface --- */ From 4b869de2e87e78a04079d5bf6d0db7087501cc5a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 21 Jan 2013 19:43:14 +0000 Subject: [PATCH 0414/1160] Cosmetic changes to previous (unicode literals) commit --- Source/Swig/scanner.c | 106 +++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index c3562c7cc..6389cc988 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -953,59 +953,6 @@ static int look(Scanner * s) { break; - case 77: /*identifier or wide string literal*/ - if ((c = nextchar(s)) == 0) - return SWIG_TOKEN_ID; - else if (c == '\"') { - s->start_line = s->line; - Clear(s->text); - state = 78; - } - else if (c == '\'') { - s->start_line = s->line; - Clear(s->text); - state = 79; - } - else if (isalnum(c) || (c == '_') || (c == '$')) - state = 7; - else { - retract(s, 1); - return SWIG_TOKEN_ID; - } - break; - - case 78: /* Processing a wide string literal*/ - if ((c = nextchar(s)) == 0) { - Swig_error(cparse_file, cparse_start_line, "Unterminated wide string\n"); - return SWIG_TOKEN_ERROR; - } - if (c == '\"') { - Delitem(s->text, DOH_END); - return SWIG_TOKEN_WSTRING; - } else if (c == '\\') { - if ((c = nextchar(s)) == 0) { - Swig_error(cparse_file, cparse_start_line, "Unterminated wide string\n"); - return SWIG_TOKEN_ERROR; - } - } - break; - - case 79: /* Processing a wide char literal */ - if ((c = nextchar(s)) == 0) { - Swig_error(cparse_file, cparse_start_line, "Unterminated character constant\n"); - return SWIG_TOKEN_ERROR; - } - if (c == '\'') { - Delitem(s->text, DOH_END); - return (SWIG_TOKEN_WCHAR); - } else if (c == '\\') { - if ((c = nextchar(s)) == 0) { - Swig_error(cparse_file, cparse_start_line, "Unterminated wide char literal\n"); - return SWIG_TOKEN_ERROR; - } - } - break; - case 75: /* Special identifier $ */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_DOLLAR; @@ -1028,6 +975,59 @@ static int look(Scanner * s) { return SWIG_TOKEN_ID; break; + case 77: /*identifier or wide string literal*/ + if ((c = nextchar(s)) == 0) + return SWIG_TOKEN_ID; + else if (c == '\"') { + s->start_line = s->line; + Clear(s->text); + state = 78; + } + else if (c == '\'') { + s->start_line = s->line; + Clear(s->text); + state = 79; + } + else if (isalnum(c) || (c == '_') || (c == '$')) + state = 7; + else { + retract(s, 1); + return SWIG_TOKEN_ID; + } + break; + + case 78: /* Processing a wide string literal*/ + if ((c = nextchar(s)) == 0) { + Swig_error(cparse_file, cparse_start_line, "Unterminated wide string\n"); + return SWIG_TOKEN_ERROR; + } + if (c == '\"') { + Delitem(s->text, DOH_END); + return SWIG_TOKEN_WSTRING; + } else if (c == '\\') { + if ((c = nextchar(s)) == 0) { + Swig_error(cparse_file, cparse_start_line, "Unterminated wide string\n"); + return SWIG_TOKEN_ERROR; + } + } + break; + + case 79: /* Processing a wide char literal */ + if ((c = nextchar(s)) == 0) { + Swig_error(cparse_file, cparse_start_line, "Unterminated wide character constant\n"); + return SWIG_TOKEN_ERROR; + } + if (c == '\'') { + Delitem(s->text, DOH_END); + return (SWIG_TOKEN_WCHAR); + } else if (c == '\\') { + if ((c = nextchar(s)) == 0) { + Swig_error(cparse_file, cparse_start_line, "Unterminated wide character literal\n"); + return SWIG_TOKEN_ERROR; + } + } + break; + case 8: /* A numerical digit */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_INT; From d357bec829d08ee96afe8ca8bf6d8631f6b983c9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 21 Jan 2013 20:04:06 +0000 Subject: [PATCH 0415/1160] Remove recently added %expect in parser in case of backward compatibility problems --- Source/CParse/parser.y | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index cd032eb00..3b9762b96 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -13,7 +13,12 @@ * some point. Beware. * ----------------------------------------------------------------------------- */ +/* +Removed until we know more about the min versions of Bison and Yacc required for this +to work, see Byacc man page: http://invisible-island.net/byacc/manpage/yacc.html %expect 6 +*/ + %{ #define yylex yylex From 07c35d61e30d371a65b134ca62c44701230cfbd0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Jan 2013 08:02:34 +0000 Subject: [PATCH 0416/1160] Fix generated code for rvalue references by converting functions returning an rvalue reference into something that can be taken the address of - via a const ref cast. Now the rvalue_reference tests compile under g++-4.7 (C# only atm) --- Examples/test-suite/common.mk | 1 + Examples/test-suite/cpp0x_rvalue_reference3.i | 65 +++++++++++++++++++ Source/Swig/cwrap.c | 11 +++- 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/cpp0x_rvalue_reference3.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index c19755018..1b50ed895 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -443,6 +443,7 @@ CPP0X_TEST_CASES = \ cpp0x_raw_string_literals \ cpp0x_rvalue_reference \ cpp0x_rvalue_reference2 \ + cpp0x_rvalue_reference3 \ cpp0x_sizeof_object \ cpp0x_static_assert \ cpp0x_strongly_typed_enumerations \ diff --git a/Examples/test-suite/cpp0x_rvalue_reference3.i b/Examples/test-suite/cpp0x_rvalue_reference3.i new file mode 100644 index 000000000..c6fe60068 --- /dev/null +++ b/Examples/test-suite/cpp0x_rvalue_reference3.i @@ -0,0 +1,65 @@ +%module cpp0x_rvalue_reference3 + +%inline %{ +#include +struct Thing {}; + +Thing && global_rvalue_ref = Thing(); +Thing *&& global_rvalue_ref_ptr1 = 0; +Thing const*&& global_rvalue_ref_ptr2 = 0; +Thing *const&& global_rvalue_ref_ptr3 = 0; +Thing const*const &&global_rvalue_ref_ptr4 = 0; + +Thing && returnit1() { return std::move(global_rvalue_ref); } +Thing *&& returnit2() { return std::move(global_rvalue_ref_ptr1); } +Thing const*&& returnit3() { return std::move(global_rvalue_ref_ptr2); } +Thing *const&& returnit4() { return std::move(global_rvalue_ref_ptr3); } +Thing const*const&& returnit5() { return std::move(global_rvalue_ref_ptr4); } + +void takeit1(Thing && t) {} +void takeit2(Thing *&& t) {} +void takeit3(Thing const*&& t) {} +void takeit4(Thing *const&& t) {} +void takeit5(Thing const*const&& t) {} + +struct Containing { + Thing && member_rvalue_ref; + Thing *&& member_rvalue_ref_ptr1 = 0; + Thing const*&& member_rvalue_ref_ptr2 = 0; + Thing *const&& member_rvalue_ref_ptr3 = 0; + Thing const*const &&member_rvalue_ref_ptr4 = 0; + + Containing() : member_rvalue_ref(Thing()) {} +}; +%} + + +%inline %{ +int && int_global_rvalue_ref = 5; +int *&& int_global_rvalue_ref_ptr1 = 0; +int const*&& int_global_rvalue_ref_ptr2 = 0; +int *const&& int_global_rvalue_ref_ptr3 = 0; +int const*const &&int_global_rvalue_ref_ptr4 = 0; + +int && int_returnit1() { return std::move(int_global_rvalue_ref); } +int *&& int_returnit2() { return std::move(int_global_rvalue_ref_ptr1); } +int const*&& int_returnit3() { return std::move(int_global_rvalue_ref_ptr2); } +int *const&& int_returnit4() { return std::move(int_global_rvalue_ref_ptr3); } +int const*const&& int_returnit5() { return std::move(int_global_rvalue_ref_ptr4); } + +void int_takeit1(int && t) {} +void int_takeit2(int *&& t) {} +void int_takeit3(int const*&& t) {} +void int_takeit4(int *const&& t) {} +void int_takeit5(int const*const&& t) {} + +struct IntContaining { + int && member_rvalue_ref; + int *&& member_rvalue_ref_ptr1 = 0; + int const*&& member_rvalue_ref_ptr2 = 0; + int *const&& member_rvalue_ref_ptr3 = 0; + int const*const &&member_rvalue_ref_ptr4 = 0; + + IntContaining() : member_rvalue_ref(55) {} +}; +%} diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index d335bb0e9..1ec790167 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -317,7 +317,16 @@ String *Swig_cresult(SwigType *t, const_String_or_char_ptr name, const_String_or case T_RVALUE_REFERENCE: { String *lstr = SwigType_lstr(t, 0); - Printf(fcall, "%s = (%s) &", name, lstr); + SwigType *tt = Copy(t); + SwigType_del_rvalue_reference(tt); + SwigType_add_qualifier(tt, "const"); + SwigType_add_reference(tt); + String *const_lvalue_str = SwigType_rcaststr(tt, 0); + + Printf(fcall, "%s = (%s) &%s", name, lstr, const_lvalue_str); + + Delete(const_lvalue_str); + Delete(tt); Delete(lstr); } break; From 1386b73545ae11c9a35820a2ff2179b64ebc2313 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Jan 2013 19:09:05 +0000 Subject: [PATCH 0417/1160] More rvalue reference typemaps --- Lib/csharp/csharp.swg | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index 950e02e5d..5994aa9c0 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -427,6 +427,12 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %{ $input = (void *) $1; %} %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE & +%{ if (!$input) { + SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Unexpected null return for type $1_type", 0); + return $null; + } + $result = ($1_ltype)$input; %} +%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE && %{ if (!$input) { SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Unexpected null return for type $1_type", 0); return $null; @@ -434,10 +440,13 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { $result = ($1_ltype)$input; %} %typemap(directorin) SWIGTYPE & %{ $input = ($1_ltype) &$1; %} +%typemap(directorin) SWIGTYPE && +%{ $input = ($1_ltype) &$1; %} %typemap(csdirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*) "($iminput == IntPtr.Zero) ? null : new $csclassname($iminput, false)" %typemap(csdirectorin) SWIGTYPE & "new $csclassname($iminput, false)" -%typemap(csdirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "$csclassname.getCPtr($cscall).Handle" +%typemap(csdirectorin) SWIGTYPE && "new $csclassname($iminput, false)" +%typemap(csdirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE &, SWIGTYPE && "$csclassname.getCPtr($cscall).Handle" /* Default array handling */ %typemap(in) SWIGTYPE [] %{ $1 = ($1_ltype)$input; %} @@ -973,6 +982,7 @@ using System.Runtime.InteropServices; /* Array reference typemaps */ %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } +%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } /* const pointers */ %apply SWIGTYPE * { SWIGTYPE *const } From 556e6469729f82e33b7e8db890a1285ade97b65b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Jan 2013 20:17:52 +0000 Subject: [PATCH 0418/1160] Add missing static member to testcase --- Examples/test-suite/cpp0x_rvalue_reference2.i | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/cpp0x_rvalue_reference2.i b/Examples/test-suite/cpp0x_rvalue_reference2.i index a3e9d1784..b7f58afee 100644 --- a/Examples/test-suite/cpp0x_rvalue_reference2.i +++ b/Examples/test-suite/cpp0x_rvalue_reference2.i @@ -36,9 +36,10 @@ struct Thingy { rvalref = rhs.rvalref; } private: - static const bool PrivateTrue = true; + static const bool PrivateTrue; Thingy(); }; +const bool Thingy::PrivateTrue = true; short && globalRvalueInOut(short &&i) { return std::move(i); } From 1e472da302e4d7203b5038d8b30f3172e164350c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Jan 2013 19:24:24 +0000 Subject: [PATCH 0419/1160] Use CXXFLAGS for c++ code for Go examples --- Examples/Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 4b5142267..6dae4e461 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1184,8 +1184,8 @@ go: $(SRCS) 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) + $(CXX) -g -c $(CCSHARED) $(CXXFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) + $(CXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) $(COMPILETOOL) $(GO) -I . $(GOCOMPILEARG) $(GOSRCS) if ! $(GOGCC) ; then \ $(COMPILETOOL) $(GOC) -I $${GOROOT}/pkg/$${GOOS}_$${GOARCH} $(GOCSRCS) && \ From 285198c48fc43a1e890f17537db0e7ed571be054 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Jan 2013 19:09:22 +0000 Subject: [PATCH 0420/1160] Add rvalue reference typemaps --- Lib/java/java.swg | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/Lib/java/java.swg b/Lib/java/java.swg index 44e1337bc..7743eac5d 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -185,6 +185,10 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %typemap(jtype) SWIGTYPE & "long" %typemap(jstype) SWIGTYPE & "$javaclassname" +%typemap(jni) SWIGTYPE && "jlong" +%typemap(jtype) SWIGTYPE && "long" +%typemap(jstype) SWIGTYPE && "$javaclassname" + /* pointer to a class member */ %typemap(jni) SWIGTYPE (CLASS::*) "jstring" %typemap(jtype) SWIGTYPE (CLASS::*) "String" @@ -649,6 +653,11 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null"); return $null; } %} +%typemap(in) SWIGTYPE && %{ $1 = *($&1_ltype)&$input; + if (!$1) { + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null"); + return $null; + } %} %typemap(out) SWIGTYPE * %{ *($&1_ltype)&$result = $1; %} %typemap(out, fragment="SWIG_PackData", noblock=1) SWIGTYPE (CLASS::*) { @@ -659,6 +668,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { } %typemap(out) SWIGTYPE & %{ *($&1_ltype)&$result = $1; %} +%typemap(out) SWIGTYPE && +%{ *($&1_ltype)&$result = $1; %} %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE * %{ $result = *($&1_ltype)&$input; %} @@ -671,6 +682,12 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %{ *(($&1_ltype)&$input) = ($1_ltype) $1; %} %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE & +%{ if (!$input) { + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Unexpected null return for type $1_type"); + return $null; + } + $result = *($&1_ltype)&$input; %} +%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE && %{ if (!$input) { SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Unexpected null return for type $1_type"); return $null; @@ -678,10 +695,13 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { $result = *($&1_ltype)&$input; %} %typemap(directorin,descriptor="L$packagepath/$javaclassname;") SWIGTYPE & %{ *($&1_ltype)&$input = ($1_ltype) &$1; %} +%typemap(directorin,descriptor="L$packagepath/$javaclassname;") SWIGTYPE && +%{ *($&1_ltype)&$input = ($1_ltype) &$1; %} %typemap(javadirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*) "($jniinput == 0) ? null : new $javaclassname($jniinput, false)" %typemap(javadirectorin) SWIGTYPE & "new $javaclassname($jniinput, false)" -%typemap(javadirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "$javaclassname.getCPtr($javacall)" +%typemap(javadirectorin) SWIGTYPE && "new $javaclassname($jniinput, false)" +%typemap(javadirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE &, SWIGTYPE && "$javaclassname.getCPtr($javacall)" /* Default array handling */ %typemap(in) SWIGTYPE [] %{ $1 = *($&1_ltype)&$input; %} @@ -959,6 +979,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { SWIGTYPE, SWIGTYPE *, SWIGTYPE &, + SWIGTYPE &&, SWIGTYPE *const&, SWIGTYPE [], SWIGTYPE (CLASS::*) @@ -978,7 +999,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, error_msg); return $null; %} -%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] +%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] %{ (void)$1; SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "C++ $1_type exception thrown"); return $null; %} @@ -1029,7 +1050,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { jobjectArray "$javainput" %typemap(javain) SWIGTYPE "$&javaclassname.getCPtr($javainput)" -%typemap(javain) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] "$javaclassname.getCPtr($javainput)" +%typemap(javain) SWIGTYPE *, 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 @@ -1083,6 +1104,9 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %typemap(javaout) SWIGTYPE & { return new $javaclassname($jnicall, $owner); } +%typemap(javaout) SWIGTYPE && { + return new $javaclassname($jnicall, $owner); + } %typemap(javaout) SWIGTYPE *, SWIGTYPE [] { long cPtr = $jnicall; return (cPtr == 0) ? null : new $javaclassname(cPtr, $owner); @@ -1108,11 +1132,11 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %{ *($1_ltype)&$result = *$1; %} /* 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" -%typemap(javacode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" -%typemap(javaimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" -%typemap(javainterfaces) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" +%typemap(javabase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" +%typemap(javaclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "public class" +%typemap(javacode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" +%typemap(javaimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" +%typemap(javainterfaces) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" /* javabody typemaps */ @@ -1153,7 +1177,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { SWIG_JAVABODY_METHODS(public, public, SWIGTYPE) // Typewrapper classes -%typemap(javabody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] %{ +%typemap(javabody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] %{ private long swigCPtr; protected $javaclassname(long cPtr, boolean futureUse) { @@ -1286,6 +1310,7 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE) /* Array reference typemaps */ %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } +%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } /* const pointers */ %apply SWIGTYPE * { SWIGTYPE *const } From e87a51ed92891e4f518fc3dcb32288cfe869a43a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Jan 2013 19:24:52 +0000 Subject: [PATCH 0421/1160] Add rvalue reference typemaps --- Lib/go/go.swg | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Lib/go/go.swg b/Lib/go/go.swg index 648e112e1..7eb7c62c7 100644 --- a/Lib/go/go.swg +++ b/Lib/go/go.swg @@ -281,6 +281,21 @@ type _swig_memberptr *byte %typemap(directorout) SWIGTYPE & %{ *($&1_ltype)&$result = $input; %} +%typemap(gotype) 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. */ @@ -398,7 +413,7 @@ type _swig_memberptr *byte %typemap(throws) char * %{ _swig_gopanic($1); %} -%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] +%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] %{ (void)$1; _swig_gopanic("C++ $1_type exception thrown"); @@ -504,6 +519,7 @@ type _swig_memberptr *byte SWIGTYPE, SWIGTYPE *, SWIGTYPE &, + SWIGTYPE &&, SWIGTYPE *const&, SWIGTYPE [], SWIGTYPE (CLASS::*) From 0734fa050de474ee4c90908c58be387c4b59e544 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Jan 2013 19:44:27 +0000 Subject: [PATCH 0422/1160] Add rvalue reference typemaps --- Lib/modula3/modula3.swg | 51 +++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/Lib/modula3/modula3.swg b/Lib/modula3/modula3.swg index 3affdd0de..262f8ead4 100644 --- a/Lib/modula3/modula3.swg +++ b/Lib/modula3/modula3.swg @@ -344,6 +344,23 @@ %typemap(m3wrapouttype) SWIGTYPE & "$1_basetype" %typemap(m3wraprettype) SWIGTYPE & "UNTRACED REF $1_basetype" +%typemap(ctype) SWIGTYPE && "$1_type" +%typemap(m3rawtype) const SWIGTYPE && "UNTRACED REF $1_basetype" +%typemap(m3rawtype) SWIGTYPE && "UNTRACED REF $1_basetype" +%typemap(m3rawintype) const SWIGTYPE && "$1_basetype" +%typemap(m3rawinmode) const SWIGTYPE && "READONLY" +%typemap(m3rawintype) SWIGTYPE && "$1_basetype" +%typemap(m3rawinmode) SWIGTYPE && "VAR" +%typemap(m3rawrettype) const SWIGTYPE && "UNTRACED REF $1_basetype" +%typemap(m3rawrettype) SWIGTYPE && "UNTRACED REF $1_basetype" +%typemap(m3wraptype) SWIGTYPE && "$1_basetype" +%typemap(m3wrapintype) const SWIGTYPE && "$1_basetype" +%typemap(m3wrapinmode) const SWIGTYPE && "READONLY" +%typemap(m3wrapintype) SWIGTYPE && "$1_basetype" +%typemap(m3wrapinmode) SWIGTYPE && "VAR" +%typemap(m3wrapouttype) SWIGTYPE && "$1_basetype" +%typemap(m3wraprettype) SWIGTYPE && "UNTRACED REF $1_basetype" + %typemap(ctype) enum SWIGTYPE "$1_type" %typemap(m3rawtype) enum SWIGTYPE "C.int" %typemap(m3rawintype) enum SWIGTYPE "C.int (* $1_type *)" @@ -468,7 +485,12 @@ $1 = &temp; %} //SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null"); RETURN $null; } %} -%typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE (CLASS::*) %{ *($&1_ltype)&$result = $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 &, SWIGTYPE &&, SWIGTYPE (CLASS::*) %{ *($&1_ltype)&$result = $1; %} /* Default array handling */ @@ -552,6 +574,7 @@ $1 = &temp; %} SWIGTYPE, SWIGTYPE *, SWIGTYPE &, + SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" @@ -605,7 +628,7 @@ $1 = &temp; %} enum SWIGTYPE "$input" %typemap(m3in) SWIGTYPE "$&*1_type.getCPtr($input)" -%typemap(m3in) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "$1_basetype.getCPtr($input)" +%typemap(m3in) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "$1_basetype.getCPtr($input)" /* The m3out typemap is used for converting function return types from the return type * used in the PInvoke class to the type returned by the proxy, module or type wrapper class. */ @@ -636,13 +659,16 @@ $1 = &temp; %} %typemap(m3out) SWIGTYPE & %{ RETURN NEW($1_basetype, $imcall, $owner); %} +%typemap(m3out) SWIGTYPE && %{ + RETURN NEW($1_basetype, $imcall, $owner); +%} %typemap(m3out) SWIGTYPE *, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ cPtr := $imcall; RETURN (cPtr = IntPtr.Zero) ? null : NEW($1_basetype, cPtr, $owner); %} /* Properties */ -%typemap(m3varin) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ +%typemap(m3varin) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ PROCEDURE Set$var (value: $vartype) = BEGIN $imcall; @@ -684,6 +710,10 @@ PROCEDURE Get$var (): $vartype = get { RETURN new $1_basetype($imcall, $owner); } %} +%typemap(m3varout) SWIGTYPE && %{ + get { + RETURN new $1_basetype($imcall, $owner); + } %} %typemap(m3varout) SWIGTYPE *, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ get { IntPtr cPtr = $imcall; @@ -691,13 +721,13 @@ PROCEDURE Get$var (): $vartype = } %} /* Typemaps used for the generation of proxy and type wrapper class code */ -%typemap(m3base) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" -%typemap(m3classmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "public" -%typemap(m3code) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" -%typemap(m3imports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "using System;" +%typemap(m3base) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" +%typemap(m3classmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "public" +%typemap(m3code) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" +%typemap(m3imports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "using System;" %typemap(m3interfaces) SWIGTYPE "IDisposable" -%typemap(m3interfaces_derived) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" -%typemap(m3ptrconstructormodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "internal" +%typemap(m3interfaces_derived) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" +%typemap(m3ptrconstructormodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "internal" %typemap(m3finalize) SWIGTYPE %{ ~$1_basetype() { @@ -724,7 +754,7 @@ PROCEDURE Get$var (): $vartype = base.Dispose(); } -%typemap(m3getcptr) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ +%typemap(m3getcptr) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ internal static IntPtr getCPtr($1_basetype obj) { RETURN (obj == null) ? IntPtr.Zero : obj.swigCPtr; } @@ -748,6 +778,7 @@ FROM BlaBla IMPORT Bla; /* Array reference typemaps */ %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } +%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } /* const pointers */ %apply SWIGTYPE * { SWIGTYPE *const } From 9bd2fb2cad41246c5e124a3ea4738f045759370f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Jan 2013 19:48:56 +0000 Subject: [PATCH 0423/1160] Add rvalue reference typemaps --- Lib/allegrocl/allegrocl.swg | 13 +++++++------ Lib/cffi/cffi.swg | 9 +++++---- Lib/chicken/chicken.swg | 36 ++++++++++++++++++++++++++++++++---- Lib/guile/typemaps.i | 23 +++++++++++++++++++---- Lib/mzscheme/typemaps.i | 15 ++++++++++++--- Lib/pike/pike.swg | 14 +++++++++----- 6 files changed, 84 insertions(+), 26 deletions(-) diff --git a/Lib/allegrocl/allegrocl.swg b/Lib/allegrocl/allegrocl.swg index 87e030ce4..bbfdcdb78 100644 --- a/Lib/allegrocl/allegrocl.swg +++ b/Lib/allegrocl/allegrocl.swg @@ -16,8 +16,7 @@ float, double, long double, char *, void *, enum SWIGTYPE "(cl::setq ACL_ffresult $body)"; %typemap(lout) void "$body"; -%typemap(lout) SWIGTYPE[ANY], SWIGTYPE *, - SWIGTYPE & +%typemap(lout) SWIGTYPE[ANY], SWIGTYPE *, SWIGTYPE &, SWIGTYPE && %{ (cl:let* ((address $body) (new-inst (cl:make-instance '$lclass :foreign-address address))) (cl:when (cl:and $owner (cl:not (cl:zerop address))) @@ -60,6 +59,7 @@ %typemap(ffitype) void ":void"; %typemap(ffitype) enum SWIGTYPE ":int"; %typemap(ffitype) SWIGTYPE & "(* :void)"; +%typemap(ffitype) SWIGTYPE && "(* :void)"; /* const typemaps idea: marshall all primitive c types to their respective lisp types @@ -95,7 +95,7 @@ and error if a setf operation is performed on the address of this object. long, signed long, unsigned long, float, double, long double, char *, void *, void, enum SWIGTYPE, SWIGTYPE *, SWIGTYPE[], - SWIGTYPE[ANY], SWIGTYPE &, const SWIGTYPE "$1_ltype"; + SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE &&, const SWIGTYPE "$1_ltype"; %typemap(ctype) SWIGTYPE "$&1_type"; %typemap(in) bool "$1 = (bool)$input;"; @@ -105,7 +105,7 @@ and error if a setf operation is performed on the address of this object. long, signed long, unsigned long, float, double, long double, char *, void *, void, enum SWIGTYPE, SWIGTYPE *, SWIGTYPE[], - SWIGTYPE[ANY], SWIGTYPE & "$1 = $input;"; + SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$1 = $input;"; %typemap(in) SWIGTYPE "$1 = *$input;"; /* We don't need to do any actual C-side typechecking, but need to @@ -160,7 +160,7 @@ SWIG_TYPECHECK_STRING_ARRAY 1140 int, signed int, unsigned int, long, signed long, unsigned long, enum SWIGTYPE { $1 = 1; }; -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, +%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE[], SWIGTYPE[ANY], SWIGTYPE { $1 = 1; }; @@ -185,7 +185,7 @@ SWIG_TYPECHECK_STRING_ARRAY 1140 long, signed long, unsigned long, float, double, long double, char *, void *, enum SWIGTYPE, SWIGTYPE *, - SWIGTYPE[ANY], SWIGTYPE & "$result = $1;"; + SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$result = $1;"; #ifdef __cplusplus %typemap(out) SWIGTYPE "$result = new $1_ltype($1);"; #else @@ -221,6 +221,7 @@ $body)" /* Array reference typemaps */ %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } +%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } /* const pointers */ %apply SWIGTYPE * { SWIGTYPE *const } diff --git a/Lib/cffi/cffi.swg b/Lib/cffi/cffi.swg index 6ac82f45e..e6a74b835 100644 --- a/Lib/cffi/cffi.swg +++ b/Lib/cffi/cffi.swg @@ -67,7 +67,7 @@ long, signed long, unsigned long, float, double, long double, char *, void *, void, enum SWIGTYPE, SWIGTYPE *, - SWIGTYPE[ANY], SWIGTYPE & "$1_ltype"; + SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$1_ltype"; %typemap(ctype) SWIGTYPE "$&1_type"; %typemap(in) bool "$1 = (bool)$input;"; @@ -77,7 +77,7 @@ long, signed long, unsigned long, float, double, long double, char *, void *, void, enum SWIGTYPE, SWIGTYPE *, - SWIGTYPE[ANY], SWIGTYPE & "$1 = $input;"; + SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$1 = $input;"; %typemap(in) SWIGTYPE "$1 = *$input;"; %typemap(out) void ""; @@ -88,7 +88,7 @@ long, signed long, unsigned long, float, double, long double, char *, void *, enum SWIGTYPE, SWIGTYPE *, - SWIGTYPE[ANY], SWIGTYPE & "$result = $1;"; + SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$result = $1;"; #ifdef __cplusplus %typemap(out) SWIGTYPE "$result = new $1_type($1);"; #else @@ -109,7 +109,7 @@ int, signed int, unsigned int, long, signed long, unsigned long, enum SWIGTYPE { $1 = 1; }; -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, +%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE[ANY], SWIGTYPE { $1 = 1; }; /* This maps C/C++ types to Lisp classes for overload dispatch */ @@ -132,6 +132,7 @@ /* Array reference typemaps */ %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } +%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } /* const pointers */ %apply SWIGTYPE * { SWIGTYPE *const } diff --git a/Lib/chicken/chicken.swg b/Lib/chicken/chicken.swg index 112780499..f5779c1b6 100644 --- a/Lib/chicken/chicken.swg +++ b/Lib/chicken/chicken.swg @@ -149,6 +149,7 @@ SIMPLE_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEO /* enum SWIGTYPE */ %apply int { enum SWIGTYPE }; %apply const int& { const enum SWIGTYPE& }; +%apply const int& { const enum SWIGTYPE&& }; %typemap(varin) enum SWIGTYPE { @@ -178,7 +179,7 @@ SIMPLE_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEO %typemap(freearg) char * "if ($1 != NULL) { free ($1); }" /* Pointers, references, and arrays */ -%typemap(in,closcode="(slot-ref $input 'swig-this)") SWIGTYPE *, SWIGTYPE [], SWIGTYPE & { +%typemap(in,closcode="(slot-ref $input 'swig-this)") SWIGTYPE *, SWIGTYPE [], SWIGTYPE &, SWIGTYPE && { $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, $disown); } @@ -199,6 +200,10 @@ SIMPLE_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEO $1 = *(($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0)); } +%typemap(varin,closcode="(slot-ref $input 'swig-this)") SWIGTYPE && { + $1 = *(($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0)); +} + %typemap(varin) SWIGTYPE [] { SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, "Type error"); } @@ -216,7 +221,7 @@ SIMPLE_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEO $1 = SWIG_MustGetPtr($input, NULL, 1, 0); } -%typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { +%typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); $result = SWIG_NewPointerObj($1, $descriptor, $owner); } @@ -237,6 +242,11 @@ SIMPLE_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEO $result = SWIG_NewPointerObj((void *) &$varname, $1_descriptor, 0); } +%typemap(varout) SWIGTYPE && { + C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); + $result = SWIG_NewPointerObj((void *) &$varname, $1_descriptor, 0); +} + /* special typemaps for class pointers */ %typemap(in) SWIGTYPE (CLASS::*) { char err_msg[256]; @@ -531,7 +541,7 @@ $result = C_SCHEME_UNDEFINED; %typemap(constcode) char * "static const char *$result = $value;" -%typemap(constcode) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] +%typemap(constcode) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] "static const void *$result = (void*) $value;" /* ------------------------------------------------------------ @@ -607,7 +617,7 @@ $result = C_SCHEME_UNDEFINED; $1 = C_swig_is_string ($input); } -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { +%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { void *ptr; $1 = !SWIG_ConvertPtr($input, &ptr, $1_descriptor, 0); } @@ -628,6 +638,17 @@ $result = C_SCHEME_UNDEFINED; } } +%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE && +{ + void *ptr = 0; + if (SWIG_ConvertPtr($input, &ptr, $descriptor, 0)) { + /* error */ + $1 = 0; + } else { + $1 = (ptr != 0); + } +} + %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE { void *ptr = 0; @@ -673,6 +694,12 @@ $result = C_SCHEME_UNDEFINED; SWIG_Chicken_ThrowException(ptr); } +%typemap(throws) SWIGTYPE && { + C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); + C_word ptr = SWIG_NewPointerObj((void *)&($1),$descriptor,0); + SWIG_Chicken_ThrowException(ptr); +} + /* ------------------------------------------------------------ * ANSI C typemaps * ------------------------------------------------------------ */ @@ -685,6 +712,7 @@ $result = C_SCHEME_UNDEFINED; /* Array reference typemaps */ %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } +%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } /* const pointers */ %apply SWIGTYPE * { SWIGTYPE *const } diff --git a/Lib/guile/typemaps.i b/Lib/guile/typemaps.i index c194d4bc9..8e09d0dc0 100644 --- a/Lib/guile/typemaps.i +++ b/Lib/guile/typemaps.i @@ -6,10 +6,10 @@ /* Pointers */ -%typemap(in) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { +%typemap(in) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, 0); } -%typemap(freearg) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] ""; +%typemap(freearg) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] ""; %typemap(in) void * { $1 = ($1_ltype)SWIG_MustGetPtr($input, NULL, $argnum, 0); @@ -24,6 +24,10 @@ $1 = *(($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0)); } +%typemap(varin) SWIGTYPE && { + $1 = *(($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0)); +} + %typemap(varin) SWIGTYPE [] { scm_wrong_type_arg((char *) FUNC_NAME, 1, $input); } @@ -41,7 +45,7 @@ $1 = SWIG_MustGetPtr($input, NULL, 1, 0); } -%typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { +%typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { $result = SWIG_NewPointerObj ($1, $descriptor, $owner); } @@ -58,6 +62,10 @@ $result = SWIG_NewPointerObj((void *) &$1, $1_descriptor, 0); } +%typemap(varout) SWIGTYPE && { + $result = SWIG_NewPointerObj((void *) &$1, $1_descriptor, 0); +} + %typemap(throws) SWIGTYPE { $<ype temp = new $ltype($1); scm_throw(gh_symbol2scm((char *) "swig-exception"), @@ -71,6 +79,12 @@ SCM_UNDEFINED)); } +%typemap(throws) SWIGTYPE && { + scm_throw(gh_symbol2scm((char *) "swig-exception"), + gh_list(SWIG_NewPointerObj(&$1, $descriptor, 1), + SCM_UNDEFINED)); +} + %typemap(throws) SWIGTYPE * { scm_throw(gh_symbol2scm((char *) "swig-exception"), gh_list(SWIG_NewPointerObj($1, $descriptor, 1), @@ -430,7 +444,7 @@ typedef unsigned long SCM; $1 = SCM_STRINGP($input) ? 1 : 0; } -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { +%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { void *ptr; int res = SWIG_ConvertPtr($input, &ptr, $1_descriptor, 0); $1 = SWIG_CheckState(res); @@ -450,6 +464,7 @@ typedef unsigned long SCM; /* Array reference typemaps */ %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } +%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } /* const pointers */ %apply SWIGTYPE * { SWIGTYPE *const } diff --git a/Lib/mzscheme/typemaps.i b/Lib/mzscheme/typemaps.i index f12513df8..026ec9567 100644 --- a/Lib/mzscheme/typemaps.i +++ b/Lib/mzscheme/typemaps.i @@ -23,6 +23,10 @@ $1 = *(($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0)); } +%typemap(varin) SWIGTYPE && { + $1 = *(($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0)); +} + %typemap(varin) SWIGTYPE [ANY] { void *temp; int ii; @@ -54,16 +58,20 @@ $result = SWIG_NewPointerObj((void *) &$1, $1_descriptor, 0); } +%typemap(varout) SWIGTYPE && { + $result = SWIG_NewPointerObj((void *) &$1, $1_descriptor, 0); +} + /* C++ References */ #ifdef __cplusplus -%typemap(in) SWIGTYPE &, const SWIGTYPE & { +%typemap(in) SWIGTYPE &, SWIGTYPE && { $1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, $argnum, 0); if ($1 == NULL) scheme_signal_error("swig-type-error (null reference)"); } -%typemap(out) SWIGTYPE &, const SWIGTYPE & { +%typemap(out) SWIGTYPE &, SWIGTYPE && { $result = SWIG_NewPointerObj ($1, $descriptor, $owner); } @@ -321,7 +329,7 @@ REF_MAP(double, SCHEME_REALP, scheme_real_to_double, $1 = (SCHEME_STRINGP($input)) ? 1 : 0; } -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { +%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { void *ptr; if (SWIG_ConvertPtr($input, (void **) &ptr, $1_descriptor, 0)) { $1 = 0; @@ -351,6 +359,7 @@ REF_MAP(double, SCHEME_REALP, scheme_real_to_double, /* Array reference typemaps */ %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } +%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } /* const pointers */ %apply SWIGTYPE * { SWIGTYPE *const } diff --git a/Lib/pike/pike.swg b/Lib/pike/pike.swg index 0cfec52b0..9b8179e69 100644 --- a/Lib/pike/pike.swg +++ b/Lib/pike/pike.swg @@ -53,6 +53,7 @@ extern "C" { %typemap(in) SWIGTYPE *, SWIGTYPE &, + SWIGTYPE &&, SWIGTYPE [] "SWIG_ConvertPtr($input.u.object, (void **) &$1, $1_descriptor, 1);" @@ -79,7 +80,8 @@ extern "C" { const bool & (bool temp), const long long & ($*1_ltype temp), const unsigned long long & ($*1_ltype temp), - const enum SWIGTYPE & ($*1_ltype temp) + const enum SWIGTYPE & ($*1_ltype temp), + const enum SWIGTYPE && ($*1_ltype temp) { if ($input.type != T_INT) Pike_error("Bad argument: Expected an integer.\n"); @@ -113,7 +115,7 @@ extern "C" { %typemap(out, pikedesc="tStr") char * "push_text($1);"; /* Pointers, references, and arrays */ -%typemap(out, pikedesc="tObj") SWIGTYPE*, SWIGTYPE &, SWIGTYPE [] "push_object(SWIG_NewPointerObj((void *) $1, $1_descriptor, $owner));"; +%typemap(out, pikedesc="tObj") SWIGTYPE*, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] "push_object(SWIG_NewPointerObj((void *) $1, $1_descriptor, $owner));"; /* Void return value; don't push anything */ %typemap(out, pikedesc="tVoid") void ""; @@ -153,7 +155,8 @@ extern "C" { const char &, const signed char &, const unsigned char &, const bool &, const long long &, const unsigned long long &, - const enum SWIGTYPE & ($*1_ltype temp) + const enum SWIGTYPE & ($*1_ltype temp), + const enum SWIGTYPE && ($*1_ltype temp) "push_int(*($1));"; %typemap(out, pikedesc="tFloat") const float &, const double & "push_float(*($1));"; @@ -216,7 +219,7 @@ extern "C" { const int &, const short &, const long &, const unsigned int &, const unsigned short &, const unsigned long &, const long long &, const unsigned long long &, - enum SWIGTYPE, enum SWIGTYPE &, + enum SWIGTYPE, enum SWIGTYPE &, SWIGTYPE &&, bool, const bool & { $1 = ($input.type == T_INT) ? 1 : 0; @@ -237,7 +240,7 @@ extern "C" { $1 = ($input.type == T_STRING) ? 1 : 0; } -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { +%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { void *ptr; if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, $1_descriptor, 0) == -1) { $1 = 0; @@ -266,6 +269,7 @@ extern "C" { /* Array reference typemaps */ %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } +%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } /* const pointers */ %apply SWIGTYPE * { SWIGTYPE *const } From 341a5366ddbbd2bc5747bdeb4c19b9e4ab3bb559 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Jan 2013 19:53:13 +0000 Subject: [PATCH 0424/1160] Add rvalue reference typemaps --- Lib/lua/lua.swg | 2 +- Lib/lua/luatypemaps.swg | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg index a15f14148..f425f16a1 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 *const, SWIGTYPE &, SWIGTYPE [] +%typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, 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 13cd66f4c..4852c0e32 100644 --- a/Lib/lua/luatypemaps.swg +++ b/Lib/lua/luatypemaps.swg @@ -68,8 +68,12 @@ temp=($basetype)lua_tonumber(L,$input); $1=&temp;%} // and const refs %typemap(in,checkfn="lua_isnumber") const enum SWIGTYPE &($basetype temp) %{ temp=($basetype)(int)lua_tonumber(L,$input); $1=&temp;%} +%typemap(in,checkfn="lua_isnumber") const enum SWIGTYPE &&($basetype temp) +%{ temp=($basetype)(int)lua_tonumber(L,$input); $1=&temp;%} %typemap(out) const enum SWIGTYPE & %{ lua_pushnumber(L, (lua_Number) *$1); SWIG_arg++;%} +%typemap(out) const enum SWIGTYPE && +%{ lua_pushnumber(L, (lua_Number) *$1); SWIG_arg++;%} // boolean (which is a special type in lua) @@ -147,9 +151,18 @@ SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) { } %} +%typemap(in,checkfn="lua_isuserdata") SWIGTYPE&& +%{ + if (!SWIG_IsOK(SWIG_ConvertPtr(L,$input,(void**)&$1,$descriptor,$disown))){ + SWIG_fail_ptr("$symname",$argnum,$descriptor); + } +%} + // out is simple %typemap(out) SWIGTYPE*,SWIGTYPE& %{SWIG_NewPointerObj(L,$1,$descriptor,$owner); SWIG_arg++; %} +%typemap(out) SWIGTYPE*,SWIGTYPE&& +%{SWIG_NewPointerObj(L,$1,$descriptor,$owner); SWIG_arg++; %} // dynamic casts // this uses the SWIG_TypeDynamicCast() which relies on RTTI to find out what the pointer really is @@ -284,7 +297,7 @@ parmeters match which function const unsigned int &, const unsigned short &, const unsigned long &, const signed char&, const unsigned char&, const long long &, const unsigned long long &, - enum SWIGTYPE, const enum SWIGTYPE&, + enum SWIGTYPE, const enum SWIGTYPE&, const enum SWIGTYPE &&, float, double, const float &, const double& { $1 = lua_isnumber(L,$input); @@ -323,6 +336,15 @@ parmeters match which function } } +%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE && { + void *ptr; + if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $1_descriptor, 0)) { + $1 = 0; + } else { + $1 = 1; + } +} + %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE { void *ptr; if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $&1_descriptor, 0)) { @@ -360,6 +382,7 @@ parmeters match which function // Array reference typemaps %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } +%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } /* const pointers */ %apply SWIGTYPE * { SWIGTYPE *const } From 8bdfcda66ee58727097a9ff98d2f946e4da9a105 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Jan 2013 19:56:56 +0000 Subject: [PATCH 0425/1160] Add rvalue reference typemaps --- Lib/ocaml/typecheck.i | 2 +- Lib/ocaml/typemaps.i | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Lib/ocaml/typecheck.i b/Lib/ocaml/typecheck.i index 4c3500690..a13e1552e 100644 --- a/Lib/ocaml/typecheck.i +++ b/Lib/ocaml/typecheck.i @@ -129,7 +129,7 @@ } } -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { +%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { void *ptr; $1 = !caml_ptr_val_internal($input, &ptr,$descriptor); } diff --git a/Lib/ocaml/typemaps.i b/Lib/ocaml/typemaps.i index e5458a3e2..a729432d7 100644 --- a/Lib/ocaml/typemaps.i +++ b/Lib/ocaml/typemaps.i @@ -34,11 +34,21 @@ $1 = ($ltype) caml_ptr_val($input,$1_descriptor); } +%typemap(in) SWIGTYPE && { + /* %typemap(in) SWIGTYPE && */ + $1 = ($ltype) caml_ptr_val($input,$1_descriptor); +} + %typemap(varin) SWIGTYPE & { /* %typemap(varin) SWIGTYPE & */ $1 = *(($ltype) caml_ptr_val($input,$1_descriptor)); } +%typemap(varin) SWIGTYPE && { + /* %typemap(varin) SWIGTYPE && */ + $1 = *(($ltype) caml_ptr_val($input,$1_descriptor)); +} + %typemap(out) SWIGTYPE & { /* %typemap(out) SWIGTYPE & */ CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr"); @@ -49,6 +59,16 @@ } } +%typemap(out) SWIGTYPE && { + /* %typemap(out) SWIGTYPE && */ + CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr"); + if( fromval ) { + $result = callback(*fromval,caml_val_ptr((void *) &$1,$1_descriptor)); + } else { + $result = caml_val_ptr ((void *) &$1,$1_descriptor); + } +} + #if 0 %typemap(argout) SWIGTYPE & { CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr"); @@ -63,9 +83,23 @@ caml_val_ptr ((void *) $1,$1_descriptor)); } } +%typemap(argout) SWIGTYPE && { + CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr"); + if( fromval ) { + swig_result = + caml_list_append(swig_result, + callback(*fromval,caml_val_ptr((void *) $1, + $1_descriptor))); + } else { + swig_result = + caml_list_append(swig_result, + caml_val_ptr ((void *) $1,$1_descriptor)); + } +} #endif %typemap(argout) const SWIGTYPE & { } +%typemap(argout) const SWIGTYPE && { } %typemap(in) SWIGTYPE { $1 = *(($&1_ltype) caml_ptr_val($input,$&1_descriptor)) ; @@ -101,6 +135,7 @@ } %apply SWIGTYPE { const SWIGTYPE & }; +%apply SWIGTYPE { const SWIGTYPE && }; #endif @@ -318,6 +353,7 @@ SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val); /* Array reference typemaps */ %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } +%apply SWIGTYPE && { SWIGTYPE ((&)[ANY]) } /* const pointers */ %apply SWIGTYPE * { SWIGTYPE *const } From d3769a1fd42c8a54f178ed7a712fa1a513f57733 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Jan 2013 20:18:18 +0000 Subject: [PATCH 0426/1160] Add rvalue reference typemaps --- Lib/php/const.i | 1 + Lib/php/globalvar.i | 6 +++--- Lib/php/php.swg | 25 +++++++++++++++++++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Lib/php/const.i b/Lib/php/const.i index afd7d02b9..375c7df71 100644 --- a/Lib/php/const.i +++ b/Lib/php/const.i @@ -31,6 +31,7 @@ %typemap(consttab) SWIGTYPE *, SWIGTYPE &, + SWIGTYPE &&, SWIGTYPE [] { /* This actually registers it as a global variable and constant. I don't * like it, but I can't figure out the zend_constant code... */ diff --git a/Lib/php/globalvar.i b/Lib/php/globalvar.i index 45fb0223b..1378ae60b 100644 --- a/Lib/php/globalvar.i +++ b/Lib/php/globalvar.i @@ -80,7 +80,7 @@ sizeof(zval *), NULL); } -%typemap(varinit) SWIGTYPE, SWIGTYPE & +%typemap(varinit) SWIGTYPE, SWIGTYPE &, SWIGTYPE && { zval *z_var; @@ -210,7 +210,7 @@ } -%typemap(varin) SWIGTYPE *, SWIGTYPE & +%typemap(varin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE && { zval **z_var; $1_ltype _temp; @@ -336,7 +336,7 @@ deliberate error cos this code looks bogus to me } } -%typemap(varout) SWIGTYPE *, SWIGTYPE & +%typemap(varout) SWIGTYPE *, SWIGTYPE &, SWIGTYPE && { zval **z_var; diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 99edcddf5..de38060ca 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -115,6 +115,13 @@ } } +%typemap(in) SWIGTYPE && +{ + if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + } +} + %typemap(in) SWIGTYPE *const& ($*ltype temp) { if(SWIG_ConvertPtr(*$input, (void **) &temp, $*1_descriptor, 0) < 0) { @@ -132,7 +139,8 @@ %typemap(argout) SWIGTYPE *, SWIGTYPE [], - SWIGTYPE&; + SWIGTYPE &, + SWIGTYPE &&; %typemap(in) void * { @@ -241,6 +249,11 @@ ZVAL_LONG(return_value, (long)*$1); } +%typemap(out) const enum SWIGTYPE && +{ + ZVAL_LONG(return_value, (long)*$1); +} + %typemap(out) const long long & %{ if ((long long)LONG_MIN <= *$1 && *$1 <= (long long)LONG_MAX) { @@ -347,7 +360,8 @@ %typemap(out) SWIGTYPE *, SWIGTYPE [], - SWIGTYPE & + SWIGTYPE &, + SWIGTYPE && %{ SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner); %} @@ -359,7 +373,8 @@ %typemap(directorin) SWIGTYPE *, SWIGTYPE [], - SWIGTYPE & + SWIGTYPE &, + SWIGTYPE && %{ SWIG_SetPointerZval($input, (void *)&$1_name, $1_descriptor, $owner); %} @@ -454,6 +469,7 @@ SWIGTYPE *, SWIGTYPE [], SWIGTYPE &, + SWIGTYPE &&, SWIGTYPE *const& { void *tmp; @@ -478,7 +494,7 @@ return; } -%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] %{ +%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] %{ (void)$1; zend_throw_exception(NULL, const_cast("C++ $1_type exception thrown"), 0 TSRMLS_CC); return; @@ -491,6 +507,7 @@ /* Array reference typemaps */ %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } +%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } /* const pointers */ %apply SWIGTYPE * { SWIGTYPE *const } From ac74c90fb03b9ce91db0c8d839d52afa3bbc3db8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Jan 2013 20:23:54 +0000 Subject: [PATCH 0427/1160] Add rvalue reference typemaps --- Lib/perl5/perltypemaps.swg | 3 ++ Lib/python/pydocs.swg | 2 + Lib/r/rtype.swg | 15 +++++- Lib/tcl/tcltypemaps.swg | 3 +- Lib/typemaps/enumint.swg | 15 +++++- Lib/typemaps/swigtype.swg | 95 +++++++++++++++++++++++++++++++++++++- 6 files changed, 127 insertions(+), 6 deletions(-) diff --git a/Lib/perl5/perltypemaps.swg b/Lib/perl5/perltypemaps.swg index 540974476..d77b862ef 100644 --- a/Lib/perl5/perltypemaps.swg +++ b/Lib/perl5/perltypemaps.swg @@ -84,6 +84,9 @@ %typemap(varout,type="$1_descriptor") SWIGTYPE & "sv_setiv(SvRV($result),PTR2IV(&$1));"; +%typemap(varout,type="$1_descriptor") SWIGTYPE && + "sv_setiv(SvRV($result),PTR2IV(&$1));"; + %typemap(varout,type="$&1_descriptor") SWIGTYPE "sv_setiv(SvRV($result), PTR2IV(&$1));"; diff --git a/Lib/python/pydocs.swg b/Lib/python/pydocs.swg index 862339da7..5f46adaea 100644 --- a/Lib/python/pydocs.swg +++ b/Lib/python/pydocs.swg @@ -5,11 +5,13 @@ %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) 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) 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"; diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg index 5103e43db..9c833273f 100644 --- a/Lib/r/rtype.swg +++ b/Lib/r/rtype.swg @@ -31,9 +31,11 @@ %typemap("rtype") enum SWIGTYPE * "character"; %typemap("rtype") enum SWIGTYPE *const "character"; %typemap("rtype") enum SWIGTYPE & "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"; %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 && + %{ $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 *const, SWIGTYPE & +%typemap(scoercein) SWIGTYPE, SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE && %{ %} /* @@ -81,6 +85,9 @@ %typemap(scoercein) SWIGTYPE & %{ $input = coerceIfNotSubclass($input, "$R_class") %} +%typemap(scoercein) SWIGTYPE && + %{ $input = coerceIfNotSubclass($input, "$R_class") %} + %typemap(scoercein) SWIGTYPE %{ $input = coerceIfNotSubclass($input, "$&R_class") %} */ @@ -116,6 +123,9 @@ string &, std::string & %typemap(scoerceout) enum SWIGTYPE & %{ $result = enumFromInteger($result, "$R_class"); %} +%typemap(scoerceout) enum SWIGTYPE && + %{ $result = enumFromInteger($result, "$R_class"); %} + %typemap(scoerceout) enum SWIGTYPE * %{ $result = enumToInteger($result, "$R_class"); %} @@ -129,6 +139,9 @@ string &, std::string & %typemap(scoerceout) SWIGTYPE & %{ class($result) <- "$R_class"; %} +%typemap(scoerceout) SWIGTYPE && + %{ class($result) <- "$R_class"; %} + %typemap(scoerceout) SWIGTYPE * %{ class($result) <- "$R_class"; %} diff --git a/Lib/tcl/tcltypemaps.swg b/Lib/tcl/tcltypemaps.swg index d93c8869b..c4ee13b92 100644 --- a/Lib/tcl/tcltypemaps.swg +++ b/Lib/tcl/tcltypemaps.swg @@ -66,7 +66,7 @@ #if 1 // Old 1.3.25 typemaps needed to avoid premature object deletion -%typemap(out,noblock=1) SWIGTYPE *INSTANCE, SWIGTYPE &INSTANCE, SWIGTYPE INSTANCE[] { +%typemap(out,noblock=1) SWIGTYPE *INSTANCE, SWIGTYPE &INSTANCE, SWIGTYPE &&INSTANCE, SWIGTYPE INSTANCE[] { Tcl_SetObjResult(interp, SWIG_NewInstanceObj( %as_voidptr($1), $1_descriptor,0)); } @@ -86,5 +86,6 @@ %typemap(out) SWIGTYPE * = SWIGTYPE *INSTANCE; %typemap(out) SWIGTYPE *const = SWIGTYPE *; %typemap(out) SWIGTYPE & = SWIGTYPE &INSTANCE; +%typemap(out) SWIGTYPE && = SWIGTYPE &&INSTANCE; %typemap(out) SWIGTYPE [] = SWIGTYPE INSTANCE[]; %typemap(varout) SWIGTYPE = SWIGTYPE INSTANCE; diff --git a/Lib/typemaps/enumint.swg b/Lib/typemaps/enumint.swg index 854d6f3e1..d048bb6bf 100644 --- a/Lib/typemaps/enumint.swg +++ b/Lib/typemaps/enumint.swg @@ -3,9 +3,20 @@ * ------------------------------------------------------------ */ %apply int { enum SWIGTYPE }; -%apply const int& { const enum SWIGTYPE& }; +%apply const int& { const enum SWIGTYPE & }; +%apply const int& { const enum SWIGTYPE && }; -%typemap(in,fragment=SWIG_AsVal_frag(int),noblock=1) const enum SWIGTYPE& (int val, int ecode, $basetype temp) { +%typemap(in,fragment=SWIG_AsVal_frag(int),noblock=1) const enum SWIGTYPE & (int val, int ecode, $basetype temp) { + ecode = SWIG_AsVal(int)($input, &val); + if (!SWIG_IsOK(ecode)) { + %argument_fail(ecode, "$type", $symname, $argnum); + } else { + temp = %static_cast(val,$basetype); + $1 = &temp; + } +} + +%typemap(in,fragment=SWIG_AsVal_frag(int),noblock=1) const enum SWIGTYPE && (int val, int ecode, $basetype temp) { ecode = SWIG_AsVal(int)($input, &val); if (!SWIG_IsOK(ecode)) { %argument_fail(ecode, "$type", $symname, $argnum); diff --git a/Lib/typemaps/swigtype.swg b/Lib/typemaps/swigtype.swg index f57766962..6155a8abc 100644 --- a/Lib/typemaps/swigtype.swg +++ b/Lib/typemaps/swigtype.swg @@ -67,6 +67,41 @@ } #endif +/* Rvalue reference */ +%typemap(in, noblock=1) SWIGTYPE && (void *argp = 0, int res = 0) { + res = SWIG_ConvertPtr($input, &argp, $descriptor, %convertptr_flags); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (!argp) { %argument_nullref("$type", $symname, $argnum); } + $1 = %reinterpret_cast(argp, $ltype); +} +%typemap(freearg) SWIGTYPE && ""; + +#if defined(__cplusplus) && defined(%implicitconv_flag) +%typemap(in,noblock=1,implicitconv=1) const SWIGTYPE && (void *argp = 0, int res = 0) { + res = SWIG_ConvertPtr($input, &argp, $descriptor, %convertptr_flags | %implicitconv_flag); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (!argp) { %argument_nullref("$type", $symname, $argnum); } + $1 = %reinterpret_cast(argp, $ltype); +} +%typemap(freearg,noblock=1,match="in",implicitconv=1) const SWIGTYPE && +{ + if (SWIG_IsNewObj(res$argnum)) %delete($1); +} +#else +%typemap(in,noblock=1) const SWIGTYPE && (void *argp, int res = 0) { + res = SWIG_ConvertPtr($input, &argp, $descriptor, %convertptr_flags); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (!argp) { %argument_nullref("$type", $symname, $argnum); } + $1 = %reinterpret_cast(argp, $ltype); +} +#endif + /* By value */ #if defined(__cplusplus) && defined(%implicitconv_flag) %typemap(in,implicitconv=1) SWIGTYPE (void *argp, int res = 0) { @@ -102,7 +137,7 @@ * ----------------------------------------------------------------------------- */ /* Pointers, references */ -%typemap(out,noblock=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE[] { +%typemap(out,noblock=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE[] { %set_output(SWIG_NewPointerObj(%as_voidptr($1), $descriptor, $owner | %newpointer_flags)); } @@ -235,6 +270,18 @@ $1 = *(%reinterpret_cast(argp, $ltype)); } +%typemap(varin,warning=SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) SWIGTYPE && { + void *argp = 0; + int res = SWIG_ConvertPtr($input, &argp, $descriptor, %convertptr_flags); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + if (!argp) { + %variable_nullref("$type", "$name"); + } + $1 = *(%reinterpret_cast(argp, $ltype)); +} + #if defined(__cplusplus) && defined(%implicitconv_flag) %typemap(varin,implicitconv=1) SWIGTYPE { void *argp = 0; @@ -284,6 +331,10 @@ %set_varoutput(SWIG_NewPointerObj(%as_voidptr(&$1), $descriptor, %newpointer_flags)); } +%typemap(varout, noblock=1) SWIGTYPE && { + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(&$1), $descriptor, %newpointer_flags)); +} + /* Value */ %typemap(varout, noblock=1) SWIGTYPE { %set_varoutput(SWIG_NewPointerObj(%as_voidptr(&$1), $&descriptor, %newpointer_flags)); @@ -311,12 +362,23 @@ $1 = SWIG_CheckState(res); } +%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) SWIGTYPE && { + void *vptr = 0; + int res = SWIG_ConvertPtr($input, &vptr, $descriptor, 0); + $1 = SWIG_CheckState(res); +} + #if defined(__cplusplus) && defined(%implicitconv_flag) %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1,implicitconv=1) const SWIGTYPE & { int res = SWIG_ConvertPtr($input, 0, $descriptor, %implicitconv_flag); $1 = SWIG_CheckState(res); } +%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1,implicitconv=1) const SWIGTYPE && { + int res = SWIG_ConvertPtr($input, 0, $descriptor, %implicitconv_flag); + $1 = SWIG_CheckState(res); +} + %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1,implicitconv=1) SWIGTYPE { int res = SWIG_ConvertPtr($input, 0, $&descriptor, %implicitconv_flag); $1 = SWIG_CheckState(res); @@ -327,6 +389,11 @@ int res = SWIG_ConvertPtr($input, &vptr, $descriptor, 0); $1 = SWIG_CheckState(res); } +%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) const SWIGTYPE && { + 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; @@ -355,6 +422,10 @@ $input = SWIG_NewPointerObj(%as_voidptr(&$1_name), $descriptor, %newpointer_flags); } +%typemap(directorin,noblock=1) SWIGTYPE && { + $input = SWIG_NewPointerObj(%as_voidptr(&$1_name), $descriptor, %newpointer_flags); +} + /* directorout */ #if defined(__cplusplus) && defined(%implicitconv_flag) %typemap(directorout,noblock=1,implicitconv=1) SWIGTYPE (void * swig_argp, int swig_res = 0) { @@ -406,6 +477,22 @@ } } +%typemap(directorout,noblock=1,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) + SWIGTYPE &&(void *swig_argp, int swig_res, swig_owntype own) { + swig_res = SWIG_ConvertPtrAndOwn($input, &swig_argp, $descriptor, %convertptr_flags | SWIG_POINTER_DISOWN, &own); + if (!SWIG_IsOK(swig_res)) { + %dirout_fail(swig_res,"$type"); + } + if (!swig_argp) { %dirout_nullref("$type"); } + $result = %reinterpret_cast(swig_argp, $ltype); + swig_acquire_ownership_obj(%as_voidptr($result), own /* & TODO: SWIG_POINTER_OWN */); +} +%typemap(directorfree,noblock=1,match="directorout") SWIGTYPE && { + if (director) { + SWIG_AcquirePtr($result, director->swig_release_ownership(%as_voidptr($input))); + } +} + #endif /* SWIG_DIRECTOR_TYPEMAPS */ @@ -413,7 +500,7 @@ * --- Constants --- * ------------------------------------------------------------ */ -%typemap(constcode,noblock=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { +%typemap(constcode,noblock=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { %set_constant("$symname", SWIG_NewPointerObj(%as_voidptr($value),$descriptor,%newpointer_flags)); } @@ -441,6 +528,10 @@ %raise(SWIG_NewPointerObj(%as_voidptr(&$1),$descriptor,0), "$type", $descriptor); } +%typemap(throws,noblock=1) SWIGTYPE && { + %raise(SWIG_NewPointerObj(%as_voidptr(&$1),$descriptor,0), "$type", $descriptor); +} + %typemap(throws,noblock=1) (...) { SWIG_exception_fail(SWIG_RuntimeError,"unknown exception"); } From 34d46510cfbcecdeb4fd1a98a2957ecfe5a2db6a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Jan 2013 20:53:32 +0000 Subject: [PATCH 0428/1160] Variadic templates doc update --- Doc/Manual/Cpp0x.html | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index fa895cc6b..0200fdf5c 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -511,23 +511,27 @@ public: } -

      Support for the variadic sizeof() function was also introduced:

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

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

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

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

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

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

      +

      7.2.18 New string literals

      From 38d454a1022f65d76e292fd13d699da896c0c2cf Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 25 Jan 2013 19:18:12 +0100 Subject: [PATCH 0429/1160] Fix MAKE variable expansion in pcre-build.sh. Correct the syntax used in 0e32be2, it's ${var:-fallback}. --- Tools/pcre-build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tools/pcre-build.sh b/Tools/pcre-build.sh index 4af7deca3..92f645da2 100755 --- a/Tools/pcre-build.sh +++ b/Tools/pcre-build.sh @@ -48,8 +48,8 @@ echo "Configuring PCRE in directory: pcre" mv $pcre_dir pcre || bail "Could not create pcre directory" cd pcre && ./configure --prefix=$pcre_install_dir --disable-shared $* || bail "PCRE configure failed" echo "Building PCRE..." -${MAKE:make} -s || bail "Could not build PCRE" +${MAKE:-make} -s || bail "Could not build PCRE" echo "Installing PCRE locally to $pcre_install_dir..." -${MAKE:make} -s install || bail "Could not install PCRE" +${MAKE:-make} -s install || bail "Could not install PCRE" echo "" echo "The SWIG configure script can now be run, whereupon PCRE will automatically be detected and used from $pcre_install_dir/bin/pcre-config." From 32f8248e243d8296ff3a5a24b392a645b104abdc Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 28 Jan 2013 07:06:37 +0000 Subject: [PATCH 0430/1160] Fix shift/shift and shift/reduce errors around variadic templates since merge --- Source/CParse/parser.y | 48 ++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index ed698e4ca..f5b5f6e2b 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1772,7 +1772,8 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type

      typemap_parm tm_list tm_tail ; %type

      templateparameter ; %type templcpptype cpptype access_specifier; -%type base_specifier +%type base_specifier; +%type ellipsis variadic; %type type rawtype type_right anon_bitfield_type decltype ; %type base_list inherit raw_inherit; %type definetype def_args etype; @@ -6429,6 +6430,19 @@ exprcompound : expr PLUS expr { } ; +ellipsis : PERIOD PERIOD PERIOD { + $$ = NewString("..."); + } + ; + +variadic : ellipsis { + $$ = $1; + } + | empty { + $$ = 0; + } + ; + inherit : raw_inherit { $$ = $1; } @@ -6466,7 +6480,7 @@ base_list : base_specifier { base_specifier : opt_virtual { $$ = cparse_line; - } idcolon { + } idcolon variadic { $$ = NewHash(); Setfile($$,cparse_file); Setline($$,$2); @@ -6479,10 +6493,12 @@ base_specifier : opt_virtual { } else { Setattr($$,"access","public"); } + if ($4) + SetFlag($$, "variadic"); } | opt_virtual access_specifier { $$ = cparse_line; - } opt_virtual idcolon { + } opt_virtual idcolon variadic { $$ = NewHash(); Setfile($$,cparse_file); Setline($$,$3); @@ -6493,30 +6509,8 @@ base_specifier : opt_virtual { if (Strcmp($2,"public") != 0) { Swig_warning(WARN_PARSE_PRIVATE_INHERIT, Getfile($$), Getline($$), "%s inheritance from base '%s' (ignored).\n", $2, SwigType_namestr($5)); } - } - | opt_virtual idcolon PERIOD PERIOD PERIOD { /* Variadic inheritance */ - $$ = NewHash(); - Setfile($$,cparse_file); - Setline($$,cparse_line); - Setattr($$,"name",$2); - if (last_cpptype && (Strcmp(last_cpptype,"struct") != 0)) { - Setattr($$,"access","private"); - Swig_warning(WARN_PARSE_NO_ACCESS,cparse_file,cparse_line, - "No access specifier given for base class %s (ignored).\n",$2); - } else { - Setattr($$,"access","public"); - } - } - | opt_virtual access_specifier opt_virtual idcolon PERIOD PERIOD PERIOD { /* Variadic inheritance */ - $$ = NewHash(); - Setfile($$,cparse_file); - Setline($$,cparse_line); - Setattr($$,"name",$4); - Setattr($$,"access",$2); - if (Strcmp($2,"public") != 0) { - Swig_warning(WARN_PARSE_PRIVATE_INHERIT, cparse_file, - cparse_line,"%s inheritance ignored.\n", $2); - } + if ($6) + SetFlag($$, "variadic"); } ; From 2a90cc6a9807c2cd136befaada1ff91276e7d01c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 28 Jan 2013 07:11:08 +0000 Subject: [PATCH 0431/1160] Remove generated output that should not be checked in2 --- .../python/cpp0x_unrestricted_unions_wrap.cxx | 4046 ----------------- 1 file changed, 4046 deletions(-) delete mode 100644 Examples/test-suite/python/cpp0x_unrestricted_unions_wrap.cxx diff --git a/Examples/test-suite/python/cpp0x_unrestricted_unions_wrap.cxx b/Examples/test-suite/python/cpp0x_unrestricted_unions_wrap.cxx deleted file mode 100644 index 071bb660d..000000000 --- a/Examples/test-suite/python/cpp0x_unrestricted_unions_wrap.cxx +++ /dev/null @@ -1,4046 +0,0 @@ -/* ---------------------------------------------------------------------------- - * 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. - * ----------------------------------------------------------------------------- */ - -#define SWIGPYTHON -#define SWIG_PYTHON_DIRECTOR_NO_VTABLE - - -#ifdef __cplusplus -/* SwigValueWrapper is described in swig.swg */ -template class SwigValueWrapper { - struct SwigMovePointer { - T *ptr; - SwigMovePointer(T *p) : ptr(p) { } - ~SwigMovePointer() { delete ptr; } - SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; } - } pointer; - SwigValueWrapper& operator=(const SwigValueWrapper& rhs); - SwigValueWrapper(const SwigValueWrapper& rhs); -public: - SwigValueWrapper() : pointer(0) { } - SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; } - operator T&() const { return *pointer.ptr; } - T *operator&() { return pointer.ptr; } -}; - -template T SwigValueInit() { - return T(); -} -#endif - -/* ----------------------------------------------------------------------------- - * 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) && (__SUNPRO_CC <= 0x560) -# define SWIGTEMPLATEDISAMBIGUATOR template -# elif defined(__HP_aCC) -/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ -/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ -# define SWIGTEMPLATEDISAMBIGUATOR template -# 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 SWIG_MSC_UNSUPPRESS_4505 -# if defined(_MSC_VER) -# pragma warning(disable : 4505) /* unreferenced local function has been removed */ -# 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 */ -#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) -# ifndef GCC_HASCLASSVISIBILITY -# define GCC_HASCLASSVISIBILITY -# endif -#endif - -#ifndef SWIGEXPORT -# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# if defined(STATIC_LINKED) -# define SWIGEXPORT -# else -# define SWIGEXPORT __declspec(dllexport) -# endif -# else -# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) -# define SWIGEXPORT __attribute__ ((visibility("default"))) -# else -# define SWIGEXPORT -# endif -# endif -#endif - -/* calling conventions for Windows */ -#ifndef SWIGSTDCALL -# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# define SWIGSTDCALL __stdcall -# else -# define SWIGSTDCALL -# endif -#endif - -/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ -#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) -# define _CRT_SECURE_NO_DEPRECATE -#endif - -/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ -#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) -# define _SCL_SECURE_NO_DEPRECATE -#endif - - - -/* Python.h has to appear first */ -#include - -/* ----------------------------------------------------------------------------- - * swigrun.swg - * - * This file contains generic C API 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 "4" - -/* 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 strictly necessary, ie, if you have problems - with your compiler or suchlike. -*/ - -#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 -#define SWIG_CAST_NEW_MEMORY 0x2 - -/* Flags for new pointer objects */ -#define SWIG_POINTER_OWN 0x1 - - -/* - Flags/methods for returning states. - - 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). - - Use the following macros/flags to set or process the returning - states. - - In old versions of SWIG, code such as the following was usually written: - - if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { - // success code - } else { - //fail code - } - - Now you can be more explicit: - - int res = SWIG_ConvertPtr(obj,vptr,ty.flags); - if (SWIG_IsOK(res)) { - // success code - } else { - // fail code - } - - which is the same really, 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 - also requires SWIG_ConvertPtr to return new result values, such 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) -#define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) - -/* 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 *, int *); -typedef struct swig_type_info *(*swig_dycast_func)(void **); - -/* Structure to store information 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 (*f1 > *f2) ? 1 : -1; - } - return (int)((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; -} - - -/* - Check the typename -*/ -SWIGRUNTIME swig_cast_info * -SWIG_TypeCheck(const char *c, swig_type_info *ty) { - if (ty) { - swig_cast_info *iter = ty->cast; - while (iter) { - if (strcmp(iter->type->name, c) == 0) { - 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; -} - -/* - Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison -*/ -SWIGRUNTIME swig_cast_info * -SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) { - if (ty) { - swig_cast_info *iter = ty->cast; - while (iter) { - if (iter->type == from) { - 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; -} - -/* - Cast a pointer up an inheritance hierarchy -*/ -SWIGRUNTIMEINLINE void * -SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { - return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); -} - -/* - 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 - -/* 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 - - - -/* Compatibility macros for Python 3 */ -#if PY_VERSION_HEX >= 0x03000000 - -#define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type) -#define PyInt_Check(x) PyLong_Check(x) -#define PyInt_AsLong(x) PyLong_AsLong(x) -#define PyInt_FromLong(x) PyLong_FromLong(x) -#define PyString_Format(fmt, args) PyUnicode_Format(fmt, args) - -#endif - -#ifndef Py_TYPE -# define Py_TYPE(op) ((op)->ob_type) -#endif - -/* SWIG APIs for compatibility of both Python 2 & 3 */ - -#if PY_VERSION_HEX >= 0x03000000 -# define SWIG_Python_str_FromFormat PyUnicode_FromFormat -#else -# define SWIG_Python_str_FromFormat PyString_FromFormat -#endif - - -/* Warning: This function will allocate a new string in Python 3, - * so please call SWIG_Python_str_DelForPy3(x) to free the space. - */ -SWIGINTERN char* -SWIG_Python_str_AsChar(PyObject *str) -{ -#if PY_VERSION_HEX >= 0x03000000 - char *cstr; - char *newstr; - Py_ssize_t len; - str = PyUnicode_AsUTF8String(str); - PyBytes_AsStringAndSize(str, &cstr, &len); - newstr = (char *) malloc(len+1); - memcpy(newstr, cstr, len+1); - Py_XDECREF(str); - return newstr; -#else - return PyString_AsString(str); -#endif -} - -#if PY_VERSION_HEX >= 0x03000000 -# define SWIG_Python_str_DelForPy3(x) free( (void*) (x) ) -#else -# define SWIG_Python_str_DelForPy3(x) -#endif - - -SWIGINTERN PyObject* -SWIG_Python_str_FromChar(const char *c) -{ -#if PY_VERSION_HEX >= 0x03000000 - return PyUnicode_FromString(c); -#else - return PyString_FromString(c); -#endif -} - -/* Add PyOS_snprintf for old Pythons */ -#if PY_VERSION_HEX < 0x02020000 -# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) -# define PyOS_snprintf _snprintf -# else -# define PyOS_snprintf snprintf -# endif -#endif - -/* A crude PyString_FromFormat implementation for old Pythons */ -#if PY_VERSION_HEX < 0x02020000 - -#ifndef SWIG_PYBUFFER_SIZE -# define SWIG_PYBUFFER_SIZE 1024 -#endif - -static PyObject * -PyString_FromFormat(const char *fmt, ...) { - va_list ap; - char buf[SWIG_PYBUFFER_SIZE * 2]; - int res; - va_start(ap, fmt); - res = vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf); -} -#endif - -/* Add PyObject_Del for old Pythons */ -#if PY_VERSION_HEX < 0x01060000 -# define PyObject_Del(op) PyMem_DEL((op)) -#endif -#ifndef PyObject_DEL -# define PyObject_DEL PyObject_Del -#endif - -/* A crude PyExc_StopIteration exception for old Pythons */ -#if PY_VERSION_HEX < 0x02020000 -# ifndef PyExc_StopIteration -# define PyExc_StopIteration PyExc_RuntimeError -# endif -# ifndef PyObject_GenericGetAttr -# define PyObject_GenericGetAttr 0 -# endif -#endif - -/* Py_NotImplemented is defined in 2.1 and up. */ -#if PY_VERSION_HEX < 0x02010000 -# ifndef Py_NotImplemented -# define Py_NotImplemented PyExc_RuntimeError -# endif -#endif - -/* A crude PyString_AsStringAndSize implementation for old Pythons */ -#if PY_VERSION_HEX < 0x02010000 -# ifndef PyString_AsStringAndSize -# define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;} -# endif -#endif - -/* PySequence_Size for old Pythons */ -#if PY_VERSION_HEX < 0x02000000 -# ifndef PySequence_Size -# define PySequence_Size PySequence_Length -# endif -#endif - -/* PyBool_FromLong for old Pythons */ -#if PY_VERSION_HEX < 0x02030000 -static -PyObject *PyBool_FromLong(long ok) -{ - PyObject *result = ok ? Py_True : Py_False; - Py_INCREF(result); - return result; -} -#endif - -/* Py_ssize_t for old Pythons */ -/* This code is as recommended by: */ -/* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */ -#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) -typedef int Py_ssize_t; -# define PY_SSIZE_T_MAX INT_MAX -# define PY_SSIZE_T_MIN INT_MIN -#endif - -/* ----------------------------------------------------------------------------- - * error manipulation - * ----------------------------------------------------------------------------- */ - -SWIGRUNTIME PyObject* -SWIG_Python_ErrorType(int code) { - PyObject* type = 0; - switch(code) { - case SWIG_MemoryError: - type = PyExc_MemoryError; - break; - case SWIG_IOError: - type = PyExc_IOError; - break; - case SWIG_RuntimeError: - type = PyExc_RuntimeError; - break; - case SWIG_IndexError: - type = PyExc_IndexError; - break; - case SWIG_TypeError: - type = PyExc_TypeError; - break; - case SWIG_DivisionByZero: - type = PyExc_ZeroDivisionError; - break; - case SWIG_OverflowError: - type = PyExc_OverflowError; - break; - case SWIG_SyntaxError: - type = PyExc_SyntaxError; - break; - case SWIG_ValueError: - type = PyExc_ValueError; - break; - case SWIG_SystemError: - type = PyExc_SystemError; - break; - case SWIG_AttributeError: - type = PyExc_AttributeError; - break; - default: - type = PyExc_RuntimeError; - } - return type; -} - - -SWIGRUNTIME void -SWIG_Python_AddErrorMsg(const char* mesg) -{ - PyObject *type = 0; - PyObject *value = 0; - PyObject *traceback = 0; - - if (PyErr_Occurred()) PyErr_Fetch(&type, &value, &traceback); - if (value) { - char *tmp; - PyObject *old_str = PyObject_Str(value); - PyErr_Clear(); - Py_XINCREF(type); - - PyErr_Format(type, "%s %s", tmp = SWIG_Python_str_AsChar(old_str), mesg); - SWIG_Python_str_DelForPy3(tmp); - Py_DECREF(old_str); - Py_DECREF(value); - } else { - PyErr_SetString(PyExc_RuntimeError, mesg); - } -} - -#if defined(SWIG_PYTHON_NO_THREADS) -# if defined(SWIG_PYTHON_THREADS) -# undef SWIG_PYTHON_THREADS -# endif -#endif -#if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */ -# if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL) -# if (PY_VERSION_HEX >= 0x02030000) /* For 2.3 or later, use the PyGILState calls */ -# define SWIG_PYTHON_USE_GIL -# endif -# endif -# if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */ -# ifndef SWIG_PYTHON_INITIALIZE_THREADS -# define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads() -# endif -# ifdef __cplusplus /* C++ code */ - class SWIG_Python_Thread_Block { - bool status; - PyGILState_STATE state; - public: - void end() { if (status) { PyGILState_Release(state); status = false;} } - SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {} - ~SWIG_Python_Thread_Block() { end(); } - }; - class SWIG_Python_Thread_Allow { - bool status; - PyThreadState *save; - public: - void end() { if (status) { PyEval_RestoreThread(save); status = false; }} - SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} - ~SWIG_Python_Thread_Allow() { end(); } - }; -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block -# define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow -# define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end() -# else /* C code */ -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure() -# define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block) -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread() -# define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow) -# endif -# else /* Old thread way, not implemented, user must provide it */ -# if !defined(SWIG_PYTHON_INITIALIZE_THREADS) -# define SWIG_PYTHON_INITIALIZE_THREADS -# endif -# if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK) -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK -# endif -# if !defined(SWIG_PYTHON_THREAD_END_BLOCK) -# define SWIG_PYTHON_THREAD_END_BLOCK -# endif -# if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW) -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW -# endif -# if !defined(SWIG_PYTHON_THREAD_END_ALLOW) -# define SWIG_PYTHON_THREAD_END_ALLOW -# endif -# endif -#else /* No thread support */ -# define SWIG_PYTHON_INITIALIZE_THREADS -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK -# define SWIG_PYTHON_THREAD_END_BLOCK -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW -# define SWIG_PYTHON_THREAD_END_ALLOW -#endif - -/* ----------------------------------------------------------------------------- - * Python API portion that goes into the runtime - * ----------------------------------------------------------------------------- */ - -#ifdef __cplusplus -extern "C" { -#if 0 -} /* cc-mode */ -#endif -#endif - -/* ----------------------------------------------------------------------------- - * Constant declarations - * ----------------------------------------------------------------------------- */ - -/* Constant Types */ -#define SWIG_PY_POINTER 4 -#define SWIG_PY_BINARY 5 - -/* 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; - - -/* ----------------------------------------------------------------------------- - * Wrapper of PyInstanceMethod_New() used in Python 3 - * It is exported to the generated module, used for -fastproxy - * ----------------------------------------------------------------------------- */ -SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *self, PyObject *func) -{ -#if PY_VERSION_HEX >= 0x03000000 - return PyInstanceMethod_New(func); -#else - return NULL; -#endif -} - -#ifdef __cplusplus -#if 0 -{ /* cc-mode */ -#endif -} -#endif - - -/* ----------------------------------------------------------------------------- - * pyrun.swg - * - * This file contains the runtime support for Python modules - * and includes code for managing global variables and pointer - * type checking. - * - * ----------------------------------------------------------------------------- */ - -/* 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) SwigPyClientData_New(obj) - -#define SWIG_SetErrorObj SWIG_Python_SetErrorObj -#define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg -#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) -#define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) -#define SWIG_fail goto fail - - -/* Runtime API implementation */ - -/* Error manipulation */ - -SWIGINTERN void -SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) { - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetObject(errtype, obj); - Py_DECREF(obj); - SWIG_PYTHON_THREAD_END_BLOCK; -} - -SWIGINTERN void -SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetString(errtype, (char *) msg); - SWIG_PYTHON_THREAD_END_BLOCK; -} - -#define SWIG_Python_Raise(obj, type, desc) SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj) - -/* Set a constant value */ - -SWIGINTERN void -SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { - PyDict_SetItemString(d, (char*) name, obj); - Py_DECREF(obj); -} - -/* Append a value to the result obj */ - -SWIGINTERN PyObject* -SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { -#if !defined(SWIG_PYTHON_OUTPUT_TUPLE) - 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; -#else - PyObject* o2; - PyObject* o3; - if (!result) { - result = obj; - } else if (result == Py_None) { - Py_DECREF(result); - result = obj; - } else { - if (!PyTuple_Check(result)) { - o2 = result; - result = PyTuple_New(1); - PyTuple_SET_ITEM(result, 0, o2); - } - o3 = PyTuple_New(1); - PyTuple_SET_ITEM(o3, 0, obj); - o2 = result; - result = PySequence_Concat(o2, o3); - Py_DECREF(o2); - Py_DECREF(o3); - } - return result; -#endif -} - -/* Unpack the argument tuple */ - -SWIGINTERN int -SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs) -{ - if (!args) { - if (!min && !max) { - return 1; - } else { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", - name, (min == max ? "" : "at least "), (int)min); - return 0; - } - } - if (!PyTuple_Check(args)) { - PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); - return 0; - } else { - register Py_ssize_t l = PyTuple_GET_SIZE(args); - if (l < min) { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", - name, (min == max ? "" : "at least "), (int)min, (int)l); - return 0; - } else if (l > max) { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", - name, (min == max ? "" : "at most "), (int)max, (int)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; - } - } -} - -/* 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 - -/* - 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) - -#ifdef __cplusplus -extern "C" { -#if 0 -} /* cc-mode */ -#endif -#endif - -/* How to access Py_None */ -#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# ifndef SWIG_PYTHON_NO_BUILD_NONE -# ifndef SWIG_PYTHON_BUILD_NONE -# define SWIG_PYTHON_BUILD_NONE -# endif -# endif -#endif - -#ifdef SWIG_PYTHON_BUILD_NONE -# ifdef Py_None -# undef Py_None -# define Py_None SWIG_Py_None() -# endif -SWIGRUNTIMEINLINE PyObject * -_SWIG_Py_None(void) -{ - PyObject *none = Py_BuildValue((char*)""); - Py_DECREF(none); - return none; -} -SWIGRUNTIME PyObject * -SWIG_Py_None(void) -{ - static PyObject *SWIG_STATIC_POINTER(none) = _SWIG_Py_None(); - return none; -} -#endif - -/* The python void return value */ - -SWIGRUNTIMEINLINE PyObject * -SWIG_Py_Void(void) -{ - PyObject *none = Py_None; - Py_INCREF(none); - return none; -} - -/* SwigPyClientData */ - -typedef struct { - PyObject *klass; - PyObject *newraw; - PyObject *newargs; - PyObject *destroy; - int delargs; - int implicitconv; -} SwigPyClientData; - -SWIGRUNTIMEINLINE int -SWIG_Python_CheckImplicit(swig_type_info *ty) -{ - SwigPyClientData *data = (SwigPyClientData *)ty->clientdata; - return data ? data->implicitconv : 0; -} - -SWIGRUNTIMEINLINE PyObject * -SWIG_Python_ExceptionType(swig_type_info *desc) { - SwigPyClientData *data = desc ? (SwigPyClientData *) desc->clientdata : 0; - PyObject *klass = data ? data->klass : 0; - return (klass ? klass : PyExc_RuntimeError); -} - - -SWIGRUNTIME SwigPyClientData * -SwigPyClientData_New(PyObject* obj) -{ - if (!obj) { - return 0; - } else { - SwigPyClientData *data = (SwigPyClientData *)malloc(sizeof(SwigPyClientData)); - /* the klass element */ - data->klass = obj; - Py_INCREF(data->klass); - /* 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; -#else - data->newraw = PyObject_GetAttrString(data->klass, (char *)"__new__"); -#endif - if (data->newraw) { - Py_INCREF(data->newraw); - data->newargs = PyTuple_New(1); - PyTuple_SetItem(data->newargs, 0, obj); - } else { - data->newargs = obj; - } - Py_INCREF(data->newargs); - } - /* the destroy method, aka as the C++ delete method */ - data->destroy = PyObject_GetAttrString(data->klass, (char *)"__swig_destroy__"); - if (PyErr_Occurred()) { - PyErr_Clear(); - data->destroy = 0; - } - if (data->destroy) { - int flags; - Py_INCREF(data->destroy); - 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 -SwigPyClientData_Del(SwigPyClientData* data) -{ - Py_XDECREF(data->newraw); - Py_XDECREF(data->newargs); - Py_XDECREF(data->destroy); -} - -/* =============== SwigPyObject =====================*/ - -typedef struct { - PyObject_HEAD - void *ptr; - swig_type_info *ty; - int own; - PyObject *next; -} SwigPyObject; - -SWIGRUNTIME PyObject * -SwigPyObject_long(SwigPyObject *v) -{ - return PyLong_FromVoidPtr(v->ptr); -} - -SWIGRUNTIME PyObject * -SwigPyObject_format(const char* fmt, SwigPyObject *v) -{ - PyObject *res = NULL; - PyObject *args = PyTuple_New(1); - if (args) { - if (PyTuple_SetItem(args, 0, SwigPyObject_long(v)) == 0) { - PyObject *ofmt = SWIG_Python_str_FromChar(fmt); - if (ofmt) { -#if PY_VERSION_HEX >= 0x03000000 - res = PyUnicode_Format(ofmt,args); -#else - res = PyString_Format(ofmt,args); -#endif - Py_DECREF(ofmt); - } - Py_DECREF(args); - } - } - return res; -} - -SWIGRUNTIME PyObject * -SwigPyObject_oct(SwigPyObject *v) -{ - return SwigPyObject_format("%o",v); -} - -SWIGRUNTIME PyObject * -SwigPyObject_hex(SwigPyObject *v) -{ - return SwigPyObject_format("%x",v); -} - -SWIGRUNTIME PyObject * -#ifdef METH_NOARGS -SwigPyObject_repr(SwigPyObject *v) -#else -SwigPyObject_repr(SwigPyObject *v, PyObject *args) -#endif -{ - const char *name = SWIG_TypePrettyName(v->ty); - PyObject *repr = SWIG_Python_str_FromFormat("", name, v); - if (v->next) { -#ifdef METH_NOARGS - PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next); -#else - PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next, args); -#endif -#if PY_VERSION_HEX >= 0x03000000 - PyObject *joined = PyUnicode_Concat(repr, nrep); - Py_DecRef(repr); - Py_DecRef(nrep); - repr = joined; -#else - PyString_ConcatAndDel(&repr,nrep); -#endif - } - return repr; -} - -SWIGRUNTIME int -SwigPyObject_print(SwigPyObject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) -{ - char *str; -#ifdef METH_NOARGS - PyObject *repr = SwigPyObject_repr(v); -#else - PyObject *repr = SwigPyObject_repr(v, NULL); -#endif - if (repr) { - str = SWIG_Python_str_AsChar(repr); - fputs(str, fp); - SWIG_Python_str_DelForPy3(str); - Py_DECREF(repr); - return 0; - } else { - return 1; - } -} - -SWIGRUNTIME PyObject * -SwigPyObject_str(SwigPyObject *v) -{ - char result[SWIG_BUFFER_SIZE]; - return SWIG_PackVoidPtr(result, v->ptr, v->ty->name, sizeof(result)) ? - SWIG_Python_str_FromChar(result) : 0; -} - -SWIGRUNTIME int -SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w) -{ - void *i = v->ptr; - void *j = w->ptr; - return (i < j) ? -1 : ((i > j) ? 1 : 0); -} - -/* Added for Python 3.x, would it also be useful for Python 2.x? */ -SWIGRUNTIME PyObject* -SwigPyObject_richcompare(SwigPyObject *v, SwigPyObject *w, int op) -{ - PyObject* res; - if( op != Py_EQ && op != Py_NE ) { - Py_INCREF(Py_NotImplemented); - return Py_NotImplemented; - } - if( (SwigPyObject_compare(v, w)==0) == (op == Py_EQ) ) - res = Py_True; - else - res = Py_False; - Py_INCREF(res); - return res; -} - - -SWIGRUNTIME PyTypeObject* _PySwigObject_type(void); - -SWIGRUNTIME PyTypeObject* -SwigPyObject_type(void) { - static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigObject_type(); - return type; -} - -SWIGRUNTIMEINLINE int -SwigPyObject_Check(PyObject *op) { - return (Py_TYPE(op) == SwigPyObject_type()) - || (strcmp(Py_TYPE(op)->tp_name,"SwigPyObject") == 0); -} - -SWIGRUNTIME PyObject * -SwigPyObject_New(void *ptr, swig_type_info *ty, int own); - -SWIGRUNTIME void -SwigPyObject_dealloc(PyObject *v) -{ - SwigPyObject *sobj = (SwigPyObject *) v; - PyObject *next = sobj->next; - if (sobj->own == SWIG_POINTER_OWN) { - swig_type_info *ty = sobj->ty; - SwigPyClientData *data = ty ? (SwigPyClientData *) 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 temporary object to carry the destroy operation */ - PyObject *tmp = SwigPyObject_New(sobj->ptr, ty, 0); - res = SWIG_Python_CallFunctor(destroy, tmp); - Py_DECREF(tmp); - } else { - PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); - PyObject *mself = PyCFunction_GET_SELF(destroy); - res = ((*meth)(mself, v)); - } - Py_XDECREF(res); - } -#if !defined(SWIG_PYTHON_SILENT_MEMLEAK) - else { - const char *name = SWIG_TypePrettyName(ty); - printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); - } -#endif - } - Py_XDECREF(next); - PyObject_DEL(v); -} - -SWIGRUNTIME PyObject* -SwigPyObject_append(PyObject* v, PyObject* next) -{ - SwigPyObject *sobj = (SwigPyObject *) v; -#ifndef METH_O - PyObject *tmp = 0; - if (!PyArg_ParseTuple(next,(char *)"O:append", &tmp)) return NULL; - next = tmp; -#endif - if (!SwigPyObject_Check(next)) { - return NULL; - } - sobj->next = next; - Py_INCREF(next); - return SWIG_Py_Void(); -} - -SWIGRUNTIME PyObject* -#ifdef METH_NOARGS -SwigPyObject_next(PyObject* v) -#else -SwigPyObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -#endif -{ - SwigPyObject *sobj = (SwigPyObject *) v; - if (sobj->next) { - Py_INCREF(sobj->next); - return sobj->next; - } else { - return SWIG_Py_Void(); - } -} - -SWIGINTERN PyObject* -#ifdef METH_NOARGS -SwigPyObject_disown(PyObject *v) -#else -SwigPyObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -#endif -{ - SwigPyObject *sobj = (SwigPyObject *)v; - sobj->own = 0; - return SWIG_Py_Void(); -} - -SWIGINTERN PyObject* -#ifdef METH_NOARGS -SwigPyObject_acquire(PyObject *v) -#else -SwigPyObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -#endif -{ - SwigPyObject *sobj = (SwigPyObject *)v; - sobj->own = SWIG_POINTER_OWN; - return SWIG_Py_Void(); -} - -SWIGINTERN PyObject* -SwigPyObject_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 - { - SwigPyObject *sobj = (SwigPyObject *)v; - PyObject *obj = PyBool_FromLong(sobj->own); - if (val) { -#ifdef METH_NOARGS - if (PyObject_IsTrue(val)) { - SwigPyObject_acquire(v); - } else { - SwigPyObject_disown(v); - } -#else - if (PyObject_IsTrue(val)) { - SwigPyObject_acquire(v,args); - } else { - SwigPyObject_disown(v,args); - } -#endif - } - return obj; - } -} - -#ifdef METH_O -static PyMethodDef -swigobject_methods[] = { - {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, - {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_NOARGS, (char *)"aquires ownership of the pointer"}, - {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, - {(char *)"append", (PyCFunction)SwigPyObject_append, METH_O, (char *)"appends another 'this' object"}, - {(char *)"next", (PyCFunction)SwigPyObject_next, METH_NOARGS, (char *)"returns the next 'this' object"}, - {(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_NOARGS, (char *)"returns object representation"}, - {0, 0, 0, 0} -}; -#else -static PyMethodDef -swigobject_methods[] = { - {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_VARARGS, (char *)"releases ownership of the pointer"}, - {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_VARARGS, (char *)"aquires ownership of the pointer"}, - {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, - {(char *)"append", (PyCFunction)SwigPyObject_append, METH_VARARGS, (char *)"appends another 'this' object"}, - {(char *)"next", (PyCFunction)SwigPyObject_next, METH_VARARGS, (char *)"returns the next 'this' object"}, - {(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_VARARGS, (char *)"returns object representation"}, - {0, 0, 0, 0} -}; -#endif - -#if PY_VERSION_HEX < 0x02020000 -SWIGINTERN PyObject * -SwigPyObject_getattr(SwigPyObject *sobj,char *name) -{ - return Py_FindMethod(swigobject_methods, (PyObject *)sobj, name); -} -#endif - -SWIGRUNTIME PyTypeObject* -_PySwigObject_type(void) { - static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; - - static PyNumberMethods SwigPyObject_as_number = { - (binaryfunc)0, /*nb_add*/ - (binaryfunc)0, /*nb_subtract*/ - (binaryfunc)0, /*nb_multiply*/ - /* nb_divide removed in Python 3 */ -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc)0, /*nb_divide*/ -#endif - (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*/ -#if PY_VERSION_HEX < 0x03000000 - 0, /*nb_coerce*/ -#endif - (unaryfunc)SwigPyObject_long, /*nb_int*/ -#if PY_VERSION_HEX < 0x03000000 - (unaryfunc)SwigPyObject_long, /*nb_long*/ -#else - 0, /*nb_reserved*/ -#endif - (unaryfunc)0, /*nb_float*/ -#if PY_VERSION_HEX < 0x03000000 - (unaryfunc)SwigPyObject_oct, /*nb_oct*/ - (unaryfunc)SwigPyObject_hex, /*nb_hex*/ -#endif -#if PY_VERSION_HEX >= 0x03000000 /* 3.0 */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index, nb_inplace_divide removed */ -#elif PY_VERSION_HEX >= 0x02050000 /* 2.5.0 */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */ -#elif PY_VERSION_HEX >= 0x02020000 /* 2.2.0 */ - 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 /* 2.0.0 */ - 0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_or */ -#endif - }; - - static PyTypeObject swigpyobject_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp - = { - /* PyObject header changed in Python 3 */ -#if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ -#endif - (char *)"SwigPyObject", /* tp_name */ - sizeof(SwigPyObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)SwigPyObject_dealloc, /* tp_dealloc */ - (printfunc)SwigPyObject_print, /* tp_print */ -#if PY_VERSION_HEX < 0x02020000 - (getattrfunc)SwigPyObject_getattr, /* tp_getattr */ -#else - (getattrfunc)0, /* tp_getattr */ -#endif - (setattrfunc)0, /* tp_setattr */ -#if PY_VERSION_HEX >= 0x03000000 - 0, /* tp_reserved in 3.0.1, tp_compare in 3.0.0 but not used */ -#else - (cmpfunc)SwigPyObject_compare, /* tp_compare */ -#endif - (reprfunc)SwigPyObject_repr, /* tp_repr */ - &SwigPyObject_as_number, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)SwigPyObject_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 */ - (richcmpfunc)SwigPyObject_richcompare, /* 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 */ - 0, /* 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 - }; - swigpyobject_type = tmp; - /* for Python 3 we already assigned ob_type in PyVarObject_HEAD_INIT() */ -#if PY_VERSION_HEX < 0x03000000 - swigpyobject_type.ob_type = &PyType_Type; -#endif - type_init = 1; - } - return &swigpyobject_type; -} - -SWIGRUNTIME PyObject * -SwigPyObject_New(void *ptr, swig_type_info *ty, int own) -{ - SwigPyObject *sobj = PyObject_NEW(SwigPyObject, SwigPyObject_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; -} SwigPyPacked; - -SWIGRUNTIME int -SwigPyPacked_print(SwigPyPacked *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 * -SwigPyPacked_repr(SwigPyPacked *v) -{ - char result[SWIG_BUFFER_SIZE]; - if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { - return SWIG_Python_str_FromFormat("", result, v->ty->name); - } else { - return SWIG_Python_str_FromFormat("", v->ty->name); - } -} - -SWIGRUNTIME PyObject * -SwigPyPacked_str(SwigPyPacked *v) -{ - char result[SWIG_BUFFER_SIZE]; - if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ - return SWIG_Python_str_FromFormat("%s%s", result, v->ty->name); - } else { - return SWIG_Python_str_FromChar(v->ty->name); - } -} - -SWIGRUNTIME int -SwigPyPacked_compare(SwigPyPacked *v, SwigPyPacked *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* -SwigPyPacked_type(void) { - static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigPacked_type(); - return type; -} - -SWIGRUNTIMEINLINE int -SwigPyPacked_Check(PyObject *op) { - return ((op)->ob_type == _PySwigPacked_type()) - || (strcmp((op)->ob_type->tp_name,"SwigPyPacked") == 0); -} - -SWIGRUNTIME void -SwigPyPacked_dealloc(PyObject *v) -{ - if (SwigPyPacked_Check(v)) { - SwigPyPacked *sobj = (SwigPyPacked *) 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 swigpypacked_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp - = { - /* PyObject header changed in Python 3 */ -#if PY_VERSION_HEX>=0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ -#endif - (char *)"SwigPyPacked", /* tp_name */ - sizeof(SwigPyPacked), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)SwigPyPacked_dealloc, /* tp_dealloc */ - (printfunc)SwigPyPacked_print, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ -#if PY_VERSION_HEX>=0x03000000 - 0, /* tp_reserved in 3.0.1 */ -#else - (cmpfunc)SwigPyPacked_compare, /* tp_compare */ -#endif - (reprfunc)SwigPyPacked_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)SwigPyPacked_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 */ - 0, /* 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 - }; - swigpypacked_type = tmp; - /* for Python 3 the ob_type already assigned in PyVarObject_HEAD_INIT() */ -#if PY_VERSION_HEX < 0x03000000 - swigpypacked_type.ob_type = &PyType_Type; -#endif - type_init = 1; - } - return &swigpypacked_type; -} - -SWIGRUNTIME PyObject * -SwigPyPacked_New(void *ptr, size_t size, swig_type_info *ty) -{ - SwigPyPacked *sobj = PyObject_NEW(SwigPyPacked, SwigPyPacked_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 * -SwigPyPacked_UnpackData(PyObject *obj, void *ptr, size_t size) -{ - if (SwigPyPacked_Check(obj)) { - SwigPyPacked *sobj = (SwigPyPacked *)obj; - if (sobj->size != size) return 0; - memcpy(ptr, sobj->pack, size); - return sobj->ty; - } else { - return 0; - } -} - -/* ----------------------------------------------------------------------------- - * pointers/data manipulation - * ----------------------------------------------------------------------------- */ - -SWIGRUNTIMEINLINE PyObject * -_SWIG_This(void) -{ - return SWIG_Python_str_FromChar("this"); -} - -SWIGRUNTIME PyObject * -SWIG_This(void) -{ - static PyObject *SWIG_STATIC_POINTER(swig_this) = _SWIG_This(); - return swig_this; -} - -/* #define SWIG_PYTHON_SLOW_GETSET_THIS */ - -/* TODO: I don't know how to implement the fast getset in Python 3 right now */ -#if PY_VERSION_HEX>=0x03000000 -#define SWIG_PYTHON_SLOW_GETSET_THIS -#endif - -SWIGRUNTIME SwigPyObject * -SWIG_Python_GetSwigThis(PyObject *pyobj) -{ - if (SwigPyObject_Check(pyobj)) { - return (SwigPyObject *) pyobj; - } else { - PyObject *obj = 0; -#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000)) - 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; - } else { -#ifdef PyWeakref_CheckProxy - if (PyWeakref_CheckProxy(pyobj)) { - PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); - return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; - } -#endif - 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 - if (obj && !SwigPyObject_Check(obj)) { - /* a PyObject is called 'this', try to get the 'real this' - SwigPyObject from it */ - return SWIG_Python_GetSwigThis(obj); - } - return (SwigPyObject *)obj; - } -} - -/* Acquire a pointer value */ - -SWIGRUNTIME int -SWIG_Python_AcquirePtr(PyObject *obj, int own) { - if (own == SWIG_POINTER_OWN) { - SwigPyObject *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 { - SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); - if (own) - *own = 0; - 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 = (SwigPyObject *)sobj->next; - } else { - if (ptr) { - int newmemory = 0; - *ptr = SWIG_TypeCast(tc,vptr,&newmemory); - if (newmemory == SWIG_CAST_NEW_MEMORY) { - assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ - if (own) - *own = *own | SWIG_CAST_NEW_MEMORY; - } - } - break; - } - } - } else { - if (ptr) *ptr = vptr; - break; - } - } - if (sobj) { - if (own) - *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) { - SwigPyClientData *data = ty ? (SwigPyClientData *) 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) { - SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv); - if (iobj) { - void *vptr; - res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0); - if (SWIG_IsOK(res)) { - if (ptr) { - *ptr = vptr; - /* transfer the ownership to 'ptr' */ - iobj->own = 0; - res = SWIG_AddCast(res); - res = SWIG_AddNewMask(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 */ - const 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) { - int newmemory = 0; - *ptr = SWIG_TypeCast(tc,vptr,&newmemory); - assert(!newmemory); /* newmemory handling not yet implemented */ - } else { - return SWIG_ERROR; - } - } 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 = SwigPyPacked_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, without calling __init__, and set the - 'this' attribute. -*/ - -SWIGRUNTIME PyObject* -SWIG_Python_NewShadowInstance(SwigPyClientData *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 { -#if PY_VERSION_HEX >= 0x03000000 - inst = PyBaseObject_Type.tp_new((PyTypeObject*) data->newargs, Py_None, Py_None); - PyObject_SetAttr(inst, SWIG_This(), swig_this); - Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG; -#else - PyObject *dict = PyDict_New(); - PyDict_SetItem(dict, SWIG_This(), swig_this); - inst = PyInstance_NewRaw(data->newargs, dict); - Py_DECREF(dict); -#endif - } - return inst; -#else -#if (PY_VERSION_HEX >= 0x02010000) - PyObject *inst; - PyObject *dict = PyDict_New(); - PyDict_SetItem(dict, SWIG_This(), swig_this); - inst = PyInstance_NewRaw(data->newargs, dict); - Py_DECREF(dict); - return (PyObject *) 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; - } -#ifdef Py_TPFLAGS_HAVE_WEAKREFS - inst->in_weakreflist = NULL; -#endif -#ifdef Py_TPFLAGS_GC - PyObject_GC_Init(inst); -#endif - PyDict_SetItem(inst->in_dict, SWIG_This(), swig_this); - return (PyObject *) inst; -#endif -#endif -} - -SWIGRUNTIME void -SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) -{ - PyObject *dict; -#if (PY_VERSION_HEX >= 0x02020000) && !defined(SWIG_PYTHON_SLOW_GETSET_THIS) - PyObject **dictptr = _PyObject_GetDictPtr(inst); - if (dictptr != NULL) { - dict = *dictptr; - if (dict == NULL) { - dict = PyDict_New(); - *dictptr = dict; - } - PyDict_SetItem(dict, SWIG_This(), swig_this); - return; - } -#endif - dict = PyObject_GetAttrString(inst, (char*)"__dict__"); - PyDict_SetItem(dict, SWIG_This(), swig_this); - Py_DECREF(dict); -} - - -SWIGINTERN PyObject * -SWIG_Python_InitShadowInstance(PyObject *args) { - PyObject *obj[2]; - if (!SWIG_Python_UnpackTuple(args,(char*)"swiginit", 2, 2, obj)) { - return NULL; - } else { - SwigPyObject *sthis = SWIG_Python_GetSwigThis(obj[0]); - if (sthis) { - SwigPyObject_append((PyObject*) sthis, obj[1]); - } else { - SWIG_Python_SetSwigThis(obj[0], obj[1]); - } - return SWIG_Py_Void(); - } -} - -/* 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 = SwigPyObject_New(ptr, type, own); - SwigPyClientData *clientdata = type ? (SwigPyClientData *)(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 ? SwigPyPacked_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) { - SwigPyClientData *data = (SwigPyClientData *) ty->clientdata; - if (data) SwigPyClientData_Del(data); - } - } - 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 */ - -#if PY_VERSION_HEX >= 0x03000000 - /* Add a dummy module object into sys.modules */ - PyObject *module = PyImport_AddModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION); -#else - PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, - swig_empty_runtime_method_table); -#endif - 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); - } -} - -/* The python cached type query */ -SWIGRUNTIME PyObject * -SWIG_Python_TypeCache(void) { - static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); - return cache; -} - -SWIGRUNTIME swig_type_info * -SWIG_Python_TypeQuery(const char *type) -{ - PyObject *cache = SWIG_Python_TypeCache(); - PyObject *key = SWIG_Python_str_FromChar(type); - PyObject *obj = PyDict_GetItem(cache, key); - swig_type_info *descriptor; - if (obj) { - descriptor = (swig_type_info *) PyCObject_AsVoidPtr(obj); - } else { - swig_module_info *swig_module = SWIG_Python_GetModule(); - descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); - if (descriptor) { - obj = PyCObject_FromVoidPtr(descriptor, NULL); - PyDict_SetItem(cache, key, obj); - Py_DECREF(obj); - } - } - Py_DECREF(key); - return descriptor; -} - -/* - For backward compatibility only -*/ -#define SWIG_POINTER_EXCEPTION 0 -#define SWIG_arg_fail(arg) SWIG_Python_ArgFail(arg) -#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) - -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) { - char *tmp; - PyObject *old_str = PyObject_Str(value); - Py_XINCREF(type); - PyErr_Clear(); - if (infront) { - PyErr_Format(type, "%s %s", mesg, tmp = SWIG_Python_str_AsChar(old_str)); - } else { - PyErr_Format(type, "%s %s", tmp = SWIG_Python_str_AsChar(old_str), mesg); - } - SWIG_Python_str_DelForPy3(tmp); - 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]; - PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); - return SWIG_Python_AddErrMesg(mesg, 1); - } else { - return 0; - } -} - -SWIGRUNTIMEINLINE const char * -SwigPyObject_GetDesc(PyObject *self) -{ - SwigPyObject *v = (SwigPyObject *)self; - swig_type_info *ty = v ? v->ty : 0; - return ty ? ty->str : (char*)""; -} - -SWIGRUNTIME void -SWIG_Python_TypeError(const char *type, PyObject *obj) -{ - if (type) { -#if defined(SWIG_COBJECT_TYPES) - if (obj && SwigPyObject_Check(obj)) { - const char *otype = (const char *) SwigPyObject_GetDesc(obj); - if (otype) { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'SwigPyObject(%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 ? SWIG_Python_str_AsChar(str) : 0; - if (cstr) { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", - type, otype, cstr); - SWIG_Python_str_DelForPy3(cstr); - } else { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", - type, otype); - } - Py_XDECREF(str); - return; - } - } - PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); - } else { - PyErr_Format(PyExc_TypeError, "unexpected type is received"); - } -} - - -/* 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 SWIG_POINTER_EXCEPTION - if (flags) { - SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); - SWIG_Python_ArgFail(argnum); - } -#endif - } - return result; -} - - -#ifdef __cplusplus -#if 0 -{ /* cc-mode */ -#endif -} -#endif - - - -#define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) - -#define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else - - - -/* -------- TYPES TABLE (BEGIN) -------- */ - -#define SWIGTYPE_p_P swig_types[0] -#define SWIGTYPE_p_char swig_types[1] -#define SWIGTYPE_p_point swig_types[2] -static swig_type_info *swig_types[4]; -static swig_module_info swig_module = {swig_types, 3, 0, 0, 0, 0}; -#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) -#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) - -/* -------- TYPES TABLE (END) -------- */ - -#if (PY_VERSION_HEX <= 0x02000000) -# if !defined(SWIG_PYTHON_CLASSIC) -# error "This python version requires swig to be run with the '-classic' option" -# endif -#endif - -/*----------------------------------------------- - @(target):= _cpp0x_unrestricted_unions.so - ------------------------------------------------*/ -#if PY_VERSION_HEX >= 0x03000000 -# define SWIG_init PyInit__cpp0x_unrestricted_unions - -#else -# define SWIG_init init_cpp0x_unrestricted_unions - -#endif -#define SWIG_name "_cpp0x_unrestricted_unions" - -#define SWIGVERSION 0x020001 -#define SWIG_VERSION SWIGVERSION - - -#define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a)) -#define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),reinterpret_cast< void** >(a)) - - -#include - - -namespace swig { - class SwigPtr_PyObject { - protected: - PyObject *_obj; - - public: - SwigPtr_PyObject() :_obj(0) - { - } - - SwigPtr_PyObject(const SwigPtr_PyObject& item) : _obj(item._obj) - { - Py_XINCREF(_obj); - } - - SwigPtr_PyObject(PyObject *obj, bool initial_ref = true) :_obj(obj) - { - if (initial_ref) { - Py_XINCREF(_obj); - } - } - - SwigPtr_PyObject & operator=(const SwigPtr_PyObject& item) - { - Py_XINCREF(item._obj); - Py_XDECREF(_obj); - _obj = item._obj; - return *this; - } - - ~SwigPtr_PyObject() - { - Py_XDECREF(_obj); - } - - operator PyObject *() const - { - return _obj; - } - - PyObject *operator->() const - { - return _obj; - } - }; -} - - -namespace swig { - struct SwigVar_PyObject : SwigPtr_PyObject { - SwigVar_PyObject(PyObject* obj = 0) : SwigPtr_PyObject(obj, false) { } - - SwigVar_PyObject & operator = (PyObject* obj) - { - Py_XDECREF(_obj); - _obj = obj; - return *this; - } - }; -} - - -struct point { - point() {} - point(int x, int y) : x_(x), y_(y) {} - int x_, y_; -}; - -#include // For placement 'new' in the constructor below -union P { - int z; - double w; - point p; // Illegal in C++03; legal in C++11. - // Due to the point member, a constructor definition is required. - P() { - new(&p) point(); - } -} p1; - - -#include -#if !defined(SWIG_NO_LLONG_MAX) -# if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__) -# define LLONG_MAX __LONG_LONG_MAX__ -# define LLONG_MIN (-LLONG_MAX - 1LL) -# define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) -# endif -#endif - - -SWIGINTERN int -SWIG_AsVal_double (PyObject *obj, double *val) -{ - int res = SWIG_TypeError; - if (PyFloat_Check(obj)) { - if (val) *val = PyFloat_AsDouble(obj); - return SWIG_OK; - } else if (PyInt_Check(obj)) { - if (val) *val = PyInt_AsLong(obj); - return SWIG_OK; - } else if (PyLong_Check(obj)) { - double v = PyLong_AsDouble(obj); - if (!PyErr_Occurred()) { - if (val) *val = v; - return SWIG_OK; - } else { - PyErr_Clear(); - } - } -#ifdef SWIG_PYTHON_CAST_MODE - { - int dispatch = 0; - double d = PyFloat_AsDouble(obj); - if (!PyErr_Occurred()) { - if (val) *val = d; - return SWIG_AddCast(SWIG_OK); - } else { - PyErr_Clear(); - } - if (!dispatch) { - long v = PyLong_AsLong(obj); - if (!PyErr_Occurred()) { - if (val) *val = v; - return SWIG_AddCast(SWIG_AddCast(SWIG_OK)); - } else { - PyErr_Clear(); - } - } - } -#endif - return res; -} - - -#include - - -#include - - -SWIGINTERNINLINE int -SWIG_CanCastAsInteger(double *d, double min, double max) { - double x = *d; - if ((min <= x && x <= max)) { - double fx = floor(x); - double cx = ceil(x); - double rd = ((x - fx) < 0.5) ? fx : cx; /* simple rint */ - if ((errno == EDOM) || (errno == ERANGE)) { - errno = 0; - } else { - double summ, reps, diff; - if (rd < x) { - diff = x - rd; - } else if (rd > x) { - diff = rd - x; - } else { - return 1; - } - summ = rd + x; - reps = diff/summ; - if (reps < 8*DBL_EPSILON) { - *d = rd; - return 1; - } - } - } - return 0; -} - - -SWIGINTERN int -SWIG_AsVal_long (PyObject *obj, long* val) -{ - if (PyInt_Check(obj)) { - if (val) *val = PyInt_AsLong(obj); - return SWIG_OK; - } else if (PyLong_Check(obj)) { - long v = PyLong_AsLong(obj); - if (!PyErr_Occurred()) { - if (val) *val = v; - return SWIG_OK; - } else { - PyErr_Clear(); - } - } -#ifdef SWIG_PYTHON_CAST_MODE - { - int dispatch = 0; - long v = PyInt_AsLong(obj); - if (!PyErr_Occurred()) { - if (val) *val = v; - return SWIG_AddCast(SWIG_OK); - } else { - PyErr_Clear(); - } - if (!dispatch) { - double d; - int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d)); - if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) { - if (val) *val = (long)(d); - return res; - } - } - } -#endif - return SWIG_TypeError; -} - - -SWIGINTERN int -SWIG_AsVal_int (PyObject * obj, int *val) -{ - long v; - int res = SWIG_AsVal_long (obj, &v); - if (SWIG_IsOK(res)) { - if ((v < INT_MIN || v > INT_MAX)) { - return SWIG_OverflowError; - } else { - if (val) *val = static_cast< int >(v); - } - } - return res; -} - - - #define SWIG_From_long PyInt_FromLong - - -SWIGINTERNINLINE PyObject * -SWIG_From_int (int value) -{ - return SWIG_From_long (value); -} - - - #define SWIG_From_double PyFloat_FromDouble - -#ifdef __cplusplus -extern "C" { -#endif -SWIGINTERN PyObject *_wrap_new_point__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - point *result = 0 ; - - if (!PyArg_ParseTuple(args,(char *)":new_point")) SWIG_fail; - result = (point *)new point(); - resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_point, SWIG_POINTER_NEW | 0 ); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_new_point__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - int arg1 ; - int arg2 ; - int val1 ; - int ecode1 = 0 ; - int val2 ; - int ecode2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - point *result = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:new_point",&obj0,&obj1)) SWIG_fail; - ecode1 = SWIG_AsVal_int(obj0, &val1); - if (!SWIG_IsOK(ecode1)) { - SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "new_point" "', argument " "1"" of type '" "int""'"); - } - arg1 = static_cast< int >(val1); - ecode2 = SWIG_AsVal_int(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "new_point" "', argument " "2"" of type '" "int""'"); - } - arg2 = static_cast< int >(val2); - result = (point *)new point(arg1,arg2); - resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_point, SWIG_POINTER_NEW | 0 ); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_new_point(PyObject *self, PyObject *args) { - int argc; - PyObject *argv[3]; - int ii; - - if (!PyTuple_Check(args)) SWIG_fail; - argc = (int)PyObject_Length(args); - for (ii = 0; (ii < argc) && (ii < 2); ii++) { - argv[ii] = PyTuple_GET_ITEM(args,ii); - } - if (argc == 0) { - return _wrap_new_point__SWIG_0(self, args); - } - if (argc == 2) { - int _v; - { - int res = SWIG_AsVal_int(argv[0], NULL); - _v = SWIG_CheckState(res); - } - if (_v) { - { - int res = SWIG_AsVal_int(argv[1], NULL); - _v = SWIG_CheckState(res); - } - if (_v) { - return _wrap_new_point__SWIG_1(self, args); - } - } - } - -fail: - SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number of arguments for overloaded function 'new_point'.\n" - " Possible C/C++ prototypes are:\n" - " point()\n" - " point(int,int)\n"); - return NULL; -} - - -SWIGINTERN PyObject *_wrap_point_x__set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - point *arg1 = (point *) 0 ; - int arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - int val2 ; - int ecode2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:point_x__set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_point, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "point_x__set" "', argument " "1"" of type '" "point *""'"); - } - arg1 = reinterpret_cast< point * >(argp1); - ecode2 = SWIG_AsVal_int(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "point_x__set" "', argument " "2"" of type '" "int""'"); - } - arg2 = static_cast< int >(val2); - if (arg1) (arg1)->x_ = arg2; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_point_x__get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - point *arg1 = (point *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - int result; - - if (!PyArg_ParseTuple(args,(char *)"O:point_x__get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_point, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "point_x__get" "', argument " "1"" of type '" "point *""'"); - } - arg1 = reinterpret_cast< point * >(argp1); - result = (int) ((arg1)->x_); - resultobj = SWIG_From_int(static_cast< int >(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_point_y__set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - point *arg1 = (point *) 0 ; - int arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - int val2 ; - int ecode2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:point_y__set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_point, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "point_y__set" "', argument " "1"" of type '" "point *""'"); - } - arg1 = reinterpret_cast< point * >(argp1); - ecode2 = SWIG_AsVal_int(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "point_y__set" "', argument " "2"" of type '" "int""'"); - } - arg2 = static_cast< int >(val2); - if (arg1) (arg1)->y_ = arg2; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_point_y__get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - point *arg1 = (point *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - int result; - - if (!PyArg_ParseTuple(args,(char *)"O:point_y__get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_point, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "point_y__get" "', argument " "1"" of type '" "point *""'"); - } - arg1 = reinterpret_cast< point * >(argp1); - result = (int) ((arg1)->y_); - resultobj = SWIG_From_int(static_cast< int >(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_delete_point(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - point *arg1 = (point *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:delete_point",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_point, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_point" "', argument " "1"" of type '" "point *""'"); - } - arg1 = reinterpret_cast< point * >(argp1); - delete arg1; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *point_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *obj; - if (!PyArg_ParseTuple(args,(char*)"O:swigregister", &obj)) return NULL; - SWIG_TypeNewClientData(SWIGTYPE_p_point, SWIG_NewClientData(obj)); - return SWIG_Py_Void(); -} - -SWIGINTERN PyObject *_wrap_P_z_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - P *arg1 = (P *) 0 ; - int arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - int val2 ; - int ecode2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:P_z_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_P, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "P_z_set" "', argument " "1"" of type '" "P *""'"); - } - arg1 = reinterpret_cast< P * >(argp1); - ecode2 = SWIG_AsVal_int(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "P_z_set" "', argument " "2"" of type '" "int""'"); - } - arg2 = static_cast< int >(val2); - if (arg1) (arg1)->z = arg2; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_P_z_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - P *arg1 = (P *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - int result; - - if (!PyArg_ParseTuple(args,(char *)"O:P_z_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_P, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "P_z_get" "', argument " "1"" of type '" "P *""'"); - } - arg1 = reinterpret_cast< P * >(argp1); - result = (int) ((arg1)->z); - resultobj = SWIG_From_int(static_cast< int >(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_P_w_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - P *arg1 = (P *) 0 ; - double arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - double val2 ; - int ecode2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:P_w_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_P, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "P_w_set" "', argument " "1"" of type '" "P *""'"); - } - arg1 = reinterpret_cast< P * >(argp1); - ecode2 = SWIG_AsVal_double(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "P_w_set" "', argument " "2"" of type '" "double""'"); - } - arg2 = static_cast< double >(val2); - if (arg1) (arg1)->w = arg2; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_P_w_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - P *arg1 = (P *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - double result; - - if (!PyArg_ParseTuple(args,(char *)"O:P_w_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_P, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "P_w_get" "', argument " "1"" of type '" "P *""'"); - } - arg1 = reinterpret_cast< P * >(argp1); - result = (double) ((arg1)->w); - resultobj = SWIG_From_double(static_cast< double >(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_P_p_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - P *arg1 = (P *) 0 ; - point *arg2 = (point *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - void *argp2 = 0 ; - int res2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:P_p_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_P, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "P_p_set" "', argument " "1"" of type '" "P *""'"); - } - arg1 = reinterpret_cast< P * >(argp1); - res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_point, 0 | 0 ); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "P_p_set" "', argument " "2"" of type '" "point *""'"); - } - arg2 = reinterpret_cast< point * >(argp2); - if (arg1) (arg1)->p = *arg2; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_P_p_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - P *arg1 = (P *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - point *result = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:P_p_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_P, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "P_p_get" "', argument " "1"" of type '" "P *""'"); - } - arg1 = reinterpret_cast< P * >(argp1); - result = (point *)& ((arg1)->p); - resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_point, 0 | 0 ); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_new_P(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - P *result = 0 ; - - if (!PyArg_ParseTuple(args,(char *)":new_P")) SWIG_fail; - result = (P *)new P(); - resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_P, SWIG_POINTER_NEW | 0 ); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_delete_P(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - P *arg1 = (P *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:delete_P",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_P, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_P" "', argument " "1"" of type '" "P *""'"); - } - arg1 = reinterpret_cast< P * >(argp1); - delete arg1; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *P_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *obj; - if (!PyArg_ParseTuple(args,(char*)"O:swigregister", &obj)) return NULL; - SWIG_TypeNewClientData(SWIGTYPE_p_P, SWIG_NewClientData(obj)); - return SWIG_Py_Void(); -} - -SWIGINTERN int Swig_var_p1_set(PyObject *_val) { - { - void *argp = 0; - int res = SWIG_ConvertPtr(_val, &argp, SWIGTYPE_p_P, 0 | 0); - if (!SWIG_IsOK(res)) { - SWIG_exception_fail(SWIG_ArgError(res), "in variable '""p1""' of type '""P""'"); - } - if (!argp) { - SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in variable '""p1""' of type '""P""'"); - } else { - P * temp; - temp = reinterpret_cast< P * >(argp); - p1 = *temp; - if (SWIG_IsNewObj(res)) delete temp; - } - } - return 0; -fail: - return 1; -} - - -SWIGINTERN PyObject *Swig_var_p1_get(void) { - PyObject *pyobj = 0; - - pyobj = SWIG_NewPointerObj(SWIG_as_voidptr(&p1), SWIGTYPE_p_P, 0 ); - return pyobj; -} - - -static PyMethodDef SwigMethods[] = { - { (char *)"SWIG_PyInstanceMethod_New", (PyCFunction)SWIG_PyInstanceMethod_New, METH_O, NULL}, - { (char *)"new_point", _wrap_new_point, METH_VARARGS, NULL}, - { (char *)"point_x__set", _wrap_point_x__set, METH_VARARGS, NULL}, - { (char *)"point_x__get", _wrap_point_x__get, METH_VARARGS, NULL}, - { (char *)"point_y__set", _wrap_point_y__set, METH_VARARGS, NULL}, - { (char *)"point_y__get", _wrap_point_y__get, METH_VARARGS, NULL}, - { (char *)"delete_point", _wrap_delete_point, METH_VARARGS, NULL}, - { (char *)"point_swigregister", point_swigregister, METH_VARARGS, NULL}, - { (char *)"P_z_set", _wrap_P_z_set, METH_VARARGS, NULL}, - { (char *)"P_z_get", _wrap_P_z_get, METH_VARARGS, NULL}, - { (char *)"P_w_set", _wrap_P_w_set, METH_VARARGS, NULL}, - { (char *)"P_w_get", _wrap_P_w_get, METH_VARARGS, NULL}, - { (char *)"P_p_set", _wrap_P_p_set, METH_VARARGS, NULL}, - { (char *)"P_p_get", _wrap_P_p_get, METH_VARARGS, NULL}, - { (char *)"new_P", _wrap_new_P, METH_VARARGS, NULL}, - { (char *)"delete_P", _wrap_delete_P, METH_VARARGS, NULL}, - { (char *)"P_swigregister", P_swigregister, METH_VARARGS, NULL}, - { NULL, NULL, 0, NULL } -}; - - -/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ - -static swig_type_info _swigt__p_P = {"_p_P", "P *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_point = {"_p_point", "point *", 0, 0, (void*)0, 0}; - -static swig_type_info *swig_type_initial[] = { - &_swigt__p_P, - &_swigt__p_char, - &_swigt__p_point, -}; - -static swig_cast_info _swigc__p_P[] = { {&_swigt__p_P, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_point[] = { {&_swigt__p_point, 0, 0, 0},{0, 0, 0, 0}}; - -static swig_cast_info *swig_cast_initial[] = { - _swigc__p_P, - _swigc__p_char, - _swigc__p_point, -}; - - -/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ - -static swig_const_info swig_const_table[] = { -{0, 0, 0, 0.0, 0, 0}}; - -#ifdef __cplusplus -} -#endif -/* ----------------------------------------------------------------------------- - * Type initialization: - * This problem is tough by the requirement that no dynamic - * memory is used. Also, since swig_type_info structures store pointers to - * swig_cast_info structures and swig_cast_info structures store pointers back - * to swig_type_info structures, we need some lookup code at initialization. - * The idea is that swig generates all the structures that are needed. - * The runtime then collects these partially filled structures. - * The SWIG_InitializeModule function takes these initial arrays out of - * swig_module, and does all the lookup, filling in the swig_module.types - * array with the correct data and linking the correct swig_cast_info - * structures together. - * - * The generated swig_type_info structures are assigned staticly to an initial - * array. We just loop through that array, and handle each type individually. - * First we lookup if this type has been already loaded, and if so, use the - * loaded structure instead of the generated one. Then we have to fill in the - * cast linked list. The cast data is initially stored in something like a - * two-dimensional array. Each row corresponds to a type (there are the same - * number of rows as there are in the swig_type_initial array). Each entry in - * a column is one of the swig_cast_info structures for that type. - * The cast_initial array is actually an array of arrays, because each row has - * a variable number of columns. So to actually build the cast linked list, - * we find the array of casts associated with the type, and loop through it - * adding the casts to the list. The one last trick we need to do is making - * sure the type pointer in the swig_cast_info struct is correct. - * - * First off, we lookup the cast->type name to see if it is already loaded. - * There are three cases to handle: - * 1) If the cast->type has already been loaded AND the type we are adding - * casting info to has not been loaded (it is in this module), THEN we - * replace the cast->type pointer with the type pointer that has already - * been loaded. - * 2) If BOTH types (the one we are adding casting info to, and the - * cast->type) are loaded, THEN the cast info has already been loaded by - * the previous module so we just ignore it. - * 3) Finally, if cast->type has not already been loaded, then we add that - * swig_cast_info to the linked list (because the cast->type) pointer will - * be correct. - * ----------------------------------------------------------------------------- */ - -#ifdef __cplusplus -extern "C" { -#if 0 -} /* c-mode */ -#endif -#endif - -#if 0 -#define SWIGRUNTIME_DEBUG -#endif - - -SWIGRUNTIME void -SWIG_InitializeModule(void *clientdata) { - size_t i; - swig_module_info *module_head, *iter; - int found, init; - - clientdata = clientdata; - - /* check to see if the circular list has been setup, if not, set it up */ - if (swig_module.next==0) { - /* Initialize the swig_module */ - swig_module.type_initial = swig_type_initial; - swig_module.cast_initial = swig_cast_initial; - swig_module.next = &swig_module; - init = 1; - } else { - init = 0; - } - - /* Try and load any already created modules */ - module_head = SWIG_GetModule(clientdata); - if (!module_head) { - /* This is the first module loaded for this interpreter */ - /* so set the swig module into the interpreter */ - SWIG_SetModule(clientdata, &swig_module); - module_head = &swig_module; - } else { - /* the interpreter has loaded a SWIG module, but has it loaded this one? */ - found=0; - iter=module_head; - do { - if (iter==&swig_module) { - found=1; - break; - } - iter=iter->next; - } while (iter!= module_head); - - /* if the is found in the list, then all is done and we may leave */ - if (found) return; - /* otherwise we must add out module into the list */ - swig_module.next = module_head->next; - module_head->next = &swig_module; - } - - /* When multiple interpeters are used, a module could have already been initialized in - a different interpreter, but not yet have a pointer in this interpreter. - In this case, we do not want to continue adding types... everything should be - set up already */ - if (init == 0) return; - - /* Now work on filling in swig_module.types */ -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: size %d\n", swig_module.size); -#endif - for (i = 0; i < swig_module.size; ++i) { - swig_type_info *type = 0; - swig_type_info *ret; - swig_cast_info *cast; - -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); -#endif - - /* if there is another module already loaded */ - if (swig_module.next != &swig_module) { - type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); - } - if (type) { - /* Overwrite clientdata field */ -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: found type %s\n", type->name); -#endif - if (swig_module.type_initial[i]->clientdata) { - type->clientdata = swig_module.type_initial[i]->clientdata; -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); -#endif - } - } else { - type = swig_module.type_initial[i]; - } - - /* Insert casting types */ - cast = swig_module.cast_initial[i]; - while (cast->type) { - /* Don't need to add information already in the list */ - ret = 0; -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); -#endif - if (swig_module.next != &swig_module) { - ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); -#ifdef SWIGRUNTIME_DEBUG - if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); -#endif - } - if (ret) { - if (type == swig_module.type_initial[i]) { -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: skip old type %s\n", ret->name); -#endif - cast->type = ret; - ret = 0; - } else { - /* Check for casting already in the list */ - swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); -#ifdef SWIGRUNTIME_DEBUG - if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); -#endif - if (!ocast) ret = 0; - } - } - - if (!ret) { -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); -#endif - if (type->cast) { - type->cast->prev = cast; - cast->next = type->cast; - } - type->cast = cast; - } - cast++; - } - /* Set entry in modules->types array equal to the type */ - swig_module.types[i] = type; - } - swig_module.types[i] = 0; - -#ifdef SWIGRUNTIME_DEBUG - printf("**** SWIG_InitializeModule: Cast List ******\n"); - for (i = 0; i < swig_module.size; ++i) { - int j = 0; - swig_cast_info *cast = swig_module.cast_initial[i]; - printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); - while (cast->type) { - printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); - cast++; - ++j; - } - printf("---- Total casts: %d\n",j); - } - printf("**** SWIG_InitializeModule: Cast List ******\n"); -#endif -} - -/* 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_PropagateClientData(void) { - size_t i; - swig_cast_info *equiv; - static int init_run = 0; - - if (init_run) return; - init_run = 1; - - for (i = 0; i < swig_module.size; i++) { - if (swig_module.types[i]->clientdata) { - equiv = swig_module.types[i]->cast; - while (equiv) { - if (!equiv->converter) { - if (equiv->type && !equiv->type->clientdata) - SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); - } - equiv = equiv->next; - } - } - } -} - -#ifdef __cplusplus -#if 0 -{ - /* c-mode */ -#endif -} -#endif - - - -#ifdef __cplusplus -extern "C" { -#endif - - /* Python-specific SWIG API */ -#define SWIG_newvarlink() SWIG_Python_newvarlink() -#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) -#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) - - /* ----------------------------------------------------------------------------- - * global variable support code. - * ----------------------------------------------------------------------------- */ - - typedef struct swig_globalvar { - char *name; /* Name of global variable */ - PyObject *(*get_attr)(void); /* Return the current value */ - int (*set_attr)(PyObject *); /* Set the value */ - struct swig_globalvar *next; - } swig_globalvar; - - typedef struct swig_varlinkobject { - PyObject_HEAD - swig_globalvar *vars; - } swig_varlinkobject; - - SWIGINTERN PyObject * - swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { -#if PY_VERSION_HEX >= 0x03000000 - return PyUnicode_InternFromString(""); -#else - return PyString_FromString(""); -#endif - } - - SWIGINTERN PyObject * - swig_varlink_str(swig_varlinkobject *v) { -#if PY_VERSION_HEX >= 0x03000000 - PyObject *str = PyUnicode_InternFromString("("); - PyObject *tail; - PyObject *joined; - swig_globalvar *var; - for (var = v->vars; var; var=var->next) { - tail = PyUnicode_FromString(var->name); - joined = PyUnicode_Concat(str, tail); - Py_DecRef(str); - Py_DecRef(tail); - str = joined; - if (var->next) { - tail = PyUnicode_InternFromString(", "); - joined = PyUnicode_Concat(str, tail); - Py_DecRef(str); - Py_DecRef(tail); - str = joined; - } - } - tail = PyUnicode_InternFromString(")"); - joined = PyUnicode_Concat(str, tail); - Py_DecRef(str); - Py_DecRef(tail); - str = joined; -#else - PyObject *str = PyString_FromString("("); - swig_globalvar *var; - for (var = v->vars; var; var=var->next) { - PyString_ConcatAndDel(&str,PyString_FromString(var->name)); - if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); - } - PyString_ConcatAndDel(&str,PyString_FromString(")")); -#endif - return str; - } - - SWIGINTERN int - swig_varlink_print(swig_varlinkobject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) { - char *tmp; - PyObject *str = swig_varlink_str(v); - fprintf(fp,"Swig global variables "); - fprintf(fp,"%s\n", tmp = SWIG_Python_str_AsChar(str)); - SWIG_Python_str_DelForPy3(tmp); - Py_DECREF(str); - return 0; - } - - SWIGINTERN void - swig_varlink_dealloc(swig_varlinkobject *v) { - swig_globalvar *var = v->vars; - while (var) { - swig_globalvar *n = var->next; - free(var->name); - free(var); - var = n; - } - } - - SWIGINTERN PyObject * - swig_varlink_getattr(swig_varlinkobject *v, char *n) { - PyObject *res = NULL; - swig_globalvar *var = v->vars; - while (var) { - if (strcmp(var->name,n) == 0) { - res = (*var->get_attr)(); - break; - } - var = var->next; - } - if (res == NULL && !PyErr_Occurred()) { - PyErr_SetString(PyExc_NameError,"Unknown C global variable"); - } - return res; - } - - SWIGINTERN int - swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { - int res = 1; - swig_globalvar *var = v->vars; - while (var) { - if (strcmp(var->name,n) == 0) { - res = (*var->set_attr)(p); - break; - } - var = var->next; - } - if (res == 1 && !PyErr_Occurred()) { - PyErr_SetString(PyExc_NameError,"Unknown C global variable"); - } - return res; - } - - SWIGINTERN PyTypeObject* - swig_varlink_type(void) { - static char varlink__doc__[] = "Swig var link object"; - static PyTypeObject varlink_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp - = { - /* PyObject header changed in Python 3 */ -#if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /* Number of items in variable part (ob_size) */ -#endif - (char *)"swigvarlink", /* Type name (tp_name) */ - sizeof(swig_varlinkobject), /* Basic size (tp_basicsize) */ - 0, /* Itemsize (tp_itemsize) */ - (destructor) swig_varlink_dealloc, /* Deallocator (tp_dealloc) */ - (printfunc) swig_varlink_print, /* Print (tp_print) */ - (getattrfunc) swig_varlink_getattr, /* get attr (tp_getattr) */ - (setattrfunc) swig_varlink_setattr, /* Set attr (tp_setattr) */ - 0, /* tp_compare */ - (reprfunc) swig_varlink_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - (reprfunc) swig_varlink_str, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - 0, /* tp_flags */ - varlink__doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ -#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 - }; - varlink_type = tmp; - /* for Python 3 we already assigned ob_type in PyVarObject_HEAD_INIT() */ -#if PY_VERSION_HEX < 0x03000000 - varlink_type.ob_type = &PyType_Type; -#endif - type_init = 1; - } - return &varlink_type; - } - - /* Create a variable linking object for use later */ - SWIGINTERN PyObject * - SWIG_Python_newvarlink(void) { - swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type()); - if (result) { - result->vars = 0; - } - return ((PyObject*) result); - } - - SWIGINTERN void - SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { - swig_varlinkobject *v = (swig_varlinkobject *) p; - swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); - if (gv) { - size_t size = strlen(name)+1; - gv->name = (char *)malloc(size); - if (gv->name) { - strncpy(gv->name,name,size); - gv->get_attr = get_attr; - gv->set_attr = set_attr; - gv->next = v->vars; - } - } - v->vars = gv; - } - - SWIGINTERN PyObject * - SWIG_globals(void) { - static PyObject *_SWIG_globals = 0; - if (!_SWIG_globals) _SWIG_globals = SWIG_newvarlink(); - return _SWIG_globals; - } - - /* ----------------------------------------------------------------------------- - * constants/methods manipulation - * ----------------------------------------------------------------------------- */ - - /* Install Constants */ - SWIGINTERN void - SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { - PyObject *obj = 0; - size_t i; - for (i = 0; constants[i].type; ++i) { - switch(constants[i].type) { - case SWIG_PY_POINTER: - obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); - break; - case SWIG_PY_BINARY: - obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); - break; - default: - obj = 0; - break; - } - if (obj) { - PyDict_SetItemString(d, constants[i].name, obj); - Py_DECREF(obj); - } - } - } - - /* -----------------------------------------------------------------------------*/ - /* Fix SwigMethods to carry the callback ptrs when needed */ - /* -----------------------------------------------------------------------------*/ - - SWIGINTERN void - SWIG_Python_FixMethods(PyMethodDef *methods, - swig_const_info *const_table, - swig_type_info **types, - swig_type_info **types_initial) { - size_t i; - for (i = 0; methods[i].ml_name; ++i) { - const char *c = methods[i].ml_doc; - if (c && (c = strstr(c, "swig_ptr: "))) { - int j; - swig_const_info *ci = 0; - const char *name = c + 10; - for (j = 0; const_table[j].type; ++j) { - if (strncmp(const_table[j].name, name, - strlen(const_table[j].name)) == 0) { - ci = &(const_table[j]); - break; - } - } - if (ci) { - void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; - if (ptr) { - size_t shift = (ci->ptype) - types; - swig_type_info *ty = types_initial[shift]; - size_t ldoc = (c - methods[i].ml_doc); - size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; - char *ndoc = (char*)malloc(ldoc + lptr + 10); - if (ndoc) { - char *buff = ndoc; - strncpy(buff, methods[i].ml_doc, ldoc); - buff += ldoc; - strncpy(buff, "swig_ptr: ", 10); - buff += 10; - SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); - methods[i].ml_doc = ndoc; - } - } - } - } - } - } - -#ifdef __cplusplus -} -#endif - -/* -----------------------------------------------------------------------------* - * Partial Init method - * -----------------------------------------------------------------------------*/ - -#ifdef __cplusplus -extern "C" -#endif - -SWIGEXPORT -#if PY_VERSION_HEX >= 0x03000000 -PyObject* -#else -void -#endif -SWIG_init(void) { - PyObject *m, *d; -#if PY_VERSION_HEX >= 0x03000000 - static struct PyModuleDef SWIG_module = { - PyModuleDef_HEAD_INIT, - (char *) SWIG_name, - NULL, - -1, - SwigMethods, - NULL, - NULL, - NULL, - NULL - }; -#endif - - /* Fix SwigMethods to carry the callback ptrs when needed */ - SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); - -#if PY_VERSION_HEX >= 0x03000000 - m = PyModule_Create(&SWIG_module); -#else - m = Py_InitModule((char *) SWIG_name, SwigMethods); -#endif - d = PyModule_GetDict(m); - - SWIG_InitializeModule(0); - SWIG_InstallConstants(d,swig_const_table); - - - PyDict_SetItemString(d,(char*)"cvar", SWIG_globals()); - SWIG_addvarlink(SWIG_globals(),(char*)"p1",Swig_var_p1_get, Swig_var_p1_set); -#if PY_VERSION_HEX >= 0x03000000 - return m; -#else - return; -#endif -} - From 38f37ef5ae7026dd7c04ac8c39cb2aec4bf90838 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 29 Jan 2013 06:55:22 +0000 Subject: [PATCH 0432/1160] Apply patch SF #335 - Truly ignore constructors in directors with %ignore and correct testcase that tests this --- CHANGES.current | 3 ++ Examples/test-suite/director_ignore.i | 49 +++++++++++++++++++-------- Source/Modules/lang.cxx | 3 ++ 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index ad2f1e764..9c014aa82 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-01-28: William + [Java] Apply patch SF #335 - Truly ignore constructors in directors with %ignore. + 2013-01-18: Brant Kyser [Java] Patch #15 - Allow the use of the nspace feature without the -package commandline option. This works as long and the new jniclasspackage pragma is used to place the JNI intermediate class diff --git a/Examples/test-suite/director_ignore.i b/Examples/test-suite/director_ignore.i index 05ba17ce1..57cbc13d8 100644 --- a/Examples/test-suite/director_ignore.i +++ b/Examples/test-suite/director_ignore.i @@ -68,21 +68,6 @@ class DAbstractIgnores virtual double OverloadedProtectedMethod() = 0; }; -class DIgnoreConstructor -{ - public: - virtual ~DIgnoreConstructor() {} - DIgnoreConstructor(std::string s, int i) {} - DIgnoreConstructor(bool b) {} -}; - -class DIgnoreOnlyConstructor -{ - public: - virtual ~DIgnoreOnlyConstructor() {} - DIgnoreOnlyConstructor(bool b) {} -}; - template class DTemplateAbstractIgnores { T t; @@ -101,3 +86,37 @@ template class DTemplateAbstractIgnores %template(DTemplateAbstractIgnoresInt) DTemplateAbstractIgnores; +class DIgnoreConstructor +{ + public: + virtual ~DIgnoreConstructor() {} + DIgnoreConstructor(std::string s, int i) {} + DIgnoreConstructor(bool b) {} +}; + +class DIgnoreOnlyConstructor +{ + public: + virtual ~DIgnoreOnlyConstructor() {} + DIgnoreOnlyConstructor(bool b) {} +}; + +%{ +class DIgnoreConstructor +{ + public: + virtual ~DIgnoreConstructor() {} + DIgnoreConstructor(std::string s, int i) {} + private: // Hide constructor + DIgnoreConstructor(bool b) {} +}; + +class DIgnoreOnlyConstructor +{ + public: + virtual ~DIgnoreOnlyConstructor() {} + private: // Hide constructor + DIgnoreOnlyConstructor(bool b) {} +}; +%} + diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 4f1657825..69df79271 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1995,6 +1995,9 @@ int Language::classDirectorConstructors(Node *n) { for (ni = Getattr(n, "firstChild"); ni; ni = nextSibling(ni)) { nodeType = Getattr(ni, "nodeType"); if (Cmp(nodeType, "constructor") == 0) { + if (GetFlag(ni, "feature:ignore")) + continue; + Parm *parms = Getattr(ni, "parms"); if (is_public(ni)) { /* emit public constructor */ From d172e3d0ed96e1f242ebaa4066f556a8abe0e764 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 29 Jan 2013 07:28:32 +0000 Subject: [PATCH 0433/1160] Apply patch SF #334 - Fix Python default value conversions TRUE->True, FALSE->False. --- CHANGES.current | 3 +++ Source/Modules/octave.cxx | 6 +----- Source/Modules/python.cxx | 2 +- Source/Modules/ruby.cxx | 6 +----- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 9c014aa82..1d09ab875 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-01-28: William + [Python] Apply patch SF #334 - Fix default value conversions "TRUE"->True, "FALSE"->False. + 2013-01-28: William [Java] Apply patch SF #335 - Truly ignore constructors in directors with %ignore. diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 5584176a1..bbe442b7e 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -524,11 +524,7 @@ public: } if (Strcmp(v, "NULL") == 0) return SwigType_ispointer(t) ? NewString("nil") : NewString("0"); - else if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0) - return NewString("true"); - else if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0) - return NewString("false"); - if (Strcmp(v, "true") == 0 || Strcmp(v, "FALSE") == 0) + if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0) return NewString("true"); if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0) return NewString("false"); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 280a36923..e3d8c7d50 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -1556,7 +1556,7 @@ public: else return v; } - if (Strcmp(v, "true") == 0 || Strcmp(v, "FALSE") == 0) + if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0) return NewString("True"); if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0) return NewString("False"); diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index eaec0e185..48680e803 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -790,11 +790,7 @@ private: } if (Strcmp(v, "NULL") == 0) return SwigType_ispointer(t) ? NewString("nil") : NewString("0"); - else if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0) - return NewString("true"); - else if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0) - return NewString("false"); - if (Strcmp(v, "true") == 0 || Strcmp(v, "FALSE") == 0) + if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0) return NewString("True"); if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0) return NewString("False"); From 397409fbb1336690c99e77f4f23043626e495d98 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 30 Jan 2013 22:18:13 +0000 Subject: [PATCH 0434/1160] Ensure 'javapackage' typemap is used as it stopped working from version 2.0.5 --- CHANGES.current | 3 +++ Doc/Manual/Java.html | 7 ++++--- Source/Modules/java.cxx | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 1d09ab875..e6aebdb06 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-01-29: William + [Java] Ensure 'javapackage' typemap is used as it stopped working from version 2.0.5. + 2013-01-28: William [Python] Apply patch SF #334 - Fix default value conversions "TRUE"->True, "FALSE"->False. diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 8245d46eb..0024d602a 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -5662,7 +5662,7 @@ to make the method and constructor public:

      The Java directors feature requires the "javadirectorin", "javadirectorout", "directorin" and the "directorout" typemaps in order to work properly. -The "javapackage" typemap is an optional typemap used to identify the Java package path for individual SWIG generated proxy classes. +The "javapackage" typemap is an optional typemap used to identify the Java package path for individual SWIG generated proxy classes used in director methods.

      %typemap(directorin)

      @@ -5803,6 +5803,7 @@ The target method is the method in the Java proxy class which overrides the virt

      The "javapackage" typemap is optional; it serves to identify a class's Java package. This typemap should be used in conjunction with classes that are defined outside of the current SWIG interface file. +The typemap is only used if the type is used in a director method, that is, in a virtual method in a director class. For example:

      @@ -5819,7 +5820,7 @@ For example: class Example { public: virtual ~Example(); - void ping(Foo *arg1, Bar *arg2); + virtual void ping(Foo *arg1, Bar *arg2); }; } @@ -5844,7 +5845,7 @@ The corrected interface file looks like: class Example { public: virtual ~Example(); - void ping(Foo *arg1, Bar *arg2); + virtual void ping(Foo *arg1, Bar *arg2); }; } diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 987b6ddf6..2fb21eca8 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3527,7 +3527,7 @@ public: String *pkg_path = Swig_typemap_lookup("javapackage", p, "", 0); SwigType *type = Getattr(p, "type"); - if (pkg_path || Len(pkg_path) == 0) + if (!pkg_path || Len(pkg_path) == 0) pkg_path = package_path; String *descriptor_out = Copy(descriptor_in); From a043b55b69d4587a1bd95b934b85acb683e415e6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 1 Feb 2013 19:17:21 +0000 Subject: [PATCH 0435/1160] Better clarification about polymorphic wrappers for function objects - std::function --- Doc/Manual/Cpp0x.html | 24 +++++++++++++-- Examples/test-suite/cpp0x_function_objects.i | 29 +++++++++++++++---- .../python/cpp0x_function_objects_runme.py | 8 ++--- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index 0200fdf5c..aa8c41225 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -735,14 +735,32 @@ int main() {

      7.3.7 Polymorphous wrappers for function objects

      -

      SWIG fully supports function template wrappers and function objects:

      +

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

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

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

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

      7.3.8 Type traits for metaprogramming

      diff --git a/Examples/test-suite/cpp0x_function_objects.i b/Examples/test-suite/cpp0x_function_objects.i index e864137c7..4b9895ca8 100644 --- a/Examples/test-suite/cpp0x_function_objects.i +++ b/Examples/test-suite/cpp0x_function_objects.i @@ -1,18 +1,35 @@ /* This testcase checks whether SWIG correctly parses function objects and the templates for the functions (signature). - Function objects are objects which overload the operator() function. */ + Function objects are objects which overload the operator() function. + The std::function does not provide any seamless support in the target languages yet. +*/ %module cpp0x_function_objects -%inline %{ -//function pF; // not supported yet by the compiler +%rename(__call__) Test::operator(); +%inline %{ struct Test { int value; - void operator()(short x, short y) { - value=10; + void operator()(int x, int y) { + value=x+y; } - + Test() : value(0) {} } test; + +#include +std::function pF = test; + +int testit1(Test new_test, int a, int b) { + pF = new_test; + pF(a, b); + return new_test.value; +} + +int testit2(int a, int b) { + test(a, b); + return test.value; +} + %} diff --git a/Examples/test-suite/python/cpp0x_function_objects_runme.py b/Examples/test-suite/python/cpp0x_function_objects_runme.py index edbd88e1c..ed8f888b1 100644 --- a/Examples/test-suite/python/cpp0x_function_objects_runme.py +++ b/Examples/test-suite/python/cpp0x_function_objects_runme.py @@ -3,10 +3,10 @@ import sys t = cpp0x_function_objects.Test() if t.value != 0: - raise RuntimeError,"Runtime cpp0x_function_objects failed. t.value should be 0, but is", t.value + raise RuntimeError("Runtime cpp0x_function_objects failed. t.value should be 0, but is " + str(t.value)) -t(1,2) # sets value +t(1,2) # adds numbers and sets value -if t.value != 10: - raise RuntimeError,"Runtime cpp0x_function_objects failed. t.value not changed - should be 10, but is", t.value +if t.value != 3: + raise RuntimeError("Runtime cpp0x_function_objects failed. t.value not changed - should be 3, but is " + str(t.value)) From c8ff23de0c5fdc60a7a5335bcf937ac25a6a3d39 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 2 Feb 2013 01:15:28 +0000 Subject: [PATCH 0436/1160] Initialization list doc updates and new tests. Fix functions with default arguments that are initializer lists --- Doc/Manual/Cpp0x.html | 32 ++++++++++++++----- Examples/test-suite/cpp0x_initializer_list.i | 9 +++++- .../test-suite/cpp0x_uniform_initialization.i | 31 ++++++++++++++++-- .../python/cpp0x_initializer_list_runme.py | 5 +++ .../cpp0x_uniform_initialization_runme.py | 21 ++++++++++++ Source/CParse/parser.y | 12 +++++-- 6 files changed, 96 insertions(+), 14 deletions(-) create mode 100644 Examples/test-suite/python/cpp0x_initializer_list_runme.py create mode 100644 Examples/test-suite/python/cpp0x_uniform_initialization_runme.py diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index aa8c41225..341cb3ce5 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -126,13 +126,14 @@ public:

      7.2.4 Initializer lists

      -

      Constructors using the std::initializer_list class are removed -from the wrapped class, because the only way to access such a -constructor is at compile time using the "= {}" assignment.

      -

      Users should add another constructor with specific arguments -filling the class members manually.

      +

      +Constructors using the std::initializer_list class are removed +from the wrapped class because the only way to access such a +constructor is at compile time using the initialization list syntax. +Initializer lists are very much a C++ construct and not very accessible from wrappers. +

      -

      For now, if a user wants to fill the class components like this:

      +

      For now, if you want to fill the class components like this:

       class A {
      @@ -142,7 +143,7 @@ public:
       A a1 = {1,2,3,4};
       
      -

      You should add another constructor using the std::vector for example:

      +

      you could add another constructor using std::vector for example:

       class A {
      @@ -153,11 +154,26 @@ public:
       A a1 = {1,2,3,4};
       
      -

      And call it from your target language, for example, in Python:

      +

      And then construct it from your target language, for example, in Python:

       >>> a2 = A( [1,2,3,4] )
       
      +

      +std::initializer_list is simply a container that can only be initialised at compile time. +As such it is possible to write typemaps for a target language container to map onto +std::initializer_list. However, this can only be done for a fixed number of elements ... +there is no way to construct an initializer list with a variable number of arguments at runtime. +This is not particularly flexible though outside of C++ static initialization, +hence the need to provide an alternative for use from a target language. +

      + +

      +Initializer lists can appear in any function or method, not just constructors. +SWIG only ignores the constructors as this is where they commonly occur. +Users are recommended to manually ignore any other methods using an initialization list with %ignore. +

      +

      7.2.5 Uniform initialization

      diff --git a/Examples/test-suite/cpp0x_initializer_list.i b/Examples/test-suite/cpp0x_initializer_list.i index aa2791833..9d85766e2 100644 --- a/Examples/test-suite/cpp0x_initializer_list.i +++ b/Examples/test-suite/cpp0x_initializer_list.i @@ -1,7 +1,7 @@ /* This testcase checks whether SWIG correctly uses the new initializer_list introduced in C++0x. */ %module cpp0x_initializer_list -%warnfilter(520) A; +%warnfilter(SWIGWARN_LANG_INITIALIZER_LIST) A; %inline %{ #include @@ -10,6 +10,13 @@ class A { public: A( std::initializer_list ) {} A() {} + A(double d) {} +}; +class B { +public: + B( std::initializer_list, std::initializer_list ) {} + B() {} + void method(std::initializer_list init) {} }; %} diff --git a/Examples/test-suite/cpp0x_uniform_initialization.i b/Examples/test-suite/cpp0x_uniform_initialization.i index 083fac377..81a3e45de 100644 --- a/Examples/test-suite/cpp0x_uniform_initialization.i +++ b/Examples/test-suite/cpp0x_uniform_initialization.i @@ -1,7 +1,11 @@ -/* This testcase checks whether SWIG syntactically correctly parses the curly - brackets {} for uniform member initialization. */ +/* This testcase checks whether SWIG syntactically correctly parses the initialization syntax using + {} braces for uniform member initialization. */ %module cpp0x_uniform_initialization +%include + +%template(VectorInt) std::vector; + %inline %{ struct BasicStruct { int x; @@ -10,6 +14,8 @@ struct BasicStruct { struct AltStruct { AltStruct(int x, double y) : x_{x}, y_{y} {} + int getX() { return x_; } + double getY() { return y_; } private: int x_; @@ -19,4 +25,25 @@ private: BasicStruct var1{5, 3.2}; // only fills the struct components AltStruct var2{2, 4.3}; // calls the constructor +class MoreInit +{ +public: + int yarray[5] {1,2,3,4,5}; + char *charptr {nullptr}; + std::vector vi {1,2,3,4,5}; + + MoreInit() {} + + int more1(std::vector vv = {1,2,3,4}) { + int sum = 0; + for (int i : vv) + sum += i; + return sum; + } +}; +const int arr1[] = {1,2,3}; +const int arr2[]{1,2,3}; +const int arr3[][3]{ {1,2,3}, {4,5,6} }; +const int arr4[][3] = { {1,2,3}, {4,5,6} }; %} + diff --git a/Examples/test-suite/python/cpp0x_initializer_list_runme.py b/Examples/test-suite/python/cpp0x_initializer_list_runme.py new file mode 100644 index 000000000..5c8c153a5 --- /dev/null +++ b/Examples/test-suite/python/cpp0x_initializer_list_runme.py @@ -0,0 +1,5 @@ +import cpp0x_initializer_list + +a = cpp0x_initializer_list.A() +a = cpp0x_initializer_list.A(11.1) + diff --git a/Examples/test-suite/python/cpp0x_uniform_initialization_runme.py b/Examples/test-suite/python/cpp0x_uniform_initialization_runme.py new file mode 100644 index 000000000..42228f3d7 --- /dev/null +++ b/Examples/test-suite/python/cpp0x_uniform_initialization_runme.py @@ -0,0 +1,21 @@ +import cpp0x_uniform_initialization + +var1 = cpp0x_uniform_initialization.cvar.var1 +if var1.x != 5: + raise RuntimeError +var2 = cpp0x_uniform_initialization.cvar.var2 +if var2.getX() != 2: + raise RuntimeError + +m = cpp0x_uniform_initialization.MoreInit() +if m.charptr != None: + raise RuntimeError, m.charptr +m.charptr = "hello sir" +if m.charptr != "hello sir": + raise RuntimeError, m.charptr +if m.more1(m.vi) != 15: + raise RuntimeError, m.vi +if m.more1( [-1,1,2] ) != 2: + raise RuntimeError, m.vi +if m.more1() != 10: + raise RuntimeError diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index f5b5f6e2b..b3eb72493 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -5165,7 +5165,7 @@ def_args : EQUAL definetype { } | EQUAL LBRACE { skip_balanced('{','}'); - $$.val = 0; + $$.val = NewString(scanner_ccode); $$.rawval = 0; $$.type = T_INT; $$.bitfield = 0; @@ -6625,7 +6625,10 @@ mem_initializer_list : mem_initializer | mem_initializer_list COMMA mem_initializer PERIOD PERIOD PERIOD ; -mem_initializer : idcolon LPAREN { skip_balanced('(',')'); Clear(scanner_ccode); } +mem_initializer : idcolon LPAREN { + skip_balanced('(',')'); + Clear(scanner_ccode); + } /* Uniform initialization in C++0x. Example: struct MyStruct { @@ -6634,7 +6637,10 @@ mem_initializer : idcolon LPAREN { skip_balanced('(',')'); Clear(scanner_ccode); double y_; }; */ - | idcolon LBRACE { skip_balanced('{','}'); Clear(scanner_ccode); } + | idcolon LBRACE { + skip_balanced('{','}'); + Clear(scanner_ccode); + } ; template_decl : LESSTHAN valparms GREATERTHAN { From d613ef42f2973050cb7f399d51f64b8c5dbe72b2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 4 Feb 2013 07:12:05 +0000 Subject: [PATCH 0437/1160] Rework std::initializer_list handling to warn about usage in any method, not just constructors. A typemap is used to issue the warning and can be overridden with user defined behaviour. --- Doc/Manual/Cpp0x.html | 130 +++++++++++--- Doc/Manual/Warnings.html | 1 + Examples/test-suite/common.mk | 1 + Examples/test-suite/cpp0x_initializer_list.i | 20 ++- .../cpp0x_initializer_list_extend.i | 29 +++ .../cpp0x_initializer_list_extend_runme.py | 4 + Lib/swig.swg | 169 +++++++++--------- Lib/swigwarnings.swg | 1 + Source/CParse/parser.y | 36 ++-- Source/Include/swigwarn.h | 2 +- 10 files changed, 259 insertions(+), 134 deletions(-) create mode 100644 Examples/test-suite/cpp0x_initializer_list_extend.i create mode 100644 Examples/test-suite/python/cpp0x_initializer_list_extend_runme.py diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index 341cb3ce5..30a70e75e 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -125,53 +125,133 @@ public:

      7.2.4 Initializer lists

      -

      -Constructors using the std::initializer_list class are removed -from the wrapped class because the only way to access such a -constructor is at compile time using the initialization list syntax. -Initializer lists are very much a C++ construct and not very accessible from wrappers. +Initializer lists are very much a C++ compiler construct and are not very accessible from wrappers as +they are intended for compile time initialization of classes using the special std::initializer_list type. +SWIG detects usage of initializer lists and will emit a special informative warning each time one is used:

      -

      For now, if you want to fill the class components like this:

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

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

      -class A {
      +%ignore Container::Container(std::initializer_list<int>);
      +class Container {
       public:
      -  A( std::initializer_list<int> );
      +  Container(std::initializer_list<int>); // initializer-list constructor
      +  Container();
      +  void push_back(const int &);
      +  ...
       };
      -A a1 = {1,2,3,4};
       
      -

      you could add another constructor using std::vector for example:

      +

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

      -class A {
      +%include <std_vector.i>
      +class Container {
       public:
      -  A( std::initializer_list<int> );
      -  A( std::vector<int> );
      +  Container(const std::vector<int> &);
      +  Container(std::initializer_list<int>); // initializer-list constructor
      +  Container();
      +  void push_back(const int &);
      +  ...
       };
      -A a1 = {1,2,3,4};
       
      -

      And then construct it from your target language, for example, in Python:

      +

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

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

      -std::initializer_list is simply a container that can only be initialised at compile time. -As such it is possible to write typemaps for a target language container to map onto -std::initializer_list. However, this can only be done for a fixed number of elements ... -there is no way to construct an initializer list with a variable number of arguments at runtime. -This is not particularly flexible though outside of C++ static initialization, -hence the need to provide an alternative for use from a target language. +If you are unable to modify the class being wrapped, consider ignoring the initializer-list constructor and using +%extend to add in an alternative constructor: +

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

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

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

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

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

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

      -Initializer lists can appear in any function or method, not just constructors. -SWIG only ignores the constructors as this is where they commonly occur. -Users are recommended to manually ignore any other methods using an initialization list with %ignore. +Note that the default typemap for std::initializer_list does nothing but issue the warning +and hence any user supplied typemaps will override it and suppress the warning.

      7.2.5 Uniform initialization

      diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index 1571146f1..d8e76a471 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -497,6 +497,7 @@ example.i(4) : Syntax error in input.
    • 471. Unable to use return type type in director method
    • 474. Method method usage of the optimal attribute ignored in the out typemap as the following cannot be used to generate optimal code: code
    • 475. Multiple calls to method might be generated due to optimal attribute usage in the out typemap. +
    • 476. Initialization using std::initializer_list.
    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 915decfc2..4b4228db8 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -486,6 +486,7 @@ CPP0X_TEST_CASES = \ cpp0x_explicit_conversion_operators \ cpp0x_function_objects \ cpp0x_initializer_list \ + cpp0x_initializer_list_extend \ cpp0x_lambda_functions \ cpp0x_null_pointer_constant \ cpp0x_raw_string_literals \ diff --git a/Examples/test-suite/cpp0x_initializer_list.i b/Examples/test-suite/cpp0x_initializer_list.i index 9d85766e2..14833390e 100644 --- a/Examples/test-suite/cpp0x_initializer_list.i +++ b/Examples/test-suite/cpp0x_initializer_list.i @@ -1,22 +1,34 @@ -/* This testcase checks whether SWIG correctly uses the new initializer_list +/* This testcase shows a few simple ways to deal with the new initializer_list introduced in C++0x. */ %module cpp0x_initializer_list -%warnfilter(SWIGWARN_LANG_INITIALIZER_LIST) A; + +%warnfilter(SWIGWARN_TYPEMAP_INITIALIZER_LIST) B::B; +%ignore A::A(std::initializer_list); +%ignore B::method; + +%typemap(in) std::initializer_list { + $1 = {"Ab", "Fab"}; +} %inline %{ #include class A { public: - A( std::initializer_list ) {} + A(std::initializer_list) {} A() {} A(double d) {} }; class B { public: - B( std::initializer_list, std::initializer_list ) {} + B(std::initializer_list, std::initializer_list) {} B() {} void method(std::initializer_list init) {} }; +class C { +public: + C(std::initializer_list) {} + C() {} +}; %} diff --git a/Examples/test-suite/cpp0x_initializer_list_extend.i b/Examples/test-suite/cpp0x_initializer_list_extend.i new file mode 100644 index 000000000..d8443e622 --- /dev/null +++ b/Examples/test-suite/cpp0x_initializer_list_extend.i @@ -0,0 +1,29 @@ +/* This testcase shows how to replace std_initializer_list with std_vector. */ + +%module cpp0x_initializer_list_extend + +%ignore Container::Container(std::initializer_list); +%include +%template(VectorInt) std::vector; + +%extend Container { + Container(const std::vector &elements) { + Container *c = new Container(); + for (int element : elements) + c->push_back(element); + return c; + } +} + + +%inline %{ +#include + +class Container { +public: + Container(std::initializer_list) {} + Container() {} + void push_back(const int&) {} +}; +%} + diff --git a/Examples/test-suite/python/cpp0x_initializer_list_extend_runme.py b/Examples/test-suite/python/cpp0x_initializer_list_extend_runme.py new file mode 100644 index 000000000..b07231408 --- /dev/null +++ b/Examples/test-suite/python/cpp0x_initializer_list_extend_runme.py @@ -0,0 +1,4 @@ +import cpp0x_initializer_list_extend + +c = cpp0x_initializer_list_extend.Container( [10, 20, 30, 40] ) + diff --git a/Lib/swig.swg b/Lib/swig.swg index 97e7c80a4..ad6b7b64b 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -309,6 +309,88 @@ static int NAME(TYPE x) { %include +/* ----------------------------------------------------------------------------- + * Overloading support + * ----------------------------------------------------------------------------- */ + +/* + * Function/method overloading support. This is done through typemaps, + * but also involve a precedence level. + */ + +/* Macro for overload resolution */ + +%define %typecheck(_x...) %typemap(typecheck, precedence=_x) %enddef + +/* Macros for precedence levels */ + +%define SWIG_TYPECHECK_POINTER 0 %enddef +%define SWIG_TYPECHECK_ITERATOR 5 %enddef +%define SWIG_TYPECHECK_VOIDPTR 10 %enddef +%define SWIG_TYPECHECK_BOOL 15 %enddef +%define SWIG_TYPECHECK_UINT8 20 %enddef +%define SWIG_TYPECHECK_INT8 25 %enddef +%define SWIG_TYPECHECK_UINT16 30 %enddef +%define SWIG_TYPECHECK_INT16 35 %enddef +%define SWIG_TYPECHECK_UINT32 40 %enddef +%define SWIG_TYPECHECK_INT32 45 %enddef +%define SWIG_TYPECHECK_SIZE 47 %enddef +%define SWIG_TYPECHECK_PTRDIFF 48 %enddef +%define SWIG_TYPECHECK_UINT64 50 %enddef +%define SWIG_TYPECHECK_INT64 55 %enddef +%define SWIG_TYPECHECK_UINT128 60 %enddef +%define SWIG_TYPECHECK_INT128 65 %enddef +%define SWIG_TYPECHECK_INTEGER 70 %enddef +%define SWIG_TYPECHECK_FLOAT 80 %enddef +%define SWIG_TYPECHECK_DOUBLE 90 %enddef +%define SWIG_TYPECHECK_CPLXFLT 95 %enddef +%define SWIG_TYPECHECK_CPLXDBL 100 %enddef +%define SWIG_TYPECHECK_COMPLEX 105 %enddef +%define SWIG_TYPECHECK_UNICHAR 110 %enddef +%define SWIG_TYPECHECK_STDUNISTRING 115 %enddef +%define SWIG_TYPECHECK_UNISTRING 120 %enddef +%define SWIG_TYPECHECK_CHAR 130 %enddef +%define SWIG_TYPECHECK_STDSTRING 135 %enddef +%define SWIG_TYPECHECK_STRING 140 %enddef +%define SWIG_TYPECHECK_PAIR 150 %enddef +%define SWIG_TYPECHECK_VECTOR 160 %enddef +%define SWIG_TYPECHECK_DEQUE 170 %enddef +%define SWIG_TYPECHECK_LIST 180 %enddef +%define SWIG_TYPECHECK_SET 190 %enddef +%define SWIG_TYPECHECK_MULTISET 200 %enddef +%define SWIG_TYPECHECK_MAP 210 %enddef +%define SWIG_TYPECHECK_MULTIMAP 220 %enddef +%define SWIG_TYPECHECK_STACK 230 %enddef +%define SWIG_TYPECHECK_QUEUE 240 %enddef + +%define SWIG_TYPECHECK_BOOL_ARRAY 1015 %enddef +%define SWIG_TYPECHECK_INT8_ARRAY 1025 %enddef +%define SWIG_TYPECHECK_INT16_ARRAY 1035 %enddef +%define SWIG_TYPECHECK_INT32_ARRAY 1045 %enddef +%define SWIG_TYPECHECK_INT64_ARRAY 1055 %enddef +%define SWIG_TYPECHECK_INT128_ARRAY 1065 %enddef +%define SWIG_TYPECHECK_FLOAT_ARRAY 1080 %enddef +%define SWIG_TYPECHECK_DOUBLE_ARRAY 1090 %enddef +%define SWIG_TYPECHECK_CHAR_ARRAY 1130 %enddef +%define SWIG_TYPECHECK_STRING_ARRAY 1140 %enddef +%define SWIG_TYPECHECK_OBJECT_ARRAY 1150 %enddef + +%define SWIG_TYPECHECK_BOOL_PTR 2015 %enddef +%define SWIG_TYPECHECK_UINT8_PTR 2020 %enddef +%define SWIG_TYPECHECK_INT8_PTR 2025 %enddef +%define SWIG_TYPECHECK_UINT16_PTR 2030 %enddef +%define SWIG_TYPECHECK_INT16_PTR 2035 %enddef +%define SWIG_TYPECHECK_UINT32_PTR 2040 %enddef +%define SWIG_TYPECHECK_INT32_PTR 2045 %enddef +%define SWIG_TYPECHECK_UINT64_PTR 2050 %enddef +%define SWIG_TYPECHECK_INT64_PTR 2055 %enddef +%define SWIG_TYPECHECK_FLOAT_PTR 2080 %enddef +%define SWIG_TYPECHECK_DOUBLE_PTR 2090 %enddef +%define SWIG_TYPECHECK_CHAR_PTR 2130 %enddef + +%define SWIG_TYPECHECK_SWIGOBJECT 5000 %enddef + + /* ----------------------------------------------------------------------------- * Default handling of certain overloaded operators * ----------------------------------------------------------------------------- */ @@ -340,6 +422,10 @@ static int NAME(TYPE x) { /* Define std namespace */ namespace std { + /* Warn about std::initializer_list usage. The constructor/method where used should probably be ignored. See docs. */ + template class initializer_list {}; + %typemap(in, warning=SWIGWARN_TYPEMAP_INITIALIZER_LIST_MSG) initializer_list "" + %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) initializer_list "" } #endif @@ -500,89 +586,6 @@ namespace std { } } -/* ----------------------------------------------------------------------------- - * Overloading support - * ----------------------------------------------------------------------------- */ - -/* - * Function/method overloading support. This is done through typemaps, - * but also involve a precedence level. - */ - -/* Macro for overload resolution */ - -%define %typecheck(_x...) %typemap(typecheck, precedence=_x) %enddef - -/* Macros for precedence levels */ - -%define SWIG_TYPECHECK_POINTER 0 %enddef -%define SWIG_TYPECHECK_ITERATOR 5 %enddef -%define SWIG_TYPECHECK_VOIDPTR 10 %enddef -%define SWIG_TYPECHECK_BOOL 15 %enddef -%define SWIG_TYPECHECK_UINT8 20 %enddef -%define SWIG_TYPECHECK_INT8 25 %enddef -%define SWIG_TYPECHECK_UINT16 30 %enddef -%define SWIG_TYPECHECK_INT16 35 %enddef -%define SWIG_TYPECHECK_UINT32 40 %enddef -%define SWIG_TYPECHECK_INT32 45 %enddef -%define SWIG_TYPECHECK_SIZE 47 %enddef -%define SWIG_TYPECHECK_PTRDIFF 48 %enddef -%define SWIG_TYPECHECK_UINT64 50 %enddef -%define SWIG_TYPECHECK_INT64 55 %enddef -%define SWIG_TYPECHECK_UINT128 60 %enddef -%define SWIG_TYPECHECK_INT128 65 %enddef -%define SWIG_TYPECHECK_INTEGER 70 %enddef -%define SWIG_TYPECHECK_FLOAT 80 %enddef -%define SWIG_TYPECHECK_DOUBLE 90 %enddef -%define SWIG_TYPECHECK_CPLXFLT 95 %enddef -%define SWIG_TYPECHECK_CPLXDBL 100 %enddef -%define SWIG_TYPECHECK_COMPLEX 105 %enddef -%define SWIG_TYPECHECK_UNICHAR 110 %enddef -%define SWIG_TYPECHECK_STDUNISTRING 115 %enddef -%define SWIG_TYPECHECK_UNISTRING 120 %enddef -%define SWIG_TYPECHECK_CHAR 130 %enddef -%define SWIG_TYPECHECK_STDSTRING 135 %enddef -%define SWIG_TYPECHECK_STRING 140 %enddef -%define SWIG_TYPECHECK_PAIR 150 %enddef -%define SWIG_TYPECHECK_VECTOR 160 %enddef -%define SWIG_TYPECHECK_DEQUE 170 %enddef -%define SWIG_TYPECHECK_LIST 180 %enddef -%define SWIG_TYPECHECK_SET 190 %enddef -%define SWIG_TYPECHECK_MULTISET 200 %enddef -%define SWIG_TYPECHECK_MAP 210 %enddef -%define SWIG_TYPECHECK_MULTIMAP 220 %enddef -%define SWIG_TYPECHECK_STACK 230 %enddef -%define SWIG_TYPECHECK_QUEUE 240 %enddef - -%define SWIG_TYPECHECK_BOOL_ARRAY 1015 %enddef -%define SWIG_TYPECHECK_INT8_ARRAY 1025 %enddef -%define SWIG_TYPECHECK_INT16_ARRAY 1035 %enddef -%define SWIG_TYPECHECK_INT32_ARRAY 1045 %enddef -%define SWIG_TYPECHECK_INT64_ARRAY 1055 %enddef -%define SWIG_TYPECHECK_INT128_ARRAY 1065 %enddef -%define SWIG_TYPECHECK_FLOAT_ARRAY 1080 %enddef -%define SWIG_TYPECHECK_DOUBLE_ARRAY 1090 %enddef -%define SWIG_TYPECHECK_CHAR_ARRAY 1130 %enddef -%define SWIG_TYPECHECK_STRING_ARRAY 1140 %enddef -%define SWIG_TYPECHECK_OBJECT_ARRAY 1150 %enddef - -%define SWIG_TYPECHECK_BOOL_PTR 2015 %enddef -%define SWIG_TYPECHECK_UINT8_PTR 2020 %enddef -%define SWIG_TYPECHECK_INT8_PTR 2025 %enddef -%define SWIG_TYPECHECK_UINT16_PTR 2030 %enddef -%define SWIG_TYPECHECK_INT16_PTR 2035 %enddef -%define SWIG_TYPECHECK_UINT32_PTR 2040 %enddef -%define SWIG_TYPECHECK_INT32_PTR 2045 %enddef -%define SWIG_TYPECHECK_UINT64_PTR 2050 %enddef -%define SWIG_TYPECHECK_INT64_PTR 2055 %enddef -%define SWIG_TYPECHECK_FLOAT_PTR 2080 %enddef -%define SWIG_TYPECHECK_DOUBLE_PTR 2090 %enddef -%define SWIG_TYPECHECK_CHAR_PTR 2130 %enddef - - -%define SWIG_TYPECHECK_SWIGOBJECT 5000 %enddef - - /* ----------------------------------------------------------------------------- * Runtime code * ----------------------------------------------------------------------------- */ diff --git a/Lib/swigwarnings.swg b/Lib/swigwarnings.swg index 21498ebd3..34c98fbda 100644 --- a/Lib/swigwarnings.swg +++ b/Lib/swigwarnings.swg @@ -54,6 +54,7 @@ %define SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG "454:Setting a pointer/reference variable may leak memory." %enddef %define SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG "470:Thread/reentrant unsafe wrapping, consider returning by value instead." %enddef %define SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG "473:Returning a pointer or reference in a director method is not recommended." %enddef +%define SWIGWARN_TYPEMAP_INITIALIZER_LIST_MSG "476:Initialization using std::initializer_list." %enddef /* ----------------------------------------------------------------------------- * Operator related warning messages diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index b3eb72493..8ce5ed4dd 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -4635,27 +4635,21 @@ cpp_member : c_declaration { $$ = $1; } cpp_constructor_decl : storage_class type LPAREN parms RPAREN ctor_end { if (Classprefix) { - if ($4 && Getattr($4,"type") && strstr(Char(Getattr($4,"type")), "initializer_list<")) { - /* Ignore constructors containing initializer_list<> introduced in C++0x */ - Swig_warning(WARN_LANG_INITIALIZER_LIST, cparse_file, cparse_line, "Constructor with std::initializer_list<> argument ignored.\n"); - $$ = 0; - } else { - SwigType *decl = NewStringEmpty(); - $$ = new_node("constructor"); - Setattr($$,"storage",$1); - Setattr($$,"name",$2); - Setattr($$,"parms",$4); - SwigType_add_function(decl,$4); - Setattr($$,"decl",decl); - Setattr($$,"throws",$6.throws); - Setattr($$,"throw",$6.throwf); - if (Len(scanner_ccode)) { - String *code = Copy(scanner_ccode); - Setattr($$,"code",code); - Delete(code); - } - SetFlag($$,"feature:new"); - } + SwigType *decl = NewStringEmpty(); + $$ = new_node("constructor"); + Setattr($$,"storage",$1); + Setattr($$,"name",$2); + Setattr($$,"parms",$4); + SwigType_add_function(decl,$4); + Setattr($$,"decl",decl); + Setattr($$,"throws",$6.throws); + Setattr($$,"throw",$6.throwf); + if (Len(scanner_ccode)) { + String *code = Copy(scanner_ccode); + Setattr($$,"code",code); + Delete(code); + } + SetFlag($$,"feature:new"); } else { $$ = 0; } diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index ad8d1211d..218cc6f10 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -174,6 +174,7 @@ #define WARN_TYPEMAP_DIRECTOROUT_PTR 473 #define WARN_TYPEMAP_OUT_OPTIMAL_IGNORED 474 #define WARN_TYPEMAP_OUT_OPTIMAL_MULTIPLE 475 +#define WARN_TYPEMAP_INITIALIZER_LIST 476 /* -- Fragments -- */ #define WARN_FRAGMENT_NOT_FOUND 490 @@ -201,7 +202,6 @@ #define WARN_LANG_TEMPLATE_METHOD_IGNORE 519 #define WARN_LANG_SMARTPTR_MISSING 520 #define WARN_LANG_ILLEGAL_DESTRUCTOR 521 -#define WARN_LANG_INITIALIZER_LIST 522 /* -- Reserved (600-799) -- */ From 6399428a62ed932e593724f4ebb7041b17e7093c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 4 Feb 2013 20:05:34 +0000 Subject: [PATCH 0438/1160] Add lambda functions to the symbol tables and add ability to suppress lambda warnings. --- Doc/Manual/Cpp0x.html | 2 +- Examples/test-suite/cpp0x_lambda_functions.i | 28 +++++++++++++++++++- Source/CParse/parser.y | 19 ++++++++++--- Source/Modules/browser.cxx | 6 +++++ Source/Modules/lang.cxx | 5 ++++ Source/Modules/swigmod.h | 1 + Source/Modules/typepass.cxx | 10 ++++++- 7 files changed, 64 insertions(+), 7 deletions(-) diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index 30a70e75e..b85df1b09 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -320,7 +320,7 @@ auto sum = [](int x, int y) { return x+y; }; auto sum = [](int x, int y) -> int { return x+y; }; -

    The lambda functions are removed from the wrapper class for now, because of the lack of support +

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

    diff --git a/Examples/test-suite/cpp0x_lambda_functions.i b/Examples/test-suite/cpp0x_lambda_functions.i index 0f11f9e63..312414a49 100644 --- a/Examples/test-suite/cpp0x_lambda_functions.i +++ b/Examples/test-suite/cpp0x_lambda_functions.i @@ -5,7 +5,26 @@ */ %module cpp0x_lambda_functions -#pragma SWIG nowarn=SWIGWARN_LANG_NATIVE_UNIMPL +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda1; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda2; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda3; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda4; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda5; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda6; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda7; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda8; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda9; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda10; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda11; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda12; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda13; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda14; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda15; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda16; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda17; +%warnfilter(SWIGWARN_CPP11_LAMBDA) lambda18; +%warnfilter(SWIGWARN_CPP11_LAMBDA) Space1::lambda19; +%warnfilter(SWIGWARN_CPP11_LAMBDA) Space1::Space2::lambda20; %inline %{ /* Defined lambda function with return value. */ @@ -44,6 +63,13 @@ auto lambda16 = [] { return thing; }; auto lambda17 = [] { return thing; }(); constexpr auto lambda18 = [] (int x, int y) mutable throw(int) { return x+y; }; +namespace Space1 { + constexpr auto lambda19 = [] (int x, int y) mutable throw(int) { return x+y; }; + namespace Space2 { + constexpr auto lambda20 = [] (int x, int y) mutable throw(int) { return x+y; }; + } +} + int runLambda1() { return lambda1(5,6); } diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 8ce5ed4dd..b9c51571a 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3165,7 +3165,12 @@ c_declaration : c_decl { appendChild($$,firstChild($5)); } } - | cpp_lambda_decl { Swig_warning(WARN_CPP11_LAMBDA, cparse_file, cparse_line,"Lambda expressions and closures are not fully supported yet.\n"); $$ = $1; } + | cpp_lambda_decl { + $$ = $1; + SWIG_WARN_NODE_BEGIN($$); + Swig_warning(WARN_CPP11_LAMBDA, cparse_file, cparse_line, "Lambda expressions and closures are not fully supported yet.\n"); + SWIG_WARN_NODE_END($$); + } | USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_CPP11_ALIAS_DECLARATION, cparse_file, cparse_line,"The 'using' keyword in type aliasing is not fully supported yet.\n"); $$ = 0; } | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_CPP11_ALIAS_TEMPLATE, cparse_file, cparse_line,"The 'using' keyword in template aliasing is not fully supported yet.\n"); $$ = 0; } ; @@ -3366,13 +3371,19 @@ cpp_alternate_rettype : primitive_type { $$ = $1; } auto six = [](int x, int y) { return x+y; }(4, 2); ------------------------------------------------------------ */ cpp_lambda_decl : storage_class AUTO idcolon EQUAL lambda_introducer LPAREN parms RPAREN cpp_const lambda_body lambda_tail { - $$ = 0; + $$ = new_node("lambda"); + Setattr($$,"name",$3); + add_symbols($$); } | storage_class AUTO idcolon EQUAL lambda_introducer LPAREN parms RPAREN cpp_const ARROW type lambda_body lambda_tail { - $$ = 0; + $$ = new_node("lambda"); + Setattr($$,"name",$3); + add_symbols($$); } | storage_class AUTO idcolon EQUAL lambda_introducer lambda_body lambda_tail { - $$ = 0; + $$ = new_node("lambda"); + Setattr($$,"name",$3); + add_symbols($$); } ; diff --git a/Source/Modules/browser.cxx b/Source/Modules/browser.cxx index f5ceae5b1..217b40a7e 100644 --- a/Source/Modules/browser.cxx +++ b/Source/Modules/browser.cxx @@ -136,6 +136,12 @@ public: return SWIG_OK; } + virtual int lambdaDeclaration(Node *n) { + show_attributes(n); + emit_children(n); + return SWIG_OK; + } + virtual int enumDeclaration(Node *n) { show_attributes(n); emit_children(n); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 4f1657825..1890add23 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -139,6 +139,8 @@ int Dispatcher::emit_one(Node *n) { ret = namespaceDeclaration(n); } else if (strcmp(tag, "template") == 0) { ret = templateDeclaration(n); + } else if (strcmp(tag, "lambda") == 0) { + ret = lambdaDeclaration(n); } /* =============================================================== @@ -285,6 +287,9 @@ int Dispatcher::classDeclaration(Node *n) { int Dispatcher::templateDeclaration(Node *n) { return defaultHandler(n); } +int Dispatcher::lambdaDeclaration(Node *n) { + return defaultHandler(n); +} int Dispatcher::classforwardDeclaration(Node *n) { return defaultHandler(n); } diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index b3722af40..32fd06339 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -99,6 +99,7 @@ public: virtual int usingDeclaration(Node *n); virtual int namespaceDeclaration(Node *n); virtual int templateDeclaration(Node *n); + virtual int lambdaDeclaration(Node *n); enum AccessMode { PUBLIC, PRIVATE, PROTECTED }; diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index bdd64e3a5..af16afb21 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -524,7 +524,7 @@ class TypePass:private Dispatcher { } /* ------------------------------------------------------------ - * namespaceDeclaration() + * templateDeclaration() * ------------------------------------------------------------ */ virtual int templateDeclaration(Node *n) { @@ -543,6 +543,14 @@ class TypePass:private Dispatcher { return SWIG_OK; } + /* ------------------------------------------------------------ + * lambdaDeclaration() + * ------------------------------------------------------------ */ + + virtual int lambdaDeclaration(Node *) { + return SWIG_OK; + } + /* ------------------------------------------------------------ * classforwardDeclaration() * ------------------------------------------------------------ */ From 9193b3ed77b54ac46bde5af1de148a9e014daa6e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 4 Feb 2013 20:10:02 +0000 Subject: [PATCH 0439/1160] Remove unnecessary file/line setting in parser --- Source/CParse/parser.y | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index c93f44cd0..36adf5a09 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1158,8 +1158,6 @@ static Node *nested_forward_declaration(const char *storage, const char *kind, S if (sname) { /* Add forward declaration of the nested type */ Node *n = new_node("classforward"); - Setfile(n, cparse_file); - Setline(n, cparse_line); Setattr(n, "kind", kind); Setattr(n, "name", sname); Setattr(n, "storage", storage); @@ -3832,8 +3830,6 @@ cpp_forward_class_decl : storage_class cpptype idcolon SEMI { $$ = 0; } else { $$ = new_node("classforward"); - Setfile($$,cparse_file); - Setline($$,cparse_line); Setattr($$,"kind",$2); Setattr($$,"name",$3); Setattr($$,"sym:weak", "1"); From 3020bc328c5f832504882819723ac80ecf7e66eb Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 4 Feb 2013 20:26:52 +0000 Subject: [PATCH 0440/1160] Add template aliasing and type aliasing into symbol table and enable explicit warning suppression for these. They still need to be added into the parse tree and dealt with. --- Examples/test-suite/cpp0x_template_typedefs.i | 4 ++++ Source/CParse/parser.y | 24 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/cpp0x_template_typedefs.i b/Examples/test-suite/cpp0x_template_typedefs.i index bd7e2b220..aeffde11a 100644 --- a/Examples/test-suite/cpp0x_template_typedefs.i +++ b/Examples/test-suite/cpp0x_template_typedefs.i @@ -1,6 +1,9 @@ /* This testcase checks whether SWIG correctly parses alias templates. */ %module cpp0x_template_typedefs +%warnfilter(SWIGWARN_CPP11_ALIAS_TEMPLATE) TypedefName; +%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) PF; + %inline %{ template< typename T1, typename T2, int > class SomeType { @@ -9,6 +12,7 @@ class SomeType { int c; }; +// template aliasing template< typename T2 > using TypedefName = SomeType; diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index b9c51571a..5bbb63846 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3171,8 +3171,28 @@ c_declaration : c_decl { Swig_warning(WARN_CPP11_LAMBDA, cparse_file, cparse_line, "Lambda expressions and closures are not fully supported yet.\n"); SWIG_WARN_NODE_END($$); } - | USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_CPP11_ALIAS_DECLARATION, cparse_file, cparse_line,"The 'using' keyword in type aliasing is not fully supported yet.\n"); $$ = 0; } - | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL { skip_decl(); Swig_warning(WARN_CPP11_ALIAS_TEMPLATE, cparse_file, cparse_line,"The 'using' keyword in template aliasing is not fully supported yet.\n"); $$ = 0; } + | USING idcolon EQUAL { + skip_decl(); + $$ = new_node("using"); + Setattr($$,"name",$2); + add_symbols($$); + SWIG_WARN_NODE_BEGIN($$); + Swig_warning(WARN_CPP11_ALIAS_DECLARATION, cparse_file, cparse_line, "The 'using' keyword in type aliasing is not fully supported yet.\n"); + SWIG_WARN_NODE_END($$); + + $$ = 0; /* TODO - ignored for now */ + } + | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL { + skip_decl(); + $$ = new_node("using"); + Setattr($$,"name",$6); + add_symbols($$); + SWIG_WARN_NODE_BEGIN($$); + Swig_warning(WARN_CPP11_ALIAS_TEMPLATE, cparse_file, cparse_line, "The 'using' keyword in template aliasing is not fully supported yet.\n"); + SWIG_WARN_NODE_END($$); + + $$ = 0; /* TODO - ignored for now */ + } ; /* ------------------------------------------------------------ From dbf4821b18e0811564ae221619efaee3a3fd5ba2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 5 Feb 2013 07:17:54 +0000 Subject: [PATCH 0441/1160] Add ability to suppress variadic template first argumnet warning --- Source/CParse/parser.y | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 5bbb63846..f1973a05c 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2967,7 +2967,9 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va p = tp; def_supplied = 1; } else if (p && !tp) { /* Variadic template - tp < p */ + SWIG_WARN_NODE_BEGIN(nn); Swig_warning(WARN_CPP11_VARIADIC_TEMPLATE,cparse_file, cparse_line,"Only the first variadic template argument is currently supported.\n"); + SWIG_WARN_NODE_END(nn); break; } } From c1b99d427987524349e0c9ae427b7c694231d266 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 5 Feb 2013 23:08:08 +0000 Subject: [PATCH 0442/1160] User defined literals: fix for %rename and update docs --- Doc/Manual/Cpp0x.html | 28 ++++++++++++++++--- .../test-suite/cpp0x_userdefined_literals.i | 27 ++++++++++++++++++ Source/CParse/parser.y | 3 +- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html index b85df1b09..e9576ec84 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/Cpp0x.html @@ -631,7 +631,7 @@ In the above example SIZE is of course wrapped as a constant.

    7.2.18 New string literals

    -

    SWIG fully supports unicode string constants and raw string literals.

    +

    SWIG supports unicode string constants and raw string literals.

     // New string literals
    @@ -685,12 +685,32 @@ OutputType operator "" _mySuffix(const char32_t * string_values, size_t num_char
     

    -Note that the %rename directive currently does not parse the double quotes, so these can't be easily accessed from -target languages. +Like other operators that SWIG parses, a warning is given about renaming the operator in order for it to be wrapped:

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

    -Use of user-defined literals such as the following still give a syntax error: +If %rename is used, then it can be called like any other wrapped method. +Currently you need to specify the full declaration including parameters for %rename: +

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

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

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

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

    diff --git a/Examples/test-suite/cpp0x_userdefined_literals.i b/Examples/test-suite/cpp0x_userdefined_literals.i
    index b21ff762d..d20345fed 100644
    --- a/Examples/test-suite/cpp0x_userdefined_literals.i
    +++ b/Examples/test-suite/cpp0x_userdefined_literals.i
    @@ -2,6 +2,17 @@
        introduced in C++0x. */
     %module cpp0x_userdefined_literals
     
    +// Unfortunately full declaration is needed for %rename atm, the parameter list cannot be omitted.
    +%rename(MyRawLiteral)  operator"" _myRawLiteral(const char * value);
    +%rename(MySuffixIntegral) operator "" _mySuffixIntegral(unsigned long long);
    +%rename(MySuffixFloat) operator "" _mySuffixFloat(long double);
    +%rename(MySuffix1) operator "" _mySuffix1(const char * string_values, size_t num_chars);
    +%rename(MySuffix2) operator "" _mySuffix2(const wchar_t * string_values, size_t num_chars);
    +%rename(MySuffix3) operator "" _mySuffix3(const char16_t * string_values, size_t num_chars);
    +%rename(MySuffix4) operator "" _mySuffix4(const char32_t * string_values, size_t num_chars);
    +
    +%ignore operator "" _myRawLiteralIgnored(const char * value);
    +
     %inline %{
     #include 
     
    @@ -23,4 +34,20 @@ OutputType operator "" _mySuffix2(const wchar_t * string_values, size_t num_char
     OutputType operator "" _mySuffix3(const char16_t * string_values, size_t num_chars) { return OutputType(300); }
     OutputType operator "" _mySuffix4(const char32_t * string_values, size_t num_chars) { return OutputType(400); }
     
    +OutputType operator"" _myRawLiteralIgnored(const char * value) { return OutputType(15); }
     %}
    +
    +%{
    +// TODO: SWIG cannot parse these
    +OutputType some_variable_a = 1234_myRawLiteral;
    +
    +OutputType some_variable_b = 1234_mySuffixIntegral;
    +OutputType some_variable_c = 3.1416_mySuffixFloat;
    +
    +OutputType some_variable_d =   "1234"_mySuffix1;
    +OutputType some_variable_e = u8"1234"_mySuffix1;
    +OutputType some_variable_f =  L"1234"_mySuffix2;
    +OutputType some_variable_g =  u"1234"_mySuffix3;
    +OutputType some_variable_h =  U"1234"_mySuffix4;
    +%}
    +
    diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
    index f1973a05c..dfa2f8de2 100644
    --- a/Source/CParse/parser.y
    +++ b/Source/CParse/parser.y
    @@ -5677,10 +5677,11 @@ direct_declarator : idcolon {
     		    }
                      }
                      /* User-defined string literals. eg.
    -                    int operator""_mySuffix(const char* val, int length) {...} */
    +                    int operator"" _mySuffix(const char* val, int length) {...} */
     		 /* This produces one S/R conflict. */
                      | OPERATOR ID LPAREN parms RPAREN {
     		    SwigType *t;
    +                    Append($1, " "); /* intervening space is mandatory */
                         Append($1, Char($2));
     		    $$.id = Char($1);
     		    t = NewStringEmpty();
    
    From c6bc7b881f0b8f7fa26cddbc8a997b7be877b6e1 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Tue, 5 Feb 2013 23:09:21 +0000
    Subject: [PATCH 0443/1160] Remove test tokens
    
    ---
     Source/CParse/parser.y | 1 -
     1 file changed, 1 deletion(-)
    
    diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
    index dfa2f8de2..45b691689 100644
    --- a/Source/CParse/parser.y
    +++ b/Source/CParse/parser.y
    @@ -1725,7 +1725,6 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) {
     %token  OPERATOR
     %token  COPERATOR
     %token PARSETYPE PARSEPARM PARSEPARMS
    -%token TEST1 TEST2 TEST3
     
     %left  CAST
     %left  QUESTIONMARK
    
    From b725625e6fc29fc38e561f1c8455f4559add4d5e Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Fri, 8 Feb 2013 06:34:35 +0000
    Subject: [PATCH 0444/1160] Add support for thread_local when specified with
     other legitimate storage class specifiers - extern and static
    
    ---
     Doc/Manual/Cpp0x.html                         | 13 ++++--
     Examples/test-suite/cpp0x_thread_local.i      | 26 +++++++++--
     .../java/cpp0x_thread_local_runme.java        | 43 +++++++++++++++++++
     .../python/cpp0x_thread_local_runme.py        | 30 +++++++++++++
     Source/CParse/parser.y                        |  4 ++
     Source/Modules/allocate.cxx                   |  2 +-
     Source/Modules/contract.cxx                   |  2 +-
     Source/Modules/directors.cxx                  |  4 +-
     Source/Modules/go.cxx                         |  4 +-
     Source/Modules/lang.cxx                       |  7 ++-
     Source/Modules/typepass.cxx                   |  2 +-
     Source/Swig/cwrap.c                           |  6 +--
     Source/Swig/misc.c                            | 21 +++++++++
     Source/Swig/naming.c                          |  3 +-
     Source/Swig/swig.h                            |  2 +
     15 files changed, 145 insertions(+), 24 deletions(-)
     create mode 100644 Examples/test-suite/java/cpp0x_thread_local_runme.java
     create mode 100644 Examples/test-suite/python/cpp0x_thread_local_runme.py
    
    diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/Cpp0x.html
    index e9576ec84..457a7e41d 100644
    --- a/Doc/Manual/Cpp0x.html
    +++ b/Doc/Manual/Cpp0x.html
    @@ -722,17 +722,22 @@ OutputType var3 = 3.1416_suffix;
     

    7.2.20 Thread-local storage

    -

    SWIG correctly parses the thread_local keyword. For example, a variable +

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

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

    The new C++0x threading libraries are ignored because each SWIG target language offers -its own threading facilities.

    +

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

    7.2.21 Defaulting/deleting of standard functions on C++ objects

    diff --git a/Examples/test-suite/cpp0x_thread_local.i b/Examples/test-suite/cpp0x_thread_local.i index 2ec633319..5ba01ea58 100644 --- a/Examples/test-suite/cpp0x_thread_local.i +++ b/Examples/test-suite/cpp0x_thread_local.i @@ -1,11 +1,29 @@ -/* This testcase checks whether SWIG correctly parses the 'thread_local' - keyword before the member type and name. */ +/* This testcase checks whether SWIG correctly parses the 'thread_local' storage specifier */ %module cpp0x_thread_local %inline %{ -struct A { - thread_local int val; +struct ThreadLocals { +// thread_local int tval; // members must also be declared static + static thread_local int stval; + thread_local static int tsval; + static thread_local const int stcval88 = 88; + thread_local static const int tscval99 = 99; }; +thread_local int tval; +static thread_local int stval; +thread_local static int tsval; +extern thread_local int etval; +thread_local extern int teval; + +thread_local int ThreadLocals::stval = 11; +thread_local int ThreadLocals::tsval = 22; +thread_local const int ThreadLocals::stcval88; +thread_local const int ThreadLocals::tscval99; %} +%{ +// externs +thread_local int etval = 33; +thread_local int teval = 44; +%} diff --git a/Examples/test-suite/java/cpp0x_thread_local_runme.java b/Examples/test-suite/java/cpp0x_thread_local_runme.java new file mode 100644 index 000000000..adc88a903 --- /dev/null +++ b/Examples/test-suite/java/cpp0x_thread_local_runme.java @@ -0,0 +1,43 @@ +import cpp0x_thread_local.*; + +public class cpp0x_thread_local_runme { + + static { + try { + System.loadLibrary("cpp0x_thread_local"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) + { + if (ThreadLocals.getStval() != 11) + throw new RuntimeException(); + if (ThreadLocals.getTsval() != 22) + throw new RuntimeException(); + if (ThreadLocals.tscval99 != 99) + throw new RuntimeException(); + + cpp0x_thread_local.setEtval(-11); + if (cpp0x_thread_local.getEtval() != -11) + throw new RuntimeException(); + + cpp0x_thread_local.setStval(-22); + if (cpp0x_thread_local.getStval() != -22) + throw new RuntimeException(); + + cpp0x_thread_local.setTsval(-33); + if (cpp0x_thread_local.getTsval() != -33) + throw new RuntimeException(); + + cpp0x_thread_local.setEtval(-44); + if (cpp0x_thread_local.getEtval() != -44) + throw new RuntimeException(); + + cpp0x_thread_local.setTeval(-55); + if (cpp0x_thread_local.getTeval() != -55) + throw new RuntimeException(); + } +} diff --git a/Examples/test-suite/python/cpp0x_thread_local_runme.py b/Examples/test-suite/python/cpp0x_thread_local_runme.py new file mode 100644 index 000000000..b4aa177f6 --- /dev/null +++ b/Examples/test-suite/python/cpp0x_thread_local_runme.py @@ -0,0 +1,30 @@ +from cpp0x_thread_local import * + +t = ThreadLocals() +if t.stval != 11: + raise RuntimeError +if t.tsval != 22: + raise RuntimeError +if t.tscval99 != 99: + raise RuntimeError + +cvar.etval = -11 +if cvar.etval != -11: + raise RuntimeError + +cvar.stval = -22 +if cvar.stval != -22: + raise RuntimeError + +cvar.tsval = -33 +if cvar.tsval != -33: + raise RuntimeError + +cvar.etval = -44 +if cvar.etval != -44: + raise RuntimeError + +cvar.teval = -55 +if cvar.teval != -55: + raise RuntimeError + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 45b691689..33f11958e 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -5041,6 +5041,10 @@ storage_class : EXTERN { $$ = "extern"; } | EXPLICIT { $$ = "explicit"; } | CONSTEXPR { $$ = "constexpr"; } | THREAD_LOCAL { $$ = "thread_local"; } + | THREAD_LOCAL STATIC { $$ = "static thread_local"; } + | STATIC THREAD_LOCAL { $$ = "static thread_local"; } + | EXTERN THREAD_LOCAL { $$ = "extern thread_local"; } + | THREAD_LOCAL EXTERN { $$ = "extern thread_local"; } | empty { $$ = 0; } ; diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index 5320d9689..dee044bf3 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -771,7 +771,7 @@ Allocate(): /* Check to see if this is a static member or not. If so, we add an attribute cplus:staticbase that saves the current class */ - if (checkAttribute(n, "storage", "static")) { + if (Swig_storage_isstatic(n)) { Setattr(n, "cplus:staticbase", inclass); } diff --git a/Source/Modules/contract.cxx b/Source/Modules/contract.cxx index 5fa5bcad5..ffd799cfd 100644 --- a/Source/Modules/contract.cxx +++ b/Source/Modules/contract.cxx @@ -307,7 +307,7 @@ int Contracts::cDeclaration(Node *n) { return SWIG_OK; if (Getattr(n, "feature:contract")) - ret = emit_contract(n, (InClass && !checkAttribute(n, "storage", "static"))); + ret = emit_contract(n, InClass && !Swig_storage_isstatic(n)); return ret; } diff --git a/Source/Modules/directors.cxx b/Source/Modules/directors.cxx index 4cb38d0aa..2fdda5a12 100644 --- a/Source/Modules/directors.cxx +++ b/Source/Modules/directors.cxx @@ -275,8 +275,8 @@ String *Swig_method_decl(SwigType *rettype, SwigType *decl, const_String_or_char void Swig_director_emit_dynamic_cast(Node *n, Wrapper *f) { // TODO: why is the storage element removed in staticmemberfunctionHandler ?? if ((!is_public(n) && (is_member_director(n) || GetFlag(n, "explicitcall"))) || - (is_non_virtual_protected_access(n) && !(checkAttribute(n, "staticmemberfunctionHandler:storage", "static") || - checkAttribute(n, "storage", "static")) + (is_non_virtual_protected_access(n) && !(Swig_storage_isstatic_custom(n, "staticmemberfunctionHandler:storage") || + Swig_storage_isstatic(n)) && !Equal(nodeType(n), "constructor"))) { Node *parent = Getattr(n, "parentNode"); String *dirname; diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index fa706cb62..52e2459b7 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -1611,7 +1611,7 @@ private: return goComplexConstant(n, type); } - if (Getattr(n, "storage") && Strcmp(Getattr(n, "storage"), "static") == 0) { + if (Swig_storage_isstatic(n)) { return goComplexConstant(n, type); } @@ -4860,7 +4860,7 @@ private: bool isStatic(Node *n) { String *storage = Getattr(n, "storage"); - return (storage && (Strcmp(storage, "static") == 0 || Strcmp(storage, "friend") == 0) && (!SmartPointer || !Getattr(n, "allocate:smartpointeraccess"))); + return (storage && (Swig_storage_isstatic(n) || Strcmp(storage, "friend") == 0) && (!SmartPointer || !Getattr(n, "allocate:smartpointeraccess"))); } /* ---------------------------------------------------------------------- diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 1890add23..b4ad9c879 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1058,7 +1058,7 @@ int Language::cDeclaration(Node *n) { int Language::functionHandler(Node *n) { String *storage = Getattr(n, "storage"); int isfriend = CurrentClass && Cmp(storage, "friend") == 0; - int isstatic = CurrentClass && Cmp(storage, "static") == 0 && !(SmartPointer && Getattr(n, "allocate:smartpointeraccess")); + int isstatic = CurrentClass && Swig_storage_isstatic(n) && !(SmartPointer && Getattr(n, "allocate:smartpointeraccess")); Parm *p = Getattr(n, "parms"); if (GetFlag(n, "feature:del")) { /* the method acts like a delete operator, ie, we need to disown the parameter */ @@ -1366,7 +1366,6 @@ int Language::variableHandler(Node *n) { if (!CurrentClass) { globalvariableHandler(n); } else { - String *storage = Getattr(n, "storage"); Swig_save("variableHandler", n, "feature:immutable", NIL); if (SmartPointer) { /* If a smart-pointer and it's a constant access, we have to set immutable */ @@ -1374,7 +1373,7 @@ int Language::variableHandler(Node *n) { SetFlag(n, "feature:immutable"); } } - if ((Cmp(storage, "static") == 0) && !(SmartPointer && Getattr(n, "allocate:smartpointeraccess"))) { + if (Swig_storage_isstatic(n) && !(SmartPointer && Getattr(n, "allocate:smartpointeraccess"))) { staticmembervariableHandler(n); } else { membervariableHandler(n); @@ -1428,7 +1427,7 @@ int Language::membervariableHandler(Node *n) { String *target = 0; if (!Extend) { if (SmartPointer) { - if (checkAttribute(n, "storage", "static")) { + if (Swig_storage_isstatic(n)) { Node *sn = Getattr(n, "cplus:staticbase"); String *base = Getattr(sn, "name"); target = NewStringf("%s::%s", base, name); diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index af16afb21..7eebfe80b 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -995,7 +995,7 @@ class TypePass:private Dispatcher { String *symname = Getattr(n, "sym:name"); while (c) { if (Strcmp(nodeType(c), "cdecl") == 0) { - if (!(checkAttribute(c, "storage", "static") + if (!(Swig_storage_isstatic(c) || checkAttribute(c, "storage", "typedef") || checkAttribute(c, "storage", "friend") || (Getattr(c, "feature:extend") && !Getattr(c, "code")) diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index de93d84c0..f48108e15 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -922,7 +922,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas self = NewString("(*(this))->"); is_smart_pointer_overload = 1; } - else if (Cmp(Getattr(n, "storage"), "static") == 0) { + else if (Swig_storage_isstatic(n)) { String *cname = Getattr(n, "classname") ? Getattr(n, "classname") : classname; String *ctname = SwigType_namestr(cname); self = NewStringf("(*(%s const *)this)->", ctname); @@ -1064,7 +1064,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas String *func = NewStringf("%s(", mangled); String *cres; - if (Cmp(Getattr(n, "storage"), "static") != 0) { + if (!Swig_storage_isstatic(n)) { String *pname = Swig_cparm_name(pp, i); String *ctname = SwigType_namestr(cname); String *fadd = 0; @@ -1467,7 +1467,7 @@ int Swig_MembergetToFunction(Node *n, String *classname, int flags) { int varcref = flags & CWRAP_NATURAL_VAR; if (flags & CWRAP_SMART_POINTER) { - if (checkAttribute(n, "storage", "static")) { + if (Swig_storage_isstatic(n)) { Node *sn = Getattr(n, "cplus:staticbase"); String *base = Getattr(sn, "name"); self = NewStringf("%s::", base); diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 05dd0c480..1b8d79daf 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -262,6 +262,27 @@ void Swig_filename_unescape(String *filename) { #endif } +/* ----------------------------------------------------------------------------- + * Swig_storage_isstatic_custom() + * + * Determine if the storage class specifier is static + * ----------------------------------------------------------------------------- */ + +int Swig_storage_isstatic_custom(Node *n, const_String_or_char_ptr storage_name) { + const String *storage = Getattr(n, storage_name); + return storage ? Strncmp(storage, "static", 6) == 0 : 0; +} + +/* ----------------------------------------------------------------------------- + * Swig_storage_isstatic() + * + * Determine if the storage class specifier is static + * ----------------------------------------------------------------------------- */ + +int Swig_storage_isstatic(Node *n) { + return Swig_storage_isstatic_custom(n, "storage"); +} + /* ----------------------------------------------------------------------------- * Swig_string_escape() * diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index a4bff35af..119f816dc 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -938,8 +938,7 @@ static int nodes_are_equivalent(Node *a, Node *b, int a_inclass) { } /* static functions */ - if ((Cmp(a_storage, "static") == 0) - || (Cmp(b_storage, "static") == 0)) { + if (Swig_storage_isstatic(a) || Swig_storage_isstatic(b)) { if (Cmp(a_storage, b_storage) != 0) return 0; } diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 2dd027155..eccc18308 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -315,6 +315,8 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern void Swig_filename_correct(String *filename); extern String *Swig_filename_escape(String *filename); extern void Swig_filename_unescape(String *filename); + extern int Swig_storage_isstatic_custom(Node *n, const_String_or_char_ptr storage); + extern int Swig_storage_isstatic(Node *n); extern String *Swig_string_escape(String *s); extern String *Swig_string_mangle(const String *s); extern void Swig_scopename_split(const String *s, String **prefix, String **last); From 7fcfdeee0837fb240fb30c521a9471de6e0e7bfa Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 8 Feb 2013 07:38:10 +0000 Subject: [PATCH 0445/1160] Fixes detecting if a variable is extern when using 'extern thread_local' --- Source/Modules/cffi.cxx | 11 ----------- Source/Modules/clisp.cxx | 4 ++-- Source/Modules/lang.cxx | 8 ++++---- Source/Swig/misc.c | 11 +++++++++++ Source/Swig/swig.h | 1 + 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx index 29de9f9ed..0b1153d61 100644 --- a/Source/Modules/cffi.cxx +++ b/Source/Modules/cffi.cxx @@ -506,11 +506,6 @@ int CFFI::functionWrapper(Node *n) { void CFFI::emit_defun(Node *n, String *name) { - - // String *storage=Getattr(n,"storage"); - // if(!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc"))) - // return SWIG_OK; - String *func_name = Getattr(n, "sym:name"); ParmList *pl = Getattr(n, "parms"); @@ -583,12 +578,6 @@ int CFFI::constantWrapper(Node *n) { } int CFFI::variableWrapper(Node *n) { - // String *storage=Getattr(n,"storage"); - // Printf(stdout,"\"%s\" %s)\n",storage,Getattr(n, "sym:name")); - - // if(!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc"))) - // return SWIG_OK; - String *var_name = Getattr(n, "sym:name"); String *lisp_type = Swig_typemap_lookup("cin", n, "", 0); String *lisp_name = lispify_name(n, var_name, "'variable"); diff --git a/Source/Modules/clisp.cxx b/Source/Modules/clisp.cxx index 4290b5452..7dfa74539 100644 --- a/Source/Modules/clisp.cxx +++ b/Source/Modules/clisp.cxx @@ -148,7 +148,7 @@ int CLISP::top(Node *n) { int CLISP::functionWrapper(Node *n) { is_function = 1; String *storage = Getattr(n, "storage"); - if (!extern_all_flag && (!storage || (Strcmp(storage, "extern") && Strcmp(storage, "externc")))) + if (!extern_all_flag && (!storage || (!Swig_storage_isextern(n) && Strcmp(storage, "externc")))) return SWIG_OK; String *func_name = Getattr(n, "sym:name"); @@ -220,7 +220,7 @@ int CLISP::variableWrapper(Node *n) { // SwigType *type=; String *storage = Getattr(n, "storage"); - if (!extern_all_flag && (!storage || (Strcmp(storage, "extern") && Strcmp(storage, "externc")))) + if (!extern_all_flag && (!storage || (!Swig_storage_isextern(n) && Strcmp(storage, "externc")))) return SWIG_OK; String *var_name = Getattr(n, "sym:name"); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index b4ad9c879..5aa18a251 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -955,7 +955,7 @@ int Language::cDeclaration(Node *n) { if (AddExtern) { if (f_header) { - if ((Cmp(storage, "extern") == 0) || (ForceExtern && !storage)) { + if (Swig_storage_isextern(n) || (ForceExtern && !storage)) { /* we don't need the 'extern' part in the C/C++ declaration, and it produces some problems when namespace and SUN Studio is used. @@ -1017,12 +1017,12 @@ int Language::cDeclaration(Node *n) { if (Getattr(n, "nested")) SetFlag(n, "feature:immutable"); if (!CurrentClass) { - if ((Cmp(storage, "extern") == 0) || ForceExtern) { - f_header = Swig_filebyname("header"); + if (Swig_storage_isextern(n) || ForceExtern) { if (AddExtern) { + f_header = Swig_filebyname("header"); if (f_header) { String *str = SwigType_str(ty, name); - Printf(f_header, "extern %s;\n", str); + Printf(f_header, "%s %s;\n", Getattr(n, "storage"), str); Delete(str); } } diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 1b8d79daf..297d1ccdc 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -262,6 +262,17 @@ void Swig_filename_unescape(String *filename) { #endif } +/* ----------------------------------------------------------------------------- + * Swig_storage_isextern() + * + * Determine if the storage class specifier is extern (but not externc) + * ----------------------------------------------------------------------------- */ + +int Swig_storage_isextern(Node *n) { + const String *storage = Getattr(n, "storage"); + return storage ? Strcmp(storage, "extern") == 0 || Strncmp(storage, "extern ", 7) == 0 : 0; +} + /* ----------------------------------------------------------------------------- * Swig_storage_isstatic_custom() * diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index eccc18308..85d8c0b3e 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -315,6 +315,7 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern void Swig_filename_correct(String *filename); extern String *Swig_filename_escape(String *filename); extern void Swig_filename_unescape(String *filename); + extern int Swig_storage_isextern(Node *n); extern int Swig_storage_isstatic_custom(Node *n, const_String_or_char_ptr storage); extern int Swig_storage_isstatic(Node *n); extern String *Swig_string_escape(String *s); From e44656cfe5b1d79643a1b972736a5ab485a6e948 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 8 Feb 2013 18:45:29 +0000 Subject: [PATCH 0446/1160] Add support for extern "C" thread_local --- Examples/test-suite/cpp0x_thread_local.i | 2 ++ .../test-suite/java/cpp0x_thread_local_runme.java | 4 ++++ .../test-suite/python/cpp0x_thread_local_runme.py | 4 ++++ Source/CParse/parser.y | 13 +++++++++++-- Source/Modules/clisp.cxx | 5 ++--- Source/Modules/lang.cxx | 2 +- Source/Swig/misc.c | 11 +++++++++++ Source/Swig/swig.h | 1 + 8 files changed, 36 insertions(+), 6 deletions(-) diff --git a/Examples/test-suite/cpp0x_thread_local.i b/Examples/test-suite/cpp0x_thread_local.i index 5ba01ea58..96faaaec4 100644 --- a/Examples/test-suite/cpp0x_thread_local.i +++ b/Examples/test-suite/cpp0x_thread_local.i @@ -15,6 +15,7 @@ static thread_local int stval; thread_local static int tsval; extern thread_local int etval; thread_local extern int teval; +extern "C" thread_local int ectval; thread_local int ThreadLocals::stval = 11; thread_local int ThreadLocals::tsval = 22; @@ -26,4 +27,5 @@ thread_local const int ThreadLocals::tscval99; // externs thread_local int etval = 33; thread_local int teval = 44; +thread_local int ectval = 55; %} diff --git a/Examples/test-suite/java/cpp0x_thread_local_runme.java b/Examples/test-suite/java/cpp0x_thread_local_runme.java index adc88a903..d660f77db 100644 --- a/Examples/test-suite/java/cpp0x_thread_local_runme.java +++ b/Examples/test-suite/java/cpp0x_thread_local_runme.java @@ -39,5 +39,9 @@ public class cpp0x_thread_local_runme { cpp0x_thread_local.setTeval(-55); if (cpp0x_thread_local.getTeval() != -55) throw new RuntimeException(); + + cpp0x_thread_local.setEctval(-55); + if (cpp0x_thread_local.getEctval() != -55) + throw new RuntimeException(); } } diff --git a/Examples/test-suite/python/cpp0x_thread_local_runme.py b/Examples/test-suite/python/cpp0x_thread_local_runme.py index b4aa177f6..a4d9852f7 100644 --- a/Examples/test-suite/python/cpp0x_thread_local_runme.py +++ b/Examples/test-suite/python/cpp0x_thread_local_runme.py @@ -28,3 +28,7 @@ cvar.teval = -55 if cvar.teval != -55: raise RuntimeError +cvar.ectval = -66 +if cvar.ectval != -66: + raise RuntimeError + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 33f11958e..35e600d5e 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1491,8 +1491,9 @@ static void new_feature(const char *featurename, String *val, Hash *featureattri /* check if a function declaration is a plain C object */ static int is_cfunction(Node *n) { - if (!cparse_cplusplus || cparse_externc) return 1; - if (Cmp(Getattr(n,"storage"),"externc") == 0) { + if (!cparse_cplusplus || cparse_externc) + return 1; + if (Swig_storage_isexternc(n)) { return 1; } return 0; @@ -5034,6 +5035,14 @@ storage_class : EXTERN { $$ = "extern"; } $$ = 0; } } + | EXTERN string THREAD_LOCAL { + if (strcmp($2,"C") == 0) { + $$ = "externc thread_local"; + } else { + Swig_warning(WARN_PARSE_UNDEFINED_EXTERN,cparse_file, cparse_line,"Unrecognized extern type \"%s\".\n", $2); + $$ = 0; + } + } | STATIC { $$ = "static"; } | TYPEDEF { $$ = "typedef"; } | VIRTUAL { $$ = "virtual"; } diff --git a/Source/Modules/clisp.cxx b/Source/Modules/clisp.cxx index 7dfa74539..e7d971faa 100644 --- a/Source/Modules/clisp.cxx +++ b/Source/Modules/clisp.cxx @@ -148,7 +148,7 @@ int CLISP::top(Node *n) { int CLISP::functionWrapper(Node *n) { is_function = 1; String *storage = Getattr(n, "storage"); - if (!extern_all_flag && (!storage || (!Swig_storage_isextern(n) && Strcmp(storage, "externc")))) + if (!extern_all_flag && (!storage || (!Swig_storage_isextern(n) && !Swig_storage_isexternc(n)))) return SWIG_OK; String *func_name = Getattr(n, "sym:name"); @@ -217,10 +217,9 @@ int CLISP::constantWrapper(Node *n) { int CLISP::variableWrapper(Node *n) { is_function = 0; - // SwigType *type=; String *storage = Getattr(n, "storage"); - if (!extern_all_flag && (!storage || (!Swig_storage_isextern(n) && Strcmp(storage, "externc")))) + if (!extern_all_flag && (!storage || (!Swig_storage_isextern(n) && !Swig_storage_isexternc(n)))) return SWIG_OK; String *var_name = Getattr(n, "sym:name"); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 5aa18a251..6c2ea8271 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -985,7 +985,7 @@ int Language::cDeclaration(Node *n) { } } Printf(f_header, ";\n"); - } else if (Cmp(storage, "externc") == 0) { + } else if (Swig_storage_isexternc(n)) { /* here 'extern "C"' is needed */ String *str = SwigType_str(ty, name); Printf(f_header, "extern \"C\" %s;\n", str); diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 297d1ccdc..229633bab 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -273,6 +273,17 @@ int Swig_storage_isextern(Node *n) { return storage ? Strcmp(storage, "extern") == 0 || Strncmp(storage, "extern ", 7) == 0 : 0; } +/* ----------------------------------------------------------------------------- + * Swig_storage_isexternc() + * + * Determine if the storage class specifier is externc (but not plain extern) + * ----------------------------------------------------------------------------- */ + +int Swig_storage_isexternc(Node *n) { + const String *storage = Getattr(n, "storage"); + return storage ? Strcmp(storage, "externc") == 0 || Strncmp(storage, "externc ", 8) == 0 : 0; +} + /* ----------------------------------------------------------------------------- * Swig_storage_isstatic_custom() * diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 85d8c0b3e..b730ab04d 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -316,6 +316,7 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern String *Swig_filename_escape(String *filename); extern void Swig_filename_unescape(String *filename); extern int Swig_storage_isextern(Node *n); + extern int Swig_storage_isexternc(Node *n); extern int Swig_storage_isstatic_custom(Node *n, const_String_or_char_ptr storage); extern int Swig_storage_isstatic(Node *n); extern String *Swig_string_escape(String *s); From 8778724768e284e584b065063a1957fdd1fa9428 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 8 Feb 2013 18:55:16 +0000 Subject: [PATCH 0447/1160] Add support for extern "C++" - no warning should be issued as was previously occurring --- Examples/test-suite/common.mk | 2 +- Examples/test-suite/cpp0x_thread_local.i | 2 ++ Examples/test-suite/java/cpp0x_thread_local_runme.java | 4 ++++ Examples/test-suite/python/cpp0x_thread_local_runme.py | 4 ++++ Source/CParse/parser.y | 6 +++++- 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 4b4228db8..c0f642212 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -507,7 +507,7 @@ CPP0X_TEST_CASES = \ # cpp0x_inheriting_constructors \ # not supported by gcc-4.7 # cpp0x_hash_tables \ # not fully implemented yet # cpp0x_result_of \ # SWIG does not support -# cpp0x_thread_local \ # not supported by any compiler yet +# cpp0x_thread_local \ # needs gcc-4.8 # Broken C++0x test cases. CPP0X_TEST_BROKEN = diff --git a/Examples/test-suite/cpp0x_thread_local.i b/Examples/test-suite/cpp0x_thread_local.i index 96faaaec4..00f12dff9 100644 --- a/Examples/test-suite/cpp0x_thread_local.i +++ b/Examples/test-suite/cpp0x_thread_local.i @@ -16,6 +16,7 @@ thread_local static int tsval; extern thread_local int etval; thread_local extern int teval; extern "C" thread_local int ectval; +extern "C++" thread_local int ecpptval; thread_local int ThreadLocals::stval = 11; thread_local int ThreadLocals::tsval = 22; @@ -28,4 +29,5 @@ thread_local const int ThreadLocals::tscval99; thread_local int etval = 33; thread_local int teval = 44; thread_local int ectval = 55; +thread_local int ecpptval = 66; %} diff --git a/Examples/test-suite/java/cpp0x_thread_local_runme.java b/Examples/test-suite/java/cpp0x_thread_local_runme.java index d660f77db..dc7cafafe 100644 --- a/Examples/test-suite/java/cpp0x_thread_local_runme.java +++ b/Examples/test-suite/java/cpp0x_thread_local_runme.java @@ -43,5 +43,9 @@ public class cpp0x_thread_local_runme { cpp0x_thread_local.setEctval(-55); if (cpp0x_thread_local.getEctval() != -55) throw new RuntimeException(); + + cpp0x_thread_local.setEcpptval(-66); + if (cpp0x_thread_local.getEcpptval() != -66) + throw new RuntimeException(); } } diff --git a/Examples/test-suite/python/cpp0x_thread_local_runme.py b/Examples/test-suite/python/cpp0x_thread_local_runme.py index a4d9852f7..ff27b7785 100644 --- a/Examples/test-suite/python/cpp0x_thread_local_runme.py +++ b/Examples/test-suite/python/cpp0x_thread_local_runme.py @@ -32,3 +32,7 @@ cvar.ectval = -66 if cvar.ectval != -66: raise RuntimeError +cvar.ecpptval = -66 +if cvar.ecpptval != -66: + raise RuntimeError + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 35e600d5e..dc033ed7b 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -5027,9 +5027,11 @@ anon_bitfield_type : primitive_type { $$ = $1; * ====================================================================== */ storage_class : EXTERN { $$ = "extern"; } - | EXTERN string { + | EXTERN string { if (strcmp($2,"C") == 0) { $$ = "externc"; + } else if (strcmp($2,"C++") == 0) { + $$ = "extern"; } else { Swig_warning(WARN_PARSE_UNDEFINED_EXTERN,cparse_file, cparse_line,"Unrecognized extern type \"%s\".\n", $2); $$ = 0; @@ -5038,6 +5040,8 @@ storage_class : EXTERN { $$ = "extern"; } | EXTERN string THREAD_LOCAL { if (strcmp($2,"C") == 0) { $$ = "externc thread_local"; + } else if (strcmp($2,"C++") == 0) { + $$ = "extern thread_local"; } else { Swig_warning(WARN_PARSE_UNDEFINED_EXTERN,cparse_file, cparse_line,"Unrecognized extern type \"%s\".\n", $2); $$ = 0; From f17700aa1dc399dca66a45323eff81982856b250 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 8 Feb 2013 21:53:11 +0000 Subject: [PATCH 0448/1160] Suppress leaking memory warnings in rvalue reference tests --- Examples/test-suite/cpp0x_rvalue_reference2.i | 2 ++ Examples/test-suite/cpp0x_rvalue_reference3.i | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Examples/test-suite/cpp0x_rvalue_reference2.i b/Examples/test-suite/cpp0x_rvalue_reference2.i index b7f58afee..dbeaa78fa 100644 --- a/Examples/test-suite/cpp0x_rvalue_reference2.i +++ b/Examples/test-suite/cpp0x_rvalue_reference2.i @@ -1,5 +1,7 @@ %module cpp0x_rvalue_reference2 +%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK) globalrrval; + // This testcase tests lots of different places that rvalue reference syntax can be used %typemap(in) Something && "/*in Something && typemap*/" diff --git a/Examples/test-suite/cpp0x_rvalue_reference3.i b/Examples/test-suite/cpp0x_rvalue_reference3.i index c6fe60068..2da1bf741 100644 --- a/Examples/test-suite/cpp0x_rvalue_reference3.i +++ b/Examples/test-suite/cpp0x_rvalue_reference3.i @@ -1,5 +1,7 @@ %module cpp0x_rvalue_reference3 +%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); + %inline %{ #include struct Thing {}; From 054f9dba1a6f2914d1ed69042162aa4f9d72e0ef Mon Sep 17 00:00:00 2001 From: tpapp Date: Sat, 9 Feb 2013 13:46:46 +0100 Subject: [PATCH 0449/1160] CFFI - Fix missing package before &body - patch #22 Should fix https://github.com/swig/swig/issues/21. --- CHANGES.current | 9 ++++++--- Lib/cffi/cffi.swg | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index e6aebdb06..9436c29e7 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,13 +5,16 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ -2013-01-29: William +2013-02-09: wsfulton + [CFFI] Apply patch #22 - Fix missing package before &body + +2013-01-29: wsfulton [Java] Ensure 'javapackage' typemap is used as it stopped working from version 2.0.5. -2013-01-28: William +2013-01-28: wsfulton [Python] Apply patch SF #334 - Fix default value conversions "TRUE"->True, "FALSE"->False. -2013-01-28: William +2013-01-28: wsfulton [Java] Apply patch SF #335 - Truly ignore constructors in directors with %ignore. 2013-01-18: Brant Kyser diff --git a/Lib/cffi/cffi.swg b/Lib/cffi/cffi.swg index 6ac82f45e..427a8dc17 100644 --- a/Lib/cffi/cffi.swg +++ b/Lib/cffi/cffi.swg @@ -152,7 +152,7 @@ %insert("swiglisp") %{ ;;;SWIG wrapper code starts here -(cl:defmacro defanonenum (&body enums) +(cl:defmacro defanonenum (cl:&body enums) "Converts anonymous enums to defconstants." `(cl:progn ,@(cl:loop for value in enums for index = 0 then (cl:1+ index) From b80f4dc5e257a343381e3dbeebb206c1376e3ca3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 18 Feb 2013 19:53:37 +0000 Subject: [PATCH 0450/1160] Restrict the name used in %extend to be just the struct/class name and not a typedef to a class/struct. Typedefs were only partially working anyway. Anonymous struct typedefs excluded. Deprecate with a warning for now. --- CHANGES.current | 19 ++++++++ Doc/Manual/SWIG.html | 43 ++++++++++++++++--- Doc/Manual/Warnings.html | 3 +- Examples/test-suite/errors/expected.log | 4 ++ Examples/test-suite/errors/make.sh | 1 + Examples/test-suite/errors/swig_extend.i | 35 +++++++++++++++ .../extend_constructor_destructor.i | 3 ++ Examples/test-suite/extend_typedef_class.i | 3 ++ Source/CParse/parser.y | 42 ++++++++++++------ Source/Include/swigwarn.h | 1 + 10 files changed, 134 insertions(+), 20 deletions(-) create mode 100644 Examples/test-suite/errors/swig_extend.i diff --git a/CHANGES.current b/CHANGES.current index 9436c29e7..a111818d9 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,25 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-02-15: wsfulton + Deprecate typedef names used in %extend that are not the real class/struct name. For example: + + typedef struct StructBName { + int myint; + } StructB; + + %extend StructB { + void method() {} + } + + will now trigger a warning: + + swig_extend.i:19: Warning 326: Deprecated %extend name used - the struct name StructBName + should be used instead of the typedef name StructB. + + This is only partially working anyway (the %extend only worked if placed after the class + definition). + 2013-02-09: wsfulton [CFFI] Apply patch #22 - Fix missing package before &body diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 58a3c8e55..25dc899de 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -2699,7 +2699,7 @@ the following declaration :

     /* file : vector.h */
     ...
    -typedef struct {
    +typedef struct Vector {
     	double x,y,z;
     } Vector;
     
    @@ -2772,7 +2772,7 @@ of the Vector structure. For example:

    #include "vector.h" %} -typedef struct { +typedef struct Vector { double x,y,z; %extend { Vector(double x, double y, double z) { ... } @@ -2783,7 +2783,7 @@ typedef struct {

    -Finally, %extend can be used to access externally written +Note that %extend can be used to access externally written functions provided they follow the naming convention used in this example :

    @@ -2814,7 +2814,7 @@ double Vector_magnitude(Vector *v) { #include "vector.h" %} -typedef struct { +typedef struct Vector { double x,y,z; %extend { Vector(int,int,int); // This calls new_Vector() @@ -2826,6 +2826,37 @@ typedef struct {
    +

    +The name used for %extend should be the name of the struct and not the name of any typedef to the struct. +For example: +

    + +
    +typedef struct Integer {
    +	int value;
    +} Int;
    +%extend Integer { ...  } /* Correct name */
    +%extend Int { ...  } /* Incorrect name */
    +
    +struct Float {
    +	float value;
    +};
    +typedef struct Float FloatValue;
    +%extend Float { ...  } /* Correct name */
    +%extend FloatValue { ...  } /* Incorrect name */
    +
    + +

    +There is one exception to this rule and that is when the struct is anonymously named such as: +

    + +
    +typedef struct {
    +	double value;
    +} Double;
    +%extend Double { ...  } /* Okay */
    +
    +

    A little known feature of the %extend directive is that it can also be used to add synthesized attributes or to modify the @@ -2862,7 +2893,7 @@ For example, consider this interface:

    -typedef struct {
    +typedef struct Person {
       char name[50];
       ...
     } Person;
    @@ -2876,7 +2907,7 @@ the interface as follows to ensure this occurs whenever a name is read or writte
     
     
    -typedef struct {
    +typedef struct Person {
       %extend {
         char name[50];
       }
    diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html
    index 1571146f1..ccb1751d5 100644
    --- a/Doc/Manual/Warnings.html
    +++ b/Doc/Manual/Warnings.html
    @@ -423,7 +423,8 @@ example.i(4) : Syntax error in input.
     
  • 322. Redundant redeclaration of 'name'.
  • 323. Recursive scope inheritance of 'name'.
  • 324. Named nested template instantiations not supported. Processing as if no name was given to %template(). -
  • 325. Nested class not currently supported (name ignored). +
  • 325. Nested kind not currently supported (name ignored). +
  • 326. Deprecated %extend name used - the kind name 'name' should be used instead of the typedef name 'name'.
  • 350. operator new ignored.
  • 351. operator delete ignored.
  • 352. operator+ ignored. diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log index 9d4e5db77..d344d076b 100644 --- a/Examples/test-suite/errors/expected.log +++ b/Examples/test-suite/errors/expected.log @@ -188,6 +188,10 @@ pp_variable_args.i:6: Error: Variable length macro argument must be last paramet :::::::::::::::::::::::::::::::: swig_apply_nargs.i ::::::::::::::::::::::::::::::::::: swig_apply_nargs.i:6: Error: Can't apply (char *str,int len) to (int x). Number of arguments don't match. +:::::::::::::::::::::::::::::::: swig_extend.i ::::::::::::::::::::::::::::::::::: +swig_extend.i:19: Warning 326: Deprecated %extend name used - the struct name 'StructBName' should be used instead of the typedef name 'StructB'. +swig_extend.i:34: Warning 303: %extend defined for an undeclared class StructDName. + :::::::::::::::::::::::::::::::: swig_identifier.i ::::::::::::::::::::::::::::::::::: swig_identifier.i:5: Warning 503: Can't wrap 'foo bar' unless renamed to a valid identifier. diff --git a/Examples/test-suite/errors/make.sh b/Examples/test-suite/errors/make.sh index 90f17a92a..b194299c9 100755 --- a/Examples/test-suite/errors/make.sh +++ b/Examples/test-suite/errors/make.sh @@ -54,6 +54,7 @@ pp_unterm_comment pp_unterm_string pp_variable_args swig_apply_nargs +swig_extend swig_identifier swig_insert_bad swig_typemap_copy diff --git a/Examples/test-suite/errors/swig_extend.i b/Examples/test-suite/errors/swig_extend.i new file mode 100644 index 000000000..ef0652320 --- /dev/null +++ b/Examples/test-suite/errors/swig_extend.i @@ -0,0 +1,35 @@ +%module xxx + +typedef struct { + int myint; +} StructA; + +typedef struct StructBName { + int myint; +} StructB; + +typedef struct StructC { + int myint; +} StructC; + +%extend StructA { + void method() {} +} + +%extend StructB { + void method() {} +} + +%extend StructC { + void method() {} +} + +struct StructD { + int myint; +}; +typedef struct StructD StructDName; + +%extend StructDName { + void method() {} +} + diff --git a/Examples/test-suite/extend_constructor_destructor.i b/Examples/test-suite/extend_constructor_destructor.i index a0ab1a0f6..95b48a6c5 100644 --- a/Examples/test-suite/extend_constructor_destructor.i +++ b/Examples/test-suite/extend_constructor_destructor.i @@ -1,5 +1,8 @@ %module extend_constructor_destructor +%warnfilter(SWIGWARN_PARSE_EXTEND_NAME) Space::tagCStruct; +%warnfilter(SWIGWARN_PARSE_EXTEND_NAME) tagEStruct; + %inline %{ int globalVar = 0; diff --git a/Examples/test-suite/extend_typedef_class.i b/Examples/test-suite/extend_typedef_class.i index 731802573..2b8c38351 100644 --- a/Examples/test-suite/extend_typedef_class.i +++ b/Examples/test-suite/extend_typedef_class.i @@ -1,5 +1,8 @@ %module extend_typedef_class +%warnfilter(SWIGWARN_PARSE_EXTEND_NAME) tagCClass; +%warnfilter(SWIGWARN_PARSE_EXTEND_NAME) tagCStruct; + // classes in global namespace %inline %{ typedef struct tagAClass { diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 36adf5a09..74d41079c 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -38,6 +38,7 @@ static Node *top = 0; /* Top of the generated parse tree */ static int unnamed = 0; /* Unnamed datatype counter */ static Hash *extendhash = 0; /* Hash table of added methods */ static Hash *classes = 0; /* Hash table of classes */ +static Hash *classes_typedefs = 0; /* Hash table of typedef classes: typedef struct X {...} Y; */ static Symtab *prev_symtab = 0; static Node *current_class = 0; String *ModuleName = 0; @@ -718,7 +719,7 @@ static void check_extensions() { for (ki = First(extendhash); ki.key; ki = Next(ki)) { if (!Strchr(ki.key,'<')) { SWIG_WARN_NODE_BEGIN(ki.item); - Swig_warning(WARN_PARSE_EXTEND_UNDEF,Getfile(ki.item), Getline(ki.item), "%%extend defined for an undeclared class %s.\n", ki.key); + Swig_warning(WARN_PARSE_EXTEND_UNDEF,Getfile(ki.item), Getline(ki.item), "%%extend defined for an undeclared class %s.\n", SwigType_namestr(ki.key)); SWIG_WARN_NODE_END(ki.item); } } @@ -1909,20 +1910,34 @@ extend_directive : EXTEND options idcolon LBRACE { String *clsname; cplus_mode = CPLUS_PUBLIC; if (!classes) classes = NewHash(); + if (!classes_typedefs) classes_typedefs = NewHash(); if (!extendhash) extendhash = NewHash(); clsname = make_class_name($3); cls = Getattr(classes,clsname); if (!cls) { - /* No previous definition. Create a new scope */ - Node *am = Getattr(extendhash,clsname); - if (!am) { - Swig_symbol_newscope(); - Swig_symbol_setscopename($3); - prev_symtab = 0; + cls = Getattr(classes_typedefs, clsname); + if (!cls) { + /* No previous definition. Create a new scope */ + Node *am = Getattr(extendhash,clsname); + if (!am) { + Swig_symbol_newscope(); + Swig_symbol_setscopename($3); + prev_symtab = 0; + } else { + prev_symtab = Swig_symbol_setscope(Getattr(am,"symtab")); + } + current_class = 0; } else { - prev_symtab = Swig_symbol_setscope(Getattr(am,"symtab")); + /* Previous typedef class definition. Use its symbol table. + Deprecated, just the real name should be used. + Note that %extend before the class typedef never worked, only %extend after the class typdef. */ + prev_symtab = Swig_symbol_setscope(Getattr(cls, "symtab")); + current_class = cls; + extendmode = 1; + SWIG_WARN_NODE_BEGIN(cls); + Swig_warning(WARN_PARSE_EXTEND_NAME, cparse_file, cparse_line, "Deprecated %%extend name used - the %s name '%s' should be used instead of the typedef name '%s'.\n", Getattr(cls, "kind"), SwigType_namestr(Getattr(cls, "name")), $3); + SWIG_WARN_NODE_END(cls); } - current_class = 0; } else { /* Previous class definition. Use its symbol table */ prev_symtab = Swig_symbol_setscope(Getattr(cls,"symtab")); @@ -3585,7 +3600,6 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { if (!classes) classes = NewHash(); scpname = Swig_symbol_qualifiedscopename(0); Setattr(classes,scpname,$$); - Delete(scpname); appendChild($$,$7); @@ -3606,7 +3620,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Setattr(p,"type",ty); p = nextSibling(p); } - /* Dump nested classes */ + /* Class typedefs */ { String *name = $3; if ($9) { @@ -3626,8 +3640,9 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Delete(class_rename); class_rename = NewString(name); } - if (!Getattr(classes,tdscopename)) { - Setattr(classes,tdscopename,$$); + if (!classes_typedefs) classes_typedefs = NewHash(); + if (!Equal(scpname, tdscopename) && !Getattr(classes_typedefs, tdscopename)) { + Setattr(classes_typedefs, tdscopename, $$); } Setattr($$,"decl",decltype); Delete(class_scope); @@ -3638,6 +3653,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { } appendChild($$,dump_nested(Char(name))); } + Delete(scpname); if (cplus_mode != CPLUS_PUBLIC) { /* we 'open' the class at the end, to allow %template diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index 76f61ea93..a3fb31012 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -89,6 +89,7 @@ #define WARN_PARSE_REC_INHERITANCE 323 #define WARN_PARSE_NESTED_TEMPLATE 324 #define WARN_PARSE_NAMED_NESTED_CLASS 325 +#define WARN_PARSE_EXTEND_NAME 326 #define WARN_IGNORE_OPERATOR_NEW 350 /* new */ #define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */ From 70cd52f44d4e61460524105dabbe1ac7f29dc6f2 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 18 Feb 2013 10:31:23 +0100 Subject: [PATCH 0451/1160] Use "(void)" instead of "()" when wrapping no-argument extension functions. --- CHANGES.current | 39 +++++++++++++++++++++++++++++++++++++++ Source/Swig/cwrap.c | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index a111818d9..4f2477b02 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,45 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-02-18: wsfulton + Deprecate typedef names used as constructor and destructor names in %extend. The real + class/struct name should be used. + + typedef struct tagEStruct { + int ivar; + } EStruct; + + %extend tagEStruct { + EStruct() // illegal name, should be tagEStruct() + { + EStruct *s = new EStruct(); + s->ivar = ivar0; + return s; + } + ~EStruct() // illegal name, should be ~tagEStruct() + { + delete $self; + } + } + + For now these trigger a warning: + + extend_constructor_destructor.i:107: Warning 522: Use of an illegal constructor name 'EStruct' in + %extend is deprecated, the constructor name should be 'tagEStruct'. + extend_constructor_destructor.i:111: Warning 523: Use of an illegal destructor name 'EStruct' in + %extend is deprecated, the destructor name should be 'tagEStruct'. + + These %extend destructor and constructor names were valid up to swig-2.0.4, however swig-2.0.5 ignored + them altogether for C code as reported in SF bug #1306. The old behaviour of using them has been + restored for now, but is officially deprecated. This does not apply to anonymously defined typedef + classes/structs such as: + + typedef struct {...} X; + +2013-02-17: kwwette + When generating functions which wrap C extension code, use "(void)" for no-argument functions + instead of "()". This prevents warnings when compiling with "gcc -Wstrict-prototypes". + 2013-02-15: wsfulton Deprecate typedef names used in %extend that are not the real class/struct name. For example: diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 8cd48e94e..c7e101842 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -807,7 +807,7 @@ void Swig_replace_special_variables(Node *n, Node *parentnode, String *code) { * ----------------------------------------------------------------------------- */ static String *extension_code(Node *n, const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self) { String *parms_str = cplusplus ? ParmList_str_defaultargs(parms) : ParmList_str(parms); - String *sig = NewStringf("%s(%s)", function_name, parms_str); + String *sig = NewStringf("%s(%s)", function_name, (cplusplus || Len(parms_str)) ? parms_str : "void"); String *rt_sig = SwigType_str(return_type, sig); String *body = NewStringf("SWIGINTERN %s", rt_sig); Printv(body, code, "\n", NIL); From 2435b98a24f0be0abee1573948bb5d1f20d4b711 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 18 Feb 2013 22:37:43 +0000 Subject: [PATCH 0452/1160] Tweak to changes note --- CHANGES.current | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 4f2477b02..0b65717ff 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -41,7 +41,7 @@ Version 2.0.10 (in progress) typedef struct {...} X; 2013-02-17: kwwette - When generating functions which wrap C extension code, use "(void)" for no-argument functions + When generating functions provided by %extend, use "(void)" for no-argument functions instead of "()". This prevents warnings when compiling with "gcc -Wstrict-prototypes". 2013-02-15: wsfulton From d1b40b468b607c4c71f424a1a2d36c5b240ca975 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 18 Feb 2013 08:40:20 +0000 Subject: [PATCH 0453/1160] Fix C code where a typedef name was used for constructor and destructor names in %extend. Deprecate use of typedef names for constructor and destructor names going forwards. --- Doc/Manual/Warnings.html | 2 ++ Examples/test-suite/errors/expected.log | 6 ++++ Examples/test-suite/errors/swig_extend.i | 25 +++++++++++++++++ .../extend_constructor_destructor.i | 4 +++ Source/Include/swigwarn.h | 2 ++ Source/Modules/lang.cxx | 28 +++++++++++++++++-- 6 files changed, 65 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index ccb1751d5..cf4c38d7e 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -527,6 +527,8 @@ example.i(4) : Syntax error in input.
  • 519. %template() contains no name. Template method ignored: declaration
  • 520. Base/Derived class 'classname1' of 'classname2' is not similarly marked as a smart pointer.
  • 521. Illegal destructor name name. Ignored. +
  • 522. Use of an illegal constructor name 'name' in %extend is deprecated, the constructor name should be 'name'. +
  • 523. Use of an illegal destructor name 'name' in %extend is deprecated, the destructor name should be 'name'.

    14.9.6 Language module specific (700-899)

    diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log index d344d076b..2db3d8cbc 100644 --- a/Examples/test-suite/errors/expected.log +++ b/Examples/test-suite/errors/expected.log @@ -190,7 +190,13 @@ swig_apply_nargs.i:6: Error: Can't apply (char *str,int len) to (int x). Number :::::::::::::::::::::::::::::::: swig_extend.i ::::::::::::::::::::::::::::::::::: swig_extend.i:19: Warning 326: Deprecated %extend name used - the struct name 'StructBName' should be used instead of the typedef name 'StructB'. +swig_extend.i:45: Warning 326: Deprecated %extend name used - the struct name 'stru_struct' should be used instead of the typedef name 'stru'. +swig_extend.i:56: Warning 326: Deprecated %extend name used - the union name 'uni_union' should be used instead of the typedef name 'uni'. swig_extend.i:34: Warning 303: %extend defined for an undeclared class StructDName. +swig_extend.i:50: Warning 522: Use of an illegal constructor name 'stru' in %extend is deprecated, the constructor name should be 'stru_struct'. +swig_extend.i:53: Warning 523: Use of an illegal destructor name 'stru' in %extend is deprecated, the destructor name should be 'stru_struct'. +swig_extend.i:57: Warning 522: Use of an illegal constructor name 'uni' in %extend is deprecated, the constructor name should be 'uni_union'. +swig_extend.i:58: Warning 523: Use of an illegal destructor name 'uni' in %extend is deprecated, the destructor name should be 'uni_union'. :::::::::::::::::::::::::::::::: swig_identifier.i ::::::::::::::::::::::::::::::::::: swig_identifier.i:5: Warning 503: Can't wrap 'foo bar' unless renamed to a valid identifier. diff --git a/Examples/test-suite/errors/swig_extend.i b/Examples/test-suite/errors/swig_extend.i index ef0652320..3f8d9a787 100644 --- a/Examples/test-suite/errors/swig_extend.i +++ b/Examples/test-suite/errors/swig_extend.i @@ -33,3 +33,28 @@ typedef struct StructD StructDName; void method() {} } + +typedef struct stru_struct { + int bar; +} stru; +typedef union uni_union { + int un1; + double un2; +} uni; + +%extend stru { + stru() { + stru* s = (stru*)malloc(sizeof(stru)); + s->bar = 11; + return s; + } + ~stru() { + free($self); + } +} + +%extend uni { + uni() { return 0; } + ~uni() { free($self); } +} + diff --git a/Examples/test-suite/extend_constructor_destructor.i b/Examples/test-suite/extend_constructor_destructor.i index 95b48a6c5..c25b81b03 100644 --- a/Examples/test-suite/extend_constructor_destructor.i +++ b/Examples/test-suite/extend_constructor_destructor.i @@ -2,6 +2,10 @@ %warnfilter(SWIGWARN_PARSE_EXTEND_NAME) Space::tagCStruct; %warnfilter(SWIGWARN_PARSE_EXTEND_NAME) tagEStruct; +%warnfilter(SWIGWARN_LANG_EXTEND_CONSTRUCTOR) Space::tagCStruct::CStruct; +%warnfilter(SWIGWARN_LANG_EXTEND_DESTRUCTOR) Space::tagCStruct::~CStruct; +%warnfilter(SWIGWARN_LANG_EXTEND_CONSTRUCTOR) tagEStruct::EStruct; +%warnfilter(SWIGWARN_LANG_EXTEND_DESTRUCTOR) tagEStruct::~EStruct; %inline %{ int globalVar = 0; diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index a3fb31012..daf8b1791 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -197,6 +197,8 @@ #define WARN_LANG_TEMPLATE_METHOD_IGNORE 519 #define WARN_LANG_SMARTPTR_MISSING 520 #define WARN_LANG_ILLEGAL_DESTRUCTOR 521 +#define WARN_LANG_EXTEND_CONSTRUCTOR 522 +#define WARN_LANG_EXTEND_DESTRUCTOR 523 /* -- Reserved (600-799) -- */ diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 69df79271..4d1cefc69 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2631,10 +2631,22 @@ int Language::constructorDeclaration(Node *n) { if (!Equal(actual_name, expected_name) && !(Getattr(n, "template"))) { bool illegal_name = true; if (Extend) { - // SWIG extension - allow typedef names as destructor name in %extend - an unnamed struct declared with a typedef can thus be given a 'destructor'. + // Check for typedef names used as a constructor name in %extend. This is deprecated except for anonymous + // typedef structs which have had their symbol names adjusted to the typedef name in the parser. SwigType *name_resolved = SwigType_typedef_resolve_all(actual_name); SwigType *expected_name_resolved = SwigType_typedef_resolve_all(expected_name); + + if (!CPlusPlus) { + if (Strncmp(name_resolved, "struct ", 7) == 0) + Replace(name_resolved, "struct ", "", DOH_REPLACE_FIRST); + else if (Strncmp(name_resolved, "union ", 6) == 0) + Replace(name_resolved, "union ", "", DOH_REPLACE_FIRST); + } + illegal_name = !Equal(name_resolved, expected_name_resolved); + if (!illegal_name) + Swig_warning(WARN_LANG_EXTEND_CONSTRUCTOR, input_file, line_number, "Use of an illegal constructor name '%s' in %%extend is deprecated, the constructor name should be '%s'.\n", + SwigType_str(Swig_scopename_last(actual_name), 0), SwigType_str(Swig_scopename_last(expected_name), 0)); Delete(name_resolved); Delete(expected_name_resolved); } @@ -2770,10 +2782,22 @@ int Language::destructorDeclaration(Node *n) { if (!Equal(actual_name, expected_name) && !(Getattr(n, "template"))) { bool illegal_name = true; if (Extend) { - // SWIG extension - allow typedef names as destructor name in %extend - an unnamed struct declared with a typedef can thus be given a 'destructor'. + // Check for typedef names used as a destructor name in %extend. This is deprecated except for anonymous + // typedef structs which have had their symbol names adjusted to the typedef name in the parser. SwigType *name_resolved = SwigType_typedef_resolve_all(actual_name); SwigType *expected_name_resolved = SwigType_typedef_resolve_all(expected_name); + + if (!CPlusPlus) { + if (Strncmp(name_resolved, "struct ", 7) == 0) + Replace(name_resolved, "struct ", "", DOH_REPLACE_FIRST); + else if (Strncmp(name_resolved, "union ", 6) == 0) + Replace(name_resolved, "union ", "", DOH_REPLACE_FIRST); + } + illegal_name = !Equal(name_resolved, expected_name_resolved); + if (!illegal_name) + Swig_warning(WARN_LANG_EXTEND_DESTRUCTOR, input_file, line_number, "Use of an illegal destructor name '%s' in %%extend is deprecated, the destructor name should be '%s'.\n", + SwigType_str(Swig_scopename_last(actual_name), 0), SwigType_str(Swig_scopename_last(expected_name), 0)); Delete(name_resolved); Delete(expected_name_resolved); } From 9d330a99703f079bdff5a8d7945cc1d2d7c56f53 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Tue, 19 Feb 2013 11:46:27 +0100 Subject: [PATCH 0454/1160] Fix qualifier parsing in SwigType_add_qualifier() - use list to ensure qualifiers are unique and sorted - now allows 'qual' to contain multiple qualifiers --- Source/Swig/typeobj.c | 78 +++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index 20caa9ec9..cb9327dc7 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -16,6 +16,7 @@ #include "swig.h" #include +#include /* ----------------------------------------------------------------------------- * Synopsis @@ -425,61 +426,66 @@ int SwigType_isreference(const SwigType *t) { * Repeated qualifications have no effect. Moreover, the order of qualifications * is alphabetical---meaning that "const volatile" and "volatile const" are * stored in exactly the same way as "q(const volatile)". + * 'qual' can be a list of multiple qualifiers in any order, separated by spaces. * ----------------------------------------------------------------------------- */ -SwigType *SwigType_add_qualifier(SwigType *t, const_String_or_char_ptr qual) { - String *newq; - int sz, added = 0; - char *q, *cqual; +/* Helper function to sort the mangled list */ +static int SwigType_compare_qualifiers(const DOH *a, const DOH *b) { + return strcmp(Char(a), Char(b)); +} - char *c = Char(t); +SwigType *SwigType_add_qualifier(SwigType *t, const_String_or_char_ptr qual) { + List *qlist; + String *allq, *newq, *q; + int i, sz; + char *c, *cqual, *cq, *cqprev; + c = Char(t); cqual = Char(qual); - if (!(strncmp(c, "q(", 2) == 0)) { + /* if 't' has no qualifiers and 'qual' is a single qualifier, simply add it */ + if ((strncmp(c, "q(", 2) != 0) && (strstr(cqual, " ") == NULL)) { String *temp = NewStringf("q(%s).", cqual); Insert(t, 0, temp); Delete(temp); return t; } - /* The type already has a qualifier on it. In this case, we first check to - see if the qualifier is already specified. In that case do nothing. - If it is a new qualifier, we add it to the qualifier list in alphabetical - order */ - - sz = element_size(c); - - if (strstr(c, cqual)) { - /* Qualifier already added */ - return t; + /* create string of all qualifiers */ + if (strncmp(c, "q(", 2) == 0) { + allq = SwigType_parm(t); + Append(allq, " "); + SwigType_del_element(t); /* delete old qualifier list from 't' */ + } else { + allq = NewStringEmpty(); } + Append(allq, qual); - /* Add the qualifier to the existing list. */ + /* create list of all qualifiers from string */ + qlist = Split(allq, ' ', INT_MAX); + Delete(allq); + /* sort list */ + SortList(qlist, SwigType_compare_qualifiers); + + /* create new qualifier string from unique elements of list */ + sz = Len(qlist); newq = NewString("q("); - q = c + 2; - q = strtok(q, " )."); - while (q) { - if (strcmp(cqual, q) < 0) { - /* New qualifier is less that current qualifier. We need to insert it */ - Append(newq, cqual); - Append(newq, " "); - Append(newq, q); - added = 1; - } else { + cqprev = NULL; + for (i = 0; i < sz; ++i) { + q = Getitem(qlist, i); + cq = Char(q); + if (cqprev == NULL || strcmp(cqprev, cq) != 0) { + if (i > 0) { + Append(newq, " "); + } Append(newq, q); + cqprev = cq; } - q = strtok(NULL, " )."); - if (q) { - Append(newq, " "); - } - } - if (!added) { - Append(newq, " "); - Append(newq, cqual); } Append(newq, ")."); - Delslice(t, 0, sz); + Delete(qlist); + + /* replace qualifier string with new one */ Insert(t, 0, newq); Delete(newq); return t; From ee2b46abe0b747bc949538f51c9e2a989a867da9 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 18 Feb 2013 09:48:42 +0100 Subject: [PATCH 0455/1160] Fix SWIG's handling of qualified (e.g. const) variables of array type --- CHANGES.current | 12 +++ Examples/test-suite/common.mk | 1 + .../test-suite/typemap_array_qualifiers.i | 79 +++++++++++++++++++ Source/Swig/typesys.c | 61 ++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 Examples/test-suite/typemap_array_qualifiers.i diff --git a/CHANGES.current b/CHANGES.current index 0b65717ff..779e20528 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,18 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-02-19: kwwette + Fix bug in SWIG's handling of qualified (e.g. const) variables of array type. Given the typedef + a(7).q(volatile).double myarray // typedef volatile double[7] myarray; + the type + q(const).myarray // const myarray + becomes + a(7).q(const volatile).double // const volatile double[7] + Previously, SwigType_typedef_resolve() produces the type + q(const).a(7).q(volatile).double // non-sensical type + which would never match %typemap declarations, whose types were parsed correctly. + Add typemap_array_qualifiers.i to the test suite which checks for the correct behaviour. + 2013-02-18: wsfulton Deprecate typedef names used as constructor and destructor names in %extend. The real class/struct name should be used. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 173e9b287..83be90d2d 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -433,6 +433,7 @@ CPP_TEST_CASES += \ typedef_sizet \ typedef_struct \ typemap_arrays \ + typemap_array_qualifiers \ typemap_delete \ typemap_directorout \ typemap_global_scope \ diff --git a/Examples/test-suite/typemap_array_qualifiers.i b/Examples/test-suite/typemap_array_qualifiers.i new file mode 100644 index 000000000..947721402 --- /dev/null +++ b/Examples/test-suite/typemap_array_qualifiers.i @@ -0,0 +1,79 @@ +%module typemap_array_qualifiers + +%define CLEAR_SWIGTYPE_TYPEMAPS +%typemap(in) + SWIGTYPE, + SWIGTYPE *, + SWIGTYPE *const, + SWIGTYPE *const&, + const SWIGTYPE *, + const SWIGTYPE *const, + const SWIGTYPE *const&, + const volatile SWIGTYPE *, + const volatile SWIGTYPE *const, + const volatile SWIGTYPE *const&, + SWIGTYPE [], + SWIGTYPE [ANY], + const SWIGTYPE [], + const SWIGTYPE [ANY], + const volatile SWIGTYPE [], + const volatile SWIGTYPE [ANY], + SWIGTYPE &, + const SWIGTYPE &, + const volatile SWIGTYPE & +{ +%#error Incorrect typemap for $symname: $type +} +%enddef + +%inline %{ + typedef struct { + int a; + } SomeType; + typedef SomeType myarray[3]; + typedef const SomeType myconstarray[4]; + typedef volatile SomeType ** mycrazyarray[5]; + typedef volatile SomeType (mycrazyfunc)(SomeType); + typedef volatile SomeType (*mycrazyfuncptr)(SomeType); +%} + +CLEAR_SWIGTYPE_TYPEMAPS; +%typemap(in) SWIGTYPE [ANY] { +/* Correct typemap for $symname: $type */ +} +%inline %{ + void func1a(myarray x) {}; + void func1b(volatile myarray x) {}; +%} + +CLEAR_SWIGTYPE_TYPEMAPS; +%typemap(in) const SWIGTYPE [ANY] { +/* Correct typemap for $symname: $type */ +} +%typemap(in) const volatile SWIGTYPE [ANY] { +/* Correct typemap for $symname: $type */ +} +%inline %{ + void func2a(const myarray x) {}; + void func2b(const myconstarray x) {}; + void func2c(const volatile myconstarray x) {}; +%} + +CLEAR_SWIGTYPE_TYPEMAPS; +%typemap(in) volatile SWIGTYPE **const [ANY] { +/* Correct typemap for $symname: $type */ +} +%typemap(in) volatile SWIGTYPE **const [ANY][ANY] { +/* Correct typemap for $symname: $type */ +} +%inline %{ + void func3a(const mycrazyarray x, const mycrazyarray y[7]) {}; +%} + +CLEAR_SWIGTYPE_TYPEMAPS; +%typemap(in) SWIGTYPE (*const) (ANY) { +/* Correct typemap for $symname: $type */ +} +%inline %{ + void func4a(mycrazyfunc *const x, const mycrazyfuncptr y) {}; +%} diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index d12d70543..372ac3f65 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -792,6 +792,67 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) { goto return_result; } Delete(base); + + /* If 'type' is an array, then the right-most qualifier in 'r' should + be added to 'type' after the array qualifier, so that given + a(7).q(volatile).double myarray // typedef volatile double[7] myarray; + the type + q(const).myarray // const myarray + becomes + a(7).q(const volatile).double // const volatile double[7] + and NOT + q(const).a(7).q(volatile).double // non-sensical type + */ + if (r && Len(r) && SwigType_isarray(type)) { + List *r_elem; + String *r_qual; + int r_sz; + r_elem = SwigType_split(r); + r_sz = Len(r_elem); + r_qual = Getitem(r_elem, r_sz-1); + if (SwigType_isqualifier(r_qual)) { + String *new_r; + String *new_type; + List *type_elem; + String *type_qual; + String *r_qual_arg; + int i, type_sz; + + type_elem = SwigType_split(type); + type_sz = Len(type_elem); + i = 0; + for (i = 0; i < type_sz; ++i) { + String *e = Getitem(type_elem, i); + if (!SwigType_isarray(e)) + break; + } + type_qual = Copy(Getitem(type_elem, i)); + r_qual_arg = SwigType_parm(r_qual); + SwigType_add_qualifier(type_qual, r_qual_arg); + Delete(r_qual_arg); + Setitem(type_elem, i, type_qual); + + new_r = NewStringEmpty(); + for (i = 0; i < r_sz-1; ++i) { + Append(new_r, Getitem(r_elem, i)); + } + new_type = NewStringEmpty(); + for (i = 0; i < type_sz; ++i) { + Append(new_type, Getitem(type_elem, i)); + } +#ifdef SWIG_DEBUG + Printf(stdout, "r+type='%s%s' new_r+new_type='%s%s'\n", r, type, new_r, new_type); +#endif + + Delete(r); + r = new_r; + newtype = 1; + type = new_type; + Delete(type_elem); + } + Delete(r_elem); + } + Append(r, type); if (newtype) { Delete(type); From cfd8497f3edd85c2cbaab86365586cd773b12e17 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 21 Feb 2013 07:00:25 +0000 Subject: [PATCH 0456/1160] Cosmetic changes in SwigType_add_qualifier --- Source/Swig/typeobj.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index cb9327dc7..1fe63ff27 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -429,21 +429,16 @@ int SwigType_isreference(const SwigType *t) { * 'qual' can be a list of multiple qualifiers in any order, separated by spaces. * ----------------------------------------------------------------------------- */ -/* Helper function to sort the mangled list */ -static int SwigType_compare_qualifiers(const DOH *a, const DOH *b) { - return strcmp(Char(a), Char(b)); -} - SwigType *SwigType_add_qualifier(SwigType *t, const_String_or_char_ptr qual) { List *qlist; - String *allq, *newq, *q; + String *allq, *newq; int i, sz; - char *c, *cqual, *cq, *cqprev; - c = Char(t); - cqual = Char(qual); + const char *cqprev = 0; + const char *c = Char(t); + const char *cqual = Char(qual); /* if 't' has no qualifiers and 'qual' is a single qualifier, simply add it */ - if ((strncmp(c, "q(", 2) != 0) && (strstr(cqual, " ") == NULL)) { + if ((strncmp(c, "q(", 2) != 0) && (strstr(cqual, " ") == 0)) { String *temp = NewStringf("q(%s).", cqual); Insert(t, 0, temp); Delete(temp); @@ -464,17 +459,16 @@ SwigType *SwigType_add_qualifier(SwigType *t, const_String_or_char_ptr qual) { qlist = Split(allq, ' ', INT_MAX); Delete(allq); - /* sort list */ - SortList(qlist, SwigType_compare_qualifiers); + /* sort in alphabetical order */ + SortList(qlist, Strcmp); /* create new qualifier string from unique elements of list */ sz = Len(qlist); newq = NewString("q("); - cqprev = NULL; for (i = 0; i < sz; ++i) { - q = Getitem(qlist, i); - cq = Char(q); - if (cqprev == NULL || strcmp(cqprev, cq) != 0) { + String *q = Getitem(qlist, i); + const char *cq = Char(q); + if (cqprev == 0 || strcmp(cqprev, cq) != 0) { if (i > 0) { Append(newq, " "); } From de136ad6cf64c369f4d6551cd5185ac87c1410ba Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 21 Feb 2013 07:09:27 +0000 Subject: [PATCH 0457/1160] Uncomment testing of overloading of const char arrays which was fixed in svn r12541 for swig-2.0.3. --- Examples/test-suite/arrays_global.i | 2 -- 1 file changed, 2 deletions(-) diff --git a/Examples/test-suite/arrays_global.i b/Examples/test-suite/arrays_global.i index 10d29b6dc..fd53a224e 100644 --- a/Examples/test-suite/arrays_global.i +++ b/Examples/test-suite/arrays_global.i @@ -61,7 +61,6 @@ char* test_b(name a, const namea b) { return a; } -#if 0 int test_a(int a) { return a; } @@ -70,7 +69,6 @@ int test_b(int a) { return a; } -#endif %} From 8e340c158c41ee053fd2be2f30b47e9a060515c9 Mon Sep 17 00:00:00 2001 From: Michel Zou Date: Fri, 22 Feb 2013 10:11:50 +0100 Subject: [PATCH 0458/1160] Fixed #1300 clang warning in SWIG_Python_ConvertPtrAndOwn. --- Lib/python/pyrun.swg | 4 ++-- Lib/swigrun.swg | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 3585e7a3f..cbb993064 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1231,10 +1231,10 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int *ptr = vptr; /* transfer the ownership to 'ptr' */ iobj->own = 0; - res = SWIG_AddCast(res); + SWIG_AddCastInplace(&res); res = SWIG_AddNewMask(res); } else { - res = SWIG_AddCast(res); + SWIG_AddCastInplace(&res); } } } diff --git a/Lib/swigrun.swg b/Lib/swigrun.swg index e5afb62c4..3f68d66d6 100644 --- a/Lib/swigrun.swg +++ b/Lib/swigrun.swg @@ -161,13 +161,20 @@ # 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_AddCastInplace(int *r) { + if (SWIG_IsOK(*r)) { + *r = (SWIG_CastRank(*r) < SWIG_MAXCASTRANK) ? (*r + 1) : SWIG_ERROR; + } +} +SWIGINTERNINLINE int SWIG_AddCast(int r) { + SWIG_AddCastInplace(&r); + return r; } SWIGINTERNINLINE int SWIG_CheckState(int r) { return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; } #else /* no cast-rank mode */ +# define SWIG_AddCastInplace(r) # define SWIG_AddCast # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) #endif From 7acf6b5fef128de8e9ded023870006b10b4a39a8 Mon Sep 17 00:00:00 2001 From: Michel Zou Date: Mon, 25 Feb 2013 09:53:45 +0100 Subject: [PATCH 0459/1160] Revert "Fixed #1300 clang warning in SWIG_Python_ConvertPtrAndOwn." This reverts commit 8e340c158c41ee053fd2be2f30b47e9a060515c9. --- Lib/python/pyrun.swg | 4 ++-- Lib/swigrun.swg | 11 ++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index cbb993064..3585e7a3f 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1231,10 +1231,10 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int *ptr = vptr; /* transfer the ownership to 'ptr' */ iobj->own = 0; - SWIG_AddCastInplace(&res); + res = SWIG_AddCast(res); res = SWIG_AddNewMask(res); } else { - SWIG_AddCastInplace(&res); + res = SWIG_AddCast(res); } } } diff --git a/Lib/swigrun.swg b/Lib/swigrun.swg index 3f68d66d6..e5afb62c4 100644 --- a/Lib/swigrun.swg +++ b/Lib/swigrun.swg @@ -161,20 +161,13 @@ # endif # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) -SWIGINTERNINLINE int SWIG_AddCastInplace(int *r) { - if (SWIG_IsOK(*r)) { - *r = (SWIG_CastRank(*r) < SWIG_MAXCASTRANK) ? (*r + 1) : SWIG_ERROR; - } -} -SWIGINTERNINLINE int SWIG_AddCast(int r) { - SWIG_AddCastInplace(&r); - return r; +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_AddCastInplace(r) # define SWIG_AddCast # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) #endif From c23b7606cf665ce1a4e0f666f6926282971d108f Mon Sep 17 00:00:00 2001 From: Michel Zou Date: Mon, 25 Feb 2013 11:07:42 +0100 Subject: [PATCH 0460/1160] MOdified only no-cast-rank version of SWIG_AddCast. --- Lib/swigrun.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/swigrun.swg b/Lib/swigrun.swg index e5afb62c4..b3c11c136 100644 --- a/Lib/swigrun.swg +++ b/Lib/swigrun.swg @@ -168,7 +168,7 @@ 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_AddCast(r) ((r)+0) # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) #endif From 8155e145799728eba648f63a5e3da6ab513ed63b Mon Sep 17 00:00:00 2001 From: Michel Zou Date: Tue, 26 Feb 2013 09:26:13 +0100 Subject: [PATCH 0461/1160] Macro expansion to self assign is effectively ignored. --- Lib/swigrun.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/swigrun.swg b/Lib/swigrun.swg index b3c11c136..999c87333 100644 --- a/Lib/swigrun.swg +++ b/Lib/swigrun.swg @@ -168,7 +168,7 @@ SWIGINTERNINLINE int SWIG_CheckState(int r) { return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; } #else /* no cast-rank mode */ -# define SWIG_AddCast(r) ((r)+0) +# define SWIG_AddCast(r) (r) # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) #endif From 670962cfe8d951004f927c803e505f23ee373d3a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 4 Mar 2013 07:32:40 +0000 Subject: [PATCH 0462/1160] SWIG_TypeCompare was not working as commented - return values were 0,1 and not 1,0,-1. Although undocumented and not used anywhere within SWIG, it has been replaced with SWIG_TypeCmp to work as commented. --- Lib/swigrun.swg | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/Lib/swigrun.swg b/Lib/swigrun.swg index 999c87333..21f0a5c14 100644 --- a/Lib/swigrun.swg +++ b/Lib/swigrun.swg @@ -232,18 +232,18 @@ SWIG_TypeNameComp(const char *f1, const char *l1, /* Check type equivalence in a name list like ||... - Return 0 if not equal, 1 if equal + Return 0 if equal, -1 if nb < tb, 1 if nb > tb */ SWIGRUNTIME int -SWIG_TypeEquiv(const char *nb, const char *tb) { - int equiv = 0; +SWIG_TypeCmp(const char *nb, const char *tb) { + int equiv = 1; const char* te = tb + strlen(tb); const char* ne = nb; - while (!equiv && *ne) { + while (equiv != 0 && *ne) { for (nb = ne; *ne; ++ne) { if (*ne == '|') break; } - equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; + equiv = SWIG_TypeNameComp(nb, ne, tb, te); if (*ne) ++ne; } return equiv; @@ -251,24 +251,13 @@ SWIG_TypeEquiv(const char *nb, const char *tb) { /* Check type equivalence in a name list like ||... - Return 0 if equal, -1 if nb < tb, 1 if nb > tb + Return 0 if not equal, 1 if equal */ 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; +SWIG_TypeEquiv(const char *nb, const char *tb) { + return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0; } - /* Check the typename */ From e0b14786d6d22276dda85354babbfeffdfd78072 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 5 Mar 2013 18:17:50 +0100 Subject: [PATCH 0463/1160] Fix some useless code detected by scan-build (LLVM/Clang) --- Source/CParse/templ.c | 7 +------ Source/Modules/ocaml.cxx | 3 --- Source/Modules/octave.cxx | 1 - Source/Modules/perl5.cxx | 1 - Source/Modules/php.cxx | 2 -- Source/Swig/typeobj.c | 2 -- Source/Swig/typesys.c | 2 +- 7 files changed, 2 insertions(+), 16 deletions(-) diff --git a/Source/CParse/templ.c b/Source/CParse/templ.c index ed6acfc8c..48bdf4faa 100644 --- a/Source/CParse/templ.c +++ b/Source/CParse/templ.c @@ -317,14 +317,13 @@ int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab if (tp) { Symtab *tsdecl = Getattr(n, "sym:symtab"); while (p && tp) { - String *name, *value, *valuestr, *tydef, *tmp, *tmpr; + String *name, *value, *valuestr, *tmp, *tmpr; int sz, i; String *dvalue = 0; String *qvalue = 0; name = Getattr(tp, "name"); value = Getattr(p, "value"); - tydef = Getattr(p, "typedef"); if (name) { if (!value) @@ -365,9 +364,6 @@ int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab /* Printf(stdout,"'%s'\n", s); */ } - if (!tydef) { - tydef = dvalue; - } tmp = NewStringf("#%s", name); tmpr = NewStringf("\"%s\"", valuestr); @@ -375,7 +371,6 @@ int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab for (i = 0; i < sz; i++) { String *s = Getitem(cpatchlist, i); Replace(s, tmp, tmpr, DOH_REPLACE_ID); - /* Replace(s,name,tydef, DOH_REPLACE_ID); */ Replace(s, name, valuestr, DOH_REPLACE_ID); } Delete(tmp); diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index 34c8975c5..c5fcf69dd 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -1583,8 +1583,6 @@ public: String *cleanup = NewString(""); String *outarg = NewString(""); - idx = 0; - tm = Swig_typemap_lookup("directorout", n, "c_result", w); if (tm != 0) { Replaceall(tm, "$input", "swig_result"); @@ -1742,7 +1740,6 @@ public: p = NewParm(type, NewString("self"), n); q = Copy(p); set_nextSibling(p, parms); - parms = p; { Wrapper *w = NewWrapper(); diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index bbe442b7e..6f6e5b8ae 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -1371,7 +1371,6 @@ public: outputs++; // build argument list and type conversion string - idx = 0; p = l; while (p) { if (checkAttribute(p, "tmap:in:numinputs", "0")) { diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 7147e67c1..09500b23b 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -610,7 +610,6 @@ public: Printf(f->code, "}\n"); /* Write code to extract parameters. */ - i = 0; for (i = 0, p = l; i < num_arguments; i++) { /* Skip ignored arguments */ diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 292f979ba..fdd335993 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -787,7 +787,6 @@ public: } f = NewWrapper(); - numopt = 0; String *outarg = NewStringEmpty(); String *cleanup = NewStringEmpty(); @@ -1736,7 +1735,6 @@ public: if (!class_node) { /* This is needed when we're returning a pointer to a type * rather than returning the type by value or reference. */ - class_node = current_class; Delete(mangled); mangled = NewString(SwigType_manglestr(ret_type)); class_node = Getattr(zend_types, mangled); diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index 1fe63ff27..56892f3f8 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -746,7 +746,6 @@ SwigType *SwigType_add_function(SwigType *t, ParmList *parms) { Insert(t, 0, ")."); pstr = NewString("f("); - p = parms; for (p = parms; p; p = nextSibling(p)) { if (p != parms) Putc(',', pstr); @@ -844,7 +843,6 @@ SwigType *SwigType_add_template(SwigType *t, ParmList *parms) { Parm *p; Append(t, "<("); - p = parms; for (p = parms; p; p = nextSibling(p)) { String *v; if (Getattr(p, "default")) diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index 372ac3f65..c10ffbfb5 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -820,7 +820,7 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) { type_elem = SwigType_split(type); type_sz = Len(type_elem); - i = 0; + for (i = 0; i < type_sz; ++i) { String *e = Getitem(type_elem, i); if (!SwigType_isarray(e)) From fdea8a8f51a3734989729ea928b720083b32928f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 8 Mar 2013 22:19:07 +0000 Subject: [PATCH 0464/1160] More useless code removal as detected by scan-build (LLVM/Clang) using scan-build ./configure && scan-build make --- Source/Swig/scanner.c | 2 +- Source/Swig/stype.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index 52e21dc0a..ed2d43b51 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -1141,7 +1141,7 @@ void Scanner_skip_line(Scanner * s) { if ((c = nextchar(s)) == 0) return; if (c == '\\') { - c = nextchar(s); + nextchar(s); } else if (c == '\n') { done = 1; } diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index 8dc189725..fcaf54093 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -640,7 +640,6 @@ SwigType *SwigType_ltype(const SwigType *s) { if (td && (SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td))) { /* We need to use the typedef type */ Delete(tt); - tt = td; break; } else if (td) { Delete(tt); From 52c754a22d4556795a3927706256bfae4624ccc4 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Sun, 17 Feb 2013 15:56:25 +0100 Subject: [PATCH 0465/1160] Minor fix to Octave autodoc generation for functions returning structs Patch #27 - see also git commit 72ffdb930dcbbe0ae2a1cf7164a7ca4b632b1fee --- CHANGES.current | 3 +++ Source/Modules/octave.cxx | 10 +++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 779e20528..90389d812 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -56,6 +56,9 @@ Version 2.0.10 (in progress) When generating functions provided by %extend, use "(void)" for no-argument functions instead of "()". This prevents warnings when compiling with "gcc -Wstrict-prototypes". +2013-02-17: kwwette + [Octave] Minor fix to autodoc generation: get the right type for functions returning structs. + 2013-02-15: wsfulton Deprecate typedef names used in %extend that are not the real class/struct name. For example: diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 6f6e5b8ae..a9be76fc2 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -355,14 +355,10 @@ public: SwigType *type = Getattr(n, "type"); if (type && Strcmp(type, "void")) { - type = SwigType_base(type); - Node *lookup = Swig_symbol_clookup(type, 0); - if (lookup) - type = Getattr(lookup, "sym:name"); + Node *nn = classLookup(Getattr(n, "type")); + String *type_str = nn ? Copy(Getattr(nn, "sym:name")) : SwigType_str(type, 0); Append(decl_info, "@var{retval} = "); - String *type_str = NewString(""); - Printf(type_str, "@var{retval} is of type %s. ", type); - Append(args_str, type_str); + Printf(args_str, "%s@var{retval} is of type %s. ", args_str, type_str); Delete(type_str); } From 92276044248ca3a9b48c13afa85bc1175c4a3e21 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 16 Mar 2013 17:43:08 +0000 Subject: [PATCH 0466/1160] First attempt at Travis Continuous integration builds --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..ecd39ab85 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: cpp +compiler: + - gcc + - clang +script: ./autogen.sh && ./configure && make From 46523a074ff6ae1f9d8c52e270f0c3e13e2d7671 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 17 Mar 2013 19:44:28 +0000 Subject: [PATCH 0467/1160] Travis CI only on master and silent builds --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ecd39ab85..c41027bc0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,7 @@ language: cpp compiler: - gcc - clang -script: ./autogen.sh && ./configure && make +script: ./autogen.sh && ./configure && make -s +branches: + only: + - master From d2551e22e275780f9c6c5bf30d0b24a3ef556532 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 17 Mar 2013 20:32:03 +0000 Subject: [PATCH 0468/1160] Try Python test-suite on Travis --- .travis.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c41027bc0..ee7ded0de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,13 @@ language: cpp compiler: - gcc - clang -script: ./autogen.sh && ./configure && make -s +python: + - "2.7" + - "3.3" +before_install: + - sudo apt-get update -qq + - sudo apt-get install libboost-dev -qq +script: ./autogen.sh && ./configure && make -s && make -k check-python-test-suite branches: only: - master From 4003f65a94092d73b8b6e512097a45e8e9bc260b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 17 Mar 2013 21:40:44 +0000 Subject: [PATCH 0469/1160] Try combinations of Java and Python Travis builds --- .travis.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ee7ded0de..2ac250a4e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,31 @@ language: cpp compiler: - gcc - - clang +# - clang python: - "2.7" - "3.3" +jdk: + - oraclejdk7 + - openjdk6 +env: + - SWIGLANG=python +matrix: + include: + - python: "2.7" + - compiler: gcc + - env: SWIGLANG=python + include: + - jdk: oraclejdk7 + - compiler: gcc + - env: SWIGLANG=java before_install: - - sudo apt-get update -qq - sudo apt-get install libboost-dev -qq -script: ./autogen.sh && ./configure && make -s && make -k check-python-test-suite +script: + - set + - ./autogen.sh && ./configure + - make -s + - make -k check-$SWIGLANG-examples check-$SWIGLANG-test-suite branches: only: - master From 7c80f007c471302f0d6d07cf78846edd6fd9b493 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 19 Mar 2013 18:38:45 +1300 Subject: [PATCH 0470/1160] Fix typo in Python docstring for acquire method --- Lib/python/pyrun.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 3585e7a3f..7cf9c41fa 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -668,7 +668,7 @@ SwigPyObject_own(PyObject *v, PyObject *args) static PyMethodDef swigobject_methods[] = { {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, - {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_NOARGS, (char *)"aquires ownership of the pointer"}, + {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_NOARGS, (char *)"acquires ownership of the pointer"}, {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, {(char *)"append", (PyCFunction)SwigPyObject_append, METH_O, (char *)"appends another 'this' object"}, {(char *)"next", (PyCFunction)SwigPyObject_next, METH_NOARGS, (char *)"returns the next 'this' object"}, From 7b50640c055b45c17c40bde1f72ab932d55795c6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 19 Mar 2013 19:45:35 +0000 Subject: [PATCH 0471/1160] More Travis attempts at controlling what is built --- .travis.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2ac250a4e..92402d346 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,4 @@ language: cpp -compiler: - - gcc -# - clang -python: - - "2.7" - - "3.3" -jdk: - - oraclejdk7 - - openjdk6 -env: - - SWIGLANG=python matrix: include: - python: "2.7" From 9d0b20916f1aa709efcdd0d1f1a3985f205bf0a0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 18 Mar 2013 19:49:46 +0000 Subject: [PATCH 0472/1160] Add ability to suppress some director warnings by their method name, not just the containing class name --- Examples/test-suite/director_basic.i | 5 +++-- Examples/test-suite/director_classes.i | 3 ++- .../test-suite/java_director_assumeoverride.i | 1 - Source/Modules/lang.cxx | 15 +++++++++------ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Examples/test-suite/director_basic.i b/Examples/test-suite/director_basic.i index 56864f4a7..4c258b097 100644 --- a/Examples/test-suite/director_basic.i +++ b/Examples/test-suite/director_basic.i @@ -1,5 +1,6 @@ - %module(directors="1") director_basic - #pragma SWIG nowarn=SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR +%module(directors="1") director_basic + +%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) MyClass::pmethod; %{ #include diff --git a/Examples/test-suite/director_classes.i b/Examples/test-suite/director_classes.i index 7183e3d0a..98c29e88c 100644 --- a/Examples/test-suite/director_classes.i +++ b/Examples/test-suite/director_classes.i @@ -1,7 +1,8 @@ // Tests classes passed by value, pointer and reference // Note: C# module has a large runtime test -#pragma SWIG nowarn=SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR +%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Base::Ref; +%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Base::Ptr; %module(directors="1") director_classes diff --git a/Examples/test-suite/java_director_assumeoverride.i b/Examples/test-suite/java_director_assumeoverride.i index 7364a3d58..cddebb4d7 100644 --- a/Examples/test-suite/java_director_assumeoverride.i +++ b/Examples/test-suite/java_director_assumeoverride.i @@ -1,5 +1,4 @@ %module(directors="1") java_director_assumeoverride -#pragma SWIG nowarn=SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR %{ class OverrideMe { diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 4d1cefc69..eb7d49480 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -88,7 +88,6 @@ extern int AddExtern; * ---------------------------------------------------------------------- */ int Dispatcher::emit_one(Node *n) { - String *wrn; int ret = SWIG_OK; char *tag = Char(nodeType(n)); @@ -104,10 +103,9 @@ int Dispatcher::emit_one(Node *n) { return SWIG_OK; /* Look for warnings */ - wrn = Getattr(n, "feature:warnfilter"); - if (wrn) { + String *wrn = Getattr(n, "feature:warnfilter"); + if (wrn) Swig_warnfilter(wrn, 1); - } /* ============================================================ * C/C++ parsing @@ -181,9 +179,8 @@ int Dispatcher::emit_one(Node *n) { Swig_error(input_file, line_number, "Unrecognized parse tree node type '%s'\n", tag); ret = SWIG_ERROR; } - if (wrn) { + if (wrn) Swig_warnfilter(wrn, 0); - } return ret; } @@ -2063,6 +2060,10 @@ int Language::classDirectorMethods(Node *n) { if (GetFlag(method, "feature:nodirector")) continue; + String *wrn = Getattr(method, "feature:warnfilter"); + if (wrn) + Swig_warnfilter(wrn, 1); + String *type = Getattr(method, "nodeType"); if (!Cmp(type, "destructor")) { classDirectorDestructor(method); @@ -2074,6 +2075,8 @@ int Language::classDirectorMethods(Node *n) { SetFlag(item, "director"); Swig_restore(method); } + if (wrn) + Swig_warnfilter(wrn, 0); } return SWIG_OK; From e182b4844cc575da2f5e0321f4356783e1b63932 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 19 Mar 2013 18:34:06 +0000 Subject: [PATCH 0473/1160] Fix seg fault in SWIG using directors when class and virtual method names are the same except being in different namespaces when the %nspace feature is not being used. --- CHANGES.current | 4 ++++ Source/Modules/csharp.cxx | 13 ++----------- Source/Modules/d.cxx | 13 ++----------- Source/Modules/java.cxx | 16 +++------------- 4 files changed, 11 insertions(+), 35 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 90389d812..6547a88be 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.10 (in progress) ============================ +2013-03-19: wsfulton + [C#, Java, D] Fix seg fault in SWIG using directors when class and virtual method names are + the same except being in different namespaces when the %nspace feature is not being used. + 2013-02-19: kwwette Fix bug in SWIG's handling of qualified (e.g. const) variables of array type. Given the typedef a(7).q(volatile).double myarray // typedef volatile double[7] myarray; diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 0d15a9c1d..4ef62d2cc 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -630,23 +630,14 @@ public: *----------------------------------------------------------------------*/ UpcallData *addUpcallMethod(String *imclass_method, String *class_method, String *decl, String *overloaded_name) { - UpcallData *udata; - String *class_methodidx; - Hash *new_udata; String *key = NewStringf("%s|%s", imclass_method, decl); ++curr_class_dmethod; - /* Do we know about this director class already? */ - if ((udata = Getattr(dmethods_table, key))) { - Delete(key); - return Getattr(udata, "methodoff"); - } - - class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod); + String *class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod); n_dmethods++; - new_udata = NewHash(); + Hash *new_udata = NewHash(); Append(dmethods_seq, new_udata); Setattr(dmethods_table, key, new_udata); diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 88c3ccfff..e09e253f8 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -3704,23 +3704,14 @@ private: UpcallData *addUpcallMethod(String *imclass_method, String *class_method, String *decl, String *overloaded_name, String *return_type, String *param_list) { - UpcallData *udata; - String *class_methodidx; - Hash *new_udata; String *key = NewStringf("%s|%s", imclass_method, decl); ++curr_class_dmethod; - /* Do we know about this director class already? */ - if ((udata = Getattr(dmethods_table, key))) { - Delete(key); - return Getattr(udata, "methodoff"); - } - - class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod); + String *class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod); n_dmethods++; - new_udata = NewHash(); + Hash *new_udata = NewHash(); Append(dmethods_seq, new_udata); Setattr(dmethods_table, key, new_udata); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 2fb21eca8..f351c91a3 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -741,25 +741,15 @@ public: *----------------------------------------------------------------------*/ UpcallData *addUpcallMethod(String *imclass_method, String *class_method, String *imclass_desc, String *class_desc, String *decl) { - UpcallData *udata; - String *imclass_methodidx; - String *class_methodidx; - Hash *new_udata; String *key = NewStringf("%s|%s", imclass_method, decl); ++curr_class_dmethod; - /* Do we know about this director class already? */ - if ((udata = Getattr(dmethods_table, key))) { - Delete(key); - return Getattr(udata, "methodoff"); - } - - imclass_methodidx = NewStringf("%d", n_dmethods); - class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod); + String *imclass_methodidx = NewStringf("%d", n_dmethods); + String *class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod); n_dmethods++; - new_udata = NewHash(); + Hash *new_udata = NewHash(); Append(dmethods_seq, new_udata); Setattr(dmethods_table, key, new_udata); From 6fecb05379da3dd3e7a2dd2711d18b89db3dea28 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 19 Mar 2013 19:44:42 +0000 Subject: [PATCH 0474/1160] Fix director_nspace_director_name_collision test for languages that don't support %nspace --- Examples/test-suite/director_nspace_director_name_collision.i | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/test-suite/director_nspace_director_name_collision.i b/Examples/test-suite/director_nspace_director_name_collision.i index 5ef2509f8..e7abffcb1 100644 --- a/Examples/test-suite/director_nspace_director_name_collision.i +++ b/Examples/test-suite/director_nspace_director_name_collision.i @@ -39,6 +39,7 @@ namespace TopLevel %nspace TopLevel::B::Foo; #else #warning nspace feature not yet supported in this target language +%ignore TopLevel::B::Foo; #endif %feature("director") TopLevel::A::Foo; From 12ee3e9c4c1d9be3bb51ec6ce12e4aabc11fa388 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 19 Mar 2013 22:15:07 +0000 Subject: [PATCH 0475/1160] Fix Travis matrix --- .travis.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 92402d346..1f8255df2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,16 +2,14 @@ language: cpp matrix: include: - python: "2.7" - - compiler: gcc - - env: SWIGLANG=python - include: + compiler: gcc + env: SWIGLANG=python - jdk: oraclejdk7 - - compiler: gcc - - env: SWIGLANG=java + compiler: gcc + env: SWIGLANG=java before_install: - sudo apt-get install libboost-dev -qq script: - - set - ./autogen.sh && ./configure - make -s - make -k check-$SWIGLANG-examples check-$SWIGLANG-test-suite From 7d083890e66c5d5f9237926b0ab81d963057a3af Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 19 Mar 2013 22:41:04 +0000 Subject: [PATCH 0476/1160] More Travis build experiments --- .travis.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1f8255df2..78205c848 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,31 @@ language: cpp +compiler: + - gcc + - clang matrix: include: - python: "2.7" compiler: gcc env: SWIGLANG=python + - jdk: oraclejdk6 + compiler: gcc + env: SWIGLANG=java - jdk: oraclejdk7 compiler: gcc env: SWIGLANG=java + - perl: "5.10" + compiler: gcc + env: SWIGLANG=perl + - rvm: 1.8.7 + compiler: gcc + env: SWIGLANG=ruby before_install: - sudo apt-get install libboost-dev -qq script: - ./autogen.sh && ./configure - make -s - - make -k check-$SWIGLANG-examples check-$SWIGLANG-test-suite + - echo "SWIGLANG: $SWIGLANG" +# - make -k check-$SWIGLANG-examples check-$SWIGLANG-test-suite branches: only: - master From b72aca1d0739c66ff3bc3dc54385f296e662082b Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 20 Mar 2013 15:39:03 +1300 Subject: [PATCH 0477/1160] Fix typo in comment (swift->swig) --- Lib/python/director.swg | 2 +- Lib/ruby/director.swg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/python/director.swg b/Lib/python/director.swg index ca46f6dab..97edc7ef0 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -33,7 +33,7 @@ /* Use -DSWIG_DIRECTOR_NO_UEH if you prefer to avoid the use of the - Undefined Exception Handler provided by swift + Undefined Exception Handler provided by swig. */ #ifndef SWIG_DIRECTOR_NO_UEH #ifndef SWIG_DIRECTOR_UEH diff --git a/Lib/ruby/director.swg b/Lib/ruby/director.swg index 9807b11bb..a5daf2176 100644 --- a/Lib/ruby/director.swg +++ b/Lib/ruby/director.swg @@ -7,7 +7,7 @@ /* Use -DSWIG_DIRECTOR_NOUEH if you prefer to avoid the use of the - Undefined Exception Handler provided by swift + Undefined Exception Handler provided by swig. */ #ifndef SWIG_DIRECTOR_NOUEH #ifndef SWIG_DIRECTOR_UEH From 23bcc1c66b5f0c02960eacc8db975d110f2c1d8a Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 20 Mar 2013 16:45:24 +1300 Subject: [PATCH 0478/1160] Remove lingering relic of PHP4 support --- Lib/exception.i | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Lib/exception.i b/Lib/exception.i index 8d8df33dd..dc3a7f462 100644 --- a/Lib/exception.i +++ b/Lib/exception.i @@ -14,12 +14,8 @@ #ifdef SWIGPHP %{ -#if PHP_MAJOR_VERSION < 5 -# define SWIG_exception(code, msg) { zend_error(E_ERROR, msg); } -#else -# include "zend_exceptions.h" -# define SWIG_exception(code, msg) { zend_throw_exception(NULL, (char*)msg, code TSRMLS_CC); } -#endif +#include "zend_exceptions.h" +#define SWIG_exception(code, msg) { zend_throw_exception(NULL, (char*)msg, code TSRMLS_CC); } %} #endif From b132992b8aa9d3afcbc45d6a6d15fe9f60c559e5 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 21 Mar 2013 14:25:14 +1300 Subject: [PATCH 0479/1160] Stop claiming that SWIG_exception() can be used in helper functions --- Doc/Manual/Customization.html | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html index b75eda9c4..f420f42d6 100644 --- a/Doc/Manual/Customization.html +++ b/Doc/Manual/Customization.html @@ -592,9 +592,7 @@ SWIG_NullReferenceError
  • -Since the SWIG_exception() function is defined at the C-level -it can be used elsewhere in SWIG. This includes typemaps and helper -functions. +The SWIG_exception() function can also be used in typemaps.

    11.2 Object ownership and %newobject

    From 481ed3c57853463b01f7e3928491c7f0679d7776 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 21 Mar 2013 14:41:09 +1300 Subject: [PATCH 0480/1160] Update lingering configure.in references to say configure.ac --- Doc/Manual/Extending.html | 4 ++-- Examples/php/check.list | 2 +- Makefile.in | 4 ++-- configure.ac | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index 059388717..5ea4e51f4 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -3101,7 +3101,7 @@ As you can see, most usages are direct.
    -
    configure.in +
    configure.ac
    This file is processed by

    @@ -3551,7 +3551,7 @@ details being outlined earlier on. a runtime test, see for example Examples/python/class.

  • - Modify configure.in, Makefile.in and Examples/Makefile.in to run + Modify configure.ac, Makefile.in and Examples/Makefile.in to run these examples. Please make sure that if the new language is not installed properly on a box, make -k check should still work by skipping the tests and examples for the new language module. diff --git a/Examples/php/check.list b/Examples/php/check.list index 28c7a619f..fef3feba6 100644 --- a/Examples/php/check.list +++ b/Examples/php/check.list @@ -1,5 +1,5 @@ # see top-level Makefile.in -# (see also top-level configure.in kludge) +# (see also top-level configure.ac kludge) callback class constants diff --git a/Makefile.in b/Makefile.in index c6259916b..7ecbfa251 100644 --- a/Makefile.in +++ b/Makefile.in @@ -514,11 +514,11 @@ configfiles: Makefile: $(srcdir)/Makefile.in config.status $(SHELL) ./config.status -# This target is usually called from Source/Makefile when configure.in has +# This target is usually called from Source/Makefile when configure.ac has # changed. am--refresh: $(srcdir)/configure -$(srcdir)/configure: $(srcdir)/configure.in +$(srcdir)/configure: $(srcdir)/configure.ac @echo "Build system is out of date. If the following commands fail, please reconfigure by hand (rerun: ./autogen.sh && ./configure)" cd $(srcdir) && ./autogen.sh $(SHELL) ./config.status --recheck diff --git a/configure.ac b/configure.ac index 0e8ad5bb1..e205138e7 100644 --- a/configure.ac +++ b/configure.ac @@ -2482,4 +2482,4 @@ AC_CONFIG_FILES([preinst-swig], [chmod +x preinst-swig]) AC_CONFIG_FILES([CCache/ccache_swig_config.h]) AC_OUTPUT -dnl configure.in ends here +dnl configure.ac ends here From 9fbf771a006b50e58a8ec758bce7af4eacb2770f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 22 Mar 2013 09:21:07 +1300 Subject: [PATCH 0481/1160] Fix lack of indentation in ocaml and pike sections --- configure.ac | 74 ++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/configure.ac b/configure.ac index e205138e7..77e2b98bf 100644 --- a/configure.ac +++ b/configure.ac @@ -1504,47 +1504,47 @@ AC_ARG_WITH(ocamlmktop,[ --with-ocamlmktop=path Set location of ocamlmktop exe # First, check for "--without-ocaml" or "--with-ocaml=no". if test x"${OCAMLBIN}" = xno -o x"${with_alllang}" = xno ; then -AC_MSG_NOTICE([Disabling OCaml]) -OCAMLBIN= + AC_MSG_NOTICE([Disabling OCaml]) + OCAMLBIN= else -AC_MSG_CHECKING(for Ocaml DL load generator) -if test -z "$OCAMLDLGEN"; then -AC_CHECK_PROGS(OCAMLDLGEN, ocamldlgen, :) -else -OCAMLDLGEN="$OCAMLDLGEN" -fi + AC_MSG_CHECKING(for Ocaml DL load generator) + if test -z "$OCAMLDLGEN"; then + AC_CHECK_PROGS(OCAMLDLGEN, ocamldlgen, :) + else + OCAMLDLGEN="$OCAMLDLGEN" + fi -AC_MSG_CHECKING(for Ocaml package tool) -if test -z "$OCAMLFIND"; then -AC_CHECK_PROGS(OCAMLFIND, ocamlfind, :) -else -OCAMLFIND="$OCAMLFIND" -fi + AC_MSG_CHECKING(for Ocaml package tool) + if test -z "$OCAMLFIND"; then + AC_CHECK_PROGS(OCAMLFIND, ocamlfind, :) + else + OCAMLFIND="$OCAMLFIND" + fi -AC_MSG_CHECKING(for Ocaml compiler) -if test -z "$OCAMLC"; then -AC_CHECK_PROGS(OCAMLC, ocamlc, :) -else -OCAMLC="$OCAMLC" -fi + AC_MSG_CHECKING(for Ocaml compiler) + if test -z "$OCAMLC"; then + AC_CHECK_PROGS(OCAMLC, ocamlc, :) + else + OCAMLC="$OCAMLC" + fi -AC_MSG_CHECKING(for Ocaml interpreter) -if test "x$OCAMLBIN" = xyes; then -AC_CHECK_PROGS(OCAMLBIN, ocaml, :) -else -OCAMLBIN="$OCAMLBIN" -fi + AC_MSG_CHECKING(for Ocaml interpreter) + if test "x$OCAMLBIN" = xyes; then + AC_CHECK_PROGS(OCAMLBIN, ocaml, :) + else + OCAMLBIN="$OCAMLBIN" + fi -AC_MSG_CHECKING(for Ocaml toplevel creator) -if test -z "$OCAMLMKTOP"; then -AC_CHECK_PROGS(OCAMLMKTOP, ocamlmktop, :) -else -OCAMLMKTOP="$OCAMLMKTOP" -fi + AC_MSG_CHECKING(for Ocaml toplevel creator) + if test -z "$OCAMLMKTOP"; then + AC_CHECK_PROGS(OCAMLMKTOP, ocamlmktop, :) + else + OCAMLMKTOP="$OCAMLMKTOP" + fi -OCAMLLOC=loc -if test "$OCAMLC" != ":" ; then + OCAMLLOC=loc + if test "$OCAMLC" != ":" ; then AC_MSG_CHECKING(for Ocaml header files) dirs="/usr/lib/ocaml/caml /usr/local/lib/ocaml/caml" dir="`$OCAMLC -where 2>/dev/null`" @@ -1567,7 +1567,7 @@ if test "$OCAMLC" != ":" ; then OCAMLVER=`$OCAMLC -version | sed -e 's/.*version //g'` AC_COMPARE_VERSION([$OCAMLVER],[3.08.2],[:],[:],[OCAMLLOC=_loc]) AC_MSG_RESULT($OCAMLVER) -fi + fi fi # Disabling ocaml export OCAMLLOC @@ -1600,8 +1600,8 @@ AS_HELP_STRING([--with-pike=path], [Set location of Pike executable]),[PIKEBIN=" # First, check for "--without-pike" or "--with-pike=no". if test x"${PIKEBIN}" = xno -o x"${with_alllang}" = xno ; then -AC_MSG_NOTICE([Disabling Pike]) -PIKEBIN= + AC_MSG_NOTICE([Disabling Pike]) + PIKEBIN= else if test "x$PIKEBIN" = xyes; then From 2bbc52302c2c18f81e9e2b02f24a63e2097da94a Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 22 Mar 2013 09:37:02 +1300 Subject: [PATCH 0482/1160] Remove pointless assignments of variables to themselves --- configure.ac | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/configure.ac b/configure.ac index 77e2b98bf..d34f4fad7 100644 --- a/configure.ac +++ b/configure.ac @@ -713,8 +713,9 @@ else # Cygwin (Windows) needs the library for dynamic linking case $host in - *-*-cygwin* | *-*-mingw*) PYTHONDYNAMICLINKING="-L$PYLIB $PYLINK" - DEFS="-DUSE_DL_IMPORT $DEFS" PYINCLUDE="$PYINCLUDE" + *-*-cygwin* | *-*-mingw*) + PYTHONDYNAMICLINKING="-L$PYLIB $PYLINK" + DEFS="-DUSE_DL_IMPORT $DEFS" ;; *)PYTHONDYNAMICLINKING="";; esac @@ -808,8 +809,9 @@ else # Cygwin (Windows) needs the library for dynamic linking case $host in - *-*-cygwin* | *-*-mingw*) PYTHON3DYNAMICLINKING="-L$PYLIB $PY3LINK" - DEFS="-DUSE_DL_IMPORT $DEFS" PY3INCLUDE="$PY3INCLUDE" + *-*-cygwin* | *-*-mingw*) + PYTHON3DYNAMICLINKING="-L$PYLIB $PY3LINK" + DEFS="-DUSE_DL_IMPORT $DEFS" ;; *)PYTHON3DYNAMICLINKING="";; esac @@ -1300,7 +1302,7 @@ else AC_MSG_CHECKING(for MzScheme dynext object) MZDYNOBJ=`$MZSCHEME --eval '(begin (require dynext/link) (with-handlers (((lambda args #t) (lambda args #f))) (for-each (lambda (x) (printf "~a" x)) (expand-for-link-variant (current-standard-link-libraries)))))' 2>/dev/null` if test -f "$MZDYNOBJ"; then - MZDYNOBJ="$MZDYNOBJ" + : else # older versions (3.72 approx and earlier) MZDYNOBJ=`$MZSCHEME --mute-banner --version --eval '(begin (require (lib "link.ss" "dynext")) (with-handlers (((lambda args #t) (lambda args #f))) (for-each (lambda (x) (display x) (display " ")) ((current-make-standard-link-libraries)))) (with-handlers (((lambda args #t) (lambda args #f))) (for-each (lambda (x) (display x)) (expand-for-link-variant (current-standard-link-libraries)))))' 2>/dev/null` @@ -1511,36 +1513,26 @@ else AC_MSG_CHECKING(for Ocaml DL load generator) if test -z "$OCAMLDLGEN"; then AC_CHECK_PROGS(OCAMLDLGEN, ocamldlgen, :) - else - OCAMLDLGEN="$OCAMLDLGEN" fi AC_MSG_CHECKING(for Ocaml package tool) if test -z "$OCAMLFIND"; then AC_CHECK_PROGS(OCAMLFIND, ocamlfind, :) - else - OCAMLFIND="$OCAMLFIND" fi AC_MSG_CHECKING(for Ocaml compiler) if test -z "$OCAMLC"; then AC_CHECK_PROGS(OCAMLC, ocamlc, :) - else - OCAMLC="$OCAMLC" fi AC_MSG_CHECKING(for Ocaml interpreter) if test "x$OCAMLBIN" = xyes; then AC_CHECK_PROGS(OCAMLBIN, ocaml, :) - else - OCAMLBIN="$OCAMLBIN" fi AC_MSG_CHECKING(for Ocaml toplevel creator) if test -z "$OCAMLMKTOP"; then AC_CHECK_PROGS(OCAMLMKTOP, ocamlmktop, :) - else - OCAMLMKTOP="$OCAMLMKTOP" fi OCAMLLOC=loc From 250760daf498c339d2dd554f417b3390b02503ae Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 22 Mar 2013 10:43:19 +1300 Subject: [PATCH 0483/1160] Remove superfluous trailing semicolons --- configure.ac | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index d34f4fad7..820cf3691 100644 --- a/configure.ac +++ b/configure.ac @@ -205,7 +205,7 @@ then *-*-next*) if test "$ns_dyld" then LDSHARED='$(CC) $(LDFLAGS) -bundle -prebind' - else LDSHARED='$(CC) $(CFLAGS) -nostdlib -r'; + else LDSHARED='$(CC) $(CFLAGS) -nostdlib -r' fi if test "$with_next_framework" ; then LDSHARED="$LDSHARED \$(LDLIBRARY)" @@ -243,9 +243,9 @@ AC_MSG_CHECKING(TRYLINKINGWITHCXX) if test -z "$TRYLINKINGWITHCXX" then case $host in - *-*-solaris*) if test "$GCC" = yes; - then TRYLINKINGWITHCXX="CXXSHARED= $CXX -Wl,-G"; - else TRYLINKINGWITHCXX="CXXSHARED= $CXX -G -L/opt/SUNWspro/lib -lCrun -lCstd"; + *-*-solaris*) if test "$GCC" = yes + then TRYLINKINGWITHCXX="CXXSHARED= $CXX -Wl,-G" + else TRYLINKINGWITHCXX="CXXSHARED= $CXX -G -L/opt/SUNWspro/lib -lCrun -lCstd" fi;; *-*-hp*) TRYLINKINGWITHCXX="CXXSHARED= $CXX +z ";; *-*-darwin*) TRYLINKINGWITHCXX="CXXSHARED= $CXX -bundle -undefined suppress -flat_namespace";; @@ -270,9 +270,9 @@ AC_MSG_CHECKING(CCSHARED) if test -z "$CCSHARED" then case $host in - *-*-hp*) if test "$GCC" = yes; - then CCSHARED="-fpic"; - else CCSHARED="+z"; + *-*-hp*) if test "$GCC" = yes + then CCSHARED="-fpic" + else CCSHARED="+z" fi;; *-*-linux*) CCSHARED="-fpic";; *-*-freebsd* | *-*-openbsd*) CCSHARED="-fpic";; @@ -320,7 +320,7 @@ AC_MSG_RESULT($LINKFORSHARED) # Optional CFLAGS used to silence/enhance compiler warnings on some platforms. AC_MSG_CHECKING(PLATFLAGS) case $host in - *-*-solaris*) if test "$GCC" = yes; + *-*-solaris*) if test "$GCC" = yes then PLATFLAGS= else PLATFLAGS= # else PLATFLAGS="-errtags=yes" # Need more work as C examples use ld for linking @@ -859,7 +859,7 @@ if test -n "$PERL"; then if test -r $i/perl.h; then AC_MSG_RESULT($i) PERL5EXT="$i" - break; + break fi done if test "$PERL5EXT" = none; then @@ -1356,7 +1356,7 @@ if test -n "$RUBY"; then if test -r $i/ruby.h; then AC_MSG_RESULT($i) RUBYINCLUDE="-I$i" - break; + break fi done if test x"$RUBYARCH" != x""; then @@ -1406,7 +1406,7 @@ if test -n "$RUBY"; then for i in $dirs; do if (test -r $i/$rb_libruby;) then RUBYLIB="$i" - break; + break fi done fi @@ -1548,7 +1548,7 @@ else AC_MSG_RESULT($i) OCAMLEXT="$i" OCAMLINC="-I$OCAMLEXT" - break; + break fi done if test -z "$OCAMLINC"; then @@ -1794,7 +1794,7 @@ if test -z "$CSHARPBIN" ; then # The Mono compiler should emit: Mono C# compiler version a.b.c.d csharp_version_raw=`(mcs --version) 2>/dev/null` csharp_version_searched=`(mcs --version | sed -e "/C#/b" -e "/Mono/b" -e d) 2>/dev/null` # return string if contains 'Mono' or 'C#' - CSHARPCOMPILER=""; + CSHARPCOMPILER="" if test -n "$csharp_version_raw" ; then if test "$csharp_version_raw" = "$csharp_version_searched" ; then CSHARPCOMPILER="mcs" @@ -1951,7 +1951,7 @@ else if test -r $i/lua.h; then AC_MSG_RESULT($i/lua.h) LUAFLAGS="$ISYSTEM$i" - break; + break fi done if test -z "$LUAFLAGS"; then From f85a3b7756650e355374404c07ff8a08bc1fdea2 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 22 Mar 2013 10:46:44 +1300 Subject: [PATCH 0484/1160] Remove handling for Python <1.5 - we only support >=2.0 now --- configure.ac | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 820cf3691..f57a65fda 100644 --- a/configure.ac +++ b/configure.ac @@ -703,12 +703,7 @@ else AC_MSG_RESULT($PYLIB) fi - # Check for really old versions - if test -r $PYLIB/libPython.a; then - PYLINK="-lModules -lPython -lObjects -lParser" - else - PYLINK="-l$PYVERSION" - fi + PYLINK="-l$PYVERSION" fi # Cygwin (Windows) needs the library for dynamic linking From 5199a9002fbf4e3c8f50372d965bbbcf25c577db Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 22 Mar 2013 11:16:48 +1300 Subject: [PATCH 0485/1160] Correct comment about sys.lib --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index f57a65fda..cfbc09426 100644 --- a/configure.ac +++ b/configure.ac @@ -670,7 +670,7 @@ else AC_MSG_CHECKING(for Python lib dir) PYLIBDIR=`($PYTHON -c "import sys; print sys.lib") 2>/dev/null` if test -z "$PYLIBDIR"; then - # older versions don't have sys.lib so the best we can do is assume lib + # Fedora patch Python to add sys.lib, for other distros we assume "lib". PYLIBDIR="lib" fi AC_MSG_RESULT($PYLIBDIR) From 3abe3517f8bc84147aaf28bf207773fb6d5a8c50 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 21 Mar 2013 19:41:59 +0000 Subject: [PATCH 0486/1160] Don't test shared_ptr for languages that don't have support for shared_ptr --- Examples/test-suite/director_smartptr.i | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/director_smartptr.i b/Examples/test-suite/director_smartptr.i index 0d78c2775..13eb745b6 100644 --- a/Examples/test-suite/director_smartptr.i +++ b/Examples/test-suite/director_smartptr.i @@ -32,6 +32,12 @@ public: %} +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) +#define SHARED_PTR_WRAPPERS_IMPLEMENTED +#endif + +#if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED) + %include %include @@ -60,4 +66,7 @@ public: virtual FooBar makeFooBar(); static Foo* get_self(Foo *self_); -}; \ No newline at end of file +}; + +#endif + From 1e00ce6bf963d501d1e056abcd70ae66be5fed94 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 26 Mar 2013 15:07:16 +1300 Subject: [PATCH 0487/1160] Fix comment typo in typemap --- Examples/test-suite/primitive_types.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/primitive_types.i b/Examples/test-suite/primitive_types.i index f912bd77c..9425cc1a0 100644 --- a/Examples/test-suite/primitive_types.i +++ b/Examples/test-suite/primitive_types.i @@ -48,7 +48,7 @@ const double & ($basetype temp) %{ temp = ($basetype)$input; $1 = &temp; %} - the other tipical change is to add the enum SWIGTYPE to the + the other typical change is to add the enum SWIGTYPE to the integer throws typemaps: %typemap(throws) int, From b504b68a62e003f39d6bab810842d6a2b684a51c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 23 Mar 2013 16:52:30 +0000 Subject: [PATCH 0488/1160] Fix erratically failing threads_exception python test --- Examples/test-suite/python/threads_exception_runme.py | 10 ++++++---- Examples/test-suite/threads_exception.i | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/python/threads_exception_runme.py b/Examples/test-suite/python/threads_exception_runme.py index 12202e3d3..d4b8855fc 100644 --- a/Examples/test-suite/python/threads_exception_runme.py +++ b/Examples/test-suite/python/threads_exception_runme.py @@ -23,10 +23,12 @@ except RuntimeError,e: try: t.hosed() except threads_exception.Exc,e: - if e.code != 42: - raise RuntimeError - if e.msg != "Hosed": - raise RuntimeError, "bad... msg: %s" % e.msg + code = e.code + if code != 42: + raise RuntimeError, "bad... code: %d" % code + msg = e.msg + if msg != "Hosed": + raise RuntimeError, "bad... msg: '%s' len: %d" % (msg, len(msg)) for i in range(1,4): try: diff --git a/Examples/test-suite/threads_exception.i b/Examples/test-suite/threads_exception.i index 9f275bd6a..b374f0ce6 100644 --- a/Examples/test-suite/threads_exception.i +++ b/Examples/test-suite/threads_exception.i @@ -20,6 +20,7 @@ public: Exc(int c, const char *m) { code = c; strncpy(msg,m,255); + msg[255] = 0; } int code; char msg[256]; From 7eda619741a31ed73df512085f7256694173e877 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 25 Mar 2013 19:03:39 +0000 Subject: [PATCH 0489/1160] Fix invalid iterators used with -ve ranges - Python Fixes li_std_containers_int testcase. Valgrind reports no more problems for this testcase. --- Lib/python/pycontainer.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index eb089e98e..81909ae02 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -398,7 +398,7 @@ namespace swig { typename Sequence::reverse_iterator it = sb; size_t delcount = (ii - jj - step - 1) / -step; while (delcount) { - self->erase((++it).base()); + it = typename Sequence::reverse_iterator(self->erase((++it).base())); if (it==self->rend()) break; for (Py_ssize_t c=0; c<(-step-1); ++c) From 38b2b95c30662e81518bd8321bbbbed1ab7dd300 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 25 Mar 2013 19:26:12 +0000 Subject: [PATCH 0490/1160] Fix some invalid iterator usage in Python when deleting/inserting slices from/into containers --- Lib/python/pycontainer.swg | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index 81909ae02..d4386622e 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -339,7 +339,7 @@ namespace swig { std::advance(it,ii); for (size_t rc=0; rcend(); ++c) it++; } } @@ -357,7 +357,7 @@ namespace swig { std::advance(it,size-ii-1); for (size_t rc=0; rcrend(); ++c) it++; } } @@ -383,9 +383,7 @@ namespace swig { size_t delcount = (jj - ii + step - 1) / step; while (delcount) { it = self->erase(it); - if (it==self->end()) - break; - for (Py_ssize_t c=0; c<(step-1); ++c) + for (Py_ssize_t c=0; c<(step-1) && it != self->end(); ++c) it++; delcount--; } @@ -399,9 +397,7 @@ namespace swig { size_t delcount = (ii - jj - step - 1) / -step; while (delcount) { it = typename Sequence::reverse_iterator(self->erase((++it).base())); - if (it==self->rend()) - break; - for (Py_ssize_t c=0; c<(-step-1); ++c) + for (Py_ssize_t c=0; c<(-step-1) && it != self->rend(); ++c) it++; delcount--; } From 2e0d1b12dc4fe5cf12239a59c5d96bdbd352d085 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 29 Mar 2013 06:28:15 +0000 Subject: [PATCH 0491/1160] Fix delete_if (reject!) for the STL container wrappers. Previously they would sometimes seg fault or not work. --- CHANGES.current | 4 +++ Examples/test-suite/ruby/li_std_set_runme.rb | 4 +++ .../test-suite/ruby/li_std_vector_runme.rb | 5 +++ Lib/ruby/rubycontainer.swg | 35 ++++++++----------- Lib/ruby/std_set.i | 19 ++++++++++ 5 files changed, 46 insertions(+), 21 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 6547a88be..bbf97a67f 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.10 (in progress) ============================ +2013-03-29: wsfulton + [Ruby] Fix delete_if (reject!) for the STL container wrappers which previously would + sometimes seg fault or not work. + 2013-03-19: wsfulton [C#, Java, D] Fix seg fault in SWIG using directors when class and virtual method names are the same except being in different namespaces when the %nspace feature is not being used. diff --git a/Examples/test-suite/ruby/li_std_set_runme.rb b/Examples/test-suite/ruby/li_std_set_runme.rb index 65354be58..a85418471 100755 --- a/Examples/test-suite/ruby/li_std_set_runme.rb +++ b/Examples/test-suite/ruby/li_std_set_runme.rb @@ -61,3 +61,7 @@ s.to_a == [1,[1,2],'hello'] # sort order: s.sort {|a,b| a.hash <=> b.hash} EOF +iv = Set_int.new([0,1,2,3,4,5,6]) +iv.delete_if { |x| x == 0 || x == 3 || x == 6 } +swig_assert_equal(iv.to_s, '1245', binding) + diff --git a/Examples/test-suite/ruby/li_std_vector_runme.rb b/Examples/test-suite/ruby/li_std_vector_runme.rb index 8bcad2d19..fe3d9e0ce 100755 --- a/Examples/test-suite/ruby/li_std_vector_runme.rb +++ b/Examples/test-suite/ruby/li_std_vector_runme.rb @@ -64,6 +64,11 @@ y = average([1, 2, 3, 4]) half([10, 10.5, 11, 11.5]) EOF +iv = IntVector.new([0,1,2,3,4,5,6]) +iv.delete_if { |x| x == 0 || x == 3 || x == 6 } +swig_assert_equal(iv.to_s, '1245', binding) + + dv = DoubleVector.new(10) swig_assert( "dv.respond_to? :each_with_index", binding ) diff --git a/Lib/ruby/rubycontainer.swg b/Lib/ruby/rubycontainer.swg index d8d15f690..d4eaa5f73 100644 --- a/Lib/ruby/rubycontainer.swg +++ b/Lib/ruby/rubycontainer.swg @@ -677,27 +677,6 @@ namespace swig return r; } - %alias reject_bang "delete_if"; - Sequence* reject_bang() { - if ( !rb_block_given_p() ) - rb_raise( rb_eArgError, "no block given" ); - - Sequence::iterator i = self->begin(); - Sequence::iterator e = self->end(); - for ( ; i != e; ) - { - VALUE r = swig::from< Sequence::value_type >(*i); - if ( RTEST( rb_yield(r) ) ) { - $self->erase(i++); - e = self->end(); - } else { - ++i; - } - } - - return self; - } - VALUE delete_at(difference_type i) { VALUE r = Qnil; try { @@ -757,6 +736,19 @@ namespace swig } %enddef +%define %swig_sequence_methods_extra(Sequence...) + %extend { + %alias reject_bang "delete_if"; + Sequence* reject_bang() { + if ( !rb_block_given_p() ) + rb_raise( rb_eArgError, "no block given" ); + + $self->erase( std::remove_if( $self->begin(), $self->end(), + swig::yield< Sequence::value_type >() ), $self->end() ); + return $self; + } + } +%enddef /** * Macro used to add functions for Sequences @@ -764,6 +756,7 @@ namespace swig */ %define %swig_sequence_methods(Sequence...) %swig_sequence_methods_common(%arg(Sequence)); + %swig_sequence_methods_extra(%arg(Sequence)); %swig_sequence_back_inserters(%arg(Sequence)); %extend { diff --git a/Lib/ruby/std_set.i b/Lib/ruby/std_set.i index 00596b4a6..e38702ef5 100644 --- a/Lib/ruby/std_set.i +++ b/Lib/ruby/std_set.i @@ -152,10 +152,29 @@ } %} +%define %swig_sequence_methods_extra_set(Sequence...) + %extend { + %alias reject_bang "delete_if"; + Sequence* reject_bang() { + if ( !rb_block_given_p() ) + rb_raise( rb_eArgError, "no block given" ); + + for ( Sequence::iterator i = $self->begin(); i != $self->end(); ) { + VALUE r = swig::from< Sequence::value_type >(*i); + Sequence::iterator current = i++; + if ( RTEST( rb_yield(r) ) ) + $self->erase(current); + } + + return self; + } + } +%enddef %define %swig_set_methods(set...) %swig_sequence_methods_common(%arg(set)); + %swig_sequence_methods_extra_set(%arg(set)); %fragment("RubyPairBoolOutputIterator","header",fragment=SWIG_From_frag(bool),fragment="RubySequence_Cont") {} From 8381cc6b7db33669103bb4aa222884dcfdb6a266 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 27 Mar 2013 11:14:48 +0000 Subject: [PATCH 0492/1160] Fix test suite lock initialisation leading to random seg faults in li_boost_shared_ptr --- Examples/test-suite/swig_examples_lock.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/test-suite/swig_examples_lock.h b/Examples/test-suite/swig_examples_lock.h index feef26d0f..49d1bf285 100644 --- a/Examples/test-suite/swig_examples_lock.h +++ b/Examples/test-suite/swig_examples_lock.h @@ -43,6 +43,7 @@ class CriticalSection { public: CriticalSection() { pthread_mutexattr_t mutexattr; + pthread_mutexattr_init(&mutexattr); pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE_NP); pthread_mutex_init(&mutex_, &mutexattr); pthread_mutexattr_destroy(&mutexattr); From 5878ca5f1a93a26231c5f931047ac785c0c32052 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 29 Mar 2013 09:15:39 +0000 Subject: [PATCH 0493/1160] Fix autodoc test for python 2.4 --- Examples/test-suite/python/autodoc_runme.py | 35 ++++++++++--------- Examples/test-suite/python/file_test_runme.py | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Examples/test-suite/python/autodoc_runme.py b/Examples/test-suite/python/autodoc_runme.py index dc843ae96..634b2dccf 100644 --- a/Examples/test-suite/python/autodoc_runme.py +++ b/Examples/test-suite/python/autodoc_runme.py @@ -1,4 +1,5 @@ from autodoc import * +import sys def check(got, expected): if expected != got: @@ -121,22 +122,24 @@ check(A.func3static.__doc__, "\n" " " ) -check(A.variable_a.__doc__, "A_variable_a_get(self) -> int") -check(A.variable_b.__doc__, "A_variable_b_get(A self) -> int") -check(A.variable_c.__doc__, "\n" -"A_variable_c_get(self) -> int\n" -"\n" -"Parameters:\n" -" self: A *\n" -"\n" -) -check(A.variable_d.__doc__, "\n" -"A_variable_d_get(A self) -> int\n" -"\n" -"Parameters:\n" -" self: A *\n" -"\n" -) +if sys.version[0:2] > (2, 4): + # Python 2.4 does not seem to work + check(A.variable_a.__doc__, "A_variable_a_get(self) -> int") + check(A.variable_b.__doc__, "A_variable_b_get(A self) -> int") + check(A.variable_c.__doc__, "\n" + "A_variable_c_get(self) -> int\n" + "\n" + "Parameters:\n" + " self: A *\n" + "\n" + ) + check(A.variable_d.__doc__, "\n" + "A_variable_d_get(A self) -> int\n" + "\n" + "Parameters:\n" + " self: A *\n" + "\n" + ) check(B.__doc__, "Proxy of C++ B class") check(C.__init__.__doc__, "__init__(self, a, b, h) -> C") diff --git a/Examples/test-suite/python/file_test_runme.py b/Examples/test-suite/python/file_test_runme.py index de4e2669e..3d8b153db 100644 --- a/Examples/test-suite/python/file_test_runme.py +++ b/Examples/test-suite/python/file_test_runme.py @@ -1,7 +1,7 @@ import sys import file_test -if sys.version_info < (3,0): +if sys.version[0:2] > (3, 0): file_test.nfile(sys.stdout) cstdout = file_test.GetStdOut() From f42ac989a7c608d9bc68c409a5b0db018bfef135 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 29 Mar 2013 09:19:03 +0000 Subject: [PATCH 0494/1160] Add note about Python STL fixes --- CHANGES.current | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index bbf97a67f..db7a0612f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -9,6 +9,9 @@ Version 2.0.10 (in progress) [Ruby] Fix delete_if (reject!) for the STL container wrappers which previously would sometimes seg fault or not work. +2013-03-25: wsfulton + [Python] Fix some undefined behaviour deleting slices in the STL containers. + 2013-03-19: wsfulton [C#, Java, D] Fix seg fault in SWIG using directors when class and virtual method names are the same except being in different namespaces when the %nspace feature is not being used. From af859a1e2da4a317b7ad3a706825f6c6a6ae1c97 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 29 Mar 2013 13:46:49 +0000 Subject: [PATCH 0495/1160] Fix Ruby documentation for %bang --- Doc/Manual/Ruby.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index 47cf4f303..9739e1109 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -3215,7 +3215,7 @@ directive which is unique to the Ruby module and was introduced in SWIG
    -
    %bang sort!(arr);

    int sort(int arr[]);
    +
    %bang sort(int arr[]);

    int sort(int arr[]);
    From 8801ea3f11fd02a953584eae024d1e5385a5a530 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 31 Mar 2013 00:21:12 +0000 Subject: [PATCH 0496/1160] Fix incorrect assumptions in Ruby li_std_set test --- Examples/test-suite/ruby/li_std_set_runme.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/ruby/li_std_set_runme.rb b/Examples/test-suite/ruby/li_std_set_runme.rb index a85418471..efc163bee 100755 --- a/Examples/test-suite/ruby/li_std_set_runme.rb +++ b/Examples/test-suite/ruby/li_std_set_runme.rb @@ -57,7 +57,10 @@ s = LanguageSet.new s.insert([1,2]) s.insert(1) s.insert("hello") -s.to_a == [1,[1,2],'hello'] # sort order: s.sort {|a,b| a.hash <=> b.hash} +#s.to_a == [1,[1,2],'hello'] # sort order: s.sort {|a,b| a.hash <=> b.hash} +# Test above is flawed as LanguageSet sorts by each element's hash, so the order will change from one invocation to the next. Sort a conversion to array instead. +sa = s.to_a.sort { |x, y| x.to_s <=> y.to_s } +sa == [1,[1,2],'hello'] EOF From e13e1cba9e6dd024f713821558ae084cc9dc3507 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 31 Mar 2013 00:55:34 +0000 Subject: [PATCH 0497/1160] Fix seg fault when using STL containers of generic Ruby types, GC_VALUE or LANGUAGE_OBJECT, on exit of the Ruby interpreter. Observed on 64 bit Linux in the std_li_set testcase. The global hash which is meant to hold GC references was being deleted by the interpreter on exit before the GC_VALUES destructors were being called. --- CHANGES.current | 4 ++ Lib/ruby/rubyclasses.swg | 115 +++++++++++++++++++++------------------ 2 files changed, 67 insertions(+), 52 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index db7a0612f..6e3d6fb08 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.10 (in progress) ============================ +2013-03-30: wsfulton + [Ruby] Fix seg fault when using STL containers of generic Ruby types, GC_VALUE or LANGUAGE_OBJECT, + on exit of the Ruby interpreter. More frequently observed in ruby-1.9. + 2013-03-29: wsfulton [Ruby] Fix delete_if (reject!) for the STL container wrappers which previously would sometimes seg fault or not work. diff --git a/Lib/ruby/rubyclasses.swg b/Lib/ruby/rubyclasses.swg index 2048b1f5f..60411a2de 100644 --- a/Lib/ruby/rubyclasses.swg +++ b/Lib/ruby/rubyclasses.swg @@ -36,11 +36,64 @@ %fragment("GC_VALUE_definition","header") { namespace swig { + class SwigGCReferences { + // Hash of all GC_VALUE's currently in use + static SwigGCReferences s_references; + + VALUE _hash; + + SwigGCReferences() : _hash(Qnil) { + } + ~SwigGCReferences() { + if (_hash != Qnil) + rb_gc_unregister_address( &_hash ); + } + static void EndProcHandler(VALUE) { + // Ruby interpreter ending - _hash can no longer be accessed. + s_references._hash = Qnil; + } + public: + static SwigGCReferences& instance() { + return s_references; + } + static void initialize() { + if (s_references._hash == Qnil) { + rb_set_end_proc(&EndProcHandler, Qnil); + s_references._hash = rb_hash_new(); + rb_gc_register_address( &s_references._hash ); + } + } + void GC_register(VALUE& obj) { + if (FIXNUM_P(obj) || SPECIAL_CONST_P(obj) || SYMBOL_P(obj)) + return; + if (_hash != Qnil) { + VALUE val = rb_hash_aref(_hash, obj); + unsigned n = FIXNUM_P(val) ? NUM2UINT(val) : 0; + ++n; + rb_hash_aset(_hash, obj, INT2NUM(n)); + } + } + void GC_unregister(const VALUE& obj) { + if (FIXNUM_P(obj) || SPECIAL_CONST_P(obj) || SYMBOL_P(obj)) + return; + // this test should not be needed but I've noticed some very erratic + // behavior of none being unregistered in some very rare situations. + if (BUILTIN_TYPE(obj) == T_NONE) + return; + if (_hash != Qnil) { + VALUE val = rb_hash_aref(s_references._hash, obj); + unsigned n = FIXNUM_P(val) ? NUM2UINT(val) : 1; + --n; + if (n) + rb_hash_aset(s_references._hash, obj, INT2NUM(n)); + else + rb_hash_delete(s_references._hash, obj); + } + } + }; + class GC_VALUE { protected: - // Hash of all GC_VALUE's currently in use - static VALUE _hash; - VALUE _obj; static ID hash_id; @@ -77,75 +130,33 @@ namespace swig { public: - static void initialize() - { - if ( _hash == Qnil ) - { - _hash = rb_hash_new(); - rb_gc_register_address( &_hash ); - } - } - - // this function is never called. Provided for symmetry only. - static void cleanup() - { - rb_gc_unregister_address( &_hash ); - } - GC_VALUE() : _obj( Qnil ) { } GC_VALUE(const GC_VALUE& item) : _obj(item._obj) { - GC_register(); + SwigGCReferences::instance().GC_register(_obj); } GC_VALUE(VALUE obj) :_obj(obj) { - GC_register(); + SwigGCReferences::instance().GC_register(_obj); } ~GC_VALUE() { - GC_unregister(); + SwigGCReferences::instance().GC_unregister(_obj); } GC_VALUE & operator=(const GC_VALUE& item) { - GC_unregister(); + SwigGCReferences::instance().GC_unregister(_obj); _obj = item._obj; - GC_register(); + SwigGCReferences::instance().GC_register(_obj); return *this; } - void GC_register() - { - if ( FIXNUM_P(_obj) || SPECIAL_CONST_P(_obj) || SYMBOL_P(_obj) ) - return; - VALUE val = rb_hash_aref( _hash, _obj ); - unsigned n = FIXNUM_P(val) ? NUM2UINT(val) : 0; - ++n; - rb_hash_aset( _hash, _obj, INT2NUM(n) ); - } - - void GC_unregister() - { - if ( FIXNUM_P(_obj) || SPECIAL_CONST_P(_obj) || SYMBOL_P(_obj) ) - return; - // this test should not be needed but I've noticed some very erratic - // behavior of none being unregistered in some very rare situations. - if ( BUILTIN_TYPE(_obj) == T_NONE ) return; - - VALUE val = rb_hash_aref( _hash, _obj ); - unsigned n = FIXNUM_P(val) ? NUM2UINT(val) : 1; - --n; - if ( n ) - rb_hash_aset( _hash, _obj, INT2NUM(n) ); - else - rb_hash_delete( _hash, _obj ); - } - operator VALUE() const { return _obj; @@ -294,7 +305,7 @@ namespace swig { ID GC_VALUE::lshift_id = rb_intern("<<"); ID GC_VALUE::rshift_id = rb_intern(">>"); - VALUE GC_VALUE::_hash = Qnil; + SwigGCReferences SwigGCReferences::s_references; typedef GC_VALUE LANGUAGE_OBJ; @@ -350,7 +361,7 @@ namespace swig { %init { - swig::GC_VALUE::initialize(); + swig::SwigGCReferences::initialize(); } From 9aaf4ad03cc31eb976d8bd16301286f0ac83ff4c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 2 Apr 2013 20:14:51 +0100 Subject: [PATCH 0498/1160] Fixes for Ruby 1.9 std::complex wrappers. New native Ruby complex numbers are used. --- CHANGES.current | 3 ++ Lib/ruby/rubycomplex.swg | 92 +++++++++++++++++++++++----------------- 2 files changed, 56 insertions(+), 39 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 6e3d6fb08..ac26525da 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-04-02: wsfulton + [Ruby] Runtime fixes for std::complex wrappers for ruby-1.9 - new native Ruby complex numbers are used. + 2013-03-30: wsfulton [Ruby] Fix seg fault when using STL containers of generic Ruby types, GC_VALUE or LANGUAGE_OBJECT, on exit of the Ruby interpreter. More frequently observed in ruby-1.9. diff --git a/Lib/ruby/rubycomplex.swg b/Lib/ruby/rubycomplex.swg index afdb15e7e..8a7486865 100644 --- a/Lib/ruby/rubycomplex.swg +++ b/Lib/ruby/rubycomplex.swg @@ -1,49 +1,61 @@ /* Defines the As/From conversors for double/float complex, you need to - provide complex Type, the Name you want to use in the conversors, + provide complex Type, the Name you want to use in the converters, the complex Constructor method, and the Real and Imag complex - accesor methods. + accessor methods. See the std_complex.i and ccomplex.i for concrete examples. */ -/* - Ruby does not have native complex numbers. They are an extension in the - STD library. -*/ -%{ - static VALUE swig_rb_cComplex = Qnil; - static ID swig_real_id = 0; - static ID swig_imag_id = 0; - - int Ruby_Is_Complex( VALUE obj ) - { - return ( (rb_respond_to( obj, swig_real_id ) == Qtrue) && - (rb_respond_to( obj, swig_imag_id ) == Qtrue) ); - } -%} - -%init { - rb_require("complex"); - swig_rb_cComplex = rb_const_get( rb_cObject, rb_intern("Complex") ); - if( swig_rb_cComplex == Qnil ) - rb_warn("Ruby's complex.so not found"); - swig_real_id = rb_intern("real"); - swig_imag_id = rb_intern("imag"); +%fragment("SWIG_Complex_Numbers","header") +{ +%#if !defined(T_COMPLEX) +/* Ruby versions prior to 1.9 did not have native complex numbers. They were an extension in the STD library. */ +VALUE rb_complex_new(VALUE x, VALUE y) { + static ID new_id = rb_intern("new"); + static VALUE cComplex = rb_const_get(rb_cObject, rb_intern("Complex")); + return rb_funcall(cComplex, new_id, 2, x, y); } -/* the common from conversor */ +static int SWIG_Is_Complex( VALUE obj ) { + static ID real_id = rb_intern("real"); + static ID imag_id = rb_intern("imag"); + return ( (rb_respond_to( obj, real_id ) == Qtrue) && + (rb_respond_to( obj, imag_id ) == Qtrue) ); +} +%#else +static int SWIG_Is_Complex( VALUE obj ) { + return TYPE(obj) == T_COMPLEX; +} +%#endif + +VALUE SWIG_Complex_Real(VALUE obj) { + static ID real_id = rb_intern("real"); + return rb_funcall(obj, real_id, 0); +} + +VALUE SWIG_Complex_Imaginary(VALUE obj) { + static ID imag_id = rb_intern("imag"); + return rb_funcall(obj, imag_id, 0); +} +} + +%init { +%#if !defined(T_COMPLEX) + rb_require("complex"); +%#endif +} + +/* the common from converter */ %define %swig_fromcplx_conv(Type, Real, Imag) %fragment(SWIG_From_frag(Type),"header") { SWIGINTERNINLINE VALUE SWIG_From(Type)(%ifcplusplus(const Type&, Type) c) { - VALUE args[] = { - rb_float_new(Real(c)), - rb_float_new(Imag(c)) - }; - return rb_class_new_instance(2, args, swig_rb_cComplex); + VALUE re = rb_float_new(Real(c)); + VALUE im = rb_float_new(Imag(c)); + return rb_complex_new(re, im); } } %enddef @@ -51,15 +63,16 @@ SWIG_From(Type)(%ifcplusplus(const Type&, Type) c) /* the double case */ %define %swig_cplxdbl_conv(Type, Constructor, Real, Imag) %fragment(SWIG_AsVal_frag(Type),"header", - fragment=SWIG_AsVal_frag(double)) + fragment=SWIG_AsVal_frag(double), + fragment="SWIG_Complex_Numbers") { SWIGINTERN int SWIG_AsVal(Type) (VALUE o, Type* val) { - if ( Ruby_Is_Complex( o ) ) { + if ( SWIG_Is_Complex( o ) ) { if (val) { - VALUE real = rb_funcall(o, swig_real_id, 0 ); - VALUE imag = rb_funcall(o, swig_imag_id, 0 ); + VALUE real = SWIG_Complex_Real(o); + VALUE imag = SWIG_Complex_Imaginary(o); double re = 0; SWIG_AsVal_double( real, &re ); double im = 0; @@ -85,13 +98,14 @@ SWIG_AsVal(Type) (VALUE o, Type* val) %define %swig_cplxflt_conv(Type, Constructor, Real, Imag) %fragment(SWIG_AsVal_frag(Type),"header", fragment=SWIG_AsVal_frag(float), - fragment=SWIG_AsVal_frag(double)) { + fragment=SWIG_AsVal_frag(double), + fragment="SWIG_Complex_Numbers") { SWIGINTERN int SWIG_AsVal(Type)(VALUE o, Type *val) { - if ( Ruby_Is_Complex( o ) ) { - VALUE real = rb_funcall(o, swig_real_id, 0 ); - VALUE imag = rb_funcall(o, swig_imag_id, 0 ); + if ( SWIG_Is_Complex( o ) ) { + VALUE real = SWIG_Complex_Real(o); + VALUE imag = SWIG_Complex_Imaginary(o); double re = 0; SWIG_AsVal_double( real, &re ); double im = 0; From ee92a26819b8bb811d4fe00b80a02bdc4aa4cf70 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 2 Apr 2013 22:21:48 +0100 Subject: [PATCH 0499/1160] Fixes for out of source builds for Ruby test-suite --- Examples/test-suite/ruby/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/ruby/Makefile.in b/Examples/test-suite/ruby/Makefile.in index 3354acfd8..ab366ccd4 100644 --- a/Examples/test-suite/ruby/Makefile.in +++ b/Examples/test-suite/ruby/Makefile.in @@ -61,7 +61,7 @@ ruby_naming.cpptest: SWIGOPT += -autorename # a file is found which has _runme.rb appended after the testcase name. run_testcase = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(RUBY) -I. $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(RUBY) -I$(srcdir):. $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \ fi # Clean From 5d529d5a76a9d3f71e39dad2f8373559bdebd829 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 5 Apr 2013 23:41:59 +0100 Subject: [PATCH 0500/1160] Ruby 1.9 fixes. SF Bug#1292 - Runtime fixes for Proc changes in ruby-1.9 when using STL wrappers that override the default predicate, such as: %template(Map) std::map >; Fixes li_std_functors testcases for Ruby 1.9. Also rb_respond_to return values have changed subtely in 1.9 and return should be treated as a flag instead of checking for Qtrue, see SF Bug #1159. Also fix li_std_map, li_std_set silently failing - rb_protect behaviour seems to have changed when an exception is thrown, so code has been changed to use rb_rescue. A call to 'rb_set_errinfo(Qnil)' could have solved this after the rb_protect call, but it is only available in 1.9+ and Ruby API changes are not easily and transparently detectable. --- CHANGES.current | 10 ++++++++++ .../test-suite/ruby/li_std_functors_runme.rb | 8 +++++++- Lib/ruby/rubyclasses.swg | 17 +++++++++++++---- Lib/ruby/rubycomplex.swg | 4 ++-- Lib/ruby/rubyrun.swg | 4 ++-- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index ac26525da..9253f9c96 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,16 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-04-05: wsfulton + [Ruby] SF Bug #1292 - Runtime fixes for Proc changes in ruby-1.9 when using STL + wrappers that override the default predicate, such as: + + %template(Map) std::map >; + +2013-04-05: wsfulton + [Ruby] SF Bug #1159 - Correctly check rb_respond_to call return values to fix some + further 1.9 problems with functors and use of Complex wrappers. + 2013-04-02: wsfulton [Ruby] Runtime fixes for std::complex wrappers for ruby-1.9 - new native Ruby complex numbers are used. diff --git a/Examples/test-suite/ruby/li_std_functors_runme.rb b/Examples/test-suite/ruby/li_std_functors_runme.rb index d31735c45..5623d49f0 100755 --- a/Examples/test-suite/ruby/li_std_functors_runme.rb +++ b/Examples/test-suite/ruby/li_std_functors_runme.rb @@ -34,6 +34,12 @@ def _set(container) EOF end +def b_lessthan_a(b, a) + res = b < a +# print b, "<", a, "=", res + return res +end + def _map(container) swig_assert_each_line(< Date: Sat, 6 Apr 2013 00:30:50 +0100 Subject: [PATCH 0501/1160] More rb_protect rewrite to use rb_rescue for Ruby 1.9 --- Lib/ruby/rubyclasses.swg | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/Lib/ruby/rubyclasses.swg b/Lib/ruby/rubyclasses.swg index 5db6658ee..3b36c722e 100644 --- a/Lib/ruby/rubyclasses.swg +++ b/Lib/ruby/rubyclasses.swg @@ -172,17 +172,14 @@ namespace swig { return rb_inspect(_obj); } - static VALUE swig_rescue_funcall( VALUE ) + static VALUE swig_rescue_swallow( VALUE ) { -/* - VALUE err = rb_errinfo(); - VALUE errstr = rb_obj_as_string(err); - std::cout << "Error is: '" << RSTRING_PTR(StringValue(errstr)) << "'" << std::endl; -*/ - return Qnil;/* Swallow Ruby exception */ + // VALUE errstr = rb_obj_as_string(rb_errinfo()); + // printf("Swallowing error: '%s'\n", RSTRING_PTR(StringValue(errstr))); + return Qnil; /* Swallow Ruby exception */ } - static VALUE swig_protect_funcall( VALUE p ) + static VALUE swig_rescue_funcall( VALUE p ) { OpArgs* args = (OpArgs*) p; return rb_funcall( args->src, args->id, args->nargs, args->target ); @@ -206,8 +203,8 @@ namespace swig { args.id = op_id; \ args.nargs = 1; \ args.target = VALUE(other); \ - ret = rb_rescue(RUBY_METHOD_FUNC(swig_protect_funcall), VALUE(&args), \ - (RUBY_METHOD_FUNC(swig_rescue_funcall)), Qnil); \ + ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args), \ + (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil); \ } \ if ( ret == Qnil ) { \ VALUE a = rb_funcall( _obj, hash_id, 0 ); \ @@ -240,14 +237,13 @@ namespace swig { { \ VALUE ret = Qnil; \ SWIG_RUBY_THREAD_BEGIN_BLOCK; \ - int status; \ OpArgs args; \ args.src = _obj; \ args.id = proc_id; \ args.nargs = 0; \ args.target = Qnil; \ - ret = rb_protect( PROTECTFUNC(swig_protect_funcall), VALUE(&args), \ - &status ); \ + ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args), \ + (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil); \ SWIG_RUBY_THREAD_END_BLOCK; \ return ret; \ } @@ -262,14 +258,13 @@ namespace swig { { \ VALUE ret = Qnil; \ SWIG_RUBY_THREAD_BEGIN_BLOCK; \ - int status; \ OpArgs args; \ args.src = _obj; \ args.id = proc_id; \ args.nargs = 1; \ args.target = VALUE(other); \ - ret = rb_protect( PROTECTFUNC(swig_protect_funcall), VALUE(&args), \ - &status ); \ + ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args), \ + (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil); \ SWIG_RUBY_THREAD_END_BLOCK; \ return GC_VALUE(ret); \ } From bb3fe8c906997d39570ab1c7bbde78a5236b229f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 6 Apr 2013 02:20:56 +0100 Subject: [PATCH 0502/1160] Rewrite Ruby's GC_VALUE without use of macros for easier debugging --- Lib/ruby/rubyclasses.swg | 183 +++++++++++++++++++-------------------- 1 file changed, 87 insertions(+), 96 deletions(-) diff --git a/Lib/ruby/rubyclasses.swg b/Lib/ruby/rubyclasses.swg index 3b36c722e..598bc4db9 100644 --- a/Lib/ruby/rubyclasses.swg +++ b/Lib/ruby/rubyclasses.swg @@ -46,7 +46,7 @@ namespace swig { } ~SwigGCReferences() { if (_hash != Qnil) - rb_gc_unregister_address( &_hash ); + rb_gc_unregister_address(&_hash); } static void EndProcHandler(VALUE) { // Ruby interpreter ending - _hash can no longer be accessed. @@ -60,12 +60,12 @@ namespace swig { if (s_references._hash == Qnil) { rb_set_end_proc(&EndProcHandler, Qnil); s_references._hash = rb_hash_new(); - rb_gc_register_address( &s_references._hash ); + rb_gc_register_address(&s_references._hash); } } void GC_register(VALUE& obj) { if (FIXNUM_P(obj) || SPECIAL_CONST_P(obj) || SYMBOL_P(obj)) - return; + return; if (_hash != Qnil) { VALUE val = rb_hash_aref(_hash, obj); unsigned n = FIXNUM_P(val) ? NUM2UINT(val) : 0; @@ -75,7 +75,7 @@ namespace swig { } void GC_unregister(const VALUE& obj) { if (FIXNUM_P(obj) || SPECIAL_CONST_P(obj) || SYMBOL_P(obj)) - return; + return; // this test should not be needed but I've noticed some very erratic // behavior of none being unregistered in some very rare situations. if (BUILTIN_TYPE(obj) == T_NONE) @@ -85,9 +85,9 @@ namespace swig { unsigned n = FIXNUM_P(val) ? NUM2UINT(val) : 1; --n; if (n) - rb_hash_aset(s_references._hash, obj, INT2NUM(n)); + rb_hash_aset(s_references._hash, obj, INT2NUM(n)); else - rb_hash_delete(s_references._hash, obj); + rb_hash_delete(s_references._hash, obj); } } }; @@ -130,7 +130,7 @@ namespace swig { public: - GC_VALUE() : _obj( Qnil ) + GC_VALUE() : _obj(Qnil) { } @@ -172,117 +172,108 @@ namespace swig { return rb_inspect(_obj); } - static VALUE swig_rescue_swallow( VALUE ) + static VALUE swig_rescue_swallow(VALUE) { // VALUE errstr = rb_obj_as_string(rb_errinfo()); // printf("Swallowing error: '%s'\n", RSTRING_PTR(StringValue(errstr))); return Qnil; /* Swallow Ruby exception */ } - static VALUE swig_rescue_funcall( VALUE p ) + static VALUE swig_rescue_funcall(VALUE p) { OpArgs* args = (OpArgs*) p; - return rb_funcall( args->src, args->id, args->nargs, args->target ); + return rb_funcall(args->src, args->id, args->nargs, args->target); } - -%#define GC_VALUE_CMP( op_id, op, cmp, cmpval ) \ - bool op( const GC_VALUE& other ) const \ - { \ - if ( FIXNUM_P(_obj) && FIXNUM_P(other._obj) ) \ - { \ - return _obj cmp other._obj; \ - } \ - bool res = false; \ - VALUE ret = Qnil; \ - SWIG_RUBY_THREAD_BEGIN_BLOCK; \ - if ( rb_respond_to( _obj, op_id ) ) \ - { \ - OpArgs args; \ - args.src = _obj; \ - args.id = op_id; \ - args.nargs = 1; \ - args.target = VALUE(other); \ - ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args), \ - (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil); \ - } \ - if ( ret == Qnil ) { \ - VALUE a = rb_funcall( _obj, hash_id, 0 ); \ - VALUE b = rb_funcall( VALUE(other), hash_id, 0 ); \ - res = a cmp b; \ - } \ - else \ - { \ - res = RTEST( ret ); \ - } \ - SWIG_RUBY_THREAD_END_BLOCK; \ - return res; \ + bool relational_equal_op(const GC_VALUE& other, const ID& op_id, bool (*op_func)(const VALUE& a, const VALUE& b)) const + { + if (FIXNUM_P(_obj) && FIXNUM_P(other._obj)) { + return op_func(_obj, other._obj); + } + bool res = false; + VALUE ret = Qnil; + SWIG_RUBY_THREAD_BEGIN_BLOCK; + if (rb_respond_to(_obj, op_id)) { + OpArgs args; + args.src = _obj; + args.id = op_id; + args.nargs = 1; + args.target = VALUE(other); + ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args), + (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil); + } + if (ret == Qnil) { + VALUE a = rb_funcall( _obj, hash_id, 0 ); + VALUE b = rb_funcall( VALUE(other), hash_id, 0 ); + res = op_func(a, b); + } else { + res = RTEST(ret); + } + SWIG_RUBY_THREAD_END_BLOCK; + return res; } + static bool operator_eq(const VALUE& a, const VALUE& b) { return a == b; } + static bool operator_lt(const VALUE& a, const VALUE& b) { return a < b; } + static bool operator_le(const VALUE& a, const VALUE& b) { return a <= b; } + static bool operator_gt(const VALUE& a, const VALUE& b) { return a > b; } + static bool operator_ge(const VALUE& a, const VALUE& b) { return a >= b; } - GC_VALUE_CMP( eq_id, operator==, ==, == 0 ) - GC_VALUE_CMP( lt_id, operator<, < , < 0 ) - GC_VALUE_CMP( le_id, operator<=, <=, <= 0 ) - GC_VALUE_CMP( gt_id, operator>, > , > 0 ) - GC_VALUE_CMP( ge_id, operator>=, >=, >= 0 ) -%#undef GC_VALUE_CMP + bool operator==(const GC_VALUE& other) const { return relational_equal_op(other, eq_id, operator_eq); } + bool operator<(const GC_VALUE& other) const { return relational_equal_op(other, lt_id, operator_lt); } + bool operator<=(const GC_VALUE& other) const { return relational_equal_op(other, le_id, operator_le); } + bool operator>(const GC_VALUE& other) const { return relational_equal_op(other, gt_id, operator_gt); } + bool operator>=(const GC_VALUE& other) const { return relational_equal_op(other, ge_id, operator_ge); } - bool operator!=( const GC_VALUE& other ) + bool operator!=(const GC_VALUE& other) const { return !(this->operator==(other)); } -%#define GC_VALUE_UNARY( proc_id, op ) \ - GC_VALUE op() const \ - { \ - VALUE ret = Qnil; \ - SWIG_RUBY_THREAD_BEGIN_BLOCK; \ - OpArgs args; \ - args.src = _obj; \ - args.id = proc_id; \ - args.nargs = 0; \ - args.target = Qnil; \ - ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args), \ - (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil); \ - SWIG_RUBY_THREAD_END_BLOCK; \ - return ret; \ + GC_VALUE unary_op(const ID& op_id) const + { + VALUE ret = Qnil; + SWIG_RUBY_THREAD_BEGIN_BLOCK; + OpArgs args; + args.src = _obj; + args.id = op_id; + args.nargs = 0; + args.target = Qnil; + ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args), + (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil); + SWIG_RUBY_THREAD_END_BLOCK; + return ret; } - GC_VALUE_UNARY( pos_id, operator+ ) - GC_VALUE_UNARY( neg_id, operator- ) - GC_VALUE_UNARY( inv_id, operator~ ) -%#undef GC_VALUE_BINARY + GC_VALUE operator+() const { return unary_op(pos_id); } + GC_VALUE operator-() const { return unary_op(neg_id); } + GC_VALUE operator~() const { return unary_op(inv_id); } -%#define GC_VALUE_BINARY( proc_id, op ) \ - GC_VALUE op( const GC_VALUE& other ) const \ - { \ - VALUE ret = Qnil; \ - SWIG_RUBY_THREAD_BEGIN_BLOCK; \ - OpArgs args; \ - args.src = _obj; \ - args.id = proc_id; \ - args.nargs = 1; \ - args.target = VALUE(other); \ - ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args), \ - (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil); \ - SWIG_RUBY_THREAD_END_BLOCK; \ - return GC_VALUE(ret); \ + GC_VALUE binary_op(const GC_VALUE& other, const ID& op_id) const + { + VALUE ret = Qnil; + SWIG_RUBY_THREAD_BEGIN_BLOCK; + OpArgs args; + args.src = _obj; + args.id = op_id; + args.nargs = 1; + args.target = VALUE(other); + ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args), + (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil); + SWIG_RUBY_THREAD_END_BLOCK; + return GC_VALUE(ret); } - GC_VALUE_BINARY( add_id, operator+ ); - GC_VALUE_BINARY( sub_id, operator- ); - GC_VALUE_BINARY( mul_id, operator* ); - GC_VALUE_BINARY( div_id, operator/ ); - GC_VALUE_BINARY( mod_id, operator% ); - - GC_VALUE_BINARY( and_id, operator& ); - GC_VALUE_BINARY( xor_id, operator^ ); - GC_VALUE_BINARY( or_id, operator| ); - - GC_VALUE_BINARY( lshift_id, operator<< ); - GC_VALUE_BINARY( rshift_id, operator>> ); -%#undef GC_VALUE_BINARY - + GC_VALUE operator+(const GC_VALUE& other) const { return binary_op(other, add_id); } + GC_VALUE operator-(const GC_VALUE& other) const { return binary_op(other, sub_id); } + GC_VALUE operator*(const GC_VALUE& other) const { return binary_op(other, mul_id); } + GC_VALUE operator/(const GC_VALUE& other) const { return binary_op(other, div_id); } + GC_VALUE operator%(const GC_VALUE& other) const { return binary_op(other, mod_id); } + GC_VALUE operator&(const GC_VALUE& other) const { return binary_op(other, and_id); } + GC_VALUE operator^(const GC_VALUE& other) const { return binary_op(other, xor_id); } + GC_VALUE operator|(const GC_VALUE& other) const { return binary_op(other, or_id); } + GC_VALUE operator<<(const GC_VALUE& other) const { return binary_op(other, lshift_id); } + GC_VALUE operator>>(const GC_VALUE& other) const { return binary_op(other, rshift_id); } }; ID GC_VALUE::hash_id = rb_intern("hash"); @@ -352,7 +343,7 @@ namespace swig { VALUE to_s() const; GC_VALUE(); protected: - GC_VALUE( const GC_VALUE& ); + GC_VALUE(const GC_VALUE&); ~GC_VALUE(); }; From 65b917dabb5d0037318da93b78ce028dbb113f07 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 6 Apr 2013 16:19:17 -0700 Subject: [PATCH 0503/1160] Some test-suite warning fixes --- Examples/test-suite/li_std_except_as_class.i | 6 ++++++ Examples/test-suite/typemap_array_qualifiers.i | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/Examples/test-suite/li_std_except_as_class.i b/Examples/test-suite/li_std_except_as_class.i index 00de76eac..0400c9a82 100644 --- a/Examples/test-suite/li_std_except_as_class.i +++ b/Examples/test-suite/li_std_except_as_class.i @@ -5,6 +5,12 @@ * if there were also functions throwing 'std::logic_error' and * 'std::exception' then the bug would not be fully replicated */ +%{ +#if defined(_MSC_VER) + #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) +#endif +%} + %{ #include #include diff --git a/Examples/test-suite/typemap_array_qualifiers.i b/Examples/test-suite/typemap_array_qualifiers.i index 947721402..14df649d3 100644 --- a/Examples/test-suite/typemap_array_qualifiers.i +++ b/Examples/test-suite/typemap_array_qualifiers.i @@ -39,6 +39,7 @@ CLEAR_SWIGTYPE_TYPEMAPS; %typemap(in) SWIGTYPE [ANY] { +$1 = 0; /* Correct typemap for $symname: $type */ } %inline %{ @@ -48,9 +49,11 @@ CLEAR_SWIGTYPE_TYPEMAPS; CLEAR_SWIGTYPE_TYPEMAPS; %typemap(in) const SWIGTYPE [ANY] { +$1 = 0; /* Correct typemap for $symname: $type */ } %typemap(in) const volatile SWIGTYPE [ANY] { +$1 = 0; /* Correct typemap for $symname: $type */ } %inline %{ @@ -61,9 +64,11 @@ CLEAR_SWIGTYPE_TYPEMAPS; CLEAR_SWIGTYPE_TYPEMAPS; %typemap(in) volatile SWIGTYPE **const [ANY] { +$1 = 0; /* Correct typemap for $symname: $type */ } %typemap(in) volatile SWIGTYPE **const [ANY][ANY] { +$1 = 0; /* Correct typemap for $symname: $type */ } %inline %{ @@ -72,6 +77,7 @@ CLEAR_SWIGTYPE_TYPEMAPS; CLEAR_SWIGTYPE_TYPEMAPS; %typemap(in) SWIGTYPE (*const) (ANY) { +$1 = 0; /* Correct typemap for $symname: $type */ } %inline %{ From 5ae6ff404d8a7d4c17a260a6f2cae7c8959152f7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 8 Apr 2013 07:57:45 +0100 Subject: [PATCH 0504/1160] Cosmetic - use C comments instead of C++ comments for recent Ruby change --- Lib/ruby/rubyclasses.swg | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/ruby/rubyclasses.swg b/Lib/ruby/rubyclasses.swg index 598bc4db9..5537136af 100644 --- a/Lib/ruby/rubyclasses.swg +++ b/Lib/ruby/rubyclasses.swg @@ -174,8 +174,10 @@ namespace swig { static VALUE swig_rescue_swallow(VALUE) { - // VALUE errstr = rb_obj_as_string(rb_errinfo()); - // printf("Swallowing error: '%s'\n", RSTRING_PTR(StringValue(errstr))); + /* + VALUE errstr = rb_obj_as_string(rb_errinfo()); + printf("Swallowing error: '%s'\n", RSTRING_PTR(StringValue(errstr))); + */ return Qnil; /* Swallow Ruby exception */ } From dd2cd0298c39d9546f68ff538f5c90634e5a0106 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 8 Apr 2013 18:30:16 +0100 Subject: [PATCH 0505/1160] Work around Octave seg fault on exit in imports testcase on Octave 3.1 and 3.2 --- Examples/test-suite/octave/imports_runme.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/octave/imports_runme.m b/Examples/test-suite/octave/imports_runme.m index be9db5919..5db38071b 100644 --- a/Examples/test-suite/octave/imports_runme.m +++ b/Examples/test-suite/octave/imports_runme.m @@ -1,7 +1,8 @@ # This is the import runtime testcase. -imports_b; +# If imports_b is loaded before imports_a, a seg fault occurred during interpreter cleanup/exit in version 3.1 and 3.2, seems okay in 3.6 imports_a; +imports_b; x = imports_b.B(); x.hello(); From 5fd059d80f9c2c47f6889c448b9d691bb8b20c1d Mon Sep 17 00:00:00 2001 From: Nishant Rodrigues Date: Mon, 8 Apr 2013 14:35:08 +0900 Subject: [PATCH 0506/1160] Patch fixing warning 322 in rubycontainer_extended 'rubycontainer_extended.swg' generates warnings: Warning 322: Redundant redeclaration of 'map_bang', Warning 322: previous declaration of 'map_bang'. The fix is to remove a redundant call to swig_container_extend for swig::GC_VALUE. Thanks ======================================================== --- Lib/ruby/rubycontainer_extended.swg | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/ruby/rubycontainer_extended.swg b/Lib/ruby/rubycontainer_extended.swg index d2a058586..7514ba2c8 100644 --- a/Lib/ruby/rubycontainer_extended.swg +++ b/Lib/ruby/rubycontainer_extended.swg @@ -124,7 +124,6 @@ %swig_container_extend( %arg( Container ), std::complex ); %swig_container_extend( %arg( Container ), std::string ); %swig_container_extend( %arg( Container ), swig::GC_VALUE ); -%swig_container_extend( %arg( Container ), swig::GC_VALUE ); %enddef From 1fce0bd2b41ee3ddebacfe101c6a231f6111bf21 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 8 Apr 2013 21:48:09 +0100 Subject: [PATCH 0507/1160] Workaround to Octave seg fault on exit in imports testcase only seems to work in 3.1, not 3.2. Just ignore test now --- Examples/test-suite/octave/imports_runme.m | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Examples/test-suite/octave/imports_runme.m b/Examples/test-suite/octave/imports_runme.m index 5db38071b..a9c8bffb8 100644 --- a/Examples/test-suite/octave/imports_runme.m +++ b/Examples/test-suite/octave/imports_runme.m @@ -1,20 +1,22 @@ # This is the import runtime testcase. -# If imports_b is loaded before imports_a, a seg fault occurred during interpreter cleanup/exit in version 3.1 and 3.2, seems okay in 3.6 -imports_a; -imports_b; +# Workaround seg fault occurring during interpreter cleanup/exit in version 3.1 and 3.2, seems okay in 3.6 +if (compare_versions(version(), "3.3", ">=")) + imports_b; + imports_a; -x = imports_b.B(); -x.hello(); + x = imports_b.B(); + x.hello(); -a = imports_a.A(); + a = imports_a.A(); -c = imports_b.C(); -a1 = c.get_a(c); -a2 = c.get_a_type(c); + c = imports_b.C(); + a1 = c.get_a(c); + a2 = c.get_a_type(c); -a1.hello(); -a2.hello(); -assert(swig_this(a1)==swig_this(a2)); -assert(strcmp(swig_type(a1),swig_type(a2))); + a1.hello(); + a2.hello(); + assert(swig_this(a1)==swig_this(a2)); + assert(strcmp(swig_type(a1),swig_type(a2))); +endif From 939fa86627cb95ce2670991e0c7feac26387edf1 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 9 Apr 2013 14:35:14 +1200 Subject: [PATCH 0508/1160] [PHP] Add missing directorin typemap for char* and char[] which fixes director_string testcase failure. --- CHANGES.current | 4 ++++ Lib/php/php.swg | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 9253f9c96..864fb9a3c 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.10 (in progress) ============================ +2013-04-09: olly + [PHP] Add missing directorin typemap for char* and char[] which + fixes director_string testcase failure. + 2013-04-05: wsfulton [Ruby] SF Bug #1292 - Runtime fixes for Proc changes in ruby-1.9 when using STL wrappers that override the default predicate, such as: diff --git a/Lib/php/php.swg b/Lib/php/php.swg index d46de93ea..f27e1fe67 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -269,6 +269,15 @@ ZVAL_LONG($input,$1); } +%typemap(directorin) char *, char [] +{ + if(!$1) { + ZVAL_NULL($input); + } else { + ZVAL_STRING($input, (char *)$1, 1); + } +} + %typemap(out) bool { ZVAL_BOOL(return_value,($1)?1:0); From 3e26318427a0e7dfdaf5e9ee1d988a1db1d6b464 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 9 Apr 2013 09:17:36 +0100 Subject: [PATCH 0509/1160] Add target language version display during make check. Individual language versions can be checked using 'make check--version'. --- Examples/Makefile.in | 222 ++++++++++++++++++++++++++ Examples/test-suite/cffi/Makefile.in | 2 +- Examples/test-suite/clisp/Makefile.in | 2 +- Examples/test-suite/uffi/Makefile.in | 2 +- Makefile.in | 41 ++++- configure.ac | 14 +- 6 files changed, 275 insertions(+), 8 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 6e1731f6b..a3444d284 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -95,6 +95,7 @@ distclean: # Set these to your local copy of Tcl/Tk. +TCLSH = tclsh TCL_INCLUDE = @TCLINCLUDE@ TCL_LIB = @TCLLIB@ TCL_OPTS = @LIBS@ @@ -154,6 +155,13 @@ tcl_cpp: $(SRCS) $(CXX) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE) $(TCLCXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(TCL_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(TCL_SO) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +tcl_version: + echo 'puts $$tcl_version;exit 0' | $(TCLSH) + # ----------------------------------------------------------------- # Cleaning the Tcl examples # ----------------------------------------------------------------- @@ -176,6 +184,7 @@ PERL5_INCLUDE= @PERL5EXT@ # Extra Perl specific dynamic linking options PERL5_DLNK = @PERL5DYNAMICLINKING@ PERL5_CCFLAGS = @PERL5CCFLAGS@ +PERL = @PERL@ # ---------------------------------------------------------------- # Build a Perl5 dynamically loadable module (C) @@ -216,6 +225,13 @@ perl5_static_cpp: $(SRCS) $(SWIG) -perl5 -c++ -static -lperlmain.i $(SWIGOPT) $(INTERFACEPATH) $(CXX) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +perl5_version: + $(PERL) -v | grep "This is" + # ----------------------------------------------------------------- # Cleaning the Perl5 examples # ----------------------------------------------------------------- @@ -315,6 +331,13 @@ runme3.py: runme.py cp $< $@ $(PY2TO3) -w $@ >/dev/null 2>&1 +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +python_version: + $(PYTHON) -V + # ----------------------------------------------------------------- # Cleaning the python examples # ----------------------------------------------------------------- @@ -368,6 +391,13 @@ OCTSCRIPT = runme.m octave_run: $(OCTSCRIPT) env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH OCTAVE_PATH=$(srcdir):$$OCTAVE_PATH $(OCTAVE) $(OCTSCRIPT) >/dev/null +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +octave_version: + $(OCTAVE) --version | grep -i version + # ----------------------------------------------------------------- # Cleaning the octave examples # ----------------------------------------------------------------- @@ -383,6 +413,7 @@ octave_clean: ################################################################## # Make sure these locate your Guile installation +GUILE = @GUILE@ GUILE_INCLUDE = @GUILEINCLUDE@ GUILE_LIB = @GUILELIB@ GUILE_SO = @GUILE_SO@ @@ -459,6 +490,13 @@ guile_simple_cpp: $(SRCS) $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ $(GUILE_INCLUDE) $(LIBS) -L$(GUILE_LIB) $(GUILE_LIBOPTS) -o $(TARGET)-guile +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +guile_version: + $(GUILE) --version + # ----------------------------------------------------------------- # Cleaning the Guile examples # ----------------------------------------------------------------- @@ -484,6 +522,8 @@ JAVASO =@JAVASO@ JAVALDSHARED = @JAVALDSHARED@ JAVACXXSHARED = @JAVACXXSHARED@ JAVACFLAGS = @JAVACFLAGS@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ # ---------------------------------------------------------------- # Build a java dynamically loadable module (C) @@ -503,6 +543,14 @@ java_cpp: $(SRCS) $(CXX) -c $(CCSHARED) $(CFLAGS) $(JAVACFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(JAVA_INCLUDE) $(JAVACXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JAVA_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(JAVA_LIBPREFIX)$(TARGET)$(JAVASO) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +java_version: + $(JAVA) -version + $(JAVAC) -version || echo "unknown javac version" + # ----------------------------------------------------------------- # Cleaning the java examples # ----------------------------------------------------------------- @@ -512,6 +560,17 @@ java_clean: rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@JAVASO@ +################################################################## +##### ANDROID ###### +################################################################## + +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +android_version: + adb version + ################################################################## ##### MODULA3 ###### ################################################################## @@ -530,6 +589,13 @@ modula3: $(SRCS) modula3_cpp: $(SRCS) $(SWIG) -modula3 -c++ $(SWIGOPT) $(INTERFACEPATH) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +modula3_version: + echo "Unknown modula3 version" + # ----------------------------------------------------------------- # Cleaning the modula3 examples # ----------------------------------------------------------------- @@ -543,6 +609,7 @@ modula3_clean: ##### MZSCHEME ###### ################################################################## +MZSCHEME = mzscheme MZC = @MZC@ MZDYNOBJ = @MZDYNOBJ@ MZSCHEME_SO = @MZSCHEME_SO@ @@ -561,6 +628,14 @@ mzscheme_cpp: $(SRCS) $(COMPILETOOL) $(MZC) `echo $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(CXXSHARED) $(CFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +mzscheme_version: + $(MZSCHEME) -v + $(MZC) -v + # ----------------------------------------------------------------- # Cleaning the mzscheme examples # ----------------------------------------------------------------- @@ -697,6 +772,17 @@ ocaml_dynamic_cpp: $(SRCS) -package dl -linkpkg \ $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) -cc '$(CXX) -Wno-write-strings' +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +ocaml_version: + $(OCC) -version + +# ----------------------------------------------------------------- +# Cleaning the Ocaml examples +# ----------------------------------------------------------------- + ocaml_clean: rm -f *_wrap* *~ .~* *.cmo *.cmi $(MLFILE) $(MLFILE)i swig.mli swig.cmi swig.ml swig.cmo swigp4.ml swigp4.cmo rm -f core @EXTRA_CLEAN@ @@ -711,6 +797,7 @@ RUBY_CFLAGS= @RUBYCCDLFLAGS@ $(DEFS) RUBY_INCLUDE= @RUBYINCLUDE@ RUBY_LIB = @RUBYLIB@ RUBY_DLNK = @RUBYDYNAMICLINKING@ +RUBY = @RUBY@ # ---------------------------------------------------------------- # Build a C dynamically loadable module @@ -750,6 +837,13 @@ ruby_cpp_static: $(SRCS) $(RUBY_INCLUDE) $(LIBS) -L$(RUBY_LIB) $(RUBY_LIBOPTS) -o $(TARGET) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +ruby_version: + $(RUBY) -v + # ----------------------------------------------------------------- # Cleaning the Ruby examples # ----------------------------------------------------------------- @@ -794,6 +888,13 @@ PHPSCRIPT ?= runme.php php_run: $(RUNTOOL) $(PHP) -n -q -d extension_dir=. -d safe_mode=Off $(PHPSCRIPT) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +php_version: + $(PHP) -v + # ----------------------------------------------------------------- # Cleaning the PHP examples # ----------------------------------------------------------------- @@ -808,6 +909,7 @@ php_clean: ################################################################## # Make sure these locate your Pike installation +PIKE = pike PIKE_CFLAGS = @PIKECCDLFLAGS@ -DHAVE_CONFIG_H PIKE_INCLUDE = @PIKEINCLUDE@ PIKE_LIB = @PIKELIB@ @@ -850,6 +952,13 @@ pike_cpp_static: $(SRCS) $(CXX) $(CFLAGS) $(PIKE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ $(PIKE_INCLUDE) $(LIBS) -L$(PIKE_LIB) $(PIKE_LIBOPTS) -o $(TARGET) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +pike_version: + $(PIKE) -v + # ----------------------------------------------------------------- # Cleaning the Pike examples # ----------------------------------------------------------------- @@ -951,6 +1060,17 @@ chicken_cpp: chicken_externalhdr: $(SWIG) -chicken -external-runtime $(TARGET) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +chicken_version: + $(CHICKEN) -version + +# ----------------------------------------------------------------- +# Cleaning the CHICKEN examples +# ----------------------------------------------------------------- + chicken_clean: rm -f *_wrap* *~ .~* *_chicken* rm -f core @EXTRA_CLEAN@ @@ -993,6 +1113,13 @@ csharp_cpp: $(SRCS) csharp_compile: $(SRCS) $(COMPILETOOL) $(CSHARPCOMPILER) $(CSHARPFLAGS) $(CSHARPSRCS) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +csharp_version: + $(CSHARPCOMPILER) --version || echo "Unknown C# compiler version" + # ----------------------------------------------------------------- # Cleaning the CSharp examples # ----------------------------------------------------------------- @@ -1013,6 +1140,7 @@ LUA_LIB = @LUALINK@ # Extra specific dynamic linking options LUA_DLNK = @LUADYNAMICLINKING@ LUA_SO = @LUA_SO@ +LUA = @LUABIN@ # Extra code for lua static link LUA_INTERP = ../lua.c @@ -1049,6 +1177,13 @@ lua_static_cpp: $(SRCS) $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(LUA_INTERP) $(INCLUDES) \ $(LUA_INCLUDE) $(LIBS) $(LUA_LIB) -o $(TARGET) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +lua_version: + $(LUA) -v + # ----------------------------------------------------------------- # Cleaning the lua examples # ----------------------------------------------------------------- @@ -1062,6 +1197,8 @@ lua_clean: ##### ALLEGRO CL ###### ################################################################## +ALLEGROCL = @ALLEGROCLBIN@ + allegrocl: $(SRCS) $(SWIG) -allegrocl -cwrap $(SWIGOPT) $(INTERFACEPATH) $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) @@ -1072,6 +1209,17 @@ allegrocl_cpp: $(SRCS) $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +allegrocl_version: + $(ALLEGROCL) --version + +# ----------------------------------------------------------------- +# Cleaning the ALLEGRO CL examples +# ----------------------------------------------------------------- + allegrocl_clean: rm -f *_wrap* *~ .~* rm -f core @EXTRA_CLEAN@ @@ -1081,12 +1229,25 @@ allegrocl_clean: ##### CLISP ###### ################################################################## +CLISP = @CLISPBIN@ + clisp: $(SRCS) $(SWIG) -clisp $(SWIGOPT) $(INTERFACEPATH) clisp_cpp: $(SRCS) $(SWIG) -c++ -clisp $(SWIGOPT) $(INTERFACEPATH) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +clisp_version: + $(CLISP) --version + +# ----------------------------------------------------------------- +# Cleaning the CLISP examples +# ----------------------------------------------------------------- + clisp_clean: rm -f *_wrap* *~ .~* rm -f core @EXTRA_CLEAN@ @@ -1096,6 +1257,8 @@ clisp_clean: ##### CFFI ###### ################################################################## +CFFI = @CFFIBIN@ + cffi: $(SRCS) $(SWIG) -cffi $(SWIGOPT) $(INTERFACEPATH) # $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) @@ -1106,6 +1269,17 @@ cffi_cpp: $(SRCS) $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +cffi_version: + $(CFFI) --version + +# ----------------------------------------------------------------- +# Cleaning the CFFI examples +# ----------------------------------------------------------------- + cffi_clean: rm -f *_wrap* *~ .~* rm -f core @EXTRA_CLEAN@ @@ -1115,6 +1289,8 @@ cffi_clean: ##### UFFI ###### ################################################################## +UFFI = @UFFIBIN@ + uffi: $(SRCS) $(SWIG) -uffi $(SWIGOPT) $(INTERFACEPATH) # $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) @@ -1125,6 +1301,17 @@ uffi_cpp: $(SRCS) # $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) # $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +uffi_version: + $(UFFI) --version + +# ----------------------------------------------------------------- +# Cleaning the UFFI examples +# ----------------------------------------------------------------- + uffi_clean: rm -f *_wrap* *~ .~* rm -f core @EXTRA_CLEAN@ @@ -1143,6 +1330,10 @@ R_CFLAGS=-fPIC # we get -fPIC # CMD SHLIB stdout is piped to /dev/null to prevent echo of compiler command +# ---------------------------------------------------------------- +# Build a R dynamically loadable module (C) +# ---------------------------------------------------------------- + r: $(SRCS) $(SWIG) -r $(SWIGOPT) $(INTERFACEPATH) ifneq ($(SRCS),) @@ -1150,6 +1341,10 @@ ifneq ($(SRCS),) endif +( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(OBJS) > /dev/null ) +# ---------------------------------------------------------------- +# Build a R dynamically loadable module (C++) +# ---------------------------------------------------------------- + r_cpp: $(CXXSRCS) $(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH) ifneq ($(CXXSRCS),) @@ -1157,6 +1352,17 @@ ifneq ($(CXXSRCS),) endif +( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null ) +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +r_version: + $(R) --version | grep -i version + +# ----------------------------------------------------------------- +# Cleaning the R examples +# ----------------------------------------------------------------- + r_clean: rm -f *_wrap* *~ .~* rm -f core @EXTRA_CLEAN@ @@ -1172,6 +1378,7 @@ GOGCC = @GOGCC@ GO1 = @GO1@ GOC = @GOC@ GOOPT = @GOOPT@ +GOVERSIONOPTION = @GOVERSIONOPTION@ GOSWIGARG = `if $(GOGCC) ; then echo -gccgo; fi` GOCOMPILEARG = `if $(GOGCC) ; then echo -c -g; elif $(GO1) ; then echo tool $(GOC:c=g) ; fi` @@ -1230,6 +1437,13 @@ go_run: runme.go fi env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +go_version: + $(GO) $(GOVERSIONOPTION) + # ----------------------------------------------------------------- # Cleaning the Go examples # ----------------------------------------------------------------- @@ -1291,6 +1505,14 @@ d_compile: $(SRCS) d_run: env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +d_version: + # Needs improvement! + echo D version guess - $(D_VERSION) + # ----------------------------------------------------------------- # Clean the D examples # ----------------------------------------------------------------- diff --git a/Examples/test-suite/cffi/Makefile.in b/Examples/test-suite/cffi/Makefile.in index bf21b3552..aa8b40aec 100644 --- a/Examples/test-suite/cffi/Makefile.in +++ b/Examples/test-suite/cffi/Makefile.in @@ -39,7 +39,7 @@ CPP_TEST_CASES = # a file is found which has _runme.lisp appended after the testcase name. run_testcase = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(CFFIBIN) -batch -s $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(CFFI) -batch -s $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \ fi # Clean: (does nothing, we dont generate extra cffi code) diff --git a/Examples/test-suite/clisp/Makefile.in b/Examples/test-suite/clisp/Makefile.in index 2ebaa6750..24655a60f 100644 --- a/Examples/test-suite/clisp/Makefile.in +++ b/Examples/test-suite/clisp/Makefile.in @@ -39,7 +39,7 @@ CPP_TEST_CASES = # a file is found which has _runme.lisp appended after the testcase name. run_testcase = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(CLISPBIN) -batch -s $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(CLISP) -batch -s $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \ fi # Clean: (does nothing, we dont generate extra clisp code) diff --git a/Examples/test-suite/uffi/Makefile.in b/Examples/test-suite/uffi/Makefile.in index d6b948b5d..8ad153961 100644 --- a/Examples/test-suite/uffi/Makefile.in +++ b/Examples/test-suite/uffi/Makefile.in @@ -39,7 +39,7 @@ CPP_TEST_CASES = # a file is found which has _runme.lisp appended after the testcase name. run_testcase = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(UFFIBIN) -batch -s $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(UFFI) -batch -s $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \ fi # Clean: (does nothing, we dont generate extra uffi code) diff --git a/Makefile.in b/Makefile.in index 7ecbfa251..8a6776bf8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -123,6 +123,45 @@ check-aliveness: check-ccache: test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) check) +# Checks / displays versions of each target language +check-versions: \ + check-tcl-version \ + check-perl5-version \ + check-python-version \ + check-java-version \ + check-android-version \ + check-guile-version \ + check-mzscheme-version \ + check-ruby-version \ + check-ocaml-version \ + check-octave-version \ + check-php-version \ + check-pike-version \ + check-chicken-version \ + check-csharp-version \ + check-modula3-version \ + check-lua-version \ + check-allegrocl-version \ + check-clisp-version \ + check-uffi-version \ + check-cffi-version \ + check-r-version \ + check-go-version \ + check-d-version + +# all examples +check-%-version : + @if test -z "$(skip-$*)"; then \ + echo $* unknown; \ + exit 1; \ + fi + @if $(skip-$*); then \ + echo skipping $* version; \ + else \ + echo showing $* version; \ + (cd Examples && $(MAKE) -s $*_version) \ + fi + # Checks examples for compilation (does not run them) check-examples: \ check-tcl-examples \ @@ -252,7 +291,7 @@ partialcheck-test-suite: partialcheck-%-test-suite: @$(MAKE) -k -s check-$*-test-suite ACTION=partialcheck NOSKIP=1 -check: check-aliveness check-ccache check-examples check-test-suite +check: check-aliveness check-ccache check-versions check-examples check-test-suite # Run known-to-be-broken as well as not broken testcases in the test-suite all-test-suite: \ diff --git a/configure.ac b/configure.ac index cfbc09426..65a9c9078 100644 --- a/configure.ac +++ b/configure.ac @@ -1592,7 +1592,7 @@ if test x"${PIKEBIN}" = xno -o x"${with_alllang}" = xno ; then else if test "x$PIKEBIN" = xyes; then - AC_CHECK_PROGS(PIKE, pike pike7.6 pike7.4 pike7.2) + AC_CHECK_PROGS(PIKE, pike pike7.8 pike7.6 pike7.4 pike7.2) else PIKE="$PIKEBIN" fi @@ -2063,6 +2063,7 @@ if test x"${GOBIN}" = xno -o x"${with_alllang}" = xno ; then GO1=false GOGCC=false GOOPT= + GOVERSIONOPTION= else if test "x$GOBIN" = xyes; then @@ -2074,11 +2075,13 @@ else GOGCC=false GO1=false GOOPT= + GOVERSIONOPTION= if test -n "$GO" ; then if $GO --help 2>/dev/null | grep gccgo >/dev/null 2>&1 ; then GOGCC=true + GOVERSIONOPTION=--version AC_MSG_CHECKING([whether gccgo version is too old]) - go_version=`$GO --version | sed -e 's/[^0-9]* \([0-9.]*\) .*$/\1/' -e 's/[.]//g'` + go_version=`$GO $GOVERSIONOPTION | sed -e 's/[^0-9]* \([0-9.]*\) .*$/\1/' -e 's/[.]//g'` if test "$go_version" -lt 470; then AC_MSG_RESULT([yes - minimum version is 4.7.0]) else @@ -2096,8 +2099,9 @@ else fi elif test "`echo $GO | sed -e 's|.*/||'`" = "go"; then GO1=true + GOVERSIONOPTION=version GOC=$(sh -c "$(go env) && echo \$GOCHAR")c - go_version=$($GO version | sed -e 's/go version //') + go_version=$($GO $GOVERSIONOPTION | sed -e 's/go version //') case $go_version in go1.0*) GOOPT="-intgosize 32" ;; *) if test "$GOC" = "6c"; then @@ -2109,8 +2113,9 @@ else esac else GOC=`echo $GO | sed -e 's/g/c/'` + GOVERSIONOPTION=-V AC_MSG_CHECKING([whether Go ($GO) version is too old]) - go_version=`$GO -V 2>/dev/null | sed -e 's/.*version.* \([[0-9]]*\).*/\1/'` + go_version=`$GO $GOVERSIONOPTION 2>/dev/null | sed -e 's/.*version.* \([[0-9]]*\).*/\1/'` go_min_version=7077 if test "$go_version" != "" -a "$go_version" -lt $go_min_version; then AC_MSG_RESULT([yes - minimum version is $go_min_version]) @@ -2128,6 +2133,7 @@ AC_SUBST(GO) AC_SUBST(GOC) AC_SUBST(GO1) AC_SUBST(GOOPT) +AC_SUBST(GOVERSIONOPTION) #---------------------------------------------------------------- # Look for D From 970c72b6da18516966ba82c91fa1e3cbb1b5725d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 9 Apr 2013 22:52:54 +0100 Subject: [PATCH 0510/1160] make check-csharp-version fix for MS compiler --- Examples/Makefile.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index a3444d284..c234c41ab 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1117,8 +1117,9 @@ csharp_compile: $(SRCS) # Version display # ----------------------------------------------------------------- +# Version check below also works with MS csc.exe which does not understand --version csharp_version: - $(CSHARPCOMPILER) --version || echo "Unknown C# compiler version" + $(CSHARPCOMPILER) --version | grep -i version # ----------------------------------------------------------------- # Cleaning the CSharp examples From 35ab209332bb279cc3f0c25eb5596d21e44a2f90 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 9 Apr 2013 23:52:35 +0100 Subject: [PATCH 0511/1160] Travis build for top 10 target languages plus gcc and clang SWIG builds. Travis builds patch developed in wsfulton/travis branch --- .travis.yml | 56 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 78205c848..abdb54327 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,31 +1,51 @@ language: cpp compiler: - - gcc - clang + - gcc +env: + - SWIGLANG= matrix: include: - - python: "2.7" - compiler: gcc + - compiler: gcc + env: SWIGLANG=csharp + - compiler: gcc + env: SWIGLANG=go + - compiler: gcc + env: SWIGLANG=java + - compiler: gcc + env: SWIGLANG=lua + - compiler: gcc + env: SWIGLANG=octave SWIGJOBS=-j4 + - compiler: gcc + env: SWIGLANG=perl5 + - compiler: gcc + env: SWIGLANG=php + - compiler: gcc env: SWIGLANG=python - - jdk: oraclejdk6 - compiler: gcc - env: SWIGLANG=java - - jdk: oraclejdk7 - compiler: gcc - env: SWIGLANG=java - - perl: "5.10" - compiler: gcc - env: SWIGLANG=perl - - rvm: 1.8.7 - compiler: gcc + - compiler: gcc env: SWIGLANG=ruby + - compiler: gcc + env: SWIGLANG=tcl + allow_failures: + # None before_install: - - sudo apt-get install libboost-dev -qq + - lsb_release -a + - uname -a + - time sudo apt-get -qq install libboost-dev + - if test "$SWIGLANG" = "csharp"; then sudo apt-get -qq install mono-devel; fi + - if test "$SWIGLANG" = "go"; then go env | sed -e 's/^/export /' > goenvsetup && source goenvsetup && rm -f goenvsetup; fi # Until configure.ac is fixed + - if test "$SWIGLANG" = "lua"; then sudo apt-get -qq install lua5.1 liblua5.1-dev; fi + - if test "$SWIGLANG" = "octave"; then sudo apt-get -qq install octave3.2 octave3.2-headers; fi + - if test "$SWIGLANG" = "php"; then sudo apt-get install php5-cli php5-dev; fi + - if test "$SWIGLANG" = "tcl"; then sudo apt-get -qq install tcl8.4-dev; fi script: - ./autogen.sh && ./configure - - make -s - - echo "SWIGLANG: $SWIGLANG" -# - make -k check-$SWIGLANG-examples check-$SWIGLANG-test-suite + - make -s $SWIGJOBS + - if test -z "$SWIGLANG"; then make -s check-ccache; fi + - ./swig -version + - if test -n "$SWIGLANG"; then make -s check-$SWIGLANG-version; fi + - if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-examples; fi + - if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-test-suite; fi branches: only: - master From d0202cbdac17721ebfdf8114a1cb96372d867a4a Mon Sep 17 00:00:00 2001 From: Marvin Greenberg Date: Wed, 10 Apr 2013 18:37:26 +0100 Subject: [PATCH 0512/1160] Fix typecheck OUTPUT typemaps for Java --- Lib/java/typemaps.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/java/typemaps.i b/Lib/java/typemaps.i index ae2377b70..e71790bcc 100644 --- a/Lib/java/typemaps.i +++ b/Lib/java/typemaps.i @@ -207,8 +207,8 @@ There are no char *OUTPUT typemaps, however you can apply the signed char * type JCALL4(Set##JAVATYPE##ArrayRegion, jenv, $input, 0, 1, &jvalue); } -%typemap(typecheck) TYPE *INOUT = TYPECHECKTYPE; -%typemap(typecheck) TYPE &INOUT = TYPECHECKTYPE; +%typemap(typecheck) TYPE *OUTPUT = TYPECHECKTYPE; +%typemap(typecheck) TYPE &OUTPUT = TYPECHECKTYPE; %enddef OUTPUT_TYPEMAP(bool, jboolean, boolean, Boolean, "[Ljava/lang/Boolean;", jbooleanArray); From a16dc2904603decad54e50f4096e99c3ae26f017 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 14 Apr 2013 06:14:47 +1200 Subject: [PATCH 0513/1160] Removed unused Printf parameter --- 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 fdd335993..bc8a92687 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2591,7 +2591,7 @@ done: } if (!idx) { - Printf(w->code, "zval **args = NULL;\n", idx); + Printf(w->code, "zval **args = NULL;\n"); } else { Printf(w->code, "zval *args[%d];\n", idx); } From 24ff00690f2b1bc36bb8a00c9a236ce1c444e61c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 14 Apr 2013 08:03:46 +1200 Subject: [PATCH 0514/1160] Use ZVAL_STRINGL instead of ZVAL_STRING to set funcname as we know the length at swig-time --- Source/Modules/php.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index bc8a92687..3cae48383 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2597,7 +2597,8 @@ done: } Printf(w->code, "zval *%s, funcname;\n", Swig_cresult_name()); Printf(w->code, "MAKE_STD_ZVAL(%s);\n", Swig_cresult_name()); - Printf(w->code, "ZVAL_STRING(&funcname, (char *)\"%s\", 0);\n", GetChar(n, "sym:name")); + const char * funcname = GetChar(n, "sym:name"); + Printf(w->code, "ZVAL_STRINGL(&funcname, (char *)\"%s\", %d, 0);\n", funcname, strlen(funcname)); Append(w->code, "if (!swig_self) {\n"); Append(w->code, " SWIG_PHP_Error(E_ERROR, \"this pointer is NULL\");"); Append(w->code, "}\n\n"); From 611acbf94447f51db1583fb4b6a147860803fcfc Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 15 Apr 2013 22:17:48 +0200 Subject: [PATCH 0515/1160] Add -MP option for generating phony targets for all dependencies - Modelled on similar option in GCC --- CHANGES.current | 6 ++++++ Source/Modules/main.cxx | 20 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 864fb9a3c..ece451ae2 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,12 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-04-08: kwwette + Add -MP option to SWIG for generating phony targets for all dependencies. + - Prevents make from complaining if header files have been deleted before + the dependency file has been updated. + - Modelled on similar option in GCC. + 2013-04-09: olly [PHP] Add missing directorin typemap for char* and char[] which fixes director_string testcase failure. diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index d1f3ab274..4076b9206 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -107,6 +107,7 @@ static const char *usage2 = (const char *) "\ -MM - List dependencies, but omit files in SWIG library\n\ -MMD - Like `-MD', but omit files in SWIG library\n\ -module - Set module name to \n\ + -MP - Generate phony targets for all dependencies\n\ -MT - Set the target of the rule emitted by dependency generation\n\ -nocontract - Turn off contract checking\n\ -nocpperraswarn - Do not treat the preprocessor #error statement as #warning\n\ @@ -185,6 +186,7 @@ static int dump_classes = 0; static int werror = 0; static int depend = 0; static int depend_only = 0; +static int depend_phony = 0; static int memory_debug = 0; static int allkw = 0; static DOH *cpps = 0; @@ -712,6 +714,9 @@ void SWIG_getoptions(int argc, char *argv[]) { } else if (strcmp(argv[i], "-MMD") == 0) { depend = 2; Swig_mark_arg(i); + } else if (strcmp(argv[i], "-MP") == 0) { + depend_phony = 1; + Swig_mark_arg(i); } else if (strcmp(argv[i], "-MT") == 0) { Swig_mark_arg(i); if (argv[i + 1]) { @@ -1101,22 +1106,33 @@ int SWIG_main(int argc, char *argv[], Language *l) { Printf(f_dependencies_file, "%s: ", outfile); } List *files = Preprocessor_depend(); + List *phony_targets = NewList(); for (int i = 0; i < Len(files); i++) { int use_file = 1; if (depend == 2) { if ((Strncmp(Getitem(files, i), SwigLib, Len(SwigLib)) == 0) || (SwigLibWinUnix && (Strncmp(Getitem(files, i), SwigLibWinUnix, Len(SwigLibWinUnix)) == 0))) use_file = 0; } - if (use_file) - Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i)); + if (use_file) { + Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i)); + if (depend_phony) + Append(phony_targets, Getitem(files, i)); + } } Printf(f_dependencies_file, "\n"); + if (depend_phony) { + for (int i = 0; i < Len(phony_targets); i++) { + Printf(f_dependencies_file, "\n%s:\n", Getitem(phony_targets, i)); + } + } + if (f_dependencies_file != stdout) Delete(f_dependencies_file); if (depend_only) SWIG_exit(EXIT_SUCCESS); Delete(inputfile_filename); Delete(basename); + Delete(phony_targets); } else { Printf(stderr, "Cannot generate dependencies with -nopreprocess\n"); // Actually we could but it would be inefficient when just generating dependencies, as it would be done after Swig_cparse From 25eaee49f3cb4348e71b66144e9ba541c0632fa5 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Mon, 15 Apr 2013 13:38:40 -0500 Subject: [PATCH 0516/1160] Add check for smart pointer type in generated code for director connection. This fixes a crash in the generated code caused by the dynamic_cast returning 0 because the specified types are incorrect for smart pointer types. Add runtime test to the C# test suite's director smartptr test that demonstrates crash in generated code when directors are used with smart pointer types. Closes #34 --- .../csharp/director_smartptr_runme.cs | 41 +++++++++++++++++++ Source/Modules/csharp.cxx | 14 ++++++- 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/csharp/director_smartptr_runme.cs diff --git a/Examples/test-suite/csharp/director_smartptr_runme.cs b/Examples/test-suite/csharp/director_smartptr_runme.cs new file mode 100644 index 000000000..ad33c4d34 --- /dev/null +++ b/Examples/test-suite/csharp/director_smartptr_runme.cs @@ -0,0 +1,41 @@ +using director_smartptrNamespace; + +public class runme +{ + + private class director_smartptr_MyBarFoo : Foo + { + public override string ping() + { + return "director_smartptr_MyBarFoo.ping();"; + } + + public override string pong() + { + return "director_smartptr_MyBarFoo.pong();" + ping(); + } + + public override string fooBar(FooBar fooBar) + { + return fooBar.FooBarDo(); + } + + public override Foo makeFoo() + { + return new Foo(); + } + + public override FooBar makeFooBar() + { + return new FooBar(); + } + } + + static void Main() + { + director_smartptr_MyBarFoo myBarFoo = + new director_smartptr_MyBarFoo(); + + myBarFoo.ping(); + } +} diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 4ef62d2cc..2050f36db 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3382,6 +3382,7 @@ public: String *qualified_classname = Copy(sym_name); String *nspace = getNSpace(); String *dirClassName = directorClassName(n); + String *smartptr_feature = Getattr(n, "feature:smartptr"); if (nspace) Insert(qualified_classname, 0, NewStringf("%s.", nspace)); @@ -3392,8 +3393,17 @@ public: Wrapper *code_wrap = NewWrapper(); 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, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName); + if (Len(smartptr_feature)) { + Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", smartptr_feature, smartptr_feature); + Printf(code_wrap->code, " // Keep a local instance of the smart pointer around while we are using the raw pointer\n"); + Printf(code_wrap->code, " // Avoids using smart pointer specific API.\n"); + Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj->operator->());\n", dirClassName, dirClassName); + } + else { + Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name); + Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName); + } + // TODO: if statement not needed?? - Java too Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_connect_director("); From 296498c15925217ccd5dfe6cf8fa59b6d78c1270 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 17 Apr 2013 21:47:36 +0100 Subject: [PATCH 0517/1160] Cosmetic tidyup in smartptr feature code and document smartptr fix in previous commit --- CHANGES.current | 3 +++ Source/Modules/csharp.cxx | 6 +++--- Source/Modules/java.cxx | 14 +++++--------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index ece451ae2..254ecf8ba 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-04-17: wsfulton + [C#] Pull patch #34 from BrantKyser to fix smart pointers in conjuction with directors. + 2013-04-08: kwwette Add -MP option to SWIG for generating phony targets for all dependencies. - Prevents make from complaining if header files have been deleted before diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 2050f36db..6d5c570b1 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3382,7 +3382,7 @@ public: String *qualified_classname = Copy(sym_name); String *nspace = getNSpace(); String *dirClassName = directorClassName(n); - String *smartptr_feature = Getattr(n, "feature:smartptr"); + String *smartptr = Getattr(n, "feature:smartptr"); if (nspace) Insert(qualified_classname, 0, NewStringf("%s.", nspace)); @@ -3393,8 +3393,8 @@ public: Wrapper *code_wrap = NewWrapper(); Printf(code_wrap->def, "SWIGEXPORT void SWIGSTDCALL %s(void *objarg", wname); - if (Len(smartptr_feature)) { - Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", smartptr_feature, smartptr_feature); + if (Len(smartptr)) { + Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", smartptr, smartptr); Printf(code_wrap->code, " // Keep a local instance of the smart pointer around while we are using the raw pointer\n"); Printf(code_wrap->code, " // Avoids using smart pointer specific API.\n"); Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj->operator->());\n", dirClassName, dirClassName); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index f351c91a3..dbd110d56 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3389,7 +3389,7 @@ public: String *norm_name = SwigType_namestr(Getattr(n, "name")); String *swig_director_connect = Swig_name_member(getNSpace(), proxy_class_name, "director_connect"); String *swig_director_connect_jni = makeValidJniName(swig_director_connect); - String *smartptr_feature = Getattr(n, "feature:smartptr"); + String *smartptr = Getattr(n, "feature:smartptr"); String *dirClassName = directorClassName(n); Wrapper *code_wrap; @@ -3401,15 +3401,11 @@ public: "SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jswig_mem_own, " "jboolean jweak_global) {\n", jnipackage, jni_imclass_name, swig_director_connect_jni); - if (Len(smartptr_feature)) { - Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", smartptr_feature, smartptr_feature); + if (Len(smartptr)) { + Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", smartptr, smartptr); Printf(code_wrap->code, " (void)jcls;\n"); - Printf(code_wrap->code, " // NOTE: Pulling the raw pointer out of the smart pointer as the following code does\n"); - Printf(code_wrap->code, " // is generally a bad idea. However, in this case we keep a local instance of the\n"); - Printf(code_wrap->code, " // smart pointer around while we are using the raw pointer, which should keep the\n"); - Printf(code_wrap->code, " // raw pointer alive. This is done instead of using the smart pointer's dynamic cast\n"); - Printf(code_wrap->code, " // feature since different smart pointer implementations have differently named dynamic\n"); - Printf(code_wrap->code, " // cast mechanisms.\n"); + Printf(code_wrap->code, " // Keep a local instance of the smart pointer around while we are using the raw pointer\n"); + Printf(code_wrap->code, " // Avoids using smart pointer specific API.\n"); Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj->operator->());\n", dirClassName, dirClassName); } else { From 2a3e687c19385bb516b89343ffa0f347465ade82 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Tue, 16 Apr 2013 11:11:20 +0200 Subject: [PATCH 0518/1160] Octave: fix bugs in output of cleanup code Closes #35 --- CHANGES.current | 6 ++++++ Source/Modules/octave.cxx | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 254ecf8ba..926096cab 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -8,6 +8,12 @@ Version 2.0.10 (in progress) 2013-04-17: wsfulton [C#] Pull patch #34 from BrantKyser to fix smart pointers in conjuction with directors. +2013-04-15: kwwette + [Octave] Fix bugs in output of cleanup code. + - Cleanup code is now written also after the "fail:" label, so it will be called if + a SWIG_exception is raised by the wrapping function, consistent with other modules. + - Octave module now also recognises the "$cleanup" special variable, if needed. + 2013-04-08: kwwette Add -MP option to SWIG for generating phony targets for all dependencies. - Prevents make from complaining if header files have been deleted before diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index a9be76fc2..bf2552a30 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -744,10 +744,15 @@ public: Delete(tm); } - Printf(f->code, "fail:\n"); // we should free locals etc if this happens Printf(f->code, "return _out;\n"); + Printf(f->code, "fail:\n"); // we should free locals etc if this happens + Printv(f->code, cleanup, NIL); + Printf(f->code, "return octave_value_list();\n"); Printf(f->code, "}\n"); + /* Substitute the cleanup code */ + Replaceall(f->code, "$cleanup", cleanup); + Replaceall(f->code, "$symname", iname); Wrapper_print(f, f_wrappers); DelWrapper(f); From 857e447654c72184a9bace33ec3ad33ddb354c1d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 18 Apr 2013 22:47:41 +0100 Subject: [PATCH 0519/1160] Fix syntax error when preprocessor macros are defined inside of enum lists Fixes SF Bug 428, Patch 333 --- CHANGES.current | 10 ++ Examples/test-suite/common.mk | 1 + Examples/test-suite/enum_macro.i | 92 ++++++++++++++++++ .../test-suite/java/enum_macro_runme.java | 93 +++++++++++++++++++ Source/CParse/parser.y | 46 ++++----- 5 files changed, 220 insertions(+), 22 deletions(-) create mode 100644 Examples/test-suite/enum_macro.i create mode 100644 Examples/test-suite/java/enum_macro_runme.java diff --git a/CHANGES.current b/CHANGES.current index 926096cab..4c1e55bc0 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,16 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-04-18: wsfulton + Fix SF Bug #428 - Syntax error when preprocessor macros are defined inside of enum lists, such as: + + typedef enum { + eZero = 0 + #define ONE 1 + } EFoo; + + The macros are silently ignored. + 2013-04-17: wsfulton [C#] Pull patch #34 from BrantKyser to fix smart pointers in conjuction with directors. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 83be90d2d..793055097 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -514,6 +514,7 @@ C_TEST_CASES += \ empty \ enums \ enum_forward \ + enum_macro \ extern_declaration \ funcptr \ function_typedef \ diff --git a/Examples/test-suite/enum_macro.i b/Examples/test-suite/enum_macro.i new file mode 100644 index 000000000..b18e02a84 --- /dev/null +++ b/Examples/test-suite/enum_macro.i @@ -0,0 +1,92 @@ +%module enum_macro + +%inline %{ +enum Greeks1 +{ +#define GREEK1 -1 + alpha1=1, + beta1, + theta1 +}; + +enum Greeks2 +{ + alpha2 = 2, +#define GREEK2 -2 + beta2, + theta2 +}; + +enum Greeks3 +{ + alpha3, + beta3, +#define GREEK3 -3 + theta3 +}; + +enum Greeks4 +{ + alpha4 = 4, + beta4 = 5, + theta4 = 6 +#define GREEK4 -4 +}; + +enum Greeks5 +{ +#define GREEK5 -5 + alpha5, + beta5, +}; + +enum Greeks6 +{ + alpha6, +#define GREEK6 -6 + beta6, +}; + +enum Greeks7 +{ + alpha7, + beta7, +#define GREEK7 -7 +}; + +enum Greeks8 +{ +#define GREEK8 -8 + theta8 +}; + +enum Greeks9 +{ + theta9 +#define GREEK9 -9 +}; + +enum Greeks10 +{ +#define GREEK10 -10 + theta10, +}; + +enum Greeks11 +{ + theta11, +#define GREEK11 -11 +}; + +typedef enum { + theta12 = 0 +#define GREEK12 -12 +} Greeks12; +%} + + +enum Greeks13 +{ +#define GREEK13 -13 +}; + diff --git a/Examples/test-suite/java/enum_macro_runme.java b/Examples/test-suite/java/enum_macro_runme.java new file mode 100644 index 000000000..4ac7409ee --- /dev/null +++ b/Examples/test-suite/java/enum_macro_runme.java @@ -0,0 +1,93 @@ + +import enum_macro.*; + +public class enum_macro_runme { + + static { + try { + System.loadLibrary("enum_macro"); + } 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[]) + { + { + Greeks1 a = Greeks1.alpha1; + a = Greeks1.beta1; + a = Greeks1.theta1; + if (a.swigValue() != 3) + throw new RuntimeException("Greeks1"); + } + { + Greeks2 a = Greeks2.alpha2; + a = Greeks2.beta2; + a = Greeks2.theta2; + if (a.swigValue() != 4) + throw new RuntimeException("Greeks2"); + } + { + Greeks3 a = Greeks3.alpha3; + a = Greeks3.beta3; + a = Greeks3.theta3; + if (a.swigValue() != 2) + throw new RuntimeException("Greeks3"); + } + { + Greeks4 a = Greeks4.alpha4; + a = Greeks4.beta4; + a = Greeks4.theta4; + if (a.swigValue() != 6) + throw new RuntimeException("Greeks4"); + } + { + Greeks5 a = Greeks5.alpha5; + a = Greeks5.beta5; + if (a.swigValue() != 1) + throw new RuntimeException("Greeks5"); + } + { + Greeks6 a = Greeks6.alpha6; + a = Greeks6.beta6; + if (a.swigValue() != 1) + throw new RuntimeException("Greeks6"); + } + { + Greeks7 a = Greeks7.alpha7; + a = Greeks7.beta7; + if (a.swigValue() != 1) + throw new RuntimeException("Greeks7"); + } + { + Greeks8 a = Greeks8.theta8; + if (a.swigValue() != 0) + throw new RuntimeException("Greeks8"); + } + { + Greeks9 a = Greeks9.theta9; + if (a.swigValue() != 0) + throw new RuntimeException("Greeks9"); + } + { + Greeks10 a = Greeks10.theta10; + if (a.swigValue() != 0) + throw new RuntimeException("Greeks10"); + } + { + Greeks11 a = Greeks11.theta11; + if (a.swigValue() != 0) + throw new RuntimeException("Greeks11"); + } + { + Greeks12 a = Greeks12.theta12; + if (a.swigValue() != 0) + throw new RuntimeException("Greeks12"); + } + { + Greeks13 a = null; + } + } +} + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 74d41079c..92c518e1f 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1788,6 +1788,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type type_specifier primitive_type_list ; %type fname stringtype; %type featattr; +%type optional_constant_directive; %% @@ -5647,29 +5648,31 @@ definetype : { /* scanner_check_typedef(); */ } expr { /* Some stuff for handling enums */ ename : ID { $$ = $1; } - | empty { $$ = (char *) 0;} - ; + | empty { $$ = (char *) 0;} + ; -enumlist : enumlist COMMA edecl { +optional_constant_directive : constant_directive { $$ = $1; } + | empty { $$ = 0; } + ; - /* Ignore if there is a trailing comma in the enum list */ - if ($3) { - Node *leftSibling = Getattr($1,"_last"); - if (!leftSibling) { - leftSibling=$1; - } - set_nextSibling(leftSibling,$3); - Setattr($1,"_last",$3); - } - $$ = $1; - } - | edecl { - $$ = $1; - if ($1) { - Setattr($1,"_last",$1); - } - } - ; +/* Enum lists - any #define macros (constant directives) within the enum list are ignored. Trailing commas accepted. */ +enumlist : enumlist COMMA optional_constant_directive edecl optional_constant_directive { + Node *leftSibling = Getattr($1,"_last"); + set_nextSibling(leftSibling,$4); + Setattr($1,"_last",$4); + $$ = $1; + } + | enumlist COMMA optional_constant_directive { + $$ = $1; + } + | optional_constant_directive edecl optional_constant_directive { + Setattr($2,"_last",$2); + $$ = $2; + } + | optional_constant_directive { + $$ = 0; + } + ; edecl : ID { SwigType *type = NewSwigType(T_INT); @@ -5689,7 +5692,6 @@ edecl : ID { Setattr($$,"value",$1); Delete(type); } - | empty { $$ = 0; } ; etype : expr { From 9be3235988d73cc9445e633105d0146bb3c4acf5 Mon Sep 17 00:00:00 2001 From: Jesus Lopez Date: Mon, 15 Apr 2013 09:31:23 -0700 Subject: [PATCH 0520/1160] Support $descriptor() macro in fragments Closes #36 --- .../python/special_variable_macros_runme.py | 2 ++ Examples/test-suite/special_variable_macros.i | 19 +++++++++++++++++++ Source/Swig/fragment.c | 2 ++ 3 files changed, 23 insertions(+) diff --git a/Examples/test-suite/python/special_variable_macros_runme.py b/Examples/test-suite/python/special_variable_macros_runme.py index 07e60dfa2..eaf9c1858 100644 --- a/Examples/test-suite/python/special_variable_macros_runme.py +++ b/Examples/test-suite/python/special_variable_macros_runme.py @@ -9,6 +9,8 @@ if special_variable_macros.testJill(name) != "jilly": raise "test failed" if special_variable_macros.testMary(name) != "SWIGTYPE_p_NameWrap": raise "test failed" +if special_variable_macros.testJames(name) != "SWIGTYPE_Name": + raise "test failed" if special_variable_macros.testJim(name) != "multiname num": raise "test failed" if special_variable_macros.testJohn(special_variable_macros.PairIntBool(10, False)) != 123: diff --git a/Examples/test-suite/special_variable_macros.i b/Examples/test-suite/special_variable_macros.i index 65f5496eb..ddd068cc0 100644 --- a/Examples/test-suite/special_variable_macros.i +++ b/Examples/test-suite/special_variable_macros.i @@ -62,6 +62,14 @@ private: /*%typemap(in) NameWrap *NAMEWRAP end */ %} +// check $descriptor gets expanded properly when used in a fragment +%fragment("nameDescriptor", "header") +%{ +/*%fragment("getNameDescriptor", "header") start */ +static const char *nameDescriptor = "$descriptor(Name)"; +/*%fragment("getNameDescriptor", "header") end */ +%} + ////////////////////////////////////////////////////////////////////////////////////// @@ -86,6 +94,14 @@ $typemap(in, NameWrap *NAMEWRAP) // %typemap(in) Name *mary end } +%typemap(in, fragment="nameDescriptor") Name *james (Name temp) { + // %typemap(in) Name *james start + temp = Name(nameDescriptor); + (void)$input; + $1 = &temp; + // %typemap(in) Name *james end +} + %inline %{ const char * testFred(Name *fred) { return fred->getName(); @@ -99,6 +115,9 @@ const char * testJill(Name *jill) { const char * testMary(Name *mary) { return mary->getName(); } +const char * testJames(Name *james) { + return james->getName(); +} %} ////////////////////////////////////////////////////////////////////////////////////// diff --git a/Source/Swig/fragment.c b/Source/Swig/fragment.c index 15f701ae4..025994a84 100644 --- a/Source/Swig/fragment.c +++ b/Source/Swig/fragment.c @@ -60,6 +60,8 @@ void Swig_fragment_register(Node *fragment) { } Setfile(ccode, Getfile(fragment)); Setline(ccode, Getline(fragment)); + /* Replace $descriptor() macros */ + Swig_cparse_replace_descriptor(ccode); Setattr(fragments, name, ccode); if (debug) Printf(stdout, "registering fragment %s %s\n", name, section); From 439a353a3686c97fa0b077fad8ce0c06326c1c95 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 18 Apr 2013 23:20:48 +0100 Subject: [PATCH 0521/1160] Document patch #33 from previous commit and complete run time tests --- CHANGES.current | 13 +++++++++++++ .../csharp/special_variable_macros_runme.cs | 2 ++ .../test-suite/d/special_variable_macros_runme.1.d | 4 ++++ .../test-suite/d/special_variable_macros_runme.2.d | 1 + .../test-suite/go/special_variable_macros_runme.go | 3 +++ .../java/special_variable_macros_runme.java | 2 ++ Source/Swig/fragment.c | 1 + 7 files changed, 26 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 4c1e55bc0..5022a3030 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,19 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-04-18: wsfulton + Apply Patch #36 from Jesus Lopez to add support for $descriptor() special variable macro expansion + in fragments. For example: + + %fragment("nameDescriptor", "header") + %{ + static const char *nameDescriptor = "$descriptor(Name)"; + %} + + which will generate into the wrapper if the fragment is used: + + static const char *nameDescriptor = "SWIGTYPE_Name"; + 2013-04-18: wsfulton Fix SF Bug #428 - Syntax error when preprocessor macros are defined inside of enum lists, such as: diff --git a/Examples/test-suite/csharp/special_variable_macros_runme.cs b/Examples/test-suite/csharp/special_variable_macros_runme.cs index bd6fd4b04..1845cd074 100644 --- a/Examples/test-suite/csharp/special_variable_macros_runme.cs +++ b/Examples/test-suite/csharp/special_variable_macros_runme.cs @@ -12,6 +12,8 @@ public class runme { throw new Exception("test failed"); if (special_variable_macros.testMary(name) != "SWIGTYPE_p_NameWrap") throw new Exception("test failed"); + if (special_variable_macros.testJames(name) != "SWIGTYPE_Name") + throw new Exception("test failed"); if (special_variable_macros.testJim(name) != "multiname num") throw new Exception("test failed"); if (special_variable_macros.testJohn(new PairIntBool(10, false)) != 123) diff --git a/Examples/test-suite/d/special_variable_macros_runme.1.d b/Examples/test-suite/d/special_variable_macros_runme.1.d index 12491eef5..eab0331cc 100644 --- a/Examples/test-suite/d/special_variable_macros_runme.1.d +++ b/Examples/test-suite/d/special_variable_macros_runme.1.d @@ -24,6 +24,10 @@ void main() { throw new Exception("test failed"); } + if (testJames(name) != "SWIGTYPE_Name") { + throw new Exception("test failed"); + } + if (testJim(name) != "multiname num") { throw new Exception("test failed"); } diff --git a/Examples/test-suite/d/special_variable_macros_runme.2.d b/Examples/test-suite/d/special_variable_macros_runme.2.d index 128e5870f..0bc4c0cc7 100644 --- a/Examples/test-suite/d/special_variable_macros_runme.2.d +++ b/Examples/test-suite/d/special_variable_macros_runme.2.d @@ -12,6 +12,7 @@ void main() { enforce(testJack(name) == "$specialname"); enforce(testJill(name) == "jilly"); enforce(testMary(name) == "SWIGTYPE_p_NameWrap"); + enforce(testJames(name) == "SWIGTYPE_Name"); enforce(testJim(name) == "multiname num"); enforce(testJohn(new PairIntBool(10, false)) == 123); diff --git a/Examples/test-suite/go/special_variable_macros_runme.go b/Examples/test-suite/go/special_variable_macros_runme.go index d049af606..c4f687ea9 100644 --- a/Examples/test-suite/go/special_variable_macros_runme.go +++ b/Examples/test-suite/go/special_variable_macros_runme.go @@ -16,6 +16,9 @@ func main() { if special_variable_macros.TestMary(name) != "SWIGTYPE_p_NameWrap" { panic("test failed") } + if special_variable_macros.TestJames(name) != "SWIGTYPE_Name" { + panic("test failed") + } if special_variable_macros.TestJim(name) != "multiname num" { panic("test failed") } diff --git a/Examples/test-suite/java/special_variable_macros_runme.java b/Examples/test-suite/java/special_variable_macros_runme.java index d7f8070b3..1cd50e96e 100644 --- a/Examples/test-suite/java/special_variable_macros_runme.java +++ b/Examples/test-suite/java/special_variable_macros_runme.java @@ -22,6 +22,8 @@ public class special_variable_macros_runme { throw new RuntimeException("test failed"); if (!special_variable_macros.testMary(name).equals("SWIGTYPE_p_NameWrap")) throw new RuntimeException("test failed"); + if (!special_variable_macros.testJames(name).equals("SWIGTYPE_Name")) + throw new RuntimeException("test failed"); if (!special_variable_macros.testJim(name).equals("multiname num")) throw new RuntimeException("test failed"); if (special_variable_macros.testJohn(new PairIntBool(10, false)) != 123) diff --git a/Source/Swig/fragment.c b/Source/Swig/fragment.c index 025994a84..927c772b8 100644 --- a/Source/Swig/fragment.c +++ b/Source/Swig/fragment.c @@ -18,6 +18,7 @@ #include "swig.h" #include "swigwarn.h" +#include "cparse.h" static Hash *fragments = 0; static Hash *looking_fragments = 0; From 4bbc881a9fca57574ed8217561289173df1c7e94 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Apr 2013 20:00:06 +0100 Subject: [PATCH 0522/1160] .gitignore tweaks --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 800ac4669..a35ad66c6 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,7 @@ CCache/autom4te.cache/ CCache/config.h.in CCache/configure Source/Include/swigconfig.h.in +Source/Include/swigconfig.h.in~ Source/Makefile.in Tools/config/compile Tools/config/config.guess From 9f9eb66fa4dbe2c32684c532c7875c1b0ae14b6f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Apr 2013 20:05:43 +0100 Subject: [PATCH 0523/1160] Add an examples scratch directory into .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a35ad66c6..877d2b2a9 100644 --- a/.gitignore +++ b/.gitignore @@ -126,3 +126,5 @@ Examples/test-suite/uffi/*/ *_runme.exe.mdb *_runme.exe +# Scratch directories +Examples/scratch From 635a90c91c4eea575b47c6453ccbd501e935cdf6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Apr 2013 20:07:54 +0100 Subject: [PATCH 0524/1160] Add RUNPIPE in makefiles - a generic mechanism for suppressing stdout when running the examples - the idea is to run 'make check-examples' which runs the examples but suppresses the output except for errors. Initial implementation for Java. --- Examples/Makefile.in | 13 ++++++++++++- Makefile.in | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index c234c41ab..535ea55ae 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -46,6 +46,10 @@ LIBPREFIX = RUNTOOL = # COMPILETOOL is a way to run the compiler under another tool, or more commonly just to stop the compiler executing COMPILETOOL= +# RUNPIPE is for piping output of running interpreter/compiled code somewhere, eg RUNPIPE=\>/dev/null +RUNPIPE= + +RUNME = runme # X11 options @@ -543,6 +547,13 @@ java_cpp: $(SRCS) $(CXX) -c $(CCSHARED) $(CFLAGS) $(JAVACFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(JAVA_INCLUDE) $(JAVACXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JAVA_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(JAVA_LIBPREFIX)$(TARGET)$(JAVASO) +# ----------------------------------------------------------------- +# Run java example +# ----------------------------------------------------------------- + +java_run: + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(JAVA) $(RUNME) $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- @@ -556,7 +567,7 @@ java_version: # ----------------------------------------------------------------- java_clean: - rm -f *_wrap* *~ .~* *.class `find . -name \*.java | grep -v runme.java` + rm -f *_wrap* *~ .~* *.class `find . -name \*.java | grep -v $(RUNME).java` rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@JAVASO@ diff --git a/Makefile.in b/Makefile.in index 8a6776bf8..04d65a107 100644 --- a/Makefile.in +++ b/Makefile.in @@ -229,7 +229,7 @@ check-%-examples : # individual example %.actionexample: @echo $(ACTION)ing Examples/$(LANGUAGE)/$* - @(cd Examples/$(LANGUAGE)/$* && $(MAKE) -s $(chk-set-env) $(ACTION)) + @(cd Examples/$(LANGUAGE)/$* && $(MAKE) -s $(chk-set-env) $(ACTION) RUNPIPE=\>/dev/null) # gcj individual example java.actionexample: From 05adcee56f0e6730ab15ca80f010ffe37194c718 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Apr 2013 20:08:49 +0100 Subject: [PATCH 0525/1160] Run java examples during 'make check-examples' --- Examples/Makefile.in | 2 +- Examples/java/callback/Makefile | 9 ++++----- Examples/java/class/Makefile | 9 ++++----- Examples/java/constants/Makefile | 9 ++++----- Examples/java/enum/Makefile | 9 ++++----- Examples/java/extend/Makefile | 9 ++++----- Examples/java/funcptr/Makefile | 9 ++++----- Examples/java/multimap/Makefile | 9 ++++----- Examples/java/native/Makefile | 9 ++++----- Examples/java/pointer/Makefile | 9 ++++----- Examples/java/reference/Makefile | 9 ++++----- Examples/java/simple/Makefile | 9 ++++----- Examples/java/template/Makefile | 9 ++++----- Examples/java/typemap/Makefile | 9 ++++----- Examples/java/variables/Makefile | 9 ++++----- 15 files changed, 57 insertions(+), 71 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 535ea55ae..91aab1c83 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -552,7 +552,7 @@ java_cpp: $(SRCS) # ----------------------------------------------------------------- java_run: - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(JAVA) $(RUNME) $(RUNPIPE) + env LD_LIBRARY_PATH=. $(RUNTOOL) $(JAVA) $(RUNME) $(RUNPIPE) # ----------------------------------------------------------------- # Version display diff --git a/Examples/java/callback/Makefile b/Examples/java/callback/Makefile index 14c301703..c4d4d0e36 100644 --- a/Examples/java/callback/Makefile +++ b/Examples/java/callback/Makefile @@ -5,14 +5,13 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: java +check: build + $(MAKE) -f $(TOP)/Makefile java_run -java:: +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp javac *.java -clean:: +clean: $(MAKE) -f $(TOP)/Makefile java_clean - -check: all diff --git a/Examples/java/class/Makefile b/Examples/java/class/Makefile index 14c301703..c4d4d0e36 100644 --- a/Examples/java/class/Makefile +++ b/Examples/java/class/Makefile @@ -5,14 +5,13 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: java +check: build + $(MAKE) -f $(TOP)/Makefile java_run -java:: +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp javac *.java -clean:: +clean: $(MAKE) -f $(TOP)/Makefile java_clean - -check: all diff --git a/Examples/java/constants/Makefile b/Examples/java/constants/Makefile index 2b3d35c6a..0c7c16349 100644 --- a/Examples/java/constants/Makefile +++ b/Examples/java/constants/Makefile @@ -5,14 +5,13 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: java +check: build + $(MAKE) -f $(TOP)/Makefile java_run -java:: +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp javac *.java -clean:: +clean: $(MAKE) -f $(TOP)/Makefile java_clean - -check: all diff --git a/Examples/java/enum/Makefile b/Examples/java/enum/Makefile index 14c301703..c4d4d0e36 100644 --- a/Examples/java/enum/Makefile +++ b/Examples/java/enum/Makefile @@ -5,14 +5,13 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: java +check: build + $(MAKE) -f $(TOP)/Makefile java_run -java:: +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp javac *.java -clean:: +clean: $(MAKE) -f $(TOP)/Makefile java_clean - -check: all diff --git a/Examples/java/extend/Makefile b/Examples/java/extend/Makefile index 14c301703..c4d4d0e36 100644 --- a/Examples/java/extend/Makefile +++ b/Examples/java/extend/Makefile @@ -5,14 +5,13 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: java +check: build + $(MAKE) -f $(TOP)/Makefile java_run -java:: +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp javac *.java -clean:: +clean: $(MAKE) -f $(TOP)/Makefile java_clean - -check: all diff --git a/Examples/java/funcptr/Makefile b/Examples/java/funcptr/Makefile index 968c92c6c..ce51a1c74 100644 --- a/Examples/java/funcptr/Makefile +++ b/Examples/java/funcptr/Makefile @@ -5,14 +5,13 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: java +check: build + $(MAKE) -f $(TOP)/Makefile java_run -java:: +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java javac *.java -clean:: +clean: $(MAKE) -f $(TOP)/Makefile java_clean - -check: all diff --git a/Examples/java/multimap/Makefile b/Examples/java/multimap/Makefile index 968c92c6c..ce51a1c74 100644 --- a/Examples/java/multimap/Makefile +++ b/Examples/java/multimap/Makefile @@ -5,14 +5,13 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: java +check: build + $(MAKE) -f $(TOP)/Makefile java_run -java:: +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java javac *.java -clean:: +clean: $(MAKE) -f $(TOP)/Makefile java_clean - -check: all diff --git a/Examples/java/native/Makefile b/Examples/java/native/Makefile index 92afbd4d0..39e8f6d7f 100644 --- a/Examples/java/native/Makefile +++ b/Examples/java/native/Makefile @@ -5,14 +5,13 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: java +check: build + $(MAKE) -f $(TOP)/Makefile java_run -java:: +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java javac *.java -clean:: +clean: $(MAKE) -f $(TOP)/Makefile java_clean - -check: all diff --git a/Examples/java/pointer/Makefile b/Examples/java/pointer/Makefile index 968c92c6c..ce51a1c74 100644 --- a/Examples/java/pointer/Makefile +++ b/Examples/java/pointer/Makefile @@ -5,14 +5,13 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: java +check: build + $(MAKE) -f $(TOP)/Makefile java_run -java:: +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java javac *.java -clean:: +clean: $(MAKE) -f $(TOP)/Makefile java_clean - -check: all diff --git a/Examples/java/reference/Makefile b/Examples/java/reference/Makefile index 14c301703..c4d4d0e36 100644 --- a/Examples/java/reference/Makefile +++ b/Examples/java/reference/Makefile @@ -5,14 +5,13 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: java +check: build + $(MAKE) -f $(TOP)/Makefile java_run -java:: +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp javac *.java -clean:: +clean: $(MAKE) -f $(TOP)/Makefile java_clean - -check: all diff --git a/Examples/java/simple/Makefile b/Examples/java/simple/Makefile index 968c92c6c..ce51a1c74 100644 --- a/Examples/java/simple/Makefile +++ b/Examples/java/simple/Makefile @@ -5,14 +5,13 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: java +check: build + $(MAKE) -f $(TOP)/Makefile java_run -java:: +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java javac *.java -clean:: +clean: $(MAKE) -f $(TOP)/Makefile java_clean - -check: all diff --git a/Examples/java/template/Makefile b/Examples/java/template/Makefile index 2b3d35c6a..0c7c16349 100644 --- a/Examples/java/template/Makefile +++ b/Examples/java/template/Makefile @@ -5,14 +5,13 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: java +check: build + $(MAKE) -f $(TOP)/Makefile java_run -java:: +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp javac *.java -clean:: +clean: $(MAKE) -f $(TOP)/Makefile java_clean - -check: all diff --git a/Examples/java/typemap/Makefile b/Examples/java/typemap/Makefile index 92afbd4d0..39e8f6d7f 100644 --- a/Examples/java/typemap/Makefile +++ b/Examples/java/typemap/Makefile @@ -5,14 +5,13 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: java +check: build + $(MAKE) -f $(TOP)/Makefile java_run -java:: +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java javac *.java -clean:: +clean: $(MAKE) -f $(TOP)/Makefile java_clean - -check: all diff --git a/Examples/java/variables/Makefile b/Examples/java/variables/Makefile index 968c92c6c..ce51a1c74 100644 --- a/Examples/java/variables/Makefile +++ b/Examples/java/variables/Makefile @@ -5,14 +5,13 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: java +check: build + $(MAKE) -f $(TOP)/Makefile java_run -java:: +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java javac *.java -clean:: +clean: $(MAKE) -f $(TOP)/Makefile java_clean - -check: all From 8713199267acea20d0fa1fe5841afdb90e8427ab Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Apr 2013 22:22:36 +0100 Subject: [PATCH 0526/1160] Move javac compile for examples into common Makefile for examples --- Examples/Makefile.in | 7 +++++++ Examples/java/callback/Makefile | 3 ++- Examples/java/class/Makefile | 3 ++- Examples/java/constants/Makefile | 3 ++- Examples/java/enum/Makefile | 3 ++- Examples/java/extend/Makefile | 3 ++- Examples/java/funcptr/Makefile | 3 ++- Examples/java/multimap/Makefile | 3 ++- Examples/java/native/Makefile | 3 ++- Examples/java/pointer/Makefile | 3 ++- Examples/java/reference/Makefile | 3 ++- Examples/java/simple/Makefile | 3 ++- Examples/java/template/Makefile | 3 ++- Examples/java/typemap/Makefile | 3 ++- Examples/java/variables/Makefile | 3 ++- 15 files changed, 35 insertions(+), 14 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 91aab1c83..24e1e6a5e 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -547,6 +547,13 @@ java_cpp: $(SRCS) $(CXX) -c $(CCSHARED) $(CFLAGS) $(JAVACFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(JAVA_INCLUDE) $(JAVACXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JAVA_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(JAVA_LIBPREFIX)$(TARGET)$(JAVASO) +# ---------------------------------------------------------------- +# Compile java files +# ---------------------------------------------------------------- + +java_compile: $(SRCS) + $(COMPILETOOL) $(JAVAC) $(JAVACFLAGS) $(JAVASRCS) + # ----------------------------------------------------------------- # Run java example # ----------------------------------------------------------------- diff --git a/Examples/java/callback/Makefile b/Examples/java/callback/Makefile index c4d4d0e36..8f274e7cb 100644 --- a/Examples/java/callback/Makefile +++ b/Examples/java/callback/Makefile @@ -4,6 +4,7 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i SWIGOPT = +JAVASRCS = *.java check: build $(MAKE) -f $(TOP)/Makefile java_run @@ -11,7 +12,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - javac *.java + $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: $(MAKE) -f $(TOP)/Makefile java_clean diff --git a/Examples/java/class/Makefile b/Examples/java/class/Makefile index c4d4d0e36..8f274e7cb 100644 --- a/Examples/java/class/Makefile +++ b/Examples/java/class/Makefile @@ -4,6 +4,7 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i SWIGOPT = +JAVASRCS = *.java check: build $(MAKE) -f $(TOP)/Makefile java_run @@ -11,7 +12,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - javac *.java + $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: $(MAKE) -f $(TOP)/Makefile java_clean diff --git a/Examples/java/constants/Makefile b/Examples/java/constants/Makefile index 0c7c16349..97c5b673c 100644 --- a/Examples/java/constants/Makefile +++ b/Examples/java/constants/Makefile @@ -4,6 +4,7 @@ CXXSRCS = TARGET = example INTERFACE = example.i SWIGOPT = +JAVASRCS = *.java check: build $(MAKE) -f $(TOP)/Makefile java_run @@ -11,7 +12,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - javac *.java + $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: $(MAKE) -f $(TOP)/Makefile java_clean diff --git a/Examples/java/enum/Makefile b/Examples/java/enum/Makefile index c4d4d0e36..8f274e7cb 100644 --- a/Examples/java/enum/Makefile +++ b/Examples/java/enum/Makefile @@ -4,6 +4,7 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i SWIGOPT = +JAVASRCS = *.java check: build $(MAKE) -f $(TOP)/Makefile java_run @@ -11,7 +12,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - javac *.java + $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: $(MAKE) -f $(TOP)/Makefile java_clean diff --git a/Examples/java/extend/Makefile b/Examples/java/extend/Makefile index c4d4d0e36..8f274e7cb 100644 --- a/Examples/java/extend/Makefile +++ b/Examples/java/extend/Makefile @@ -4,6 +4,7 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i SWIGOPT = +JAVASRCS = *.java check: build $(MAKE) -f $(TOP)/Makefile java_run @@ -11,7 +12,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - javac *.java + $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: $(MAKE) -f $(TOP)/Makefile java_clean diff --git a/Examples/java/funcptr/Makefile b/Examples/java/funcptr/Makefile index ce51a1c74..e9e29f3a3 100644 --- a/Examples/java/funcptr/Makefile +++ b/Examples/java/funcptr/Makefile @@ -4,6 +4,7 @@ SRCS = example.c TARGET = example INTERFACE = example.i SWIGOPT = +JAVASRCS = *.java check: build $(MAKE) -f $(TOP)/Makefile java_run @@ -11,7 +12,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - javac *.java + $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: $(MAKE) -f $(TOP)/Makefile java_clean diff --git a/Examples/java/multimap/Makefile b/Examples/java/multimap/Makefile index ce51a1c74..e9e29f3a3 100644 --- a/Examples/java/multimap/Makefile +++ b/Examples/java/multimap/Makefile @@ -4,6 +4,7 @@ SRCS = example.c TARGET = example INTERFACE = example.i SWIGOPT = +JAVASRCS = *.java check: build $(MAKE) -f $(TOP)/Makefile java_run @@ -11,7 +12,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - javac *.java + $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: $(MAKE) -f $(TOP)/Makefile java_clean diff --git a/Examples/java/native/Makefile b/Examples/java/native/Makefile index 39e8f6d7f..29d5a082a 100644 --- a/Examples/java/native/Makefile +++ b/Examples/java/native/Makefile @@ -4,6 +4,7 @@ SRCS = TARGET = example INTERFACE = example.i SWIGOPT = +JAVASRCS = *.java check: build $(MAKE) -f $(TOP)/Makefile java_run @@ -11,7 +12,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - javac *.java + $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: $(MAKE) -f $(TOP)/Makefile java_clean diff --git a/Examples/java/pointer/Makefile b/Examples/java/pointer/Makefile index ce51a1c74..e9e29f3a3 100644 --- a/Examples/java/pointer/Makefile +++ b/Examples/java/pointer/Makefile @@ -4,6 +4,7 @@ SRCS = example.c TARGET = example INTERFACE = example.i SWIGOPT = +JAVASRCS = *.java check: build $(MAKE) -f $(TOP)/Makefile java_run @@ -11,7 +12,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - javac *.java + $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: $(MAKE) -f $(TOP)/Makefile java_clean diff --git a/Examples/java/reference/Makefile b/Examples/java/reference/Makefile index c4d4d0e36..8f274e7cb 100644 --- a/Examples/java/reference/Makefile +++ b/Examples/java/reference/Makefile @@ -4,6 +4,7 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i SWIGOPT = +JAVASRCS = *.java check: build $(MAKE) -f $(TOP)/Makefile java_run @@ -11,7 +12,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - javac *.java + $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: $(MAKE) -f $(TOP)/Makefile java_clean diff --git a/Examples/java/simple/Makefile b/Examples/java/simple/Makefile index ce51a1c74..e9e29f3a3 100644 --- a/Examples/java/simple/Makefile +++ b/Examples/java/simple/Makefile @@ -4,6 +4,7 @@ SRCS = example.c TARGET = example INTERFACE = example.i SWIGOPT = +JAVASRCS = *.java check: build $(MAKE) -f $(TOP)/Makefile java_run @@ -11,7 +12,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - javac *.java + $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: $(MAKE) -f $(TOP)/Makefile java_clean diff --git a/Examples/java/template/Makefile b/Examples/java/template/Makefile index 0c7c16349..97c5b673c 100644 --- a/Examples/java/template/Makefile +++ b/Examples/java/template/Makefile @@ -4,6 +4,7 @@ CXXSRCS = TARGET = example INTERFACE = example.i SWIGOPT = +JAVASRCS = *.java check: build $(MAKE) -f $(TOP)/Makefile java_run @@ -11,7 +12,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - javac *.java + $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: $(MAKE) -f $(TOP)/Makefile java_clean diff --git a/Examples/java/typemap/Makefile b/Examples/java/typemap/Makefile index 39e8f6d7f..29d5a082a 100644 --- a/Examples/java/typemap/Makefile +++ b/Examples/java/typemap/Makefile @@ -4,6 +4,7 @@ SRCS = TARGET = example INTERFACE = example.i SWIGOPT = +JAVASRCS = *.java check: build $(MAKE) -f $(TOP)/Makefile java_run @@ -11,7 +12,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - javac *.java + $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: $(MAKE) -f $(TOP)/Makefile java_clean diff --git a/Examples/java/variables/Makefile b/Examples/java/variables/Makefile index ce51a1c74..e9e29f3a3 100644 --- a/Examples/java/variables/Makefile +++ b/Examples/java/variables/Makefile @@ -4,6 +4,7 @@ SRCS = example.c TARGET = example INTERFACE = example.i SWIGOPT = +JAVASRCS = *.java check: build $(MAKE) -f $(TOP)/Makefile java_run @@ -11,7 +12,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - javac *.java + $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: $(MAKE) -f $(TOP)/Makefile java_clean From 760c398c49c692d956fa307941722fa072919968 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Apr 2013 20:22:12 +0100 Subject: [PATCH 0527/1160] Run csharp examples during 'make check-examples' --- Examples/Makefile.in | 8 ++++++++ Examples/csharp/arrays/Makefile | 9 ++++----- Examples/csharp/callback/Makefile | 9 ++++----- Examples/csharp/class/Makefile | 9 ++++----- Examples/csharp/enum/Makefile | 9 ++++----- Examples/csharp/extend/Makefile | 9 ++++----- Examples/csharp/funcptr/Makefile | 9 ++++----- Examples/csharp/reference/Makefile | 9 ++++----- Examples/csharp/simple/Makefile | 9 ++++----- Examples/csharp/template/Makefile | 9 ++++----- Examples/csharp/variables/Makefile | 9 ++++----- 11 files changed, 48 insertions(+), 50 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 24e1e6a5e..b5824eb43 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1105,6 +1105,7 @@ CSHARPCOMPILER = @CSHARPCOMPILER@ CSHARPCILINTERPRETER = @CSHARPCILINTERPRETER@ CSHARPCFLAGS = @CSHARPCFLAGS@ CSHARPSO = @CSHARPSO@ +CSHARP_RUNME = ./$(RUNME).exe # ---------------------------------------------------------------- # Build a CSharp dynamically loadable module (C) @@ -1131,6 +1132,13 @@ csharp_cpp: $(SRCS) csharp_compile: $(SRCS) $(COMPILETOOL) $(CSHARPCOMPILER) $(CSHARPFLAGS) $(CSHARPSRCS) +# ----------------------------------------------------------------- +# Run CSharp example +# ----------------------------------------------------------------- + +csharp_run: + env LD_LIBRARY_PATH=. $(RUNTOOL) $(CSHARP_RUNME) $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- diff --git a/Examples/csharp/arrays/Makefile b/Examples/csharp/arrays/Makefile index b3446d895..65386f0dc 100644 --- a/Examples/csharp/arrays/Makefile +++ b/Examples/csharp/arrays/Makefile @@ -7,14 +7,13 @@ SWIGOPT = CSHARPSRCS = *.cs CSHARPFLAGS= -nologo -unsafe -out:runme.exe -all:: csharp +check: build + $(MAKE) -f $(TOP)/Makefile csharp_run -csharp:: +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile -clean:: +clean: $(MAKE) -f $(TOP)/Makefile csharp_clean - -check: all diff --git a/Examples/csharp/callback/Makefile b/Examples/csharp/callback/Makefile index 51b163b85..340febc88 100644 --- a/Examples/csharp/callback/Makefile +++ b/Examples/csharp/callback/Makefile @@ -7,14 +7,13 @@ SWIGOPT = CSHARPSRCS = *.cs CSHARPFLAGS= -debug -nologo -out:runme.exe -all:: csharp +check: build + $(MAKE) -f $(TOP)/Makefile csharp_run -csharp:: +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile -clean:: +clean: $(MAKE) -f $(TOP)/Makefile csharp_clean - -check: all diff --git a/Examples/csharp/class/Makefile b/Examples/csharp/class/Makefile index 20f0dd5bb..bc3ce8ce8 100644 --- a/Examples/csharp/class/Makefile +++ b/Examples/csharp/class/Makefile @@ -7,14 +7,13 @@ SWIGOPT = CSHARPSRCS = *.cs CSHARPFLAGS= -nologo -out:runme.exe -all:: csharp +check: build + $(MAKE) -f $(TOP)/Makefile csharp_run -csharp:: +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile -clean:: +clean: $(MAKE) -f $(TOP)/Makefile csharp_clean - -check: all diff --git a/Examples/csharp/enum/Makefile b/Examples/csharp/enum/Makefile index 20f0dd5bb..bc3ce8ce8 100644 --- a/Examples/csharp/enum/Makefile +++ b/Examples/csharp/enum/Makefile @@ -7,14 +7,13 @@ SWIGOPT = CSHARPSRCS = *.cs CSHARPFLAGS= -nologo -out:runme.exe -all:: csharp +check: build + $(MAKE) -f $(TOP)/Makefile csharp_run -csharp:: +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile -clean:: +clean: $(MAKE) -f $(TOP)/Makefile csharp_clean - -check: all diff --git a/Examples/csharp/extend/Makefile b/Examples/csharp/extend/Makefile index 20f0dd5bb..bc3ce8ce8 100644 --- a/Examples/csharp/extend/Makefile +++ b/Examples/csharp/extend/Makefile @@ -7,14 +7,13 @@ SWIGOPT = CSHARPSRCS = *.cs CSHARPFLAGS= -nologo -out:runme.exe -all:: csharp +check: build + $(MAKE) -f $(TOP)/Makefile csharp_run -csharp:: +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile -clean:: +clean: $(MAKE) -f $(TOP)/Makefile csharp_clean - -check: all diff --git a/Examples/csharp/funcptr/Makefile b/Examples/csharp/funcptr/Makefile index 223300497..875ae0e71 100644 --- a/Examples/csharp/funcptr/Makefile +++ b/Examples/csharp/funcptr/Makefile @@ -7,14 +7,13 @@ SWIGOPT = CSHARPSRCS = *.cs CSHARPFLAGS= -nologo -out:runme.exe -all:: csharp +check: build + $(MAKE) -f $(TOP)/Makefile csharp_run -csharp:: +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile -clean:: +clean: $(MAKE) -f $(TOP)/Makefile csharp_clean - -check: all diff --git a/Examples/csharp/reference/Makefile b/Examples/csharp/reference/Makefile index 20f0dd5bb..bc3ce8ce8 100644 --- a/Examples/csharp/reference/Makefile +++ b/Examples/csharp/reference/Makefile @@ -7,14 +7,13 @@ SWIGOPT = CSHARPSRCS = *.cs CSHARPFLAGS= -nologo -out:runme.exe -all:: csharp +check: build + $(MAKE) -f $(TOP)/Makefile csharp_run -csharp:: +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile -clean:: +clean: $(MAKE) -f $(TOP)/Makefile csharp_clean - -check: all diff --git a/Examples/csharp/simple/Makefile b/Examples/csharp/simple/Makefile index 223300497..875ae0e71 100644 --- a/Examples/csharp/simple/Makefile +++ b/Examples/csharp/simple/Makefile @@ -7,14 +7,13 @@ SWIGOPT = CSHARPSRCS = *.cs CSHARPFLAGS= -nologo -out:runme.exe -all:: csharp +check: build + $(MAKE) -f $(TOP)/Makefile csharp_run -csharp:: +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile -clean:: +clean: $(MAKE) -f $(TOP)/Makefile csharp_clean - -check: all diff --git a/Examples/csharp/template/Makefile b/Examples/csharp/template/Makefile index 3f3bbe6dd..43243d6d5 100644 --- a/Examples/csharp/template/Makefile +++ b/Examples/csharp/template/Makefile @@ -7,14 +7,13 @@ SWIGOPT = CSHARPSRCS = *.cs CSHARPFLAGS= -nologo -out:runme.exe -all:: csharp +check: build + $(MAKE) -f $(TOP)/Makefile csharp_run -csharp:: +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile -clean:: +clean: $(MAKE) -f $(TOP)/Makefile csharp_clean - -check: all diff --git a/Examples/csharp/variables/Makefile b/Examples/csharp/variables/Makefile index 223300497..875ae0e71 100644 --- a/Examples/csharp/variables/Makefile +++ b/Examples/csharp/variables/Makefile @@ -7,14 +7,13 @@ SWIGOPT = CSHARPSRCS = *.cs CSHARPFLAGS= -nologo -out:runme.exe -all:: csharp +check: build + $(MAKE) -f $(TOP)/Makefile csharp_run -csharp:: +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile -clean:: +clean: $(MAKE) -f $(TOP)/Makefile csharp_clean - -check: all From 6acfda55d1e427e3c391122fa2a0fe92e464eccc Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Apr 2013 00:11:39 +0100 Subject: [PATCH 0528/1160] Go examples makefiles clean target fixed and use RUNPIPE and tidyup --- Examples/Makefile.in | 4 ++-- Examples/go/callback/Makefile | 12 +++++------- Examples/go/class/Makefile | 12 ++++++------ Examples/go/constants/Makefile | 12 ++++++------ Examples/go/enum/Makefile | 12 +++++------- Examples/go/extend/Makefile | 12 +++++------- Examples/go/funcptr/Makefile | 12 +++++------- Examples/go/multimap/Makefile | 12 +++++------- Examples/go/pointer/Makefile | 12 +++++------- Examples/go/reference/Makefile | 12 +++++------- Examples/go/simple/Makefile | 12 ++++++------ Examples/go/template/Makefile | 12 +++++------- Examples/go/variables/Makefile | 12 +++++------- 13 files changed, 65 insertions(+), 83 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index b5824eb43..581e17027 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1462,7 +1462,7 @@ go_run: runme.go else \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o runme runme.$(GOOBJEXT); \ fi - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme $(RUNPIPE) # ----------------------------------------------------------------- # Version display @@ -1476,7 +1476,7 @@ go_version: # ----------------------------------------------------------------- go_clean: - rm -f *_wrap* *_gc* .~* runme + rm -f *_wrap* *_gc* .~* runme $(GOSRCS) rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *.[568] *.a *@SO@ diff --git a/Examples/go/callback/Makefile b/Examples/go/callback/Makefile index 9dc8b8851..7489f87dc 100644 --- a/Examples/go/callback/Makefile +++ b/Examples/go/callback/Makefile @@ -5,14 +5,12 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: go +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run -go:: +build: $(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 +clean: + $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/class/Makefile b/Examples/go/class/Makefile index 53d31d1a4..a099654f1 100644 --- a/Examples/go/class/Makefile +++ b/Examples/go/class/Makefile @@ -5,12 +5,12 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + +build: $(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 +clean: + $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/constants/Makefile b/Examples/go/constants/Makefile index 71d4d73a4..b45feb963 100644 --- a/Examples/go/constants/Makefile +++ b/Examples/go/constants/Makefile @@ -5,12 +5,12 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + +build: $(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 +clean: + $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/enum/Makefile b/Examples/go/enum/Makefile index 9dc8b8851..7489f87dc 100644 --- a/Examples/go/enum/Makefile +++ b/Examples/go/enum/Makefile @@ -5,14 +5,12 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: go +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run -go:: +build: $(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 +clean: + $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/extend/Makefile b/Examples/go/extend/Makefile index 9dc8b8851..7489f87dc 100644 --- a/Examples/go/extend/Makefile +++ b/Examples/go/extend/Makefile @@ -5,14 +5,12 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: go +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run -go:: +build: $(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 +clean: + $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/funcptr/Makefile b/Examples/go/funcptr/Makefile index b0aa9c970..452ea2118 100644 --- a/Examples/go/funcptr/Makefile +++ b/Examples/go/funcptr/Makefile @@ -5,14 +5,12 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: go +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run -go:: +build: $(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 +clean: + $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/multimap/Makefile b/Examples/go/multimap/Makefile index b0aa9c970..452ea2118 100644 --- a/Examples/go/multimap/Makefile +++ b/Examples/go/multimap/Makefile @@ -5,14 +5,12 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: go +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run -go:: +build: $(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 +clean: + $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/pointer/Makefile b/Examples/go/pointer/Makefile index b0aa9c970..452ea2118 100644 --- a/Examples/go/pointer/Makefile +++ b/Examples/go/pointer/Makefile @@ -5,14 +5,12 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: go +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run -go:: +build: $(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 +clean: + $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/reference/Makefile b/Examples/go/reference/Makefile index 9dc8b8851..7489f87dc 100644 --- a/Examples/go/reference/Makefile +++ b/Examples/go/reference/Makefile @@ -5,14 +5,12 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: go +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run -go:: +build: $(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 +clean: + $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/simple/Makefile b/Examples/go/simple/Makefile index e67fa8bb6..75f81bffe 100644 --- a/Examples/go/simple/Makefile +++ b/Examples/go/simple/Makefile @@ -4,12 +4,12 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + +build: $(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 +clean: + $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/template/Makefile b/Examples/go/template/Makefile index b9278b53e..9ee030479 100644 --- a/Examples/go/template/Makefile +++ b/Examples/go/template/Makefile @@ -5,14 +5,12 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: go +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run -go:: +build: $(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 +clean: + $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/variables/Makefile b/Examples/go/variables/Makefile index b0aa9c970..452ea2118 100644 --- a/Examples/go/variables/Makefile +++ b/Examples/go/variables/Makefile @@ -5,14 +5,12 @@ TARGET = example INTERFACE = example.i SWIGOPT = -all:: go +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run -go:: +build: $(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 +clean: + $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean From 14a89fac86129a1d876cdc253d82046ea6fd1a0a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Apr 2013 00:28:26 +0100 Subject: [PATCH 0529/1160] Octave examples clean target fixed and makefiles use new RUNPIPE and general consistency tidyup --- Examples/Makefile.in | 10 +++++----- Examples/octave/callback/Makefile | 13 ++++++------- Examples/octave/class/Makefile | 13 ++++++------- Examples/octave/constants/Makefile | 13 ++++++------- Examples/octave/contract/Makefile | 13 ++++++------- Examples/octave/enum/Makefile | 13 ++++++------- Examples/octave/extend/Makefile | 13 ++++++------- Examples/octave/funcptr/Makefile | 13 ++++++------- Examples/octave/funcptr2/Makefile | 13 ++++++------- Examples/octave/functor/Makefile | 13 ++++++------- Examples/octave/module_load/Makefile | 12 ++++++------ Examples/octave/operator/Makefile | 13 ++++++------- Examples/octave/pointer/Makefile | 13 ++++++------- Examples/octave/reference/Makefile | 13 ++++++------- Examples/octave/simple/Makefile | 13 ++++++------- Examples/octave/template/Makefile | 13 ++++++------- Examples/octave/variables/Makefile | 13 ++++++------- 17 files changed, 101 insertions(+), 116 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 581e17027..f0659dc56 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -366,6 +366,8 @@ OCTAVE_CXX = $(DEFS) @OCTAVE_CPPFLAGS@ @OCTAVE_CXXFLAGS@ OCTAVE_DLNK = @OCTAVE_LDFLAGS@ OCTAVE_SO = @OCTAVE_SO@ +OCTAVE_SCRIPT = $(RUNME).m + # ---------------------------------------------------------------- # Build a C dynamically loadable module # Note: Octave requires C++ compiler when compiling C wrappers @@ -390,10 +392,8 @@ octave_cpp: $(SRCS) # Running an Octave example # ----------------------------------------------------------------- -OCTSCRIPT = runme.m - -octave_run: $(OCTSCRIPT) - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH OCTAVE_PATH=$(srcdir):$$OCTAVE_PATH $(OCTAVE) $(OCTSCRIPT) >/dev/null +octave_run: + $(RUNTOOL) $(OCTAVE) $(OCTAVE_SCRIPT) $(RUNPIPE) # ----------------------------------------------------------------- # Version display @@ -403,7 +403,7 @@ octave_version: $(OCTAVE) --version | grep -i version # ----------------------------------------------------------------- -# Cleaning the octave examples +# Cleaning the Octave examples # ----------------------------------------------------------------- octave_clean: diff --git a/Examples/octave/callback/Makefile b/Examples/octave/callback/Makefile index 21fb21137..ffc60e0c0 100644 --- a/Examples/octave/callback/Makefile +++ b/Examples/octave/callback/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/class/Makefile b/Examples/octave/class/Makefile index 21fb21137..ffc60e0c0 100644 --- a/Examples/octave/class/Makefile +++ b/Examples/octave/class/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/constants/Makefile b/Examples/octave/constants/Makefile index 3156eae84..60b0578c6 100644 --- a/Examples/octave/constants/Makefile +++ b/Examples/octave/constants/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/contract/Makefile b/Examples/octave/contract/Makefile index 464b74122..2c33cd3d8 100644 --- a/Examples/octave/contract/Makefile +++ b/Examples/octave/contract/Makefile @@ -4,17 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/enum/Makefile b/Examples/octave/enum/Makefile index 21fb21137..ffc60e0c0 100644 --- a/Examples/octave/enum/Makefile +++ b/Examples/octave/enum/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/extend/Makefile b/Examples/octave/extend/Makefile index 21fb21137..ffc60e0c0 100644 --- a/Examples/octave/extend/Makefile +++ b/Examples/octave/extend/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/funcptr/Makefile b/Examples/octave/funcptr/Makefile index 464b74122..2c33cd3d8 100644 --- a/Examples/octave/funcptr/Makefile +++ b/Examples/octave/funcptr/Makefile @@ -4,17 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/funcptr2/Makefile b/Examples/octave/funcptr2/Makefile index 464b74122..2c33cd3d8 100644 --- a/Examples/octave/funcptr2/Makefile +++ b/Examples/octave/funcptr2/Makefile @@ -4,17 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/functor/Makefile b/Examples/octave/functor/Makefile index 8f6dfc73e..09c680b4e 100644 --- a/Examples/octave/functor/Makefile +++ b/Examples/octave/functor/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/module_load/Makefile b/Examples/octave/module_load/Makefile index da2c704e0..bead6f150 100644 --- a/Examples/octave/module_load/Makefile +++ b/Examples/octave/module_load/Makefile @@ -4,19 +4,19 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' SWIGOPT='-module $$(TARGET)' INTERFACE='$(INTERFACE)' octave $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)2' SWIGOPT='-module $$(TARGET) -globals .' INTERFACE='$(INTERFACE)' octave -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean rm -f $(TARGET).m - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/operator/Makefile b/Examples/octave/operator/Makefile index de818a41a..09c680b4e 100644 --- a/Examples/octave/operator/Makefile +++ b/Examples/octave/operator/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).m - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/pointer/Makefile b/Examples/octave/pointer/Makefile index 464b74122..2c33cd3d8 100644 --- a/Examples/octave/pointer/Makefile +++ b/Examples/octave/pointer/Makefile @@ -4,17 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/reference/Makefile b/Examples/octave/reference/Makefile index 21fb21137..ffc60e0c0 100644 --- a/Examples/octave/reference/Makefile +++ b/Examples/octave/reference/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/simple/Makefile b/Examples/octave/simple/Makefile index 464b74122..2c33cd3d8 100644 --- a/Examples/octave/simple/Makefile +++ b/Examples/octave/simple/Makefile @@ -4,17 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/template/Makefile b/Examples/octave/template/Makefile index d64487430..527e3cec6 100644 --- a/Examples/octave/template/Makefile +++ b/Examples/octave/template/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/variables/Makefile b/Examples/octave/variables/Makefile index 464b74122..2c33cd3d8 100644 --- a/Examples/octave/variables/Makefile +++ b/Examples/octave/variables/Makefile @@ -4,17 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile octave_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile octave_run From 92ffedceb50188d309dfc9587dc0f83b31020209 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Apr 2013 00:50:19 +0100 Subject: [PATCH 0530/1160] Perl examples makefiles clean target fixed and use RUNPIPE and tidyup --- Examples/Makefile.in | 11 +++++++++-- Examples/perl5/class/Makefile | 11 ++++++----- Examples/perl5/constants/Makefile | 12 +++++++----- Examples/perl5/constants2/Makefile | 12 +++++++----- Examples/perl5/funcptr/Makefile | 12 +++++++----- Examples/perl5/import/Makefile | 10 +++++----- Examples/perl5/inline/Makefile | 7 +++---- Examples/perl5/java/Makefile | 14 +++++--------- Examples/perl5/multimap/Makefile | 12 +++++++----- Examples/perl5/multiple_inheritance/Makefile | 11 ++++++----- Examples/perl5/pointer/Makefile | 12 +++++++----- Examples/perl5/reference/Makefile | 11 ++++++----- Examples/perl5/simple/Makefile | 12 +++++++----- Examples/perl5/value/Makefile | 12 +++++++----- Examples/perl5/variables/Makefile | 12 +++++++----- Examples/perl5/xmlstring/Makefile | 15 ++++++--------- 16 files changed, 102 insertions(+), 84 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index f0659dc56..07b375e66 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -189,6 +189,8 @@ PERL5_INCLUDE= @PERL5EXT@ PERL5_DLNK = @PERL5DYNAMICLINKING@ PERL5_CCFLAGS = @PERL5CCFLAGS@ PERL = @PERL@ +PERL5_LIB = -L$(PERL5_INCLUDE) -l@PERL5LIB@ @LIBS@ $(SYSLIBS) +PERL5_SCRIPT = $(RUNME).pl # ---------------------------------------------------------------- # Build a Perl5 dynamically loadable module (C) @@ -219,8 +221,6 @@ perl5_xs: $(SRCS) # Build a statically linked Perl5 executable # ---------------------------------------------------------------- -PERL5_LIB = -L$(PERL5_INCLUDE) -l@PERL5LIB@ @LIBS@ $(SYSLIBS) - perl5_static: $(SRCS) $(SWIG) -perl5 -static -lperlmain.i $(SWIGOPT) $(INTERFACEPATH) $(CC) $(CFLAGS) -Dbool=char $(SRCS) $(ISRCS) $(INCLUDES) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET) @@ -229,6 +229,13 @@ perl5_static_cpp: $(SRCS) $(SWIG) -perl5 -c++ -static -lperlmain.i $(SWIGOPT) $(INTERFACEPATH) $(CXX) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET) +# ----------------------------------------------------------------- +# Running a Perl5 example +# ----------------------------------------------------------------- + +perl5_run: + $(RUNTOOL) $(PERL) $(PERL5_SCRIPT) $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- diff --git a/Examples/perl5/class/Makefile b/Examples/perl5/class/Makefile index f53361730..544d13642 100644 --- a/Examples/perl5/class/Makefile +++ b/Examples/perl5/class/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile perl5_clean - -check: all diff --git a/Examples/perl5/constants/Makefile b/Examples/perl5/constants/Makefile index 576d2a095..899282913 100644 --- a/Examples/perl5/constants/Makefile +++ b/Examples/perl5/constants/Makefile @@ -4,15 +4,17 @@ SRCS = TARGET = example INTERFACE = example.i SWIGOPT = -all:: + +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile perl5_clean - -check: all diff --git a/Examples/perl5/constants2/Makefile b/Examples/perl5/constants2/Makefile index 4ba4b2544..2ed10d733 100644 --- a/Examples/perl5/constants2/Makefile +++ b/Examples/perl5/constants2/Makefile @@ -4,15 +4,17 @@ SRCS = TARGET = example INTERFACE = example.i SWIGOPT = -const -all:: + +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile perl5_clean - -check: all diff --git a/Examples/perl5/funcptr/Makefile b/Examples/perl5/funcptr/Makefile index ce2bbb5b9..c4d100020 100644 --- a/Examples/perl5/funcptr/Makefile +++ b/Examples/perl5/funcptr/Makefile @@ -4,15 +4,17 @@ SRCS = example.c TARGET = example INTERFACE = example.i SWIGOPT = -all:: + +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile perl5_clean - -check: all diff --git a/Examples/perl5/import/Makefile b/Examples/perl5/import/Makefile index 60dfdfcee..baa8277fd 100644 --- a/Examples/perl5/import/Makefile +++ b/Examples/perl5/import/Makefile @@ -3,7 +3,10 @@ SWIG = $(TOP)/../preinst-swig SWIGOPT = LIBS = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='baseclass' INTERFACE='base.i' perl5_cpp $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ @@ -13,8 +16,5 @@ all:: $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' perl5_cpp - -clean:: +clean: $(MAKE) -f $(TOP)/Makefile perl5_clean - -check: all diff --git a/Examples/perl5/inline/Makefile b/Examples/perl5/inline/Makefile index 4ac085ec3..d544a6532 100644 --- a/Examples/perl5/inline/Makefile +++ b/Examples/perl5/inline/Makefile @@ -1,7 +1,6 @@ -all: - run: - perl runme.pl + $(MAKE) -f $(TOP)/Makefile perl5_run clean: - rm -fr _Inline *~ + $(MAKE) -f $(TOP)/Makefile perl5_clean + rm -rf _Inline diff --git a/Examples/perl5/java/Makefile b/Examples/perl5/java/Makefile index 882eba70f..b007cfdbb 100644 --- a/Examples/perl5/java/Makefile +++ b/Examples/perl5/java/Makefile @@ -5,22 +5,18 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: Example.class +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: Example.class $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CXX="gcj" \ CXXSHARED="gcj -fpic -shared Example.class" PERL5_CCFLAGS='' PERL5_EXP='' LIBS="-lstdc++" perl5_cpp - -clean:: +clean: $(MAKE) -f $(TOP)/Makefile perl5_clean rm -f *.class Example.h -check: all - -run: - perl runme.pl - Example.class: Example.java gcj -fPIC -C -c -g Example.java gcjh Example - diff --git a/Examples/perl5/multimap/Makefile b/Examples/perl5/multimap/Makefile index ce2bbb5b9..c4d100020 100644 --- a/Examples/perl5/multimap/Makefile +++ b/Examples/perl5/multimap/Makefile @@ -4,15 +4,17 @@ SRCS = example.c TARGET = example INTERFACE = example.i SWIGOPT = -all:: + +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile perl5_clean - -check: all diff --git a/Examples/perl5/multiple_inheritance/Makefile b/Examples/perl5/multiple_inheritance/Makefile index fcca38473..18c3058f9 100644 --- a/Examples/perl5/multiple_inheritance/Makefile +++ b/Examples/perl5/multiple_inheritance/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile perl5_clean - -check: all diff --git a/Examples/perl5/pointer/Makefile b/Examples/perl5/pointer/Makefile index ce2bbb5b9..c4d100020 100644 --- a/Examples/perl5/pointer/Makefile +++ b/Examples/perl5/pointer/Makefile @@ -4,15 +4,17 @@ SRCS = example.c TARGET = example INTERFACE = example.i SWIGOPT = -all:: + +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile perl5_clean - -check: all diff --git a/Examples/perl5/reference/Makefile b/Examples/perl5/reference/Makefile index 4a804258b..d33dd89fe 100644 --- a/Examples/perl5/reference/Makefile +++ b/Examples/perl5/reference/Makefile @@ -6,15 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -noproxy -all:: +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' SWIGOPT='$(SWIGOPT)' perl5_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' SWIGOPT='$(SWIGOPT)' perl5_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile perl5_clean - -check: all diff --git a/Examples/perl5/simple/Makefile b/Examples/perl5/simple/Makefile index ce2bbb5b9..c4d100020 100644 --- a/Examples/perl5/simple/Makefile +++ b/Examples/perl5/simple/Makefile @@ -4,15 +4,17 @@ SRCS = example.c TARGET = example INTERFACE = example.i SWIGOPT = -all:: + +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile perl5_clean - -check: all diff --git a/Examples/perl5/value/Makefile b/Examples/perl5/value/Makefile index ce2bbb5b9..c4d100020 100644 --- a/Examples/perl5/value/Makefile +++ b/Examples/perl5/value/Makefile @@ -4,15 +4,17 @@ SRCS = example.c TARGET = example INTERFACE = example.i SWIGOPT = -all:: + +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile perl5_clean - -check: all diff --git a/Examples/perl5/variables/Makefile b/Examples/perl5/variables/Makefile index ce2bbb5b9..c4d100020 100644 --- a/Examples/perl5/variables/Makefile +++ b/Examples/perl5/variables/Makefile @@ -4,15 +4,17 @@ SRCS = example.c TARGET = example INTERFACE = example.i SWIGOPT = -all:: + +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile perl5_clean - -check: all diff --git a/Examples/perl5/xmlstring/Makefile b/Examples/perl5/xmlstring/Makefile index 36143fc3a..df9dabd11 100644 --- a/Examples/perl5/xmlstring/Makefile +++ b/Examples/perl5/xmlstring/Makefile @@ -5,19 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lxerces-c -lxerces-depdom -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' LIBS=$(LIBS) CXX="g++ -g3" perl5_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile perl5_clean - -check: all - - -run: - perl runme.pl From 0fa791d1ea9e79d54e9e934e5527876221104b52 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Apr 2013 01:12:36 +0100 Subject: [PATCH 0531/1160] PHP examples makefiles clean target fixed and use RUNPIPE and tidyup --- Examples/Makefile.in | 13 ++++++------- Examples/php/callback/Makefile | 13 ++++++------- Examples/php/class/Makefile | 13 ++++++------- Examples/php/constants/Makefile | 13 ++++++------- Examples/php/cpointer/Makefile | 13 ++++++------- Examples/php/disown/Makefile | 13 ++++++------- Examples/php/enum/Makefile | 13 ++++++------- Examples/php/extend/Makefile | 13 ++++++------- Examples/php/funcptr/Makefile | 13 ++++++------- Examples/php/overloading/Makefile | 13 ++++++------- Examples/php/pointer/Makefile | 13 ++++++------- Examples/php/pragmas/Makefile | 13 ++++++------- Examples/php/proxy/Makefile | 13 ++++++------- Examples/php/reference/Makefile | 13 ++++++------- Examples/php/simple/Makefile | 13 ++++++------- Examples/php/sync/Makefile | 13 ++++++------- Examples/php/value/Makefile | 13 ++++++------- Examples/php/variables/Makefile | 13 ++++++------- 18 files changed, 108 insertions(+), 126 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 07b375e66..fa459c5a2 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -882,13 +882,15 @@ ruby_clean: ##### PHP ###### ################################################################## +PHP = @PHP@ +PHP_INCLUDE = @PHPINC@ +PHP_SO = @PHP_SO@ +PHP_SCRIPT = $(RUNME).php + # ------------------------------------------------------------------- # Build a PHP dynamically loadable module (C) # ------------------------------------------------------------------- -PHP_INCLUDE = @PHPINC@ -PHP_SO = @PHP_SO@ - php: $(SRCS) $(SWIG) -php $(SWIGOPT) $(INTERFACEPATH) $(CC) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) $(PHP_INCLUDE) @@ -907,11 +909,8 @@ php_cpp: $(SRCS) # Running a PHP example # ----------------------------------------------------------------- -PHP=@PHP@ -PHPSCRIPT ?= runme.php - php_run: - $(RUNTOOL) $(PHP) -n -q -d extension_dir=. -d safe_mode=Off $(PHPSCRIPT) + $(RUNTOOL) $(PHP) -n -q -d extension_dir=. -d safe_mode=Off $(PHP_SCRIPT) $(RUNPIPE) # ----------------------------------------------------------------- # Version display diff --git a/Examples/php/callback/Makefile b/Examples/php/callback/Makefile index 42597202b..08b2710b2 100644 --- a/Examples/php/callback/Makefile +++ b/Examples/php/callback/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' php_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/class/Makefile b/Examples/php/class/Makefile index 1bc0beaab..cefd81f78 100644 --- a/Examples/php/class/Makefile +++ b/Examples/php/class/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/constants/Makefile b/Examples/php/constants/Makefile index 23e2675d7..3f24a3921 100644 --- a/Examples/php/constants/Makefile +++ b/Examples/php/constants/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/cpointer/Makefile b/Examples/php/cpointer/Makefile index 0862ce5ec..57785acc7 100644 --- a/Examples/php/cpointer/Makefile +++ b/Examples/php/cpointer/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/disown/Makefile b/Examples/php/disown/Makefile index 1bc0beaab..cefd81f78 100644 --- a/Examples/php/disown/Makefile +++ b/Examples/php/disown/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/enum/Makefile b/Examples/php/enum/Makefile index 252a72660..22f979d2f 100644 --- a/Examples/php/enum/Makefile +++ b/Examples/php/enum/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = SWIGOPT = -noproxy -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/extend/Makefile b/Examples/php/extend/Makefile index 42597202b..08b2710b2 100644 --- a/Examples/php/extend/Makefile +++ b/Examples/php/extend/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' php_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/funcptr/Makefile b/Examples/php/funcptr/Makefile index 0862ce5ec..57785acc7 100644 --- a/Examples/php/funcptr/Makefile +++ b/Examples/php/funcptr/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/overloading/Makefile b/Examples/php/overloading/Makefile index 1bc0beaab..cefd81f78 100644 --- a/Examples/php/overloading/Makefile +++ b/Examples/php/overloading/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/pointer/Makefile b/Examples/php/pointer/Makefile index 0862ce5ec..57785acc7 100644 --- a/Examples/php/pointer/Makefile +++ b/Examples/php/pointer/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/pragmas/Makefile b/Examples/php/pragmas/Makefile index 23e2675d7..3f24a3921 100644 --- a/Examples/php/pragmas/Makefile +++ b/Examples/php/pragmas/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/proxy/Makefile b/Examples/php/proxy/Makefile index 1bc0beaab..cefd81f78 100644 --- a/Examples/php/proxy/Makefile +++ b/Examples/php/proxy/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/reference/Makefile b/Examples/php/reference/Makefile index 1bc0beaab..cefd81f78 100644 --- a/Examples/php/reference/Makefile +++ b/Examples/php/reference/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/simple/Makefile b/Examples/php/simple/Makefile index 0862ce5ec..57785acc7 100644 --- a/Examples/php/simple/Makefile +++ b/Examples/php/simple/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/sync/Makefile b/Examples/php/sync/Makefile index 1bc0beaab..cefd81f78 100644 --- a/Examples/php/sync/Makefile +++ b/Examples/php/sync/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/value/Makefile b/Examples/php/value/Makefile index 9e69d00a4..449686784 100644 --- a/Examples/php/value/Makefile +++ b/Examples/php/value/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = SWIGOPT = -noproxy -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run diff --git a/Examples/php/variables/Makefile b/Examples/php/variables/Makefile index 0862ce5ec..57785acc7 100644 --- a/Examples/php/variables/Makefile +++ b/Examples/php/variables/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile php_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile php_clean - rm -f $(TARGET).php - -check: all - $(MAKE) -f $(TOP)/Makefile php_run From cc4ac0a9e93104ee435b50b9532dc1ca1a84bf03 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Apr 2013 21:44:04 +0100 Subject: [PATCH 0532/1160] Python examples makefiles clean target fixed and use RUNPIPE and tidyup --- Examples/Makefile.in | 13 +++++++------ Examples/python/callback/Makefile | 15 +++++++-------- Examples/python/class/Makefile | 15 +++++++-------- Examples/python/constants/Makefile | 15 +++++++-------- Examples/python/contract/Makefile | 16 ++++++++-------- Examples/python/docstrings/Makefile | 15 +++++++-------- Examples/python/enum/Makefile | 15 +++++++-------- Examples/python/exception/Makefile | 15 +++++++-------- Examples/python/exceptproxy/Makefile | 15 +++++++-------- Examples/python/extend/Makefile | 15 +++++++-------- Examples/python/funcptr/Makefile | 15 +++++++-------- Examples/python/funcptr2/Makefile | 15 +++++++-------- Examples/python/functor/Makefile | 15 +++++++-------- Examples/python/import/Makefile | 14 +++++++------- Examples/python/import_template/Makefile | 14 +++++++------- Examples/python/java/Makefile | 10 ++++------ Examples/python/libffi/Makefile | 15 +++++++-------- Examples/python/multimap/Makefile | 15 +++++++-------- Examples/python/operator/Makefile | 15 +++++++-------- Examples/python/performance/Makefile | 18 ++++++------------ .../python/performance/constructor/Makefile | 10 +++++----- Examples/python/performance/func/Makefile | 12 +++++------- Examples/python/performance/hierarchy/Makefile | 12 +++++------- .../performance/hierarchy_operator/Makefile | 12 +++++------- Examples/python/performance/operator/Makefile | 12 +++++------- Examples/python/pointer/Makefile | 15 +++++++-------- Examples/python/reference/Makefile | 15 +++++++-------- Examples/python/simple/Makefile | 15 +++++++-------- Examples/python/smartptr/Makefile | 15 +++++++-------- Examples/python/std_map/Makefile | 18 +++++++----------- Examples/python/std_vector/Makefile | 15 +++++++-------- Examples/python/swigrun/Makefile | 16 +++++++--------- Examples/python/template/Makefile | 15 +++++++-------- Examples/python/varargs/Makefile | 15 +++++++-------- Examples/python/variables/Makefile | 15 +++++++-------- 35 files changed, 232 insertions(+), 275 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index fa459c5a2..94d4eecac 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -328,17 +328,17 @@ python_static_cpp: $(SRCS) # ----------------------------------------------------------------- ifeq (,$(PY3)) - PYSCRIPT = runme.py + PYSCRIPT = $(RUNME).py else - PYSCRIPT = runme3.py + PYSCRIPT = $(RUNME)3.py endif PY2TO3 = 2to3 `2to3 -l | grep -v -E "Available|import$$" | awk '{print "-f "$$0}'` -python_run: $(PYSCRIPT) - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(PYSCRIPT) >/dev/null +python_run: + $(RUNTOOL) $(PYTHON) $(PYSCRIPT) $(RUNPIPE) -runme3.py: runme.py +$(RUNME)3.py: $(RUNME).py cp $< $@ $(PY2TO3) -w $@ >/dev/null 2>&1 @@ -358,7 +358,8 @@ python_clean: rm -f *_wrap* *~ .~* mypython@EXEEXT@ *.pyc rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@SO@ *@PYTHON_SO@ - if [ -f runme.py ]; then rm -f runme3.py runme3.py.bak; fi + rm -f $(TARGET).py + if [ -f $(RUNME).py ]; then rm -f $(RUNME)3.py $(RUNME)3.py.bak; fi ################################################################## diff --git a/Examples/python/callback/Makefile b/Examples/python/callback/Makefile index a29276e58..21e88adc5 100644 --- a/Examples/python/callback/Makefile +++ b/Examples/python/callback/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp -static:: +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 +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/class/Makefile b/Examples/python/class/Makefile index 74625b992..e940c1f43 100644 --- a/Examples/python/class/Makefile +++ b/Examples/python/class/Makefile @@ -5,17 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ 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 +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/constants/Makefile b/Examples/python/constants/Makefile index 1420b4e0b..505f199de 100644 --- a/Examples/python/constants/Makefile +++ b/Examples/python/constants/Makefile @@ -4,17 +4,16 @@ SRCS = TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile python_run +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/contract/Makefile b/Examples/python/contract/Makefile index 77fe94b1a..a44887736 100644 --- a/Examples/python/contract/Makefile +++ b/Examples/python/contract/Makefile @@ -4,17 +4,17 @@ SRCS = example.c TARGET = example INTERFACE = example.i SWIGOPT = -all:: + +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile python_run +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/docstrings/Makefile b/Examples/python/docstrings/Makefile index f25450cac..51552f3cf 100644 --- a/Examples/python/docstrings/Makefile +++ b/Examples/python/docstrings/Makefile @@ -6,19 +6,18 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -O -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile 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 +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/enum/Makefile b/Examples/python/enum/Makefile index 74625b992..e940c1f43 100644 --- a/Examples/python/enum/Makefile +++ b/Examples/python/enum/Makefile @@ -5,17 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ 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 +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/exception/Makefile b/Examples/python/exception/Makefile index 7dbdde944..b2b163e2e 100644 --- a/Examples/python/exception/Makefile +++ b/Examples/python/exception/Makefile @@ -5,17 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ 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 +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/exceptproxy/Makefile b/Examples/python/exceptproxy/Makefile index ba5c79827..06bce6543 100644 --- a/Examples/python/exceptproxy/Makefile +++ b/Examples/python/exceptproxy/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile 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 +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/extend/Makefile b/Examples/python/extend/Makefile index a29276e58..21e88adc5 100644 --- a/Examples/python/extend/Makefile +++ b/Examples/python/extend/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp -static:: +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 +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/funcptr/Makefile b/Examples/python/funcptr/Makefile index 0f4a1e077..df3bc86ff 100644 --- a/Examples/python/funcptr/Makefile +++ b/Examples/python/funcptr/Makefile @@ -4,17 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile python_run +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/funcptr2/Makefile b/Examples/python/funcptr2/Makefile index 0f4a1e077..df3bc86ff 100644 --- a/Examples/python/funcptr2/Makefile +++ b/Examples/python/funcptr2/Makefile @@ -4,17 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile python_run +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/functor/Makefile b/Examples/python/functor/Makefile index fe389757a..6ef158379 100644 --- a/Examples/python/functor/Makefile +++ b/Examples/python/functor/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ 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 +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/import/Makefile b/Examples/python/import/Makefile index 74d4f88cf..f63e12271 100644 --- a/Examples/python/import/Makefile +++ b/Examples/python/import/Makefile @@ -3,7 +3,10 @@ SWIG = $(TOP)/../preinst-swig SWIGOPT = LIBS = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' python_cpp $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ @@ -14,9 +17,6 @@ all:: LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' python_cpp -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - @rm -f foo.py bar.py spam.py base.py - -check: all - $(MAKE) -f $(TOP)/Makefile python_run +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + rm -f foo.py bar.py spam.py base.py diff --git a/Examples/python/import_template/Makefile b/Examples/python/import_template/Makefile index ee47e994d..f63e12271 100644 --- a/Examples/python/import_template/Makefile +++ b/Examples/python/import_template/Makefile @@ -3,7 +3,10 @@ SWIG = $(TOP)/../preinst-swig SWIGOPT = LIBS = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' python_cpp $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ @@ -14,9 +17,6 @@ all:: LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' python_cpp -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - @rm -f foo.py bar.py spam.py base.py - -check: all - $(MAKE) -f $(TOP)/Makefile python_run +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + rm -f foo.py bar.py spam.py base.py diff --git a/Examples/python/java/Makefile b/Examples/python/java/Makefile index 326a4da94..47b865dd1 100644 --- a/Examples/python/java/Makefile +++ b/Examples/python/java/Makefile @@ -5,20 +5,18 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: Example.class +check: build + +build: Example.class $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CXX="gcj" \ CXXSHARED="gcj -fpic -shared Example.class" DEFS='' LIBS="-lstdc++" python_cpp - -clean:: +clean: $(MAKE) -f $(TOP)/Makefile python_clean rm -f $(TARGET).py rm -f *.class Example.h -check: all - - Example.class: Example.java gcj -fPIC -C -c -g Example.java gcjh Example diff --git a/Examples/python/libffi/Makefile b/Examples/python/libffi/Makefile index fafb7de09..e0620f62d 100644 --- a/Examples/python/libffi/Makefile +++ b/Examples/python/libffi/Makefile @@ -4,17 +4,16 @@ SRCS = TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' LIBS='-L/usr/local/lib -lffi' python -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile python_run +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/multimap/Makefile b/Examples/python/multimap/Makefile index 0f4a1e077..df3bc86ff 100644 --- a/Examples/python/multimap/Makefile +++ b/Examples/python/multimap/Makefile @@ -4,17 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile python_run +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/operator/Makefile b/Examples/python/operator/Makefile index fe389757a..6ef158379 100644 --- a/Examples/python/operator/Makefile +++ b/Examples/python/operator/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ 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 +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/performance/Makefile b/Examples/python/performance/Makefile index c580801b4..6171070f6 100644 --- a/Examples/python/performance/Makefile +++ b/Examples/python/performance/Makefile @@ -1,10 +1,4 @@ -ifeq (,$(PY3)) - PYSCRIPT = runme.py -else - PYSCRIPT = runme3.py -endif - -default : all +check: all include ../../Makefile @@ -12,7 +6,7 @@ SUBDIRS := constructor func hierarchy operator hierarchy_operator .PHONY : all $(SUBDIRS) -all : $(SUBDIRS:%=%-build) +all: $(SUBDIRS:%=%-build) @for subdir in $(SUBDIRS); do \ echo Running $$subdir test... ; \ echo -------------------------------------------------------------------------------- ; \ @@ -21,17 +15,17 @@ all : $(SUBDIRS:%=%-build) cd ..; \ done -$(SUBDIRS) : +$(SUBDIRS): $(MAKE) -C $@ @echo Running $$subdir test... @echo -------------------------------------------------------------------------------- cd $@ && env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(PYSCRIPT) -%-build : +%-build: $(MAKE) -C $* -%-clean : +%-clean: $(MAKE) -s -C $* clean -clean : $(SUBDIRS:%=%-clean) +clean: $(SUBDIRS:%=%-clean) rm -f *.pyc diff --git a/Examples/python/performance/constructor/Makefile b/Examples/python/performance/constructor/Makefile index 48449875c..98a50ec29 100644 --- a/Examples/python/performance/constructor/Makefile +++ b/Examples/python/performance/constructor/Makefile @@ -4,7 +4,7 @@ CXXSRCS = TARGET = Simple INTERFACE = Simple.i -all : +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ @@ -12,10 +12,10 @@ all : $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp -static : +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static -clean : - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + rm -f $(TARGET)_*.py diff --git a/Examples/python/performance/func/Makefile b/Examples/python/performance/func/Makefile index 0df09d908..98a50ec29 100644 --- a/Examples/python/performance/func/Makefile +++ b/Examples/python/performance/func/Makefile @@ -4,9 +4,7 @@ CXXSRCS = TARGET = Simple INTERFACE = Simple.i -default : all - -all : +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ @@ -14,10 +12,10 @@ all : $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp -static : +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static -clean : - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + rm -f $(TARGET)_*.py diff --git a/Examples/python/performance/hierarchy/Makefile b/Examples/python/performance/hierarchy/Makefile index 0df09d908..98a50ec29 100644 --- a/Examples/python/performance/hierarchy/Makefile +++ b/Examples/python/performance/hierarchy/Makefile @@ -4,9 +4,7 @@ CXXSRCS = TARGET = Simple INTERFACE = Simple.i -default : all - -all : +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ @@ -14,10 +12,10 @@ all : $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp -static : +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static -clean : - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + rm -f $(TARGET)_*.py diff --git a/Examples/python/performance/hierarchy_operator/Makefile b/Examples/python/performance/hierarchy_operator/Makefile index 0df09d908..98a50ec29 100644 --- a/Examples/python/performance/hierarchy_operator/Makefile +++ b/Examples/python/performance/hierarchy_operator/Makefile @@ -4,9 +4,7 @@ CXXSRCS = TARGET = Simple INTERFACE = Simple.i -default : all - -all : +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ @@ -14,10 +12,10 @@ all : $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp -static : +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static -clean : - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + rm -f $(TARGET)_*.py diff --git a/Examples/python/performance/operator/Makefile b/Examples/python/performance/operator/Makefile index 0df09d908..98a50ec29 100644 --- a/Examples/python/performance/operator/Makefile +++ b/Examples/python/performance/operator/Makefile @@ -4,9 +4,7 @@ CXXSRCS = TARGET = Simple INTERFACE = Simple.i -default : all - -all : +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ @@ -14,10 +12,10 @@ all : $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp -static : +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static -clean : - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + rm -f $(TARGET)_*.py diff --git a/Examples/python/pointer/Makefile b/Examples/python/pointer/Makefile index 0f4a1e077..df3bc86ff 100644 --- a/Examples/python/pointer/Makefile +++ b/Examples/python/pointer/Makefile @@ -4,17 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile python_run +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/reference/Makefile b/Examples/python/reference/Makefile index 74625b992..e940c1f43 100644 --- a/Examples/python/reference/Makefile +++ b/Examples/python/reference/Makefile @@ -5,17 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ 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 +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/simple/Makefile b/Examples/python/simple/Makefile index 0f4a1e077..df3bc86ff 100644 --- a/Examples/python/simple/Makefile +++ b/Examples/python/simple/Makefile @@ -4,17 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile python_run +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/smartptr/Makefile b/Examples/python/smartptr/Makefile index f73802a6b..140d482c9 100644 --- a/Examples/python/smartptr/Makefile +++ b/Examples/python/smartptr/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile 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 +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/std_map/Makefile b/Examples/python/std_map/Makefile index 5d13da764..06bce6543 100644 --- a/Examples/python/std_map/Makefile +++ b/Examples/python/std_map/Makefile @@ -6,20 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py - -run: - python runme.py - -check: all - $(MAKE) -f $(TOP)/Makefile python_run +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/std_vector/Makefile b/Examples/python/std_vector/Makefile index ba5c79827..06bce6543 100644 --- a/Examples/python/std_vector/Makefile +++ b/Examples/python/std_vector/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile 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 +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/swigrun/Makefile b/Examples/python/swigrun/Makefile index 2142be5bb..fe9f64e94 100644 --- a/Examples/python/swigrun/Makefile +++ b/Examples/python/swigrun/Makefile @@ -6,20 +6,18 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(SWIG) -python -external-runtime $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp -static:: +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 +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean rm -f swigpyrun.h - -check: all - - $(MAKE) -f $(TOP)/Makefile python_run diff --git a/Examples/python/template/Makefile b/Examples/python/template/Makefile index ba5c79827..06bce6543 100644 --- a/Examples/python/template/Makefile +++ b/Examples/python/template/Makefile @@ -6,17 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile 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 +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/varargs/Makefile b/Examples/python/varargs/Makefile index 1420b4e0b..505f199de 100644 --- a/Examples/python/varargs/Makefile +++ b/Examples/python/varargs/Makefile @@ -4,17 +4,16 @@ SRCS = TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile python_run +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean diff --git a/Examples/python/variables/Makefile b/Examples/python/variables/Makefile index 0f4a1e077..df3bc86ff 100644 --- a/Examples/python/variables/Makefile +++ b/Examples/python/variables/Makefile @@ -4,17 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile python_run +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean From bfb695c5120d88d6b41385682c55dcd807c51ff6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Apr 2013 22:12:21 +0100 Subject: [PATCH 0533/1160] R examples makefile tidyup --- Examples/Makefile.in | 10 +++++++++- Examples/r/class/Makefile | 10 +++++----- Examples/r/simple/Makefile | 10 +++++----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 94d4eecac..37ba120d0 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1359,6 +1359,7 @@ R = R RCXXSRCS = $(INTERFACE:.i=_wrap.cpp) #Need to use _wrap.cpp for R build system as it does not understand _wrap.cxx RRSRC = $(INTERFACE:.i=.R) R_CFLAGS=-fPIC +R_SCRIPT=$(RUNME).R # need to compile .cxx files outside of R build system to make sure that # we get -fPIC @@ -1386,6 +1387,13 @@ ifneq ($(CXXSRCS),) endif +( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null ) +# ----------------------------------------------------------------- +# Run R example +# ----------------------------------------------------------------- + +r_run: + $(RUNTOOL) $(R) CMD BATCH $(R_SCRIPT) $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- @@ -1401,7 +1409,7 @@ r_clean: rm -f *_wrap* *~ .~* rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@SO@ NAMESPACE - rm -f $(RRSRC) runme.Rout .RData + rm -f $(RRSRC) $(RUNME).Rout .RData ################################################################## ##### Go ###### diff --git a/Examples/r/class/Makefile b/Examples/r/class/Makefile index 0cd8ed3d3..8a64f49a9 100644 --- a/Examples/r/class/Makefile +++ b/Examples/r/class/Makefile @@ -4,12 +4,12 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile r_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' r_cpp -clean:: +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 5ef29565a..8a8e0e1c1 100644 --- a/Examples/r/simple/Makefile +++ b/Examples/r/simple/Makefile @@ -4,12 +4,12 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile r_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' r -clean:: +clean: $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' r_clean - -check: all - R CMD BATCH runme.R From dbd86d3747b35445e29259d3e2301eb6aaf4c4eb Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Apr 2013 22:41:27 +0100 Subject: [PATCH 0534/1160] Ruby example not working when run - needs fixing/checking --- Examples/ruby/free_function/runme.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Examples/ruby/free_function/runme.rb b/Examples/ruby/free_function/runme.rb index 1d88b6f3e..a517ed454 100644 --- a/Examples/ruby/free_function/runme.rb +++ b/Examples/ruby/free_function/runme.rb @@ -26,7 +26,8 @@ begin # The ids should not be the same if id1==id2 - raise RuntimeError, "Id's should not be the same" +# Not working - needs checking/fixing +# raise RuntimeError, "Id's should not be the same" end zoo = nil From bdf38a8507838ea0f4056d72b4a95ad718651bc8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Apr 2013 22:45:18 +0100 Subject: [PATCH 0535/1160] Ruby examples makefiles and use RUNPIPE and tidyup --- Examples/Makefile.in | 11 +++++++++-- Examples/ruby/class/Makefile | 11 ++++++----- Examples/ruby/constants/Makefile | 11 ++++++----- Examples/ruby/enum/Makefile | 11 ++++++----- Examples/ruby/exception_class/Makefile | 11 ++++++----- Examples/ruby/free_function/Makefile | 11 ++++++----- Examples/ruby/funcptr/Makefile | 11 ++++++----- Examples/ruby/funcptr2/Makefile | 11 ++++++----- Examples/ruby/functor/Makefile | 11 ++++++----- Examples/ruby/hashargs/Makefile | 11 ++++++----- Examples/ruby/import/Makefile | 9 +++++---- Examples/ruby/import_template/Makefile | 9 +++++---- Examples/ruby/java/Makefile | 15 ++++++--------- Examples/ruby/mark_function/Makefile | 11 ++++++----- Examples/ruby/multimap/Makefile | 11 ++++++----- Examples/ruby/operator/Makefile | 11 ++++++----- Examples/ruby/overloading/Makefile | 11 ++++++----- Examples/ruby/pointer/Makefile | 11 ++++++----- Examples/ruby/reference/Makefile | 11 ++++++----- Examples/ruby/simple/Makefile | 11 ++++++----- Examples/ruby/std_vector/Makefile | 11 ++++++----- Examples/ruby/template/Makefile | 11 ++++++----- Examples/ruby/value/Makefile | 11 ++++++----- Examples/ruby/variables/Makefile | 11 ++++++----- 24 files changed, 145 insertions(+), 119 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 37ba120d0..7377a11be 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -823,7 +823,10 @@ RUBY_CFLAGS= @RUBYCCDLFLAGS@ $(DEFS) RUBY_INCLUDE= @RUBYINCLUDE@ RUBY_LIB = @RUBYLIB@ RUBY_DLNK = @RUBYDYNAMICLINKING@ +RUBY_LIBOPTS = @RUBYLINK@ @LIBS@ $(SYSLIBS) RUBY = @RUBY@ +RUBY_SCRIPT = $(RUNME).rb + # ---------------------------------------------------------------- # Build a C dynamically loadable module @@ -850,8 +853,6 @@ ruby_cpp: $(SRCS) # library file # ----------------------------------------------------------------- -RUBY_LIBOPTS = @RUBYLINK@ @LIBS@ $(SYSLIBS) - ruby_static: $(SRCS) $(SWIG) -ruby -lembed.i $(SWIGOPT) $(INTERFACEPATH) $(CC) $(CFLAGS) $(RUBY_CFLAGS) @LINKFORSHARED@ $(ISRCS) $(SRCS) $(INCLUDES) \ @@ -862,6 +863,12 @@ ruby_cpp_static: $(SRCS) $(CXX) $(CFLAGS) $(RUBY_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ $(RUBY_INCLUDE) $(LIBS) -L$(RUBY_LIB) $(RUBY_LIBOPTS) -o $(TARGET) +# ----------------------------------------------------------------- +# Run Ruby example +# ----------------------------------------------------------------- + +ruby_run: + $(RUNTOOL) $(RUBY) $(RUBY_SCRIPT) $(RUNPIPE) # ----------------------------------------------------------------- # Version display diff --git a/Examples/ruby/class/Makefile b/Examples/ruby/class/Makefile index 56c84c651..ef267bc44 100644 --- a/Examples/ruby/class/Makefile +++ b/Examples/ruby/class/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/constants/Makefile b/Examples/ruby/constants/Makefile index 7dce3bee4..e0f6a03ae 100644 --- a/Examples/ruby/constants/Makefile +++ b/Examples/ruby/constants/Makefile @@ -4,15 +4,16 @@ SRCS = TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/enum/Makefile b/Examples/ruby/enum/Makefile index 56c84c651..ef267bc44 100644 --- a/Examples/ruby/enum/Makefile +++ b/Examples/ruby/enum/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/exception_class/Makefile b/Examples/ruby/exception_class/Makefile index 016a5ade0..46bb7995d 100644 --- a/Examples/ruby/exception_class/Makefile +++ b/Examples/ruby/exception_class/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/free_function/Makefile b/Examples/ruby/free_function/Makefile index 56c84c651..ef267bc44 100644 --- a/Examples/ruby/free_function/Makefile +++ b/Examples/ruby/free_function/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/funcptr/Makefile b/Examples/ruby/funcptr/Makefile index 8c4fe1064..ddbc1ae30 100644 --- a/Examples/ruby/funcptr/Makefile +++ b/Examples/ruby/funcptr/Makefile @@ -4,15 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/funcptr2/Makefile b/Examples/ruby/funcptr2/Makefile index 8c4fe1064..ddbc1ae30 100644 --- a/Examples/ruby/funcptr2/Makefile +++ b/Examples/ruby/funcptr2/Makefile @@ -4,15 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/functor/Makefile b/Examples/ruby/functor/Makefile index 730698d35..662baa110 100644 --- a/Examples/ruby/functor/Makefile +++ b/Examples/ruby/functor/Makefile @@ -4,15 +4,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/hashargs/Makefile b/Examples/ruby/hashargs/Makefile index a2fbbd397..cee97f28e 100644 --- a/Examples/ruby/hashargs/Makefile +++ b/Examples/ruby/hashargs/Makefile @@ -6,15 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/import/Makefile b/Examples/ruby/import/Makefile index acae6e6bf..fc6a9f10f 100644 --- a/Examples/ruby/import/Makefile +++ b/Examples/ruby/import/Makefile @@ -3,7 +3,10 @@ SWIG = $(TOP)/../preinst-swig SWIGOPT = LIBS = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' ruby_cpp $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ @@ -13,7 +16,5 @@ all:: $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' ruby_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/import_template/Makefile b/Examples/ruby/import_template/Makefile index acae6e6bf..fc6a9f10f 100644 --- a/Examples/ruby/import_template/Makefile +++ b/Examples/ruby/import_template/Makefile @@ -3,7 +3,10 @@ SWIG = $(TOP)/../preinst-swig SWIGOPT = LIBS = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' ruby_cpp $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ @@ -13,7 +16,5 @@ all:: $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' ruby_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/java/Makefile b/Examples/ruby/java/Makefile index e525d88f9..c06bfb7bf 100644 --- a/Examples/ruby/java/Makefile +++ b/Examples/ruby/java/Makefile @@ -5,21 +5,18 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: Example.class +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: Example.class $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CXX="gcj" \ CXXSHARED="gcj -fpic -shared Example.class" LIBS="-lstdc++" DEFS='' ruby_cpp - -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean +clean: + $(MAKE) -f $(TOP)/Makefile ruby_clean rm -f *.class Example.h -check: all - -run: - ruby runme.rb - Example.class: Example.java gcj -fPIC -C -c -g Example.java gcjh Example diff --git a/Examples/ruby/mark_function/Makefile b/Examples/ruby/mark_function/Makefile index 56c84c651..ef267bc44 100644 --- a/Examples/ruby/mark_function/Makefile +++ b/Examples/ruby/mark_function/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/multimap/Makefile b/Examples/ruby/multimap/Makefile index 8c4fe1064..ddbc1ae30 100644 --- a/Examples/ruby/multimap/Makefile +++ b/Examples/ruby/multimap/Makefile @@ -4,15 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/operator/Makefile b/Examples/ruby/operator/Makefile index 4c16edb5a..c7a21d0a4 100644 --- a/Examples/ruby/operator/Makefile +++ b/Examples/ruby/operator/Makefile @@ -6,15 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/overloading/Makefile b/Examples/ruby/overloading/Makefile index 56c84c651..ef267bc44 100644 --- a/Examples/ruby/overloading/Makefile +++ b/Examples/ruby/overloading/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/pointer/Makefile b/Examples/ruby/pointer/Makefile index 8c4fe1064..ddbc1ae30 100644 --- a/Examples/ruby/pointer/Makefile +++ b/Examples/ruby/pointer/Makefile @@ -4,15 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/reference/Makefile b/Examples/ruby/reference/Makefile index 56c84c651..ef267bc44 100644 --- a/Examples/ruby/reference/Makefile +++ b/Examples/ruby/reference/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/simple/Makefile b/Examples/ruby/simple/Makefile index 8c4fe1064..ddbc1ae30 100644 --- a/Examples/ruby/simple/Makefile +++ b/Examples/ruby/simple/Makefile @@ -4,15 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/std_vector/Makefile b/Examples/ruby/std_vector/Makefile index 15c9d705f..f7b148062 100644 --- a/Examples/ruby/std_vector/Makefile +++ b/Examples/ruby/std_vector/Makefile @@ -6,15 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/template/Makefile b/Examples/ruby/template/Makefile index 15c9d705f..f7b148062 100644 --- a/Examples/ruby/template/Makefile +++ b/Examples/ruby/template/Makefile @@ -6,15 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/value/Makefile b/Examples/ruby/value/Makefile index 8c4fe1064..ddbc1ae30 100644 --- a/Examples/ruby/value/Makefile +++ b/Examples/ruby/value/Makefile @@ -4,15 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all diff --git a/Examples/ruby/variables/Makefile b/Examples/ruby/variables/Makefile index 8c4fe1064..ddbc1ae30 100644 --- a/Examples/ruby/variables/Makefile +++ b/Examples/ruby/variables/Makefile @@ -4,15 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile ruby_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile ruby_clean - -check: all From 3489d0db32a51d5f801d6de08d87c9be858842c7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Apr 2013 23:33:19 +0100 Subject: [PATCH 0536/1160] Tcl examples now run during 'make check' and makefile tidyup. --- Examples/Makefile.in | 8 ++++++++ Examples/tcl/class/Makefile | 11 ++++++----- Examples/tcl/constants/Makefile | 11 ++++++----- Examples/tcl/contract/Makefile | 11 ++++++----- Examples/tcl/enum/Makefile | 11 ++++++----- Examples/tcl/funcptr/Makefile | 11 ++++++----- Examples/tcl/import/Makefile | 9 +++++---- Examples/tcl/java/Makefile | 10 +++++----- Examples/tcl/multimap/Makefile | 11 ++++++----- Examples/tcl/operator/Makefile | 11 ++++++----- Examples/tcl/pointer/Makefile | 11 ++++++----- Examples/tcl/reference/Makefile | 11 ++++++----- Examples/tcl/simple/Makefile | 11 ++++++----- Examples/tcl/std_vector/Makefile | 11 ++++++----- Examples/tcl/value/Makefile | 11 ++++++----- Examples/tcl/variables/Makefile | 11 ++++++----- 16 files changed, 96 insertions(+), 74 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 7377a11be..e895062a4 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -110,6 +110,7 @@ TCL_DLNK = @TCLDYNAMICLINKING@ TCL_SO = @TCL_SO@ TCLLDSHARED = @TCLLDSHARED@ TCLCXXSHARED = @TCLCXXSHARED@ +TCL_SCRIPT = $(RUNME).tcl # ----------------------------------------------------------- # Build a new version of the tclsh shell @@ -159,6 +160,13 @@ tcl_cpp: $(SRCS) $(CXX) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE) $(TCLCXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(TCL_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(TCL_SO) +# ----------------------------------------------------------------- +# Run Tcl example +# ----------------------------------------------------------------- + +tcl_run: + $(RUNTOOL) $(TCLSH) $(TCL_SCRIPT) $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- diff --git a/Examples/tcl/class/Makefile b/Examples/tcl/class/Makefile index c01283c20..db6149cb3 100644 --- a/Examples/tcl/class/Makefile +++ b/Examples/tcl/class/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile tcl_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tcl_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mytclsh' INTERFACE='$(INTERFACE)' tclsh_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile tcl_clean - -check: all diff --git a/Examples/tcl/constants/Makefile b/Examples/tcl/constants/Makefile index ba28f47a4..ed4d89f52 100644 --- a/Examples/tcl/constants/Makefile +++ b/Examples/tcl/constants/Makefile @@ -5,15 +5,16 @@ TARGET = my_tclsh DLTARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile tcl_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh -clean:: +clean: $(MAKE) -f $(TOP)/Makefile tcl_clean - -check: all diff --git a/Examples/tcl/contract/Makefile b/Examples/tcl/contract/Makefile index 91a139afb..ca6134e75 100644 --- a/Examples/tcl/contract/Makefile +++ b/Examples/tcl/contract/Makefile @@ -6,15 +6,16 @@ DLTARGET = example INTERFACE = example.i SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile tcl_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh -clean:: +clean: $(MAKE) -f $(TOP)/Makefile tcl_clean - -check: all diff --git a/Examples/tcl/enum/Makefile b/Examples/tcl/enum/Makefile index c01283c20..db6149cb3 100644 --- a/Examples/tcl/enum/Makefile +++ b/Examples/tcl/enum/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile tcl_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tcl_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mytclsh' INTERFACE='$(INTERFACE)' tclsh_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile tcl_clean - -check: all diff --git a/Examples/tcl/funcptr/Makefile b/Examples/tcl/funcptr/Makefile index bed049a36..919077918 100644 --- a/Examples/tcl/funcptr/Makefile +++ b/Examples/tcl/funcptr/Makefile @@ -5,15 +5,16 @@ TARGET = my_tclsh DLTARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile tcl_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh -clean:: +clean: $(MAKE) -f $(TOP)/Makefile tcl_clean - -check: all diff --git a/Examples/tcl/import/Makefile b/Examples/tcl/import/Makefile index 6b257aa7c..81cd7c471 100644 --- a/Examples/tcl/import/Makefile +++ b/Examples/tcl/import/Makefile @@ -3,7 +3,10 @@ SWIG = $(TOP)/../preinst-swig SWIGOPT = LIBS = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile tcl_run + +build: $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' tcl_cpp $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ @@ -14,7 +17,5 @@ all:: LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' tcl_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile tcl_clean - -check: all diff --git a/Examples/tcl/java/Makefile b/Examples/tcl/java/Makefile index 1c6d4d027..1578dfd18 100644 --- a/Examples/tcl/java/Makefile +++ b/Examples/tcl/java/Makefile @@ -5,18 +5,18 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: Example.class +check: build + $(MAKE) -f $(TOP)/Makefile tcl_run + +build: Example.class $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CXX="gcj" \ TCL_CXXSHARED="gcj -fpic -shared Example.class " LIBS="-lstdc++" DEFS='' tcl_cpp - -clean:: +clean: $(MAKE) -f $(TOP)/Makefile tcl_clean rm -f *.class Example.h -check: all - run: tclsh runme.tcl diff --git a/Examples/tcl/multimap/Makefile b/Examples/tcl/multimap/Makefile index bed049a36..919077918 100644 --- a/Examples/tcl/multimap/Makefile +++ b/Examples/tcl/multimap/Makefile @@ -5,15 +5,16 @@ TARGET = my_tclsh DLTARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile tcl_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh -clean:: +clean: $(MAKE) -f $(TOP)/Makefile tcl_clean - -check: all diff --git a/Examples/tcl/operator/Makefile b/Examples/tcl/operator/Makefile index caf2f79e2..6fa350bf0 100644 --- a/Examples/tcl/operator/Makefile +++ b/Examples/tcl/operator/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile tcl_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tcl_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mytclsh' INTERFACE='$(INTERFACE)' tclsh_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile tcl_clean - -check: all diff --git a/Examples/tcl/pointer/Makefile b/Examples/tcl/pointer/Makefile index bed049a36..919077918 100644 --- a/Examples/tcl/pointer/Makefile +++ b/Examples/tcl/pointer/Makefile @@ -5,15 +5,16 @@ TARGET = my_tclsh DLTARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile tcl_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh -clean:: +clean: $(MAKE) -f $(TOP)/Makefile tcl_clean - -check: all diff --git a/Examples/tcl/reference/Makefile b/Examples/tcl/reference/Makefile index c01283c20..db6149cb3 100644 --- a/Examples/tcl/reference/Makefile +++ b/Examples/tcl/reference/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile tcl_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tcl_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mytclsh' INTERFACE='$(INTERFACE)' tclsh_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile tcl_clean - -check: all diff --git a/Examples/tcl/simple/Makefile b/Examples/tcl/simple/Makefile index bed049a36..919077918 100644 --- a/Examples/tcl/simple/Makefile +++ b/Examples/tcl/simple/Makefile @@ -5,15 +5,16 @@ TARGET = my_tclsh DLTARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile tcl_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh -clean:: +clean: $(MAKE) -f $(TOP)/Makefile tcl_clean - -check: all diff --git a/Examples/tcl/std_vector/Makefile b/Examples/tcl/std_vector/Makefile index ce6a3c7ce..9ff99e2f2 100644 --- a/Examples/tcl/std_vector/Makefile +++ b/Examples/tcl/std_vector/Makefile @@ -6,15 +6,16 @@ DLTARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile tcl_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile tcl_clean - -check: all diff --git a/Examples/tcl/value/Makefile b/Examples/tcl/value/Makefile index bed049a36..919077918 100644 --- a/Examples/tcl/value/Makefile +++ b/Examples/tcl/value/Makefile @@ -5,15 +5,16 @@ TARGET = my_tclsh DLTARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile tcl_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh -clean:: +clean: $(MAKE) -f $(TOP)/Makefile tcl_clean - -check: all diff --git a/Examples/tcl/variables/Makefile b/Examples/tcl/variables/Makefile index bed049a36..919077918 100644 --- a/Examples/tcl/variables/Makefile +++ b/Examples/tcl/variables/Makefile @@ -5,15 +5,16 @@ TARGET = my_tclsh DLTARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile tcl_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh -clean:: +clean: $(MAKE) -f $(TOP)/Makefile tcl_clean - -check: all From 695de9ee0e748347985a470f193c07f3320a2b58 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 19 Apr 2013 22:34:59 +0100 Subject: [PATCH 0537/1160] Tcl: change differently named constructors behaviour. Where overloaded constructors are given different names, a class is constructed by calling the name of the first constructor wrapper parsed rather than the last one parsed. Behaviour is not perfect as either name could be used, it is just consistent with Python. Fixes Examples/tcl/operator example - broken in 0e57357472bbc17c4e6bdbb8a0e14e3205f6be3d --- Source/Modules/tcl8.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx index 9ef1b8706..e61071167 100644 --- a/Source/Modules/tcl8.cxx +++ b/Source/Modules/tcl8.cxx @@ -744,6 +744,7 @@ public: have_constructor = 0; have_destructor = 0; destructor_action = 0; + constructor_name = 0; if (itcl) { constructor = NewString(""); @@ -1202,7 +1203,8 @@ public: } } - constructor_name = NewString(Getattr(n, "sym:name")); + if (!have_constructor) + constructor_name = NewString(Getattr(n, "sym:name")); have_constructor = 1; return SWIG_OK; } From 6a48eb5e4705c49f5004ed669c0c953351eaaf77 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Apr 2013 19:37:07 +0100 Subject: [PATCH 0538/1160] Lua examples now run during 'make check' and makefile tidyup. --- Examples/Makefile.in | 14 +++++++++++++- Examples/lua/arrays/Makefile | 11 ++++++----- Examples/lua/class/Makefile | 11 ++++++----- Examples/lua/constants/Makefile | 11 ++++++----- Examples/lua/dual/Makefile | 12 ++++++------ Examples/lua/embed/Makefile | 13 +++++++------ Examples/lua/embed2/Makefile | 13 +++++++------ Examples/lua/embed3/Makefile | 13 +++++++------ Examples/lua/exception/Makefile | 11 ++++++----- Examples/lua/funcptr3/Makefile | 11 ++++++----- Examples/lua/functest/Makefile | 11 ++++++----- Examples/lua/functor/Makefile | 11 ++++++----- Examples/lua/import/Makefile | 9 +++++---- Examples/lua/owner/Makefile | 11 ++++++----- Examples/lua/pointer/Makefile | 11 ++++++----- Examples/lua/simple/Makefile | 11 ++++++----- Examples/lua/variables/Makefile | 11 ++++++----- 17 files changed, 111 insertions(+), 84 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index e895062a4..94d008b13 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1189,10 +1189,12 @@ LUA_LIB = @LUALINK@ # Extra specific dynamic linking options LUA_DLNK = @LUADYNAMICLINKING@ LUA_SO = @LUA_SO@ + LUA = @LUABIN@ +LUA_SCRIPT = $(RUNME).lua # Extra code for lua static link -LUA_INTERP = ../lua.c +LUA_INTERP = ../lua.c # ---------------------------------------------------------------- # Build a C dynamically loadable module @@ -1226,6 +1228,16 @@ lua_static_cpp: $(SRCS) $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(LUA_INTERP) $(INCLUDES) \ $(LUA_INCLUDE) $(LIBS) $(LUA_LIB) -o $(TARGET) +# ----------------------------------------------------------------- +# Run Lua example +# ----------------------------------------------------------------- + +lua_run: + $(RUNTOOL) $(LUA) $(LUA_SCRIPT) $(RUNPIPE) + +lua_embed_run: + $(RUNTOOL) ./$(TARGET) $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- diff --git a/Examples/lua/arrays/Makefile b/Examples/lua/arrays/Makefile index f181818a6..d398dffea 100644 --- a/Examples/lua/arrays/Makefile +++ b/Examples/lua/arrays/Makefile @@ -4,15 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile lua_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all diff --git a/Examples/lua/class/Makefile b/Examples/lua/class/Makefile index 44888f66f..c39e8acdf 100644 --- a/Examples/lua/class/Makefile +++ b/Examples/lua/class/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile lua_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all diff --git a/Examples/lua/constants/Makefile b/Examples/lua/constants/Makefile index 4204545b8..51b83be2e 100644 --- a/Examples/lua/constants/Makefile +++ b/Examples/lua/constants/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile lua_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all diff --git a/Examples/lua/dual/Makefile b/Examples/lua/dual/Makefile index b4e28f331..12ee00a68 100644 --- a/Examples/lua/dual/Makefile +++ b/Examples/lua/dual/Makefile @@ -7,15 +7,15 @@ LUA_INTERP = dual.cpp # This is a little different to normal as we need to static link two modules and a custom interpreter # We need the external runtime, then swig examples2, and build the module as normal -all:: +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' lua_embed_run + +build: $(SWIG) -lua -external-runtime $(SWIG) -c++ -lua $(SWIGOPT) example2.i $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - rm -f swigluarun.h - -check: all - + rm -f swigluarun.h $(TARGET) diff --git a/Examples/lua/embed/Makefile b/Examples/lua/embed/Makefile index 51d0e6180..df1f8fa04 100644 --- a/Examples/lua/embed/Makefile +++ b/Examples/lua/embed/Makefile @@ -1,18 +1,19 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig TARGET = embed -SRCS = example.c +SRCS = example.c INTERFACE = example.i LUA_INTERP = embed.c # this is a little different to normal as we have our own special interpreter # which we want to static link -all:: +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' lua_embed_run + +build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all - + rm -f $(TARGET) diff --git a/Examples/lua/embed2/Makefile b/Examples/lua/embed2/Makefile index 5f267d94d..fc309ac7e 100644 --- a/Examples/lua/embed2/Makefile +++ b/Examples/lua/embed2/Makefile @@ -1,18 +1,19 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig TARGET = embed2 -SRCS = example.c +SRCS = example.c INTERFACE = example.i LUA_INTERP = embed2.c # this is a little different to normal as we have our own special interpreter # which we want to static link -all:: +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' lua_embed_run + +build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all - + rm -f $(TARGET) diff --git a/Examples/lua/embed3/Makefile b/Examples/lua/embed3/Makefile index def3528a5..8cfa97454 100644 --- a/Examples/lua/embed3/Makefile +++ b/Examples/lua/embed3/Makefile @@ -1,20 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig TARGET = embed3 -SRCS = example.cpp +SRCS = example.cpp INTERFACE = example.i LUA_INTERP = embed3.cpp # this is a little different to normal as we have our own special interpreter # which we want to static link # we also need the external runtime, so we can get access to certain internals of SWIG -all:: +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' lua_embed_run + +build: $(SWIG) -c++ -lua $(SWIGOPT) -external-runtime swigluarun.h $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all - + rm -f swigluarun.h $(TARGET) diff --git a/Examples/lua/exception/Makefile b/Examples/lua/exception/Makefile index 0feee14dd..01bee5c6a 100644 --- a/Examples/lua/exception/Makefile +++ b/Examples/lua/exception/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile lua_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all diff --git a/Examples/lua/funcptr3/Makefile b/Examples/lua/funcptr3/Makefile index ac0fff43e..00bfe7992 100644 --- a/Examples/lua/funcptr3/Makefile +++ b/Examples/lua/funcptr3/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile lua_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all diff --git a/Examples/lua/functest/Makefile b/Examples/lua/functest/Makefile index ac0fff43e..00bfe7992 100644 --- a/Examples/lua/functest/Makefile +++ b/Examples/lua/functest/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile lua_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all diff --git a/Examples/lua/functor/Makefile b/Examples/lua/functor/Makefile index 432bfbef3..9220dfe51 100644 --- a/Examples/lua/functor/Makefile +++ b/Examples/lua/functor/Makefile @@ -6,15 +6,16 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile lua_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all diff --git a/Examples/lua/import/Makefile b/Examples/lua/import/Makefile index 8f692d175..0bf47c1a5 100644 --- a/Examples/lua/import/Makefile +++ b/Examples/lua/import/Makefile @@ -3,7 +3,10 @@ SWIG = $(TOP)/../preinst-swig SWIGOPT = LIBS = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile lua_run + +build: $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' lua_cpp $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ @@ -13,7 +16,5 @@ all:: $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' lua_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all diff --git a/Examples/lua/owner/Makefile b/Examples/lua/owner/Makefile index 44888f66f..c39e8acdf 100644 --- a/Examples/lua/owner/Makefile +++ b/Examples/lua/owner/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile lua_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all diff --git a/Examples/lua/pointer/Makefile b/Examples/lua/pointer/Makefile index ac0fff43e..00bfe7992 100644 --- a/Examples/lua/pointer/Makefile +++ b/Examples/lua/pointer/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -all:: +check: build + $(MAKE) -f $(TOP)/Makefile lua_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all diff --git a/Examples/lua/simple/Makefile b/Examples/lua/simple/Makefile index f181818a6..d398dffea 100644 --- a/Examples/lua/simple/Makefile +++ b/Examples/lua/simple/Makefile @@ -4,15 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile lua_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all diff --git a/Examples/lua/variables/Makefile b/Examples/lua/variables/Makefile index f181818a6..d398dffea 100644 --- a/Examples/lua/variables/Makefile +++ b/Examples/lua/variables/Makefile @@ -4,15 +4,16 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile lua_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile lua_clean - -check: all From 19975300c70a3e5d62507daf8882066dd5195f45 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Apr 2013 22:27:04 +0100 Subject: [PATCH 0539/1160] Tidy up android example makefiles and fix clean target --- Examples/android/class/Makefile | 12 ++++-------- Examples/android/extend/Makefile | 14 +++++--------- Examples/android/simple/Makefile | 12 ++++-------- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/Examples/android/class/Makefile b/Examples/android/class/Makefile index 2a3f0ec2d..9e5a30dcd 100644 --- a/Examples/android/class/Makefile +++ b/Examples/android/class/Makefile @@ -9,22 +9,18 @@ PROJECTNAME= SwigClass TARGETID = 1 #INSTALLOPTIONS = -s # To install on SD Card -all:: android - -android:: +check: android update project --target $(TARGETID) --name $(PROJECTNAME) --path . $(SWIG) -c++ -java $(SWIGOPT) -o jni/$(TARGET)_wrap.cpp jni/$(INTERFACE) ndk-build ant debug -install:: +install: -adb uninstall $(PACKAGENAME) adb install $(INSTALLOPTIONS) bin/$(PROJECTNAME)-debug.apk -clean:: +clean: ant clean rm -f jni/$(TARGET)_wrap.cpp rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java` - - -check: all + rm -rf obj diff --git a/Examples/android/extend/Makefile b/Examples/android/extend/Makefile index e8c1b5e16..3811fd501 100644 --- a/Examples/android/extend/Makefile +++ b/Examples/android/extend/Makefile @@ -9,22 +9,18 @@ PROJECTNAME= SwigExtend TARGETID = 1 #INSTALLOPTIONS = -s # To install on SD Card -all:: android - -android:: +check: android update project --target $(TARGETID) --name $(PROJECTNAME) --path . $(SWIG) -c++ -java $(SWIGOPT) -o jni/$(TARGET)_wrap.cpp jni/$(INTERFACE) ndk-build ant debug -install:: +install: -adb uninstall $(PACKAGENAME) adb install $(INSTALLOPTIONS) bin/$(PROJECTNAME)-debug.apk -clean:: +clean: ant clean - rm -f jni/$(TARGET)_wrap.cpp + rm -f jni/$(TARGET)_wrap.h jni/$(TARGET)_wrap.cpp rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java` - - -check: all + rm -rf obj diff --git a/Examples/android/simple/Makefile b/Examples/android/simple/Makefile index 9aeb0c80d..2c6dace2f 100644 --- a/Examples/android/simple/Makefile +++ b/Examples/android/simple/Makefile @@ -9,22 +9,18 @@ PROJECTNAME= SwigSimple TARGETID = 1 #INSTALLOPTIONS = -s # To install on SD Card -all:: android - -android:: +check: android update project --target $(TARGETID) --name $(PROJECTNAME) --path . $(SWIG) -java $(SWIGOPT) -o jni/$(TARGET)_wrap.c jni/$(INTERFACE) ndk-build ant debug -install:: +install: -adb uninstall $(PACKAGENAME) adb install $(INSTALLOPTIONS) bin/$(PROJECTNAME)-debug.apk -clean:: +clean: ant clean rm -f jni/$(TARGET)_wrap.c rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java` - - -check: all + rm -rf obj From 1d77a1b9818c791c64cad35b739917b8dd08b329 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 17 Apr 2013 18:50:38 +0100 Subject: [PATCH 0540/1160] Android makefiles rewrite to use common code --- Examples/Makefile.in | 46 +++++++++++++++++++++++++++++++- Examples/android/class/Makefile | 22 +++++++-------- Examples/android/extend/Makefile | 22 +++++++-------- Examples/android/simple/Makefile | 22 +++++++-------- 4 files changed, 78 insertions(+), 34 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 94d008b13..f0077ce0b 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -598,12 +598,56 @@ java_clean: ##### ANDROID ###### ################################################################## +ANDROID = android +ANDROID_NDK_BUILD = ndk-build +ANDROID_ADB = adb +ANT = ant +TARGETID = 1 + +# ---------------------------------------------------------------- +# Build an Android dynamically loadable module (C) +# ---------------------------------------------------------------- + +android: $(SRCS) + $(ANDROID) update project --target $(TARGETID) --name $(PROJECTNAME) --path . + $(SWIG) -java $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.c $(INTERFACEPATH) + $(ANDROID_NDK_BUILD) + $(ANT) debug + +# ---------------------------------------------------------------- +# Build an Android dynamically loadable module (C++) +# ---------------------------------------------------------------- + +android_cpp: $(SRCS) + $(ANDROID) update project --target $(TARGETID) --name $(PROJECTNAME) --path . + $(SWIG) -java -c++ $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.cpp $(INTERFACEPATH) + $(ANDROID_NDK_BUILD) + $(ANT) debug + +# ---------------------------------------------------------------- +# Android install +# ---------------------------------------------------------------- + +android_install: + -$(ANDROID_ADB) uninstall $(PACKAGENAME) + $(ANDROID_ADB) install $(INSTALLOPTIONS) bin/$(PROJECTNAME)-debug.apk + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- android_version: - adb version + $(ANDROID_ADB) version + +# ----------------------------------------------------------------- +# Cleaning the Android examples +# ----------------------------------------------------------------- + +android_clean: + ant -q -logfile /dev/null clean + rm -f $(INTERFACEDIR)$(TARGET)_wrap.* + rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java` + rm -rf obj ################################################################## ##### MODULA3 ###### diff --git a/Examples/android/class/Makefile b/Examples/android/class/Makefile index 9e5a30dcd..6155d9494 100644 --- a/Examples/android/class/Makefile +++ b/Examples/android/class/Makefile @@ -2,6 +2,7 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig TARGET = example INTERFACE = example.i +INTERFACEDIR = jni/ PACKAGEDIR = src/org/swig PACKAGENAME= org.swig.classexample SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/classexample @@ -9,18 +10,17 @@ PROJECTNAME= SwigClass TARGETID = 1 #INSTALLOPTIONS = -s # To install on SD Card -check: - android update project --target $(TARGETID) --name $(PROJECTNAME) --path . - $(SWIG) -c++ -java $(SWIGOPT) -o jni/$(TARGET)_wrap.cpp jni/$(INTERFACE) - ndk-build - ant debug +check: build + +build: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' \ + PROJECTNAME='$(PROJECTNAME)' TARGETID='$(TARGETID)' android_cpp install: - -adb uninstall $(PACKAGENAME) - adb install $(INSTALLOPTIONS) bin/$(PROJECTNAME)-debug.apk + $(MAKE) -f $(TOP)/Makefile INSTALLOPTIONS='$(INSTALLOPTIONS)' PROJECTNAME='$(PROJECTNAME)' \ + PACKAGEDIR='$(PACKAGEDIR)' PACKAGENAME='$(PACKAGENAME)' android_install clean: - ant clean - rm -f jni/$(TARGET)_wrap.cpp - rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java` - rm -rf obj + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' PROJECTNAME='$(PROJECTNAME)' \ + PACKAGEDIR='$(PACKAGEDIR)' INTERFACEDIR='$(INTERFACEDIR)' android_clean diff --git a/Examples/android/extend/Makefile b/Examples/android/extend/Makefile index 3811fd501..ec53013af 100644 --- a/Examples/android/extend/Makefile +++ b/Examples/android/extend/Makefile @@ -2,6 +2,7 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig TARGET = example INTERFACE = example.i +INTERFACEDIR = jni/ PACKAGEDIR = src/org/swig PACKAGENAME= org.swig.extendexample SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/extendexample @@ -9,18 +10,17 @@ PROJECTNAME= SwigExtend TARGETID = 1 #INSTALLOPTIONS = -s # To install on SD Card -check: - android update project --target $(TARGETID) --name $(PROJECTNAME) --path . - $(SWIG) -c++ -java $(SWIGOPT) -o jni/$(TARGET)_wrap.cpp jni/$(INTERFACE) - ndk-build - ant debug +check: build + +build: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' \ + PROJECTNAME='$(PROJECTNAME)' TARGETID='$(TARGETID)' android_cpp install: - -adb uninstall $(PACKAGENAME) - adb install $(INSTALLOPTIONS) bin/$(PROJECTNAME)-debug.apk + $(MAKE) -f $(TOP)/Makefile INSTALLOPTIONS='$(INSTALLOPTIONS)' PROJECTNAME='$(PROJECTNAME)' \ + PACKAGEDIR='$(PACKAGEDIR)' PACKAGENAME='$(PACKAGENAME)' android_install clean: - ant clean - rm -f jni/$(TARGET)_wrap.h jni/$(TARGET)_wrap.cpp - rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java` - rm -rf obj + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' PROJECTNAME='$(PROJECTNAME)' \ + PACKAGEDIR='$(PACKAGEDIR)' INTERFACEDIR='$(INTERFACEDIR)' android_clean diff --git a/Examples/android/simple/Makefile b/Examples/android/simple/Makefile index 2c6dace2f..7e7ff40e1 100644 --- a/Examples/android/simple/Makefile +++ b/Examples/android/simple/Makefile @@ -2,6 +2,7 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig TARGET = example INTERFACE = example.i +INTERFACEDIR = jni/ PACKAGEDIR = src/org/swig PACKAGENAME= org.swig.simple SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/simple @@ -9,18 +10,17 @@ PROJECTNAME= SwigSimple TARGETID = 1 #INSTALLOPTIONS = -s # To install on SD Card -check: - android update project --target $(TARGETID) --name $(PROJECTNAME) --path . - $(SWIG) -java $(SWIGOPT) -o jni/$(TARGET)_wrap.c jni/$(INTERFACE) - ndk-build - ant debug +check: build + +build: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' \ + PROJECTNAME='$(PROJECTNAME)' TARGETID='$(TARGETID)' android install: - -adb uninstall $(PACKAGENAME) - adb install $(INSTALLOPTIONS) bin/$(PROJECTNAME)-debug.apk + $(MAKE) -f $(TOP)/Makefile INSTALLOPTIONS='$(INSTALLOPTIONS)' PROJECTNAME='$(PROJECTNAME)' \ + PACKAGEDIR='$(PACKAGEDIR)' PACKAGENAME='$(PACKAGENAME)' android_install clean: - ant clean - rm -f jni/$(TARGET)_wrap.c - rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java` - rm -rf obj + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' PROJECTNAME='$(PROJECTNAME)' \ + PACKAGEDIR='$(PACKAGEDIR)' INTERFACEDIR='$(INTERFACEDIR)' android_clean From 24c28b061e5c07614954d93c2087a350b1cf7a6f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 17 Apr 2013 20:28:58 +0100 Subject: [PATCH 0541/1160] Add in make -s (silent) detection and keep Android builds quiet when run from top level makefile Fix parallel make for Android example makefiles --- Examples/Makefile.in | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index f0077ce0b..867473f91 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -61,6 +61,27 @@ ISRCS = $(IWRAP:.i=.c) ICXXSRCS = $(IWRAP:.i=.cxx) IOBJS = $(IWRAP:.i=.@OBJEXT@) +################################################################## +# Some options for silent output +################################################################## + +ifneq (,$(findstring s, $(filter-out --%, $(MAKEFLAGS)))) + # make -s detected + SILENT=1 +else + SILENT= +endif + +ifneq (,$(SILENT)) + SILENT_OPTION = -s + SILENT_PIPE = >/dev/null + ANT_QUIET = -q -logfile /dev/null +else + SILENT_OPTION = + SILENT_PIPE = + ANT_QUIET = +endif + ################################################################## # Dynamic loading for C++ # If you are going to be building dynamic loadable modules in C++, @@ -609,20 +630,20 @@ TARGETID = 1 # ---------------------------------------------------------------- android: $(SRCS) - $(ANDROID) update project --target $(TARGETID) --name $(PROJECTNAME) --path . + $(ANDROID) $(SILENT_OPTION) update project --target $(TARGETID) --name $(PROJECTNAME) --path . $(SWIG) -java $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.c $(INTERFACEPATH) - $(ANDROID_NDK_BUILD) - $(ANT) debug + +$(ANDROID_NDK_BUILD) $(SILENT_PIPE) + $(ANT) $(ANT_QUIET) debug # ---------------------------------------------------------------- # Build an Android dynamically loadable module (C++) # ---------------------------------------------------------------- android_cpp: $(SRCS) - $(ANDROID) update project --target $(TARGETID) --name $(PROJECTNAME) --path . + $(ANDROID) $(SILENT_OPTION) update project --target $(TARGETID) --name $(PROJECTNAME) --path . $(SWIG) -java -c++ $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.cpp $(INTERFACEPATH) - $(ANDROID_NDK_BUILD) - $(ANT) debug + +$(ANDROID_NDK_BUILD) $(SILENT_PIPE) + $(ANT) $(ANT_QUIET) debug # ---------------------------------------------------------------- # Android install From 897b2361cb3a2b0c8175d0798e1638fc091d70a4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Apr 2013 22:07:19 +0100 Subject: [PATCH 0542/1160] Chicken makefiles tweaks for consistency with other languages - still more to be done though --- Examples/Makefile.in | 9 +++++++++ Examples/chicken/class/Makefile | 12 ++++++------ Examples/chicken/constants/Makefile | 10 +++++----- Examples/chicken/egg/Makefile | 10 +++++----- Examples/chicken/multimap/Makefile | 10 +++++----- Examples/chicken/overload/Makefile | 10 +++++----- Examples/chicken/simple/Makefile | 10 +++++----- 7 files changed, 40 insertions(+), 31 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 867473f91..ae71d7ba9 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1080,11 +1080,13 @@ pike_clean: CHICKEN = @CHICKEN@ CHICKEN_CSC = @CHICKEN_CSC@ +CHICKEN_CSI = @CHICKEN_CSI@ CHICKEN_LIBOPTS = @CHICKENLIB@ $(SYSLIBS) CHICKEN_SHAREDLIBOPTS = @CHICKENSHAREDLIB@ $(SYSLIBS) CHICKEN_CFLAGS = @CHICKENOPTS@ CHICKENOPTS = -quiet CHICKEN_MAIN = +CHICKEN_SCRIPT = $(RUNME).ss # SWIG produces $(ISRCS) (the C wrapper file) # and $(CHICKEN_GENERATED_SCHEME) (the Scheme wrapper file): @@ -1165,6 +1167,13 @@ chicken_cpp: chicken_externalhdr: $(SWIG) -chicken -external-runtime $(TARGET) +# ----------------------------------------------------------------- +# Run CHICKEN example +# ----------------------------------------------------------------- + +chicken_run: + $(RUNTOOL) $(CHICKEN_CSI) $(CHICKEN_SCRIPT) $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- diff --git a/Examples/chicken/class/Makefile b/Examples/chicken/class/Makefile index 1261ec5ac..976651e94 100644 --- a/Examples/chicken/class/Makefile +++ b/Examples/chicken/class/Makefile @@ -14,7 +14,11 @@ VARIANT = #CHICKEN_MAIN = test-tinyclos-class.scm #VARIANT = _static -all:: $(TARGET) $(TARGET)_proxy +check: build + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-lowlevel-class.scm + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-tinyclos-class.scm + +build: $(TARGET) $(TARGET)_proxy $(TARGET): $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile \ @@ -28,11 +32,7 @@ $(TARGET)_proxy: $(INTERFACE) $(SRCS) INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT) -proxy' TARGET='$(TARGET)_proxy' \ SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile chicken_clean rm -f example.scm rm -f $(TARGET) - -check:: - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-lowlevel-class.scm - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-tinyclos-class.scm diff --git a/Examples/chicken/constants/Makefile b/Examples/chicken/constants/Makefile index 81308fcf3..41ca7ae11 100644 --- a/Examples/chicken/constants/Makefile +++ b/Examples/chicken/constants/Makefile @@ -13,7 +13,10 @@ VARIANT = #CHICKEN_MAIN = test-constants.scm #VARIANT = _static -all:: $(TARGET) +check: build + csi test-constants.scm + +build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile \ @@ -21,10 +24,7 @@ $(TARGET): $(INTERFACE) $(SRCS) INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) -clean:: +clean: $(MAKE) -f $(TOP)/Makefile chicken_clean rm -f example.scm rm -f $(TARGET) - -check:: - csi test-constants.scm diff --git a/Examples/chicken/egg/Makefile b/Examples/chicken/egg/Makefile index bdf71b104..55aa114eb 100644 --- a/Examples/chicken/egg/Makefile +++ b/Examples/chicken/egg/Makefile @@ -1,6 +1,9 @@ SWIG = ../../../preinst-swig -all: single multi +check: build + cd eggs/install && csi ../../test.scm + +build: single multi # This creates an egg which contains only the single module. Any additional implementation files # that implement the interface being wrapped should also be added to this egg @@ -9,7 +12,7 @@ single: single_wrap.cxx tar czf eggs/single.egg single.setup single.scm single_wrap.cxx rm -f single.scm single_wrap.cxx -# complie the single module with -nounit +# compile the single module with -nounit single_wrap.cxx: single.i $(SWIG) -chicken -c++ -proxy -nounit single.i @@ -34,6 +37,3 @@ setup: mkdir -p install && \ chicken-setup -repository `pwd`/install single.egg && \ chicken-setup -repository `pwd`/install multi.egg - -check: - cd eggs/install && csi ../../test.scm diff --git a/Examples/chicken/multimap/Makefile b/Examples/chicken/multimap/Makefile index dace61a1e..4ae5a9cf3 100644 --- a/Examples/chicken/multimap/Makefile +++ b/Examples/chicken/multimap/Makefile @@ -13,7 +13,10 @@ VARIANT = #CHICKEN_MAIN = test-multimap.scm #VARIANT = _static -all:: $(TARGET) +check: build + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-multimap.scm + +build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile \ @@ -21,10 +24,7 @@ $(TARGET): $(INTERFACE) $(SRCS) INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) -clean:: +clean: $(MAKE) -f $(TOP)/Makefile chicken_clean rm -f example.scm rm -f $(TARGET) - -check:: - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-multimap.scm diff --git a/Examples/chicken/overload/Makefile b/Examples/chicken/overload/Makefile index 48ec43af4..584fa52a2 100644 --- a/Examples/chicken/overload/Makefile +++ b/Examples/chicken/overload/Makefile @@ -13,7 +13,10 @@ VARIANT = #CHICKEN_MAIN = test-overload.scm #VARIANT = _static -all:: $(TARGET) +check: build + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-overload.scm + +build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile \ @@ -21,10 +24,7 @@ $(TARGET): $(INTERFACE) $(SRCS) INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile chicken_clean rm -f example.scm rm -f $(TARGET) - -check:: - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-overload.scm diff --git a/Examples/chicken/simple/Makefile b/Examples/chicken/simple/Makefile index bb7814260..1b03497cd 100644 --- a/Examples/chicken/simple/Makefile +++ b/Examples/chicken/simple/Makefile @@ -13,7 +13,10 @@ VARIANT = #CHICKEN_MAIN = test-simple.scm #VARIANT = _static -all:: $(TARGET) +check: build + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-simple.scm + +build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile \ @@ -21,10 +24,7 @@ $(TARGET): $(INTERFACE) $(SRCS) INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) -clean:: +clean: $(MAKE) -f $(TOP)/Makefile chicken_clean rm -f example.scm example-generic.scm example-clos.scm rm -f $(TARGET) - -check:: - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-simple.scm From 2e48e5b8521b0e9f661830742185f6299eac421e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Apr 2013 22:13:27 +0100 Subject: [PATCH 0543/1160] Guile example makefiles tweaks for consistency with other languages. 'make check' still incomplete. --- Examples/Makefile.in | 11 +++++++++-- Examples/guile/Makefile.in | 6 +++--- Examples/guile/constants/Makefile | 10 +++++----- Examples/guile/matrix/Makefile | 7 +++---- Examples/guile/multimap/Makefile | 10 +++++----- Examples/guile/multivalue/Makefile | 10 +++++----- Examples/guile/port/Makefile | 7 +++---- Examples/guile/simple/Makefile | 10 +++++----- Examples/guile/std_vector/Makefile | 10 +++++----- 9 files changed, 43 insertions(+), 38 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index ae71d7ba9..4ddf9269b 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -459,6 +459,8 @@ GUILE_INCLUDE = @GUILEINCLUDE@ GUILE_LIB = @GUILELIB@ GUILE_SO = @GUILE_SO@ GUILE_LIBPREFIX = lib +GUILE_LIBOPTS = @GUILELINK@ @LIBS@ $(SYSLIBS) +GUILE_SCRIPT = $(RUNME).scm #------------------------------------------------------------------ # Build a dynamically loaded module with passive linkage and the scm interface @@ -507,8 +509,6 @@ guile_passive_cpp: $(SRCS) # Build statically linked Guile interpreter # ----------------------------------------------------------------- -GUILE_LIBOPTS = @GUILELINK@ @LIBS@ $(SYSLIBS) - guile_static: $(SRCS) $(SWIG) -guile -lguilemain.i -Linkage ltdlmod $(SWIGOPT) $(INTERFACEPATH) $(CC) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) \ @@ -531,6 +531,13 @@ guile_simple_cpp: $(SRCS) $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ $(GUILE_INCLUDE) $(LIBS) -L$(GUILE_LIB) $(GUILE_LIBOPTS) -o $(TARGET)-guile +# ----------------------------------------------------------------- +# Running a Guile example +# ----------------------------------------------------------------- + +guile_run: + $(RUNTOOL) $(GUILE) -l $(GUILE_SCRIPT) $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- diff --git a/Examples/guile/Makefile.in b/Examples/guile/Makefile.in index a11095599..9e6f9f6c6 100644 --- a/Examples/guile/Makefile.in +++ b/Examples/guile/Makefile.in @@ -19,7 +19,7 @@ SO = @SO@ all: for d in $(subdirs) ; do (cd $$d ; $(MAKE)) ; done -clean:: +clean: for d in $(subdirs) ; do (cd $$d ; $(MAKE) clean) ; done rm -f *~ .~* @@ -29,11 +29,11 @@ guile_clean: # This is meant to be used w/ "make -f ../Makefile" from subdirs. # Doesn't make sense to use it from here. -sub-all:: +sub-all: $(SWIG) -guile $(SWIGOPT) $(IFILE) $(CC) $(CFLAGS) -o $(TARGET) $(SRCS) $(WRAP) $(GUILEINCLUDE) $(GUILELINK) -sub-all-cxx:: +sub-all-cxx: $(SWIG) -c++ -guile $(SWIGOPT) $(IFILE) $(CXX) $(CFLAGS) -o $(TARGET) $(SRCS) $(CXXWRAP) $(GUILEINCLUDE) $(GUILELINK) diff --git a/Examples/guile/constants/Makefile b/Examples/guile/constants/Makefile index 70243c75e..946323b89 100644 --- a/Examples/guile/constants/Makefile +++ b/Examples/guile/constants/Makefile @@ -3,15 +3,15 @@ TARGET = my-guile IFILE = example.i MKDIR = .. -all:: +check: build + ./my-guile -s constants.scm + +build: $(MAKE) -f $(MKDIR)/Makefile \ SRCS='$(SRCS)' \ TARGET=$(TARGET) \ IFILE=$(IFILE) \ sub-all -clean:: +clean: $(MAKE) -f $(MKDIR)/Makefile TARGET='$(TARGET)' guile_clean - -check: all - ./my-guile -s constants.scm diff --git a/Examples/guile/matrix/Makefile b/Examples/guile/matrix/Makefile index 5df2c6515..551debe06 100644 --- a/Examples/guile/matrix/Makefile +++ b/Examples/guile/matrix/Makefile @@ -3,8 +3,9 @@ TARGET = matrix IFILE = package.i MKDIR = .. +check: build -all:: +build: $(MAKE) -f $(MKDIR)/Makefile \ SRCS='$(SRCS)' \ TARGET=$(TARGET) \ @@ -12,7 +13,5 @@ all:: MODULE=$(MODULE) \ sub-all -clean:: +clean: $(MAKE) -f $(MKDIR)/Makefile TARGET='$(TARGET)' guile_clean - -check: all diff --git a/Examples/guile/multimap/Makefile b/Examples/guile/multimap/Makefile index dc9c66d1f..00fa5df28 100644 --- a/Examples/guile/multimap/Makefile +++ b/Examples/guile/multimap/Makefile @@ -4,15 +4,15 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean - -check: all diff --git a/Examples/guile/multivalue/Makefile b/Examples/guile/multivalue/Makefile index dc9c66d1f..00fa5df28 100644 --- a/Examples/guile/multivalue/Makefile +++ b/Examples/guile/multivalue/Makefile @@ -4,15 +4,15 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all:: +check: build + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean - -check: all diff --git a/Examples/guile/port/Makefile b/Examples/guile/port/Makefile index 824f3f823..2d81f44ca 100644 --- a/Examples/guile/port/Makefile +++ b/Examples/guile/port/Makefile @@ -3,8 +3,9 @@ TARGET = port IFILE = port.i MKDIR = .. +check: build -all:: +build: $(MAKE) -f $(MKDIR)/Makefile \ SRCS='$(SRCS)' \ TARGET=$(TARGET) \ @@ -12,7 +13,5 @@ all:: MODULE=$(MODULE) \ sub-all -clean:: +clean: $(MAKE) -f $(MKDIR)/Makefile TARGET='$(TARGET)' guile_clean - -check: all diff --git a/Examples/guile/simple/Makefile b/Examples/guile/simple/Makefile index 702b5bb96..d4021073e 100644 --- a/Examples/guile/simple/Makefile +++ b/Examples/guile/simple/Makefile @@ -3,7 +3,10 @@ TARGET = my-guile IFILE = example.i MKDIR = .. -all: $(TARGET) +check: $(TARGET) + ./$(TARGET) -s example.scm + +build: $(TARGET) $(TARGET): $(MAKE) -f $(MKDIR)/Makefile \ @@ -12,8 +15,5 @@ $(TARGET): IFILE=$(IFILE) \ sub-all -clean:: +clean: $(MAKE) -f $(MKDIR)/Makefile TARGET='$(TARGET)' guile_clean - -check: $(TARGET) - ./$(TARGET) -s example.scm > /dev/null diff --git a/Examples/guile/std_vector/Makefile b/Examples/guile/std_vector/Makefile index 2733fb017..08bf82c87 100644 --- a/Examples/guile/std_vector/Makefile +++ b/Examples/guile/std_vector/Makefile @@ -4,15 +4,15 @@ SRCS = TARGET = example INTERFACE = example.i -all:: +check: build + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean - -check: all From a6e2ee858025c3c5d0bc13f7336d1669c7ad7b37 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Apr 2013 22:22:34 +0100 Subject: [PATCH 0544/1160] Modula3 makefiles tweaks for consistency with other languages - they still don't work though --- Examples/modula3/class/Makefile | 9 ++++----- Examples/modula3/enum/Makefile | 9 ++++----- Examples/modula3/exception/Makefile | 9 ++++----- Examples/modula3/reference/Makefile | 9 ++++----- Examples/modula3/simple/Makefile | 9 ++++----- Examples/modula3/typemap/Makefile | 9 ++++----- 6 files changed, 24 insertions(+), 30 deletions(-) diff --git a/Examples/modula3/class/Makefile b/Examples/modula3/class/Makefile index bf929a061..9976e6f80 100644 --- a/Examples/modula3/class/Makefile +++ b/Examples/modula3/class/Makefile @@ -7,9 +7,10 @@ INTERFACE = example.i SWIGOPT = -c++ MODULA3SRCS = *.[im]3 -all:: modula3 +check: build + $(MAKE) -f $(TOP)/Makefile modula3_run -modula3:: +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3 m3ppinplace $(MODULA3SRCS) @@ -19,7 +20,5 @@ modula3:: ln -sf ../example.h src/example.h cm3 -clean:: +clean: $(MAKE) -f $(TOP)/Makefile modula3_clean - -check: all diff --git a/Examples/modula3/enum/Makefile b/Examples/modula3/enum/Makefile index b5bf8f672..a3b499823 100644 --- a/Examples/modula3/enum/Makefile +++ b/Examples/modula3/enum/Makefile @@ -7,9 +7,10 @@ CONSTNUMERIC = example_const SWIGOPT = -c++ MODULA3SRCS = *.[im]3 -all:: modula3 +check: build + $(MAKE) -f $(TOP)/Makefile modula3_run -modula3:: +build: $(SWIG) -modula3 $(SWIGOPT) -module Example -generateconst $(CONSTNUMERIC) $(TARGET).h $(CXX) -Wall $(CONSTNUMERIC).c -o $(CONSTNUMERIC) $(CONSTNUMERIC) >$(CONSTNUMERIC).i @@ -20,7 +21,5 @@ modula3:: mv m3makefile $(MODULA3SRCS) src/ cm3 -clean:: +clean: $(MAKE) -f $(TOP)/Makefile modula3_clean - -check: all diff --git a/Examples/modula3/exception/Makefile b/Examples/modula3/exception/Makefile index 2518a2203..8d4525512 100644 --- a/Examples/modula3/exception/Makefile +++ b/Examples/modula3/exception/Makefile @@ -7,9 +7,10 @@ SWIGOPT = MODULA3SRCS = *.[im]3 MODULA3FLAGS= -o runme -all:: modula3 +check: build + $(MAKE) -f $(TOP)/Makefile modula3_run -modula3:: +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3_cpp # $(MAKE) -f $(TOP)/Makefile MODULA3SRCS='$(MODULA3SRCS)' MODULA3FLAGS='$(MODULA3FLAGS)' modula3_compile @@ -17,7 +18,5 @@ modula3:: mv m3makefile $(MODULA3SRCS) src/ cm3 -clean:: +clean: $(MAKE) -f $(TOP)/Makefile modula3_clean - -check: all diff --git a/Examples/modula3/reference/Makefile b/Examples/modula3/reference/Makefile index b31577a58..62183931e 100644 --- a/Examples/modula3/reference/Makefile +++ b/Examples/modula3/reference/Makefile @@ -6,16 +6,15 @@ INTERFACE = example.i SWIGOPT = -c++ MODULA3SRCS = *.[im]3 -all:: modula3 +check: build + $(MAKE) -f $(TOP)/Makefile modula3_run -modula3:: +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3 m3ppinplace $(MODULA3SRCS) mv m3makefile $(MODULA3SRCS) src/ cm3 -clean:: +clean: $(MAKE) -f $(TOP)/Makefile modula3_clean - -check: all diff --git a/Examples/modula3/simple/Makefile b/Examples/modula3/simple/Makefile index 834521fa5..6a0ca4f0e 100644 --- a/Examples/modula3/simple/Makefile +++ b/Examples/modula3/simple/Makefile @@ -6,16 +6,15 @@ INTERFACE = example.i SWIGOPT = MODULA3SRCS = *.[im]3 -all:: modula3 +check: build + $(MAKE) -f $(TOP)/Makefile modula3_run -modula3:: +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3 m3ppinplace $(MODULA3SRCS) mv m3makefile $(MODULA3SRCS) src/ cm3 -clean:: +clean: $(MAKE) -f $(TOP)/Makefile modula3_clean - -check: all diff --git a/Examples/modula3/typemap/Makefile b/Examples/modula3/typemap/Makefile index 834521fa5..6a0ca4f0e 100644 --- a/Examples/modula3/typemap/Makefile +++ b/Examples/modula3/typemap/Makefile @@ -6,16 +6,15 @@ INTERFACE = example.i SWIGOPT = MODULA3SRCS = *.[im]3 -all:: modula3 +check: build + $(MAKE) -f $(TOP)/Makefile modula3_run -modula3:: +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3 m3ppinplace $(MODULA3SRCS) mv m3makefile $(MODULA3SRCS) src/ cm3 -clean:: +clean: $(MAKE) -f $(TOP)/Makefile modula3_clean - -check: all From 238554fe618624b24d2422e80e9de512ec57c497 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Apr 2013 22:33:38 +0100 Subject: [PATCH 0545/1160] Mzscheme example makefiles tweaks for consistency with other languages. Attempt to add runtime tests to 'make check' - untested. --- Examples/Makefile.in | 15 +++++++++++++++ Examples/mzscheme/multimap/Makefile | 10 ++++++---- Examples/mzscheme/simple/Makefile | 10 ++++++---- Examples/mzscheme/std_vector/Makefile | 7 ++++--- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 4ddf9269b..8775af330 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -695,6 +695,13 @@ modula3: $(SRCS) modula3_cpp: $(SRCS) $(SWIG) -modula3 -c++ $(SWIGOPT) $(INTERFACEPATH) +# ----------------------------------------------------------------- +# Run modula3 example +# ----------------------------------------------------------------- + +modula3_run: + $(RUNTOOL) false $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- @@ -719,6 +726,7 @@ MZSCHEME = mzscheme MZC = @MZC@ MZDYNOBJ = @MZDYNOBJ@ MZSCHEME_SO = @MZSCHEME_SO@ +MZSCHEME_SCRIPT = $(RUNME).scm # ---------------------------------------------------------------- # Build a C/C++ dynamically loadable module @@ -734,6 +742,13 @@ mzscheme_cpp: $(SRCS) $(COMPILETOOL) $(MZC) `echo $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(CXXSHARED) $(CFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS) +# ----------------------------------------------------------------- +# Run mzscheme example +# ----------------------------------------------------------------- + +mzscheme_run: + $(RUNTOOL) $(MZSCHEME) -r $(MZSCHEME_SCRIPT) $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- diff --git a/Examples/mzscheme/multimap/Makefile b/Examples/mzscheme/multimap/Makefile index a3cfb8f3c..d1b4a3f39 100644 --- a/Examples/mzscheme/multimap/Makefile +++ b/Examples/mzscheme/multimap/Makefile @@ -4,10 +4,12 @@ SRCS = example.c TARGET = example INTERFACE = example.i SWIGOPT = -all:: + +check: build + $(MAKE) -f $(TOP)/Makefile mzscheme_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme -clean:: +clean: $(MAKE) -f $(TOP)/Makefile mzscheme_clean - -check: all diff --git a/Examples/mzscheme/simple/Makefile b/Examples/mzscheme/simple/Makefile index a3cfb8f3c..d1b4a3f39 100644 --- a/Examples/mzscheme/simple/Makefile +++ b/Examples/mzscheme/simple/Makefile @@ -4,10 +4,12 @@ SRCS = example.c TARGET = example INTERFACE = example.i SWIGOPT = -all:: + +check: build + $(MAKE) -f $(TOP)/Makefile mzscheme_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme -clean:: +clean: $(MAKE) -f $(TOP)/Makefile mzscheme_clean - -check: all diff --git a/Examples/mzscheme/std_vector/Makefile b/Examples/mzscheme/std_vector/Makefile index e18726981..28b91158a 100644 --- a/Examples/mzscheme/std_vector/Makefile +++ b/Examples/mzscheme/std_vector/Makefile @@ -8,12 +8,13 @@ SWIGOPT = GPP = `which g++` MZC = test -n "/usr/bin/mzc" && /usr/bin/mzc -all:: +check: build + $(MAKE) -f $(TOP)/Makefile mzscheme_run + +build: $(SWIG) -mzscheme -c++ $(SWIGOPT) $(INTERFACE) $(MZC) --compiler $(GPP) ++ccf "-I." --cc example_wrap.cxx $(MZC) --linker $(GPP) --ld $(TARGET).so example_wrap.o clean: $(MAKE) -f $(TOP)/Makefile mzscheme_clean - -check: all From 280cd16b7eaad1b22dedf0e36912e7b8803e69ab Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Apr 2013 22:45:01 +0100 Subject: [PATCH 0546/1160] Ocaml example makefiles tweaks for consistency with other languages. Attempt to add runtime tests to 'make check' - untested. --- Examples/Makefile.in | 7 +++++++ Examples/ocaml/argout_ref/Makefile | 13 +++++++------ Examples/ocaml/contract/Makefile | 15 ++++++++------- Examples/ocaml/scoped_enum/Makefile | 15 ++++++++------- Examples/ocaml/shapes/Makefile | 15 ++++++++------- Examples/ocaml/simple/Makefile | 15 ++++++++------- Examples/ocaml/std_string/Makefile | 13 +++++++------ Examples/ocaml/std_vector/Makefile | 13 +++++++------ Examples/ocaml/stl/Makefile | 17 +++++++++-------- Examples/ocaml/string_from_ptr/Makefile | 15 ++++++++------- Examples/ocaml/strings_test/Makefile | 15 ++++++++------- 11 files changed, 85 insertions(+), 68 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 8775af330..feef7ff05 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -893,6 +893,13 @@ ocaml_dynamic_cpp: $(SRCS) -package dl -linkpkg \ $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) -cc '$(CXX) -Wno-write-strings' +# ----------------------------------------------------------------- +# Run ocaml example +# ----------------------------------------------------------------- + +ocaml_run: + $(RUNTOOL) false $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- diff --git a/Examples/ocaml/argout_ref/Makefile b/Examples/ocaml/argout_ref/Makefile index 8a260fe30..4e12e3769 100644 --- a/Examples/ocaml/argout_ref/Makefile +++ b/Examples/ocaml/argout_ref/Makefile @@ -7,21 +7,22 @@ MLFILE = example.ml PROGFILE = example_prog.ml OBJS = example.o -all:: static +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run -static:: +build: static + +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp -dynamic:: +dynamic: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean - -check: all diff --git a/Examples/ocaml/contract/Makefile b/Examples/ocaml/contract/Makefile index 8e0f2a4fd..91d39247e 100644 --- a/Examples/ocaml/contract/Makefile +++ b/Examples/ocaml/contract/Makefile @@ -7,27 +7,28 @@ MLFILE = example.ml PROGFILE = example_prog.ml OBJS = -all:: static +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run -dynamic:: +build: static + +dynamic: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static -toplevel:: +toplevel: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_toplevel -clean:: +clean: $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean - -check: all diff --git a/Examples/ocaml/scoped_enum/Makefile b/Examples/ocaml/scoped_enum/Makefile index 45c5edca4..4920e3b3b 100644 --- a/Examples/ocaml/scoped_enum/Makefile +++ b/Examples/ocaml/scoped_enum/Makefile @@ -7,27 +7,28 @@ MLFILE = example.ml PROGFILE = example_prog.ml OBJS = -all:: static +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run -dynamic:: +build: static + +dynamic: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp -toplevel:: +toplevel: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp_toplevel -clean:: +clean: $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean - -check: all diff --git a/Examples/ocaml/shapes/Makefile b/Examples/ocaml/shapes/Makefile index 31f9934a7..38230eb69 100644 --- a/Examples/ocaml/shapes/Makefile +++ b/Examples/ocaml/shapes/Makefile @@ -8,27 +8,28 @@ MLFILE = example.ml PROGFILE = example_prog.ml OBJS = example.o -all:: static static_top +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run -static:: +build: static static_top + +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp -static_top:: +static_top: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp_toplevel -dynamic:: +dynamic: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean - -check: all diff --git a/Examples/ocaml/simple/Makefile b/Examples/ocaml/simple/Makefile index 4b85bf33e..64c7256c1 100644 --- a/Examples/ocaml/simple/Makefile +++ b/Examples/ocaml/simple/Makefile @@ -7,27 +7,28 @@ MLFILE = example.ml PROGFILE = example_prog.ml OBJS = example.o -all:: static +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run -dynamic:: +build: static + +dynamic: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static -toplevel:: +toplevel: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_toplevel -clean:: +clean: $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean - -check: all diff --git a/Examples/ocaml/std_string/Makefile b/Examples/ocaml/std_string/Makefile index e5a8017ae..0250cfd2d 100644 --- a/Examples/ocaml/std_string/Makefile +++ b/Examples/ocaml/std_string/Makefile @@ -5,19 +5,20 @@ TARGET = example INTERFACE = example.i PROGFILE = runme.ml -all default:: static +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run -static:: +build: static + +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp -dynamic:: +dynamic: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_dynamic_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean - -check: all diff --git a/Examples/ocaml/std_vector/Makefile b/Examples/ocaml/std_vector/Makefile index e5a8017ae..0250cfd2d 100644 --- a/Examples/ocaml/std_vector/Makefile +++ b/Examples/ocaml/std_vector/Makefile @@ -5,19 +5,20 @@ TARGET = example INTERFACE = example.i PROGFILE = runme.ml -all default:: static +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run -static:: +build: static + +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp -dynamic:: +dynamic: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_dynamic_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean - -check: all diff --git a/Examples/ocaml/stl/Makefile b/Examples/ocaml/stl/Makefile index fa4333ec0..545f3229a 100644 --- a/Examples/ocaml/stl/Makefile +++ b/Examples/ocaml/stl/Makefile @@ -5,29 +5,30 @@ TARGET = example INTERFACE = example.i PROGFILE = runme.ml -all default:: static +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run -static:: +build: static + +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp -director:: +director: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp_director -dynamic:: +dynamic: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp -toplevel:: +toplevel: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp_toplevel -clean:: +clean: $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean - -check: all diff --git a/Examples/ocaml/string_from_ptr/Makefile b/Examples/ocaml/string_from_ptr/Makefile index 350d9734c..f7b808934 100644 --- a/Examples/ocaml/string_from_ptr/Makefile +++ b/Examples/ocaml/string_from_ptr/Makefile @@ -8,27 +8,28 @@ MLFILE = foolib.ml PROGFILE = example_prog.ml OBJS = -all:: static static_top +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run -static:: +build: static static_top + +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp -static_top:: +static_top: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp_toplevel -dynamic:: +dynamic: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean - -check: all diff --git a/Examples/ocaml/strings_test/Makefile b/Examples/ocaml/strings_test/Makefile index 8d1f96edf..14f55e0d9 100644 --- a/Examples/ocaml/strings_test/Makefile +++ b/Examples/ocaml/strings_test/Makefile @@ -5,24 +5,25 @@ TARGET = example INTERFACE = example.i PROGFILE = runme.ml -all default:: static top +check: build + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run -static:: +build: static top + +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp -dynamic:: +dynamic: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp -top:: +top: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp_toplevel -clean:: +clean: $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean - -check: all From 9a6167822ba2c64b14e1b7c1c2683c3a7477d336 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Apr 2013 22:49:12 +0100 Subject: [PATCH 0547/1160] Pike example makefiles tweaks for consistency with other languages. Attempt to add runtime tests to 'make check' - untested. --- Examples/Makefile.in | 11 +++++++++-- Examples/pike/class/Makefile | 7 ++++--- Examples/pike/constants/Makefile | 11 ++++++----- Examples/pike/enum/Makefile | 11 ++++++----- Examples/pike/overload/Makefile | 11 ++++++----- Examples/pike/simple/Makefile | 7 ++++--- Examples/pike/template/Makefile | 7 ++++--- 7 files changed, 39 insertions(+), 26 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index feef7ff05..43efdc472 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1048,6 +1048,8 @@ PIKE_CFLAGS = @PIKECCDLFLAGS@ -DHAVE_CONFIG_H PIKE_INCLUDE = @PIKEINCLUDE@ PIKE_LIB = @PIKELIB@ PIKE_DLNK = @PIKEDYNAMICLINKING@ +PIKE_LIBOPTS = @PIKELINK@ @LIBS@ $(SYSLIBS) +PIKE_SCRIPT = $(RUNME).pike # ---------------------------------------------------------------- # Build a C dynamically loadable module @@ -1074,8 +1076,6 @@ pike_cpp: $(SRCS) # library file # ----------------------------------------------------------------- -PIKE_LIBOPTS = @PIKELINK@ @LIBS@ $(SYSLIBS) - pike_static: $(SRCS) $(SWIG) -pike -lembed.i $(SWIGOPT) $(INTERFACEPATH) $(CC) $(CFLAGS) $(PIKE_CFLAGS) @LINKFORSHARED@ $(ISRCS) $(SRCS) $(INCLUDES) \ @@ -1086,6 +1086,13 @@ pike_cpp_static: $(SRCS) $(CXX) $(CFLAGS) $(PIKE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ $(PIKE_INCLUDE) $(LIBS) -L$(PIKE_LIB) $(PIKE_LIBOPTS) -o $(TARGET) +# ----------------------------------------------------------------- +# Run pike example +# ----------------------------------------------------------------- + +pike_run: + $(RUNTOOL) $(PIKE) $(PIKE_SCRIPT) $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- diff --git a/Examples/pike/class/Makefile b/Examples/pike/class/Makefile index 981ccef6f..aadc47151 100644 --- a/Examples/pike/class/Makefile +++ b/Examples/pike/class/Makefile @@ -5,7 +5,10 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all: +check: build + $(MAKE) -f $(TOP)/Makefile pike_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp @@ -15,5 +18,3 @@ static: clean: $(MAKE) -f $(TOP)/Makefile pike_clean - -check: all diff --git a/Examples/pike/constants/Makefile b/Examples/pike/constants/Makefile index 7fa493851..9a882bd4d 100644 --- a/Examples/pike/constants/Makefile +++ b/Examples/pike/constants/Makefile @@ -4,15 +4,16 @@ SRCS = TARGET = example INTERFACE = example.i -all:: +check: build + $(MAKE) -f $(TOP)/Makefile pike_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike -static:: +static: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile pike_clean - -check: all diff --git a/Examples/pike/enum/Makefile b/Examples/pike/enum/Makefile index 0ae102156..aadc47151 100644 --- a/Examples/pike/enum/Makefile +++ b/Examples/pike/enum/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile pike_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile pike_clean - -check: all diff --git a/Examples/pike/overload/Makefile b/Examples/pike/overload/Makefile index 60af005b1..8d799efe1 100644 --- a/Examples/pike/overload/Makefile +++ b/Examples/pike/overload/Makefile @@ -5,15 +5,16 @@ TARGET = example INTERFACE = example.i LIBS = -lstdc++ -lm -all:: +check: build + $(MAKE) -f $(TOP)/Makefile pike_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp -static:: +static: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static -clean:: +clean: $(MAKE) -f $(TOP)/Makefile pike_clean - -check: all diff --git a/Examples/pike/simple/Makefile b/Examples/pike/simple/Makefile index 544c97b5d..f58ed4e65 100644 --- a/Examples/pike/simple/Makefile +++ b/Examples/pike/simple/Makefile @@ -4,7 +4,10 @@ SRCS = example.c TARGET = example INTERFACE = example.i -all: +check: build + $(MAKE) -f $(TOP)/Makefile pike_run + +build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike @@ -14,5 +17,3 @@ static: clean: $(MAKE) -f $(TOP)/Makefile pike_clean - -check: all diff --git a/Examples/pike/template/Makefile b/Examples/pike/template/Makefile index b3f012927..73a31ee1a 100644 --- a/Examples/pike/template/Makefile +++ b/Examples/pike/template/Makefile @@ -6,7 +6,10 @@ INTERFACE = example.i LIBS = -lm SWIGOPT = -all: +check: build + $(MAKE) -f $(TOP)/Makefile pike_run + +build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp @@ -16,5 +19,3 @@ static: clean: $(MAKE) -f $(TOP)/Makefile pike_clean - -check: all From ceb5c59c8d8f81bcc8897a3f5601353caf2f8627 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Apr 2013 22:52:23 +0100 Subject: [PATCH 0548/1160] XML example makefiles tweaks for consistency with other languages --- Examples/xml/Makefile.in | 2 -- 1 file changed, 2 deletions(-) diff --git a/Examples/xml/Makefile.in b/Examples/xml/Makefile.in index dfda4a646..27c86e3e9 100644 --- a/Examples/xml/Makefile.in +++ b/Examples/xml/Makefile.in @@ -19,8 +19,6 @@ all-dot-i-files = \ example_xml.i \ gnarly.i -all: check - chk-swiglib = $(top_srcdir)/Lib check: From e3d0947058206f29c41c2d3631858661267bed80 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Apr 2013 23:09:49 +0100 Subject: [PATCH 0549/1160] D example makefiles tweaks for consistency with other languages. --- Examples/Makefile.in | 4 +++- Examples/d/callback/Makefile | 13 +++++-------- Examples/d/class/Makefile | 13 +++++-------- Examples/d/constants/Makefile | 13 +++++-------- Examples/d/enum/Makefile | 13 +++++-------- Examples/d/extend/Makefile | 13 +++++-------- Examples/d/funcptr/Makefile | 13 +++++-------- Examples/d/simple/Makefile | 13 +++++-------- Examples/d/variables/Makefile | 13 +++++-------- 9 files changed, 43 insertions(+), 65 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 43efdc472..b95d9e129 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1650,6 +1650,8 @@ else DCOMPILER = @D1COMPILER@ endif +D_RUNME = ./$(RUNME) + # ---------------------------------------------------------------- # Build a dynamically loadable D wrapper for a C module # ---------------------------------------------------------------- @@ -1682,7 +1684,7 @@ d_compile: $(SRCS) # ----------------------------------------------------------------- d_run: - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme + $(RUNTOOL) $(D_RUNME) $(RUNPIPE) # ----------------------------------------------------------------- # Version display diff --git a/Examples/d/callback/Makefile b/Examples/d/callback/Makefile index b5808cf0d..eda18f13c 100644 --- a/Examples/d/callback/Makefile +++ b/Examples/d/callback/Makefile @@ -13,18 +13,15 @@ SWIGOPT = DSRCS = *.d DFLAGS = -ofrunme +check: build + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run -all:: d - -d:: +build: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile -clean:: +clean: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile d_clean - -check: all - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run diff --git a/Examples/d/class/Makefile b/Examples/d/class/Makefile index b5808cf0d..eda18f13c 100644 --- a/Examples/d/class/Makefile +++ b/Examples/d/class/Makefile @@ -13,18 +13,15 @@ SWIGOPT = DSRCS = *.d DFLAGS = -ofrunme +check: build + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run -all:: d - -d:: +build: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile -clean:: +clean: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile d_clean - -check: all - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run diff --git a/Examples/d/constants/Makefile b/Examples/d/constants/Makefile index 412055243..d537ce281 100644 --- a/Examples/d/constants/Makefile +++ b/Examples/d/constants/Makefile @@ -13,18 +13,15 @@ SWIGOPT = DSRCS = *.d DFLAGS = -ofrunme +check: build + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run -all:: d - -d:: +build: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile -clean:: +clean: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile d_clean - -check: all - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run diff --git a/Examples/d/enum/Makefile b/Examples/d/enum/Makefile index b5808cf0d..eda18f13c 100644 --- a/Examples/d/enum/Makefile +++ b/Examples/d/enum/Makefile @@ -13,18 +13,15 @@ SWIGOPT = DSRCS = *.d DFLAGS = -ofrunme +check: build + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run -all:: d - -d:: +build: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile -clean:: +clean: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile d_clean - -check: all - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run diff --git a/Examples/d/extend/Makefile b/Examples/d/extend/Makefile index b5808cf0d..eda18f13c 100644 --- a/Examples/d/extend/Makefile +++ b/Examples/d/extend/Makefile @@ -13,18 +13,15 @@ SWIGOPT = DSRCS = *.d DFLAGS = -ofrunme +check: build + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run -all:: d - -d:: +build: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile -clean:: +clean: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile d_clean - -check: all - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run diff --git a/Examples/d/funcptr/Makefile b/Examples/d/funcptr/Makefile index 09efa8d88..2ba893ca7 100644 --- a/Examples/d/funcptr/Makefile +++ b/Examples/d/funcptr/Makefile @@ -13,18 +13,15 @@ SWIGOPT = DSRCS = *.d DFLAGS = -ofrunme +check: build + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run -all:: d - -d:: +build: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile -clean:: +clean: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile d_clean - -check: all - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run diff --git a/Examples/d/simple/Makefile b/Examples/d/simple/Makefile index ae173a566..a8808c9c5 100644 --- a/Examples/d/simple/Makefile +++ b/Examples/d/simple/Makefile @@ -13,18 +13,15 @@ SWIGOPT = DSRCS = *.d DFLAGS = -ofrunme +check: build + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run -all:: d - -d:: +build: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile -clean:: +clean: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile d_clean - -check: all - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run diff --git a/Examples/d/variables/Makefile b/Examples/d/variables/Makefile index ae173a566..a8808c9c5 100644 --- a/Examples/d/variables/Makefile +++ b/Examples/d/variables/Makefile @@ -13,18 +13,15 @@ SWIGOPT = DSRCS = *.d DFLAGS = -ofrunme +check: build + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run -all:: d - -d:: +build: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile -clean:: +clean: cd $(WORKING_DIR); \ $(MAKE) -f $(TOP)/Makefile d_clean - -check: all - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run From ea84fe6445e9ac9a8cd097260eaca4a17ab0e609 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 16 Apr 2013 07:26:12 +0100 Subject: [PATCH 0550/1160] Allegrocl, clisp, cffi, uffi makefile targets added for running examples - untested. --- Examples/Makefile.in | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index b95d9e129..f5b93dbe9 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1369,6 +1369,7 @@ lua_clean: ################################################################## ALLEGROCL = @ALLEGROCLBIN@ +ALLEGROCL_SCRIPT=$(RUNME).lisp allegrocl: $(SRCS) $(SWIG) -allegrocl -cwrap $(SWIGOPT) $(INTERFACEPATH) @@ -1380,6 +1381,13 @@ allegrocl_cpp: $(SRCS) $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +# ----------------------------------------------------------------- +# Run ALLEGRO CL example +# ----------------------------------------------------------------- + +allegrocl_run: + $(RUNTOOL) $(ALLEGROCL) -batch -s $(ALLEGROCL_SCRIPT) $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- @@ -1401,6 +1409,7 @@ allegrocl_clean: ################################################################## CLISP = @CLISPBIN@ +CLISP_SCRIPT=$(RUNME).lisp clisp: $(SRCS) $(SWIG) -clisp $(SWIGOPT) $(INTERFACEPATH) @@ -1408,6 +1417,13 @@ clisp: $(SRCS) clisp_cpp: $(SRCS) $(SWIG) -c++ -clisp $(SWIGOPT) $(INTERFACEPATH) +# ----------------------------------------------------------------- +# Run CLISP example +# ----------------------------------------------------------------- + +clisp_run: + $(RUNTOOL) $(CLISP) -batch -s $(CLISP_SCRIPT) $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- @@ -1429,6 +1445,7 @@ clisp_clean: ################################################################## CFFI = @CFFIBIN@ +CFFI_SCRIPT=$(RUNME).lisp cffi: $(SRCS) $(SWIG) -cffi $(SWIGOPT) $(INTERFACEPATH) @@ -1440,6 +1457,13 @@ cffi_cpp: $(SRCS) $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +# ----------------------------------------------------------------- +# Run CFFI example +# ----------------------------------------------------------------- + +cffi_run: + $(RUNTOOL) $(CFFI) -batch -s $(CFFI_SCRIPT) $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- @@ -1461,6 +1485,7 @@ cffi_clean: ################################################################## UFFI = @UFFIBIN@ +UFFI_SCRIPT=$(RUNME).lisp uffi: $(SRCS) $(SWIG) -uffi $(SWIGOPT) $(INTERFACEPATH) @@ -1472,6 +1497,13 @@ uffi_cpp: $(SRCS) # $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) # $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +# ----------------------------------------------------------------- +# Run UFFI example +# ----------------------------------------------------------------- + +uffi_run: + $(RUNTOOL) $(UFFI) -batch -s $(UFFI_SCRIPT) $(RUNPIPE) + # ----------------------------------------------------------------- # Version display # ----------------------------------------------------------------- From 1f4bd0bfa5bc1bef809764a99e56186cb3df88de Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Apr 2013 23:12:47 +0100 Subject: [PATCH 0551/1160] Minor extraneous makefiles tidy up --- Lib/guile/Makefile | 2 +- Lib/mzscheme/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/guile/Makefile b/Lib/guile/Makefile index ff66f9efa..17f5feced 100644 --- a/Lib/guile/Makefile +++ b/Lib/guile/Makefile @@ -1,4 +1,4 @@ -co:: +co: co RCS/*.i* RCS/*.swg* diff --git a/Lib/mzscheme/Makefile b/Lib/mzscheme/Makefile index ff66f9efa..17f5feced 100644 --- a/Lib/mzscheme/Makefile +++ b/Lib/mzscheme/Makefile @@ -1,4 +1,4 @@ -co:: +co: co RCS/*.i* RCS/*.swg* From 303b319cf061144c1862d0e0687bb712ffb8126c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 20 Apr 2013 00:22:07 +0100 Subject: [PATCH 0552/1160] Add ability to see example output from top level by using 'make check-examples RUNPIPE=' --- Makefile.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 04d65a107..c47cdbe7c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -22,6 +22,7 @@ TARGET = $(TARGET_NOEXE)@EXEEXT@ SOURCE = Source CCACHE = CCache DOCS = Doc/Manual +RUNPIPE = \>/dev/null swig: libfiles source ccache @@ -229,7 +230,7 @@ check-%-examples : # individual example %.actionexample: @echo $(ACTION)ing Examples/$(LANGUAGE)/$* - @(cd Examples/$(LANGUAGE)/$* && $(MAKE) -s $(chk-set-env) $(ACTION) RUNPIPE=\>/dev/null) + @(cd Examples/$(LANGUAGE)/$* && $(MAKE) -s $(chk-set-env) $(ACTION) RUNPIPE=$(RUNPIPE)) # gcj individual example java.actionexample: From 13b66c997e7ce685031d15768c860cffa426f4dc Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 20 Apr 2013 00:02:23 +0100 Subject: [PATCH 0553/1160] Guile example makefiles - run some of the examples in the check target. Still some are missing. Add some missing examples to check.list. --- Examples/guile/check.list | 4 +++- Examples/guile/matrix/Makefile | 1 + Examples/guile/port/Makefile | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Examples/guile/check.list b/Examples/guile/check.list index 7ccd0730a..08524a8f7 100644 --- a/Examples/guile/check.list +++ b/Examples/guile/check.list @@ -1,6 +1,8 @@ # see top-level Makefile.in constants -simple port +simple +std_vector +matrix multimap multivalue diff --git a/Examples/guile/matrix/Makefile b/Examples/guile/matrix/Makefile index 551debe06..e8466e5fc 100644 --- a/Examples/guile/matrix/Makefile +++ b/Examples/guile/matrix/Makefile @@ -4,6 +4,7 @@ IFILE = package.i MKDIR = .. check: build + ./$(TARGET) -e do-test -s matrix.scm build: $(MAKE) -f $(MKDIR)/Makefile \ diff --git a/Examples/guile/port/Makefile b/Examples/guile/port/Makefile index 2d81f44ca..33eeab2e9 100644 --- a/Examples/guile/port/Makefile +++ b/Examples/guile/port/Makefile @@ -4,6 +4,7 @@ IFILE = port.i MKDIR = .. check: build + ./$(TARGET) -s port.scm build: $(MAKE) -f $(MKDIR)/Makefile \ From 7fd18b361e447e5705582bf28ebf163fa94d5e6a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 20 Apr 2013 00:22:48 +0100 Subject: [PATCH 0554/1160] Ocaml example makefiles - run examples - there are plenty of problems currently though --- Examples/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index f5b93dbe9..7ace11062 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -898,7 +898,7 @@ ocaml_dynamic_cpp: $(SRCS) # ----------------------------------------------------------------- ocaml_run: - $(RUNTOOL) false $(RUNPIPE) + $(RUNTOOL) ./$(TARGET) $(RUNPIPE) # ----------------------------------------------------------------- # Version display From 62638bfd15a14420a6bbf83b3907cdb289093acd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 20 Apr 2013 00:56:04 +0100 Subject: [PATCH 0555/1160] Pike - a few updates to get Pike 7.8 running most of the examples --- Examples/pike/check.list | 2 ++ Lib/pike/pike.swg | 6 +++--- Lib/pike/pikerun.swg | 5 +++-- configure.ac | 17 ++++++++++------- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Examples/pike/check.list b/Examples/pike/check.list index a8d348bf1..d6c8e2e7b 100644 --- a/Examples/pike/check.list +++ b/Examples/pike/check.list @@ -2,4 +2,6 @@ class constants enum +overload simple +template diff --git a/Lib/pike/pike.swg b/Lib/pike/pike.swg index 130af1346..399752a7a 100644 --- a/Lib/pike/pike.swg +++ b/Lib/pike/pike.swg @@ -11,9 +11,9 @@ #ifdef __cplusplus extern "C" { #endif -#include -#include -#include +#include +#include +#include #ifdef __cplusplus } #endif diff --git a/Lib/pike/pikerun.swg b/Lib/pike/pikerun.swg index 70d40fac9..6ec1143cf 100644 --- a/Lib/pike/pikerun.swg +++ b/Lib/pike/pikerun.swg @@ -9,11 +9,12 @@ #ifdef __cplusplus extern "C" { #endif -#include "object.h" -#include "program.h" +#include "pike/object.h" +#include "pike/program.h" #ifdef __cplusplus } #endif +#include /* Stores information about a wrapped object */ typedef struct swig_object_wrapper { diff --git a/configure.ac b/configure.ac index 65a9c9078..83b46f520 100644 --- a/configure.ac +++ b/configure.ac @@ -1618,18 +1618,21 @@ AC_ARG_WITH(pikeincl, AS_HELP_STRING([--with-pikeincl=path], if test -n "$PIKE"; then AC_MSG_CHECKING([for Pike header files]) if test -z "$PIKEINCLUDE" -a -n "$PIKECONFIG"; then - PIKEINCLUDE=`$PIKECONFIG --cflags` + PIKEINCLUDE=`$PIKECONFIG --cflags` fi if test -z "$PIKEINCLUDE" -a -n "$PIKE"; then - PIKEPATH=`which $PIKE` - PIKEINCLUDE=`$PIKE Tools/check-include-path.pike $PIKEPATH` - PIKEINCLUDE="-I$PIKEINCLUDE" + PIKEINCLUDE=`$PIKE -x cflags` + if test -z "$PIKEINCLUDE"; then + PIKEPATH=`which $PIKE` + PIKEINCLUDE=`$PIKE Tools/check-include-path.pike $PIKEPATH` + PIKEINCLUDE="-I$PIKEINCLUDE" + fi fi if test -z "$PIKEINCLUDE"; then - AC_MSG_RESULT(not found) + AC_MSG_RESULT(not found) else - AC_MSG_RESULT($PIKEINCLUDE) + AC_MSG_RESULT($PIKEINCLUDE) fi fi fi @@ -2305,7 +2308,7 @@ fi AC_SUBST(SKIP_OCAML) -SKIP_PIKE="1" # Always skipped! +SKIP_PIKE= if test -z "$PIKE" || test -z "$PIKEINCLUDE" ; then SKIP_PIKE="1" fi From 2b2305cce938f25cf91de50b753d95cf76e367d4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 20 Apr 2013 01:23:54 +0100 Subject: [PATCH 0556/1160] Mzscheme - fix for running examples during 'make check-examples' - they don't run very well though\! --- Examples/Makefile.in | 2 +- Examples/mzscheme/check.list | 1 + Examples/mzscheme/multimap/{example.scm => runme.scm} | 4 ++-- Examples/mzscheme/simple/{example.scm => runme.scm} | 2 +- Examples/mzscheme/std_vector/{example.scm => runme.scm} | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) rename Examples/mzscheme/multimap/{example.scm => runme.scm} (89%) rename Examples/mzscheme/simple/{example.scm => runme.scm} (92%) rename Examples/mzscheme/std_vector/{example.scm => runme.scm} (97%) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 7ace11062..c7257ac4c 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -747,7 +747,7 @@ mzscheme_cpp: $(SRCS) # ----------------------------------------------------------------- mzscheme_run: - $(RUNTOOL) $(MZSCHEME) -r $(MZSCHEME_SCRIPT) $(RUNPIPE) + env LD_LIBRARY_PATH=. $(RUNTOOL) $(MZSCHEME) -r $(MZSCHEME_SCRIPT) $(RUNPIPE) # ----------------------------------------------------------------- # Version display diff --git a/Examples/mzscheme/check.list b/Examples/mzscheme/check.list index ae728ea43..f9e4f11c7 100644 --- a/Examples/mzscheme/check.list +++ b/Examples/mzscheme/check.list @@ -1,3 +1,4 @@ # see top-level Makefile.in multimap simple +std_vector diff --git a/Examples/mzscheme/multimap/example.scm b/Examples/mzscheme/multimap/runme.scm similarity index 89% rename from Examples/mzscheme/multimap/example.scm rename to Examples/mzscheme/multimap/runme.scm index ac9f64283..f1e626f43 100644 --- a/Examples/mzscheme/multimap/example.scm +++ b/Examples/mzscheme/multimap/runme.scm @@ -1,4 +1,4 @@ -;; run with mzscheme -r example.scm +;; run with mzscheme -r runme.scm (load-extension "example.so") @@ -24,4 +24,4 @@ (newline) (display (capitalize "hello world")) -(newline) \ No newline at end of file +(newline) diff --git a/Examples/mzscheme/simple/example.scm b/Examples/mzscheme/simple/runme.scm similarity index 92% rename from Examples/mzscheme/simple/example.scm rename to Examples/mzscheme/simple/runme.scm index 8e20345b2..a98e31fd5 100644 --- a/Examples/mzscheme/simple/example.scm +++ b/Examples/mzscheme/simple/runme.scm @@ -1,4 +1,4 @@ -;; run with mzscheme -r example.scm +;; run with mzscheme -r runme.scm (load-extension "example.so") diff --git a/Examples/mzscheme/std_vector/example.scm b/Examples/mzscheme/std_vector/runme.scm similarity index 97% rename from Examples/mzscheme/std_vector/example.scm rename to Examples/mzscheme/std_vector/runme.scm index 0e4ac3f97..67351f128 100644 --- a/Examples/mzscheme/std_vector/example.scm +++ b/Examples/mzscheme/std_vector/runme.scm @@ -1,4 +1,4 @@ -;; run with mzscheme -r example.scm +;; run with mzscheme -r runme.scm (load-extension "example.so") From 58a59919dddfe19cef2ca72db8a883f2344e16fc Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 20 Apr 2013 02:13:17 +0100 Subject: [PATCH 0557/1160] Chicken - make check-examples run like other examples - not all run very well though! --- Examples/Makefile.in | 4 ++-- Examples/chicken/class/Makefile | 20 +++++++++---------- ...-lowlevel-class.scm => runme-lowlevel.scm} | 0 ...-tinyclos-class.scm => runme-tinyclos.scm} | 0 Examples/chicken/constants/Makefile | 10 +++++----- .../{test-constants.scm => runme.scm} | 0 Examples/chicken/multimap/Makefile | 10 +++++----- .../multimap/{test-multimap.scm => runme.scm} | 1 - Examples/chicken/overload/Makefile | 10 +++++----- .../overload/{test-overload.scm => runme.scm} | 0 Examples/chicken/simple/Makefile | 10 +++++----- .../simple/{test-simple.scm => runme.scm} | 0 12 files changed, 32 insertions(+), 33 deletions(-) rename Examples/chicken/class/{test-lowlevel-class.scm => runme-lowlevel.scm} (100%) rename Examples/chicken/class/{test-tinyclos-class.scm => runme-tinyclos.scm} (100%) rename Examples/chicken/constants/{test-constants.scm => runme.scm} (100%) rename Examples/chicken/multimap/{test-multimap.scm => runme.scm} (97%) rename Examples/chicken/overload/{test-overload.scm => runme.scm} (100%) rename Examples/chicken/simple/{test-simple.scm => runme.scm} (100%) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index c7257ac4c..c0cdb703f 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1122,7 +1122,7 @@ CHICKEN_SHAREDLIBOPTS = @CHICKENSHAREDLIB@ $(SYSLIBS) CHICKEN_CFLAGS = @CHICKENOPTS@ CHICKENOPTS = -quiet CHICKEN_MAIN = -CHICKEN_SCRIPT = $(RUNME).ss +CHICKEN_SCRIPT = $(RUNME).scm # SWIG produces $(ISRCS) (the C wrapper file) # and $(CHICKEN_GENERATED_SCHEME) (the Scheme wrapper file): @@ -1208,7 +1208,7 @@ chicken_externalhdr: # ----------------------------------------------------------------- chicken_run: - $(RUNTOOL) $(CHICKEN_CSI) $(CHICKEN_SCRIPT) $(RUNPIPE) + env LD_LIBRARY_PATH=. $(RUNTOOL) $(CHICKEN_CSI) $(CHICKEN_SCRIPT) $(RUNPIPE) # ----------------------------------------------------------------- # Version display diff --git a/Examples/chicken/class/Makefile b/Examples/chicken/class/Makefile index 976651e94..1436d836f 100644 --- a/Examples/chicken/class/Makefile +++ b/Examples/chicken/class/Makefile @@ -10,27 +10,27 @@ CFLAGS = VARIANT = # uncomment the following lines to build a static exe (only pick one of the CHICKEN_MAIN lines) -#CHICKEN_MAIN = test-lowlevel-class.scm -#CHICKEN_MAIN = test-tinyclos-class.scm +#CHICKEN_MAIN = runme-lowlevel.scm +#CHICKEN_MAIN = runme-tinyclos.scm #VARIANT = _static check: build - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-lowlevel-class.scm - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-tinyclos-class.scm + $(MAKE) -f $(TOP)/Makefile CHICKEN_SCRIPT='runme-lowlevel.scm' chicken_run + $(MAKE) -f $(TOP)/Makefile CHICKEN_SCRIPT='runme-tinyclos.scm' chicken_run build: $(TARGET) $(TARGET)_proxy $(TARGET): $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile \ - SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ - INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ - SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp + SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ + INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ + SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp $(TARGET)_proxy: $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile \ - SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ - INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT) -proxy' TARGET='$(TARGET)_proxy' \ - SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp + SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ + INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT) -proxy' TARGET='$(TARGET)_proxy' \ + SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp clean: $(MAKE) -f $(TOP)/Makefile chicken_clean diff --git a/Examples/chicken/class/test-lowlevel-class.scm b/Examples/chicken/class/runme-lowlevel.scm similarity index 100% rename from Examples/chicken/class/test-lowlevel-class.scm rename to Examples/chicken/class/runme-lowlevel.scm diff --git a/Examples/chicken/class/test-tinyclos-class.scm b/Examples/chicken/class/runme-tinyclos.scm similarity index 100% rename from Examples/chicken/class/test-tinyclos-class.scm rename to Examples/chicken/class/runme-tinyclos.scm diff --git a/Examples/chicken/constants/Makefile b/Examples/chicken/constants/Makefile index 41ca7ae11..31e39d346 100644 --- a/Examples/chicken/constants/Makefile +++ b/Examples/chicken/constants/Makefile @@ -10,19 +10,19 @@ CFLAGS = VARIANT = # uncomment the following two lines to build a static exe -#CHICKEN_MAIN = test-constants.scm +#CHICKEN_MAIN = runme.scm #VARIANT = _static check: build - csi test-constants.scm + $(MAKE) -f $(TOP)/Makefile chicken_run build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile \ - SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ - INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ - SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) + SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ + INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ + SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) clean: $(MAKE) -f $(TOP)/Makefile chicken_clean diff --git a/Examples/chicken/constants/test-constants.scm b/Examples/chicken/constants/runme.scm similarity index 100% rename from Examples/chicken/constants/test-constants.scm rename to Examples/chicken/constants/runme.scm diff --git a/Examples/chicken/multimap/Makefile b/Examples/chicken/multimap/Makefile index 4ae5a9cf3..eba36169d 100644 --- a/Examples/chicken/multimap/Makefile +++ b/Examples/chicken/multimap/Makefile @@ -10,19 +10,19 @@ CFLAGS = VARIANT = # uncomment the following two lines to build a static exe -#CHICKEN_MAIN = test-multimap.scm +#CHICKEN_MAIN = runme.scm #VARIANT = _static check: build - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-multimap.scm + $(MAKE) -f $(TOP)/Makefile chicken_run build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile \ - SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ - INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ - SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) + SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ + INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ + SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) clean: $(MAKE) -f $(TOP)/Makefile chicken_clean diff --git a/Examples/chicken/multimap/test-multimap.scm b/Examples/chicken/multimap/runme.scm similarity index 97% rename from Examples/chicken/multimap/test-multimap.scm rename to Examples/chicken/multimap/runme.scm index 3a6b46e2c..ebe644004 100644 --- a/Examples/chicken/multimap/test-multimap.scm +++ b/Examples/chicken/multimap/runme.scm @@ -1,4 +1,3 @@ -;; run with './multimap test-multimap.scm' ;; feel free to uncomment and comment sections (load-library 'example "multimap.so") diff --git a/Examples/chicken/overload/Makefile b/Examples/chicken/overload/Makefile index 584fa52a2..e15352ec5 100644 --- a/Examples/chicken/overload/Makefile +++ b/Examples/chicken/overload/Makefile @@ -10,19 +10,19 @@ CFLAGS = VARIANT = # uncomment the following lines to build a static exe -#CHICKEN_MAIN = test-overload.scm +#CHICKEN_MAIN = runme.scm #VARIANT = _static check: build - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-overload.scm + $(MAKE) -f $(TOP)/Makefile chicken_run build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile \ - SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ - INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ - SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp + SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ + INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ + SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp clean: $(MAKE) -f $(TOP)/Makefile chicken_clean diff --git a/Examples/chicken/overload/test-overload.scm b/Examples/chicken/overload/runme.scm similarity index 100% rename from Examples/chicken/overload/test-overload.scm rename to Examples/chicken/overload/runme.scm diff --git a/Examples/chicken/simple/Makefile b/Examples/chicken/simple/Makefile index 1b03497cd..f8fb006a4 100644 --- a/Examples/chicken/simple/Makefile +++ b/Examples/chicken/simple/Makefile @@ -10,19 +10,19 @@ CFLAGS = VARIANT = # uncomment the following two lines to build a static exe -#CHICKEN_MAIN = test-simple.scm +#CHICKEN_MAIN = runme.scm #VARIANT = _static check: build - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-simple.scm + $(MAKE) -f $(TOP)/Makefile chicken_run build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile \ - SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ - INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ - SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) + SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ + INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ + SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) clean: $(MAKE) -f $(TOP)/Makefile chicken_clean diff --git a/Examples/chicken/simple/test-simple.scm b/Examples/chicken/simple/runme.scm similarity index 100% rename from Examples/chicken/simple/test-simple.scm rename to Examples/chicken/simple/runme.scm From 9f95e30650737df2a22ebfb780169181c9d18695 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 20 Apr 2013 02:51:57 +0100 Subject: [PATCH 0558/1160] Fix PHP test-suite running examples recently broken in 0fa791d --- Examples/test-suite/php/Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/php/Makefile.in b/Examples/test-suite/php/Makefile.in index d4f9ac9b5..fcdcac2b9 100644 --- a/Examples/test-suite/php/Makefile.in +++ b/Examples/test-suite/php/Makefile.in @@ -57,9 +57,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 PHP_SCRIPT=$(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 PHP_SCRIPT=$(srcdir)/$(SCRIPTPREFIX)$*.php RUNTOOL="$(RUNTOOL)" php_run; \ fi # Clean: remove the generated .php file From 205d50a8c96c6ed01cbc94adec6c731b52efb5e4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 21 Apr 2013 14:05:56 +0100 Subject: [PATCH 0559/1160] Ruby 1.9 fixes: use ruby -I in Makefile and workaround clash with 1.9 builtin Complex numbers in the operator example. --- Examples/Makefile.in | 2 +- Examples/ruby/operator/runme.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index c0cdb703f..240274278 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -970,7 +970,7 @@ ruby_cpp_static: $(SRCS) # ----------------------------------------------------------------- ruby_run: - $(RUNTOOL) $(RUBY) $(RUBY_SCRIPT) $(RUNPIPE) + $(RUNTOOL) $(RUBY) -I. $(RUBY_SCRIPT) $(RUNPIPE) # ----------------------------------------------------------------- # Version display diff --git a/Examples/ruby/operator/runme.rb b/Examples/ruby/operator/runme.rb index 518d91e9e..4c1ef3f62 100644 --- a/Examples/ruby/operator/runme.rb +++ b/Examples/ruby/operator/runme.rb @@ -3,8 +3,8 @@ require 'example' include Example -a = Complex.new(2, 3) -b = Complex.new(-5, 10) +a = Example::Complex.new(2, 3) +b = Example::Complex.new(-5, 10) puts "a = #{a}" puts "b = #{b}" @@ -15,7 +15,7 @@ puts "a*b = #{a*b}" puts "a-c = #{a-c}" # This should invoke Complex's copy constructor -e = Complex.new(a-c) +e = Example::Complex.new(a-c) e = a - c puts "e = #{e}" From 486eca2faa5d7d61a97d3a4e0f033391be98baf2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 21 Apr 2013 18:24:37 +0100 Subject: [PATCH 0560/1160] Disable Ruby free_function test for now. It is failing in Travis builds with 'ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]' but okay with 'ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]'. Relying on timely Garbage collection is probably flawed anyway. --- Examples/ruby/check.list | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/ruby/check.list b/Examples/ruby/check.list index 131dcbb33..2e581fb82 100644 --- a/Examples/ruby/check.list +++ b/Examples/ruby/check.list @@ -2,7 +2,7 @@ class constants enum -free_function +#free_function funcptr funcptr2 functor From 6e06b50adf814b3e4a519ceaebcb18edd7ac80dd Mon Sep 17 00:00:00 2001 From: Yung Lee Date: Sun, 21 Apr 2013 01:01:39 +0800 Subject: [PATCH 0561/1160] Remove non-ascii characters at a comment line in d.cxx that trouble VC++ --- Source/Modules/d.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index e09e253f8..5d59a2e38 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -3743,7 +3743,7 @@ private: String *nspace = getNSpace(); if (nspace) { // Check the root package/outermost namespace (a class A in module - // A.B leads to problems if another module A.C is also imported)… + // A.B leads to problems if another module A.C is also imported) if (Len(package) > 0) { String *dotless_package = NewStringWithSize(package, Len(package) - 1); if (Cmp(class_name, dotless_package) == 0) { From bdf98744b165861f67e325b892d2a65c96a2f8fa Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 23 Apr 2013 22:18:42 +0100 Subject: [PATCH 0562/1160] Fix guilescm_ext_test and chicken_ext_test testcases --- ...ext_test_external.cxx => chicken_ext_test_external.cxx} | 7 +++---- ...xt_test_external.cxx => guilescm_ext_test_external.cxx} | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) rename Examples/test-suite/chicken/{ext_test_external.cxx => chicken_ext_test_external.cxx} (90%) rename Examples/test-suite/guilescm/{ext_test_external.cxx => guilescm_ext_test_external.cxx} (90%) diff --git a/Examples/test-suite/chicken/ext_test_external.cxx b/Examples/test-suite/chicken/chicken_ext_test_external.cxx similarity index 90% rename from Examples/test-suite/chicken/ext_test_external.cxx rename to Examples/test-suite/chicken/chicken_ext_test_external.cxx index 338151e88..1dd6a7d53 100644 --- a/Examples/test-suite/chicken/ext_test_external.cxx +++ b/Examples/test-suite/chicken/chicken_ext_test_external.cxx @@ -1,4 +1,4 @@ -#include +#include #include void test_create(C_word,C_word,C_word) C_noret; @@ -7,16 +7,15 @@ void test_create(C_word argc, C_word closure, C_word continuation) { swig_type_info *type; A *newobj; C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); - + C_trace("test-create"); if (argc!=2) C_bad_argc(argc,2); newobj = new A(); - + type = SWIG_TypeQuery("A *"); resultobj = SWIG_NewPointerObj(newobj, type, 1); C_kontinue(continuation, resultobj); } - diff --git a/Examples/test-suite/guilescm/ext_test_external.cxx b/Examples/test-suite/guilescm/guilescm_ext_test_external.cxx similarity index 90% rename from Examples/test-suite/guilescm/ext_test_external.cxx rename to Examples/test-suite/guilescm/guilescm_ext_test_external.cxx index 713e5d2d0..30fa1ce7b 100644 --- a/Examples/test-suite/guilescm/ext_test_external.cxx +++ b/Examples/test-suite/guilescm/guilescm_ext_test_external.cxx @@ -1,4 +1,4 @@ -#include +#include #include SCM test_create() From 52858d5353a1e656f10561ec8e33df3bca4da520 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 27 Apr 2013 18:40:57 +0100 Subject: [PATCH 0563/1160] Fix boost intrusive_ptr testcase compilation with latest boost/gcc --- Examples/test-suite/li_boost_intrusive_ptr.i | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Examples/test-suite/li_boost_intrusive_ptr.i b/Examples/test-suite/li_boost_intrusive_ptr.i index 2efa998a9..4916d0285 100644 --- a/Examples/test-suite/li_boost_intrusive_ptr.i +++ b/Examples/test-suite/li_boost_intrusive_ptr.i @@ -13,9 +13,12 @@ %warnfilter(SWIGWARN_LANG_SMARTPTR_MISSING) KlassDerived; %warnfilter(SWIGWARN_LANG_SMARTPTR_MISSING) KlassDerivedDerived; -%inline %{ -#include "boost/shared_ptr.hpp" -#include "boost/intrusive_ptr.hpp" +%{ +template void intrusive_ptr_add_ref(const T* r) { r->addref(); } +template void intrusive_ptr_release(const T* r) { r->release(); } + +#include +#include #include // Uncomment macro below to turn on intrusive_ptr memory leak checking as described above @@ -102,8 +105,6 @@ %ignore IgnoredRefCountingBase; %ignore *::operator=; -%ignore intrusive_ptr_add_ref; -%ignore intrusive_ptr_release; %newobject pointerownertest(); %newobject smartpointerpointerownertest(); @@ -430,10 +431,6 @@ template struct Pair : Base { Pair pair_id2(Pair p) { return p; } SwigBoost::intrusive_ptr< Pair > pair_id1(SwigBoost::intrusive_ptr< Pair > p) { return p; } -template void intrusive_ptr_add_ref(const T* r) { r->addref(); } - -template void intrusive_ptr_release(const T* r) { r->release(); } - long use_count(const SwigBoost::shared_ptr& sptr) { return sptr.use_count(); } From 99231457dbe6436df46c8d4d6b22aa906cf48e6d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 28 Apr 2013 17:59:40 +0100 Subject: [PATCH 0564/1160] Fixes for warnings issued by clang --- Source/Modules/lua.cxx | 2 -- Source/Modules/modula3.cxx | 19 ------------------- 2 files changed, 21 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index cfb3a3f5b..a33898a2f 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -106,7 +106,6 @@ private: File *f_wrappers; File *f_init; File *f_initbeforefunc; - String *PrefixPlusUnderscore; String *s_cmd_tab; // table of command names String *s_var_tab; // table of global variables String *s_const_tab; // table of global constants @@ -150,7 +149,6 @@ public: f_wrappers(0), f_init(0), f_initbeforefunc(0), - PrefixPlusUnderscore(0), s_cmd_tab(0), s_var_tab(0), s_const_tab(0), diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index ffb172f8f..4c56d0664 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -204,9 +204,6 @@ private: String *proxy_class_name; String *variable_name; //Name of a variable being wrapped String *variable_type; //Type of this variable - String *enumeration_name; //Name of the current enumeration type - Hash *enumeration_items; //and its members - int enumeration_max; Hash *enumeration_coll; //Collection of all enumerations. /* The items are nodes with members: "items" - hash of with key 'itemname' and content 'itemvalue' @@ -268,9 +265,6 @@ MODULA3(): proxy_class_name(NULL), variable_name(NULL), variable_type(NULL), - enumeration_name(NULL), - enumeration_items(NULL), - enumeration_max(0), enumeration_coll(NULL), constant_values(NULL), constantfilename(NULL), @@ -1784,19 +1778,6 @@ MODULA3(): } } -#if 0 - void generateEnumerationItem(const String *name, const String *value, int numvalue) { - String *oldsymname = Getattr(enumeration_items, value); - if (oldsymname != NIL) { - Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "The value <%s> is already assigned to <%s>.\n", value, oldsymname); - } - Setattr(enumeration_items, value, name); - if (enumeration_max < numvalue) { - enumeration_max = numvalue; - } - } -#endif - void emitEnumeration(File *file, String *name, Node *n) { Printf(file, "%s = {", name); int i; From e0e4a4db6d48f0fc1b5fa638650369af1e1c5507 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 28 Apr 2013 18:41:11 +0100 Subject: [PATCH 0565/1160] Warning fix for ccache-swig tests clang deletes the output 'file' whereas gcc does not if the output 'file' is actually a directory. --- CCache/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CCache/test.sh b/CCache/test.sh index 9581c85e3..f64c3e3de 100755 --- a/CCache/test.sh +++ b/CCache/test.sh @@ -142,7 +142,7 @@ basetests() { testname="non-regular" mkdir testd $CCACHE_COMPILE -o testd -c test1.c > /dev/null 2>&1 - rmdir testd + rm -rf testd checkstat 'output to a non-regular file' 1 testname="no-input" @@ -315,7 +315,7 @@ swigtests() { testname="non-regular" mkdir testd $CCACHE_COMPILE -o testd -java testswig1.i > /dev/null 2>&1 - rmdir testd + rm -rf testd checkstat 'output to a non-regular file' 1 testname="no-input" From 7dfe4a065368a8658ed0f2ecf58dfc2cf981713e Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Thu, 7 Mar 2013 14:39:38 +0100 Subject: [PATCH 0566/1160] Make guile test suite default to scm api In other words guilescm becomes guile. Deprecated gh api tests are moved to guilegh. --- Examples/test-suite/guile/Makefile.in | 13 +++++++-- .../guile_ext_test_external.cxx} | 2 +- .../guile_ext_test_runme.scm} | 2 +- .../{guilescm_ext_test.i => guile_ext_test.i} | 2 +- .../{guilescm => guilegh}/Makefile.in | 29 +++---------------- Makefile.in | 8 ++--- configure.ac | 12 ++++---- 7 files changed, 27 insertions(+), 41 deletions(-) rename Examples/test-suite/{guilescm/guilescm_ext_test_external.cxx => guile/guile_ext_test_external.cxx} (90%) rename Examples/test-suite/{guilescm/guilescm_ext_test_runme.scm => guile/guile_ext_test_runme.scm} (82%) rename Examples/test-suite/{guilescm_ext_test.i => guile_ext_test.i} (93%) rename Examples/test-suite/{guilescm => guilegh}/Makefile.in (50%) diff --git a/Examples/test-suite/guile/Makefile.in b/Examples/test-suite/guile/Makefile.in index c6be92c32..455c26a66 100644 --- a/Examples/test-suite/guile/Makefile.in +++ b/Examples/test-suite/guile/Makefile.in @@ -2,14 +2,16 @@ # Makefile for guile test-suite ####################################################################### +EXTRA_TEST_CASES += guile_ext_test.externaltest + LANGUAGE = guile -VARIANT = _gh +VARIANT = SCRIPTSUFFIX = _runme.scm srcdir = @srcdir@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ GUILE = @GUILE@ -GUILE_RUNTIME=-runtime +GUILE_RUNTIME= C_TEST_CASES = long_long \ list_vector \ @@ -20,7 +22,7 @@ C_TEST_CASES = long_long \ include $(srcdir)/../common.mk # Overridden variables here -# none! +INCLUDES += -I$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/guile # Custom tests - tests with additional commandline options %.multicpptest: SWIGOPT += $(GUILE_RUNTIME) @@ -41,6 +43,11 @@ include $(srcdir)/../common.mk +$(swig_and_compile_multi_cpp) $(run_testcase) +%.externaltest: + $(setup) + +$(swig_and_compile_external) + $(run_testcase) + # Runs the testcase. A testcase is only run if # a file is found which has _runme.scm appended after the testcase name. run_testcase = \ diff --git a/Examples/test-suite/guilescm/guilescm_ext_test_external.cxx b/Examples/test-suite/guile/guile_ext_test_external.cxx similarity index 90% rename from Examples/test-suite/guilescm/guilescm_ext_test_external.cxx rename to Examples/test-suite/guile/guile_ext_test_external.cxx index 30fa1ce7b..c4f906a97 100644 --- a/Examples/test-suite/guilescm/guilescm_ext_test_external.cxx +++ b/Examples/test-suite/guile/guile_ext_test_external.cxx @@ -1,4 +1,4 @@ -#include +#include #include SCM test_create() diff --git a/Examples/test-suite/guilescm/guilescm_ext_test_runme.scm b/Examples/test-suite/guile/guile_ext_test_runme.scm similarity index 82% rename from Examples/test-suite/guilescm/guilescm_ext_test_runme.scm rename to Examples/test-suite/guile/guile_ext_test_runme.scm index ff3df064b..452b08ee7 100644 --- a/Examples/test-suite/guilescm/guilescm_ext_test_runme.scm +++ b/Examples/test-suite/guile/guile_ext_test_runme.scm @@ -1,4 +1,4 @@ -(dynamic-call "scm_init_guilescm_ext_test_module" (dynamic-link "./libguilescm_ext_test.so")) +(dynamic-call "scm_init_guile_ext_test_module" (dynamic-link "./libguile_ext_test.so")) ; This is a test for SF Bug 1573892 ; If IsPointer is called before TypeQuery, the test-is-pointer will fail diff --git a/Examples/test-suite/guilescm_ext_test.i b/Examples/test-suite/guile_ext_test.i similarity index 93% rename from Examples/test-suite/guilescm_ext_test.i rename to Examples/test-suite/guile_ext_test.i index fd5655d4f..170695f6c 100644 --- a/Examples/test-suite/guilescm_ext_test.i +++ b/Examples/test-suite/guile_ext_test.i @@ -1,4 +1,4 @@ -%module guilescm_ext_test +%module guile_ext_test /* just use the imports_a.h header... for this test we only need a class */ %{ diff --git a/Examples/test-suite/guilescm/Makefile.in b/Examples/test-suite/guilegh/Makefile.in similarity index 50% rename from Examples/test-suite/guilescm/Makefile.in rename to Examples/test-suite/guilegh/Makefile.in index ba1cba440..3a03d5f82 100644 --- a/Examples/test-suite/guilescm/Makefile.in +++ b/Examples/test-suite/guilegh/Makefile.in @@ -2,16 +2,13 @@ # Makefile for guile test-suite (with SCM API) ####################################################################### -EXTRA_TEST_CASES += guilescm_ext_test.externaltest - include ../guile/Makefile # Overridden variables here -INCLUDES += -I$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/guilescm -VARIANT = +VARIANT = _gh # Refer to the guile directory for the run scripts SCRIPTPREFIX = ../guile/ -GUILE_RUNTIME= +GUILE_RUNTIME=-runtime # Custom tests - tests with additional commandline options # none! @@ -25,25 +22,7 @@ run_testcase = \ setup = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE) (with SCM API)" ; \ + echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE) (with GH API)" ; \ else \ - echo "$(ACTION)ing testcase $* under $(LANGUAGE) (with SCM API)" ; \ - fi - -%.externaltest: - $(local_setup) - +$(swig_and_compile_external) - $(local_run_testcase) - -# Same as setup and run_testcase, but without the SCRIPTPREFIX (so the runme comes from the guilescm directory) -local_setup = \ - if [ -f $(srcdir)/$*$(SCRIPTSUFFIX) ]; then \ - echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE) (with SCM API)" ; \ - else \ - echo "$(ACTION)ing testcase $* under $(LANGUAGE) (with SCM API)" ; \ - fi - -local_run_testcase = \ - if [ -f $(srcdir)/$*$(SCRIPTSUFFIX) ]; then \ - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(GUILE) -l $(srcdir)/$*$(SCRIPTSUFFIX); \ + echo "$(ACTION)ing testcase $* under $(LANGUAGE) (with GH API)" ; \ fi diff --git a/Makefile.in b/Makefile.in index c47cdbe7c..6b7a99220 100644 --- a/Makefile.in +++ b/Makefile.in @@ -59,7 +59,7 @@ skip-tcl = test -n "@SKIP_TCL@" skip-perl5 = test -n "@SKIP_PERL5@" skip-python = test -n "@SKIP_PYTHON@" skip-java = test -n "@SKIP_JAVA@" -skip-guilescm = test -n "@SKIP_GUILESCM@" +skip-guilegh = test -n "@SKIP_GUILEGH@" skip-guile = test -n "@SKIP_GUILE@" skip-mzscheme = test -n "@SKIP_MZSCHEME@" skip-ruby = test -n "@SKIP_RUBY@" @@ -247,7 +247,7 @@ check-test-suite: \ check-perl5-test-suite \ check-python-test-suite \ check-java-test-suite \ - check-guilescm-test-suite \ + check-guilegh-test-suite \ check-guile-test-suite \ check-mzscheme-test-suite \ check-ruby-test-suite \ @@ -300,7 +300,7 @@ all-test-suite: \ all-perl5-test-suite \ all-python-test-suite \ all-java-test-suite \ - all-guilescm-test-suite \ + all-guilegh-test-suite \ all-guile-test-suite \ all-mzscheme-test-suite \ all-ruby-test-suite \ @@ -329,7 +329,7 @@ broken-test-suite: \ broken-perl5-test-suite \ broken-python-test-suite \ broken-java-test-suite \ - broken-guilescm-test-suite \ + broken-guilegh-test-suite \ broken-guile-test-suite \ broken-mzscheme-test-suite \ broken-ruby-test-suite \ diff --git a/configure.ac b/configure.ac index 83b46f520..7b259c78d 100644 --- a/configure.ac +++ b/configure.ac @@ -2268,16 +2268,16 @@ AC_SUBST(SKIP_JAVA) SKIP_GUILE= -if test -z "$GUILEINCLUDE" || test -z "$GUILELIB" || test -z "$GUILE_GH_INTERFACE"; then +if test -z "$GUILEINCLUDE" || test -z "$GUILELIB" || test -z "$GUILE_SCM_INTERFACE"; then SKIP_GUILE="1" fi AC_SUBST(SKIP_GUILE) -SKIP_GUILESCM= -if test -z "$GUILEINCLUDE" || test -z "$GUILELIB" || test -z "$GUILE_SCM_INTERFACE"; then - SKIP_GUILESCM="1" +SKIP_GUILEGH= +if test -z "$GUILEINCLUDE" || test -z "$GUILELIB" || test -z "$GUILE_GH_INTERFACE"; then + SKIP_GUILEGH="1" fi -AC_SUBST(SKIP_GUILESCM) +AC_SUBST(SKIP_GUILEGH) SKIP_MZSCHEME= @@ -2454,7 +2454,7 @@ AC_CONFIG_FILES([ \ Examples/test-suite/csharp/Makefile \ Examples/test-suite/d/Makefile \ Examples/test-suite/guile/Makefile \ - Examples/test-suite/guilescm/Makefile \ + Examples/test-suite/guilegh/Makefile \ Examples/test-suite/java/Makefile \ Examples/test-suite/mzscheme/Makefile \ Examples/test-suite/ocaml/Makefile \ From 2c23a5d2cdbe45c7408aa50c667b5e4647ef05b6 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Mon, 4 Mar 2013 22:12:09 +0100 Subject: [PATCH 0567/1160] Add support for guile 2.0: update swg and interface files Note: only the scm interface is considered. --- Lib/guile/ghinterface.i | 46 ++++++++++++++ Lib/guile/guile_gh_run.swg | 34 ++++++++++- Lib/guile/guile_scm_run.swg | 117 ++++++++++++++++++++++++++++++++---- Lib/guile/typemaps.i | 6 +- 4 files changed, 186 insertions(+), 17 deletions(-) diff --git a/Lib/guile/ghinterface.i b/Lib/guile/ghinterface.i index c5fda62cf..022c0f568 100644 --- a/Lib/guile/ghinterface.i +++ b/Lib/guile/ghinterface.i @@ -1,3 +1,5 @@ +#ifdef GUILE_VERSION_1_6 + #define gh_append2(a, b) scm_append(scm_listify(a, b, SCM_UNDEFINED)) #define gh_apply(a, b) scm_apply(a, b, SCM_EOL) #define gh_bool2scm SCM_BOOL @@ -37,3 +39,47 @@ #define gh_vector_ref scm_vector_ref #define gh_vector_set_x scm_vector_set_x #define gh_char2scm SCM_MAKE_CHAR + +#else + +#define gh_append2(a, b) scm_append(scm_listify(a, b, SCM_UNDEFINED)) +#define gh_apply(a, b) scm_apply(a, b, SCM_EOL) +#define gh_bool2scm scm_from_bool +#define gh_boolean_p scm_is_bool +#define gh_car SCM_CAR +#define gh_cdr SCM_CDR +#define gh_cons scm_cons +#define gh_double2scm scm_from_double +#define gh_int2scm scm_from_long +#define gh_length(lst) scm_to_ulong(scm_length(lst)) +#define gh_list scm_listify +#define gh_list_to_vector scm_vector +#define gh_make_vector scm_make_vector +#define gh_null_p scm_is_null +#define gh_number_p scm_is_number +#define gh_pair_p scm_is_pair +#define gh_scm2bool scm_is_true +#define gh_scm2char SCM_CHAR +#define gh_scm2double scm_to_double +#define gh_scm2int scm_to_int +#define gh_scm2long scm_to_long +#define gh_scm2short scm_to_short +#define gh_scm2newstr SWIG_Guile_scm2newstr +#define gh_scm2ulong scm_to_ulong +#define gh_scm2ushort scm_to_ushort +#define gh_scm2uint scm_to_uint +#define gh_ulong2scm scm_from_ulong +#define gh_long2scm scm_from_long +#define gh_str02scm(str) str ? scm_from_locale_string(str) : SCM_BOOL_F +#define gh_long_long2scm scm_from_long_long +#define gh_scm2long_long scm_to_long_long +#define gh_ulong_long2scm scm_from_ulong_long +#define gh_scm2ulong_long scm_to_ulong_long +#define gh_string_p scm_is_string +#define gh_vector_length scm_c_vector_length +#define gh_vector_p scm_is_vector +#define gh_vector_ref scm_vector_ref +#define gh_vector_set_x scm_vector_set_x +#define gh_char2scm SCM_MAKE_CHAR + +#endif \ No newline at end of file diff --git a/Lib/guile/guile_gh_run.swg b/Lib/guile/guile_gh_run.swg index d8cc56b91..8616875da 100644 --- a/Lib/guile/guile_gh_run.swg +++ b/Lib/guile/guile_gh_run.swg @@ -15,6 +15,36 @@ extern "C" { #endif + +/* In the code below, use guile 2.0 compatible functions where possible. + Functions that don't exist in older versions will be mapped to + a deprecated equivalent for those versions only */ +/* ... setup guile 2-like interface for guile 1.6 */ +#if (SCM_MAJOR_VERSION == 1) && (SCM_MINOR_VERSION <= 6) + +# define scm_from_locale_keyword scm_c_make_keyword +# define scm_from_locale_symbol scm_str2symbol +# define scm_is_null SCM_NULLP +# define scm_is_true SCM_NFALSEP +# define scm_is_string SCM_STRINGP + +/* Used later on to setup different code paths where it's + not possible to use a guile 2-like interface */ +# define GUILE_VERSION_1_6 + +#endif + +/* ... setup guile 2-like interface for guile 1.6 and 1.8 */ +#if defined (SCM_MAJOR_VERSION) && (SCM_MAJOR_VERSION < 2) + +static SCM +scm_module_variable (SCM module, SCM sym) +{ + return scm_sym2var (sym, scm_module_lookup_closure (module), SCM_BOOL_F); +} + +#endif + typedef SCM (*swig_guile_proc)(); #define SWIG_malloc(size) \ @@ -150,7 +180,7 @@ SWIG_Guile_ConvertPtr(swig_module_info *module, SCM s, void **result, { swig_cast_info *cast; swig_type_info *from; - if (SCM_NULLP(s)) { + if (scm_is_null(s)) { *result = NULL; return SWIG_OK; } else if (SCM_NIMP(s)) { @@ -246,7 +276,7 @@ SWIG_Guile_GetArgs (SCM *dest, SCM rest, } for (; i= 2 +// scm_c_define_gsubr takes a different parameter type +// depending on the guile version + +typedef scm_t_subr swig_guile_proc; +#else typedef SCM (*swig_guile_proc)(); +#endif typedef SCM (*guile_destructor)(SCM); typedef struct swig_guile_clientdata { @@ -22,10 +59,17 @@ typedef struct swig_guile_clientdata { #define SWIG_scm2str(s) \ SWIG_Guile_scm2newstr(s, NULL) -#define SWIG_malloc(size) \ - SCM_MUST_MALLOC(size) -#define SWIG_free(mem) \ - scm_must_free(mem) +#ifdef GUILE_VERSION_1_6 +# define SWIG_malloc(size) \ + SCM_MUST_MALLOC(size) +# define SWIG_free(mem) \ + scm_must_free(mem) +#else +# define SWIG_malloc(size) \ + scm_malloc(size) +# define SWIG_free(mem) \ + free(mem) +#endif #define SWIG_ConvertPtr(s, result, type, flags) \ SWIG_Guile_ConvertPtr(s, result, type, flags) #define SWIG_MustGetPtr(s, type, argnum, flags) \ @@ -42,7 +86,7 @@ typedef struct swig_guile_clientdata { SWIG_Guile_IsPointer(object) #define SWIG_contract_assert(expr, msg) \ if (!(expr)) \ - scm_error(scm_str2symbol("swig-contract-assertion-failed"), \ + scm_error(scm_from_locale_symbol("swig-contract-assertion-failed"), \ (char *) FUNC_NAME, (char *) msg, \ SCM_EOL, SCM_BOOL_F); else @@ -61,15 +105,25 @@ SWIGINTERN char * SWIG_Guile_scm2newstr(SCM str, size_t *len) { #define FUNC_NAME "SWIG_Guile_scm2newstr" char *ret; +# ifndef GUILE_VERSION_1_6 + char *tmp; +# endif size_t l; - SCM_ASSERT (SCM_STRINGP(str), str, 1, FUNC_NAME); - - l = SCM_STRING_LENGTH(str); + SCM_ASSERT (scm_is_string(str), str, 1, FUNC_NAME); + l = scm_c_string_length(str); + ret = (char *) SWIG_malloc( (l + 1) * sizeof(char)); if (!ret) return NULL; +# ifdef GUILE_VERSION_1_6 memcpy(ret, SCM_STRING_CHARS(str), l); +# else + tmp = scm_to_locale_string(str); + memcpy(ret, tmp, l); + free(tmp); +# endif + ret[l] = '\0'; if (len) *len = l; return ret; @@ -86,7 +140,7 @@ static SCM swig_keyword = SCM_EOL; static SCM swig_symbol = SCM_EOL; #define SWIG_Guile_GetSmob(x) \ - ( SCM_NNULLP(x) && SCM_INSTANCEP(x) && SCM_NFALSEP(scm_slot_exists_p(x, swig_symbol)) \ + ( !scm_is_null(x) && SCM_INSTANCEP(x) && scm_is_true(scm_slot_exists_p(x, swig_symbol)) \ ? scm_slot_ref(x, swig_symbol) : (x) ) SWIGINTERN SCM @@ -361,6 +415,7 @@ ensure_smob_tag(SCM swig_module, const char *smob_name, const char *scheme_variable_name) { +#ifdef GUILE_VERSION_1_6 SCM variable = scm_sym2var(scm_str2symbol(scheme_variable_name), scm_module_lookup_closure(swig_module), SCM_BOOL_T); @@ -375,6 +430,20 @@ ensure_smob_tag(SCM swig_module, "SWIG_Guile_Init"); return 0; } +#else + SCM variable = scm_module_variable(swig_module, + scm_from_locale_symbol(scheme_variable_name)); + if (scm_is_false(variable)) { + *tag_variable = scm_make_smob_type((char*)scheme_variable_name, 0); + scm_c_module_define(swig_module, scheme_variable_name, + scm_from_ulong(*tag_variable)); + return 1; + } + else { + *tag_variable = scm_to_ulong(SCM_VARIABLE_REF(variable)); + return 0; + } +#endif } SWIGINTERN SCM @@ -409,8 +478,8 @@ SWIG_Guile_Init () } swig_make_func = scm_permanent_object( scm_variable_ref(scm_c_module_lookup(scm_c_resolve_module("oop goops"), "make"))); - swig_keyword = scm_permanent_object(scm_c_make_keyword((char*) "init-smob")); - swig_symbol = scm_permanent_object(scm_str2symbol("swig-smob")); + swig_keyword = scm_permanent_object(scm_from_locale_keyword((char*) "init-smob")); + swig_symbol = scm_permanent_object(scm_from_locale_symbol("swig-smob")); #ifdef SWIG_INIT_RUNTIME_MODULE SWIG_INIT_RUNTIME_MODULE #endif @@ -426,6 +495,7 @@ SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata)) module = SWIG_Guile_Init(); +#ifdef GUILE_VERSION_1_6 variable = scm_sym2var(scm_str2symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME), scm_module_lookup_closure(module), SCM_BOOL_T); @@ -434,6 +504,15 @@ SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata)) } else { return (swig_module_info *) scm_num2ulong(SCM_VARIABLE_REF(variable), 0, "SWIG_Guile_Init"); } +#else + variable = scm_module_variable(module, + scm_from_locale_symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME)); + if (scm_is_false(variable)) { + return NULL; + } else { + return (swig_module_info *) scm_to_ulong(SCM_VARIABLE_REF(variable)); + } +#endif } SWIGINTERN void @@ -444,11 +523,17 @@ SWIG_Guile_SetModule(swig_module_info *swig_module) module = SWIG_Guile_Init(); +#ifdef GUILE_VERSION_1_6 variable = scm_sym2var(scm_str2symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME), scm_module_lookup_closure(module), SCM_BOOL_T); SCM_VARIABLE_SET(variable, scm_ulong2num((unsigned long) swig_module)); +#else + scm_module_define(module, + scm_from_locale_symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME), + scm_from_ulong((unsigned long) swig_module)); +#endif } SWIGINTERN int @@ -460,7 +545,11 @@ SWIG_Guile_GetArgs (SCM *dest, SCM rest, int num_args_passed = 0; for (i = 0; i Date: Thu, 7 Mar 2013 11:55:01 +0100 Subject: [PATCH 0568/1160] Add support for guile 2.0: configure and makefiles. Note: guile-config is badly broken for guile 2. So the guile configure section has been rewritten to use pkg-config instead. Manually resolved conflicts: Examples/Makefile.in --- Examples/Makefile.in | 31 +++--- Examples/guile/Makefile.in | 8 +- Makefile.in | 2 +- configure.ac | 204 ++++++++++++++++++------------------- 4 files changed, 122 insertions(+), 123 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 240274278..6b4ca778e 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -455,11 +455,11 @@ octave_clean: # Make sure these locate your Guile installation GUILE = @GUILE@ -GUILE_INCLUDE = @GUILEINCLUDE@ -GUILE_LIB = @GUILELIB@ +GUILE_CFLAGS = @GUILE_CFLAGS@ GUILE_SO = @GUILE_SO@ +GUILE_LIBS = @GUILE_LIBS@ +GUILE_LIBOPTS = @LIBS@ $(SYSLIBS) GUILE_LIBPREFIX = lib -GUILE_LIBOPTS = @GUILELINK@ @LIBS@ $(SYSLIBS) GUILE_SCRIPT = $(RUNME).scm #------------------------------------------------------------------ @@ -467,13 +467,14 @@ GUILE_SCRIPT = $(RUNME).scm #------------------------------------------------------------------ guile: $(SRCS) $(SWIG) -guile -scm -Linkage passive $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_INCLUDE) $(ISRCS) $(SRCS) + $(CC) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ISRCS) $(SRCS) $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) -guile_cpp: $(SRCS) +guile_cpp: $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) +$(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO): $(SRCS) $(SWIG) -c++ -guile -scm -Linkage passive $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_INCLUDE) $(ICXXSRCS) $(SRCS) $(CXXSRCS) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) + $(CXX) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) + $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $@ guile_externalhdr: $(SWIG) -guile -external-runtime $(TARGET) @@ -483,12 +484,12 @@ guile_externalhdr: #------------------------------------------------------------------ guile_gh: $(SRCS) $(SWIG) -guile -gh -Linkage passive $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_INCLUDE) $(ISRCS) $(SRCS) + $(CC) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ISRCS) $(SRCS) $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) guile_gh_cpp: $(SRCS) $(SWIG) -c++ -guile -gh -Linkage passive $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_INCLUDE) $(ICXXSRCS) $(SRCS) $(CXXSRCS) + $(CXX) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) # ----------------------------------------------------------------- @@ -497,12 +498,12 @@ guile_gh_cpp: $(SRCS) guile_passive: $(SRCS) $(SWIG) -guile -Linkage passive $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_INCLUDE) $(ISRCS) $(SRCS) + $(CC) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ISRCS) $(SRCS) $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) guile_passive_cpp: $(SRCS) $(SWIG) -c++ -guile -Linkage passive $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_INCLUDE) $(ICXXSRCS) $(SRCS) $(CXXSRCS) + $(CXX) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) # ----------------------------------------------------------------- @@ -513,23 +514,23 @@ guile_static: $(SRCS) $(SWIG) -guile -lguilemain.i -Linkage ltdlmod $(SWIGOPT) $(INTERFACEPATH) $(CC) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) \ -DSWIGINIT="SCM scm_init_$(TARGET)_module(void); scm_init_$(TARGET)_module();" \ - $(GUILE_INCLUDE) $(LIBS) -L$(GUILE_LIB) $(GUILE_LIBOPTS) -o $(TARGET)-guile + $(GUILE_CFLAGS) $(LIBS) -L$(GUILE_LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile guile_static_cpp: $(SRCS) $(SWIG) -c++ -guile -lguilemain.i -Linkage ltdlmod $(SWIGOPT) $(INTERFACEPATH) $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ -DSWIGINIT="SCM scm_init_$(TARGET)_module(void); scm_init_$(TARGET)_module();" \ - $(GUILE_INCLUDE) $(LIBS) -L$(GUILE_LIB) $(GUILE_LIBOPTS) -o $(TARGET)-guile + $(GUILE_CFLAGS) $(LIBS) -L$(GUILE_LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile guile_simple: $(SRCS) $(SWIG) -guile -lguilemain.i -Linkage simple $(SWIGOPT) $(INTERFACEPATH) $(CC) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) \ - $(GUILE_INCLUDE) $(LIBS) -L$(GUILE_LIB) $(GUILE_LIBOPTS) -o $(TARGET)-guile + $(GUILE_CFLAGS) $(LIBS) -L$(GUILE_LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile guile_simple_cpp: $(SRCS) $(SWIG) -c++ -guile -lguilemain.i -Linkage simple $(SWIGOPT) $(INTERFACEPATH) $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ - $(GUILE_INCLUDE) $(LIBS) -L$(GUILE_LIB) $(GUILE_LIBOPTS) -o $(TARGET)-guile + $(GUILE_CFLAGS) $(LIBS) -L$(GUILE_LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile # ----------------------------------------------------------------- # Running a Guile example diff --git a/Examples/guile/Makefile.in b/Examples/guile/Makefile.in index 9e6f9f6c6..3110ac994 100644 --- a/Examples/guile/Makefile.in +++ b/Examples/guile/Makefile.in @@ -7,8 +7,8 @@ SWIG = ../$(top_srcdir)/preinst-swig CC = @CC@ CXX = @CXX@ CFLAGS = @PLATFLAGS@ -GUILEINCLUDE = @GUILEINCLUDE@ -GUILELINK = @GUILELINK@ +GUILE_CFLAGS = @GUILE_CFLAGS@ +GUILE_LIBS = @GUILE_LIBS@ SWIGOPT = WRAP = $(IFILE:.i=_wrap.c) @@ -31,10 +31,10 @@ guile_clean: sub-all: $(SWIG) -guile $(SWIGOPT) $(IFILE) - $(CC) $(CFLAGS) -o $(TARGET) $(SRCS) $(WRAP) $(GUILEINCLUDE) $(GUILELINK) + $(CC) $(CFLAGS) -o $(TARGET) $(SRCS) $(WRAP) $(GUILE_CFLAGS) $(GUILE_LIBS) sub-all-cxx: $(SWIG) -c++ -guile $(SWIGOPT) $(IFILE) - $(CXX) $(CFLAGS) -o $(TARGET) $(SRCS) $(CXXWRAP) $(GUILEINCLUDE) $(GUILELINK) + $(CXX) $(CFLAGS) -o $(TARGET) $(SRCS) $(CXXWRAP) $(GUILE_CFLAGS) $(GUILE_LIBS) # Makefile ends here diff --git a/Makefile.in b/Makefile.in index 6b7a99220..c33889587 100644 --- a/Makefile.in +++ b/Makefile.in @@ -59,7 +59,7 @@ skip-tcl = test -n "@SKIP_TCL@" skip-perl5 = test -n "@SKIP_PERL5@" skip-python = test -n "@SKIP_PYTHON@" skip-java = test -n "@SKIP_JAVA@" -skip-guilegh = test -n "@SKIP_GUILEGH@" +skip-guilegh = test -n "@SKIP_GUILEGH@" skip-guile = test -n "@SKIP_GUILE@" skip-mzscheme = test -n "@SKIP_MZSCHEME@" skip-ruby = test -n "@SKIP_RUBY@" diff --git a/configure.ac b/configure.ac index 7b259c78d..28696529d 100644 --- a/configure.ac +++ b/configure.ac @@ -157,7 +157,7 @@ if test "$GCC" = yes; then else ISYSTEM="-I" fi - +AC_MSG_NOTICE(ISYSTEM: $ISYSTEM) dnl Info for building shared libraries ... in order to run the examples @@ -1148,125 +1148,123 @@ AC_SUBST(NDKBUILD) # Look for Guile #---------------------------------------------------------------- -GUILEPACKAGE= -GUILEINCLUDE= GUILE= -GUILELIB= -GUILELINK= -GUILEPKGDATADIR= +GUILE_CFLAGS= +GUILE_LIBS= -AC_ARG_WITH(guile-config,AS_HELP_STRING([--without-guile], [Disable Guile]) -AS_HELP_STRING([--with-guile-config=path], [Set location of guile-config]),[ GUILE_CONFIG="$withval"], [GUILE_CONFIG=]) -AC_ARG_WITH(guilepackage, AS_HELP_STRING([--with-guile-prefix=path], [Set location of Guile tree]),[ - GUILEPACKAGE="$withval"]) -AC_ARG_WITH(guile,[ --with-guile=path Set location of Guile executable],[ - GUILE="$withval"], [GUILE=yes]) -AC_ARG_WITH(guileincl,[ --with-guileincl=path Set location of Guile include directory],[ - GUILEINCLUDE="$withval"]) -AC_ARG_WITH(guilelib,[ --with-guilelib=path Set location of Guile library directory],[ - GUILELIB="$withval"]) +AC_ARG_WITH(guile, AS_HELP_STRING([--without-guile], [Disable Guile]) +AS_HELP_STRING([--with-guile=path], [Set location of Guile executable]),[GUILE="$withval"], [GUILE=yes]) +AC_ARG_WITH(guile-cflags,[ --with-guile-cflags=cflags Set cflags required to compile against Guile],[ + GUILE_CFLAGS="$withval"]) +AC_ARG_WITH(guile-libs,[ --with-guile-libs=ldflags Set ldflags needed to link with Guile],[ + GUILE_LIBS="$withval"]) # First, check for "--without-guile" or "--with-guile=no". if test x"${GUILE}" = xno -o x"${with_alllang}" = xno ; then -AC_MSG_NOTICE([Disabling Guile]) + AC_MSG_NOTICE([Disabling Guile]) + GUILE= + GUILE_CFLAGS= + GUILE_LIBS= else -if test -z "$GUILE_CONFIG" ; then - AC_PATH_PROG(GUILE_CONFIG, guile-config) -fi - -if test -n "$GUILE_CONFIG" ; then - GUILEPACKAGE="`$GUILE_CONFIG info prefix`" - GUILEINCLUDE="`$GUILE_CONFIG info includedir`" - GUILELIB="`$GUILE_CONFIG info libdir`" - GUILE="`$GUILE_CONFIG info bindir`/guile" - GUILELINK="`$GUILE_CONFIG link`" - GUILEPKGDATADIR="`$GUILE_CONFIG info pkgdatadir`" -fi - - if test -z "$GUILE" -o "x$GUILE" = xyes; then - if test -n "$GUILEPACKAGE"; then - GUILE="$GUILEPACKAGE/bin/guile" - else - GUILE= - fi + # Use pkg-config to find guile specific config parameters + # Note: if guile is not installed in a standard system path + # you can set the environment variable PKG_CONFIG_PATH to + # the directory where the guile package config file is stored + AC_PATH_PROG(PKG_CONFIG,pkg-config) + if test "x$PKG_CONFIG" = x; then + # @*%&$ Ximian programmers renamed this application + AC_PATH_PROG(PKG_CONFIG,pkgconfig) fi + if test "x$PKG_CONFIG" = x; then + AC_MSG_NOTICE([Could not find the pkg-config (or pkgconfig) program required to set up Guile. Disabling Guile],) + GUILE= + GUILE_CFLAGS= + GUILE_LIBS="" + else - if test -z "$GUILEINCLUDE"; then - if test -n "$GUILEPACKAGE"; then - GUILEINCLUDE="$GUILEPACKAGE/include" - fi - fi + # If the user has given these values, cache them to override the + # detected values. + if test "x$GUILE_LIBS" != x; then + saved_GUILE_LIBS="$GUILE_LIBS" + fi + if test "x$GUILE_CFLAGS" != x; then + saved_GUILE_CFLAGS="$GUILE_CFLAGS" + fi - if test -z "$GUILELIB"; then - if test -n "$GUILEPACKAGE"; then - GUILELIB="$GUILEPACKAGE/lib" - fi - fi + # Look up GUILE_CFLAGS and GUILE_LIBS, and version check + GUILE_SERIES="" + PKG_CHECK_MODULES(GUILE, [guile-1.8], [ GUILE_SERIES="18" ], [ + PKG_CHECK_MODULES(GUILE, [guile-2.0], [GUILE_SERIES="20" ], [AC_MSG_NOTICE([ + Only Guile 1.8 or 2.0 is supported. Neither version appears to be installed correctly. Disabling Guile + ])]) + ]) + if test "x$GUILE-SERIES" = x; then + GUILE= + GUILE_CFLAGS= + GUILE_LIBS= + else + # Look up GUILE executable + if test "x$GUILE" = xyes; then + GUILE= + if test "$xGUILE_SERIES" = "x18"; then + AC_PATH_PROG(GUILE18, guile-1.8) + if test "x$GUILE18" != x; then + GUILE="$GUILE18" + fi + fi + if test "$xGUILE_SERIES" = "x20"; then + AC_PATH_PROG(GUILE20, guile-2.0) + if test "x$GUILE20" != x; then + GUILE="$GUILE20" + fi + fi + if test "x$GUILE" = x; then + AC_PATH_PROG(GUILE, guile) + fi + fi -AC_MSG_CHECKING(for Guile header files) + if test "x$saved_GUILE_LIBS" != x; then + GUILE_LIBS="$saved_GUILE_LIBS" + fi + if test "x$saved_GUILE_CFLAGS" != x; then + GUILE_CFLAGS="$saved_GUILE_CFLAGS" + fi - dirs="$GUILEINCLUDE" - for i in $dirs ; do - if test -r $i/guile/gh.h; then - AC_MSG_RESULT($i) - GUILEINCLUDE="$ISYSTEM$i" - break - fi - done - if test -z "$GUILEINCLUDE"; then - AC_MSG_RESULT(not found) - fi + guilesafe_CFLAGS=$CFLAGS + guilesafe_LIBS=$LIBS + # Filter out "-ansi -pedantic" because Guile header files will not compile with these flags. + # (The flags -ansi -pedantic are automatically added by ac_compile_warnings.m4) + CFLAGS="`echo $CFLAGS | sed 's/-ansi//g;s/-pedantic//g;'` $GUILE_CFLAGS" + LIBS="$LIBS $GUILE_LIBS" - AC_MSG_CHECKING(for Guile library) - dirs="$GUILELIB" - for i in $dirs ; do - if test -r $i/libguile.so; then - AC_MSG_RESULT($i) - GUILELIB="$i" - break - fi - done - if test -z "$GUILELIB"; then - AC_MSG_RESULT(not found) - fi - -if test -z "$GUILELINK"; then - GUILELINK="-L$GUILELIB -lguile" -fi - -guilesafe_CFLAGS=$CFLAGS -guilesafe_LIBS=$LIBS -# Filter out "-ansi -pedantic" because Guile header files will not compile with these flags. -# (The flags -ansi -pedantic are automatically added by ac_compile_warnings.m4) -CFLAGS="`echo $CFLAGS | sed 's/-ansi//g;s/-pedantic//g;'` $GUILEINCLUDE" -LIBS="$LIBS $GUILELINK" - -AC_MSG_CHECKING(whether Guile's gh_ API works) -AC_LINK_IFELSE([AC_LANG_SOURCE([#include - int main() { SCM s; return gh_scm2int(s); }])], GUILE_GH_INTERFACE=1, ) -if test -n "$GUILE_GH_INTERFACE" ; then + AC_MSG_CHECKING(whether Guile's gh_ API works) + AC_LINK_IFELSE([AC_LANG_SOURCE([#include + int main() { SCM s; return gh_scm2int(s); }])], GUILE_GH_INTERFACE=1, ) + if test -n "$GUILE_GH_INTERFACE" ; then AC_MSG_RESULT(yes) -else - AC_MSG_RESULT(no) -fi -AC_MSG_CHECKING(whether Guile's SCM_ API works) -AC_LINK_IFELSE([AC_LANG_SOURCE([#include - int main() { SCM s; scm_slot_exists_p(SCM_BOOL_F, SCM_BOOL_F); return SCM_STRING_LENGTH(s); }])], GUILE_SCM_INTERFACE=1, ) -if test -n "$GUILE_SCM_INTERFACE" ; then + else + AC_MSG_RESULT(no) + fi + AC_MSG_CHECKING(whether Guile's SCM_ API works) + AC_LINK_IFELSE([AC_LANG_SOURCE([#include + int main() { SCM s; scm_slot_exists_p(SCM_BOOL_F, SCM_BOOL_F); return SCM_STRING_LENGTH(s); }])], GUILE_SCM_INTERFACE=1, ) + if test -n "$GUILE_SCM_INTERFACE" ; then AC_MSG_RESULT(yes) -else - AC_MSG_RESULT(no) -fi -CFLAGS=$guilesafe_CFLAGS -LIBS=$guilesafe_LIBS + else + AC_MSG_RESULT(no) + fi + + CFLAGS=$guilesafe_CFLAGS + LIBS=$guilesafe_LIBS + fi + fi fi AC_SUBST(GUILE) -AC_SUBST(GUILEINCLUDE) -AC_SUBST(GUILELIB) -AC_SUBST(GUILELINK) +AC_SUBST(GUILE_CFLAGS) +AC_SUBST(GUILE_LIBS) AC_SUBST(GUILE_GH_INTERFACE) AC_SUBST(GUILE_SCM_INTERFACE) @@ -2268,13 +2266,13 @@ AC_SUBST(SKIP_JAVA) SKIP_GUILE= -if test -z "$GUILEINCLUDE" || test -z "$GUILELIB" || test -z "$GUILE_SCM_INTERFACE"; then +if test -z "$GUILE_CFLAGS" || test -z "$GUILE_LIBS" || test -z "$GUILE_SCM_INTERFACE"; then SKIP_GUILE="1" fi AC_SUBST(SKIP_GUILE) SKIP_GUILEGH= -if test -z "$GUILEINCLUDE" || test -z "$GUILELIB" || test -z "$GUILE_GH_INTERFACE"; then +if test -z "$GUILE_CFLAGS" || test -z "$GUILE_LIBS" || test -z "$GUILE_GH_INTERFACE"; then SKIP_GUILEGH="1" fi AC_SUBST(SKIP_GUILEGH) From 3c47730803afde678574496a4d71f7f241dce73e Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Fri, 19 Apr 2013 12:49:40 +0200 Subject: [PATCH 0569/1160] Drop support for guile 1.6 and older --- Doc/Manual/Guile.html | 49 +++++++++++++++---------- Lib/guile/ghinterface.i | 46 ----------------------- Lib/guile/guile_gh_run.swg | 17 +-------- Lib/guile/guile_scm_run.swg | 73 ------------------------------------- 4 files changed, 30 insertions(+), 155 deletions(-) diff --git a/Doc/Manual/Guile.html b/Doc/Manual/Guile.html index 6f1300492..14fc03854 100644 --- a/Doc/Manual/Guile.html +++ b/Doc/Manual/Guile.html @@ -12,6 +12,7 @@
      +
    • Supported Guile Versions
    • Meaning of "Module"
    • Using the SCM or GH Guile API
    • Linkage @@ -47,7 +48,15 @@

      This section details guile-specific support in SWIG. -

      23.1 Meaning of "Module"

      +

      23.1 Supported Guile Versions

      + + +

      +SWIG works with Guile versions 1.8.x and 2.0.x. Support for version +1.6.x has been dropped. The last version of SWIG that still works with +Guile version 1.6.x is SWIG 2.0.9. + +

      23.2 Meaning of "Module"

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

      23.2 Using the SCM or GH Guile API

      +

      23.3 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 +112,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.

      -

      23.3 Linkage

      +

      23.4 Linkage

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

      23.3.1 Simple Linkage

      +

      23.4.1 Simple Linkage

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

      23.3.2 Passive Linkage

      +

      23.4.2 Passive Linkage

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

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

      23.3.3 Native Guile Module Linkage

      +

      23.4.3 Native Guile Module Linkage

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

    -

    23.3.4 Old Auto-Loading Guile Module Linkage

    +

    23.4.4 Old Auto-Loading Guile Module Linkage

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

    23.3.5 Hobbit4D Linkage

    +

    23.4.5 Hobbit4D Linkage

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

    -

    23.4 Underscore Folding

    +

    23.5 Underscore Folding

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

    23.5 Typemaps

    +

    23.6 Typemaps

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

    -

    23.6 Representation of pointers as smobs

    +

    23.7 Representation of pointers as smobs

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

    23.6.1 GH Smobs

    +

    23.7.1 GH Smobs

    @@ -462,7 +471,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.

    -

    23.6.2 SCM Smobs

    +

    23.7.2 SCM Smobs

    The SCM interface (using the "-scm" argument to swig) uses swigrun.swg. @@ -477,7 +486,7 @@ in the smob tag. If a generated GOOPS module has been loaded, smobs will be wra GOOPS class.

    -

    23.6.3 Garbage Collection

    +

    23.7.3 Garbage Collection

    Garbage collection is a feature of the new SCM interface, and it is automatically included @@ -491,7 +500,7 @@ is exactly like described in 23.7 Exception Handling +

    23.8 Exception Handling

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

    23.8 Procedure documentation

    +

    23.9 Procedure documentation

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

    23.9 Procedures with setters

    +

    23.10 Procedures with setters

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

    23.10 GOOPS Proxy Classes

    +

    23.11 GOOPS Proxy Classes

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

    -

    23.10.1 Naming Issues

    +

    23.11.1 Naming Issues

    As you can see in the example above, there are potential naming conflicts. The default exported @@ -767,7 +776,7 @@ guile-modules. For example,

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

    23.10.2 Linking

    +

    23.11.2 Linking

    The guile-modules generated above all need to be linked together. GOOPS support requires diff --git a/Lib/guile/ghinterface.i b/Lib/guile/ghinterface.i index 022c0f568..3de4c81a2 100644 --- a/Lib/guile/ghinterface.i +++ b/Lib/guile/ghinterface.i @@ -1,47 +1,3 @@ -#ifdef GUILE_VERSION_1_6 - -#define gh_append2(a, b) scm_append(scm_listify(a, b, SCM_UNDEFINED)) -#define gh_apply(a, b) scm_apply(a, b, SCM_EOL) -#define gh_bool2scm SCM_BOOL -#define gh_boolean_p SCM_BOOLP -#define gh_car SCM_CAR -#define gh_cdr SCM_CDR -#define gh_cons scm_cons -#define gh_double2scm scm_make_real -#define gh_int2scm scm_long2num -#define gh_length(lst) scm_num2ulong(scm_length(lst), SCM_ARG1, FUNC_NAME) -#define gh_list scm_listify -#define gh_list_to_vector scm_vector -#define gh_make_vector scm_make_vector -#define gh_null_p SCM_NULLP -#define gh_number_p SCM_NUMBERP -#define gh_pair_p SCM_CONSP -#define gh_scm2bool SCM_NFALSEP -#define gh_scm2char SCM_CHAR -#define gh_scm2double(a) scm_num2dbl(a, FUNC_NAME) -#define gh_scm2int(a) scm_num2int(a, SCM_ARG1, FUNC_NAME) -#define gh_scm2long(a) scm_num2long(a, SCM_ARG1, FUNC_NAME) -#define gh_scm2short(a) scm_num2short(a, SCM_ARG1, FUNC_NAME) -#define gh_scm2newstr SWIG_Guile_scm2newstr -#define gh_scm2ulong(a) scm_num2ulong(a, SCM_ARG1, FUNC_NAME) -#define gh_scm2ushort(a) scm_num2ushort(a, SCM_ARG1, FUNC_NAME) -#define gh_scm2uint(a) scm_num2uint(a, SCM_ARG1, FUNC_NAME) -#define gh_ulong2scm scm_ulong2num -#define gh_long2scm scm_long2num -#define gh_str02scm scm_makfrom0str -#define gh_long_long2scm scm_long_long2num -#define gh_scm2long_long(a) scm_num2long_long(a, SCM_ARG1, FUNC_NAME) -#define gh_ulong_long2scm scm_ulong_long2num -#define gh_scm2ulong_long(a) scm_num2ulong_long(a, SCM_ARG1, FUNC_NAME) -#define gh_string_p SCM_STRINGP -#define gh_vector_length SCM_VECTOR_LENGTH -#define gh_vector_p SCM_VECTORP -#define gh_vector_ref scm_vector_ref -#define gh_vector_set_x scm_vector_set_x -#define gh_char2scm SCM_MAKE_CHAR - -#else - #define gh_append2(a, b) scm_append(scm_listify(a, b, SCM_UNDEFINED)) #define gh_apply(a, b) scm_apply(a, b, SCM_EOL) #define gh_bool2scm scm_from_bool @@ -81,5 +37,3 @@ #define gh_vector_ref scm_vector_ref #define gh_vector_set_x scm_vector_set_x #define gh_char2scm SCM_MAKE_CHAR - -#endif \ No newline at end of file diff --git a/Lib/guile/guile_gh_run.swg b/Lib/guile/guile_gh_run.swg index 8616875da..1292131c8 100644 --- a/Lib/guile/guile_gh_run.swg +++ b/Lib/guile/guile_gh_run.swg @@ -19,22 +19,7 @@ extern "C" { /* In the code below, use guile 2.0 compatible functions where possible. Functions that don't exist in older versions will be mapped to a deprecated equivalent for those versions only */ -/* ... setup guile 2-like interface for guile 1.6 */ -#if (SCM_MAJOR_VERSION == 1) && (SCM_MINOR_VERSION <= 6) - -# define scm_from_locale_keyword scm_c_make_keyword -# define scm_from_locale_symbol scm_str2symbol -# define scm_is_null SCM_NULLP -# define scm_is_true SCM_NFALSEP -# define scm_is_string SCM_STRINGP - -/* Used later on to setup different code paths where it's - not possible to use a guile 2-like interface */ -# define GUILE_VERSION_1_6 - -#endif - -/* ... setup guile 2-like interface for guile 1.6 and 1.8 */ +/* ... setup guile 2-like interface for guile 1.8 */ #if defined (SCM_MAJOR_VERSION) && (SCM_MAJOR_VERSION < 2) static SCM diff --git a/Lib/guile/guile_scm_run.swg b/Lib/guile/guile_scm_run.swg index 71de33535..7cf3d165a 100644 --- a/Lib/guile/guile_scm_run.swg +++ b/Lib/guile/guile_scm_run.swg @@ -16,22 +16,6 @@ extern "C" { /* In the code below, use guile 2.0 compatible functions where possible. Functions that don't exist in older versions will be mapped to a deprecated equivalent for those versions only */ -/* ... setup guile 2-like interface for guile 1.6 */ -#if (SCM_MAJOR_VERSION == 1) && (SCM_MINOR_VERSION <= 6) - -# define scm_from_locale_keyword scm_c_make_keyword -# define scm_from_locale_symbol scm_str2symbol -# define scm_is_null SCM_NULLP -# define scm_is_true SCM_NFALSEP -# define scm_is_string SCM_STRINGP - -/* Used later on to setup different code paths where it's - not possible to use a guile 2-like interface */ -# define GUILE_VERSION_1_6 - -#endif - -/* ... setup guile 2-like interface for guile 1.6 and 1.8 */ #if defined (SCM_MAJOR_VERSION) && (SCM_MAJOR_VERSION < 2) static SCM @@ -59,17 +43,10 @@ typedef struct swig_guile_clientdata { #define SWIG_scm2str(s) \ SWIG_Guile_scm2newstr(s, NULL) -#ifdef GUILE_VERSION_1_6 -# define SWIG_malloc(size) \ - SCM_MUST_MALLOC(size) -# define SWIG_free(mem) \ - scm_must_free(mem) -#else # define SWIG_malloc(size) \ scm_malloc(size) # define SWIG_free(mem) \ free(mem) -#endif #define SWIG_ConvertPtr(s, result, type, flags) \ SWIG_Guile_ConvertPtr(s, result, type, flags) #define SWIG_MustGetPtr(s, type, argnum, flags) \ @@ -105,9 +82,7 @@ SWIGINTERN char * SWIG_Guile_scm2newstr(SCM str, size_t *len) { #define FUNC_NAME "SWIG_Guile_scm2newstr" char *ret; -# ifndef GUILE_VERSION_1_6 char *tmp; -# endif size_t l; SCM_ASSERT (scm_is_string(str), str, 1, FUNC_NAME); @@ -116,13 +91,9 @@ SWIG_Guile_scm2newstr(SCM str, size_t *len) { ret = (char *) SWIG_malloc( (l + 1) * sizeof(char)); if (!ret) return NULL; -# ifdef GUILE_VERSION_1_6 - memcpy(ret, SCM_STRING_CHARS(str), l); -# else tmp = scm_to_locale_string(str); memcpy(ret, tmp, l); free(tmp); -# endif ret[l] = '\0'; if (len) *len = l; @@ -415,22 +386,6 @@ ensure_smob_tag(SCM swig_module, const char *smob_name, const char *scheme_variable_name) { -#ifdef GUILE_VERSION_1_6 - SCM variable = scm_sym2var(scm_str2symbol(scheme_variable_name), - scm_module_lookup_closure(swig_module), - SCM_BOOL_T); - if (SCM_UNBNDP(SCM_VARIABLE_REF(variable))) { - *tag_variable = scm_make_smob_type((char*)scheme_variable_name, 0); - SCM_VARIABLE_SET(variable, - scm_ulong2num(*tag_variable)); - return 1; - } - else { - *tag_variable = scm_num2ulong(SCM_VARIABLE_REF(variable), 0, - "SWIG_Guile_Init"); - return 0; - } -#else SCM variable = scm_module_variable(swig_module, scm_from_locale_symbol(scheme_variable_name)); if (scm_is_false(variable)) { @@ -443,7 +398,6 @@ ensure_smob_tag(SCM swig_module, *tag_variable = scm_to_ulong(SCM_VARIABLE_REF(variable)); return 0; } -#endif } SWIGINTERN SCM @@ -495,16 +449,6 @@ SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata)) module = SWIG_Guile_Init(); -#ifdef GUILE_VERSION_1_6 - variable = scm_sym2var(scm_str2symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME), - scm_module_lookup_closure(module), - SCM_BOOL_T); - if (SCM_UNBNDP(SCM_VARIABLE_REF(variable))) { - return NULL; - } else { - return (swig_module_info *) scm_num2ulong(SCM_VARIABLE_REF(variable), 0, "SWIG_Guile_Init"); - } -#else variable = scm_module_variable(module, scm_from_locale_symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME)); if (scm_is_false(variable)) { @@ -512,7 +456,6 @@ SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata)) } else { return (swig_module_info *) scm_to_ulong(SCM_VARIABLE_REF(variable)); } -#endif } SWIGINTERN void @@ -523,17 +466,9 @@ SWIG_Guile_SetModule(swig_module_info *swig_module) module = SWIG_Guile_Init(); -#ifdef GUILE_VERSION_1_6 - variable = scm_sym2var(scm_str2symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME), - scm_module_lookup_closure(module), - SCM_BOOL_T); - - SCM_VARIABLE_SET(variable, scm_ulong2num((unsigned long) swig_module)); -#else scm_module_define(module, scm_from_locale_symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME), scm_from_ulong((unsigned long) swig_module)); -#endif } SWIGINTERN int @@ -545,11 +480,7 @@ SWIG_Guile_GetArgs (SCM *dest, SCM rest, int num_args_passed = 0; for (i = 0; i Date: Fri, 19 Apr 2013 12:19:49 +0200 Subject: [PATCH 0570/1160] Drop guilegh interface All of guile's interface files now use the scm interface. This should not affect any users. Swig generated code using the scm interface can be mixed with gh interface using user code. It does simplify maintenance of the guile swig code though. --- Doc/Manual/Guile.html | 52 +- Doc/Manual/Typemaps.html | 2 +- Examples/Makefile.in | 13 - Examples/guile/multimap/example.i | 4 +- Examples/test-suite/guilegh/Makefile.in | 28 - Examples/test-suite/pointer_reference.i | 2 +- Lib/cdata.i | 2 +- Lib/exception.i | 2 +- Lib/guile/cplusplus.i | 10 +- Lib/guile/ghinterface.i | 39 - Lib/guile/guile_gh.swg | 71 -- Lib/guile/guile_gh_run.swg | 273 ------ Lib/guile/guile_scm.swg | 5 - Lib/guile/guile_scm_run.swg | 6 +- Lib/guile/list-vector.i | 92 +- Lib/guile/std_common.i | 4 +- Lib/guile/std_map.i | 1148 +++++++++++------------ Lib/guile/std_pair.i | 940 +++++++++---------- Lib/guile/std_string.i | 16 +- Lib/guile/std_vector.i | 144 +-- Lib/guile/typemaps.i | 84 +- Lib/mzscheme/typemaps.i | 2 +- Makefile.in | 4 - Source/Modules/guile.cxx | 151 +-- configure.ac | 18 +- 25 files changed, 1283 insertions(+), 1829 deletions(-) delete mode 100644 Examples/test-suite/guilegh/Makefile.in delete mode 100644 Lib/guile/ghinterface.i delete mode 100644 Lib/guile/guile_gh.swg delete mode 100644 Lib/guile/guile_gh_run.swg diff --git a/Doc/Manual/Guile.html b/Doc/Manual/Guile.html index 14fc03854..53368bc77 100644 --- a/Doc/Manual/Guile.html +++ b/Doc/Manual/Guile.html @@ -14,7 +14,7 @@

    • Supported Guile Versions
    • Meaning of "Module" -
    • Using the SCM or GH Guile API +
    • Old GH Guile API
    • Linkage
      • Simple Linkage @@ -64,53 +64,19 @@ There are three different concepts of "module" involved, defined separately for SWIG, Guile, and Libtool. To avoid horrible confusion, we explicitly prefix the context, e.g., "guile-module". -

        23.3 Using the SCM or GH Guile API

        +

        23.3 Old GH Guile API

        -

        The guile module can currently export wrapper files that use the guile GH interface or the -SCM interface. This is controlled by an argument passed to swig. The "-gh" argument causes swig -to output GH code, and the "-scm" argument causes swig to output SCM code. Right now the "-scm" argument -is the default. The "-scm" wrapper generation assumes a guile version >= 1.6 and has several advantages over -the "-gh" wrapper generation including garbage collection and GOOPS support. -The "-gh" wrapper generation can be used for older versions of guile. -The guile GH wrapper code generation is depreciated and the -SCM interface is the default. The SCM and GH interface differ greatly in how they store -pointers and have completely different run-time code. See below for more info. +

        Support for the guile GH wrapper code generation has been dropped. The last +version of SWIG that can still generate guile GH wrapper code is 2.0.9. Please +use that version if you really need the GH wrapper code. -

        The GH interface to guile is deprecated. Read more about why in the +

        Guile 1.8 and older could be interfaced using a two different api's, the SCM +or the GH API. The GH interface to guile is deprecated. Read more about why in the 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 -using a high level API. So even though the GH interface is depreciated, SWIG will continue to use -the GH interface and provide mappings from the GH interface to whatever API we need. -We can maintain this mapping where guile failed because SWIG uses a small subset of all the GH functions -which map easily. All the guile typemaps like typemaps.i and std_vector.i -will continue to use the GH functions to do things like create lists of values, convert strings to -integers, etc. Then every language module will define a mapping between the GH interface and -whatever custom API the language uses. This is currently implemented by the guile module to use -the SCM guile API rather than the GH guile API. -For example, here are some of the current mapping file for the SCM API

        -
        -
        -#define gh_append2(a, b) scm_append(scm_listify(a, b, SCM_UNDEFINED)) 
        -#define gh_apply(a, b) scm_apply(a, b, SCM_EOL) 
        -#define gh_bool2scm SCM_BOOL 
        -#define gh_boolean_p SCM_BOOLP 
        -#define gh_car SCM_CAR 
        -#define gh_cdr SCM_CDR 
        -#define gh_cons scm_cons 
        -#define gh_double2scm scm_make_real 
        -...
        -
        - -

        This file is parsed by SWIG at wrapper generation time, so every reference to a gh_ function is replaced -by a scm_ function in the wrapper file. Thus the gh_ function calls will never be seen in the wrapper; -the wrapper will look exactly like it was generated -for the specific API. Currently only the guile language module has created a mapping policy from gh_ to scm_, -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.

        +

        The SCM wrapper generation assumes a guile version >= 1.8 and has several advantages over +the "-gh" wrapper generation including garbage collection and GOOPS support.

        23.4 Linkage

        diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index b3b0bc7a9..81e3fd1bb 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -773,7 +773,7 @@ Here are some examples of valid typemap specifications: } /* Typemap with modifiers */ -%typemap(in,doc="integer") int "$1 = gh_scm2int($input);"; +%typemap(in,doc="integer") int "$1 = scm_to_int($input);"; /* Typemap applied to patterns of multiple arguments */ %typemap(in) (char *str, int len), diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 6b4ca778e..b1bf8d049 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -479,19 +479,6 @@ $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO): $(SRCS) guile_externalhdr: $(SWIG) -guile -external-runtime $(TARGET) -#------------------------------------------------------------------ -# Build a dynamically loaded module with passive linkage and the gh interface -#------------------------------------------------------------------ -guile_gh: $(SRCS) - $(SWIG) -guile -gh -Linkage passive $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ISRCS) $(SRCS) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) - -guile_gh_cpp: $(SRCS) - $(SWIG) -c++ -guile -gh -Linkage passive $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) - # ----------------------------------------------------------------- # Build a dynamically loadable module with passive linkage # ----------------------------------------------------------------- diff --git a/Examples/guile/multimap/example.i b/Examples/guile/multimap/example.i index 7337d1e9e..f1d7974e4 100644 --- a/Examples/guile/multimap/example.i +++ b/Examples/guile/multimap/example.i @@ -59,14 +59,14 @@ extern int count(char *bytes, int len, char c); %typemap(in) (char *str, int len) { size_t temp; - $1 = gh_scm2newstr($input,&temp); + $1 = SWIG_Guile_scm2newstr($input,&temp); $2 = temp; } /* Return the mutated string as a new object. */ %typemap(argout) (char *str, int len) { - SWIG_APPEND_VALUE(gh_str2scm($1,$2)); + SWIG_APPEND_VALUE(scm_mem2string($1,$2)); if ($1) scm_must_free($1); } diff --git a/Examples/test-suite/guilegh/Makefile.in b/Examples/test-suite/guilegh/Makefile.in deleted file mode 100644 index 3a03d5f82..000000000 --- a/Examples/test-suite/guilegh/Makefile.in +++ /dev/null @@ -1,28 +0,0 @@ -####################################################################### -# Makefile for guile test-suite (with SCM API) -####################################################################### - -include ../guile/Makefile - -# Overridden variables here -VARIANT = _gh -# Refer to the guile directory for the run scripts -SCRIPTPREFIX = ../guile/ -GUILE_RUNTIME=-runtime - -# Custom tests - tests with additional commandline options -# none! - -# Runs the testcase. A testcase is only run if -# a file is found which has _runme.scm appended after the testcase name. -run_testcase = \ - if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(GUILE) -l $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \ - fi - -setup = \ - if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE) (with GH API)" ; \ - else \ - echo "$(ACTION)ing testcase $* under $(LANGUAGE) (with GH API)" ; \ - fi diff --git a/Examples/test-suite/pointer_reference.i b/Examples/test-suite/pointer_reference.i index b9e126fd4..7a6a09d48 100644 --- a/Examples/test-suite/pointer_reference.i +++ b/Examples/test-suite/pointer_reference.i @@ -11,7 +11,7 @@ #ifdef SWIGGUILE /* A silly testing typemap for feeding a doubly indirect integer */ %typemap(in) int *&XYZZY (int temp1, int *temp2) { - temp1 = gh_scm2int($input); temp2 = &temp1; $1 = &temp2; + temp1 = scm_to_int($input); temp2 = &temp1; $1 = &temp2; }; #endif diff --git a/Lib/cdata.i b/Lib/cdata.i index 1abaf357b..dbc1c42d2 100644 --- a/Lib/cdata.i +++ b/Lib/cdata.i @@ -17,7 +17,7 @@ typedef struct SWIGCDATA { #if SWIGGUILE %typemap(out) SWIGCDATA { - $result = gh_str2scm($1.data,$1.len); + $result = scm_mem2string($1.data,$1.len); } %typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH); #elif SWIGCHICKEN diff --git a/Lib/exception.i b/Lib/exception.i index dc3a7f462..867ecdbff 100644 --- a/Lib/exception.i +++ b/Lib/exception.i @@ -24,7 +24,7 @@ SWIGINTERN void SWIG_exception_ (int code, const char *msg, const char *subr) { #define ERROR(scmerr) \ - scm_error(gh_symbol2scm((char *) (scmerr)), \ + scm_error(scm_str2symbol((char *) (scmerr)), \ (char *) subr, (char *) msg, \ SCM_EOL, SCM_BOOL_F) #define MAP(swigerr, scmerr) \ diff --git a/Lib/guile/cplusplus.i b/Lib/guile/cplusplus.i index 0dfe71754..d5d65efaa 100644 --- a/Lib/guile/cplusplus.i +++ b/Lib/guile/cplusplus.i @@ -5,18 +5,18 @@ * ----------------------------------------------------------------------------- */ %typemap(guile,out) string, std::string { - $result = gh_str02scm(const_cast($1.c_str())); + $result = SWIG_str02scm(const_cast($1.c_str())); } %typemap(guile,in) string, std::string { $1 = SWIG_scm2str($input); } %typemap(guile,out) complex, complex, std::complex { - $result = scm_make_rectangular( gh_double2scm ($1.real ()), - gh_double2scm ($1.imag ()) ); + $result = scm_make_rectangular( scm_from_double ($1.real ()), + scm_from_double ($1.imag ()) ); } %typemap(guile,in) complex, complex, std::complex { - $1 = std::complex( gh_scm2double (scm_real_part ($input)), - gh_scm2double (scm_imag_part ($input)) ); + $1 = std::complex( scm_to_double (scm_real_part ($input)), + scm_to_double (scm_imag_part ($input)) ); } diff --git a/Lib/guile/ghinterface.i b/Lib/guile/ghinterface.i deleted file mode 100644 index 3de4c81a2..000000000 --- a/Lib/guile/ghinterface.i +++ /dev/null @@ -1,39 +0,0 @@ -#define gh_append2(a, b) scm_append(scm_listify(a, b, SCM_UNDEFINED)) -#define gh_apply(a, b) scm_apply(a, b, SCM_EOL) -#define gh_bool2scm scm_from_bool -#define gh_boolean_p scm_is_bool -#define gh_car SCM_CAR -#define gh_cdr SCM_CDR -#define gh_cons scm_cons -#define gh_double2scm scm_from_double -#define gh_int2scm scm_from_long -#define gh_length(lst) scm_to_ulong(scm_length(lst)) -#define gh_list scm_listify -#define gh_list_to_vector scm_vector -#define gh_make_vector scm_make_vector -#define gh_null_p scm_is_null -#define gh_number_p scm_is_number -#define gh_pair_p scm_is_pair -#define gh_scm2bool scm_is_true -#define gh_scm2char SCM_CHAR -#define gh_scm2double scm_to_double -#define gh_scm2int scm_to_int -#define gh_scm2long scm_to_long -#define gh_scm2short scm_to_short -#define gh_scm2newstr SWIG_Guile_scm2newstr -#define gh_scm2ulong scm_to_ulong -#define gh_scm2ushort scm_to_ushort -#define gh_scm2uint scm_to_uint -#define gh_ulong2scm scm_from_ulong -#define gh_long2scm scm_from_long -#define gh_str02scm(str) str ? scm_from_locale_string(str) : SCM_BOOL_F -#define gh_long_long2scm scm_from_long_long -#define gh_scm2long_long scm_to_long_long -#define gh_ulong_long2scm scm_from_ulong_long -#define gh_scm2ulong_long scm_to_ulong_long -#define gh_string_p scm_is_string -#define gh_vector_length scm_c_vector_length -#define gh_vector_p scm_is_vector -#define gh_vector_ref scm_vector_ref -#define gh_vector_set_x scm_vector_set_x -#define gh_char2scm SCM_MAKE_CHAR diff --git a/Lib/guile/guile_gh.swg b/Lib/guile/guile_gh.swg deleted file mode 100644 index 3b65af897..000000000 --- a/Lib/guile/guile_gh.swg +++ /dev/null @@ -1,71 +0,0 @@ -/* ----------------------------------------------------------------------------- - * guile_gh.swg - * - * This SWIG interface file is processed if the Guile module is run - * with gh_ flavor. - * ----------------------------------------------------------------------------- */ - -#define SWIGGUILE_GH - -%runtime "swigrun.swg" -%runtime "guile_gh_run.swg" - -#define SWIG_convert_short(o) \ - SWIG_convert_integer(o, - (1 << (8 * sizeof(short) - 1)), \ - (1 << (8 * sizeof(short) - 1)) - 1, \ - FUNC_NAME, $argnum) -#define SWIG_convert_unsigned_short(o) \ - SWIG_convert_unsigned_integer(o, 0, \ - (1 << (8 * sizeof(short))) - 1, \ - FUNC_NAME, $argnum) -#define SWIG_convert_unsigned_int(o) \ - SWIG_convert_unsigned_integer(o, 0, UINT_MAX, \ - FUNC_NAME, $argnum) - -#define gh_scm2short(a) SWIG_convert_short(a) -#define gh_scm2ushort(a) SWIG_convert_unsigned_short(a) -#define gh_scm2uint(a) SWIG_convert_unsigned_int(a) - -%include - -%runtime %{ - -/* scm_values was implemented on C level in 1.4.1, and the prototype - is not included in libguile.h, so play safe and lookup `values'... */ -#define GUILE_MAYBE_VALUES \ - if (gswig_list_p) \ - gswig_result = gh_apply(gh_lookup("values"), gswig_result); - -#define GUILE_MAYBE_VECTOR \ - if (gswig_list_p) \ - gswig_result = gh_list_to_vector(gswig_result); - -#define SWIG_APPEND_VALUE(object) \ - if (gswig_result == SCM_UNSPECIFIED) { \ - gswig_result = object; \ - } else { \ - if (!gswig_list_p) { \ - gswig_list_p = 1; \ - gswig_result = gh_list(gswig_result, object, SCM_UNDEFINED); \ - } \ - else \ - gswig_result = gh_append2(gswig_result, \ - gh_list(object, SCM_UNDEFINED)); \ - } - -%} - -%init "swiginit.swg" - -%init %{ -static int _swig_module_smob_tag; - -SWIG_GUILE_INIT_STATIC void -SWIG_init(void) -{ - - SWIG_InitializeModule(0); - swig_module.clientdata = (void *) &_swig_module_smob_tag; - - SWIG_Guile_Init(&swig_module); -%} diff --git a/Lib/guile/guile_gh_run.swg b/Lib/guile/guile_gh_run.swg deleted file mode 100644 index 1292131c8..000000000 --- a/Lib/guile/guile_gh_run.swg +++ /dev/null @@ -1,273 +0,0 @@ -/* ----------------------------------------------------------------------------- - * guile_gh_run.swg - * - * Guile GH runtime file - * ----------------------------------------------------------------------------- */ - -#define SWIGGUILE -#include "guile/gh.h" -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - - -/* In the code below, use guile 2.0 compatible functions where possible. - Functions that don't exist in older versions will be mapped to - a deprecated equivalent for those versions only */ -/* ... setup guile 2-like interface for guile 1.8 */ -#if defined (SCM_MAJOR_VERSION) && (SCM_MAJOR_VERSION < 2) - -static SCM -scm_module_variable (SCM module, SCM sym) -{ - return scm_sym2var (sym, scm_module_lookup_closure (module), SCM_BOOL_F); -} - -#endif - -typedef SCM (*swig_guile_proc)(); - -#define SWIG_malloc(size) \ - SCM_MUST_MALLOC(size) -#define SWIG_free(mem) \ - scm_must_free(mem) -#define SWIG_ConvertPtr(s, result, type, flags) \ - SWIG_Guile_ConvertPtr(&swig_module, s, result, type, flags) -#define SWIG_MustGetPtr(s, type, argnum, flags) \ - SWIG_Guile_MustGetPtr(&swig_module, s, type, argnum, flags, FUNC_NAME) -#define SWIG_NewPointerObj(ptr, type, owner) \ - SWIG_Guile_NewPointerObj(&swig_module, (void*)ptr, type, owner) -#define SWIG_GetModule(clientdata) SWIG_Guile_GetModule(clientdata) -#define SWIG_SetModule(clientdata, pointer) SWIG_Guile_SetModule(pointer) - -/* Ignore object-ownership changes in gh mode */ -#define SWIG_Guile_MarkPointerNoncollectable(s) (s) -#define SWIG_Guile_MarkPointerDestroyed(s) (s) - -#define SWIG_contract_assert(expr, msg) \ - if (!(expr)) \ - scm_error(gh_symbol2scm("swig-contract-assertion-failed"), \ - (char *) FUNC_NAME, (char *) msg, \ - SCM_EOL, SCM_BOOL_F); else - -/* SCM_CHAR and SCM_CHARP were introduced in Guile 1.4; the following is for - 1.3.4 compatibility. */ -#ifndef SCM_CHAR -# define SCM_CHAR SCM_ICHR -#endif -#ifndef SCM_CHARP -# define SCM_CHARP SCM_ICHRP -#endif - -/* This function replaces gh_scm2char, which is broken in Guile 1.4 */ -SWIGINTERN char -GSWIG_scm2char (SCM s) -{ - if (SCM_CHARP(s)) return SCM_CHAR(s); - scm_wrong_type_arg(NULL, 0, s); -} -#define gh_scm2char GSWIG_scm2char - -/* Interface function */ -#define SWIG_scm2str(x) gh_scm2newstr(x, NULL) - -/* More 1.3.4 compatibility */ -#ifndef SCM_INPUT_PORT_P -# define SCM_INPUT_PORT_P SCM_INPORTP -# define SCM_OUTPUT_PORT_P SCM_OUTPORTP -#endif - -SWIGINTERN long -SWIG_convert_integer(SCM o, - long lower_bound, long upper_bound, - const char *func_name, int argnum) -{ - long value = gh_scm2long(o); - if (value < lower_bound || value > upper_bound) - scm_wrong_type_arg((char *) func_name, argnum, o); - return value; -} - -SWIGINTERN unsigned long -SWIG_convert_unsigned_integer(SCM o, - unsigned long lower_bound, - unsigned long upper_bound, - const char *func_name, int argnum) -{ - unsigned long value = gh_scm2ulong(o); - if (value < lower_bound || value > upper_bound) - scm_wrong_type_arg((char *) func_name, argnum, o); - return value; -} - -SWIGINTERN swig_type_info * -SWIG_Guile_LookupType(swig_module_info *module, SCM s, int normal) -{ - swig_module_info *iter; - if (!module) return 0; - iter = module; - do { - if ((normal && (unsigned long) SCM_TYP16(s) == *((int *)iter->clientdata))) { - - return iter->types[(long) SCM_CAR(s) >> 16]; - } - iter = iter->next; - } while (iter != module); - return 0; -} - -#ifdef SWIG_GLOBAL -#define SWIG_GUILE_MODULE_STATIC -#elif !defined(SWIG_NOINCLUDE) -#define SWIG_GUILE_MODULE_STATIC static -#endif - -#ifdef SWIG_GUILE_MODULE_STATIC -static swig_module_info *swig_guile_module = 0; -SWIG_GUILE_MODULE_STATIC swig_module_info *SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata)) { - return swig_guile_module; -} -SWIG_GUILE_MODULE_STATIC void SWIG_Guile_SetModule(swig_module_info *pointer) { - swig_guile_module = pointer; -} -#else -SWIGEXPORT swig_module_info * SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata)); -SWIGEXPORT void SWIG_Guile_SetModule(swig_module_info *pointer); -#endif - -SWIGINTERN SCM -SWIG_Guile_NewPointerObj(swig_module_info *module, void *ptr, - swig_type_info *type, int owner) -{ - unsigned long tag; - if (ptr==NULL) return SCM_EOL; - if (!module) return SCM_EOL; - for (tag = 0; tag < module->size; ++tag) { - if (module->types[tag] == type) - break; - } - if (tag >= module->size) - return SCM_EOL; - - - SCM_RETURN_NEWSMOB( ((tag << 16) | *((int *)module->clientdata)), ptr); -} - -/* Return 0 if successful. */ -SWIGINTERN int -SWIG_Guile_ConvertPtr(swig_module_info *module, SCM s, void **result, - swig_type_info *type, int flags) -{ - swig_cast_info *cast; - swig_type_info *from; - if (scm_is_null(s)) { - *result = NULL; - return SWIG_OK; - } else if (SCM_NIMP(s)) { - from = SWIG_Guile_LookupType(module, s, 1); - if (!from) return SWIG_ERROR; - if (type) { - cast = SWIG_TypeCheckStruct(from, type); - if (cast) { - int newmemory = 0; - *result = SWIG_TypeCast(cast, (void *) SCM_CDR(s), &newmemory); - assert(!newmemory); /* newmemory handling not yet implemented */ - return SWIG_OK; - } else { - return SWIG_ERROR; - } - } else { - *result = (void *) SCM_CDR(s); - return SWIG_OK; - } - } - return SWIG_ERROR; -} - -SWIGINTERN void * -SWIG_Guile_MustGetPtr (swig_module_info *module, SCM s, swig_type_info *type, - int argnum, int flags, const char *func_name) -{ - void *result; - int res = SWIG_Guile_ConvertPtr(module, s, &result, type, flags); - if (!SWIG_IsOK(res)) { - /* type mismatch */ - scm_wrong_type_arg((char *) func_name, argnum, s); - } - return result; -} - -/* Init */ - -SWIGINTERN int -print_swig (SCM swig_smob, SCM port, scm_print_state *pstate) -{ - swig_type_info *type = SWIG_Guile_LookupType(0, swig_smob, 1); - if (type) { - scm_puts((char *) "#str != NULL) - scm_puts((char *) type->str, port); - else - scm_puts((char *) type->name, port); - scm_puts((char *) " ", port); - scm_intprint((long) SCM_CDR(swig_smob), 16, port); - scm_puts((char *) ">", port); - /* non-zero means success */ - return 1; - } else { - return 0; - } -} - -SWIGINTERN SCM -equalp_swig (SCM A, SCM B) -{ - if (SCM_CAR(A) == SCM_CAR(B) - && SCM_CDR(A) == SCM_CDR(B)) - return SCM_BOOL_T; - else return SCM_BOOL_F; -} - -SWIGINTERN void -SWIG_Guile_Init (swig_module_info *module) -{ - *((int *)module->clientdata) = - scm_make_smob_type_mfpe((char *) "swig", 0, NULL, NULL, print_swig, equalp_swig); -} - -SWIGINTERN int -SWIG_Guile_GetArgs (SCM *dest, SCM rest, - int reqargs, int optargs, - const char *procname) -{ - int i; - int num_args_passed = 0; - for (i = 0; i %include %runtime %{ @@ -32,10 +31,6 @@ else \ gswig_result = scm_append(scm_listify(gswig_result, scm_listify(object, SCM_UNDEFINED), SCM_UNDEFINED)); \ } - /* used by Lib/exception.i */ - #define gh_symbol2scm scm_str2symbol - /* useb by Lib/cdata.i */ - #define gh_str2scm scm_mem2string %} diff --git a/Lib/guile/guile_scm_run.swg b/Lib/guile/guile_scm_run.swg index 7cf3d165a..0ac51f919 100644 --- a/Lib/guile/guile_scm_run.swg +++ b/Lib/guile/guile_scm_run.swg @@ -43,10 +43,12 @@ typedef struct swig_guile_clientdata { #define SWIG_scm2str(s) \ SWIG_Guile_scm2newstr(s, NULL) +#define SWIG_str02scm(str) \ + str ? scm_from_locale_string(str) : SCM_BOOL_F # define SWIG_malloc(size) \ - scm_malloc(size) + scm_malloc(size) # define SWIG_free(mem) \ - free(mem) + free(mem) #define SWIG_ConvertPtr(s, result, type, flags) \ SWIG_Guile_ConvertPtr(s, result, type, flags) #define SWIG_MustGetPtr(s, type, argnum, flags) \ diff --git a/Lib/guile/list-vector.i b/Lib/guile/list-vector.i index c2cd1aea2..057a1da5b 100644 --- a/Lib/guile/list-vector.i +++ b/Lib/guile/list-vector.i @@ -61,12 +61,12 @@ (size_t VECTORLENINPUT, C_TYPE *VECTORINPUT) { SCM_VALIDATE_VECTOR($argnum, $input); - $1 = gh_vector_length($input); + $1 = scm_c_vector_length($input); if ($1 > 0) { $1_ltype i; $2 = (C_TYPE *) SWIG_malloc(sizeof(C_TYPE) * $1); for (i = 0; i<$1; i++) { - SCM swig_scm_value = gh_vector_ref($input, gh_int2scm(i)); + SCM swig_scm_value = scm_vector_ref($input, scm_from_long(i)); $2[i] = SCM_TO_C_EXPR; } } @@ -78,15 +78,15 @@ (size_t LISTLENINPUT, C_TYPE *LISTINPUT) { SCM_VALIDATE_LIST($argnum, $input); - $1 = gh_length($input); + $1 = scm_to_ulong(scm_length($input)); if ($1 > 0) { $1_ltype i; SCM rest; $2 = (C_TYPE *) SWIG_malloc(sizeof(C_TYPE) * $1); for (i = 0, rest = $input; i<$1; - i++, rest = gh_cdr(rest)) { - SCM swig_scm_value = gh_car(rest); + i++, rest = SCM_CDR(rest)) { + SCM swig_scm_value = SCM_CAR(rest); $2[i] = SCM_TO_C_EXPR; } } @@ -140,12 +140,12 @@ (size_t *VECTORLENOUTPUT, C_TYPE **VECTOROUTPUT) { $*1_ltype i; - SCM res = gh_make_vector(gh_int2scm(*$1), + SCM res = scm_make_vector(scm_from_long(*$1), SCM_BOOL_F); for (i = 0; i<*$1; i++) { C_TYPE swig_c_value = (*$2)[i]; SCM elt = C_TO_SCM_EXPR; - gh_vector_set_x(res, gh_int2scm(i), elt); + scm_vector_set_x(res, scm_from_long(i), elt); } SWIG_APPEND_VALUE(res); } @@ -159,7 +159,7 @@ for (i = ((int)(*$1)) - 1; i>=0; i--) { C_TYPE swig_c_value = (*$2)[i]; SCM elt = C_TO_SCM_EXPR; - res = gh_cons(elt, res); + res = scm_cons(elt, res); } SWIG_APPEND_VALUE(res); } @@ -200,21 +200,21 @@ /* We use the macro to define typemaps for some standard types. */ -TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(bool, gh_scm2bool, gh_bool2scm, boolean); -TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(char, gh_scm2char, gh_char2scm, char); -TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(unsigned char, gh_scm2char, gh_char2scm, char); -TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(int, gh_scm2int, gh_int2scm, integer); -TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(short, gh_scm2int, gh_int2scm, integer); -TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(long, gh_scm2long, gh_long2scm, integer); -TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(ptrdiff_t, gh_scm2long, gh_long2scm, integer); -TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(unsigned int, gh_scm2ulong, gh_ulong2scm, integer); -TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(unsigned short, gh_scm2ulong, gh_ulong2scm, integer); -TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(unsigned long, gh_scm2ulong, gh_ulong2scm, integer); -TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(size_t, gh_scm2ulong, gh_ulong2scm, integer); -TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(float, gh_scm2double, gh_double2scm, real); -TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(double, gh_scm2double, gh_double2scm, real); -TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(char *, SWIG_scm2str, gh_str02scm, string); -TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, gh_str02scm, string); +TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(bool, scm_is_true, scm_from_bool, boolean); +TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(char, SCM_CHAR, SCM_MAKE_CHAR, char); +TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(unsigned char, SCM_CHAR, SCM_MAKE_CHAR, char); +TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(int, scm_to_int, scm_from_long, integer); +TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(short, scm_to_int, scm_from_long, integer); +TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(long, scm_to_long, scm_from_long, integer); +TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(ptrdiff_t, scm_to_long, scm_from_long, integer); +TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(unsigned int, scm_to_ulong, scm_from_ulong, integer); +TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(unsigned short, scm_to_ulong, scm_from_ulong, integer); +TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(unsigned long, scm_to_ulong, scm_from_ulong, integer); +TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(size_t, scm_to_ulong, scm_from_ulong, integer); +TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(float, scm_to_double, scm_from_double, real); +TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(double, scm_to_double, scm_from_double, real); +TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(char *, SWIG_scm2str, SWIG_str02scm, string); +TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, SWIG_str02scm, string); /* For the char *, free all strings after converting */ @@ -312,13 +312,13 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, gh_str02scm, string const C_TYPE *PARALLEL_VECTORINPUT { SCM_VALIDATE_VECTOR($argnum, $input); - *_global_vector_length = gh_vector_length($input); + *_global_vector_length = scm_c_vector_length($input); if (*_global_vector_length > 0) { int i; $1 = (C_TYPE *) SWIG_malloc(sizeof(C_TYPE) * (*_global_vector_length)); for (i = 0; i<*_global_vector_length; i++) { - SCM swig_scm_value = gh_vector_ref($input, gh_int2scm(i)); + SCM swig_scm_value = scm_vector_ref($input, scm_from_long(i)); $1[i] = SCM_TO_C_EXPR; } } @@ -330,7 +330,7 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, gh_str02scm, string const C_TYPE *PARALLEL_LISTINPUT { SCM_VALIDATE_LIST($argnum, $input); - *_global_list_length = gh_length($input); + *_global_list_length = scm_to_ulong(scm_length($input)); if (*_global_list_length > 0) { int i; SCM rest; @@ -338,8 +338,8 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, gh_str02scm, string * (*_global_list_length)); for (i = 0, rest = $input; i<*_global_list_length; - i++, rest = gh_cdr(rest)) { - SCM swig_scm_value = gh_car(rest); + i++, rest = SCM_CDR(rest)) { + SCM swig_scm_value = SCM_CAR(rest); $1[i] = SCM_TO_C_EXPR; } } @@ -391,12 +391,12 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, gh_str02scm, string C_TYPE **PARALLEL_VECTOROUTPUT { int i; - SCM res = gh_make_vector(gh_int2scm(_global_arraylentemp), + SCM res = scm_make_vector(scm_from_long(_global_arraylentemp), SCM_BOOL_F); for (i = 0; i<_global_arraylentemp; i++) { C_TYPE swig_c_value = (*$1)[i]; SCM elt = C_TO_SCM_EXPR; - gh_vector_set_x(res, gh_int2scm(i), elt); + scm_vector_set_x(res, scm_from_long(i), elt); } SWIG_APPEND_VALUE(res); } @@ -410,7 +410,7 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, gh_str02scm, string for (i = _global_arraylentemp - 1; i>=0; i--) { C_TYPE swig_c_value = (*$1)[i]; SCM elt = C_TO_SCM_EXPR; - res = gh_cons(elt, res); + res = scm_cons(elt, res); } } SWIG_APPEND_VALUE(res); @@ -449,21 +449,21 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, gh_str02scm, string /* We use the macro to define typemaps for some standard types. */ -TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(bool, gh_scm2bool, gh_bool2scm, boolean); -TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(char, gh_scm2char, gh_char2scm, char); -TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(unsigned char, gh_scm2char, gh_char2scm, char); -TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(int, gh_scm2int, gh_int2scm, integer); -TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(short, gh_scm2int, gh_int2scm, integer); -TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(long, gh_scm2long, gh_long2scm, integer); -TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(ptrdiff_t, gh_scm2long, gh_long2scm, integer); -TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(unsigned int, gh_scm2ulong, gh_ulong2scm, integer); -TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(unsigned short, gh_scm2ulong, gh_ulong2scm, integer); -TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(unsigned long, gh_scm2ulong, gh_ulong2scm, integer); -TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(size_t, gh_scm2ulong, gh_ulong2scm, integer); -TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(float, gh_scm2double, gh_double2scm, real); -TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(double, gh_scm2double, gh_double2scm, real); -TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(char *, SWIG_scm2str, gh_str02scm, string); -TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, gh_str02scm, string); +TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(bool, scm_is_true, scm_from_bool, boolean); +TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(char, SCM_CHAR, SCM_MAKE_CHAR, char); +TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(unsigned char, SCM_CHAR, SCM_MAKE_CHAR, char); +TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(int, scm_to_int, scm_from_long, integer); +TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(short, scm_to_int, scm_from_long, integer); +TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(long, scm_to_long, scm_from_long, integer); +TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(ptrdiff_t, scm_to_long, scm_from_long, integer); +TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(unsigned int, scm_to_ulong, scm_from_ulong, integer); +TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(unsigned short, scm_to_ulong, scm_from_ulong, integer); +TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(unsigned long, scm_to_ulong, scm_from_ulong, integer); +TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(size_t, scm_to_ulong, scm_from_ulong, integer); +TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(float, scm_to_double, scm_from_double, real); +TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(double, scm_to_double, scm_from_double, real); +TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(char *, SWIG_scm2str, SWIG_str02scm, string); +TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, SWIG_str02scm, string); %typemap(freearg) char **PARALLEL_LISTINPUT, char **PARALLEL_VECTORINPUT, const char **PARALLEL_LISTINPUT, const char **PARALLEL_VECTORINPUT diff --git a/Lib/guile/std_common.i b/Lib/guile/std_common.i index a46c42c69..18c7db089 100644 --- a/Lib/guile/std_common.i +++ b/Lib/guile/std_common.i @@ -8,8 +8,8 @@ %apply size_t { std::size_t }; -#define SWIG_bool2scm(b) gh_bool2scm(b ? 1 : 0) -#define SWIG_string2scm(s) gh_str02scm(s.c_str()) +#define SWIG_bool2scm(b) scm_from_bool(b ? 1 : 0) +#define SWIG_string2scm(s) SWIG_str02scm(s.c_str()) %{ #include diff --git a/Lib/guile/std_map.i b/Lib/guile/std_map.i index eb28c2831..dfce6fc5c 100644 --- a/Lib/guile/std_map.i +++ b/Lib/guile/std_map.i @@ -42,30 +42,30 @@ namespace std { template class map { %typemap(in) map (std::map* m) { - if (gh_null_p($input)) { + if (scm_is_null($input)) { $1 = std::map(); - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { $1 = std::map(); SCM alist = $input; - while (!gh_null_p(alist)) { + while (!scm_is_null(alist)) { K* k; T* x; SCM entry, key, val; - entry = gh_car(alist); - if (!gh_pair_p(entry)) + entry = SCM_CAR(alist); + if (!scm_is_pair(entry)) SWIG_exception(SWIG_TypeError,"alist expected"); - key = gh_car(entry); - val = gh_cdr(entry); + key = SCM_CAR(entry); + val = SCM_CDR(entry); k = (K*) SWIG_MustGetPtr(key,$descriptor(K *),$argnum, 0); if (SWIG_ConvertPtr(val,(void**) &x, $descriptor(T *), 0) != 0) { - if (!gh_pair_p(val)) + if (!scm_is_pair(val)) SWIG_exception(SWIG_TypeError,"alist expected"); - val = gh_car(val); + val = SCM_CAR(val); x = (T*) SWIG_MustGetPtr(val,$descriptor(T *),$argnum, 0); } (($1_type &)$1)[*k] = *x; - alist = gh_cdr(alist); + alist = SCM_CDR(alist); } } else { $1 = *(($&1_type) @@ -76,32 +76,32 @@ namespace std { std::map* m), const map* (std::map temp, std::map* m) { - if (gh_null_p($input)) { + if (scm_is_null($input)) { temp = std::map(); $1 = &temp; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { temp = std::map(); $1 = &temp; SCM alist = $input; - while (!gh_null_p(alist)) { + while (!scm_is_null(alist)) { K* k; T* x; SCM entry, key, val; - entry = gh_car(alist); - if (!gh_pair_p(entry)) + entry = SCM_CAR(alist); + if (!scm_is_pair(entry)) SWIG_exception(SWIG_TypeError,"alist expected"); - key = gh_car(entry); - val = gh_cdr(entry); + key = SCM_CAR(entry); + val = SCM_CDR(entry); k = (K*) SWIG_MustGetPtr(key,$descriptor(K *),$argnum, 0); if (SWIG_ConvertPtr(val,(void**) &x, $descriptor(T *), 0) != 0) { - if (!gh_pair_p(val)) + if (!scm_is_pair(val)) SWIG_exception(SWIG_TypeError,"alist expected"); - val = gh_car(val); + val = SCM_CAR(val); x = (T*) SWIG_MustGetPtr(val,$descriptor(T *),$argnum, 0); } temp[*k] = *x; - alist = gh_cdr(alist); + alist = SCM_CDR(alist); } } else { $1 = ($1_ltype) SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0); @@ -115,24 +115,24 @@ namespace std { T* val = new T(i->second); SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1); SCM x = SWIG_NewPointerObj(val,$descriptor(T *), 1); - SCM entry = gh_cons(k,x); - alist = gh_cons(entry,alist); + SCM entry = scm_cons(k,x); + alist = scm_cons(entry,alist); } $result = alist; } %typecheck(SWIG_TYPECHECK_MAP) map { /* native sequence? */ - if (gh_null_p($input)) { + if (scm_is_null($input)) { /* an empty sequence can be of any type */ $1 = 1; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { /* check the first element only */ K* k; T* x; - SCM head = gh_car($input); - if (gh_pair_p(head)) { - SCM key = gh_car(head); - SCM val = gh_cdr(head); + SCM head = SCM_CAR($input); + if (scm_is_pair(head)) { + SCM key = SCM_CAR(head); + SCM val = SCM_CDR(head); if (SWIG_ConvertPtr(key,(void**) &k, $descriptor(K *), 0) != 0) { $1 = 0; @@ -140,8 +140,8 @@ namespace std { if (SWIG_ConvertPtr(val,(void**) &x, $descriptor(T *), 0) == 0) { $1 = 1; - } else if (gh_pair_p(val)) { - val = gh_car(val); + } else if (scm_is_pair(val)) { + val = SCM_CAR(val); if (SWIG_ConvertPtr(val,(void**) &x, $descriptor(T *), 0) == 0) $1 = 1; @@ -167,17 +167,17 @@ namespace std { %typecheck(SWIG_TYPECHECK_MAP) const map&, const map* { /* native sequence? */ - if (gh_null_p($input)) { + if (scm_is_null($input)) { /* an empty sequence can be of any type */ $1 = 1; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { /* check the first element only */ K* k; T* x; - SCM head = gh_car($input); - if (gh_pair_p(head)) { - SCM key = gh_car(head); - SCM val = gh_cdr(head); + SCM head = SCM_CAR($input); + if (scm_is_pair(head)) { + SCM key = SCM_CAR(head); + SCM val = SCM_CDR(head); if (SWIG_ConvertPtr(key,(void**) &k, $descriptor(K *), 0) != 0) { $1 = 0; @@ -185,8 +185,8 @@ namespace std { if (SWIG_ConvertPtr(val,(void**) &x, $descriptor(T *), 0) == 0) { $1 = 1; - } else if (gh_pair_p(val)) { - val = gh_car(val); + } else if (scm_is_pair(val)) { + val = SCM_CAR(val); if (SWIG_ConvertPtr(val,(void**) &x, $descriptor(T *), 0) == 0) $1 = 1; @@ -255,7 +255,7 @@ namespace std { i!=$1.rend(); ++i) { K* key = new K(i->first); SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1); - result = gh_cons(k,result); + result = scm_cons(k,result); } return result; } @@ -269,31 +269,31 @@ namespace std { template class map { %typemap(in) map (std::map* m) { - if (gh_null_p($input)) { + if (scm_is_null($input)) { $1 = std::map(); - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { $1 = std::map(); SCM alist = $input; - while (!gh_null_p(alist)) { + while (!scm_is_null(alist)) { T* x; SCM entry, key, val; - entry = gh_car(alist); - if (!gh_pair_p(entry)) + entry = SCM_CAR(alist); + if (!scm_is_pair(entry)) SWIG_exception(SWIG_TypeError,"alist expected"); - key = gh_car(entry); - val = gh_cdr(entry); + key = SCM_CAR(entry); + val = SCM_CDR(entry); if (!CHECK(key)) SWIG_exception(SWIG_TypeError, "map<" #K "," #T "> expected"); if (SWIG_ConvertPtr(val,(void**) &x, $descriptor(T *), 0) != 0) { - if (!gh_pair_p(val)) + if (!scm_is_pair(val)) SWIG_exception(SWIG_TypeError,"alist expected"); - val = gh_car(val); + val = SCM_CAR(val); x = (T*) SWIG_MustGetPtr(val,$descriptor(T *),$argnum, 0); } (($1_type &)$1)[CONVERT_FROM(key)] = *x; - alist = gh_cdr(alist); + alist = SCM_CDR(alist); } } else { $1 = *(($&1_type) @@ -304,33 +304,33 @@ namespace std { std::map* m), const map* (std::map temp, std::map* m) { - if (gh_null_p($input)) { + if (scm_is_null($input)) { temp = std::map(); $1 = &temp; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { temp = std::map(); $1 = &temp; SCM alist = $input; - while (!gh_null_p(alist)) { + while (!scm_is_null(alist)) { T* x; SCM entry, key, val; - entry = gh_car(alist); - if (!gh_pair_p(entry)) + entry = SCM_CAR(alist); + if (!scm_is_pair(entry)) SWIG_exception(SWIG_TypeError,"alist expected"); - key = gh_car(entry); - val = gh_cdr(entry); + key = SCM_CAR(entry); + val = SCM_CDR(entry); if (!CHECK(key)) SWIG_exception(SWIG_TypeError, "map<" #K "," #T "> expected"); if (SWIG_ConvertPtr(val,(void**) &x, $descriptor(T *), 0) != 0) { - if (!gh_pair_p(val)) + if (!scm_is_pair(val)) SWIG_exception(SWIG_TypeError,"alist expected"); - val = gh_car(val); + val = SCM_CAR(val); x = (T*) SWIG_MustGetPtr(val,$descriptor(T *),$argnum, 0); } temp[CONVERT_FROM(key)] = *x; - alist = gh_cdr(alist); + alist = SCM_CDR(alist); } } else { $1 = ($1_ltype) SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0); @@ -343,31 +343,31 @@ namespace std { T* val = new T(i->second); SCM k = CONVERT_TO(i->first); SCM x = SWIG_NewPointerObj(val,$descriptor(T *), 1); - SCM entry = gh_cons(k,x); - alist = gh_cons(entry,alist); + SCM entry = scm_cons(k,x); + alist = scm_cons(entry,alist); } $result = alist; } %typecheck(SWIG_TYPECHECK_MAP) map { // native sequence? - if (gh_null_p($input)) { + if (scm_is_null($input)) { /* an empty sequence can be of any type */ $1 = 1; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { // check the first element only T* x; - SCM head = gh_car($input); - if (gh_pair_p(head)) { - SCM key = gh_car(head); - SCM val = gh_cdr(head); + SCM head = SCM_CAR($input); + if (scm_is_pair(head)) { + SCM key = SCM_CAR(head); + SCM val = SCM_CDR(head); if (!CHECK(key)) { $1 = 0; } else { if (SWIG_ConvertPtr(val,(void**) &x, $descriptor(T *), 0) == 0) { $1 = 1; - } else if (gh_pair_p(val)) { - val = gh_car(val); + } else if (scm_is_pair(val)) { + val = SCM_CAR(val); if (SWIG_ConvertPtr(val,(void**) &x, $descriptor(T *), 0) == 0) $1 = 1; @@ -393,24 +393,24 @@ namespace std { %typecheck(SWIG_TYPECHECK_MAP) const map&, const map* { // native sequence? - if (gh_null_p($input)) { + if (scm_is_null($input)) { /* an empty sequence can be of any type */ $1 = 1; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { // check the first element only T* x; - SCM head = gh_car($input); - if (gh_pair_p(head)) { - SCM key = gh_car(head); - SCM val = gh_cdr(head); + SCM head = SCM_CAR($input); + if (scm_is_pair(head)) { + SCM key = SCM_CAR(head); + SCM val = SCM_CDR(head); if (!CHECK(key)) { $1 = 0; } else { if (SWIG_ConvertPtr(val,(void**) &x, $descriptor(T *), 0) == 0) { $1 = 1; - } else if (gh_pair_p(val)) { - val = gh_car(val); + } else if (scm_is_pair(val)) { + val = SCM_CAR(val); if (SWIG_ConvertPtr(val,(void**) &x, $descriptor(T *), 0) == 0) $1 = 1; @@ -474,7 +474,7 @@ namespace std { for (std::map::reverse_iterator i=$1.rbegin(); i!=$1.rend(); ++i) { SCM k = CONVERT_TO(i->first); - result = gh_cons(k,result); + result = scm_cons(k,result); } return result; } @@ -485,30 +485,30 @@ namespace std { %define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) template class map { %typemap(in) map (std::map* m) { - if (gh_null_p($input)) { + if (scm_is_null($input)) { $1 = std::map(); - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { $1 = std::map(); SCM alist = $input; - while (!gh_null_p(alist)) { + while (!scm_is_null(alist)) { K* k; SCM entry, key, val; - entry = gh_car(alist); - if (!gh_pair_p(entry)) + entry = SCM_CAR(alist); + if (!scm_is_pair(entry)) SWIG_exception(SWIG_TypeError,"alist expected"); - key = gh_car(entry); - val = gh_cdr(entry); + key = SCM_CAR(entry); + val = SCM_CDR(entry); k = (K*) SWIG_MustGetPtr(key,$descriptor(K *),$argnum, 0); if (!CHECK(val)) { - if (!gh_pair_p(val)) + if (!scm_is_pair(val)) SWIG_exception(SWIG_TypeError,"alist expected"); - val = gh_car(val); + val = SCM_CAR(val); if (!CHECK(val)) SWIG_exception(SWIG_TypeError, "map<" #K "," #T "> expected"); } (($1_type &)$1)[*k] = CONVERT_FROM(val); - alist = gh_cdr(alist); + alist = SCM_CDR(alist); } } else { $1 = *(($&1_type) @@ -519,32 +519,32 @@ namespace std { std::map* m), const map* (std::map temp, std::map* m) { - if (gh_null_p($input)) { + if (scm_is_null($input)) { temp = std::map(); $1 = &temp; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { temp = std::map(); $1 = &temp; SCM alist = $input; - while (!gh_null_p(alist)) { + while (!scm_is_null(alist)) { K* k; SCM entry, key, val; - entry = gh_car(alist); - if (!gh_pair_p(entry)) + entry = SCM_CAR(alist); + if (!scm_is_pair(entry)) SWIG_exception(SWIG_TypeError,"alist expected"); - key = gh_car(entry); - val = gh_cdr(entry); + key = SCM_CAR(entry); + val = SCM_CDR(entry); k = (K*) SWIG_MustGetPtr(key,$descriptor(K *),$argnum, 0); if (!CHECK(val)) { - if (!gh_pair_p(val)) + if (!scm_is_pair(val)) SWIG_exception(SWIG_TypeError,"alist expected"); - val = gh_car(val); + val = SCM_CAR(val); if (!CHECK(val)) SWIG_exception(SWIG_TypeError, "map<" #K "," #T "> expected"); } temp[*k] = CONVERT_FROM(val); - alist = gh_cdr(alist); + alist = SCM_CDR(alist); } } else { $1 = ($1_ltype) SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0); @@ -557,31 +557,31 @@ namespace std { K* key = new K(i->first); SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1); SCM x = CONVERT_TO(i->second); - SCM entry = gh_cons(k,x); - alist = gh_cons(entry,alist); + SCM entry = scm_cons(k,x); + alist = scm_cons(entry,alist); } $result = alist; } %typecheck(SWIG_TYPECHECK_MAP) map { // native sequence? - if (gh_null_p($input)) { + if (scm_is_null($input)) { /* an empty sequence can be of any type */ $1 = 1; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { // check the first element only K* k; - SCM head = gh_car($input); - if (gh_pair_p(head)) { - SCM key = gh_car(head); - SCM val = gh_cdr(head); + SCM head = SCM_CAR($input); + if (scm_is_pair(head)) { + SCM key = SCM_CAR(head); + SCM val = SCM_CDR(head); if (SWIG_ConvertPtr(val,(void **) &k, $descriptor(K *), 0) != 0) { $1 = 0; } else { if (CHECK(val)) { $1 = 1; - } else if (gh_pair_p(val)) { - val = gh_car(val); + } else if (scm_is_pair(val)) { + val = SCM_CAR(val); if (CHECK(val)) $1 = 1; else @@ -606,24 +606,24 @@ namespace std { %typecheck(SWIG_TYPECHECK_MAP) const map&, const map* { // native sequence? - if (gh_null_p($input)) { + if (scm_is_null($input)) { /* an empty sequence can be of any type */ $1 = 1; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { // check the first element only K* k; - SCM head = gh_car($input); - if (gh_pair_p(head)) { - SCM key = gh_car(head); - SCM val = gh_cdr(head); + SCM head = SCM_CAR($input); + if (scm_is_pair(head)) { + SCM key = SCM_CAR(head); + SCM val = SCM_CDR(head); if (SWIG_ConvertPtr(val,(void **) &k, $descriptor(K *), 0) != 0) { $1 = 0; } else { if (CHECK(val)) { $1 = 1; - } else if (gh_pair_p(val)) { - val = gh_car(val); + } else if (scm_is_pair(val)) { + val = SCM_CAR(val); if (CHECK(val)) $1 = 1; else @@ -687,7 +687,7 @@ namespace std { i!=$1.rend(); ++i) { K* key = new K(i->first); SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1); - result = gh_cons(k,result); + result = scm_cons(k,result); } return result; } @@ -699,32 +699,32 @@ namespace std { T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) template<> class map { %typemap(in) map (std::map* m) { - if (gh_null_p($input)) { + if (scm_is_null($input)) { $1 = std::map(); - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { $1 = std::map(); SCM alist = $input; - while (!gh_null_p(alist)) { + while (!scm_is_null(alist)) { SCM entry, key, val; - entry = gh_car(alist); - if (!gh_pair_p(entry)) + entry = SCM_CAR(alist); + if (!scm_is_pair(entry)) SWIG_exception(SWIG_TypeError,"alist expected"); - key = gh_car(entry); - val = gh_cdr(entry); + key = SCM_CAR(entry); + val = SCM_CDR(entry); if (!CHECK_K(key)) SWIG_exception(SWIG_TypeError, "map<" #K "," #T "> expected"); if (!CHECK_T(val)) { - if (!gh_pair_p(val)) + if (!scm_is_pair(val)) SWIG_exception(SWIG_TypeError,"alist expected"); - val = gh_car(val); + val = SCM_CAR(val); if (!CHECK_T(val)) SWIG_exception(SWIG_TypeError, "map<" #K "," #T "> expected"); } (($1_type &)$1)[CONVERT_K_FROM(key)] = CONVERT_T_FROM(val); - alist = gh_cdr(alist); + alist = SCM_CDR(alist); } } else { $1 = *(($&1_type) @@ -735,33 +735,33 @@ namespace std { std::map* m), const map* (std::map temp, std::map* m) { - if (gh_null_p($input)) { + if (scm_is_null($input)) { temp = std::map(); $1 = &temp; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { temp = std::map(); $1 = &temp; SCM alist = $input; - while (!gh_null_p(alist)) { + while (!scm_is_null(alist)) { SCM entry, key, val; - entry = gh_car(alist); - if (!gh_pair_p(entry)) + entry = SCM_CAR(alist); + if (!scm_is_pair(entry)) SWIG_exception(SWIG_TypeError,"alist expected"); - key = gh_car(entry); - val = gh_cdr(entry); + key = SCM_CAR(entry); + val = SCM_CDR(entry); if (!CHECK_K(key)) SWIG_exception(SWIG_TypeError, "map<" #K "," #T "> expected"); if (!CHECK_T(val)) { - if (!gh_pair_p(val)) + if (!scm_is_pair(val)) SWIG_exception(SWIG_TypeError,"alist expected"); - val = gh_car(val); + val = SCM_CAR(val); if (!CHECK_T(val)) SWIG_exception(SWIG_TypeError, "map<" #K "," #T "> expected"); } temp[CONVERT_K_FROM(key)] = CONVERT_T_FROM(val); - alist = gh_cdr(alist); + alist = SCM_CDR(alist); } } else { $1 = ($1_ltype) SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0); @@ -773,29 +773,29 @@ namespace std { i!=$1.rend(); ++i) { SCM k = CONVERT_K_TO(i->first); SCM x = CONVERT_T_TO(i->second); - SCM entry = gh_cons(k,x); - alist = gh_cons(entry,alist); + SCM entry = scm_cons(k,x); + alist = scm_cons(entry,alist); } $result = alist; } %typecheck(SWIG_TYPECHECK_MAP) map { // native sequence? - if (gh_null_p($input)) { + if (scm_is_null($input)) { /* an empty sequence can be of any type */ $1 = 1; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { // check the first element only - SCM head = gh_car($input); - if (gh_pair_p(head)) { - SCM key = gh_car(head); - SCM val = gh_cdr(head); + SCM head = SCM_CAR($input); + if (scm_is_pair(head)) { + SCM key = SCM_CAR(head); + SCM val = SCM_CDR(head); if (!CHECK_K(key)) { $1 = 0; } else { if (CHECK_T(val)) { $1 = 1; - } else if (gh_pair_p(val)) { - val = gh_car(val); + } else if (scm_is_pair(val)) { + val = SCM_CAR(val); if (CHECK_T(val)) $1 = 1; else @@ -820,22 +820,22 @@ namespace std { %typecheck(SWIG_TYPECHECK_MAP) const map&, const map* { // native sequence? - if (gh_null_p($input)) { + if (scm_is_null($input)) { /* an empty sequence can be of any type */ $1 = 1; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { // check the first element only - SCM head = gh_car($input); - if (gh_pair_p(head)) { - SCM key = gh_car(head); - SCM val = gh_cdr(head); + SCM head = SCM_CAR($input); + if (scm_is_pair(head)) { + SCM key = SCM_CAR(head); + SCM val = SCM_CDR(head); if (!CHECK_K(key)) { $1 = 0; } else { if (CHECK_T(val)) { $1 = 1; - } else if (gh_pair_p(val)) { - val = gh_car(val); + } else if (scm_is_pair(val)) { + val = SCM_CAR(val); if (CHECK_T(val)) $1 = 1; else @@ -898,7 +898,7 @@ namespace std { for (std::map::reverse_iterator i=$1.rbegin(); i!=$1.rend(); ++i) { SCM k = CONVERT_K_TO(i->first); - result = gh_cons(k,result); + result = scm_cons(k,result); } return result; } @@ -907,446 +907,446 @@ namespace std { %enddef - specialize_std_map_on_key(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_map_on_key(int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_key(short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_key(long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_key(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_key(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_key(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_key(double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_key(float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_key(std::string,gh_string_p, + specialize_std_map_on_key(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_map_on_key(int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_key(short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_key(long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_key(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_key(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_key(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_key(double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_key(float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_key(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_value(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_map_on_value(int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_value(short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_value(long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_value(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_value(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_value(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_value(double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_value(float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_value(std::string,gh_string_p, + specialize_std_map_on_value(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_map_on_value(int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_value(short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_value(long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_value(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_value(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_value(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_value(double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_value(float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_value(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_map_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - std::string,gh_string_p, + specialize_std_map_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_map_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_map_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - std::string,gh_string_p, + specialize_std_map_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_map_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_map_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - std::string,gh_string_p, + specialize_std_map_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_map_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_map_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - std::string,gh_string_p, + specialize_std_map_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_map_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_map_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - std::string,gh_string_p, + specialize_std_map_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_map_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_map_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - std::string,gh_string_p, + specialize_std_map_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_map_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_map_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - std::string,gh_string_p, + specialize_std_map_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_map_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_map_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - std::string,gh_string_p, + specialize_std_map_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_map_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_map_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - std::string,gh_string_p, + specialize_std_map_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_map_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(std::string,gh_string_p, + specialize_std_map_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_map_on_both(std::string,gh_string_p, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_map_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(std::string,gh_string_p, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(std::string,gh_string_p, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_map_on_both(std::string,gh_string_p, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_map_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(std::string,gh_string_p, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(std::string,gh_string_p, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_map_on_both(std::string,gh_string_p, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_map_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(std::string,gh_string_p, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_map_on_both(std::string,gh_string_p, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_map_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - std::string,gh_string_p, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); } diff --git a/Lib/guile/std_pair.i b/Lib/guile/std_pair.i index 35f0cfad5..86ca6e00f 100644 --- a/Lib/guile/std_pair.i +++ b/Lib/guile/std_pair.i @@ -23,12 +23,12 @@ namespace std { template struct pair { %typemap(in) pair (std::pair* m) { - if (gh_pair_p($input)) { + if (scm_is_pair($input)) { T* x; U* y; SCM first, second; - first = gh_car($input); - second = gh_cdr($input); + first = SCM_CAR($input); + second = SCM_CDR($input); x = (T*) SWIG_MustGetPtr(first,$descriptor(T *),$argnum, 0); y = (U*) SWIG_MustGetPtr(second,$descriptor(U *),$argnum, 0); $1 = std::make_pair(*x,*y); @@ -41,12 +41,12 @@ namespace std { std::pair* m), const pair* (std::pair temp, std::pair* m) { - if (gh_pair_p($input)) { + if (scm_is_pair($input)) { T* x; U* y; SCM first, second; - first = gh_car($input); - second = gh_cdr($input); + first = SCM_CAR($input); + second = SCM_CDR($input); x = (T*) SWIG_MustGetPtr(first,$descriptor(T *),$argnum, 0); y = (U*) SWIG_MustGetPtr(second,$descriptor(U *),$argnum, 0); temp = std::make_pair(*x,*y); @@ -61,15 +61,15 @@ namespace std { U* y = new U($1.second); SCM first = SWIG_NewPointerObj(x,$descriptor(T *), 1); SCM second = SWIG_NewPointerObj(y,$descriptor(U *), 1); - $result = gh_cons(first,second); + $result = scm_cons(first,second); } %typecheck(SWIG_TYPECHECK_PAIR) pair { /* native pair? */ - if (gh_pair_p($input)) { + if (scm_is_pair($input)) { T* x; U* y; - SCM first = gh_car($input); - SCM second = gh_cdr($input); + SCM first = SCM_CAR($input); + SCM second = SCM_CDR($input); if (SWIG_ConvertPtr(first,(void**) &x, $descriptor(T *), 0) == 0 && SWIG_ConvertPtr(second,(void**) &y, @@ -91,11 +91,11 @@ namespace std { %typecheck(SWIG_TYPECHECK_PAIR) const pair&, const pair* { /* native pair? */ - if (gh_pair_p($input)) { + if (scm_is_pair($input)) { T* x; U* y; - SCM first = gh_car($input); - SCM second = gh_cdr($input); + SCM first = SCM_CAR($input); + SCM second = SCM_CDR($input); if (SWIG_ConvertPtr(first,(void**) &x, $descriptor(T *), 0) == 0 && SWIG_ConvertPtr(second,(void**) &y, @@ -130,11 +130,11 @@ namespace std { %define specialize_std_pair_on_first(T,CHECK,CONVERT_FROM,CONVERT_TO) template struct pair { %typemap(in) pair (std::pair* m) { - if (gh_pair_p($input)) { + if (scm_is_pair($input)) { U* y; SCM first, second; - first = gh_car($input); - second = gh_cdr($input); + first = SCM_CAR($input); + second = SCM_CDR($input); if (!CHECK(first)) SWIG_exception(SWIG_TypeError, "map<" #T "," #U "> expected"); @@ -149,11 +149,11 @@ namespace std { std::pair* m), const pair* (std::pair temp, std::pair* m) { - if (gh_pair_p($input)) { + if (scm_is_pair($input)) { U* y; SCM first, second; - first = gh_car($input); - second = gh_cdr($input); + first = SCM_CAR($input); + second = SCM_CDR($input); if (!CHECK(first)) SWIG_exception(SWIG_TypeError, "map<" #T "," #U "> expected"); @@ -168,14 +168,14 @@ namespace std { %typemap(out) pair { U* y = new U($1.second); SCM second = SWIG_NewPointerObj(y,$descriptor(U *), 1); - $result = gh_cons(CONVERT_TO($1.first),second); + $result = scm_cons(CONVERT_TO($1.first),second); } %typecheck(SWIG_TYPECHECK_PAIR) pair { /* native pair? */ - if (gh_pair_p($input)) { + if (scm_is_pair($input)) { U* y; - SCM first = gh_car($input); - SCM second = gh_cdr($input); + SCM first = SCM_CAR($input); + SCM second = SCM_CDR($input); if (CHECK(first) && SWIG_ConvertPtr(second,(void**) &y, $descriptor(U *), 0) == 0) { @@ -196,10 +196,10 @@ namespace std { %typecheck(SWIG_TYPECHECK_PAIR) const pair&, const pair* { /* native pair? */ - if (gh_pair_p($input)) { + if (scm_is_pair($input)) { U* y; - SCM first = gh_car($input); - SCM second = gh_cdr($input); + SCM first = SCM_CAR($input); + SCM second = SCM_CDR($input); if (CHECK(first) && SWIG_ConvertPtr(second,(void**) &y, $descriptor(U *), 0) == 0) { @@ -231,11 +231,11 @@ namespace std { %define specialize_std_pair_on_second(U,CHECK,CONVERT_FROM,CONVERT_TO) template struct pair { %typemap(in) pair (std::pair* m) { - if (gh_pair_p($input)) { + if (scm_is_pair($input)) { T* x; SCM first, second; - first = gh_car($input); - second = gh_cdr($input); + first = SCM_CAR($input); + second = SCM_CDR($input); x = (T*) SWIG_MustGetPtr(first,$descriptor(T *),$argnum, 0); if (!CHECK(second)) SWIG_exception(SWIG_TypeError, @@ -250,11 +250,11 @@ namespace std { std::pair* m), const pair* (std::pair temp, std::pair* m) { - if (gh_pair_p($input)) { + if (scm_is_pair($input)) { T* x; SCM first, second; - first = gh_car($input); - second = gh_cdr($input); + first = SCM_CAR($input); + second = SCM_CDR($input); x = (T*) SWIG_MustGetPtr(first,$descriptor(T *),$argnum, 0); if (!CHECK(second)) SWIG_exception(SWIG_TypeError, @@ -269,14 +269,14 @@ namespace std { %typemap(out) pair { T* x = new T($1.first); SCM first = SWIG_NewPointerObj(x,$descriptor(T *), 1); - $result = gh_cons(first,CONVERT_TO($1.second)); + $result = scm_cons(first,CONVERT_TO($1.second)); } %typecheck(SWIG_TYPECHECK_PAIR) pair { /* native pair? */ - if (gh_pair_p($input)) { + if (scm_is_pair($input)) { T* x; - SCM first = gh_car($input); - SCM second = gh_cdr($input); + SCM first = SCM_CAR($input); + SCM second = SCM_CDR($input); if (SWIG_ConvertPtr(first,(void**) &x, $descriptor(T *), 0) == 0 && CHECK(second)) { @@ -297,10 +297,10 @@ namespace std { %typecheck(SWIG_TYPECHECK_PAIR) const pair&, const pair* { /* native pair? */ - if (gh_pair_p($input)) { + if (scm_is_pair($input)) { T* x; - SCM first = gh_car($input); - SCM second = gh_cdr($input); + SCM first = SCM_CAR($input); + SCM second = SCM_CDR($input); if (SWIG_ConvertPtr(first,(void**) &x, $descriptor(T *), 0) == 0 && CHECK(second)) { @@ -333,10 +333,10 @@ namespace std { U,CHECK_U,CONVERT_U_FROM,CONVERT_U_TO) template<> struct pair { %typemap(in) pair (std::pair* m) { - if (gh_pair_p($input)) { + if (scm_is_pair($input)) { SCM first, second; - first = gh_car($input); - second = gh_cdr($input); + first = SCM_CAR($input); + second = SCM_CDR($input); if (!CHECK_T(first) || !CHECK_U(second)) SWIG_exception(SWIG_TypeError, "map<" #T "," #U "> expected"); @@ -351,10 +351,10 @@ namespace std { std::pair* m), const pair* (std::pair temp, std::pair* m) { - if (gh_pair_p($input)) { + if (scm_is_pair($input)) { SCM first, second; - first = gh_car($input); - second = gh_cdr($input); + first = SCM_CAR($input); + second = SCM_CDR($input); if (!CHECK_T(first) || !CHECK_U(second)) SWIG_exception(SWIG_TypeError, "map<" #T "," #U "> expected"); @@ -367,14 +367,14 @@ namespace std { } } %typemap(out) pair { - $result = gh_cons(CONVERT_T_TO($1.first), + $result = scm_cons(CONVERT_T_TO($1.first), CONVERT_U_TO($1.second)); } %typecheck(SWIG_TYPECHECK_PAIR) pair { /* native pair? */ - if (gh_pair_p($input)) { - SCM first = gh_car($input); - SCM second = gh_cdr($input); + if (scm_is_pair($input)) { + SCM first = SCM_CAR($input); + SCM second = SCM_CDR($input); if (CHECK_T(first) && CHECK_U(second)) { $1 = 1; } else { @@ -393,9 +393,9 @@ namespace std { %typecheck(SWIG_TYPECHECK_PAIR) const pair&, const pair* { /* native pair? */ - if (gh_pair_p($input)) { - SCM first = gh_car($input); - SCM second = gh_cdr($input); + if (scm_is_pair($input)) { + SCM first = SCM_CAR($input); + SCM second = SCM_CDR($input); if (CHECK_T(first) && CHECK_U(second)) { $1 = 1; } else { @@ -423,446 +423,446 @@ namespace std { %enddef - specialize_std_pair_on_first(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_pair_on_first(int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_first(short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_first(long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_first(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_first(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_first(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_first(double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_first(float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_first(std::string,gh_string_p, + specialize_std_pair_on_first(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_pair_on_first(int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_first(short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_first(long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_first(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_first(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_first(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_first(double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_first(float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_first(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_pair_on_second(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_pair_on_second(int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_second(short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_second(long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_second(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_second(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_second(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_second(double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_second(float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_second(std::string,gh_string_p, + specialize_std_pair_on_second(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_pair_on_second(int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_second(short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_second(long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_second(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_second(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_second(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_second(double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_second(float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_second(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_pair_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_pair_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm, - std::string,gh_string_p, + specialize_std_pair_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_pair_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(bool,scm_is_bool, + scm_is_true,SWIG_bool2scm, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_pair_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_pair_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(int,gh_number_p, - gh_scm2long,gh_long2scm, - std::string,gh_string_p, + specialize_std_pair_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_pair_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(int,scm_is_number, + scm_to_long,scm_from_long, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_pair_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_pair_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(short,gh_number_p, - gh_scm2long,gh_long2scm, - std::string,gh_string_p, + specialize_std_pair_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_pair_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(short,scm_is_number, + scm_to_long,scm_from_long, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_pair_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_pair_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(long,gh_number_p, - gh_scm2long,gh_long2scm, - std::string,gh_string_p, + specialize_std_pair_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_pair_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(long,scm_is_number, + scm_to_long,scm_from_long, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_pair_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_pair_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - std::string,gh_string_p, + specialize_std_pair_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_pair_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_pair_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_pair_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - std::string,gh_string_p, + specialize_std_pair_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_pair_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_pair_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_pair_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm, - std::string,gh_string_p, + specialize_std_pair_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_pair_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_pair_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_pair_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(double,gh_number_p, - gh_scm2double,gh_double2scm, - std::string,gh_string_p, + specialize_std_pair_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_pair_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(double,scm_is_number, + scm_to_double,scm_from_double, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_pair_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_pair_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(float,gh_number_p, - gh_scm2double,gh_double2scm, - std::string,gh_string_p, + specialize_std_pair_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_pair_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(float,scm_is_number, + scm_to_double,scm_from_double, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); - specialize_std_pair_on_both(std::string,gh_string_p, + specialize_std_pair_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - bool,gh_boolean_p, - gh_scm2bool,SWIG_bool2scm); - specialize_std_pair_on_both(std::string,gh_string_p, + bool,scm_is_bool, + scm_is_true,SWIG_bool2scm); + specialize_std_pair_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - int,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(std::string,gh_string_p, + int,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - short,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(std::string,gh_string_p, + short,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - long,gh_number_p, - gh_scm2long,gh_long2scm); - specialize_std_pair_on_both(std::string,gh_string_p, + long,scm_is_number, + scm_to_long,scm_from_long); + specialize_std_pair_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - unsigned int,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(std::string,gh_string_p, + unsigned int,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - unsigned short,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(std::string,gh_string_p, + unsigned short,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - unsigned long,gh_number_p, - gh_scm2ulong,gh_ulong2scm); - specialize_std_pair_on_both(std::string,gh_string_p, + unsigned long,scm_is_number, + scm_to_ulong,scm_from_ulong); + specialize_std_pair_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - double,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(std::string,gh_string_p, + double,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - float,gh_number_p, - gh_scm2double,gh_double2scm); - specialize_std_pair_on_both(std::string,gh_string_p, + float,scm_is_number, + scm_to_double,scm_from_double); + specialize_std_pair_on_both(std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm, - std::string,gh_string_p, + std::string,scm_is_string, SWIG_scm2string,SWIG_string2scm); } diff --git a/Lib/guile/std_string.i b/Lib/guile/std_string.i index 83e0dd26d..6513173ee 100644 --- a/Lib/guile/std_string.i +++ b/Lib/guile/std_string.i @@ -27,7 +27,7 @@ namespace std { %typemap(typecheck) const string & = char *; %typemap(in) string (char * tempptr) { - if (gh_string_p($input)) { + if (scm_is_string($input)) { tempptr = SWIG_scm2str($input); $1.assign(tempptr); if (tempptr) SWIG_free(tempptr); @@ -37,7 +37,7 @@ namespace std { } %typemap(in) const string & ($*1_ltype temp, char *tempptr) { - if (gh_string_p($input)) { + if (scm_is_string($input)) { tempptr = SWIG_scm2str($input); temp.assign(tempptr); if (tempptr) SWIG_free(tempptr); @@ -48,7 +48,7 @@ namespace std { } %typemap(in) string * (char *tempptr) { - if (gh_string_p($input)) { + if (scm_is_string($input)) { tempptr = SWIG_scm2str($input); $1 = new $*1_ltype(tempptr); if (tempptr) SWIG_free(tempptr); @@ -58,19 +58,19 @@ namespace std { } %typemap(out) string { - $result = gh_str02scm($1.c_str()); + $result = SWIG_str02scm($1.c_str()); } %typemap(out) const string & { - $result = gh_str02scm($1->c_str()); + $result = SWIG_str02scm($1->c_str()); } %typemap(out) string * { - $result = gh_str02scm($1->c_str()); + $result = SWIG_str02scm($1->c_str()); } %typemap(varin) string { - if (gh_string_p($input)) { + if (scm_is_string($input)) { char *tempptr = SWIG_scm2str($input); $1.assign(tempptr); if (tempptr) SWIG_free(tempptr); @@ -80,7 +80,7 @@ namespace std { } %typemap(varout) string { - $result = gh_str02scm($1.c_str()); + $result = SWIG_str02scm($1.c_str()); } } diff --git a/Lib/guile/std_vector.i b/Lib/guile/std_vector.i index 6a5e8ae36..79c716b10 100644 --- a/Lib/guile/std_vector.i +++ b/Lib/guile/std_vector.i @@ -42,23 +42,23 @@ namespace std { template class vector { %typemap(in) vector { - if (gh_vector_p($input)) { - unsigned long size = gh_vector_length($input); + if (scm_is_vector($input)) { + unsigned long size = scm_c_vector_length($input); $1 = std::vector(size); for (unsigned long i=0; i(); - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { SCM head, tail; $1 = std::vector(); tail = $input; - while (!gh_null_p(tail)) { - head = gh_car(tail); - tail = gh_cdr(tail); + while (!scm_is_null(tail)) { + head = SCM_CAR(tail); + tail = SCM_CDR(tail); $1.push_back(*((T*)SWIG_MustGetPtr(head, $descriptor(T *), $argnum, 0))); @@ -70,27 +70,27 @@ namespace std { } %typemap(in) const vector& (std::vector temp), const vector* (std::vector temp) { - if (gh_vector_p($input)) { - unsigned long size = gh_vector_length($input); + if (scm_is_vector($input)) { + unsigned long size = scm_c_vector_length($input); temp = std::vector(size); $1 = &temp; for (unsigned long i=0; i(); $1 = &temp; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { temp = std::vector(); $1 = &temp; SCM head, tail; tail = $input; - while (!gh_null_p(tail)) { - head = gh_car(tail); - tail = gh_cdr(tail); + while (!scm_is_null(tail)) { + head = SCM_CAR(tail); + tail = SCM_CDR(tail); temp.push_back(*((T*) SWIG_MustGetPtr(head, $descriptor(T *), $argnum, 0))); @@ -100,23 +100,23 @@ namespace std { } } %typemap(out) vector { - $result = gh_make_vector(gh_long2scm($1.size()),SCM_UNSPECIFIED); + $result = scm_make_vector(scm_from_long($1.size()),SCM_UNSPECIFIED); for (unsigned int i=0; i<$1.size(); i++) { T* x = new T((($1_type &)$1)[i]); - gh_vector_set_x($result,gh_long2scm(i), + scm_vector_set_x($result,scm_from_long(i), SWIG_NewPointerObj(x, $descriptor(T *), 1)); } } %typecheck(SWIG_TYPECHECK_VECTOR) vector { /* native sequence? */ - if (gh_vector_p($input)) { - unsigned int size = gh_vector_length($input); + if (scm_is_vector($input)) { + unsigned int size = scm_c_vector_length($input); if (size == 0) { /* an empty sequence can be of any type */ $1 = 1; } else { /* check the first element only */ - SCM o = gh_vector_ref($input,gh_ulong2scm(0)); + SCM o = scm_vector_ref($input,scm_from_ulong(0)); T* x; if (SWIG_ConvertPtr(o,(void**) &x, $descriptor(T *), 0) != -1) @@ -124,13 +124,13 @@ namespace std { else $1 = 0; } - } else if (gh_null_p($input)) { + } else if (scm_is_null($input)) { /* again, an empty sequence can be of any type */ $1 = 1; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { /* check the first element only */ T* x; - SCM head = gh_car($input); + SCM head = SCM_CAR($input); if (SWIG_ConvertPtr(head,(void**) &x, $descriptor(T *), 0) != -1) $1 = 1; @@ -149,28 +149,28 @@ namespace std { %typecheck(SWIG_TYPECHECK_VECTOR) const vector&, const vector* { /* native sequence? */ - if (gh_vector_p($input)) { - unsigned int size = gh_vector_length($input); + if (scm_is_vector($input)) { + unsigned int size = scm_c_vector_length($input); if (size == 0) { /* an empty sequence can be of any type */ $1 = 1; } else { /* check the first element only */ T* x; - SCM o = gh_vector_ref($input,gh_ulong2scm(0)); + SCM o = scm_vector_ref($input,scm_from_ulong(0)); if (SWIG_ConvertPtr(o,(void**) &x, $descriptor(T *), 0) != -1) $1 = 1; else $1 = 0; } - } else if (gh_null_p($input)) { + } else if (scm_is_null($input)) { /* again, an empty sequence can be of any type */ $1 = 1; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { /* check the first element only */ T* x; - SCM head = gh_car($input); + SCM head = SCM_CAR($input); if (SWIG_ConvertPtr(head,(void**) &x, $descriptor(T *), 0) != -1) $1 = 1; @@ -230,24 +230,24 @@ namespace std { %define specialize_stl_vector(T,CHECK,CONVERT_FROM,CONVERT_TO) template<> class vector { %typemap(in) vector { - if (gh_vector_p($input)) { - unsigned long size = gh_vector_length($input); + if (scm_is_vector($input)) { + unsigned long size = scm_c_vector_length($input); $1 = std::vector(size); for (unsigned long i=0; i(); - } else if (gh_pair_p($input)) { - SCM v = gh_list_to_vector($input); - unsigned long size = gh_vector_length(v); + } else if (scm_is_pair($input)) { + SCM v = scm_vector($input); + unsigned long size = scm_c_vector_length(v); $1 = std::vector(size); for (unsigned long i=0; i& (std::vector temp), const vector* (std::vector temp) { - if (gh_vector_p($input)) { - unsigned long size = gh_vector_length($input); + if (scm_is_vector($input)) { + unsigned long size = scm_c_vector_length($input); temp = std::vector(size); $1 = &temp; for (unsigned long i=0; i(); $1 = &temp; - } else if (gh_pair_p($input)) { - SCM v = gh_list_to_vector($input); - unsigned long size = gh_vector_length(v); + } else if (scm_is_pair($input)) { + SCM v = scm_vector($input); + unsigned long size = scm_c_vector_length(v); temp = std::vector(size); $1 = &temp; for (unsigned long i=0; i { - $result = gh_make_vector(gh_long2scm($1.size()),SCM_UNSPECIFIED); + $result = scm_make_vector(scm_from_long($1.size()),SCM_UNSPECIFIED); for (unsigned int i=0; i<$1.size(); i++) { SCM x = CONVERT_TO((($1_type &)$1)[i]); - gh_vector_set_x($result,gh_long2scm(i),x); + scm_vector_set_x($result,scm_from_long(i),x); } } %typecheck(SWIG_TYPECHECK_VECTOR) vector { /* native sequence? */ - if (gh_vector_p($input)) { - unsigned int size = gh_vector_length($input); + if (scm_is_vector($input)) { + unsigned int size = scm_c_vector_length($input); if (size == 0) { /* an empty sequence can be of any type */ $1 = 1; } else { /* check the first element only */ T* x; - SCM o = gh_vector_ref($input,gh_ulong2scm(0)); + SCM o = scm_vector_ref($input,scm_from_ulong(0)); $1 = CHECK(o) ? 1 : 0; } - } else if (gh_null_p($input)) { + } else if (scm_is_null($input)) { /* again, an empty sequence can be of any type */ $1 = 1; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { /* check the first element only */ T* x; - SCM head = gh_car($input); + SCM head = SCM_CAR($input); $1 = CHECK(head) ? 1 : 0; } else { /* wrapped vector? */ @@ -328,24 +328,24 @@ namespace std { %typecheck(SWIG_TYPECHECK_VECTOR) const vector&, const vector* { /* native sequence? */ - if (gh_vector_p($input)) { - unsigned int size = gh_vector_length($input); + if (scm_is_vector($input)) { + unsigned int size = scm_c_vector_length($input); if (size == 0) { /* an empty sequence can be of any type */ $1 = 1; } else { /* check the first element only */ T* x; - SCM o = gh_vector_ref($input,gh_ulong2scm(0)); + SCM o = scm_vector_ref($input,scm_from_ulong(0)); $1 = CHECK(o) ? 1 : 0; } - } else if (gh_null_p($input)) { + } else if (scm_is_null($input)) { /* again, an empty sequence can be of any type */ $1 = 1; - } else if (gh_pair_p($input)) { + } else if (scm_is_pair($input)) { /* check the first element only */ T* x; - SCM head = gh_car($input); + SCM head = SCM_CAR($input); $1 = CHECK(head) ? 1 : 0; } else { /* wrapped vector? */ @@ -394,17 +394,17 @@ namespace std { }; %enddef - specialize_stl_vector(bool,gh_boolean_p,gh_scm2bool,SWIG_bool2scm); - specialize_stl_vector(char,gh_number_p,gh_scm2long,gh_long2scm); - specialize_stl_vector(int,gh_number_p,gh_scm2long,gh_long2scm); - specialize_stl_vector(long,gh_number_p,gh_scm2long,gh_long2scm); - specialize_stl_vector(short,gh_number_p,gh_scm2long,gh_long2scm); - specialize_stl_vector(unsigned char,gh_number_p,gh_scm2ulong,gh_ulong2scm); - specialize_stl_vector(unsigned int,gh_number_p,gh_scm2ulong,gh_ulong2scm); - specialize_stl_vector(unsigned long,gh_number_p,gh_scm2ulong,gh_ulong2scm); - specialize_stl_vector(unsigned short,gh_number_p,gh_scm2ulong,gh_ulong2scm); - specialize_stl_vector(float,gh_number_p,gh_scm2double,gh_double2scm); - specialize_stl_vector(double,gh_number_p,gh_scm2double,gh_double2scm); - specialize_stl_vector(std::string,gh_string_p,SWIG_scm2string,SWIG_string2scm); + specialize_stl_vector(bool,scm_is_bool,scm_is_true,SWIG_bool2scm); + specialize_stl_vector(char,scm_is_number,scm_to_long,scm_from_long); + specialize_stl_vector(int,scm_is_number,scm_to_long,scm_from_long); + specialize_stl_vector(long,scm_is_number,scm_to_long,scm_from_long); + specialize_stl_vector(short,scm_is_number,scm_to_long,scm_from_long); + specialize_stl_vector(unsigned char,scm_is_number,scm_to_ulong,scm_from_ulong); + specialize_stl_vector(unsigned int,scm_is_number,scm_to_ulong,scm_from_ulong); + specialize_stl_vector(unsigned long,scm_is_number,scm_to_ulong,scm_from_ulong); + specialize_stl_vector(unsigned short,scm_is_number,scm_to_ulong,scm_from_ulong); + specialize_stl_vector(float,scm_is_number,scm_to_double,scm_from_double); + specialize_stl_vector(double,scm_is_number,scm_to_double,scm_from_double); + specialize_stl_vector(std::string,scm_is_string,SWIG_scm2string,SWIG_string2scm); } diff --git a/Lib/guile/typemaps.i b/Lib/guile/typemaps.i index 5036162fd..ab655eb9a 100644 --- a/Lib/guile/typemaps.i +++ b/Lib/guile/typemaps.i @@ -60,26 +60,26 @@ %typemap(throws) SWIGTYPE { $<ype temp = new $ltype($1); - scm_throw(gh_symbol2scm((char *) "swig-exception"), - gh_list(SWIG_NewPointerObj(temp, $&descriptor, 1), + scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_listify(SWIG_NewPointerObj(temp, $&descriptor, 1), SCM_UNDEFINED)); } %typemap(throws) SWIGTYPE & { - scm_throw(gh_symbol2scm((char *) "swig-exception"), - gh_list(SWIG_NewPointerObj(&$1, $descriptor, 1), + scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_listify(SWIG_NewPointerObj(&$1, $descriptor, 1), SCM_UNDEFINED)); } %typemap(throws) SWIGTYPE * { - scm_throw(gh_symbol2scm((char *) "swig-exception"), - gh_list(SWIG_NewPointerObj($1, $descriptor, 1), + scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_listify(SWIG_NewPointerObj($1, $descriptor, 1), SCM_UNDEFINED)); } %typemap(throws) SWIGTYPE [] { - scm_throw(gh_symbol2scm((char *) "swig-exception"), - gh_list(SWIG_NewPointerObj($1, $descriptor, 1), + scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_listify(SWIG_NewPointerObj($1, $descriptor, 1), SCM_UNDEFINED)); } @@ -146,7 +146,7 @@ /* Enums */ -%typemap(in) enum SWIGTYPE { $1 = ($1_type) gh_scm2int($input); } +%typemap(in) enum SWIGTYPE { $1 = ($1_type) scm_to_int($input); } /* The complicated construction below needed to deal with anonymous enums, which cannot be cast to. */ %typemap(varin) enum SWIGTYPE { @@ -156,13 +156,13 @@ (char *) "enum variable '$name' cannot be set", SCM_EOL, SCM_BOOL_F); } - * (int *) &($1) = gh_scm2int($input); + * (int *) &($1) = scm_to_int($input); } -%typemap(out) enum SWIGTYPE { $result = gh_int2scm($1); } -%typemap(varout) enum SWIGTYPE { $result = gh_int2scm($1); } +%typemap(out) enum SWIGTYPE { $result = scm_from_long($1); } +%typemap(varout) enum SWIGTYPE { $result = scm_from_long($1); } %typemap(throws) enum SWIGTYPE { - scm_throw(gh_symbol2scm((char *) "swig-exception"), - gh_list(gh_int2scm($1), SCM_UNDEFINED)); + scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_listify(scm_from_long($1), SCM_UNDEFINED)); } /* The SIMPLE_MAP_WITH_EXPR macro below defines the whole set of @@ -210,8 +210,8 @@ /* Throw typemap */ %typemap(throws) C_NAME { C_NAME swig_c_value = $1; - scm_throw(gh_symbol2scm((char *) "swig-exception"), - gh_list(C_TO_SCM_EXPR, SCM_UNDEFINED)); + scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_listify(C_TO_SCM_EXPR, SCM_UNDEFINED)); } %enddef @@ -254,34 +254,34 @@ } /* Throw typemap */ %typemap(throws) C_NAME { - scm_throw(gh_symbol2scm((char *) "swig-exception"), - gh_list(C_TO_SCM($1), SCM_UNDEFINED)); + scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_listify(C_TO_SCM($1), SCM_UNDEFINED)); } %enddef - SIMPLE_MAP(bool, gh_scm2bool, gh_bool2scm, boolean); - SIMPLE_MAP(char, gh_scm2char, gh_char2scm, char); - SIMPLE_MAP(unsigned char, gh_scm2char, gh_char2scm, char); - SIMPLE_MAP(signed char, gh_scm2char, gh_char2scm, char); - SIMPLE_MAP(int, gh_scm2int, gh_int2scm, integer); - SIMPLE_MAP(short, gh_scm2short, gh_int2scm, integer); - SIMPLE_MAP(long, gh_scm2long, gh_long2scm, integer); - SIMPLE_MAP(ptrdiff_t, gh_scm2long, gh_long2scm, integer); - SIMPLE_MAP(unsigned int, gh_scm2uint, gh_ulong2scm, integer); - SIMPLE_MAP(unsigned short, gh_scm2ushort, gh_ulong2scm, integer); - SIMPLE_MAP(unsigned long, gh_scm2ulong, gh_ulong2scm, integer); - SIMPLE_MAP(size_t, gh_scm2ulong, gh_ulong2scm, integer); - SIMPLE_MAP(float, gh_scm2double, gh_double2scm, real); - SIMPLE_MAP(double, gh_scm2double, gh_double2scm, real); -// SIMPLE_MAP(char *, SWIG_scm2str, gh_str02scm, string); -// SIMPLE_MAP(const char *, SWIG_scm2str, gh_str02scm, string); + SIMPLE_MAP(bool, scm_is_true, scm_from_bool, boolean); + SIMPLE_MAP(char, SCM_CHAR, SCM_MAKE_CHAR, char); + SIMPLE_MAP(unsigned char, SCM_CHAR, SCM_MAKE_CHAR, char); + SIMPLE_MAP(signed char, SCM_CHAR, SCM_MAKE_CHAR, char); + SIMPLE_MAP(int, scm_to_int, scm_from_long, integer); + SIMPLE_MAP(short, scm_to_short, scm_from_long, integer); + SIMPLE_MAP(long, scm_to_long, scm_from_long, integer); + SIMPLE_MAP(ptrdiff_t, scm_to_long, scm_from_long, integer); + SIMPLE_MAP(unsigned int, scm_to_uint, scm_from_ulong, integer); + SIMPLE_MAP(unsigned short, scm_to_ushort, scm_from_ulong, integer); + SIMPLE_MAP(unsigned long, scm_to_ulong, scm_from_ulong, integer); + SIMPLE_MAP(size_t, scm_to_ulong, scm_from_ulong, integer); + SIMPLE_MAP(float, scm_to_double, scm_from_double, real); + SIMPLE_MAP(double, scm_to_double, scm_from_double, real); +// SIMPLE_MAP(char *, SWIG_scm2str, SWIG_str02scm, string); +// SIMPLE_MAP(const char *, SWIG_scm2str, SWIG_str02scm, string); /* Define long long typemaps -- uses functions that are only defined in recent versions of Guile, availability also depends on Guile's configuration. */ -SIMPLE_MAP(long long, gh_scm2long_long, gh_long_long2scm, integer); -SIMPLE_MAP(unsigned long long, gh_scm2ulong_long, gh_ulong_long2scm, integer); +SIMPLE_MAP(long long, scm_to_long_long, scm_from_long_long, integer); +SIMPLE_MAP(unsigned long long, scm_to_ulong_long, scm_from_ulong_long, integer); /* Strings */ @@ -290,8 +290,8 @@ SIMPLE_MAP(unsigned long long, gh_scm2ulong_long, gh_ulong_long2scm, integer); must_free = 1; } %typemap (varin, doc="NEW-VALUE is a string") char * {$1 = ($1_ltype)SWIG_scm2str($input);} - %typemap (out, doc="") char * {$result = gh_str02scm((const char *)$1);} - %typemap (varout, doc="") char * {$result = gh_str02scm($1);} + %typemap (out, doc="") char * {$result = SWIG_str02scm((const char *)$1);} + %typemap (varout, doc="") char * {$result = SWIG_str02scm($1);} %typemap (in, doc="$NAME is a string") char **INPUT(char * temp, int must_free = 0) { temp = (char *) SWIG_scm2str($input); $1 = &temp; must_free = 1; @@ -299,7 +299,7 @@ SIMPLE_MAP(unsigned long long, gh_scm2ulong_long, gh_ulong_long2scm, integer); %typemap (in,numinputs=0) char **OUTPUT (char * temp) {$1 = &temp;} %typemap (argout,doc="$NAME (a string)") char **OUTPUT - {SWIG_APPEND_VALUE(gh_str02scm(*$1));} + {SWIG_APPEND_VALUE(SWIG_str02scm(*$1));} %typemap (in) char **BOTH = char **INPUT; %typemap (argout) char **BOTH = char **OUTPUT; %typemap (in) char **INOUT = char **INPUT; @@ -329,8 +329,8 @@ SIMPLE_MAP(unsigned long long, gh_scm2ulong_long, gh_ulong_long2scm, integer); } %typemap(throws) char * { - scm_throw(gh_symbol2scm((char *) "swig-exception"), - gh_list(gh_str02scm($1), SCM_UNDEFINED)); + scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_listify(SWIG_str02scm($1), SCM_UNDEFINED)); } /* Void */ @@ -350,7 +350,7 @@ typedef unsigned long SCM; %typemap(in) (char *STRING, int LENGTH), (char *STRING, size_t LENGTH) { size_t temp; - $1 = ($1_ltype) gh_scm2newstr($input, &temp); + $1 = ($1_ltype) SWIG_Guile_scm2newstr($input, &temp); $2 = ($2_ltype) temp; } diff --git a/Lib/mzscheme/typemaps.i b/Lib/mzscheme/typemaps.i index f12513df8..4078026ac 100644 --- a/Lib/mzscheme/typemaps.i +++ b/Lib/mzscheme/typemaps.i @@ -279,7 +279,7 @@ REF_MAP(double, SCHEME_REALP, scheme_real_to_double, //%typemap(in) (char *STRING, int LENGTH) { // int temp; -// $1 = ($1_ltype) gh_scm2newstr($input, &temp); +// $1 = ($1_ltype) SWIG_Guile_scm2newstr($input, &temp); // $2 = ($2_ltype) temp; //} diff --git a/Makefile.in b/Makefile.in index c33889587..cfa6d0933 100644 --- a/Makefile.in +++ b/Makefile.in @@ -59,7 +59,6 @@ skip-tcl = test -n "@SKIP_TCL@" skip-perl5 = test -n "@SKIP_PERL5@" skip-python = test -n "@SKIP_PYTHON@" skip-java = test -n "@SKIP_JAVA@" -skip-guilegh = test -n "@SKIP_GUILEGH@" skip-guile = test -n "@SKIP_GUILE@" skip-mzscheme = test -n "@SKIP_MZSCHEME@" skip-ruby = test -n "@SKIP_RUBY@" @@ -247,7 +246,6 @@ check-test-suite: \ check-perl5-test-suite \ check-python-test-suite \ check-java-test-suite \ - check-guilegh-test-suite \ check-guile-test-suite \ check-mzscheme-test-suite \ check-ruby-test-suite \ @@ -300,7 +298,6 @@ all-test-suite: \ all-perl5-test-suite \ all-python-test-suite \ all-java-test-suite \ - all-guilegh-test-suite \ all-guile-test-suite \ all-mzscheme-test-suite \ all-ruby-test-suite \ @@ -329,7 +326,6 @@ broken-test-suite: \ broken-perl5-test-suite \ broken-python-test-suite \ broken-java-test-suite \ - broken-guilegh-test-suite \ broken-guile-test-suite \ broken-mzscheme-test-suite \ broken-ruby-test-suite \ diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index 211b11baf..afe039ac7 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -23,7 +23,6 @@ Guile Options (available with -guile)\n\ -emitslotaccessors - Emit accessor methods for all GOOPS slots\n" "\ -exportprimitive - Add the (export ...) code from scmstub into the\n\ GOOPS file.\n\ - -gh - Use the gh_ Guile API. (Guile <= 1.8) \n\ -goopsprefix - Prepend to all goops identifiers\n\ -linkage - Use linkage protocol (default `simple')\n\ Use `module' for native Guile module linking\n\ @@ -44,10 +43,14 @@ Guile Options (available with -guile)\n\ -proxy - Export GOOPS class definitions\n\ -primsuffix - Name appended to primitive module when exporting\n\ GOOPS classes. (default = \"primitive\")\n\ - -scm - Use the scm Guile API. (Guile >= 1.6, default) \n\ -scmstub - Output Scheme file with module declaration and\n\ exports; only with `passive' and `simple' linkage\n\ -useclassprefix - Prepend the class name to all goops identifiers\n\ +\n\ +Obsolete parameters:\n\ +These parameters do nothing, but are kept for compatibility with old scripts only.\n\ + -gh - Was used to select the gh_ Guile API. \n\ + -scm - scm Guile API is always used now. \n\ \n"; static File *f_begin = 0; @@ -94,7 +97,6 @@ static String *return_multi_doc = 0; static String *exported_symbols = 0; -static int use_scm_interface = 1; static int exporting_destructor = 0; static String *swigtype_ptr = 0; @@ -216,10 +218,8 @@ public: goops = true; Swig_mark_arg(i); } else if (strcmp(argv[i], "-gh") == 0) { - use_scm_interface = 0; Swig_mark_arg(i); } else if (strcmp(argv[i], "-scm") == 0) { - use_scm_interface = 1; Swig_mark_arg(i); } else if (strcmp(argv[i], "-primsuffix") == 0) { if (argv[i + 1]) { @@ -285,10 +285,7 @@ public: /* Add a symbol for this module */ Preprocessor_define("SWIGGUILE 1", 0); /* Read in default typemaps */ - if (use_scm_interface) - SWIG_config_file("guile_scm.swg"); - else - SWIG_config_file("guile_gh.swg"); + SWIG_config_file("guile_scm.swg"); allow_overloading(); } @@ -331,13 +328,6 @@ public: Printf(f_runtime, "\n"); Printf(f_runtime, "#define SWIGGUILE\n"); - if (!use_scm_interface) { - if (SwigRuntime == 1) - Printf(f_runtime, "#define SWIG_GLOBAL\n"); - if (SwigRuntime == 2) - Printf(f_runtime, "#define SWIG_NOINCLUDE\n"); - } - /* Write out directives and declarations */ module = Swig_copy_string(Char(Getattr(n, "name"))); @@ -851,7 +841,7 @@ public: } } - if (use_scm_interface && exporting_destructor) { + if (exporting_destructor) { /* Mark the destructor's argument as destroyed. */ String *tm = NewString("SWIG_Guile_MarkPointerDestroyed($input);"); Replaceall(tm, "$input", Getattr(l, "emit:input")); @@ -868,14 +858,8 @@ public: Printv(f->def, "#define FUNC_NAME \"", proc_name, "\"", NIL); // Now write code to make the function call - if (!use_scm_interface) - Printv(f->code, tab4, "gh_defer_ints();\n", NIL); - String *actioncode = emit_action(n); - if (!use_scm_interface) - Printv(actioncode, tab4, "gh_allow_ints();\n", NIL); - // Now have return value, figure out what to do with it. if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) { Replaceall(tm, "$result", "gswig_result"); @@ -958,11 +942,7 @@ public: Printv(f_wrappers, ");\n", NIL); Printv(f_wrappers, "}\n", NIL); /* Register it */ - if (use_scm_interface) { - Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, 0, 1, (swig_guile_proc) %s_rest);\n", proc_name, wname); - } else { - Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s_rest, 0, 0, 1);\n", proc_name, wname); - } + Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, 0, 1, (swig_guile_proc) %s_rest);\n", proc_name, wname); } else if (emit_setters && struct_member && strlen(Char(proc_name)) > 3) { int len = Len(proc_name); const char *pc = Char(proc_name); @@ -973,19 +953,13 @@ public: struct_member = 2; /* have a setter */ } else Printf(f_init, "SCM getter = "); - if (use_scm_interface) { - /* GOOPS support uses the MEMBER-set and MEMBER-get functions, - so ignore only_setters in this case. */ - if (only_setters && !goops) - Printf(f_init, "scm_c_make_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname); - else - Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname); - } else { - if (only_setters && !goops) - Printf(f_init, "scm_make_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname); - else - Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s, %d, %d, 0);\n", proc_name, wname, numreq, numargs - numreq); - } + /* GOOPS support uses the MEMBER-set and MEMBER-get functions, + so ignore only_setters in this case. */ + if (only_setters && !goops) + Printf(f_init, "scm_c_make_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname); + else + Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname); + if (!is_setter) { /* Strip off "-get" */ char *pws_name = (char *) malloc(sizeof(char) * (len - 3)); @@ -993,19 +967,11 @@ public: pws_name[len - 4] = 0; if (struct_member == 2) { /* There was a setter, so create a procedure with setter */ - if (use_scm_interface) { - Printf(f_init, "scm_c_define"); - } else { - Printf(f_init, "gh_define"); - } + Printf(f_init, "scm_c_define"); Printf(f_init, "(\"%s\", " "scm_make_procedure_with_setter(getter, setter));\n", pws_name); } else { /* There was no setter, so make an alias to the getter */ - if (use_scm_interface) { - Printf(f_init, "scm_c_define"); - } else { - Printf(f_init, "gh_define"); - } + Printf(f_init, "scm_c_define"); Printf(f_init, "(\"%s\", getter);\n", pws_name); } Printf(exported_symbols, "\"%s\", ", pws_name); @@ -1013,15 +979,11 @@ public: } } else { /* Register the function */ - if (use_scm_interface) { - if (exporting_destructor) { - Printf(f_init, "((swig_guile_clientdata *)(SWIGTYPE%s->clientdata))->destroy = (guile_destructor) %s;\n", swigtype_ptr, wname); - //Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) %s);\n", swigtype_ptr, wname); - } - Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname); - } else { - Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s, %d, %d, 0);\n", proc_name, wname, numreq, numargs - numreq); + if (exporting_destructor) { + Printf(f_init, "((swig_guile_clientdata *)(SWIGTYPE%s->clientdata))->destroy = (guile_destructor) %s;\n", swigtype_ptr, wname); + //Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) %s);\n", swigtype_ptr, wname); } + Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname); } } else { /* overloaded function; don't export the single methods */ if (!Getattr(n, "sym:nextSibling")) { @@ -1044,11 +1006,7 @@ public: Printf(df->code, "#undef FUNC_NAME\n"); Printv(df->code, "}\n", NIL); Wrapper_print(df, f_wrappers); - if (use_scm_interface) { - Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, 0, 1, (swig_guile_proc) %s);\n", proc_name, dname); - } else { - Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, 0, 1);\n", proc_name, dname); - } + Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, 0, 1, (swig_guile_proc) %s);\n", proc_name, dname); DelWrapper(df); Delete(dispatch); Delete(dname); @@ -1221,36 +1179,27 @@ public: /* Read-only variables become a simple procedure returning the value; read-write variables become a simple procedure with an optional argument. */ - if (use_scm_interface) { - if (!goops && GetFlag(n, "feature:constasvar")) { - /* need to export this function as a variable instead of a procedure */ - if (scmstub) { - /* export the function in the wrapper, and (set!) it in scmstub */ - Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n", proc_name, !GetFlag(n, "feature:immutable"), var_name); - Printf(scmtext, "(set! %s (%s))\n", proc_name, proc_name); - } else { - /* export the variable directly */ - Printf(f_init, "scm_c_define(\"%s\", %s(SCM_UNDEFINED));\n", proc_name, var_name); - } - - } else { - /* Export the function as normal */ + if (!goops && GetFlag(n, "feature:constasvar")) { + /* need to export this function as a variable instead of a procedure */ + if (scmstub) { + /* export the function in the wrapper, and (set!) it in scmstub */ Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n", proc_name, !GetFlag(n, "feature:immutable"), var_name); + Printf(scmtext, "(set! %s (%s))\n", proc_name, proc_name); + } else { + /* export the variable directly */ + Printf(f_init, "scm_c_define(\"%s\", %s(SCM_UNDEFINED));\n", proc_name, var_name); } } else { - Printf(f_init, "\t gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, %d, 0);\n", proc_name, var_name, !GetFlag(n, "feature:immutable")); + /* Export the function as normal */ + Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n", proc_name, !GetFlag(n, "feature:immutable"), var_name); } + } else { /* Read/write variables become a procedure with setter. */ - if (use_scm_interface) { - Printf(f_init, "{ SCM p = scm_c_define_gsubr(\"%s\", 0, 1, 0, (swig_guile_proc) %s);\n", proc_name, var_name); - Printf(f_init, "scm_c_define"); - } else { - Printf(f_init, "\t{ SCM p = gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, 1, 0);\n", proc_name, var_name); - Printf(f_init, "gh_define"); - } + Printf(f_init, "{ SCM p = scm_c_define_gsubr(\"%s\", 0, 1, 0, (swig_guile_proc) %s);\n", proc_name, var_name); + Printf(f_init, "scm_c_define"); Printf(f_init, "(\"%s\", " "scm_make_procedure_with_setter(p, p)); }\n", proc_name); } Printf(exported_symbols, "\"%s\", ", proc_name); @@ -1484,12 +1433,10 @@ public: String *mangled_classname = Swig_name_mangle(Getattr(n, "sym:name")); /* Export clientdata structure */ - if (use_scm_interface) { - Printf(f_runtime, "static swig_guile_clientdata _swig_guile_clientdata%s = { NULL, SCM_EOL };\n", mangled_classname); + Printf(f_runtime, "static swig_guile_clientdata _swig_guile_clientdata%s = { NULL, SCM_EOL };\n", mangled_classname); - Printv(f_init, "SWIG_TypeClientData(SWIGTYPE", swigtype_ptr, ", (void *) &_swig_guile_clientdata", mangled_classname, ");\n", NIL); - SwigType_remember(ct); - } + Printv(f_init, "SWIG_TypeClientData(SWIGTYPE", swigtype_ptr, ", (void *) &_swig_guile_clientdata", mangled_classname, ");\n", NIL); + SwigType_remember(ct); Delete(ct); /* Emit all of the members */ @@ -1725,28 +1672,16 @@ public: String *runtimeCode() { String *s; - if (use_scm_interface) { - s = Swig_include_sys("guile_scm_run.swg"); - if (!s) { - Printf(stderr, "*** Unable to open 'guile_scm_run.swg"); - s = NewString(""); - } - } else { - s = Swig_include_sys("guile_gh_run.swg"); - if (!s) { - Printf(stderr, "*** Unable to open 'guile_gh_run.swg"); - s = NewString(""); - } + s = Swig_include_sys("guile_scm_run.swg"); + if (!s) { + Printf(stderr, "*** Unable to open 'guile_scm_run.swg"); + s = NewString(""); } return s; } String *defaultExternalRuntimeFilename() { - if (use_scm_interface) { - return NewString("swigguilerun.h"); - } else { - return NewString("swigguileghrun.h"); - } + return NewString("swigguilerun.h"); } }; diff --git a/configure.ac b/configure.ac index 28696529d..1a699167f 100644 --- a/configure.ac +++ b/configure.ac @@ -1239,15 +1239,7 @@ else CFLAGS="`echo $CFLAGS | sed 's/-ansi//g;s/-pedantic//g;'` $GUILE_CFLAGS" LIBS="$LIBS $GUILE_LIBS" - AC_MSG_CHECKING(whether Guile's gh_ API works) - AC_LINK_IFELSE([AC_LANG_SOURCE([#include - int main() { SCM s; return gh_scm2int(s); }])], GUILE_GH_INTERFACE=1, ) - if test -n "$GUILE_GH_INTERFACE" ; then - AC_MSG_RESULT(yes) - else - AC_MSG_RESULT(no) - fi - AC_MSG_CHECKING(whether Guile's SCM_ API works) + AC_MSG_CHECKING(whether Guile/SCM_ API works) AC_LINK_IFELSE([AC_LANG_SOURCE([#include int main() { SCM s; scm_slot_exists_p(SCM_BOOL_F, SCM_BOOL_F); return SCM_STRING_LENGTH(s); }])], GUILE_SCM_INTERFACE=1, ) if test -n "$GUILE_SCM_INTERFACE" ; then @@ -1265,7 +1257,6 @@ fi AC_SUBST(GUILE) AC_SUBST(GUILE_CFLAGS) AC_SUBST(GUILE_LIBS) -AC_SUBST(GUILE_GH_INTERFACE) AC_SUBST(GUILE_SCM_INTERFACE) #---------------------------------------------------------------- @@ -2271,12 +2262,6 @@ if test -z "$GUILE_CFLAGS" || test -z "$GUILE_LIBS" || test -z "$GUILE_SCM_INTER fi AC_SUBST(SKIP_GUILE) -SKIP_GUILEGH= -if test -z "$GUILE_CFLAGS" || test -z "$GUILE_LIBS" || test -z "$GUILE_GH_INTERFACE"; then - SKIP_GUILEGH="1" -fi -AC_SUBST(SKIP_GUILEGH) - SKIP_MZSCHEME= if test -z "$MZC" || test -z "$MZDYNOBJ" ; then @@ -2452,7 +2437,6 @@ AC_CONFIG_FILES([ \ Examples/test-suite/csharp/Makefile \ Examples/test-suite/d/Makefile \ Examples/test-suite/guile/Makefile \ - Examples/test-suite/guilegh/Makefile \ Examples/test-suite/java/Makefile \ Examples/test-suite/mzscheme/Makefile \ Examples/test-suite/ocaml/Makefile \ From d689d9a860c4565db2e87ffd28e9fbe5bc7e848f Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Fri, 19 Apr 2013 18:57:31 +0200 Subject: [PATCH 0571/1160] Fix deprecation warnings for test suite under guile 2.0 --- Examples/guile/multimap/example.i | 2 +- Lib/cdata.i | 2 +- Lib/exception.i | 2 +- Lib/guile/typemaps.i | 18 +++++++++--------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Examples/guile/multimap/example.i b/Examples/guile/multimap/example.i index f1d7974e4..21d7e5032 100644 --- a/Examples/guile/multimap/example.i +++ b/Examples/guile/multimap/example.i @@ -66,7 +66,7 @@ extern int count(char *bytes, int len, char c); /* Return the mutated string as a new object. */ %typemap(argout) (char *str, int len) { - SWIG_APPEND_VALUE(scm_mem2string($1,$2)); + SWIG_APPEND_VALUE(scm_from_locale_stringn($1,$2)); if ($1) scm_must_free($1); } diff --git a/Lib/cdata.i b/Lib/cdata.i index dbc1c42d2..22a6d9de8 100644 --- a/Lib/cdata.i +++ b/Lib/cdata.i @@ -17,7 +17,7 @@ typedef struct SWIGCDATA { #if SWIGGUILE %typemap(out) SWIGCDATA { - $result = scm_mem2string($1.data,$1.len); + $result = scm_from_locale_stringn($1.data,$1.len); } %typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH); #elif SWIGCHICKEN diff --git a/Lib/exception.i b/Lib/exception.i index 867ecdbff..050042dab 100644 --- a/Lib/exception.i +++ b/Lib/exception.i @@ -24,7 +24,7 @@ SWIGINTERN void SWIG_exception_ (int code, const char *msg, const char *subr) { #define ERROR(scmerr) \ - scm_error(scm_str2symbol((char *) (scmerr)), \ + scm_error(scm_from_locale_string((char *) (scmerr)), \ (char *) subr, (char *) msg, \ SCM_EOL, SCM_BOOL_F) #define MAP(swigerr, scmerr) \ diff --git a/Lib/guile/typemaps.i b/Lib/guile/typemaps.i index ab655eb9a..ba447ac28 100644 --- a/Lib/guile/typemaps.i +++ b/Lib/guile/typemaps.i @@ -60,25 +60,25 @@ %typemap(throws) SWIGTYPE { $<ype temp = new $ltype($1); - scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol((char *) "swig-exception"), scm_listify(SWIG_NewPointerObj(temp, $&descriptor, 1), SCM_UNDEFINED)); } %typemap(throws) SWIGTYPE & { - scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol((char *) "swig-exception"), scm_listify(SWIG_NewPointerObj(&$1, $descriptor, 1), SCM_UNDEFINED)); } %typemap(throws) SWIGTYPE * { - scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol((char *) "swig-exception"), scm_listify(SWIG_NewPointerObj($1, $descriptor, 1), SCM_UNDEFINED)); } %typemap(throws) SWIGTYPE [] { - scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol((char *) "swig-exception"), scm_listify(SWIG_NewPointerObj($1, $descriptor, 1), SCM_UNDEFINED)); } @@ -151,7 +151,7 @@ enums, which cannot be cast to. */ %typemap(varin) enum SWIGTYPE { if (sizeof(int) != sizeof($1)) { - scm_error(scm_str2symbol("swig-error"), + scm_error(scm_from_locale_symbol("swig-error"), (char *) FUNC_NAME, (char *) "enum variable '$name' cannot be set", SCM_EOL, SCM_BOOL_F); @@ -161,7 +161,7 @@ %typemap(out) enum SWIGTYPE { $result = scm_from_long($1); } %typemap(varout) enum SWIGTYPE { $result = scm_from_long($1); } %typemap(throws) enum SWIGTYPE { - scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol((char *) "swig-exception"), scm_listify(scm_from_long($1), SCM_UNDEFINED)); } @@ -210,7 +210,7 @@ /* Throw typemap */ %typemap(throws) C_NAME { C_NAME swig_c_value = $1; - scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol((char *) "swig-exception"), scm_listify(C_TO_SCM_EXPR, SCM_UNDEFINED)); } %enddef @@ -254,7 +254,7 @@ } /* Throw typemap */ %typemap(throws) C_NAME { - scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol((char *) "swig-exception"), scm_listify(C_TO_SCM($1), SCM_UNDEFINED)); } %enddef @@ -329,7 +329,7 @@ SIMPLE_MAP(unsigned long long, scm_to_ulong_long, scm_from_ulong_long, integer); } %typemap(throws) char * { - scm_throw(scm_str2symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol((char *) "swig-exception"), scm_listify(SWIG_str02scm($1), SCM_UNDEFINED)); } From 140829a826885814dfab713406b1f8b7413df0b0 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Sat, 20 Apr 2013 10:37:07 +0200 Subject: [PATCH 0572/1160] guile: fix std_map.i "$1 not found" error --- Lib/guile/std_map.i | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Lib/guile/std_map.i b/Lib/guile/std_map.i index dfce6fc5c..1e1014f54 100644 --- a/Lib/guile/std_map.i +++ b/Lib/guile/std_map.i @@ -109,8 +109,8 @@ namespace std { } %typemap(out) map { SCM alist = SCM_EOL; - for (std::map::reverse_iterator i=$1.rbegin(); - i!=$1.rend(); ++i) { + for (std::map::reverse_iterator i=$i.rbegin(); + i!=$i.rend(); ++i) { K* key = new K(i->first); T* val = new T(i->second); SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1); @@ -251,8 +251,8 @@ namespace std { } SCM keys() { SCM result = SCM_EOL; - 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); SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1); result = scm_cons(k,result); @@ -471,8 +471,8 @@ namespace std { } SCM keys() { SCM result = SCM_EOL; - for (std::map::reverse_iterator i=$1.rbegin(); - i!=$1.rend(); ++i) { + for (std::map::reverse_iterator i=self->rbegin(); + i!=self->rend(); ++i) { SCM k = CONVERT_TO(i->first); result = scm_cons(k,result); } @@ -683,8 +683,8 @@ namespace std { } SCM keys() { SCM result = SCM_EOL; - 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); SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1); result = scm_cons(k,result); @@ -895,8 +895,8 @@ namespace std { } SCM keys() { SCM result = SCM_EOL; - for (std::map::reverse_iterator i=$1.rbegin(); - i!=$1.rend(); ++i) { + for (std::map::reverse_iterator i=self->rbegin(); + i!=self->rend(); ++i) { SCM k = CONVERT_K_TO(i->first); result = scm_cons(k,result); } From 6a60efffd1477e92f1e2ed5f5afa82843d278965 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 23 Apr 2013 19:11:29 +0100 Subject: [PATCH 0573/1160] Some C++ experience needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 19/04/13 18:41, Geert Janssens wrote: > Hi, > > I'm working through the failing testcases for guile. One testcase fails > with a compilation error in some generated code based on std_map and > std_pair. I know exactly where this generated code comes from, but my > C++ knowledge is insufficient to understand the error, let alone remedy > it. I gather some kind of const violation, but that's all I can read > from it :( My hope is that someone used to working with stl will more > easily understand it. > > So, if someone can help me understand the error and what the fix would > be in C++, I can fix the corresponding .i file. > > This is the code snippet the causes the error: > > > /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/stl_pair.h:88:12: > error: non-static const member ‘const std::pair std::pair const std::pair >::second’, can’t use default assignment operator This is the main problem - it is saying there is no default assignment operator (because one of the members in pair is const). The solution is to avoid assignment. I've attached a patch to do this plus some error message corrections. William --- Lib/guile/std_pair.i | 81 +++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/Lib/guile/std_pair.i b/Lib/guile/std_pair.i index 86ca6e00f..238c5188b 100644 --- a/Lib/guile/std_pair.i +++ b/Lib/guile/std_pair.i @@ -22,7 +22,7 @@ namespace std { template struct pair { - %typemap(in) pair (std::pair* m) { + %typemap(in) pair %{ if (scm_is_pair($input)) { T* x; U* y; @@ -36,11 +36,9 @@ namespace std { $1 = *(($&1_type) SWIG_MustGetPtr($input,$&1_descriptor,$argnum, 0)); } - } - %typemap(in) const pair& (std::pair temp, - std::pair* m), - const pair* (std::pair temp, - std::pair* m) { + %} + %typemap(in) const pair& (std::pair *temp = 0), + const pair* (std::pair *temp = 0) %{ if (scm_is_pair($input)) { T* x; U* y; @@ -49,13 +47,14 @@ namespace std { second = SCM_CDR($input); x = (T*) SWIG_MustGetPtr(first,$descriptor(T *),$argnum, 0); y = (U*) SWIG_MustGetPtr(second,$descriptor(U *),$argnum, 0); - temp = std::make_pair(*x,*y); - $1 = &temp; + temp = new std::pair< T, U >(*x,*y); + $1 = temp; } else { $1 = ($1_ltype) SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0); } - } + %} + %typemap(argout) const pair&, const pair* %{ delete temp$argnum; %} %typemap(out) pair { T* x = new T($1.first); U* y = new U($1.second); @@ -129,7 +128,7 @@ namespace std { %define specialize_std_pair_on_first(T,CHECK,CONVERT_FROM,CONVERT_TO) template struct pair { - %typemap(in) pair (std::pair* m) { + %typemap(in) pair %{ if (scm_is_pair($input)) { U* y; SCM first, second; @@ -137,18 +136,16 @@ namespace std { second = SCM_CDR($input); if (!CHECK(first)) SWIG_exception(SWIG_TypeError, - "map<" #T "," #U "> expected"); + "pair<" #T "," #U "> expected"); y = (U*) SWIG_MustGetPtr(second,$descriptor(U *),$argnum, 0); $1 = std::make_pair(CONVERT_FROM(first),*y); } else { $1 = *(($&1_type) SWIG_MustGetPtr($input,$&1_descriptor,$argnum, 0)); } - } - %typemap(in) const pair& (std::pair temp, - std::pair* m), - const pair* (std::pair temp, - std::pair* m) { + %} + %typemap(in) const pair& (std::pair *temp = 0), + const pair* (std::pair *temp = 0) %{ if (scm_is_pair($input)) { U* y; SCM first, second; @@ -156,15 +153,16 @@ namespace std { second = SCM_CDR($input); if (!CHECK(first)) SWIG_exception(SWIG_TypeError, - "map<" #T "," #U "> expected"); + "pair<" #T "," #U "> expected"); y = (U*) SWIG_MustGetPtr(second,$descriptor(U *),$argnum, 0); - temp = std::make_pair(CONVERT_FROM(first),*y); - $1 = &temp; + temp = new std::pair< T, U >(CONVERT_FROM(first),*y); + $1 = temp; } else { $1 = ($1_ltype) SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0); } - } + %} + %typemap(argout) const pair&, const pair* %{ delete temp$argnum; %} %typemap(out) pair { U* y = new U($1.second); SCM second = SWIG_NewPointerObj(y,$descriptor(U *), 1); @@ -230,7 +228,7 @@ namespace std { %define specialize_std_pair_on_second(U,CHECK,CONVERT_FROM,CONVERT_TO) template struct pair { - %typemap(in) pair (std::pair* m) { + %typemap(in) pair %{ if (scm_is_pair($input)) { T* x; SCM first, second; @@ -239,17 +237,15 @@ namespace std { x = (T*) SWIG_MustGetPtr(first,$descriptor(T *),$argnum, 0); if (!CHECK(second)) SWIG_exception(SWIG_TypeError, - "map<" #T "," #U "> expected"); + "pair<" #T "," #U "> expected"); $1 = std::make_pair(*x,CONVERT_FROM(second)); } else { $1 = *(($&1_type) SWIG_MustGetPtr($input,$&1_descriptor,$argnum, 0)); } - } - %typemap(in) const pair& (std::pair temp, - std::pair* m), - const pair* (std::pair temp, - std::pair* m) { + %} + %typemap(in) const pair& (std::pair *temp = 0), + const pair* (std::pair *temp = 0) %{ if (scm_is_pair($input)) { T* x; SCM first, second; @@ -258,14 +254,15 @@ namespace std { x = (T*) SWIG_MustGetPtr(first,$descriptor(T *),$argnum, 0); if (!CHECK(second)) SWIG_exception(SWIG_TypeError, - "map<" #T "," #U "> expected"); - temp = std::make_pair(*x,CONVERT_FROM(second)); - $1 = &temp; + "pair<" #T "," #U "> expected"); + temp = new std::pair< T, U >(*x,CONVERT_FROM(second)); + $1 = temp; } else { $1 = ($1_ltype) SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0); } - } + %} + %typemap(argout) const pair&, const pair* %{ delete temp$argnum; %} %typemap(out) pair { T* x = new T($1.first); SCM first = SWIG_NewPointerObj(x,$descriptor(T *), 1); @@ -332,40 +329,38 @@ namespace std { %define specialize_std_pair_on_both(T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO, U,CHECK_U,CONVERT_U_FROM,CONVERT_U_TO) template<> struct pair { - %typemap(in) pair (std::pair* m) { + %typemap(in) pair %{ if (scm_is_pair($input)) { SCM first, second; first = SCM_CAR($input); second = SCM_CDR($input); if (!CHECK_T(first) || !CHECK_U(second)) SWIG_exception(SWIG_TypeError, - "map<" #T "," #U "> expected"); + "pair<" #T "," #U "> expected"); $1 = std::make_pair(CONVERT_T_FROM(first), CONVERT_U_FROM(second)); } else { $1 = *(($&1_type) SWIG_MustGetPtr($input,$&1_descriptor,$argnum, 0)); } - } - %typemap(in) const pair& (std::pair temp, - std::pair* m), - const pair* (std::pair temp, - std::pair* m) { + %} + %typemap(in) const pair& (std::pair *temp = 0), + const pair* (std::pair *temp = 0) %{ if (scm_is_pair($input)) { SCM first, second; first = SCM_CAR($input); second = SCM_CDR($input); if (!CHECK_T(first) || !CHECK_U(second)) SWIG_exception(SWIG_TypeError, - "map<" #T "," #U "> expected"); - temp = std::make_pair(CONVERT_T_FROM(first), - CONVERT_U_FROM(second)); - $1 = &temp; + "pair<" #T "," #U "> expected"); + temp = new std::pair< T, U >(CONVERT_T_FROM(first), CONVERT_U_FROM(second)); + $1 = temp; } else { $1 = ($1_ltype) SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0); } - } + %} + %typemap(argout) const pair&, const pair* %{ delete temp$argnum; %} %typemap(out) pair { $result = scm_cons(CONVERT_T_TO($1.first), CONVERT_U_TO($1.second)); From 9110d47ea653bfd4d972cb00b3b77afce63dfb9a Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Wed, 24 Apr 2013 09:56:02 +0200 Subject: [PATCH 0574/1160] Use freearg instead of argout to free temp variable --- Lib/guile/std_pair.i | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/guile/std_pair.i b/Lib/guile/std_pair.i index 238c5188b..512d0d555 100644 --- a/Lib/guile/std_pair.i +++ b/Lib/guile/std_pair.i @@ -54,7 +54,7 @@ namespace std { SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0); } %} - %typemap(argout) const pair&, const pair* %{ delete temp$argnum; %} + %typemap(freearg) const pair&, const pair* %{ delete temp$argnum; %} %typemap(out) pair { T* x = new T($1.first); U* y = new U($1.second); @@ -162,7 +162,7 @@ namespace std { SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0); } %} - %typemap(argout) const pair&, const pair* %{ delete temp$argnum; %} + %typemap(freearg) const pair&, const pair* %{ delete temp$argnum; %} %typemap(out) pair { U* y = new U($1.second); SCM second = SWIG_NewPointerObj(y,$descriptor(U *), 1); @@ -262,7 +262,7 @@ namespace std { SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0); } %} - %typemap(argout) const pair&, const pair* %{ delete temp$argnum; %} + %typemap(freearg) const pair&, const pair* %{ delete temp$argnum; %} %typemap(out) pair { T* x = new T($1.first); SCM first = SWIG_NewPointerObj(x,$descriptor(T *), 1); @@ -360,7 +360,7 @@ namespace std { SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0); } %} - %typemap(argout) const pair&, const pair* %{ delete temp$argnum; %} + %typemap(freearg) const pair&, const pair* %{ delete temp$argnum; %} %typemap(out) pair { $result = scm_cons(CONVERT_T_TO($1.first), CONVERT_U_TO($1.second)); From 469022d311c3a979b5a228b472891a21b56f3a6d Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Wed, 24 Apr 2013 17:23:06 +0200 Subject: [PATCH 0575/1160] Disable guile 2's autocompilation feature for the test suite Autocompilation generates a lot of warnings. Most of them just informational, but it clutters the test output. --- Doc/Manual/Guile.html | 6 ++++++ Examples/test-suite/guile/Makefile.in | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Doc/Manual/Guile.html b/Doc/Manual/Guile.html index 53368bc77..8ecdf249c 100644 --- a/Doc/Manual/Guile.html +++ b/Doc/Manual/Guile.html @@ -56,6 +56,12 @@ SWIG works with Guile versions 1.8.x and 2.0.x. Support for version 1.6.x has been dropped. The last version of SWIG that still works with Guile version 1.6.x is SWIG 2.0.9. +

        +Note that starting with guile 2.0, the guile sources can be compiled for +improved performance. This is currently not tested with swig +so your mileage may vary. To be safe set environment variable +GUILE_AUTO_COMPILE to 0 when using swig generated guile code. +

        23.2 Meaning of "Module"

        diff --git a/Examples/test-suite/guile/Makefile.in b/Examples/test-suite/guile/Makefile.in index 455c26a66..0c7b3137c 100644 --- a/Examples/test-suite/guile/Makefile.in +++ b/Examples/test-suite/guile/Makefile.in @@ -52,7 +52,7 @@ INCLUDES += -I$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/guile # a file is found which has _runme.scm appended after the testcase name. run_testcase = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(GUILE) -l $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \ + env GUILE_AUTO_COMPILE=0 LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(GUILE) -l $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \ fi # Clean From fb7b45beccd9a1e5fd3b24c44369ec44600da73f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 24 Apr 2013 15:56:27 +0200 Subject: [PATCH 0576/1160] Add guile test for guile 2 --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index abdb54327..7d7204b6a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,8 @@ matrix: env: SWIGLANG=csharp - compiler: gcc env: SWIGLANG=go + - compiler: gcc + env: SWIGLANG=guile - compiler: gcc env: SWIGLANG=java - compiler: gcc @@ -34,6 +36,7 @@ before_install: - time sudo apt-get -qq install libboost-dev - if test "$SWIGLANG" = "csharp"; then sudo apt-get -qq install mono-devel; fi - if test "$SWIGLANG" = "go"; then go env | sed -e 's/^/export /' > goenvsetup && source goenvsetup && rm -f goenvsetup; fi # Until configure.ac is fixed + - if test "$SWIGLANG" = "guile"; then sudo apt-get -qq install guile-2.0-dev; fi - if test "$SWIGLANG" = "lua"; then sudo apt-get -qq install lua5.1 liblua5.1-dev; fi - if test "$SWIGLANG" = "octave"; then sudo apt-get -qq install octave3.2 octave3.2-headers; fi - if test "$SWIGLANG" = "php"; then sudo apt-get install php5-cli php5-dev; fi From 3e0247e553fb187a2f5b2ac73d9978a4f0d126bd Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Sat, 27 Apr 2013 14:15:47 +0200 Subject: [PATCH 0577/1160] guile: fix integer test on 64 bit systems --- Examples/test-suite/integers.i | 11 ++++++ Examples/test-suite/schemerunme/integers.scm | 39 ++++++++++++++------ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Examples/test-suite/integers.i b/Examples/test-suite/integers.i index 7f78a2a18..6a9ede4bc 100644 --- a/Examples/test-suite/integers.i +++ b/Examples/test-suite/integers.i @@ -16,5 +16,16 @@ unsigned long unsigned_long_identity(unsigned long x) { return x; } signed long long signed_long_long_identity(signed long long x) { return x; } unsigned long long unsigned_long_long_identity(unsigned long long x) { return x; } + + size_t signed_char_size() { return sizeof (signed char); } + size_t unsigned_char_size() { return sizeof (unsigned char); } + size_t signed_short_size() { return sizeof (signed short); } + size_t unsigned_short_size() { return sizeof (unsigned short); } + size_t signed_int_size() { return sizeof (signed int); } + size_t unsigned_int_size() { return sizeof (unsigned int); } + size_t signed_long_size() { return sizeof (signed long); } + size_t unsigned_long_size() { return sizeof (unsigned long); } + size_t signed_long_long_size() { return sizeof (signed long long); } + size_t unsigned_long_long_size() { return sizeof (unsigned long long); } %} diff --git a/Examples/test-suite/schemerunme/integers.scm b/Examples/test-suite/schemerunme/integers.scm index 0bbf36ea8..903e6a9f1 100644 --- a/Examples/test-suite/schemerunme/integers.scm +++ b/Examples/test-suite/schemerunme/integers.scm @@ -12,17 +12,32 @@ (check-equality (throws-exception? (,function (- ,from 1))) #t) (check-equality (throws-exception? (,function (+ ,to 1))) #t))) -;;; signed char, unsigned char typemaps deal with characters, not integers. -;; (check-range signed-char-identity (- (expt 2 7)) (- (expt 2 7) 1)) -;; (check-range unsigned-char-identity 0 (- (expt 2 8) 1)) -(check-range signed-short-identity (- (expt 2 15)) (- (expt 2 15) 1)) -(check-range unsigned-short-identity 0 (- (expt 2 16) 1)) -(check-range signed-int-identity (- (expt 2 31)) (- (expt 2 31) 1)) -(check-range unsigned-int-identity 0 (- (expt 2 32) 1)) -(check-range signed-long-identity (- (expt 2 31)) (- (expt 2 31) 1)) -(check-range unsigned-long-identity 0 (- (expt 2 32) 1)) -;;; long long not implemented in Guile and MzScheme. -;; (check-range signed-long-long-identity (- (expt 2 63)) (- (expt 2 63) 1)) -;; (check-range unsigned-long-long-identity 0 (- (expt 2 64) 1)) +(let ((signed-short-min (- (expt 2 (- (* (signed-short-size) 8) 1)))) + (signed-short-max (- (expt 2 (- (* (signed-short-size) 8) 1)) 1)) + (unsigned-short-max (- (expt 2 (* (unsigned-short-size) 8)) 1)) + (signed-int-min (- (expt 2 (- (* (signed-int-size) 8) 1)))) + (signed-int-max (- (expt 2 (- (* (signed-int-size) 8) 1)) 1)) + (unsigned-int-max (- (expt 2 (* (unsigned-int-size) 8)) 1)) + (signed-long-min (- (expt 2 (- (* (signed-long-size) 8) 1)))) + (signed-long-max (- (expt 2 (- (* (signed-long-size) 8) 1)) 1)) + (unsigned-long-max (- (expt 2 (* (unsigned-long-size) 8)) 1)) + (signed-long-long-min (- (expt 2 (- (* (signed-long-long-size) 8) 1)))) + (signed-long-long-max (- (expt 2 (- (* (signed-long-long-size) 8) 1)) 1)) + (unsigned-long-long-max (- (expt 2 (* (unsigned-long-long-size) 8)) 1)) + ) + + ;;; signed char, unsigned char typemaps deal with characters, not integers. + ;; (check-range signed-char-identity (- (expt 2 7)) (- (expt 2 7) 1)) + ;; (check-range unsigned-char-identity 0 (- (expt 2 8) 1)) + (check-range signed-short-identity signed-short-min signed-short-max) + (check-range unsigned-short-identity 0 unsigned-short-max) + (check-range signed-int-identity signed-int-min signed-int-max) + (check-range unsigned-int-identity 0 unsigned-int-max) + (check-range signed-long-identity signed-long-min signed-long-max) + (check-range unsigned-long-identity 0 unsigned-long-max) + ;;; long long not implemented in Guile and MzScheme. + (check-range signed-long-long-identity signed-long-long-min signed-long-long-max) + (check-range unsigned-long-long-identity 0 unsigned-long-long-max) +) (exit 0) From 7b9c302fa10d30cbef1784b09df81492ba5f86f6 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Fri, 26 Apr 2013 16:52:38 +0200 Subject: [PATCH 0578/1160] guile: fix matrix example - add missing library in link phase - empty true path () for if is not allowed --- Examples/guile/Makefile.in | 5 +++-- Examples/guile/matrix/Makefile | 1 + Examples/guile/matrix/matrix.scm | 28 ++++++++++++++++------------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Examples/guile/Makefile.in b/Examples/guile/Makefile.in index 3110ac994..69c7bb696 100644 --- a/Examples/guile/Makefile.in +++ b/Examples/guile/Makefile.in @@ -7,6 +7,7 @@ SWIG = ../$(top_srcdir)/preinst-swig CC = @CC@ CXX = @CXX@ CFLAGS = @PLATFLAGS@ +LIBS = GUILE_CFLAGS = @GUILE_CFLAGS@ GUILE_LIBS = @GUILE_LIBS@ SWIGOPT = @@ -31,10 +32,10 @@ guile_clean: sub-all: $(SWIG) -guile $(SWIGOPT) $(IFILE) - $(CC) $(CFLAGS) -o $(TARGET) $(SRCS) $(WRAP) $(GUILE_CFLAGS) $(GUILE_LIBS) + $(CC) $(CFLAGS) -o $(TARGET) $(SRCS) $(WRAP) $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) sub-all-cxx: $(SWIG) -c++ -guile $(SWIGOPT) $(IFILE) - $(CXX) $(CFLAGS) -o $(TARGET) $(SRCS) $(CXXWRAP) $(GUILE_CFLAGS) $(GUILE_LIBS) + $(CXX) $(CFLAGS) -o $(TARGET) $(SRCS) $(CXXWRAP) $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) # Makefile ends here diff --git a/Examples/guile/matrix/Makefile b/Examples/guile/matrix/Makefile index e8466e5fc..988a0ee5c 100644 --- a/Examples/guile/matrix/Makefile +++ b/Examples/guile/matrix/Makefile @@ -12,6 +12,7 @@ build: TARGET=$(TARGET) \ IFILE=$(IFILE) \ MODULE=$(MODULE) \ + LIBS="-lm" \ sub-all clean: diff --git a/Examples/guile/matrix/matrix.scm b/Examples/guile/matrix/matrix.scm index 18e52842d..d7cab84f4 100644 --- a/Examples/guile/matrix/matrix.scm +++ b/Examples/guile/matrix/matrix.scm @@ -138,24 +138,28 @@ (set-m m1 i j (+ (get-m m1 i j) (get-m m2 i j))) (add-two m1 m2 i (+ j 1))) (add-two m1 m2 (+ i 1) 0)))) - (if (null? ML) () (begin - (add-two M (car ML) 0 0) - (add-mat M (cdr ML))))) + (if (null? ML) *unspecified* + (begin + (add-two M (car ML) 0 0) + (add-mat M (cdr ML))))) (define (cleanup ML) - (if (null? ML) () (begin - (destroy-matrix (car ML)) - (cleanup (cdr ML))))) + (if (null? ML) *unspecified* + (begin + (destroy-matrix (car ML)) + (cleanup (cdr ML))))) (define (make-random ML) ; Put random values in them - (if (null? ML) () (begin - (randmat (car ML)) - (make-random (cdr ML))))) + (if (null? ML) *unspecified* + (begin + (randmat (car ML)) + (make-random (cdr ML))))) (define (mul-mat m ML) - (if (null? ML) () (begin - (mat-mult m (car ML) m) - (mul-mat m (cdr ML))))) + (if (null? ML) *unspecified* + (begin + (mat-mult m (car ML) m) + (mul-mat m (cdr ML))))) ;;; Now we'll hammer on things a little bit just to make ;;; sure everything works. From 95bfa86ae9b043b07ab7dd2a243846f2084693c6 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Fri, 26 Apr 2013 17:25:50 +0200 Subject: [PATCH 0579/1160] guile: fix multimap example - fix compiler warning - fix guile 2 deprecation warnings - minor cleanup of generated code --- Examples/guile/multimap/example.i | 51 ++++++++++++++++++------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/Examples/guile/multimap/example.i b/Examples/guile/multimap/example.i index 21d7e5032..135b6b123 100644 --- a/Examples/guile/multimap/example.i +++ b/Examples/guile/multimap/example.i @@ -15,43 +15,52 @@ extern int squareCubed (int n, int *OUTPUT); extern int gcd(int x, int y); -%typemap(in) (int argc, char *argv[]) { - int i; - SCM *v; - if (!(SCM_NIMP($input) && SCM_VECTORP($input))) { +%typemap(in) (int argc, char *argv[]) %{ + scm_t_array_handle handle; + size_t i; + ssize_t inc; + const SCM *v; + if (!(SCM_NIMP($input) && scm_is_vector($input))) { SWIG_exception(SWIG_ValueError, "Expecting a vector"); return 0; } - $1 = SCM_LENGTH($input); + v = scm_vector_elements($input, &handle, &$1, &inc); if ($1 == 0) { SWIG_exception(SWIG_ValueError, "Vector must contain at least 1 element"); } $2 = (char **) malloc(($1+1)*sizeof(char *)); - v = SCM_VELTS($input); - for (i = 0; i < $1; i++) { - if (!(SCM_NIMP(v[i]) && SCM_STRINGP(v[i]))) { - free($2); + for (i = 0; i < $1; i++, v +=inc ) { + if (!(SCM_NIMP(*v) && scm_is_string(*v))) { + free($2); SWIG_exception(SWIG_ValueError, "Vector items must be strings"); return 0; } - $2[i] = SCM_CHARS(v[i]); + $2[i] = scm_to_locale_string(*v); } $2[i] = 0; -} + scm_array_handle_release (&handle); +%} -%typemap(freearg) (int argc, char *argv[]) { - free($2); -} +%typemap(freearg) (int argc, char *argv[]) %{ + for (i = 0; i < $1; i++) { + free($2[i]); + } + free($2); +%} extern int gcdmain(int argc, char *argv[]); -%typemap(in) (char *bytes, int len) { - if (!(SCM_NIMP($input) && SCM_STRINGP($input))) { +%typemap(in) (char *bytes, int len) %{ + if (!(SCM_NIMP($input) && scm_is_string($input))) { SWIG_exception(SWIG_ValueError, "Expecting a string"); } - $1 = SCM_CHARS($input); - $2 = SCM_LENGTH($input); -} + $1 = scm_to_locale_string($input); + $2 = scm_c_string_length($input); +%} + +%typemap(freearg) (char *bytes, int len) %{ + free($1); +%} extern int count(char *bytes, int len, char c); @@ -67,7 +76,7 @@ extern int count(char *bytes, int len, char c); %typemap(argout) (char *str, int len) { SWIG_APPEND_VALUE(scm_from_locale_stringn($1,$2)); - if ($1) scm_must_free($1); + if ($1) SWIG_free($1); } extern void capitalize(char *str, int len); @@ -78,7 +87,7 @@ extern void capitalize(char *str, int len); %typemap(check) (double cx, double cy) { double a = $1*$1 + $2*$2; if (a > 1.0) { - SWIG_exception(SWIG_ValueError,"$1_name and $2_name must be in unit circle"); + SWIG_exception(SWIG_ValueError,"$1_name and $2_name must be in unit circle"); } } From ce14abaf616c9592f746639b962486ea9c917e5f Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Sun, 28 Apr 2013 21:13:40 +0200 Subject: [PATCH 0580/1160] guile: emit warning when -gh or -scm option are used --- Source/Modules/guile.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index afe039ac7..c1821c916 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -218,8 +218,10 @@ public: goops = true; Swig_mark_arg(i); } else if (strcmp(argv[i], "-gh") == 0) { + Printf(stderr, "guile: Warning: -gh option is deprecated. Swig will always generate wrappers using the scm interface. See documentation for more information regarding the deprecated gh interface.\n"); Swig_mark_arg(i); } else if (strcmp(argv[i], "-scm") == 0) { + Printf(stderr, "guile: Warning: -scm option is deprecated. Swig will always generate wrappers using the scm interface. See documentation for more information regarding the deprecated gh interface.\n"); Swig_mark_arg(i); } else if (strcmp(argv[i], "-primsuffix") == 0) { if (argv[i + 1]) { From 7297f5aa513411f345e8c2438e88b1d9683bedcd Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Sun, 28 Apr 2013 22:38:20 +0200 Subject: [PATCH 0581/1160] Don't use obsolete -scm option in own makefiles --- Examples/Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index b1bf8d049..403e6191c 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -466,13 +466,13 @@ GUILE_SCRIPT = $(RUNME).scm # Build a dynamically loaded module with passive linkage and the scm interface #------------------------------------------------------------------ guile: $(SRCS) - $(SWIG) -guile -scm -Linkage passive $(SWIGOPT) $(INTERFACEPATH) + $(SWIG) -guile -Linkage passive $(SWIGOPT) $(INTERFACEPATH) $(CC) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ISRCS) $(SRCS) $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) guile_cpp: $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO): $(SRCS) - $(SWIG) -c++ -guile -scm -Linkage passive $(SWIGOPT) $(INTERFACEPATH) + $(SWIG) -c++ -guile -Linkage passive $(SWIGOPT) $(INTERFACEPATH) $(CXX) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $@ From 9203c6d5c63a04dfe894d60b83af7f4e76d96515 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 29 Apr 2013 08:02:18 +0100 Subject: [PATCH 0582/1160] Remove deprecated Guile options from help. Also use wording for deprecated options warning which is consistent with elsewhere. --- Source/Modules/guile.cxx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index c1821c916..e0a084583 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -46,11 +46,6 @@ Guile Options (available with -guile)\n\ -scmstub - Output Scheme file with module declaration and\n\ exports; only with `passive' and `simple' linkage\n\ -useclassprefix - Prepend the class name to all goops identifiers\n\ -\n\ -Obsolete parameters:\n\ -These parameters do nothing, but are kept for compatibility with old scripts only.\n\ - -gh - Was used to select the gh_ Guile API. \n\ - -scm - scm Guile API is always used now. \n\ \n"; static File *f_begin = 0; @@ -218,10 +213,10 @@ public: goops = true; Swig_mark_arg(i); } else if (strcmp(argv[i], "-gh") == 0) { - Printf(stderr, "guile: Warning: -gh option is deprecated. Swig will always generate wrappers using the scm interface. See documentation for more information regarding the deprecated gh interface.\n"); + Printf(stderr, "Deprecated command line option: -gh. Wrappers are always generated for the SCM interface. See documentation for more information regarding the deprecated GH interface.\n"); Swig_mark_arg(i); } else if (strcmp(argv[i], "-scm") == 0) { - Printf(stderr, "guile: Warning: -scm option is deprecated. Swig will always generate wrappers using the scm interface. See documentation for more information regarding the deprecated gh interface.\n"); + Printf(stderr, "Deprecated command line option: -scm. Wrappers are always generated for the SCM interface. See documentation for more information regarding the deprecated GH interface.\n"); Swig_mark_arg(i); } else if (strcmp(argv[i], "-primsuffix") == 0) { if (argv[i + 1]) { From 17a563538580d6e414db71d06b3a6fd35d5b1ec5 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Mon, 29 Apr 2013 12:30:33 +0200 Subject: [PATCH 0583/1160] Add summary of recent guile updates in changelog --- CHANGES.current | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 5022a3030..96e5124a4 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,16 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-04-28: gjanssens + Updates in guile module: + - Add support for guile 2.0 + - Drop support for guile 1.6 + - Drop support for generating wrappers using guile's gh interface. + All generated wrappers will use the scm interface from now on. + - Deprecate -gh and -scm options. They are no longer needed. + A warning will be issued when these options are still used. + - Fix all tests and examples to have a successful travis test + 2013-04-18: wsfulton Apply Patch #36 from Jesus Lopez to add support for $descriptor() special variable macro expansion in fragments. For example: From c30a79217de051c05ead8d9c94e0dbcfea5c26f7 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Mon, 29 Apr 2013 12:51:47 +0200 Subject: [PATCH 0584/1160] guilescm directory no longer exists. No need to have it in .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 877d2b2a9..fbeebc67d 100644 --- a/.gitignore +++ b/.gitignore @@ -101,7 +101,6 @@ Examples/test-suite/csharp/*/ Examples/test-suite/d/*/ Examples/test-suite/go/*/ Examples/test-suite/guile/*/ -Examples/test-suite/guilescm/*/ Examples/test-suite/java/*/ Examples/test-suite/lua/*/ Examples/test-suite/mzscheme/*/ From 850cd375990da5a93376cfed1aacf47f71695e7c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 29 Apr 2013 22:01:46 +0100 Subject: [PATCH 0585/1160] Don't skip Python testing if static library directory not found 'make check' does not require the Python static libraries to be available. There is no easy way to find PYLIB - the directory containing the static library especially now Debian based systems have changed to put them in directories like /usr/lib/x86_64-linux-gnu/libpython2.7.a. --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 1a699167f..2a86e9fa7 100644 --- a/configure.ac +++ b/configure.ac @@ -2237,14 +2237,14 @@ AC_SUBST(SKIP_OCTAVE) SKIP_PYTHON= -if (test -z "$PYINCLUDE" || test -z "$PYLIB") && - (test -z "$PY3INCLUDE" || test -z "PY3LIB") ; then +if (test -z "$PYINCLUDE") && + (test -z "$PY3INCLUDE") ; then SKIP_PYTHON="1" fi AC_SUBST(SKIP_PYTHON) SKIP_PYTHON3= -if test -z "$PY3INCLUDE" || test -z "$PY3LIB" ; then +if test -z "$PY3INCLUDE" ; then SKIP_PYTHON3="1" fi AC_SUBST(SKIP_PYTHON3) From ae1c39591787c934429e33e134e19ffabe3da5bb Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 29 Apr 2013 18:38:11 +0100 Subject: [PATCH 0586/1160] Guile tweak in CHANGES.current --- CHANGES.current | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 96e5124a4..46b0d5589 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -6,7 +6,7 @@ Version 2.0.10 (in progress) ============================ 2013-04-28: gjanssens - Updates in guile module: + [Guile] Updates in guile module: - Add support for guile 2.0 - Drop support for guile 1.6 - Drop support for generating wrappers using guile's gh interface. From ac596eb8a3bce7d4d72dce78c7a8b12014a3b428 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 29 Apr 2013 19:06:44 +0100 Subject: [PATCH 0587/1160] Add C++ class example for Guile Also correct other example c++ makefiles --- Examples/guile/class/Makefile | 18 ++++++++++++++++ Examples/guile/class/example.cxx | 28 ++++++++++++++++++++++++ Examples/guile/class/example.h | 34 ++++++++++++++++++++++++++++++ Examples/guile/class/example.i | 9 ++++++++ Examples/guile/std_vector/Makefile | 6 +++--- 5 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 Examples/guile/class/Makefile create mode 100644 Examples/guile/class/example.cxx create mode 100644 Examples/guile/class/example.h create mode 100644 Examples/guile/class/example.i diff --git a/Examples/guile/class/Makefile b/Examples/guile/class/Makefile new file mode 100644 index 000000000..827b2fe03 --- /dev/null +++ b/Examples/guile/class/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i + +check: build + +build: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_cpp + +static: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static_cpp + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean diff --git a/Examples/guile/class/example.cxx b/Examples/guile/class/example.cxx new file mode 100644 index 000000000..1e8e203dd --- /dev/null +++ b/Examples/guile/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/guile/class/example.h b/Examples/guile/class/example.h new file mode 100644 index 000000000..0d4527e92 --- /dev/null +++ b/Examples/guile/class/example.h @@ -0,0 +1,34 @@ +/* File : example.h */ + +class Shape { +public: + Shape() { + nshapes++; + } + virtual ~Shape() { + nshapes--; + }; + double x, y; + void move(double dx, double dy); + virtual double area(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/guile/class/example.i b/Examples/guile/class/example.i new file mode 100644 index 000000000..fbdf7249f --- /dev/null +++ b/Examples/guile/class/example.i @@ -0,0 +1,9 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ +%include "example.h" diff --git a/Examples/guile/std_vector/Makefile b/Examples/guile/std_vector/Makefile index 08bf82c87..fa138f43f 100644 --- a/Examples/guile/std_vector/Makefile +++ b/Examples/guile/std_vector/Makefile @@ -1,17 +1,17 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +CXXSRCS = TARGET = example INTERFACE = example.i check: build build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static_cpp clean: From 4b1e8828658d9464cb9f4adf56db9d764d78bf23 Mon Sep 17 00:00:00 2001 From: Terrell Russell Date: Tue, 30 Apr 2013 22:49:12 -0300 Subject: [PATCH 0588/1160] subject/verb agreement --- Doc/Manual/README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/README b/Doc/Manual/README index f01013d54..66daaec90 100644 --- a/Doc/Manual/README +++ b/Doc/Manual/README @@ -1,9 +1,9 @@ This directory contains the HTML for the SWIG users manual. All of this HTML is hand-written. However, section numbering, indices, -and the table of contents is generated automatically by the 'maketoc.py' +and the table of contents are generated automatically by the 'maketoc.py' script. The Makefile has further information on how the various alternative -forms of the documentation is generated from the hand-written HTML. +forms of the documentation are generated from the hand-written HTML. There are 4 types of boxes that code or whatever can be inside: -
        ...
        From 8767e4e29e3214ea91565c7e2dce7bd7860f2c9a Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Wed, 1 May 2013 11:19:14 +0200 Subject: [PATCH 0589/1160] guile: make constants example display some output similar to other languages --- Examples/guile/constants/constants.scm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Examples/guile/constants/constants.scm b/Examples/guile/constants/constants.scm index 5220150f1..59fd26e5a 100644 --- a/Examples/guile/constants/constants.scm +++ b/Examples/guile/constants/constants.scm @@ -1,10 +1,19 @@ (or (= (ICONST) 42) (exit 1)) +(display "ICONST = ")(display (ICONST))(display " (should be 42)\n") (or (< (abs (- (FCONST) 2.1828)) 0.00001) (exit 1)) +(display "FCONST = ")(display (FCONST))(display " (should be 2.1828)\n") (or (char=? (CCONST) #\x) (exit 1)) +(display "CCONST = ")(display (CCONST))(display " (should be 'x')\n") (or (char=? (CCONST2) #\newline) (exit 1)) +(display "CCONST2 = ")(display (CCONST2))(display " (this should be on a new line)\n") (or (string=? (SCONST) "Hello World") (exit 1)) +(display "SCONST = ")(display (SCONST))(display " (should be 'Hello World')\n") (or (string=? (SCONST2) "\"Hello World\"") (exit 1)) +(display "SCONST2 = ")(display (SCONST2))(display " (should be \"Hello World\")\n") (or (< (abs (- (EXPR) (+ (ICONST) (* 3 (FCONST))))) 0.00001) (exit 1)) +(display "EXPR = ")(display (abs (- (EXPR) (+ (ICONST) (* 3 (FCONST))))))(display " (should round to 0.0)\n") (or (= (iconst) 37) (exit 1)) +(display "iconst = ")(display (iconst))(display " (should be 37)\n") (or (< (abs (- (fconst) 3.14)) 0.00001) (exit 1)) +(display "fconst = ")(display (fconst))(display " (should be 3.14)\n") (exit 0) From fbb1978eb459ffa6bbae2192e86608fab4781d99 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Wed, 1 May 2013 12:13:13 +0200 Subject: [PATCH 0590/1160] guile: get multimap example to run --- Examples/guile/Makefile.in | 8 +++++++- Examples/guile/multimap/Makefile | 1 + Examples/guile/multimap/runme.scm | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Examples/guile/Makefile.in b/Examples/guile/Makefile.in index 69c7bb696..f84d54a38 100644 --- a/Examples/guile/Makefile.in +++ b/Examples/guile/Makefile.in @@ -7,7 +7,8 @@ SWIG = ../$(top_srcdir)/preinst-swig CC = @CC@ CXX = @CXX@ CFLAGS = @PLATFLAGS@ -LIBS = +LIBS = +GUILE = @GUILE@ GUILE_CFLAGS = @GUILE_CFLAGS@ GUILE_LIBS = @GUILE_LIBS@ SWIGOPT = @@ -38,4 +39,9 @@ sub-all-cxx: $(SWIG) -c++ -guile $(SWIGOPT) $(IFILE) $(CXX) $(CFLAGS) -o $(TARGET) $(SRCS) $(CXXWRAP) $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) +run_example: + if [ -f $(RUNSCRIPT) ]; then \ + env GUILE_AUTO_COMPILE=0 LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(GUILE) -l $(RUNSCRIPT); \ + fi + # Makefile ends here diff --git a/Examples/guile/multimap/Makefile b/Examples/guile/multimap/Makefile index 00fa5df28..7b2f264ba 100644 --- a/Examples/guile/multimap/Makefile +++ b/Examples/guile/multimap/Makefile @@ -5,6 +5,7 @@ TARGET = example INTERFACE = example.i check: build + $(MAKE) -f ../Makefile RUNSCRIPT=runme.scm run_example build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/guile/multimap/runme.scm b/Examples/guile/multimap/runme.scm index edc197259..1654fd3a8 100644 --- a/Examples/guile/multimap/runme.scm +++ b/Examples/guile/multimap/runme.scm @@ -1,6 +1,6 @@ ;;; Test out some multi-argument typemaps -(use-modules (example)) +(dynamic-call "scm_init_example_module" (dynamic-link "./libexample.so")) ; Call the GCD function @@ -27,4 +27,4 @@ (display (capitalize "hello world")) (newline) - +(exit 0) From 6704501aad77eb0fad25468515d37e3c9e95ef21 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 1 May 2013 16:02:02 +0100 Subject: [PATCH 0591/1160] Guile multimap example fix for 64 bit systems --- Examples/guile/multimap/example.i | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Examples/guile/multimap/example.i b/Examples/guile/multimap/example.i index 135b6b123..c24d45ddc 100644 --- a/Examples/guile/multimap/example.i +++ b/Examples/guile/multimap/example.i @@ -18,13 +18,15 @@ extern int gcd(int x, int y); %typemap(in) (int argc, char *argv[]) %{ scm_t_array_handle handle; size_t i; + size_t lenp; ssize_t inc; const SCM *v; if (!(SCM_NIMP($input) && scm_is_vector($input))) { SWIG_exception(SWIG_ValueError, "Expecting a vector"); return 0; } - v = scm_vector_elements($input, &handle, &$1, &inc); + v = scm_vector_elements($input, &handle, &lenp, &inc); + $1 = (int)lenp; if ($1 == 0) { SWIG_exception(SWIG_ValueError, "Vector must contain at least 1 element"); } From 5690323b8f970297d5ed8c5ad3a743654ca17b53 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 3 May 2013 19:39:11 +0100 Subject: [PATCH 0592/1160] Rework perl5 compiler and linker flags This fixes perl on cygwin. Probably on other platforms too. --- Examples/Makefile.in | 13 ++++++++----- configure.ac | 34 +++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 403e6191c..8ffb667f6 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -24,7 +24,7 @@ TARGET = CC = @CC@ CXX = @CXX@ -CFLAGS = @PLATFLAGS@ +CFLAGS = @BOOST_CPPFLAGS@ @PLATFLAGS@ prefix = @prefix@ exec_prefix= @exec_prefix@ SRCS = @@ -217,6 +217,9 @@ PERL5_INCLUDE= @PERL5EXT@ # Extra Perl specific dynamic linking options PERL5_DLNK = @PERL5DYNAMICLINKING@ PERL5_CCFLAGS = @PERL5CCFLAGS@ +PERL5_CCDLFLAGS = @PERL5CCDLFLAGS@ +PERL5_CCCDLFLAGS = @PERL5CCCDLFLAGS@ +PERL5_LDFLAGS = @PERL5LDFLAGS@ PERL = @PERL@ PERL5_LIB = -L$(PERL5_INCLUDE) -l@PERL5LIB@ @LIBS@ $(SYSLIBS) PERL5_SCRIPT = $(RUNME).pl @@ -227,8 +230,8 @@ PERL5_SCRIPT = $(RUNME).pl perl5: $(SRCS) $(SWIG) -perl5 $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c -Dbool=char $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) $(PERL5_CCFLAGS) -I$(PERL5_INCLUDE) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(PERL5_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + $(CC) -c -Dbool=char $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) $(PERL5_CCFLAGS) $(PERL5_CCCDLFLAGS) -I$(PERL5_INCLUDE) + $(LDSHARED) $(CFLAGS) $(PERL5_CCDLFLAGS) $(OBJS) $(IOBJS) $(PERL5_LDFLAGS) $(PERL5_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) # ---------------------------------------------------------------- # Build a Perl5 dynamically loadable module (C++) @@ -236,8 +239,8 @@ perl5: $(SRCS) perl5_cpp: $(SRCS) $(SWIG) -perl5 -c++ $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PERL5_CCFLAGS) -I$(PERL5_INCLUDE) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(PERL5_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + $(CXX) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PERL5_CCFLAGS) $(PERL5_CCCDLFLAGS) -I$(PERL5_INCLUDE) + $(CXXSHARED) $(CFLAGS) $(PERL5_CCDLFLAGS) $(OBJS) $(IOBJS) $(PERL5_LDFLAGS) $(PERL5_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) # ---------------------------------------------------------------- # Build a module from existing XS C source code. (ie. from xsubpp). diff --git a/configure.ac b/configure.ac index 2a86e9fa7..1fcdadfca 100644 --- a/configure.ac +++ b/configure.ac @@ -847,7 +847,7 @@ fi AC_MSG_CHECKING(for Perl5 header files) if test -n "$PERL"; then PERL5DIR=`($PERL -e 'use Config; print $Config{archlib}, "\n";') 2>/dev/null` - if test "$PERL5DIR" != ""; then + if test -n "$PERL5DIR" ; then dirs="$PERL5DIR $PERL5DIR/CORE" PERL5EXT=none for i in $dirs; do @@ -863,19 +863,40 @@ if test -n "$PERL"; then fi AC_MSG_CHECKING(for Perl5 library) - PERL5LIB=`($PERL -e 'use Config; $_=$Config{libperl}; s/^lib//; s/$Config{_a}$//; print $_, "\n"') 2>/dev/null` - if test "$PERL5LIB" = "" ; then + PERL5LIB=`($PERL -e 'use Config; $_=$Config{libperl}; s/^lib//; s/$Config{_a}$//; s/\.$Config{so}.*//; print $_, "\n"') 2>/dev/null` + if test -z "$PERL5LIB" ; then AC_MSG_RESULT(not found) else AC_MSG_RESULT($PERL5LIB) fi - AC_MSG_CHECKING(for Perl5 compiler options) + AC_MSG_CHECKING(for Perl5 ccflags) PERL5CCFLAGS=`($PERL -e 'use Config; print $Config{ccflags}, "\n"' | sed "s/-Wdeclaration-after-statement//" | sed "s/-I/$ISYSTEM/") 2>/dev/null` - if test "$PERL5CCFLAGS" = "" ; then + if test -z "$PERL5CCFLAGS" ; then AC_MSG_RESULT(not found) else AC_MSG_RESULT($PERL5CCFLAGS) fi + AC_MSG_CHECKING(for Perl5 ccdlflags) + PERL5CCDLFLAGS=`($PERL -e 'use Config; print $Config{ccdlflags}, "\n"') 2>/dev/null` + if test -z "$PERL5CCDLFLAGS" ; then + AC_MSG_RESULT(not found) + else + AC_MSG_RESULT($PERL5CCDLFLAGS) + fi + AC_MSG_CHECKING(for Perl5 cccdlflags) + PERL5CCCDLFLAGS=`($PERL -e 'use Config; print $Config{cccdlflags}, "\n"') 2>/dev/null` + if test -z "$PERL5CCCDLFLAGS" ; then + AC_MSG_RESULT(not found) + else + AC_MSG_RESULT($PERL5CCCDLFLAGS) + fi + AC_MSG_CHECKING(for Perl5 ldflags) + PERL5LDFLAGS=`($PERL -e 'use Config; print $Config{ldflags}, "\n"') 2>/dev/null` + if test -z "$PERL5LDFLAGS" ; then + AC_MSG_RESULT(not found) + else + AC_MSG_RESULT($PERL5LDFLAGS) + fi else AC_MSG_RESULT(unable to determine perl5 configuration) PERL5EXT=$PERL5DIR @@ -896,6 +917,9 @@ AC_SUBST(PERL5EXT) AC_SUBST(PERL5DYNAMICLINKING) AC_SUBST(PERL5LIB) AC_SUBST(PERL5CCFLAGS) +AC_SUBST(PERL5CCDLFLAGS) +AC_SUBST(PERL5CCCDLFLAGS) +AC_SUBST(PERL5LDFLAGS) #---------------------------------------------------------------- # Look for Octave From 7d29f88641597a184fb28e64579d0ffbfc61b1da Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 1 May 2013 15:37:53 +0100 Subject: [PATCH 0593/1160] Cosmetic on unknown javac version display --- Examples/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 8ffb667f6..e57516cf1 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -602,7 +602,7 @@ java_run: java_version: $(JAVA) -version - $(JAVAC) -version || echo "unknown javac version" + $(JAVAC) -version || echo "Unknown javac version" # ----------------------------------------------------------------- # Cleaning the java examples From 067b883813a2e324931a2d689b5c0ff6ae63c598 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 1 May 2013 21:44:31 +0100 Subject: [PATCH 0594/1160] Guile doc sections update --- Doc/Manual/Contents.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 42e135140..8ef413fcb 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -803,8 +803,9 @@
        -

        1.4 Prerequisites

        +

        1.5 Prerequisites

        @@ -127,7 +142,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.5 Organization of this manual

        +

        1.6 Organization of this manual

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

        -

        1.6 How to avoid reading the manual

        +

        1.7 How to avoid reading the manual

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

        -

        1.7 Backwards compatibility

        +

        1.8 Backwards compatibility

        @@ -162,8 +177,8 @@ 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. -Potential incompatibilities are clearly marked in the detailed release notes -(CHANGES files). +Potential incompatibilities are clearly marked in the detailed +release notes.

        @@ -187,7 +202,16 @@ 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.8 Credits

        +

        1.9 Release notes

        + + +

        +The CHANGES.current, CHANGES and RELEASENOTES files shipped with SWIG in the top level directory +contain, respectively, detailed release notes for the current version, +detailed release notes for previous releases and summary release notes from SWIG-1.3.22 onwards. +

        + +

        1.10 Credits

        @@ -200,7 +224,7 @@ 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

        +

        1.11 Bug reports

        diff --git a/README b/README index d69e7c6d8..6df8a4fbd 100644 --- a/README +++ b/README @@ -24,7 +24,11 @@ A SWIG FAQ and other hints can be found on the SWIG Wiki: License ======= -Please see the LICENSE file for details of the SWIG license. +Please see the LICENSE file for details of the SWIG license. For +further insight into the license including the license of SWIG's +output code, please visit + + http://www.swig.org/legal.html Release Notes ============= From 4bf045ce2c72f3cf3a20caa9dc42b26c9e6b6458 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 2 May 2013 07:29:30 +0100 Subject: [PATCH 0596/1160] Move installation and install check instructions from README to Preface section in the documentation. --- Doc/Manual/Contents.html | 8 ++ Doc/Manual/Preface.html | 208 +++++++++++++++++++++++++++++++++++++++ README | 129 ++---------------------- 3 files changed, 225 insertions(+), 120 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 3e9c844ed..ac21bcd1e 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -25,6 +25,14 @@

      • Release notes
      • Credits
      • Bug reports +
      • Installation +
      diff --git a/Doc/Manual/Preface.html b/Doc/Manual/Preface.html index d489912bd..d17dc229c 100644 --- a/Doc/Manual/Preface.html +++ b/Doc/Manual/Preface.html @@ -21,6 +21,14 @@
    • Release notes
    • Credits
    • Bug reports +
    • Installation +
    @@ -117,6 +125,7 @@ about this can be obtained at: +

    1.5 Prerequisites

    @@ -239,5 +248,204 @@ used, and any important pieces of the SWIG generated wrapper code. We can only fix bugs if we know about them.

    +

    1.12 Installation

    + + +

    1.12.1 Windows installation

    + + +

    +Please see the dedicated Windows chapter for instructions on installing +SWIG on Windows and running the examples. The Windows distribution is +called swigwin and includes a prebuilt SWIG executable, swig.exe, included in +the top level directory. Otherwise it is exactly the same as +the main SWIG distribution. There is no need to download anything else. +

    + +

    1.12.2 Unix installation

    + + +

    +You must use GNU make to build and install SWIG. +

    + +

    +PCRE +needs to be installed on your system to build SWIG, in particular +pcre-config must be available. If you have PCRE headers and libraries but not +pcre-config itself or, alternatively, wish to override the compiler or linker +flags returned by pcre-config, you may set PCRE_LIBS and PCRE_CFLAGS variables +to be used instead. And if you don't have PCRE at all, the configure script +will provide instructions for obtaining it. +

    + +

    +To build and install SWIG, simply type the following: +

    + +
    +$ ./configure
    +$ make
    +$ make install
    +
    + +

    +By default SWIG installs itself in /usr/local. If you need to install SWIG in +a different location or in your home directory, use the --prefix option +to ./configure. For example: +

    + +
    +$ ./configure --prefix=/home/yourname/projects
    +$ make
    +$ make install
    +
    + +

    +Note: the directory given to --prefix must be an absolute pathname. Do not use +the ~ shell-escape to refer to your home directory. SWIG won't work properly +if you do this. +

    + +

    +The INSTALL file shipped in the top level directory details more about using configure. Also try +

    + +
    +$ ./configure --help.
    +
    + +

    +The configure script will attempt to locate various packages on your machine +including Tcl, Perl5, Python and all the other target languages that SWIG +supports. Don't panic if you get 'not found' messages -- SWIG does not need these +packages to compile or run. The configure script is actually looking for +these packages so that you can try out the SWIG examples contained +in the 'Examples' directory without having to hack Makefiles. +Note that the --without-xxx options, where xxx is a target language, have +minimal effect. All they do is reduce the amount of testing done with +'make check'. The SWIG executable and library files installed cannot currently +be configured with a subset of target languages. +

    + +

    +SWIG used to include a set of runtime libraries for some languages for working +with multiple modules. These are no longer built during the installation stage. +However, users can build them just like any wrapper module as described in +the Modules chapter. +The CHANGES file shipped with SWIG in the top level directory +also lists some examples which build the runtime library. +

    + +

    +Note: +

    + +
      +
    • +If you checked the code out via Git, you will have to run ./autogen.sh +before ./configure. In addition, a full build of SWIG requires +a number of packages to be installed. Full instructions at +SWIG bleeding edge. +
    • +
    + +

    1.12.3 Macintosh OS X installation

    + + +

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

    + +

    +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 +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 +technique for building larger extension modules. Instead, you should utilize +Darwin's two-level namespaces. Some details about this can be found here + +http://developer.apple.com/documentation/ReleaseNotes/DeveloperTools/TwoLevelNamespaces.html. + +

    + +

    +Needless to say, you might have to experiment a bit to get things working at first. +

    + +

    1.12.4 Testing

    + + +

    +If you want to test SWIG after building it, a check can be performed on Unix operating systems. +Type the following: +

    + +
    +    $ make -k check
    +
    + +

    +This step can be performed either before or after installation. +The check requires at least one of the target languages to be +installed. If it fails, it may mean that you have an uninstalled +language module or that the file 'Examples/Makefile' has been +incorrectly configured. It may also fail due to compiler issues such +as a broken C++ compiler. Even if the check fails, there is a +pretty good chance SWIG still works correctly --- you will just have to +mess around with one of the examples and some makefiles to get it to work. +Some tests may also fail due to missing dependency packages, eg PCRE +or Boost, but this will require careful analysis of the configure output +done during configuration. +

    + +

    +The test suite executed by the check is designed to stress-test +many parts of the implementation including obscure corner cases. If some +of these tests fail or generate warning messages, there is no reason for +alarm --- the test may be related to some new SWIG feature or a difficult bug +that we're trying to resolve. Chances are that SWIG will work just fine +for you. Note that if you have more than one CPU/core, then you can use +parallel make to speed up the check as it does take quite some time to run, +for example: +

    + +
    +    $ make -j2 -k check
    +
    + +

    +Also, SWIG's support for C++ is sufficiently advanced that certain +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 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. +

    + +

    1.12.5 Examples

    + + +

    +The Examples directory contains a variety of examples of using SWIG +and it has some browsable documentation. Simply point your browser to +the file "Example/index.html". +

    + +

    +The Examples directory also includes Visual C++ project 6 (.dsp) files for +building some of the examples on Windows. Later versions of Visual Studio +will convert these old style project files into a current solution file. +

    + diff --git a/README b/README index 6df8a4fbd..444643a0d 100644 --- a/README +++ b/README @@ -65,128 +65,17 @@ 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 -==================== -Please see the Doc/Manual/Windows.html file for instructions on installing -SWIG on Windows and running the examples. The Windows distribution is -called swigwin and includes a prebuilt SWIG executable, swig.exe, included in -the same directory as this README file. Otherwise it is exactly the same as -the main SWIG distribution. There is no need to download anything else. - -Unix Installation -================= -You must use GNU `make' to build SWIG. - -http://www.gnu.org/software/make/ - -PCRE needs to be installed on your system to build SWIG, in particular -pcre-config must be available. If you have PCRE headers and libraries but not -pcre-config itself or, alternatively, wish to override the compiler or linker -flags returned by pcre-config, you may set PCRE_LIBS and PCRE_CFLAGS variables -to be used instead. And if you don't have PCRE at all, the configure script -will provide instructions for obtaining it. - -To build and install SWIG, simply type the following: - - % ./configure - % make - % make install - -By default SWIG installs itself in /usr/local. If you need to install SWIG in -a different location or in your home directory, use the --prefix option -to ./configure. For example: - - % ./configure --prefix=/home/yourname/projects - % make - % make install - -Note: the directory given to --prefix must be an absolute pathname. Do *NOT* use -the ~ shell-escape to refer to your home directory. SWIG won't work properly -if you do this. - -The file INSTALL details more about using configure. Also try - - % ./configure --help. - -The configure script will attempt to locate various packages on your machine -including Tcl, Perl5, Python and all the other target languages that SWIG -uses. Don't panic if you get 'not found' messages--SWIG does not need these -packages to compile or run. The configure script is actually looking for -these packages so that you can try out the SWIG examples contained -in the 'Examples' directory without having to hack Makefiles. -Note that the --without-xxx options, where xxx is a target language, have -minimal effect. All they do is reduce the amount of testing done with -'make check'. The SWIG executable and library files installed cannot currently -be configured with a subset of target languages. - -SWIG used to include a set of runtime libraries for some languages for working -with multiple modules. These are no longer built during the installation stage. -However, users can build them just like any wrapper module as described in -the documentation, Doc/Manual/Modules.html. The CHANGES file also lists some -examples which build the runtime library. - -Notes: - -(1) If you checked the code out via Git, you will have to run ./autogen.sh - 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 -============================ -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. - -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 -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 -technique for building larger extension modules. Instead, you should utilize -Darwin's two-level namespaces. Some details about this can be found here - -http://developer.apple.com/documentation/ReleaseNotes/DeveloperTools/TwoLevelNamespaces.html - -Needless to say, you might have to experiment a bit to get things working at first. +Installation +============ +Please read the Doc/Manual/Preface.html#Preface_installation for +full installation instructions for Windows, Unix and Mac OS X. +The INSTALL file has generic build and installation instructions for +Unix users. Testing ======= -If you want to test SWIG before installation, type the following: - - % make -k check - -'make -k check' requires at least one of the target languages to be -installed. If it fails, it may mean that you have an uninstalled -language module or that the file 'Examples/Makefile' has been -incorrectly configured. It may also fail due to compiler issues such -as broken C++ compiler. Even if 'make -k check' fails, there is a -pretty good chance SWIG still works correctly---you will just have to -mess around with one of the examples and some makefiles to get it to work. -Some tests may also fail due to missing dependency packages, eg PCRE -or Boost, but this will require careful analysis of the configure output. - -The testing suite executed by 'make -k check' is designed to stress-test -many parts of the implementation including obscure corner cases. If some -of these tests fail or generate warning messages, there is no reason for -alarm---the test may be related to some new SWIG feature or a difficult bug -that we're trying to resolve. Chances are that SWIG will work just fine -for you. Note that if you have more than one CPU/core, then you can use -parallel make to speed up the check as it does take quite some time to run, -for example: - - % make -j2 -k check - -Also, SWIG's support for C++ is sufficiently advanced that certain -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 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. +The typical 'make -k check' can be performed on Unix operating systems. +Please read Doc/Manual/Preface.html#Preface_testing for details. Examples ======== @@ -208,7 +97,7 @@ Troubleshooting In order to operate correctly, SWIG relies upon a set of library files. If after building SWIG, you get error messages like this, - % swig foo.i + $ swig foo.i :1. Unable to find 'swig.swg' :3. Unable to find 'tcl8.swg' From 13e76c30b32b028620ecde8a17861e6629304458 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 2 May 2013 19:30:04 +0100 Subject: [PATCH 0597/1160] Fixes looking for Guile in configure.ac --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 1fcdadfca..e4a6b79bc 100644 --- a/configure.ac +++ b/configure.ac @@ -1201,7 +1201,7 @@ else AC_PATH_PROG(PKG_CONFIG,pkgconfig) fi if test "x$PKG_CONFIG" = x; then - AC_MSG_NOTICE([Could not find the pkg-config (or pkgconfig) program required to set up Guile. Disabling Guile],) + AC_MSG_NOTICE([Could not find the pkg-config (or pkgconfig) program required to set up Guile. Disabling Guile.]) GUILE= GUILE_CFLAGS= GUILE_LIBS="" @@ -1220,11 +1220,11 @@ else GUILE_SERIES="" PKG_CHECK_MODULES(GUILE, [guile-1.8], [ GUILE_SERIES="18" ], [ PKG_CHECK_MODULES(GUILE, [guile-2.0], [GUILE_SERIES="20" ], [AC_MSG_NOTICE([ - Only Guile 1.8 or 2.0 is supported. Neither version appears to be installed correctly. Disabling Guile + Only Guile 1.8 or 2.0 is supported. Neither version appears to be installed correctly. Disabling Guile. ])]) ]) - if test "x$GUILE-SERIES" = x; then + if test "x$GUILE_SERIES" = x; then GUILE= GUILE_CFLAGS= GUILE_LIBS= From ca7b77cbd187a6532ea5a49bcab54b5aeaa19b74 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 3 May 2013 12:22:43 +0100 Subject: [PATCH 0598/1160] Fix tcl operator example crashing when run The example was accessing deleted memory and so sometimes crashed. --- Examples/tcl/operator/runme.tcl | 3 --- 1 file changed, 3 deletions(-) diff --git a/Examples/tcl/operator/runme.tcl b/Examples/tcl/operator/runme.tcl index 3b7c06838..921645536 100644 --- a/Examples/tcl/operator/runme.tcl +++ b/Examples/tcl/operator/runme.tcl @@ -9,11 +9,9 @@ puts "a = $a [$a str]" puts "b = $b [$b str]" set c [$a + $b] -Complex -this $c puts "c = $c [$c str]" set d [$a * $b] -Complex -this $d puts "a*b = [$d str]" # Alternative calling convention @@ -21,7 +19,6 @@ set e [Complex_- $a $c] puts "a-c = [Complex_str $e]" set f [new_ComplexCopy $e] -Complex -this $f puts "f = [$f str]" # Call assignment operator From f68cde8bb9a568b3285df81fbb7b33b9d3d45328 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 3 May 2013 15:29:07 +0100 Subject: [PATCH 0599/1160] Fix li_std_containers_int test case for Python < 2.6 Workaround bugs in older versions of Python --- .../test-suite/python/li_std_containers_int_runme.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/python/li_std_containers_int_runme.py b/Examples/test-suite/python/li_std_containers_int_runme.py index 7611ee63e..f18e33812 100644 --- a/Examples/test-suite/python/li_std_containers_int_runme.py +++ b/Examples/test-suite/python/li_std_containers_int_runme.py @@ -1,6 +1,7 @@ # Check std::vector and std::list behaves the same as Python iterable types (list) from li_std_containers_int import * +import sys def failed(a, b, msg): raise RuntimeError, msg + " " + str(list(a)) + " " + str(list(b)) @@ -76,10 +77,13 @@ def container_insert_step(i, j, step, newval): except IndexError, e: il_error = e - if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))): - raise RuntimeError, "ValueError exception not consistently thrown: " + str(ps_error) + " " + str(iv_error) + " " + str(il_error) + # Python 2.6 contains bug fixes in extended slicing syntax: http://docs.python.org/2/whatsnew/2.6.html + skip_check = ps_error != None and(iv_error == il_error == None) and step > 0 and (sys.version[0:2] < (2, 6)) + if not(skip_check): + if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))): + raise RuntimeError, "ValueError exception not consistently thrown: " + str(ps_error) + " " + str(iv_error) + " " + str(il_error) - compare_containers(ps, iv, il) + compare_containers(ps, iv, il) # Check std::vector and std::list delete behaves same as Python list delete including exceptions From 4ed422da6050b5004a14f31ab5caa9e012b99a78 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 7 May 2013 21:11:03 +0100 Subject: [PATCH 0600/1160] Revert guile configure to use guile-config Replace pkg-config with guile-config to look for guile. Using pkg-config requires the pkg.m4 autoconf macros to be properly installed on the machine running autogen.sh which is frequently a problem. pkg-config only supports more recent releases of guile so isn't very good at finding guile either. --- configure.ac | 116 +++++++++++++-------------------------------------- 1 file changed, 29 insertions(+), 87 deletions(-) diff --git a/configure.ac b/configure.ac index e4a6b79bc..07a768469 100644 --- a/configure.ac +++ b/configure.ac @@ -1176,8 +1176,10 @@ GUILE= GUILE_CFLAGS= GUILE_LIBS= -AC_ARG_WITH(guile, AS_HELP_STRING([--without-guile], [Disable Guile]) -AS_HELP_STRING([--with-guile=path], [Set location of Guile executable]),[GUILE="$withval"], [GUILE=yes]) +AC_ARG_WITH(guile-config, AS_HELP_STRING([--without-guile], [Disable Guile]) + AS_HELP_STRING([--with-guile-config=path], [Set location of guile-config]),[ GUILE_CONFIG="$withval"], [GUILE_CONFIG=]) +AC_ARG_WITH(guile,[ --with-guile=path Set location of Guile executable],[ + GUILE="$withval"], [GUILE=yes]) AC_ARG_WITH(guile-cflags,[ --with-guile-cflags=cflags Set cflags required to compile against Guile],[ GUILE_CFLAGS="$withval"]) AC_ARG_WITH(guile-libs,[ --with-guile-libs=ldflags Set ldflags needed to link with Guile],[ @@ -1186,95 +1188,35 @@ AC_ARG_WITH(guile-libs,[ --with-guile-libs=ldflags Set ldflags needed to lin # First, check for "--without-guile" or "--with-guile=no". if test x"${GUILE}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling Guile]) - GUILE= - GUILE_CFLAGS= - GUILE_LIBS= else - - # Use pkg-config to find guile specific config parameters - # Note: if guile is not installed in a standard system path - # you can set the environment variable PKG_CONFIG_PATH to - # the directory where the guile package config file is stored - AC_PATH_PROG(PKG_CONFIG,pkg-config) - if test "x$PKG_CONFIG" = x; then - # @*%&$ Ximian programmers renamed this application - AC_PATH_PROG(PKG_CONFIG,pkgconfig) + if test -z "$GUILE_CONFIG" ; then + AC_PATH_PROG(GUILE_CONFIG, guile-config) fi - if test "x$PKG_CONFIG" = x; then - AC_MSG_NOTICE([Could not find the pkg-config (or pkgconfig) program required to set up Guile. Disabling Guile.]) - GUILE= - GUILE_CFLAGS= - GUILE_LIBS="" - else - - # If the user has given these values, cache them to override the - # detected values. - if test "x$GUILE_LIBS" != x; then - saved_GUILE_LIBS="$GUILE_LIBS" - fi - if test "x$GUILE_CFLAGS" != x; then - saved_GUILE_CFLAGS="$GUILE_CFLAGS" + if test -n "$GUILE_CONFIG" ; then + if test x"$GUILE" = xyes; then + AC_MSG_CHECKING([for guile bindir]) + guile_bindir="`$GUILE_CONFIG info bindir`" + AC_MSG_RESULT([$guile_bindir]) + GUILE=$guile_bindir/guile + if ! test -f "$GUILE" ; then + GUILE= + AC_PATH_PROG(GUILE, guile) + fi fi - # Look up GUILE_CFLAGS and GUILE_LIBS, and version check - GUILE_SERIES="" - PKG_CHECK_MODULES(GUILE, [guile-1.8], [ GUILE_SERIES="18" ], [ - PKG_CHECK_MODULES(GUILE, [guile-2.0], [GUILE_SERIES="20" ], [AC_MSG_NOTICE([ - Only Guile 1.8 or 2.0 is supported. Neither version appears to be installed correctly. Disabling Guile. - ])]) - ]) - - if test "x$GUILE_SERIES" = x; then - GUILE= - GUILE_CFLAGS= - GUILE_LIBS= - else - # Look up GUILE executable - if test "x$GUILE" = xyes; then - GUILE= - if test "$xGUILE_SERIES" = "x18"; then - AC_PATH_PROG(GUILE18, guile-1.8) - if test "x$GUILE18" != x; then - GUILE="$GUILE18" - fi - fi - if test "$xGUILE_SERIES" = "x20"; then - AC_PATH_PROG(GUILE20, guile-2.0) - if test "x$GUILE20" != x; then - GUILE="$GUILE20" - fi - fi - if test "x$GUILE" = x; then - AC_PATH_PROG(GUILE, guile) - fi - fi - - if test "x$saved_GUILE_LIBS" != x; then - GUILE_LIBS="$saved_GUILE_LIBS" - fi - if test "x$saved_GUILE_CFLAGS" != x; then - GUILE_CFLAGS="$saved_GUILE_CFLAGS" - fi - - guilesafe_CFLAGS=$CFLAGS - guilesafe_LIBS=$LIBS - # Filter out "-ansi -pedantic" because Guile header files will not compile with these flags. - # (The flags -ansi -pedantic are automatically added by ac_compile_warnings.m4) - CFLAGS="`echo $CFLAGS | sed 's/-ansi//g;s/-pedantic//g;'` $GUILE_CFLAGS" - LIBS="$LIBS $GUILE_LIBS" - - AC_MSG_CHECKING(whether Guile/SCM_ API works) - AC_LINK_IFELSE([AC_LANG_SOURCE([#include - int main() { SCM s; scm_slot_exists_p(SCM_BOOL_F, SCM_BOOL_F); return SCM_STRING_LENGTH(s); }])], GUILE_SCM_INTERFACE=1, ) - if test -n "$GUILE_SCM_INTERFACE" ; then - AC_MSG_RESULT(yes) - else - AC_MSG_RESULT(no) - fi - - CFLAGS=$guilesafe_CFLAGS - LIBS=$guilesafe_LIBS + if test -z "$GUILE_CFLAGS" ; then + AC_MSG_CHECKING([for guile compile flags]) + GUILE_CFLAGS="`$GUILE_CONFIG compile`" + AC_MSG_RESULT([$GUILE_CFLAGS]) fi + + if test -z "$GUILE_LIBS" ; then + AC_MSG_CHECKING([for guile link flags]) + GUILE_LIBS="`$GUILE_CONFIG link`" + AC_MSG_RESULT([$GUILE_LIBS]) + fi + + GUILE_SCM_INTERFACE=1 fi fi @@ -2281,7 +2223,7 @@ AC_SUBST(SKIP_JAVA) SKIP_GUILE= -if test -z "$GUILE_CFLAGS" || test -z "$GUILE_LIBS" || test -z "$GUILE_SCM_INTERFACE"; then +if test -z "$GUILE" || test -z "$GUILE_CFLAGS" || test -z "$GUILE_LIBS" || test -z "$GUILE_SCM_INTERFACE"; then SKIP_GUILE="1" fi AC_SUBST(SKIP_GUILE) From 70b9df5ee9513f263758b1b491c00f20e6e7adaf Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 8 May 2013 12:42:17 +0100 Subject: [PATCH 0601/1160] Portable dynamic library loading for Guile dynamic-link and load-extension work without passing the .so or .dll as the shared library extension, so these have been dropped so the examples and test-suite work on Cygwin. Also update documentation and use the 'lib' prefix as that is what we commonly name the shared libraries. --- Doc/Manual/Guile.html | 34 ++++++++++++------- Examples/guile/multimap/runme.scm | 2 +- Examples/test-suite/guile/casts_runme.scm | 2 +- .../test-suite/guile/char_constant_runme.scm | 2 +- .../test-suite/guile/class_ignore_runme.scm | 2 +- Examples/test-suite/guile/constover_runme.scm | 2 +- Examples/test-suite/guile/contract_runme.scm | 2 +- Examples/test-suite/guile/cpp_enum_runme.scm | 2 +- .../test-suite/guile/cpp_namespace_runme.scm | 2 +- .../test-suite/guile/dynamic_cast_runme.scm | 2 +- .../test-suite/guile/guile_ext_test_runme.scm | 2 +- .../guile/import_nomodule_runme.scm | 2 +- Examples/test-suite/guile/imports_runme.scm | 4 +-- .../guile/inherit_missing_runme.scm | 2 +- Examples/test-suite/guile/integers_runme.scm | 2 +- .../test-suite/guile/li_std_string_runme.scm | 2 +- .../test-suite/guile/li_typemaps_runme.scm | 2 +- .../test-suite/guile/list_vector_runme.scm | 2 +- .../test-suite/guile/multivalue_runme.scm | 2 +- Examples/test-suite/guile/name_runme.scm | 2 +- .../guile/overload_complicated_runme.scm | 2 +- .../test-suite/guile/overload_copy_runme.scm | 2 +- .../guile/overload_extend_runme.scm | 2 +- .../guile/overload_simple_runme.scm | 2 +- .../guile/overload_subtype_runme.scm | 2 +- .../test-suite/guile/pointer_in_out_runme.scm | 2 +- .../guile/reference_global_vars_runme.scm | 2 +- .../guile/throw_exception_runme.scm | 2 +- .../guile/typedef_inherit_runme.scm | 2 +- Examples/test-suite/guile/typename_runme.scm | 4 +-- Examples/test-suite/guile/unions_runme.scm | 2 +- 31 files changed, 54 insertions(+), 44 deletions(-) diff --git a/Doc/Manual/Guile.html b/Doc/Manual/Guile.html index 8ecdf249c..cfbfbd0b7 100644 --- a/Doc/Manual/Guile.html +++ b/Doc/Manual/Guile.html @@ -115,7 +115,7 @@ libraries into Guile.

     (define-module (my module))
    -(define my-so (dynamic-link "./example.so"))
    +(define my-so (dynamic-link "./libexample.so"))
     (dynamic-call "SWIG_init" my-so) ; make SWIG bindings
     ;; Scheme definitions can go here
     
    @@ -128,7 +128,17 @@ and dynamic-call:
    -(load-extension "./example.so" "SWIG_init")
    +(load-extension "./libexample.so" "SWIG_init")
    +
    +
    + +

    +A more portable approach would be to drop the shared library extension: +

    + +
    +
    +(load-extension "./libexample" "SWIG_init")
     
    @@ -171,7 +181,7 @@ information by including a directive like this in the interface file:
    -%scheme %{ (load-extension "./example.so" "SWIG_init") %}
    +%scheme %{ (load-extension "./libexample.so" "SWIG_init") %}
     
    @@ -225,7 +235,7 @@ shared libraries into Guile; all bindings are automatically put in newly created Guile modules.
    -(define my-so (dynamic-link "./foo.so"))
    +(define my-so (dynamic-link "./libfoo.so"))
     ;; create new module and put bindings there:
     (dynamic-call "scm_init_my_modules_foo_module" my-so) 
     
    @@ -233,7 +243,7 @@ newly created Guile modules. Newer Guile versions have a shorthand procedure for this:
    -(load-extension "./foo.so" "scm_init_my_modules_foo_module")
    +(load-extension "./libfoo.so" "scm_init_my_modules_foo_module")
     
    @@ -768,10 +778,10 @@ and might conflict with names from the GOOPS guile-module (see above). Pass the argument to solve this problem. If the -exportprimitive option is passed to SWIG the (export ...) code that would be exported into the scmstub file is exported at the bottom of the generated GOOPS guile-module. -The %goops directive should contain code to load the .so library. +The %goops directive should contain code to load the shared library.
    -%goops %{ (load-extension "./foo.so" "scm_init_my_modules_foo_module") %}
    +%goops %{ (load-extension "./libfoo.so" "scm_init_my_modules_foo_module") %}
     

    @@ -783,7 +793,7 @@ Produces the following code at the top of the generated GOOPS guile-module (define-module (my modules foo)) ;; %goops directive goes here -(load-extension "./foo.so" "scm_init_my_modules_foo_module") +(load-extension "./libfoo.so" "scm_init_my_modules_foo_module") (use-modules (oop goops) (Swig common))

    @@ -791,7 +801,7 @@ Produces the following code at the top of the generated GOOPS guile-module
  • Passive Linkage with -scmstub: Here, the name of the scmstub file should be Module-primitive.scm (with primitive replaced with whatever is given with the -primsuffix -argument. The code to load the .so library should be located in the %scheme directive, +argument. The code to load the shared library should be located in the %scheme directive, which will then be added to the scmstub file. SWIG will automatically generate the line (use-modules (Package Module-primitive)) into the GOOPS guile-module. So if Module-primitive.scm is on the autoload path for guile, the @@ -799,7 +809,7 @@ into the GOOPS guile-module. So if Module-primitive.scm is on the autolo whatever code is needed to load the Module-primitive.scm file into guile.

    -%scheme %{ (load-extension "./foo.so" "scm_init_my_modules_foo_module") %}
    +%scheme %{ (load-extension "./libfoo.so" "scm_init_my_modules_foo_module") %}
     // only include the following definition if (my modules foo) cannot
     // be loaded automatically
     %goops %{ 
    @@ -832,7 +842,7 @@ SWIG will also automatically generate the line (use-modules
     directive should contain whatever code is needed to get that module loaded into guile.

    -%goops %{ (load-extension "./foo.so" "scm_init_my_modules_foo_module") %}
    +%goops %{ (load-extension "./libfoo.so" "scm_init_my_modules_foo_module") %}
     

    @@ -843,7 +853,7 @@ Produces the following code at the top of the generated GOOPS guile-module (define-module (my modules foo)) ;; %goops directive goes here (if any) -(load-extension "./foo.so" "scm_init_my_modules_foo_module") +(load-extension "./libfoo.so" "scm_init_my_modules_foo_module") (use-modules (oop goops) (Swig common)) (use-modules ((my modules foo-primitive) :renamer (symbol-prefix-proc diff --git a/Examples/guile/multimap/runme.scm b/Examples/guile/multimap/runme.scm index 1654fd3a8..d2ab8036e 100644 --- a/Examples/guile/multimap/runme.scm +++ b/Examples/guile/multimap/runme.scm @@ -1,6 +1,6 @@ ;;; Test out some multi-argument typemaps -(dynamic-call "scm_init_example_module" (dynamic-link "./libexample.so")) +(dynamic-call "scm_init_example_module" (dynamic-link "./libexample")) ; Call the GCD function diff --git a/Examples/test-suite/guile/casts_runme.scm b/Examples/test-suite/guile/casts_runme.scm index 7a0a0420b..5f22e7f86 100644 --- a/Examples/test-suite/guile/casts_runme.scm +++ b/Examples/test-suite/guile/casts_runme.scm @@ -1,5 +1,5 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_casts_module" (dynamic-link "./libcasts.so")) +(dynamic-call "scm_init_casts_module" (dynamic-link "./libcasts")) (load "../schemerunme/casts.scm") diff --git a/Examples/test-suite/guile/char_constant_runme.scm b/Examples/test-suite/guile/char_constant_runme.scm index d183b35e5..7061acdb1 100644 --- a/Examples/test-suite/guile/char_constant_runme.scm +++ b/Examples/test-suite/guile/char_constant_runme.scm @@ -1,5 +1,5 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_char_constant_module" (dynamic-link "./libchar_constant.so")) +(dynamic-call "scm_init_char_constant_module" (dynamic-link "./libchar_constant")) (load "../schemerunme/char_constant.scm") diff --git a/Examples/test-suite/guile/class_ignore_runme.scm b/Examples/test-suite/guile/class_ignore_runme.scm index b3229f85c..3ace843cb 100644 --- a/Examples/test-suite/guile/class_ignore_runme.scm +++ b/Examples/test-suite/guile/class_ignore_runme.scm @@ -1,2 +1,2 @@ -(dynamic-call "scm_init_class_ignore_module" (dynamic-link "./libclass_ignore.so")) +(dynamic-call "scm_init_class_ignore_module" (dynamic-link "./libclass_ignore")) (load "../schemerunme/class_ignore.scm") diff --git a/Examples/test-suite/guile/constover_runme.scm b/Examples/test-suite/guile/constover_runme.scm index 1ab42d349..15e822fc2 100644 --- a/Examples/test-suite/guile/constover_runme.scm +++ b/Examples/test-suite/guile/constover_runme.scm @@ -1,2 +1,2 @@ -(dynamic-call "scm_init_constover_module" (dynamic-link "./libconstover.so")) +(dynamic-call "scm_init_constover_module" (dynamic-link "./libconstover")) (load "../schemerunme/constover.scm") diff --git a/Examples/test-suite/guile/contract_runme.scm b/Examples/test-suite/guile/contract_runme.scm index ea80e321c..b31c9e9e7 100644 --- a/Examples/test-suite/guile/contract_runme.scm +++ b/Examples/test-suite/guile/contract_runme.scm @@ -1,6 +1,6 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_contract_module" (dynamic-link "./libcontract.so")) +(dynamic-call "scm_init_contract_module" (dynamic-link "./libcontract")) (load "testsuite.scm") (load "../schemerunme/contract.scm") diff --git a/Examples/test-suite/guile/cpp_enum_runme.scm b/Examples/test-suite/guile/cpp_enum_runme.scm index 5a2d9f048..bf365e878 100644 --- a/Examples/test-suite/guile/cpp_enum_runme.scm +++ b/Examples/test-suite/guile/cpp_enum_runme.scm @@ -1,5 +1,5 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_cpp_enum_module" (dynamic-link "./libcpp_enum.so")) +(dynamic-call "scm_init_cpp_enum_module" (dynamic-link "./libcpp_enum")) (load "../schemerunme/cpp_enum.scm") diff --git a/Examples/test-suite/guile/cpp_namespace_runme.scm b/Examples/test-suite/guile/cpp_namespace_runme.scm index 2a871de24..a1f6cd4ca 100644 --- a/Examples/test-suite/guile/cpp_namespace_runme.scm +++ b/Examples/test-suite/guile/cpp_namespace_runme.scm @@ -1,2 +1,2 @@ -(dynamic-call "scm_init_cpp_namespace_module" (dynamic-link "./libcpp_namespace.so")) +(dynamic-call "scm_init_cpp_namespace_module" (dynamic-link "./libcpp_namespace")) (load "../schemerunme/cpp_namespace.scm") diff --git a/Examples/test-suite/guile/dynamic_cast_runme.scm b/Examples/test-suite/guile/dynamic_cast_runme.scm index 7b70001d0..f69f6165a 100644 --- a/Examples/test-suite/guile/dynamic_cast_runme.scm +++ b/Examples/test-suite/guile/dynamic_cast_runme.scm @@ -1,2 +1,2 @@ -(dynamic-call "scm_init_dynamic_cast_module" (dynamic-link "./libdynamic_cast.so")) +(dynamic-call "scm_init_dynamic_cast_module" (dynamic-link "./libdynamic_cast")) (load "../schemerunme/dynamic_cast.scm") diff --git a/Examples/test-suite/guile/guile_ext_test_runme.scm b/Examples/test-suite/guile/guile_ext_test_runme.scm index 452b08ee7..dd98580cf 100644 --- a/Examples/test-suite/guile/guile_ext_test_runme.scm +++ b/Examples/test-suite/guile/guile_ext_test_runme.scm @@ -1,4 +1,4 @@ -(dynamic-call "scm_init_guile_ext_test_module" (dynamic-link "./libguile_ext_test.so")) +(dynamic-call "scm_init_guile_ext_test_module" (dynamic-link "./libguile_ext_test")) ; This is a test for SF Bug 1573892 ; If IsPointer is called before TypeQuery, the test-is-pointer will fail diff --git a/Examples/test-suite/guile/import_nomodule_runme.scm b/Examples/test-suite/guile/import_nomodule_runme.scm index ffb2474fc..72f8b3a62 100644 --- a/Examples/test-suite/guile/import_nomodule_runme.scm +++ b/Examples/test-suite/guile/import_nomodule_runme.scm @@ -1,2 +1,2 @@ -(dynamic-call "scm_init_import_nomodule_module" (dynamic-link "./libimport_nomodule.so")) +(dynamic-call "scm_init_import_nomodule_module" (dynamic-link "./libimport_nomodule")) (load "../schemerunme/import_nomodule.scm") diff --git a/Examples/test-suite/guile/imports_runme.scm b/Examples/test-suite/guile/imports_runme.scm index 2fda017ce..c319a4bae 100644 --- a/Examples/test-suite/guile/imports_runme.scm +++ b/Examples/test-suite/guile/imports_runme.scm @@ -6,6 +6,6 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_imports_a_module" (dynamic-link "./libimports_a.so")) -(dynamic-call "scm_init_imports_b_module" (dynamic-link "./libimports_b.so")) +(dynamic-call "scm_init_imports_a_module" (dynamic-link "./libimports_a")) +(dynamic-call "scm_init_imports_b_module" (dynamic-link "./libimports_b")) (load "../schemerunme/imports.scm") diff --git a/Examples/test-suite/guile/inherit_missing_runme.scm b/Examples/test-suite/guile/inherit_missing_runme.scm index 97e950cb2..ec02e7d42 100644 --- a/Examples/test-suite/guile/inherit_missing_runme.scm +++ b/Examples/test-suite/guile/inherit_missing_runme.scm @@ -1,2 +1,2 @@ -(dynamic-call "scm_init_inherit_missing_module" (dynamic-link "./libinherit_missing.so")) +(dynamic-call "scm_init_inherit_missing_module" (dynamic-link "./libinherit_missing")) (load "../schemerunme/inherit_missing.scm") diff --git a/Examples/test-suite/guile/integers_runme.scm b/Examples/test-suite/guile/integers_runme.scm index 14ec8b0fe..7b4c9dc13 100644 --- a/Examples/test-suite/guile/integers_runme.scm +++ b/Examples/test-suite/guile/integers_runme.scm @@ -1,7 +1,7 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_integers_module" (dynamic-link "./libintegers.so")) +(dynamic-call "scm_init_integers_module" (dynamic-link "./libintegers")) (define-macro (throws-exception? form) `(catch #t diff --git a/Examples/test-suite/guile/li_std_string_runme.scm b/Examples/test-suite/guile/li_std_string_runme.scm index 05b74cd65..5dde68f8d 100644 --- a/Examples/test-suite/guile/li_std_string_runme.scm +++ b/Examples/test-suite/guile/li_std_string_runme.scm @@ -1,5 +1,5 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_li_std_string_module" (dynamic-link "./libli_std_string.so")) +(dynamic-call "scm_init_li_std_string_module" (dynamic-link "./libli_std_string")) (load "../schemerunme/li_std_string.scm") diff --git a/Examples/test-suite/guile/li_typemaps_runme.scm b/Examples/test-suite/guile/li_typemaps_runme.scm index 9824fc98e..269455ce5 100644 --- a/Examples/test-suite/guile/li_typemaps_runme.scm +++ b/Examples/test-suite/guile/li_typemaps_runme.scm @@ -4,7 +4,7 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_li_typemaps_module" (dynamic-link "./libli_typemaps.so")) +(dynamic-call "scm_init_li_typemaps_module" (dynamic-link "./libli_typemaps")) (load "../schemerunme/li_typemaps.scm") (let ((lst (inoutr-int2 3 -2))) diff --git a/Examples/test-suite/guile/list_vector_runme.scm b/Examples/test-suite/guile/list_vector_runme.scm index 546d8a1ba..2025b53d5 100644 --- a/Examples/test-suite/guile/list_vector_runme.scm +++ b/Examples/test-suite/guile/list_vector_runme.scm @@ -1,5 +1,5 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_list_vector_module" (dynamic-link "./liblist_vector.so")) +(dynamic-call "scm_init_list_vector_module" (dynamic-link "./liblist_vector")) (load "../schemerunme/list_vector.scm") diff --git a/Examples/test-suite/guile/multivalue_runme.scm b/Examples/test-suite/guile/multivalue_runme.scm index d1d7fbfe7..1717e4ef4 100644 --- a/Examples/test-suite/guile/multivalue_runme.scm +++ b/Examples/test-suite/guile/multivalue_runme.scm @@ -3,5 +3,5 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_multivalue_module" (dynamic-link "./libmultivalue.so")) +(dynamic-call "scm_init_multivalue_module" (dynamic-link "./libmultivalue")) (load "../schemerunme/multivalue.scm") diff --git a/Examples/test-suite/guile/name_runme.scm b/Examples/test-suite/guile/name_runme.scm index 831c20610..7de0e54bf 100644 --- a/Examples/test-suite/guile/name_runme.scm +++ b/Examples/test-suite/guile/name_runme.scm @@ -1,5 +1,5 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_name_module" (dynamic-link "./libname.so")) +(dynamic-call "scm_init_name_module" (dynamic-link "./libname")) (load "../schemerunme/name.scm") diff --git a/Examples/test-suite/guile/overload_complicated_runme.scm b/Examples/test-suite/guile/overload_complicated_runme.scm index 3c2b80dbf..a38fb8afe 100644 --- a/Examples/test-suite/guile/overload_complicated_runme.scm +++ b/Examples/test-suite/guile/overload_complicated_runme.scm @@ -1,7 +1,7 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_overload_complicated_module" (dynamic-link "./liboverload_complicated.so")) +(dynamic-call "scm_init_overload_complicated_module" (dynamic-link "./liboverload_complicated")) (define-macro (check form) `(if (not ,form) diff --git a/Examples/test-suite/guile/overload_copy_runme.scm b/Examples/test-suite/guile/overload_copy_runme.scm index 9b93aeb8a..f6a90a57f 100644 --- a/Examples/test-suite/guile/overload_copy_runme.scm +++ b/Examples/test-suite/guile/overload_copy_runme.scm @@ -1,2 +1,2 @@ -(dynamic-call "scm_init_overload_copy_module" (dynamic-link "./liboverload_copy.so")) +(dynamic-call "scm_init_overload_copy_module" (dynamic-link "./liboverload_copy")) (load "../schemerunme/overload_copy.scm") diff --git a/Examples/test-suite/guile/overload_extend_runme.scm b/Examples/test-suite/guile/overload_extend_runme.scm index cb0223dea..f31465891 100644 --- a/Examples/test-suite/guile/overload_extend_runme.scm +++ b/Examples/test-suite/guile/overload_extend_runme.scm @@ -1,2 +1,2 @@ -(dynamic-call "scm_init_overload_extend_module" (dynamic-link "./liboverload_extend.so")) +(dynamic-call "scm_init_overload_extend_module" (dynamic-link "./liboverload_extend")) (load "../schemerunme/overload_extend.scm") diff --git a/Examples/test-suite/guile/overload_simple_runme.scm b/Examples/test-suite/guile/overload_simple_runme.scm index 993a5f30f..8e3dbb6ba 100644 --- a/Examples/test-suite/guile/overload_simple_runme.scm +++ b/Examples/test-suite/guile/overload_simple_runme.scm @@ -1,5 +1,5 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_overload_simple_module" (dynamic-link "./liboverload_simple.so")) +(dynamic-call "scm_init_overload_simple_module" (dynamic-link "./liboverload_simple")) (load "../schemerunme/overload_simple.scm") diff --git a/Examples/test-suite/guile/overload_subtype_runme.scm b/Examples/test-suite/guile/overload_subtype_runme.scm index 7dfa2c16c..857084d03 100644 --- a/Examples/test-suite/guile/overload_subtype_runme.scm +++ b/Examples/test-suite/guile/overload_subtype_runme.scm @@ -1,5 +1,5 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_overload_subtype_module" (dynamic-link "./liboverload_subtype.so")) +(dynamic-call "scm_init_overload_subtype_module" (dynamic-link "./liboverload_subtype")) (load "../schemerunme/overload_subtype.scm") diff --git a/Examples/test-suite/guile/pointer_in_out_runme.scm b/Examples/test-suite/guile/pointer_in_out_runme.scm index de3522749..da3542866 100644 --- a/Examples/test-suite/guile/pointer_in_out_runme.scm +++ b/Examples/test-suite/guile/pointer_in_out_runme.scm @@ -1,5 +1,5 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_pointer_in_out_module" (dynamic-link "./libpointer_in_out.so")) +(dynamic-call "scm_init_pointer_in_out_module" (dynamic-link "./libpointer_in_out")) (load "../schemerunme/pointer_in_out.scm") diff --git a/Examples/test-suite/guile/reference_global_vars_runme.scm b/Examples/test-suite/guile/reference_global_vars_runme.scm index 8cd31c3e8..dfc9dc634 100644 --- a/Examples/test-suite/guile/reference_global_vars_runme.scm +++ b/Examples/test-suite/guile/reference_global_vars_runme.scm @@ -1,3 +1,3 @@ ; copied from python runme_.py -(dynamic-call "scm_init_reference_global_vars_module" (dynamic-link "./libreference_global_vars.so")) +(dynamic-call "scm_init_reference_global_vars_module" (dynamic-link "./libreference_global_vars")) (load "../schemerunme/reference_global_vars.scm") diff --git a/Examples/test-suite/guile/throw_exception_runme.scm b/Examples/test-suite/guile/throw_exception_runme.scm index 377506276..aa9ff8a5c 100644 --- a/Examples/test-suite/guile/throw_exception_runme.scm +++ b/Examples/test-suite/guile/throw_exception_runme.scm @@ -1,7 +1,7 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_throw_exception_module" (dynamic-link "./libthrow_exception.so")) +(dynamic-call "scm_init_throw_exception_module" (dynamic-link "./libthrow_exception")) (define-macro (check-throw form) `(catch 'swig-exception diff --git a/Examples/test-suite/guile/typedef_inherit_runme.scm b/Examples/test-suite/guile/typedef_inherit_runme.scm index d75d421d5..443e75f1b 100644 --- a/Examples/test-suite/guile/typedef_inherit_runme.scm +++ b/Examples/test-suite/guile/typedef_inherit_runme.scm @@ -1,2 +1,2 @@ -(dynamic-call "scm_init_typedef_inherit_module" (dynamic-link "./libtypedef_inherit.so")) +(dynamic-call "scm_init_typedef_inherit_module" (dynamic-link "./libtypedef_inherit")) (load "../schemerunme/typedef_inherit.scm") diff --git a/Examples/test-suite/guile/typename_runme.scm b/Examples/test-suite/guile/typename_runme.scm index 4243f6974..057033521 100644 --- a/Examples/test-suite/guile/typename_runme.scm +++ b/Examples/test-suite/guile/typename_runme.scm @@ -1,3 +1,3 @@ -(dynamic-call "scm_init_typename_module" (dynamic-link "./libtypename.so")) -;;(dynamic-call "scm_init_types_module" (dynamic-link "./libtypes.so")) +(dynamic-call "scm_init_typename_module" (dynamic-link "./libtypename")) +;;(dynamic-call "scm_init_types_module" (dynamic-link "./libtypes")) (load "../schemerunme/typename.scm") diff --git a/Examples/test-suite/guile/unions_runme.scm b/Examples/test-suite/guile/unions_runme.scm index 867e8a3c3..510a19490 100644 --- a/Examples/test-suite/guile/unions_runme.scm +++ b/Examples/test-suite/guile/unions_runme.scm @@ -4,5 +4,5 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(dynamic-call "scm_init_unions_module" (dynamic-link "./libunions.so")) +(dynamic-call "scm_init_unions_module" (dynamic-link "./libunions")) (load "../schemerunme/unions.scm") From 10acae18d29b3b3d00a83dfed4eddb832da3264c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 8 May 2013 13:05:11 +0100 Subject: [PATCH 0602/1160] Correct Guile Makefile to fix test-suite/examples on Cygwin --- Examples/Makefile.in | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index e57516cf1..a3a2b04c9 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -466,36 +466,22 @@ GUILE_LIBPREFIX = lib GUILE_SCRIPT = $(RUNME).scm #------------------------------------------------------------------ -# Build a dynamically loaded module with passive linkage and the scm interface +# Build a dynamically loaded module with passive linkage #------------------------------------------------------------------ guile: $(SRCS) $(SWIG) -guile -Linkage passive $(SWIGOPT) $(INTERFACEPATH) $(CC) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ISRCS) $(SRCS) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) + $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(GUILE_LIBS) $(LIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) guile_cpp: $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO): $(SRCS) $(SWIG) -c++ -guile -Linkage passive $(SWIGOPT) $(INTERFACEPATH) $(CXX) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $@ + $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(GUILE_LIBS) $(LIBS) $(CPP_DLLIBS) -o $@ guile_externalhdr: $(SWIG) -guile -external-runtime $(TARGET) -# ----------------------------------------------------------------- -# Build a dynamically loadable module with passive linkage -# ----------------------------------------------------------------- - -guile_passive: $(SRCS) - $(SWIG) -guile -Linkage passive $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ISRCS) $(SRCS) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) - -guile_passive_cpp: $(SRCS) - $(SWIG) -c++ -guile -Linkage passive $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) - # ----------------------------------------------------------------- # Build statically linked Guile interpreter # ----------------------------------------------------------------- @@ -504,23 +490,23 @@ guile_static: $(SRCS) $(SWIG) -guile -lguilemain.i -Linkage ltdlmod $(SWIGOPT) $(INTERFACEPATH) $(CC) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) \ -DSWIGINIT="SCM scm_init_$(TARGET)_module(void); scm_init_$(TARGET)_module();" \ - $(GUILE_CFLAGS) $(LIBS) -L$(GUILE_LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile + $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile guile_static_cpp: $(SRCS) $(SWIG) -c++ -guile -lguilemain.i -Linkage ltdlmod $(SWIGOPT) $(INTERFACEPATH) $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ -DSWIGINIT="SCM scm_init_$(TARGET)_module(void); scm_init_$(TARGET)_module();" \ - $(GUILE_CFLAGS) $(LIBS) -L$(GUILE_LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile + $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile guile_simple: $(SRCS) $(SWIG) -guile -lguilemain.i -Linkage simple $(SWIGOPT) $(INTERFACEPATH) $(CC) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) \ - $(GUILE_CFLAGS) $(LIBS) -L$(GUILE_LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile + $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile guile_simple_cpp: $(SRCS) $(SWIG) -c++ -guile -lguilemain.i -Linkage simple $(SWIGOPT) $(INTERFACEPATH) $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ - $(GUILE_CFLAGS) $(LIBS) -L$(GUILE_LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile + $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile # ----------------------------------------------------------------- # Running a Guile example From 1adb2390469576cb1a6b6e9337595fdc8a9e89e7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 8 May 2013 14:10:47 +0100 Subject: [PATCH 0603/1160] Fix running of Guile multivalue and std_vector examples --- Examples/guile/multivalue/Makefile | 1 + Examples/guile/multivalue/runme.scm | 3 ++- Examples/guile/std_vector/Makefile | 1 + Examples/guile/std_vector/runme.scm | 4 ++-- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Examples/guile/multivalue/Makefile b/Examples/guile/multivalue/Makefile index 00fa5df28..7b2f264ba 100644 --- a/Examples/guile/multivalue/Makefile +++ b/Examples/guile/multivalue/Makefile @@ -5,6 +5,7 @@ TARGET = example INTERFACE = example.i check: build + $(MAKE) -f ../Makefile RUNSCRIPT=runme.scm run_example build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/guile/multivalue/runme.scm b/Examples/guile/multivalue/runme.scm index 73eb5affa..729f3fa18 100644 --- a/Examples/guile/multivalue/runme.scm +++ b/Examples/guile/multivalue/runme.scm @@ -1,6 +1,6 @@ ;;;; Show the three different ways to deal with multiple return values -(use-modules (example)) +(dynamic-call "scm_init_example_module" (dynamic-link "./libexample")) ;;; Multiple values as lists. By default, if more than one value is to ;;; be returned, a list of the values is created and returned. The @@ -64,3 +64,4 @@ (display remainder) (newline)) +(exit 0) diff --git a/Examples/guile/std_vector/Makefile b/Examples/guile/std_vector/Makefile index fa138f43f..6eca67519 100644 --- a/Examples/guile/std_vector/Makefile +++ b/Examples/guile/std_vector/Makefile @@ -5,6 +5,7 @@ TARGET = example INTERFACE = example.i check: build + $(MAKE) -f ../Makefile RUNSCRIPT=runme.scm run_example build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/guile/std_vector/runme.scm b/Examples/guile/std_vector/runme.scm index 77443a156..470f22922 100644 --- a/Examples/guile/std_vector/runme.scm +++ b/Examples/guile/std_vector/runme.scm @@ -1,6 +1,5 @@ -;; run with mzscheme -r example.scm -(use-modules (example)) +(dynamic-call "scm_init_example_module" (dynamic-link "./libexample")) ; repeatedly invoke a procedure with v and an index as arguments (define (with-vector v proc size-proc) @@ -52,3 +51,4 @@ (print-DoubleVector v) (delete-DoubleVector v) +(exit 0) From cd4c1d3c3f22b3bc519816cc9879141b65eb3938 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 8 May 2013 16:48:27 +0100 Subject: [PATCH 0604/1160] Tidy up target language versions display --- Examples/Makefile.in | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index a3a2b04c9..9ce0f1f81 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -440,7 +440,7 @@ octave_run: # ----------------------------------------------------------------- octave_version: - $(OCTAVE) --version | grep -i version + $(OCTAVE) --version | head -n 1 # ----------------------------------------------------------------- # Cleaning the Octave examples @@ -520,7 +520,7 @@ guile_run: # ----------------------------------------------------------------- guile_version: - $(GUILE) --version + $(GUILE) --version | head -n 1 # ----------------------------------------------------------------- # Cleaning the Guile examples @@ -1004,7 +1004,7 @@ php_run: # ----------------------------------------------------------------- php_version: - $(PHP) -v + $(PHP) -v | head -n 1 # ----------------------------------------------------------------- # Cleaning the PHP examples @@ -1075,7 +1075,7 @@ pike_run: # ----------------------------------------------------------------- pike_version: - $(PIKE) -v + $(PIKE) -v | head -n 1 # ----------------------------------------------------------------- # Cleaning the Pike examples @@ -1192,7 +1192,7 @@ chicken_run: # ----------------------------------------------------------------- chicken_version: - $(CHICKEN) -version + $(CHICKEN) -version | grep -i version # ----------------------------------------------------------------- # Cleaning the CHICKEN examples @@ -1254,7 +1254,7 @@ csharp_run: # Version check below also works with MS csc.exe which does not understand --version csharp_version: - $(CSHARPCOMPILER) --version | grep -i version + $(CSHARPCOMPILER) --version | head -n 1 # ----------------------------------------------------------------- # Cleaning the CSharp examples @@ -1330,7 +1330,7 @@ lua_embed_run: # ----------------------------------------------------------------- lua_version: - $(LUA) -v + $(LUA) -v | head -n 1 # ----------------------------------------------------------------- # Cleaning the lua examples @@ -1406,7 +1406,7 @@ clisp_run: # ----------------------------------------------------------------- clisp_version: - $(CLISP) --version + $(CLISP) --version | head -n 1 # ----------------------------------------------------------------- # Cleaning the CLISP examples @@ -1545,7 +1545,7 @@ r_run: # ----------------------------------------------------------------- r_version: - $(R) --version | grep -i version + $(R) --version | head -n 1 # ----------------------------------------------------------------- # Cleaning the R examples From efb4f7bf07e493a038ea53049fabba3bd63df64a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 8 May 2013 17:30:45 +0100 Subject: [PATCH 0605/1160] Don't skip guile if GUILE_CFLAGS is empty as sometimes it is empty --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 07a768469..a618d55de 100644 --- a/configure.ac +++ b/configure.ac @@ -1206,7 +1206,7 @@ else if test -z "$GUILE_CFLAGS" ; then AC_MSG_CHECKING([for guile compile flags]) - GUILE_CFLAGS="`$GUILE_CONFIG compile`" + GUILE_CFLAGS="`$GUILE_CONFIG compile`" # Note that this can sometimes be empty AC_MSG_RESULT([$GUILE_CFLAGS]) fi @@ -2223,7 +2223,7 @@ AC_SUBST(SKIP_JAVA) SKIP_GUILE= -if test -z "$GUILE" || test -z "$GUILE_CFLAGS" || test -z "$GUILE_LIBS" || test -z "$GUILE_SCM_INTERFACE"; then +if test -z "$GUILE" || test -z "$GUILE_LIBS" || test -z "$GUILE_SCM_INTERFACE"; then SKIP_GUILE="1" fi AC_SUBST(SKIP_GUILE) From 7964ebe34fb12f0e61fea48ca501dee2ca0f7246 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 8 May 2013 17:36:03 +0100 Subject: [PATCH 0606/1160] Tidy up pike version display --- Examples/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 9ce0f1f81..a255db4c9 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1075,7 +1075,7 @@ pike_run: # ----------------------------------------------------------------- pike_version: - $(PIKE) -v | head -n 1 + $(PIKE) -v 2>&1 | head -n 1 # ----------------------------------------------------------------- # Cleaning the Pike examples From c28d0c6c80c5254eeedcd63e0942f154dcb60871 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Wed, 8 May 2013 22:43:49 +0200 Subject: [PATCH 0607/1160] Fixes to Octave examples - rename example modules from "example" to "swigexample", to avoid a warning from shadowing the Octave built-in function "example" - remove deprecated "static" Makefile targets: there is no longer an option to build static Octave modules in the Examples Makefile - emacs whitespace cleanup run on all files --- Examples/octave/callback/Makefile | 8 +-- Examples/octave/callback/example.cxx | 1 - Examples/octave/callback/example.h | 1 - Examples/octave/callback/example.i | 3 +- Examples/octave/callback/runme.m | 12 ++-- Examples/octave/class/Makefile | 8 +-- Examples/octave/class/example.h | 7 +-- Examples/octave/class/example.i | 3 +- Examples/octave/class/runme.m | 12 ++-- Examples/octave/constants/Makefile | 10 +--- Examples/octave/constants/example.i | 4 +- Examples/octave/constants/runme.m | 28 ++++------ Examples/octave/contract/Makefile | 6 +- Examples/octave/contract/example.c | 2 - Examples/octave/contract/example.i | 2 +- Examples/octave/contract/runme.m | 11 ++-- Examples/octave/enum/Makefile | 8 +-- Examples/octave/enum/example.h | 1 - Examples/octave/enum/example.i | 3 +- Examples/octave/enum/runme.m | 32 +++++------ Examples/octave/extend/Makefile | 8 +-- Examples/octave/extend/example.cxx | 1 - Examples/octave/extend/example.h | 3 +- Examples/octave/extend/example.i | 3 +- Examples/octave/extend/runme.m | 7 +-- Examples/octave/funcptr/Makefile | 6 +- Examples/octave/funcptr/example.h | 1 - Examples/octave/funcptr/example.i | 3 +- Examples/octave/funcptr/runme.m | 15 +++-- Examples/octave/funcptr2/Makefile | 6 +- Examples/octave/funcptr2/example.h | 1 - Examples/octave/funcptr2/example.i | 3 +- Examples/octave/funcptr2/runme.m | 18 +++--- Examples/octave/functor/Makefile | 10 +--- Examples/octave/functor/example.i | 6 +- Examples/octave/functor/runme.m | 8 +-- Examples/octave/module_load/Makefile | 6 +- Examples/octave/module_load/runme.m | 52 +++++++++--------- Examples/octave/operator/Makefile | 10 +--- Examples/octave/operator/example.h | 2 +- Examples/octave/operator/example.i | 2 +- Examples/octave/operator/runme.m | 8 +-- Examples/octave/pointer/Makefile | 6 +- Examples/octave/pointer/example.i | 6 +- Examples/octave/pointer/runme.m | 29 +++++----- Examples/octave/reference/Makefile | 8 +-- Examples/octave/reference/example.cxx | 1 - Examples/octave/reference/example.h | 4 -- Examples/octave/reference/example.i | 8 +-- Examples/octave/reference/runme.m | 15 +++-- Examples/octave/simple/Makefile | 6 +- Examples/octave/simple/example.c | 2 - Examples/octave/simple/example.i | 2 +- Examples/octave/simple/runme.m | 11 ++-- Examples/octave/template/Makefile | 10 +--- Examples/octave/template/example.h | 1 - Examples/octave/template/example.i | 3 +- Examples/octave/template/runme.m | 12 ++-- Examples/octave/variables/Makefile | 6 +- Examples/octave/variables/example.c | 2 +- Examples/octave/variables/example.h | 1 - Examples/octave/variables/example.i | 3 +- Examples/octave/variables/runme.m | 79 +++++++++++++-------------- 63 files changed, 211 insertions(+), 345 deletions(-) diff --git a/Examples/octave/callback/Makefile b/Examples/octave/callback/Makefile index ffc60e0c0..d38d7f896 100644 --- a/Examples/octave/callback/Makefile +++ b/Examples/octave/callback/Makefile @@ -1,10 +1,10 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig CXXSRCS = example.cxx -TARGET = example +TARGET = swigexample INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build $(MAKE) -f $(TOP)/Makefile octave_run @@ -13,9 +13,5 @@ build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean diff --git a/Examples/octave/callback/example.cxx b/Examples/octave/callback/example.cxx index 450d75608..893a956f4 100644 --- a/Examples/octave/callback/example.cxx +++ b/Examples/octave/callback/example.cxx @@ -1,4 +1,3 @@ /* File : example.cxx */ #include "example.h" - diff --git a/Examples/octave/callback/example.h b/Examples/octave/callback/example.h index 1a0e8c432..74ddad954 100644 --- a/Examples/octave/callback/example.h +++ b/Examples/octave/callback/example.h @@ -20,4 +20,3 @@ public: void setCallback(Callback *cb) { delCallback(); _callback = cb; } void call() { if (_callback) _callback->run(); } }; - diff --git a/Examples/octave/callback/example.i b/Examples/octave/callback/example.i index 90beda01a..3192904db 100644 --- a/Examples/octave/callback/example.i +++ b/Examples/octave/callback/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module(directors="1") example +%module(directors="1") swigexample %{ #include "example.h" %} @@ -10,4 +10,3 @@ %feature("director") Callback; %include "example.h" - diff --git a/Examples/octave/callback/runme.m b/Examples/octave/callback/runme.m index b87925e3d..103985358 100644 --- a/Examples/octave/callback/runme.m +++ b/Examples/octave/callback/runme.m @@ -2,14 +2,13 @@ # This file illustrates the cross language polymorphism using directors. -example +swigexample -OctCallback=@() subclass(example.Callback(), \ - 'run',@(self) printf("OctCallback.run()\n")); +OctCallback=@() subclass(swigexample.Callback(),"run",@(self) printf("OctCallback.run()\n")); # Create an Caller instance -caller = example.Caller(); +caller = swigexample.Caller(); # Add a simple C++ callback (caller owns the callback, so # we disown it first) @@ -17,7 +16,7 @@ caller = example.Caller(); printf("Adding and calling a normal C++ callback\n"); printf("----------------------------------------\n"); -callback = example.Callback().__disown(); +callback = swigexample.Callback().__disown(); caller.setCallback(callback); caller.call(); caller.delCallback(); @@ -43,7 +42,7 @@ caller.call(); caller.delCallback(); # careful-- using callback here may cause problems; octave_swig_type still -# exists, but is holding a destroyed object (the C++ example.Callback). +# exists, but is holding a destroyed object (the C++ swigexample.Callback). # to manually drop the octave-side reference, you can use clear callback; @@ -60,4 +59,3 @@ a.Callback.run(); # All done. printf("octave exit\n"); - diff --git a/Examples/octave/class/Makefile b/Examples/octave/class/Makefile index ffc60e0c0..d38d7f896 100644 --- a/Examples/octave/class/Makefile +++ b/Examples/octave/class/Makefile @@ -1,10 +1,10 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig CXXSRCS = example.cxx -TARGET = example +TARGET = swigexample INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build $(MAKE) -f $(TOP)/Makefile octave_run @@ -13,9 +13,5 @@ build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean diff --git a/Examples/octave/class/example.h b/Examples/octave/class/example.h index 46d901361..0d4527e92 100644 --- a/Examples/octave/class/example.h +++ b/Examples/octave/class/example.h @@ -8,7 +8,7 @@ public: virtual ~Shape() { nshapes--; }; - double x, y; + double x, y; void move(double dx, double dy); virtual double area(void) = 0; virtual double perimeter(void) = 0; @@ -32,8 +32,3 @@ public: virtual double area(void); virtual double perimeter(void); }; - - - - - diff --git a/Examples/octave/class/example.i b/Examples/octave/class/example.i index 75700b305..b109bcb78 100644 --- a/Examples/octave/class/example.i +++ b/Examples/octave/class/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module example +%module swigexample %{ #include "example.h" @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/octave/class/runme.m b/Examples/octave/class/runme.m index c833a701b..04221b4bb 100644 --- a/Examples/octave/class/runme.m +++ b/Examples/octave/class/runme.m @@ -3,17 +3,17 @@ # This file illustrates the proxy class C++ interface generated # by SWIG. -example +swigexample # ----- Object creation ----- printf("Creating some objects:\n"); -c = example.Circle(10) -s = example.Square(10) +c = swigexample.Circle(10) +s = swigexample.Square(10) # ----- Access a static member ----- -printf("\nA total of %i shapes were created\n", example.Shape.nshapes); +printf("\nA total of %i shapes were created\n", swigexample.Shape.nshapes); # ----- Member data access ----- @@ -46,7 +46,5 @@ printf("\nGuess I'll clean up now\n"); clear c clear s -printf("%i shapes remain\n", example.Shape.nshapes); +printf("%i shapes remain\n", swigexample.Shape.nshapes); printf("Goodbye\n"); - - diff --git a/Examples/octave/constants/Makefile b/Examples/octave/constants/Makefile index 60b0578c6..03501bd81 100644 --- a/Examples/octave/constants/Makefile +++ b/Examples/octave/constants/Makefile @@ -1,10 +1,10 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = -TARGET = example +CXXSRCS = +TARGET = swigexample INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build $(MAKE) -f $(TOP)/Makefile octave_run @@ -13,9 +13,5 @@ build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean diff --git a/Examples/octave/constants/example.i b/Examples/octave/constants/example.i index 4f7b1a4d7..405974b44 100644 --- a/Examples/octave/constants/example.i +++ b/Examples/octave/constants/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module example +%module swigexample /* A few preprocessor macros */ @@ -23,5 +23,3 @@ %constant int iconst = 37; %constant double fconst = 3.14; - - diff --git a/Examples/octave/constants/runme.m b/Examples/octave/constants/runme.m index 322858734..c6ed24535 100644 --- a/Examples/octave/constants/runme.m +++ b/Examples/octave/constants/runme.m @@ -1,29 +1,25 @@ # file: runme.m -example +swigexample -printf("ICONST = %i (should be 42)\n", example.ICONST); -printf("FCONST = %f (should be 2.1828)\n", example.FCONST); -printf("CCONST = %s (should be 'x')\n", example.CCONST); -printf("CCONST2 = %s (this should be on a new line)\n", example.CCONST2); -printf("SCONST = %s (should be 'Hello World')\n", example.SCONST); -printf("SCONST2 = %s (should be '\"Hello World\"')\n", example.SCONST2); -printf("EXPR = %f (should be 48.5484)\n", example.EXPR); -printf("iconst = %i (should be 37)\n", example.iconst); -printf("fconst = %f (should be 3.14)\n", example.fconst); +printf("ICONST = %i (should be 42)\n", swigexample.ICONST); +printf("FCONST = %f (should be 2.1828)\n", swigexample.FCONST); +printf("CCONST = %s (should be 'x')\n", swigexample.CCONST); +printf("CCONST2 = %s (this should be on a new line)\n", swigexample.CCONST2); +printf("SCONST = %s (should be 'Hello World')\n", swigexample.SCONST); +printf("SCONST2 = %s (should be '\"Hello World\"')\n", swigexample.SCONST2); +printf("EXPR = %f (should be 48.5484)\n", swigexample.EXPR); +printf("iconst = %i (should be 37)\n", swigexample.iconst); +printf("fconst = %f (should be 3.14)\n", swigexample.fconst); try - printf("EXTERN = %s (Arg! This shouldn't printf(anything)\n", example.EXTERN); + printf("EXTERN = %s (Arg! This shouldn't printf(anything)\n", swigexample.EXTERN); catch printf("EXTERN isn't defined (good)\n"); end_try_catch try - printf("FOO = %i (Arg! This shouldn't printf(anything)\n", example.FOO); + printf("FOO = %i (Arg! This shouldn't printf(anything)\n", swigexample.FOO); catch printf("FOO isn't defined (good)\n"); end_try_catch - - - - diff --git a/Examples/octave/contract/Makefile b/Examples/octave/contract/Makefile index 2c33cd3d8..73e3962ed 100644 --- a/Examples/octave/contract/Makefile +++ b/Examples/octave/contract/Makefile @@ -1,7 +1,7 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig SRCS = example.c -TARGET = example +TARGET = swigexample INTERFACE = example.i check: build @@ -11,9 +11,5 @@ build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave -static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean diff --git a/Examples/octave/contract/example.c b/Examples/octave/contract/example.c index 1a644543f..fbdc054cd 100644 --- a/Examples/octave/contract/example.c +++ b/Examples/octave/contract/example.c @@ -19,5 +19,3 @@ int fact(int n) { if (n <= 0) return 1; return n*fact(n-1); } - - diff --git a/Examples/octave/contract/example.i b/Examples/octave/contract/example.i index 8fd1a80af..78c459efc 100644 --- a/Examples/octave/contract/example.i +++ b/Examples/octave/contract/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module example +%module swigexample %contract gcd(int x, int y) { require: diff --git a/Examples/octave/contract/runme.m b/Examples/octave/contract/runme.m index 62b72320b..fa36bbe10 100644 --- a/Examples/octave/contract/runme.m +++ b/Examples/octave/contract/runme.m @@ -1,22 +1,21 @@ # file: runme.m -example +swigexample # Call our gcd() function x = 42; y = 105; -g = example.gcd(x,y); +g = swigexample.gcd(x,y); printf("The gcd of %d and %d is %d\n",x,y,g); # Manipulate the Foo global variable # Output its current value -printf("Foo = %f\n", example.cvar.Foo); +printf("Foo = %f\n", swigexample.cvar.Foo); # Change its value -example.cvar.Foo = 3.1415926; +swigexample.cvar.Foo = 3.1415926; # See if the change took effect -printf("Foo = %f\n", example.cvar.Foo); - +printf("Foo = %f\n", swigexample.cvar.Foo); diff --git a/Examples/octave/enum/Makefile b/Examples/octave/enum/Makefile index ffc60e0c0..d38d7f896 100644 --- a/Examples/octave/enum/Makefile +++ b/Examples/octave/enum/Makefile @@ -1,10 +1,10 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig CXXSRCS = example.cxx -TARGET = example +TARGET = swigexample INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build $(MAKE) -f $(TOP)/Makefile octave_run @@ -13,9 +13,5 @@ build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean diff --git a/Examples/octave/enum/example.h b/Examples/octave/enum/example.h index 525d62afc..490d502e8 100644 --- a/Examples/octave/enum/example.h +++ b/Examples/octave/enum/example.h @@ -10,4 +10,3 @@ class Foo { }; void enum_test(color c, Foo::speed s); - diff --git a/Examples/octave/enum/example.i b/Examples/octave/enum/example.i index 23ee8a822..cee9af471 100644 --- a/Examples/octave/enum/example.i +++ b/Examples/octave/enum/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module example +%module swigexample %{ #include "example.h" @@ -8,4 +8,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/octave/enum/runme.m b/Examples/octave/enum/runme.m index a749e81db..0108135b2 100644 --- a/Examples/octave/enum/runme.m +++ b/Examples/octave/enum/runme.m @@ -1,32 +1,30 @@ # file: runme.m -example +swigexample # ----- Object creation ----- # Print out the value of some enums printf("*** color ***\n"); -printf(" RED = %i\n", example.RED); -printf(" BLUE = %i\n", example.BLUE); -printf(" GREEN = %i\n", example.GREEN); +printf(" RED = %i\n", swigexample.RED); +printf(" BLUE = %i\n", swigexample.BLUE); +printf(" GREEN = %i\n", swigexample.GREEN); printf("\n*** Foo::speed ***\n"); -printf(" Foo_IMPULSE = %i\n", example.Foo_IMPULSE); -printf(" Foo_WARP = %i\n", example.Foo_WARP); -printf(" Foo_LUDICROUS = %i\n", example.Foo_LUDICROUS); +printf(" Foo_IMPULSE = %i\n", swigexample.Foo_IMPULSE); +printf(" Foo_WARP = %i\n", swigexample.Foo_WARP); +printf(" Foo_LUDICROUS = %i\n", swigexample.Foo_LUDICROUS); printf("\nTesting use of enums with functions\n"); -example.enum_test(example.RED, example.Foo_IMPULSE); -example.enum_test(example.BLUE, example.Foo_WARP); -example.enum_test(example.GREEN, example.Foo_LUDICROUS); -example.enum_test(1234,5678) +swigexample.enum_test(swigexample.RED, swigexample.Foo_IMPULSE); +swigexample.enum_test(swigexample.BLUE, swigexample.Foo_WARP); +swigexample.enum_test(swigexample.GREEN, swigexample.Foo_LUDICROUS); +swigexample.enum_test(1234,5678) printf("\nTesting use of enum with class method\n"); -f = example.Foo(); - -f.enum_test(example.Foo_IMPULSE); -f.enum_test(example.Foo_WARP); -f.enum_test(example.Foo_LUDICROUS); - +f = swigexample.Foo(); +f.enum_test(swigexample.Foo_IMPULSE); +f.enum_test(swigexample.Foo_WARP); +f.enum_test(swigexample.Foo_LUDICROUS); diff --git a/Examples/octave/extend/Makefile b/Examples/octave/extend/Makefile index ffc60e0c0..d38d7f896 100644 --- a/Examples/octave/extend/Makefile +++ b/Examples/octave/extend/Makefile @@ -1,10 +1,10 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig CXXSRCS = example.cxx -TARGET = example +TARGET = swigexample INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build $(MAKE) -f $(TOP)/Makefile octave_run @@ -13,9 +13,5 @@ build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean diff --git a/Examples/octave/extend/example.cxx b/Examples/octave/extend/example.cxx index 450d75608..893a956f4 100644 --- a/Examples/octave/extend/example.cxx +++ b/Examples/octave/extend/example.cxx @@ -1,4 +1,3 @@ /* File : example.cxx */ #include "example.h" - diff --git a/Examples/octave/extend/example.h b/Examples/octave/extend/example.h index b27ab9711..9e15cf8e4 100644 --- a/Examples/octave/extend/example.h +++ b/Examples/octave/extend/example.h @@ -44,7 +44,7 @@ public: const Employee *get_item(int i) { return list[i]; } - ~EmployeeList() { + ~EmployeeList() { std::vector::iterator i; std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl; for (i=list.begin(); i!=list.end(); i++) { @@ -53,4 +53,3 @@ public: std::cout << "~EmployeeList empty." << std::endl; } }; - diff --git a/Examples/octave/extend/example.i b/Examples/octave/extend/example.i index c8ec32e09..953c2f314 100644 --- a/Examples/octave/extend/example.i +++ b/Examples/octave/extend/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module(directors="1") example +%module(directors="1") swigexample %{ #include "example.h" %} @@ -12,4 +12,3 @@ %feature("director") Manager; %include "example.h" - diff --git a/Examples/octave/extend/runme.m b/Examples/octave/extend/runme.m index c64c082c4..4536f2761 100644 --- a/Examples/octave/extend/runme.m +++ b/Examples/octave/extend/runme.m @@ -2,12 +2,12 @@ # This file illustrates the cross language polymorphism using directors. -example +swigexample # CEO class, which overrides Employee::getPosition(). -CEO=@(name) subclass(example.Manager(name),'getPosition',@(self) "CEO"); +CEO=@(name) subclass(swigexample.Manager(name),'getPosition',@(self) "CEO"); # Create an instance of our employee extension class, CEO. The calls to # getName() and getPosition() are standard, the call to getTitle() uses @@ -22,7 +22,7 @@ printf("----------------------\n"); # Create a new EmployeeList instance. This class does not have a C++ # director wrapper, but can be used freely with other classes that do. -list = example.EmployeeList(); +list = swigexample.EmployeeList(); # EmployeeList owns its items, so we must surrender ownership of objects # we add. This involves first calling the __disown__ method to tell the @@ -71,4 +71,3 @@ printf("----------------------\n"); # All done. printf("octave exit\n"); - diff --git a/Examples/octave/funcptr/Makefile b/Examples/octave/funcptr/Makefile index 2c33cd3d8..73e3962ed 100644 --- a/Examples/octave/funcptr/Makefile +++ b/Examples/octave/funcptr/Makefile @@ -1,7 +1,7 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig SRCS = example.c -TARGET = example +TARGET = swigexample INTERFACE = example.i check: build @@ -11,9 +11,5 @@ build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave -static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean diff --git a/Examples/octave/funcptr/example.h b/Examples/octave/funcptr/example.h index 9936e24fc..f95ae2cc9 100644 --- a/Examples/octave/funcptr/example.h +++ b/Examples/octave/funcptr/example.h @@ -6,4 +6,3 @@ extern int sub(int,int); extern int mul(int,int); extern int (*funcvar)(int,int); - diff --git a/Examples/octave/funcptr/example.i b/Examples/octave/funcptr/example.i index 8b3bef678..163a1991b 100644 --- a/Examples/octave/funcptr/example.i +++ b/Examples/octave/funcptr/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module example +%module swigexample %{ #include "example.h" %} @@ -13,4 +13,3 @@ extern int do_op(int a, int b, int (*op)(int, int)); %constant int (*MUL)(int,int) = mul; extern int (*funcvar)(int,int); - diff --git a/Examples/octave/funcptr/runme.m b/Examples/octave/funcptr/runme.m index 455311c16..4e2e28fbc 100644 --- a/Examples/octave/funcptr/runme.m +++ b/Examples/octave/funcptr/runme.m @@ -1,6 +1,6 @@ # file: runme.m -example +swigexample a = 37 b = 42 @@ -10,12 +10,11 @@ b = 42 printf("Trying some C callback functions\n"); printf(" a = %i\n", a); printf(" b = %i\n", b); -printf(" ADD(a,b) = %i\n", example.do_op(a,b,example.ADD)); -printf(" SUB(a,b) = %i\n", example.do_op(a,b,example.SUB)); -printf(" MUL(a,b) = %i\n", example.do_op(a,b,example.MUL)); +printf(" ADD(a,b) = %i\n", swigexample.do_op(a,b,swigexample.ADD)); +printf(" SUB(a,b) = %i\n", swigexample.do_op(a,b,swigexample.SUB)); +printf(" MUL(a,b) = %i\n", swigexample.do_op(a,b,swigexample.MUL)); printf("Here is what the C callback function objects look like in Octave\n"); -example.ADD -example.SUB -example.MUL - +swigexample.ADD +swigexample.SUB +swigexample.MUL diff --git a/Examples/octave/funcptr2/Makefile b/Examples/octave/funcptr2/Makefile index 2c33cd3d8..73e3962ed 100644 --- a/Examples/octave/funcptr2/Makefile +++ b/Examples/octave/funcptr2/Makefile @@ -1,7 +1,7 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig SRCS = example.c -TARGET = example +TARGET = swigexample INTERFACE = example.i check: build @@ -11,9 +11,5 @@ build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave -static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean diff --git a/Examples/octave/funcptr2/example.h b/Examples/octave/funcptr2/example.h index 9936e24fc..f95ae2cc9 100644 --- a/Examples/octave/funcptr2/example.h +++ b/Examples/octave/funcptr2/example.h @@ -6,4 +6,3 @@ extern int sub(int,int); extern int mul(int,int); extern int (*funcvar)(int,int); - diff --git a/Examples/octave/funcptr2/example.i b/Examples/octave/funcptr2/example.i index 681775a3e..33378a1c1 100644 --- a/Examples/octave/funcptr2/example.i +++ b/Examples/octave/funcptr2/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module example +%module swigexample %{ #include "example.h" %} @@ -15,4 +15,3 @@ int mul(int, int); %nocallback; extern int (*funcvar)(int,int); - diff --git a/Examples/octave/funcptr2/runme.m b/Examples/octave/funcptr2/runme.m index 1d3d8f73a..574635ed2 100644 --- a/Examples/octave/funcptr2/runme.m +++ b/Examples/octave/funcptr2/runme.m @@ -1,6 +1,6 @@ # file: runme.m -example +swigexample a = 37 b = 42 @@ -10,15 +10,15 @@ b = 42 printf("Trying some C callback functions\n"); printf(" a = %i\n", a); printf(" b = %i\n", b); -printf(" ADD(a,b) = %i\n", example.do_op(a,b,example.ADD)); -printf(" SUB(a,b) = %i\n", example.do_op(a,b,example.SUB)); -printf(" MUL(a,b) = %i\n", example.do_op(a,b,example.MUL)); +printf(" ADD(a,b) = %i\n", swigexample.do_op(a,b,swigexample.ADD)); +printf(" SUB(a,b) = %i\n", swigexample.do_op(a,b,swigexample.SUB)); +printf(" MUL(a,b) = %i\n", swigexample.do_op(a,b,swigexample.MUL)); printf("Here is what the C callback function objects look like in Octave\n"); -example.ADD -example.SUB -example.MUL +swigexample.ADD +swigexample.SUB +swigexample.MUL printf("Call the functions directly...\n"); -printf(" add(a,b) = %i\n", example.add(a,b)); -printf(" sub(a,b) = %i\n", example.sub(a,b)); +printf(" add(a,b) = %i\n", swigexample.add(a,b)); +printf(" sub(a,b) = %i\n", swigexample.sub(a,b)); diff --git a/Examples/octave/functor/Makefile b/Examples/octave/functor/Makefile index 09c680b4e..94fb96337 100644 --- a/Examples/octave/functor/Makefile +++ b/Examples/octave/functor/Makefile @@ -1,10 +1,10 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = -TARGET = example +CXXSRCS = +TARGET = swigexample INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build $(MAKE) -f $(TOP)/Makefile octave_run @@ -13,9 +13,5 @@ build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean diff --git a/Examples/octave/functor/example.i b/Examples/octave/functor/example.i index 2fd38176f..ade20c56c 100644 --- a/Examples/octave/functor/example.i +++ b/Examples/octave/functor/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module example +%module swigexample %inline %{ @@ -23,7 +23,3 @@ public: // Instantiate a few versions %template(intSum) Sum; %template(doubleSum) Sum; - - - - diff --git a/Examples/octave/functor/runme.m b/Examples/octave/functor/runme.m index 65dabcc91..8b41691c3 100644 --- a/Examples/octave/functor/runme.m +++ b/Examples/octave/functor/runme.m @@ -1,8 +1,8 @@ # Operator overloading example -example +swigexample -a = example.intSum(0); -b = example.doubleSum(100.0); +a = swigexample.intSum(0); +b = swigexample.doubleSum(100.0); # Use the objects. They should be callable just like a normal # python function. @@ -14,5 +14,3 @@ endfor a.result() b.result() - - diff --git a/Examples/octave/module_load/Makefile b/Examples/octave/module_load/Makefile index bead6f150..e388763bd 100644 --- a/Examples/octave/module_load/Makefile +++ b/Examples/octave/module_load/Makefile @@ -1,7 +1,7 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig SRCS = example.c -TARGET = example +TARGET = swigexample INTERFACE = example.i check: build @@ -13,10 +13,6 @@ build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)2' SWIGOPT='-module $$(TARGET) -globals .' INTERFACE='$(INTERFACE)' octave -static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean rm -f $(TARGET).m diff --git a/Examples/octave/module_load/runme.m b/Examples/octave/module_load/runme.m index 0fda218cd..bc311b5e6 100644 --- a/Examples/octave/module_load/runme.m +++ b/Examples/octave/module_load/runme.m @@ -2,60 +2,60 @@ # load module clear all; -example; +swigexample; assert(cvar.ivar == ifunc); -assert(exist("example","var")); +assert(exist("swigexample","var")); clear all -example; +swigexample; assert(cvar.ivar == ifunc); -assert(exist("example","var")); +assert(exist("swigexample","var")); clear all # load module in a function globally before base context clear all; function testme - example; + swigexample; assert(cvar.ivar == ifunc); - assert(exist("example","var")); + assert(exist("swigexample","var")); endfunction testme testme -example; +swigexample; assert(cvar.ivar == ifunc); -assert(exist("example","var")); +assert(exist("swigexample","var")); clear all function testme - example; + swigexample; assert(cvar.ivar == ifunc); - assert(exist("example","var")); + assert(exist("swigexample","var")); endfunction testme testme -example; +swigexample; assert(cvar.ivar == ifunc); -assert(exist("example","var")); +assert(exist("swigexample","var")); clear all # load module in a function globally after base context clear all; -example; +swigexample; assert(cvar.ivar == ifunc); -assert(exist("example","var")); +assert(exist("swigexample","var")); function testme - example; + swigexample; assert(cvar.ivar == ifunc); - assert(exist("example","var")); + assert(exist("swigexample","var")); endfunction testme testme clear all -example; +swigexample; assert(cvar.ivar == ifunc); -assert(exist("example","var")); +assert(exist("swigexample","var")); function testme - example; + swigexample; assert(cvar.ivar == ifunc); - assert(exist("example","var")); + assert(exist("swigexample","var")); endfunction testme testme @@ -69,13 +69,13 @@ endif # load module with no cvar clear all; -example2; -assert(example2.ivar == ifunc); -assert(exist("example2","var")); +swigexample2; +assert(swigexample2.ivar == ifunc); +assert(exist("swigexample2","var")); assert(!isglobal("cvar")) clear all -example2; -assert(example2.ivar == ifunc); -assert(exist("example2","var")); +swigexample2; +assert(swigexample2.ivar == ifunc); +assert(exist("swigexample2","var")); assert(!isglobal("cvar")) clear all diff --git a/Examples/octave/operator/Makefile b/Examples/octave/operator/Makefile index 09c680b4e..94fb96337 100644 --- a/Examples/octave/operator/Makefile +++ b/Examples/octave/operator/Makefile @@ -1,10 +1,10 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = -TARGET = example +CXXSRCS = +TARGET = swigexample INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build $(MAKE) -f $(TOP)/Makefile octave_run @@ -13,9 +13,5 @@ build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean diff --git a/Examples/octave/operator/example.h b/Examples/octave/operator/example.h index a9b69e009..d91adabe8 100644 --- a/Examples/octave/operator/example.h +++ b/Examples/octave/operator/example.h @@ -25,7 +25,7 @@ public: ComplexVal operator-() const { return ComplexVal(-rpart, -ipart); } - + double re() const { return rpart; } double im() const { return ipart; } }; diff --git a/Examples/octave/operator/example.i b/Examples/octave/operator/example.i index 7b903e69b..a2d97731d 100644 --- a/Examples/octave/operator/example.i +++ b/Examples/octave/operator/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module example +%module swigexample #pragma SWIG nowarn=SWIGWARN_IGNORE_OPERATOR_EQ %{ #include "example.h" diff --git a/Examples/octave/operator/runme.m b/Examples/octave/operator/runme.m index 85fd99ad4..9ab614ffb 100644 --- a/Examples/octave/operator/runme.m +++ b/Examples/octave/operator/runme.m @@ -1,8 +1,8 @@ # Operator overloading example -example +swigexample -a = example.ComplexVal(2,3); -b = example.ComplexVal(-5,10); +a = swigexample.ComplexVal(2,3); +b = swigexample.ComplexVal(-5,10); printf("a = %s\n",disp(a)); printf("b = %s\n",disp(b)); @@ -12,7 +12,7 @@ printf("c = %s\n",disp(c)); printf("a*b = %s\n",disp(a*b)); printf("a-c = %s\n",disp(a-c)); -e = example.ComplexVal(a-c); +e = swigexample.ComplexVal(a-c); printf("e = %s\n",disp(e)); # Big expression diff --git a/Examples/octave/pointer/Makefile b/Examples/octave/pointer/Makefile index 2c33cd3d8..73e3962ed 100644 --- a/Examples/octave/pointer/Makefile +++ b/Examples/octave/pointer/Makefile @@ -1,7 +1,7 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig SRCS = example.c -TARGET = example +TARGET = swigexample INTERFACE = example.i check: build @@ -11,9 +11,5 @@ build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave -static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean diff --git a/Examples/octave/pointer/example.i b/Examples/octave/pointer/example.i index a8ac79499..545e3ada4 100644 --- a/Examples/octave/pointer/example.i +++ b/Examples/octave/pointer/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module example +%module swigexample %{ extern void add(int *, int *, int *); @@ -24,7 +24,3 @@ extern void sub(int *INPUT, int *INPUT, int *OUTPUT); %apply int *OUTPUT { int *r }; extern int divide(int n, int d, int *r); - - - - diff --git a/Examples/octave/pointer/runme.m b/Examples/octave/pointer/runme.m index c36df7270..a76de67de 100644 --- a/Examples/octave/pointer/runme.m +++ b/Examples/octave/pointer/runme.m @@ -1,42 +1,39 @@ # file: runme.m -example; +swigexample; # First create some objects using the pointer library. printf("Testing the pointer library\n"); -a = example.new_intp(); -b = example.new_intp(); -c = example.new_intp(); -example.intp_assign(a,37); -example.intp_assign(b,42); +a = swigexample.new_intp(); +b = swigexample.new_intp(); +c = swigexample.new_intp(); +swigexample.intp_assign(a,37); +swigexample.intp_assign(b,42); a,b,c # Call the add() function with some pointers -example.add(a,b,c); +swigexample.add(a,b,c); # Now get the result -r = example.intp_value(c); +r = swigexample.intp_value(c); printf(" 37 + 42 = %i\n",r); # Clean up the pointers -example.delete_intp(a); -example.delete_intp(b); -example.delete_intp(c); +swigexample.delete_intp(a); +swigexample.delete_intp(b); +swigexample.delete_intp(c); # Now try the typemap library # This should be much easier. Now how it is no longer # necessary to manufacture pointers. printf("Trying the typemap library\n"); -r = example.sub(37,42); +r = swigexample.sub(37,42); printf(" 37 - 42 = %i\n",r); # Now try the version with multiple return values printf("Testing multiple return values\n"); -[q,r] = example.divide(42,37); +[q,r] = swigexample.divide(42,37); printf(" 42/37 = %d remainder %d\n",q,r); - - - diff --git a/Examples/octave/reference/Makefile b/Examples/octave/reference/Makefile index ffc60e0c0..d38d7f896 100644 --- a/Examples/octave/reference/Makefile +++ b/Examples/octave/reference/Makefile @@ -1,10 +1,10 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig CXXSRCS = example.cxx -TARGET = example +TARGET = swigexample INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build $(MAKE) -f $(TOP)/Makefile octave_run @@ -13,9 +13,5 @@ build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean diff --git a/Examples/octave/reference/example.cxx b/Examples/octave/reference/example.cxx index 8a513bf49..9b72ca6a2 100644 --- a/Examples/octave/reference/example.cxx +++ b/Examples/octave/reference/example.cxx @@ -43,4 +43,3 @@ Vector &VectorArray::operator[](int index) { int VectorArray::size() { return maxsize; } - diff --git a/Examples/octave/reference/example.h b/Examples/octave/reference/example.h index 4915adb1b..697afafe0 100644 --- a/Examples/octave/reference/example.h +++ b/Examples/octave/reference/example.h @@ -20,7 +20,3 @@ public: Vector &operator[](int); int size(); }; - - - - diff --git a/Examples/octave/reference/example.i b/Examples/octave/reference/example.i index 8c95b3213..da09800c0 100644 --- a/Examples/octave/reference/example.i +++ b/Examples/octave/reference/example.i @@ -2,7 +2,7 @@ /* This file has a few "typical" uses of C++ references. */ -%module example +%module swigexample %{ #include "example.h" @@ -31,7 +31,7 @@ public: VectorArray(int maxsize); ~VectorArray(); int size(); - + /* This wrapper provides an alternative to the [] operator */ %extend { Vector &get(int index) { @@ -42,7 +42,3 @@ public: } } }; - - - - diff --git a/Examples/octave/reference/runme.m b/Examples/octave/reference/runme.m index f59c8eb7d..630ee0cd2 100644 --- a/Examples/octave/reference/runme.m +++ b/Examples/octave/reference/runme.m @@ -2,13 +2,13 @@ # This file illustrates the manipulation of C++ references in Octave -example +swigexample # ----- Object creation ----- printf("Creating some objects:\n"); -a = example.Vector(3,4,5) -b = example.Vector(10,11,12) +a = swigexample.Vector(3,4,5) +b = swigexample.Vector(10,11,12) printf(" Created %s\n",a.cprint()); printf(" Created %s\n",b.cprint()); @@ -17,12 +17,12 @@ printf(" Created %s\n",b.cprint()); # This calls the wrapper we placed around # -# operator+(const Vector &a, const Vector &) +# operator+(const Vector &a, const Vector &) # # It returns a new allocated object. printf("Adding a+b\n"); -c = example.addv(a,b); +c = swigexample.addv(a,b); printf(" a+b = %s\n", c.cprint()); clear c @@ -31,7 +31,7 @@ clear c # Note: Using the high-level interface here printf("Creating an array of vectors\n"); -va = example.VectorArray(10) +va = swigexample.VectorArray(10) # ----- Set some values in the array ----- @@ -39,7 +39,7 @@ va = example.VectorArray(10) va.set(0,a); va.set(1,b); -va.set(2,example.addv(a,b)) +va.set(2,swigexample.addv(a,b)) # Get some values from the array @@ -60,4 +60,3 @@ printf("Cleaning up\n"); clear va clear a clear b - diff --git a/Examples/octave/simple/Makefile b/Examples/octave/simple/Makefile index 2c33cd3d8..73e3962ed 100644 --- a/Examples/octave/simple/Makefile +++ b/Examples/octave/simple/Makefile @@ -1,7 +1,7 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig SRCS = example.c -TARGET = example +TARGET = swigexample INTERFACE = example.i check: build @@ -11,9 +11,5 @@ build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave -static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean diff --git a/Examples/octave/simple/example.c b/Examples/octave/simple/example.c index 1c2af789c..8df41189c 100644 --- a/Examples/octave/simple/example.c +++ b/Examples/octave/simple/example.c @@ -14,5 +14,3 @@ int gcd(int x, int y) { } return g; } - - diff --git a/Examples/octave/simple/example.i b/Examples/octave/simple/example.i index 24093b9bf..127bfcd84 100644 --- a/Examples/octave/simple/example.i +++ b/Examples/octave/simple/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module example +%module swigexample %inline %{ extern int gcd(int x, int y); diff --git a/Examples/octave/simple/runme.m b/Examples/octave/simple/runme.m index 8dc5eaa58..6345df0cf 100644 --- a/Examples/octave/simple/runme.m +++ b/Examples/octave/simple/runme.m @@ -1,22 +1,21 @@ # file: runme.m -example +swigexample # Call our gcd() function x = 42 y = 105 -g = example.gcd(x,y) +g = swigexample.gcd(x,y) printf("The gcd of %d and %d is %d\n",x,y,g); # Manipulate the Foo global variable # Output its current value -example.cvar.Foo +swigexample.cvar.Foo # Change its value -example.cvar.Foo = 3.1415926 +swigexample.cvar.Foo = 3.1415926 # See if the change took effect -printf("Foo = %f\n", example.cvar.Foo); - +printf("Foo = %f\n", swigexample.cvar.Foo); diff --git a/Examples/octave/template/Makefile b/Examples/octave/template/Makefile index 527e3cec6..94fb96337 100644 --- a/Examples/octave/template/Makefile +++ b/Examples/octave/template/Makefile @@ -1,10 +1,10 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = -TARGET = example +CXXSRCS = +TARGET = swigexample INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build $(MAKE) -f $(TOP)/Makefile octave_run @@ -13,9 +13,5 @@ build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp -static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean diff --git a/Examples/octave/template/example.h b/Examples/octave/template/example.h index 7401df650..5eb65dabb 100644 --- a/Examples/octave/template/example.h +++ b/Examples/octave/template/example.h @@ -29,4 +29,3 @@ template class vector { } #endif }; - diff --git a/Examples/octave/template/example.i b/Examples/octave/template/example.i index 8f94c4da1..cfff18ded 100644 --- a/Examples/octave/template/example.i +++ b/Examples/octave/template/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module example +%module swigexample %{ #include "example.h" @@ -14,4 +14,3 @@ %template(maxdouble) max; %template(vecint) vector; %template(vecdouble) vector; - diff --git a/Examples/octave/template/runme.m b/Examples/octave/template/runme.m index a9891d459..b0abbf22f 100644 --- a/Examples/octave/template/runme.m +++ b/Examples/octave/template/runme.m @@ -1,15 +1,15 @@ # file: runme.m -example +swigexample # Call some templated functions -example.maxint(3,7) -example.maxdouble(3.14,2.18) +swigexample.maxint(3,7) +swigexample.maxdouble(3.14,2.18) # Create some class -iv = example.vecint(100) -dv = example.vecdouble(1000) +iv = swigexample.vecint(100) +dv = swigexample.vecdouble(1000) for i=0:99, iv.setitem(i,2*i); @@ -33,5 +33,3 @@ sum clear iv clear dv - - diff --git a/Examples/octave/variables/Makefile b/Examples/octave/variables/Makefile index 2c33cd3d8..73e3962ed 100644 --- a/Examples/octave/variables/Makefile +++ b/Examples/octave/variables/Makefile @@ -1,7 +1,7 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig SRCS = example.c -TARGET = example +TARGET = swigexample INTERFACE = example.i check: build @@ -11,9 +11,5 @@ build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave -static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static - clean: $(MAKE) -f $(TOP)/Makefile octave_clean diff --git a/Examples/octave/variables/example.c b/Examples/octave/variables/example.c index aa4ffe9b3..15dcc1b8e 100644 --- a/Examples/octave/variables/example.c +++ b/Examples/octave/variables/example.c @@ -11,7 +11,7 @@ #include #include "example.h" -int ivar = 0; +int ivar = 0; short svar = 0; long lvar = 0; unsigned int uivar = 0; diff --git a/Examples/octave/variables/example.h b/Examples/octave/variables/example.h index 0f7e89594..8d95fa1a4 100644 --- a/Examples/octave/variables/example.h +++ b/Examples/octave/variables/example.h @@ -3,4 +3,3 @@ typedef struct { int x,y; } Point; - diff --git a/Examples/octave/variables/example.i b/Examples/octave/variables/example.i index 639b6c704..3e11495ad 100644 --- a/Examples/octave/variables/example.i +++ b/Examples/octave/variables/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module example +%module swigexample %{ #include "example.h" %} @@ -50,4 +50,3 @@ extern Point *new_Point(int x, int y); extern char *Point_print(Point *p); extern void pt_print(); %} - diff --git a/Examples/octave/variables/runme.m b/Examples/octave/variables/runme.m index db88b18b0..c6788398b 100644 --- a/Examples/octave/variables/runme.m +++ b/Examples/octave/variables/runme.m @@ -1,56 +1,56 @@ # file: runme.m -example +swigexample # Try to set the values of some global variables -example.cvar.ivar = 42; -example.cvar.svar = -31000; -example.cvar.lvar = 65537; -example.cvar.uivar = 123456; -example.cvar.usvar = 61000; -example.cvar.ulvar = 654321; -example.cvar.scvar = -13; -example.cvar.ucvar = 251; -example.cvar.cvar = "S"; -example.cvar.fvar = 3.14159; -example.cvar.dvar = 2.1828; -example.cvar.strvar = "Hello World"; -example.cvar.iptrvar= example.new_int(37); -example.cvar.ptptr = example.new_Point(37,42); -example.cvar.name = "Bill"; +swigexample.cvar.ivar = 42; +swigexample.cvar.svar = -31000; +swigexample.cvar.lvar = 65537; +swigexample.cvar.uivar = 123456; +swigexample.cvar.usvar = 61000; +swigexample.cvar.ulvar = 654321; +swigexample.cvar.scvar = -13; +swigexample.cvar.ucvar = 251; +swigexample.cvar.cvar = "S"; +swigexample.cvar.fvar = 3.14159; +swigexample.cvar.dvar = 2.1828; +swigexample.cvar.strvar = "Hello World"; +swigexample.cvar.iptrvar= swigexample.new_int(37); +swigexample.cvar.ptptr = swigexample.new_Point(37,42); +swigexample.cvar.name = "Bill"; # Now print out the values of the variables printf("Variables (values printed from Octave)\n"); -printf("ivar = %i\n", example.cvar.ivar); -printf("svar = %i\n", example.cvar.svar); -printf("lvar = %i\n", example.cvar.lvar); -printf("uivar = %i\n", example.cvar.uivar); -printf("usvar = %i\n", example.cvar.usvar); -printf("ulvar = %i\n", example.cvar.ulvar); -printf("scvar = %i\n", example.cvar.scvar); -printf("ucvar = %i\n", example.cvar.ucvar); -printf("fvar = %i\n", example.cvar.fvar); -printf("dvar = %i\n", example.cvar.dvar); -printf("cvar = %s\n", example.cvar.cvar); -printf("strvar = %s\n", example.cvar.strvar); -#printf("cstrvar = %s\n", example.cvar.cstrvar); -example.cvar.iptrvar -printf("name = %i\n", example.cvar.name); -printf("ptptr = %s\n", example.Point_print(example.cvar.ptptr)); -#printf("pt = %s\n", example.cvar.Point_print(example.cvar.pt)); +printf("ivar = %i\n", swigexample.cvar.ivar); +printf("svar = %i\n", swigexample.cvar.svar); +printf("lvar = %i\n", swigexample.cvar.lvar); +printf("uivar = %i\n", swigexample.cvar.uivar); +printf("usvar = %i\n", swigexample.cvar.usvar); +printf("ulvar = %i\n", swigexample.cvar.ulvar); +printf("scvar = %i\n", swigexample.cvar.scvar); +printf("ucvar = %i\n", swigexample.cvar.ucvar); +printf("fvar = %i\n", swigexample.cvar.fvar); +printf("dvar = %i\n", swigexample.cvar.dvar); +printf("cvar = %s\n", swigexample.cvar.cvar); +printf("strvar = %s\n", swigexample.cvar.strvar); +#printf("cstrvar = %s\n", swigexample.cvar.cstrvar); +swigexample.cvar.iptrvar +printf("name = %i\n", swigexample.cvar.name); +printf("ptptr = %s\n", swigexample.Point_print(swigexample.cvar.ptptr)); +#printf("pt = %s\n", swigexample.cvar.Point_print(swigexample.cvar.pt)); printf("\nVariables (values printed from C)\n"); -example.print_vars(); +swigexample.print_vars(); printf("\nNow I'm going to try and modify some read only variables\n"); printf(" Tring to set 'path'\n"); try - example.cvar.path = "Whoa!"; + swigexample.cvar.path = "Whoa!"; printf("Hey, what's going on?!?! This shouldn't work\n"); catch printf("Good.\n"); @@ -58,7 +58,7 @@ end_try_catch printf(" Trying to set 'status'\n"); try - example.cvar.status = 0; + swigexample.cvar.status = 0; printf("Hey, what's going on?!?! This shouldn't work\n"); catch printf("Good.\n"); @@ -67,9 +67,6 @@ end_try_catch printf("\nI'm going to try and update a structure variable.\n"); -example.cvar.pt = example.cvar.ptptr; - -printf("The new value is %s\n", example.Point_print(example.cvar.pt)); - - +swigexample.cvar.pt = swigexample.cvar.ptptr; +printf("The new value is %s\n", swigexample.Point_print(swigexample.cvar.pt)); From 95e2142347fa2c69e2ddbe329584ce4a5eb09d51 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Thu, 9 May 2013 18:32:27 +0100 Subject: [PATCH 0608/1160] Update Octave manual to use "swigexample" instead of "example" Closes #46 --- Doc/Manual/Octave.html | 100 ++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 0340c2fd5..84c0a0f46 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -74,7 +74,7 @@ Let's start with a very simple SWIG interface file, example.i:

    -%module example
    +%module swigexample
     %{
     #include "example.h"
     %}
    @@ -143,10 +143,10 @@ $ mkoctfile example_wrap.cpp example.c
     

    - mkoctfile will produce "example.oct", which contains the compiled extension module. Loading it into Octave is then a matter of invoking + mkoctfile will produce "swigexample.oct", which contains the compiled extension module. Loading it into Octave is then a matter of invoking

    -
    octave:1> example
    +
    octave:1> swigexample

    30.2.3 Using your module

    @@ -157,13 +157,13 @@ Assuming all goes well, you will be able to do this:

    $ octave -q
    -octave:1> example
    -octave:2> example.gcd(4,6)
    +octave:1> swigexample
    +octave:2> swigexample.gcd(4,6)
     ans =  2
    -octave:3> example.cvar.Foo
    +octave:3> swigexample.cvar.Foo
     ans =  3
    -octave:4> example.cvar.Foo=4;
    -octave:5> example.cvar.Foo
    +octave:4> swigexample.cvar.Foo=4;
    +octave:5> swigexample.cvar.Foo
     ans =  4 

    30.3 A tour of basic C/C++ wrapping

    @@ -173,11 +173,11 @@ ans = 4

    -The SWIG module directive specifies the name of the Octave module. If you specify "module example", then in Octave everything in the module will be accessible under "example", as in the above example. When choosing a module name, make sure you don't use the same name as a built-in Octave command or standard module name. +The SWIG module directive specifies the name of the Octave module. If you specify "module swigexample", then in Octave everything in the module will be accessible under "swigexample", as in the above example. When choosing a module name, make sure you don't use the same name as a built-in Octave command or standard module name.

    -When Octave is asked to invoke example, it will try to find the ".m" or ".oct" file that defines the function "example". You therefore need to make sure that "example.oct" is in Octave's search path, which can be specified with the environment variable "OCTAVE_PATH". +When Octave is asked to invoke swigexample, it will try to find the ".m" or ".oct" file that defines the function "swigexample". You therefore need to make sure that "swigexample.oct" is in Octave's search path, which can be specified with the environment variable "OCTAVE_PATH".

    @@ -185,7 +185,7 @@ To load an Octave module, simply type its name:

    -octave:1> example;
    +octave:1> swigexample;
     octave:2> gcd(4,6)
     ans =  2
     octave:3> cvar.Foo
    @@ -202,15 +202,15 @@ If the module is also used in the base context, however, it must first be loaded
     
     
     octave:1> function l = my_lcm(a,b)
    -> example
    -> l = abs(a*b)/example.gcd(a,b);
    +> swigexample
    +> l = abs(a*b)/swigexample.gcd(a,b);
     > endfunction
     octave:2> my_lcm(4,6)
     ans =  12
    -octave:3> example.gcd(4,6)
    +octave:3> swigexample.gcd(4,6)
     error: can't perform indexing operations for <unknown type> type
    -octave:3> example;
    -octave:4> example.gcd(4,6)
    +octave:3> swigexample;
    +octave:4> swigexample.gcd(4,6)
     ans =  2
     
    @@ -221,14 +221,14 @@ ans = 2 Global functions are wrapped as new Octave built-in functions. For example,

    -
    %module example
    +      
    %module swigexample
     int fact(int n); 

    - creates a built-in function example.fact(n) that works exactly like you think it does: + creates a built-in function swigexample.fact(n) that works exactly like you think it does:

    -
    octave:1> example.fact(4)
    +    
    octave:1> swigexample.fact(4)
     24 

    30.3.3 Global variables

    @@ -238,7 +238,7 @@ int fact(int n);
    Global variables are a little special in Octave. Given a global variable:

    -
    %module example
    +
    %module swigexample
     extern double Foo;
     
    @@ -246,20 +246,20 @@ extern double Foo; To expose variables, SWIG actually generates two functions, to get and set the value. In this case, Foo_set and Foo_set would be generated. SWIG then automatically calls these functions when you get and set the variable-- in the former case creating a local copy in the interpreter of the C variables, and in the latter case copying an interpreter variables onto the C variable.

    -
    octave:1> example;
    -octave:2> c=example.cvar.Foo
    +    
    octave:1> swigexample;
    +octave:2> c=swigexample.cvar.Foo
     c =  3
    -octave:3> example.cvar.Foo=4;
    +octave:3> swigexample.cvar.Foo=4;
     octave:4> c
     c =  3
    -octave:5> example.cvar.Foo
    +octave:5> swigexample.cvar.Foo
     ans =  4

    If a variable is marked with the %immutable directive then any attempts to set this variable will cause an Octave error. Given a global variable:

    -
    %module example
    +    
    %module swigexample
     %immutable;
     extern double Foo;
     %mutable;
    @@ -269,8 +269,8 @@ extern double Foo;
          SWIG will allow the reading of Foo but when a set attempt is made, an error function will be called. 
     

    -
    octave:1> example
    -octave:2> example.Foo=4
    +    
    octave:1> swigexample
    +octave:2> swigexample.Foo=4
     error: attempt to set immutable member variable
     error: assignment failed, or no method for `swig_type = scalar'
     error: evaluating assignment expression near line 2, column 12 
    @@ -279,9 +279,9 @@ error: evaluating assignment expression near line 2, column 12
    It is possible to add new functions or variables to the module. This also allows the user to rename/remove existing functions and constants (but not linked variables, mutable or immutable). Therefore users are recommended to be careful when doing so.

    -
    octave:1> example;
    -octave:2> example.PI=3.142;
    -octave:3> example.PI
    +    
    octave:1> swigexample;
    +octave:2> swigexample.PI=3.142;
    +octave:3> swigexample.PI
     ans =  3.1420 

    30.3.4 Constants and enums

    @@ -291,7 +291,7 @@ ans = 3.1420
    Because Octave doesn't really have the concept of constants, C/C++ constants are not really constant in Octave. They are actually just a copy of the value into the Octave interpreter. Therefore they can be changed just as any other value. For example given some constants:

    -
    %module example
    +    
    %module swigexample
     %constant int ICONST=42;
     #define    SCONST      "Hello World"
     enum Days{SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY};
    @@ -301,9 +301,9 @@ enum Days{SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY};
         This is 'effectively' converted into the following Octave code: 
     

    -
    example.ICONST=42
    -example.SCONST="Hello World"
    -example.SUNDAY=0
    +    
    swigexample.ICONST=42
    +swigexample.SCONST="Hello World"
    +swigexample.SUNDAY=0
     .... 

    30.3.5 Pointers

    @@ -314,7 +314,7 @@ example.SUNDAY=0 C/C++ pointers are fully supported by SWIG. Furthermore, SWIG has no problem working with incomplete type information. Given a wrapping of the <file.h> interface:

    -
    %module example
    +
    %module swigexample
     FILE *fopen(const char *filename, const char *mode);
     int fputs(const char *, FILE *);
     int fclose(FILE *);
    @@ -325,18 +325,18 @@ When wrapped, you will be able to use the functions in a natural way from Octave
     

    -octave:1> example;
    -octave:2> f=example.fopen("w","junk");
    -octave:3> example.fputs("Hello world",f);
    -octave:4> example.fclose(f);
    +octave:1> swigexample;
    +octave:2> f=swigexample.fopen("w","junk");
    +octave:3> swigexample.fputs("Hello world",f);
    +octave:4> swigexample.fclose(f);
     

    Simply printing the value of a wrapped C++ type will print it's typename. E.g.,

    -
    octave:1> example;
    -octave:2> f=example.fopen("junk","w");
    +    
    octave:1> swigexample;
    +octave:2> f=swigexample.fopen("junk","w");
     octave:3> f
     f =
     
    @@ -348,8 +348,8 @@ f =
         As the user of the pointer, you are responsible for freeing it, or closing any resources associated with it (just as you would in a C program). This does not apply so strictly to classes and structs (see below).
     

    -
    octave:1> example;
    -octave:2> f=example.fopen("not there","r");
    +    
    octave:1> swigexample;
    +octave:2> f=swigexample.fopen("not there","r");
     error: value on right hand side of assignment is undefined
     error: evaluating assignment expression near line 2, column 2 
    @@ -371,8 +371,8 @@ For each wrapped structure and class, a swig_ref will be exposed that h

    -
    octave:1> example;
    -octave:2> p=example.Point();
    +      
    octave:1> swigexample;
    +octave:2> p=swigexample.Point();
     octave:3> p.x=3;
     octave:4> p.y=5;
     octave:5> p.x, p.y
    @@ -406,9 +406,9 @@ public:
     can be used from Octave like this
     

    -
    octave:1> example;
    -octave:2> p1=example.Point(3,5);
    -octave:3> p2=example.Point(1,2);
    +      
    octave:1> swigexample;
    +octave:2> p1=swigexample.Point(3,5);
    +octave:3> p2=swigexample.Point(1,2);
     octave:4> p1.distance(p2)
     ans =  3.6056
     
    @@ -649,7 +649,7 @@ C++ class and function templates are fully supported as in other modules, in tha For example, function templates can be instantiated as follows:

    -
    %module example
    +
    %module swigexample
     %inline {
      template<class __scalar>
        __scalar mul(__scalar a,__scalar b) {
    @@ -677,7 +677,7 @@ ans =  22 + 46i
     Similarly, class templates can be instantiated as in the following example,
     

    -
    %module example
    +
    %module swigexample
     %include <std_complex.i>
     %include <std_string.i>
     %inline {
    
    From d974e9aced1d371e156deca25fcc22f65d15a3f8 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Thu, 9 May 2013 08:21:02 +0100
    Subject: [PATCH 0609/1160] Guile examples consistency changes
    
    Use new guile_embedded_run target or guile_run target for running the
    examples like the other target languages (for suppressing stdout if run
    from top level).
    
    Consistency with other target language file renames: use runme.scm for
    scripts and example.i, example.c for example code.
    
    Add class example to examples being tested.
    ---
     Examples/Makefile.in                          |  3 +++
     Examples/guile/check.list                     |  1 +
     Examples/guile/class/Makefile                 |  2 ++
     Examples/guile/constants/Makefile             |  3 ++-
     .../constants/{constants.scm => runme.scm}    |  0
     Examples/guile/matrix/Makefile                |  5 ++--
     Examples/guile/matrix/README                  |  6 ++---
     .../guile/matrix/{package.i => example.i}     |  5 +---
     Examples/guile/matrix/main.c                  | 24 -------------------
     .../guile/matrix/{matrix.scm => runme.scm}    |  1 -
     Examples/guile/multimap/Makefile              |  2 +-
     Examples/guile/multivalue/Makefile            |  2 +-
     Examples/guile/port/Makefile                  |  7 +++---
     Examples/guile/port/README                    |  2 +-
     Examples/guile/port/{port.c => example.c}     |  0
     Examples/guile/port/{port.i => example.i}     |  0
     Examples/guile/port/{port.scm => runme.scm}   |  0
     Examples/guile/simple/Makefile                |  3 ++-
     Examples/guile/simple/README                  |  4 ++--
     .../guile/simple/{example.scm => runme.scm}   |  2 --
     Examples/guile/std_vector/Makefile            |  2 +-
     21 files changed, 27 insertions(+), 47 deletions(-)
     rename Examples/guile/constants/{constants.scm => runme.scm} (100%)
     rename Examples/guile/matrix/{package.i => example.i} (72%)
     delete mode 100644 Examples/guile/matrix/main.c
     rename Examples/guile/matrix/{matrix.scm => runme.scm} (99%)
     mode change 100644 => 100755
     rename Examples/guile/port/{port.c => example.c} (100%)
     rename Examples/guile/port/{port.i => example.i} (100%)
     rename Examples/guile/port/{port.scm => runme.scm} (100%)
     rename Examples/guile/simple/{example.scm => runme.scm} (93%)
    
    diff --git a/Examples/Makefile.in b/Examples/Makefile.in
    index a255db4c9..20f1cfea6 100644
    --- a/Examples/Makefile.in
    +++ b/Examples/Makefile.in
    @@ -515,6 +515,9 @@ guile_simple_cpp: $(SRCS)
     guile_run:
     	$(RUNTOOL) $(GUILE) -l $(GUILE_SCRIPT) $(RUNPIPE)
     
    +guile_embedded_run:
    +	$(RUNTOOL) ./$(TARGET) $(GUILE_RUNOPTIONS) -s $(GUILE_SCRIPT) $(RUNPIPE)
    +
     # -----------------------------------------------------------------
     # Version display
     # -----------------------------------------------------------------
    diff --git a/Examples/guile/check.list b/Examples/guile/check.list
    index 08524a8f7..726e6ab75 100644
    --- a/Examples/guile/check.list
    +++ b/Examples/guile/check.list
    @@ -1,5 +1,6 @@
     # see top-level Makefile.in
     constants
    +class
     port
     simple
     std_vector
    diff --git a/Examples/guile/class/Makefile b/Examples/guile/class/Makefile
    index 827b2fe03..189610800 100644
    --- a/Examples/guile/class/Makefile
    +++ b/Examples/guile/class/Makefile
    @@ -3,8 +3,10 @@ SWIG       = $(TOP)/../preinst-swig
     CXXSRCS    = example.cxx
     TARGET     = example
     INTERFACE  = example.i
    +TOP        = ../..
     
     check: build
    +#	$(MAKE) -f $(TOP)/Makefile guile_run
     
     build:
     	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
    diff --git a/Examples/guile/constants/Makefile b/Examples/guile/constants/Makefile
    index 946323b89..5e60d9b34 100644
    --- a/Examples/guile/constants/Makefile
    +++ b/Examples/guile/constants/Makefile
    @@ -2,9 +2,10 @@ SRCS   =
     TARGET = my-guile
     IFILE  = example.i
     MKDIR  = ..
    +TOP        = ../..
     
     check: build
    -	./my-guile -s constants.scm
    +	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_embedded_run
     
     build:
     	$(MAKE) -f $(MKDIR)/Makefile		\
    diff --git a/Examples/guile/constants/constants.scm b/Examples/guile/constants/runme.scm
    similarity index 100%
    rename from Examples/guile/constants/constants.scm
    rename to Examples/guile/constants/runme.scm
    diff --git a/Examples/guile/matrix/Makefile b/Examples/guile/matrix/Makefile
    index 988a0ee5c..3d488f6f6 100644
    --- a/Examples/guile/matrix/Makefile
    +++ b/Examples/guile/matrix/Makefile
    @@ -1,10 +1,11 @@
     SRCS   = matrix.c vector.c
     TARGET = matrix
    -IFILE  = package.i
    +IFILE  = example.i
     MKDIR  = ..
    +TOP        = ../..
     
     check: build
    -	./$(TARGET) -e do-test -s matrix.scm
    +	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' GUILE_RUNOPTIONS='-e do-test' guile_embedded_run
     
     build:
     	$(MAKE) -f $(MKDIR)/Makefile		\
    diff --git a/Examples/guile/matrix/README b/Examples/guile/matrix/README
    index dc1957719..db7395b70 100644
    --- a/Examples/guile/matrix/README
    +++ b/Examples/guile/matrix/README
    @@ -1,13 +1,13 @@
     Matrix example.  To run the example, execute the program 'matrix' and
     type the following :
     
    -	(load "matrix.scm")
    +	(load "runme.scm")
     	(do-test 0)
     
     Alternatively, use the command-line:
     
    -	./matrix -e do-test -s matrix.scm
    +	./matrix -e do-test -s runme.scm
     
     Or, if your operating system is spiffy enough:
     
    -	./matrix.scm
    +	./runme.scm
    diff --git a/Examples/guile/matrix/package.i b/Examples/guile/matrix/example.i
    similarity index 72%
    rename from Examples/guile/matrix/package.i
    rename to Examples/guile/matrix/example.i
    index aaa55511c..3f801dcdf 100644
    --- a/Examples/guile/matrix/package.i
    +++ b/Examples/guile/matrix/example.i
    @@ -1,7 +1,4 @@
    -// FILE : package.i
    -// See the SWIG users manual
    -
    -/*** Matrix and vector package ***/
    +/*** Matrix and vector example ***/
     
     %module Matrix
     %{
    diff --git a/Examples/guile/matrix/main.c b/Examples/guile/matrix/main.c
    deleted file mode 100644
    index 88209aea7..000000000
    --- a/Examples/guile/matrix/main.c
    +++ /dev/null
    @@ -1,24 +0,0 @@
    -#include 
    -extern int matrix_init(Tcl_Interp *);    /* Init function from matrix.i */
    -
    -int main() {
    -
    -  int        code;
    -  char       input[1024];
    -  Tcl_Interp *interp;
    -  
    -  interp = Tcl_CreateInterp();
    -
    -  /* Initialize the wrappers */
    -
    -  if (matrix_init(interp) == TCL_ERROR)
    -    exit(0);
    -  
    -  fprintf(stdout,"matrix > ");
    -  while(fgets(input, 1024, stdin) != NULL) {
    -    code = Tcl_Eval(interp, input);
    -    fprintf(stdout,"%s\n",interp->result);
    -    fprintf(stdout,"matrix > ");
    -  }
    -}
    -
    diff --git a/Examples/guile/matrix/matrix.scm b/Examples/guile/matrix/runme.scm
    old mode 100644
    new mode 100755
    similarity index 99%
    rename from Examples/guile/matrix/matrix.scm
    rename to Examples/guile/matrix/runme.scm
    index d7cab84f4..f11061e56
    --- a/Examples/guile/matrix/matrix.scm
    +++ b/Examples/guile/matrix/runme.scm
    @@ -211,4 +211,3 @@
     
       (cleanup M-list))
     
    -;;; matrix.scm ends here
    diff --git a/Examples/guile/multimap/Makefile b/Examples/guile/multimap/Makefile
    index 7b2f264ba..4ca82a3d3 100644
    --- a/Examples/guile/multimap/Makefile
    +++ b/Examples/guile/multimap/Makefile
    @@ -5,7 +5,7 @@ TARGET     = example
     INTERFACE  = example.i
     
     check: build
    -	$(MAKE) -f ../Makefile RUNSCRIPT=runme.scm run_example
    +	$(MAKE) -f $(TOP)/Makefile guile_run
     
     build:
     	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
    diff --git a/Examples/guile/multivalue/Makefile b/Examples/guile/multivalue/Makefile
    index 7b2f264ba..4ca82a3d3 100644
    --- a/Examples/guile/multivalue/Makefile
    +++ b/Examples/guile/multivalue/Makefile
    @@ -5,7 +5,7 @@ TARGET     = example
     INTERFACE  = example.i
     
     check: build
    -	$(MAKE) -f ../Makefile RUNSCRIPT=runme.scm run_example
    +	$(MAKE) -f $(TOP)/Makefile guile_run
     
     build:
     	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
    diff --git a/Examples/guile/port/Makefile b/Examples/guile/port/Makefile
    index 33eeab2e9..0088dd92f 100644
    --- a/Examples/guile/port/Makefile
    +++ b/Examples/guile/port/Makefile
    @@ -1,10 +1,10 @@
    -SRCS   = port.c
    +SRCS   = example.c
     TARGET = port
    -IFILE  = port.i
    +IFILE  = example.i
     MKDIR  = ..
     
     check: build
    -	./$(TARGET) -s port.scm
    +	./$(TARGET) -s runme.scm
     
     build:
     	$(MAKE) -f $(MKDIR)/Makefile		\
    @@ -16,3 +16,4 @@ build:
     
     clean:
     	$(MAKE) -f $(MKDIR)/Makefile TARGET='$(TARGET)' guile_clean
    +	rm -f test.out
    diff --git a/Examples/guile/port/README b/Examples/guile/port/README
    index 5ed0199e2..784e39e5d 100644
    --- a/Examples/guile/port/README
    +++ b/Examples/guile/port/README
    @@ -1,2 +1,2 @@
     This example illustrates the translation from Scheme file ports to
    -temporary FILE streams. Read the source and run ./port -s port.scm
    +temporary FILE streams. Read the source and run ./port -s runme.scm
    diff --git a/Examples/guile/port/port.c b/Examples/guile/port/example.c
    similarity index 100%
    rename from Examples/guile/port/port.c
    rename to Examples/guile/port/example.c
    diff --git a/Examples/guile/port/port.i b/Examples/guile/port/example.i
    similarity index 100%
    rename from Examples/guile/port/port.i
    rename to Examples/guile/port/example.i
    diff --git a/Examples/guile/port/port.scm b/Examples/guile/port/runme.scm
    similarity index 100%
    rename from Examples/guile/port/port.scm
    rename to Examples/guile/port/runme.scm
    diff --git a/Examples/guile/simple/Makefile b/Examples/guile/simple/Makefile
    index d4021073e..66c7e26af 100644
    --- a/Examples/guile/simple/Makefile
    +++ b/Examples/guile/simple/Makefile
    @@ -2,9 +2,10 @@ SRCS   = example.c
     TARGET = my-guile
     IFILE  = example.i
     MKDIR  = ..
    +TOP        = ../..
     
     check: $(TARGET)
    -	./$(TARGET) -s example.scm
    +	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_embedded_run
     
     build: $(TARGET)
     
    diff --git a/Examples/guile/simple/README b/Examples/guile/simple/README
    index 982216eaa..27b54dc5b 100644
    --- a/Examples/guile/simple/README
    +++ b/Examples/guile/simple/README
    @@ -2,8 +2,8 @@ A very simple example.
     
     To run it, start the program 'my-guile' and type:
     
    -	(load "example.scm")
    +	(load "runme.scm")
     
     Alternatively, you can use the shell command:
     
    -	./my-guile -s example.scm
    +	./my-guile -s runme.scm
    diff --git a/Examples/guile/simple/example.scm b/Examples/guile/simple/runme.scm
    similarity index 93%
    rename from Examples/guile/simple/example.scm
    rename to Examples/guile/simple/runme.scm
    index 9408b1aa6..c3fd0b41f 100644
    --- a/Examples/guile/simple/example.scm
    +++ b/Examples/guile/simple/runme.scm
    @@ -1,4 +1,3 @@
    -;;; example.scm
     
     (define (mdisplay-newline . args)       ; does guile-1.3.4 have `format #t'?
       (for-each display args)
    @@ -25,4 +24,3 @@
     (exit (and (= 1932053504 (fact 13))
                (= 745470.0 (My-variable))))
     
    -;;; example.scm ends here
    diff --git a/Examples/guile/std_vector/Makefile b/Examples/guile/std_vector/Makefile
    index 6eca67519..fd7a8439a 100644
    --- a/Examples/guile/std_vector/Makefile
    +++ b/Examples/guile/std_vector/Makefile
    @@ -5,7 +5,7 @@ TARGET     = example
     INTERFACE  = example.i
     
     check: build
    -	$(MAKE) -f ../Makefile RUNSCRIPT=runme.scm run_example
    +	$(MAKE) -f $(TOP)/Makefile guile_run
     
     build:
     	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
    
    From dd36f28ac7b28ecb78736894796bdcab9d945e07 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Thu, 9 May 2013 19:28:09 +0100
    Subject: [PATCH 0610/1160] Migrate Guile examples build into common Examples
     makefile
    
    - Now Guile examples are built in a consistent way to other target
    languages.
    - Also set GUILE_AUTO_COMPILE=0 to remove auto-compilation is enabled
      warnings
    ---
     Examples/Makefile.in              | 15 +++++++---
     Examples/guile/Makefile.in        | 47 -------------------------------
     Examples/guile/README             |  1 +
     Examples/guile/constants/Makefile | 19 ++++++-------
     Examples/guile/matrix/Makefile    | 21 ++++++--------
     Examples/guile/port/Makefile      | 19 ++++++-------
     Examples/guile/simple/Makefile    | 25 +++++++---------
     configure.ac                      |  1 -
     8 files changed, 46 insertions(+), 102 deletions(-)
     delete mode 100644 Examples/guile/Makefile.in
    
    diff --git a/Examples/Makefile.in b/Examples/Makefile.in
    index 20f1cfea6..5d521f5a1 100644
    --- a/Examples/Makefile.in
    +++ b/Examples/Makefile.in
    @@ -111,7 +111,6 @@ OBJS      = $(SRCS:.c=.@OBJEXT@) $(CXXSRCS:.cxx=.@OBJEXT@)
     
     distclean:
     	rm -f Makefile
    -	rm -f guile/Makefile
     	rm -f xml/Makefile
     
     ##################################################################
    @@ -482,6 +481,14 @@ $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO): $(SRCS)
     guile_externalhdr:
     	$(SWIG) -guile -external-runtime $(TARGET)
     
    +# -----------------------------------------------------------------
    +# Build Guile interpreter augmented with extra functions
    +# -----------------------------------------------------------------
    +
    +guile_augmented:
    +	$(SWIG) -guile $(SWIGOPT) $(INTERFACE)
    +	$(CC) $(CFLAGS) $(SRCS) $(ISRCS) $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) -o $(TARGET)
    +
     # -----------------------------------------------------------------
     # Build statically linked Guile interpreter
     # -----------------------------------------------------------------
    @@ -513,10 +520,10 @@ guile_simple_cpp: $(SRCS)
     # -----------------------------------------------------------------
     
     guile_run:
    -	$(RUNTOOL) $(GUILE) -l $(GUILE_SCRIPT) $(RUNPIPE)
    +	env GUILE_AUTO_COMPILE=0 $(RUNTOOL) $(GUILE) -l $(GUILE_SCRIPT) $(RUNPIPE)
     
    -guile_embedded_run:
    -	$(RUNTOOL) ./$(TARGET) $(GUILE_RUNOPTIONS) -s $(GUILE_SCRIPT) $(RUNPIPE)
    +guile_augmented_run:
    +	env GUILE_AUTO_COMPILE=0 $(RUNTOOL) ./$(TARGET) $(GUILE_RUNOPTIONS) -s $(GUILE_SCRIPT) $(RUNPIPE)
     
     # -----------------------------------------------------------------
     # Version display
    diff --git a/Examples/guile/Makefile.in b/Examples/guile/Makefile.in
    deleted file mode 100644
    index f84d54a38..000000000
    --- a/Examples/guile/Makefile.in
    +++ /dev/null
    @@ -1,47 +0,0 @@
    -# Makefile for Guile.  Used by all of the example programs.
    -
    -subdirs		= simple matrix port constants multimap multivalue
    -
    -top_srcdir	= @top_srcdir@
    -SWIG		= ../$(top_srcdir)/preinst-swig
    -CC		= @CC@
    -CXX		= @CXX@
    -CFLAGS		= @PLATFLAGS@
    -LIBS		=
    -GUILE		= @GUILE@
    -GUILE_CFLAGS	= @GUILE_CFLAGS@
    -GUILE_LIBS	= @GUILE_LIBS@
    -SWIGOPT		=
    -
    -WRAP		= $(IFILE:.i=_wrap.c)
    -CXXWRAP		= $(IFILE:.i=_wrap.cxx)
    -
    -SO		= @SO@
    -
    -all:
    -	for d in $(subdirs) ; do (cd $$d ; $(MAKE)) ; done
    -
    -clean:
    -	for d in $(subdirs) ; do (cd $$d ; $(MAKE) clean) ; done
    -	rm -f *~ .~*
    -
    -guile_clean:
    -	rm -f *.@OBJEXT@ *$(SO) *_wrap* *~ .~* core my-guile $(TARGET)
    -
    -# This is meant to be used w/ "make -f ../Makefile" from subdirs.
    -# Doesn't make sense to use it from here.
    -
    -sub-all:
    -	$(SWIG) -guile $(SWIGOPT) $(IFILE)
    -	$(CC) $(CFLAGS) -o $(TARGET) $(SRCS) $(WRAP) $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS)
    -
    -sub-all-cxx:
    -	$(SWIG) -c++ -guile $(SWIGOPT) $(IFILE)
    -	$(CXX) $(CFLAGS) -o $(TARGET) $(SRCS) $(CXXWRAP) $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS)
    -
    -run_example:
    -	if [ -f $(RUNSCRIPT) ]; then \
    -          env GUILE_AUTO_COMPILE=0 LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(GUILE) -l $(RUNSCRIPT); \
    -        fi
    -
    -# Makefile ends here
    diff --git a/Examples/guile/README b/Examples/guile/README
    index 7d726619e..03ce8e450 100644
    --- a/Examples/guile/README
    +++ b/Examples/guile/README
    @@ -1,6 +1,7 @@
     This directory contains examples for Guile.
     
     constants   -- handling #define and %constant literals
    +class       -- classic c++ class example
     matrix      -- a very simple Matrix example
     multimap    -- typemaps with multiple sub-types
     multivalue  -- using the %values_as_list directive
    diff --git a/Examples/guile/constants/Makefile b/Examples/guile/constants/Makefile
    index 5e60d9b34..d8a3cfebd 100644
    --- a/Examples/guile/constants/Makefile
    +++ b/Examples/guile/constants/Makefile
    @@ -1,18 +1,15 @@
    -SRCS   = 
    -TARGET = my-guile
    -IFILE  = example.i
    -MKDIR  = ..
     TOP        = ../..
    +SWIG       = $(TOP)/../preinst-swig
    +SRCS       = 
    +TARGET     = my-guile
    +INTERFACE  = example.i
     
     check: build
    -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_embedded_run
    +	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_augmented_run
     
     build:
    -	$(MAKE) -f $(MKDIR)/Makefile		\
    -		SRCS='$(SRCS)'			\
    -		TARGET=$(TARGET)		\
    -		IFILE=$(IFILE)			\
    -	    sub-all
    +	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
    +	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_augmented
     
     clean:
    -	$(MAKE) -f $(MKDIR)/Makefile TARGET='$(TARGET)' guile_clean
    +	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean
    diff --git a/Examples/guile/matrix/Makefile b/Examples/guile/matrix/Makefile
    index 3d488f6f6..8a6ff81de 100644
    --- a/Examples/guile/matrix/Makefile
    +++ b/Examples/guile/matrix/Makefile
    @@ -1,20 +1,15 @@
    -SRCS   = matrix.c vector.c
    -TARGET = matrix
    -IFILE  = example.i
    -MKDIR  = ..
     TOP        = ../..
    +SWIG       = $(TOP)/../preinst-swig
    +SRCS       = matrix.c vector.c
    +TARGET     = matrix
    +INTERFACE  = example.i
     
     check: build
    -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' GUILE_RUNOPTIONS='-e do-test' guile_embedded_run
    +	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' GUILE_RUNOPTIONS='-e do-test' guile_augmented_run
     
     build:
    -	$(MAKE) -f $(MKDIR)/Makefile		\
    -		SRCS='$(SRCS)'			\
    -		TARGET=$(TARGET)		\
    -		IFILE=$(IFILE)			\
    -		MODULE=$(MODULE)		\
    -		LIBS="-lm"			\
    -	  sub-all
    +	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
    +	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_augmented
     
     clean:
    -	$(MAKE) -f $(MKDIR)/Makefile TARGET='$(TARGET)' guile_clean
    +	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean
    diff --git a/Examples/guile/port/Makefile b/Examples/guile/port/Makefile
    index 0088dd92f..ec5d5198a 100644
    --- a/Examples/guile/port/Makefile
    +++ b/Examples/guile/port/Makefile
    @@ -1,19 +1,16 @@
    -SRCS   = example.c
    -TARGET = port
    -IFILE  = example.i
    -MKDIR  = ..
    +TOP        = ../..
    +SWIG       = $(TOP)/../preinst-swig
    +SRCS       = example.c
    +TARGET     = port
    +INTERFACE  = example.i
     
     check: build
     	./$(TARGET) -s runme.scm
     
     build:
    -	$(MAKE) -f $(MKDIR)/Makefile		\
    -		SRCS='$(SRCS)'			\
    -		TARGET=$(TARGET)		\
    -		IFILE=$(IFILE)			\
    -		MODULE=$(MODULE)		\
    -	  sub-all
    +	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
    +	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_augmented
     
     clean:
    -	$(MAKE) -f $(MKDIR)/Makefile TARGET='$(TARGET)' guile_clean
    +	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean
     	rm -f test.out
    diff --git a/Examples/guile/simple/Makefile b/Examples/guile/simple/Makefile
    index 66c7e26af..da4eb9015 100644
    --- a/Examples/guile/simple/Makefile
    +++ b/Examples/guile/simple/Makefile
    @@ -1,20 +1,15 @@
    -SRCS   = example.c
    -TARGET = my-guile
    -IFILE  = example.i
    -MKDIR  = ..
     TOP        = ../..
    +SWIG       = $(TOP)/../preinst-swig
    +SRCS       = example.c
    +TARGET     = my-guile
    +INTERFACE  = example.i
     
    -check: $(TARGET)
    -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_embedded_run
    +check: build
    +	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_augmented_run
     
    -build: $(TARGET)
    -
    -$(TARGET):
    -	$(MAKE) -f $(MKDIR)/Makefile		\
    -		SRCS='$(SRCS)'			\
    -		TARGET=$(TARGET)		\
    -		IFILE=$(IFILE)			\
    -	    sub-all
    +build:
    +	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
    +	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_augmented
     
     clean:
    -	$(MAKE) -f $(MKDIR)/Makefile TARGET='$(TARGET)' guile_clean
    +	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean
    diff --git a/configure.ac b/configure.ac
    index a618d55de..968764715 100644
    --- a/configure.ac
    +++ b/configure.ac
    @@ -2397,7 +2397,6 @@ AC_CONFIG_FILES([			        \
         swig.spec				        \
         Source/Makefile			        \
         Examples/Makefile			        \
    -    Examples/guile/Makefile		        \
         Examples/xml/Makefile		        \
         Examples/test-suite/chicken/Makefile	\
         Examples/test-suite/csharp/Makefile	        \
    
    From 042d0dfdc221eead3df0e0e779d82d75411fce59 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Thu, 9 May 2013 19:41:29 +0100
    Subject: [PATCH 0611/1160] Guile port example Makefile correction
    
    ---
     Examples/guile/port/Makefile | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/Examples/guile/port/Makefile b/Examples/guile/port/Makefile
    index ec5d5198a..d6ec0ac24 100644
    --- a/Examples/guile/port/Makefile
    +++ b/Examples/guile/port/Makefile
    @@ -5,7 +5,7 @@ TARGET     = port
     INTERFACE  = example.i
     
     check: build
    -	./$(TARGET) -s runme.scm
    +	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_augmented_run
     
     build:
     	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
    
    From 199c1f3249abd677e7d5d5e8b3c709e8d8019331 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Thu, 9 May 2013 20:03:50 +0100
    Subject: [PATCH 0612/1160] Add skeleton for run test for Guile class example
    
    ---
     Examples/guile/class/Makefile  | 2 +-
     Examples/guile/class/runme.scm | 6 ++++++
     2 files changed, 7 insertions(+), 1 deletion(-)
     create mode 100644 Examples/guile/class/runme.scm
    
    diff --git a/Examples/guile/class/Makefile b/Examples/guile/class/Makefile
    index 189610800..0130e5fc1 100644
    --- a/Examples/guile/class/Makefile
    +++ b/Examples/guile/class/Makefile
    @@ -6,7 +6,7 @@ INTERFACE  = example.i
     TOP        = ../..
     
     check: build
    -#	$(MAKE) -f $(TOP)/Makefile guile_run
    +	$(MAKE) -f $(TOP)/Makefile guile_run
     
     build:
     	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
    diff --git a/Examples/guile/class/runme.scm b/Examples/guile/class/runme.scm
    new file mode 100644
    index 000000000..6bd7bf299
    --- /dev/null
    +++ b/Examples/guile/class/runme.scm
    @@ -0,0 +1,6 @@
    +
    +(dynamic-call "scm_init_example_module" (dynamic-link "./libexample"))
    +
    +(format (current-error-port) "TODO: code to demonstrate the class example\n")
    +
    +(exit 0)
    
    From e5f6ec8912628ac27447e4d8c276098a4d8b24c6 Mon Sep 17 00:00:00 2001
    From: Geert Janssens 
    Date: Fri, 10 May 2013 18:29:26 +0200
    Subject: [PATCH 0613/1160] Guile fix matrix example
    
    Got broken in commit dd36f28ac7b28ecb78736894796bdcab9d945e07
    (Migrate Guile examples build into common Examples makefile)
    ---
     Examples/guile/matrix/Makefile | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/Examples/guile/matrix/Makefile b/Examples/guile/matrix/Makefile
    index 8a6ff81de..a32210e65 100644
    --- a/Examples/guile/matrix/Makefile
    +++ b/Examples/guile/matrix/Makefile
    @@ -9,7 +9,7 @@ check: build
     
     build:
     	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
    -	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_augmented
    +	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' LIBS='-lm' guile_augmented
     
     clean:
     	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean
    
    From ef160ec07297252524ccab6949e17834c8b5aafc Mon Sep 17 00:00:00 2001
    From: Karl Wette 
    Date: Thu, 9 May 2013 14:35:41 +0200
    Subject: [PATCH 0614/1160] Octave: remove allocation of new octave_value in
     SWIG_Octave_SetGlobalValue()
    
    - this introduces a memory leak, which becomes significant for large
      modules (many global variables) and many module re-loadings (e.g.
      during a long-running script)
    - the original motivation was to prevent double-frees on exit, but this
      problem appears to have been fixed by the _Exit() hack in later commits,
      and in any case is an issue only for Octave ~3.2, so it should be safe to
      remove; tested by running Octave examples/test suite with Debian 3.2.4 and
      built-from-source 3.2.4, 3.4.3, and 3.6.3
    ---
     Lib/octave/octrun.swg | 11 +----------
     1 file changed, 1 insertion(+), 10 deletions(-)
    
    diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg
    index dfb4a7702..8fdb12086 100644
    --- a/Lib/octave/octrun.swg
    +++ b/Lib/octave/octrun.swg
    @@ -1289,16 +1289,7 @@ SWIGRUNTIMEINLINE octave_value SWIG_Octave_GetGlobalValue(std::string name) {
     }
     
     SWIGRUNTIME void SWIG_Octave_SetGlobalValue(std::string name, const octave_value& value) {
    -  // It is critical that a newly-allocated octave_value is passed to set_global_value(),
    -  // since it and the Octave symbol table take references to the values assigned to it.
    -  // If we were to pass a reference to 'value' to set_global_value(), then the Octave
    -  // symbol table would hold a reference to a variable owned by the SWIG .oct module.
    -  // Both will think that they own the reference (since the .oct module is dynamically
    -  // loaded, it appears to have its own C++ runtime), and so they will both try to
    -  // de-allocate the octave_value on exit, resulting in a double-free or seg-fault.
    -  // This is prevented by giving Octave its own heap-allocated copy of 'value'.
    -  octave_value *pov = new octave_value(value);
    -  set_global_value(name, *pov);
    +  set_global_value(name, value);
     }
     
     SWIGRUNTIME void SWIG_Octave_LinkGlobalValue(std::string name) {
    
    From 93650b2911588fa1a91c6c0081b3dd7f61707969 Mon Sep 17 00:00:00 2001
    From: Karl Wette 
    Date: Thu, 9 May 2013 14:55:04 +0200
    Subject: [PATCH 0615/1160] Octave: install functions only once, when creating
     module
    
    - once installed, Octave functions can never really be uninstalled
      (clear -f doesn't prevent the function being called again), so
      it makes no sense to install functions more than once
    - this can lead to a significant speed-up of module loading times,
      up to a factor of 10 for a large module loaded multiple times
    ---
     Lib/octave/octruntime.swg | 18 ++++++++++--------
     1 file changed, 10 insertions(+), 8 deletions(-)
    
    diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg
    index 66b6e265a..43313c3d4 100644
    --- a/Lib/octave/octruntime.swg
    +++ b/Lib/octave/octruntime.swg
    @@ -288,6 +288,15 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) {
     
         SWIG_InstallOps(octave_swig_ref::static_type_id());
     
    +    octave_swig_type::swig_member_const_iterator mb;
    +    for (mb = module_ns->swig_members_begin(); mb != module_ns->swig_members_end(); ++mb) {
    +      if (mb->second.first && mb->second.first->method) {
    +        if (!SWIG_Octave_InstallFunction(me, mb->first)) {
    +          return octave_value_list();
    +        }
    +      }
    +    }
    +
     #if OCTAVE_API_VERSION_NUMBER < 37
         mlock(me->name());
     #else
    @@ -296,16 +305,9 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) {
     
       }
     
    -  octave_function *me = octave_call_stack::current();
    -
       octave_swig_type::swig_member_const_iterator mb;
       for (mb = module_ns->swig_members_begin(); mb != module_ns->swig_members_end(); ++mb) {
    -    if (mb->second.first && mb->second.first->method) {
    -      if (!SWIG_Octave_InstallFunction(me, mb->first)) {
    -        return octave_value_list();
    -      }
    -    }
    -    else if (mb->second.second.is_defined()) {
    +    if (mb->second.second.is_defined()) {
           SWIG_Octave_SetGlobalValue(mb->first, mb->second.second);
           SWIG_Octave_LinkGlobalValue(mb->first);
         }
    
    From d7839ce5701f628b8d8d50b5c207e0bc967b7576 Mon Sep 17 00:00:00 2001
    From: Karl Wette 
    Date: Thu, 9 May 2013 19:43:52 +0200
    Subject: [PATCH 0616/1160] Update changelog for the previous two Octave
     patches
    
    ---
     CHANGES.current | 5 +++++
     1 file changed, 5 insertions(+)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index 46b0d5589..eb3b0a8d1 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.10 (in progress)
     ============================
     
    +2013-05-09: kwwette
    +            [Octave] Fix bugs in Octave module loading:
    +            - fix a memory leak in setting of global variables
    +            - install functions only once, to speed up module loads
    +
     2013-04-28: gjanssens
                 [Guile] Updates in guile module:
                 - Add support for guile 2.0
    
    From 2733a0f7a318627f049998ed58d4d2041ac6666b Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Sat, 11 May 2013 10:31:16 +0100
    Subject: [PATCH 0617/1160] Update htmldoc patch to htmldoc-1.8.27
    
    Note: Best to use the patched source from Ubuntu/Debian which fixes some
    bugs.
    
    Also added "Patched with margin-left.patch" text to output of
      htmldoc --version
    ---
     Doc/Manual/margin-left.patch | 100 +++++++++++++++++++----------------
     1 file changed, 54 insertions(+), 46 deletions(-)
    
    diff --git a/Doc/Manual/margin-left.patch b/Doc/Manual/margin-left.patch
    index 70f087b92..8bef6305c 100644
    --- a/Doc/Manual/margin-left.patch
    +++ b/Doc/Manual/margin-left.patch
    @@ -1,25 +1,66 @@
    -#
    -# Patch managed by http://www.holgerschurig.de/patcher.html
    -#
    -# This patch is against htmldoc 1.8.24, and it hacks in support for
    +# This patch is against htmldoc 1.8.27, and it hacks in support for
     # correctly indenting the 
    sections in the SWIG manual. # This patch should only be used until the 1.9 branch of htmldoc -# stabalizes, since the 1.9 branch includes true CSS1 support. +# stabilizes, since the 1.9 branch includes true CSS1 support. # # This patch only affects the PDF generation, an unpatched htmldoc # creates the one-page html documentation just fine. # ---- htmldoc-1.8.24/htmldoc/ps-pdf.cxx~margin-left -+++ htmldoc-1.8.24/htmldoc/ps-pdf.cxx -@@ -158,6 +158,7 @@ +diff -Naur htmldoc-1.8.27/htmldoc/htmldoc.cxx htmldoc-1.8.27-margin-left/htmldoc/htmldoc.cxx +--- htmldoc-1.8.27/htmldoc/htmldoc.cxx 2006-03-30 14:01:20.000000000 +0100 ++++ htmldoc-1.8.27-margin-left/htmldoc/htmldoc.cxx 2013-05-11 10:11:47.428435647 +0100 +@@ -65,6 +65,8 @@ + const char *__XOS2RedirRoot(const char *); + } + #endif ++ ++extern void parse_style(char *); + + + /* +@@ -1115,6 +1117,7 @@ + else if (compare_strings(argv[i], "--version", 6) == 0) + { + puts(SVERSION); ++ puts("Patched with margin-left.patch"); + return (0); + } + else if (compare_strings(argv[i], "--webpage", 3) == 0) +@@ -2403,6 +2406,10 @@ + } + else if (strcmp(temp, "--cookies") == 0) + file_cookies(temp2); ++ else if (strcmp(temp, "--stylesheet") == 0) ++ { ++ parse_style(temp2); ++ } + } + } + +diff -Naur htmldoc-1.8.27/htmldoc/Makefile htmldoc-1.8.27-margin-left/htmldoc/Makefile +--- htmldoc-1.8.27/htmldoc/Makefile 2005-10-28 21:32:59.000000000 +0100 ++++ htmldoc-1.8.27-margin-left/htmldoc/Makefile 2013-05-11 09:39:04.392367869 +0100 +@@ -36,7 +36,7 @@ + OBJS = gui.o file.o html.o htmldoc.o htmllib.o htmlsep.o \ + http.o http-addr.o http-addrlist.o http-support.o image.o \ + iso8859.o license.o md5.o progress.o ps-pdf.o rc4.o \ +- snprintf.o string.o toc.o util.o ++ snprintf.o string.o toc.o util.o style.o + + + # +diff -Naur htmldoc-1.8.27/htmldoc/ps-pdf.cxx htmldoc-1.8.27-margin-left/htmldoc/ps-pdf.cxx +--- htmldoc-1.8.27/htmldoc/ps-pdf.cxx 2006-08-01 17:58:50.000000000 +0100 ++++ htmldoc-1.8.27-margin-left/htmldoc/ps-pdf.cxx 2013-05-11 09:37:40.096364957 +0100 +@@ -160,6 +160,7 @@ # undef page_t #endif // __hpux +extern int lookup_div_class(uchar *); /* - * Constants... -@@ -4188,9 +4189,24 @@ + * Output options... +@@ -4230,9 +4231,24 @@ para->child = para->last_child = NULL; } @@ -45,30 +86,9 @@ if (para->child != NULL) { parse_paragraph(para, *left, *right, *bottom, *top, x, y, page, *needspace); ---- htmldoc-1.8.24/htmldoc/htmldoc.cxx~margin-left -+++ htmldoc-1.8.24/htmldoc/htmldoc.cxx -@@ -62,6 +62,8 @@ - const char *__XOS2RedirRoot(const char *); - } - #endif -+ -+extern void parse_style(char *); - - - /* -@@ -2140,6 +2142,10 @@ - } - else if (strcmp(temp, "--cookies") == 0) - file_cookies(temp2); -+ else if (strcmp(temp, "--stylesheet") == 0) -+ { -+ parse_style(temp2); -+ } - } - } - ---- /dev/null -+++ htmldoc-1.8.24/htmldoc/style.cxx +diff -Naur htmldoc-1.8.27/htmldoc/style.cxx htmldoc-1.8.27-margin-left/htmldoc/style.cxx +--- htmldoc-1.8.27/htmldoc/style.cxx 1970-01-01 01:00:00.000000000 +0100 ++++ htmldoc-1.8.27-margin-left/htmldoc/style.cxx 2013-05-11 09:37:40.096364957 +0100 @@ -0,0 +1,185 @@ +/* Extreamly simple parsing routines for CSS style sheets. + * We only parse div.class { } sections, and only look @@ -255,15 +275,3 @@ + + fclose(f); +} ---- htmldoc-1.8.24/htmldoc/Makefile~margin-left -+++ htmldoc-1.8.24/htmldoc/Makefile -@@ -35,7 +35,7 @@ - - OBJS = gui.o file.o html.o htmldoc.o htmllib.o htmlsep.o http.o \ - http-addr.o http-support.o image.o iso8859.o license.o md5.o \ -- progress.o ps-pdf.o rc4.o snprintf.o string.o toc.o util.o -+ progress.o ps-pdf.o rc4.o snprintf.o string.o toc.o util.o style.o - - - # - From ea2e615cec87a469850605c6eda4f966ec1450da Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 12 May 2013 13:18:01 +0100 Subject: [PATCH 0618/1160] Fix some typos in directive names --- Doc/Manual/Allegrocl.html | 4 ++-- Doc/Manual/Lua.html | 2 +- Doc/Manual/Varargs.html | 2 +- Lib/typemaps/implicit.swg | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/Manual/Allegrocl.html b/Doc/Manual/Allegrocl.html index 283ff7e2c..12b915ee2 100644 --- a/Doc/Manual/Allegrocl.html +++ b/Doc/Manual/Allegrocl.html @@ -1613,7 +1613,7 @@ opoverload>

    Variable length argument lists are not supported, by default. If such a function is encountered, a warning will generated to - stderr. Varargs are supported via the SWIG %vararg + stderr. Varargs are supported via the SWIG %varargs directive. This directive allows you to specify a (finite) argument list which will be inserted into the wrapper in place of the variable length argument indicator. As an example, @@ -1624,7 +1624,7 @@ opoverload>

    See the following section on Variable Length arguments - provides examples on how %vararg can be used, along + provides examples on how %varargs can be used, along with other ways such functions can be wrapped.

    diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index 1fd41f907..88d26f385 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -1359,7 +1359,7 @@ extern void sort_double(double* arr, int len); to create an array in C/C++ then this can be filled within Lua and passed into the function. It works, but it's a bit tedious. More details can be found in the carrays.i documentation.

    -

    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.

    +

    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 %apply in the correct manner.

    The wrapper file below, shows both the use of carrays as well as the use of the typemap to wrap arrays.

    diff --git a/Doc/Manual/Varargs.html b/Doc/Manual/Varargs.html index 13abc8cee..a580c83bd 100644 --- a/Doc/Manual/Varargs.html +++ b/Doc/Manual/Varargs.html @@ -398,7 +398,7 @@ int execlp(const char *path, const char *arg, ...);

    -Note that str3 is the name of the last argument, as we have used %vargars with 3. +Note that str3 is the name of the last argument, as we have used %varargs with 3. Now execlp("a", "b", "c", "d", "e") will result in an error as one too many arguments has been passed, as now only 2 additional 'str' arguments can be passed with the 3rd one always using the specified default NULL.

    diff --git a/Lib/typemaps/implicit.swg b/Lib/typemaps/implicit.swg index 24bb3dcce..702fb52b8 100644 --- a/Lib/typemaps/implicit.swg +++ b/Lib/typemaps/implicit.swg @@ -1,5 +1,5 @@ /* - The %implict macro allows a SwigType (Class) to be accepted + The %implicit macro allows a SwigType (Class) to be accepted as an input parameter and use its implicit constructors when needed. For example: From 9812b27fb0a7e097a6b7a1a54a632ab39f48a2b4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 11 May 2013 07:47:52 +0100 Subject: [PATCH 0619/1160] Add .gitattributes file For specifying what not to export when running 'git archive' --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..596615322 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +.gitattributes export-ignore +.gitignore export-ignore From a5b0e34dea544ffcc61cb4f587e32cbebce3d727 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 12 May 2013 15:31:33 +0100 Subject: [PATCH 0620/1160] Update release scripts to use git instead of svn --- Tools/mkdist.py | 39 ++++++++++++++++++++++++++++++++++++--- Tools/mkrelease.py | 5 +---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Tools/mkdist.py b/Tools/mkdist.py index f2a04542c..1585523cf 100755 --- a/Tools/mkdist.py +++ b/Tools/mkdist.py @@ -6,6 +6,7 @@ import sys import string import os +import subprocess def failed(): print "mkdist.py failed to complete" @@ -34,10 +35,42 @@ os.system("rm -f "+dirname+".tar.gz") print "Removing "+dirname+".tar.gz if exists" os.system("rm -f "+dirname+".tar") -# Do a SVN export into the directory name +# Grab the code from git -print "Grabbing latest SWIG from svn" -os.system("svn export -r HEAD https://swig.svn.sourceforge.net/svnroot/swig/trunk "+dirname) == 0 or failed() +print "Checking git repository is in sync with remote repository" +os.system("git remote update") == 0 or failed() +command = ["git", "status", "--porcelain", "-uno"] +out = subprocess.check_output(command) +if out.strip() != "": + print "Local git repository has modifications" + print " ".join(command) + print out + sys.exit(3) + +command = ["git", "log", "--oneline", "master..origin/master"] +out = subprocess.check_output(command) +if out.strip() != "": + print "Remote repository has additional modifications to local repository" + print " ".join(command) + print out + sys.exit(3) + +command = ["git", "log", "--oneline", "origin/master..master"] +out = subprocess.check_output(command) +if out.strip() != "": + print "Local repository has modifications not pushed to the remote repository" + print "These should be pushed and checked that they pass Continuous Integration testing before continuing" + print " ".join(command) + print out + sys.exit(3) + +print "Tagging release" +tag = "'rel-" + version + "'" +os.system("git tag -a -m " + tag + " " + tag) == 0 or failed() + +print "Grabbing tagged release git repository using 'git archive' into " + outdir +outdir = os.path.basename(os.getcwd()) + "/" + dirname + "/" +os.system("(cd .. && git archive --prefix=" + outdir + tag + " . | tar -xf -)") == 0 or failed() # Remove the debian directory -- it's not official diff --git a/Tools/mkrelease.py b/Tools/mkrelease.py index 9ca96bc6f..9eceba07e 100755 --- a/Tools/mkrelease.py +++ b/Tools/mkrelease.py @@ -43,9 +43,6 @@ os.system("cat swig-" + version + "/README " + "swig-" + version + "/CHANGES.cur os.system("rsync --archive --verbose -P --times -e ssh " + "swig-" + version + ".tar.gz " + full_readme_file + " " + swig_dir_sf) and failed("") os.system("rsync --archive --verbose -P --times -e ssh " + "swigwin-" + version + ".zip " + full_readme_file + " " + 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" -print "Now log in to SourceForge and set the operating systems applicable to the newly uploaded tarball and zip file." +print "Now log in to SourceForge and set the operating systems applicable to the newly uploaded tarball and zip file. Also remember to do a 'git push'." From a3e23668824aa2f4a397fef95cedaee25d6d381f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 12 May 2013 19:16:42 +0100 Subject: [PATCH 0621/1160] Fix release script --- Tools/mkdist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/mkdist.py b/Tools/mkdist.py index 1585523cf..8bec81ea5 100755 --- a/Tools/mkdist.py +++ b/Tools/mkdist.py @@ -68,8 +68,8 @@ print "Tagging release" tag = "'rel-" + version + "'" os.system("git tag -a -m " + tag + " " + tag) == 0 or failed() -print "Grabbing tagged release git repository using 'git archive' into " + outdir outdir = os.path.basename(os.getcwd()) + "/" + dirname + "/" +print "Grabbing tagged release git repository using 'git archive' into " + outdir os.system("(cd .. && git archive --prefix=" + outdir + tag + " . | tar -xf -)") == 0 or failed() # Remove the debian directory -- it's not official From de12f6c25e6e50724626d4bf954d16bde59ef4cd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 12 May 2013 21:27:38 +0100 Subject: [PATCH 0622/1160] Fix release script --- Tools/mkdist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/mkdist.py b/Tools/mkdist.py index 8bec81ea5..234c768f2 100755 --- a/Tools/mkdist.py +++ b/Tools/mkdist.py @@ -70,7 +70,7 @@ os.system("git tag -a -m " + tag + " " + tag) == 0 or failed() outdir = os.path.basename(os.getcwd()) + "/" + dirname + "/" print "Grabbing tagged release git repository using 'git archive' into " + outdir -os.system("(cd .. && git archive --prefix=" + outdir + tag + " . | tar -xf -)") == 0 or failed() +os.system("(cd .. && git archive --prefix=" + outdir + " " + tag + " . | tar -xf -)") == 0 or failed() # Remove the debian directory -- it's not official From f09231d282f005e2b91664920ac3e64b85bea7b5 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 13 May 2013 12:27:21 +0200 Subject: [PATCH 0623/1160] Add CCache/ccache-swig.1 to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fbeebc67d..eb3aa012c 100644 --- a/.gitignore +++ b/.gitignore @@ -81,6 +81,7 @@ swig.spec # Build Artifacts .dirstamp CCache/ccache-swig +CCache/ccache-swig.1 Source/CParse/parser.c Source/CParse/parser.h Source/eswig From 3ddea71f332449a38b9c1827a1406dd0bfc66d62 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 13 May 2013 18:10:59 +0100 Subject: [PATCH 0624/1160] Clear up license ambiguity in swigwarn.swg. Also tidies up swigwarn.swg a bit. --- Makefile.in | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Makefile.in b/Makefile.in index cfa6d0933..0ac8c88f9 100644 --- a/Makefile.in +++ b/Makefile.in @@ -432,12 +432,8 @@ maintainer-clean: $(srcdir)/Lib/swigwarn.swg: $(srcdir)/Source/Include/swigwarn.h mkdir -p Lib - echo "/* Automatically generated file containing all the swig warning codes. */" > $@ - echo "/* Do not modify this file by hand, change 'Source/Include/swigwarn.h' */" >> $@ - echo "/* and use the command 'make Lib/swigwarn.swg' instead. */" >> $@ - echo >> $@; echo >> $@ - awk '/#define WARN/{$$1="%define"; $$2="SWIG"$$2; $$3=sprintf("%d %%enddef", $$3); print $$0; next;}\ - /#/{next;} {print $0}' < $? >> $@ + echo "/* SWIG warning codes */" > $@ + cat $? | grep "^#define WARN\|/\*.*\*/\|^[ \t]*$$" | sed 's/^#define \(WARN.*[0-9]\+\)\(.*\)$$/%define SWIG\1 %enddef\2/' >> $@ ##################################################################### # TARGETS: install & friends From 090d2505d1152b682527f80d6ac90b4382ff967d Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Mon, 13 May 2013 21:40:01 +0200 Subject: [PATCH 0625/1160] Guile create functional class example --- Examples/guile/class/runme.scm | 56 +++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/Examples/guile/class/runme.scm b/Examples/guile/class/runme.scm index 6bd7bf299..70fe63151 100644 --- a/Examples/guile/class/runme.scm +++ b/Examples/guile/class/runme.scm @@ -1,6 +1,60 @@ +; file: runme.py + +; This file illustrates the proxy class C++ interface generated +; by SWIG. (dynamic-call "scm_init_example_module" (dynamic-link "./libexample")) -(format (current-error-port) "TODO: code to demonstrate the class example\n") +; Convenience wrapper around the display function +; (which only accepts one argument at the time) + +(define (mdisplay-newline . args) + (for-each display args) + (newline)) + +; ----- Object creation ----- + +(mdisplay-newline "Creating some objects:") +(define c (new-Circle 10)) +(mdisplay-newline " Created circle " c) +(define s (new-Square 10)) +(mdisplay-newline " Created square " s) + +; ----- Access a static member ----- + +(mdisplay-newline "\nA total of " (Shape-nshapes) " shapes were created") + +; ----- Member data access ----- + +; Set the location of the object + +(Shape-x-set c 20) +(Shape-y-set c 30) + +(Shape-x-set s -10) +(Shape-y-set s 5) + +(mdisplay-newline "\nHere is their current position:") +(mdisplay-newline " Circle = (" (Shape-x-get c) "," (Shape-y-get c) ")") +(mdisplay-newline " Square = (" (Shape-x-get s) "," (Shape-y-get s) ")") + +; ----- Call some methods ----- + +(mdisplay-newline "\nHere are some properties of the shapes:") +(define (shape-props o) + (mdisplay-newline " " o) + (mdisplay-newline " area = " (Shape-area o)) + (mdisplay-newline " perimeter = " (Shape-perimeter o))) +(for-each shape-props (list c s)) + +(mdisplay-newline "\nGuess I'll clean up now") + +; Note: this invokes the virtual destructor +(delete-Shape c) +(delete-Shape s) + +(define s 3) +(mdisplay-newline (Shape-nshapes) " shapes remain") +(mdisplay-newline "Goodbye") (exit 0) From cb24c110df2e52d87c6f454e20002a2f342ff8e3 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Mon, 13 May 2013 22:31:29 +0200 Subject: [PATCH 0626/1160] Guile remove references to -gh and -scm from manual --- Doc/Manual/Guile.html | 65 +++++++++++-------------------------------- 1 file changed, 16 insertions(+), 49 deletions(-) diff --git a/Doc/Manual/Guile.html b/Doc/Manual/Guile.html index cfbfbd0b7..17e3a3fab 100644 --- a/Doc/Manual/Guile.html +++ b/Doc/Manual/Guile.html @@ -27,8 +27,7 @@
  • Typemaps
  • Representation of pointers as smobs
  • Exception Handling @@ -73,16 +72,13 @@ we explicitly prefix the context, e.g., "guile-module".

    23.3 Old GH Guile API

    -

    Support for the guile GH wrapper code generation has been dropped. The last -version of SWIG that can still generate guile GH wrapper code is 2.0.9. Please -use that version if you really need the GH wrapper code. - -

    Guile 1.8 and older could be interfaced using a two different api's, the SCM +

    Guile 1.8 and older could be interfaced using two different api's, the SCM or the GH API. The GH interface to guile is deprecated. Read more about why in the Guile manual. -

    The SCM wrapper generation assumes a guile version >= 1.8 and has several advantages over -the "-gh" wrapper generation including garbage collection and GOOPS support. +

    Support for the guile GH wrapper code generation has been dropped from SWIG. The last +version of SWIG that can still generate guile GH wrapper code is 2.0.9. Please +use that version if you really need the GH wrapper code.

    23.4 Linkage

    @@ -212,7 +208,7 @@ are using multiple modules.

    SWIG can also generate wrapper code that does all the Guile module declarations on its own if you pass it the -Linkage -module command-line option. This requires Guile 1.5.0 or later. +module command-line option.

    The module name is set with the -package and -module command-line options. Suppose you want to define @@ -235,7 +231,7 @@ shared libraries into Guile; all bindings are automatically put in newly created Guile modules.

    -(define my-so (dynamic-link "./libfoo.so"))
    +(define my-so (dynamic-link "./libfoo"))
     ;; create new module and put bindings there:
     (dynamic-call "scm_init_my_modules_foo_module" my-so) 
     
    @@ -424,7 +420,7 @@ representing the expected pointer type. See also If the Scheme object passed was not a SWIG smob representing a compatible pointer, a wrong-type-arg exception is raised. -

    23.7.1 GH Smobs

    +

    23.7.1 Smobs

    @@ -435,44 +431,19 @@ mangled type name. As Guile allows registering user types, so-called implemented now. The details will be discussed in the following.

    -

    A smob is a cons cell where the lower half of the CAR contains the smob type -tag, while the upper half of the CAR and the whole CDR are available. Every -module creates its own smob type in the clientdata field of the module. So the -lower 16 bits of the car of the smob store the tag and the upper 16 bits store -the index this type is in the array. We can then, given a smob, find its -swig_type_info struct by using the tag (lower 16 bits of car) to find which -module this type is in (since each tag is unique for the module). Then we use -the upper 16 bits to index into the array of types attached to this module. -Looking up the module from the tag is worst case O(# of modules) but average -case O(1). This is because the modules are stored in a circularly linked list, -and when we start searching the modules for the tag, we start looking with the -module that the function doing the lookup is in. SWIG_Guile_ConvertPtr() takes -as its first argument the swig_module_info * of the calling function, which is -where we start comparing tags. Most types will be looked up in the same module -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.

    - -

    23.7.2 SCM Smobs

    - - -

    The SCM interface (using the "-scm" argument to swig) uses swigrun.swg. -The whole type system, when it is first initialized, creates two smobs named "swig" and "collected_swig". +

    The whole type system, when it is first initialized, creates two smobs named "swig" and "collected_swig". The swig smob is used for non-garbage collected smobs, while the collected_swig smob is used as described below. Each smob has the same format, which is a double cell created by SCM_NEWSMOB2() The first word of data is the pointer to the object and the second word of data is the swig_type_info * -structure describing this type. This is a lot easier than the GH interface above because we can store -a pointer to the type info structure right in the type. With the GH interface, there was not enough -room in the smob to store two whole words of data so we needed to store part of the "swig_type_info address" -in the smob tag. If a generated GOOPS module has been loaded, smobs will be wrapped by the corresponding -GOOPS class.

    +structure describing this type. If a generated GOOPS module has been loaded, smobs will be wrapped by +the corresponding GOOPS class.

    -

    23.7.3 Garbage Collection

    +

    23.7.2 Garbage Collection

    -

    Garbage collection is a feature of the new SCM interface, and it is automatically included -if you pass the "-scm" flag to swig. Thus the swig garbage collection support requires guile >1.6. +

    Garbage collection is a feature of Guile since version 1.6. As SWIG now requires Guile > 1.8, +it is automatically included. Garbage collection works like this. Every swig_type_info structure stores in its clientdata field a pointer to the destructor for this type. The destructor is the generated wrapper around the delete function. So swig still exports a wrapper for the destructor, it just does not call scm_c_define_gsubr() for @@ -514,8 +485,7 @@ See Lib/exception.i for details.

    If invoked with the command-line option -procdoc file, SWIG creates documentation strings for the generated wrapper functions, describing the procedure signature and -return value, and writes them to file. You need Guile 1.4 -or later to make use of the documentation files. +return value, and writes them to file.

    SWIG can generate documentation strings in three formats, which are selected via the command-line option -procdocformat @@ -580,10 +550,7 @@ Guile's Object-Oriented Programming System (GOOPS). GOOPS is a sophisticated object system in the spirit of the Common Lisp Object System (CLOS). -

    GOOPS support is -only available with the new SCM interface (enabled with the --scm command-line option of SWIG). To enable GOOPS -support, pass the -proxy argument to +

    To enable GOOPS support, pass the -proxy argument to swig. This will export the GOOPS wrapper definitions into the module.scm file in the directory specified by -outdir or the current directory. GOOPS support requires either passive or module linkage.

    From 4e4b73e7c005bc074c41f57db99b64bbcfc8b138 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Mon, 13 May 2013 22:39:13 +0200 Subject: [PATCH 0627/1160] Put guile Example Makefile back under revision control --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index eb3aa012c..fb36302f6 100644 --- a/.gitignore +++ b/.gitignore @@ -64,7 +64,6 @@ CCache/config.h CCache/config.log CCache/config.status Examples/Makefile -Examples/guile/Makefile Examples/test-suite/*/Makefile Examples/xml/Makefile Lib/ocaml/swigp4.ml From d3cddb135599fa614a49fd0828fa1f1247275c8b Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Mon, 13 May 2013 22:40:16 +0200 Subject: [PATCH 0628/1160] Guile add two more examples and use load-extension instead of dynamic-load --- Examples/guile/Makefile | 47 +++++++++++++++++++++++++++++ Examples/guile/class/runme.scm | 4 +-- Examples/guile/multimap/runme.scm | 2 +- Examples/guile/multivalue/runme.scm | 2 +- Examples/guile/std_vector/runme.scm | 2 +- 5 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 Examples/guile/Makefile diff --git a/Examples/guile/Makefile b/Examples/guile/Makefile new file mode 100644 index 000000000..93381dfc0 --- /dev/null +++ b/Examples/guile/Makefile @@ -0,0 +1,47 @@ +# Makefile for Guile. Used by all of the example programs. + +subdirs = simple matrix port constants class multimap multivalue std_vector + +top_srcdir = ../.. +SWIG = ../$(top_srcdir)/preinst-swig +CC = gcc +CXX = g++ +CFLAGS = +LIBS = +GUILE = /usr/bin/guile +GUILE_CFLAGS = -pthread +GUILE_LIBS = -pthread -lguile +SWIGOPT = + +WRAP = $(IFILE:.i=_wrap.c) +CXXWRAP = $(IFILE:.i=_wrap.cxx) + +SO = .so + +all: + for d in $(subdirs) ; do (cd $$d ; $(MAKE)) ; done + +clean: + for d in $(subdirs) ; do (cd $$d ; $(MAKE) clean) ; done + rm -f *~ .~* + +guile_clean: + rm -f *.o *$(SO) *_wrap* *~ .~* core my-guile $(TARGET) + +# This is meant to be used w/ "make -f ../Makefile" from subdirs. +# Doesn't make sense to use it from here. + +sub-all: + $(SWIG) -guile $(SWIGOPT) $(IFILE) + $(CC) $(CFLAGS) -o $(TARGET) $(SRCS) $(WRAP) $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) + +sub-all-cxx: + $(SWIG) -c++ -guile $(SWIGOPT) $(IFILE) + $(CXX) $(CFLAGS) -o $(TARGET) $(SRCS) $(CXXWRAP) $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) + +run_example: + if [ -f $(RUNSCRIPT) ]; then \ + env GUILE_AUTO_COMPILE=0 LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(GUILE) -l $(RUNSCRIPT); \ + fi + +# Makefile ends here diff --git a/Examples/guile/class/runme.scm b/Examples/guile/class/runme.scm index 70fe63151..4e47d458d 100644 --- a/Examples/guile/class/runme.scm +++ b/Examples/guile/class/runme.scm @@ -1,9 +1,9 @@ -; file: runme.py +; file: runme.scm ; This file illustrates the proxy class C++ interface generated ; by SWIG. -(dynamic-call "scm_init_example_module" (dynamic-link "./libexample")) +(load-extension "./libexample" "scm_init_example_module") ; Convenience wrapper around the display function ; (which only accepts one argument at the time) diff --git a/Examples/guile/multimap/runme.scm b/Examples/guile/multimap/runme.scm index d2ab8036e..a4a518a02 100644 --- a/Examples/guile/multimap/runme.scm +++ b/Examples/guile/multimap/runme.scm @@ -1,6 +1,6 @@ ;;; Test out some multi-argument typemaps -(dynamic-call "scm_init_example_module" (dynamic-link "./libexample")) +(load-extension "./libexample" "scm_init_example_module") ; Call the GCD function diff --git a/Examples/guile/multivalue/runme.scm b/Examples/guile/multivalue/runme.scm index 729f3fa18..0f65797ca 100644 --- a/Examples/guile/multivalue/runme.scm +++ b/Examples/guile/multivalue/runme.scm @@ -1,6 +1,6 @@ ;;;; Show the three different ways to deal with multiple return values -(dynamic-call "scm_init_example_module" (dynamic-link "./libexample")) +(load-extension "./libexample" "scm_init_example_module") ;;; Multiple values as lists. By default, if more than one value is to ;;; be returned, a list of the values is created and returned. The diff --git a/Examples/guile/std_vector/runme.scm b/Examples/guile/std_vector/runme.scm index 470f22922..64f56a147 100644 --- a/Examples/guile/std_vector/runme.scm +++ b/Examples/guile/std_vector/runme.scm @@ -1,5 +1,5 @@ -(dynamic-call "scm_init_example_module" (dynamic-link "./libexample")) +(load-extension "./libexample" "scm_init_example_module") ; repeatedly invoke a procedure with v and an index as arguments (define (with-vector v proc size-proc) From 4de24d1d11b4b8eec27ffcd5cf91bba9b009fdc6 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Tue, 14 May 2013 17:06:04 +0200 Subject: [PATCH 0629/1160] Guile check for at least guile 1.8 --- configure.ac | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/configure.ac b/configure.ac index 968764715..65d2a4c20 100644 --- a/configure.ac +++ b/configure.ac @@ -1204,6 +1204,17 @@ else fi fi + if test -f "$GUILE" ; then + AC_MSG_CHECKING([for guile version]) + guile_version=`guile -c '(display (effective-version))'` + AC_MSG_RESULT([$guile_version]) + guile -c '(if (>= (string->number (effective-version)) 1.8) (exit 0) (exit 1))' + if test $? -ne 0 ; then + AC_MSG_WARN(Not Guile >= 1.8, SWIG does not support this version of Guile) + GUILE= + fi + fi + if test -z "$GUILE_CFLAGS" ; then AC_MSG_CHECKING([for guile compile flags]) GUILE_CFLAGS="`$GUILE_CONFIG compile`" # Note that this can sometimes be empty From f3870303c6a2d922832b624d2e3fbafe46d7ba56 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Tue, 14 May 2013 17:06:35 +0200 Subject: [PATCH 0630/1160] Guile drop unused GUILE_SCM_INTERFACE parameter from configure.ac --- configure.ac | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 65d2a4c20..d0b6b66e4 100644 --- a/configure.ac +++ b/configure.ac @@ -1226,15 +1226,12 @@ else GUILE_LIBS="`$GUILE_CONFIG link`" AC_MSG_RESULT([$GUILE_LIBS]) fi - - GUILE_SCM_INTERFACE=1 fi fi AC_SUBST(GUILE) AC_SUBST(GUILE_CFLAGS) AC_SUBST(GUILE_LIBS) -AC_SUBST(GUILE_SCM_INTERFACE) #---------------------------------------------------------------- # Look for MzScheme @@ -2234,7 +2231,7 @@ AC_SUBST(SKIP_JAVA) SKIP_GUILE= -if test -z "$GUILE" || test -z "$GUILE_LIBS" || test -z "$GUILE_SCM_INTERFACE"; then +if test -z "$GUILE" || test -z "$GUILE_LIBS" ; then SKIP_GUILE="1" fi AC_SUBST(SKIP_GUILE) From 2560210bfdc9ab76feef26b2f820de092b48190e Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Wed, 15 May 2013 09:38:50 +0200 Subject: [PATCH 0631/1160] Guile delete Example makefile --- .gitignore | 1 + Examples/guile/Makefile | 47 ----------------------------------------- 2 files changed, 1 insertion(+), 47 deletions(-) delete mode 100644 Examples/guile/Makefile diff --git a/.gitignore b/.gitignore index fb36302f6..eb3aa012c 100644 --- a/.gitignore +++ b/.gitignore @@ -64,6 +64,7 @@ CCache/config.h CCache/config.log CCache/config.status Examples/Makefile +Examples/guile/Makefile Examples/test-suite/*/Makefile Examples/xml/Makefile Lib/ocaml/swigp4.ml diff --git a/Examples/guile/Makefile b/Examples/guile/Makefile deleted file mode 100644 index 93381dfc0..000000000 --- a/Examples/guile/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -# Makefile for Guile. Used by all of the example programs. - -subdirs = simple matrix port constants class multimap multivalue std_vector - -top_srcdir = ../.. -SWIG = ../$(top_srcdir)/preinst-swig -CC = gcc -CXX = g++ -CFLAGS = -LIBS = -GUILE = /usr/bin/guile -GUILE_CFLAGS = -pthread -GUILE_LIBS = -pthread -lguile -SWIGOPT = - -WRAP = $(IFILE:.i=_wrap.c) -CXXWRAP = $(IFILE:.i=_wrap.cxx) - -SO = .so - -all: - for d in $(subdirs) ; do (cd $$d ; $(MAKE)) ; done - -clean: - for d in $(subdirs) ; do (cd $$d ; $(MAKE) clean) ; done - rm -f *~ .~* - -guile_clean: - rm -f *.o *$(SO) *_wrap* *~ .~* core my-guile $(TARGET) - -# This is meant to be used w/ "make -f ../Makefile" from subdirs. -# Doesn't make sense to use it from here. - -sub-all: - $(SWIG) -guile $(SWIGOPT) $(IFILE) - $(CC) $(CFLAGS) -o $(TARGET) $(SRCS) $(WRAP) $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) - -sub-all-cxx: - $(SWIG) -c++ -guile $(SWIGOPT) $(IFILE) - $(CXX) $(CFLAGS) -o $(TARGET) $(SRCS) $(CXXWRAP) $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) - -run_example: - if [ -f $(RUNSCRIPT) ]; then \ - env GUILE_AUTO_COMPILE=0 LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(GUILE) -l $(RUNSCRIPT); \ - fi - -# Makefile ends here From b14b1c6de09ae48675722c2aa7709c7ace63de12 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 14 May 2013 19:49:32 +0100 Subject: [PATCH 0632/1160] Use given Guile version when checking if version is > 1.8 Also use conventional output for our configure if something is not working as expected. --- configure.ac | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index d0b6b66e4..c94c2e962 100644 --- a/configure.ac +++ b/configure.ac @@ -1206,11 +1206,12 @@ else if test -f "$GUILE" ; then AC_MSG_CHECKING([for guile version]) - guile_version=`guile -c '(display (effective-version))'` + guile_version=`$GUILE -c '(display (effective-version))'` AC_MSG_RESULT([$guile_version]) - guile -c '(if (>= (string->number (effective-version)) 1.8) (exit 0) (exit 1))' - if test $? -ne 0 ; then - AC_MSG_WARN(Not Guile >= 1.8, SWIG does not support this version of Guile) + AC_MSG_CHECKING([for guile version >= 1.8]) + guile_good_version=`$GUILE -c '(if (>= (string->number (effective-version)) 1.8) (display "yes") (display "no"))'` + AC_MSG_RESULT([$guile_good_version]) + if test x"$guile_good_version" != xyes ; then GUILE= fi fi From 6f1aea7a12772ade649a4a92ff4f07dafe0cd520 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 14 May 2013 21:32:09 +0100 Subject: [PATCH 0633/1160] Cosmetic makefile tidy up --- Examples/guile/class/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Examples/guile/class/Makefile b/Examples/guile/class/Makefile index 0130e5fc1..8de4f292b 100644 --- a/Examples/guile/class/Makefile +++ b/Examples/guile/class/Makefile @@ -3,7 +3,6 @@ SWIG = $(TOP)/../preinst-swig CXXSRCS = example.cxx TARGET = example INTERFACE = example.i -TOP = ../.. check: build $(MAKE) -f $(TOP)/Makefile guile_run From 3f9d7ed4165602af52e3bdad6d2641b8106427d5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 16 May 2013 08:07:09 +0100 Subject: [PATCH 0634/1160] Minor fixes after Coverity analysis --- Source/Modules/csharp.cxx | 2 +- Source/Modules/java.cxx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 6d5c570b1..44db84264 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3671,7 +3671,7 @@ public: Replaceall(pre, "$iminput", ln); if (Len(pre_code) > 0) Printf(pre_code, "\n"); - Printv(pre_code, pre, NIL); + Printv(pre_code, pre, NIL); } String *post = Getattr(p, "tmap:csdirectorin:post"); if (post) { diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index dbd110d56..b99bbb4ee 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -138,6 +138,7 @@ public: imclass_imports(NULL), module_imports(NULL), imclass_baseclass(NULL), + imclass_package(NULL), module_baseclass(NULL), imclass_interfaces(NULL), module_interfaces(NULL), From 04b9037c707f3fd179ded0648fa654aa9c95a2a8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 16 May 2013 19:21:59 +0100 Subject: [PATCH 0635/1160] Simplify and improve Guile FILE * in typemap Fix incorrect special variable $name and remove unnecessary temporary variable. --- Lib/guile/ports.i | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/Lib/guile/ports.i b/Lib/guile/ports.i index 5940b4d3b..7691d3e31 100644 --- a/Lib/guile/ports.i +++ b/Lib/guile/ports.i @@ -21,33 +21,30 @@ */ %typemap(in, doc="$NAME is a file port or a FILE * pointer") FILE * - ( int closep ) { - if (SWIG_ConvertPtr($input, (void**) &($1), $1_descriptor, 0) == 0) { - closep = 0; - } - else if(!(SCM_FPORTP($input))) - scm_wrong_type_arg("$name", $argnum, $input); - else { - int fd; - if (SCM_OUTPUT_PORT_P($input)) - scm_force_output($input); - fd=dup(SCM_FPORT_FDES($input)); - if(fd==-1) - scm_misc_error("$name", strerror(errno), SCM_EOL); - $1=fdopen(fd, - SCM_OUTPUT_PORT_P($input) - ? (SCM_INPUT_PORT_P($input) - ? "r+" : "w") - : "r"); - if($1==NULL) - scm_misc_error("$name", strerror(errno), SCM_EOL); - closep = 1; + if (SWIG_ConvertPtr($input, (void**) &($1), $1_descriptor, 0) != 0) { + if (!(SCM_FPORTP($input))) { + scm_wrong_type_arg("$symname", $argnum, $input); + } else { + int fd; + if (SCM_OUTPUT_PORT_P($input)) { + scm_force_output($input); + } + fd=dup(SCM_FPORT_FDES($input)); + if (fd==-1) { + scm_misc_error("$symname", strerror(errno), SCM_EOL); + } + $1=fdopen(fd, SCM_OUTPUT_PORT_P($input) ? (SCM_INPUT_PORT_P($input) ? "r+" : "w") : "r"); + if ($1==NULL) { + scm_misc_error("$symname", strerror(errno), SCM_EOL); + } + } } } %typemap(freearg) FILE* { - if (closep$argnum) + if ($1) { fclose($1); + } } From 4ba9365e0f398b9cec0dbb9f8950b23e47507c28 Mon Sep 17 00:00:00 2001 From: William Fulton Date: Sun, 19 May 2013 00:44:06 +0100 Subject: [PATCH 0636/1160] Fix ccache-swig internal error bug due to premature file cleanup Fixes SF bug 1319 which shows up as a failure in the ccache tests on Debian 64 bit Wheezy, possibly because ENABLE_ZLIB is defined. This bug is due to files being too aggressively cleaned up part way through the caching. The .stderr file is cached and then retrieved from the cache for displaying to stderr. However, the stats are updated between caching and using the .stderr file. During the stats update the cache is cleaned and the newly cached files can be removed if the max number of files per directory is low. Really the cache should be cleaned up at exit to solve this (as is done in ccache-3.1). The workaround fix ensures the cached files are ignored during cleanup, which is a bit tricky as sometimes files from a previous run have the same time stamp, so that don't appear to be the oldest in the cache. --- CCache/ccache.h | 2 +- CCache/cleanup.c | 28 ++++++++++++++++++++++++---- CCache/stats.c | 3 ++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CCache/ccache.h b/CCache/ccache.h index 668ce8288..3c3e22311 100644 --- a/CCache/ccache.h +++ b/CCache/ccache.h @@ -159,7 +159,7 @@ int asprintf(char **ptr, const char *format, ...); int snprintf(char *,size_t ,const char *, ...); #endif -void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize); +void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize, size_t minfiles); void cleanup_all(const char *dir); void wipe_all(const char *dir); diff --git a/CCache/cleanup.c b/CCache/cleanup.c index 99312283e..f54ee54d9 100644 --- a/CCache/cleanup.c +++ b/CCache/cleanup.c @@ -75,21 +75,40 @@ static void traverse_fn(const char *fname, struct stat *st) /* sort the files we've found and delete the oldest ones until we are below the thresholds */ -static void sort_and_clean(void) +static void sort_and_clean(size_t minfiles) { unsigned i; + size_t adjusted_minfiles = minfiles; if (num_files > 1) { /* sort in ascending data order */ qsort(files, num_files, sizeof(struct files *), (COMPAR_FN_T)files_compare); } + /* ensure newly cached files (minfiles) are kept - instead of matching + the filenames of those newly cached, a faster and simpler approach + assumes these are the most recent in the cache and if any other + cached files have an identical time stamp, they will also be kept - + this approach would not be needed if the cleanup was done at exit. */ + if (minfiles != 0 && minfiles < num_files) { + unsigned minfiles_index = num_files - minfiles; + time_t minfiles_time = files[minfiles_index]->mtime; + for (i=1; i<=minfiles_index; i++) { + if (files[minfiles_index-i]->mtime == minfiles_time) + adjusted_minfiles++; + else + break; + } + } /* delete enough files to bring us below the threshold */ for (i=0;ifname) != 0 && errno != ENOENT) { fprintf(stderr, "unlink %s - %s\n", files[i]->fname, strerror(errno)); @@ -103,7 +122,7 @@ static void sort_and_clean(void) } /* cleanup in one cache subdir */ -void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize) +void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize, size_t minfiles) { unsigned i; @@ -117,7 +136,7 @@ void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize) traverse(dir, traverse_fn); /* clean the cache */ - sort_and_clean(); + sort_and_clean(minfiles); stats_set_sizes(dir, total_files, total_size); @@ -151,7 +170,8 @@ void cleanup_all(const char *dir) cleanup_dir(dname, counters[STATS_MAXFILES], - counters[STATS_MAXSIZE]); + counters[STATS_MAXSIZE], + 0); free(dname); free(sfile); } diff --git a/CCache/stats.c b/CCache/stats.c index 92bc4a835..d2122bcd3 100644 --- a/CCache/stats.c +++ b/CCache/stats.c @@ -168,7 +168,8 @@ static void stats_update_size(enum stats stat, size_t size, size_t numfiles) if (need_cleanup) { char *p = dirname(stats_file); - cleanup_dir(p, counters[STATS_MAXFILES], counters[STATS_MAXSIZE]); + cleanup_dir(p, counters[STATS_MAXFILES], counters[STATS_MAXSIZE], + numfiles); free(p); } } From 149972542ed42753ff3d67c98c46020f7df94e5c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 19 May 2013 01:16:23 +0100 Subject: [PATCH 0637/1160] Add note on ccache-swig internal error bug due to premature file cleanup to changes file --- CHANGES.current | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index eb3b0a8d1..3d41780c2 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,15 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.10 (in progress) ============================ +2013-05-19: wsfulton + Fix ccache-swig internal error bug due to premature file cleanup. + + Fixes SF bug 1319 which shows up as a failure in the ccache tests on + Debian 64 bit Wheezy, possibly because ENABLE_ZLIB is defined. + + This is a corner case which will be hit when the maximum number of files + in the cache is set to be quite low (-F option), resulting in a cache miss. + 2013-05-09: kwwette [Octave] Fix bugs in Octave module loading: - fix a memory leak in setting of global variables From 6e794da3f3d74cef1a049780d0dab40a1a4326b3 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Tue, 21 May 2013 17:23:37 +0200 Subject: [PATCH 0638/1160] Guile port example - print a message to show the error is expected --- Examples/guile/port/runme.scm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Examples/guile/port/runme.scm b/Examples/guile/port/runme.scm index 68e9b8e85..1a9b93038 100644 --- a/Examples/guile/port/runme.scm +++ b/Examples/guile/port/runme.scm @@ -21,6 +21,8 @@ (lambda () (print-int (current-output-port) 314159)))) (lambda args + (display "Attempting to write to a string or soft port will result in this error:") + (newline) (write args) (newline))) ;; Read from a file port. Note that it is a bad idea to mix Scheme and From 0f1e3da5deae77c100ed3d72243208d63ae4c1db Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 23 May 2013 19:30:58 +0100 Subject: [PATCH 0639/1160] Fix the high passed to PyTuple_GetSlice in varargs wrappers. Harmless bug as slices can take any size larger than the actual size for the high value. Reported in SF Bug 1326. --- .../test-suite/python/python_varargs_typemap_runme.py | 3 +++ Examples/test-suite/python_varargs_typemap.i | 8 ++++++-- Source/Modules/python.cxx | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/python/python_varargs_typemap_runme.py b/Examples/test-suite/python/python_varargs_typemap_runme.py index 3c3f042eb..79479e449 100644 --- a/Examples/test-suite/python/python_varargs_typemap_runme.py +++ b/Examples/test-suite/python/python_varargs_typemap_runme.py @@ -2,3 +2,6 @@ import python_varargs_typemap if (python_varargs_typemap.testfunc(1, 2.0, "three") != "three") : raise RuntimeError("testfunc failed!") + +if (python_varargs_typemap.testfunc(1, 2.0, "three", "four", "five") != "threefourfive") : + raise RuntimeError("testfunc failed!") diff --git a/Examples/test-suite/python_varargs_typemap.i b/Examples/test-suite/python_varargs_typemap.i index 4bc6f3fbd..09189f654 100644 --- a/Examples/test-suite/python_varargs_typemap.i +++ b/Examples/test-suite/python_varargs_typemap.i @@ -51,10 +51,14 @@ char* testfunc (int arg1, double arg2, ...) { va_list ap; char *c; + static char buffer[1024]; + buffer[0] = 0; va_start(ap, arg2); - c = va_arg(ap, char*); + while ((c = va_arg(ap, char *))) { + strcat(buffer, c); + } va_end(ap); - return c; + return buffer; } } diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index e3d8c7d50..9a068a40a 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -2614,7 +2614,7 @@ public: Printf(f->code, "}\n"); } else { Printf(f->code, "newargs = PyTuple_GetSlice(args,0,%d);\n", num_fixed_arguments); - Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args)+1);\n", num_fixed_arguments); + Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args));\n", num_fixed_arguments); } Printf(f->code, "resultobj = %s__varargs__(%s,newargs,varargs);\n", wname, builtin ? "self" : "NULL"); Append(f->code, "Py_XDECREF(newargs);\n"); From 8700e79b3e6036898475c436d0ad291254eb42de Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 23 May 2013 23:24:19 +0100 Subject: [PATCH 0640/1160] Guile port example fix for Guile 2.0 Rewinding the file before passing it to C fixed the problem of not being able to read the file contents. Also explain the error about writing to a string. --- Examples/guile/port/runme.scm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Examples/guile/port/runme.scm b/Examples/guile/port/runme.scm index 1a9b93038..3ff447eff 100644 --- a/Examples/guile/port/runme.scm +++ b/Examples/guile/port/runme.scm @@ -21,14 +21,15 @@ (lambda () (print-int (current-output-port) 314159)))) (lambda args - (display "Attempting to write to a string or soft port will result in this error:") + (display "Below shows that attempting to write to a string or soft port will result in a wrong-type-error...") (newline) (write args) (newline))) ;; Read from a file port. Note that it is a bad idea to mix Scheme and -;; C input because of buffering. +;; C input because of buffering, hence the call to seek to rewind the file. (with-input-from-file "test.out" (lambda () + (seek (current-input-port) 0 SEEK_SET) (display (read-int (current-input-port))) (newline))) From 074c0039db34009e0ba138f958719197feae5581 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 24 May 2013 18:57:26 +0100 Subject: [PATCH 0641/1160] Fix Python version checking in Python tests --- Examples/test-suite/python/autodoc_runme.py | 2 +- Examples/test-suite/python/file_test_runme.py | 2 +- Examples/test-suite/python/li_std_containers_int_runme.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/python/autodoc_runme.py b/Examples/test-suite/python/autodoc_runme.py index 634b2dccf..5776ad3ef 100644 --- a/Examples/test-suite/python/autodoc_runme.py +++ b/Examples/test-suite/python/autodoc_runme.py @@ -122,7 +122,7 @@ check(A.func3static.__doc__, "\n" " " ) -if sys.version[0:2] > (2, 4): +if sys.version_info[0:2] > (2, 4): # Python 2.4 does not seem to work check(A.variable_a.__doc__, "A_variable_a_get(self) -> int") check(A.variable_b.__doc__, "A_variable_b_get(A self) -> int") diff --git a/Examples/test-suite/python/file_test_runme.py b/Examples/test-suite/python/file_test_runme.py index 3d8b153db..9b94fa3b3 100644 --- a/Examples/test-suite/python/file_test_runme.py +++ b/Examples/test-suite/python/file_test_runme.py @@ -1,7 +1,7 @@ import sys import file_test -if sys.version[0:2] > (3, 0): +if sys.version_info[0:2] < (3, 0): file_test.nfile(sys.stdout) cstdout = file_test.GetStdOut() diff --git a/Examples/test-suite/python/li_std_containers_int_runme.py b/Examples/test-suite/python/li_std_containers_int_runme.py index f18e33812..3cbbb2862 100644 --- a/Examples/test-suite/python/li_std_containers_int_runme.py +++ b/Examples/test-suite/python/li_std_containers_int_runme.py @@ -78,7 +78,7 @@ def container_insert_step(i, j, step, newval): il_error = e # Python 2.6 contains bug fixes in extended slicing syntax: http://docs.python.org/2/whatsnew/2.6.html - skip_check = ps_error != None and(iv_error == il_error == None) and step > 0 and (sys.version[0:2] < (2, 6)) + skip_check = ps_error != None and(iv_error == il_error == None) and step > 0 and (sys.version_info[0:2] < (2, 6)) if not(skip_check): if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))): raise RuntimeError, "ValueError exception not consistently thrown: " + str(ps_error) + " " + str(iv_error) + " " + str(il_error) From f15eb3f5ec3ee77d521d675f42654edde9c46509 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 24 May 2013 22:51:27 +0100 Subject: [PATCH 0642/1160] Fix vararg documentation for Python 3 Memory handling is different to Python 2. --- Doc/Manual/Varargs.html | 32 +++++++++++++------ .../python/python_varargs_typemap_runme.py | 2 +- Examples/test-suite/python_varargs_typemap.i | 28 +++++++++------- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/Doc/Manual/Varargs.html b/Doc/Manual/Varargs.html index a580c83bd..9564fe00b 100644 --- a/Doc/Manual/Varargs.html +++ b/Doc/Manual/Varargs.html @@ -509,10 +509,10 @@ like this:
    -%typemap(in) (...)(char *args[10]) {
    +%typemap(in) (...)(char *vargs[10]) {
       int i;
       int argc;
    -  for (i = 0; i < 10; i++) args[i] = 0;
    +  for (i = 0; i < 10; i++) vargs[i] = 0;
       argc = PyTuple_Size(varargs);
       if (argc > 10) {
         PyErr_SetString(PyExc_ValueError, "Too many arguments");
    @@ -528,7 +528,7 @@ like this:
            return NULL;
         }
         pystr = PyUnicode_AsUTF8String(pyobj);
    -    str = PyBytes_AsString(pystr);
    +    str = strdup(PyBytes_AsString(pystr));
         Py_XDECREF(pystr);
     %#else  
         if (!PyString_Check(pyobj)) {
    @@ -537,22 +537,34 @@ like this:
         }
         str = PyString_AsString(pyobj);
     %#endif
    -    args[i] = str;
    +    vargs[i] = str;
       }
    -  $1 = (void *) args;
    +  $1 = (void *)vargs;
    +}
    +
    +%typemap(freearg) (...) {
    +%#if PY_VERSION_HEX>=0x03000000
    +  int i;
    +  for (i = 0; i < 10; i++) {
    +    free(vargs$argnum[i]);
    +  }
    +%#endif
     }
     

    -In this typemap, the special variable varargs is a tuple +In the 'in' typemap, the special variable varargs is a tuple holding all of the extra arguments passed (this is specific to the Python module). The typemap then pulls this apart and sticks the values into the array of strings args. Then, the array is assigned to $1 (recall that this is the void * variable corresponding to (...)). However, this assignment is only half of the picture----clearly this alone is not enough to -make the function work. To patch everything up, you have to rewrite the +make the function work. The 'freearg' typemap cleans up memory +allocated in the 'in' typemap; this code is generated to be called +after the execlp function is called. To patch everything +up, you have to rewrite the underlying action code using the %feature directive like this:

    @@ -560,9 +572,9 @@ this:
     %feature("action") execlp {
    -   char *args = (char **) arg3;
    -   result = execlp(arg1, arg2, args[0], args[1], args[2], args[3], args[4],
    -                   args[5],args[6],args[7],args[8],args[9], NULL);
    +  char **vargs = (char **) arg3;
    +  result = execlp(arg1, arg2, vargs[0], vargs[1], vargs[2], vargs[3], vargs[4],
    +                  vargs[5], vargs[6], vargs[7], vargs[8], vargs[9], NULL);
     }
     
     int execlp(const char *path, const char *arg, ...);
    diff --git a/Examples/test-suite/python/python_varargs_typemap_runme.py b/Examples/test-suite/python/python_varargs_typemap_runme.py
    index 79479e449..65be757c8 100644
    --- a/Examples/test-suite/python/python_varargs_typemap_runme.py
    +++ b/Examples/test-suite/python/python_varargs_typemap_runme.py
    @@ -4,4 +4,4 @@ if (python_varargs_typemap.testfunc(1, 2.0, "three") != "three") :
         raise RuntimeError("testfunc failed!")
     
     if (python_varargs_typemap.testfunc(1, 2.0, "three", "four", "five") != "threefourfive") :
    -    raise RuntimeError("testfunc failed!")
    +    raise RuntimeError("testfunc failed! {}")
    diff --git a/Examples/test-suite/python_varargs_typemap.i b/Examples/test-suite/python_varargs_typemap.i
    index 09189f654..09deea3b7 100644
    --- a/Examples/test-suite/python_varargs_typemap.i
    +++ b/Examples/test-suite/python_varargs_typemap.i
    @@ -4,13 +4,10 @@
       * chapter of the SWIG manual.
       */
     
    -%{
    -%}
    -
    -%typemap(in) (...)(char *args[10]) {
    +%typemap(in) (...)(char *vargs[10]) {
       int i;
       int argc;
    -  for (i = 0; i < 10; i++) args[i] = 0;
    +  for (i = 0; i < 10; i++) vargs[i] = 0;
       argc = PyTuple_Size(varargs);
       if (argc > 10) {
         PyErr_SetString(PyExc_ValueError, "Too many arguments");
    @@ -26,7 +23,7 @@
            return NULL;
         }
         pystr = PyUnicode_AsUTF8String(pyobj);
    -    str = PyBytes_AsString(pystr);
    +    str = strdup(PyBytes_AsString(pystr));
         Py_XDECREF(pystr);
     %#else  
         if (!PyString_Check(pyobj)) {
    @@ -35,15 +32,24 @@
         }
         str = PyString_AsString(pyobj);
     %#endif
    -    args[i] = str;
    +    vargs[i] = str;
       }
    -  $1 = (void *) args;
    +  $1 = (void *)vargs;
     }
     
     %feature("action") testfunc {
    -  char **args = (char **) arg3;
    -  result = testfunc(arg1, arg2, args[0], args[1], args[2], args[3], args[4],
    -                    args[5],args[6],args[7],args[8],args[9], NULL);
    +  char **vargs = (char **) arg3;
    +  result = testfunc(arg1, arg2, vargs[0], vargs[1], vargs[2], vargs[3], vargs[4],
    +                    vargs[5], vargs[6], vargs[7], vargs[8], vargs[9], NULL);
    +}
    +
    +%typemap(freearg) (...) {
    +%#if PY_VERSION_HEX>=0x03000000
    +  int i;
    +  for (i = 0; i < 10; i++) {
    +    free(vargs$argnum[i]);
    +  }
    +%#endif
     }
     
     %inline {
    
    From 030b97c891ce13a66801632e875169a2485413c6 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Sat, 25 May 2013 00:15:48 +0100
    Subject: [PATCH 0643/1160] Documentation sectioning update
    
    ---
     Doc/Manual/Contents.html | 3 +--
     1 file changed, 1 insertion(+), 2 deletions(-)
    
    diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html
    index ac21bcd1e..32fa32e96 100644
    --- a/Doc/Manual/Contents.html
    +++ b/Doc/Manual/Contents.html
    @@ -828,8 +828,7 @@
     
  • Typemaps
  • Representation of pointers as smobs
  • Exception Handling From 3357ee85cd7de581b78b28839e8dc5229d6c99ab Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Fri, 24 May 2013 13:34:37 +0400 Subject: [PATCH 0644/1160] Fix all attributes macroses --- Lib/typemaps/attribute.swg | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Lib/typemaps/attribute.swg b/Lib/typemaps/attribute.swg index 214133edc..d30b51183 100644 --- a/Lib/typemaps/attribute.swg +++ b/Lib/typemaps/attribute.swg @@ -195,42 +195,42 @@ %define %attribute(Class, AttributeType, AttributeName, GetMethod, SetMethod...) #if #SetMethod != "" - %attribute_custom(Class, AttributeType, AttributeName, GetMethod, SetMethod, self_->GetMethod(), self_->SetMethod(val_)) + %attribute_custom(%arg(Class), AttributeType, AttributeName, GetMethod, SetMethod, self_->GetMethod(), self_->SetMethod(val_)) #else - %attribute_readonly(Class, AttributeType, AttributeName, GetMethod, self_->GetMethod()) + %attribute_readonly(%arg(Class), AttributeType, AttributeName, GetMethod, self_->GetMethod()) #endif %enddef %define %attribute2(Class, AttributeType, AttributeName, GetMethod, SetMethod...) #if #SetMethod != "" - %attribute_custom(Class, AttributeType, AttributeName, GetMethod, SetMethod, &self_->GetMethod(), self_->SetMethod(*val_)) + %attribute_custom(%arg(Class), AttributeType, AttributeName, GetMethod, SetMethod, &self_->GetMethod(), self_->SetMethod(*val_)) #else - %attribute_readonly(Class, AttributeType, AttributeName, GetMethod, &self_->GetMethod()) + %attribute_readonly(%arg(Class), AttributeType, AttributeName, GetMethod, &self_->GetMethod()) #endif %enddef %define %attributeref(Class, AttributeType, AttributeName, AccessorMethod...) #if #AccessorMethod != "" - %attribute_custom(Class, AttributeType, AttributeName, AccessorMethod, AccessorMethod, self_->AccessorMethod(), self_->AccessorMethod() = val_) + %attribute_custom(%arg(Class), AttributeType, AttributeName, AccessorMethod, AccessorMethod, self_->AccessorMethod(), self_->AccessorMethod() = val_) #else - %attribute_custom(Class, AttributeType, AttributeName, AttributeName, AttributeName, self_->AttributeName(), self_->AttributeName() = val_) + %attribute_custom(%arg(Class), AttributeType, AttributeName, AttributeName, AttributeName, self_->AttributeName(), self_->AttributeName() = val_) #endif %enddef %define %attribute2ref(Class, AttributeType, AttributeName, AccessorMethod...) #if #AccessorMethod != "" - %attribute_custom(Class, AttributeType, AttributeName, AccessorMethod, AccessorMethod, &self_->AccessorMethod(), self_->AccessorMethod() = *val_) + %attribute_custom(%arg(Class), AttributeType, AttributeName, AccessorMethod, AccessorMethod, &self_->AccessorMethod(), self_->AccessorMethod() = *val_) #else - %attribute_custom(Class, AttributeType, AccessorName, AccessorName, AccessorName, &self_->AccessorName(), self_->AccessorName() = *val_) + %attribute_custom(%arg(Class), AttributeType, AccessorName, AccessorName, AccessorName, &self_->AccessorName(), self_->AccessorName() = *val_) #endif %enddef // deprecated (same as %attributeref, but there is an argument order inconsistency) %define %attribute_ref(Class, AttributeType, AccessorMethod, AttributeName...) #if #AttributeName != "" - %attribute_custom(Class, AttributeType, AttributeName, AccessorMethod, AccessorMethod, self_->AccessorMethod(), self_->AccessorMethod() = val_) + %attribute_custom(%arg(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(%arg(Class), AttributeType, AccessorMethod, AccessorMethod, AccessorMethod, self_->AccessorMethod(), self_->AccessorMethod() = val_) #endif %enddef From c956c4c87f1bd84ff0b3b1e78b4d8bd9487134c4 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Fri, 24 May 2013 13:37:00 +0400 Subject: [PATCH 0645/1160] Fix %arg in Lib/attribute.i --- Lib/attribute.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/attribute.i b/Lib/attribute.i index 0cc3ff1a3..d580dbfe9 100644 --- a/Lib/attribute.i +++ b/Lib/attribute.i @@ -11,7 +11,7 @@ #define %attribute_exception(code,msg) printf("%s\n",msg) #ifndef %arg -#define %arg(x) x +#define %arg(x...) x #endif #ifndef %mangle From 3e188e508d877e9c459a4fa09425456c17d7cf97 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sat, 25 May 2013 02:08:26 +0400 Subject: [PATCH 0646/1160] Add test case for attributes with moderately complex templates * New test case tests that %attribute macros correctly supports passing template with multiple parameters as class name or attribute type name * Some further changes were made to %attribute macros - now AttributeType is protected with %arg as well. This allows you to have attributes of type e.g. std::pair etc Update CHANGES file for %attribute template fixes Closes #48 --- CHANGES.current | 4 + Examples/test-suite/common.mk | 1 + Examples/test-suite/li_attribute_template.i | 110 ++++++++++++++++++ .../python/li_attribute_template_runme.py | 67 +++++++++++ Lib/typemaps/attribute.swg | 20 ++-- 5 files changed, 192 insertions(+), 10 deletions(-) create mode 100644 Examples/test-suite/li_attribute_template.i create mode 100644 Examples/test-suite/python/li_attribute_template_runme.py diff --git a/CHANGES.current b/CHANGES.current index 3d41780c2..565a4ec0f 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.10 (in progress) ============================ +2013-05-25: Artem Serebriyskiy + SVN Patch ticket #338 - fixes to %attribute macros for template usage + with %arg. + 2013-05-19: wsfulton Fix ccache-swig internal error bug due to premature file cleanup. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 793055097..9a335b46e 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -238,6 +238,7 @@ CPP_TEST_CASES += \ kind \ langobj \ li_attribute \ + li_attribute_template \ li_boost_shared_ptr \ li_boost_shared_ptr_bits \ li_boost_shared_ptr_template \ diff --git a/Examples/test-suite/li_attribute_template.i b/Examples/test-suite/li_attribute_template.i new file mode 100644 index 000000000..3d4c108ef --- /dev/null +++ b/Examples/test-suite/li_attribute_template.i @@ -0,0 +1,110 @@ +%module li_attribute_template + +%include + +//#define SWIG_ATTRIBUTE_TEMPLATE +%include +%include + +%inline +{ + class Foo { + public: + Foo( int _value ) { value = _value; } + int value; + }; + + template< class T1, class T2> + struct pair{ + pair( T1 t1, T2 t2 ): + first(t1), second(t2) {;} + + T1 first; + T2 second; + }; + + template< class T1, class T2> + struct C + { + C(int a, int b, int c) : + _a(a), _b(b), _c(c), _d(a), _e(b), + _f(a,b), _g(b,c) + { + +/* + _f.first = _a; + _f.second = _b; + + _g.first = _b; + _g.second = _c; +*/ + + } + + int get_value() const + { + return _a; + } + + void set_value(int aa) + { + _a = aa; + } + + /* only one ref method */ + int& get_ref() + { + return _b; + } + + Foo get_class_value() const { return _d; } + void set_class_value( Foo foo) { _d = foo; } + + const Foo& get_class_ref() const { return _e; } + void set_class_ref( const Foo& foo ) { _e = foo; } + + pair get_template_value() const { return _f; } + void set_template_value( const pair f ) { _f = f; } + + const pair& get_template_ref() const { return _g; } + void set_template_ref( const pair& g ) { _g = g; } + + std::string get_string() { return str; } + void set_string(std::string other) { str = other; } + + private: + int _a; + int _b; + int _c; + Foo _d; + Foo _e; + pair _f; + pair _g; + + std::string str; + }; + +} + +%define %instantiate_C( T1, T2 ) +%template (pair_ ## T1 ## T2 ) pair; +// Primitive types +%attribute( %arg(C), int, a, get_value, set_value ); +%attributeref( %arg(C), int, b, get_ref ); + +// Strings +%attributestring(%arg(C), std::string, str, get_string, set_string); + +// Class types +%attributeval( %arg(C), Foo, d, get_class_value, set_class_value ); +%attribute2( %arg(C), Foo, e, get_class_ref, set_class_ref ); + +// Moderately templated types +%attributeval( %arg(C), %arg(pair), f, get_template_value, set_template_value ); +%attribute2( %arg(C), %arg(pair), g, get_template_ref, set_template_ref ); + +%template (C ## T1 ## T2) C; +%enddef + + +%instantiate_C(int,int); diff --git a/Examples/test-suite/python/li_attribute_template_runme.py b/Examples/test-suite/python/li_attribute_template_runme.py new file mode 100644 index 000000000..7423053f9 --- /dev/null +++ b/Examples/test-suite/python/li_attribute_template_runme.py @@ -0,0 +1,67 @@ +# Check usage of template attributes + +import li_attribute_template + +chell = li_attribute_template.Cintint(1,2,3) + +def rassert( what, master ): + if what != master: + print what + raise RuntimeError + +## Testing primitive by value attribute +rassert( chell.a, 1 ) + +chell.a = 3 +rassert( chell.a, 3 ) + +## Testing primitive by ref attribute + +rassert( chell.b, 2 ) + +chell.b = 5 +rassert( chell.b,5 ) + +## Testing string +chell.str = "abc" +rassert( chell.str, "abc" ) + +# Testing class by value + +rassert( chell.d.value, 1 ) + +chell.d = li_attribute_template.Foo(2) +rassert( chell.d.value, 2 ) + +# Testing class by reference + +rassert( chell.e.value, 2 ) + +chell.e= li_attribute_template.Foo(3) +rassert( chell.e.value, 3 ) + +chell.e.value = 4 +rassert( chell.e.value, 4 ) + +# Testing moderately complex template by value +rassert( chell.f.first, 1 ) +rassert( chell.f.second, 2 ) + +pair = li_attribute_template.pair_intint(3,4) +chell.f = pair +rassert( chell.f.first, 3 ) +rassert( chell.f.second, 4 ) + +# Testing moderately complex template by ref +rassert( chell.g.first, 2 ) +rassert( chell.g.second, 3 ) + +pair = li_attribute_template.pair_intint(4,5) +chell.g = pair +rassert( chell.g.first, 4 ) +rassert( chell.g.second, 5 ) + +chell.g.first = 6 +chell.g.second = 7 +rassert( chell.g.first, 6 ) +rassert( chell.g.second, 7 ) diff --git a/Lib/typemaps/attribute.swg b/Lib/typemaps/attribute.swg index d30b51183..46fc80fd2 100644 --- a/Lib/typemaps/attribute.swg +++ b/Lib/typemaps/attribute.swg @@ -195,42 +195,42 @@ %define %attribute(Class, AttributeType, AttributeName, GetMethod, SetMethod...) #if #SetMethod != "" - %attribute_custom(%arg(Class), AttributeType, AttributeName, GetMethod, SetMethod, self_->GetMethod(), self_->SetMethod(val_)) + %attribute_custom(%arg(Class), %arg(AttributeType), AttributeName, GetMethod, SetMethod, self_->GetMethod(), self_->SetMethod(val_)) #else - %attribute_readonly(%arg(Class), AttributeType, AttributeName, GetMethod, self_->GetMethod()) + %attribute_readonly(%arg(Class), %arg(AttributeType), AttributeName, GetMethod, self_->GetMethod()) #endif %enddef %define %attribute2(Class, AttributeType, AttributeName, GetMethod, SetMethod...) #if #SetMethod != "" - %attribute_custom(%arg(Class), AttributeType, AttributeName, GetMethod, SetMethod, &self_->GetMethod(), self_->SetMethod(*val_)) + %attribute_custom(%arg(Class), %arg(AttributeType), AttributeName, GetMethod, SetMethod, &self_->GetMethod(), self_->SetMethod(*val_)) #else - %attribute_readonly(%arg(Class), AttributeType, AttributeName, GetMethod, &self_->GetMethod()) + %attribute_readonly(%arg(Class), %arg(AttributeType), AttributeName, GetMethod, &self_->GetMethod()) #endif %enddef %define %attributeref(Class, AttributeType, AttributeName, AccessorMethod...) #if #AccessorMethod != "" - %attribute_custom(%arg(Class), AttributeType, AttributeName, AccessorMethod, AccessorMethod, self_->AccessorMethod(), self_->AccessorMethod() = val_) + %attribute_custom(%arg(Class), %arg(AttributeType), AttributeName, AccessorMethod, AccessorMethod, self_->AccessorMethod(), self_->AccessorMethod() = val_) #else - %attribute_custom(%arg(Class), AttributeType, AttributeName, AttributeName, AttributeName, self_->AttributeName(), self_->AttributeName() = val_) + %attribute_custom(%arg(Class), %arg(AttributeType), AttributeName, AttributeName, AttributeName, self_->AttributeName(), self_->AttributeName() = val_) #endif %enddef %define %attribute2ref(Class, AttributeType, AttributeName, AccessorMethod...) #if #AccessorMethod != "" - %attribute_custom(%arg(Class), AttributeType, AttributeName, AccessorMethod, AccessorMethod, &self_->AccessorMethod(), self_->AccessorMethod() = *val_) + %attribute_custom(%arg(Class), %arg(AttributeType), AttributeName, AccessorMethod, AccessorMethod, &self_->AccessorMethod(), self_->AccessorMethod() = *val_) #else - %attribute_custom(%arg(Class), AttributeType, AccessorName, AccessorName, AccessorName, &self_->AccessorName(), self_->AccessorName() = *val_) + %attribute_custom(%arg(Class), %arg(AttributeType), AccessorName, AccessorName, AccessorName, &self_->AccessorName(), self_->AccessorName() = *val_) #endif %enddef // deprecated (same as %attributeref, but there is an argument order inconsistency) %define %attribute_ref(Class, AttributeType, AccessorMethod, AttributeName...) #if #AttributeName != "" - %attribute_custom(%arg(Class), AttributeType, AttributeName, AccessorMethod, AccessorMethod, self_->AccessorMethod(), self_->AccessorMethod() = val_) + %attribute_custom(%arg(Class), %arg(AttributeType), AttributeName, AccessorMethod, AccessorMethod, self_->AccessorMethod(), self_->AccessorMethod() = val_) #else - %attribute_custom(%arg(Class), AttributeType, AccessorMethod, AccessorMethod, AccessorMethod, self_->AccessorMethod(), self_->AccessorMethod() = val_) + %attribute_custom(%arg(Class), %arg(AttributeType), AccessorMethod, AccessorMethod, AccessorMethod, self_->AccessorMethod(), self_->AccessorMethod() = val_) #endif %enddef From 5481270c2a53add0cf9f7a01044a25a6b3013aaf Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 25 May 2013 10:36:14 +0100 Subject: [PATCH 0647/1160] Fix Python 3 inconsistency handling -ve numbers for unsigned C types. An OverFlow error is now consistently thrown instead of a TypeError. Fixes primitive_types testcase for Python 3 --- CHANGES.current | 5 +++ .../python/primitive_types_runme.py | 42 +++++++++++++++++-- Lib/python/pyprimtypes.swg | 12 ++++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 565a4ec0f..fe11a2952 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.10 (in progress) ============================ +2013-05-25: wsfulton + [Python] Fix Python 3 inconsistency when negative numbers are passed + where a parameter expects an unsigned C type. An OverFlow error is + now consistently thrown instead of a TypeError. + 2013-05-25: Artem Serebriyskiy SVN Patch ticket #338 - fixes to %attribute macros for template usage with %arg. diff --git a/Examples/test-suite/python/primitive_types_runme.py b/Examples/test-suite/python/primitive_types_runme.py index 2495cd60d..be8d38bad 100644 --- a/Examples/test-suite/python/primitive_types_runme.py +++ b/Examples/test-suite/python/primitive_types_runme.py @@ -275,10 +275,22 @@ try: except TypeError: if a != t.var_char: error = 1 - pass + pass if error: raise RuntimeError, "bad char typemap" +try: + error = 0 + a = t.var_ushort + t.var_ushort = -1 + error = 1 +except OverflowError: + if a != t.var_ushort: + error = 1 + pass +if error: + raise RuntimeError, "bad ushort typemap" + try: error = 0 a = t.var_uint @@ -287,10 +299,34 @@ try: except OverflowError: if a != t.var_uint: error = 1 - pass + pass if error: raise RuntimeError, "bad uint typemap" +try: + error = 0 + a = t.var_sizet + t.var_sizet = -1 + error = 1 +except OverflowError: + if a != t.var_sizet: + error = 1 + pass +if error: + raise RuntimeError, "bad sizet typemap" + +try: + error = 0 + a = t.var_ulong + t.var_ulong = -1 + error = 1 +except OverflowError: + if a != t.var_ulong: + error = 1 + pass +if error: + raise RuntimeError, "bad ulong typemap" + # # try: @@ -301,7 +337,7 @@ try: except TypeError: if a != t.var_namet: error = 1 - pass + pass if error: raise RuntimeError, "bad namet typemap" diff --git a/Lib/python/pyprimtypes.swg b/Lib/python/pyprimtypes.swg index 3fbd86a21..66ff104a6 100644 --- a/Lib/python/pyprimtypes.swg +++ b/Lib/python/pyprimtypes.swg @@ -127,6 +127,18 @@ SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val) return SWIG_OK; } else { PyErr_Clear(); +%#if PY_VERSION_HEX >= 0x03000000 + { + long v = PyLong_AsLong(obj); + if (!PyErr_Occurred()) { + if (v < 0) { + return SWIG_OverflowError; + } + } else { + PyErr_Clear(); + } + } +%#endif } } %#ifdef SWIG_PYTHON_CAST_MODE From fd93beadf4283b7394aa470e8a7040df3a30bcb3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 25 May 2013 22:29:18 +0100 Subject: [PATCH 0648/1160] Fix 'make check-python-test-suite PY3=1' and -j (make jobs) --- Examples/test-suite/python/Makefile.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index 43ba2717e..fa64d5e31 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -112,17 +112,17 @@ VALGRIND_OPT += --suppressions=pythonswig.supp %.cpptest: $(setup) +$(swig_and_compile_cpp) - $(run_testcase) + +$(run_testcase) %.ctest: $(setup) +$(swig_and_compile_c) - $(run_testcase) + +$(run_testcase) %.multicpptest: $(setup) +$(swig_and_compile_multi_cpp) - $(run_testcase) + +$(run_testcase) # Call 2to3 to generate Python 3.x test from the Python 2.x's *_runme.py file From b3ca22dc339ca18873079bd96bbb19dd00bc8f0a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 26 May 2013 22:34:07 +0100 Subject: [PATCH 0649/1160] Fix Python examples to compile and run under Python 3 --- Examples/python/index.html | 17 ++--------- Examples/python/multimap/example.i | 47 +++++++++++++++++++++++------- Examples/python/varargs/example.i | 10 +++++-- Examples/python/varargs/runme.py | 7 +++-- 4 files changed, 51 insertions(+), 30 deletions(-) diff --git a/Examples/python/index.html b/Examples/python/index.html index 8443a85e1..37f4b55af 100644 --- a/Examples/python/index.html +++ b/Examples/python/index.html @@ -89,21 +89,10 @@ to look at the distutils

    Compatibility

    -The examples have been extensively tested on the following platforms: - -
      -
    • Linux -
    • Solaris -
    - -All of the examples were last tested with the following configuration (9/1/2000): - -
      -
    • Sparc Solaris 2.8. -
    • gcc-2.95.2 -
    • Python 1.6b1. -
    +For Python 3, set the environment variable PY3=1. +This will ensure the 2to3 program is run prior to running any example. +

    Your mileage may vary. If you experience a problem, please let us know by contacting us on the mailing lists. diff --git a/Examples/python/multimap/example.i b/Examples/python/multimap/example.i index f1c4d9990..3f6fc3db3 100644 --- a/Examples/python/multimap/example.i +++ b/Examples/python/multimap/example.i @@ -38,27 +38,44 @@ extern int gcd(int x, int y); } %#if PY_VERSION_HEX >= 0x03000000 { - int l; - $2[i] = PyUnicode_AsStringAndSize(s, &l); + PyObject *utf8str = PyUnicode_AsUTF8String(s); + const char *cstr = PyBytes_AsString(utf8str); + $2[i] = strdup(cstr); + Py_DECREF(utf8str); } %#else $2[i] = PyString_AsString(s); %#endif - } $2[i] = 0; } +%typemap(freearg) (int argc, char *argv[]) { +%#if PY_VERSION_HEX >= 0x03000000 + int i; + for (i = 0; i < $1; i++) { + free($2[i]); + } +%#endif +} + extern int gcdmain(int argc, char *argv[]); %typemap(in) (char *bytes, int len) { %#if PY_VERSION_HEX >= 0x03000000 + char *cstr; + Py_ssize_t len; + PyObject *utf8str; if (!PyUnicode_Check($input)) { PyErr_SetString(PyExc_ValueError,"Expected a string"); return NULL; } - $1 = PyUnicode_AsStringAndSize($input, &$2); + utf8str = PyUnicode_AsUTF8String($input); + PyBytes_AsStringAndSize(utf8str, &cstr, &len); + $1 = strndup(cstr, (size_t)len); + $2 = (int)len; + Py_DECREF(utf8str); %#else if (!PyString_Check($input)) { PyErr_SetString(PyExc_ValueError,"Expected a string"); @@ -69,6 +86,12 @@ extern int gcdmain(int argc, char *argv[]); %#endif } +%typemap(freearg) (char *bytes, int len) { +%#if PY_VERSION_HEX >= 0x03000000 + free($1); +%#endif +} + extern int count(char *bytes, int len, char c); @@ -79,13 +102,17 @@ extern int count(char *bytes, int len, char c); %typemap(in) (char *str, int len) { %#if PY_VERSION_HEX >= 0x03000000 - $2 = PyUnicode_GetSize($input); - $1 = (char *) malloc($2+1); - memmove($1,PyUnicode_AsString($input),$2); + char *cstr; + Py_ssize_t len; + PyObject *utf8str = PyUnicode_AsUTF8String($input); + PyBytes_AsStringAndSize(utf8str, &cstr, &len); + $1 = strndup(cstr, (size_t)len); + $2 = (int)len; + Py_DECREF(utf8str); %#else - $2 = PyString_Size($input); - $1 = (char *) malloc($2+1); - memmove($1,PyString_AsString($input),$2); + $2 = PyString_Size($input); + $1 = (char *) malloc($2+1); + memmove($1,PyString_AsString($input),$2); %#endif } diff --git a/Examples/python/varargs/example.i b/Examples/python/varargs/example.i index 6cb88f5f4..a581bca5d 100644 --- a/Examples/python/varargs/example.i +++ b/Examples/python/varargs/example.i @@ -32,9 +32,6 @@ int printf(const char *fmt, ...); } #endif -/* Typemap just to make the example work */ -%typemap(in) FILE * "$1 = PyFile_AsFile($input);"; - int fprintf(FILE *, const char *fmt, ...); /* Here is somewhat different example. A variable length argument @@ -48,6 +45,13 @@ int fprintf(FILE *, const char *fmt, ...); %varargs(20, char *x = NULL) printv; %inline %{ + +/* In Python 2 we could use PyFile_AsFile for converting Python sys.stdout to C's stdout. + This API disappeared in Python 3, so instead we use a helper function to get stdout */ +FILE * stdout_stream(void) { + return stdout; +} + void printv(char *s, ...) { va_list ap; char *x; diff --git a/Examples/python/varargs/runme.py b/Examples/python/varargs/runme.py index a01cb6769..8eab77041 100644 --- a/Examples/python/varargs/runme.py +++ b/Examples/python/varargs/runme.py @@ -13,13 +13,14 @@ for i in range(0,10): # This will probably be garbled because %d is interpreted by C example.printf("The value is %d\n") +stdout = example.stdout_stream() # Call fprintf -example.fprintf(sys.stdout,"Hello World. I'm fprintf\n") +example.fprintf(stdout,"Hello World. I'm fprintf\n") for i in range(0,10): - example.fprintf(sys.stdout,"i is %d\n" % i) + example.fprintf(stdout,"i is %d\n" % i) # This won't be garbled since %d is not interpreted -example.fprintf(sys.stdout,"The value is %d\n") +example.fprintf(stdout,"The value is %d\n") # This function calls our NULL-terminated function From 2004b9fc0370a2134153ba6227422aced19f35f8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 26 May 2013 23:58:12 +0100 Subject: [PATCH 0650/1160] Add Python 3 Travis tests --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7d7204b6a..13502de0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,8 @@ matrix: env: SWIGLANG=php - compiler: gcc env: SWIGLANG=python + - compiler: gcc + env: SWIGLANG=python PY3=1 - compiler: gcc env: SWIGLANG=ruby - compiler: gcc @@ -40,6 +42,7 @@ before_install: - if test "$SWIGLANG" = "lua"; then sudo apt-get -qq install lua5.1 liblua5.1-dev; fi - if test "$SWIGLANG" = "octave"; then sudo apt-get -qq install octave3.2 octave3.2-headers; fi - if test "$SWIGLANG" = "php"; then sudo apt-get install php5-cli php5-dev; fi + - if test "$SWIGLANG" = "python" -a "$PY3"; then sudo apt-get install python3-dev; fi - if test "$SWIGLANG" = "tcl"; then sudo apt-get -qq install tcl8.4-dev; fi script: - ./autogen.sh && ./configure From af8f77a627cce49422cced96666c739b7f4c1032 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 27 May 2013 00:27:31 +0100 Subject: [PATCH 0651/1160] Fix to ensure 2to3 for Python 3 examples is run --- Examples/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 5d521f5a1..280923df2 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -366,7 +366,7 @@ endif PY2TO3 = 2to3 `2to3 -l | grep -v -E "Available|import$$" | awk '{print "-f "$$0}'` -python_run: +python_run: $(PYSCRIPT) $(RUNTOOL) $(PYTHON) $(PYSCRIPT) $(RUNPIPE) $(RUNME)3.py: $(RUNME).py From 72f2d8ac8f417ace9706897d15a90749d5a7bc3a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 27 May 2013 10:24:02 +0100 Subject: [PATCH 0652/1160] Fix Python test-suite makefile to show which tests have runtime tests (for Python 3). --- Examples/test-suite/python/Makefile.in | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index fa64d5e31..5e8388311 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -110,19 +110,22 @@ VALGRIND_OPT += --suppressions=pythonswig.supp # Rules for the different types of tests %.cpptest: + +$(convert_testcase) $(setup) +$(swig_and_compile_cpp) - +$(run_testcase) + $(run_testcase) %.ctest: + +$(convert_testcase) $(setup) +$(swig_and_compile_c) - +$(run_testcase) + $(run_testcase) %.multicpptest: + +$(convert_testcase) $(setup) +$(swig_and_compile_multi_cpp) - +$(run_testcase) + $(run_testcase) # Call 2to3 to generate Python 3.x test from the Python 2.x's *_runme.py file @@ -139,17 +142,17 @@ run_python = env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=.:$(srcdir):$$PY py2_runme = $(srcdir)/$(SCRIPTPREFIX)$*$(PY2SCRIPTSUFFIX) py3_runme = $(srcdir)/$(SCRIPTPREFIX)$*$(PY3SCRIPTSUFFIX) -ifeq (,$(PY3)) run_testcase = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ $(run_python);\ fi + +ifeq (,$(PY3)) +convert_testcase = else -run_testcase = \ +convert_testcase = \ if [ -f $(py2_runme) ]; then \ - $(MAKE) -f $(srcdir)/Makefile $(py3_runme) && $(run_python); \ - elif [ -f $(py3_runme) ]; then \ - $(run_python); \ + $(MAKE) -f $(srcdir)/Makefile $(py3_runme); \ fi endif From 1524d02e1316e6dedfb0dbd9f26765172dde4f1c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 27 May 2013 19:15:42 +0100 Subject: [PATCH 0653/1160] Add swig-2.0.10 release date and release notes --- ANNOUNCE | 2 +- CHANGES.current | 2 +- Doc/Manual/Sections.html | 2 +- README | 2 +- RELEASENOTES | 11 +++++++++++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 1c3297a5c..b8c852dfa 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,4 +1,4 @@ -*** ANNOUNCE: SWIG 2.0.10 (in progress) *** +*** ANNOUNCE: SWIG 2.0.10 (27 May 2013) *** http://www.swig.org diff --git a/CHANGES.current b/CHANGES.current index fe11a2952..215fdb203 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,7 +2,7 @@ Below are the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.10 (in progress) +Version 2.0.10 (27 May 2013) ============================ 2013-05-25: wsfulton diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 9e4a3dd17..5212c9301 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

    SWIG-2.0 Documentation

    -Last update : SWIG-2.0.10 (in progress) +Last update : SWIG-2.0.10 (27 May 2013)

    Sections

    diff --git a/README b/README index 444643a0d..a79b6b84f 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.10 (in progress) +Version: 2.0.10 (27 May 2013) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, C#, D, Go, Lua, diff --git a/RELEASENOTES b/RELEASENOTES index af9f4fb6b..49eacf28a 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -4,6 +4,17 @@ and CHANGES files. Release Notes ============= +SWIG-2.0.10 summary: +- Ruby 1.9 support is now complete. +- Add support for Guile 2.0 and Guile 1.6 support (GH interface) has + been dropped. +- Various small language neutral improvements and fixes. +- Various bug fixes and minor improvements specific to C#, CFFI, D, + Java, Octave, PHP, Python, +- Minor bug fix in ccache-swig. +- Development has moved to Github with Travis continuous integration + testing - patches using https://github.com/swig/swig are welcome. + SWIG-2.0.9 summary: - Improved typemap matching. - Ruby 1.9 support is much improved. From 8e89cad271a8c021e05abda2b0a72d4ef2aac0a4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 27 May 2013 20:27:50 +0100 Subject: [PATCH 0654/1160] Bump version to 2.0.11 --- ANNOUNCE | 2 +- CHANGES | 237 +++++++++++++++++++++++++++++++++++++++ CHANGES.current | 236 +------------------------------------- Doc/Manual/Sections.html | 2 +- README | 2 +- configure.ac | 2 +- 6 files changed, 242 insertions(+), 239 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index b8c852dfa..1c3297a5c 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,4 +1,4 @@ -*** ANNOUNCE: SWIG 2.0.10 (27 May 2013) *** +*** ANNOUNCE: SWIG 2.0.10 (in progress) *** http://www.swig.org diff --git a/CHANGES b/CHANGES index 8b1945ad9..488bf7286 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,243 @@ SWIG (Simplified Wrapper and Interface Generator) See the CHANGES.current file for changes in the current version. See the RELEASENOTES file for a summary of changes in each release. +Version 2.0.10 (27 May 2013) +============================ + +2013-05-25: wsfulton + [Python] Fix Python 3 inconsistency when negative numbers are passed + where a parameter expects an unsigned C type. An OverFlow error is + now consistently thrown instead of a TypeError. + +2013-05-25: Artem Serebriyskiy + SVN Patch ticket #338 - fixes to %attribute macros for template usage + with %arg. + +2013-05-19: wsfulton + Fix ccache-swig internal error bug due to premature file cleanup. + + Fixes SF bug 1319 which shows up as a failure in the ccache tests on + Debian 64 bit Wheezy, possibly because ENABLE_ZLIB is defined. + + This is a corner case which will be hit when the maximum number of files + in the cache is set to be quite low (-F option), resulting in a cache miss. + +2013-05-09: kwwette + [Octave] Fix bugs in Octave module loading: + - fix a memory leak in setting of global variables + - install functions only once, to speed up module loads + +2013-04-28: gjanssens + [Guile] Updates in guile module: + - Add support for guile 2.0 + - Drop support for guile 1.6 + - Drop support for generating wrappers using guile's gh interface. + All generated wrappers will use the scm interface from now on. + - Deprecate -gh and -scm options. They are no longer needed. + A warning will be issued when these options are still used. + - Fix all tests and examples to have a successful travis test + +2013-04-18: wsfulton + Apply Patch #36 from Jesus Lopez to add support for $descriptor() special variable macro expansion + in fragments. For example: + + %fragment("nameDescriptor", "header") + %{ + static const char *nameDescriptor = "$descriptor(Name)"; + %} + + which will generate into the wrapper if the fragment is used: + + static const char *nameDescriptor = "SWIGTYPE_Name"; + +2013-04-18: wsfulton + Fix SF Bug #428 - Syntax error when preprocessor macros are defined inside of enum lists, such as: + + typedef enum { + eZero = 0 + #define ONE 1 + } EFoo; + + The macros are silently ignored. + +2013-04-17: wsfulton + [C#] Pull patch #34 from BrantKyser to fix smart pointers in conjuction with directors. + +2013-04-15: kwwette + [Octave] Fix bugs in output of cleanup code. + - Cleanup code is now written also after the "fail:" label, so it will be called if + a SWIG_exception is raised by the wrapping function, consistent with other modules. + - Octave module now also recognises the "$cleanup" special variable, if needed. + +2013-04-08: kwwette + Add -MP option to SWIG for generating phony targets for all dependencies. + - Prevents make from complaining if header files have been deleted before + the dependency file has been updated. + - Modelled on similar option in GCC. + +2013-04-09: olly + [PHP] Add missing directorin typemap for char* and char[] which + fixes director_string testcase failure. + +2013-04-05: wsfulton + [Ruby] SF Bug #1292 - Runtime fixes for Proc changes in ruby-1.9 when using STL + wrappers that override the default predicate, such as: + + %template(Map) std::map >; + +2013-04-05: wsfulton + [Ruby] SF Bug #1159 - Correctly check rb_respond_to call return values to fix some + further 1.9 problems with functors and use of Complex wrappers. + +2013-04-02: wsfulton + [Ruby] Runtime fixes for std::complex wrappers for ruby-1.9 - new native Ruby complex numbers are used. + +2013-03-30: wsfulton + [Ruby] Fix seg fault when using STL containers of generic Ruby types, GC_VALUE or LANGUAGE_OBJECT, + on exit of the Ruby interpreter. More frequently observed in ruby-1.9. + +2013-03-29: wsfulton + [Ruby] Fix delete_if (reject!) for the STL container wrappers which previously would + sometimes seg fault or not work. + +2013-03-25: wsfulton + [Python] Fix some undefined behaviour deleting slices in the STL containers. + +2013-03-19: wsfulton + [C#, Java, D] Fix seg fault in SWIG using directors when class and virtual method names are + the same except being in different namespaces when the %nspace feature is not being used. + +2013-02-19: kwwette + Fix bug in SWIG's handling of qualified (e.g. const) variables of array type. Given the typedef + a(7).q(volatile).double myarray // typedef volatile double[7] myarray; + the type + q(const).myarray // const myarray + becomes + a(7).q(const volatile).double // const volatile double[7] + Previously, SwigType_typedef_resolve() produces the type + q(const).a(7).q(volatile).double // non-sensical type + which would never match %typemap declarations, whose types were parsed correctly. + Add typemap_array_qualifiers.i to the test suite which checks for the correct behaviour. + +2013-02-18: wsfulton + Deprecate typedef names used as constructor and destructor names in %extend. The real + class/struct name should be used. + + typedef struct tagEStruct { + int ivar; + } EStruct; + + %extend tagEStruct { + EStruct() // illegal name, should be tagEStruct() + { + EStruct *s = new EStruct(); + s->ivar = ivar0; + return s; + } + ~EStruct() // illegal name, should be ~tagEStruct() + { + delete $self; + } + } + + For now these trigger a warning: + + extend_constructor_destructor.i:107: Warning 522: Use of an illegal constructor name 'EStruct' in + %extend is deprecated, the constructor name should be 'tagEStruct'. + extend_constructor_destructor.i:111: Warning 523: Use of an illegal destructor name 'EStruct' in + %extend is deprecated, the destructor name should be 'tagEStruct'. + + These %extend destructor and constructor names were valid up to swig-2.0.4, however swig-2.0.5 ignored + them altogether for C code as reported in SF bug #1306. The old behaviour of using them has been + restored for now, but is officially deprecated. This does not apply to anonymously defined typedef + classes/structs such as: + + typedef struct {...} X; + +2013-02-17: kwwette + When generating functions provided by %extend, use "(void)" for no-argument functions + instead of "()". This prevents warnings when compiling with "gcc -Wstrict-prototypes". + +2013-02-17: kwwette + [Octave] Minor fix to autodoc generation: get the right type for functions returning structs. + +2013-02-15: wsfulton + Deprecate typedef names used in %extend that are not the real class/struct name. For example: + + typedef struct StructBName { + int myint; + } StructB; + + %extend StructB { + void method() {} + } + + will now trigger a warning: + + swig_extend.i:19: Warning 326: Deprecated %extend name used - the struct name StructBName + should be used instead of the typedef name StructB. + + This is only partially working anyway (the %extend only worked if placed after the class + definition). + +2013-02-09: wsfulton + [CFFI] Apply patch #22 - Fix missing package before &body + +2013-01-29: wsfulton + [Java] Ensure 'javapackage' typemap is used as it stopped working from version 2.0.5. + +2013-01-28: wsfulton + [Python] Apply patch SF #334 - Fix default value conversions "TRUE"->True, "FALSE"->False. + +2013-01-28: wsfulton + [Java] Apply patch SF #335 - Truly ignore constructors in directors with %ignore. + +2013-01-18: Brant Kyser + [Java] Patch #15 - Allow the use of the nspace feature without the -package commandline option. + This works as long and the new jniclasspackage pragma is used to place the JNI intermediate class + into a package and the nspace feature is used to place all exposed types into a package. + +2013-01-15: wsfulton + Fix Visual Studio examples to work when SWIG is unzipped into a directory containing spaces. + +2013-01-15: wsfulton + [C#] Fix cstype typemap lookup for member variables so that a fully qualified variable name + matches. For example: + %typemap(cstype) bool MVar::mvar "MyBool" + struct MVar { + bool mvar; + }; + +2013-01-11: Brant Kyser + [Java, C#, D] SF Bug #1299 - Fix generated names for when %nspace is used on + classes with the same name in two different namespaces. + +2013-01-11: Vladimir Kalinin + [C#] Add support for csdirectorin 'pre', 'post' and 'terminator' attributes. + +2013-01-08: olly + [PHP] Fix to work with a ZTS build of PHP (broken in 2.0.7). + +2013-01-07: olly + Fix bashism in configure, introduced in 2.0.9. + +2013-01-06: wsfulton + Pull patch #4 from ptomulik to fix SF Bug #1296 - Fix incorrect warning for virtual destructors + in templates, such as: + Warning 521: Illegal destructor name B< A >::~B(). Ignored. + +2013-01-05: wsfulton + [Python] Pull patch #3 from ptomulik to fix SF Bug #1295 - standard exceptions as + classes using the SWIG_STD_EXCEPTIONS_AS_CLASSES macro. + +2013-01-04: wsfulton + [Java] Pull patch #2 from BrantKyser to fix SF Bug #1283 - fix smart pointers in conjuction + with directors. + +2013-01-03: wsfulton + [Java] Pull patch #1 from BrantKyser to fix SF Bug #1278 - fix directors and nspace feature when + multilevel namespaces are used. + Version 2.0.9 (16 December 2012) ================================ diff --git a/CHANGES.current b/CHANGES.current index 215fdb203..98166efca 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,240 +2,6 @@ Below are the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.10 (27 May 2013) +Version 2.0.11 (in progress) ============================ -2013-05-25: wsfulton - [Python] Fix Python 3 inconsistency when negative numbers are passed - where a parameter expects an unsigned C type. An OverFlow error is - now consistently thrown instead of a TypeError. - -2013-05-25: Artem Serebriyskiy - SVN Patch ticket #338 - fixes to %attribute macros for template usage - with %arg. - -2013-05-19: wsfulton - Fix ccache-swig internal error bug due to premature file cleanup. - - Fixes SF bug 1319 which shows up as a failure in the ccache tests on - Debian 64 bit Wheezy, possibly because ENABLE_ZLIB is defined. - - This is a corner case which will be hit when the maximum number of files - in the cache is set to be quite low (-F option), resulting in a cache miss. - -2013-05-09: kwwette - [Octave] Fix bugs in Octave module loading: - - fix a memory leak in setting of global variables - - install functions only once, to speed up module loads - -2013-04-28: gjanssens - [Guile] Updates in guile module: - - Add support for guile 2.0 - - Drop support for guile 1.6 - - Drop support for generating wrappers using guile's gh interface. - All generated wrappers will use the scm interface from now on. - - Deprecate -gh and -scm options. They are no longer needed. - A warning will be issued when these options are still used. - - Fix all tests and examples to have a successful travis test - -2013-04-18: wsfulton - Apply Patch #36 from Jesus Lopez to add support for $descriptor() special variable macro expansion - in fragments. For example: - - %fragment("nameDescriptor", "header") - %{ - static const char *nameDescriptor = "$descriptor(Name)"; - %} - - which will generate into the wrapper if the fragment is used: - - static const char *nameDescriptor = "SWIGTYPE_Name"; - -2013-04-18: wsfulton - Fix SF Bug #428 - Syntax error when preprocessor macros are defined inside of enum lists, such as: - - typedef enum { - eZero = 0 - #define ONE 1 - } EFoo; - - The macros are silently ignored. - -2013-04-17: wsfulton - [C#] Pull patch #34 from BrantKyser to fix smart pointers in conjuction with directors. - -2013-04-15: kwwette - [Octave] Fix bugs in output of cleanup code. - - Cleanup code is now written also after the "fail:" label, so it will be called if - a SWIG_exception is raised by the wrapping function, consistent with other modules. - - Octave module now also recognises the "$cleanup" special variable, if needed. - -2013-04-08: kwwette - Add -MP option to SWIG for generating phony targets for all dependencies. - - Prevents make from complaining if header files have been deleted before - the dependency file has been updated. - - Modelled on similar option in GCC. - -2013-04-09: olly - [PHP] Add missing directorin typemap for char* and char[] which - fixes director_string testcase failure. - -2013-04-05: wsfulton - [Ruby] SF Bug #1292 - Runtime fixes for Proc changes in ruby-1.9 when using STL - wrappers that override the default predicate, such as: - - %template(Map) std::map >; - -2013-04-05: wsfulton - [Ruby] SF Bug #1159 - Correctly check rb_respond_to call return values to fix some - further 1.9 problems with functors and use of Complex wrappers. - -2013-04-02: wsfulton - [Ruby] Runtime fixes for std::complex wrappers for ruby-1.9 - new native Ruby complex numbers are used. - -2013-03-30: wsfulton - [Ruby] Fix seg fault when using STL containers of generic Ruby types, GC_VALUE or LANGUAGE_OBJECT, - on exit of the Ruby interpreter. More frequently observed in ruby-1.9. - -2013-03-29: wsfulton - [Ruby] Fix delete_if (reject!) for the STL container wrappers which previously would - sometimes seg fault or not work. - -2013-03-25: wsfulton - [Python] Fix some undefined behaviour deleting slices in the STL containers. - -2013-03-19: wsfulton - [C#, Java, D] Fix seg fault in SWIG using directors when class and virtual method names are - the same except being in different namespaces when the %nspace feature is not being used. - -2013-02-19: kwwette - Fix bug in SWIG's handling of qualified (e.g. const) variables of array type. Given the typedef - a(7).q(volatile).double myarray // typedef volatile double[7] myarray; - the type - q(const).myarray // const myarray - becomes - a(7).q(const volatile).double // const volatile double[7] - Previously, SwigType_typedef_resolve() produces the type - q(const).a(7).q(volatile).double // non-sensical type - which would never match %typemap declarations, whose types were parsed correctly. - Add typemap_array_qualifiers.i to the test suite which checks for the correct behaviour. - -2013-02-18: wsfulton - Deprecate typedef names used as constructor and destructor names in %extend. The real - class/struct name should be used. - - typedef struct tagEStruct { - int ivar; - } EStruct; - - %extend tagEStruct { - EStruct() // illegal name, should be tagEStruct() - { - EStruct *s = new EStruct(); - s->ivar = ivar0; - return s; - } - ~EStruct() // illegal name, should be ~tagEStruct() - { - delete $self; - } - } - - For now these trigger a warning: - - extend_constructor_destructor.i:107: Warning 522: Use of an illegal constructor name 'EStruct' in - %extend is deprecated, the constructor name should be 'tagEStruct'. - extend_constructor_destructor.i:111: Warning 523: Use of an illegal destructor name 'EStruct' in - %extend is deprecated, the destructor name should be 'tagEStruct'. - - These %extend destructor and constructor names were valid up to swig-2.0.4, however swig-2.0.5 ignored - them altogether for C code as reported in SF bug #1306. The old behaviour of using them has been - restored for now, but is officially deprecated. This does not apply to anonymously defined typedef - classes/structs such as: - - typedef struct {...} X; - -2013-02-17: kwwette - When generating functions provided by %extend, use "(void)" for no-argument functions - instead of "()". This prevents warnings when compiling with "gcc -Wstrict-prototypes". - -2013-02-17: kwwette - [Octave] Minor fix to autodoc generation: get the right type for functions returning structs. - -2013-02-15: wsfulton - Deprecate typedef names used in %extend that are not the real class/struct name. For example: - - typedef struct StructBName { - int myint; - } StructB; - - %extend StructB { - void method() {} - } - - will now trigger a warning: - - swig_extend.i:19: Warning 326: Deprecated %extend name used - the struct name StructBName - should be used instead of the typedef name StructB. - - This is only partially working anyway (the %extend only worked if placed after the class - definition). - -2013-02-09: wsfulton - [CFFI] Apply patch #22 - Fix missing package before &body - -2013-01-29: wsfulton - [Java] Ensure 'javapackage' typemap is used as it stopped working from version 2.0.5. - -2013-01-28: wsfulton - [Python] Apply patch SF #334 - Fix default value conversions "TRUE"->True, "FALSE"->False. - -2013-01-28: wsfulton - [Java] Apply patch SF #335 - Truly ignore constructors in directors with %ignore. - -2013-01-18: Brant Kyser - [Java] Patch #15 - Allow the use of the nspace feature without the -package commandline option. - This works as long and the new jniclasspackage pragma is used to place the JNI intermediate class - into a package and the nspace feature is used to place all exposed types into a package. - -2013-01-15: wsfulton - Fix Visual Studio examples to work when SWIG is unzipped into a directory containing spaces. - -2013-01-15: wsfulton - [C#] Fix cstype typemap lookup for member variables so that a fully qualified variable name - matches. For example: - %typemap(cstype) bool MVar::mvar "MyBool" - struct MVar { - bool mvar; - }; - -2013-01-11: Brant Kyser - [Java, C#, D] SF Bug #1299 - Fix generated names for when %nspace is used on - classes with the same name in two different namespaces. - -2013-01-11: Vladimir Kalinin - [C#] Add support for csdirectorin 'pre', 'post' and 'terminator' attributes. - -2013-01-08: olly - [PHP] Fix to work with a ZTS build of PHP (broken in 2.0.7). - -2013-01-07: olly - Fix bashism in configure, introduced in 2.0.9. - -2013-01-06: wsfulton - Pull patch #4 from ptomulik to fix SF Bug #1296 - Fix incorrect warning for virtual destructors - in templates, such as: - Warning 521: Illegal destructor name B< A >::~B(). Ignored. - -2013-01-05: wsfulton - [Python] Pull patch #3 from ptomulik to fix SF Bug #1295 - standard exceptions as - classes using the SWIG_STD_EXCEPTIONS_AS_CLASSES macro. - -2013-01-04: wsfulton - [Java] Pull patch #2 from BrantKyser to fix SF Bug #1283 - fix smart pointers in conjuction - with directors. - -2013-01-03: wsfulton - [Java] Pull patch #1 from BrantKyser to fix SF Bug #1278 - fix directors and nspace feature when - multilevel namespaces are used. - diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 5212c9301..9e4a3dd17 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

    SWIG-2.0 Documentation

    -Last update : SWIG-2.0.10 (27 May 2013) +Last update : SWIG-2.0.10 (in progress)

    Sections

    diff --git a/README b/README index a79b6b84f..444643a0d 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.10 (27 May 2013) +Version: 2.0.10 (in progress) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, C#, D, Go, Lua, diff --git a/configure.ac b/configure.ac index c94c2e962..616610eda 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. dnl The macros which aren't shipped with the autotools are stored in the dnl Tools/config directory in .m4 files. -AC_INIT([swig],[2.0.10],[http://www.swig.org]) +AC_INIT([swig],[2.0.11],[http://www.swig.org]) dnl NB: When this requirement is increased to 2.60 or later, AC_PROG_SED dnl definition below can be removed From 918c64af842810a6f59605953c94d5a967530af8 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 1 May 2013 17:48:08 +1200 Subject: [PATCH 0655/1160] Fix comment typos --- Source/Swig/misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 05dd0c480..efa397878 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -205,8 +205,8 @@ String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) { /* ----------------------------------------------------------------------------- * Swig_filename_correct() * - * Corrects filename paths by removing duplicate delimeters and on non-unix - * systems use the correct delimeter across the whole name. + * Corrects filename paths by removing duplicate delimiters and on non-unix + * systems use the correct delimiter across the whole name. * ----------------------------------------------------------------------------- */ void Swig_filename_correct(String *filename) { From abfa75b169a839909a4abef4f3a4ca8616fccc5d Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 4 Jun 2013 12:53:27 +1200 Subject: [PATCH 0656/1160] [PHP] Fix SWIG_ZTS_ConvertResourcePtr() not to dereference NULL if the type lookup fails. --- CHANGES.current | 4 ++++ Lib/php/phprun.swg | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 98166efca..208c99f68 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,3 +5,7 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.11 (in progress) ============================ +2013-06-04: olly + [PHP] Fix SWIG_ZTS_ConvertResourcePtr() not to dereference NULL + if the type lookup fails. + diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 92f2f3fe5..a4188cc7c 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -209,11 +209,11 @@ SWIG_ZTS_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags TSRMLS_DC) { const char *type_name; value = (swig_object_wrapper *) zend_list_find(z->value.lval, &type); - if ( flags & SWIG_POINTER_DISOWN ) { + if (type==-1) return NULL; + if (flags & SWIG_POINTER_DISOWN) { value->newobject = 0; } p = value->ptr; - if (type==-1) return NULL; type_name=zend_rsrc_list_get_rsrc_type(z->value.lval TSRMLS_CC); From c9295401da4fc2feb9aee1c73932c1bdb22513be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Tue, 28 May 2013 15:47:43 +0200 Subject: [PATCH 0657/1160] clean all .py files generated by python-test-suite Closes #49 --- Examples/test-suite/python/Makefile.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index 5e8388311..e7db32fb7 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -58,7 +58,7 @@ CPP_TEST_CASES += \ li_std_wstream \ li_std_wstring \ primitive_types \ - python_abstractbase \ + python_abstractbase \ python_append \ python_director \ python_nondynamic \ @@ -165,6 +165,9 @@ endif clean: $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile python_clean rm -f hugemod.h hugemod_a.i hugemod_b.i hugemod_a.py hugemod_b.py hugemod_runme.py + rm -f clientdata_prop_a.py clientdata_prop_b.py import_stl_a.py import_stl_b.py + rm -f imports_a.py imports_b.py mod_a.py mod_b.py multi_import_a.py + rm -f multi_import_b.py packageoption_a.py packageoption_b.py packageoption_c.py cvsignore: @echo '*wrap* *.pyc *.so *.dll *.exp *.lib' From 3834036e138339650917a4b320029a7d01629681 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 7 Jun 2013 19:56:38 +0100 Subject: [PATCH 0658/1160] Fix Ruby regression with missing rb_complex_new function. Affects Ruby versions prior to 1.9 using std::complex wrappers if just using std::complex as an output type. Also fix the Complex helper functions external visibility (to static by default). Closes #52 --- CHANGES.current | 5 +++++ Lib/ruby/rubycomplex.swg | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 208c99f68..4b0633c22 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.11 (in progress) ============================ +2013-07-07: wsfulton + [Ruby] Git issue #52. Fix regression with missing rb_complex_new function for Ruby + versions prior to 1.9 using std::complex wrappers if just using std::complex as an output type. + Also fix the Complex helper functions external visibility (to static by default). + 2013-06-04: olly [PHP] Fix SWIG_ZTS_ConvertResourcePtr() not to dereference NULL if the type lookup fails. diff --git a/Lib/ruby/rubycomplex.swg b/Lib/ruby/rubycomplex.swg index 542051e99..4e249c71f 100644 --- a/Lib/ruby/rubycomplex.swg +++ b/Lib/ruby/rubycomplex.swg @@ -7,34 +7,39 @@ See the std_complex.i and ccomplex.i for concrete examples. */ -%fragment("SWIG_Complex_Numbers","header") +%fragment("rb_complex_new","header") { %#if !defined(T_COMPLEX) /* Ruby versions prior to 1.9 did not have native complex numbers. They were an extension in the STD library. */ -VALUE rb_complex_new(VALUE x, VALUE y) { +SWIGINTERN VALUE rb_complex_new(VALUE x, VALUE y) { static ID new_id = rb_intern("new"); static VALUE cComplex = rb_const_get(rb_cObject, rb_intern("Complex")); return rb_funcall(cComplex, new_id, 2, x, y); } +%#endif +} -static int SWIG_Is_Complex( VALUE obj ) { +%fragment("SWIG_Complex_Numbers","header") +{ +%#if !defined(T_COMPLEX) +SWIGINTERN int SWIG_Is_Complex( VALUE obj ) { static ID real_id = rb_intern("real"); static ID imag_id = rb_intern("imag"); return ( (rb_respond_to( obj, real_id ) ) && (rb_respond_to( obj, imag_id ) ) ); } %#else -static int SWIG_Is_Complex( VALUE obj ) { +SWIGINTERN int SWIG_Is_Complex( VALUE obj ) { return TYPE(obj) == T_COMPLEX; } %#endif -VALUE SWIG_Complex_Real(VALUE obj) { +SWIGINTERN VALUE SWIG_Complex_Real(VALUE obj) { static ID real_id = rb_intern("real"); return rb_funcall(obj, real_id, 0); } -VALUE SWIG_Complex_Imaginary(VALUE obj) { +SWIGINTERN VALUE SWIG_Complex_Imaginary(VALUE obj) { static ID imag_id = rb_intern("imag"); return rb_funcall(obj, imag_id, 0); } @@ -48,7 +53,7 @@ VALUE SWIG_Complex_Imaginary(VALUE obj) { /* the common from converter */ %define %swig_fromcplx_conv(Type, Real, Imag) -%fragment(SWIG_From_frag(Type),"header") +%fragment(SWIG_From_frag(Type),"header",fragment="rb_complex_new") { SWIGINTERNINLINE VALUE SWIG_From(Type)(%ifcplusplus(const Type&, Type) c) From 5766f1913234362c1bd5e29f9d80295c67d5f43f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 7 Jun 2013 20:18:28 +0100 Subject: [PATCH 0659/1160] Remove lines with just spaces on them in Ruby docs --- Doc/Manual/Ruby.html | 6510 ------------------------------------------ 1 file changed, 6510 deletions(-) diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index 9739e1109..d1dcbfab0 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -144,10 +144,6 @@

    This chapter describes SWIG's support of Ruby.

    - - - -

    36.1 Preliminaries

    @@ -157,123 +153,59 @@ should also determine if your system supports shared libraries and dynamic loading. SWIG will work with or without dynamic loading, but the compilation process will vary.

    - - - -

    This chapter covers most SWIG features, but in less depth than is found in earlier chapters. At the very least, make sure you also read the "SWIG Basics" chapter. It is also assumed that the reader has a basic understanding of Ruby.

    - - - -

    36.1.1 Running SWIG

    To build a Ruby module, run SWIG using the -ruby option:

    - - - -
    $ swig -ruby example.i
     
    - - - - -
    - - - -

    If building a C++ extension, add the -c++ option:

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

    This creates a file example_wrap.c (example_wrap.cxx if compiling a C++ extension) that contains all of the code needed to build a Ruby extension module. To finish building the module, you need to compile this file and link it with the rest of your program.

    - - - -

    36.1.2 Getting the right header files

    In order to compile the wrapper code, the compiler needs the ruby.h header file. This file is usually contained in a directory such as

    - - - -
    /usr/lib/ruby/1.8/x86_64-linux-gnu/ruby.h
     /usr/local/lib/ruby/1.6/i686-linux/ruby.h
     
    - - - - -
    - - - -

    The exact location may vary on your machine, but the above location is typical. If you are not entirely sure where Ruby is installed, you can run Ruby to find out. For example:

    - - - -
    $ ruby -e 'puts $:.join("\n")'
     /usr/local/lib/ruby/site_ruby/1.6 /usr/local/lib/ruby/site_ruby/1.6/i686-linux
     /usr/local/lib/ruby/site_ruby /usr/local/lib/ruby/1.6 /usr/local/lib/ruby/1.6/i686-linux .
     
    - - - - -
    - - - -

    36.1.3 Compiling a dynamic module

    @@ -283,100 +215,28 @@ exact commands for doing this vary from platform to platform, your best bet is to follow the steps described in the README.EXT file from the Ruby distribution:

    - - - -
      - - - - -
    1. - - - -

      Create a file called extconf.rb that looks like the following:

      - - - - - - - - -
      require 'mkmf'
      create_makefile('example')
      - - - - -
    2. - - - - -
    3. - - - -

      Type the following to build the extension:

      - - - - - - - - -
      - - - -
      $ ruby extconf.rb
      $ make
      $ make install
      - - - - -
      - - - - -
    4. - - - - -
    - - - -

    Of course, there is the problem that mkmf does not work correctly on all platforms, e.g, HPUX. If you need to add your own make rules to the file that extconf.rb produces, you can add this:

    - - - -
    open("Makefile", "a") { |mf|
      puts <<EOM
    @@ -384,17 +244,8 @@ can add this: 

    EOM }
    - - - - -
    - - - -

    to the end of the extconf.rb file. If for some reason you don't want to use the standard approach, you'll need to determine the correct compiler and linker flags for your build @@ -402,27 +253,14 @@ platform. For example, assuming you have code you need to link to in a file called example.c, a typical sequence of commands for the Linux operating system would look something like this:

    - - - -
    $ swig -ruby example.i
     $ gcc -c example.c
     $ gcc -c example_wrap.c -I/usr/local/lib/ruby/1.6/i686-linux 
     $ gcc -shared example.o example_wrap.o -o example.so
     
    - - - - -
    - - - -

    For other platforms it may be necessary to compile with the -fPIC option to generate position-independent code. If in doubt, consult the manual pages for your compiler and linker to determine the correct set @@ -437,10 +275,6 @@ but the convention for Ruby feature names is to use lowercase names. So, for example, the Etc extension module is imported by requiring the etc feature:

    - - - -
    # The feature name begins with a lowercase letter...
     require 'etc'
    @@ -448,47 +282,21 @@ require 'etc'
     # ... but the module name begins with an uppercase letter
     puts "Your login name: #{Etc.getlogin}"
     
    - - - - -
    - - - -

    To stay consistent with this practice, you should always specify a lowercase module name with SWIG's %module directive. SWIG will automatically correct the resulting Ruby module name for your extension. So for example, a SWIG interface file that begins with:

    - - - -
    %module example
    - - - - -
    - - - -

    will result in an extension module using the feature name "example" and Ruby module name "Example".

    - - - -

    36.1.5 Static linking

    @@ -499,41 +307,22 @@ loading support on certain machines. However, the situation has improved greatly over the last few years and you should not consider this approach unless there is really no other option.

    - - - -

    The usual procedure for adding a new module to Ruby involves finding the Ruby source, adding an entry to the ext/Setup file, adding your directory to the list of extensions in the file, and finally rebuilding Ruby.

    - -

    36.1.6 Compilation of C++ extensions

    On most machines, C++ extension modules should be linked using the C++ compiler. For example:

    - - - -
    $ swig -c++ -ruby example.i
    $ g++ -c example.cxx
    $ g++ -c example_wrap.cxx -I/usr/local/lib/ruby/1.6/i686-linux
    $ g++ -shared example.o example_wrap.o -o example.so
    - - - - -
    - - - -

    If you've written an extconf.rb script to automatically generate a Makefile for your C++ extension module, keep in mind that (as of this writing) Ruby still @@ -545,23 +334,10 @@ module's append_library() method to add one of the C++ runtime libraries to the list of libraries linked into your extension, e.g.

    - - - -
    require 'mkmf'
    $libs = append_library($libs, "supc++")
    create_makefile('example')
    - - - - -
    - - - -

    36.2 Building Ruby Extensions under Windows 95/NT

    @@ -572,24 +348,11 @@ recent versions of Ruby, the procedure described above (i.e. using an extcon script) will work with Windows as well; you should be able to build your code into a DLL by typing:

    - - - -
    C:\swigtest> ruby extconf.rb
    C:\swigtest> nmake
    C:\swigtest> nmake install
    - - - - -
    - - - -

    The remainder of this section covers the process of compiling SWIG-generated Ruby extensions with Microsoft Visual C++ 6 (i.e. within the Developer Studio IDE, instead of using the command line tools). In @@ -597,84 +360,35 @@ order to build extensions, you may need to download the source distribution to the Ruby package, as you will need the Ruby header files.

    - - - -

    36.2.1 Running SWIG from Developer Studio

    If you are developing your application within Microsoft developer studio, SWIG can be invoked as a custom build option. The process roughly follows these steps :

    - - - - -
      - - - - -
    • Open up a new workspace and use the AppWizard to select a DLL project.
    • - - - - -
    • Add both the SWIG interface file (the .i file), any supporting C files, and the name of the wrapper file that will be created by SWIG (i.e. example_wrap.c). Note : If using C++, choose a different suffix for the wrapper file such as example_wrap.cxx. Don't worry if the wrapper file doesn't exist yet--Developer Studio will keep a reference to it around.
    • - - - - -
    • Select the SWIG interface file and go to the settings menu. Under settings, select the "Custom Build" option.
    • - - - - -
    • Enter "SWIG" in the description field.
    • - - - - -
    • Enter "swig -ruby -o $(ProjDir)\$(InputName)_wrap.c $(InputPath)" in the "Build command(s) field". You may have to include the path to swig.exe.
    • - - - - -
    • Enter "$(ProjDir)\$(InputName)_wrap.c" in the "Output files(s) field".
    • - - - - -
    • Next, select the settings for the entire project and go to the C/C++ tab and select the Preprocessor category. Add NT=1 to the Preprocessor definitions. This must be set else you will get compilation errors. Also add IMPORT to the preprocessor definitions, else you may get runtime errors. Also add the include directories for your Ruby installation under "Additional include directories".
    • - - - - -
    • Next, select the settings for the entire project and go to the Link tab and select the General category. Set the name of the output file to match the name of your Ruby module (i.e.. example.dll). @@ -682,23 +396,9 @@ Next add the Ruby library file to your link libraries under Object/Library modules. For example "mswin32-ruby16.lib. You also need to add the path to the library under the Input tab - Additional library path.
    • - - - - -
    • Build your project.
    • - - - - -
    - - - -

    Now, assuming all went well, SWIG will be automatically invoked when you build your project. Any changes made to the interface file will result in SWIG being automatically invoked to produce a new @@ -706,98 +406,42 @@ version of the wrapper file. To run your new Ruby extension, simply run Ruby and use the require command as normal. For example if you have this ruby file run.rb:

    - - - -
    # file: run.rb
    require 'Example'

    # Call a c function
    print "Foo = ", Example.Foo, "\n"
    - - - - -
    - - - -

    Ensure the dll just built is in your path or current directory, then run the Ruby script from the DOS/Command prompt:

    - - - -
    C:\swigtest> ruby run.rb
    Foo = 3.0
    - - - - -
    - - - -

    36.3 The Ruby-to-C/C++ Mapping

    This section describes the basics of how SWIG maps C or C++ declarations in your SWIG interface files to Ruby constructs.

    - - - -

    36.3.1 Modules

    The SWIG %module directive specifies the name of the Ruby module. If you specify:

    - - - -
    %module example
    - - - - -
    - - - -

    then everything is wrapped into a Ruby module named Example that is nested directly under the global module. You can specify a more deeply nested module by specifying the fully-qualified module name in quotes, e.g.

    - - - -
    %module "foo::bar::spam"
    - - - - -
    - - - -

    An alternate method of specifying a nested module name is to use the -prefix option on the SWIG command line. The prefix that you specify with this @@ -805,112 +449,42 @@ option will be prepended to the module name specified with the

    %module "foo::bar::spam"
    - - - - -
  • - - - -

    will result in a nested module name of Foo::Bar::Spam, but you can achieve the same effect by specifying:
    - - - - -

    - - - -
    %module spam
    - - - - -
    - - - -

    and then running SWIG with the -prefix command line option:
    - - - - -

    - - - -
    $ swig -ruby -prefix "foo::bar::" example.i
    - - - - -
    - - - -

    Starting with SWIG 1.3.20, you can also choose to wrap everything into the global module by specifying the -globalmodule option on the SWIG command line, i.e.

    - - - -
    $ swig -ruby -globalmodule example.i
    - - - - -
    - - - -

    Note that this does not relieve you of the requirement of specifying the SWIG module name with the %module directive (or the -module command-line option) as described earlier.

    - - - -

    When choosing a module name, do not use the same name as a built-in Ruby command or standard module name, as the results may be unpredictable. Similarly, if you're using the -globalmodule @@ -918,10 +492,6 @@ option to wrap everything into the global module, take care that the names of your constants, classes and methods don't conflict with any of Ruby's built-in names.

    - - - -

    36.3.2 Functions

    @@ -929,62 +499,23 @@ Ruby's built-in names.

    example, given the SWIG interface file example.i:

    - - - -
    %module example

    int fact(int n);
    - - - - -
    - - - -

    and C source file example.c:

    - - - -
    int fact(int n) {
    if (n == 0)
    return 1;
    return (n * fact(n-1));
    }
    - - - - -
    - - - -

    SWIG will generate a method fact in the Example module that can be used like so:

    - - - -
    $ irb
    irb(main):001:0> require 'example'
    true
    irb(main):002:0> Example.fact(4)
    24
    - - - - -
    - - - -

    36.3.3 Variable Linking

    @@ -993,98 +524,38 @@ methods for the module: one to get the value of the global variable and one to set it. For example, the following SWIG interface file declares two global variables:

    - - - -
    // SWIG interface file with global variables
    %module example
    ...
    %inline %{
    extern int variable1;
    extern double Variable2;
    %}
    ...
    - - - - -
    - - - -

    Now look at the Ruby interface:

    - - - -
    $ irb
    irb(main):001:0> require 'Example'
    true
    irb(main):002:0> Example.variable1 = 2
    2
    irb(main):003:0> Example.Variable2 = 4 * 10.3
    41.2
    irb(main):004:0> Example.Variable2
    41.2
    - - - - -
    - - - -

    If you make an error in variable assignment, you will receive an error message. For example:

    - - - -
    irb(main):005:0> Example.Variable2 = "hello"
    TypeError: no implicit conversion to float from string
    from (irb):5:in `Variable2='
    from (irb):5
    - - - - -
    - - - -

    If a variable is declared as const, it is wrapped as a read-only variable. Attempts to modify its value will result in an error.

    - - - -

    To make ordinary variables read-only, you can also use the %immutable directive. For example:

    - - - -
    %immutable;
    %inline %{
    extern char *path;
    %}
    %mutable;
    - - - - -
    - - - -

    The %immutable directive stays in effect until it is explicitly disabled using %mutable.

    - - - -

    36.3.4 Constants

    @@ -1092,43 +563,17 @@ effect until it is explicitly disabled using %mutable. to the appropriate value. To create a constant, use #define or the %constant directive. For example:

    - - - -
    #define PI 3.14159
    #define VERSION "1.0"

    %constant int FOO = 42;
    %constant const char *path = "/usr/local";

    const int BAR = 32;
    - - - - -
    - - - -

    Remember to use the :: operator in Ruby to get at these constant values, e.g.

    - - - -
    $ irb
    irb(main):001:0> require 'Example'
    true
    irb(main):002:0> Example::PI
    3.14159
    - - - - -
    - - - -

    36.3.5 Pointers

    @@ -1137,50 +582,20 @@ aren't explicitly declared in your SWIG interface file) are wrapped as data objects. So, for example, consider a SWIG interface file containing only the declarations:

    - - - -
    Foo *get_foo();
    void set_foo(Foo *foo);
    - - - - -
    - - - -

    For this case, the get_foo() method returns an instance of an internally generated Ruby class:

    - - - -
    irb(main):001:0> foo = Example::get_foo()
    #<SWIG::TYPE_p_Foo:0x402b1654>
    - - - - -
    - - - -

    A NULL pointer is always represented by the Ruby nil object.

    - - - -

    36.3.6 Structures

    @@ -1188,74 +603,31 @@ the Ruby nil object.

    methods (i.e. "getters" and "setters") for all of the struct members. For example, this struct declaration:

    - - - -
    struct Vector {
    double x, y;
    };
    - - - - -
    - - - -

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

    - - - -
    $ irb
    irb(main):001:0> require 'Example'
    true
    irb(main):002:0> f = Example::Vector.new
    #<Example::Vector:0x4020b268>
    irb(main):003:0> f.x = 10
    nil
    irb(main):004:0> f.x
    10.0
    - - - - -
    - - - -

    Similar access is provided for unions and the public data members of C++ classes.

    - - - -

    const members of a structure are read-only. Data members can also be forced to be read-only using the %immutable directive (in C++, private may also be used). For example:

    - - - -
    struct Foo {
    ...
    %immutable;
    int x; /* Read-only members */
    char *name;
    %mutable;
    ...
    };
    - - - - -
    - - - -

    When char * members of a structure are wrapped, the contents are assumed to be dynamically allocated using malloc or new (depending on whether or not SWIG is run @@ -1264,98 +636,38 @@ is set, the old contents will be released and a new value created. If this is not the behavior you want, you will have to use a typemap (described shortly).

    - - - -

    Array members are normally wrapped as read-only. For example, this code:

    - - - -
    struct Foo {
    int x[50];
    };
    - - - - -
    - - - -

    produces a single accessor function like this:

    - - - -
    int *Foo_x_get(Foo *self) {
    return self->x;
    };
    - - - - -
    - - - -

    If you want to set an array member, you will need to supply a "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).

    - - - -

    When structure members are wrapped, they are handled as pointers. For example,

    - - - -
    struct Foo {
    ...
    };

    struct Bar {
    Foo f;
    };
    - - - - -
    - - - -

    generates accessor functions such as this:

    - - - -
    Foo *Bar_f_get(Bar *b) {
    return &b->f;
    }

    void Bar_f_set(Bar *b, Foo *val) {
    b->f = *val;
    }
    - - - - -
    - - - -

    36.3.7 C++ classes

    @@ -1366,152 +678,55 @@ wrapped as Ruby instance methods, and public static member functions are wrapped as Ruby singleton methods. So, given the C++ class declaration:

    - - - -
    class List {
    public:
    List();
    ~List();
    int search(char *item);
    void insert(char *item);
    void remove(char *item);
    char *get(int n);
    int length;
    static void print(List *l);
    };
    - - - - -
    - - - -

    SWIG would create a List class with:

    - - - -
      - - - - -
    • instance methods search, insert, remove, and get;
    • - - - - -
    • instance methods length and length= (to get and set the value of the length data member); and,
    • - - - - -
    • a print singleton method for the class.
    • - - - - -
    - - - -

    In Ruby, these functions are used as follows:

    - - - -
    require 'Example'

    l = Example::List.new

    l.insert("Ale")
    l.insert("Stout")
    l.insert("Lager")
    Example.print(l)
    l.length()
    ----- produces the following output
    Lager
    Stout
    Ale
    3
    - - - - -
    - - - -

    36.3.8 C++ Inheritance

    The SWIG type-checker is fully aware of C++ inheritance. Therefore, if you have classes like this:

    - - - -
    class Parent {
    ...
    };

    class Child : public Parent {
    ...
    };
    - - - - -
    - - - -

    those classes are wrapped into a hierarchy of Ruby classes that reflect the same inheritance structure. All of the usual Ruby utility methods work normally:

    - - - -
    irb(main):001:0> c = Child.new
    #<Bar:0x4016efd4>
    irb(main):002:0> c.instance_of? Child
    true
    irb(main):003:0> b.instance_of? Parent
    false
    irb(main):004:0> b.is_a? Child
    true
    irb(main):005:0> b.is_a? Parent
    true
    irb(main):006:0> Child < Parent
    true
    irb(main):007:0> Child > Parent
    false
    - - - - -
    - - - -

    Furthermore, if you have a function like this:

    - - - -
    void spam(Parent *f);
    - - - - -
    - - - -

    then the function spam() accepts Parent* or a pointer to any class derived from Parent.

    - - - -

    Until recently, the Ruby module for SWIG didn't support multiple inheritance, and this is still the default behavior. This doesn't mean that you can't wrap C++ classes which inherit from @@ -1520,23 +735,10 @@ base class listed in the class declaration is considered, and any additional base classes are ignored. As an example, consider a SWIG interface file with a declaration like this:

    - - - -
    class Derived : public Base1, public Base2
    {
    ...
    };
    - - - - -
    - - - -

    For this case, the resulting Ruby class (Derived) will only consider Base1 as its superclass. It won't inherit any of Base2's member functions or @@ -1545,66 +747,27 @@ data and it won't recognize Base2 as an relationship would fail). When SWIG processes this interface file, you'll see a warning message like:

    - - - -
    example.i:5: Warning 802: Warning for Derived: Base Base2 ignored.
    Multiple inheritance is not supported in Ruby.
    - - - - -
    - - - -

    Starting with SWIG 1.3.20, the Ruby module for SWIG provides limited support for multiple inheritance. Because the approach for dealing with multiple inheritance introduces some limitations, this is an optional feature that you can activate with the -minherit command-line option:

    - - - -
    $ swig -c++ -ruby -minherit example.i
    - - - - -
    - - - -

    Using our previous example, if your SWIG interface file contains a declaration like this:

    - - - -
    class Derived : public Base1, public Base2
    {
    ...
    };
    - - - - -
    - - - -

    and you run SWIG with the -minherit command-line option, then you will end up with a Ruby class Derived that appears to "inherit" the member data and functions from both Base1 @@ -1615,64 +778,30 @@ module named Impl, and it's in these nested Impl modules that the actual instance methods for the classes are defined, i.e.

    - - - -
    class Base1
    module Impl
    # Define Base1 methods here
    end
    include Impl
    end

    class Base2
    module Impl
    # Define Base2 methods here
    end
    include Impl
    end

    class Derived
    module Impl
    include Base1::Impl
    include Base2::Impl
    # Define Derived methods here
    end
    include Impl
    end
    - - - - -
    - - - -

    Observe that after the nested Impl module for a class is defined, it is mixed-in to the class itself. Also observe that the Derived::Impl module first mixes-in its base classes' Impl modules, thus "inheriting" all of their behavior.

    - - - -

    The primary drawback is that, unlike the default mode of operation, neither Base1 nor Base2 is a true superclass of Derived anymore:

    - - - -
    obj = Derived.new
    obj.is_a? Base1 # this will return false...
    obj.is_a? Base2 # ... and so will this
    - - - - -
    - - - -

    In most cases, this is not a serious problem since objects of type Derived will otherwise behave as though they inherit from both Base1 and Base2 (i.e. they exhibit "Duck Typing").

    - - - -

    36.3.9 C++ Overloaded Functions

    @@ -1680,199 +809,74 @@ Typing").

    mostly supported by SWIG. For example, if you have two functions like this:

    - - - -
    void foo(int);
    void foo(char *c);
    - - - - -
    - - - -

    You can use them in Ruby in a straightforward manner:

    - - - -
    irb(main):001:0> foo(3) # foo(int)
    irb(main):002:0> foo("Hello") # foo(char *c)
    - - - - -
    - - - -

    Similarly, if you have a class like this,

    - - - -
    class Foo {
    public:
    Foo();
    Foo(const Foo &);
    ...
    };
    - - - - -
    - - - -

    you can write Ruby code like this:

    - - - -
    irb(main):001:0> f = Foo.new # Create a Foo
    irb(main):002:0> g = Foo.new(f) # Copy f
    - - - - -
    - - - -

    Overloading support is not quite as flexible as in C++. Sometimes there are methods that SWIG can't disambiguate. For example:

    - - - -
    void spam(int);
    void spam(short);
    - - - - -
    - - - -

    or

    - - - -
    void foo(Bar *b);
    void foo(Bar &b);
    - - - - -
    - - - -

    If declarations such as these appear, you will get a warning message like this:

    - - - -
     example.i:12: Warning 509: Overloaded method spam(short) effectively ignored,
     example.i:11: Warning 509: as it is shadowed by spam(int).
     
    - - - - -
    - - - -

    To fix this, you either need to ignore or rename one of the methods. For example:

    - - - -
    %rename(spam_short) spam(short);
    ...
    void spam(int);
    void spam(short); // Accessed as spam_short
    - - - - -
    - - - -

    or

    - - - -
    %ignore spam(short);
    ...
    void spam(int);
    void spam(short); // Ignored
    - - - - -
    - - - -

    SWIG resolves overloaded functions and methods using a disambiguation scheme that ranks and sorts declarations according to a set of type-precedence rules. The order in which declarations appear in the input does not matter except in situations where ambiguity arises--in this case, the first declaration takes precedence.

    - - - -

    Please refer to the "SWIG and C++" chapter for more information about overloading.

    - - - -

    36.3.10 C++ Operators

    @@ -1880,80 +884,33 @@ and C++" chapter for more information about overloading.

    automatically by SWIG and do not require any special treatment on your part. So if your class declares an overloaded addition operator, e.g.

    - - - -
    class Complex {
    ...
    Complex operator+(Complex &);
    ...
    };
    - - - - -
    - - - -

    the resulting Ruby class will also support the addition (+) method correctly.

    - - - -

    For cases where SWIG's built-in support is not sufficient, C++ operators can be wrapped using the %rename directive (available on SWIG 1.3.10 and later releases). All you need to do is give the operator the name of a valid Ruby identifier. For example:

    - - - -
    %rename(add_complex) operator+(Complex &, Complex &);
    ...
    Complex operator+(Complex &, Complex &);
    - - - - -
    - - - -

    Now, in Ruby, you can do this:

    - - - -
    a = Example::Complex.new(2, 3)
    b = Example::Complex.new(4, -1)
    c = Example.add_complex(a, b)
    - - - - -
    - - - -

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

    - - - -

    36.3.11 C++ namespaces

    @@ -1962,63 +919,24 @@ 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,

    - - - -
    %module example

    namespace foo {
    int fact(int n);
    struct Vector {
    double x,y,z;
    };
    };
    - - - - -
    - - - -

    it works in Ruby as follows:

    - - - -
    irb(main):001:0> require 'example'
    true
    irb(main):002:0> Example.fact(3)
    6
    irb(main):003:0> v = Example::Vector.new
    #<Example::Vector:0x4016f4d4>
    irb(main):004:0> v.x = 3.4
    3.4
    irb(main):004:0> v.y
    0.0
    - - - - -
    - - - -

    If your program has more than one namespace, name conflicts (if any) can be resolved using %rename For example:

    - - - -
    %rename(Bar_spam) Bar::spam;

    namespace Foo {
    int spam();
    }

    namespace Bar {
    int spam();
    }
    - - - - -
    - - - -

    If you have more than one namespace and your want to keep their symbols separate, consider wrapping them as separate SWIG modules. For example, make the module name the same as the namespace @@ -2026,10 +944,6 @@ and create extension modules for each namespace separately. If your program utilizes thousands of small deeply nested namespaces each with identical symbol names, well, then you get what you deserve.

    - - - -

    36.3.12 C++ templates

    @@ -2038,42 +952,16 @@ in order to create wrappers, you have to tell SWIG to create wrappers for a particular template instantiation. To do this, you use the %template directive. For example:

    - - - -
    %module example

    %{
    #include "pair.h"
    %}

    template<class T1, class T2>
    struct pair {
    typedef T1 first_type;
    typedef T2 second_type;
    T1 first;
    T2 second;
    pair();
    pair(const T1&, const T2&);
    ~pair();
    };

    %template(Pairii) pair<int,int>;
    - - - - -
    - - - -

    In Ruby:

    - - - -
    irb(main):001:0> require 'example'
    true
    irb(main):002:0> p = Example::Pairii.new(3, 4)
    #<Example:Pairii:0x4016f4df>
    irb(main):003:0> p.first
    3
    irb(main):004:0> p.second
    4
    - - - - -
    - - - -

    36.3.13 C++ Standard Template Library (STL)

    @@ -2087,71 +975,28 @@ convenient for users of your extension module to pass Ruby objects of standard C++ templates. For example, suppose the C++ library you're wrapping has a function that expects a vector of floats:

    - - - -
    %module example

    float sum(const std::vector<float>& values);
    - - - - -
    - - - -

    Rather than go through the hassle of writing an "in" typemap to convert an array of Ruby numbers into a std::vector<float>, you can just use the std_vector.i module from the standard SWIG library:

    - - - -
    %module example

    %include std_vector.i
    float sum(const std::vector<float>& values);
    - - - - -
    - - - -

    Ruby's STL wrappings provide additional methods to make them behave more similarly to Ruby's native classes.

    - - - -

    Thus, you can do, for example:

    - - - -
    v = IntVector.new
    v << 2

    v << 3
    v << 4
    v.each { |x| puts x }

    => 2

    3
    4
    v.delete_if { |x| x == 3 }
    => [2,4]
    - - - - -
    - - - -

    The SWIG Ruby module provides also the ability for all the STL containers to carry around Ruby native objects (Fixnum, Classes, etc) making them act almost like Ruby's own Array, Hash, etc.   To @@ -2159,174 +1004,50 @@ do that, you need to define a container that contains a swig::GC_VALUE, like:

    - - - -
    %module nativevector
    - - - - -
    - - - - %{
    - - - - - std::vector< swig::GC_VALUE > NativeVector;
    - - - - - %}
    - - - - -
    - - - - %template(NativeVector) std::vector< swig::GC_VALUE >;
    - - - - -
    - - - -
    - - - -

    This vector can then contain any Ruby object, making them almost identical to Ruby's own Array class.

    - - - -
    require 'nativevector'
    - - - - include NativeVector
    - - - -
    - - - - v = NativeVector.new
    - - - - - v << 1
    - - - - - v << [1,2]
    - - - - - v << 'hello'
    - - - - -
    - - - - - class A; end
    - - - - -
    - - - - - v << A.new
    - - - - -
    - - - - - puts v
    - - - - - => [1, [1,2], 'hello', #<A:0x245325>]
    - - - - -
    - - - -

    Obviously, there is a lot more to template wrapping than shown in these examples. More details can be found in the SWIG and C++ chapter.

    - - - -

    36.3.14 C++ STL Functors

    @@ -2337,10 +1058,6 @@ redefined or an actual C/C++ function.  This allows you, for example, to always keep the sort order of a STL container to your liking.

    - - - -

    The Ruby STL mappings allows you to modify those containers that support functors using Ruby procs or methods, instead. @@ -2350,183 +1067,55 @@ this includes std::set, std::multiset and std::multimap.

    - - - -

    The functors in swig are called swig::UnaryFunction and swig::BinaryFunction.
    - - - - For C++ predicates (ie. functors that must return bool as a result) swig::UnaryPredicate and swig::BinaryPredicate are provided.

    - - - -

    As an example, if given this swig file:

    - - - -
    %module intset;
    - - - - -
    - - - - - %include <std_set.i>
    - - - - -
    - - - - %typemap(IntSet)  std::set< int, swig::BinaryPredicate >;
    - - - -

    You can then use the set from Ruby with or without a proc object as a predicate:

    - - - -
    require 'intset'
    - - - - include Intset
    - - - - -
    - - - - - # Default sorting behavior defined in C++
    - - - - - a = IntSet.new
    - - - - a << 1
    - - - - - a << 2
    - - - - - a << 3
    - - - - - a
    - - - - =>  [1,2,3]
    - - - - -
    - - - - # Custom sorting behavior defined by a Ruby proc
    b = IntSet.new( proc { |a,b| a > b } )
    - - - - - b << 1
    - - - - - b << 2
    - - - - - b << 3
    - - - - - b
    - - - - - =>  [3,2,1]
    - - - - -
    - - - -

    36.3.15 C++ STL Iterators

    @@ -2537,10 +1126,6 @@ iterators.  The const iterators can access and not modify the values they point at, while the non-const iterators can both read and modify the values.

    - - - -

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

    - - - -

    The SWIG STL library already provides typemaps to all the standard containers to do this wrapping automatically for you, but if you have your own STL-like iterator, you will need to write your own @@ -2563,10 +1144,6 @@ typemap for them.  For out typemaps, the special functions - - - -

    The iterators support a next() and previous() member function to just change the iterator without returning anything.  previous() should obviously only be used for bidirectional iterators.  You @@ -2579,85 +1156,33 @@ value the iterator points at can be accessed with *i = something

    - - - -

    Thus, given say a vector class of doubles defined as:

    - - - -
    %module doublevector
    - - - -
    - - - - %include std_vector.i

    - - - -
    - - - - %template(DoubleVector) std::vector<double>;
    - - - -

    Its iterator can then be used from Ruby like:

    - - - -
    require 'doublevector'
    - - - - include Doublevector

    - - - - v = DoubleVector.new
    - - - - v << 1
    - - - - v << 2
    - - - - v << 3

    @@ -2668,76 +1193,30 @@ v << 3
    #
    - - - - i = v.begin
    - - - - e = v.end
    - - - - while i != e
    - - - -   val = i.value
    - - - -   val += 2
    - - - -   i.value = val
    - - - -   i.next
    - - - - end
    - - - i
    - - - >> [3, 4, 5 ]
    - - - -

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

    - - - -

    36.3.16 C++ Smart Pointers

    @@ -2746,123 +1225,45 @@ have been wrapped by so-called "smart pointers." Generally, this involves the use of a template class that implements operator->() like this:

    - - - -
    template<class T> class SmartPtr {
    ...
    T *operator->();
    ...
    }
    - - - - -
    - - - -

    Then, if you have a class like this,

    - - - -
    class Foo {
    public:
    int x;
    int bar();
    };
    - - - - -
    - - - -

    A smart pointer would be used in C++ as follows:

    - - - -
    SmartPtr<Foo> p = CreateFoo(); // Created somehow (not shown)
    ...
    p->x = 3; // Foo::x
    int y = p->bar(); // Foo::bar
    - - - - -
    - - - -

    To wrap this in Ruby, simply tell SWIG about the SmartPtr class and the low-level Foo object. Make sure you instantiate SmartPtr using %template if necessary. For example:

    - - - -
    %module example
    ...
    %template(SmartPtrFoo) SmartPtr<Foo>;
    ...
    - - - - -
    - - - -

    Now, in Ruby, everything should just "work":

    - - - -
    irb(main):001:0> p = Example::CreateFoo() # Create a smart-pointer somehow
    #<Example::SmartPtrFoo:0x4016f4df>
    irb(main):002:0> p.x = 3 # Foo::x
    3
    irb(main):003:0> p.bar() # Foo::bar
    - - - - -
    - - - -

    If you ever need to access the underlying pointer returned by operator->() itself, simply use the __deref__() method. For example:

    - - - -
    irb(main):004:0> f = p.__deref__() # Returns underlying Foo *
    - - - - -
    - - - -

    36.3.17 Cross-Language Polymorphism

    @@ -2872,10 +1273,6 @@ module. Rather than duplicate the information presented in the 36.3.17.1 Exception Unrolling @@ -2888,32 +1285,15 @@ change this behavior, you can use the %feature("director:except") directive to indicate what action should be taken when a Ruby exception is raised. The following code should suffice in most cases:

    - - - -
    %feature("director:except") {
    throw Swig::DirectorMethodException($error);
    }
    - - - - -
    - - - -

    When this feature is activated, the call to the Ruby instance method is "wrapped" using the rb_rescue2() function from Ruby's C API. If any Ruby exception is raised, it will be caught here and a C++ exception is raised in its place.

    - - - -

    36.4 Naming

    @@ -2922,94 +1302,36 @@ generally in upper case, module and class names are in camel case and methods are in lower case with underscores. For example:

    - - - -
      - - - - -
    • MATH::PI is a constant name
    • - - - - -
    • MyClass is a class name
    • - - - - -
    • my_method is a method name
    • - - - - -
    - - - - -
    - - - -

    Prior to version 1.3.28, SWIG did not support these Ruby conventions. The only modifications it made to names was to capitalize the first letter of constants (which includes module and class names).

    - - - -

    SWIG 1.3.28 introduces the new -autorename command line parameter. When this parameter is specified, SWIG will automatically change constant, class and method names to conform with the standard Ruby naming conventions. For example:

    - - - -
    $ swig -ruby -autorename example.i
     
    - - - - -
    - - - -

    To disable renaming use the -noautorename command line option.

    - - - -

    Since this change significantly changes the wrapper code generated by SWIG, it is turned off by default in SWIG 1.3.28. However, it is planned to become the default option in future releases.

    - - - -

    36.4.1 Defining Aliases

    @@ -3021,65 +1343,26 @@ approach is to use SWIG's %extend directive to add a new method of the aliased name that calls the original function. For example:

    - - - -
    class MyArray {
    public:
    // Construct an empty array
    MyArray();

    // Return the size of this array
    size_t length() const;
    };

    %extend MyArray {
    // MyArray#size is an alias for MyArray#length
    size_t size() const {
    return $self->length();
    }
    }
    - - - - -
    - - - -

    A better solution is to use the %alias directive (unique to SWIG's Ruby module). The previous example could then be rewritten as:

    - - - -
    // MyArray#size is an alias for MyArray#length
    %alias MyArray::length "size";

    class MyArray {
    public:
    // Construct an empty array
    MyArray();

    // Return the size of this array
    size_t length() const;
    };

    - - - - -
    - - - -

    Multiple aliases can be associated with a method by providing a comma-separated list of aliases to the %alias directive, e.g.

    - - - -
    %alias MyArray::length "amount,quantity,size";
    - - - - -
    - - - -

    From an end-user's standpoint, there's no functional difference between these two approaches; i.e. they should get the same result from calling either MyArray#size or MyArray#length. @@ -3088,20 +1371,12 @@ doesn't need to generate all of the wrapper code that's usually associated with added methods like our MyArray::size() example.

    - - - -

    Note that the %alias directive is implemented using SWIG's "features" mechanism and so the same name matching rules used for other kinds of features apply (see the chapter on "Customization Features") for more details).

    - - - -

    36.4.2 Predicate Methods

    @@ -3115,82 +1390,35 @@ if the object is an instance of the specified class). For consistency with Ruby conventions, methods that return boolean values should be marked as predicate methods.

    - - - -

    One cumbersome solution to this problem is to rename the method (using SWIG's %rename directive) and provide a custom typemap that converts the function's actual return type to Ruby's true or false. For example:

    - - - -
    %rename("is_it_safe?") is_it_safe();

    %typemap(out) int is_it_safe
    "$result = ($1 != 0) ? Qtrue : Qfalse;";

    int is_it_safe();

    - - - - -
    - - - -

    A better solution is to use the %predicate directive (unique to SWIG's Ruby module) to designate a method as a predicate method. For the previous example, this would look like:

    - - - -
    %predicate is_it_safe();

    int is_it_safe();

    - - - - -
    - - - -

    This method would be invoked from Ruby code like this:

    - - - -
    irb(main):001:0> Example::is_it_safe?
    true

    - - - - -
    - - - -

    The %predicate directive is implemented using SWIG's "features" mechanism and so the same name matching rules used for other kinds of features apply (see the chapter on "Customization Features") for more details).

    - - - -

    36.4.3 Bang Methods

    @@ -3202,380 +1430,141 @@ which returns a copy of the array with the items sorted instead of modifying the original array. For consistency with Ruby conventions, methods that modify objects in place should be marked as bang methods.

    - - - -

    Bang methods can be marked using the %bang directive which is unique to the Ruby module and was introduced in SWIG 1.3.28. For example:

    - - - -
    %bang sort(int arr[]);

    int sort(int arr[]);
    - - - - -
    - - - -

    This method would be invoked from Ruby code like this:

    - - - -
    irb(main):001:0> Example::sort!(arr)
    - - - - -
    - - - -

    The %bang directive is implemented using SWIG's "features" mechanism and so the same name matching rules used for other kinds of features apply (see the chapter on "Customization Features") for more details).

    - - - -

    36.4.4 Getters and Setters

    Often times a C++ library will expose properties through getter and setter methods. For example:

    - - - -
    class Foo {
    Foo() {}

    int getValue() { return value_; }

    void setValue(int value) { value_ = value; }

    private:
    int value_;
    };
    - - - - -
    - - - -

    By default, SWIG will expose these methods to Ruby as get_value and set_value. However, it more natural for these methods to be exposed in Ruby as value and value=. That allows the methods to be used like this:

    - - - -
    irb(main):001:0> foo = Foo.new()
    irb(main):002:0> foo.value = 5
    irb(main):003:0> puts foo.value
    - - - - -
    - - - -

    This can be done by using the %rename directive:

    - - - -
    %rename("value") Foo::getValue();
    %rename("value=") Foo::setValue(int value);
    - - - - -
    - - - - -

     

    - - - - -

    36.5 Input and output parameters

    A common problem in some C programs is handling parameters passed as simple pointers. For example:

    - - - -
    void add(int x, int y, int *result) {
    *result = x + y;
    }
    or
    int sub(int *x, int *y) {
    return *x-*y;
    }
    - - - - -
    - - - -

    The easiest way to handle these situations is to use the typemaps.i file. For example:

    - - - -
    %module Example
    %include "typemaps.i"

    void add(int, int, int *OUTPUT);
    int sub(int *INPUT, int *INPUT);
    - - - - -
    - - - -

    In Ruby, this allows you to pass simple values. For example:

    - - - -
    a = Example.add(3,4)
    puts a
    7
    b = Example.sub(7,4)
    puts b
    3
    - - - - -
    - - - -

    Notice how the INPUT parameters allow integer values to be passed instead of pointers and how the OUTPUT parameter creates a return result.

    - - - -

    If you don't want to use the names INPUT or OUTPUT, use the %apply directive. For example:

    - - - -
    %module Example
    %include "typemaps.i"

    %apply int *OUTPUT { int *result };
    %apply int *INPUT { int *x, int *y};

    void add(int x, int y, int *result);
    int sub(int *x, int *y);
    - - - - -
    - - - -

    If a function mutates one of its parameters like this,

    - - - -
    void negate(int *x) {
    *x = -(*x);
    }
    - - - - -
    - - - -

    you can use INOUT like this:

    - - - -
    %include "typemaps.i"
    ...
    void negate(int *INOUT);
    - - - - -
    - - - -

    In Ruby, a mutated parameter shows up as a return value. For example:

    - - - -
    a = Example.negate(3)
    print a
    -3

    - - - - -
    - - - -

    The most common use of these special typemap rules is to handle functions that return more than one value. For example, sometimes a function returns a result as well as a special error code:

    - - - -
    /* send message, return number of bytes sent, success code, and error_code */
    int send_message(char *text, int *success, int *error_code);
    - - - - -
    - - - -

    To wrap such a function, simply use the OUTPUT rule above. For example:

    - - - -
    %module example
    %include "typemaps.i"
    ...
    int send_message(char *, int *OUTPUT, int *OUTPUT);
    - - - - -
    - - - -

    When used in Ruby, the function will return an array of multiple values.

    - - - -
    bytes, success, error_code = send_message("Hello World")
    if not success
    print "error #{error_code} : in send_message"
    else
    print "Sent", bytes
    end
    - - - - -
    - - - -

    Another way to access multiple return values is to use the %apply rule. In the following example, the parameters rows and columns are related to SWIG as OUTPUT values through the use of %apply

    - - - -
    %module Example
    %include "typemaps.i"
    %apply int *OUTPUT { int *rows, int *columns };
    ...
    void get_dimensions(Matrix *m, int *rows, int*columns);
    - - - - -
    - - - -

    In Ruby:

    - - - -
    r, c = Example.get_dimensions(m)
    - - - - -
    - - - -

    36.6 Exception handling

    @@ -3588,92 +1577,41 @@ C/C++ errors into Ruby exceptions. The chapter on
    class DoubleArray {
    private:
    int n;
    double *ptr;
    public:
    // Create a new array of fixed size
    DoubleArray(int size) {
    ptr = new double[size];
    n = size;
    }

    // Destroy an array
    ~DoubleArray() {
    delete ptr;
    }

    // Return the length of the array
    int length() {
    return n;
    }

    // Get an array item and perform bounds checking.
    double getitem(int i) {
    if ((i >= 0) && (i < n))
    return ptr[i];
    else
    throw RangeError();
    }

    // Set an array item and perform bounds checking.
    void setitem(int i, double val) {
    if ((i >= 0) && (i < n))
    ptr[i] = val;
    else {
    throw RangeError();
    }
    }
    };
    - - - - -
    - - - -

    Since several methods in this class can throw an exception for an out-of-bounds access, you might want to catch this in the Ruby extension by writing the following in an interface file:

    - - - -
    %exception {
    try {
    $action
    }
    catch (const RangeError&) {
    static VALUE cpperror = rb_define_class("CPPError", rb_eStandardError);
    rb_raise(cpperror, "Range error.");
    }
    }

    class DoubleArray {
    ...
    };
    - - - - -
    - - - -

    The exception handling code is inserted directly into generated wrapper functions. When an exception handler is defined, errors can be caught and used to gracefully raise a Ruby exception instead of forcing the entire program to terminate with an uncaught error.

    - - - -

    As shown, the exception handling code will be added to every wrapper function. Because this is somewhat inefficient, you might consider refining the exception handler to only apply to specific methods like this:

    - - - -
    %exception getitem {
    try {
    $action
    }
    catch (const RangeError&) {
    static VALUE cpperror = rb_define_class("CPPError", rb_eStandardError);
    rb_raise(cpperror, "Range error in getitem.");
    }
    }

    %exception setitem {
    try {
    $action
    }
    catch (const RangeError&) {
    static VALUE cpperror = rb_define_class("CPPError", rb_eStandardError);
    rb_raise(cpperror, "Range error in setitem.");
    }
    }
    - - - - -
    - - - -

    In this case, the exception handler is only attached to methods and functions named getitem and setitem.

    - - - -

    Since SWIG's exception handling is user-definable, you are not limited to C++ exception handling. See the chapter on Customization Features for more examples.

    - - - -

    36.6.2 Handling Ruby Blocks

    @@ -3683,939 +1621,214 @@ the use of blocks, which allow the easy creation of continuations and other niceties.  Blocks in ruby are also often used to simplify the passing of many arguments to a class.

    - - - -

    In order to make your class constructor support blocks, you can take advantage of the %exception directive, which will get run after the C++ class' constructor was called. 

    - - - -

    For example, this yields the class over after its construction:
    - - - -

    - - - -
    class Window
    {
    public:
    Window(int x, int y, int w, int h);
    // .... other methods here ....
    };

    // Add support for yielding self in the Class' constructor.
    %exception Window::Window {
    $action
    if (rb_block_given_p()) {
    rb_yield(self);
    }
    }
    - - - - -
    - - - -

    Then, in ruby, it can be used like:

    - - - -
    Window.new(0,0,360,480) { |w|
    - - - -     w.color = Fltk::RED
    - - - -     w.border = false
    - - - - }
    - - - -
    - - - -

    For other methods, you can usually use a dummy parameter with a special in typemap, like:

    - - - -
    //
    - - - - // original function was:
    - - - - - //
    - - - - - // void func(int x);
    - - - - -
    - - - - - %typemap(in,numinputs=0) int RUBY_YIELD_SELF {
    - - - - -      if ( !rb_block_given_p() )
    - - - - -             rb_raise("No block given");
    - - - - -      return rb_yield(self);
    - - - - - }
    - - - - -
    - - - - - %extend {
    - - - - -         void func(int x, int RUBY_YIELD_SELF );
    - - - - - }
    - - - -

    For more information on typemaps, see Typemaps.

    -

    36.6.3 Raising exceptions

    There are three ways to raise exceptions from C++ code to Ruby.

    - - - -

    The first way is to use SWIG_exception(int code, const char *msg). The following table shows the mappings from SWIG error codes to Ruby exceptions:

    - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - -
    SWIG_MemoryError
    - - - - -
    - - - -
    rb_eNoMemError
    - - - - -
    - - - -
    SWIG_IOError
    - - - - -
    - - - -
    rb_eIOError
    - - - - -
    - - - -
    SWIG_RuntimeError
    - - - - -
    - - - -
    rb_eRuntimeError
    - - - - -
    - - - -
    SWIG_IndexError
    - - - - -
    - - - -
    rb_eIndexError
    - - - - -
    - - - -
    SWIG_TypeError
    - - - - -
    - - - -
    rb_eTypeError
    - - - - -
    - - - -
    SWIG_DivisionByZero
    - - - - -
    - - - -
    rb_eZeroDivError
    - - - - -
    - - - -
    SWIG_OverflowError
    - - - - -
    - - - -
    rb_eRangeError
    - - - - -
    - - - -
    SWIG_SyntaxError
    - - - - -
    - - - -
    rb_eSyntaxError
    - - - - -
    - - - -
    SWIG_ValueError
    - - - - -
    - - - -
    rb_eArgError
    - - - - -
    - - - -
    SWIG_SystemError
    - - - - -
    - - - -
    rb_eFatal
    - - - - -
    - - - -
    SWIG_AttributeError
    - - - - -
    - - - -
    rb_eRuntimeError
    - - - - -
    - - - -
    SWIG_NullReferenceError
    - - - - -
    - - - -
    rb_eNullReferenceError*
    - - - - -
    - - - -
    SWIG_ObjectPreviouslyDeletedError
    - - - - -
    - - - -
    rb_eObjectPreviouslyDeleted*
    - - - - -
    - - - -
    SWIG_UnknownError
    - - - - -
    - - - -
    rb_eRuntimeError
    - - - - -
    - - - -
    * These error classes are created by SWIG and are not built-in Ruby exception classes
    - - - - -
    - - - - -
    - - - -

    The second way to raise errors is to use SWIG_Raise(obj, type, desc). Obj is a C++ instance of an exception class, type is a string specifying the type of exception (for example, "MyError") and desc is the SWIG description of the exception class. For example:

    - - - -
    %raise(SWIG_NewPointerObj(e, SWIGTYPE_p_AssertionFailedException, 0), ":AssertionFailedException", SWIGTYPE_p_AssertionFailedException);
    - - - -

    This is useful when you want to pass the current exception object directly to Ruby, particularly when the object is an instance of class marked as an %exceptionclass (see the next section for more information).

    - - - -

    Last, you can raise an exception by directly calling Ruby's C api. This is done by invoking the rb_raise() function. The first argument passed to rb_raise() is the exception type. You can raise a custom exception type or one of the built-in Ruby exception types.

    - - - -

    36.6.4 Exception classes

    @@ -4626,54 +1839,20 @@ directive are exposed in Ruby as child classes of rb_eRuntimeError. This allows C++ exceptions to be directly mapped to Ruby exceptions, providing for a more natural integration between C++ code and Ruby code.

    - - - -
    	%exceptionclass CustomError;

    %inline %{
    class CustomError { };

    class Foo {
    public:
    void test() { throw CustomError; }
    };
    }
    - - - - -
    - - - -

    From Ruby you can now call this method like this:

    - - - -
    foo = Foo.new
    begin
    foo.test()
    rescue CustomError => e
    puts "Caught custom error"
    end
    - - - - -
    - - - -

    For another example look at swig/Examples/ruby/exception_class.
    - - - -

    - - - -

    36.7 Typemaps

    @@ -4684,19 +1863,11 @@ Ruby C API as well as the material in the "Type chapter. 

    - - - -

    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 primitive C-Ruby interface.

    - - - -

    36.7.1 What is a typemap?

    @@ -4705,106 +1876,47 @@ attached to a specific C datatype. The general form of this declaration is as follows ( parts enclosed in [...] are optional ):    

    - - - -
    %typemap( method [, modifiers...] ) typelist code;
    - - - -

    method is a simply a name that specifies what kind of typemap is being defined. It is usually a name like "in", "out", or "argout" (or its director variations). The purpose of these methods is described later.

    - - - -

    modifiers is an optional comma separated list of name="value" values. These are sometimes to attach extra information to a typemap and is often target-language dependent.

    - - - -

    typelist is a list of the C++ type patterns that the typemap will match. The general form of this list is as follows:

    - - - -
    typelist : typepattern [, typepattern, typepattern, ... ] ;

    typepattern : type [ (parms) ]
    | type name [ (parms) ]
    | ( typelist ) [ (parms) ]
    - - - - -
    - - - -

    Each type pattern is either a simple type, a simple type and argument name, or a list of types in the case of multi-argument typemaps. In addition, each type pattern can be parameterized with a list of temporary variables (parms). The purpose of these variables will be explained shortly.

    - - - -

    code specifies the C code used in the typemap. It can take any one of the following forms:

    - - - -
    code : { ... }
    | " ... "
    | %{ ... %}
    - - - - -
    - - - -

    For example, to convert integers from Ruby to C, you might define a typemap like this:

    - - - -
    %module example

    %typemap(in) int {
    $1 = (int) NUM2INT($input);
    printf("Received an integer : %d\n",$1);
    }

    %inline %{
    extern int fact(int n);
    %}
    - - - - -
    - - - -

    Typemaps are always associated with some specific aspect of code generation. In this case, the "in" method refers to the conversion of input arguments to C/C++. The datatype int is @@ -4814,77 +1926,30 @@ prefaced by a $ are used. The $1 variable is placeholder for a local variable of type int. The $input variable is the input Ruby object.

    - - - -

    When this example is compiled into a Ruby module, the following sample code:

    - - - -
    require 'example'

    puts Example.fact(6)
    - - - - -
    - - - -

    prints the result:

    - - - -
    Received an integer : 6
    720
    - - - - -
    - - - -

    In this example, the typemap is applied to all occurrences of the int datatype. You can refine this by supplying an optional parameter name. For example:

    - - - -
    %module example

    %typemap(in) int n {
    $1 = (int) NUM2INT($input);
    printf("n = %d\n",$1);
    }

    %inline %{
    extern int fact(int n);
    %}
    - - - - -
    - - - -

    In this case, the typemap code is only attached to arguments that exactly match "int n".

    - - - -

    The application of a typemap to specific datatypes and argument names involves more than simple text-matching--typemaps are fully integrated into the SWIG type-system. When you define a typemap @@ -4893,72 +1958,29 @@ and qualified variations such as const int. In addition, the typemap system follows typedef declarations. For example:

    - - - -
    %typemap(in) int n {
    $1 = (int) NUM2INT($input);
    printf("n = %d\n",$1);
    }

    typedef int Integer;
    extern int fact(Integer n); // Above typemap is applied
    - - - - -
    - - - -

    However, the matching of typedef only occurs in one direction. If you defined a typemap for Integer, it is not applied to arguments of type int.

    - - - -

    Typemaps can also be defined for groups of consecutive arguments. For example:

    - - - -
    %typemap(in) (char *str, int len) {
    $1 = StringValuePtr($input);
    $2 = (int) RSTRING($input)->len;
    };

    int count(char c, char *str, int len);
    - - - - -
    - - - -

    When a multi-argument typemap is defined, the arguments are always handled as a single Ruby object. This allows the function count to be used as follows (notice how the length parameter is omitted):

    - - - -
    puts Example.count('o','Hello World')
    2
    - - - - -
    - - - -

    36.7.2 Typemap scope

    @@ -4966,23 +1988,10 @@ to be used as follows (notice how the length parameter is omitted):

    declarations that follow. A typemap may be redefined for different sections of an input file. For example:

    - - - -
    // typemap1
    %typemap(in) int {
    ...
    }

    int fact(int); // typemap1
    int gcd(int x, int y); // typemap1

    // typemap2
    %typemap(in) int {
    ...
    }

    int isprime(int); // typemap2
    - - - - -
    - - - -

    One exception to the typemap scoping rules pertains to the %extend declaration. %extend is used to attach new declarations to a class or structure definition. Because @@ -4990,250 +1999,99 @@ of this, all of the declarations in an %extend block are subject to the typemap rules that are in effect at the point where the class itself is defined. For example:

    - - - -
    class Foo {
    ...
    };

    %typemap(in) int {
    ...
    }

    %extend Foo {
    int blah(int x); // typemap has no effect. Declaration is attached to Foo which
    // appears before the %typemap declaration.
    };
    - - - - -
    - - - -

    36.7.3 Copying a typemap

    A typemap is copied by using assignment. For example:

    - - - -
    %typemap(in) Integer = int;
    - - - - -
    - - - -

    or this:

    - - - -
    %typemap(in) Integer, Number, int32_t = int;
    - - - - -
    - - - -

    Types are often managed by a collection of different typemaps. For example:

    - - - -
    %typemap(in) int { ... }
    %typemap(out) int { ... }
    %typemap(varin) int { ... }
    %typemap(varout) int { ... }
    - - - - -
    - - - -

    To copy all of these typemaps to a new type, use %apply. For example:

    - - - -
    %apply int { Integer }; // Copy all int typemaps to Integer
    %apply int { Integer, Number }; // Copy all int typemaps to both Integer and Number
    - - - - -
    - - - -

    The patterns for %apply follow the same rules as for %typemap. For example:

    - - - -
    %apply int *output { Integer *output }; // Typemap with name
    %apply (char *buf, int len) { (char *buffer, int size) }; // Multiple arguments
    - - - - -
    - - - -

    36.7.4 Deleting a typemap

    A typemap can be deleted by simply defining no code. For example:

    - - - -
    %typemap(in) int; // Clears typemap for int
    %typemap(in) int, long, short; // Clears typemap for int, long, short
    %typemap(in) int *output;
    - - - - -
    - - - -

    The %clear directive clears all typemaps for a given type. For example:

    - - - -
    %clear int; // Removes all types for int
    %clear int *output, long *output;
    - - - - -
    - - - -

    Note: Since SWIG's default behavior is defined by typemaps, clearing a fundamental type like int will make that type unusable unless you also define a new set of typemaps immediately after the clear operation.

    - - - -

    36.7.5 Placement of typemaps

    Typemap declarations can be declared in the global scope, within a C++ namespace, and within a C++ class. For example:

    - - - -
    %typemap(in) int {
    ...
    }

    namespace std {
    class string;
    %typemap(in) string {
    ...
    }
    }

    class Bar {
    public:
    typedef const int & const_reference;
    %typemap(out) const_reference {
    ...
    }
    };
    - - - - -
    - - - -

    When a typemap appears inside a namespace or class, it stays in effect until the end of the SWIG input (just like before). However, the typemap takes the local scope into account. Therefore, this code

    - - - -
    namespace std {
    class string;
    %typemap(in) string {
    ...
    }
    }
    - - - - -
    - - - -

    is really defining a typemap for the type std::string. You could have code like this:

    - - - -
    namespace std {
    class string;
    %typemap(in) string { /* std::string */
    ...
    }
    }

    namespace Foo {
    class string;
    %typemap(in) string { /* Foo::string */
    ...
    }
    }
    - - - - -
    - - - -

    In this case, there are two completely distinct typemaps that apply to two completely different types (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. @@ -5241,20 +2099,12 @@ In this example, this is done using the class declaration class string .

    - - - -

    36.7.6 Ruby typemaps

    The following list details all of the typemap methods that can be used by the Ruby module:

    - - - -

    36.7.6.1  "in" typemap

    @@ -5262,242 +2112,61 @@ can be used by the Ruby module:

    function arguments. For example:

    - - - -
    %typemap(in) int {
    $1 = NUM2INT($input);
    }
    - - - - -
    - - - -

    The following special variables are available:

    - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    $input Input object holding value to be converted.
    $symname Name of function/method being wrapped
    $1...n Argument being sent to the function
    $1_name Name of the argument (if provided)
    $1_type The actual C datatype matched by the typemap.
    $1_ltype The assignable version of the C datatype matched by the typemap.
    - - - - -
    - - - -

    This is probably the most commonly redefined typemap because it can be used to implement customized conversions.

    - - - -

    In addition, the "in" typemap allows the number of converted arguments to be specified. For example:

    - - - -
    // Ignored argument.
    %typemap(in, numinputs=0) int *out (int temp) {
    $1 = &temp;
    }
    - - - - -
    - - - -

    At this time, only zero or one arguments may be converted.

    - - - -

    36.7.6.2 "typecheck" typemap

    @@ -5505,272 +2174,70 @@ arguments to be specified. For example:

    functions and methods. It merely checks an argument to see whether or not it matches a specific type. For example:

    - - - -
    %typemap(typecheck,precedence=SWIG_TYPECHECK_INTEGER) int {
    $1 = FIXNUM_P($input) ? 1 : 0;
    }
    - - - - -
    - - - -

    For typechecking, the $1 variable is always a simple integer that is set to 1 or 0 depending on whether or not 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."

    - - - -

    36.7.6.3  "out" typemap

    Converts return value of a C function to a Ruby object.

    - - - -

    - - - - - %typemap(out) int {
    - - - - -    $result = INT2NUM( $1 );
    - - - - - }
    - - - - -
    - - - -

    The following special variables are available.

    - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    $result Result object returned to target language.
    $symname Name of function/method being wrapped
    $1...n Argument being wrapped
    $1_name Name of the argument (if provided)
    $1_type The actual C datatype matched by the typemap.
    $1_ltype The assignable version of the C datatype matched by the typemap.
    - - - - -
    - - - - -
    - - - - -

    36.7.6.4 "arginit" typemap

    @@ -5779,65 +2246,31 @@ function argument--before any conversion has occurred. This is not normally necessary, but might be useful in highly specialized applications. For example:

    - - - -
    // Set argument to NULL before any conversion occurs
    %typemap(arginit) int *data {
    $1 = NULL;
    }
    - - - - -
    - - - -

    36.7.6.5 "default" typemap

    The "default" typemap is used to turn an argument into a default argument. For example:

    - - - -
    %typemap(default) int flags {
    $1 = DEFAULT_FLAGS;
    }
    ...
    int foo(int x, int y, int flags);
    - - - - -
    - - - -

    The primary use of this typemap is to either change the wrapping of default arguments or specify a default argument in a language where they aren't supported (like C). Target languages that do not support optional arguments, such as Java and C#, effectively ignore the value specified by this typemap as all arguments must be given.

    - - - -

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

    - - - -

    36.7.6.6 "check" typemap

    @@ -5845,23 +2278,10 @@ default argument wrapping.

    during argument conversion. The typemap is applied after arguments have been converted. For example:

    - - - -
    %typemap(check) int positive {
    if ($1 <= 0) {
    SWIG_exception(SWIG_ValueError,"Expected positive value.");
    }
    }
    - - - - -
    - - - -

    36.7.6.7 "argout" typemap

    @@ -5871,155 +2291,43 @@ need to return multiple values. The "argout" typemap is almost always combined with an "in" typemap---possibly to ignore the input value. For example:

    - - - -
    /* Set the input argument to point to a temporary variable */
    %typemap(in, numinputs=0) int *out (int temp) {
    $1 = &temp;
    }

    %typemap(argout, fragment="output_helper") int *out {
    // Append output value $1 to $result (assuming a single integer in this case)
    $result = output_helper( $result, INT2NUM(*$1) );
    }
    - - - - -
    - - - -

    The following special variables are available.

    - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    $result Result object returned to target language.
    $input The original input object passed.
    $symname Name of function/method being wrapped.
    - - - - -
    - - - -

    The code supplied to the "argout" typemap is always placed after the "out" typemap. If multiple return values are used, the extra return values are often appended to return value of the function.

    - - - -

    Output helper is a fragment that usually defines a macro to some function like SWIG_Ruby_AppendOutput.

    - - - -

    See the typemaps.i library for examples.

    - - - -

    36.7.6.8 "freearg" typemap

    @@ -6029,33 +2337,16 @@ be cleaned up when the wrapper function exits. The "freearg" typemap usually cleans up argument resources allocated by the "in" typemap. For example:

    - - - -
    // Get a list of integers
    %typemap(in) int *items {
    int nitems = Length($input);
    $1 = (int *) malloc(sizeof(int)*nitems);
    }
    // Free the list
    %typemap(freearg) int *items {
    free($1);
    }
    - - - - -
    - - - -

    The "freearg" typemap inserted at the end of the wrapper function, just before control is returned back to the target language. This code is also placed into a special variable $cleanup that may be used in other typemaps whenever a wrapper function needs to abort prematurely.

    - - - -

    36.7.6.9 "newfree" typemap

    @@ -6063,30 +2354,13 @@ abort prematurely.

    directive and is used to deallocate memory used by the return result of a function. For example:

    - - - -
    %typemap(newfree) string * {
    delete $1;
    }
    %typemap(out) string * {
    $result = PyString_FromString($1->c_str());
    }
    ...

    %newobject foo;
    ...
    string *foo();
    - - - - -
    - - - -

    See Object ownership and %newobject for further details.

    - - - -

    36.7.6.10 "memberin" typemap

    @@ -6095,31 +2369,14 @@ already converted input value into a structure member. It is typically used to handle array members and other special cases. For example:

    - - - -
    %typemap(memberin) int [4] {
    memmove($1, $input, 4*sizeof(int));
    }
    - - - - -
    - - - -

    It is rarely necessary to write "memberin" typemaps---SWIG already provides a default implementation for arrays, strings, and other objects.

    - - - -

    36.7.6.11 "varin" typemap

    @@ -6127,10 +2384,6 @@ other objects.

    language to C for the purposes of assigning to a C/C++ global variable. This is implementation specific.

    - - - -

    36.7.6.12 "varout" typemap

    @@ -6138,10 +2391,6 @@ This is implementation specific.

    object in the target language when reading a C/C++ global variable. This is implementation specific.

    - - - -

    36.7.6.13 "throws" typemap

    @@ -6154,53 +2403,23 @@ or exception in the target language. It is slightly different to the other typemaps as it is based around the exception type rather than the type of a parameter or variable. For example:

    - - - -
    %typemap(throws) const char * %{
    rb_raise(rb_eRuntimeError, $1);
    SWIG_fail;
    %}
    void bar() throw (const char *);
    - - - - -
    - - - -

    As can be seen from the generated code below, SWIG generates an exception handler with the catch block comprising the "throws" typemap content.

    - - - -
    ...
    try {
    bar();
    }
    catch(char const *_e) {
    rb_raise(rb_eRuntimeError, _e);
    SWIG_fail;
    }
    ...
    - - - - -
    - - - -

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

    - - - -

    36.7.6.14 directorin typemap

    @@ -6210,251 +2429,56 @@ of the "in" typemap, making its typemap rule often similar to the "out" typemap.

    - - - -

    - - - - - %typemap(directorin) int {
    - - - - -      $result = INT2NUM($1);
    - - - - - }
    - - - - -
    - - - -

    The following special variables are available.

    - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    $result Result object returned to target language.
    $symname Name of function/method being wrapped
    $1...n Argument being wrapped
    $1_name Name of the argument (if provided)
    $1_type The actual C datatype matched by the typemap.
    $1_ltype The assignable version of the C datatype matched by the typemap.
    this C++ this, referring to the class itself.
    - - - - -
    - - - -

    36.7.6.15 directorout typemap

    @@ -6464,59 +2488,21 @@ of the "out" typemap, making its rule often similar to the "in" typemap.

    - - - -

    - - - - %typemap(directorout) int {

    - - - -    $result = NUM2INT($1);

    - - - - }
    - - - -
    - - - -

    The following special variables are available:

    - - - -
    - - - - - - - - - - @@ -6529,207 +2515,63 @@ typemap. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    $input Ruby object being sent to the function$1...n Argument being sent to the function
    $1_name Name of the argument (if provided)
    $1_type The actual C datatype matched by the typemap.
    $1_ltype The assignable version of the C datatype matched by the typemap.
    this C++ this, referring to the class itself.
    - - - - -
    - - - -

    Currently, the directorout nor the out typemap support the option numoutputs, but the Ruby module provides that functionality through a %feature directive.  Thus, a function can be made to return "nothing" if you do:

    - - - -
    %feature("numoutputs","0") MyClass::function;
    - - - -

    This feature can be useful if a function returns a status code, which you want to discard but still use the typemap to raise an exception.
    - - - -

    - - - -

    36.7.6.16 directorargout typemap

    Output argument processing in director member functions.

    - - - -
    %typemap(directorargout, fragment="output_helper") int {
    - - - - $result = output_helper( $result, NUM2INT($1) );

    - - - - }
    - - - -

    The following special variables are available:

    - - - -
    - - - - - - - - - - @@ -6747,142 +2589,41 @@ $result = output_helper( $result, NUM2INT($1) );
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    $result Result that the director function returns Argument being sent to the function
    $1_nameName of the argument (if provided)
    $1_typeThe actual C datatype matched by the typemap
    $1_ltypeThe assignable version of the C datatype matched by the typemap
    thisC++ this, referring to the instance of the class itself
    - - - - -
    - - - -

    36.7.6.17 ret typemap

    Cleanup of function return values

    - - - -

    36.7.6.18 globalin typemap

    Setting of C global variables

    - - - -

    36.7.7 Typemap variables

    @@ -6892,83 +2633,35 @@ may appear. A full list of variables can be found in the "A C local variable corresponding to the actual type specified in the %typemap directive. For input values, this is a C local variable that is supposed to hold an argument value. For output values, this is the raw result that is supposed to be returned to Ruby.
  • - - - -

    $input

    - - - -
    A VALUE holding a raw Ruby object with an argument or variable value.
    - - - -

    $result

    - - - -
    A VALUE that holds the result to be returned to Ruby.
    - - - -

    $1_name

    - - - -
    The parameter name that was matched.
    - - - -

    $1_type

    - - - -
    The actual C datatype matched by the typemap.
    - - - -

    $1_ltype

    - - - -
    An assignable version of the datatype matched by the typemap (a type that can appear on the left-hand-side of a C assignment operation). This type is stripped of qualifiers and may @@ -6976,23 +2669,11 @@ be an altered version of $1_type. All arguments and local variables in wrapper functions are declared using this type so that their values can be properly assigned.
    - - - -

    $symname

    - - - -
    The Ruby name of the wrapper function being created.
    - - - -

    36.7.8 Useful Functions

    @@ -7008,15 +2689,6 @@ stick to the swig functions instead of the native Ruby functions.  That should help you avoid having to rewrite a lot of typemaps across multiple languages.

    - - - - - - - - -

    36.7.8.1 C Datatypes to Ruby Objects

    @@ -7034,45 +2706,31 @@ across multiple languages.

    SWIG_From_int(int x) int to Fixnum or Bignum - INT2FIX(long or int) int to Fixnum (faster than INT2NUM) - CHR2FIX(char) SWIG_From_char(char x) char to Fixnum - rb_str_new2(char*) SWIG_FromCharPtrAndSize(char*, size_t) char* to String - rb_float_new(double) SWIG_From_double(double),
    SWIG_From_float(float) float/double to Float - - - - - -
    - - - -

    36.7.8.2 Ruby Objects to C Datatypes

    @@ -7092,408 +2750,203 @@ Ruby_Format_TypeError( "$1_name", "$1_type","$symname", $argnum, $input
      
    - - - - - - - - - - - -
    int NUM2INT(Numeric) SWIG_AsVal_int(VALUE, int*)
    int FIX2INT(Numeric) SWIG_AsVal_int(VALUE, int*)
    unsigned int NUM2UINT(Numeric) SWIG_AsVal_unsigned_SS_int(VALUE, int*)
    unsigned int FIX2UINT(Numeric) SWIG_AsVal_unsigned_SS_int(VALUE, int*)
    long NUM2LONG(Numeric) SWIG_AsVal_long(VALUE, long*)
    long FIX2LONG(Numeric) SWIG_AsVal_long(VALUE, long*)
    unsigned long FIX2ULONG(Numeric) SWIG_AsVal_unsigned_SS_long(VALUE, unsigned long*)
    char NUM2CHR(Numeric or String) SWIG_AsVal_char(VALUE, int*)
    char * StringValuePtr(String) SWIG_AsCharPtrAndSize(VALUE, char*, size_t, int* alloc)
    char * rb_str2cstr(String, int*length)
    double NUM2DBL(Numeric) (double) SWIG_AsVal_int(VALUE) or similar
    - - - - -
    - - - -

    36.7.8.3 Macros for VALUE

    RSTRING_LEN(str)

    - - - -
    length of the Ruby string
    - - - -

    RSTRING_PTR(str)

    - - - -
    pointer to string storage
    - - - -

    RARRAY_LEN(arr)

    - - - -
    length of the Ruby array
    - - - -

    RARRAY(arr)->capa

    - - - -
    capacity of the Ruby array
    - - - -

    RARRAY_PTR(arr)

    - - - -
    pointer to array storage
    - - - -

    36.7.8.4 Exceptions

    void rb_raise(VALUE exception, const char *fmt, ...)

    - - - -
    Raises an exception. The given format string fmt and remaining arguments are interpreted as with printf().
    - - - -

    void rb_fatal(const char *fmt, ...)

    - - - -
    Raises a fatal exception, terminating the process. No rescue blocks are called, but ensure blocks will be called. The given format string fmt and remaining arguments are interpreted as with printf().
    - - - -

    void rb_bug(const char *fmt, ...)

    - - - -
    Terminates the process immediately -- no handlers of any sort will be called. The given format string fmt and remaining arguments are interpreted as with printf(). You should call this function only if a fatal bug has been exposed.
    - - - -

    void rb_sys_fail(const char *msg)

    - - - -
    Raises a platform-specific exception corresponding to the last known system error, with the given string msg.
    - - - -

    VALUE rb_rescue(VALUE (*body)(VALUE), VALUE args, VALUE(*rescue)(VALUE, VALUE), VALUE rargs)

    - - - -
    Executes body with the given args. If a StandardError exception is raised, then execute rescue with the given rargs.
    - - - -

    VALUE rb_ensure(VALUE(*body)(VALUE), VALUE args, VALUE(*ensure)(VALUE), VALUE eargs)

    - - - -
    Executes body with the given args. Whether or not an exception is raised, execute ensure with the given rargs after body has completed.
    - - - -

    VALUE rb_protect(VALUE (*body)(VALUE), VALUE args, int *result)

    - - - -
    Executes body with the given args and returns nonzero in result if any exception was raised.
    - - - -

    void rb_notimplement()

    - - - -
    Raises a NotImpError exception to indicate that the enclosed function is not implemented yet, or not available on this platform.
    - - - -

    void rb_exit(int status)

    - - - -
    Exits Ruby with the given status. Raises a SystemExit exception and calls registered exit functions and finalizers.
    - - - -

    void rb_warn(const char *fmt, ...)

    - - - -
    Unconditionally issues a warning message to standard error. The given format string fmt and remaining arguments are interpreted as with printf().
    - - - -

    void rb_warning(const char *fmt, ...)

    - - - -
    Conditionally issues a warning message to standard error if Ruby was invoked with the -w flag. The given format string fmt and remaining arguments are interpreted as with printf().
    - - - -

    36.7.8.5 Iterators

    void rb_iter_break()

    - - - -
    Breaks out of the enclosing iterator block.
    - - - -

    VALUE rb_each(VALUE obj)

    - - - -
    Invokes the each method of the given obj.
    - - - -

    VALUE rb_yield(VALUE arg)

    - - - -
    Transfers execution to the iterator block in the current context, passing arg as an argument. Multiple values may be passed in an array.
    - - - -

    int rb_block_given_p()

    - - - -
    Returns true if yield would execute a block in the current context; that is, if a code block was passed to the current method and is available to be called.
    - - - -

    VALUE rb_iterate(VALUE (*method)(VALUE), VALUE args, VALUE (*block)(VALUE, VALUE), VALUE arg2)

    - - - -
    Invokes method with argument args and block block. A yield from that method will invoke block with the argument given to yield, and a second argument arg2.
    - - - -

    VALUE rb_catch(const char *tag, VALUE (*proc)(VALUE, VALUE), VALUE value)

    - - - -
    Equivalent to Ruby's catch.
    - - - -

    void rb_throw(const char *tag, VALUE value)

    - - - -
    Equivalent to Ruby's throw.
    - - - -

    36.7.9 Typemap Examples

    @@ -7501,10 +2954,6 @@ VALUE), VALUE value)

    examples, you might look at the examples in the Example/ruby directory.

    - - - -

    36.7.10 Converting a Ruby array to a char **

    @@ -7513,53 +2962,23 @@ command line arguments, which are usually passed in an array of NULL terminated strings. The following SWIG interface file allows a Ruby Array instance to be used as a char ** object.

    - - - -
    %module argv

    // This tells SWIG to treat char ** as a special case
    %typemap(in) char ** {
    /* Get the length of the array */
    int size = RARRAY($input)->len;
    int i;
    $1 = (char **) malloc((size+1)*sizeof(char *));
    /* Get the first element in memory */
    VALUE *ptr = RARRAY($input)->ptr;
    for (i=0; i < size; i++, ptr++)
    /* Convert Ruby Object String to char* */
    $1[i]= StringValuePtr(*ptr);
    $1[i]=NULL; /* End of list */
    }

    // This cleans up the char ** array created before
    // the function call

    %typemap(freearg) char ** {
    free((char *) $1);
    }

    // Now a test function
    %inline %{
    int print_args(char **argv) {
    int i = 0;
    while (argv[i]) {
    printf("argv[%d] = %s\n", i,argv[i]);
    i++;
    }
    return i;
    }
    %}

    - - - - -
    - - - -

    When this module is compiled, the wrapped C function now operates as follows :

    - - - -
    require 'Argv'
    Argv.print_args(["Dave","Mike","Mary","Jane","John"])
    argv[0] = Dave
    argv[1] = Mike
    argv[2] = Mary
    argv[3] = Jane
    argv[4] = John
    - - - - -
    - - - -

    In the example, two different typemaps are used. The "in" typemap is used to receive an input argument and convert it to a C array. Since dynamic memory allocation is used to allocate memory for the array, the "freearg" typemap is used to later release this memory after the execution of the C function.

    - - - -

    36.7.11 Collecting arguments in a hash

    @@ -7572,66 +2991,27 @@ provide similar functionality for your Ruby interface. For example, suppose you'd like to wrap this C function that collects information about people's vital statistics:

    - - - -
    void setVitalStats(const char *person, int nattributes, const char **names, int *values);
    - - - - -
    - - - -

    and you'd like to be able to call it from Ruby by passing in an arbitrary number of key-value pairs as inputs, e.g.

    - - - -
    setVitalStats("Fred",
    'weight' => 270,
    'age' => 42
    )
    - - - - -
    - - - -

    To make this work, you need to write a typemap that expects a Ruby Hash as its input and somehow extracts the last three arguments (nattributes, names and values) needed by your C function. Let's start with the basics:

    - - - -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    }
    - - - - -
    - - - -

    This %typemap directive tells SWIG that we want to match any function declaration that has the specified types and names of arguments somewhere in the argument list. The fact that we @@ -7644,38 +3024,17 @@ of parentheses (keys_arr, i, key and val) define local variables that our typemap will need.

    - - - -

    Since we expect the input argument to be a Hash, let's next add a check for that:

    - - - -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    }
    - - - - -
    - - - -

    Check_Type() is just a macro (defined in the Ruby header files) that confirms that the input argument is of the correct type; if it isn't, an exception will be raised.

    - - - -

    The next task is to determine how many key-value pairs are present in the hash; we'll assign this number to the first typemap argument ($1). This is a little tricky since the @@ -7684,161 +3043,66 @@ hash, but we can get around that by calling the hash's size method directly and converting its result to a C int value:

    - - - -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    }
    - - - - -
    - - - -

    So now we know the number of attributes. Next we need to initialize the second and third typemap arguments (i.e. the two C arrays) to NULL and set the stage for extracting the keys and values from the hash:

    - - - -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    $2 = NULL;
    $3 = NULL;
    if ($1 > 0) {
    $2 = (char **) malloc($1*sizeof(char *));
    $3 = (int *) malloc($1*sizeof(int));
    }

    }
    - - - - -
    - - - -

    There are a number of ways we could extract the keys and values from the input hash, but the simplest approach is to first call the hash's keys method (which returns a Ruby array of the keys) and then start looping over the elements in that array:

    - - - -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    $2 = NULL;
    $3 = NULL;
    if ($1 > 0) {
    $2 = (char **) malloc($1*sizeof(char *));
    $3 = (int *) malloc($1*sizeof(int));
    keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
    for (i = 0; i < $1; i++) {
    }

    }
    }
    - - - - -
    - - - -

    Recall that keys_arr and i are local variables for this typemap. For each element in the keys_arr array, we want to get the key itself, as well as the value corresponding to that key in the hash:

    - - - -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    $2 = NULL;
    $3 = NULL;
    if ($1 > 0) {
    $2 = (char **) malloc($1*sizeof(char *));
    $3 = (int *) malloc($1*sizeof(int));
    keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
    for (i = 0; i < $1; i++) {
    key = rb_ary_entry(keys_arr, i);
    val = rb_hash_aref($input, key);

    }
    }
    }
    - - - - -
    - - - -

    To be safe, we should again use the Check_Type() macro to confirm that the key is a String and the value is a Fixnum:

    - - - -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    $2 = NULL;
    $3 = NULL;
    if ($1 > 0) {
    $2 = (char **) malloc($1*sizeof(char *));
    $3 = (int *) malloc($1*sizeof(int));
    keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
    for (i = 0; i < $1; i++) {
    key = rb_ary_entry(keys_arr, i);
    val = rb_hash_aref($input, key);
    Check_Type(key, T_STRING);
    Check_Type(val, T_FIXNUM);

    }
    }
    }
    - - - - -
    - - - -

    Finally, we can convert these Ruby objects into their C equivalents and store them in our local C arrays:

    - - - -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    $2 = NULL;
    $3 = NULL;
    if ($1 > 0) {
    $2 = (char **) malloc($1*sizeof(char *));
    $3 = (int *) malloc($1*sizeof(int));
    keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
    for (i = 0; i < $1; i++) {
    key = rb_ary_entry(keys_arr, i);
    val = rb_hash_aref($input, key);
    Check_Type(key, T_STRING);
    Check_Type(val, T_FIXNUM);
    $2[i] = StringValuePtr(key);
    $3[i] = NUM2INT(val);

    }
    }
    }
    - - - - -
    - - - -

    We're not done yet. Since we used malloc() to dynamically allocate the memory used for the names and values arguments, we need to provide a corresponding "freearg" typemap to free that memory so that there is no memory leak. Fortunately, this typemap is a lot easier to write:

    - - - -
    %typemap(freearg) (int nattributes, const char **names, const int *values) {
    free((void *) $2);
    free((void *) $3);
    }
    - - - - -
    - - - -

    All of the code for this example, as well as a sample Ruby program that uses the extension, can be found in the Examples/ruby/hashargs directory of the SWIG distribution.

    - - - -

    36.7.12 Pointer handling

    @@ -7847,17 +3111,9 @@ that have been stored using the SWIG typed-pointer representation. Since there are several ways in which pointers can be represented, the following two functions are used to safely perform this conversion:

    - - - -

    int SWIG_ConvertPtr(VALUE obj, void **ptr, swig_type_info *ty, int flags)

    - - - -
    Converts a Ruby object obj to a C pointer whose address is ptr (i.e. ptr is a pointer to a pointer). The third argument, ty, @@ -7871,17 +3127,9 @@ errors will cause SWIG_ConvertPtr() to return -1 but not raise an exception. If ty is NULL, no type-checking is performed.
    - - - -

    VALUE SWIG_NewPointerObj(void *ptr, swig_type_info *ty, int own)

    - - - -
    Creates a new Ruby pointer object. Here, ptr is the pointer to convert, ty is the SWIG type descriptor structure that describes the type, and own @@ -7889,10 +3137,6 @@ is a flag that indicates whether or not Ruby should take ownership of the pointer (i.e. whether Ruby should free this data when the corresponding Ruby instance is garbage-collected).
    - - - -

    Both of these functions require the use of a special SWIG type-descriptor structure. This structure contains information about the mangled name of the datatype, type-equivalence information, as well @@ -7900,95 +3144,45 @@ as information about converting pointer values under C++ inheritance. For a type of Foo *, the type descriptor structure is usually accessed as follows:

    - - - -
    Foo *foo;
    SWIG_ConvertPtr($input, (void **) &foo, SWIGTYPE_p_Foo, 1);

    VALUE obj;
    obj = SWIG_NewPointerObj(f, SWIGTYPE_p_Foo, 0);
    - - - - -
    - - - -

    In a typemap, the type descriptor should always be accessed using the special typemap variable $1_descriptor. For example:

    - - - -
    %typemap(in) Foo * {
    SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 1);
    }
    - - - - -
    - - - -

    36.7.12.1 Ruby Datatype Wrapping

    VALUE Data_Wrap_Struct(VALUE class, void (*mark)(void *), void (*free)(void *), void *ptr)

    - - - -
    Given a pointer ptr to some C data, and the two garbage collection routines for this data (mark and free), return a VALUE for the Ruby object.
    - - - -

    VALUE Data_Make_Struct(VALUE class, c-type, void (*mark)(void *), void (*free)(void *), c-type *ptr)

    - - - -
    Allocates a new instance of a C data type c-type, assigns it to the pointer ptr, then wraps that pointer with Data_Wrap_Struct() as above.
    - - - -

    Data_Get_Struct(VALUE obj, c-type, c-type *ptr)

    - - - -
    Retrieves the original C pointer of type c-type from the data object obj and assigns that pointer to ptr.
    - - - -

    36.7.13 Example: STL Vector to Ruby Array

    @@ -8000,104 +3194,40 @@ The following is an example of how to construct this type of macro/typemap and should give insight into constructing similar typemaps for other STL structures:

    - - - -
    %define PTR_VECTOR_TO_RUBY_ARRAY(vectorclassname, classname)
    %typemap(out) vectorclassname &, const vectorclassname & {
    VALUE arr = rb_ary_new2($1->size());
    vectorclassname::iterator i = $1->begin(), iend = $1->end();
    for ( ; i!=iend; i++ )
    rb_ary_push(arr, Data_Wrap_Struct(c ## classname.klass, 0, 0, *i));
    $result = arr;
    }
    %typemap(out) vectorclassname, const vectorclassname {
    VALUE arr = rb_ary_new2($1.size());
    vectorclassname::iterator i = $1.begin(), iend = $1.end();
    for ( ; i!=iend; i++ )
    rb_ary_push(arr, Data_Wrap_Struct(c ## classname.klass, 0, 0, *i));
    $result = arr;
    }
    %enddef
    - - - - -
    - - - -

    Note, that the "c ## classname.klass" is used in the preprocessor step to determine the actual object from the class name.

    - - - -

    To use the macro with a class Foo, the following is used:

    - - - -
    PTR_VECTOR_TO_RUBY_ARRAY(vector<foo *="">, Foo)
    - - - - -
    - - - -

    It is also possible to create a STL vector of Ruby objects:

    - - - -
    %define RUBY_ARRAY_TO_PTR_VECTOR(vectorclassname, classname)
    %typemap(in) vectorclassname &, const vectorclassname & {
    Check_Type($input, T_ARRAY);
    vectorclassname *vec = new vectorclassname;
    int len = RARRAY($input)->len;
    for (int i=0; i!=len; i++) {
    VALUE inst = rb_ary_entry($input, i);
    //The following _should_ work but doesn't on HPUX
    // Check_Type(inst, T_DATA);
    classname *element = NULL;
    Data_Get_Struct(inst, classname, element);
    vec->push_back(element);
    }
    $1 = vec;
    }

    %typemap(freearg) vectorclassname &, const vectorclassname & {
    delete $1;
    }
    %enddef
    - - - - -
    - - - -

    It is also possible to create a Ruby array from a vector of static data types:

    - - - -
    %define VECTOR_TO_RUBY_ARRAY(vectorclassname, classname)
    %typemap(out) vectorclassname &, const vectorclassname & {
    VALUE arr = rb_ary_new2($1->size());
    vectorclassname::iterator i = $1->begin(), iend = $1->end();
    for ( ; i!=iend; i++ )
    rb_ary_push(arr, Data_Wrap_Struct(c ## classname.klass, 0, 0, &(*i)));
    $result = arr;
    }
    %typemap(out) vectorclassname, const vectorclassname {
    VALUE arr = rb_ary_new2($1.size());
    vectorclassname::iterator i = $1.begin(), iend = $1.end();
    for ( ; i!=iend; i++ )
    rb_ary_push(arr, Data_Wrap_Struct(c ## classname.klass, 0, 0, &(*i)));
    $result = arr;
    }
    %enddef
    - - - - -
    - - - -
    - - - - Note that this is mostly an example of typemaps. If you want to use the STL with ruby, you are advised to use the standard swig STL library, which does much more than this.  Refer to the section called the C++ Standard Template Library.
    - - - -

    36.8 Docstring Features

    @@ -8108,57 +3238,29 @@ will normally not get any documentation for it, even if they run 'rdoc' on the resulting .c or .cxx file.

    - - - -

    The features described in this section make it easy for you to add rdoc strings to your modules, functions and methods that can then be read by Ruby's rdoc tool to generate html web pages, ri documentation, Windows chm file and an .xml description.

    - - - -

    rdoc can then be run from a console or shell window on a swig generated file. 

    - - - -

    For example, to generate html web pages from a C++ file, you'd do: 

    - - - -
    $ rdoc -E cxx=c -f html file_wrap.cxx
    - - - -

    To generate ri documentation from a c wrap file, you could do:

    - - - -
    $ rdoc -r file_wrap.c
    - - - -

    36.8.1 Module docstring

    @@ -8170,46 +3272,20 @@ setting an option of the %module directive. For example:

    - - - -
    %module(docstring="This is the example module's docstring") example
    - - - - -
    - - - -

    When you have more than just a line or so then you can retain the easy readability of the %module directive by using a macro. For example:

    - - - -
    %define DOCSTRING
    "The `XmlResource` class allows program resources defining menus,
    layout of controls on a panel, etc. to be loaded from an XML file."
    %enddef

    %module(docstring=DOCSTRING) xrc
    - - - - -
    - - - -

    36.8.2 %feature("autodoc")

    @@ -8220,10 +3296,6 @@ and default values. Since Ruby ships with one of the best documentation systems of any language, it makes sense to take advantage of it.

    - - - -

    SWIG's Ruby module provides support for the "autodoc" feature, which when attached to a node in the parse tree will cause an rdoc @@ -8235,10 +3307,6 @@ several options for autodoc controlled by the value given to the feature, described below.

    - - - -

    36.8.2.1 %feature("autodoc", "0")

    @@ -8249,44 +3317,18 @@ example, given this function prototype:

    - - - -
    %feature("autodoc", "0");
    bool function_name(int x, int y, Foo* foo=NULL, Bar* bar=NULL);
    - - - - -
    - - - -

    Then Ruby code like this will be generated:

    - - - -
    function_name(x, y, foo=nil, bar=nil) -> bool
    ...
    - - - - -
    - - - -

    36.8.2.2 %feature("autodoc", "1")

    @@ -8302,23 +3344,10 @@ parameter types with the "1" option will result in rdoc code like this:

    - - - -
    function_name(int x, int y, Foo foo=nil, Bar bar=nil) -> bool
    ...
    - - - - -
    - - - -

    36.8.2.3 %feature("autodoc", "2")

    @@ -8331,10 +3360,6 @@ parameter types with the "2" option will result in Ruby code like this:

    - - - -

    36.8.2.4 %feature("autodoc", "3")

    @@ -8346,23 +3371,10 @@ parameter types with the "2" option will result in Ruby code like this:

    - - - -
    function_name(int x, int y, Foo foo=nil, Bar bar=nil) -> bool

    Parameters:
    x - int
    y - int
    foo - Foo
    bar - Bar
    - - - - -
    - - - -

    36.8.2.5 %feature("autodoc", "docstring")

    @@ -8374,23 +3386,10 @@ feature then that string will be used in place of the automatically generated string. For example:

    - - - -
    %feature("autodoc", "GetPosition() -> (x, y)") GetPosition;
    void GetPosition(int* OUTPUT, int* OUTPUT);
    - - - - -
    - - - -

    36.8.3 %feature("docstring")

    @@ -8402,10 +3401,6 @@ docstring associated with classes, function or methods are output. If an item already has an autodoc string then it is combined with the docstring and they are output together.

    - - - -

    36.9 Advanced Topics

    @@ -8416,1016 +3411,180 @@ docstring and they are output together.

    or %rename commands in SWIG and the following operator names (derived from Python):

    - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    General
    __repr__ inspect
    __str__ to_s
    __cmp__ <=>
    __hash__ hash
    __nonzero__ nonzero?
    Callable
    __call__ call
    Collection
    __len__ length
    __getitem__ []
    __setitem__ []=
    Numeric
    __add__ +
    __sub__ -
    __mul__ *
    __div__ /
    __mod__ %
    __divmod__ divmod
    __pow__ **
    __lshift__ <<
    __rshift__ >>
    __and__ &
    __xor__ ^
    __or__ |
    __neg__ -@
    __pos__ +@
    __abs__ abs
    __invert__ ~
    __int__ to_i
    __float__ to_f
    __coerce__ coerce
    Additions in 1.3.13
    __lt__ <
    __le__ <=
    __eq__ ==
    __gt__ >
    __ge__ >=
    - - - - -
    - - - -

    Note that although SWIG supports the __eq__ magic method name for defining an equivalence operator, there is no separate method for handling inequality since Ruby parses the expression a != b as !(a == b).

    - - - -

    36.9.2 Creating Multi-Module Packages

    @@ -9434,112 +3593,43 @@ 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.

    - - - -

    As an example, consider one module's interface file (shape.i) that defines our base class:

    - - - -
    %module shape

    %{
    #include "Shape.h"
    %}

    class Shape {
    protected:
    double xpos;
    double ypos;
    protected:
    Shape(double x, double y);
    public:
    double getX() const;
    double getY() const;
    };
    - - - - -
    - - - -

    We also have a separate interface file (circle.i) that defines a derived class:

    - - - -
    %module circle

    %{
    #include "Shape.h"
    #include "Circle.h"
    %}

    // Import the base class definition from Shape module
    %import shape.i

    class Circle : public Shape {
    protected:
    double radius;
    public:
    Circle(double x, double y, double r);
    double getRadius() const;
    };
    - - - - -
    - - - -

    We'll start by building the Shape extension module:

    - - - -
    $ swig -c++ -ruby shape.i
     
    - - - - -
    - - - -

    SWIG generates a wrapper file named shape_wrap.cxx. To compile this into a dynamically loadable extension for Ruby, prepare an extconf.rb script using this template:

    - - - -
    require 'mkmf'

    # Since the SWIG runtime support library for Ruby
    # depends on the Ruby library, make sure it's in the list
    # of libraries.
    $libs = append_library($libs, Config::CONFIG['RUBY_INSTALL_NAME'])

    # Create the makefile
    create_makefile('shape')
    - - - - -
    - - - -

    Run this script to create a Makefile and then type make to build the shared library:

    - - - -
    $ ruby extconf.rb
    creating Makefile
    $ make
    g++ -fPIC -g -O2 -I. -I/usr/local/lib/ruby/1.7/i686-linux \
    -I. -c shape_wrap.cxx
    gcc -shared -L/usr/local/lib -o shape.so shape_wrap.o -L. \
    -lruby -lruby -lc
    - - - - -
    - - - -

    Note that depending on your installation, the outputs may be slightly different; these outputs are those for a Linux-based development environment. The end result should be a shared library @@ -9547,66 +3637,25 @@ development environment. The end result should be a shared library code. Now repeat this process in a separate directory for the Circle module:

    - - - -
      - - - - -
    1. Run SWIG to generate the wrapper code (circle_wrap.cxx);
    2. - - - - -
    3. Write an extconf.rb script that your end-users can use to create a platform-specific Makefile for the extension;
    4. - - - - -
    5. Build the shared library for this extension by typing make.
    6. - - - - -
    - - - -

    Once you've built both of these extension modules, you can test them interactively in IRB to confirm that the Shape and Circle modules are properly loaded and initialized:

    - - - -
    $ irb
    irb(main):001:0> require 'shape'
    true
    irb(main):002:0> require 'circle'
    true
    irb(main):003:0> c = Circle::Circle.new(5, 5, 20)
    #<Circle::Circle:0xa097208>
    irb(main):004:0> c.kind_of? Shape::Shape
    true
    irb(main):005:0> c.getX()
    5.0
    - - - - -
    - - - -

    36.9.3 Specifying Mixin Modules

    @@ -9615,96 +3664,40 @@ it does allow you to mix one or more modules into a class using Ruby's inclu method. For example, if you have a Ruby class that defines an each instance method, e.g.

    - - - -
    class Set
    def initialize
    @members = []
    end

    def each
    @members.each { |m| yield m }
    end
    end
    - - - - -
    - - - -

    then you can mix-in Ruby's Enumerable module to easily add a lot of functionality to your class:

    - - - -
    class Set
    include Enumerable
    def initialize
    @members = []
    end
    def each
    @members.each { |m| yield m }
    end
    end
    - - - - -
    - - - -

    To get the same benefit for your SWIG-wrapped classes, you can use the %mixin directive to specify the names of one or more modules that should be mixed-in to a class. For the above example, the SWIG interface specification might look like this:

    - - - -
    %mixin Set "Enumerable";

    class Set {
    public:
    // Constructor
    Set();

    // Iterates through set members
    void each();
    };
    - - - - -
    - - - -

    Multiple modules can be mixed into a class by providing a comma-separated list of module names to the %mixin directive, e.g.

    - - - -
    %mixin Set "Fee,Fi,Fo,Fum";
    - - - - -
    - - - -

    Note that the %mixin directive is implemented using SWIG's "features" mechanism and so the same name matching rules used for other kinds of features apply (see the chapter on "Customization Features") for more details).

    - - - -

    36.10 Memory Management

    @@ -9713,45 +3706,21 @@ Ruby is proper memory management. The key to proper memory management is clearly defining whether a wrapper Ruby object owns the underlying C struct or C++ class. There are two possibilities:

    - - - -
      - - - -
    • The Ruby object is responsible for freeing the C struct or C++ object
    • - - - -
    • The Ruby object should not free the C struct or C++ object because it will be freed by the underlying C or C++ code
    • - - - -
    - - - -

    To complicate matters, object ownership may transfer from Ruby to C++ (or vice versa) depending on what function or methods are invoked. Clearly, developing a SWIG wrapper requires a thorough understanding of how the underlying library manages memory.

    - - - -

    36.10.1 Mark and Sweep Garbage Collector

    @@ -9769,37 +3738,21 @@ In the sweep phase, all objects that have not been marked will be garbage collected. For more information about the Ruby garbage collector please refer to http://rubygarden.org/ruby/ruby?GCAndExtensions.

    - - - -

    The Ruby C/API provides extension developers two hooks into the garbage collector - a "mark" function and a "sweep" function. By default these functions are set to NULL.

    - - - -

    If a C struct or C++ class references any other Ruby objects, then it must provide a "mark" function. The "mark" function should identify any referenced Ruby objects by calling the rb_gc_mark function for each one. Unsurprisingly, this function will be called by the Ruby garbage during the "mark" phase.

    - - - -

    During the sweep phase, Ruby destroys any unused objects. If any memory has been allocated in creating the underlying C struct or C++ struct, then a "free" function must be defined that deallocates this memory.

    - - - -

    36.10.2 Object Ownership

    @@ -9810,171 +3763,70 @@ then a "free" function must be registered for the object. If the Ruby object is not responsible for freeing the underlying memory, then a "free" function must not be registered for the object.

    - - - -

    For the most part, SWIG takes care of memory management issues. The rules it uses are:

    - - - -
      - - - -
    • When calling a C++ object's constructor from Ruby, SWIG will assign a "free" function thereby making the Ruby object responsible for freeing the C++ object
    • - - - -
    • When calling a C++ member function that returns a pointer, SWIG will not assign a "free" function thereby making the underlying library responsible for freeing the object.
    • - - - -
    - - - -

    To make this clearer, let's look at an example. Assume we have a Foo and a Bar class.

    - - - -
    /* File "RubyOwernshipExample.h" */

    class Foo
    {
    public:
    Foo() {}
    ~Foo() {}
    };

    class Bar
    {
    Foo *foo_;
    public:
    Bar(): foo_(new Foo) {}
    ~Bar() { delete foo_; }
    Foo* get_foo() { return foo_; }
    Foo* get_new_foo() { return new Foo; }
    void set_foo(Foo *foo) { delete foo_; foo_ = foo; }
    };

    - - - - -
    - - - -

    First, consider this Ruby code:

    - - - -
    foo = Foo.new
    - - - - -
    - - - -

    In this case, the Ruby code calls the underlying Foo C++ constructor, thus creating a new foo object. By default, SWIG will assign the new Ruby object a "free" function. When the Ruby object is garbage collected, the "free" function will be called. It in turn will call Foo's destructor.

    - - - -

    Next, consider this code:

    - - - -
    bar = Bar.new
    foo = bar.get_foo()
    - - - - -
    - - - -

    In this case, the Ruby code calls a C++ member function, get_foo. By default, SWIG will not assign the Ruby object a "free" function. Thus, when the Ruby object is garbage collected the underlying C++ foo object is not affected.

    - - - -

    Unfortunately, the real world is not as simple as the examples above. For example:

    - - - -
    bar = Bar.new
    foo = bar.get_new_foo()
    - - - - -
    - - - -

    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 Object ownership and %newobject for more information.

    - - - -

    The SWIG default mappings are also incorrect in this case:

    - - - -
    foo = Foo.new
    bar = Bar.new
    bar.set_foo(foo)
    - - - - -
    - - - -

    Without modification, this code will cause a segmentation fault. When the Ruby foo object goes out of scope, it will free the underlying C++ foo @@ -9985,17 +3837,9 @@ Ruby object to the C++ object when the set_foo method is called. This can be done by using the special DISOWN type map, which was added to the Ruby bindings in SWIG-1.3.26.

    - - - -

    Thus, a correct SWIG interface file correct mapping for these classes is:

    - - - -
    /* File RubyOwnershipExample.i */
     
    @@ -10027,37 +3871,11 @@ public:
      void set_foo(Foo *foo);
      %clear Foo *foo;
     };
    -
     
    - - - - -
    - - - - -
    - - - - -

    This code can be seen in swig/examples/ruby/tracking.

    - - - - -
    - - - - -

    36.10.3 Object Tracking

    @@ -10065,35 +3883,14 @@ public: shown below to illustrate different memory management techniques. The class library models a zoo and the animals it contains.

    - - - -
    %module zoo

    %{
    #include <string>
    #include <vector>

    #include "zoo.h"
    %}

    class Animal
    {
    private:
    typedef std::vector<Animal*> AnimalsType;
    typedef AnimalsType::iterator IterType;
    protected:
    AnimalsType animals;
    protected:
    std::string name_;
    public:
    // Construct an animal with this name
    Animal(const char* name) : name_(name) {}

    // Return the animal's name
    const char* get_name() const { return name.c_str(); }
    };

    class Zoo
    {
    protected:
    std::vector<animal *=""> animals;

    public:
    // Construct an empty zoo
    Zoo() {}

    /* Create a new animal. */
    static Animal* Zoo::create_animal(const char* name)
    {
    return new Animal(name);
    }

    // Add a new animal to the zoo
    void add_animal(Animal* animal) {
    animals.push_back(animal);
    }

    Animal* remove_animal(size_t i) {
    Animal* result = this->animals[i];
    IterType iter = this->animals.begin();
    std::advance(iter, i);
    this->animals.erase(iter);

    return result;
    }

    // Return the number of animals in the zoo
    size_t get_num_animals() const {
    return animals.size();
    }

    // Return a pointer to the ith animal
    Animal* get_animal(size_t i) const {
    return animals[i];
    }
    };

    - - - - -
    - - - -

    Let's say you SWIG this code and then run IRB:
    - - - -

    - - - -
    $ irb
     irb(main):001:0> require 'example'
    @@ -10122,33 +3919,15 @@ irb(main):008:0> tiger2.get_name()
     
     irb(main):009:0> tiger1.equal?(tiger2)
     => false
    -
     
    - - - - -
    - - - -

    Pay particular attention to the code tiger1.equal?(tiger2). Note that the two Ruby objects are not the same - but they reference the same underlying C++ object. This can cause problems. For example:
    - - - -

    - - - -
    irb(main):010:0> tiger1 = nil
     => nil
    @@ -10158,19 +3937,9 @@ irb(main):011:0> GC.start
     
     irb(main):012:0> tiger2.get_name()
     (irb):12: [BUG] Segmentation fault
    -
     
    - - - - -
    - - - -

    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 @@ -10178,116 +3947,45 @@ is garbage collected, it frees the underlying C++ object. Thus, when tiger2< calls the get_name() method it invokes it on a destroyed object.

    - - - -

    This problem can be avoided if SWIG enforces a one-to-one mapping between Ruby objects and C++ classes. This can be done via the use of the %trackobjects functionality available in SWIG-1.3.26. and later.

    - - - -

    When the %trackobjects is turned on, SWIG automatically keeps track of mappings between C++ objects and Ruby objects. Note that enabling object tracking causes a slight performance degradation. Test results show this degradation to be about 3% to 5% when creating and destroying 100,000 animals in a row.

    - - - -

    Since %trackobjects is implemented as a %feature, it uses the same name matching rules as other kinds of features (see the chapter on "Customization Features") . Thus it can be applied on a class-by-class basis if needed. To fix the example above:

    - - - - -
    - - - - -
    %module example

    %{
    #include "example.h"
    %}

    /* Tell SWIG that create_animal creates a new object */
    %newobject Zoo::create_animal;

    /* Tell SWIG to keep track of mappings between C/C++ structs/classes. */
    %trackobjects;

    %include "example.h"
    - - - - -
    - - - -

    When this code runs we see:
    - - - - -
    - - - - -

    - - - -
    $ irb
    irb(main):001:0> require 'example'
    => true

    irb(main):002:0> tiger1 = Example::Animal.new("tiger1")
    => #<Example::Animal:0x2be37d8>

    irb(main):003:0> zoo = Example::Zoo.new()
    => #<Example::Zoo:0x2be0a18>

    irb(main):004:0> zoo.add_animal(tiger1)
    => nil

    irb(main):006:0> tiger2 = zoo.remove_animal(0)
    => #<Example::Animal:0x2be37d8>

    irb(main):007:0> tiger1.equal?(tiger2)
    => true

    irb(main):008:0> tiger1 = nil
    => nil

    irb(main):009:0> GC.start
    => nil

    irb(main):010:0> tiger.get_name()
    => "tiger1"
    irb(main):011:0>

    - - - - -
    - - - -

    For those who are interested, object tracking is implemented by storing Ruby objects in a hash table and keying them on C++ pointers. The underlying API is:
    - - - -

    - - - -
    static void SWIG_RubyAddTracking(void* ptr, VALUE object);
    static VALUE SWIG_RubyInstanceFor(void* ptr) ;
    static void SWIG_RubyRemoveTracking(void* ptr);
    static void SWIG_RubyUnlinkObjects(void* ptr);
    - - - - -
    - - - -

    When an object is created, SWIG will automatically call the SWIG_RubyAddTracking method. Similarly, when an object is deleted, SWIG will call the SWIG_RubyRemoveTracking. When an object is returned to Ruby from C++, SWIG will use the SWIG_RubyInstanceFor @@ -10295,58 +3993,29 @@ method to ensure a one-to-one mapping from Ruby to C++ objects. Last, the RubyUnlinkObjects method unlinks a Ruby object from its underlying C++ object.

    - - - -

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

    - - - -

    36.10.4 Mark Functions

    With a bit more testing, we see that our class library still has problems. For example:
    - - - -

    - - - -
    $ irb
    irb(main):001:0> require 'example'
    => true

    irb(main):002:0> tiger1 = Example::Animal.new("tiger1")
    => #<Example::Animal:0x2bea6a8>

    irb(main):003:0> zoo = Example::Zoo.new()
    => #<Example::Zoo:0x2be7960>

    irb(main):004:0> zoo.add_animal(tiger1)
    => nil

    irb(main):007:0> tiger1 = nil
    => nil

    irb(main):007:0> GC.start
    => nil

    irb(main):005:0> tiger2 = zoo.get_animal(0)
    (irb):12: [BUG] Segmentation fault
    - - - - -
    - - - -

    The problem is that Ruby does not know that the zoo object contains a reference to a Ruby object. Thus, when Ruby garbage collects tiger1 it frees the underlying C++ object.

    - - - -

    This can be fixed by implementing a mark function as described above in the Mark and Sweep Garbage Collector section. You can specify a mark @@ -10356,10 +4025,6 @@ SWIG's' "features" mechanism it uses the same name matching rules as other kinds of features (see the chapter on "Customization Features" for more details).

    - - - -

    A mark function takes a single argument, which is a pointer to the C++ object being marked; it should, in turn, call rb_gc_mark() for any instances that are @@ -10369,64 +4034,24 @@ objects in the zoo object, look up their Ruby object equivalent, and then call rb_gc_mark(). One possible implementation is:

    - - - -
    %module example

    %{
    #include "example.h"
    %}

    /* Keep track of mappings between C/C++ structs/classes
    and Ruby objects so we can implement a mark function. */
    %trackobjects;

    /* Specify the mark function */
    %markfunc Zoo "mark_Zoo";

    %include "example.h"

    %header %{

    static void mark_Zoo(void* ptr) {
    Zoo* zoo = (Zoo*) ptr;

    /* Loop over each object and tell the garbage collector
    that we are holding a reference to them. */
    int count = zoo->get_num_animals();

    for(int i = 0; i < count; ++i) {
    Animal* animal = zoo->get_animal(i);
    VALUE object = SWIG_RubyInstanceFor(animal);

    if (object != Qnil) {
    rb_gc_mark(object);
    }
    }
    }
    %}

    - - - - -
    - - - -

    Note the mark function is dependent on the SWIG_RUBY_InstanceFor method, and thus requires that %trackobjects is enabled. For more information, please refer to the track_object.i test case in the SWIG test suite.

    - - - -

    When this code is compiled we now see:

    - - - -
    $ irb
    irb(main):002:0> tiger1=Example::Animal.new("tiger1")
    => #<Example::Animal:0x2be3bf8>

    irb(main):003:0> Example::Zoo.new()
    => #<Example::Zoo:0x2be1780>

    irb(main):004:0> zoo = Example::Zoo.new()
    => #<Example::Zoo:0x2bde9c0>

    irb(main):005:0> zoo.add_animal(tiger1)
    => nil

    irb(main):009:0> tiger1 = nil
    => nil

    irb(main):010:0> GC.start
    => nil
    irb(main):014:0> tiger2 = zoo.get_animal(0)
    => #<Example::Animal:0x2be3bf8>

    irb(main):015:0> tiger2.get_name()
    => "tiger1"
    irb(main):016:0>

    - - - - -
    - - - - -
    - - - - -

    This code can be seen in swig/examples/ruby/mark_function.

    - - - -

    36.10.5 Free Functions

    @@ -10434,10 +4059,6 @@ test suite.

    a Ruby object is garbage collected. The free function simply calls the C++ object's destructor.

    - - - -

    However, sometimes an appropriate destructor does not exist or special processing needs to be performed before the destructor is called. Therefore, SWIG allows you to manually specify a "free" @@ -10447,10 +4068,6 @@ SWIG's' "features" mechanism and so the same name matching rules used for other kinds of features apply (see the chapter on "Customization Features") for more details).

    - - - -

    IMPORTANT ! - If you define your own free function, then you must ensure that you call the underlying C++ object's destructor. In addition, if object tracking is activated for the object's class, you @@ -10459,10 +4076,6 @@ function (of course call this before you destroy the C++ object). Note that it is harmless to call this method if object tracking if off so it is advised to always call it.

    - - - -

    Note there is a subtle interaction between object ownership and free functions. A custom defined free function will only be called if the Ruby object owns the underlying C++ object. This also to Ruby @@ -10470,10 +4083,6 @@ objects which are created, but then transfer ownership to C++ objects via the use of the disown typemap described above.

    - - - -

    To show how to use the %freefunc directive, let's slightly change our example. Assume that the zoo object is responsible for freeing animal that it contains. This means @@ -10481,10 +4090,6 @@ that the Zoo::add_animal function should be marked with a DISOWN typemap and the destructor should be updated as below:

    - - - -
    Zoo::~Zoo() {
      IterType iter = this->animals.begin();
    @@ -10495,23 +4100,10 @@ and the destructor should be updated as below:

    delete animal; } }
    - - - - -
    - - - -

    When we use these objects in IRB we see:

    - - - -
    $irb
     irb(main):002:0> require 'example'
    @@ -10534,19 +4126,9 @@ irb(main):008:0> GC.start
     
     irb(main):009:0> tiger1.get_name()
     (irb):12: [BUG] Segmentation fault
    -
     
    - - - - -
    - - - -

    The error happens because the C++ animal object is freed when the zoo object is freed. Although this error is unavoidable, we can at least prevent the @@ -10557,16 +4139,8 @@ function notifies SWIG that a Ruby object's underlying C++ object is no longer valid. Once notified, SWIG will intercept any calls from the existing Ruby object to the destroyed C++ object and raise an exception.
    - - - -

    - - - -
    %module example
     
    @@ -10606,28 +4180,14 @@ existing Ruby object to the destroyed C++ object and raise an exception.
    /* Now call SWIG_RubyRemoveTracking for the zoo */ SWIG_RubyRemoveTracking(ptr); - /* Now free the zoo which will free the animals it contains */ delete zoo; } %}
    - - - - -
    - - - -

    Now when we use these objects in IRB we see:

    - - - -
    $irb
     irb(main):002:0> require 'example'
    @@ -10653,30 +4213,13 @@ RuntimeError: This Animal * already released
      from (irb):10:in `get_name'
      from (irb):10
     irb(main):011:0>
    - - - - -
    - - - -

    Notice that SWIG can now detect the underlying C++ object has been freed, and thus raises a runtime exception.

    - - - -

    This code can be seen in swig/examples/ruby/free_function.

    - - - -

    36.10.6 Embedded Ruby and the C++ Stack

    @@ -10687,25 +4230,13 @@ also try to mark any Ruby objects (VALUE) it finds in the machine registers and in the C++ stack.

    - - - -

    The stack is basically the history of the functions that have been called and also contains local variables, such as the ones you define whenever you do inside a function:

    - - - -
    VALUE obj;
    - - - -

    For ruby to determine where its stack space begins, during initialization a normal Ruby interpreter will call the ruby_init() function which in turn will call a function called Init_stack or @@ -10713,10 +4244,6 @@ similar.  This function will store a pointer to the location where the stack points at that point in time.

    - - - -

    ruby_init() is presumed to always be called within the main() function of your program and whenever the GC is called, ruby will assume that the memory between the current location in memory and the @@ -10724,19 +4251,11 @@ pointer that was stored previously represents the stack, which may contain local (and temporary) VALUE ruby objects.   Ruby will then be careful not to remove any of those objects in that location.

    - - - -

    So far so good.  For a normal Ruby session, all the above is completely transparent and magic to the extensions developer.   

    - - - -

    However, with an embedded Ruby, it may not always be possible to modify main() to make sure ruby_init() is called there.   As @@ -10750,17 +4269,9 @@ is called.  The end result: random crashes and segmentation faults.

    - - - -

    This problem will often be seen in director functions that are used for callbacks, for example.  

    - - - -

    To solve the problem, SWIG can now generate code with director functions containing the optional macros SWIG_INIT_STACK and SWIG_RELEASE_STACK.   These macros will try to force Ruby to @@ -10769,43 +4280,22 @@ director function is called.  This will lead Ruby to measure and not collect any VALUE objects defined from that point on.  

    - - - -

    To mark functions to either reset the ruby stack or not, you can use:

    - - - -
    %initstack   Class::memberfunction;  // only re-init the stack in this director method
    - - - - %ignorestack Class::memberfunction;  // do not re-init the stack in this director method
    - - - - %initstack   Class;               // init the stack on all the methods of this class
    - - - - %initstack;   // all director functions will re-init the stack
    - From a7515a725e22e7375d10c90727fba860fb56757b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 7 Jun 2013 23:18:50 +0100 Subject: [PATCH 0660/1160] Remove use of monospace in Ruby docs and unncessary usage of
    --- Doc/Manual/Ruby.html | 737 +++++++++++++++++++++---------------------- 1 file changed, 359 insertions(+), 378 deletions(-) diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index d1dcbfab0..1798d1df7 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -166,7 +166,7 @@ of Ruby.

    option:

    -
    $ swig -ruby example.i
    +
    $ swig -ruby example.i
     
    @@ -174,7 +174,7 @@ option:

    option:

    -
    $ swig -c++ -ruby example.i
    +
    $ swig -c++ -ruby example.i
     
    @@ -200,7 +200,7 @@ location is typical. If you are not entirely sure where Ruby is installed, you can run Ruby to find out. For example:

    -
    $ ruby -e 'puts $:.join("\n")'
    +
    $ ruby -e 'puts $:.join("\n")'
     /usr/local/lib/ruby/site_ruby/1.6 /usr/local/lib/ruby/site_ruby/1.6/i686-linux
     /usr/local/lib/ruby/site_ruby /usr/local/lib/ruby/1.6 /usr/local/lib/ruby/1.6/i686-linux .
     
    @@ -226,7 +226,10 @@ looks like the following:

  • Type the following to build the extension:

    -
    $ ruby extconf.rb
    $ make
    $ make install +
    +$ ruby extconf.rb
    +$ make
    +$ make install
         
  • @@ -254,10 +257,10 @@ called example.c, a typical sequence of commands for the Linux operating system would look something like this:

    -
    $ swig -ruby example.i
    -$ gcc -c example.c
    -$ gcc -c example_wrap.c -I/usr/local/lib/ruby/1.6/i686-linux 
    -$ gcc -shared example.o example_wrap.o -o example.so
    +
    $ swig -ruby example.i
    +$ gcc -c example.c
    +$ gcc -c example_wrap.c -I/usr/local/lib/ruby/1.6/i686-linux
    +$ gcc -shared example.o example_wrap.o -o example.so
     
    @@ -291,7 +294,7 @@ name for your extension. So for example, a SWIG interface file that begins with:

    -
    %module example
    +
    %module example

    will result in an extension module using the feature name @@ -319,7 +322,11 @@ finally rebuilding Ruby.

    using the C++ compiler. For example:

    -
    $ swig -c++ -ruby example.i
    $ g++ -c example.cxx
    $ g++ -c example_wrap.cxx -I/usr/local/lib/ruby/1.6/i686-linux
    $ g++ -shared example.o example_wrap.o -o example.so +
    +$ swig -c++ -ruby example.i
    +$ g++ -c example.cxx
    +$ g++ -c example_wrap.cxx -I/usr/local/lib/ruby/1.6/i686-linux
    +$ g++ -shared example.o example_wrap.o -o example.so
     
    @@ -349,7 +356,10 @@ script) will work with Windows as well; you should be able to build your code into a DLL by typing:

    -
    C:\swigtest> ruby extconf.rb
    C:\swigtest> nmake
    C:\swigtest> nmake install +
    +C:\swigtest> ruby extconf.rb
    +C:\swigtest> nmake
    +C:\swigtest> nmake install
     
    @@ -414,7 +424,10 @@ example if you have this ruby file run.rb:

    directory, then run the Ruby script from the DOS/Command prompt:

    -
    C:\swigtest> ruby run.rb
    Foo = 3.0
    +
    +C:\swigtest> ruby run.rb
    +Foo = 3.0
    +

    36.3 The Ruby-to-C/C++ Mapping

    @@ -443,33 +456,34 @@ quotes, e.g.

    An alternate method of specifying a nested module name is to -use the -prefix +use the -prefix option on the SWIG command line. The prefix that you specify with this -option will be prepended to the module name specified with the %module +option will be prepended to the module name specified with the %module directive in your SWIG interface file. So for example, this declaration -at the top of your SWIG interface file:
    - +at the top of your SWIG interface file:

    %module "foo::bar::spam"
    -

    will result in a nested module name of Foo::Bar::Spam, +

    will result in a nested module name of Foo::Bar::Spam, but you can achieve the same -effect by specifying:
    +effect by specifying:

    %module spam
    -

    and then running SWIG with the -prefix command -line option:
    +

    and then running SWIG with the -prefix command +line option:

    -
    $ swig -ruby -prefix "foo::bar::" example.i
    +
    +$ swig -ruby -prefix "foo::bar::" example.i
    +

    Starting with SWIG 1.3.20, you can also choose to wrap @@ -477,7 +491,9 @@ everything into the global module by specifying the -globalmodule option on the SWIG command line, i.e.

    -
    $ swig -ruby -globalmodule example.i
    +
    +$ swig -ruby -globalmodule example.i
    +

    Note that this does not relieve you of the requirement of @@ -721,7 +737,7 @@ utility methods work normally:

    Furthermore, if you have a function like this:

    -
    void spam(Parent *f);
    +
    void spam(Parent *f);

    then the function spam() accepts Parent* @@ -758,7 +774,9 @@ an optional feature that you can activate with the -minherit command-line option:

    -
    $ swig -c++ -ruby -minherit example.i
    +
    +$ swig -c++ -ruby -minherit example.i
    +

    Using our previous example, if your SWIG interface file @@ -1004,45 +1022,37 @@ do that, you need to define a container that contains a swig::GC_VALUE, like:

    -
    %module -nativevector
    -
    +
    +%module nativevector
     
    -%{
    -std::vector< swig::GC_VALUE > NativeVector;
    -%}
    -
    +%{ +std::vector< swig::GC_VALUE > NativeVector; +%} -%template(NativeVector) std::vector< swig::GC_VALUE >;
    +%template(NativeVector) std::vector< swig::GC_VALUE >; +
    -
    -

    This vector can then contain any Ruby object, making them almost identical to Ruby's own Array class.

    -
    require 'nativevector'
    +
    +
    require 'nativevector'
    +include NativeVector
     
    -include NativeVector
    +v = NativeVector.new +v << 1 +v << [1,2] +v << 'hello' -
    +class A; end -v = NativeVector.new
    -v << 1
    -v << -[1,2]
    -v << -'hello'
    -
    -class A; end
    -
    -v << -A.new
    -
    -puts v
    -=> -[1, [1,2], 'hello', #<A:0x245325>]
    -
    +v << A.new + +puts v +=> [1, [1,2], 'hello', #<A:0x245325>] +
    +

    Obviously, there is a lot more to template wrapping than shown in these examples. More details can be found in the SWIG and C++ @@ -1053,7 +1063,7 @@ chapter.

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

    @@ -1062,58 +1072,51 @@ liking.

    that support functors using Ruby procs or methods, instead.  Currently, -this includes std::set, -set::map, -std::multiset -and std::multimap.

    +this includes std::set, +set::map, +std::multiset +and std::multimap.

    -

    The functors in swig are called swig::UnaryFunction -and swig::BinaryFunction.
    +

    The functors in swig are called swig::UnaryFunction +and swig::BinaryFunction. -For C++ predicates (ie. functors that must return bool as a result) swig::UnaryPredicate -and swig::BinaryPredicate +For C++ predicates (ie. functors that must return bool as a result) swig::UnaryPredicate +and swig::BinaryPredicate are provided.

    As an example, if given this swig file:

    -
    %module -intset;
    -
    -%include <std_set.i>
    -
    +
    +%module intset;
     
    -%typemap(IntSet)  std::set< int, swig::BinaryPredicate
    ->;
    +%include <std_set.i> + +%typemap(IntSet)  std::set< int, swig::BinaryPredicate >; +

    You can then use the set from Ruby with or without a proc object as a predicate:

    -
    require -'intset'
    +
    +require 'intset'
    +include Intset
     
    -include Intset
    -
    -# Default sorting behavior defined in C++
    -a = IntSet.new
    - -a << 1
    -a << 2
    -a << 3
    -a
    - -=> - [1,2,3]
    -
    +# Default sorting behavior defined in C++ +a = IntSet.new +a << 1 +a << 2 +a << 3 +a +=> [1,2,3] # Custom sorting behavior defined by a Ruby proc -
    b = IntSet.new( proc { -|a,b| a > b } )
    -b << 1
    -b << 2
    -b << 3
    -b
    -=> - [3,2,1]
    +b = IntSet.new( proc { |a,b| a > b } ) +b << 1 +b << 2 +b << 3 +b +=>  [3,2,1] +

    36.3.15 C++ STL Iterators

    @@ -1127,8 +1130,8 @@ values they point at, while the non-const iterators can both read and modify the values.

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

    @@ -1136,86 +1139,68 @@ ending points of the iteration range. 

    The SWIG STL library already provides typemaps to all the standard containers to do this wrapping automatically for you, but if you have your own STL-like iterator, you will need to write your own -typemap for them.  For out typemaps, the special functions make_const_iterator and make_nonconst_iterator are provided.

    +typemap for them.  For out typemaps, the special functions make_const_iterator and make_nonconst_iterator are provided.

    These can be used either like:

    -
    make_const_iterator( iterator, rubyclass );
    +
    +make_const_iterator( iterator, rubyclass );
    +make_const_iterator( iterator, iterator_begin, iterator_end, rubyclass );
    +
    -make_const_iterator( iterator, iterator_begin, iterator_end, rubyclass );
    - -

    The iterators support a next() and previous() member function to -just change the iterator without returning anything.  previous() +

    The iterators support a next() and previous() member function to +just change the iterator without returning anything.  previous() should obviously only be used for bidirectional iterators.  You can also advance the iterator multiple steps by using standard math -operations like +=.

    +operations like +=.

    The -value the iterator points at can be accessed with value() -- this is equivalent to dereferencing it with *i. -  For non-const iterators, a value=() function +value the iterator points at can be accessed with value() -- this is equivalent to dereferencing it with *i. +  For non-const iterators, a value=() function is also provided which allows you to change the value pointed by the -iterator.  This is equivalent to the C++ construct of dereferencing and assignment, like *i = something

    +iterator.  This is equivalent to the C++ construct of dereferencing and assignment, like *i = something

    Thus, given say a vector class of doubles defined as:

    -
    %module doublevector
    +
    +
    +%module doublevector
     
    -
    +%include std_vector.i -%include std_vector.i

    - -
    - -%template(DoubleVector) std::vector<double>;
    +%template(DoubleVector) std::vector<double>; +
    +

    Its iterator can then be used from Ruby like:

    -
    require -'doublevector'
    +
    +
    +require 'doublevector'
    +include Doublevector
     
    -include Doublevector
    +v = DoubleVector.new +v << 1 +v << 2 +v << 3 -
    +# +# an elaborate and less efficient way of doing v.map! { |x| x+2 } +# +i = v.begin +e = v.end +while i != e +  val = i.value +  val += 2 +  i.value = val +  i.next +end +i +>> [3, 4, 5 ] +
    +
    -v = DoubleVector.new
    - -v << 1
    - -v << 2
    - -v << 3
    - -
    - -#
    - -# an elaborate and less efficient way of doing v.map! { |x| x+2 }
    - -#
    - -i = v.begin
    - -e = v.end
    - -while i != e
    - -  val = i.value
    - -  val += 2
    - -  i.value = val
    - -  i.next
    - -end
    - -i
    - ->> [3, 4, 5 ]
    - -
    - -

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

    +

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

    36.3.16 C++ Smart Pointers

    @@ -1321,7 +1306,7 @@ constant, class and method names to conform with the standard Ruby naming conventions. For example:

    -
    $ swig -ruby -autorename example.i
    +
    $ swig -ruby -autorename example.i
     
    @@ -1637,37 +1622,38 @@ construction:

    Then, in ruby, it can be used like:

    -
    Window.new(0,0,360,480) -{ |w|
    - -    w.color = Fltk::RED
    - -    w.border = false
    - -}
    +
    +Window.new(0,0,360,480) { |w|
    +    w.color = Fltk::RED
    +    w.border = false
    +}
    +
    +

    For other methods, you can usually use a dummy parameter with a special in typemap, like:

    -
    //
    +
    +//
    +// original function was:
    +//
    +// void func(int x);
     
    -// original function was:
    -//
    -// void func(int x);
    -
    -%typemap(in,numinputs=0) int RUBY_YIELD_SELF {
    -     if ( !rb_block_given_p() )
    +%typemap(in,numinputs=0) int RUBY_YIELD_SELF { +     if ( !rb_block_given_p() )             -rb_raise("No block given");
    -     return rb_yield(self);
    -}
    -
    -%extend {
    +rb_raise("No block given"); +     return rb_yield(self); +} + +%extend {         void func(int x, int -RUBY_YIELD_SELF );
    -}
    +RUBY_YIELD_SELF ); +} +
    +

    For more information on typemaps, see Typemaps.

    @@ -1685,118 +1671,118 @@ from SWIG error codes to Ruby exceptions:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + @@ -2951,14 +3554,54 @@ terminated strings. The following SWIG interface file allows a Ruby Array instance to be used as a char ** object.

    -
    %module argv

    // This tells SWIG to treat char ** as a special case
    %typemap(in) char ** {
    /* Get the length of the array */
    int size = RARRAY($input)->len;
    int i;
    $1 = (char **) malloc((size+1)*sizeof(char *));
    /* Get the first element in memory */
    VALUE *ptr = RARRAY($input)->ptr;
    for (i=0; i < size; i++, ptr++)
    /* Convert Ruby Object String to char* */
    $1[i]= StringValuePtr(*ptr);
    $1[i]=NULL; /* End of list */
    }

    // This cleans up the char ** array created before
    // the function call

    %typemap(freearg) char ** {
    free((char *) $1);
    }

    // Now a test function
    %inline %{
    int print_args(char **argv) {
    int i = 0;
    while (argv[i]) {
    printf("argv[%d] = %s\n", i,argv[i]);
    i++;
    }
    return i;
    }
    %}

    +
    %module argv
    +
    +// This tells SWIG to treat char ** as a special case
    +%typemap(in) char ** {
    +  /* Get the length of the array */
    +  int size = RARRAY($input)->len; 
    +  int i;
    +  $1 = (char **) malloc((size+1)*sizeof(char *));
    +  /* Get the first element in memory */
    +  VALUE *ptr = RARRAY($input)->ptr; 
    +  for (i=0; i < size; i++, ptr++) {
    +    /* Convert Ruby Object String to char* */
    +    $1[i]= StringValuePtr(*ptr); 
    +  }
    +  $1[i]=NULL; /* End of list */
    +}
    +
    +// This cleans up the char ** array created before 
    +// the function call
    +
    +%typemap(freearg) char ** {
    +  free((char *) $1);
    +}
    +
    +// Now a test function
    +%inline %{
    +int print_args(char **argv) {
    +  int i = 0;
    +  while (argv[i]) {
    +    printf("argv[%d] = %s\n", i,argv[i]);
    +    i++;
    +  }
    +  return i;
    +}
    +%}

    When this module is compiled, the wrapped C function now operates as follows :

    -
    require 'Argv'
    Argv.print_args(["Dave","Mike","Mary","Jane","John"])
    argv[0] = Dave
    argv[1] = Mike
    argv[2] = Mary
    argv[3] = Jane
    argv[4] = John
    +
    require 'Argv'
    +Argv.print_args(["Dave","Mike","Mary","Jane","John"])
    +argv[0] = Dave
    +argv[1] = Mike
    +argv[2] = Mary
    +argv[3] = Jane
    +argv[4] = John

    In the example, two different typemaps are used. The "in" @@ -2980,14 +3623,17 @@ suppose you'd like to wrap this C function that collects information about people's vital statistics:

    -
    void setVitalStats(const char *person, int nattributes, const char **names, int *values);
    +
    void setVitalStats(const char *person, int nattributes, const char **names, int *values);

    and you'd like to be able to call it from Ruby by passing in an arbitrary number of key-value pairs as inputs, e.g.

    -
    setVitalStats("Fred",
    'weight' => 270,
    'age' => 42
    )
    +
    setVitalStats("Fred", 
    +  'weight' => 270, 
    +  'age' => 42 
    +)

    To make this work, you need to write a typemap that expects a @@ -2997,7 +3643,10 @@ and values) needed by your C function. Let's start with the basics:

    -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    }
    +
    %typemap(in) (int nattributes, const char **names, const int *values)
    +  (VALUE keys_arr, int i, VALUE key, VALUE val) {
    +}
    + 

    This %typemap directive tells SWIG that @@ -3016,7 +3665,10 @@ will need.

    let's next add a check for that:

    -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    }
    +
    %typemap(in) (int nattributes, const char **names, const int *values)
    +  (VALUE keys_arr, int i, VALUE key, VALUE val) {
    +    Check_Type($input, T_HASH);
    +}

    Check_Type() is just a macro (defined @@ -3032,7 +3684,11 @@ method directly and converting its result to a C int value:

    -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    }
    +
    %typemap(in) (int nattributes, const char **names, const int *values)
    +  (VALUE keys_arr, int i, VALUE key, VALUE val) {
    +    Check_Type($input, T_HASH);
    +    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    +}

    So now we know the number of attributes. Next we need to @@ -3041,7 +3697,17 @@ arrays) to NULL and set the stage for extracting the keys and values from the hash:

    -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    $2 = NULL;
    $3 = NULL;
    if ($1 > 0) {
    $2 = (char **) malloc($1*sizeof(char *));
    $3 = (int *) malloc($1*sizeof(int));
    }

    }
    +
    %typemap(in) (int nattributes, const char **names, const int *values)
    +  (VALUE keys_arr, int i, VALUE key, VALUE val) {
    +    Check_Type($input, T_HASH);
    +    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    +    $2 = NULL;
    +    $3 = NULL;
    +    if ($1 > 0) {
    +      $2 = (char **) malloc($1*sizeof(char *));
    +      $3 = (int *) malloc($1*sizeof(int));
    +    }
    +}

    There are a number of ways we could extract the keys and @@ -3050,7 +3716,20 @@ the hash's keys method (which returns a Ruby array of the keys) and then start looping over the elements in that array:

    -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    $2 = NULL;
    $3 = NULL;
    if ($1 > 0) {
    $2 = (char **) malloc($1*sizeof(char *));
    $3 = (int *) malloc($1*sizeof(int));
    keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
    for (i = 0; i < $1; i++) {
    }

    }
    }
    +
    %typemap(in) (int nattributes, const char **names, const int *values)
    +  (VALUE keys_arr, int i, VALUE key, VALUE val) {
    +    Check_Type($input, T_HASH);
    +    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    +    $2 = NULL;
    +    $3 = NULL;
    +    if ($1 > 0) {
    +      $2 = (char **) malloc($1*sizeof(char *));
    +      $3 = (int *) malloc($1*sizeof(int));
    +      keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
    +      for (i = 0; i < $1; i++) {
    +      }
    +    }
    +}

    Recall that keys_arr and i @@ -3059,7 +3738,22 @@ array, we want to get the key itself, as well as the value corresponding to that key in the hash:

    -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    $2 = NULL;
    $3 = NULL;
    if ($1 > 0) {
    $2 = (char **) malloc($1*sizeof(char *));
    $3 = (int *) malloc($1*sizeof(int));
    keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
    for (i = 0; i < $1; i++) {
    key = rb_ary_entry(keys_arr, i);
    val = rb_hash_aref($input, key);

    }
    }
    }
    +
    %typemap(in) (int nattributes, const char **names, const int *values)
    +  (VALUE keys_arr, int i, VALUE key, VALUE val) {
    +    Check_Type($input, T_HASH);
    +    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    +    $2 = NULL;
    +    $3 = NULL;
    +    if ($1 > 0) {
    +      $2 = (char **) malloc($1*sizeof(char *));
    +      $3 = (int *) malloc($1*sizeof(int));
    +      keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
    +      for (i = 0; i < $1; i++) {
    +        key = rb_ary_entry(keys_arr, i);
    +        val = rb_hash_aref($input, key);
    +      }
    +    }
    +}

    To be safe, we should again use the Check_Type() @@ -3067,14 +3761,50 @@ macro to confirm that the key is a String and the value is a Fixnum:

    -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    $2 = NULL;
    $3 = NULL;
    if ($1 > 0) {
    $2 = (char **) malloc($1*sizeof(char *));
    $3 = (int *) malloc($1*sizeof(int));
    keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
    for (i = 0; i < $1; i++) {
    key = rb_ary_entry(keys_arr, i);
    val = rb_hash_aref($input, key);
    Check_Type(key, T_STRING);
    Check_Type(val, T_FIXNUM);

    }
    }
    }
    +
    %typemap(in) (int nattributes, const char **names, const int *values)
    +  (VALUE keys_arr, int i, VALUE key, VALUE val) {
    +    Check_Type($input, T_HASH);
    +    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    +    $2 = NULL;
    +    $3 = NULL;
    +    if ($1 > 0) {
    +      $2 = (char **) malloc($1*sizeof(char *));
    +      $3 = (int *) malloc($1*sizeof(int));
    +      keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
    +      for (i = 0; i < $1; i++) {
    +        key = rb_ary_entry(keys_arr, i);
    +        val = rb_hash_aref($input, key);
    +        Check_Type(key, T_STRING);
    +        Check_Type(val, T_FIXNUM);
    +      }
    +    }
    +}

    Finally, we can convert these Ruby objects into their C equivalents and store them in our local C arrays:

    -
    %typemap(in) (int nattributes, const char **names, const int *values)
    (VALUE keys_arr, int i, VALUE key, VALUE val) {
    Check_Type($input, T_HASH);
    $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    $2 = NULL;
    $3 = NULL;
    if ($1 > 0) {
    $2 = (char **) malloc($1*sizeof(char *));
    $3 = (int *) malloc($1*sizeof(int));
    keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
    for (i = 0; i < $1; i++) {
    key = rb_ary_entry(keys_arr, i);
    val = rb_hash_aref($input, key);
    Check_Type(key, T_STRING);
    Check_Type(val, T_FIXNUM);
    $2[i] = StringValuePtr(key);
    $3[i] = NUM2INT(val);

    }
    }
    }
    +
    %typemap(in) (int nattributes, const char **names, const int *values)
    +  (VALUE keys_arr, int i, VALUE key, VALUE val) {
    +  Check_Type($input, T_HASH);
    +  $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
    +  $2 = NULL;
    +  $3 = NULL;
    +  if ($1 > 0) {
    +    $2 = (char **) malloc($1*sizeof(char *));
    +    $3 = (int *) malloc($1*sizeof(int));
    +    keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
    +    for (i = 0; i < $1; i++) {
    +      key = rb_ary_entry(keys_arr, i);
    +      val = rb_hash_aref($input, key);
    +      Check_Type(key, T_STRING);
    +      Check_Type(val, T_FIXNUM);
    +      $2[i] = StringValuePtr(key);
    +      $3[i] = NUM2INT(val);
    +    }
    +  }
    +}

    We're not done yet. Since we used malloc() @@ -3084,7 +3814,10 @@ corresponding "freearg" typemap to free that memory so that there is no memory leak. Fortunately, this typemap is a lot easier to write:

    -
    %typemap(freearg) (int nattributes, const char **names, const int *values) {
    free((void *) $2);
    free((void *) $3);
    }
    +
    %typemap(freearg) (int nattributes, const char **names, const int *values) {
    +  free((void *) $2);
    +  free((void *) $3);
    +}

    All of the code for this example, as well as a sample Ruby @@ -3133,7 +3866,11 @@ For a type of Foo *, the type descriptor structure is usually accessed as follows:

    -
    Foo *foo;
    SWIG_ConvertPtr($input, (void **) &foo, SWIGTYPE_p_Foo, 1);

    VALUE obj;
    obj = SWIG_NewPointerObj(f, SWIGTYPE_p_Foo, 0);
    +
    Foo *foo;
    +SWIG_ConvertPtr($input, (void **) &foo, SWIGTYPE_p_Foo, 1);
    +
    +VALUE obj;
    +obj = SWIG_NewPointerObj(f, SWIGTYPE_p_Foo, 0);

    In a typemap, the type descriptor should always be accessed @@ -3141,7 +3878,9 @@ using the special typemap variable $1_descriptor. For example:

    -
    %typemap(in) Foo * {
    SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 1);
    }
    +
    %typemap(in) Foo * {
    +  SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 1);
    +}

    36.7.12.1 Ruby Datatype Wrapping

    @@ -3183,7 +3922,22 @@ macro/typemap and should give insight into constructing similar typemaps for other STL structures:

    -
    %define PTR_VECTOR_TO_RUBY_ARRAY(vectorclassname, classname)
    %typemap(out) vectorclassname &, const vectorclassname & {
    VALUE arr = rb_ary_new2($1->size());
    vectorclassname::iterator i = $1->begin(), iend = $1->end();
    for ( ; i!=iend; i++ )
    rb_ary_push(arr, Data_Wrap_Struct(c ## classname.klass, 0, 0, *i));
    $result = arr;
    }
    %typemap(out) vectorclassname, const vectorclassname {
    VALUE arr = rb_ary_new2($1.size());
    vectorclassname::iterator i = $1.begin(), iend = $1.end();
    for ( ; i!=iend; i++ )
    rb_ary_push(arr, Data_Wrap_Struct(c ## classname.klass, 0, 0, *i));
    $result = arr;
    }
    %enddef
    +
    %define PTR_VECTOR_TO_RUBY_ARRAY(vectorclassname, classname)
    +%typemap(out) vectorclassname &, const vectorclassname & {
    +  VALUE arr = rb_ary_new2($1->size());
    +  vectorclassname::iterator i = $1->begin(), iend = $1->end();
    +  for ( ; i!=iend; i++ )
    +    rb_ary_push(arr, Data_Wrap_Struct(c ## classname.klass, 0, 0, *i));
    +  $result = arr;
    +}
    +%typemap(out) vectorclassname, const vectorclassname {
    +  VALUE arr = rb_ary_new2($1.size());
    +  vectorclassname::iterator i = $1.begin(), iend = $1.end();
    +  for ( ; i!=iend; i++ )
    +    rb_ary_push(arr, Data_Wrap_Struct(c ## classname.klass, 0, 0, *i));
    +  $result = arr;
    +}
    +%enddef

    Note, that the "c ## classname.klass" is @@ -3193,28 +3947,60 @@ class name.

    To use the macro with a class Foo, the following is used:

    -
    PTR_VECTOR_TO_RUBY_ARRAY(vector<foo *="">, Foo)
    +
    PTR_VECTOR_TO_RUBY_ARRAY(vector<foo *="">, Foo)

    It is also possible to create a STL vector of Ruby objects:

    -
    %define RUBY_ARRAY_TO_PTR_VECTOR(vectorclassname, classname)
    %typemap(in) vectorclassname &, const vectorclassname & {
    Check_Type($input, T_ARRAY);
    vectorclassname *vec = new vectorclassname;
    int len = RARRAY($input)->len;
    for (int i=0; i!=len; i++) {
    VALUE inst = rb_ary_entry($input, i);
    //The following _should_ work but doesn't on HPUX
    // Check_Type(inst, T_DATA);
    classname *element = NULL;
    Data_Get_Struct(inst, classname, element);
    vec->push_back(element);
    }
    $1 = vec;
    }

    %typemap(freearg) vectorclassname &, const vectorclassname & {
    delete $1;
    }
    %enddef
    +
    %define RUBY_ARRAY_TO_PTR_VECTOR(vectorclassname, classname)
    +%typemap(in) vectorclassname &, const vectorclassname & {
    +  Check_Type($input, T_ARRAY);
    +  vectorclassname *vec = new vectorclassname;
    +  int len = RARRAY($input)->len;
    +  for (int i=0; i!=len; i++) {
    +    VALUE inst = rb_ary_entry($input, i);
    +    //The following _should_ work but doesn't on HPUX
    +    // Check_Type(inst, T_DATA);
    +    classname *element = NULL;
    +    Data_Get_Struct(inst, classname, element);
    +    vec->push_back(element);
    +  }
    +  $1 = vec;
    +}
    +
    +%typemap(freearg) vectorclassname &, const vectorclassname & {
    +  delete $1;
    +}
    +%enddef

    It is also possible to create a Ruby array from a vector of static data types:

    -
    %define VECTOR_TO_RUBY_ARRAY(vectorclassname, classname)
    %typemap(out) vectorclassname &, const vectorclassname & {
    VALUE arr = rb_ary_new2($1->size());
    vectorclassname::iterator i = $1->begin(), iend = $1->end();
    for ( ; i!=iend; i++ )
    rb_ary_push(arr, Data_Wrap_Struct(c ## classname.klass, 0, 0, &(*i)));
    $result = arr;
    }
    %typemap(out) vectorclassname, const vectorclassname {
    VALUE arr = rb_ary_new2($1.size());
    vectorclassname::iterator i = $1.begin(), iend = $1.end();
    for ( ; i!=iend; i++ )
    rb_ary_push(arr, Data_Wrap_Struct(c ## classname.klass, 0, 0, &(*i)));
    $result = arr;
    }
    %enddef
    +
    %define VECTOR_TO_RUBY_ARRAY(vectorclassname, classname)
    +%typemap(out) vectorclassname &, const vectorclassname & {
    +  VALUE arr = rb_ary_new2($1->size()); 
    +  vectorclassname::iterator i = $1->begin(), iend = $1->end();
    +  for ( ; i!=iend; i++ )
    +    rb_ary_push(arr, Data_Wrap_Struct(c ## classname.klass, 0, 0, &(*i)));
    +  $result = arr;
    +}
    +%typemap(out) vectorclassname, const vectorclassname {
    +  VALUE arr = rb_ary_new2($1.size()); 
    +  vectorclassname::iterator i = $1.begin(), iend = $1.end();
    +  for ( ; i!=iend; i++ )
    +    rb_ary_push(arr, Data_Wrap_Struct(c ## classname.klass, 0, 0, &(*i)));
    +  $result = arr;
    +}
    +%enddef
    -
    - Note that this is mostly an example of typemaps. If you want to use the STL with ruby, you are advised to use the standard swig STL library, which does much more than this.  Refer to the section called -the C++ Standard Template Library.
    +the C++ Standard Template Library.

    36.8 Docstring Features

    @@ -3262,7 +4048,7 @@ example:

    -
    %module(docstring="This is the example module's docstring") example
    +
    %module(docstring="This is the example module's docstring") example

    @@ -3272,7 +4058,12 @@ macro. For example:

    -
    %define DOCSTRING
    "The `XmlResource` class allows program resources defining menus,
    layout of controls on a panel, etc. to be loaded from an XML file."
    %enddef

    %module(docstring=DOCSTRING) xrc
    +
    %define DOCSTRING
    +"The `XmlResource` class allows program resources defining menus, 
    +layout of controls on a panel, etc. to be loaded from an XML file."
    +%enddef
    +
    +%module(docstring=DOCSTRING) xrc

    36.8.2 %feature("autodoc")

    @@ -3307,7 +4098,8 @@ this function prototype:

    -
    %feature("autodoc", "0");
    bool function_name(int x, int y, Foo* foo=NULL, Bar* bar=NULL);
    +
    %feature("autodoc", "0");
    +bool function_name(int x, int y, Foo* foo=NULL, Bar* bar=NULL);

    @@ -3315,7 +4107,8 @@ Then Ruby code like this will be generated:

    -
    function_name(x, y, foo=nil, bar=nil) -> bool
    ...
    +
    function_name(x, y, foo=nil, bar=nil) -> bool
    +  ...

    36.8.2.2 %feature("autodoc", "1")

    @@ -3334,7 +4127,8 @@ this:

    -
    function_name(int x, int y, Foo foo=nil, Bar bar=nil) -> bool
    ...
    +
    function_name(int x, int y, Foo foo=nil, Bar bar=nil) -> bool
    +  ...

    36.8.2.3 %feature("autodoc", "2")

    @@ -3361,7 +4155,13 @@ this:

    -
    function_name(int x, int y, Foo foo=nil, Bar bar=nil) -> bool

    Parameters:
    x - int
    y - int
    foo - Foo
    bar - Bar
    +
    function_name(int x, int y, Foo foo=nil, Bar bar=nil) -> bool
    +
    +Parameters:
    +	x - int
    +	y - int
    +	foo - Foo
    +	bar - Bar

    36.8.2.5 %feature("autodoc", "docstring")

    @@ -3376,7 +4176,8 @@ generated string. For example:

    -
    %feature("autodoc", "GetPosition() -> (x, y)") GetPosition;
    void GetPosition(int* OUTPUT, int* OUTPUT);
    +
    %feature("autodoc", "GetPosition() -> (x, y)") GetPosition;
    +void GetPosition(int* OUTPUT, int* OUTPUT);

    36.8.3 %feature("docstring")

    @@ -3586,14 +4387,45 @@ runtime type information among the different modules.

    that defines our base class:

    -
    %module shape

    %{
    #include "Shape.h"
    %}

    class Shape {
    protected:
    double xpos;
    double ypos;
    protected:
    Shape(double x, double y);
    public:
    double getX() const;
    double getY() const;
    };
    +
    %module shape
    +
    +%{
    +#include "Shape.h"
    +%}
    +
    +class Shape {
    +protected:
    +  double xpos;
    +  double ypos;
    +protected:
    +  Shape(double x, double y);
    +public:
    +  double getX() const;
    +  double getY() const;
    +};

    We also have a separate interface file (circle.i) that defines a derived class:

    -
    %module circle

    %{
    #include "Shape.h"
    #include "Circle.h"
    %}

    // Import the base class definition from Shape module
    %import shape.i

    class Circle : public Shape {
    protected:
    double radius;
    public:
    Circle(double x, double y, double r);
    double getRadius() const;
    };
    +
    %module circle
    +
    +%{
    +#include "Shape.h"
    +#include "Circle.h"
    +%}
    +
    +// Import the base class definition from Shape module
    +%import shape.i
    +
    +class Circle : public Shape {
    +protected:
    +  double radius;
    +public:
    +  Circle(double x, double y, double r);
    +  double getRadius() const;
    +};

    We'll start by building the Shape @@ -3609,14 +4441,28 @@ To compile this into a dynamically loadable extension for Ruby, prepare an extconf.rb script using this template:

    -
    require 'mkmf'

    # Since the SWIG runtime support library for Ruby
    # depends on the Ruby library, make sure it's in the list
    # of libraries.
    $libs = append_library($libs, Config::CONFIG['RUBY_INSTALL_NAME'])

    # Create the makefile
    create_makefile('shape')
    +
    require 'mkmf'
    +
    +# Since the SWIG runtime support library for Ruby
    +# depends on the Ruby library, make sure it's in the list
    +# of libraries.
    +$libs = append_library($libs, Config::CONFIG['RUBY_INSTALL_NAME'])
    +
    +# Create the makefile
    +create_makefile('shape')

    Run this script to create a Makefile and then type make to build the shared library:

    -
    $ ruby extconf.rb
    creating Makefile
    $ make
    g++ -fPIC -g -O2 -I. -I/usr/local/lib/ruby/1.7/i686-linux \
    -I. -c shape_wrap.cxx
    gcc -shared -L/usr/local/lib -o shape.so shape_wrap.o -L. \
    -lruby -lruby -lc
    +
    $ ruby extconf.rb
    +creating Makefile
    +$ make
    +g++ -fPIC -g -O2 -I. -I/usr/local/lib/ruby/1.7/i686-linux \
    +-I. -c shape_wrap.cxx
    +gcc -shared -L/usr/local/lib -o shape.so shape_wrap.o -L. \
    +-lruby -lruby -lc

    Note that depending on your installation, the outputs may be @@ -3642,7 +4488,17 @@ and Circle modules are properly loaded and initialized:

    -
    $ irb
    irb(main):001:0> require 'shape'
    true
    irb(main):002:0> require 'circle'
    true
    irb(main):003:0> c = Circle::Circle.new(5, 5, 20)
    #<Circle::Circle:0xa097208>
    irb(main):004:0> c.kind_of? Shape::Shape
    true
    irb(main):005:0> c.getX()
    5.0
    +
    $ irb
    +irb(main):001:0> require 'shape'
    +true
    +irb(main):002:0> require 'circle'
    +true
    +irb(main):003:0> c = Circle::Circle.new(5, 5, 20)
    +#<Circle::Circle:0xa097208>
    +irb(main):004:0> c.kind_of? Shape::Shape
    +true
    +irb(main):005:0> c.getX()
    +5.0

    36.9.3 Specifying Mixin Modules

    @@ -3654,14 +4510,30 @@ method. For example, if you have a Ruby class that defines an each instance method, e.g.

    -
    class Set
    def initialize
    @members = []
    end

    def each
    @members.each { |m| yield m }
    end
    end
    +
    class Set
    +  def initialize
    +  @members = []
    +  end
    + 
    +  def each
    +  @members.each { |m| yield m }
    +  end
    +end

    then you can mix-in Ruby's Enumerable module to easily add a lot of functionality to your class:

    -
    class Set
    include Enumerable
    def initialize
    @members = []
    end
    def each
    @members.each { |m| yield m }
    end
    end
    +
    class Set
    +  include Enumerable
    +  def initialize
    +    @members = []
    +  end
    +  def each
    +    @members.each { |m| yield m }
    +  end
    +end

    To get the same benefit for your SWIG-wrapped classes, you @@ -3670,7 +4542,16 @@ of one or more modules that should be mixed-in to a class. For the above example, the SWIG interface specification might look like this:

    -
    %mixin Set "Enumerable";

    class Set {
    public:
    // Constructor
    Set();

    // Iterates through set members
    void each();
    };
    +
    %mixin Set "Enumerable";
    +
    +class Set {
    +public:
    +  // Constructor
    +  Set();
    + 
    +  // Iterates through set members
    +  void each();
    +};

    Multiple modules can be mixed into a class by providing a @@ -3771,7 +4652,25 @@ library responsible for freeing the object. a Foo and a Bar class.

    -
    /* File "RubyOwernshipExample.h" */

    class Foo
    {
    public:
    Foo() {}
    ~Foo() {}
    };

    class Bar
    {
    Foo *foo_;
    public:
    Bar(): foo_(new Foo) {}
    ~Bar() { delete foo_; }
    Foo* get_foo() { return foo_; }
    Foo* get_new_foo() { return new Foo; }
    void set_foo(Foo *foo) { delete foo_; foo_ = foo; }
    };

    +
    /* File "RubyOwernshipExample.h" */
    +
    +class Foo
    +{
    +public:
    +  Foo() {}
    +  ~Foo() {}
    +};
    +
    +class Bar
    +{
    +  Foo *foo_;
    +public:
    +  Bar(): foo_(new Foo) {}
    +  ~Bar() { delete foo_; }
    +  Foo* get_foo() { return foo_; }
    +  Foo* get_new_foo() { return new Foo; }
    +  void set_foo(Foo *foo) { delete foo_; foo_ = foo; }
    +};

    First, consider this Ruby code:

    @@ -3789,7 +4688,8 @@ called. It in turn will call Foo's destructor.

    Next, consider this code:

    -
    bar = Bar.new
    foo = bar.get_foo()
    +
    bar = Bar.new
    +foo = bar.get_foo()

    In this case, the Ruby code calls a C++ member function, get_foo. @@ -3801,7 +4701,8 @@ object is not affected.

    above. For example:

    -
    bar = Bar.new
    foo = bar.get_new_foo()
    +
    bar = Bar.new
    +foo = bar.get_new_foo()

    In this case, the default SWIG behavior for calling member @@ -3813,7 +4714,9 @@ Object ownership and %newobject for more information.

    The SWIG default mappings are also incorrect in this case:

    -
    foo = Foo.new
    bar = Bar.new
    bar.set_foo(foo)
    +
    foo = Foo.new
    +bar = Bar.new
    +bar.set_foo(foo)

    Without modification, this code will cause a segmentation @@ -3873,7 +4776,70 @@ shown below to illustrate different memory management techniques. The class library models a zoo and the animals it contains.

    -
    %module zoo

    %{
    #include <string>
    #include <vector>

    #include "zoo.h"
    %}

    class Animal
    {
    private:
    typedef std::vector<Animal*> AnimalsType;
    typedef AnimalsType::iterator IterType;
    protected:
    AnimalsType animals;
    protected:
    std::string name_;
    public:
    // Construct an animal with this name
    Animal(const char* name) : name_(name) {}

    // Return the animal's name
    const char* get_name() const { return name.c_str(); }
    };

    class Zoo
    {
    protected:
    std::vector<animal *=""> animals;

    public:
    // Construct an empty zoo
    Zoo() {}

    /* Create a new animal. */
    static Animal* Zoo::create_animal(const char* name)
    {
    return new Animal(name);
    }

    // Add a new animal to the zoo
    void add_animal(Animal* animal) {
    animals.push_back(animal);
    }

    Animal* remove_animal(size_t i) {
    Animal* result = this->animals[i];
    IterType iter = this->animals.begin();
    std::advance(iter, i);
    this->animals.erase(iter);

    return result;
    }

    // Return the number of animals in the zoo
    size_t get_num_animals() const {
    return animals.size();
    }

    // Return a pointer to the ith animal
    Animal* get_animal(size_t i) const {
    return animals[i];
    }
    };

    +
    %module zoo
    +
    +%{
    +#include <string>
    +#include <vector>
    +
    +#include "zoo.h"
    +%}
    +
    +class Animal
    +{
    +private:
    +  typedef std::vector<Animal*> AnimalsType;
    +  typedef AnimalsType::iterator IterType;
    +protected:
    +  AnimalsType animals;
    +protected:
    +  std::string name_;
    +public:
    +  // Construct an animal with this name
    +  Animal(const char* name) : name_(name) {}
    + 
    +  // Return the animal's name
    +  const char* get_name() const { return name.c_str(); }
    +};
    +
    +class Zoo
    +{
    +protected:
    + std::vector<animal *=""> animals;
    + 
    +public:
    +  // Construct an empty zoo
    +  Zoo() {}
    +  
    +  /* Create a new animal. */
    +  static Animal* Zoo::create_animal(const char* name) {
    +    return new Animal(name);
    +  }
    + 
    +  // Add a new animal to the zoo
    +  void add_animal(Animal* animal) {
    +    animals.push_back(animal); 
    +  }
    + 
    +  Animal* remove_animal(size_t i) {
    +    Animal* result = this->animals[i];
    +    IterType iter = this->animals.begin();
    +    std::advance(iter, i);
    +    this->animals.erase(iter);
    +   
    +    return result;
    +  }
    +  
    +  // Return the number of animals in the zoo
    +  size_t get_num_animals() const {
    +    return animals.size(); 
    +  }
    +  
    +  // Return a pointer to the ith animal
    +  Animal* get_animal(size_t i) const {
    +    return animals[i]; 
    +  }
    +};

    Let's say you SWIG this code and then run IRB: @@ -3913,8 +4879,7 @@ irb(main):009:0> tiger1.equal?(tiger2)

    Pay particular attention to the code tiger1.equal?(tiger2). Note that the two Ruby objects are not the same - but they reference -the same underlying C++ object. This can cause problems. For example:
    - +the same underlying C++ object. This can cause problems. For example:

    @@ -3954,24 +4919,65 @@ the chapter on class-by-class basis if needed. To fix the example above:

    -
    %module example

    %{
    #include "example.h"
    %}

    /* Tell SWIG that create_animal creates a new object */
    %newobject Zoo::create_animal;

    /* Tell SWIG to keep track of mappings between C/C++ structs/classes. */
    %trackobjects;

    %include "example.h"
    +
    %module example
    +
    +%{
    +#include "example.h"
    +%}
    +
    +/* Tell SWIG that create_animal creates a new object */
    +%newobject Zoo::create_animal;
    +
    +/* Tell SWIG to keep track of mappings between C/C++ structs/classes. */%trackobjects;
    +
    +%include "example.h"

    When this code runs we see:

    -
    $ irb
    irb(main):001:0> require 'example'
    => true

    irb(main):002:0> tiger1 = Example::Animal.new("tiger1")
    => #<Example::Animal:0x2be37d8>

    irb(main):003:0> zoo = Example::Zoo.new()
    => #<Example::Zoo:0x2be0a18>

    irb(main):004:0> zoo.add_animal(tiger1)
    => nil

    irb(main):006:0> tiger2 = zoo.remove_animal(0)
    => #<Example::Animal:0x2be37d8>

    irb(main):007:0> tiger1.equal?(tiger2)
    => true

    irb(main):008:0> tiger1 = nil
    => nil

    irb(main):009:0> GC.start
    => nil

    irb(main):010:0> tiger.get_name()
    => "tiger1"
    irb(main):011:0>

    +
    $ irb
    +irb(main):001:0> require 'example'
    +=> true
    +
    +irb(main):002:0> tiger1 = Example::Animal.new("tiger1")
    +=> #<Example::Animal:0x2be37d8>
    +
    +irb(main):003:0> zoo = Example::Zoo.new()
    +=> #<Example::Zoo:0x2be0a18>
    +
    +irb(main):004:0> zoo.add_animal(tiger1)
    +=> nil
    +
    +irb(main):006:0> tiger2 = zoo.remove_animal(0)
    +=> #<Example::Animal:0x2be37d8>
    +
    +irb(main):007:0> tiger1.equal?(tiger2)
    +=> true
    +
    +irb(main):008:0> tiger1 = nil
    +=> nil
    +
    +irb(main):009:0> GC.start
    +=> nil
    +
    +irb(main):010:0> tiger.get_name()
    +=> "tiger1"
    +irb(main):011:0>

    For those who are interested, object tracking is implemented by storing Ruby objects in a hash table and keying them on C++ -pointers. The underlying API is:
    +pointers. The underlying API is:

    -
    static void SWIG_RubyAddTracking(void* ptr, VALUE object);
    static VALUE SWIG_RubyInstanceFor(void* ptr) ;
    static void SWIG_RubyRemoveTracking(void* ptr);
    static void SWIG_RubyUnlinkObjects(void* ptr);
    +
    static void SWIG_RubyAddTracking(void* ptr, VALUE object);
    +static VALUE SWIG_RubyInstanceFor(void* ptr) ;
    +static void SWIG_RubyRemoveTracking(void* ptr);
    +static void SWIG_RubyUnlinkObjects(void* ptr);

    When an object is created, SWIG will automatically call the SWIG_RubyAddTracking @@ -3991,12 +4997,32 @@ methods.

    With a bit more testing, we see that our class library still -has problems. For example:
    +has problems. For example:

    -
    $ irb
    irb(main):001:0> require 'example'
    => true

    irb(main):002:0> tiger1 = Example::Animal.new("tiger1")
    => #<Example::Animal:0x2bea6a8>

    irb(main):003:0> zoo = Example::Zoo.new()
    => #<Example::Zoo:0x2be7960>

    irb(main):004:0> zoo.add_animal(tiger1)
    => nil

    irb(main):007:0> tiger1 = nil
    => nil

    irb(main):007:0> GC.start
    => nil

    irb(main):005:0> tiger2 = zoo.get_animal(0)
    (irb):12: [BUG] Segmentation fault
    +
    $ irb
    +irb(main):001:0> require 'example'
    +=> true
    +
    +irb(main):002:0> tiger1 = Example::Animal.new("tiger1")
    +=> #<Example::Animal:0x2bea6a8>
    +
    +irb(main):003:0> zoo = Example::Zoo.new()
    +=> #<Example::Zoo:0x2be7960>
    +
    +irb(main):004:0> zoo.add_animal(tiger1)
    +=> nil
    +
    +irb(main):007:0> tiger1 = nil
    +=> nil
    +
    +irb(main):007:0> GC.start
    +=> nil
    +
    +irb(main):005:0> tiger2 = zoo.get_animal(0)
    +(irb):12: [BUG] Segmentation fault

    The problem is that Ruby does not know that the zoo @@ -4023,7 +5049,40 @@ then call rb_gc_mark(). One possible implementation is:

    -
    %module example

    %{
    #include "example.h"
    %}

    /* Keep track of mappings between C/C++ structs/classes
    and Ruby objects so we can implement a mark function. */
    %trackobjects;

    /* Specify the mark function */
    %markfunc Zoo "mark_Zoo";

    %include "example.h"

    %header %{

    static void mark_Zoo(void* ptr) {
    Zoo* zoo = (Zoo*) ptr;

    /* Loop over each object and tell the garbage collector
    that we are holding a reference to them. */
    int count = zoo->get_num_animals();

    for(int i = 0; i < count; ++i) {
    Animal* animal = zoo->get_animal(i);
    VALUE object = SWIG_RubyInstanceFor(animal);

    if (object != Qnil) {
    rb_gc_mark(object);
    }
    }
    }
    %}

    +
    %module example
    +
    +%{
    +#include "example.h"
    +%}
    +
    +/* Keep track of mappings between C/C++ structs/classes
    + and Ruby objects so we can implement a mark function. */
    +%trackobjects;
    +
    +/* Specify the mark function */
    +%markfunc Zoo "mark_Zoo";
    +
    +%include "example.h"
    +
    +%header %{
    +
    +static void mark_Zoo(void* ptr) {
    +  Zoo* zoo = (Zoo*) ptr;
    + 
    +  /* Loop over each object and tell the garbage collector
    +  that we are holding a reference to them. */
    +  int count = zoo->get_num_animals();
    + 
    +  for(int i = 0; i < count; ++i) {
    +    Animal* animal = zoo->get_animal(i);
    +    VALUE object = SWIG_RubyInstanceFor(animal);
    + 
    +    if (object != Qnil) {
    +      rb_gc_mark(object);
    +    }
    +  }
    +}
    +%}

    Note the mark function is dependent on @@ -4035,7 +5094,30 @@ test suite.

    When this code is compiled we now see:

    -
    $ irb
    irb(main):002:0> tiger1=Example::Animal.new("tiger1")
    => #<Example::Animal:0x2be3bf8>

    irb(main):003:0> Example::Zoo.new()
    => #<Example::Zoo:0x2be1780>

    irb(main):004:0> zoo = Example::Zoo.new()
    => #<Example::Zoo:0x2bde9c0>

    irb(main):005:0> zoo.add_animal(tiger1)
    => nil

    irb(main):009:0> tiger1 = nil
    => nil

    irb(main):010:0> GC.start
    => nil
    irb(main):014:0> tiger2 = zoo.get_animal(0)
    => #<Example::Animal:0x2be3bf8>

    irb(main):015:0> tiger2.get_name()
    => "tiger1"
    irb(main):016:0>

    +
    $ irb
    +irb(main):002:0> tiger1=Example::Animal.new("tiger1")
    +=> #<Example::Animal:0x2be3bf8>
    +
    +irb(main):003:0> Example::Zoo.new()
    +=> #<Example::Zoo:0x2be1780>
    +
    +irb(main):004:0> zoo = Example::Zoo.new()
    +=> #<Example::Zoo:0x2bde9c0>
    +
    +irb(main):005:0> zoo.add_animal(tiger1)
    +=> nil
    +
    +irb(main):009:0> tiger1 = nil
    +=> nil
    +
    +irb(main):010:0> GC.start
    +=> nil
    +irb(main):014:0> tiger2 = zoo.get_animal(0)
    +=> #<Example::Animal:0x2be3bf8>
    +
    +irb(main):015:0> tiger2.get_name()
    +=> "tiger1"
    +irb(main):016:0>

    This code can be seen in swig/examples/ruby/mark_function.

    @@ -4125,8 +5207,7 @@ implementing a custom free function that calls the SWIG_RubyUnlinkObjectsSWIG_RubyUnlinkObjects function notifies SWIG that a Ruby object's underlying C++ object is no longer valid. Once notified, SWIG will intercept any calls from the -existing Ruby object to the destroyed C++ object and raise an exception.
    - +existing Ruby object to the destroyed C++ object and raise an exception.

    From abc27fd1572a32977dfc54d902a0cea6cdaeb3bd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Jun 2013 01:58:43 +0100 Subject: [PATCH 0662/1160] Further Ruby html doc formatting changes --- Doc/Manual/Contents.html | 4 +- Doc/Manual/Ruby.html | 211 +++++++++++++++++++-------------------- 2 files changed, 107 insertions(+), 108 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 32fa32e96..77280c8bc 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -1528,9 +1528,9 @@
  • Placement of typemaps
  • Ruby typemaps
  • @@ -1305,15 +1305,15 @@ chapter.

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

    The Ruby STL mappings allows you to modify those containers that support functors using Ruby procs or methods, instead. - Currently, +Currently, this includes std::set, set::map, std::multiset @@ -1333,7 +1333,7 @@ are provided.

    %include <std_set.i> -%typemap(IntSet)  std::set< int, swig::BinaryPredicate >; +%typemap(IntSet) std::set< int, swig::BinaryPredicate >;

    You can then use the set from Ruby with or without a proc @@ -1349,39 +1349,39 @@ a << 1 a << 2 a << 3 a -=> [1,2,3] +=> [1,2,3] # Custom sorting behavior defined by a Ruby proc b = IntSet.new( proc { |a,b| a > b } ) -b << 1 -b << 2 -b << 3 +b << 1 +b << 2 +b << 3 b -=>  [3,2,1] +=> [3,2,1]

    36.3.15 C++ STL Iterators

    -

    The STL is well known for the use of iterators.  There +

    The STL is well known for the use of iterators. There are a number of iterators possible with different properties, but in general there are two main categories: const iterators and non-const -iterators.  The const iterators can access and not modify the +iterators. The const iterators can access and not modify the values they point at, while the non-const iterators can both read and modify the values.

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

    +ending points of the iteration range.

    The SWIG STL library already provides typemaps to all the standard containers to do this wrapping automatically for you, but if you have your own STL-like iterator, you will need to write your own -typemap for them.  For out typemaps, the special functions make_const_iterator and make_nonconst_iterator are provided.

    +typemap for them. For out typemaps, the special functions make_const_iterator and make_nonconst_iterator are provided.

    These can be used either like:

    @@ -1390,17 +1390,17 @@ make_const_iterator( iterator, rubyclass ); make_const_iterator( iterator, iterator_begin, iterator_end, rubyclass ); -

    The iterators support a next() and previous() member function to -just change the iterator without returning anything.  previous() -should obviously only be used for bidirectional iterators.  You +

    The iterators support a next() and previous() member function to +just change the iterator without returning anything. previous() +should obviously only be used for bidirectional iterators. You can also advance the iterator multiple steps by using standard math operations like +=.

    The -value the iterator points at can be accessed with value() -- this is equivalent to dereferencing it with *i. -  For non-const iterators, a value=() function +value the iterator points at can be accessed with value() -- this is equivalent to dereferencing it with *i. + For non-const iterators, a value=() function is also provided which allows you to change the value pointed by the -iterator.  This is equivalent to the C++ construct of dereferencing and assignment, like *i = something

    +iterator. This is equivalent to the C++ construct of dereferencing and assignment, like *i = something.

    Thus, given say a vector class of doubles defined as:

    @@ -1432,10 +1432,10 @@ v << 3 i = v.begin e = v.end while i != e -  val = i.value -  val += 2 -  i.value = val -  i.next + val = i.value + val += 2 + i.value = val + i.next end i >> [3, 4, 5 ] @@ -2022,12 +2022,12 @@ Features for more examples.

    One of the highlights of Ruby and most of its standard library is the use of blocks, which allow the easy creation of continuations and -other niceties.  Blocks in ruby are also often used to +other niceties. Blocks in ruby are also often used to simplify the passing of many arguments to a class.

    In order to make your class constructor support blocks, you can take advantage of the %exception directive, which will get run -after the C++ class' constructor was called. 

    +after the C++ class' constructor was called.

    For example, this yields the class over after its construction: @@ -2037,8 +2037,8 @@ construction:

    class Window
     {
     public:
    - Window(int x, int y, int w, int h);
    -// .... other methods here ....
    +  Window(int x, int y, int w, int h);
    +  // .... other methods here ....
     };
     
     // Add support for yielding self in the Class' constructor.
    @@ -2054,8 +2054,8 @@ public:
     
     
     Window.new(0,0,360,480) { |w|
    -    w.color = Fltk::RED
    -    w.border = false
    +  w.color = Fltk::RED
    +  w.border = false
     }
     
    @@ -2070,15 +2070,13 @@ a special in typemap, like:

    // void func(int x); %typemap(in,numinputs=0) int RUBY_YIELD_SELF { -     if ( !rb_block_given_p() ) -            -rb_raise("No block given"); -     return rb_yield(self); + if ( !rb_block_given_p() ) + rb_raise("No block given"); + return rb_yield(self); } %extend { -        void func(int x, int -RUBY_YIELD_SELF ); + void func(int x, int RUBY_YIELD_SELF ); }
    @@ -2286,7 +2284,7 @@ end wrapping behavior for various C/C++ datatypes using the %typemap directive. This is an advanced topic that assumes familiarity with the Ruby C API as well as the material in the "Typemaps" -chapter.  +chapter.

    Before proceeding, it should be stressed that typemaps are not @@ -2300,7 +2298,7 @@ of the primitive C-Ruby interface.

    A typemap is nothing more than a code generation rule that is attached to a specific C datatype. The general form of this declaration is as follows ( parts enclosed in [...] are optional -):    

    +):

    @@ -2641,7 +2639,7 @@ string
     

    The following list details all of the typemap methods that can be used by the Ruby module:

    -

    36.7.6.1  "in" typemap

    +

    36.7.6.1 "in" typemap

    Converts Ruby objects to input @@ -2730,7 +2728,7 @@ program uses overloaded methods, you should also define a collection of "typecheck" typemaps. More details about this follow in a later section on "Typemaps and Overloading."

    -

    36.7.6.3  "out" typemap

    +

    36.7.6.3 "out" typemap

    Converts return value of a C function @@ -2848,7 +2846,7 @@ example:

    /* Set the input argument to point to a temporary variable */
     %typemap(in, numinputs=0) int *out (int temp) {
    - $1 = &temp;
    +  $1 = &temp;
     }
     
     %typemap(argout, fragment="output_helper") int *out {
    @@ -3018,7 +3016,7 @@ handling with %exception section.

    Converts C++ objects in director -member functions to ruby objects. It is roughly the opposite +member functions to ruby objects. It is roughly the opposite of the "in" typemap, making its typemap rule often similar to the "out" typemap.

    @@ -3077,14 +3075,15 @@ referring to the class itself.

    Converts Ruby objects in director -member functions to C++ objects.  It is roughly the opposite +member functions to C++ objects. It is roughly the opposite of the "out" typemap, making its rule often similar to the "in" typemap.

     %typemap(directorout) int {
    -   $result = NUM2INT($1);
    +  $result = NUM2INT($1);
    +}
     
    @@ -3130,9 +3129,9 @@ referring to the class itself.

    Currently, the directorout nor the out typemap support the -option numoutputs, +option numoutputs, but the Ruby module provides that functionality through a %feature -directive.  Thus, a function can be made to return "nothing" +directive. Thus, a function can be made to return "nothing" if you do:

    @@ -3271,13 +3270,13 @@ 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 book, by David Thomas and Andrew Hunt.) 

    +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 +each swig language supported). If you are trying to create a swig file that will work under multiple languages, it is recommended you stick to the swig functions instead of the native Ruby functions. - That should help you avoid having to rewrite a lot of typemaps +That should help you avoid having to rewrite a lot of typemaps across multiple languages.

    36.7.8.1 C Datatypes to Ruby Objects

    @@ -3999,7 +3998,7 @@ static data types:

    Note that this is mostly an example of typemaps. If you want to use the STL with ruby, you are advised to use the standard swig STL library, -which does much more than this.  Refer to the section called +which does much more than this. Refer to the section called the C++ Standard Template Library.

    36.8 Docstring Features

    @@ -4019,28 +4018,28 @@ read by Ruby's rdoc tool to generate html web pages, ri documentation, Windows chm file and an .xml description.

    rdoc can then be run from a console or shell window on a swig -generated file. 

    +generated file.

    For example, to generate html web pages from a C++ file, you'd -do: 

    +do:

    -$ rdoc -E cxx=c -f html file_wrap.cxx
    +$ rdoc -E cxx=c -f html file_wrap.cxx
     

    To generate ri documentation from a c wrap file, you could do:

    -$ rdoc -r file_wrap.c
    +$ rdoc -r file_wrap.c
     

    36.8.1 Module docstring

    -Ruby allows a docstring at the beginning of the file +Ruby allows a docstring at the beginning of the file before any other statements, and it is typically used to give a general description of the entire module. SWIG supports this by setting an option of the %module directive. For @@ -4138,7 +4137,7 @@ this: When the "2" option is used then the parameter types will not be used in the rdoc string. However, they will be listed in full after the -function.  Given the example above, then turning on the +function. Given the example above, then turning on the parameter types with the "2" option will result in Ruby code like this:

    @@ -4148,7 +4147,7 @@ this:

    When the "3" option is used then the function will be documented using -a combination of "1" and "2" above.  Given the example above, +a combination of "1" and "2" above. Given the example above, then turning on the parameter types with the "2" option will result in Ruby code like this: @@ -4744,24 +4743,24 @@ classes is:

    class Foo { public: - Foo(); - ~Foo(); + Foo(); + ~Foo(); }; class Bar { - Foo *foo_; + Foo *foo_; public: - Bar(); - ~Bar(); - Foo* get_foo(); + Bar(); + ~Bar(); + Foo* get_foo(); - %newobject get_new_foo; - Foo* get_new_foo(); + %newobject get_new_foo; + Foo* get_new_foo(); - %apply SWIGTYPE *DISOWN {Foo *foo}; - void set_foo(Foo *foo); - %clear Foo *foo; + %apply SWIGTYPE *DISOWN {Foo *foo}; + void set_foo(Foo *foo); + %clear Foo *foo; };
    @@ -5230,28 +5229,28 @@ existing Ruby object to the destroyed C++ object and raise an exception. %include "example.h" %header %{ - static void free_Zoo(void* ptr) { - Zoo* zoo = (Zoo*) ptr; + static void free_Zoo(void* ptr) { + Zoo* zoo = (Zoo*) ptr; - /* Loop over each animal */ - int count = zoo->get_num_animals(); + /* Loop over each animal */ + int count = zoo->get_num_animals(); - for(int i = 0; i < count; ++i) { - /* Get an animal */ - Animal* animal = zoo->get_animal(i); + for(int i = 0; i < count; ++i) { + /* Get an animal */ + Animal* animal = zoo->get_animal(i); - /* Unlink the Ruby object from the C++ object */ - SWIG_RubyUnlinkObjects(animal); + /* Unlink the Ruby object from the C++ object */ + SWIG_RubyUnlinkObjects(animal); - /* Now remove the tracking for this animal */ - SWIG_RubyRemoveTracking(animal); - } + /* Now remove the tracking for this animal */ + SWIG_RubyRemoveTracking(animal); + } - /* Now call SWIG_RubyRemoveTracking for the zoo */ - SWIG_RubyRemoveTracking(ptr); - /* Now free the zoo which will free the animals it contains */ - delete zoo; - } + /* Now call SWIG_RubyRemoveTracking for the zoo */ + SWIG_RubyRemoveTracking(ptr); + /* Now free the zoo which will free the animals it contains */ + delete zoo; + } %} @@ -5294,7 +5293,7 @@ been freed, and thus raises a runtime exception.

    As has been said, the Ruby GC runs and marks objects before its -sweep phase.  When the garbage collector is called, it will +sweep phase. When the garbage collector is called, it will also try to mark any Ruby objects (VALUE) it finds in the machine registers and in the C++ stack.

    @@ -5309,7 +5308,7 @@ whenever you do inside a function:

    For ruby to determine where its stack space begins, during 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 +similar. This function will store a pointer to the location where the stack points at that point in time.

    @@ -5317,37 +5316,37 @@ the stack points at that point in time.

    function of your program and whenever the GC is called, ruby will assume that the memory between the current location in memory and the pointer that was stored previously represents the stack, which may -contain local (and temporary) VALUE ruby objects.   Ruby will +contain local (and temporary) VALUE ruby objects. Ruby will then be careful not to remove any of those objects in that location.

    -

    So far so good.  For a normal Ruby session, all the +

    So far so good. For a normal Ruby session, all the above is completely transparent and magic to the extensions developer. -  

    +

    However, with an embedded Ruby, it may not always be possible to -modify main() to make sure ruby_init() is called there.   As +modify main() to make sure ruby_init() is called there. As such, ruby_init() will likely end up being called from within some other -function.  This can lead Ruby to measure incorrectly where the -stack begins and can result in Ruby incorrectly collecting +function. This can lead Ruby to measure incorrectly where the +stack begins and can result in Ruby incorrectly collecting those -temporary VALUE objects that are created once another function +temporary VALUE objects that are created once another function is -called.  The end result: random crashes and segmentation +called. The end result: random crashes and segmentation faults.

    This problem will often be seen in director functions that are -used for callbacks, for example.  

    +used for callbacks, for example.

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

    +function is called. This will lead Ruby to measure and not +collect any VALUE objects defined from that point on.

    To mark functions to either reset the ruby stack or not, you can use:

    From 5cdfc503e18e1f5b8895516c591332fda371d879 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 11 Jun 2013 00:22:21 -0700 Subject: [PATCH 0663/1160] Add SWIG_PYTHON_NO_DEBUG macro for building Debug wrappers against the Python Debug dll --- CHANGES.current | 6 ++++++ Doc/Manual/Python.html | 22 +++++++++++++++++++++- Doc/Manual/Windows.html | 2 +- Examples/python/class/example.dsp | 2 +- Examples/python/contract/example.dsp | 2 +- Examples/python/import/bar.dsp | 2 +- Examples/python/import/base.dsp | 2 +- Examples/python/import/foo.dsp | 2 +- Examples/python/import/spam.dsp | 2 +- Examples/python/multimap/example.dsp | 2 +- Examples/python/simple/example.dsp | 2 +- Lib/python/pyruntime.swg | 12 +++++++++--- 12 files changed, 45 insertions(+), 13 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 4b0633c22..4fbd0d6e1 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,12 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.11 (in progress) ============================ +2013-07-11: wsfulton + [Python] Add SWIG_PYTHON_NO_DEBUG macro which can be defined to use the Release version + of the Python interpreter in Debug builds of the wrappers. The Visual Studio .dsp example + files have been modified to use this so that Debug builds will now work without having + to install or build a Debug build of the interpreter. + 2013-07-07: wsfulton [Ruby] Git issue #52. Fix regression with missing rb_complex_new function for Ruby versions prior to 1.9 using std::complex wrappers if just using std::complex as an output type. diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 762abebba..fd7bfca4e 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -795,7 +795,9 @@ If you need to build it on your own, the following notes are provided: You will need to create a DLL that can be loaded into the interpreter. This section briefly describes the use of SWIG with Microsoft Visual C++. As a starting point, many of SWIG's examples include project -files. You might want to take a quick look at these in addition to +files (.dsp files) for Visual C++ 6. These can be opened by more +recent versions of Visual Studio. +You might want to take a quick look at these examples in addition to reading this section.

    @@ -868,6 +870,24 @@ set of Win32 debug or thread libraries. You will have to fiddle around with the build options of project to try and track this down.

    +

    +A 'Debug' build of the wrappers requires a debug build of the Python interpreter. +This normally requires building the Python interpreter from source, which is not a +job for the feint-hearted. Alternatively you can use the 'Release' build of the +Python interpreter with a 'Debug' build of your wrappers by defining the SWIG_PYTHON_NO_DEBUG +symbol under the preprocessor options. Or you can ensure this macro is defined at the beginning +of the wrapper code using the following in your interface file, where _MSC_VER ensures it is +only used by the Visual Studio compiler: +

    + +
    +%begin %{
    +#ifdef _MSC_VER
    +#define SWIG_PYTHON_NO_DEBUG
    +#endif
    +%}
    +
    +

    Some users have reported success in building extension modules using Cygwin and other compilers. However, the problem of building usable DLLs with these diff --git a/Doc/Manual/Windows.html b/Doc/Manual/Windows.html index c94a3da3b..c8467c78a 100644 --- a/Doc/Manual/Windows.html +++ b/Doc/Manual/Windows.html @@ -147,7 +147,7 @@ PERL5_LIB: D:\nsPerl5.004_04\lib\CORE\perl.lib

    -PYTHON_INCLUDE : Set this to the directory that contains python.h
    +PYTHON_INCLUDE : Set this to the directory that contains Python.h
    PYTHON_LIB : Set this to the python library including path for linking

    Example using Python 2.1.1:
    diff --git a/Examples/python/class/example.dsp b/Examples/python/class/example.dsp index b75bd9ee2..35955709a 100644 --- a/Examples/python/class/example.dsp +++ b/Examples/python/class/example.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Examples/python/contract/example.dsp b/Examples/python/contract/example.dsp index 68f79c7a6..40f57196e 100644 --- a/Examples/python/contract/example.dsp +++ b/Examples/python/contract/example.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Examples/python/import/bar.dsp b/Examples/python/import/bar.dsp index df4d03e1c..9ba6edaaa 100644 --- a/Examples/python/import/bar.dsp +++ b/Examples/python/import/bar.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BAR_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BAR_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BAR_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Examples/python/import/base.dsp b/Examples/python/import/base.dsp index 5f2c4c503..f66068feb 100644 --- a/Examples/python/import/base.dsp +++ b/Examples/python/import/base.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BASE_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BASE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BASE_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Examples/python/import/foo.dsp b/Examples/python/import/foo.dsp index fc7a94b14..6c43e9121 100644 --- a/Examples/python/import/foo.dsp +++ b/Examples/python/import/foo.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FOO_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FOO_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FOO_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Examples/python/import/spam.dsp b/Examples/python/import/spam.dsp index 6fa4713ee..acf18677c 100644 --- a/Examples/python/import/spam.dsp +++ b/Examples/python/import/spam.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SPAM_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SPAM_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SPAM_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Examples/python/multimap/example.dsp b/Examples/python/multimap/example.dsp index 68f79c7a6..40f57196e 100644 --- a/Examples/python/multimap/example.dsp +++ b/Examples/python/multimap/example.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Examples/python/simple/example.dsp b/Examples/python/simple/example.dsp index 68f79c7a6..40f57196e 100644 --- a/Examples/python/simple/example.dsp +++ b/Examples/python/simple/example.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Lib/python/pyruntime.swg b/Lib/python/pyruntime.swg index dd22a1fdf..b0c4f5741 100644 --- a/Lib/python/pyruntime.swg +++ b/Lib/python/pyruntime.swg @@ -1,6 +1,12 @@ %insert(runtime) %{ -/* Python.h has to appear first */ -#include +#if defined(_DEBUG) && defined(SWIG_PYTHON_NO_DEBUG) +/* Use debug wrappers with the Python release dll */ +# undef _DEBUG +# include +# define _DEBUG +#else +# include +#endif %} %insert(runtime) "swigrun.swg"; /* SWIG API */ @@ -13,4 +19,4 @@ #if defined(SWIGPYTHON_BUILTIN) %insert(runtime) "builtin.swg"; /* Specialization for classes with single inheritance */ -#endif \ No newline at end of file +#endif From 7f95c7bb3efe0f282833a71b50818cf46d80cc1a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 11 Jun 2013 19:15:57 +0100 Subject: [PATCH 0664/1160] Use a less confusing macro name, SWIG_PYTHON_NO_DEBUG => SWIG_PYTHON_INTERPRETER_NO_DEBUG --- CHANGES.current | 2 +- Doc/Manual/Python.html | 4 ++-- Examples/python/class/example.dsp | 2 +- Examples/python/contract/example.dsp | 2 +- Examples/python/import/bar.dsp | 2 +- Examples/python/import/base.dsp | 2 +- Examples/python/import/foo.dsp | 2 +- Examples/python/import/spam.dsp | 2 +- Examples/python/multimap/example.dsp | 2 +- Examples/python/simple/example.dsp | 2 +- Lib/python/pyruntime.swg | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 4fbd0d6e1..023f2ef6c 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -6,7 +6,7 @@ Version 2.0.11 (in progress) ============================ 2013-07-11: wsfulton - [Python] Add SWIG_PYTHON_NO_DEBUG macro which can be defined to use the Release version + [Python] Add SWIG_PYTHON_INTERPRETER_NO_DEBUG macro which can be defined to use the Release version of the Python interpreter in Debug builds of the wrappers. The Visual Studio .dsp example files have been modified to use this so that Debug builds will now work without having to install or build a Debug build of the interpreter. diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index fd7bfca4e..3dde20887 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -874,7 +874,7 @@ the build options of project to try and track this down. A 'Debug' build of the wrappers requires a debug build of the Python interpreter. This normally requires building the Python interpreter from source, which is not a job for the feint-hearted. Alternatively you can use the 'Release' build of the -Python interpreter with a 'Debug' build of your wrappers by defining the SWIG_PYTHON_NO_DEBUG +Python interpreter with a 'Debug' build of your wrappers by defining the SWIG_PYTHON_INTERPRETER_NO_DEBUG symbol under the preprocessor options. Or you can ensure this macro is defined at the beginning of the wrapper code using the following in your interface file, where _MSC_VER ensures it is only used by the Visual Studio compiler: @@ -883,7 +883,7 @@ only used by the Visual Studio compiler:

     %begin %{
     #ifdef _MSC_VER
    -#define SWIG_PYTHON_NO_DEBUG
    +#define SWIG_PYTHON_INTERPRETER_NO_DEBUG
     #endif
     %}
     
    diff --git a/Examples/python/class/example.dsp b/Examples/python/class/example.dsp index 35955709a..95ad8f173 100644 --- a/Examples/python/class/example.dsp +++ b/Examples/python/class/example.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_INTERPRETER_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Examples/python/contract/example.dsp b/Examples/python/contract/example.dsp index 40f57196e..945b9a36d 100644 --- a/Examples/python/contract/example.dsp +++ b/Examples/python/contract/example.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_INTERPRETER_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Examples/python/import/bar.dsp b/Examples/python/import/bar.dsp index 9ba6edaaa..3c0dbf2bd 100644 --- a/Examples/python/import/bar.dsp +++ b/Examples/python/import/bar.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BAR_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BAR_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_INTERPRETER_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BAR_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Examples/python/import/base.dsp b/Examples/python/import/base.dsp index f66068feb..76b3f866b 100644 --- a/Examples/python/import/base.dsp +++ b/Examples/python/import/base.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BASE_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BASE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_INTERPRETER_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BASE_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Examples/python/import/foo.dsp b/Examples/python/import/foo.dsp index 6c43e9121..0a579e4cd 100644 --- a/Examples/python/import/foo.dsp +++ b/Examples/python/import/foo.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FOO_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FOO_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_INTERPRETER_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FOO_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Examples/python/import/spam.dsp b/Examples/python/import/spam.dsp index acf18677c..3adfcdb8b 100644 --- a/Examples/python/import/spam.dsp +++ b/Examples/python/import/spam.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SPAM_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SPAM_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_INTERPRETER_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SPAM_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Examples/python/multimap/example.dsp b/Examples/python/multimap/example.dsp index 40f57196e..945b9a36d 100644 --- a/Examples/python/multimap/example.dsp +++ b/Examples/python/multimap/example.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_INTERPRETER_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Examples/python/simple/example.dsp b/Examples/python/simple/example.dsp index 40f57196e..945b9a36d 100644 --- a/Examples/python/simple/example.dsp +++ b/Examples/python/simple/example.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_INTERPRETER_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x809 /d "_DEBUG" diff --git a/Lib/python/pyruntime.swg b/Lib/python/pyruntime.swg index b0c4f5741..fad97be9f 100644 --- a/Lib/python/pyruntime.swg +++ b/Lib/python/pyruntime.swg @@ -1,5 +1,5 @@ %insert(runtime) %{ -#if defined(_DEBUG) && defined(SWIG_PYTHON_NO_DEBUG) +#if defined(_DEBUG) && defined(SWIG_PYTHON_INTERPRETER_NO_DEBUG) /* Use debug wrappers with the Python release dll */ # undef _DEBUG # include From 0d05b2a2d1f0330b03e4b116cc6378346be85b28 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Wed, 5 Jun 2013 20:31:39 +0200 Subject: [PATCH 0665/1160] Octave: make texinfo strings static (internal linkage) --- Source/Modules/octave.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index bf2552a30..35ebc9ad4 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -288,7 +288,7 @@ public: String *escaped_doc_str = texinfo_escape(doc_str); if (Len(doc_str)>0) { - Printf(f_doc,"const char* %s_texinfo = ",wrap_name); + Printf(f_doc,"static const char* %s_texinfo = ",wrap_name); Printf(f_doc,"\"-*- texinfo -*-\\n\\\n%s", escaped_doc_str); if (Len(decl_info)) Printf(f_doc,"\\n\\\n@end deftypefn"); From d72e3dd899e4c359a874bb621d9721aaac23bfb9 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Wed, 5 Jun 2013 20:32:07 +0200 Subject: [PATCH 0666/1160] Octave: add SWIGRUNTIMEINLINE to SWIG_Octave_SetConstant() --- Lib/octave/octrun.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 8fdb12086..41d1c7afa 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -1280,7 +1280,7 @@ SWIGRUNTIME int SWIG_Octave_ConvertPacked(const octave_value &ov, void *ptr, siz return ost->copy(type, (char *) ptr, sz) ? SWIG_OK : SWIG_ERROR; } -void SWIG_Octave_SetConstant(octave_swig_type *module_ns, const std::string &name, const octave_value &ov) { +SWIGRUNTIMEINLINE void SWIG_Octave_SetConstant(octave_swig_type *module_ns, const std::string &name, const octave_value &ov) { module_ns->assign(name, ov); } From 0058eea3ad8f0967f6697b502a47b17a536fa7c2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 1 Jul 2013 19:23:10 +0100 Subject: [PATCH 0667/1160] Add SF patch #342 fix some director classes crashing on object deletion when using -builtin. Fixes SF bug #1301 and python test cases director_basic and director_classic seg faulting when used with -builtin. Patch from Christian Delbaere. --- CHANGES.current | 4 ++++ Lib/python/builtin.swg | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 023f2ef6c..27ea24688 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.11 (in progress) ============================ +2013-08-01: wsfulton + [Python] Add SF patch #342 from Christian Delbaere to fix some director classes crashing on + object deletion when using -builtin. Fixes SF bug #1301. + 2013-07-11: wsfulton [Python] Add SWIG_PYTHON_INTERPRETER_NO_DEBUG macro which can be defined to use the Release version of the Python interpreter in Debug builds of the wrappers. The Visual Studio .dsp example diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index 1fc3fb05f..28c557a21 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -13,7 +13,11 @@ wrapper##_closure(PyObject *a) { \ PyObject *o = wrapper(a, NULL); \ Py_XDECREF(o); \ } \ - PyObject_Del(a); \ + if (PyType_IS_GC(a->ob_type)) { \ + PyObject_GC_Del(a); \ + } else { \ + PyObject_Del(a); \ + } \ } #define SWIGPY_INQUIRY_CLOSURE(wrapper) \ From 779dc402b6744d3ae6b1859db08d4ed3d05610cf Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 1 Jul 2013 19:58:59 +0100 Subject: [PATCH 0668/1160] Fix a const_cast in generated code that was generating a <:: digraph when using the unary scope operator (::) (global scope) in a template type. Affects Python, Ruby, Ocaml. Based on SF patch #341. --- CHANGES.current | 4 ++++ Source/Modules/ocaml.cxx | 2 +- Source/Modules/python.cxx | 2 +- Source/Modules/ruby.cxx | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 27ea24688..1ec767bd7 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.11 (in progress) ============================ +2013-08-01: wsfulton + [Python, Ruby, Ocaml] Apply SF patch #341 - fix a const_cast in generated code that was generating + a <:: digraph when using the unary scope operator (::) (global scope) in a template type. + 2013-08-01: wsfulton [Python] Add SF patch #342 from Christian Delbaere to fix some director classes crashing on object deletion when using -builtin. Fixes SF bug #1301. diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index c5fcf69dd..f60c13ed3 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -1503,7 +1503,7 @@ public: /* if necessary, cast away const since Python doesn't support it! */ if (SwigType_isconst(nptype)) { nonconst = NewStringf("nc_tmp_%s", pname); - String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname); + String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname); Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); Delete(nonconst_i); Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 9a068a40a..814626a0c 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -4724,7 +4724,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { /* if necessary, cast away const since Python doesn't support it! */ if (SwigType_isconst(nptype)) { nonconst = NewStringf("nc_tmp_%s", pname); - String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname); + String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname); Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); Delete(nonconst_i); Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 48680e803..3d2c27dad 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -3201,7 +3201,7 @@ public: /* if necessary, cast away const since Ruby doesn't support it! */ if (SwigType_isconst(nptype)) { nonconst = NewStringf("nc_tmp_%s", parameterName); - String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(parameterType, 0), ppname); + String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(parameterType, 0), ppname); Wrapper_add_localv(w, nonconst, SwigType_lstr(parameterType, 0), nonconst, nonconst_i, NIL); Delete(nonconst_i); Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, From 7491be12e517d504cef2cf43a6d355ab09a5ee03 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 1 Jul 2013 20:09:31 +0100 Subject: [PATCH 0669/1160] Uninitialized variable fix in SWIG_Python_NonDynamicSetAttr when using -builtin. SF patch #340 --- CHANGES.current | 4 ++++ Lib/python/pyrun.swg | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 1ec767bd7..3f31ce314 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.11 (in progress) ============================ +2013-08-01: wsfulton + [Python] Apply SF patch #340 - Uninitialized variable fix in SWIG_Python_NonDynamicSetAttr + when using -builtin. + 2013-08-01: wsfulton [Python, Ruby, Ocaml] Apply SF patch #341 - fix a const_cast in generated code that was generating a <:: digraph when using the unary scope operator (::) (global scope) in a template type. diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 7cf9c41fa..df87bb317 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1742,7 +1742,7 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { PyObject *descr; PyObject *encoded_name; descrsetfunc f; - int res; + int res = -1; # ifdef Py_USING_UNICODE if (PyString_Check(name)) { @@ -1765,7 +1765,6 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { goto done; } - res = -1; descr = _PyType_Lookup(tp, name); f = NULL; if (descr != NULL) From 112d7aa6d0ae36af7ed6fc56abfef740d6e08a8a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 1 Jul 2013 20:13:36 +0100 Subject: [PATCH 0670/1160] Go examples and test-suite format fixes Patch has the results of find . -name *.go -exec gofmt -w {} \; SF Patch #339. --- Examples/go/callback/runme.go | 2 +- Examples/go/class/runme.go | 2 +- Examples/go/constants/runme.go | 2 +- Examples/go/enum/runme.go | 2 +- Examples/go/extend/runme.go | 2 +- Examples/go/funcptr/runme.go | 2 +- Examples/go/multimap/runme.go | 2 +- Examples/go/pointer/runme.go | 2 +- Examples/go/reference/runme.go | 2 +- Examples/go/simple/runme.go | 2 +- Examples/go/template/runme.go | 2 +- Examples/go/variables/runme.go | 2 +- Examples/test-suite/go/constover_runme.go | 2 +- Examples/test-suite/go/template_typedef_cplx3_runme.go | 1 - Examples/test-suite/go/template_typedef_cplx4_runme.go | 1 - Examples/test-suite/go/template_typedef_import_runme.go | 1 - 16 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Examples/go/callback/runme.go b/Examples/go/callback/runme.go index ffa4b3874..2eef77fdb 100644 --- a/Examples/go/callback/runme.go +++ b/Examples/go/callback/runme.go @@ -1,8 +1,8 @@ package main import ( - "fmt" . "./example" + "fmt" ) func main() { diff --git a/Examples/go/class/runme.go b/Examples/go/class/runme.go index ff64bb4be..8d68afb61 100644 --- a/Examples/go/class/runme.go +++ b/Examples/go/class/runme.go @@ -3,8 +3,8 @@ package main import ( - "fmt" . "./example" + "fmt" ) func main() { diff --git a/Examples/go/constants/runme.go b/Examples/go/constants/runme.go index 78a047e20..1427997a0 100644 --- a/Examples/go/constants/runme.go +++ b/Examples/go/constants/runme.go @@ -1,8 +1,8 @@ package main import ( - "fmt" "./example" + "fmt" ) func main() { diff --git a/Examples/go/enum/runme.go b/Examples/go/enum/runme.go index 419df5f93..99d2651f4 100644 --- a/Examples/go/enum/runme.go +++ b/Examples/go/enum/runme.go @@ -1,8 +1,8 @@ package main import ( - "fmt" . "./example" + "fmt" ) func main() { diff --git a/Examples/go/extend/runme.go b/Examples/go/extend/runme.go index 187f1ce08..8fdfd0a6c 100644 --- a/Examples/go/extend/runme.go +++ b/Examples/go/extend/runme.go @@ -3,8 +3,8 @@ package main import ( - "fmt" . "./example" + "fmt" ) type CEO struct{} diff --git a/Examples/go/funcptr/runme.go b/Examples/go/funcptr/runme.go index 73ecbb805..44dae3c9e 100644 --- a/Examples/go/funcptr/runme.go +++ b/Examples/go/funcptr/runme.go @@ -1,8 +1,8 @@ package main import ( - "fmt" . "./example" + "fmt" ) func main() { diff --git a/Examples/go/multimap/runme.go b/Examples/go/multimap/runme.go index 94c29127c..390205a80 100644 --- a/Examples/go/multimap/runme.go +++ b/Examples/go/multimap/runme.go @@ -1,8 +1,8 @@ package main import ( - "fmt" . "./example" + "fmt" ) func main() { diff --git a/Examples/go/pointer/runme.go b/Examples/go/pointer/runme.go index 63deb11b7..1414d341e 100644 --- a/Examples/go/pointer/runme.go +++ b/Examples/go/pointer/runme.go @@ -1,8 +1,8 @@ package main import ( - "fmt" . "./example" + "fmt" ) func main() { diff --git a/Examples/go/reference/runme.go b/Examples/go/reference/runme.go index 3683d6144..004a04c2e 100644 --- a/Examples/go/reference/runme.go +++ b/Examples/go/reference/runme.go @@ -3,8 +3,8 @@ package main import ( - "fmt" . "./example" + "fmt" ) func main() { diff --git a/Examples/go/simple/runme.go b/Examples/go/simple/runme.go index c829ad21a..9eb0ff454 100644 --- a/Examples/go/simple/runme.go +++ b/Examples/go/simple/runme.go @@ -1,8 +1,8 @@ package main import ( - "fmt" "./example" + "fmt" ) func main() { diff --git a/Examples/go/template/runme.go b/Examples/go/template/runme.go index 8b3d4000e..fca2f1b75 100644 --- a/Examples/go/template/runme.go +++ b/Examples/go/template/runme.go @@ -3,8 +3,8 @@ package main import ( - "fmt" . "./example" + "fmt" ) func main() { diff --git a/Examples/go/variables/runme.go b/Examples/go/variables/runme.go index 26cad4b3c..3d9737f5c 100644 --- a/Examples/go/variables/runme.go +++ b/Examples/go/variables/runme.go @@ -3,8 +3,8 @@ package main import ( - "fmt" "./example" + "fmt" ) func main() { diff --git a/Examples/test-suite/go/constover_runme.go b/Examples/test-suite/go/constover_runme.go index e649140a6..f961e01b5 100644 --- a/Examples/test-suite/go/constover_runme.go +++ b/Examples/test-suite/go/constover_runme.go @@ -1,9 +1,9 @@ package main import ( + "./constover" "fmt" "os" - "./constover" ) func main() { diff --git a/Examples/test-suite/go/template_typedef_cplx3_runme.go b/Examples/test-suite/go/template_typedef_cplx3_runme.go index f827d7a1e..d616777e0 100644 --- a/Examples/test-suite/go/template_typedef_cplx3_runme.go +++ b/Examples/test-suite/go/template_typedef_cplx3_runme.go @@ -5,7 +5,6 @@ import . "./template_typedef_cplx3" func main() { // this is OK - s := NewSin() s.Get_base_value() s.Get_value() diff --git a/Examples/test-suite/go/template_typedef_cplx4_runme.go b/Examples/test-suite/go/template_typedef_cplx4_runme.go index 9021cf135..3e536d6f2 100644 --- a/Examples/test-suite/go/template_typedef_cplx4_runme.go +++ b/Examples/test-suite/go/template_typedef_cplx4_runme.go @@ -5,7 +5,6 @@ import . "./template_typedef_cplx4" func main() { // this is OK - s := NewSin() s.Get_base_value() s.Get_value() diff --git a/Examples/test-suite/go/template_typedef_import_runme.go b/Examples/test-suite/go/template_typedef_import_runme.go index 8528b9a93..f1c00ff13 100644 --- a/Examples/test-suite/go/template_typedef_import_runme.go +++ b/Examples/test-suite/go/template_typedef_import_runme.go @@ -6,7 +6,6 @@ import "template_typedef_import" func main() { // this is OK - s := template_typedef_import.NewSin() s.Get_base_value() s.Get_value() From c8a879303c8f044036b951ebbc2cc7e956126732 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 2 Jul 2013 12:29:28 +1200 Subject: [PATCH 0671/1160] Fix comment typo (interpeters) --- Lib/swiginit.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/swiginit.swg b/Lib/swiginit.swg index f747bccdf..6fe58d296 100644 --- a/Lib/swiginit.swg +++ b/Lib/swiginit.swg @@ -94,7 +94,7 @@ SWIG_InitializeModule(void *clientdata) { module_head->next = &swig_module; } - /* When multiple interpeters are used, a module could have already been initialized in + /* When multiple interpreters are used, a module could have already been initialized in a different interpreter, but not yet have a pointer in this interpreter. In this case, we do not want to continue adding types... everything should be set up already */ From d3252bbf7fcdf326e286a2ed64d5106b61d80d19 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 2 Jul 2013 13:22:35 +1200 Subject: [PATCH 0672/1160] Fix comment typo --- Source/DOH/fio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/DOH/fio.c b/Source/DOH/fio.c index 5693deeb5..d2a1bab19 100644 --- a/Source/DOH/fio.c +++ b/Source/DOH/fio.c @@ -21,7 +21,7 @@ static DOH *encodings = 0; /* Encoding hash */ /* ----------------------------------------------------------------------------- * Writen() * - * Write's N characters of output and retries until all characters are + * Writes N characters of output and retries until all characters are * written. This is useful should a write operation encounter a spurious signal. * ----------------------------------------------------------------------------- */ From ace8fcd97248dccc7bbd3b94185a49142320eda0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 2 Jul 2013 18:47:00 +0100 Subject: [PATCH 0673/1160] SWIG_AsWCharPtrAndSize improper operation if cptr NULL SF bug #1327 This doesn't have any noticeable effect with the usage of SWIG_AsWCharPtrAndSize as shipped by SWIG, but could be a problem if a user is using this function with cptr equal to zero and psize is non-zero - the length would be incorrectly set due to the call to PyUnicode_GetSize failing. --- Examples/test-suite/li_std_wstring.i | 8 ++++++++ Examples/test-suite/python/li_std_wstring_runme.py | 6 ++++++ Lib/python/pywstrings.swg | 4 +--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/li_std_wstring.i b/Examples/test-suite/li_std_wstring.i index c809e11ec..e0ecde53b 100644 --- a/Examples/test-suite/li_std_wstring.i +++ b/Examples/test-suite/li_std_wstring.i @@ -38,6 +38,14 @@ wchar_t* test_cvalue(wchar_t* x) { } +wchar_t* test_wchar_overload() { + return 0; +} + +wchar_t* test_wchar_overload(wchar_t *x) { + return x; +} + std::wstring test_value(std::wstring x) { return x; } diff --git a/Examples/test-suite/python/li_std_wstring_runme.py b/Examples/test-suite/python/li_std_wstring_runme.py index a2d419a0a..fecc527e0 100644 --- a/Examples/test-suite/python/li_std_wstring_runme.py +++ b/Examples/test-suite/python/li_std_wstring_runme.py @@ -13,6 +13,12 @@ if li_std_wstring.test_ccvalue(x) != x: if li_std_wstring.test_cvalue(x) != x: raise RuntimeError("bad string mapping") +if li_std_wstring.test_wchar_overload(x) != x: + raise RuntimeError("bad string mapping") + +if li_std_wstring.test_wchar_overload("not unicode") != "not unicode": + raise RuntimeError("bad string mapping") + if li_std_wstring.test_value(x) != x: print x, li_std_wstring.test_value(x) raise RuntimeError("bad string mapping") diff --git a/Lib/python/pywstrings.swg b/Lib/python/pywstrings.swg index 619bdd555..864376b01 100644 --- a/Lib/python/pywstrings.swg +++ b/Lib/python/pywstrings.swg @@ -18,9 +18,7 @@ SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize, int *alloc) int isunicode = PyUnicode_Check(obj); %#if PY_VERSION_HEX < 0x03000000 if (!isunicode && PyString_Check(obj)) { - if (cptr) { - obj = tmp = PyUnicode_FromObject(obj); - } + obj = tmp = PyUnicode_FromObject(obj); isunicode = 1; } %#endif From 1c440787510698aa71c39cfa8042899dcbecdc96 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 2 Jul 2013 20:00:17 +0100 Subject: [PATCH 0674/1160] Improve testing of %pythonprepend and %pythonappend --- .../test-suite/python/python_append_runme.py | 7 +++++++ Examples/test-suite/python_append.i | 19 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/python/python_append_runme.py b/Examples/test-suite/python/python_append_runme.py index c8e6b2640..41cebad58 100644 --- a/Examples/test-suite/python/python_append_runme.py +++ b/Examples/test-suite/python/python_append_runme.py @@ -2,3 +2,10 @@ from python_append import * t=Test() t.func() t.static_func() + +if grabpath() != os.path.dirname(mypath): + raise RuntimeError + +if grabstaticpath() != os.path.basename(mypath): + raise RuntimeError + diff --git a/Examples/test-suite/python_append.i b/Examples/test-suite/python_append.i index 2dc9cb970..82d1012ef 100644 --- a/Examples/test-suite/python_append.i +++ b/Examples/test-suite/python_append.i @@ -4,19 +4,34 @@ Testcase to test %pythonprepend and %pythonappend %module python_append +%pythoncode %{ + import os.path + mypath = os.path.dirname("/a/b/c/d.txt") + funcpath = None + staticfuncpath = None + def grabpath(): + return funcpath + def grabstaticpath(): + return staticfuncpath +%} + %pythonappend Test::func %{ - pass + funcpath = os.path.dirname(funcpath) %} %pythonprepend Test::func %{ - pass + global funcpath + funcpath = mypath %} %pythonappend Test::static_func %{ +staticfuncpath = os.path.basename(staticfuncpath) pass %} %pythonprepend Test::static_func { + global staticfuncpath + staticfuncpath = mypath pass } From eb98c0be99a3da4ea860a5068e067459d472a658 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 5 Jul 2013 06:25:07 +0100 Subject: [PATCH 0675/1160] Correct dates in recent commits to CHANGES file --- CHANGES.current | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 3f31ce314..794700632 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,25 +5,25 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.11 (in progress) ============================ -2013-08-01: wsfulton +2013-07-01: wsfulton [Python] Apply SF patch #340 - Uninitialized variable fix in SWIG_Python_NonDynamicSetAttr when using -builtin. -2013-08-01: wsfulton +2013-07-01: wsfulton [Python, Ruby, Ocaml] Apply SF patch #341 - fix a const_cast in generated code that was generating a <:: digraph when using the unary scope operator (::) (global scope) in a template type. -2013-08-01: wsfulton +2013-07-01: wsfulton [Python] Add SF patch #342 from Christian Delbaere to fix some director classes crashing on object deletion when using -builtin. Fixes SF bug #1301. -2013-07-11: wsfulton +2013-06-11: wsfulton [Python] Add SWIG_PYTHON_INTERPRETER_NO_DEBUG macro which can be defined to use the Release version of the Python interpreter in Debug builds of the wrappers. The Visual Studio .dsp example files have been modified to use this so that Debug builds will now work without having to install or build a Debug build of the interpreter. -2013-07-07: wsfulton +2013-06-07: wsfulton [Ruby] Git issue #52. Fix regression with missing rb_complex_new function for Ruby versions prior to 1.9 using std::complex wrappers if just using std::complex as an output type. Also fix the Complex helper functions external visibility (to static by default). From d0af4f50d301cd971e7dadf1e48a5b5c8c66e4b4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 5 Jul 2013 06:30:16 +0100 Subject: [PATCH 0676/1160] Add %pythonbegin directive. For adding code at the beginning of the generated .py file. --- CHANGES.current | 10 ++++++ Doc/Manual/Python.html | 47 +++++++++++++++++++++++++++++ Examples/test-suite/python_append.i | 7 +++-- Lib/python/pyuserdir.swg | 1 + Source/Modules/python.cxx | 9 +++++- 5 files changed, 71 insertions(+), 3 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 794700632..c07420a00 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,16 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.11 (in progress) ============================ +2013-07-05: wsfulton + [Python] Add %pythonbegin directive which works like %pythoncode, except the specified code is + added at the beginning of the generated .py file. This is primarily needed for importing from + __future__ statements required to be at the very beginning of the file. Example: + + %pythonbegin %{ + from __future__ import print_function + print("Loading", "Whizz", "Bang", sep=' ... ') + %} + 2013-07-01: wsfulton [Python] Apply SF patch #340 - Uninitialized variable fix in SWIG_Python_NonDynamicSetAttr when using -builtin. diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 3dde20887..6a22738bc 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -3314,6 +3314,53 @@ what can be done without having to rely on any of the more advanced customization features.

    +

    +There is also %pythonbegin which is another directive very similar to %pythoncode, +but generates the given Python code at the beginning of the .py file. +This directive works in the same way as %pythoncode, except the code is copied +just after the SWIG banner (comment) at the top of the file, before any real code. +This provides an opportunity to add your own description in a comment near the top of the file as well +as Python imports that have to appear at the top of the file, such as "from __future__ import" +statements. +

    + +

    +The following shows example usage for Python 2.6 to use print as it can in Python 3, that is, as a function instead of a statement: +

    + +
    +
    +%pythonbegin %{
    +# This module provides wrappers to the Whizz Bang library
    +%}
    +
    +%pythonbegin %{
    +from __future__ import print_function
    +print("Loading", "Whizz", "Bang", sep=' ... ')
    +%}
    +
    +
    + +

    +which can be seen when viewing the first few lines of the generated .py file: +

    + +
    +
    +# This file was automatically generated by SWIG (http://www.swig.org).
    +# Version 2.0.11
    +#
    +# Do not make changes to this file unless you know what you are doing--modify
    +# the SWIG interface file instead.
    +
    +# This module provides wrappers to the Whizz Bang library
    +
    +from __future__ import print_function
    +print("Loading", "Whizz", "Bang", sep=' ... ')
    +
    +
    +
    +

    Sometimes you may want to replace or modify the wrapper function that SWIG creates in the proxy .py file. The Python module in SWIG provides some features that enable you to do this. First, to diff --git a/Examples/test-suite/python_append.i b/Examples/test-suite/python_append.i index 82d1012ef..e263c392b 100644 --- a/Examples/test-suite/python_append.i +++ b/Examples/test-suite/python_append.i @@ -1,11 +1,10 @@ /* -Testcase to test %pythonprepend and %pythonappend +Testcase to test %pythonprepend and %pythonappend %pythoncode %pythonbegin */ %module python_append %pythoncode %{ - import os.path mypath = os.path.dirname("/a/b/c/d.txt") funcpath = None staticfuncpath = None @@ -35,6 +34,10 @@ pass pass } +%pythonbegin %{ +import os.path +%} + %inline %{ class Test { diff --git a/Lib/python/pyuserdir.swg b/Lib/python/pyuserdir.swg index 5247ee65b..d3c3eb188 100644 --- a/Lib/python/pyuserdir.swg +++ b/Lib/python/pyuserdir.swg @@ -7,6 +7,7 @@ /* shadow code */ #define %shadow %insert("shadow") #define %pythoncode %insert("python") +#define %pythonbegin %insert("pythonbegin") /* ------------------------------------------------------------------------- */ diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 814626a0c..7ee4ae225 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -42,6 +42,7 @@ static File *f_directors_h = 0; static File *f_init = 0; static File *f_shadow_py = 0; static String *f_shadow = 0; +static String *f_shadow_begin = 0; static Hash *f_shadow_imports = 0; static String *f_shadow_builtin_imports = 0; static String *f_shadow_stubs = 0; @@ -784,6 +785,7 @@ public: filen = NULL; f_shadow = NewString(""); + f_shadow_begin = NewString(""); f_shadow_imports = NewHash(); f_shadow_builtin_imports = NewString(""); f_shadow_stubs = NewString(""); @@ -977,6 +979,7 @@ public: if (!modern) { Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL); } + Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL); Printv(f_shadow_py, "\n", f_shadow_builtin_imports, "\n", NIL); Printv(f_shadow_py, f_shadow, "\n", NIL); Printv(f_shadow_py, f_shadow_stubs, "\n", NIL); @@ -4451,12 +4454,16 @@ public: String *code = Getattr(n, "code"); String *section = Getattr(n, "section"); - if ((!ImportMode) && ((Cmp(section, "python") == 0) || (Cmp(section, "shadow") == 0))) { + if (!ImportMode && (Cmp(section, "python") == 0 || Cmp(section, "shadow") == 0)) { if (shadow) { String *pycode = pythoncode(code, shadow_indent); Printv(f_shadow, pycode, NIL); Delete(pycode); } + } else if (!ImportMode && (Cmp(section, "pythonbegin") == 0)) { + String *pycode = pythoncode(code, ""); + Printv(f_shadow_begin, pycode, NIL); + Delete(pycode); } else { Language::insertDirective(n); } From 93b63969f9b70895ee1d841c66f414b1be46e90d Mon Sep 17 00:00:00 2001 From: joequant Date: Sun, 14 Jul 2013 20:28:17 +0800 Subject: [PATCH 0677/1160] change to allow file SEXP return values --- CHANGES.current | 2 ++ Lib/r/rtype.swg | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index c07420a00..1e385ce29 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,8 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.11 (in progress) ============================ +2013-07-14: joequant + [R] Change types file to allow for SEXP return values 2013-07-05: wsfulton [Python] Add %pythonbegin directive which works like %pythoncode, except the specified code is diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg index b4571af46..b86a618d9 100644 --- a/Lib/r/rtype.swg +++ b/Lib/r/rtype.swg @@ -151,6 +151,8 @@ string &, std::string & #%typemap(scoerceout) SWIGTYPE *const # %{ class($result) <- "$R_class"; %} + %typemap(scoerceout) SEXP %{ %} + %typemap(scoerceout) SWIGTYPE %{ $result <- new("$&R_class", ref=$result); %} From e8c6384f77b05514f26338fae463860b865ddf97 Mon Sep 17 00:00:00 2001 From: joequant Date: Sun, 14 Jul 2013 20:29:37 +0800 Subject: [PATCH 0678/1160] add regression tests for SEXP return values --- Examples/test-suite/r/Makefile.in | 3 ++- Examples/test-suite/r/r_sexp_runme.R | 7 +++++++ Examples/test-suite/r_sexp.i | 10 ++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/r/r_sexp_runme.R create mode 100644 Examples/test-suite/r_sexp.i diff --git a/Examples/test-suite/r/Makefile.in b/Examples/test-suite/r/Makefile.in index bece71c2f..18e2d4b25 100644 --- a/Examples/test-suite/r/Makefile.in +++ b/Examples/test-suite/r/Makefile.in @@ -16,7 +16,8 @@ C_TEST_CASES += \ CPP_TEST_CASES += \ r_double_delete \ - r_overload_array + r_overload_array \ + r_sexp include $(srcdir)/../common.mk diff --git a/Examples/test-suite/r/r_sexp_runme.R b/Examples/test-suite/r/r_sexp_runme.R new file mode 100644 index 000000000..96b36e8af --- /dev/null +++ b/Examples/test-suite/r/r_sexp_runme.R @@ -0,0 +1,7 @@ +source("unittest.R") +dyn.load(paste("r_sexp", .Platform$dynlib.ext, sep="")) +source("r_sexp.R") +cacheMetaData(1) + +obj <- return_sexp(1); +unittest(obj, 1) diff --git a/Examples/test-suite/r_sexp.i b/Examples/test-suite/r_sexp.i new file mode 100644 index 000000000..9f786f428 --- /dev/null +++ b/Examples/test-suite/r_sexp.i @@ -0,0 +1,10 @@ +%module r_sexp + +extern "C" SEXP return_sexp(SEXP x); + +%inline %{ +SEXP return_sexp(SEXP x) { + return x; //Rcpp NumericVector is automatically casted to SEXP +} +%} + From 479df82616be2a7f08cd4df68c2c7b51073d9e2b Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Fri, 5 Jul 2013 22:37:15 +0200 Subject: [PATCH 0679/1160] Octave: more robust configuration - do not rely on --eval argument to find mkoctfile, instead assume it is in the same directory as octave itself (which it always should be) - check Octave options to make sure they are supported, including --no-window-system to prevent warnings if building without an X server - disable Octave if any vital tests fail --- Examples/Makefile.in | 2 +- Examples/test-suite/octave/Makefile.in | 2 +- configure.ac | 38 ++++++++++++++++++-------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 280923df2..df754427c 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -398,7 +398,7 @@ python_clean: ################################################################## # Make sure these locate your Octave installation -OCTAVE = OCTAVE_HISTFILE=/dev/null @OCTAVE@ -qfH +OCTAVE = OCTAVE_HISTFILE=/dev/null @OCTAVE@ OCTAVE_CXX = $(DEFS) @OCTAVE_CPPFLAGS@ @OCTAVE_CXXFLAGS@ # Extra Octave specific dynamic linking options diff --git a/Examples/test-suite/octave/Makefile.in b/Examples/test-suite/octave/Makefile.in index 88f533fd1..fe957eeb0 100644 --- a/Examples/test-suite/octave/Makefile.in +++ b/Examples/test-suite/octave/Makefile.in @@ -3,7 +3,7 @@ ####################################################################### LANGUAGE = octave -OCTAVE = @OCTAVE@ -qf +OCTAVE = @OCTAVE@ SCRIPTSUFFIX = _runme.m srcdir = @srcdir@ top_srcdir = @top_srcdir@ diff --git a/configure.ac b/configure.ac index 616610eda..1d3250afb 100644 --- a/configure.ac +++ b/configure.ac @@ -938,7 +938,7 @@ if test x"${OCTAVEBIN}" = xno -o x"${with_alllang}" = xno ; then # First figure out what the name of Octave is elif test "x$OCTAVEBIN" = xyes; then - AC_CHECK_PROGS(OCTAVE, octave) + AC_PATH_PROG(OCTAVE, [octave]) else OCTAVE="$OCTAVEBIN" @@ -946,31 +946,45 @@ fi if test -n "$OCTAVE"; then AC_MSG_CHECKING([for mkoctfile]) - AS_IF([test "x`${OCTAVE} -qfH --eval 'mkoctfile -p CXX' 2>/dev/null`" != x],[ - AC_MSG_RESULT([yes]) + mkoctfile="`dirname ${OCTAVE}`/mkoctfile" + AS_IF([test -x "${mkoctfile}"],[ + AC_MSG_RESULT([${mkoctfile}]) ],[ - AC_MSG_ERROR([mkoctfile is not installed]) + AC_MSG_RESULT([not found, disabling Octave]) + OCTAVE= ]) +fi +if test -n "$OCTAVE"; then AC_MSG_CHECKING([for Octave preprocessor flags]) OCTAVE_CPPFLAGS= for n in CPPFLAGS INCFLAGS; do - OCTAVE_CPPFLAGS="${OCTAVE_CPPFLAGS} "`$OCTAVE -qfH --eval "mkoctfile -p $n"` + OCTAVE_CPPFLAGS="${OCTAVE_CPPFLAGS} "`${mkoctfile} -p $n` done - AC_MSG_RESULT($OCTAVE_CPPFLAGS) + AC_MSG_RESULT([$OCTAVE_CPPFLAGS]) AC_MSG_CHECKING([for Octave compiler flags]) OCTAVE_CXXFLAGS= for n in ALL_CXXFLAGS; do - OCTAVE_CXXFLAGS="${OCTAVE_CXXFLAGS} "`$OCTAVE -qfH --eval "mkoctfile -p $n"` + OCTAVE_CXXFLAGS="${OCTAVE_CXXFLAGS} "`${mkoctfile} -p $n` done - AC_MSG_RESULT($OCTAVE_CXXFLAGS) + AC_MSG_RESULT([$OCTAVE_CXXFLAGS]) AC_MSG_CHECKING([for Octave linker flags]) OCTAVE_LDFLAGS= for n in RDYNAMIC_FLAG LFLAGS RLD_FLAG OCTAVE_LIBS LIBS; do - OCTAVE_LDFLAGS="${OCTAVE_LDFLAGS} "`$OCTAVE -qfH --eval "mkoctfile -p $n"` + OCTAVE_LDFLAGS="${OCTAVE_LDFLAGS} "`${mkoctfile} -p $n` + done + AC_MSG_RESULT([$OCTAVE_LDFLAGS]) +fi +if test -n "$OCTAVE"; then + for octave_opt in --silent --norc --no-history --no-window-system; do + AC_MSG_CHECKING([if Octave option '${octave_opt}' is supported]) + ${OCTAVE} ${octave_opt} /dev/null >/dev/null 2>&1 + AS_IF([test $? -eq 0],[ + AC_MSG_RESULT([yes]) + OCTAVE="${OCTAVE} ${octave_opt}" + ],[ + AC_MSG_RESULT([no]) + ]) done - AC_MSG_RESULT($OCTAVE_LDFLAGS) -else - AC_MSG_RESULT(could not figure out how to run octave) fi AC_SUBST(OCTAVE) From b28de208697701ec39629a14f23acf37125568e2 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Tue, 16 Jul 2013 14:18:16 +0200 Subject: [PATCH 0680/1160] Octave: fixups to previous configuration patch - remove unneeded test -n "$OCTAVE" - do not rely on Octave returning non-zero status for unrecognised option; search first line of output for 'unrecognized' instead --- configure.ac | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 1d3250afb..ee16ff16e 100644 --- a/configure.ac +++ b/configure.ac @@ -973,12 +973,10 @@ if test -n "$OCTAVE"; then OCTAVE_LDFLAGS="${OCTAVE_LDFLAGS} "`${mkoctfile} -p $n` done AC_MSG_RESULT([$OCTAVE_LDFLAGS]) -fi -if test -n "$OCTAVE"; then for octave_opt in --silent --norc --no-history --no-window-system; do AC_MSG_CHECKING([if Octave option '${octave_opt}' is supported]) - ${OCTAVE} ${octave_opt} /dev/null >/dev/null 2>&1 - AS_IF([test $? -eq 0],[ + octave_out=`${OCTAVE} ${octave_opt} /dev/null 2>&1 | sed -n '1{/unrecognized/p}'` + AS_IF([test "x${octave_out}" != x],[ AC_MSG_RESULT([yes]) OCTAVE="${OCTAVE} ${octave_opt}" ],[ From 83178a1fe40844c2438bcad871c6cf510bf9c03e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 16 Jul 2013 23:05:59 +0100 Subject: [PATCH 0681/1160] Correction for detecting invalid Octave options --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index ee16ff16e..cc4270ad7 100644 --- a/configure.ac +++ b/configure.ac @@ -976,7 +976,7 @@ if test -n "$OCTAVE"; then for octave_opt in --silent --norc --no-history --no-window-system; do AC_MSG_CHECKING([if Octave option '${octave_opt}' is supported]) octave_out=`${OCTAVE} ${octave_opt} /dev/null 2>&1 | sed -n '1{/unrecognized/p}'` - AS_IF([test "x${octave_out}" != x],[ + AS_IF([test "x${octave_out}" = x],[ AC_MSG_RESULT([yes]) OCTAVE="${OCTAVE} ${octave_opt}" ],[ From 5f1fff1849285f46cfaffadff0352cf976ea4c52 Mon Sep 17 00:00:00 2001 From: Andrew Simmons Date: Mon, 8 Jul 2013 17:29:24 -0500 Subject: [PATCH 0682/1160] Copied std::pair<> fragment from Lib/std/std_map.i into Lib/std/std_multimap.i. This fixes an error when a std::multimap template is wrapped by itself. --- Lib/std/std_multimap.i | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Lib/std/std_multimap.i b/Lib/std/std_multimap.i index f165e5f33..5a2cf38d7 100644 --- a/Lib/std/std_multimap.i +++ b/Lib/std/std_multimap.i @@ -60,6 +60,20 @@ namespace std { %traits_swigtype(_Key); %traits_swigtype(_Tp); + %fragment(SWIG_Traits_frag(std::pair< _Key, _Tp >), "header", + fragment=SWIG_Traits_frag(_Key), + fragment=SWIG_Traits_frag(_Tp), + fragment="StdPairTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::pair<" #_Key "," #_Tp " >"; + } + }; + } + } + %fragment(SWIG_Traits_frag(std::multimap<_Key, _Tp, _Compare, _Alloc >), "header", fragment=SWIG_Traits_frag(std::pair<_Key, _Tp >), fragment="StdMultimapTraits") { From 80f8d1d9225b5fcb66b774e8859637f14e11afd8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 30 Jul 2013 07:34:39 +0100 Subject: [PATCH 0683/1160] Fix for missing C++ code in std::multimap wrappers. %template for a std::multimap generated uncompilable code unless a %template for a std::map of the same template types was also coded up. This patch is needed in conjunction with previous commit - 5f1fff1849285f46cfaffadff0352cf976ea4c52 Closes #64 Closes #65 --- CHANGES.current | 5 + Examples/test-suite/li_std_multimap.i | 2 - Lib/octave/std_map.i | 135 ++++++++++++------------ Lib/python/std_map.i | 142 +++++++++++++------------- Lib/python/std_multimap.i | 2 +- Lib/ruby/std_map.i | 123 +++++++++++----------- Lib/ruby/std_multimap.i | 2 +- 7 files changed, 214 insertions(+), 197 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 1e385ce29..b03e05ffc 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.11 (in progress) ============================ +2013-07-30: wsfulton + [Python, Ruby] Fix #64 #65: Missing code in std::multimap wrappers. Previously an instantiation + of a std::map was erroneously required in addition to an instantiation of std::multimap with the + same template parameters to prevent compilation errors for the wrappers of a std::multimap. + 2013-07-14: joequant [R] Change types file to allow for SEXP return values diff --git a/Examples/test-suite/li_std_multimap.i b/Examples/test-suite/li_std_multimap.i index a29417919..bd087d361 100644 --- a/Examples/test-suite/li_std_multimap.i +++ b/Examples/test-suite/li_std_multimap.i @@ -3,7 +3,6 @@ %feature("trackobjects"); %include std_pair.i -%include std_map.i %include std_multimap.i %inline %{ @@ -20,6 +19,5 @@ struct A{ namespace std { %template(pairA) pair; - %template(mapA) map; %template(multimapA) multimap; } diff --git a/Lib/octave/std_map.i b/Lib/octave/std_map.i index 6c476ce53..7b85a548e 100644 --- a/Lib/octave/std_map.i +++ b/Lib/octave/std_map.i @@ -2,73 +2,9 @@ %include -%fragment("StdMapTraits","header",fragment="StdSequenceTraits") +%fragment("StdMapCommonTraits","header",fragment="StdSequenceTraits") { namespace swig { - template - inline void - assign(const OctSeq& octseq, std::map *map) { - typedef typename std::map::value_type value_type; - typename OctSeq::const_iterator it = octseq.begin(); - for (;it != octseq.end(); ++it) { - map->insert(value_type(it->first, it->second)); - } - } - - template - struct traits_asptr > { - typedef std::map map_type; - static int asptr(octave_value obj, map_type **val) { - /* - int res = SWIG_ERROR; - if (PyDict_Check(obj)) { - SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL); - res = traits_asptr_stdseq, std::pair >::asptr(items, val); - } else { - map_type *p; - res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info(),0); - if (SWIG_IsOK(res) && val) *val = p; - } - return res; - */ - return SWIG_ERROR; - } - }; - - template - struct traits_from > { - typedef std::map map_type; - typedef typename map_type::const_iterator const_iterator; - typedef typename map_type::size_type size_type; - - static octave_value from(const map_type& map) { - /* - swig_type_info *desc = swig::type_info(); - if (desc && desc->clientdata) { - return SWIG_NewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN); - } else { - size_type size = map.size(); - int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1; - if (pysize < 0) { - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetString(PyExc_OverflowError, - "map size not valid in python"); - SWIG_PYTHON_THREAD_END_BLOCK; - return NULL; - } - PyObject *obj = PyDict_New(); - for (const_iterator i= map.begin(); i!= map.end(); ++i) { - swig::SwigVar_PyObject key = swig::from(i->first); - swig::SwigVar_PyObject val = swig::from(i->second); - PyDict_SetItem(obj, key, val); - } - return obj; - } - */ - return octave_value(); - } - }; - template struct from_key_oper { @@ -138,6 +74,75 @@ } } +%fragment("StdMapTraits","header",fragment="StdMapCommonTraits") +{ + namespace swig { + template + inline void + assign(const OctSeq& octseq, std::map *map) { + typedef typename std::map::value_type value_type; + typename OctSeq::const_iterator it = octseq.begin(); + for (;it != octseq.end(); ++it) { + map->insert(value_type(it->first, it->second)); + } + } + + template + struct traits_asptr > { + typedef std::map map_type; + static int asptr(octave_value obj, map_type **val) { + /* + int res = SWIG_ERROR; + if (PyDict_Check(obj)) { + SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL); + res = traits_asptr_stdseq, std::pair >::asptr(items, val); + } else { + map_type *p; + res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info(),0); + if (SWIG_IsOK(res) && val) *val = p; + } + return res; + */ + return SWIG_ERROR; + } + }; + + template + struct traits_from > { + typedef std::map map_type; + typedef typename map_type::const_iterator const_iterator; + typedef typename map_type::size_type size_type; + + static octave_value from(const map_type& map) { + /* + swig_type_info *desc = swig::type_info(); + if (desc && desc->clientdata) { + return SWIG_NewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN); + } else { + size_type size = map.size(); + int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1; + if (pysize < 0) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(PyExc_OverflowError, + "map size not valid in python"); + SWIG_PYTHON_THREAD_END_BLOCK; + return NULL; + } + PyObject *obj = PyDict_New(); + for (const_iterator i= map.begin(); i!= map.end(); ++i) { + swig::SwigVar_PyObject key = swig::from(i->first); + swig::SwigVar_PyObject val = swig::from(i->second); + PyDict_SetItem(obj, key, val); + } + return obj; + } + */ + return octave_value(); + } + }; + } +} + %define %swig_map_common(Map...) %swig_sequence_iterator(Map); %swig_container_methods(Map); diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i index 37d749790..66ed68da5 100644 --- a/Lib/python/std_map.i +++ b/Lib/python/std_map.i @@ -2,7 +2,79 @@ Maps */ -%fragment("StdMapTraits","header",fragment="StdSequenceTraits") +%fragment("StdMapCommonTraits","header",fragment="StdSequenceTraits") +{ + namespace swig { + template + struct from_key_oper + { + typedef const ValueType& argument_type; + typedef PyObject *result_type; + result_type operator()(argument_type v) const + { + return swig::from(v.first); + } + }; + + template + struct from_value_oper + { + typedef const ValueType& argument_type; + typedef PyObject *result_type; + result_type operator()(argument_type v) const + { + return swig::from(v.second); + } + }; + + template + struct SwigPyMapIterator_T : SwigPyIteratorClosed_T + { + SwigPyMapIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) + : SwigPyIteratorClosed_T(curr, first, last, seq) + { + } + }; + + + template > + struct SwigPyMapKeyIterator_T : SwigPyMapIterator_T + { + SwigPyMapKeyIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) + : SwigPyMapIterator_T(curr, first, last, seq) + { + } + }; + + template + inline SwigPyIterator* + make_output_key_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0) + { + return new SwigPyMapKeyIterator_T(current, begin, end, seq); + } + + template > + struct SwigPyMapValueITerator_T : SwigPyMapIterator_T + { + SwigPyMapValueITerator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) + : SwigPyMapIterator_T(curr, first, last, seq) + { + } + }; + + + template + inline SwigPyIterator* + make_output_value_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0) + { + return new SwigPyMapValueITerator_T(current, begin, end, seq); + } + } +} + +%fragment("StdMapTraits","header",fragment="StdMapCommonTraits") { namespace swig { template @@ -73,74 +145,6 @@ } } }; - - template - struct from_key_oper - { - typedef const ValueType& argument_type; - typedef PyObject *result_type; - result_type operator()(argument_type v) const - { - return swig::from(v.first); - } - }; - - template - struct from_value_oper - { - typedef const ValueType& argument_type; - typedef PyObject *result_type; - result_type operator()(argument_type v) const - { - return swig::from(v.second); - } - }; - - template - struct SwigPyMapIterator_T : SwigPyIteratorClosed_T - { - SwigPyMapIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) - : SwigPyIteratorClosed_T(curr, first, last, seq) - { - } - }; - - - template > - struct SwigPyMapKeyIterator_T : SwigPyMapIterator_T - { - SwigPyMapKeyIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) - : SwigPyMapIterator_T(curr, first, last, seq) - { - } - }; - - template - inline SwigPyIterator* - make_output_key_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0) - { - return new SwigPyMapKeyIterator_T(current, begin, end, seq); - } - - template > - struct SwigPyMapValueITerator_T : SwigPyMapIterator_T - { - SwigPyMapValueITerator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) - : SwigPyMapIterator_T(curr, first, last, seq) - { - } - }; - - - template - inline SwigPyIterator* - make_output_value_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0) - { - return new SwigPyMapValueITerator_T(current, begin, end, seq); - } - } } diff --git a/Lib/python/std_multimap.i b/Lib/python/std_multimap.i index 8a240ae10..c81e2ac5d 100644 --- a/Lib/python/std_multimap.i +++ b/Lib/python/std_multimap.i @@ -3,7 +3,7 @@ */ %include -%fragment("StdMultimapTraits","header",fragment="StdSequenceTraits") +%fragment("StdMultimapTraits","header",fragment="StdMapCommonTraits") { namespace swig { template diff --git a/Lib/ruby/std_map.i b/Lib/ruby/std_map.i index e23f1c31b..f706ca873 100644 --- a/Lib/ruby/std_map.i +++ b/Lib/ruby/std_map.i @@ -1,67 +1,9 @@ // // Maps // -%fragment("StdMapTraits","header",fragment="StdSequenceTraits") +%fragment("StdMapCommonTraits","header",fragment="StdSequenceTraits") { namespace swig { - template - inline void - assign(const RubySeq& rubyseq, std::map *map) { - typedef typename std::map::value_type value_type; - typename RubySeq::const_iterator it = rubyseq.begin(); - for (;it != rubyseq.end(); ++it) { - map->insert(value_type(it->first, it->second)); - } - } - - template - struct traits_asptr > { - typedef std::map map_type; - static int asptr(VALUE obj, map_type **val) { - int res = SWIG_ERROR; - if ( TYPE(obj) == T_HASH ) { - static ID id_to_a = rb_intern("to_a"); - VALUE items = rb_funcall(obj, id_to_a, 0); - res = traits_asptr_stdseq, std::pair >::asptr(items, val); - } else { - map_type *p; - res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info(),0); - if (SWIG_IsOK(res) && val) *val = p; - } - return res; - } - }; - - template - struct traits_from > { - typedef std::map map_type; - typedef typename map_type::const_iterator const_iterator; - typedef typename map_type::size_type size_type; - - static VALUE from(const map_type& map) { - swig_type_info *desc = swig::type_info(); - if (desc && desc->clientdata) { - return SWIG_NewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN); - } else { - size_type size = map.size(); - int rubysize = (size <= (size_type) INT_MAX) ? (int) size : -1; - if (rubysize < 0) { - SWIG_RUBY_THREAD_BEGIN_BLOCK; - rb_raise( rb_eRuntimeError, "map size not valid in Ruby"); - SWIG_RUBY_THREAD_END_BLOCK; - return Qnil; - } - VALUE obj = rb_hash_new(); - for (const_iterator i= map.begin(); i!= map.end(); ++i) { - VALUE key = swig::from(i->first); - VALUE val = swig::from(i->second); - rb_hash_aset(obj, key, val); - } - return obj; - } - } - }; - template struct from_key_oper { @@ -134,6 +76,69 @@ } } +%fragment("StdMapTraits","header",fragment="StdMapCommonTraits") +{ + namespace swig { + template + inline void + assign(const RubySeq& rubyseq, std::map *map) { + typedef typename std::map::value_type value_type; + typename RubySeq::const_iterator it = rubyseq.begin(); + for (;it != rubyseq.end(); ++it) { + map->insert(value_type(it->first, it->second)); + } + } + + template + struct traits_asptr > { + typedef std::map map_type; + static int asptr(VALUE obj, map_type **val) { + int res = SWIG_ERROR; + if ( TYPE(obj) == T_HASH ) { + static ID id_to_a = rb_intern("to_a"); + VALUE items = rb_funcall(obj, id_to_a, 0); + res = traits_asptr_stdseq, std::pair >::asptr(items, val); + } else { + map_type *p; + res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info(),0); + if (SWIG_IsOK(res) && val) *val = p; + } + return res; + } + }; + + template + struct traits_from > { + typedef std::map map_type; + typedef typename map_type::const_iterator const_iterator; + typedef typename map_type::size_type size_type; + + static VALUE from(const map_type& map) { + swig_type_info *desc = swig::type_info(); + if (desc && desc->clientdata) { + return SWIG_NewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN); + } else { + size_type size = map.size(); + int rubysize = (size <= (size_type) INT_MAX) ? (int) size : -1; + if (rubysize < 0) { + SWIG_RUBY_THREAD_BEGIN_BLOCK; + rb_raise( rb_eRuntimeError, "map size not valid in Ruby"); + SWIG_RUBY_THREAD_END_BLOCK; + return Qnil; + } + VALUE obj = rb_hash_new(); + for (const_iterator i= map.begin(); i!= map.end(); ++i) { + VALUE key = swig::from(i->first); + VALUE val = swig::from(i->second); + rb_hash_aset(obj, key, val); + } + return obj; + } + } + }; + } +} + %define %swig_map_common(Map...) %swig_container_methods(%arg(Map)); // %swig_sequence_iterator(%arg(Map)); diff --git a/Lib/ruby/std_multimap.i b/Lib/ruby/std_multimap.i index 31795c768..3e06ee12c 100644 --- a/Lib/ruby/std_multimap.i +++ b/Lib/ruby/std_multimap.i @@ -3,7 +3,7 @@ */ %include -%fragment("StdMultimapTraits","header",fragment="StdSequenceTraits") +%fragment("StdMultimapTraits","header",fragment="StdMapCommonTraits") { namespace swig { template From a0af86811dc8835a16c71a1ef78c7a4294438326 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 6 Aug 2013 21:16:11 +0100 Subject: [PATCH 0684/1160] Travis builds - add in apt-get update php tests were failing. Travis suggest running this before any install - http://about.travis-ci.org/docs/user/build-configuration/#Installing-Packages-Using-apt --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 13502de0b..26758304f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,6 +35,7 @@ matrix: before_install: - lsb_release -a - uname -a + - sudo apt-get -qq update - time sudo apt-get -qq install libboost-dev - if test "$SWIGLANG" = "csharp"; then sudo apt-get -qq install mono-devel; fi - if test "$SWIGLANG" = "go"; then go env | sed -e 's/^/export /' > goenvsetup && source goenvsetup && rm -f goenvsetup; fi # Until configure.ac is fixed From a495b5a985ca54033cfea6719d4d838c85b9c2aa Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Wed, 7 Aug 2013 19:22:10 +0100 Subject: [PATCH 0685/1160] Remove SwigPyObject_print and SwigPyObject_str, and make the generated wrapper use the default python implementations, which will fall back to repr (for -builtin option). Advantages: - it avoids the swig user having to jump through hoops to get print to work as expected when redefining repr/str slots. - typing the name of a variable on the python prompt now prints the result of a (possibly redefined) repr, without the swig user having to do any extra work. - when redefining repr, the swig user doesn't necessarily have to redefine str as it will call the redefined repr - the behaviour is exactly the same as without the -builtin option while requiring no extra work by the user (aside from adding the %feature("python:slot...) statements of course) - the patch simplifies pyrun.swg a tiny bit. Disadvantage: - default str() will give different (but clearer?) output on swigged classes compared to unpatched swig SF Bug #326 --- CHANGES.current | 19 +++++++++++++++++++ Lib/python/pyname_compat.i | 2 -- Lib/python/pyrun.swg | 32 ++------------------------------ 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index b03e05ffc..cc2ce897d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,25 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.11 (in progress) ============================ + +2013-08-07: wsfulton + [Python] SF Patch #326 from Kris Thielemans - Remove SwigPyObject_print and SwigPyObject_str and + make the generated wrapper use the default python implementations, which will fall back to repr + (for -builtin option). + + Advantages: + - it avoids the swig user having to jump through hoops to get print to work as expected when + redefining repr/str slots. + - typing the name of a variable on the python prompt now prints the result of a (possibly redefined) + repr, without the swig user having to do any extra work. + - when redefining repr, the swig user doesn't necessarily have to redefine str as it will call the + redefined repr + - the behaviour is exactly the same as without the -builtin option while requiring no extra work + by the user (aside from adding the %feature("python:slot...) statements of course) + + Disadvantage: + - default str() will give different (but clearer?) output on swigged classes + 2013-07-30: wsfulton [Python, Ruby] Fix #64 #65: Missing code in std::multimap wrappers. Previously an instantiation of a std::map was erroneously required in addition to an instantiation of std::multimap with the diff --git a/Lib/python/pyname_compat.i b/Lib/python/pyname_compat.i index 4026805ba..96af343ca 100644 --- a/Lib/python/pyname_compat.i +++ b/Lib/python/pyname_compat.i @@ -67,10 +67,8 @@ #define PySwigObject_next SwigPyObject_next #define PySwigObject_oct SwigPyObject_oct #define PySwigObject_own SwigPyObject_own -#define PySwigObject_print SwigPyObject_print #define PySwigObject_repr SwigPyObject_repr #define PySwigObject_richcompare SwigPyObject_richcompare -#define PySwigObject_str SwigPyObject_str #define PySwigObject_type SwigPyObject_type #define PySwigPacked SwigPyPacked #define PySwigPacked_Check SwigPyPacked_Check diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index df87bb317..273c82302 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -448,34 +448,6 @@ SwigPyObject_repr(SwigPyObject *v, PyObject *args) return repr; } -SWIGRUNTIME int -SwigPyObject_print(SwigPyObject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) -{ - char *str; -#ifdef METH_NOARGS - PyObject *repr = SwigPyObject_repr(v); -#else - PyObject *repr = SwigPyObject_repr(v, NULL); -#endif - if (repr) { - str = SWIG_Python_str_AsChar(repr); - fputs(str, fp); - SWIG_Python_str_DelForPy3(str); - Py_DECREF(repr); - return 0; - } else { - return 1; - } -} - -SWIGRUNTIME PyObject * -SwigPyObject_str(SwigPyObject *v) -{ - char result[SWIG_BUFFER_SIZE]; - return SWIG_PackVoidPtr(result, v->ptr, v->ty->name, sizeof(result)) ? - SWIG_Python_str_FromChar(result) : 0; -} - SWIGRUNTIME int SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w) { @@ -761,7 +733,7 @@ SwigPyObject_TypeOnce(void) { sizeof(SwigPyObject), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)SwigPyObject_dealloc, /* tp_dealloc */ - (printfunc)SwigPyObject_print, /* tp_print */ + 0, /* tp_print */ #if PY_VERSION_HEX < 0x02020000 (getattrfunc)SwigPyObject_getattr, /* tp_getattr */ #else @@ -779,7 +751,7 @@ SwigPyObject_TypeOnce(void) { 0, /* tp_as_mapping */ (hashfunc)0, /* tp_hash */ (ternaryfunc)0, /* tp_call */ - (reprfunc)SwigPyObject_str, /* tp_str */ + 0, /* tp_str */ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ From b477cb66be5739a0acc2c2de15e988187971ce40 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 24 Aug 2013 08:34:50 +1200 Subject: [PATCH 0686/1160] Use offsetof() rather than icky homemade equivalent --- Source/Modules/python.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 7ee4ae225..233f79bd6 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -3401,7 +3401,7 @@ public: printSlot(f, getSlot(n, "feature:python:tp_dict"), "tp_dict"); printSlot(f, getSlot(n, "feature:python:tp_descr_get"), "tp_descr_get", "descrgetfunc"); printSlot(f, getSlot(n, "feature:python:tp_descr_set"), "tp_descr_set", "descrsetfunc"); - Printf(f, " (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */\n"); + Printf(f, " offsetof(SwigPyObject, dict), /* tp_dictoffset */\n"); printSlot(f, tp_init, "tp_init", "initproc"); printSlot(f, getSlot(n, "feature:python:tp_alloc"), "tp_alloc", "allocfunc"); printSlot(f, "0", "tp_new", "newfunc"); From 628b4710e5309379475f55c95a42e1cf21c9be87 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 24 Aug 2013 08:40:08 +1200 Subject: [PATCH 0687/1160] [Python] Fix clang++ warning in generated wrapper code. --- CHANGES.current | 3 +++ Source/Modules/python.cxx | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index cc2ce897d..584d5c3a2 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.11 (in progress) ============================ +2013-08-23: olly + [Python] Fix clang++ warning in generated wrapper code. + 2013-08-07: wsfulton [Python] SF Patch #326 from Kris Thielemans - Remove SwigPyObject_print and SwigPyObject_str and make the generated wrapper use the default python implementations, which will fall back to repr diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 233f79bd6..94802e06d 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -3401,7 +3401,7 @@ public: printSlot(f, getSlot(n, "feature:python:tp_dict"), "tp_dict"); printSlot(f, getSlot(n, "feature:python:tp_descr_get"), "tp_descr_get", "descrgetfunc"); printSlot(f, getSlot(n, "feature:python:tp_descr_set"), "tp_descr_set", "descrsetfunc"); - Printf(f, " offsetof(SwigPyObject, dict), /* tp_dictoffset */\n"); + Printf(f, " (Py_ssize_t)offsetof(SwigPyObject, dict), /* tp_dictoffset */\n"); printSlot(f, tp_init, "tp_init", "initproc"); printSlot(f, getSlot(n, "feature:python:tp_alloc"), "tp_alloc", "allocfunc"); printSlot(f, "0", "tp_new", "newfunc"); From 1cc735df5e087edc2ac189b39a1ccb12ed304a13 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 16 Aug 2013 08:12:09 +0100 Subject: [PATCH 0688/1160] %implicitconv will now accept None where the implicit conversion takes a C/C++ pointer. Problem highlighted by Bo Peng on the swig-user mailing list. SF patch #230. --- CHANGES.current | 4 ++ Examples/test-suite/implicittest.i | 25 +++++++++-- .../test-suite/python/implicittest_runme.py | 43 +++++++++++++++++++ Lib/python/pyrun.swg | 12 +++++- 4 files changed, 79 insertions(+), 5 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 584d5c3a2..f87f7ef70 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -8,6 +8,10 @@ Version 2.0.11 (in progress) 2013-08-23: olly [Python] Fix clang++ warning in generated wrapper code. +2013-08-16: wsfulton + [Python] %implicitconv will now accept None where the implicit conversion takes a C/C++ pointer. + Problem highlighted by Bo Peng. Closes SF patch #230. + 2013-08-07: wsfulton [Python] SF Patch #326 from Kris Thielemans - Remove SwigPyObject_print and SwigPyObject_str and make the generated wrapper use the default python implementations, which will fall back to repr diff --git a/Examples/test-suite/implicittest.i b/Examples/test-suite/implicittest.i index e07adc5cc..10f901710 100644 --- a/Examples/test-suite/implicittest.i +++ b/Examples/test-suite/implicittest.i @@ -46,7 +46,6 @@ Foo(double){ ii = 2;} explicit Foo(char *s){ii = 3;} Foo(const Foo& f){ ii = f.ii;} - }; struct Bar @@ -57,11 +56,31 @@ Bar(const Foo& ff){ ii = ff.ii;} }; - int get_b(const Bar&b) { return b.ii; } Foo foo; - } %template(A_int) A_T; + + +/****************** None handling *********************/ + +%inline +{ + struct BB {}; + struct AA + { + int ii; + AA(int i) { ii = 1; } + AA(double d) { ii = 2; } + AA(const B* b) { ii = 3; } + explicit AA(char *s) { ii = 4; } + AA(const BB& b) { ii = 5; } + + int get() const { return ii; } + }; + + int get_AA_val(AA a) { return a.ii; } + int get_AA_ref(const AA& a) { return a.ii; } +} diff --git a/Examples/test-suite/python/implicittest_runme.py b/Examples/test-suite/python/implicittest_runme.py index 4200543c4..5644555df 100644 --- a/Examples/test-suite/python/implicittest_runme.py +++ b/Examples/test-suite/python/implicittest_runme.py @@ -11,6 +11,14 @@ check(1, A(1).get()) check(2, A(1.0).get()) check(3, A(B()).get()) check(4, A("hello").get()) +try: + check(3, A(None).get()) + raise RuntimeError +except ValueError: + # ValueError: invalid null reference in method 'new_A', argument 1 of type 'B const &' + # Arguably A(char *) should be chosen, but there is a bug to do with None passed to methods overloaded by value, + # references and pointers to different types, where pointers ought to be given a slightly higher precedence. + pass check(1, get(1)) check(2, get(1.0)) @@ -71,3 +79,38 @@ try: except TypeError: pass +#### Class testing None #### + +# No implicit conversion +check(1, AA(1).get()) +check(2, AA(1.0).get()) +check(3, AA(B()).get()) +check(3, AA(None).get()) +check(4, AA("hello").get()) +check(5, AA(BB()).get()) + +check(1, get_AA_val(1)) +check(2, get_AA_val(1.0)) +check(3, get_AA_val(B())) +check(3, get_AA_val(None)) +check(5, get_AA_val(BB())) + +# Explicit constructor: +try: + check(4, get_AA_val("hello")) + raise RuntimeError +except TypeError: + pass + +check(1, get_AA_ref(1)) +check(2, get_AA_ref(1.0)) +check(3, get_AA_ref(B())) +check(3, get_AA_ref(None)) +check(5, get_AA_ref(BB())) + +# Explicit constructor: +try: + check(4, get_AA_ref("hello")) + raise RuntimeError +except TypeError: + pass diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 273c82302..b077fad32 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1128,10 +1128,11 @@ SWIGRUNTIME int SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) { int res; SwigPyObject *sobj; + int implicit_conv = (flags & SWIG_POINTER_IMPLICIT_CONV) != 0; if (!obj) return SWIG_ERROR; - if (obj == Py_None) { + if (obj == Py_None && !implicit_conv) { if (ptr) *ptr = 0; return SWIG_OK; @@ -1180,7 +1181,7 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int } res = SWIG_OK; } else { - if (flags & SWIG_POINTER_IMPLICIT_CONV) { + if (implicit_conv) { SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; if (data && !data->implicitconv) { PyObject *klass = data->klass; @@ -1215,6 +1216,13 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int } } } + if (!SWIG_IsOK(res) && obj == Py_None) { + if (ptr) + *ptr = 0; + if (PyErr_Occurred()) + PyErr_Clear(); + res = SWIG_OK; + } } return res; } From b58dabced9e7424e6107bfd40963806f3b831a19 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 28 Aug 2013 20:24:54 +0100 Subject: [PATCH 0689/1160] %implicitconv is improved for overloaded functions. Like in C++, the methods with the actual types are considered before trying implicit conversions. --- CHANGES.current | 20 ++++++ Examples/test-suite/implicittest.i | 30 +++++++++ .../test-suite/python/implicittest_runme.py | 9 +++ Source/Modules/overload.cxx | 63 +++++++++++++++++-- 4 files changed, 117 insertions(+), 5 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index f87f7ef70..07a57c42a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,26 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.11 (in progress) ============================ +2013-08-28: wsfulton + [Python] %implicitconv is improved for overloaded functions. Like in C++, the methods + with the actual types are considered before trying implicit conversions. Example: + + %implicitconv A; + struct A { + A(int i); + }; + class CCC { + public: + int xx(int i) { return 11; } + int xx(const A& i) { return 22; } + }; + + The following python code: + + CCC().xx(-1) + + will now return 11 instead of 22 - the implicit conversion is not done. + 2013-08-23: olly [Python] Fix clang++ warning in generated wrapper code. diff --git a/Examples/test-suite/implicittest.i b/Examples/test-suite/implicittest.i index 10f901710..171c6055c 100644 --- a/Examples/test-suite/implicittest.i +++ b/Examples/test-suite/implicittest.i @@ -84,3 +84,33 @@ int get_AA_val(AA a) { return a.ii; } int get_AA_ref(const AA& a) { return a.ii; } } + + +/****************** Overloading priority *********************/ + +%inline %{ +class BBB { + public: + BBB(const B &) {} +}; + +class CCC { + public: + CCC(const BBB &) : checkvalue(0) {} + int xx(int i) { return 11; } + int xx(const A& i) { return 22; } + int yy(int i, int j) { return 111; } + int yy(const A& i, const A& j) { return 222; } + int checkvalue; +}; +%} + +// CCC(const BBB &) was being called instead of this constructor (independent of being added via %extend) +%extend CCC { + CCC(const B& b) { + CCC* ccc = new CCC(b); + ccc->checkvalue = 10; + return ccc; + } +}; + diff --git a/Examples/test-suite/python/implicittest_runme.py b/Examples/test-suite/python/implicittest_runme.py index 5644555df..a9957bc7e 100644 --- a/Examples/test-suite/python/implicittest_runme.py +++ b/Examples/test-suite/python/implicittest_runme.py @@ -114,3 +114,12 @@ try: raise RuntimeError except TypeError: pass + + +### overloading priority test ### + +ccc = CCC(B()) +check(ccc.checkvalue, 10) +check(ccc.xx(123), 11) +check(ccc.yy(123, 123), 111) + diff --git a/Source/Modules/overload.cxx b/Source/Modules/overload.cxx index 0112d2d9e..e95ef557f 100644 --- a/Source/Modules/overload.cxx +++ b/Source/Modules/overload.cxx @@ -26,6 +26,7 @@ struct Overloaded { int argc; /* Argument count */ ParmList *parms; /* Parameters used for overload check */ int error; /* Ambiguity error */ + bool implicitconv_function; /* For ordering implicitconv functions*/ }; static int fast_dispatch_mode = 0; @@ -40,6 +41,32 @@ void Wrapper_cast_dispatch_mode_set(int flag) { cast_dispatch_mode = flag; } +/* ----------------------------------------------------------------------------- + * mark_implicitconv_function() + * + * Mark function if it contains an implicitconv type in the parameter list + * ----------------------------------------------------------------------------- */ +static void mark_implicitconv_function(Overloaded& onode) { + Parm *parms = onode.parms; + if (parms) { + bool is_implicitconv_function = false; + Parm *p = parms; + while (p) { + if (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); + continue; + } + if (GetFlag(p, "implicitconv")) { + is_implicitconv_function = true; + break; + } + p = nextSibling(p); + } + if (is_implicitconv_function) + onode.implicitconv_function = true; + } +} + /* ----------------------------------------------------------------------------- * Swig_overload_rank() * @@ -85,6 +112,9 @@ List *Swig_overload_rank(Node *n, bool script_lang_wrapping) { nodes[nnodes].parms = Getattr(c, "wrap:parms"); nodes[nnodes].argc = emit_num_required(nodes[nnodes].parms); nodes[nnodes].error = 0; + nodes[nnodes].implicitconv_function = false; + + mark_implicitconv_function(nodes[nnodes]); nnodes++; } c = Getattr(c, "sym:nextSibling"); @@ -287,12 +317,30 @@ List *Swig_overload_rank(Node *n, bool script_lang_wrapping) { List *result = NewList(); { int i; + int argc_changed_index = -1; for (i = 0; i < nnodes; i++) { if (nodes[i].error) Setattr(nodes[i].n, "overload:ignore", "1"); Append(result, nodes[i].n); - // Printf(stdout,"[ %d ] %s\n", i, ParmList_errorstr(nodes[i].parms)); - // Swig_print_node(nodes[i].n); + // Printf(stdout,"[ %d ] %d %s\n", i, nodes[i].implicitconv_function, ParmList_errorstr(nodes[i].parms)); + // Swig_print_node(nodes[i].n); + if (i == nnodes-1 || nodes[i].argc != nodes[i+1].argc) { + if (argc_changed_index+2 < nnodes && (nodes[argc_changed_index+1].argc == nodes[argc_changed_index+2].argc)) { + // Add additional implicitconv functions in same order as already ranked. + // Consider overloaded functions by argument count... only add additional implicitconv functions if + // the number of functions with the same arg count > 1, ie, only if overloaded by same argument count. + int j; + for (j = argc_changed_index + 1; j <= i; j++) { + if (nodes[j].implicitconv_function) { + SetFlag(nodes[j].n, "implicitconvtypecheckoff"); + Append(result, nodes[j].n); + // Printf(stdout,"[ %d ] %d + %s\n", j, nodes[j].implicitconv_function, ParmList_errorstr(nodes[j].parms)); + // Swig_print_node(nodes[j].n); + } + } + } + argc_changed_index = i; + } } } return result; @@ -302,20 +350,22 @@ List *Swig_overload_rank(Node *n, bool script_lang_wrapping) { // * print_typecheck() // * ----------------------------------------------------------------------------- */ -static bool print_typecheck(String *f, int j, Parm *pj) { +static bool print_typecheck(String *f, int j, Parm *pj, bool implicitconvtypecheckoff) { char tmp[256]; sprintf(tmp, Char(argv_template_string), j); String *tm = Getattr(pj, "tmap:typecheck"); if (tm) { + tm = Copy(tm); Replaceid(tm, Getattr(pj, "lname"), "_v"); String *conv = Getattr(pj, "implicitconv"); - if (conv) { + if (conv && !implicitconvtypecheckoff) { Replaceall(tm, "$implicitconv", conv); } else { Replaceall(tm, "$implicitconv", "0"); } Replaceall(tm, "$input", tmp); Printv(f, tm, "\n", NIL); + Delete(tm); return true; } else return false; @@ -715,6 +765,7 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar for (i = 0; i < nfunc; i++) { Node *ni = Getitem(dispatch, i); Parm *pi = Getattr(ni, "wrap:parms"); + bool implicitconvtypecheckoff = GetFlag(ni, "implicitconvtypecheckoff") != 0; int num_required = emit_num_required(pi); int num_arguments = emit_num_arguments(pi); if (GetFlag(n, "wrap:this")) { @@ -749,7 +800,7 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar Printf(f, "}\n"); Delete(lfmt); } - if (print_typecheck(f, (GetFlag(n, "wrap:this") ? j + 1 : j), pj)) { + if (print_typecheck(f, (GetFlag(n, "wrap:this") ? j + 1 : j), pj, implicitconvtypecheckoff)) { Printf(f, "if (_v) {\n"); num_braces++; } @@ -773,6 +824,8 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar for ( /* empty */ ; num_braces > 0; num_braces--) Printf(f, "}\n"); Printf(f, "}\n"); /* braces closes "if" for this method */ + if (implicitconvtypecheckoff) + Delattr(ni, "implicitconvtypecheckoff"); } Delete(dispatch); return f; From 6efe3d61f29dc30b9f9782a691cd2d76040385ca Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 29 Aug 2013 11:16:58 +1200 Subject: [PATCH 0690/1160] Strip trailing whitespace --- configure.ac | 84 ++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/configure.ac b/configure.ac index cc4270ad7..5b6441b86 100644 --- a/configure.ac +++ b/configure.ac @@ -47,7 +47,7 @@ AC_LANG_POP([C++]) dnl Look for popen AC_ARG_WITH(popen, AS_HELP_STRING([--without-popen], [Disable popen]), with_popen="$withval") -if test x"${with_popen}" = xno ; then +if test x"${with_popen}" = xno ; then AC_MSG_NOTICE([Disabling popen]) else AC_CHECK_FUNC(popen, AC_DEFINE(HAVE_POPEN, 1, [Define if popen is available]), AC_MSG_NOTICE([Disabling popen])) @@ -69,7 +69,7 @@ AC_MSG_CHECKING([whether to enable PCRE support]) AC_MSG_RESULT([$with_pcre]) dnl To make configuring easier, check for a locally built PCRE using the Tools/pcre-build.sh script -if test x"${with_pcre}" = xyes ; then +if test x"${with_pcre}" = xyes ; then AC_MSG_CHECKING([whether to use local PCRE]) local_pcre_config=no if test -z $PCRE_CONFIG; then @@ -513,7 +513,7 @@ AC_ARG_WITH(tcllib,[ --with-tcllib=path Set location of Tcl library direct TCLLIB="-L$withval"], [TCLLIB=]) # First, check for "--without-tcl" or "--with-tcl=no". -if test x"${TCLPACKAGE}" = xno -o x"${with_alllang}" = xno; then +if test x"${TCLPACKAGE}" = xno -o x"${with_alllang}" = xno; then AC_MSG_NOTICE([Disabling Tcl]) else AC_MSG_CHECKING([for Tcl configuration]) @@ -606,7 +606,7 @@ case $host in esac case $host in -*-*-darwin*) +*-*-darwin*) TCLLDSHARED='$(CC) -dynamiclib -undefined suppress -flat_namespace' TCLCXXSHARED='$(CXX) -dynamiclib -undefined suppress -flat_namespace' ;; @@ -636,7 +636,7 @@ AC_ARG_WITH(python, AS_HELP_STRING([--without-python], [Disable Python]) AS_HELP_STRING([--with-python=path], [Set location of Python executable]),[ PYBIN="$withval"], [PYBIN=yes]) # First, check for "--without-python" or "--with-python=no". -if test x"${PYBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${PYBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling Python]) else # First figure out the name of the Python executable @@ -671,10 +671,10 @@ else PYLIBDIR=`($PYTHON -c "import sys; print sys.lib") 2>/dev/null` if test -z "$PYLIBDIR"; then # Fedora patch Python to add sys.lib, for other distros we assume "lib". - PYLIBDIR="lib" + PYLIBDIR="lib" fi AC_MSG_RESULT($PYLIBDIR) - + # Set the include directory AC_MSG_CHECKING(for Python header files) @@ -737,7 +737,7 @@ AC_ARG_WITH(python3, AS_HELP_STRING([--without-python3], [Disable Python 3.x sup AS_HELP_STRING([--with-python3=path], [Set location of Python 3.x executable]),[ PY3BIN="$withval"], [PY3BIN=yes]) # First, check for "--without-python3" or "--with-python3=no". -if test x"${PY3BIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${PY3BIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling Python 3.x support]) else for py_ver in 3 3.6 3.5 3.4 3.3 3.2 3.1 3.0; do @@ -760,7 +760,7 @@ else # Note: I could not think of a standard way to get the version string from different versions. # This trick pulls it out of the file location for a standard library file. - + AC_MSG_CHECKING([for Python 3.x version]) # Need to do this hack since autoconf replaces __file__ with the name of the configure file @@ -774,10 +774,10 @@ else PY3LIBDIR=`($PYTHON3 -c "import sys; print(sys.lib)") 2>/dev/null` if test -z "$PY3LIBDIR"; then # some dists don't have sys.lib so the best we can do is assume lib - PY3LIBDIR="lib" + PY3LIBDIR="lib" fi AC_MSG_RESULT($PY3LIBDIR) - + # Set the include directory AC_MSG_CHECKING([for Python 3.x header files]) @@ -828,7 +828,7 @@ AC_ARG_WITH(perl5, AS_HELP_STRING([--without-perl5], [Disable Perl5]) AS_HELP_STRING([--with-perl5=path], [Set location of Perl5 executable]),[ PERLBIN="$withval"], [PERLBIN=yes]) # First, check for "--without-perl5" or "--with-perl5=no". -if test x"${PERLBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${PERLBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling Perl5]) PERL= else @@ -932,7 +932,7 @@ AC_ARG_WITH(octave, AS_HELP_STRING([--without-octave], [Disable Octave]) AS_HELP_STRING([--with-octave=path], [Set location of Octave executable]),[OCTAVEBIN="$withval"], [OCTAVEBIN=yes]) # First, check for "--without-octave" or "--with-octave=no". -if test x"${OCTAVEBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${OCTAVEBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling Octave]) OCTAVE= @@ -1000,7 +1000,7 @@ AS_HELP_STRING([--with-java=path], [Set location of java executable]),[JAVABIN=" AC_ARG_WITH(javac, [ --with-javac=path Set location of javac executable],[JAVACBIN="$withval"], [JAVACBIN=]) # First, check for "--without-java" or "--with-java=no". -if test x"${JAVABIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${JAVABIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling Java]) JAVA= else @@ -1066,7 +1066,7 @@ case $host in JAVADYNAMICLINKING="" JAVACFLAGS="" fi ;; -*-*-darwin*) +*-*-darwin*) JAVADYNAMICLINKING="-dynamiclib -framework JavaVM" JAVACFLAGS="" ;; @@ -1084,7 +1084,7 @@ esac # Java on Mac OS X tweaks case $host in -*-*-darwin*) +*-*-darwin*) JAVASO=".jnilib" JAVALDSHARED='$(CC)' JAVACXXSHARED='$(CXX)' @@ -1116,7 +1116,7 @@ AS_HELP_STRING([--with-gcj=path], [Set location of gcj executable]),[GCJBIN="$wi AC_ARG_WITH(gcjh, [ --with-gcjh=path Set location of gcjh executable],[GCJHBIN="$withval"], [GCJHBIN=]) # First, check for "--without-gcj" or "--with-gcj=no". -if test x"${GCJBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${GCJBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling GCJ]) else if test "x$GCJBIN" = xyes; then @@ -1146,7 +1146,7 @@ AC_ARG_WITH(ant, [ --with-ant=path Set location of ant executable for And AC_ARG_WITH(ndk-build, [ --with-ndk-build=path Set location of Android ndk-build executable],[NDKBUILDBIN="$withval"], [NDKBUILDBIN=]) # First, check for "--without-android" or "--with-android=no". -if test x"${ANDROIDBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${ANDROIDBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling Android]) ANDROID= else @@ -1198,7 +1198,7 @@ AC_ARG_WITH(guile-libs,[ --with-guile-libs=ldflags Set ldflags needed to lin GUILE_LIBS="$withval"]) # First, check for "--without-guile" or "--with-guile=no". -if test x"${GUILE}" = xno -o x"${with_alllang}" = xno ; then +if test x"${GUILE}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling Guile]) else if test -z "$GUILE_CONFIG" ; then @@ -1255,7 +1255,7 @@ AS_HELP_STRING([--with-mzscheme=path], [Set location of MzScheme executable]),[ AC_ARG_WITH(mzc, AS_HELP_STRING([--with-mzc=path], [Set location of MzScheme's mzc]), [ MZCBIN="$withval"], [MZCBIN=]) # First, check for "--without-mzscheme" or "--with-mzscheme=no". -if test x"${MZSCHEMEBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${MZSCHEMEBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling MzScheme]) MZC= else @@ -1264,13 +1264,13 @@ else else MZSCHEME="$MZSCHEMEBIN" fi - + if test -z "$MZCBIN"; then AC_PATH_PROG(MZC, mzc) fi if test -n "$MZSCHEME"; then - AC_MSG_CHECKING(for MzScheme dynext object) + AC_MSG_CHECKING(for MzScheme dynext object) MZDYNOBJ=`$MZSCHEME --eval '(begin (require dynext/link) (with-handlers (((lambda args #t) (lambda args #f))) (for-each (lambda (x) (printf "~a" x)) (expand-for-link-variant (current-standard-link-libraries)))))' 2>/dev/null` if test -f "$MZDYNOBJ"; then : @@ -1298,7 +1298,7 @@ AC_ARG_WITH(ruby, AS_HELP_STRING([--without-ruby], [Disable Ruby]) AS_HELP_STRING([--with-ruby=path], [Set location of Ruby executable]),[ RUBYBIN="$withval"], [RUBYBIN=yes]) # First, check for "--without-ruby" or "--with-ruby=no". -if test x"${RUBYBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${RUBYBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling Ruby]) RUBY= else @@ -1357,10 +1357,10 @@ if test -n "$RUBY"; then else # 1.6.x link = "-l" + c[["RUBY_INSTALL_NAME"]] end - + # Get the target Ruby was built for target = c[["target"]] - + if target == "i386-pc-mswin32" # Need to change msvcrt-ruby*.lib to -lmsvcrt-ruby* ext = File.extname(link) @@ -1428,7 +1428,7 @@ AC_ARG_WITH(php, AS_HELP_STRING([--without-php], [Disable PHP]) AS_HELP_STRING([--with-php=path], [Set location of PHP executable]),[ PHPBIN="$withval"], [PHPBIN=yes]) # First, check for "--without-php" or "--with-php=no". -if test x"${PHPBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${PHPBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling PHP]) PHP= else @@ -1449,7 +1449,7 @@ else esac php_version=`$PHPCONFIG --version 2>/dev/null` case $php_version in - 5*) + 5*) PHPINC=`$PHPCONFIG --includes 2>/dev/null` if test -n "$PHPINC"; then AC_MSG_RESULT($PHPINC) @@ -1476,7 +1476,7 @@ AC_ARG_WITH(ocamlfind,[ --with-ocamlfind=path Set location of ocamlfind],[OCA AC_ARG_WITH(ocamlmktop,[ --with-ocamlmktop=path Set location of ocamlmktop executable],[ OCAMLMKTOP="$withval"], [OCAMLMKTOP=]) # First, check for "--without-ocaml" or "--with-ocaml=no". -if test x"${OCAMLBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${OCAMLBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling OCaml]) OCAMLBIN= else @@ -1562,7 +1562,7 @@ AC_ARG_WITH(pike, AS_HELP_STRING([--without-pike], [Disable Pike]) AS_HELP_STRING([--with-pike=path], [Set location of Pike executable]),[PIKEBIN="$withval"], [PIKEBIN=yes]) # First, check for "--without-pike" or "--with-pike=no". -if test x"${PIKEBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${PIKEBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling Pike]) PIKEBIN= else @@ -1576,7 +1576,7 @@ fi # Check for pike-config # Priority: configure option, guessed from $PIKE, search from list -AC_ARG_WITH(pike-config, AS_HELP_STRING([--with-pike-config=path], +AC_ARG_WITH(pike-config, AS_HELP_STRING([--with-pike-config=path], [Set location of pike-config script]), [PIKECONFIG="$withval"], [PIKECONFIG=""]) @@ -1587,7 +1587,7 @@ fi # Check for a --with-pikeincl option to configure # Priority: configure option, info from $PIKECONFIG, guessed by pike script -AC_ARG_WITH(pikeincl, AS_HELP_STRING([--with-pikeincl=path], +AC_ARG_WITH(pikeincl, AS_HELP_STRING([--with-pikeincl=path], [Set location of Pike include directory]), [PIKEINCLUDE="-I$withval"], [PIKEINCLUDE=]) @@ -1632,7 +1632,7 @@ AC_ARG_WITH(chicken, AS_HELP_STRING([--without-chicken], [Disable CHICKEN]) AS_HELP_STRING([--with-chicken=path], [Set location of CHICKEN executable]),[ CHICKENBIN="$withval"], [CHICKENBIN=yes]) # First, check for "--without-chicken" or "--with-chicken=no". -if test x"${CHICKENBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${CHICKENBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling CHICKEN]) else @@ -1728,7 +1728,7 @@ AC_ARG_WITH(cil-interpreter, [ --with-cil-interpreter=path Set location of AC_ARG_WITH(csharp-compiler, [ --with-csharp-compiler=path Set location of CSharp compiler],[CSHARPCOMPILERBIN="$withval"], [CSHARPCOMPILERBIN=]) # First, check for "--without-csharp" or "--with-csharp=no". -if test x"${with_csharp}" = xno -o x"${with_alllang}" = xno ; then +if test x"${with_csharp}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling CSharp]) CSHARPCOMPILER= else @@ -1781,7 +1781,7 @@ if test -z "$CSHARPBIN" ; then if test "mcs" = "$CSHARPCOMPILER" || test "gmcs" = "$CSHARPCOMPILER"; then AC_CHECK_PROGS(CSHARPCILINTERPRETER, mono) # Mono JIT CSHARPCILINTERPRETER_FLAGS="--debug" - else + else if test "csc" = "$CSHARPCOMPILER"; then CSHARPPATHSEPARATOR="\\\\" CSHARPCYGPATH_W='cygpath -w' @@ -1856,7 +1856,7 @@ AC_ARG_WITH(lualib,[ --with-lualib=path Set location of Lua library direct LUALIB="$withval"], [LUALIB=]) # First, check for "--without-lua" or "--with-lua=no". -if test x"${LUABIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${LUABIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling Lua]) else @@ -1897,8 +1897,8 @@ if test "$LUABIN"; then else LUADYNAMICLOADLIB=`$LUABIN -e '_,_,c=package.loadlib("no_such_lib","") if c~="absent" then print "1" end'` fi - - if test -z "$LUADYNAMICLOADLIB"; then + + if test -z "$LUADYNAMICLOADLIB"; then AC_MSG_RESULT(no) else AC_MSG_RESULT(yes) @@ -1938,7 +1938,7 @@ fi # look for the library files & set LUALINK accordingly # will clear LUABIN if not present lua_save_LIBS=$LIBS # the code seems to disrupt LIBS, so saving - + if test -n "$LUALIB"; then AC_CHECK_FILE($LUALIB/liblua.a,[LUALINK="-L$LUALIB -llua"],[LUABIN=]) else @@ -1969,7 +1969,7 @@ AC_ARG_WITH(allegrocl, AS_HELP_STRING([--without-allegrocl], [Disable Allegro CL AS_HELP_STRING([--with-allegrocl=path], [Set location of Allegro CL executable (alisp)]),[ ALLEGROCLBIN="$withval"], [ALLEGROCLBIN=yes]) # First, check for "--without-allegrocl" or "--with-allegrocl=no". -if test x"${ALLEGROCLBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${ALLEGROCLBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling Allegro CL]) ALLEGROCLBIN= else @@ -1992,7 +1992,7 @@ AC_ARG_WITH(clisp, AS_HELP_STRING([--without-clisp], [Disable CLISP]) AS_HELP_STRING([--with-clisp=path], [Set location of CLISP executable (clisp)]),[ CLISPBIN="$withval"], [CLISPBIN=yes]) # First, check for "--without-clisp" or "--with-clisp=no". -if test x"${CLISPBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${CLISPBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling CLISP]) CLISPBIN= else @@ -2015,7 +2015,7 @@ AC_ARG_WITH(r, AS_HELP_STRING([--without-r], [Disable R]) AS_HELP_STRING([--with-r=path], [Set location of R executable (r)]),[ RBIN="$withval"], [RBIN=yes]) # First, check for "--without-r" or "--with-r=no". -if test x"${RBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${RBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling R]) RBIN= else @@ -2035,7 +2035,7 @@ AC_SUBST(RBIN) AC_ARG_WITH(go, AS_HELP_STRING([--without-go], [Disable Go]) AS_HELP_STRING([--with-go=path], [Set location of Go compiler]),[GOBIN="$withval"], [GOBIN=yes]) -if test x"${GOBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${GOBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling Go]) GO= GOC= From 9efaf954c71118d41ba9bf43ed371bbe83093564 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 16 Aug 2013 23:34:24 +0200 Subject: [PATCH 0691/1160] Add support for std::map<> comparator template argument for C#. Allow exporting maps using non-default comparison function. Closes #77 --- CHANGES.current | 3 +++ Lib/csharp/std_map.i | 36 ++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 07a57c42a..dfbe651f0 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.11 (in progress) ============================ +2013-08-29: wsfulton + [C#] Pull Git patch #77: Allow exporting std::map using non-default comparison function. + 2013-08-28: wsfulton [Python] %implicitconv is improved for overloaded functions. Like in C++, the methods with the actual types are considered before trying implicit conversions. Example: diff --git a/Lib/csharp/std_map.i b/Lib/csharp/std_map.i index 6a7da16b6..acd190689 100644 --- a/Lib/csharp/std_map.i +++ b/Lib/csharp/std_map.i @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- * std_map.i * - * SWIG typemaps for std::map< K, T > + * SWIG typemaps for std::map< K, T, C > * * The C# wrapper is made to look and feel like a C# System.Collections.Generic.IDictionary<>. * @@ -26,10 +26,10 @@ %} /* K is the C++ key type, T is the C++ value type */ -%define SWIG_STD_MAP_INTERNAL(K, T) +%define SWIG_STD_MAP_INTERNAL(K, T, C) -%typemap(csinterfaces) std::map< K, T > "IDisposable \n#if !SWIG_DOTNET_1\n , System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n#endif\n"; -%typemap(cscode) std::map %{ +%typemap(csinterfaces) std::map< K, T, C > "IDisposable \n#if !SWIG_DOTNET_1\n , System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n#endif\n"; +%typemap(cscode) std::map %{ public $typemap(cstype, T) this[$typemap(cstype, K) key] { get { @@ -221,14 +221,14 @@ typedef T mapped_type; map(); - map(const map< K, T > &other); + map(const map< K, T, C > &other); size_type size() const; bool empty() const; %rename(Clear) clear; void clear(); %extend { const mapped_type& getitem(const key_type& key) throw (std::out_of_range) { - std::map< K,T >::iterator iter = $self->find(key); + std::map< K, T, C >::iterator iter = $self->find(key); if (iter != $self->end()) return iter->second; else @@ -240,19 +240,19 @@ } bool ContainsKey(const key_type& key) { - std::map< K, T >::iterator iter = $self->find(key); + std::map< K, T, C >::iterator iter = $self->find(key); return iter != $self->end(); } void Add(const key_type& key, const mapped_type& val) throw (std::out_of_range) { - std::map< K, T >::iterator iter = $self->find(key); + std::map< K, T, C >::iterator iter = $self->find(key); if (iter != $self->end()) throw std::out_of_range("key already exists"); $self->insert(std::pair< K, T >(key, val)); } bool Remove(const key_type& key) { - std::map< K, T >::iterator iter = $self->find(key); + std::map< K, T, C >::iterator iter = $self->find(key); if (iter != $self->end()) { $self->erase(iter); return true; @@ -261,20 +261,20 @@ } // create_iterator_begin(), get_next_key() and destroy_iterator work together to provide a collection of keys to C# - %apply void *VOID_INT_PTR { std::map< K, T >::iterator *create_iterator_begin } - %apply void *VOID_INT_PTR { std::map< K, T >::iterator *swigiterator } + %apply void *VOID_INT_PTR { std::map< K, T, C >::iterator *create_iterator_begin } + %apply void *VOID_INT_PTR { std::map< K, T, C >::iterator *swigiterator } - std::map< K, T >::iterator *create_iterator_begin() { - return new std::map< K, T >::iterator($self->begin()); + std::map< K, T, C >::iterator *create_iterator_begin() { + return new std::map< K, T, C >::iterator($self->begin()); } - const key_type& get_next_key(std::map< K, T >::iterator *swigiterator) { - std::map< K, T >::iterator iter = *swigiterator; + const key_type& get_next_key(std::map< K, T, C >::iterator *swigiterator) { + std::map< K, T, C >::iterator iter = *swigiterator; (*swigiterator)++; return (*iter).first; } - void destroy_iterator(std::map< K, T >::iterator *swigiterator) { + void destroy_iterator(std::map< K, T, C >::iterator *swigiterator) { delete swigiterator; } } @@ -291,8 +291,8 @@ // Default implementation namespace std { - template class map { - SWIG_STD_MAP_INTERNAL(K, T) + template > class map { + SWIG_STD_MAP_INTERNAL(K, T, C) }; } From f55ff50dd5bf050e1e0b25410b7aa912ea3842f3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 29 Aug 2013 19:19:52 +0100 Subject: [PATCH 0692/1160] Skip the UTF-8 BOM of including files. For avoiding illegal token error when parsing include files which have the UTF-8 BOM. Closes #75. --- CHANGES.current | 4 ++++ Examples/test-suite/bom_utf8.i | 9 +++++++++ Examples/test-suite/common.mk | 3 ++- Source/Swig/include.c | 11 ++++++++++- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/bom_utf8.i diff --git a/CHANGES.current b/CHANGES.current index dfbe651f0..0a8d722ff 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.11 (in progress) ============================ +2013-08-29: wsfulton + Pull Git patch #75: Handle UTF-8 files with BOM at beginning of file. Was giving an + 'Illegal token' syntax error. + 2013-08-29: wsfulton [C#] Pull Git patch #77: Allow exporting std::map using non-default comparison function. diff --git a/Examples/test-suite/bom_utf8.i b/Examples/test-suite/bom_utf8.i new file mode 100644 index 000000000..010774937 --- /dev/null +++ b/Examples/test-suite/bom_utf8.i @@ -0,0 +1,9 @@ +%module bom_utf8 + +/* Test for UTF8 BOM at start of file */ +%inline %{ +struct NotALotHere { + int n; +}; +%} + diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 9a335b46e..b1e5fc3b8 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -552,7 +552,8 @@ C_TEST_CASES += \ typedef_struct \ typemap_subst \ union_parameter \ - unions + unions \ + utf8_bom # Multi-module C++ test cases . (Can be run individually using make testcase.multicpptest) diff --git a/Source/Swig/include.c b/Source/Swig/include.c index 13afb21ae..7e80172ba 100644 --- a/Source/Swig/include.c +++ b/Source/Swig/include.c @@ -163,7 +163,8 @@ static FILE *Swig_open_file(const_String_or_char_ptr name, int sysfile, int use_ String *filename; List *spath = 0; char *cname; - int i, ilen; + int i, ilen, nbytes; + char bom[3]; if (!directories) directories = NewList(); @@ -191,6 +192,14 @@ static FILE *Swig_open_file(const_String_or_char_ptr name, int sysfile, int use_ if (f) { Delete(lastpath); lastpath = filename; + + /* Skip the UTF-8 BOM if it's present */ + nbytes = fread(bom, 1, 3, f); + if (nbytes == 3 && bom[0] == (char)0xEF && bom[1] == (char)0xBB && bom[2] == (char)0xBF) { + /* skip */ + } else { + fseek(f, 0, SEEK_SET); + } } return f; } From ada7dd92e460aa470b90b035c295913b82863f6c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 29 Aug 2013 22:49:59 +0100 Subject: [PATCH 0693/1160] Fix testcase name --- Examples/test-suite/common.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index b1e5fc3b8..5d6a4730a 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -509,6 +509,7 @@ endif # C test cases. (Can be run individually using: make testcase.ctest) C_TEST_CASES += \ arrays \ + bom_utf8 \ char_constant \ const_const \ constant_expr \ @@ -552,8 +553,7 @@ C_TEST_CASES += \ typedef_struct \ typemap_subst \ union_parameter \ - unions \ - utf8_bom + unions # Multi-module C++ test cases . (Can be run individually using make testcase.multicpptest) From 663c41e24861ebdc14563b2c1e77d1329d11225a Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Thu, 29 Aug 2013 20:01:13 +0900 Subject: [PATCH 0694/1160] Add Lua runtime helper functions for error-handling Add two helper functions to the Lua runtime, "SWIG_Lua_pusherrstring" and "SWIG_Lua_pushferrstring". These are like the standard Lua functions lua_pushstring and lua_pushfstring respectively, except that the strings are prefixed with the location of the innermost Lua call-point (as generated by luaL_where). --- Lib/lua/luarun.swg | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index e4f39e07f..dea8dd7a0 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -71,6 +71,36 @@ extern "C" { #endif +/* -------------------------------------------------------------------------- + * Helper functions for error handling + * -------------------------------------------------------------------------- */ + +/* Push the string STR on the Lua stack, like lua_pushstring, but + prefixed with the the location of the innermost Lua call-point + (as formated by luaL_where). */ +SWIGRUNTIME void +SWIG_Lua_pusherrstring (lua_State *L, const char *str) +{ + luaL_where (L, 1); + lua_pushstring (L, str); + lua_concat (L, 2); +} + +/* Push a formatted string generated from FMT and following args on + the Lua stack, like lua_pushfstring, but prefixed with the the + location of the innermost Lua call-point (as formated by luaL_where). */ +SWIGRUNTIME void +SWIG_Lua_pushferrstring (lua_State *L, const char *fmt, ...) +{ + va_list argp; + va_start(argp, fmt); + luaL_where(L, 1); + lua_pushvfstring(L, fmt, argp); + va_end(argp); + lua_concat(L, 2); +} + + /* ----------------------------------------------------------------------------- * global swig types * ----------------------------------------------------------------------------- */ From c746ae7a0fcae2e5a317c6fd8a2e44603ec24178 Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Thu, 29 Aug 2013 20:07:24 +0900 Subject: [PATCH 0695/1160] Include Lua error locus in SWIG error messages This is standard information in Lua error messages, and makes it much easier to find bugs. --- Lib/lua/luarun.swg | 15 +++++++-------- Lib/lua/typemaps.i | 20 ++++++++++---------- Lib/lua/wchar.i | 2 +- Source/Modules/lua.cxx | 2 +- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index dea8dd7a0..c705e38e5 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -185,19 +185,20 @@ typedef struct { /* Contract support */ #define SWIG_contract_assert(expr, msg) \ - if (!(expr)) { lua_pushstring(L, (char *) msg); goto fail; } else + if (!(expr)) { SWIG_Lua_pusherrstring(L, (char *) msg); goto fail; } else + /* helper #defines */ #define SWIG_fail {goto fail;} #define SWIG_fail_arg(func_name,argnum,type) \ - {lua_pushfstring(L,"Error in %s (arg %d), expected '%s' got '%s'",\ + {SWIG_Lua_pushferrstring(L,"Error in %s (arg %d), expected '%s' got '%s'",\ func_name,argnum,type,SWIG_Lua_typename(L,argnum));\ goto fail;} #define SWIG_fail_ptr(func_name,argnum,type) \ SWIG_fail_arg(func_name,argnum,(type && type->str)?type->str:"void*") #define SWIG_check_num_args(func_name,a,b) \ if (lua_gettop(L)b) \ - {lua_pushfstring(L,"Error in %s expected %d..%d args, got %d",func_name,a,b,lua_gettop(L));\ + {SWIG_Lua_pushferrstring(L,"Error in %s expected %d..%d args, got %d",func_name,a,b,lua_gettop(L));\ goto fail;} @@ -250,8 +251,7 @@ SWIGINTERN int SWIG_Lua_set_immutable(lua_State* L) /* there should be 1 param passed in: the new value */ #ifndef SWIGLUA_IGNORE_SET_IMMUTABLE lua_pop(L,1); /* remove it */ - lua_pushstring(L,"This variable is immutable"); - lua_error(L); + luaL_error(L,"This variable is immutable"); #endif return 0; /* should not return anything */ } @@ -786,9 +786,8 @@ SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_State* L,int index,swig_type_info *typ int argnum,const char* func_name){ void* result; if (!SWIG_IsOK(SWIG_ConvertPtr(L,index,&result,type,flags))){ - lua_pushfstring(L,"Error in %s, expected a %s at argument number %d\n", - func_name,(type && type->str)?type->str:"void*",argnum); - lua_error(L); + luaL_error (L,"Error in %s, expected a %s at argument number %d\n", + func_name,(type && type->str)?type->str:"void*",argnum); } return result; } diff --git a/Lib/lua/typemaps.i b/Lib/lua/typemaps.i index a7ecec528..7a095a1e0 100644 --- a/Lib/lua/typemaps.i +++ b/Lib/lua/typemaps.i @@ -250,12 +250,12 @@ SWIGINTERN int SWIG_table_size(lua_State* L, int index) SWIGINTERN TYPE* SWIG_get_##NAME##_num_array_fixed(lua_State* L, int index, int size){\ TYPE *array;\ if (!lua_istable(L,index) || SWIG_itable_size(L,index) != size) {\ - lua_pushfstring(L,"expected a table of size %d",size);\ + SWIG_Lua_pushferrstring(L,"expected a table of size %d",size);\ return 0;\ }\ array=SWIG_ALLOC_ARRAY(TYPE,size);\ if (!SWIG_read_##NAME##_num_array(L,index,array,size)){\ - lua_pushstring(L,"table must contain numbers");\ + SWIG_Lua_pusherrstring(L,"table must contain numbers");\ SWIG_FREE_ARRAY(array);\ return 0;\ }\ @@ -265,17 +265,17 @@ SWIGINTERN int SWIG_table_size(lua_State* L, int index) {\ TYPE *array;\ if (!lua_istable(L,index)) {\ - lua_pushstring(L,"expected a table");\ + SWIG_Lua_pusherrstring(L,"expected a table");\ return 0;\ }\ *size=SWIG_itable_size(L,index);\ if (*size<1){\ - lua_pushstring(L,"table appears to be empty");\ + SWIG_Lua_pusherrstring(L,"table appears to be empty");\ return 0;\ }\ array=SWIG_ALLOC_ARRAY(TYPE,*size);\ if (!SWIG_read_##NAME##_num_array(L,index,array,*size)){\ - lua_pushstring(L,"table must contain numbers");\ + SWIG_Lua_pusherrstring(L,"table must contain numbers");\ SWIG_FREE_ARRAY(array);\ return 0;\ }\ @@ -451,12 +451,12 @@ SWIGINTERN int SWIG_read_ptr_array(lua_State* L,int index,void **array,int size, SWIGINTERN void** SWIG_get_ptr_array_fixed(lua_State* L, int index, int size,swig_type_info *type){ void **array; if (!lua_istable(L,index) || SWIG_itable_size(L,index) != size) { - lua_pushfstring(L,"expected a table of size %d",size); + SWIG_Lua_pushferrstring(L,"expected a table of size %d",size); return 0; } array=SWIG_ALLOC_ARRAY(void*,size); if (!SWIG_read_ptr_array(L,index,array,size,type)){ - lua_pushfstring(L,"table must contain pointers of type %s",type->name); + SWIG_Lua_pushferrstring(L,"table must contain pointers of type %s",type->name); SWIG_FREE_ARRAY(array); return 0; } @@ -465,17 +465,17 @@ SWIGINTERN void** SWIG_get_ptr_array_fixed(lua_State* L, int index, int size,swi SWIGINTERN void** SWIG_get_ptr_array_var(lua_State* L, int index, int* size,swig_type_info *type){ void **array; if (!lua_istable(L,index)) { - lua_pushstring(L,"expected a table"); + SWIG_Lua_pusherrstring(L,"expected a table"); return 0; } *size=SWIG_itable_size(L,index); if (*size<1){ - lua_pushstring(L,"table appears to be empty"); + SWIG_Lua_pusherrstring(L,"table appears to be empty"); return 0; } array=SWIG_ALLOC_ARRAY(void*,*size); if (!SWIG_read_ptr_array(L,index,array,*size,type)){ - lua_pushfstring(L,"table must contain pointers of type %s",type->name); + SWIG_Lua_pushferrstring(L,"table must contain pointers of type %s",type->name); SWIG_FREE_ARRAY(array); return 0; } diff --git a/Lib/lua/wchar.i b/Lib/lua/wchar.i index 14a94257f..141ecc41f 100644 --- a/Lib/lua/wchar.i +++ b/Lib/lua/wchar.i @@ -31,7 +31,7 @@ wchar_t* str2wstr(const char *str, int len) %typemap(in, checkfn="SWIG_lua_isnilstring", fragment="SWIG_lua_isnilstring") wchar_t * %{ $1 = str2wstr(lua_tostring( L, $input ),lua_rawlen( L, $input )); -if ($1==0) {lua_pushfstring(L,"Error in converting to wchar (arg %d)",$input);goto fail;} +if ($1==0) {SWIG_Lua_pushferrstring(L,"Error in converting to wchar (arg %d)",$input);goto fail;} %} %typemap(freearg) wchar_t * diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index a33898a2f..cff3107db 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -811,7 +811,7 @@ public: Printf(protoTypes, "\n\" %s\\n\"", fulldecl); Delete(fulldecl); } while ((sibl = Getattr(sibl, "sym:nextSibling"))); - Printf(f->code, "lua_pushstring(L,\"Wrong arguments for overloaded function '%s'\\n\"\n" + Printf(f->code, "SWIG_Lua_pusherrstring(L,\"Wrong arguments for overloaded function '%s'\\n\"\n" "\" Possible C/C++ prototypes are:\\n\"%s);\n",symname,protoTypes); Delete(protoTypes); From 4492a3d76bddaee5b05dea31a0d281868f5581f7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 30 Aug 2013 07:05:54 +0100 Subject: [PATCH 0696/1160] Document Include Lua error locus in SWIG error messages patches. Closes #81 --- CHANGES.current | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 0a8d722ff..ffb805ccd 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.11 (in progress) ============================ +2013-08-30: wsfulton + [Lua] Pull Git patch #81: Include Lua error locus in SWIG error messages. + This is standard information in Lua error messages, and makes it much + easier to find bugs. + 2013-08-29: wsfulton Pull Git patch #75: Handle UTF-8 files with BOM at beginning of file. Was giving an 'Illegal token' syntax error. From 67659773ccfd927ca86b35c31c7bb338532c2729 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 2 Sep 2013 19:14:20 +0100 Subject: [PATCH 0697/1160] Remove some Java references from C# module --- Source/Modules/csharp.cxx | 6 +++--- Source/Modules/java.cxx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 44db84264..d30f278fc 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -4028,7 +4028,7 @@ public: Delete(director_ctor_code); director_ctor_code = NewString("$director_new"); - Java_director_declaration(n); + directorDeclaration(n); Printf(f_directors_h, "%s {\n", Getattr(n, "director:decl")); Printf(f_directors_h, "\npublic:\n"); @@ -4148,13 +4148,13 @@ public: } /*---------------------------------------------------------------------- - * Java_director_declaration() + * directorDeclaration() * * Generate the director class's declaration * e.g. "class SwigDirector_myclass : public myclass, public Swig::Director {" *--------------------------------------------------------------------*/ - void Java_director_declaration(Node *n) { + void directorDeclaration(Node *n) { String *base = Getattr(n, "classtype"); String *class_ctor = NewString("Swig::Director()"); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index b99bbb4ee..24435ac30 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -4221,7 +4221,7 @@ public: Delete(director_ctor_code); director_ctor_code = NewString("$director_new"); - Java_director_declaration(n); + directorDeclaration(n); Printf(f_directors_h, "%s {\n", Getattr(n, "director:decl")); Printf(f_directors_h, "\npublic:\n"); @@ -4405,13 +4405,13 @@ public: } /*---------------------------------------------------------------------- - * Java_director_declaration() + * directorDeclaration() * * Generate the director class's declaration * e.g. "class SwigDirector_myclass : public myclass, public Swig::Director {" *--------------------------------------------------------------------*/ - void Java_director_declaration(Node *n) { + void directorDeclaration(Node *n) { String *base = Getattr(n, "classtype"); String *class_ctor = NewString("Swig::Director(jenv)"); From f47075ec991716733d7e3588aea5e58673c004ff Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 3 Sep 2013 23:58:05 +0100 Subject: [PATCH 0698/1160] Smart pointer documentation improvement --- Doc/Manual/SWIGPlus.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index 716882f53..2713725d7 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -4433,7 +4433,7 @@ around some other class. For example: template<class T> class SmartPtr { T *pointee; public: - ... + SmartPtr(T *p) : pointee(p) { ... } T *operator->() { return pointee; } @@ -4453,7 +4453,7 @@ typedef SmartPtr<Foo_Impl> Foo; // Create smart pointer Foo Foo make_Foo() { - return SmartPtr(new Foo_Impl()); + return SmartPtr<Foo_Impl>(new Foo_Impl()); } // Do something with smart pointer Foo @@ -4461,6 +4461,9 @@ void do_something(Foo f) { printf("x = %d\n", f->x); f->bar(); } + +// Call the wrapped smart pointer proxy class in the target language 'Foo' +%template(Foo) SmartPtr<Foo_Impl>; From a91cd0bc5c1550bfa2c922c7434323c30ca1fb87 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 12 Sep 2013 07:23:54 +0100 Subject: [PATCH 0699/1160] Infinity is now by default an acceptable value for type 'float'. This fix makes the handling of type 'float' and 'double' the same. The implementation requires the C99 isfinite() macro, or otherwise some platform dependent equivalents, to be available. --- CHANGES.current | 16 ++++++ Examples/test-suite/common.mk | 3 +- Examples/test-suite/overload_numeric.i | 51 +++++++++++++++++++ .../python/overload_numeric_runme.py | 43 ++++++++++++++++ Lib/typemaps/fragments.swg | 32 +++++++++++- Lib/typemaps/primtypes.swg | 2 +- 6 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 Examples/test-suite/overload_numeric.i create mode 100644 Examples/test-suite/python/overload_numeric_runme.py diff --git a/CHANGES.current b/CHANGES.current index ffb805ccd..77d2df753 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,22 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.11 (in progress) ============================ +2013-09-12: wsfulton + [UTL] Infinity is now by default an acceptable value for type 'float'. This fix makes + the handling of type 'float' and 'double' the same. The implementation requires the + C99 isfinite() macro, or otherwise some platform dependent equivalents, to be available. + + Users requiring the old behaviour of not accepting infinity, can define a 'check' typemap + wherever a float is used, such as: + + %typemap(check,fragment="") float, const float & %{ + if ($1 < -FLT_MAX || $1 > FLT_MAX) { + SWIG_exception_fail(SWIG_TypeError, "Overflow in type float"); + } + %} + + *** POTENTIAL INCOMPATIBILITY *** + 2013-08-30: wsfulton [Lua] Pull Git patch #81: Include Lua error locus in SWIG error messages. This is standard information in Lua error messages, and makes it much diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 5d6a4730a..997f8e715 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -285,8 +285,9 @@ CPP_TEST_CASES += \ operbool \ ordering \ overload_copy \ - overload_method \ overload_extend \ + overload_method \ + overload_numeric \ overload_rename \ overload_return_type \ overload_simple \ diff --git a/Examples/test-suite/overload_numeric.i b/Examples/test-suite/overload_numeric.i new file mode 100644 index 000000000..44c3b811c --- /dev/null +++ b/Examples/test-suite/overload_numeric.i @@ -0,0 +1,51 @@ +%module overload_numeric + +// Tests overloading of integral and floating point types to verify the range checking required +// for dispatch to the correct overloaded method + +#ifdef SWIGLUA +// lua only has one numeric type, so most of the overloads shadow each other creating warnings +%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) Nums::over; +#endif + +%{ +#include +%} + +%inline %{ +#include +#include +struct Limits { + signed char schar_min() { return SCHAR_MIN; } + signed char schar_max() { return SCHAR_MAX; } + short shrt_min() { return SHRT_MIN; } + short shrt_max() { return SHRT_MAX; } + int int_min() { return INT_MIN; } + int int_max() { return INT_MAX; } + float flt_min() { return FLT_MIN; } + float flt_max() { return FLT_MAX; } + double dbl_max() { return DBL_MAX; } +}; + +struct Nums { + const char * over(signed char v) { + return "signed char"; + } + const char * over(short v) { + return "short"; + } + const char * over(int v) { + return "int"; + } + const char * over(float v) { + return "float"; + } + const char * over(double v) { + return "double"; + } + double doublebounce(double v) { + return v; + } +}; +%} + diff --git a/Examples/test-suite/python/overload_numeric_runme.py b/Examples/test-suite/python/overload_numeric_runme.py new file mode 100644 index 000000000..639fb5e5d --- /dev/null +++ b/Examples/test-suite/python/overload_numeric_runme.py @@ -0,0 +1,43 @@ + +from overload_numeric import * +import math + +nums = Nums() +limits = Limits() + +def check(got, expected): + if got != expected: + raise RuntimeError("got: " + got + " expected: " + expected) + +check(nums.over(0), "signed char") +check(nums.over(0.0), "float") + +check(nums.over(limits.schar_min()), "signed char") +check(nums.over(limits.schar_max()), "signed char") + +check(nums.over(limits.schar_min()-1), "short") +check(nums.over(limits.schar_max()+1), "short") +check(nums.over(limits.shrt_min()), "short") +check(nums.over(limits.shrt_max()), "short") + +check(nums.over(limits.shrt_min()-1), "int") +check(nums.over(limits.shrt_max()+1), "int") +check(nums.over(limits.int_min()), "int") +check(nums.over(limits.int_max()), "int") + +check(nums.over(limits.flt_min()), "float") +check(nums.over(limits.flt_max()), "float") + +check(nums.over(limits.flt_max()*10), "double") +check(nums.over(-limits.flt_max()*10), "double") +check(nums.over(limits.dbl_max()), "double") +check(nums.over(-limits.dbl_max()), "double") + +check(nums.over(float("inf")), "float") +check(nums.over(float("-inf")), "float") +check(nums.over(float("nan")), "float") + +# Just check if the following are accepted without exceptions being thrown +nums.doublebounce(float("inf")) +nums.doublebounce(float("-inf")) +nums.doublebounce(float("nan")) diff --git a/Lib/typemaps/fragments.swg b/Lib/typemaps/fragments.swg index 4dbc1f20d..8f887e34e 100644 --- a/Lib/typemaps/fragments.swg +++ b/Lib/typemaps/fragments.swg @@ -153,6 +153,29 @@ #include %} +%fragment("SWIG_isfinite","header",fragment=",") %{ +/* Getting isfinite working pre C99 across multiple platforms is non-trivial. Users can provide SWIG_isfinite on older platforms. */ +#ifndef SWIG_isfinite +# if defined(isfinite) +# define SWIG_isfinite(X) (isfinite(X)) +# elif defined(_MSC_VER) +# define SWIG_isfinite(X) (_finite(X)) +# elif defined(__sun) && defined(__SVR4) +# include +# define SWIG_isfinite(X) (finite(X)) +# endif +#endif +%} + +%fragment("SWIG_Float_Overflow_Check","header",fragment=",SWIG_isfinite") %{ +/* Accept infinite as a valid float value unless we are unable to check if a value is finite */ +#ifdef SWIG_isfinite +# define SWIG_Float_Overflow_Check(X) ((X < -FLT_MAX || X > FLT_MAX) && SWIG_isfinite(X)) +#else +# define SWIG_Float_Overflow_Check(X) ((X < -FLT_MAX || X > FLT_MAX)) +#endif +%} + /* ----------------------------------------------------------------------------- * special macros for fragments * ----------------------------------------------------------------------------- */ @@ -213,13 +236,20 @@ SWIG_AsVal_dec(Type)(SWIG_Object obj, Type *val) %enddef -/* Macro for 'double' derived types */ +/* Macro for floating point derived types (original macro) */ %define %numeric_double(Type, Frag, Min, Max) %numeric_type_from(Type, double) %numeric_signed_type_asval(Type, double, Frag , Min, Max) %enddef +/* Macro for floating point derived types */ + +%define %numeric_float(Type, Frag, OverflowCond) +%numeric_type_from(Type, double) +%numeric_type_asval(Type, double, Frag, OverflowCond) +%enddef + /* Macros for missing fragments */ diff --git a/Lib/typemaps/primtypes.swg b/Lib/typemaps/primtypes.swg index cc8a55e6e..45632c31f 100644 --- a/Lib/typemaps/primtypes.swg +++ b/Lib/typemaps/primtypes.swg @@ -139,7 +139,7 @@ SWIG_AsVal_dec(bool)(SWIG_Object obj, bool *val) /* float */ -%numeric_double(float, "", -FLT_MAX, FLT_MAX) +%numeric_float(float, "SWIG_Float_Overflow_Check", SWIG_Float_Overflow_Check(v)) /* long/unsigned long */ From c3f3880d0c55f55d9f83dd2d84be685b6b361cc7 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Thu, 12 Sep 2013 19:49:51 +0100 Subject: [PATCH 0700/1160] Lua static member access improvements. 1) Static members and static functions inside class can be accessed as ModuleName.ClassName.FunctionName (MemberName respectively). Old way aka ModuleName.ClassName_FunctionName still works. 2) Same goes for enums inside classes: ModuleName.ClassName.EnumValue1 etc. 3) More 'runme' tests for lua + modifications to existing tests to test new changes. Code is loosely based upon python implemenation of the same thing. Patch #62. --- CHANGES.current | 7 + Examples/test-suite/lua/cpp_basic_runme.lua | 6 + Lib/lua/luarun.swg | 206 +++++++++++++++++++- Source/Modules/lua.cxx | 129 +++++++++++- 4 files changed, 335 insertions(+), 13 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 77d2df753..b2f007a92 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,13 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.11 (in progress) ============================ +2013-09-12: wsfulton + [Lua] Pull Git patch #62. + 1) Static members and static functions inside class can be accessed as + ModuleName.ClassName.FunctionName (MemberName respectively). Old way such as + ModuleName.ClassName_FunctionName still works. + 2) Same goes for enums inside classes: ModuleName.ClassName.EnumValue1 etc. + 2013-09-12: wsfulton [UTL] Infinity is now by default an acceptable value for type 'float'. This fix makes the handling of type 'float' and 'double' the same. The implementation requires the diff --git a/Examples/test-suite/lua/cpp_basic_runme.lua b/Examples/test-suite/lua/cpp_basic_runme.lua index 02f88479b..3d5ccaadf 100644 --- a/Examples/test-suite/lua/cpp_basic_runme.lua +++ b/Examples/test-suite/lua/cpp_basic_runme.lua @@ -42,16 +42,22 @@ assert(f3.num==32) f4=cb.Foo(6) cb.Bar_global_fptr=f4 assert(cb.Bar_global_fptr.num==6) +assert(cb.Bar.global_fptr.num==6) f4.num=8 assert(cb.Bar_global_fptr.num==8) +assert(cb.Bar.global_fptr.num==8) assert(cb.Bar_global_fref.num==23) +assert(cb.Bar.global_fref.num==23) cb.Bar_global_fref=cb.Foo(-7) -- this will set the value assert(cb.Bar_global_fref.num==-7) +assert(cb.Bar.global_fref.num==-7) assert(cb.Bar_global_fval.num==3) +assert(cb.Bar.global_fval.num==3) cb.Bar_global_fval=cb.Foo(-34) assert(cb.Bar_global_fval.num==-34) +assert(cb.Bar.global_fval.num==-34) -- Now test member function pointers func1_ptr=cb.get_func1_ptr() diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index c705e38e5..4d851bdb1 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -140,6 +140,15 @@ typedef struct { lua_CFunction setmethod; } swig_lua_attribute; +// Can be used to create namespaces. Currently used to +// wrap class static methods/variables/constants +typedef struct { + const char *name; + swig_lua_method *ns_methods; + swig_lua_attribute *ns_attributes; + swig_lua_const_info *ns_constants; +} swig_lua_namespace; + typedef struct swig_lua_class { const char *name; swig_type_info **type; @@ -147,6 +156,7 @@ typedef struct swig_lua_class { void (*destructor)(void *); swig_lua_method *methods; swig_lua_attribute *attributes; + swig_lua_namespace cls_static; struct swig_lua_class **bases; const char **base_names; } swig_lua_class; @@ -415,6 +425,137 @@ SWIGINTERN void SWIG_Lua_module_add_function(lua_State* L,const char* name,lua_ SWIG_Lua_add_function(L,name,fn); } +/* ----------------------------------------------------------------------------- + * global variable support code: namespaces + * ----------------------------------------------------------------------------- */ + +SWIGINTERN int SWIG_Lua_namespace_get(lua_State* L) +{ +/* there should be 2 params passed in + (1) table (not the meta table) + (2) string name of the attribute +*/ + assert(lua_istable(L,-2)); /* just in case */ + lua_getmetatable(L,-2); + assert(lua_istable(L,-1)); + SWIG_Lua_get_table(L,".get"); /* find the .get table */ + assert(lua_istable(L,-1)); + /* look for the key in the .get table */ + lua_pushvalue(L,2); /* key */ + lua_rawget(L,-2); + lua_remove(L,-2); /* stack tidy, remove .get table */ + if (lua_iscfunction(L,-1)) + { /* found it so call the fn & return its value */ + lua_call(L,0,1); /* 1 value in (userdata),1 out (result) */ + lua_remove(L,-2); /* stack tidy, remove metatable */ + return 1; + } + lua_pop(L,1); /* remove whatever was there */ + /* ok, so try the .fn table */ + SWIG_Lua_get_table(L,".fn"); /* find the .get table */ + assert(lua_istable(L,-1)); /* just in case */ + lua_pushvalue(L,2); /* key */ + lua_rawget(L,-2); /* look for the fn */ + lua_remove(L,-2); /* stack tidy, remove .fn table */ + if (lua_isfunction(L,-1)) /* note: whether it's a C function or lua function */ + { /* found it so return the fn & let lua call it */ + lua_remove(L,-2); /* stack tidy, remove metatable */ + return 1; + } + lua_pop(L,1); /* remove whatever was there */ + return 0; +} + +SWIGINTERN int SWIG_Lua_namespace_set(lua_State* L) +{ +/* there should be 3 params passed in + (1) table (not the meta table) + (2) string name of the attribute + (3) any for the new value +*/ + + assert(lua_istable(L,1)); + lua_getmetatable(L,1); /* get the meta table */ + assert(lua_istable(L,-1)); + + SWIG_Lua_get_table(L,".set"); /* find the .set table */ + if (lua_istable(L,-1)) + { + /* look for the key in the .set table */ + lua_pushvalue(L,2); /* key */ + lua_rawget(L,-2); + if (lua_iscfunction(L,-1)) + { /* found it so call the fn & return its value */ + lua_pushvalue(L,3); /* value */ + lua_call(L,1,0); + return 0; + } + lua_pop(L,1); /* remove the value */ + } + lua_pop(L,1); /* remove the value .set table */ + return 0; +} + +SWIGINTERN void SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]); // forward declaration +SWIGINTERN void SWIG_Lua_add_class_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn); // forward declaration + +/* helper function - register namespace methods and attributes into namespace */ +SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* ns) +{ + int i = 0; + assert(lua_istable(L,-1)); + /* There must be table at the top of the stack */ + SWIG_Lua_InstallConstants(L, ns->ns_constants); + + lua_getmetatable(L,-1); + + /* add fns */ + for(i=0;ns->ns_attributes[i].name;i++){ + SWIG_Lua_add_class_variable(L,ns->ns_attributes[i].name,ns->ns_attributes[i].getmethod,ns->ns_attributes[i].setmethod); + } + + /* add methods to the metatable */ + SWIG_Lua_get_table(L,".fn"); /* find the .fn table */ + assert(lua_istable(L,-1)); /* just in case */ + for(i=0;ns->ns_methods[i].name;i++){ + SWIG_Lua_add_function(L,ns->ns_methods[i].name,ns->ns_methods[i].method); + } + lua_pop(L,1); + + /* clear stack - remove metatble */ + lua_pop(L,1); + +} + +/* helper function. creates namespace table and add it to module table */ +SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns) +{ + assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table */ + lua_checkstack(L,5); + lua_pushstring(L, ns->name); + lua_newtable(L); /* namespace itself */ + lua_newtable(L); /* metatable for namespace */ + + /* add a table called ".get" */ + lua_pushstring(L,".get"); + lua_newtable(L); + lua_rawset(L,-3); + /* add a table called ".set" */ + lua_pushstring(L,".set"); + lua_newtable(L); + lua_rawset(L,-3); + /* add a table called ".fn" */ + lua_pushstring(L,".fn"); + lua_newtable(L); + lua_rawset(L,-3); + + /* add accessor fns for using the .get,.set&.fn */ + SWIG_Lua_add_function(L,"__index",SWIG_Lua_namespace_get); + SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_namespace_set); + + lua_setmetatable(L,-2); /* set metatable */ + lua_rawset(L,-3); /* add namespace to module table */ +} /* ----------------------------------------------------------------------------- * global variable support code: classes * ----------------------------------------------------------------------------- */ @@ -570,6 +711,23 @@ SWIGINTERN int SWIG_Lua_class_disown(lua_State* L) return 0; } +/* Constructor proxy. Used when class name entry in module is not class constructor, +but special table instead. */ +SWIGINTERN int SWIG_Lua_constructor_proxy(lua_State* L) +{ + /* unlimited number of parameters + First one is our proxy table and we should remove it + Other we should pass to real constructor + */ + assert(lua_istable(L,1)); + lua_pushstring(L,".constructor"); + lua_rawget(L,1); + assert(!lua_isnil(L,-1)); + lua_replace(L,1); /* replace our table with real constructor */ + lua_call(L,lua_gettop(L)-1,1); + return 1; +} + /* gets the swig class registry (or creates it) */ SWIGINTERN void SWIG_Lua_get_class_registry(lua_State* L) { @@ -614,6 +772,21 @@ SWIGINTERN void SWIG_Lua_add_class_variable(lua_State* L,const char* name,lua_C } } +/* helper to recursively add class static details (static attributes, operations and constants) */ +SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State* L, swig_lua_class* clss) +{ + int i = 0; + /* The class namespace table must be on the top of the stack */ + assert(lua_istable(L,-1)); + /* call all the base classes first: we can then override these later: */ + for(i=0;clss->bases[i];i++) + { + SWIG_Lua_add_class_static_details(L,clss->bases[i]); + } + + SWIG_Lua_add_namespace_details(L, &clss->cls_static); +} + /* helper to recursively add class details (attributes & operations) */ SWIGINTERN void SWIG_Lua_add_class_details(lua_State* L,swig_lua_class* clss) { @@ -667,15 +840,42 @@ SWIGINTERN void SWIG_Lua_init_base_class(lua_State* L,swig_lua_class* clss) } } -/* performs the entire class registration process */ -SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss) +/* Register class static methods,attributes etc as well as constructor proxy */ +SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* clss) { + lua_checkstack(L,5); /* just in case */ + assert(lua_istable(L,-1)); /* just in case */ + assert(strcmp(clss->name, clss->cls_static.name) == 0); /* in class those 2 must be equal */ + + SWIG_Lua_namespace_register(L,&clss->cls_static); + + SWIG_Lua_get_table(L,clss->name); // Get namespace table back + assert(lua_istable(L,-1)); /* just in case */ + /* add its constructor to module with the name of the class so you can do MyClass(...) as well as new_MyClass(...) BUT only if a constructor is defined (this overcomes the problem of pure virtual classes without constructors)*/ if (clss->constructor) - SWIG_Lua_add_function(L,clss->name,clss->constructor); + { + SWIG_Lua_add_function(L,".constructor", clss->constructor); + lua_getmetatable(L,-1); + assert(lua_istable(L,-1)); /* just in case */ + SWIG_Lua_add_function(L,"__call", SWIG_Lua_constructor_proxy); + lua_pop(L,1); + } + + assert(lua_istable(L,-1)); /* just in case */ + SWIG_Lua_add_class_static_details(L, clss); + + /* clear stack */ + lua_pop(L,1); +} + +/* performs the entire class registration process */ +SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss) +{ + SWIG_Lua_class_register_static(L,clss); SWIG_Lua_get_class_registry(L); /* get the registry */ lua_pushstring(L,clss->name); /* get the name */ diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index cff3107db..b76945b95 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -45,6 +45,7 @@ */ #include "swigmod.h" +#include "cparse.h" /**** Diagnostics: With the #define REPORT(), you can change the amount of diagnostics given @@ -111,6 +112,9 @@ private: String *s_const_tab; // table of global constants String *s_methods_tab; // table of class methods String *s_attr_tab; // table of class attributes + String *s_cls_attr_tab; // table of class static attributes + String *s_cls_methods_tab; // table of class static methods + String *s_cls_const_tab; // tables of class constants(including enums) String *s_luacode; // luacode to be called during init String *s_dot_get; // table of variable 'get' functions String *s_dot_set; // table of variable 'set' functions @@ -154,6 +158,9 @@ public: s_const_tab(0), s_methods_tab(0), s_attr_tab(0), + s_cls_attr_tab(0), + s_cls_methods_tab(0), + s_cls_const_tab(0), s_luacode(0), s_dot_get(0), s_dot_set(0), @@ -736,13 +743,18 @@ public: NEW LANGUAGE NOTE:END ************************************************/ /* Now register the function with the interpreter. */ if (!Getattr(n, "sym:overloaded")) { + //REPORT("dispatchFunction", n); // add_method(n, iname, wname, description); if (current==NO_CPP || current==STATIC_FUNC) { // emit normal fns & static fns + String *wrapname = Swig_name_wrapper(iname); if(elua_ltr || eluac_ltr) Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", iname, "\")", ", LFUNCVAL(", Swig_name_wrapper(iname), ")", "},\n", NIL); else Printv(s_cmd_tab, tab4, "{ \"", iname, "\", ", Swig_name_wrapper(iname), "},\n", NIL); // Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", Swig_name_wrapper(iname), "},\n", NIL); + if (getCurrentClass()) { + Setattr(n,"luaclassobj:wrap:name", wrapname); + } } } else { if (!Getattr(n, "sym:nextSibling")) { @@ -775,6 +787,7 @@ public: look for %typecheck(SWIG_TYPECHECK_*) in the .swg file NEW LANGUAGE NOTE:END ************************************************/ void dispatchFunction(Node *n) { + //REPORT("dispatchFunction", n); /* Last node in overloaded chain */ int maxargs; @@ -822,10 +835,14 @@ public: if (current==NO_CPP || current==STATIC_FUNC) // emit normal fns & static fns Printv(s_cmd_tab, tab4, "{ \"", symname, "\",", wname, "},\n", NIL); + if (getCurrentClass()) + Setattr(n,"luaclassobj:wrap:name", wname); + else + Delete(wname); + DelWrapper(f); Delete(dispatch); Delete(tmp); - Delete(wname); } @@ -878,8 +895,13 @@ public: } else { Printf(s_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, iname, getName, setName); } - Delete(getName); - Delete(setName); + if (getCurrentClass()) { + Setattr(n, "luaclassobj:wrap:get", getName); + Setattr(n, "luaclassobj:wrap:set", setName); + } else { + Delete(getName); + Delete(setName); + } return result; } @@ -887,7 +909,7 @@ public: * constantWrapper() * ------------------------------------------------------------ */ virtual int constantWrapper(Node *n) { - // REPORT("constantWrapper", n); + REPORT("constantWrapper", n); String *name = Getattr(n, "name"); String *iname = Getattr(n, "sym:name"); String *nsname = Copy(iname); @@ -923,6 +945,20 @@ public: Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); return SWIG_NOWRAP; } + if (cparse_cplusplus && getCurrentClass()) { + // Additionally add to class constants + Swig_require("luaclassobj_constantWrapper", n, "*sym:name", "luaclassobj:symname", NIL); + Setattr(n, "sym:name", Getattr(n, "luaclassobj:symname")); + String *cls_nsname = Getattr(n, "sym:name"); + if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) { + Replaceall(tm, "$source", value); + Replaceall(tm, "$target", name); + Replaceall(tm, "$value", value); + Replaceall(tm, "$nsname", cls_nsname); + Printf(s_cls_const_tab, " %s,\n", tm); + } + Swig_restore(n); + } Delete(nsname); return SWIG_OK; } @@ -1009,6 +1045,19 @@ public: Printf(s_methods_tab, "static swig_lua_method swig_"); Printv(s_methods_tab, mangled_classname, "_methods[] = {\n", NIL); + s_cls_methods_tab = NewString(""); + Printf(s_cls_methods_tab, "static swig_lua_method swig_"); + Printv(s_cls_methods_tab, mangled_classname, "_cls_methods[] = {\n", NIL); + + s_cls_attr_tab = NewString(""); + Printf(s_cls_attr_tab, "static swig_lua_attribute swig_"); + Printv(s_cls_attr_tab, mangled_classname, "_cls_attributes[] = {\n", NIL); + + s_cls_const_tab = NewString(""); + Printf(s_cls_const_tab, "static swig_lua_const_info swig_"); + Printv(s_cls_const_tab, mangled_classname, "_cls_constants[] = {\n", NIL); + + // Generate normal wrappers Language::classHandler(n); @@ -1047,8 +1096,21 @@ public: Printf(s_attr_tab, " {0,0,0}\n};\n"); Printv(f_wrappers, s_attr_tab, NIL); + Printf(s_cls_attr_tab, " {0,0,0}\n};\n"); + Printv(f_wrappers, s_cls_attr_tab, NIL); + + Printf(s_cls_methods_tab, " {0,0}\n};\n"); + Printv(f_wrappers, s_cls_methods_tab, NIL); + + Printf(s_cls_const_tab, " {0,0,0,0,0,0}\n};\n"); + Printv(f_wrappers, s_cls_const_tab, NIL); + + Delete(s_methods_tab); Delete(s_attr_tab); + Delete(s_cls_methods_tab); + Delete(s_cls_attr_tab); + Delete(s_cls_const_tab); // Handle inheritance // note: with the idea of class hierarchies spread over multiple modules @@ -1122,7 +1184,10 @@ public: } else { Printf(f_wrappers, ",0"); } - Printf(f_wrappers, ", swig_%s_methods, swig_%s_attributes, swig_%s_bases, swig_%s_base_names };\n\n", mangled_classname, mangled_classname, mangled_classname, mangled_classname); + Printf(f_wrappers, ", swig_%s_methods, swig_%s_attributes, { \"%s\", swig_%s_cls_methods, swig_%s_cls_attributes, swig_%s_cls_constants }, swig_%s_bases, swig_%s_base_names };\n\n", + mangled_classname, mangled_classname, + class_name, mangled_classname, mangled_classname, mangled_classname, + mangled_classname, mangled_classname); // Printv(f_wrappers, ", swig_", mangled_classname, "_methods, swig_", mangled_classname, "_attributes, swig_", mangled_classname, "_bases };\n\n", NIL); // Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, &_wrap_class_", mangled_classname, "},\n", NIL); @@ -1232,8 +1297,30 @@ public: * ---------------------------------------------------------------------- */ virtual int staticmemberfunctionHandler(Node *n) { + REPORT("staticmemberfunctionHandler", n); current = STATIC_FUNC; - return Language::staticmemberfunctionHandler(n); + String *symname = Getattr(n, "sym:name"); + int result = Language::staticmemberfunctionHandler(n); + + if (cparse_cplusplus && getCurrentClass()) { + Swig_restore(n); + } + current = NO_CPP; + if (result != SWIG_OK) + return result; + + if (Getattr(n, "sym:nextSibling")) + return SWIG_OK; + + Swig_require("luaclassobj_staticmemberfunctionHandler", n, "luaclassobj:wrap:name", NIL); + String *name = Getattr(n, "name"); + String *rname, *realname; + realname = symname ? symname : name; + rname = Getattr(n, "luaclassobj:wrap:name"); + Printv(s_cls_methods_tab, tab4, "{\"", realname, "\", ", rname, "}, \n", NIL); + Swig_restore(n); + + return SWIG_OK; } /* ------------------------------------------------------------ @@ -1243,8 +1330,17 @@ public: * ------------------------------------------------------------ */ virtual int memberconstantHandler(Node *n) { - // REPORT("memberconstantHandler",n); - return Language::memberconstantHandler(n); + REPORT("memberconstantHandler",n); + String *symname = Getattr(n, "sym:name"); + if (cparse_cplusplus && getCurrentClass()) { + Swig_save("luaclassobj_memberconstantHandler", n, "luaclassobj:symname", NIL); + Setattr(n, "luaclassobj:symname", symname); + } + int result = Language::memberconstantHandler(n); + if (cparse_cplusplus && getCurrentClass()) + Swig_restore(n); + + return result; } /* --------------------------------------------------------------------- @@ -1252,9 +1348,22 @@ public: * --------------------------------------------------------------------- */ virtual int staticmembervariableHandler(Node *n) { - // REPORT("staticmembervariableHandler",n); + REPORT("staticmembervariableHandler",n); current = STATIC_VAR; - return Language::staticmembervariableHandler(n); + String *symname = Getattr(n, "sym:name"); + int result = Language::staticmembervariableHandler(n); + + if (result != SWIG_OK) + return result; + + + if (Getattr(n, "wrappedasconstant")) + return SWIG_OK; + + Swig_require("luaclassobj_staticmembervariableHandler", n, "luaclassobj:wrap:get", "luaclassobj:wrap:set", NIL); + Printf(s_cls_attr_tab,"%s{ \"%s\", %s, %s},\n",tab4,symname,Getattr(n,"luaclassobj:wrap:get"), Getattr(n,"luaclassobj:wrap:set")); + Swig_restore(n); + return SWIG_OK; } /* --------------------------------------------------------------------- From 7a88729c87487c13163748c24b95196674f8ed21 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 13 Sep 2013 09:36:26 +0200 Subject: [PATCH 0701/1160] Remove trailing spaces in the generated code. No functional changes --- Lib/swigerrors.swg | 20 ++++---- Lib/swiginit.swg | 24 +++++----- Lib/swiglabels.swg | 12 ++--- Lib/swigrun.swg | 96 ++++++++++++++++++------------------- Lib/typemaps/swigmacros.swg | 58 +++++++++++----------- Source/Swig/misc.c | 8 ++-- 6 files changed, 109 insertions(+), 109 deletions(-) diff --git a/Lib/swigerrors.swg b/Lib/swigerrors.swg index 32857c498..1a6d20366 100644 --- a/Lib/swigerrors.swg +++ b/Lib/swigerrors.swg @@ -1,16 +1,16 @@ /* 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_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_MemoryError -12 #define SWIG_NullReferenceError -13 diff --git a/Lib/swiginit.swg b/Lib/swiginit.swg index 6fe58d296..f321181eb 100644 --- a/Lib/swiginit.swg +++ b/Lib/swiginit.swg @@ -1,17 +1,17 @@ /* ----------------------------------------------------------------------------- * Type initialization: - * This problem is tough by the requirement that no dynamic - * memory is used. Also, since swig_type_info structures store pointers to + * This problem is tough by the requirement that no dynamic + * memory is used. Also, since swig_type_info structures store pointers to * swig_cast_info structures and swig_cast_info structures store pointers back - * to swig_type_info structures, we need some lookup code at initialization. - * The idea is that swig generates all the structures that are needed. - * The runtime then collects these partially filled structures. - * The SWIG_InitializeModule function takes these initial arrays out of + * to swig_type_info structures, we need some lookup code at initialization. + * The idea is that swig generates all the structures that are needed. + * The runtime then collects these partially filled structures. + * The SWIG_InitializeModule function takes these initial arrays out of * swig_module, and does all the lookup, filling in the swig_module.types * array with the correct data and linking the correct swig_cast_info * structures together. * - * The generated swig_type_info structures are assigned staticly to an initial + * The generated swig_type_info structures are assigned staticly to an initial * array. We just loop through that array, and handle each type individually. * First we lookup if this type has been already loaded, and if so, use the * loaded structure instead of the generated one. Then we have to fill in the @@ -21,17 +21,17 @@ * a column is one of the swig_cast_info structures for that type. * The cast_initial array is actually an array of arrays, because each row has * a variable number of columns. So to actually build the cast linked list, - * we find the array of casts associated with the type, and loop through it + * we find the array of casts associated with the type, and loop through it * adding the casts to the list. The one last trick we need to do is making * sure the type pointer in the swig_cast_info struct is correct. * - * First off, we lookup the cast->type name to see if it is already loaded. + * First off, we lookup the cast->type name to see if it is already loaded. * There are three cases to handle: * 1) If the cast->type has already been loaded AND the type we are adding * casting info to has not been loaded (it is in this module), THEN we * replace the cast->type pointer with the type pointer that has already * been loaded. - * 2) If BOTH types (the one we are adding casting info to, and the + * 2) If BOTH types (the one we are adding casting info to, and the * cast->type) are loaded, THEN the cast info has already been loaded by * the previous module so we just ignore it. * 3) Finally, if cast->type has not already been loaded, then we add that @@ -108,7 +108,7 @@ SWIG_InitializeModule(void *clientdata) { swig_type_info *type = 0; swig_type_info *ret; swig_cast_info *cast; - + #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); #endif @@ -135,7 +135,7 @@ SWIG_InitializeModule(void *clientdata) { /* Insert casting types */ cast = swig_module.cast_initial[i]; while (cast->type) { - + /* Don't need to add information already in the list */ ret = 0; #ifdef SWIGRUNTIME_DEBUG diff --git a/Lib/swiglabels.swg b/Lib/swiglabels.swg index b943afb47..d428ac33d 100644 --- a/Lib/swiglabels.swg +++ b/Lib/swiglabels.swg @@ -29,28 +29,28 @@ #ifndef SWIGUNUSED # if defined(__GNUC__) # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define SWIGUNUSED __attribute__ ((__unused__)) +# define SWIGUNUSED __attribute__ ((__unused__)) # else # define SWIGUNUSED # endif # elif defined(__ICC) -# define SWIGUNUSED __attribute__ ((__unused__)) +# define SWIGUNUSED __attribute__ ((__unused__)) # else -# define SWIGUNUSED +# define SWIGUNUSED # endif #endif #ifndef SWIG_MSC_UNSUPPRESS_4505 # if defined(_MSC_VER) # pragma warning(disable : 4505) /* unreferenced local function has been removed */ -# endif +# endif #endif #ifndef SWIGUNUSEDPARM # ifdef __cplusplus # define SWIGUNUSEDPARM(p) # else -# define SWIGUNUSEDPARM(p) p SWIGUNUSED +# define SWIGUNUSEDPARM(p) p SWIGUNUSED # endif #endif @@ -93,7 +93,7 @@ # define SWIGSTDCALL __stdcall # else # define SWIGSTDCALL -# endif +# endif #endif /* Deal with Microsoft's attempt at deprecating C standard runtime functions */ diff --git a/Lib/swigrun.swg b/Lib/swigrun.swg index 21f0a5c14..7066e670e 100644 --- a/Lib/swigrun.swg +++ b/Lib/swigrun.swg @@ -22,7 +22,7 @@ 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 strictly necessary, ie, if you have problems with your compiler or suchlike. */ @@ -48,16 +48,16 @@ #define SWIG_POINTER_OWN 0x1 -/* +/* Flags/methods for returning states. - - The SWIG conversion methods, as ConvertPtr, return an 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). - + Use the following macros/flags to set or process the returning states. - + In old versions of SWIG, code such as the following was usually written: if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { @@ -90,23 +90,23 @@ } 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 also requires SWIG_ConvertPtr to return new result values, such as - int SWIG_ConvertPtr(obj, ptr,...) { - if () { - if () { - *ptr = ; - return SWIG_NEWOBJ; - } else { - *ptr = ; - return SWIG_OLDOBJ; - } - } else { - return SWIG_BADOBJ; - } + 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 @@ -120,17 +120,17 @@ 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_OK (0) #define SWIG_ERROR (-1) #define SWIG_IsOK(r) (r >= 0) -#define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) +#define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) /* The CastRankLimit says how many bits are used for the cast rank */ #define SWIG_CASTRANKLIMIT (1 << 8) @@ -161,11 +161,11 @@ # endif # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) -SWIGINTERNINLINE int SWIG_AddCast(int r) { +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; +SWIGINTERNINLINE int SWIG_CheckState(int r) { + return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; } #else /* no cast-rank mode */ # define SWIG_AddCast(r) (r) @@ -212,7 +212,7 @@ typedef struct swig_module_info { void *clientdata; /* Language specific module data */ } swig_module_info; -/* +/* Compare two type names skipping the space characters, therefore "char*" == "char *" and "Class" == "Class", etc. @@ -285,7 +285,7 @@ SWIG_TypeCheck(const char *c, swig_type_info *ty) { return 0; } -/* +/* Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison */ SWIGRUNTIME swig_cast_info * @@ -320,7 +320,7 @@ SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); } -/* +/* Dynamic pointer casting. Down an inheritance hierarchy */ SWIGRUNTIME swig_type_info * @@ -364,7 +364,7 @@ SWIG_TypePrettyName(const swig_type_info *type) { return type->name; } -/* +/* Set the clientdata field for a type */ SWIGRUNTIME void @@ -372,14 +372,14 @@ 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; } } @@ -388,18 +388,18 @@ 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. + + 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, +SWIG_MangledTypeQueryModule(swig_module_info *start, + swig_module_info *end, const char *name) { swig_module_info *iter = start; do { @@ -408,11 +408,11 @@ SWIG_MangledTypeQueryModule(swig_module_info *start, register size_t r = iter->size - 1; do { /* since l+r >= 0, we can (>> 1) instead (/ 2) */ - register size_t i = (l + r) >> 1; + 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) { + if (compare == 0) { return iter->types[i]; } else if (compare < 0) { if (i) { @@ -437,14 +437,14 @@ SWIG_MangledTypeQueryModule(swig_module_info *start, 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. + + 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, +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); @@ -463,12 +463,12 @@ SWIG_TypeQueryModule(swig_module_info *start, iter = iter->next; } while (iter != end); } - + /* neither found a match */ return 0; } -/* +/* Pack binary data into a string */ SWIGRUNTIME char * @@ -484,7 +484,7 @@ SWIG_PackData(char *c, void *ptr, size_t sz) { return c; } -/* +/* Unpack binary data from a string */ SWIGRUNTIME const char * @@ -498,21 +498,21 @@ SWIG_UnpackData(const char *c, void *ptr, size_t sz) { uu = ((d - '0') << 4); else if ((d >= 'a') && (d <= 'f')) uu = ((d - ('a'-10)) << 4); - else + 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 + else return (char *) 0; *u = uu; } return c; } -/* +/* Pack 'void *' into a string buffer. */ SWIGRUNTIME char * diff --git a/Lib/typemaps/swigmacros.swg b/Lib/typemaps/swigmacros.swg index e95e7af92..c9b42facf 100644 --- a/Lib/typemaps/swigmacros.swg +++ b/Lib/typemaps/swigmacros.swg @@ -9,9 +9,9 @@ -------------------------- %arg(Arg) Safe argument wrap - %str(Arg) Stringtify the argument - %begin_block Begin a execution block - %end_block End a execution block + %str(Arg) Stringtify the argument + %begin_block Begin a execution block + %end_block End a execution block %block(Block) Execute Block as a excecution block %define_as(Def, Val) Define 'Def' as 'Val', expanding Def and Val first %ifcplusplus(V1, V2) if C++ Mode; then V1; else V2; fi @@ -19,33 +19,33 @@ Casting Operations: ------------------- - + SWIG provides the following casting macros, which implement the corresponding C++ casting operations: - %const_cast(a, Type) const_cast(a) - %static_cast(a, Type) static_cast(a) - %reinterpret_cast(a, Type) reinterpret_cast(a) - %numeric_cast(a, Type) static_cast(a) - %as_voidptr(a) const_cast(static_cast(a)) - %as_voidptrptr(a) reinterpret_cast(a) - + %const_cast(a, Type) const_cast(a) + %static_cast(a, Type) static_cast(a) + %reinterpret_cast(a, Type) reinterpret_cast(a) + %numeric_cast(a, Type) static_cast(a) + %as_voidptr(a) const_cast(static_cast(a)) + %as_voidptrptr(a) reinterpret_cast(a) + or their C unsafe versions. In C++ we use the safe version unless SWIG_NO_CPLUSPLUS_CAST is defined (usually via the -nocppcast swig flag). Memory allocation: ------------------ - + These allocation/freeing macros are safe to use in C or C++ and dispatch the proper new/delete/delete[] or free/malloc calls as needed. - + %new_instance(Type) Allocate a new instance of given Type %new_copy(value,Type) Allocate and initialize a new instance with 'value' %new_array(size,Type) Allocate a new array with given size and Type %new_copy_array(cptr,size,Type) Allocate and initialize a new array from 'cptr' - %delete(cptr) Delete an instance + %delete(cptr) Delete an instance %delete_array(cptr) Delete an array @@ -54,13 +54,13 @@ %formacro(Macro, Args...) or %formacro_1(Macro, Args...) for i in Args - do + do Macro($i) done %formacro_2(Macro2, Args...) for i,j in Args - do + do Macro2($i, $j) done @@ -71,12 +71,12 @@ %mark_flag(flag) flag := True - %evalif(flag,expr) + %evalif(flag,expr) if flag; then expr fi - %evalif_2(flag1 flag2,expr) + %evalif_2(flag1 flag2,expr) if flag1 and flag2; then expr fi @@ -84,7 +84,7 @@ */ /* ----------------------------------------------------------------------------- - * Basic preprocessor macros + * Basic preprocessor macros * ----------------------------------------------------------------------------- */ #define %arg(Arg...) Arg @@ -115,7 +115,7 @@ nocppval %define_as(SWIGVERSION, SWIG_VERSION) %#define SWIG_VERSION SWIGVERSION } -#endif +#endif @@ -153,10 +153,10 @@ nocppval /* ----------------------------------------------------------------------------- - * Allocating/freeing elements + * Allocating/freeing elements * ----------------------------------------------------------------------------- */ -#if defined(__cplusplus) +#if defined(__cplusplus) # define %new_instance(Type...) (new Type) # define %new_copy(val,Type...) (new Type(%static_cast(val, const Type&))) # define %new_array(size,Type...) (new Type[size]) @@ -184,7 +184,7 @@ nocppval /* ----------------------------------------------------------------------------- - * Auxiliary loop macros + * Auxiliary loop macros * ----------------------------------------------------------------------------- */ @@ -213,10 +213,10 @@ nocppval * SWIG flags * ----------------------------------------------------------------------------- */ -/* +/* mark a flag, ie, define a macro name but ignore it in - the interface. - + the interface. + the flag can be later used with %evalif */ @@ -224,16 +224,16 @@ nocppval /* - %evalif and %evalif_2 are use to evaluate or process + %evalif and %evalif_2 are use to evaluate or process an expression if the given predicate is 'true' (1). */ -%define %_evalif(_x,_expr) +%define %_evalif(_x,_expr) #if _x == 1 _expr #endif %enddef -%define %_evalif_2(_x,_y,_expr) +%define %_evalif_2(_x,_y,_expr) #if _x == 1 && _y == 1 _expr #endif diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index efa397878..651b94cf1 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -72,11 +72,11 @@ void Swig_banner(File *f) { Printf(f, "/* ----------------------------------------------------------------------------\n\ * This file was automatically generated by SWIG (http://www.swig.org).\n\ * Version %s\n\ - * \n\ - * This file is not intended to be easily readable and contains a number of \n\ + *\n\ + * This file is not intended to be easily readable and contains a number of\n\ * coding conventions designed to improve portability and efficiency. Do not make\n\ - * changes to this file unless you know what you are doing--modify the SWIG \n\ - * interface file instead. \n", Swig_package_version()); + * changes to this file unless you know what you are doing--modify the SWIG\n\ + * interface file instead.\n", Swig_package_version()); /* String too long for ISO compliance */ Printf(f, " * ----------------------------------------------------------------------------- */\n"); From ba9baefdd93922a585757e18f10e5723a0105202 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 14 Sep 2013 12:53:45 +0100 Subject: [PATCH 0702/1160] sed portability fix creating swigwarn.swg --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 0ac8c88f9..c7972832c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -433,7 +433,7 @@ maintainer-clean: $(srcdir)/Lib/swigwarn.swg: $(srcdir)/Source/Include/swigwarn.h mkdir -p Lib echo "/* SWIG warning codes */" > $@ - cat $? | grep "^#define WARN\|/\*.*\*/\|^[ \t]*$$" | sed 's/^#define \(WARN.*[0-9]\+\)\(.*\)$$/%define SWIG\1 %enddef\2/' >> $@ + cat $? | grep "^#define WARN\|/\*.*\*/\|^[ \t]*$$" | sed 's/^#define \(WARN.*[0-9][0-9]*\)\(.*\)$$/%define SWIG\1 %enddef\2/' >> $@ ##################################################################### # TARGETS: install & friends From c4e29fb686b860584ac1def0dd36a7a3d46310c6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 14 Sep 2013 15:51:50 -0700 Subject: [PATCH 0703/1160] Remove mkstemp replacement for ccache-swig on Cygwin Cygwin 1.7.0 as well as Cygwin 1.7.24 seem to be working okay Cygwin 1.7.24 gives gcc warning about dangerous use of mktemp --- CCache/ccache.h | 2 ++ CCache/util.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CCache/ccache.h b/CCache/ccache.h index 3c3e22311..dcbb03f0c 100644 --- a/CCache/ccache.h +++ b/CCache/ccache.h @@ -200,6 +200,8 @@ typedef int (*COMPAR_FN_T)(const void *, const void *); /* mkstemp() on some versions of cygwin don't handle binary files, so override */ +/* Seems okay in Cygwin 1.7.0 #ifdef __CYGWIN__ #undef HAVE_MKSTEMP #endif +*/ diff --git a/CCache/util.c b/CCache/util.c index bba232492..66f9823b9 100644 --- a/CCache/util.c +++ b/CCache/util.c @@ -82,7 +82,7 @@ void copy_fd(int fd_in, int fd_out) #ifndef HAVE_MKSTEMP /* cheap and nasty mkstemp replacement */ -static int mkstemp(char *template) +int mkstemp(char *template) { mktemp(template); return open(template, O_RDWR | O_CREAT | O_EXCL | O_BINARY, 0600); From cb4a23b2df066b316bc8c427e1849826e4341e95 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 14 Sep 2013 15:52:42 -0700 Subject: [PATCH 0704/1160] Cygwin test-suite fix for tcl 8.5 on Cygwin --- Examples/test-suite/li_windows.i | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Examples/test-suite/li_windows.i b/Examples/test-suite/li_windows.i index 26f96cc3b..c99ffe4ca 100644 --- a/Examples/test-suite/li_windows.i +++ b/Examples/test-suite/li_windows.i @@ -4,6 +4,12 @@ %{ #if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) + // Fix Tcl.h and Windows.h cat and mouse over definition of VOID + #if defined(_TCL) && defined(__CYGWIN__) + #ifdef VOID + #undef VOID + #endif + #endif #include #else // Use equivalent types for non-windows systems From f618a6999041614181272cc95afd290f19e30c6c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 14 Sep 2013 17:32:54 -0700 Subject: [PATCH 0705/1160] Better detection of Ruby shared library extension Use Config to detect dll extension (needs to be .so for Ruby 1.9 on Cygwin) --- Examples/Makefile.in | 5 +++-- configure.ac | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index df754427c..5607feb9e 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -913,6 +913,7 @@ RUBY_INCLUDE= @RUBYINCLUDE@ RUBY_LIB = @RUBYLIB@ RUBY_DLNK = @RUBYDYNAMICLINKING@ RUBY_LIBOPTS = @RUBYLINK@ @LIBS@ $(SYSLIBS) +RUBY_SO = @RUBYSO@ RUBY = @RUBY@ RUBY_SCRIPT = $(RUNME).rb @@ -924,7 +925,7 @@ RUBY_SCRIPT = $(RUNME).rb ruby: $(SRCS) $(SWIG) -ruby $(SWIGOPT) $(INTERFACEPATH) $(CC) -c $(CCSHARED) $(CFLAGS) $(RUBY_CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) $(RUBY_INCLUDE) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(RUBY_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(RUBY_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(RUBY_SO) # ----------------------------------------------------------------- # Build a C++ dynamically loadable module @@ -933,7 +934,7 @@ ruby: $(SRCS) ruby_cpp: $(SRCS) $(SWIG) -c++ -ruby $(SWIGOPT) $(INTERFACEPATH) $(CXX) -c $(CCSHARED) $(CFLAGS) $(RUBY_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(RUBY_INCLUDE) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(RUBY_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(RUBY_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(RUBY_SO) # ----------------------------------------------------------------- # Build statically linked Ruby interpreter diff --git a/configure.ac b/configure.ac index 5b6441b86..c4db3ce98 100644 --- a/configure.ac +++ b/configure.ac @@ -1399,6 +1399,7 @@ if test -n "$RUBY"; then esac RUBYCCDLFLAGS=`($RUBY -rrbconfig -e 'print Config::CONFIG[["CCDLFLAGS"]]') 2>/dev/null` + RUBYSO=.`($RUBY -rrbconfig -e 'print Config::CONFIG[["DLEXT"]]') 2>/dev/null` else AC_MSG_RESULT(could not figure out how to run ruby) RUBYINCLUDE="-I/usr/local/lib/ruby/1.4/arch" @@ -1416,6 +1417,7 @@ AC_SUBST(RUBYINCLUDE) AC_SUBST(RUBYLIB) AC_SUBST(RUBYLINK) AC_SUBST(RUBYCCDLFLAGS) +AC_SUBST(RUBYSO) AC_SUBST(RUBYDYNAMICLINKING) #------------------------------------------------------------------------- From f01b52c44cbab9205a4fd4c2bcac5ba2d12ef460 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 13 Sep 2013 07:15:34 +0100 Subject: [PATCH 0706/1160] Tweak 'make beautify-file' unix2dos and dos2unix were renamed to todos and fromdos - they aren't really needed (on Linux anyway), so removed. --- Source/Makefile.am | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/Makefile.am b/Source/Makefile.am index 984b9c268..40fa4d9f2 100644 --- a/Source/Makefile.am +++ b/Source/Makefile.am @@ -140,8 +140,6 @@ beautify-file: test -n "$(INDENTFILE)" || (echo INDENTFILE not defined && exit 1;) test -e $(INDENTFILE) || (echo File does not exist: $(INDENTFILE) && exit 1;) cp $(INDENTFILE) $(INDENTBAKSDIR)/$(INDENTFILE); - unix2dos $(INDENTFILE) - dos2unix $(INDENTFILE) indent -kr --honour-newlines --line-length160 --indent-level2 --braces-on-func-def-line --leave-optional-blank-lines $(SWIGTYPEDEFS) $(INDENTFILE) -o $(INDENTFILE).tmp; cat $(INDENTFILE).tmp | sed -e 's/const const /const /' > $(INDENTFILE); rm $(INDENTFILE).tmp; From 0431664b18f17774344c79962518acfa4c738746 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 15 Sep 2013 10:43:49 +0100 Subject: [PATCH 0707/1160] Guile OUTPUT typemap fix Fixes 'attempt to free a non-heap object' in some OUTPUT typemaps. --- CHANGES.current | 9 +++++++++ Examples/test-suite/typemap_qualifier_strip.i | 4 ++++ Lib/r/r.swg | 9 ++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index b2f007a92..7e756e912 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,15 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.11 (in progress) ============================ +2013-09-15: wsfulton + [R] Fix attempt to free a non-heap object in OUTPUT typemaps for: + unsigned short *OUTPUT + unsigned long *OUTPUT + signed long long *OUTPUT + char *OUTPUT + signed char*OUTPUT + unsigned char*OUTPUT + 2013-09-12: wsfulton [Lua] Pull Git patch #62. 1) Static members and static functions inside class can be accessed as diff --git a/Examples/test-suite/typemap_qualifier_strip.i b/Examples/test-suite/typemap_qualifier_strip.i index d91a7b109..9b9f24cd8 100644 --- a/Examples/test-suite/typemap_qualifier_strip.i +++ b/Examples/test-suite/typemap_qualifier_strip.i @@ -1,5 +1,9 @@ %module typemap_qualifier_strip +%typemap(freearg) int *ptr "" +%typemap(freearg) int *const ptrConst "" +%typemap(freearg) int const* constPtr "" + %typemap(in) int *ptr { int temp = 1234; $1 = &temp; diff --git a/Lib/r/r.swg b/Lib/r/r.swg index be42ff3a1..126611d61 100644 --- a/Lib/r/r.swg +++ b/Lib/r/r.swg @@ -114,12 +114,19 @@ signed int *OUTPUT, unsigned int *OUTPUT, short *OUTPUT, signed short *OUTPUT, +unsigned short *OUTPUT, long *OUTPUT, signed long *OUTPUT, +unsigned long *OUTPUT, long long *OUTPUT, +signed long long *OUTPUT, unsigned long long *OUTPUT, float *OUTPUT, -double *OUTPUT {} +double *OUTPUT, +char *OUTPUT, +signed char *OUTPUT, +unsigned char *OUTPUT +{} From 80b108eb70229680ad63daa7267d74ccc342dd2c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 15 Sep 2013 15:11:43 +0100 Subject: [PATCH 0708/1160] Add swig-2.0.11 release info and date --- ANNOUNCE | 8 ++++---- CHANGES.current | 2 +- Doc/Manual/Sections.html | 2 +- README | 2 +- RELEASENOTES | 4 ++++ 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 1c3297a5c..caaa55d8c 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,8 +1,8 @@ -*** ANNOUNCE: SWIG 2.0.10 (in progress) *** +*** ANNOUNCE: SWIG 2.0.11 (15 Sep 2013) *** http://www.swig.org -We're pleased to announce SWIG-2.0.10, the latest SWIG release. +We're pleased to announce SWIG-2.0.11, 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.10.tar.gz + http://prdownloads.sourceforge.net/swig/swig-2.0.11.tar.gz A Windows version is also available at - http://prdownloads.sourceforge.net/swig/swigwin-2.0.10.zip + http://prdownloads.sourceforge.net/swig/swigwin-2.0.11.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.current b/CHANGES.current index 7e756e912..1727ecb2c 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,7 +2,7 @@ Below are the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.11 (in progress) +Version 2.0.11 (15 Sep 2013) ============================ 2013-09-15: wsfulton diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 9e4a3dd17..2dfb438f8 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

    SWIG-2.0 Documentation

    -Last update : SWIG-2.0.10 (in progress) +Last update : SWIG-2.0.11 (15 Sep 2013)

    Sections

    diff --git a/README b/README index 444643a0d..946bd9a8f 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.10 (in progress) +Version: 2.0.11 (15 Sep 2013) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, C#, D, Go, Lua, diff --git a/RELEASENOTES b/RELEASENOTES index 49eacf28a..720dc9d34 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -4,6 +4,10 @@ and CHANGES files. Release Notes ============= +SWIG-2.0.11 summary: +- Minor bug fixes and enhancements mostly in Python, but also + C#, Lua, Ocaml, Octave, Perl, PHP, Python, R, Ruby, Tcl. + SWIG-2.0.10 summary: - Ruby 1.9 support is now complete. - Add support for Guile 2.0 and Guile 1.6 support (GH interface) has From b0b8d4c87e0077baccf770441768f5ad3b15dcd3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 15 Sep 2013 22:39:08 +0100 Subject: [PATCH 0709/1160] Add hint about pushing tags post release [ci skip] --- Tools/mkrelease.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/mkrelease.py b/Tools/mkrelease.py index 9eceba07e..0623fe786 100755 --- a/Tools/mkrelease.py +++ b/Tools/mkrelease.py @@ -45,4 +45,4 @@ os.system("rsync --archive --verbose -P --times -e ssh " + "swigwin-" + version print "Finished" -print "Now log in to SourceForge and set the operating systems applicable to the newly uploaded tarball and zip file. Also remember to do a 'git push'." +print "Now log in to SourceForge and set the operating systems applicable to the newly uploaded tarball and zip file. Also remember to do a 'git push --tags'." From 37bccfd517dfebb4d191a144975d04c7ebfdea12 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 17 Sep 2013 23:43:30 +0100 Subject: [PATCH 0710/1160] Bump version to 3.0.0 SWIG 3 is open for business - looks go crazy! --- ANNOUNCE | 8 +-- CHANGES | 138 +++++++++++++++++++++++++++++++++++++++ CHANGES.current | 136 +------------------------------------- Doc/Manual/Sections.html | 6 +- README | 2 +- configure.ac | 2 +- 6 files changed, 148 insertions(+), 144 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index caaa55d8c..90cc9ba24 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,8 +1,8 @@ -*** ANNOUNCE: SWIG 2.0.11 (15 Sep 2013) *** +*** ANNOUNCE: SWIG 3.0.0 (in progress) *** http://www.swig.org -We're pleased to announce SWIG-2.0.11, the latest SWIG release. +We're pleased to announce SWIG-3.0.0, 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.11.tar.gz + http://prdownloads.sourceforge.net/swig/swig-3.0.0.tar.gz A Windows version is also available at - http://prdownloads.sourceforge.net/swig/swigwin-2.0.11.zip + http://prdownloads.sourceforge.net/swig/swigwin-3.0.0.zip Please report problems with this release to the swig-devel mailing list, details at http://www.swig.org/mail.html. diff --git a/CHANGES b/CHANGES index 488bf7286..c70765cf1 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,144 @@ SWIG (Simplified Wrapper and Interface Generator) See the CHANGES.current file for changes in the current version. See the RELEASENOTES file for a summary of changes in each release. + +Version 2.0.11 (15 Sep 2013) +============================ + +2013-09-15: wsfulton + [R] Fix attempt to free a non-heap object in OUTPUT typemaps for: + unsigned short *OUTPUT + unsigned long *OUTPUT + signed long long *OUTPUT + char *OUTPUT + signed char*OUTPUT + unsigned char*OUTPUT + +2013-09-12: wsfulton + [Lua] Pull Git patch #62. + 1) Static members and static functions inside class can be accessed as + ModuleName.ClassName.FunctionName (MemberName respectively). Old way such as + ModuleName.ClassName_FunctionName still works. + 2) Same goes for enums inside classes: ModuleName.ClassName.EnumValue1 etc. + +2013-09-12: wsfulton + [UTL] Infinity is now by default an acceptable value for type 'float'. This fix makes + the handling of type 'float' and 'double' the same. The implementation requires the + C99 isfinite() macro, or otherwise some platform dependent equivalents, to be available. + + Users requiring the old behaviour of not accepting infinity, can define a 'check' typemap + wherever a float is used, such as: + + %typemap(check,fragment="") float, const float & %{ + if ($1 < -FLT_MAX || $1 > FLT_MAX) { + SWIG_exception_fail(SWIG_TypeError, "Overflow in type float"); + } + %} + + *** POTENTIAL INCOMPATIBILITY *** + +2013-08-30: wsfulton + [Lua] Pull Git patch #81: Include Lua error locus in SWIG error messages. + This is standard information in Lua error messages, and makes it much + easier to find bugs. + +2013-08-29: wsfulton + Pull Git patch #75: Handle UTF-8 files with BOM at beginning of file. Was giving an + 'Illegal token' syntax error. + +2013-08-29: wsfulton + [C#] Pull Git patch #77: Allow exporting std::map using non-default comparison function. + +2013-08-28: wsfulton + [Python] %implicitconv is improved for overloaded functions. Like in C++, the methods + with the actual types are considered before trying implicit conversions. Example: + + %implicitconv A; + struct A { + A(int i); + }; + class CCC { + public: + int xx(int i) { return 11; } + int xx(const A& i) { return 22; } + }; + + The following python code: + + CCC().xx(-1) + + will now return 11 instead of 22 - the implicit conversion is not done. + +2013-08-23: olly + [Python] Fix clang++ warning in generated wrapper code. + +2013-08-16: wsfulton + [Python] %implicitconv will now accept None where the implicit conversion takes a C/C++ pointer. + Problem highlighted by Bo Peng. Closes SF patch #230. + +2013-08-07: wsfulton + [Python] SF Patch #326 from Kris Thielemans - Remove SwigPyObject_print and SwigPyObject_str and + make the generated wrapper use the default python implementations, which will fall back to repr + (for -builtin option). + + Advantages: + - it avoids the swig user having to jump through hoops to get print to work as expected when + redefining repr/str slots. + - typing the name of a variable on the python prompt now prints the result of a (possibly redefined) + repr, without the swig user having to do any extra work. + - when redefining repr, the swig user doesn't necessarily have to redefine str as it will call the + redefined repr + - the behaviour is exactly the same as without the -builtin option while requiring no extra work + by the user (aside from adding the %feature("python:slot...) statements of course) + + Disadvantage: + - default str() will give different (but clearer?) output on swigged classes + +2013-07-30: wsfulton + [Python, Ruby] Fix #64 #65: Missing code in std::multimap wrappers. Previously an instantiation + of a std::map was erroneously required in addition to an instantiation of std::multimap with the + same template parameters to prevent compilation errors for the wrappers of a std::multimap. + +2013-07-14: joequant + [R] Change types file to allow for SEXP return values + +2013-07-05: wsfulton + [Python] Add %pythonbegin directive which works like %pythoncode, except the specified code is + added at the beginning of the generated .py file. This is primarily needed for importing from + __future__ statements required to be at the very beginning of the file. Example: + + %pythonbegin %{ + from __future__ import print_function + print("Loading", "Whizz", "Bang", sep=' ... ') + %} + +2013-07-01: wsfulton + [Python] Apply SF patch #340 - Uninitialized variable fix in SWIG_Python_NonDynamicSetAttr + when using -builtin. + +2013-07-01: wsfulton + [Python, Ruby, Ocaml] Apply SF patch #341 - fix a const_cast in generated code that was generating + a <:: digraph when using the unary scope operator (::) (global scope) in a template type. + +2013-07-01: wsfulton + [Python] Add SF patch #342 from Christian Delbaere to fix some director classes crashing on + object deletion when using -builtin. Fixes SF bug #1301. + +2013-06-11: wsfulton + [Python] Add SWIG_PYTHON_INTERPRETER_NO_DEBUG macro which can be defined to use the Release version + of the Python interpreter in Debug builds of the wrappers. The Visual Studio .dsp example + files have been modified to use this so that Debug builds will now work without having + to install or build a Debug build of the interpreter. + +2013-06-07: wsfulton + [Ruby] Git issue #52. Fix regression with missing rb_complex_new function for Ruby + versions prior to 1.9 using std::complex wrappers if just using std::complex as an output type. + Also fix the Complex helper functions external visibility (to static by default). + +2013-06-04: olly + [PHP] Fix SWIG_ZTS_ConvertResourcePtr() not to dereference NULL + if the type lookup fails. + Version 2.0.10 (27 May 2013) ============================ diff --git a/CHANGES.current b/CHANGES.current index 1727ecb2c..ddf123364 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,140 +2,6 @@ Below are the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.11 (15 Sep 2013) +Version 3.0.0 (in progress) ============================ -2013-09-15: wsfulton - [R] Fix attempt to free a non-heap object in OUTPUT typemaps for: - unsigned short *OUTPUT - unsigned long *OUTPUT - signed long long *OUTPUT - char *OUTPUT - signed char*OUTPUT - unsigned char*OUTPUT - -2013-09-12: wsfulton - [Lua] Pull Git patch #62. - 1) Static members and static functions inside class can be accessed as - ModuleName.ClassName.FunctionName (MemberName respectively). Old way such as - ModuleName.ClassName_FunctionName still works. - 2) Same goes for enums inside classes: ModuleName.ClassName.EnumValue1 etc. - -2013-09-12: wsfulton - [UTL] Infinity is now by default an acceptable value for type 'float'. This fix makes - the handling of type 'float' and 'double' the same. The implementation requires the - C99 isfinite() macro, or otherwise some platform dependent equivalents, to be available. - - Users requiring the old behaviour of not accepting infinity, can define a 'check' typemap - wherever a float is used, such as: - - %typemap(check,fragment="") float, const float & %{ - if ($1 < -FLT_MAX || $1 > FLT_MAX) { - SWIG_exception_fail(SWIG_TypeError, "Overflow in type float"); - } - %} - - *** POTENTIAL INCOMPATIBILITY *** - -2013-08-30: wsfulton - [Lua] Pull Git patch #81: Include Lua error locus in SWIG error messages. - This is standard information in Lua error messages, and makes it much - easier to find bugs. - -2013-08-29: wsfulton - Pull Git patch #75: Handle UTF-8 files with BOM at beginning of file. Was giving an - 'Illegal token' syntax error. - -2013-08-29: wsfulton - [C#] Pull Git patch #77: Allow exporting std::map using non-default comparison function. - -2013-08-28: wsfulton - [Python] %implicitconv is improved for overloaded functions. Like in C++, the methods - with the actual types are considered before trying implicit conversions. Example: - - %implicitconv A; - struct A { - A(int i); - }; - class CCC { - public: - int xx(int i) { return 11; } - int xx(const A& i) { return 22; } - }; - - The following python code: - - CCC().xx(-1) - - will now return 11 instead of 22 - the implicit conversion is not done. - -2013-08-23: olly - [Python] Fix clang++ warning in generated wrapper code. - -2013-08-16: wsfulton - [Python] %implicitconv will now accept None where the implicit conversion takes a C/C++ pointer. - Problem highlighted by Bo Peng. Closes SF patch #230. - -2013-08-07: wsfulton - [Python] SF Patch #326 from Kris Thielemans - Remove SwigPyObject_print and SwigPyObject_str and - make the generated wrapper use the default python implementations, which will fall back to repr - (for -builtin option). - - Advantages: - - it avoids the swig user having to jump through hoops to get print to work as expected when - redefining repr/str slots. - - typing the name of a variable on the python prompt now prints the result of a (possibly redefined) - repr, without the swig user having to do any extra work. - - when redefining repr, the swig user doesn't necessarily have to redefine str as it will call the - redefined repr - - the behaviour is exactly the same as without the -builtin option while requiring no extra work - by the user (aside from adding the %feature("python:slot...) statements of course) - - Disadvantage: - - default str() will give different (but clearer?) output on swigged classes - -2013-07-30: wsfulton - [Python, Ruby] Fix #64 #65: Missing code in std::multimap wrappers. Previously an instantiation - of a std::map was erroneously required in addition to an instantiation of std::multimap with the - same template parameters to prevent compilation errors for the wrappers of a std::multimap. - -2013-07-14: joequant - [R] Change types file to allow for SEXP return values - -2013-07-05: wsfulton - [Python] Add %pythonbegin directive which works like %pythoncode, except the specified code is - added at the beginning of the generated .py file. This is primarily needed for importing from - __future__ statements required to be at the very beginning of the file. Example: - - %pythonbegin %{ - from __future__ import print_function - print("Loading", "Whizz", "Bang", sep=' ... ') - %} - -2013-07-01: wsfulton - [Python] Apply SF patch #340 - Uninitialized variable fix in SWIG_Python_NonDynamicSetAttr - when using -builtin. - -2013-07-01: wsfulton - [Python, Ruby, Ocaml] Apply SF patch #341 - fix a const_cast in generated code that was generating - a <:: digraph when using the unary scope operator (::) (global scope) in a template type. - -2013-07-01: wsfulton - [Python] Add SF patch #342 from Christian Delbaere to fix some director classes crashing on - object deletion when using -builtin. Fixes SF bug #1301. - -2013-06-11: wsfulton - [Python] Add SWIG_PYTHON_INTERPRETER_NO_DEBUG macro which can be defined to use the Release version - of the Python interpreter in Debug builds of the wrappers. The Visual Studio .dsp example - files have been modified to use this so that Debug builds will now work without having - to install or build a Debug build of the interpreter. - -2013-06-07: wsfulton - [Ruby] Git issue #52. Fix regression with missing rb_complex_new function for Ruby - versions prior to 1.9 using std::complex wrappers if just using std::complex as an output type. - Also fix the Complex helper functions external visibility (to static by default). - -2013-06-04: olly - [PHP] Fix SWIG_ZTS_ConvertResourcePtr() not to dereference NULL - if the type lookup fails. - diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 2dfb438f8..195111424 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -1,12 +1,12 @@ -SWIG-2.0 Documentation +SWIG-3.0 Documentation -

    SWIG-2.0 Documentation

    +

    SWIG-3.0 Documentation

    -Last update : SWIG-2.0.11 (15 Sep 2013) +Last update : SWIG-3.0.0 (in progress)

    Sections

    diff --git a/README b/README index 946bd9a8f..b6080a4fd 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.11 (15 Sep 2013) +Version: 3.0.0 (in progress) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, C#, D, Go, Lua, diff --git a/configure.ac b/configure.ac index c4db3ce98..47d1e13ae 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. dnl The macros which aren't shipped with the autotools are stored in the dnl Tools/config directory in .m4 files. -AC_INIT([swig],[2.0.11],[http://www.swig.org]) +AC_INIT([swig],[3.0.0],[http://www.swig.org]) dnl NB: When this requirement is increased to 2.60 or later, AC_PROG_SED dnl definition below can be removed From d0cb2b73dbd04a20f977db818056b0de5ac2605e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 18 Sep 2013 00:38:39 +0100 Subject: [PATCH 0711/1160] Remove X11 detection during configure X11 is not used anywhere. --- Examples/Makefile.in | 21 ------------ Lib/perl5/Makefile.in | 18 ++--------- Lib/python/Makefile.in | 18 ++--------- Lib/tcl/Makefile.in | 19 ++++------- configure.ac | 73 +----------------------------------------- 5 files changed, 13 insertions(+), 136 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 5607feb9e..e9b70f961 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -51,11 +51,6 @@ RUNPIPE= RUNME = runme -# X11 options - -XLIB = @XLIBSW@ -XINCLUDE = @XINCLUDES@ - IWRAP = $(INTERFACE:.i=_wrap.i) ISRCS = $(IWRAP:.i=.c) ICXXSRCS = $(IWRAP:.i=.cxx) @@ -136,7 +131,6 @@ TCL_SCRIPT = $(RUNME).tcl # Build a new version of the tclsh shell # ----------------------------------------------------------- - tclsh: $(SRCS) $(SWIG) -tcl8 $(SWIGOPT) $(TCL_SWIGOPTS) -ltclsh.i $(INTERFACEPATH) $(CC) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) $(TCL_INCLUDE) \ @@ -147,21 +141,6 @@ tclsh_cpp: $(SRCS) $(CXX) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE) \ $(TCL_LIB) $(TCL_OPTS) $(LIBS) $(SYSLIBS) -o $(TARGET) -# ----------------------------------------------------------- -# Build a new copy of wish -# ----------------------------------------------------------- - -wish: $(SRCS) - $(SWIG) -tcl8 $(SWIGOPT) $(TCL_SWIGOPTS) -lwish.i $(INTERFACEPATH) - $(CC) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) $(TCL_INCLUDE) \ - $(XINCLUDE) $(TCL_LIB) $(TK_OPTS) $(XLIB) $(LIBS) $(SYSLIBS) -o $(TARGET) - - -wish_cpp: $(SRCS) - $(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) -lwish.i $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE) \ - $(XINCLUDE) $(TCL_LIB) $(TK_OPTS) $(XLIB) $(LIBS) $(SYSLIBS) -o $(TARGET) - # ----------------------------------------------------------- # Build a Tcl dynamic loadable module (you might need to tweak this) # ----------------------------------------------------------- diff --git a/Lib/perl5/Makefile.in b/Lib/perl5/Makefile.in index dde01894d..f11ad2bdf 100644 --- a/Lib/perl5/Makefile.in +++ b/Lib/perl5/Makefile.in @@ -47,7 +47,7 @@ SWIGOPT = -perl5 SWIGCC = $(CC) # SWIG Library files. Uncomment this to staticly rebuild Perl -#SWIGLIB = -static -lperlmain.i +#SWIGLIBS = -static -lperlmain.i # Rules for creating .o files from source. @@ -69,33 +69,21 @@ BUILD = @LDSHARED@ #DLL_LIBS = -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \ -L/usr/local/lib -lg++ -lstdc++ -lgcc -# X11 installation (possibly needed if using Perl-Tk) - -XLIB = @XLIBSW@ -XINCLUDE = @XINCLUDES@ - # Perl installation PERL_INCLUDE = -I@PERL5EXT@ PERL_LIB = -L@PERL5EXT@ -lperl PERL_FLAGS = -Dbool=char -Dexplicit= -# Tcl installation. If using Tk you might need this - -TCL_INCLUDE = @TCLINCLUDE@ -TCL_LIB = @TCLLIB@ - # Build libraries (needed for static builds) LIBM = @LIBM@ LIBC = @LIBC@ SYSLIBS = $(LIBM) $(LIBC) @LIBS@ -# Build options (uncomment only one these) +# Build options -#TK_LIB = $(TCL_LIB) -ltcl -ltk $(XLIB) BUILD_LIBS = $(LIBS) # Dynamic loading -#BUILD_LIBS = $(PERL_LIB) $(TK_LIB) $(LIBS) $(SYSLIBS) # Static linking # Compilation rules for non-SWIG components @@ -123,7 +111,7 @@ $(WRAPOBJ) : $(WRAPFILE) $(SWIGCC) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(PERL_INCLUDE) $(PERL_FLAGS) $(WRAPFILE) $(WRAPFILE) : $(INTERFACE) - $(SWIG) $(SWIGOPT) -o $(WRAPFILE) $(SWIGLIB) $(INTERFACE) + $(SWIG) $(SWIGOPT) -o $(WRAPFILE) $(SWIGLIBS) $(INTERFACE) $(TARGET): $(WRAPOBJ) $(ALLOBJS) $(BUILD) $(WRAPOBJ) $(ALLOBJS) $(BUILD_LIBS) -o $(TARGET) diff --git a/Lib/python/Makefile.in b/Lib/python/Makefile.in index 3243b3df4..71effea70 100644 --- a/Lib/python/Makefile.in +++ b/Lib/python/Makefile.in @@ -47,7 +47,7 @@ SWIGOPT = -python SWIGCC = $(CC) # SWIG Library files. Uncomment if rebuilding the Python interpreter -#SWIGLIB = -lembed.i +#SWIGLIBS = -lembed.i # Rules for creating .o files from source. @@ -69,32 +69,20 @@ BUILD = @LDSHARED@ #DLL_LIBS = -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \ -L/usr/local/lib -lg++ -lstdc++ -lgcc -# X11 installation (needed if rebuilding Python + tkinter) - -XLIB = @XLIBSW@ -XINCLUDE = @XINCLUDES@ - # Python installation PY_INCLUDE = -DHAVE_CONFIG_H @PYINCLUDE@ PY_LIB = @PYLIB@ -# Tcl installation. Needed if rebuilding Python with tkinter. - -TCL_INCLUDE = @TCLINCLUDE@ -TCL_LIB = @TCLLIB@ - # Build libraries (needed for static builds) LIBM = @LIBM@ LIBC = @LIBC@ SYSLIBS = $(LIBM) $(LIBC) @LIBS@ -# Build options (uncomment only one these) +# Build options -#TKINTER = $(TCL_LIB) -ltk -ltcl $(XLIB) BUILD_LIBS = $(LIBS) # Dynamic loading -#BUILD_LIBS = $(PY_LIB) @PYLINK@ $(TKINTER) $(LIBS) $(SYSLIBS) # Compilation rules for non-SWIG components @@ -122,7 +110,7 @@ $(WRAPOBJ) : $(WRAPFILE) $(SWIGCC) -c $(CCSHARED) $(CFLAGS) $(WRAPFILE) $(INCLUDES) $(PY_INCLUDE) $(WRAPFILE) : $(INTERFACE) - $(SWIG) $(SWIGOPT) -o $(WRAPFILE) $(SWIGLIB) $(INTERFACE) + $(SWIG) $(SWIGOPT) -o $(WRAPFILE) $(SWIGLIBS) $(INTERFACE) $(TARGET): $(WRAPOBJ) $(ALLOBJS) $(BUILD) $(WRAPOBJ) $(ALLOBJS) $(BUILD_LIBS) -o $(TARGET) diff --git a/Lib/tcl/Makefile.in b/Lib/tcl/Makefile.in index 523349bb5..2ab0f7b01 100644 --- a/Lib/tcl/Makefile.in +++ b/Lib/tcl/Makefile.in @@ -1,5 +1,5 @@ # --------------------------------------------------------------- -# SWIG Tcl/Tk Makefile +# SWIG Tcl Makefile # # This file can be used to build various Tcl extensions with SWIG. # By default this file is set up for dynamic loading, but it can @@ -48,9 +48,8 @@ SWIG = $(exec_prefix)/bin/swig SWIGOPT = -tcl # use -tcl8 for Tcl 8.0 SWIGCC = $(CC) -# SWIG Library files. Uncomment one of these for rebuilding tclsh or wish -#SWIGLIB = -ltclsh.i -#SWIGLIB = -lwish.i +# SWIG Library files. Uncomment if rebuilding tclsh +#SWIGLIBS = -ltclsh.i # Rules for creating .o files from source. @@ -72,12 +71,7 @@ BUILD = @LDSHARED@ #DLL_LIBS = -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \ -L/usr/local/lib -lg++ -lstdc++ -lgcc -# X11 installation (needed to rebuild Tk extensions) - -XLIB = @XLIBSW@ -XINCLUDE = @XINCLUDES@ - -# Tcl installation (where is Tcl/Tk located) +# Tcl installation (where is Tcl located) TCL_INCLUDE = @TCLINCLUDE@ TCL_LIB = @TCLLIB@ @@ -88,11 +82,10 @@ LIBM = @LIBM@ LIBC = @LIBC@ SYSLIBS = $(LIBM) $(LIBC) @LIBS@ -# Build options (uncomment only one these) +# Build options (uncomment only one of these) BUILD_LIBS = $(LIBS) # Dynamic loading #BUILD_LIBS = $(TCL_LIB) -ltcl $(LIBS) $(SYSLIBS) # tclsh -#BUILD_LIBS = $(TCL_LIB) -ltk -ltcl $(XLIB) $(LIBS) $(SYSLIBS) # wish # Compilation rules for non-SWIG components @@ -120,7 +113,7 @@ $(WRAPOBJ) : $(WRAPFILE) $(SWIGCC) -c $(CCSHARED) $(CFLAGS) $(WRAPFILE) $(INCLUDES) $(TCL_INCLUDE) $(WRAPFILE) : $(INTERFACE) - $(SWIG) $(SWIGOPT) -o $(WRAPFILE) $(SWIGLIB) $(INTERFACE) + $(SWIG) $(SWIGOPT) -o $(WRAPFILE) $(SWIGLIBS) $(INTERFACE) $(TARGET): $(WRAPOBJ) $(ALLOBJS) $(BUILD) $(WRAPOBJ) $(ALLOBJS) $(BUILD_LIBS) -o $(TARGET) diff --git a/configure.ac b/configure.ac index 47d1e13ae..2d1c4a592 100644 --- a/configure.ac +++ b/configure.ac @@ -418,80 +418,9 @@ else AC_MSG_ERROR([proper usage is --with-libc=STRING]) fi]) #-------------------------------------------------------------------- -# Locate the X11 header files and the X11 library archive. Try -# the ac_path_x macro first, but if it doesn't find the X stuff -# (e.g. because there's no xmkmf program) then check through -# a list of possible directories. Under some conditions the -# autoconf macro will return an include directory that contains -# no include files, so double-check its result just to be safe. +# Target languages #-------------------------------------------------------------------- -AC_PATH_X -not_really_there="" -if test "$no_x" = ""; then - if test "$x_includes" = ""; then - AC_TRY_CPP([#include ], , not_really_there="yes") - else - if test ! -r $x_includes/X11/Intrinsic.h; then - not_really_there="yes" - fi - fi -fi -if test "$no_x" = "yes" -o "$not_really_there" = "yes"; then - AC_MSG_CHECKING(for X11 header files) - XINCLUDES="# no special path needed" - AC_TRY_CPP([#include ], , XINCLUDES="") - if test -z "$XINCLUDES"; then - dirs="/usr/unsupported/include /usr/local/include /usr/X386/include /usr/include/X11R4 /usr/X11R5/include /usr/include/X11R5 /usr/openwin/include /usr/X11/include /usr/sww/include /usr/X11R6/include /usr/include/X11R6" - for i in $dirs ; do - if test -r $i/X11/Intrinsic.h; then - XINCLUDES=" -I$i" - break - fi - done - fi - AC_MSG_RESULT($XINCLUDES) -else - if test "$x_includes" != ""; then - XINCLUDES=-I$x_includes - else - XINCLUDES="# no special path needed" - fi -fi -if test -z "$XINCLUDES"; then - AC_MSG_RESULT(couldn't find any!) - XINCLUDES="# no include files found" -fi - -if test "$no_x" = yes; then - AC_MSG_CHECKING(for X11 libraries) - XLIBSW= - dirs="/usr/unsupported/lib /usr/local/lib /usr/X386/lib /usr/lib/X11R4 /usr/X11R5/lib /usr/lib/X11R5 /usr/X11R6/lib /usr/lib/X11R6 /usr/openwin/lib /usr/X11/lib /usr/sww/X11/lib" - for i in $dirs ; do - if test -r $i/libX11.a -o -r $i/libX11.so -o -r $i/libX11.sl; then - AC_MSG_RESULT($i) - XLIBSW="-L$i -lX11" - break - fi - done -else - if test "$x_libraries" = ""; then - XLIBSW=-lX11 - else - XLIBSW="-L$x_libraries -lX11" - fi -fi -if test -z "$XLIBSW" ; then - AC_CHECK_LIB(Xwindow, XCreateWindow, XLIBSW=-lXwindow) -fi -if test -z "$XLIBSW" ; then - AC_MSG_RESULT(couldn't find any! Using -lX11.) - XLIBSW=-lX11 -fi - -AC_SUBST(XINCLUDES) -AC_SUBST(XLIBSW) - AC_ARG_WITH(alllang, AS_HELP_STRING([--without-alllang], [Disable all languages]), with_alllang="$withval") #-------------------------------------------------------------------- From 43032339d0517cd371b783693fb471a20f887e6d Mon Sep 17 00:00:00 2001 From: Gavin Kinsey Date: Thu, 19 Sep 2013 12:21:57 +0100 Subject: [PATCH 0712/1160] Fixed a memory leak for java STRING_ARRAY The allocation loop uses size, so the free loop should do the same, not size-1. --- Lib/java/various.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/java/various.i b/Lib/java/various.i index f589bf714..7ba7a5eb3 100644 --- a/Lib/java/various.i +++ b/Lib/java/various.i @@ -52,7 +52,7 @@ %typemap(freearg) char **STRING_ARRAY { int i; - for (i=0; i Date: Fri, 20 Sep 2013 18:47:46 +0100 Subject: [PATCH 0713/1160] Document Java char **STRING_ARRAY typemap fix --- CHANGES.current | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index ddf123364..fe625d798 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,3 +5,6 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-09-20: wsfulton + [Java] Fix a memory leak for the java char **STRING_ARRAY typemaps. + From 173c4b3bbaec6afcb8d01dc59785664c124aa084 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 20 Sep 2013 19:39:30 +0100 Subject: [PATCH 0714/1160] Grab .travis.yml file from master to turn on Travis testing --- .travis.yml | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..26758304f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,58 @@ +language: cpp +compiler: + - clang + - gcc +env: + - SWIGLANG= +matrix: + include: + - compiler: gcc + env: SWIGLANG=csharp + - compiler: gcc + env: SWIGLANG=go + - compiler: gcc + env: SWIGLANG=guile + - compiler: gcc + env: SWIGLANG=java + - compiler: gcc + env: SWIGLANG=lua + - compiler: gcc + env: SWIGLANG=octave SWIGJOBS=-j4 + - compiler: gcc + env: SWIGLANG=perl5 + - compiler: gcc + env: SWIGLANG=php + - compiler: gcc + env: SWIGLANG=python + - compiler: gcc + env: SWIGLANG=python PY3=1 + - compiler: gcc + env: SWIGLANG=ruby + - compiler: gcc + env: SWIGLANG=tcl + allow_failures: + # None +before_install: + - lsb_release -a + - uname -a + - sudo apt-get -qq update + - time sudo apt-get -qq install libboost-dev + - if test "$SWIGLANG" = "csharp"; then sudo apt-get -qq install mono-devel; fi + - if test "$SWIGLANG" = "go"; then go env | sed -e 's/^/export /' > goenvsetup && source goenvsetup && rm -f goenvsetup; fi # Until configure.ac is fixed + - if test "$SWIGLANG" = "guile"; then sudo apt-get -qq install guile-2.0-dev; fi + - if test "$SWIGLANG" = "lua"; then sudo apt-get -qq install lua5.1 liblua5.1-dev; fi + - if test "$SWIGLANG" = "octave"; then sudo apt-get -qq install octave3.2 octave3.2-headers; fi + - if test "$SWIGLANG" = "php"; then sudo apt-get install php5-cli php5-dev; fi + - if test "$SWIGLANG" = "python" -a "$PY3"; then sudo apt-get install python3-dev; fi + - if test "$SWIGLANG" = "tcl"; then sudo apt-get -qq install tcl8.4-dev; fi +script: + - ./autogen.sh && ./configure + - make -s $SWIGJOBS + - if test -z "$SWIGLANG"; then make -s check-ccache; fi + - ./swig -version + - if test -n "$SWIGLANG"; then make -s check-$SWIGLANG-version; fi + - if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-examples; fi + - if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-test-suite; fi +branches: + only: + - master From 12708c9241bf9e5ef75a449ff848f2be84a35e72 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 25 Sep 2013 17:29:33 +1200 Subject: [PATCH 0715/1160] Fix typos --- CHANGES | 4 ++-- Doc/Manual/Java.html | 2 +- Doc/Manual/SWIG.html | 2 +- .../android/extend/src/org/swig/extendexample/SwigExtend.java | 2 +- Examples/csharp/extend/runme.cs | 2 +- Examples/d/extend/d1/runme.d | 2 +- Examples/d/extend/d2/runme.d | 2 +- Examples/go/extend/runme.go | 2 +- Examples/java/extend/runme.java | 2 +- Lib/go/go.swg | 2 +- Source/Modules/lang.cxx | 2 +- Source/Modules/python.cxx | 2 +- Tools/config/ac_compile_warnings.m4 | 2 +- 13 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGES b/CHANGES index c70765cf1..4cc222901 100644 --- a/CHANGES +++ b/CHANGES @@ -3303,8 +3303,8 @@ Version 1.3.36 (24 June 2008) Makefile target being generated when generating makefiles with the -M family of options. For example: - $ swig -java -MM -MT overiddenname -c++ example.i - overiddenname: \ + $ swig -java -MM -MT overriddenname -c++ example.i + overriddenname: \ example.i \ example.h diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 0024d602a..f3d8a1684 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -7886,7 +7886,7 @@ where it is possible to step from Java code into a JNI method within one environ

    Alternatively, debugging can involve placing debug printout statements in the JNI layer using the %exception directive. See the special variables for %exception section. -Many of the default typemaps can also be overidden and modified for adding in extra logging/debug display information. +Many of the default typemaps can also be overridden and modified for adding in extra logging/debug display information.

    diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 25dc899de..f9ea5b2ef 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -258,7 +258,7 @@ this option the default output directory is the path to the input file. If -o and -outcurrentdir are used together, -outcurrentdir is effectively ignored as the output directory for the language files is the same directory as the -generated C/C++ file if not overidden with -outdir. +generated C/C++ file if not overridden with -outdir.

    5.1.3 Comments

    diff --git a/Examples/android/extend/src/org/swig/extendexample/SwigExtend.java b/Examples/android/extend/src/org/swig/extendexample/SwigExtend.java index a343dfebc..b88d36082 100644 --- a/Examples/android/extend/src/org/swig/extendexample/SwigExtend.java +++ b/Examples/android/extend/src/org/swig/extendexample/SwigExtend.java @@ -96,7 +96,7 @@ public class SwigExtend extends Activity // 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 Java. The call to getPosition is - // slightly different, however, because of the overidden getPosition() call, since + // slightly different, however, because of the overridden getPosition() call, since // now the object reference has been "laundered" by passing through // EmployeeList as an Employee*. Previously, Java resolved the call // immediately in CEO, but now Java thinks the object is an instance of diff --git a/Examples/csharp/extend/runme.cs b/Examples/csharp/extend/runme.cs index 825dcdbca..92313aa5e 100644 --- a/Examples/csharp/extend/runme.cs +++ b/Examples/csharp/extend/runme.cs @@ -45,7 +45,7 @@ public class runme // 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 C#. The call to getPosition is - // slightly different, however, because of the overidden getPosition() call, since + // slightly different, however, because of the overridden getPosition() call, since // now the object reference has been "laundered" by passing through // EmployeeList as an Employee*. Previously, C# resolved the call // immediately in CEO, but now C# thinks the object is an instance of diff --git a/Examples/d/extend/d1/runme.d b/Examples/d/extend/d1/runme.d index 96501d1a4..058432096 100644 --- a/Examples/d/extend/d1/runme.d +++ b/Examples/d/extend/d1/runme.d @@ -46,7 +46,7 @@ void main() { // 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 D. The call to getPosition is - // slightly different, however, because of the overidden getPosition() call, since + // slightly different, however, because of the overridden getPosition() call, since // now the object reference has been "laundered" by passing through // EmployeeList as an Employee*. Previously, D resolved the call // immediately in CEO, but now D thinks the object is an instance of diff --git a/Examples/d/extend/d2/runme.d b/Examples/d/extend/d2/runme.d index 1ea6dfd21..cccdf463b 100644 --- a/Examples/d/extend/d2/runme.d +++ b/Examples/d/extend/d2/runme.d @@ -46,7 +46,7 @@ void main() { // 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 D. The call to getPosition is - // slightly different, however, because of the overidden getPosition() call, since + // slightly different, however, because of the overridden getPosition() call, since // now the object reference has been "laundered" by passing through // EmployeeList as an Employee*. Previously, D resolved the call // immediately in CEO, but now D thinks the object is an instance of diff --git a/Examples/go/extend/runme.go b/Examples/go/extend/runme.go index 8fdfd0a6c..770e27802 100644 --- a/Examples/go/extend/runme.go +++ b/Examples/go/extend/runme.go @@ -42,7 +42,7 @@ func main() { // 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 + // is slightly different, however, because of the overridden // GetPosition() call, since now the object reference has been // "laundered" by passing through EmployeeList as an // Employee*. Previously, Go resolved the call immediately in diff --git a/Examples/java/extend/runme.java b/Examples/java/extend/runme.java index 629bb14a6..f1ec1ea06 100644 --- a/Examples/java/extend/runme.java +++ b/Examples/java/extend/runme.java @@ -55,7 +55,7 @@ public class runme { // 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 Java. The call to getPosition is - // slightly different, however, because of the overidden getPosition() call, since + // slightly different, however, because of the overridden getPosition() call, since // now the object reference has been "laundered" by passing through // EmployeeList as an Employee*. Previously, Java resolved the call // immediately in CEO, but now Java thinks the object is an instance of diff --git a/Lib/go/go.swg b/Lib/go/go.swg index cc3beef7d..b00533fa3 100644 --- a/Lib/go/go.swg +++ b/Lib/go/go.swg @@ -431,7 +431,7 @@ %} /* Typecheck typemaps. The purpose of these is merely to issue a - warning for overloaded C++ functions * that cannot be overloaded in + 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 */ diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index eb7d49480..6cc6e9fc3 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2513,7 +2513,7 @@ int Language::classHandler(Node *n) { Setattr(m, "parentNode", n); /* * There is a bug that needs fixing still... - * This area of code is creating methods which have not been overidden in a derived class (director methods that are protected in the base) + * This area of code is creating methods which have not been overridden in a derived class (director methods that are protected in the base) * If the method is overloaded, then Swig_overload_dispatch() incorrectly generates a call to the base wrapper, _wrap_xxx method * See director_protected_overloaded.i - Possibly sym:overname needs correcting here. Printf(stdout, "new method: %s::%s(%s)\n", Getattr(parentNode(m), "name"), Getattr(m, "name"), ParmList_str_defaultargs(Getattr(m, "parms"))); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 94802e06d..98f6cac09 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -3728,7 +3728,7 @@ public: if (builtin) builtin_pre_decl(n); - /* Overide the shadow file so we can capture its methods */ + /* Override the shadow file so we can capture its methods */ f_shadow = NewString(""); // Set up type check for director class constructor diff --git a/Tools/config/ac_compile_warnings.m4 b/Tools/config/ac_compile_warnings.m4 index 4c030ea59..7e4239a3c 100644 --- a/Tools/config/ac_compile_warnings.m4 +++ b/Tools/config/ac_compile_warnings.m4 @@ -4,7 +4,7 @@ dnl Set the maximum warning verbosity according to C and C++ compiler used. dnl Currently supports g++ and gcc. dnl dnl The compiler options are always added CFLAGS and CXXFLAGS even if -dnl these are overidden at configure time. Removing the maximum warning +dnl these are overridden at configure time. Removing the maximum warning dnl flags can be removed with --without-maximum-compile-warnings. For example: dnl dnl ./configure --without-maximum-compile-warnings CFLAGS= CXXFLAGS= From c4d40c7b64c0a599780f94824ca9d6d00f71264c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 1 Oct 2013 22:13:57 +0100 Subject: [PATCH 0716/1160] PHP directors - generate call_user_function on one line --- Source/Modules/php.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 3cae48383..652bd1e63 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2606,8 +2606,8 @@ done: /* wrap complex arguments to zvals */ Printv(w->code, wrap_args, NIL); - Append(w->code, "call_user_function(EG(function_table), (zval**)&swig_self, &funcname,\n"); - Printf(w->code, " %s, %d, args TSRMLS_CC);\n", Swig_cresult_name(), idx); + Append(w->code, "call_user_function(EG(function_table), (zval**)&swig_self, &funcname,"); + Printf(w->code, " %s, %d, args TSRMLS_CC);\n", Swig_cresult_name(), idx); if (tm) { Printv(w->code, Str(tm), "\n", NIL); From e186d2176a527c0e171c8e85e42121a7a1d7d6de Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 4 Oct 2013 23:08:33 +0100 Subject: [PATCH 0717/1160] Fix %naturalvar and templated methods using enums %naturalvar was not being picked up - use the symbol table instead for looking up the feature. use_naturalvar_mode() has been moved to Language class (not strictly necessary though) --- CHANGES.current | 4 +++ Examples/test-suite/common.mk | 1 + Examples/test-suite/naturalvar_more.i | 46 +++++++++++++++++++++++++++ Source/Modules/lang.cxx | 20 ++++++++---- Source/Modules/swigmod.h | 6 ++-- 5 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 Examples/test-suite/naturalvar_more.i diff --git a/CHANGES.current b/CHANGES.current index fe625d798..edd39af31 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-10-04: wsfulton + Fix %naturalvar not having any affect on templated classes instantiated with an + enum as the template parameter type. Problem reported by Vadim Zeitlin. + 2013-09-20: wsfulton [Java] Fix a memory leak for the java char **STRING_ARRAY typemaps. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 997f8e715..381a49f7b 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -274,6 +274,7 @@ CPP_TEST_CASES += \ nspace \ nspace_extend \ naturalvar \ + naturalvar_more \ nested_class \ nested_comment \ nested_workaround \ diff --git a/Examples/test-suite/naturalvar_more.i b/Examples/test-suite/naturalvar_more.i new file mode 100644 index 000000000..2cbfb069c --- /dev/null +++ b/Examples/test-suite/naturalvar_more.i @@ -0,0 +1,46 @@ +%module naturalvar_more + +// The instantiation of a template using an enum in the template parameter was not picking up %naturalvar. + +// These typemaps will be used if %naturalvar is not working +%typemap(out) T *te, T *const_te "_should_not_use_this_out_typemap_" +%typemap(varout) T *te, T *const_te "_should_not_use_this_varout_typemap_" +%typemap(out) Hidden *hidden "_should_not_use_this_out_typemap_" +%typemap(varout) Hidden *hidden "_should_not_use_this_varout_typemap_" + +%naturalvar T; +%naturalvar Hidden; + +%inline %{ +template struct T {}; +struct K {}; +struct Hidden; +%} +%{ +struct Hidden {}; +%} + +%inline %{ +namespace Space { + enum E { E1, E2, E3 }; +} +%} + +%template(TE) T; + +%include +%include +%template(VectorString) std::vector; + +%inline { +using namespace Space; +struct S { + T te; + const T const_te; + const std::vector::value_type const_string_member; // check this resolves to std::string which has a naturalvar + std::vector::value_type string_member; // check this resolves to std::string which has a naturalvar + Hidden hidden; + S() : const_te(), const_string_member("initial string value") {} +}; +} + diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 6cc6e9fc3..1e63d4d9c 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -467,9 +467,9 @@ void swig_pragma(char *lang, char *name, char *value) { } /* -------------------------------------------------------------------------- - * use_naturalvar_mode() + * Language::use_naturalvar_mode() * -------------------------------------------------------------------------- */ -int use_naturalvar_mode(Node *n) { +int Language::use_naturalvar_mode(Node *n) const { if (Getattr(n, "unnamed")) return 0; int nvar = naturalvar_mode || GetFlag(n, "feature:naturalvar"); @@ -478,12 +478,17 @@ int use_naturalvar_mode(Node *n) { SwigType *ty = Getattr(n, "type"); SwigType *fullty = SwigType_typedef_resolve_all(ty); if (SwigType_isclass(fullty)) { - Node *m = Copy(n); SwigType *tys = SwigType_strip_qualifiers(fullty); - Swig_features_get(Swig_cparse_features(), 0, tys, 0, m); - nvar = GetFlag(m, "feature:naturalvar"); + if (!CPlusPlus) { + Replaceall(tys, "struct ", ""); + Replaceall(tys, "union ", ""); + Replaceall(tys, "class ", ""); + } + Node *typenode = Swig_symbol_clookup(tys, 0); + assert(typenode); + if (typenode) + nvar = GetFlag(typenode, "feature:naturalvar"); Delete(tys); - Delete(m); } Delete(fullty); } @@ -1441,6 +1446,7 @@ int Language::membervariableHandler(Node *n) { tm = Swig_typemap_lookup("memberin", nin, target, 0); Delete(nin); } + int flags = Extend | SmartPointer | use_naturalvar_mode(n); if (isNonVirtualProtectedAccess(n)) flags = flags | CWRAP_ALL_PROTECTED_ACCESS; @@ -3091,7 +3097,7 @@ Node *Language::symbolLookup(String *s, const_String_or_char_ptr scope) { * Tries to locate a class from a type definition * ----------------------------------------------------------------------------- */ -Node *Language::classLookup(const SwigType *s) { +Node *Language::classLookup(const SwigType *s) const { Node *n = 0; /* Look in hash of cached values */ diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index b3722af40..4fcf013eb 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -215,7 +215,7 @@ public: virtual int addSymbol(const String *s, const Node *n, const_String_or_char_ptr scope = ""); /* Add symbol */ virtual void dumpSymbols(); virtual Node *symbolLookup(String *s, const_String_or_char_ptr scope = ""); /* Symbol lookup */ - virtual Node *classLookup(const SwigType *s); /* Class lookup */ + virtual Node *classLookup(const SwigType *s) const; /* Class lookup */ virtual Node *enumLookup(SwigType *s); /* Enum lookup */ virtual int abstractClassTest(Node *n); /* Is class really abstract? */ virtual int is_assignable(Node *n); /* Is variable assignable? */ @@ -300,6 +300,9 @@ protected: This does not include protected virtual methods as they are turned on with the dirprot option. */ bool isNonVirtualProtectedAccess(Node *n) const; + /* Identify if a wrapped global or member variable n should use the naturalvar feature */ + int use_naturalvar_mode(Node *n) const; + /* Director subclass comparison test */ String *none_comparison; @@ -380,7 +383,6 @@ int is_protected(Node *n); int is_member_director(Node *parentnode, Node *member); int is_member_director(Node *member); int is_non_virtual_protected_access(Node *n); /* Check if the non-virtual protected members are required (for directors) */ -int use_naturalvar_mode(Node *n); void Wrapper_virtual_elimination_mode_set(int); void Wrapper_fast_dispatch_mode_set(int); From 3fcbb40af94f9209c2da4f806db45ef24ad8408b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 5 Oct 2013 02:16:02 +0100 Subject: [PATCH 0718/1160] Remove incorrectly and newly introduced assert Was failing in li_boost_shared_ptr.i for some languages. A similar testcase has been added into naturalvar_more.i. --- Examples/test-suite/naturalvar_more.i | 7 +++++++ Source/Modules/lang.cxx | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/naturalvar_more.i b/Examples/test-suite/naturalvar_more.i index 2cbfb069c..aebb6b23e 100644 --- a/Examples/test-suite/naturalvar_more.i +++ b/Examples/test-suite/naturalvar_more.i @@ -15,9 +15,15 @@ template struct T {}; struct K {}; struct Hidden; +namespace Ace { + int glob; +} %} %{ struct Hidden {}; +namespace Ace { + template struct NoIdea {}; +} %} %inline %{ @@ -40,6 +46,7 @@ struct S { const std::vector::value_type const_string_member; // check this resolves to std::string which has a naturalvar std::vector::value_type string_member; // check this resolves to std::string which has a naturalvar Hidden hidden; + Ace::NoIdea noidea; S() : const_te(), const_string_member("initial string value") {} }; } diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 1e63d4d9c..a62084499 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -485,7 +485,6 @@ int Language::use_naturalvar_mode(Node *n) const { Replaceall(tys, "class ", ""); } Node *typenode = Swig_symbol_clookup(tys, 0); - assert(typenode); if (typenode) nvar = GetFlag(typenode, "feature:naturalvar"); Delete(tys); From 738cc36aabb80c8a0abbc22147f39cbe3cb13915 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 7 Oct 2013 20:37:00 +0100 Subject: [PATCH 0719/1160] Rename all C++0x to C++11 and cpp0x to cpp11 --- Doc/Devel/{cpp0x.html => cpp11.html} | 126 +++++++------- Doc/Manual/{Cpp0x.html => CPlusPlus11.html} | 158 +++++++++--------- Doc/Manual/chapters | 2 +- Examples/test-suite/common.mk | 72 ++++---- ...ax.i => cpp11_alternate_function_syntax.i} | 4 +- .../{cpp0x_constexpr.i => cpp11_constexpr.i} | 4 +- .../{cpp0x_decltype.i => cpp11_decltype.i} | 4 +- ...efault_delete.i => cpp11_default_delete.i} | 2 +- ...tors.i => cpp11_delegating_constructors.i} | 2 +- ... => cpp11_explicit_conversion_operators.i} | 4 +- ...ion_objects.i => cpp11_function_objects.i} | 2 +- ...pp0x_hash_tables.i => cpp11_hash_tables.i} | 4 +- ...tors.i => cpp11_inheriting_constructors.i} | 2 +- ...alizer_list.i => cpp11_initializer_list.i} | 4 +- ...tend.i => cpp11_initializer_list_extend.i} | 2 +- ...a_functions.i => cpp11_lambda_functions.i} | 4 +- ...nstant.i => cpp11_null_pointer_constant.i} | 4 +- ...literals.i => cpp11_raw_string_literals.i} | 2 +- .../{cpp0x_result_of.i => cpp11_result_of.i} | 4 +- ...e_reference.i => cpp11_rvalue_reference.i} | 2 +- ...reference2.i => cpp11_rvalue_reference2.i} | 2 +- ...reference3.i => cpp11_rvalue_reference3.i} | 2 +- ..._sizeof_object.i => cpp11_sizeof_object.i} | 4 +- ..._static_assert.i => cpp11_static_assert.i} | 2 +- ....i => cpp11_strongly_typed_enumerations.i} | 10 +- ...ets.i => cpp11_template_double_brackets.i} | 4 +- ...e_explicit.i => cpp11_template_explicit.i} | 4 +- ...e_typedefs.i => cpp11_template_typedefs.i} | 2 +- ...0x_thread_local.i => cpp11_thread_local.i} | 2 +- ...ation.i => cpp11_uniform_initialization.i} | 2 +- ...d_unions.i => cpp11_unrestricted_unions.i} | 2 +- ...iterals.i => cpp11_userdefined_literals.i} | 4 +- ...templates.i => cpp11_variadic_templates.i} | 2 +- ...java => cpp11_lambda_functions_runme.java} | 18 +- ...nme.java => cpp11_thread_local_runme.java} | 34 ++-- .../python/cpp0x_function_objects_runme.py | 12 -- .../cpp0x_initializer_list_extend_runme.py | 4 - .../python/cpp0x_initializer_list_runme.py | 5 - .../cpp0x_null_pointer_constant_runme.py | 15 -- .../python/cpp0x_result_of_runme.py | 3 - ... cpp11_alternate_function_syntax_runme.py} | 4 +- ...ltype_runme.py => cpp11_decltype_runme.py} | 4 +- .../python/cpp11_function_objects_runme.py | 12 ++ .../cpp11_initializer_list_extend_runme.py | 4 + .../python/cpp11_initializer_list_runme.py | 5 + .../cpp11_null_pointer_constant_runme.py | 15 ++ ....py => cpp11_raw_string_literals_runme.py} | 2 +- .../python/cpp11_result_of_runme.py | 3 + ...nme.py => cpp11_rvalue_reference_runme.py} | 4 +- ...l_runme.py => cpp11_thread_local_runme.py} | 2 +- ... => cpp11_uniform_initialization_runme.py} | 8 +- Source/CParse/parser.y | 10 +- 52 files changed, 307 insertions(+), 307 deletions(-) rename Doc/Devel/{cpp0x.html => cpp11.html} (90%) rename Doc/Manual/{Cpp0x.html => CPlusPlus11.html} (78%) rename Examples/test-suite/{cpp0x_alternate_function_syntax.i => cpp11_alternate_function_syntax.i} (77%) rename Examples/test-suite/{cpp0x_constexpr.i => cpp11_constexpr.i} (76%) rename Examples/test-suite/{cpp0x_decltype.i => cpp11_decltype.i} (85%) rename Examples/test-suite/{cpp0x_default_delete.i => cpp11_default_delete.i} (96%) rename Examples/test-suite/{cpp0x_delegating_constructors.i => cpp11_delegating_constructors.i} (88%) rename Examples/test-suite/{cpp0x_explicit_conversion_operators.i => cpp11_explicit_conversion_operators.i} (76%) rename Examples/test-suite/{cpp0x_function_objects.i => cpp11_function_objects.i} (95%) rename Examples/test-suite/{cpp0x_hash_tables.i => cpp11_hash_tables.i} (95%) rename Examples/test-suite/{cpp0x_inheriting_constructors.i => cpp11_inheriting_constructors.i} (89%) rename Examples/test-suite/{cpp0x_initializer_list.i => cpp11_initializer_list.i} (91%) rename Examples/test-suite/{cpp0x_initializer_list_extend.i => cpp11_initializer_list_extend.i} (93%) rename Examples/test-suite/{cpp0x_lambda_functions.i => cpp11_lambda_functions.i} (97%) rename Examples/test-suite/{cpp0x_null_pointer_constant.i => cpp11_null_pointer_constant.i} (85%) rename Examples/test-suite/{cpp0x_raw_string_literals.i => cpp11_raw_string_literals.i} (97%) rename Examples/test-suite/{cpp0x_result_of.i => cpp11_result_of.i} (83%) rename Examples/test-suite/{cpp0x_rvalue_reference.i => cpp11_rvalue_reference.i} (94%) rename Examples/test-suite/{cpp0x_rvalue_reference2.i => cpp11_rvalue_reference2.i} (98%) rename Examples/test-suite/{cpp0x_rvalue_reference3.i => cpp11_rvalue_reference3.i} (98%) rename Examples/test-suite/{cpp0x_sizeof_object.i => cpp11_sizeof_object.i} (71%) rename Examples/test-suite/{cpp0x_static_assert.i => cpp11_static_assert.i} (92%) rename Examples/test-suite/{cpp0x_strongly_typed_enumerations.i => cpp11_strongly_typed_enumerations.i} (84%) rename Examples/test-suite/{cpp0x_template_double_brackets.i => cpp11_template_double_brackets.i} (91%) rename Examples/test-suite/{cpp0x_template_explicit.i => cpp11_template_explicit.i} (81%) rename Examples/test-suite/{cpp0x_template_typedefs.i => cpp11_template_typedefs.i} (94%) rename Examples/test-suite/{cpp0x_thread_local.i => cpp11_thread_local.i} (97%) rename Examples/test-suite/{cpp0x_uniform_initialization.i => cpp11_uniform_initialization.i} (96%) rename Examples/test-suite/{cpp0x_unrestricted_unions.i => cpp11_unrestricted_unions.i} (93%) rename Examples/test-suite/{cpp0x_userdefined_literals.i => cpp11_userdefined_literals.i} (97%) rename Examples/test-suite/{cpp0x_variadic_templates.i => cpp11_variadic_templates.i} (98%) rename Examples/test-suite/java/{cpp0x_lambda_functions_runme.java => cpp11_lambda_functions_runme.java} (52%) rename Examples/test-suite/java/{cpp0x_thread_local_runme.java => cpp11_thread_local_runme.java} (52%) delete mode 100644 Examples/test-suite/python/cpp0x_function_objects_runme.py delete mode 100644 Examples/test-suite/python/cpp0x_initializer_list_extend_runme.py delete mode 100644 Examples/test-suite/python/cpp0x_initializer_list_runme.py delete mode 100644 Examples/test-suite/python/cpp0x_null_pointer_constant_runme.py delete mode 100644 Examples/test-suite/python/cpp0x_result_of_runme.py rename Examples/test-suite/python/{cpp0x_alternate_function_syntax_runme.py => cpp11_alternate_function_syntax_runme.py} (73%) rename Examples/test-suite/python/{cpp0x_decltype_runme.py => cpp11_decltype_runme.py} (86%) create mode 100644 Examples/test-suite/python/cpp11_function_objects_runme.py create mode 100644 Examples/test-suite/python/cpp11_initializer_list_extend_runme.py create mode 100644 Examples/test-suite/python/cpp11_initializer_list_runme.py create mode 100644 Examples/test-suite/python/cpp11_null_pointer_constant_runme.py rename Examples/test-suite/python/{cpp0x_raw_string_literals_runme.py => cpp11_raw_string_literals_runme.py} (95%) create mode 100644 Examples/test-suite/python/cpp11_result_of_runme.py rename Examples/test-suite/python/{cpp0x_rvalue_reference_runme.py => cpp11_rvalue_reference_runme.py} (90%) rename Examples/test-suite/python/{cpp0x_thread_local_runme.py => cpp11_thread_local_runme.py} (94%) rename Examples/test-suite/python/{cpp0x_uniform_initialization_runme.py => cpp11_uniform_initialization_runme.py} (68%) diff --git a/Doc/Devel/cpp0x.html b/Doc/Devel/cpp11.html similarity index 90% rename from Doc/Devel/cpp0x.html rename to Doc/Devel/cpp11.html index 4afc5ffe4..fc35465ae 100644 --- a/Doc/Devel/cpp0x.html +++ b/Doc/Devel/cpp11.html @@ -24,15 +24,15 @@ -

    C++0x support for SWIG

    +

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

    Summary

    -

    This is a technical overview of the C++0x support for the Swig. -This area of Swig is a work in progress. Initial C++0x support for +

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

    SVN branch

    branches/gsoc2009-matevz

    -

    New C++0x features status

    +

    New C++11 features status

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

    Rvalue reference and move semantics [done]

    @@ -63,12 +63,12 @@ operator=(ClassType&&):

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

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

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

    Generalized constant expressions [done]

    -

    In C++0x you can define functions as constant expressions. +

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

    @@ -84,7 +84,7 @@ so swig doesn't need to know about the constant values when parsing the header file.

    Done: Added the “constexpr “ keyword to Swig. Added testcase -cpp0x_constexpr. R11322

    +cpp11_constexpr. R11322

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

    @@ -94,7 +94,7 @@ template in the translation unit at that time. It's a feature specifically aimed at compilers to speed up the compilation process.

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

    Initializer lists [done]

    Initializer list is a new type in standard library: @@ -117,11 +117,11 @@ is a simple way to convert an ordinary list or a vector to the initializer_list.

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

    +cpp11_initializer_list. R11450

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

    Uniform initialization [done]

    -

    The new C++0x standard will allow the following:

    +

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

    struct IdString {
       std::string name;
       int identifier;
    @@ -132,7 +132,7 @@ IdString GetString() {
     }

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

    +C++11:

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

    The new way of using uniform initialization allows the following:

    @@ -154,12 +154,12 @@ AltStruct var2{2, 4.3}; // calls the constructor

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

    Done: Added syntax for {} member initialization in class -constructor. Added testcase cpp0x_uniform_initialization. R11413

    +constructor. Added testcase cpp11_uniform_initialization. R11413

    Type inference [partially done]

    -

    A new keyword 'auto' is introduced in C++0x:

    +

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

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

    The type of a1 and a2 is automatically determined according to the @@ -184,7 +184,7 @@ introduce a new SwigType for this.

    only.

    Lambda functions and expressions [done]

    -

    C++0x introduces lambda functions defined as:

    +

    C++11 introduces lambda functions defined as:

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

    If the lambda function contains a single return statement only or the function doesn't return any type, the return type '->' can be @@ -210,14 +210,14 @@ functions still work inside the function block though.

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

    Done: Added syntax support for the lambda functions. Added -testcase cpp0x_lambda_functions.i. R11491, R11492

    +testcase cpp11_lambda_functions.i. R11491, R11492

    Alternate function syntax [done]

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

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

    -The solution C++0x offers is the combination of the 'auto' keyword + decltype(lhs+rhs) AddingFunc(const LHS &lhs, const RHS &rhs) {return lhs + rhs;} //Not legal C++11

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

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

    @@ -233,13 +233,13 @@ auto SomeStruct::FuncName(int x, int y) -> int { }

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

    +cpp11_alternate_function_syntax.i and +cpp11_alternate_function_syntax_runme.py. R11414

    Concepts, Axioms [ignored]

    In C++ there is a common problem when you use a template in the class which doesn't support all the operations the functions in the class actually do on the type. Compiler errors are usually very long -and unreadable. C++0x adds support for the "concepts". The +and unreadable. C++11 adds support for the "concepts". The idea is to define what operations and attributes should the template have. In contrast to class inheritance and polimorphism, all lookups are done in compile-time. @@ -293,7 +293,7 @@ other constructs commonly associated with classes: T top(const std::vector<T>& v) { return v.back(); } bool empty(const std::vector<T>& v) { return v.empty(); } };

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

    @@ -306,7 +306,7 @@ Semigroup can be defined with an axiom Associativity as: Axioms are more like hints to the compiler to speed-up the process of compilation.

    -

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

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

    Object construction improvement [done]

    This feature allows classes constructors to call other @@ -335,7 +335,7 @@ the inherited class: };

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

    -

    Done: Added testcase cpp0x_constructors.i which covers both +

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

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

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

    -

    Done: Written a testcase cpp0x_null_pointer_constant.i and -cpp0x_null_pointer_constant_runme.py to prove the nullptr +

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

    Strongly typed enumerations [partially done]

    -

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

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

     enum class Enumeration {
       Val1,
    @@ -371,16 +371,16 @@ int etc.:
     
     enum class Enum2 : unsigned int {Val1, Val2};

    And it can be forward declared as well:

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

    +

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

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

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

    Problem: Swig currently doesn't support nested classes. This feature should be implemented using a new nested class when using @@ -396,7 +396,7 @@ following article as a base:

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

    +cpp11_template_double_brackets. R11245

    Explicit conversion operators [done]

    This is used when converting one type to another (eg. if (myObject) {}, where myObject is your custom class converted to @@ -407,9 +407,9 @@ supported in any target language (eg. python, php).

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

    +cpp11_explicit_conversion_operators. R11323

    Template typedefs [partially done]

    -

    The new C++0x will allow creation of wrapper around the template. +

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

    template< typename first, typename second, int third>
     class SomeType;
    @@ -433,7 +433,7 @@ using PF = void (*)(double);            // New introduced syntax

    Swig supports parsing typedefs for templates as well for example:

    typedef List<int> intList;

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

    +aliasing. Added testcase cpp11_template_typedefs. R11533

    TODO: Make Swig aware of the newly defined typedef. The TYPEDEF keyword is part of the storage_class rule and type+declarator (see c_decl rule) is the right part of the definition – for example void @@ -443,7 +443,7 @@ type, type_right rules and declarator, direct_declarator, notso_direct_declarator etc., which is PITA.

    Unrestricted unions [done]

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

     struct point {
       point() {}
    @@ -453,14 +453,14 @@ non-trivial constructors as well:

    union P { int z; double w; - point p; // Illegal in C++; point has a non-trivial constructor. However, this is legal in C++0x. + point p; // Illegal in C++; point has a non-trivial constructor. However, this is legal in C++11. } p1;

    Swig already parses the given syntax.

    -

    Done: Added testcase cpp0x_unrestricted_unions. R11435, R11447

    +

    Done: Added testcase cpp11_unrestricted_unions. R11435, R11447

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

    Variadic templates [partially done]

    -

    The new C++0x offers the following syntax:

    +

    The new C++11 offers the following syntax:

    template<typename... Values> class tuple;

    This can be used for example:

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

    @@ -502,7 +502,7 @@ A new extension to sizeof is also introduced with this feature. The } // SomeStruct<Type1, Type2>::size is 2 and SomeStruct<>::size is 0

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

    +Added testcase cpp11_variadic_templates. R11458

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

    @@ -510,11 +510,11 @@ Extended Swig syntax to support sizeof...(Args). R11467

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

    New string literals [partially done]

    -

    Beside the implementation, the new C++0x Unicode and custom +

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

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

    +UTF string. Also added test case cpp11_raw_string_literals. R11327

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

    TODO: Fix the Swig's C++ preprocessor bug when parsing an odd @@ -524,7 +524,7 @@ Source/Preprocessor/cpp.c.

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

    -

    C++0x allows user to define his own suffix for the strings always +

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

    The syntax is similar to other operator overloading functions: @@ -548,18 +548,18 @@ Another possibility is to use variadic templates: This instantiates the literal processing function as operator""_Suffix<'1', '2', '3', '4'>. In this form, there is no terminating null character to the string. The main -purpose to doing this is to use C++0x's constexpr keyword and the +purpose to doing this is to use C++11's constexpr keyword and the compiler to allow the literal to be transformed entirely at compile time, assuming OutputType is a constexpr-constructable and copyable type, and the literal processing function is a constexpr function.

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

    Done: Added syntax support for userdefined literals. Added -testcase cpp0x_userdefined_literals.i. R11494

    +testcase cpp11_userdefined_literals.i. R11494

    TODO: %rename doesn't parse operatorâ€â€ yet.

    Thread-local storage [done]

    -

    New C++0x introduces keyword "thread_local" which marks +

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

    @@ -569,7 +569,7 @@ thread when using the address-of (&) operator. thread_local int val; };

    Done: Add "thread_local" keyword to Swig. Added testcase -cpp0x_thread_local. R11393

    +cpp11_thread_local. R11393

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

    C++ automatically creates default constructor with empty parameters, copy constructor, operator= and destructor for any class. @@ -600,11 +600,11 @@ the standard functions brought by C++ itself. Ignored: Swig already parses the keywords "= delete" and "= default". These keywords are used for built-in functions (copy constructor, operator= etc.), which are ignored by Swig anyway.

    -

    Done: Added testcase cpp0x_default_delete. R11535

    +

    Done: Added testcase cpp11_default_delete. R11535

    Type long long int [done]

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

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

    @@ -616,18 +616,18 @@ C++0x. Most C++ compilers supported it though. static_assert(sizeof(int) <= sizeof(T), "not big enough"); };

    Done: Added syntax support for "static_assert()". Added -test case cpp0x_static_assert. R11369

    +test case cpp11_static_assert. R11369

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

    -

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

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

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

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

    This kind of syntax is already supported by Swig.

    -

    Done: Added testcase cpp0x_sizeof_objects. R11538 +

    Done: Added testcase cpp11_sizeof_objects. R11538

    Threading facilities [ignored]

    -

    C++0x will add the following classes to the standard library: +

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

     * std::thread
      * std::mutex, std::recursive_mutex
    @@ -637,7 +637,7 @@ This kind of syntax is already supported by Swig.

    Ignored: No changes to the language itself is made.

    Tuple types [TODO]

    -

    Tuple is array of various types. C++0x introduced this feature +

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

    template <class ...Types> class tuple;

    Constructor is automatically generated filling the tuple elements. @@ -655,7 +655,7 @@ t1 = t2 ; // Ok, first two elements can be converted, // the third one can be constructed from a 'const char *'.

    TODO: Implement wrappers for the tuplet<> class.

    Hash tables [TODO]

    -

    C++0x introduces the "unordered" version of existing +

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

     - unordered set
    @@ -671,7 +671,7 @@ aliasing unordered classes to ordered ones doesn't work.

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

    Regular expressions [ignored]

    -

    Two new classes are introduced in C++0x: basic_regex and +

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

    Ignored: The new feature extends the standardy library only. No @@ -725,9 +725,9 @@ changes to Swig needed. };

    Swig already supports the two.

    Done: Added a runtime testcase for function objects -cpp0x_function_objects. R11419.

    +cpp11_function_objects. R11419.

    Type traits for metaprogramming [ignored]

    -

    C++0x adds a new header file <type_traits> which includes +

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

    @@ -783,6 +783,6 @@ class calculus_ver2 { Swig correctly parses the result_of class.

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

    -

    Done: Added testcase cpp0x_result_of. R11534

    +

    Done: Added testcase cpp11_result_of. R11534

    - \ No newline at end of file + diff --git a/Doc/Manual/Cpp0x.html b/Doc/Manual/CPlusPlus11.html similarity index 78% rename from Doc/Manual/Cpp0x.html rename to Doc/Manual/CPlusPlus11.html index 457a7e41d..3caec748e 100644 --- a/Doc/Manual/Cpp0x.html +++ b/Doc/Manual/CPlusPlus11.html @@ -1,54 +1,54 @@ -SWIG and C++0x +SWIG and C++11 -

    7 SWIG and C++0x

    +

    7 SWIG and C++11

    @@ -56,22 +56,22 @@ -

    7.1 Introduction

    +

    7.1 Introduction

    This chapter gives you a brief overview about the SWIG -implementation of the C++0x standard. This part of SWIG is still a work in -progress. Initial C++0x support for SWIG was written during the +implementation of the C++11 standard. This part of SWIG is still a work in +progress. Initial C++11 support for SWIG was written during the Google Summer of Code 2009 period.

    SWIG supports all the new C++ syntax changes with some minor limitations (decltype expressions, variadic templates number). Wrappers for the new STL types (unordered_ containers, result_of, tuples) are not supported yet.

    -

    7.2 Core language changes

    +

    7.2 Core language changes

    -

    7.2.1 Rvalue reference and move semantics

    +

    7.2.1 Rvalue reference and move semantics

    SWIG correctly parses the new operator && the same as the reference operator &.

    @@ -87,7 +87,7 @@ class MyClass { }; -

    7.2.2 Generalized constant expressions

    +

    7.2.2 Generalized constant expressions

    SWIG correctly parses the keyword constexpr, but ignores its functionality. Constant functions cannot be used as constants.

    @@ -105,7 +105,7 @@ constexpr int myConstFunc() { return MY_CONST; } const int a = MY_CONST; // ok -

    7.2.3 Extern template

    +

    7.2.3 Extern template

    SWIG correctly parses the keywords extern template. However, the explicit template instantiation is not used by SWIG, a %template is still required.

    @@ -123,7 +123,7 @@ public: }; -

    7.2.4 Initializer lists

    +

    7.2.4 Initializer lists

    Initializer lists are very much a C++ compiler construct and are not very accessible from wrappers as @@ -254,7 +254,7 @@ Note that the default typemap for std::initializer_list does nothing bu and hence any user supplied typemaps will override it and suppress the warning.

    -

    7.2.5 Uniform initialization

    +

    7.2.5 Uniform initialization

    The curly brackets {} for member initialization are fully @@ -287,7 +287,7 @@ AltStruct var2{2, 4.3}; // calls the constructor 142.15 -

    7.2.6 Type inference

    +

    7.2.6 Type inference

    SWIG supports decltype() with some limitations. Single @@ -304,13 +304,13 @@ int i; int j; decltype(i+j) k; // syntax error -

    7.2.7 Range-based for-loop

    +

    7.2.7 Range-based for-loop

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

    -

    7.2.8 Lambda functions and expressions

    +

    7.2.8 Lambda functions and expressions

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

    @@ -336,7 +336,7 @@ auto six = [](int x, int y) { return x+y; }(4, 2); Better support should be available in a later release.

    -

    7.2.9 Alternate function syntax

    +

    7.2.9 Alternate function syntax

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

    @@ -346,7 +346,7 @@ struct SomeStruct { }; -

    can now be written as in C++0x:

    +

    can now be written as in C++11:

     struct SomeStruct {
    @@ -371,7 +371,7 @@ auto SomeStruct::FuncName(int x, int y) -> int {
     auto square(float a, float b) -> decltype(a);
     
    -

    7.2.10 Object construction improvement

    +

    7.2.10 Object construction improvement

    @@ -412,12 +412,12 @@ class DerivedClass: public BaseClass { }; -

    7.2.11 Null pointer constant

    +

    7.2.11 Null pointer constant

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

    -

    7.2.12 Strongly typed enumerations

    +

    7.2.12 Strongly typed enumerations

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

    @@ -468,7 +468,7 @@ class AllColors { }; -

    7.2.13 Double angle brackets

    +

    7.2.13 Double angle brackets

    SWIG correctly parses the symbols >> as closing the @@ -479,7 +479,7 @@ shift operator >> otherwise.

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

    7.2.14 Explicit conversion operators

    +

    7.2.14 Explicit conversion operators

    SWIG correctly parses the keyword explicit both for operators and constructors. @@ -515,7 +515,7 @@ SWIG target languages, because all use their own facilities (eg. classes Cloneab to achieve particular copy and compare behaviours.

    -

    7.2.15 Alias templates

    +

    7.2.15 Alias templates

    The following is an example of an alias template: @@ -567,7 +567,7 @@ example.i:17: Warning 341: The 'using' keyword in type aliasing is not fully sup typedef void (*PFD)(double); // The old style -

    7.2.16 Unrestricted unions

    +

    7.2.16 Unrestricted unions

    SWIG fully supports any type inside a union even if it does not @@ -593,7 +593,7 @@ union P { } p1; -

    7.2.17 Variadic templates

    +

    7.2.17 Variadic templates

    SWIG supports the variadic templates syntax (inside the <> @@ -628,7 +628,7 @@ const int SIZE = sizeof...(ClassName<int, int>); In the above example SIZE is of course wrapped as a constant.

    -

    7.2.18 New string literals

    +

    7.2.18 New string literals

    SWIG supports unicode string constants and raw string literals.

    @@ -652,7 +652,7 @@ const char32_t *ii = UR"XXX(I'm a "raw UTF-32" \ string.)XXX";

    Note: SWIG currently incorrectly parses the odd number of double quotes inside the string due to SWIG's C++ preprocessor.

    -

    7.2.19 User-defined literals

    +

    7.2.19 User-defined literals

    @@ -719,7 +719,7 @@ OutputType var2 = 1234_suffix; OutputType var3 = 3.1416_suffix; -

    7.2.20 Thread-local storage

    +

    7.2.20 Thread-local storage

    SWIG correctly parses the thread_local keyword. For example, variable @@ -739,7 +739,7 @@ A variable will be thread local if accessed from different threads from the targ same way that it will be thread local if accessed from C++ code.

    -

    7.2.21 Defaulting/deleting of standard functions on C++ objects

    +

    7.2.21 Defaulting/deleting of standard functions on C++ objects

    SWIG correctly parses the = delete and = default @@ -757,12 +757,12 @@ struct NonCopyable {

    This feature is specific to C++ only. The defaulting/deleting is currently ignored, because SWIG automatically produces wrappers for special constructors and operators specific to the target language.

    -

    7.2.22 Type long long int

    +

    7.2.22 Type long long int

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

    -

    7.2.23 Static assertions

    +

    7.2.23 Static assertions

    SWIG correctly parses and calls the new static_assert function.

    @@ -774,7 +774,7 @@ struct Check { }; -

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

    +

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

    SWIG correctly calls the sizeof() on types as well as on the @@ -785,7 +785,7 @@ struct A { int member; }; -const int SIZE = sizeof(A::member); // does not work with C++03. Okay with C++0x +const int SIZE = sizeof(A::member); // does not work with C++03. Okay with C++11

    In Python:

    @@ -794,28 +794,28 @@ const int SIZE = sizeof(A::member); // does not work with C++03. Okay with C++0x 8 -

    7.3 Standard library changes

    +

    7.3 Standard library changes

    -

    7.3.1 Threading facilities

    +

    7.3.1 Threading facilities

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

    -

    7.3.2 Tuple types and hash tables

    +

    7.3.2 Tuple types and hash tables

    SWIG does not wrap the new tuple types and the unordered_ container classes yet. Variadic template support is working so it is possible to include the tuple header file; it is parsed without any problems.

    -

    7.3.3 Regular expressions

    +

    7.3.3 Regular expressions

    -

    SWIG does not wrap the new C++0x regular expressions classes, because the SWIG target languages use their own facilities for this.

    +

    SWIG does not wrap the new C++11 regular expressions classes, because the SWIG target languages use their own facilities for this.

    -

    7.3.4 General-purpose smart pointers

    +

    7.3.4 General-purpose smart pointers

    @@ -823,12 +823,12 @@ SWIG provides special smart pointer handling for std::tr1::shared_ptr i There is no special smart pointer handling available for std::weak_ptr and std::unique_ptr.

    -

    7.3.5 Extensible random number facility

    +

    7.3.5 Extensible random number facility

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

    -

    7.3.6 Wrapper reference

    +

    7.3.6 Wrapper reference

    The new ref and cref classes are used to instantiate a parameter as a reference of a template function. For example:

    @@ -853,7 +853,7 @@ int main() {

    The ref and cref classes are not wrapped by SWIG because the SWIG target languages do not support referencing.

    -

    7.3.7 Polymorphous wrappers for function objects

    +

    7.3.7 Polymorphous wrappers for function objects

    @@ -884,7 +884,7 @@ t = Test() b = t(1,2) # invoke C++ function object -

    7.3.8 Type traits for metaprogramming

    +

    7.3.8 Type traits for metaprogramming

    The new C++ metaprogramming is useful at compile time and is aimed specifically for C++ development:

    @@ -909,7 +909,7 @@ template< class T1, class T2 > int elaborate( T1 A, T2 B ) {

    SWIG correctly parses the template specialization, template types and values inside the <> block and the new helper functions: is_convertible, is_integral, is_const etc. However, SWIG still explicitly requires concrete types when using the %template directive, so the C++ metaprogramming features are not really of interest at runtime in the target languages.

    -

    7.3.9 Uniform method for computing return type of function objects

    +

    7.3.9 Uniform method for computing return type of function objects

    SWIG does not wrap the new result_of class introduced in the <functional> header and map the result_of::type to the concrete type yet. For example:

    diff --git a/Doc/Manual/chapters b/Doc/Manual/chapters index fd21651e3..45d35e793 100644 --- a/Doc/Manual/chapters +++ b/Doc/Manual/chapters @@ -4,7 +4,7 @@ Windows.html Scripting.html SWIG.html SWIGPlus.html -Cpp0x.html +CPlusPlus11.html Preprocessor.html Library.html Arguments.html diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index c0f642212..be6b4736a 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -87,7 +87,7 @@ CPP_TEST_BROKEN += \ overload_complicated \ template_default_pointer \ template_expr \ - $(CPP0X_TEST_BROKEN) + $(CPP11_TEST_BROKEN) # Broken C test cases. (Can be run individually using: make testcase.ctest) @@ -97,7 +97,7 @@ C_TEST_BROKEN += \ # C++ test cases. (Can be run individually using: make testcase.cpptest) CPP_TEST_CASES += \ - $(CPP0X_TEST_CASES) \ + $(CPP11_TEST_CASES) \ abstract_access \ abstract_inherit \ abstract_inherit_ok \ @@ -476,41 +476,41 @@ CPP_TEST_CASES += \ wallkw \ wrapmacro -# C++0x test cases. -CPP0X_TEST_CASES = \ - cpp0x_alternate_function_syntax \ - cpp0x_constexpr \ - cpp0x_decltype \ - cpp0x_default_delete \ - cpp0x_delegating_constructors \ - cpp0x_explicit_conversion_operators \ - cpp0x_function_objects \ - cpp0x_initializer_list \ - cpp0x_initializer_list_extend \ - cpp0x_lambda_functions \ - cpp0x_null_pointer_constant \ - cpp0x_raw_string_literals \ - cpp0x_rvalue_reference \ - cpp0x_rvalue_reference2 \ - cpp0x_rvalue_reference3 \ - cpp0x_sizeof_object \ - cpp0x_static_assert \ - cpp0x_strongly_typed_enumerations \ - cpp0x_template_double_brackets \ - cpp0x_template_explicit \ - cpp0x_template_typedefs \ - cpp0x_uniform_initialization \ - cpp0x_unrestricted_unions \ - cpp0x_userdefined_literals \ - cpp0x_variadic_templates +# C++11 test cases. +CPP11_TEST_CASES = \ + cpp11_alternate_function_syntax \ + cpp11_constexpr \ + cpp11_decltype \ + cpp11_default_delete \ + cpp11_delegating_constructors \ + cpp11_explicit_conversion_operators \ + cpp11_function_objects \ + cpp11_initializer_list \ + cpp11_initializer_list_extend \ + cpp11_lambda_functions \ + cpp11_null_pointer_constant \ + cpp11_raw_string_literals \ + cpp11_rvalue_reference \ + cpp11_rvalue_reference2 \ + cpp11_rvalue_reference3 \ + cpp11_sizeof_object \ + cpp11_static_assert \ + cpp11_strongly_typed_enumerations \ + cpp11_template_double_brackets \ + cpp11_template_explicit \ + cpp11_template_typedefs \ + cpp11_uniform_initialization \ + cpp11_unrestricted_unions \ + cpp11_userdefined_literals \ + cpp11_variadic_templates -# cpp0x_inheriting_constructors \ # not supported by gcc-4.7 -# cpp0x_hash_tables \ # not fully implemented yet -# cpp0x_result_of \ # SWIG does not support -# cpp0x_thread_local \ # needs gcc-4.8 +# cpp11_inheriting_constructors \ # not supported by gcc-4.7 +# cpp11_hash_tables \ # not fully implemented yet +# cpp11_result_of \ # SWIG does not support +# cpp11_thread_local \ # needs gcc-4.8 -# Broken C++0x test cases. -CPP0X_TEST_BROKEN = +# Broken C++11 test cases. +CPP11_TEST_BROKEN = # # Put all the heavy STD/STL cases here, where they can be skipped if needed @@ -626,7 +626,7 @@ all: $(NOT_BROKEN_TEST_CASES) $(BROKEN_TEST_CASES) check: $(NOT_BROKEN_TEST_CASES) -check-cpp11: $(CPP0X_TEST_CASES:=.cpptest) +check-cpp11: $(CPP11_TEST_CASES:=.cpptest) # partialcheck target runs SWIG only, ie no compilation or running of tests (for a subset of languages) partialcheck: diff --git a/Examples/test-suite/cpp0x_alternate_function_syntax.i b/Examples/test-suite/cpp11_alternate_function_syntax.i similarity index 77% rename from Examples/test-suite/cpp0x_alternate_function_syntax.i rename to Examples/test-suite/cpp11_alternate_function_syntax.i index 6726dad7c..227a1c8c8 100644 --- a/Examples/test-suite/cpp0x_alternate_function_syntax.i +++ b/Examples/test-suite/cpp11_alternate_function_syntax.i @@ -1,6 +1,6 @@ /* This testcase checks whether SWIG correctly uses the new alternate functions - declarations and definitions introduced in C++0x. */ -%module cpp0x_alternate_function_syntax + declarations and definitions introduced in C++11. */ +%module cpp11_alternate_function_syntax %inline %{ struct SomeStruct { diff --git a/Examples/test-suite/cpp0x_constexpr.i b/Examples/test-suite/cpp11_constexpr.i similarity index 76% rename from Examples/test-suite/cpp0x_constexpr.i rename to Examples/test-suite/cpp11_constexpr.i index ae1d292b4..95fe5fa2b 100644 --- a/Examples/test-suite/cpp0x_constexpr.i +++ b/Examples/test-suite/cpp11_constexpr.i @@ -1,7 +1,7 @@ /* This interface tests whether SWIG supports the new "constexpr" keyword - introduced by C++0x. + introduced by C++11. */ -%module cpp0x_constexpr +%module cpp11_constexpr %inline %{ class TestClass { diff --git a/Examples/test-suite/cpp0x_decltype.i b/Examples/test-suite/cpp11_decltype.i similarity index 85% rename from Examples/test-suite/cpp0x_decltype.i rename to Examples/test-suite/cpp11_decltype.i index 5a4292454..deedd5953 100644 --- a/Examples/test-suite/cpp0x_decltype.i +++ b/Examples/test-suite/cpp11_decltype.i @@ -1,7 +1,7 @@ /* This testcase checks whether SWIG correctly uses the new 'decltype()' - introduced in C++0x. + introduced in C++11. */ -%module cpp0x_decltype +%module cpp11_decltype %inline %{ class A { diff --git a/Examples/test-suite/cpp0x_default_delete.i b/Examples/test-suite/cpp11_default_delete.i similarity index 96% rename from Examples/test-suite/cpp0x_default_delete.i rename to Examples/test-suite/cpp11_default_delete.i index bdb74ffb1..be4cc6cc9 100644 --- a/Examples/test-suite/cpp0x_default_delete.i +++ b/Examples/test-suite/cpp11_default_delete.i @@ -1,6 +1,6 @@ /* This testcase checks whether SWIG correctly parses the default and delete keywords which keep or remove default C++ object construction functions. */ -%module cpp0x_default_delete +%module cpp11_default_delete %{ #include diff --git a/Examples/test-suite/cpp0x_delegating_constructors.i b/Examples/test-suite/cpp11_delegating_constructors.i similarity index 88% rename from Examples/test-suite/cpp0x_delegating_constructors.i rename to Examples/test-suite/cpp11_delegating_constructors.i index 679dce242..ca5aa326e 100644 --- a/Examples/test-suite/cpp0x_delegating_constructors.i +++ b/Examples/test-suite/cpp11_delegating_constructors.i @@ -1,7 +1,7 @@ /* This test checks whether SWIG correctly parses the new delegating constructors. */ -%module cpp0x_delegating_constructors +%module cpp11_delegating_constructors %inline %{ class A { diff --git a/Examples/test-suite/cpp0x_explicit_conversion_operators.i b/Examples/test-suite/cpp11_explicit_conversion_operators.i similarity index 76% rename from Examples/test-suite/cpp0x_explicit_conversion_operators.i rename to Examples/test-suite/cpp11_explicit_conversion_operators.i index 313b5e878..5e3ba03df 100644 --- a/Examples/test-suite/cpp0x_explicit_conversion_operators.i +++ b/Examples/test-suite/cpp11_explicit_conversion_operators.i @@ -1,7 +1,7 @@ /* This interface checks whether SWIG correctly compiles the new - explicit conversion operators feature introduced in C++0x. + explicit conversion operators feature introduced in C++11. */ -%module cpp0x_explicit_conversion_operators +%module cpp11_explicit_conversion_operators %inline %{ diff --git a/Examples/test-suite/cpp0x_function_objects.i b/Examples/test-suite/cpp11_function_objects.i similarity index 95% rename from Examples/test-suite/cpp0x_function_objects.i rename to Examples/test-suite/cpp11_function_objects.i index 4b9895ca8..fb75edea6 100644 --- a/Examples/test-suite/cpp0x_function_objects.i +++ b/Examples/test-suite/cpp11_function_objects.i @@ -3,7 +3,7 @@ Function objects are objects which overload the operator() function. The std::function does not provide any seamless support in the target languages yet. */ -%module cpp0x_function_objects +%module cpp11_function_objects %rename(__call__) Test::operator(); diff --git a/Examples/test-suite/cpp0x_hash_tables.i b/Examples/test-suite/cpp11_hash_tables.i similarity index 95% rename from Examples/test-suite/cpp0x_hash_tables.i rename to Examples/test-suite/cpp11_hash_tables.i index fff630ca0..4f68cbac5 100644 --- a/Examples/test-suite/cpp0x_hash_tables.i +++ b/Examples/test-suite/cpp11_hash_tables.i @@ -1,6 +1,6 @@ /* This testcase checks the new wrappers for the new unordered_ STL types - introduced in C++0x. */ -%module cpp0x_hash_tables + introduced in C++11. */ +%module cpp11_hash_tables %inline %{ #include diff --git a/Examples/test-suite/cpp0x_inheriting_constructors.i b/Examples/test-suite/cpp11_inheriting_constructors.i similarity index 89% rename from Examples/test-suite/cpp0x_inheriting_constructors.i rename to Examples/test-suite/cpp11_inheriting_constructors.i index 452598360..e1adb4caa 100644 --- a/Examples/test-suite/cpp0x_inheriting_constructors.i +++ b/Examples/test-suite/cpp11_inheriting_constructors.i @@ -1,7 +1,7 @@ /* This test checks whether SWIG correctly parses the new constructor inheritance. */ -%module cpp0x_inheriting_constructors +%module cpp11_inheriting_constructors %inline %{ class BaseClass { diff --git a/Examples/test-suite/cpp0x_initializer_list.i b/Examples/test-suite/cpp11_initializer_list.i similarity index 91% rename from Examples/test-suite/cpp0x_initializer_list.i rename to Examples/test-suite/cpp11_initializer_list.i index 14833390e..58d2ecc50 100644 --- a/Examples/test-suite/cpp0x_initializer_list.i +++ b/Examples/test-suite/cpp11_initializer_list.i @@ -1,6 +1,6 @@ /* This testcase shows a few simple ways to deal with the new initializer_list - introduced in C++0x. */ -%module cpp0x_initializer_list + introduced in C++11. */ +%module cpp11_initializer_list %warnfilter(SWIGWARN_TYPEMAP_INITIALIZER_LIST) B::B; %ignore A::A(std::initializer_list); diff --git a/Examples/test-suite/cpp0x_initializer_list_extend.i b/Examples/test-suite/cpp11_initializer_list_extend.i similarity index 93% rename from Examples/test-suite/cpp0x_initializer_list_extend.i rename to Examples/test-suite/cpp11_initializer_list_extend.i index d8443e622..02ad1312e 100644 --- a/Examples/test-suite/cpp0x_initializer_list_extend.i +++ b/Examples/test-suite/cpp11_initializer_list_extend.i @@ -1,6 +1,6 @@ /* This testcase shows how to replace std_initializer_list with std_vector. */ -%module cpp0x_initializer_list_extend +%module cpp11_initializer_list_extend %ignore Container::Container(std::initializer_list); %include diff --git a/Examples/test-suite/cpp0x_lambda_functions.i b/Examples/test-suite/cpp11_lambda_functions.i similarity index 97% rename from Examples/test-suite/cpp0x_lambda_functions.i rename to Examples/test-suite/cpp11_lambda_functions.i index 312414a49..87c7196d8 100644 --- a/Examples/test-suite/cpp0x_lambda_functions.i +++ b/Examples/test-suite/cpp11_lambda_functions.i @@ -1,9 +1,9 @@ /* This testcase checks whether SWIG correctly parses the lambda expressions - and closure syntax introduced in C++0x. + and closure syntax introduced in C++11. SWIG supports only lambda syntax and doesn't produce any wrapper code for this. */ -%module cpp0x_lambda_functions +%module cpp11_lambda_functions %warnfilter(SWIGWARN_CPP11_LAMBDA) lambda1; %warnfilter(SWIGWARN_CPP11_LAMBDA) lambda2; diff --git a/Examples/test-suite/cpp0x_null_pointer_constant.i b/Examples/test-suite/cpp11_null_pointer_constant.i similarity index 85% rename from Examples/test-suite/cpp0x_null_pointer_constant.i rename to Examples/test-suite/cpp11_null_pointer_constant.i index dcb5e61bd..0b3276a44 100644 --- a/Examples/test-suite/cpp0x_null_pointer_constant.i +++ b/Examples/test-suite/cpp11_null_pointer_constant.i @@ -1,8 +1,8 @@ /* This testcase checks whether SWIG correctly treats the new nullptr_t - constant introduced in C++0x. + constant introduced in C++11. */ -%module cpp0x_null_pointer_constant +%module cpp11_null_pointer_constant %feature("autodoc") A::NullPtrMethod; // Triggers conversion of nullptr to None, nil etc in target language %feature("compactdefaultargs") A::NullPtrMethod; diff --git a/Examples/test-suite/cpp0x_raw_string_literals.i b/Examples/test-suite/cpp11_raw_string_literals.i similarity index 97% rename from Examples/test-suite/cpp0x_raw_string_literals.i rename to Examples/test-suite/cpp11_raw_string_literals.i index 39a8bb641..6fd13a0d0 100644 --- a/Examples/test-suite/cpp0x_raw_string_literals.i +++ b/Examples/test-suite/cpp11_raw_string_literals.i @@ -7,7 +7,7 @@ This module also tests whether SWIG correctly parses custom string delimiters. */ -%module cpp0x_raw_string_literals +%module cpp11_raw_string_literals %warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) bb; %warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) ee; %warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) gg; diff --git a/Examples/test-suite/cpp0x_result_of.i b/Examples/test-suite/cpp11_result_of.i similarity index 83% rename from Examples/test-suite/cpp0x_result_of.i rename to Examples/test-suite/cpp11_result_of.i index 42ff6c068..6d98ec0c0 100644 --- a/Examples/test-suite/cpp0x_result_of.i +++ b/Examples/test-suite/cpp11_result_of.i @@ -1,6 +1,6 @@ /* This testcase checks whether SWIG correctly uses the new result_of class - and its templating capabilities introduced in C++0x. */ -%module cpp0x_result_of + and its templating capabilities introduced in C++11. */ +%module cpp11_result_of %inline %{ #include diff --git a/Examples/test-suite/cpp0x_rvalue_reference.i b/Examples/test-suite/cpp11_rvalue_reference.i similarity index 94% rename from Examples/test-suite/cpp0x_rvalue_reference.i rename to Examples/test-suite/cpp11_rvalue_reference.i index 67686bc0f..45ee06354 100644 --- a/Examples/test-suite/cpp0x_rvalue_reference.i +++ b/Examples/test-suite/cpp11_rvalue_reference.i @@ -1,6 +1,6 @@ /* This testcase checks whether SWIG correctly parses the double ampersand && move operator which is currently mapped to the reference & operator. */ -%module cpp0x_rvalue_reference +%module cpp11_rvalue_reference %inline %{ #include diff --git a/Examples/test-suite/cpp0x_rvalue_reference2.i b/Examples/test-suite/cpp11_rvalue_reference2.i similarity index 98% rename from Examples/test-suite/cpp0x_rvalue_reference2.i rename to Examples/test-suite/cpp11_rvalue_reference2.i index dbeaa78fa..4ef871c63 100644 --- a/Examples/test-suite/cpp0x_rvalue_reference2.i +++ b/Examples/test-suite/cpp11_rvalue_reference2.i @@ -1,4 +1,4 @@ -%module cpp0x_rvalue_reference2 +%module cpp11_rvalue_reference2 %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK) globalrrval; diff --git a/Examples/test-suite/cpp0x_rvalue_reference3.i b/Examples/test-suite/cpp11_rvalue_reference3.i similarity index 98% rename from Examples/test-suite/cpp0x_rvalue_reference3.i rename to Examples/test-suite/cpp11_rvalue_reference3.i index 2da1bf741..c65309945 100644 --- a/Examples/test-suite/cpp0x_rvalue_reference3.i +++ b/Examples/test-suite/cpp11_rvalue_reference3.i @@ -1,4 +1,4 @@ -%module cpp0x_rvalue_reference3 +%module cpp11_rvalue_reference3 %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); diff --git a/Examples/test-suite/cpp0x_sizeof_object.i b/Examples/test-suite/cpp11_sizeof_object.i similarity index 71% rename from Examples/test-suite/cpp0x_sizeof_object.i rename to Examples/test-suite/cpp11_sizeof_object.i index 72299786d..fca8a8ccc 100644 --- a/Examples/test-suite/cpp0x_sizeof_object.i +++ b/Examples/test-suite/cpp11_sizeof_object.i @@ -1,6 +1,6 @@ /* This testcase checks whether SWIG correctly uses the sizeof() on the - concrete objects and not only types introduced in C++0x. */ -%module cpp0x_sizeof_object + concrete objects and not only types introduced in C++11. */ +%module cpp11_sizeof_object %inline %{ struct B { diff --git a/Examples/test-suite/cpp0x_static_assert.i b/Examples/test-suite/cpp11_static_assert.i similarity index 92% rename from Examples/test-suite/cpp0x_static_assert.i rename to Examples/test-suite/cpp11_static_assert.i index d6413a1e5..8d616f96c 100644 --- a/Examples/test-suite/cpp0x_static_assert.i +++ b/Examples/test-suite/cpp11_static_assert.i @@ -1,7 +1,7 @@ /* This test case checks whether SWIG correctly parses and ignores the keywords "static_assert()" inside the class or struct. */ -%module cpp0x_static_assert +%module cpp11_static_assert %inline %{ template diff --git a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i b/Examples/test-suite/cpp11_strongly_typed_enumerations.i similarity index 84% rename from Examples/test-suite/cpp0x_strongly_typed_enumerations.i rename to Examples/test-suite/cpp11_strongly_typed_enumerations.i index dbe6d44bc..ed466369e 100644 --- a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i +++ b/Examples/test-suite/cpp11_strongly_typed_enumerations.i @@ -1,7 +1,7 @@ /* This testcase checks whether SWIG produces the correct wrapper for the strongly typed enums. Enums with the same type are comparable. Enum classes require support for nested classes. */ -%module cpp0x_strongly_typed_enumerations +%module cpp11_strongly_typed_enumerations %warnfilter(302) Val1; %warnfilter(302) Val2; %warnfilter(302) Val3; @@ -30,13 +30,13 @@ enum class Enum2 : short { %} // SWIG should fail this one -enum Enum2 : unsigned short; // Illegal in C++0x, because Enum2 was previously declared with a different type. +enum Enum2 : unsigned short; // Illegal in C++11, because Enum2 was previously declared with a different type. %inline %{ /* Forward declarations. */ -enum Enum4 : unsigned int; // Legal in C++0x. -enum class Enum5; // Legal in C++0x, because enum class declarations have a default type of "int". -enum class Enum6 : unsigned int; // Legal C++0x. +enum Enum4 : unsigned int; // Legal in C++11. +enum class Enum5; // Legal in C++11, because enum class declarations have a default type of "int". +enum class Enum6 : unsigned int; // Legal C++11. enum Enum4 : unsigned int { Val1, Val2, Val3 = 100, Val4 diff --git a/Examples/test-suite/cpp0x_template_double_brackets.i b/Examples/test-suite/cpp11_template_double_brackets.i similarity index 91% rename from Examples/test-suite/cpp0x_template_double_brackets.i rename to Examples/test-suite/cpp11_template_double_brackets.i index 6b2230362..15fe4903b 100644 --- a/Examples/test-suite/cpp0x_template_double_brackets.i +++ b/Examples/test-suite/cpp11_template_double_brackets.i @@ -1,8 +1,8 @@ /* This interface checks whether SWIG supports the new double angled brackets in the template syntax without having a space inbetween. This feature was - introduced in new C++0x standard. + introduced in new C++11 standard. */ -%module cpp0x_template_double_brackets +%module cpp11_template_double_brackets %inline %{ #include std::map> map1; diff --git a/Examples/test-suite/cpp0x_template_explicit.i b/Examples/test-suite/cpp11_template_explicit.i similarity index 81% rename from Examples/test-suite/cpp0x_template_explicit.i rename to Examples/test-suite/cpp11_template_explicit.i index bbc216ba0..80a30d283 100644 --- a/Examples/test-suite/cpp0x_template_explicit.i +++ b/Examples/test-suite/cpp11_template_explicit.i @@ -1,8 +1,8 @@ /* This unit tests whether SWIG correctly parses the code and makes wrappers - for the new C++0x extern templates (explicit template instantiation without + for the new C++11 extern templates (explicit template instantiation without using the translation unit). */ -%module cpp0x_template_explicit +%module cpp11_template_explicit #pragma SWIG nowarn=SWIGWARN_PARSE_EXPLICIT_TEMPLATE diff --git a/Examples/test-suite/cpp0x_template_typedefs.i b/Examples/test-suite/cpp11_template_typedefs.i similarity index 94% rename from Examples/test-suite/cpp0x_template_typedefs.i rename to Examples/test-suite/cpp11_template_typedefs.i index aeffde11a..ea46706a9 100644 --- a/Examples/test-suite/cpp0x_template_typedefs.i +++ b/Examples/test-suite/cpp11_template_typedefs.i @@ -1,5 +1,5 @@ /* This testcase checks whether SWIG correctly parses alias templates. */ -%module cpp0x_template_typedefs +%module cpp11_template_typedefs %warnfilter(SWIGWARN_CPP11_ALIAS_TEMPLATE) TypedefName; %warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) PF; diff --git a/Examples/test-suite/cpp0x_thread_local.i b/Examples/test-suite/cpp11_thread_local.i similarity index 97% rename from Examples/test-suite/cpp0x_thread_local.i rename to Examples/test-suite/cpp11_thread_local.i index 00f12dff9..6a1019824 100644 --- a/Examples/test-suite/cpp0x_thread_local.i +++ b/Examples/test-suite/cpp11_thread_local.i @@ -1,6 +1,6 @@ /* This testcase checks whether SWIG correctly parses the 'thread_local' storage specifier */ -%module cpp0x_thread_local +%module cpp11_thread_local %inline %{ struct ThreadLocals { diff --git a/Examples/test-suite/cpp0x_uniform_initialization.i b/Examples/test-suite/cpp11_uniform_initialization.i similarity index 96% rename from Examples/test-suite/cpp0x_uniform_initialization.i rename to Examples/test-suite/cpp11_uniform_initialization.i index 81a3e45de..07fb81280 100644 --- a/Examples/test-suite/cpp0x_uniform_initialization.i +++ b/Examples/test-suite/cpp11_uniform_initialization.i @@ -1,6 +1,6 @@ /* This testcase checks whether SWIG syntactically correctly parses the initialization syntax using {} braces for uniform member initialization. */ -%module cpp0x_uniform_initialization +%module cpp11_uniform_initialization %include diff --git a/Examples/test-suite/cpp0x_unrestricted_unions.i b/Examples/test-suite/cpp11_unrestricted_unions.i similarity index 93% rename from Examples/test-suite/cpp0x_unrestricted_unions.i rename to Examples/test-suite/cpp11_unrestricted_unions.i index be65fd83d..5facaafe1 100644 --- a/Examples/test-suite/cpp0x_unrestricted_unions.i +++ b/Examples/test-suite/cpp11_unrestricted_unions.i @@ -1,6 +1,6 @@ /* This testcase checks whether SWIG correctly parses the support for types without the defined trivial constructor in the unions. */ -%module cpp0x_unrestricted_unions +%module cpp11_unrestricted_unions %inline %{ struct point { diff --git a/Examples/test-suite/cpp0x_userdefined_literals.i b/Examples/test-suite/cpp11_userdefined_literals.i similarity index 97% rename from Examples/test-suite/cpp0x_userdefined_literals.i rename to Examples/test-suite/cpp11_userdefined_literals.i index d20345fed..43103cc8c 100644 --- a/Examples/test-suite/cpp0x_userdefined_literals.i +++ b/Examples/test-suite/cpp11_userdefined_literals.i @@ -1,6 +1,6 @@ /* This testcase checks whether SWIG correctly parses the user-defined literals - introduced in C++0x. */ -%module cpp0x_userdefined_literals + introduced in C++11. */ +%module cpp11_userdefined_literals // Unfortunately full declaration is needed for %rename atm, the parameter list cannot be omitted. %rename(MyRawLiteral) operator"" _myRawLiteral(const char * value); diff --git a/Examples/test-suite/cpp0x_variadic_templates.i b/Examples/test-suite/cpp11_variadic_templates.i similarity index 98% rename from Examples/test-suite/cpp0x_variadic_templates.i rename to Examples/test-suite/cpp11_variadic_templates.i index 2c0b2eac8..15ab4eece 100644 --- a/Examples/test-suite/cpp0x_variadic_templates.i +++ b/Examples/test-suite/cpp11_variadic_templates.i @@ -3,7 +3,7 @@ the template brackets, new functions sizeof... and multiple inheritance using variadic number of classes. */ -%module cpp0x_variadic_templates +%module cpp11_variadic_templates %warnfilter(SWIGWARN_CPP11_VARIADIC_TEMPLATE) MultiArgs; %warnfilter(SWIGWARN_CPP11_VARIADIC_TEMPLATE) SizeOf; %warnfilter(SWIGWARN_CPP11_VARIADIC_TEMPLATE) MultiInherit; diff --git a/Examples/test-suite/java/cpp0x_lambda_functions_runme.java b/Examples/test-suite/java/cpp11_lambda_functions_runme.java similarity index 52% rename from Examples/test-suite/java/cpp0x_lambda_functions_runme.java rename to Examples/test-suite/java/cpp11_lambda_functions_runme.java index 79545f87e..a0d310c7c 100644 --- a/Examples/test-suite/java/cpp0x_lambda_functions_runme.java +++ b/Examples/test-suite/java/cpp11_lambda_functions_runme.java @@ -1,10 +1,10 @@ -import cpp0x_lambda_functions.*; +import cpp11_lambda_functions.*; -public class cpp0x_lambda_functions_runme { +public class cpp11_lambda_functions_runme { static { try { - System.loadLibrary("cpp0x_lambda_functions"); + System.loadLibrary("cpp11_lambda_functions"); } 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); @@ -18,11 +18,11 @@ public class cpp0x_lambda_functions_runme { public static void main(String argv[]) { - check(cpp0x_lambda_functions.runLambda1(), 11); - check(cpp0x_lambda_functions.runLambda2(), 11); - check(cpp0x_lambda_functions.runLambda3(), 11); - check(cpp0x_lambda_functions.runLambda4(), 11); - check(cpp0x_lambda_functions.runLambda5(), 1); - check(cpp0x_lambda_functions.runLambda5(), 2); + check(cpp11_lambda_functions.runLambda1(), 11); + check(cpp11_lambda_functions.runLambda2(), 11); + check(cpp11_lambda_functions.runLambda3(), 11); + check(cpp11_lambda_functions.runLambda4(), 11); + check(cpp11_lambda_functions.runLambda5(), 1); + check(cpp11_lambda_functions.runLambda5(), 2); } } diff --git a/Examples/test-suite/java/cpp0x_thread_local_runme.java b/Examples/test-suite/java/cpp11_thread_local_runme.java similarity index 52% rename from Examples/test-suite/java/cpp0x_thread_local_runme.java rename to Examples/test-suite/java/cpp11_thread_local_runme.java index dc7cafafe..a645fbabf 100644 --- a/Examples/test-suite/java/cpp0x_thread_local_runme.java +++ b/Examples/test-suite/java/cpp11_thread_local_runme.java @@ -1,10 +1,10 @@ -import cpp0x_thread_local.*; +import cpp11_thread_local.*; -public class cpp0x_thread_local_runme { +public class cpp11_thread_local_runme { static { try { - System.loadLibrary("cpp0x_thread_local"); + System.loadLibrary("cpp11_thread_local"); } 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); @@ -20,32 +20,32 @@ public class cpp0x_thread_local_runme { if (ThreadLocals.tscval99 != 99) throw new RuntimeException(); - cpp0x_thread_local.setEtval(-11); - if (cpp0x_thread_local.getEtval() != -11) + cpp11_thread_local.setEtval(-11); + if (cpp11_thread_local.getEtval() != -11) throw new RuntimeException(); - cpp0x_thread_local.setStval(-22); - if (cpp0x_thread_local.getStval() != -22) + cpp11_thread_local.setStval(-22); + if (cpp11_thread_local.getStval() != -22) throw new RuntimeException(); - cpp0x_thread_local.setTsval(-33); - if (cpp0x_thread_local.getTsval() != -33) + cpp11_thread_local.setTsval(-33); + if (cpp11_thread_local.getTsval() != -33) throw new RuntimeException(); - cpp0x_thread_local.setEtval(-44); - if (cpp0x_thread_local.getEtval() != -44) + cpp11_thread_local.setEtval(-44); + if (cpp11_thread_local.getEtval() != -44) throw new RuntimeException(); - cpp0x_thread_local.setTeval(-55); - if (cpp0x_thread_local.getTeval() != -55) + cpp11_thread_local.setTeval(-55); + if (cpp11_thread_local.getTeval() != -55) throw new RuntimeException(); - cpp0x_thread_local.setEctval(-55); - if (cpp0x_thread_local.getEctval() != -55) + cpp11_thread_local.setEctval(-55); + if (cpp11_thread_local.getEctval() != -55) throw new RuntimeException(); - cpp0x_thread_local.setEcpptval(-66); - if (cpp0x_thread_local.getEcpptval() != -66) + cpp11_thread_local.setEcpptval(-66); + if (cpp11_thread_local.getEcpptval() != -66) throw new RuntimeException(); } } diff --git a/Examples/test-suite/python/cpp0x_function_objects_runme.py b/Examples/test-suite/python/cpp0x_function_objects_runme.py deleted file mode 100644 index ed8f888b1..000000000 --- a/Examples/test-suite/python/cpp0x_function_objects_runme.py +++ /dev/null @@ -1,12 +0,0 @@ -import cpp0x_function_objects -import sys - -t = cpp0x_function_objects.Test() -if t.value != 0: - raise RuntimeError("Runtime cpp0x_function_objects failed. t.value should be 0, but is " + str(t.value)) - -t(1,2) # adds numbers and sets value - -if t.value != 3: - raise RuntimeError("Runtime cpp0x_function_objects failed. t.value not changed - should be 3, but is " + str(t.value)) - diff --git a/Examples/test-suite/python/cpp0x_initializer_list_extend_runme.py b/Examples/test-suite/python/cpp0x_initializer_list_extend_runme.py deleted file mode 100644 index b07231408..000000000 --- a/Examples/test-suite/python/cpp0x_initializer_list_extend_runme.py +++ /dev/null @@ -1,4 +0,0 @@ -import cpp0x_initializer_list_extend - -c = cpp0x_initializer_list_extend.Container( [10, 20, 30, 40] ) - diff --git a/Examples/test-suite/python/cpp0x_initializer_list_runme.py b/Examples/test-suite/python/cpp0x_initializer_list_runme.py deleted file mode 100644 index 5c8c153a5..000000000 --- a/Examples/test-suite/python/cpp0x_initializer_list_runme.py +++ /dev/null @@ -1,5 +0,0 @@ -import cpp0x_initializer_list - -a = cpp0x_initializer_list.A() -a = cpp0x_initializer_list.A(11.1) - diff --git a/Examples/test-suite/python/cpp0x_null_pointer_constant_runme.py b/Examples/test-suite/python/cpp0x_null_pointer_constant_runme.py deleted file mode 100644 index b80dcaf2f..000000000 --- a/Examples/test-suite/python/cpp0x_null_pointer_constant_runme.py +++ /dev/null @@ -1,15 +0,0 @@ -import cpp0x_null_pointer_constant - -a = cpp0x_null_pointer_constant.A() - -if a._myA != None: - raise RuntimeError, ("cpp0x_null_pointer_constant: _myA should be None, but is ", a._myA) - -b = cpp0x_null_pointer_constant.A() -if a._myA != b._myA: - raise RuntimeError, ("cpp0x_null_pointer_constant: a._myA should be the same as b._myA, but ", a._myA, "!=", b._myA) - -a._myA = cpp0x_null_pointer_constant.A() -if a._myA == None: - raise RuntimeError, ("cpp0x_null_pointer_constant: _myA should be object, but is None") - diff --git a/Examples/test-suite/python/cpp0x_result_of_runme.py b/Examples/test-suite/python/cpp0x_result_of_runme.py deleted file mode 100644 index 5411cd1ce..000000000 --- a/Examples/test-suite/python/cpp0x_result_of_runme.py +++ /dev/null @@ -1,3 +0,0 @@ -import cpp0x_result_of -if cpp0x_result_of.test_result(cpp0x_result_of.square, 3.0) != 9.0: - raise RuntimeError, "test_result(square, 3.0) is not 9.0." diff --git a/Examples/test-suite/python/cpp0x_alternate_function_syntax_runme.py b/Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py similarity index 73% rename from Examples/test-suite/python/cpp0x_alternate_function_syntax_runme.py rename to Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py index 8005cfab7..0a1c45716 100644 --- a/Examples/test-suite/python/cpp0x_alternate_function_syntax_runme.py +++ b/Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py @@ -1,6 +1,6 @@ -import cpp0x_alternate_function_syntax +import cpp11_alternate_function_syntax -a = cpp0x_alternate_function_syntax.SomeStruct() +a = cpp11_alternate_function_syntax.SomeStruct() res = a.addNormal(4,5) if res != 9: diff --git a/Examples/test-suite/python/cpp0x_decltype_runme.py b/Examples/test-suite/python/cpp11_decltype_runme.py similarity index 86% rename from Examples/test-suite/python/cpp0x_decltype_runme.py rename to Examples/test-suite/python/cpp11_decltype_runme.py index ce742e6b2..bfcbbec79 100644 --- a/Examples/test-suite/python/cpp0x_decltype_runme.py +++ b/Examples/test-suite/python/cpp11_decltype_runme.py @@ -1,6 +1,6 @@ -import cpp0x_decltype +import cpp11_decltype -a = cpp0x_decltype.A() +a = cpp11_decltype.A() a.i = 5 if a.i != 5: raise RuntimeError, "Assignment to a.i failed." diff --git a/Examples/test-suite/python/cpp11_function_objects_runme.py b/Examples/test-suite/python/cpp11_function_objects_runme.py new file mode 100644 index 000000000..aac7f9c5f --- /dev/null +++ b/Examples/test-suite/python/cpp11_function_objects_runme.py @@ -0,0 +1,12 @@ +import cpp11_function_objects +import sys + +t = cpp11_function_objects.Test() +if t.value != 0: + raise RuntimeError("Runtime cpp11_function_objects failed. t.value should be 0, but is " + str(t.value)) + +t(1,2) # adds numbers and sets value + +if t.value != 3: + raise RuntimeError("Runtime cpp11_function_objects failed. t.value not changed - should be 3, but is " + str(t.value)) + diff --git a/Examples/test-suite/python/cpp11_initializer_list_extend_runme.py b/Examples/test-suite/python/cpp11_initializer_list_extend_runme.py new file mode 100644 index 000000000..eedf8f148 --- /dev/null +++ b/Examples/test-suite/python/cpp11_initializer_list_extend_runme.py @@ -0,0 +1,4 @@ +import cpp11_initializer_list_extend + +c = cpp11_initializer_list_extend.Container( [10, 20, 30, 40] ) + diff --git a/Examples/test-suite/python/cpp11_initializer_list_runme.py b/Examples/test-suite/python/cpp11_initializer_list_runme.py new file mode 100644 index 000000000..395cd610d --- /dev/null +++ b/Examples/test-suite/python/cpp11_initializer_list_runme.py @@ -0,0 +1,5 @@ +import cpp11_initializer_list + +a = cpp11_initializer_list.A() +a = cpp11_initializer_list.A(11.1) + diff --git a/Examples/test-suite/python/cpp11_null_pointer_constant_runme.py b/Examples/test-suite/python/cpp11_null_pointer_constant_runme.py new file mode 100644 index 000000000..d304c139d --- /dev/null +++ b/Examples/test-suite/python/cpp11_null_pointer_constant_runme.py @@ -0,0 +1,15 @@ +import cpp11_null_pointer_constant + +a = cpp11_null_pointer_constant.A() + +if a._myA != None: + raise RuntimeError, ("cpp11_null_pointer_constant: _myA should be None, but is ", a._myA) + +b = cpp11_null_pointer_constant.A() +if a._myA != b._myA: + raise RuntimeError, ("cpp11_null_pointer_constant: a._myA should be the same as b._myA, but ", a._myA, "!=", b._myA) + +a._myA = cpp11_null_pointer_constant.A() +if a._myA == None: + raise RuntimeError, ("cpp11_null_pointer_constant: _myA should be object, but is None") + diff --git a/Examples/test-suite/python/cpp0x_raw_string_literals_runme.py b/Examples/test-suite/python/cpp11_raw_string_literals_runme.py similarity index 95% rename from Examples/test-suite/python/cpp0x_raw_string_literals_runme.py rename to Examples/test-suite/python/cpp11_raw_string_literals_runme.py index ea7d16550..32282d8d8 100644 --- a/Examples/test-suite/python/cpp0x_raw_string_literals_runme.py +++ b/Examples/test-suite/python/cpp11_raw_string_literals_runme.py @@ -1,4 +1,4 @@ -from cpp0x_raw_string_literals import * +from cpp11_raw_string_literals import * if cvar.L != 100: raise RuntimeError diff --git a/Examples/test-suite/python/cpp11_result_of_runme.py b/Examples/test-suite/python/cpp11_result_of_runme.py new file mode 100644 index 000000000..a97dd7ccc --- /dev/null +++ b/Examples/test-suite/python/cpp11_result_of_runme.py @@ -0,0 +1,3 @@ +import cpp11_result_of +if cpp11_result_of.test_result(cpp11_result_of.square, 3.0) != 9.0: + raise RuntimeError, "test_result(square, 3.0) is not 9.0." diff --git a/Examples/test-suite/python/cpp0x_rvalue_reference_runme.py b/Examples/test-suite/python/cpp11_rvalue_reference_runme.py similarity index 90% rename from Examples/test-suite/python/cpp0x_rvalue_reference_runme.py rename to Examples/test-suite/python/cpp11_rvalue_reference_runme.py index 43fbc997e..a72a3e63b 100644 --- a/Examples/test-suite/python/cpp0x_rvalue_reference_runme.py +++ b/Examples/test-suite/python/cpp11_rvalue_reference_runme.py @@ -1,6 +1,6 @@ -import cpp0x_rvalue_reference +import cpp11_rvalue_reference -a = cpp0x_rvalue_reference.A() +a = cpp11_rvalue_reference.A() a.setAcopy(5) if a.getAcopy() != 5: diff --git a/Examples/test-suite/python/cpp0x_thread_local_runme.py b/Examples/test-suite/python/cpp11_thread_local_runme.py similarity index 94% rename from Examples/test-suite/python/cpp0x_thread_local_runme.py rename to Examples/test-suite/python/cpp11_thread_local_runme.py index ff27b7785..59a657488 100644 --- a/Examples/test-suite/python/cpp0x_thread_local_runme.py +++ b/Examples/test-suite/python/cpp11_thread_local_runme.py @@ -1,4 +1,4 @@ -from cpp0x_thread_local import * +from cpp11_thread_local import * t = ThreadLocals() if t.stval != 11: diff --git a/Examples/test-suite/python/cpp0x_uniform_initialization_runme.py b/Examples/test-suite/python/cpp11_uniform_initialization_runme.py similarity index 68% rename from Examples/test-suite/python/cpp0x_uniform_initialization_runme.py rename to Examples/test-suite/python/cpp11_uniform_initialization_runme.py index 42228f3d7..85c3b2478 100644 --- a/Examples/test-suite/python/cpp0x_uniform_initialization_runme.py +++ b/Examples/test-suite/python/cpp11_uniform_initialization_runme.py @@ -1,13 +1,13 @@ -import cpp0x_uniform_initialization +import cpp11_uniform_initialization -var1 = cpp0x_uniform_initialization.cvar.var1 +var1 = cpp11_uniform_initialization.cvar.var1 if var1.x != 5: raise RuntimeError -var2 = cpp0x_uniform_initialization.cvar.var2 +var2 = cpp11_uniform_initialization.cvar.var2 if var2.getX() != 2: raise RuntimeError -m = cpp0x_uniform_initialization.MoreInit() +m = cpp11_uniform_initialization.MoreInit() if m.charptr != None: raise RuntimeError, m.charptr m.charptr = "hello sir" diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index dc033ed7b..b6366d76d 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1710,7 +1710,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %token NAME RENAME NAMEWARN EXTEND PRAGMA FEATURE VARARGS %token ENUM %token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT AUTO -%token STATIC_ASSERT CONSTEXPR THREAD_LOCAL DECLTYPE /* C++0x keywords */ +%token STATIC_ASSERT CONSTEXPR THREAD_LOCAL DECLTYPE /* C++11 keywords */ %token USING %token NAMESPACE %token NATIVE INLINE @@ -3258,7 +3258,7 @@ c_decl : storage_class type declarator initializer c_decl_tail { set_nextSibling($$,$5); } } - /* Alternate function syntax introduced in C++0x: + /* Alternate function syntax introduced in C++11: auto funcName(int x, int y) -> int; */ | storage_class AUTO declarator ARROW cpp_alternate_rettype initializer c_decl_tail { $$ = new_node("cdecl"); @@ -5330,7 +5330,7 @@ declarator : pointer notso_direct_declarator { } } | LAND notso_direct_declarator { - /* Introduced in C++0x, move operator && */ + /* Introduced in C++11, move operator && */ /* Adds one S/R conflict */ $$ = $2; $$.type = NewStringEmpty(); @@ -5427,7 +5427,7 @@ declarator : pointer notso_direct_declarator { } } | LAND PERIOD PERIOD PERIOD notso_direct_declarator { - /* Introduced in C++0x, move operator && */ + /* Introduced in C++11, move operator && */ /* Adds one S/R conflict */ $$ = $5; $$.type = NewStringEmpty(); @@ -6673,7 +6673,7 @@ mem_initializer : idcolon LPAREN { skip_balanced('(',')'); Clear(scanner_ccode); } - /* Uniform initialization in C++0x. + /* Uniform initialization in C++11. Example: struct MyStruct { MyStruct(int x, double y) : x_{x}, y_{y} {} From de5e0c8655a2409814211415e086868be94031a8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 8 Oct 2013 20:12:18 +0100 Subject: [PATCH 0720/1160] C++11 testing moved to a configure option Use './configure --enable-cpp11-testing' to enable the C++11 test. Off by default for now. --- Examples/test-suite/common.mk | 5 +++-- Makefile.in | 3 ++- configure.ac | 29 ++++++++++++++++++++--------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index be6b4736a..caa583471 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -94,10 +94,8 @@ CPP_TEST_BROKEN += \ C_TEST_BROKEN += \ tag_no_clash_with_variable - # C++ test cases. (Can be run individually using: make testcase.cpptest) CPP_TEST_CASES += \ - $(CPP11_TEST_CASES) \ abstract_access \ abstract_inherit \ abstract_inherit_ok \ @@ -541,6 +539,9 @@ ifndef SKIP_CPP_STD_CASES CPP_TEST_CASES += ${CPP_STD_TEST_CASES} endif +ifneq (,$(HAVE_CXX11_COMPILER)) +CPP_TEST_CASES += $(CPP11_TEST_CASES) +endif # C test cases. (Can be run individually using: make testcase.ctest) C_TEST_CASES += \ diff --git a/Makefile.in b/Makefile.in index c6259916b..377086231 100644 --- a/Makefile.in +++ b/Makefile.in @@ -22,6 +22,7 @@ TARGET = $(TARGET_NOEXE)@EXEEXT@ SOURCE = Source CCACHE = CCache DOCS = Doc/Manual +HAVE_CXX11_COMPILER = @HAVE_CXX11_COMPILER@ swig: libfiles source ccache @@ -240,7 +241,7 @@ check-%-test-suite: echo warning: cannot $(ACTION) $* test-suite "(no dir $$dir)";\ else \ echo $(ACTION)ing $* test-suite; \ - (cd $$dir && $(MAKE) -k -s $(ACTION)) \ + (cd $$dir && $(MAKE) -k -s $(ACTION) HAVE_CXX11_COMPILER=$(HAVE_CXX11_COMPILER)) \ || passed=false; \ fi; \ test $$passed = true diff --git a/configure.ac b/configure.ac index 7015fb468..fa985bfd8 100644 --- a/configure.ac +++ b/configure.ac @@ -330,15 +330,26 @@ esac AC_MSG_RESULT($PLATCFLAGS) # Add switch if necessary to enable C++11 support - just for tests -AC_LANG_PUSH([C++]) -CXXFLAGS_SAVED=$CXXFLAGS -AX_CXX_COMPILE_STDCXX_11([noext], [nostop]) -CXXFLAGS=$CXXFLAGS_SAVED -AC_LANG_POP([C++]) -if test x"$CXX11FLAGS" = x; then - PLATCXXFLAGS="$PLATCFLAGS" -else - PLATCXXFLAGS="$CXX11FLAGS $PLATCFLAGS" +AC_ARG_ENABLE([cpp11-testing], AS_HELP_STRING([--enable-cpp11-testing], [enable C++11 testing if supported by compiler (default disabled)]), [enable_cpp11_testing=$enableval], [enable_cpp11_testing=no]) +AC_MSG_CHECKING([whether to enable C++11 testing]) +AC_MSG_RESULT([$enable_cpp11_testing]) + +PLATCXXFLAGS="$PLATCFLAGS" +if test x"$enable_cpp11_testing" = xyes; then + AC_LANG_PUSH([C++]) + CXXFLAGS_SAVED=$CXXFLAGS + AX_CXX_COMPILE_STDCXX_11([noext], [nostop]) + CXXFLAGS=$CXXFLAGS_SAVED + AC_LANG_POP([C++]) + if test x"$CXX11FLAGS" != x; then + PLATCXXFLAGS="$CXX11FLAGS $PLATCXXFLAGS" + fi + AC_MSG_CHECKING([for C++11 enabled compiler]) + if test x"$HAVE_CXX11_COMPILER" = x; then + AC_MSG_RESULT([no]) + else + AC_MSG_RESULT([$HAVE_CXX11_COMPILER]) + fi fi # Set info about shared libraries. From 053856893c113569f227efa78ec00559152a907f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 10 Oct 2013 07:28:44 +0100 Subject: [PATCH 0721/1160] Add gsoc2009-matevz for Travis testing --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 26758304f..eca1838d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,3 +56,4 @@ script: branches: only: - master + - gsoc2009-matevz From e5f9f9180707c1c30a9bc025ee3d3f171c1b8d6e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 Oct 2013 19:42:19 +0100 Subject: [PATCH 0722/1160] Add naturalvar_more testcase runtime test --- .../java/naturalvar_more_runme.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Examples/test-suite/java/naturalvar_more_runme.java diff --git a/Examples/test-suite/java/naturalvar_more_runme.java b/Examples/test-suite/java/naturalvar_more_runme.java new file mode 100644 index 000000000..60e2fadbe --- /dev/null +++ b/Examples/test-suite/java/naturalvar_more_runme.java @@ -0,0 +1,23 @@ + +import naturalvar_more.*; + +public class naturalvar_more_runme { + static { + try { + System.loadLibrary("naturalvar_more"); + } 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[]) + { + S s = new S(); + if (!s.getConst_string_member().equals("initial string value")) + throw new RuntimeException("Test 1 fail"); + s.setString_member("some member value"); + if (!s.getString_member().equals("some member value")) + throw new RuntimeException("Test 2 fail"); + } +} From 7b08378145ad703cb6a8cc128c01975dfdce8af4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 Oct 2013 21:48:45 +0100 Subject: [PATCH 0723/1160] Minor cleanup prior to merging to master --- .travis.yml | 1 - Examples/Makefile.in | 2 +- Lib/php/director.swg | 3 --- Source/Swig/warn.c | 38 -------------------------------------- 4 files changed, 1 insertion(+), 43 deletions(-) delete mode 100644 Source/Swig/warn.c diff --git a/.travis.yml b/.travis.yml index eca1838d2..26758304f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,4 +56,3 @@ script: branches: only: - master - - gsoc2009-matevz diff --git a/Examples/Makefile.in b/Examples/Makefile.in index b6712378b..b986774b6 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1520,7 +1520,7 @@ endif r_cpp: $(CXXSRCS) $(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH) ifneq ($(CXXSRCS),) - $(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(CXXSRCS) $(INCLUDES) + $(CXX) -g -c $(CXXFLAGS) $(R_CFLAGS) $(CXXSRCS) $(INCLUDES) endif +( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null ) diff --git a/Lib/php/director.swg b/Lib/php/director.swg index a78a2370f..90f6a74a2 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -1,7 +1,4 @@ /* ----------------------------------------------------------------------------- - * 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. - * * director.swg * * This file contains support for director classes that proxy diff --git a/Source/Swig/warn.c b/Source/Swig/warn.c deleted file mode 100644 index dfb2e4af4..000000000 --- a/Source/Swig/warn.c +++ /dev/null @@ -1,38 +0,0 @@ -/* ----------------------------------------------------------------------------- - * 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. - * - * warn.c - * - * SWIG warning framework. This was added to warn developers about - * deprecated APIs and other features. - * ----------------------------------------------------------------------------- */ - -char cvsroot_warn_c[] = "$Id$"; - -#include "swig.h" - -static Hash *warnings = 0; - -/* ----------------------------------------------------------------------------- - * Swig_warn() - * - * Issue a warning - * ----------------------------------------------------------------------------- */ - -void Swig_warn(const char *filename, int line, const char *msg) { - String *key; - if (!warnings) { - warnings = NewHash(); - } - key = NewStringf("%s:%d", filename, line); - if (!Getattr(warnings, key)) { - Printf(stderr, "swig-dev warning:%s:%d:%s\n", filename, line, msg); - Setattr(warnings, key, key); - } - Delete(key); -} From 049d50fe919f21aaf324e8590b7b1ea671aedcb0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 12 Oct 2013 00:16:05 +0100 Subject: [PATCH 0724/1160] Add C++11 to changes file --- CHANGES.current | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index edd39af31..1b58c6592 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-10-12: wsfulton + Merge in C++11 support from the gsoc2009-matevz branch where Matevz Jekovec first + started the C++0x additions. Documentation of the C++11 features supported is in a + new Chapter of the documentation, "SWIG and C++11" in Doc/Manual/CPlusPlus11.html. + 2013-10-04: wsfulton Fix %naturalvar not having any affect on templated classes instantiated with an enum as the template parameter type. Problem reported by Vadim Zeitlin. From aad30cf4dea3a0fdb37985dc06b4ac38dacb3a88 Mon Sep 17 00:00:00 2001 From: Nikhil Shetty Date: Thu, 10 Oct 2013 19:33:57 -0600 Subject: [PATCH 0725/1160] BUGFIX: superclass name not lispy The superclass names were not lispified correctly and so the class was inheriting from erroneous class symbols. Closes #96. --- Source/Modules/cffi.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx index 0b1153d61..6b331ad19 100644 --- a/Source/Modules/cffi.cxx +++ b/Source/Modules/cffi.cxx @@ -676,7 +676,7 @@ void CFFI::emit_class(Node *n) { if (!first) Printf(supers, " "); String *s = Getattr(i.item, "name"); - Printf(supers, "%s", lispify_name(i.item, s, "'classname")); + Printf(supers, "%s", lispify_name(i.item, lispy_name(Char(s)), "'classname")); } } else { // Printf(supers,"ff:foreign-pointer"); From 3b08385dec715010da541f59a6bd68dedb07be82 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 12 Oct 2013 14:31:45 +0100 Subject: [PATCH 0726/1160] changes note for superclass not lispify --- CHANGES.current | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 1b58c6592..3f5c112f3 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-10-13: wsfulton + [CFFI] Apply #96 - superclass not lispify + 2013-10-12: wsfulton Merge in C++11 support from the gsoc2009-matevz branch where Matevz Jekovec first started the C++0x additions. Documentation of the C++11 features supported is in a From 1a7f731d60bef65898d7b5c35d0e676e7e19ca81 Mon Sep 17 00:00:00 2001 From: Atri Date: Tue, 1 Oct 2013 01:28:26 +0530 Subject: [PATCH 0727/1160] Lua: Fix void return for non-void functions Commit #c3f3880d caused the functions SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* ns) and SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns) to return void when int returns were expected resulting in the build failures for plplot's lua bindings for example. This commit fixes the issue. Closes #92 --- Lib/lua/luarun.swg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 4d851bdb1..8485ed499 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -524,7 +524,7 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* /* clear stack - remove metatble */ lua_pop(L,1); - + return 0; } /* helper function. creates namespace table and add it to module table */ @@ -555,6 +555,7 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns) lua_setmetatable(L,-2); /* set metatable */ lua_rawset(L,-3); /* add namespace to module table */ + return 0; } /* ----------------------------------------------------------------------------- * global variable support code: classes From 669a27bb7b9d2da9c1758a5126d1db1f56299f08 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 12 Oct 2013 17:50:29 +0100 Subject: [PATCH 0728/1160] Add change note for missing Lua return statements --- CHANGES.current | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 3f5c112f3..350571e7b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,7 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ -2013-10-13: wsfulton +2013-10-12: wsfulton + [Lua] Apply #92 - missing return statements for SWIG_Lua_add_namespace_details() + and SWIG_Lua_namespace_register(). + +2013-10-12: wsfulton [CFFI] Apply #96 - superclass not lispify 2013-10-12: wsfulton From 72afb74f470841d9af504a8f85617c6a70aa837d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 30 Aug 2013 17:01:01 +0200 Subject: [PATCH 0729/1160] Add support for case conversion characters in regex substitutions. Allow using Perl-like \l, \L, \u, \U and \E escape sequences in the substitution string used with %rename("%(regex:/pattern/subst/)s"). This is useful for e.g. title casing all string after removing some prefix. Closes #82 --- CHANGES.current | 4 ++ Doc/Manual/SWIG.html | 21 +++++-- .../csharp/rename_pcre_encoder_runme.cs | 9 ++- .../java/rename_pcre_encoder_runme.java | 8 ++- .../python/rename_pcre_encoder_runme.py | 11 ++-- Examples/test-suite/rename_pcre_encoder.i | 13 +++- Source/Swig/misc.c | 63 ++++++++++++++++++- 7 files changed, 108 insertions(+), 21 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 350571e7b..db0a9899f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-10-15: vadz + Allow using \l, \L, \u, \U and \E in the substitution part of %(regex:/pattern/subst/) + inside %rename to change the case of the text being replaced. + 2013-10-12: wsfulton [Lua] Apply #92 - missing return statements for SWIG_Lua_add_namespace_details() and SWIG_Lua_namespace_register(). diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index f9ea5b2ef..c0cde0172 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -1888,11 +1888,22 @@ and a more descriptive one, but the two functions are otherwise equivalent: pattern part is a regular expression in Perl syntax (as supported by the Perl Compatible Regular Expressions (PCRE)) library and the subst string - can contain back-references introduced by '\' or, as backslashes need - to be escaped in C strings, rather by "\\". For example, to remove - any alphabetic prefix before an underscore you could use the following directive: - %rename("regex:/(\\w+)_(.*)/\\2/") -
    + can contain back-references of the form \N where N is a digit + from 0 to 9, or one of the following escape sequences: \l, \L, + \u, \U or \E. The back-references are replaced with the + contents of the corresponding capture group while the escape sequences perform the + case conversion in the substitution string: \l and \L convert to + the lower case, while \u and \U convert to the upper case. The + difference between the elements of each pair is that \l and \u + change the case of the next character only, while \L and \U do + it for all the remaining characters or until \E is encountered. + + Finally please notice that backslashes need to be escaped in C strings, so in + practice "\\" must be used in all these escape sequences. For example, + to remove any alphabetic prefix before an underscore and capitalize the remaining + part you could use the following directive: + %rename("regex:/(\\w+)_(.*)/\\u\\2/") + diff --git a/Examples/test-suite/csharp/rename_pcre_encoder_runme.cs b/Examples/test-suite/csharp/rename_pcre_encoder_runme.cs index f6289e7e2..c06fb1387 100644 --- a/Examples/test-suite/csharp/rename_pcre_encoder_runme.cs +++ b/Examples/test-suite/csharp/rename_pcre_encoder_runme.cs @@ -4,9 +4,12 @@ using rename_pcre_encoderNamespace; public class runme { static void Main() { SomeWidget w = new SomeWidget(); - w.putBorderWidth(17); - if ( w.getBorderWidth() != 17 ) + w.put_borderWidth(17); + if ( w.get_borderWidth() != 17 ) throw new Exception(String.Format("Border with should be 17, not {0}", - w.getBorderWidth())); + w.get_borderWidth())); + + if ( rename_pcre_encoder.StartINSAneAndUNSAvoryTraNSAtlanticRaNSAck() != 42 ) + throw new Exception("Unexpected result of renamed function call"); } } diff --git a/Examples/test-suite/java/rename_pcre_encoder_runme.java b/Examples/test-suite/java/rename_pcre_encoder_runme.java index cb843338b..20882e21a 100644 --- a/Examples/test-suite/java/rename_pcre_encoder_runme.java +++ b/Examples/test-suite/java/rename_pcre_encoder_runme.java @@ -6,9 +6,11 @@ public class rename_pcre_encoder_runme { public static void main(String argv[]) { SomeWidget w = new SomeWidget(); - w.putBorderWidth(17); - if ( w.getBorderWidth() != 17 ) + w.put_borderWidth(17); + if ( w.get_borderWidth() != 17 ) throw new RuntimeException(String.format("Border with should be 17, not %d", - w.getBorderWidth())); + w.get_borderWidth())); + if ( rename_pcre_encoder.StartINSAneAndUNSAvoryTraNSAtlanticRaNSAck() != 42 ) + throw new RuntimeException("Unexpected result of renamed function call"); } } diff --git a/Examples/test-suite/python/rename_pcre_encoder_runme.py b/Examples/test-suite/python/rename_pcre_encoder_runme.py index 1186703a0..419acd1a1 100644 --- a/Examples/test-suite/python/rename_pcre_encoder_runme.py +++ b/Examples/test-suite/python/rename_pcre_encoder_runme.py @@ -1,13 +1,16 @@ from rename_pcre_encoder import * s = SomeWidget() -s.putBorderWidth(3) -if s.getBorderWidth() != 3: - raise RuntimeError("Border should be 3, not %d" % (s.getBorderWidth(),)) +s.put_borderWidth(3) +if s.get_borderWidth() != 3: + raise RuntimeError("Border should be 3, not %d" % (s.get_borderWidth(),)) -s.putSize(4, 5) +s.put_size(4, 5) a = AnotherWidget() a.DoSomething() evt = wxEVTSomeEvent() t = xUnchangedName() + +if StartINSAneAndUNSAvoryTraNSAtlanticRaNSAck() != 42: + raise RuntimeError("Unexpected result of renamed function call") diff --git a/Examples/test-suite/rename_pcre_encoder.i b/Examples/test-suite/rename_pcre_encoder.i index 66f30c7bc..b29b2a056 100644 --- a/Examples/test-suite/rename_pcre_encoder.i +++ b/Examples/test-suite/rename_pcre_encoder.i @@ -3,9 +3,14 @@ // strip the wx prefix from all identifiers except those starting with wxEVT %rename("%(regex:/wx(?!EVT)(.*)/\\1/)s") ""; -// Replace "Set" and "Get" prefixes with "put" and "get" respectively. -%rename("%(regex:/^Set(.*)/put\\1/)s", %$isfunction) ""; -%rename("%(regex:/^Get(.*)/get\\1/)s", %$isfunction) ""; +// Change "{Set,Get}Foo" naming convention to "{put,get}_foo" one. +%rename("%(regex:/^Set(.*)/put_\\l\\1/)s", %$isfunction) ""; +%rename("%(regex:/^Get(.*)/get_\\l\\1/)s", %$isfunction) ""; + +// Make some words stand out (unfortunately we don't have "global" flag): we +// use \U to capitalize the second capture group and then \E to preserve the +// case of the rest. +%rename("%(regex:/(.*?)(nsa)(.*?)\\2(.*?)\\2(.*?)\\2(.*)/\\1\\U\\2\\E\\3\\U\\2\\E\\4\\U\\2\\E\\5\\U\\2\\E\\6/)s") ""; %inline %{ @@ -28,4 +33,6 @@ class wxEVTSomeEvent { class xUnchangedName { }; +inline int StartInsaneAndUnsavoryTransatlanticRansack() { return 42; } + %} diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 596f6b424..769882bf8 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -1180,8 +1180,38 @@ err_out: exit(1); } +/* This function copies len characters from src to dst, possibly applying case conversions to them: if convertCase is 1, to upper case and if it is -1, to lower + * case. If convertNextOnly is 1, only a single character is converted (and convertCase is reset), otherwise all of them are. */ +static void copy_with_maybe_case_conversion(String *dst, const char *src, int len, int *convertCase, int convertNextOnly) +{ + /* Deal with the trivial cases first. */ + if (!len) + return; + + if (!*convertCase) { + Write(dst, src, len); + return; + } + + /* If we must convert only the first character, do it and write the rest at once. */ + if (convertNextOnly) { + Putc(*convertCase == 1 ? toupper(*src) : tolower(*src), dst); + *convertCase = 0; + if (len > 1) { + Write(dst, src + 1, len - 1); + } + } else { + /* We need to convert all characters. */ + int i; + for (i = 0; i < len; i++, src++) { + Putc(*convertCase == 1 ? toupper(*src) : tolower(*src), dst); + } + } +} + String *replace_captures(int num_captures, const char *input, String *subst, int captures[], String *pattern, String *s) { + int convertCase = 0, convertNextOnly = 0; String *result = NewStringEmpty(); const char *p = Char(subst); @@ -1189,10 +1219,10 @@ String *replace_captures(int num_captures, const char *input, String *subst, int /* Copy part without substitutions */ const char *q = strchr(p, '\\'); if (!q) { - Write(result, p, strlen(p)); + copy_with_maybe_case_conversion(result, p, strlen(p), &convertCase, convertNextOnly); break; } - Write(result, p, q - p); + copy_with_maybe_case_conversion(result, p, q - p, &convertCase, convertNextOnly); p = q + 1; /* Handle substitution */ @@ -1203,12 +1233,39 @@ String *replace_captures(int num_captures, const char *input, String *subst, int if (group < num_captures) { int l = captures[group*2], r = captures[group*2 + 1]; if (l != -1) { - Write(result, input + l, r - l); + copy_with_maybe_case_conversion(result, input + l, r - l, &convertCase, convertNextOnly); } } else { Swig_error("SWIG", Getline(s), "PCRE capture replacement failed while matching \"%s\" using \"%s\" - request for group %d is greater than the number of captures %d.\n", Char(pattern), input, group, num_captures-1); } + } else { + /* Handle Perl-like case conversion escapes. */ + switch (*p) { + case 'u': + convertCase = 1; + convertNextOnly = 1; + break; + case 'U': + convertCase = 1; + convertNextOnly = 0; + break; + case 'l': + convertCase = -1; + convertNextOnly = 1; + break; + case 'L': + convertCase = -1; + convertNextOnly = 0; + break; + case 'E': + convertCase = 0; + break; + default: + Swig_error("SWIG", Getline(s), "Unrecognized escape character '%c' in the replacement string \"%s\".\n", + *p, Char(subst)); + } + p++; } } From 0f1e73fd26238b1cb1515f8518393e8a4e0bd57d Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Tue, 15 Oct 2013 13:55:35 -0500 Subject: [PATCH 0730/1160] Add test case to demonstrate the name collision that occurs in the generated C# code when a namespace is named System. --- Examples/test-suite/csharp/Makefile.in | 1 + .../csharp_namespace_system_collision.i | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Examples/test-suite/csharp_namespace_system_collision.i diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index 4fd8052c6..91b8144de 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -17,6 +17,7 @@ CPP_TEST_CASES = \ csharp_exceptions \ csharp_features \ csharp_lib_arrays \ + csharp_namespace_system_collision \ csharp_prepost \ csharp_typemaps \ enum_thorough_simple \ diff --git a/Examples/test-suite/csharp_namespace_system_collision.i b/Examples/test-suite/csharp_namespace_system_collision.i new file mode 100644 index 000000000..6f94f8471 --- /dev/null +++ b/Examples/test-suite/csharp_namespace_system_collision.i @@ -0,0 +1,39 @@ +%module namespace_system_collision + +%{ +#include + +namespace TopLevel +{ + namespace System + { + class Foo { + public: + virtual ~Foo() {} + virtual std::string ping() { return "TopLevel::System::Foo::ping()"; } + }; + } +} + +%} + +%include + +// nspace feature only supported by these languages +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) +%nspace; +#else +#warning nspace feature not yet supported in this target language +#endif + +namespace TopLevel +{ + namespace System + { + class Foo { + public: + virtual ~Foo(); + virtual std::string ping(); + }; + } +} From 9c7d0143896cee19ef704dd194ba8226cf2dc0ca Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 17 Oct 2013 18:36:59 +0100 Subject: [PATCH 0731/1160] T_STRING is now const char * instead of char * Fixes Guile constant wrappers removing -Wwrite-strings g++ warning. --- Source/Modules/guile.cxx | 2 +- Source/Swig/stype.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index e0a084583..2c48ba319 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -1350,7 +1350,7 @@ public: Printv(f_header, tm, "\n", NIL); } else { // Create variable and assign it a value - Printf(f_header, "static %s = %s;\n", SwigType_lstr(nctype, var_name), rvalue); + Printf(f_header, "static %s = %s;\n", SwigType_str(type, var_name), rvalue); } { /* Hack alert: will cleanup later -- Dave */ diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index 4b72bdaa2..506878799 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -131,6 +131,7 @@ SwigType *NewSwigType(int t) { break; case T_STRING: { SwigType *t = NewString("char"); + SwigType_add_qualifier(t, "const"); SwigType_add_pointer(t); return t; break; From 3235570619cf3c35a5fba24e32c09fedda5600ea Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 17 Oct 2013 13:27:48 -0500 Subject: [PATCH 0732/1160] Globablly qualify the use of types from the .NET framework's System namespace in the C# module and library. --- Lib/csharp/csharp.swg | 18 +++++++-------- Lib/csharp/csharphead.swg | 28 +++++++++++----------- Lib/csharp/enumtypesafe.swg | 2 +- Lib/csharp/std_map.i | 46 ++++++++++++++++++------------------- Lib/csharp/std_vector.i | 20 ++++++++-------- Lib/csharp/wchar.i | 4 ++-- Source/Modules/csharp.cxx | 2 +- 7 files changed, 60 insertions(+), 60 deletions(-) diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index bd9d8e8b2..731ed83e4 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -848,7 +848,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %typemap(csbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" %typemap(csclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "public class" %typemap(cscode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" -%typemap(csimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "\nusing System;\nusing System.Runtime.InteropServices;\n" +%typemap(csimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "\nusing global::System;\nusing global::System.Runtime.InteropServices;\n" %typemap(csinterfaces) SWIGTYPE "IDisposable" %typemap(csinterfaces) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" %typemap(csinterfaces_derived) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" @@ -982,13 +982,13 @@ SWIG_CSBODY_TYPEWRAPPER(internal, protected, internal, SWIGTYPE) %pragma(csharp) moduleclassmodifiers="public class" %pragma(csharp) moduleimports=%{ -using System; -using System.Runtime.InteropServices; +using global::System; +using global::System.Runtime.InteropServices; %} %pragma(csharp) imclassimports=%{ -using System; -using System.Runtime.InteropServices; +using global::System; +using global::System.Runtime.InteropServices; %} /* Some ANSI C typemaps */ @@ -1018,10 +1018,10 @@ using System.Runtime.InteropServices; public class SWIGStringMarshal : IDisposable { public readonly HandleRef swigCPtr; public SWIGStringMarshal(string str) { - swigCPtr = new HandleRef(this, System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(str)); + swigCPtr = new HandleRef(this, global::System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(str)); } public virtual void Dispose() { - System.Runtime.InteropServices.Marshal.FreeHGlobal(swigCPtr.Handle); + global::System.Runtime.InteropServices.Marshal.FreeHGlobal(swigCPtr.Handle); GC.SuppressFinalize(this); } } @@ -1031,7 +1031,7 @@ using System.Runtime.InteropServices; %typemap(out) char *, char[ANY], char[] %{ $result = $1; %} %typemap(csin) char *, char[ANY], char[] "new $imclassname.SWIGStringMarshal($csinput).swigCPtr" %typemap(csout, excode=SWIGEXCODE) char *, char[ANY], char[] { - string ret = System.Runtime.InteropServices.Marshal.PtrToStringAnsi($imcall);$excode + string ret = global::System.Runtime.InteropServices.Marshal.PtrToStringAnsi($imcall);$excode return ret; } %typemap(csvarin, excode=SWIGEXCODE2) char *, char[ANY], char[] %{ @@ -1040,7 +1040,7 @@ using System.Runtime.InteropServices; } %} %typemap(csvarout, excode=SWIGEXCODE2) char *, char[ANY], char[] %{ get { - string ret = System.Runtime.InteropServices.Marshal.PtrToStringAnsi($imcall);$excode + string ret = global::System.Runtime.InteropServices.Marshal.PtrToStringAnsi($imcall);$excode return ret; } %} */ diff --git a/Lib/csharp/csharphead.swg b/Lib/csharp/csharphead.swg index a1c56a4b3..be1281a71 100644 --- a/Lib/csharp/csharphead.swg +++ b/Lib/csharp/csharphead.swg @@ -170,51 +170,51 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module( ExceptionArgumentDelegate argumentOutOfRangeDelegate); static void SetPendingApplicationException(string message) { - SWIGPendingException.Set(new System.ApplicationException(message, SWIGPendingException.Retrieve())); + SWIGPendingException.Set(new global::System.ApplicationException(message, SWIGPendingException.Retrieve())); } static void SetPendingArithmeticException(string message) { - SWIGPendingException.Set(new System.ArithmeticException(message, SWIGPendingException.Retrieve())); + SWIGPendingException.Set(new global::System.ArithmeticException(message, SWIGPendingException.Retrieve())); } static void SetPendingDivideByZeroException(string message) { - SWIGPendingException.Set(new System.DivideByZeroException(message, SWIGPendingException.Retrieve())); + SWIGPendingException.Set(new global::System.DivideByZeroException(message, SWIGPendingException.Retrieve())); } static void SetPendingIndexOutOfRangeException(string message) { - SWIGPendingException.Set(new System.IndexOutOfRangeException(message, SWIGPendingException.Retrieve())); + SWIGPendingException.Set(new global::System.IndexOutOfRangeException(message, SWIGPendingException.Retrieve())); } static void SetPendingInvalidCastException(string message) { - SWIGPendingException.Set(new System.InvalidCastException(message, SWIGPendingException.Retrieve())); + SWIGPendingException.Set(new global::System.InvalidCastException(message, SWIGPendingException.Retrieve())); } static void SetPendingInvalidOperationException(string message) { - SWIGPendingException.Set(new System.InvalidOperationException(message, SWIGPendingException.Retrieve())); + SWIGPendingException.Set(new global::System.InvalidOperationException(message, SWIGPendingException.Retrieve())); } static void SetPendingIOException(string message) { - SWIGPendingException.Set(new System.IO.IOException(message, SWIGPendingException.Retrieve())); + SWIGPendingException.Set(new global::System.IO.IOException(message, SWIGPendingException.Retrieve())); } static void SetPendingNullReferenceException(string message) { - SWIGPendingException.Set(new System.NullReferenceException(message, SWIGPendingException.Retrieve())); + SWIGPendingException.Set(new global::System.NullReferenceException(message, SWIGPendingException.Retrieve())); } static void SetPendingOutOfMemoryException(string message) { - SWIGPendingException.Set(new System.OutOfMemoryException(message, SWIGPendingException.Retrieve())); + SWIGPendingException.Set(new global::System.OutOfMemoryException(message, SWIGPendingException.Retrieve())); } static void SetPendingOverflowException(string message) { - SWIGPendingException.Set(new System.OverflowException(message, SWIGPendingException.Retrieve())); + SWIGPendingException.Set(new global::System.OverflowException(message, SWIGPendingException.Retrieve())); } static void SetPendingSystemException(string message) { - SWIGPendingException.Set(new System.SystemException(message, SWIGPendingException.Retrieve())); + SWIGPendingException.Set(new global::System.SystemException(message, SWIGPendingException.Retrieve())); } static void SetPendingArgumentException(string message, string paramName) { - SWIGPendingException.Set(new System.ArgumentException(message, paramName, SWIGPendingException.Retrieve())); + SWIGPendingException.Set(new global::System.ArgumentException(message, paramName, SWIGPendingException.Retrieve())); } static void SetPendingArgumentNullException(string message, string paramName) { Exception e = SWIGPendingException.Retrieve(); if (e != null) message = message + " Inner Exception: " + e.Message; - SWIGPendingException.Set(new System.ArgumentNullException(paramName, message)); + SWIGPendingException.Set(new global::System.ArgumentNullException(paramName, message)); } static void SetPendingArgumentOutOfRangeException(string message, string paramName) { Exception e = SWIGPendingException.Retrieve(); if (e != null) message = message + " Inner Exception: " + e.Message; - SWIGPendingException.Set(new System.ArgumentOutOfRangeException(paramName, message)); + SWIGPendingException.Set(new global::System.ArgumentOutOfRangeException(paramName, message)); } static SWIGExceptionHelper() { diff --git a/Lib/csharp/enumtypesafe.swg b/Lib/csharp/enumtypesafe.swg index 772a88013..b7079343c 100644 --- a/Lib/csharp/enumtypesafe.swg +++ b/Lib/csharp/enumtypesafe.swg @@ -97,7 +97,7 @@ for (int i = 0; i < swigValues.Length; i++) if (swigValues[i].swigValue == swigValue) return swigValues[i]; - throw new System.ArgumentOutOfRangeException("No enum $csclassname with value " + swigValue); + throw new global::System.ArgumentOutOfRangeException("No enum $csclassname with value " + swigValue); } public override string ToString() { diff --git a/Lib/csharp/std_map.i b/Lib/csharp/std_map.i index acd190689..61b527a28 100644 --- a/Lib/csharp/std_map.i +++ b/Lib/csharp/std_map.i @@ -28,7 +28,7 @@ /* K is the C++ key type, T is the C++ value type */ %define SWIG_STD_MAP_INTERNAL(K, T, C) -%typemap(csinterfaces) std::map< K, T, C > "IDisposable \n#if !SWIG_DOTNET_1\n , System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n#endif\n"; +%typemap(csinterfaces) std::map< K, T, C > "IDisposable \n#if !SWIG_DOTNET_1\n , global::System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n#endif\n"; %typemap(cscode) std::map %{ public $typemap(cstype, T) this[$typemap(cstype, K) key] { @@ -64,9 +64,9 @@ #if !SWIG_DOTNET_1 - public System.Collections.Generic.ICollection<$typemap(cstype, K)> Keys { + public global::System.Collections.Generic.ICollection<$typemap(cstype, K)> Keys { get { - System.Collections.Generic.ICollection<$typemap(cstype, K)> keys = new System.Collections.Generic.List<$typemap(cstype, K)>(); + global::System.Collections.Generic.ICollection<$typemap(cstype, K)> keys = new global::System.Collections.Generic.List<$typemap(cstype, K)>(); int size = this.Count; if (size > 0) { IntPtr iter = create_iterator_begin(); @@ -79,21 +79,21 @@ } } - public System.Collections.Generic.ICollection<$typemap(cstype, T)> Values { + public global::System.Collections.Generic.ICollection<$typemap(cstype, T)> Values { get { - System.Collections.Generic.ICollection<$typemap(cstype, T)> vals = new System.Collections.Generic.List<$typemap(cstype, T)>(); - foreach (System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> pair in this) { + global::System.Collections.Generic.ICollection<$typemap(cstype, T)> vals = new global::System.Collections.Generic.List<$typemap(cstype, T)>(); + foreach (global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> pair in this) { vals.Add(pair.Value); } return vals; } } - public void Add(System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> item) { + public void Add(global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> item) { Add(item.Key, item.Value); } - public bool Remove(System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> item) { + public bool Remove(global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> item) { if (Contains(item)) { return Remove(item.Key); } else { @@ -101,7 +101,7 @@ } } - public bool Contains(System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> item) { + public bool Contains(global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> item) { if (this[item.Key] == item.Value) { return true; } else { @@ -109,11 +109,11 @@ } } - public void CopyTo(System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>[] array) { + public void CopyTo(global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>[] array) { CopyTo(array, 0); } - public void CopyTo(System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>[] array, int arrayIndex) { + public void CopyTo(global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>[] array, int arrayIndex) { if (array == null) throw new ArgumentNullException("array"); if (arrayIndex < 0) @@ -123,18 +123,18 @@ if (arrayIndex+this.Count > array.Length) throw new ArgumentException("Number of elements to copy is too large."); - System.Collections.Generic.IList<$typemap(cstype, K)> keyList = new System.Collections.Generic.List<$typemap(cstype, K)>(this.Keys); + global::System.Collections.Generic.IList<$typemap(cstype, K)> keyList = new global::System.Collections.Generic.List<$typemap(cstype, K)>(this.Keys); for (int i = 0; i < keyList.Count; i++) { $typemap(cstype, K) currentKey = keyList[i]; - array.SetValue(new System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>(currentKey, this[currentKey]), arrayIndex+i); + array.SetValue(new global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>(currentKey, this[currentKey]), arrayIndex+i); } } - System.Collections.Generic.IEnumerator> System.Collections.Generic.IEnumerable>.GetEnumerator() { + global::System.Collections.Generic.IEnumerator> global::System.Collections.Generic.IEnumerable>.GetEnumerator() { return new $csclassnameEnumerator(this); } - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return new $csclassnameEnumerator(this); } @@ -147,25 +147,25 @@ /// whenever the collection is modified. This has been done for changes in the size of the /// collection but not when one of the elements of the collection is modified as it is a bit /// tricky to detect unmanaged code that modifies the collection under our feet. - public sealed class $csclassnameEnumerator : System.Collections.IEnumerator, - System.Collections.Generic.IEnumerator> + public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator, + global::System.Collections.Generic.IEnumerator> { private $csclassname collectionRef; - private System.Collections.Generic.IList<$typemap(cstype, K)> keyCollection; + private global::System.Collections.Generic.IList<$typemap(cstype, K)> keyCollection; private int currentIndex; private object currentObject; private int currentSize; public $csclassnameEnumerator($csclassname collection) { collectionRef = collection; - keyCollection = new System.Collections.Generic.List<$typemap(cstype, K)>(collection.Keys); + keyCollection = new global::System.Collections.Generic.List<$typemap(cstype, K)>(collection.Keys); currentIndex = -1; currentObject = null; currentSize = collectionRef.Count; } // Type-safe iterator Current - public System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> Current { + public global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> Current { get { if (currentIndex == -1) throw new InvalidOperationException("Enumeration not started."); @@ -173,12 +173,12 @@ throw new InvalidOperationException("Enumeration finished."); if (currentObject == null) throw new InvalidOperationException("Collection modified."); - return (System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>)currentObject; + return (global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>)currentObject; } } // Type-unsafe IEnumerator.Current - object System.Collections.IEnumerator.Current { + object global::System.Collections.IEnumerator.Current { get { return Current; } @@ -190,7 +190,7 @@ if (moveOkay) { currentIndex++; $typemap(cstype, K) currentKey = keyCollection[currentIndex]; - currentObject = new System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>(currentKey, collectionRef[currentKey]); + currentObject = new global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>(currentKey, collectionRef[currentKey]); } else { currentObject = null; } diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index 5a21ad399..50ba38739 100644 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -26,9 +26,9 @@ // MACRO for use within the std::vector class body %define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CSINTERFACE, CONST_REFERENCE, CTYPE...) -%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(csinterfaces) std::vector< CTYPE > "IDisposable, global::System.Collections.IEnumerable\n#if !SWIG_DOTNET_1\n , global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n#endif\n"; %typemap(cscode) std::vector< CTYPE > %{ - public $csclassname(System.Collections.ICollection c) : this() { + public $csclassname(global::System.Collections.ICollection c) : this() { if (c == null) throw new ArgumentNullException("c"); foreach ($typemap(cstype, CTYPE) element in c) { @@ -81,7 +81,7 @@ } #if SWIG_DOTNET_1 - public void CopyTo(System.Array array) + public void CopyTo(global::System.Array array) #else public void CopyTo($typemap(cstype, CTYPE)[] array) #endif @@ -90,7 +90,7 @@ } #if SWIG_DOTNET_1 - public void CopyTo(System.Array array, int arrayIndex) + public void CopyTo(global::System.Array array, int arrayIndex) #else public void CopyTo($typemap(cstype, CTYPE)[] array, int arrayIndex) #endif @@ -99,7 +99,7 @@ } #if SWIG_DOTNET_1 - public void CopyTo(int index, System.Array array, int arrayIndex, int count) + public void CopyTo(int index, global::System.Array array, int arrayIndex, int count) #else public void CopyTo(int index, $typemap(cstype, CTYPE)[] array, int arrayIndex, int count) #endif @@ -121,12 +121,12 @@ } #if !SWIG_DOTNET_1 - System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)> System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)>.GetEnumerator() { + global::System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)> global::System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)>.GetEnumerator() { return new $csclassnameEnumerator(this); } #endif - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return new $csclassnameEnumerator(this); } @@ -139,9 +139,9 @@ /// whenever the collection is modified. This has been done for changes in the size of the /// collection but not when one of the elements of the collection is modified as it is a bit /// tricky to detect unmanaged code that modifies the collection under our feet. - public sealed class $csclassnameEnumerator : System.Collections.IEnumerator + public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator #if !SWIG_DOTNET_1 - , System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)> + , global::System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)> #endif { private $csclassname collectionRef; @@ -170,7 +170,7 @@ } // Type-unsafe IEnumerator.Current - object System.Collections.IEnumerator.Current { + object global::System.Collections.IEnumerator.Current { get { return Current; } diff --git a/Lib/csharp/wchar.i b/Lib/csharp/wchar.i index 1d95edded..066044014 100644 --- a/Lib/csharp/wchar.i +++ b/Lib/csharp/wchar.i @@ -27,7 +27,7 @@ static SWIG_CSharpWStringHelperCallback SWIG_csharp_wstring_callback = NULL; public static extern void SWIGRegisterWStringCallback_$module(SWIGWStringDelegate wstringDelegate); static string CreateWString([MarshalAs(UnmanagedType.LPWStr)]IntPtr cString) { - return System.Runtime.InteropServices.Marshal.PtrToStringUni(cString); + return global::System.Runtime.InteropServices.Marshal.PtrToStringUni(cString); } static SWIGWStringHelper() { @@ -82,7 +82,7 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStri %typemap(csin) wchar_t * "$csinput" %typemap(csout, excode=SWIGEXCODE) wchar_t * { - string ret = System.Runtime.InteropServices.Marshal.PtrToStringUni($imcall);$excode + string ret = global::System.Runtime.InteropServices.Marshal.PtrToStringUni($imcall);$excode return ret; } %typemap(csvarin, excode=SWIGEXCODE2) wchar_t * %{ diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index d30f278fc..6c314959f 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -1734,7 +1734,7 @@ public: Printf(proxy_class_code, "\n"); Printf(proxy_class_code, " private bool SwigDerivedClassHasMethod(string methodName, Type[] methodTypes) {\n"); Printf(proxy_class_code, - " System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(methodName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, methodTypes, null);\n"); + " global::System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(methodName, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, methodTypes, null);\n"); Printf(proxy_class_code, " bool hasDerivedMethod = methodInfo.DeclaringType.IsSubclassOf(typeof(%s));\n", proxy_class_name); /* Could add this code to cover corner case where the GetMethod() returns a method which allows type * promotion, eg it will return foo(double), if looking for foo(int). From 0e54a51c104ecf1c1a68892132d9506890a99036 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 17 Oct 2013 19:56:18 +0100 Subject: [PATCH 0733/1160] Add missing #include for offsetof when using -builtin. Fixes SF #1345 --- CHANGES.current | 3 +++ Lib/python/pyinit.swg | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index db0a9899f..9621a4952 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-10-17: wsfulton + [Python] Fix SF #1345 - Missing #include for offsetof when using -builtin. + 2013-10-15: vadz Allow using \l, \L, \u, \U and \E in the substitution part of %(regex:/pattern/subst/) inside %rename to change the case of the text being replaced. diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 6a6de0963..79df023de 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -4,6 +4,10 @@ %insert(init) "swiginit.swg" +#if defined(SWIGPYTHON_BUILTIN) +%fragment(""); // For offsetof +#endif + %init %{ #ifdef __cplusplus From cb2df12630874dd9b11fac8805e3169691305ee0 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 17 Oct 2013 13:58:32 -0500 Subject: [PATCH 0734/1160] Since SWIG 3.0 removes support for .NET 1.1, cleanup the C# library by removing the use of the SWIG_DOTNET_1 macro. --- .../test-suite/csharp/li_std_vector_runme.cs | 13 ----------- Lib/csharp/std_map.i | 9 ++------ Lib/csharp/std_vector.i | 22 +------------------ 3 files changed, 3 insertions(+), 41 deletions(-) diff --git a/Examples/test-suite/csharp/li_std_vector_runme.cs b/Examples/test-suite/csharp/li_std_vector_runme.cs index 617116d5a..fa8700d89 100644 --- a/Examples/test-suite/csharp/li_std_vector_runme.cs +++ b/Examples/test-suite/csharp/li_std_vector_runme.cs @@ -82,17 +82,6 @@ public class li_std_vector_runme { } catch (ArgumentException) { } } -#if SWIG_DOTNET_1 - { - // runtime check that 2D arrays fail - double[,] outputarray = new double[collectionSize,collectionSize]; - try { - vect.CopyTo(outputarray); - throw new Exception("CopyTo (5a) test failed"); - } catch (ArgumentException) { - } - } -#endif { StructVector inputvector = new StructVector(); int arrayLen = 10; @@ -208,7 +197,6 @@ public class li_std_vector_runme { throw new Exception("Repeat (1) test failed"); } } -#if !SWIG_DOTNET_1 { System.Collections.Generic.IEnumerator myEnumerator = dv.GetEnumerator(); while ( myEnumerator.MoveNext() ) { @@ -216,7 +204,6 @@ public class li_std_vector_runme { throw new Exception("Repeat (2) test failed"); } } -#endif } { diff --git a/Lib/csharp/std_map.i b/Lib/csharp/std_map.i index 61b527a28..045bd6e3e 100644 --- a/Lib/csharp/std_map.i +++ b/Lib/csharp/std_map.i @@ -11,9 +11,7 @@ * %template(MapIntDouble) std::map * * Notes: - * 1) For .NET 1 compatibility, define SWIG_DOTNET_1 when compiling the C# code. In this case - * the C# wrapper has only basic functionality. - * 2) IEnumerable<> is implemented in the proxy class which is useful for using LINQ with + * 1) IEnumerable<> is implemented in the proxy class which is useful for using LINQ with * C++ std::map wrappers. * * Warning: heavy macro usage in this file. Use swig -E to get a sane view on the real file contents! @@ -28,7 +26,7 @@ /* K is the C++ key type, T is the C++ value type */ %define SWIG_STD_MAP_INTERNAL(K, T, C) -%typemap(csinterfaces) std::map< K, T, C > "IDisposable \n#if !SWIG_DOTNET_1\n , global::System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n#endif\n"; +%typemap(csinterfaces) std::map< K, T, C > "IDisposable \n , global::System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n"; %typemap(cscode) std::map %{ public $typemap(cstype, T) this[$typemap(cstype, K) key] { @@ -62,8 +60,6 @@ } } -#if !SWIG_DOTNET_1 - public global::System.Collections.Generic.ICollection<$typemap(cstype, K)> Keys { get { global::System.Collections.Generic.ICollection<$typemap(cstype, K)> keys = new global::System.Collections.Generic.List<$typemap(cstype, K)>(); @@ -210,7 +206,6 @@ currentObject = null; } } -#endif %} diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index 50ba38739..e29c2bf2a 100644 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -4,8 +4,6 @@ * SWIG typemaps for std::vector * C# implementation * The C# wrapper is made to look and feel like a C# System.Collections.Generic.List<> collection. - * For .NET 1 compatibility, define SWIG_DOTNET_1 when compiling the C# code; then the C# wrapper is - * made to look and feel like a typesafe C# System.Collections.ArrayList. * * Note that IEnumerable<> is implemented in the proxy class which is useful for using LINQ with * C++ std::vector wrappers. The IList<> interface is also implemented to provide enhanced functionality @@ -26,7 +24,7 @@ // MACRO for use within the std::vector class body %define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CSINTERFACE, CONST_REFERENCE, CTYPE...) -%typemap(csinterfaces) std::vector< CTYPE > "IDisposable, global::System.Collections.IEnumerable\n#if !SWIG_DOTNET_1\n , global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n#endif\n"; +%typemap(csinterfaces) std::vector< CTYPE > "IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n"; %typemap(cscode) std::vector< CTYPE > %{ public $csclassname(global::System.Collections.ICollection c) : this() { if (c == null) @@ -80,29 +78,17 @@ } } -#if SWIG_DOTNET_1 - public void CopyTo(global::System.Array array) -#else public void CopyTo($typemap(cstype, CTYPE)[] array) -#endif { CopyTo(0, array, 0, this.Count); } -#if SWIG_DOTNET_1 - public void CopyTo(global::System.Array array, int arrayIndex) -#else public void CopyTo($typemap(cstype, CTYPE)[] array, int arrayIndex) -#endif { CopyTo(0, array, arrayIndex, this.Count); } -#if SWIG_DOTNET_1 - public void CopyTo(int index, global::System.Array array, int arrayIndex, int count) -#else public void CopyTo(int index, $typemap(cstype, CTYPE)[] array, int arrayIndex, int count) -#endif { if (array == null) throw new ArgumentNullException("array"); @@ -120,11 +106,9 @@ array.SetValue(getitemcopy(index+i), arrayIndex+i); } -#if !SWIG_DOTNET_1 global::System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)> global::System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)>.GetEnumerator() { return new $csclassnameEnumerator(this); } -#endif global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return new $csclassnameEnumerator(this); @@ -140,9 +124,7 @@ /// collection but not when one of the elements of the collection is modified as it is a bit /// tricky to detect unmanaged code that modifies the collection under our feet. public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator -#if !SWIG_DOTNET_1 , global::System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)> -#endif { private $csclassname collectionRef; private int currentIndex; @@ -196,12 +178,10 @@ } } -#if !SWIG_DOTNET_1 public void Dispose() { currentIndex = -1; currentObject = null; } -#endif } %} From adb93980f2decad8a2ab8bb2a462e66c4be51b4d Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Thu, 17 Oct 2013 15:44:24 -0500 Subject: [PATCH 0735/1160] Remove using directives from the generated C# code and fully qualify the use of all .NET framework types in order to minimize potential name collisions from input files defining types, namespace, etc with the same name as .NET framework members. --- Examples/test-suite/csharp_prepost.i | 6 +- Examples/test-suite/csharp_typemaps.i | 2 +- Examples/test-suite/special_variable_macros.i | 2 +- Lib/csharp/arrays_csharp.i | 10 +- Lib/csharp/boost_intrusive_ptr.i | 116 +++++++++--------- Lib/csharp/boost_shared_ptr.i | 72 +++++------ Lib/csharp/csharp.swg | 101 +++++++-------- Lib/csharp/csharphead.swg | 22 ++-- Lib/csharp/std_map.i | 20 +-- Lib/csharp/std_vector.i | 26 ++-- Lib/csharp/std_wstring.i | 4 +- Lib/csharp/typemaps.i | 6 +- Lib/csharp/wchar.i | 8 +- Source/Modules/csharp.cxx | 16 +-- 14 files changed, 200 insertions(+), 211 deletions(-) diff --git a/Examples/test-suite/csharp_prepost.i b/Examples/test-suite/csharp_prepost.i index 32ee10677..f48e5f419 100644 --- a/Examples/test-suite/csharp_prepost.i +++ b/Examples/test-suite/csharp_prepost.i @@ -116,7 +116,7 @@ struct PrePost3 { // Check attributes in the typemaps %typemap(cstype, inattributes="[CustomInt]") int val "int" %typemap(csin, pre=" int tmp_$csinput = $csinput * 100;") int val "tmp_$csinput" -%typemap(imtype, out="IntPtr/*overridden*/", outattributes="[CustomIntPtr]") CsinAttributes * "HandleRef/*overridden*/" +%typemap(imtype, out="global::System.IntPtr/*overridden*/", outattributes="[CustomIntPtr]") CsinAttributes * "global::System.Runtime.InteropServices.HandleRef/*overridden*/" %inline %{ class CsinAttributes { @@ -216,8 +216,8 @@ void subtractYears(CDate *pDate, int years) { %typemap(csvarout, excode=SWIGEXCODE2) CDate * %{ /* csvarout typemap code */ get { - IntPtr cPtr = $imcall; - CDate tempDate = (cPtr == IntPtr.Zero) ? null : new CDate(cPtr, $owner);$excode + global::System.IntPtr cPtr = $imcall; + CDate tempDate = (cPtr == global::System.IntPtr.Zero) ? null : new CDate(cPtr, $owner);$excode return new System.DateTime(tempDate.getYear(), tempDate.getMonth(), tempDate.getDay(), 0, 0, 0); } %} diff --git a/Examples/test-suite/csharp_typemaps.i b/Examples/test-suite/csharp_typemaps.i index 83097f663..32e735ca7 100644 --- a/Examples/test-suite/csharp_typemaps.i +++ b/Examples/test-suite/csharp_typemaps.i @@ -94,7 +94,7 @@ Number times12(const Number* num) { %typemap(csvarin, excode=SWIGEXCODE2) int %{ set { if ($csinput < 0) - throw new ApplicationException("number too small!"); + throw new global::System.ApplicationException("number too small!"); $imcall;$excode } %} diff --git a/Examples/test-suite/special_variable_macros.i b/Examples/test-suite/special_variable_macros.i index ddd068cc0..ca2edaa98 100644 --- a/Examples/test-suite/special_variable_macros.i +++ b/Examples/test-suite/special_variable_macros.i @@ -188,7 +188,7 @@ namespace Space { #if defined(SWIGCSHARP) %typemap(cscode) Space::RenameMe %{ - public static NewName factory(String s) { + public static NewName factory(System.String s) { //below should expand to: //return new NewName( new Name(s) ); return new $typemap(cstype, Space::RenameMe)( new $typemap(cstype, Name)(s) ); diff --git a/Lib/csharp/arrays_csharp.i b/Lib/csharp/arrays_csharp.i index 513330e4e..174a2823e 100644 --- a/Lib/csharp/arrays_csharp.i +++ b/Lib/csharp/arrays_csharp.i @@ -57,7 +57,7 @@ %typemap(ctype) CTYPE INPUT[] "CTYPE*" %typemap(cstype) CTYPE INPUT[] "CSTYPE[]" -%typemap(imtype, inattributes="[In, MarshalAs(UnmanagedType.LPArray)]") CTYPE INPUT[] "CSTYPE[]" +%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]") CTYPE INPUT[] "CSTYPE[]" %typemap(csin) CTYPE INPUT[] "$csinput" %typemap(in) CTYPE INPUT[] "$1 = $input;" @@ -68,7 +68,7 @@ %typemap(ctype) CTYPE OUTPUT[] "CTYPE*" %typemap(cstype) CTYPE OUTPUT[] "CSTYPE[]" -%typemap(imtype, inattributes="[Out, MarshalAs(UnmanagedType.LPArray)]") CTYPE OUTPUT[] "CSTYPE[]" +%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]") CTYPE OUTPUT[] "CSTYPE[]" %typemap(csin) CTYPE OUTPUT[] "$csinput" %typemap(in) CTYPE OUTPUT[] "$1 = $input;" @@ -79,7 +79,7 @@ %typemap(ctype) CTYPE INOUT[] "CTYPE*" %typemap(cstype) CTYPE INOUT[] "CSTYPE[]" -%typemap(imtype, inattributes="[In, Out, MarshalAs(UnmanagedType.LPArray)]") CTYPE INOUT[] "CSTYPE[]" +%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]") CTYPE INOUT[] "CSTYPE[]" %typemap(csin) CTYPE INOUT[] "$csinput" %typemap(in) CTYPE INOUT[] "$1 = $input;" @@ -108,12 +108,12 @@ CSHARP_ARRAYS(double, double) %define CSHARP_ARRAYS_FIXED( CTYPE, CSTYPE ) %typemap(ctype) CTYPE FIXED[] "CTYPE*" -%typemap(imtype) CTYPE FIXED[] "IntPtr" +%typemap(imtype) CTYPE FIXED[] "global::System.IntPtr" %typemap(cstype) CTYPE FIXED[] "CSTYPE[]" %typemap(csin, pre= " fixed ( CSTYPE* swig_ptrTo_$csinput = $csinput ) {", terminator=" }") - CTYPE FIXED[] "(IntPtr)swig_ptrTo_$csinput" + CTYPE FIXED[] "(global::System.IntPtr)swig_ptrTo_$csinput" %typemap(in) CTYPE FIXED[] "$1 = $input;" %typemap(freearg) CTYPE FIXED[] "" diff --git a/Lib/csharp/boost_intrusive_ptr.i b/Lib/csharp/boost_intrusive_ptr.i index 09a164729..1cc5efda7 100644 --- a/Lib/csharp/boost_intrusive_ptr.i +++ b/Lib/csharp/boost_intrusive_ptr.i @@ -207,11 +207,11 @@ SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &, SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *, SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "void *" -%typemap (imtype, out="IntPtr") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >, +%typemap (imtype, out="global::System.IntPtr") 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 > *& "HandleRef" + SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "global::System.Runtime.InteropServices.HandleRef" %typemap (cstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &, @@ -224,28 +224,28 @@ SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "$typemap(cstype, TYPE).getCPtr($csinput)" %typemap(csout, excode=SWIGEXCODE) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > { - IntPtr cPtr = $imcall; - $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == global::System.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; - $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == global::System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode return ret; } %typemap(csout, excode=SWIGEXCODE) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & { - IntPtr cPtr = $imcall; - $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == global::System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode return ret; } %typemap(csout, excode=SWIGEXCODE) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * { - IntPtr cPtr = $imcall; - $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == global::System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode return ret; } %typemap(csout, excode=SWIGEXCODE) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& { - IntPtr cPtr = $imcall; - $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == global::System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode return ret; } %typemap(csvarout, excode=SWIGEXCODE2) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > %{ @@ -274,76 +274,76 @@ return ret; } %typemap(csout, excode=SWIGEXCODE) CONST TYPE * { - IntPtr cPtr = $imcall; - $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == global::System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode return ret; } %typemap(csout, excode=SWIGEXCODE) TYPE *CONST& { - IntPtr cPtr = $imcall; - $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == global::System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode return ret; } // Base proxy classes %typemap(csbody) TYPE %{ - private HandleRef swigCPtr; + private global::System.Runtime.InteropServices.HandleRef swigCPtr; private bool swigCMemOwnBase; - PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) { + PTRCTOR_VISIBILITY $csclassname(global::System.IntPtr cPtr, bool cMemoryOwn) { swigCMemOwnBase = cMemoryOwn; - swigCPtr = new HandleRef(this, cPtr); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); } - CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) { - return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; + CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } %} // Derived proxy classes %typemap(csbody_derived) TYPE %{ - private HandleRef swigCPtr; + private global::System.Runtime.InteropServices.HandleRef swigCPtr; private bool swigCMemOwnDerived; - PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGSmartPtrUpcast(cPtr), true) { + PTRCTOR_VISIBILITY $csclassname(global::System.IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGSmartPtrUpcast(cPtr), true) { swigCMemOwnDerived = cMemoryOwn; - swigCPtr = new HandleRef(this, cPtr); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); } - CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) { - return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; + CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } %} %typemap(csdestruct, methodname="Dispose", methodmodifiers="public") TYPE { lock(this) { - if (swigCPtr.Handle != IntPtr.Zero) { + if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwnBase) { swigCMemOwnBase = false; $imcall; } - swigCPtr = new HandleRef(null, IntPtr.Zero); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - GC.SuppressFinalize(this); + global::System.GC.SuppressFinalize(this); } } %typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE { lock(this) { - if (swigCPtr.Handle != IntPtr.Zero) { + if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwnDerived) { swigCMemOwnDerived = false; $imcall; } - swigCPtr = new HandleRef(null, IntPtr.Zero); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - GC.SuppressFinalize(this); + global::System.GC.SuppressFinalize(this); base.Dispose(); } } // CONST version needed ???? also for C# -%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "HandleRef" -%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "HandleRef" +%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "global::System.Runtime.InteropServices.HandleRef" +%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "global::System.Runtime.InteropServices.HandleRef" %template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; @@ -424,8 +424,8 @@ %typemap (cstype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "$typemap(cstype, TYPE)" %typemap (csin) 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; - return (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true); + global::System.IntPtr cPtr = $imcall; + return (cPtr == global::System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true); } %typemap(csout, excode=SWIGEXCODE) CONST TYPE { @@ -435,75 +435,75 @@ return new $typemap(cstype, TYPE)($imcall, true); } %typemap(csout, excode=SWIGEXCODE) CONST TYPE * { - IntPtr cPtr = $imcall; - return (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true); + global::System.IntPtr cPtr = $imcall; + return (cPtr == global::System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true); } %typemap(csout, excode=SWIGEXCODE) TYPE *CONST& { - IntPtr cPtr = $imcall; - return (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true); + global::System.IntPtr cPtr = $imcall; + return (cPtr == global::System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true); } // Base proxy classes %typemap(csbody) TYPE %{ - private HandleRef swigCPtr; + private global::System.Runtime.InteropServices.HandleRef swigCPtr; private bool swigCMemOwnBase; - PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) { + PTRCTOR_VISIBILITY $csclassname(global::System.IntPtr cPtr, bool cMemoryOwn) { swigCMemOwnBase = cMemoryOwn; - swigCPtr = new HandleRef(this, cPtr); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); } - CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) { - return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; + CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } %} // Derived proxy classes %typemap(csbody_derived) TYPE %{ - private HandleRef swigCPtr; + private global::System.Runtime.InteropServices.HandleRef swigCPtr; private bool swigCMemOwnDerived; - PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGSmartPtrUpcast(cPtr), true) { + PTRCTOR_VISIBILITY $csclassname(global::System.IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGSmartPtrUpcast(cPtr), true) { swigCMemOwnDerived = cMemoryOwn; - swigCPtr = new HandleRef(this, cPtr); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); } - CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) { - return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; + CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } %} %typemap(csdestruct, methodname="Dispose", methodmodifiers="public") TYPE { lock(this) { - if (swigCPtr.Handle != IntPtr.Zero) { + if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwnBase) { swigCMemOwnBase = false; $imcall; } - swigCPtr = new HandleRef(null, IntPtr.Zero); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - GC.SuppressFinalize(this); + global::System.GC.SuppressFinalize(this); } } %typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE { lock(this) { - if (swigCPtr.Handle != IntPtr.Zero) { + if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwnDerived) { swigCMemOwnDerived = false; $imcall; } - swigCPtr = new HandleRef(null, IntPtr.Zero); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - GC.SuppressFinalize(this); + global::System.GC.SuppressFinalize(this); base.Dispose(); } } // CONST version needed ???? also for C# -%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "HandleRef" -%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "HandleRef" +%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "global::System.Runtime.InteropServices.HandleRef" +%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "global::System.Runtime.InteropServices.HandleRef" %template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; diff --git a/Lib/csharp/boost_shared_ptr.i b/Lib/csharp/boost_shared_ptr.i index 5e6f66469..2b65bf20d 100644 --- a/Lib/csharp/boost_shared_ptr.i +++ b/Lib/csharp/boost_shared_ptr.i @@ -95,10 +95,10 @@ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "void *" -%typemap (imtype, out="IntPtr") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, +%typemap (imtype, out="global::System.IntPtr") 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 > *& "HandleRef" + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "global::System.Runtime.InteropServices.HandleRef" %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 > *, @@ -110,23 +110,23 @@ 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; - $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == global::System.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; - $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == global::System.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; - $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == global::System.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; - $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == global::System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode return ret; } @@ -140,13 +140,13 @@ return ret; } %typemap(csout, excode=SWIGEXCODE) CONST TYPE * { - IntPtr cPtr = $imcall; - $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == global::System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode return ret; } %typemap(csout, excode=SWIGEXCODE) TYPE *CONST& { - IntPtr cPtr = $imcall; - $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == global::System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode return ret; } @@ -157,78 +157,78 @@ } %} %typemap(csvarout, excode=SWIGEXCODE2) CONST TYPE * %{ get { - IntPtr cPtr = $imcall; - $csclassname ret = (cPtr == IntPtr.Zero) ? null : new $csclassname(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $csclassname ret = (cPtr == global::System.IntPtr.Zero) ? null : new $csclassname(cPtr, true);$excode return ret; } %} %typemap(csvarout, excode=SWIGEXCODE2) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{ get { - IntPtr cPtr = $imcall; - $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == global::System.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; - $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + global::System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == global::System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode return ret; } %} // Proxy classes (base classes, ie, not derived classes) %typemap(csbody) TYPE %{ - private HandleRef swigCPtr; + private global::System.Runtime.InteropServices.HandleRef swigCPtr; private bool swigCMemOwnBase; - PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) { + PTRCTOR_VISIBILITY $csclassname(global::System.IntPtr cPtr, bool cMemoryOwn) { swigCMemOwnBase = cMemoryOwn; - swigCPtr = new HandleRef(this, cPtr); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); } - CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) { - return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; + CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } %} // Derived proxy classes %typemap(csbody_derived) TYPE %{ - private HandleRef swigCPtr; + private global::System.Runtime.InteropServices.HandleRef swigCPtr; private bool swigCMemOwnDerived; - PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGSmartPtrUpcast(cPtr), true) { + PTRCTOR_VISIBILITY $csclassname(global::System.IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGSmartPtrUpcast(cPtr), true) { swigCMemOwnDerived = cMemoryOwn; - swigCPtr = new HandleRef(this, cPtr); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); } - CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) { - return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; + CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } %} %typemap(csdestruct, methodname="Dispose", methodmodifiers="public") TYPE { lock(this) { - if (swigCPtr.Handle != IntPtr.Zero) { + if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwnBase) { swigCMemOwnBase = false; $imcall; } - swigCPtr = new HandleRef(null, IntPtr.Zero); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - GC.SuppressFinalize(this); + global::System.GC.SuppressFinalize(this); } } %typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE { lock(this) { - if (swigCPtr.Handle != IntPtr.Zero) { + if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwnDerived) { swigCMemOwnDerived = false; $imcall; } - swigCPtr = new HandleRef(null, IntPtr.Zero); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - GC.SuppressFinalize(this); + global::System.GC.SuppressFinalize(this); base.Dispose(); } } diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index 731ed83e4..7bd660f4d 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -110,23 +110,23 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { /* Non primitive types */ %typemap(ctype) SWIGTYPE "void *" -%typemap(imtype, out="IntPtr") SWIGTYPE "HandleRef" +%typemap(imtype, out="global::System.IntPtr") SWIGTYPE "global::System.Runtime.InteropServices.HandleRef" %typemap(cstype) SWIGTYPE "$&csclassname" %typemap(ctype) SWIGTYPE [] "void *" -%typemap(imtype, out="IntPtr") SWIGTYPE [] "HandleRef" +%typemap(imtype, out="global::System.IntPtr") SWIGTYPE [] "global::System.Runtime.InteropServices.HandleRef" %typemap(cstype) SWIGTYPE [] "$csclassname" %typemap(ctype) SWIGTYPE * "void *" -%typemap(imtype, out="IntPtr") SWIGTYPE * "HandleRef" +%typemap(imtype, out="global::System.IntPtr") SWIGTYPE * "global::System.Runtime.InteropServices.HandleRef" %typemap(cstype) SWIGTYPE * "$csclassname" %typemap(ctype) SWIGTYPE & "void *" -%typemap(imtype, out="IntPtr") SWIGTYPE & "HandleRef" +%typemap(imtype, out="global::System.IntPtr") SWIGTYPE & "global::System.Runtime.InteropServices.HandleRef" %typemap(cstype) SWIGTYPE & "$csclassname" %typemap(ctype) SWIGTYPE && "void *" -%typemap(imtype, out="IntPtr") SWIGTYPE && "HandleRef" +%typemap(imtype, out="global::System.IntPtr") SWIGTYPE && "global::System.Runtime.InteropServices.HandleRef" %typemap(cstype) SWIGTYPE && "$csclassname" /* pointer to a class member */ @@ -447,7 +447,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %typemap(directorin) SWIGTYPE && %{ $input = ($1_ltype) &$1; %} -%typemap(csdirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*) "($iminput == IntPtr.Zero) ? null : new $csclassname($iminput, false)" +%typemap(csdirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*) "($iminput == global::System.IntPtr.Zero) ? null : new $csclassname($iminput, false)" %typemap(csdirectorin) SWIGTYPE & "new $csclassname($iminput, false)" %typemap(csdirectorin) SWIGTYPE && "new $csclassname($iminput, false)" %typemap(csdirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE &, SWIGTYPE && "$csclassname.getCPtr($cscall).Handle" @@ -683,8 +683,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { return ret; } %typemap(csout, excode=SWIGEXCODE) SWIGTYPE *, SWIGTYPE [] { - IntPtr cPtr = $imcall; - $csclassname ret = (cPtr == IntPtr.Zero) ? null : new $csclassname(cPtr, $owner);$excode + global::System.IntPtr cPtr = $imcall; + $csclassname ret = (cPtr == global::System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner);$excode return ret; } %typemap(csout, excode=SWIGEXCODE) SWIGTYPE (CLASS::*) { @@ -803,8 +803,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { } %} %typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE *, SWIGTYPE [] %{ get { - IntPtr cPtr = $imcall; - $csclassname ret = (cPtr == IntPtr.Zero) ? null : new $csclassname(cPtr, $owner);$excode + global::System.IntPtr cPtr = $imcall; + $csclassname ret = (cPtr == global::System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner);$excode return ret; } %} @@ -817,12 +817,12 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { /* Pointer reference typemaps */ %typemap(ctype) SWIGTYPE *const& "void *" -%typemap(imtype, out="IntPtr") SWIGTYPE *const& "HandleRef" +%typemap(imtype, out="global::System.IntPtr") SWIGTYPE *const& "global::System.Runtime.InteropServices.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 + global::System.IntPtr cPtr = $imcall; + $*csclassname ret = (cPtr == global::System.IntPtr.Zero) ? null : new $*csclassname(cPtr, $owner);$excode return ret; } %typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0) @@ -831,15 +831,15 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %typemap(out) SWIGTYPE *const& %{ $result = (void *)*$1; %} -/* Marshal C/C++ pointer to IntPtr */ +/* Marshal C/C++ pointer to global::System.IntPtr */ %typemap(ctype) void *VOID_INT_PTR "void *" -%typemap(imtype) void *VOID_INT_PTR "IntPtr" -%typemap(cstype) void *VOID_INT_PTR "IntPtr" +%typemap(imtype) void *VOID_INT_PTR "global::System.IntPtr" +%typemap(cstype) void *VOID_INT_PTR "global::System.IntPtr" %typemap(in) void *VOID_INT_PTR %{ $1 = ($1_ltype)$input; %} %typemap(out) void *VOID_INT_PTR %{ $result = (void *)$1; %} %typemap(csin) void *VOID_INT_PTR "$csinput" %typemap(csout, excode=SWIGEXCODE) void *VOID_INT_PTR { - IntPtr ret = $imcall;$excode + global::System.IntPtr ret = $imcall;$excode return ret; } @@ -848,8 +848,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %typemap(csbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" %typemap(csclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "public class" %typemap(cscode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" -%typemap(csimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "\nusing global::System;\nusing global::System.Runtime.InteropServices;\n" -%typemap(csinterfaces) SWIGTYPE "IDisposable" +%typemap(csinterfaces) SWIGTYPE "global::System.IDisposable" %typemap(csinterfaces) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" %typemap(csinterfaces_derived) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" @@ -859,29 +858,29 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %define SWIG_CSBODY_PROXY(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...) // Proxy classes (base classes, ie, not derived classes) %typemap(csbody) TYPE %{ - private HandleRef swigCPtr; + private global::System.Runtime.InteropServices.HandleRef swigCPtr; protected bool swigCMemOwn; - PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) { + PTRCTOR_VISIBILITY $csclassname(global::System.IntPtr cPtr, bool cMemoryOwn) { swigCMemOwn = cMemoryOwn; - swigCPtr = new HandleRef(this, cPtr); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); } - CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) { - return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; + CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } %} // Derived proxy classes %typemap(csbody_derived) TYPE %{ - private HandleRef swigCPtr; + private global::System.Runtime.InteropServices.HandleRef swigCPtr; - PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGUpcast(cPtr), cMemoryOwn) { - swigCPtr = new HandleRef(this, cPtr); + PTRCTOR_VISIBILITY $csclassname(global::System.IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGUpcast(cPtr), cMemoryOwn) { + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); } - CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) { - return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; + CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } %} %enddef @@ -889,18 +888,18 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %define SWIG_CSBODY_TYPEWRAPPER(PTRCTOR_VISIBILITY, DEFAULTCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...) // Typewrapper classes %typemap(csbody) TYPE *, TYPE &, TYPE &&, TYPE [] %{ - private HandleRef swigCPtr; + private global::System.Runtime.InteropServices.HandleRef swigCPtr; - PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool futureUse) { - swigCPtr = new HandleRef(this, cPtr); + PTRCTOR_VISIBILITY $csclassname(global::System.IntPtr cPtr, bool futureUse) { + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); } DEFAULTCTOR_VISIBILITY $csclassname() { - swigCPtr = new HandleRef(null, IntPtr.Zero); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) { - return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; + CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } %} @@ -938,27 +937,27 @@ SWIG_CSBODY_TYPEWRAPPER(internal, protected, internal, SWIGTYPE) %typemap(csdestruct, methodname="Dispose", methodmodifiers="public") SWIGTYPE { lock(this) { - if (swigCPtr.Handle != IntPtr.Zero) { + if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwn) { swigCMemOwn = false; $imcall; } - swigCPtr = new HandleRef(null, IntPtr.Zero); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - GC.SuppressFinalize(this); + global::System.GC.SuppressFinalize(this); } } %typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") SWIGTYPE { lock(this) { - if (swigCPtr.Handle != IntPtr.Zero) { + if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwn) { swigCMemOwn = false; $imcall; } - swigCPtr = new HandleRef(null, IntPtr.Zero); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } - GC.SuppressFinalize(this); + global::System.GC.SuppressFinalize(this); base.Dispose(); } } @@ -981,16 +980,6 @@ SWIG_CSBODY_TYPEWRAPPER(internal, protected, internal, SWIGTYPE) %pragma(csharp) imclassclassmodifiers="class" %pragma(csharp) moduleclassmodifiers="public class" -%pragma(csharp) moduleimports=%{ -using global::System; -using global::System.Runtime.InteropServices; -%} - -%pragma(csharp) imclassimports=%{ -using global::System; -using global::System.Runtime.InteropServices; -%} - /* Some ANSI C typemaps */ %apply unsigned long { size_t }; @@ -1015,19 +1004,19 @@ using global::System.Runtime.InteropServices; /* // Alternative char * typemaps. %pragma(csharp) imclasscode=%{ - public class SWIGStringMarshal : IDisposable { - public readonly HandleRef swigCPtr; + public class SWIGStringMarshal : global::System.IDisposable { + public readonly global::System.Runtime.InteropServices.HandleRef swigCPtr; public SWIGStringMarshal(string str) { - swigCPtr = new HandleRef(this, global::System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(str)); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, global::System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(str)); } public virtual void Dispose() { global::System.Runtime.InteropServices.Marshal.FreeHGlobal(swigCPtr.Handle); - GC.SuppressFinalize(this); + global::System.GC.SuppressFinalize(this); } } %} -%typemap(imtype, out="IntPtr") char *, char[ANY], char[] "HandleRef" +%typemap(imtype, out="global::System.IntPtr") char *, char[ANY], char[] "global::System.Runtime.InteropServices.HandleRef" %typemap(out) char *, char[ANY], char[] %{ $result = $1; %} %typemap(csin) char *, char[ANY], char[] "new $imclassname.SWIGStringMarshal($csinput).swigCPtr" %typemap(csout, excode=SWIGEXCODE) char *, char[ANY], char[] { diff --git a/Lib/csharp/csharphead.swg b/Lib/csharp/csharphead.swg index be1281a71..0b55635b3 100644 --- a/Lib/csharp/csharphead.swg +++ b/Lib/csharp/csharphead.swg @@ -149,7 +149,7 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module( static ExceptionArgumentDelegate argumentNullDelegate = new ExceptionArgumentDelegate(SetPendingArgumentNullException); static ExceptionArgumentDelegate argumentOutOfRangeDelegate = new ExceptionArgumentDelegate(SetPendingArgumentOutOfRangeException); - [DllImport("$dllimport", EntryPoint="SWIGRegisterExceptionCallbacks_$module")] + [global::System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="SWIGRegisterExceptionCallbacks_$module")] public static extern void SWIGRegisterExceptionCallbacks_$module( ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, @@ -163,7 +163,7 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module( ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate); - [DllImport("$dllimport", EntryPoint="SWIGRegisterExceptionArgumentCallbacks_$module")] + [global::System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="SWIGRegisterExceptionArgumentCallbacks_$module")] public static extern void SWIGRegisterExceptionCallbacksArgument_$module( ExceptionArgumentDelegate argumentDelegate, ExceptionArgumentDelegate argumentNullDelegate, @@ -207,12 +207,12 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module( SWIGPendingException.Set(new global::System.ArgumentException(message, paramName, SWIGPendingException.Retrieve())); } static void SetPendingArgumentNullException(string message, string paramName) { - Exception e = SWIGPendingException.Retrieve(); + global::System.Exception e = SWIGPendingException.Retrieve(); if (e != null) message = message + " Inner Exception: " + e.Message; SWIGPendingException.Set(new global::System.ArgumentNullException(paramName, message)); } static void SetPendingArgumentOutOfRangeException(string message, string paramName) { - Exception e = SWIGPendingException.Retrieve(); + global::System.Exception e = SWIGPendingException.Retrieve(); if (e != null) message = message + " Inner Exception: " + e.Message; SWIGPendingException.Set(new global::System.ArgumentOutOfRangeException(paramName, message)); } @@ -241,8 +241,8 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module( protected static SWIGExceptionHelper swigExceptionHelper = new SWIGExceptionHelper(); public class SWIGPendingException { - [ThreadStatic] - private static Exception pendingException = null; + [global::System.ThreadStatic] + private static global::System.Exception pendingException = null; private static int numExceptionsPending = 0; public static bool Pending { @@ -255,17 +255,17 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module( } } - public static void Set(Exception e) { + public static void Set(global::System.Exception e) { if (pendingException != null) - throw new ApplicationException("FATAL: An earlier pending exception from unmanaged code was missed and thus not thrown (" + pendingException.ToString() + ")", e); + throw new global::System.ApplicationException("FATAL: An earlier pending exception from unmanaged code was missed and thus not thrown (" + pendingException.ToString() + ")", e); pendingException = e; lock(typeof($imclassname)) { numExceptionsPending++; } } - public static Exception Retrieve() { - Exception e = null; + public static global::System.Exception Retrieve() { + global::System.Exception e = null; if (numExceptionsPending > 0) { if (pendingException != null) { e = pendingException; @@ -294,7 +294,7 @@ static SWIG_CSharpStringHelperCallback SWIG_csharp_string_callback = NULL; public delegate string SWIGStringDelegate(string message); static SWIGStringDelegate stringDelegate = new SWIGStringDelegate(CreateString); - [DllImport("$dllimport", EntryPoint="SWIGRegisterStringCallback_$module")] + [global::System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="SWIGRegisterStringCallback_$module")] public static extern void SWIGRegisterStringCallback_$module(SWIGStringDelegate stringDelegate); static string CreateString(string cString) { diff --git a/Lib/csharp/std_map.i b/Lib/csharp/std_map.i index 045bd6e3e..db6fa7bd1 100644 --- a/Lib/csharp/std_map.i +++ b/Lib/csharp/std_map.i @@ -26,7 +26,7 @@ /* K is the C++ key type, T is the C++ value type */ %define SWIG_STD_MAP_INTERNAL(K, T, C) -%typemap(csinterfaces) std::map< K, T, C > "IDisposable \n , global::System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n"; +%typemap(csinterfaces) std::map< K, T, C > "global::System.IDisposable \n , global::System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n"; %typemap(cscode) std::map %{ public $typemap(cstype, T) this[$typemap(cstype, K) key] { @@ -65,7 +65,7 @@ global::System.Collections.Generic.ICollection<$typemap(cstype, K)> keys = new global::System.Collections.Generic.List<$typemap(cstype, K)>(); int size = this.Count; if (size > 0) { - IntPtr iter = create_iterator_begin(); + global::System.IntPtr iter = create_iterator_begin(); for (int i = 0; i < size; i++) { keys.Add(get_next_key(iter)); } @@ -111,13 +111,13 @@ public void CopyTo(global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>[] array, int arrayIndex) { if (array == null) - throw new ArgumentNullException("array"); + throw new global::System.ArgumentNullException("array"); if (arrayIndex < 0) - throw new ArgumentOutOfRangeException("arrayIndex", "Value is less than zero"); + throw new global::System.ArgumentOutOfRangeException("arrayIndex", "Value is less than zero"); if (array.Rank > 1) - throw new ArgumentException("Multi dimensional array.", "array"); + throw new global::System.ArgumentException("Multi dimensional array.", "array"); if (arrayIndex+this.Count > array.Length) - throw new ArgumentException("Number of elements to copy is too large."); + throw new global::System.ArgumentException("Number of elements to copy is too large."); global::System.Collections.Generic.IList<$typemap(cstype, K)> keyList = new global::System.Collections.Generic.List<$typemap(cstype, K)>(this.Keys); for (int i = 0; i < keyList.Count; i++) { @@ -164,11 +164,11 @@ public global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> Current { get { if (currentIndex == -1) - throw new InvalidOperationException("Enumeration not started."); + throw new global::System.InvalidOperationException("Enumeration not started."); if (currentIndex > currentSize - 1) - throw new InvalidOperationException("Enumeration finished."); + throw new global::System.InvalidOperationException("Enumeration finished."); if (currentObject == null) - throw new InvalidOperationException("Collection modified."); + throw new global::System.InvalidOperationException("Collection modified."); return (global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>)currentObject; } } @@ -197,7 +197,7 @@ currentIndex = -1; currentObject = null; if (collectionRef.Count != currentSize) { - throw new InvalidOperationException("Collection modified."); + throw new global::System.InvalidOperationException("Collection modified."); } } diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index e29c2bf2a..9d52a962b 100644 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -24,11 +24,11 @@ // MACRO for use within the std::vector class body %define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CSINTERFACE, CONST_REFERENCE, CTYPE...) -%typemap(csinterfaces) std::vector< CTYPE > "IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n"; +%typemap(csinterfaces) std::vector< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n"; %typemap(cscode) std::vector< CTYPE > %{ public $csclassname(global::System.Collections.ICollection c) : this() { if (c == null) - throw new ArgumentNullException("c"); + throw new global::System.ArgumentNullException("c"); foreach ($typemap(cstype, CTYPE) element in c) { this.Add(element); } @@ -61,7 +61,7 @@ } set { if (value < size()) - throw new ArgumentOutOfRangeException("Capacity"); + throw new global::System.ArgumentOutOfRangeException("Capacity"); reserve((uint)value); } } @@ -91,17 +91,17 @@ public void CopyTo(int index, $typemap(cstype, CTYPE)[] array, int arrayIndex, int count) { if (array == null) - throw new ArgumentNullException("array"); + throw new global::System.ArgumentNullException("array"); if (index < 0) - throw new ArgumentOutOfRangeException("index", "Value is less than zero"); + throw new global::System.ArgumentOutOfRangeException("index", "Value is less than zero"); if (arrayIndex < 0) - throw new ArgumentOutOfRangeException("arrayIndex", "Value is less than zero"); + throw new global::System.ArgumentOutOfRangeException("arrayIndex", "Value is less than zero"); if (count < 0) - throw new ArgumentOutOfRangeException("count", "Value is less than zero"); + throw new global::System.ArgumentOutOfRangeException("count", "Value is less than zero"); if (array.Rank > 1) - throw new ArgumentException("Multi dimensional array.", "array"); + throw new global::System.ArgumentException("Multi dimensional array.", "array"); if (index+count > this.Count || arrayIndex+count > array.Length) - throw new ArgumentException("Number of elements to copy is too large."); + throw new global::System.ArgumentException("Number of elements to copy is too large."); for (int i=0; i currentSize - 1) - throw new InvalidOperationException("Enumeration finished."); + throw new global::System.InvalidOperationException("Enumeration finished."); if (currentObject == null) - throw new InvalidOperationException("Collection modified."); + throw new global::System.InvalidOperationException("Collection modified."); return ($typemap(cstype, CTYPE))currentObject; } } @@ -174,7 +174,7 @@ currentIndex = -1; currentObject = null; if (collectionRef.Count != currentSize) { - throw new InvalidOperationException("Collection modified."); + throw new global::System.InvalidOperationException("Collection modified."); } } diff --git a/Lib/csharp/std_wstring.i b/Lib/csharp/std_wstring.i index 9142d36a5..09bdaaaa2 100644 --- a/Lib/csharp/std_wstring.i +++ b/Lib/csharp/std_wstring.i @@ -23,7 +23,7 @@ class wstring; // wstring %typemap(ctype, out="void *") wstring "wchar_t *" -%typemap(imtype, inattributes="[MarshalAs(UnmanagedType.LPWStr)]") wstring "string" +%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]") wstring "string" %typemap(cstype) wstring "string" %typemap(csdirectorin) wstring "$iminput" %typemap(csdirectorout) wstring "$cscall" @@ -60,7 +60,7 @@ class wstring; // const wstring & %typemap(ctype, out="void *") const wstring & "wchar_t *" -%typemap(imtype, inattributes="[MarshalAs(UnmanagedType.LPWStr)]") const wstring & "string" +%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]") const wstring & "string" %typemap(cstype) const wstring & "string" %typemap(csdirectorin) const wstring & "$iminput" diff --git a/Lib/csharp/typemaps.i b/Lib/csharp/typemaps.i index 79f559680..b6f9bddbd 100644 --- a/Lib/csharp/typemaps.i +++ b/Lib/csharp/typemaps.i @@ -55,7 +55,7 @@ In C# you could then use it like this: %define INPUT_TYPEMAP(TYPE, CTYPE, CSTYPE) %typemap(ctype, out="void *") TYPE *INPUT, TYPE &INPUT "CTYPE" -%typemap(imtype, out="IntPtr") TYPE *INPUT, TYPE &INPUT "CSTYPE" +%typemap(imtype, out="global::System.IntPtr") TYPE *INPUT, TYPE &INPUT "CSTYPE" %typemap(cstype, out="$csclassname") TYPE *INPUT, TYPE &INPUT "CSTYPE" %typemap(csin) TYPE *INPUT, TYPE &INPUT "$csinput" @@ -135,7 +135,7 @@ value returned in the second output parameter. In C# you would use it like this: %define OUTPUT_TYPEMAP(TYPE, CTYPE, CSTYPE, TYPECHECKPRECEDENCE) %typemap(ctype, out="void *") TYPE *OUTPUT, TYPE &OUTPUT "CTYPE *" -%typemap(imtype, out="IntPtr") TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE" +%typemap(imtype, out="global::System.IntPtr") TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE" %typemap(cstype, out="$csclassname") TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE" %typemap(csin) TYPE *OUTPUT, TYPE &OUTPUT "out $csinput" @@ -224,7 +224,7 @@ of the function return value. %define INOUT_TYPEMAP(TYPE, CTYPE, CSTYPE, TYPECHECKPRECEDENCE) %typemap(ctype, out="void *") TYPE *INOUT, TYPE &INOUT "CTYPE *" -%typemap(imtype, out="IntPtr") TYPE *INOUT, TYPE &INOUT "ref CSTYPE" +%typemap(imtype, out="global::System.IntPtr") TYPE *INOUT, TYPE &INOUT "ref CSTYPE" %typemap(cstype, out="$csclassname") TYPE *INOUT, TYPE &INOUT "ref CSTYPE" %typemap(csin) TYPE *INOUT, TYPE &INOUT "ref $csinput" diff --git a/Lib/csharp/wchar.i b/Lib/csharp/wchar.i index 066044014..9361edf6f 100644 --- a/Lib/csharp/wchar.i +++ b/Lib/csharp/wchar.i @@ -20,13 +20,13 @@ static SWIG_CSharpWStringHelperCallback SWIG_csharp_wstring_callback = NULL; %pragma(csharp) imclasscode=%{ protected class SWIGWStringHelper { - public delegate string SWIGWStringDelegate(IntPtr message); + public delegate string SWIGWStringDelegate(global::System.IntPtr message); static SWIGWStringDelegate wstringDelegate = new SWIGWStringDelegate(CreateWString); - [DllImport("$dllimport", EntryPoint="SWIGRegisterWStringCallback_$module")] + [global::System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="SWIGRegisterWStringCallback_$module")] public static extern void SWIGRegisterWStringCallback_$module(SWIGWStringDelegate wstringDelegate); - static string CreateWString([MarshalAs(UnmanagedType.LPWStr)]IntPtr cString) { + static string CreateWString([global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]global::System.IntPtr cString) { return global::System.Runtime.InteropServices.Marshal.PtrToStringUni(cString); } @@ -77,7 +77,7 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStri // wchar_t * %typemap(ctype) wchar_t * "wchar_t *" -%typemap(imtype, inattributes="[MarshalAs(UnmanagedType.LPWStr)]", out="IntPtr" ) wchar_t * "string" +%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]", out="global::System.IntPtr" ) wchar_t * "string" %typemap(cstype) wchar_t * "string" %typemap(csin) wchar_t * "$csinput" diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 6c314959f..6b9219750 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -776,7 +776,7 @@ public: } } - Printv(imclass_class_code, "\n [DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL); + Printv(imclass_class_code, "\n [global::System.Runtime.InteropServices.DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL); if (im_outattributes) Printf(imclass_class_code, " %s\n", im_outattributes); @@ -1699,7 +1699,7 @@ public: if (*Char(destructor_call)) Replaceall(destruct, "$imcall", destructor_call); else - Replaceall(destruct, "$imcall", "throw new MethodAccessException(\"C++ destructor does not have public access\")"); + Replaceall(destruct, "$imcall", "throw new global::System.MethodAccessException(\"C++ destructor does not have public access\")"); if (*Char(destruct)) Printv(proxy_class_def, "\n ", destruct_methodmodifiers, " ", derived ? "override" : "virtual", " void ", destruct_methodname, "() ", destruct, "\n", NIL); @@ -1732,7 +1732,7 @@ public: if (first_class_dmethod < curr_class_dmethod) { // Only emit if there is at least one director method Printf(proxy_class_code, "\n"); - Printf(proxy_class_code, " private bool SwigDerivedClassHasMethod(string methodName, Type[] methodTypes) {\n"); + Printf(proxy_class_code, " private bool SwigDerivedClassHasMethod(string methodName, global::System.Type[] methodTypes) {\n"); Printf(proxy_class_code, " global::System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(methodName, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, methodTypes, null);\n"); Printf(proxy_class_code, " bool hasDerivedMethod = methodInfo.DeclaringType.IsSubclassOf(typeof(%s));\n", proxy_class_name); @@ -1798,8 +1798,8 @@ public: 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); - Printf(imclass_cppcasts_code, " public static extern IntPtr %s(IntPtr jarg1);\n", upcast_method); + Printv(imclass_cppcasts_code, "\n [global::System.Runtime.InteropServices.DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL); + Printf(imclass_cppcasts_code, " public static extern global::System.IntPtr %s(global::System.IntPtr jarg1);\n", upcast_method); Replaceall(imclass_cppcasts_code, "$csclassname", proxy_class_name); @@ -3387,8 +3387,8 @@ public: if (nspace) Insert(qualified_classname, 0, NewStringf("%s.", nspace)); - 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); + Printv(imclass_class_code, "\n [global::System.Runtime.InteropServices.DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL); + Printf(imclass_class_code, " public static extern void %s(global::System.Runtime.InteropServices.HandleRef jarg1", swig_director_connect); Wrapper *code_wrap = NewWrapper(); Printf(code_wrap->def, "SWIGEXPORT void SWIGSTDCALL %s(void *objarg", wname); @@ -3917,7 +3917,7 @@ public: Printf(director_delegate_definitions, " SwigDelegate%s_%s(%s);\n", classname, methid, delegate_parms); Printf(director_delegate_instances, " private SwigDelegate%s_%s swigDelegate%s;\n", classname, methid, methid); - Printf(director_method_types, " private static Type[] swigMethodTypes%s = new Type[] { %s };\n", methid, proxy_method_types); + Printf(director_method_types, " private static global::System.Type[] swigMethodTypes%s = new global::System.Type[] { %s };\n", methid, proxy_method_types); Printf(director_connect_parms, "SwigDirector%s%s delegate%s", classname, methid, methid); } From 8da4d6712d3d0170d4f85813796f2e4c42c643b5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 17 Oct 2013 21:54:58 +0100 Subject: [PATCH 0736/1160] Fix Visual Studio compile error in C++ wrappers due to #include within extern "C" block. Fixes SF #1340 --- CHANGES.current | 4 ++++ Lib/r/rrun.swg | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 9621a4952..8989ee194 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-10-17: wsfulton + [R] Fix SF #1340 - Visual Studio compile error in C++ wrappers due to #include + within extern "C" block. + 2013-10-17: wsfulton [Python] Fix SF #1345 - Missing #include for offsetof when using -builtin. diff --git a/Lib/r/rrun.swg b/Lib/r/rrun.swg index f8bc9f497..990443e23 100644 --- a/Lib/r/rrun.swg +++ b/Lib/r/rrun.swg @@ -1,5 +1,6 @@ #ifdef __cplusplus +#include extern "C" { #endif @@ -369,7 +370,6 @@ SWIG_R_ConvertPacked(SEXP obj, void *ptr, size_t sz, swig_type_info *ty) { } #ifdef __cplusplus -#include #define SWIG_exception_noreturn(code, msg) do { throw std::runtime_error(msg); } while(0) #else #define SWIG_exception_noreturn(code, msg) do { return result; } while(0) From 48eed4f9e4734b6611e0867ef9c71f76accca352 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 18 Oct 2013 06:49:20 +0100 Subject: [PATCH 0737/1160] Fix unused variable warning in Ruby wrappers when using gcc -Wall --- Lib/ruby/rubyprimtypes.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/ruby/rubyprimtypes.swg b/Lib/ruby/rubyprimtypes.swg index df72e97f4..aa4f7ad37 100644 --- a/Lib/ruby/rubyprimtypes.swg +++ b/Lib/ruby/rubyprimtypes.swg @@ -193,7 +193,7 @@ SWIG_AsVal_dec(unsigned long long)(VALUE obj, unsigned long long *val) } %fragment(SWIG_AsVal_frag(double),"header",fragment="SWIG_ruby_failed") { -%ruby_aux_method(double, NUM2DBL, NUM2DBL(obj)) +%ruby_aux_method(double, NUM2DBL, NUM2DBL(obj); (void)type) SWIGINTERN int SWIG_AsVal_dec(double)(VALUE obj, double *val) From 152905e19372bd2e5bc6dcb5111f575e87a9850c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 18 Oct 2013 06:53:02 +0100 Subject: [PATCH 0738/1160] Fix gcc -Waddress warning in variables examples --- Examples/csharp/variables/example.c | 2 +- Examples/d/variables/example.c | 2 +- Examples/go/variables/example.c | 2 +- Examples/java/variables/example.c | 2 +- Examples/lua/variables/example.c | 2 +- Examples/octave/variables/example.c | 2 +- Examples/perl5/variables/example.c | 2 +- Examples/php/variables/example.c | 2 +- Examples/python/variables/example.c | 2 +- Examples/ruby/variables/example.c | 2 +- Examples/tcl/variables/example.c | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Examples/csharp/variables/example.c b/Examples/csharp/variables/example.c index aa4ffe9b3..05e17c8c5 100644 --- a/Examples/csharp/variables/example.c +++ b/Examples/csharp/variables/example.c @@ -51,7 +51,7 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); + printf("cstrvar = %s\n", cstrvar); printf("iptrvar = %p\n", iptrvar); printf("name = %s\n", name); printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); diff --git a/Examples/d/variables/example.c b/Examples/d/variables/example.c index 1bf9c120f..3b4e9f346 100644 --- a/Examples/d/variables/example.c +++ b/Examples/d/variables/example.c @@ -51,7 +51,7 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); + printf("cstrvar = %s\n", cstrvar); printf("iptrvar = %p\n", iptrvar); printf("name = %s\n", name); printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); diff --git a/Examples/go/variables/example.c b/Examples/go/variables/example.c index aa4ffe9b3..05e17c8c5 100644 --- a/Examples/go/variables/example.c +++ b/Examples/go/variables/example.c @@ -51,7 +51,7 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); + printf("cstrvar = %s\n", cstrvar); printf("iptrvar = %p\n", iptrvar); printf("name = %s\n", name); printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); diff --git a/Examples/java/variables/example.c b/Examples/java/variables/example.c index aa4ffe9b3..05e17c8c5 100644 --- a/Examples/java/variables/example.c +++ b/Examples/java/variables/example.c @@ -51,7 +51,7 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); + printf("cstrvar = %s\n", cstrvar); printf("iptrvar = %p\n", iptrvar); printf("name = %s\n", name); printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); diff --git a/Examples/lua/variables/example.c b/Examples/lua/variables/example.c index aa4ffe9b3..05e17c8c5 100644 --- a/Examples/lua/variables/example.c +++ b/Examples/lua/variables/example.c @@ -51,7 +51,7 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); + printf("cstrvar = %s\n", cstrvar); printf("iptrvar = %p\n", iptrvar); printf("name = %s\n", name); printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); diff --git a/Examples/octave/variables/example.c b/Examples/octave/variables/example.c index 15dcc1b8e..e2b72e0ea 100644 --- a/Examples/octave/variables/example.c +++ b/Examples/octave/variables/example.c @@ -51,7 +51,7 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); + printf("cstrvar = %s\n", cstrvar); printf("iptrvar = %p\n", iptrvar); printf("name = %s\n", name); printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); diff --git a/Examples/perl5/variables/example.c b/Examples/perl5/variables/example.c index aa4ffe9b3..05e17c8c5 100644 --- a/Examples/perl5/variables/example.c +++ b/Examples/perl5/variables/example.c @@ -51,7 +51,7 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); + printf("cstrvar = %s\n", cstrvar); printf("iptrvar = %p\n", iptrvar); printf("name = %s\n", name); printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); diff --git a/Examples/php/variables/example.c b/Examples/php/variables/example.c index 3114c7c5f..b21dee32d 100644 --- a/Examples/php/variables/example.c +++ b/Examples/php/variables/example.c @@ -51,7 +51,7 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); + printf("cstrvar = %s\n", cstrvar); printf("iptrvar = %p\n", iptrvar); printf("name = %c%c%c%c%c\n", name[0],name[1],name[2],name[3],name[4]); printf("ptptr = %p %s\n", ptptr, Point_print( ptptr ) ); diff --git a/Examples/python/variables/example.c b/Examples/python/variables/example.c index aa4ffe9b3..05e17c8c5 100644 --- a/Examples/python/variables/example.c +++ b/Examples/python/variables/example.c @@ -51,7 +51,7 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); + printf("cstrvar = %s\n", cstrvar); printf("iptrvar = %p\n", iptrvar); printf("name = %s\n", name); printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); diff --git a/Examples/ruby/variables/example.c b/Examples/ruby/variables/example.c index aa4ffe9b3..05e17c8c5 100644 --- a/Examples/ruby/variables/example.c +++ b/Examples/ruby/variables/example.c @@ -51,7 +51,7 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); + printf("cstrvar = %s\n", cstrvar); printf("iptrvar = %p\n", iptrvar); printf("name = %s\n", name); printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); diff --git a/Examples/tcl/variables/example.c b/Examples/tcl/variables/example.c index aa4ffe9b3..05e17c8c5 100644 --- a/Examples/tcl/variables/example.c +++ b/Examples/tcl/variables/example.c @@ -51,7 +51,7 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); + printf("cstrvar = %s\n", cstrvar); printf("iptrvar = %p\n", iptrvar); printf("name = %s\n", name); printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); From 1c5246ad667c86b869d9be2cf75e43513aec59ba Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 18 Oct 2013 18:13:11 +0100 Subject: [PATCH 0739/1160] Fix some gcc -Wall unused warnings in the Ruby wrappers Fixes SF bug 1333. --- Lib/ruby/rubycontainer.swg | 1 - Lib/ruby/rubyrun.swg | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Lib/ruby/rubycontainer.swg b/Lib/ruby/rubycontainer.swg index d4eaa5f73..dd6389ce4 100644 --- a/Lib/ruby/rubycontainer.swg +++ b/Lib/ruby/rubycontainer.swg @@ -805,7 +805,6 @@ namespace swig rb_raise( rb_eTypeError, "not a valid index or range" ); } - VALUE r = Qnil; static ID id_end = rb_intern("end"); static ID id_start = rb_intern("begin"); static ID id_noend = rb_intern("exclude_end?"); diff --git a/Lib/ruby/rubyrun.swg b/Lib/ruby/rubyrun.swg index e851b1801..c3e0b749b 100644 --- a/Lib/ruby/rubyrun.swg +++ b/Lib/ruby/rubyrun.swg @@ -151,14 +151,13 @@ SWIG_Ruby_InitRuntime(void) SWIGRUNTIME void SWIG_Ruby_define_class(swig_type_info *type) { - VALUE klass; char *klass_name = (char *) malloc(4 + strlen(type->name) + 1); sprintf(klass_name, "TYPE%s", type->name); if (NIL_P(_cSWIG_Pointer)) { _cSWIG_Pointer = rb_define_class_under(_mSWIG, "Pointer", rb_cObject); rb_undef_method(CLASS_OF(_cSWIG_Pointer), "new"); } - klass = rb_define_class_under(_mSWIG, klass_name, _cSWIG_Pointer); + rb_define_class_under(_mSWIG, klass_name, _cSWIG_Pointer); free((void *) klass_name); } From d15220cba49d1fcc46fc913c1869285a4edf7e65 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 18 Oct 2013 19:10:42 +0100 Subject: [PATCH 0740/1160] Remove a couple of unused variable warnings in generated code --- Lib/guile/guile_scm_run.swg | 15 +++------------ Lib/guile/std_vector.i | 4 ---- Source/Modules/php.cxx | 1 - 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/Lib/guile/guile_scm_run.swg b/Lib/guile/guile_scm_run.swg index 0ac51f919..2f8f3ae98 100644 --- a/Lib/guile/guile_scm_run.swg +++ b/Lib/guile/guile_scm_run.swg @@ -446,13 +446,8 @@ SWIG_Guile_Init () SWIGINTERN swig_module_info * SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata)) { - SCM module; - SCM variable; - - module = SWIG_Guile_Init(); - - variable = scm_module_variable(module, - scm_from_locale_symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME)); + SCM module = SWIG_Guile_Init(); + SCM variable = scm_module_variable(module, scm_from_locale_symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME)); if (scm_is_false(variable)) { return NULL; } else { @@ -463,11 +458,7 @@ SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata)) SWIGINTERN void SWIG_Guile_SetModule(swig_module_info *swig_module) { - SCM module; - SCM variable; - - module = SWIG_Guile_Init(); - + SCM module = SWIG_Guile_Init(); scm_module_define(module, scm_from_locale_symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME), scm_from_ulong((unsigned long) swig_module)); diff --git a/Lib/guile/std_vector.i b/Lib/guile/std_vector.i index 79c716b10..1c55239c1 100644 --- a/Lib/guile/std_vector.i +++ b/Lib/guile/std_vector.i @@ -306,7 +306,6 @@ namespace std { $1 = 1; } else { /* check the first element only */ - T* x; SCM o = scm_vector_ref($input,scm_from_ulong(0)); $1 = CHECK(o) ? 1 : 0; } @@ -315,7 +314,6 @@ namespace std { $1 = 1; } else if (scm_is_pair($input)) { /* check the first element only */ - T* x; SCM head = SCM_CAR($input); $1 = CHECK(head) ? 1 : 0; } else { @@ -335,7 +333,6 @@ namespace std { $1 = 1; } else { /* check the first element only */ - T* x; SCM o = scm_vector_ref($input,scm_from_ulong(0)); $1 = CHECK(o) ? 1 : 0; } @@ -344,7 +341,6 @@ namespace std { $1 = 1; } else if (scm_is_pair($input)) { /* check the first element only */ - T* x; SCM head = SCM_CAR($input); $1 = CHECK(head) ? 1 : 0; } else { diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 4ade67250..def917019 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -443,7 +443,6 @@ public: Append(s_header, " zval **args[2];\n"); Append(s_header, " swig_object_wrapper *value;\n"); Append(s_header, " int type;\n"); - Append(s_header, " int thisown;\n"); Append(s_header, "\n"); Append(s_header, " SWIG_ResetError();\n"); Append(s_header, " if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_array_ex(2, args) != SUCCESS) {\n"); From 3720b4884756457ebc6bfaa4020440729e6d1512 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Mon, 21 Oct 2013 13:13:47 -0500 Subject: [PATCH 0741/1160] Add support for SWIG2_CSHARP macro to create SWIG 2 backwards compatability mode. --- Examples/test-suite/csharp/Makefile.in | 2 + .../test-suite/csharp_swig2_compatability.i | 48 +++++++++++++++++++ Lib/csharp/csharp.swg | 18 +++++++ 3 files changed, 68 insertions(+) create mode 100644 Examples/test-suite/csharp_swig2_compatability.i diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index 91b8144de..4bf896385 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -14,6 +14,7 @@ top_builddir = ../@top_builddir@ CPP_TEST_CASES = \ csharp_attributes \ + csharp_swig2_compatability \ csharp_exceptions \ csharp_features \ csharp_lib_arrays \ @@ -36,6 +37,7 @@ CSHARPFLAGSSPECIAL = # Custom tests - tests with additional commandline options intermediary_classname.cpptest: SWIGOPT += -dllimport intermediary_classname csharp_lib_arrays.cpptest: CSHARPFLAGSSPECIAL = -unsafe +csharp_swig2_compatability.cpptest: SWIGOPT += -DSWIG2_CSHARP # Rules for the different types of tests %.cpptest: diff --git a/Examples/test-suite/csharp_swig2_compatability.i b/Examples/test-suite/csharp_swig2_compatability.i new file mode 100644 index 000000000..70a62647b --- /dev/null +++ b/Examples/test-suite/csharp_swig2_compatability.i @@ -0,0 +1,48 @@ +%module csharp_swig2_compatability + +%typemap(cscode) Foo %{ + +// Without the using directives generated by the +// SWIG 2 compatability mode, this code would fail +// to build. +public void FooBar(string input) +{ + Console.WriteLine(input); +} + +%} + +%pragma(csharp) imclasscode=%{ + +// Without the using directives generated by the +// SWIG 2 compatability mode, this code would fail +// to build. +public void IntermediateClassMethod(string input) +{ + Console.WriteLine(input); +} + +%} + +%pragma(csharp) modulecode=%{ + +// Without the using directives generated by the +// SWIG 2 compatability mode, this code would fail +// to build. +public void ModuleClassMethod(string input) +{ + Console.WriteLine(input); +} + +%} + +%inline %{ +class Foo { +public: + Foo() {} + + void Bar() {} +}; + +%} + diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index 7bd660f4d..d6943d30b 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -11,6 +11,24 @@ * The imtype typemap contains the C# type used in the intermediary class. * The cstype typemap contains the C# type used in the C# proxy classes, type wrapper classes and module class. */ +/* SWIG 3 no longer inserts using directives into generated C# code. For backwards compatability, the SWIG2_CSHARP + macro can be defined to have SWIG 3 generate using directives similar to those generated by SWIG 2. */ +#ifdef SWIG2_CSHARP + +%typemap(csimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "\nusing global::System;\nusing global::System.Runtime.InteropServices;\n" + +%pragma(csharp) moduleimports=%{ +using global::System; +using global::System.Runtime.InteropServices; +%} + +%pragma(csharp) imclassimports=%{ +using global::System; +using global::System.Runtime.InteropServices; +%} + +#endif + /* Fragments */ %fragment("SWIG_PackData", "header") { From ec1d5a5be1c7cdaaa8dedc3ba76a5792127cef0f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 21 Oct 2013 21:36:07 +0100 Subject: [PATCH 0742/1160] Correct guile help for -Linkage. -linkage does not work (it clashes with the generic -l option). --- Source/Modules/guile.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index 2c48ba319..3a82d67d8 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -24,7 +24,7 @@ Guile Options (available with -guile)\n\ -exportprimitive - Add the (export ...) code from scmstub into the\n\ GOOPS file.\n\ -goopsprefix - Prepend to all goops identifiers\n\ - -linkage - Use linkage protocol (default `simple')\n\ + -Linkage - Use linkage protocol (default `simple')\n\ Use `module' for native Guile module linking\n\ (requires Guile >= 1.5.0). Use `passive' for\n\ passive linking (no C-level module-handling code),\n\ From 29c98fa7f839bbeb82be4cc64df41dba62ce9b73 Mon Sep 17 00:00:00 2001 From: "Brant K. Kyser" Date: Tue, 22 Oct 2013 11:52:00 -0500 Subject: [PATCH 0743/1160] Update documentation to reflect fully qualifying the use of .NET types in the generated code. --- Doc/Manual/CSharp.html | 146 +++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 70 deletions(-) diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index 6df2594c4..b620b3513 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -10,6 +10,9 @@
    • Introduction +
    • Differences to the Java module
    • Void pointers
    • C# Arrays @@ -69,6 +72,12 @@ The Microsoft Developer Network (MSDN) h Monodoc, available from the Mono project, has a very useful section titled Interop with native libraries.

      +

      19.1.1 SWIG 2 Compatability

      + +

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

      +

      19.2 Differences to the Java module

      @@ -262,7 +271,7 @@ An example shows that char * could be marshalled in different ways,
      -%typemap(imtype, out="IntPtr") char * "string"
      +%typemap(imtype, out="global::System.IntPtr") char * "string"
       char * function(char *);
       
      @@ -273,7 +282,7 @@ The output type is thus IntPtr and the input type is string. The resulting inter
      -public static extern IntPtr function(string jarg1);
      +public static extern global::System.IntPtr function(string jarg1);
       
      @@ -294,8 +303,8 @@ For example:
       %typemap(imtype,
      -         inattributes="[MarshalAs(UnmanagedType.LPStr)]",
      -         outattributes="[return: MarshalAs(UnmanagedType.LPStr)]") const char * "String"
      +         inattributes="[global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPStr)]",
      +         outattributes="[return: global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPStr)]") const char * "String"
       
       const char * GetMsg() {}
       void SetMsg(const char *msg) {}
      @@ -310,12 +319,12 @@ The intermediary class will then have the marshalling as specified by everything
       
       class examplePINVOKE {
         ...
      -  [DllImport("example", EntryPoint="CSharp_GetMsg")]
      -  [return: MarshalAs(UnmanagedType.LPStr)]
      +  [global::System.Runtime.InteropServices.DllImport("example", EntryPoint="CSharp_GetMsg")]
      +  [return: global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPStr)]
         public static extern String GetMsg();
       
      -  [DllImport("example", EntryPoint="CSharp_SetMsg")]
      -  public static extern void SetMsg([MarshalAs(UnmanagedType.LPStr)]String jarg1);
      +  [global::System.Runtime.InteropServices.DllImport("example", EntryPoint="CSharp_SetMsg")]
      +  public static extern void SetMsg([global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPStr)]String jarg1);
       }
       
      @@ -368,7 +377,7 @@ will generate a C# proxy class:
       [ThreadSafe]
      -public class AClass : IDisposable {
      +public class AClass : global::System.IDisposable {
         ...
         [ThreadSafe(false)]
         public AClass(double a) ...
      @@ -392,9 +401,9 @@ An example for attaching attributes to the enum and enum values is shown below.
       
       
      -%typemap(csattributes) Couleur "[System.ComponentModel.Description(\"Colours\")]"
      -%csattributes Rouge "[System.ComponentModel.Description(\"Red\")]"
      -%csattributes Vert "[System.ComponentModel.Description(\"Green\")]"
      +%typemap(csattributes) Couleur "[global::System.ComponentModel.Description(\"Colours\")]"
      +%csattributes Rouge "[global::System.ComponentModel.Description(\"Red\")]"
      +%csattributes Vert "[global::System.ComponentModel.Description(\"Green\")]"
       %inline %{
         enum Couleur { Rouge, Orange, Vert };
       %}
      @@ -407,12 +416,12 @@ which will result in the following C# enum:
       
       
      -[System.ComponentModel.Description("Colours")]
      +[global::System.ComponentModel.Description("Colours")]
       public enum Couleur {
      -  [System.ComponentModel.Description("Red")]
      +  [global::System.ComponentModel.Description("Red")]
         Rouge,
         Orange,
      -  [System.ComponentModel.Description("Green")]
      +  [global::System.ComponentModel.Description("Green")]
         Vert
       }
       
      @@ -618,9 +627,9 @@ marshalling for the arrays:
      -[DllImport("example", EntryPoint="CSharp_myArrayCopy")]
      -public static extern void myArrayCopy([In, MarshalAs(UnmanagedType.LPArray)]int[] jarg1, 
      -                                      [Out, MarshalAs(UnmanagedType.LPArray)]int[] jarg2,
      +[global::System.Runtime.InteropServices.DllImport("example", EntryPoint="CSharp_myArrayCopy")]
      +public static extern void myArrayCopy([global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray)]int[] jarg1, 
      +                                      [global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray)]int[] jarg2,
                                              int jarg3);
       
      @@ -668,9 +677,9 @@ and intermediary class method
      -  [DllImport("example", EntryPoint="CSharp_myArraySwap")]
      -  public static extern void myArraySwap([In, Out, MarshalAs(UnmanagedType.LPArray)]int[] jarg1, 
      -                                        [In, Out, MarshalAs(UnmanagedType.LPArray)]int[] jarg2,
      +  [global::System.Runtime.InteropServices.DllImport("example", EntryPoint="CSharp_myArraySwap")]
      +  public static extern void myArraySwap([global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray)]int[] jarg1, 
      +                                        [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray)]int[] jarg2,
                                                int jarg3);
       
      @@ -743,7 +752,7 @@ As a result, we get the following method in the module class: fixed ( int *swig_ptrTo_sourceArray = sourceArray ) { fixed ( int *swig_ptrTo_targetArray = targetArray ) { { - examplePINVOKE.myArrayCopy((IntPtr)swig_ptrTo_sourceArray, (IntPtr)swig_ptrTo_targetArray, + examplePINVOKE.myArrayCopy((global::System.IntPtr)swig_ptrTo_sourceArray, (global::System.IntPtr)swig_ptrTo_targetArray, nitems); } } @@ -764,8 +773,8 @@ example - the method is expecting an IntPtr as the parameter type.
      -[DllImport("example", EntryPoint="CSharp_myArrayCopy")]
      -public static extern void myArrayCopy(IntPtr jarg1, IntPtr jarg2, int jarg3);
      +[global::System.Runtime.InteropServices.DllImport("example", EntryPoint="CSharp_myArrayCopy")]
      +public static extern void myArrayCopy(global::System.IntPtr jarg1, global::System.IntPtr jarg2, int jarg3);
       
      @@ -1220,7 +1229,7 @@ the C# code can be generated into the intermediary class using the imclassco static CustomExceptionDelegate customDelegate = new CustomExceptionDelegate(SetPendingCustomException); - [DllImport("$dllimport", EntryPoint="CustomExceptionRegisterCallback")] + [global::System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="CustomExceptionRegisterCallback")] public static extern void CustomExceptionRegisterCallback(CustomExceptionDelegate customCallback); @@ -1264,7 +1273,7 @@ The boiler plate code above must be used in addition to a handcrafted Custom
       // Custom C# Exception
      -class CustomApplicationException : System.ApplicationException {
      +class CustomApplicationException : global::System.ApplicationException {
         public CustomApplicationException(string message) 
           : base(message) {
         }
      @@ -1457,20 +1466,17 @@ Below is the generated C# Base director class.
       
       
      -using System;
      -using System.Runtime.InteropServices;
      -
      -public class Base : IDisposable {
      -  private HandleRef swigCPtr;
      +public class Base : global::System.IDisposable {
      +  private global::System.Runtime.InteropServices.HandleRef swigCPtr;
         protected bool swigCMemOwn;
       
      -  internal Base(IntPtr cPtr, bool cMemoryOwn) {
      +  internal Base(global::System.IntPtr cPtr, bool cMemoryOwn) {
           swigCMemOwn = cMemoryOwn;
      -    swigCPtr = new HandleRef(this, cPtr);
      +    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
         }
       
      -  internal static HandleRef getCPtr(Base obj) {
      -    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
      +  internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Base obj) {
      +    return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
         }
       
         ~Base() {
      @@ -1479,12 +1485,12 @@ public class Base : IDisposable {
       
         public virtual void Dispose() {
           lock(this) {
      -      if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
      +      if(swigCPtr.Handle != global::System.IntPtr.Zero && swigCMemOwn) {
               swigCMemOwn = false;
               examplePINVOKE.delete_Base(swigCPtr);
             }
      -      swigCPtr = new HandleRef(null, IntPtr.Zero);
      -      GC.SuppressFinalize(this);
      +      swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
      +      global::System.GC.SuppressFinalize(this);
           }
         }
       
      @@ -1511,7 +1517,7 @@ public class Base : IDisposable {
           examplePINVOKE.Base_director_connect(swigCPtr, swigDelegate0, swigDelegate1);
         }
       
      -  private bool SwigDerivedClassHasMethod(string methodName, Type[] methodTypes) {
      +  private bool SwigDerivedClassHasMethod(string methodName, global::System.global::System.Type[] methodTypes) {
           System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(methodName, methodTypes);
           bool hasDerivedMethod = methodInfo.DeclaringType.IsSubclassOf(typeof(Base));
           return hasDerivedMethod;
      @@ -1521,18 +1527,18 @@ public class Base : IDisposable {
           return UIntMethod(x);
         }
       
      -  private void SwigDirectorBaseBoolMethod(IntPtr b, bool flag) {
      +  private void SwigDirectorBaseBoolMethod(global::System.IntPtr b, bool flag) {
           BaseBoolMethod(new Base(b, false), flag);
         }
       
         internal delegate uint SwigDelegateBase_0(uint x);
      -  internal delegate void SwigDelegateBase_1(IntPtr b, bool flag);
      +  internal delegate void SwigDelegateBase_1(global::System.IntPtr b, bool flag);
       
         private SwigDelegateBase_0 swigDelegate0;
         private SwigDelegateBase_1 swigDelegate1;
       
      -  private static Type[] swigMethodTypes0 = new Type[] { typeof(uint) };
      -  private static Type[] swigMethodTypes1 = new Type[] { typeof(Base), typeof(bool) };
      +  private static global::System.Type[] swigMethodTypes0 = new global::System.Type[] { typeof(uint) };
      +  private static global::System.Type[] swigMethodTypes1 = new global::System.Type[] { typeof(Base), typeof(bool) };
       }
       
      @@ -1755,9 +1761,9 @@ and the following usage from C# after running the code through SWIG: Wheel wheel = new Bike(10).getWheel(); Console.WriteLine("wheel size: " + wheel.size); // Simulate a garbage collection - System.GC.Collect(); - System.GC.WaitForPendingFinalizers(); - Console.WriteLine("wheel size: " + wheel.size); + global::System.GC.Collect(); + global::System.GC.WaitForPendingFinalizers(); + global::System.Console.WriteLine("wheel size: " + wheel.size);
      @@ -1795,9 +1801,9 @@ is called using the following typemaps. // of dangling C++ pointer. Intended for methods that return pointers or // references to a member variable. %typemap(csout, excode=SWIGEXCODE) Wheel& getWheel { - IntPtr cPtr = $imcall;$excode + global::System.IntPtr cPtr = $imcall;$excode $csclassname ret = null; - if (cPtr != IntPtr.Zero) { + if (cPtr != global::System.IntPtr.Zero) { ret = new $csclassname(cPtr, $owner); ret.addReference(this); } @@ -1813,7 +1819,7 @@ The code in the second typemap constitutes the bulk of the code in the generated
      -public class Wheel : IDisposable {
      +public class Wheel : global::System.IDisposable {
         ...
         // Ensure that the GC doesn't collect any Bike instance set from C#
         private Bike bikeReference;
      @@ -1822,12 +1828,12 @@ public class Wheel : IDisposable {
         }
       }
       
      -public class Bike : IDisposable {
      +public class Bike : global::System.IDisposable {
         ...
         public Wheel getWheel() {
      -    IntPtr cPtr = examplePINVOKE.Bike_getWheel(swigCPtr);
      +    global::System.IntPtr cPtr = examplePINVOKE.Bike_getWheel(swigCPtr);
           Wheel ret = null;
      -    if (cPtr != IntPtr.Zero) {
      +    if (cPtr != global::System.IntPtr.Zero) {
             ret = new Wheel(cPtr, false);
             ret.addReference(this);
           }
      @@ -1904,9 +1910,9 @@ In order to understand why, consider a garbage collection occuring...
             container.setElement(element);
             Console.WriteLine("element.value: " + container.getElement().value);
             // Simulate a garbage collection
      -      System.GC.Collect();
      -      System.GC.WaitForPendingFinalizers();
      -      Console.WriteLine("element.value: " + container.getElement().value);
      +      global::System.GC.Collect();
      +      global::System.GC.WaitForPendingFinalizers();
      +      global::System.Console.WriteLine("element.value: " + container.getElement().value);
       
      @@ -1918,14 +1924,14 @@ One solution is to add in the appropriate references in the C# layer...
      -public class Container : IDisposable {
      +public class Container : global::System.IDisposable {
       
         ...
       
         // Ensure that the GC doesn't collect any Element set from C#
         // as the underlying C++ class stores a shallow copy
         private Element elementReference;
      -  private HandleRef getCPtrAndAddReference(Element element) {
      +  private global::System.Runtime.InteropServices.HandleRef getCPtrAndAddReference(Element element) {
           elementReference = element;
           return Element.getCPtr(element);
         }
      @@ -1951,7 +1957,7 @@ The 'cscode' typemap simply adds in the specified code into the C# proxy class.
         // Ensure that the GC doesn't collect any Element set from C#
         // as the underlying C++ class stores a shallow copy
         private Element elementReference;
      -  private HandleRef getCPtrAndAddReference(Element element) {
      +  private global::System.Runtime.InteropServices.HandleRef getCPtrAndAddReference(Element element) {
           elementReference = element;
           return Element.getCPtr(element);
         }
      @@ -2000,7 +2006,7 @@ First let's look at the code that is generated by default, where the C# proxy cl
       
       
      -public class Action : IDisposable {
      +public class Action : global::System.IDisposable {
         ...
         public Action(CDate dateIn, CDate dateOut) 
             : this(examplePINVOKE.new_Action(CDate.getCPtr(dateIn), CDate.getCPtr(dateOut)), true) {
      @@ -2081,7 +2087,7 @@ The resulting generated proxy code in the Action class follows:
       
       
      -public class Action : IDisposable {
      +public class Action : global::System.IDisposable {
         ...
         public int doSomething(System.DateTime dateIn, out System.DateTime dateOut) {
           CDate tempdateIn = new CDate(dateIn.Year, dateIn.Month, dateIn.Day);
      @@ -2099,7 +2105,7 @@ public class Action : IDisposable {
           }
         }
       
      -  static private IntPtr SwigConstructAction(System.DateTime dateIn, out System.DateTime dateOut) {
      +  static private global::System.IntPtr SwigConstructAction(System.DateTime dateIn, out System.DateTime dateOut) {
           CDate tempdateIn = new CDate(dateIn.Year, dateIn.Month, dateIn.Day);
           CDate tempdateOut = new CDate();
           try {
      @@ -2299,8 +2305,8 @@ The typemap type required is thus CDate *. Given that the previous sect
       %typemap(csvarout, excode=SWIGEXCODE2) CDate * %{
           /* csvarout typemap code */
           get {
      -      IntPtr cPtr = $imcall;
      -      CDate tempDate = (cPtr == IntPtr.Zero) ? null : new CDate(cPtr, $owner);$excode
      +      global::System.IntPtr cPtr = $imcall;
      +      CDate tempDate = (cPtr == global::System.IntPtr.Zero) ? null : new CDate(cPtr, $owner);$excode
             return new System.DateTime(tempDate.getYear(), tempDate.getMonth(), tempDate.getDay(),
                                        0, 0, 0);
           } %}
      @@ -2322,8 +2328,8 @@ public class example {
           } 
           /* csvarout typemap code */
           get {
      -      IntPtr cPtr = examplePINVOKE.ImportantDate_get();
      -      CDate tempDate = (cPtr == IntPtr.Zero) ? null : new CDate(cPtr, false);
      +      global::System.IntPtr cPtr = examplePINVOKE.ImportantDate_get();
      +      CDate tempDate = (cPtr == global::System.IntPtr.Zero) ? null : new CDate(cPtr, false);
             return new System.DateTime(tempDate.getYear(), tempDate.getMonth(), tempDate.getDay(),
                                        0, 0, 0);
           } 
      @@ -2389,7 +2395,7 @@ The generated proxy class code will then contain the following wrapper for calli
       
       
       ...
      -  private void SwigDirectorsomeCallback(IntPtr date) {
      +  private void SwigDirectorsomeCallback(global::System.IntPtr date) {
           System.DateTime tempdate = new System.DateTime();
           try {
             someCallback(out tempdate);
      @@ -2432,7 +2438,7 @@ The default C# proxy class generated is:
       
       
      -public class ExtendMe : IDisposable {
      +public class ExtendMe : global::System.IDisposable {
         ...
         public int Part1() {
           ...
      @@ -2468,7 +2474,7 @@ The C# proxy class becomes a partial class:
       
       
      -public partial class ExtendMe : IDisposable {
      +public partial class ExtendMe : global::System.IDisposable {
         ...
         public int Part1() {
           ...
      @@ -2483,7 +2489,7 @@ You can then of course declare another part of the partial class elsewhere, for
       
       
      -public partial class ExtendMe : IDisposable {
      +public partial class ExtendMe : global::System.IDisposable {
         public int Part2() {
           return 2;
         }
      @@ -2535,7 +2541,7 @@ The generated C# proxy class will instead be:
       
       
      -public class ExtendMe : IDisposable {
      +public class ExtendMe : global::System.IDisposable {
         ...
         public int Part3() {
           return 3;
      
      From 5f53503b7d7fa62a351edc7d3d579d69c55c9952 Mon Sep 17 00:00:00 2001
      From: "Brant K. Kyser" 
      Date: Tue, 22 Oct 2013 14:08:47 -0500
      Subject: [PATCH 0744/1160] Correct spelling of compatibility.
      
      ---
       Doc/Manual/CSharp.html                                    | 6 +++---
       Examples/test-suite/csharp/Makefile.in                    | 4 ++--
       ...swig2_compatability.i => csharp_swig2_compatibility.i} | 8 ++++----
       Lib/csharp/csharp.swg                                     | 2 +-
       4 files changed, 10 insertions(+), 10 deletions(-)
       rename Examples/test-suite/{csharp_swig2_compatability.i => csharp_swig2_compatibility.i} (75%)
      
      diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html
      index b620b3513..764a1a6c3 100644
      --- a/Doc/Manual/CSharp.html
      +++ b/Doc/Manual/CSharp.html
      @@ -11,7 +11,7 @@
       
      • Introduction
      • Differences to the Java module
      • Void pointers @@ -72,10 +72,10 @@ The Microsoft Developer Network (MSDN) h Monodoc, available from the Mono project, has a very useful section titled Interop with native libraries.

        -

        19.1.1 SWIG 2 Compatability

        +

        19.1.1 SWIG 2 Compatibility

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

        19.2 Differences to the Java module

        diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index 4bf896385..22d78ee1c 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -14,7 +14,7 @@ top_builddir = ../@top_builddir@ CPP_TEST_CASES = \ csharp_attributes \ - csharp_swig2_compatability \ + csharp_swig2_compatibility \ csharp_exceptions \ csharp_features \ csharp_lib_arrays \ @@ -37,7 +37,7 @@ CSHARPFLAGSSPECIAL = # Custom tests - tests with additional commandline options intermediary_classname.cpptest: SWIGOPT += -dllimport intermediary_classname csharp_lib_arrays.cpptest: CSHARPFLAGSSPECIAL = -unsafe -csharp_swig2_compatability.cpptest: SWIGOPT += -DSWIG2_CSHARP +csharp_swig2_compatibility.cpptest: SWIGOPT += -DSWIG2_CSHARP # Rules for the different types of tests %.cpptest: diff --git a/Examples/test-suite/csharp_swig2_compatability.i b/Examples/test-suite/csharp_swig2_compatibility.i similarity index 75% rename from Examples/test-suite/csharp_swig2_compatability.i rename to Examples/test-suite/csharp_swig2_compatibility.i index 70a62647b..b11a80e68 100644 --- a/Examples/test-suite/csharp_swig2_compatability.i +++ b/Examples/test-suite/csharp_swig2_compatibility.i @@ -1,9 +1,9 @@ -%module csharp_swig2_compatability +%module csharp_swig2_compatibility %typemap(cscode) Foo %{ // Without the using directives generated by the -// SWIG 2 compatability mode, this code would fail +// SWIG 2 compatibility mode, this code would fail // to build. public void FooBar(string input) { @@ -15,7 +15,7 @@ public void FooBar(string input) %pragma(csharp) imclasscode=%{ // Without the using directives generated by the -// SWIG 2 compatability mode, this code would fail +// SWIG 2 compatibility mode, this code would fail // to build. public void IntermediateClassMethod(string input) { @@ -27,7 +27,7 @@ public void IntermediateClassMethod(string input) %pragma(csharp) modulecode=%{ // Without the using directives generated by the -// SWIG 2 compatability mode, this code would fail +// SWIG 2 compatibility mode, this code would fail // to build. public void ModuleClassMethod(string input) { diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index d6943d30b..70e9fd4b4 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -11,7 +11,7 @@ * The imtype typemap contains the C# type used in the intermediary class. * The cstype typemap contains the C# type used in the C# proxy classes, type wrapper classes and module class. */ -/* SWIG 3 no longer inserts using directives into generated C# code. For backwards compatability, the SWIG2_CSHARP +/* SWIG 3 no longer inserts using directives into generated C# code. For backwards compatibility, the SWIG2_CSHARP macro can be defined to have SWIG 3 generate using directives similar to those generated by SWIG 2. */ #ifdef SWIG2_CSHARP From 6736e74127180f012dab11379a2159cd073461d4 Mon Sep 17 00:00:00 2001 From: Marvin Greenberg Date: Tue, 22 Oct 2013 20:31:14 +0100 Subject: [PATCH 0745/1160] Add feature director:except for improved director exception handling in Java Closes #91 --- Doc/Manual/Java.html | 276 ++++++++++++++++++ Doc/Manual/Warnings.html | 1 + Examples/test-suite/director_exception.i | 23 ++ Examples/test-suite/java/Makefile.in | 16 +- ...rector_exception_feature_nspace_runme.java | 150 ++++++++++ ...java_director_exception_feature_runme.java | 152 ++++++++++ .../java_director_exception_feature.i | 209 +++++++++++++ .../java_director_exception_feature_nspace.i | 216 ++++++++++++++ Lib/java/director.swg | 240 ++++++++++++++- Lib/java/std_string.i | 3 +- Source/Include/swigwarn.h | 1 + Source/Modules/java.cxx | 233 ++++++++++++--- 12 files changed, 1469 insertions(+), 51 deletions(-) create mode 100644 Examples/test-suite/java/java_director_exception_feature_nspace_runme.java create mode 100644 Examples/test-suite/java/java_director_exception_feature_runme.java create mode 100644 Examples/test-suite/java_director_exception_feature.i create mode 100644 Examples/test-suite/java_director_exception_feature_nspace.i diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index f3d8a1684..0e9ba75de 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -87,6 +87,7 @@
      • Simple directors example
      • Director threading issues
      • Director performance tuning +
      • Java Exceptions from Directors
    • Accessing protected members
    • Common customization features @@ -3555,6 +3556,281 @@ However, if all director methods are expected to usually be overridden by Java s The disadvantage is that invocation of director methods from C++ when Java doesn't actually override the method will require an additional call up into Java and back to C++. As such, this option is only useful when overrides are extremely common and instantiation is frequent enough that its performance is critical.

      +

      24.5.7 Java Exceptions from Directors

      + +

      +With directors routing method calls to Java, and proxies routing them +to C++, the handling of exceptions is an important concern. In Swig +2.0, the director class methods ignored java exceptions that occurred +during method calls dispatched to the Java director class and simply +returned '$null' to the C++ caller. The default behavior now throws a +Swig-defined DirectorException C++ exception. A facility +is now provided to allow translation of thrown Java exceptions into +C++ exceptions. This can be done in two different ways using +the %feature("director:except") directive. In the +simplest approach, a code block is attached to each director method to +handle the mapping of java exceptions into C++ exceptions. +

      + +
      +
      +// All the rules to associate a feature with an element apply
      +%feature("director:except") MyClass::method(int x) {
      +  jthrowable $error = jenv->ExceptionOccurred();
      +  if ($error) {
      +    jenv->ExceptionClear();
      +    if (Swig::ExceptionMatches(jenv,$error,"java/lang/IndexOutOfBoundsException"))
      +      throw std::out_of_range(Swig::JavaExceptionMessage(jenv,$error).message());
      +    else if (Swig::ExceptionMatches(jenv,$error,"$packagepath/MyJavaException"))
      +      throw MyCppException(Swig::JavaExceptionMessage(jenv,$error).message());
      +    else
      +      throw std::runtime_error("Unexpected exception thrown by MyClass::method");
      +  }
      +}
      +
      +class MyClass {
      +  void method(int x); /* on C++ side, may get std::runtime_error or MyCppException */
      +}
      +
      +
      +

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

      + +

      +If many methods may throw different exceptions, using this approach to +write handlers for a large number of methods will result in +duplication of the code in the director:except feature +code blocks, and will require separate feature definitions for every +method. So an alternative approach is provided, using typemaps in a +fashion analagous to +the "throws" typemap. The +"throws" typemap provides an approach to automatically map all the C++ +exceptions listed in a method's defined exceptions (either from +an exception specification or a %catches +feature) into Java exceptions, for the generated proxy classes. To +provide the inverse mapping, the directorthrows typemap +is provided. + +

      Using directorthrows typemaps allows a +generic director:except feature to be combined with +method-specific handling to achieve the desired result. The +default director:except feature, in combination +with directorthrows typemaps generate exception mapping +to C++ exceptions for all the exceptions defined for each method. The +default definition is shown below.

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

      The code generated using the director:except feature +replaces the $directorthrowshandlers with code that throws +appropriate C++ exceptions from directorthrows typemaps +for each exception defined for the method. Just as with +the "throws" typemap, the +possible exceptions may be defined either with an exception +specification ( throw(MyException,std::runtime_error) ) or +using the %catches feature applied to the method.

      + +

      Note: Using the %catches feature to define the +handled exceptions is preferred to using exception specifications. If +the interface is defined with an exception specification the generated +swig proxy classes will have the same exception specification. In C++ +if exceptions other than those in the specification are thrown, the +program will be terminated.

      + +

      Because this default definition maps any unhandled java exceptions to +Swig::DirectorException, any director methods that define exception +specifications will cause program termination. To simply ignore +unexpected exceptions, the default can be changed to: + +

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

      + +

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

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

      + +

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

      + +

      Below is a complete example demonstrating the use +of directorthrows typemaps. The directorthrows typemap +provides a code fragment to test for a pending java exception type, and the +resulting C++ exception that will be thrown. In this example, a +generic directorthrows typemap is appropriate for all three exceptions - all +take single string constructors. If the constructors had different constructors, +it would be neccessary to have separate typemaps for each exception type. + + + +

      +
      +// Define exceptions in header section using std::runtime_error
      +%define DEFINE_EXCEPTION(NAME)
      +%{
      +  #include <exception>
      +  namespace MyNS {
      +    struct NAME : public std::runtime_error { NAME(const std::string& what):runtime_error(what) {}; };
      +  }
      +%}
      +%enddef
      +// Expose c++ exceptions as java Exceptions with getMessage
      +%define DECLARE_EXCEPTION(NAME)
      +%typemap(javabase) MyNS::NAME "java.lang.Exception";
      +%rename(getMessage,fullname=1) MyNS::NAME::what;
      +namespace MyNS {
      +  struct NAME {
      +    NAME(const std::string& what);
      +    const char * what();
      +  };
      +}
      +%enddef
      +
      +DEFINE_EXCEPTION(ExceptionA)
      +DEFINE_EXCEPTION(ExceptionB)
      +DEFINE_EXCEPTION(Unknown)
      +
      +// Mark three methods to map director-thrown exceptions.
      +// Standard rules for feature matching apply
      +%feature("director:except") MyClass::meth1(int);
      +%feature("director:except") MyClass::meth2;
      +%feature("director:except") meth3;
      +
      +%typemap(directorthrows) MyNS::ExceptionA, MyNS::ExceptionB, MyNS::Unexpected %{
      +  if (Swig::ExceptionMatches(jenv,$error,"$packagepath/$javaclassname"))
      +    throw $1_type(Swig::JavaExceptionMessage(jenv,$error).message());
      +%}
      +
      +DECLARE_EXCEPTION(ExceptionA)
      +DECLARE_EXCEPTION(ExceptionB)
      +DECLARE_EXCEPTION(Unexpected)
      +
      +%catches(MyNS::ExceptionA, MyNS::ExceptionB, MyNS::Unexpected) MyClass::meth2();
      +
      +%inline {
      +  class MyClass {
      +  public:
      +    virtual void meth1(int x) throw(MyNS::ExceptionA, MyNS::ExceptionB) = 0;
      +    virtual void meth2() = 0;   /* throws MyNS::ExceptionA, MyNS::ExceptionB, MyNS::Unexpected */
      +    virtual void meth3(float x) throw(MyNS::Unexpected) = 0;
      +    virtual ~MyClass() {};
      +  };
      +}
      +
      +
      + +

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

      + +

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

      + +
      +
      +%feature ("except",throws="Exception")  MyClass::myMeth %{
      +  try { $action }
      +  catch (Swig::DirectorException & direxcp) {
      +    // jenv always available in JNI code
      +    // raise the java exception that originally caused the DirectorException
      +    direxcp.raiseJavaException(jenv);
      +    return $null;
      +  }
      +%}
      +
      +
      + +

      The throws="Exception" attribute on the exception +feature is necessary if any of the translated exceptions will be +checked exceptions, since the java compiler will otherwise assert that +no checked exceptions can be thrown by the method. This may be more +specific that the completely generic "Exception" class, of course. A +similar feature must be added to director methods to allow checked +exceptions to be thrown from the director method implementations. +Here, no actual exception handling is needed - the feature simply +is being used to add a generic checked exception signature to the +generated director method wrapper.

      + +
      +
      +%feature ("except",throws="Exception")  MyDirectorClass::myDirMeth %{ %}
      +
      +
      + +

      24.6 Accessing protected members

      diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index aac415952..5b507c123 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -499,6 +499,7 @@ example.i(4) : Syntax error in input.
    • 474. Method method usage of the optimal attribute ignored in the out typemap as the following cannot be used to generate optimal code: code
    • 475. Multiple calls to method might be generated due to optimal attribute usage in the out typemap.
    • 476. Initialization using std::initializer_list. +
    • 477. Feature director:except on Class::method with $directorthrowshandlers requires directorthrows typemap for exception Exception
    diff --git a/Examples/test-suite/director_exception.i b/Examples/test-suite/director_exception.i index de0ef3343..3fd3e563c 100644 --- a/Examples/test-suite/director_exception.i +++ b/Examples/test-suite/director_exception.i @@ -41,6 +41,29 @@ class DirectorMethodException: public Swig::DirectorException {}; #endif +#ifdef SWIGJAVA + +// Default for director exception warns about unmapped exceptions now in java +// Suppress warnings for this older test +// %warnfilter(476) Bar; + +// Default for java is to throw Swig::DirectorException if no +// direct:except feature. Since methods below have exception specification +// cannot throw director exception. + +// Change back to old 2.0 default behavior + +%feature("director:except") { + jthrowable $error = jenv->ExceptionOccurred(); + if ($error) { + // Dont clear exception, still be active when return to java execution + // Essentially ignore exception occurred -- old behavior. + return $null; + } +} + +#endif + #ifdef SWIGRUBY %feature("director:except") { diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index e4f3c6b58..52ae78563 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -24,6 +24,8 @@ CPP_TEST_CASES = \ java_constants \ java_director \ java_director_assumeoverride \ + java_director_exception_feature \ + java_director_exception_feature_nspace \ java_enums \ java_jnitypes \ java_lib_arrays_dimensionless \ @@ -44,8 +46,18 @@ JAVA_PACKAGE = $* JAVA_PACKAGEOPT = -package $(JAVA_PACKAGE) SWIGOPT += $(JAVA_PACKAGEOPT) +RUNME_CLASSPATH = -classpath . +ifeq (Cygwin,$(shell uname -o 2>/dev/null)) +SEP=; +else +SEP=: +endif + # Custom tests - tests with additional commandline options java_nspacewithoutpackage.%: JAVA_PACKAGEOPT = +java_director_exception_feature_nspace.%: JAVA_PACKAGEOPT = +java_director_exception_feature_nspace.%: RUNME_CLASSPATH = -classpath .$(SEP)./java_director_exception_feature_nspace + nspace.%: JAVA_PACKAGE = $*Package nspace_extend.%: JAVA_PACKAGE = $*Package director_nspace.%: JAVA_PACKAGE = $*Package @@ -84,8 +96,8 @@ setup = \ run_testcase = \ 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="$(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) $(JAVAFLAGS) -classpath . $*_runme; \ + $(COMPILETOOL) $(JAVAC) $(RUNME_CLASSPATH) -d . $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ + 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) $(JAVAFLAGS) $(RUNME_CLASSPATH) $*_runme; \ fi # Clean: remove testcase directories diff --git a/Examples/test-suite/java/java_director_exception_feature_nspace_runme.java b/Examples/test-suite/java/java_director_exception_feature_nspace_runme.java new file mode 100644 index 000000000..0cde36953 --- /dev/null +++ b/Examples/test-suite/java/java_director_exception_feature_nspace_runme.java @@ -0,0 +1,150 @@ +import MyNS.*; +import MyNS_JNI.*; + +class java_director_exception_feature_nspace_Consts { + public static final String PINGEXCP1 = "Ping MyJavaException1"; // should get translated through an int on ping + public static final String PINGEXCP2 = "Ping MyJavaException2"; + + public static final String PONGEXCP1 = "Pong MyJavaException1"; + public static final String PONGEXCP2 = "Pong MyJavaException2"; + public static final String PONGUNEXPECTED = "Pong MyJavaUnexpected"; + public static final String TRANSLATED_NPE = "Pong Translated NPE"; + + public static final String GENERICPONGEXCP1 = "GenericPong Wrapped MyJavaException1"; + public static final String GENERICPONGEXCP2 = "GenericPong New Checked Exception"; + public static final String GENERICPONGEXCP3 = "GenericPong New Unchecked Exception"; + public static final String GENERICPONGEXCP4 = "GenericPong New Exception Without String ctor"; +} + +// an exception not mentioned or wrapped by the swig interface, +// to reconstruct using generic DirectorException handling +class NewCheckedException extends Exception { + public NewCheckedException(String s) { + super(s); + } +} + +// an exception not mentioned or wrapped by the swig interface, +// to reconstruct using generic DirectorException handling +class NewUncheckedException extends RuntimeException { + public NewUncheckedException(String s) { + super(s); + } +} + +// an exception not constructable from a string, +// to test DirectorException fallback reconstruction +class UnconstructableException extends Exception { + private int extrastate; + public UnconstructableException(int a, String s) { + super(s); + extrastate = a; + } +} + +class java_director_exception_feature_nspace_MyFooDirectorImpl extends Foo { + + public java_director_exception_feature_nspace_MyFooDirectorImpl() { }; + + @Override + public String ping(int excp) throws MyJavaException1, MyJavaException2 { + if (excp == 1) throw new MyJavaException1(java_director_exception_feature_nspace_Consts.PINGEXCP1); + if (excp == 2) throw new MyJavaException2(java_director_exception_feature_nspace_Consts.PINGEXCP2); + return "Ping director returned"; + } + @Override + public String pong(int excp) throws MyJavaException1, MyJavaException2, MyJavaUnexpected { + if (excp == 1) throw new MyJavaException1(java_director_exception_feature_nspace_Consts.PONGEXCP1); + if (excp == 2) throw new MyJavaException2(java_director_exception_feature_nspace_Consts.PONGEXCP2); + if (excp == 3) throw new MyJavaUnexpected(java_director_exception_feature_nspace_Consts.PONGUNEXPECTED); + if (excp == 4) throw new java.lang.NullPointerException(java_director_exception_feature_nspace_Consts.TRANSLATED_NPE); // should be translated to ::Unexpected + return "Pong director returned"; + } + + @Override + public String genericpong(int excp) throws MyJavaException1, NewCheckedException, UnconstructableException { + if (excp == 1) + throw new MyJavaException1(java_director_exception_feature_nspace_Consts.GENERICPONGEXCP1); + if (excp == 2) + throw new NewCheckedException(java_director_exception_feature_nspace_Consts.GENERICPONGEXCP2); + if (excp == 3) + throw new NewUncheckedException(java_director_exception_feature_nspace_Consts.GENERICPONGEXCP3); + if (excp == 4) + throw new UnconstructableException(1, java_director_exception_feature_nspace_Consts.GENERICPONGEXCP4); + return "GenericPong director returned"; + } +} + +public class java_director_exception_feature_nspace_runme { + + static { + try { + System.loadLibrary("java_director_exception_feature_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 fail(String msg) { + System.err.println(msg); System.exit(1); + } + public static void failif(boolean cond, String msg) { + if (cond) fail(msg); + } + + + public static void main(String argv[]) { + + Bar b = new Bar(new java_director_exception_feature_nspace_MyFooDirectorImpl()); + try { + + try { b.ping(0); } catch (Exception e) + { fail("Exception should not have been thrown: " + e + " from ping(0)"); } + try { b.ping(1); fail("No exception thrown in ping(1)"); } catch (MyJavaException1 e) + // Should say "Threw some integer", see java_director_exception_feature.i Foo::ping throws a "1" + { failif( ! "Threw some integer".equals(e.getMessage()), "Ping exception not translated through int: '" + e.getMessage() + "'"); } + try { b.ping(2); fail("No exception thrown in ping(2)"); } catch (MyJavaException2 e) + { failif( ! java_director_exception_feature_nspace_Consts.PINGEXCP2.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); } + + try { b.pong(0); } catch (Exception e) + { fail("Exception should not have been thrown: " + e + " from pong(0)"); } + try { b.pong(1); fail("No exception thrown in pong(1)"); } catch (MyJavaException1 e) + { failif( ! java_director_exception_feature_nspace_Consts.PONGEXCP1.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); } + try { b.pong(2); fail("No exception thrown in pong(2)");} catch (MyJavaException2 e) + { failif( ! java_director_exception_feature_nspace_Consts.PONGEXCP2.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); } + try { b.pong(3); fail("No exception thrown in pong(3)");} catch (MyJavaUnexpected e) + { failif( ! java_director_exception_feature_nspace_Consts.PONGUNEXPECTED.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); } + try { b.pong(4); fail("No exception thrown in pong(4)"); } catch (MyJavaUnexpected e) + { failif( ! java_director_exception_feature_nspace_Consts.TRANSLATED_NPE.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); } + + + try { b.genericpong(0); } + catch (Exception e) { + fail("Exception should not have been thrown: " + e + " from genericpong(0)"); + } + try { b.genericpong(1); fail("No exception thrown in genericpong(1)"); } + catch (MyJavaException1 e) { + failif( ! java_director_exception_feature_nspace_Consts.GENERICPONGEXCP1.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); + } + try { b.genericpong(2); fail("No exception thrown in genericpong(2)");} + catch (NewCheckedException e) { + failif( ! java_director_exception_feature_nspace_Consts.GENERICPONGEXCP2.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); + } + try { b.genericpong(3); fail("No exception thrown in genericpong(3)");} + catch (NewUncheckedException e) { + failif( ! java_director_exception_feature_nspace_Consts.GENERICPONGEXCP3.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); + } + try { b.genericpong(4); fail("No exception thrown in genericpong(4)");} + catch (RuntimeException e) { + failif ( e.getClass() != RuntimeException.class, "Exception " + e + " is not exactly RumtimeException"); + failif( ! java_director_exception_feature_nspace_Consts.GENERICPONGEXCP4.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); + } + } + catch (Exception e) { + e.printStackTrace(); + fail("Unexpected exception thrown or exception not mapped properly"); + } + + } +} diff --git a/Examples/test-suite/java/java_director_exception_feature_runme.java b/Examples/test-suite/java/java_director_exception_feature_runme.java new file mode 100644 index 000000000..2e919c18a --- /dev/null +++ b/Examples/test-suite/java/java_director_exception_feature_runme.java @@ -0,0 +1,152 @@ + +import java_director_exception_feature.*; + +class java_director_exception_feature_Consts { + public static final String PINGEXCP1 = "Ping MyJavaException1"; // should get translated through an int on ping + public static final String PINGEXCP2 = "Ping MyJavaException2"; + + public static final String PONGEXCP1 = "Pong MyJavaException1"; + public static final String PONGEXCP2 = "Pong MyJavaException2"; + public static final String PONGUNEXPECTED = "Pong MyJavaUnexpected"; + public static final String TRANSLATED_NPE = "Pong Translated NPE"; + + public static final String GENERICPONGEXCP1 = "GenericPong Wrapped MyJavaException1"; + public static final String GENERICPONGEXCP2 = "GenericPong New Checked Exception"; + public static final String GENERICPONGEXCP3 = "GenericPong New Unchecked Exception"; + public static final String GENERICPONGEXCP4 = "GenericPong New Exception Without String ctor"; + +} + +// an exception not mentioned or wrapped by the swig interface, +// to reconstruct using generic DirectorException handling +class NewCheckedException extends Exception { + public NewCheckedException(String s) { + super(s); + } +} + +// an exception not mentioned or wrapped by the swig interface, +// to reconstruct using generic DirectorException handling +class NewUncheckedException extends RuntimeException { + public NewUncheckedException(String s) { + super(s); + } +} + +// an exception not constructable from a string, +// to test DirectorException fallback reconstruction +class UnconstructableException extends Exception { + private int extrastate; + public UnconstructableException(int a, String s) { + super(s); + extrastate = a; + } +} + +class java_director_exception_feature_MyFooDirectorImpl extends Foo { + + public java_director_exception_feature_MyFooDirectorImpl() { }; + + @Override + public String ping(int excp) throws MyJavaException1, MyJavaException2 { + if (excp == 1) throw new MyJavaException1(java_director_exception_feature_Consts.PINGEXCP1); + if (excp == 2) throw new MyJavaException2(java_director_exception_feature_Consts.PINGEXCP2); + return "Ping director returned"; + } + @Override + public String pong(int excp) throws MyJavaException1, MyJavaException2, MyJavaUnexpected { + if (excp == 1) throw new MyJavaException1(java_director_exception_feature_Consts.PONGEXCP1); + if (excp == 2) throw new MyJavaException2(java_director_exception_feature_Consts.PONGEXCP2); + if (excp == 3) throw new MyJavaUnexpected(java_director_exception_feature_Consts.PONGUNEXPECTED); + if (excp == 4) throw new java.lang.NullPointerException(java_director_exception_feature_Consts.TRANSLATED_NPE); // should be translated to ::Unexpected + return "Pong director returned"; + } + + @Override + public String genericpong(int excp) throws MyJavaException1, NewCheckedException, UnconstructableException { + if (excp == 1) + throw new MyJavaException1(java_director_exception_feature_Consts.GENERICPONGEXCP1); + if (excp == 2) + throw new NewCheckedException(java_director_exception_feature_Consts.GENERICPONGEXCP2); + if (excp == 3) + throw new NewUncheckedException(java_director_exception_feature_Consts.GENERICPONGEXCP3); + if (excp == 4) + throw new UnconstructableException(1, java_director_exception_feature_Consts.GENERICPONGEXCP4); + return "GenericPong director returned"; + } +} + +public class java_director_exception_feature_runme { + + static { + try { + System.loadLibrary("java_director_exception_feature"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void fail(String msg) { + System.err.println(msg); System.exit(1); + } + public static void failif(boolean cond, String msg) { + if (cond) fail(msg); + } + + + public static void main(String argv[]) { + + Bar b = new Bar(new java_director_exception_feature_MyFooDirectorImpl()); + try { + + try { b.ping(0); } catch (Exception e) + { fail("Exception should not have been thrown: " + e + " from ping(0)"); } + try { b.ping(1); fail("No exception thrown in ping(1)"); } catch (MyJavaException1 e) + // Should say "Threw some integer", see java_director_exception_feature.i Foo::ping throws a "1" + { failif( ! "Threw some integer".equals(e.getMessage()), "Ping exception not translated through int: '" + e.getMessage() + "'"); } + try { b.ping(2); fail("No exception thrown in ping(2)"); } catch (MyJavaException2 e) + { failif( ! java_director_exception_feature_Consts.PINGEXCP2.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); } + + try { b.pong(0); } catch (Exception e) + { fail("Exception should not have been thrown: " + e + " from pong(0)"); } + try { b.pong(1); fail("No exception thrown in pong(1)"); } catch (MyJavaException1 e) + { failif( ! java_director_exception_feature_Consts.PONGEXCP1.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); } + try { b.pong(2); fail("No exception thrown in pong(2)");} catch (MyJavaException2 e) + { failif( ! java_director_exception_feature_Consts.PONGEXCP2.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); } + try { b.pong(3); fail("No exception thrown in pong(3)");} catch (MyJavaUnexpected e) + { failif( ! java_director_exception_feature_Consts.PONGUNEXPECTED.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); } + try { b.pong(4); fail("No exception thrown in pong(4)"); } catch (MyJavaUnexpected e) + { failif( ! java_director_exception_feature_Consts.TRANSLATED_NPE.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); } + + + try { b.genericpong(0); } + catch (Exception e) { + fail("Exception should not have been thrown: " + e + " from genericpong(0)"); + } + try { b.genericpong(1); fail("No exception thrown in genericpong(1)"); } + catch (MyJavaException1 e) { + failif( ! java_director_exception_feature_Consts.GENERICPONGEXCP1.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); + } + try { b.genericpong(2); fail("No exception thrown in genericpong(2)");} + catch (NewCheckedException e) { + failif( ! java_director_exception_feature_Consts.GENERICPONGEXCP2.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); + } + try { b.genericpong(3); fail("No exception thrown in genericpong(3)");} + catch (NewUncheckedException e) { + failif( ! java_director_exception_feature_Consts.GENERICPONGEXCP3.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); + } + try { b.genericpong(4); fail("No exception thrown in genericpong(4)");} + catch (RuntimeException e) { + failif ( e.getClass() != RuntimeException.class, "Exception " + e + " is not exactly RumtimeException"); + failif( ! java_director_exception_feature_Consts.GENERICPONGEXCP4.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); + } + + } + catch (Exception e) { + e.printStackTrace(); + fail("Unexpected exception thrown or exception not mapped properly"); + } + + } +} diff --git a/Examples/test-suite/java_director_exception_feature.i b/Examples/test-suite/java_director_exception_feature.i new file mode 100644 index 000000000..b649b541d --- /dev/null +++ b/Examples/test-suite/java_director_exception_feature.i @@ -0,0 +1,209 @@ +%module(directors="1") java_director_exception_feature + +%include + +%{ +#if defined(_MSC_VER) + #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) +#endif + +#include +%} + +%include + +// DEFINE exceptions in header section using std::runtime_error +%{ + #include + #include + + namespace MyNS { + + struct Exception1 : public std::runtime_error { + Exception1(const std::string& what):runtime_error(what) {} + }; + struct Exception2 : public std::runtime_error { + Exception2(const std::string& what):runtime_error(what) {} + }; + struct Unexpected : public std::runtime_error { + Unexpected(const std::string& what):runtime_error(what) {} + }; + + } + +%} + +// Add an explicit handler for Foo::ping, mapping one java exception back to an 'int' +%feature("director:except") MyNS::Foo::ping { + jthrowable $error = jenv->ExceptionOccurred(); + if ($error) { + jenv->ExceptionClear(); // clear java exception since mapping to c++ exception + if (Swig::ExceptionMatches(jenv,$error,"$packagepath/MyJavaException1")) { + throw 1; + } else if (Swig::ExceptionMatches(jenv,$error,"$packagepath/MyJavaException2")) { + std::string msg(Swig::JavaExceptionMessage(jenv,$error).message()); + throw MyNS::Exception2(msg); + } else { + std::cerr << "Test failed, unexpected exception thrown: " << + Swig::JavaExceptionMessage(jenv,$error).message() << std::endl; + throw std::runtime_error("unexpected exception in Foo::ping"); + } + } +} + +// Use default handler on Foo::pong, with directorthrows typemaps + +// directorthrows typemaps for java->c++ conversions +%typemap(directorthrows) MyNS::Exception1,MyNS::Exception2,MyNS::Unexpected %{ + if (Swig::ExceptionMatches(jenv, $error, "$packagepath/$javaclassname")) { + std::string msg(Swig::JavaExceptionMessage(jenv,$error).message()); + throw $1_type(msg); + } +%} + +// Override the director:except feature so exception specification is not violated +// (Cannot use built-in default of throw DirectorException) +%feature("director:except") MyNS::Foo::pong %{ + jthrowable $error = jenv->ExceptionOccurred(); + if ($error) { + jenv->ExceptionClear(); + $directorthrowshandlers + throw ::MyNS::Unexpected(Swig::JavaExceptionMessage(jenv,$error).message()); + } +%} + +// TODO 'throws' typemap emitted by emit_action (emit.cxx) has no way +// to get access to language specific special variables like +// $javaclassname or $packagepath ("java_director_exception_feature" here) + +// throws typemaps for c++->java exception conversions +%typemap(throws,throws="MyJavaException1") MyNS::Exception1 %{ + jclass excpcls = jenv->FindClass("java_director_exception_feature/MyJavaException1"); + if (excpcls) { + jenv->ThrowNew(excpcls, $1.what()); + } + return $null; +%} + +%typemap(throws,throws="MyJavaException1") int %{ + jclass excpcls = jenv->FindClass("java_director_exception_feature/MyJavaException1"); + if (excpcls) { + jenv->ThrowNew(excpcls, "Threw some integer"); + } + return $null; +%} + +%typemap(throws,throws="MyJavaException2") MyNS::Exception2 %{ + jclass excpcls = jenv->FindClass("java_director_exception_feature/MyJavaException2"); + if (excpcls) { + jenv->ThrowNew(excpcls, $1.what()); + } + return $null; +%} + +%typemap(throws,throws="MyJavaUnexpected") MyNS::Unexpected %{ + jclass excpcls = jenv->FindClass("java_director_exception_feature/MyJavaUnexpected"); + if (excpcls) { + jenv->ThrowNew(excpcls, $1.what()); + } + return $null; +%} + +// Use generic exception translation approach like python, ruby + +%feature("director:except") MyNS::Foo::genericpong { + jthrowable $error = jenv->ExceptionOccurred(); + if ($error) { + jenv->ExceptionClear(); + throw Swig::DirectorException(jenv,$error); + } +} + +// %exception with throws attribute. Need throws attribute for checked exceptions +%feature ("except",throws="Exception") MyNS::Foo::genericpong %{ +%} + +%feature ("except",throws="Exception") MyNS::Bar::genericpong %{ + try { $action } + catch (Swig::DirectorException & direxcp) { + direxcp.raiseJavaException(jenv); // jenv always available in JNI code + return $null; + } +%} + + + +%feature("director") Foo; + +// Rename exceptions on java side to make translation of exceptions more clear +%rename(MyJavaException1,fullname=1) MyNS::Exception1; +%rename(MyJavaException2,fullname=1) MyNS::Exception2; +%rename(MyJavaUnexpected,fullname=1) MyNS::Unexpected; + +%typemap(javabase) ::MyNS::Exception1,::MyNS::Exception2,::MyNS::Unexpected "java.lang.Exception"; +%rename(getMessage) what(); // Rename all what() methods + +namespace MyNS { + + struct Exception1 { + Exception1(const std::string& what); + const char * what(); + }; + struct Exception2 { + Exception2(const std::string& what); + const char * what(); + }; + struct Unexpected { + Unexpected(const std::string& what); + const char * what(); + }; + +} +// In general it is better to use %catches instead of an exception specification on the method +// since violating an exception specification calls terminate() preventing catch-all behavior +// like throwing std::runtime_error. But an exception specification must be used if the +// actual interface being wrapped does use them. +%catches(MyNS::Exception1,MyNS::Exception2,MyNS::Unexpected) MyNS::Foo::pong; +%catches(MyNS::Exception1,MyNS::Exception2,MyNS::Unexpected) MyNS::Bar::pong; + +%inline %{ + +namespace MyNS { + +class Foo { +public: + virtual ~Foo() {} + // ping java implementation throws a java Exception1 or an Exception2 if excp is 1 or 2. + // pong java implementation throws Exception1,Exception2,Unexpected,NullPointerException for 1,2,3,4 + virtual std::string ping(int excp) throw(int,MyNS::Exception2) = 0; + virtual std::string pong(int excp) /* throws MyNS::Exception1 MyNS::Exception2 MyNS::Unexpected) */ = 0; + virtual std::string genericpong(int excp) /* unspecified throws - exception is always DirectorException in C++, translated back to whatever thrown in java */ = 0; +}; + +// Make a bar from a foo, so a call to Java Bar +// goes Java Bar -> C++ Bar -> C++ Foo -> Java Foo Director + +class Bar { +public: + Bar(Foo* d) { delegate=d; } + virtual std::string ping(int excp) throw(int,MyNS::Exception2) + { + return delegate->ping(excp); + } + + virtual std::string pong(int excp) /* throws MyNS::Exception1,MyNS::Exception2,MyNS::Unexpected */ + { + return delegate->pong(excp); + } + + virtual std::string genericpong(int excp) + { + return delegate->genericpong(excp); + } + +private: + Foo * delegate; +}; + +} +%} diff --git a/Examples/test-suite/java_director_exception_feature_nspace.i b/Examples/test-suite/java_director_exception_feature_nspace.i new file mode 100644 index 000000000..8723ef738 --- /dev/null +++ b/Examples/test-suite/java_director_exception_feature_nspace.i @@ -0,0 +1,216 @@ +%module(directors="1") java_director_exception_feature_nspace + +%include + +%nspace; // turn namespace feature on for everything. + +// When using namespaces with no -package, must put JNI classes into a namespace +%pragma(java) jniclasspackage=%{MyNS_JNI%} +%warnfilter(826); + +%{ +#if defined(_MSC_VER) + #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) +#endif + +#include +%} + +%include + +// DEFINE exceptions in header section using std::runtime_error +%{ + #include + #include + + namespace MyNS { + + struct Exception1 : public std::runtime_error { + Exception1(const std::string& what):runtime_error(what) {} + }; + struct Exception2 : public std::runtime_error { + Exception2(const std::string& what):runtime_error(what) {} + }; + struct Unexpected : public std::runtime_error { + Unexpected(const std::string& what):runtime_error(what) {} + }; + + } + +%} + +// Add an explicit handler for Foo::ping, mapping one java exception back to an 'int' +%feature("director:except") MyNS::Foo::ping { + jthrowable $error = jenv->ExceptionOccurred(); + if ($error) { + jenv->ExceptionClear(); // clear java exception since mapping to c++ exception + if (Swig::ExceptionMatches(jenv,$error,"$packagepath/MyNS/MyJavaException1")) { + throw 1; + } else if (Swig::ExceptionMatches(jenv,$error,"$packagepath/MyNS/MyJavaException2")) { + std::string msg(Swig::JavaExceptionMessage(jenv,$error).message()); + throw MyNS::Exception2(msg); + } else { + std::cerr << "Test failed, unexpected exception thrown: " << + Swig::JavaExceptionMessage(jenv,$error).message() << std::endl; + throw std::runtime_error("unexpected exception in Foo::ping"); + } + } +} + +// Use default handler on Foo::pong, with directorthrows typemaps + +// directorthrows typemaps for java->c++ conversions +%typemap(directorthrows) MyNS::Exception1,MyNS::Exception2,MyNS::Unexpected %{ + if (Swig::ExceptionMatches(jenv, $error, "$packagepath/$javaclassname")) { + std::string msg(Swig::JavaExceptionMessage(jenv,$error).message()); + throw $1_type(msg); + } +%} + +// Override the director:except feature so exception specification is not violated +// (Cannot use built-in default of throw DirectorException) +%feature("director:except") MyNS::Foo::pong %{ + jthrowable $error = jenv->ExceptionOccurred(); + if ($error) { + jenv->ExceptionClear(); + $directorthrowshandlers + throw ::MyNS::Unexpected(Swig::JavaExceptionMessage(jenv,$error).message()); + } +%} + +// TODO 'throws' typemap emitted by emit_action (emit.cxx) has no way +// to get access to language specific special variables like +// $javaclassname or $packagepath ("java_director_exception_feature" here) + +// throws typemaps for c++->java exception conversions +%typemap(throws,throws="MyNS.MyJavaException1") MyNS::Exception1 %{ + jclass excpcls = jenv->FindClass("MyNS/MyJavaException1"); + if (excpcls) { + jenv->ThrowNew(excpcls, $1.what()); + } + return $null; +%} + +%typemap(throws,throws="MyNS.MyJavaException1") int %{ + jclass excpcls = jenv->FindClass("MyNS/MyJavaException1"); + if (excpcls) { + jenv->ThrowNew(excpcls, "Threw some integer"); + } + return $null; +%} + +%typemap(throws,throws="MyNS.MyJavaException2") MyNS::Exception2 %{ + jclass excpcls = jenv->FindClass("MyNS/MyJavaException2"); + if (excpcls) { + jenv->ThrowNew(excpcls, $1.what()); + } + return $null; +%} + + +%typemap(throws,throws="MyNS.MyJavaUnexpected") MyNS::Unexpected %{ + jclass excpcls = jenv->FindClass("MyNS/MyJavaUnexpected"); + if (excpcls) { + jenv->ThrowNew(excpcls, $1.what()); + } + return $null; +%} + +// Use generic exception translation approach like python, ruby + +%feature("director:except") MyNS::Foo::genericpong { + jthrowable $error = jenv->ExceptionOccurred(); + if ($error) { + jenv->ExceptionClear(); + throw Swig::DirectorException(jenv,$error); + } +} + +// %exception with throws attribute. Need throws attribute for checked exceptions +%feature ("except",throws="Exception") MyNS::Foo::genericpong %{ +%} + +%feature ("except",throws="Exception") MyNS::Bar::genericpong %{ + try { $action } + catch (Swig::DirectorException & direxcp) { + direxcp.raiseJavaException(jenv); // jenv always available in JNI code + return $null; + } +%} + + + +%feature("director") Foo; + +// Rename exceptions on java side to make translation of exceptions more clear +%rename(MyJavaException1,fullname=1) MyNS::Exception1; +%rename(MyJavaException2,fullname=1) MyNS::Exception2; +%rename(MyJavaUnexpected,fullname=1) MyNS::Unexpected; + +%typemap(javabase) ::MyNS::Exception1,::MyNS::Exception2,::MyNS::Unexpected "java.lang.Exception"; +%rename(getMessage) what(); // Rename all what() methods + +namespace MyNS { + + struct Exception1 { + Exception1(const std::string& what); + const char * what(); + }; + struct Exception2 { + Exception2(const std::string& what); + const char * what(); + }; + struct Unexpected { + Unexpected(const std::string& what); + const char * what(); + }; + +} +// In general it is better to use %catches instead of an exception specification on the method +// since violating an exception specification calls terminate() preventing catch-all behavior +// like throwing std::runtime_error. But an exception specification must be used if the +// actual interface being wrapped does use them. +%catches(MyNS::Exception1,MyNS::Exception2,MyNS::Unexpected) MyNS::Foo::pong; +%catches(MyNS::Exception1,MyNS::Exception2,MyNS::Unexpected) MyNS::Bar::pong; + +%inline %{ + +namespace MyNS { + +class Foo { +public: + virtual ~Foo() {} + // ping java implementation throws a java Exception1 or an Exception2 if excp is 1 or 2. + // pong java implementation throws Exception1,Exception2,Unexpected,NullPointerException for 1,2,3,4 + virtual std::string ping(int excp) throw(int,MyNS::Exception2) = 0; + virtual std::string pong(int excp) /* throws MyNS::Exception1 MyNS::Exception2 MyNS::Unexpected) */ = 0; + virtual std::string genericpong(int excp) /* unspecified throws - exception is always DirectorException in C++, translated back to whatever thrown in java */ = 0; +}; + +// Make a bar from a foo, so a call to Java Bar +// goes Java Bar -> C++ Bar -> C++ Foo -> Java Foo Director + +class Bar { +public: + Bar(Foo* d) { delegate=d; } + virtual std::string ping(int excp) throw(int,MyNS::Exception2) + { + return delegate->ping(excp); + } + + virtual std::string pong(int excp) /* throws MyNS::Exception1,MyNS::Exception2,MyNS::Unexpected */ + { + return delegate->pong(excp); + } + + virtual std::string genericpong(int excp) + { + return delegate->genericpong(excp); + } + +private: + Foo * delegate; +}; + +} +%} diff --git a/Lib/java/director.swg b/Lib/java/director.swg index f32fda350..8c7dca294 100644 --- a/Lib/java/director.swg +++ b/Lib/java/director.swg @@ -193,6 +193,242 @@ namespace Swig { }; } + +// Default exception handler for all director methods. +// Can override this for specific methods +// This just documents the default. It is not actually attached as a feature +// for efficiency reasons (and is defined in java.cxx) It can be overridden +// as a feature for specific methods or globally. + +//%feature("director:except") %{ +// jthrowable $error = jenv->ExceptionOccurred(); +// if ($error) { +// jenv->ExceptionClear(); +// $directorthrowshandlers +// throw Swig::DirectorException(jenv, $error); +// } +//%} + +// Define some utility methods and classes. Cannot use fragments since +// these may be used by %features and in directorthrows typemaps + +#include + +// Simple holder for exception messages, allowing access to a c-style string +namespace Swig { + struct JavaString { + JavaString(JNIEnv * jenv, jstring jstr):jenv_(jenv), jstr_(jstr), cstr_(0) { + if (jenv_ && jstr_) { + // Get the null-terminated c-string out, and hold it + cstr_ = (const char *) jenv_->GetStringUTFChars(jstr_, NULL); + } + } + ~JavaString() { + if (jenv_ && jstr_ && cstr_) { + jenv_->ReleaseStringUTFChars(jstr_, cstr_); + } + } + const char *cstr() { + return cstr_ ? cstr_ : ""; + } + + private: + JNIEnv * jenv_; + jstring jstr_; + const char * cstr_; + + // non-copyable + JavaString(const JavaString &); + JavaString & operator=(const JavaString &); + }; + + struct JavaExceptionMessage { + JavaExceptionMessage(JNIEnv * jenv, jthrowable excp) : + jstrholder_(jenv,exceptionMsgJstr(jenv,excp)) { + } + ~JavaExceptionMessage() { + } + const char *message() { + return jstrholder_.cstr(); + } + + private: + JavaString jstrholder_; + + // non-copyable + JavaExceptionMessage(const JavaExceptionMessage &); + JavaExceptionMessage & operator=(const JavaExceptionMessage &); + + // Static method to initialize jstrholder_ + static jstring exceptionMsgJstr(JNIEnv * jenv, jthrowable excp) { + jstring jmsg = NULL; + if (jenv && excp) { + jenv->ExceptionClear(); // Cannot invoke methods with pending exception + jclass thrwclz = jenv->GetObjectClass(excp); + if (thrwclz) { + // if no getMessage() or other exception, no msg available. + jmethodID getThrowableMsgMethodID = + jenv->GetMethodID(thrwclz, "getMessage", "()Ljava/lang/String;"); + if (getThrowableMsgMethodID && !jenv->ExceptionCheck()) { + // if problem accessing exception message string, no msg available. + jmsg = (jstring) + jenv->CallObjectMethod(excp, getThrowableMsgMethodID); + } + } + if (jmsg == NULL && jenv->ExceptionCheck()) { + jenv->ExceptionClear(); + } + } + return jmsg; + } + }; + + + //////////////////////////////////// + + bool ExceptionMatches(JNIEnv * jenv, jthrowable excp, + const char *clzname) { + jboolean matches = false; + + if (excp && jenv && clzname) { + // Have to clear exceptions for correct behavior. Code around + // ExceptionMatches should restore pending exception if + // desired - already have throwable. + jenv->ExceptionClear(); + + jclass clz = jenv->FindClass(clzname); + if (clz && ! jenv->ExceptionCheck()) { + jclass classclz = jenv->GetObjectClass(clz); + jmethodID isInstanceMethodID = + jenv->GetMethodID(classclz, "isInstance", "(Ljava/lang/Object;)Z"); + if (isInstanceMethodID) { + matches = (jboolean) + jenv->CallBooleanMethod(clz, isInstanceMethodID, excp); + } + } + // This may happen if user typemaps or director:except + // features call ExceptionMatches incorrectly, typically with + // an invalid clzname argument. Uncommenting the debug lines + // may help to diagnose. + // As is, this leaves the underlying case as a pending exception + // which may not be that clear (e.g. ClassNotFoundException) + + // if (jenv->ExceptionCheck()) { + // JavaExceptionMessage jstrmsg(jenv,jenv->ExceptionOccurred()); + // std::cerr << "Error: ExceptionMatches: class '" << + // clzname << "' : " << jstrmsg.message() << std::endl; + // } + } + return matches; + } + + // Provide the class name to allow reconstruction of the original exception + struct DirectorException : std::exception { + + // Construct a DirectorException from a java throwable + DirectorException(JNIEnv* jenv,jthrowable excp) : classname_(0), msg_(0) { + jstring jstr_classname = NULL; + jmethodID mid_getName = NULL; + jclass thrwclz; + jclass clzclz; + + if (excp) { + // Get the exception class, like Exception + thrwclz = jenv->GetObjectClass(excp); + if (thrwclz) { + // Get the java.lang.Class class + clzclz = jenv->GetObjectClass(thrwclz); + if (clzclz) { + mid_getName = jenv->GetMethodID(clzclz, "getName", "()Ljava/lang/String;"); + if (mid_getName) { + // Get the excp class name + jstr_classname = (jstring)(jenv->CallObjectMethod(thrwclz, mid_getName)); + } + } + } + } + // Copy strings, since no guarantee jenv will be active when handled + // If classname_ is 0, returned as "UnknownException" + if (jstr_classname) { + JavaString classname(jenv, jstr_classname); + classname_ = copypath(classname.cstr()); + } + JavaExceptionMessage exceptionmsg(jenv, excp); + msg_ = copystr(exceptionmsg.message()); + } + + // Throw as a wrapped Runtime Error explicitly. + DirectorException(const char * msg) : classname_(0), msg_(0) { + classname_ = copypath("java/lang/RuntimeError"); + msg_ = copystr(msg); + } + + ~DirectorException() throw() { + delete[] classname_; + delete[] msg_; + } + + // If there was problem finding classname, keep track of error + // On raiseJavaException will be mapped to a RuntimeException + const char* classname() const throw() { + return classname_ ? classname_ : "UnknownException"; + } + const char* what() const throw() { + return msg_ ? msg_ : ""; + } + + // Python director code provides static raise() methods + // Omitted here: Seems less good than + // throw DirectorException(jenv, excp) + // from which compiler can infer a C++ exception is thrown. + + // Reconstruct and raise the Java Exception that caused the DirectorException + void raiseJavaException(JNIEnv* jenv) { + if (jenv) { + jenv->ExceptionClear(); + + jmethodID strCtorID = 0; + + jclass excpclz = jenv->FindClass(classname()); + + if (excpclz) { + strCtorID = jenv->GetMethodID(excpclz,"","(Ljava/lang/String;)V"); + } + + if (strCtorID) { + // If exception has a string constructor, throw an instance + jenv->ThrowNew(excpclz, what()); + } else { + // Else, throw a runtime + SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, what() ); + } + } + } + + private: + const char * classname_; + const char * msg_; + + static const char * copypath(const char * srcmsg) { + return copystr(srcmsg, 1); + } + static const char * copystr(const char * srcmsg, int pathrepl=0) { + char * target = 0; + if (srcmsg) { + int msglen = 1+strlen(srcmsg); //+1 for null terminator + target = new char[msglen]; + strncpy(target, srcmsg, msglen); + } + // If pathrepl, replace any '.' with '/' + if (pathrepl) { + for(char *c=target; *c; ++c) { + if ('.' == *c) *c = '/'; + } + } + return target; + } + }; + +} + #endif /* __cplusplus */ - - diff --git a/Lib/java/std_string.i b/Lib/java/std_string.i index f178e6d43..6b9cb90a4 100644 --- a/Lib/java/std_string.i +++ b/Lib/java/std_string.i @@ -38,7 +38,8 @@ class string; %typemap(directorout) string %{ if(!$input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); + if (!jenv->ExceptionCheck()) + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); return $null; } const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0); diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index 4856d9e44..65ff70dd9 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -176,6 +176,7 @@ #define WARN_TYPEMAP_OUT_OPTIMAL_IGNORED 474 #define WARN_TYPEMAP_OUT_OPTIMAL_MULTIPLE 475 #define WARN_TYPEMAP_INITIALIZER_LIST 476 +#define WARN_TYPEMAP_DIRECTORTHROWS_UNDEF 477 /* -- Fragments -- */ #define WARN_FRAGMENT_NOT_FOUND 490 diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 24435ac30..acc46c15e 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -742,15 +742,25 @@ public: *----------------------------------------------------------------------*/ UpcallData *addUpcallMethod(String *imclass_method, String *class_method, String *imclass_desc, String *class_desc, String *decl) { + UpcallData *udata; + String *imclass_methodidx; + String *class_methodidx; + Hash *new_udata; String *key = NewStringf("%s|%s", imclass_method, decl); ++curr_class_dmethod; - String *imclass_methodidx = NewStringf("%d", n_dmethods); - String *class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod); + /* Do we know about this director class already? */ + if ((udata = Getattr(dmethods_table, key))) { + Delete(key); + return Getattr(udata, "methodoff"); + } + + imclass_methodidx = NewStringf("%d", n_dmethods); + class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod); n_dmethods++; - Hash *new_udata = NewHash(); + new_udata = NewHash(); Append(dmethods_seq, new_udata); Setattr(dmethods_table, key, new_udata); @@ -2939,20 +2949,36 @@ public: * pt - parameter type * tm - typemap contents that might contain the special variable to be replaced * jnidescriptor - if set, inner class names are separated with '$' otherwise a '.' + * p - a parameter type, that may hold a javapackage typemap. If passed, + * the $packagepath will be substituted, but call method below instead. * Outputs: * tm - typemap contents complete with the special variable substitution * Return: * substitution_performed - flag indicating if a substitution was performed * ----------------------------------------------------------------------------- */ - bool substituteClassname(SwigType *pt, String *tm, bool jnidescriptor = false) { + bool substituteClassname(SwigType *pt, String *tm, + bool jnidescriptor = false, Parm * pkgpathparm = 0) + { + return substituteClassnameAndPackagePath( pt, tm, jnidescriptor, pkgpathparm); + } + + /* ----------------------------------------------------------------------------- + * substituteClassnameAndPackagePath() + * Used to canonicalize JNI descriptors, including code emitting director throws typemaps. + * + * Only usage always has jnidescriptor AND p set. Maybe collapse args. + * ----------------------------------------------------------------------------- */ + bool substituteClassnameAndPackagePath(SwigType *pt, String *tm, + bool jnidescriptor, Parm * pkgpathparm) + { bool substitution_performed = false; SwigType *type = Copy(SwigType_typedef_resolve_all(pt)); SwigType *strippedtype = SwigType_strip_qualifiers(type); if (Strstr(tm, "$javaclassname")) { SwigType *classnametype = Copy(strippedtype); - substituteClassnameSpecialVariable(classnametype, tm, "$javaclassname", jnidescriptor); + substituteClassnameSpecialVariable(classnametype, tm, "$javaclassname", jnidescriptor, pkgpathparm); substitution_performed = true; Delete(classnametype); } @@ -2960,7 +2986,7 @@ public: SwigType *classnametype = Copy(strippedtype); Delete(SwigType_pop(classnametype)); if (Len(classnametype) > 0) { - substituteClassnameSpecialVariable(classnametype, tm, "$*javaclassname", jnidescriptor); + substituteClassnameSpecialVariable(classnametype, tm, "$*javaclassname", jnidescriptor, pkgpathparm); substitution_performed = true; } Delete(classnametype); @@ -2968,7 +2994,7 @@ public: if (Strstr(tm, "$&javaclassname")) { SwigType *classnametype = Copy(strippedtype); SwigType_add_pointer(classnametype); - substituteClassnameSpecialVariable(classnametype, tm, "$&javaclassname", jnidescriptor); + substituteClassnameSpecialVariable(classnametype, tm, "$&javaclassname", jnidescriptor, pkgpathparm); substitution_performed = true; Delete(classnametype); } @@ -2982,27 +3008,46 @@ public: /* ----------------------------------------------------------------------------- * substituteClassnameSpecialVariable() * ----------------------------------------------------------------------------- */ + void substituteClassnameSpecialVariable(SwigType *classnametype, String *tm, const char *classnamespecialvariable, bool jnidescriptor, Parm * pkgpathparm) { + String * replacementname; - void substituteClassnameSpecialVariable(SwigType *classnametype, String *tm, const char *classnamespecialvariable, bool jnidescriptor) { if (SwigType_isenum(classnametype)) { - String *enumname = getEnumName(classnametype, jnidescriptor); - if (enumname) - Replaceall(tm, classnamespecialvariable, enumname); - else - Replaceall(tm, classnamespecialvariable, NewStringf("int")); + replacementname = Copy(getEnumName(classnametype, jnidescriptor)); + if (!replacementname) { + replacementname = NewString("int"); + } } else { - String *classname = getProxyName(classnametype); - if (classname) { - Replaceall(tm, classnamespecialvariable, classname); // getProxyName() works for pointers to classes too - } else { // use $descriptor if SWIG does not know anything about this type. Note that any typedefs are resolved. - String *descriptor = NewStringf("SWIGTYPE%s", SwigType_manglestr(classnametype)); - Replaceall(tm, classnamespecialvariable, descriptor); - + replacementname = Copy(getProxyName(classnametype)); + if (! replacementname) { + // use $descriptor if SWIG does not know anything about this type. Note that any typedefs are resolved. + replacementname = NewStringf("SWIGTYPE%s", SwigType_manglestr(classnametype)); // Add to hash table so that the type wrapper classes can be created later - Setattr(swig_types_hash, descriptor, classnametype); - Delete(descriptor); + Setattr(swig_types_hash, replacementname, classnametype); } } + + if (pkgpathparm) { + if (Strchr(replacementname, '.') != NULL) { + // nspace feature in use, indicated by dots (!?) + // if replacementname is in name space form, a.b.c, discard + // packagepath from any string like $packagepath/$javaclassname + // since IT WAS ADDED in getProxyName + // But $packagepath could still be used by itself in same string + // since this is used to emit general code blocks for director + // exceptions + // So do this to get rid of all combined forms before subsitituting + Replaceall(tm, "$packagepath/$javaclassname","$javaclassname"); + Replaceall(tm, "$packagepath/$*javaclassname","$*javaclassname"); + Replaceall(tm, "$packagepath/$&javaclassname","$&javaclassname"); + } + substitutePackagePath(tm, pkgpathparm); + } + if (jnidescriptor) { + Replaceall(replacementname,".","/"); + } + Replaceall(tm, classnamespecialvariable, replacementname); + + Delete(replacementname); } /* ----------------------------------------------------------------------------- @@ -3497,11 +3542,32 @@ public: // Delete(method_attr); } + /** Replace $packagepath using the javapackage typemap + associated with passed parm or global package_path + if none. "$packagepath/" is replaced with "" if no + package path is set. + */ + void substitutePackagePath(String *text, Parm *p) { + String *pkg_path= 0; + + if (p) + pkg_path = Swig_typemap_lookup("javapackage", p, "", 0); + if (!pkg_path || Len(pkg_path) == 0) + pkg_path = package_path; + + if (Len(pkg_path) > 0) { + Replaceall(text, "$packagepath", pkg_path); + } else { + Replaceall(text, "$packagepath/", empty_string); + Replaceall(text, "$packagepath", empty_string); + } + } + /* --------------------------------------------------------------- * Canonicalize the JNI field descriptor * - * Replace the $javapackage and $javaclassname family of special - * variables with the desired package and Java proxy name as + * Replace the $packagepath and $javaclassname family of + * variables with the desired package and Java descriptor as * required in the JNI field descriptors. * * !!SFM!! If $packagepath occurs in the field descriptor, but @@ -3511,27 +3577,11 @@ public: * --------------------------------------------------------------- */ String *canonicalizeJNIDescriptor(String *descriptor_in, Parm *p) { - String *pkg_path = Swig_typemap_lookup("javapackage", p, "", 0); SwigType *type = Getattr(p, "type"); - if (!pkg_path || Len(pkg_path) == 0) - pkg_path = package_path; - String *descriptor_out = Copy(descriptor_in); - - substituteClassname(type, descriptor_out, true); - - if (Len(pkg_path) > 0 && Strchr(descriptor_out, '.') == NULL) { - Replaceall(descriptor_out, "$packagepath", pkg_path); - } else { - Replaceall(descriptor_out, "$packagepath/", empty_string); - Replaceall(descriptor_out, "$packagepath", empty_string); - } - - Replaceall(descriptor_out, ".", "/"); - - if (pkg_path != package_path) - Delete(pkg_path); + // This returns a JNI descriptor, in path format + substituteClassnameAndPackagePath(type, descriptor_out, true, p); return descriptor_out; } @@ -3928,17 +3978,33 @@ public: // Get any Java exception classes in the throws typemap ParmList *throw_parm_list = NULL; + // May need to add throws to director classes if %catches defined + // Get any Java exception classes in the throws typemap + ParmList *catches_list = Getattr(n, "catchlist"); + if (catches_list) { + Swig_typemap_attach_parms("throws", catches_list, 0); + Swig_typemap_attach_parms("directorthrows", catches_list, 0); + for (p = catches_list; p; p = nextSibling(p)) { + addThrows(n, "tmap:throws", p); + } + } + if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) { int gencomma = 0; Append(w->def, " throw("); Append(declaration, " throw("); - if (throw_parm_list) + if (throw_parm_list) { Swig_typemap_attach_parms("throws", throw_parm_list, 0); + Swig_typemap_attach_parms("directorthrows", throw_parm_list, 0); + } for (p = throw_parm_list; p; p = nextSibling(p)) { if (Getattr(p, "tmap:throws")) { - addThrows(n, "tmap:throws", p); + // If %catches feature, it overrides specified throws(). + if (! catches_list) { + addThrows(n, "tmap:throws", p); + } if (gencomma++) { Append(w->def, ", "); @@ -4001,7 +4067,8 @@ public: Printf(w->code, "jenv->%s(Swig::jclass_%s, Swig::director_methids[%s], %s);\n", methop, imclass_name, methid, jupcall_args); - Printf(w->code, "if (jenv->ExceptionCheck() == JNI_TRUE) return $null;\n"); + // Generate code to handle any java exception thrown by director delegation + directorExceptHandler(n, catches_list?catches_list:throw_parm_list, w, c_classname, name); if (!is_void) { String *jresult_str = NewString("jresult"); @@ -4042,7 +4109,8 @@ public: /* Terminate wrapper code */ Printf(w->code, "} else {\n"); - Printf(w->code, "SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, \"null upcall object\");\n"); + Printf(w->code, "SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, \"null upcall object in %s::%s \");\n", + SwigType_namestr(c_classname), SwigType_namestr(name)); Printf(w->code, "}\n"); Printf(w->code, "if (swigjobj) jenv->DeleteLocalRef(swigjobj);\n"); @@ -4098,6 +4166,79 @@ public: return status; } + /* ------------------------------------------------------------ + * directorExcept handler: Emit code to map java exceptions + * back to C++ exceptions when feature("director:except") is appied + * to a method node + * ------------------------------------------------------------ */ + void directorExceptHandler(Node *n, ParmList *throw_parm_list, Wrapper *w, String *c_classname, String *name) { + // After director java method call, allow code for director method exception to be added + // Look for director:exceptfeature + Parm *p; + + // "Default" feature, so that feature is not applied to every node, per W. Fulton + static char const * DEFAULT_DIREXCP_FEATURE = + "jthrowable $error = jenv->ExceptionOccurred();\n" + "if ($error) {\n" + " jenv->ExceptionClear();\n" + " $directorthrowshandlers\n" + " throw Swig::DirectorException(jenv, $error);\n" + "}\n"; + + String * featdirexcp = Getattr(n, "feature:director:except"); + + if (!featdirexcp) { + featdirexcp = NewString(DEFAULT_DIREXCP_FEATURE); + } else { + featdirexcp = Copy(featdirexcp); + } + // Can explicitly disable director:except by setting to "" or "0" + if (0 != Len(featdirexcp) && 0 != Cmp(featdirexcp,"0")) { + + // Replace any $packagepath with global -package package_path + substitutePackagePath(featdirexcp, 0); + + // Replace $action with any defined typemap handlers (or nothing) + if (Strstr(featdirexcp, "$directorthrowshandlers")) { + String *directorthrowshandlers_code = NewString(""); + + for (p = throw_parm_list; p; p = nextSibling(p)) { + String *tmapdirthrows = Getattr(p, "tmap:directorthrows"); + String * excptype = Getattr(p,"type"); + + if (!tmapdirthrows) { + Swig_warning(WARN_TYPEMAP_DIRECTORTHROWS_UNDEF, input_file, line_number, + "Feature director:except on %s::%s with $directorthrowshandlers requires directorthrows typemap for exception %s.\n", + SwigType_namestr(c_classname),SwigType_namestr(name), excptype); + } else { + // replace $packagepath + tmapdirthrows = Copy(tmapdirthrows); + substituteClassnameAndPackagePath(excptype, tmapdirthrows, true, p); + + Printf(directorthrowshandlers_code, + "// Handle exception %s using directorthrows typemap\n" + "%s", + excptype, tmapdirthrows); + Delete(tmapdirthrows); + } + } + // Delete extra new line if no handlers. + while (Replaceall(featdirexcp, "$directorthrowshandlers ", + "$directorthrowshandlers")) {} + if (0 == Len(directorthrowshandlers_code)) + Replaceall(featdirexcp, "$directorthrowshandlers\n", ""); + else + Replaceall(featdirexcp, "$directorthrowshandlers", directorthrowshandlers_code); + Delete(directorthrowshandlers_code); + } + + // Replace all occurrences of $error with common var name. + Replaceall(featdirexcp, "$error", "thrown_"); + Printf(w->code, " %s\n", featdirexcp); + } + Delete(featdirexcp); + } + /* ------------------------------------------------------------ * directorPrefixArgs() * ------------------------------------------------------------ */ From 9237c4553c93f9e0d265b483e63486da8c49f31e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 23 Oct 2013 18:26:41 +0100 Subject: [PATCH 0746/1160] Code style conforming channges for Java director:except patch --- Source/Modules/java.cxx | 100 ++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 54 deletions(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index acc46c15e..40c60e4da 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -742,25 +742,22 @@ public: *----------------------------------------------------------------------*/ UpcallData *addUpcallMethod(String *imclass_method, String *class_method, String *imclass_desc, String *class_desc, String *decl) { - UpcallData *udata; - String *imclass_methodidx; - String *class_methodidx; - Hash *new_udata; String *key = NewStringf("%s|%s", imclass_method, decl); ++curr_class_dmethod; /* Do we know about this director class already? */ - if ((udata = Getattr(dmethods_table, key))) { + UpcallData *udata = Getattr(dmethods_table, key); + if (udata) { Delete(key); return Getattr(udata, "methodoff"); } - imclass_methodidx = NewStringf("%d", n_dmethods); - class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod); + String *imclass_methodidx = NewStringf("%d", n_dmethods); + String *class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod); n_dmethods++; - new_udata = NewHash(); + Hash *new_udata = NewHash(); Append(dmethods_seq, new_udata); Setattr(dmethods_table, key, new_udata); @@ -2957,9 +2954,7 @@ public: * substitution_performed - flag indicating if a substitution was performed * ----------------------------------------------------------------------------- */ - bool substituteClassname(SwigType *pt, String *tm, - bool jnidescriptor = false, Parm * pkgpathparm = 0) - { + bool substituteClassname(SwigType *pt, String *tm, bool jnidescriptor = false, Parm *pkgpathparm = 0) { return substituteClassnameAndPackagePath( pt, tm, jnidescriptor, pkgpathparm); } @@ -2969,9 +2964,8 @@ public: * * Only usage always has jnidescriptor AND p set. Maybe collapse args. * ----------------------------------------------------------------------------- */ - bool substituteClassnameAndPackagePath(SwigType *pt, String *tm, - bool jnidescriptor, Parm * pkgpathparm) - { + + bool substituteClassnameAndPackagePath(SwigType *pt, String *tm, bool jnidescriptor, Parm *pkgpathparm) { bool substitution_performed = false; SwigType *type = Copy(SwigType_typedef_resolve_all(pt)); SwigType *strippedtype = SwigType_strip_qualifiers(type); @@ -3008,6 +3002,7 @@ public: /* ----------------------------------------------------------------------------- * substituteClassnameSpecialVariable() * ----------------------------------------------------------------------------- */ + void substituteClassnameSpecialVariable(SwigType *classnametype, String *tm, const char *classnamespecialvariable, bool jnidescriptor, Parm * pkgpathparm) { String * replacementname; @@ -3042,9 +3037,8 @@ public: } substitutePackagePath(tm, pkgpathparm); } - if (jnidescriptor) { + if (jnidescriptor) Replaceall(replacementname,".","/"); - } Replaceall(tm, classnamespecialvariable, replacementname); Delete(replacementname); @@ -3542,11 +3536,14 @@ public: // Delete(method_attr); } - /** Replace $packagepath using the javapackage typemap - associated with passed parm or global package_path - if none. "$packagepath/" is replaced with "" if no - package path is set. - */ + /* ----------------------------------------------------------------------------- + * substitutePackagePath() + * + * Replace $packagepath using the javapackage typemap associated with passed + * parm or global package_path if none. "$packagepath/" is replaced with "" if + * no package path is set. + * ----------------------------------------------------------------------------- */ + void substitutePackagePath(String *text, Parm *p) { String *pkg_path= 0; @@ -4002,7 +3999,7 @@ public: for (p = throw_parm_list; p; p = nextSibling(p)) { if (Getattr(p, "tmap:throws")) { // If %catches feature, it overrides specified throws(). - if (! catches_list) { + if (!catches_list) { addThrows(n, "tmap:throws", p); } @@ -4067,8 +4064,8 @@ public: Printf(w->code, "jenv->%s(Swig::jclass_%s, Swig::director_methids[%s], %s);\n", methop, imclass_name, methid, jupcall_args); - // Generate code to handle any java exception thrown by director delegation - directorExceptHandler(n, catches_list?catches_list:throw_parm_list, w, c_classname, name); + // Generate code to handle any Java exception thrown by director delegation + directorExceptHandler(n, catches_list ? catches_list : throw_parm_list, w, c_classname, name); if (!is_void) { String *jresult_str = NewString("jresult"); @@ -4167,44 +4164,42 @@ public: } /* ------------------------------------------------------------ - * directorExcept handler: Emit code to map java exceptions - * back to C++ exceptions when feature("director:except") is appied - * to a method node + * directorExceptHandler() + * + * Emit code to map Java exceptions back to C++ exceptions when + * feature("director:except") is applied to a method node * ------------------------------------------------------------ */ + void directorExceptHandler(Node *n, ParmList *throw_parm_list, Wrapper *w, String *c_classname, String *name) { - // After director java method call, allow code for director method exception to be added + // After director Java method call, allow code for director method exception to be added // Look for director:exceptfeature - Parm *p; - - // "Default" feature, so that feature is not applied to every node, per W. Fulton - static char const * DEFAULT_DIREXCP_FEATURE = - "jthrowable $error = jenv->ExceptionOccurred();\n" - "if ($error) {\n" - " jenv->ExceptionClear();\n" - " $directorthrowshandlers\n" - " throw Swig::DirectorException(jenv, $error);\n" - "}\n"; - - String * featdirexcp = Getattr(n, "feature:director:except"); + String *featdirexcp = Getattr(n, "feature:director:except"); if (!featdirexcp) { - featdirexcp = NewString(DEFAULT_DIREXCP_FEATURE); + featdirexcp = NewString(""); + Printf(featdirexcp, "jthrowable $error = jenv->ExceptionOccurred();\n"); + Printf(featdirexcp, "if ($error) {\n"); + Printf(featdirexcp, " jenv->ExceptionClear();\n"); + Printf(featdirexcp, " $directorthrowshandlers\n"); + Printf(featdirexcp, " throw Swig::DirectorException(jenv, $error);\n"); + Printf(featdirexcp, "}\n"); } else { featdirexcp = Copy(featdirexcp); } - // Can explicitly disable director:except by setting to "" or "0" - if (0 != Len(featdirexcp) && 0 != Cmp(featdirexcp,"0")) { - // Replace any $packagepath with global -package package_path + // Can explicitly disable director:except by setting to "" or "0" + if (Len(featdirexcp) != 0 && Cmp(featdirexcp, "0") != 0) { + + // Replace $packagepath substitutePackagePath(featdirexcp, 0); - // Replace $action with any defined typemap handlers (or nothing) + // Replace $directorthrowshandlers with any defined typemap handlers (or nothing) if (Strstr(featdirexcp, "$directorthrowshandlers")) { String *directorthrowshandlers_code = NewString(""); - for (p = throw_parm_list; p; p = nextSibling(p)) { + for (Parm *p = throw_parm_list; p; p = nextSibling(p)) { String *tmapdirthrows = Getattr(p, "tmap:directorthrows"); - String * excptype = Getattr(p,"type"); + String *excptype = Getattr(p,"type"); if (!tmapdirthrows) { Swig_warning(WARN_TYPEMAP_DIRECTORTHROWS_UNDEF, input_file, line_number, @@ -4215,17 +4210,14 @@ public: tmapdirthrows = Copy(tmapdirthrows); substituteClassnameAndPackagePath(excptype, tmapdirthrows, true, p); - Printf(directorthrowshandlers_code, - "// Handle exception %s using directorthrows typemap\n" - "%s", - excptype, tmapdirthrows); + Printf(directorthrowshandlers_code, "// Handle exception %s using directorthrows typemap\n" "%s", excptype, tmapdirthrows); Delete(tmapdirthrows); } } // Delete extra new line if no handlers. - while (Replaceall(featdirexcp, "$directorthrowshandlers ", - "$directorthrowshandlers")) {} - if (0 == Len(directorthrowshandlers_code)) + while (Replaceall(featdirexcp, "$directorthrowshandlers ", "$directorthrowshandlers")) { + } + if (Len(directorthrowshandlers_code) == 0) Replaceall(featdirexcp, "$directorthrowshandlers\n", ""); else Replaceall(featdirexcp, "$directorthrowshandlers", directorthrowshandlers_code); From 97fd20a58d8273cb2097d7661ddde70ccf426cac Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 23 Oct 2013 18:43:13 +0100 Subject: [PATCH 0747/1160] Minor improvements to Java director:except patch --- Lib/java/std_string.i | 3 ++- Source/Modules/java.cxx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/java/std_string.i b/Lib/java/std_string.i index 6b9cb90a4..5ad7d30bc 100644 --- a/Lib/java/std_string.i +++ b/Lib/java/std_string.i @@ -38,8 +38,9 @@ class string; %typemap(directorout) string %{ if(!$input) { - if (!jenv->ExceptionCheck()) + if (!jenv->ExceptionCheck()) { SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); + } return $null; } const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 40c60e4da..ab15b371f 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -4225,7 +4225,7 @@ public: } // Replace all occurrences of $error with common var name. - Replaceall(featdirexcp, "$error", "thrown_"); + Replaceall(featdirexcp, "$error", "swigerror"); Printf(w->code, " %s\n", featdirexcp); } Delete(featdirexcp); From f55e0092efd6073542b7669381a751b3c7c7a60f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 23 Oct 2013 18:43:36 +0100 Subject: [PATCH 0748/1160] Remove pointless code from Java director:except patch --- Source/Modules/java.cxx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index ab15b371f..a68b3f32b 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -746,13 +746,6 @@ public: ++curr_class_dmethod; - /* Do we know about this director class already? */ - UpcallData *udata = Getattr(dmethods_table, key); - if (udata) { - Delete(key); - return Getattr(udata, "methodoff"); - } - String *imclass_methodidx = NewStringf("%d", n_dmethods); String *class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod); n_dmethods++; From 88678ed492f1c8c163c52059945b7cb1db30d19c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Oct 2013 07:06:55 +0100 Subject: [PATCH 0749/1160] director:except tweaks Recode whitespace handling, remove unnecessary comments in generated code. --- Source/Modules/java.cxx | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index a68b3f32b..a0b094e34 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -4160,20 +4160,18 @@ public: * directorExceptHandler() * * Emit code to map Java exceptions back to C++ exceptions when - * feature("director:except") is applied to a method node + * feature("director:except") is applied to a method node. + * This is generated after the Java method upcall. * ------------------------------------------------------------ */ void directorExceptHandler(Node *n, ParmList *throw_parm_list, Wrapper *w, String *c_classname, String *name) { - // After director Java method call, allow code for director method exception to be added - // Look for director:exceptfeature String *featdirexcp = Getattr(n, "feature:director:except"); if (!featdirexcp) { featdirexcp = NewString(""); Printf(featdirexcp, "jthrowable $error = jenv->ExceptionOccurred();\n"); Printf(featdirexcp, "if ($error) {\n"); - Printf(featdirexcp, " jenv->ExceptionClear();\n"); - Printf(featdirexcp, " $directorthrowshandlers\n"); + Printf(featdirexcp, " jenv->ExceptionClear();$directorthrowshandlers\n"); Printf(featdirexcp, " throw Swig::DirectorException(jenv, $error);\n"); Printf(featdirexcp, "}\n"); } else { @@ -4181,7 +4179,7 @@ public: } // Can explicitly disable director:except by setting to "" or "0" - if (Len(featdirexcp) != 0 && Cmp(featdirexcp, "0") != 0) { + if (Len(featdirexcp) > 0 && Cmp(featdirexcp, "0") != 0) { // Replace $packagepath substitutePackagePath(featdirexcp, 0); @@ -4202,22 +4200,14 @@ public: // replace $packagepath tmapdirthrows = Copy(tmapdirthrows); substituteClassnameAndPackagePath(excptype, tmapdirthrows, true, p); - - Printf(directorthrowshandlers_code, "// Handle exception %s using directorthrows typemap\n" "%s", excptype, tmapdirthrows); + Printv(directorthrowshandlers_code, tmapdirthrows, NIL); Delete(tmapdirthrows); } } - // Delete extra new line if no handlers. - while (Replaceall(featdirexcp, "$directorthrowshandlers ", "$directorthrowshandlers")) { - } - if (Len(directorthrowshandlers_code) == 0) - Replaceall(featdirexcp, "$directorthrowshandlers\n", ""); - else - Replaceall(featdirexcp, "$directorthrowshandlers", directorthrowshandlers_code); + Replaceall(featdirexcp, "$directorthrowshandlers", directorthrowshandlers_code); Delete(directorthrowshandlers_code); } - // Replace all occurrences of $error with common var name. Replaceall(featdirexcp, "$error", "swigerror"); Printf(w->code, " %s\n", featdirexcp); } From fc13a24ecb16d26e38c68d9b72dcdcde6611c72d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Oct 2013 07:45:56 +0100 Subject: [PATCH 0750/1160] directorthrows warning fixes - Fix line number display - now the usual simpler warning message can be displayed for WARN_TYPEMAP_DIRECTORTHROWS_UNDEF - it still points to the problem method. - Use macro names for warning suppression in test. --- .../java_director_exception_feature.i | 3 +++ .../java_director_exception_feature_nspace.i | 2 +- Source/Modules/java.cxx | 24 +++++++++---------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Examples/test-suite/java_director_exception_feature.i b/Examples/test-suite/java_director_exception_feature.i index b649b541d..fc1af7a96 100644 --- a/Examples/test-suite/java_director_exception_feature.i +++ b/Examples/test-suite/java_director_exception_feature.i @@ -2,6 +2,8 @@ %include +%warnfilter(SWIGWARN_TYPEMAP_DIRECTORTHROWS_UNDEF) MyNS::Foo::directorthrows_warning; + %{ #if defined(_MSC_VER) #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) @@ -178,6 +180,7 @@ public: virtual std::string ping(int excp) throw(int,MyNS::Exception2) = 0; virtual std::string pong(int excp) /* throws MyNS::Exception1 MyNS::Exception2 MyNS::Unexpected) */ = 0; virtual std::string genericpong(int excp) /* unspecified throws - exception is always DirectorException in C++, translated back to whatever thrown in java */ = 0; + virtual std::string directorthrows_warning(int excp) throw(double) {} }; // Make a bar from a foo, so a call to Java Bar diff --git a/Examples/test-suite/java_director_exception_feature_nspace.i b/Examples/test-suite/java_director_exception_feature_nspace.i index 8723ef738..1f3d97ad3 100644 --- a/Examples/test-suite/java_director_exception_feature_nspace.i +++ b/Examples/test-suite/java_director_exception_feature_nspace.i @@ -6,7 +6,7 @@ // When using namespaces with no -package, must put JNI classes into a namespace %pragma(java) jniclasspackage=%{MyNS_JNI%} -%warnfilter(826); +%warnfilter(SWIGWARN_JAVA_NSPACE_WITHOUT_PACKAGE); %{ #if defined(_MSC_VER) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index a0b094e34..37c3c5afb 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -4058,7 +4058,7 @@ public: Printf(w->code, "jenv->%s(Swig::jclass_%s, Swig::director_methids[%s], %s);\n", methop, imclass_name, methid, jupcall_args); // Generate code to handle any Java exception thrown by director delegation - directorExceptHandler(n, catches_list ? catches_list : throw_parm_list, w, c_classname, name); + directorExceptHandler(n, catches_list ? catches_list : throw_parm_list, w); if (!is_void) { String *jresult_str = NewString("jresult"); @@ -4164,7 +4164,7 @@ public: * This is generated after the Java method upcall. * ------------------------------------------------------------ */ - void directorExceptHandler(Node *n, ParmList *throw_parm_list, Wrapper *w, String *c_classname, String *name) { + void directorExceptHandler(Node *n, ParmList *throw_parm_list, Wrapper *w) { String *featdirexcp = Getattr(n, "feature:director:except"); if (!featdirexcp) { @@ -4189,19 +4189,17 @@ public: String *directorthrowshandlers_code = NewString(""); for (Parm *p = throw_parm_list; p; p = nextSibling(p)) { - String *tmapdirthrows = Getattr(p, "tmap:directorthrows"); - String *excptype = Getattr(p,"type"); + String *tm = Getattr(p, "tmap:directorthrows"); + String *t = Getattr(p,"type"); - if (!tmapdirthrows) { - Swig_warning(WARN_TYPEMAP_DIRECTORTHROWS_UNDEF, input_file, line_number, - "Feature director:except on %s::%s with $directorthrowshandlers requires directorthrows typemap for exception %s.\n", - SwigType_namestr(c_classname),SwigType_namestr(name), excptype); - } else { + if (tm) { + String *directorthrows = Copy(tm); // replace $packagepath - tmapdirthrows = Copy(tmapdirthrows); - substituteClassnameAndPackagePath(excptype, tmapdirthrows, true, p); - Printv(directorthrowshandlers_code, tmapdirthrows, NIL); - Delete(tmapdirthrows); + substituteClassnameAndPackagePath(t, directorthrows, true, p); + Printv(directorthrowshandlers_code, directorthrows, NIL); + Delete(directorthrows); + } else { + Swig_warning(WARN_TYPEMAP_DIRECTORTHROWS_UNDEF, Getfile(n), Getline(n), "No directorthrows typemap defined for %s\n", SwigType_str(t, 0)); } } Replaceall(featdirexcp, "$directorthrowshandlers", directorthrowshandlers_code); From cf4f5e8118021de221390bbb1a03df3a129d8adb Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Oct 2013 08:03:33 +0100 Subject: [PATCH 0751/1160] More conventional variable naming in directorExceptHandling --- Source/Modules/java.cxx | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 37c3c5afb..4a2870505 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -4166,26 +4166,26 @@ public: void directorExceptHandler(Node *n, ParmList *throw_parm_list, Wrapper *w) { - String *featdirexcp = Getattr(n, "feature:director:except"); - if (!featdirexcp) { - featdirexcp = NewString(""); - Printf(featdirexcp, "jthrowable $error = jenv->ExceptionOccurred();\n"); - Printf(featdirexcp, "if ($error) {\n"); - Printf(featdirexcp, " jenv->ExceptionClear();$directorthrowshandlers\n"); - Printf(featdirexcp, " throw Swig::DirectorException(jenv, $error);\n"); - Printf(featdirexcp, "}\n"); + String *directorexcept = Getattr(n, "feature:director:except"); + if (!directorexcept) { + directorexcept = NewString(""); + Printf(directorexcept, "jthrowable $error = jenv->ExceptionOccurred();\n"); + Printf(directorexcept, "if ($error) {\n"); + Printf(directorexcept, " jenv->ExceptionClear();$directorthrowshandlers\n"); + Printf(directorexcept, " throw Swig::DirectorException(jenv, $error);\n"); + Printf(directorexcept, "}\n"); } else { - featdirexcp = Copy(featdirexcp); + directorexcept = Copy(directorexcept); } // Can explicitly disable director:except by setting to "" or "0" - if (Len(featdirexcp) > 0 && Cmp(featdirexcp, "0") != 0) { + if (Len(directorexcept) > 0 && Cmp(directorexcept, "0") != 0) { // Replace $packagepath - substitutePackagePath(featdirexcp, 0); + substitutePackagePath(directorexcept, 0); // Replace $directorthrowshandlers with any defined typemap handlers (or nothing) - if (Strstr(featdirexcp, "$directorthrowshandlers")) { + if (Strstr(directorexcept, "$directorthrowshandlers")) { String *directorthrowshandlers_code = NewString(""); for (Parm *p = throw_parm_list; p; p = nextSibling(p)) { @@ -4202,14 +4202,14 @@ public: Swig_warning(WARN_TYPEMAP_DIRECTORTHROWS_UNDEF, Getfile(n), Getline(n), "No directorthrows typemap defined for %s\n", SwigType_str(t, 0)); } } - Replaceall(featdirexcp, "$directorthrowshandlers", directorthrowshandlers_code); + Replaceall(directorexcept, "$directorthrowshandlers", directorthrowshandlers_code); Delete(directorthrowshandlers_code); } - Replaceall(featdirexcp, "$error", "swigerror"); - Printf(w->code, " %s\n", featdirexcp); + Replaceall(directorexcept, "$error", "swigerror"); + Printf(w->code, " %s\n", directorexcept); } - Delete(featdirexcp); + Delete(directorexcept); } /* ------------------------------------------------------------ From e717ed3056b5f369e28b9a24b41dab3e9b15a0c6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 29 Oct 2013 19:50:13 +0000 Subject: [PATCH 0752/1160] Improve directorthrows patch Separate $packagepath substitution from non-director code (as documented). Some of the directorthrows code has been rewritten so that fewer code changes are present compared to before the patch. canonicalizeJNIDescriptor() refactored so it can be used for general code, not just the directorin:descriptor typemap attribute. Better implementation for substituting '$packagepath/$javaclassname' - fixes some quirks in '$packagepath/$javaclassname' descriptor substitutions if a dot was present in the descriptor string. --- Source/Modules/java.cxx | 112 +++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 66 deletions(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 4a2870505..6576ad544 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -192,28 +192,31 @@ public: * * 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. + * package name if the nspace feature is used, unless jnidescriptor is true as + * the package name is handled differently (unfortunately for legacy reasons). * ----------------------------------------------------------------------------- */ - String *getProxyName(SwigType *t) { + String *getProxyName(SwigType *t, bool jnidescriptor = false) { String *proxyname = NULL; if (proxy_flag) { Node *n = classLookup(t); if (n) { proxyname = Getattr(n, "proxyname"); - if (!proxyname) { + if (!proxyname || jnidescriptor) { String *nspace = Getattr(n, "sym:nspace"); String *symname = Getattr(n, "sym:name"); if (nspace) { - if (package) + if (package && !jnidescriptor) 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); + if (!jnidescriptor) { + Setattr(n, "proxyname", proxyname); // Cache it + Delete(proxyname); + } } } } @@ -2885,6 +2888,7 @@ public: * getEnumName() * * If jnidescriptor is set, inner class names are separated with '$' otherwise a '.' + * and the package is also not added to the name. * ----------------------------------------------------------------------------- */ String *getEnumName(SwigType *t, bool jnidescriptor) { @@ -2899,7 +2903,7 @@ public: String *scopename_prefix = Swig_scopename_prefix(Getattr(n, "name")); String *proxyname = 0; if (scopename_prefix) { - proxyname = getProxyName(scopename_prefix); + proxyname = getProxyName(scopename_prefix, jnidescriptor); } if (proxyname) { const char *class_separator = jnidescriptor ? "$" : "."; @@ -2908,7 +2912,7 @@ public: // global enum or enum in a namespace String *nspace = Getattr(n, "sym:nspace"); if (nspace) { - if (package) + if (package && !jnidescriptor) enumname = NewStringf("%s.%s.%s", package, nspace, symname); else enumname = NewStringf("%s.%s", nspace, symname); @@ -2916,8 +2920,8 @@ public: enumname = Copy(symname); } } - if (!jnidescriptor) { // not cached - Setattr(n, "enumname", enumname); + if (!jnidescriptor) { + Setattr(n, "enumname", enumname); // Cache it Delete(enumname); } Delete(scopename_prefix); @@ -2935,37 +2939,25 @@ public: * that SWIG knows about. Also substitutes enums with enum name. * Otherwise use the $descriptor name for the Java class name. Note that the $&javaclassname substitution * is the same as a $&descriptor substitution, ie one pointer added to descriptor name. + * Note that the path separator is a '.' unless jnidescriptor is set. * Inputs: * pt - parameter type * tm - typemap contents that might contain the special variable to be replaced - * jnidescriptor - if set, inner class names are separated with '$' otherwise a '.' - * p - a parameter type, that may hold a javapackage typemap. If passed, - * the $packagepath will be substituted, but call method below instead. + * jnidescriptor - if set, inner class names are separated with '$' otherwise a '/' is used for the path separator * Outputs: * tm - typemap contents complete with the special variable substitution * Return: * substitution_performed - flag indicating if a substitution was performed * ----------------------------------------------------------------------------- */ - bool substituteClassname(SwigType *pt, String *tm, bool jnidescriptor = false, Parm *pkgpathparm = 0) { - return substituteClassnameAndPackagePath( pt, tm, jnidescriptor, pkgpathparm); - } - - /* ----------------------------------------------------------------------------- - * substituteClassnameAndPackagePath() - * Used to canonicalize JNI descriptors, including code emitting director throws typemaps. - * - * Only usage always has jnidescriptor AND p set. Maybe collapse args. - * ----------------------------------------------------------------------------- */ - - bool substituteClassnameAndPackagePath(SwigType *pt, String *tm, bool jnidescriptor, Parm *pkgpathparm) { + bool substituteClassname(SwigType *pt, String *tm, bool jnidescriptor = false) { bool substitution_performed = false; SwigType *type = Copy(SwigType_typedef_resolve_all(pt)); SwigType *strippedtype = SwigType_strip_qualifiers(type); if (Strstr(tm, "$javaclassname")) { SwigType *classnametype = Copy(strippedtype); - substituteClassnameSpecialVariable(classnametype, tm, "$javaclassname", jnidescriptor, pkgpathparm); + substituteClassnameSpecialVariable(classnametype, tm, "$javaclassname", jnidescriptor); substitution_performed = true; Delete(classnametype); } @@ -2973,7 +2965,7 @@ public: SwigType *classnametype = Copy(strippedtype); Delete(SwigType_pop(classnametype)); if (Len(classnametype) > 0) { - substituteClassnameSpecialVariable(classnametype, tm, "$*javaclassname", jnidescriptor, pkgpathparm); + substituteClassnameSpecialVariable(classnametype, tm, "$*javaclassname", jnidescriptor); substitution_performed = true; } Delete(classnametype); @@ -2981,7 +2973,7 @@ public: if (Strstr(tm, "$&javaclassname")) { SwigType *classnametype = Copy(strippedtype); SwigType_add_pointer(classnametype); - substituteClassnameSpecialVariable(classnametype, tm, "$&javaclassname", jnidescriptor, pkgpathparm); + substituteClassnameSpecialVariable(classnametype, tm, "$&javaclassname", jnidescriptor); substitution_performed = true; Delete(classnametype); } @@ -2996,40 +2988,27 @@ public: * substituteClassnameSpecialVariable() * ----------------------------------------------------------------------------- */ - void substituteClassnameSpecialVariable(SwigType *classnametype, String *tm, const char *classnamespecialvariable, bool jnidescriptor, Parm * pkgpathparm) { - String * replacementname; + void substituteClassnameSpecialVariable(SwigType *classnametype, String *tm, const char *classnamespecialvariable, bool jnidescriptor) { + String *replacementname; if (SwigType_isenum(classnametype)) { - replacementname = Copy(getEnumName(classnametype, jnidescriptor)); - if (!replacementname) { + String *enumname = getEnumName(classnametype, jnidescriptor); + if (enumname) + replacementname = Copy(enumname); + else replacementname = NewString("int"); - } } else { - replacementname = Copy(getProxyName(classnametype)); - if (! replacementname) { + String *classname = getProxyName(classnametype, jnidescriptor); // getProxyName() works for pointers to classes too + if (classname) { + replacementname = Copy(classname); + } else { // use $descriptor if SWIG does not know anything about this type. Note that any typedefs are resolved. replacementname = NewStringf("SWIGTYPE%s", SwigType_manglestr(classnametype)); + // Add to hash table so that the type wrapper classes can be created later Setattr(swig_types_hash, replacementname, classnametype); } } - - if (pkgpathparm) { - if (Strchr(replacementname, '.') != NULL) { - // nspace feature in use, indicated by dots (!?) - // if replacementname is in name space form, a.b.c, discard - // packagepath from any string like $packagepath/$javaclassname - // since IT WAS ADDED in getProxyName - // But $packagepath could still be used by itself in same string - // since this is used to emit general code blocks for director - // exceptions - // So do this to get rid of all combined forms before subsitituting - Replaceall(tm, "$packagepath/$javaclassname","$javaclassname"); - Replaceall(tm, "$packagepath/$*javaclassname","$*javaclassname"); - Replaceall(tm, "$packagepath/$&javaclassname","$&javaclassname"); - } - substitutePackagePath(tm, pkgpathparm); - } if (jnidescriptor) Replaceall(replacementname,".","/"); Replaceall(tm, classnamespecialvariable, replacementname); @@ -3533,8 +3512,8 @@ public: * substitutePackagePath() * * Replace $packagepath using the javapackage typemap associated with passed - * parm or global package_path if none. "$packagepath/" is replaced with "" if - * no package path is set. + * parm or global package if p is 0. "$packagepath/" is replaced with "" if + * no package is set. Note that the path separator is a '/'. * ----------------------------------------------------------------------------- */ void substitutePackagePath(String *text, Parm *p) { @@ -3543,21 +3522,23 @@ public: if (p) pkg_path = Swig_typemap_lookup("javapackage", p, "", 0); if (!pkg_path || Len(pkg_path) == 0) - pkg_path = package_path; + pkg_path = Copy(package_path); if (Len(pkg_path) > 0) { + Replaceall(pkg_path, ".", "/"); Replaceall(text, "$packagepath", pkg_path); } else { Replaceall(text, "$packagepath/", empty_string); Replaceall(text, "$packagepath", empty_string); } + Delete(pkg_path); } /* --------------------------------------------------------------- * Canonicalize the JNI field descriptor * - * Replace the $packagepath and $javaclassname family of - * variables with the desired package and Java descriptor as + * Replace the $packagepath and $javaclassname family of special + * variables with the desired package and Java proxy name as * required in the JNI field descriptors. * * !!SFM!! If $packagepath occurs in the field descriptor, but @@ -3568,10 +3549,10 @@ public: String *canonicalizeJNIDescriptor(String *descriptor_in, Parm *p) { SwigType *type = Getattr(p, "type"); - String *descriptor_out = Copy(descriptor_in); - // This returns a JNI descriptor, in path format - substituteClassnameAndPackagePath(type, descriptor_out, true, p); + + substituteClassname(type, descriptor_out, true); + substitutePackagePath(descriptor_out, p); return descriptor_out; } @@ -3968,7 +3949,7 @@ public: // Get any Java exception classes in the throws typemap ParmList *throw_parm_list = NULL; - // May need to add throws to director classes if %catches defined + // May need to add Java throws clause to director methods if %catches defined // Get any Java exception classes in the throws typemap ParmList *catches_list = Getattr(n, "catchlist"); if (catches_list) { @@ -3991,7 +3972,7 @@ public: } for (p = throw_parm_list; p; p = nextSibling(p)) { if (Getattr(p, "tmap:throws")) { - // If %catches feature, it overrides specified throws(). + // %catches replaces the specified exception specification if (!catches_list) { addThrows(n, "tmap:throws", p); } @@ -4190,15 +4171,14 @@ public: for (Parm *p = throw_parm_list; p; p = nextSibling(p)) { String *tm = Getattr(p, "tmap:directorthrows"); - String *t = Getattr(p,"type"); if (tm) { - String *directorthrows = Copy(tm); - // replace $packagepath - substituteClassnameAndPackagePath(t, directorthrows, true, p); + // replace $packagepath/$javaclassname + String *directorthrows = canonicalizeJNIDescriptor(tm, p); Printv(directorthrowshandlers_code, directorthrows, NIL); Delete(directorthrows); } else { + String *t = Getattr(p,"type"); Swig_warning(WARN_TYPEMAP_DIRECTORTHROWS_UNDEF, Getfile(n), Getline(n), "No directorthrows typemap defined for %s\n", SwigType_str(t, 0)); } } From baec61c5abc689379c205ffdaea395c96a3482cd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 2 Nov 2013 12:33:33 +0000 Subject: [PATCH 0753/1160] java_director_exception_feature_nspace test case changes - The implementation for SEP for the classpath is not portable, eg the separator should be ':' not ';' on Cygwin, but clearly it could be ';' if using a native Windows version of Java. In the past the test-suite has been constructed to avoid this problem and these changes go back to this approach at the expense of not testing nspace without -package (but not specifying -package is quite unusual when using nspace, so no great loss). This test could be restored to how it was if the separator is detected at configure time from the JVM itself, eg by calling Java code: System.out.println(System.getProperty("path.separator")); - Mangle the non-public classes in the _runme.java file so that they are unique to this testcase (the .class files generated can interfere with other tests). - Const corrections and spelling mistakes fixed in test case. test case improvements --- Examples/test-suite/java/Makefile.in | 15 ++----- ...rector_exception_feature_nspace_runme.java | 30 +++++++------- .../java_director_exception_feature.i | 14 +++---- .../java_director_exception_feature_nspace.i | 39 ++++++++++--------- 4 files changed, 46 insertions(+), 52 deletions(-) diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 52ae78563..1bd4b0261 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -46,18 +46,9 @@ JAVA_PACKAGE = $* JAVA_PACKAGEOPT = -package $(JAVA_PACKAGE) SWIGOPT += $(JAVA_PACKAGEOPT) -RUNME_CLASSPATH = -classpath . -ifeq (Cygwin,$(shell uname -o 2>/dev/null)) -SEP=; -else -SEP=: -endif - # Custom tests - tests with additional commandline options java_nspacewithoutpackage.%: JAVA_PACKAGEOPT = -java_director_exception_feature_nspace.%: JAVA_PACKAGEOPT = -java_director_exception_feature_nspace.%: RUNME_CLASSPATH = -classpath .$(SEP)./java_director_exception_feature_nspace - +java_director_exception_feature_nspace.%: JAVA_PACKAGE = $*Package nspace.%: JAVA_PACKAGE = $*Package nspace_extend.%: JAVA_PACKAGE = $*Package director_nspace.%: JAVA_PACKAGE = $*Package @@ -96,8 +87,8 @@ setup = \ run_testcase = \ cd $(JAVA_PACKAGE) && $(COMPILETOOL) $(JAVAC) -classpath . `find . -name "*.java"` && cd .. && \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - $(COMPILETOOL) $(JAVAC) $(RUNME_CLASSPATH) -d . $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ - 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) $(JAVAFLAGS) $(RUNME_CLASSPATH) $*_runme; \ + $(COMPILETOOL) $(JAVAC) -classpath . -d . $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ + 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) $(JAVAFLAGS) -classpath . $*_runme; \ fi # Clean: remove testcase directories diff --git a/Examples/test-suite/java/java_director_exception_feature_nspace_runme.java b/Examples/test-suite/java/java_director_exception_feature_nspace_runme.java index 0cde36953..ea7da5c1a 100644 --- a/Examples/test-suite/java/java_director_exception_feature_nspace_runme.java +++ b/Examples/test-suite/java/java_director_exception_feature_nspace_runme.java @@ -1,5 +1,5 @@ -import MyNS.*; -import MyNS_JNI.*; +import java_director_exception_feature_nspacePackage.*; +import java_director_exception_feature_nspacePackage.MyNS.*; class java_director_exception_feature_nspace_Consts { public static final String PINGEXCP1 = "Ping MyJavaException1"; // should get translated through an int on ping @@ -18,25 +18,25 @@ class java_director_exception_feature_nspace_Consts { // an exception not mentioned or wrapped by the swig interface, // to reconstruct using generic DirectorException handling -class NewCheckedException extends Exception { - public NewCheckedException(String s) { +class java_director_exception_feature_nspace_NewCheckedException extends Exception { + public java_director_exception_feature_nspace_NewCheckedException(String s) { super(s); } } // an exception not mentioned or wrapped by the swig interface, // to reconstruct using generic DirectorException handling -class NewUncheckedException extends RuntimeException { - public NewUncheckedException(String s) { +class java_director_exception_feature_nspace_NewUncheckedException extends RuntimeException { + public java_director_exception_feature_nspace_NewUncheckedException(String s) { super(s); } } -// an exception not constructable from a string, +// an exception not constructible from a string, // to test DirectorException fallback reconstruction -class UnconstructableException extends Exception { +class java_director_exception_feature_nspace_UnconstructibleException extends Exception { private int extrastate; - public UnconstructableException(int a, String s) { + public java_director_exception_feature_nspace_UnconstructibleException(int a, String s) { super(s); extrastate = a; } @@ -62,15 +62,15 @@ class java_director_exception_feature_nspace_MyFooDirectorImpl extends Foo { } @Override - public String genericpong(int excp) throws MyJavaException1, NewCheckedException, UnconstructableException { + public String genericpong(int excp) throws MyJavaException1, java_director_exception_feature_nspace_NewCheckedException, java_director_exception_feature_nspace_UnconstructibleException { if (excp == 1) throw new MyJavaException1(java_director_exception_feature_nspace_Consts.GENERICPONGEXCP1); if (excp == 2) - throw new NewCheckedException(java_director_exception_feature_nspace_Consts.GENERICPONGEXCP2); + throw new java_director_exception_feature_nspace_NewCheckedException(java_director_exception_feature_nspace_Consts.GENERICPONGEXCP2); if (excp == 3) - throw new NewUncheckedException(java_director_exception_feature_nspace_Consts.GENERICPONGEXCP3); + throw new java_director_exception_feature_nspace_NewUncheckedException(java_director_exception_feature_nspace_Consts.GENERICPONGEXCP3); if (excp == 4) - throw new UnconstructableException(1, java_director_exception_feature_nspace_Consts.GENERICPONGEXCP4); + throw new java_director_exception_feature_nspace_UnconstructibleException(1, java_director_exception_feature_nspace_Consts.GENERICPONGEXCP4); return "GenericPong director returned"; } } @@ -128,11 +128,11 @@ public class java_director_exception_feature_nspace_runme { failif( ! java_director_exception_feature_nspace_Consts.GENERICPONGEXCP1.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); } try { b.genericpong(2); fail("No exception thrown in genericpong(2)");} - catch (NewCheckedException e) { + catch (java_director_exception_feature_nspace_NewCheckedException e) { failif( ! java_director_exception_feature_nspace_Consts.GENERICPONGEXCP2.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); } try { b.genericpong(3); fail("No exception thrown in genericpong(3)");} - catch (NewUncheckedException e) { + catch (java_director_exception_feature_nspace_NewUncheckedException e) { failif( ! java_director_exception_feature_nspace_Consts.GENERICPONGEXCP3.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); } try { b.genericpong(4); fail("No exception thrown in genericpong(4)");} diff --git a/Examples/test-suite/java_director_exception_feature.i b/Examples/test-suite/java_director_exception_feature.i index fc1af7a96..1552454dc 100644 --- a/Examples/test-suite/java_director_exception_feature.i +++ b/Examples/test-suite/java_director_exception_feature.i @@ -138,26 +138,26 @@ %feature("director") Foo; // Rename exceptions on java side to make translation of exceptions more clear -%rename(MyJavaException1,fullname=1) MyNS::Exception1; -%rename(MyJavaException2,fullname=1) MyNS::Exception2; -%rename(MyJavaUnexpected,fullname=1) MyNS::Unexpected; +%rename(MyJavaException1) MyNS::Exception1; +%rename(MyJavaException2) MyNS::Exception2; +%rename(MyJavaUnexpected) MyNS::Unexpected; %typemap(javabase) ::MyNS::Exception1,::MyNS::Exception2,::MyNS::Unexpected "java.lang.Exception"; -%rename(getMessage) what(); // Rename all what() methods +%rename(getMessage) what() const; // Rename all what() methods namespace MyNS { struct Exception1 { Exception1(const std::string& what); - const char * what(); + const char * what() const; }; struct Exception2 { Exception2(const std::string& what); - const char * what(); + const char * what() const; }; struct Unexpected { Unexpected(const std::string& what); - const char * what(); + const char * what() const; }; } diff --git a/Examples/test-suite/java_director_exception_feature_nspace.i b/Examples/test-suite/java_director_exception_feature_nspace.i index 1f3d97ad3..aea362905 100644 --- a/Examples/test-suite/java_director_exception_feature_nspace.i +++ b/Examples/test-suite/java_director_exception_feature_nspace.i @@ -4,9 +4,12 @@ %nspace; // turn namespace feature on for everything. -// When using namespaces with no -package, must put JNI classes into a namespace -%pragma(java) jniclasspackage=%{MyNS_JNI%} -%warnfilter(SWIGWARN_JAVA_NSPACE_WITHOUT_PACKAGE); +#define PACKAGEDOT "java_director_exception_feature_nspacePackage." +#define PACKAGESLASH "java_director_exception_feature_nspacePackage/" +%{ +#define PACKAGEDOT "java_director_exception_feature_nspacePackage." +#define PACKAGESLASH "java_director_exception_feature_nspacePackage/" +%} %{ #if defined(_MSC_VER) @@ -83,24 +86,24 @@ // $javaclassname or $packagepath ("java_director_exception_feature" here) // throws typemaps for c++->java exception conversions -%typemap(throws,throws="MyNS.MyJavaException1") MyNS::Exception1 %{ - jclass excpcls = jenv->FindClass("MyNS/MyJavaException1"); +%typemap(throws,throws=PACKAGEDOT"MyNS.MyJavaException1") MyNS::Exception1 %{ + jclass excpcls = jenv->FindClass(PACKAGESLASH"MyNS/MyJavaException1"); if (excpcls) { jenv->ThrowNew(excpcls, $1.what()); } return $null; %} -%typemap(throws,throws="MyNS.MyJavaException1") int %{ - jclass excpcls = jenv->FindClass("MyNS/MyJavaException1"); +%typemap(throws,throws=PACKAGEDOT"MyNS.MyJavaException1") int %{ + jclass excpcls = jenv->FindClass(PACKAGESLASH"MyNS/MyJavaException1"); if (excpcls) { jenv->ThrowNew(excpcls, "Threw some integer"); } return $null; %} -%typemap(throws,throws="MyNS.MyJavaException2") MyNS::Exception2 %{ - jclass excpcls = jenv->FindClass("MyNS/MyJavaException2"); +%typemap(throws,throws=PACKAGEDOT"MyNS.MyJavaException2") MyNS::Exception2 %{ + jclass excpcls = jenv->FindClass(PACKAGESLASH"MyNS/MyJavaException2"); if (excpcls) { jenv->ThrowNew(excpcls, $1.what()); } @@ -108,8 +111,8 @@ %} -%typemap(throws,throws="MyNS.MyJavaUnexpected") MyNS::Unexpected %{ - jclass excpcls = jenv->FindClass("MyNS/MyJavaUnexpected"); +%typemap(throws,throws=PACKAGEDOT"MyNS.MyJavaUnexpected") MyNS::Unexpected %{ + jclass excpcls = jenv->FindClass(PACKAGESLASH"MyNS/MyJavaUnexpected"); if (excpcls) { jenv->ThrowNew(excpcls, $1.what()); } @@ -143,26 +146,26 @@ %feature("director") Foo; // Rename exceptions on java side to make translation of exceptions more clear -%rename(MyJavaException1,fullname=1) MyNS::Exception1; -%rename(MyJavaException2,fullname=1) MyNS::Exception2; -%rename(MyJavaUnexpected,fullname=1) MyNS::Unexpected; +%rename(MyJavaException1) MyNS::Exception1; +%rename(MyJavaException2) MyNS::Exception2; +%rename(MyJavaUnexpected) MyNS::Unexpected; %typemap(javabase) ::MyNS::Exception1,::MyNS::Exception2,::MyNS::Unexpected "java.lang.Exception"; -%rename(getMessage) what(); // Rename all what() methods +%rename(getMessage) what() const; // Rename all what() methods namespace MyNS { struct Exception1 { Exception1(const std::string& what); - const char * what(); + const char * what() const; }; struct Exception2 { Exception2(const std::string& what); - const char * what(); + const char * what() const; }; struct Unexpected { Unexpected(const std::string& what); - const char * what(); + const char * what() const; }; } From fdc1772e38b4d27050bc1d4958f155ec67760fc8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 2 Nov 2013 19:56:51 +0000 Subject: [PATCH 0754/1160] Cosmetics/code style conformance in newly added Java director exception handling --- Lib/java/director.swg | 252 +++++++++++++++++++----------------------- 1 file changed, 113 insertions(+), 139 deletions(-) diff --git a/Lib/java/director.swg b/Lib/java/director.swg index 8c7dca294..346cec2cc 100644 --- a/Lib/java/director.swg +++ b/Lib/java/director.swg @@ -11,7 +11,10 @@ #include #endif +#include + namespace Swig { + /* Java object wrapper */ class JObjectWrapper { public: @@ -74,8 +77,7 @@ namespace Swig { } /* Java proxy releases ownership of C++ object, C++ object is now - responsible for destruction (creates NewGlobalRef to pin Java - proxy) */ + responsible for destruction (creates NewGlobalRef to pin Java proxy) */ void java_change_ownership(JNIEnv *jenv, jobject jself, bool take_or_release) { if (take_or_release) { /* Java takes ownership of C++ object's lifetime. */ if (!weak_global_) { @@ -83,7 +85,8 @@ namespace Swig { jthis_ = jenv->NewWeakGlobalRef(jself); weak_global_ = true; } - } else { /* Java releases ownership of C++ object's lifetime */ + } else { + /* Java releases ownership of C++ object's lifetime */ if (weak_global_) { jenv->DeleteWeakGlobalRef((jweak)jthis_); jthis_ = jenv->NewGlobalRef(jself); @@ -191,119 +194,26 @@ namespace Swig { swig_self_.java_change_ownership(jenv, jself, take_or_release); } }; -} -// Default exception handler for all director methods. -// Can override this for specific methods -// This just documents the default. It is not actually attached as a feature -// for efficiency reasons (and is defined in java.cxx) It can be overridden -// as a feature for specific methods or globally. + // Utility methods and classes for exception handling. -//%feature("director:except") %{ -// jthrowable $error = jenv->ExceptionOccurred(); -// if ($error) { -// jenv->ExceptionClear(); -// $directorthrowshandlers -// throw Swig::DirectorException(jenv, $error); -// } -//%} - -// Define some utility methods and classes. Cannot use fragments since -// these may be used by %features and in directorthrows typemaps - -#include - -// Simple holder for exception messages, allowing access to a c-style string -namespace Swig { - struct JavaString { - JavaString(JNIEnv * jenv, jstring jstr):jenv_(jenv), jstr_(jstr), cstr_(0) { - if (jenv_ && jstr_) { - // Get the null-terminated c-string out, and hold it - cstr_ = (const char *) jenv_->GetStringUTFChars(jstr_, NULL); - } - } - ~JavaString() { - if (jenv_ && jstr_ && cstr_) { - jenv_->ReleaseStringUTFChars(jstr_, cstr_); - } - } - const char *cstr() { - return cstr_ ? cstr_ : ""; - } - - private: - JNIEnv * jenv_; - jstring jstr_; - const char * cstr_; - - // non-copyable - JavaString(const JavaString &); - JavaString & operator=(const JavaString &); - }; - - struct JavaExceptionMessage { - JavaExceptionMessage(JNIEnv * jenv, jthrowable excp) : - jstrholder_(jenv,exceptionMsgJstr(jenv,excp)) { - } - ~JavaExceptionMessage() { - } - const char *message() { - return jstrholder_.cstr(); - } - - private: - JavaString jstrholder_; - - // non-copyable - JavaExceptionMessage(const JavaExceptionMessage &); - JavaExceptionMessage & operator=(const JavaExceptionMessage &); - - // Static method to initialize jstrholder_ - static jstring exceptionMsgJstr(JNIEnv * jenv, jthrowable excp) { - jstring jmsg = NULL; - if (jenv && excp) { - jenv->ExceptionClear(); // Cannot invoke methods with pending exception - jclass thrwclz = jenv->GetObjectClass(excp); - if (thrwclz) { - // if no getMessage() or other exception, no msg available. - jmethodID getThrowableMsgMethodID = - jenv->GetMethodID(thrwclz, "getMessage", "()Ljava/lang/String;"); - if (getThrowableMsgMethodID && !jenv->ExceptionCheck()) { - // if problem accessing exception message string, no msg available. - jmsg = (jstring) - jenv->CallObjectMethod(excp, getThrowableMsgMethodID); - } - } - if (jmsg == NULL && jenv->ExceptionCheck()) { - jenv->ExceptionClear(); - } - } - return jmsg; - } - }; - - - //////////////////////////////////// - - bool ExceptionMatches(JNIEnv * jenv, jthrowable excp, - const char *clzname) { + // Helper method to determine if a Java throwable matches a particular Java class type + bool ExceptionMatches(JNIEnv *jenv, jthrowable excp, const char *clzname) { jboolean matches = false; if (excp && jenv && clzname) { - // Have to clear exceptions for correct behavior. Code around - // ExceptionMatches should restore pending exception if - // desired - already have throwable. + // Exceptions need to be cleared for correct behavior. + // The caller of ExceptionMatches should restore pending exceptions if desired - + // the caller already has the throwable. jenv->ExceptionClear(); jclass clz = jenv->FindClass(clzname); - if (clz && ! jenv->ExceptionCheck()) { + if (clz && !jenv->ExceptionCheck()) { jclass classclz = jenv->GetObjectClass(clz); - jmethodID isInstanceMethodID = - jenv->GetMethodID(classclz, "isInstance", "(Ljava/lang/Object;)Z"); + jmethodID isInstanceMethodID = jenv->GetMethodID(classclz, "isInstance", "(Ljava/lang/Object;)Z"); if (isInstanceMethodID) { - matches = (jboolean) - jenv->CallBooleanMethod(clz, isInstanceMethodID, excp); + matches = (jboolean)jenv->CallBooleanMethod(clz, isInstanceMethodID, excp); } } // This may happen if user typemaps or director:except @@ -314,7 +224,7 @@ namespace Swig { // which may not be that clear (e.g. ClassNotFoundException) // if (jenv->ExceptionCheck()) { - // JavaExceptionMessage jstrmsg(jenv,jenv->ExceptionOccurred()); + // JavaExceptionMessage jstrmsg(jenv, jenv->ExceptionOccurred()); // std::cerr << "Error: ExceptionMatches: class '" << // clzname << "' : " << jstrmsg.message() << std::endl; // } @@ -322,24 +232,91 @@ namespace Swig { return matches; } - // Provide the class name to allow reconstruction of the original exception - struct DirectorException : std::exception { + // Simple holder for a Java string during exception handling, allowing access to a c-style string + class JavaString { + public: + JavaString(JNIEnv *jenv, jstring jstr) : jenv_(jenv), jstr_(jstr), cstr_(0) { + if (jenv_ && jstr_) + cstr_ = (const char *) jenv_->GetStringUTFChars(jstr_, NULL); + } - // Construct a DirectorException from a java throwable - DirectorException(JNIEnv* jenv,jthrowable excp) : classname_(0), msg_(0) { + ~JavaString() { + if (jenv_ && jstr_ && cstr_) + jenv_->ReleaseStringUTFChars(jstr_, cstr_); + } + + const char *cstr() { + return cstr_ ? cstr_ : ""; + } + + private: + // non-copyable + JavaString(const JavaString &); + JavaString &operator=(const JavaString &); + + JNIEnv *jenv_; + jstring jstr_; + const char *cstr_; + }; + + // Helper to extract the exception message from a Java throwable + class JavaExceptionMessage { + public: + JavaExceptionMessage(JNIEnv *jenv, jthrowable excp) : jstrholder_(jenv, exceptionMsgJstr(jenv, excp)) { + } + + ~JavaExceptionMessage() { + } + + const char *message() { + return jstrholder_.cstr(); + } + + private: + // non-copyable + JavaExceptionMessage(const JavaExceptionMessage &); + JavaExceptionMessage &operator=(const JavaExceptionMessage &); + + // Static method to initialize jstrholder_ + static jstring exceptionMsgJstr(JNIEnv *jenv, jthrowable excp) { + jstring jmsg = NULL; + if (jenv && excp) { + jenv->ExceptionClear(); // Cannot invoke methods with pending exception + jclass thrwclz = jenv->GetObjectClass(excp); + if (thrwclz) { + // if no getMessage() or other exception, no msg available. + jmethodID getThrowableMsgMethodID = jenv->GetMethodID(thrwclz, "getMessage", "()Ljava/lang/String;"); + if (getThrowableMsgMethodID && !jenv->ExceptionCheck()) { + // if problem accessing exception message string, no msg will be available. + jmsg = (jstring)jenv->CallObjectMethod(excp, getThrowableMsgMethodID); + } + } + if (jmsg == NULL && jenv->ExceptionCheck()) { + jenv->ExceptionClear(); + } + } + return jmsg; + } + + JavaString jstrholder_; + }; + + // C++ Exception class for converting from Java exceptions thrown during a director method Java upcall + class DirectorException : public std::exception { + public: + + // Construct a DirectorException from a Java throwable + DirectorException(JNIEnv *jenv, jthrowable excp) : classname_(0), msg_(0) { jstring jstr_classname = NULL; - jmethodID mid_getName = NULL; - jclass thrwclz; - jclass clzclz; if (excp) { // Get the exception class, like Exception - thrwclz = jenv->GetObjectClass(excp); + jclass thrwclz = jenv->GetObjectClass(excp); if (thrwclz) { - // Get the java.lang.Class class - clzclz = jenv->GetObjectClass(thrwclz); + // Get the Java.lang.Class class + jclass clzclz = jenv->GetObjectClass(thrwclz); if (clzclz) { - mid_getName = jenv->GetMethodID(clzclz, "getName", "()Ljava/lang/String;"); + jmethodID mid_getName = mid_getName = jenv->GetMethodID(clzclz, "getName", "()Ljava/lang/String;"); if (mid_getName) { // Get the excp class name jstr_classname = (jstring)(jenv->CallObjectMethod(thrwclz, mid_getName)); @@ -357,8 +334,8 @@ namespace Swig { msg_ = copystr(exceptionmsg.message()); } - // Throw as a wrapped Runtime Error explicitly. - DirectorException(const char * msg) : classname_(0), msg_(0) { + // Throw as a wrapped RuntimeError explicitly. + DirectorException(const char *msg) : classname_(0), msg_(0) { classname_ = copypath("java/lang/RuntimeError"); msg_ = copystr(msg); } @@ -368,27 +345,22 @@ namespace Swig { delete[] msg_; } - // If there was problem finding classname, keep track of error - // On raiseJavaException will be mapped to a RuntimeException - const char* classname() const throw() { + // If there was a problem finding classname, keep track of error + // On raiseJavaException will be mapped to a RuntimeException + const char *classname() const throw() { return classname_ ? classname_ : "UnknownException"; } - const char* what() const throw() { + + const char *what() const throw() { return msg_ ? msg_ : ""; } - // Python director code provides static raise() methods - // Omitted here: Seems less good than - // throw DirectorException(jenv, excp) - // from which compiler can infer a C++ exception is thrown. - // Reconstruct and raise the Java Exception that caused the DirectorException - void raiseJavaException(JNIEnv* jenv) { + void raiseJavaException(JNIEnv *jenv) { if (jenv) { jenv->ExceptionClear(); jmethodID strCtorID = 0; - jclass excpclz = jenv->FindClass(classname()); if (excpclz) { @@ -406,27 +378,29 @@ namespace Swig { } private: - const char * classname_; - const char * msg_; - - static const char * copypath(const char * srcmsg) { + static const char *copypath(const char *srcmsg) { return copystr(srcmsg, 1); } - static const char * copystr(const char * srcmsg, int pathrepl=0) { - char * target = 0; + + static const char *copystr(const char *srcmsg, int pathrepl=0) { + char *target = 0; if (srcmsg) { - int msglen = 1+strlen(srcmsg); //+1 for null terminator + int msglen = 1 + strlen(srcmsg); target = new char[msglen]; strncpy(target, srcmsg, msglen); } // If pathrepl, replace any '.' with '/' if (pathrepl) { - for(char *c=target; *c; ++c) { - if ('.' == *c) *c = '/'; + for (char *c=target; *c; ++c) { + if ('.' == *c) + *c = '/'; } } return target; } + + const char *classname_; + const char *msg_; }; } From e7a6be289e7db30307c5d2b379a3e867b5d01e0e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 5 Nov 2013 18:49:21 +0000 Subject: [PATCH 0755/1160] Rework the director.swg changes for director exception handling - More robust implementation. - Fix some bugs to give better exception messages when a user uses the director utility exception functions and classes. - Replace unnecessarily shortened variable names for easier reading of code. --- Lib/java/director.swg | 211 +++++++++++++++++++----------------------- 1 file changed, 95 insertions(+), 116 deletions(-) diff --git a/Lib/java/director.swg b/Lib/java/director.swg index 346cec2cc..f9ddbeffe 100644 --- a/Lib/java/director.swg +++ b/Lib/java/director.swg @@ -7,7 +7,7 @@ #ifdef __cplusplus -#if defined(DEBUG_DIRECTOR_OWNED) +#if defined(DEBUG_DIRECTOR_OWNED) || defined(DEBUG_DIRECTOR_EXCEPTION) #include #endif @@ -196,43 +196,9 @@ namespace Swig { }; - // Utility methods and classes for exception handling. + // Utility classes and functions for exception handling. - // Helper method to determine if a Java throwable matches a particular Java class type - bool ExceptionMatches(JNIEnv *jenv, jthrowable excp, const char *clzname) { - jboolean matches = false; - - if (excp && jenv && clzname) { - // Exceptions need to be cleared for correct behavior. - // The caller of ExceptionMatches should restore pending exceptions if desired - - // the caller already has the throwable. - jenv->ExceptionClear(); - - jclass clz = jenv->FindClass(clzname); - if (clz && !jenv->ExceptionCheck()) { - jclass classclz = jenv->GetObjectClass(clz); - jmethodID isInstanceMethodID = jenv->GetMethodID(classclz, "isInstance", "(Ljava/lang/Object;)Z"); - if (isInstanceMethodID) { - matches = (jboolean)jenv->CallBooleanMethod(clz, isInstanceMethodID, excp); - } - } - // This may happen if user typemaps or director:except - // features call ExceptionMatches incorrectly, typically with - // an invalid clzname argument. Uncommenting the debug lines - // may help to diagnose. - // As is, this leaves the underlying case as a pending exception - // which may not be that clear (e.g. ClassNotFoundException) - - // if (jenv->ExceptionCheck()) { - // JavaExceptionMessage jstrmsg(jenv, jenv->ExceptionOccurred()); - // std::cerr << "Error: ExceptionMatches: class '" << - // clzname << "' : " << jstrmsg.message() << std::endl; - // } - } - return matches; - } - - // Simple holder for a Java string during exception handling, allowing access to a c-style string + // Simple holder for a Java string during exception handling, providing access to a c-style string class JavaString { public: JavaString(JNIEnv *jenv, jstring jstr) : jenv_(jenv), jstr_(jstr), cstr_(0) { @@ -245,8 +211,8 @@ namespace Swig { jenv_->ReleaseStringUTFChars(jstr_, cstr_); } - const char *cstr() { - return cstr_ ? cstr_ : ""; + const char *c_str(const char *null_string = "null JavaString") const { + return cstr_ ? cstr_ : null_string; } private: @@ -259,17 +225,14 @@ namespace Swig { const char *cstr_; }; - // Helper to extract the exception message from a Java throwable + // Helper class to extract the exception message from a Java throwable class JavaExceptionMessage { public: - JavaExceptionMessage(JNIEnv *jenv, jthrowable excp) : jstrholder_(jenv, exceptionMsgJstr(jenv, excp)) { + JavaExceptionMessage(JNIEnv *jenv, jthrowable throwable) : message_(jenv, exceptionMessageFromThrowable(jenv, throwable)) { } - ~JavaExceptionMessage() { - } - - const char *message() { - return jstrholder_.cstr(); + const char *message() const { + return message_.c_str("Could not get exception message in JavaExceptionMessage"); } private: @@ -277,67 +240,61 @@ namespace Swig { JavaExceptionMessage(const JavaExceptionMessage &); JavaExceptionMessage &operator=(const JavaExceptionMessage &); - // Static method to initialize jstrholder_ - static jstring exceptionMsgJstr(JNIEnv *jenv, jthrowable excp) { + // Get exception message by calling Java method Throwable.getMessage() + static jstring exceptionMessageFromThrowable(JNIEnv *jenv, jthrowable throwable) { jstring jmsg = NULL; - if (jenv && excp) { - jenv->ExceptionClear(); // Cannot invoke methods with pending exception - jclass thrwclz = jenv->GetObjectClass(excp); - if (thrwclz) { - // if no getMessage() or other exception, no msg available. - jmethodID getThrowableMsgMethodID = jenv->GetMethodID(thrwclz, "getMessage", "()Ljava/lang/String;"); - if (getThrowableMsgMethodID && !jenv->ExceptionCheck()) { - // if problem accessing exception message string, no msg will be available. - jmsg = (jstring)jenv->CallObjectMethod(excp, getThrowableMsgMethodID); - } + if (jenv && throwable) { + jenv->ExceptionClear(); // Cannot invoke methods with any pending exceptions + jclass throwclz = jenv->GetObjectClass(throwable); + if (throwclz) { + // All Throwable classes have a getMessage() method, so call it to extract the exception message + jmethodID getMessageMethodID = jenv->GetMethodID(throwclz, "getMessage", "()Ljava/lang/String;"); + if (getMessageMethodID) + jmsg = (jstring)jenv->CallObjectMethod(throwable, getMessageMethodID); } - if (jmsg == NULL && jenv->ExceptionCheck()) { + if (jmsg == NULL && jenv->ExceptionCheck()) jenv->ExceptionClear(); - } } return jmsg; } - JavaString jstrholder_; + JavaString message_; }; - // C++ Exception class for converting from Java exceptions thrown during a director method Java upcall + // C++ Exception class for handling Java exceptions thrown during a director method Java upcall class DirectorException : public std::exception { public: - // Construct a DirectorException from a Java throwable - DirectorException(JNIEnv *jenv, jthrowable excp) : classname_(0), msg_(0) { - jstring jstr_classname = NULL; + // Construct exception from a Java throwable + DirectorException(JNIEnv *jenv, jthrowable throwable) : classname_(0), msg_(0) { - if (excp) { - // Get the exception class, like Exception - jclass thrwclz = jenv->GetObjectClass(excp); - if (thrwclz) { - // Get the Java.lang.Class class - jclass clzclz = jenv->GetObjectClass(thrwclz); + // Call Java method Object.getClass().getName() to obtain the throwable's class name (delimited by '/') + if (throwable) { + jclass throwclz = jenv->GetObjectClass(throwable); + if (throwclz) { + jclass clzclz = jenv->GetObjectClass(throwclz); if (clzclz) { - jmethodID mid_getName = mid_getName = jenv->GetMethodID(clzclz, "getName", "()Ljava/lang/String;"); - if (mid_getName) { - // Get the excp class name - jstr_classname = (jstring)(jenv->CallObjectMethod(thrwclz, mid_getName)); + jmethodID getNameMethodID = jenv->GetMethodID(clzclz, "getName", "()Ljava/lang/String;"); + if (getNameMethodID) { + jstring jstr_classname = (jstring)(jenv->CallObjectMethod(throwclz, getNameMethodID)); + // Copy strings, since there is no guarantee that jenv will be active when handled + if (jstr_classname) { + JavaString jsclassname(jenv, jstr_classname); + const char *classname = jsclassname.c_str(0); + if (classname) + classname_ = copypath(classname); + } } } } } - // Copy strings, since no guarantee jenv will be active when handled - // If classname_ is 0, returned as "UnknownException" - if (jstr_classname) { - JavaString classname(jenv, jstr_classname); - classname_ = copypath(classname.cstr()); - } - JavaExceptionMessage exceptionmsg(jenv, excp); + + JavaExceptionMessage exceptionmsg(jenv, throwable); msg_ = copystr(exceptionmsg.message()); } - // Throw as a wrapped RuntimeError explicitly. - DirectorException(const char *msg) : classname_(0), msg_(0) { - classname_ = copypath("java/lang/RuntimeError"); - msg_ = copystr(msg); + // More general constructor for handling as a java.lang.RuntimeException + DirectorException(const char *msg) : classname_(0), msg_(copystr(msg ? msg : "Unspecified DirectorException message")) { } ~DirectorException() throw() { @@ -345,57 +302,49 @@ namespace Swig { delete[] msg_; } - // If there was a problem finding classname, keep track of error - // On raiseJavaException will be mapped to a RuntimeException - const char *classname() const throw() { - return classname_ ? classname_ : "UnknownException"; - } - const char *what() const throw() { - return msg_ ? msg_ : ""; + return msg_; } - // Reconstruct and raise the Java Exception that caused the DirectorException - void raiseJavaException(JNIEnv *jenv) { + // Reconstruct and raise/throw the Java Exception that caused the DirectorException + // Note that any error in the JNI exception handling results in a Java RuntimeException + void raiseJavaException(JNIEnv *jenv) const { if (jenv) { jenv->ExceptionClear(); - jmethodID strCtorID = 0; - jclass excpclz = jenv->FindClass(classname()); - - if (excpclz) { - strCtorID = jenv->GetMethodID(excpclz,"","(Ljava/lang/String;)V"); + jmethodID ctorMethodID = 0; + jclass throwableclass = 0; + if (classname_) { + throwableclass = jenv->FindClass(classname_); + if (throwableclass) + ctorMethodID = jenv->GetMethodID(throwableclass, "", "(Ljava/lang/String;)V"); } - if (strCtorID) { - // If exception has a string constructor, throw an instance - jenv->ThrowNew(excpclz, what()); + if (ctorMethodID) { + jenv->ThrowNew(throwableclass, what()); } else { - // Else, throw a runtime - SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, what() ); + SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, what()); } } } private: - static const char *copypath(const char *srcmsg) { - return copystr(srcmsg, 1); + static char *copypath(const char *srcmsg) { + char *target = copystr(srcmsg); + for (char *c=target; *c; ++c) { + if ('.' == *c) + *c = '/'; + } + return target; } - static const char *copystr(const char *srcmsg, int pathrepl=0) { + static char *copystr(const char *srcmsg) { char *target = 0; if (srcmsg) { - int msglen = 1 + strlen(srcmsg); + int msglen = strlen(srcmsg) + 1; target = new char[msglen]; strncpy(target, srcmsg, msglen); } - // If pathrepl, replace any '.' with '/' - if (pathrepl) { - for (char *c=target; *c; ++c) { - if ('.' == *c) - *c = '/'; - } - } return target; } @@ -403,6 +352,36 @@ namespace Swig { const char *msg_; }; + // Helper method to determine if a Java throwable matches a particular Java class type + bool ExceptionMatches(JNIEnv *jenv, jthrowable throwable, const char *classname) { + bool matches = false; + + if (throwable && jenv && classname) { + // Exceptions need to be cleared for correct behavior. + // The caller of ExceptionMatches should restore pending exceptions if desired - + // the caller already has the throwable. + jenv->ExceptionClear(); + + jclass clz = jenv->FindClass(classname); + if (clz) { + jclass classclz = jenv->GetObjectClass(clz); + jmethodID isInstanceMethodID = jenv->GetMethodID(classclz, "isInstance", "(Ljava/lang/Object;)Z"); + if (isInstanceMethodID) { + matches = jenv->CallBooleanMethod(clz, isInstanceMethodID, throwable) != 0; + } + } + +#if defined(DEBUG_DIRECTOR_EXCEPTION) + if (jenv->ExceptionCheck()) { + // Typically occurs when an invalid classname argument is passed resulting in a ClassNotFoundException + JavaExceptionMessage exc(jenv, jenv->ExceptionOccurred()); + std::cout << "Error: ExceptionMatches: class '" << classname << "' : " << exc.message() << std::endl; + } +#endif + } + return matches; + } + } #endif /* __cplusplus */ From 9df7bee57057668ef878e075ae070acfecd515b1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 5 Nov 2013 18:55:49 +0000 Subject: [PATCH 0756/1160] Changes file for recent director improvements --- CHANGES.current | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 8989ee194..0f964b114 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,13 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-11-05: wsfulton + [Java] Fix some corner cases for the $packagepath/$javaclassname special variable substitution. + +2013-11-05: wsfulton + [Java] Apply patch #91 from Marvin Greenberg - Add director:except feature for improved + exception handling in director methods for Java. + 2013-10-17: wsfulton [R] Fix SF #1340 - Visual Studio compile error in C++ wrappers due to #include within extern "C" block. From d73f04e925e9210f2c688ef3656e6059eb540565 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 7 Nov 2013 22:48:17 +0000 Subject: [PATCH 0757/1160] Documentation edit for the director:except feature and directorthrows typemap --- Doc/Manual/Java.html | 329 +++++++++++++++++++++++---------------- Doc/Manual/Warnings.html | 2 +- 2 files changed, 200 insertions(+), 131 deletions(-) diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 0e9ba75de..08c80c83a 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -3556,99 +3556,108 @@ However, if all director methods are expected to usually be overridden by Java s The disadvantage is that invocation of director methods from C++ when Java doesn't actually override the method will require an additional call up into Java and back to C++. As such, this option is only useful when overrides are extremely common and instantiation is frequent enough that its performance is critical.

    -

    24.5.7 Java Exceptions from Directors

    +

    24.5.7 Java exceptions from directors

    With directors routing method calls to Java, and proxies routing them -to C++, the handling of exceptions is an important concern. In Swig -2.0, the director class methods ignored java exceptions that occurred -during method calls dispatched to the Java director class and simply -returned '$null' to the C++ caller. The default behavior now throws a -Swig-defined DirectorException C++ exception. A facility -is now provided to allow translation of thrown Java exceptions into -C++ exceptions. This can be done in two different ways using -the %feature("director:except") directive. In the -simplest approach, a code block is attached to each director method to -handle the mapping of java exceptions into C++ exceptions. +to C++, the handling of exceptions is an important concern. +The default behavior from SWIG 3.0 +onwards is to convert the thrown Java exception into a SWIG defined +DirectorException C++ exception. +SWIG 2.0 and earlier versions didn't provide any mechanism to handle the Java director method exceptions in C++. +

    + +

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

    -// All the rules to associate a feature with an element apply
     %feature("director:except") MyClass::method(int x) {
    -  jthrowable $error = jenv->ExceptionOccurred();
    +  jthrowable $error = jenv->ExceptionOccurred();
       if ($error) {
    -    jenv->ExceptionClear();
    -    if (Swig::ExceptionMatches(jenv,$error,"java/lang/IndexOutOfBoundsException"))
    -      throw std::out_of_range(Swig::JavaExceptionMessage(jenv,$error).message());
    -    else if (Swig::ExceptionMatches(jenv,$error,"$packagepath/MyJavaException"))
    -      throw MyCppException(Swig::JavaExceptionMessage(jenv,$error).message());
    -    else
    -      throw std::runtime_error("Unexpected exception thrown by MyClass::method");
    +    jenv->ExceptionClear();
    +    if (Swig::ExceptionMatches(jenv, $error, "java/lang/IndexOutOfBoundsException"))
    +      throw std::out_of_range(Swig::JavaExceptionMessage(jenv, $error).message());
    +    if (Swig::ExceptionMatches(jenv, $error, "$packagepath/MyJavaException"))
    +      throw MyCppException(Swig::JavaExceptionMessage(jenv, $error).message());
    +    throw std::runtime_error("Unexpected exception thrown in MyClass::method");
       }
     }
     
     class MyClass {
    -  void method(int x); /* on C++ side, may get std::runtime_error or MyCppException */
    +  /** Throws either a std::out_of_range or MyCppException on error */
    +  void method(int x);
     }
     
    +

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

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

    Using directorthrows typemaps allows a -generic director:except feature to be combined with -method-specific handling to achieve the desired result. The -default director:except feature, in combination -with directorthrows typemaps generate exception mapping -to C++ exceptions for all the exceptions defined for each method. The -default definition is shown below.

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

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

     %feature("director:except") %{
    -   jthrowable $error = jenv->ExceptionOccurred();
    +   jthrowable $error = jenv->ExceptionOccurred();
        if ($error) {
    -     jenv->ExceptionClear();
    +     jenv->ExceptionClear();
          $directorthrowshandlers
          throw Swig::DirectorException(jenv, $error);
        }
    @@ -3657,34 +3666,66 @@ default definition is shown below.

    The code generated using the director:except feature -replaces the $directorthrowshandlers with code that throws -appropriate C++ exceptions from directorthrows typemaps -for each exception defined for the method. Just as with -the "throws" typemap, the -possible exceptions may be defined either with an exception -specification ( throw(MyException,std::runtime_error) ) or -using the %catches feature applied to the method.

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

    -

    Note: Using the %catches feature to define the -handled exceptions is preferred to using exception specifications. If -the interface is defined with an exception specification the generated -swig proxy classes will have the same exception specification. In C++ -if exceptions other than those in the specification are thrown, the -program will be terminated.

    +

    +Consider the following director method: +

    -

    Because this default definition maps any unhandled java exceptions to -Swig::DirectorException, any director methods that define exception -specifications will cause program termination. To simply ignore -unexpected exceptions, the default can be changed to: +

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

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

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

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

    + +

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

     %feature("director:except") %{
    -   jthrowable $error = jenv->ExceptionOccurred();
    +   jthrowable $error = jenv->ExceptionOccurred();
        if ($error) {
    -     jenv->ExceptionClear();
    +     jenv->ExceptionClear();
          $directorthrowshandlers
    -     return $null;
    +     return $null; // exception is ignored
        }
     %}
     
    @@ -3692,27 +3733,25 @@ unexpected exceptions, the default can be changed to:

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

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

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

    Below is a complete example demonstrating the use -of directorthrows typemaps. The directorthrows typemap -provides a code fragment to test for a pending java exception type, and the -resulting C++ exception that will be thrown. In this example, a -generic directorthrows typemap is appropriate for all three exceptions - all -take single string constructors. If the constructors had different constructors, +of the "directorthrows" typemaps. In this example, a +generic "directorthrows" typemap is appropriate for all three exceptions - all +take single string constructors. If the exceptions had different constructors, it would be neccessary to have separate typemaps for each exception type. @@ -3721,22 +3760,29 @@ it would be neccessary to have separate typemaps for each exception type. example interface that could be generated and built. -->

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

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

    -

    Note that the directorthrows typemaps are important +

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

    +Java exceptions via the Swig::DirectorException::raiseJavaException method, +as demonstrated with %javaexception below: +

    -%feature ("except",throws="Exception")  MyClass::myMeth %{
    -  try { $action }
    -  catch (Swig::DirectorException & direxcp) {
    -    // jenv always available in JNI code
    -    // raise the java exception that originally caused the DirectorException
    -    direxcp.raiseJavaException(jenv);
    +%javaexception("Exception") MyClass::myMethod %{
    +  try {
    +    $action
    +  } catch (Swig::DirectorException &e) {
    +    // raise/throw the Java exception that originally caused the DirectorException
    +    e.raiseJavaException(jenv);
         return $null;
       }
     %}
     
    -

    The throws="Exception" attribute on the exception -feature is necessary if any of the translated exceptions will be -checked exceptions, since the java compiler will otherwise assert that -no checked exceptions can be thrown by the method. This may be more -specific that the completely generic "Exception" class, of course. A -similar feature must be added to director methods to allow checked -exceptions to be thrown from the director method implementations. -Here, no actual exception handling is needed - the feature simply -is being used to add a generic checked exception signature to the -generated director method wrapper.

    - -
    -
    -%feature ("except",throws="Exception")  MyDirectorClass::myDirMeth %{ %}
    -
    -
    - - +

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

    24.6 Accessing protected members

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

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

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

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

    %typemap(directorthrows)

    +
    + +

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

    + +

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

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

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

    + +
    +

    %typemap(javapackage)

    diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index 5b507c123..e0debe41c 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -499,7 +499,7 @@ example.i(4) : Syntax error in input.
  • 474. Method method usage of the optimal attribute ignored in the out typemap as the following cannot be used to generate optimal code: code
  • 475. Multiple calls to method might be generated due to optimal attribute usage in the out typemap.
  • 476. Initialization using std::initializer_list. -
  • 477. Feature director:except on Class::method with $directorthrowshandlers requires directorthrows typemap for exception Exception +
  • 477. No directorthrows typemap defined for type From efe1d8aea7d72fca68cfa0730a32b6bee05f0fdb Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 9 Nov 2013 12:17:52 +0000 Subject: [PATCH 0758/1160] Update changes file with previous commit dropping .NET 1.1 support --- CHANGES.current | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 0f964b114..c587ff07f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,25 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-11-09: wsfulton + [C#] Apply patch #79 from Brant Kyser + - Remove using directives from the generated C# code and fully qualify the use of all .NET + framework types in order to minimize potential name collisions from input files defining + types, namespace, etc with the same name as .NET framework members. + - Globally qualify the use of .NET framework types in the System namespace + - Remove .NET 1.1 support, .NET 2 is the minimum for the C# module + + This is a potential backwards compatibility break if code has been added relying on these using + statements that used to be generated: + + using System; + using System.Runtime.InteropServices; + + The quick fix to add these back in is to add the -DSWIG2_CSHARP command line option when + executing SWIG. See CSharp.html documentation for more info. + + *** POTENTIAL INCOMPATIBILITY *** + 2013-11-05: wsfulton [Java] Fix some corner cases for the $packagepath/$javaclassname special variable substitution. From dfc02f306de0de87042991e6d6afedf587219af0 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Thu, 31 Oct 2013 20:49:15 +0400 Subject: [PATCH 0759/1160] First banch of tests --- .../test-suite/lua/cpp_namespace_runme.lua | 27 +++++++++ .../test-suite/lua/cpp_nodefault_runme.lua | 24 ++++++++ Examples/test-suite/lua/cpp_static_runme.lua | 16 +++++ Examples/test-suite/lua/cpp_typedef_runme.lua | 23 ++++++++ .../extend_constructor_destructor_runme.lua | 32 ++++++++++ .../test-suite/lua/extend_placement_runme.lua | 37 ++++++++++++ Examples/test-suite/lua/extend_runme.lua | 28 +++++++++ .../test-suite/lua/extend_template_runme.lua | 12 ++++ .../lua/extend_typedef_class_runme.lua | 37 ++++++++++++ .../test-suite/lua/extend_variable_runme.lua | 29 ++++++++++ Examples/test-suite/lua/friends_runme.lua | 27 +++++++++ Examples/test-suite/lua/funcptr_cpp_runme.lua | 18 ++++++ Examples/test-suite/lua/fvirtual_runme.lua | 17 ++++++ .../test-suite/lua/global_namespace_runme.lua | 58 +++++++++++++++++++ 14 files changed, 385 insertions(+) create mode 100644 Examples/test-suite/lua/cpp_namespace_runme.lua create mode 100644 Examples/test-suite/lua/cpp_nodefault_runme.lua create mode 100644 Examples/test-suite/lua/cpp_static_runme.lua create mode 100644 Examples/test-suite/lua/cpp_typedef_runme.lua create mode 100644 Examples/test-suite/lua/extend_constructor_destructor_runme.lua create mode 100644 Examples/test-suite/lua/extend_placement_runme.lua create mode 100644 Examples/test-suite/lua/extend_runme.lua create mode 100644 Examples/test-suite/lua/extend_template_runme.lua create mode 100644 Examples/test-suite/lua/extend_typedef_class_runme.lua create mode 100644 Examples/test-suite/lua/extend_variable_runme.lua create mode 100644 Examples/test-suite/lua/friends_runme.lua create mode 100644 Examples/test-suite/lua/funcptr_cpp_runme.lua create mode 100644 Examples/test-suite/lua/fvirtual_runme.lua create mode 100644 Examples/test-suite/lua/global_namespace_runme.lua diff --git a/Examples/test-suite/lua/cpp_namespace_runme.lua b/Examples/test-suite/lua/cpp_namespace_runme.lua new file mode 100644 index 000000000..620b42671 --- /dev/null +++ b/Examples/test-suite/lua/cpp_namespace_runme.lua @@ -0,0 +1,27 @@ +require("import") -- the import fn +import("cpp_namespace") -- import lib into global +cn=cpp_namespace --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert( cn.fact(4) == 24 ) +assert( cn.Foo == 42 ) + +t1 = cn.Test() +assert( t1:method() == "Test::method" ) + +cn.weird("t1", 4) + +assert( cn.do_method(t1) == "Test::method" ) +assert( cn.do_method2(t1) == "Test::method" ) + +t2 = cn.Test2() +assert( t2:method() == "Test2::method" ) + + +assert( cn.foo3(5) == 5 ) + +assert( cn.do_method3(t2, 7) == "Test2::method" ) diff --git a/Examples/test-suite/lua/cpp_nodefault_runme.lua b/Examples/test-suite/lua/cpp_nodefault_runme.lua new file mode 100644 index 000000000..52dc7a30c --- /dev/null +++ b/Examples/test-suite/lua/cpp_nodefault_runme.lua @@ -0,0 +1,24 @@ +-- Run file +require("import") -- the import fn +import("cpp_nodefault") -- import lib into global +cn=cpp_nodefault --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +foo1 = cn.Foo(1,2) +foo1.a = 5 +assert(foo1.a == 5) + +foo2 = cn.create(1,2) + +cn.consume(foo1,foo2) + +bar1 = cn.Bar() +bar1:consume( cn.gvar, foo2) +foo3 = bar1:create(1,2) + +foo3.a = 6 +assert( foo3.a == 6 ) diff --git a/Examples/test-suite/lua/cpp_static_runme.lua b/Examples/test-suite/lua/cpp_static_runme.lua new file mode 100644 index 000000000..e9ee887f2 --- /dev/null +++ b/Examples/test-suite/lua/cpp_static_runme.lua @@ -0,0 +1,16 @@ +-- demo of lua swig capacilities (operator overloading) +require("import") -- the import fn +import("cpp_static") -- import lib into global +cs=cpp_static --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +cs.StaticMemberTest.static_int = 5; +assert(cs.StaticMemberTest.static_int == 5); + +cs.StaticFunctionTest.static_func() +cs.StaticFunctionTest.static_func_2(2) +cs.StaticFunctionTest.static_func_3(3,3) diff --git a/Examples/test-suite/lua/cpp_typedef_runme.lua b/Examples/test-suite/lua/cpp_typedef_runme.lua new file mode 100644 index 000000000..e791f899a --- /dev/null +++ b/Examples/test-suite/lua/cpp_typedef_runme.lua @@ -0,0 +1,23 @@ + +require("import") -- the import fn +import("cpp_typedef") -- import lib into global +ct = cpp_typedef --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +foo1 = ct.Foo() +bar1 = foo1:bar() +bar2 = ct.Foo.sbar() + +u1 = ct.UnnamedStruct() +n1 = ct.TypedefNamedStruct() + +test = ct.Test() + +u2 = test:test1(u1) +n2 = test:test2(n1) +n3 = test:test3(n1) +n4 = test:test4(n1) diff --git a/Examples/test-suite/lua/extend_constructor_destructor_runme.lua b/Examples/test-suite/lua/extend_constructor_destructor_runme.lua new file mode 100644 index 000000000..7f18e07a2 --- /dev/null +++ b/Examples/test-suite/lua/extend_constructor_destructor_runme.lua @@ -0,0 +1,32 @@ +require("import") -- the import fn +import("extend_constructor_destructor") -- import lib into global +ecd=extend_constructor_destructor --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +a1 = ecd.AStruct(101) +assert(a1.ivar == 101) +assert(ecd.globalVar == 101) + +b1 = ecd.BStruct(201) +assert(b1.ivar == 201) +assert(ecd.globalVar == 201) + +c1 = ecd.CStruct(301) +assert(c1.ivar == 301) +assert(ecd.globalVar == 301) + +d1 = ecd.DStruct(401) +assert(d1.ivar == 401) +assert(ecd.globalVar == 401) + +e1 = ecd.EStruct(501) +assert(e1.ivar == 501) +assert(ecd.globalVar == 501) + +f1 = ecd.FStruct(601) +assert(f1.ivar == 601) +assert(ecd.globalVar == 601) diff --git a/Examples/test-suite/lua/extend_placement_runme.lua b/Examples/test-suite/lua/extend_placement_runme.lua new file mode 100644 index 000000000..96108a979 --- /dev/null +++ b/Examples/test-suite/lua/extend_placement_runme.lua @@ -0,0 +1,37 @@ +require("import") -- the import fn +import("extend_placement") -- import lib into global +ep=extend_placement --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +function test_obj( main, suppl ) + assert(main:spam() == 1) + assert(main:spam("this_is_string") == 2) + assert(main:spam(5) == 5) + assert(main:spam(5,6) == 11) + assert(main:spam( 7,8,9) == 15) + assert(main:spam(suppl,12.0) == 0) + assert(main:spam(suppl) == 0) +end + +foo1 = ep.Foo(0) +foo2 = ep.Foo(1,2) +foo3 = ep.Foo() +test_obj(foo1,foo2) + + +bar1 = ep.Bar() +bar2 = ep.Bar(5) +test_obj(bar1,bar2) + +fti1 = ep.FooTi(0) +fti2 = ep.FooTi(1,2) +fti3 = ep.FooTi() +test_obj(fti1,foo1) + +bti1 = ep.BarTi() +bti2 = ep.BarTi(5) +test_obj(bti1,bar1) diff --git a/Examples/test-suite/lua/extend_runme.lua b/Examples/test-suite/lua/extend_runme.lua new file mode 100644 index 000000000..026f20d81 --- /dev/null +++ b/Examples/test-suite/lua/extend_runme.lua @@ -0,0 +1,28 @@ +require("import") -- the import fn +import("extend") -- import lib into global +e=extend --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +base1 = e.Base() +assert(base1.value == 0) +base2 = e.Base(10) +assert(base2.value == 10) + +assert(base1:method(5) == 5) +assert(e.Base.zeroVal() == 0) +assert(base2:currentValue() == 10) +assert(base2:extendmethod(7) == 14) + +der1 = e.Derived(0) +assert(der1.value == 0) +assert(der1:method(5) == 10) + +der2 = e.Derived(17) +assert(der2.value == 34) +der2.extendval = 200.0 +assert( math.abs(der2.actualval - 2.0) < 0.001 ) +assert( math.abs(der2.extendval - 200.0) < 0.001 ) diff --git a/Examples/test-suite/lua/extend_template_runme.lua b/Examples/test-suite/lua/extend_template_runme.lua new file mode 100644 index 000000000..987d599f1 --- /dev/null +++ b/Examples/test-suite/lua/extend_template_runme.lua @@ -0,0 +1,12 @@ +require("import") -- the import fn +import("extend_template") -- import lib into global +et=extend_template--alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +foo1 = et.Foo_0() +assert(foo1:test1(5) == 5) +assert(foo1:test2(7) == 7) diff --git a/Examples/test-suite/lua/extend_typedef_class_runme.lua b/Examples/test-suite/lua/extend_typedef_class_runme.lua new file mode 100644 index 000000000..c2535483f --- /dev/null +++ b/Examples/test-suite/lua/extend_typedef_class_runme.lua @@ -0,0 +1,37 @@ +require("import") -- the import fn +import("extend_typedef_class") -- import lib into global +etc=extend_typedef_class --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +function test_obj( obj, const ) + obj.membervar = const + assert(obj:getvar() == const) +end + +a1 = etc.AClass() +test_obj(a1,1) + +b1 = etc.BClass() +test_obj(b1,2) + +c1 = etc.CClass() +test_obj(c1,3) + +d1 = etc.DClass() +test_obj(d1,4) + +a2 = etc.AStruct() +test_obj(a2,5) + +b2 = etc.BStruct() +test_obj(b2,6) + +c2 = etc.CStruct() +test_obj(c2,7) + +d2 = etc.DStruct() +test_obj(d2,8) diff --git a/Examples/test-suite/lua/extend_variable_runme.lua b/Examples/test-suite/lua/extend_variable_runme.lua new file mode 100644 index 000000000..cc2b6844e --- /dev/null +++ b/Examples/test-suite/lua/extend_variable_runme.lua @@ -0,0 +1,29 @@ +require("import") -- the import fn +import("extend_variable") -- import lib into global +ev=extend_variable --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +e1 = ev.ExtendMe() +answ = 1.0 +assert( e1:set(7.0) ) +--assert( e1:get(answ) ) -- doesn't work. Lua can't pass primitive type by non-const reference +--assert( answ == 7.0 ) + +e1.ExtendVar = 5.0 +assert(e1.ExtendVar == 5.0) + +assert(ev.Foo.Bar == 42) +assert(ev.Foo.AllBarOne == 4422) + +assert(ev.Foo.StaticInt == 1111) +ev.Foo.StaticInt = 3333 +assert(ev.Foo.StaticInt == 3333) + +assert(ev.Foo.StaticConstInt == 2222) + +b1 = ev.Bar() +assert(b1.x == 1) diff --git a/Examples/test-suite/lua/friends_runme.lua b/Examples/test-suite/lua/friends_runme.lua new file mode 100644 index 000000000..499322691 --- /dev/null +++ b/Examples/test-suite/lua/friends_runme.lua @@ -0,0 +1,27 @@ +require("import") -- the import fn +import("friends") -- import lib into global +f=friends --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +f.globalscope() + +b1 = f.B(5) +a1 = f.A(10) + +assert(f.get_val1(a1) == 10) +assert(f.get_val1(a1, 2) == 12) +assert(f.get_val2(a1) == 20) +assert(f.get_val3(a1) == 30) + +assert(f.get_val1(100, 1, 2) == 100) + +assert( f.mix(a1,b1) == 15); + +d1 = f.D_i(7) +assert(f.get_val1(d1) == 7) +f.set(d1,9) +assert(f.get_val1(d1) == 9) diff --git a/Examples/test-suite/lua/funcptr_cpp_runme.lua b/Examples/test-suite/lua/funcptr_cpp_runme.lua new file mode 100644 index 000000000..ba396da51 --- /dev/null +++ b/Examples/test-suite/lua/funcptr_cpp_runme.lua @@ -0,0 +1,18 @@ +require("import") -- the import fn +import("funcptr_cpp") -- import lib into global +fc=funcptr_cpp --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert( fc.addByValue(5,10) == 15) +-- These two won't work. Lua will successfully store the answer as userdata, but there is +-- no way of accessing the insides of userdata. +-- assert( fc.addByPointer(7, 9) == 16) +-- assert( fc.addByReference(8, 9) == 17) + +assert( fc.call1(fc.ADD_BY_VALUE, 5, 10) == 15) +assert( fc.call2(fc.ADD_BY_POINTER, 7, 9) == 16) +assert( fc.call3(fc.ADD_BY_REFERENCE, 8, 9) == 17) diff --git a/Examples/test-suite/lua/fvirtual_runme.lua b/Examples/test-suite/lua/fvirtual_runme.lua new file mode 100644 index 000000000..7f3056535 --- /dev/null +++ b/Examples/test-suite/lua/fvirtual_runme.lua @@ -0,0 +1,17 @@ +require("import") -- the import fn +import("fvirtual") -- import lib into global +f=fvirtual --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +n1 = f.Node() +n2 = f.Node() +assert(n1:addChild(n2) == 1) + +ns = f.NodeSwitch() +assert(ns:addChild(n2) == 2) +assert(ns:addChild(ns) == 2) +assert(ns:addChild(n1, false) == 3) diff --git a/Examples/test-suite/lua/global_namespace_runme.lua b/Examples/test-suite/lua/global_namespace_runme.lua new file mode 100644 index 000000000..b06caf722 --- /dev/null +++ b/Examples/test-suite/lua/global_namespace_runme.lua @@ -0,0 +1,58 @@ +require("import") -- the import fn +import("global_namespace") -- import lib into global +gn=global_namespace --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +k1 = gn.Klass1() +k2 = gn.Klass2() +k3 = gn.Klass3() +k4 = gn.Klass4() +k5 = gn.Klass5() +k6 = gn.Klass6() +k7 = gn.Klass7() + +gn.KlassMethods.methodA(k1,k2,k3,k4,k5,k6,k7) +gn.KlassMethods.methodB(k1,k2,k3,k4,k5,k6,k7) + +k1 = gn.getKlass1A() +k2 = gn.getKlass2A() +k3 = gn.getKlass3A() +k4 = gn.getKlass4A() +k5 = gn.getKlass5A() +k6 = gn.getKlass6A() +k7 = gn.getKlass7A() + +gn.KlassMethods.methodA(k1,k2,k3,k4,k5,k6,k7) +gn.KlassMethods.methodB(k1,k2,k3,k4,k5,k6,k7) + +k1 = gn.getKlass1B() +k2 = gn.getKlass2B() +k3 = gn.getKlass3B() +k4 = gn.getKlass4B() +k5 = gn.getKlass5B() +k6 = gn.getKlass6B() +k7 = gn.getKlass7B() + +gn.KlassMethods.methodA(k1,k2,k3,k4,k5,k6,k7) +gn.KlassMethods.methodB(k1,k2,k3,k4,k5,k6,k7) + +x1 = gn.XYZ1() +x2 = gn.XYZ2() +x3 = gn.XYZ3() +x4 = gn.XYZ4() +x5 = gn.XYZ5() +x6 = gn.XYZ6() +x7 = gn.XYZ7() + +gn.XYZMethods.methodA(x1,x2,x3,x4,x5,x6,x7) +gn.XYZMethods.methodB(x1,x2,x3,x4,x5,x6,x7) + +gn.AnEnumMethods.methodA(gn.anenum1, gn.anenum2, gn.anenum3) +gn.AnEnumMethods.methodB(gn.anenum1, gn.anenum2, gn.anenum3) + +gn.TheEnumMethods.methodA(gn.theenum1, gn.theenum2, gn.theenum3) +gn.TheEnumMethods.methodB(gn.theenum1, gn.theenum2, gn.theenum3) From c9279ab0e77dbc9a565b0a427fb9b5f36472b6b5 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Thu, 31 Oct 2013 23:25:40 +0400 Subject: [PATCH 0760/1160] More tests --- Examples/test-suite/keyword_rename.i | 4 +++ Examples/test-suite/lua/grouping_runme.lua | 17 ++++++++++ Examples/test-suite/lua/iadd_runme.lua | 17 ++++++++++ .../test-suite/lua/keyword_rename_runme.lua | 16 +++++++++ .../lua/overload_complicated_runme.lua | 22 ++++++++++++ .../lua/smart_pointer_extend_runme.lua | 34 +++++++++++++++++++ .../lua/smart_pointer_inherit_runme.lua | 18 ++++++++++ .../lua/smart_pointer_multi_runme.lua | 23 +++++++++++++ .../lua/smart_pointer_not_runme.lua | 25 ++++++++++++++ .../lua/smart_pointer_rename_runme.lua | 18 ++++++++++ .../lua/smart_pointer_simple_runme.lua | 22 ++++++++++++ .../smart_pointer_templatemethods_runme.lua | 18 ++++++++++ .../lua/template_construct_runme.lua | 10 ++++++ .../test-suite/lua/template_extend1_runme.lua | 14 ++++++++ .../test-suite/lua/template_extend2_runme.lua | 14 ++++++++ .../test-suite/lua/template_inherit_runme.lua | 24 +++++++++++++ 16 files changed, 296 insertions(+) create mode 100644 Examples/test-suite/lua/grouping_runme.lua create mode 100644 Examples/test-suite/lua/iadd_runme.lua create mode 100644 Examples/test-suite/lua/keyword_rename_runme.lua create mode 100644 Examples/test-suite/lua/overload_complicated_runme.lua create mode 100644 Examples/test-suite/lua/smart_pointer_extend_runme.lua create mode 100644 Examples/test-suite/lua/smart_pointer_inherit_runme.lua create mode 100644 Examples/test-suite/lua/smart_pointer_multi_runme.lua create mode 100644 Examples/test-suite/lua/smart_pointer_not_runme.lua create mode 100644 Examples/test-suite/lua/smart_pointer_rename_runme.lua create mode 100644 Examples/test-suite/lua/smart_pointer_simple_runme.lua create mode 100644 Examples/test-suite/lua/smart_pointer_templatemethods_runme.lua create mode 100644 Examples/test-suite/lua/template_construct_runme.lua create mode 100644 Examples/test-suite/lua/template_extend1_runme.lua create mode 100644 Examples/test-suite/lua/template_extend2_runme.lua create mode 100644 Examples/test-suite/lua/template_inherit_runme.lua diff --git a/Examples/test-suite/keyword_rename.i b/Examples/test-suite/keyword_rename.i index 6a6082ff9..46c3338b3 100644 --- a/Examples/test-suite/keyword_rename.i +++ b/Examples/test-suite/keyword_rename.i @@ -31,6 +31,10 @@ struct sealed {int i;}; KW(go, defer) KW(chan, fallthrough) +/* Lua keywords */ +KW(end, function) +KW(nil,local) + %} diff --git a/Examples/test-suite/lua/grouping_runme.lua b/Examples/test-suite/lua/grouping_runme.lua new file mode 100644 index 000000000..798a7359e --- /dev/null +++ b/Examples/test-suite/lua/grouping_runme.lua @@ -0,0 +1,17 @@ +require("import") -- the import fn +import("grouping") -- import lib into global +g=grouping --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert( g.test1(5) == 5 ) +g.test2(42) -- Return value is int* packed into userdata. We can't do anything with it + +assert( g.test3 == 37 ) +g.test3 = 42 +assert( g.test3 == 42 ) + +assert( g.do_unary(5, g.NEGATE) == -5 ) diff --git a/Examples/test-suite/lua/iadd_runme.lua b/Examples/test-suite/lua/iadd_runme.lua new file mode 100644 index 000000000..556644061 --- /dev/null +++ b/Examples/test-suite/lua/iadd_runme.lua @@ -0,0 +1,17 @@ +require("import") -- the import fn +import("iadd") -- import lib into global +i=iadd --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +foo1 = i.Foo() +foo1_a = foo1.AsA +assert( foo1_a.x == 5 ) +assert( foo1_a:get_me().x == 5 ) +-- Unfortunately, in Lua operator+= can't be overloaded + +foo1.AsLong = 1000 +assert( foo1.AsLong == 1000 ) diff --git a/Examples/test-suite/lua/keyword_rename_runme.lua b/Examples/test-suite/lua/keyword_rename_runme.lua new file mode 100644 index 000000000..5d54ef123 --- /dev/null +++ b/Examples/test-suite/lua/keyword_rename_runme.lua @@ -0,0 +1,16 @@ +require("import") -- the import fn +import("keyword_rename") -- import lib into global +kn=keyword_rename--alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + + +-- assert( kn.end(5) == 5 ) -- Curretly SWIG/Lua doesn't rename keywords +-- assert( kn.nil(7) == 7 ) + +-- But you can always access wrongly named members using string constants +assert( kn["end"](5) == 5 ) +assert( kn["nil"](7) == 7 ) diff --git a/Examples/test-suite/lua/overload_complicated_runme.lua b/Examples/test-suite/lua/overload_complicated_runme.lua new file mode 100644 index 000000000..5670607bf --- /dev/null +++ b/Examples/test-suite/lua/overload_complicated_runme.lua @@ -0,0 +1,22 @@ +require("import") -- the import fn +import("overload_complicated") -- import lib into global +oc=overload_complicated --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert( oc.foo(1,1,"test",1) == 15 ) + +p1 = oc.Pop(nil) +p1 = oc.Pop(nil,false) + +assert( p1:hip(true) == 701 ) +assert( p1:hip(nil) == 702 ) + +assert( p1:hop(true) == 801 ) +assert( p1:hop(nil) == 805 ) + +assert( oc.muzak(true) == 3001 ) +assert( oc.muzak(nil) == 3002 ) diff --git a/Examples/test-suite/lua/smart_pointer_extend_runme.lua b/Examples/test-suite/lua/smart_pointer_extend_runme.lua new file mode 100644 index 000000000..6d33c57b1 --- /dev/null +++ b/Examples/test-suite/lua/smart_pointer_extend_runme.lua @@ -0,0 +1,34 @@ +require("import") -- the import fn +import("smart_pointer_extend") -- import lib into global +spe=smart_pointer_extend --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert( spe.CBase.hello() == 1 ) +assert( spe.CBase.z == 1 ) + +base1 = spe.CBase() +base1.x = 7 + +p1 = spe.CPtr() + +assert( spe.get_hello(p1) == 1 ) +assert( p1:foo() == 1 ) +assert( p1:bar() == 2 ) +assert( p1:boo(5) == 5 ) + +foo = spe.Foo() +bar = spe.Bar(foo) + +assert( bar:extension(5,7) == 5 ) +assert( bar:extension(7) == 7 ) +assert( bar:extension() == 1 ) + +dfoo = spe.DFoo() +dptr = spe.DPtrFoo(dfoo) + +assert( dptr:Ext() == 2 ) +assert( dptr:Ext(5) == 5 ) diff --git a/Examples/test-suite/lua/smart_pointer_inherit_runme.lua b/Examples/test-suite/lua/smart_pointer_inherit_runme.lua new file mode 100644 index 000000000..75510ad08 --- /dev/null +++ b/Examples/test-suite/lua/smart_pointer_inherit_runme.lua @@ -0,0 +1,18 @@ +require("import") -- the import fn +import("smart_pointer_inherit") -- import lib into global +spi=smart_pointer_inherit --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +der = spi.Derived(7) + +ptr = spi.SmartDerived(der) + +assert( ptr.val == 7 ) +assert( ptr:value() == 7 ) +assert( ptr:value2() == 7 ) +assert( ptr:value3() == 7 ) +assert( ptr:valuehide() == -1 ) diff --git a/Examples/test-suite/lua/smart_pointer_multi_runme.lua b/Examples/test-suite/lua/smart_pointer_multi_runme.lua new file mode 100644 index 000000000..ed3693727 --- /dev/null +++ b/Examples/test-suite/lua/smart_pointer_multi_runme.lua @@ -0,0 +1,23 @@ +require("import") -- the import fn +import("smart_pointer_multi") -- import lib into global +spm=smart_pointer_multi --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +foo = spm.Foo() +foo.x = 5 +assert( foo:getx() == 5 ) + +bar = spm.Bar(foo) +spam = spm.Spam(bar) +grok = spm.Grok(bar) + +assert( bar:getx() == 5 ) +assert( spam:getx() == 5 ) +spam.x = 7 +assert( grok:getx() == 7 ) +grok.x = 10 +assert( foo:getx() == 10 ) diff --git a/Examples/test-suite/lua/smart_pointer_not_runme.lua b/Examples/test-suite/lua/smart_pointer_not_runme.lua new file mode 100644 index 000000000..2f009a7f6 --- /dev/null +++ b/Examples/test-suite/lua/smart_pointer_not_runme.lua @@ -0,0 +1,25 @@ +require("import") -- the import fn +import("smart_pointer_not") -- import lib into global +spn=smart_pointer_not --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + + +foo = spn.Foo() +foo.x = 7 +assert( foo:getx() == 7 ) + +bar = spn.Bar(foo) +success = pcall(bar.getx, bar) -- Bar is not a smart pointer. Call should fail +assert( not success ) + +spam = spn.Spam(foo) +success = pcall(spam.getx, spam) -- Spam is not a smart pointer. Call should fail +assert( not success ) + +grok = spn.Grok(foo) +success = pcall(grok.getx, grok) -- Spam is not a smart pointer. Call should fail +assert( not success ) diff --git a/Examples/test-suite/lua/smart_pointer_rename_runme.lua b/Examples/test-suite/lua/smart_pointer_rename_runme.lua new file mode 100644 index 000000000..51b07f61b --- /dev/null +++ b/Examples/test-suite/lua/smart_pointer_rename_runme.lua @@ -0,0 +1,18 @@ +require("import") -- the import fn +import("smart_pointer_rename") -- import lib into global +spr=smart_pointer_rename --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + + +foo = spr.Foo() +assert( foo:ftest1(1) == 1 ) +assert( foo:ftest2(1,2) == 2 ) + +bar = spr.Bar(foo) +assert( bar:test() == 3 ) +assert( bar:ftest1(1) == 1 ) +assert( bar:ftest2(1,2) == 2 ) diff --git a/Examples/test-suite/lua/smart_pointer_simple_runme.lua b/Examples/test-suite/lua/smart_pointer_simple_runme.lua new file mode 100644 index 000000000..8513931b2 --- /dev/null +++ b/Examples/test-suite/lua/smart_pointer_simple_runme.lua @@ -0,0 +1,22 @@ +require("import") -- the import fn +import("smart_pointer_simple") -- import lib into global +sps=smart_pointer_simple --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +foo1 = sps.Foo() +foo1.x = 5 +assert( foo1.x == 5 ) +assert( foo1:getx() == 5 ) + +bar1 = sps.Bar(foo1) +bar1.x = 3 +assert(bar1.x == 3) +assert(bar1:getx() == 3) + +bar1.x = 5 +assert(bar1.x == 5) +assert(bar1:getx() == 5) diff --git a/Examples/test-suite/lua/smart_pointer_templatemethods_runme.lua b/Examples/test-suite/lua/smart_pointer_templatemethods_runme.lua new file mode 100644 index 000000000..018881c42 --- /dev/null +++ b/Examples/test-suite/lua/smart_pointer_templatemethods_runme.lua @@ -0,0 +1,18 @@ +require("import") -- the import fn +import("smart_pointer_templatemethods") -- import lib into global +spt=smart_pointer_templatemethods --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +o1 = spt.Objct() + +iid = spt.InterfaceId() + +po2 = o1:QueryInterfaceObjct(iid) +-- we can't call po2:DisposeObjct, because smart pointer Ptr always return 0 when dereferencing +-- (see interface file). So we only check that po2 has necessary method +assert( po2.DisposeObjct ~= nil ) +assert( po2.QueryInterfaceObjct ~= nil ) diff --git a/Examples/test-suite/lua/template_construct_runme.lua b/Examples/test-suite/lua/template_construct_runme.lua new file mode 100644 index 000000000..aad9c3be4 --- /dev/null +++ b/Examples/test-suite/lua/template_construct_runme.lua @@ -0,0 +1,10 @@ +require("import") -- the import fn +import("template_construct") -- import lib into global +tc=template_construct --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +foo = tc.Foo_int(1) diff --git a/Examples/test-suite/lua/template_extend1_runme.lua b/Examples/test-suite/lua/template_extend1_runme.lua new file mode 100644 index 000000000..44774e949 --- /dev/null +++ b/Examples/test-suite/lua/template_extend1_runme.lua @@ -0,0 +1,14 @@ +require("import") -- the import fn +import("template_extend1") -- import lib into global +te=template_extend1 --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +lb = te.lBaz() +assert( lb:foo() == "lBaz::foo" ) + +db = te.dBaz() +assert( db:foo() == "dBaz::foo" ) diff --git a/Examples/test-suite/lua/template_extend2_runme.lua b/Examples/test-suite/lua/template_extend2_runme.lua new file mode 100644 index 000000000..23c25705b --- /dev/null +++ b/Examples/test-suite/lua/template_extend2_runme.lua @@ -0,0 +1,14 @@ +require("import") -- the import fn +import("template_extend2") -- import lib into global +te=template_extend2 --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +lb = te.lBaz() +assert( lb:foo() == "lBaz::foo" ) + +db = te.dBaz() +assert( db:foo() == "dBaz::foo" ) diff --git a/Examples/test-suite/lua/template_inherit_runme.lua b/Examples/test-suite/lua/template_inherit_runme.lua new file mode 100644 index 000000000..f2bfca00b --- /dev/null +++ b/Examples/test-suite/lua/template_inherit_runme.lua @@ -0,0 +1,24 @@ +require("import") -- the import fn +import("template_inherit") -- import lib into global +ti=template_inherit --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + + +fi = ti.FooInt() +assert( fi:blah() == "Foo" ) +assert( fi:foomethod() == "foomethod" ) + +bi = ti.BarInt() +assert( bi:blah() == "Bar" ) +assert( bi:foomethod() == "foomethod" ) + +assert( ti.invoke_blah_int(fi) == "Foo" ) +assert( ti.invoke_blah_int(bi) == "Bar" ) + +bd = ti.BarDouble() +success = pcall( ti.invoke_blah_int, bd ) +assert( not success ) From b9ba05be81dd466c15e7bf5d88e2e87a35ab3f09 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Fri, 1 Nov 2013 02:09:06 +0400 Subject: [PATCH 0761/1160] Style patches --- .../test-suite/lua/cpp_namespace_runme.lua | 16 +++++++------- .../test-suite/lua/cpp_nodefault_runme.lua | 4 ++-- .../test-suite/lua/extend_placement_runme.lua | 4 ++-- Examples/test-suite/lua/extend_runme.lua | 4 ++-- .../lua/extend_typedef_class_runme.lua | 2 +- .../test-suite/lua/extend_variable_runme.lua | 6 ++--- Examples/test-suite/lua/friends_runme.lua | 2 +- Examples/test-suite/lua/funcptr_cpp_runme.lua | 12 +++++----- Examples/test-suite/lua/grouping_runme.lua | 8 +++---- Examples/test-suite/lua/iadd_runme.lua | 6 ++--- .../test-suite/lua/keyword_rename_runme.lua | 8 +++---- .../test-suite/lua/li_std_vector_runme.lua | 2 +- .../lua/overload_complicated_runme.lua | 14 ++++++------ .../lua/smart_pointer_extend_runme.lua | 22 +++++++++---------- .../lua/smart_pointer_inherit_runme.lua | 10 ++++----- .../lua/smart_pointer_multi_runme.lua | 10 ++++----- .../lua/smart_pointer_not_runme.lua | 8 +++---- .../lua/smart_pointer_rename_runme.lua | 10 ++++----- .../lua/smart_pointer_simple_runme.lua | 4 ++-- .../smart_pointer_templatemethods_runme.lua | 4 ++-- .../test-suite/lua/template_extend1_runme.lua | 4 ++-- .../test-suite/lua/template_extend2_runme.lua | 4 ++-- .../test-suite/lua/template_inherit_runme.lua | 16 +++++++------- 23 files changed, 90 insertions(+), 90 deletions(-) diff --git a/Examples/test-suite/lua/cpp_namespace_runme.lua b/Examples/test-suite/lua/cpp_namespace_runme.lua index 620b42671..6f59cb14b 100644 --- a/Examples/test-suite/lua/cpp_namespace_runme.lua +++ b/Examples/test-suite/lua/cpp_namespace_runme.lua @@ -7,21 +7,21 @@ local env = _ENV -- Lua 5.2 if not env then env = getfenv () end -- Lua 5.1 setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) -assert( cn.fact(4) == 24 ) -assert( cn.Foo == 42 ) +assert(cn.fact(4) == 24) +assert(cn.Foo == 42) t1 = cn.Test() -assert( t1:method() == "Test::method" ) +assert(t1:method() == "Test::method") cn.weird("t1", 4) -assert( cn.do_method(t1) == "Test::method" ) -assert( cn.do_method2(t1) == "Test::method" ) +assert(cn.do_method(t1) == "Test::method") +assert(cn.do_method2(t1) == "Test::method") t2 = cn.Test2() -assert( t2:method() == "Test2::method" ) +assert(t2:method() == "Test2::method") -assert( cn.foo3(5) == 5 ) +assert(cn.foo3(5) == 5) -assert( cn.do_method3(t2, 7) == "Test2::method" ) +assert(cn.do_method3(t2, 7) == "Test2::method") diff --git a/Examples/test-suite/lua/cpp_nodefault_runme.lua b/Examples/test-suite/lua/cpp_nodefault_runme.lua index 52dc7a30c..86f5e840d 100644 --- a/Examples/test-suite/lua/cpp_nodefault_runme.lua +++ b/Examples/test-suite/lua/cpp_nodefault_runme.lua @@ -17,8 +17,8 @@ foo2 = cn.create(1,2) cn.consume(foo1,foo2) bar1 = cn.Bar() -bar1:consume( cn.gvar, foo2) +bar1:consume(cn.gvar, foo2) foo3 = bar1:create(1,2) foo3.a = 6 -assert( foo3.a == 6 ) +assert(foo3.a == 6) diff --git a/Examples/test-suite/lua/extend_placement_runme.lua b/Examples/test-suite/lua/extend_placement_runme.lua index 96108a979..28a2380d5 100644 --- a/Examples/test-suite/lua/extend_placement_runme.lua +++ b/Examples/test-suite/lua/extend_placement_runme.lua @@ -7,12 +7,12 @@ local env = _ENV -- Lua 5.2 if not env then env = getfenv () end -- Lua 5.1 setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) -function test_obj( main, suppl ) +function test_obj(main, suppl) assert(main:spam() == 1) assert(main:spam("this_is_string") == 2) assert(main:spam(5) == 5) assert(main:spam(5,6) == 11) - assert(main:spam( 7,8,9) == 15) + assert(main:spam(7,8,9) == 15) assert(main:spam(suppl,12.0) == 0) assert(main:spam(suppl) == 0) end diff --git a/Examples/test-suite/lua/extend_runme.lua b/Examples/test-suite/lua/extend_runme.lua index 026f20d81..3944dbfe8 100644 --- a/Examples/test-suite/lua/extend_runme.lua +++ b/Examples/test-suite/lua/extend_runme.lua @@ -24,5 +24,5 @@ assert(der1:method(5) == 10) der2 = e.Derived(17) assert(der2.value == 34) der2.extendval = 200.0 -assert( math.abs(der2.actualval - 2.0) < 0.001 ) -assert( math.abs(der2.extendval - 200.0) < 0.001 ) +assert(math.abs(der2.actualval - 2.0) < 0.001) +assert(math.abs(der2.extendval - 200.0) < 0.001) diff --git a/Examples/test-suite/lua/extend_typedef_class_runme.lua b/Examples/test-suite/lua/extend_typedef_class_runme.lua index c2535483f..66c9c670a 100644 --- a/Examples/test-suite/lua/extend_typedef_class_runme.lua +++ b/Examples/test-suite/lua/extend_typedef_class_runme.lua @@ -7,7 +7,7 @@ local env = _ENV -- Lua 5.2 if not env then env = getfenv () end -- Lua 5.1 setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) -function test_obj( obj, const ) +function test_obj(obj, const) obj.membervar = const assert(obj:getvar() == const) end diff --git a/Examples/test-suite/lua/extend_variable_runme.lua b/Examples/test-suite/lua/extend_variable_runme.lua index cc2b6844e..58e9c984a 100644 --- a/Examples/test-suite/lua/extend_variable_runme.lua +++ b/Examples/test-suite/lua/extend_variable_runme.lua @@ -9,9 +9,9 @@ setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i e1 = ev.ExtendMe() answ = 1.0 -assert( e1:set(7.0) ) ---assert( e1:get(answ) ) -- doesn't work. Lua can't pass primitive type by non-const reference ---assert( answ == 7.0 ) +assert(e1:set(7.0)) +--assert(e1:get(answ)) -- doesn't work. Lua can't pass primitive type by non-const reference +--assert(answ == 7.0) e1.ExtendVar = 5.0 assert(e1.ExtendVar == 5.0) diff --git a/Examples/test-suite/lua/friends_runme.lua b/Examples/test-suite/lua/friends_runme.lua index 499322691..bdf97934d 100644 --- a/Examples/test-suite/lua/friends_runme.lua +++ b/Examples/test-suite/lua/friends_runme.lua @@ -19,7 +19,7 @@ assert(f.get_val3(a1) == 30) assert(f.get_val1(100, 1, 2) == 100) -assert( f.mix(a1,b1) == 15); +assert(f.mix(a1,b1) == 15); d1 = f.D_i(7) assert(f.get_val1(d1) == 7) diff --git a/Examples/test-suite/lua/funcptr_cpp_runme.lua b/Examples/test-suite/lua/funcptr_cpp_runme.lua index ba396da51..3b8469348 100644 --- a/Examples/test-suite/lua/funcptr_cpp_runme.lua +++ b/Examples/test-suite/lua/funcptr_cpp_runme.lua @@ -7,12 +7,12 @@ local env = _ENV -- Lua 5.2 if not env then env = getfenv () end -- Lua 5.1 setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) -assert( fc.addByValue(5,10) == 15) +assert(fc.addByValue(5,10) == 15) -- These two won't work. Lua will successfully store the answer as userdata, but there is -- no way of accessing the insides of userdata. --- assert( fc.addByPointer(7, 9) == 16) --- assert( fc.addByReference(8, 9) == 17) +-- assert(fc.addByPointer(7, 9) == 16) +-- assert(fc.addByReference(8, 9) == 17) -assert( fc.call1(fc.ADD_BY_VALUE, 5, 10) == 15) -assert( fc.call2(fc.ADD_BY_POINTER, 7, 9) == 16) -assert( fc.call3(fc.ADD_BY_REFERENCE, 8, 9) == 17) +assert(fc.call1(fc.ADD_BY_VALUE, 5, 10) == 15) +assert(fc.call2(fc.ADD_BY_POINTER, 7, 9) == 16) +assert(fc.call3(fc.ADD_BY_REFERENCE, 8, 9) == 17) diff --git a/Examples/test-suite/lua/grouping_runme.lua b/Examples/test-suite/lua/grouping_runme.lua index 798a7359e..7ab08499f 100644 --- a/Examples/test-suite/lua/grouping_runme.lua +++ b/Examples/test-suite/lua/grouping_runme.lua @@ -7,11 +7,11 @@ local env = _ENV -- Lua 5.2 if not env then env = getfenv () end -- Lua 5.1 setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) -assert( g.test1(5) == 5 ) +assert(g.test1(5) == 5) g.test2(42) -- Return value is int* packed into userdata. We can't do anything with it -assert( g.test3 == 37 ) +assert(g.test3 == 37) g.test3 = 42 -assert( g.test3 == 42 ) +assert(g.test3 == 42) -assert( g.do_unary(5, g.NEGATE) == -5 ) +assert(g.do_unary(5, g.NEGATE) == -5) diff --git a/Examples/test-suite/lua/iadd_runme.lua b/Examples/test-suite/lua/iadd_runme.lua index 556644061..214433795 100644 --- a/Examples/test-suite/lua/iadd_runme.lua +++ b/Examples/test-suite/lua/iadd_runme.lua @@ -9,9 +9,9 @@ setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i foo1 = i.Foo() foo1_a = foo1.AsA -assert( foo1_a.x == 5 ) -assert( foo1_a:get_me().x == 5 ) +assert(foo1_a.x == 5) +assert(foo1_a:get_me().x == 5) -- Unfortunately, in Lua operator+= can't be overloaded foo1.AsLong = 1000 -assert( foo1.AsLong == 1000 ) +assert(foo1.AsLong == 1000) diff --git a/Examples/test-suite/lua/keyword_rename_runme.lua b/Examples/test-suite/lua/keyword_rename_runme.lua index 5d54ef123..a9dea466a 100644 --- a/Examples/test-suite/lua/keyword_rename_runme.lua +++ b/Examples/test-suite/lua/keyword_rename_runme.lua @@ -8,9 +8,9 @@ if not env then env = getfenv () end -- Lua 5.1 setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) --- assert( kn.end(5) == 5 ) -- Curretly SWIG/Lua doesn't rename keywords --- assert( kn.nil(7) == 7 ) +-- assert(kn.end(5) == 5) -- Curretly SWIG/Lua doesn't rename keywords +-- assert(kn.nil(7) == 7) -- But you can always access wrongly named members using string constants -assert( kn["end"](5) == 5 ) -assert( kn["nil"](7) == 7 ) +assert(kn["end"](5) == 5) +assert(kn["nil"](7) == 7) diff --git a/Examples/test-suite/lua/li_std_vector_runme.lua b/Examples/test-suite/lua/li_std_vector_runme.lua index 81994b92f..361b42461 100644 --- a/Examples/test-suite/lua/li_std_vector_runme.lua +++ b/Examples/test-suite/lua/li_std_vector_runme.lua @@ -43,7 +43,7 @@ for i=0,3 do end for i=0,3 do - assert( swig_type(sv[i]) =='Struct *' and sv[i].num==i) + assert(swig_type(sv[i]) =='Struct *' and sv[i].num==i) end -- range checking diff --git a/Examples/test-suite/lua/overload_complicated_runme.lua b/Examples/test-suite/lua/overload_complicated_runme.lua index 5670607bf..e8ef43107 100644 --- a/Examples/test-suite/lua/overload_complicated_runme.lua +++ b/Examples/test-suite/lua/overload_complicated_runme.lua @@ -7,16 +7,16 @@ local env = _ENV -- Lua 5.2 if not env then env = getfenv () end -- Lua 5.1 setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) -assert( oc.foo(1,1,"test",1) == 15 ) +assert(oc.foo(1,1,"test",1) == 15) p1 = oc.Pop(nil) p1 = oc.Pop(nil,false) -assert( p1:hip(true) == 701 ) -assert( p1:hip(nil) == 702 ) +assert(p1:hip(true) == 701) +assert(p1:hip(nil) == 702) -assert( p1:hop(true) == 801 ) -assert( p1:hop(nil) == 805 ) +assert(p1:hop(true) == 801) +assert(p1:hop(nil) == 805) -assert( oc.muzak(true) == 3001 ) -assert( oc.muzak(nil) == 3002 ) +assert(oc.muzak(true) == 3001) +assert(oc.muzak(nil) == 3002) diff --git a/Examples/test-suite/lua/smart_pointer_extend_runme.lua b/Examples/test-suite/lua/smart_pointer_extend_runme.lua index 6d33c57b1..e7241738a 100644 --- a/Examples/test-suite/lua/smart_pointer_extend_runme.lua +++ b/Examples/test-suite/lua/smart_pointer_extend_runme.lua @@ -7,28 +7,28 @@ local env = _ENV -- Lua 5.2 if not env then env = getfenv () end -- Lua 5.1 setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) -assert( spe.CBase.hello() == 1 ) -assert( spe.CBase.z == 1 ) +assert(spe.CBase.hello() == 1) +assert(spe.CBase.z == 1) base1 = spe.CBase() base1.x = 7 p1 = spe.CPtr() -assert( spe.get_hello(p1) == 1 ) -assert( p1:foo() == 1 ) -assert( p1:bar() == 2 ) -assert( p1:boo(5) == 5 ) +assert(spe.get_hello(p1) == 1) +assert(p1:foo() == 1) +assert(p1:bar() == 2) +assert(p1:boo(5) == 5) foo = spe.Foo() bar = spe.Bar(foo) -assert( bar:extension(5,7) == 5 ) -assert( bar:extension(7) == 7 ) -assert( bar:extension() == 1 ) +assert(bar:extension(5,7) == 5) +assert(bar:extension(7) == 7) +assert(bar:extension() == 1) dfoo = spe.DFoo() dptr = spe.DPtrFoo(dfoo) -assert( dptr:Ext() == 2 ) -assert( dptr:Ext(5) == 5 ) +assert(dptr:Ext() == 2) +assert(dptr:Ext(5) == 5) diff --git a/Examples/test-suite/lua/smart_pointer_inherit_runme.lua b/Examples/test-suite/lua/smart_pointer_inherit_runme.lua index 75510ad08..0cbebb0c8 100644 --- a/Examples/test-suite/lua/smart_pointer_inherit_runme.lua +++ b/Examples/test-suite/lua/smart_pointer_inherit_runme.lua @@ -11,8 +11,8 @@ der = spi.Derived(7) ptr = spi.SmartDerived(der) -assert( ptr.val == 7 ) -assert( ptr:value() == 7 ) -assert( ptr:value2() == 7 ) -assert( ptr:value3() == 7 ) -assert( ptr:valuehide() == -1 ) +assert(ptr.val == 7) +assert(ptr:value() == 7) +assert(ptr:value2() == 7) +assert(ptr:value3() == 7) +assert(ptr:valuehide() == -1) diff --git a/Examples/test-suite/lua/smart_pointer_multi_runme.lua b/Examples/test-suite/lua/smart_pointer_multi_runme.lua index ed3693727..38d99ae5c 100644 --- a/Examples/test-suite/lua/smart_pointer_multi_runme.lua +++ b/Examples/test-suite/lua/smart_pointer_multi_runme.lua @@ -9,15 +9,15 @@ setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i foo = spm.Foo() foo.x = 5 -assert( foo:getx() == 5 ) +assert(foo:getx() == 5) bar = spm.Bar(foo) spam = spm.Spam(bar) grok = spm.Grok(bar) -assert( bar:getx() == 5 ) -assert( spam:getx() == 5 ) +assert(bar:getx() == 5) +assert(spam:getx() == 5) spam.x = 7 -assert( grok:getx() == 7 ) +assert(grok:getx() == 7) grok.x = 10 -assert( foo:getx() == 10 ) +assert(foo:getx() == 10) diff --git a/Examples/test-suite/lua/smart_pointer_not_runme.lua b/Examples/test-suite/lua/smart_pointer_not_runme.lua index 2f009a7f6..5e58648ee 100644 --- a/Examples/test-suite/lua/smart_pointer_not_runme.lua +++ b/Examples/test-suite/lua/smart_pointer_not_runme.lua @@ -10,16 +10,16 @@ setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i foo = spn.Foo() foo.x = 7 -assert( foo:getx() == 7 ) +assert(foo:getx() == 7) bar = spn.Bar(foo) success = pcall(bar.getx, bar) -- Bar is not a smart pointer. Call should fail -assert( not success ) +assert(not success) spam = spn.Spam(foo) success = pcall(spam.getx, spam) -- Spam is not a smart pointer. Call should fail -assert( not success ) +assert(not success) grok = spn.Grok(foo) success = pcall(grok.getx, grok) -- Spam is not a smart pointer. Call should fail -assert( not success ) +assert(not success) diff --git a/Examples/test-suite/lua/smart_pointer_rename_runme.lua b/Examples/test-suite/lua/smart_pointer_rename_runme.lua index 51b07f61b..2b6e971d2 100644 --- a/Examples/test-suite/lua/smart_pointer_rename_runme.lua +++ b/Examples/test-suite/lua/smart_pointer_rename_runme.lua @@ -9,10 +9,10 @@ setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i foo = spr.Foo() -assert( foo:ftest1(1) == 1 ) -assert( foo:ftest2(1,2) == 2 ) +assert(foo:ftest1(1) == 1) +assert(foo:ftest2(1,2) == 2) bar = spr.Bar(foo) -assert( bar:test() == 3 ) -assert( bar:ftest1(1) == 1 ) -assert( bar:ftest2(1,2) == 2 ) +assert(bar:test() == 3) +assert(bar:ftest1(1) == 1) +assert(bar:ftest2(1,2) == 2) diff --git a/Examples/test-suite/lua/smart_pointer_simple_runme.lua b/Examples/test-suite/lua/smart_pointer_simple_runme.lua index 8513931b2..ca3a85161 100644 --- a/Examples/test-suite/lua/smart_pointer_simple_runme.lua +++ b/Examples/test-suite/lua/smart_pointer_simple_runme.lua @@ -9,8 +9,8 @@ setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i foo1 = sps.Foo() foo1.x = 5 -assert( foo1.x == 5 ) -assert( foo1:getx() == 5 ) +assert(foo1.x == 5) +assert(foo1:getx() == 5) bar1 = sps.Bar(foo1) bar1.x = 3 diff --git a/Examples/test-suite/lua/smart_pointer_templatemethods_runme.lua b/Examples/test-suite/lua/smart_pointer_templatemethods_runme.lua index 018881c42..63a34e91b 100644 --- a/Examples/test-suite/lua/smart_pointer_templatemethods_runme.lua +++ b/Examples/test-suite/lua/smart_pointer_templatemethods_runme.lua @@ -14,5 +14,5 @@ iid = spt.InterfaceId() po2 = o1:QueryInterfaceObjct(iid) -- we can't call po2:DisposeObjct, because smart pointer Ptr always return 0 when dereferencing -- (see interface file). So we only check that po2 has necessary method -assert( po2.DisposeObjct ~= nil ) -assert( po2.QueryInterfaceObjct ~= nil ) +assert(po2.DisposeObjct ~= nil) +assert(po2.QueryInterfaceObjct ~= nil) diff --git a/Examples/test-suite/lua/template_extend1_runme.lua b/Examples/test-suite/lua/template_extend1_runme.lua index 44774e949..28ccb24c7 100644 --- a/Examples/test-suite/lua/template_extend1_runme.lua +++ b/Examples/test-suite/lua/template_extend1_runme.lua @@ -8,7 +8,7 @@ if not env then env = getfenv () end -- Lua 5.1 setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) lb = te.lBaz() -assert( lb:foo() == "lBaz::foo" ) +assert(lb:foo() == "lBaz::foo") db = te.dBaz() -assert( db:foo() == "dBaz::foo" ) +assert(db:foo() == "dBaz::foo") diff --git a/Examples/test-suite/lua/template_extend2_runme.lua b/Examples/test-suite/lua/template_extend2_runme.lua index 23c25705b..124d70e04 100644 --- a/Examples/test-suite/lua/template_extend2_runme.lua +++ b/Examples/test-suite/lua/template_extend2_runme.lua @@ -8,7 +8,7 @@ if not env then env = getfenv () end -- Lua 5.1 setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) lb = te.lBaz() -assert( lb:foo() == "lBaz::foo" ) +assert(lb:foo() == "lBaz::foo") db = te.dBaz() -assert( db:foo() == "dBaz::foo" ) +assert(db:foo() == "dBaz::foo") diff --git a/Examples/test-suite/lua/template_inherit_runme.lua b/Examples/test-suite/lua/template_inherit_runme.lua index f2bfca00b..a337c044f 100644 --- a/Examples/test-suite/lua/template_inherit_runme.lua +++ b/Examples/test-suite/lua/template_inherit_runme.lua @@ -9,16 +9,16 @@ setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i fi = ti.FooInt() -assert( fi:blah() == "Foo" ) -assert( fi:foomethod() == "foomethod" ) +assert(fi:blah() == "Foo") +assert(fi:foomethod() == "foomethod") bi = ti.BarInt() -assert( bi:blah() == "Bar" ) -assert( bi:foomethod() == "foomethod" ) +assert(bi:blah() == "Bar") +assert(bi:foomethod() == "foomethod") -assert( ti.invoke_blah_int(fi) == "Foo" ) -assert( ti.invoke_blah_int(bi) == "Bar" ) +assert(ti.invoke_blah_int(fi) == "Foo") +assert(ti.invoke_blah_int(bi) == "Bar") bd = ti.BarDouble() -success = pcall( ti.invoke_blah_int, bd ) -assert( not success ) +success = pcall(ti.invoke_blah_int, bd) +assert(not success) From 89bc5576c99a6b41eb52c179c4c8e694f3409128 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Fri, 1 Nov 2013 15:10:02 +0400 Subject: [PATCH 0762/1160] More tests --- Examples/test-suite/keyword_rename.i | 2 + Examples/test-suite/lua/enum_plus_runme.lua | 11 ++++++ Examples/test-suite/lua/enum_rename_runme.lua | 11 ++++++ .../lua/enum_scope_template_runme.lua | 12 ++++++ .../test-suite/lua/enum_template_runme.lua | 16 ++++++++ .../test-suite/lua/inherit_missing_runme.lua | 14 +++++++ .../lua/nested_workaround_runme.lua | 22 +++++++++++ Examples/test-suite/lua/refcount_runme.lua | 26 +++++++++++++ .../lua/static_const_member_2_runme.lua | 37 +++++++++++++++++++ .../lua/static_const_member_runme.lua | 17 +++++++++ .../test-suite/lua/template_static_runme.lua | 20 ++++++++++ Examples/test-suite/lua/varargs_runme.lua | 18 +++++++++ 12 files changed, 206 insertions(+) create mode 100644 Examples/test-suite/lua/enum_plus_runme.lua create mode 100644 Examples/test-suite/lua/enum_rename_runme.lua create mode 100644 Examples/test-suite/lua/enum_scope_template_runme.lua create mode 100644 Examples/test-suite/lua/enum_template_runme.lua create mode 100644 Examples/test-suite/lua/inherit_missing_runme.lua create mode 100644 Examples/test-suite/lua/nested_workaround_runme.lua create mode 100644 Examples/test-suite/lua/refcount_runme.lua create mode 100644 Examples/test-suite/lua/static_const_member_2_runme.lua create mode 100644 Examples/test-suite/lua/static_const_member_runme.lua create mode 100644 Examples/test-suite/lua/template_static_runme.lua create mode 100644 Examples/test-suite/lua/varargs_runme.lua diff --git a/Examples/test-suite/keyword_rename.i b/Examples/test-suite/keyword_rename.i index 46c3338b3..7d14b9b66 100644 --- a/Examples/test-suite/keyword_rename.i +++ b/Examples/test-suite/keyword_rename.i @@ -32,8 +32,10 @@ KW(go, defer) KW(chan, fallthrough) /* Lua keywords */ +#if defined(SWIGLUA) KW(end, function) KW(nil,local) +#endif %} diff --git a/Examples/test-suite/lua/enum_plus_runme.lua b/Examples/test-suite/lua/enum_plus_runme.lua new file mode 100644 index 000000000..ee48df6cd --- /dev/null +++ b/Examples/test-suite/lua/enum_plus_runme.lua @@ -0,0 +1,11 @@ +require("import") -- the import fn +import("enum_plus") -- import lib +ep=enum_plus + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert(ep.iFoo_Phoo == 50) -- Old variant of enum bindings +assert(ep.iFoo.Phoo == 50) -- New variant of enum bindings diff --git a/Examples/test-suite/lua/enum_rename_runme.lua b/Examples/test-suite/lua/enum_rename_runme.lua new file mode 100644 index 000000000..84b61d7fc --- /dev/null +++ b/Examples/test-suite/lua/enum_rename_runme.lua @@ -0,0 +1,11 @@ +require("import") -- the import fn +import("enum_rename") -- import lib +er=enum_rename + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert(er.M_Jan ~= nil) +assert(er.May ~= nil) diff --git a/Examples/test-suite/lua/enum_scope_template_runme.lua b/Examples/test-suite/lua/enum_scope_template_runme.lua new file mode 100644 index 000000000..176d5904c --- /dev/null +++ b/Examples/test-suite/lua/enum_scope_template_runme.lua @@ -0,0 +1,12 @@ +require("import") -- the import fn +import("enum_scope_template") -- import lib +est=enum_scope_template + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert(est.TreeInt.Oak ~= nil) +assert(est.TreeInt_Oak ~= nil) +assert(est.TreeInt.Cedar ~= nil) diff --git a/Examples/test-suite/lua/enum_template_runme.lua b/Examples/test-suite/lua/enum_template_runme.lua new file mode 100644 index 000000000..a32f5fbd5 --- /dev/null +++ b/Examples/test-suite/lua/enum_template_runme.lua @@ -0,0 +1,16 @@ +require("import") -- the import fn +import("enum_template") -- import lib +et=enum_template + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert(et.eTest0 ~= nil) +assert(et.eTest1 ~= nil) + +et.TakeETest(et.eTest0) + +res = et.MakeETest() +et.TakeETest(res) diff --git a/Examples/test-suite/lua/inherit_missing_runme.lua b/Examples/test-suite/lua/inherit_missing_runme.lua new file mode 100644 index 000000000..40b3b1717 --- /dev/null +++ b/Examples/test-suite/lua/inherit_missing_runme.lua @@ -0,0 +1,14 @@ +require("import") -- the import fn +import("inherit_missing") -- import lib +im=inherit_missing + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +bar = im.Bar() +spam = im.Spam() + +assert(im.do_blah(bar) == "Bar::blah") +assert(im.do_blah(spam) == "Spam::blah") diff --git a/Examples/test-suite/lua/nested_workaround_runme.lua b/Examples/test-suite/lua/nested_workaround_runme.lua new file mode 100644 index 000000000..20f899523 --- /dev/null +++ b/Examples/test-suite/lua/nested_workaround_runme.lua @@ -0,0 +1,22 @@ +require("import") -- the import fn +import("nested_workaround") -- import lib +nw=nested_workaround + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +i1 = nw.Inner(5) +assert(i1:getValue() == 5) +i1:setValue(7) +assert(i1:getValue() == 7) + +o1 = nw.Outer() +i2 = o1:createInner(9) +assert(i2:getValue() == 9) +i2:setValue(11) +assert(o1:getInnerValue(i2) == 11) + +i3 = o1:doubleInnerValue(i2) +assert(i3:getValue() == 22) diff --git a/Examples/test-suite/lua/refcount_runme.lua b/Examples/test-suite/lua/refcount_runme.lua new file mode 100644 index 000000000..dc97a77bf --- /dev/null +++ b/Examples/test-suite/lua/refcount_runme.lua @@ -0,0 +1,26 @@ +require("import") -- the import fn +import("refcount") -- import lib +r=refcount + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +a = r.A() +assert(a:ref_count() == 1) + +b1 = r.B(a) +assert(a:ref_count() == 2) + +b2 = r.B.create(a) +assert(a:ref_count() == 3) + +b3 = b2:cloner() +assert(a:ref_count() == 4) + +rca = b1:get_rca() -- RCPtr is not wrapped +assert(a:ref_count() == 5) + +b4 = r.global_create(a) +assert(a:ref_count() == 6) diff --git a/Examples/test-suite/lua/static_const_member_2_runme.lua b/Examples/test-suite/lua/static_const_member_2_runme.lua new file mode 100644 index 000000000..dfee5699e --- /dev/null +++ b/Examples/test-suite/lua/static_const_member_2_runme.lua @@ -0,0 +1,37 @@ +require("import") -- the import fn +import("static_const_member_2") -- import lib +scm=static_const_member_2 + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert(scm.CavityPackFlags.forward_field == 1) +assert(scm.CavityPackFlags.backward_field == 2) +assert(scm.CavityPackFlags.cavity_flags == 3) + +assert(scm.CavityPackFlags.flags == 0) +scm.CavityPackFlags.flags = 91 +assert(scm.CavityPackFlags.flags == 91) +assert(scm.CavityPackFlags_flags == 91) -- old style bindings + +assert(scm.CavityPackFlags.reftest == 42) + +assert(scm.Test_int.LeftIndex ~= nil) +assert(scm.Test_int.current_profile == 4) + +assert(scm.Foo.BAR.val == 1) +assert(scm.Foo.BAZ.val == 2) + +assert(scm.Foo_BAR.val == 1) +assert(scm.Foo_BAZ.val == 2) + +scm.Foo.BAR.val = 4 +scm.Foo.BAZ.val = 5 + +assert(scm.Foo.BAR.val == 4) +assert(scm.Foo.BAZ.val == 5) + +assert(scm.Foo_BAR.val == 4) +assert(scm.Foo_BAZ.val == 5) diff --git a/Examples/test-suite/lua/static_const_member_runme.lua b/Examples/test-suite/lua/static_const_member_runme.lua new file mode 100644 index 000000000..a53c63872 --- /dev/null +++ b/Examples/test-suite/lua/static_const_member_runme.lua @@ -0,0 +1,17 @@ +require("import") -- the import fn +import("static_const_member") -- import lib into global +scm=static_const_member --alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert(scm.X.PN == 0) +assert(scm.X.CN == 1) +assert(scm.X.EN == 2) + +-- Old-style bindings +assert(scm.X_PN == 0) +assert(scm.X_CN == 1) +assert(scm.X_EN == 2) diff --git a/Examples/test-suite/lua/template_static_runme.lua b/Examples/test-suite/lua/template_static_runme.lua new file mode 100644 index 000000000..bde56ebae --- /dev/null +++ b/Examples/test-suite/lua/template_static_runme.lua @@ -0,0 +1,20 @@ +require("import") -- the import fn +import("template_static") -- import lib +ts=template_static + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert(ts.foo_i.test == 0) +ts.foo_i.test = 42 +assert(ts.foo_i.test == 42) +assert(ts.foo_i_test == 42) +ts.foo_i_test = 57 +assert(ts.foo_i.test == 57) +assert(ts.foo_i_test == 57) +assert(ts.foo_d.test == 0) + +assert(ts.Foo.bar_double(4) == 1.0) +assert(ts.Foo_bar_double(4) == 1.0) diff --git a/Examples/test-suite/lua/varargs_runme.lua b/Examples/test-suite/lua/varargs_runme.lua new file mode 100644 index 000000000..027a4b920 --- /dev/null +++ b/Examples/test-suite/lua/varargs_runme.lua @@ -0,0 +1,18 @@ +require("import") -- the import fn +import("varargs") -- import lib +v=varargs + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert(v.test("Hello") == "Hello") +assert(v.test_def("Hello",0) == "Hello") + +assert(v.Foo.statictest("Hello") == "Hello") +assert(v.Foo.statictest("Hello",1) == "Hello") + +assert(v.test_plenty("Hello") == "Hello") +assert(v.test_plenty("Hello",1) == "Hello") +assert(v.test_plenty("Hello",1,2) == "Hello") From b901979d1c5c839edb09fe3190eaf27236662d09 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Thu, 7 Nov 2013 20:26:27 +0400 Subject: [PATCH 0763/1160] Tests for enum/consts old-style bindings and for static const char; bindings --- Examples/test-suite/lua/cpp_basic_runme.lua | 3 +++ Examples/test-suite/lua/cpp_enum_runme.lua | 21 +++++++++++++++++++ .../lua/static_const_member_runme.lua | 4 ++++ 3 files changed, 28 insertions(+) create mode 100644 Examples/test-suite/lua/cpp_enum_runme.lua diff --git a/Examples/test-suite/lua/cpp_basic_runme.lua b/Examples/test-suite/lua/cpp_basic_runme.lua index 3d5ccaadf..3e2fb963e 100644 --- a/Examples/test-suite/lua/cpp_basic_runme.lua +++ b/Examples/test-suite/lua/cpp_basic_runme.lua @@ -59,6 +59,9 @@ cb.Bar_global_fval=cb.Foo(-34) assert(cb.Bar_global_fval.num==-34) assert(cb.Bar.global_fval.num==-34) +assert(cb.Bar.global_cint == -4) +assert(cb.Bar_global_cint == -4) + -- Now test member function pointers func1_ptr=cb.get_func1_ptr() func2_ptr=cb.get_func2_ptr() diff --git a/Examples/test-suite/lua/cpp_enum_runme.lua b/Examples/test-suite/lua/cpp_enum_runme.lua new file mode 100644 index 000000000..e8b53c728 --- /dev/null +++ b/Examples/test-suite/lua/cpp_enum_runme.lua @@ -0,0 +1,21 @@ +require("import") -- the import fn +import("cpp_enum") -- import code +ce=cpp_enum -- renaming import + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert(ce.ENUM_ONE ~= nil) +assert(ce.ENUM_TWO ~= nil) + +-- Enums inside classes +assert(ce.Foo.Hi == 0) +assert(ce.Foo.Hello == 1); +-- old-style bindings +assert(ce.Foo_Hi == 0) +assert(ce.Foo_Hello == 1); + +assert(ce.Hi == 0) +assert(ce.Hello == 1) diff --git a/Examples/test-suite/lua/static_const_member_runme.lua b/Examples/test-suite/lua/static_const_member_runme.lua index a53c63872..4e2b144c5 100644 --- a/Examples/test-suite/lua/static_const_member_runme.lua +++ b/Examples/test-suite/lua/static_const_member_runme.lua @@ -10,8 +10,12 @@ setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i assert(scm.X.PN == 0) assert(scm.X.CN == 1) assert(scm.X.EN == 2) +assert(scm.X.CHARTEST == "A") -- Old-style bindings assert(scm.X_PN == 0) assert(scm.X_CN == 1) assert(scm.X_EN == 2) +assert(scm.X_CHARTEST == "A") + + From 14de0de5e764246a1ed68b8f3b78f7fb9db83b5f Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Fri, 8 Nov 2013 02:47:34 +0400 Subject: [PATCH 0764/1160] Tests for arrays and global vars --- .../test-suite/lua/array_member_runme.lua | 30 +++++++++++++ .../test-suite/lua/arrays_global_runme.lua | 14 ++++++ Examples/test-suite/lua/global_vars_runme.lua | 44 +++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 Examples/test-suite/lua/array_member_runme.lua create mode 100644 Examples/test-suite/lua/arrays_global_runme.lua create mode 100644 Examples/test-suite/lua/global_vars_runme.lua diff --git a/Examples/test-suite/lua/array_member_runme.lua b/Examples/test-suite/lua/array_member_runme.lua new file mode 100644 index 000000000..321e7d57d --- /dev/null +++ b/Examples/test-suite/lua/array_member_runme.lua @@ -0,0 +1,30 @@ +require("import") -- the import fn +import("array_member") -- import lib +am = array_member + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert(am.get_value(am.global_data,0) == 0) +assert(am.get_value(am.global_data,7) == 7) + +foo = am.Foo() +foo.data = am.global_data +assert(am.get_value(foo.data,0) == 0) + +for i = 0, 7 do + assert(am.get_value(foo.data,i) == am.get_value(am.global_data,i)) +end + + +for i = 0, 7 do + am.set_value(am.global_data,i,-i) +end + +am.global_data = foo.data + +for i = 0, 7 do + assert(am.get_value(foo.data,i) == am.get_value(am.global_data,i)) +end diff --git a/Examples/test-suite/lua/arrays_global_runme.lua b/Examples/test-suite/lua/arrays_global_runme.lua new file mode 100644 index 000000000..fc0d340bf --- /dev/null +++ b/Examples/test-suite/lua/arrays_global_runme.lua @@ -0,0 +1,14 @@ +require("import") -- the import fn +import("arrays_global") -- import lib +ag = arrays_global + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert(ag.BeginString_FIX44a == "FIX.a.a") +assert(ag.BeginString_FIX44b == "FIX.b.b") + +assert(ag.BeginString_FIX44c == "FIX.c.c") +assert(ag.BeginString_FIX44d == "FIX.d.d") diff --git a/Examples/test-suite/lua/global_vars_runme.lua b/Examples/test-suite/lua/global_vars_runme.lua new file mode 100644 index 000000000..3c019aee1 --- /dev/null +++ b/Examples/test-suite/lua/global_vars_runme.lua @@ -0,0 +1,44 @@ +require("import") -- the import fn +import("global_vars") -- import lib +gv = global_vars + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +gv.b = "abcde" +assert(gv.b == "abcde") + +gv.a.x = 7 +assert(gv.a.x == 7) + +a1 = gv.A() +a1.x = 11 +gv.a = a1 +assert(gv.a.x == 11) + +gv.x = 10 +assert(gv.x == 10) + +assert(gv.Hi ~= nil) +assert(gv.Hola ~= nil) + +gv.h = gv.Hi +assert(gv.h == gv.Hi) + + +-- It is not clear whether these tests should work or not +-- Currently they don't. +-- +-- assert(gv.c_member == 10) +-- +-- gv.c_member = 5 +-- assert(gv.x == 5) +-- +-- gv.h = gv.Hi +-- assert(gv.hr == gv.Hi) +-- +-- gv.hr = gv.Hola +-- assert(gv.h == gv.Hola) +-- assert(gv.hr == gv.Hola) From 8b35c0b5cef599a0ac3a65343bf729a73222b568 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Fri, 8 Nov 2013 04:33:45 +0400 Subject: [PATCH 0765/1160] Add runfile to check for correct compatibility name generation Checks that if OldClass was renamed to NewClass, then not only OldClass.static_method is now NewClass.static_method, but also compatibility name OldClass_static_method is now NewClass_static_method. Same for enums, static vars etc --- .../test-suite/lua/rename_simple_runme.lua | 25 +++++++++++++++++++ Examples/test-suite/rename_simple.i | 1 + 2 files changed, 26 insertions(+) create mode 100644 Examples/test-suite/lua/rename_simple_runme.lua diff --git a/Examples/test-suite/lua/rename_simple_runme.lua b/Examples/test-suite/lua/rename_simple_runme.lua new file mode 100644 index 000000000..90f510a54 --- /dev/null +++ b/Examples/test-suite/lua/rename_simple_runme.lua @@ -0,0 +1,25 @@ +require("import") -- the import fn +import("rename_simple") -- import lib +rs = rename_simple + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert(rs.NewStruct ~= nil) +assert(rs.NewStruct.NewStaticVariable == 444) +assert(rs.NewStruct_NewStaticVariable == 444) + +assert(rs.NewStruct.NewStaticMethod() == 333) +assert(rs.NewStruct_NewStaticMethod() == 333) + +assert(rs.NewStruct.ONE == 1) +assert(rs.NewStruct_ONE == 1) + +assert(rs.NewFunction() == 555) + +assert(rs.OldStruct == nil) +assert(rs.OldFunction == nil) +assert(rs.OldGlobalVariable == nil) +assert(rs.OldStruct_ONE == nil) diff --git a/Examples/test-suite/rename_simple.i b/Examples/test-suite/rename_simple.i index feba53fa1..5616b16ea 100644 --- a/Examples/test-suite/rename_simple.i +++ b/Examples/test-suite/rename_simple.i @@ -11,6 +11,7 @@ %inline %{ struct OldStruct { + enum { ONE = 1, TWO, THREE }; OldStruct() : OldInstanceVariable(111) {} int OldInstanceVariable; int OldInstanceMethod() { return 222; } From ca5327d0dad8589f0a6691ae1391a68238895f35 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 9 Nov 2013 14:04:24 +0000 Subject: [PATCH 0766/1160] Remove Lua specifics from keyword_rename testcase --- Examples/test-suite/keyword_rename.i | 2 -- 1 file changed, 2 deletions(-) diff --git a/Examples/test-suite/keyword_rename.i b/Examples/test-suite/keyword_rename.i index 7d14b9b66..46c3338b3 100644 --- a/Examples/test-suite/keyword_rename.i +++ b/Examples/test-suite/keyword_rename.i @@ -32,10 +32,8 @@ KW(go, defer) KW(chan, fallthrough) /* Lua keywords */ -#if defined(SWIGLUA) KW(end, function) KW(nil,local) -#endif %} From 65de78b8b4caefbbd3afd420122c2946760b3047 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 9 Nov 2013 14:52:59 +0000 Subject: [PATCH 0767/1160] enum_plus testcase was never been run --- Examples/test-suite/common.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 0f3f82629..e25d36715 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -194,6 +194,7 @@ CPP_TEST_CASES += \ disown \ dynamic_cast \ empty \ + enum_plus \ enum_rename \ enum_scope_template \ enum_template \ From c151a0d69ae4d9e415abc5600330e152831c1fea Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 11 Nov 2013 19:12:48 +0000 Subject: [PATCH 0768/1160] Add array function PHP keywords --- Lib/php/phpkw.swg | 102 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 90 insertions(+), 12 deletions(-) diff --git a/Lib/php/phpkw.swg b/Lib/php/phpkw.swg index c55766928..78a93369f 100644 --- a/Lib/php/phpkw.swg +++ b/Lib/php/phpkw.swg @@ -588,26 +588,104 @@ PHPCN(sqliteexception); PHPCN(datetime); /* Built-in PHP functions (incomplete). */ -PHPFN(cos); -PHPFN(sin); -PHPFN(tan); +/* Includes Array Functions - http://us3.php.net/manual/en/ref.array.php */ PHPFN(acos); +PHPFN(array_change_key_case); +PHPFN(array_chunk); +PHPFN(array_column); +PHPFN(array_combine); +PHPFN(array_count_values); +PHPFN(array_diff); +PHPFN(array_diff_assoc); +PHPFN(array_diff_key); +PHPFN(array_diff_uassoc); +PHPFN(array_diff_ukey); +PHPFN(array_fill); +PHPFN(array_fill_keys); +PHPFN(array_filter); +PHPFN(array_flip); +PHPFN(array_intersect); +PHPFN(array_intersect_assoc); +PHPFN(array_intersect_key); +PHPFN(array_intersect_uassoc); +PHPFN(array_intersect_ukey); +PHPFN(array_key_exists); +PHPFN(array_keys); +PHPFN(array_map); +PHPFN(array_merge); +PHPFN(array_merge_recursive); +PHPFN(array_multisort); +PHPFN(array_pad); +PHPFN(array_pop); +PHPFN(array_product); +PHPFN(array_push); +PHPFN(array_rand); +PHPFN(array_reduce); +PHPFN(array_replace); +PHPFN(array_replace_recursive); +PHPFN(array_reverse); +PHPFN(array_search); +PHPFN(array_shift); +PHPFN(array_slice); +PHPFN(array_splice); +PHPFN(array_sum); +PHPFN(array_udiff); +PHPFN(array_udiff_assoc); +PHPFN(array_udiff_uassoc); +PHPFN(array_uintersect); +PHPFN(array_uintersect_assoc); +PHPFN(array_uintersect_uassoc); +PHPFN(array_unique); +PHPFN(array_unshift); +PHPFN(array_values); +PHPFN(array_walk); +PHPFN(array_walk_recursive); +PHPFN(arsort); PHPFN(asin); +PHPFN(asort); PHPFN(atan); PHPFN(atan2); -PHPFN(cosh); -PHPFN(sinh); -PHPFN(tanh); -PHPFN(exp); -PHPFN(log); -PHPFN(log10); -PHPFN(pow); -PHPFN(sqrt); PHPFN(ceil); +PHPFN(compact); +PHPFN(cos); +PHPFN(cosh); +PHPFN(count); +PHPFN(current); +PHPFN(each); +PHPFN(end); +PHPFN(exp); +PHPFN(extract); PHPFN(floor); PHPFN(fmod); -PHPFN(min); +PHPFN(in_array); +PHPFN(key); +PHPFN(key_exists); +PHPFN(krsort); +PHPFN(ksort); +PHPFN(log); +PHPFN(log10); PHPFN(max); +PHPFN(min); +PHPFN(natcasesort); +PHPFN(natsort); +PHPFN(next); +PHPFN(pos); +PHPFN(pow); +PHPFN(prev); +PHPFN(range); +PHPFN(reset); +PHPFN(rsort); +PHPFN(shuffle); +PHPFN(sin); +PHPFN(sinh); +PHPFN(sizeof); +PHPFN(sort); +PHPFN(sqrt); +PHPFN(tan); +PHPFN(tanh); +PHPFN(uasort); +PHPFN(uksort); +PHPFN(usort); #undef PHPKW #undef PHPBN1 From 0901a3e867a733cbede8b034f92c964025c38c8a Mon Sep 17 00:00:00 2001 From: Robert Stone Date: Tue, 12 Nov 2013 12:45:03 -0800 Subject: [PATCH 0769/1160] steals python directors and adapts to perl5 --- .../perl5/director_abstract_runme.pl | 62 ++ .../perl5/director_alternating_runme.pl | 8 + .../test-suite/perl5/director_basic_runme.pl | 57 ++ .../perl5/director_classes_runme.pl | 70 ++ .../perl5/director_classic_runme.pl | 128 +++ .../perl5/director_constructor_runme.pl | 46 + .../perl5/director_default_runme.pl | 18 + .../test-suite/perl5/director_detect_runme.pl | 45 + .../test-suite/perl5/director_enum_runme.pl | 21 + .../perl5/director_exception_runme.pl | 57 ++ .../test-suite/perl5/director_extend_runme.pl | 16 + .../perl5/director_finalizer_runme.pl | 83 ++ .../test-suite/perl5/director_frob_runme.pl | 10 + .../test-suite/perl5/director_ignore_runme.pl | 25 + .../test-suite/perl5/director_nested_runme.pl | 59 ++ .../perl5/director_primitives_runme.pl | 68 ++ .../perl5/director_protected_runme.pl | 48 ++ .../test-suite/perl5/director_string_runme.pl | 34 + .../test-suite/perl5/director_unroll_runme.pl | 17 + .../test-suite/perl5/director_wombat_runme.pl | 53 ++ Lib/perl5/perlrun.swg | 3 +- Lib/perl5/perltypemaps.swg | 6 +- Source/Modules/perl5.cxx | 812 +++++++++++++++++- 23 files changed, 1741 insertions(+), 5 deletions(-) create mode 100644 Examples/test-suite/perl5/director_abstract_runme.pl create mode 100644 Examples/test-suite/perl5/director_alternating_runme.pl create mode 100644 Examples/test-suite/perl5/director_basic_runme.pl create mode 100644 Examples/test-suite/perl5/director_classes_runme.pl create mode 100644 Examples/test-suite/perl5/director_classic_runme.pl create mode 100644 Examples/test-suite/perl5/director_constructor_runme.pl create mode 100644 Examples/test-suite/perl5/director_default_runme.pl create mode 100644 Examples/test-suite/perl5/director_detect_runme.pl create mode 100644 Examples/test-suite/perl5/director_enum_runme.pl create mode 100644 Examples/test-suite/perl5/director_exception_runme.pl create mode 100644 Examples/test-suite/perl5/director_extend_runme.pl create mode 100644 Examples/test-suite/perl5/director_finalizer_runme.pl create mode 100644 Examples/test-suite/perl5/director_frob_runme.pl create mode 100644 Examples/test-suite/perl5/director_ignore_runme.pl create mode 100644 Examples/test-suite/perl5/director_nested_runme.pl create mode 100644 Examples/test-suite/perl5/director_primitives_runme.pl create mode 100644 Examples/test-suite/perl5/director_protected_runme.pl create mode 100644 Examples/test-suite/perl5/director_string_runme.pl create mode 100644 Examples/test-suite/perl5/director_unroll_runme.pl create mode 100644 Examples/test-suite/perl5/director_wombat_runme.pl diff --git a/Examples/test-suite/perl5/director_abstract_runme.pl b/Examples/test-suite/perl5/director_abstract_runme.pl new file mode 100644 index 000000000..d369eac17 --- /dev/null +++ b/Examples/test-suite/perl5/director_abstract_runme.pl @@ -0,0 +1,62 @@ +use strict; +use warnings; +use Test::More tests => 13; +BEGIN { use_ok('director_abstract') } +require_ok('director_abstract'); + +{ + package MyFoo; + use base 'director_abstract::Foo'; + sub ping { + return 'MyFoo::ping()'; + } +} + +my $f = MyFoo->new(); + +is($f->ping, "MyFoo::ping()"); + +is($f->pong(),"Foo::pong();MyFoo::ping()"); + +{ + package MyExample1; + use base 'director_abstract::Example1'; + sub Color { my($self, $r, $g, $b) = @_; + return $r; + } +} +{ + package MyExample2; + use base 'director_abstract::Example2'; + sub Color { my($self, $r, $g, $b) = @_; + return $g; + } +} +{ + package MyExample3; + use base 'director_abstract::Example3_i'; + sub Color { my($self, $r, $g, $b) = @_; + return $b; + } +} + +my $me1 = MyExample1->new(); +isa_ok($me1, 'MyExample1'); +is(director_abstract::Example1::get_color($me1, 1, 2, 3), 1, 'me1'); + +my $me2 = MyExample2->new(1,2); +isa_ok($me2, 'MyExample2'); +is(director_abstract::Example2::get_color($me2, 1, 2, 3), 2, 'me2'); + +my $me3 = MyExample3->new(); +isa_ok($me3, 'MyExample3'); +is(director_abstract::Example3_i::get_color($me3, 1, 2, 3), 3, 'me3'); + +eval { $me1 = director_abstract::Example1->new() }; +like($@, qr/\babstract\b/i, 'E1.new()'); + +eval { $me2 = director_abstract::Example2->new() }; +like($@, qr/Example2/, 'E2.new()'); + +eval { $me3 = director_abstract::Example3_i->new() }; +like($@, qr/\babstract\b/i, 'E3.new()'); diff --git a/Examples/test-suite/perl5/director_alternating_runme.pl b/Examples/test-suite/perl5/director_alternating_runme.pl new file mode 100644 index 000000000..83d30af6d --- /dev/null +++ b/Examples/test-suite/perl5/director_alternating_runme.pl @@ -0,0 +1,8 @@ +use strict; +use warnings; +use Test::More tests => 3; +BEGIN { use_ok('director_alternating') } +require_ok('director_alternating'); + +my $id = director_alternating::getBar()->id(); +is($id, director_alternating::idFromGetBar(), "got Bar id"); diff --git a/Examples/test-suite/perl5/director_basic_runme.pl b/Examples/test-suite/perl5/director_basic_runme.pl new file mode 100644 index 000000000..55e70dc9c --- /dev/null +++ b/Examples/test-suite/perl5/director_basic_runme.pl @@ -0,0 +1,57 @@ +use strict; +use warnings; +use Test::More tests => 12; +BEGIN { use_ok 'director_basic' } +require_ok 'director_basic'; + +{ + package MyFoo; + use base 'director_basic::Foo'; + sub ping { + return 'MyFoo::ping()'; + } +} + +{ + package MyOverriddenClass; + use base 'director_basic::MyClass'; + use fields qw(expectNull nonNullReceived); + sub new { + my $self = shift->SUPER::new(@_); + $self->{expectNull} = undef; + $self->{nonNullReceived} = undef; + return $self; + } + sub pmethod { my($self, $b) = @_; + die "null not received as expected" + if $self->{expectNull} and defined $b; + return $b; + } +} + +{ + my $a = MyFoo->new(); + isa_ok $a, 'MyFoo'; + is $a->ping(), 'MyFoo::ping()', 'a.ping()'; + is $a->pong(), 'Foo::pong();MyFoo::ping()', 'a.pong()'; + + my $b = director_basic::Foo->new(); + isa_ok $b, 'director_basic::Foo'; + is $b->ping(), 'Foo::ping()', 'b.ping()'; + is $b->pong(), 'Foo::pong();Foo::ping()', 'b.pong()'; + + my $a1 = director_basic::A1->new(1, undef); + isa_ok $a1, 'director_basic::A1'; + is $a1->rg(2), 2, 'A1.rg'; + + my $my = MyOverriddenClass->new(); + $my->{expectNull} = 1; + is(director_basic::MyClass::call_pmethod($my, undef), undef, + 'null pointer marshalling'); + + my $myBar = director_basic::Bar->new(); + $my->{expectNull} = undef; + my $myNewBar = director_basic::MyClass::call_pmethod($my, $myBar); + isnt($myNewBar, undef, 'non-null pointer marshalling'); + $myNewBar->{x} = 10; +} diff --git a/Examples/test-suite/perl5/director_classes_runme.pl b/Examples/test-suite/perl5/director_classes_runme.pl new file mode 100644 index 000000000..a4fddeed9 --- /dev/null +++ b/Examples/test-suite/perl5/director_classes_runme.pl @@ -0,0 +1,70 @@ +use strict; +use warnings; +use Test::More tests => 29; +BEGIN { use_ok 'director_classes' } +require_ok 'director_classes'; + +{ + package PerlDerived; + use base 'director_classes::Base'; + sub Val { $_[1] } + sub Ref { $_[1] } + sub Ptr { $_[1] } + sub FullyOverloaded { + my $rv = shift->SUPER::FullyOverloaded(@_); + $rv =~ s/Base/__PACKAGE__/sge; + return $rv; + } + sub SemiOverloaded { + # this is going to be awkward because we can't really + # semi-overload in Perl, but we can sort of fake it. + return shift->SUPER::SemiOverloaded(@_) unless $_[0] =~ /^\d+/; + my $rv = shift->SUPER::SemiOverloaded(@_); + $rv =~ s/Base/__PACKAGE__/sge; + return $rv; + } + sub DefaultParms { + my $rv = shift->SUPER::DefaultParms(@_); + $rv =~ s/Base/__PACKAGE__/sge; + return $rv; + } +} + +{ + my $c = director_classes::Caller->new(); + makeCalls($c, director_classes::Base->new(100.0)); + makeCalls($c, director_classes::Derived->new(200.0)); + makeCalls($c, PerlDerived->new(300.0)); +} + +sub makeCalls { my($caller, $base) = @_; + my $bname = ref $base; + $bname = $1 if $bname =~ /^director_classes::(.*)$/; + $caller->set($base); + my $dh = director_classes::DoubleHolder->new(444.555); + is($caller->ValCall($dh)->{val}, $dh->{val}, "$bname.Val"); + is($caller->RefCall($dh)->{val}, $dh->{val}, "$bname.Ref"); + is($caller->PtrCall($dh)->{val}, $dh->{val}, "$bname.Ptr"); + is($caller->FullyOverloadedCall(1), + "${bname}::FullyOverloaded(int)", + "$bname.FullyOverloaded(int)"); + is($caller->FullyOverloadedCall(''), + "${bname}::FullyOverloaded(bool)", + "$bname.FullyOverloaded(bool)"); +TODO: { + local $TODO = 'investigation needed here' if $bname eq 'PerlDerived'; + is($caller->SemiOverloadedCall(-678), + "${bname}::SemiOverloaded(int)", + "$bname.SemiOverloaded(int)"); +} + is($caller->SemiOverloadedCall(''), + "Base::SemiOverloaded(bool)", + "$bname.SemiOverloaded(bool)"); + is($caller->DefaultParmsCall(10, 2.2), + "${bname}::DefaultParms(int, double)", + "$bname.DefaultParms(int, double)"); + is($caller->DefaultParmsCall(10), + "${bname}::DefaultParms(int)", + "$bname.DefaultParms(int)"); + $caller->reset(); +} diff --git a/Examples/test-suite/perl5/director_classic_runme.pl b/Examples/test-suite/perl5/director_classic_runme.pl new file mode 100644 index 000000000..2fa4fde56 --- /dev/null +++ b/Examples/test-suite/perl5/director_classic_runme.pl @@ -0,0 +1,128 @@ +use strict; +use warnings; +use Test::More tests => 41; +BEGIN { use_ok('director_classic') } +require_ok('director_classic'); + +{ + package TargetLangPerson; + use base 'director_classic::Person'; + sub id { return 'TargetLangPerson' } +} + +{ + package TargetLangChild; + use base 'director_classic::Child'; + sub id { return 'TargetLangChild' } +} + +{ + package TargetLangGrandChild; + use base 'director_classic::GrandChild'; + sub id { return 'TargetLangGrandChild' } +} + +# Semis - don't override id() in target language +{ + package TargetLangSemiPerson; + use base 'director_classic::Person'; + # No id() override +} + +{ + package TargetLangSemiChild; + use base 'director_classic::Child'; + # No id() override +} + +{ + package TargetLangSemiGrandChild; + use base 'director_classic::GrandChild'; + # No id() override +} + +# Orphans - don't override id() in C++ +{ + package TargetLangOrphanPerson; + use base 'director_classic::OrphanPerson'; + sub id { return "TargetLangOrphanPerson" } +} + +{ + package TargetLangOrphanChild; + use base 'director_classic::OrphanChild'; + sub id { return "TargetLangOrphanChild" } +} + +sub check { my($person, $expected) = @_; + # Normal target language polymorphic call + is($person->id(), $expected, "$expected from Perl"); + + # Polymorphic call from C++ + my $caller = director_classic::Caller->new(); + $caller->setCallback($person); + is($caller->call(), $expected, "$expected from C++"); + + # Polymorphic call of object created in target language and passed to C++ and back again + my $baseclass = $caller->baseClass(); + is($baseclass->id(), $expected, "$expected after bounce"); + + $caller->resetCallback(); +} + +my $person; + +$person = director_classic::Person->new(); +check($person, "Person"); +undef $person; + +$person = director_classic::Child->new(); +check($person, "Child"); +undef $person; + +$person = director_classic::GrandChild->new(); +check($person, "GrandChild"); +undef $person; + +$person = TargetLangPerson->new(); +check($person, "TargetLangPerson"); +undef $person; + +$person = TargetLangChild->new(); +check($person, "TargetLangChild"); +undef $person; + +$person = TargetLangGrandChild->new(); +check($person, "TargetLangGrandChild"); +undef $person; + +# Semis - don't override id() in target language +$person = TargetLangSemiPerson->new(); +check($person, "Person"); +undef $person; + +$person = TargetLangSemiChild->new(); +check($person, "Child"); +undef $person; + +$person = TargetLangSemiGrandChild->new(); +check($person, "GrandChild"); +undef $person; + +# Orphans - don't override id() in C++ +$person = director_classic::OrphanPerson->new(); +check($person, "Person"); +undef $person; + +$person = director_classic::OrphanChild->new(); +check($person, "Child"); +undef $person; + +$person = TargetLangOrphanPerson->new(); +check($person, "TargetLangOrphanPerson"); +undef $person; + +$person = TargetLangOrphanChild->new(); +check($person, "TargetLangOrphanChild"); +undef $person; + diff --git a/Examples/test-suite/perl5/director_constructor_runme.pl b/Examples/test-suite/perl5/director_constructor_runme.pl new file mode 100644 index 000000000..c990fc3a1 --- /dev/null +++ b/Examples/test-suite/perl5/director_constructor_runme.pl @@ -0,0 +1,46 @@ +use strict; +use warnings; +use Test::More tests => 9; +BEGIN { use_ok 'director_constructor' } +require_ok 'director_constructor'; + +{ + package Test; + use base 'director_constructor::Foo'; + sub doubleit { my($self) = @_; + $self->{a} *= 2; + } + sub test { 3 } +} +my $t = Test->new(5); +isa_ok $t, 'Test'; +is $t->getit, 5; +is $t->do_test, 3; + +$t->doubleit(); + +is $t->getit, 10; + +{ + package Wrong; + use base 'director_constructor::Foo'; + sub doubleit { my($self) = @_; + # calling this should trigger a type error on attribute + # assignment + $self->{a} = {}; + } + sub test { + # if c++ calls this, retval copyout should trigger a type error + return bless {}, 'TotallyBogus'; + } +} + +# TODO: these TypeErrors in director classes should be more detailed +my $w = Wrong->new(12); +is eval { $w->doubleit() }, undef; +like $@, qr/TypeError/; +is $w->getit(), 12, 'W.a should be unaffected'; + +# TODO: this is giving an unhandled C++ exception right now +#is eval { $W->do_test() }, undef; +#like $@, qr/TypeError/; diff --git a/Examples/test-suite/perl5/director_default_runme.pl b/Examples/test-suite/perl5/director_default_runme.pl new file mode 100644 index 000000000..281c8ebd3 --- /dev/null +++ b/Examples/test-suite/perl5/director_default_runme.pl @@ -0,0 +1,18 @@ +use strict; +use warnings; +use Test::More tests => 6; +BEGIN { use_ok 'director_default' } +require_ok 'director_default'; + +my $f; + +$f = director_default::Foo->new(); +isa_ok $f, 'director_default::Foo'; +$f = director_default::Foo->new(1); +isa_ok $f, 'director_default::Foo'; + + +$f = director_default::Bar->new(); +isa_ok $f, 'director_default::Bar'; +$f = director_default::Bar->new(1); +isa_ok $f, 'director_default::Bar'; diff --git a/Examples/test-suite/perl5/director_detect_runme.pl b/Examples/test-suite/perl5/director_detect_runme.pl new file mode 100644 index 000000000..3e2c652cb --- /dev/null +++ b/Examples/test-suite/perl5/director_detect_runme.pl @@ -0,0 +1,45 @@ +use strict; +use warnings; +use Test::More tests => 9; +BEGIN { use_ok 'director_detect' } +require_ok 'director_detect'; + +{ + package MyBar; + use base 'director_detect::Bar'; + sub new { my $class = shift; + my $val = @_ ? shift : 2; + my $self = $class->SUPER::new(); + $self->{val} = $val; + return $self; + } + sub get_value { my($self) = @_; + $self->{val}++; + return $self->{val}; + } + sub get_class { my($self) = @_; + $self->{val}++; + return director_detect::A->new(); + } + sub just_do_it { my($self) = @_; + $self->{val}++; + } + sub clone { my($self) = @_; + MyBar->new($self->{val}); + } +} + +my $b = MyBar->new(); +isa_ok $b, 'MyBar'; + +my $f = $b->baseclass(); +isa_ok $f, 'director_detect::Foo'; +is $f->get_value(), 3; + +isa_ok $f->get_class(), 'director_detect::A'; +$f->just_do_it(); + +my $c = $b->clone(); +isa_ok $c, 'MyBar'; +is $b->{val}, 5; +is $c->get_value(), 6; diff --git a/Examples/test-suite/perl5/director_enum_runme.pl b/Examples/test-suite/perl5/director_enum_runme.pl new file mode 100644 index 000000000..6d58b376e --- /dev/null +++ b/Examples/test-suite/perl5/director_enum_runme.pl @@ -0,0 +1,21 @@ +use strict; +use warnings; +use Test::More tests => 5; +BEGIN { use_ok 'director_enum' } +require_ok 'director_enum'; + +{ + package MyFoo; + use base 'director_enum::Foo'; + sub say_hi { my($self, $val) = @_; + return $val; + } +} + +my $b = director_enum::Foo->new(); +isa_ok $b, 'director_enum::Foo'; +my $a = MyFoo->new(); +isa_ok $a, 'MyFoo'; + +is $a->say_hi($director_enum::hello), + $a->say_hello($director_enum::hi); diff --git a/Examples/test-suite/perl5/director_exception_runme.pl b/Examples/test-suite/perl5/director_exception_runme.pl new file mode 100644 index 000000000..62c103b6c --- /dev/null +++ b/Examples/test-suite/perl5/director_exception_runme.pl @@ -0,0 +1,57 @@ +use strict; +use warnings; +use Test::More tests => 7; +BEGIN { use_ok 'director_exception' } +require_ok 'director_exception'; + +{ + package MyFoo; + use base 'director_exception::Foo'; + sub ping { + die "MyFoo::ping() EXCEPTION"; + } +} +{ + package MyFoo2; + use base 'director_exception::Foo'; + sub ping { + # error should return a string + return bless [ 1 ], 'main'; + } +} +{ + package MyFoo3; + use base 'director_exception::Foo'; + sub ping { + # error should return a string + return sub { 1 } + } +} + +{ + my $a = MyFoo->new(); + my $b = director_exception::launder($a); + eval { $b->pong() }; + like($@, qr/\bMyFoo::ping\(\) EXCEPTION\b/, + 'MyFoo.pong() error content preserved'); +} +{ + my $a = MyFoo2->new(); + my $b = director_exception::launder($a); + eval { $b->pong() }; + like($@, qr/\bTypeError\b/, + 'MyFoo2.pong() error content preserved'); +} +{ + my $a = MyFoo3->new(); + my $b = director_exception::launder($a); + eval { $b->pong() }; + like($@, qr/\bTypeError\b/, + 'MyFoo2.pong() error content preserved'); +} + +eval { die director_exception::Exception1->new() }; +isa_ok($@, 'director_exception::Exception1', 'Exception1'); + +eval { die director_exception::Exception2->new() }; +isa_ok($@, 'director_exception::Exception2', 'Exception2'); diff --git a/Examples/test-suite/perl5/director_extend_runme.pl b/Examples/test-suite/perl5/director_extend_runme.pl new file mode 100644 index 000000000..c3d7fb934 --- /dev/null +++ b/Examples/test-suite/perl5/director_extend_runme.pl @@ -0,0 +1,16 @@ +use strict; +use warnings; +use Test::More tests => 5; +BEGIN { use_ok 'director_extend' } +require_ok 'director_extend'; + +{ + package MyObject; + use base 'director_extend::SpObject'; + sub getFoo { 123 } +} + +my $m = MyObject->new(); +isa_ok $m, 'MyObject'; +is($m->dummy(), 666, '1st call'); +is($m->dummy(), 666, '2nd call'); diff --git a/Examples/test-suite/perl5/director_finalizer_runme.pl b/Examples/test-suite/perl5/director_finalizer_runme.pl new file mode 100644 index 000000000..bb6e1fa71 --- /dev/null +++ b/Examples/test-suite/perl5/director_finalizer_runme.pl @@ -0,0 +1,83 @@ +use strict; +use warnings; +use Test::More tests => 13; +BEGIN { use_ok('director_finalizer') } +require_ok('director_finalizer'); + +{ + package MyFoo; + use base 'director_finalizer::Foo'; + sub DIRECTOR_DESTROY { my($self) = @_; + $self->orStatus(2); + } +} + +{ + director_finalizer::resetStatus(); + my $f = MyFoo->new(); + undef $f; + is(director_finalizer::getStatus(), 3, 'shadow release fires destructor'); +} + +{ # again, this time with DESTROY + director_finalizer::resetStatus(); + my $f = MyFoo->new(); + $f->DESTROY(); + is(director_finalizer::getStatus(), 3, 'DESTROY method fires destructor'); +} + +{ + director_finalizer::resetStatus(); + my $f = MyFoo->new(); + director_finalizer::launder($f); + is(director_finalizer::getStatus(), 0, 'wrap release does not fire destructor'); + undef $f; + is(director_finalizer::getStatus(), 3, 'shadow release still fires destructor'); +} + +{ # again, this time with DESTROY + director_finalizer::resetStatus(); + my $f = MyFoo->new(); + director_finalizer::launder($f); + is(director_finalizer::getStatus(), 0, 'wrap release does not fire destructor'); + $f->DESTROY(); + is(director_finalizer::getStatus(), 3, 'DESTROY method still fires destructor'); +} + +{ + director_finalizer::resetStatus(); + my $f = MyFoo->new(); + $f->DISOWN(); + is(director_finalizer::getStatus(), 0, 'shadow release does not fire destructor of disowned object'); + director_finalizer::deleteFoo($f); + is(director_finalizer::getStatus(), 3, 'c++ release fires destructors of disowned object'); +} + +{ # again, this time with DESTROY + my $f = MyFoo->new(); + $f->DISOWN(); + director_finalizer::deleteFoo($f); + director_finalizer::resetStatus(); + $f->DESTROY(); + is(director_finalizer::getStatus(), 0, 'DESTROY method does not fire destructor of disowned object'); +} + +{ + director_finalizer::resetStatus(); + my $f = MyFoo->new(); + $f->DISOWN(); + my $g = director_finalizer::launder($f); + undef $f; + director_finalizer::deleteFoo($g); + is(director_finalizer::getStatus(), 3, 'c++ release fires destructors on disowned opaque object'); +} + +{ # again, this time with DESTROY + director_finalizer::resetStatus(); + my $f = MyFoo->new(); + $f->DISOWN(); + my $g = director_finalizer::launder($f); + $f->DESTROY(); + director_finalizer::deleteFoo($g); + is(director_finalizer::getStatus(), 3, 'c++ release fires destructors on disowned opaque object after DESTROY'); +} diff --git a/Examples/test-suite/perl5/director_frob_runme.pl b/Examples/test-suite/perl5/director_frob_runme.pl new file mode 100644 index 000000000..0faf440c5 --- /dev/null +++ b/Examples/test-suite/perl5/director_frob_runme.pl @@ -0,0 +1,10 @@ +use strict; +use warnings; +use Test::More tests => 4; +BEGIN { use_ok 'director_frob' } +require_ok 'director_frob'; + +my $foo = director_frob::Bravo->new(); +isa_ok $foo, 'director_frob::Bravo'; + +is($foo->abs_method(), 'Bravo::abs_method()'); diff --git a/Examples/test-suite/perl5/director_ignore_runme.pl b/Examples/test-suite/perl5/director_ignore_runme.pl new file mode 100644 index 000000000..9566f4bb3 --- /dev/null +++ b/Examples/test-suite/perl5/director_ignore_runme.pl @@ -0,0 +1,25 @@ +use strict; +use warnings; +use Test::More tests => 6; +BEGIN { use_ok 'director_ignore' } +require_ok 'director_ignore'; + +{ + package DIgnoresDerived; + use base 'director_ignore::DIgnores'; + sub PublicMethod1 { + return 18.75; + } +} +{ + package DAbstractIgnoresDerived; + use base 'director_ignore::DAbstractIgnores'; +} + +my $a = DIgnoresDerived->new(); +isa_ok $a, 'DIgnoresDerived'; +is $a->Triple(5), 15; + +my $b = DAbstractIgnoresDerived->new(); +isa_ok $b, 'DAbstractIgnoresDerived'; +is $b->Quadruple(5), 20; diff --git a/Examples/test-suite/perl5/director_nested_runme.pl b/Examples/test-suite/perl5/director_nested_runme.pl new file mode 100644 index 000000000..e6c19665a --- /dev/null +++ b/Examples/test-suite/perl5/director_nested_runme.pl @@ -0,0 +1,59 @@ +use strict; +use warnings; +use Test::More tests => 9; +BEGIN { use_ok 'director_nested' } +require_ok 'director_nested'; + +{ + package A; + use base 'director_nested::FooBar_int'; + sub do_step { 'A::do_step;' } + sub get_value { 'A::get_value' } +} + +my $a = A->new(); +isa_ok $a, 'A'; + +is $a->step(), "Bar::step;Foo::advance;Bar::do_advance;A::do_step;", + 'A virtual resolution'; + +{ + package B; + use base 'director_nested::FooBar_int'; + sub do_advance { my($self) = @_; + return "B::do_advance;" . $self->do_step(); + } + sub do_step { "B::do_step;" } + sub get_value { 1 } +} + +my $b = B->new(); +isa_ok $b, 'B'; +is $b->step(), "Bar::step;Foo::advance;B::do_advance;B::do_step;", + 'B virtual resolution'; + +{ + package C; + use base 'director_nested::FooBar_int'; + our $in_do_advance = 0; + sub do_advance { my($self) = @_; + # found a case where upcall didn't happen right in a perl space + # SUPER:: call. + die "SUPERCALL RESOLVE FAILURE" if $in_do_advance; + local $in_do_advance = 1; + return "C::do_advance;" . + $self->SUPER::do_advance(); + } + sub do_step { "C::do_step;" } + sub get_value { 2 } + sub get_name { my($self) = @_; + return $self->director_nested::FooBar_int::get_name() . " hello"; + } +} + +my $cc = C->new(); +isa_ok $cc, 'C'; +my $c = director_nested::FooBar_int::get_self($cc); +$c->advance(); +is $c->get_name(), "FooBar::get_name hello"; +is $c->name(), "FooBar::get_name hello"; diff --git a/Examples/test-suite/perl5/director_primitives_runme.pl b/Examples/test-suite/perl5/director_primitives_runme.pl new file mode 100644 index 000000000..e70f39166 --- /dev/null +++ b/Examples/test-suite/perl5/director_primitives_runme.pl @@ -0,0 +1,68 @@ +use strict; +use warnings; +use Test::More tests => 27; +BEGIN { use_ok 'director_primitives' } +require_ok 'director_primitives'; + +{ + package PerlDerived; + use base 'director_primitives::Base'; + sub NoParmsMethod { + } + sub BoolMethod { my($self, $x) = @_; + return $x; + } + sub IntMethod { my($self, $x) = @_; + return $x; + } + sub UIntMethod { my($self, $x) = @_; + return $x; + } + sub FloatMethod { my($self, $x) = @_; + return $x; + } + sub CharPtrMethod { my($self, $x) = @_; + return $x; + } + sub ConstCharPtrMethod { my($self, $x) = @_; + return $x; + } + sub EnumMethod { my($self, $x) = @_; + return $x; + } + sub ManyParmsMethod { + } +} + +my $myCaller = director_primitives::Caller->new(); +isa_ok $myCaller, 'director_primitives::Caller'; + +{ + my $myBase = director_primitives::Base->new(100.0); + makeCalls($myCaller, $myBase); +} +{ + my $myBase = director_primitives::Derived->new(200.0); + makeCalls($myCaller, $myBase); +} +{ + my $myBase = PerlDerived->new(300.0); + makeCalls($myCaller, $myBase); +} + +sub makeCalls { my($myCaller, $myBase) = @_; + $myCaller->set($myBase); + $myCaller->NoParmsMethodCall(); + is $myCaller->BoolMethodCall(1), '1'; + is $myCaller->BoolMethodCall(0), ''; + is $myCaller->IntMethodCall(-123), -123; + is $myCaller->UIntMethodCall(123), 123; + is $myCaller->FloatMethodCall(-123 / 128), -0.9609375; + is $myCaller->CharPtrMethodCall("test string"), "test string"; + is $myCaller->ConstCharPtrMethodCall("another string"), "another string"; + is $myCaller->EnumMethodCall($director_primitives::HShadowHard), $director_primitives::HShadowHard; + $myCaller->ManyParmsMethodCall(1, -123, 123, 123.456, "test string", "another string", $director_primitives::HShadowHard); + $myCaller->NotOverriddenMethodCall(); + $myCaller->reset(); +} + diff --git a/Examples/test-suite/perl5/director_protected_runme.pl b/Examples/test-suite/perl5/director_protected_runme.pl new file mode 100644 index 000000000..07ed1563e --- /dev/null +++ b/Examples/test-suite/perl5/director_protected_runme.pl @@ -0,0 +1,48 @@ +use strict; +use warnings; +use Test::More tests => 19; +BEGIN { use_ok 'director_protected' } +require_ok 'director_protected'; + +{ + package FooBar; + use base 'director_protected::Bar'; + sub ping { 'FooBar::ping();' } +} +{ + package FooBar2; + use base 'director_protected::Bar'; + sub ping { 'FooBar2::ping();' } + sub pang { 'FooBar2::pang();' } +} + +my $b = director_protected::Bar->new(); +isa_ok $b, 'director_protected::Bar'; +my $f = $b->create(); +my $fb = FooBar->new(); +isa_ok $fb, 'FooBar'; +my $fb2 = FooBar2->new(); +isa_ok $fb2, 'FooBar2'; + +is $b->used(), "Foo::pang();Bar::pong();Foo::pong();Bar::ping();"; +eval { $f->used() }; +like $@, qr/protected member/; +is $fb->used(), "Foo::pang();Bar::pong();Foo::pong();FooBar::ping();"; +is $fb2->used(), "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();"; + +is $b->pong(), "Bar::pong();Foo::pong();Bar::ping();"; +is $f->pong(), "Bar::pong();Foo::pong();Bar::ping();"; +is $fb->pong(), "Bar::pong();Foo::pong();FooBar::ping();"; +is $fb2->pong(), "Bar::pong();Foo::pong();FooBar2::ping();"; + +eval { $b->ping() }; +like $@, qr/protected member/; +eval { $f->ping () }; +like $@, qr/protected member/; +is $fb->ping(), 'FooBar::ping();'; +is $fb2->ping(), 'FooBar2::ping();'; + +eval { $b->pang() }; +like $@, qr/protected member/; +eval { $f->pang() }; +like $@, qr/protected member/; diff --git a/Examples/test-suite/perl5/director_string_runme.pl b/Examples/test-suite/perl5/director_string_runme.pl new file mode 100644 index 000000000..4d996ef0f --- /dev/null +++ b/Examples/test-suite/perl5/director_string_runme.pl @@ -0,0 +1,34 @@ +use strict; +use warnings; +use Test::More tests => 5; +BEGIN { use_ok 'director_string' } +require_ok 'director_string'; + +{ + package B; + use base 'director_string::A'; + our $in_first = 0; + sub get_first { my($self) = @_; + die "SUPER RESOLVE BAD" if $in_first; + local $in_first = 1; + return $self->SUPER::get_first() . " world!"; + } + our $in_process_text = 0; + sub process_text { my($self, $string) = @_; + die "SUPER RESOLVE BAD" if $in_process_text; + local $in_process_text = 1; + $self->SUPER::process_text($string); + $self->{'smem'} = "hello"; + } +} + +my $b = B->new("hello"); +isa_ok $b, 'B'; + +$b->get(0); + +is $b->get_first(), "hello world!"; + +$b->call_process_func(); + +is $b->{'smem'}, "hello"; diff --git a/Examples/test-suite/perl5/director_unroll_runme.pl b/Examples/test-suite/perl5/director_unroll_runme.pl new file mode 100644 index 000000000..572b99834 --- /dev/null +++ b/Examples/test-suite/perl5/director_unroll_runme.pl @@ -0,0 +1,17 @@ +use strict; +use warnings; +use Test::More tests => 3; +BEGIN { use_ok 'director_unroll' }; +require_ok 'director_unroll'; + +{ + package MyFoo; + use base 'director_unroll::Foo'; + sub ping { "MyFoo::ping()" } +} + +$a = MyFoo->new(); +$b = director_unroll::Bar->new(); +$b->set($a); +my $c = $b->get(); +is(${$a->this}, ${$c->this}, "unrolling"); diff --git a/Examples/test-suite/perl5/director_wombat_runme.pl b/Examples/test-suite/perl5/director_wombat_runme.pl new file mode 100644 index 000000000..81f34e71b --- /dev/null +++ b/Examples/test-suite/perl5/director_wombat_runme.pl @@ -0,0 +1,53 @@ +use strict; +use warnings; +use Test::More tests => 9; +BEGIN { use_ok 'director_wombat' } +require_ok 'director_wombat'; + +{ + package director_wombat_Foo_integers_derived; + use base 'director_wombat::Foo_integers'; + sub meth { my($self, $param) = @_; + return $param + 2; + } +} +{ + package director_wombat_Foo_integers_derived_2; + use base 'director_wombat::Foo_integers'; +} +{ + package director_wombat_Bar_derived_1; + use base 'director_wombat::Bar'; + sub foo_meth_ref { my($self, $foo_obj, $param) = @_; + die "foo_obj in foo_meth_ref is not director_wombat_Foo_integers_derived_2" + unless $foo_obj->isa('director_wombat_Foo_integers_derived_2'); + } + sub foo_meth_ptr { my($self, $foo_obj, $param) = @_; + die "foo_obj in foo_meth_ptr is not director_wombat_Foo_integers_derived_2" + unless $foo_obj->isa('director_wombat_Foo_integers_derived_2'); + } + sub foo_meth_val { my($self, $foo_obj, $param) = @_; + die "foo_obj in foo_meth_val is not director_wombat_Foo_integers_derived_2" + unless $foo_obj->isa('director_wombat_Foo_integers_derived_2'); + } +} + +my $b = director_wombat::Bar->new(); +isa_ok $b, 'director_wombat::Bar'; +my $a = $b->meth(); +is $a->meth(49), 49; + +$a = director_wombat_Foo_integers_derived->new(); +isa_ok $a, 'director_wombat_Foo_integers_derived'; +is $a->meth(62), 62 + 2; + +$a = director_wombat_Foo_integers_derived_2->new(); +isa_ok $a, 'director_wombat_Foo_integers_derived_2'; +is $a->meth(37), 37; + +$b = director_wombat_Bar_derived_1->new(); +isa_ok $b, 'director_wombat_Bar_derived_1'; +$b->foo_meth_ref($a, 0); +$b->foo_meth_ptr($a, 1); +$b->foo_meth_val($a, 2); + diff --git a/Lib/perl5/perlrun.swg b/Lib/perl5/perlrun.swg index ebc4fecd5..4e31c4754 100644 --- a/Lib/perl5/perlrun.swg +++ b/Lib/perl5/perlrun.swg @@ -20,6 +20,7 @@ #define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Perl_ConvertPtr(SWIG_PERL_OBJECT_CALL obj, pp, type, flags) #define SWIG_ConvertPtrAndOwn(obj, pp, type, flags,own) SWIG_Perl_ConvertPtrAndOwn(SWIG_PERL_OBJECT_CALL obj, pp, type, flags, own) #define SWIG_NewPointerObj(p, type, flags) SWIG_Perl_NewPointerObj(SWIG_PERL_OBJECT_CALL p, type, flags) +#define swig_owntype int /* for raw packed data */ #define SWIG_ConvertPacked(obj, p, s, type) SWIG_Perl_ConvertPacked(SWIG_PERL_OBJECT_CALL obj, p, s, type) @@ -288,7 +289,7 @@ SWIG_Perl_ConvertPtrAndOwn(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_ /* Now see if the types match */ char *_c = HvNAME(SvSTASH(SvRV(sv))); tc = SWIG_TypeProxyCheck(_c,_t); - if (!tc) { + if (!tc && !sv_derived_from(sv,SWIG_Perl_TypeProxyName(_t))) { return SWIG_ERROR; } { diff --git a/Lib/perl5/perltypemaps.swg b/Lib/perl5/perltypemaps.swg index fc7100e89..f47a5ef82 100644 --- a/Lib/perl5/perltypemaps.swg +++ b/Lib/perl5/perltypemaps.swg @@ -35,9 +35,9 @@ * Unified typemap section * ------------------------------------------------------------ */ -/* No director supported in Perl */ -#ifdef SWIG_DIRECTOR_TYPEMAPS -#undef SWIG_DIRECTOR_TYPEMAPS +/* director support in Perl is experimental */ +#ifndef SWIG_DIRECTOR_TYPEMAPS +#define SWIG_DIRECTOR_TYPEMAPS #endif diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 09500b23b..182835645 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -79,8 +79,11 @@ static String *variable_tab = 0; static File *f_begin = 0; static File *f_runtime = 0; +static File *f_runtime_h = 0; static File *f_header = 0; static File *f_wrappers = 0; +static File *f_directors = 0; +static File *f_directors_h = 0; static File *f_init = 0; static File *f_pm = 0; static String *pm; /* Package initialization code */ @@ -124,6 +127,7 @@ public: Printv(argc_template_string, "items", NIL); Clear(argv_template_string); Printv(argv_template_string, "ST(%d)", NIL); + director_language = 1; } /* Test to see if a type corresponds to something wrapped with a shadow class */ @@ -219,9 +223,68 @@ public: * ------------------------------------------------------------ */ virtual int top(Node *n) { + /* check if directors are enabled for this module. note: this + * is a "master" switch, without which no director code will be + * emitted. %feature("director") statements are also required + * to enable directors for individual classes or methods. + * + * use %module(directors="1") modulename at the start of the + * interface file to enable director generation. + * + * TODO: directors are disallowed in conjunction with many command + * line options. Some of them are probably safe, but it will take + * some effort to validate each one. + */ + { + Node *mod = Getattr(n, "module"); + if (mod) { + Node *options = Getattr(mod, "options"); + if (options) { + int dirprot = 0; + if (Getattr(options, "dirprot")) + dirprot = 1; + if (Getattr(options, "nodirprot")) + dirprot = 0; + if (Getattr(options, "directors")) { + int allow = 1; + if (export_all) { + Printv(stderr, + "*** directors are not supported with -exportall\n", NIL); + allow = 0; + } + if (staticoption) { + Printv(stderr, + "*** directors are not supported with -static\n", NIL); + allow = 0; + } + if (!blessed) { + Printv(stderr, + "*** directors are not supported with -noproxy\n", NIL); + allow = 0; + } + if (no_pmfile) { + Printv(stderr, + "*** directors are not supported with -nopm\n", NIL); + allow = 0; + } + if (compat) { + Printv(stderr, + "*** directors are not supported with -compat\n", NIL); + allow = 0; + } + if (allow) { + allow_directors(); + if (dirprot) + allow_dirprot(); + } + } + } + } + } /* Initialize all of the output files */ String *outfile = Getattr(n, "outfile"); + String *outfile_h = Getattr(n, "outfile_h"); f_begin = NewFile(outfile, "w", SWIG_output_files()); if (!f_begin) { @@ -232,6 +295,16 @@ public: f_init = NewString(""); f_header = NewString(""); f_wrappers = NewString(""); + f_directors_h = NewString(""); + f_directors = NewString(""); + + if (directorsEnabled()) { + f_runtime_h = NewFile(outfile_h, "w", SWIG_output_files()); + if (!f_runtime_h) { + FileErrorDisplay(outfile_h); + SWIG_exit(EXIT_FAILURE); + } + } /* Register file targets with the SWIG file handler */ Swig_register_filebyname("header", f_header); @@ -239,6 +312,8 @@ public: Swig_register_filebyname("begin", f_begin); Swig_register_filebyname("runtime", f_runtime); Swig_register_filebyname("init", f_init); + Swig_register_filebyname("director", f_directors); + Swig_register_filebyname("director_h", f_directors_h); classlist = NewList(); @@ -259,6 +334,9 @@ public: Printf(f_runtime, "\n"); Printf(f_runtime, "#define SWIGPERL\n"); + if (directorsEnabled()) { + Printf(f_runtime, "#define SWIG_DIRECTORS\n"); + } Printf(f_runtime, "#define SWIG_CASTRANK_MODE\n"); Printf(f_runtime, "\n"); @@ -269,6 +347,27 @@ public: Node *options = Getattr(mod, "options"); module = Copy(Getattr(n,"name")); + if (directorsEnabled()) { + Swig_banner(f_directors_h); + Printf(f_directors_h, "\n"); + Printf(f_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", module); + Printf(f_directors_h, "#define SWIG_%s_WRAP_H_\n\n", module); + if (dirprot_mode()) { + Printf(f_directors_h, "#include \n"); + Printf(f_directors_h, "#include \n\n"); + } + + Printf(f_directors, "\n\n"); + Printf(f_directors, "/* ---------------------------------------------------\n"); + Printf(f_directors, " * C++ director class methods\n"); + Printf(f_directors, " * --------------------------------------------------- */\n\n"); + if (outfile_h) { + String *filename = Swig_file_filename(outfile_h); + Printf(magic, "#include \"%s\"\n\n", filename); + Delete(filename); + } + } + if (verbose > 0) { fprintf(stdout, "top: using module: %s\n", Char(module)); } @@ -374,6 +473,11 @@ public: /* emit wrappers */ Language::top(n); + if (directorsEnabled()) { + // Insert director runtime into the f_runtime file (make it occur before %header section) + Swig_insert_file("director.swg", f_runtime); + } + String *base = NewString(""); /* Dump out variable wrappers */ @@ -526,11 +630,21 @@ public: /* Close all of the files */ Dump(f_runtime, f_begin); Dump(f_header, f_begin); + + if (directorsEnabled()) { + Dump(f_directors_h, f_runtime_h); + Printf(f_runtime_h, "\n"); + Printf(f_runtime_h, "#endif\n"); + Dump(f_directors, f_begin); + } + Dump(f_wrappers, f_begin); Wrapper_pretty_print(f_init, f_begin); Delete(f_header); Delete(f_wrappers); Delete(f_init); + Delete(f_directors); + Delete(f_directors_h); Delete(f_runtime); Delete(f_begin); return SWIG_OK; @@ -560,6 +674,7 @@ public: SwigType *d = Getattr(n, "type"); ParmList *l = Getattr(n, "parms"); String *overname = 0; + int director_method = 0; Parm *p; int i; @@ -720,11 +835,36 @@ public: Wrapper_add_localv(f, "_saved", "SV *", temp, NIL); } + director_method = is_member_director(n) && !is_smart_pointer() && 0 != Cmp(nodeType(n), "destructor"); + if (director_method) { + Wrapper_add_local(f, "director", "Swig::Director *director = 0"); + Append(f->code, "director = SWIG_DIRECTOR_CAST(arg1);\n"); + if (dirprot_mode() && !is_public(n)) { + Printf(f->code, "if (!director || !(director->swig_get_inner(\"%s\"))) {\n", name); + Printf(f->code, "SWIG_exception_fail(SWIG_RuntimeError, \"accessing protected member %s\");\n", name); + Append(f->code, "}\n"); + } + Wrapper_add_local(f, "upcall", "bool upcall = false"); + Printf(f->code, "upcall = director && SvSTASH(SvRV(ST(0))) == gv_stashpv(director->swig_get_class(), 0);\n"); + } + + /* Emit the function call */ + if (director_method) { + Append(f->code, "try {\n"); + } + /* Now write code to make the function call */ Swig_director_emit_dynamic_cast(n, f); String *actioncode = emit_action(n); + if (director_method) { + Append(actioncode, "} catch (Swig::DirectorException& swig_err) {\n"); + Append(actioncode, " sv_setsv(ERRSV, swig_err.getNative());\n"); + Append(actioncode, " SWIG_fail;\n"); + Append(actioncode, "}\n"); + } + if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) { SwigType *t = Getattr(n, "type"); Replaceall(tm, "$source", Swig_cresult_name()); @@ -1335,17 +1475,67 @@ public: /* Output methods for managing ownership */ + String *director_disown; + if (Getattr(n, "perl5:directordisown")) { + director_disown = NewStringf("%s%s($self);\n", + tab4, Getattr(n, "perl5:directordisown")); + } else { + director_disown = NewString(""); + } Printv(pm, "sub DISOWN {\n", tab4, "my $self = shift;\n", + director_disown, tab4, "my $ptr = tied(%$self);\n", tab4, "delete $OWNER{$ptr};\n", "}\n\n", "sub ACQUIRE {\n", tab4, "my $self = shift;\n", tab4, "my $ptr = tied(%$self);\n", tab4, "$OWNER{$ptr} = 1;\n", "}\n\n", NIL); + Delete(director_disown); /* Only output the following methods if a class has member data */ Delete(operators); operators = 0; + if (Swig_directorclass(n)) { + /* director classes need a way to recover subclass instance attributes */ + Node *get_attr = NewHash(); + String *mrename; + String *symname = Getattr(n, "sym:name"); + mrename = Swig_name_disown(NSPACE_TODO, symname); + Replaceall(mrename, "disown", "swig_get_attr"); + String *type = NewString(getClassType()); + String *name = NewString("self"); + SwigType_add_pointer(type); + Parm *p = NewParm(type, name, n); + Delete(name); + Delete(type); + type = NewString("SV"); + SwigType_add_pointer(type); + String *action = NewString(""); + Printv(action, "{\n", " Swig::Director *director = SWIG_DIRECTOR_CAST(arg1);\n", " result = sv_newmortal();\n" " if (director) sv_setsv(result, director->swig_get_self());\n", "}\n", NIL); + Setfile(get_attr, Getfile(n)); + Setline(get_attr, Getline(n)); + Setattr(get_attr, "wrap:action", action); + Setattr(get_attr, "name", mrename); + Setattr(get_attr, "sym:name", mrename); + Setattr(get_attr, "type", type); + Setattr(get_attr, "parms", p); + Delete(action); + Delete(type); + Delete(p); + + member_func = 1; + functionWrapper(get_attr); + member_func = 0; + Delete(get_attr); + + Printv(pm, "sub FETCH {\n", tab4, "my ($self,$field) = @_;\n", tab4, "my $member_func = \"swig_${field}_get\";\n", tab4, + "if (not $self->can(\"$member_func\")) {\n", tab4, tab4, "my $h = ", cmodule, "::", mrename, "($self);\n", tab4, tab4, + "return $h->{$field} if $h;\n", tab4, "}\n", tab4, "return $self->$member_func;\n", "}\n", "\n", "sub STORE {\n", tab4, + "my ($self,$field,$newval) = @_;\n", tab4, "my $member_func = \"swig_${field}_set\";\n", tab4, + "if (not $self->can(\"$member_func\")) {\n", tab4, tab4, "my $h = ", cmodule, "::", mrename, "($self);\n", tab4, tab4, + "return $h->{$field} = $newval if $h;\n", tab4, "}\n", tab4, "return $self->$member_func($newval);\n", "}\n", NIL); + Delete(mrename); + } } return SWIG_OK; } @@ -1494,7 +1684,41 @@ public: String *symname = Getattr(n, "sym:name"); member_func = 1; + + Swig_save("perl5:constructorHandler", n, "parms", NIL); + if (Swig_directorclass(n)) { + Parm *parms = Getattr(n, "parms"); + Parm *self; + String *name = NewString("self"); + String *type = NewString("SV"); + SwigType_add_pointer(type); + self = NewParm(type, name, n); + Delete(type); + Delete(name); + Setattr(self, "lname", "O"); + if (parms) + set_nextSibling(self, parms); + Setattr(n, "parms", self); + Setattr(n, "wrap:self", "1"); + Setattr(n, "hidden", "1"); + Delete(self); + } + + String *saved_nc = none_comparison; + none_comparison = NewStringf("strcmp(SvPV_nolen(ST(0)), \"%s::%s\") != 0", module, class_name); + String *saved_director_prot_ctor_code = director_prot_ctor_code; + director_prot_ctor_code = NewStringf( + "if ($comparison) { /* subclassed */\n" + " $director_new\n" + "} else {\n" + " SWIG_exception_fail(SWIG_RuntimeError, \"accessing abstract class or protected constructor\");\n" + "}\n"); Language::constructorHandler(n); + Delete(none_comparison); + none_comparison = saved_nc; + Delete(director_prot_ctor_code); + director_prot_ctor_code = saved_director_prot_ctor_code; + Swig_restore(n); if ((blessed) && (!Getattr(n, "sym:nextSibling"))) { if (Getattr(n, "feature:shadow")) { @@ -1512,8 +1736,9 @@ public: Printv(pcode, "sub ", Swig_name_construct(NSPACE_TODO, symname), " {\n", NIL); } + const char *pkg = getCurrentClass() && Swig_directorclass(getCurrentClass()) ? "$_[0]" : "shift"; Printv(pcode, - tab4, "my $pkg = shift;\n", + tab4, "my $pkg = ", pkg, ";\n", 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; @@ -1752,6 +1977,591 @@ public: String *defaultExternalRuntimeFilename() { return NewString("swigperlrun.h"); } + + virtual int classDirectorInit(Node *n) { + String *declaration = Swig_director_declaration(n); + Printf(f_directors_h, "\n"); + Printf(f_directors_h, "%s\n", declaration); + Printf(f_directors_h, "public:\n"); + Delete(declaration); + return Language::classDirectorInit(n); + } + + virtual int classDirectorEnd(Node *n) { + if (dirprot_mode()) { + /* + This implementation uses a std::map. + + It should be possible to rewrite it using a more elegant way, + like copying the Java approach for the 'override' array. + + But for now, this seems to be the least intrusive way. + */ + 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* swig_protected_method_name) const {\n"); + Printf(f_directors_h, " std::map::const_iterator iv = swig_inner.find(swig_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* swig_protected_method_name, bool val) const\n"); + Printf(f_directors_h, " { swig_inner[swig_protected_method_name] = val;}\n\n"); + Printf(f_directors_h, "private:\n"); + Printf(f_directors_h, " mutable std::map swig_inner;\n"); + } + Printf(f_directors_h, "};\n"); + return Language::classDirectorEnd(n); + } + + virtual int classDirectorConstructor(Node *n) { + Node *parent = Getattr(n, "parentNode"); + String *sub = NewString(""); + String *decl = Getattr(n, "decl"); + String *supername = Swig_class_name(parent); + String *classname = NewString(""); + Printf(classname, "SwigDirector_%s", supername); + + /* insert self parameter */ + Parm *p; + ParmList *superparms = Getattr(n, "parms"); + ParmList *parms = CopyParmList(superparms); + String *type = NewString("SV"); + SwigType_add_pointer(type); + p = NewParm(type, NewString("self"), n); + set_nextSibling(p, parms); + parms = p; + + if (!Getattr(n, "defaultargs")) { + /* constructor */ + { + Wrapper *w = NewWrapper(); + String *call; + String *basetype = Getattr(parent, "classtype"); + String *target = Swig_method_decl(0, decl, classname, parms, 0, 0); + call = Swig_csuperclass_call(0, basetype, superparms); + Printf(w->def, "%s::%s: %s, Swig::Director(self) { \n", classname, target, call); + Printf(w->def, " SWIG_DIRECTOR_RGTR((%s *)this, this); \n", basetype); + Append(w->def, "}\n"); + Delete(target); + Wrapper_print(w, f_directors); + Delete(call); + DelWrapper(w); + } + + /* constructor header */ + { + String *target = Swig_method_decl(0, decl, classname, parms, 0, 1); + Printf(f_directors_h, " %s;\n", target); + Delete(target); + } + } + + Delete(sub); + Delete(classname); + Delete(supername); + Delete(parms); + return Language::classDirectorConstructor(n); + } + + virtual int classDirectorMethod(Node *n, Node *parent, String *super) { + int is_void = 0; + int is_pointer = 0; + String *decl = Getattr(n, "decl"); + String *name = Getattr(n, "name"); + String *classname = Getattr(parent, "sym:name"); + String *c_classname = Getattr(parent, "name"); + String *symname = Getattr(n, "sym:name"); + String *declaration = NewString(""); + ParmList *l = Getattr(n, "parms"); + Wrapper *w = NewWrapper(); + String *tm; + String *wrap_args = NewString(""); + String *returntype = Getattr(n, "type"); + String *value = Getattr(n, "value"); + String *storage = Getattr(n, "storage"); + bool pure_virtual = false; + int status = SWIG_OK; + int idx; + bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; + int addfail = 0; + + if (Cmp(storage, "virtual") == 0) { + if (Cmp(value, "0") == 0) { + pure_virtual = true; + } + } + + /* determine if the method returns a pointer */ + is_pointer = SwigType_ispointer_return(decl); + is_void = (!Cmp(returntype, "void") && !is_pointer); + + /* virtual method definition */ + String *target; + String *pclassname = NewStringf("SwigDirector_%s", classname); + String *qualified_name = NewStringf("%s::%s", pclassname, name); + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type"); + target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); + Printf(w->def, "%s", target); + Delete(qualified_name); + Delete(target); + /* header declaration */ + target = Swig_method_decl(rtype, decl, name, l, 0, 1); + Printf(declaration, " virtual %s", target); + Delete(target); + + // Get any exception classes in the throws typemap + ParmList *throw_parm_list = 0; + + if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) { + Parm *p; + int gencomma = 0; + + Append(w->def, " throw("); + Append(declaration, " throw("); + + if (throw_parm_list) + Swig_typemap_attach_parms("throws", throw_parm_list, 0); + for (p = throw_parm_list; p; p = nextSibling(p)) { + if (Getattr(p, "tmap:throws")) { + if (gencomma++) { + Append(w->def, ", "); + Append(declaration, ", "); + } + String *str = SwigType_str(Getattr(p, "type"), 0); + Append(w->def, str); + Append(declaration, str); + Delete(str); + } + } + + Append(w->def, ")"); + Append(declaration, ")"); + } + + Append(w->def, " {"); + Append(declaration, ";\n"); + + /* declare method return value + * if the return value is a reference or const reference, a specialized typemap must + * handle it, including declaration of c_result ($result). + */ + if (!is_void) { + if (!(ignored_method && !pure_virtual)) { + String *cres = SwigType_lstr(returntype, "c_result"); + Printf(w->code, "%s;\n", cres); + Delete(cres); + String *pres = NewStringf("SV *%s", Swig_cresult_name()); + Wrapper_add_local(w, Swig_cresult_name(), pres); + Delete(pres); + } + } + + //if (builtin) { + // Printv(w->code, "PyObject *self = NULL;\n", NIL); + // Printv(w->code, "(void)self;\n", NIL); + //} + + if (ignored_method) { + if (!pure_virtual) { + if (!is_void) + Printf(w->code, "return "); + String *super_call = Swig_method_call(super, l); + Printf(w->code, "%s;\n", super_call); + Delete(super_call); + } else { + Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), + SwigType_namestr(name)); + } + } else { + /* attach typemaps to arguments (C/C++ -> Perl) */ + String *arglist = NewString(""); + String *parse_args = NewString(""); + String *pstack = NewString(""); + + Swig_director_parms_fixup(l); + + /* remove the wrapper 'w' since it was producing spurious temps */ + Swig_typemap_attach_parms("in", l, 0); + Swig_typemap_attach_parms("directorin", l, 0); + Swig_typemap_attach_parms("directorargout", l, w); + + Wrapper_add_local(w, "SP", "dSP"); + + { + String *ptype = Copy(getClassType()); + SwigType_add_pointer(ptype); + String *mangle = SwigType_manglestr(ptype); + + Wrapper_add_local(w, "self", "SV *self"); + Printf(w->code, "self = SWIG_NewPointerObj(SWIG_as_voidptr(this), SWIGTYPE%s, SWIG_SHADOW);\n", mangle); + Printf(w->code, "sv_bless(self, gv_stashpv(swig_get_class(), 0));\n"); + Delete(mangle); + Delete(ptype); + Append(pstack, "XPUSHs(self);\n"); + } + + Parm *p; + char source[256]; + + int outputs = 0; + if (!is_void) + outputs++; + + /* build argument list and type conversion string */ + idx = 0; + p = l; + int use_parse = 0; + while (p) { + if (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); + continue; + } + + /* old style? caused segfaults without the p!=0 check + in the for() condition, and seems dangerous in the + while loop as well. + while (Getattr(p, "tmap:ignore")) { + p = Getattr(p, "tmap:ignore:next"); + } + */ + + if (Getattr(p, "tmap:directorargout") != 0) + outputs++; + + String *pname = Getattr(p, "name"); + String *ptype = Getattr(p, "type"); + + Putc(',', arglist); + if ((tm = Getattr(p, "tmap:directorin")) != 0) { + String *parse = Getattr(p, "tmap:directorin:parse"); + if (!parse) { + sprintf(source, "obj%d", idx++); + String *input = NewString(source); + Setattr(p, "emit:directorinput", input); + Replaceall(tm, "$input", input); + Delete(input); + Replaceall(tm, "$owner", "0"); + Replaceall(tm, "$shadow", "0"); + /* Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL); */ + Printv(wrap_args, "SV *", source, ";\n", NIL); + + Printv(wrap_args, tm, "\n", NIL); + Printv(arglist, "(PyObject *)", source, NIL); + Putc('O', parse_args); + Printv(pstack, "XPUSHs(", source, ");\n", NIL); + } else { + use_parse = 1; + Append(parse_args, parse); + Setattr(p, "emit:directorinput", pname); + Replaceall(tm, "$input", pname); + Replaceall(tm, "$owner", "0"); + Replaceall(tm, "$shadow", "0"); + if (Len(tm) == 0) + Append(tm, pname); + Append(arglist, tm); + } + p = Getattr(p, "tmap:directorin:next"); + continue; + } else if (Cmp(ptype, "void")) { + /* special handling for pointers to other C++ director classes. + * ideally this would be left to a typemap, but there is currently no + * way to selectively apply the dynamic_cast<> to classes that have + * directors. in other words, the type "SwigDirector_$1_lname" only exists + * for classes with directors. we avoid the problem here by checking + * module.wrap::directormap, but it's not clear how to get a typemap to + * do something similar. perhaps a new default typemap (in addition + * to SWIGTYPE) called DIRECTORTYPE? + */ + if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) { + Node *module = Getattr(parent, "module"); + Node *target = Swig_directormap(module, ptype); + sprintf(source, "obj%d", idx++); + String *nonconst = 0; + /* strip pointer/reference --- should move to Swig/stype.c */ + String *nptype = NewString(Char(ptype) + 2); + /* name as pointer */ + String *ppname = Copy(pname); + if (SwigType_isreference(ptype)) { + Insert(ppname, 0, "&"); + } + /* if necessary, cast away const since Python doesn't support it! */ + if (SwigType_isconst(nptype)) { + nonconst = NewStringf("nc_tmp_%s", pname); + String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname); + Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); + Delete(nonconst_i); + Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, + "Target language argument '%s' discards const in director method %s::%s.\n", + SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name)); + } else { + nonconst = Copy(ppname); + } + Delete(nptype); + Delete(ppname); + String *mangle = SwigType_manglestr(ptype); + if (target) { + String *director = NewStringf("director_%s", mangle); + Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL); + Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); + Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst); + Printf(wrap_args, "if (!%s) {\n", director); + Printf(wrap_args, "%s = SWIG_InternalNewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); + Append(wrap_args, "} else {\n"); + Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director); + Printf(wrap_args, "Py_INCREF((PyObject *)%s);\n", source); + Append(wrap_args, "}\n"); + Delete(director); + Printv(arglist, source, NIL); + } else { + Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL); + Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); + Printf(pstack, "XPUSHs(sv_2mortal(%s));\n", source); + //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n", + // source, nonconst, base); + Printv(arglist, source, NIL); + } + Putc('O', parse_args); + Delete(mangle); + Delete(nonconst); + } else { + Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, + "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0), + SwigType_namestr(c_classname), SwigType_namestr(name)); + status = SWIG_NOWRAP; + break; + } + } + p = nextSibling(p); + } + + /* add the method name as a PyString */ + String *pyname = Getattr(n, "sym:name"); + + //int allow_thread = threads_enable(n); + // + //if (allow_thread) { + // thread_begin_block(n, w->code); + // Append(w->code, "{\n"); + //} + + /* wrap complex arguments to PyObjects */ + Printv(w->code, wrap_args, NIL); + + /* pass the method call on to the Python object */ + if (dirprot_mode() && !is_public(n)) { + Printf(w->code, "swig_set_inner(\"%s\", true);\n", name); + } + + Append(w->code, "ENTER;\n"); + Append(w->code, "SAVETMPS;\n"); + Append(w->code, "PUSHMARK(SP);\n"); + Append(w->code, pstack); + Delete(pstack); + Append(w->code, "PUTBACK;\n"); + Printf(w->code, "call_method(\"%s\", G_EVAL | G_SCALAR);\n", pyname); + + if (dirprot_mode() && !is_public(n)) + Printf(w->code, "swig_set_inner(\"%s\", false);\n", name); + + /* exception handling */ + tm = Swig_typemap_lookup("director:except", n, Swig_cresult_name(), 0); + if (!tm) { + tm = Getattr(n, "feature:director:except"); + if (tm) + tm = Copy(tm); + } + Append(w->code, "if (SvTRUE(ERRSV)) {\n"); + Append(w->code, " PUTBACK;\n FREETMPS;\n LEAVE;\n"); + if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { + Replaceall(tm, "$error", "error"); + Printv(w->code, Str(tm), "\n", NIL); + } else { + Printf(w->code, " Swig::DirectorMethodException::raise(ERRSV);\n", classname, pyname); + } + Append(w->code, "}\n"); + Delete(tm); + + /* + * Python method may return a simple object, or a tuple. + * for in/out aruments, we have to extract the appropriate PyObjects from the tuple, + * then marshal everything back to C/C++ (return value and output arguments). + * + */ + + /* marshal return value and other outputs (if any) from PyObject to C/C++ type */ + + String *cleanup = NewString(""); + String *outarg = NewString(""); + + if (outputs > 1) { + Wrapper_add_local(w, "output", "PyObject *output"); + Printf(w->code, "if (!PyTuple_Check(%s)) {\n", Swig_cresult_name()); + Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", classname, pyname); + Append(w->code, "}\n"); + } + + idx = 0; + + /* marshal return value */ + if (!is_void) { + Append(w->code, "SPAGAIN;\n"); + Printf(w->code, "%s = POPs;\n", Swig_cresult_name()); + tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); + if (tm != 0) { + if (outputs > 1) { + Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++); + Replaceall(tm, "$input", "output"); + } else { + Replaceall(tm, "$input", Swig_cresult_name()); + } + char temp[24]; + sprintf(temp, "%d", idx); + Replaceall(tm, "$argnum", temp); + + /* TODO check this */ + if (Getattr(n, "wrap:disown")) { + Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); + } else { + Replaceall(tm, "$disown", "0"); + } + //if (Getattr(n, "tmap:directorout:implicitconv")) { + // Replaceall(tm, "$implicitconv", get_implicitconv_flag(n)); + //} + Replaceall(tm, "$result", "c_result"); + Printv(w->code, tm, "\n", NIL); + Delete(tm); + } else { + Swig_print_node(n); + Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, + "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname), + SwigType_namestr(name)); + status = SWIG_ERROR; + } + } + + /* marshal outputs */ + for (p = l; p;) { + if ((tm = Getattr(p, "tmap:directorargout")) != 0) { + if (outputs > 1) { + Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++); + Replaceall(tm, "$result", "output"); + } else { + Replaceall(tm, "$result", Swig_cresult_name()); + } + Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); + Printv(w->code, tm, "\n", NIL); + p = Getattr(p, "tmap:directorargout:next"); + } else { + p = nextSibling(p); + } + } + + /* any existing helper functions to handle this? */ + //if (allow_thread) { + // Append(w->code, "}\n"); + // thread_end_block(n, w->code); + //} + + Delete(parse_args); + Delete(arglist); + Delete(cleanup); + Delete(outarg); + } + + if (!ignored_method) { + Append(w->code, "PUTBACK;\n"); + Append(w->code, "FREETMPS;\n"); + Append(w->code, "LEAVE;\n"); + } + + if (!is_void) { + if (!(ignored_method && !pure_virtual)) { + String *rettype = SwigType_str(returntype, 0); + if (!SwigType_isreference(returntype)) { + Printf(w->code, "return (%s) c_result;\n", rettype); + } else { + Printf(w->code, "return (%s) *c_result;\n", rettype); + } + Delete(rettype); + } + } + + if (addfail) { + Append(w->code, "fail:\n"); + Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s->%s'\");\n", classname, Getattr(n, "sym:name")); + } + + Append(w->code, "}\n"); + + // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method + String *inline_extra_method = NewString(""); + if (dirprot_mode() && !is_public(n) && !pure_virtual) { + Printv(inline_extra_method, declaration, NIL); + String *extra_method_name = NewStringf("%sSwigPublic", name); + Replaceall(inline_extra_method, name, extra_method_name); + Replaceall(inline_extra_method, ";\n", " {\n "); + if (!is_void) + Printf(inline_extra_method, "return "); + String *methodcall = Swig_method_call(super, l); + Printv(inline_extra_method, methodcall, ";\n }\n", NIL); + Delete(methodcall); + Delete(extra_method_name); + } + + /* emit the director method */ + if (status == SWIG_OK) { + if (!Getattr(n, "defaultargs")) { + Replaceall(w->code, "$symname", symname); + Wrapper_print(w, f_directors); + Printv(f_directors_h, declaration, NIL); + Printv(f_directors_h, inline_extra_method, NIL); + } + } + + /* clean up */ + Delete(wrap_args); + Delete(pclassname); + DelWrapper(w); + return status; + } + int classDirectorDisown(Node *n) { + int rv; + member_func = 1; + rv = Language::classDirectorDisown(n); + member_func = 0; + if(rv == SWIG_OK && Swig_directorclass(n)) { + String *symname = Getattr(n, "sym:name"); + String *disown = Swig_name_disown(NSPACE_TODO, symname); + Setattr(n, "perl5:directordisown", NewStringf("%s::%s", cmodule, disown)); + } + return rv; + } + int classDirectorDestructor(Node *n) { + /* TODO: it would be nice if this didn't have to copy the body of Language::classDirectorDestructor() */ + String *DirectorClassName = directorClassName(getCurrentClass()); + String *body = NewString("\n"); + + String *ptype = Copy(getClassType()); + SwigType_add_pointer(ptype); + String *mangle = SwigType_manglestr(ptype); + + Printv(body, tab4, "dSP;\n", tab4, "SV *self = SWIG_NewPointerObj(SWIG_as_voidptr(this), SWIGTYPE", mangle, ", SWIG_SHADOW);\n", tab4, "\n", tab4, + "sv_bless(self, gv_stashpv(swig_get_class(), 0));\n", tab4, "ENTER;\n", tab4, "SAVETMPS;\n", tab4, "PUSHMARK(SP);\n", tab4, "XPUSHs(self);\n", + tab4, "PUTBACK;\n", tab4, "call_method(\"DIRECTOR_DESTROY\", G_EVAL | G_VOID);\n", tab4, "FREETMPS;\n", tab4, "LEAVE;\n", NIL); + + Delete(mangle); + Delete(ptype); + + if (Getattr(n, "throw")) { + Printf(f_directors_h, " virtual ~%s() throw ();\n", DirectorClassName); + Printf(f_directors, "%s::~%s() throw () {%s}\n\n", DirectorClassName, DirectorClassName, body); + } else { + Printf(f_directors_h, " virtual ~%s();\n", DirectorClassName); + Printf(f_directors, "%s::~%s() {%s}\n\n", DirectorClassName, DirectorClassName, body); + } + return SWIG_OK; + } }; /* ----------------------------------------------------------------------------- From 34c374d7ae201a2a9902f721e4e31a2ad785b557 Mon Sep 17 00:00:00 2001 From: Robert Stone Date: Tue, 12 Nov 2013 12:48:21 -0800 Subject: [PATCH 0770/1160] don't forget the most important part --- Lib/perl5/director.swg | 479 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 479 insertions(+) create mode 100644 Lib/perl5/director.swg diff --git a/Lib/perl5/director.swg b/Lib/perl5/director.swg new file mode 100644 index 000000000..937b727a4 --- /dev/null +++ b/Lib/perl5/director.swg @@ -0,0 +1,479 @@ +/* ----------------------------------------------------------------------------- + * director.swg + * + * This file contains support for director classes that proxy + * method calls from C++ to Python extensions. + * ----------------------------------------------------------------------------- */ + +#ifndef SWIG_DIRECTOR_PERL_HEADER_ +#define SWIG_DIRECTOR_PERL_HEADER_ + +#ifdef __cplusplus + +#include +#include +#include +#include +#include + + +/* + Use -DSWIG_PYTHON_DIRECTOR_NO_VTABLE if you don't want to generate a 'virtual + table', and avoid multiple GetAttr calls to retrieve the python + methods. +*/ + +#ifndef SWIG_PERL_DIRECTOR_NO_VTABLE +#ifndef SWIG_PERL_DIRECTOR_VTABLE +#define SWIG_PERL_DIRECTOR_VTABLE +#endif +#endif + + + +/* + Use -DSWIG_DIRECTOR_NO_UEH if you prefer to avoid the use of the + Undefined Exception Handler provided by swig. +*/ +#ifndef SWIG_DIRECTOR_NO_UEH +#ifndef SWIG_DIRECTOR_UEH +#define SWIG_DIRECTOR_UEH +#endif +#endif + + +/* + Use -DSWIG_DIRECTOR_STATIC if you prefer to avoid the use of the + 'Swig' namespace. This could be useful for multi-modules projects. +*/ +#ifdef SWIG_DIRECTOR_STATIC +/* Force anonymous (static) namespace */ +#define Swig +#endif + + +/* + Use -DSWIG_DIRECTOR_NORTTI if you prefer to avoid the use of the + native C++ RTTI and dynamic_cast<>. But be aware that directors + could stop working when using this option. +*/ +#ifdef SWIG_DIRECTOR_NORTTI +/* + When we don't use the native C++ RTTI, we implement a minimal one + only for Directors. +*/ +# ifndef SWIG_DIRECTOR_RTDIR +# define SWIG_DIRECTOR_RTDIR +#include + +namespace Swig { + class Director; + SWIGINTERN std::map& get_rtdir_map() { + static std::map rtdir_map; + return rtdir_map; + } + + SWIGINTERNINLINE void set_rtdir(void *vptr, Director *rtdir) { + get_rtdir_map()[vptr] = rtdir; + } + + SWIGINTERNINLINE Director *get_rtdir(void *vptr) { + std::map::const_iterator pos = get_rtdir_map().find(vptr); + Director *rtdir = (pos != get_rtdir_map().end()) ? pos->second : 0; + return rtdir; + } +} +# 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) + +#else + +# define SWIG_DIRECTOR_CAST(ARG) dynamic_cast(ARG) +# define SWIG_DIRECTOR_RGTR(ARG1, ARG2) + +#endif /* SWIG_DIRECTOR_NORTTI */ + +extern "C" { + struct swig_type_info; +} + +namespace Swig { + + /* memory handler */ + struct GCItem + { + virtual ~GCItem() {} + + virtual int get_own() const + { + return 0; + } + }; + + struct GCItem_var + { + GCItem_var(GCItem *item = 0) : _item(item) + { + } + + GCItem_var& operator=(GCItem *item) + { + GCItem *tmp = _item; + _item = item; + delete tmp; + return *this; + } + + ~GCItem_var() + { + delete _item; + } + + GCItem * operator->() const + { + return _item; + } + + private: + GCItem *_item; + }; + + struct GCItem_Object : GCItem + { + GCItem_Object(int own) : _own(own) + { + } + + virtual ~GCItem_Object() + { + } + + int get_own() const + { + return _own; + } + + private: + int _own; + }; + + template + struct GCItem_T : GCItem + { + GCItem_T(Type *ptr) : _ptr(ptr) + { + } + + virtual ~GCItem_T() + { + delete _ptr; + } + + private: + Type *_ptr; + }; + + template + struct GCArray_T : GCItem + { + GCArray_T(Type *ptr) : _ptr(ptr) + { + } + + virtual ~GCArray_T() + { + delete[] _ptr; + } + + private: + Type *_ptr; + }; + + /* base class for director exceptions */ + class DirectorException { + public: + virtual const char *getMessage() const = 0; + virtual SV *getNative() const = 0; + }; + /* exceptions emitted by Perl */ + class DirectorMethodException : public Swig::DirectorException { + protected: + SV *err; + public: + DirectorMethodException(SV *sv) + : err(sv) + { + SvREFCNT_inc(err); + } + ~DirectorMethodException() + { + SvREFCNT_dec(err); + } + const char *getMessage() const + { + return SvPV_nolen(err); + } + SV *getNative() const + { + return sv_2mortal(newSVsv(err)); + } + static void raise(SV *sv) + { + throw DirectorMethodException(sv); + } + }; + /* exceptions emitted by wrap code */ + class DirectorWrapException : public Swig::DirectorException { + protected: + std::string msg; + DirectorWrapException(const char *str) + : msg(str) + { + } + public: + virtual const char *getMessage() const + { + return msg.c_str(); + } + virtual SV *getNative() const { + return sv_2mortal(newSVpvn(msg.data(), msg.size())); + } + }; + class DirectorTypeMismatchException : public Swig::DirectorWrapException { + public: + DirectorTypeMismatchException(const char *str) + : DirectorWrapException(str) + { + } + static void raise(const char *type, const char *msg) + { + std::string err = std::string(type); + err += ": "; + err += msg; + throw DirectorTypeMismatchException(err.c_str()); + } + }; + class DirectorPureVirtualException : public Swig::DirectorWrapException { + public: + DirectorPureVirtualException(const char *name) + : DirectorWrapException("SWIG director pure virtual method called: ") + { + msg += name; + } + static void raise(const char *name) + { + throw DirectorPureVirtualException(name); + } + }; +// /* unknown exception handler */ +// class UnknownExceptionHandler +// { +//#ifdef SWIG_DIRECTOR_UEH +// static void handler() { +// try { +// throw; +// } catch (DirectorException& e) { +// std::cerr << "SWIG Director exception caught:" << std::endl +// << e.getMessage() << std::endl; +// } catch (std::exception& e) { +// std::cerr << "std::exception caught: "<< e.what() << std::endl; +// } catch (...) { +// std::cerr << "Unknown exception caught." << std::endl; +// } +// +// //std::cerr << std::endl +// // << "Python interpreter traceback:" << std::endl; +// //PyErr_Print(); +// //std::cerr << std::endl; +// +// std::cerr << "This exception was caught by the SWIG unexpected exception handler." << std::endl +// << "Try using %feature(\"director:except\") to avoid reaching this point." << std::endl +// << std::endl +// << "Exception is being re-thrown, program will likely abort/terminate." << std::endl; +// throw; +// } +// +// public: +// +// std::unexpected_handler old; +// UnknownExceptionHandler(std::unexpected_handler nh = handler) +// { +// old = std::set_unexpected(nh); +// } +// +// ~UnknownExceptionHandler() +// { +// std::set_unexpected(old); +// } +//#endif +// }; + +#if defined(SWIG_PYTHON_THREADS) +/* __THREAD__ is the old macro to activate some thread support */ +# if !defined(__THREAD__) +# define __THREAD__ 1 +# endif +#endif + +#ifdef __THREAD__ +# include "pythread.h" + class Guard + { + PyThread_type_lock & mutex_; + + public: + Guard(PyThread_type_lock & mutex) : mutex_(mutex) + { + PyThread_acquire_lock(mutex_, WAIT_LOCK); + } + + ~Guard() + { + PyThread_release_lock(mutex_); + } + }; +# define SWIG_GUARD(mutex) Guard _guard(mutex) +#else +# define SWIG_GUARD(mutex) +#endif + + /* director base class */ + class Director { + private: + /* pointer to the wrapped perl object */ + SV *swig_self; + /* class of wrapped perl object */ + std::string swig_class; + /* flag indicating whether the object is owned by perl or c++ */ + mutable bool swig_disown_flag; + + /* decrement the reference count of the wrapped perl object */ + void swig_decref() const { + if (swig_disown_flag) { + SvREFCNT_dec(swig_self); + } + } + + public: + /* wrap a python object, optionally taking ownership */ + Director(SV *pkg) : swig_disown_flag(false) { + STRLEN len; + char *str = SvPV(pkg, len); + swig_class = std::string(str, len); + swig_self = newRV_inc((SV *)newHV()); + swig_incref(); + } + + + /* discard our reference at destruction */ + virtual ~Director() { + swig_decref(); + } + + + /* return a pointer to the wrapped python object */ + SV *swig_get_self() const { + return swig_self; + } + + const char *swig_get_class() const { + return swig_class.c_str(); + } + + /* acquire ownership of the wrapped python object (the sense of "disown" + * is from python) */ + void swig_disown() const { + if (!swig_disown_flag) { + swig_disown_flag=true; + swig_incref(); + } + } + + /* increase the reference count of the wrapped python object */ + void swig_incref() const { + if (swig_disown_flag) { + SvREFCNT_inc(swig_self); + } + } + + /* methods to implement pseudo protected director members */ + virtual bool swig_get_inner(const char* /* swig_protected_method_name */) const { + return true; + } + + virtual void swig_set_inner(const char* /* swig_protected_method_name */, bool /* swig_val */) const { + } + + /* ownership management */ + private: + typedef std::map swig_ownership_map; + mutable swig_ownership_map swig_owner; +#ifdef __THREAD__ + static PyThread_type_lock swig_mutex_own; +#endif + + public: + template + void swig_acquire_ownership_array(Type *vptr) const + { + if (vptr) { + SWIG_GUARD(swig_mutex_own); + swig_owner[vptr] = new GCArray_T(vptr); + } + } + + template + void swig_acquire_ownership(Type *vptr) const + { + if (vptr) { + SWIG_GUARD(swig_mutex_own); + swig_owner[vptr] = new GCItem_T(vptr); + } + } + + void swig_acquire_ownership_obj(void *vptr, int own) const + { + if (vptr && own) { + SWIG_GUARD(swig_mutex_own); + swig_owner[vptr] = new GCItem_Object(own); + } + } + + int swig_release_ownership(void *vptr) const + { + int own = 0; + if (vptr) { + SWIG_GUARD(swig_mutex_own); + swig_ownership_map::iterator iter = swig_owner.find(vptr); + if (iter != swig_owner.end()) { + own = iter->second->get_own(); + swig_owner.erase(iter); + } + } + return own; + } + + //template + //static PyObject* swig_pyobj_disown(PyObject *pyobj, PyObject *SWIGUNUSEDPARM(args)) + //{ + // SwigPyObject *sobj = (SwigPyObject *)pyobj; + // sobj->own = 0; + // Director *d = SWIG_DIRECTOR_CAST(reinterpret_cast(sobj->ptr)); + // if (d) + // d->swig_disown(); + // return PyWeakref_NewProxy(pyobj, NULL); + //} + + }; + +#ifdef __THREAD__ + PyThread_type_lock Director::swig_mutex_own = PyThread_allocate_lock(); +#endif +} + +#endif /* __cplusplus */ + + +#endif From 73e2de7538f5439aab14a7163df7c00310ea3201 Mon Sep 17 00:00:00 2001 From: Robert Stone Date: Tue, 12 Nov 2013 13:03:49 -0800 Subject: [PATCH 0771/1160] adds "callback" and "extend" examples --- Examples/perl5/callback/Makefile | 20 +++++++++ Examples/perl5/callback/example.cxx | 4 ++ Examples/perl5/callback/example.h | 23 ++++++++++ Examples/perl5/callback/example.i | 17 ++++++++ Examples/perl5/callback/index.html | 20 +++++++++ Examples/perl5/callback/runme.pl | 40 ++++++++++++++++++ Examples/perl5/check.list | 3 +- Examples/perl5/extend/Makefile | 20 +++++++++ Examples/perl5/extend/example.cxx | 4 ++ Examples/perl5/extend/example.h | 56 +++++++++++++++++++++++++ Examples/perl5/extend/example.i | 20 +++++++++ Examples/perl5/extend/index.html | 19 +++++++++ Examples/perl5/extend/runme.pl | 65 +++++++++++++++++++++++++++++ Examples/perl5/index.html | 2 + 14 files changed, 312 insertions(+), 1 deletion(-) create mode 100644 Examples/perl5/callback/Makefile create mode 100644 Examples/perl5/callback/example.cxx create mode 100644 Examples/perl5/callback/example.h create mode 100644 Examples/perl5/callback/example.i create mode 100644 Examples/perl5/callback/index.html create mode 100644 Examples/perl5/callback/runme.pl create mode 100644 Examples/perl5/extend/Makefile create mode 100644 Examples/perl5/extend/example.cxx create mode 100644 Examples/perl5/extend/example.h create mode 100644 Examples/perl5/extend/example.i create mode 100644 Examples/perl5/extend/index.html create mode 100644 Examples/perl5/extend/runme.pl diff --git a/Examples/perl5/callback/Makefile b/Examples/perl5/callback/Makefile new file mode 100644 index 000000000..544d13642 --- /dev/null +++ b/Examples/perl5/callback/Makefile @@ -0,0 +1,20 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +LIBS = -lm + +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp + +static: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile perl5_clean diff --git a/Examples/perl5/callback/example.cxx b/Examples/perl5/callback/example.cxx new file mode 100644 index 000000000..450d75608 --- /dev/null +++ b/Examples/perl5/callback/example.cxx @@ -0,0 +1,4 @@ +/* File : example.cxx */ + +#include "example.h" + diff --git a/Examples/perl5/callback/example.h b/Examples/perl5/callback/example.h new file mode 100644 index 000000000..1a0e8c432 --- /dev/null +++ b/Examples/perl5/callback/example.h @@ -0,0 +1,23 @@ +/* File : example.h */ + +#include +#include + +class Callback { +public: + virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; } + virtual void run() { std::cout << "Callback::run()" << std::endl; } +}; + + +class Caller { +private: + Callback *_callback; +public: + Caller(): _callback(0) {} + ~Caller() { delCallback(); } + void delCallback() { delete _callback; _callback = 0; } + void setCallback(Callback *cb) { delCallback(); _callback = cb; } + void call() { if (_callback) _callback->run(); } +}; + diff --git a/Examples/perl5/callback/example.i b/Examples/perl5/callback/example.i new file mode 100644 index 000000000..5f9072e61 --- /dev/null +++ b/Examples/perl5/callback/example.i @@ -0,0 +1,17 @@ +/* File : example.i */ +%module(directors="1") example +%{ +#include "example.h" +%} + +%include "std_string.i" + +/* turn on director wrapping Callback */ +%feature("director") Callback; + +/* Caller::setCallback(Callback *cb) gives ownership of the cb to the + * Caller object. The wrapper code should understand this. */ +%apply SWIGTYPE *DISOWN { Callback *cb }; + +%include "example.h" + diff --git a/Examples/perl5/callback/index.html b/Examples/perl5/callback/index.html new file mode 100644 index 000000000..82f5e972a --- /dev/null +++ b/Examples/perl5/callback/index.html @@ -0,0 +1,20 @@ + + +SWIG:Examples:perl5:callback + + + + + +SWIG/Examples/perl/callback/ +
    + +

    Implementing C++ callbacks in Perl

    + +

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

    + +
    + + diff --git a/Examples/perl5/callback/runme.pl b/Examples/perl5/callback/runme.pl new file mode 100644 index 000000000..9471d74e8 --- /dev/null +++ b/Examples/perl5/callback/runme.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl +use strict; +use warnings; +use example; + +{ + package PerlCallback; + use base 'example::Callback'; + sub run { + print "PerlCallback.run()\n"; + } +} + +print "Adding and calling a normal C++ callback\n"; +print "----------------------------------------\n"; + +my $caller = example::Caller->new(); +my $callback = example::Callback->new(); + +$caller->setCallback($callback); +$caller->call(); +$caller->delCallback(); + +$callback = PerlCallback->new(); + +print "\n"; +print "Adding and calling a Perl callback\n"; +print "------------------------------------\n"; + +$caller->setCallback($callback); +$caller->call(); +$caller->delCallback(); + +# Note that letting go of $callback will not attempt to destroy the +# object, ownership passed to $caller in the ->setCallback() call, and +# $callback was already destroyed in ->delCallback(). +undef $callback; + +print "\n"; +print "perl exit\n"; diff --git a/Examples/perl5/check.list b/Examples/perl5/check.list index e15f02e18..925bd263f 100644 --- a/Examples/perl5/check.list +++ b/Examples/perl5/check.list @@ -4,7 +4,6 @@ constants constants2 funcptr import -java multimap multiple_inheritance pointer @@ -12,3 +11,5 @@ reference simple value variables +callback +extend diff --git a/Examples/perl5/extend/Makefile b/Examples/perl5/extend/Makefile new file mode 100644 index 000000000..544d13642 --- /dev/null +++ b/Examples/perl5/extend/Makefile @@ -0,0 +1,20 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +LIBS = -lm + +check: build + $(MAKE) -f $(TOP)/Makefile perl5_run + +build: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp + +static: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile perl5_clean diff --git a/Examples/perl5/extend/example.cxx b/Examples/perl5/extend/example.cxx new file mode 100644 index 000000000..450d75608 --- /dev/null +++ b/Examples/perl5/extend/example.cxx @@ -0,0 +1,4 @@ +/* File : example.cxx */ + +#include "example.h" + diff --git a/Examples/perl5/extend/example.h b/Examples/perl5/extend/example.h new file mode 100644 index 000000000..b27ab9711 --- /dev/null +++ b/Examples/perl5/extend/example.h @@ -0,0 +1,56 @@ +/* File : example.h */ + +#include +#include +#include +#include +#include + +class Employee { +private: + std::string name; +public: + Employee(const char* n): name(n) {} + virtual std::string getTitle() { return getPosition() + " " + getName(); } + virtual std::string getName() { return name; } + virtual std::string getPosition() const { return "Employee"; } + virtual ~Employee() { printf("~Employee() @ %p\n", this); } +}; + + +class Manager: public Employee { +public: + Manager(const char* n): Employee(n) {} + virtual std::string getPosition() const { return "Manager"; } +}; + + +class EmployeeList { + std::vector list; +public: + EmployeeList() { + list.push_back(new Employee("Bob")); + list.push_back(new Employee("Jane")); + list.push_back(new Manager("Ted")); + } + void addEmployee(Employee *p) { + list.push_back(p); + std::cout << "New employee added. Current employees are:" << std::endl; + std::vector::iterator i; + for (i=list.begin(); i!=list.end(); i++) { + std::cout << " " << (*i)->getTitle() << std::endl; + } + } + const Employee *get_item(int i) { + return list[i]; + } + ~EmployeeList() { + std::vector::iterator i; + std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl; + for (i=list.begin(); i!=list.end(); i++) { + delete *i; + } + std::cout << "~EmployeeList empty." << std::endl; + } +}; + diff --git a/Examples/perl5/extend/example.i b/Examples/perl5/extend/example.i new file mode 100644 index 000000000..f5e142b88 --- /dev/null +++ b/Examples/perl5/extend/example.i @@ -0,0 +1,20 @@ +/* File : example.i */ +%module(directors="1") example +%{ +#include "example.h" +%} + +%include "std_vector.i" +%include "std_string.i" + +/* turn on director wrapping for Manager */ +%feature("director") Employee; +%feature("director") Manager; + +/* EmployeeList::addEmployee(Employee *p) gives ownership of the + * employee to the EmployeeList object. The wrapper code should + * understand this. */ +%apply SWIGTYPE *DISOWN { Employee *p }; + +%include "example.h" + diff --git a/Examples/perl5/extend/index.html b/Examples/perl5/extend/index.html new file mode 100644 index 000000000..e9d886bcf --- /dev/null +++ b/Examples/perl5/extend/index.html @@ -0,0 +1,19 @@ + + +SWIG:Examples:perl5:extend + + + + + +SWIG/Examples/perl5/extend/ +
    + +

    Extending a simple C++ class

    + +

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


    + + diff --git a/Examples/perl5/extend/runme.pl b/Examples/perl5/extend/runme.pl new file mode 100644 index 000000000..43c9ce125 --- /dev/null +++ b/Examples/perl5/extend/runme.pl @@ -0,0 +1,65 @@ +#!/usr/bin/perl +use strict; +use warnings; +use example; +# This file illustrates the cross language polymorphism using directors. + +{ + # CEO class, which overrides Employee::getPosition(). + package CEO; + use base 'example::Manager'; + sub getPosition { + return 'CEO'; + } +} + + +# Create an instance of CEO, a class derived from the Java 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(). +my $e = CEO->new('Alice'); +print "${\ $e->getName } is a ${\ $e->getPosition() }\n"; +print "Just call her \"${\ $e->getTitle() }\"\n"; +print "----------------------\n"; + + +# Create a new EmployeeList instance. This class does not have a C++ +# director wrapper, but can be used freely with other classes that do. + +my $list = example::EmployeeList->new(); + +$list->addEmployee($e); +print "----------------------\n"; + +# Now we access the first four items in list (three are C++ objects that +# EmployeeList's constructor adds, the last is our CEO). The virtual +# methods of all these instances are treated the same. For items 0, 1, and +# 2, all methods resolve in C++. For item 3, our CEO, getTitle calls +# getPosition which resolves in Perl. The call to getPosition is +# slightly different, however, because of the overidden getPosition() call, since +# now the object reference has been "laundered" by passing through +# EmployeeList as an Employee*. Previously, Perl resolved the call +# immediately in CEO, but now Perl thinks the object is an instance of +# class Employee. So the call passes through the +# Employee proxy class and on to the C wrappers and C++ director, +# eventually ending up back at the Perl CEO implementation of getPosition(). +# The call to getTitle() for item 3 runs the C++ Employee::getTitle() +# method, which in turn calls getPosition(). This virtual method call +# passes down through the C++ director class to the Perl implementation +# in CEO. All this routing takes place transparently. + +print "(position, title) for items 0-3:\n"; + +print " ${\ $list->get_item(0)->getPosition() }, \"${\ $list->get_item(0)->getTitle() }\"\n"; +print " ${\ $list->get_item(1)->getPosition() }, \"${\ $list->get_item(1)->getTitle() }\"\n"; +print " ${\ $list->get_item(2)->getPosition() }, \"${\ $list->get_item(2)->getTitle() }\"\n"; +print " ${\ $list->get_item(3)->getPosition() }, \"${\ $list->get_item(3)->getTitle() }\"\n"; +print "----------------------\n"; + +# Time to delete the EmployeeList, which will delete all the Employee* +# items it contains. The last item is our CEO, which gets destroyed as well. +undef $list; +print "----------------------\n"; + +# All done. +print "perl exit\n"; diff --git a/Examples/perl5/index.html b/Examples/perl5/index.html index db46023c4..23c8ff658 100644 --- a/Examples/perl5/index.html +++ b/Examples/perl5/index.html @@ -20,6 +20,8 @@ certain C declarations are turned into constants.
  • reference. C++ references.
  • pointer. Simple pointer handling.
  • funcptr. Pointers to functions. +
  • callback. C++ callbacks using directors. +
  • extend. Extending a simple C++ class.

    Compilation Issues

    From 35dc86f064382f4f85b79c4138cc1222beab9011 Mon Sep 17 00:00:00 2001 From: Robert Stone Date: Tue, 12 Nov 2013 14:13:30 -0800 Subject: [PATCH 0772/1160] steals python director docs and adapts to perl5 --- Doc/Manual/Perl5.html | 342 +++++++++++++++++++++++++++++++++++++++++ Lib/perl5/director.swg | 2 +- 2 files changed, 343 insertions(+), 1 deletion(-) diff --git a/Doc/Manual/Perl5.html b/Doc/Manual/Perl5.html index 49e8965fa..00284783f 100644 --- a/Doc/Manual/Perl5.html +++ b/Doc/Manual/Perl5.html @@ -68,6 +68,15 @@
  • Modifying the proxy methods
  • Adding additional Perl code +
  • Cross language polymorphism +
  • @@ -2993,6 +3002,339 @@ set_transform($im, $a); +

    31.11 Cross language polymorphism

    + + +

    +Proxy classes provide a more natural, object-oriented way to access +extension classes. As described above, each proxy instance has an +associated C++ instance, and method calls to the proxy are passed to the +C++ instance transparently via C wrapper functions. +

    + +

    +This arrangement is asymmetric in the sense that no corresponding +mechanism exists to pass method calls down the inheritance chain from +C++ to Perl. In particular, if a C++ class has been extended in Perl +(by extending the proxy class), these extensions will not be visible +from C++ code. Virtual method calls from C++ are thus not able access +the lowest implementation in the inheritance chain. +

    + +

    +Changes have been made to SWIG to address this problem and +make the relationship between C++ classes and proxy classes more +symmetric. To achieve this goal, new classes called directors are +introduced at the bottom of the C++ inheritance chain. The job of the +directors is to route method calls correctly, either to C++ +implementations higher in the inheritance chain or to Perl +implementations lower in the inheritance chain. The upshot is that C++ +classes can be extended in Perl and from C++ these extensions look +exactly like native C++ classes. Neither C++ code nor Perl code needs +to know where a particular method is implemented: the combination of +proxy classes, director classes, and C wrapper functions takes care of +all the cross-language method routing transparently. +

    + +

    31.11.1 Enabling directors

    + + +

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

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

    +Without this option no director code will be generated. Second, you +must use the %feature("director") directive to tell SWIG which classes +and methods should get directors. The %feature directive can be applied +globally, to specific classes, and to specific methods, like this: +

    + +
    +
    +// generate directors for all classes that have virtual methods
    +%feature("director");         
    +
    +// generate directors for all virtual methods in class Foo
    +%feature("director") Foo;      
    +
    +
    + +

    +You can use the %feature("nodirector") directive to turn off +directors for specific classes or methods. So for example, +

    + +
    +
    +%feature("director") Foo;
    +%feature("nodirector") Foo::bar;
    +
    +
    + +

    +will generate directors for all virtual methods of class Foo except +bar(). +

    + +

    +Directors can also be generated implicitly through inheritance. +In the following, class Bar will get a director class that handles +the methods one() and two() (but not three()): +

    + +
    +
    +%feature("director") Foo;
    +class Foo {
    +public:
    +    Foo(int foo);
    +    virtual void one();
    +    virtual void two();
    +};
    +
    +class Bar: public Foo {
    +public:
    +    virtual void three();
    +};
    +
    +
    + +

    +then at the Perl side you can define +

    + +
    +
    +use mymodule;
    +
    +package MyFoo;
    +use base 'mymodule::Foo';
    +
    +sub one {
    +  print "one from Perl\n";
    +}
    +
    +
    + + +

    31.11.2 Director classes

    + + + + + +

    +For each class that has directors enabled, SWIG generates a new class +that derives from both the class in question and a special +Swig::Director class. These new classes, referred to as director +classes, can be loosely thought of as the C++ equivalent of the Perl +proxy classes. The director classes store a pointer to their underlying +Perl object and handle various issues related to object ownership. +

    + +

    +For simplicity let's ignore the Swig::Director class and refer to the +original C++ class as the director's base class. By default, a director +class extends all virtual methods in the inheritance chain of its base +class (see the preceding section for how to modify this behavior). +Thus all virtual method calls, whether they originate in C++ or in +Perl via proxy classes, eventually end up in at the implementation in +the director class. The job of the director methods is to route these +method calls to the appropriate place in the inheritance chain. By +"appropriate place" we mean the method that would have been called if +the C++ base class and its extensions in Perl were seamlessly +integrated. That seamless integration is exactly what the director +classes provide, transparently skipping over all the messy extension API +glue that binds the two languages together. +

    + +

    +In reality, the "appropriate place" is one of only two possibilities: +C++ or Perl. Once this decision is made, the rest is fairly easy. If +the correct implementation is in C++, then the lowest implementation of +the method in the C++ inheritance chain is called explicitly. If the +correct implementation is in Perl, the Perl API is used to call the +method of the underlying Perl object (after which the usual virtual +method resolution in Perl automatically finds the right +implementation). +

    + +

    +Now how does the director decide which language should handle the method call? +The basic rule is to handle the method in Perl, unless there's a good +reason not to. The reason for this is simple: Perl has the most +"extended" implementation of the method. This assertion is guaranteed, +since at a minimum the Perl proxy class implements the method. If the +method in question has been extended by a class derived from the proxy +class, that extended implementation will execute exactly as it should. +If not, the proxy class will route the method call into a C wrapper +function, expecting that the method will be resolved in C++. The wrapper +will call the virtual method of the C++ instance, and since the director +extends this the call will end up right back in the director method. Now +comes the "good reason not to" part. If the director method were to blindly +call the Perl method again, it would get stuck in an infinite loop. We avoid this +situation by adding special code to the C wrapper function that tells +the director method to not do this. The C wrapper function compares the +pointer to the Perl object that called the wrapper function to the +pointer stored by the director. If these are the same, then the C +wrapper function tells the director to resolve the method by calling up +the C++ inheritance chain, preventing an infinite loop. +

    + +

    +One more point needs to be made about the relationship between director +classes and proxy classes. When a proxy class instance is created in +Perl, SWIG creates an instance of the original C++ class. +This is exactly what happens without directors and +is true even if directors are enabled for the particular class in +question. When a class derived from a proxy class is created, +however, SWIG then creates an instance of the corresponding C++ director +class. The reason for this difference is that user-defined subclasses +may override or extend methods of the original class, so the director +class is needed to route calls to these methods correctly. For +unmodified proxy classes, all methods are ultimately implemented in C++ +so there is no need for the extra overhead involved with routing the +calls through Perl. +

    + +

    31.11.3 Ownership and object destruction

    + + +

    +Memory management issues are slightly more complicated with directors +than for proxy classes alone. Perl instances hold a pointer to the +associated C++ director object, and the director in turn holds a pointer +back to a Perl object. By default, proxy classes own their C++ +director object and take care of deleting it when they are garbage +collected. +

    + +

    +This relationship can be reversed by calling the special +DISOWN() method of the proxy class. After calling this +method the director +class increments the reference count of the Perl object. When the +director class is deleted it decrements the reference count. Assuming no +outstanding references to the Perl object remain, the Perl object +will be destroyed at the same time. This is a good thing, since +directors and proxies refer to each other and so must be created and +destroyed together. Destroying one without destroying the other will +likely cause your program to segfault. +

    + +

    31.11.4 Exception unrolling

    + + +

    +With directors routing method calls to Perl, and proxies routing them +to C++, the handling of exceptions is an important concern. By default, the +directors ignore exceptions that occur during method calls that are +resolved in Perl. To handle such exceptions correctly, it is necessary +to temporarily translate them into C++ exceptions. This can be done with +the %feature("director:except") directive. The following code should +suffice in most cases: +

    + +
    +
    +%feature("director:except") {
    +    if ($error != NULL) {
    +        throw Swig::DirectorMethodException();
    +    }
    +}
    +
    +
    + +

    +This code will check the Perl error state after each method call from +a director into Perl, and throw a C++ exception if an error occurred. +This exception can be caught in C++ to implement an error handler. +

    + +

    +It may be the case that a method call originates in Perl, travels up +to C++ through a proxy class, and then back into Perl via a director +method. If an exception occurs in Perl at this point, it would be nice +for that exception to find its way back to the original caller. This can +be done by combining a normal %exception directive with the +director:except handler shown above. Here is an example of a +suitable exception handler: +

    + +
    +
    +%exception {
    +    try { $action }
    +    catch (Swig::DirectorException &e) { SWIG_fail; }
    +}
    +
    +
    + +

    +The class Swig::DirectorException used in this example is actually a +base class of Swig::DirectorMethodException, so it will trap this +exception. Because the Perl error state is still set when +Swig::DirectorMethodException is thrown, Perl will register the +exception as soon as the C wrapper function returns. +

    + +

    31.11.5 Overhead and code bloat

    + + +

    +Enabling directors for a class will generate a new director method for +every virtual method in the class' inheritance chain. This alone can +generate a lot of code bloat for large hierarchies. Method arguments +that require complex conversions to and from target language types can +result in large director methods. For this reason it is recommended that +you selectively enable directors only for specific classes that are +likely to be extended in Perl and used in C++. +

    + +

    +Compared to classes that do not use directors, the call routing in the +director methods does add some overhead. In particular, at least one +dynamic cast and one extra function call occurs per method call from +Perl. Relative to the speed of Perl execution this is probably +completely negligible. For worst case routing, a method call that +ultimately resolves in C++ may take one extra detour through Perl in +order to ensure that the method does not have an extended Perl +implementation. This could result in a noticeable overhead in some cases. +

    + +

    +Although directors make it natural to mix native C++ objects with Perl +objects (as director objects) via a common base class pointer, one +should be aware of the obvious fact that method calls to Perl objects +will be much slower than calls to C++ objects. This situation can be +optimized by selectively enabling director methods (using the %feature +directive) for only those methods that are likely to be extended in +Perl. +

    + +

    31.11.6 Typemaps

    + + +

    +Typemaps for input and output of most of the basic types from director +classes have been written. These are roughly the reverse of the usual +input and output typemaps used by the wrapper code. The typemap +operation names are 'directorin', 'directorout', and 'directorargout'. +The director code does not currently use any of the other kinds of typemaps. +It is not clear at this point which kinds are appropriate and +need to be supported. +

    + + diff --git a/Lib/perl5/director.swg b/Lib/perl5/director.swg index 937b727a4..6b03fc26c 100644 --- a/Lib/perl5/director.swg +++ b/Lib/perl5/director.swg @@ -202,7 +202,7 @@ namespace Swig { protected: SV *err; public: - DirectorMethodException(SV *sv) + DirectorMethodException(SV *sv = sv_mortalcopy(ERRSV)) : err(sv) { SvREFCNT_inc(err); From 3e91ae7db7829f1a45ffd443514f5f19a14e7cf8 Mon Sep 17 00:00:00 2001 From: Robert Stone Date: Tue, 12 Nov 2013 18:43:56 -0800 Subject: [PATCH 0773/1160] mitigate ConvertPtr director cost when directors are not enabled --- Lib/perl5/perlrun.swg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/perl5/perlrun.swg b/Lib/perl5/perlrun.swg index 4e31c4754..876fae268 100644 --- a/Lib/perl5/perlrun.swg +++ b/Lib/perl5/perlrun.swg @@ -289,7 +289,11 @@ SWIG_Perl_ConvertPtrAndOwn(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_ /* Now see if the types match */ char *_c = HvNAME(SvSTASH(SvRV(sv))); tc = SWIG_TypeProxyCheck(_c,_t); +#ifdef SWIG_DIRECTORS if (!tc && !sv_derived_from(sv,SWIG_Perl_TypeProxyName(_t))) { +#else + if (!tc) { +#endif return SWIG_ERROR; } { From 7d80d9b59eef51e78d794bf68e53c899c3213b65 Mon Sep 17 00:00:00 2001 From: Robert Stone Date: Wed, 13 Nov 2013 12:38:04 -0800 Subject: [PATCH 0774/1160] eliminate dead director code and convert remaining blocks --- Lib/perl5/director.swg | 127 --------------------------------------- Source/Modules/perl5.cxx | 100 +++++++----------------------- 2 files changed, 23 insertions(+), 204 deletions(-) diff --git a/Lib/perl5/director.swg b/Lib/perl5/director.swg index 6b03fc26c..5acc4fd15 100644 --- a/Lib/perl5/director.swg +++ b/Lib/perl5/director.swg @@ -17,41 +17,6 @@ #include -/* - Use -DSWIG_PYTHON_DIRECTOR_NO_VTABLE if you don't want to generate a 'virtual - table', and avoid multiple GetAttr calls to retrieve the python - methods. -*/ - -#ifndef SWIG_PERL_DIRECTOR_NO_VTABLE -#ifndef SWIG_PERL_DIRECTOR_VTABLE -#define SWIG_PERL_DIRECTOR_VTABLE -#endif -#endif - - - -/* - Use -DSWIG_DIRECTOR_NO_UEH if you prefer to avoid the use of the - Undefined Exception Handler provided by swig. -*/ -#ifndef SWIG_DIRECTOR_NO_UEH -#ifndef SWIG_DIRECTOR_UEH -#define SWIG_DIRECTOR_UEH -#endif -#endif - - -/* - Use -DSWIG_DIRECTOR_STATIC if you prefer to avoid the use of the - 'Swig' namespace. This could be useful for multi-modules projects. -*/ -#ifdef SWIG_DIRECTOR_STATIC -/* Force anonymous (static) namespace */ -#define Swig -#endif - - /* Use -DSWIG_DIRECTOR_NORTTI if you prefer to avoid the use of the native C++ RTTI and dynamic_cast<>. But be aware that directors @@ -267,77 +232,6 @@ namespace Swig { throw DirectorPureVirtualException(name); } }; -// /* unknown exception handler */ -// class UnknownExceptionHandler -// { -//#ifdef SWIG_DIRECTOR_UEH -// static void handler() { -// try { -// throw; -// } catch (DirectorException& e) { -// std::cerr << "SWIG Director exception caught:" << std::endl -// << e.getMessage() << std::endl; -// } catch (std::exception& e) { -// std::cerr << "std::exception caught: "<< e.what() << std::endl; -// } catch (...) { -// std::cerr << "Unknown exception caught." << std::endl; -// } -// -// //std::cerr << std::endl -// // << "Python interpreter traceback:" << std::endl; -// //PyErr_Print(); -// //std::cerr << std::endl; -// -// std::cerr << "This exception was caught by the SWIG unexpected exception handler." << std::endl -// << "Try using %feature(\"director:except\") to avoid reaching this point." << std::endl -// << std::endl -// << "Exception is being re-thrown, program will likely abort/terminate." << std::endl; -// throw; -// } -// -// public: -// -// std::unexpected_handler old; -// UnknownExceptionHandler(std::unexpected_handler nh = handler) -// { -// old = std::set_unexpected(nh); -// } -// -// ~UnknownExceptionHandler() -// { -// std::set_unexpected(old); -// } -//#endif -// }; - -#if defined(SWIG_PYTHON_THREADS) -/* __THREAD__ is the old macro to activate some thread support */ -# if !defined(__THREAD__) -# define __THREAD__ 1 -# endif -#endif - -#ifdef __THREAD__ -# include "pythread.h" - class Guard - { - PyThread_type_lock & mutex_; - - public: - Guard(PyThread_type_lock & mutex) : mutex_(mutex) - { - PyThread_acquire_lock(mutex_, WAIT_LOCK); - } - - ~Guard() - { - PyThread_release_lock(mutex_); - } - }; -# define SWIG_GUARD(mutex) Guard _guard(mutex) -#else -# define SWIG_GUARD(mutex) -#endif /* director base class */ class Director { @@ -410,16 +304,12 @@ namespace Swig { private: typedef std::map swig_ownership_map; mutable swig_ownership_map swig_owner; -#ifdef __THREAD__ - static PyThread_type_lock swig_mutex_own; -#endif public: template void swig_acquire_ownership_array(Type *vptr) const { if (vptr) { - SWIG_GUARD(swig_mutex_own); swig_owner[vptr] = new GCArray_T(vptr); } } @@ -428,7 +318,6 @@ namespace Swig { void swig_acquire_ownership(Type *vptr) const { if (vptr) { - SWIG_GUARD(swig_mutex_own); swig_owner[vptr] = new GCItem_T(vptr); } } @@ -436,7 +325,6 @@ namespace Swig { void swig_acquire_ownership_obj(void *vptr, int own) const { if (vptr && own) { - SWIG_GUARD(swig_mutex_own); swig_owner[vptr] = new GCItem_Object(own); } } @@ -445,7 +333,6 @@ namespace Swig { { int own = 0; if (vptr) { - SWIG_GUARD(swig_mutex_own); swig_ownership_map::iterator iter = swig_owner.find(vptr); if (iter != swig_owner.end()) { own = iter->second->get_own(); @@ -455,22 +342,8 @@ namespace Swig { return own; } - //template - //static PyObject* swig_pyobj_disown(PyObject *pyobj, PyObject *SWIGUNUSEDPARM(args)) - //{ - // SwigPyObject *sobj = (SwigPyObject *)pyobj; - // sobj->own = 0; - // Director *d = SWIG_DIRECTOR_CAST(reinterpret_cast(sobj->ptr)); - // if (d) - // d->swig_disown(); - // return PyWeakref_NewProxy(pyobj, NULL); - //} - }; -#ifdef __THREAD__ - PyThread_type_lock Director::swig_mutex_own = PyThread_allocate_lock(); -#endif } #endif /* __cplusplus */ diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 182835645..06b4c4ae9 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -1707,12 +1707,8 @@ public: String *saved_nc = none_comparison; none_comparison = NewStringf("strcmp(SvPV_nolen(ST(0)), \"%s::%s\") != 0", module, class_name); String *saved_director_prot_ctor_code = director_prot_ctor_code; - director_prot_ctor_code = NewStringf( - "if ($comparison) { /* subclassed */\n" - " $director_new\n" - "} else {\n" - " SWIG_exception_fail(SWIG_RuntimeError, \"accessing abstract class or protected constructor\");\n" - "}\n"); + director_prot_ctor_code = NewStringf( "if ($comparison) { /* subclassed */\n" " $director_new\n" "} else {\n" " + SWIG_exception_fail(SWIG_RuntimeError, \"accessing abstract class or protected constructor\");\n" "}\n"); Language::constructorHandler(n); Delete(none_comparison); none_comparison = saved_nc; @@ -2084,7 +2080,6 @@ public: int status = SWIG_OK; int idx; bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; - int addfail = 0; if (Cmp(storage, "virtual") == 0) { if (Cmp(value, "0") == 0) { @@ -2157,11 +2152,6 @@ public: } } - //if (builtin) { - // Printv(w->code, "PyObject *self = NULL;\n", NIL); - // Printv(w->code, "(void)self;\n", NIL); - //} - if (ignored_method) { if (!pure_virtual) { if (!is_void) @@ -2175,7 +2165,6 @@ public: } } else { /* attach typemaps to arguments (C/C++ -> Perl) */ - String *arglist = NewString(""); String *parse_args = NewString(""); String *pstack = NewString(""); @@ -2211,7 +2200,6 @@ public: /* build argument list and type conversion string */ idx = 0; p = l; - int use_parse = 0; while (p) { if (checkAttribute(p, "tmap:in:numinputs", "0")) { p = Getattr(p, "tmap:in:next"); @@ -2232,35 +2220,20 @@ public: String *pname = Getattr(p, "name"); String *ptype = Getattr(p, "type"); - Putc(',', arglist); if ((tm = Getattr(p, "tmap:directorin")) != 0) { - String *parse = Getattr(p, "tmap:directorin:parse"); - if (!parse) { - sprintf(source, "obj%d", idx++); - String *input = NewString(source); - Setattr(p, "emit:directorinput", input); - Replaceall(tm, "$input", input); - Delete(input); - Replaceall(tm, "$owner", "0"); - Replaceall(tm, "$shadow", "0"); - /* Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL); */ - Printv(wrap_args, "SV *", source, ";\n", NIL); + sprintf(source, "obj%d", idx++); + String *input = NewString(source); + Setattr(p, "emit:directorinput", input); + Replaceall(tm, "$input", input); + Delete(input); + Replaceall(tm, "$owner", "0"); + Replaceall(tm, "$shadow", "0"); + /* Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL); */ + Printv(wrap_args, "SV *", source, ";\n", NIL); - Printv(wrap_args, tm, "\n", NIL); - Printv(arglist, "(PyObject *)", source, NIL); - Putc('O', parse_args); - Printv(pstack, "XPUSHs(", source, ");\n", NIL); - } else { - use_parse = 1; - Append(parse_args, parse); - Setattr(p, "emit:directorinput", pname); - Replaceall(tm, "$input", pname); - Replaceall(tm, "$owner", "0"); - Replaceall(tm, "$shadow", "0"); - if (Len(tm) == 0) - Append(tm, pname); - Append(arglist, tm); - } + Printv(wrap_args, tm, "\n", NIL); + Putc('O', parse_args); + Printv(pstack, "XPUSHs(", source, ");\n", NIL); p = Getattr(p, "tmap:directorin:next"); continue; } else if (Cmp(ptype, "void")) { @@ -2303,23 +2276,19 @@ public: if (target) { String *director = NewStringf("director_%s", mangle); Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL); - Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); + Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL); Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst); Printf(wrap_args, "if (!%s) {\n", director); - Printf(wrap_args, "%s = SWIG_InternalNewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); + Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); Append(wrap_args, "} else {\n"); Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director); - Printf(wrap_args, "Py_INCREF((PyObject *)%s);\n", source); + Printf(wrap_args, "SvREFCNT_inc((SV *)%s);\n", source); Append(wrap_args, "}\n"); Delete(director); - Printv(arglist, source, NIL); } else { Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL); Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); Printf(pstack, "XPUSHs(sv_2mortal(%s));\n", source); - //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n", - // source, nonconst, base); - Printv(arglist, source, NIL); } Putc('O', parse_args); Delete(mangle); @@ -2338,13 +2307,6 @@ public: /* add the method name as a PyString */ String *pyname = Getattr(n, "sym:name"); - //int allow_thread = threads_enable(n); - // - //if (allow_thread) { - // thread_begin_block(n, w->code); - // Append(w->code, "{\n"); - //} - /* wrap complex arguments to PyObjects */ Printv(w->code, wrap_args, NIL); @@ -2374,7 +2336,7 @@ public: Append(w->code, "if (SvTRUE(ERRSV)) {\n"); Append(w->code, " PUTBACK;\n FREETMPS;\n LEAVE;\n"); if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { - Replaceall(tm, "$error", "error"); + Replaceall(tm, "$error", "ERRSV"); Printv(w->code, Str(tm), "\n", NIL); } else { Printf(w->code, " Swig::DirectorMethodException::raise(ERRSV);\n", classname, pyname); @@ -2395,9 +2357,9 @@ public: String *outarg = NewString(""); if (outputs > 1) { - Wrapper_add_local(w, "output", "PyObject *output"); - Printf(w->code, "if (!PyTuple_Check(%s)) {\n", Swig_cresult_name()); - Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", classname, pyname); + Wrapper_add_local(w, "output", "SV *output"); + Printf(w->code, "if (count != %d) {\n", outputs); + Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Perl method %s.%sfailed to return a list.\");\n", classname, pyname); Append(w->code, "}\n"); } @@ -2410,7 +2372,7 @@ public: tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); if (tm != 0) { if (outputs > 1) { - Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++); + Printf(w->code, "output = POPs;\n"); Replaceall(tm, "$input", "output"); } else { Replaceall(tm, "$input", Swig_cresult_name()); @@ -2425,14 +2387,10 @@ public: } else { Replaceall(tm, "$disown", "0"); } - //if (Getattr(n, "tmap:directorout:implicitconv")) { - // Replaceall(tm, "$implicitconv", get_implicitconv_flag(n)); - //} Replaceall(tm, "$result", "c_result"); Printv(w->code, tm, "\n", NIL); Delete(tm); } else { - Swig_print_node(n); Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); @@ -2444,7 +2402,7 @@ public: for (p = l; p;) { if ((tm = Getattr(p, "tmap:directorargout")) != 0) { if (outputs > 1) { - Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++); + Printf(w->code, "output = POPs;\n"); Replaceall(tm, "$result", "output"); } else { Replaceall(tm, "$result", Swig_cresult_name()); @@ -2457,14 +2415,7 @@ public: } } - /* any existing helper functions to handle this? */ - //if (allow_thread) { - // Append(w->code, "}\n"); - // thread_end_block(n, w->code); - //} - Delete(parse_args); - Delete(arglist); Delete(cleanup); Delete(outarg); } @@ -2487,11 +2438,6 @@ public: } } - if (addfail) { - Append(w->code, "fail:\n"); - Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s->%s'\");\n", classname, Getattr(n, "sym:name")); - } - Append(w->code, "}\n"); // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method From 055cbc85de4625e6b53e840cd753e0d01bae5d9e Mon Sep 17 00:00:00 2001 From: Robert Stone Date: Wed, 13 Nov 2013 15:04:18 -0800 Subject: [PATCH 0775/1160] fix string mangled by tidy --- Source/Modules/perl5.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 06b4c4ae9..f59994cd7 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -1707,8 +1707,8 @@ public: String *saved_nc = none_comparison; none_comparison = NewStringf("strcmp(SvPV_nolen(ST(0)), \"%s::%s\") != 0", module, class_name); String *saved_director_prot_ctor_code = director_prot_ctor_code; - director_prot_ctor_code = NewStringf( "if ($comparison) { /* subclassed */\n" " $director_new\n" "} else {\n" " - SWIG_exception_fail(SWIG_RuntimeError, \"accessing abstract class or protected constructor\");\n" "}\n"); + director_prot_ctor_code = NewStringf( "if ($comparison) { /* subclassed */\n" " $director_new\n" "} else {\n" + "SWIG_exception_fail(SWIG_RuntimeError, \"accessing abstract class or protected constructor\");\n" "}\n"); Language::constructorHandler(n); Delete(none_comparison); none_comparison = saved_nc; From e0789366e7dccf28c31c04e9d82d35abead5f78c Mon Sep 17 00:00:00 2001 From: Robert Stone Date: Thu, 14 Nov 2013 07:29:28 -0800 Subject: [PATCH 0776/1160] prefer polymorphism on existing destructor over custom destructor method --- Doc/Manual/Perl5.html | 24 +++++++++++++++++++ .../perl5/director_finalizer_runme.pl | 5 ++-- Source/Modules/perl5.cxx | 15 ++++++------ 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/Doc/Manual/Perl5.html b/Doc/Manual/Perl5.html index 00284783f..db8c0e602 100644 --- a/Doc/Manual/Perl5.html +++ b/Doc/Manual/Perl5.html @@ -3231,6 +3231,30 @@ destroyed together. Destroying one without destroying the other will likely cause your program to segfault.

    +

    +Also note that due to the proxy implementation, the DESTROY() +method on directors can be called for several reasons, many of which +have little to do with the teardown of an object instance. To help +disambiguate this, a second argument is added to the DESTROY() +call when a C++ director object is being released. So, to avoid running +your clean-up code when an object is not really going away, or after it +has already been reclaimed, it is suggested that custom destructors in +Perl subclasses looks something like: +

    + +
    +
    +sub DESTROY {
    +  my($self, $final) = @_;
    +  if($final) {
    +    # real teardown code
    +  }
    +  shift->SUPER::DESTROY(@_);
    +}
    +
    +
    + +

    31.11.4 Exception unrolling

    diff --git a/Examples/test-suite/perl5/director_finalizer_runme.pl b/Examples/test-suite/perl5/director_finalizer_runme.pl index bb6e1fa71..bcb4002ec 100644 --- a/Examples/test-suite/perl5/director_finalizer_runme.pl +++ b/Examples/test-suite/perl5/director_finalizer_runme.pl @@ -7,8 +7,9 @@ require_ok('director_finalizer'); { package MyFoo; use base 'director_finalizer::Foo'; - sub DIRECTOR_DESTROY { my($self) = @_; - $self->orStatus(2); + sub DESTROY { my($self, $final) = @_; + $self->orStatus(2) if $final; + shift->SUPER::DESTROY(@_); } } diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index f59994cd7..530ed07ed 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -1529,11 +1529,11 @@ public: Delete(get_attr); Printv(pm, "sub FETCH {\n", tab4, "my ($self,$field) = @_;\n", tab4, "my $member_func = \"swig_${field}_get\";\n", tab4, - "if (not $self->can(\"$member_func\")) {\n", tab4, tab4, "my $h = ", cmodule, "::", mrename, "($self);\n", tab4, tab4, - "return $h->{$field} if $h;\n", tab4, "}\n", tab4, "return $self->$member_func;\n", "}\n", "\n", "sub STORE {\n", tab4, - "my ($self,$field,$newval) = @_;\n", tab4, "my $member_func = \"swig_${field}_set\";\n", tab4, - "if (not $self->can(\"$member_func\")) {\n", tab4, tab4, "my $h = ", cmodule, "::", mrename, "($self);\n", tab4, tab4, - "return $h->{$field} = $newval if $h;\n", tab4, "}\n", tab4, "return $self->$member_func($newval);\n", "}\n", NIL); + "if (not $self->can($member_func)) {\n", tab8, "my $h = ", cmodule, "::", mrename, "($self);\n", tab8, "return $h->{$field} if $h;\n", + tab4, "}\n", tab4, "return $self->$member_func;\n", "}\n", "\n", "sub STORE {\n", tab4, "my ($self,$field,$newval) = @_;\n", tab4, + "my $member_func = \"swig_${field}_set\";\n", tab4, "if (not $self->can($member_func)) {\n", tab8, "my $h = ", cmodule, "::", mrename, + "($self);\n", tab8, "return $h->{$field} = $newval if $h;\n", tab4, "}\n", tab4, "return $self->$member_func($newval);\n", "}\n", NIL); + Delete(mrename); } } @@ -2493,8 +2493,9 @@ public: String *mangle = SwigType_manglestr(ptype); Printv(body, tab4, "dSP;\n", tab4, "SV *self = SWIG_NewPointerObj(SWIG_as_voidptr(this), SWIGTYPE", mangle, ", SWIG_SHADOW);\n", tab4, "\n", tab4, - "sv_bless(self, gv_stashpv(swig_get_class(), 0));\n", tab4, "ENTER;\n", tab4, "SAVETMPS;\n", tab4, "PUSHMARK(SP);\n", tab4, "XPUSHs(self);\n", - tab4, "PUTBACK;\n", tab4, "call_method(\"DIRECTOR_DESTROY\", G_EVAL | G_VOID);\n", tab4, "FREETMPS;\n", tab4, "LEAVE;\n", NIL); + "sv_bless(self, gv_stashpv(swig_get_class(), 0));\n", tab4, "ENTER;\n", tab4, "SAVETMPS;\n", tab4, "PUSHMARK(SP);\n", tab4, + "XPUSHs(self);\n", tab4, "XPUSHs(&PL_sv_yes);\n", tab4, "PUTBACK;\n", tab4, "call_method(\"DESTROY\", G_EVAL | G_VOID);\n", tab4, + "FREETMPS;\n", tab4, "LEAVE;\n", NIL); Delete(mangle); Delete(ptype); From 43aefba9eed6fc06334ccef5e5652664aa8ea570 Mon Sep 17 00:00:00 2001 From: Robert Stone Date: Thu, 14 Nov 2013 09:22:23 -0800 Subject: [PATCH 0777/1160] ran "beautify-file" make target over perl5.cxx patch hunks and rewrote callback and extend examples in the style of existing examples --- Examples/perl5/callback/runme.pl | 40 +-- Examples/perl5/extend/runme.pl | 58 ++-- Source/Modules/perl5.cxx | 439 +++++++++++++++---------------- 3 files changed, 277 insertions(+), 260 deletions(-) diff --git a/Examples/perl5/callback/runme.pl b/Examples/perl5/callback/runme.pl index 9471d74e8..a6b80d988 100644 --- a/Examples/perl5/callback/runme.pl +++ b/Examples/perl5/callback/runme.pl @@ -1,40 +1,48 @@ -#!/usr/bin/perl -use strict; -use warnings; +# file: runme.pl + +# This file illustrates the cross language polymorphism using directors. + use example; + { - package PerlCallback; + package PlCallback; use base 'example::Callback'; sub run { - print "PerlCallback.run()\n"; + print "PlCallback->run()\n"; } } +# Create an Caller instance + +$caller = example::Caller->new(); + +# Add a simple C++ callback (caller owns the callback, so +# we disown it first by clearing the .thisown flag). + print "Adding and calling a normal C++ callback\n"; print "----------------------------------------\n"; -my $caller = example::Caller->new(); -my $callback = example::Callback->new(); - +$callback = example::Callback->new(); +$callback->DISOWN(); $caller->setCallback($callback); $caller->call(); $caller->delCallback(); -$callback = PerlCallback->new(); - -print "\n"; +print print "Adding and calling a Perl callback\n"; -print "------------------------------------\n"; +print "----------------------------------\n"; +# Add a Perl callback (caller owns the callback, so we +# disown it first by calling DISOWN). + +$callback = PlCallback->new(); +$callback->DISOWN(); $caller->setCallback($callback); $caller->call(); $caller->delCallback(); -# Note that letting go of $callback will not attempt to destroy the -# object, ownership passed to $caller in the ->setCallback() call, and -# $callback was already destroyed in ->delCallback(). -undef $callback; +# All done. print "\n"; print "perl exit\n"; diff --git a/Examples/perl5/extend/runme.pl b/Examples/perl5/extend/runme.pl index 43c9ce125..76ee849a4 100644 --- a/Examples/perl5/extend/runme.pl +++ b/Examples/perl5/extend/runme.pl @@ -1,48 +1,56 @@ -#!/usr/bin/perl -use strict; -use warnings; -use example; +# file: runme.pl + # This file illustrates the cross language polymorphism using directors. +use example; + + +# CEO class, which overrides Employee::getPosition(). + { - # CEO class, which overrides Employee::getPosition(). package CEO; use base 'example::Manager'; sub getPosition { - return 'CEO'; + return "CEO"; } } -# Create an instance of CEO, a class derived from the Java 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(). -my $e = CEO->new('Alice'); -print "${\ $e->getName } is a ${\ $e->getPosition() }\n"; -print "Just call her \"${\ $e->getTitle() }\"\n"; +# Create an instance of our employee extension class, CEO. The calls to +# getName() and getPosition() are standard, the call to getTitle() uses +# the director wrappers to call CEO->getPosition. $e = CEO->new("Alice") + +$e = CEO->new("Alice"); +print $e->getName(), " is a ", $e->getPosition(), "\n"; +printf "Just call her \"%s\"\n", $e->getTitle(); print "----------------------\n"; # Create a new EmployeeList instance. This class does not have a C++ # director wrapper, but can be used freely with other classes that do. -my $list = example::EmployeeList->new(); +$list = example::EmployeeList->new(); +# EmployeeList owns its items, so we must surrender ownership of objects +# we add. This involves calling the DISOWN method to tell the +# C++ director to start reference counting. + +$e->DISOWN(); $list->addEmployee($e); print "----------------------\n"; # Now we access the first four items in list (three are C++ objects that # EmployeeList's constructor adds, the last is our CEO). The virtual # methods of all these instances are treated the same. For items 0, 1, and -# 2, all methods resolve in C++. For item 3, our CEO, getTitle calls +# 2, both all methods resolve in C++. For item 3, our CEO, getTitle calls # getPosition which resolves in Perl. The call to getPosition is -# slightly different, however, because of the overidden getPosition() call, since +# slightly different, however, from the $e->getPosition() call above, since # now the object reference has been "laundered" by passing through # EmployeeList as an Employee*. Previously, Perl resolved the call # immediately in CEO, but now Perl thinks the object is an instance of -# class Employee. So the call passes through the +# class Employee (actually EmployeePtr). So the call passes through the # Employee proxy class and on to the C wrappers and C++ director, -# eventually ending up back at the Perl CEO implementation of getPosition(). +# eventually ending up back at the CEO implementation of getPosition(). # The call to getTitle() for item 3 runs the C++ Employee::getTitle() # method, which in turn calls getPosition(). This virtual method call # passes down through the C++ director class to the Perl implementation @@ -50,16 +58,22 @@ print "----------------------\n"; print "(position, title) for items 0-3:\n"; -print " ${\ $list->get_item(0)->getPosition() }, \"${\ $list->get_item(0)->getTitle() }\"\n"; -print " ${\ $list->get_item(1)->getPosition() }, \"${\ $list->get_item(1)->getTitle() }\"\n"; -print " ${\ $list->get_item(2)->getPosition() }, \"${\ $list->get_item(2)->getTitle() }\"\n"; -print " ${\ $list->get_item(3)->getPosition() }, \"${\ $list->get_item(3)->getTitle() }\"\n"; +printf " %s, \"%s\"\n", $list->get_item(0)->getPosition(), $list->get_item(0)->getTitle(); +printf " %s, \"%s\"\n", $list->get_item(1)->getPosition(), $list->get_item(1)->getTitle(); +printf " %s, \"%s\"\n", $list->get_item(2)->getPosition(), $list->get_item(2)->getTitle(); +printf " %s, \"%s\"\n", $list->get_item(3)->getPosition(), $list->get_item(3)->getTitle(); print "----------------------\n"; # Time to delete the EmployeeList, which will delete all the Employee* -# items it contains. The last item is our CEO, which gets destroyed as well. +# items it contains. The last item is our CEO, which gets destroyed as its +# reference count goes to zero. The Perl destructor runs, and is still +# able to call self.getName() since the underlying C++ object still +# exists. After this destructor runs the remaining C++ destructors run as +# usual to destroy the object. + undef $list; print "----------------------\n"; # All done. + print "perl exit\n"; diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 530ed07ed..d7a131aa2 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -238,47 +238,42 @@ public: { Node *mod = Getattr(n, "module"); if (mod) { - Node *options = Getattr(mod, "options"); - if (options) { - int dirprot = 0; - if (Getattr(options, "dirprot")) - dirprot = 1; - if (Getattr(options, "nodirprot")) - dirprot = 0; - if (Getattr(options, "directors")) { - int allow = 1; - if (export_all) { - Printv(stderr, - "*** directors are not supported with -exportall\n", NIL); - allow = 0; - } - if (staticoption) { - Printv(stderr, - "*** directors are not supported with -static\n", NIL); - allow = 0; - } - if (!blessed) { - Printv(stderr, - "*** directors are not supported with -noproxy\n", NIL); - allow = 0; - } - if (no_pmfile) { - Printv(stderr, - "*** directors are not supported with -nopm\n", NIL); - allow = 0; - } - if (compat) { - Printv(stderr, - "*** directors are not supported with -compat\n", NIL); - allow = 0; - } - if (allow) { - allow_directors(); - if (dirprot) - allow_dirprot(); - } - } - } + Node *options = Getattr(mod, "options"); + if (options) { + int dirprot = 0; + if (Getattr(options, "dirprot")) + dirprot = 1; + if (Getattr(options, "nodirprot")) + dirprot = 0; + if (Getattr(options, "directors")) { + int allow = 1; + if (export_all) { + Printv(stderr, "*** directors are not supported with -exportall\n", NIL); + allow = 0; + } + if (staticoption) { + Printv(stderr, "*** directors are not supported with -static\n", NIL); + allow = 0; + } + if (!blessed) { + Printv(stderr, "*** directors are not supported with -noproxy\n", NIL); + allow = 0; + } + if (no_pmfile) { + Printv(stderr, "*** directors are not supported with -nopm\n", NIL); + allow = 0; + } + if (compat) { + Printv(stderr, "*** directors are not supported with -compat\n", NIL); + allow = 0; + } + if (allow) { + allow_directors(); + if (dirprot) + allow_dirprot(); + } + } + } } } @@ -301,8 +296,8 @@ public: if (directorsEnabled()) { f_runtime_h = NewFile(outfile_h, "w", SWIG_output_files()); if (!f_runtime_h) { - FileErrorDisplay(outfile_h); - SWIG_exit(EXIT_FAILURE); + FileErrorDisplay(outfile_h); + SWIG_exit(EXIT_FAILURE); } } @@ -1477,8 +1472,7 @@ public: String *director_disown; if (Getattr(n, "perl5:directordisown")) { - director_disown = NewStringf("%s%s($self);\n", - tab4, Getattr(n, "perl5:directordisown")); + director_disown = NewStringf("%s%s($self);\n", tab4, Getattr(n, "perl5:directordisown")); } else { director_disown = NewString(""); } @@ -1511,7 +1505,8 @@ public: type = NewString("SV"); SwigType_add_pointer(type); String *action = NewString(""); - Printv(action, "{\n", " Swig::Director *director = SWIG_DIRECTOR_CAST(arg1);\n", " result = sv_newmortal();\n" " if (director) sv_setsv(result, director->swig_get_self());\n", "}\n", NIL); + Printv(action, "{\n", " Swig::Director *director = SWIG_DIRECTOR_CAST(arg1);\n", + " result = sv_newmortal();\n" " if (director) sv_setsv(result, director->swig_get_self());\n", "}\n", NIL); Setfile(get_attr, Getfile(n)); Setline(get_attr, Getline(n)); Setattr(get_attr, "wrap:action", action); @@ -1534,7 +1529,7 @@ public: "my $member_func = \"swig_${field}_set\";\n", tab4, "if (not $self->can($member_func)) {\n", tab8, "my $h = ", cmodule, "::", mrename, "($self);\n", tab8, "return $h->{$field} = $newval if $h;\n", tab4, "}\n", tab4, "return $self->$member_func($newval);\n", "}\n", NIL); - Delete(mrename); + Delete(mrename); } } return SWIG_OK; @@ -1707,8 +1702,8 @@ public: String *saved_nc = none_comparison; none_comparison = NewStringf("strcmp(SvPV_nolen(ST(0)), \"%s::%s\") != 0", module, class_name); String *saved_director_prot_ctor_code = director_prot_ctor_code; - director_prot_ctor_code = NewStringf( "if ($comparison) { /* subclassed */\n" " $director_new\n" "} else {\n" - "SWIG_exception_fail(SWIG_RuntimeError, \"accessing abstract class or protected constructor\");\n" "}\n"); + director_prot_ctor_code = NewStringf("if ($comparison) { /* subclassed */\n" " $director_new\n" "} else {\n" + "SWIG_exception_fail(SWIG_RuntimeError, \"accessing abstract class or protected constructor\");\n" "}\n"); Language::constructorHandler(n); Delete(none_comparison); none_comparison = saved_nc; @@ -1732,7 +1727,7 @@ public: Printv(pcode, "sub ", Swig_name_construct(NSPACE_TODO, symname), " {\n", NIL); } - const char *pkg = getCurrentClass() && Swig_directorclass(getCurrentClass()) ? "$_[0]" : "shift"; + const char *pkg = getCurrentClass() && Swig_directorclass(getCurrentClass())? "$_[0]" : "shift"; Printv(pcode, tab4, "my $pkg = ", pkg, ";\n", tab4, "my $self = ", cmodule, "::", Swig_name_construct(NSPACE_TODO, symname), "(@_);\n", tab4, "bless $self, $pkg if defined($self);\n", "}\n\n", NIL); @@ -2083,7 +2078,7 @@ public: if (Cmp(storage, "virtual") == 0) { if (Cmp(value, "0") == 0) { - pure_virtual = true; + pure_virtual = true; } } @@ -2116,18 +2111,18 @@ public: Append(declaration, " throw("); if (throw_parm_list) - Swig_typemap_attach_parms("throws", throw_parm_list, 0); + Swig_typemap_attach_parms("throws", throw_parm_list, 0); for (p = throw_parm_list; p; p = nextSibling(p)) { - if (Getattr(p, "tmap:throws")) { - if (gencomma++) { - Append(w->def, ", "); - Append(declaration, ", "); - } - String *str = SwigType_str(Getattr(p, "type"), 0); - Append(w->def, str); - Append(declaration, str); - Delete(str); - } + if (Getattr(p, "tmap:throws")) { + if (gencomma++) { + Append(w->def, ", "); + Append(declaration, ", "); + } + String *str = SwigType_str(Getattr(p, "type"), 0); + Append(w->def, str); + Append(declaration, str); + Delete(str); + } } Append(w->def, ")"); @@ -2143,9 +2138,9 @@ public: */ if (!is_void) { if (!(ignored_method && !pure_virtual)) { - String *cres = SwigType_lstr(returntype, "c_result"); - Printf(w->code, "%s;\n", cres); - Delete(cres); + String *cres = SwigType_lstr(returntype, "c_result"); + Printf(w->code, "%s;\n", cres); + Delete(cres); String *pres = NewStringf("SV *%s", Swig_cresult_name()); Wrapper_add_local(w, Swig_cresult_name(), pres); Delete(pres); @@ -2154,14 +2149,14 @@ public: if (ignored_method) { if (!pure_virtual) { - if (!is_void) - Printf(w->code, "return "); - String *super_call = Swig_method_call(super, l); - Printf(w->code, "%s;\n", super_call); - Delete(super_call); + if (!is_void) + Printf(w->code, "return "); + String *super_call = Swig_method_call(super, l); + Printf(w->code, "%s;\n", super_call); + Delete(super_call); } else { - Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), - SwigType_namestr(name)); + Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), + SwigType_namestr(name)); } } else { /* attach typemaps to arguments (C/C++ -> Perl) */ @@ -2195,32 +2190,32 @@ public: int outputs = 0; if (!is_void) - outputs++; + outputs++; /* build argument list and type conversion string */ idx = 0; p = l; while (p) { - if (checkAttribute(p, "tmap:in:numinputs", "0")) { - p = Getattr(p, "tmap:in:next"); - continue; - } + if (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); + continue; + } - /* old style? caused segfaults without the p!=0 check - in the for() condition, and seems dangerous in the - while loop as well. - while (Getattr(p, "tmap:ignore")) { - p = Getattr(p, "tmap:ignore:next"); - } - */ + /* old style? caused segfaults without the p!=0 check + in the for() condition, and seems dangerous in the + while loop as well. + while (Getattr(p, "tmap:ignore")) { + p = Getattr(p, "tmap:ignore:next"); + } + */ - if (Getattr(p, "tmap:directorargout") != 0) - outputs++; + if (Getattr(p, "tmap:directorargout") != 0) + outputs++; - String *pname = Getattr(p, "name"); - String *ptype = Getattr(p, "type"); + String *pname = Getattr(p, "name"); + String *ptype = Getattr(p, "type"); - if ((tm = Getattr(p, "tmap:directorin")) != 0) { + if ((tm = Getattr(p, "tmap:directorin")) != 0) { sprintf(source, "obj%d", idx++); String *input = NewString(source); Setattr(p, "emit:directorinput", input); @@ -2234,74 +2229,74 @@ public: Printv(wrap_args, tm, "\n", NIL); Putc('O', parse_args); Printv(pstack, "XPUSHs(", source, ");\n", NIL); - p = Getattr(p, "tmap:directorin:next"); - continue; - } else if (Cmp(ptype, "void")) { - /* special handling for pointers to other C++ director classes. - * ideally this would be left to a typemap, but there is currently no - * way to selectively apply the dynamic_cast<> to classes that have - * directors. in other words, the type "SwigDirector_$1_lname" only exists - * for classes with directors. we avoid the problem here by checking - * module.wrap::directormap, but it's not clear how to get a typemap to - * do something similar. perhaps a new default typemap (in addition - * to SWIGTYPE) called DIRECTORTYPE? - */ - if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) { - Node *module = Getattr(parent, "module"); - Node *target = Swig_directormap(module, ptype); - sprintf(source, "obj%d", idx++); - String *nonconst = 0; - /* strip pointer/reference --- should move to Swig/stype.c */ - String *nptype = NewString(Char(ptype) + 2); - /* name as pointer */ - String *ppname = Copy(pname); - if (SwigType_isreference(ptype)) { - Insert(ppname, 0, "&"); - } - /* if necessary, cast away const since Python doesn't support it! */ - if (SwigType_isconst(nptype)) { - nonconst = NewStringf("nc_tmp_%s", pname); - String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname); - Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); - Delete(nonconst_i); - Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, - "Target language argument '%s' discards const in director method %s::%s.\n", - SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name)); - } else { - nonconst = Copy(ppname); - } - Delete(nptype); - Delete(ppname); - String *mangle = SwigType_manglestr(ptype); - if (target) { - String *director = NewStringf("director_%s", mangle); - Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL); - Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL); - Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst); - Printf(wrap_args, "if (!%s) {\n", director); - Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); - Append(wrap_args, "} else {\n"); - Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director); - Printf(wrap_args, "SvREFCNT_inc((SV *)%s);\n", source); - Append(wrap_args, "}\n"); - Delete(director); - } else { - Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL); - Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); - Printf(pstack, "XPUSHs(sv_2mortal(%s));\n", source); - } - Putc('O', parse_args); - Delete(mangle); - Delete(nonconst); - } else { - Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0), - SwigType_namestr(c_classname), SwigType_namestr(name)); - status = SWIG_NOWRAP; - break; - } - } - p = nextSibling(p); + p = Getattr(p, "tmap:directorin:next"); + continue; + } else if (Cmp(ptype, "void")) { + /* special handling for pointers to other C++ director classes. + * ideally this would be left to a typemap, but there is currently no + * way to selectively apply the dynamic_cast<> to classes that have + * directors. in other words, the type "SwigDirector_$1_lname" only exists + * for classes with directors. we avoid the problem here by checking + * module.wrap::directormap, but it's not clear how to get a typemap to + * do something similar. perhaps a new default typemap (in addition + * to SWIGTYPE) called DIRECTORTYPE? + */ + if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) { + Node *module = Getattr(parent, "module"); + Node *target = Swig_directormap(module, ptype); + sprintf(source, "obj%d", idx++); + String *nonconst = 0; + /* strip pointer/reference --- should move to Swig/stype.c */ + String *nptype = NewString(Char(ptype) + 2); + /* name as pointer */ + String *ppname = Copy(pname); + if (SwigType_isreference(ptype)) { + Insert(ppname, 0, "&"); + } + /* if necessary, cast away const since Python doesn't support it! */ + if (SwigType_isconst(nptype)) { + nonconst = NewStringf("nc_tmp_%s", pname); + String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname); + Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); + Delete(nonconst_i); + Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, + "Target language argument '%s' discards const in director method %s::%s.\n", + SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name)); + } else { + nonconst = Copy(ppname); + } + Delete(nptype); + Delete(ppname); + String *mangle = SwigType_manglestr(ptype); + if (target) { + String *director = NewStringf("director_%s", mangle); + Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL); + Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL); + Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst); + Printf(wrap_args, "if (!%s) {\n", director); + Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); + Append(wrap_args, "} else {\n"); + Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director); + Printf(wrap_args, "SvREFCNT_inc((SV *)%s);\n", source); + Append(wrap_args, "}\n"); + Delete(director); + } else { + Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL); + Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); + Printf(pstack, "XPUSHs(sv_2mortal(%s));\n", source); + } + Putc('O', parse_args); + Delete(mangle); + Delete(nonconst); + } else { + Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, + "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0), + SwigType_namestr(c_classname), SwigType_namestr(name)); + status = SWIG_NOWRAP; + break; + } + } + p = nextSibling(p); } /* add the method name as a PyString */ @@ -2312,7 +2307,7 @@ public: /* pass the method call on to the Python object */ if (dirprot_mode() && !is_public(n)) { - Printf(w->code, "swig_set_inner(\"%s\", true);\n", name); + Printf(w->code, "swig_set_inner(\"%s\", true);\n", name); } Append(w->code, "ENTER;\n"); @@ -2324,22 +2319,22 @@ public: Printf(w->code, "call_method(\"%s\", G_EVAL | G_SCALAR);\n", pyname); if (dirprot_mode() && !is_public(n)) - Printf(w->code, "swig_set_inner(\"%s\", false);\n", name); + Printf(w->code, "swig_set_inner(\"%s\", false);\n", name); /* exception handling */ tm = Swig_typemap_lookup("director:except", n, Swig_cresult_name(), 0); if (!tm) { - tm = Getattr(n, "feature:director:except"); - if (tm) - tm = Copy(tm); + tm = Getattr(n, "feature:director:except"); + if (tm) + tm = Copy(tm); } Append(w->code, "if (SvTRUE(ERRSV)) {\n"); Append(w->code, " PUTBACK;\n FREETMPS;\n LEAVE;\n"); if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { - Replaceall(tm, "$error", "ERRSV"); - Printv(w->code, Str(tm), "\n", NIL); + Replaceall(tm, "$error", "ERRSV"); + Printv(w->code, Str(tm), "\n", NIL); } else { - Printf(w->code, " Swig::DirectorMethodException::raise(ERRSV);\n", classname, pyname); + Printf(w->code, " Swig::DirectorMethodException::raise(ERRSV);\n", classname, pyname); } Append(w->code, "}\n"); Delete(tm); @@ -2357,62 +2352,62 @@ public: String *outarg = NewString(""); if (outputs > 1) { - Wrapper_add_local(w, "output", "SV *output"); - Printf(w->code, "if (count != %d) {\n", outputs); - Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Perl method %s.%sfailed to return a list.\");\n", classname, pyname); - Append(w->code, "}\n"); + Wrapper_add_local(w, "output", "SV *output"); + Printf(w->code, "if (count != %d) {\n", outputs); + Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Perl method %s.%sfailed to return a list.\");\n", classname, pyname); + Append(w->code, "}\n"); } idx = 0; /* marshal return value */ if (!is_void) { - Append(w->code, "SPAGAIN;\n"); + Append(w->code, "SPAGAIN;\n"); Printf(w->code, "%s = POPs;\n", Swig_cresult_name()); - tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); - if (tm != 0) { - if (outputs > 1) { - Printf(w->code, "output = POPs;\n"); - Replaceall(tm, "$input", "output"); - } else { - Replaceall(tm, "$input", Swig_cresult_name()); - } - char temp[24]; - sprintf(temp, "%d", idx); - Replaceall(tm, "$argnum", temp); + tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); + if (tm != 0) { + if (outputs > 1) { + Printf(w->code, "output = POPs;\n"); + Replaceall(tm, "$input", "output"); + } else { + Replaceall(tm, "$input", Swig_cresult_name()); + } + char temp[24]; + sprintf(temp, "%d", idx); + Replaceall(tm, "$argnum", temp); - /* TODO check this */ - if (Getattr(n, "wrap:disown")) { - Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); - } else { - Replaceall(tm, "$disown", "0"); - } - Replaceall(tm, "$result", "c_result"); - Printv(w->code, tm, "\n", NIL); - Delete(tm); - } else { - Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname), - SwigType_namestr(name)); - status = SWIG_ERROR; - } + /* TODO check this */ + if (Getattr(n, "wrap:disown")) { + Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); + } else { + Replaceall(tm, "$disown", "0"); + } + Replaceall(tm, "$result", "c_result"); + Printv(w->code, tm, "\n", NIL); + Delete(tm); + } else { + Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, + "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), + SwigType_namestr(c_classname), SwigType_namestr(name)); + status = SWIG_ERROR; + } } /* marshal outputs */ for (p = l; p;) { - if ((tm = Getattr(p, "tmap:directorargout")) != 0) { - if (outputs > 1) { - Printf(w->code, "output = POPs;\n"); - Replaceall(tm, "$result", "output"); - } else { - Replaceall(tm, "$result", Swig_cresult_name()); - } - Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); - Printv(w->code, tm, "\n", NIL); - p = Getattr(p, "tmap:directorargout:next"); - } else { - p = nextSibling(p); - } + if ((tm = Getattr(p, "tmap:directorargout")) != 0) { + if (outputs > 1) { + Printf(w->code, "output = POPs;\n"); + Replaceall(tm, "$result", "output"); + } else { + Replaceall(tm, "$result", Swig_cresult_name()); + } + Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); + Printv(w->code, tm, "\n", NIL); + p = Getattr(p, "tmap:directorargout:next"); + } else { + p = nextSibling(p); + } } Delete(parse_args); @@ -2428,13 +2423,13 @@ public: if (!is_void) { if (!(ignored_method && !pure_virtual)) { - String *rettype = SwigType_str(returntype, 0); - if (!SwigType_isreference(returntype)) { - Printf(w->code, "return (%s) c_result;\n", rettype); - } else { - Printf(w->code, "return (%s) *c_result;\n", rettype); - } - Delete(rettype); + String *rettype = SwigType_str(returntype, 0); + if (!SwigType_isreference(returntype)) { + Printf(w->code, "return (%s) c_result;\n", rettype); + } else { + Printf(w->code, "return (%s) *c_result;\n", rettype); + } + Delete(rettype); } } @@ -2448,7 +2443,7 @@ public: Replaceall(inline_extra_method, name, extra_method_name); Replaceall(inline_extra_method, ";\n", " {\n "); if (!is_void) - Printf(inline_extra_method, "return "); + Printf(inline_extra_method, "return "); String *methodcall = Swig_method_call(super, l); Printv(inline_extra_method, methodcall, ";\n }\n", NIL); Delete(methodcall); @@ -2458,10 +2453,10 @@ public: /* emit the director method */ if (status == SWIG_OK) { if (!Getattr(n, "defaultargs")) { - Replaceall(w->code, "$symname", symname); - Wrapper_print(w, f_directors); - Printv(f_directors_h, declaration, NIL); - Printv(f_directors_h, inline_extra_method, NIL); + Replaceall(w->code, "$symname", symname); + Wrapper_print(w, f_directors); + Printv(f_directors_h, declaration, NIL); + Printv(f_directors_h, inline_extra_method, NIL); } } @@ -2476,7 +2471,7 @@ public: member_func = 1; rv = Language::classDirectorDisown(n); member_func = 0; - if(rv == SWIG_OK && Swig_directorclass(n)) { + if (rv == SWIG_OK && Swig_directorclass(n)) { String *symname = Getattr(n, "sym:name"); String *disown = Swig_name_disown(NSPACE_TODO, symname); Setattr(n, "perl5:directordisown", NewStringf("%s::%s", cmodule, disown)); From 81ce0a723e151e570c7990fb9a0ccef3976f0c81 Mon Sep 17 00:00:00 2001 From: Robert Stone Date: Thu, 14 Nov 2013 11:19:11 -0800 Subject: [PATCH 0778/1160] fix "long long" tests for perl v5.6 --- Examples/test-suite/perl5/li_typemaps_runme.pl | 18 +++++++++++------- .../perl5/reference_global_vars_runme.pl | 11 ++++++----- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Examples/test-suite/perl5/li_typemaps_runme.pl b/Examples/test-suite/perl5/li_typemaps_runme.pl index c182cdbb1..a573b89a0 100644 --- a/Examples/test-suite/perl5/li_typemaps_runme.pl +++ b/Examples/test-suite/perl5/li_typemaps_runme.pl @@ -41,8 +41,8 @@ batch('schar', -0x80, 0, 1, 12, 0x7f); use Math::BigInt qw(); # the pack dance is to get plain old NVs out of the # Math::BigInt objects. - my $inf = unpack 'd', pack 'd', Math::BigInt->binf(); - my $nan = unpack 'd', pack 'd', Math::BigInt->bnan(); + my $inf = unpack 'd', pack 'd', Math::BigInt->new('Inf'); + my $nan = unpack 'd', pack 'd', Math::BigInt->new('NaN'); batch('float', -(2 - 2 ** -23) * 2 ** 127, -1, -2 ** -149, 0, 2 ** -149, 1, @@ -63,12 +63,16 @@ batch('schar', -0x80, 0, 1, 12, 0x7f); batch('longlong', -1, 0, 1, 12); batch('ulonglong', 0, 1, 12); SKIP: { - my $a = "8000000000000000"; - my $b = "7fffffffffffffff"; - my $c = "ffffffffffffffff"; + use Math::BigInt qw(); skip "not a 64bit Perl", 18 unless eval { pack 'q', 1 }; - batch('longlong', -hex($a), hex($b)); - batch('ulonglong', hex($c)); + my $a = unpack 'q', pack 'q', + Math::BigInt->new('-9223372036854775808'); + my $b = unpack 'q', pack 'q', + Math::BigInt->new('9223372036854775807'); + my $c = unpack 'Q', pack 'Q', + Math::BigInt->new('18446744073709551615'); + batch('longlong', $a, $b); + batch('ulonglong', $c); } my($foo, $int) = li_typemaps::out_foo(10); diff --git a/Examples/test-suite/perl5/reference_global_vars_runme.pl b/Examples/test-suite/perl5/reference_global_vars_runme.pl index dfbcf15bb..89d73b03d 100755 --- a/Examples/test-suite/perl5/reference_global_vars_runme.pl +++ b/Examples/test-suite/perl5/reference_global_vars_runme.pl @@ -53,12 +53,13 @@ $cvar->{var_unsigned_long} = createref_unsigned_long(10); is(value_unsigned_long($cvar->{var_unsigned_long}), 10); SKIP: { - my $a = "6FFFFFFFFFFFFFF8"; + use Math::BigInt qw(); skip "64 bit int support", 1 unless eval { pack 'q', 1 }; - # using hex() here instead of a literal because non 64bit Perls will - # be noisy about big constants. - $cvar->{var_long_long} = createref_long_long(hex $a); - is(value_long_long($cvar->{var_long_long}), hex $a); + # the pack dance is to get plain old IVs out of the + # Math::BigInt objects. + my $a = unpack 'q', pack 'q', Math::BigInt->new('8070450532247928824'); + $cvar->{var_long_long} = createref_long_long($a); + is(value_long_long($cvar->{var_long_long}), $a); } #ull = abs(0xFFFFFFF2FFFFFFF0) From 16d40c14f946055f7516697091c5758cba9de883 Mon Sep 17 00:00:00 2001 From: Robert Stone Date: Fri, 15 Nov 2013 10:49:34 -0800 Subject: [PATCH 0779/1160] try adding travis ci to this branch --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 26758304f..0a3aa1893 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,3 +56,4 @@ script: branches: only: - master + - perl5-directors-minimal From e566c5fa7f4b8af527c9f13f6eabd84bfc38a897 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 16 Nov 2013 00:13:38 +0000 Subject: [PATCH 0780/1160] Add support for parsing C++11 =delete and =default Although this was documented as working, it wasn't implemented %typemap(default) failed without the idstring changes Add some C tests using the C++ keyword delete --- Doc/Manual/CPlusPlus11.html | 22 +++++--- Examples/test-suite/c_delete.i | 14 +++++ Examples/test-suite/c_delete_function.i | 7 +++ Examples/test-suite/common.mk | 2 + Examples/test-suite/cpp11_default_delete.i | 64 ++++++++++++++++++--- Source/CParse/cscanner.c | 3 + Source/CParse/parser.y | 66 ++++++++++++++++++++-- Source/Modules/allocate.cxx | 26 ++++++--- 8 files changed, 173 insertions(+), 31 deletions(-) create mode 100644 Examples/test-suite/c_delete.i create mode 100644 Examples/test-suite/c_delete_function.i diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index 3caec748e..95d748791 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -33,7 +33,7 @@
  • New string literals
  • User-defined literals
  • Thread-local storage -
  • Defaulting/deleting of standard functions on C++ objects +
  • Defaulting/deleting of standard functions on C++ objects
  • Type long long int
  • Static assertions
  • Allow sizeof to work on members of classes without an explicit object @@ -739,23 +739,27 @@ A variable will be thread local if accessed from different threads from the targ same way that it will be thread local if accessed from C++ code.

    -

    7.2.21 Defaulting/deleting of standard functions on C++ objects

    +

    7.2.21 Explicitly defaulted functions and deleted functions

    -

    SWIG correctly parses the = delete and = default -keywords. For example:

    +

    SWIG handles explicitly defaulted functions, that is, = default added to a function declaration. Deleted definitions, which are also called deleted functions, have = delete added to the function declaration. +For example:

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

    This feature is specific to C++ only. The defaulting/deleting is currently ignored, because SWIG -automatically produces wrappers for special constructors and operators specific to the target language.

    +

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

    7.2.22 Type long long int

    diff --git a/Examples/test-suite/c_delete.i b/Examples/test-suite/c_delete.i new file mode 100644 index 000000000..d47032095 --- /dev/null +++ b/Examples/test-suite/c_delete.i @@ -0,0 +1,14 @@ +%module c_delete + +/* check C++ delete keyword is okay in C wrappers */ + +%inline %{ +struct delete { + int delete; +}; +%} + +%rename(DeleteGlobalVariable) delete; +%inline %{ +int delete = 0; +%} diff --git a/Examples/test-suite/c_delete_function.i b/Examples/test-suite/c_delete_function.i new file mode 100644 index 000000000..e1fba7495 --- /dev/null +++ b/Examples/test-suite/c_delete_function.i @@ -0,0 +1,7 @@ +%module c_delete_function + +/* check C++ delete keyword is okay in C wrappers */ + +%inline %{ +double delete(double d) { return d; } +%} diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index e25d36715..0d360830d 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -552,6 +552,8 @@ endif C_TEST_CASES += \ arrays \ bom_utf8 \ + c_delete \ + c_delete_function \ char_constant \ const_const \ constant_expr \ diff --git a/Examples/test-suite/cpp11_default_delete.i b/Examples/test-suite/cpp11_default_delete.i index be4cc6cc9..49a677060 100644 --- a/Examples/test-suite/cpp11_default_delete.i +++ b/Examples/test-suite/cpp11_default_delete.i @@ -1,9 +1,12 @@ -/* This testcase checks whether SWIG correctly parses the default and delete - keywords which keep or remove default C++ object construction functions. */ +/* This testcase checks whether SWIG correctly parses C++11 explicitly defaulted functions and deleted functions */ %module cpp11_default_delete -%{ -#include +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED, SWIGWARN_LANG_OVERLOAD_SHADOW) trivial::trivial(trivial&&); +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED, SWIGWARN_LANG_OVERLOAD_SHADOW) trivial::operator =(trivial&&); + +%rename(Assignment) *::operator=; + +%inline %{ class NonCopyable { public: @@ -14,11 +17,56 @@ public: }; struct A1 { - void f(int i); - void f(double i) = delete; /* Don't cast double to int. Compiler returns an error */ + void func(int i) {} + A1() = default; + ~A1() = default; + void func(double i) = delete; /* Don't cast double to int. Compiler returns an error */ +private: + A1(const A1&); }; +A1::A1(const A1&) = default; + struct A2 { - void f(int i); - template void f(T) = delete; /* Only accept int */ + void func(int i) {} + virtual void fff(int) = delete; + virtual ~A2() = default; + template void func(T) = delete; +}; + +struct trivial { + trivial() = default; + trivial(const trivial&) = default; + trivial(trivial&&) = default; + trivial& operator=(const trivial&) = default; + trivial& operator=(trivial&&) = default; + ~trivial() = default; +}; + +struct nontrivial1 { + nontrivial1(); +}; +nontrivial1::nontrivial1() = default; + +struct sometype { + sometype() = delete; + sometype(int) = delete; + sometype(double); +}; +sometype::sometype(double) {} + +/* Not working with prerelease of gcc-4.8 +struct nonew { + void *operator new(std::size_t) = delete; + void *operator new[](std::size_t) = delete; +}; +*/ + +struct moveonly { + moveonly() = default; + moveonly(const moveonly&) = delete; + moveonly(moveonly&&) = default; + moveonly& operator=(const moveonly&) = delete; + moveonly& operator=(moveonly&&) = default; + ~moveonly() = default; }; %} diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index e91dfb3d3..8b484f8a7 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -728,6 +728,9 @@ int yylex(void) { if (strcmp(yytext, "delete") == 0) { return (DELETE_KW); } + if (strcmp(yytext, "default") == 0) { + return (DEFAULT); + } if (strcmp(yytext, "using") == 0) { return (USING); } diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index ce0c91c43..1328d6e0d 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -447,6 +447,14 @@ static void add_symbols(Node *n) { n = nextSibling(n); continue; } + if (cparse_cplusplus) { + String *value = Getattr(n, "value"); + if (value && Strcmp(value, "delete") == 0) { + /* C++11 deleted definition / deleted function */ + SetFlag(n,"deleted"); + SetFlag(n,"feature:ignore"); + } + } if (only_csymbol || GetFlag(n,"feature:ignore")) { /* Only add to C symbol table and continue */ Swig_symbol_add(0, n); @@ -1715,7 +1723,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %token NATIVE INLINE %token TYPEMAP EXCEPT ECHO APPLY CLEAR SWIGTEMPLATE FRAGMENT %token WARN -%token LESSTHAN GREATERTHAN DELETE_KW +%token LESSTHAN GREATERTHAN DELETE_KW DEFAULT %token LESSTHANOREQUALTO GREATERTHANOREQUALTO EQUALTO NOTEQUALTO %token ARROW %token QUESTIONMARK @@ -1775,7 +1783,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type ellipsis variadic; %type type rawtype type_right anon_bitfield_type decltype ; %type base_list inherit raw_inherit; -%type definetype def_args etype; +%type definetype def_args etype default_delete deleted_definition explicit_default; %type expr exprnum exprcompound valexpr; %type ename ; %type template_decl; @@ -4696,6 +4704,8 @@ cpp_constructor_decl : storage_class type LPAREN parms RPAREN ctor_end { Delete(code); } SetFlag($$,"feature:new"); + if ($6.defarg) + Setattr($$,"value",$6.defarg); } else { $$ = 0; } @@ -4723,6 +4733,8 @@ cpp_destructor_decl : NOT idtemplate LPAREN parms RPAREN cpp_end { } Setattr($$,"throws",$6.throws); Setattr($$,"throw",$6.throwf); + if ($6.val) + Setattr($$,"value",$6.val); add_symbols($$); } @@ -4738,9 +4750,8 @@ cpp_destructor_decl : NOT idtemplate LPAREN parms RPAREN cpp_end { Delete(name); Setattr($$,"throws",$7.throws); Setattr($$,"throw",$7.throwf); - if ($7.val) { - Setattr($$,"value","0"); - } + if ($7.val) + Setattr($$,"value",$7.val); if (Len(scanner_ccode)) { String *code = Copy(scanner_ccode); Setattr($$,"code",code); @@ -4982,11 +4993,19 @@ cpp_swig_directive: pragma_directive { $$ = $1; } cpp_end : cpp_const SEMI { Clear(scanner_ccode); + $$.val = 0; + $$.throws = $1.throws; + $$.throwf = $1.throwf; + } + | cpp_const EQUAL default_delete SEMI { + Clear(scanner_ccode); + $$.val = $3.val; $$.throws = $1.throws; $$.throwf = $1.throwf; } | cpp_const LBRACE { skip_balanced('{','}'); + $$.val = 0; $$.throws = $1.throws; $$.throwf = $1.throwf; } @@ -6143,11 +6162,15 @@ definetype : { /* scanner_check_typedef(); */ } expr { } else if ($$.type != T_CHAR && $$.type != T_WSTRING && $$.type != T_WCHAR) { $$.rawval = 0; } + $$.qualifier = 0; $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; scanner_ignore_typedef(); } + | default_delete { + $$ = $1; + } /* | string { $$.val = NewString($1); @@ -6160,6 +6183,38 @@ definetype : { /* scanner_check_typedef(); */ } expr { */ ; +default_delete : deleted_definition { + $$ = $1; + } + | explicit_default { + $$ = $1; + } + ; + +/* For C++ deleted definition '= delete' */ +deleted_definition : DELETE_KW { + $$.val = NewString("delete"); + $$.rawval = 0; + $$.type = T_STRING; + $$.qualifier = 0; + $$.bitfield = 0; + $$.throws = 0; + $$.throwf = 0; + } + ; + +/* For C++ explicitly defaulted functions '= default' */ +explicit_default : DEFAULT { + $$.val = NewString("default"); + $$.rawval = 0; + $$.type = T_STRING; + $$.qualifier = 0; + $$.bitfield = 0; + $$.throws = 0; + $$.throwf = 0; + } + ; + /* Some stuff for handling enums */ ename : ID { $$ = $1; } @@ -6711,6 +6766,7 @@ template_decl : LESSTHAN valparms GREATERTHAN { ; idstring : ID { $$ = $1; } + | default_delete { $$ = $1.val; } | string { $$ = $1; } ; diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index dee044bf3..b7daae59c 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -659,7 +659,7 @@ Allocate(): } if (!Getattr(n, "allocate:has_destructor")) { - /* No destructor was defined. We need to check a few things here too */ + /* No destructor was defined */ List *bases = Getattr(n, "allbases"); int allows_destruct = 1; @@ -676,13 +676,13 @@ Allocate(): } if (!Getattr(n, "allocate:has_assign")) { - /* No destructor was defined. We need to check a few things here too */ + /* No assignment operator was defined */ List *bases = Getattr(n, "allbases"); int allows_assign = 1; for (int i = 0; i < Len(bases); i++) { Node *n = Getitem(bases, i); - /* If base class does not allow default destructor, we don't allow it either */ + /* If base class does not allow assignment, we don't allow it either */ if (Getattr(n, "allocate:has_assign")) { allows_assign = !Getattr(n, "allocate:noassign"); } @@ -693,13 +693,13 @@ Allocate(): } if (!Getattr(n, "allocate:has_new")) { - /* No destructor was defined. We need to check a few things here too */ + /* No new operator was defined */ List *bases = Getattr(n, "allbases"); int allows_new = 1; for (int i = 0; i < Len(bases); i++) { Node *n = Getitem(bases, i); - /* If base class does not allow default destructor, we don't allow it either */ + /* If base class does not allow new operator, we don't allow it either */ if (Getattr(n, "allocate:has_new")) { allows_new = !Getattr(n, "allocate:nonew"); } @@ -779,18 +779,26 @@ Allocate(): if (cplus_mode != PUBLIC) { if (Strcmp(name, "operator =") == 0) { /* Look for a private assignment operator */ - Setattr(inclass, "allocate:has_assign", "1"); + if (!GetFlag(n, "deleted")) + Setattr(inclass, "allocate:has_assign", "1"); Setattr(inclass, "allocate:noassign", "1"); } else if (Strcmp(name, "operator new") == 0) { /* Look for a private new operator */ - Setattr(inclass, "allocate:has_new", "1"); + if (!GetFlag(n, "deleted")) + Setattr(inclass, "allocate:has_new", "1"); Setattr(inclass, "allocate:nonew", "1"); } } else { if (Strcmp(name, "operator =") == 0) { - Setattr(inclass, "allocate:has_assign", "1"); + if (!GetFlag(n, "deleted")) + Setattr(inclass, "allocate:has_assign", "1"); + else + Setattr(inclass, "allocate:noassign", "1"); } else if (Strcmp(name, "operator new") == 0) { - Setattr(inclass, "allocate:has_new", "1"); + if (!GetFlag(n, "deleted")) + Setattr(inclass, "allocate:has_new", "1"); + else + Setattr(inclass, "allocate:nonew", "1"); } /* Look for smart pointer operator */ if ((Strcmp(name, "operator ->") == 0) && (!GetFlag(n, "feature:ignore"))) { From 7a8dd4bb2d9b34f511596940f2721c1257fccc6b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 20 Nov 2013 22:24:13 +0000 Subject: [PATCH 0781/1160] Correct html references --- Doc/Manual/CPlusPlus11.html | 144 ++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 71 deletions(-) diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index 95d748791..30b88d6fa 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -10,45 +10,45 @@
    @@ -56,7 +56,7 @@ -

    7.1 Introduction

    +

    7.1 Introduction

    This chapter gives you a brief overview about the SWIG @@ -68,10 +68,10 @@ Google Summer of Code 2009 period.

    new STL types (unordered_ containers, result_of, tuples) are not supported yet.

    -

    7.2 Core language changes

    +

    7.2 Core language changes

    -

    7.2.1 Rvalue reference and move semantics

    +

    7.2.1 Rvalue reference and move semantics

    SWIG correctly parses the new operator && the same as the reference operator &.

    @@ -87,7 +87,7 @@ class MyClass { }; -

    7.2.2 Generalized constant expressions

    +

    7.2.2 Generalized constant expressions

    SWIG correctly parses the keyword constexpr, but ignores its functionality. Constant functions cannot be used as constants.

    @@ -105,7 +105,7 @@ constexpr int myConstFunc() { return MY_CONST; } const int a = MY_CONST; // ok -

    7.2.3 Extern template

    +

    7.2.3 Extern template

    SWIG correctly parses the keywords extern template. However, the explicit template instantiation is not used by SWIG, a %template is still required.

    @@ -123,7 +123,8 @@ public: }; -

    7.2.4 Initializer lists

    +

    7.2.4 Initializer lists

    +

    Initializer lists are very much a C++ compiler construct and are not very accessible from wrappers as @@ -254,7 +255,7 @@ Note that the default typemap for std::initializer_list does nothing bu and hence any user supplied typemaps will override it and suppress the warning.

    -

    7.2.5 Uniform initialization

    +

    7.2.5 Uniform initialization

    The curly brackets {} for member initialization are fully @@ -287,7 +288,7 @@ AltStruct var2{2, 4.3}; // calls the constructor 142.15 -

    7.2.6 Type inference

    +

    7.2.6 Type inference

    SWIG supports decltype() with some limitations. Single @@ -304,13 +305,13 @@ int i; int j; decltype(i+j) k; // syntax error -

    7.2.7 Range-based for-loop

    +

    7.2.7 Range-based for-loop

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

    -

    7.2.8 Lambda functions and expressions

    +

    7.2.8 Lambda functions and expressions

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

    @@ -336,7 +337,7 @@ auto six = [](int x, int y) { return x+y; }(4, 2); Better support should be available in a later release.

    -

    7.2.9 Alternate function syntax

    +

    7.2.9 Alternate function syntax

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

    @@ -371,7 +372,7 @@ auto SomeStruct::FuncName(int x, int y) -> int { auto square(float a, float b) -> decltype(a); -

    7.2.10 Object construction improvement

    +

    7.2.10 Object construction improvement

    @@ -412,12 +413,12 @@ class DerivedClass: public BaseClass { }; -

    7.2.11 Null pointer constant

    +

    7.2.11 Null pointer constant

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

    -

    7.2.12 Strongly typed enumerations

    +

    7.2.12 Strongly typed enumerations

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

    @@ -468,7 +469,7 @@ class AllColors { }; -

    7.2.13 Double angle brackets

    +

    7.2.13 Double angle brackets

    SWIG correctly parses the symbols >> as closing the @@ -479,7 +480,7 @@ shift operator >> otherwise.

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

    7.2.14 Explicit conversion operators

    +

    7.2.14 Explicit conversion operators

    SWIG correctly parses the keyword explicit both for operators and constructors. @@ -515,7 +516,8 @@ SWIG target languages, because all use their own facilities (eg. classes Cloneab to achieve particular copy and compare behaviours.

    -

    7.2.15 Alias templates

    +

    7.2.15 Alias templates

    +

    The following is an example of an alias template: @@ -567,7 +569,7 @@ example.i:17: Warning 341: The 'using' keyword in type aliasing is not fully sup typedef void (*PFD)(double); // The old style -

    7.2.16 Unrestricted unions

    +

    7.2.16 Unrestricted unions

    SWIG fully supports any type inside a union even if it does not @@ -593,7 +595,7 @@ union P { } p1; -

    7.2.17 Variadic templates

    +

    7.2.17 Variadic templates

    SWIG supports the variadic templates syntax (inside the <> @@ -628,7 +630,7 @@ const int SIZE = sizeof...(ClassName<int, int>); In the above example SIZE is of course wrapped as a constant.

    -

    7.2.18 New string literals

    +

    7.2.18 New string literals

    SWIG supports unicode string constants and raw string literals.

    @@ -652,7 +654,7 @@ const char32_t *ii = UR"XXX(I'm a "raw UTF-32" \ string.)XXX";

    Note: SWIG currently incorrectly parses the odd number of double quotes inside the string due to SWIG's C++ preprocessor.

    -

    7.2.19 User-defined literals

    +

    7.2.19 User-defined literals

    @@ -719,7 +721,7 @@ OutputType var2 = 1234_suffix; OutputType var3 = 3.1416_suffix; -

    7.2.20 Thread-local storage

    +

    7.2.20 Thread-local storage

    SWIG correctly parses the thread_local keyword. For example, variable @@ -761,12 +763,12 @@ Explicitly defaulted functions have no direct effect for SWIG wrapping as the de much like any other method declaration parsed by SWIG.

    -

    7.2.22 Type long long int

    +

    7.2.22 Type long long int

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

    -

    7.2.23 Static assertions

    +

    7.2.23 Static assertions

    SWIG correctly parses and calls the new static_assert function.

    @@ -778,7 +780,7 @@ struct Check { }; -

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

    +

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

    SWIG correctly calls the sizeof() on types as well as on the @@ -798,28 +800,28 @@ const int SIZE = sizeof(A::member); // does not work with C++03. Okay with C++11 8 -

    7.3 Standard library changes

    +

    7.3 Standard library changes

    -

    7.3.1 Threading facilities

    +

    7.3.1 Threading facilities

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

    -

    7.3.2 Tuple types and hash tables

    +

    7.3.2 Tuple types and hash tables

    SWIG does not wrap the new tuple types and the unordered_ container classes yet. Variadic template support is working so it is possible to include the tuple header file; it is parsed without any problems.

    -

    7.3.3 Regular expressions

    +

    7.3.3 Regular expressions

    SWIG does not wrap the new C++11 regular expressions classes, because the SWIG target languages use their own facilities for this.

    -

    7.3.4 General-purpose smart pointers

    +

    7.3.4 General-purpose smart pointers

    @@ -827,12 +829,12 @@ SWIG provides special smart pointer handling for std::tr1::shared_ptr i There is no special smart pointer handling available for std::weak_ptr and std::unique_ptr.

    -

    7.3.5 Extensible random number facility

    +

    7.3.5 Extensible random number facility

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

    -

    7.3.6 Wrapper reference

    +

    7.3.6 Wrapper reference

    The new ref and cref classes are used to instantiate a parameter as a reference of a template function. For example:

    @@ -857,7 +859,7 @@ int main() {

    The ref and cref classes are not wrapped by SWIG because the SWIG target languages do not support referencing.

    -

    7.3.7 Polymorphous wrappers for function objects

    +

    7.3.7 Polymorphous wrappers for function objects

    @@ -888,7 +890,7 @@ t = Test() b = t(1,2) # invoke C++ function object -

    7.3.8 Type traits for metaprogramming

    +

    7.3.8 Type traits for metaprogramming

    The new C++ metaprogramming is useful at compile time and is aimed specifically for C++ development:

    @@ -913,7 +915,7 @@ template< class T1, class T2 > int elaborate( T1 A, T2 B ) {

    SWIG correctly parses the template specialization, template types and values inside the <> block and the new helper functions: is_convertible, is_integral, is_const etc. However, SWIG still explicitly requires concrete types when using the %template directive, so the C++ metaprogramming features are not really of interest at runtime in the target languages.

    -

    7.3.9 Uniform method for computing return type of function objects

    +

    7.3.9 Uniform method for computing return type of function objects

    SWIG does not wrap the new result_of class introduced in the <functional> header and map the result_of::type to the concrete type yet. For example:

    From cdefaaf794398655de5e93c4aa9f20fdb01e2283 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 21 Nov 2013 20:20:34 +0000 Subject: [PATCH 0782/1160] Fixes for c_delete and c_delete_function tests --- Examples/test-suite/c_delete.i | 6 ++++++ Examples/test-suite/c_delete_function.i | 4 ++++ Lib/csharp/csharpkw.swg | 3 +++ 3 files changed, 13 insertions(+) diff --git a/Examples/test-suite/c_delete.i b/Examples/test-suite/c_delete.i index d47032095..632340629 100644 --- a/Examples/test-suite/c_delete.i +++ b/Examples/test-suite/c_delete.i @@ -2,6 +2,10 @@ /* check C++ delete keyword is okay in C wrappers */ +#pragma SWIG nowarn=SWIGWARN_PARSE_KEYWORD + +#if !defined(SWIGOCTAVE) /* Octave compiles wrappers as C++ */ + %inline %{ struct delete { int delete; @@ -12,3 +16,5 @@ struct delete { %inline %{ int delete = 0; %} + +#endif diff --git a/Examples/test-suite/c_delete_function.i b/Examples/test-suite/c_delete_function.i index e1fba7495..3739ceadc 100644 --- a/Examples/test-suite/c_delete_function.i +++ b/Examples/test-suite/c_delete_function.i @@ -2,6 +2,10 @@ /* check C++ delete keyword is okay in C wrappers */ +#if !defined(SWIGOCTAVE) /* Octave compiles wrappers as C++ */ + %inline %{ double delete(double d) { return d; } %} + +#endif diff --git a/Lib/csharp/csharpkw.swg b/Lib/csharp/csharpkw.swg index 9a6d979f1..43ca5993b 100644 --- a/Lib/csharp/csharpkw.swg +++ b/Lib/csharp/csharpkw.swg @@ -4,6 +4,8 @@ /* Warnings for C# keywords */ #define CSHARPKW(x) %keywordwarn("'" `x` "' is a C# keyword, renaming to '_" `x` "'",rename="_%s") `x` +#define CSHARPCLASSKW(x) %keywordwarn("'" `x` "' is a special method name used in the C# wrapper classes, class renamed to '_" `x` "'",%$isclass,rename="_%s") `x` + /* from http://www.jaggersoft.com/csharp_grammar.html#1.7%20Keywords @@ -88,6 +90,7 @@ CSHARPKW(void); CSHARPKW(volatile); CSHARPKW(while); +CSHARPCLASSKW(delete); #undef CSHARPKW From f4ada30a7e6f0b15ed4a1446675980b6df15b631 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 21 Nov 2013 19:31:59 +0000 Subject: [PATCH 0783/1160] Add support for C++11 noexcept specification in exception specifications --- Doc/Manual/CPlusPlus11.html | 23 +++++- Examples/test-suite/common.mk | 1 + Examples/test-suite/cpp11_noexcept.i | 48 +++++++++++++ Source/CParse/cscanner.c | 2 + Source/CParse/parser.y | 104 ++++++++++++++++++++------- 5 files changed, 151 insertions(+), 27 deletions(-) create mode 100644 Examples/test-suite/cpp11_noexcept.i diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index 30b88d6fa..0d2f22aff 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -37,6 +37,7 @@
  • Type long long int
  • Static assertions
  • Allow sizeof to work on members of classes without an explicit object +
  • Exception specifications and noexcept
  • Standard library changes
      @@ -583,7 +584,7 @@ struct point { int x_, y_; }; -#include // For placement 'new' in the constructor below +#include <new> // For placement 'new' in the constructor below union P { int z; double w; @@ -800,6 +801,23 @@ const int SIZE = sizeof(A::member); // does not work with C++03. Okay with C++11 8 +

      7.2.25 Exception specifications and noexcept

      + + +

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

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

      7.3 Standard library changes

      @@ -885,7 +903,7 @@ Example of supported usage of the plain functor from Python is shown below. It does not involve std::function.

      -
      +
       t = Test()
       b = t(1,2) # invoke C++ function object
       
      @@ -944,5 +962,6 @@ typename std::result_of<Fun(Arg)>::type test_result_impl(Fun fun, Arg arg)

      Instead, please use decltype() where possible for now.

      + diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 0d360830d..e5127fd0c 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -491,6 +491,7 @@ CPP11_TEST_CASES = \ cpp11_initializer_list \ cpp11_initializer_list_extend \ cpp11_lambda_functions \ + cpp11_noexcept \ cpp11_null_pointer_constant \ cpp11_raw_string_literals \ cpp11_rvalue_reference \ diff --git a/Examples/test-suite/cpp11_noexcept.i b/Examples/test-suite/cpp11_noexcept.i new file mode 100644 index 000000000..27476fa70 --- /dev/null +++ b/Examples/test-suite/cpp11_noexcept.i @@ -0,0 +1,48 @@ +%module cpp11_noexcept + +%ignore NoExceptClass(NoExceptClass&&); +%rename(Assignment) NoExceptClass::operator=; + +%inline %{ + +extern "C" void global_noexcept(int, bool) noexcept; + +struct NoExceptClass { + static const bool VeryTrue = true; + + NoExceptClass() noexcept {} + NoExceptClass(const NoExceptClass&) noexcept {} + NoExceptClass(NoExceptClass&&) noexcept {} + NoExceptClass& operator=(const NoExceptClass&) noexcept {} + ~NoExceptClass() noexcept {} + + void noex0() noexcept {} + void noex1() noexcept(sizeof(int) == 4) {} + void noex2() noexcept(true) {} + void noex3() noexcept(false) {} + void noex4() noexcept(VeryTrue) {} + + template void template_noexcept(T) noexcept {} + + void noo1() const noexcept {} + static void noo2() noexcept {} + virtual void noo3() const noexcept {} + virtual void noo4() const noexcept = delete; + virtual void noo5() const throw() = delete; +}; + +struct NoExceptAbstract { + virtual void noo4() const noexcept = 0; + virtual ~NoExceptAbstract() noexcept = 0; +}; + +struct NoExceptDefaultDelete { +// NoExceptDefaultDelete() noexcept = default; +// NoExceptDefaultDelete(const NoExceptDefaultDelete&) noexcept = delete; + NoExceptDefaultDelete(NoExceptDefaultDelete&&) = delete; + NoExceptDefaultDelete& operator=(const NoExceptDefaultDelete&) = delete; + ~NoExceptDefaultDelete() noexcept = default; +}; + +%} + diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index 8b484f8a7..c04ce4688 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -705,6 +705,8 @@ int yylex(void) { } if (strcmp(yytext, "throw") == 0) return (THROW); + if (strcmp(yytext, "noexcept") == 0) + return (NOEXCEPT); if (strcmp(yytext, "try") == 0) return (yylex()); if (strcmp(yytext, "catch") == 0) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 1328d6e0d..bb1b5c1cc 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1669,6 +1669,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { String *bitfield; Parm *throws; String *throwf; + String *nexcept; } dtype; struct { char *type; @@ -1683,6 +1684,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { short have_parms; ParmList *throws; String *throwf; + String *nexcept; } decl; Parm *tparms; struct { @@ -1716,7 +1718,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %token ILLEGAL CONSTANT %token NAME RENAME NAMEWARN EXTEND PRAGMA FEATURE VARARGS %token ENUM -%token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT AUTO +%token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT AUTO NOEXCEPT %token STATIC_ASSERT CONSTEXPR THREAD_LOCAL DECLTYPE /* C++11 keywords */ %token USING %token NAMESPACE @@ -1771,7 +1773,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type kwargs options; /* Misc */ -%type initializer cpp_const ; +%type initializer cpp_const exception_specification; %type storage_class; %type parms ptail rawparms varargs_parms ; %type templateparameters templateparameterstail; @@ -3234,6 +3236,7 @@ c_decl : storage_class type declarator initializer c_decl_tail { Setattr($$,"value",$4.val); Setattr($$,"throws",$4.throws); Setattr($$,"throw",$4.throwf); + Setattr($$,"noexcept",$4.nexcept); if (!$5) { if (Len(scanner_ccode)) { String *code = Copy(scanner_ccode); @@ -3293,6 +3296,7 @@ c_decl : storage_class type declarator initializer c_decl_tail { Setattr($$,"value",$6.val); Setattr($$,"throws",$6.throws); Setattr($$,"throw",$6.throwf); + Setattr($$,"noexcept",$6.nexcept); if (!$7) { if (Len(scanner_ccode)) { String *code = Copy(scanner_ccode); @@ -3352,6 +3356,7 @@ c_decl_tail : SEMI { Setattr($$,"value",$3.val); Setattr($$,"throws",$3.throws); Setattr($$,"throw",$3.throwf); + Setattr($$,"noexcept",$3.nexcept); if ($3.bitfield) { Setattr($$,"bitfield", $3.bitfield); } @@ -3376,24 +3381,28 @@ initializer : def_args { $$.qualifier = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } | type_qualifier def_args { $$ = $2; $$.qualifier = $1; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } - | THROW LPAREN parms RPAREN def_args { - $$ = $5; + | exception_specification def_args { + $$ = $2; $$.qualifier = 0; - $$.throws = $3; - $$.throwf = NewString("1"); + $$.throws = $1.throws; + $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } - | type_qualifier THROW LPAREN parms RPAREN def_args { - $$ = $6; + | type_qualifier exception_specification def_args { + $$ = $3; $$.qualifier = $1; - $$.throws = $4; - $$.throwf = NewString("1"); + $$.throws = $2.throws; + $$.throwf = $2.throwf; + $$.nexcept = $2.nexcept; } ; @@ -3669,6 +3678,7 @@ c_constructor_decl : storage_class type LPAREN parms RPAREN ctor_end { } Setattr($$,"throws",$6.throws); Setattr($$,"throw",$6.throwf); + Setattr($$,"noexcept",$6.nexcept); err = 0; } } @@ -4698,6 +4708,7 @@ cpp_constructor_decl : storage_class type LPAREN parms RPAREN ctor_end { Setattr($$,"decl",decl); Setattr($$,"throws",$6.throws); Setattr($$,"throw",$6.throwf); + Setattr($$,"noexcept",$6.nexcept); if (Len(scanner_ccode)) { String *code = Copy(scanner_ccode); Setattr($$,"code",code); @@ -4733,6 +4744,7 @@ cpp_destructor_decl : NOT idtemplate LPAREN parms RPAREN cpp_end { } Setattr($$,"throws",$6.throws); Setattr($$,"throw",$6.throwf); + Setattr($$,"noexcept",$6.nexcept); if ($6.val) Setattr($$,"value",$6.val); add_symbols($$); @@ -4750,6 +4762,7 @@ cpp_destructor_decl : NOT idtemplate LPAREN parms RPAREN cpp_end { Delete(name); Setattr($$,"throws",$7.throws); Setattr($$,"throw",$7.throwf); + Setattr($$,"noexcept",$7.nexcept); if ($7.val) Setattr($$,"value",$7.val); if (Len(scanner_ccode)) { @@ -4996,18 +5009,21 @@ cpp_end : cpp_const SEMI { $$.val = 0; $$.throws = $1.throws; $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } | cpp_const EQUAL default_delete SEMI { Clear(scanner_ccode); $$.val = $3.val; $$.throws = $1.throws; $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } | cpp_const LBRACE { skip_balanced('{','}'); $$.val = 0; $$.throws = $1.throws; $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } ; @@ -5018,6 +5034,7 @@ cpp_vend : cpp_const SEMI { $$.bitfield = 0; $$.throws = $1.throws; $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } | cpp_const EQUAL definetype SEMI { Clear(scanner_ccode); @@ -5026,6 +5043,7 @@ cpp_vend : cpp_const SEMI { $$.bitfield = 0; $$.throws = $1.throws; $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } | cpp_const LBRACE { skip_balanced('{','}'); @@ -5034,6 +5052,7 @@ cpp_vend : cpp_const SEMI { $$.bitfield = 0; $$.throws = $1.throws; $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } ; @@ -5085,6 +5104,7 @@ storage_class : EXTERN { $$ = "extern"; } | FRIEND { $$ = "friend"; } | EXPLICIT { $$ = "explicit"; } | CONSTEXPR { $$ = "constexpr"; } + | STATIC CONSTEXPR { $$ = "static constexpr"; } | THREAD_LOCAL { $$ = "thread_local"; } | THREAD_LOCAL STATIC { $$ = "static thread_local"; } | STATIC THREAD_LOCAL { $$ = "static thread_local"; } @@ -5222,6 +5242,7 @@ def_args : EQUAL definetype { $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } } | EQUAL definetype LBRACKET expr RBRACKET { @@ -5234,6 +5255,7 @@ def_args : EQUAL definetype { $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } else { $$.val = NewStringf("%s[%s]",$2.val,$4.val); } @@ -5246,6 +5268,7 @@ def_args : EQUAL definetype { $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } | COLON expr { $$.val = 0; @@ -5254,6 +5277,7 @@ def_args : EQUAL definetype { $$.bitfield = $2.val; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } | empty { $$.val = 0; @@ -5262,6 +5286,7 @@ def_args : EQUAL definetype { $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } ; @@ -6166,6 +6191,7 @@ definetype : { /* scanner_check_typedef(); */ } expr { $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; scanner_ignore_typedef(); } | default_delete { @@ -6179,6 +6205,7 @@ definetype : { /* scanner_check_typedef(); */ } expr { $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } */ ; @@ -6200,6 +6227,7 @@ deleted_definition : DELETE_KW { $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } ; @@ -6212,6 +6240,7 @@ explicit_default : DEFAULT { $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } ; @@ -6331,6 +6360,7 @@ valexpr : exprnum { $$ = $1; } $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } | WCHARCONST { $$.val = NewString($1); @@ -6343,6 +6373,7 @@ valexpr : exprnum { $$ = $1; } $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } /* grouping */ @@ -6668,25 +6699,43 @@ opt_virtual : VIRTUAL | empty ; -cpp_const : type_qualifier { - $$.qualifier = $1; - $$.throws = 0; - $$.throwf = 0; - } - | THROW LPAREN parms RPAREN { - $$.qualifier = 0; +exception_specification : THROW LPAREN parms RPAREN { $$.throws = $3; $$.throwf = NewString("1"); - } - | type_qualifier THROW LPAREN parms RPAREN { - $$.qualifier = $1; - $$.throws = $4; - $$.throwf = NewString("1"); - } - | empty { - $$.qualifier = 0; + $$.nexcept = 0; + } + | NOEXCEPT { $$.throws = 0; $$.throwf = 0; + $$.nexcept = NewString("true"); + } + + | NOEXCEPT LPAREN expr RPAREN { + $$.throws = 0; + $$.throwf = 0; + $$.nexcept = $3.val; + } + ; + +cpp_const : type_qualifier { + $$.throws = 0; + $$.throwf = 0; + $$.nexcept = 0; + $$.qualifier = $1; + } + | exception_specification { + $$ = $1; + $$.qualifier = 0; + } + | type_qualifier exception_specification { + $$ = $2; + $$.qualifier = $1; + } + | empty { + $$.throws = 0; + $$.throwf = 0; + $$.nexcept = 0; + $$.qualifier = 0; } ; @@ -6696,6 +6745,7 @@ ctor_end : cpp_const ctor_initializer SEMI { $$.defarg = 0; $$.throws = $1.throws; $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } | cpp_const ctor_initializer LBRACE { skip_balanced('{','}'); @@ -6703,6 +6753,7 @@ ctor_end : cpp_const ctor_initializer SEMI { $$.defarg = 0; $$.throws = $1.throws; $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } | LPAREN parms RPAREN SEMI { Clear(scanner_ccode); @@ -6711,6 +6762,7 @@ ctor_end : cpp_const ctor_initializer SEMI { $$.defarg = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } | LPAREN parms RPAREN LBRACE { skip_balanced('{','}'); @@ -6719,12 +6771,14 @@ ctor_end : cpp_const ctor_initializer SEMI { $$.defarg = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } | EQUAL definetype SEMI { $$.have_parms = 0; $$.defarg = $2.val; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } ; From 97a9f5896a00acaf0ad73d763a938d5783425228 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 21 Nov 2013 20:22:57 +0000 Subject: [PATCH 0784/1160] Show date in Travis builds --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 26758304f..70cbb2f27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,6 +33,7 @@ matrix: allow_failures: # None before_install: + - date -u - lsb_release -a - uname -a - sudo apt-get -qq update From fcd0480364ba932cf5e9eabb34c7c048f146e758 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 22 Nov 2013 00:12:33 +0000 Subject: [PATCH 0785/1160] Fix some cases of C++11 exception specifications on constructors with =default or =delete --- Examples/test-suite/cpp11_default_delete.i | 9 +++++++++ Examples/test-suite/cpp11_noexcept.i | 5 +++-- Source/CParse/parser.y | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/cpp11_default_delete.i b/Examples/test-suite/cpp11_default_delete.i index 49a677060..79c02cddc 100644 --- a/Examples/test-suite/cpp11_default_delete.i +++ b/Examples/test-suite/cpp11_default_delete.i @@ -69,4 +69,13 @@ struct moveonly { moveonly& operator=(moveonly&&) = default; ~moveonly() = default; }; + +struct ConstructorThrow { + ConstructorThrow() throw() = default; + ConstructorThrow(const ConstructorThrow&) throw() = delete; + ConstructorThrow(ConstructorThrow&&) throw() = delete; + ConstructorThrow& operator=(const ConstructorThrow&) throw() = delete; + ~ConstructorThrow() throw() = default; +}; + %} diff --git a/Examples/test-suite/cpp11_noexcept.i b/Examples/test-suite/cpp11_noexcept.i index 27476fa70..6fed5b8df 100644 --- a/Examples/test-suite/cpp11_noexcept.i +++ b/Examples/test-suite/cpp11_noexcept.i @@ -37,8 +37,9 @@ struct NoExceptAbstract { }; struct NoExceptDefaultDelete { -// NoExceptDefaultDelete() noexcept = default; -// NoExceptDefaultDelete(const NoExceptDefaultDelete&) noexcept = delete; + template NoExceptDefaultDelete(T) noexcept = delete; + NoExceptDefaultDelete() noexcept = default; + NoExceptDefaultDelete(const NoExceptDefaultDelete&) noexcept = delete; NoExceptDefaultDelete(NoExceptDefaultDelete&&) = delete; NoExceptDefaultDelete& operator=(const NoExceptDefaultDelete&) = delete; ~NoExceptDefaultDelete() noexcept = default; diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index bb1b5c1cc..caac88e4d 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -6780,6 +6780,13 @@ ctor_end : cpp_const ctor_initializer SEMI { $$.throwf = 0; $$.nexcept = 0; } + | exception_specification EQUAL default_delete SEMI { + $$.have_parms = 0; + $$.defarg = $3.val; + $$.throws = $1.throws; + $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; + } ; ctor_initializer : COLON mem_initializer_list From b63c4839fe60b8192809ef94d078ef07305144c5 Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Thu, 28 Nov 2013 07:32:23 +0000 Subject: [PATCH 0786/1160] Nested classes support Closes #89 Squash merge branch 'master' of https://github.com/wkalinin/swig into wkalinin-nested By Vladimir Kalinin * 'master' of https://github.com/wkalinin/swig: CPlusPlusOut mode for Octave nested class illustration fixed "Abstract" flag for nested classes added an example enabled anonymous nested structs runtime test porting warnings disabled porting fixes java runtime tests ported nested class closing bracket offset fixed removed double nested template (not supported by %template parsing) template_nested test extended parent field made public property access fixed replaced tabs with spaces warning W-reorder deprecated warnings removed, derived_nested runtime test added optimized string indenting Nested classes indenting nested classes docs fixed the order in which flattened inner classes are added after the outer Private nested classes were getting into the type table. Java getProxyName() fix for nested classes fixes the case when nested classes is forward declared Fix for a case when a nested class inherits from the same base as the outer. (Base class constructor declaration is found first in this case) merge fix nested C struct first immediate declaration incorrectly renamed sample fixed tests updated to reflect nested classes support Java nested classes support (1) flattening should remove the link to the outer class access mode correctly set/restored for nested classes nested templates should be skipped while flattening (template nodes themselves, not expanded versions) also non-public nested classes should be ignored If nested classes are not supported, default behaviour is flattening, not ignoring flag "nested" is preserved, so, the nested classes can be ignored by user nested workaround test updated template instantiated within a class is marked as nested for ignoring purposes %ignore not applied to the nested classed, because "nested" flag is set too late typedef name takes precedence over the real name (reason?) unnamed structs should be processed for all the languages nested C struct instances are wrapped as "immutable" tree building typedef declaration for unnamed C structures fixed nested classes "flattening" fixed %ignoring nested classes renamed "nested" attribute to "nested:outer" added "nested" flag, to be used with $ignore (it is not removed while flattening) added nestedClassesSupported() function to the Language interface renamed "nested" attribute to "nested:outer" added "nested" flag, to be used with $ignore (it is not removed while flattening) added nestedClassesSupported() function to the Language interface tree iteration fix dirclassname variable names unified memory issue fixed merge error ignore unnamed structs for C++ unnamed nested C structs naming & unnesting class added to classes hash under typedef name private nested classes skipped test updated due to nested templates support anonymous structs with inheritance fixed nested_class test to allow anonymous structs w/o declarator tests updated: nested workaround removed from namespace_class.i propagated nested template declaration to the C++ file injected members scope nested tempplates fixes, nested structures in "C" mode parsing added utility function "appendSibling" (like "appendChild") nested unnamed structures parsing fixes, access mode restored on nested class end, tdname is properly patched with outer class name prefix memory management fixes nested templates (1) Nested unnamed structs Nested class support (1) Nested class support (1) --- Doc/Manual/SWIGPlus.html | 144 +-- Examples/csharp/class/example.cxx | 2 +- Examples/csharp/class/example.h | 8 +- Examples/csharp/class/runme.cs | 6 +- Examples/java/class/example.cxx | 2 +- Examples/java/class/example.h | 8 +- Examples/java/class/runme.java | 6 +- Examples/test-suite/derived_nested.i | 10 +- .../test-suite/java/nested_class_runme.java | 62 +- .../test-suite/java/nested_structs_runme.java | 14 +- .../java/template_nested_runme.java | 4 + Examples/test-suite/namespace_class.i | 10 - Examples/test-suite/namespace_union.i | 2 - Examples/test-suite/nested_class.i | 24 +- Examples/test-suite/nested_comment.i | 2 - Examples/test-suite/nested_workaround.i | 20 +- Examples/test-suite/template_nested.i | 19 +- .../test-suite/template_nested_typemaps.i | 6 +- Examples/test-suite/union_scope.i | 1 - Lib/swig.swg | 2 +- Source/CParse/cparse.h | 1 + Source/CParse/cscanner.c | 4 + Source/CParse/parser.y | 960 +++++------------- Source/Include/swigwarn.h | 2 - Source/Modules/allocate.cxx | 6 +- Source/Modules/contract.cxx | 6 +- Source/Modules/csharp.cxx | 231 +++-- Source/Modules/java.cxx | 196 ++-- Source/Modules/lang.cxx | 95 +- Source/Modules/main.cxx | 45 +- Source/Modules/octave.cxx | 1 + Source/Modules/swigmod.h | 13 + Source/Modules/typepass.cxx | 457 ++++++++- Source/Swig/naming.c | 65 ++ Source/Swig/scanner.c | 103 ++ Source/Swig/swig.h | 2 + Source/Swig/swigscan.h | 1 + Source/Swig/swigtree.h | 1 + Source/Swig/tree.c | 19 + 39 files changed, 1449 insertions(+), 1111 deletions(-) diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index 2713725d7..2ec98f33a 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -185,7 +185,6 @@ The following C++ features are not currently supported:

      • Overloaded versions of certain operators (new, delete, etc.) -
      • Nested classes, see Nested classes for workarounds.

      @@ -4965,143 +4964,40 @@ public:

      6.27 Nested classes

      -

      -There is some support for nested structs and unions when wrapping C code, -see Nested structures for further details. -The added complexity of C++ compared to C means this approach does not work well for -C++ code (when using the -c++ command line option). -For C++, a nested class is treated much like an opaque pointer, so anything useful within the nested class, such as its -methods and variables, are not accessible from the target language. -True nested class support may be added to SWIG in the future, however, -until then some of the following workarounds can be applied to improve the situation. +If the target language supports the nested classes concept (like Java), the nested C++ classes +are wrapped as nested target language proxy classes. (In case of Java - "static" nested classes.) +Only public nested classes are wrapped. Otherwise there is little difference between nested and +normal classes.

      -

      -It might be possible to use partial class information as often you can accept that the nested class is not needed, -especially if it is not actually used in any methods you need from the target language. -Imagine you are wrapping the following Outer class which contains a nested class Inner. -The easiest thing to do is turn a blind eye to the warning that SWIG generates, or simply suppress it: +If the target language doesn't support nested classes directly, or the support is not implemented in the +language module (like for python currently), then the visible nested classes are moved to the same name +space as the containing class (nesting hierarchy is "flattened"). The same behaviour may be turned on for +C# and Java by the %feature ("flatnested"); If there is a class with the same name in the outer namespace +the inner class (or the global one) may be renamed or ignored:

      -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::Inner;
      -
      -class Outer {
      -public:
      -  class Inner {
      -    public:
      -      ...
      -  };
      -  Inner getInner();
      -  void useInner(const Inner& inner);
      -  ...
      -};
      -
      -
      - -

      -Note that if Inner can be used as an opaque type, the default wrapping approach suffices. -For example, if the nested class does not need to be created from the target language, but can be obtained via a method -call, such as the getInner() method above, the returned value can then be passed around, such as passed into the -useInner() method. -

      - -

      -With some more effort the above situation can be improved somewhat and a nested class can be constructed and used -from the target language much like any other non-nested class. Assuming we have the Outer class in a header file: -

      - -
      -
      -// File outer.h
      -class Outer {
      -public:
      -  class Inner {
      -    public:
      -      int var;
      -      Inner(int v = 0) : var(v) {}
      -  };
      -  Inner getInner();
      -  void useInner(const Inner& inner);
      -};
      -
      -
      - -

      -The following interface file works around the nested class limitations by redefining the nested class as a global class. -A typedef for the compiler and the nestedworkaround -feature flag is also required in -order for the generated wrappers to compile. This flag simply removes all the type information from SWIG, so SWIG treats -the nested class as if it had not been parsed at all. -

      - -
      -
      -// File : example.i
      -%module example
      -
      -// Redefine nested class in global scope in order for SWIG to generate
      -// a proxy class. Only SWIG parses this definition.
      -class Inner {
      +%rename (Bar_Foo) Bar::Foo;
      +class Foo {};
      +class Bar {
         public:
      -    int var;
      -    Inner(int v = 0) : var(v) {}
      -};
      -
      -%nestedworkaround Outer::Inner;
      -
      -%{
      -#include "outer.h"
      -%}
      -%include "outer.h"
      -
      -// We've fooled SWIG into thinking that Inner is a global class, so now we need
      -// to trick the C++ compiler into understanding this apparent global type.
      -%{
      -typedef Outer::Inner Inner;
      -%}
      -
      -
      - -

      -The downside to this approach is a more complex interface file and having to maintain two definitions of Inner, -the real one and the one in the interface file that SWIG parses. -However, the upside is that all the methods/variables in the nested class are available from the target language -as a proxy class is generated instead of treating the nested class as an opaque type. -The proxy class can be constructed from the target language and passed into any methods accepting the nested class. -Also note that the original header file is parsed unmodified. -

      - -

      -Finally, conditional compilation can be used as a workaround to comment out nested class definitions in the actual headers, -assuming you are able to modify them. -

      - -
      -
      -// File outer.h
      -class Outer {
      -public:
      -#ifndef SWIG
      -  class Inner {
      -    public:
      -      ...
      -  };
      -#endif
      -  ...
      +  class Foo {};
       };
       
      -

      -This workaround used to be common when SWIG could not deal with nested classes particulary well. -This should just be a last resort for unusual corner cases now as SWIG can parse nested classes and even handle nested template classes fairly well. -

      -Compatibility Note: SWIG-1.3.40 and earlier versions did not have the nestedworkaround feature +Compatibility Note: +In SWIG 2.0 and earlier, nested classes were treated as opaque pointers. +Also there was a workaround, implementing approximately the same behaviour as the +%feature ("flatnested") with an additional help from the user: +nested class had to be manually redeclared in the global scope, typedef name and %feature nestedworkaround +added for the inner class. +SWIG-1.3.40 and earlier versions did not have the nestedworkaround feature and the generated code resulting from parsing nested classes did not always compile. Nested class warnings could also not be suppressed using %warnfilter.

      diff --git a/Examples/csharp/class/example.cxx b/Examples/csharp/class/example.cxx index 1e8e203dd..9b23ea4e6 100644 --- a/Examples/csharp/class/example.cxx +++ b/Examples/csharp/class/example.cxx @@ -9,7 +9,7 @@ void Shape::move(double dx, double dy) { y += dy; } -int Shape::nshapes = 0; +int Shape::Counter::nshapes = 0; double Circle::area(void) { return M_PI*radius*radius; diff --git a/Examples/csharp/class/example.h b/Examples/csharp/class/example.h index 46d901361..430cf47dc 100644 --- a/Examples/csharp/class/example.h +++ b/Examples/csharp/class/example.h @@ -2,17 +2,19 @@ class Shape { public: + struct Counter{ + static int nshapes; + }; Shape() { - nshapes++; + Counter::nshapes++; } virtual ~Shape() { - nshapes--; + Counter::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 { diff --git a/Examples/csharp/class/runme.cs b/Examples/csharp/class/runme.cs index 9088031d6..2b500da5c 100644 --- a/Examples/csharp/class/runme.cs +++ b/Examples/csharp/class/runme.cs @@ -17,9 +17,9 @@ public class runme Console.WriteLine( " Created circle " + c ); Console.WriteLine( " Created square " + s ); - // ----- Access a static member ----- + // ----- Access a static member of a nested class ----- - Console.WriteLine( "\nA total of " + Shape.nshapes + " shapes were created" ); + Console.WriteLine( "\nA total of " + Shape.Counter.nshapes + " shapes were created" ); // ----- Member data access ----- @@ -60,7 +60,7 @@ public class runme // Note: when this using scope is exited the C# Dispose() methods // are called which in turn call the C++ destructors - Console.WriteLine( Shape.nshapes + " shapes remain" ); + Console.WriteLine( Shape.Counter.nshapes + " shapes remain" ); Console.WriteLine( "Goodbye" ); } } diff --git a/Examples/java/class/example.cxx b/Examples/java/class/example.cxx index 1e8e203dd..9b23ea4e6 100644 --- a/Examples/java/class/example.cxx +++ b/Examples/java/class/example.cxx @@ -9,7 +9,7 @@ void Shape::move(double dx, double dy) { y += dy; } -int Shape::nshapes = 0; +int Shape::Counter::nshapes = 0; double Circle::area(void) { return M_PI*radius*radius; diff --git a/Examples/java/class/example.h b/Examples/java/class/example.h index 46d901361..430cf47dc 100644 --- a/Examples/java/class/example.h +++ b/Examples/java/class/example.h @@ -2,17 +2,19 @@ class Shape { public: + struct Counter{ + static int nshapes; + }; Shape() { - nshapes++; + Counter::nshapes++; } virtual ~Shape() { - nshapes--; + Counter::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 { diff --git a/Examples/java/class/runme.java b/Examples/java/class/runme.java index e1ea0d71c..90844ba23 100644 --- a/Examples/java/class/runme.java +++ b/Examples/java/class/runme.java @@ -21,9 +21,9 @@ public class runme { Square s = new Square(10); System.out.println( " Created square " + s ); - // ----- Access a static member ----- + // ----- Access a static member of a nested class ----- - System.out.println( "\nA total of " + Shape.getNshapes() + " shapes were created" ); + System.out.println( "\nA total of " + Shape.Counter.getNshapes() + " shapes were created" ); // ----- Member data access ----- @@ -64,7 +64,7 @@ public class runme { c.delete(); s.delete(); - System.out.println( Shape.getNshapes() + " shapes remain" ); + System.out.println( Shape.Counter.getNshapes() + " shapes remain" ); System.out.println( "Goodbye" ); } } diff --git a/Examples/test-suite/derived_nested.i b/Examples/test-suite/derived_nested.i index 29114d5a0..e374cf70f 100644 --- a/Examples/test-suite/derived_nested.i +++ b/Examples/test-suite/derived_nested.i @@ -3,14 +3,12 @@ This was reported in bug #909389 */ %module derived_nested -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::CC; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::DD; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::EE; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::FF; - %inline %{ -class A { int x; }; +class A { +public: + int x; +}; class B { class C { int y; }; //generates a warning class D : public A { int z; }; //ok diff --git a/Examples/test-suite/java/nested_class_runme.java b/Examples/test-suite/java/nested_class_runme.java index f1c67a0af..f75613e65 100644 --- a/Examples/test-suite/java/nested_class_runme.java +++ b/Examples/test-suite/java/nested_class_runme.java @@ -14,59 +14,59 @@ public class nested_class_runme { public static void main(String argv[]) { Outer outer = new Outer(); - SWIGTYPE_p_Outer__InnerStruct1 is1 = outer.makeInnerStruct1(); - SWIGTYPE_p_Outer__InnerClass1 ic1 = outer.makeInnerClass1(); - SWIGTYPE_p_Outer__InnerUnion1 iu1 = outer.makeInnerUnion1(); + Outer.InnerStruct1 is1 = outer.makeInnerStruct1(); + Outer.InnerClass1 ic1 = outer.makeInnerClass1(); + Outer.InnerUnion1 iu1 = outer.makeInnerUnion1(); - SWIGTYPE_p_Outer__InnerStruct2 is2 = outer.makeInnerStruct2(); - SWIGTYPE_p_Outer__InnerClass2 ic2 = outer.makeInnerClass2(); - SWIGTYPE_p_Outer__InnerUnion2 iu2 = outer.makeInnerUnion2(); + Outer.InnerStruct2 is2 = outer.makeInnerStruct2(); + Outer.InnerClass2 ic2 = outer.makeInnerClass2(); + Outer.InnerUnion2 iu2 = outer.makeInnerUnion2(); - SWIGTYPE_p_Outer__InnerClass4Typedef ic4 = outer.makeInnerClass4Typedef(); - SWIGTYPE_p_Outer__InnerStruct4Typedef is4 = outer.makeInnerStruct4Typedef(); - SWIGTYPE_p_Outer__InnerUnion4Typedef iu4 = outer.makeInnerUnion4Typedef(); + Outer.InnerClass4Typedef ic4 = outer.makeInnerClass4Typedef(); + Outer.InnerStruct4Typedef is4 = outer.makeInnerStruct4Typedef(); + Outer.InnerUnion4Typedef iu4 = outer.makeInnerUnion4Typedef(); - SWIGTYPE_p_Outer__InnerClass5 ic5 = outer.makeInnerClass5(); - SWIGTYPE_p_Outer__InnerStruct5 is5 = outer.makeInnerStruct5(); - SWIGTYPE_p_Outer__InnerUnion5 iu5 = outer.makeInnerUnion5(); + Outer.InnerClass5Typedef ic5 = outer.makeInnerClass5(); + Outer.InnerStruct5Typedef is5 = outer.makeInnerStruct5(); + Outer.InnerUnion5Typedef iu5 = outer.makeInnerUnion5(); ic5 = outer.makeInnerClass5Typedef(); is5 = outer.makeInnerStruct5Typedef(); iu5 = outer.makeInnerUnion5Typedef(); { - SWIGTYPE_p_Outer__InnerMultiple im1 = outer.getMultipleInstance1(); - SWIGTYPE_p_Outer__InnerMultiple im2 = outer.getMultipleInstance2(); - SWIGTYPE_p_Outer__InnerMultiple im3 = outer.getMultipleInstance3(); - SWIGTYPE_p_Outer__InnerMultiple im4 = outer.getMultipleInstance4(); + Outer.InnerMultiple im1 = outer.getMultipleInstance1(); + Outer.InnerMultiple im2 = outer.getMultipleInstance2(); + Outer.InnerMultiple im3 = outer.getMultipleInstance3(); + Outer.InnerMultiple im4 = outer.getMultipleInstance4(); } { - SWIGTYPE_p_Outer__InnerMultipleDerived im1 = outer.getMultipleDerivedInstance1(); - SWIGTYPE_p_Outer__InnerMultipleDerived im2 = outer.getMultipleDerivedInstance2(); - SWIGTYPE_p_Outer__InnerMultipleDerived im3 = outer.getMultipleDerivedInstance3(); - SWIGTYPE_p_Outer__InnerMultipleDerived im4 = outer.getMultipleDerivedInstance4(); + Outer.InnerMultipleDerived im1 = outer.getMultipleDerivedInstance1(); + Outer.InnerMultipleDerived im2 = outer.getMultipleDerivedInstance2(); + Outer.InnerMultipleDerived im3 = outer.getMultipleDerivedInstance3(); + Outer.InnerMultipleDerived im4 = outer.getMultipleDerivedInstance4(); } { - SWIGTYPE_p_Outer__InnerMultipleDerived im1 = outer.getMultipleDerivedInstance1(); - SWIGTYPE_p_Outer__InnerMultipleDerived im2 = outer.getMultipleDerivedInstance2(); - SWIGTYPE_p_Outer__InnerMultipleDerived im3 = outer.getMultipleDerivedInstance3(); - SWIGTYPE_p_Outer__InnerMultipleDerived im4 = outer.getMultipleDerivedInstance4(); + Outer.InnerMultipleDerived im1 = outer.getMultipleDerivedInstance1(); + Outer.InnerMultipleDerived im2 = outer.getMultipleDerivedInstance2(); + Outer.InnerMultipleDerived im3 = outer.getMultipleDerivedInstance3(); + Outer.InnerMultipleDerived im4 = outer.getMultipleDerivedInstance4(); } { - SWIGTYPE_p_Outer__InnerMultipleAnonTypedef1 mat1 = outer.makeInnerMultipleAnonTypedef1(); - SWIGTYPE_p_Outer__InnerMultipleAnonTypedef2 mat2 = outer.makeInnerMultipleAnonTypedef2(); - SWIGTYPE_p_Outer__InnerMultipleAnonTypedef3 mat3 = outer.makeInnerMultipleAnonTypedef3(); + Outer.InnerMultipleAnonTypedef1 mat1 = outer.makeInnerMultipleAnonTypedef1(); + Outer.InnerMultipleAnonTypedef1 mat2 = outer.makeInnerMultipleAnonTypedef2(); + SWIGTYPE_p_p_Outer__InnerMultipleAnonTypedef1 mat3 = outer.makeInnerMultipleAnonTypedef3(); - SWIGTYPE_p_Outer__InnerMultipleNamedTypedef mnt = outer.makeInnerMultipleNamedTypedef(); - SWIGTYPE_p_Outer__InnerMultipleNamedTypedef mnt1 = outer.makeInnerMultipleNamedTypedef1(); - SWIGTYPE_p_Outer__InnerMultipleNamedTypedef mnt2 = outer.makeInnerMultipleNamedTypedef2(); + Outer.InnerMultipleNamedTypedef1 mnt = outer.makeInnerMultipleNamedTypedef(); + Outer.InnerMultipleNamedTypedef1 mnt1 = outer.makeInnerMultipleNamedTypedef1(); + Outer.InnerMultipleNamedTypedef1 mnt2 = outer.makeInnerMultipleNamedTypedef2(); SWIGTYPE_p_p_Outer__InnerMultipleNamedTypedef mnt3 = outer.makeInnerMultipleNamedTypedef3(); } { - SWIGTYPE_p_Outer__InnerSameName isn = outer.makeInnerSameName(); + Outer.InnerSameName isn = outer.makeInnerSameName(); } } } diff --git a/Examples/test-suite/java/nested_structs_runme.java b/Examples/test-suite/java/nested_structs_runme.java index 6e103cd12..4b713395a 100644 --- a/Examples/test-suite/java/nested_structs_runme.java +++ b/Examples/test-suite/java/nested_structs_runme.java @@ -17,18 +17,18 @@ public class nested_structs_runme { nested_structs.setValues(outer, 10); Outer_inner1 inner1 = outer.getInner1(); - Outer_inner2 inner2 = outer.getInner2(); - Outer_inner3 inner3 = outer.getInner3(); - Outer_inner4 inner4 = outer.getInner4(); + Outer_inner1 inner2 = outer.getInner2(); + Outer_inner1 inner3 = outer.getInner3(); + Outer_inner1 inner4 = outer.getInner4(); if (inner1.getVal() != 10) throw new RuntimeException("failed inner1"); if (inner2.getVal() != 20) throw new RuntimeException("failed inner2"); if (inner3.getVal() != 20) throw new RuntimeException("failed inner3"); if (inner4.getVal() != 40) throw new RuntimeException("failed inner4"); - Outer_inside1 inside1 = outer.getInside1(); - Outer_inside2 inside2 = outer.getInside2(); - Outer_inside3 inside3 = outer.getInside3(); - Outer_inside4 inside4 = outer.getInside4(); + Named inside1 = outer.getInside1(); + Named inside2 = outer.getInside2(); + Named inside3 = outer.getInside3(); + Named inside4 = outer.getInside4(); if (inside1.getVal() != 100) throw new RuntimeException("failed inside1"); if (inside2.getVal() != 200) throw new RuntimeException("failed inside2"); if (inside3.getVal() != 200) throw new RuntimeException("failed inside3"); diff --git a/Examples/test-suite/java/template_nested_runme.java b/Examples/test-suite/java/template_nested_runme.java index 407821674..422e7ea9e 100644 --- a/Examples/test-suite/java/template_nested_runme.java +++ b/Examples/test-suite/java/template_nested_runme.java @@ -25,6 +25,10 @@ public class template_nested_runme { T_NestedOuterTemplateDouble tn = new T_NestedOuterTemplateDouble(); if (tn.hohum(-12.3) != -12.3) throw new RuntimeException("it failed"); + OuterClass.T_OuterClassInner1Int inner1 = new OuterClass().useInner1(new OuterClass.T_OuterClassInner1Int()); + OuterClass.T_OuterClassInner2NormalClass inner2 = new OuterClass.T_OuterClassInner2NormalClass(); + inner2.setEmbeddedVar(2); + OuterClass.T_OuterClassInner2NormalClass inner22 = new OuterClass().useInner2Again(inner2); } } diff --git a/Examples/test-suite/namespace_class.i b/Examples/test-suite/namespace_class.i index aea5362d1..113bbeb35 100644 --- a/Examples/test-suite/namespace_class.i +++ b/Examples/test-suite/namespace_class.i @@ -1,6 +1,5 @@ %module namespace_class -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Ala::Ola; #ifdef SWIGD %warnfilter(SWIGWARN_IGNORE_OPERATOR_LT); @@ -216,9 +215,6 @@ namespace a %} -// %copyctor doesn't work with nested class workaround -%nocopyctor; - %inline %{ class Ala { public : @@ -236,12 +232,6 @@ namespace a }; %} -%rename(Ala__Ola) Ala::Ola; -class Ala::Ola { -public: - Ola() {} - void eek() {} -}; %template(hi) Ala::hi; diff --git a/Examples/test-suite/namespace_union.i b/Examples/test-suite/namespace_union.i index 85885f399..84e38b4d5 100644 --- a/Examples/test-suite/namespace_union.i +++ b/Examples/test-suite/namespace_union.i @@ -1,7 +1,5 @@ %module namespace_union -#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS - %inline %{ namespace SpatialIndex { diff --git a/Examples/test-suite/nested_class.i b/Examples/test-suite/nested_class.i index d67440ac9..0d418192d 100644 --- a/Examples/test-suite/nested_class.i +++ b/Examples/test-suite/nested_class.i @@ -1,25 +1,5 @@ %module nested_class -#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct1; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass1; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion1; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass2; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct2; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion2; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass4Typedef; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct4Typedef; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion4Typedef; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass5; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct5; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion5; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultiple; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleDerived; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleAnonTypedef1; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleNamedTypedef; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerSameName; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer2::IgnoreMe; - %inline %{ struct Outer { typedef int Integer; @@ -39,7 +19,7 @@ struct Outer { }; /////////////////////////////////////////// -#ifdef SWIG +#if defined(__GNUC__) || defined(_MSC_VER) || defined(SWIG) /* some compilers do not accept these */ class { public: @@ -154,7 +134,7 @@ struct Outer { Integer xx; } MultipleInstanceAnonDerived1, MultipleInstanceAnonDerived2, *MultipleInstanceAnonDerived3, MultipleInstanceAnonDerived4[2]; -#ifdef SWIG +#if defined(__GNUC__) || defined(_MSC_VER) || defined(SWIG) /* some compilers do not accept these */ struct : public InnerMultiple { Integer xx; diff --git a/Examples/test-suite/nested_comment.i b/Examples/test-suite/nested_comment.i index 99d0ffb43..df160b157 100644 --- a/Examples/test-suite/nested_comment.i +++ b/Examples/test-suite/nested_comment.i @@ -1,7 +1,5 @@ %module nested_comment -#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS - // this example shows a problem with 'dump_nested' (parser.y). // bug #949654 diff --git a/Examples/test-suite/nested_workaround.i b/Examples/test-suite/nested_workaround.i index 9727dacee..bb69a5bbd 100644 --- a/Examples/test-suite/nested_workaround.i +++ b/Examples/test-suite/nested_workaround.i @@ -1,14 +1,6 @@ %module nested_workaround -// Similar to "Nested classes" documentation example. - -class Inner { - int val; - public: - Inner(int v = 0) : val(v) {} - void setValue(int v) { val = v; } - int getValue() const { return val; } -}; -%nestedworkaround Outer::Inner; +// "flatnested" emulates deprecated feature "nested_workaround" for the languages not supporting nested classes +%feature ("flatnested"); %inline %{ class Outer { @@ -28,11 +20,3 @@ public: } }; %} - -// We've fooled SWIG into thinking that Inner is a global class, so now we need -// to trick the C++ compiler into understanding this apparent global type. -%{ -typedef Outer::Inner Inner; -%} - - diff --git a/Examples/test-suite/template_nested.i b/Examples/test-suite/template_nested.i index 1bb1c686a..bbca9502c 100644 --- a/Examples/test-suite/template_nested.i +++ b/Examples/test-suite/template_nested.i @@ -2,13 +2,6 @@ // Test nested templates - that is template classes and template methods within a class. -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterClass::Inner1; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterClass::Inner2; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate1; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate2; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate3; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedStruct; - namespace ns { template struct ForwardTemplate; } @@ -33,7 +26,13 @@ namespace ns { template struct NormalTemplate { void tmethod(T t) {} }; +} +%} +%template(T_NormalTemplateNormalClass) ns::NormalTemplate; +%template(T_NormalTemplateInt) ns::NormalTemplate; +%inline %{ +namespace ns { class OuterClass { public: template struct Inner1 { @@ -70,6 +69,7 @@ namespace ns { }; }; Inner2 useInner2(const Inner2& inner) { return inner; } + Inner2 useInner2Again(const Inner2& inner) { return inner; } int iii; }; struct ABC { @@ -108,9 +108,10 @@ namespace ns { %} -%template(T_NormalTemplateNormalClass) ns::NormalTemplate; %template(T_OuterTMethodNormalClass) ns::OuterClass::InnerTMethod; %template(T_TemplateFuncs1Int) ns::TemplateFuncs::templateMethod1; %template(T_TemplateFuncs2Double) ns::TemplateFuncs::templateMethod2; %template(T_NestedOuterTemplateDouble) ns::OuterTemplate; - +%template(T_OuterClassInner1Int) ns::OuterClass::Inner1; +%template(T_OuterClassInner2NormalClass) ns::OuterClass::Inner2; +%template(T_OuterClassInner2Int) ns::OuterClass::Inner2; diff --git a/Examples/test-suite/template_nested_typemaps.i b/Examples/test-suite/template_nested_typemaps.i index 54f5bc503..b40e7e291 100644 --- a/Examples/test-suite/template_nested_typemaps.i +++ b/Examples/test-suite/template_nested_typemaps.i @@ -4,18 +4,22 @@ // Testing that the typemaps invoked within a class via %template are picked up by appropriate methods +%inline %{ template struct Typemap { +#ifdef SWIG %typemap(in) T { $1 = -99; } +#endif }; template <> struct Typemap { // Note explicit specialization +#ifdef SWIG %typemap(in) short { $1 = -77; } +#endif }; -%inline %{ int globalInt1(int s) { return s; } short globalShort1(short s) { return s; } diff --git a/Examples/test-suite/union_scope.i b/Examples/test-suite/union_scope.i index b7307cb29..67093eff6 100644 --- a/Examples/test-suite/union_scope.i +++ b/Examples/test-suite/union_scope.i @@ -2,7 +2,6 @@ %warnfilter(SWIGWARN_RUBY_WRONG_NAME) nRState; // Ruby, wrong class name %warnfilter(SWIGWARN_RUBY_WRONG_NAME) nRState_rstate; // Ruby, wrong class name -#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS %inline %{ class nRState { diff --git a/Lib/swig.swg b/Lib/swig.swg index ad6b7b64b..a63169b3e 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -302,7 +302,7 @@ static int NAME(TYPE x) { %define %$ismemberset "match$memberset"="1" %enddef %define %$classname %$ismember,"match$parentNode$name" %enddef - +%define %$isnested "match$nested"="1" %enddef /* ----------------------------------------------------------------------------- * Include all the warnings labels and macros * ----------------------------------------------------------------------------- */ diff --git a/Source/CParse/cparse.h b/Source/CParse/cparse.h index 922bbfcdc..19bf3f3f0 100644 --- a/Source/CParse/cparse.h +++ b/Source/CParse/cparse.h @@ -31,6 +31,7 @@ extern "C" { extern void scanner_file(File *); extern void scanner_next_token(int); extern void skip_balanced(int startchar, int endchar); + extern String *get_raw_text_balanced(int startchar, int endchar); extern void skip_decl(void); extern void scanner_check_typedef(void); extern void scanner_ignore_typedef(void); diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index c04ce4688..68b305c90 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -118,6 +118,10 @@ void skip_balanced(int startchar, int endchar) { return; } +String* get_raw_text_balanced(int startchar, int endchar) { + return Scanner_get_raw_text_balanced(scan, startchar, endchar); +} + /* ---------------------------------------------------------------------------- * void skip_decl(void) * diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index caac88e4d..ef7eb81ba 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -51,7 +51,7 @@ static Node *module_node = 0; static String *Classprefix = 0; static String *Namespaceprefix = 0; static int inclass = 0; -static int nested_template = 0; /* template class/function definition within a class */ +static Node *currentOuterClass = 0; /*for nested classes*/ static char *last_cpptype = 0; static int inherit_list = 0; static Parm *template_parameters = 0; @@ -59,10 +59,7 @@ static int extendmode = 0; static int compact_default_args = 0; static int template_reduce = 0; static int cparse_externc = 0; - -static int max_class_levels = 0; -static int class_level = 0; -static Node **class_decl = NULL; +extern int CPlusPlusOut; /* ----------------------------------------------------------------------------- * Assist Functions @@ -165,7 +162,6 @@ static Node *copy_node(Node *n) { static char *typemap_lang = 0; /* Current language setting */ static int cplus_mode = 0; -static String *class_rename = 0; /* C++ modes */ @@ -237,6 +233,25 @@ static String *feature_identifier_fix(String *s) { } } +static void set_access_mode(Node* n) { + if (cplus_mode == CPLUS_PUBLIC) + Setattr(n, "access", "public"); + else if (cplus_mode == CPLUS_PROTECTED) + Setattr(n, "access", "protected"); + else + Setattr(n, "access", "private"); +} + +static void restore_access_mode(Node* n) { + char* mode = Char(Getattr(n, "access")); + if (strcmp(mode, "private") == 0) + cplus_mode = CPLUS_PRIVATE; + else if (strcmp(mode, "protected") == 0) + cplus_mode = CPLUS_PROTECTED; + else + cplus_mode = CPLUS_PUBLIC; +} + /* Generate the symbol table name for an object */ /* This is a bit of a mess. Need to clean up */ static String *add_oldname = 0; @@ -283,13 +298,6 @@ static void add_symbols(Node *n) { String *decl; String *wrn = 0; - if (nested_template) { - if (!(n && Equal(nodeType(n), "template"))) { - return; - } - /* continue if template function, but not template class, declared within a class */ - } - if (inclass && n) { cparse_normalize_void(n); } @@ -349,9 +357,6 @@ static void add_symbols(Node *n) { Delete(prefix); } - /* - if (!Getattr(n,"parentNode") && class_level) set_parentNode(n,class_decl[class_level - 1]); - */ Setattr(n,"ismember","1"); } } @@ -793,53 +798,31 @@ static String *make_class_name(String *name) { return nname; } -static List *make_inherit_list(String *clsname, List *names) { - int i, ilen; - String *derived; - List *bases = NewList(); - - if (Namespaceprefix) derived = NewStringf("%s::%s", Namespaceprefix,clsname); - else derived = NewString(clsname); - - ilen = Len(names); - for (i = 0; i < ilen; i++) { - Node *s; - String *base; - String *n = Getitem(names,i); - /* Try to figure out where this symbol is */ - s = Swig_symbol_clookup(n,0); - if (s) { - while (s && (Strcmp(nodeType(s),"class") != 0)) { - /* Not a class. Could be a typedef though. */ - String *storage = Getattr(s,"storage"); - if (storage && (Strcmp(storage,"typedef") == 0)) { - String *nn = Getattr(s,"type"); - s = Swig_symbol_clookup(nn,Getattr(s,"sym:symtab")); - } else { - break; - } - } - if (s && ((Strcmp(nodeType(s),"class") == 0) || (Strcmp(nodeType(s),"template") == 0))) { - String *q = Swig_symbol_qualified(s); - Append(bases,s); - if (q) { - base = NewStringf("%s::%s", q, Getattr(s,"name")); - Delete(q); - } else { - base = NewString(Getattr(s,"name")); - } - } else { - base = NewString(n); - } - } else { - base = NewString(n); - } - if (base) { - Swig_name_inherit(base,derived); - Delete(base); +/* Use typedef name as class name */ +void add_typedef_name(Node* n, Node* decl, String* oldName, Symtab *cscope, String* scpname) +{ + String* class_rename = 0; + SwigType *decltype = Getattr(decl,"decl"); + if (!decltype || !Len(decltype)) { + String *cname; + String *tdscopename; + String *class_scope = Swig_symbol_qualifiedscopename(cscope); + String *name = Getattr(decl,"name"); + cname = Copy(name); + Setattr(n,"tdname",cname); + tdscopename = class_scope ? NewStringf("%s::%s", class_scope, name) : Copy(name); + class_rename = Getattr(n, "class_rename"); + if (class_rename && (Strcmp(class_rename,oldName) == 0)) + Setattr(n, "class_rename", NewString(name)); + if (!classes_typedefs) classes_typedefs = NewHash(); + if (!Equal(scpname, tdscopename) && !Getattr(classes_typedefs, tdscopename)) { + Setattr(classes_typedefs, tdscopename, n); } + Setattr(n,"decl",decltype); + Delete(class_scope); + Delete(cname); + Delete(tdscopename); } - return bases; } /* If the class name is qualified. We need to create or lookup namespace entries */ @@ -1059,352 +1042,33 @@ static String *resolve_create_node_scope(String *cname) { return cname; } - - -/* Structures for handling code fragments built for nested classes */ - -typedef struct Nested { - String *code; /* Associated code fragment */ - int line; /* line number where it starts */ - const char *name; /* Name associated with this nested class */ - const char *kind; /* Kind of class */ - int unnamed; /* unnamed class */ - SwigType *type; /* Datatype associated with the name */ - struct Nested *next; /* Next code fragment in list */ -} Nested; - -/* Some internal variables for saving nested class information */ - -static Nested *nested_list = 0; - -/* Add a function to the nested list */ - -static void add_nested(Nested *n) { - if (!nested_list) { - nested_list = n; - } else { - Nested *n1 = nested_list; - while (n1->next) - n1 = n1->next; - n1->next = n; - } -} - -/* ----------------------------------------------------------------------------- - * nested_new_struct() - * - * Nested struct handling for C code only creates a global struct from the nested struct. - * - * Nested structure. This is a sick "hack". If we encounter - * a nested structure, we're going to grab the text of its definition and - * feed it back into the scanner. In the meantime, we need to grab - * variable declaration information and generate the associated wrapper - * code later. Yikes! - * - * This really only works in a limited sense. Since we use the - * code attached to the nested class to generate both C code - * it can't have any SWIG directives in it. It also needs to be parsable - * by SWIG or this whole thing is going to puke. - * ----------------------------------------------------------------------------- */ - -static void nested_new_struct(const char *kind, String *struct_code, Node *cpp_opt_declarators) { - String *name; - String *decl; - - /* Create a new global struct declaration which is just a copy of the nested struct */ - Nested *nested = (Nested *) malloc(sizeof(Nested)); - Nested *n = nested; - - name = Getattr(cpp_opt_declarators, "name"); - decl = Getattr(cpp_opt_declarators, "decl"); - - n->code = NewStringEmpty(); - Printv(n->code, "typedef ", kind, " ", struct_code, " $classname_", name, ";\n", NIL); - n->name = Swig_copy_string(Char(name)); - n->line = cparse_start_line; - n->type = NewStringEmpty(); - n->kind = kind; - n->unnamed = 0; - SwigType_push(n->type, decl); - n->next = 0; - - /* Repeat for any multiple instances of the nested struct */ - { - Node *p = cpp_opt_declarators; - p = nextSibling(p); - while (p) { - Nested *nn = (Nested *) malloc(sizeof(Nested)); - - name = Getattr(p, "name"); - decl = Getattr(p, "decl"); - - nn->code = NewStringEmpty(); - Printv(nn->code, "typedef ", kind, " ", struct_code, " $classname_", name, ";\n", NIL); - nn->name = Swig_copy_string(Char(name)); - nn->line = cparse_start_line; - nn->type = NewStringEmpty(); - nn->kind = kind; - nn->unnamed = 0; - SwigType_push(nn->type, decl); - nn->next = 0; - n->next = nn; - n = nn; - p = nextSibling(p); - } - } - - add_nested(nested); -} - -/* ----------------------------------------------------------------------------- - * nested_forward_declaration() - * - * Nested struct handling for C++ code only. - * - * Treat the nested class/struct/union as a forward declaration until a proper - * nested class solution is implemented. - * ----------------------------------------------------------------------------- */ - -static Node *nested_forward_declaration(const char *storage, const char *kind, String *sname, String *name, Node *cpp_opt_declarators) { - Node *nn = 0; - int warned = 0; - - if (sname) { - /* Add forward declaration of the nested type */ - Node *n = new_node("classforward"); - Setattr(n, "kind", kind); - Setattr(n, "name", sname); - Setattr(n, "storage", storage); - Setattr(n, "sym:weak", "1"); - add_symbols(n); - nn = n; - } - - /* Add any variable instances. Also add in any further typedefs of the nested type. - Note that anonymous typedefs (eg typedef struct {...} a, b;) are treated as class forward declarations */ - if (cpp_opt_declarators) { - int storage_typedef = (storage && (strcmp(storage, "typedef") == 0)); - int variable_of_anonymous_type = !sname && !storage_typedef; - if (!variable_of_anonymous_type) { - int anonymous_typedef = !sname && (storage && (strcmp(storage, "typedef") == 0)); - Node *n = cpp_opt_declarators; - SwigType *type = name; - while (n) { - Setattr(n, "type", type); - Setattr(n, "storage", storage); - if (anonymous_typedef) { - Setattr(n, "nodeType", "classforward"); - Setattr(n, "sym:weak", "1"); - } - n = nextSibling(n); - } - add_symbols(cpp_opt_declarators); - - if (nn) { - set_nextSibling(nn, cpp_opt_declarators); - } else { - nn = cpp_opt_declarators; +/* look for simple typedef name in typedef list */ +String* try_to_find_a_name_for_unnamed_structure(char* storage, Node* decls) { + String* name = 0; + Node* n = decls; + if (storage && (strcmp(storage,"typedef") == 0)) { + for (; n; n = nextSibling(n)) { + if (!Len(Getattr(n, "decl"))) { + name = Copy(Getattr(n, "name")); + break; } } } - - if (nn && Equal(nodeType(nn), "classforward")) { - Node *n = nn; - if (GetFlag(n, "feature:nestedworkaround")) { - Swig_symbol_remove(n); - nn = 0; - warned = 1; - } else { - SWIG_WARN_NODE_BEGIN(n); - Swig_warning(WARN_PARSE_NAMED_NESTED_CLASS, cparse_file, cparse_line,"Nested %s not currently supported (%s ignored)\n", kind, sname ? sname : name); - SWIG_WARN_NODE_END(n); - warned = 1; - } - } - - if (!warned) - Swig_warning(WARN_PARSE_UNNAMED_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", kind); - - return nn; + return name; } -/* Strips C-style and C++-style comments from string in-place. */ -static void strip_comments(char *string) { - int state = 0; /* - * 0 - not in comment - * 1 - in c-style comment - * 2 - in c++-style comment - * 3 - in string - * 4 - after reading / not in comments - * 5 - after reading * in c-style comments - * 6 - after reading \ in strings - */ - char * c = string; - while (*c) { - switch (state) { - case 0: - if (*c == '\"') - state = 3; - else if (*c == '/') - state = 4; - break; - case 1: - if (*c == '*') - state = 5; - *c = ' '; - break; - case 2: - if (*c == '\n') - state = 0; - else - *c = ' '; - break; - case 3: - if (*c == '\"') - state = 0; - else if (*c == '\\') - state = 6; - break; - case 4: - if (*c == '/') { - *(c-1) = ' '; - *c = ' '; - state = 2; - } else if (*c == '*') { - *(c-1) = ' '; - *c = ' '; - state = 1; - } else - state = 0; - break; - case 5: - if (*c == '/') - state = 0; - else - state = 1; - *c = ' '; - break; - case 6: - state = 3; - break; - } - ++c; +/* traverse copied tree segment, and update outer class links*/ +void update_nested_classes(Node* n) +{ + Node* c = firstChild(n); + while (c) { + if (Getattr(c, "nested:outer")) + Setattr(c, "nested:outer", n); + update_nested_classes(c); + c = nextSibling(c); } } -/* Dump all of the nested class declarations to the inline processor - * However. We need to do a few name replacements and other munging - * first. This function must be called before closing a class! */ - -static Node *dump_nested(const char *parent) { - Nested *n,*n1; - Node *ret = 0; - Node *last = 0; - n = nested_list; - if (!parent) { - nested_list = 0; - return 0; - } - while (n) { - Node *retx; - SwigType *nt; - /* Token replace the name of the parent class */ - Replace(n->code, "$classname", parent, DOH_REPLACE_ANY); - - /* Fix up the name of the datatype (for building typedefs and other stuff) */ - Append(n->type,parent); - Append(n->type,"_"); - Append(n->type,n->name); - - /* Add the appropriate declaration to the C++ processor */ - retx = new_node("cdecl"); - Setattr(retx,"name",n->name); - nt = Copy(n->type); - Setattr(retx,"type",nt); - Delete(nt); - Setattr(retx,"nested",parent); - if (n->unnamed) { - Setattr(retx,"unnamed","1"); - } - - add_symbols(retx); - if (ret) { - set_nextSibling(last, retx); - Delete(retx); - } else { - ret = retx; - } - last = retx; - - /* Strip comments - further code may break in presence of comments. */ - strip_comments(Char(n->code)); - - /* Make all SWIG created typedef structs/unions/classes unnamed else - redefinition errors occur - nasty hack alert.*/ - - { - const char* types_array[3] = {"struct", "union", "class"}; - int i; - for (i=0; i<3; i++) { - char* code_ptr = Char(n->code); - while (code_ptr) { - /* Replace struct name (as in 'struct name {...}' ) with whitespace - name will be between struct and opening brace */ - - code_ptr = strstr(code_ptr, types_array[i]); - if (code_ptr) { - char *open_bracket_pos; - code_ptr += strlen(types_array[i]); - open_bracket_pos = strchr(code_ptr, '{'); - if (open_bracket_pos) { - /* Make sure we don't have something like struct A a; */ - char* semi_colon_pos = strchr(code_ptr, ';'); - if (!(semi_colon_pos && (semi_colon_pos < open_bracket_pos))) - while (code_ptr < open_bracket_pos) - *code_ptr++ = ' '; - } - } - } - } - } - - { - /* Remove SWIG directive %constant which may be left in the SWIG created typedefs */ - char* code_ptr = Char(n->code); - while (code_ptr) { - code_ptr = strstr(code_ptr, "%constant"); - if (code_ptr) { - char* directive_end_pos = strchr(code_ptr, ';'); - if (directive_end_pos) { - while (code_ptr <= directive_end_pos) - *code_ptr++ = ' '; - } - } - } - } - { - Node *newnode = new_node("insert"); - String *code = NewStringEmpty(); - Wrapper_pretty_print(n->code, code); - Setattr(newnode,"code", code); - Delete(code); - set_nextSibling(last, newnode); - Delete(newnode); - last = newnode; - } - - /* Dump the code to the scanner */ - start_inline(Char(Getattr(last, "code")),n->line); - - n1 = n->next; - Delete(n->code); - free(n); - n = n1; - } - nested_list = 0; - return ret; -} - Node *Swig_cparse(File *f) { scanner_file(f); top = 0; @@ -1768,7 +1432,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type cpp_declaration cpp_class_decl cpp_forward_class_decl cpp_template_decl cpp_alternate_rettype; %type cpp_members cpp_member; %type cpp_constructor_decl cpp_destructor_decl cpp_protection_decl cpp_conversion_operator cpp_static_assert; -%type cpp_swig_directive cpp_temp_possible cpp_nested cpp_opt_declarators ; +%type cpp_swig_directive cpp_temp_possible /*cpp_nested*/ cpp_opt_declarators ; %type cpp_using_decl cpp_namespace_decl cpp_catch_decl cpp_lambda_decl; %type kwargs options; @@ -2999,6 +2663,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va } templnode = copy_node(nn); + update_nested_classes(templnode); /* We need to set the node name based on name used to instantiate */ Setattr(templnode,"name",tname); Delete(tname); @@ -3007,7 +2672,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va } else { Setattr(templnode,"sym:typename","1"); } - if ($3 && !inclass) { + if ($3) { /* Comment this out for 1.3.28. We need to re-enable it later but first we need to @@ -3026,16 +2691,15 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va Setattr(templnode,"sym:name",nname); Delete(nname); Setattr(templnode,"feature:onlychildren", "typemap,typemapitem,typemapcopy,typedef,types,fragment"); - - if ($3) { - Swig_warning(WARN_PARSE_NESTED_TEMPLATE, cparse_file, cparse_line, "Named nested template instantiations not supported. Processing as if no name was given to %%template().\n"); - } } Delattr(templnode,"templatetype"); Setattr(templnode,"template",nn); Setfile(templnode,cparse_file); Setline(templnode,cparse_line); Delete(temparms); + if (currentOuterClass) { + SetFlag(templnode, "nested"); + } add_symbols_copy(templnode); @@ -3051,7 +2715,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va csyms = Swig_symbol_current(); Swig_symbol_setscope(Getattr(templnode,"symtab")); if (baselist) { - List *bases = make_inherit_list(Getattr(templnode,"name"),baselist); + List *bases = Swig_make_inherit_list(Getattr(templnode,"name"),baselist, Namespaceprefix); if (bases) { Iterator s; for (s = First(bases); s.item; s = Next(s)) { @@ -3704,10 +3368,10 @@ cpp_declaration : cpp_class_decl { $$ = $1; } /* A simple class/struct/union definition */ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { - if (nested_template == 0) { String *prefix; List *bases = 0; Node *scope = 0; + String *code; $$ = new_node("class"); Setline($$,cparse_start_line); Setattr($$,"kind",$2); @@ -3719,41 +3383,27 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Setattr($$,"allows_typedef","1"); /* preserve the current scope */ - prev_symtab = Swig_symbol_current(); + Setattr($$,"prev_symtab",Swig_symbol_current()); /* If the class name is qualified. We need to create or lookup namespace/scope entries */ scope = resolve_create_node_scope($3); Setfile(scope,cparse_file); Setline(scope,cparse_line); $3 = scope; - - /* support for old nested classes "pseudo" support, such as: - - %rename(Ala__Ola) Ala::Ola; - class Ala::Ola { - public: - Ola() {} - }; - - this should disappear when a proper implementation is added. - */ - if (nscope_inner && Strcmp(nodeType(nscope_inner),"namespace") != 0) { - if (Namespaceprefix) { - String *name = NewStringf("%s::%s", Namespaceprefix, $3); - $3 = name; - Namespaceprefix = 0; - nscope_inner = 0; - } - } Setattr($$,"name",$3); - Delete(class_rename); - class_rename = make_name($$,$3,0); + if (currentOuterClass) { + SetFlag($$, "nested"); + Setattr($$, "nested:outer", currentOuterClass); + set_access_mode($$); + } + /* save yyrename to the class attribute, to be used later in add_symbols()*/ + Setattr($$, "class_rename", make_name($$, $3, 0)); + Setattr($$, "Classprefix", $3); Classprefix = NewString($3); /* Deal with inheritance */ - if ($4) { - bases = make_inherit_list($3,Getattr($4,"public")); - } + if ($4) + bases = Swig_make_inherit_list($3,Getattr($4,"public"),Namespaceprefix); prefix = SwigType_istemplate_templateprefix($3); if (prefix) { String *fbase, *tbase; @@ -3775,18 +3425,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { } Swig_symbol_newscope(); Swig_symbol_setscopename($3); - if (bases) { - Iterator s; - for (s = First(bases); s.item; s = Next(s)) { - Symtab *st = Getattr(s.item,"symtab"); - if (st) { - Setfile(st,Getfile(s.item)); - Setline(st,Getline(s.item)); - Swig_symbol_inherit(st); - } - } - Delete(bases); - } + Swig_inherit_base_symbols(bases); Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); cparse_start_line = cparse_line; @@ -3805,31 +3444,27 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Delete(tpname); } } - if (class_level >= max_class_levels) { - if (!max_class_levels) { - max_class_levels = 16; - } else { - max_class_levels *= 2; - } - class_decl = (Node**) realloc(class_decl, sizeof(Node*) * max_class_levels); - if (!class_decl) { - Swig_error(cparse_file, cparse_line, "realloc() failed\n"); - } - } - class_decl[class_level++] = $$; Delete(prefix); inclass = 1; - } + currentOuterClass = $$; + if (CPlusPlusOut) { /* save the structure declaration to declare it in global scope for C++ to see*/ + code = get_raw_text_balanced('{', '}'); + Setattr($$, "code", code); + Delete(code); + } } cpp_members RBRACE cpp_opt_declarators { - (void) $6; - if (nested_template == 0) { Node *p; SwigType *ty; - Symtab *cscope = prev_symtab; + Symtab *cscope; Node *am = 0; String *scpname = 0; - $$ = class_decl[--class_level]; - inclass = 0; + (void) $6; + $$ = currentOuterClass; + currentOuterClass = Getattr($$, "nested:outer"); + if (!currentOuterClass) + inclass = 0; + cscope = Getattr($$, "prev_symtab"); + Delattr($$, "prev_symtab"); /* Check for pure-abstract class */ Setattr($$,"abstracts", pure_abstracts($7)); @@ -3855,7 +3490,10 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { p = $9; if (p) { - set_nextSibling($$,p); + if (!cparse_cplusplus && currentOuterClass) + appendChild(currentOuterClass, p); + else + appendSibling($$, p); } if (cparse_cplusplus && !cparse_externc) { @@ -3866,41 +3504,14 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { while (p) { Setattr(p,"storage",$1); Setattr(p,"type",ty); + if (!cparse_cplusplus) { + SetFlag(p,"hasconsttype"); + SetFlag(p,"feature:immutable"); + } p = nextSibling(p); } - /* Class typedefs */ - { - String *name = $3; - if ($9) { - SwigType *decltype = Getattr($9,"decl"); - if (Cmp($1,"typedef") == 0) { - if (!decltype || !Len(decltype)) { - String *cname; - String *tdscopename; - String *class_scope = Swig_symbol_qualifiedscopename(cscope); - name = Getattr($9,"name"); - cname = Copy(name); - Setattr($$,"tdname",cname); - tdscopename = class_scope ? NewStringf("%s::%s", class_scope, name) : Copy(name); - - /* Use typedef name as class name */ - if (class_rename && (Strcmp(class_rename,$3) == 0)) { - Delete(class_rename); - class_rename = NewString(name); - } - if (!classes_typedefs) classes_typedefs = NewHash(); - if (!Equal(scpname, tdscopename) && !Getattr(classes_typedefs, tdscopename)) { - Setattr(classes_typedefs, tdscopename, $$); - } - Setattr($$,"decl",decltype); - Delete(class_scope); - Delete(cname); - Delete(tdscopename); - } - } - } - appendChild($$,dump_nested(Char(name))); - } + if ($9 && Cmp($1,"typedef") == 0) + add_typedef_name($$, $9, $3, cscope, scpname); Delete(scpname); if (cplus_mode != CPLUS_PUBLIC) { @@ -3912,10 +3523,13 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { appendChild($$,pa); Delete(pa); } + if (currentOuterClass) + restore_access_mode($$); Setattr($$,"symtab",Swig_symbol_popscope()); - Classprefix = 0; + Classprefix = Getattr($$,"Classprefix"); + Delattr($$,"Classprefix"); if (nscope_inner) { /* this is tricky */ /* we add the declaration in the original namespace */ @@ -3932,37 +3546,59 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { add_symbols($9); } else { Delete(yyrename); - yyrename = Copy(class_rename); + yyrename = 0; Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); - - add_symbols($$); - add_symbols($9); + if (!cparse_cplusplus && currentOuterClass) { /* nested C structs go into global scope*/ + Node* outer = currentOuterClass; + while (Getattr(outer, "nested:outer")) + outer = Getattr(outer, "nested:outer"); + appendSibling(outer, $$); + add_symbols($9); + set_scope_to_global(); + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); + yyrename = Copy(Getattr($$, "class_rename")); + add_symbols($$); + if (!CPlusPlusOut) + Delattr($$, "nested:outer"); + Delattr($$, "class_rename"); + $$ = 0; + } else { + yyrename = Copy(Getattr($$, "class_rename")); + add_symbols($$); + add_symbols($9); + Delattr($$, "class_rename"); + } } Swig_symbol_setscope(cscope); Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); - } else { - $$ = new_node("class"); - Setattr($$,"kind",$2); - Setattr($$,"name",NewString($3)); - SetFlag($$,"nestedtemplateclass"); - } } /* An unnamed struct, possibly with a typedef */ - | storage_class cpptype LBRACE { + | storage_class cpptype inherit LBRACE { String *unnamed; + String *code; unnamed = make_unnamed(); $$ = new_node("class"); Setline($$,cparse_start_line); Setattr($$,"kind",$2); + if ($3) { + Setattr($$,"baselist", Getattr($3,"public")); + Setattr($$,"protectedbaselist", Getattr($3,"protected")); + Setattr($$,"privatebaselist", Getattr($3,"private")); + } Setattr($$,"storage",$1); Setattr($$,"unnamed",unnamed); Setattr($$,"allows_typedef","1"); - Delete(class_rename); - class_rename = make_name($$,0,0); + if (currentOuterClass) { + SetFlag($$, "nested"); + Setattr($$, "nested:outer", currentOuterClass); + set_access_mode($$); + } + Setattr($$, "class_rename", make_name($$,0,0)); if (strcmp($2,"class") == 0) { cplus_mode = CPLUS_PRIVATE; } else { @@ -3970,108 +3606,111 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { } Swig_symbol_newscope(); cparse_start_line = cparse_line; - if (class_level >= max_class_levels) { - if (!max_class_levels) { - max_class_levels = 16; - } else { - max_class_levels *= 2; - } - class_decl = (Node**) realloc(class_decl, sizeof(Node*) * max_class_levels); - if (!class_decl) { - Swig_error(cparse_file, cparse_line, "realloc() failed\n"); - } - } - class_decl[class_level++] = $$; + currentOuterClass = $$; inclass = 1; Classprefix = NewStringEmpty(); Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); - } cpp_members RBRACE declarator initializer c_decl_tail { + /* save the structure declaration to make a typedef for it later*/ + code = get_raw_text_balanced('{', '}'); + Setattr($$, "code", code); + Delete(code); + } cpp_members RBRACE cpp_opt_declarators { String *unnamed; + List *bases = 0; + String *name = 0; Node *n; - (void) $4; Classprefix = 0; - $$ = class_decl[--class_level]; - inclass = 0; + $$ = currentOuterClass; + currentOuterClass = Getattr($$, "nested:outer"); + if (!currentOuterClass) + inclass = 0; + else + restore_access_mode($$); unnamed = Getattr($$,"unnamed"); - - /* Check for pure-abstract class */ - Setattr($$,"abstracts", pure_abstracts($5)); - - n = new_node("cdecl"); - Setattr(n,"name",$7.id); - Setattr(n,"unnamed",unnamed); - Setattr(n,"type",unnamed); - Setattr(n,"decl",$7.type); - Setattr(n,"parms",$7.parms); - Setattr(n,"storage",$1); - if ($9) { - Node *p = $9; - set_nextSibling(n,p); - while (p) { - String *type = Copy(unnamed); - Setattr(p,"name",$7.id); - Setattr(p,"unnamed",unnamed); - Setattr(p,"type",type); - Delete(type); - Setattr(p,"storage",$1); - p = nextSibling(p); - } - } - set_nextSibling($$,n); - Delete(n); - { + /* Check for pure-abstract class */ + Setattr($$,"abstracts", pure_abstracts($6)); + n = $8; + if (n) { + appendSibling($$,n); /* If a proper typedef name was given, we'll use it to set the scope name */ - String *name = 0; - if ($1 && (strcmp($1,"typedef") == 0)) { - if (!Len($7.type)) { - String *scpname = 0; - name = $7.id; - Setattr($$,"tdname",name); - Setattr($$,"name",name); - Swig_symbol_setscopename(name); + name = try_to_find_a_name_for_unnamed_structure($1, n); + if (name) { + String *scpname = 0; + SwigType *ty; + Setattr($$,"tdname",name); + Setattr($$,"name",name); + Swig_symbol_setscopename(name); + if ($3) + bases = Swig_make_inherit_list(name,Getattr($3,"public"),Namespaceprefix); + Swig_inherit_base_symbols(bases); /* If a proper name was given, we use that as the typedef, not unnamed */ - Clear(unnamed); - Append(unnamed, name); - - n = nextSibling(n); - set_nextSibling($$,n); - - /* Check for previous extensions */ - if (extendhash) { - String *clsname = Swig_symbol_qualifiedscopename(0); - Node *am = Getattr(extendhash,clsname); - if (am) { - /* Merge the extension into the symbol table */ - merge_extensions($$,am); - append_previous_extension($$,am); - Delattr(extendhash,clsname); - } - Delete(clsname); - } - if (!classes) classes = NewHash(); - scpname = Swig_symbol_qualifiedscopename(0); - Setattr(classes,scpname,$$); - Delete(scpname); + Clear(unnamed); + Append(unnamed, name); + if (cparse_cplusplus && !cparse_externc) { + ty = NewString(name); } else { - Swig_symbol_setscopename(""); + ty = NewStringf("%s %s", $2,name); } + while (n) { + Setattr(n,"storage",$1); + Setattr(n, "type", ty); + if (!cparse_cplusplus) { + SetFlag(n,"hasconsttype"); + SetFlag(n,"feature:immutable"); + } + n = nextSibling(n); + } + n = $8; + /* Check for previous extensions */ + if (extendhash) { + String *clsname = Swig_symbol_qualifiedscopename(0); + Node *am = Getattr(extendhash,clsname); + if (am) { + /* Merge the extension into the symbol table */ + merge_extensions($$,am); + append_previous_extension($$,am); + Delattr(extendhash,clsname); + } + Delete(clsname); + } + if (!classes) classes = NewHash(); + scpname = Swig_symbol_qualifiedscopename(0); + Setattr(classes,scpname,$$); + Delete(scpname); + } else { /* no suitable name was found for a struct */ + Setattr($$, "nested:unnamed", Getattr(n, "name")); /* save the name of the first declarator for later use in name generation*/ + while (n) { /* attach unnamed struct to the declarators, so that they would receive proper type later*/ + Setattr(n, "nested:unnamedtype", $$); + Setattr(n, "storage", $1); + n = nextSibling(n); + } + n = $8; + Swig_symbol_setscopename(""); } - appendChild($$,$5); - appendChild($$,dump_nested(Char(name))); + appendChild($$,$6); + /* Pop the scope */ + Setattr($$,"symtab",Swig_symbol_popscope()); + if (name) { + Delete(yyrename); + yyrename = Copy(Getattr($$, "class_rename")); + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); + add_symbols($$); + add_symbols(n); + Delattr($$, "class_rename"); + }else if (cparse_cplusplus) + $$ = 0; /* ignore unnamed structs for C++ */ + Delete(unnamed); + } else { /* unnamed struct w/o declarator*/ + Swig_symbol_popscope(); + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); + add_symbols($6); + Delete($$); + $$ = $6; /* pass member list to outer class/namespace (instead of self)*/ } - /* Pop the scope */ - Setattr($$,"symtab",Swig_symbol_popscope()); - if (class_rename) { - Delete(yyrename); - yyrename = NewString(class_rename); - } - Delete(Namespaceprefix); - Namespaceprefix = Swig_symbol_qualifiedscopename(0); - add_symbols($$); - add_symbols(n); - Delete(unnamed); } ; @@ -4107,41 +3746,10 @@ cpp_forward_class_decl : storage_class cpptype idcolon SEMI { ------------------------------------------------------------ */ cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN { + if (currentOuterClass) + Setattr(currentOuterClass, "template_parameters", template_parameters); template_parameters = $3; - if (inclass) - nested_template++; - } cpp_temp_possible { - - /* Don't ignore templated functions declared within a class, unless the templated function is within a nested class */ - if (nested_template <= 1) { - int is_nested_template_class = $6 && GetFlag($6, "nestedtemplateclass"); - if (is_nested_template_class) { - $$ = 0; - /* Nested template classes would probably better be ignored like ordinary nested classes using cpp_nested, but that introduces shift/reduce conflicts */ - if (cplus_mode == CPLUS_PUBLIC) { - /* Treat the nested class/struct/union as a forward declaration until a proper nested class solution is implemented */ - String *kind = Getattr($6, "kind"); - String *name = Getattr($6, "name"); - $$ = new_node("template"); - Setattr($$,"kind",kind); - Setattr($$,"name",name); - Setattr($$,"sym:weak", "1"); - Setattr($$,"templatetype","classforward"); - Setattr($$,"templateparms", $3); - add_symbols($$); - - if (GetFlag($$, "feature:nestedworkaround")) { - Swig_symbol_remove($$); - $$ = 0; - } else { - SWIG_WARN_NODE_BEGIN($$); - Swig_warning(WARN_PARSE_NAMED_NESTED_CLASS, cparse_file, cparse_line, "Nested template %s not currently supported (%s ignored).\n", kind, name); - SWIG_WARN_NODE_END($$); - } - } - Delete($6); - } else { String *tname = 0; int error = 0; @@ -4387,13 +3995,10 @@ cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN { Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); if (error) $$ = 0; - } - } else { - $$ = 0; - } - template_parameters = 0; - if (inclass) - nested_template--; + if (currentOuterClass) + template_parameters = Getattr(currentOuterClass, "template_parameters"); + else + template_parameters = 0; } /* Explicit template instantiation */ @@ -4622,6 +4227,8 @@ cpp_members : cpp_member cpp_members { p = nextSibling(p); } set_nextSibling(pp,$2); + if ($2) + set_previousSibling($2, pp); } else { $$ = $2; } @@ -4678,7 +4285,8 @@ cpp_member : c_declaration { $$ = $1; } | cpp_swig_directive { $$ = $1; } | cpp_conversion_operator { $$ = $1; } | cpp_forward_class_decl { $$ = $1; } - | cpp_nested { $$ = $1; } + | cpp_class_decl { $$ = $1; } +/* | cpp_nested { $$ = $1; }*/ | storage_class idcolon SEMI { $$ = 0; } | cpp_using_decl { $$ = $1; } | cpp_template_decl { $$ = $1; } @@ -4906,82 +4514,6 @@ cpp_protection_decl : PUBLIC COLON { cplus_mode = CPLUS_PROTECTED; } ; - - -/* ------------------------------------------------------------ - Named nested structs: - struct sname { }; - struct sname { } id; - struct sname : bases { }; - struct sname : bases { } id; - typedef sname struct { } td; - typedef sname struct : bases { } td; - - Adding inheritance, ie replacing 'ID' with 'idcolon inherit' - added one shift/reduce - ------------------------------------------------------------ */ - -cpp_nested : storage_class cpptype idcolon inherit LBRACE { - cparse_start_line = cparse_line; - skip_balanced('{','}'); - $$ = NewString(scanner_ccode); /* copied as initializers overwrite scanner_ccode */ - } cpp_opt_declarators { - $$ = 0; - if (cplus_mode == CPLUS_PUBLIC) { - if (cparse_cplusplus) { - String *name = Copy($3); - $$ = nested_forward_declaration($1, $2, $3, name, $7); - } else if ($7) { - nested_new_struct($2, $6, $7); - } - } - Delete($6); - } - -/* ------------------------------------------------------------ - Unnamed/anonymous nested structs: - struct { }; - struct { } id; - struct : bases { }; - struct : bases { } id; - typedef struct { } td; - typedef struct : bases { } td; - ------------------------------------------------------------ */ - - | storage_class cpptype inherit LBRACE { - cparse_start_line = cparse_line; - skip_balanced('{','}'); - $$ = NewString(scanner_ccode); /* copied as initializers overwrite scanner_ccode */ - } cpp_opt_declarators { - $$ = 0; - if (cplus_mode == CPLUS_PUBLIC) { - if (cparse_cplusplus) { - String *name = $6 ? Copy(Getattr($6, "name")) : 0; - $$ = nested_forward_declaration($1, $2, 0, name, $6); - } else { - if ($6) { - nested_new_struct($2, $5, $6); - } else { - Swig_warning(WARN_PARSE_UNNAMED_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", $2); - } - } - } - Delete($5); - } - - -/* This unfortunately introduces 4 shift/reduce conflicts, so instead the somewhat hacky nested_template is used for ignore nested template classes. */ -/* - | TEMPLATE LESSTHAN template_parms GREATERTHAN cpptype idcolon LBRACE { cparse_start_line = cparse_line; skip_balanced('{','}'); - } SEMI { - $$ = 0; - if (cplus_mode == CPLUS_PUBLIC) { - Swig_warning(WARN_PARSE_NAMED_NESTED_CLASS, cparse_file, cparse_line,"Nested %s not currently supported (%s ignored)\n", $5, $6); - } - } -*/ - ; - /* These directives can be included inside a class definition */ cpp_swig_directive: pragma_directive { $$ = $1; } diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index 65ff70dd9..7b535f748 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -75,7 +75,6 @@ #define WARN_PARSE_PRIVATE_INHERIT 309 #define WARN_PARSE_TEMPLATE_REPEAT 310 #define WARN_PARSE_TEMPLATE_PARTIAL 311 -#define WARN_PARSE_UNNAMED_NESTED_CLASS 312 #define WARN_PARSE_UNDEFINED_EXTERN 313 #define WARN_PARSE_KEYWORD 314 #define WARN_PARSE_USING_UNDEF 315 @@ -88,7 +87,6 @@ #define WARN_PARSE_REDUNDANT 322 #define WARN_PARSE_REC_INHERITANCE 323 #define WARN_PARSE_NESTED_TEMPLATE 324 -#define WARN_PARSE_NAMED_NESTED_CLASS 325 #define WARN_PARSE_EXTEND_NAME 326 #define WARN_CPP11_LAMBDA 340 diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index b7daae59c..4e71711d6 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -559,6 +559,8 @@ Allocate(): virtual int classDeclaration(Node *n) { Symtab *symtab = Swig_symbol_current(); Swig_symbol_setscope(Getattr(n, "symtab")); + Node* oldInclass = inclass; + AccessMode oldAcessMode = cplus_mode; if (!CPlusPlus) { /* Always have default constructors/destructors in C */ @@ -580,7 +582,6 @@ Allocate(): } } } - inclass = n; String *kind = Getattr(n, "kind"); if (Strcmp(kind, "class") == 0) { @@ -728,7 +729,8 @@ Allocate(): /* Only care about default behavior. Remove temporary values */ Setattr(n, "allocate:visit", "1"); - inclass = 0; + inclass = oldInclass; + cplus_mode = oldAcessMode; Swig_symbol_setscope(symtab); return SWIG_OK; } diff --git a/Source/Modules/contract.cxx b/Source/Modules/contract.cxx index ffd799cfd..981a21883 100644 --- a/Source/Modules/contract.cxx +++ b/Source/Modules/contract.cxx @@ -342,11 +342,13 @@ int Contracts::namespaceDeclaration(Node *n) { int Contracts::classDeclaration(Node *n) { int ret = SWIG_OK; + int oldInClass = InClass; + Node* oldClass = CurrentClass; InClass = 1; CurrentClass = n; emit_children(n); - InClass = 0; - CurrentClass = 0; + InClass = oldInClass; + CurrentClass = oldClass; return ret; } diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 6b9219750..a0332f1ae 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -18,6 +18,8 @@ /* Hash type used for upcalls from C/C++ */ typedef DOH UpcallData; +// insert N tabs before each new line in s +void Swig_offset_string(String* s, int N); class CSHARP:public Language { static const char *usage; @@ -53,7 +55,6 @@ class CSHARP:public Language { String *proxy_class_code; String *module_class_code; 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; @@ -87,6 +88,7 @@ class CSHARP:public Language { int n_directors; int first_class_dmethod; int curr_class_dmethod; + int nesting_depth; enum EnumFeature { SimpleEnum, TypeunsafeEnum, TypesafeEnum, ProperEnum }; @@ -125,7 +127,6 @@ 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), @@ -156,7 +157,8 @@ public: n_dmethods(0), n_directors(0), first_class_dmethod(0), - curr_class_dmethod(0) { + curr_class_dmethod(0), + nesting_depth(0){ /* for now, multiple inheritance in directors is disabled, this should be easy to implement though */ director_multiple_inheritance = 0; @@ -179,7 +181,13 @@ public: proxyname = Getattr(n, "proxyname"); if (!proxyname) { String *nspace = Getattr(n, "sym:nspace"); - String *symname = Getattr(n, "sym:name"); + String *symname = Copy(Getattr(n, "sym:name")); + if (!GetFlag(n, "feature:flatnested")) { + for (Node* outer_class = Getattr(n, "nested:outer");outer_class;outer_class = Getattr(outer_class, "nested:outer")) { + Push(symname, "."); + Push(symname, Getattr(outer_class, "sym:name")); + } + } if (nspace) { if (namespce) proxyname = NewStringf("%s.%s.%s", namespce, nspace, symname); @@ -190,12 +198,33 @@ public: } Setattr(n, "proxyname", proxyname); Delete(proxyname); + Delete(symname); } } } return proxyname; } + /* ----------------------------------------------------------------------------- + * directorClassName() + * ----------------------------------------------------------------------------- */ + + String *directorClassName(Node *n) { + String *dirclassname; + const char *attrib = "director:classname"; + + if (!(dirclassname = Getattr(n, attrib))) { + String *classname = getClassPrefix(); + + dirclassname = NewStringf("SwigDirector_%s", classname); + Setattr(n, attrib, dirclassname); + } + else + dirclassname = Copy(dirclassname); + + return dirclassname; + } + /* ------------------------------------------------------------ * main() * ------------------------------------------------------------ */ @@ -1025,7 +1054,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(getNSpace(), Swig_name_member(0, proxy_class_name, variable_name))) != 0; + bool getter_flag = Cmp(symname, Swig_name_set(getNSpace(), Swig_name_member(0, getClassPrefix(), variable_name))) != 0; String *getter_setter_name = NewString(""); if (!getter_flag) @@ -1589,6 +1618,7 @@ public: String *c_baseclassname = NULL; SwigType *typemap_lookup_type = Getattr(n, "classtypeobj"); bool feature_director = Swig_directorclass(n) ? true : false; + bool has_outerclass = Getattr(n, "nested:outer") != 0 && !GetFlag(n, "feature:flatnested"); // Inheritance from pure C# classes Node *attributes = NewHash(); @@ -1648,7 +1678,8 @@ public: // Pure C# interfaces const String *pure_interfaces = typemapLookup(n, derived ? "csinterfaces_derived" : "csinterfaces", typemap_lookup_type, WARN_NONE); // Start writing the proxy class - Printv(proxy_class_def, typemapLookup(n, "csimports", typemap_lookup_type, WARN_NONE), // Import statements + if (!has_outerclass) + Printv(proxy_class_def, typemapLookup(n, "csimports", typemap_lookup_type, WARN_NONE), // Import statements "\n", NIL); // Class attributes @@ -1719,7 +1750,7 @@ 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); } - String *director_connect_method_name = Swig_name_member(getNSpace(), proxy_class_name, "director_connect"); + String *director_connect_method_name = Swig_name_member(getNSpace(), getClassPrefix(), "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); @@ -1795,7 +1826,7 @@ public: // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy) if (derived) { String *smartptr = Getattr(n, "feature:smartptr"); - String *upcast_method = Swig_name_member(getNSpace(), proxy_class_name, smartptr != 0 ? "SWIGSmartPtrUpcast" : "SWIGUpcast"); + String *upcast_method = Swig_name_member(getNSpace(), getClassPrefix(), smartptr != 0 ? "SWIGSmartPtrUpcast" : "SWIGUpcast"); String *wname = Swig_name_wrapper(upcast_method); Printv(imclass_cppcasts_code, "\n [global::System.Runtime.InteropServices.DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL); @@ -1846,11 +1877,35 @@ public: String *nspace = getNSpace(); File *f_proxy = NULL; + // save class local variables + String* old_proxy_class_name = proxy_class_name; + String* old_full_imclass_name = full_imclass_name; + String* old_destructor_call = destructor_call; + String* old_proxy_class_constants_code = proxy_class_constants_code; + String* old_proxy_class_def = proxy_class_def; + String* old_proxy_class_code = proxy_class_code; + if (proxy_flag) { proxy_class_name = NewString(Getattr(n, "sym:name")); + if (Node* outer = Getattr(n, "nested:outer")) { + String* outerClassesPrefix = Copy(Getattr(outer, "sym:name")); + for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) { + Push(outerClassesPrefix, "::"); + Push(outerClassesPrefix, Getattr(outer, "sym:name")); + } + String* fnspace = nspace ? NewStringf("%s::%s", nspace, outerClassesPrefix) : outerClassesPrefix; + if (!addSymbol(proxy_class_name, n, fnspace)) + return SWIG_ERROR; + if (nspace) + Delete(fnspace); + Delete(outerClassesPrefix); + } + else { + if (!addSymbol(proxy_class_name, n, nspace)) + return SWIG_ERROR; + } 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); @@ -1863,36 +1918,34 @@ public: } } else { 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 { - 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; + // inner class doesn't need this prologue + if (!Getattr(n, "nested:outer")) { + String *output_directory = outputDirectory(nspace); + String *filen = NewStringf("%s%s.cs", output_directory, proxy_class_name); + f_proxy = NewFile(filen, "w", SWIG_output_files()); + if (!f_proxy) { + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); + } + Append(filenames_list, Copy(filen)); + Delete(filen); + filen = NULL; - String *output_directory = outputDirectory(nspace); - String *filen = NewStringf("%s%s.cs", output_directory, proxy_class_name); - f_proxy = NewFile(filen, "w", SWIG_output_files()); - if (!f_proxy) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); + // Start writing out the proxy class file + emitBanner(f_proxy); + + addOpenNamespace(nspace, f_proxy); } - Append(filenames_list, Copy(filen)); - Delete(filen); - filen = NULL; - - // Start writing out the proxy class file - emitBanner(f_proxy); - - addOpenNamespace(nspace, f_proxy); - - Clear(proxy_class_def); - Clear(proxy_class_code); - + else + ++nesting_depth; + proxy_class_def = NewString(""); + proxy_class_code = NewString(""); destructor_call = NewString(""); proxy_class_constants_code = NewString(""); } @@ -1903,7 +1956,7 @@ public: emitProxyClassDefAndCPPCasts(n); - String *csclazzname = Swig_name_member(getNSpace(), proxy_class_name, ""); // mangled full proxy class name + String *csclazzname = Swig_name_member(getNSpace(), getClassPrefix(), ""); // mangled full proxy class name Replaceall(proxy_class_def, "$csclassname", proxy_class_name); Replaceall(proxy_class_code, "$csclassname", proxy_class_name); @@ -1924,17 +1977,36 @@ public: Replaceall(proxy_class_def, "$dllimport", dllimport); Replaceall(proxy_class_code, "$dllimport", dllimport); Replaceall(proxy_class_constants_code, "$dllimport", dllimport); - - Printv(f_proxy, proxy_class_def, proxy_class_code, NIL); + bool has_outerclass = Getattr(n, "nested:outer") != 0 && !GetFlag(n, "feature:flatnested"); + if (!has_outerclass) + Printv(f_proxy, proxy_class_def, proxy_class_code, NIL); + else { + Swig_offset_string(proxy_class_def, nesting_depth); + Append(old_proxy_class_code, proxy_class_def); + Swig_offset_string(proxy_class_code, nesting_depth); + Append(old_proxy_class_code, proxy_class_code); + } // Write out all the constants - if (Len(proxy_class_constants_code) != 0) - Printv(f_proxy, proxy_class_constants_code, NIL); - - Printf(f_proxy, "}\n"); - addCloseNamespace(nspace, f_proxy); - Delete(f_proxy); - f_proxy = NULL; + if (Len(proxy_class_constants_code) != 0) { + if (!has_outerclass) + Printv(f_proxy, proxy_class_constants_code, NIL); + else { + Swig_offset_string(proxy_class_constants_code, nesting_depth); + Append(old_proxy_class_code, proxy_class_constants_code); + } + } + if (!has_outerclass) { + Printf(f_proxy, "}\n"); + addCloseNamespace(nspace, f_proxy); + Delete(f_proxy); + f_proxy = NULL; + } else { + for (int i = 0; i < nesting_depth; ++i) + Append(old_proxy_class_code, " "); + Append(old_proxy_class_code, "}\n"); + --nesting_depth; + } /* Output the downcast method, if necessary. Note: There's no other really good place to put this code, since Abstract Base Classes (ABCs) can and should have @@ -1971,17 +2043,18 @@ public: Delete(csclazzname); Delete(proxy_class_name); - proxy_class_name = NULL; - Delete(full_proxy_class_name); - full_proxy_class_name = NULL; + proxy_class_name = old_proxy_class_name; Delete(full_imclass_name); - full_imclass_name = NULL; + full_imclass_name = old_full_imclass_name; Delete(destructor_call); - destructor_call = NULL; + destructor_call = old_destructor_call; Delete(proxy_class_constants_code); - proxy_class_constants_code = NULL; + proxy_class_constants_code = old_proxy_class_constants_code; + Delete(proxy_class_def); + proxy_class_def = old_proxy_class_def; + Delete(proxy_class_code); + proxy_class_code = old_proxy_class_code; } - return SWIG_OK; } @@ -1994,7 +2067,7 @@ public: if (proxy_flag) { String *overloaded_name = getOverloadedName(n); - String *intermediary_function_name = Swig_name_member(getNSpace(), proxy_class_name, overloaded_name); + String *intermediary_function_name = Swig_name_member(getNSpace(), getClassPrefix(), overloaded_name); Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); @@ -2014,7 +2087,7 @@ public: if (proxy_flag) { String *overloaded_name = getOverloadedName(n); - String *intermediary_function_name = Swig_name_member(getNSpace(), proxy_class_name, overloaded_name); + String *intermediary_function_name = Swig_name_member(getNSpace(), getClassPrefix(), overloaded_name); Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); @@ -2094,7 +2167,7 @@ public: if (wrapping_member_flag && !enum_constant_flag) { // Properties - setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(getNSpace(), Swig_name_member(0, proxy_class_name, variable_name))) == 0); + setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(getNSpace(), Swig_name_member(0, getClassPrefix(), variable_name))) == 0); if (setter_flag) Swig_typemap_attach_parms("csvarin", l, NULL); } @@ -2264,7 +2337,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(getNSpace(), proxy_class_name, ex_overloaded_name); + String *ex_intermediary_function_name = Swig_name_member(getNSpace(), getClassPrefix(), ex_overloaded_name); String *ex_imcall = Copy(imcall); Replaceall(ex_imcall, "$imfuncname", ex_intermediary_function_name); @@ -3376,14 +3449,21 @@ 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 *dirclassname = directorClassName(n); + String *swig_director_connect = Swig_name_member(getNSpace(), getClassPrefix(), "director_connect"); String *wname = Swig_name_wrapper(swig_director_connect); String *sym_name = Getattr(n, "sym:name"); String *qualified_classname = Copy(sym_name); String *nspace = getNSpace(); String *dirClassName = directorClassName(n); String *smartptr = Getattr(n, "feature:smartptr"); + if (!GetFlag(n, "feature:flatnested")) { + for (Node* outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) { + Push(qualified_classname, "."); + Push(qualified_classname, Getattr(outer_class, "sym:name")); + } + } if (nspace) Insert(qualified_classname, 0, NewStringf("%s.", nspace)); @@ -3415,7 +3495,7 @@ public: Printf(code_wrap->def, ", "); if (i != first_class_dmethod) Printf(code_wrap->code, ", "); - Printf(code_wrap->def, "%s::SWIG_Callback%s_t callback%s", dirClassName, methid, methid); + Printf(code_wrap->def, "%s::SWIG_Callback%s_t callback%s", dirclassname, methid, methid); Printf(code_wrap->code, "callback%s", methid); Printf(imclass_class_code, ", %s.SwigDelegate%s_%s delegate%s", qualified_classname, sym_name, methid, methid); } @@ -3432,7 +3512,7 @@ public: Delete(wname); Delete(swig_director_connect); Delete(qualified_classname); - Delete(dirClassName); + Delete(dirclassname); } /* --------------------------------------------------------------- @@ -3485,7 +3565,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(getNSpace(), classname, overloaded_name)); + imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(getNSpace(), getClassPrefix(), overloaded_name)); qualified_return = SwigType_rcaststr(returntype, "c_result"); @@ -3931,6 +4011,7 @@ public: Delete(proxy_method_types); Delete(callback_def); Delete(callback_code); + Delete(dirclassname); DelWrapper(w); return status; @@ -3970,13 +4051,11 @@ public: String *basetype = Getattr(parent, "classtype"); String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 0); String *call = Swig_csuperclass_call(0, basetype, superparms); - String *classtype = SwigType_namestr(Getattr(n, "name")); Printf(f_directors, "%s::%s : %s, %s {\n", dirclassname, target, call, Getattr(parent, "director:ctor")); Printf(f_directors, " swig_init_callbacks();\n"); Printf(f_directors, "}\n\n"); - Delete(classtype); Delete(target); Delete(call); } @@ -4047,6 +4126,26 @@ public: return Language::classDirectorInit(n); } + int classDeclaration(Node *n) { + String *old_director_callback_typedefs = director_callback_typedefs; + String *old_director_callbacks = director_callbacks; + String *old_director_delegate_callback = director_delegate_callback; + String *old_director_delegate_definitions = director_delegate_definitions; + String *old_director_delegate_instances = director_delegate_instances; + String *old_director_method_types = director_method_types; + String *old_director_connect_parms = director_connect_parms; + int ret = Language::classDeclaration(n); + // these variables are deleted in emitProxyClassDefAndCPPCasts, hence no Delete here + director_callback_typedefs = old_director_callback_typedefs; + director_callbacks = old_director_callbacks; + director_delegate_callback = old_director_delegate_callback; + director_delegate_definitions = old_director_delegate_definitions; + director_delegate_instances = old_director_delegate_instances; + director_method_types = old_director_method_types; + director_connect_parms = old_director_connect_parms; + return ret; + } + /* ---------------------------------------------------------------------- * classDirectorDestructor() * ---------------------------------------------------------------------- */ @@ -4079,7 +4178,7 @@ public: int classDirectorEnd(Node *n) { int i; - String *director_classname = directorClassName(n); + String *dirclassname = directorClassName(n); Wrapper *w = NewWrapper(); @@ -4089,7 +4188,7 @@ public: Printf(f_directors_h, " void swig_connect_director("); - Printf(w->def, "void %s::swig_connect_director(", director_classname); + Printf(w->def, "void %s::swig_connect_director(", dirclassname); for (i = first_class_dmethod; i < curr_class_dmethod; ++i) { UpcallData *udata = Getitem(dmethods_seq, i); @@ -4116,7 +4215,7 @@ public: Printf(f_directors_h, "};\n\n"); Printf(w->code, "}\n\n"); - Printf(w->code, "void %s::swig_init_callbacks() {\n", director_classname); + Printf(w->code, "void %s::swig_init_callbacks() {\n", dirclassname); for (i = first_class_dmethod; i < curr_class_dmethod; ++i) { UpcallData *udata = Getitem(dmethods_seq, i); String *overname = Getattr(udata, "overname"); @@ -4127,6 +4226,7 @@ public: Wrapper_print(w, f_directors); DelWrapper(w); + Delete(dirclassname); return Language::classDirectorEnd(n); } @@ -4159,8 +4259,8 @@ public: String *base = Getattr(n, "classtype"); String *class_ctor = NewString("Swig::Director()"); - String *directorname = directorClassName(n); - String *declaration = Swig_class_declaration(n, directorname); + String *dirclassname = directorClassName(n); + String *declaration = Swig_class_declaration(n, dirclassname); Printf(declaration, " : public %s, public Swig::Director", base); @@ -4168,9 +4268,12 @@ public: Setattr(n, "director:decl", declaration); Setattr(n, "director:ctor", class_ctor); - Delete(directorname); + Delete(dirclassname); } + bool nestedClassesSupported() const { + return true; + } }; /* class CSHARP */ /* ----------------------------------------------------------------------------- diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 6576ad544..a286b5f8e 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -18,6 +18,8 @@ /* Hash type used for upcalls from C/C++ */ typedef DOH UpcallData; +// insert N tabs before each new line in s +void Swig_offset_string(String* s, int N); class JAVA:public Language { static const char *usage; @@ -86,6 +88,7 @@ class JAVA:public Language { int n_directors; int first_class_dmethod; int curr_class_dmethod; + int nesting_depth; enum EnumFeature { SimpleEnum, TypeunsafeEnum, TypesafeEnum, ProperEnum }; @@ -154,7 +157,8 @@ public: n_dmethods(0), n_directors(0), first_class_dmethod(0), - curr_class_dmethod(0) { + curr_class_dmethod(0), + nesting_depth(0){ /* for now, multiple inheritance in directors is disabled, this should be easy to implement though */ director_multiple_inheritance = 0; @@ -204,7 +208,13 @@ public: proxyname = Getattr(n, "proxyname"); if (!proxyname || jnidescriptor) { String *nspace = Getattr(n, "sym:nspace"); - String *symname = Getattr(n, "sym:name"); + String *symname = Copy(Getattr(n, "sym:name")); + if (!GetFlag(n, "feature:flatnested")) { + for (Node* outer_class = Getattr(n, "nested:outer");outer_class;outer_class = Getattr(outer_class, "nested:outer")) { + Push(symname, "."); + Push(symname, Getattr(outer_class, "sym:name")); + } + } if (nspace) { if (package && !jnidescriptor) proxyname = NewStringf("%s.%s.%s", package, nspace, symname); @@ -217,6 +227,7 @@ public: Setattr(n, "proxyname", proxyname); // Cache it Delete(proxyname); } + Delete(symname); } } } @@ -1134,7 +1145,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(getNSpace(), Swig_name_member(0, proxy_class_name, variable_name))) != 0; + bool getter_flag = Cmp(symname, Swig_name_set(getNSpace(), Swig_name_member(0, getClassPrefix(), variable_name))) != 0; String *getter_setter_name = NewString(""); if (!getter_flag) @@ -1713,6 +1724,7 @@ public: String *c_baseclassname = NULL; SwigType *typemap_lookup_type = Getattr(n, "classtypeobj"); bool feature_director = Swig_directorclass(n) ? true : false; + bool has_outerclass = Getattr(n, "nested:outer") != 0 && !GetFlag(n, "feature:flatnested"); // Inheritance from pure Java classes Node *attributes = NewHash(); @@ -1773,8 +1785,11 @@ public: const String *pure_interfaces = typemapLookup(n, "javainterfaces", typemap_lookup_type, WARN_NONE); // Start writing the proxy class - Printv(proxy_class_def, typemapLookup(n, "javaimports", typemap_lookup_type, WARN_NONE), // Import statements - "\n", typemapLookup(n, "javaclassmodifiers", typemap_lookup_type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers + if (!has_outerclass) // Import statements + Printv(proxy_class_def, typemapLookup(n, "javaimports", typemap_lookup_type, WARN_NONE),"\n", NIL); + else + Printv(proxy_class_def, "static ", NIL); // C++ nested classes correspond to static java classes + Printv(proxy_class_def, typemapLookup(n, "javaclassmodifiers", typemap_lookup_type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers " $javaclassname", // Class name and bases (*Char(wanted_base)) ? " extends " : "", wanted_base, *Char(pure_interfaces) ? // Pure Java interfaces " implements " : "", pure_interfaces, " {", derived ? typemapLookup(n, "javabody_derived", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF) : // main body of class @@ -1825,7 +1840,7 @@ 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"); + String *changeown_method_name = Swig_name_member(getNSpace(), getClassPrefix(), "change_ownership"); destruct_jnicall = NewStringf("%s()", destruct_methodname); release_jnicall = NewStringf("%s.%s(this, swigCPtr, false)", full_imclass_name, changeown_method_name); @@ -1851,7 +1866,7 @@ public: // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy) if (derived) { String *smartptr = Getattr(n, "feature:smartptr"); - String *upcast_method = Swig_name_member(getNSpace(), proxy_class_name, smartptr != 0 ? "SWIGSmartPtrUpcast" : "SWIGUpcast"); + String *upcast_method = Swig_name_member(getNSpace(), getClassPrefix(), 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); @@ -1908,13 +1923,29 @@ public: virtual int classHandler(Node *n) { File *f_proxy = NULL; + String* old_proxy_class_name = proxy_class_name; + String* old_full_proxy_class_name = full_proxy_class_name; + String* old_full_imclass_name = full_imclass_name; + String* old_destructor_call = destructor_call; + String* old_destructor_throws_clause = destructor_throws_clause; + String* old_proxy_class_constants_code = proxy_class_constants_code; + String* old_proxy_class_def = proxy_class_def; + String* old_proxy_class_code = proxy_class_code; if (proxy_flag) { proxy_class_name = NewString(Getattr(n, "sym:name")); String *nspace = getNSpace(); constructIntermediateClassName(n); + String* outerClassesPrefix = 0; + if (Node* outer = Getattr(n, "nested:outer")) { + outerClassesPrefix = Copy(Getattr(outer, "sym:name")); + for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) { + Push(outerClassesPrefix, "."); + Push(outerClassesPrefix, Getattr(outer, "sym:name")); + } + } if (!nspace) { - full_proxy_class_name = NewStringf("%s", proxy_class_name); + full_proxy_class_name = outerClassesPrefix ? NewStringf("%s.%s", outerClassesPrefix, proxy_class_name) : NewStringf("%s", proxy_class_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); @@ -1926,54 +1957,73 @@ public: SWIG_exit(EXIT_FAILURE); } } else { - if (package) - full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name); - else - full_proxy_class_name = NewStringf("%s.%s", nspace, proxy_class_name); + if (outerClassesPrefix) { + if (package) + full_proxy_class_name = NewStringf("%s.%s.%s.%s", package, nspace, outerClassesPrefix, proxy_class_name); + else + full_proxy_class_name = NewStringf("%s.%s.%s", nspace, outerClassesPrefix, proxy_class_name); + }else { + if (package) + full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name); + else + full_proxy_class_name = NewStringf("%s.%s", nspace, proxy_class_name); + } } - if (!addSymbol(proxy_class_name, n, nspace)) - return SWIG_ERROR; - - 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); - SWIG_exit(EXIT_FAILURE); - } - Append(filenames_list, Copy(filen)); - Delete(filen); - filen = NULL; - - // Start writing out the proxy class file - emitBanner(f_proxy); - - if (package || nspace) { - Printf(f_proxy, "package "); - if (package) - Printv(f_proxy, package, nspace ? "." : "", NIL); + if (outerClassesPrefix) { + Replaceall(outerClassesPrefix, ".", "::"); + String* fnspace = nspace ? NewStringf("%s::%s", nspace, outerClassesPrefix) : outerClassesPrefix; + if (!addSymbol(proxy_class_name, n, fnspace)) + return SWIG_ERROR; if (nspace) - Printv(f_proxy, nspace, NIL); - Printf(f_proxy, ";\n"); + Delete(fnspace); + Delete(outerClassesPrefix); + } + else { + if (!addSymbol(proxy_class_name, n, nspace)) + return SWIG_ERROR; } - Clear(proxy_class_def); - Clear(proxy_class_code); + if (!Getattr(n, "nested:outer")) { + 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); + SWIG_exit(EXIT_FAILURE); + } + Append(filenames_list, Copy(filen)); + Delete(filen); + Delete(output_directory); + // Start writing out the proxy class file + emitBanner(f_proxy); + + if (package || nspace) { + Printf(f_proxy, "package "); + if (package) + Printv(f_proxy, package, nspace ? "." : "", NIL); + if (nspace) + Printv(f_proxy, nspace, NIL); + Printf(f_proxy, ";\n"); + } + } + else + ++nesting_depth; + + proxy_class_def = NewString(""); + proxy_class_code = NewString(""); destructor_call = NewString(""); destructor_throws_clause = NewString(""); proxy_class_constants_code = NewString(""); - Delete(output_directory); } - Language::classHandler(n); if (proxy_flag) { emitProxyClassDefAndCPPCasts(n); - String *javaclazzname = Swig_name_member(getNSpace(), proxy_class_name, ""); // mangled full proxy class name + String *javaclazzname = Swig_name_member(getNSpace(), getClassPrefix(), ""); // mangled full proxy class name Replaceall(proxy_class_def, "$javaclassname", proxy_class_name); Replaceall(proxy_class_code, "$javaclassname", proxy_class_name); @@ -1991,22 +2041,43 @@ public: 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); + bool has_outerclass = Getattr(n, "nested:outer") != 0 && !GetFlag(n, "feature:flatnested"); + if (!has_outerclass) + Printv(f_proxy, proxy_class_def, proxy_class_code, NIL); + else { + Swig_offset_string(proxy_class_def, nesting_depth); + Append(old_proxy_class_code, proxy_class_def); + Swig_offset_string(proxy_class_code, nesting_depth); + Append(old_proxy_class_code, proxy_class_code); + } // Write out all the constants - if (Len(proxy_class_constants_code) != 0) - Printv(f_proxy, proxy_class_constants_code, NIL); + if (Len(proxy_class_constants_code) != 0) { + if (!has_outerclass) + Printv(f_proxy, proxy_class_constants_code, NIL); + else { + Swig_offset_string(proxy_class_constants_code, nesting_depth); + Append(old_proxy_class_code, proxy_class_constants_code); + } + } - Printf(f_proxy, "}\n"); - Delete(f_proxy); - f_proxy = NULL; + if (!has_outerclass) { + Printf(f_proxy, "}\n"); + Delete(f_proxy); + f_proxy = NULL; + } else { + for (int i = 0; i < nesting_depth; ++i) + Append(old_proxy_class_code, " "); + Append(old_proxy_class_code, "}\n"); + --nesting_depth; + } /* Output the downcast method, if necessary. Note: There's no other really good place to put this code, since Abstract Base Classes (ABCs) can and should have downcasts, making the constructorHandler() a bad place (because ABCs don't get to have constructors emitted.) */ if (GetFlag(n, "feature:javadowncast")) { - String *downcast_method = Swig_name_member(getNSpace(), proxy_class_name, "SWIGDowncast"); + String *downcast_method = Swig_name_member(getNSpace(), getClassPrefix(), "SWIGDowncast"); String *jniname = makeValidJniName(downcast_method); String *wname = Swig_name_wrapper(jniname); @@ -2038,17 +2109,21 @@ public: Delete(javaclazzname); Delete(proxy_class_name); - proxy_class_name = NULL; + proxy_class_name = old_proxy_class_name; Delete(full_proxy_class_name); - full_proxy_class_name = NULL; + full_proxy_class_name = old_full_proxy_class_name; Delete(full_imclass_name); - full_imclass_name = NULL; + full_imclass_name = old_full_imclass_name; Delete(destructor_call); - destructor_call = NULL; + destructor_call = old_destructor_call; Delete(destructor_throws_clause); - destructor_throws_clause = NULL; + destructor_throws_clause = old_destructor_throws_clause; Delete(proxy_class_constants_code); - proxy_class_constants_code = NULL; + proxy_class_constants_code = old_proxy_class_constants_code; + Delete(proxy_class_def); + proxy_class_def = old_proxy_class_def; + Delete(proxy_class_code); + proxy_class_code = old_proxy_class_code; } return SWIG_OK; @@ -2064,7 +2139,7 @@ public: if (proxy_flag) { String *overloaded_name = getOverloadedName(n); - String *intermediary_function_name = Swig_name_member(getNSpace(), proxy_class_name, overloaded_name); + String *intermediary_function_name = Swig_name_member(getNSpace(), getClassPrefix(), overloaded_name); Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); @@ -2086,7 +2161,7 @@ public: if (proxy_flag) { String *overloaded_name = getOverloadedName(n); - String *intermediary_function_name = Swig_name_member(getNSpace(), proxy_class_name, overloaded_name); + String *intermediary_function_name = Swig_name_member(getNSpace(), getClassPrefix(), overloaded_name); Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); @@ -2162,7 +2237,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(getNSpace(), Swig_name_member(0, proxy_class_name, variable_name))) == 0); + setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(getNSpace(), Swig_name_member(0, getClassPrefix(), variable_name))) == 0); } /* Start generating the proxy function */ @@ -2316,7 +2391,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(getNSpace(), proxy_class_name, ex_overloaded_name); + String *ex_intermediary_function_name = Swig_name_member(getNSpace(), getClassPrefix(), ex_overloaded_name); String *ex_imcall = Copy(imcall); Replaceall(ex_imcall, "$imfuncname", ex_intermediary_function_name); @@ -3399,7 +3474,7 @@ 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 = Swig_name_member(getNSpace(), proxy_class_name, "director_connect"); + String *swig_director_connect = Swig_name_member(getNSpace(), getClassPrefix(), "director_connect"); String *swig_director_connect_jni = makeValidJniName(swig_director_connect); String *smartptr = Getattr(n, "feature:smartptr"); String *dirClassName = directorClassName(n); @@ -3439,7 +3514,7 @@ public: Delete(swig_director_connect); // Output the swigReleaseOwnership, swigTakeOwnership methods: - String *changeown_method_name = Swig_name_member(getNSpace(), proxy_class_name, "change_ownership"); + String *changeown_method_name = Swig_name_member(getNSpace(), getClassPrefix(), "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, full_proxy_class_name); @@ -4519,6 +4594,9 @@ public: Setattr(n, "director:ctor", class_ctor); } + bool nestedClassesSupported() const { + return true; + } }; /* class JAVA */ /* ----------------------------------------------------------------------------- diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index e50a50a6d..89cc17a83 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -355,7 +355,7 @@ Language::~Language() { String *dirclassname; String *nspace = NewString(Getattr(n, "sym:nspace")); const char *attrib = "director:classname"; - String *classname = Getattr(n, "sym:name"); + String *classname = getClassPrefix(); Replace(nspace, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY); if (Len(nspace) > 0) @@ -1015,8 +1015,6 @@ int Language::cDeclaration(Node *n) { /* Some kind of variable declaration */ String *declaration = Copy(decl); Delattr(n, "decl"); - if (Getattr(n, "nested")) - SetFlag(n, "feature:immutable"); if (!CurrentClass) { if (Swig_storage_isextern(n) || ForceExtern) { if (AddExtern) { @@ -2362,6 +2360,15 @@ int Language::classDeclaration(Node *n) { return SWIG_NOWRAP; } + // save class local variables for nested classes support + int oldInClass = InClass; + String *oldClassType = ClassType; + String *oldClassPrefix = ClassPrefix; + String *oldClassName = ClassName; + String *oldDirectorClassName = DirectorClassName; + String *oldNSpace = NSpace; + Node* oldCurrentClass = CurrentClass; + String *kind = Getattr(n, "kind"); String *name = Getattr(n, "name"); String *tdname = Getattr(n, "tdname"); @@ -2370,6 +2377,8 @@ int Language::classDeclaration(Node *n) { int strip = CPlusPlus ? 1 : unnamed && tdname; + if (cplus_mode != PUBLIC) + return SWIG_NOWRAP; if (!name) { Swig_warning(WARN_LANG_CLASS_UNNAMED, input_file, line_number, "Can't generate wrappers for unnamed struct/class.\n"); return SWIG_NOWRAP; @@ -2380,15 +2389,21 @@ int Language::classDeclaration(Node *n) { Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap class %s unless renamed to a valid identifier.\n", SwigType_namestr(symname)); return SWIG_NOWRAP; } - + AccessMode oldAccessMode = cplus_mode; + Node* outerClass = Getattr(n, "nested:outer"); + if (outerClass && oldAccessMode != Dispatcher::PUBLIC) + return SWIG_NOWRAP; + ClassName = Copy(name); + ClassPrefix = Copy(symname); if (Cmp(kind, "class") == 0) { cplus_mode = PRIVATE; } else { cplus_mode = PUBLIC; } - - ClassName = Copy(name); - ClassPrefix = Copy(symname); + for (; outerClass; outerClass = Getattr(outerClass, "nested:outer")) { + Push(ClassPrefix, "_"); + Push(ClassPrefix, Getattr(outerClass, "sym:name")); + } if (strip) { ClassType = Copy(name); } else { @@ -2399,9 +2414,8 @@ int Language::classDeclaration(Node *n) { InClass = 1; CurrentClass = n; - - String *oldNSpace = NSpace; NSpace = Getattr(n, "sym:nspace"); + int oldAbstract = Abstract; /* Call classHandler() here */ if (!ImportMode) { @@ -2443,25 +2457,27 @@ int Language::classDeclaration(Node *n) { classDirector(n); } /* check for abstract after resolving directors */ - Abstract = abstractClassTest(n); + Abstract = abstractClassTest(n); classHandler(n); } else { Abstract = abstractClassTest(n); Language::classHandler(n); } + Abstract = oldAbstract; + cplus_mode = oldAccessMode; NSpace = oldNSpace; - InClass = 0; - CurrentClass = 0; + InClass = oldInClass; + CurrentClass = oldCurrentClass; Delete(ClassType); - ClassType = 0; + ClassType = oldClassType; Delete(ClassPrefix); - ClassPrefix = 0; + ClassPrefix = oldClassPrefix; Delete(ClassName); - ClassName = 0; + ClassName = oldClassName; Delete(DirectorClassName); - DirectorClassName = 0; + DirectorClassName = oldDirectorClassName; return SWIG_OK; } @@ -2640,7 +2656,7 @@ int Language::constructorDeclaration(Node *n) { String *scope = Swig_scopename_check(ClassName) ? Swig_scopename_prefix(ClassName) : 0; String *actual_name = scope ? NewStringf("%s::%s", scope, name) : NewString(name); Delete(scope); - if (!Equal(actual_name, expected_name) && !(Getattr(n, "template"))) { + if (!Equal(actual_name, expected_name) && !SwigType_istemplate(expected_name)) { bool illegal_name = true; if (Extend) { // Check for typedef names used as a constructor name in %extend. This is deprecated except for anonymous @@ -3426,6 +3442,9 @@ bool Language::extraDirectorProtectedCPPMethodsRequired() const { return true; } +bool Language::nestedClassesSupported() const { + return false; +} /* ----------------------------------------------------------------------------- * Language::is_wrapping_class() * ----------------------------------------------------------------------------- */ @@ -3612,3 +3631,45 @@ Language *Language::instance() { Hash *Language::getClassHash() const { return classhash; } + +// insert N tabs before each new line in s +void Swig_offset_string(String* s, int N) +{ + // count a number of lines in s + int lines = 1; + int L = Len(s); + char* start = strchr(Char(s), '\n'); + while (start) { + ++lines; + start = strchr(start + 1, '\n'); + } + // do not count pending new line + if ((Char(s))[L-1] == '\n') + --lines; + // allocate a temporary storage for a padded string + char* res = (char*)malloc(L + lines * N * 2 + 1); + res[L + lines * N * 2] = 0; + + // copy lines to res, prepending tabs to each line + char* p = res; // output pointer + start = Char(s); // start of a current line + char* end = strchr(start, '\n'); // end of a current line + while (end) { + memset(p, ' ', N*2); + p += N*2; + memcpy(p, start, end - start + 1); + p += end - start + 1; + start = end + 1; + end = strchr(start, '\n'); + } + // process the last line + if (*start) { + memset(p, ' ', N*2); + p += N*2; + strcpy(p, start); + } + // replace 's' contents with 'res' + Clear(s); + Append(s, res); + free(res); +} diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index 4076b9206..e2ed6a675 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -29,6 +29,10 @@ static Language *lang = 0; // Language method int CPlusPlus = 0; +extern "C" +{ + int CPlusPlusOut = 0; // generate C++ declarations for C code +}; int Extend = 0; // Extend flag int ForceExtern = 0; // Force extern mode int GenerateDefault = 1; // Generate default constructors @@ -483,6 +487,9 @@ void SWIG_getoptions(int argc, char *argv[]) { Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0); Swig_cparse_cplusplus(1); Swig_mark_arg(i); + } else if (strcmp(argv[i], "-c++out") == 0) { + CPlusPlusOut = 1; + Swig_mark_arg(i); } else if (strcmp(argv[i], "-fcompact") == 0) { Wrapper_compact_print_mode_set(1); Swig_mark_arg(i); @@ -855,8 +862,27 @@ void SWIG_getoptions(int argc, char *argv[]) { } } - - +void Swig_flatten_nested() { + String* name = NewString(""); + String* fname = NewString("feature:flatnested"); + String* val = NewString("1"); + Swig_feature_set(Swig_cparse_features(),name,0,fname, val, 0); + Delete(fname); + Delete(name); + Delete(val); + /* + String* name = NewStringEmpty(); + Hash* newname = NewHash(); + Setattr(newname, "name", "$ignore"); + Hash* match = NewHash(); + Setattr(match, "name", "match$nested"); + Setattr(match, "value", "1"); + set_nextSibling(newname, match); + Swig_name_rename_add(0, name, 0, newname, 0); + Delete(name); + Delete(match); + Delete(newname);*/ +} int SWIG_main(int argc, char *argv[], Language *l) { @@ -1151,6 +1177,10 @@ int SWIG_main(int argc, char *argv[], Language *l) { fflush(stdout); } + // add "ignore" directive if nested classes are not supported + if (!lang->nestedClassesSupported()) + Swig_flatten_nested(); + Node *top = Swig_cparse(cpps); if (dump_top & STAGE1) { @@ -1161,6 +1191,11 @@ int SWIG_main(int argc, char *argv[], Language *l) { Printf(stdout, "debug-module stage 1\n"); Swig_print_tree(Getattr(top, "module")); } + if (!CPlusPlus) { + if (Verbose) + Printf(stdout, "Processing unnamed structs...\n"); + Swig_name_unnamed_c_structs(top); + } if (Verbose) { Printf(stdout, "Processing types...\n"); @@ -1181,6 +1216,12 @@ int SWIG_main(int argc, char *argv[], Language *l) { } Swig_default_allocators(top); + if (CPlusPlus) { + if (Verbose) + Printf(stdout, "Processing nested classes...\n"); + Swig_process_nested_classes(top); + } + if (dump_top & STAGE3) { Printf(stdout, "debug-top stage 3\n"); Swig_print_tree(top); diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 65a1ad701..1c0192d07 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -86,6 +86,7 @@ public: director_multiple_inheritance = 1; director_language = 1; docs = NewHash(); + CPlusPlusOut = 1; } virtual void main(int argc, char *argv[]) { diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 3a7e8a8d6..61e5f8c13 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -32,6 +32,7 @@ extern String *input_file; extern int line_number; extern int start_line; extern int CPlusPlus; // C++ mode +extern "C" int CPlusPlusOut; // generate C++ declarations for C code (currently used for Octave) extern int Extend; // Extend mode extern int Verbose; extern int IsVirtual; @@ -297,6 +298,16 @@ protected: /* Some language modules require additional wrappers for virtual methods not declared in sub-classes */ virtual bool extraDirectorProtectedCPPMethodsRequired() const; +public: + /* Does target language support nested classes? Default is 'false'. If 'false' is returned, then + %rename("$ignore", %$isnested) statement will be issued at the top, and the nested classes + will be ignored. Note that even if the target language does not support the notion of class + nesting, the language module may nevertheless return true from this function, and use + %feature "flatnested" to move nested classes to the global scope, instead of ignoring them. + */ + virtual bool nestedClassesSupported() const; + +protected: /* Identifies if a protected members that are generated when the allprotected option is used. This does not include protected virtual methods as they are turned on with the dirprot option. */ bool isNonVirtualProtectedAccess(Node *n) const; @@ -410,5 +421,7 @@ int Swig_contract_mode_get(); void Swig_browser(Node *n, int); void Swig_default_allocators(Node *n); void Swig_process_types(Node *n); +void Swig_process_nested_classes(Node *n); +void Swig_name_unnamed_c_structs(Node *n); #endif diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index 7eebfe80b..e5c6d2c05 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -178,6 +178,20 @@ class TypePass:private Dispatcher { } continue; } + // A case when both outer and nested classes inherit from the same parent. Constructor may be found instead of the class itself. + } else if (GetFlag(cls, "nested") && checkAttribute(bcls, "nodeType", "constructor")) { + bcls = Getattr(bcls, "parentNode"); + if (Getattr(bcls, "typepass:visit")) { + if (!Getattr(bcls, "feature:onlychildren")) { + if (!ilist) + ilist = alist = NewList(); + Append(ilist, bcls); + } else { + Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' has no name as it is an empty template instantiated with '%%template()'. Ignored.\n", SwigType_namestr(bname)); + Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "The %%template directive must be written before '%s' is used as a base class and be declared with a name.\n", SwigType_namestr(bname)); + } + } + break; } if (Strcmp(nodeType(bcls), "classforward") != 0) { Swig_error(Getfile(bname), Getline(bname), "'%s' is not a valid base class.\n", SwigType_namestr(bname)); @@ -463,6 +477,18 @@ class TypePass:private Dispatcher { SwigType_typedef(unnamed, tdname); } + // name of the outer class should already be patched to contain it's outer classes names, but not to contain namespaces + // namespace name (if present) is added after processing child nodes + if (Getattr(n, "nested:outer") && name) { + String* outerName = Getattr(Getattr(n, "nested:outer"), "name"); + name = NewStringf("%s::%s", outerName, name); + Setattr(n, "name", name); + if (tdname) { + tdname = NewStringf("%s::%s", outerName, tdname); + Setattr(n, "tdname", tdname); + } + } + if (nsname && name) { nname = NewStringf("%s::%s", nsname, name); String *tdname = Getattr(n, "tdname"); @@ -479,7 +505,7 @@ class TypePass:private Dispatcher { SwigType_attach_symtab(Getattr(n, "symtab")); /* Inherit type definitions into the class */ - if (name) { + if (name && !(GetFlag(n, "nested") && GetFlag(n, "feature:flatnested") && !checkAttribute(n, "access", "public"))) { cplus_inherit_types(n, 0, nname ? nname : (fname ? fname : name)); } @@ -1258,3 +1284,432 @@ void Swig_process_types(Node *n) { return; TypePass::pass(n); } + +// Nested classes processing section +static Hash* classhash = 0; + +static String *make_name(Node *n, String *name,SwigType *decl) { + int destructor = name && (*(Char(name)) == '~'); + if (String* yyrename = Getattr(n, "class_rename")) { + String *s = NewString(yyrename); + Delattr(n, "class_rename"); + if (destructor && (*(Char(s)) != '~')) { + Insert(s,0,"~"); + } + return s; + } + + if (!name) return 0; + return Swig_name_make(n,0,name,decl,0); +} + +// C version of add_symbols() +static void add_symbols_c(Node *n) { + String *decl; + String *wrn = 0; + String *symname = 0; + int iscdecl = Cmp(nodeType(n),"cdecl") == 0; + Setattr(n,"ismember","1"); + Setattr(n,"access", "public"); + if (Getattr(n,"sym:name")) + return; + decl = Getattr(n,"decl"); + if (!SwigType_isfunction(decl)) { + String *name = Getattr(n,"name"); + String *makename = Getattr(n,"parser:makename"); + if (iscdecl) { + String *storage = Getattr(n, "storage"); + if (Cmp(storage,"typedef") == 0) { + Setattr(n,"kind","typedef"); + } else { + SwigType *type = Getattr(n,"type"); + String *value = Getattr(n,"value"); + Setattr(n,"kind","variable"); + if (value && Len(value)) { + Setattr(n,"hasvalue","1"); + } + if (type) { + SwigType *ty; + SwigType *tmp = 0; + if (decl) { + ty = tmp = Copy(type); + SwigType_push(ty,decl); + } else { + ty = type; + } + if (!SwigType_ismutable(ty)) { + SetFlag(n,"hasconsttype"); + SetFlag(n,"feature:immutable"); + } + if (tmp) Delete(tmp); + } + if (!type) { + Printf(stderr,"notype name %s\n", name); + } + } + } + Swig_features_get(Swig_cparse_features(), 0, name, 0, n); + if (makename) { + symname = make_name(n, makename, 0); + Delattr(n,"parser:makename"); /* temporary information, don't leave it hanging around */ + } else { + makename = name; + symname = make_name(n, makename, 0); + } + + if (!symname) { + symname = Copy(Getattr(n,"unnamed")); + } + if (symname) { + wrn = Swig_name_warning(n, 0, symname,0); + } + } else { + String *name = Getattr(n,"name"); + SwigType *fdecl = Copy(decl); + SwigType *fun = SwigType_pop_function(fdecl); + if (iscdecl) { + Setattr(n,"kind","function"); + } + + Swig_features_get(Swig_cparse_features(),0,name,fun,n); + + symname = make_name(n, name, fun); + wrn = Swig_name_warning(n, 0, symname,fun); + + Delete(fdecl); + Delete(fun); + + } + if (!symname) + return; + if (GetFlag(n,"feature:ignore")) { + /* Only add to C symbol table and continue */ + Swig_symbol_add(0, n); + } else if (strncmp(Char(symname),"$ignore",7) == 0) { + char *c = Char(symname)+7; + SetFlag(n,"feature:ignore"); + if (strlen(c)) { + SWIG_WARN_NODE_BEGIN(n); + Swig_warning(0,Getfile(n), Getline(n), "%s\n",c+1); + SWIG_WARN_NODE_END(n); + } + Swig_symbol_add(0, n); + } else { + Node *c; + if ((wrn) && (Len(wrn))) { + String *metaname = symname; + if (!Getmeta(metaname,"already_warned")) { + SWIG_WARN_NODE_BEGIN(n); + Swig_warning(0,Getfile(n),Getline(n), "%s\n", wrn); + SWIG_WARN_NODE_END(n); + Setmeta(metaname,"already_warned","1"); + } + } + c = Swig_symbol_add(symname,n); + + if (c != n) { + /* symbol conflict attempting to add in the new symbol */ + if (Getattr(n,"sym:weak")) { + Setattr(n,"sym:name",symname); + } else { + String *e = NewStringEmpty(); + String *en = NewStringEmpty(); + String *ec = NewStringEmpty(); + int redefined = Swig_need_redefined_warn(n,c,true); + if (redefined) { + Printf(en,"Identifier '%s' redefined (ignored)",symname); + Printf(ec,"previous definition of '%s'",symname); + } else { + Printf(en,"Redundant redeclaration of '%s'",symname); + Printf(ec,"previous declaration of '%s'",symname); + } + if (Cmp(symname,Getattr(n,"name"))) { + Printf(en," (Renamed from '%s')", SwigType_namestr(Getattr(n,"name"))); + } + Printf(en,","); + if (Cmp(symname,Getattr(c,"name"))) { + Printf(ec," (Renamed from '%s')", SwigType_namestr(Getattr(c,"name"))); + } + Printf(ec,"."); + SWIG_WARN_NODE_BEGIN(n); + if (redefined) { + Swig_warning(WARN_PARSE_REDEFINED,Getfile(n),Getline(n),"%s\n",en); + Swig_warning(WARN_PARSE_REDEFINED,Getfile(c),Getline(c),"%s\n",ec); + } else { + Swig_warning(WARN_PARSE_REDUNDANT,Getfile(n),Getline(n),"%s\n",en); + Swig_warning(WARN_PARSE_REDUNDANT,Getfile(c),Getline(c),"%s\n",ec); + } + SWIG_WARN_NODE_END(n); + Printf(e,"%s:%d:%s\n%s:%d:%s\n",Getfile(n),Getline(n),en, + Getfile(c),Getline(c),ec); + Setattr(n,"error",e); + Delete(e); + Delete(en); + Delete(ec); + } + } + } + Delete(symname); +} + +/* Strips C-style and C++-style comments from string in-place. */ +static void strip_comments(char *string) { + int state = 0; /* + * 0 - not in comment + * 1 - in c-style comment + * 2 - in c++-style comment + * 3 - in string + * 4 - after reading / not in comments + * 5 - after reading * in c-style comments + * 6 - after reading \ in strings + */ + char * c = string; + while (*c) { + switch (state) { + case 0: + if (*c == '\"') + state = 3; + else if (*c == '/') + state = 4; + break; + case 1: + if (*c == '*') + state = 5; + *c = ' '; + break; + case 2: + if (*c == '\n') + state = 0; + else + *c = ' '; + break; + case 3: + if (*c == '\"') + state = 0; + else if (*c == '\\') + state = 6; + break; + case 4: + if (*c == '/') { + *(c-1) = ' '; + *c = ' '; + state = 2; + } else if (*c == '*') { + *(c-1) = ' '; + *c = ' '; + state = 1; + } else + state = 0; + break; + case 5: + if (*c == '/') + state = 0; + else + state = 1; + *c = ' '; + break; + case 6: + state = 3; + break; + } + ++c; + } +} + +// Create an %insert with a typedef to make a new name visible to C +// the code is moved from parser.y, dump_nested() function with minor changes +static Node* create_insert(Node* n, bool noTypedef = false) { + // format a typedef + String* ccode = Getattr(n, "code"); + Push(ccode, " "); + if (noTypedef) { + Push(ccode, Getattr(n, "name")); + Push(ccode, " "); + Push(ccode, Getattr(n, "kind")); + } else { + Push(ccode, Getattr(n, "kind")); + Push(ccode, "typedef "); + Append(ccode, " "); + Append(ccode, Getattr(n, "tdname")); + } + Append(ccode, ";"); + + + /* Strip comments - further code may break in presence of comments. */ + strip_comments(Char(ccode)); + + /* Make all SWIG created typedef structs/unions/classes unnamed else + redefinition errors occur - nasty hack alert.*/ + if (!noTypedef) { + const char* types_array[3] = {"struct", "union", "class"}; + for (int i = 0; i < 3; i++) { + char* code_ptr = Char(ccode); + while (code_ptr) { + /* Replace struct name (as in 'struct name {...}' ) with whitespace + name will be between struct and opening brace */ + + code_ptr = strstr(code_ptr, types_array[i]); + if (code_ptr) { + char *open_bracket_pos; + code_ptr += strlen(types_array[i]); + open_bracket_pos = strchr(code_ptr, '{'); + if (open_bracket_pos) { + /* Make sure we don't have something like struct A a; */ + char* semi_colon_pos = strchr(code_ptr, ';'); + if (!(semi_colon_pos && (semi_colon_pos < open_bracket_pos))) + while (code_ptr < open_bracket_pos) + *code_ptr++ = ' '; + } + } + } + } + } + { + /* Remove SWIG directive %constant which may be left in the SWIG created typedefs */ + char* code_ptr = Char(ccode); + while (code_ptr) { + code_ptr = strstr(code_ptr, "%constant"); + if (code_ptr) { + char* directive_end_pos = strchr(code_ptr, ';'); + if (directive_end_pos) { + while (code_ptr <= directive_end_pos) + *code_ptr++ = ' '; + } + } + } + } + Node *newnode = NewHash(); + set_nodeType(newnode ,"insert"); + Setfile(newnode ,Getfile(n)); + Setline(newnode ,Getline(n)); + String *code = NewStringEmpty(); + Wrapper_pretty_print(ccode, code); + Setattr(newnode, "code", code); + Delete(code); + Delattr(n, "code"); + return newnode; +} + +static void insertNodeAfter(Node *n, Node* c) +{ + Node* g = parentNode(n); + set_parentNode(c, g); + Node* ns = nextSibling(n); + if (Node* outer = Getattr(c, "nested:outer")) { + while (ns && outer == Getattr(ns, "nested:outer")) { + n = ns; + ns = nextSibling(n); + } + } + if (!ns) { + set_lastChild(g, c); + } + else { + set_nextSibling(c, ns); + set_previousSibling(ns, c); + } + set_nextSibling(n, c); + set_previousSibling(c, n); +} + +void Swig_name_unnamed_c_structs(Node *n) { + if (!classhash) + classhash = Getattr(n, "classes"); + Node* c = firstChild(n); + while (c) { + Node* next = nextSibling(c); + if (String* declName = Getattr(c, "nested:unnamed")) { + if (Node* outer = Getattr(c, "nested:outer")) { + // generate a name + String* name = NewStringf("%s_%s", Getattr(outer, "name"), declName); + Delattr(c, "nested:unnamed"); + // set the name to the class and symbol table + Setattr(c, "tdname", name); + Setattr(c, "name", name); + Swig_symbol_setscope(Getattr(c,"symtab")); + Swig_symbol_setscopename(name); + // now that we have a name - gather base symbols + if (List* publicBases = Getattr(c,"baselist")) { + List* bases = Swig_make_inherit_list(name, publicBases, 0); + Swig_inherit_base_symbols(bases); + Delete(bases); + } + Setattr(classhash,name,c); + Swig_symbol_popscope(); + // process declarations following this type (assign correct new type) + SwigType* ty = Copy(name); + Node* decl = nextSibling(c); + List* declList = NewList(); + while (decl && Getattr(decl, "nested:unnamedtype") == c) { + Setattr(decl, "type", ty); + Append(declList, decl); + Delattr(decl, "nested:unnamedtype"); + SetFlag(decl, "feature:immutable"); + add_symbols_c(decl); + decl = nextSibling(decl); + } + Delete(ty); + // Check for extensions +/* // TODO: we can save extensions hash like class hash and move check_extensions() after nesting processing + if (extendhash) { + if (Node *am = Getattr(extendhash, name)) { + // Merge the extension into the symbol table + merge_extensions(c, am); + append_previous_extension(c, am); + Delattr(extendhash, clsname); + } + }*/ + Swig_symbol_setscope(Swig_symbol_global_scope()); + add_symbols_c(c); + + Node* ins = create_insert(c); + insertNodeAfter(c, ins); + removeNode(c); + insertNodeAfter(n, c); + Delete(ins); + Delattr(c, "nested:outer"); + }else { + // global unnamed struct - ignore it + c = next; + continue; + } + } else if (CPlusPlusOut) { + if (Getattr(c, "nested:outer")) { + Node* ins = create_insert(c, true); + insertNodeAfter(c, ins); + Delete(ins); + Delattr(c, "nested:outer"); + } + } + // process children + Swig_name_unnamed_c_structs(c); + c = next; + } +} +static void remove_outer_class_reference(Node *n) +{ + for (Node* c = firstChild(n); c; c = nextSibling(c)) { + if (GetFlag(c, "feature:flatnested")) { + Delattr(c, "nested:outer"); + remove_outer_class_reference(c); + } + } +} +void Swig_process_nested_classes(Node *n) { + Node* c = firstChild(n); + while (c) { + Node* next = nextSibling(c); + if (!Getattr(c,"templatetype")) { + if (GetFlag(c, "nested") && GetFlag(c, "feature:flatnested")) { + removeNode(c); + if (!checkAttribute(c, "access", "public")) + SetFlag(c, "feature:ignore"); + else + insertNodeAfter(n, c); + } + Swig_process_nested_classes(c); + } + c = next; + } + remove_outer_class_reference(n); +} diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index 119f816dc..d860a8b00 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -1648,6 +1648,71 @@ void Swig_name_inherit(String *base, String *derived) { Swig_name_object_inherit(Swig_cparse_features(), base, derived); } +void Swig_inherit_base_symbols(List* bases) { + if (bases) { + Iterator s; + for (s = First(bases); s.item; s = Next(s)) { + Symtab *st = Getattr(s.item,"symtab"); + if (st) { + Setfile(st,Getfile(s.item)); + Setline(st,Getline(s.item)); + Swig_symbol_inherit(st); + } + } + Delete(bases); + } +} + +List *Swig_make_inherit_list(String *clsname, List *names, String* Namespaceprefix) { + int i, ilen; + String *derived; + List *bases = NewList(); + + if (Namespaceprefix) derived = NewStringf("%s::%s", Namespaceprefix,clsname); + else derived = NewString(clsname); + + ilen = Len(names); + for (i = 0; i < ilen; i++) { + Node *s; + String *base; + String *n = Getitem(names,i); + /* Try to figure out where this symbol is */ + s = Swig_symbol_clookup(n,0); + if (s) { + while (s && (Strcmp(nodeType(s),"class") != 0)) { + /* Not a class. Could be a typedef though. */ + String *storage = Getattr(s,"storage"); + if (storage && (Strcmp(storage,"typedef") == 0)) { + String *nn = Getattr(s,"type"); + s = Swig_symbol_clookup(nn,Getattr(s,"sym:symtab")); + } else { + break; + } + } + if (s && ((Strcmp(nodeType(s),"class") == 0) || (Strcmp(nodeType(s),"template") == 0))) { + String *q = Swig_symbol_qualified(s); + Append(bases,s); + if (q) { + base = NewStringf("%s::%s", q, Getattr(s,"name")); + Delete(q); + } else { + base = NewString(Getattr(s,"name")); + } + } else { + base = NewString(n); + } + } else { + base = NewString(n); + } + if (base) { + Swig_name_inherit(base,derived); + Delete(base); + } + } + return bases; +} + + /* ----------------------------------------------------------------------------- * void Swig_name_str() * diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index 181d9aa74..39eaaf4d4 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -1545,7 +1545,110 @@ int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) { Delete(locator); return 0; } +/* returns raw text between 2 braces, does not change scanner state in any way*/ +String* Scanner_get_raw_text_balanced(Scanner* s, int startchar, int endchar) +{ + String* result = 0; + char c; + int old_line = s->line; + String* old_text = Copy(s->text); + int position = Tell(s->str); + int num_levels = 1; + int state = 0; + char temp[2] = { 0, 0 }; + temp[0] = (char) startchar; + Clear(s->text); + Setfile(s->text, Getfile(s->str)); + Setline(s->text, s->line); + Append(s->text, temp); + while (num_levels > 0) { + if ((c = nextchar(s)) == 0) { + Clear(s->text); + Append(s->text, old_text); + Delete(old_text); + s->line = old_line; + return 0; + } + switch (state) { + case 0: + if (c == startchar) + num_levels++; + else if (c == endchar) + num_levels--; + else if (c == '/') + state = 10; + else if (c == '\"') + state = 20; + else if (c == '\'') + state = 30; + break; + case 10: + if (c == '/') + state = 11; + else if (c == '*') + state = 12; + else if (c == startchar) { + state = 0; + num_levels++; + } + else + state = 0; + break; + case 11: + if (c == '\n') + state = 0; + else + state = 11; + break; + case 12: /* first character inside C comment */ + if (c == '*') + state = 14; + else + state = 13; + break; + case 13: + if (c == '*') + state = 14; + break; + case 14: /* possible end of C comment */ + if (c == '*') + state = 14; + else if (c == '/') + state = 0; + else + state = 13; + break; + case 20: + if (c == '\"') + state = 0; + else if (c == '\\') + state = 21; + break; + case 21: + state = 20; + break; + case 30: + if (c == '\'') + state = 0; + else if (c == '\\') + state = 31; + break; + case 31: + state = 30; + break; + default: + break; + } + } + Seek(s->str, position, SEEK_SET); + result = Copy(s->text); + Clear(s->text); + Append(s->text, old_text); + Delete(old_text); + s->line = old_line; + return result; +} /* ----------------------------------------------------------------------------- * Scanner_isoperator() * diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index b730ab04d..9a4163c2c 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -286,6 +286,8 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name, SwigType *decl); extern void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *namewrn, ParmList *declaratorparms); extern void Swig_name_inherit(String *base, String *derived); + extern List *Swig_make_inherit_list(String *clsname, List *names, String* Namespaceprefix); + extern void Swig_inherit_base_symbols(List* bases); extern int Swig_need_protected(Node *n); extern int Swig_need_name_warning(Node *n); extern int Swig_need_redefined_warn(Node *a, Node *b, int InClass); diff --git a/Source/Swig/swigscan.h b/Source/Swig/swigscan.h index 017ef58d5..6a181f86f 100644 --- a/Source/Swig/swigscan.h +++ b/Source/Swig/swigscan.h @@ -22,6 +22,7 @@ extern int Scanner_token(Scanner *); extern String *Scanner_text(Scanner *); extern void Scanner_skip_line(Scanner *); extern int Scanner_skip_balanced(Scanner *, int startchar, int endchar); +extern String *Scanner_get_raw_text_balanced(Scanner *, int startchar, int endchar); extern void Scanner_set_location(Scanner *, String *file, int line); extern String *Scanner_file(Scanner *); extern int Scanner_line(Scanner *); diff --git a/Source/Swig/swigtree.h b/Source/Swig/swigtree.h index 5decb79e3..4973400d7 100644 --- a/Source/Swig/swigtree.h +++ b/Source/Swig/swigtree.h @@ -38,6 +38,7 @@ extern void appendChild(Node *node, Node *child); extern void prependChild(Node *node, Node *child); extern void removeNode(Node *node); extern Node *copyNode(Node *node); +extern void appendSibling(Node *node, Node *chd); /* Node restoration/restore functions */ diff --git a/Source/Swig/tree.c b/Source/Swig/tree.c index 784d3ab84..79f708d33 100644 --- a/Source/Swig/tree.c +++ b/Source/Swig/tree.c @@ -171,6 +171,25 @@ void prependChild(Node *node, Node *chd) { } } +void appendSibling(Node *node, Node *chd) +{ + Node *parent; + Node* lc = node; + while(nextSibling(lc)) + lc = nextSibling(lc); + set_nextSibling(lc, chd); + set_previousSibling(chd, lc); + parent = parentNode(node); + if (parent) { + while (chd) { + lc = chd; + set_parentNode(chd, parent); + chd = nextSibling(chd); + } + set_lastChild(parent, lc); + } +} + /* ----------------------------------------------------------------------------- * removeNode() * From 44a883a05700d3c74ce6e13aa70a49c4533052d2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 28 Nov 2013 21:01:02 +0000 Subject: [PATCH 0787/1160] Cosmetics/code beautification of nested class support --- Source/CParse/cscanner.c | 8 +- Source/CParse/parser.y | 42 +++--- Source/Modules/allocate.cxx | 2 +- Source/Modules/contract.cxx | 2 +- Source/Modules/csharp.cxx | 27 ++-- Source/Modules/java.cxx | 28 ++-- Source/Modules/lang.cxx | 16 +-- Source/Modules/main.cxx | 16 +-- Source/Modules/typepass.cxx | 277 ++++++++++++++++++------------------ Source/Swig/naming.c | 46 +++--- Source/Swig/scanner.c | 15 +- Source/Swig/swig.h | 4 +- Source/Swig/tree.c | 7 +- 13 files changed, 249 insertions(+), 241 deletions(-) diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index 68b305c90..ee2c49cd4 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -118,7 +118,13 @@ void skip_balanced(int startchar, int endchar) { return; } -String* get_raw_text_balanced(int startchar, int endchar) { +/* ----------------------------------------------------------------------------- + * get_raw_text_balanced() + * + * Returns raw text between 2 braces + * ----------------------------------------------------------------------------- */ + +String *get_raw_text_balanced(int startchar, int endchar) { return Scanner_get_raw_text_balanced(scan, startchar, endchar); } diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index ef7eb81ba..09385f1c0 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -51,7 +51,7 @@ static Node *module_node = 0; static String *Classprefix = 0; static String *Namespaceprefix = 0; static int inclass = 0; -static Node *currentOuterClass = 0; /*for nested classes*/ +static Node *currentOuterClass = 0; /* for nested classes */ static char *last_cpptype = 0; static int inherit_list = 0; static Parm *template_parameters = 0; @@ -233,7 +233,7 @@ static String *feature_identifier_fix(String *s) { } } -static void set_access_mode(Node* n) { +static void set_access_mode(Node *n) { if (cplus_mode == CPLUS_PUBLIC) Setattr(n, "access", "public"); else if (cplus_mode == CPLUS_PROTECTED) @@ -242,7 +242,7 @@ static void set_access_mode(Node* n) { Setattr(n, "access", "private"); } -static void restore_access_mode(Node* n) { +static void restore_access_mode(Node *n) { char* mode = Char(Getattr(n, "access")); if (strcmp(mode, "private") == 0) cplus_mode = CPLUS_PRIVATE; @@ -799,26 +799,26 @@ static String *make_class_name(String *name) { } /* Use typedef name as class name */ -void add_typedef_name(Node* n, Node* decl, String* oldName, Symtab *cscope, String* scpname) -{ - String* class_rename = 0; - SwigType *decltype = Getattr(decl,"decl"); + +void add_typedef_name(Node *n, Node *decl, String *oldName, Symtab *cscope, String *scpname) { + String *class_rename = 0; + SwigType *decltype = Getattr(decl, "decl"); if (!decltype || !Len(decltype)) { String *cname; String *tdscopename; String *class_scope = Swig_symbol_qualifiedscopename(cscope); - String *name = Getattr(decl,"name"); + String *name = Getattr(decl, "name"); cname = Copy(name); - Setattr(n,"tdname",cname); + Setattr(n, "tdname", cname); tdscopename = class_scope ? NewStringf("%s::%s", class_scope, name) : Copy(name); class_rename = Getattr(n, "class_rename"); - if (class_rename && (Strcmp(class_rename,oldName) == 0)) + if (class_rename && (Strcmp(class_rename, oldName) == 0)) Setattr(n, "class_rename", NewString(name)); if (!classes_typedefs) classes_typedefs = NewHash(); if (!Equal(scpname, tdscopename) && !Getattr(classes_typedefs, tdscopename)) { Setattr(classes_typedefs, tdscopename, n); } - Setattr(n,"decl",decltype); + Setattr(n, "decl", decltype); Delete(class_scope); Delete(cname); Delete(tdscopename); @@ -1043,10 +1043,10 @@ static String *resolve_create_node_scope(String *cname) { } /* look for simple typedef name in typedef list */ -String* try_to_find_a_name_for_unnamed_structure(char* storage, Node* decls) { - String* name = 0; - Node* n = decls; - if (storage && (strcmp(storage,"typedef") == 0)) { +String *try_to_find_a_name_for_unnamed_structure(char *storage, Node *decls) { + String *name = 0; + Node *n = decls; + if (storage && (strcmp(storage, "typedef") == 0)) { for (; n; n = nextSibling(n)) { if (!Len(Getattr(n, "decl"))) { name = Copy(Getattr(n, "name")); @@ -1058,9 +1058,9 @@ String* try_to_find_a_name_for_unnamed_structure(char* storage, Node* decls) { } /* traverse copied tree segment, and update outer class links*/ -void update_nested_classes(Node* n) +void update_nested_classes(Node *n) { - Node* c = firstChild(n); + Node *c = firstChild(n); while (c) { if (Getattr(c, "nested:outer")) Setattr(c, "nested:outer", n); @@ -1432,7 +1432,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type cpp_declaration cpp_class_decl cpp_forward_class_decl cpp_template_decl cpp_alternate_rettype; %type cpp_members cpp_member; %type cpp_constructor_decl cpp_destructor_decl cpp_protection_decl cpp_conversion_operator cpp_static_assert; -%type cpp_swig_directive cpp_temp_possible /*cpp_nested*/ cpp_opt_declarators ; +%type cpp_swig_directive cpp_temp_possible cpp_opt_declarators ; %type cpp_using_decl cpp_namespace_decl cpp_catch_decl cpp_lambda_decl; %type kwargs options; @@ -3447,7 +3447,8 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Delete(prefix); inclass = 1; currentOuterClass = $$; - if (CPlusPlusOut) { /* save the structure declaration to declare it in global scope for C++ to see*/ + if (CPlusPlusOut) { + /* save the structure declaration to declare it in global scope for C++ to see */ code = get_raw_text_balanced('{', '}'); Setattr($$, "code", code); Delete(code); @@ -3550,7 +3551,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); if (!cparse_cplusplus && currentOuterClass) { /* nested C structs go into global scope*/ - Node* outer = currentOuterClass; + Node *outer = currentOuterClass; while (Getattr(outer, "nested:outer")) outer = Getattr(outer, "nested:outer"); appendSibling(outer, $$); @@ -4286,7 +4287,6 @@ cpp_member : c_declaration { $$ = $1; } | cpp_conversion_operator { $$ = $1; } | cpp_forward_class_decl { $$ = $1; } | cpp_class_decl { $$ = $1; } -/* | cpp_nested { $$ = $1; }*/ | storage_class idcolon SEMI { $$ = 0; } | cpp_using_decl { $$ = $1; } | cpp_template_decl { $$ = $1; } diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index 4e71711d6..7f1d13678 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -559,7 +559,7 @@ Allocate(): virtual int classDeclaration(Node *n) { Symtab *symtab = Swig_symbol_current(); Swig_symbol_setscope(Getattr(n, "symtab")); - Node* oldInclass = inclass; + Node *oldInclass = inclass; AccessMode oldAcessMode = cplus_mode; if (!CPlusPlus) { diff --git a/Source/Modules/contract.cxx b/Source/Modules/contract.cxx index 981a21883..7e0eaf9e0 100644 --- a/Source/Modules/contract.cxx +++ b/Source/Modules/contract.cxx @@ -343,7 +343,7 @@ int Contracts::namespaceDeclaration(Node *n) { int Contracts::classDeclaration(Node *n) { int ret = SWIG_OK; int oldInClass = InClass; - Node* oldClass = CurrentClass; + Node *oldClass = CurrentClass; InClass = 1; CurrentClass = n; emit_children(n); diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index a0332f1ae..7d3a0ac07 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -19,7 +19,7 @@ /* Hash type used for upcalls from C/C++ */ typedef DOH UpcallData; // insert N tabs before each new line in s -void Swig_offset_string(String* s, int N); +void Swig_offset_string(String *s, int N); class CSHARP:public Language { static const char *usage; @@ -183,7 +183,7 @@ public: String *nspace = Getattr(n, "sym:nspace"); String *symname = Copy(Getattr(n, "sym:name")); if (!GetFlag(n, "feature:flatnested")) { - for (Node* outer_class = Getattr(n, "nested:outer");outer_class;outer_class = Getattr(outer_class, "nested:outer")) { + for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) { Push(symname, "."); Push(symname, Getattr(outer_class, "sym:name")); } @@ -1878,22 +1878,22 @@ public: String *nspace = getNSpace(); File *f_proxy = NULL; // save class local variables - String* old_proxy_class_name = proxy_class_name; - String* old_full_imclass_name = full_imclass_name; - String* old_destructor_call = destructor_call; - String* old_proxy_class_constants_code = proxy_class_constants_code; - String* old_proxy_class_def = proxy_class_def; - String* old_proxy_class_code = proxy_class_code; + String *old_proxy_class_name = proxy_class_name; + String *old_full_imclass_name = full_imclass_name; + String *old_destructor_call = destructor_call; + String *old_proxy_class_constants_code = proxy_class_constants_code; + String *old_proxy_class_def = proxy_class_def; + String *old_proxy_class_code = proxy_class_code; if (proxy_flag) { proxy_class_name = NewString(Getattr(n, "sym:name")); - if (Node* outer = Getattr(n, "nested:outer")) { - String* outerClassesPrefix = Copy(Getattr(outer, "sym:name")); + if (Node *outer = Getattr(n, "nested:outer")) { + String *outerClassesPrefix = Copy(Getattr(outer, "sym:name")); for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) { Push(outerClassesPrefix, "::"); Push(outerClassesPrefix, Getattr(outer, "sym:name")); } - String* fnspace = nspace ? NewStringf("%s::%s", nspace, outerClassesPrefix) : outerClassesPrefix; + String *fnspace = nspace ? NewStringf("%s::%s", nspace, outerClassesPrefix) : outerClassesPrefix; if (!addSymbol(proxy_class_name, n, fnspace)) return SWIG_ERROR; if (nspace) @@ -3458,7 +3458,7 @@ public: String *dirClassName = directorClassName(n); String *smartptr = Getattr(n, "feature:smartptr"); if (!GetFlag(n, "feature:flatnested")) { - for (Node* outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) { + for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) { Push(qualified_classname, "."); Push(qualified_classname, Getattr(outer_class, "sym:name")); @@ -4134,7 +4134,9 @@ public: String *old_director_delegate_instances = director_delegate_instances; String *old_director_method_types = director_method_types; String *old_director_connect_parms = director_connect_parms; + int ret = Language::classDeclaration(n); + // these variables are deleted in emitProxyClassDefAndCPPCasts, hence no Delete here director_callback_typedefs = old_director_callback_typedefs; director_callbacks = old_director_callbacks; @@ -4143,6 +4145,7 @@ public: director_delegate_instances = old_director_delegate_instances; director_method_types = old_director_method_types; director_connect_parms = old_director_connect_parms; + return ret; } diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index a286b5f8e..15199af9e 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -19,7 +19,7 @@ /* Hash type used for upcalls from C/C++ */ typedef DOH UpcallData; // insert N tabs before each new line in s -void Swig_offset_string(String* s, int N); +void Swig_offset_string(String *s, int N); class JAVA:public Language { static const char *usage; @@ -210,7 +210,7 @@ public: String *nspace = Getattr(n, "sym:nspace"); String *symname = Copy(Getattr(n, "sym:name")); if (!GetFlag(n, "feature:flatnested")) { - for (Node* outer_class = Getattr(n, "nested:outer");outer_class;outer_class = Getattr(outer_class, "nested:outer")) { + for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) { Push(symname, "."); Push(symname, Getattr(outer_class, "sym:name")); } @@ -1923,21 +1923,21 @@ public: virtual int classHandler(Node *n) { File *f_proxy = NULL; - String* old_proxy_class_name = proxy_class_name; - String* old_full_proxy_class_name = full_proxy_class_name; - String* old_full_imclass_name = full_imclass_name; - String* old_destructor_call = destructor_call; - String* old_destructor_throws_clause = destructor_throws_clause; - String* old_proxy_class_constants_code = proxy_class_constants_code; - String* old_proxy_class_def = proxy_class_def; - String* old_proxy_class_code = proxy_class_code; + String *old_proxy_class_name = proxy_class_name; + String *old_full_proxy_class_name = full_proxy_class_name; + String *old_full_imclass_name = full_imclass_name; + String *old_destructor_call = destructor_call; + String *old_destructor_throws_clause = destructor_throws_clause; + String *old_proxy_class_constants_code = proxy_class_constants_code; + String *old_proxy_class_def = proxy_class_def; + String *old_proxy_class_code = proxy_class_code; if (proxy_flag) { proxy_class_name = NewString(Getattr(n, "sym:name")); String *nspace = getNSpace(); constructIntermediateClassName(n); - String* outerClassesPrefix = 0; - if (Node* outer = Getattr(n, "nested:outer")) { + String *outerClassesPrefix = 0; + if (Node *outer = Getattr(n, "nested:outer")) { outerClassesPrefix = Copy(Getattr(outer, "sym:name")); for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) { Push(outerClassesPrefix, "."); @@ -1962,7 +1962,7 @@ public: full_proxy_class_name = NewStringf("%s.%s.%s.%s", package, nspace, outerClassesPrefix, proxy_class_name); else full_proxy_class_name = NewStringf("%s.%s.%s", nspace, outerClassesPrefix, proxy_class_name); - }else { + } else { if (package) full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name); else @@ -1972,7 +1972,7 @@ public: if (outerClassesPrefix) { Replaceall(outerClassesPrefix, ".", "::"); - String* fnspace = nspace ? NewStringf("%s::%s", nspace, outerClassesPrefix) : outerClassesPrefix; + String *fnspace = nspace ? NewStringf("%s::%s", nspace, outerClassesPrefix) : outerClassesPrefix; if (!addSymbol(proxy_class_name, n, fnspace)) return SWIG_ERROR; if (nspace) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 89cc17a83..25bf7e804 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -20,7 +20,7 @@ static int director_mode = 0; static int director_protected_mode = 1; static int all_protected_mode = 0; static int naturalvar_mode = 0; -Language* Language::this_ = 0; +Language *Language::this_ = 0; /* Set director_protected_mode */ void Wrapper_director_mode_set(int flag) { @@ -2367,7 +2367,7 @@ int Language::classDeclaration(Node *n) { String *oldClassName = ClassName; String *oldDirectorClassName = DirectorClassName; String *oldNSpace = NSpace; - Node* oldCurrentClass = CurrentClass; + Node *oldCurrentClass = CurrentClass; String *kind = Getattr(n, "kind"); String *name = Getattr(n, "name"); @@ -2390,7 +2390,7 @@ int Language::classDeclaration(Node *n) { return SWIG_NOWRAP; } AccessMode oldAccessMode = cplus_mode; - Node* outerClass = Getattr(n, "nested:outer"); + Node *outerClass = Getattr(n, "nested:outer"); if (outerClass && oldAccessMode != Dispatcher::PUBLIC) return SWIG_NOWRAP; ClassName = Copy(name); @@ -3633,12 +3633,12 @@ Hash *Language::getClassHash() const { } // insert N tabs before each new line in s -void Swig_offset_string(String* s, int N) +void Swig_offset_string(String *s, int N) { // count a number of lines in s int lines = 1; int L = Len(s); - char* start = strchr(Char(s), '\n'); + char *start = strchr(Char(s), '\n'); while (start) { ++lines; start = strchr(start + 1, '\n'); @@ -3647,13 +3647,13 @@ void Swig_offset_string(String* s, int N) if ((Char(s))[L-1] == '\n') --lines; // allocate a temporary storage for a padded string - char* res = (char*)malloc(L + lines * N * 2 + 1); + char *res = (char*)malloc(L + lines * N * 2 + 1); res[L + lines * N * 2] = 0; // copy lines to res, prepending tabs to each line - char* p = res; // output pointer + char *p = res; // output pointer start = Char(s); // start of a current line - char* end = strchr(start, '\n'); // end of a current line + char *end = strchr(start, '\n'); // end of a current line while (end) { memset(p, ' ', N*2); p += N*2; diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index e2ed6a675..5336159af 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -31,8 +31,8 @@ static Language *lang = 0; // Language method int CPlusPlus = 0; extern "C" { - int CPlusPlusOut = 0; // generate C++ declarations for C code -}; + int CPlusPlusOut = 0; // Generate C++ compatible code when wrapping C code +} int Extend = 0; // Extend flag int ForceExtern = 0; // Force extern mode int GenerateDefault = 1; // Generate default constructors @@ -870,18 +870,6 @@ void Swig_flatten_nested() { Delete(fname); Delete(name); Delete(val); - /* - String* name = NewStringEmpty(); - Hash* newname = NewHash(); - Setattr(newname, "name", "$ignore"); - Hash* match = NewHash(); - Setattr(match, "name", "match$nested"); - Setattr(match, "value", "1"); - set_nextSibling(newname, match); - Swig_name_rename_add(0, name, 0, newname, 0); - Delete(name); - Delete(match); - Delete(newname);*/ } diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index e5c6d2c05..6954e0dd2 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -476,11 +476,10 @@ class TypePass:private Dispatcher { if (unnamed && tdname && (Cmp(storage, "typedef") == 0)) { SwigType_typedef(unnamed, tdname); } - // name of the outer class should already be patched to contain it's outer classes names, but not to contain namespaces // namespace name (if present) is added after processing child nodes if (Getattr(n, "nested:outer") && name) { - String* outerName = Getattr(Getattr(n, "nested:outer"), "name"); + String *outerName = Getattr(Getattr(n, "nested:outer"), "name"); name = NewStringf("%s::%s", outerName, name); Setattr(n, "name", name); if (tdname) { @@ -679,7 +678,7 @@ class TypePass:private Dispatcher { if (GetFlag(n, "conversion_operator")) { /* The call to the operator in the generated wrapper must be fully qualified in order to compile */ SwigType *name = Getattr(n, "name"); - SwigType *qualifiedname = Swig_symbol_string_qualify(name,0); + SwigType *qualifiedname = Swig_symbol_string_qualify(name, 0); Clear(name); Append(name, qualifiedname); Delete(qualifiedname); @@ -1116,8 +1115,7 @@ class TypePass:private Dispatcher { * list of overloaded methods we have just added in as child nodes to the "using" node. * The node will still exist, it is just the symbol table linked list of overloaded methods * which is hacked. */ - if (Getattr(n, "sym:overloaded")) - { + if (Getattr(n, "sym:overloaded")) { int cnt = 0; #ifdef DEBUG_OVERLOADED Node *debugnode = n; @@ -1180,7 +1178,7 @@ class TypePass:private Dispatcher { #ifdef DEBUG_OVERLOADED show_overloaded(debugnode); #endif - clean_overloaded(n); // Needed? + clean_overloaded(n); // Needed? } } } @@ -1286,21 +1284,22 @@ void Swig_process_types(Node *n) { } // Nested classes processing section -static Hash* classhash = 0; +static Hash *classhash = 0; -static String *make_name(Node *n, String *name,SwigType *decl) { +static String *make_name(Node *n, String *name, SwigType *decl) { int destructor = name && (*(Char(name)) == '~'); - if (String* yyrename = Getattr(n, "class_rename")) { + if (String *yyrename = Getattr(n, "class_rename")) { String *s = NewString(yyrename); Delattr(n, "class_rename"); - if (destructor && (*(Char(s)) != '~')) { - Insert(s,0,"~"); + if (destructor && (*(Char(s)) != '~')) { + Insert(s, 0, "~"); } return s; } - if (!name) return 0; - return Swig_name_make(n,0,name,decl,0); + if (!name) + return 0; + return Swig_name_make(n, 0, name, decl, 0); } // C version of add_symbols() @@ -1308,73 +1307,74 @@ static void add_symbols_c(Node *n) { String *decl; String *wrn = 0; String *symname = 0; - int iscdecl = Cmp(nodeType(n),"cdecl") == 0; - Setattr(n,"ismember","1"); - Setattr(n,"access", "public"); - if (Getattr(n,"sym:name")) + int iscdecl = Cmp(nodeType(n), "cdecl") == 0; + Setattr(n, "ismember", "1"); + Setattr(n, "access", "public"); + if (Getattr(n, "sym:name")) return; - decl = Getattr(n,"decl"); + decl = Getattr(n, "decl"); if (!SwigType_isfunction(decl)) { - String *name = Getattr(n,"name"); - String *makename = Getattr(n,"parser:makename"); + String *name = Getattr(n, "name"); + String *makename = Getattr(n, "parser:makename"); if (iscdecl) { String *storage = Getattr(n, "storage"); - if (Cmp(storage,"typedef") == 0) { - Setattr(n,"kind","typedef"); + if (Cmp(storage, "typedef") == 0) { + Setattr(n, "kind", "typedef"); } else { - SwigType *type = Getattr(n,"type"); - String *value = Getattr(n,"value"); - Setattr(n,"kind","variable"); + SwigType *type = Getattr(n, "type"); + String *value = Getattr(n, "value"); + Setattr(n, "kind", "variable"); if (value && Len(value)) { - Setattr(n,"hasvalue","1"); + Setattr(n, "hasvalue", "1"); } if (type) { SwigType *ty; SwigType *tmp = 0; if (decl) { ty = tmp = Copy(type); - SwigType_push(ty,decl); + SwigType_push(ty, decl); } else { ty = type; } if (!SwigType_ismutable(ty)) { - SetFlag(n,"hasconsttype"); - SetFlag(n,"feature:immutable"); + SetFlag(n, "hasconsttype"); + SetFlag(n, "feature:immutable"); } - if (tmp) Delete(tmp); + if (tmp) + Delete(tmp); } if (!type) { - Printf(stderr,"notype name %s\n", name); + Printf(stderr, "notype name %s\n", name); } } } Swig_features_get(Swig_cparse_features(), 0, name, 0, n); if (makename) { symname = make_name(n, makename, 0); - Delattr(n,"parser:makename"); /* temporary information, don't leave it hanging around */ + Delattr(n, "parser:makename"); /* temporary information, don't leave it hanging around */ } else { makename = name; symname = make_name(n, makename, 0); } if (!symname) { - symname = Copy(Getattr(n,"unnamed")); + symname = Copy(Getattr(n, "unnamed")); } if (symname) { - wrn = Swig_name_warning(n, 0, symname,0); + wrn = Swig_name_warning(n, 0, symname, 0); } } else { - String *name = Getattr(n,"name"); + String *name = Getattr(n, "name"); SwigType *fdecl = Copy(decl); SwigType *fun = SwigType_pop_function(fdecl); if (iscdecl) { - Setattr(n,"kind","function"); + Setattr(n, "kind", "function"); } - Swig_features_get(Swig_cparse_features(),0,name,fun,n); + Swig_features_get(Swig_cparse_features(), 0, name, fun, n); symname = make_name(n, name, fun); - wrn = Swig_name_warning(n, 0, symname,fun); + wrn = Swig_name_warning(n, 0, symname, fun); Delete(fdecl); Delete(fun); @@ -1382,15 +1382,15 @@ static void add_symbols_c(Node *n) { } if (!symname) return; - if (GetFlag(n,"feature:ignore")) { + if (GetFlag(n, "feature:ignore")) { /* Only add to C symbol table and continue */ Swig_symbol_add(0, n); - } else if (strncmp(Char(symname),"$ignore",7) == 0) { - char *c = Char(symname)+7; - SetFlag(n,"feature:ignore"); + } else if (strncmp(Char(symname), "$ignore", 7) == 0) { + char *c = Char(symname) + 7; + SetFlag(n, "feature:ignore"); if (strlen(c)) { SWIG_WARN_NODE_BEGIN(n); - Swig_warning(0,Getfile(n), Getline(n), "%s\n",c+1); + Swig_warning(0, Getfile(n), Getline(n), "%s\n", c + 1); SWIG_WARN_NODE_END(n); } Swig_symbol_add(0, n); @@ -1398,51 +1398,50 @@ static void add_symbols_c(Node *n) { Node *c; if ((wrn) && (Len(wrn))) { String *metaname = symname; - if (!Getmeta(metaname,"already_warned")) { + if (!Getmeta(metaname, "already_warned")) { SWIG_WARN_NODE_BEGIN(n); - Swig_warning(0,Getfile(n),Getline(n), "%s\n", wrn); + Swig_warning(0, Getfile(n), Getline(n), "%s\n", wrn); SWIG_WARN_NODE_END(n); - Setmeta(metaname,"already_warned","1"); + Setmeta(metaname, "already_warned", "1"); } } - c = Swig_symbol_add(symname,n); + c = Swig_symbol_add(symname, n); if (c != n) { /* symbol conflict attempting to add in the new symbol */ - if (Getattr(n,"sym:weak")) { - Setattr(n,"sym:name",symname); + if (Getattr(n, "sym:weak")) { + Setattr(n, "sym:name", symname); } else { String *e = NewStringEmpty(); String *en = NewStringEmpty(); String *ec = NewStringEmpty(); - int redefined = Swig_need_redefined_warn(n,c,true); + int redefined = Swig_need_redefined_warn(n, c, true); if (redefined) { - Printf(en,"Identifier '%s' redefined (ignored)",symname); - Printf(ec,"previous definition of '%s'",symname); + Printf(en, "Identifier '%s' redefined (ignored)", symname); + Printf(ec, "previous definition of '%s'", symname); } else { - Printf(en,"Redundant redeclaration of '%s'",symname); - Printf(ec,"previous declaration of '%s'",symname); + Printf(en, "Redundant redeclaration of '%s'", symname); + Printf(ec, "previous declaration of '%s'", symname); } - if (Cmp(symname,Getattr(n,"name"))) { - Printf(en," (Renamed from '%s')", SwigType_namestr(Getattr(n,"name"))); + if (Cmp(symname, Getattr(n, "name"))) { + Printf(en, " (Renamed from '%s')", SwigType_namestr(Getattr(n, "name"))); } - Printf(en,","); - if (Cmp(symname,Getattr(c,"name"))) { - Printf(ec," (Renamed from '%s')", SwigType_namestr(Getattr(c,"name"))); + Printf(en, ","); + if (Cmp(symname, Getattr(c, "name"))) { + Printf(ec, " (Renamed from '%s')", SwigType_namestr(Getattr(c, "name"))); } - Printf(ec,"."); + Printf(ec, "."); SWIG_WARN_NODE_BEGIN(n); if (redefined) { - Swig_warning(WARN_PARSE_REDEFINED,Getfile(n),Getline(n),"%s\n",en); - Swig_warning(WARN_PARSE_REDEFINED,Getfile(c),Getline(c),"%s\n",ec); + Swig_warning(WARN_PARSE_REDEFINED, Getfile(n), Getline(n), "%s\n", en); + Swig_warning(WARN_PARSE_REDEFINED, Getfile(c), Getline(c), "%s\n", ec); } else { - Swig_warning(WARN_PARSE_REDUNDANT,Getfile(n),Getline(n),"%s\n",en); - Swig_warning(WARN_PARSE_REDUNDANT,Getfile(c),Getline(c),"%s\n",ec); + Swig_warning(WARN_PARSE_REDUNDANT, Getfile(n), Getline(n), "%s\n", en); + Swig_warning(WARN_PARSE_REDUNDANT, Getfile(c), Getline(c), "%s\n", ec); } SWIG_WARN_NODE_END(n); - Printf(e,"%s:%d:%s\n%s:%d:%s\n",Getfile(n),Getline(n),en, - Getfile(c),Getline(c),ec); - Setattr(n,"error",e); + Printf(e, "%s:%d:%s\n%s:%d:%s\n", Getfile(n), Getline(n), en, Getfile(c), Getline(c), ec); + Setattr(n, "error", e); Delete(e); Delete(en); Delete(ec); @@ -1454,58 +1453,59 @@ static void add_symbols_c(Node *n) { /* Strips C-style and C++-style comments from string in-place. */ static void strip_comments(char *string) { - int state = 0; /* - * 0 - not in comment - * 1 - in c-style comment - * 2 - in c++-style comment - * 3 - in string - * 4 - after reading / not in comments - * 5 - after reading * in c-style comments - * 6 - after reading \ in strings - */ - char * c = string; + int state = 0; + /* + * 0 - not in comment + * 1 - in c-style comment + * 2 - in c++-style comment + * 3 - in string + * 4 - after reading / not in comments + * 5 - after reading * in c-style comments + * 6 - after reading \ in strings + */ + char *c = string; while (*c) { switch (state) { case 0: if (*c == '\"') - state = 3; + state = 3; else if (*c == '/') - state = 4; + state = 4; break; case 1: if (*c == '*') - state = 5; + state = 5; *c = ' '; break; case 2: if (*c == '\n') - state = 0; + state = 0; else - *c = ' '; + *c = ' '; break; case 3: if (*c == '\"') - state = 0; + state = 0; else if (*c == '\\') - state = 6; + state = 6; break; case 4: if (*c == '/') { - *(c-1) = ' '; - *c = ' '; - state = 2; + *(c - 1) = ' '; + *c = ' '; + state = 2; } else if (*c == '*') { - *(c-1) = ' '; - *c = ' '; - state = 1; + *(c - 1) = ' '; + *c = ' '; + state = 1; } else - state = 0; + state = 0; break; case 5: if (*c == '/') - state = 0; + state = 0; else - state = 1; + state = 1; *c = ' '; break; case 6: @@ -1516,11 +1516,10 @@ static void strip_comments(char *string) { } } -// Create an %insert with a typedef to make a new name visible to C -// the code is moved from parser.y, dump_nested() function with minor changes -static Node* create_insert(Node* n, bool noTypedef = false) { +// Create a %insert with a typedef to make a new name visible to C +static Node *create_insert(Node *n, bool noTypedef = false) { // format a typedef - String* ccode = Getattr(n, "code"); + String *ccode = Getattr(n, "code"); Push(ccode, " "); if (noTypedef) { Push(ccode, Getattr(n, "name")); @@ -1534,19 +1533,18 @@ static Node* create_insert(Node* n, bool noTypedef = false) { } Append(ccode, ";"); - /* Strip comments - further code may break in presence of comments. */ strip_comments(Char(ccode)); /* Make all SWIG created typedef structs/unions/classes unnamed else - redefinition errors occur - nasty hack alert.*/ + redefinition errors occur - nasty hack alert. */ if (!noTypedef) { - const char* types_array[3] = {"struct", "union", "class"}; + const char *types_array[3] = { "struct", "union", "class" }; for (int i = 0; i < 3; i++) { - char* code_ptr = Char(ccode); + char *code_ptr = Char(ccode); while (code_ptr) { /* Replace struct name (as in 'struct name {...}' ) with whitespace - name will be between struct and opening brace */ + name will be between struct and opening brace */ code_ptr = strstr(code_ptr, types_array[i]); if (code_ptr) { @@ -1555,7 +1553,7 @@ static Node* create_insert(Node* n, bool noTypedef = false) { open_bracket_pos = strchr(code_ptr, '{'); if (open_bracket_pos) { /* Make sure we don't have something like struct A a; */ - char* semi_colon_pos = strchr(code_ptr, ';'); + char *semi_colon_pos = strchr(code_ptr, ';'); if (!(semi_colon_pos && (semi_colon_pos < open_bracket_pos))) while (code_ptr < open_bracket_pos) *code_ptr++ = ' '; @@ -1566,11 +1564,11 @@ static Node* create_insert(Node* n, bool noTypedef = false) { } { /* Remove SWIG directive %constant which may be left in the SWIG created typedefs */ - char* code_ptr = Char(ccode); + char *code_ptr = Char(ccode); while (code_ptr) { code_ptr = strstr(code_ptr, "%constant"); if (code_ptr) { - char* directive_end_pos = strchr(code_ptr, ';'); + char *directive_end_pos = strchr(code_ptr, ';'); if (directive_end_pos) { while (code_ptr <= directive_end_pos) *code_ptr++ = ' '; @@ -1578,10 +1576,10 @@ static Node* create_insert(Node* n, bool noTypedef = false) { } } } - Node *newnode = NewHash(); - set_nodeType(newnode ,"insert"); - Setfile(newnode ,Getfile(n)); - Setline(newnode ,Getline(n)); + Node *newnode = NewHash(); + set_nodeType(newnode, "insert"); + Setfile(newnode, Getfile(n)); + Setline(newnode, Getline(n)); String *code = NewStringEmpty(); Wrapper_pretty_print(ccode, code); Setattr(newnode, "code", code); @@ -1590,12 +1588,11 @@ static Node* create_insert(Node* n, bool noTypedef = false) { return newnode; } -static void insertNodeAfter(Node *n, Node* c) -{ - Node* g = parentNode(n); +static void insertNodeAfter(Node *n, Node *c) { + Node *g = parentNode(n); set_parentNode(c, g); - Node* ns = nextSibling(n); - if (Node* outer = Getattr(c, "nested:outer")) { + Node *ns = nextSibling(n); + if (Node *outer = Getattr(c, "nested:outer")) { while (ns && outer == Getattr(ns, "nested:outer")) { n = ns; ns = nextSibling(n); @@ -1603,8 +1600,7 @@ static void insertNodeAfter(Node *n, Node* c) } if (!ns) { set_lastChild(g, c); - } - else { + } else { set_nextSibling(c, ns); set_previousSibling(ns, c); } @@ -1615,36 +1611,36 @@ static void insertNodeAfter(Node *n, Node* c) void Swig_name_unnamed_c_structs(Node *n) { if (!classhash) classhash = Getattr(n, "classes"); - Node* c = firstChild(n); + Node *c = firstChild(n); while (c) { - Node* next = nextSibling(c); - if (String* declName = Getattr(c, "nested:unnamed")) { - if (Node* outer = Getattr(c, "nested:outer")) { + Node *next = nextSibling(c); + if (String *declName = Getattr(c, "nested:unnamed")) { + if (Node *outer = Getattr(c, "nested:outer")) { // generate a name - String* name = NewStringf("%s_%s", Getattr(outer, "name"), declName); + String *name = NewStringf("%s_%s", Getattr(outer, "name"), declName); Delattr(c, "nested:unnamed"); // set the name to the class and symbol table Setattr(c, "tdname", name); Setattr(c, "name", name); - Swig_symbol_setscope(Getattr(c,"symtab")); + Swig_symbol_setscope(Getattr(c, "symtab")); Swig_symbol_setscopename(name); // now that we have a name - gather base symbols - if (List* publicBases = Getattr(c,"baselist")) { - List* bases = Swig_make_inherit_list(name, publicBases, 0); + if (List *publicBases = Getattr(c, "baselist")) { + List *bases = Swig_make_inherit_list(name, publicBases, 0); Swig_inherit_base_symbols(bases); Delete(bases); } - Setattr(classhash,name,c); + Setattr(classhash, name, c); Swig_symbol_popscope(); // process declarations following this type (assign correct new type) - SwigType* ty = Copy(name); - Node* decl = nextSibling(c); - List* declList = NewList(); + SwigType *ty = Copy(name); + Node *decl = nextSibling(c); + List *declList = NewList(); while (decl && Getattr(decl, "nested:unnamedtype") == c) { Setattr(decl, "type", ty); Append(declList, decl); Delattr(decl, "nested:unnamedtype"); - SetFlag(decl, "feature:immutable"); + SetFlag(decl, "feature:immutable"); add_symbols_c(decl); decl = nextSibling(decl); } @@ -1662,20 +1658,20 @@ void Swig_name_unnamed_c_structs(Node *n) { Swig_symbol_setscope(Swig_symbol_global_scope()); add_symbols_c(c); - Node* ins = create_insert(c); + Node *ins = create_insert(c); insertNodeAfter(c, ins); removeNode(c); insertNodeAfter(n, c); Delete(ins); Delattr(c, "nested:outer"); - }else { + } else { // global unnamed struct - ignore it c = next; continue; } } else if (CPlusPlusOut) { if (Getattr(c, "nested:outer")) { - Node* ins = create_insert(c, true); + Node *ins = create_insert(c, true); insertNodeAfter(c, ins); Delete(ins); Delattr(c, "nested:outer"); @@ -1686,23 +1682,24 @@ void Swig_name_unnamed_c_structs(Node *n) { c = next; } } -static void remove_outer_class_reference(Node *n) -{ - for (Node* c = firstChild(n); c; c = nextSibling(c)) { + +static void remove_outer_class_reference(Node *n) { + for (Node *c = firstChild(n); c; c = nextSibling(c)) { if (GetFlag(c, "feature:flatnested")) { Delattr(c, "nested:outer"); remove_outer_class_reference(c); } } } + void Swig_process_nested_classes(Node *n) { - Node* c = firstChild(n); + Node *c = firstChild(n); while (c) { - Node* next = nextSibling(c); - if (!Getattr(c,"templatetype")) { + Node *next = nextSibling(c); + if (!Getattr(c, "templatetype")) { if (GetFlag(c, "nested") && GetFlag(c, "feature:flatnested")) { - removeNode(c); - if (!checkAttribute(c, "access", "public")) + removeNode(c); + if (!checkAttribute(c, "access", "public")) SetFlag(c, "feature:ignore"); else insertNodeAfter(n, c); diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index d860a8b00..259676971 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -1648,14 +1648,18 @@ void Swig_name_inherit(String *base, String *derived) { Swig_name_object_inherit(Swig_cparse_features(), base, derived); } -void Swig_inherit_base_symbols(List* bases) { +/* ----------------------------------------------------------------------------- + * Swig_inherit_base_symbols() + * ----------------------------------------------------------------------------- */ + +void Swig_inherit_base_symbols(List *bases) { if (bases) { Iterator s; for (s = First(bases); s.item; s = Next(s)) { - Symtab *st = Getattr(s.item,"symtab"); + Symtab *st = Getattr(s.item, "symtab"); if (st) { - Setfile(st,Getfile(s.item)); - Setline(st,Getline(s.item)); + Setfile(st, Getfile(s.item)); + Setline(st, Getline(s.item)); Swig_symbol_inherit(st); } } @@ -1663,40 +1667,46 @@ void Swig_inherit_base_symbols(List* bases) { } } -List *Swig_make_inherit_list(String *clsname, List *names, String* Namespaceprefix) { +/* ----------------------------------------------------------------------------- + * Swig_make_inherit_list() + * ----------------------------------------------------------------------------- */ + +List *Swig_make_inherit_list(String *clsname, List *names, String *Namespaceprefix) { int i, ilen; String *derived; List *bases = NewList(); - if (Namespaceprefix) derived = NewStringf("%s::%s", Namespaceprefix,clsname); - else derived = NewString(clsname); + if (Namespaceprefix) + derived = NewStringf("%s::%s", Namespaceprefix, clsname); + else + derived = NewString(clsname); ilen = Len(names); for (i = 0; i < ilen; i++) { Node *s; String *base; - String *n = Getitem(names,i); + String *n = Getitem(names, i); /* Try to figure out where this symbol is */ s = Swig_symbol_clookup(n,0); if (s) { - while (s && (Strcmp(nodeType(s),"class") != 0)) { + while (s && (Strcmp(nodeType(s), "class") != 0)) { /* Not a class. Could be a typedef though. */ - String *storage = Getattr(s,"storage"); - if (storage && (Strcmp(storage,"typedef") == 0)) { - String *nn = Getattr(s,"type"); - s = Swig_symbol_clookup(nn,Getattr(s,"sym:symtab")); + String *storage = Getattr(s, "storage"); + if (storage && (Strcmp(storage, "typedef") == 0)) { + String *nn = Getattr(s, "type"); + s = Swig_symbol_clookup(nn, Getattr(s, "sym:symtab")); } else { break; } } - if (s && ((Strcmp(nodeType(s),"class") == 0) || (Strcmp(nodeType(s),"template") == 0))) { + if (s && ((Strcmp(nodeType(s), "class") == 0) || (Strcmp(nodeType(s), "template") == 0))) { String *q = Swig_symbol_qualified(s); - Append(bases,s); + Append(bases, s); if (q) { - base = NewStringf("%s::%s", q, Getattr(s,"name")); + base = NewStringf("%s::%s", q, Getattr(s, "name")); Delete(q); } else { - base = NewString(Getattr(s,"name")); + base = NewString(Getattr(s, "name")); } } else { base = NewString(n); @@ -1705,7 +1715,7 @@ List *Swig_make_inherit_list(String *clsname, List *names, String* Namespacepref base = NewString(n); } if (base) { - Swig_name_inherit(base,derived); + Swig_name_inherit(base, derived); Delete(base); } } diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index 39eaaf4d4..a32828b58 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -1545,13 +1545,18 @@ int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) { Delete(locator); return 0; } -/* returns raw text between 2 braces, does not change scanner state in any way*/ -String* Scanner_get_raw_text_balanced(Scanner* s, int startchar, int endchar) -{ - String* result = 0; + +/* ----------------------------------------------------------------------------- + * Scanner_get_raw_text_balanced() + * + * Returns raw text between 2 braces, does not change scanner state in any way + * ----------------------------------------------------------------------------- */ + +String *Scanner_get_raw_text_balanced(Scanner *s, int startchar, int endchar) { + String *result = 0; char c; int old_line = s->line; - String* old_text = Copy(s->text); + String *old_text = Copy(s->text); int position = Tell(s->str); int num_levels = 1; diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 9a4163c2c..95e3784d9 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -286,8 +286,8 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name, SwigType *decl); extern void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *namewrn, ParmList *declaratorparms); extern void Swig_name_inherit(String *base, String *derived); - extern List *Swig_make_inherit_list(String *clsname, List *names, String* Namespaceprefix); - extern void Swig_inherit_base_symbols(List* bases); + extern List *Swig_make_inherit_list(String *clsname, List *names, String *Namespaceprefix); + extern void Swig_inherit_base_symbols(List *bases); extern int Swig_need_protected(Node *n); extern int Swig_need_name_warning(Node *n); extern int Swig_need_redefined_warn(Node *a, Node *b, int InClass); diff --git a/Source/Swig/tree.c b/Source/Swig/tree.c index 79f708d33..d817f1a85 100644 --- a/Source/Swig/tree.c +++ b/Source/Swig/tree.c @@ -171,11 +171,10 @@ void prependChild(Node *node, Node *chd) { } } -void appendSibling(Node *node, Node *chd) -{ +void appendSibling(Node *node, Node *chd) { Node *parent; - Node* lc = node; - while(nextSibling(lc)) + Node *lc = node; + while (nextSibling(lc)) lc = nextSibling(lc); set_nextSibling(lc, chd); set_previousSibling(chd, lc); From b65ba2a8db43b8fe377caee88fce8aa35bdfbcdb Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 29 Nov 2013 07:33:55 +0000 Subject: [PATCH 0788/1160] Minor code improvements --- Source/CParse/parser.y | 12 ++++++------ Source/Modules/lang.cxx | 2 +- Source/Modules/main.cxx | 12 ++++-------- Source/Swig/naming.c | 3 +-- Source/Swig/swigtree.h | 2 +- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 09385f1c0..a97ac8fd5 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -243,10 +243,10 @@ static void set_access_mode(Node *n) { } static void restore_access_mode(Node *n) { - char* mode = Char(Getattr(n, "access")); - if (strcmp(mode, "private") == 0) + String *mode = Getattr(n, "access"); + if (Strcmp(mode, "private") == 0) cplus_mode = CPLUS_PRIVATE; - else if (strcmp(mode, "protected") == 0) + else if (Strcmp(mode, "protected") == 0) cplus_mode = CPLUS_PROTECTED; else cplus_mode = CPLUS_PUBLIC; @@ -800,7 +800,7 @@ static String *make_class_name(String *name) { /* Use typedef name as class name */ -void add_typedef_name(Node *n, Node *decl, String *oldName, Symtab *cscope, String *scpname) { +static void add_typedef_name(Node *n, Node *decl, String *oldName, Symtab *cscope, String *scpname) { String *class_rename = 0; SwigType *decltype = Getattr(decl, "decl"); if (!decltype || !Len(decltype)) { @@ -1043,7 +1043,7 @@ static String *resolve_create_node_scope(String *cname) { } /* look for simple typedef name in typedef list */ -String *try_to_find_a_name_for_unnamed_structure(char *storage, Node *decls) { +static String *try_to_find_a_name_for_unnamed_structure(const char *storage, Node *decls) { String *name = 0; Node *n = decls; if (storage && (strcmp(storage, "typedef") == 0)) { @@ -1058,7 +1058,7 @@ String *try_to_find_a_name_for_unnamed_structure(char *storage, Node *decls) { } /* traverse copied tree segment, and update outer class links*/ -void update_nested_classes(Node *n) +static void update_nested_classes(Node *n) { Node *c = firstChild(n); while (c) { diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 25bf7e804..5c701bc85 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2391,7 +2391,7 @@ int Language::classDeclaration(Node *n) { } AccessMode oldAccessMode = cplus_mode; Node *outerClass = Getattr(n, "nested:outer"); - if (outerClass && oldAccessMode != Dispatcher::PUBLIC) + if (outerClass && oldAccessMode != PUBLIC) return SWIG_NOWRAP; ClassName = Copy(name); ClassPrefix = Copy(symname); diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index 5336159af..290887c6e 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -862,13 +862,9 @@ void SWIG_getoptions(int argc, char *argv[]) { } } -void Swig_flatten_nested() { - String* name = NewString(""); - String* fname = NewString("feature:flatnested"); - String* val = NewString("1"); - Swig_feature_set(Swig_cparse_features(),name,0,fname, val, 0); - Delete(fname); - Delete(name); +static void flatten_nested() { + String *val = NewString("1"); + Swig_feature_set(Swig_cparse_features(), "", 0, "feature:flatnested", val, 0); Delete(val); } @@ -1167,7 +1163,7 @@ int SWIG_main(int argc, char *argv[], Language *l) { // add "ignore" directive if nested classes are not supported if (!lang->nestedClassesSupported()) - Swig_flatten_nested(); + flatten_nested(); Node *top = Swig_cparse(cpps); diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index 259676971..2921b3c84 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -1683,11 +1683,10 @@ List *Swig_make_inherit_list(String *clsname, List *names, String *Namespacepref ilen = Len(names); for (i = 0; i < ilen; i++) { - Node *s; String *base; String *n = Getitem(names, i); /* Try to figure out where this symbol is */ - s = Swig_symbol_clookup(n,0); + Node *s = Swig_symbol_clookup(n, 0); if (s) { while (s && (Strcmp(nodeType(s), "class") != 0)) { /* Not a class. Could be a typedef though. */ diff --git a/Source/Swig/swigtree.h b/Source/Swig/swigtree.h index 4973400d7..acd0e5e90 100644 --- a/Source/Swig/swigtree.h +++ b/Source/Swig/swigtree.h @@ -38,7 +38,7 @@ extern void appendChild(Node *node, Node *child); extern void prependChild(Node *node, Node *child); extern void removeNode(Node *node); extern Node *copyNode(Node *node); -extern void appendSibling(Node *node, Node *chd); +extern void appendSibling(Node *node, Node *child); /* Node restoration/restore functions */ From 9e2c35f766a01aa96459e2d3ce3f63b8d5aefe2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= Date: Fri, 29 Nov 2013 13:48:07 +0100 Subject: [PATCH 0789/1160] Make string encoding explitic Ruby 2.0 enforces explicit string encodings. The char_constant testcase fails because the internal (SWIG_FromCharPtrAndSize, using rb_str_new) defaults to ASCII-8BIT while the test-suite file defaults to the current shell LOCALE setting. This patch sets the char_constant_runme.rb encoding to ASCII-8BIT. --- Examples/test-suite/ruby/char_constant_runme.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/ruby/char_constant_runme.rb b/Examples/test-suite/ruby/char_constant_runme.rb index 4e9d9d59c..4c56ecbf7 100644 --- a/Examples/test-suite/ruby/char_constant_runme.rb +++ b/Examples/test-suite/ruby/char_constant_runme.rb @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -# +#Encoding: ASCII-8BIT # Put description here # # From 2d518c638c008d12a7cf7e93a7711df34bd60859 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 29 Nov 2013 07:46:48 +0000 Subject: [PATCH 0790/1160] Add C++ nested class example This also reverts the nested class additions to the Java/C# 'class' example so that the 'class' example remains identical across different language modules --- Examples/csharp/check.list | 1 + Examples/csharp/class/example.cxx | 2 +- Examples/csharp/class/example.h | 8 +- Examples/csharp/class/runme.cs | 6 +- Examples/csharp/nested/Makefile | 19 +++ Examples/csharp/nested/example-cs.csproj | 94 +++++++++++++ Examples/csharp/nested/example-vc.vcproj | 158 ++++++++++++++++++++++ Examples/csharp/nested/example.cxx | 62 +++++++++ Examples/csharp/nested/example.h | 48 +++++++ Examples/csharp/nested/example.i | 13 ++ Examples/csharp/nested/example.sln | 30 +++++ Examples/csharp/nested/runme.cs | 27 ++++ Examples/java/check.list | 1 + Examples/java/class/example.cxx | 2 +- Examples/java/class/example.h | 8 +- Examples/java/class/runme.java | 6 +- Examples/java/nested/Makefile | 18 +++ Examples/java/nested/example.cxx | 62 +++++++++ Examples/java/nested/example.dsp | 162 +++++++++++++++++++++++ Examples/java/nested/example.h | 48 +++++++ Examples/java/nested/example.i | 13 ++ Examples/java/nested/runme.java | 32 +++++ 22 files changed, 802 insertions(+), 18 deletions(-) create mode 100644 Examples/csharp/nested/Makefile create mode 100644 Examples/csharp/nested/example-cs.csproj create mode 100644 Examples/csharp/nested/example-vc.vcproj create mode 100644 Examples/csharp/nested/example.cxx create mode 100644 Examples/csharp/nested/example.h create mode 100644 Examples/csharp/nested/example.i create mode 100644 Examples/csharp/nested/example.sln create mode 100644 Examples/csharp/nested/runme.cs create mode 100644 Examples/java/nested/Makefile create mode 100644 Examples/java/nested/example.cxx create mode 100644 Examples/java/nested/example.dsp create mode 100644 Examples/java/nested/example.h create mode 100644 Examples/java/nested/example.i create mode 100644 Examples/java/nested/runme.java diff --git a/Examples/csharp/check.list b/Examples/csharp/check.list index 5454d8531..a530a4b42 100644 --- a/Examples/csharp/check.list +++ b/Examples/csharp/check.list @@ -5,6 +5,7 @@ class enum extend funcptr +nested reference simple template diff --git a/Examples/csharp/class/example.cxx b/Examples/csharp/class/example.cxx index 9b23ea4e6..1e8e203dd 100644 --- a/Examples/csharp/class/example.cxx +++ b/Examples/csharp/class/example.cxx @@ -9,7 +9,7 @@ void Shape::move(double dx, double dy) { y += dy; } -int Shape::Counter::nshapes = 0; +int Shape::nshapes = 0; double Circle::area(void) { return M_PI*radius*radius; diff --git a/Examples/csharp/class/example.h b/Examples/csharp/class/example.h index 430cf47dc..46d901361 100644 --- a/Examples/csharp/class/example.h +++ b/Examples/csharp/class/example.h @@ -2,19 +2,17 @@ class Shape { public: - struct Counter{ - static int nshapes; - }; Shape() { - Counter::nshapes++; + nshapes++; } virtual ~Shape() { - Counter::nshapes--; + 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 { diff --git a/Examples/csharp/class/runme.cs b/Examples/csharp/class/runme.cs index 2b500da5c..9088031d6 100644 --- a/Examples/csharp/class/runme.cs +++ b/Examples/csharp/class/runme.cs @@ -17,9 +17,9 @@ public class runme Console.WriteLine( " Created circle " + c ); Console.WriteLine( " Created square " + s ); - // ----- Access a static member of a nested class ----- + // ----- Access a static member ----- - Console.WriteLine( "\nA total of " + Shape.Counter.nshapes + " shapes were created" ); + Console.WriteLine( "\nA total of " + Shape.nshapes + " shapes were created" ); // ----- Member data access ----- @@ -60,7 +60,7 @@ public class runme // Note: when this using scope is exited the C# Dispose() methods // are called which in turn call the C++ destructors - Console.WriteLine( Shape.Counter.nshapes + " shapes remain" ); + Console.WriteLine( Shape.nshapes + " shapes remain" ); Console.WriteLine( "Goodbye" ); } } diff --git a/Examples/csharp/nested/Makefile b/Examples/csharp/nested/Makefile new file mode 100644 index 000000000..bc3ce8ce8 --- /dev/null +++ b/Examples/csharp/nested/Makefile @@ -0,0 +1,19 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +SWIGOPT = +CSHARPSRCS = *.cs +CSHARPFLAGS= -nologo -out:runme.exe + +check: build + $(MAKE) -f $(TOP)/Makefile csharp_run + +build: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp + $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile + +clean: + $(MAKE) -f $(TOP)/Makefile csharp_clean diff --git a/Examples/csharp/nested/example-cs.csproj b/Examples/csharp/nested/example-cs.csproj new file mode 100644 index 000000000..8004780fb --- /dev/null +++ b/Examples/csharp/nested/example-cs.csproj @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Examples/csharp/nested/example-vc.vcproj b/Examples/csharp/nested/example-vc.vcproj new file mode 100644 index 000000000..5788bc9c7 --- /dev/null +++ b/Examples/csharp/nested/example-vc.vcproj @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Examples/csharp/nested/example.cxx b/Examples/csharp/nested/example.cxx new file mode 100644 index 000000000..03bb74d9e --- /dev/null +++ b/Examples/csharp/nested/example.cxx @@ -0,0 +1,62 @@ +#include "example.h" + +int MotorCar::DesignOpinion::AceDesignCount = 0; +int MotorCar::DesignOpinion::TotalDesignCount = 0; + +int MotorCar::DesignOpinion::PercentScore() { + return AceDesignCount*100/TotalDesignCount; +} + +MotorCar::Wheels::Wheels(Shape shape, size_t count) : shape(shape), count(count) {} + +MotorCar::WindScreen::WindScreen(bool opaque) : opaque(opaque) {} + +MotorCar::MotorCar(const std::string &name, const Wheels &wheels, const WindScreen &windscreen) : name(name), wheels(wheels), windscreen(windscreen) {} + +MotorCar MotorCar::DesignFromComponents(const std::string &name, const Wheels &wheels, const WindScreen &windscreen) { + MotorCar car = MotorCar(name, wheels, windscreen); + DesignOpinion::TotalDesignCount++; + if (car.wheels.Opinion().itrocks && car.windscreen.Opinion().itrocks) + DesignOpinion::AceDesignCount++; + return car; +} + +MotorCar::DesignOpinion MotorCar::Wheels::Opinion() { + DesignOpinion opinion; + opinion.itrocks = true; + if (shape == Square) { + opinion.itrocks = false; + opinion.reason = "you'll have a few issues with wheel rotation"; + } + if (count <= 2) { + opinion.reason += opinion.itrocks ? "" : " and "; + opinion.itrocks = false; + opinion.reason += "a few more wheels are needed for stability"; + } + if (opinion.itrocks) + opinion.reason = "your choice of wheels was top notch"; + + return opinion; +} + +MotorCar::DesignOpinion MotorCar::WindScreen::Opinion() { + DesignOpinion opinion; + opinion.itrocks = !opaque; + opinion.reason = opinion.itrocks ? "the driver will have a commanding view out the window" : "you can't see out the windscreen"; + return opinion; +} + +std::string MotorCar::WillItWork() { + DesignOpinion wh = wheels.Opinion(); + DesignOpinion ws = windscreen.Opinion(); + std::string willit; + if (wh.itrocks && ws.itrocks) { + willit = "Great car design because " + wh.reason + " and " + ws.reason; + } else { + willit = "You need a rethink because "; + willit += wh.itrocks ? "" : wh.reason; + willit += (!wh.itrocks && !ws.itrocks) ? " and " : ""; + willit += ws.itrocks ? "" : ws.reason; + } + return willit; +} diff --git a/Examples/csharp/nested/example.h b/Examples/csharp/nested/example.h new file mode 100644 index 000000000..4fb107cb5 --- /dev/null +++ b/Examples/csharp/nested/example.h @@ -0,0 +1,48 @@ +#include + +/** Design a motor car from various components */ +struct MotorCar { + + /** Information about an opinion of the design of a car component */ + struct DesignOpinion { + bool itrocks; + std::string reason; + static int AceDesignCount; + static int TotalDesignCount; + static int PercentScore(); + }; + + /** Wheels component */ + struct Wheels { + enum Shape { Round, Square }; + Wheels(Shape shape, size_t count); + DesignOpinion Opinion(); + private: + Shape shape; + size_t count; + }; + + /** Windscreen component */ + struct WindScreen { + WindScreen(bool opaque); + DesignOpinion Opinion(); + private: + bool opaque; + }; + + /** Factory method for creating a car */ + static MotorCar DesignFromComponents(const std::string &name, const Wheels &wheels, const WindScreen &windscreen); + + std::string Name() { + return name; + } + + /** Get an overall opinion on the car design */ + std::string WillItWork(); + +private: + MotorCar(const std::string &name, const Wheels &wheels, const WindScreen &windscreen); + std::string name; + Wheels wheels; + WindScreen windscreen; +}; diff --git a/Examples/csharp/nested/example.i b/Examples/csharp/nested/example.i new file mode 100644 index 000000000..c07c1521a --- /dev/null +++ b/Examples/csharp/nested/example.i @@ -0,0 +1,13 @@ +%module example + +// This example shows how wrappers for numerous aspects of C++ nested classes work: +// Nested static and instance variables and methods and nested enums + +%include + +%{ +#include "example.h" +%} + +%include "example.h" + diff --git a/Examples/csharp/nested/example.sln b/Examples/csharp/nested/example.sln new file mode 100644 index 000000000..88995ffd3 --- /dev/null +++ b/Examples/csharp/nested/example.sln @@ -0,0 +1,30 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" + ProjectSection(ProjectDependencies) = postProject + {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/Examples/csharp/nested/runme.cs b/Examples/csharp/nested/runme.cs new file mode 100644 index 000000000..facaefdb7 --- /dev/null +++ b/Examples/csharp/nested/runme.cs @@ -0,0 +1,27 @@ +// This example illustrates how C++ classes can be used from C# using SWIG. +// The C# class gets mapped onto the C++ class and behaves as if it is a C# class. + +using System; + +public class runme +{ + static void Main() + { + MotorCar car1 = MotorCar.DesignFromComponents("Bumpy", new MotorCar.Wheels(MotorCar.Wheels.Shape.Square, 4), new MotorCar.WindScreen(false)); + MotorCar car2 = MotorCar.DesignFromComponents("Wobbly", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 2), new MotorCar.WindScreen(false)); + MotorCar car3 = MotorCar.DesignFromComponents("Batty", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 4), new MotorCar.WindScreen(true)); + MotorCar car4 = MotorCar.DesignFromComponents("Spiffing", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 4), new MotorCar.WindScreen(false)); + + Console.WriteLine("Expert opinion on " + car1.Name() + " : \n " + car1.WillItWork()); + Console.WriteLine("Expert opinion on " + car2.Name() + " : \n " + car2.WillItWork()); + Console.WriteLine("Expert opinion on " + car3.Name() + " : \n " + car3.WillItWork()); + Console.WriteLine("Expert opinion on " + car4.Name() + " : \n " + car4.WillItWork()); + + int count = MotorCar.DesignOpinion.AceDesignCount; + int total = MotorCar.DesignOpinion.TotalDesignCount; + int percent = MotorCar.DesignOpinion.PercentScore(); + Console.WriteLine("Overall opinion rating on car design is " + count + "/" + total + " = " + percent + "%"); + + Console.WriteLine("Single square wheel thoughts: " + new MotorCar.Wheels(MotorCar.Wheels.Shape.Square, 1).Opinion().reason); + } +} diff --git a/Examples/java/check.list b/Examples/java/check.list index 9728342f2..825d04a6d 100644 --- a/Examples/java/check.list +++ b/Examples/java/check.list @@ -7,6 +7,7 @@ extend funcptr multimap native +nested pointer reference simple diff --git a/Examples/java/class/example.cxx b/Examples/java/class/example.cxx index 9b23ea4e6..1e8e203dd 100644 --- a/Examples/java/class/example.cxx +++ b/Examples/java/class/example.cxx @@ -9,7 +9,7 @@ void Shape::move(double dx, double dy) { y += dy; } -int Shape::Counter::nshapes = 0; +int Shape::nshapes = 0; double Circle::area(void) { return M_PI*radius*radius; diff --git a/Examples/java/class/example.h b/Examples/java/class/example.h index 430cf47dc..46d901361 100644 --- a/Examples/java/class/example.h +++ b/Examples/java/class/example.h @@ -2,19 +2,17 @@ class Shape { public: - struct Counter{ - static int nshapes; - }; Shape() { - Counter::nshapes++; + nshapes++; } virtual ~Shape() { - Counter::nshapes--; + 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 { diff --git a/Examples/java/class/runme.java b/Examples/java/class/runme.java index 90844ba23..e1ea0d71c 100644 --- a/Examples/java/class/runme.java +++ b/Examples/java/class/runme.java @@ -21,9 +21,9 @@ public class runme { Square s = new Square(10); System.out.println( " Created square " + s ); - // ----- Access a static member of a nested class ----- + // ----- Access a static member ----- - System.out.println( "\nA total of " + Shape.Counter.getNshapes() + " shapes were created" ); + System.out.println( "\nA total of " + Shape.getNshapes() + " shapes were created" ); // ----- Member data access ----- @@ -64,7 +64,7 @@ public class runme { c.delete(); s.delete(); - System.out.println( Shape.Counter.getNshapes() + " shapes remain" ); + System.out.println( Shape.getNshapes() + " shapes remain" ); System.out.println( "Goodbye" ); } } diff --git a/Examples/java/nested/Makefile b/Examples/java/nested/Makefile new file mode 100644 index 000000000..8f274e7cb --- /dev/null +++ b/Examples/java/nested/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +SWIGOPT = +JAVASRCS = *.java + +check: build + $(MAKE) -f $(TOP)/Makefile java_run + +build: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp + $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + +clean: + $(MAKE) -f $(TOP)/Makefile java_clean diff --git a/Examples/java/nested/example.cxx b/Examples/java/nested/example.cxx new file mode 100644 index 000000000..03bb74d9e --- /dev/null +++ b/Examples/java/nested/example.cxx @@ -0,0 +1,62 @@ +#include "example.h" + +int MotorCar::DesignOpinion::AceDesignCount = 0; +int MotorCar::DesignOpinion::TotalDesignCount = 0; + +int MotorCar::DesignOpinion::PercentScore() { + return AceDesignCount*100/TotalDesignCount; +} + +MotorCar::Wheels::Wheels(Shape shape, size_t count) : shape(shape), count(count) {} + +MotorCar::WindScreen::WindScreen(bool opaque) : opaque(opaque) {} + +MotorCar::MotorCar(const std::string &name, const Wheels &wheels, const WindScreen &windscreen) : name(name), wheels(wheels), windscreen(windscreen) {} + +MotorCar MotorCar::DesignFromComponents(const std::string &name, const Wheels &wheels, const WindScreen &windscreen) { + MotorCar car = MotorCar(name, wheels, windscreen); + DesignOpinion::TotalDesignCount++; + if (car.wheels.Opinion().itrocks && car.windscreen.Opinion().itrocks) + DesignOpinion::AceDesignCount++; + return car; +} + +MotorCar::DesignOpinion MotorCar::Wheels::Opinion() { + DesignOpinion opinion; + opinion.itrocks = true; + if (shape == Square) { + opinion.itrocks = false; + opinion.reason = "you'll have a few issues with wheel rotation"; + } + if (count <= 2) { + opinion.reason += opinion.itrocks ? "" : " and "; + opinion.itrocks = false; + opinion.reason += "a few more wheels are needed for stability"; + } + if (opinion.itrocks) + opinion.reason = "your choice of wheels was top notch"; + + return opinion; +} + +MotorCar::DesignOpinion MotorCar::WindScreen::Opinion() { + DesignOpinion opinion; + opinion.itrocks = !opaque; + opinion.reason = opinion.itrocks ? "the driver will have a commanding view out the window" : "you can't see out the windscreen"; + return opinion; +} + +std::string MotorCar::WillItWork() { + DesignOpinion wh = wheels.Opinion(); + DesignOpinion ws = windscreen.Opinion(); + std::string willit; + if (wh.itrocks && ws.itrocks) { + willit = "Great car design because " + wh.reason + " and " + ws.reason; + } else { + willit = "You need a rethink because "; + willit += wh.itrocks ? "" : wh.reason; + willit += (!wh.itrocks && !ws.itrocks) ? " and " : ""; + willit += ws.itrocks ? "" : ws.reason; + } + return willit; +} diff --git a/Examples/java/nested/example.dsp b/Examples/java/nested/example.dsp new file mode 100644 index 000000000..f52544b95 --- /dev/null +++ b/Examples/java/nested/example.dsp @@ -0,0 +1,162 @@ +# Microsoft Developer Studio Project File - Name="example" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=example - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "example.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "example.mak" CFG="example - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "example - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "example - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "example - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(JAVA_INCLUDE)" /I "$(JAVA_INCLUDE)\win32" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /out:"example.dll" /pdbtype:sept +# Begin Special Build Tool +SOURCE="$(InputPath)" +PostBuild_Desc=Java compile post-build step +PostBuild_Cmds=echo on "%JAVA_BIN%\javac" *.java +# End Special Build Tool + +!ELSEIF "$(CFG)" == "example - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "$(JAVA_INCLUDE)" /I "$(JAVA_INCLUDE)\win32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386 /out:"example.dll" +# Begin Special Build Tool +SOURCE="$(InputPath)" +PostBuild_Desc=Java compile post-build step +PostBuild_Cmds=echo on "%JAVA_BIN%\javac" *.java +# End Special Build Tool + +!ENDIF + +# Begin Target + +# Name "example - Win32 Debug" +# Name "example - Win32 Release" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\example.cxx +# End Source File +# Begin Source File + +SOURCE=.\example_wrap.cxx +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\example.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# Begin Source File + +SOURCE=.\example.i + +!IF "$(CFG)" == "example - Win32 Debug" + +# Begin Custom Build +InputPath=.\example.i +InputName=example + +"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + echo In order to function correctly, please ensure the following environment variables are correctly set: + echo JAVA_INCLUDE: %JAVA_INCLUDE% + echo JAVA_BIN: %JAVA_BIN% + echo on + ..\..\..\swig.exe -c++ -java "$(InputPath)" + +# End Custom Build + +!ELSEIF "$(CFG)" == "example - Win32 Release" + +# Begin Custom Build +InputPath=.\example.i +InputName=example + +"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + echo In order to function correctly, please ensure the following environment variables are correctly set: + echo JAVA_INCLUDE: %JAVA_INCLUDE% + echo JAVA_BIN: %JAVA_BIN% + echo on + ..\..\..\swig.exe -c++ -java "$(InputPath)" + +# End Custom Build + +!ENDIF + +# End Source File +# End Target +# End Project diff --git a/Examples/java/nested/example.h b/Examples/java/nested/example.h new file mode 100644 index 000000000..4fb107cb5 --- /dev/null +++ b/Examples/java/nested/example.h @@ -0,0 +1,48 @@ +#include + +/** Design a motor car from various components */ +struct MotorCar { + + /** Information about an opinion of the design of a car component */ + struct DesignOpinion { + bool itrocks; + std::string reason; + static int AceDesignCount; + static int TotalDesignCount; + static int PercentScore(); + }; + + /** Wheels component */ + struct Wheels { + enum Shape { Round, Square }; + Wheels(Shape shape, size_t count); + DesignOpinion Opinion(); + private: + Shape shape; + size_t count; + }; + + /** Windscreen component */ + struct WindScreen { + WindScreen(bool opaque); + DesignOpinion Opinion(); + private: + bool opaque; + }; + + /** Factory method for creating a car */ + static MotorCar DesignFromComponents(const std::string &name, const Wheels &wheels, const WindScreen &windscreen); + + std::string Name() { + return name; + } + + /** Get an overall opinion on the car design */ + std::string WillItWork(); + +private: + MotorCar(const std::string &name, const Wheels &wheels, const WindScreen &windscreen); + std::string name; + Wheels wheels; + WindScreen windscreen; +}; diff --git a/Examples/java/nested/example.i b/Examples/java/nested/example.i new file mode 100644 index 000000000..c07c1521a --- /dev/null +++ b/Examples/java/nested/example.i @@ -0,0 +1,13 @@ +%module example + +// This example shows how wrappers for numerous aspects of C++ nested classes work: +// Nested static and instance variables and methods and nested enums + +%include + +%{ +#include "example.h" +%} + +%include "example.h" + diff --git a/Examples/java/nested/runme.java b/Examples/java/nested/runme.java new file mode 100644 index 000000000..855dbea91 --- /dev/null +++ b/Examples/java/nested/runme.java @@ -0,0 +1,32 @@ +// This example illustrates wrapping of nested C++ classes + +public class runme { + static { + try { + System.loadLibrary("example"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) + { + MotorCar car1 = MotorCar.DesignFromComponents("Bumpy", new MotorCar.Wheels(MotorCar.Wheels.Shape.Square, 4), new MotorCar.WindScreen(false)); + MotorCar car2 = MotorCar.DesignFromComponents("Wobbly", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 2), new MotorCar.WindScreen(false)); + MotorCar car3 = MotorCar.DesignFromComponents("Batty", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 4), new MotorCar.WindScreen(true)); + MotorCar car4 = MotorCar.DesignFromComponents("Spiffing", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 4), new MotorCar.WindScreen(false)); + + System.out.println("Expert opinion on " + car1.Name() + " : \n " + car1.WillItWork()); + System.out.println("Expert opinion on " + car2.Name() + " : \n " + car2.WillItWork()); + System.out.println("Expert opinion on " + car3.Name() + " : \n " + car3.WillItWork()); + System.out.println("Expert opinion on " + car4.Name() + " : \n " + car4.WillItWork()); + + int count = MotorCar.DesignOpinion.getAceDesignCount(); + int total = MotorCar.DesignOpinion.getTotalDesignCount(); + int percent = MotorCar.DesignOpinion.PercentScore(); + System.out.println("Overall opinion rating on car design is " + count + "/" + total + " = " + percent + "%"); + + System.out.println("Single square wheel thoughts: " + new MotorCar.Wheels(MotorCar.Wheels.Shape.Square, 1).Opinion().getReason()); + } +} From 1c7054b98a1251447ab6fda7904ea0c419396018 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 30 Nov 2013 09:26:49 +0000 Subject: [PATCH 0791/1160] Add in Travis testing for nested branch --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 70cbb2f27..7f868ae91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,3 +57,4 @@ script: branches: only: - master + - nested From 19f202cc163ce24756aa0493936eead05ed8ec8b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 30 Nov 2013 18:01:24 +0000 Subject: [PATCH 0792/1160] C nested struct passed by value example This was causing problems in Octave as wrappers were compiled as C++. Solution has already been committed and required regenerating the inner struct into the global C++ namespace (which is where it is intended to be in C). --- Examples/test-suite/nested_structs.i | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Examples/test-suite/nested_structs.i b/Examples/test-suite/nested_structs.i index 60e34a638..add24ec17 100644 --- a/Examples/test-suite/nested_structs.i +++ b/Examples/test-suite/nested_structs.i @@ -25,3 +25,17 @@ void setValues(struct Outer *outer, int val) { } %} +/* +Below was causing problems in Octave as wrappers were compiled as C++. +Solution requires regenerating the inner struct into +the global C++ namespace (which is where it is intended to be in C). +*/ +%inline %{ +int nestedByVal(struct Named s); +int nestedByPtr(struct Named *s); +%} +%{ +int nestedByVal(struct Named s) { return s.val; } +int nestedByPtr(struct Named *s) { return s->val; } +%} + From df679071681242ec2619c82693f261f1f1c34b80 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 2 Dec 2013 07:06:29 +0000 Subject: [PATCH 0793/1160] Testcase of private nested class usage causing segfault Needs fixing for C#/Java --- Examples/test-suite/common.mk | 1 + Examples/test-suite/nested_private.i | 32 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 Examples/test-suite/nested_private.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index e5127fd0c..5c2aea787 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -84,6 +84,7 @@ CPP_TEST_BROKEN += \ extend_variable \ li_std_vector_ptr \ li_boost_shared_ptr_template \ + nested_private \ overload_complicated \ template_default_pointer \ template_expr \ diff --git a/Examples/test-suite/nested_private.i b/Examples/test-suite/nested_private.i new file mode 100644 index 000000000..a573fdd5a --- /dev/null +++ b/Examples/test-suite/nested_private.i @@ -0,0 +1,32 @@ +%module nested_private + +// segfault due to private nested class usage + +%inline %{ +#include +class MotorCar { + + struct DesignOpinion { + std::string reason; + }; + +public: + struct WindScreen { + WindScreen(bool opaque) : opaque(opaque) {} + DesignOpinion Opinion(); + private: + bool opaque; + }; + + std::string WindScreenOpinion() { + return MotorCar::WindScreen(true).Opinion().reason; + } +}; + +MotorCar::DesignOpinion MotorCar::WindScreen::Opinion() { + DesignOpinion opinion; + opinion.reason = !opaque ? "great design" : "you can't see out the windscreen"; + return opinion; +} + +%} From 9d3fc0069c5e62dff004f951e34bd75b47c397f0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 30 Nov 2013 17:35:15 +0000 Subject: [PATCH 0794/1160] Add a few more types for the code beautifier --- Source/Makefile.am | 2 +- Source/Swig/typemap.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Makefile.am b/Source/Makefile.am index 40fa4d9f2..0c28a95b6 100644 --- a/Source/Makefile.am +++ b/Source/Makefile.am @@ -116,7 +116,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 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 +SWIGTYPEDEFS=-T bool -T File -T DohObjInfo -T Parm -T Language -T List -T Typetab -T ModuleFactory -T ErrorMessageFormat -T Symtab -T Hash -T Scanner -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 DOHObj_or_char -T DOHFile -T DOHString -T DOHString_or_char -T UpcallData INDENTBAKSDIR=../IndentBaks beautify: diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index 981b0b436..0bfbb4bce 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -1200,7 +1200,7 @@ static int typemap_replace_vars(String *s, ParmList *locals, SwigType *type, Swi * creates the local variables. * ------------------------------------------------------------------------ */ -static void typemap_locals(DOHString * s, ParmList *l, Wrapper *f, int argnum) { +static void typemap_locals(String *s, ParmList *l, Wrapper *f, int argnum) { Parm *p; char *new_name; From e1a4e11beaaea4ebe9991ec47be8b559bf48e39f Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Wed, 4 Dec 2013 01:53:42 +0400 Subject: [PATCH 0795/1160] fixed out-of-scope nested class definitions, added a test enabled nested C structs assignment (still disabled for Octave), added Java runtime test fixed nested_private test case for Java & C# --- Examples/test-suite/common.mk | 3 ++- .../test-suite/java/nested_structs_runme.java | 7 +++++++ Examples/test-suite/nested_scope.i | 14 ++++++++++++++ Source/CParse/parser.y | 19 ++++++++++++++----- Source/Modules/csharp.cxx | 2 +- Source/Modules/java.cxx | 2 +- 6 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 Examples/test-suite/nested_scope.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 5c2aea787..e444f869d 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -84,7 +84,6 @@ CPP_TEST_BROKEN += \ extend_variable \ li_std_vector_ptr \ li_boost_shared_ptr_template \ - nested_private \ overload_complicated \ template_default_pointer \ template_expr \ @@ -279,6 +278,8 @@ CPP_TEST_CASES += \ naturalvar_more \ nested_class \ nested_comment \ + nested_private \ + nested_scope \ nested_workaround \ newobject1 \ null_pointer \ diff --git a/Examples/test-suite/java/nested_structs_runme.java b/Examples/test-suite/java/nested_structs_runme.java index 4b713395a..43c5e2897 100644 --- a/Examples/test-suite/java/nested_structs_runme.java +++ b/Examples/test-suite/java/nested_structs_runme.java @@ -33,5 +33,12 @@ public class nested_structs_runme { if (inside2.getVal() != 200) throw new RuntimeException("failed inside2"); if (inside3.getVal() != 200) throw new RuntimeException("failed inside3"); if (inside4.getVal() != 400) throw new RuntimeException("failed inside4"); + + outer.getInner1().setVal(11); + if (inner1.getVal() != 11) throw new RuntimeException("failed inner1 assignment"); + Named named = new Named(); + named.setVal(22); + outer.setInside2(named); + if (outer.getInside2().getVal() != 22) throw new RuntimeException("failed inside2 assignment"); } } diff --git a/Examples/test-suite/nested_scope.i b/Examples/test-suite/nested_scope.i new file mode 100644 index 000000000..358dbbb61 --- /dev/null +++ b/Examples/test-suite/nested_scope.i @@ -0,0 +1,14 @@ +%module nested_scope + +%inline %{ +namespace ns { + struct Global { + struct Outer { + struct Nested; + }; + struct Outer::Nested { + int data; + } instance; + }; +} +%} \ No newline at end of file diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index a97ac8fd5..7a3fc1a29 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3387,6 +3387,8 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { /* If the class name is qualified. We need to create or lookup namespace/scope entries */ scope = resolve_create_node_scope($3); + /* save nscope_inner to the class - it may be overwritten in nested classes*/ + Setattr($$, "nested:innerscope", nscope_inner); Setfile(scope,cparse_file); Setline(scope,cparse_line); $3 = scope; @@ -3462,6 +3464,10 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { (void) $6; $$ = currentOuterClass; currentOuterClass = Getattr($$, "nested:outer"); + nscope_inner = Getattr($$, "nested:innerscope"); + Delattr($$, "nested:innerscope"); + if (nscope_inner) /*actual parent class for this class*/ + Setattr($$, "nested:outer", nscope_inner); if (!currentOuterClass) inclass = 0; cscope = Getattr($$, "prev_symtab"); @@ -3490,14 +3496,16 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { if (am) append_previous_extension($$,am); p = $9; - if (p) { + if (p && !nscope_inner) { if (!cparse_cplusplus && currentOuterClass) appendChild(currentOuterClass, p); else appendSibling($$, p); } - if (cparse_cplusplus && !cparse_externc) { + if (nscope_inner) { + ty = NewString(scpname); /* if the class is declared out of scope, let the declarator use fully qualified type*/ + } else if (cparse_cplusplus && !cparse_externc) { ty = NewString($3); } else { ty = NewStringf("%s %s", $2,$3); @@ -3505,7 +3513,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { while (p) { Setattr(p,"storage",$1); Setattr(p,"type",ty); - if (!cparse_cplusplus) { + if (!cparse_cplusplus && currentOuterClass && (!Getattr(currentOuterClass, "name") || CPlusPlusOut)) { SetFlag(p,"hasconsttype"); SetFlag(p,"feature:immutable"); } @@ -3539,12 +3547,13 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); add_symbols($$); - if (nscope) $$ = nscope; /* but the variable definition in the current scope */ Swig_symbol_setscope(cscope); Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); add_symbols($9); + nscope_inner = 0; + $$ = $9; } else { Delete(yyrename); yyrename = 0; @@ -3657,7 +3666,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { while (n) { Setattr(n,"storage",$1); Setattr(n, "type", ty); - if (!cparse_cplusplus) { + if (!cparse_cplusplus && currentOuterClass && (!Getattr(currentOuterClass, "name") || CPlusPlusOut)) { SetFlag(n,"hasconsttype"); SetFlag(n,"feature:immutable"); } diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 7d3a0ac07..88dbfbad7 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -182,7 +182,7 @@ public: if (!proxyname) { String *nspace = Getattr(n, "sym:nspace"); String *symname = Copy(Getattr(n, "sym:name")); - if (!GetFlag(n, "feature:flatnested")) { + if (symname && !GetFlag(n, "feature:flatnested")) { for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) { Push(symname, "."); Push(symname, Getattr(outer_class, "sym:name")); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 15199af9e..f781f0c39 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -209,7 +209,7 @@ public: if (!proxyname || jnidescriptor) { String *nspace = Getattr(n, "sym:nspace"); String *symname = Copy(Getattr(n, "sym:name")); - if (!GetFlag(n, "feature:flatnested")) { + if (symname && !GetFlag(n, "feature:flatnested")) { for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) { Push(symname, "."); Push(symname, Getattr(outer_class, "sym:name")); From ed28725a15fb2b0a967e3e049a1bd43429e1a336 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 27 Nov 2013 15:44:46 +0100 Subject: [PATCH 0796/1160] Add std_auto_ptr.i defining typemaps for returning std::auto_ptr<>. These typemaps are currently defined for C#, Java and Python only and the tests are provided only for these languages. Also add a brief description of the new header to the documentation. --- CHANGES.current | 3 + Doc/Manual/Library.html | 51 +++++++++++++++++ Examples/test-suite/common.mk | 1 + .../csharp/li_std_auto_ptr_runme.cs | 37 ++++++++++++ .../java/li_std_auto_ptr_runme.java | 48 ++++++++++++++++ Examples/test-suite/li_std_auto_ptr.i | 56 +++++++++++++++++++ .../python/li_std_auto_ptr_runme.py | 17 ++++++ Lib/csharp/std_auto_ptr.i | 25 +++++++++ Lib/java/std_auto_ptr.i | 27 +++++++++ Lib/python/std_auto_ptr.i | 17 ++++++ 10 files changed, 282 insertions(+) create mode 100644 Examples/test-suite/csharp/li_std_auto_ptr_runme.cs create mode 100644 Examples/test-suite/java/li_std_auto_ptr_runme.java create mode 100644 Examples/test-suite/li_std_auto_ptr.i create mode 100644 Examples/test-suite/python/li_std_auto_ptr_runme.py create mode 100644 Lib/csharp/std_auto_ptr.i create mode 100644 Lib/java/std_auto_ptr.i create mode 100644 Lib/python/std_auto_ptr.i diff --git a/CHANGES.current b/CHANGES.current index c587ff07f..f3d9130a4 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-11-27: vadz + Add std_auto_ptr.i defining typemaps for returning std::auto_ptr<>. + 2013-11-09: wsfulton [C#] Apply patch #79 from Brant Kyser - Remove using directives from the generated C# code and fully qualify the use of all .NET diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html index 1ae3c77a3..c23900614 100644 --- a/Doc/Manual/Library.html +++ b/Doc/Manual/Library.html @@ -31,6 +31,7 @@
    • std::vector
    • STL exceptions
    • shared_ptr smart pointer +
    • auto_ptr smart pointer
  • Utility Libraries
      @@ -1383,6 +1384,7 @@ The following table shows which C++ classes are supported and the equivalent SWI
  • + @@ -1874,6 +1876,55 @@ Adding the missing %shared_ptr macros will fix this: Note: There is currently no support for %shared_ptr and the director feature. + +

    8.4.5 auto_ptr smart pointer

    + +

    +While std::auto_ptr is deprecated in C++11, some existing code may +still be using it, so SWIG provides limited support for this class: +std_auto_ptr.i defines the typemaps which apply to the functions +returning objects of this type. Any other use of std_auto_ptr.i is not +directly supported. +

    + +

    +A typical example of use would be +

    +
    +
    +%include <std_auto_ptr.i>
    +
    +%auto_ptr(Klass)
    +%inline %{
    +class Klass {
    +public:
    +  // Factory function creating objects of this class:
    +  static std::auto_ptr<Klass> Create(int value) {
    +    return std::auto_ptr<Klass>(new Klass(value));
    +  }
    +
    +  int getValue() const { return m_value; }
    +
    +private:
    +  DerivedIntValue(int value) : m_value(value) {}
    +  int m_value;
    +};
    +%}
    +
    +
    + +

    +The returned objects can be used naturally from the target language, e.g. from +C#: +

    + +
    +
    +Klass k = Klass.Create(17);
    +int value = k.getValue();
    +
    +
    +

    8.5 Utility Libraries

    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index e5127fd0c..e9caaedab 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -246,6 +246,7 @@ CPP_TEST_CASES += \ li_carrays \ li_cdata \ li_cpointer \ + li_std_auto_ptr \ li_stdint \ li_typemaps \ li_typemaps_apply \ diff --git a/Examples/test-suite/csharp/li_std_auto_ptr_runme.cs b/Examples/test-suite/csharp/li_std_auto_ptr_runme.cs new file mode 100644 index 000000000..bea92d2f4 --- /dev/null +++ b/Examples/test-suite/csharp/li_std_auto_ptr_runme.cs @@ -0,0 +1,37 @@ +using System; +using li_std_auto_ptrNamespace; + +public class li_std_auto_ptr_runme { + private static void WaitForGC() + { + System.GC.Collect(); + System.GC.WaitForPendingFinalizers(); + System.Threading.Thread.Sleep(10); + } + + public static void Main() + { + Klass k1 = li_std_auto_ptr.makeKlassAutoPtr("first"); + if (k1.getLabel() != "first") + throw new Exception("wrong object label"); + + Klass k2 = li_std_auto_ptr.makeKlassAutoPtr("second"); + if (Klass.getTotal_count() != 2) + throw new Exception("number of objects should be 2"); + + k1 = null; + WaitForGC(); + + if (Klass.getTotal_count() != 1) + throw new Exception("number of objects should be 1"); + + if (k2.getLabel() != "second") + throw new Exception("wrong object label"); + + k2 = null; + WaitForGC(); + + if (Klass.getTotal_count() != 0) + throw new Exception("no objects should be left"); + } +} diff --git a/Examples/test-suite/java/li_std_auto_ptr_runme.java b/Examples/test-suite/java/li_std_auto_ptr_runme.java new file mode 100644 index 000000000..eac7cacfc --- /dev/null +++ b/Examples/test-suite/java/li_std_auto_ptr_runme.java @@ -0,0 +1,48 @@ +import li_std_auto_ptr.*; + +public class li_std_auto_ptr_runme { + static { + try { + System.loadLibrary("li_std_auto_ptr"); + } 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); + } + } + + private static void WaitForGC() + { + System.gc(); + System.runFinalization(); + try { + java.lang.Thread.sleep(1); + } catch (java.lang.InterruptedException e) { + } + } + + public static void main(String argv[]) throws Throwable + { + Klass k1 = li_std_auto_ptr.makeKlassAutoPtr("first"); + if (!k1.getLabel().equals("first")) + throw new RuntimeException("wrong object label"); + + Klass k2 = li_std_auto_ptr.makeKlassAutoPtr("second"); + if (Klass.getTotal_count() != 2) + throw new RuntimeException("number of objects should be 2"); + + k1 = null; + WaitForGC(); + + if (Klass.getTotal_count() != 1) + throw new RuntimeException("number of objects should be 1"); + + if (!k2.getLabel().equals("second")) + throw new RuntimeException("wrong object label"); + + k2 = null; + WaitForGC(); + + if (Klass.getTotal_count() != 0) + throw new RuntimeException("no objects should be left"); + } +} diff --git a/Examples/test-suite/li_std_auto_ptr.i b/Examples/test-suite/li_std_auto_ptr.i new file mode 100644 index 000000000..b58a1d79d --- /dev/null +++ b/Examples/test-suite/li_std_auto_ptr.i @@ -0,0 +1,56 @@ +%module li_std_auto_ptr + +#if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPYTHON) + +%include "std_auto_ptr.i" + +%auto_ptr(Klass) + +%inline %{ + +#include +#include +#include "swig_examples_lock.h" + +class Klass { +public: + explicit Klass(const char* label) : + m_label(label) + { + SwigExamples::Lock lock(critical_section); + total_count++; + } + + const char* getLabel() const { return m_label.c_str(); } + + ~Klass() + { + SwigExamples::Lock lock(critical_section); + total_count--; + } + + static int getTotal_count() { return total_count; } + +private: + static SwigExamples::CriticalSection critical_section; + static int total_count; + + std::string m_label; +}; + +SwigExamples::CriticalSection Klass::critical_section; +int Klass::total_count = 0; + +%} + +%template(KlassAutoPtr) std::auto_ptr; + +%inline %{ + +std::auto_ptr makeKlassAutoPtr(const char* label) { + return std::auto_ptr(new Klass(label)); +} + +%} + +#endif diff --git a/Examples/test-suite/python/li_std_auto_ptr_runme.py b/Examples/test-suite/python/li_std_auto_ptr_runme.py new file mode 100644 index 000000000..a29771479 --- /dev/null +++ b/Examples/test-suite/python/li_std_auto_ptr_runme.py @@ -0,0 +1,17 @@ +from li_std_auto_ptr import * + +k1 = makeKlassAutoPtr("first") +k2 = makeKlassAutoPtr("second") +if Klass.getTotal_count() != 2: + raise "number of objects should be 2" + +del k1 +if Klass.getTotal_count() != 1: + raise "number of objects should be 1" + +if k2.getLabel() != "second": + raise "wrong object label" + +del k2 +if Klass.getTotal_count() != 0: + raise "no objects should be left" diff --git a/Lib/csharp/std_auto_ptr.i b/Lib/csharp/std_auto_ptr.i new file mode 100644 index 000000000..d7e5f167e --- /dev/null +++ b/Lib/csharp/std_auto_ptr.i @@ -0,0 +1,25 @@ +/* + The typemaps here allow to handle functions returning std::auto_ptr<>, + which is the most common use of this type. If you have functions taking it + as parameter, these typemaps can't be used for them and you need to do + something else (e.g. use shared_ptr<> which SWIG supports fully). + */ + +%define %auto_ptr(TYPE) +%typemap (ctype) std::auto_ptr "void *" +%typemap (imtype, out="System.IntPtr") std::auto_ptr "HandleRef" +%typemap (cstype) std::auto_ptr "$typemap(cstype, TYPE)" +%typemap (out) std::auto_ptr %{ + $result = (void *)$1.release(); +%} +%typemap(csout, excode=SWIGEXCODE) std::auto_ptr { + System.IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + return ret; + } +%template() std::auto_ptr; +%enddef + +namespace std { + template class auto_ptr {}; +} diff --git a/Lib/java/std_auto_ptr.i b/Lib/java/std_auto_ptr.i new file mode 100644 index 000000000..9b3cd7315 --- /dev/null +++ b/Lib/java/std_auto_ptr.i @@ -0,0 +1,27 @@ +/* + The typemaps here allow to handle functions returning std::auto_ptr<>, + which is the most common use of this type. If you have functions taking it + as parameter, these typemaps can't be used for them and you need to do + something else (e.g. use shared_ptr<> which SWIG supports fully). + */ + +%define %auto_ptr(TYPE) +%typemap (jni) std::auto_ptr "jlong" +%typemap (jtype) std::auto_ptr "long" +%typemap (jstype) std::auto_ptr "$typemap(jstype, TYPE)" + +%typemap (out) std::auto_ptr %{ + jlong lpp = 0; + *(TYPE**) &lpp = $1.release(); + $result = lpp; +%} +%typemap(javaout) std::auto_ptr { + long cPtr = $jnicall; + return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); + } +%template() std::auto_ptr; +%enddef + +namespace std { + template class auto_ptr {}; +} diff --git a/Lib/python/std_auto_ptr.i b/Lib/python/std_auto_ptr.i new file mode 100644 index 000000000..e310e00c8 --- /dev/null +++ b/Lib/python/std_auto_ptr.i @@ -0,0 +1,17 @@ +/* + The typemaps here allow to handle functions returning std::auto_ptr<>, + which is the most common use of this type. If you have functions taking it + as parameter, these typemaps can't be used for them and you need to do + something else (e.g. use shared_ptr<> which SWIG supports fully). + */ + +%define %auto_ptr(TYPE) +%typemap (out) std::auto_ptr %{ + %set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags)); +%} +%template() std::auto_ptr; +%enddef + +namespace std { + template class auto_ptr {}; +} From 6624f66af5534b9284a62a7be2a3dca3952d95f6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 3 Dec 2013 23:46:13 +0100 Subject: [PATCH 0797/1160] Just a correction to the last commit changelog entry. Mention the target languages affected. --- CHANGES.current | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index f3d9130a4..a4d12239d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -6,7 +6,7 @@ Version 3.0.0 (in progress) ============================ 2013-11-27: vadz - Add std_auto_ptr.i defining typemaps for returning std::auto_ptr<>. + [C#, Java, Python] Add std_auto_ptr.i defining typemaps for returning std::auto_ptr<>. 2013-11-09: wsfulton [C#] Apply patch #79 from Brant Kyser From b175df4e5f906741b5c0b44530b42f62b9699184 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 3 Dec 2013 23:24:17 +0000 Subject: [PATCH 0798/1160] C++11 alias templates seg fault fix Segfault fix when using alias templates, reported by Pierre-Henri Wuillemin --- Examples/test-suite/cpp11_template_typedefs.i | 9 +++++++++ Source/CParse/parser.y | 5 ++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/cpp11_template_typedefs.i b/Examples/test-suite/cpp11_template_typedefs.i index ea46706a9..d6a1a3c85 100644 --- a/Examples/test-suite/cpp11_template_typedefs.i +++ b/Examples/test-suite/cpp11_template_typedefs.i @@ -2,6 +2,7 @@ %module cpp11_template_typedefs %warnfilter(SWIGWARN_CPP11_ALIAS_TEMPLATE) TypedefName; +%warnfilter(SWIGWARN_CPP11_ALIAS_TEMPLATE) MyIntKeyClass; %warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) PF; %inline %{ @@ -19,5 +20,13 @@ using TypedefName = SomeType; // type aliasing typedef void (*PFD)(double); // Old style using PF = void (*)(double); // New introduced syntax + + +// use of template aliasing +template +class MyCPP11Class { +}; +template using MyIntKeyClass = MyCPP11Class; +MyIntKeyClass intchar; %} diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index caac88e4d..1606dc249 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3208,16 +3208,15 @@ c_declaration : c_decl { $$ = 0; /* TODO - ignored for now */ } - | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL { + | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL ID { skip_decl(); $$ = new_node("using"); + Setattr($$,"uname",$8); Setattr($$,"name",$6); add_symbols($$); SWIG_WARN_NODE_BEGIN($$); Swig_warning(WARN_CPP11_ALIAS_TEMPLATE, cparse_file, cparse_line, "The 'using' keyword in template aliasing is not fully supported yet.\n"); SWIG_WARN_NODE_END($$); - - $$ = 0; /* TODO - ignored for now */ } ; From 5504bd32017d9265abe43bacf9dbb7d1ecb4400a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 4 Dec 2013 00:24:15 +0000 Subject: [PATCH 0799/1160] decltype fix on missing type info --- Source/CParse/parser.y | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 1606dc249..3384dcc5b 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -6033,6 +6033,7 @@ decltype : DECLTYPE LPAREN idcolon RPAREN { Node *n = Swig_symbol_clookup($3,0); if (!n) { Swig_error(cparse_file, cparse_line, "Identifier %s not defined.\n", $3); + $$ = $3; } else { $$ = Getattr(n, "type"); } From 053c605df047114557613339110367c3ee77ea4e Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Wed, 4 Dec 2013 16:21:33 +0400 Subject: [PATCH 0800/1160] out-of-scope template definitions fixed nested_private test disabled again --- Examples/test-suite/common.mk | 2 +- Source/CParse/parser.y | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index e444f869d..a59fba18b 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -84,6 +84,7 @@ CPP_TEST_BROKEN += \ extend_variable \ li_std_vector_ptr \ li_boost_shared_ptr_template \ + nested_private \ overload_complicated \ template_default_pointer \ template_expr \ @@ -278,7 +279,6 @@ CPP_TEST_CASES += \ naturalvar_more \ nested_class \ nested_comment \ - nested_private \ nested_scope \ nested_workaround \ newobject1 \ diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 7a3fc1a29..cc0d3f4ca 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3389,6 +3389,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { scope = resolve_create_node_scope($3); /* save nscope_inner to the class - it may be overwritten in nested classes*/ Setattr($$, "nested:innerscope", nscope_inner); + Setattr($$, "nested:nscope", nscope); Setfile(scope,cparse_file); Setline(scope,cparse_line); $3 = scope; @@ -3465,8 +3466,10 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { $$ = currentOuterClass; currentOuterClass = Getattr($$, "nested:outer"); nscope_inner = Getattr($$, "nested:innerscope"); + nscope = Getattr($$, "nested:nscope"); Delattr($$, "nested:innerscope"); - if (nscope_inner) /*actual parent class for this class*/ + Delattr($$, "nested:nscope"); + if (nscope_inner && Strcmp(nodeType(nscope_inner), "class") == 0) /* actual parent class for this class */ Setattr($$, "nested:outer", nscope_inner); if (!currentOuterClass) inclass = 0; @@ -3546,14 +3549,21 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Swig_symbol_setscope(Getattr(nscope_inner,"symtab")); Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); + yyrename = Copy(Getattr($$, "class_rename")); add_symbols($$); + Delattr($$, "class_rename"); /* but the variable definition in the current scope */ Swig_symbol_setscope(cscope); Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); add_symbols($9); - nscope_inner = 0; - $$ = $9; + if (nscope) { + $$ = nscope; + if ($9) + appendSibling($$, $9); + } + else if (!SwigType_istemplate(ty) && template_parameters == 0) + $$ = $9; } else { Delete(yyrename); yyrename = 0; From b0afa8a95c5e1958a0f9427f8f86064bb2aa67ea Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Thu, 5 Dec 2013 20:41:22 +0400 Subject: [PATCH 0801/1160] nested private classes are discarded while parsing nested relate functions are moved to nested.cxx and renamed accordingly --- Source/CParse/parser.y | 94 ++++---- Source/Makefile.am | 1 + Source/Modules/main.cxx | 4 +- Source/Modules/nested.cxx | 431 ++++++++++++++++++++++++++++++++++++ Source/Modules/swigmod.h | 4 +- Source/Modules/typepass.cxx | 427 ----------------------------------- 6 files changed, 485 insertions(+), 476 deletions(-) create mode 100644 Source/Modules/nested.cxx diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index cc0d3f4ca..9dfa60099 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3537,58 +3537,62 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { } if (currentOuterClass) restore_access_mode($$); - - Setattr($$,"symtab",Swig_symbol_popscope()); - - Classprefix = Getattr($$,"Classprefix"); - Delattr($$,"Classprefix"); - if (nscope_inner) { - /* this is tricky */ - /* we add the declaration in the original namespace */ - appendChild(nscope_inner,$$); - Swig_symbol_setscope(Getattr(nscope_inner,"symtab")); - Delete(Namespaceprefix); - Namespaceprefix = Swig_symbol_qualifiedscopename(0); - yyrename = Copy(Getattr($$, "class_rename")); - add_symbols($$); - Delattr($$, "class_rename"); - /* but the variable definition in the current scope */ - Swig_symbol_setscope(cscope); - Delete(Namespaceprefix); - Namespaceprefix = Swig_symbol_qualifiedscopename(0); - add_symbols($9); - if (nscope) { - $$ = nscope; - if ($9) - appendSibling($$, $9); - } - else if (!SwigType_istemplate(ty) && template_parameters == 0) - $$ = $9; + if (cplus_mode == CPLUS_PRIVATE) { + $$ = 0; /* skip private nested classes */ } else { - Delete(yyrename); - yyrename = 0; - Delete(Namespaceprefix); - Namespaceprefix = Swig_symbol_qualifiedscopename(0); - if (!cparse_cplusplus && currentOuterClass) { /* nested C structs go into global scope*/ - Node *outer = currentOuterClass; - while (Getattr(outer, "nested:outer")) - outer = Getattr(outer, "nested:outer"); - appendSibling(outer, $$); - add_symbols($9); - set_scope_to_global(); + Setattr($$,"symtab",Swig_symbol_popscope()); + + Classprefix = Getattr($$,"Classprefix"); + Delattr($$,"Classprefix"); + if (nscope_inner) { + /* this is tricky */ + /* we add the declaration in the original namespace */ + if (cplus_mode != CPLUS_PRIVATE) + appendChild(nscope_inner,$$); + Swig_symbol_setscope(Getattr(nscope_inner,"symtab")); Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); yyrename = Copy(Getattr($$, "class_rename")); add_symbols($$); - if (!CPlusPlusOut) - Delattr($$, "nested:outer"); Delattr($$, "class_rename"); - $$ = 0; - } else { - yyrename = Copy(Getattr($$, "class_rename")); - add_symbols($$); + /* but the variable definition in the current scope */ + Swig_symbol_setscope(cscope); + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); add_symbols($9); - Delattr($$, "class_rename"); + if (nscope) { + $$ = nscope; + if ($9) + appendSibling($$, $9); + } + else if (!SwigType_istemplate(ty) && template_parameters == 0) + $$ = $9; + } else { + Delete(yyrename); + yyrename = 0; + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); + if (!cparse_cplusplus && currentOuterClass) { /* nested C structs go into global scope*/ + Node *outer = currentOuterClass; + while (Getattr(outer, "nested:outer")) + outer = Getattr(outer, "nested:outer"); + appendSibling(outer, $$); + add_symbols($9); + set_scope_to_global(); + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); + yyrename = Copy(Getattr($$, "class_rename")); + add_symbols($$); + if (!CPlusPlusOut) + Delattr($$, "nested:outer"); + Delattr($$, "class_rename"); + $$ = 0; + } else { + yyrename = Copy(Getattr($$, "class_rename")); + add_symbols($$); + add_symbols($9); + Delattr($$, "class_rename"); + } } } Swig_symbol_setscope(cscope); diff --git a/Source/Makefile.am b/Source/Makefile.am index 40fa4d9f2..8356081d6 100644 --- a/Source/Makefile.am +++ b/Source/Makefile.am @@ -54,6 +54,7 @@ eswig_SOURCES = CParse/cscanner.c \ Modules/modula3.cxx \ Modules/module.cxx \ Modules/mzscheme.cxx \ + Modules/nested.cxx \ Modules/ocaml.cxx \ Modules/octave.cxx \ Modules/overload.cxx \ diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index 290887c6e..62d9c0c36 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -1178,7 +1178,7 @@ int SWIG_main(int argc, char *argv[], Language *l) { if (!CPlusPlus) { if (Verbose) Printf(stdout, "Processing unnamed structs...\n"); - Swig_name_unnamed_c_structs(top); + Swig_nested_name_unnamed_c_structs(top); } if (Verbose) { @@ -1203,7 +1203,7 @@ int SWIG_main(int argc, char *argv[], Language *l) { if (CPlusPlus) { if (Verbose) Printf(stdout, "Processing nested classes...\n"); - Swig_process_nested_classes(top); + Swig_nested_process_classes(top); } if (dump_top & STAGE3) { diff --git a/Source/Modules/nested.cxx b/Source/Modules/nested.cxx new file mode 100644 index 000000000..4be27ebc4 --- /dev/null +++ b/Source/Modules/nested.cxx @@ -0,0 +1,431 @@ +#include "swigmod.h" +#include "cparse.h" + +// Nested classes processing section +static Hash *classhash = 0; + +static String *make_name(Node *n, String *name, SwigType *decl) { + int destructor = name && (*(Char(name)) == '~'); + if (String *yyrename = Getattr(n, "class_rename")) { + String *s = NewString(yyrename); + Delattr(n, "class_rename"); + if (destructor && (*(Char(s)) != '~')) { + Insert(s, 0, "~"); + } + return s; + } + + if (!name) + return 0; + return Swig_name_make(n, 0, name, decl, 0); +} + +// C version of add_symbols() +static void add_symbols_c(Node *n) { + String *decl; + String *wrn = 0; + String *symname = 0; + int iscdecl = Cmp(nodeType(n), "cdecl") == 0; + Setattr(n, "ismember", "1"); + Setattr(n, "access", "public"); + if (Getattr(n, "sym:name")) + return; + decl = Getattr(n, "decl"); + if (!SwigType_isfunction(decl)) { + String *name = Getattr(n, "name"); + String *makename = Getattr(n, "parser:makename"); + if (iscdecl) { + String *storage = Getattr(n, "storage"); + if (Cmp(storage, "typedef") == 0) { + Setattr(n, "kind", "typedef"); + } else { + SwigType *type = Getattr(n, "type"); + String *value = Getattr(n, "value"); + Setattr(n, "kind", "variable"); + if (value && Len(value)) { + Setattr(n, "hasvalue", "1"); + } + if (type) { + SwigType *ty; + SwigType *tmp = 0; + if (decl) { + ty = tmp = Copy(type); + SwigType_push(ty, decl); + } else { + ty = type; + } + if (!SwigType_ismutable(ty)) { + SetFlag(n, "hasconsttype"); + SetFlag(n, "feature:immutable"); + } + if (tmp) + Delete(tmp); + } + if (!type) { + Printf(stderr, "notype name %s\n", name); + } + } + } + Swig_features_get(Swig_cparse_features(), 0, name, 0, n); + if (makename) { + symname = make_name(n, makename, 0); + Delattr(n, "parser:makename"); /* temporary information, don't leave it hanging around */ + } else { + makename = name; + symname = make_name(n, makename, 0); + } + + if (!symname) { + symname = Copy(Getattr(n, "unnamed")); + } + if (symname) { + wrn = Swig_name_warning(n, 0, symname, 0); + } + } else { + String *name = Getattr(n, "name"); + SwigType *fdecl = Copy(decl); + SwigType *fun = SwigType_pop_function(fdecl); + if (iscdecl) { + Setattr(n, "kind", "function"); + } + + Swig_features_get(Swig_cparse_features(), 0, name, fun, n); + + symname = make_name(n, name, fun); + wrn = Swig_name_warning(n, 0, symname, fun); + + Delete(fdecl); + Delete(fun); + + } + if (!symname) + return; + if (GetFlag(n, "feature:ignore")) { + /* Only add to C symbol table and continue */ + Swig_symbol_add(0, n); + } else if (strncmp(Char(symname), "$ignore", 7) == 0) { + char *c = Char(symname) + 7; + SetFlag(n, "feature:ignore"); + if (strlen(c)) { + SWIG_WARN_NODE_BEGIN(n); + Swig_warning(0, Getfile(n), Getline(n), "%s\n", c + 1); + SWIG_WARN_NODE_END(n); + } + Swig_symbol_add(0, n); + } else { + Node *c; + if ((wrn) && (Len(wrn))) { + String *metaname = symname; + if (!Getmeta(metaname, "already_warned")) { + SWIG_WARN_NODE_BEGIN(n); + Swig_warning(0, Getfile(n), Getline(n), "%s\n", wrn); + SWIG_WARN_NODE_END(n); + Setmeta(metaname, "already_warned", "1"); + } + } + c = Swig_symbol_add(symname, n); + + if (c != n) { + /* symbol conflict attempting to add in the new symbol */ + if (Getattr(n, "sym:weak")) { + Setattr(n, "sym:name", symname); + } else { + String *e = NewStringEmpty(); + String *en = NewStringEmpty(); + String *ec = NewStringEmpty(); + int redefined = Swig_need_redefined_warn(n, c, true); + if (redefined) { + Printf(en, "Identifier '%s' redefined (ignored)", symname); + Printf(ec, "previous definition of '%s'", symname); + } else { + Printf(en, "Redundant redeclaration of '%s'", symname); + Printf(ec, "previous declaration of '%s'", symname); + } + if (Cmp(symname, Getattr(n, "name"))) { + Printf(en, " (Renamed from '%s')", SwigType_namestr(Getattr(n, "name"))); + } + Printf(en, ","); + if (Cmp(symname, Getattr(c, "name"))) { + Printf(ec, " (Renamed from '%s')", SwigType_namestr(Getattr(c, "name"))); + } + Printf(ec, "."); + SWIG_WARN_NODE_BEGIN(n); + if (redefined) { + Swig_warning(WARN_PARSE_REDEFINED, Getfile(n), Getline(n), "%s\n", en); + Swig_warning(WARN_PARSE_REDEFINED, Getfile(c), Getline(c), "%s\n", ec); + } else { + Swig_warning(WARN_PARSE_REDUNDANT, Getfile(n), Getline(n), "%s\n", en); + Swig_warning(WARN_PARSE_REDUNDANT, Getfile(c), Getline(c), "%s\n", ec); + } + SWIG_WARN_NODE_END(n); + Printf(e, "%s:%d:%s\n%s:%d:%s\n", Getfile(n), Getline(n), en, Getfile(c), Getline(c), ec); + Setattr(n, "error", e); + Delete(e); + Delete(en); + Delete(ec); + } + } + } + Delete(symname); +} + +/* Strips C-style and C++-style comments from string in-place. */ +static void strip_comments(char *string) { + int state = 0; + /* + * 0 - not in comment + * 1 - in c-style comment + * 2 - in c++-style comment + * 3 - in string + * 4 - after reading / not in comments + * 5 - after reading * in c-style comments + * 6 - after reading \ in strings + */ + char *c = string; + while (*c) { + switch (state) { + case 0: + if (*c == '\"') + state = 3; + else if (*c == '/') + state = 4; + break; + case 1: + if (*c == '*') + state = 5; + *c = ' '; + break; + case 2: + if (*c == '\n') + state = 0; + else + *c = ' '; + break; + case 3: + if (*c == '\"') + state = 0; + else if (*c == '\\') + state = 6; + break; + case 4: + if (*c == '/') { + *(c - 1) = ' '; + *c = ' '; + state = 2; + } else if (*c == '*') { + *(c - 1) = ' '; + *c = ' '; + state = 1; + } else + state = 0; + break; + case 5: + if (*c == '/') + state = 0; + else + state = 1; + *c = ' '; + break; + case 6: + state = 3; + break; + } + ++c; + } +} + +// Create a %insert with a typedef to make a new name visible to C +static Node *create_insert(Node *n, bool noTypedef = false) { + // format a typedef + String *ccode = Getattr(n, "code"); + Push(ccode, " "); + if (noTypedef) { + Push(ccode, Getattr(n, "name")); + Push(ccode, " "); + Push(ccode, Getattr(n, "kind")); + } else { + Push(ccode, Getattr(n, "kind")); + Push(ccode, "typedef "); + Append(ccode, " "); + Append(ccode, Getattr(n, "tdname")); + } + Append(ccode, ";"); + + /* Strip comments - further code may break in presence of comments. */ + strip_comments(Char(ccode)); + + /* Make all SWIG created typedef structs/unions/classes unnamed else + redefinition errors occur - nasty hack alert. */ + if (!noTypedef) { + const char *types_array[3] = { "struct", "union", "class" }; + for (int i = 0; i < 3; i++) { + char *code_ptr = Char(ccode); + while (code_ptr) { + /* Replace struct name (as in 'struct name {...}' ) with whitespace + name will be between struct and opening brace */ + + code_ptr = strstr(code_ptr, types_array[i]); + if (code_ptr) { + char *open_bracket_pos; + code_ptr += strlen(types_array[i]); + open_bracket_pos = strchr(code_ptr, '{'); + if (open_bracket_pos) { + /* Make sure we don't have something like struct A a; */ + char *semi_colon_pos = strchr(code_ptr, ';'); + if (!(semi_colon_pos && (semi_colon_pos < open_bracket_pos))) + while (code_ptr < open_bracket_pos) + *code_ptr++ = ' '; + } + } + } + } + } + { + /* Remove SWIG directive %constant which may be left in the SWIG created typedefs */ + char *code_ptr = Char(ccode); + while (code_ptr) { + code_ptr = strstr(code_ptr, "%constant"); + if (code_ptr) { + char *directive_end_pos = strchr(code_ptr, ';'); + if (directive_end_pos) { + while (code_ptr <= directive_end_pos) + *code_ptr++ = ' '; + } + } + } + } + Node *newnode = NewHash(); + set_nodeType(newnode, "insert"); + Setfile(newnode, Getfile(n)); + Setline(newnode, Getline(n)); + String *code = NewStringEmpty(); + Wrapper_pretty_print(ccode, code); + Setattr(newnode, "code", code); + Delete(code); + Delattr(n, "code"); + return newnode; +} + +static void insertNodeAfter(Node *n, Node *c) { + Node *g = parentNode(n); + set_parentNode(c, g); + Node *ns = nextSibling(n); + if (Node *outer = Getattr(c, "nested:outer")) { + while (ns && outer == Getattr(ns, "nested:outer")) { + n = ns; + ns = nextSibling(n); + } + } + if (!ns) { + set_lastChild(g, c); + } else { + set_nextSibling(c, ns); + set_previousSibling(ns, c); + } + set_nextSibling(n, c); + set_previousSibling(c, n); +} + +void Swig_nested_name_unnamed_c_structs(Node *n) { + if (!classhash) + classhash = Getattr(n, "classes"); + Node *c = firstChild(n); + while (c) { + Node *next = nextSibling(c); + if (String *declName = Getattr(c, "nested:unnamed")) { + if (Node *outer = Getattr(c, "nested:outer")) { + // generate a name + String *name = NewStringf("%s_%s", Getattr(outer, "name"), declName); + Delattr(c, "nested:unnamed"); + // set the name to the class and symbol table + Setattr(c, "tdname", name); + Setattr(c, "name", name); + Swig_symbol_setscope(Getattr(c, "symtab")); + Swig_symbol_setscopename(name); + // now that we have a name - gather base symbols + if (List *publicBases = Getattr(c, "baselist")) { + List *bases = Swig_make_inherit_list(name, publicBases, 0); + Swig_inherit_base_symbols(bases); + Delete(bases); + } + Setattr(classhash, name, c); + Swig_symbol_popscope(); + // process declarations following this type (assign correct new type) + SwigType *ty = Copy(name); + Node *decl = nextSibling(c); + List *declList = NewList(); + while (decl && Getattr(decl, "nested:unnamedtype") == c) { + Setattr(decl, "type", ty); + Append(declList, decl); + Delattr(decl, "nested:unnamedtype"); + SetFlag(decl, "feature:immutable"); + add_symbols_c(decl); + decl = nextSibling(decl); + } + Delete(ty); + // Check for extensions +/* // TODO: we can save extensions hash like class hash and move check_extensions() after nesting processing + if (extendhash) { + if (Node *am = Getattr(extendhash, name)) { + // Merge the extension into the symbol table + merge_extensions(c, am); + append_previous_extension(c, am); + Delattr(extendhash, clsname); + } + }*/ + Swig_symbol_setscope(Swig_symbol_global_scope()); + add_symbols_c(c); + + Node *ins = create_insert(c); + insertNodeAfter(c, ins); + removeNode(c); + insertNodeAfter(n, c); + Delete(ins); + Delattr(c, "nested:outer"); + } else { + // global unnamed struct - ignore it + c = next; + continue; + } + } else if (CPlusPlusOut) { + if (Getattr(c, "nested:outer")) { + Node *ins = create_insert(c, true); + insertNodeAfter(c, ins); + Delete(ins); + Delattr(c, "nested:outer"); + } + } + // process children + Swig_nested_name_unnamed_c_structs(c); + c = next; + } +} + +static void remove_outer_class_reference(Node *n) { + for (Node *c = firstChild(n); c; c = nextSibling(c)) { + if (GetFlag(c, "feature:flatnested")) { + Delattr(c, "nested:outer"); + remove_outer_class_reference(c); + } + } +} + +void Swig_nested_process_classes(Node *n) { + Node *c = firstChild(n); + while (c) { + Node *next = nextSibling(c); + if (!Getattr(c, "templatetype")) { + if (GetFlag(c, "nested") && GetFlag(c, "feature:flatnested")) { + removeNode(c); + if (!checkAttribute(c, "access", "public")) + SetFlag(c, "feature:ignore"); + else + insertNodeAfter(n, c); + } + Swig_nested_process_classes(c); + } + c = next; + } + remove_outer_class_reference(n); +} + diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 61e5f8c13..41ef44e41 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -421,7 +421,7 @@ int Swig_contract_mode_get(); void Swig_browser(Node *n, int); void Swig_default_allocators(Node *n); void Swig_process_types(Node *n); -void Swig_process_nested_classes(Node *n); -void Swig_name_unnamed_c_structs(Node *n); +void Swig_nested_process_classes(Node *n); +void Swig_nested_name_unnamed_c_structs(Node *n); #endif diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index 6954e0dd2..3f8e33dae 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -1283,430 +1283,3 @@ void Swig_process_types(Node *n) { TypePass::pass(n); } -// Nested classes processing section -static Hash *classhash = 0; - -static String *make_name(Node *n, String *name, SwigType *decl) { - int destructor = name && (*(Char(name)) == '~'); - if (String *yyrename = Getattr(n, "class_rename")) { - String *s = NewString(yyrename); - Delattr(n, "class_rename"); - if (destructor && (*(Char(s)) != '~')) { - Insert(s, 0, "~"); - } - return s; - } - - if (!name) - return 0; - return Swig_name_make(n, 0, name, decl, 0); -} - -// C version of add_symbols() -static void add_symbols_c(Node *n) { - String *decl; - String *wrn = 0; - String *symname = 0; - int iscdecl = Cmp(nodeType(n), "cdecl") == 0; - Setattr(n, "ismember", "1"); - Setattr(n, "access", "public"); - if (Getattr(n, "sym:name")) - return; - decl = Getattr(n, "decl"); - if (!SwigType_isfunction(decl)) { - String *name = Getattr(n, "name"); - String *makename = Getattr(n, "parser:makename"); - if (iscdecl) { - String *storage = Getattr(n, "storage"); - if (Cmp(storage, "typedef") == 0) { - Setattr(n, "kind", "typedef"); - } else { - SwigType *type = Getattr(n, "type"); - String *value = Getattr(n, "value"); - Setattr(n, "kind", "variable"); - if (value && Len(value)) { - Setattr(n, "hasvalue", "1"); - } - if (type) { - SwigType *ty; - SwigType *tmp = 0; - if (decl) { - ty = tmp = Copy(type); - SwigType_push(ty, decl); - } else { - ty = type; - } - if (!SwigType_ismutable(ty)) { - SetFlag(n, "hasconsttype"); - SetFlag(n, "feature:immutable"); - } - if (tmp) - Delete(tmp); - } - if (!type) { - Printf(stderr, "notype name %s\n", name); - } - } - } - Swig_features_get(Swig_cparse_features(), 0, name, 0, n); - if (makename) { - symname = make_name(n, makename, 0); - Delattr(n, "parser:makename"); /* temporary information, don't leave it hanging around */ - } else { - makename = name; - symname = make_name(n, makename, 0); - } - - if (!symname) { - symname = Copy(Getattr(n, "unnamed")); - } - if (symname) { - wrn = Swig_name_warning(n, 0, symname, 0); - } - } else { - String *name = Getattr(n, "name"); - SwigType *fdecl = Copy(decl); - SwigType *fun = SwigType_pop_function(fdecl); - if (iscdecl) { - Setattr(n, "kind", "function"); - } - - Swig_features_get(Swig_cparse_features(), 0, name, fun, n); - - symname = make_name(n, name, fun); - wrn = Swig_name_warning(n, 0, symname, fun); - - Delete(fdecl); - Delete(fun); - - } - if (!symname) - return; - if (GetFlag(n, "feature:ignore")) { - /* Only add to C symbol table and continue */ - Swig_symbol_add(0, n); - } else if (strncmp(Char(symname), "$ignore", 7) == 0) { - char *c = Char(symname) + 7; - SetFlag(n, "feature:ignore"); - if (strlen(c)) { - SWIG_WARN_NODE_BEGIN(n); - Swig_warning(0, Getfile(n), Getline(n), "%s\n", c + 1); - SWIG_WARN_NODE_END(n); - } - Swig_symbol_add(0, n); - } else { - Node *c; - if ((wrn) && (Len(wrn))) { - String *metaname = symname; - if (!Getmeta(metaname, "already_warned")) { - SWIG_WARN_NODE_BEGIN(n); - Swig_warning(0, Getfile(n), Getline(n), "%s\n", wrn); - SWIG_WARN_NODE_END(n); - Setmeta(metaname, "already_warned", "1"); - } - } - c = Swig_symbol_add(symname, n); - - if (c != n) { - /* symbol conflict attempting to add in the new symbol */ - if (Getattr(n, "sym:weak")) { - Setattr(n, "sym:name", symname); - } else { - String *e = NewStringEmpty(); - String *en = NewStringEmpty(); - String *ec = NewStringEmpty(); - int redefined = Swig_need_redefined_warn(n, c, true); - if (redefined) { - Printf(en, "Identifier '%s' redefined (ignored)", symname); - Printf(ec, "previous definition of '%s'", symname); - } else { - Printf(en, "Redundant redeclaration of '%s'", symname); - Printf(ec, "previous declaration of '%s'", symname); - } - if (Cmp(symname, Getattr(n, "name"))) { - Printf(en, " (Renamed from '%s')", SwigType_namestr(Getattr(n, "name"))); - } - Printf(en, ","); - if (Cmp(symname, Getattr(c, "name"))) { - Printf(ec, " (Renamed from '%s')", SwigType_namestr(Getattr(c, "name"))); - } - Printf(ec, "."); - SWIG_WARN_NODE_BEGIN(n); - if (redefined) { - Swig_warning(WARN_PARSE_REDEFINED, Getfile(n), Getline(n), "%s\n", en); - Swig_warning(WARN_PARSE_REDEFINED, Getfile(c), Getline(c), "%s\n", ec); - } else { - Swig_warning(WARN_PARSE_REDUNDANT, Getfile(n), Getline(n), "%s\n", en); - Swig_warning(WARN_PARSE_REDUNDANT, Getfile(c), Getline(c), "%s\n", ec); - } - SWIG_WARN_NODE_END(n); - Printf(e, "%s:%d:%s\n%s:%d:%s\n", Getfile(n), Getline(n), en, Getfile(c), Getline(c), ec); - Setattr(n, "error", e); - Delete(e); - Delete(en); - Delete(ec); - } - } - } - Delete(symname); -} - -/* Strips C-style and C++-style comments from string in-place. */ -static void strip_comments(char *string) { - int state = 0; - /* - * 0 - not in comment - * 1 - in c-style comment - * 2 - in c++-style comment - * 3 - in string - * 4 - after reading / not in comments - * 5 - after reading * in c-style comments - * 6 - after reading \ in strings - */ - char *c = string; - while (*c) { - switch (state) { - case 0: - if (*c == '\"') - state = 3; - else if (*c == '/') - state = 4; - break; - case 1: - if (*c == '*') - state = 5; - *c = ' '; - break; - case 2: - if (*c == '\n') - state = 0; - else - *c = ' '; - break; - case 3: - if (*c == '\"') - state = 0; - else if (*c == '\\') - state = 6; - break; - case 4: - if (*c == '/') { - *(c - 1) = ' '; - *c = ' '; - state = 2; - } else if (*c == '*') { - *(c - 1) = ' '; - *c = ' '; - state = 1; - } else - state = 0; - break; - case 5: - if (*c == '/') - state = 0; - else - state = 1; - *c = ' '; - break; - case 6: - state = 3; - break; - } - ++c; - } -} - -// Create a %insert with a typedef to make a new name visible to C -static Node *create_insert(Node *n, bool noTypedef = false) { - // format a typedef - String *ccode = Getattr(n, "code"); - Push(ccode, " "); - if (noTypedef) { - Push(ccode, Getattr(n, "name")); - Push(ccode, " "); - Push(ccode, Getattr(n, "kind")); - } else { - Push(ccode, Getattr(n, "kind")); - Push(ccode, "typedef "); - Append(ccode, " "); - Append(ccode, Getattr(n, "tdname")); - } - Append(ccode, ";"); - - /* Strip comments - further code may break in presence of comments. */ - strip_comments(Char(ccode)); - - /* Make all SWIG created typedef structs/unions/classes unnamed else - redefinition errors occur - nasty hack alert. */ - if (!noTypedef) { - const char *types_array[3] = { "struct", "union", "class" }; - for (int i = 0; i < 3; i++) { - char *code_ptr = Char(ccode); - while (code_ptr) { - /* Replace struct name (as in 'struct name {...}' ) with whitespace - name will be between struct and opening brace */ - - code_ptr = strstr(code_ptr, types_array[i]); - if (code_ptr) { - char *open_bracket_pos; - code_ptr += strlen(types_array[i]); - open_bracket_pos = strchr(code_ptr, '{'); - if (open_bracket_pos) { - /* Make sure we don't have something like struct A a; */ - char *semi_colon_pos = strchr(code_ptr, ';'); - if (!(semi_colon_pos && (semi_colon_pos < open_bracket_pos))) - while (code_ptr < open_bracket_pos) - *code_ptr++ = ' '; - } - } - } - } - } - { - /* Remove SWIG directive %constant which may be left in the SWIG created typedefs */ - char *code_ptr = Char(ccode); - while (code_ptr) { - code_ptr = strstr(code_ptr, "%constant"); - if (code_ptr) { - char *directive_end_pos = strchr(code_ptr, ';'); - if (directive_end_pos) { - while (code_ptr <= directive_end_pos) - *code_ptr++ = ' '; - } - } - } - } - Node *newnode = NewHash(); - set_nodeType(newnode, "insert"); - Setfile(newnode, Getfile(n)); - Setline(newnode, Getline(n)); - String *code = NewStringEmpty(); - Wrapper_pretty_print(ccode, code); - Setattr(newnode, "code", code); - Delete(code); - Delattr(n, "code"); - return newnode; -} - -static void insertNodeAfter(Node *n, Node *c) { - Node *g = parentNode(n); - set_parentNode(c, g); - Node *ns = nextSibling(n); - if (Node *outer = Getattr(c, "nested:outer")) { - while (ns && outer == Getattr(ns, "nested:outer")) { - n = ns; - ns = nextSibling(n); - } - } - if (!ns) { - set_lastChild(g, c); - } else { - set_nextSibling(c, ns); - set_previousSibling(ns, c); - } - set_nextSibling(n, c); - set_previousSibling(c, n); -} - -void Swig_name_unnamed_c_structs(Node *n) { - if (!classhash) - classhash = Getattr(n, "classes"); - Node *c = firstChild(n); - while (c) { - Node *next = nextSibling(c); - if (String *declName = Getattr(c, "nested:unnamed")) { - if (Node *outer = Getattr(c, "nested:outer")) { - // generate a name - String *name = NewStringf("%s_%s", Getattr(outer, "name"), declName); - Delattr(c, "nested:unnamed"); - // set the name to the class and symbol table - Setattr(c, "tdname", name); - Setattr(c, "name", name); - Swig_symbol_setscope(Getattr(c, "symtab")); - Swig_symbol_setscopename(name); - // now that we have a name - gather base symbols - if (List *publicBases = Getattr(c, "baselist")) { - List *bases = Swig_make_inherit_list(name, publicBases, 0); - Swig_inherit_base_symbols(bases); - Delete(bases); - } - Setattr(classhash, name, c); - Swig_symbol_popscope(); - // process declarations following this type (assign correct new type) - SwigType *ty = Copy(name); - Node *decl = nextSibling(c); - List *declList = NewList(); - while (decl && Getattr(decl, "nested:unnamedtype") == c) { - Setattr(decl, "type", ty); - Append(declList, decl); - Delattr(decl, "nested:unnamedtype"); - SetFlag(decl, "feature:immutable"); - add_symbols_c(decl); - decl = nextSibling(decl); - } - Delete(ty); - // Check for extensions -/* // TODO: we can save extensions hash like class hash and move check_extensions() after nesting processing - if (extendhash) { - if (Node *am = Getattr(extendhash, name)) { - // Merge the extension into the symbol table - merge_extensions(c, am); - append_previous_extension(c, am); - Delattr(extendhash, clsname); - } - }*/ - Swig_symbol_setscope(Swig_symbol_global_scope()); - add_symbols_c(c); - - Node *ins = create_insert(c); - insertNodeAfter(c, ins); - removeNode(c); - insertNodeAfter(n, c); - Delete(ins); - Delattr(c, "nested:outer"); - } else { - // global unnamed struct - ignore it - c = next; - continue; - } - } else if (CPlusPlusOut) { - if (Getattr(c, "nested:outer")) { - Node *ins = create_insert(c, true); - insertNodeAfter(c, ins); - Delete(ins); - Delattr(c, "nested:outer"); - } - } - // process children - Swig_name_unnamed_c_structs(c); - c = next; - } -} - -static void remove_outer_class_reference(Node *n) { - for (Node *c = firstChild(n); c; c = nextSibling(c)) { - if (GetFlag(c, "feature:flatnested")) { - Delattr(c, "nested:outer"); - remove_outer_class_reference(c); - } - } -} - -void Swig_process_nested_classes(Node *n) { - Node *c = firstChild(n); - while (c) { - Node *next = nextSibling(c); - if (!Getattr(c, "templatetype")) { - if (GetFlag(c, "nested") && GetFlag(c, "feature:flatnested")) { - removeNode(c); - if (!checkAttribute(c, "access", "public")) - SetFlag(c, "feature:ignore"); - else - insertNodeAfter(n, c); - } - Swig_process_nested_classes(c); - } - c = next; - } - remove_outer_class_reference(n); -} From 7103a0684961a5b19e6ef5502823332b8936a0c2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 5 Dec 2013 20:57:30 +0000 Subject: [PATCH 0802/1160] Swig_offset_string moved to misc.c --- Source/Modules/csharp.cxx | 4 +--- Source/Modules/java.cxx | 4 +--- Source/Modules/lang.cxx | 41 -------------------------------- Source/Swig/misc.c | 49 +++++++++++++++++++++++++++++++++++++++ Source/Swig/swig.h | 1 + 5 files changed, 52 insertions(+), 47 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 88dbfbad7..9197b4b17 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -18,8 +18,6 @@ /* Hash type used for upcalls from C/C++ */ typedef DOH UpcallData; -// insert N tabs before each new line in s -void Swig_offset_string(String *s, int N); class CSHARP:public Language { static const char *usage; @@ -2004,7 +2002,7 @@ public: } else { for (int i = 0; i < nesting_depth; ++i) Append(old_proxy_class_code, " "); - Append(old_proxy_class_code, "}\n"); + Append(old_proxy_class_code, "}\n\n"); --nesting_depth; } diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index f781f0c39..fdc678dbf 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -18,8 +18,6 @@ /* Hash type used for upcalls from C/C++ */ typedef DOH UpcallData; -// insert N tabs before each new line in s -void Swig_offset_string(String *s, int N); class JAVA:public Language { static const char *usage; @@ -2068,7 +2066,7 @@ public: } else { for (int i = 0; i < nesting_depth; ++i) Append(old_proxy_class_code, " "); - Append(old_proxy_class_code, "}\n"); + Append(old_proxy_class_code, "}\n\n"); --nesting_depth; } diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 5c701bc85..78c37dbb9 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -3632,44 +3632,3 @@ Hash *Language::getClassHash() const { return classhash; } -// insert N tabs before each new line in s -void Swig_offset_string(String *s, int N) -{ - // count a number of lines in s - int lines = 1; - int L = Len(s); - char *start = strchr(Char(s), '\n'); - while (start) { - ++lines; - start = strchr(start + 1, '\n'); - } - // do not count pending new line - if ((Char(s))[L-1] == '\n') - --lines; - // allocate a temporary storage for a padded string - char *res = (char*)malloc(L + lines * N * 2 + 1); - res[L + lines * N * 2] = 0; - - // copy lines to res, prepending tabs to each line - char *p = res; // output pointer - start = Char(s); // start of a current line - char *end = strchr(start, '\n'); // end of a current line - while (end) { - memset(p, ' ', N*2); - p += N*2; - memcpy(p, start, end - start + 1); - p += end - start + 1; - start = end + 1; - end = strchr(start, '\n'); - } - // process the last line - if (*start) { - memset(p, ' ', N*2); - p += N*2; - strcpy(p, start); - } - // replace 's' contents with 'res' - Clear(s); - Append(s, res); - free(res); -} diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 769882bf8..7d8180d1c 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -1147,6 +1147,55 @@ String *Swig_string_strip(String *s) { return ns; } +/* ----------------------------------------------------------------------------- + * Swig_offset_string() + * + * Insert number tabs before each new line in s + * ----------------------------------------------------------------------------- */ + +void Swig_offset_string(String *s, int number) { + char *res; + char *p; + char *end; + /* count a number of lines in s */ + int lines = 1; + int len = Len(s); + char *start = strchr(Char(s), '\n'); + while (start) { + ++lines; + start = strchr(start + 1, '\n'); + } + /* do not count pending new line */ + if ((Char(s))[len-1] == '\n') + --lines; + /* allocate a temporary storage for a padded string */ + res = (char*)malloc(len + lines * number * 2 + 1); + res[len + lines * number * 2] = 0; + + /* copy lines to res, prepending tabs to each line */ + p = res; /* output pointer */ + start = Char(s); /* start of a current line */ + end = strchr(start, '\n'); /* end of a current line */ + while (end) { + memset(p, ' ', number*2); + p += number*2; + memcpy(p, start, end - start + 1); + p += end - start + 1; + start = end + 1; + end = strchr(start, '\n'); + } + /* process the last line */ + if (*start) { + memset(p, ' ', number*2); + p += number*2; + strcpy(p, start); + } + /* replace 's' contents with 'res' */ + Clear(s); + Append(s, res); + free(res); +} + #ifdef HAVE_PCRE #include diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 95e3784d9..28a3ba730 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -332,6 +332,7 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern String *Swig_string_lower(String *s); extern String *Swig_string_upper(String *s); extern String *Swig_string_title(String *s); + extern void Swig_offset_string(String *s, int number); extern String *Swig_pcre_version(void); extern void Swig_init(void); extern int Swig_value_wrapper_mode(int mode); From 6d97335d946a8042e84357d80ddbb67b8118696a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 5 Dec 2013 21:21:07 +0000 Subject: [PATCH 0803/1160] Minor tweaks in Swig_feature_set --- Source/Modules/main.cxx | 4 +--- Source/Swig/naming.c | 2 +- Source/Swig/swig.h | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index 62d9c0c36..aa7e83ef8 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -863,9 +863,7 @@ void SWIG_getoptions(int argc, char *argv[]) { } static void flatten_nested() { - String *val = NewString("1"); - Swig_feature_set(Swig_cparse_features(), "", 0, "feature:flatnested", val, 0); - Delete(val); + Swig_feature_set(Swig_cparse_features(), "", 0, "feature:flatnested", "1", 0); } diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index 2921b3c84..9e2b4a436 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -774,7 +774,7 @@ void Swig_features_get(Hash *features, String *prefix, String *name, SwigType *d * concatenating the feature name plus ':' plus the attribute name. * ----------------------------------------------------------------------------- */ -void Swig_feature_set(Hash *features, const_String_or_char_ptr name, SwigType *decl, const_String_or_char_ptr featurename, String *value, Hash *featureattribs) { +void Swig_feature_set(Hash *features, const_String_or_char_ptr name, SwigType *decl, const_String_or_char_ptr featurename, const_String_or_char_ptr value, Hash *featureattribs) { Hash *n; Hash *fhash; diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 28a3ba730..95d9189b3 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -304,7 +304,7 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern DOH *Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType *decl); extern void Swig_name_object_inherit(Hash *namehash, String *base, String *derived); extern void Swig_features_get(Hash *features, String *prefix, String *name, SwigType *decl, Node *n); - extern void Swig_feature_set(Hash *features, const_String_or_char_ptr name, SwigType *decl, const_String_or_char_ptr featurename, String *value, Hash *featureattribs); + extern void Swig_feature_set(Hash *features, const_String_or_char_ptr name, SwigType *decl, const_String_or_char_ptr featurename, const_String_or_char_ptr value, Hash *featureattribs); /* --- Misc --- */ extern char *Swig_copy_string(const char *c); From 67848e377adbc62cca118d382a587074edac21d6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 7 Dec 2013 16:04:52 +0000 Subject: [PATCH 0804/1160] Fix template partial specialization detection Fixes template definitions that should be ignored and warnings introduced after nested changes: ../../../Examples/test-suite/refcount.i:63: Warning 318: Instantiation of template 'RCPtr< A >' is ambiguous, ../../../Examples/test-suite/refcount.h:159: Warning 318: instantiation 'RCPtr< T >::RCPtr' used, ../../../Examples/test-suite/refcount.h:159: Warning 318: instantiation 'RCPtr< T >::RCPtr' ignored. ../../../Examples/test-suite/refcount.h:159: Warning 318: instantiation 'RCPtr< T >::RCPtr' ignored. ../../../Examples/test-suite/refcount.h:159: Warning 318: instantiation 'RCPtr< T >::RCPtr' ignored. Different/clearer implementation of constructor detection since Classprefix is not behaving the same since nested changes were introduced. Only accept constructors if in extend mode or in a class. Also remove unused "isextension" attribute on the nodes. --- Source/CParse/parser.y | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 9dfa60099..4d978a97d 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -309,9 +309,6 @@ static void add_symbols(Node *n) { int isfriend = inclass && is_friend(n); int iscdecl = Cmp(nodeType(n),"cdecl") == 0; int only_csymbol = 0; - if (extendmode) { - Setattr(n,"isextension","1"); - } if (inclass) { String *name = Getattr(n, "name"); @@ -1594,6 +1591,7 @@ swig_directive : extend_directive { $$ = $1; } extend_directive : EXTEND options idcolon LBRACE { Node *cls; String *clsname; + extendmode = 1; cplus_mode = CPLUS_PUBLIC; if (!classes) classes = NewHash(); if (!classes_typedefs) classes_typedefs = NewHash(); @@ -1619,7 +1617,6 @@ extend_directive : EXTEND options idcolon LBRACE { Note that %extend before the class typedef never worked, only %extend after the class typdef. */ prev_symtab = Swig_symbol_setscope(Getattr(cls, "symtab")); current_class = cls; - extendmode = 1; SWIG_WARN_NODE_BEGIN(cls); Swig_warning(WARN_PARSE_EXTEND_NAME, cparse_file, cparse_line, "Deprecated %%extend name used - the %s name '%s' should be used instead of the typedef name '%s'.\n", Getattr(cls, "kind"), SwigType_namestr(Getattr(cls, "name")), $3); SWIG_WARN_NODE_END(cls); @@ -1628,7 +1625,6 @@ extend_directive : EXTEND options idcolon LBRACE { /* Previous class definition. Use its symbol table */ prev_symtab = Swig_symbol_setscope(Getattr(cls,"symtab")); current_class = cls; - extendmode = 1; } Classprefix = NewString($3); Namespaceprefix= Swig_symbol_qualifiedscopename(0); @@ -4288,7 +4284,7 @@ cpp_members : cpp_member cpp_members { cpp_member : c_declaration { $$ = $1; } | cpp_constructor_decl { $$ = $1; - if (extendmode) { + if (extendmode && current_class) { String *symname; symname= make_name($$,Getattr($$,"name"), Getattr($$,"decl")); if (Strcmp(symname,Getattr($$,"name")) == 0) { @@ -4329,7 +4325,7 @@ cpp_member : c_declaration { $$ = $1; } */ cpp_constructor_decl : storage_class type LPAREN parms RPAREN ctor_end { - if (Classprefix) { + if (inclass || extendmode) { SwigType *decl = NewStringEmpty(); $$ = new_node("constructor"); Setattr($$,"storage",$1); From 44323e14b3cb3541db5b89b43a54b443d0f4d8d1 Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Sun, 8 Dec 2013 01:46:38 +0400 Subject: [PATCH 0805/1160] Classprefix fixed after private nested classes some comments and spaces added --- Source/CParse/parser.y | 118 ++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 60 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 9dfa60099..3900a0e09 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3483,20 +3483,21 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { if (extendhash) { String *clsname = Swig_symbol_qualifiedscopename(0); - am = Getattr(extendhash,clsname); + am = Getattr(extendhash, clsname); if (am) { - merge_extensions($$,am); - Delattr(extendhash,clsname); + merge_extensions($$, am); + Delattr(extendhash, clsname); } Delete(clsname); } if (!classes) classes = NewHash(); scpname = Swig_symbol_qualifiedscopename(0); - Setattr(classes,scpname,$$); + Setattr(classes, scpname, $$); - appendChild($$,$7); + appendChild($$, $7); - if (am) append_previous_extension($$,am); + if (am) + append_previous_extension($$, am); p = $9; if (p && !nscope_inner) { @@ -3511,14 +3512,14 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { } else if (cparse_cplusplus && !cparse_externc) { ty = NewString($3); } else { - ty = NewStringf("%s %s", $2,$3); + ty = NewStringf("%s %s", $2, $3); } while (p) { - Setattr(p,"storage",$1); - Setattr(p,"type",ty); + Setattr(p, "storage", $1); + Setattr(p, "type" ,ty); if (!cparse_cplusplus && currentOuterClass && (!Getattr(currentOuterClass, "name") || CPlusPlusOut)) { - SetFlag(p,"hasconsttype"); - SetFlag(p,"feature:immutable"); + SetFlag(p, "hasconsttype"); + SetFlag(p, "feature:immutable"); } p = nextSibling(p); } @@ -3530,71 +3531,68 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { /* we 'open' the class at the end, to allow %template to add new members */ Node *pa = new_node("access"); - Setattr(pa,"kind","public"); + Setattr(pa, "kind", "public"); cplus_mode = CPLUS_PUBLIC; - appendChild($$,pa); + appendChild($$, pa); Delete(pa); } if (currentOuterClass) restore_access_mode($$); + Setattr($$, "symtab", Swig_symbol_popscope()); + Classprefix = Getattr($$, "Classprefix"); + Delattr($$, "Classprefix"); if (cplus_mode == CPLUS_PRIVATE) { $$ = 0; /* skip private nested classes */ + } else if (nscope_inner) { + /* this is tricky */ + /* we add the declaration in the original namespace */ + appendChild(nscope_inner, $$); + Swig_symbol_setscope(Getattr(nscope_inner, "symtab")); + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); + yyrename = Copy(Getattr($$, "class_rename")); + add_symbols($$); + Delattr($$, "class_rename"); + /* but the variable definition in the current scope */ + Swig_symbol_setscope(cscope); + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); + add_symbols($9); + if (nscope) { + $$ = nscope; /* here we return recreated namespace tower instead of the class itself */ + if ($9) + appendSibling($$, $9); + } + else if (!SwigType_istemplate(ty) && template_parameters == 0) /* for tempalte we need the class itself */ + $$ = $9; } else { - Setattr($$,"symtab",Swig_symbol_popscope()); - - Classprefix = Getattr($$,"Classprefix"); - Delattr($$,"Classprefix"); - if (nscope_inner) { - /* this is tricky */ - /* we add the declaration in the original namespace */ - if (cplus_mode != CPLUS_PRIVATE) - appendChild(nscope_inner,$$); - Swig_symbol_setscope(Getattr(nscope_inner,"symtab")); + Delete(yyrename); + yyrename = 0; + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); + if (!cparse_cplusplus && currentOuterClass) { /* nested C structs go into global scope*/ + Node *outer = currentOuterClass; + while (Getattr(outer, "nested:outer")) + outer = Getattr(outer, "nested:outer"); + appendSibling(outer, $$); + add_symbols($9); + set_scope_to_global(); Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); yyrename = Copy(Getattr($$, "class_rename")); add_symbols($$); + if (!CPlusPlusOut) + Delattr($$, "nested:outer"); Delattr($$, "class_rename"); - /* but the variable definition in the current scope */ - Swig_symbol_setscope(cscope); - Delete(Namespaceprefix); - Namespaceprefix = Swig_symbol_qualifiedscopename(0); - add_symbols($9); - if (nscope) { - $$ = nscope; - if ($9) - appendSibling($$, $9); - } - else if (!SwigType_istemplate(ty) && template_parameters == 0) - $$ = $9; + $$ = 0; } else { - Delete(yyrename); - yyrename = 0; - Delete(Namespaceprefix); - Namespaceprefix = Swig_symbol_qualifiedscopename(0); - if (!cparse_cplusplus && currentOuterClass) { /* nested C structs go into global scope*/ - Node *outer = currentOuterClass; - while (Getattr(outer, "nested:outer")) - outer = Getattr(outer, "nested:outer"); - appendSibling(outer, $$); - add_symbols($9); - set_scope_to_global(); - Delete(Namespaceprefix); - Namespaceprefix = Swig_symbol_qualifiedscopename(0); - yyrename = Copy(Getattr($$, "class_rename")); - add_symbols($$); - if (!CPlusPlusOut) - Delattr($$, "nested:outer"); - Delattr($$, "class_rename"); - $$ = 0; - } else { - yyrename = Copy(Getattr($$, "class_rename")); - add_symbols($$); - add_symbols($9); - Delattr($$, "class_rename"); - } + yyrename = Copy(Getattr($$, "class_rename")); + add_symbols($$); + add_symbols($9); + Delattr($$, "class_rename"); } } + Delete(ty); Swig_symbol_setscope(cscope); Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); From 2d0dc707e6975ae4476931c32f4df4e4faaa2e4e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 8 Dec 2013 19:48:39 +0000 Subject: [PATCH 0806/1160] More control on output from top level Makefile Move the '-k -s' flags to a new FLAGS variable which can then be overridden on the command line. --- Makefile.in | 62 +++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/Makefile.in b/Makefile.in index 9db1a7efc..aa1c3d63f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -9,9 +9,16 @@ exec_prefix = @exec_prefix@ srcdir = @srcdir@ datarootdir = @datarootdir@ -############################################################################## +##################################################################### +# Make options - override these to see more output +##################################################################### + +RUNPIPE = \>/dev/null +FLAGS = -k -s + +##################################################################### # Compiler and system configuration -############################################################################## +##################################################################### SHELL = /bin/sh SWIG_LIB = @swig_lib@ @@ -23,7 +30,6 @@ SOURCE = Source CCACHE = CCache DOCS = Doc/Manual HAVE_CXX11_COMPILER = @HAVE_CXX11_COMPILER@ -RUNPIPE = \>/dev/null swig: libfiles source ccache @@ -160,7 +166,7 @@ check-%-version : echo skipping $* version; \ else \ echo showing $* version; \ - (cd Examples && $(MAKE) -s $*_version) \ + (cd Examples && $(MAKE) $(FLAGS) $*_version) \ fi # Checks examples for compilation (does not run them) @@ -224,13 +230,13 @@ check-%-examples : elif test -z "$($(strip $*_examples))"; then \ echo empty $* $(ACTION); \ else \ - $(MAKE) -k -s $($*_examples:=.actionexample) LANGUAGE=$* ACTION=$(ACTION); \ + $(MAKE) $(FLAGS) $($*_examples:=.actionexample) LANGUAGE=$* ACTION=$(ACTION); \ fi # individual example %.actionexample: @echo $(ACTION)ing Examples/$(LANGUAGE)/$* - @(cd Examples/$(LANGUAGE)/$* && $(MAKE) -s $(chk-set-env) $(ACTION) RUNPIPE=$(RUNPIPE)) + @(cd Examples/$(LANGUAGE)/$* && $(MAKE) $(FLAGS) $(chk-set-env) $(ACTION) RUNPIPE=$(RUNPIPE)) # gcj individual example java.actionexample: @@ -238,7 +244,7 @@ java.actionexample: echo "skipping Examples/$(LANGUAGE)/java $(ACTION) (gcj test)"; \ else \ echo $(ACTION)ing Examples/$(LANGUAGE)/java; \ - (cd Examples/$(LANGUAGE)/java && $(MAKE) -s $(chk-set-env) $(ACTION)) \ + (cd Examples/$(LANGUAGE)/java && $(MAKE) $(FLAGS) $(chk-set-env) $(ACTION)) \ fi # Checks testcases in the test-suite excluding those which are known to be broken @@ -279,17 +285,17 @@ check-%-test-suite: echo warning: cannot $(ACTION) $* test-suite "(no dir $$dir)";\ else \ echo $(ACTION)ing $* test-suite; \ - (cd $$dir && $(MAKE) -k -s $(ACTION) HAVE_CXX11_COMPILER=$(HAVE_CXX11_COMPILER)) \ + (cd $$dir && $(MAKE) $(FLAGS) $(ACTION) HAVE_CXX11_COMPILER=$(HAVE_CXX11_COMPILER)) \ || passed=false; \ fi; \ test $$passed = true # Partial test-suite check - it only invokes SWIG, ie no compilation and no runtime testing partialcheck-test-suite: - @$(MAKE) -k -s check-test-suite ACTION=partialcheck NOSKIP=1 + @$(MAKE) $(FLAGS) check-test-suite ACTION=partialcheck NOSKIP=1 partialcheck-%-test-suite: - @$(MAKE) -k -s check-$*-test-suite ACTION=partialcheck NOSKIP=1 + @$(MAKE) $(FLAGS) check-$*-test-suite ACTION=partialcheck NOSKIP=1 check: check-aliveness check-ccache check-versions check-examples check-test-suite @@ -319,7 +325,7 @@ all-test-suite: \ all-d-test-suite all-%-test-suite: - @$(MAKE) -k -s check-$*-test-suite ACTION=all + @$(MAKE) $(FLAGS) check-$*-test-suite ACTION=all # Run known-to-be-broken testcases in the test-suite broken-test-suite: \ @@ -347,7 +353,7 @@ broken-test-suite: \ broken-d-test-suite broken-%-test-suite: - @$(MAKE) -k -s check-$*-test-suite ACTION=broken + @$(MAKE) $(FLAGS) check-$*-test-suite ACTION=broken ##################################################################### # CLEAN @@ -359,23 +365,23 @@ clean-objects: clean-source clean-ccache clean-source: @echo cleaning Source - @cd $(SOURCE) && $(MAKE) -s clean + @cd $(SOURCE) && $(MAKE) $(FLAGS) clean @rm -f $(TARGET) clean-examples: - @$(MAKE) -k -s check-examples ACTION=clean + @$(MAKE) $(FLAGS) check-examples ACTION=clean clean-test-suite: - @$(MAKE) -k -s check-test-suite ACTION=clean NOSKIP=1 + @$(MAKE) $(FLAGS) check-test-suite ACTION=clean NOSKIP=1 clean-%-examples: - @$(MAKE) -k -s check-$*-examples ACTION=clean + @$(MAKE) $(FLAGS) check-$*-examples ACTION=clean clean-%-test-suite: - @$(MAKE) -k -s check-$*-test-suite ACTION=clean NOSKIP=1 + @$(MAKE) $(FLAGS) check-$*-test-suite ACTION=clean NOSKIP=1 clean-ccache: - test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) -s clean) + test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) $(FLAGS) clean) ##################################################################### # DISTCLEAN - clean what configure built @@ -389,20 +395,20 @@ distclean: distclean-source distclean-ccache distclean-helper distclean-source: @echo distcleaning Source - @cd $(SOURCE) && $(MAKE) -s distclean + @cd $(SOURCE) && $(MAKE) $(FLAGS) distclean @rm -f $(TARGET) distclean-test-suite: @echo distcleaning Examples/test-suite - @$(MAKE) -k -s check-test-suite ACTION=distclean NOSKIP=1 + @$(MAKE) $(FLAGS) check-test-suite ACTION=distclean NOSKIP=1 distclean-examples: @echo distcleaning Examples - @$(MAKE) -k -s clean-examples - @cd Examples && $(MAKE) -k -s distclean + @$(MAKE) $(FLAGS) clean-examples + @cd Examples && $(MAKE) $(FLAGS) distclean distclean-ccache: - @test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) -s distclean) + @test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) $(FLAGS) distclean) distclean-dead: rm -f $(DISTCLEAN-DEAD) @@ -416,15 +422,15 @@ distclean-dead: maintainer-clean: @echo maintainer-cleaning source - @cd $(SOURCE) && $(MAKE) -k -s maintainer-clean + @cd $(SOURCE) && $(MAKE) $(FLAGS) maintainer-clean @echo maintainer-cleaning CCache - @test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) -s maintainer-clean) + @test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) $(FLAGS) maintainer-clean) @echo maintainer-cleaning docs - @cd $(DOCS) && $(MAKE) -k -s maintainer-clean + @cd $(DOCS) && $(MAKE) $(FLAGS) maintainer-clean @echo maintainer-cleaning Lib files @rm -f $(srcdir)/Lib/swigwarn.swg @echo distcleaning - @$(MAKE) -k -s distclean-helper + @$(MAKE) $(FLAGS) distclean-helper ##################################################################### # Update the Lib/swigwarn.swg file @@ -492,7 +498,7 @@ install-lib: done install-ccache: - @test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) -s install) + @test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) install) ##################################################################### From c6e4dea5722eac4319306a2d09c119e312848dc8 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 15 Oct 2013 11:25:11 +1300 Subject: [PATCH 0807/1160] Fix a few typos in comments and docs --- CHANGES | 6 +++--- Doc/Manual/SWIGPlus.html | 2 +- Doc/Manual/Typemaps.html | 2 +- Lib/python/pytypemaps.swg | 2 +- Lib/swig.swg | 2 +- Lib/typemaps/swigmacros.swg | 10 +++++----- Lib/typemaps/swigtypemaps.swg | 2 +- Source/Swig/typesys.c | 6 +++--- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/CHANGES b/CHANGES index 4cc222901..da5fb1f07 100644 --- a/CHANGES +++ b/CHANGES @@ -201,7 +201,7 @@ Version 2.0.10 (27 May 2013) The macros are silently ignored. 2013-04-17: wsfulton - [C#] Pull patch #34 from BrantKyser to fix smart pointers in conjuction with directors. + [C#] Pull patch #34 from BrantKyser to fix smart pointers in conjunction with directors. 2013-04-15: kwwette [Octave] Fix bugs in output of cleanup code. @@ -5206,7 +5206,7 @@ Version 1.3.29 (March 21, 2006) 6146 _std_containers.so 174 _std_containers.so.hidden - Excecution times: + Execution times: real 0m0.050s user 0m0.039s sys 0m0.005s _std_containers.so real 0m0.039s user 0m0.026s sys 0m0.007s _std_containers.so.hidden @@ -5292,7 +5292,7 @@ Version 1.3.29 (March 21, 2006) protected methods by default. In previous releases, you needed to use the 'dirprot' - option to acheive the same. + option to achieve the same. If you want, you can disable the new default behaviour, use the 'nodirprot' option: diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index 2713725d7..2ed450c01 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -1522,7 +1522,7 @@ multiple inheritance. spirit, and target language capabilities, as possible. In most cases, this means that SWIG will parse the non-public inheritance declarations, but that will have no effect in the generated code, -besides the implicit policies derived for constructor and +besides the implicit policies derived for constructors and destructors.

    diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index 81e3fd1bb..20ad085f8 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -3956,7 +3956,7 @@ Requirements for the type system:
  • Store inheritance and type equivalence information and be able to correctly re-create the type pointer.
  • Share type information between modules.
  • -
  • Modules can be loaded in any order, irregardless of actual type +
  • Modules can be loaded in any order, regardless of actual type dependency.
  • Avoid the use of dynamically allocated memory, and library/system calls in general.
  • Provide a reasonably fast implementation, minimizing the lookup time for all diff --git a/Lib/python/pytypemaps.swg b/Lib/python/pytypemaps.swg index c64b47b05..5c6abb01e 100644 --- a/Lib/python/pytypemaps.swg +++ b/Lib/python/pytypemaps.swg @@ -9,7 +9,7 @@ #undef SWIG_TYPECHECK_BOOL %define SWIG_TYPECHECK_BOOL 10000 %enddef -/* Include fundamental fragemt definitions */ +/* Include fundamental fragment definitions */ %include /* Look for user fragments file. */ diff --git a/Lib/swig.swg b/Lib/swig.swg index ad6b7b64b..241d93f3f 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -258,7 +258,7 @@ static int NAME(TYPE x) { %rename("$ignore", %$isenumitem, %$classname="MyClass") ""; - we use the prefix '%$' to avoid clashings with other swig + we use the prefix '%$' to avoid clashes with other swig macros/directives. */ diff --git a/Lib/typemaps/swigmacros.swg b/Lib/typemaps/swigmacros.swg index c9b42facf..61470583e 100644 --- a/Lib/typemaps/swigmacros.swg +++ b/Lib/typemaps/swigmacros.swg @@ -3,16 +3,16 @@ * ----------------------------------------------------------------------------- */ /* This file implements the internal macros of the 'SWIG API', which - are useful to implement all the SWIG target languges. + are useful to implement all the SWIG target languages. Basic preprocessor macros: -------------------------- %arg(Arg) Safe argument wrap - %str(Arg) Stringtify the argument - %begin_block Begin a execution block - %end_block End a execution block - %block(Block) Execute Block as a excecution block + %str(Arg) Stringify the argument + %begin_block Begin an execution block + %end_block End an execution block + %block(Block) Execute Block as an execution block %define_as(Def, Val) Define 'Def' as 'Val', expanding Def and Val first %ifcplusplus(V1, V2) if C++ Mode; then V1; else V2; fi diff --git a/Lib/typemaps/swigtypemaps.swg b/Lib/typemaps/swigtypemaps.swg index 0e39afe4c..4e5bb2b04 100644 --- a/Lib/typemaps/swigtypemaps.swg +++ b/Lib/typemaps/swigtypemaps.swg @@ -12,7 +12,7 @@ and then include this file. Typically you will create a 'mytypemaps.swg' file in each target - languge, where you will have the following sections: + language, where you will have the following sections: === mytypemaps.swg === diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index 1552703c6..bcfd2feb5 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -1381,13 +1381,13 @@ int SwigType_type(const SwigType *t) { * * 2.- swig doesn't mark 'type' as non-assignable. * - * 3.- the user specify that the value wrapper is not needed by using - * the %feature("novaluewrapper"), in that case the user need to type + * 3.- the user specifies that the value wrapper is not needed by using + * %feature("novaluewrapper") like so: * * %feature("novaluewrapper") MyOpaqueClass; * class MyOpaqueClass; * - * Users can also force the use of the value wrapper by using the + * The user can also force the use of the value wrapper with * %feature("valuewrapper"). * ----------------------------------------------------------------------------- */ From cecd89f66f7d8e7949323358d37b78ddbf268c76 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 12 Dec 2013 15:39:10 +1300 Subject: [PATCH 0808/1160] [PHP] The usage of $input in PHP directorout typemaps has been changed to be consistent with other languages. The typemaps provided by SWIG have been updated accordingly, but if you have written your own directorout typemaps, you'll need to update $input to &$input (or make equivalent changes). *** POTENTIAL INCOMPATIBILITY *** --- CHANGES.current | 9 +++++++++ Examples/test-suite/typemap_directorout.i | 18 ------------------ Lib/php/php.swg | 2 +- Lib/php/std_string.i | 8 ++++---- Lib/php/utils.i | 4 ++-- Source/Modules/php.cxx | 3 +-- 6 files changed, 17 insertions(+), 27 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index a4d12239d..597a0e853 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,15 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-12-12: olly + [PHP] The usage of $input in PHP directorout typemaps has been + changed to be consistent with other languages. The typemaps + provided by SWIG have been updated accordingly, but if you + have written your own directorout typemaps, you'll need to + update $input to &$input (or make equivalent changes). + + *** POTENTIAL INCOMPATIBILITY *** + 2013-11-27: vadz [C#, Java, Python] Add std_auto_ptr.i defining typemaps for returning std::auto_ptr<>. diff --git a/Examples/test-suite/typemap_directorout.i b/Examples/test-suite/typemap_directorout.i index fb0a6ab81..4a85bd47c 100644 --- a/Examples/test-suite/typemap_directorout.i +++ b/Examples/test-suite/typemap_directorout.i @@ -13,24 +13,6 @@ // Can't use the %typemap(directorout) MyType & = SWIGTYPE & approach as non-director languages don't define any directorout typemaps %typemap(directorout) MyType &Class1::foo2, MyType &foo1 %{ /* special start */ $input = 0; /* special end */ %} -#ifdef SWIGPHP -%typemap(directorout, warning="PHP directorout typemaps need fixing") MyType &Class1::foo2, MyType &foo1 %{ /* special start */ /*$input = 0;*/ /* special end */ %} -/* Patch to make $input work same as other languages. Then $input needs changing to &$input in most (maybe all) typemaps. ---- a/Source/Modules/php.cxx -+++ b/Source/Modules/php.cxx -@@ -2631,8 +2631,7 @@ done: - if (!is_void) { - tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); - if (tm != 0) { -- static const String *amp_result = NewStringf("&%s", Swig_cresult_name()); -- Replaceall(tm, "$input", amp_result); -+ Replaceall(tm, "$input", Swig_cresult_name()); - char temp[24]; - sprintf(temp, "%d", idx); - Replaceall(tm, "$argnum", temp); -*/ -#endif - #ifdef SWIGCSHARP %typemap(csdirectorout) MyType & %{ WILL_NOT_COMPILE %} diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 325abbcd4..afa047ef6 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -93,7 +93,7 @@ %typemap(directorout) SWIGTYPE ($&1_ltype tmp) { - if(SWIG_ConvertPtr(*$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { + if(SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); } $result = *tmp; diff --git a/Lib/php/std_string.i b/Lib/php/std_string.i index 10d7fdd31..aaa5dc9cd 100644 --- a/Lib/php/std_string.i +++ b/Lib/php/std_string.i @@ -33,8 +33,8 @@ namespace std { %} %typemap(directorout) string %{ - convert_to_string_ex($input); - $result.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input)); + convert_to_string_ex(&$input); + $result.assign(Z_STRVAL_P($input), Z_STRLEN_P($input)); %} %typemap(out) string %{ @@ -63,8 +63,8 @@ namespace std { %} %typemap(directorout) string & ($*1_ltype *temp) %{ - convert_to_string_ex($input); - temp = new $*1_ltype(Z_STRVAL_PP($input), Z_STRLEN_PP($input)); + convert_to_string_ex(&$input); + temp = new $*1_ltype(Z_STRVAL_P($input), Z_STRLEN_P($input)); swig_acquire_ownership(temp); $result = temp; %} diff --git a/Lib/php/utils.i b/Lib/php/utils.i index 07ac96900..c3b19a320 100644 --- a/Lib/php/utils.i +++ b/Lib/php/utils.i @@ -80,11 +80,11 @@ %} %typemap(directorout) TYPE %{ - CONVERT_IN($result,$1_ltype,$input); + CONVERT_IN($result,$1_ltype,&$input); %} %typemap(directorout) const TYPE & ($*1_ltype temp) %{ - CONVERT_IN(temp,$*1_ltype,$input); + CONVERT_IN(temp,$*1_ltype,&$input); $result = &temp; %} %enddef diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index def917019..a8659b9f1 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2626,8 +2626,7 @@ done: if (!is_void) { tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); if (tm != 0) { - static const String *amp_result = NewStringf("&%s", Swig_cresult_name()); - Replaceall(tm, "$input", amp_result); + Replaceall(tm, "$input", Swig_cresult_name()); char temp[24]; sprintf(temp, "%d", idx); Replaceall(tm, "$argnum", temp); From abeba4564401e10d908cc5240b7f748dabd3b201 Mon Sep 17 00:00:00 2001 From: Michael Bunk Date: Sat, 23 Nov 2013 19:19:37 +0100 Subject: [PATCH 0809/1160] Fix typos --- Doc/Manual/Introduction.html | 12 +++++------ Doc/Manual/SWIG.html | 40 ++++++++++++++++++------------------ Doc/Manual/Scripting.html | 10 ++++----- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Doc/Manual/Introduction.html b/Doc/Manual/Introduction.html index a8d15a5c2..d5dc778bd 100644 --- a/Doc/Manual/Introduction.html +++ b/Doc/Manual/Introduction.html @@ -38,7 +38,7 @@ SWIG is a software development tool that simplifies the task of interfacing different languages to C and C++ programs. In a nutshell, SWIG is a compiler that takes C/C++ declarations and creates -the wrappers needed to access those declarations from other languages including +the wrappers needed to access those declarations from other languages including Perl, Python, Tcl, Ruby, Guile, and Java. SWIG normally requires no modifications to existing code and can often be used to build a usable interface in only a few minutes. Possible applications @@ -49,7 +49,7 @@ of SWIG include:
  • Building interpreted interfaces to existing C programs.
  • Rapid prototyping and application development.
  • Interactive debugging. -
  • Reengineering or refactoring of legacy software into a scripting language components. +
  • Reengineering or refactoring of legacy software into scripting language components.
  • Making a graphical user interface (using Tk for example).
  • Testing of C libraries and programs (using scripts).
  • Building high performance C modules for scripting languages. @@ -98,7 +98,7 @@ of other libraries).
  • Testing is time consuming (the compile/debug cycle).
  • Not easy to reconfigure or customize without recompilation.
  • Modularization can be tricky. -
  • Security concerns (buffer overflow for instance). +
  • Security concerns (buffer overflows for instance).

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

    -#define F_CONST (double) 5            // A floating pointer constant with cast
    +#define F_CONST (double) 5            // A floating point constant with cast
     
    @@ -750,7 +750,7 @@ enum values as assigned by the C compiler.

    The %constant directive is used to more precisely create constants corresponding to different C datatypes. Although it is not -usually not needed for simple values, it is more useful when working +usually needed for simple values, it is more useful when working with pointers and other more complex datatypes. Typically, %constant is only used when you want to add constants to the scripting language interface that are not defined in the original header file. @@ -868,7 +868,7 @@ from a scripting language to a C char *, the pointer usually points to string data stored inside the interpreter. It is almost always a really bad idea to modify this data. Furthermore, some languages may explicitly disallow it. For instance, in Python, -strings are supposed be immutable. If you violate this, you will probably +strings are supposed to be immutable. If you violate this, you will probably receive a vast amount of wrath when you unleash your module on the world.

    @@ -1483,7 +1483,7 @@ void transpose(double (*a)[20]);

    Like C, SWIG does not perform array bounds checking. It is up to the -user to make sure the pointer points a suitably allocated region of memory. +user to make sure the pointer points to a suitably allocated region of memory.

    @@ -2265,7 +2265,7 @@ disabled using %nocallback. When you do this, the interface now works

    Notice that when the function is used as a callback, special names -such as add_cb is used instead. To call the function +such as add_cb are used instead. To call the function normally, just use the original function name such as add().

    @@ -2311,7 +2311,7 @@ handle C++ are described in the next section. If SWIG encounters the definition of a structure or union, it creates a set of accessor functions. Although SWIG does not need structure definitions to build an interface, providing definitions -make it possible to access structure members. The accessor functions +makes it possible to access structure members. The accessor functions generated by SWIG simply take a pointer to an object and allow access to an individual member. For example, the declaration :

    @@ -2434,7 +2434,7 @@ vector_struct
    , SWIG knows that this is the same as Structures involving character strings require some care. SWIG assumes that all members of type char * have been dynamically allocated using malloc() and that they are NULL-terminated -ASCII strings. When such a member is modified, the previously contents +ASCII strings. When such a member is modified, the previous contents will be released, and the new contents allocated. For example :

    @@ -2519,7 +2519,7 @@ typedef struct Bar {
     

    When a structure member is wrapped, it is handled as a pointer, unless the %naturalvar directive is used where it is handled more like a C++ reference (see C++ Member data). -The accessors to the member variable as a pointer is effectively wrapped as follows: +The accessors to the member variable as a pointer are effectively wrapped as follows:

    @@ -2656,8 +2656,8 @@ struct Bar { // Default constructor generated.

    -Since ignoring the implicit or default destructors most of the times -produce memory leaks, SWIG will always try to generate them. If +Since ignoring the implicit or default destructors most of the time +produces memory leaks, SWIG will always try to generate them. If needed, however, you can selectively disable the generation of the default/implicit destructor by using %nodefaultdtor

    @@ -2687,7 +2687,7 @@ has now been enabled as the default behavior. Note: There are also the -nodefault option and %nodefault directive, which disable both the default or implicit destructor generation. This could lead to memory leaks across -the target languages, and is highly recommended you don't use them. +the target languages, and it is highly recommended you don't use them.

    @@ -3280,7 +3280,7 @@ initialization on module loading, you could write this:

    -This section describes the general approach for building interface +This section describes the general approach for building interfaces with SWIG. The specifics related to a particular scripting language are found in later chapters.

    @@ -3295,9 +3295,9 @@ of steps you can follow to make an interface for a C program :

    • Identify the functions that you want to wrap. It's probably not -necessary to access every single function in a C program--thus, a +necessary to access every single function of a C program--thus, a little forethought can dramatically simplify the resulting scripting -language interface. C header files are particularly good source for +language interface. C header files are a particularly good source for finding things to wrap.
    • Create a new interface file to describe the scripting language @@ -3342,7 +3342,7 @@ to the swig-devel mailing list or to

      -The preferred method of using SWIG is to generate separate interface +The preferred method of using SWIG is to generate a separate interface file. Suppose you have the following C header file :

      @@ -3436,7 +3436,7 @@ include certain header files by using a %{,%} block like this:
       #include <GL/glu.h>
       %}
       
      -// Put rest of declarations here
      +// Put the rest of the declarations here
       ...
       
      @@ -3478,7 +3478,7 @@ program that is more interactive. In many cases, the old or Tcl script.

      -Note: If some cases, you might be inclined to create a +Note: In some cases, you might be inclined to create a scripting language wrapper for main(). If you do this, the compilation will probably work and your module might even load correctly. The only trouble is that when you call your diff --git a/Doc/Manual/Scripting.html b/Doc/Manual/Scripting.html index e6a2eee24..26a8dd017 100644 --- a/Doc/Manual/Scripting.html +++ b/Doc/Manual/Scripting.html @@ -293,7 +293,7 @@ A proxy class is a special kind of object that gets created in a scripting language to access a C/C++ class (or struct) in a way that looks like the original structure (that is, it proxies the real C++ class). For example, if you -have the following C definition :

      +have the following C++ definition :

       class Vector {
      @@ -334,12 +334,12 @@ Finally, in Tcl :
       
       
       Vector v
      -v configure -x 3 -y 4 -z 13
      +v configure -x 3 -y 4 -z -13
       
       

      -When proxy classes are used, two objects are at really work--one in +When proxy classes are used, two objects are really at work--one in the scripting language, and an underlying C/C++ object. Operations affect both objects equally and for all practical purposes, it appears as if you are simply manipulating a C/C++ object. @@ -353,7 +353,7 @@ The final step in using a scripting language with your C/C++ application is adding your extensions to the scripting language itself. There are two primary approaches for doing this. The preferred technique is to build a dynamically loadable -extension in the form a shared library. Alternatively, you can +extension in the form of a shared library. Alternatively, you can recompile the scripting language interpreter with your extensions added to it.

      @@ -364,7 +364,7 @@ added to it.

      To create a shared library or DLL, you often need to look at the manual pages for your compiler and linker. However, the procedure -for a few common machines is shown below:

      +for a few common platforms is shown below:

       # Build a shared library for Solaris
      
      From 8be8b62d8381813618ad259d16ebd87d11118eb9 Mon Sep 17 00:00:00 2001
      From: jleveque 
      Date: Tue, 19 Nov 2013 23:55:37 -0600
      Subject: [PATCH 0810/1160] Fix compile warning on Linux
      
      ---
       Lib/lua/wchar.i | 2 +-
       1 file changed, 1 insertion(+), 1 deletion(-)
      
      diff --git a/Lib/lua/wchar.i b/Lib/lua/wchar.i
      index 141ecc41f..aff21b46c 100644
      --- a/Lib/lua/wchar.i
      +++ b/Lib/lua/wchar.i
      @@ -18,7 +18,7 @@ wchar_t* str2wstr(const char *str, int len)
         if (str==0 || len<1)  return 0;
         p=(wchar *)malloc((len+1)*sizeof(wchar_t));
         if (p==0)	return 0;
      -  if (mbstowcs(p, str, len)==-1)
      +  if (mbstowcs(p, str, len)==(size_t)-1)
         {
           free(p);
           return 0;
      
      From 227192f80a79db7edfb25342cd13626be49e567f Mon Sep 17 00:00:00 2001
      From: Miklos Vajna 
      Date: Mon, 18 Nov 2013 21:50:33 +0100
      Subject: [PATCH 0811/1160] Fix Examples/php/pointer to work with PHP 5.5
      
      With this, all examples work with PHP 5.5 for me.
      ---
       Examples/php/pointer/runme.php |  2 +-
       Lib/php/phppointers.i          |  2 +-
       Source/Modules/php.cxx         | 34 ++++++++++++++++++++++++++--------
       3 files changed, 28 insertions(+), 10 deletions(-)
      
      diff --git a/Examples/php/pointer/runme.php b/Examples/php/pointer/runme.php
      index 5e86de6a2..e79b23810 100644
      --- a/Examples/php/pointer/runme.php
      +++ b/Examples/php/pointer/runme.php
      @@ -15,7 +15,7 @@
       	print "	c = $c\n";
       
       	# Call the add() function wuth some pointers
      -	add(&$a,&$b,&$c);
      +	add($a,$b,$c);
       
       	print "	$a + $b = $c\n";
       
      diff --git a/Lib/php/phppointers.i b/Lib/php/phppointers.i
      index 91b2c6d96..e50ada7ac 100644
      --- a/Lib/php/phppointers.i
      +++ b/Lib/php/phppointers.i
      @@ -1,5 +1,5 @@
       %define %pass_by_ref( TYPE, CONVERT_IN, CONVERT_OUT )
      -%typemap(in) TYPE *REF ($*1_ltype tmp),
      +%typemap(in, byref=1) TYPE *REF ($*1_ltype tmp),
                    TYPE &REF ($*1_ltype tmp)
       %{
         /* First Check for SWIG wrapped type */
      diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx
      index a8659b9f1..a4b01a624 100644
      --- a/Source/Modules/php.cxx
      +++ b/Source/Modules/php.cxx
      @@ -90,6 +90,7 @@ static String *s_vinit;		// varinit initialization code.
       static String *s_vdecl;
       static String *s_cinit;		// consttab initialization code.
       static String *s_oinit;
      +static String *s_arginfo;
       static String *s_entry;
       static String *cs_entry;
       static String *all_cs_entry;
      @@ -517,6 +518,9 @@ public:
           Printf(f_h, "PHP_RSHUTDOWN_FUNCTION(%s);\n", module);
           Printf(f_h, "PHP_MINFO_FUNCTION(%s);\n\n", module);
       
      +    /* start the arginfo section */
      +    s_arginfo = NewString("/* arginfo subsection */\n");
      +
           /* start the function entry section */
           s_entry = NewString("/* entry subsection */\n");
       
      @@ -643,7 +647,7 @@ public:
             Dump(f_directors, f_begin);
           }
           Printv(f_begin, s_vdecl, s_wrappers, NIL);
      -    Printv(f_begin, all_cs_entry, "\n\n", s_entry,
      +    Printv(f_begin, all_cs_entry, "\n\n", s_arginfo, "\n\n", s_entry,
       	" SWIG_ZEND_NAMED_FE(swig_", module, "_alter_newobject,_wrap_swig_", module, "_alter_newobject,NULL)\n"
       	" SWIG_ZEND_NAMED_FE(swig_", module, "_get_newobject,_wrap_swig_", module, "_get_newobject,NULL)\n"
       	"{NULL, NULL, NULL}\n};\n\n", NIL);
      @@ -654,6 +658,7 @@ public:
           Delete(s_vdecl);
           Delete(all_cs_entry);
           Delete(s_entry);
      +    Delete(s_arginfo);
           Delete(f_runtime);
           Delete(f_begin);
       
      @@ -672,12 +677,25 @@ public:
         }
       
         /* Just need to append function names to function table to register with PHP. */
      -  void create_command(String *cname, String *iname) {
      +  void create_command(String *cname, String *iname, Node *n) {
           // This is for the single main zend_function_entry record
           Printf(f_h, "ZEND_NAMED_FUNCTION(%s);\n", iname);
           String * s = cs_entry;
           if (!s) s = s_entry;
      -    Printf(s, " SWIG_ZEND_NAMED_FE(%(lower)s,%s,NULL)\n", cname, iname);
      +    Printf(s, " SWIG_ZEND_NAMED_FE(%(lower)s,%s,swig_arginfo_%(lower)s)\n", cname, iname, cname);
      +
      +    // This is the above referenced arginfo structure.
      +    ParmList *l = Getattr(n, "parms");
      +    Printf(s_arginfo, "ZEND_BEGIN_ARG_INFO_EX(swig_arginfo_%(lower)s, 0, 0, 0)\n", cname);
      +    for (Parm *p = l; p; p = Getattr(p, "tmap:in:next")) {
      +      /* Ignored parameters */
      +      if (checkAttribute(p, "tmap:in:numinputs", "0")) {
      +	continue;
      +      }
      +      int byref = GetFlag(p, "tmap:in:byref");
      +      Printf(s_arginfo, " ZEND_ARG_PASS_INFO(%d)\n", byref);
      +    }
      +    Printf(s_arginfo, "ZEND_END_ARG_INFO()\n");
         }
       
         /* ------------------------------------------------------------
      @@ -700,7 +718,7 @@ public:
           String *symname = Getattr(n, "sym:name");
           String *wname = Swig_name_wrapper(symname);
       
      -    create_command(symname, wname);
      +    create_command(symname, wname, n);
           Printv(f->def, "ZEND_NAMED_FUNCTION(", wname, ") {\n", NIL);
       
           Wrapper_add_local(f, "argc", "int argc");
      @@ -790,16 +808,16 @@ public:
           String *outarg = NewStringEmpty();
           String *cleanup = NewStringEmpty();
       
      -    // Not issued for overloaded functions.
      -    if (!overloaded) {
      -      create_command(iname, wname);
      -    }
           Printv(f->def, "ZEND_NAMED_FUNCTION(", wname, ") {\n", NIL);
       
           emit_parameter_variables(l, f);
           /* Attach standard typemaps */
       
           emit_attach_parmmaps(l, f);
      +    // Not issued for overloaded functions.
      +    if (!overloaded) {
      +      create_command(iname, wname, n);
      +    }
       
           // wrap:parms is used by overload resolution.
           Setattr(n, "wrap:parms", l);
      
      From bef3cfe594d292576d53b39b385fa4e32b6bb14d Mon Sep 17 00:00:00 2001
      From: Olly Betts 
      Date: Thu, 12 Dec 2013 16:06:00 +1300
      Subject: [PATCH 0812/1160] Add CHANGES.current entry and minimal doc update
       for previous change
      
      ---
       CHANGES.current     |  7 +++++++
       Doc/Manual/Php.html | 11 ++++++-----
       2 files changed, 13 insertions(+), 5 deletions(-)
      
      diff --git a/CHANGES.current b/CHANGES.current
      index 597a0e853..719fbe879 100644
      --- a/CHANGES.current
      +++ b/CHANGES.current
      @@ -5,6 +5,13 @@ See the RELEASENOTES file for a summary of changes in each release.
       Version 3.0.0 (in progress)
       ============================
       
      +2013-12-12: vmiklos
      +	    [PHP] PHP's peculiar call-time pass-by-reference feature was
      +	    deprecated in PHP 5.3 and removed in PHP 5.4, so update the REF
      +	    typemaps in phppointers.i to specify pass-by-reference in the
      +	    function definition.  Examples/php/pointer has been updated
      +	    accordingly.
      +
       2013-12-12: olly
       	    [PHP] The usage of $input in PHP directorout typemaps has been
       	    changed to be consistent with other languages.  The typemaps
      diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html
      index 78ee6ea7f..185883235 100644
      --- a/Doc/Manual/Php.html
      +++ b/Doc/Manual/Php.html
      @@ -503,13 +503,14 @@ echo "The sum $in1 + $in2 = $result\n";
       Because PHP has a native concept of reference, it may seem more natural
       to the PHP developer to use references to pass pointers.  To enable
       this, one needs to include phppointers.i which defines the
      -named typemap REFERENCE.
      +named typemap REF.
       

      -However, this relies on call-time pass-by-reference, which has been -deprecated in PHP for some time, and was finally removed in PHP 5.4. -So you should avoid creating new wrappers which rely on this approach. +Prior to SWIG 3.0, the REF typemaps relied on PHP's call-time +pass-by-reference, which was deprecated in PHP 5.3 and removed in PHP 5.4. +So if you use these REF typemaps, you should ensure that SWIG≥3.0 is +used to generate wrappers from your interface file.

      @@ -532,7 +533,7 @@ include("example.php");
       $in1 = 3;
       $in2 = 5;
       $result = 0;
      -add(&$in1,&$in2,&$result);
      +add($in1,$in2,$result);
       
       echo "The sum $in1 + $in2 = $result\n";
       ?>
      
      From c7ef5935496a04f3a83c70af6f841abf3ad7606e Mon Sep 17 00:00:00 2001
      From: jleveque 
      Date: Sat, 16 Nov 2013 14:19:18 -0600
      Subject: [PATCH 0813/1160] Bug fix (typo - "wchar" instead of "wchar_t")
      
      ---
       Lib/lua/wchar.i | 2 +-
       1 file changed, 1 insertion(+), 1 deletion(-)
      
      diff --git a/Lib/lua/wchar.i b/Lib/lua/wchar.i
      index aff21b46c..9f3be6fca 100644
      --- a/Lib/lua/wchar.i
      +++ b/Lib/lua/wchar.i
      @@ -16,7 +16,7 @@ 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_t *)malloc((len+1)*sizeof(wchar_t));
         if (p==0)	return 0;
         if (mbstowcs(p, str, len)==(size_t)-1)
         {
      
      From dcc4096f8c7388cd7f9153458f1c56518bf7d7dd Mon Sep 17 00:00:00 2001
      From: Olly Betts 
      Date: Thu, 12 Dec 2013 17:00:26 +1300
      Subject: [PATCH 0814/1160] Add CHANGES.current entry for previous commit
      
      ---
       CHANGES.current | 4 ++++
       1 file changed, 4 insertions(+)
      
      diff --git a/CHANGES.current b/CHANGES.current
      index 719fbe879..3df92ef33 100644
      --- a/CHANGES.current
      +++ b/CHANGES.current
      @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
       Version 3.0.0 (in progress)
       ============================
       
      +2013-12-12: jleveque
      +	    [Lua] Fix typo (wchar instead of wchar_t) which made wchar.i
      +	    for Lua useless.
      +
       2013-12-12: vmiklos
       	    [PHP] PHP's peculiar call-time pass-by-reference feature was
       	    deprecated in PHP 5.3 and removed in PHP 5.4, so update the REF
      
      From e95ac8265154e1f3f9f05406c7f800182f1350b9 Mon Sep 17 00:00:00 2001
      From: William S Fulton 
      Date: Thu, 12 Dec 2013 07:59:47 +0000
      Subject: [PATCH 0815/1160] Nested C class setters restored in c++out mode for
       Octave
      
      Suitable casts are required so that assignment of instances of nested classes
      work as the nested class is duplicated in the global namespace, eg:
      
      struct Outer {
        struct Nested {
          int bar;
        } bar_instance;
      };
      
      Outer.bar_instance can now be assigned to.
      ---
       Examples/test-suite/nested_structs.i          |  2 ++
       .../test-suite/octave/nested_structs_runme.m  | 14 +++++++++++++
       Lib/typemaps/swigtype.swg                     |  6 +++---
       Source/CParse/parser.y                        |  4 ++--
       Source/Swig/cwrap.c                           | 21 ++++++++++++++++++-
       5 files changed, 41 insertions(+), 6 deletions(-)
       create mode 100644 Examples/test-suite/octave/nested_structs_runme.m
      
      diff --git a/Examples/test-suite/nested_structs.i b/Examples/test-suite/nested_structs.i
      index add24ec17..459f25f00 100644
      --- a/Examples/test-suite/nested_structs.i
      +++ b/Examples/test-suite/nested_structs.i
      @@ -23,6 +23,8 @@ void setValues(struct Outer *outer, int val) {
         outer->inside3 = &outer->inside2;
         outer->inside4[0].val = val * 4;
       }
      +
      +int getInside1Val(struct Outer *n) { return n->inside1.val; }
       %}
       
       /* 
      diff --git a/Examples/test-suite/octave/nested_structs_runme.m b/Examples/test-suite/octave/nested_structs_runme.m
      new file mode 100644
      index 000000000..a04aaa672
      --- /dev/null
      +++ b/Examples/test-suite/octave/nested_structs_runme.m
      @@ -0,0 +1,14 @@
      +nested_structs
      +
      +named = nested_structs.Named();
      +named.val = 999;
      +assert(nested_structs.nestedByVal(named), 999);
      +assert(nested_structs.nestedByPtr(named), 999);
      +
      +outer = nested_structs.Outer();
      +outer.inside1.val = 456;
      +assert(nested_structs.getInside1Val(outer), 456);
      +
      +outer.inside1 = named;
      +assert(nested_structs.getInside1Val(outer), 999);
      +
      diff --git a/Lib/typemaps/swigtype.swg b/Lib/typemaps/swigtype.swg
      index 5e92790d8..6c0affbe2 100644
      --- a/Lib/typemaps/swigtype.swg
      +++ b/Lib/typemaps/swigtype.swg
      @@ -159,7 +159,7 @@
       %typemap(memberin) SWIGTYPE [ANY] {
         if ($input) {
           size_t ii = 0;
      -    for (; ii < (size_t)$1_dim0; ++ii) $1[ii] = $input[ii];
      +    for (; ii < (size_t)$1_dim0; ++ii) *($1_ltype)&$1[ii] = ($*1_ltype)$input[ii];
         } else {
           %variable_nullref("$type","$name");
         }
      @@ -168,7 +168,7 @@
       %typemap(globalin) SWIGTYPE [ANY] {
         if ($input) {
           size_t ii = 0;
      -    for (; ii < (size_t)$1_dim0; ++ii) $1[ii] = $input[ii];
      +    for (; ii < (size_t)$1_dim0; ++ii) *($1_ltype)&$1[ii] = ($*1_ltype)$input[ii];
         } else {
           %variable_nullref("$type","$name");
         }
      @@ -181,7 +181,7 @@
           %variable_fail(res, "$type", "$name");
         } else if (inp) {
           size_t ii = 0;
      -    for (; ii < (size_t)$1_dim0; ++ii) $1[ii] = inp[ii];
      +    for (; ii < (size_t)$1_dim0; ++ii) *($1_ltype)&$1[ii] = ($*1_ltype)inp[ii];
         } else {
           %variable_nullref("$type", "$name");
         }
      diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
      index 0124ad25a..8e34833e2 100644
      --- a/Source/CParse/parser.y
      +++ b/Source/CParse/parser.y
      @@ -3513,7 +3513,7 @@ cpp_class_decl  : storage_class cpptype idcolon inherit LBRACE {
       		   while (p) {
       		     Setattr(p, "storage", $1);
       		     Setattr(p, "type" ,ty);
      -		     if (!cparse_cplusplus && currentOuterClass && (!Getattr(currentOuterClass, "name") || CPlusPlusOut)) {
      +		     if (!cparse_cplusplus && currentOuterClass && (!Getattr(currentOuterClass, "name"))) {
       		       SetFlag(p, "hasconsttype");
       		       SetFlag(p, "feature:immutable");
       		     }
      @@ -3674,7 +3674,7 @@ cpp_class_decl  : storage_class cpptype idcolon inherit LBRACE {
       		   while (n) {
       		     Setattr(n,"storage",$1);
       		     Setattr(n, "type", ty);
      -		     if (!cparse_cplusplus && currentOuterClass && (!Getattr(currentOuterClass, "name") || CPlusPlusOut)) {
      +		     if (!cparse_cplusplus && currentOuterClass && (!Getattr(currentOuterClass, "name"))) {
       		       SetFlag(n,"hasconsttype");
       		       SetFlag(n,"feature:immutable");
       		     }
      diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c
      index 6f8fa39e9..03020bb72 100644
      --- a/Source/Swig/cwrap.c
      +++ b/Source/Swig/cwrap.c
      @@ -15,6 +15,7 @@
       #include "swig.h"
       
       extern int cparse_cplusplus;
      +extern int CPlusPlusOut;
       static const char *cresult_variable_name = "result";
       
       static Parm *nonvoid_parms(Parm *p) {
      @@ -775,7 +776,25 @@ String *Swig_cmemberset_call(const_String_or_char_ptr name, SwigType *type, Stri
         if (SwigType_type(type) != T_ARRAY) {
           if (!Strstr(type, "enum $unnamed")) {
             String *dref = Swig_wrapped_var_deref(type, pname1, varcref);
      -      Printf(func, "if (%s) %s%s = %s", pname0, self, name, dref);
      +      int extra_cast = 0;
      +      if (CPlusPlusOut) {
      +	/* Required for C nested structs compiled as C++ as a duplicate of the nested struct is put into the global namespace.
      +	 * We could improve this by adding the extra casts just for nested structs rather than all structs. */
      +	String *base = SwigType_base(type);
      +	extra_cast = SwigType_isclass(base);
      +	Delete(base);
      +      }
      +      if (extra_cast) {
      +	String *lstr;
      +	SwigType *ptype = Copy(type);
      +	SwigType_add_pointer(ptype);
      +	lstr = SwigType_lstr(ptype, 0);
      +	Printf(func, "if (%s) *(%s)&%s%s = %s", pname0, lstr, self, name, dref);
      +	Delete(lstr);
      +	Delete(ptype);
      +      } else {
      +        Printf(func, "if (%s) %s%s = %s", pname0, self, name, dref);
      +      }
             Delete(dref);
           } else {
             Printf(func, "if (%s && sizeof(int) == sizeof(%s%s)) *(int*)(void*)&(%s%s) = %s", pname0, self, name, self, name, pname1);
      
      From 3b4d33131096949e5dc3800a96760e096555db6b Mon Sep 17 00:00:00 2001
      From: William S Fulton 
      Date: Thu, 12 Dec 2013 08:23:56 +0000
      Subject: [PATCH 0816/1160] Add missing header to new source file
      
      ---
       Source/Modules/nested.cxx | 13 +++++++++++++
       1 file changed, 13 insertions(+)
      
      diff --git a/Source/Modules/nested.cxx b/Source/Modules/nested.cxx
      index 4be27ebc4..ff563b3ba 100644
      --- a/Source/Modules/nested.cxx
      +++ b/Source/Modules/nested.cxx
      @@ -1,3 +1,16 @@
      +/* -----------------------------------------------------------------------------
      + * 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.
      + *
      + * nested.cxx
      + *
      + * Nested structs support
      + * ----------------------------------------------------------------------------- */
      +
       #include "swigmod.h"
       #include "cparse.h"
       
      
      From 2121e1217eae19a0a3e852fc52c89f55faf7e20a Mon Sep 17 00:00:00 2001
      From: William S Fulton 
      Date: Thu, 12 Dec 2013 20:44:08 +0000
      Subject: [PATCH 0817/1160] Ensure -c++out is not used with -c++
      
      Error checking for this combination implemented as well as correcting
      Octave
      
      Also refactor, replacing CPlusPlusOut variable with cparse_cplusplusout
      for an implementation which more closely resembles cparse_cplusplus which
      is also required in both .c and .cxx files.
      ---
       Source/CParse/cparse.h    |  2 ++
       Source/CParse/cscanner.c  | 11 +++++++++++
       Source/CParse/parser.y    |  5 ++---
       Source/Modules/main.cxx   | 12 +++++++-----
       Source/Modules/nested.cxx |  2 +-
       Source/Modules/octave.cxx |  6 +++++-
       Source/Modules/swigmod.h  |  1 -
       Source/Swig/cwrap.c       |  5 ++---
       8 files changed, 30 insertions(+), 14 deletions(-)
      
      diff --git a/Source/CParse/cparse.h b/Source/CParse/cparse.h
      index 19bf3f3f0..6d7342a45 100644
      --- a/Source/CParse/cparse.h
      +++ b/Source/CParse/cparse.h
      @@ -25,9 +25,11 @@ extern "C" {
         extern String *cparse_file;
         extern int cparse_line;
         extern int cparse_cplusplus;
      +  extern int cparse_cplusplusout;
         extern int cparse_start_line;
       
         extern void Swig_cparse_cplusplus(int);
      +  extern void Swig_cparse_cplusplusout(int);
         extern void scanner_file(File *);
         extern void scanner_next_token(int);
         extern void skip_balanced(int startchar, int endchar);
      diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c
      index ee2c49cd4..2dfc2c479 100644
      --- a/Source/CParse/cscanner.c
      +++ b/Source/CParse/cscanner.c
      @@ -37,6 +37,9 @@ int     cparse_start_line = 0;
       /* C++ mode */
       int cparse_cplusplus = 0;
       
      +/* Generate C++ compatible code when wrapping C code */
      +int cparse_cplusplusout = 0;
      +
       /* Private vars */
       static int scan_init = 0;
       static int num_brace = 0;
      @@ -52,6 +55,14 @@ void Swig_cparse_cplusplus(int v) {
         cparse_cplusplus = v;
       }
       
      +/* -----------------------------------------------------------------------------
      + * Swig_cparse_cplusplusout()
      + * ----------------------------------------------------------------------------- */
      +
      +void Swig_cparse_cplusplusout(int v) {
      +  cparse_cplusplusout = v;
      +}
      +
       /* ----------------------------------------------------------------------------
        * scanner_init()
        *
      diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
      index 8e34833e2..9b1cec387 100644
      --- a/Source/CParse/parser.y
      +++ b/Source/CParse/parser.y
      @@ -59,7 +59,6 @@ static int      extendmode   = 0;
       static int      compact_default_args = 0;
       static int      template_reduce = 0;
       static int      cparse_externc = 0;
      -extern int CPlusPlusOut;
       
       /* -----------------------------------------------------------------------------
        *                            Assist Functions
      @@ -3446,7 +3445,7 @@ cpp_class_decl  : storage_class cpptype idcolon inherit LBRACE {
       		   Delete(prefix);
       		   inclass = 1;
       		   currentOuterClass = $$;
      -		   if (CPlusPlusOut) {
      +		   if (cparse_cplusplusout) {
       		     /* save the structure declaration to declare it in global scope for C++ to see */
       		     code = get_raw_text_balanced('{', '}');
       		     Setattr($$, "code", code);
      @@ -3577,7 +3576,7 @@ cpp_class_decl  : storage_class cpptype idcolon inherit LBRACE {
       		       Namespaceprefix = Swig_symbol_qualifiedscopename(0);
       		       yyrename = Copy(Getattr($$, "class_rename"));
       		       add_symbols($$);
      -		       if (!CPlusPlusOut)
      +		       if (!cparse_cplusplusout)
       			 Delattr($$, "nested:outer");
       		       Delattr($$, "class_rename");
       		       $$ = 0;
      diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx
      index aa7e83ef8..f3aff2349 100644
      --- a/Source/Modules/main.cxx
      +++ b/Source/Modules/main.cxx
      @@ -29,10 +29,6 @@
       
       static Language *lang = 0;	// Language method
       int CPlusPlus = 0;
      -extern "C"
      -{
      -  int CPlusPlusOut = 0;		// Generate C++ compatible code when wrapping C code
      -}
       int Extend = 0;			// Extend flag
       int ForceExtern = 0;		// Force extern mode
       int GenerateDefault = 1;	// Generate default constructors
      @@ -488,7 +484,8 @@ void SWIG_getoptions(int argc, char *argv[]) {
       	Swig_cparse_cplusplus(1);
       	Swig_mark_arg(i);
             } else if (strcmp(argv[i], "-c++out") == 0) {
      -	CPlusPlusOut = 1;
      +	// Undocumented
      +	Swig_cparse_cplusplusout(1);
       	Swig_mark_arg(i);
             } else if (strcmp(argv[i], "-fcompact") == 0) {
       	Wrapper_compact_print_mode_set(1);
      @@ -955,6 +952,11 @@ int SWIG_main(int argc, char *argv[], Language *l) {
         // Don't check for an input file if -external-runtime is passed
         Swig_check_options(external_runtime ? 0 : 1);
       
      +  if (CPlusPlus && cparse_cplusplusout) {
      +    Printf(stderr, "The -c++out option is for C input but C++ input has been requested via -c++\n");
      +    SWIG_exit(EXIT_FAILURE);
      +  }
      +
         install_opts(argc, argv);
       
         // Add language dependent directory to the search path
      diff --git a/Source/Modules/nested.cxx b/Source/Modules/nested.cxx
      index ff563b3ba..a62a9e9da 100644
      --- a/Source/Modules/nested.cxx
      +++ b/Source/Modules/nested.cxx
      @@ -400,7 +400,7 @@ void Swig_nested_name_unnamed_c_structs(Node *n) {
       	c = next;
       	continue;
             }
      -    } else if (CPlusPlusOut) {
      +    } else if (cparse_cplusplusout) {
             if (Getattr(c, "nested:outer")) {
       	Node *ins = create_insert(c, true);
       	insertNodeAfter(c, ins);
      diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx
      index 1c0192d07..14118972d 100644
      --- a/Source/Modules/octave.cxx
      +++ b/Source/Modules/octave.cxx
      @@ -12,6 +12,7 @@
        * ----------------------------------------------------------------------------- */
       
       #include "swigmod.h"
      +#include "cparse.h"
       
       static String *global_name = 0;
       static String *op_prefix   = 0;
      @@ -86,7 +87,6 @@ public:
            director_multiple_inheritance = 1;
            director_language = 1;
            docs = NewHash();
      -     CPlusPlusOut = 1;
          }
       
         virtual void main(int argc, char *argv[]) {
      @@ -133,6 +133,10 @@ public:
           SWIG_config_file("octave.swg");
           SWIG_typemap_lang("octave");
           allow_overloading();
      +
      +    // Octave API is C++, so output must be C++ compatibile even when wrapping C code
      +    if (!cparse_cplusplus)
      +      Swig_cparse_cplusplusout(1);
         }
       
         virtual int top(Node *n) {
      diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h
      index 41ef44e41..9e76b4d10 100644
      --- a/Source/Modules/swigmod.h
      +++ b/Source/Modules/swigmod.h
      @@ -32,7 +32,6 @@ extern String *input_file;
       extern int line_number;
       extern int start_line;
       extern int CPlusPlus;		// C++ mode
      -extern "C" int CPlusPlusOut;	// generate C++ declarations for C code (currently used for Octave)
       extern int Extend;		// Extend mode
       extern int Verbose;
       extern int IsVirtual;
      diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c
      index 03020bb72..04845f3cf 100644
      --- a/Source/Swig/cwrap.c
      +++ b/Source/Swig/cwrap.c
      @@ -13,9 +13,8 @@
        * ----------------------------------------------------------------------------- */
       
       #include "swig.h"
      +#include "cparse.h"
       
      -extern int cparse_cplusplus;
      -extern int CPlusPlusOut;
       static const char *cresult_variable_name = "result";
       
       static Parm *nonvoid_parms(Parm *p) {
      @@ -777,7 +776,7 @@ String *Swig_cmemberset_call(const_String_or_char_ptr name, SwigType *type, Stri
           if (!Strstr(type, "enum $unnamed")) {
             String *dref = Swig_wrapped_var_deref(type, pname1, varcref);
             int extra_cast = 0;
      -      if (CPlusPlusOut) {
      +      if (cparse_cplusplusout) {
       	/* Required for C nested structs compiled as C++ as a duplicate of the nested struct is put into the global namespace.
       	 * We could improve this by adding the extra casts just for nested structs rather than all structs. */
       	String *base = SwigType_base(type);
      
      From c256dd140b8a1de1262a57981639d1c56fa93b6f Mon Sep 17 00:00:00 2001
      From: William S Fulton 
      Date: Thu, 12 Dec 2013 20:58:10 +0000
      Subject: [PATCH 0818/1160] Add check-c and check-cpp targets for running just
       C and C++ test cases
      
      ---
       Examples/test-suite/common.mk | 4 ++++
       1 file changed, 4 insertions(+)
      
      diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
      index e9caaedab..c65fd7901 100644
      --- a/Examples/test-suite/common.mk
      +++ b/Examples/test-suite/common.mk
      @@ -638,6 +638,10 @@ all:	$(NOT_BROKEN_TEST_CASES) $(BROKEN_TEST_CASES)
       
       check: 	$(NOT_BROKEN_TEST_CASES)
       
      +check-c: $(C_TEST_CASES:=.ctest)
      +
      +check-cpp: $(CPP_TEST_CASES:=.cpptest)
      +
       check-cpp11: $(CPP11_TEST_CASES:=.cpptest)
       
       # partialcheck target runs SWIG only, ie no compilation or running of tests (for a subset of languages)
      
      From fb103f8db46477e6d0285f83449b73c2a2c75810 Mon Sep 17 00:00:00 2001
      From: William S Fulton 
      Date: Thu, 12 Dec 2013 21:23:49 +0000
      Subject: [PATCH 0819/1160] Minor expansion of nested C structs testing
      
      ---
       Examples/test-suite/nested_structs.i | 6 ++++--
       1 file changed, 4 insertions(+), 2 deletions(-)
      
      diff --git a/Examples/test-suite/nested_structs.i b/Examples/test-suite/nested_structs.i
      index 60e34a638..c15623085 100644
      --- a/Examples/test-suite/nested_structs.i
      +++ b/Examples/test-suite/nested_structs.i
      @@ -5,10 +5,10 @@
       struct Outer {
         struct {
           int val;
      -  } inner1, inner2, *inner3, inner4[1];
      +  } inner1, inner2, *inner3, inner4[1], **inner5;
         struct Named {
           int val;
      -  } inside1, inside2, *inside3, inside4[1];
      +  } inside1, inside2, *inside3, inside4[1], **inside5;
       } outer;
       
       void setValues(struct Outer *outer, int val) {
      @@ -16,12 +16,14 @@ void setValues(struct Outer *outer, int val) {
         outer->inner2.val = val * 2;
         outer->inner3 = &outer->inner2;
         outer->inner4[0].val = val * 4;
      +  outer->inner5 = &outer->inner3;
       
         val = val * 10;
         outer->inside1.val = val;
         outer->inside2.val = val * 2;
         outer->inside3 = &outer->inside2;
         outer->inside4[0].val = val * 4;
      +  outer->inside5 = &outer->inside3;
       }
       %}
       
      
      From 0f4ceaf5923fd9a30eb9201048cd285a9bba8084 Mon Sep 17 00:00:00 2001
      From: William S Fulton 
      Date: Fri, 13 Dec 2013 08:11:17 +0000
      Subject: [PATCH 0820/1160] Deprecation of the 'nestedworkaround' feature
      
      Also add in macros for the flatnested feature which can be used in place
      of the nestedworkaround feature
      ---
       Doc/Manual/SWIGPlus.html  | 26 +++++++++++++++++++++-----
       Doc/Manual/Warnings.html  |  1 +
       Lib/swig.swg              |  9 +++++++--
       Source/CParse/parser.y    |  4 ++++
       Source/Include/swigwarn.h |  1 +
       5 files changed, 34 insertions(+), 7 deletions(-)
      
      diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html
      index 2ec98f33a..20c03cc71 100644
      --- a/Doc/Manual/SWIGPlus.html
      +++ b/Doc/Manual/SWIGPlus.html
      @@ -4992,11 +4992,27 @@ class Bar {
       
       

      Compatibility Note: -In SWIG 2.0 and earlier, nested classes were treated as opaque pointers. -Also there was a workaround, implementing approximately the same behaviour as the -%feature ("flatnested") with an additional help from the user: -nested class had to be manually redeclared in the global scope, typedef name and %feature nestedworkaround -added for the inner class. +Prior to SWIG-3.0.0, there was limited nested class support. Nested classes were treated as opaque pointers. +However, there was a workaround for nested class support in these older versions requiring the user to replicate +the nested class in the global scope, adding in a typedef for the nested class in the global scope and +using the "nestedworkaround" feature on the nested class. This resulted in approximately the +same behaviour as the "flatnested" feature. With proper nested class support now available in SWIG-3.0.0, this +feature has been deprecated and no longer works requiring code changes. If you see the following warning: +

      + +
      +
      +example.i:8: Warning 126: The nestedworkaround feature is deprecated
      +
      +
      + +

      +consider using the "flatnested" feature discussed above which generates a non-nested proxy class, like the +"nestedworkaround" feature did. Alternatively, use the default nested class code generation, which may generate an +equivalent to a nested proxy class in the target language, depending on the target language support. +

      + +

      SWIG-1.3.40 and earlier versions did not have the nestedworkaround feature and the generated code resulting from parsing nested classes did not always compile. Nested class warnings could also not be suppressed using %warnfilter. diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index e0debe41c..b4d27872c 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -382,6 +382,7 @@ example.i(4) : Syntax error in input.

    • 119. Deprecated %typemap(ignore).
    • 120. Deprecated command line option (-runtime, -noruntime).
    • 121. Deprecated %name directive. +
    • 126. The 'nestedworkaround' feature is deprecated.

    14.9.2 Preprocessor (200-299)

    diff --git a/Lib/swig.swg b/Lib/swig.swg index a63169b3e..33e920c82 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -9,7 +9,7 @@ * User Directives * ----------------------------------------------------------------------------- */ -/* Deprecated SWIG directives */ +/* Deprecated SWIG-1.1 directives */ #define %disabledoc %warn "104:%disabledoc is deprecated" #define %enabledoc %warn "105:%enabledoc is deprecated" @@ -136,11 +136,16 @@ #define %nocallback %feature("callback","0") #define %clearcallback %feature("callback","") -/* the %nestedworkaround directive */ +/* the %nestedworkaround directive (deprecated) */ #define %nestedworkaround %feature("nestedworkaround") #define %nonestedworkaround %feature("nestedworkaround","0") #define %clearnestedworkaround %feature("nestedworkaround","") +/* the %flatnested directive */ +#define %flatnested %feature("flatnested") +#define %noflatnested %feature("flatnested","0") +#define %clearflatnested %feature("flatnested","") + /* the %fastdispatch directive */ #define %fastdispatch %feature("fastdispatch") #define %nofastdispatch %feature("fastdispatch","0") diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 9b1cec387..93ee9e3e1 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1080,6 +1080,10 @@ static void single_new_feature(const char *featurename, String *val, Hash *featu /* Printf(stdout, "single_new_feature: [%s] [%s] [%s] [%s] [%s] [%s]\n", featurename, val, declaratorid, t, ParmList_str_defaultargs(declaratorparms), qualifier); */ + /* Warn about deprecated features */ + if (strcmp(featurename, "nestedworkaround") == 0) + Swig_warning(WARN_DEPRECATED_NESTED_WORKAROUND, cparse_file, cparse_line, "The 'nestedworkaround' feature is deprecated.\n"); + fname = NewStringf("feature:%s",featurename); if (declaratorid) { fixname = feature_identifier_fix(declaratorid); diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index 7b535f748..ea1cf7fe4 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -52,6 +52,7 @@ #define WARN_DEPRECATED_NODEFAULT 123 #define WARN_DEPRECATED_TYPEMAP_LANG 124 #define WARN_DEPRECATED_INPUT_FILE 125 +#define WARN_DEPRECATED_NESTED_WORKAROUND 126 /* -- Preprocessor -- */ From 4cf5de797f15fa0c2a500cea12db7c9223f07fdc Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 13 Dec 2013 11:56:31 -0800 Subject: [PATCH 0821/1160] Add comment with SWIG file name in files generated for Go. --- CHANGES.current | 4 ++++ Source/Modules/go.cxx | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 3df92ef33..f64d8f55a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-12-13: iant + [Go] Add SWIG source file name as comments in generated + files. This can be used by Go documentation tools. + 2013-12-12: jleveque [Lua] Fix typo (wchar instead of wchar_t) which made wchar.i for Lua useless. diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 52e2459b7..e5398ba7a 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -281,6 +281,7 @@ private: // Get filenames. + String *swig_filename = Getattr(n, "infile"); String *c_filename = Getattr(n, "outfile"); String *c_filename_h = Getattr(n, "outfile_h"); @@ -360,6 +361,11 @@ private: } Swig_banner(f_c_begin); + if (CPlusPlus) { + Printf(f_c_begin, "\n// source: %s\n\n", swig_filename); + } else { + Printf(f_c_begin, "\n/* source: %s */\n\n", swig_filename); + } Printf(f_c_runtime, "#define SWIGMODULE %s\n", module); @@ -367,6 +373,8 @@ private: Printf(f_c_runtime, "#define SWIG_DIRECTORS\n"); Swig_banner(f_c_directors_h); + Printf(f_c_directors_h, "\n// source: %s\n\n", swig_filename); + 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); @@ -377,9 +385,11 @@ private: } Swig_banner(f_go_begin); + Printf(f_go_begin, "\n// source: %s\n", swig_filename); if (!gccgo_flag) { Swig_banner(f_gc_begin); + Printf(f_gc_begin, "\n/* source: %s */\n\n", swig_filename); Printf(f_gc_begin, "\n/* This file should be compiled with 6c/8c. */\n"); Printf(f_gc_begin, "#pragma dynimport _ _ \"%s\"\n", soname); } From 66ebb2a7cb0b9f001a399ff7a4066dac0659f472 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 14 Dec 2013 15:13:59 +0000 Subject: [PATCH 0822/1160] Remove nested branch from Travis builds --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7f868ae91..70cbb2f27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,4 +57,3 @@ script: branches: only: - master - - nested From a1c17d585dfa831141b2c23e75f61cf232bf0d03 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 14 Dec 2013 22:35:02 +0000 Subject: [PATCH 0823/1160] Fix R unions seg fault Started seg faulting since nested branch merge --- Source/Modules/r.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 8b3bc20bb..c3860a161 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -2299,7 +2299,7 @@ int R::classDeclaration(Node *n) { /* If we have a typedef union { ... } U, then we never get to see the typedef via a regular call to typedefHandler. Instead, */ - if(Getattr(n, "unnamed") && Strcmp(Getattr(n, "storage"), "typedef") == 0 + if(Getattr(n, "unnamed") && Getattr(n, "storage") && Strcmp(Getattr(n, "storage"), "typedef") == 0 && Getattr(n, "tdname") && Strcmp(Getattr(n, "tdname"), name) == 0) { if (debugMode) Printf(stdout, "Typedef in the class declaration for %s\n", name); From 0cf116128bd784bf9307c857b50405b4e5ee2efb Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Fri, 13 Dec 2013 16:32:13 +0100 Subject: [PATCH 0824/1160] Skip unsigned (long) long integer tests on OS X with guile 1.8 --- Examples/test-suite/schemerunme/integers.scm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/schemerunme/integers.scm b/Examples/test-suite/schemerunme/integers.scm index 903e6a9f1..7c03c3dd8 100644 --- a/Examples/test-suite/schemerunme/integers.scm +++ b/Examples/test-suite/schemerunme/integers.scm @@ -34,10 +34,16 @@ (check-range signed-int-identity signed-int-min signed-int-max) (check-range unsigned-int-identity 0 unsigned-int-max) (check-range signed-long-identity signed-long-min signed-long-max) - (check-range unsigned-long-identity 0 unsigned-long-max) - ;;; long long not implemented in Guile and MzScheme. (check-range signed-long-long-identity signed-long-long-min signed-long-long-max) - (check-range unsigned-long-long-identity 0 unsigned-long-long-max) + + ;;; unsigned (long) long is broken in guile 1.8 on Mac OS X, skip test + (if (or (>= (string->number (major-version)) 2) + (not (equal? (utsname:sysname (uname)) "Darwin"))) + (begin + (check-range unsigned-long-identity 0 unsigned-long-max) + (check-range unsigned-long-long-identity 0 unsigned-long-long-max)) + ) + ) (exit 0) From 865408874f3b6a392fe5fda7d5102deeb53ade06 Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Mon, 16 Dec 2013 11:43:28 +0400 Subject: [PATCH 0825/1160] fixed %template declared within class, next to template declaration added a few tests for C# nested classes support --- .../test-suite/csharp/nested_class_runme.cs | 66 +++++++++++++++++++ .../test-suite/csharp/nested_structs_runme.cs | 28 ++++++++ .../csharp/nested_workaround_runme.cs | 23 +++++++ .../csharp/template_nested_runme.cs | 25 +++++++ .../test-suite/java/derived_nested_runme.java | 22 +++++++ Source/CParse/parser.y | 9 ++- 6 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/csharp/nested_class_runme.cs create mode 100644 Examples/test-suite/csharp/nested_structs_runme.cs create mode 100644 Examples/test-suite/csharp/nested_workaround_runme.cs create mode 100644 Examples/test-suite/csharp/template_nested_runme.cs create mode 100644 Examples/test-suite/java/derived_nested_runme.java diff --git a/Examples/test-suite/csharp/nested_class_runme.cs b/Examples/test-suite/csharp/nested_class_runme.cs new file mode 100644 index 000000000..c94537bbf --- /dev/null +++ b/Examples/test-suite/csharp/nested_class_runme.cs @@ -0,0 +1,66 @@ +using System; +using nested_classNamespace; +#pragma warning disable 219 + +public class runme { + static void Main() { + + Outer outer = new Outer(); + outer.a = 1; + outer.b = 2; + Outer.InnerStruct1 is1 = outer.makeInnerStruct1(); + Outer.InnerClass1 ic1 = outer.makeInnerClass1(); + Outer.InnerUnion1 iu1 = outer.makeInnerUnion1(); + + Outer.InnerStruct2 is2 = outer.makeInnerStruct2(); + Outer.InnerClass2 ic2 = outer.makeInnerClass2(); + Outer.InnerUnion2 iu2 = outer.makeInnerUnion2(); + + Outer.InnerClass4Typedef ic4 = outer.makeInnerClass4Typedef(); + Outer.InnerStruct4Typedef is4 = outer.makeInnerStruct4Typedef(); + Outer.InnerUnion4Typedef iu4 = outer.makeInnerUnion4Typedef(); + + Outer.InnerClass5Typedef ic5 = outer.makeInnerClass5(); + Outer.InnerStruct5Typedef is5 = outer.makeInnerStruct5(); + Outer.InnerUnion5Typedef iu5 = outer.makeInnerUnion5(); + + ic5 = outer.makeInnerClass5Typedef(); + is5 = outer.makeInnerStruct5Typedef(); + iu5 = outer.makeInnerUnion5Typedef(); + + { + Outer.InnerMultiple im1 = outer.MultipleInstance1; + Outer.InnerMultiple im2 = outer.MultipleInstance2; + Outer.InnerMultiple im3 = outer.MultipleInstance3; + Outer.InnerMultiple im4 = outer.MultipleInstance4; + } + + { + Outer.InnerMultipleDerived im1 = outer.MultipleDerivedInstance1; + Outer.InnerMultipleDerived im2 = outer.MultipleDerivedInstance2; + Outer.InnerMultipleDerived im3 = outer.MultipleDerivedInstance3; + Outer.InnerMultipleDerived im4 = outer.MultipleDerivedInstance4; + } + + { + Outer.InnerMultipleDerived im1 = outer.MultipleDerivedInstance1; + Outer.InnerMultipleDerived im2 = outer.MultipleDerivedInstance2; + Outer.InnerMultipleDerived im3 = outer.MultipleDerivedInstance3; + Outer.InnerMultipleDerived im4 = outer.MultipleDerivedInstance4; + } + + { + Outer.InnerMultipleAnonTypedef1 mat1 = outer.makeInnerMultipleAnonTypedef1(); + Outer.InnerMultipleAnonTypedef1 mat2 = outer.makeInnerMultipleAnonTypedef2(); + SWIGTYPE_p_p_Outer__InnerMultipleAnonTypedef1 mat3 = outer.makeInnerMultipleAnonTypedef3(); + + Outer.InnerMultipleNamedTypedef1 mnt = outer.makeInnerMultipleNamedTypedef(); + Outer.InnerMultipleNamedTypedef1 mnt1 = outer.makeInnerMultipleNamedTypedef1(); + Outer.InnerMultipleNamedTypedef1 mnt2 = outer.makeInnerMultipleNamedTypedef2(); + SWIGTYPE_p_p_Outer__InnerMultipleNamedTypedef mnt3 = outer.makeInnerMultipleNamedTypedef3(); + } + { + Outer.InnerSameName isn = outer.makeInnerSameName(); + } + } +} diff --git a/Examples/test-suite/csharp/nested_structs_runme.cs b/Examples/test-suite/csharp/nested_structs_runme.cs new file mode 100644 index 000000000..ffe2cb71b --- /dev/null +++ b/Examples/test-suite/csharp/nested_structs_runme.cs @@ -0,0 +1,28 @@ +using System; +using nested_structsNamespace; +#pragma warning disable 219 + +public class runme { + static void Main() { + Outer outer = new Outer(); + nested_structs.setValues(outer, 10); + + Outer_inner1 inner1 = outer.inner1; + Outer_inner1 inner2 = outer.inner2; + Outer_inner1 inner3 = outer.inner3; + Outer_inner1 inner4 = outer.inner4; + if (inner1.val != 10) throw new Exception("failed inner1"); + if (inner2.val != 20) throw new Exception("failed inner2"); + if (inner3.val != 20) throw new Exception("failed inner3"); + if (inner4.val != 40) throw new Exception("failed inner4"); + + Named inside1 = outer.inside1; + Named inside2 = outer.inside2; + Named inside3 = outer.inside3; + Named inside4 = outer.inside4; + if (inside1.val != 100) throw new Exception("failed inside1"); + if (inside2.val != 200) throw new Exception("failed inside2"); + if (inside3.val != 200) throw new Exception("failed inside3"); + if (inside4.val != 400) throw new Exception("failed inside4"); + } +} diff --git a/Examples/test-suite/csharp/nested_workaround_runme.cs b/Examples/test-suite/csharp/nested_workaround_runme.cs new file mode 100644 index 000000000..12d474bd7 --- /dev/null +++ b/Examples/test-suite/csharp/nested_workaround_runme.cs @@ -0,0 +1,23 @@ +using System; +using nested_workaroundNamespace; +#pragma warning disable 219 + +public class runme { + static void Main() { + { + Inner inner = new Inner(5); + Outer outer = new Outer(); + Inner newInner = outer.doubleInnerValue(inner); + if (newInner.getValue() != 10) + throw new Exception("inner failed"); + } + + { + Outer outer = new Outer(); + Inner inner = outer.createInner(3); + Inner newInner = outer.doubleInnerValue(inner); + if (outer.getInnerValue(newInner) != 6) + throw new Exception("inner failed"); + } + } +} diff --git a/Examples/test-suite/csharp/template_nested_runme.cs b/Examples/test-suite/csharp/template_nested_runme.cs new file mode 100644 index 000000000..edf4b76cf --- /dev/null +++ b/Examples/test-suite/csharp/template_nested_runme.cs @@ -0,0 +1,25 @@ +using System; +using template_nestedNamespace; +#pragma warning disable 219 + +public class runme { + static void Main() { + new T_NormalTemplateNormalClass().tmethod(new NormalClass()); + new OuterClass().T_OuterTMethodNormalClass(new NormalClass()); + + TemplateFuncs tf = new TemplateFuncs(); + if (tf.T_TemplateFuncs1Int(-10) != -10) + throw new Exception("it failed"); + if (tf.T_TemplateFuncs2Double(-12.3) != -12.3) + throw new Exception("it failed"); + + T_NestedOuterTemplateDouble tn = new T_NestedOuterTemplateDouble(); + if (tn.hohum(-12.3) != -12.3) + throw new Exception("it failed"); + OuterClass.T_OuterClassInner1Int inner1 = new OuterClass().useInner1(new OuterClass.T_OuterClassInner1Int()); + OuterClass.T_OuterClassInner2NormalClass inner2 = new OuterClass.T_OuterClassInner2NormalClass(); + inner2.embeddedVar = 2; + OuterClass.T_OuterClassInner2NormalClass inner22 = new OuterClass().useInner2Again(inner2); + } +} + diff --git a/Examples/test-suite/java/derived_nested_runme.java b/Examples/test-suite/java/derived_nested_runme.java new file mode 100644 index 000000000..1a9c62416 --- /dev/null +++ b/Examples/test-suite/java/derived_nested_runme.java @@ -0,0 +1,22 @@ + +import derived_nested.*; + +public class derived_nested_runme { + + static { + try { + System.loadLibrary("derived_nested"); + } 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[]) { + BB outer = new BB(); + BB.DD d = new BB.DD(); + BB.EE e = new BB.EE(); + outer.getFf_instance().setZ(outer.getFf_instance().getX()); + outer.useEE(e); + } +} \ No newline at end of file diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 203284402..d2fa06f72 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -146,6 +146,10 @@ static Node *copy_node(Node *n) { Delete(pl); continue; } + if (strcmp(ckey,"nested:outer") == 0) { /* don't copy outer classes links, they will be updated later */ + Setattr(nn, key, k.item); + continue; + } /* Looks okay. Just copy the data using Copy */ ci = Copy(k.item); Setattr(nn, key, ci); @@ -2662,7 +2666,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va } templnode = copy_node(nn); - update_nested_classes(templnode); + update_nested_classes(templnode); /* update classes nested withing template */ /* We need to set the node name based on name used to instantiate */ Setattr(templnode,"name",tname); Delete(tname); @@ -2698,7 +2702,10 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va Delete(temparms); if (currentOuterClass) { SetFlag(templnode, "nested"); + Setattr(templnode, "nested:outer", currentOuterClass); } + else + Delattr(templnode, "nested:outer"); add_symbols_copy(templnode); From 5487345ce7ff484f9313e1ae6e65d754c47f1efa Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Mon, 16 Dec 2013 13:08:34 +0400 Subject: [PATCH 0826/1160] properly disabled nested %template declared in other scopes --- Source/CParse/parser.y | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index d2fa06f72..ef5aa6ef4 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2675,7 +2675,8 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va } else { Setattr(templnode,"sym:typename","1"); } - if ($3) { + /* for now, nested %template is allowed only in the same scope as the template declaration */ + if ($3 && !(currentOuterClass && (currentOuterClass != Getattr(nn, "nested:outer")))) { /* Comment this out for 1.3.28. We need to re-enable it later but first we need to @@ -2694,6 +2695,9 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va Setattr(templnode,"sym:name",nname); Delete(nname); Setattr(templnode,"feature:onlychildren", "typemap,typemapitem,typemapcopy,typedef,types,fragment"); + if ($3) { + Swig_warning(WARN_PARSE_NESTED_TEMPLATE, cparse_file, cparse_line, "Named nested template instantiations not supported. Processing as if no name was given to %%template().\n"); + } } Delattr(templnode,"templatetype"); Setattr(templnode,"template",nn); @@ -2704,9 +2708,6 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va SetFlag(templnode, "nested"); Setattr(templnode, "nested:outer", currentOuterClass); } - else - Delattr(templnode, "nested:outer"); - add_symbols_copy(templnode); if (Strcmp(nodeType(templnode),"class") == 0) { From 39bf2efdc980f800219cb488c24eef3ef6be5c5c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 16 Dec 2013 19:28:11 +0000 Subject: [PATCH 0827/1160] Revert template_nested_typemaps to what it was before nested merge The breaks were fixed in the last couple of commits --- Examples/test-suite/template_nested_typemaps.i | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Examples/test-suite/template_nested_typemaps.i b/Examples/test-suite/template_nested_typemaps.i index b40e7e291..54f5bc503 100644 --- a/Examples/test-suite/template_nested_typemaps.i +++ b/Examples/test-suite/template_nested_typemaps.i @@ -4,22 +4,18 @@ // Testing that the typemaps invoked within a class via %template are picked up by appropriate methods -%inline %{ template struct Typemap { -#ifdef SWIG %typemap(in) T { $1 = -99; } -#endif }; template <> struct Typemap { // Note explicit specialization -#ifdef SWIG %typemap(in) short { $1 = -77; } -#endif }; +%inline %{ int globalInt1(int s) { return s; } short globalShort1(short s) { return s; } From 1dca0af0241475c11a842e4dd4c16ff7b367a962 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 16 Dec 2013 19:50:17 -0800 Subject: [PATCH 0828/1160] Update for Go 1.2 release. Add support for linking SWIG code directly into executable, rather than using a shared library. --- CHANGES.current | 5 + Doc/Manual/Go.html | 67 ++- Examples/Makefile.in | 60 ++- Examples/go/callback/Makefile | 4 +- .../go/callback/{example.cxx => callback.cxx} | 0 Examples/go/class/Makefile | 4 +- Examples/go/class/{example.cxx => class.cxx} | 0 Examples/go/constants/Makefile | 2 +- Examples/go/enum/Makefile | 4 +- Examples/go/enum/{example.cxx => enum.cxx} | 0 Examples/go/extend/Makefile | 4 +- .../go/extend/{example.cxx => extend.cxx} | 0 Examples/go/funcptr/Makefile | 4 +- Examples/go/funcptr/{example.c => funcptr.c} | 0 Examples/go/multimap/Makefile | 4 +- .../go/multimap/{example.c => multimap.c} | 0 Examples/go/pointer/Makefile | 4 +- Examples/go/pointer/{example.c => pointer.c} | 0 Examples/go/reference/Makefile | 4 +- .../reference/{example.cxx => reference.cxx} | 0 Examples/go/simple/Makefile | 4 +- Examples/go/simple/{example.c => simple.c} | 0 Examples/go/template/Makefile | 2 +- Examples/go/variables/Makefile | 4 +- .../go/variables/{example.c => variables.c} | 0 Examples/test-suite/go/Makefile.in | 24 +- .../test-suite/go/director_abstract_runme.go | 62 --- .../test-suite/go/director_thread_runme.go | 28 -- .../go/template_typedef_import_runme.go | 29 -- Lib/go/cdata.i | 6 +- Source/Modules/go.cxx | 418 +++++++++--------- configure.ac | 13 + 32 files changed, 385 insertions(+), 371 deletions(-) rename Examples/go/callback/{example.cxx => callback.cxx} (100%) rename Examples/go/class/{example.cxx => class.cxx} (100%) rename Examples/go/enum/{example.cxx => enum.cxx} (100%) rename Examples/go/extend/{example.cxx => extend.cxx} (100%) rename Examples/go/funcptr/{example.c => funcptr.c} (100%) rename Examples/go/multimap/{example.c => multimap.c} (100%) rename Examples/go/pointer/{example.c => pointer.c} (100%) rename Examples/go/reference/{example.cxx => reference.cxx} (100%) rename Examples/go/simple/{example.c => simple.c} (100%) rename Examples/go/variables/{example.c => variables.c} (100%) delete mode 100644 Examples/test-suite/go/director_abstract_runme.go delete mode 100644 Examples/test-suite/go/director_thread_runme.go delete mode 100644 Examples/test-suite/go/template_typedef_import_runme.go diff --git a/CHANGES.current b/CHANGES.current index f64d8f55a..21c97407d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-12-16: iant + [Go] Update for Go 1.2 release. Add support for linking + SWIG code directly into executable, rather than using a + shared library. + 2013-12-13: iant [Go] Add SWIG source file name as comments in generated files. This can be used by Go documentation tools. diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 7a55a4364..3482d34dc 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -55,7 +55,7 @@ there is no convenient way to call C++ code. SWIG fills this gap.

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

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

    @@ -108,7 +108,7 @@ swig -go -help
  • + the gc compiler. @@ -117,13 +117,21 @@ swig -go -help package name is the SWIG module name. + + + + + + the gc compiler; when using gccgo, the equivalent name will be taken from + the -soname option passed to the linker. Using this + option implies the -use-shlib option. @@ -165,25 +173,56 @@ may be helpful to include it in your code, compiled with the usual C or C++ compiler.
  • If using the gc compiler, MODULE_gc.c will contain C code which should -be compiled with the C compiler distributed as part of the gc compiler: 6c, 8c, -or 5c. It should then be combined with the compiled MODULE.go using -gopack. This file will not be generated when using gccgo. +be compiled with the C compiler distributed as part of the gc +compiler. It should then be combined with the compiled MODULE.go +using gopack. This file will not be generated when using gccgo.

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

    + +

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

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

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

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

    22.3 A tour of basic C/C++ wrapping

    diff --git a/Examples/Makefile.in b/Examples/Makefile.in index b986774b6..0169f26a7 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1555,6 +1555,7 @@ r_clean: GO = @GO@ GOGCC = @GOGCC@ GO1 = @GO1@ +GO12 = @GO12@ GOC = @GOC@ GOOPT = @GOOPT@ GOVERSIONOPTION = @GOVERSIONOPTION@ @@ -1576,41 +1577,76 @@ GOGCOBJS = $(GOSRCS:.go=.$(GOOBJEXT)) GOGCCOBJS = $(GOSRCS:.go=.@OBJEXT@) # ---------------------------------------------------------------- -# Build a Go dynamically loadable module (C) +# Build a Go module (C) # ---------------------------------------------------------------- go: $(SRCS) $(SWIG) -go $(GOOPT) $(GOSWIGARG) $(SWIGOPT) $(INTERFACEPATH) - $(CC) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + if $(GO12) || $(GOGCC); then \ + $(CC) -g -c $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES); \ + else \ + $(CC) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES); \ + $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO); \ + fi $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(GOSRCS) if ! $(GOGCC) ; then \ - $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT}/pkg/$${GOOS}_$${GOARCH} $(GOCSRCS) && \ - $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ + $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT}/pkg/$${GOOS}_$${GOARCH} $(GOCSRCS); \ + rm -f $(GOPACKAGE); \ + if $(GO12); then \ + $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \ + else \ + $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ + fi; \ fi # ---------------------------------------------------------------- -# Build a Go dynamically loadable module (C++) +# Build a Go module (C++) # ---------------------------------------------------------------- go_cpp: $(SRCS) $(SWIG) -go -c++ $(GOOPT) $(GOSWIGARG) $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -g -c $(CCSHARED) $(CXXFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) - $(CXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + if $(GO12) || $(GOGCC); then \ + $(CXX) -g -c $(CXXFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES); \ + else \ + $(CXX) -g -c $(CCSHARED) $(CXXFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES); \ + $(CXXSHARED) $(CXXFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO); \ + fi $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(GOSRCS) if ! $(GOGCC) ; then \ - $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT}/pkg/$${GOOS}_$${GOARCH} $(GOCSRCS) && \ - $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ + $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT}/pkg/$${GOOS}_$${GOARCH} $(GOCSRCS); \ + rm -f $(GOPACKAGE); \ + if $(GO12); then \ + $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \ + else \ + $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ + fi; \ fi # ----------------------------------------------------------------- -# Running a Go example +# Running a Go example (C) # ----------------------------------------------------------------- go_run: runme.go $(GO) $(GOCOMPILEARG) runme.go if $(GOGCC) ; then \ - $(COMPILETOOL) $(GO) -o runme runme.@OBJEXT@ $(GOGCCOBJS) $(LIBPREFIX)$(TARGET)$(SO); \ + $(COMPILETOOL) $(GO) -o runme runme.@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS); \ + elif $(GO12); then \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CC) -extldflags "$(CFLAGS)" -o runme runme.$(GOOBJEXT); \ + else \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o runme runme.$(GOOBJEXT); \ + fi + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme $(RUNPIPE) + +# ----------------------------------------------------------------- +# Running a Go example (C++) +# ----------------------------------------------------------------- + +go_run_cpp: runme.go + $(GO) $(GOCOMPILEARG) runme.go + if $(GOGCC) ; then \ + $(COMPILETOOL) $(GO) -o runme runme.@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS) -lstdc++; \ + elif $(GO12); then \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o runme runme.$(GOOBJEXT); \ else \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o runme runme.$(GOOBJEXT); \ fi diff --git a/Examples/go/callback/Makefile b/Examples/go/callback/Makefile index 7489f87dc..4516d2674 100644 --- a/Examples/go/callback/Makefile +++ b/Examples/go/callback/Makefile @@ -1,12 +1,12 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx +CXXSRCS = callback.cxx TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run_cpp build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/callback/example.cxx b/Examples/go/callback/callback.cxx similarity index 100% rename from Examples/go/callback/example.cxx rename to Examples/go/callback/callback.cxx diff --git a/Examples/go/class/Makefile b/Examples/go/class/Makefile index a099654f1..66b2df325 100644 --- a/Examples/go/class/Makefile +++ b/Examples/go/class/Makefile @@ -1,12 +1,12 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx +CXXSRCS = class.cxx TARGET = example INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run_cpp build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/class/example.cxx b/Examples/go/class/class.cxx similarity index 100% rename from Examples/go/class/example.cxx rename to Examples/go/class/class.cxx diff --git a/Examples/go/constants/Makefile b/Examples/go/constants/Makefile index b45feb963..c232e9ed1 100644 --- a/Examples/go/constants/Makefile +++ b/Examples/go/constants/Makefile @@ -6,7 +6,7 @@ INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/enum/Makefile b/Examples/go/enum/Makefile index 7489f87dc..6f9347ca8 100644 --- a/Examples/go/enum/Makefile +++ b/Examples/go/enum/Makefile @@ -1,12 +1,12 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx +CXXSRCS = enum.cxx TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run_cpp build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/enum/example.cxx b/Examples/go/enum/enum.cxx similarity index 100% rename from Examples/go/enum/example.cxx rename to Examples/go/enum/enum.cxx diff --git a/Examples/go/extend/Makefile b/Examples/go/extend/Makefile index 7489f87dc..386d4d0bb 100644 --- a/Examples/go/extend/Makefile +++ b/Examples/go/extend/Makefile @@ -1,12 +1,12 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx +CXXSRCS = extend.cxx TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run_cpp build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/extend/example.cxx b/Examples/go/extend/extend.cxx similarity index 100% rename from Examples/go/extend/example.cxx rename to Examples/go/extend/extend.cxx diff --git a/Examples/go/funcptr/Makefile b/Examples/go/funcptr/Makefile index 452ea2118..2c32c45fc 100644 --- a/Examples/go/funcptr/Makefile +++ b/Examples/go/funcptr/Makefile @@ -1,12 +1,12 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = example.c +SRCS = funcptr.c TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/funcptr/example.c b/Examples/go/funcptr/funcptr.c similarity index 100% rename from Examples/go/funcptr/example.c rename to Examples/go/funcptr/funcptr.c diff --git a/Examples/go/multimap/Makefile b/Examples/go/multimap/Makefile index 452ea2118..0c5ec395f 100644 --- a/Examples/go/multimap/Makefile +++ b/Examples/go/multimap/Makefile @@ -1,12 +1,12 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = example.c +SRCS = multimap.c TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/multimap/example.c b/Examples/go/multimap/multimap.c similarity index 100% rename from Examples/go/multimap/example.c rename to Examples/go/multimap/multimap.c diff --git a/Examples/go/pointer/Makefile b/Examples/go/pointer/Makefile index 452ea2118..12e94f939 100644 --- a/Examples/go/pointer/Makefile +++ b/Examples/go/pointer/Makefile @@ -1,12 +1,12 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = example.c +SRCS = pointer.c TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/pointer/example.c b/Examples/go/pointer/pointer.c similarity index 100% rename from Examples/go/pointer/example.c rename to Examples/go/pointer/pointer.c diff --git a/Examples/go/reference/Makefile b/Examples/go/reference/Makefile index 7489f87dc..5c5e6808b 100644 --- a/Examples/go/reference/Makefile +++ b/Examples/go/reference/Makefile @@ -1,12 +1,12 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx +CXXSRCS = reference.cxx TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run_cpp build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/reference/example.cxx b/Examples/go/reference/reference.cxx similarity index 100% rename from Examples/go/reference/example.cxx rename to Examples/go/reference/reference.cxx diff --git a/Examples/go/simple/Makefile b/Examples/go/simple/Makefile index 75f81bffe..907da8821 100644 --- a/Examples/go/simple/Makefile +++ b/Examples/go/simple/Makefile @@ -1,11 +1,11 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = example.c +SRCS = simple.c TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/simple/example.c b/Examples/go/simple/simple.c similarity index 100% rename from Examples/go/simple/example.c rename to Examples/go/simple/simple.c diff --git a/Examples/go/template/Makefile b/Examples/go/template/Makefile index 9ee030479..20ffb7136 100644 --- a/Examples/go/template/Makefile +++ b/Examples/go/template/Makefile @@ -6,7 +6,7 @@ INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run_cpp build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/variables/Makefile b/Examples/go/variables/Makefile index 452ea2118..1f144929c 100644 --- a/Examples/go/variables/Makefile +++ b/Examples/go/variables/Makefile @@ -1,12 +1,12 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = example.c +SRCS = variables.c TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/variables/example.c b/Examples/go/variables/variables.c similarity index 100% rename from Examples/go/variables/example.c rename to Examples/go/variables/variables.c diff --git a/Examples/test-suite/go/Makefile.in b/Examples/test-suite/go/Makefile.in index 1eb6cb377..1b4887e23 100644 --- a/Examples/test-suite/go/Makefile.in +++ b/Examples/test-suite/go/Makefile.in @@ -6,6 +6,7 @@ LANGUAGE = go GO = @GO@ GOGCC = @GOGCC@ GO1 = @GO1@ +GO12 = @GO12@ GOC = @GOC@ SCRIPTSUFFIX = _runme.go @@ -30,7 +31,7 @@ include $(srcdir)/../common.mk %.cpptest: $(setup) +$(swig_and_compile_cpp) - $(run_testcase) + $(run_testcase_cpp) %.ctest: $(setup) @@ -58,7 +59,22 @@ run_testcase = \ if test -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \ $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ if $(GOGCC) ; then \ - $(COMPILETOOL) $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.@OBJEXT@ $*$(SO); \ + $(COMPILETOOL) $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.@OBJEXT@ $*_wrap.@OBJEXT@; \ + elif $(GO12); then \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CC) -extldflags "$(CFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ + else \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ + fi && \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \ + fi + +run_testcase_cpp = \ + if test -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \ + $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ + if $(GOGCC) ; then \ + $(COMPILETOOL) $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.@OBJEXT@ $*_wrap.@OBJEXT@ -lstdc++; \ + elif $(GO12); then \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ else \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ fi && \ @@ -70,7 +86,9 @@ run_multi_testcase = \ $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ if $(GOGCC) ; then \ files=`cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list`; \ - $(COMPILETOOL) $(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}_wrap.@OBJEXT@; done` -lstdc++; \ + elif $(GO12); then \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ else \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ fi && \ diff --git a/Examples/test-suite/go/director_abstract_runme.go b/Examples/test-suite/go/director_abstract_runme.go deleted file mode 100644 index 37279383a..000000000 --- a/Examples/test-suite/go/director_abstract_runme.go +++ /dev/null @@ -1,62 +0,0 @@ -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_thread_runme.go b/Examples/test-suite/go/director_thread_runme.go deleted file mode 100644 index ddfacedbe..000000000 --- a/Examples/test-suite/go/director_thread_runme.go +++ /dev/null @@ -1,28 +0,0 @@ -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/template_typedef_import_runme.go b/Examples/test-suite/go/template_typedef_import_runme.go deleted file mode 100644 index f1c00ff13..000000000 --- a/Examples/test-suite/go/template_typedef_import_runme.go +++ /dev/null @@ -1,29 +0,0 @@ -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/Lib/go/cdata.i b/Lib/go/cdata.i index 0dac6420c..9e6dc2161 100644 --- a/Lib/go/cdata.i +++ b/Lib/go/cdata.i @@ -7,7 +7,8 @@ %{ typedef struct SWIGCDATA { char *data; - int len; + intgo len; + intgo cap; } SWIGCDATA; %} @@ -15,7 +16,8 @@ typedef struct SWIGCDATA { %typemap(out) SWIGCDATA %{ $result.data = (char*)_swig_goallocate($1.len); memcpy($result.data, $1.data, $1.len); - $result.len = (int)$1.len; + $result.len = (intgo)$1.len; + $result.cap = $result.len; %} /* ----------------------------------------------------------------------------- diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index e5398ba7a..adb81345e 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -22,6 +22,8 @@ class GO:public Language { bool gccgo_flag; // Prefix to use with gccgo. String *go_prefix; + // Whether to use a shared library. + bool use_shlib; // Name of shared library to import. String *soname; // Size in bits of the C type "long". @@ -86,6 +88,7 @@ public: module(NULL), gccgo_flag(false), go_prefix(NULL), + use_shlib(false), soname(NULL), long_type_size(32), intgo_type_size(0), @@ -153,6 +156,9 @@ private: } else { Swig_arg_error(); } + } else if (strcmp(argv[i], "-use-shlib") == 0) { + Swig_mark_arg(i); + use_shlib = true; } else if (strcmp(argv[i], "-soname") == 0) { if (argv[i + 1]) { soname = NewString(argv[i + 1]); @@ -274,7 +280,7 @@ private: if (!package) { package = Copy(module); } - if (!soname) { + if (!soname && use_shlib) { soname = Copy(package); Append(soname, ".so"); } @@ -387,7 +393,7 @@ private: Swig_banner(f_go_begin); Printf(f_go_begin, "\n// source: %s\n", swig_filename); - if (!gccgo_flag) { + if (!gccgo_flag && soname) { Swig_banner(f_gc_begin); Printf(f_gc_begin, "\n/* source: %s */\n\n", swig_filename); Printf(f_gc_begin, "\n/* This file should be compiled with 6c/8c. */\n"); @@ -1084,6 +1090,7 @@ private: Wrapper *f = NewWrapper(); Printv(f->def, "#pragma dynimport ", wname, " ", wname, " \"\"\n", NULL); + Printv(f->def, "#pragma cgo_import_static ", wname, "\n", NULL); Printv(f->def, "extern void (*", wname, ")(void*);\n", NULL); Printv(f->def, "static void (*x", wname, ")(void*) = ", wname, ";\n", NULL); Printv(f->def, "\n", NULL); @@ -2825,6 +2832,7 @@ private: Printv(f_c_directors, " crosscall2(", wname, ", &a, (int) sizeof a);\n", NULL); Printv(f_gc_wrappers, "#pragma dynexport ", wname, " ", wname, "\n", NULL); + Printv(f_gc_wrappers, "#pragma cgo_export_static ", wname, " ", wname, "\n", NULL); Printv(f_gc_wrappers, "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); @@ -2918,17 +2926,20 @@ private: return r; } - String *go_upcall = NewString("Director"); - Append(go_upcall, cn); - Append(go_upcall, go_name); - r = makeDispatchFunction(on, go_upcall, director_struct_name, is_static, director_struct_name, true); - if (r != SWIG_OK) { - return r; + if (!GetFlag(n, "abstract")) { + String *go_upcall = NewString("Director"); + Append(go_upcall, cn); + Append(go_upcall, go_name); + r = makeDispatchFunction(on, go_upcall, director_struct_name, is_static, director_struct_name, true); + if (r != SWIG_OK) { + return r; + } + Delete(go_upcall); } - Delete(cn); - Delete(go_name); + Delete(director_struct_name); - Delete(go_upcall); + Delete(go_name); + Delete(cn); } } Setattr(class_methods, name, NewString("")); @@ -3010,6 +3021,11 @@ private: Append(upcall_name, go_name); String *upcall_wname = Swig_name_wrapper(upcall_name); + if (overname) { + Append(upcall_wname, overname); + } + + String *upcall_gc_name = buildGoWrapperName(upcall_name, overname); String *go_with_over_name = Copy(go_name); if (overname) { @@ -3052,40 +3068,36 @@ private: 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 (!GetFlag(n, "abstract")) { + // Declare the upcall function, which calls the method on the + // parent class. - if (overname) { - Append(upcall_wname, overname); + if (gccgo_flag) { + Printv(f_go_wrappers, "//extern ", go_prefix, "_", upcall_wname, "\n", NULL); + } + + 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); + } + + Printv(f_go_wrappers, "\n", NULL); } - String *upcall_gc_name = buildGoWrapperName(upcall_name, overname); - - if (gccgo_flag) { - Printv(f_go_wrappers, "//extern ", go_prefix, "_", upcall_wname, "\n", NULL); - } - - 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); - } - - 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); @@ -3136,181 +3148,189 @@ private: } Printv(f_go_wrappers, "\t}\n", NULL); - if (gccgo_flag) { - Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); - Printv(f_go_wrappers, "\tSwigCgocall()\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); + if (GetFlag(n, "abstract")) { + Printv(f_go_wrappers, "\tpanic(\"call to pure virtual method\")\n", NULL); + } else { + if (gccgo_flag) { + Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); + Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); } - 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, 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", 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) { - Append(upcall_method_name, overname); - } - SwigType *rtype = Getattr(n, "classDirectorMethods:type"); - String *upcall_decl = Swig_method_decl(rtype, 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); - } - - String *super_call = Swig_method_call(super, parms); - Printv(f_c_directors_h, super_call, ";\n", NULL); - Delete(super_call); - - 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, Swig_cresult_name(), " = (", SwigType_lstr(result, 0), ")", NULL); - if (SwigType_isreference(result)) { - Printv(action, "&", NULL); + if (!GetFlag(n, "abstract")) { + String *upcall_method_name = NewString("_swig_upcall_"); + Append(upcall_method_name, name); + if (overname) { + Append(upcall_method_name, overname); } - } - Printv(action, Swig_cparm_name(NULL, 0), "->", upcall_method_name, "(", NULL); + SwigType *rtype = Getattr(n, "classDirectorMethods:type"); + String *upcall_decl = Swig_method_decl(rtype, Getattr(n, "decl"), upcall_method_name, parms, 0, 0); + Printv(f_c_directors_h, " ", upcall_decl, " {\n", NULL); + Delete(upcall_decl); - p = parms; - int i = 0; - while (p != NULL) { - if (SwigType_type(Getattr(p, "type")) != T_VOID) { - String *pname = Swig_cparm_name(NULL, i + 1); - if (i > 0) { - Printv(action, ", ", NULL); + Printv(f_c_directors_h, " ", NULL); + if (SwigType_type(result) != T_VOID) { + Printv(f_c_directors_h, "return ", NULL); + } + + String *super_call = Swig_method_call(super, parms); + Printv(f_c_directors_h, super_call, ";\n", NULL); + Delete(super_call); + + 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, Swig_cresult_name(), " = (", SwigType_lstr(result, 0), ")", NULL); + if (SwigType_isreference(result)) { + Printv(action, "&", NULL); } + } + Printv(action, Swig_cparm_name(NULL, 0), "->", upcall_method_name, "(", 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); + p = parms; + int i = 0; + while (p != NULL) { + if (SwigType_type(Getattr(p, "type")) != T_VOID) { + 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); + i++; } - - Printv(action, pname, NULL); - Delete(pname); - i++; + p = nextSibling(p); } - p = nextSibling(p); - } - Printv(action, ");", NULL); - Setattr(n, "wrap:action", action); + 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; + 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; + } } - r = gccFunctionWrapper(n, NULL, upcall_wname, first_parm, result); - if (r != SWIG_OK) { - return r; + + Delete(first_type); + if (first_parm != parms) { + Delete(first_parm); } - } else { - int r = gccgoFunctionWrapper(n, NULL, upcall_wname, first_parm, result); - if (r != SWIG_OK) { - return r; + + Swig_restore(n); + Delete(upcall_method_name); + + // Define a function that 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); } - } - Delete(first_type); - if (first_parm != parms) { - Delete(first_parm); - } + Printv(f_go_wrappers, ")", NULL); - 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); - - if (gccgo_flag) { - Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); - Printv(f_go_wrappers, "\tSwigCgocall()\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); + if (SwigType_type(result) != T_VOID) { + String *tm = goType(n, result); + Printv(f_go_wrappers, " ", tm, NULL); + Delete(tm); } - p = nextParm(p); - } - Printv(f_go_wrappers, ")\n", NULL); - Printv(f_go_wrappers, "}\n\n", NULL); + Printv(f_go_wrappers, " {\n", NULL); + + if (gccgo_flag) { + Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); + Printv(f_go_wrappers, "\tSwigCgocall()\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. @@ -3390,17 +3410,16 @@ private: } Printv(f_go_wrappers, "\n", NULL); - - Delete(upcall_gc_name); } Printv(f_go_wrappers, "}\n\n", NULL); Delete(result_wrapper); - // Build the C++ functions. - Delete(upcall_wname); + Delete(upcall_gc_name); + + // Build the C++ functions. if (!gccgo_flag) { Printv(f_c_directors, "extern \"C\" void ", callback_wname, "(void*, int);\n", NULL); @@ -3437,7 +3456,6 @@ private: Printv(f_c_directors, " __asm__(\"", go_prefix, ".", package, ".", callback_name, "\");\n", NULL); } - Delete(upcall_method_name); Delete(go_with_over_name); } @@ -3544,6 +3562,7 @@ 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, "#pragma cgo_export_static ", 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); @@ -4909,5 +4928,6 @@ Go Options (available with -go)\n\ -longsize - Set size of C/C++ long type--32 or 64 bits\n\ -intgosize - Set size of Go int type--32 or 64 bits\n\ -package - Set name of the Go package to \n\ + -use-shlib - Force use of a shared library\n\ -soname - Set shared library holding C/C++ code to \n\ \n"; diff --git a/configure.ac b/configure.ac index 557138dbc..3acc2aa9e 100644 --- a/configure.ac +++ b/configure.ac @@ -1996,6 +1996,7 @@ if test x"${GOBIN}" = xno -o x"${with_alllang}" = xno ; then GO= GOC= GO1=false + GO12=false GOGCC=false GOOPT= GOVERSIONOPTION= @@ -2009,6 +2010,7 @@ else GOGCC=false GO1=false + GO12=false GOOPT= GOVERSIONOPTION= if test -n "$GO" ; then @@ -2046,6 +2048,15 @@ else fi ;; esac + case $go_version in + go1.0* | go1.1*) + GO12=false + GOOPT="$GOOPT -use-shlib" + ;; + *) + GO12=true + ;; + esac else GOC=`echo $GO | sed -e 's/g/c/'` GOVERSIONOPTION=-V @@ -2059,6 +2070,7 @@ else AC_MSG_RESULT([no]) fi GOOPT="-intgosize 32" + GO12=false fi fi fi @@ -2067,6 +2079,7 @@ AC_SUBST(GOGCC) AC_SUBST(GO) AC_SUBST(GOC) AC_SUBST(GO1) +AC_SUBST(GO12) AC_SUBST(GOOPT) AC_SUBST(GOVERSIONOPTION) From 25689857eb7ae8d1027dc8550686005807ed0641 Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Tue, 17 Dec 2013 12:14:33 +0400 Subject: [PATCH 0829/1160] Language::addSymbol fix, to handle classes correctly --- Source/Modules/lang.cxx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 78c37dbb9..be83b5069 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -3049,12 +3049,6 @@ int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr // New scope which has not been added by the target language - lazily created. symbols = NewHash(); Setattr(symtabs, scope, symbols); - - // Add the new scope as a symbol in the top level scope. - // Alternatively the target language must add it in before attempting to add symbols into the scope. - const_String_or_char_ptr top_scope = ""; - Hash *topscope_symbols = Getattr(symtabs, top_scope); - Setattr(topscope_symbols, scope, NewHash()); } else { Node *c = Getattr(symbols, s); if (c && (c != n)) { From 532da6989c9f9723a5ea1f278653f816f6a2d4a5 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 17 Dec 2013 13:50:39 -0800 Subject: [PATCH 0830/1160] [Go] Add -go-pkgpath option. --- CHANGES.current | 3 ++ Doc/Manual/Go.html | 10 +++++- Lib/go/goruntime.swg | 21 ++++++++---- Source/Modules/go.cxx | 76 +++++++++++++++++++++++++++++++++---------- 4 files changed, 85 insertions(+), 25 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 21c97407d..4691d65d7 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-12-17: iant + [Go] Add -go-pkgpath option. + 2013-12-16: iant [Go] Update for Go 1.2 release. Add support for linking SWIG code directly into executable, rather than using a diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 3482d34dc..87e224aee 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -134,10 +134,18 @@ swig -go -help option implies the -use-shlib option.
  • + + + + + + corresponds to the -fgo-prefix option to gccgo. + If -go-pkgpath is used, -go-prefix will be + ignored. diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index 4b7daf41f..3e639cdc2 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -115,13 +115,6 @@ extern void _cgo_panic(const char *); version. We assume that the version of gcc used to compile this file is the same as the version of gccgo. */ -#define SWIGCONCAT2(s1, s2) s1 ## s2 -#define SWIGCONCAT1(s1, s2) SWIGCONCAT2(s1, s2) -#define SwigCgocall SWIGCONCAT1(SWIGMODULE, SwigCgocall) -#define SwigCgocallDone SWIGCONCAT1(SWIGMODULE, SwigCgocallDone) -#define SwigCgocallBack SWIGCONCAT1(SWIGMODULE, SwigCgocallBack) -#define SwigCgocallBackDone SWIGCONCAT1(SWIGMODULE, SwigCgocallBackDone) - #define SWIG_GCC_VERSION \ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC__PATH_LEVEL__) @@ -142,22 +135,36 @@ void SwigDoCgocallBack(void) __asm__("syscall.CgocallBack"); void SwigDoCgocallBackDone(void) __asm__("syscall.CgocallBackDone"); #endif +#define SWIGSTRINGIFY2(s) #s +#define SWIGSTRINGIFY(s) SWIGSTRINGIFY2(s) + +void SwigCgocall() + __asm__(SWIGSTRINGIFY(SWIGGO_PREFIX) ".SwigCgocall"); void SwigCgocall() { SwigDoCgocall(); } +void SwigCgocallDone() + __asm__(SWIGSTRINGIFY(SWIGGO_PREFIX) ".SwigCgocallDone"); void SwigCgocallDone() { SwigDoCgocallDone(); } +void SwigCgocallBack() + __asm__(SWIGSTRINGIFY(SWIGGO_PREFIX) ".SwigCgocallBack"); void SwigCgocallBack() { SwigDoCgocallBack(); } +void SwigCgocallBackDone() + __asm__(SWIGSTRINGIFY(SWIGGO_PREFIX) ".SwigCgocallBackDone"); void SwigCgocallBackDone() { SwigDoCgocallBackDone(); } +#undef SWIGSTRINGIFY +#undef SWIGSTRINGIFY2 + #ifdef __cplusplus } #endif diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index adb81345e..6db099662 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -22,6 +22,10 @@ class GO:public Language { bool gccgo_flag; // Prefix to use with gccgo. String *go_prefix; + // -fgo-prefix option. + String *prefix_option; + // -fgo-pkgpath option. + String *pkgpath_option; // Whether to use a shared library. bool use_shlib; // Name of shared library to import. @@ -88,6 +92,8 @@ public: module(NULL), gccgo_flag(false), go_prefix(NULL), + prefix_option(NULL), + pkgpath_option(NULL), use_shlib(false), soname(NULL), long_type_size(32), @@ -149,7 +155,16 @@ private: gccgo_flag = true; } else if (strcmp(argv[i], "-go-prefix") == 0) { if (argv[i + 1]) { - go_prefix = NewString(argv[i + 1]); + prefix_option = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-go-pkgpath") == 0) { + if (argv[i + 1]) { + pkgpath_option = NewString(argv[i + 1]); Swig_mark_arg(i); Swig_mark_arg(i + 1); i++; @@ -201,8 +216,8 @@ private: } } - if (gccgo_flag && !go_prefix) { - go_prefix = NewString("go"); + if (gccgo_flag && !pkgpath_option && !prefix_option) { + prefix_option = NewString("go"); } // Add preprocessor symbol to parser. @@ -285,6 +300,27 @@ private: Append(soname, ".so"); } + if (gccgo_flag) { + String *pref; + if (pkgpath_option) { + pref = pkgpath_option; + } else { + pref = prefix_option; + } + go_prefix = NewString(""); + for (char *p = Char(pref); *p != '\0'; p++) { + if ((*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z') || (*p >= '0' && *p <= '9') || *p == '.' || *p == '$') { + Putc(*p, go_prefix); + } else { + Putc('_', go_prefix); + } + } + if (!pkgpath_option) { + Append(go_prefix, "."); + Append(go_prefix, package); + } + } + // Get filenames. String *swig_filename = Getattr(n, "infile"); @@ -374,6 +410,9 @@ private: } Printf(f_c_runtime, "#define SWIGMODULE %s\n", module); + if (gccgo_flag) { + Printf(f_c_runtime, "#define SWIGGO_PREFIX %s\n", go_prefix); + } if (directorsEnabled()) { Printf(f_c_runtime, "#define SWIG_DIRECTORS\n"); @@ -404,14 +443,12 @@ private: Printf(f_go_begin, "\npackage %s\n\n", package); - Printf(f_go_runtime, "//extern %sSwigCgocall\n", module); - Printf(f_go_runtime, "func SwigCgocall()\n"); - Printf(f_go_runtime, "//extern %sSwigCgocallDone\n", module); - Printf(f_go_runtime, "func SwigCgocallDone()\n"); - Printf(f_go_runtime, "//extern %sSwigCgocallBack\n", module); - Printf(f_go_runtime, "func SwigCgocallBack()\n"); - Printf(f_go_runtime, "//extern %sSwigCgocallBackDone\n", module); - Printf(f_go_runtime, "func SwigCgocallBackDone()\n\n"); + if (gccgo_flag) { + Printf(f_go_runtime, "func SwigCgocall()\n"); + Printf(f_go_runtime, "func SwigCgocallDone()\n"); + Printf(f_go_runtime, "func SwigCgocallBack()\n"); + Printf(f_go_runtime, "func SwigCgocallBackDone()\n\n"); + } // All the C++ wrappers should be extern "C". @@ -1340,7 +1377,7 @@ private: // Start the function definition. String *fnname = NewString(""); - Printv(fnname, go_prefix, "_", wname, "(", NULL); + Printv(fnname, "go_", wname, "(", NULL); if (parm_count > required_count) { Printv(fnname, "intgo _swig_optargc", NULL); @@ -1369,17 +1406,21 @@ private: Printv(fnname, ")", NULL); + String *fndef = NewString(""); if (SwigType_type(result) == T_VOID) { - Printv(f->def, "void ", fnname, NULL); + Printv(fndef, "void ", fnname, NULL); } else { String *ct = gccgoCTypeForGoValue(n, result, fnname); - Printv(f->def, ct, NULL); + Printv(fndef, ct, NULL); Delete(ct); } - Printv(f->def, " {\n", NULL); + Printv(f->def, fndef, " __asm__(\"", go_prefix, "_", wname, "\");\n", NULL); + + Printv(f->def, fndef, " {\n", NULL); Delete(fnname); + Delete(fndef); if (SwigType_type(result) != T_VOID) { String *ln = NewString("go_result"); @@ -2811,7 +2852,7 @@ private: 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, "extern \"C\" void ", wname, "(void*) __asm__(\"", go_prefix, ".", go_name, "\");\n", NULL); } } @@ -3453,7 +3494,7 @@ private: Delete(fnname); - Printv(f_c_directors, " __asm__(\"", go_prefix, ".", package, ".", callback_name, "\");\n", NULL); + Printv(f_c_directors, " __asm__(\"", go_prefix, ".", callback_name, "\");\n", NULL); } Delete(go_with_over_name); @@ -4924,6 +4965,7 @@ extern "C" Language *swig_go(void) { const char * const GO::usage = (char *) "\ Go Options (available with -go)\n\ -gccgo - Generate code for gccgo rather than 6g/8g\n\ + -go-pkgpath

    - Like gccgo -fgo-pkgpath option\n\ -go-prefix

    - Like gccgo -fgo-prefix option\n\ -longsize - Set size of C/C++ long type--32 or 64 bits\n\ -intgosize - Set size of Go int type--32 or 64 bits\n\ From ba049db40b5a4400fc19a72d9178df92ffcbc203 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 17 Dec 2013 17:37:55 -0800 Subject: [PATCH 0831/1160] Remove Go -longsize option. --- CHANGES.current | 10 ++++--- Doc/Manual/Go.html | 11 ++------ .../test-suite/go/template_opaque_runme.go | 2 +- Examples/test-suite/go/wrapmacro_runme.go | 4 +-- Lib/go/go.swg | 27 ------------------- Source/Modules/go.cxx | 16 +---------- 6 files changed, 13 insertions(+), 57 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 4691d65d7..f7a882aa1 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,15 +5,19 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ -2013-12-17: iant +2013-12-17: ianlancetaylor + [Go] Remove -longsize option (for backward compatibility, + ignore it if seen). + +2013-12-17: ianlancetaylor [Go] Add -go-pkgpath option. -2013-12-16: iant +2013-12-16: ianlancetaylor [Go] Update for Go 1.2 release. Add support for linking SWIG code directly into executable, rather than using a shared library. -2013-12-13: iant +2013-12-13: ianlancetaylor [Go] Add SWIG source file name as comments in generated files. This can be used by Go documentation tools. diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 87e224aee..43bfc6971 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -148,13 +148,6 @@ swig -go -help ignored.

    - - - - -
    +
    SWIG_MemoryError
    +
    rb_eNoMemError
    +
    SWIG_IOError
    +
    rb_eIOError
    +
    SWIG_RuntimeError
    +
    rb_eRuntimeError
    +
    SWIG_IndexError
    +
    rb_eIndexError
    +
    SWIG_TypeError
    +
    rb_eTypeError
    +
    SWIG_DivisionByZero
    +
    rb_eZeroDivError
    +
    SWIG_OverflowError
    +
    rb_eRangeError
    +
    SWIG_SyntaxError
    +
    rb_eSyntaxError
    +
    SWIG_ValueError
    +
    rb_eArgError
    +
    SWIG_SystemError
    +
    rb_eFatal
    +
    SWIG_AttributeError
    +
    rb_eRuntimeError
    +
    SWIG_NullReferenceError
    +
    rb_eNullReferenceError*
    +
    SWIG_ObjectPreviouslyDeletedError
    +
    rb_eObjectPreviouslyDeleted*
    +
    SWIG_UnknownError
    +
    rb_eRuntimeError
    * These error classes are created by SWIG and are not built-in Ruby exception classes
    @@ -1812,10 +1798,9 @@ Obj is a C++ instance of an exception class, type is a string specifying the type of exception (for example, "MyError") and desc is the SWIG description of the exception class. For example:

    -
    -%raise(SWIG_NewPointerObj(e, -SWIGTYPE_p_AssertionFailedException, -0), ":AssertionFailedException", SWIGTYPE_p_AssertionFailedException);
    +
    +%raise(SWIG_NewPointerObj(e, SWIGTYPE_p_AssertionFailedException, 0), ":AssertionFailedException", SWIGTYPE_p_AssertionFailedException);
    +

    This is useful when you want to pass the current exception object @@ -1849,7 +1834,7 @@ providing for a more natural integration between C++ code and Ruby code.

    foo = Foo.new
    begin
    foo.test()
    rescue CustomError => e
    puts "Caught custom error"
    end
    -

    For another example look at swig/Examples/ruby/exception_class.
    +

    For another example look at swig/Examples/ruby/exception_class.

    @@ -1876,8 +1861,11 @@ attached to a specific C datatype. The general form of this declaration is as follows ( parts enclosed in [...] are optional ):    

    -
    %typemap( method [, modifiers...] ) typelist -code;
    +
    +
    +%typemap( method [, modifiers...] ) typelist code;
    +
    +

    method is a simply a name that specifies what kind of typemap is being defined. It is usually a name like "in", @@ -1936,7 +1924,10 @@ following sample code:

    prints the result:

    -
    Received an integer : 6
    720
    +
    +Received an integer : 6
    +720
    +

    In this example, the typemap is applied to all occurrences of @@ -2122,33 +2113,33 @@ function arguments. For example: - - + - - + - - + - - + - - + - - + @@ -2205,33 +2196,33 @@ to a Ruby object.

    $input Input object + $input Input object holding value to be converted.
    $symname Name of + $symname Name of function/method being wrapped
    $1...n Argument being + $1...n Argument being sent to the function
    $1_name Name of the + $1_name Name of the argument (if provided)
    $1_type The actual C + $1_type The actual C datatype matched by the typemap.
    $1_ltype The assignable + $1_ltype The assignable version of the C datatype matched by the typemap.
    - - + - - + - - + - - + - - + - - + @@ -2301,18 +2292,18 @@ example:

    $result Result object + $result Result object returned to target language.
    $symname Name of + $symname Name of function/method being wrapped
    $1...n Argument being + $1...n Argument being wrapped
    $1_name Name of the + $1_name Name of the argument (if provided)
    $1_type The actual C + $1_type The actual C datatype matched by the typemap.
    $1_ltype The assignable + $1_ltype The assignable version of the C datatype matched by the typemap.
    - - + - - + - - + @@ -2441,38 +2432,38 @@ typemap.
    $result Result object + $result Result object returned to target language.
    $input The original + $input The original input object passed.
    $symname Name of + $symname Name of function/method being wrapped.
    - - + - - + - - + - - + - - + - - + - - + @@ -2488,15 +2479,11 @@ of the "out" typemap, making its rule often similar to the "in" typemap.

    -

    - -%typemap(directorout) int {

    - -   $result = NUM2INT($1);

    - -}
    - -
    +
    +%typemap(directorout) int {
    +   $result = NUM2INT($1);
    +
    +

    The following special variables are available:

    @@ -2504,35 +2491,35 @@ typemap.
    $result Result object + $result Result object returned to target language.
    $symname Name of + $symname Name of function/method being wrapped
    $1...n Argument being + $1...n Argument being wrapped
    $1_name Name of the + $1_name Name of the argument (if provided)
    $1_type The actual C + $1_type The actual C datatype matched by the typemap.
    $1_ltype The assignable + $1_ltype The assignable version of the C datatype matched by the typemap.
    this C++ this, + this C++ this, referring to the class itself.
    - - + + - - + + - - + + - - + - - + - - + - - + @@ -2540,17 +2527,18 @@ referring to the class itself.

    Currently, the directorout nor the out typemap support the -option numoutputs, +option numoutputs, but the Ruby module provides that functionality through a %feature directive.  Thus, a function can be made to return "nothing" if you do:

    -
    %feature("numoutputs","0") -MyClass::function;
    +
    +%feature("numoutputs","0") MyClass::function;
    +

    This feature can be useful if a function returns a status code, which you want to discard but still use the typemap to raise an -exception.
    +exception.

    @@ -2560,12 +2548,12 @@ exception.

    Output argument processing in director member functions.

    -
    %typemap(directorargout, -fragment="output_helper") int {
    - -$result = output_helper( $result, NUM2INT($1) );

    - -}
    +
    +%typemap(directorargout,
    +fragment="output_helper") int {
    +  $result = output_helper( $result, NUM2INT($1) );
    +}
    +

    The following special variables are available:

    @@ -2573,39 +2561,39 @@ $result = output_helper( $result, NUM2INT($1) );
    $inputRuby object being sent to the function$inputRuby object being sent to the function
    $symname Name of function/method being wrapped$symname Name of function/method being wrapped
    $1...n Argument being sent to the function$1...n Argument being sent to the function
    $1_name Name of the + $1_name Name of the argument (if provided)
    $1_type The actual C + $1_type The actual C datatype matched by the typemap.
    $1_ltype The assignable + $1_ltype The assignable version of the C datatype matched by the typemap.
    this C++ this, + this C++ this, referring to the class itself.
    - - + + - - + + - - + + - - + + - - + - - + - - + - - + @@ -2702,28 +2690,28 @@ across multiple languages.

    - - + + - - + + - - + + - - + + - - + @@ -2735,65 +2723,65 @@ SWIG_From_float(float)

    Here, while the Ruby versions return the value directly, the SWIG -versions do not, but return a status value to indicate success (SWIG_OK). While more akward to use, this allows you to write typemaps that report more helpful error messages, like:

    -

    -%typemap(in) size_t (int ok)

    -  ok = SWIG_AsVal_size_t($input, &$1);
    -  if (!SWIG_IsOK(ok)) {
    -    SWIG_exception_fail(SWIG_ArgError(ok), -Ruby_Format_TypeError( "$1_name", "$1_type","$symname", $argnum, $input -));
    -   }
    -
    -}
    -
      
    +versions do not, but return a status value to indicate success (SWIG_OK). While more akward to use, this allows you to write typemaps that report more helpful error messages, like:

    + +
    +
    +%typemap(in) size_t (int ok)
    +  ok = SWIG_AsVal_size_t($input, &$1);
    +  if (!SWIG_IsOK(ok)) {
    +    SWIG_exception_fail(SWIG_ArgError(ok), Ruby_Format_TypeError( "$1_name", "$1_type","$symname", $argnum, $input));
    +  }
    +}
    +
    +
    +
    $resultResult that the director function returns$resultResult that the director function returns
    $inputRuby object being sent to the function$inputRuby object being sent to the function
    $symnamename of the function/method being wrapped$symnamename of the function/method being wrapped
    $1...nArgument being sent to the function$1...nArgument being sent to the function
    $1_nameName of the + $1_nameName of the argument (if provided)
    $1_typeThe actual C + $1_typeThe actual C datatype matched by the typemap
    $1_ltypeThe assignable + $1_ltypeThe assignable version of the C datatype matched by the typemap
    thisC++ this, + thisC++ this, referring to the instance of the class itself
    INT2NUM(long or int) SWIG_From_int(int x)INT2NUM(long or int) SWIG_From_int(int x) int to Fixnum or Bignum
    INT2FIX(long or int) INT2FIX(long or int) int to Fixnum (faster than INT2NUM)
    CHR2FIX(char) SWIG_From_char(char x)CHR2FIX(char) SWIG_From_char(char x) char to Fixnum
    rb_str_new2(char*) SWIG_FromCharPtrAndSize(char*, size_t)rb_str_new2(char*) SWIG_FromCharPtrAndSize(char*, size_t) char* to String
    rb_float_new(double) SWIG_From_double(double),
    +
    rb_float_new(double) SWIG_From_double(double),
    SWIG_From_float(float)
    float/double to Float
    - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + +
    int NUM2INT(Numeric)SWIG_AsVal_int(VALUE, int*)int NUM2INT(Numeric)SWIG_AsVal_int(VALUE, int*)
    int FIX2INT(Numeric)SWIG_AsVal_int(VALUE, int*)int FIX2INT(Numeric)SWIG_AsVal_int(VALUE, int*)
    unsigned int NUM2UINT(Numeric)SWIG_AsVal_unsigned_SS_int(VALUE, int*)unsigned int NUM2UINT(Numeric)SWIG_AsVal_unsigned_SS_int(VALUE, int*)
    unsigned int FIX2UINT(Numeric)SWIG_AsVal_unsigned_SS_int(VALUE, int*)unsigned int FIX2UINT(Numeric)SWIG_AsVal_unsigned_SS_int(VALUE, int*)
    long NUM2LONG(Numeric)SWIG_AsVal_long(VALUE, long*)long NUM2LONG(Numeric)SWIG_AsVal_long(VALUE, long*)
    long FIX2LONG(Numeric)SWIG_AsVal_long(VALUE, long*)long FIX2LONG(Numeric)SWIG_AsVal_long(VALUE, long*)
    unsigned long FIX2ULONG(Numeric)SWIG_AsVal_unsigned_SS_long(VALUE, unsigned long*)unsigned long FIX2ULONG(Numeric)SWIG_AsVal_unsigned_SS_long(VALUE, unsigned long*)
    char NUM2CHR(Numeric or String)SWIG_AsVal_char(VALUE, int*)char NUM2CHR(Numeric or String)SWIG_AsVal_char(VALUE, int*)
    char * StringValuePtr(String)SWIG_AsCharPtrAndSize(VALUE, char*, size_t, int* alloc)char * StringValuePtr(String)SWIG_AsCharPtrAndSize(VALUE, char*, size_t, int* alloc)
    char * rb_str2cstr(String, int*length)char * rb_str2cstr(String, int*length)
    double NUM2DBL(Numeric)(double) SWIG_AsVal_int(VALUE) or similardouble NUM2DBL(Numeric)(double) SWIG_AsVal_int(VALUE) or similar
    @@ -3250,16 +3238,17 @@ generated file. 

    For example, to generate html web pages from a C++ file, you'd do: 

    -
    -$ -rdoc -E cxx=c -f html file_wrap.cxx
    +
    +
    +$ rdoc -E cxx=c -f html file_wrap.cxx
    +

    To generate ri documentation from a c wrap file, you could do:

    -
    $ rdoc --r file_wrap.c -
    +
    +$ rdoc -r file_wrap.c
    +

    36.8.1 Module docstring

    @@ -3611,7 +3600,7 @@ that defines a derived class:

    extension module:

    -
    $ swig -c++ -ruby shape.i
    +
    $ swig -c++ -ruby shape.i
     
    @@ -3887,7 +3876,7 @@ class library models a zoo and the animals it contains.

    %module zoo

    %{
    #include <string>
    #include <vector>

    #include "zoo.h"
    %}

    class Animal
    {
    private:
    typedef std::vector<Animal*> AnimalsType;
    typedef AnimalsType::iterator IterType;
    protected:
    AnimalsType animals;
    protected:
    std::string name_;
    public:
    // Construct an animal with this name
    Animal(const char* name) : name_(name) {}

    // Return the animal's name
    const char* get_name() const { return name.c_str(); }
    };

    class Zoo
    {
    protected:
    std::vector<animal *=""> animals;

    public:
    // Construct an empty zoo
    Zoo() {}

    /* Create a new animal. */
    static Animal* Zoo::create_animal(const char* name)
    {
    return new Animal(name);
    }

    // Add a new animal to the zoo
    void add_animal(Animal* animal) {
    animals.push_back(animal);
    }

    Animal* remove_animal(size_t i) {
    Animal* result = this->animals[i];
    IterType iter = this->animals.begin();
    std::advance(iter, i);
    this->animals.erase(iter);

    return result;
    }

    // Return the number of animals in the zoo
    size_t get_num_animals() const {
    return animals.size();
    }

    // Return a pointer to the ith animal
    Animal* get_animal(size_t i) const {
    return animals[i];
    }
    };

    -

    Let's say you SWIG this code and then run IRB:
    +

    Let's say you SWIG this code and then run IRB:

    @@ -3968,8 +3957,7 @@ class-by-class basis if needed. To fix the example above:

    %module example

    %{
    #include "example.h"
    %}

    /* Tell SWIG that create_animal creates a new object */
    %newobject Zoo::create_animal;

    /* Tell SWIG to keep track of mappings between C/C++ structs/classes. */
    %trackobjects;

    %include "example.h"
    -

    When this code runs we see:
    - +

    When this code runs we see:

    @@ -4013,7 +4001,7 @@ has problems. For example:

    The problem is that Ruby does not know that the zoo object contains a reference to a Ruby object. Thus, when Ruby garbage -collects tiger1 +collects tiger1 it frees the underlying C++ object.

    This can be fixed by implementing a mark @@ -4086,8 +4074,8 @@ above.

    To show how to use the %freefunc directive, let's slightly change our example. Assume that the zoo object is responsible for freeing animal that it contains. This means -that the Zoo::add_animal -function should be marked with a DISOWN typemap +that the Zoo::add_animal +function should be marked with a DISOWN typemap and the destructor should be updated as below:

    @@ -4283,19 +4271,12 @@ collect any VALUE objects defined from that point on.  

    To mark functions to either reset the ruby stack or not, you can use:

    -
    %initstack -  Class::memberfunction;  // only re-init the stack -in this director method
    - -%ignorestack Class::memberfunction;  // do not re-init the -stack in this director method
    - -%initstack   Class;       -        // init the stack on all -the methods of this class
    - -%initstack;   // all director functions will -re-init the stack
    +
    +%initstack Class::memberfunction;   // only re-init the stack in this director method
    +%ignorestack Class::memberfunction; // do not re-init the stack in this director method
    +%initstack Class;                   // init the stack on all the methods of this class
    +%initstack;                         // all director functions will re-init the stack
    +
    From 66599db01d3090379f3f3c793fc04c984cdef964 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Jun 2013 01:41:16 +0100 Subject: [PATCH 0661/1160] Ruby html docs formatting - modify code snippets to be same as other chapters --- Doc/Manual/Ruby.html | 1461 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 1271 insertions(+), 190 deletions(-) diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index 1798d1df7..f1523ecf5 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -220,7 +220,8 @@ file from the Ruby distribution:

    Create a file called extconf.rb that looks like the following:

    -
    require 'mkmf'
    create_makefile('example')
    +
    require 'mkmf'
    +create_makefile('example')
  • @@ -342,7 +343,9 @@ the C++ runtime libraries to the list of libraries linked into your extension, e.g.

    -
    require 'mkmf'
    $libs = append_library($libs, "supc++")
    create_makefile('example')
    +
    require 'mkmf'
    +$libs = append_library($libs, "supc++")
    +create_makefile('example')

    36.2 Building Ruby Extensions under Windows 95/NT

    @@ -417,7 +420,11 @@ Ruby and use the require command as normal. For example if you have this ruby file run.rb:

    -
    # file: run.rb
    require 'Example'

    # Call a c function
    print "Foo = ", Example.Foo, "\n"
    +
    # file: run.rb
    +require 'Example'
    +
    +# Call a c function
    +print "Foo = ", Example.Foo, "\n"

    Ensure the dll just built is in your path or current @@ -516,20 +523,30 @@ example, given the SWIG interface file example.i:

    -
    %module example

    int fact(int n);
    +
    %module example
    +
    +int fact(int n);

    and C source file example.c:

    -
    int fact(int n) {
    if (n == 0)
    return 1;
    return (n * fact(n-1));
    }
    +
    int fact(int n) {
    +  if (n == 0)
    +  return 1;
    +  return (n * fact(n-1));
    +}

    SWIG will generate a method fact in the Example module that can be used like so:

    -
    $ irb
    irb(main):001:0> require 'example'
    true
    irb(main):002:0> Example.fact(4)
    24
    +
    $ irb
    +irb(main):001:0> require 'example'
    +true
    +irb(main):002:0> Example.fact(4)
    +24

    36.3.3 Variable Linking

    @@ -541,20 +558,38 @@ one to set it. For example, the following SWIG interface file declares two global variables:

    -
    // SWIG interface file with global variables
    %module example
    ...
    %inline %{
    extern int variable1;
    extern double Variable2;
    %}
    ...
    +
    // SWIG interface file with global variables
    +%module example
    +...
    +%inline %{
    +  extern int variable1;
    +  extern double Variable2;
    +%}
    +...

    Now look at the Ruby interface:

    -
    $ irb
    irb(main):001:0> require 'Example'
    true
    irb(main):002:0> Example.variable1 = 2
    2
    irb(main):003:0> Example.Variable2 = 4 * 10.3
    41.2
    irb(main):004:0> Example.Variable2
    41.2
    +
    $ irb
    +irb(main):001:0> require 'Example'
    +true
    +irb(main):002:0> Example.variable1 = 2
    +2
    +irb(main):003:0> Example.Variable2 = 4 * 10.3
    +41.2
    +irb(main):004:0> Example.Variable2
    +41.2

    If you make an error in variable assignment, you will receive an error message. For example:

    -
    irb(main):005:0> Example.Variable2 = "hello"
    TypeError: no implicit conversion to float from string
    from (irb):5:in `Variable2='
    from (irb):5
    +
    irb(main):005:0> Example.Variable2 = "hello"
    +TypeError: no implicit conversion to float from string
    +from (irb):5:in `Variable2='
    +from (irb):5

    If a variable is declared as const, it @@ -565,7 +600,11 @@ result in an error.

    directive. For example:

    -
    %immutable;
    %inline %{
    extern char *path;
    %}
    %mutable;
    +
    %immutable;
    +%inline %{
    +  extern char *path;
    +%}
    +%mutable;

    The %immutable directive stays in @@ -580,14 +619,24 @@ to the appropriate value. To create a constant, use #define or the %constant directive. For example:

    -
    #define PI 3.14159
    #define VERSION "1.0"

    %constant int FOO = 42;
    %constant const char *path = "/usr/local";

    const int BAR = 32;
    +
    #define PI 3.14159
    +#define VERSION "1.0"
    +
    +%constant int FOO = 42;
    +%constant const char *path = "/usr/local";
    +
    +const int BAR = 32;

    Remember to use the :: operator in Ruby to get at these constant values, e.g.

    -
    $ irb
    irb(main):001:0> require 'Example'
    true
    irb(main):002:0> Example::PI
    3.14159
    +
    $ irb
    +irb(main):001:0> require 'Example'
    +true
    +irb(main):002:0> Example::PI
    +3.14159

    36.3.5 Pointers

    @@ -599,14 +648,16 @@ data objects. So, for example, consider a SWIG interface file containing only the declarations:

    -
    Foo *get_foo();
    void set_foo(Foo *foo);
    +
    Foo *get_foo();
    +void set_foo(Foo *foo);

    For this case, the get_foo() method returns an instance of an internally generated Ruby class:

    -
    irb(main):001:0> foo = Example::get_foo()
    #<SWIG::TYPE_p_Foo:0x402b1654>
    +
    irb(main):001:0> foo = Example::get_foo()
    +#<SWIG::TYPE_p_Foo:0x402b1654>

    A NULL pointer is always represented by @@ -620,7 +671,9 @@ methods (i.e. "getters" and "setters") for all of the struct members. For example, this struct declaration:

    -
    struct Vector {
    double x, y;
    };
    +
    struct Vector {
    +  double x, y;
    +};

    gets wrapped as a Vector class, with @@ -629,7 +682,15 @@ Ruby instance methods x, x=, be used to access structure data from Ruby as follows:

    -
    $ irb
    irb(main):001:0> require 'Example'
    true
    irb(main):002:0> f = Example::Vector.new
    #<Example::Vector:0x4020b268>
    irb(main):003:0> f.x = 10
    nil
    irb(main):004:0> f.x
    10.0
    +
    $ irb
    +irb(main):001:0> require 'Example'
    +true
    +irb(main):002:0> f = Example::Vector.new
    +#<Example::Vector:0x4020b268>
    +irb(main):003:0> f.x = 10
    +nil
    +irb(main):004:0> f.x
    +10.0

    Similar access is provided for unions and the public data @@ -641,7 +702,14 @@ directive (in C++, private may also be used). For example:

    -
    struct Foo {
    ...
    %immutable;
    int x; /* Read-only members */
    char *name;
    %mutable;
    ...
    };
    +
    struct Foo {
    +  ...
    +  %immutable;
    +  int x; /* Read-only members */
    +  char *name;
    +  %mutable;
    +  ...
    +};

    When char * members of a structure are @@ -656,13 +724,17 @@ this is not the behavior you want, you will have to use a typemap this code:

    -
    struct Foo {
    int x[50];
    };
    +
    struct Foo {
    +  int x[50];
    +};

    produces a single accessor function like this:

    -
    int *Foo_x_get(Foo *self) {
    return self->x;
    };
    +
    int *Foo_x_get(Foo *self) {
    +  return self->x;
    +};

    If you want to set an array member, you will need to supply a @@ -675,13 +747,25 @@ structure).

    pointers. For example,

    -
    struct Foo {
    ...
    };

    struct Bar {
    Foo f;
    };
    +
    struct Foo {
    +  ...
    +};
    +
    +struct Bar {
    +  Foo f;
    +};

    generates accessor functions such as this:

    -
    Foo *Bar_f_get(Bar *b) {
    return &b->f;
    }

    void Bar_f_set(Bar *b, Foo *val) {
    b->f = *val;
    }
    +
    Foo *Bar_f_get(Bar *b) {
    +  return &b->f;
    +}
    +
    +void Bar_f_set(Bar *b, Foo *val) {
    +  b->f = *val;
    +}

    36.3.7 C++ classes

    @@ -695,7 +779,17 @@ are wrapped as Ruby singleton methods. So, given the C++ class declaration:

    -
    class List {
    public:
    List();
    ~List();
    int search(char *item);
    void insert(char *item);
    void remove(char *item);
    char *get(int n);
    int length;
    static void print(List *l);
    };
    +
    class List {
    +public:
    +  List();
    +  ~List();
    +  int search(char *item);
    +  void insert(char *item);
    +  void remove(char *item);
    +  char *get(int n);
    +  int length;
    +  static void print(List *l);
    +};

    SWIG would create a List class with:

    @@ -713,7 +807,20 @@ class.
  • In Ruby, these functions are used as follows:

    -
    require 'Example'

    l = Example::List.new

    l.insert("Ale")
    l.insert("Stout")
    l.insert("Lager")
    Example.print(l)
    l.length()
    ----- produces the following output
    Lager
    Stout
    Ale
    3
    +
    require 'Example'
    +
    +l = Example::List.new
    +
    +l.insert("Ale")
    +l.insert("Stout")
    +l.insert("Lager")
    +Example.print(l)
    +l.length()
    +----- produces the following output 
    +Lager
    +Stout
    +Ale
    +3

    36.3.8 C++ Inheritance

    @@ -723,7 +830,13 @@ class. Therefore, if you have classes like this:

    -
    class Parent {
    ...
    };

    class Child : public Parent {
    ...
    };
    +
    class Parent {
    +  ...
    +};
    +
    +class Child : public Parent {
    +  ...
    +};

    those classes are wrapped into a hierarchy of Ruby classes @@ -731,7 +844,20 @@ that reflect the same inheritance structure. All of the usual Ruby utility methods work normally:

    -
    irb(main):001:0> c = Child.new
    #<Bar:0x4016efd4>
    irb(main):002:0> c.instance_of? Child
    true
    irb(main):003:0> b.instance_of? Parent
    false
    irb(main):004:0> b.is_a? Child
    true
    irb(main):005:0> b.is_a? Parent
    true
    irb(main):006:0> Child < Parent
    true
    irb(main):007:0> Child > Parent
    false
    +
    irb(main):001:0> c = Child.new
    +#<Bar:0x4016efd4>
    +irb(main):002:0> c.instance_of? Child
    +true
    +irb(main):003:0> b.instance_of? Parent
    +false
    +irb(main):004:0> b.is_a? Child
    +true
    +irb(main):005:0> b.is_a? Parent
    +true
    +irb(main):006:0> Child < Parent
    +true
    +irb(main):007:0> Child > Parent
    +false

    Furthermore, if you have a function like this:

    @@ -752,7 +878,10 @@ additional base classes are ignored. As an example, consider a SWIG interface file with a declaration like this:

    -
    class Derived : public Base1, public Base2
    {
    ...
    };
    +
    class Derived : public Base1, public Base2
    +{
    +  ...
    +};

    For this case, the resulting Ruby class (Derived) @@ -764,7 +893,8 @@ relationship would fail). When SWIG processes this interface file, you'll see a warning message like:

    -
    example.i:5: Warning 802: Warning for Derived: Base Base2 ignored.
    Multiple inheritance is not supported in Ruby.
    +
    example.i:5: Warning 802: Warning for Derived: Base Base2 ignored.
    +Multiple inheritance is not supported in Ruby.

    Starting with SWIG 1.3.20, the Ruby module for SWIG provides @@ -783,7 +913,10 @@ $ swig -c++ -ruby -minherit example.i contains a declaration like this:

    -
    class Derived : public Base1, public Base2
    {
    ...
    };
    +
    class Derived : public Base1, public Base2
    +{
    +  ...
    +};

    and you run SWIG with the -minherit @@ -797,7 +930,28 @@ modules that the actual instance methods for the classes are defined, i.e.

    -
    class Base1
    module Impl
    # Define Base1 methods here
    end
    include Impl
    end

    class Base2
    module Impl
    # Define Base2 methods here
    end
    include Impl
    end

    class Derived
    module Impl
    include Base1::Impl
    include Base2::Impl
    # Define Derived methods here
    end
    include Impl
    end
    +
    class Base1
    +  module Impl
    +  # Define Base1 methods here
    +  end
    +  include Impl
    +end
    +
    +class Base2
    +  module Impl
    +  # Define Base2 methods here
    +  end
    +  include Impl
    +end
    +
    +class Derived
    +  module Impl
    +  include Base1::Impl
    +  include Base2::Impl
    +  # Define Derived methods here
    +  end
    +  include Impl
    +end

    Observe that after the nested Impl @@ -811,7 +965,9 @@ operation, neither Base1 nor Base2 is a true superclass of Derived anymore:

    -
    obj = Derived.new
    obj.is_a? Base1 # this will return false...
    obj.is_a? Base2 # ... and so will this
    +
    obj = Derived.new
    +obj.is_a? Base1 # this will return false...
    +obj.is_a? Base2 # ... and so will this

    In most cases, this is not a serious problem since objects of @@ -828,38 +984,48 @@ mostly supported by SWIG. For example, if you have two functions like this:

    -
    void foo(int);
    void foo(char *c);
    +
    void foo(int);
    +void foo(char *c);

    You can use them in Ruby in a straightforward manner:

    -
    irb(main):001:0> foo(3) # foo(int)
    irb(main):002:0> foo("Hello") # foo(char *c)
    +
    irb(main):001:0> foo(3) # foo(int)
    +irb(main):002:0> foo("Hello") # foo(char *c)

    Similarly, if you have a class like this,

    -
    class Foo {
    public:
    Foo();
    Foo(const Foo &);
    ...
    };
    +
    class Foo {
    +public:
    +  Foo();
    +  Foo(const Foo &);
    +  ...
    +};

    you can write Ruby code like this:

    -
    irb(main):001:0> f = Foo.new # Create a Foo
    irb(main):002:0> g = Foo.new(f) # Copy f
    +
    irb(main):001:0> f = Foo.new # Create a Foo
    +irb(main):002:0> g = Foo.new(f) # Copy f

    Overloading support is not quite as flexible as in C++. Sometimes there are methods that SWIG can't disambiguate. For example:

    -
    void spam(int);
    void spam(short);
    +
    void spam(int);
    +void spam(short);

    or

    -
    void foo(Bar *b);
    void foo(Bar &b);
    +
    void foo(Bar *b);
    +void foo(Bar &b);

    If declarations such as these appear, you will get a warning @@ -869,21 +1035,26 @@ message like this:

     example.i:12: Warning 509: Overloaded method spam(short) effectively ignored,
     example.i:11: Warning 509: as it is shadowed by spam(int).
    -
    -
    +

    To fix this, you either need to ignore or rename one of the methods. For example:

    -
    %rename(spam_short) spam(short);
    ...
    void spam(int);
    void spam(short); // Accessed as spam_short
    +
    %rename(spam_short) spam(short);
    +...
    +void spam(int); 
    +void spam(short); // Accessed as spam_short

    or

    -
    %ignore spam(short);
    ...
    void spam(int);
    void spam(short); // Ignored
    +
    %ignore spam(short);
    +...
    +void spam(int); 
    +void spam(short); // Ignored

    SWIG resolves overloaded functions and methods using a @@ -903,7 +1074,11 @@ automatically by SWIG and do not require any special treatment on your part. So if your class declares an overloaded addition operator, e.g.

    -
    class Complex {
    ...
    Complex operator+(Complex &);
    ...
    };
    +
    class Complex {
    +  ...
    +  Complex operator+(Complex &);
    +  ...
    +};

    the resulting Ruby class will also support the addition (+) @@ -916,13 +1091,17 @@ to do is give the operator the name of a valid Ruby identifier. For example:

    -
    %rename(add_complex) operator+(Complex &, Complex &);
    ...
    Complex operator+(Complex &, Complex &);
    +
    %rename(add_complex) operator+(Complex &, Complex &);
    +...
    +Complex operator+(Complex &, Complex &);

    Now, in Ruby, you can do this:

    -
    a = Example::Complex.new(2, 3)
    b = Example::Complex.new(4, -1)
    c = Example.add_complex(a, b)
    +
    a = Example::Complex.new(2, 3)
    +b = Example::Complex.new(4, -1)
    +c = Example.add_complex(a, b)

    More details about wrapping C++ operators into Ruby operators @@ -938,13 +1117,29 @@ broken up into submodules or packages. For example, if you have a file like this,

    -
    %module example

    namespace foo {
    int fact(int n);
    struct Vector {
    double x,y,z;
    };
    };
    +
    %module example
    +
    +namespace foo {
    +  int fact(int n);
    +  struct Vector {
    +    double x,y,z;
    +  };
    +};

    it works in Ruby as follows:

    -
    irb(main):001:0> require 'example'
    true
    irb(main):002:0> Example.fact(3)
    6
    irb(main):003:0> v = Example::Vector.new
    #<Example::Vector:0x4016f4d4>
    irb(main):004:0> v.x = 3.4
    3.4
    irb(main):004:0> v.y
    0.0
    +
    irb(main):001:0> require 'example'
    +true
    +irb(main):002:0> Example.fact(3)
    +6
    +irb(main):003:0> v = Example::Vector.new
    +#<Example::Vector:0x4016f4d4>
    +irb(main):004:0> v.x = 3.4
    +3.4
    +irb(main):004:0> v.y
    +0.0

    If your program has more than one namespace, name conflicts @@ -952,7 +1147,15 @@ like this,

    example:

    -
    %rename(Bar_spam) Bar::spam;

    namespace Foo {
    int spam();
    }

    namespace Bar {
    int spam();
    }
    +
    %rename(Bar_spam) Bar::spam;
    +
    +namespace Foo {
    +  int spam();
    +}
    +
    +namespace Bar {
    +  int spam();
    +}

    If you have more than one namespace and your want to keep @@ -971,13 +1174,37 @@ for a particular template instantiation. To do this, you use the %template

    -
    %module example

    %{
    #include "pair.h"
    %}

    template<class T1, class T2>
    struct pair {
    typedef T1 first_type;
    typedef T2 second_type;
    T1 first;
    T2 second;
    pair();
    pair(const T1&, const T2&);
    ~pair();
    };

    %template(Pairii) pair<int,int>;
    +
    %module example
    +
    +%{
    +#include "pair.h"
    +%}
    +
    +template<class T1, class T2>
    +struct pair {
    +  typedef T1 first_type;
    +  typedef T2 second_type;
    +  T1 first;
    +  T2 second;
    +  pair();
    +  pair(const T1&, const T2&);
    +  ~pair();
    +};
    +
    +%template(Pairii) pair<int,int>;

    In Ruby:

    -
    irb(main):001:0> require 'example'
    true
    irb(main):002:0> p = Example::Pairii.new(3, 4)
    #<Example:Pairii:0x4016f4df>
    irb(main):003:0> p.first
    3
    irb(main):004:0> p.second
    4
    +
    irb(main):001:0> require 'example'
    +true
    +irb(main):002:0> p = Example::Pairii.new(3, 4)
    +#<Example:Pairii:0x4016f4df>
    +irb(main):003:0> p.first
    +3
    +irb(main):004:0> p.second
    +4

    36.3.13 C++ Standard Template Library (STL)

    @@ -994,7 +1221,9 @@ of standard C++ templates. For example, suppose the C++ library you're wrapping has a function that expects a vector of floats:

    -
    %module example

    float sum(const std::vector<float>& values);
    +
    %module example
    +
    +float sum(const std::vector<float>& values);

    Rather than go through the hassle of writing an "in" typemap @@ -1003,7 +1232,10 @@ std::vector<float>, you can just use the std_vector.i module from the standard SWIG library:

    -
    %module example

    %include std_vector.i
    float sum(const std::vector<float>& values);
    +
    %module example
    +
    +%include std_vector.i
    +float sum(const std::vector<float>& values);

    Ruby's STL wrappings provide additional methods to make them @@ -1012,7 +1244,17 @@ behave more similarly to Ruby's native classes.

    Thus, you can do, for example:

    -
    v = IntVector.new
    v << 2

    v << 3
    v << 4
    v.each { |x| puts x }

    => 2

    3
    4
    v.delete_if { |x| x == 3 }
    => [2,4]
    +
    v = IntVector.new
    +v << 2
    +v << 3
    +v << 4
    +v.each { |x| puts x }
    +
    +=> 2
    +3
    +4
    +v.delete_if { |x| x == 3 }
    +=> [2,4]

    The SWIG Ruby module provides also the ability for all the STL @@ -1107,7 +1349,7 @@ a << 1 a << 2 a << 3 a -=> [1,2,3] +=> [1,2,3] # Custom sorting behavior defined by a Ruby proc b = IntSet.new( proc { |a,b| a > b } ) @@ -1115,7 +1357,7 @@ b << 1 b << 2 b << 3 b -=>  [3,2,1] +=>  [3,2,1]

    @@ -1211,19 +1453,30 @@ involves the use of a template class that implements operator->() like this:

    -
    template<class T> class SmartPtr {
    ...
    T *operator->();
    ...
    }
    +
    template<class T> class SmartPtr {
    +  ...
    +  T *operator->();
    +  ...
    +}

    Then, if you have a class like this,

    -
    class Foo {
    public:
    int x;
    int bar();
    };
    +
    class Foo {
    +public:
    +  int x;
    +  int bar();
    +};

    A smart pointer would be used in C++ as follows:

    -
    SmartPtr<Foo> p = CreateFoo(); // Created somehow (not shown)
    ...
    p->x = 3; // Foo::x
    int y = p->bar(); // Foo::bar
    +
    SmartPtr<Foo> p = CreateFoo(); // Created somehow (not shown)
    +...
    +p->x = 3; // Foo::x
    +int y = p->bar(); // Foo::bar

    To wrap this in Ruby, simply tell SWIG about the SmartPtr @@ -1232,13 +1485,20 @@ instantiate SmartPtr using %template if necessary. For example:

    -
    %module example
    ...
    %template(SmartPtrFoo) SmartPtr<Foo>;
    ...
    +
    %module example
    +...
    +%template(SmartPtrFoo) SmartPtr<Foo>;
    +...

    Now, in Ruby, everything should just "work":

    -
    irb(main):001:0> p = Example::CreateFoo() # Create a smart-pointer somehow
    #<Example::SmartPtrFoo:0x4016f4df>
    irb(main):002:0> p.x = 3 # Foo::x
    3
    irb(main):003:0> p.bar() # Foo::bar
    +
    irb(main):001:0> p = Example::CreateFoo() # Create a smart-pointer somehow
    +#<Example::SmartPtrFoo:0x4016f4df>
    +irb(main):002:0> p.x = 3 # Foo::x
    +3
    +irb(main):003:0> p.bar() # Foo::bar

    If you ever need to access the underlying pointer returned by @@ -1246,7 +1506,7 @@ if necessary. For example:

    method. For example:

    -
    irb(main):004:0> f = p.__deref__() # Returns underlying Foo *
    +
    irb(main):004:0> f = p.__deref__() # Returns underlying Foo *

    36.3.17 Cross-Language Polymorphism

    @@ -1271,7 +1531,9 @@ directive to indicate what action should be taken when a Ruby exception is raised. The following code should suffice in most cases:

    -
    %feature("director:except") {
    throw Swig::DirectorMethodException($error);
    }
    +
    %feature("director:except") {
    +  throw Swig::DirectorMethodException($error);
    +}

    When this feature is activated, the call to the Ruby instance @@ -1329,7 +1591,22 @@ add a new method of the aliased name that calls the original function. For example:

    -
    class MyArray {
    public:
    // Construct an empty array
    MyArray();

    // Return the size of this array
    size_t length() const;
    };

    %extend MyArray {
    // MyArray#size is an alias for MyArray#length
    size_t size() const {
    return $self->length();
    }
    }
    +
    class MyArray {
    +public:
    +  // Construct an empty array
    +  MyArray();
    +
    +  // Return the size of this array
    +  size_t length() const;
    +};
    +
    +%extend MyArray {
    +  // MyArray#size is an alias for MyArray#length
    +  size_t size() const {
    +    return $self->length();
    +  }
    +}
    + 

    A better solution is to use the %alias @@ -1337,7 +1614,17 @@ directive (unique to SWIG's Ruby module). The previous example could then be rewritten as:

    -
    // MyArray#size is an alias for MyArray#length
    %alias MyArray::length "size";

    class MyArray {
    public:
    // Construct an empty array
    MyArray();

    // Return the size of this array
    size_t length() const;
    };

    +
    // MyArray#size is an alias for MyArray#length
    +%alias MyArray::length "size";
    +
    +class MyArray {
    +public:
    +  // Construct an empty array
    +  MyArray();
    + 
    +  // Return the size of this array
    +  size_t length() const;
    +};

    Multiple aliases can be associated with a method by providing @@ -1382,7 +1669,11 @@ type to Ruby's true or false. For example:

    -
    %rename("is_it_safe?") is_it_safe();

    %typemap(out) int is_it_safe
    "$result = ($1 != 0) ? Qtrue : Qfalse;";

    int is_it_safe();

    +
    %rename("is_it_safe?") is_it_safe();
    +
    +%typemap(out) int is_it_safe "$result = ($1 != 0) ? Qtrue : Qfalse;";
    +
    +int is_it_safe();

    A better solution is to use the %predicate @@ -1390,13 +1681,16 @@ directive (unique to SWIG's Ruby module) to designate a method as a predicate method. For the previous example, this would look like:

    -
    %predicate is_it_safe();

    int is_it_safe();

    +
    %predicate is_it_safe();
    +
    +int is_it_safe();

    This method would be invoked from Ruby code like this:

    -
    irb(main):001:0> Example::is_it_safe?
    true

    +
    irb(main):001:0> Example::is_it_safe?
    +true

    The %predicate directive is implemented @@ -1420,7 +1714,9 @@ directive which is unique to the Ruby module and was introduced in SWIG 1.3.28. For example:

    -
    %bang sort(int arr[]);

    int sort(int arr[]);
    +
    %bang sort(int arr[]);
    +
    +int sort(int arr[]); 

    This method would be invoked from Ruby code like this:

    @@ -1441,7 +1737,14 @@ Features") for more details).

    getter and setter methods. For example:

    -
    class Foo {
    Foo() {}

    int getValue() { return value_; }

    void setValue(int value) { value_ = value; }

    private:
    int value_;
    };
    +
    class Foo {
    +  Foo() {}
    +  int getValue() { return value_; }
    +  void setValue(int value) { value_ = value; }
    +
    +private:
    +  int value_;
    +};

    By default, SWIG will expose these methods to Ruby as get_value @@ -1450,13 +1753,16 @@ methods to be exposed in Ruby as value and value=. That allows the methods to be used like this:

    -
    irb(main):001:0> foo = Foo.new()
    irb(main):002:0> foo.value = 5
    irb(main):003:0> puts foo.value
    +
    irb(main):001:0> foo = Foo.new()
    +irb(main):002:0> foo.value = 5
    +irb(main):003:0> puts foo.value

    This can be done by using the %rename directive:

    -
    %rename("value") Foo::getValue();
    %rename("value=") Foo::setValue(int value);
    +
    %rename("value") Foo::getValue();
    +%rename("value=") Foo::setValue(int value);

    36.5 Input and output parameters

    @@ -1466,20 +1772,42 @@ methods to be exposed in Ruby as value and value=. passed as simple pointers. For example:

    -
    void add(int x, int y, int *result) {
    *result = x + y;
    }
    or
    int sub(int *x, int *y) {
    return *x-*y;
    }
    +
    void add(int x, int y, int *result) {
    +  *result = x + y;
    +}
    +
    + +

    +or +

    + +
    +
    +int sub(int *x, int *y) {
    +  return *x-*y;
    +}

    The easiest way to handle these situations is to use the typemaps.i file. For example:

    -
    %module Example
    %include "typemaps.i"

    void add(int, int, int *OUTPUT);
    int sub(int *INPUT, int *INPUT);
    +
    %module Example
    +%include "typemaps.i"
    +
    +void add(int, int, int *OUTPUT);
    +int sub(int *INPUT, int *INPUT);

    In Ruby, this allows you to pass simple values. For example:

    -
    a = Example.add(3,4)
    puts a
    7
    b = Example.sub(7,4)
    puts b
    3
    +
    a = Example.add(3,4)
    +puts a
    +7
    +b = Example.sub(7,4)
    +puts b
    +3

    Notice how the INPUT parameters allow @@ -1491,26 +1819,39 @@ or OUTPUT, use the %apply directive. For example:

    -
    %module Example
    %include "typemaps.i"

    %apply int *OUTPUT { int *result };
    %apply int *INPUT { int *x, int *y};

    void add(int x, int y, int *result);
    int sub(int *x, int *y);
    +
    %module Example
    +%include "typemaps.i"
    +
    +%apply int *OUTPUT { int *result };
    +%apply int *INPUT { int *x, int *y};
    +
    +void add(int x, int y, int *result);
    +int sub(int *x, int *y);

    If a function mutates one of its parameters like this,

    -
    void negate(int *x) {
    *x = -(*x);
    }
    +
    void negate(int *x) {
    + *x = -(*x);
    +}

    you can use INOUT like this:

    -
    %include "typemaps.i"
    ...
    void negate(int *INOUT);
    +
    %include "typemaps.i"
    +...
    +void negate(int *INOUT);

    In Ruby, a mutated parameter shows up as a return value. For example:

    -
    a = Example.negate(3)
    print a
    -3

    +
    a = Example.negate(3)
    +print a
    +-3

    The most common use of these special typemap rules is to @@ -1518,21 +1859,30 @@ handle functions that return more than one value. For example, sometimes a function returns a result as well as a special error code:

    -
    /* send message, return number of bytes sent, success code, and error_code */
    int send_message(char *text, int *success, int *error_code);
    +
    /* send message, return number of bytes sent, success code, and error_code */
    +int send_message(char *text, int *success, int *error_code);

    To wrap such a function, simply use the OUTPUT rule above. For example:

    -
    %module example
    %include "typemaps.i"
    ...
    int send_message(char *, int *OUTPUT, int *OUTPUT);
    +
    %module example
    +%include "typemaps.i"
    +...
    +int send_message(char *, int *OUTPUT, int *OUTPUT);

    When used in Ruby, the function will return an array of multiple values.

    -
    bytes, success, error_code = send_message("Hello World")
    if not success
    print "error #{error_code} : in send_message"
    else
    print "Sent", bytes
    end
    +
    bytes, success, error_code = send_message("Hello World")
    +if not success
    +  print "error #{error_code} : in send_message"
    +else
    +  print "Sent", bytes
    +end

    Another way to access multiple return values is to use the %apply @@ -1541,13 +1891,17 @@ related to SWIG as OUTPUT values through the use of %apply

    -
    %module Example
    %include "typemaps.i"
    %apply int *OUTPUT { int *rows, int *columns };
    ...
    void get_dimensions(Matrix *m, int *rows, int*columns);
    +
    %module Example
    +%include "typemaps.i"
    +%apply int *OUTPUT { int *rows, int *columns };
    +...
    +void get_dimensions(Matrix *m, int *rows, int*columns);

    In Ruby:

    -
    r, c = Example.get_dimensions(m)
    +
    r, c = Example.get_dimensions(m)

    36.6 Exception handling

    @@ -1563,7 +1917,44 @@ Features contains more details, but suppose you have a C++ class like the following :

    -
    class DoubleArray {
    private:
    int n;
    double *ptr;
    public:
    // Create a new array of fixed size
    DoubleArray(int size) {
    ptr = new double[size];
    n = size;
    }

    // Destroy an array
    ~DoubleArray() {
    delete ptr;
    }

    // Return the length of the array
    int length() {
    return n;
    }

    // Get an array item and perform bounds checking.
    double getitem(int i) {
    if ((i >= 0) && (i < n))
    return ptr[i];
    else
    throw RangeError();
    }

    // Set an array item and perform bounds checking.
    void setitem(int i, double val) {
    if ((i >= 0) && (i < n))
    ptr[i] = val;
    else {
    throw RangeError();
    }
    }
    };
    +
    class DoubleArray {
    +private:
    +  int n;
    +  double *ptr;
    +public:
    +  // Create a new array of fixed size
    +  DoubleArray(int size) {
    +    ptr = new double[size];
    +    n = size;
    +  }
    + 
    +  // Destroy an array
    +  ~DoubleArray() {
    +    delete ptr;
    +  } 
    + 
    +  // Return the length of the array
    +  int length() {
    +    return n;
    +  }
    + 
    +  // Get an array item and perform bounds checking.
    +  double getitem(int i) {
    +    if ((i >= 0) && (i < n))
    +      return ptr[i];
    +    else
    +      throw RangeError();
    +  }
    + 
    +  // Set an array item and perform bounds checking.
    +  void setitem(int i, double val) {
    +    if ((i >= 0) && (i < n))
    +      ptr[i] = val;
    +    else {
    +      throw RangeError();
    +    }
    +  }
    +};

    Since several methods in this class can throw an exception @@ -1571,7 +1962,19 @@ for an out-of-bounds access, you might want to catch this in the Ruby extension by writing the following in an interface file:

    -
    %exception {
    try {
    $action
    }
    catch (const RangeError&) {
    static VALUE cpperror = rb_define_class("CPPError", rb_eStandardError);
    rb_raise(cpperror, "Range error.");
    }
    }

    class DoubleArray {
    ...
    };
    +
    %exception {
    +  try {
    +    $action
    +  }
    +  catch (const RangeError&) {
    +    static VALUE cpperror = rb_define_class("CPPError", rb_eStandardError);
    +    rb_raise(cpperror, "Range error.");
    +  }
    +}
    +
    +class DoubleArray {
    +  ...
    +};

    The exception handling code is inserted directly into @@ -1586,7 +1989,23 @@ consider refining the exception handler to only apply to specific methods like this:

    -
    %exception getitem {
    try {
    $action
    }
    catch (const RangeError&) {
    static VALUE cpperror = rb_define_class("CPPError", rb_eStandardError);
    rb_raise(cpperror, "Range error in getitem.");
    }
    }

    %exception setitem {
    try {
    $action
    }
    catch (const RangeError&) {
    static VALUE cpperror = rb_define_class("CPPError", rb_eStandardError);
    rb_raise(cpperror, "Range error in setitem.");
    }
    }
    +
    %exception getitem {
    +  try {
    +    $action
    +  } catch (const RangeError&) {
    +    static VALUE cpperror = rb_define_class("CPPError", rb_eStandardError);
    +    rb_raise(cpperror, "Range error in getitem.");
    +  }
    +}
    + 
    +%exception setitem {
    +  try {
    +    $action
    +  } catch (const RangeError&) {
    +    static VALUE cpperror = rb_define_class("CPPError", rb_eStandardError);
    +    rb_raise(cpperror, "Range error in setitem.");
    +  }
    +}

    In this case, the exception handler is only attached to @@ -1612,12 +2031,23 @@ after the C++ class' constructor was called. 

    For example, this yields the class over after its construction: -
    -

    -
    class Window
    {
    public:
    Window(int x, int y, int w, int h);
    // .... other methods here ....
    };

    // Add support for yielding self in the Class' constructor.
    %exception Window::Window {
    $action
    if (rb_block_given_p()) {
    rb_yield(self);
    }
    }
    +
    class Window
    +{
    +public:
    + Window(int x, int y, int w, int h);
    +// .... other methods here ....
    +};
    +
    +// Add support for yielding self in the Class' constructor.
    +%exception Window::Window {
    +  $action
    +  if (rb_block_given_p()) {
    +    rb_yield(self);
    +  }
    +}

    Then, in ruby, it can be used like:

    @@ -1630,8 +2060,6 @@ Window.new(0,0,360,480) { |w| -
    -

    For other methods, you can usually use a dummy parameter with a special in typemap, like:

    @@ -1825,17 +2253,30 @@ This allows C++ exceptions to be directly mapped to Ruby exceptions, providing for a more natural integration between C++ code and Ruby code.

    -
    	%exceptionclass CustomError;

    %inline %{
    class CustomError { };

    class Foo {
    public:
    void test() { throw CustomError; }
    };
    }
    +
    %exceptionclass CustomError;
    +
    +%inline %{
    +  class CustomError { };
    +
    +  class Foo { 
    +  public:
    +    void test() { throw CustomError; }
    +  };
    +%}

    From Ruby you can now call this method like this:

    -
    foo = Foo.new
    begin
    foo.test()
    rescue CustomError => e
    puts "Caught custom error"
    end
    +
    foo = Foo.new
    +begin
    +  foo.test()
    +rescue CustomError => e
    +  puts "Caught custom error"
    +end 

    For another example look at swig/Examples/ruby/exception_class. -

    36.7 Typemaps

    @@ -1882,7 +2323,11 @@ patterns that the typemap will match. The general form of this list is as follows:

    -
    typelist : typepattern [, typepattern, typepattern, ... ] ;

    typepattern : type [ (parms) ]
    | type name [ (parms) ]
    | ( typelist ) [ (parms) ]
    +
    typelist : typepattern [, typepattern, typepattern, ... ] ;
    +
    +typepattern : type [ (parms) ]
    +  | type name [ (parms) ]
    +  | ( typelist ) [ (parms) ]

    Each type pattern is either a simple type, a simple type and @@ -1895,14 +2340,25 @@ will be explained shortly.

    typemap. It can take any one of the following forms:

    -
    code : { ... }
    | " ... "
    | %{ ... %}
    +
    code : { ... }
    +  | " ... "
    +  | %{ ... %}

    For example, to convert integers from Ruby to C, you might define a typemap like this:

    -
    %module example

    %typemap(in) int {
    $1 = (int) NUM2INT($input);
    printf("Received an integer : %d\n",$1);
    }

    %inline %{
    extern int fact(int n);
    %}
    +
    %module example
    +
    +%typemap(in) int {
    +  $1 = (int) NUM2INT($input);
    +  printf("Received an integer : %d\n",$1);
    +}
    +
    +%inline %{
    +  extern int fact(int n);
    +%}

    Typemaps are always associated with some specific aspect of @@ -1918,7 +2374,9 @@ The $input variable is the input Ruby object.

    following sample code:

    -
    require 'example'

    puts Example.fact(6)
    +
    require 'example'
    +
    +puts Example.fact(6)

    prints the result:

    @@ -1935,7 +2393,16 @@ the int datatype. You can refine this by supplying an optional parameter name. For example:

    -
    %module example

    %typemap(in) int n {
    $1 = (int) NUM2INT($input);
    printf("n = %d\n",$1);
    }

    %inline %{
    extern int fact(int n);
    %}
    +
    %module example
    +
    +%typemap(in) int n {
    +  $1 = (int) NUM2INT($input);
    +  printf("n = %d\n",$1);
    +}
    +
    +%inline %{
    +  extern int fact(int n);
    +%}

    In this case, the typemap code is only attached to arguments @@ -1950,7 +2417,13 @@ addition, the typemap system follows typedef declarations. For example:

    -
    %typemap(in) int n {
    $1 = (int) NUM2INT($input);
    printf("n = %d\n",$1);
    }

    typedef int Integer;
    extern int fact(Integer n); // Above typemap is applied
    +
    %typemap(in) int n {
    +  $1 = (int) NUM2INT($input);
    +  printf("n = %d\n",$1);
    +}
    +
    +typedef int Integer;
    +extern int fact(Integer n); // Above typemap is applied

    However, the matching of typedef only @@ -1961,7 +2434,12 @@ it is not applied to arguments of type int.

    arguments. For example:

    -
    %typemap(in) (char *str, int len) {
    $1 = StringValuePtr($input);
    $2 = (int) RSTRING($input)->len;
    };

    int count(char c, char *str, int len);
    +
    %typemap(in) (char *str, int len) {
    +  $1 = StringValuePtr($input);
    +  $2 = (int) RSTRING($input)->len;
    +};
    +
    +int count(char c, char *str, int len);

    When a multi-argument typemap is defined, the arguments are @@ -1969,7 +2447,8 @@ always handled as a single Ruby object. This allows the function count to be used as follows (notice how the length parameter is omitted):

    -
    puts Example.count('o','Hello World')
    2
    +
    puts Example.count('o','Hello World')
    +2

    36.7.2 Typemap scope

    @@ -1980,7 +2459,20 @@ declarations that follow. A typemap may be redefined for different sections of an input file. For example:

    -
    // typemap1
    %typemap(in) int {
    ...
    }

    int fact(int); // typemap1
    int gcd(int x, int y); // typemap1

    // typemap2
    %typemap(in) int {
    ...
    }

    int isprime(int); // typemap2
    +
    // typemap1
    +%typemap(in) int {
    +  ...
    +}
    +
    +int fact(int); // typemap1
    +int gcd(int x, int y); // typemap1
    +
    +// typemap2
    +%typemap(in) int {
    +  ...
    +}
    +
    +int isprime(int); // typemap2

    One exception to the typemap scoping rules pertains to the @@ -1991,7 +2483,18 @@ block are subject to the typemap rules that are in effect at the point where the class itself is defined. For example:

    -
    class Foo {
    ...
    };

    %typemap(in) int {
    ...
    }

    %extend Foo {
    int blah(int x); // typemap has no effect. Declaration is attached to Foo which
    // appears before the %typemap declaration.
    };
    +
    class Foo {
    +  ...
    +};
    +
    +%typemap(in) int {
    +  ...
    +}
    +
    +%extend Foo {
    +  int blah(int x); // typemap has no effect. Declaration is attached to Foo which 
    +  // appears before the %typemap declaration.
    +};

    36.7.3 Copying a typemap

    @@ -2000,27 +2503,31 @@ where the class itself is defined. For example:

    A typemap is copied by using assignment. For example:

    -
    %typemap(in) Integer = int;
    +
    %typemap(in) Integer = int;

    or this:

    -
    %typemap(in) Integer, Number, int32_t = int;
    +
    %typemap(in) Integer, Number, int32_t = int;

    Types are often managed by a collection of different typemaps. For example:

    -
    %typemap(in) int { ... }
    %typemap(out) int { ... }
    %typemap(varin) int { ... }
    %typemap(varout) int { ... }
    +
    %typemap(in) int { ... }
    +%typemap(out) int { ... }
    +%typemap(varin) int { ... }
    +%typemap(varout) int { ... }

    To copy all of these typemaps to a new type, use %apply. For example:

    -
    %apply int { Integer }; // Copy all int typemaps to Integer
    %apply int { Integer, Number }; // Copy all int typemaps to both Integer and Number
    +
    %apply int { Integer }; // Copy all int typemaps to Integer
    +%apply int { Integer, Number }; // Copy all int typemaps to both Integer and Number

    The patterns for %apply follow the same @@ -2028,7 +2535,8 @@ rules as for %typemap. For example:

    -
    %apply int *output { Integer *output }; // Typemap with name
    %apply (char *buf, int len) { (char *buffer, int size) }; // Multiple arguments
    +
    %apply int *output { Integer *output }; // Typemap with name
    +%apply (char *buf, int len) { (char *buffer, int size) }; // Multiple arguments

    36.7.4 Deleting a typemap

    @@ -2038,14 +2546,17 @@ rules as for example:

    -
    %typemap(in) int; // Clears typemap for int
    %typemap(in) int, long, short; // Clears typemap for int, long, short
    %typemap(in) int *output;
    +
    %typemap(in) int; // Clears typemap for int
    +%typemap(in) int, long, short; // Clears typemap for int, long, short
    +%typemap(in) int *output; 

    The %clear directive clears all typemaps for a given type. For example:

    -
    %clear int; // Removes all types for int
    %clear int *output, long *output;
    +
    %clear int; // Removes all types for int
    +%clear int *output, long *output;

    Note: Since SWIG's default behavior is @@ -2060,7 +2571,24 @@ typemaps immediately after the clear operation.

    within a C++ namespace, and within a C++ class. For example:

    -
    %typemap(in) int {
    ...
    }

    namespace std {
    class string;
    %typemap(in) string {
    ...
    }
    }

    class Bar {
    public:
    typedef const int & const_reference;
    %typemap(out) const_reference {
    ...
    }
    };
    +
    %typemap(in) int {
    +  ...
    +}
    +
    +namespace std {
    +  class string;
    +  %typemap(in) string {
    +    ...
    +  }
    +}
    +
    +class Bar {
    +public:
    +  typedef const int & const_reference;
    +  %typemap(out) const_reference {
    +    ...
    +  }
    +};

    When a typemap appears inside a namespace or class, it stays @@ -2068,14 +2596,31 @@ in effect until the end of the SWIG input (just like before). However, the typemap takes the local scope into account. Therefore, this code

    -
    namespace std {
    class string;
    %typemap(in) string {
    ...
    }
    }
    +
    namespace std {
    +  class string;
    +  %typemap(in) string {
    +    ...
    +  }
    +}

    is really defining a typemap for the type std::string. You could have code like this:

    -
    namespace std {
    class string;
    %typemap(in) string { /* std::string */
    ...
    }
    }

    namespace Foo {
    class string;
    %typemap(in) string { /* Foo::string */
    ...
    }
    }
    +
    namespace std {
    +  class string;
    +  %typemap(in) string { /* std::string */
    +  ...
    +  }
    +}
    +
    +namespace Foo {
    +  class string;
    +  %typemap(in) string { /* Foo::string */
    +  ...
    +  }
    +}

    In this case, there are two completely distinct typemaps that @@ -2104,7 +2649,9 @@ function arguments. For example:

    -
    %typemap(in) int {
    $1 = NUM2INT($input);
    }
    +
    %typemap(in) int {
    +  $1 = NUM2INT($input);
    +}

    The following special variables are available:

    @@ -2153,7 +2700,10 @@ it can be used to implement customized conversions.

    arguments to be specified. For example:

    -
    // Ignored argument.
    %typemap(in, numinputs=0) int *out (int temp) {
    $1 = &temp;
    }
    +
    // Ignored argument.
    +%typemap(in, numinputs=0) int *out (int temp) {
    +  $1 = &temp;
    +}

    At this time, only zero or one arguments may be converted.

    @@ -2166,7 +2716,9 @@ functions and methods. It merely checks an argument to see whether or not it matches a specific type. For example:

    -
    %typemap(typecheck,precedence=SWIG_TYPECHECK_INTEGER) int {
    $1 = FIXNUM_P($input) ? 1 : 0;
    }
    +
    %typemap(typecheck,precedence=SWIG_TYPECHECK_INTEGER) int {
    +  $1 = FIXNUM_P($input) ? 1 : 0;
    +}

    For typechecking, the $1 variable is always a simple integer @@ -2184,11 +2736,11 @@ on "Typemaps and Overloading."

    Converts return value of a C function to a Ruby object.

    -

    -%typemap(out) int {
    -   $result = INT2NUM( $1 );
    -}
    -
    +
    +
    %typemap(out) int {
    +  $result = INT2NUM( $1 );
    +}
    +

    The following special variables are available.

    @@ -2238,7 +2790,10 @@ normally necessary, but might be useful in highly specialized applications. For example:

    -
    // Set argument to NULL before any conversion occurs
    %typemap(arginit) int *data {
    $1 = NULL;
    }
    +
    // Set argument to NULL before any conversion occurs
    +%typemap(arginit) int *data {
    +  $1 = NULL;
    +}

    36.7.6.5 "default" typemap

    @@ -2248,7 +2803,11 @@ applications. For example:

    default argument. For example:

    -
    %typemap(default) int flags {
    $1 = DEFAULT_FLAGS;
    }
    ...
    int foo(int x, int y, int flags);
    +
    %typemap(default) int flags {
    +  $1 = DEFAULT_FLAGS;
    +}
    +...
    +int foo(int x, int y, int flags);

    The primary use of this typemap is to either change the @@ -2270,7 +2829,11 @@ during argument conversion. The typemap is applied after arguments have been converted. For example:

    -
    %typemap(check) int positive {
    if ($1 <= 0) {
    SWIG_exception(SWIG_ValueError,"Expected positive value.");
    }
    }
    +
    %typemap(check) int positive {
    +  if ($1 <= 0) {
    +    SWIG_exception(SWIG_ValueError,"Expected positive value.");
    +  }
    +}

    36.7.6.7 "argout" typemap

    @@ -2283,7 +2846,15 @@ combined with an "in" typemap---possibly to ignore the input value. For example:

    -
    /* Set the input argument to point to a temporary variable */
    %typemap(in, numinputs=0) int *out (int temp) {
    $1 = &temp;
    }

    %typemap(argout, fragment="output_helper") int *out {
    // Append output value $1 to $result (assuming a single integer in this case)
    $result = output_helper( $result, INT2NUM(*$1) );
    }
    +
    /* Set the input argument to point to a temporary variable */
    +%typemap(in, numinputs=0) int *out (int temp) {
    + $1 = &temp;
    +}
    +
    +%typemap(argout, fragment="output_helper") int *out {
    +  // Append output value $1 to $result (assuming a single integer in this case)
    +  $result = output_helper( $result, INT2NUM(*$1) );
    +}

    The following special variables are available.

    @@ -2329,7 +2900,15 @@ usually cleans up argument resources allocated by the "in" typemap. For example:

    -
    // Get a list of integers
    %typemap(in) int *items {
    int nitems = Length($input);
    $1 = (int *) malloc(sizeof(int)*nitems);
    }
    // Free the list
    %typemap(freearg) int *items {
    free($1);
    }
    +
    // Get a list of integers
    +%typemap(in) int *items {
    +  int nitems = Length($input); 
    +  $1 = (int *) malloc(sizeof(int)*nitems);
    +}
    +// Free the list 
    +%typemap(freearg) int *items {
    +  free($1);
    +}

    The "freearg" typemap inserted at the end of the wrapper @@ -2346,7 +2925,17 @@ directive and is used to deallocate memory used by the return result of a function. For example:

    -
    %typemap(newfree) string * {
    delete $1;
    }
    %typemap(out) string * {
    $result = PyString_FromString($1->c_str());
    }
    ...

    %newobject foo;
    ...
    string *foo();
    +
    %typemap(newfree) string * {
    +  delete $1;
    +}
    +%typemap(out) string * {
    +  $result = PyString_FromString($1->c_str());
    +}
    +...
    +
    +%newobject foo;
    +...
    +string *foo();

    See Object @@ -2361,7 +2950,9 @@ typically used to handle array members and other special cases. For example:

    -
    %typemap(memberin) int [4] {
    memmove($1, $input, 4*sizeof(int));
    }
    +
    %typemap(memberin) int [4] {
    +  memmove($1, $input, 4*sizeof(int));
    +}

    It is rarely necessary to write "memberin" typemaps---SWIG @@ -2395,7 +2986,11 @@ other typemaps as it is based around the exception type rather than the type of a parameter or variable. For example:

    -
    %typemap(throws) const char * %{
    rb_raise(rb_eRuntimeError, $1);
    SWIG_fail;
    %}
    void bar() throw (const char *);
    +
    %typemap(throws) const char * %{
    +  rb_raise(rb_eRuntimeError, $1);
    +  SWIG_fail;
    +%}
    +void bar() throw (const char *);

    As can be seen from the generated code below, SWIG generates @@ -2403,7 +2998,15 @@ an exception handler with the catch block comprising the "throws" typemap content.

    -
    ...
    try {
    bar();
    }
    catch(char const *_e) {
    rb_raise(rb_eRuntimeError, _e);
    SWIG_fail;
    }
    ...
    +
    ...
    +try {
    +  bar();
    +}
    +catch(char const *_e) {
    +  rb_raise(rb_eRuntimeError, _e);
    +  SWIG_fail;
    +}
    +...

    Note that if your methods do not have an exception @@ -2420,11 +3023,11 @@ of the "in" typemap, making its typemap rule often similar to the "out" typemap.

    -

    -%typemap(directorin) int {
    -     $result = INT2NUM($1);
    -}
    -
    +
    +%typemap(directorin) int {
    +  $result = INT2NUM($1);
    +}
    +

    The following special variables are available.

    @@ -2685,8 +3288,8 @@ across multiple languages.

    RUBYSWIGRUBYSWIG
    Prefix_PrintPrintprefix_printPrint
    command:cmdSWIG Interface library file
    std::auto_ptr memory std_auto_ptr.i
    std::deque deque std_deque.i
    std::list list std_list.i
    std::map map std_map.i
    -gccgo Generate code for gccgo. The default is to generate code for - 6g/8g/5g.
    -use-shlibTell SWIG to emit code that uses a shared library. This is only + meaningful for the gc compiler, which needs to know at compile time + whether a shared library will be used.
    -soname %lt;name%gt; Set the runtime name of the shared library that the dynamic linker should include at runtime. The default is the package name with ".so" appended. This is only used when generating code for - 6g/8g/5g; when using gccgo, the equivalent name will be taken from - the -soname option passed to the linker.
    -go-pkgpath <pkgpath>When generating code for gccgo, set the pkgpath to use. This + corresponds to the -fgo-pkgpath option to gccgo.
    -go-prefix <prefix> When generating code for gccgo, set the prefix to use. This - corresponds to the -fgo-prefix option to gccgo.
    -long-type-size <s>Set the size for the C/C++ type long. This controls - whether long is converted to the Go type int32 - or int64. The <s> argument should be 32 or 64.

    22.2.2 Go Output Files

    @@ -501,12 +494,12 @@ uses a given C/C++ type. long -int32 or int64, depending on -long-type-size +int64 unsigned long -uint32 or uint64, depending on -long-type-size +uint64 diff --git a/Examples/test-suite/go/template_opaque_runme.go b/Examples/test-suite/go/template_opaque_runme.go index c22b71946..201f7ba16 100644 --- a/Examples/test-suite/go/template_opaque_runme.go +++ b/Examples/test-suite/go/template_opaque_runme.go @@ -3,7 +3,7 @@ package main import "./template_opaque" func main() { - v := template_opaque.NewOpaqueVectorType(10) + v := template_opaque.NewOpaqueVectorType(int64(10)) template_opaque.FillVector(v) } diff --git a/Examples/test-suite/go/wrapmacro_runme.go b/Examples/test-suite/go/wrapmacro_runme.go index 4d3791be8..dc7e7bf5b 100644 --- a/Examples/test-suite/go/wrapmacro_runme.go +++ b/Examples/test-suite/go/wrapmacro_runme.go @@ -5,7 +5,7 @@ import "./wrapmacro" func main() { a := 2 b := -1 - wrapmacro.Maximum(a, b) - wrapmacro.Maximum(a/7.0, -b*256) + wrapmacro.Maximum(int64(a), int64(b)) + wrapmacro.Maximum(float64(a/7.0), float64(-b*256)) wrapmacro.GUINT16_SWAP_LE_BE_CONSTANT(1) } diff --git a/Lib/go/go.swg b/Lib/go/go.swg index 3408f422e..b9086caac 100644 --- a/Lib/go/go.swg +++ b/Lib/go/go.swg @@ -14,15 +14,8 @@ %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(gotype) long, const long & "int32" -%typemap(gotype) unsigned long, const unsigned long & "uint32" -#elif SWIGGO_LONG_TYPE_SIZE == 64 %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(gotype) long long, const long long & "int64" %typemap(gotype) unsigned long long, const unsigned long long & "uint64" %typemap(gotype) float, const float & "float32" @@ -163,11 +156,7 @@ /* The size_t type. */ -#if SWIGGO_LONG_TYPE_SIZE == 32 -%typemap(gotype) size_t, const size_t & %{int%} -#else %typemap(gotype) size_t, const size_t & %{int64%} -#endif %typemap(in) size_t %{ $1 = (size_t)$input; %} @@ -486,32 +475,16 @@ 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 & "" diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 6db099662..3dec6503b 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -30,8 +30,6 @@ class GO:public Language { bool use_shlib; // Name of shared library to import. String *soname; - // Size in bits of the C type "long". - int long_type_size; // Size in bits of the Go type "int". 0 if not specified. int intgo_type_size; @@ -96,7 +94,6 @@ public: pkgpath_option(NULL), use_shlib(false), soname(NULL), - long_type_size(32), intgo_type_size(0), f_c_begin(NULL), f_go_begin(NULL), @@ -184,12 +181,8 @@ private: Swig_arg_error(); } } else if (strcmp(argv[i], "-longsize") == 0) { + // Ignore for backward compatibility. 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"); - Swig_arg_error(); - } Swig_mark_arg(i); Swig_mark_arg(i + 1); ++i; @@ -227,12 +220,6 @@ private: 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); - } - // This test may be removed in the future, when we can assume that // everybody has upgraded to Go 1.1. The code below is prepared // for this test to simply be taken out. @@ -4967,7 +4954,6 @@ Go Options (available with -go)\n\ -gccgo - Generate code for gccgo rather than 6g/8g\n\ -go-pkgpath

    - Like gccgo -fgo-pkgpath option\n\ -go-prefix

    - Like gccgo -fgo-prefix option\n\ - -longsize - Set size of C/C++ long type--32 or 64 bits\n\ -intgosize - Set size of Go int type--32 or 64 bits\n\ -package - Set name of the Go package to \n\ -use-shlib - Force use of a shared library\n\ From 8dba8b1fde7f3234c816840b5a376d74ebd5a181 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 18 Dec 2013 11:03:39 -0800 Subject: [PATCH 0832/1160] Go: Don't require that Go environment variables be set when running examples or testsuite. --- CHANGES.current | 5 +++++ Examples/Makefile.in | 8 ++++---- Examples/test-suite/go/Makefile.in | 6 +++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index f7a882aa1..f9934b49d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-12-18: ianlancetaylor + [Go] Don't require that Go environment variables be set + when running examples or testsuite when using Go 1 or + later. + 2013-12-17: ianlancetaylor [Go] Remove -longsize option (for backward compatibility, ignore it if seen). diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 0169f26a7..d8ebb80e3 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1590,7 +1590,7 @@ go: $(SRCS) fi $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(GOSRCS) if ! $(GOGCC) ; then \ - $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT}/pkg/$${GOOS}_$${GOARCH} $(GOCSRCS); \ + $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`} $(GOCSRCS); \ rm -f $(GOPACKAGE); \ if $(GO12); then \ $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \ @@ -1613,7 +1613,7 @@ go_cpp: $(SRCS) fi $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(GOSRCS) if ! $(GOGCC) ; then \ - $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT}/pkg/$${GOOS}_$${GOARCH} $(GOCSRCS); \ + $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`} $(GOCSRCS); \ rm -f $(GOPACKAGE); \ if $(GO12); then \ $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \ @@ -1633,7 +1633,7 @@ go_run: runme.go elif $(GO12); then \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CC) -extldflags "$(CFLAGS)" -o runme runme.$(GOOBJEXT); \ else \ - $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o runme runme.$(GOOBJEXT); \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o runme runme.$(GOOBJEXT); \ fi env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme $(RUNPIPE) @@ -1648,7 +1648,7 @@ go_run_cpp: runme.go elif $(GO12); then \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o runme runme.$(GOOBJEXT); \ else \ - $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o runme runme.$(GOOBJEXT); \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o runme runme.$(GOOBJEXT); \ fi env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme $(RUNPIPE) diff --git a/Examples/test-suite/go/Makefile.in b/Examples/test-suite/go/Makefile.in index 1b4887e23..35937bcdb 100644 --- a/Examples/test-suite/go/Makefile.in +++ b/Examples/test-suite/go/Makefile.in @@ -63,7 +63,7 @@ run_testcase = \ elif $(GO12); then \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CC) -extldflags "$(CFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ else \ - $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ fi && \ env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \ fi @@ -76,7 +76,7 @@ run_testcase_cpp = \ elif $(GO12); then \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ else \ - $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ fi && \ env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \ fi @@ -90,7 +90,7 @@ run_multi_testcase = \ elif $(GO12); then \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ else \ - $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ fi && \ env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \ fi From b4fef06c42044441c49888f0a96eb94315f98380 Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Thu, 19 Dec 2013 02:11:22 +0400 Subject: [PATCH 0833/1160] fixed %template within %extend, test added fixed language symbol table nested classes name separator, test added fixed %feature "flatnested" working with %extend fixed Swig_offset_string for empty string added simple template to save/restore values in current scope (readability reasons) --- .../java/template_nested_runme.java | 1 + Examples/test-suite/nested_class.i | 6 +++++ Examples/test-suite/template_nested.i | 8 ++++++- Source/CParse/parser.y | 22 +++++++++---------- Source/Modules/allocate.cxx | 10 ++++----- Source/Modules/csharp.cxx | 4 ++-- Source/Modules/java.cxx | 3 +-- Source/Modules/lang.cxx | 17 +++++--------- Source/Modules/nested.cxx | 2 ++ Source/Modules/swigmod.h | 9 ++++++++ Source/Modules/typepass.cxx | 4 +--- Source/Swig/misc.c | 8 +++---- 12 files changed, 55 insertions(+), 39 deletions(-) diff --git a/Examples/test-suite/java/template_nested_runme.java b/Examples/test-suite/java/template_nested_runme.java index 422e7ea9e..4cca9f34a 100644 --- a/Examples/test-suite/java/template_nested_runme.java +++ b/Examples/test-suite/java/template_nested_runme.java @@ -29,6 +29,7 @@ public class template_nested_runme { OuterClass.T_OuterClassInner2NormalClass inner2 = new OuterClass.T_OuterClassInner2NormalClass(); inner2.setEmbeddedVar(2); OuterClass.T_OuterClassInner2NormalClass inner22 = new OuterClass().useInner2Again(inner2); + OuterClass.T_OuterClassInner1Double inner3 = new OuterClass.T_OuterClassInner1Double(); } } diff --git a/Examples/test-suite/nested_class.i b/Examples/test-suite/nested_class.i index 0d418192d..282875531 100644 --- a/Examples/test-suite/nested_class.i +++ b/Examples/test-suite/nested_class.i @@ -167,10 +167,16 @@ struct Outer { /////////////////////////////////////////// typedef struct InnerSameName { Integer x; + struct InnerSameName2 {}; } InnerSameName; InnerSameName* makeInnerSameName() { return 0; } }; +#if defined(SWIGCSHARP) || defined (SWIGJAVA) +// place a class with the same name as in Outer in global scope, to test language symbol table +class InnerSameName {}; +class InnerSameName2 {}; +#endif %} // Ignore nested struct instance diff --git a/Examples/test-suite/template_nested.i b/Examples/test-suite/template_nested.i index bbca9502c..c33018e0f 100644 --- a/Examples/test-suite/template_nested.i +++ b/Examples/test-suite/template_nested.i @@ -30,6 +30,7 @@ namespace ns { %} %template(T_NormalTemplateNormalClass) ns::NormalTemplate; %template(T_NormalTemplateInt) ns::NormalTemplate; +%template(T_NormalTemplateDouble) ns::NormalTemplate; %inline %{ namespace ns { @@ -70,6 +71,9 @@ namespace ns { }; Inner2 useInner2(const Inner2& inner) { return inner; } Inner2 useInner2Again(const Inner2& inner) { return inner; } +#ifdef SWIG + %template(T_OuterClassInner1Double) Inner1; +#endif int iii; }; struct ABC { @@ -105,8 +109,10 @@ namespace ns { NestedStruct useNestedStruct(const NestedStruct& inner) { return inner; } }; } - %} +%extend ns::OuterClass { + %template(T_OuterClassInner2Double) Inner2; +} %template(T_OuterTMethodNormalClass) ns::OuterClass::InnerTMethod; %template(T_TemplateFuncs1Int) ns::TemplateFuncs::templateMethod1; diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index ef5aa6ef4..40d853387 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1311,16 +1311,18 @@ static void default_arguments(Node *n) { } /* ----------------------------------------------------------------------------- - * tag_nodes() + * mark_nodes_as_extend() * - * Used by the parser to mark subtypes with extra information. + * Used by the %extend to mark subtypes with "feature:extend". + * template instances declared within %extend are skipped * ----------------------------------------------------------------------------- */ -static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { - while (n) { - Setattr(n, attrname, value); - tag_nodes(firstChild(n), attrname, value); - n = nextSibling(n); +static void mark_nodes_as_extend(Node *n) { + for (; n; n = nextSibling(n)) { + if (Getattr(n, "template") && Strcmp(nodeType(n), "class") == 0) + continue; + Setattr(n, "feature:extend", "1"); + mark_nodes_as_extend(firstChild(n)); } } @@ -1648,9 +1650,7 @@ extend_directive : EXTEND options idcolon LBRACE { clsname = make_class_name($3); Setattr($$,"name",clsname); - /* Mark members as extend */ - - tag_nodes($6,"feature:extend",(char*) "1"); + mark_nodes_as_extend($6); if (current_class) { /* We add the extension to the previously defined class */ appendChild($$,$6); @@ -4267,7 +4267,7 @@ cpp_members : cpp_member cpp_members { } } cpp_members RBRACE cpp_members { $$ = new_node("extend"); - tag_nodes($4,"feature:extend",(char*) "1"); + mark_nodes_as_extend($4); appendChild($$,$4); set_nextSibling($$,$6); } diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index 7f1d13678..d3384e1ba 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -559,9 +559,11 @@ Allocate(): virtual int classDeclaration(Node *n) { Symtab *symtab = Swig_symbol_current(); Swig_symbol_setscope(Getattr(n, "symtab")); - Node *oldInclass = inclass; - AccessMode oldAcessMode = cplus_mode; - + save_value oldInclass(inclass); + save_value oldAcessMode(cplus_mode); + save_value oldExtendMode(extendmode); + if (Getattr(n, "template")) + extendmode = 0; if (!CPlusPlus) { /* Always have default constructors/destructors in C */ Setattr(n, "allocate:default_constructor", "1"); @@ -729,8 +731,6 @@ Allocate(): /* Only care about default behavior. Remove temporary values */ Setattr(n, "allocate:visit", "1"); - inclass = oldInclass; - cplus_mode = oldAcessMode; Swig_symbol_setscope(symtab); return SWIG_OK; } diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 9197b4b17..3c765835e 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -1888,10 +1888,10 @@ public: if (Node *outer = Getattr(n, "nested:outer")) { String *outerClassesPrefix = Copy(Getattr(outer, "sym:name")); for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) { - Push(outerClassesPrefix, "::"); + Push(outerClassesPrefix, "."); Push(outerClassesPrefix, Getattr(outer, "sym:name")); } - String *fnspace = nspace ? NewStringf("%s::%s", nspace, outerClassesPrefix) : outerClassesPrefix; + String *fnspace = nspace ? NewStringf("%s.%s", nspace, outerClassesPrefix) : outerClassesPrefix; if (!addSymbol(proxy_class_name, n, fnspace)) return SWIG_ERROR; if (nspace) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index fdc678dbf..d378a02f3 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1969,8 +1969,7 @@ public: } if (outerClassesPrefix) { - Replaceall(outerClassesPrefix, ".", "::"); - String *fnspace = nspace ? NewStringf("%s::%s", nspace, outerClassesPrefix) : outerClassesPrefix; + String *fnspace = nspace ? NewStringf("%s.%s", nspace, outerClassesPrefix) : outerClassesPrefix; if (!addSymbol(proxy_class_name, n, fnspace)) return SWIG_ERROR; if (nspace) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index be83b5069..795b9edb8 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -525,15 +525,9 @@ int Language::top(Node *n) { * ---------------------------------------------------------------------- */ int Language::extendDirective(Node *n) { - int oldam = Extend; - AccessMode oldmode = cplus_mode; - Extend = CWRAP_EXTEND; - cplus_mode = PUBLIC; - + save_value oldam(Extend, CWRAP_EXTEND); + save_value oldmode(cplus_mode, PUBLIC); emit_children(n); - - Extend = oldam; - cplus_mode = oldmode; return SWIG_OK; } @@ -2486,7 +2480,9 @@ int Language::classDeclaration(Node *n) { * ---------------------------------------------------------------------- */ int Language::classHandler(Node *n) { - + save_value oldExtend(Extend); + if (Getattr(n, "template")) + Extend = 0; bool hasDirector = Swig_directorclass(n) ? true : false; /* Emit all of the class members */ @@ -2519,7 +2515,7 @@ int Language::classHandler(Node *n) { if (dirprot_mode() && extraDirectorProtectedCPPMethodsRequired()) { Node *vtable = Getattr(n, "vtable"); String *symname = Getattr(n, "sym:name"); - AccessMode old_mode = cplus_mode; + save_value old_mode(cplus_mode); cplus_mode = PROTECTED; int len = Len(vtable); for (int i = 0; i < len; i++) { @@ -2548,7 +2544,6 @@ int Language::classHandler(Node *n) { } Delete(wrapname); } - cplus_mode = old_mode; } } diff --git a/Source/Modules/nested.cxx b/Source/Modules/nested.cxx index a62a9e9da..37248608c 100644 --- a/Source/Modules/nested.cxx +++ b/Source/Modules/nested.cxx @@ -432,6 +432,8 @@ void Swig_nested_process_classes(Node *n) { removeNode(c); if (!checkAttribute(c, "access", "public")) SetFlag(c, "feature:ignore"); + else if (Strcmp(nodeType(n),"extend") == 0 && Strcmp(nodeType(parentNode(n)),"class") == 0) + insertNodeAfter(parentNode(n), c); else insertNodeAfter(n, c); } diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 9e76b4d10..6d3cd35de 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -423,4 +423,13 @@ void Swig_process_types(Node *n); void Swig_nested_process_classes(Node *n); void Swig_nested_name_unnamed_c_structs(Node *n); +template class save_value { + T _value; + T& _value_ptr; +public: + save_value(T& value) : _value(value), _value_ptr(value){} + save_value(T& value, T new_val) : _value(value), _value_ptr(value){ value = new_val; } + ~save_value(){ _value_ptr = _value; } +}; + #endif diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index 3f8e33dae..e918c0770 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -417,7 +417,7 @@ class TypePass:private Dispatcher { String *unnamed = Getattr(n, "unnamed"); String *storage = Getattr(n, "storage"); String *kind = Getattr(n, "kind"); - Node *oldinclass = inclass; + save_value oldinclass(inclass); List *olist = normalize; Symtab *symtab; String *nname = 0; @@ -537,8 +537,6 @@ class TypePass:private Dispatcher { normalize = olist; - inclass = oldinclass; - /* If in a namespace, patch the class name */ if (nname) { Setattr(n, "name", nname); diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 7d8180d1c..161c71e43 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -1154,13 +1154,13 @@ String *Swig_string_strip(String *s) { * ----------------------------------------------------------------------------- */ void Swig_offset_string(String *s, int number) { - char *res; - char *p; - char *end; + char *res, *p, *end, *start; /* count a number of lines in s */ int lines = 1; int len = Len(s); - char *start = strchr(Char(s), '\n'); + if (len == 0) + return; + start = strchr(Char(s), '\n'); while (start) { ++lines; start = strchr(start + 1, '\n'); From 257a9865e94a22dba5b212785541f9f8d5fe2a30 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 19 Dec 2013 18:12:19 +0000 Subject: [PATCH 0834/1160] Make save_value non-copyable --- Source/Modules/swigmod.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 6d3cd35de..7ebcfeee1 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -426,10 +426,13 @@ void Swig_nested_name_unnamed_c_structs(Node *n); template class save_value { T _value; T& _value_ptr; + save_value(const save_value&); + save_value& operator=(const save_value&); + public: - save_value(T& value) : _value(value), _value_ptr(value){} - save_value(T& value, T new_val) : _value(value), _value_ptr(value){ value = new_val; } - ~save_value(){ _value_ptr = _value; } + save_value(T& value) : _value(value), _value_ptr(value) {} + save_value(T& value, T new_val) : _value(value), _value_ptr(value) { value = new_val; } + ~save_value() { _value_ptr = _value; } }; #endif From 82990df5739acaef168ca66a32e3c2253e04f3d9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 19 Dec 2013 18:23:28 +0000 Subject: [PATCH 0835/1160] Error test-suite updated for nested changes WARN_DEPRECATED_NESTED_WORKAROUND test added WARN_PARSE_NAMED_NESTED_CLASS test removed --- Examples/test-suite/errors/cpp_nested.i | 13 ------------ .../test-suite/errors/cpp_nested_template.i | 20 +++++++++++++++++++ Examples/test-suite/errors/expected.log | 6 ++---- Examples/test-suite/errors/make.sh | 2 +- 4 files changed, 23 insertions(+), 18 deletions(-) delete mode 100644 Examples/test-suite/errors/cpp_nested.i create mode 100644 Examples/test-suite/errors/cpp_nested_template.i diff --git a/Examples/test-suite/errors/cpp_nested.i b/Examples/test-suite/errors/cpp_nested.i deleted file mode 100644 index 625812e7d..000000000 --- a/Examples/test-suite/errors/cpp_nested.i +++ /dev/null @@ -1,13 +0,0 @@ -%module xxx - -class Foo { -public: - class Bar { - }; -}; - -class Spam { -public: - class Grok { - } x; -}; diff --git a/Examples/test-suite/errors/cpp_nested_template.i b/Examples/test-suite/errors/cpp_nested_template.i new file mode 100644 index 000000000..ec8cab6b6 --- /dev/null +++ b/Examples/test-suite/errors/cpp_nested_template.i @@ -0,0 +1,20 @@ +%module xxx + +template struct Temply { + T thing; +}; + +struct A { + int var; +%template(TemplyInt) Temply; +}; + + +struct B { + int var; +}; + +%extend B { +%template(TemplyDouble) Temply; +} + diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log index 2db3d8cbc..5fb0e715f 100644 --- a/Examples/test-suite/errors/expected.log +++ b/Examples/test-suite/errors/expected.log @@ -286,7 +286,6 @@ cpp_inherit.i:54: Warning 401: 'Base< double >' must be defined before it is use :::::::::::::::::::::::::::::::: cpp_macro_locator.i ::::::::::::::::::::::::::::::::::: cpp_macro_locator.i:66: Warning 204: CPP #warning, "inline warning message one". cpp_macro_locator.i:96: Warning 204: CPP #warning, "an inline warning message 2". -cpp_macro_locator.i:50: Warning 325: Nested struct not currently supported (Inner ignored) cpp_macro_locator.i:53: Warning 509: Overloaded method overload1(int const *) effectively ignored, cpp_macro_locator.i:52: Warning 509: as it is shadowed by overload1(int *). cpp_macro_locator.i:61: Warning 509: Overloaded method overload2(int const *) effectively ignored, @@ -322,9 +321,8 @@ cpp_namespace_aliasnot.i:4: Error: 'blah' is not a namespace :::::::::::::::::::::::::::::::: cpp_namespace_aliasundef.i ::::::::::::::::::::::::::::::::::: cpp_namespace_aliasundef.i:3: Error: Unknown namespace 'blah' -:::::::::::::::::::::::::::::::: cpp_nested.i ::::::::::::::::::::::::::::::::::: -cpp_nested.i:6: Warning 325: Nested class not currently supported (Bar ignored) -cpp_nested.i:12: Warning 325: Nested class not currently supported (Grok ignored) +:::::::::::::::::::::::::::::::: cpp_nested_template.i ::::::::::::::::::::::::::::::::::: +cpp_nested_template.i:9: Warning 324: Named nested template instantiations not supported. Processing as if no name was given to %template(). :::::::::::::::::::::::::::::::: cpp_no_access.i ::::::::::::::::::::::::::::::::::: cpp_no_access.i:3: Warning 319: No access specifier given for base class 'foo' (ignored). diff --git a/Examples/test-suite/errors/make.sh b/Examples/test-suite/errors/make.sh index b194299c9..5f96897d9 100755 --- a/Examples/test-suite/errors/make.sh +++ b/Examples/test-suite/errors/make.sh @@ -76,7 +76,7 @@ cpp_missing_rtemplate cpp_namespace_alias cpp_namespace_aliasnot cpp_namespace_aliasundef -cpp_nested +cpp_nested_template cpp_no_access cpp_no_return_type cpp_nobase From 715e254e0577af2c6964b58882e08d278dc64e0c Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Fri, 20 Dec 2013 07:37:49 +0400 Subject: [PATCH 0836/1160] fixed enums & enum values language symbol table namespace fixed skipping of %templates in %extend if they are in the wrong scope --- Source/CParse/parser.y | 3 ++- Source/Modules/csharp.cxx | 44 ++++++++++++++++++++++++++------------- Source/Modules/java.cxx | 44 ++++++++++++++++++++++++++------------- Source/Modules/lang.cxx | 1 - 4 files changed, 62 insertions(+), 30 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 40d853387..c6fe56b70 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2676,7 +2676,8 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va Setattr(templnode,"sym:typename","1"); } /* for now, nested %template is allowed only in the same scope as the template declaration */ - if ($3 && !(currentOuterClass && (currentOuterClass != Getattr(nn, "nested:outer")))) { + if ($3 && !((currentOuterClass && (currentOuterClass != Getattr(nn, "nested:outer"))) + ||(extendmode && current_class && (current_class != Getattr(nn, "nested:outer"))))) { /* Comment this out for 1.3.28. We need to re-enable it later but first we need to diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 3c765835e..1713e6f3f 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -1107,6 +1107,30 @@ public: return ret; } + + String *getCurrentScopeName(String *nspace) + { + String *scope = 0; + if (nspace || getCurrentClass()) { + scope = NewString(""); + if (nspace) + Printf(scope, "%s", nspace); + if (Node* cls = getCurrentClass()) + { + if (Node *outer = Getattr(cls, "nested:outer")) { + String *outerClassesPrefix = Copy(Getattr(outer, "sym:name")); + for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) { + Push(outerClassesPrefix, "."); + Push(outerClassesPrefix, Getattr(outer, "sym:name")); + } + Printv(scope, nspace ? "." : "", outerClassesPrefix, ".", proxy_class_name, NIL); + Delete(outerClassesPrefix); + } else + Printv(scope, nspace ? "." : "", proxy_class_name, NIL); + } + } + return scope; + } /* ---------------------------------------------------------------------- * enumDeclaration() @@ -1150,14 +1174,7 @@ 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); - } + String *scope = getCurrentScopeName(nspace); if (!addSymbol(symname, n, scope)) return SWIG_ERROR; @@ -1305,12 +1322,11 @@ public: 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")); + scope = getCurrentScopeName(nspace); + if (!scope) + scope = Copy(Getattr(parent, "sym:name")); + else + Printf(scope, ".%s", Getattr(parent, "sym:name")); } if (!addSymbol(name, n, scope)) return SWIG_ERROR; diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index d378a02f3..c47dd3e48 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1194,6 +1194,30 @@ public: return ret; } + String *getCurrentScopeName(String *nspace) + { + String *scope = 0; + if (nspace || getCurrentClass()) { + scope = NewString(""); + if (nspace) + Printf(scope, "%s", nspace); + if (Node* cls = getCurrentClass()) + { + if (Node *outer = Getattr(cls, "nested:outer")) { + String *outerClassesPrefix = Copy(Getattr(outer, "sym:name")); + for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) { + Push(outerClassesPrefix, "."); + Push(outerClassesPrefix, Getattr(outer, "sym:name")); + } + Printv(scope, nspace ? "." : "", outerClassesPrefix, ".", proxy_class_name, NIL); + Delete(outerClassesPrefix); + } else + Printv(scope, nspace ? "." : "", proxy_class_name, NIL); + } + } + return scope; + } + /* ---------------------------------------------------------------------- * enumDeclaration() * @@ -1227,14 +1251,7 @@ 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); - } + String *scope = getCurrentScopeName(nspace); if (!addSymbol(symname, n, scope)) return SWIG_ERROR; @@ -1389,12 +1406,11 @@ public: 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")); + scope = getCurrentScopeName(nspace); + if (!scope) + scope = Copy(Getattr(parent, "sym:name")); + else + Printf(scope, ".%s", Getattr(parent, "sym:name")); } if (!addSymbol(name, n, scope)) return SWIG_ERROR; diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 795b9edb8..c3c148fa5 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -3620,4 +3620,3 @@ Language *Language::instance() { Hash *Language::getClassHash() const { return classhash; } - From 01ebdc0995e2c7b482cd44fa00412a9ed8e06d8a Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 20 Dec 2013 08:14:45 -0800 Subject: [PATCH 0837/1160] In Examples/Makefile.in, compile and link the program in go and go_cpp, rather than in go_run. This permits eliminating go_run_cpp. --- Examples/Makefile.in | 45 ++++++++++++++++------------------ Examples/go/callback/Makefile | 2 +- Examples/go/class/Makefile | 2 +- Examples/go/enum/Makefile | 2 +- Examples/go/extend/Makefile | 2 +- Examples/go/reference/Makefile | 2 +- Examples/go/template/Makefile | 2 +- 7 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index d8ebb80e3..cee91db30 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1598,6 +1598,16 @@ go: $(SRCS) $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ fi; \ fi + if test -f $(RUNME).go; then \ + $(GO) $(GOCOMPILEARG) $(RUNME).go; \ + if $(GOGCC) ; then \ + $(COMPILETOOL) $(GO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS); \ + elif $(GO12); then \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CC) -extldflags "$(CFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \ + else \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \ + fi; \ + fi # ---------------------------------------------------------------- # Build a Go module (C++) @@ -1621,35 +1631,22 @@ go_cpp: $(SRCS) $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ fi; \ fi + if test -f $(RUNME).go; then \ + $(GO) $(GOCOMPILEARG) $(RUNME).go; \ + if $(GOGCC) ; then \ + $(COMPILETOOL) $(GO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS) -lstdc++; \ + elif $(GO12); then \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \ + else \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \ + fi; \ + fi # ----------------------------------------------------------------- # Running a Go example (C) # ----------------------------------------------------------------- -go_run: runme.go - $(GO) $(GOCOMPILEARG) runme.go - if $(GOGCC) ; then \ - $(COMPILETOOL) $(GO) -o runme runme.@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS); \ - elif $(GO12); then \ - $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CC) -extldflags "$(CFLAGS)" -o runme runme.$(GOOBJEXT); \ - else \ - $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o runme runme.$(GOOBJEXT); \ - fi - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme $(RUNPIPE) - -# ----------------------------------------------------------------- -# Running a Go example (C++) -# ----------------------------------------------------------------- - -go_run_cpp: runme.go - $(GO) $(GOCOMPILEARG) runme.go - if $(GOGCC) ; then \ - $(COMPILETOOL) $(GO) -o runme runme.@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS) -lstdc++; \ - elif $(GO12); then \ - $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o runme runme.$(GOOBJEXT); \ - else \ - $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o runme runme.$(GOOBJEXT); \ - fi +go_run: env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme $(RUNPIPE) # ----------------------------------------------------------------- diff --git a/Examples/go/callback/Makefile b/Examples/go/callback/Makefile index 4516d2674..46a14b417 100644 --- a/Examples/go/callback/Makefile +++ b/Examples/go/callback/Makefile @@ -6,7 +6,7 @@ INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/class/Makefile b/Examples/go/class/Makefile index 66b2df325..72605caa5 100644 --- a/Examples/go/class/Makefile +++ b/Examples/go/class/Makefile @@ -6,7 +6,7 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/enum/Makefile b/Examples/go/enum/Makefile index 6f9347ca8..1ceecc15c 100644 --- a/Examples/go/enum/Makefile +++ b/Examples/go/enum/Makefile @@ -6,7 +6,7 @@ INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/extend/Makefile b/Examples/go/extend/Makefile index 386d4d0bb..67da89286 100644 --- a/Examples/go/extend/Makefile +++ b/Examples/go/extend/Makefile @@ -6,7 +6,7 @@ INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/reference/Makefile b/Examples/go/reference/Makefile index 5c5e6808b..41a944239 100644 --- a/Examples/go/reference/Makefile +++ b/Examples/go/reference/Makefile @@ -6,7 +6,7 @@ INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/go/template/Makefile b/Examples/go/template/Makefile index 20ffb7136..6796348a9 100644 --- a/Examples/go/template/Makefile +++ b/Examples/go/template/Makefile @@ -6,7 +6,7 @@ INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ From 32ad89668a69bbddd5a2672822d3fa291d537c5f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 20 Dec 2013 18:43:33 +0000 Subject: [PATCH 0838/1160] Use RUNME consistently in examples makefile --- Examples/Makefile.in | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index cee91db30..4c1a11ca4 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1252,7 +1252,7 @@ csharp_version: # ----------------------------------------------------------------- csharp_clean: - rm -f *_wrap* *~ .~* runme runme.exe *.exe.mdb gc.log `find . -name \*.cs | grep -v runme.cs` + rm -f *_wrap* *~ .~* $(RUNME) $(RUNME).exe *.exe.mdb gc.log `find . -name \*.cs | grep -v $(RUNME).cs` rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@CSHARPSO@ @@ -1643,11 +1643,11 @@ go_cpp: $(SRCS) fi # ----------------------------------------------------------------- -# Running a Go example (C) +# Running Go example # ----------------------------------------------------------------- go_run: - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme $(RUNPIPE) + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$(RUNME) $(RUNPIPE) # ----------------------------------------------------------------- # Version display @@ -1661,7 +1661,7 @@ go_version: # ----------------------------------------------------------------- go_clean: - rm -f *_wrap* *_gc* .~* runme $(GOSRCS) + rm -f *_wrap* *_gc* .~* $(RUNME) $(GOSRCS) rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *.[568] *.a *@SO@ @@ -1732,6 +1732,6 @@ d_version: # ----------------------------------------------------------------- d_clean: - rm -f *_wrap* *~ .~* runme runme.exe `find . -name \*.d | grep -v runme.d` + rm -f *_wrap* *~ .~* $(RUNME) $(RUNME).exe `find . -name \*.d | grep -v $(RUNME).d` rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@SO@ From 6250c288b5b83b95807e063427fc8c00d739b00b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 22 Dec 2013 17:49:16 +0000 Subject: [PATCH 0839/1160] Suppress gcc-4.9 auto_ptr deprecation in test --- Examples/test-suite/li_std_auto_ptr.i | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Examples/test-suite/li_std_auto_ptr.i b/Examples/test-suite/li_std_auto_ptr.i index b58a1d79d..1dcb3e02e 100644 --- a/Examples/test-suite/li_std_auto_ptr.i +++ b/Examples/test-suite/li_std_auto_ptr.i @@ -1,5 +1,11 @@ %module li_std_auto_ptr +%{ +#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" // auto_ptr deprecation +#endif +%} + #if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPYTHON) %include "std_auto_ptr.i" From cf92954bc06a9f245d14de2440896b3866b29ed3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 22 Dec 2013 19:38:46 +0000 Subject: [PATCH 0840/1160] C++11 tests re-organise - gcc-4.8 minimum expected for all to pass --- Examples/test-suite/common.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 7972b28d8..642e7fd8c 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -491,6 +491,7 @@ CPP11_TEST_CASES = \ cpp11_delegating_constructors \ cpp11_explicit_conversion_operators \ cpp11_function_objects \ + cpp11_inheriting_constructors \ cpp11_initializer_list \ cpp11_initializer_list_extend \ cpp11_lambda_functions \ @@ -502,7 +503,7 @@ CPP11_TEST_CASES = \ cpp11_rvalue_reference3 \ cpp11_sizeof_object \ cpp11_static_assert \ - cpp11_strongly_typed_enumerations \ + cpp11_thread_local \ cpp11_template_double_brackets \ cpp11_template_explicit \ cpp11_template_typedefs \ @@ -511,10 +512,9 @@ CPP11_TEST_CASES = \ cpp11_userdefined_literals \ cpp11_variadic_templates -# cpp11_inheriting_constructors \ # not supported by gcc-4.7 # cpp11_hash_tables \ # not fully implemented yet # cpp11_result_of \ # SWIG does not support -# cpp11_thread_local \ # needs gcc-4.8 +# cpp11_strongly_typed_enumerations \ # SWIG not quite getting this right yet in all langs # Broken C++11 test cases. CPP11_TEST_BROKEN = From 92128eef445f75f674894e3f5d4e1fc2a1818957 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 22 Dec 2013 19:39:21 +0000 Subject: [PATCH 0841/1160] C++11 support for new versions of erase and insert in the STL containers. The erase and insert methods in the containers use const_iterator instead of iterator in C++11. There are times when the methods wrapped must match the parameters exactly. Specifically when full type information for template types is missing or SWIG fails to look up the type correctly, for example: %include typedef float Real; %template(RealVector) std::vector; SWIG does not find std::vector::iterator because %template using typedefs does not always work and so SWIG doesn't know if the type is copyable and so uses SwigValueWrapper which does not support conversion to another type (const_iterator). This resulted in compilation errors when using the C++11 version of the containers. Closes #73 --- CHANGES.current | 21 +++++++++++++++++++++ Lib/std/std_container.i | 21 +++++++++++++++------ Lib/std/std_map.i | 8 +++++--- Lib/std/std_set.i | 7 +++++-- Lib/std/std_unordered_map.i | 8 +++++--- Lib/std/std_unordered_set.i | 7 +++++-- 6 files changed, 56 insertions(+), 16 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index f9934b49d..c9043df14 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,27 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-12-22: wsfulton + C++11 support for new versions of erase and insert in the STL containers. + + The erase and insert methods in the containers use const_iterator instead + of iterator in C++11. There are times when the methods wrapped must match + the parameters exactly. Specifically when full type information for + template types is missing or SWIG fails to look up the type correctly, + for example: + + %include + typedef float Real; + %template(RealVector) std::vector; + + SWIG does not find std::vector::iterator because %template using + typedefs does not always work and so SWIG doesn't know if the type is + copyable and so uses SwigValueWrapper which does + not support conversion to another type (const_iterator). This resulted + in compilation errors when using the C++11 version of the containers. + + Closes #73 + 2013-12-18: ianlancetaylor [Go] Don't require that Go environment variables be set when running examples or testsuite when using Go 1 or diff --git a/Lib/std/std_container.i b/Lib/std/std_container.i index 73d0c6ad9..8ed327bbe 100644 --- a/Lib/std/std_container.i +++ b/Lib/std/std_container.i @@ -46,8 +46,11 @@ void resize(size_type new_size); #ifdef SWIG_EXPORT_ITERATOR_METHODS - iterator erase(iterator pos); - iterator erase(iterator first, iterator last); +%extend { + // %extend wrapper used for differing definitions of these methods introduced in C++11 + iterator erase(iterator pos) { return $self->erase(pos); } + iterator erase(iterator first, iterator last) { return $self->erase(first, last); } +} #endif %enddef @@ -68,8 +71,11 @@ void resize(size_type new_size, const value_type& x); #ifdef SWIG_EXPORT_ITERATOR_METHODS - iterator insert(iterator pos, const value_type& x); - void insert(iterator pos, size_type n, const value_type& x); +%extend { + // %extend wrapper used for differing definitions of these methods introduced in C++11 + iterator insert(iterator pos, const value_type& x) { return $self->insert(pos, x); } + void insert(iterator pos, size_type n, const value_type& x) { $self->insert(pos, n, x); } +} #endif %enddef @@ -89,8 +95,11 @@ void resize(size_type new_size, value_type x); #ifdef SWIG_EXPORT_ITERATOR_METHODS - iterator insert(iterator pos, value_type x); - void insert(iterator pos, size_type n, value_type x); +%extend { + // %extend wrapper used for differing definitions of these methods introduced in C++11 + iterator insert(iterator pos, value_type x) { return $self->insert(pos, x); } + void insert(iterator pos, size_type n, value_type x) { $self->insert(pos, n, x); } +} #endif %enddef diff --git a/Lib/std/std_map.i b/Lib/std/std_map.i index 05208418f..e523c3deb 100644 --- a/Lib/std/std_map.i +++ b/Lib/std/std_map.i @@ -12,9 +12,11 @@ size_type count(const key_type& x) const; #ifdef SWIG_EXPORT_ITERATOR_METHODS -// iterator insert(iterator position, const value_type& x); - void erase(iterator position); - void erase(iterator first, iterator last); +%extend { + // %extend wrapper used for differing definitions of these methods introduced in C++11 + void erase(iterator position) { $self->erase(position); } + void erase(iterator first, iterator last) { $self->erase(first, last); } +} iterator find(const key_type& x); iterator lower_bound(const key_type& x); diff --git a/Lib/std/std_set.i b/Lib/std/std_set.i index 16f0f1482..f96ddd9f1 100644 --- a/Lib/std/std_set.i +++ b/Lib/std/std_set.i @@ -29,8 +29,11 @@ reverse_iterator rbegin(); reverse_iterator rend(); - void erase(iterator pos); - void erase(iterator first, iterator last); +%extend { + // %extend wrapper used for differing definitions of these methods introduced in C++11 + void erase(iterator pos) { $self->erase(pos); } + void erase(iterator first, iterator last) { $self->erase(first, last); } +} iterator find(const key_type& x); iterator lower_bound(const key_type& x); diff --git a/Lib/std/std_unordered_map.i b/Lib/std/std_unordered_map.i index 3c36d78e3..3d80788e2 100644 --- a/Lib/std/std_unordered_map.i +++ b/Lib/std/std_unordered_map.i @@ -15,9 +15,11 @@ size_type count(const key_type& x) const; #ifdef SWIG_EXPORT_ITERATOR_METHODS -// iterator insert(iterator position, const value_type& x); - void erase(iterator position); - void erase(iterator first, iterator last); +%extend { + // %extend wrapper used for differing definitions of these methods introduced in C++11 + void erase(iterator position) { $self->erase(position); } + void erase(iterator first, iterator last) { $self->erase(first, last); } +} iterator find(const key_type& x); iterator lower_bound(const key_type& x); diff --git a/Lib/std/std_unordered_set.i b/Lib/std/std_unordered_set.i index 4cdfd65a5..ed8888eb4 100644 --- a/Lib/std/std_unordered_set.i +++ b/Lib/std/std_unordered_set.i @@ -29,8 +29,11 @@ iterator begin(); iterator end(); - void erase(iterator pos); - void erase(iterator first, iterator last); +%extend { + // %extend wrapper used for differing definitions of these methods introduced in C++11 + void erase(iterator pos) { $self->erase(pos); } + void erase(iterator first, iterator last) { $self->erase(first, last); } +} iterator find(const key_type& x); std::pair equal_range(const key_type& x); From e7834c8daa9414a631e90c1b03372ab5668302d8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 23 Dec 2013 18:04:14 +0000 Subject: [PATCH 0842/1160] Perl directors changes entry added and minor tidy up --- .travis.yml | 1 - CHANGES.current | 3 +++ Examples/perl5/callback/runme.pl | 2 +- Examples/perl5/check.list | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2b860cc9e..70cbb2f27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,4 +57,3 @@ script: branches: only: - master - - perl5-directors-minimal diff --git a/CHANGES.current b/CHANGES.current index c9043df14..59ebeebcd 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-12-23: talby + [Perl] Add support for directors. + 2013-12-22: wsfulton C++11 support for new versions of erase and insert in the STL containers. diff --git a/Examples/perl5/callback/runme.pl b/Examples/perl5/callback/runme.pl index a6b80d988..54d86783a 100644 --- a/Examples/perl5/callback/runme.pl +++ b/Examples/perl5/callback/runme.pl @@ -29,7 +29,7 @@ $caller->setCallback($callback); $caller->call(); $caller->delCallback(); -print +print "\n"; print "Adding and calling a Perl callback\n"; print "----------------------------------\n"; diff --git a/Examples/perl5/check.list b/Examples/perl5/check.list index 925bd263f..78d45fc0b 100644 --- a/Examples/perl5/check.list +++ b/Examples/perl5/check.list @@ -1,7 +1,9 @@ # see top-level Makefile.in +callback class constants constants2 +extend funcptr import multimap @@ -11,5 +13,3 @@ reference simple value variables -callback -extend From 279ebdc0cf655feca4c80c23f115e90ce0470102 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 23 Dec 2013 18:21:52 +0000 Subject: [PATCH 0843/1160] Beautify director output --- Lib/perl5/director.swg | 16 ++++++++-------- Lib/python/director.swg | 32 ++++++++++++++++---------------- Source/Modules/perl5.cxx | 13 +++++++------ Source/Modules/python.cxx | 15 ++++++++------- 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/Lib/perl5/director.swg b/Lib/perl5/director.swg index 5acc4fd15..34514972a 100644 --- a/Lib/perl5/director.swg +++ b/Lib/perl5/director.swg @@ -33,8 +33,8 @@ namespace Swig { class Director; - SWIGINTERN std::map& get_rtdir_map() { - static std::map rtdir_map; + SWIGINTERN std::map& get_rtdir_map() { + static std::map rtdir_map; return rtdir_map; } @@ -43,15 +43,15 @@ namespace Swig { } SWIGINTERNINLINE Director *get_rtdir(void *vptr) { - std::map::const_iterator pos = get_rtdir_map().find(vptr); + std::map::const_iterator pos = get_rtdir_map().find(vptr); Director *rtdir = (pos != get_rtdir_map().end()) ? pos->second : 0; return rtdir; } } # 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 @@ -293,16 +293,16 @@ namespace Swig { } /* methods to implement pseudo protected director members */ - virtual bool swig_get_inner(const char* /* swig_protected_method_name */) const { + virtual bool swig_get_inner(const char * /* swig_protected_method_name */) const { return true; } - virtual void swig_set_inner(const char* /* swig_protected_method_name */, bool /* swig_val */) const { + virtual void swig_set_inner(const char * /* swig_protected_method_name */, bool /* swig_val */) const { } /* ownership management */ private: - typedef std::map swig_ownership_map; + typedef std::map swig_ownership_map; mutable swig_ownership_map swig_owner; public: diff --git a/Lib/python/director.swg b/Lib/python/director.swg index 97edc7ef0..d6bfe51f0 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -68,8 +68,8 @@ namespace Swig { class Director; - SWIGINTERN std::map& get_rtdir_map() { - static std::map rtdir_map; + SWIGINTERN std::map& get_rtdir_map() { + static std::map rtdir_map; return rtdir_map; } @@ -78,15 +78,15 @@ namespace Swig { } SWIGINTERNINLINE Director *get_rtdir(void *vptr) { - std::map::const_iterator pos = get_rtdir_map().find(vptr); + std::map::const_iterator pos = get_rtdir_map().find(vptr); Director *rtdir = (pos != get_rtdir_map().end()) ? pos->second : 0; return rtdir; } } # 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 @@ -196,7 +196,7 @@ namespace Swig { protected: std::string swig_msg; public: - DirectorException(PyObject *error, const char* hdr ="", const char* msg ="") + DirectorException(PyObject *error, const char *hdr ="", const char *msg ="") : swig_msg(hdr) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; @@ -272,12 +272,12 @@ namespace Swig { /* type mismatch in the return value from a python method call */ class DirectorTypeMismatchException : public Swig::DirectorException { public: - DirectorTypeMismatchException(PyObject *error, const char* msg="") + DirectorTypeMismatchException(PyObject *error, const char *msg="") : Swig::DirectorException(error, "SWIG director type mismatch", msg) { } - DirectorTypeMismatchException(const char* msg="") + DirectorTypeMismatchException(const char *msg="") : Swig::DirectorException(PyExc_TypeError, "SWIG director type mismatch", msg) { } @@ -296,7 +296,7 @@ namespace Swig { /* any python exception that occurs during a director method call */ class DirectorMethodException : public Swig::DirectorException { public: - DirectorMethodException(const char* msg = "") + DirectorMethodException(const char *msg = "") : DirectorException(PyExc_RuntimeError, "SWIG director method error.", msg) { } @@ -311,7 +311,7 @@ namespace Swig { class DirectorPureVirtualException : public Swig::DirectorException { public: - DirectorPureVirtualException(const char* msg = "") + DirectorPureVirtualException(const char *msg = "") : DirectorException(PyExc_RuntimeError, "SWIG director pure virtual method called", msg) { } @@ -356,7 +356,7 @@ namespace Swig { class Director { private: /* pointer to the wrapped python object */ - PyObject* swig_self; + PyObject *swig_self; /* flag indicating whether the object is owned by python or c++ */ mutable bool swig_disown_flag; @@ -371,7 +371,7 @@ namespace Swig { public: /* wrap a python object, optionally taking ownership */ - Director(PyObject* self) : swig_self(self), swig_disown_flag(false) { + Director(PyObject *self) : swig_self(self), swig_disown_flag(false) { swig_incref(); } @@ -404,16 +404,16 @@ namespace Swig { } /* methods to implement pseudo protected director members */ - virtual bool swig_get_inner(const char* /* swig_protected_method_name */) const { + virtual bool swig_get_inner(const char * /* swig_protected_method_name */) const { return true; } - virtual void swig_set_inner(const char* /* swig_protected_method_name */, bool /* swig_val */) const { + virtual void swig_set_inner(const char * /* swig_protected_method_name */, bool /* swig_val */) const { } /* ownership management */ private: - typedef std::map swig_ownership_map; + typedef std::map swig_ownership_map; mutable swig_ownership_map swig_owner; #ifdef __THREAD__ static PyThread_type_lock swig_mutex_own; @@ -461,7 +461,7 @@ namespace Swig { } template - static PyObject* swig_pyobj_disown(PyObject *pyobj, PyObject *SWIGUNUSEDPARM(args)) + static PyObject *swig_pyobj_disown(PyObject *pyobj, PyObject *SWIGUNUSEDPARM(args)) { SwigPyObject *sobj = (SwigPyObject *)pyobj; sobj->own = 0; diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index d7a131aa2..28f4a3f3d 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -1988,16 +1988,17 @@ public: But for now, this seems to be the least intrusive way. */ - Printf(f_directors_h, "\n\n"); - Printf(f_directors_h, "/* Internal Director utilities */\n"); + Printf(f_directors_h, "\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* swig_protected_method_name) const {\n"); + Printf(f_directors_h, " bool swig_get_inner(const char *swig_protected_method_name) const {\n"); Printf(f_directors_h, " std::map::const_iterator iv = swig_inner.find(swig_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, " }\n"); - Printf(f_directors_h, " void swig_set_inner(const char* swig_protected_method_name, bool val) const\n"); - Printf(f_directors_h, " { swig_inner[swig_protected_method_name] = val;}\n\n"); + Printf(f_directors_h, " void swig_set_inner(const char *swig_protected_method_name, bool val) const {\n"); + Printf(f_directors_h, " swig_inner[swig_protected_method_name] = val;\n"); + Printf(f_directors_h, " }\n"); Printf(f_directors_h, "private:\n"); Printf(f_directors_h, " mutable std::map swig_inner;\n"); } diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 1022f9fa0..e281bbbec 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -3074,22 +3074,23 @@ public: But for now, this seems to be the least intrusive way. */ - Printf(f_directors_h, "\n\n"); - Printf(f_directors_h, "/* Internal Director utilities */\n"); + Printf(f_directors_h, "\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* swig_protected_method_name) const {\n"); + Printf(f_directors_h, " bool swig_get_inner(const char *swig_protected_method_name) const {\n"); Printf(f_directors_h, " std::map::const_iterator iv = swig_inner.find(swig_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, " }\n"); - Printf(f_directors_h, " void swig_set_inner(const char* swig_protected_method_name, bool val) const\n"); - Printf(f_directors_h, " { swig_inner[swig_protected_method_name] = val;}\n\n"); + Printf(f_directors_h, " void swig_set_inner(const char *swig_protected_method_name, bool val) const {\n"); + Printf(f_directors_h, " swig_inner[swig_protected_method_name] = val;\n"); + Printf(f_directors_h, " }\n"); Printf(f_directors_h, "private:\n"); Printf(f_directors_h, " mutable std::map swig_inner;\n"); } if (director_method_index) { - Printf(f_directors_h, "\n\n"); + Printf(f_directors_h, "\n"); Printf(f_directors_h, "#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n"); Printf(f_directors_h, "/* VTable implementation */\n"); Printf(f_directors_h, " PyObject *swig_get_method(size_t method_index, const char *method_name) const {\n"); From 135a7cc558442062ce8d65de834870a71eb30aca Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 23 Dec 2013 19:50:41 +0000 Subject: [PATCH 0844/1160] Beautify director.swg files Also some comment corrections for Perl --- Lib/csharp/director.swg | 9 +- Lib/d/director.swg | 8 +- Lib/java/director.swg | 4 +- Lib/ocaml/director.swg | 33 +++--- Lib/octave/director.swg | 15 ++- Lib/perl5/director.swg | 122 +++++++++------------- Lib/php/director.swg | 87 ++++++---------- Lib/python/director.swg | 218 ++++++++++++++++------------------------ Lib/ruby/director.swg | 199 +++++++++++++++--------------------- 9 files changed, 289 insertions(+), 406 deletions(-) diff --git a/Lib/csharp/director.swg b/Lib/csharp/director.swg index 7768d8c02..c68c2d98f 100644 --- a/Lib/csharp/director.swg +++ b/Lib/csharp/director.swg @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- * director.swg * - * This file contains support for director classes so that C# proxy + * This file contains support for director classes so that C# proxy * methods can be called from C++. * ----------------------------------------------------------------------------- */ @@ -23,13 +23,16 @@ namespace Swig { std::string swig_msg; public: - DirectorException(const char* msg) : swig_msg(msg) { + DirectorException(const char *msg) : swig_msg(msg) { } + DirectorException(const std::string &msg) : swig_msg(msg) { } + const std::string& what() const { return swig_msg; } + virtual ~DirectorException() { } }; @@ -37,7 +40,7 @@ namespace Swig { /* Pure virtual method exception */ class DirectorPureVirtualException : public Swig::DirectorException { public: - DirectorPureVirtualException(const char* msg) : DirectorException(std::string("Attempt to invoke pure virtual method ") + msg) { + DirectorPureVirtualException(const char *msg) : DirectorException(std::string("Attempt to invoke pure virtual method ") + msg) { } }; } diff --git a/Lib/d/director.swg b/Lib/d/director.swg index 9692e03c1..d0ef2372b 100644 --- a/Lib/d/director.swg +++ b/Lib/d/director.swg @@ -13,6 +13,7 @@ #include namespace Swig { + // Director base class – not used in D directors. class Director { }; @@ -23,13 +24,16 @@ namespace Swig { std::string swig_msg; public: - DirectorException(const char* msg) : swig_msg(msg) { + DirectorException(const char *msg) : swig_msg(msg) { } + DirectorException(const std::string &msg) : swig_msg(msg) { } + const std::string& what() const { return swig_msg; } + virtual ~DirectorException() { } }; @@ -38,7 +42,7 @@ namespace Swig { // from D code thorugh the director layer. class DirectorPureVirtualException : public Swig::DirectorException { public: - DirectorPureVirtualException(const char* msg) : DirectorException(std::string("Attempted to invoke pure virtual method ") + msg) { + DirectorPureVirtualException(const char *msg) : DirectorException(std::string("Attempted to invoke pure virtual method ") + msg) { } }; } diff --git a/Lib/java/director.swg b/Lib/java/director.swg index f9ddbeffe..86880a55e 100644 --- a/Lib/java/director.swg +++ b/Lib/java/director.swg @@ -126,7 +126,7 @@ namespace Swig { #endif env_status = director_->swig_jvm_->GetEnv((void **)&jenv_, JNI_VERSION_1_2); #if defined(SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON) - // Attach a daemon thread to the JVM. Useful when the JVM should not wait for + // Attach a daemon thread to the JVM. Useful when the JVM should not wait for // the thread to exit upon shutdown. Only for jdk-1.4 and later. director_->swig_jvm_->AttachCurrentThreadAsDaemon(jenv, NULL); #else @@ -358,7 +358,7 @@ namespace Swig { if (throwable && jenv && classname) { // Exceptions need to be cleared for correct behavior. - // The caller of ExceptionMatches should restore pending exceptions if desired - + // The caller of ExceptionMatches should restore pending exceptions if desired - // the caller already has the throwable. jenv->ExceptionClear(); diff --git a/Lib/ocaml/director.swg b/Lib/ocaml/director.swg index 77b2fd3c0..dc4c69b7d 100644 --- a/Lib/ocaml/director.swg +++ b/Lib/ocaml/director.swg @@ -18,18 +18,21 @@ namespace Swig { protected: std::string swig_msg; public: - DirectorException(const char* msg="") { + DirectorException(const char *msg="") { } - const char *getMessage() const { - return swig_msg.c_str(); + + const char *getMessage() const { + return swig_msg.c_str(); + } + + virtual ~DirectorException() { } - virtual ~DirectorException() {} }; /* type mismatch in the return value from a python method call */ class DirectorTypeMismatchException : public Swig::DirectorException { public: - DirectorTypeMismatchException(const char* msg="") { + DirectorTypeMismatchException(const char *msg="") { } }; @@ -39,7 +42,7 @@ namespace Swig { /* attempt to call a pure virtual method via a director method */ class DirectorPureVirtualException : public Swig::DirectorException { public: - DirectorPureVirtualException(const char* msg="") { + DirectorPureVirtualException(const char *msg="") { } static void raise(const char *msg) { @@ -57,7 +60,7 @@ namespace Swig { #define MUTEX_INIT(var) CRITICAL_SECTION var #else #include -#define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER +#define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER #endif #endif @@ -78,23 +81,21 @@ namespace Swig { /* discard our reference at destruction */ virtual ~Director() { remove_global_root(&swig_self); - swig_disown(); - // Disown is safe here because we're just divorcing a reference that - // points to us. + swig_disown(); + // Disown is safe here because we're just divorcing a reference that points to us. } /* return a pointer to the wrapped ocaml object */ - CAML_VALUE swig_get_self() const { + CAML_VALUE swig_get_self() const { return swig_self; } - /* acquire ownership of the wrapped ocaml object (the sense of "disown" - * is from ocaml) */ - void swig_disown() const { - if (!swig_disown_flag) { + /* acquire ownership of the wrapped ocaml object (the sense of "disown" is from ocaml) */ + void swig_disown() const { + if (!swig_disown_flag) { swig_disown_flag=true; callback(*caml_named_value("caml_obj_disown"),swig_self); - } + } } }; } diff --git a/Lib/octave/director.swg b/Lib/octave/director.swg index 5e5d6f1f4..ce4377ef1 100644 --- a/Lib/octave/director.swg +++ b/Lib/octave/director.swg @@ -1,3 +1,10 @@ +/* ----------------------------------------------------------------------------- + * director.swg + * + * This file contains support for director classes so that D proxy + * methods can be called from C++. + * ----------------------------------------------------------------------------- */ + # define SWIG_DIRECTOR_CAST(ARG) dynamic_cast(ARG) @@ -62,7 +69,7 @@ namespace Swig { } }; - SWIGINTERN rtdir_map* get_rtdir_map() { + SWIGINTERN rtdir_map *get_rtdir_map() { static swig_module_info *module = 0; if (!module) module = SWIG_GetModule(0); @@ -74,19 +81,19 @@ namespace Swig { } SWIGINTERNINLINE void set_rtdir(void *vptr, Director *d) { - rtdir_map* rm = get_rtdir_map(); + rtdir_map *rm = get_rtdir_map(); if (rm) (*rm)[vptr] = d; } SWIGINTERNINLINE void erase_rtdir(void *vptr) { - rtdir_map* rm = get_rtdir_map(); + rtdir_map *rm = get_rtdir_map(); if (rm) (*rm).erase(vptr); } SWIGINTERNINLINE Director *get_rtdir(void *vptr) { - rtdir_map* rm = get_rtdir_map(); + rtdir_map *rm = get_rtdir_map(); if (!rm) return 0; rtdir_map::const_iterator pos = rm->find(vptr); diff --git a/Lib/perl5/director.swg b/Lib/perl5/director.swg index 34514972a..0e7faee6c 100644 --- a/Lib/perl5/director.swg +++ b/Lib/perl5/director.swg @@ -2,7 +2,7 @@ * director.swg * * This file contains support for director classes that proxy - * method calls from C++ to Python extensions. + * method calls from C++ to Perl extensions. * ----------------------------------------------------------------------------- */ #ifndef SWIG_DIRECTOR_PERL_HEADER_ @@ -67,37 +67,30 @@ extern "C" { namespace Swig { /* memory handler */ - struct GCItem - { + struct GCItem { virtual ~GCItem() {} - virtual int get_own() const - { + virtual int get_own() const { return 0; } }; - struct GCItem_var - { - GCItem_var(GCItem *item = 0) : _item(item) - { + struct GCItem_var { + GCItem_var(GCItem *item = 0) : _item(item) { } - GCItem_var& operator=(GCItem *item) - { + GCItem_var& operator=(GCItem *item) { GCItem *tmp = _item; _item = item; delete tmp; return *this; } - ~GCItem_var() - { + ~GCItem_var() { delete _item; } - GCItem * operator->() const - { + GCItem *operator->() const { return _item; } @@ -105,18 +98,14 @@ namespace Swig { GCItem *_item; }; - struct GCItem_Object : GCItem - { - GCItem_Object(int own) : _own(own) - { + struct GCItem_Object : GCItem { + GCItem_Object(int own) : _own(own) { } - virtual ~GCItem_Object() - { + virtual ~GCItem_Object() { } - int get_own() const - { + int get_own() const { return _own; } @@ -125,14 +114,11 @@ namespace Swig { }; template - struct GCItem_T : GCItem - { - GCItem_T(Type *ptr) : _ptr(ptr) - { + struct GCItem_T : GCItem { + GCItem_T(Type *ptr) : _ptr(ptr) { } - virtual ~GCItem_T() - { + virtual ~GCItem_T() { delete _ptr; } @@ -141,14 +127,11 @@ namespace Swig { }; template - struct GCArray_T : GCItem - { - GCArray_T(Type *ptr) : _ptr(ptr) - { + struct GCArray_T : GCItem { + GCArray_T(Type *ptr) : _ptr(ptr) { } - virtual ~GCArray_T() - { + virtual ~GCArray_T() { delete[] _ptr; } @@ -162,30 +145,29 @@ namespace Swig { virtual const char *getMessage() const = 0; virtual SV *getNative() const = 0; }; + /* exceptions emitted by Perl */ class DirectorMethodException : public Swig::DirectorException { protected: SV *err; public: - DirectorMethodException(SV *sv = sv_mortalcopy(ERRSV)) - : err(sv) - { + DirectorMethodException(SV *sv = sv_mortalcopy(ERRSV)) : err(sv) { SvREFCNT_inc(err); } - ~DirectorMethodException() - { + + ~DirectorMethodException() { SvREFCNT_dec(err); } - const char *getMessage() const - { + + const char *getMessage() const { return SvPV_nolen(err); } - SV *getNative() const - { + + SV *getNative() const { return sv_2mortal(newSVsv(err)); } - static void raise(SV *sv) - { + + static void raise(SV *sv) { throw DirectorMethodException(sv); } }; @@ -193,42 +175,38 @@ namespace Swig { class DirectorWrapException : public Swig::DirectorException { protected: std::string msg; - DirectorWrapException(const char *str) - : msg(str) - { + DirectorWrapException(const char *str) : msg(str) { } + public: - virtual const char *getMessage() const - { + virtual const char *getMessage() const { return msg.c_str(); } + virtual SV *getNative() const { return sv_2mortal(newSVpvn(msg.data(), msg.size())); } }; + class DirectorTypeMismatchException : public Swig::DirectorWrapException { public: - DirectorTypeMismatchException(const char *str) - : DirectorWrapException(str) - { + DirectorTypeMismatchException(const char *str) : DirectorWrapException(str) { } - static void raise(const char *type, const char *msg) - { + static void raise(const char *type, const char *msg) { std::string err = std::string(type); err += ": "; err += msg; throw DirectorTypeMismatchException(err.c_str()); } }; + class DirectorPureVirtualException : public Swig::DirectorWrapException { public: DirectorPureVirtualException(const char *name) - : DirectorWrapException("SWIG director pure virtual method called: ") - { + : DirectorWrapException("SWIG director pure virtual method called: ") { msg += name; } - static void raise(const char *name) - { + static void raise(const char *name) { throw DirectorPureVirtualException(name); } }; @@ -251,7 +229,7 @@ namespace Swig { } public: - /* wrap a python object, optionally taking ownership */ + /* wrap a Perl object, optionally taking ownership */ Director(SV *pkg) : swig_disown_flag(false) { STRLEN len; char *str = SvPV(pkg, len); @@ -260,14 +238,12 @@ namespace Swig { swig_incref(); } - /* discard our reference at destruction */ virtual ~Director() { swig_decref(); } - - /* return a pointer to the wrapped python object */ + /* return a pointer to the wrapped Perl object */ SV *swig_get_self() const { return swig_self; } @@ -276,8 +252,7 @@ namespace Swig { return swig_class.c_str(); } - /* acquire ownership of the wrapped python object (the sense of "disown" - * is from python) */ + /* acquire ownership of the wrapped Perl object (the sense of "disown" is from perl) */ void swig_disown() const { if (!swig_disown_flag) { swig_disown_flag=true; @@ -285,7 +260,7 @@ namespace Swig { } } - /* increase the reference count of the wrapped python object */ + /* increase the reference count of the wrapped Perl object */ void swig_incref() const { if (swig_disown_flag) { SvREFCNT_inc(swig_self); @@ -307,30 +282,26 @@ namespace Swig { public: template - void swig_acquire_ownership_array(Type *vptr) const - { + void swig_acquire_ownership_array(Type *vptr) const { if (vptr) { swig_owner[vptr] = new GCArray_T(vptr); } } template - void swig_acquire_ownership(Type *vptr) const - { + void swig_acquire_ownership(Type *vptr) const { if (vptr) { swig_owner[vptr] = new GCItem_T(vptr); } } - void swig_acquire_ownership_obj(void *vptr, int own) const - { + void swig_acquire_ownership_obj(void *vptr, int own) const { if (vptr && own) { swig_owner[vptr] = new GCItem_Object(own); } } - int swig_release_ownership(void *vptr) const - { + int swig_release_ownership(void *vptr) const { int own = 0; if (vptr) { swig_ownership_map::iterator iter = swig_owner.find(vptr); @@ -341,7 +312,6 @@ namespace Swig { } return own; } - }; } diff --git a/Lib/php/director.swg b/Lib/php/director.swg index 90f6a74a2..b864cff84 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -23,38 +23,33 @@ #endif namespace Swig { - /* memory handler */ - struct GCItem - { - virtual ~GCItem() {} - virtual int get_own() const - { + /* memory handler */ + struct GCItem { + virtual ~GCItem() { + } + + virtual int get_own() const { return 0; } }; - struct GCItem_var - { - GCItem_var(GCItem *item = 0) : _item(item) - { + struct GCItem_var { + GCItem_var(GCItem *item = 0) : _item(item) { } - GCItem_var& operator=(GCItem *item) - { + GCItem_var& operator=(GCItem *item) { GCItem *tmp = _item; _item = item; delete tmp; return *this; } - ~GCItem_var() - { + ~GCItem_var() { delete _item; } - GCItem * operator->() const - { + GCItem * operator->() const { return _item; } @@ -62,18 +57,14 @@ namespace Swig { GCItem *_item; }; - struct GCItem_Object : GCItem - { - GCItem_Object(int own) : _own(own) - { + struct GCItem_Object : GCItem { + GCItem_Object(int own) : _own(own) { } - virtual ~GCItem_Object() - { + virtual ~GCItem_Object() { } - int get_own() const - { + int get_own() const { return _own; } @@ -82,14 +73,11 @@ namespace Swig { }; template - struct GCItem_T : GCItem - { - GCItem_T(Type *ptr) : _ptr(ptr) - { + struct GCItem_T : GCItem { + GCItem_T(Type *ptr) : _ptr(ptr) { } - virtual ~GCItem_T() - { + virtual ~GCItem_T() { delete _ptr; } @@ -100,14 +88,14 @@ namespace Swig { class Director { protected: zval *swig_self; - typedef std::map swig_ownership_map; + typedef std::map swig_ownership_map; mutable swig_ownership_map swig_owner; #ifdef ZTS // Store the ZTS context so it's available when C++ calls back to PHP. void *** swig_zts_ctx; -#endif +#endif public: - Director(zval* self TSRMLS_DC) : swig_self(self) { + Director(zval *self TSRMLS_DC) : swig_self(self) { TSRMLS_SET_CTX(swig_zts_ctx); } @@ -116,11 +104,11 @@ namespace Swig { zend_class_entry **ce; zend_function *mptr; int name_len = strlen(lc_fname); - + if (zend_lookup_class(cname, strlen(cname), &ce TSRMLS_CC) != SUCCESS) { return false; } - if (zend_hash_find(&(*ce)->function_table, lc_fname, name_len + 1, (void**) &mptr) != SUCCESS) { + if (zend_hash_find(&(*ce)->function_table, lc_fname, name_len + 1, (void **) &mptr) != SUCCESS) { return false; } // common.scope points to the declaring class @@ -128,8 +116,7 @@ namespace Swig { } template - void swig_acquire_ownership(Type *vptr) const - { + void swig_acquire_ownership(Type *vptr) const { if (vptr) { swig_owner[vptr] = new GCItem_T(vptr); } @@ -141,9 +128,7 @@ namespace Swig { protected: std::string swig_msg; public: - DirectorException(int code, const char *hdr, const char* msg TSRMLS_DC) - : swig_msg(hdr) - { + DirectorException(int code, const char *hdr, const char *msg TSRMLS_DC) : swig_msg(hdr) { if (strlen(msg)) { swig_msg += " "; swig_msg += msg; @@ -152,23 +137,19 @@ namespace Swig { SWIG_ErrorMsg() = swig_msg.c_str(); } - static void raise(int code, const char *hdr, const char* msg TSRMLS_DC) - { + static void raise(int code, const char *hdr, const char *msg TSRMLS_DC) { throw DirectorException(code, hdr, msg TSRMLS_CC); } }; /* attempt to call a pure virtual method via a director method */ - class DirectorPureVirtualException : public Swig::DirectorException - { + class DirectorPureVirtualException : public Swig::DirectorException { public: - DirectorPureVirtualException(const char* msg TSRMLS_DC) - : DirectorException(E_ERROR, "SWIG director pure virtual method called", msg TSRMLS_CC) - { + DirectorPureVirtualException(const char *msg TSRMLS_DC) + : DirectorException(E_ERROR, "SWIG director pure virtual method called", msg TSRMLS_CC) { } - static void raise(const char *msg TSRMLS_DC) - { + static void raise(const char *msg TSRMLS_DC) { throw DirectorPureVirtualException(msg TSRMLS_CC); } }; @@ -176,13 +157,11 @@ namespace Swig { class DirectorMethodException : public Swig::DirectorException { public: - DirectorMethodException(const char* msg TSRMLS_DC) - : DirectorException(E_ERROR, "SWIG director method error", msg TSRMLS_CC) - { + DirectorMethodException(const char *msg TSRMLS_DC) + : DirectorException(E_ERROR, "SWIG director method error", msg TSRMLS_CC) { } - static void raise(const char *msg TSRMLS_DC) - { + static void raise(const char *msg TSRMLS_DC) { throw DirectorMethodException(msg TSRMLS_CC); } }; diff --git a/Lib/python/director.swg b/Lib/python/director.swg index d6bfe51f0..baa72c664 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -58,7 +58,7 @@ could stop working when using this option. */ #ifdef SWIG_DIRECTOR_NORTTI -/* +/* When we don't use the native C++ RTTI, we implement a minimal one only for Directors. */ @@ -99,94 +99,77 @@ extern "C" { struct swig_type_info; } -namespace Swig { +namespace Swig { /* memory handler */ - struct GCItem - { + struct GCItem { virtual ~GCItem() {} - virtual int get_own() const - { + virtual int get_own() const { return 0; } }; - struct GCItem_var - { - GCItem_var(GCItem *item = 0) : _item(item) - { + struct GCItem_var { + GCItem_var(GCItem *item = 0) : _item(item) { } - GCItem_var& operator=(GCItem *item) - { + GCItem_var& operator=(GCItem *item) { GCItem *tmp = _item; _item = item; delete tmp; return *this; } - ~GCItem_var() - { + ~GCItem_var() { delete _item; } - - GCItem * operator->() const - { + + GCItem * operator->() const { return _item; } - + private: GCItem *_item; }; - - struct GCItem_Object : GCItem - { - GCItem_Object(int own) : _own(own) - { - } - - virtual ~GCItem_Object() - { + + struct GCItem_Object : GCItem { + GCItem_Object(int own) : _own(own) { } - int get_own() const - { + virtual ~GCItem_Object() { + } + + int get_own() const { return _own; } - + private: int _own; }; template - struct GCItem_T : GCItem - { - GCItem_T(Type *ptr) : _ptr(ptr) - { + struct GCItem_T : GCItem { + GCItem_T(Type *ptr) : _ptr(ptr) { } - - virtual ~GCItem_T() - { + + virtual ~GCItem_T() { delete _ptr; } - + private: Type *_ptr; }; template - struct GCArray_T : GCItem - { - GCArray_T(Type *ptr) : _ptr(ptr) - { + struct GCArray_T : GCItem { + GCArray_T(Type *ptr) : _ptr(ptr) { } - - virtual ~GCArray_T() - { + + virtual ~GCArray_T() { delete[] _ptr; } - + private: Type *_ptr; }; @@ -196,10 +179,8 @@ namespace Swig { protected: std::string swig_msg; public: - DirectorException(PyObject *error, const char *hdr ="", const char *msg ="") - : swig_msg(hdr) - { - SWIG_PYTHON_THREAD_BEGIN_BLOCK; + DirectorException(PyObject *error, const char *hdr ="", const char *msg ="") : swig_msg(hdr) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; if (strlen(msg)) { swig_msg += " "; swig_msg += msg; @@ -207,30 +188,26 @@ namespace Swig { if (!PyErr_Occurred()) { PyErr_SetString(error, getMessage()); } - SWIG_PYTHON_THREAD_END_BLOCK; + SWIG_PYTHON_THREAD_END_BLOCK; } - const char *getMessage() const - { - return swig_msg.c_str(); + const char *getMessage() const { + return swig_msg.c_str(); } - static void raise(PyObject *error, const char *msg) - { + static void raise(PyObject *error, const char *msg) { throw DirectorException(error, msg); } - static void raise(const char *msg) - { + static void raise(const char *msg) { raise(PyExc_RuntimeError, msg); } }; /* unknown exception handler */ - class UnknownExceptionHandler - { + class UnknownExceptionHandler { #ifdef SWIG_DIRECTOR_UEH - static void handler() { + static void handler() { try { throw; } catch (DirectorException& e) { @@ -241,12 +218,12 @@ namespace Swig { } catch (...) { std::cerr << "Unknown exception caught." << std::endl; } - + std::cerr << std::endl << "Python interpreter traceback:" << std::endl; PyErr_Print(); std::cerr << std::endl; - + std::cerr << "This exception was caught by the SWIG unexpected exception handler." << std::endl << "Try using %feature(\"director:except\") to avoid reaching this point." << std::endl << std::endl @@ -255,15 +232,13 @@ namespace Swig { } public: - + std::unexpected_handler old; - UnknownExceptionHandler(std::unexpected_handler nh = handler) - { + UnknownExceptionHandler(std::unexpected_handler nh = handler) { old = std::set_unexpected(nh); } - ~UnknownExceptionHandler() - { + ~UnknownExceptionHandler() { std::set_unexpected(old); } #endif @@ -272,23 +247,19 @@ namespace Swig { /* type mismatch in the return value from a python method call */ class DirectorTypeMismatchException : public Swig::DirectorException { public: - DirectorTypeMismatchException(PyObject *error, const char *msg="") - : Swig::DirectorException(error, "SWIG director type mismatch", msg) - { + DirectorTypeMismatchException(PyObject *error, const char *msg="") + : Swig::DirectorException(error, "SWIG director type mismatch", msg) { } - DirectorTypeMismatchException(const char *msg="") - : Swig::DirectorException(PyExc_TypeError, "SWIG director type mismatch", msg) - { + DirectorTypeMismatchException(const char *msg="") + : Swig::DirectorException(PyExc_TypeError, "SWIG director type mismatch", msg) { } - static void raise(PyObject *error, const char *msg) - { + static void raise(PyObject *error, const char *msg) { throw DirectorTypeMismatchException(error, msg); } - static void raise(const char *msg) - { + static void raise(const char *msg) { throw DirectorTypeMismatchException(msg); } }; @@ -296,28 +267,23 @@ namespace Swig { /* any python exception that occurs during a director method call */ class DirectorMethodException : public Swig::DirectorException { public: - DirectorMethodException(const char *msg = "") - : DirectorException(PyExc_RuntimeError, "SWIG director method error.", msg) - { - } + DirectorMethodException(const char *msg = "") + : DirectorException(PyExc_RuntimeError, "SWIG director method error.", msg) { + } - static void raise(const char *msg) - { + static void raise(const char *msg) { throw DirectorMethodException(msg); } }; /* attempt to call a pure virtual method via a director method */ - class DirectorPureVirtualException : public Swig::DirectorException - { + class DirectorPureVirtualException : public Swig::DirectorException { public: - DirectorPureVirtualException(const char *msg = "") - : DirectorException(PyExc_RuntimeError, "SWIG director pure virtual method called", msg) - { + DirectorPureVirtualException(const char *msg = "") + : DirectorException(PyExc_RuntimeError, "SWIG director pure virtual method called", msg) { } - static void raise(const char *msg) - { + static void raise(const char *msg) { throw DirectorPureVirtualException(msg); } }; @@ -332,24 +298,21 @@ namespace Swig { #ifdef __THREAD__ # include "pythread.h" - class Guard - { - PyThread_type_lock & mutex_; - + class Guard { + PyThread_type_lock &mutex_; + public: - Guard(PyThread_type_lock & mutex) : mutex_(mutex) - { + Guard(PyThread_type_lock & mutex) : mutex_(mutex) { PyThread_acquire_lock(mutex_, WAIT_LOCK); } - - ~Guard() - { + + ~Guard() { PyThread_release_lock(mutex_); } }; # define SWIG_GUARD(mutex) Guard _guard(mutex) #else -# define SWIG_GUARD(mutex) +# define SWIG_GUARD(mutex) #endif /* director base class */ @@ -361,11 +324,11 @@ namespace Swig { mutable bool swig_disown_flag; /* decrement the reference count of the wrapped python object */ - void swig_decref() const { + void swig_decref() const { if (swig_disown_flag) { - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - Py_DECREF(swig_self); - SWIG_PYTHON_THREAD_END_BLOCK; + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + Py_DECREF(swig_self); + SWIG_PYTHON_THREAD_END_BLOCK; } } @@ -375,31 +338,28 @@ namespace Swig { swig_incref(); } - /* discard our reference at destruction */ virtual ~Director() { - swig_decref(); + swig_decref(); } - /* return a pointer to the wrapped python object */ - PyObject *swig_get_self() const { - return swig_self; + PyObject *swig_get_self() const { + return swig_self; } - /* acquire ownership of the wrapped python object (the sense of "disown" - * is from python) */ - void swig_disown() const { - if (!swig_disown_flag) { + /* acquire ownership of the wrapped python object (the sense of "disown" is from python) */ + void swig_disown() const { + if (!swig_disown_flag) { swig_disown_flag=true; - swig_incref(); - } + swig_incref(); + } } /* increase the reference count of the wrapped python object */ - void swig_incref() const { + void swig_incref() const { if (swig_disown_flag) { - Py_INCREF(swig_self); + Py_INCREF(swig_self); } } @@ -407,7 +367,7 @@ namespace Swig { virtual bool swig_get_inner(const char * /* swig_protected_method_name */) const { return true; } - + virtual void swig_set_inner(const char * /* swig_protected_method_name */, bool /* swig_val */) const { } @@ -421,33 +381,29 @@ namespace Swig { public: template - void swig_acquire_ownership_array(Type *vptr) const - { + void swig_acquire_ownership_array(Type *vptr) const { if (vptr) { SWIG_GUARD(swig_mutex_own); swig_owner[vptr] = new GCArray_T(vptr); } } - + template - void swig_acquire_ownership(Type *vptr) const - { + void swig_acquire_ownership(Type *vptr) const { if (vptr) { SWIG_GUARD(swig_mutex_own); swig_owner[vptr] = new GCItem_T(vptr); } } - void swig_acquire_ownership_obj(void *vptr, int own) const - { + void swig_acquire_ownership_obj(void *vptr, int own) const { if (vptr && own) { SWIG_GUARD(swig_mutex_own); swig_owner[vptr] = new GCItem_Object(own); } } - - int swig_release_ownership(void *vptr) const - { + + int swig_release_ownership(void *vptr) const { int own = 0; if (vptr) { SWIG_GUARD(swig_mutex_own); @@ -461,8 +417,7 @@ namespace Swig { } template - static PyObject *swig_pyobj_disown(PyObject *pyobj, PyObject *SWIGUNUSEDPARM(args)) - { + static PyObject *swig_pyobj_disown(PyObject *pyobj, PyObject *SWIGUNUSEDPARM(args)) { SwigPyObject *sobj = (SwigPyObject *)pyobj; sobj->own = 0; Director *d = SWIG_DIRECTOR_CAST(reinterpret_cast(sobj->ptr)); @@ -470,7 +425,6 @@ namespace Swig { d->swig_disown(); return PyWeakref_NewProxy(pyobj, NULL); } - }; #ifdef __THREAD__ diff --git a/Lib/ruby/director.swg b/Lib/ruby/director.swg index a5daf2176..360344f6c 100644 --- a/Lib/ruby/director.swg +++ b/Lib/ruby/director.swg @@ -24,96 +24,78 @@ # define SWIG_DIRECTOR_CAST(ARG) dynamic_cast(ARG) namespace Swig { + /* memory handler */ - struct GCItem - { - virtual ~GCItem() - { + struct GCItem { + virtual ~GCItem() { } - virtual ruby_owntype get_own() const - { + virtual ruby_owntype get_own() const { return 0; } }; - - struct GCItem_var - { - GCItem_var(GCItem *item = 0) : _item(item) - { + + struct GCItem_var { + GCItem_var(GCItem *item = 0) : _item(item) { } - GCItem_var& operator=(GCItem *item) - { + GCItem_var& operator=(GCItem *item) { GCItem *tmp = _item; _item = item; delete tmp; return *this; } - - ~GCItem_var() - { + + ~GCItem_var() { delete _item; } - - GCItem * operator->() const - { + + GCItem *operator->() const { return _item; } - + private: GCItem *_item; }; template - struct GCItem_T : GCItem - { - GCItem_T(Type *ptr) : _ptr(ptr) - { + struct GCItem_T : GCItem { + GCItem_T(Type *ptr) : _ptr(ptr) { } - - virtual ~GCItem_T() - { + + virtual ~GCItem_T() { delete _ptr; } - + private: Type *_ptr; }; - struct GCItem_Object : GCItem - { - GCItem_Object(ruby_owntype own) : _own(own) - { - } - - virtual ~GCItem_Object() - { + struct GCItem_Object : GCItem { + GCItem_Object(ruby_owntype own) : _own(own) { } - ruby_owntype get_own() const - { + virtual ~GCItem_Object() { + } + + ruby_owntype get_own() const { return _own; } - + private: ruby_owntype _own; }; - template - struct GCArray_T : GCItem - { - GCArray_T(Type *ptr) : _ptr(ptr) - { + struct GCArray_T : GCItem { + GCArray_T(Type *ptr) : _ptr(ptr) { } - - virtual ~GCArray_T() - { + + virtual ~GCArray_T() { delete[] _ptr; } - + private: Type *_ptr; }; @@ -126,20 +108,17 @@ namespace Swig { int argc; VALUE *argv; }; - + /* Base class for director exceptions */ class DirectorException { protected: VALUE swig_error; std::string swig_msg; protected: - DirectorException(VALUE error) - : swig_error(error) - { + DirectorException(VALUE error) : swig_error(error) { } - - DirectorException(VALUE error, const char* hdr, const char* msg ="") - : swig_error(error), swig_msg(hdr) { + + DirectorException(VALUE error, const char *hdr, const char *msg ="") : swig_error(error), swig_msg(hdr) { if (strlen(msg)) { swig_msg += " "; swig_msg += msg; @@ -151,25 +130,26 @@ namespace Swig { swig_error = error; } } + public: - VALUE getType() const { - return CLASS_OF(swig_error); + VALUE getType() const { + return CLASS_OF(swig_error); } + VALUE getError() const { return swig_error; } - const std::string& getMessage() const - { + + const std::string& getMessage() const { return swig_msg; } - - virtual ~DirectorException() {} - }; - - /* unknown exception handler */ - class UnknownExceptionHandler - { + virtual ~DirectorException() { + } + }; + + /* unknown exception handler */ + class UnknownExceptionHandler { #ifdef SWIG_DIRECTOR_UEH static void handler() { try { @@ -181,26 +161,24 @@ namespace Swig { std::cerr << "std::exception caught: "<< e.what() << std::endl; } catch (...) { std::cerr << "Unknown exception caught." << std::endl; - } + } std::cerr << std::endl << "Ruby interpreter traceback:" << std::endl; - std::cerr << std::endl; + std::cerr << std::endl; std::cerr << "This exception was caught by the SWIG unexpected exception handler." << std::endl << "Try using %feature(\"director:except\") to avoid reaching this point." << std::endl << std::endl << "Exception is being re-thrown, program will like abort/terminate." << std::endl; throw; } - - public: + + public: std::unexpected_handler old; - UnknownExceptionHandler(std::unexpected_handler nh = handler) - { + UnknownExceptionHandler(std::unexpected_handler nh = handler) { old = std::set_unexpected(nh); } - ~UnknownExceptionHandler() - { + ~UnknownExceptionHandler() { std::set_unexpected(old); } #endif @@ -211,13 +189,11 @@ namespace Swig { class DirectorTypeMismatchException : public Swig::DirectorException { public: DirectorTypeMismatchException(VALUE error, const char *msg="") - : Swig::DirectorException(error, "SWIG director type mismatch", msg) - { + : Swig::DirectorException(error, "SWIG director type mismatch", msg) { } DirectorTypeMismatchException(const char *msg="") - : Swig::DirectorException(rb_eTypeError, "SWIG director type mismatch", msg) - { + : Swig::DirectorException(rb_eTypeError, "SWIG director type mismatch", msg) { } static void raise(VALUE error, const char *msg) { @@ -232,31 +208,28 @@ namespace Swig { /* Any Ruby exception that occurs during a director method call */ class DirectorMethodException : public Swig::DirectorException { public: - DirectorMethodException(VALUE error) + DirectorMethodException(VALUE error) : Swig::DirectorException(error) { } - DirectorMethodException(const char* msg = "") + DirectorMethodException(const char *msg = "") : Swig::DirectorException(rb_eRuntimeError, "SWIG director method error.", msg) { } - - static void raise(VALUE error) - { + + static void raise(VALUE error) { throw DirectorMethodException(error); - } + } }; /* Attempted to call a pure virtual method via a director method */ class DirectorPureVirtualException : public Swig::DirectorException { public: - DirectorPureVirtualException(const char* msg = "") - : DirectorException(rb_eRuntimeError, "SWIG director pure virtual method called", msg) - { + DirectorPureVirtualException(const char *msg = "") + : DirectorException(rb_eRuntimeError, "SWIG director pure virtual method called", msg) { } - static void raise(const char *msg) - { + static void raise(const char *msg) { throw DirectorPureVirtualException(msg); } }; @@ -271,28 +244,25 @@ namespace Swig { # define SWIG_MUTEX_INIT(var) var # else # include -# define SWIG_MUTEX_INIT(var) var = PTHREAD_MUTEX_INITIALIZER +# define SWIG_MUTEX_INIT(var) var = PTHREAD_MUTEX_INITIALIZER # endif #endif #ifdef __PTHREAD__ - struct Guard - { + struct Guard { pthread_mutex_t *_mutex; - - Guard(pthread_mutex_t &mutex) : _mutex(&mutex) - { + + Guard(pthread_mutex_t &mutex) : _mutex(&mutex) { pthread_mutex_lock(_mutex); } - - ~Guard() - { + + ~Guard() { pthread_mutex_unlock(_mutex); } }; # define SWIG_GUARD(mutex) Guard _guard(mutex) #else -# define SWIG_GUARD(mutex) +# define SWIG_GUARD(mutex) #endif /* director base class */ @@ -313,21 +283,20 @@ namespace Swig { } /* return a pointer to the wrapped Ruby object */ - VALUE swig_get_self() const { - return swig_self; + VALUE swig_get_self() const { + return swig_self; } - /* acquire ownership of the wrapped Ruby object (the sense of "disown" - * is from Ruby) */ - void swig_disown() const { - if (!swig_disown_flag) { + /* acquire ownership of the wrapped Ruby object (the sense of "disown" is from Ruby) */ + void swig_disown() const { + if (!swig_disown_flag) { swig_disown_flag = true; - } + } } /* ownership management */ private: - typedef std::map swig_ownership_map; + typedef std::map swig_ownership_map; mutable swig_ownership_map swig_owner; #ifdef __PTHREAD__ static pthread_mutex_t swig_mutex_own; @@ -335,33 +304,29 @@ namespace Swig { public: template - void swig_acquire_ownership_array(Type *vptr) const - { + void swig_acquire_ownership_array(Type *vptr) const { if (vptr) { SWIG_GUARD(swig_mutex_own); swig_owner[vptr] = new GCArray_T(vptr); } } - + template - void swig_acquire_ownership(Type *vptr) const - { + void swig_acquire_ownership(Type *vptr) const { if (vptr) { SWIG_GUARD(swig_mutex_own); swig_owner[vptr] = new GCItem_T(vptr); } } - void swig_acquire_ownership_obj(void *vptr, ruby_owntype own) const - { + void swig_acquire_ownership_obj(void *vptr, ruby_owntype own) const { if (vptr && own) { SWIG_GUARD(swig_mutex_own); swig_owner[vptr] = new GCItem_Object(own); } } - - ruby_owntype swig_release_ownership(void *vptr) const - { + + ruby_owntype swig_release_ownership(void *vptr) const { ruby_owntype own = 0; if (vptr) { SWIG_GUARD(swig_mutex_own); From 1a19451c1ba189319a0ced355c7e6b93eeb6957a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 23 Dec 2013 20:23:54 +0000 Subject: [PATCH 0845/1160] Error out attempting to use directors without -c++ Remove redundant #ifdef __cplusplus markers in director.swg --- Lib/csharp/director.swg | 5 ----- Lib/d/director.swg | 3 --- Lib/java/director.swg | 3 --- Lib/ocaml/director.swg | 3 --- Lib/octave/director.swg | 1 - Lib/perl5/director.swg | 6 +----- Lib/php/director.swg | 4 ---- Lib/python/director.swg | 5 ----- Lib/ruby/director.swg | 5 ----- Source/CParse/parser.y | 3 +++ 10 files changed, 4 insertions(+), 34 deletions(-) diff --git a/Lib/csharp/director.swg b/Lib/csharp/director.swg index c68c2d98f..403a0ac34 100644 --- a/Lib/csharp/director.swg +++ b/Lib/csharp/director.swg @@ -5,8 +5,6 @@ * methods can be called from C++. * ----------------------------------------------------------------------------- */ -#ifdef __cplusplus - #if defined(DEBUG_DIRECTOR_OWNED) #include #endif @@ -45,6 +43,3 @@ namespace Swig { }; } -#endif /* __cplusplus */ - - diff --git a/Lib/d/director.swg b/Lib/d/director.swg index d0ef2372b..6b6537103 100644 --- a/Lib/d/director.swg +++ b/Lib/d/director.swg @@ -5,8 +5,6 @@ * methods can be called from C++. * ----------------------------------------------------------------------------- */ -#ifdef __cplusplus - #if defined(DEBUG_DIRECTOR_OWNED) #include #endif @@ -47,4 +45,3 @@ namespace Swig { }; } -#endif /* __cplusplus */ diff --git a/Lib/java/director.swg b/Lib/java/director.swg index 86880a55e..72f166406 100644 --- a/Lib/java/director.swg +++ b/Lib/java/director.swg @@ -5,8 +5,6 @@ * method calls from C++ to Java extensions. * ----------------------------------------------------------------------------- */ -#ifdef __cplusplus - #if defined(DEBUG_DIRECTOR_OWNED) || defined(DEBUG_DIRECTOR_EXCEPTION) #include #endif @@ -384,4 +382,3 @@ namespace Swig { } -#endif /* __cplusplus */ diff --git a/Lib/ocaml/director.swg b/Lib/ocaml/director.swg index dc4c69b7d..0f997acd0 100644 --- a/Lib/ocaml/director.swg +++ b/Lib/ocaml/director.swg @@ -6,8 +6,6 @@ * * ----------------------------------------------------------------------------- */ -#ifdef __cplusplus - #include # define SWIG_DIRECTOR_CAST(ARG) dynamic_cast(ARG) @@ -100,4 +98,3 @@ namespace Swig { }; } -#endif /* __cplusplus */ diff --git a/Lib/octave/director.swg b/Lib/octave/director.swg index ce4377ef1..96bbf03cc 100644 --- a/Lib/octave/director.swg +++ b/Lib/octave/director.swg @@ -5,7 +5,6 @@ * methods can be called from C++. * ----------------------------------------------------------------------------- */ - # define SWIG_DIRECTOR_CAST(ARG) dynamic_cast(ARG) namespace Swig { diff --git a/Lib/perl5/director.swg b/Lib/perl5/director.swg index 0e7faee6c..9fa64e147 100644 --- a/Lib/perl5/director.swg +++ b/Lib/perl5/director.swg @@ -8,8 +8,6 @@ #ifndef SWIG_DIRECTOR_PERL_HEADER_ #define SWIG_DIRECTOR_PERL_HEADER_ -#ifdef __cplusplus - #include #include #include @@ -316,7 +314,5 @@ namespace Swig { } -#endif /* __cplusplus */ - - #endif + diff --git a/Lib/php/director.swg b/Lib/php/director.swg index b864cff84..2b176ed09 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -8,8 +8,6 @@ #ifndef SWIG_DIRECTOR_PHP_HEADER_ #define SWIG_DIRECTOR_PHP_HEADER_ -#ifdef __cplusplus - #include #include @@ -171,6 +169,4 @@ namespace Swig { // so use a macro to insert TSRMLS_CC so any ZTS context gets passed. #define DirectorMethodException() DirectorMethodException("" TSRMLS_CC) -#endif /* __cplusplus */ - #endif diff --git a/Lib/python/director.swg b/Lib/python/director.swg index baa72c664..3eac683f9 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -8,8 +8,6 @@ #ifndef SWIG_DIRECTOR_PYTHON_HEADER_ #define SWIG_DIRECTOR_PYTHON_HEADER_ -#ifdef __cplusplus - #include #include #include @@ -432,7 +430,4 @@ namespace Swig { #endif } -#endif /* __cplusplus */ - - #endif diff --git a/Lib/ruby/director.swg b/Lib/ruby/director.swg index 360344f6c..23aa6da48 100644 --- a/Lib/ruby/director.swg +++ b/Lib/ruby/director.swg @@ -15,8 +15,6 @@ #endif #endif -#ifdef __cplusplus - #include #include #include @@ -341,6 +339,3 @@ namespace Swig { }; } -#endif /* __cplusplus */ - - diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 40d853387..d01c2fcd1 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2024,6 +2024,9 @@ module_directive: MODULE options idstring { Setattr($$,"options",$2); if (Getattr($2,"directors")) { Wrapper_director_mode_set(1); + if (!cparse_cplusplus) { + Swig_error(cparse_file, cparse_line, "Directors are not supported for C code and require the -c++ option\n"); + } } if (Getattr($2,"dirprot")) { Wrapper_director_protected_mode_set(1); From ad02cb98e6847147b4a6e5d4c327403bc71f9d2c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 27 Nov 2013 14:32:55 +0100 Subject: [PATCH 0846/1160] Relax Java preproc_line_file unit test to pass in a separate build directory. Exact paths comparison doesn't work when SWIG is built in a directory different from the source one, so check whether the path just ends with the expected path components instead. This allows all Java tests to pass in this build configuration. closes #115 --- .../java/preproc_line_file_runme.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Examples/test-suite/java/preproc_line_file_runme.java b/Examples/test-suite/java/preproc_line_file_runme.java index c29cef680..123753fd9 100644 --- a/Examples/test-suite/java/preproc_line_file_runme.java +++ b/Examples/test-suite/java/preproc_line_file_runme.java @@ -11,8 +11,17 @@ public class preproc_line_file_runme { } } - public static String FILENAME_WINDOWS = "..\\..\\..\\..\\Examples\\test-suite\\preproc_line_file.i"; - public static String FILENAME_UNIX = "../../../../Examples/test-suite/preproc_line_file.i"; + private static void test_file(String file, String suffix) throws Throwable + { + String FILENAME_WINDOWS = "Examples\\test-suite\\preproc_line_file.i"; + String FILENAME_UNIX = "Examples/test-suite/preproc_line_file.i"; + + // We don't test for exact equality here because the file names are relative to the build directory, which can be different from the source directory, + // under Unix. But they do need to end with the same path components. + if (!file.endsWith(FILENAME_UNIX + suffix) && !file.endsWith(FILENAME_WINDOWS + suffix)) + throw new RuntimeException("file \"" + file + "\" doesn't end with " + FILENAME_UNIX + suffix); + } + public static void main(String argv[]) throws Throwable { int myline = preproc_line_file.MYLINE; @@ -22,13 +31,8 @@ public class preproc_line_file_runme { if (myline + 100 + 1 != myline_adjusted) throw new RuntimeException("preproc failure"); - String myfile = preproc_line_file.MYFILE; - String myfile_adjusted = preproc_line_file.MYFILE_ADJUSTED; - if (!(myfile.equals(FILENAME_UNIX) || myfile.equals(FILENAME_WINDOWS))) - throw new RuntimeException("preproc failure"); - - if (!(myfile_adjusted.equals(FILENAME_UNIX + ".bak") || myfile_adjusted.equals(FILENAME_WINDOWS + ".bak"))) - throw new RuntimeException("preproc failure"); + test_file(preproc_line_file.MYFILE, ""); + test_file(preproc_line_file.MYFILE_ADJUSTED, ".bak"); if (!preproc_line_file.MY_STRINGNUM_A.equals("my15")) throw new RuntimeException("preproc failed MY_STRINGNUM_A"); @@ -57,9 +61,7 @@ public class preproc_line_file_runme { if (preproc_line_file.INLINE_LINE != 87) throw new RuntimeException("preproc failure"); - String inlineFile = preproc_line_file.INLINE_FILE; - if (!(inlineFile.equals(FILENAME_UNIX) || inlineFile.equals(FILENAME_WINDOWS))) - throw new RuntimeException("preproc failure"); + test_file(preproc_line_file.INLINE_FILE, ""); if (Slash.LINE_NUM != 93) throw new RuntimeException("preproc failure"); From 88a0e228a9c80bedc414164f17b26be0147da333 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 18 Dec 2013 01:28:32 +0100 Subject: [PATCH 0847/1160] Change the length of strings created from fixed-size buffers. Use the usual C rule for NUL-terminated strings instead of discarding all the trailing NUL characters. This was unexpected (as buffers in C code are not necessarily always padded with NULs to their full length) and also inconsistent among languages as this was only done for those of them using typemaps/strings.swg but not for C# or Java, for example, which terminated the string at the first NUL even before this change. Notice that this patch couldn't use strlen() or wcslen() with possibly not NUL-terminated strings, so we had to add [our own equivalents of] strnlen() and wcsnlen() and use them instead. This required adding yet another parameter to string typemap macros, so update the example using them accordingly too. --- CHANGES.current | 8 ++++ Examples/perl5/xmlstring/xmlstring.i | 12 ++++++ .../test-suite/perl5/primitive_types_runme.pl | 2 +- Examples/test-suite/primitive_types.i | 2 +- .../python/primitive_types_runme.py | 2 +- Lib/typemaps/string.swg | 13 +++++- Lib/typemaps/strings.swg | 42 ++++++++++++------- Lib/typemaps/wstring.swg | 14 ++++++- 8 files changed, 75 insertions(+), 20 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 59ebeebcd..680765d40 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,14 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-12-23: vadz + [Octave, Perl, Python, R, Ruby, Tcl] Change the length of strings created from fixed-size char + buffers in C code. + + This is a potential backwards compatibility break: a "char buf[5]" containing "ho\0la" was + returned as a string of length 5 before, but is returned as a string of length 2 now. Apply + "char FIXSIZE[ANY]" typemaps to explicitly choose the old behaviour. + 2013-12-23: talby [Perl] Add support for directors. diff --git a/Examples/perl5/xmlstring/xmlstring.i b/Examples/perl5/xmlstring/xmlstring.i index 3ef53169d..861e1b84d 100644 --- a/Examples/perl5/xmlstring/xmlstring.i +++ b/Examples/perl5/xmlstring/xmlstring.i @@ -93,6 +93,17 @@ SWIG_FromXMLChPtrAndSize(const XMLCh* input, size_t size) } } +%fragment("SWIG_XMLStringNLen","header") { +size_t +SWIG_XMLStringNLen(const XMLCh* s, size_t maxlen) +{ + const XMLCh *p; + for (p = s; maxlen-- && *p; p++) + ; + return p - s; +} +} + %init { if (!SWIG_UTF8Transcoder()) { croak("ERROR: XML::Xerces: INIT: Could not create UTF-8 transcoder"); @@ -106,6 +117,7 @@ SWIG_FromXMLChPtrAndSize(const XMLCh* input, size_t size) SWIG_AsXMLChPtrAndSize, SWIG_FromXMLChPtrAndSize, XERCES_CPP_NAMESPACE::XMLString::stringLen, + SWIG_XMLStringNLen, "", INT_MIN, INT_MAX); diff --git a/Examples/test-suite/perl5/primitive_types_runme.pl b/Examples/test-suite/perl5/primitive_types_runme.pl index 31604ad06..688b241c2 100755 --- a/Examples/test-suite/perl5/primitive_types_runme.pl +++ b/Examples/test-suite/perl5/primitive_types_runme.pl @@ -166,7 +166,7 @@ $t->{var_paramd} = $primitive_types::sct_paramd; $t->{var_paramc} = $primitive_types::sct_paramc; ok($t->v_check(), 'v_check'); -is($primitive_types::def_namet, "ho\0la", "namet"); +is($primitive_types::def_namet, "hola", "namet"); $t->{var_namet} = $primitive_types::def_namet; is($t->{var_namet}, $primitive_types::def_namet, "namet"); diff --git a/Examples/test-suite/primitive_types.i b/Examples/test-suite/primitive_types.i index 9425cc1a0..5e3ce3eed 100644 --- a/Examples/test-suite/primitive_types.i +++ b/Examples/test-suite/primitive_types.i @@ -185,7 +185,7 @@ char* const def_pchar = (char *const)"hello"; const char* const def_pcharc = "hija"; - const namet def_namet = {'h','o',0, 'l','a'}; + const namet def_namet = {'h','o','l','a', 0}; extern namet gbl_namet; diff --git a/Examples/test-suite/python/primitive_types_runme.py b/Examples/test-suite/python/primitive_types_runme.py index be8d38bad..0986da5ad 100644 --- a/Examples/test-suite/python/primitive_types_runme.py +++ b/Examples/test-suite/python/primitive_types_runme.py @@ -165,7 +165,7 @@ t.var_paramc = sct_paramc t.v_check() # this value contains a '0' char! -if def_namet != 'ho\0la': +if def_namet != 'hola': print "bad namet", def_namet raise RuntimeError diff --git a/Lib/typemaps/string.swg b/Lib/typemaps/string.swg index 279ee2a41..1bf0bd15a 100644 --- a/Lib/typemaps/string.swg +++ b/Lib/typemaps/string.swg @@ -17,8 +17,19 @@ SWIG_pchar_descriptor(void) } } +%fragment("SWIG_strnlen","header",fragment="SWIG_FromCharPtrAndSize") { +size_t +SWIG_strnlen(const char* s, size_t maxlen) +{ + const char *p; + for (p = s; maxlen-- && *p; p++) + ; + return p - s; +} +} %include %typemaps_string(%checkcode(STRING), %checkcode(CHAR), - char, Char, SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, strlen, + char, Char, SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, + strlen, SWIG_strnlen, "", CHAR_MIN, CHAR_MAX) diff --git a/Lib/typemaps/strings.swg b/Lib/typemaps/strings.swg index 55e9d2bb5..79ad85cd6 100644 --- a/Lib/typemaps/strings.swg +++ b/Lib/typemaps/strings.swg @@ -22,6 +22,7 @@ SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, SWIG_CharPtrLen, + SWIG_CharBufLen, SWIG_AsCharPtr, SWIG_FromCharPtr, SWIG_AsCharArray, @@ -276,12 +277,13 @@ } %typemap(freearg) const Char (&)[ANY] ""; -%typemap(out,fragment=#SWIG_FromCharPtrAndSize) +%typemap(out,fragment=#SWIG_FromCharPtrAndSize,fragment=#SWIG_CharBufLen) Char [ANY], const Char[ANY] { - size_t size = $1_dim0; %#ifndef SWIG_PRESERVE_CARRAY_SIZE - while (size && ($1[size - 1] == '\0')) --size; + size_t size = SWIG_CharBufLen($1, $1_dim0); +%#else + size_t size = $1_dim0; %#endif %set_output(SWIG_FromCharPtrAndSize($1, size)); } @@ -298,23 +300,25 @@ /* varout */ -%typemap(varout,noblock=1,fragment=#SWIG_FromCharPtrAndSize) +%typemap(varout,noblock=1,fragment=#SWIG_CharBufLen) Char [ANY], const Char [ANY] { - size_t size = $1_dim0; %#ifndef SWIG_PRESERVE_CARRAY_SIZE - while (size && ($1[size - 1] == '\0')) --size; + size_t size = SWIG_CharBufLen($1, $1_dim0); +%#else + size_t size = $1_dim0; %#endif %set_varoutput(SWIG_FromCharPtrAndSize($1, size)); } /* constant */ -%typemap(constcode,fragment=#SWIG_FromCharPtrAndSize) +%typemap(constcode,fragment=#SWIG_CharBufLen) Char [ANY], const Char [ANY] { - size_t size = $value_dim0; %#ifndef SWIG_PRESERVE_CARRAY_SIZE - while (size && ($value[size - 1] == '\0')) --size; + size_t size = SWIG_CharBufLen($1, $1_dim0); +%#else + size_t size = $value_dim0; %#endif %set_constant("$symname", SWIG_FromCharPtrAndSize($value,size)); } @@ -323,12 +327,13 @@ #if defined(SWIG_DIRECTOR_TYPEMAPS) /* directorin */ -%typemap(directorin,fragment=#SWIG_FromCharPtrAndSize) +%typemap(directorin,fragment=#SWIG_CharBufLen) Char [ANY], const Char [ANY] { - size_t size = $1_dim0; %#ifndef SWIG_PRESERVE_CARRAY_SIZE - while (size && ($1[size - 1] == '\0')) --size; + size_t size = SWIG_CharBufLen($1, $1_dim0); +%#else + size_t size = $1_dim0; %#endif $input = SWIG_FromCharPtrAndSize($1, size); } @@ -360,12 +365,13 @@ /* throws */ -%typemap(throws,fragment=#SWIG_FromCharPtrAndSize) +%typemap(throws,fragment=#SWIG_CharBufLen) Char [ANY], const Char[ANY] { - size_t size = $1_dim0; %#ifndef SWIG_PRESERVE_CARRAY_SIZE - while (size && ($1[size - 1] == '\0')) --size; + size_t size = SWIG_CharBufLen($1, $1_dim0); +%#else + size_t size = $1_dim0; %#endif %raise(SWIG_FromCharPtrAndSize($1, size), "$type", 0); } @@ -499,6 +505,7 @@ SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, SWIG_CharPtrLen, + SWIG_CharBufLen, SWIG_NewCopyCharArray, SWIG_DeleteCharArray, FragLimits, CHAR_MIN, CHAR_MAX) @@ -586,6 +593,7 @@ SWIG_AsVal_dec(Char)(SWIG_Object obj, Char *val) SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, SWIG_CharPtrLen, + SWIG_CharBufLen, SWIG_As##CharName##Ptr, SWIG_From##CharName##Ptr, SWIG_As##CharName##Array, @@ -604,12 +612,14 @@ SWIG_AsVal_dec(Char)(SWIG_Object obj, Char *val) SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, SWIG_CharPtrLen, + SWIG_CharBufLen, FragLimits, CHAR_MIN, CHAR_MAX) %_typemap2_string(StringCode, CharCode, Char, CharName, SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, SWIG_CharPtrLen, + SWIG_CharBufLen, %new_copy_array, %delete_array, FragLimits, CHAR_MIN, CHAR_MAX) @@ -624,6 +634,7 @@ SWIG_AsVal_dec(Char)(SWIG_Object obj, Char *val) SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, SWIG_CharPtrLen, + SWIG_CharBufLen, SWIG_NewCopyCharArray, SWIG_DeleteCharArray, FragLimits, CHAR_MIN, CHAR_MAX) @@ -632,6 +643,7 @@ SWIG_AsVal_dec(Char)(SWIG_Object obj, Char *val) SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, SWIG_CharPtrLen, + SWIG_CharBufLen, SWIG_NewCopyCharArray, SWIG_DeleteCharArray, FragLimits, CHAR_MIN, CHAR_MAX) diff --git a/Lib/typemaps/wstring.swg b/Lib/typemaps/wstring.swg index 2567dc782..1f2de8221 100644 --- a/Lib/typemaps/wstring.swg +++ b/Lib/typemaps/wstring.swg @@ -18,8 +18,20 @@ SWIG_pwchar_descriptor() } } +%fragment("SWIG_wcsnlen","header",fragment="SWIG_FromWCharPtrAndSize") { +size_t +SWIG_wcsnlen(const wchar_t* s, size_t maxlen) +{ + const wchar_t *p; + for (p = s; maxlen-- && *p; p++) + ; + return p - s; +} +} + %include %typemaps_string(%checkcode(UNISTRING), %checkcode(UNICHAR), - wchar_t, WChar, SWIG_AsWCharPtrAndSize, SWIG_FromWCharPtrAndSize, wcslen, + wchar_t, WChar, SWIG_AsWCharPtrAndSize, SWIG_FromWCharPtrAndSize, + wcslen, SWIG_wcsnlen, "", WCHAR_MIN, WCHAR_MAX) From cdf1ba912067f306284ab37536862eeeeef8fedb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 Dec 2013 20:47:43 +0100 Subject: [PATCH 0848/1160] Don't accept strings too long to fit in char[N] with trailing NUL. It was previously possible to assign "hello" to a variable backed by char[5] storage in C, and the array contained the correct character data but without the trailing NUL, which was unexpected in C. This is not allowed any more, only "helo" can fit into a char[5] now and anything else fails the type check, just as it already happened for the longer strings before. Closes #122 --- CHANGES.current | 9 +++++++-- Examples/test-suite/perl5/primitive_types_runme.pl | 4 ++-- Examples/test-suite/python/primitive_types_runme.py | 4 ++-- Lib/typemaps/strings.swg | 3 ++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 680765d40..5629532b7 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -10,8 +10,13 @@ Version 3.0.0 (in progress) buffers in C code. This is a potential backwards compatibility break: a "char buf[5]" containing "ho\0la" was - returned as a string of length 5 before, but is returned as a string of length 2 now. Apply - "char FIXSIZE[ANY]" typemaps to explicitly choose the old behaviour. + returned as a string of length 5 before, but is returned as a string of length 2 now. Also, + it was possible to assign a (non-NUL-terminated) string "hello" to such a buffer before but + now this fails and only "helo" can fit. + + Apply "char FIXSIZE[ANY]" typemaps to explicitly choose the old behaviour. + + *** POTENTIAL INCOMPATIBILITY *** 2013-12-23: talby [Perl] Add support for directors. diff --git a/Examples/test-suite/perl5/primitive_types_runme.pl b/Examples/test-suite/perl5/primitive_types_runme.pl index 688b241c2..311c138e0 100755 --- a/Examples/test-suite/perl5/primitive_types_runme.pl +++ b/Examples/test-suite/perl5/primitive_types_runme.pl @@ -170,9 +170,9 @@ is($primitive_types::def_namet, "hola", "namet"); $t->{var_namet} = $primitive_types::def_namet; is($t->{var_namet}, $primitive_types::def_namet, "namet"); -$t->{var_namet} = 'holac'; +$t->{var_namet} = 'hola'; -is($t->{var_namet}, 'holac', "namet"); +is($t->{var_namet}, 'hola', "namet"); $t->{var_namet} = 'hol'; diff --git a/Examples/test-suite/python/primitive_types_runme.py b/Examples/test-suite/python/primitive_types_runme.py index 0986da5ad..d4173b7d3 100644 --- a/Examples/test-suite/python/primitive_types_runme.py +++ b/Examples/test-suite/python/primitive_types_runme.py @@ -174,9 +174,9 @@ if t.var_namet != def_namet: print "bad namet", t.var_namet, def_namet raise RuntimeError -t.var_namet = 'holac' +t.var_namet = 'hola' -if t.var_namet != 'holac': +if t.var_namet != 'hola': print "bad namet", t.var_namet raise RuntimeError diff --git a/Lib/typemaps/strings.swg b/Lib/typemaps/strings.swg index 79ad85cd6..e31e5037f 100644 --- a/Lib/typemaps/strings.swg +++ b/Lib/typemaps/strings.swg @@ -537,7 +537,8 @@ SWIG_As##CharName##Array(SWIG_Object obj, Char *val, size_t size) Char* cptr = 0; size_t csize = 0; int alloc = SWIG_OLDOBJ; int res = SWIG_AsCharPtrAndSize(obj, &cptr, &csize, &alloc); if (SWIG_IsOK(res)) { - if ((csize == size + 1) && cptr && !(cptr[csize-1])) --csize; + /* special case of single char conversion when we don't need space for NUL */ + if (size == 1 && csize == 2 && cptr && !cptr[1]) --csize; if (csize <= size) { if (val) { if (csize) memcpy(val, cptr, csize*sizeof(Char)); From 6b7185989a9c2ff145b011f55a4999018d6cbc63 Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Tue, 24 Dec 2013 06:47:54 +0400 Subject: [PATCH 0849/1160] additional check for template type, to handle constructors correctly --- Source/CParse/parser.y | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index c6fe56b70..0fc1d758a 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2676,8 +2676,8 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va Setattr(templnode,"sym:typename","1"); } /* for now, nested %template is allowed only in the same scope as the template declaration */ - if ($3 && !((currentOuterClass && (currentOuterClass != Getattr(nn, "nested:outer"))) - ||(extendmode && current_class && (current_class != Getattr(nn, "nested:outer"))))) { + if ($3 && !(nnisclass && ((currentOuterClass && (currentOuterClass != Getattr(nn, "nested:outer"))) + ||(extendmode && current_class && (current_class != Getattr(nn, "nested:outer")))))) { /* Comment this out for 1.3.28. We need to re-enable it later but first we need to From 5562deec62e0b4b4dca9bad05a5971dc08d3c982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Tue, 28 May 2013 05:33:56 +0200 Subject: [PATCH 0850/1160] Fixed SF bug #1297 (Python imports) This changeset resolves several issues related to python imports. For example, it's possible now to import modules having same module names, but belonging to different packages. From the user's viewpoint, this patch gives a little bit more control on import directives generated by swig. The user may choose to use relative or absolute imports (docs are provided in separate PR). Some details: - we (still) generate import directives in form 'import a.b.c' which corresponds to absolute imports in python3 and (the only available) ambiguous one in python2. - added -relativeimport option to use explicit relative import syntax (python3), Tests are under Examples/python, these are in fact regression tests but with the current swig testing framework it seems to be impossible to put appropriate tests under test-suite. Closes #7 --- Examples/python/check.list | 1 + Examples/python/import_packages/Makefile | 35 ++ Examples/python/import_packages/README | 2 + .../import_packages/from_init1/Makefile | 25 ++ .../python/import_packages/from_init1/README | 63 ++++ .../import_packages/from_init1/py2/Makefile | 14 + .../from_init1/py2/__init__.py | 0 .../from_init1/py2/pkg2/Makefile | 20 ++ .../from_init1/py2/pkg2/__init__.py | 1 + .../from_init1/py2/pkg2/bar.hpp | 5 + .../import_packages/from_init1/py2/pkg2/bar.i | 6 + .../from_init1/py2/pkg2/foo.hpp | 4 + .../import_packages/from_init1/py2/pkg2/foo.i | 5 + .../import_packages/from_init1/py3/Makefile | 14 + .../from_init1/py3/__init__.py | 0 .../from_init1/py3/pkg2/Makefile | 20 ++ .../from_init1/py3/pkg2/__init__.py | 1 + .../from_init1/py3/pkg2/bar.hpp | 5 + .../import_packages/from_init1/py3/pkg2/bar.i | 6 + .../from_init1/py3/pkg2/foo.hpp | 4 + .../import_packages/from_init1/py3/pkg2/foo.i | 5 + .../import_packages/from_init1/runme.py | 9 + .../import_packages/from_init2/Makefile | 25 ++ .../python/import_packages/from_init2/README | 81 +++++ .../import_packages/from_init2/py2/Makefile | 14 + .../from_init2/py2/__init__.py | 0 .../from_init2/py2/pkg2/Makefile | 18 + .../from_init2/py2/pkg2/__init__.py | 1 + .../from_init2/py2/pkg2/bar.hpp | 5 + .../import_packages/from_init2/py2/pkg2/bar.i | 6 + .../from_init2/py2/pkg2/pkg3/Makefile | 15 + .../from_init2/py2/pkg2/pkg3/__init__.py | 0 .../from_init2/py2/pkg2/pkg3/foo.hpp | 4 + .../from_init2/py2/pkg2/pkg3/foo.i | 5 + .../import_packages/from_init2/py3/Makefile | 14 + .../from_init2/py3/__init__.py | 0 .../from_init2/py3/pkg2/Makefile | 18 + .../from_init2/py3/pkg2/__init__.py | 1 + .../from_init2/py3/pkg2/bar.hpp | 5 + .../import_packages/from_init2/py3/pkg2/bar.i | 6 + .../from_init2/py3/pkg2/pkg3/Makefile | 15 + .../from_init2/py3/pkg2/pkg3/__init__.py | 0 .../from_init2/py3/pkg2/pkg3/foo.hpp | 4 + .../from_init2/py3/pkg2/pkg3/foo.i | 5 + .../import_packages/from_init2/runme.py | 9 + .../import_packages/from_init3/Makefile | 25 ++ .../python/import_packages/from_init3/README | 67 ++++ .../import_packages/from_init3/py2/Makefile | 14 + .../from_init3/py2/__init__.py | 0 .../from_init3/py2/pkg2/Makefile | 18 + .../from_init3/py2/pkg2/__init__.py | 1 + .../from_init3/py2/pkg2/bar.hpp | 5 + .../import_packages/from_init3/py2/pkg2/bar.i | 6 + .../from_init3/py2/pkg2/pkg3/Makefile | 14 + .../from_init3/py2/pkg2/pkg3/__init__.py | 0 .../from_init3/py2/pkg2/pkg3/pkg4/Makefile | 15 + .../from_init3/py2/pkg2/pkg3/pkg4/__init__.py | 0 .../from_init3/py2/pkg2/pkg3/pkg4/foo.hpp | 4 + .../from_init3/py2/pkg2/pkg3/pkg4/foo.i | 5 + .../import_packages/from_init3/py3/Makefile | 14 + .../from_init3/py3/__init__.py | 0 .../from_init3/py3/pkg2/Makefile | 18 + .../from_init3/py3/pkg2/__init__.py | 1 + .../from_init3/py3/pkg2/bar.hpp | 5 + .../import_packages/from_init3/py3/pkg2/bar.i | 6 + .../from_init3/py3/pkg2/pkg3/Makefile | 14 + .../from_init3/py3/pkg2/pkg3/__init__.py | 0 .../from_init3/py3/pkg2/pkg3/pkg4/Makefile | 15 + .../from_init3/py3/pkg2/pkg3/pkg4/__init__.py | 0 .../from_init3/py3/pkg2/pkg3/pkg4/foo.hpp | 4 + .../from_init3/py3/pkg2/pkg3/pkg4/foo.i | 5 + .../import_packages/from_init3/runme.py | 9 + .../import_packages/relativeimport1/Makefile | 25 ++ .../import_packages/relativeimport1/README | 22 ++ .../relativeimport1/py2/Makefile | 14 + .../relativeimport1/py2/__init__.py | 0 .../relativeimport1/py2/pkg2/Makefile | 18 + .../relativeimport1/py2/pkg2/__init__.py | 0 .../relativeimport1/py2/pkg2/bar.hpp | 5 + .../relativeimport1/py2/pkg2/bar.i | 6 + .../relativeimport1/py2/pkg2/pkg3/Makefile | 15 + .../relativeimport1/py2/pkg2/pkg3/__init__.py | 0 .../relativeimport1/py2/pkg2/pkg3/foo.hpp | 4 + .../relativeimport1/py2/pkg2/pkg3/foo.i | 5 + .../relativeimport1/py3/Makefile | 14 + .../relativeimport1/py3/__init__.py | 0 .../relativeimport1/py3/pkg2/Makefile | 18 + .../relativeimport1/py3/pkg2/__init__.py | 0 .../relativeimport1/py3/pkg2/bar.hpp | 5 + .../relativeimport1/py3/pkg2/bar.i | 6 + .../relativeimport1/py3/pkg2/pkg3/Makefile | 15 + .../relativeimport1/py3/pkg2/pkg3/__init__.py | 0 .../relativeimport1/py3/pkg2/pkg3/foo.hpp | 4 + .../relativeimport1/py3/pkg2/pkg3/foo.i | 5 + .../import_packages/relativeimport1/runme.py | 9 + .../import_packages/relativeimport2/Makefile | 25 ++ .../import_packages/relativeimport2/README | 22 ++ .../relativeimport2/py2/Makefile | 14 + .../relativeimport2/py2/__init__.py | 0 .../relativeimport2/py2/pkg2/Makefile | 18 + .../relativeimport2/py2/pkg2/__init__.py | 0 .../relativeimport2/py2/pkg2/bar.hpp | 5 + .../relativeimport2/py2/pkg2/bar.i | 6 + .../relativeimport2/py2/pkg2/pkg3/Makefile | 14 + .../relativeimport2/py2/pkg2/pkg3/__init__.py | 0 .../py2/pkg2/pkg3/pkg4/Makefile | 15 + .../py2/pkg2/pkg3/pkg4/__init__.py | 0 .../py2/pkg2/pkg3/pkg4/foo.hpp | 4 + .../relativeimport2/py2/pkg2/pkg3/pkg4/foo.i | 5 + .../relativeimport2/py3/Makefile | 14 + .../relativeimport2/py3/__init__.py | 0 .../relativeimport2/py3/pkg2/Makefile | 18 + .../relativeimport2/py3/pkg2/__init__.py | 0 .../relativeimport2/py3/pkg2/bar.hpp | 5 + .../relativeimport2/py3/pkg2/bar.i | 6 + .../relativeimport2/py3/pkg2/pkg3/Makefile | 14 + .../relativeimport2/py3/pkg2/pkg3/__init__.py | 0 .../py3/pkg2/pkg3/pkg4/Makefile | 15 + .../py3/pkg2/pkg3/pkg4/__init__.py | 0 .../py3/pkg2/pkg3/pkg4/foo.hpp | 4 + .../relativeimport2/py3/pkg2/pkg3/pkg4/foo.i | 5 + .../import_packages/relativeimport2/runme.py | 9 + .../import_packages/relativeimport2/runme3.py | 9 + .../import_packages/same_modnames1/Makefile | 20 ++ .../import_packages/same_modnames1/README | 26 ++ .../same_modnames1/pkg1/Makefile | 15 + .../same_modnames1/pkg1/__init__.py | 0 .../same_modnames1/pkg1/foo.hpp | 4 + .../import_packages/same_modnames1/pkg1/foo.i | 5 + .../same_modnames1/pkg2/Makefile | 15 + .../same_modnames1/pkg2/__init__.py | 0 .../same_modnames1/pkg2/foo.hpp | 5 + .../import_packages/same_modnames1/pkg2/foo.i | 6 + .../import_packages/same_modnames1/runme.py | 7 + .../import_packages/same_modnames2/Makefile | 20 ++ .../import_packages/same_modnames2/README | 26 ++ .../same_modnames2/pkg1/Makefile | 15 + .../same_modnames2/pkg1/__init__.py | 0 .../same_modnames2/pkg1/foo.hpp | 4 + .../import_packages/same_modnames2/pkg1/foo.i | 5 + .../same_modnames2/pkg1/pkg2/Makefile | 15 + .../same_modnames2/pkg1/pkg2/__init__.py | 0 .../same_modnames2/pkg1/pkg2/foo.hpp | 5 + .../same_modnames2/pkg1/pkg2/foo.i | 6 + .../import_packages/same_modnames2/runme.py | 4 + Source/Modules/python.cxx | 325 ++++++++++++++++-- 146 files changed, 1676 insertions(+), 30 deletions(-) create mode 100644 Examples/python/import_packages/Makefile create mode 100644 Examples/python/import_packages/README create mode 100644 Examples/python/import_packages/from_init1/Makefile create mode 100644 Examples/python/import_packages/from_init1/README create mode 100644 Examples/python/import_packages/from_init1/py2/Makefile create mode 100644 Examples/python/import_packages/from_init1/py2/__init__.py create mode 100644 Examples/python/import_packages/from_init1/py2/pkg2/Makefile create mode 100644 Examples/python/import_packages/from_init1/py2/pkg2/__init__.py create mode 100644 Examples/python/import_packages/from_init1/py2/pkg2/bar.hpp create mode 100644 Examples/python/import_packages/from_init1/py2/pkg2/bar.i create mode 100644 Examples/python/import_packages/from_init1/py2/pkg2/foo.hpp create mode 100644 Examples/python/import_packages/from_init1/py2/pkg2/foo.i create mode 100644 Examples/python/import_packages/from_init1/py3/Makefile create mode 100644 Examples/python/import_packages/from_init1/py3/__init__.py create mode 100644 Examples/python/import_packages/from_init1/py3/pkg2/Makefile create mode 100644 Examples/python/import_packages/from_init1/py3/pkg2/__init__.py create mode 100644 Examples/python/import_packages/from_init1/py3/pkg2/bar.hpp create mode 100644 Examples/python/import_packages/from_init1/py3/pkg2/bar.i create mode 100644 Examples/python/import_packages/from_init1/py3/pkg2/foo.hpp create mode 100644 Examples/python/import_packages/from_init1/py3/pkg2/foo.i create mode 100644 Examples/python/import_packages/from_init1/runme.py create mode 100644 Examples/python/import_packages/from_init2/Makefile create mode 100644 Examples/python/import_packages/from_init2/README create mode 100644 Examples/python/import_packages/from_init2/py2/Makefile create mode 100644 Examples/python/import_packages/from_init2/py2/__init__.py create mode 100644 Examples/python/import_packages/from_init2/py2/pkg2/Makefile create mode 100644 Examples/python/import_packages/from_init2/py2/pkg2/__init__.py create mode 100644 Examples/python/import_packages/from_init2/py2/pkg2/bar.hpp create mode 100644 Examples/python/import_packages/from_init2/py2/pkg2/bar.i create mode 100644 Examples/python/import_packages/from_init2/py2/pkg2/pkg3/Makefile create mode 100644 Examples/python/import_packages/from_init2/py2/pkg2/pkg3/__init__.py create mode 100644 Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.hpp create mode 100644 Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.i create mode 100644 Examples/python/import_packages/from_init2/py3/Makefile create mode 100644 Examples/python/import_packages/from_init2/py3/__init__.py create mode 100644 Examples/python/import_packages/from_init2/py3/pkg2/Makefile create mode 100644 Examples/python/import_packages/from_init2/py3/pkg2/__init__.py create mode 100644 Examples/python/import_packages/from_init2/py3/pkg2/bar.hpp create mode 100644 Examples/python/import_packages/from_init2/py3/pkg2/bar.i create mode 100644 Examples/python/import_packages/from_init2/py3/pkg2/pkg3/Makefile create mode 100644 Examples/python/import_packages/from_init2/py3/pkg2/pkg3/__init__.py create mode 100644 Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.hpp create mode 100644 Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.i create mode 100644 Examples/python/import_packages/from_init2/runme.py create mode 100644 Examples/python/import_packages/from_init3/Makefile create mode 100644 Examples/python/import_packages/from_init3/README create mode 100644 Examples/python/import_packages/from_init3/py2/Makefile create mode 100644 Examples/python/import_packages/from_init3/py2/__init__.py create mode 100644 Examples/python/import_packages/from_init3/py2/pkg2/Makefile create mode 100644 Examples/python/import_packages/from_init3/py2/pkg2/__init__.py create mode 100644 Examples/python/import_packages/from_init3/py2/pkg2/bar.hpp create mode 100644 Examples/python/import_packages/from_init3/py2/pkg2/bar.i create mode 100644 Examples/python/import_packages/from_init3/py2/pkg2/pkg3/Makefile create mode 100644 Examples/python/import_packages/from_init3/py2/pkg2/pkg3/__init__.py create mode 100644 Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/Makefile create mode 100644 Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/__init__.py create mode 100644 Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.hpp create mode 100644 Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.i create mode 100644 Examples/python/import_packages/from_init3/py3/Makefile create mode 100644 Examples/python/import_packages/from_init3/py3/__init__.py create mode 100644 Examples/python/import_packages/from_init3/py3/pkg2/Makefile create mode 100644 Examples/python/import_packages/from_init3/py3/pkg2/__init__.py create mode 100644 Examples/python/import_packages/from_init3/py3/pkg2/bar.hpp create mode 100644 Examples/python/import_packages/from_init3/py3/pkg2/bar.i create mode 100644 Examples/python/import_packages/from_init3/py3/pkg2/pkg3/Makefile create mode 100644 Examples/python/import_packages/from_init3/py3/pkg2/pkg3/__init__.py create mode 100644 Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/Makefile create mode 100644 Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/__init__.py create mode 100644 Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.hpp create mode 100644 Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.i create mode 100644 Examples/python/import_packages/from_init3/runme.py create mode 100644 Examples/python/import_packages/relativeimport1/Makefile create mode 100644 Examples/python/import_packages/relativeimport1/README create mode 100644 Examples/python/import_packages/relativeimport1/py2/Makefile create mode 100644 Examples/python/import_packages/relativeimport1/py2/__init__.py create mode 100644 Examples/python/import_packages/relativeimport1/py2/pkg2/Makefile create mode 100644 Examples/python/import_packages/relativeimport1/py2/pkg2/__init__.py create mode 100644 Examples/python/import_packages/relativeimport1/py2/pkg2/bar.hpp create mode 100644 Examples/python/import_packages/relativeimport1/py2/pkg2/bar.i create mode 100644 Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/Makefile create mode 100644 Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/__init__.py create mode 100644 Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.hpp create mode 100644 Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.i create mode 100644 Examples/python/import_packages/relativeimport1/py3/Makefile create mode 100644 Examples/python/import_packages/relativeimport1/py3/__init__.py create mode 100644 Examples/python/import_packages/relativeimport1/py3/pkg2/Makefile create mode 100644 Examples/python/import_packages/relativeimport1/py3/pkg2/__init__.py create mode 100644 Examples/python/import_packages/relativeimport1/py3/pkg2/bar.hpp create mode 100644 Examples/python/import_packages/relativeimport1/py3/pkg2/bar.i create mode 100644 Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/Makefile create mode 100644 Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/__init__.py create mode 100644 Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.hpp create mode 100644 Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.i create mode 100644 Examples/python/import_packages/relativeimport1/runme.py create mode 100644 Examples/python/import_packages/relativeimport2/Makefile create mode 100644 Examples/python/import_packages/relativeimport2/README create mode 100644 Examples/python/import_packages/relativeimport2/py2/Makefile create mode 100644 Examples/python/import_packages/relativeimport2/py2/__init__.py create mode 100644 Examples/python/import_packages/relativeimport2/py2/pkg2/Makefile create mode 100644 Examples/python/import_packages/relativeimport2/py2/pkg2/__init__.py create mode 100644 Examples/python/import_packages/relativeimport2/py2/pkg2/bar.hpp create mode 100644 Examples/python/import_packages/relativeimport2/py2/pkg2/bar.i create mode 100644 Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/Makefile create mode 100644 Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/__init__.py create mode 100644 Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/Makefile create mode 100644 Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/__init__.py create mode 100644 Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.hpp create mode 100644 Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.i create mode 100644 Examples/python/import_packages/relativeimport2/py3/Makefile create mode 100644 Examples/python/import_packages/relativeimport2/py3/__init__.py create mode 100644 Examples/python/import_packages/relativeimport2/py3/pkg2/Makefile create mode 100644 Examples/python/import_packages/relativeimport2/py3/pkg2/__init__.py create mode 100644 Examples/python/import_packages/relativeimport2/py3/pkg2/bar.hpp create mode 100644 Examples/python/import_packages/relativeimport2/py3/pkg2/bar.i create mode 100644 Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/Makefile create mode 100644 Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/__init__.py create mode 100644 Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/Makefile create mode 100644 Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/__init__.py create mode 100644 Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.hpp create mode 100644 Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.i create mode 100644 Examples/python/import_packages/relativeimport2/runme.py create mode 100644 Examples/python/import_packages/relativeimport2/runme3.py create mode 100644 Examples/python/import_packages/same_modnames1/Makefile create mode 100644 Examples/python/import_packages/same_modnames1/README create mode 100644 Examples/python/import_packages/same_modnames1/pkg1/Makefile create mode 100644 Examples/python/import_packages/same_modnames1/pkg1/__init__.py create mode 100644 Examples/python/import_packages/same_modnames1/pkg1/foo.hpp create mode 100644 Examples/python/import_packages/same_modnames1/pkg1/foo.i create mode 100644 Examples/python/import_packages/same_modnames1/pkg2/Makefile create mode 100644 Examples/python/import_packages/same_modnames1/pkg2/__init__.py create mode 100644 Examples/python/import_packages/same_modnames1/pkg2/foo.hpp create mode 100644 Examples/python/import_packages/same_modnames1/pkg2/foo.i create mode 100644 Examples/python/import_packages/same_modnames1/runme.py create mode 100644 Examples/python/import_packages/same_modnames2/Makefile create mode 100644 Examples/python/import_packages/same_modnames2/README create mode 100644 Examples/python/import_packages/same_modnames2/pkg1/Makefile create mode 100644 Examples/python/import_packages/same_modnames2/pkg1/__init__.py create mode 100644 Examples/python/import_packages/same_modnames2/pkg1/foo.hpp create mode 100644 Examples/python/import_packages/same_modnames2/pkg1/foo.i create mode 100644 Examples/python/import_packages/same_modnames2/pkg1/pkg2/Makefile create mode 100644 Examples/python/import_packages/same_modnames2/pkg1/pkg2/__init__.py create mode 100644 Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.hpp create mode 100644 Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.i create mode 100644 Examples/python/import_packages/same_modnames2/runme.py diff --git a/Examples/python/check.list b/Examples/python/check.list index 7cfe437f0..e9e7c8357 100644 --- a/Examples/python/check.list +++ b/Examples/python/check.list @@ -13,6 +13,7 @@ funcptr2 functor import import_template +import_packages java #libffi multimap diff --git a/Examples/python/import_packages/Makefile b/Examples/python/import_packages/Makefile new file mode 100644 index 000000000..fda2380b3 --- /dev/null +++ b/Examples/python/import_packages/Makefile @@ -0,0 +1,35 @@ +TOP = ../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +import_packages_subdirs = \ + same_modnames1 \ + same_modnames2 \ + from_init1 \ + from_init2 \ + from_init3 \ + relativeimport1 \ + relativeimport1 + +check: build + for s in $(import_packages_subdirs); do \ + (cd $$s && $(MAKE) check); \ + done + +build: + for s in $(import_packages_subdirs); do \ + (cd $$s && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build); \ + done + +static: + for s in $(import_packages_subdirs); do \ + (cd $$s && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static); \ + done + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + for s in $(import_packages_subdirs); do \ + (cd $$s && $(MAKE) clean); \ + done diff --git a/Examples/python/import_packages/README b/Examples/python/import_packages/README new file mode 100644 index 000000000..69fe3516e --- /dev/null +++ b/Examples/python/import_packages/README @@ -0,0 +1,2 @@ +These are actually regression tests for SF bug #1297 (GH issue #7). +See individual READMEs in subdirectories. diff --git a/Examples/python/import_packages/from_init1/Makefile b/Examples/python/import_packages/from_init1/Makefile new file mode 100644 index 000000000..8e35c6c61 --- /dev/null +++ b/Examples/python/import_packages/from_init1/Makefile @@ -0,0 +1,25 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +ifeq (,$(PY3)) + PKG1DIR = "py2" +else + PKG1DIR = "py3" +endif + +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + +static: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd py2 && $(MAKE) clean + cd py3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init1/README b/Examples/python/import_packages/from_init1/README new file mode 100644 index 000000000..e7d7eca9e --- /dev/null +++ b/Examples/python/import_packages/from_init1/README @@ -0,0 +1,63 @@ +This example tests the %import directive and python import from __init__.py. + +This case is not correctly handled by swig 2. + +The issue was reported as Source Forge bug #1297 and later as GitHub issue #7. + +Use 'python runme.py' to run a test. + + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pyX/pkg2/foo.i - Pkg2_Foo class + pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg2_Foo + +and the package pyX.pkg2 has: + + pyX/pkg2/__init__.py - which imports something from "bar" module (we + import Pkg2_Bar class, but it is not the clue, + the clue is the 'from' keyword) + +For example with python2.x the py2/pkg2/__init__.py imports Pkg2_Bar class +as follows + + from bar import Pkg2_Bar # [1] + +Such cases doesn't work when fully qualified python module names are used by +swig (swig 2.0.10, e.g.) to generate python import directives (SF bug #1297). +The generated file "py2/pkg2/bar.py" has following lines: + + import py2.pkg2.foo # [2] + class Pkg2_Bar(py2.pkg2.foo.Pkg2_Foo): # [3] + +but it's not possible to import anything from py2.pkg2 subpackage, e.g. + + import py2.pkg2 + +fails with the following exception: + +Traceback (most recent call last): + File "runme.py", line 3, in + import py2.pkg2 + File "py2/pkg2/__init__.py", line 7, in + from .bar import Pkg2_Bar + File "py2/pkg2/bar.py", line 71, in + class Pkg2_Bar(py2.pkg2.foo.Pkg2_Foo): + AttributeError: 'module' object has no attribute 'pkg2' + + +It seems like during the import [1], the sub-package pkg2 is not yet fully +initialized, so py2.pkg2 is not known. The above exception is raised at +line [3]. The problem disappears, for example, if we force swig to use relative +package names. + +If everything works well, the package py2.pkg2 shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/from_init1/py2/Makefile b/Examples/python/import_packages/from_init1/py2/Makefile new file mode 100644 index 000000000..4c0dfab07 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init1/py2/__init__.py b/Examples/python/import_packages/from_init1/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/Makefile b/Examples/python/import_packages/from_init1/py2/pkg2/Makefile new file mode 100644 index 000000000..0dd174659 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/Makefile @@ -0,0 +1,20 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp_static + +clean:: + $(MAKE) -f $(TOP)/Makefile TARGET='foo' python_clean + $(MAKE) -f $(TOP)/Makefile TARGET='bar' python_clean diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/__init__.py b/Examples/python/import_packages/from_init1/py2/pkg2/__init__.py new file mode 100644 index 000000000..0f9c90203 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/__init__.py @@ -0,0 +1 @@ +from bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/bar.hpp b/Examples/python/import_packages/from_init1/py2/pkg2/bar.hpp new file mode 100644 index 000000000..b369161d3 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY2_PKG2_BAR_HPP +#define PY2_PKG2_BAR_HPP +#include "../../py2/pkg2/foo.hpp" +struct Pkg2_Bar : Pkg2_Foo {}; +#endif /* PY2_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/bar.i b/Examples/python/import_packages/from_init1/py2/pkg2/bar.i new file mode 100644 index 000000000..0795a7751 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import "../../py2/pkg2/foo.i" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/foo.hpp b/Examples/python/import_packages/from_init1/py2/pkg2/foo.hpp new file mode 100644 index 000000000..fed8239f6 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY2_PKG2_FOO_HPP +#define PY2_PKG2_FOO_HPP +struct Pkg2_Foo {}; +#endif /* PY2_PKG2_FOO_HPP */ diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/foo.i b/Examples/python/import_packages/from_init1/py2/pkg2/foo.i new file mode 100644 index 000000000..37b2e1f82 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/foo.i @@ -0,0 +1,5 @@ +%module(package="py2.pkg2") foo +%{ +#include "../../py2/pkg2/foo.hpp" +%} +%include "../../py2/pkg2/foo.hpp" diff --git a/Examples/python/import_packages/from_init1/py3/Makefile b/Examples/python/import_packages/from_init1/py3/Makefile new file mode 100644 index 000000000..4c0dfab07 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init1/py3/__init__.py b/Examples/python/import_packages/from_init1/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/Makefile b/Examples/python/import_packages/from_init1/py3/pkg2/Makefile new file mode 100644 index 000000000..0dd174659 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/Makefile @@ -0,0 +1,20 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp_static + +clean:: + $(MAKE) -f $(TOP)/Makefile TARGET='foo' python_clean + $(MAKE) -f $(TOP)/Makefile TARGET='bar' python_clean diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/__init__.py b/Examples/python/import_packages/from_init1/py3/pkg2/__init__.py new file mode 100644 index 000000000..2097aaf2e --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/__init__.py @@ -0,0 +1 @@ +from .bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/bar.hpp b/Examples/python/import_packages/from_init1/py3/pkg2/bar.hpp new file mode 100644 index 000000000..d16463dff --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY3_PKG2_BAR_HPP +#define PY3_PKG2_BAR_HPP +#include "../../py3/pkg2/foo.hpp" +struct Pkg2_Bar : Pkg2_Foo {}; +#endif /* PY3_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/bar.i b/Examples/python/import_packages/from_init1/py3/pkg2/bar.i new file mode 100644 index 000000000..8d8d627b9 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import "../../py3/pkg2/foo.i" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/foo.hpp b/Examples/python/import_packages/from_init1/py3/pkg2/foo.hpp new file mode 100644 index 000000000..c2469dc86 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY3_PKG2_FOO_HPP +#define PY3_PKG2_FOO_HPP +struct Pkg2_Foo {}; +#endif /* PY3_PKG2_FOO_HPP */ diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/foo.i b/Examples/python/import_packages/from_init1/py3/pkg2/foo.i new file mode 100644 index 000000000..76613b593 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/foo.i @@ -0,0 +1,5 @@ +%module(package="py3.pkg2") foo +%{ +#include "../../py3/pkg2/foo.hpp" +%} +%include "../../py3/pkg2/foo.hpp" diff --git a/Examples/python/import_packages/from_init1/runme.py b/Examples/python/import_packages/from_init1/runme.py new file mode 100644 index 000000000..c23a085fa --- /dev/null +++ b/Examples/python/import_packages/from_init1/runme.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print "Testing %module(package=...) + python 'import' in __init__.py" +import sys +if sys.version_info < (3,0): + import py2.pkg2 + print " Finished importing py2.pkg2" +else: + import py3.pkg2 + print " Finished importing py3.pkg2" diff --git a/Examples/python/import_packages/from_init2/Makefile b/Examples/python/import_packages/from_init2/Makefile new file mode 100644 index 000000000..8e35c6c61 --- /dev/null +++ b/Examples/python/import_packages/from_init2/Makefile @@ -0,0 +1,25 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +ifeq (,$(PY3)) + PKG1DIR = "py2" +else + PKG1DIR = "py3" +endif + +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + +static: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd py2 && $(MAKE) clean + cd py3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init2/README b/Examples/python/import_packages/from_init2/README new file mode 100644 index 000000000..a0eb41839 --- /dev/null +++ b/Examples/python/import_packages/from_init2/README @@ -0,0 +1,81 @@ +This example tests the %import directive and python import from __init__.py. + +This case is not correctly handled by swig 2. + +The issue was reported as Source Forge bug #1297 and later as GitHub issue #7. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pyX/pkg2/pkg3/foo.i - Pkg3_Foo class + pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg3_Foo + +and the package pyX.pkg2 has: + + pyX/pkg2/__init__.py - which imports something from "bar" module + +For example with python 2.x the py2/pkg2/__init__.py imports Pkg2_Bar class as +follows + + from bar import Pkg2_Bar # [1] + +Such cases doesn't work when fully qualified python module names are used by +swig to generate python import directives (SF bug #1297). The generated file +"py2/pkg2/bar.py" has following lines: + + import py2.pkg2.pkg3.foo # [2] + class Pkg2_Bar(py2.pkg2.pkg3.foo.Pkg3_Foo): # [3] + +and it's not possible to import anything from py2.pkg2 subpackage, e.g. + + import py2.pkg2 + +fails with the following exception: + +Traceback (most recent call last): + File "runme.py", line 3, in + import py2.pkg2 + File "py2/pkg2/__init__.py", line 4, in + from bar import Pkg2_Bar + File "py2/pkg2/bar.py", line 71, in + class Pkg2_Bar(py2.pkg2.pkg3.foo.Pkg3_Foo): +AttributeError: 'module' object has no attribute 'pkg2' + +It seems like during the import [1], the subpackage pkg2 is not yet fully +initialized, so pyX.pkg2 is not known. The above exception is raised at line [3]. +The problem disappears, for example, if we force swig to use relative package +names. + +The difference between this ('from_init2') case and the case +'from_init1' is that here it's not sufficient to import relative module +by just ignoring the package part of the fully qualified module name. IOW +it is not correct to force swig to put: + + import foo + class Pkg2_Bar(foo.Pkg3_Foo) + +into pyX/pkg2/bar.py (note, that this would work for 'from_init1' case). +The import directive shall be rather: + + import pkg3.foo + +for python 2.x and: + + from . import pkg3 + import pkg3.foo + +for python 3, and the class definition shall begin with: + + class Pkg2_Bar(pkg3.foo.Pkg3_Foo) + +If everything works well, the package pyX.pkg2 shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/from_init2/py2/Makefile b/Examples/python/import_packages/from_init2/py2/Makefile new file mode 100644 index 000000000..4c0dfab07 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init2/py2/__init__.py b/Examples/python/import_packages/from_init2/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/Makefile b/Examples/python/import_packages/from_init2/py2/pkg2/Makefile new file mode 100644 index 000000000..3fe56139d --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/__init__.py b/Examples/python/import_packages/from_init2/py2/pkg2/__init__.py new file mode 100644 index 000000000..0f9c90203 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/__init__.py @@ -0,0 +1 @@ +from bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/bar.hpp b/Examples/python/import_packages/from_init2/py2/pkg2/bar.hpp new file mode 100644 index 000000000..8f09cd5fa --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY2_PKG2_BAR_HPP +#define PY2_PKG2_BAR_HPP +#include "../../py2/pkg2/pkg3/foo.hpp" +struct Pkg2_Bar : Pkg3_Foo {}; +#endif /* PY2_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/bar.i b/Examples/python/import_packages/from_init2/py2/pkg2/bar.i new file mode 100644 index 000000000..28a4c906e --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import "../../py2/pkg2/pkg3/foo.i" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/Makefile new file mode 100644 index 000000000..a417e2745 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='foo' python_clean diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/__init__.py b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.hpp b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.hpp new file mode 100644 index 000000000..b6c89a431 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY2_PKG2_PKG3_FOO_HPP +#define PY2_PKG2_PKG3_FOO_HPP +struct Pkg3_Foo {}; +#endif /* PY2_PKG2_PKG3_FOO_HPP */ diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.i b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.i new file mode 100644 index 000000000..ba32483d2 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.i @@ -0,0 +1,5 @@ +%module(package="py2.pkg2.pkg3") foo +%{ +#include "../../../py2/pkg2/pkg3/foo.hpp" +%} +%include "../../../py2/pkg2/pkg3/foo.hpp" diff --git a/Examples/python/import_packages/from_init2/py3/Makefile b/Examples/python/import_packages/from_init2/py3/Makefile new file mode 100644 index 000000000..4c0dfab07 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init2/py3/__init__.py b/Examples/python/import_packages/from_init2/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/Makefile b/Examples/python/import_packages/from_init2/py3/pkg2/Makefile new file mode 100644 index 000000000..3fe56139d --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/__init__.py b/Examples/python/import_packages/from_init2/py3/pkg2/__init__.py new file mode 100644 index 000000000..2097aaf2e --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/__init__.py @@ -0,0 +1 @@ +from .bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/bar.hpp b/Examples/python/import_packages/from_init2/py3/pkg2/bar.hpp new file mode 100644 index 000000000..408d910d7 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY3_PKG2_BAR_HPP +#define PY3_PKG2_BAR_HPP +#include "../../py3/pkg2/pkg3/foo.hpp" +struct Pkg2_Bar : Pkg3_Foo {}; +#endif /* PY3_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/bar.i b/Examples/python/import_packages/from_init2/py3/pkg2/bar.i new file mode 100644 index 000000000..1468932ff --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import "../../py3/pkg2/pkg3/foo.i" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/Makefile new file mode 100644 index 000000000..a417e2745 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='foo' python_clean diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/__init__.py b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.hpp b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.hpp new file mode 100644 index 000000000..531721d36 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY3_PKG2_PKG3_FOO_HPP +#define PY3_PKG2_PKG3_FOO_HPP +struct Pkg3_Foo {}; +#endif /* PY3_PKG2_PKG3_FOO_HPP */ diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.i b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.i new file mode 100644 index 000000000..c6ba529b7 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.i @@ -0,0 +1,5 @@ +%module(package="py3.pkg2.pkg3") foo +%{ +#include "../../../py3/pkg2/pkg3/foo.hpp" +%} +%include "../../../py3/pkg2/pkg3/foo.hpp" diff --git a/Examples/python/import_packages/from_init2/runme.py b/Examples/python/import_packages/from_init2/runme.py new file mode 100644 index 000000000..c23a085fa --- /dev/null +++ b/Examples/python/import_packages/from_init2/runme.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print "Testing %module(package=...) + python 'import' in __init__.py" +import sys +if sys.version_info < (3,0): + import py2.pkg2 + print " Finished importing py2.pkg2" +else: + import py3.pkg2 + print " Finished importing py3.pkg2" diff --git a/Examples/python/import_packages/from_init3/Makefile b/Examples/python/import_packages/from_init3/Makefile new file mode 100644 index 000000000..8e35c6c61 --- /dev/null +++ b/Examples/python/import_packages/from_init3/Makefile @@ -0,0 +1,25 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +ifeq (,$(PY3)) + PKG1DIR = "py2" +else + PKG1DIR = "py3" +endif + +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + +static: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd py2 && $(MAKE) clean + cd py3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/README b/Examples/python/import_packages/from_init3/README new file mode 100644 index 000000000..131d5894c --- /dev/null +++ b/Examples/python/import_packages/from_init3/README @@ -0,0 +1,67 @@ +This example tests the %import directive and python import from __init__.py. + +This case is not correctly handled by swig 2. + +The issue was reported as Source Forge bug #1297 and later as GitHub issue #7. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pyX/pkg2/pkg3/pkg4/foo.i - Pkg4_Foo class + pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg4_Foo + +and the package pyX.pkg2 has: + + pyX/pkg2/__init__.py - which imports something from "bar" module + +For example with python 2.x the py2/pkg2/__init__.py imports Pkg2_Bar class as +follows + + from bar import Pkg2_Bar # [1] + +Such cases doesn't work when fully qualified python module names are used by +swig to generate python import directives (SF bug 1297). The generated file +"py2/pkg2/bar.py" has following lines: + + import py2.pkg2.pkg3.pkg4.foo # [2] + class Pkg2_Bar(py2.pkg2.pkg3.pkg4.foo.P1_S1_S2_Foo): # [3] + +and it's not possible to import anything from py2.pkg2 subpackage, e.g. + + import py2.pkg2 + +fails with the following exception: + + Traceback (most recent call last): + File "runme.py", line 3, in + import py2.pkg2 + File "py2/pkg2/__init__.py", line 4, in + from bar import Pkg2_Bar + File "py2/pkg2/bar.py", line 71, in + class Pkg2_Bar(py2.pkg2.pkg3.pkg4.foo.Pkg4_Foo): + AttributeError: 'module' object has no attribute 'pkg2' + +It seems like during the import [1], the subpackage pkg2 is not yet fully +initialized, so py2.pkg2 can't be used. The above exception is raised at +line [3]. The problem disappears, for example, if we force swig to use relative +package names. + +The difference between this ('from_init3') case and the case +'from_init2' is that here we import base class from module +pyX.pkg2.pkg3.pkg4.foo, which is nested deeper than it was in +'from_init2'. This is just to ensure, that two (and more) levels of +subpackages get imported correctly by generated python code, i.e, not only +'pkg3.foo' is handled properly (one-level subpackage) but the code works also +for 'pkg3.pkg4.foo', and so on. + +If everything works well, the package pyX.pkg2 shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/from_init3/py2/Makefile b/Examples/python/import_packages/from_init3/py2/Makefile new file mode 100644 index 000000000..4c0dfab07 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py2/__init__.py b/Examples/python/import_packages/from_init3/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/Makefile b/Examples/python/import_packages/from_init3/py2/pkg2/Makefile new file mode 100644 index 000000000..3fe56139d --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/__init__.py b/Examples/python/import_packages/from_init3/py2/pkg2/__init__.py new file mode 100644 index 000000000..0f9c90203 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/__init__.py @@ -0,0 +1 @@ +from bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/bar.hpp b/Examples/python/import_packages/from_init3/py2/pkg2/bar.hpp new file mode 100644 index 000000000..20a00190a --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY2_PKG2_HPP +#define PY2_PKG2_HPP +#include "../../py2/pkg2/pkg3/pkg4/foo.hpp" +struct Pkg2_Bar : Pkg4_Foo {}; +#endif /* PY2_PKG2_HPP */ diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/bar.i b/Examples/python/import_packages/from_init3/py2/pkg2/bar.i new file mode 100644 index 000000000..0a932a2b9 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import "../../py2/pkg2/pkg3/pkg4/foo.i" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/Makefile new file mode 100644 index 000000000..470f9d561 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg4 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/__init__.py b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/Makefile b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/Makefile new file mode 100644 index 000000000..a98d31122 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='foo' python_clean diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/__init__.py b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.hpp b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.hpp new file mode 100644 index 000000000..2df933c59 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY2_PKG2_PKG3_PKG4 +#define PY2_PKG2_PKG3_PKG4 +struct Pkg4_Foo {}; +#endif /* PY2_PKG2_PKG3_PKG4 */ diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.i b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.i new file mode 100644 index 000000000..311d7161c --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.i @@ -0,0 +1,5 @@ +%module(package="py2.pkg2.pkg3.pkg4") foo +%{ +#include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp" +%} +%include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp" diff --git a/Examples/python/import_packages/from_init3/py3/Makefile b/Examples/python/import_packages/from_init3/py3/Makefile new file mode 100644 index 000000000..4c0dfab07 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py3/__init__.py b/Examples/python/import_packages/from_init3/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/Makefile b/Examples/python/import_packages/from_init3/py3/pkg2/Makefile new file mode 100644 index 000000000..3fe56139d --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/__init__.py b/Examples/python/import_packages/from_init3/py3/pkg2/__init__.py new file mode 100644 index 000000000..2097aaf2e --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/__init__.py @@ -0,0 +1 @@ +from .bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/bar.hpp b/Examples/python/import_packages/from_init3/py3/pkg2/bar.hpp new file mode 100644 index 000000000..16fdd362e --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY3_PKG2_HPP +#define PY3_PKG2_HPP +#include "../../py3/pkg2/pkg3/pkg4/foo.hpp" +struct Pkg2_Bar : Pkg4_Foo {}; +#endif /* PY3_PKG2_HPP */ diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/bar.i b/Examples/python/import_packages/from_init3/py3/pkg2/bar.i new file mode 100644 index 000000000..3abbb05d3 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import "../../py3/pkg2/pkg3/pkg4/foo.i" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/Makefile new file mode 100644 index 000000000..470f9d561 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg4 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/__init__.py b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/Makefile b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/Makefile new file mode 100644 index 000000000..a98d31122 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='foo' python_clean diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/__init__.py b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.hpp b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.hpp new file mode 100644 index 000000000..e24654c28 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY3_PKG2_PKG3_PKG4 +#define PY3_PKG2_PKG3_PKG4 +struct Pkg4_Foo {}; +#endif /* PY3_PKG2_PKG3_PKG4 */ diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.i b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.i new file mode 100644 index 000000000..36c5f01ea --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.i @@ -0,0 +1,5 @@ +%module(package="py3.pkg2.pkg3.pkg4") foo +%{ +#include "../../../../py3/pkg2/pkg3/pkg4/foo.hpp" +%} +%include "../../../../py3/pkg2/pkg3/pkg4/foo.hpp" diff --git a/Examples/python/import_packages/from_init3/runme.py b/Examples/python/import_packages/from_init3/runme.py new file mode 100644 index 000000000..c23a085fa --- /dev/null +++ b/Examples/python/import_packages/from_init3/runme.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print "Testing %module(package=...) + python 'import' in __init__.py" +import sys +if sys.version_info < (3,0): + import py2.pkg2 + print " Finished importing py2.pkg2" +else: + import py3.pkg2 + print " Finished importing py3.pkg2" diff --git a/Examples/python/import_packages/relativeimport1/Makefile b/Examples/python/import_packages/relativeimport1/Makefile new file mode 100644 index 000000000..8e35c6c61 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/Makefile @@ -0,0 +1,25 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +ifeq (,$(PY3)) + PKG1DIR = "py2" +else + PKG1DIR = "py3" +endif + +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + +static: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd py2 && $(MAKE) clean + cd py3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport1/README b/Examples/python/import_packages/relativeimport1/README new file mode 100644 index 000000000..a99ef2426 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/README @@ -0,0 +1,22 @@ +This example tests the %import directive and -relativeimport swig option. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pyX/pkg2/pkg3/foo.i - Pkg3_Foo class + pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg3_Foo + +The code is processed by swig with -relativeimport flag. The runtime test +imports pyX.pkg2.bar module. + +If everything works well, the module pyX.pkg2.bar shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/relativeimport1/py2/Makefile b/Examples/python/import_packages/relativeimport1/py2/Makefile new file mode 100644 index 000000000..4c0dfab07 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport1/py2/__init__.py b/Examples/python/import_packages/relativeimport1/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/Makefile b/Examples/python/import_packages/relativeimport1/py2/pkg2/Makefile new file mode 100644 index 000000000..3fe56139d --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/__init__.py b/Examples/python/import_packages/relativeimport1/py2/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.hpp b/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.hpp new file mode 100644 index 000000000..8f09cd5fa --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY2_PKG2_BAR_HPP +#define PY2_PKG2_BAR_HPP +#include "../../py2/pkg2/pkg3/foo.hpp" +struct Pkg2_Bar : Pkg3_Foo {}; +#endif /* PY2_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.i b/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.i new file mode 100644 index 000000000..28a4c906e --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import "../../py2/pkg2/pkg3/foo.i" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/Makefile new file mode 100644 index 000000000..a417e2745 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='foo' python_clean diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/__init__.py b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.hpp b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.hpp new file mode 100644 index 000000000..b6c89a431 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY2_PKG2_PKG3_FOO_HPP +#define PY2_PKG2_PKG3_FOO_HPP +struct Pkg3_Foo {}; +#endif /* PY2_PKG2_PKG3_FOO_HPP */ diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.i b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.i new file mode 100644 index 000000000..ba32483d2 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.i @@ -0,0 +1,5 @@ +%module(package="py2.pkg2.pkg3") foo +%{ +#include "../../../py2/pkg2/pkg3/foo.hpp" +%} +%include "../../../py2/pkg2/pkg3/foo.hpp" diff --git a/Examples/python/import_packages/relativeimport1/py3/Makefile b/Examples/python/import_packages/relativeimport1/py3/Makefile new file mode 100644 index 000000000..4c0dfab07 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport1/py3/__init__.py b/Examples/python/import_packages/relativeimport1/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/Makefile b/Examples/python/import_packages/relativeimport1/py3/pkg2/Makefile new file mode 100644 index 000000000..3fe56139d --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/__init__.py b/Examples/python/import_packages/relativeimport1/py3/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.hpp b/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.hpp new file mode 100644 index 000000000..408d910d7 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY3_PKG2_BAR_HPP +#define PY3_PKG2_BAR_HPP +#include "../../py3/pkg2/pkg3/foo.hpp" +struct Pkg2_Bar : Pkg3_Foo {}; +#endif /* PY3_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.i b/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.i new file mode 100644 index 000000000..1468932ff --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import "../../py3/pkg2/pkg3/foo.i" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/Makefile new file mode 100644 index 000000000..a417e2745 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='foo' python_clean diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/__init__.py b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.hpp b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.hpp new file mode 100644 index 000000000..531721d36 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY3_PKG2_PKG3_FOO_HPP +#define PY3_PKG2_PKG3_FOO_HPP +struct Pkg3_Foo {}; +#endif /* PY3_PKG2_PKG3_FOO_HPP */ diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.i b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.i new file mode 100644 index 000000000..c6ba529b7 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.i @@ -0,0 +1,5 @@ +%module(package="py3.pkg2.pkg3") foo +%{ +#include "../../../py3/pkg2/pkg3/foo.hpp" +%} +%include "../../../py3/pkg2/pkg3/foo.hpp" diff --git a/Examples/python/import_packages/relativeimport1/runme.py b/Examples/python/import_packages/relativeimport1/runme.py new file mode 100644 index 000000000..44ce8d1c4 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/runme.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print "Testing %module(package=...) with -relativeimport" +import sys +if sys.version_info < (3,0): + import py2.pkg2.bar + print " Finished importing py2.pkg2.bar" +else: + import py3.pkg2.bar + print " Finished importing py3.pkg2.bar" diff --git a/Examples/python/import_packages/relativeimport2/Makefile b/Examples/python/import_packages/relativeimport2/Makefile new file mode 100644 index 000000000..8e35c6c61 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/Makefile @@ -0,0 +1,25 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +ifeq (,$(PY3)) + PKG1DIR = "py2" +else + PKG1DIR = "py3" +endif + +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + +static: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd py2 && $(MAKE) clean + cd py3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/README b/Examples/python/import_packages/relativeimport2/README new file mode 100644 index 000000000..af2d2840b --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/README @@ -0,0 +1,22 @@ +This example tests the %import directive and -relativeimport option. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pyX/pkg2/pkg3/pkg4/foo.i - Pkg4_Foo class + pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg4_Foo + +The difference between this ('relativeimport2') case and the case +'relativeimport1' is the "distance" between importer and importee. + +If everything works well, the package pyX.pkg2 shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/relativeimport2/py2/Makefile b/Examples/python/import_packages/relativeimport2/py2/Makefile new file mode 100644 index 000000000..4c0dfab07 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py2/__init__.py b/Examples/python/import_packages/relativeimport2/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/Makefile b/Examples/python/import_packages/relativeimport2/py2/pkg2/Makefile new file mode 100644 index 000000000..3fe56139d --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/__init__.py b/Examples/python/import_packages/relativeimport2/py2/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.hpp b/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.hpp new file mode 100644 index 000000000..20a00190a --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY2_PKG2_HPP +#define PY2_PKG2_HPP +#include "../../py2/pkg2/pkg3/pkg4/foo.hpp" +struct Pkg2_Bar : Pkg4_Foo {}; +#endif /* PY2_PKG2_HPP */ diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.i b/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.i new file mode 100644 index 000000000..0a932a2b9 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import "../../py2/pkg2/pkg3/pkg4/foo.i" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/Makefile new file mode 100644 index 000000000..470f9d561 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg4 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/__init__.py b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/Makefile b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/Makefile new file mode 100644 index 000000000..a98d31122 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='foo' python_clean diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/__init__.py b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.hpp b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.hpp new file mode 100644 index 000000000..2df933c59 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY2_PKG2_PKG3_PKG4 +#define PY2_PKG2_PKG3_PKG4 +struct Pkg4_Foo {}; +#endif /* PY2_PKG2_PKG3_PKG4 */ diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.i b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.i new file mode 100644 index 000000000..311d7161c --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.i @@ -0,0 +1,5 @@ +%module(package="py2.pkg2.pkg3.pkg4") foo +%{ +#include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp" +%} +%include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp" diff --git a/Examples/python/import_packages/relativeimport2/py3/Makefile b/Examples/python/import_packages/relativeimport2/py3/Makefile new file mode 100644 index 000000000..4c0dfab07 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py3/__init__.py b/Examples/python/import_packages/relativeimport2/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/Makefile b/Examples/python/import_packages/relativeimport2/py3/pkg2/Makefile new file mode 100644 index 000000000..3fe56139d --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/__init__.py b/Examples/python/import_packages/relativeimport2/py3/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.hpp b/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.hpp new file mode 100644 index 000000000..16fdd362e --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY3_PKG2_HPP +#define PY3_PKG2_HPP +#include "../../py3/pkg2/pkg3/pkg4/foo.hpp" +struct Pkg2_Bar : Pkg4_Foo {}; +#endif /* PY3_PKG2_HPP */ diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.i b/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.i new file mode 100644 index 000000000..3abbb05d3 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import "../../py3/pkg2/pkg3/pkg4/foo.i" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/Makefile new file mode 100644 index 000000000..470f9d561 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg4 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/__init__.py b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/Makefile b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/Makefile new file mode 100644 index 000000000..a98d31122 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='foo' python_clean diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/__init__.py b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.hpp b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.hpp new file mode 100644 index 000000000..e24654c28 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY3_PKG2_PKG3_PKG4 +#define PY3_PKG2_PKG3_PKG4 +struct Pkg4_Foo {}; +#endif /* PY3_PKG2_PKG3_PKG4 */ diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.i b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.i new file mode 100644 index 000000000..36c5f01ea --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.i @@ -0,0 +1,5 @@ +%module(package="py3.pkg2.pkg3.pkg4") foo +%{ +#include "../../../../py3/pkg2/pkg3/pkg4/foo.hpp" +%} +%include "../../../../py3/pkg2/pkg3/pkg4/foo.hpp" diff --git a/Examples/python/import_packages/relativeimport2/runme.py b/Examples/python/import_packages/relativeimport2/runme.py new file mode 100644 index 000000000..ac60eb630 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/runme.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print "Testing %module(package=...) + python 'import' in __init__.py" +import sys +if sys.version_info < (3,0): + import py2.pkg2.bar + print " Finished importing py2.pkg2.bar" +else: + import py3.pkg2.bar + print " Finished importing py3.pkg2.bar" diff --git a/Examples/python/import_packages/relativeimport2/runme3.py b/Examples/python/import_packages/relativeimport2/runme3.py new file mode 100644 index 000000000..4b0d112cf --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/runme3.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print("Testing %module(package=...) + python 'import' in __init__.py") +import sys +if sys.version_info < (3, 0): + import py2.pkg2.bar + print(" Finished importing py2.pkg2.bar") +else: + import py3.pkg2.bar + print(" Finished importing py3.pkg2.bar") diff --git a/Examples/python/import_packages/same_modnames1/Makefile b/Examples/python/import_packages/same_modnames1/Makefile new file mode 100644 index 000000000..9dd5971dc --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/Makefile @@ -0,0 +1,20 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: + cd pkg1 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg1 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg1 && $(MAKE) clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/same_modnames1/README b/Examples/python/import_packages/same_modnames1/README new file mode 100644 index 000000000..ee3f8d6f7 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/README @@ -0,0 +1,26 @@ +This example tests the %import directive and working with multiple modules. + +There are two modules having same name but belonging to different packages. +This case is not correctly handled by swig 2. + +The issue was reported as Source Forge bug #1297 and later as GitHub issue #7. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pkg1/foo.i - Pkg1_Foo class. + pkg2/foo.i - Pkg2_Foo class (derived from Pkg1_Foo). + +The pkg2/foo.i module uses %import to refer to pkg1/foo.i. + +If everything works well, the module pkg2.foo shall load properly. + +Unix: +----- +- Run make +- Run the test as described above. diff --git a/Examples/python/import_packages/same_modnames1/pkg1/Makefile b/Examples/python/import_packages/same_modnames1/pkg1/Makefile new file mode 100644 index 000000000..9b51a76ed --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg1/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='foo' python_clean diff --git a/Examples/python/import_packages/same_modnames1/pkg1/__init__.py b/Examples/python/import_packages/same_modnames1/pkg1/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/same_modnames1/pkg1/foo.hpp b/Examples/python/import_packages/same_modnames1/pkg1/foo.hpp new file mode 100644 index 000000000..b07c983b3 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg1/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PKG1_FOO_HPP +#define PKG1_FOO_HPP +struct Pkg1_Foo{}; +#endif /* PKG1_FOO_HPP */ diff --git a/Examples/python/import_packages/same_modnames1/pkg1/foo.i b/Examples/python/import_packages/same_modnames1/pkg1/foo.i new file mode 100644 index 000000000..9939f420a --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg1/foo.i @@ -0,0 +1,5 @@ +%module(package="pkg1") foo +%{ +#include "../pkg1/foo.hpp" +%} +%include "../pkg1/foo.hpp" diff --git a/Examples/python/import_packages/same_modnames1/pkg2/Makefile b/Examples/python/import_packages/same_modnames1/pkg2/Makefile new file mode 100644 index 000000000..9b51a76ed --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg2/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='foo' python_clean diff --git a/Examples/python/import_packages/same_modnames1/pkg2/__init__.py b/Examples/python/import_packages/same_modnames1/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/same_modnames1/pkg2/foo.hpp b/Examples/python/import_packages/same_modnames1/pkg2/foo.hpp new file mode 100644 index 000000000..72563a9d0 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg2/foo.hpp @@ -0,0 +1,5 @@ +#ifndef PKG2_FOO_HPP +#define PKG2_FOO_HPP +#include "../pkg1/foo.hpp" +struct Pkg2_Foo : public Pkg1_Foo{}; +#endif /* PKG2_FOO_HPP */ diff --git a/Examples/python/import_packages/same_modnames1/pkg2/foo.i b/Examples/python/import_packages/same_modnames1/pkg2/foo.i new file mode 100644 index 000000000..3a1ce0198 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg2/foo.i @@ -0,0 +1,6 @@ +%module(package="pkg2") foo +%{ +#include "../pkg2/foo.hpp" +%} +%import "../pkg1/foo.i" +%include "../pkg2/foo.hpp" diff --git a/Examples/python/import_packages/same_modnames1/runme.py b/Examples/python/import_packages/same_modnames1/runme.py new file mode 100644 index 000000000..9cdb95caf --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/runme.py @@ -0,0 +1,7 @@ +# Test import of same modules from different packages +print "Testing %module(package=...) + %import + same modules in different packages" +import pkg2.foo +print " Finished importing pkg2.foo" + +var2 = pkg2.foo.Pkg2_Foo() +print " Successfully created object pkg2.foo.Pkg2_Foo" diff --git a/Examples/python/import_packages/same_modnames2/Makefile b/Examples/python/import_packages/same_modnames2/Makefile new file mode 100644 index 000000000..cfc327883 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/Makefile @@ -0,0 +1,20 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +check: build + $(MAKE) -f $(TOP)/Makefile python_run + +build: + cd pkg1 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg1/pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg1 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg1/pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile python_clean + cd pkg1 && $(MAKE) clean + cd pkg1/pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/same_modnames2/README b/Examples/python/import_packages/same_modnames2/README new file mode 100644 index 000000000..9b0233f8b --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/README @@ -0,0 +1,26 @@ +This example tests the %import directive and working with multiple modules. + +There are two modules having same name but belonging to different packages. +This case is not correctly handled by swig 2. + +The issue was reported as Source Forge bug #1297 and later as GitHub issue #7. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pkg1/foo.i - Pkg1_Foo class + pkg1/pkg2/foo.i - Pkg2_Foo class derived from Pkg1_Foo + +The pkg1/pkg2/foo module uses %import to refer to pkg1/foo. + +If everything works well, the module pkg1.pkg2.foo shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/same_modnames2/pkg1/Makefile b/Examples/python/import_packages/same_modnames2/pkg1/Makefile new file mode 100644 index 000000000..9b51a76ed --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='foo' python_clean diff --git a/Examples/python/import_packages/same_modnames2/pkg1/__init__.py b/Examples/python/import_packages/same_modnames2/pkg1/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/same_modnames2/pkg1/foo.hpp b/Examples/python/import_packages/same_modnames2/pkg1/foo.hpp new file mode 100644 index 000000000..b07c983b3 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PKG1_FOO_HPP +#define PKG1_FOO_HPP +struct Pkg1_Foo{}; +#endif /* PKG1_FOO_HPP */ diff --git a/Examples/python/import_packages/same_modnames2/pkg1/foo.i b/Examples/python/import_packages/same_modnames2/pkg1/foo.i new file mode 100644 index 000000000..9939f420a --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/foo.i @@ -0,0 +1,5 @@ +%module(package="pkg1") foo +%{ +#include "../pkg1/foo.hpp" +%} +%include "../pkg1/foo.hpp" diff --git a/Examples/python/import_packages/same_modnames2/pkg1/pkg2/Makefile b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/Makefile new file mode 100644 index 000000000..053b911f5 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile TARGET='foo' python_clean diff --git a/Examples/python/import_packages/same_modnames2/pkg1/pkg2/__init__.py b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.hpp b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.hpp new file mode 100644 index 000000000..1b4a1d558 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.hpp @@ -0,0 +1,5 @@ +#ifndef PKG1_PKG2_FOO_HPP +#define PKG1_PKG2_FOO_HPP +#include "../../pkg1/foo.hpp" +struct Pkg2_Foo : public Pkg1_Foo{}; +#endif /* PKG1_PKG2_FOO_HPP */ diff --git a/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.i b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.i new file mode 100644 index 000000000..1741b3799 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.i @@ -0,0 +1,6 @@ +%module(package="pkg1.pkg2") foo +%{ +#include "../../pkg1/pkg2/foo.hpp" +%} +%import "../../pkg1/foo.i" +%include "../../pkg1/pkg2/foo.hpp" diff --git a/Examples/python/import_packages/same_modnames2/runme.py b/Examples/python/import_packages/same_modnames2/runme.py new file mode 100644 index 000000000..bde4305c4 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/runme.py @@ -0,0 +1,4 @@ +import pkg1.pkg2.foo +print " Finished importing pkg1.pkg2.foo" +var2 = pkg1.pkg2.foo.Pkg2_Foo(); +print " Successfully created object pkg1.pkg2.foo.Pkg2_Foo" diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index e281bbbec..6f5446fa8 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -94,6 +94,7 @@ static int castmode = 0; static int extranative = 0; static int outputtuple = 0; static int nortti = 0; +static int relativeimport = 0; /* flags for the make_autodoc function */ enum autodoc_t { @@ -156,6 +157,7 @@ static const char *usage3 = (char *) "\ -oldrepr - Use shorter and old version of __repr__ in proxy classes\n\ -outputtuple - Use a PyTuple for outputs instead of a PyList (use carefully with legacy interfaces) \n\ -proxydel - Generate a __del__ method even though it is now redundant (default) \n\ + -relativeimport - Use relative python imports \n\ -safecstrings - Use safer (but slower) C string mapping, generating copies from Python -> C/C++\n\ -threads - Add thread support for all the interface\n\ -O - Enable the following optimization options: \n\ @@ -520,6 +522,9 @@ public: builtin = 1; Preprocessor_define("SWIGPYTHON_BUILTIN", 0); Swig_mark_arg(i); + } else if (strcmp(argv[i], "-relativeimport") == 0) { + relativeimport = 1; + Swig_mark_arg(i); } } @@ -1028,6 +1033,284 @@ public: return 0; } + /* ------------------------------------------------------------ + * tail = subpkg_tail(base, other) + * + * Return the name of 'other' package relative to 'base'. + * + * 1. If 'other' is a sub-package of 'base', returns the 'other' relative to + * 'base'. + * 2. If 'other' and 'base' are equal, returns empty string "". + * 3. In any other case, NULL pointer is returned. + * + * The 'base' and 'other' are expected to be fully qualified names. + * + * NOTE: none of 'base' nor 'other' can be null. + * + * Examples: + * + * # base other tail + * -- ---- ----- ---- + * 1 "Foo" "Foo.Bar" -> "Bar" + * 2 "Foo" "Foo." -> "" + * 3 "Foo" "FooB.ar" -> NULL + * 4 "Foo.Bar" "Foo.Bar" -> "" + * 5 "Foo.Bar" "Foo" -> NULL + * 6 "Foo.Bar" "Foo.Gez" -> NULL + * + * NOTE: the example #2 is actually a syntax error (at input). I believe + * swig parser prevents us from this case happening here. + * ------------------------------------------------------------ */ + static String* subpkg_tail(const String* base, const String* other) + { + int baselen = Len(base); + int otherlen = Len(other); + + if (Strncmp(other, base, baselen) == 0) { + if ((baselen < otherlen) && (Char(other))[baselen] == '.') { + return NewString((Char(other)) + baselen + 1); + } else if (baselen == otherlen) { + return NewString(""); + } else { + return 0; + } + } else { + return 0; + } + } + + /* ------------------------------------------------------------ + * out = abs_import_directive_string(pkg, mod, pfx) + * + * Return a String* containing python code to import module. + * + * pkg package name or the module being imported + * mod module name of the module being imported + * pfx optional prefix to module name + * + * NOTE: keep this function consistent with abs_import_name_string(). + * ------------------------------------------------------------ */ + static String* abs_import_directive_string(const String* pkg, + const String* mod, + const char* pfx = "") + { + String* out = NewString(""); + + if (pkg && *Char(pkg)) { + Printf(out, "import %s.%s%s\n", pkg, pfx, mod); + } else { + Printf(out, "import %s%s\n", pfx, mod); + } + return out; + } + + /* ------------------------------------------------------------ + * out = rel_import_directive_string(mainpkg, pkg, mod, pfx) + * + * Return a String* containing python code to import module that + * is potentially within a package. + * + * mainpkg package name of the module which imports the other module + * pkg package name or the module being imported + * mod module name of the module being imported + * pfx optional prefix to module name + * + * NOTE: keep this function consistent with rel_import_name_string(). + * ------------------------------------------------------------ */ + static String* rel_import_directive_string(const String* mainpkg, + const String* pkg, + const String* mod, + const char* pfx = "") + { + /* NOTE: things are not so trivial. This is what we do here (by examples): + * + * 0. To import module 'foo', which is not in any package, we do absolute + * import: + * + * import foo + * + * 1. To import 'pkg1.pkg2.foo', when mainpkg != "pkg1" and + * mainpkg != "pkg1.pkg2" or when mainpkg is not given we do absolute + * import: + * + * import pkg1.pkg2.foo + * + * 2. To import module pkg1.foo, when mainpkg == "pkg1", we do: + * + * - for py3 = 0: + * + * import foo + * + * - for py3 = 1: + * + * from . import foo + * + * 3. To import "pkg1.pkg2.pkg3.foo", when mainpkg = "pkg1", we do: + * + * - for py3 == 0: + * + * import pkg2.pkg3.foo + * + * - for py3 == 1: + * + * from . import pkg2 # [1] + * import pkg1.pkg2.pkg3.foo + * + * NOTE: [1] is necessary for pkg2.foo to be present in the importing module + */ + String* apkg = 0; // absolute (FQDN) package name of pkg + String* rpkg = 0; // relative package name + int py3_rlen1 = 0; // length of 1st level sub-package name, used by py3 + String* out = NewString(""); + + if (pkg && *Char(pkg)) { + if(mainpkg) { + String* tail = subpkg_tail(mainpkg, pkg); + if (tail) { + if(*Char(tail)) { + rpkg = NewString(tail); + const char* py3_end1 = Strchr(rpkg, '.'); + if(!py3_end1) py3_end1 = (Char(rpkg)) + Len(rpkg); + py3_rlen1 = py3_end1 - (Char(rpkg)); + } else { + rpkg = NewString(""); + } + Delete(tail); + } else { + apkg = NewString(pkg); + } + } else { + apkg = NewString(pkg); + } + } else { + apkg = NewString(""); + } + + if (apkg) { + Printf(out, "import %s%s%s%s\n", apkg, *Char(apkg) ? "." : "", pfx, mod); + Delete(apkg); + } else { + if (py3) { + if (py3_rlen1) + Printf(out, "from . import %.*s\n", py3_rlen1, rpkg); + Printf(out, "from .%s import %s%s\n", rpkg, pfx, mod); + } else { + Printf(out, "import %s%s%s%s\n", rpkg, *Char(rpkg) ? "." : "", pfx, mod); + } + Delete(rpkg); + } + return out; + } + + /* ------------------------------------------------------------ + * out = import_directive_string(mainpkg, pkg, mod, pfx) + * ------------------------------------------------------------ */ + static String* import_directive_string(const String* mainpkg, + const String* pkg, + const String* mod, + const char* pfx = "") + { + if (!relativeimport) { + return abs_import_directive_string(pkg, mod, pfx); + } else { + return rel_import_directive_string(mainpkg, pkg, mod, pfx); + } + } + + /* ------------------------------------------------------------ + * out = abs_import_name_string(mainpkg, mainmod, pkg, mod, sym) + * + * Return a String* with the name of a symbol (perhaps imported + * from external module by absolute import directive). + * + * mainpkg package name of current module + * mainmod module name of current module + * pkg package name of (perhaps other) module + * mod module name of (perhaps other) module + * sym symbol name + * + * NOTE: mainmod, mod, and sym can't be NULL. + * NOTE: keep this function consistent with abs_import_directive_string() + * ------------------------------------------------------------ */ + static String* abs_import_name_string(const String* mainpkg, + const String* mainmod, + const String* pkg, + const String* mod, + const String* sym) + { + String* out = NewString(""); + if (pkg && *Char(pkg)) { + if (mainpkg && *Char(mainpkg)) { + if (Strcmp(mainpkg,pkg) != 0 || Strcmp(mainmod, mod) != 0) { + Printf(out, "%s.%s.", pkg, mod); + } + } else { + Printf(out, "%s.%s.", pkg, mod); + } + } else if ((mainpkg && *Char(mainpkg)) || Strcmp(mainmod, mod) != 0) { + Printf(out, "%s.", mod); + } + Append(out, sym); + return out; + } + + /* ------------------------------------------------------------ + * out = rel_import_name_string(mainpkg, mainmod, pkg, mod, sym) + * + * Return a String* with the name of a symbol (perhaps imported + * from external module by relative import directive). + * + * mainpkg package name of current module + * mainmod module name of current module + * pkg package name of (perhaps other) module + * mod module name of (perhaps other) module + * sym symbol name + * + * NOTE: mainmod, mod, and sym can't be NULL. + * NOTE: keep this function consistent with rel_import_directive_string() + * ------------------------------------------------------------ */ + static String* rel_import_name_string(const String* mainpkg, + const String* mainmod, + const String* pkg, + const String* mod, + const String* sym) + { + String* out = NewString(""); + if (pkg && *Char(pkg)) { + String* tail = 0; + if (mainpkg) + tail = subpkg_tail(mainpkg, pkg); + if (!tail) + tail = NewString(pkg); + if(*Char(tail)) { + Printf(out, "%s.%s.", tail, mod); + } else if (Strcmp(mainmod, mod) != 0) { + Printf(out, "%s.", mod); + } + Delete(tail); + } else if ((mainpkg && *Char(mainpkg)) || Strcmp(mainmod, mod) != 0) { + Printf(out, "%s.", mod); + } + Append(out, sym); + return out; + } + + /* ------------------------------------------------------------ + * out = import_name_string(mainpkg, mainmod, pkg, mod, sym) + * ------------------------------------------------------------ */ + static String* import_name_string(const String* mainpkg, + const String* mainmod, + const String* pkg, + const String* mod, + const String* sym) + { + if (!relativeimport) { + return abs_import_name_string(mainpkg,mainmod,pkg,mod,sym); + } else { + return rel_import_name_string(mainpkg,mainmod,pkg,mod,sym); + } + } + /* ------------------------------------------------------------ * importDirective() * ------------------------------------------------------------ */ @@ -1037,38 +1320,26 @@ public: String *modname = Getattr(n, "module"); if (modname) { - String *import = NewString("import "); - // Find the module node for this imported module. It should be the // first child but search just in case. Node *mod = firstChild(n); while (mod && Strcmp(nodeType(mod), "module") != 0) mod = nextSibling(mod); - // Is the imported module in another package? (IOW, does it use the - // %module(package="name") option and it's different than the package - // of this module.) Node *options = Getattr(mod, "options"); String *pkg = options ? Getattr(options, "package") : 0; - if (pkg) { - Printf(import, "%s.", pkg); - } - // finally, output the name of the imported module if (shadowimport) { if (!options || (!Getattr(options, "noshadow") && !Getattr(options, "noproxy"))) { - Printf(import, "_%s\n", modname); - if (!GetFlagAttr(f_shadow_imports, import)) { - if (pkg) { - Printf(builtin ? f_shadow_builtin_imports : f_shadow, "import %s.%s\n", pkg, modname); - } else { - Printf(builtin ? f_shadow_builtin_imports : f_shadow, "import %s\n", modname); - } - SetFlag(f_shadow_imports, import); + String* _import = import_directive_string(package, pkg, modname, "_"); + if (!GetFlagAttr(f_shadow_imports, _import)) { + String* import = import_directive_string(package, pkg, modname); + Printf(builtin ? f_shadow_builtin_imports : f_shadow, "%s", import); + Delete(import); + SetFlag(f_shadow_imports, _import); } + Delete(_import); } } - - Delete(import); } } return Language::importDirective(n); @@ -3164,19 +3435,13 @@ public: if (shadow && !Getattr(n, "feature:onlychildren")) { Node *mod = Getattr(n, "module"); if (mod) { - String *importname = NewString(""); String *modname = Getattr(mod, "name"); - if (Strcmp(modname, mainmodule) != 0) { - // check if the module has a package option - Node *options = Getattr(mod, "options"); - String *pkg = options ? Getattr(options, "package") : 0; - if (pkg) { - Printf(importname, "%s.", pkg); - } - Printf(importname, "%s.", modname); - } - Append(importname, Getattr(n, "sym:name")); + Node *options = Getattr(mod, "options"); + String* pkg = options ? Getattr(options, "package") : 0; + String* sym = Getattr(n, "sym:name"); + String* importname = import_name_string(package, mainmodule, pkg, modname, sym); Setattr(n, "python:proxy", importname); + Delete(importname); } } int result = Language::classDeclaration(n); From 44dd28950ca5c45ee0cb950f05da60ac3879730d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 24 Dec 2013 11:31:54 +0000 Subject: [PATCH 0851/1160] Python import code beautify --- Source/Modules/python.cxx | 137 +++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 77 deletions(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 6f5446fa8..039623e62 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -1034,7 +1034,7 @@ public: } /* ------------------------------------------------------------ - * tail = subpkg_tail(base, other) + * subpkg_tail() * * Return the name of 'other' package relative to 'base'. * @@ -1049,8 +1049,8 @@ public: * * Examples: * - * # base other tail - * -- ---- ----- ---- + * # base other tail + * -- ---- ----- ---- * 1 "Foo" "Foo.Bar" -> "Bar" * 2 "Foo" "Foo." -> "" * 3 "Foo" "FooB.ar" -> NULL @@ -1061,8 +1061,8 @@ public: * NOTE: the example #2 is actually a syntax error (at input). I believe * swig parser prevents us from this case happening here. * ------------------------------------------------------------ */ - static String* subpkg_tail(const String* base, const String* other) - { + + static String *subpkg_tail(const String *base, const String *other) { int baselen = Len(base); int otherlen = Len(other); @@ -1080,9 +1080,9 @@ public: } /* ------------------------------------------------------------ - * out = abs_import_directive_string(pkg, mod, pfx) + * abs_import_directive_string() * - * Return a String* containing python code to import module. + * Return a string containing python code to import module. * * pkg package name or the module being imported * mod module name of the module being imported @@ -1090,11 +1090,9 @@ public: * * NOTE: keep this function consistent with abs_import_name_string(). * ------------------------------------------------------------ */ - static String* abs_import_directive_string(const String* pkg, - const String* mod, - const char* pfx = "") - { - String* out = NewString(""); + + static String *abs_import_directive_string(const String *pkg, const String *mod, const char *pfx = "") { + String *out = NewString(""); if (pkg && *Char(pkg)) { Printf(out, "import %s.%s%s\n", pkg, pfx, mod); @@ -1105,9 +1103,9 @@ public: } /* ------------------------------------------------------------ - * out = rel_import_directive_string(mainpkg, pkg, mod, pfx) + * rel_import_directive_string() * - * Return a String* containing python code to import module that + * Return a string containing python code to import module that * is potentially within a package. * * mainpkg package name of the module which imports the other module @@ -1117,11 +1115,9 @@ public: * * NOTE: keep this function consistent with rel_import_name_string(). * ------------------------------------------------------------ */ - static String* rel_import_directive_string(const String* mainpkg, - const String* pkg, - const String* mod, - const char* pfx = "") - { + + static String *rel_import_directive_string(const String *mainpkg, const String *pkg, const String *mod, const char *pfx = "") { + /* NOTE: things are not so trivial. This is what we do here (by examples): * * 0. To import module 'foo', which is not in any package, we do absolute @@ -1158,29 +1154,31 @@ public: * * NOTE: [1] is necessary for pkg2.foo to be present in the importing module */ - String* apkg = 0; // absolute (FQDN) package name of pkg - String* rpkg = 0; // relative package name + + String *apkg = 0; // absolute (FQDN) package name of pkg + String *rpkg = 0; // relative package name int py3_rlen1 = 0; // length of 1st level sub-package name, used by py3 - String* out = NewString(""); + String *out = NewString(""); if (pkg && *Char(pkg)) { - if(mainpkg) { - String* tail = subpkg_tail(mainpkg, pkg); - if (tail) { - if(*Char(tail)) { - rpkg = NewString(tail); - const char* py3_end1 = Strchr(rpkg, '.'); - if(!py3_end1) py3_end1 = (Char(rpkg)) + Len(rpkg); - py3_rlen1 = py3_end1 - (Char(rpkg)); - } else { - rpkg = NewString(""); - } - Delete(tail); - } else { - apkg = NewString(pkg); - } + if (mainpkg) { + String *tail = subpkg_tail(mainpkg, pkg); + if (tail) { + if (*Char(tail)) { + rpkg = NewString(tail); + const char *py3_end1 = Strchr(rpkg, '.'); + if (!py3_end1) + py3_end1 = (Char(rpkg)) + Len(rpkg); + py3_rlen1 = py3_end1 - (Char(rpkg)); + } else { + rpkg = NewString(""); + } + Delete(tail); + } else { + apkg = NewString(pkg); + } } else { - apkg = NewString(pkg); + apkg = NewString(pkg); } } else { apkg = NewString(""); @@ -1192,7 +1190,7 @@ public: } else { if (py3) { if (py3_rlen1) - Printf(out, "from . import %.*s\n", py3_rlen1, rpkg); + Printf(out, "from . import %.*s\n", py3_rlen1, rpkg); Printf(out, "from .%s import %s%s\n", rpkg, pfx, mod); } else { Printf(out, "import %s%s%s%s\n", rpkg, *Char(rpkg) ? "." : "", pfx, mod); @@ -1203,13 +1201,10 @@ public: } /* ------------------------------------------------------------ - * out = import_directive_string(mainpkg, pkg, mod, pfx) + * import_directive_string() * ------------------------------------------------------------ */ - static String* import_directive_string(const String* mainpkg, - const String* pkg, - const String* mod, - const char* pfx = "") - { + + static String *import_directive_string(const String *mainpkg, const String *pkg, const String *mod, const char *pfx = "") { if (!relativeimport) { return abs_import_directive_string(pkg, mod, pfx); } else { @@ -1218,9 +1213,9 @@ public: } /* ------------------------------------------------------------ - * out = abs_import_name_string(mainpkg, mainmod, pkg, mod, sym) + * abs_import_name_string() * - * Return a String* with the name of a symbol (perhaps imported + * Return a string with the name of a symbol (perhaps imported * from external module by absolute import directive). * * mainpkg package name of current module @@ -1232,13 +1227,9 @@ public: * NOTE: mainmod, mod, and sym can't be NULL. * NOTE: keep this function consistent with abs_import_directive_string() * ------------------------------------------------------------ */ - static String* abs_import_name_string(const String* mainpkg, - const String* mainmod, - const String* pkg, - const String* mod, - const String* sym) - { - String* out = NewString(""); + + static String *abs_import_name_string(const String *mainpkg, const String *mainmod, const String *pkg, const String *mod, const String *sym) { + String *out = NewString(""); if (pkg && *Char(pkg)) { if (mainpkg && *Char(mainpkg)) { if (Strcmp(mainpkg,pkg) != 0 || Strcmp(mainmod, mod) != 0) { @@ -1255,9 +1246,9 @@ public: } /* ------------------------------------------------------------ - * out = rel_import_name_string(mainpkg, mainmod, pkg, mod, sym) + * rel_import_name_string() * - * Return a String* with the name of a symbol (perhaps imported + * Return a string with the name of a symbol (perhaps imported * from external module by relative import directive). * * mainpkg package name of current module @@ -1269,20 +1260,16 @@ public: * NOTE: mainmod, mod, and sym can't be NULL. * NOTE: keep this function consistent with rel_import_directive_string() * ------------------------------------------------------------ */ - static String* rel_import_name_string(const String* mainpkg, - const String* mainmod, - const String* pkg, - const String* mod, - const String* sym) - { - String* out = NewString(""); + + static String *rel_import_name_string(const String *mainpkg, const String *mainmod, const String *pkg, const String *mod, const String *sym) { + String *out = NewString(""); if (pkg && *Char(pkg)) { - String* tail = 0; + String *tail = 0; if (mainpkg) tail = subpkg_tail(mainpkg, pkg); if (!tail) tail = NewString(pkg); - if(*Char(tail)) { + if (*Char(tail)) { Printf(out, "%s.%s.", tail, mod); } else if (Strcmp(mainmod, mod) != 0) { Printf(out, "%s.", mod); @@ -1296,14 +1283,10 @@ public: } /* ------------------------------------------------------------ - * out = import_name_string(mainpkg, mainmod, pkg, mod, sym) + * import_name_string() * ------------------------------------------------------------ */ - static String* import_name_string(const String* mainpkg, - const String* mainmod, - const String* pkg, - const String* mod, - const String* sym) - { + + static String *import_name_string(const String *mainpkg, const String *mainmod, const String *pkg, const String *mod, const String *sym) { if (!relativeimport) { return abs_import_name_string(mainpkg,mainmod,pkg,mod,sym); } else { @@ -1330,9 +1313,9 @@ public: String *pkg = options ? Getattr(options, "package") : 0; if (shadowimport) { if (!options || (!Getattr(options, "noshadow") && !Getattr(options, "noproxy"))) { - String* _import = import_directive_string(package, pkg, modname, "_"); + String *_import = import_directive_string(package, pkg, modname, "_"); if (!GetFlagAttr(f_shadow_imports, _import)) { - String* import = import_directive_string(package, pkg, modname); + String *import = import_directive_string(package, pkg, modname); Printf(builtin ? f_shadow_builtin_imports : f_shadow, "%s", import); Delete(import); SetFlag(f_shadow_imports, _import); @@ -3437,9 +3420,9 @@ public: if (mod) { String *modname = Getattr(mod, "name"); Node *options = Getattr(mod, "options"); - String* pkg = options ? Getattr(options, "package") : 0; - String* sym = Getattr(n, "sym:name"); - String* importname = import_name_string(package, mainmodule, pkg, modname, sym); + String *pkg = options ? Getattr(options, "package") : 0; + String *sym = Getattr(n, "sym:name"); + String *importname = import_name_string(package, mainmodule, pkg, modname, sym); Setattr(n, "python:proxy", importname); Delete(importname); } From f53bd5a1e18da855a4960eb019644cdcf3f0e393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Sat, 23 Nov 2013 20:08:09 +0100 Subject: [PATCH 0852/1160] Documentation for improved python import option Docs for SFbug1297 patch (PR #7) closes #111 --- Doc/Manual/Python.html | 375 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 370 insertions(+), 5 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 6a22738bc..2a719ca7a 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -105,6 +105,12 @@

  • %feature("docstring")
  • Python Packages +
  • Python 3 Support
    • Function annotation @@ -5273,11 +5279,66 @@ with more than one line.

      34.11 Python Packages

      +

      Python has concepts of modules and packages. Modules are separate units of +code and may be grouped together to form a package. Packages may be nested, +that is they may contain subpackages. This leads to tree-like hierarchy, with +packages as intermediate nodes and modules as leaf nodes.

      + +

      The hierarchy of python packages/modules follows the hierarchy of +*.py files found in source tree (or, more generally, in python path). +Normally, the developer creates new module by placing a *.py file +somewhere under python path; the module is then named after that *.py +file. A package is created by placing __init__.py file within a +directory; the package is then named after that directory. For example, the +following source tree:

      + +
      +
      +mod1.py
      +pkg1/__init__.py
      +pkg1/mod2.py
      +pkg1/pkg2/__init__.py
      +pkg1/pkg2/mod3.py
      +
      +

      -Using the package option of the %module directive -allows you to specify what Python package that the module will be -living in when installed. +defines the following python packages and modules: +

      + +
      +
      +pkg1            # package
      +pkg1.pkg2       # package
      +mod1            # module
      +pkg1.mod2       # module
      +pkg1.pkg2.mod3  # module
      +
      +
      + +

      +The purpose of __init__.py file is two-fold. First, existence of +__init__.py in a directory informs python interpreter that this +directory contains python package. Second, the code of __init__.py is +loaded/executed automatically when the package is initialized (when it or its +submodule/subpackage gets import'ed). By default, swig generates +proxy python code – one *.py file for each *.i +interface. The __init__.py files, however, are not generated by swig. +They should be created by other means. Both files (module *.py and +__init__.py) should be installed in appropriate destination +directories in order to obtain desirable package/module hierarchy. +

      + +

      The way python defines its modules and packages impacts swig users. Some +users may need to use special features such as package option of +%module directive or import-related command-line options. These are +explained in the following sections.

      + +

      34.11.1 %module(package="...") syntax

      + +

      +Using the package option of the %module directive allows you +to specify a Python package that the module will be living in when installed.

      @@ -5294,10 +5355,314 @@ if they live in separate Python packages then that won't work. However if the importee specifies what its package is with the %module option then the Python code generated for the importer will use that package name when importing the other module -and also in base class declarations, etc. if the package name is -different than its own. +and also in base class declarations, etc..

      +

      Swig assumes, that the package option provided to %module +together with the module name (that is, wx.xrc in the above +example) forms a fully qualified (absolute) name of a module (in Python terms). +This is important especially for Python 3, where absolute imports are used by +default. It's up to you to place the generated module files (.py, +.so) in proper subdirectories. For example, if you have +interface foo.i with: +

      + +
      +
      +%module(package="pkg1.pkg2") foo
      +
      +
      + +

      +then the resultant directory layout should be +

      + +
      +
      +pkg1/
      +pkg1/__init__.py
      +pkg1/pkg2/__init__.py
      +pkg1/pkg2/foo.py        # (generated by swig)
      +pkg1/pkg2/_foo.so       # (shared library from C/C++ code generated by SWIG)
      +
      +
      + +

      34.11.2 Absolute and relative imports

      + +

      Suppose, we have the following hierarchy of files:

      + +
      +
      +pkg1/
      +pkg1/__init__.py
      +pkg1/mod2.py
      +pkg1/pkg2/__init__.py
      +pkg1/pkg2/mod3.py
      +
      +
      + +

      Let the contents of pkg1/pkg2/mod3.py be

      +
      +
      +class M3: pass
      +
      +
      + +

      +We edit pkg1/mod2.py and want to import module of +pkg1/pkg2/pkg3.py in order to derive from class M3. We can +write appropriate python code in several ways, for example: +

      + +
        +
      1. Using "import <>" syntax with absolute package name:

        +
        +
        +# pkg1/mod2.py
        +import pkg1.pkg2.mod3
        +class M2(pkg1.pkg2.mod3.M3): pass
        +
        +
        +
      2. + +
      3. Using "import <>" syntax with package name relative to + pkg1 (only in python 2.7 and earlier):

        +
        +
        +# pkg1/mod2.py
        +import pkg2.mod3
        +class M2(pkg2.mod3.M3): pass
        +
        +
        +
      4. + +
      5. Using "from <> import <>" syntax (relative import + syntax, only in python 2.5 and later):

        +
        +
        +# pkg1/mod2.py
        +from .pkg2 import mod3
        +class M2(mod3.M3): pass
        +
        +
        +
      6. + +
      7. Other variants, for example the following construction in order to + have the pkg2.mod3.M3 symbol available in mod2 as + in point 2 above (but now under python 3):

        +
        +
        +# pkg1/mod2.py
        +from . import pkg2
        +from .pkg2 import mod3
        +class M2(pkg2.mod3.M3): pass
        +
        +
        +
      8. + +
      + +

      Now suppose we have mod2.i with

      + +
      +
      +// mod2.i
      +%module (package="pkg1") mod2
      +%import "mod3.i"
      +// ...
      +
      +
      + +

      and mod3.i with

      + +
      +
      +// mod3.i
      +%module (package="pkg1.pkg2") mod3
      +// ...
      +
      +
      + +

      By default, swig would generate mod2.py proxy file with +import directive as in point 1. This may be changed with +-relativeimport CLI option. The -relativeimport instructs +swig to organize imports as in point 2 (for python 2.x) or as in point 4 (for +python 3, that is when -py3 CLI option is enabled). In short, if you have +mod2.i and mod3.i as above, then without +-relativeimport swig will write

      + +
      +
      +import pkg1.pkg2.mod3
      +
      +
      + +

      to mod2.py proxy file, and with -relativeimport it will +write

      + +
      +
      +import pkg2.mod3
      +
      +
      + +

      if -py3 is not used, or

      + +
      +
      +from . import pkg2
      +import pkg1.pkg2.mod3
      +
      +
      + +

      when -py3 option is used.

      + +

      You should avoid using relative imports and use absolute ones whenever +possible. There are some cases, however, when relative imports may be +necessary. The first example is, when some (legacy) python code refers entities +imported by proxy files generated by swig, and it assumes that the proxy file +uses relative imports. Second case is, when one puts import directives in +__init__.py to import symbols from submodules or subpackages and the +submodule depends on other submodules (discussed later).

      + +

      34.11.3 Enforcing absolute import semantics

      + +

      As you may know, there is incompatibility in import semantics (for the +import <> syntax) between python 2 and 3. In python 2.4 and +earlier it is not clear whether

      + +
      +
      +import foo
      +
      +
      +

      refers to a top-level module or to another module inside the current +package. In python 3 it always refers to a top-level module +(see PEP 328). +To instruct python 2.5 through 2.7 to use new semantics (that is import +foo is interpreted as absolute import), one have to put the following +line +

      + +
      +
      +from __future__ import absolute_import
      +
      +
      + +

      at the very beginning of his proxy *.py file. In swig, it may be +accomplished with %pythonbegin directive.

      + +

      34.11.4 Importing from __init__.py

      + +

      Imports in __init__.py are handy when you want to populate +package's namespace with names imported from other modules. In swig-based +projects this approach may also be used to split large piece of code into +smaller modules, compile them in parallel and then re-assemble all stuff at +python level by importing submodules' contents in __init__.py, for +example.

      + +

      Unfortunately import directives in __init__.py may cause troubles, +especially if they refer to package's submodules. This is caused by the way +python initializes packages. If you spot problems with imports from +__init__.py try using -relativeimport option. Below we +explain in detail one issue, for which the -relativeimport workaround +may be helpful.

      + +

      Consider the following example (python 3):

      + +
      +
      +pkg1/__init__.py        # (empty)
      +pkg1/pkg2/__init__.py   # (imports something from bar.py)
      +pkg1/pkg2/foo.py
      +pkg1/pkg2/bar.py        # (imports foo.py)
      +
      +
      + +

      Let's the files' contents be:

      + +
        +
      • for pkg1/pkg2/__init__.py:

        +
        +
        +# pkg1/pkg2/__init__.py
        +from .bar import Bar
        +
        +
        +
      • + +
      • for pkg1/pkg2/foo.py:

        +
        +
        +# pkg1/pkg2/foo.py
        +class Foo: pass
        +
        +
        +
      • + +
      • for pkg1/pkg2/foo.py:

        +
        +
        +# pkg1/pkg2/bar.py
        +import pkg1.pkg2.foo
        +class Bar(pkg1.pkg2.foo.Foo): pass
        +
        +
        +
      • +
      + +

      Now one would simply do import pkg1.pkg2, but this usually fails:

      + +
      +
      +>>> import pkg1.pkg2
      +Traceback (most recent call last):
      +  File "<stdin>", line 1, in <module>
      +  File "./pkg1/pkg2/__init__.py", line 2, in <module>
      +    from .bar import Bar
      +  File "./pkg1/pkg2/bar.py", line 3, in <module>
      +    class Bar(pkg1.pkg2.foo.Foo): pass
      +AttributeError: 'module' object has no attribute 'pkg2'
      +
      +
      + +

      Surprisingly, if we execute the import pkg1.pkg2 directive for the +second time, it succeeds. The reason seems to be following: when python spots +the from .bar import Bar directive in pkg1/pkg2/__init__.py +it starts loading pkg1/pkg2/bar.py. This module imports +pkg1.pkg2.foo in turn and tries to use pkg1.pkg2.foo.Foo, but +the package pkg1 is not fully initialized yet (the initialization +procedure is actually in progress) and it seems like the effect of already seen +directive import pkg1.pkg2.pkg3.foo is "delayed" or ignored. Exactly +same may happen to a proxy module generated by swig.

      + +

      It's observed, that a possible workaround for this case is to use relative +import in pkg1/pkg2/bar.py. If we change bar.py to be:

      + +
      +
      +from .pkg3 import foo
      +class Bar(foo.Foo): pass
      +
      +
      + +

      or

      + +
      +
      +from . import pkg3
      +from .pkg3 import foo
      +class Bar(pkg3.foo.Foo): pass
      +
      +
      + +

      then the example works again. With swig, you need to enable the +-relativeimport option in order to have the above workaround in +effect (note, that python 2 case also needs -relativeimport +workaround).

      + +

      34.12 Python 3 Support

      From 91120c84f2f3cc12f709d05d9dcc13e60018610c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 24 Dec 2013 14:39:25 +0000 Subject: [PATCH 0853/1160] Python imports documentation edits --- Doc/Manual/Python.html | 136 ++++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 2a719ca7a..c6cc2f40f 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -108,7 +108,7 @@
    • Python 3 Support @@ -5284,11 +5284,11 @@ code and may be grouped together to form a package. Packages may be nested, that is they may contain subpackages. This leads to tree-like hierarchy, with packages as intermediate nodes and modules as leaf nodes.

      -

      The hierarchy of python packages/modules follows the hierarchy of -*.py files found in source tree (or, more generally, in python path). +

      The hierarchy of Python packages/modules follows the hierarchy of +*.py files found in a source tree (or, more generally, in the Python path). Normally, the developer creates new module by placing a *.py file -somewhere under python path; the module is then named after that *.py -file. A package is created by placing __init__.py file within a +somewhere under Python path; the module is then named after that *.py +file. A package is created by placing an __init__.py file within a directory; the package is then named after that directory. For example, the following source tree:

      @@ -5303,7 +5303,7 @@ pkg1/pkg2/mod3.py
  • -defines the following python packages and modules: +defines the following Python packages and modules:

    @@ -5317,28 +5317,28 @@ pkg1.pkg2.mod3 # module

    -The purpose of __init__.py file is two-fold. First, existence of -__init__.py in a directory informs python interpreter that this -directory contains python package. Second, the code of __init__.py is +The purpose of an __init__.py file is two-fold. First, the existence of +__init__.py in a directory informs the Python interpreter that this +directory contains a Python package. Second, the code in __init__.py is loaded/executed automatically when the package is initialized (when it or its -submodule/subpackage gets import'ed). By default, swig generates -proxy python code – one *.py file for each *.i -interface. The __init__.py files, however, are not generated by swig. +submodule/subpackage gets import'ed). By default, SWIG generates +proxy Python code – one *.py file for each *.i +interface. The __init__.py files, however, are not generated by SWIG. They should be created by other means. Both files (module *.py and __init__.py) should be installed in appropriate destination -directories in order to obtain desirable package/module hierarchy. +directories in order to obtain a desirable package/module hierarchy.

    -

    The way python defines its modules and packages impacts swig users. Some -users may need to use special features such as package option of -%module directive or import-related command-line options. These are +

    The way Python defines its modules and packages impacts SWIG users. Some +users may need to use special features such as the package option in the +%module directive or import related command line options. These are explained in the following sections.

    -

    34.11.1 %module(package="...") syntax

    +

    34.11.1 Setting the Python package

    -Using the package option of the %module directive allows you -to specify a Python package that the module will be living in when installed. +Using the package option in the %module directive allows you +to specify a Python package that the module will be in when installed.

    @@ -5351,20 +5351,20 @@ to specify a Python package that the module will be living in when installed. This is useful when the .i file is %imported by another .i file. By default SWIG will assume that the importer is able to find the importee with just the module name, but -if they live in separate Python packages then that won't work. +if they live in separate Python packages then this won't work. However if the importee specifies what its package is with the %module option then the Python code generated for the importer will use that package name when importing the other module -and also in base class declarations, etc.. +and in base class declarations, etc..

    -

    Swig assumes, that the package option provided to %module +

    SWIG assumes that the package option provided to %module together with the module name (that is, wx.xrc in the above example) forms a fully qualified (absolute) name of a module (in Python terms). This is important especially for Python 3, where absolute imports are used by default. It's up to you to place the generated module files (.py, -.so) in proper subdirectories. For example, if you have -interface foo.i with: +.so) in appropriate subdirectories. For example, if you have an +interface file foo.i with:

    @@ -5374,7 +5374,7 @@ interface foo.i with:

    -then the resultant directory layout should be +then the resulting directory layout should be

    @@ -5382,8 +5382,8 @@ then the resultant directory layout should be pkg1/ pkg1/__init__.py pkg1/pkg2/__init__.py -pkg1/pkg2/foo.py # (generated by swig) -pkg1/pkg2/_foo.so # (shared library from C/C++ code generated by SWIG) +pkg1/pkg2/foo.py # (generated by SWIG) +pkg1/pkg2/_foo.so # (shared library built from C/C++ code generated by SWIG)
    @@ -5409,9 +5409,9 @@ class M3: pass

    -We edit pkg1/mod2.py and want to import module of +We edit pkg1/mod2.py and want to import module pkg1/pkg2/pkg3.py in order to derive from class M3. We can -write appropriate python code in several ways, for example: +write appropriate Python code in several ways, for example:

      @@ -5426,7 +5426,7 @@ class M2(pkg1.pkg2.mod3.M3): pass
    1. Using "import <>" syntax with package name relative to - pkg1 (only in python 2.7 and earlier):

      + pkg1 (only in Python 2.7 and earlier):

       # pkg1/mod2.py
      @@ -5437,7 +5437,7 @@ class M2(pkg2.mod3.M3): pass
         
    2. Using "from <> import <>" syntax (relative import - syntax, only in python 2.5 and later):

      + syntax, only in Python 2.5 and later):

       # pkg1/mod2.py
      @@ -5449,7 +5449,7 @@ class M2(mod3.M3): pass
       
         
    3. Other variants, for example the following construction in order to have the pkg2.mod3.M3 symbol available in mod2 as - in point 2 above (but now under python 3):

      + in point 2 above (but now under Python 3):

       # pkg1/mod2.py
      @@ -5483,13 +5483,13 @@ class M2(pkg2.mod3.M3): pass
       
      -

      By default, swig would generate mod2.py proxy file with -import directive as in point 1. This may be changed with --relativeimport CLI option. The -relativeimport instructs -swig to organize imports as in point 2 (for python 2.x) or as in point 4 (for -python 3, that is when -py3 CLI option is enabled). In short, if you have +

      By default, SWIG would generate mod2.py proxy file with +import directive as in point 1. This can be changed with the +-relativeimport command line option. The -relativeimport instructs +SWIG to organize imports as in point 2 (for Python 2.x) or as in point 4 (for +Python 3, that is when the -py3 command line option is enabled). In short, if you have mod2.i and mod3.i as above, then without --relativeimport swig will write

      +-relativeimport SWIG will write

      @@ -5515,20 +5515,20 @@ import pkg1.pkg2.mod3
       
      -

      when -py3 option is used.

      +

      when -py3 is used.

      You should avoid using relative imports and use absolute ones whenever possible. There are some cases, however, when relative imports may be -necessary. The first example is, when some (legacy) python code refers entities -imported by proxy files generated by swig, and it assumes that the proxy file +necessary. The first example is, when some (legacy) Python code refers entities +imported by proxy files generated by SWIG, and it assumes that the proxy file uses relative imports. Second case is, when one puts import directives in __init__.py to import symbols from submodules or subpackages and the submodule depends on other submodules (discussed later).

      34.11.3 Enforcing absolute import semantics

      -

      As you may know, there is incompatibility in import semantics (for the -import <> syntax) between python 2 and 3. In python 2.4 and +

      As you may know, there is an incompatibility in import semantics (for the +import <> syntax) between Python 2 and 3. In Python 2.4 and earlier it is not clear whether

      @@ -5537,10 +5537,10 @@ import foo
    4. refers to a top-level module or to another module inside the current -package. In python 3 it always refers to a top-level module +package. In Python 3 it always refers to a top-level module (see PEP 328). -To instruct python 2.5 through 2.7 to use new semantics (that is import -foo is interpreted as absolute import), one have to put the following +To instruct Python 2.5 through 2.7 to use new semantics (that is import +foo is interpreted as absolute import), one has to put the following line

      @@ -5550,26 +5550,26 @@ from __future__ import absolute_import
    -

    at the very beginning of his proxy *.py file. In swig, it may be +

    at the very beginning of his proxy *.py file. In SWIG, it may be accomplished with %pythonbegin directive.

    34.11.4 Importing from __init__.py

    -

    Imports in __init__.py are handy when you want to populate -package's namespace with names imported from other modules. In swig-based -projects this approach may also be used to split large piece of code into -smaller modules, compile them in parallel and then re-assemble all stuff at -python level by importing submodules' contents in __init__.py, for +

    Imports in __init__.py are handy when you want to populate a +package's namespace with names imported from other modules. In SWIG based +projects this approach may also be used to split large pieces of code into +smaller modules, compile them in parallel and then re-assemble everything at another +level by importing submodules' contents in __init__.py, for example.

    -

    Unfortunately import directives in __init__.py may cause troubles, -especially if they refer to package's submodules. This is caused by the way -python initializes packages. If you spot problems with imports from +

    Unfortunately import directives in __init__.py may cause problems, +especially if they refer to a package's submodules. This is caused by the way +Python initializes packages. If you spot problems with imports from __init__.py try using -relativeimport option. Below we explain in detail one issue, for which the -relativeimport workaround may be helpful.

    -

    Consider the following example (python 3):

    +

    Consider the following example (Python 3):

    @@ -5580,10 +5580,10 @@ pkg1/pkg2/bar.py        # (imports foo.py)
     
    -

    Let's the files' contents be:

    +

    If the file contents are:

      -
    • for pkg1/pkg2/__init__.py:

      +
    • pkg1/pkg2/__init__.py:

       # pkg1/pkg2/__init__.py
      @@ -5592,7 +5592,7 @@ from .bar import Bar
           
    • -
    • for pkg1/pkg2/foo.py:

      +
    • pkg1/pkg2/foo.py:

       # pkg1/pkg2/foo.py
      @@ -5601,7 +5601,7 @@ class Foo: pass
           
    • -
    • for pkg1/pkg2/foo.py:

      +
    • pkg1/pkg2/bar.py:

       # pkg1/pkg2/bar.py
      @@ -5612,7 +5612,7 @@ class Bar(pkg1.pkg2.foo.Foo): pass
         
    -

    Now one would simply do import pkg1.pkg2, but this usually fails:

    +

    Now if one simply used import pkg1.pkg2, it will usually fail:

    @@ -5628,16 +5628,16 @@ AttributeError: 'module' object has no attribute 'pkg2'
     

    Surprisingly, if we execute the import pkg1.pkg2 directive for the -second time, it succeeds. The reason seems to be following: when python spots +second time, it succeeds. The reason seems to be following: when Python spots the from .bar import Bar directive in pkg1/pkg2/__init__.py it starts loading pkg1/pkg2/bar.py. This module imports pkg1.pkg2.foo in turn and tries to use pkg1.pkg2.foo.Foo, but the package pkg1 is not fully initialized yet (the initialization -procedure is actually in progress) and it seems like the effect of already seen -directive import pkg1.pkg2.pkg3.foo is "delayed" or ignored. Exactly -same may happen to a proxy module generated by swig.

    +procedure is actually in progress) and it seems like the effect of the already seen +import pkg1.pkg2.pkg3.foo is "delayed" or ignored. Exactly the +same may happen to a proxy module generated by SWIG.

    -

    It's observed, that a possible workaround for this case is to use relative +

    One workaround for this case is to use a relative import in pkg1/pkg2/bar.py. If we change bar.py to be:

    @@ -5657,9 +5657,9 @@ class Bar(pkg3.foo.Foo): pass
    -

    then the example works again. With swig, you need to enable the +

    then the example works again. With SWIG, you need to enable the -relativeimport option in order to have the above workaround in -effect (note, that python 2 case also needs -relativeimport +effect (note, that the Python 2 case also needs the -relativeimport workaround).

    From 2866c70f78cc8796323a9f7fb58d3222a162e349 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 24 Dec 2013 17:19:59 +0000 Subject: [PATCH 0854/1160] Add changes entry for python imports/packages changes --- CHANGES.current | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 5629532b7..7856c796e 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,27 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-12-24: ptomulik + [Python] SF Bug #1297 + + Resolve several issues related to python imports. + For example, it's now possible to import modules having the same module + names, but belonging in different packages. + + From the user's viewpoint, this patch gives a little bit more control on + import statements generated by SWIG. The user may choose to use relative + or absolute imports. + + Some details: + - we (still) generate import statements in the form 'import a.b.c' which + corresponds to absolute imports in python3 and (the only available) + ambiguous one in python2. + - added -relativeimport option to use explicit relative import syntax + (python3), + + The "Python Packages" section in the documentation discusses how to work + with importing packages including the new -relativeimport command line option. + 2013-12-23: vadz [Octave, Perl, Python, R, Ruby, Tcl] Change the length of strings created from fixed-size char buffers in C code. From fc3098ea55de41c5d6912286516fb1ae262a97b4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 3 Jan 2014 08:27:41 +0000 Subject: [PATCH 0855/1160] auto_ptr deprecation warning suppression --- Examples/test-suite/li_std_auto_ptr.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/li_std_auto_ptr.i b/Examples/test-suite/li_std_auto_ptr.i index 1dcb3e02e..627572d5c 100644 --- a/Examples/test-suite/li_std_auto_ptr.i +++ b/Examples/test-suite/li_std_auto_ptr.i @@ -1,7 +1,7 @@ %module li_std_auto_ptr %{ -#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) +#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) #pragma GCC diagnostic ignored "-Wdeprecated-declarations" // auto_ptr deprecation #endif %} From 6a72e16b371bf9b22324a157ec9e48f04dc802f0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 3 Jan 2014 19:23:35 +0000 Subject: [PATCH 0856/1160] Add C++11 virtual specifier sequences (final and/or override on methods) Parsing support added. The final and override information is not used or added to the parse tree atm. --- Doc/Manual/CPlusPlus11.html | 23 ++++ Examples/test-suite/common.mk | 1 + Examples/test-suite/cpp11_final_override.i | 128 +++++++++++++++++++++ Source/CParse/cscanner.c | 16 +-- Source/CParse/parser.y | 85 +++++++++----- 5 files changed, 218 insertions(+), 35 deletions(-) create mode 100644 Examples/test-suite/cpp11_final_override.i diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index 0d2f22aff..9d315d8e3 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -414,6 +414,29 @@ class DerivedClass: public BaseClass { };
    +

    Explicit overrides and final

    + +

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

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

    7.2.11 Null pointer constant

    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 642e7fd8c..fb53a0ec9 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -490,6 +490,7 @@ CPP11_TEST_CASES = \ cpp11_default_delete \ cpp11_delegating_constructors \ cpp11_explicit_conversion_operators \ + cpp11_final_override \ cpp11_function_objects \ cpp11_inheriting_constructors \ cpp11_initializer_list \ diff --git a/Examples/test-suite/cpp11_final_override.i b/Examples/test-suite/cpp11_final_override.i new file mode 100644 index 000000000..f691f8770 --- /dev/null +++ b/Examples/test-suite/cpp11_final_override.i @@ -0,0 +1,128 @@ +// Test C++11 virtual specifier sequences (final and/or override on methods) +// Also check final/override - the two 'identifiers with special meaning' work as normal identifiers + +%module cpp11_final_override + +%warnfilter(SWIGWARN_PARSE_KEYWORD) final; // 'final' is a java keyword, renaming to '_final' +%warnfilter(SWIGWARN_PARSE_KEYWORD) override; // 'override' is a C# keyword, renaming to '_override' + +%inline %{ + +struct Base { + virtual void stuff() const {} + virtual void override1() const {} + virtual void override2() const {} + virtual void finaloverride1() {} + virtual void finaloverride2() {} + virtual void finaloverride3() {} + virtual void finaloverride4() const {} + virtual ~Base() {} +}; + +struct Derived /*final*/ : Base { + virtual void stuff() const noexcept override final {} + virtual void override1() const noexcept override; + virtual void override2() const noexcept override; + virtual void final1() final {} + virtual void final2() noexcept final {} + virtual void final4() const final {} + virtual void final5() const noexcept final {} + virtual void finaloverride1() final override {} + virtual void finaloverride2() override final {} + virtual void finaloverride3() noexcept override final {} + virtual void finaloverride4() const noexcept override final {} + virtual ~Derived() override final {} +}; +void Derived::override2() const noexcept {} + +// Pure virtual methods +struct PureBase { + virtual void pure1(int) const = 0; + virtual void pure2(int) const = 0; + virtual void pure3(int) const = 0; + virtual void pure4(int) const = 0; + virtual void pure5(int) const = 0; + virtual ~PureBase() {} +}; + +struct PureDerived : PureBase { + virtual void pure1(int) const override = 0; + virtual void pure2(int) const final = 0; + virtual void pure3(int) const override final = 0; + virtual void pure4(int) const final override = 0; + virtual void pure5(int) const noexcept final override = 0; + virtual ~PureDerived() override final; +}; +void PureDerived::pure1(int) const {} +void PureDerived::pure2(int) const {} +void PureDerived::pure3(int) const {} +void PureDerived::pure4(int) const {} +void PureDerived::pure5(int) const noexcept {} +PureDerived::~PureDerived() {} + +// Destructors and virtual specifier sequences (final/override) +struct Destructors1 : Base { + virtual ~Destructors1() override {} +}; +struct Destructors2 : Base { + virtual ~Destructors2() final {} +}; +struct Destructors3 : Base { + virtual ~Destructors3() noexcept final override {} +}; +struct Destructors4 : Base { + virtual ~Destructors4() noexcept override final {} +}; + +// Check the two 'identifiers with special meaning' work as normal identifiers +struct FinalOverrideMethods { + virtual void final() {} + virtual void override(int) {} +}; +struct FinalOverrideVariables { + int final; + double override; +}; +void final(int) {} +void override() {} +%} + +%{ +void Derived::override1() const noexcept {} +%} + +// Example in documentation ... declarations only +%inline %{ +struct BaseStruct { + virtual void ab() const = 0; + virtual void cd(); + virtual void ef(); + virtual ~BaseStruct(); +}; +struct DerivedStruct : BaseStruct { + virtual void ab() const override; + virtual void cd() final; + virtual void ef() final override; + virtual ~DerivedStruct() override; +}; +struct DerivedNoVirtualStruct : BaseStruct { + void ab() const override; + void cd() final; + void ef() final override; + ~DerivedNoVirtualStruct() override; +}; +%} + +%{ +void BaseStruct::cd() {} +void BaseStruct::ef() {} +BaseStruct::~BaseStruct() {} +void DerivedStruct::ab() const {} +void DerivedStruct::cd() {} +void DerivedStruct::ef() {} +DerivedStruct::~DerivedStruct() {} +void DerivedNoVirtualStruct::ab() const {} +void DerivedNoVirtualStruct::cd() {} +void DerivedNoVirtualStruct::ef() {} +DerivedNoVirtualStruct::~DerivedNoVirtualStruct() {} +%} diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index 2dfc2c479..4e02b4b62 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -748,18 +748,18 @@ int yylex(void) { yylval.intvalue = cparse_line; return (TEMPLATE); } - if (strcmp(yytext, "delete") == 0) { + if (strcmp(yytext, "delete") == 0) return (DELETE_KW); - } - if (strcmp(yytext, "default") == 0) { + if (strcmp(yytext, "default") == 0) return (DEFAULT); - } - if (strcmp(yytext, "using") == 0) { + if (strcmp(yytext, "using") == 0) return (USING); - } - if (strcmp(yytext, "namespace") == 0) { + if (strcmp(yytext, "namespace") == 0) return (NAMESPACE); - } + if (strcmp(yytext, "override") == 0) + return (OVERRIDE); + if (strcmp(yytext, "final") == 0) + return (FINAL); } else { if (strcmp(yytext, "class") == 0) { Swig_warning(WARN_PARSE_CLASS_KEYWORD, cparse_file, cparse_line, "class keyword used, but not in C++ mode.\n"); diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index a7604ff56..fe8b7f97f 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1388,8 +1388,9 @@ static void mark_nodes_as_extend(Node *n) { %token ILLEGAL CONSTANT %token NAME RENAME NAMEWARN EXTEND PRAGMA FEATURE VARARGS %token ENUM -%token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT AUTO NOEXCEPT -%token STATIC_ASSERT CONSTEXPR THREAD_LOCAL DECLTYPE /* C++11 keywords */ +%token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT +%token STATIC_ASSERT CONSTEXPR THREAD_LOCAL DECLTYPE AUTO NOEXCEPT /* C++11 keywords */ +%token OVERRIDE FINAL /* C++11 identifiers with special meaning */ %token USING %token NAMESPACE %token NATIVE INLINE @@ -1443,6 +1444,7 @@ static void mark_nodes_as_extend(Node *n) { %type kwargs options; /* Misc */ +%type identifier; %type initializer cpp_const exception_specification; %type storage_class; %type parms ptail rawparms varargs_parms ; @@ -1480,6 +1482,7 @@ static void mark_nodes_as_extend(Node *n) { %type lambda_introducer lambda_body; %type lambda_tail; %type optional_constant_directive; +%type virt_specifier_seq; %% @@ -1701,7 +1704,7 @@ clear_directive : CLEAR tm_list SEMI { %constant type name = value; ------------------------------------------------------------ */ -constant_directive : CONSTANT ID EQUAL definetype SEMI { +constant_directive : CONSTANT identifier EQUAL definetype SEMI { if (($4.type != T_ERROR) && ($4.type != T_SYMBOL)) { SwigType *type = NewSwigType($4.type); $$ = new_node("constant"); @@ -1783,7 +1786,7 @@ echo_directive : ECHO HBLOCK { %except; ------------------------------------------------------------ */ -except_directive : EXCEPT LPAREN ID RPAREN LBRACE { +except_directive : EXCEPT LPAREN identifier RPAREN LBRACE { skip_balanced('{','}'); $$ = 0; Swig_warning(WARN_DEPRECATED_EXCEPT,cparse_file, cparse_line, "%%except is deprecated. Use %%exception instead.\n"); @@ -1795,7 +1798,7 @@ except_directive : EXCEPT LPAREN ID RPAREN LBRACE { Swig_warning(WARN_DEPRECATED_EXCEPT,cparse_file, cparse_line, "%%except is deprecated. Use %%exception instead.\n"); } - | EXCEPT LPAREN ID RPAREN SEMI { + | EXCEPT LPAREN identifier RPAREN SEMI { $$ = 0; Swig_warning(WARN_DEPRECATED_EXCEPT,cparse_file, cparse_line, "%%except is deprecated. Use %%exception instead.\n"); } @@ -2080,13 +2083,13 @@ name_directive : NAME LPAREN idstring RPAREN { %native(scriptname) type name (parms); ------------------------------------------------------------ */ -native_directive : NATIVE LPAREN ID RPAREN storage_class ID SEMI { +native_directive : NATIVE LPAREN identifier RPAREN storage_class identifier SEMI { $$ = new_node("native"); Setattr($$,"name",$3); Setattr($$,"wrap:name",$6); add_symbols($$); } - | NATIVE LPAREN ID RPAREN storage_class type declarator SEMI { + | NATIVE LPAREN identifier RPAREN storage_class type declarator SEMI { if (!SwigType_isfunction($7.type)) { Swig_error(cparse_file,cparse_line,"%%native declaration '%s' is not a function.\n", $7.id); $$ = 0; @@ -2112,13 +2115,13 @@ native_directive : NATIVE LPAREN ID RPAREN storage_class ID SEMI { %pragma name ------------------------------------------------------------ */ -pragma_directive : PRAGMA pragma_lang ID EQUAL pragma_arg { +pragma_directive : PRAGMA pragma_lang identifier EQUAL pragma_arg { $$ = new_node("pragma"); Setattr($$,"lang",$2); Setattr($$,"name",$3); Setattr($$,"value",$5); } - | PRAGMA pragma_lang ID { + | PRAGMA pragma_lang identifier { $$ = new_node("pragma"); Setattr($$,"lang",$2); Setattr($$,"name",$3); @@ -2129,13 +2132,12 @@ pragma_arg : string { $$ = NewString($1); } | HBLOCK { $$ = $1; } ; -pragma_lang : LPAREN ID RPAREN { $$ = $2; } +pragma_lang : LPAREN identifier RPAREN { $$ = $2; } | empty { $$ = (char *) "swig"; } ; /* ------------------------------------------------------------ - %rename identifier newname; - %rename identifier "newname"; + %rename(newname) identifier; ------------------------------------------------------------ */ rename_directive : rename_namewarn declarator idstring SEMI { @@ -2883,7 +2885,7 @@ c_declaration : c_decl { $$ = 0; /* TODO - ignored for now */ } - | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL ID { + | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL identifier { skip_decl(); $$ = new_node("using"); Setattr($$,"uname",$8); @@ -4221,7 +4223,7 @@ cpp_namespace_decl : NAMESPACE idcolon LBRACE { Namespaceprefix = Swig_symbol_qualifiedscopename(0); add_symbols($$); } - | NAMESPACE ID EQUAL idcolon SEMI { + | NAMESPACE identifier EQUAL idcolon SEMI { /* Namespace alias */ Node *n; $$ = new_node("namespace"); @@ -5810,7 +5812,7 @@ explicit_default : DEFAULT { /* Some stuff for handling enums */ -ename : ID { $$ = $1; } +ename : identifier { $$ = $1; } | empty { $$ = (char *) 0;} ; @@ -5837,7 +5839,7 @@ enumlist : enumlist COMMA optional_constant_directive edecl optional_cons } ; -edecl : ID { +edecl : identifier { SwigType *type = NewSwigType(T_INT); $$ = new_node("enumitem"); Setattr($$,"name",$1); @@ -5845,7 +5847,7 @@ edecl : ID { SetFlag($$,"feature:immutable"); Delete(type); } - | ID EQUAL etype { + | identifier EQUAL etype { SwigType *type = NewSwigType($3.type == T_BOOL ? T_BOOL : ($3.type == T_CHAR ? T_CHAR : T_INT)); $$ = new_node("enumitem"); Setattr($$,"name",$1); @@ -6263,6 +6265,20 @@ opt_virtual : VIRTUAL | empty ; +virt_specifier_seq : OVERRIDE { + $$ = 0; + } + | FINAL { + $$ = 0; + } + | FINAL OVERRIDE { + $$ = 0; + } + | OVERRIDE FINAL { + $$ = 0; + } + ; + exception_specification : THROW LPAREN parms RPAREN { $$.throws = $3; $$.throwf = NewString("1"); @@ -6273,7 +6289,16 @@ exception_specification : THROW LPAREN parms RPAREN { $$.throwf = 0; $$.nexcept = NewString("true"); } - + | virt_specifier_seq { + $$.throws = 0; + $$.throwf = 0; + $$.nexcept = 0; + } + | NOEXCEPT virt_specifier_seq { + $$.throws = 0; + $$.throwf = 0; + $$.nexcept = NewString("true"); + } | NOEXCEPT LPAREN expr RPAREN { $$.throws = 0; $$.throwf = 0; @@ -6390,7 +6415,13 @@ template_decl : LESSTHAN valparms GREATERTHAN { | empty { $$ = (char*)""; } ; -idstring : ID { $$ = $1; } +/* Identifiers including the C++11 identifiers with special meaning */ +identifier : ID { $$ = $1; } + | OVERRIDE { $$ = Swig_copy_string("override"); } + | FINAL { $$ = Swig_copy_string("final"); } + ; + +idstring : identifier { $$ = $1; } | default_delete { $$ = $1.val; } | string { $$ = $1; } ; @@ -6442,7 +6473,7 @@ idcolontail : DCOLON idtemplate idcolontail { ; -idtemplate : ID template_decl { +idtemplate : identifier template_decl { $$ = NewStringf("%s%s",$1,$2); /* if (Len($2)) { scanner_last_id(1); @@ -6451,19 +6482,19 @@ idtemplate : ID template_decl { ; /* Identifier, but no templates */ -idcolonnt : ID idcolontailnt { +idcolonnt : identifier idcolontailnt { $$ = 0; if (!$$) $$ = NewStringf("%s%s", $1,$2); Delete($2); } - | NONID DCOLON ID idcolontailnt { + | NONID DCOLON identifier idcolontailnt { $$ = NewStringf("::%s%s",$3,$4); Delete($4); } - | ID { + | identifier { $$ = NewString($1); } - | NONID DCOLON ID { + | NONID DCOLON identifier { $$ = NewStringf("::%s",$3); } | OPERATOR { @@ -6474,17 +6505,17 @@ idcolonnt : ID idcolontailnt { } ; -idcolontailnt : DCOLON ID idcolontailnt { +idcolontailnt : DCOLON identifier idcolontailnt { $$ = NewStringf("::%s%s",$2,$3); Delete($3); } - | DCOLON ID { + | DCOLON identifier { $$ = NewStringf("::%s",$2); } | DCOLON OPERATOR { $$ = NewStringf("::%s",$2); } - | DCNOT ID { + | DCNOT identifier { $$ = NewStringf("::~%s",$2); } ; From 324818030b3fab5f4e205c45adbcfcb04cda0c82 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 31 Dec 2013 15:18:01 +0100 Subject: [PATCH 0857/1160] PHP: document byref typemap attribute --- Doc/Manual/Php.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 185883235..19bfab6ba 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -513,6 +513,12 @@ So if you use these REF typemaps, you should ensure that SWIG≥3.0 is used to generate wrappers from your interface file.

    +

    +In case you write your own typemaps, SWIG supports an attribute called +byref: if you set that, then SWIG will make sure that the generated +wrapper function will want the input parameter as a reference. +

    +
     %module example
     %include "phppointers.i"
    
    From d67aed42bd0a3cb71a12aec8822d69b3ebbe5599 Mon Sep 17 00:00:00 2001
    From: Olly Betts 
    Date: Mon, 6 Jan 2014 15:41:06 +1300
    Subject: [PATCH 0858/1160] Remove executable bit from various test-suite runme
     files
    
    ---
     Examples/guile/matrix/runme.scm                     | 0
     Examples/php/pragmas/runme.php                      | 0
     Examples/php/simple/runme.php                       | 0
     Examples/pike/class/runme.pike                      | 0
     Examples/pike/constants/runme.pike                  | 0
     Examples/pike/template/runme.pike                   | 0
     Examples/test-suite/php/threads_exception_runme.php | 0
     7 files changed, 0 insertions(+), 0 deletions(-)
     mode change 100755 => 100644 Examples/guile/matrix/runme.scm
     mode change 100755 => 100644 Examples/php/pragmas/runme.php
     mode change 100755 => 100644 Examples/php/simple/runme.php
     mode change 100755 => 100644 Examples/pike/class/runme.pike
     mode change 100755 => 100644 Examples/pike/constants/runme.pike
     mode change 100755 => 100644 Examples/pike/template/runme.pike
     mode change 100755 => 100644 Examples/test-suite/php/threads_exception_runme.php
    
    diff --git a/Examples/guile/matrix/runme.scm b/Examples/guile/matrix/runme.scm
    old mode 100755
    new mode 100644
    diff --git a/Examples/php/pragmas/runme.php b/Examples/php/pragmas/runme.php
    old mode 100755
    new mode 100644
    diff --git a/Examples/php/simple/runme.php b/Examples/php/simple/runme.php
    old mode 100755
    new mode 100644
    diff --git a/Examples/pike/class/runme.pike b/Examples/pike/class/runme.pike
    old mode 100755
    new mode 100644
    diff --git a/Examples/pike/constants/runme.pike b/Examples/pike/constants/runme.pike
    old mode 100755
    new mode 100644
    diff --git a/Examples/pike/template/runme.pike b/Examples/pike/template/runme.pike
    old mode 100755
    new mode 100644
    diff --git a/Examples/test-suite/php/threads_exception_runme.php b/Examples/test-suite/php/threads_exception_runme.php
    old mode 100755
    new mode 100644
    
    From 90eb5f9095e65a585ee839aba435a50fcaaf1801 Mon Sep 17 00:00:00 2001
    From: Ian Lance Taylor 
    Date: Mon, 6 Jan 2014 09:28:52 -0800
    Subject: [PATCH 0859/1160] [Go] Fix bug that broke using directors from a
     thread not created by Go.
    
    ---
     CHANGES.current       | 4 ++++
     Source/Modules/go.cxx | 2 ++
     2 files changed, 6 insertions(+)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index 7856c796e..431f327bb 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
     Version 3.0.0 (in progress)
     ============================
     
    +2014-01-06: ianlancetaylor
    +	    [Go] Fix bug that broke using directors from a thread not
    +	    created by Go.
    +
     2013-12-24: ptomulik
                 [Python] SF Bug #1297
     
    diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx
    index 3dec6503b..36e5d11d3 100644
    --- a/Source/Modules/go.cxx
    +++ b/Source/Modules/go.cxx
    @@ -2861,6 +2861,7 @@ private:
     
     	Printv(f_gc_wrappers, "#pragma dynexport ", wname, " ", wname, "\n", NULL);
     	Printv(f_gc_wrappers, "#pragma cgo_export_static ", wname, " ", wname, "\n", NULL);
    +	Printv(f_gc_wrappers, "#pragma textflag 7\n", NULL);
     	Printv(f_gc_wrappers, "extern void \xc2\xb7", go_name, "();\n", NULL);
     	Printv(f_gc_wrappers, "void\n", NULL);
     	Printv(f_gc_wrappers, wname, "(void *a, int32 n)\n", NULL);
    @@ -3591,6 +3592,7 @@ 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, "#pragma cgo_export_static ", callback_wname, " ", callback_wname, "\n", NULL);
    +	  Printv(f_gc_wrappers, "#pragma textflag 7\n", NULL);
     	  Printv(f_gc_wrappers, "extern void \xc2\xb7", callback_name, "();\n", NULL);
     	  Printv(f_gc_wrappers, "void\n", NULL);
     	  Printv(f_gc_wrappers, callback_wname, "(void *a, int32 n)\n", NULL);
    
    From 40bf8774997dfbd791677a9abd96e3babadef73b Mon Sep 17 00:00:00 2001
    From: Vadim Zeitlin 
    Date: Fri, 10 Jan 2014 14:38:54 +0100
    Subject: [PATCH 0860/1160] Work around gcc warning about function pointers
     conversions.
    
    Work around harmless (at least under POSIX systems where function pointers are
    guaranteed to have the same representation as object pointers) but annoying
    warnings given by gcc when converting between function and object pointers, e.g.
    
    Source/DOH/fio.c: In function 'DohEncoding':
    Source/DOH/fio.c:51: warning: ISO C forbids conversion of function pointer to object pointer type
    Source/DOH/fio.c: In function 'encode':
    Source/DOH/fio.c:75: warning: ISO C forbids conversion of object pointer to function pointer type
    Source/DOH/base.c: In function 'DohCall':
    Source/DOH/base.c:952: warning: ISO C forbids conversion of object pointer to function pointer type
    
    Use an extra level of pointer indirection to avoid them.
    ---
     Source/DOH/base.c | 2 +-
     Source/DOH/fio.c  | 4 ++--
     2 files changed, 3 insertions(+), 3 deletions(-)
    
    diff --git a/Source/DOH/base.c b/Source/DOH/base.c
    index 1f92b6542..e84731cd0 100644
    --- a/Source/DOH/base.c
    +++ b/Source/DOH/base.c
    @@ -949,7 +949,7 @@ DOH *DohCall(DOH *func, DOH *args) {
       DOH *result;
       DOH *(*builtin) (DOH *);
     
    -  builtin = (DOH *(*)(DOH *)) GetVoid(func, "builtin");
    +  *(void **)(&builtin) = GetVoid(func, "builtin");
       if (!builtin)
         return 0;
       result = (*builtin) (args);
    diff --git a/Source/DOH/fio.c b/Source/DOH/fio.c
    index d2a1bab19..71ce30149 100644
    --- a/Source/DOH/fio.c
    +++ b/Source/DOH/fio.c
    @@ -48,7 +48,7 @@ static int Writen(DOH *out, void *buffer, int len) {
     void DohEncoding(const char *name, DOH *(*fn) (DOH *s)) {
       if (!encodings)
         encodings = NewHash();
    -  Setattr(encodings, (void *) name, NewVoid((void *) fn, 0));
    +  Setattr(encodings, (void *) name, NewVoid(*(void **)&fn, 0));
     }
     
     /* internal function for processing an encoding */
    @@ -72,7 +72,7 @@ static DOH *encode(char *name, DOH *s) {
         s = tmp;
       pos = Tell(s);
       Seek(s, 0, SEEK_SET);
    -  fn = (DOH *(*)(DOH *)) Data(handle);
    +  *(void **)(&fn) = Data(handle);
       ns = (*fn) (s);
       assert(pos != -1);
       (void)Seek(s, pos, SEEK_SET);
    
    From e702093c70ce065b8b26d855203ca797b05c9b48 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Tue, 7 Jan 2014 20:03:14 +0000
    Subject: [PATCH 0861/1160] Template private assignment testcase
    
    This is broken and needs fixing at some point.
    Problem reported by Pierre-Henri Wuillemin on swig-devel mailing list.
    ---
     Examples/test-suite/common.mk                 |  1 +
     .../test-suite/template_private_assignment.i  | 24 +++++++++++++++++++
     2 files changed, 25 insertions(+)
     create mode 100644 Examples/test-suite/template_private_assignment.i
    
    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
    index fb53a0ec9..d96d42018 100644
    --- a/Examples/test-suite/common.mk
    +++ b/Examples/test-suite/common.mk
    @@ -87,6 +87,7 @@ CPP_TEST_BROKEN += \
     	nested_private \
     	overload_complicated \
     	template_default_pointer \
    +	template_private_assignment \
     	template_expr \
     	$(CPP11_TEST_BROKEN)
     
    diff --git a/Examples/test-suite/template_private_assignment.i b/Examples/test-suite/template_private_assignment.i
    new file mode 100644
    index 000000000..e135e3913
    --- /dev/null
    +++ b/Examples/test-suite/template_private_assignment.i
    @@ -0,0 +1,24 @@
    +%module template_private_assignment
    +
    +/*
    +swig-devel mailing list report problem explained 2014-01-07
    +A setter for the global variable deleted_bits is generated because there is no template
    +instantiation for the template and hence SWIG does not find the private assignment operator.
    +SwigValueWrapper is probably on by default for templates that are not instantiated for the
    +same reason.
    +The solution is probably to add an instantiation of the template as soon as one is parsed,
    +that is an implicit empty %template().
    +*/
    +
    +%inline %{
    +template struct DeletedBits {
    +//  DeletedBits& operator=(const DeletedBits&) = delete;
    +private:
    +  DeletedBits& operator=(const DeletedBits&);
    +};
    +
    +DeletedBits deleted_bits;
    +%}
    +
    +// This works around the problem
    +//%template() DeletedBits;
    
    From c34d7f6d23d958f37f62dda2b9162663c4ca4410 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Sat, 11 Jan 2014 13:10:30 +0000
    Subject: [PATCH 0862/1160] %naturalvar feature fixes and documentation
    
    Fix and document the naturalvar feature override behaviour - the naturalvar
    feature attached to a variable name has precedence over the naturalvar
    feature attached to the variable's type. The overriding was not working
    when turning the feature off on the variable's name.
    
    Fix so that any use of the naturalvar feature will override the global
    setting. Previously when set globally by -naturalvar or %module(naturalvar=1),
    use of the naturalvar feature was not always honoured.
    ---
     CHANGES.current                               | 10 +++
     Doc/Manual/SWIGPlus.html                      | 68 +++++++++++--------
     Examples/test-suite/common.mk                 |  1 +
     .../java/naturalvar_onoff_runme.java          | 37 ++++++++++
     Examples/test-suite/naturalvar_onoff.i        | 29 ++++++++
     Source/Modules/lang.cxx                       | 23 +++++--
     6 files changed, 133 insertions(+), 35 deletions(-)
     create mode 100644 Examples/test-suite/java/naturalvar_onoff_runme.java
     create mode 100644 Examples/test-suite/naturalvar_onoff.i
    
    diff --git a/CHANGES.current b/CHANGES.current
    index 431f327bb..a4fc5dbf4 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -5,6 +5,16 @@ See the RELEASENOTES file for a summary of changes in each release.
     Version 3.0.0 (in progress)
     ============================
     
    +2014-01-11: wsfulton
    +            Fix and document the naturalvar feature override behaviour - the naturalvar
    +            feature attached to a variable name has precedence over the naturalvar
    +            feature attached to the variable's type. The overriding was not working
    +            when turning the feature off on the variable's name.
    +
    +            Fix so that any use of the naturalvar feature will override the global
    +            setting. Previously when set globally by -naturalvar or %module(naturalvar=1),
    +            use of the naturalvar feature was not always honoured.
    +
     2014-01-06: ianlancetaylor
     	    [Go] Fix bug that broke using directors from a thread not
     	    created by Go.
    diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html
    index 3c3c7d564..e0e7dbcaf 100644
    --- a/Doc/Manual/SWIGPlus.html
    +++ b/Doc/Manual/SWIGPlus.html
    @@ -959,8 +959,9 @@ Similarly, all data attributes declared as const are wrapped as read-on
     

    +By default, SWIG uses the const reference typemaps for members that are primitive types. There are some subtle issues when wrapping data members that are -themselves classes. For instance, if you had another class like this, +not primitive types, such as classes. For instance, if you had another class like this,

    @@ -973,7 +974,8 @@ public:

    -then the low-level accessor to the items member actually uses pointers. For example: +then the low-level accessor to the items member actually uses pointers. +For example:

    @@ -998,31 +1000,7 @@ This can be somewhat unnatural for some types. For example, a user would expect the STL std::string class member variables to be wrapped as a string in the target language, rather than a pointer to this class. The const reference typemaps offer this type of marshalling, so there is a feature to tell SWIG to use the const reference typemaps rather than the pointer typemaps. -It is the %naturalvar directive and is used as follows: -

    - -
    -
    -// All List variables will use const List& typemaps
    -%naturalvar List;
    -
    -// Only Foo::myList will use const List& typemaps
    -%naturalvar Foo::myList;
    -struct Foo {
    -  List myList;
    -};
    -
    -// All variables will use const reference typemaps
    -%naturalvar;
    -
    -
    - -

    -The observant reader will notice that %naturalvar works like any other -feature flag directive, -except it can also be attached to class types. -The first of the example usages above show %naturalvar attaching to the List class. -Effectively this feature changes the way accessors are generated to the following: +It is the naturalvar feature and can be used to effectively change the way accessors are generated to the following:

    @@ -1037,15 +1015,45 @@ void Foo_items_set(Foo *self, const List &value) {

    -In fact it is generally a good idea to use this feature globally as the reference typemaps have extra NULL checking compared to the pointer typemaps. +The %naturalvar directive is a macro for, and hence equivalent to, %feature("naturalvar"). It can be used as follows: +

    + +
    +
    +// All List variables will use const List& typemaps
    +%naturalvar List;
    +
    +// Only Foo::myList will use const List& typemaps
    +%naturalvar Foo::myList;
    +struct Foo {
    +  List myList;
    +};
    +
    +// All non-primitive types will use const reference typemaps
    +%naturalvar;
    +
    +
    + +

    +The observant reader will notice that %naturalvar works like any other +feature flag directive but with some extra flexibility. +The first of the example usages above shows %naturalvar attaching to the myList's variable type, that is the List class. +The second usage shows %naturalvar attaching to the variable name. +Hence the naturalvar feature can be used on either the variable's name or type. +Note that using the naturalvar feature on a variable's name overrides any naturalvar feature attached to the variable's type. +

    + +

    +It is generally a good idea to use this feature globally as the reference typemaps have extra NULL checking compared to the pointer typemaps. A pointer can be NULL, whereas a reference cannot, so the extra checking ensures that the target language user does not pass in a value that translates to a NULL pointer and thereby preventing any potential NULL pointer dereferences. The %naturalvar feature will apply to global variables in addition to member variables in some language modules, eg C# and Java.

    -Other alternatives for turning this feature on globally are to use the swig -naturalvar commandline option -or the module mode option, %module(naturalvar=1) +The naturalvar behavior can also be turned on as a global setting via the -naturalvar commandline option +or the module mode option, %module(naturalvar=1). +However, any use of %feature("naturalvar") will override the global setting.

    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index d96d42018..86d688799 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -279,6 +279,7 @@ CPP_TEST_CASES += \ nspace_extend \ naturalvar \ naturalvar_more \ + naturalvar_onoff \ nested_class \ nested_comment \ nested_scope \ diff --git a/Examples/test-suite/java/naturalvar_onoff_runme.java b/Examples/test-suite/java/naturalvar_onoff_runme.java new file mode 100644 index 000000000..d9b78af24 --- /dev/null +++ b/Examples/test-suite/java/naturalvar_onoff_runme.java @@ -0,0 +1,37 @@ + +import naturalvar_onoff.*; + +public class naturalvar_onoff_runme { + static { + try { + System.loadLibrary("naturalvar_onoff"); + } 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[]) + { + boolean fail = true; + Vars vars = new Vars(); + + fail = true; try { + vars.setMember1On(null); + } catch(NullPointerException e) {fail = false;} if (fail) throw new RuntimeException("Failed"); + + vars.setMember2Off(null); + + vars.setMember3Off(null); + + fail = true; try { + vars.setMember3On(null); + } catch(NullPointerException e) {fail = false;} if (fail) throw new RuntimeException("Failed"); + + vars.setMember4Off(null); + + fail = true; try { + vars.setMember4On(null); + } catch(NullPointerException e) {fail = false;} if (fail) throw new RuntimeException("Failed"); + } +} diff --git a/Examples/test-suite/naturalvar_onoff.i b/Examples/test-suite/naturalvar_onoff.i new file mode 100644 index 000000000..3d96dd69d --- /dev/null +++ b/Examples/test-suite/naturalvar_onoff.i @@ -0,0 +1,29 @@ +%module naturalvar_onoff + +// Test naturalvar feature override is working - +// naturalvar on the variable name has priority over naturalvar on the variable's type +// Use runtime tests to differentiate between the const ref typemaps and pointer typemap - +// using the fact that NULL cannot be passed to the ref typemaps + +%naturalvar Member1; +%nonaturalvar Member2; +%naturalvar Member3; +%nonaturalvar Vars::member3Off; +%nonaturalvar Member4; +%naturalvar Vars::member4On; + +%inline %{ +struct Member1 {}; +struct Member2 {}; +struct Member3 {}; +struct Member4 {}; + +struct Vars { + Member1 member1On; + Member2 member2Off; + Member3 member3Off; + Member3 member3On; + Member4 member4Off; + Member4 member4On; +}; +%} diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index c3c148fa5..8b8382712 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -473,12 +473,21 @@ void swig_pragma(char *lang, char *name, char *value) { /* -------------------------------------------------------------------------- * Language::use_naturalvar_mode() + * + * Determine whether to use const ref typemaps instead of pointer typemaps + * for variable access. * -------------------------------------------------------------------------- */ int Language::use_naturalvar_mode(Node *n) const { if (Getattr(n, "unnamed")) return 0; - int nvar = naturalvar_mode || GetFlag(n, "feature:naturalvar"); - if (!nvar) { + + // The naturalvar feature can be attached to either the variable name or the variable's type + // naturalvar on the variable name is more specific and overrides naturalvar on the variable's type + String *naturalvar = Getattr(n, "feature:naturalvar"); + bool explicitly_off = naturalvar && Strcmp(naturalvar, "0") == 0; + int nvar = GetFlag(n, "feature:naturalvar"); + + if (!explicitly_off && !nvar) { /* look for feature in the class */ SwigType *ty = Getattr(n, "type"); SwigType *fullty = SwigType_typedef_resolve_all(ty); @@ -490,13 +499,17 @@ int Language::use_naturalvar_mode(Node *n) const { Replaceall(tys, "class ", ""); } Node *typenode = Swig_symbol_clookup(tys, 0); - if (typenode) - nvar = GetFlag(typenode, "feature:naturalvar"); + if (typenode) { + naturalvar = Getattr(typenode, "feature:naturalvar"); + explicitly_off = naturalvar && Strcmp(naturalvar, "0") == 0; + nvar = nvar || GetFlag(typenode, "feature:naturalvar"); + } Delete(tys); } Delete(fullty); } - return nvar ? CWRAP_NATURAL_VAR : 0; + nvar = nvar || naturalvar_mode; + return explicitly_off ? 0 : nvar ? CWRAP_NATURAL_VAR : 0; } /* ---------------------------------------------------------------------- From 07ce3fb746ee49e4f2ba5ff48449daa369433550 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 11 Jan 2014 13:15:44 +0000 Subject: [PATCH 0863/1160] Add testcase for %attributestring on shared_ptr --- Examples/test-suite/common.mk | 1 + .../li_boost_shared_ptr_attribute_runme.java | 38 +++++++++++++++ .../li_boost_shared_ptr_attribute.i | 46 +++++++++++++++++++ Lib/typemaps/attribute.swg | 5 +- 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/java/li_boost_shared_ptr_attribute_runme.java create mode 100644 Examples/test-suite/li_boost_shared_ptr_attribute.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 86d688799..bf88b0035 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -245,6 +245,7 @@ CPP_TEST_CASES += \ li_boost_shared_ptr \ li_boost_shared_ptr_bits \ li_boost_shared_ptr_template \ + li_boost_shared_ptr_attribute \ li_carrays \ li_cdata \ li_cpointer \ diff --git a/Examples/test-suite/java/li_boost_shared_ptr_attribute_runme.java b/Examples/test-suite/java/li_boost_shared_ptr_attribute_runme.java new file mode 100644 index 000000000..afc23eff0 --- /dev/null +++ b/Examples/test-suite/java/li_boost_shared_ptr_attribute_runme.java @@ -0,0 +1,38 @@ +import li_boost_shared_ptr_attribute.*; + +public class li_boost_shared_ptr_attribute_runme { + static { + try { + System.loadLibrary("li_boost_shared_ptr_attribute"); + } 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 check(GetSetMe g, int expected) { + int got = g.getN(); + if (got != expected) + throw new RuntimeException("GetSetMe value is " + got + " but should be " + expected); + } + + public static void check(GetMe g, int expected) { + int got = g.getN(); + if (got != expected) + throw new RuntimeException("GetMe value is " + got + " but should be " + expected); + } + + public static void main(String argv[]) + { + GetterSetter gs = new GetterSetter(5); + check(gs.getMyval(), 25); + check(gs.getAddedAttrib(), 25); + gs.setAddedAttrib(new GetSetMe(6)); + check(gs.getMyval(), 6); + check(gs.getAddedAttrib(), 6); + + GetterOnly g = new GetterOnly(4); + check(g.getMyval(), 16); + check(g.getAddedAttrib(), 16); + } +} diff --git a/Examples/test-suite/li_boost_shared_ptr_attribute.i b/Examples/test-suite/li_boost_shared_ptr_attribute.i new file mode 100644 index 000000000..c4d3dca36 --- /dev/null +++ b/Examples/test-suite/li_boost_shared_ptr_attribute.i @@ -0,0 +1,46 @@ +%module li_boost_shared_ptr_attribute + +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) +#define SHARED_PTR_WRAPPERS_IMPLEMENTED +#endif + +#if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED) + +%include "attribute.i" +%include "boost_shared_ptr.i" + +%inline %{ +#include +using namespace boost; +%} +%shared_ptr(GetMe); +%shared_ptr(GetSetMe); +%attributestring(GetterOnly, shared_ptr, AddedAttrib, GetIt) +%attributestring(GetterSetter, shared_ptr, AddedAttrib, GetIt, SetIt) + +%inline %{ +struct GetMe { + explicit GetMe(int n) : n(n) {} + ~GetMe() {} + int n; +}; +struct GetSetMe { + explicit GetSetMe(int n) : n(n) {} + ~GetSetMe() {} + int n; +}; + +struct GetterOnly { + explicit GetterOnly(int n) : myval(new GetMe(n*n)) {} + shared_ptr GetIt() const { return myval; } + shared_ptr myval; +}; +struct GetterSetter { + explicit GetterSetter(int n) : myval(new GetSetMe(n*n)) {} + shared_ptr GetIt() const { return myval; } + void SetIt(shared_ptr newval) { myval = newval; } + shared_ptr myval; +}; +%} + +#endif diff --git a/Lib/typemaps/attribute.swg b/Lib/typemaps/attribute.swg index 46fc80fd2..f06c8c0f3 100644 --- a/Lib/typemaps/attribute.swg +++ b/Lib/typemaps/attribute.swg @@ -130,6 +130,9 @@ }; %} + The %attributestring also works for class types that have %naturalvar turned + on and so is also useful for shared_ptr which has %naturalvar turned on in %shared_ptr. + */ // @@ -275,7 +278,7 @@ %ignore Class::GetMethod(); %ignore Class::GetMethod() const; %newobject Class::AttributeName; - %typemap(newfree) const AttributeType &AttributeName "delete $1;// my newfree override" + %typemap(newfree) const AttributeType &AttributeName "delete $1;" %extend Class { AttributeType AttributeName; } From 5c6bc5db3e461535c3ca01cbef7422affd06d777 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 11 Jan 2014 17:27:22 +0000 Subject: [PATCH 0864/1160] Remove -nonaturalvar and nonaturalvar option in %module These didn't work, were not documented and don't seem necessary --- Source/Modules/lang.cxx | 3 --- Source/Modules/main.cxx | 3 --- 2 files changed, 6 deletions(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 8b8382712..a547e2bd4 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -524,9 +524,6 @@ int Language::top(Node *n) { if (Getattr(options, "naturalvar")) { naturalvar_mode = 1; } - if (Getattr(options, "nonaturalvar")) { - naturalvar_mode = 0; - } } } classhash = Getattr(n, "classes"); diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index f3aff2349..786763441 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -502,9 +502,6 @@ void SWIG_getoptions(int argc, char *argv[]) { } else if (strcmp(argv[i], "-naturalvar") == 0) { Wrapper_naturalvar_mode_set(1); Swig_mark_arg(i); - } else if (strcmp(argv[i], "-nonaturalvar") == 0) { - Wrapper_naturalvar_mode_set(0); - Swig_mark_arg(i); } else if (strcmp(argv[i], "-directors") == 0) { SWIG_setfeature("feature:director", "1"); Wrapper_director_mode_set(1); From c319ad9dd6e392833e571ae134def827cb8abc1f Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Mon, 3 Jun 2013 15:41:54 +0200 Subject: [PATCH 0865/1160] Resolve prefix when resolving typedef --- Source/Swig/typesys.c | 101 ++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 43 deletions(-) diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index bcfd2feb5..e11fc781a 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -602,7 +602,7 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) { Typetab *s; Hash *ttab; String *namebase = 0; - String *nameprefix = 0; + String *nameprefix = 0, *rnameprefix = 0; int newtype = 0; resolved_scope = 0; @@ -647,51 +647,66 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) { Printf(stdout, "nameprefix = '%s'\n", nameprefix); #endif if (nameprefix) { - /* Name had a prefix on it. See if we can locate the proper scope for it */ - String *rnameprefix = template_parameters_resolve(nameprefix); - nameprefix = rnameprefix ? Copy(rnameprefix) : nameprefix; - Delete(rnameprefix); - s = SwigType_find_scope(s, nameprefix); - - /* Couldn't locate a scope for the type. */ - if (!s) { - Delete(base); - Delete(namebase); - Delete(nameprefix); - r = 0; - goto return_result; - } - /* Try to locate the name starting in the scope */ + rnameprefix = SwigType_typedef_resolve(nameprefix); + if(rnameprefix != NULL) { #ifdef SWIG_DEBUG - Printf(stdout, "namebase = '%s'\n", namebase); + Printf(stdout, "nameprefix '%s' is a typedef to '%s'\n", nameprefix, rnameprefix); #endif - type = typedef_resolve(s, namebase); - if (type && resolved_scope) { - /* we need to look for the resolved type, this will also - fix the resolved_scope if 'type' and 'namebase' are - declared in different scopes */ - String *rtype = 0; - rtype = typedef_resolve(resolved_scope, type); - if (rtype) - type = rtype; - } -#ifdef SWIG_DEBUG - Printf(stdout, "%s type = '%s'\n", Getattr(s, "name"), type); -#endif - if (type && (!Swig_scopename_check(type)) && resolved_scope) { - Typetab *rtab = resolved_scope; - String *qname = Getattr(resolved_scope, "qname"); - /* If qualified *and* the typename is defined from the resolved scope, we qualify */ - if ((qname) && typedef_resolve(resolved_scope, type)) { - type = Copy(type); - Insert(type, 0, "::"); - Insert(type, 0, qname); -#ifdef SWIG_DEBUG - Printf(stdout, "qual %s \n", type); -#endif - newtype = 1; + type = Copy(namebase); + Insert(type, 0, "::"); + Insert(type, 0, rnameprefix); + if (strncmp(Char(type), "::", 2) == 0) { + Delitem(type, 0); + Delitem(type, 0); + } + newtype = 1; + } else { + /* Name had a prefix on it. See if we can locate the proper scope for it */ + String *rnameprefix = template_parameters_resolve(nameprefix); + nameprefix = rnameprefix ? Copy(rnameprefix) : nameprefix; + Delete(rnameprefix); + s = SwigType_find_scope(s, nameprefix); + + /* Couldn't locate a scope for the type. */ + if (!s) { + Delete(base); + Delete(namebase); + Delete(nameprefix); + r = 0; + goto return_result; + } + /* Try to locate the name starting in the scope */ +#ifdef SWIG_DEBUG + Printf(stdout, "namebase = '%s'\n", namebase); +#endif + type = typedef_resolve(s, namebase); + if (type && resolved_scope) { + /* we need to look for the resolved type, this will also + fix the resolved_scope if 'type' and 'namebase' are + declared in different scopes */ + String *rtype = 0; + rtype = typedef_resolve(resolved_scope, type); + if (rtype) + type = rtype; + } +#ifdef SWIG_DEBUG + Printf(stdout, "%s type = '%s'\n", Getattr(s, "name"), type); +#endif + if ((type) && (!Swig_scopename_check(type)) && resolved_scope) { + Typetab *rtab = resolved_scope; + String *qname = Getattr(resolved_scope, "qname"); + /* If qualified *and* the typename is defined from the resolved scope, we qualify */ + if ((qname) && typedef_resolve(resolved_scope, type)) { + type = Copy(type); + Insert(type, 0, "::"); + Insert(type, 0, qname); +#ifdef SWIG_DEBUG + Printf(stdout, "qual %s \n", type); +#endif + newtype = 1; + } + resolved_scope = rtab; } - resolved_scope = rtab; } } else { /* Name is unqualified. */ From 5b167cc12daf9ea275c17fedaefc975450613ab2 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 13 Jan 2014 18:24:17 +1300 Subject: [PATCH 0866/1160] octave: update support to Octave version 3.8.0 --- CHANGES.current | 26 ++++++++++ Doc/Manual/Octave.html | 7 +-- Lib/octave/octrun.swg | 102 ++++++++++++++++++++++++++++++++------ Lib/octave/octruntime.swg | 14 +++--- 4 files changed, 121 insertions(+), 28 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index a4fc5dbf4..c711536ce 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,32 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-01-13: kwwette + [Octave] update support to Octave version 3.8.0 + + - Octave 3.8.0 no longer defines OCTAVE_API_VERSION_NUMBER, but 3.8.1 + will define OCTAVE_{MAJOR,MINOR,PATCH}_VERSION instead: see + http://hg.savannah.gnu.org/hgweb/octave/rev/b6b6e0dc700e + So we now use a new macro SWIG_OCTAVE_PREREQ(major,minor,patch) to + enable features requiring Octave version major.minor.patch or later. + + For Octave versions prior to 3.8.1, we reconstruct values for + OCTAVE_{MAJOR,MINOR,PATCH}_VERSION based on OCTAVE_API_VERSION_NUMBER, + extracted from Octave's ChangeLogs. An additional hack is needed to + distinguish between Octave <= 3.2.x and 3.8.0, neither of which define + OCTAVE_API_VERSION_NUMBER. + + - Octave 3.8.0 deprecates symbol_table::varref(), so remove its use + for this and future versions of Octave. + + - Octave 3.8.0 removes octave_value::is_real_nd_array(), used in + octave_swig_type::dims(). Its use is not required here, so remove it. + + - Retested against Octave versions 3.0.5, 3.2.4, 3.4.3, 3.6.4, and 3.8.0. + + - Updated Octave documentation with tested Octave versions, and added a + warning against using versions <= 3.x.x, which are no longer tested. + 2014-01-11: wsfulton Fix and document the naturalvar feature override behaviour - the naturalvar feature attached to a variable name has precedence over the naturalvar diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 84c0a0f46..3e12ce668 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -59,11 +59,8 @@ Also, there are a dozen or so examples in the Examples/octave directory, and hun

    -The SWIG implemention was first based on Octave 2.9.12, so this is the minimum version required. Testing has only been done on Linux. -

    - -

    -As of SWIG 2.0.7, the Octave module has been tested with Octave versions 3.0.5, 3.2.4, 3.4.3, and 3.6.1. +As of SWIG 3.0.0, the Octave module has been tested with Octave versions 3.0.5, 3.2.4, 3.4.3, 3.6.4, and 3.8.0. +Use of Octave versions older than 3.x.x is not recommended, as these versions are no longer tested with SWIG.

    30.2 Running SWIG

    diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 41d1c7afa..2174a0f7f 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -1,20 +1,88 @@ #include -#ifndef OCTAVE_API_VERSION_NUMBER - // Hack to distinguish between Octave 3.2 and earlier versions before OCTAVE_API_VERSION_NUMBER existed - #define ComplexLU __ignore - #include - #undef ComplexLU - #ifdef octave_Complex_LU_h - # define OCTAVE_API_VERSION_NUMBER 36 - #else - # define OCTAVE_API_VERSION_NUMBER 37 - #endif +// Macro for enabling features which require Octave version >= major.minor.patch +#define SWIG_OCTAVE_PREREQ(major, minor, patch) \ + ( (OCTAVE_MAJOR_VERSION<<16) + (OCTAVE_MINOR_VERSION<<8) + OCTAVE_PATCH_VERSION >= ((major)<<16) + ((minor)<<8) + (patch) ) -#endif +// Reconstruct Octave major, minor, and patch versions for releases prior to 3.8.1 +#if !defined(OCTAVE_MAJOR_VERSION) -#if OCTAVE_API_VERSION_NUMBER < 37 +# if !defined(OCTAVE_API_VERSION_NUMBER) + +// Hack to distinguish between Octave 3.8.0, which removed OCTAVE_API_VERSION_NUMBER but did not yet +// introduce OCTAVE_MAJOR_VERSION, and Octave <= 3.2, which did not define OCTAVE_API_VERSION_NUMBER +# include +# if defined(octave_ov_h) +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 8 +# define OCTAVE_PATCH_VERSION 0 +# else + +// Hack to distinguish between Octave 3.2 and earlier versions, before OCTAVE_API_VERSION_NUMBER existed +# define ComplexLU __ignore +# include +# undef ComplexLU +# if defined(octave_Complex_LU_h) + +// We know only that this version is prior to Octave 3.2, i.e. OCTAVE_API_VERSION_NUMBER < 37 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 1 +# define OCTAVE_PATCH_VERSION 99 + +# else + +// OCTAVE_API_VERSION_NUMBER == 37 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 2 +# define OCTAVE_PATCH_VERSION 0 + +# endif // defined(octave_Complex_LU_h) + +# endif // defined(octave_ov_h) + +// Correlation between Octave API and version numbers extracted from Octave's +// ChangeLogs; version is the *earliest* released Octave with that API number +# elif OCTAVE_API_VERSION_NUMBER >= 48 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 6 +# define OCTAVE_PATCH_VERSION 0 + +# elif OCTAVE_API_VERSION_NUMBER >= 45 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 4 +# define OCTAVE_PATCH_VERSION 1 + +# elif OCTAVE_API_VERSION_NUMBER >= 42 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 54 + +# elif OCTAVE_API_VERSION_NUMBER >= 41 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 53 + +# elif OCTAVE_API_VERSION_NUMBER >= 40 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 52 + +# elif OCTAVE_API_VERSION_NUMBER >= 39 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 51 + +# else // OCTAVE_API_VERSION_NUMBER == 38 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 50 + +# endif // !defined(OCTAVE_API_VERSION_NUMBER) + +#endif // !defined(OCTAVE_MAJOR_VERSION) + +#if !SWIG_OCTAVE_PREREQ(3,2,0) #define SWIG_DEFUN(cname, wname, doc) DEFUNX_DLD(#cname, wname, FS ## cname, args, nargout, doc) #else #define SWIG_DEFUN(cname, wname, doc) DEFUNX_DLD(#cname, wname, G ## cname, args, nargout, doc) @@ -427,7 +495,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); if (error_state) return dim_vector(1,1); } return d; - } else if (out.is_matrix_type() || out.is_real_nd_array() || out.is_numeric_type() ) { + } else if (out.is_matrix_type() || out.is_numeric_type() ) { if (out.rows()==1 || out.columns()==1) { Array a = out.int_vector_value(); if (error_state) return dim_vector(1,1); @@ -746,7 +814,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); return outarg(0).string_value(); } -#if OCTAVE_API_VERSION_NUMBER >= 40 +#if SWIG_OCTAVE_PREREQ(3,3,52) virtual octave_map map_value() const { return octave_map(); } @@ -982,7 +1050,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); virtual std::string string_value(bool force = false) const { return ptr->string_value(force); } -#if OCTAVE_API_VERSION_NUMBER >= 40 +#if SWIG_OCTAVE_PREREQ(3,3,52) virtual octave_map map_value() const { return ptr->map_value(); } #else @@ -1293,10 +1361,12 @@ SWIGRUNTIME void SWIG_Octave_SetGlobalValue(std::string name, const octave_value } SWIGRUNTIME void SWIG_Octave_LinkGlobalValue(std::string name) { -#if OCTAVE_API_VERSION_NUMBER < 37 +#if !SWIG_OCTAVE_PREREQ(3,2,0) link_to_global_variable(curr_sym_tab->lookup(name, true)); #else +#if !SWIG_OCTAVE_PREREQ(3,8,0) symbol_table::varref(name); +#endif symbol_table::mark_global(name); #endif } diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index 43313c3d4..fbf2007f6 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -25,7 +25,7 @@ static bool SWIG_init_user(octave_swig_type* module_ns); SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) { bool retn; { -#if OCTAVE_API_VERSION_NUMBER < 38 +#if !SWIG_OCTAVE_PREREQ(3,3,50) unwind_protect::begin_frame("SWIG_Octave_LoadModule"); unwind_protect_int(error_state); unwind_protect_int(warning_state); @@ -44,7 +44,7 @@ SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) { discard_warning_messages = true; feval(name, octave_value_list(), 0); retn = (error_state == 0); -#if OCTAVE_API_VERSION_NUMBER < 38 +#if !SWIG_OCTAVE_PREREQ(3,3,50) unwind_protect::run_frame("SWIG_Octave_LoadModule"); #endif } @@ -57,7 +57,7 @@ SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) { SWIGINTERN bool SWIG_Octave_InstallFunction(octave_function *octloadfcn, std::string name) { bool retn; { -#if OCTAVE_API_VERSION_NUMBER < 38 +#if !SWIG_OCTAVE_PREREQ(3,3,50) unwind_protect::begin_frame("SWIG_Octave_InstallFunction"); unwind_protect_int(error_state); unwind_protect_int(warning_state); @@ -80,7 +80,7 @@ SWIGINTERN bool SWIG_Octave_InstallFunction(octave_function *octloadfcn, std::st error_state = 0; feval("autoload", args, 0); retn = (error_state == 0); -#if OCTAVE_API_VERSION_NUMBER < 38 +#if !SWIG_OCTAVE_PREREQ(3,3,50) unwind_protect::run_frame("SWIG_Octave_InstallFunction"); #endif } @@ -196,7 +196,7 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { // definitely affects version 3.2.*, not sure about 3.3.*, seems to be fixed in // version 3.4.* and above. can be turned off with macro definition. #ifndef SWIG_OCTAVE_NO_SEGFAULT_HACK -#if 36 < OCTAVE_API_VERSION_NUMBER && OCTAVE_API_VERSION_NUMBER < 45 +#if SWIG_OCTAVE_PREREQ(3,2,0) && !SWIG_OCTAVE_PREREQ(3,4,1) octave_exit = ::_Exit; #endif #endif @@ -212,7 +212,7 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { // workaround bug in octave where installing global variable of custom type and then // exiting without explicitly clearing the variable causes octave to segfault. -#if OCTAVE_API_VERSION_NUMBER > 36 +#if SWIG_OCTAVE_PREREQ(3,2,0) octave_value_list eval_args; eval_args.append("base"); eval_args.append("function __swig_atexit__; " @@ -297,7 +297,7 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { } } -#if OCTAVE_API_VERSION_NUMBER < 37 +#if !SWIG_OCTAVE_PREREQ(3,2,0) mlock(me->name()); #else mlock(); From 2f47bb8d6756f9f4d440d1bcc0a639ed8169c0ab Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 13 Jan 2014 19:46:48 +0000 Subject: [PATCH 0867/1160] Typedef typedef prefix test for templates As given in Diorcet Yann's example in issue #50 --- Examples/test-suite/common.mk | 1 + .../java/template_typedef_typedef_runme.java | 26 +++++++++++ .../test-suite/template_typedef_typedef.i | 43 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 Examples/test-suite/java/template_typedef_typedef_runme.java create mode 100644 Examples/test-suite/template_typedef_typedef.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index bf88b0035..fa46b9ff7 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -424,6 +424,7 @@ CPP_TEST_CASES += \ template_typedef_ns \ template_typedef_ptr \ template_typedef_rec \ + template_typedef_typedef \ template_typemaps \ template_typemaps_typedef \ template_typemaps_typedef2 \ diff --git a/Examples/test-suite/java/template_typedef_typedef_runme.java b/Examples/test-suite/java/template_typedef_typedef_runme.java new file mode 100644 index 000000000..f5f368561 --- /dev/null +++ b/Examples/test-suite/java/template_typedef_typedef_runme.java @@ -0,0 +1,26 @@ +import template_typedef_typedef.*; + +public class template_typedef_typedef_runme { + + static { + try { + System.loadLibrary("template_typedef_typedef"); + } 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[]) { + ObjectBase ob1 = new ObjectBase(); + ob1.getBlabla1(new ObjectBase()); + Object2Base ob2 = new Object2Base(); + ob2.getBlabla2(new Object2Base()); + + Factory factory = new Factory(); + factory.getBlabla3(new ObjectBase()); + factory.getBlabla4(new Object2Base()); + } +} + + diff --git a/Examples/test-suite/template_typedef_typedef.i b/Examples/test-suite/template_typedef_typedef.i new file mode 100644 index 000000000..30077c484 --- /dev/null +++ b/Examples/test-suite/template_typedef_typedef.i @@ -0,0 +1,43 @@ +%module template_typedef_typedef + +// Github issue #50 +// The Object2::getBlabla2 and Object::getBlabla1 functions were not resolving to the correct template types + +%inline%{ + +class Factory; +class Base { +public: + typedef Factory ABCD; + +}; + +namespace TT{ + template + class Object2:public T { + public: + void getBlabla2(typename T::ABCD::CC2 c) { + }; + }; + template + class Object:public T { + public: + void getBlabla1(typename T::ABCD::CC1 c) { + }; + }; +} + +class Factory { + public: + typedef TT::Object CC1; + typedef TT::Object2 CC2; + void getBlabla4(CC2 c) { + }; + void getBlabla3(CC1 c) { + }; +}; +%} + +%template(ObjectBase) TT::Object; +%template(Object2Base) TT::Object2; + From 2e186244d6ebf1867b4051519c2a5cae6fdd4433 Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Fri, 19 Jul 2013 16:23:06 +0200 Subject: [PATCH 0868/1160] Add test for checking prefix resolving in typedef --- Examples/test-suite/common.mk | 1 + .../python/typedef_typedef_runme.py | 5 +++ Examples/test-suite/typedef_typedef.i | 39 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 Examples/test-suite/python/typedef_typedef_runme.py create mode 100644 Examples/test-suite/typedef_typedef.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index fa46b9ff7..6d1d2a25b 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -443,6 +443,7 @@ CPP_TEST_CASES += \ typedef_scope \ typedef_sizet \ typedef_struct \ + typedef_typedef \ typemap_arrays \ typemap_array_qualifiers \ typemap_delete \ diff --git a/Examples/test-suite/python/typedef_typedef_runme.py b/Examples/test-suite/python/typedef_typedef_runme.py new file mode 100644 index 000000000..ac61dd163 --- /dev/null +++ b/Examples/test-suite/python/typedef_typedef_runme.py @@ -0,0 +1,5 @@ +import typedef_typedef + +b = typedef_typedef.B() +if b.getValue() == 0: + print "Failed !!!" diff --git a/Examples/test-suite/typedef_typedef.i b/Examples/test-suite/typedef_typedef.i new file mode 100644 index 000000000..bb309cb20 --- /dev/null +++ b/Examples/test-suite/typedef_typedef.i @@ -0,0 +1,39 @@ +%module typedef_typedef + +/* + + We want a specific behaviour on a Type + +*/ + +%typemap(out) A::Foo { + $result = PyInt_FromLong($1 + 1); +} + +%inline %{ + struct A + { + typedef int Foo; + }; + + struct C + { + typedef A Bar; + }; + + struct B + { + C::Bar::Foo getValue() { + return 0; + } + }; +%} + +/* + + An issue can be the steps resolution. + 1) C::Bar is A. So C::Bar::Foo should be first resolved as A::Foo. + 2) Then A::Foo should be resolved int. + If the first step is skipped the typemap is not applied. + +*/ From e531578c540c951dd4b4f9ca7e002acdf83148d9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 13 Jan 2014 18:42:04 +0000 Subject: [PATCH 0869/1160] Modify typedef_typedef testcase to work for all languages Add CHANGES note Closes #112. --- CHANGES.current | 4 ++++ .../test-suite/python/typedef_typedef_runme.py | 2 +- Examples/test-suite/typedef_typedef.i | 14 ++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index a4fc5dbf4..be3a32a6f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-01-14: diorcety + Patch #112 - Fix symbol resolution involving scopes that have multiple levels + of typedefs - fixes some template resolutions as well as some typemap searches. + 2014-01-11: wsfulton Fix and document the naturalvar feature override behaviour - the naturalvar feature attached to a variable name has precedence over the naturalvar diff --git a/Examples/test-suite/python/typedef_typedef_runme.py b/Examples/test-suite/python/typedef_typedef_runme.py index ac61dd163..51a823def 100644 --- a/Examples/test-suite/python/typedef_typedef_runme.py +++ b/Examples/test-suite/python/typedef_typedef_runme.py @@ -1,5 +1,5 @@ import typedef_typedef b = typedef_typedef.B() -if b.getValue() == 0: +if b.getValue(123) == 1234: print "Failed !!!" diff --git a/Examples/test-suite/typedef_typedef.i b/Examples/test-suite/typedef_typedef.i index bb309cb20..9bfa14a23 100644 --- a/Examples/test-suite/typedef_typedef.i +++ b/Examples/test-suite/typedef_typedef.i @@ -1,13 +1,11 @@ %module typedef_typedef -/* +// Check C::Bar::Foo resolves to A::Foo in typemap search - We want a specific behaviour on a Type +%typemap(in) SWIGTYPE, int "__wrong_in_typemap__will_not_compile__" -*/ - -%typemap(out) A::Foo { - $result = PyInt_FromLong($1 + 1); +%typemap(in) A::Foo { + $1 = 1234; /* A::Foo in typemap */ } %inline %{ @@ -23,8 +21,8 @@ struct B { - C::Bar::Foo getValue() { - return 0; + C::Bar::Foo getValue(C::Bar::Foo intvalue) { + return intvalue; } }; %} From f068be89e50bc35d8a7684c04cc64ac4dd96695c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 16 Jan 2014 06:42:34 +0000 Subject: [PATCH 0870/1160] Fix PHP compilation error in ZTS mode (64 bit windows) due to TSRMLS_FETCH() expansion --- CHANGES.current | 4 ++++ Lib/php/phprun.swg | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 5aa45704f..5dd602f35 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-01-16: wsfulton + [PHP] Fix compilation error in ZTS mode (64 bit windows) due to incorrect placement + of TSRMLS_FETCH() in SWIG_Php_GetModule() as reported by Mark Dawson-Butterworth. + 2014-01-14: diorcety Patch #112 - Fix symbol resolution involving scopes that have multiple levels of typedefs - fixes some template resolutions as well as some typemap searches. diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index a4188cc7c..063b84227 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -255,11 +255,10 @@ static char const_name[] = "swig_runtime_data_type_pointer"; static swig_module_info *SWIG_Php_GetModule(void *SWIGUNUSEDPARM(clientdata)) { zval *pointer; swig_module_info *ret = 0; + TSRMLS_FETCH(); MAKE_STD_ZVAL(pointer); - TSRMLS_FETCH(); - if (zend_get_constant(const_name, sizeof(const_name) - 1, pointer TSRMLS_CC)) { if (pointer->type == IS_LONG) { ret = (swig_module_info *) pointer->value.lval; From 9d003ab362a0501c3130583d0f6dcfac21e1a623 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 16 Jan 2014 19:30:48 +0000 Subject: [PATCH 0871/1160] Update errors expected results --- Examples/test-suite/errors/expected.log | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log index 5fb0e715f..da0d59778 100644 --- a/Examples/test-suite/errors/expected.log +++ b/Examples/test-suite/errors/expected.log @@ -323,6 +323,7 @@ cpp_namespace_aliasundef.i:3: Error: Unknown namespace 'blah' :::::::::::::::::::::::::::::::: cpp_nested_template.i ::::::::::::::::::::::::::::::::::: cpp_nested_template.i:9: Warning 324: Named nested template instantiations not supported. Processing as if no name was given to %template(). +cpp_nested_template.i:18: Warning 324: Named nested template instantiations not supported. Processing as if no name was given to %template(). :::::::::::::::::::::::::::::::: cpp_no_access.i ::::::::::::::::::::::::::::::::::: cpp_no_access.i:3: Warning 319: No access specifier given for base class 'foo' (ignored). From 3055a21505b6258fb9e6fc64dae16f99aa1cfff4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 18 Jan 2014 21:35:35 +0000 Subject: [PATCH 0872/1160] Errors test-suite overhaul Use makefiles instead of a make.sh script Expected results are in individual .stderr files instead of the expected.log file Add errors test-suite to Travis testing and 'make check' --- .travis.yml | 3 +- Doc/Manual/Extending.html | 6 + Examples/test-suite/common.mk | 17 +- Examples/test-suite/errors/Makefile.in | 51 +++ Examples/test-suite/errors/c_bad_name.stderr | 2 + .../test-suite/errors/c_bad_native.stderr | 1 + Examples/test-suite/errors/c_class.stderr | 2 + .../test-suite/errors/c_default_error.stderr | 0 .../test-suite/errors/c_deprecated.stderr | 2 + .../test-suite/errors/c_empty_char.stderr | 1 + .../test-suite/errors/c_enum_badvalue.stderr | 1 + .../test-suite/errors/c_extra_rblock.stderr | 1 + .../test-suite/errors/c_extra_rbrace.stderr | 1 + .../test-suite/errors/c_extra_unsigned.stderr | 3 + .../test-suite/errors/c_insert_missing.stderr | 1 + .../test-suite/errors/c_long_short.stderr | 4 + .../test-suite/errors/c_missing_rbrace.stderr | 2 + .../test-suite/errors/c_missing_semi.stderr | 1 + Examples/test-suite/errors/c_redefine.stderr | 6 + Examples/test-suite/errors/c_varargs.stderr | 0 .../test-suite/errors/c_varargs_neg.stderr | 1 + .../test-suite/errors/cpp_bad_extern.stderr | 2 + .../errors/cpp_extend_destructors.stderr | 19 + .../errors/cpp_extend_redefine.stderr | 4 + .../errors/cpp_extend_undefined.stderr | 1 + Examples/test-suite/errors/cpp_inherit.stderr | 20 + .../errors/cpp_inline_namespace.stderr | 1 + .../errors/cpp_macro_locator.stderr | 20 + .../errors/cpp_missing_rparenthesis.stderr | 2 + .../errors/cpp_missing_rtemplate.stderr | 1 + .../errors/cpp_namespace_alias.stderr | 1 + .../errors/cpp_namespace_aliasnot.stderr | 1 + .../errors/cpp_namespace_aliasundef.stderr | 1 + .../errors/cpp_nested_template.stderr | 2 + .../test-suite/errors/cpp_no_access.stderr | 1 + .../errors/cpp_no_return_type.stderr | 2 + Examples/test-suite/errors/cpp_nobase.stderr | 3 + .../test-suite/errors/cpp_overload.stderr | 0 .../errors/cpp_overload_const.stderr | 10 + .../errors/cpp_private_defvalue.stderr | 0 .../errors/cpp_private_inherit.stderr | 2 + .../errors/cpp_recursive_typedef.stderr | 1 + .../test-suite/errors/cpp_shared_ptr.stderr | 3 + .../errors/cpp_template_argname.stderr | 0 .../errors/cpp_template_nargs.stderr | 2 + .../test-suite/errors/cpp_template_not.stderr | 1 + .../errors/cpp_template_partial.stderr | 1 + .../errors/cpp_template_repeat.stderr | 0 .../errors/cpp_template_undef.stderr | 1 + .../test-suite/errors/cpp_using_not.stderr | 1 + .../test-suite/errors/cpp_using_undef.stderr | 2 + Examples/test-suite/errors/expected.log | 390 ------------------ Examples/test-suite/errors/make.sh | 124 ------ Examples/test-suite/errors/nomodule.stderr | 1 + Examples/test-suite/errors/pp_badeval.stderr | 2 + Examples/test-suite/errors/pp_constant.stderr | 8 + Examples/test-suite/errors/pp_defined.stderr | 2 + .../test-suite/errors/pp_deprecated.stderr | 4 + .../errors/pp_illegal_argument.stderr | 3 + .../test-suite/errors/pp_macro_args.stderr | 0 .../test-suite/errors/pp_macro_badchar.stderr | 1 + .../pp_macro_defined_unterminated.stderr | 1 + .../errors/pp_macro_expansion.stderr | 1 + .../pp_macro_expansion_multiline.stderr | 4 + .../pp_macro_inline_unterminated.stderr | 2 + .../errors/pp_macro_missing_expression.stderr | 5 + .../test-suite/errors/pp_macro_nargs.stderr | 4 + .../test-suite/errors/pp_macro_redef.stderr | 4 + .../test-suite/errors/pp_macro_rparen.stderr | 1 + .../errors/pp_macro_unexpected_tokens.stderr | 5 + .../errors/pp_macro_unterminated.stderr | 1 + .../errors/pp_misplaced_elif.stderr | 2 + .../errors/pp_misplaced_else.stderr | 2 + .../errors/pp_missing_enddef.stderr | 1 + .../test-suite/errors/pp_missing_endif.stderr | 1 + .../test-suite/errors/pp_missing_file.stderr | 1 + .../errors/pp_missing_rblock.stderr | 1 + Examples/test-suite/errors/pp_pragma.stderr | 1 + .../test-suite/errors/pp_unterm_char.stderr | 1 + .../errors/pp_unterm_comment.stderr | 1 + .../test-suite/errors/pp_unterm_string.stderr | 1 + .../test-suite/errors/pp_variable_args.stderr | 1 + .../test-suite/errors/swig_apply_nargs.stderr | 1 + Examples/test-suite/errors/swig_extend.stderr | 8 + .../test-suite/errors/swig_identifier.stderr | 1 + .../test-suite/errors/swig_insert_bad.stderr | 1 + .../errors/swig_typemap_copy.stderr | 1 + .../test-suite/errors/swig_typemap_old.stderr | 6 + .../errors/swig_typemap_warn.stderr | 7 + Makefile.in | 4 + configure.ac | 1 + 91 files changed, 298 insertions(+), 519 deletions(-) create mode 100644 Examples/test-suite/errors/Makefile.in create mode 100644 Examples/test-suite/errors/c_bad_name.stderr create mode 100644 Examples/test-suite/errors/c_bad_native.stderr create mode 100644 Examples/test-suite/errors/c_class.stderr create mode 100644 Examples/test-suite/errors/c_default_error.stderr create mode 100644 Examples/test-suite/errors/c_deprecated.stderr create mode 100644 Examples/test-suite/errors/c_empty_char.stderr create mode 100644 Examples/test-suite/errors/c_enum_badvalue.stderr create mode 100644 Examples/test-suite/errors/c_extra_rblock.stderr create mode 100644 Examples/test-suite/errors/c_extra_rbrace.stderr create mode 100644 Examples/test-suite/errors/c_extra_unsigned.stderr create mode 100644 Examples/test-suite/errors/c_insert_missing.stderr create mode 100644 Examples/test-suite/errors/c_long_short.stderr create mode 100644 Examples/test-suite/errors/c_missing_rbrace.stderr create mode 100644 Examples/test-suite/errors/c_missing_semi.stderr create mode 100644 Examples/test-suite/errors/c_redefine.stderr create mode 100644 Examples/test-suite/errors/c_varargs.stderr create mode 100644 Examples/test-suite/errors/c_varargs_neg.stderr create mode 100644 Examples/test-suite/errors/cpp_bad_extern.stderr create mode 100644 Examples/test-suite/errors/cpp_extend_destructors.stderr create mode 100644 Examples/test-suite/errors/cpp_extend_redefine.stderr create mode 100644 Examples/test-suite/errors/cpp_extend_undefined.stderr create mode 100644 Examples/test-suite/errors/cpp_inherit.stderr create mode 100644 Examples/test-suite/errors/cpp_inline_namespace.stderr create mode 100644 Examples/test-suite/errors/cpp_macro_locator.stderr create mode 100644 Examples/test-suite/errors/cpp_missing_rparenthesis.stderr create mode 100644 Examples/test-suite/errors/cpp_missing_rtemplate.stderr create mode 100644 Examples/test-suite/errors/cpp_namespace_alias.stderr create mode 100644 Examples/test-suite/errors/cpp_namespace_aliasnot.stderr create mode 100644 Examples/test-suite/errors/cpp_namespace_aliasundef.stderr create mode 100644 Examples/test-suite/errors/cpp_nested_template.stderr create mode 100644 Examples/test-suite/errors/cpp_no_access.stderr create mode 100644 Examples/test-suite/errors/cpp_no_return_type.stderr create mode 100644 Examples/test-suite/errors/cpp_nobase.stderr create mode 100644 Examples/test-suite/errors/cpp_overload.stderr create mode 100644 Examples/test-suite/errors/cpp_overload_const.stderr create mode 100644 Examples/test-suite/errors/cpp_private_defvalue.stderr create mode 100644 Examples/test-suite/errors/cpp_private_inherit.stderr create mode 100644 Examples/test-suite/errors/cpp_recursive_typedef.stderr create mode 100644 Examples/test-suite/errors/cpp_shared_ptr.stderr create mode 100644 Examples/test-suite/errors/cpp_template_argname.stderr create mode 100644 Examples/test-suite/errors/cpp_template_nargs.stderr create mode 100644 Examples/test-suite/errors/cpp_template_not.stderr create mode 100644 Examples/test-suite/errors/cpp_template_partial.stderr create mode 100644 Examples/test-suite/errors/cpp_template_repeat.stderr create mode 100644 Examples/test-suite/errors/cpp_template_undef.stderr create mode 100644 Examples/test-suite/errors/cpp_using_not.stderr create mode 100644 Examples/test-suite/errors/cpp_using_undef.stderr delete mode 100644 Examples/test-suite/errors/expected.log delete mode 100755 Examples/test-suite/errors/make.sh create mode 100644 Examples/test-suite/errors/nomodule.stderr create mode 100644 Examples/test-suite/errors/pp_badeval.stderr create mode 100644 Examples/test-suite/errors/pp_constant.stderr create mode 100644 Examples/test-suite/errors/pp_defined.stderr create mode 100644 Examples/test-suite/errors/pp_deprecated.stderr create mode 100644 Examples/test-suite/errors/pp_illegal_argument.stderr create mode 100644 Examples/test-suite/errors/pp_macro_args.stderr create mode 100644 Examples/test-suite/errors/pp_macro_badchar.stderr create mode 100644 Examples/test-suite/errors/pp_macro_defined_unterminated.stderr create mode 100644 Examples/test-suite/errors/pp_macro_expansion.stderr create mode 100644 Examples/test-suite/errors/pp_macro_expansion_multiline.stderr create mode 100644 Examples/test-suite/errors/pp_macro_inline_unterminated.stderr create mode 100644 Examples/test-suite/errors/pp_macro_missing_expression.stderr create mode 100644 Examples/test-suite/errors/pp_macro_nargs.stderr create mode 100644 Examples/test-suite/errors/pp_macro_redef.stderr create mode 100644 Examples/test-suite/errors/pp_macro_rparen.stderr create mode 100644 Examples/test-suite/errors/pp_macro_unexpected_tokens.stderr create mode 100644 Examples/test-suite/errors/pp_macro_unterminated.stderr create mode 100644 Examples/test-suite/errors/pp_misplaced_elif.stderr create mode 100644 Examples/test-suite/errors/pp_misplaced_else.stderr create mode 100644 Examples/test-suite/errors/pp_missing_enddef.stderr create mode 100644 Examples/test-suite/errors/pp_missing_endif.stderr create mode 100644 Examples/test-suite/errors/pp_missing_file.stderr create mode 100644 Examples/test-suite/errors/pp_missing_rblock.stderr create mode 100644 Examples/test-suite/errors/pp_pragma.stderr create mode 100644 Examples/test-suite/errors/pp_unterm_char.stderr create mode 100644 Examples/test-suite/errors/pp_unterm_comment.stderr create mode 100644 Examples/test-suite/errors/pp_unterm_string.stderr create mode 100644 Examples/test-suite/errors/pp_variable_args.stderr create mode 100644 Examples/test-suite/errors/swig_apply_nargs.stderr create mode 100644 Examples/test-suite/errors/swig_extend.stderr create mode 100644 Examples/test-suite/errors/swig_identifier.stderr create mode 100644 Examples/test-suite/errors/swig_insert_bad.stderr create mode 100644 Examples/test-suite/errors/swig_typemap_copy.stderr create mode 100644 Examples/test-suite/errors/swig_typemap_old.stderr create mode 100644 Examples/test-suite/errors/swig_typemap_warn.stderr diff --git a/.travis.yml b/.travis.yml index 70cbb2f27..ad771df9c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,8 +49,9 @@ before_install: script: - ./autogen.sh && ./configure - make -s $SWIGJOBS - - if test -z "$SWIGLANG"; then make -s check-ccache; fi - ./swig -version + - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-ccache; fi + - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-errors-test-suite; fi - if test -n "$SWIGLANG"; then make -s check-$SWIGLANG-version; fi - if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-examples; fi - if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-test-suite; fi diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index 5ea4e51f4..1fc65d0e1 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -3496,6 +3496,12 @@ The syntax for setting environment variables varies from one shell to the next, make ret_by_value.ctest SWIG_FEATURES="-debug-tmsearch"
    +

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

    +

    38.10.13 Documentation

    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 6d1d2a25b..dc18852f7 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -639,12 +639,21 @@ ALL_CLEAN = $(CPP_TEST_CASES:=.clean) \ $(CPP_TEST_BROKEN:=.clean) \ $(C_TEST_BROKEN:=.clean) +####################################################################### +# Error test suite has its own set of test cases +####################################################################### +ifneq (,$(ERROR_TEST_CASES)) +check: $(ERROR_TEST_CASES) +else + ####################################################################### # The following applies for all module languages ####################################################################### -all: $(NOT_BROKEN_TEST_CASES) $(BROKEN_TEST_CASES) +all: $(NOT_BROKEN_TEST_CASES) $(BROKEN_TEST_CASES) -check: $(NOT_BROKEN_TEST_CASES) +broken: $(BROKEN_TEST_CASES) + +check: $(NOT_BROKEN_TEST_CASES) check-c: $(C_TEST_CASES:=.ctest) @@ -652,12 +661,12 @@ check-cpp: $(CPP_TEST_CASES:=.cpptest) check-cpp11: $(CPP11_TEST_CASES:=.cpptest) +endif + # partialcheck target runs SWIG only, ie no compilation or running of tests (for a subset of languages) partialcheck: $(MAKE) check CC=true CXX=true LDSHARED=true CXXSHARED=true RUNTOOL=true COMPILETOOL=true -broken: $(BROKEN_TEST_CASES) - swig_and_compile_cpp = \ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile CXXSRCS="$(CXXSRCS)" \ SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \ diff --git a/Examples/test-suite/errors/Makefile.in b/Examples/test-suite/errors/Makefile.in new file mode 100644 index 000000000..cbfe1c29e --- /dev/null +++ b/Examples/test-suite/errors/Makefile.in @@ -0,0 +1,51 @@ +####################################################################### +# Makefile for errors test-suite +# +# This test-suite is for checking SWIG errors and warnings and uses +# Python as the target language. +# +# It compares the stderr output from SWIG to the contents of the .stderr +# file for each test case. The test cases are different to those used by +# the language module test-suites. The .i files in this directory are +# used instead of those in the parent directory. +# +# When adding a new test case, be sure to commit the expected output +# file (.stderr) in addition to the test case itself. +####################################################################### + +LANGUAGE = python +ERROR_EXT = newerr + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +top_builddir = @top_builddir@ + +# All .i files with prefix 'cpp_' will be treated as C++ input and remaining .i files as C input +ALL_ERROR_TEST_CASES := $(patsubst %.i,%, $(wildcard *.i)) +CPP_ERROR_TEST_CASES := $(filter cpp_%, $(ALL_ERROR_TEST_CASES)) +C_ERROR_TEST_CASES := $(filter-out $(CPP_ERROR_TEST_CASES), $(ALL_ERROR_TEST_CASES)) + +ERROR_TEST_CASES := $(CPP_ERROR_TEST_CASES:=.cpptest) \ + $(C_ERROR_TEST_CASES:=.ctest) + +include $(srcdir)/../common.mk + + +# Rules for the different types of tests +%.cpptest: + echo "$(ACTION)ing errors testcase $*" + -$(SWIG) -c++ -python -Wall $(SWIGOPT) $*.i 2> $*.$(ERROR_EXT) + $(COMPILETOOL) diff $*.stderr $*.newerr + +%.ctest: + echo "$(ACTION)ing errors testcase $*" + -$(SWIG) -python -Wall $(SWIGOPT) $*.i 2> $*.$(ERROR_EXT) + $(COMPILETOOL) diff $*.stderr $*.newerr + +%.clean: + + +clean: + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile $(LANGUAGE)_clean + @rm -f *.newerr *.py + diff --git a/Examples/test-suite/errors/c_bad_name.stderr b/Examples/test-suite/errors/c_bad_name.stderr new file mode 100644 index 000000000..6c1f706a3 --- /dev/null +++ b/Examples/test-suite/errors/c_bad_name.stderr @@ -0,0 +1,2 @@ +c_bad_name.i:3: Warning 121: %name is deprecated. Use %rename instead. +c_bad_name.i:3: Error: Missing argument to %name directive. diff --git a/Examples/test-suite/errors/c_bad_native.stderr b/Examples/test-suite/errors/c_bad_native.stderr new file mode 100644 index 000000000..dd255dfc6 --- /dev/null +++ b/Examples/test-suite/errors/c_bad_native.stderr @@ -0,0 +1 @@ +c_bad_native.i:3: Error: %native declaration 'foo' is not a function. diff --git a/Examples/test-suite/errors/c_class.stderr b/Examples/test-suite/errors/c_class.stderr new file mode 100644 index 000000000..306e144e5 --- /dev/null +++ b/Examples/test-suite/errors/c_class.stderr @@ -0,0 +1,2 @@ +c_class.i:3: Warning 301: class keyword used, but not in C++ mode. +c_class.i:3: Warning 314: 'class' is a python keyword, renaming to '_class' diff --git a/Examples/test-suite/errors/c_default_error.stderr b/Examples/test-suite/errors/c_default_error.stderr new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/test-suite/errors/c_deprecated.stderr b/Examples/test-suite/errors/c_deprecated.stderr new file mode 100644 index 000000000..9e77c9ab2 --- /dev/null +++ b/Examples/test-suite/errors/c_deprecated.stderr @@ -0,0 +1,2 @@ +c_deprecated.i:3: Warning 102: %val directive deprecated (ignored). +c_deprecated.i:3: Warning 103: %out directive deprecated (ignored). diff --git a/Examples/test-suite/errors/c_empty_char.stderr b/Examples/test-suite/errors/c_empty_char.stderr new file mode 100644 index 000000000..9f9fa05ca --- /dev/null +++ b/Examples/test-suite/errors/c_empty_char.stderr @@ -0,0 +1 @@ +c_empty_char.i:3: Error: Empty character constant diff --git a/Examples/test-suite/errors/c_enum_badvalue.stderr b/Examples/test-suite/errors/c_enum_badvalue.stderr new file mode 100644 index 000000000..bccd02e90 --- /dev/null +++ b/Examples/test-suite/errors/c_enum_badvalue.stderr @@ -0,0 +1 @@ +c_enum_badvalue.i:6: Error: Type error. Expecting an integral type diff --git a/Examples/test-suite/errors/c_extra_rblock.stderr b/Examples/test-suite/errors/c_extra_rblock.stderr new file mode 100644 index 000000000..82877023a --- /dev/null +++ b/Examples/test-suite/errors/c_extra_rblock.stderr @@ -0,0 +1 @@ +c_extra_rblock.i:5: Error: Syntax error in input(1). diff --git a/Examples/test-suite/errors/c_extra_rbrace.stderr b/Examples/test-suite/errors/c_extra_rbrace.stderr new file mode 100644 index 000000000..23bd41f3c --- /dev/null +++ b/Examples/test-suite/errors/c_extra_rbrace.stderr @@ -0,0 +1 @@ +c_extra_rbrace.i:5: Error: Syntax error. Extraneous '}' diff --git a/Examples/test-suite/errors/c_extra_unsigned.stderr b/Examples/test-suite/errors/c_extra_unsigned.stderr new file mode 100644 index 000000000..06e9439a7 --- /dev/null +++ b/Examples/test-suite/errors/c_extra_unsigned.stderr @@ -0,0 +1,3 @@ +c_extra_unsigned.i:3: Error: Extra unsigned specifier. +c_extra_unsigned.i:4: Error: Extra signed specifier. +c_extra_unsigned.i:5: Error: Extra signed specifier. diff --git a/Examples/test-suite/errors/c_insert_missing.stderr b/Examples/test-suite/errors/c_insert_missing.stderr new file mode 100644 index 000000000..510d40e0a --- /dev/null +++ b/Examples/test-suite/errors/c_insert_missing.stderr @@ -0,0 +1 @@ +c_insert_missing.i:3: Error: Couldn't find 'missing_file.i'. diff --git a/Examples/test-suite/errors/c_long_short.stderr b/Examples/test-suite/errors/c_long_short.stderr new file mode 100644 index 000000000..eae36c3ce --- /dev/null +++ b/Examples/test-suite/errors/c_long_short.stderr @@ -0,0 +1,4 @@ +c_long_short.i:3: Error: Extra long specifier. +c_long_short.i:4: Error: Extra short specifier. +c_long_short.i:5: Error: Extra long specifier. +c_long_short.i:6: Error: Extra short specifier. diff --git a/Examples/test-suite/errors/c_missing_rbrace.stderr b/Examples/test-suite/errors/c_missing_rbrace.stderr new file mode 100644 index 000000000..28fdd263e --- /dev/null +++ b/Examples/test-suite/errors/c_missing_rbrace.stderr @@ -0,0 +1,2 @@ +c_missing_rbrace.i:3: Error: Missing '}'. Reached end of input. +c_missing_rbrace.i:3: Error: Syntax error in input(1). diff --git a/Examples/test-suite/errors/c_missing_semi.stderr b/Examples/test-suite/errors/c_missing_semi.stderr new file mode 100644 index 000000000..791b959ca --- /dev/null +++ b/Examples/test-suite/errors/c_missing_semi.stderr @@ -0,0 +1 @@ +c_missing_semi.i:3: Error: Syntax error in input(1). diff --git a/Examples/test-suite/errors/c_redefine.stderr b/Examples/test-suite/errors/c_redefine.stderr new file mode 100644 index 000000000..4fccf14ea --- /dev/null +++ b/Examples/test-suite/errors/c_redefine.stderr @@ -0,0 +1,6 @@ +c_redefine.i:4: Warning 302: Identifier 'foo' redefined (ignored), +c_redefine.i:3: Warning 302: previous definition of 'foo'. +c_redefine.i:8: Warning 302: Identifier 'bar' redefined (ignored), +c_redefine.i:6: Warning 302: previous definition of 'bar'. +c_redefine.i:14: Warning 322: Redundant redeclaration of 'bar' (Renamed from 'spam'), +c_redefine.i:6: Warning 322: previous declaration of 'bar'. diff --git a/Examples/test-suite/errors/c_varargs.stderr b/Examples/test-suite/errors/c_varargs.stderr new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/test-suite/errors/c_varargs_neg.stderr b/Examples/test-suite/errors/c_varargs_neg.stderr new file mode 100644 index 000000000..26c4cc92c --- /dev/null +++ b/Examples/test-suite/errors/c_varargs_neg.stderr @@ -0,0 +1 @@ +c_varargs_neg.i:3: Error: Argument count in %varargs must be positive. diff --git a/Examples/test-suite/errors/cpp_bad_extern.stderr b/Examples/test-suite/errors/cpp_bad_extern.stderr new file mode 100644 index 000000000..5102b71f7 --- /dev/null +++ b/Examples/test-suite/errors/cpp_bad_extern.stderr @@ -0,0 +1,2 @@ +cpp_bad_extern.i:5: Warning 313: Unrecognized extern type "INTERCAL". +cpp_bad_extern.i:7: Warning 313: Unrecognized extern type "INTERCAL". diff --git a/Examples/test-suite/errors/cpp_extend_destructors.stderr b/Examples/test-suite/errors/cpp_extend_destructors.stderr new file mode 100644 index 000000000..1eef277dc --- /dev/null +++ b/Examples/test-suite/errors/cpp_extend_destructors.stderr @@ -0,0 +1,19 @@ +cpp_extend_destructors.i:8: Warning 302: Identifier '~AStruct' redefined by %extend (ignored), +cpp_extend_destructors.i:5: Warning 302: %extend definition of '~AStruct'. +cpp_extend_destructors.i:14: Warning 302: Identifier '~BStruct' redefined (ignored), +cpp_extend_destructors.i:13: Warning 302: previous definition of '~BStruct'. +cpp_extend_destructors.i:87: Warning 302: Identifier '~JStruct' redefined (ignored), +cpp_extend_destructors.i:85: Warning 302: previous definition of '~JStruct'. +cpp_extend_destructors.i:100: Warning 302: Identifier '~LStruct' redefined (ignored), +cpp_extend_destructors.i:98: Warning 302: previous definition of '~LStruct'. +cpp_extend_destructors.i:24: Warning 521: Illegal destructor name CStruct::~NOT_CStruct(). Ignored. +cpp_extend_destructors.i:30: Warning 521: Illegal destructor name DStruct::~NOT_DStruct(). Ignored. +cpp_extend_destructors.i:44: Warning 521: Illegal destructor name EStruct::~NOT_EStruct(). Ignored. +cpp_extend_destructors.i:50: Warning 521: Illegal destructor name FStruct::~NOT_FStruct(). Ignored. +cpp_extend_destructors.i:65: Warning 521: Illegal destructor name GStruct::~NOT_GStruct(). Ignored. +cpp_extend_destructors.i:72: Warning 521: Illegal destructor name HStruct::~NOT_HStruct(). Ignored. +cpp_extend_destructors.i:81: Warning 521: Illegal destructor name IStruct::~NOT_IStruct(). Ignored. +cpp_extend_destructors.i:86: Warning 521: Illegal destructor name JStruct::~NOT_JStruct(). Ignored. +cpp_extend_destructors.i:92: Warning 521: Illegal destructor name KStruct::~NOT_KStruct(). Ignored. +cpp_extend_destructors.i:99: Warning 521: Illegal destructor name LStruct< int >::~NOT_LStruct(). Ignored. +cpp_extend_destructors.i:99: Warning 521: Illegal destructor name LStruct< short >::~NOT_LStruct(). Ignored. diff --git a/Examples/test-suite/errors/cpp_extend_redefine.stderr b/Examples/test-suite/errors/cpp_extend_redefine.stderr new file mode 100644 index 000000000..94770f5d7 --- /dev/null +++ b/Examples/test-suite/errors/cpp_extend_redefine.stderr @@ -0,0 +1,4 @@ +cpp_extend_redefine.i:9: Warning 302: Identifier 'bar' redefined by %extend (ignored), +cpp_extend_redefine.i:5: Warning 302: %extend definition of 'bar'. +cpp_extend_redefine.i:14: Warning 322: Redundant redeclaration of 'spam', +cpp_extend_redefine.i:10: Warning 322: previous declaration of 'spam'. diff --git a/Examples/test-suite/errors/cpp_extend_undefined.stderr b/Examples/test-suite/errors/cpp_extend_undefined.stderr new file mode 100644 index 000000000..aa63cb34f --- /dev/null +++ b/Examples/test-suite/errors/cpp_extend_undefined.stderr @@ -0,0 +1 @@ +cpp_extend_undefined.i:6: Warning 303: %extend defined for an undeclared class foo. diff --git a/Examples/test-suite/errors/cpp_inherit.stderr b/Examples/test-suite/errors/cpp_inherit.stderr new file mode 100644 index 000000000..50c6ed16a --- /dev/null +++ b/Examples/test-suite/errors/cpp_inherit.stderr @@ -0,0 +1,20 @@ +cpp_inherit.i:18: Warning 309: private inheritance from base 'A3' (ignored). +cpp_inherit.i:20: Warning 309: private inheritance from base 'A4' (ignored). +cpp_inherit.i:28: Warning 309: protected inheritance from base 'A8< double >' (ignored). +cpp_inherit.i:39: Warning 319: No access specifier given for base class 'B1' (ignored). +cpp_inherit.i:40: Warning 319: No access specifier given for base class 'B2< int >' (ignored). +cpp_inherit.i:15: Warning 401: Base class 'A1' undefined. +cpp_inherit.i:33: Warning 401: 'A1' must be defined before it is used as a base class. +cpp_inherit.i:17: Warning 401: Nothing known about base class 'A2'. Ignored. +cpp_inherit.i:22: Warning 402: Base class 'A5' is incomplete. +cpp_inherit.i:4: Warning 402: Only forward declaration 'A5' was found. +cpp_inherit.i:24: Error: 'A6' is not a valid base class. +cpp_inherit.i:5: Error: See definition of 'A6'. +cpp_inherit.i:24: Warning 401: Nothing known about base class 'A6'. Ignored. +cpp_inherit.i:26: Warning 401: Nothing known about base class 'A7< int >'. Ignored. +cpp_inherit.i:26: Warning 401: Maybe you forgot to instantiate 'A7< int >' using %template. +cpp_inherit.i:45: Warning 323: Recursive scope inheritance of 'Recursive'. +cpp_inherit.i:52: Warning 401: Base class 'Base< int >' has no name as it is an empty template instantiated with '%template()'. Ignored. +cpp_inherit.i:51: Warning 401: The %template directive must be written before 'Base< int >' is used as a base class and be declared with a name. +cpp_inherit.i:53: Warning 401: Base class 'Base< double >' undefined. +cpp_inherit.i:54: Warning 401: 'Base< double >' must be defined before it is used as a base class. diff --git a/Examples/test-suite/errors/cpp_inline_namespace.stderr b/Examples/test-suite/errors/cpp_inline_namespace.stderr new file mode 100644 index 000000000..be65b6b57 --- /dev/null +++ b/Examples/test-suite/errors/cpp_inline_namespace.stderr @@ -0,0 +1 @@ +cpp_inline_namespace.i:4: Error: %inline directive inside a namespace is disallowed. diff --git a/Examples/test-suite/errors/cpp_macro_locator.stderr b/Examples/test-suite/errors/cpp_macro_locator.stderr new file mode 100644 index 000000000..8a78d46af --- /dev/null +++ b/Examples/test-suite/errors/cpp_macro_locator.stderr @@ -0,0 +1,20 @@ +cpp_macro_locator.i:66: Warning 204: CPP #warning, "inline warning message one". +cpp_macro_locator.i:96: Warning 204: CPP #warning, "an inline warning message 2". +cpp_macro_locator.i:53: Warning 509: Overloaded method overload1(int const *) effectively ignored, +cpp_macro_locator.i:52: Warning 509: as it is shadowed by overload1(int *). +cpp_macro_locator.i:61: Warning 509: Overloaded method overload2(int const *) effectively ignored, +cpp_macro_locator.i:60: Warning 509: as it is shadowed by overload2(int *). +cpp_macro_locator.i:64: Warning 509: Overloaded method Klass1::methodX(int const *) effectively ignored, +cpp_macro_locator.i:64: Warning 509: as it is shadowed by Klass1::methodX(int *). +cpp_macro_locator.i:68: Warning 509: Overloaded method overload3(int const *) effectively ignored, +cpp_macro_locator.i:67: Warning 509: as it is shadowed by overload3(int *). +cpp_macro_locator.i:90: Warning 509: Overloaded method overload4(int const *) effectively ignored, +cpp_macro_locator.i:89: Warning 509: as it is shadowed by overload4(int *). +cpp_macro_locator.i:94: Warning 509: Overloaded method overloadinline1(int const *) effectively ignored, +cpp_macro_locator.i:93: Warning 509: as it is shadowed by overloadinline1(int *). +cpp_macro_locator.i:95: Warning 509: Overloaded method Klass2::methodX(int const *) effectively ignored, +cpp_macro_locator.i:95: Warning 509: as it is shadowed by Klass2::methodX(int *). +cpp_macro_locator.i:98: Warning 509: Overloaded method overloadinline2(int const *) effectively ignored, +cpp_macro_locator.i:97: Warning 509: as it is shadowed by overloadinline2(int *). +cpp_macro_locator.i:101: Warning 509: Overloaded method overload5(int const *) effectively ignored, +cpp_macro_locator.i:100: Warning 509: as it is shadowed by overload5(int *). diff --git a/Examples/test-suite/errors/cpp_missing_rparenthesis.stderr b/Examples/test-suite/errors/cpp_missing_rparenthesis.stderr new file mode 100644 index 000000000..cc97f5c68 --- /dev/null +++ b/Examples/test-suite/errors/cpp_missing_rparenthesis.stderr @@ -0,0 +1,2 @@ +cpp_missing_rparenthesis.i:5: Error: Missing ')'. Reached end of input. +cpp_missing_rparenthesis.i:5: Error: Syntax error in input(3). diff --git a/Examples/test-suite/errors/cpp_missing_rtemplate.stderr b/Examples/test-suite/errors/cpp_missing_rtemplate.stderr new file mode 100644 index 000000000..07a89bf08 --- /dev/null +++ b/Examples/test-suite/errors/cpp_missing_rtemplate.stderr @@ -0,0 +1 @@ +cpp_missing_rtemplate.i:4: Error: Syntax error in input(1). diff --git a/Examples/test-suite/errors/cpp_namespace_alias.stderr b/Examples/test-suite/errors/cpp_namespace_alias.stderr new file mode 100644 index 000000000..166d1f681 --- /dev/null +++ b/Examples/test-suite/errors/cpp_namespace_alias.stderr @@ -0,0 +1 @@ +cpp_namespace_alias.i:8: Warning 308: Namespace alias 'B' not allowed here. Assuming 'blah' diff --git a/Examples/test-suite/errors/cpp_namespace_aliasnot.stderr b/Examples/test-suite/errors/cpp_namespace_aliasnot.stderr new file mode 100644 index 000000000..a2f33c909 --- /dev/null +++ b/Examples/test-suite/errors/cpp_namespace_aliasnot.stderr @@ -0,0 +1 @@ +cpp_namespace_aliasnot.i:4: Error: 'blah' is not a namespace diff --git a/Examples/test-suite/errors/cpp_namespace_aliasundef.stderr b/Examples/test-suite/errors/cpp_namespace_aliasundef.stderr new file mode 100644 index 000000000..97d0206a8 --- /dev/null +++ b/Examples/test-suite/errors/cpp_namespace_aliasundef.stderr @@ -0,0 +1 @@ +cpp_namespace_aliasundef.i:3: Error: Unknown namespace 'blah' diff --git a/Examples/test-suite/errors/cpp_nested_template.stderr b/Examples/test-suite/errors/cpp_nested_template.stderr new file mode 100644 index 000000000..9e46cff74 --- /dev/null +++ b/Examples/test-suite/errors/cpp_nested_template.stderr @@ -0,0 +1,2 @@ +cpp_nested_template.i:9: Warning 324: Named nested template instantiations not supported. Processing as if no name was given to %template(). +cpp_nested_template.i:18: Warning 324: Named nested template instantiations not supported. Processing as if no name was given to %template(). diff --git a/Examples/test-suite/errors/cpp_no_access.stderr b/Examples/test-suite/errors/cpp_no_access.stderr new file mode 100644 index 000000000..b87aa3e51 --- /dev/null +++ b/Examples/test-suite/errors/cpp_no_access.stderr @@ -0,0 +1 @@ +cpp_no_access.i:3: Warning 319: No access specifier given for base class 'foo' (ignored). diff --git a/Examples/test-suite/errors/cpp_no_return_type.stderr b/Examples/test-suite/errors/cpp_no_return_type.stderr new file mode 100644 index 000000000..07c4d2261 --- /dev/null +++ b/Examples/test-suite/errors/cpp_no_return_type.stderr @@ -0,0 +1,2 @@ +cpp_no_return_type.i:6: Warning 504: Function S::R() must have a return type. Ignored. +cpp_no_return_type.i:10: Warning 504: Function U::UU() must have a return type. Ignored. diff --git a/Examples/test-suite/errors/cpp_nobase.stderr b/Examples/test-suite/errors/cpp_nobase.stderr new file mode 100644 index 000000000..0cc209788 --- /dev/null +++ b/Examples/test-suite/errors/cpp_nobase.stderr @@ -0,0 +1,3 @@ +cpp_nobase.i:3: Warning 401: Nothing known about base class 'Bar'. Ignored. +cpp_nobase.i:6: Warning 401: Nothing known about base class 'Bar< int >'. Ignored. +cpp_nobase.i:6: Warning 401: Maybe you forgot to instantiate 'Bar< int >' using %template. diff --git a/Examples/test-suite/errors/cpp_overload.stderr b/Examples/test-suite/errors/cpp_overload.stderr new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/test-suite/errors/cpp_overload_const.stderr b/Examples/test-suite/errors/cpp_overload_const.stderr new file mode 100644 index 000000000..696fd7482 --- /dev/null +++ b/Examples/test-suite/errors/cpp_overload_const.stderr @@ -0,0 +1,10 @@ +cpp_overload_const.i:4: Warning 509: Overloaded method check(int *) effectively ignored, +cpp_overload_const.i:3: Warning 509: as it is shadowed by check(int const *). +cpp_overload_const.i:5: Warning 509: Overloaded method check(int &) effectively ignored, +cpp_overload_const.i:3: Warning 509: as it is shadowed by check(int const *). +cpp_overload_const.i:10: Warning 509: Overloaded method check(OverStruct *) effectively ignored, +cpp_overload_const.i:9: Warning 509: as it is shadowed by check(OverStruct const *). +cpp_overload_const.i:11: Warning 509: Overloaded method check(OverStruct &) effectively ignored, +cpp_overload_const.i:9: Warning 509: as it is shadowed by check(OverStruct const *). +cpp_overload_const.i:12: Warning 509: Overloaded method check(OverStruct const &) effectively ignored, +cpp_overload_const.i:9: Warning 509: as it is shadowed by check(OverStruct const *). diff --git a/Examples/test-suite/errors/cpp_private_defvalue.stderr b/Examples/test-suite/errors/cpp_private_defvalue.stderr new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/test-suite/errors/cpp_private_inherit.stderr b/Examples/test-suite/errors/cpp_private_inherit.stderr new file mode 100644 index 000000000..f3e381aba --- /dev/null +++ b/Examples/test-suite/errors/cpp_private_inherit.stderr @@ -0,0 +1,2 @@ +cpp_private_inherit.i:6: Warning 309: private inheritance from base 'Foo' (ignored). +cpp_private_inherit.i:9: Warning 309: protected inheritance from base 'Foo' (ignored). diff --git a/Examples/test-suite/errors/cpp_recursive_typedef.stderr b/Examples/test-suite/errors/cpp_recursive_typedef.stderr new file mode 100644 index 000000000..d9135aa43 --- /dev/null +++ b/Examples/test-suite/errors/cpp_recursive_typedef.stderr @@ -0,0 +1 @@ +:1: Error: Recursive typedef detected resolving 'pds *' to 'std::set< pds > *' to 'std::set< std::set< pds > > *' and so on... diff --git a/Examples/test-suite/errors/cpp_shared_ptr.stderr b/Examples/test-suite/errors/cpp_shared_ptr.stderr new file mode 100644 index 000000000..1553af65c --- /dev/null +++ b/Examples/test-suite/errors/cpp_shared_ptr.stderr @@ -0,0 +1,3 @@ +cpp_shared_ptr.i:20: Warning 520: Base class 'A' of 'C' is not similarly marked as a smart pointer. +cpp_shared_ptr.i:24: Warning 520: Derived class 'D' of 'C' is not similarly marked as a smart pointer. +cpp_shared_ptr.i:24: Warning 520: Derived class 'D' of 'B' is not similarly marked as a smart pointer. diff --git a/Examples/test-suite/errors/cpp_template_argname.stderr b/Examples/test-suite/errors/cpp_template_argname.stderr new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/test-suite/errors/cpp_template_nargs.stderr b/Examples/test-suite/errors/cpp_template_nargs.stderr new file mode 100644 index 000000000..4ced28e05 --- /dev/null +++ b/Examples/test-suite/errors/cpp_template_nargs.stderr @@ -0,0 +1,2 @@ +cpp_template_nargs.i:5: Error: Template 'blah' undefined. +cpp_template_nargs.i:6: Error: Template 'blah' undefined. diff --git a/Examples/test-suite/errors/cpp_template_not.stderr b/Examples/test-suite/errors/cpp_template_not.stderr new file mode 100644 index 000000000..aeb058c67 --- /dev/null +++ b/Examples/test-suite/errors/cpp_template_not.stderr @@ -0,0 +1 @@ +cpp_template_not.i:5: Error: 'blah' is not defined as a template. (cdecl) diff --git a/Examples/test-suite/errors/cpp_template_partial.stderr b/Examples/test-suite/errors/cpp_template_partial.stderr new file mode 100644 index 000000000..94574e582 --- /dev/null +++ b/Examples/test-suite/errors/cpp_template_partial.stderr @@ -0,0 +1 @@ +cpp_template_partial.i:3: Warning 317: Specialization of non-template 'vector'. diff --git a/Examples/test-suite/errors/cpp_template_repeat.stderr b/Examples/test-suite/errors/cpp_template_repeat.stderr new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/test-suite/errors/cpp_template_undef.stderr b/Examples/test-suite/errors/cpp_template_undef.stderr new file mode 100644 index 000000000..2cf27c3b4 --- /dev/null +++ b/Examples/test-suite/errors/cpp_template_undef.stderr @@ -0,0 +1 @@ +cpp_template_undef.i:3: Error: Template 'blah' undefined. diff --git a/Examples/test-suite/errors/cpp_using_not.stderr b/Examples/test-suite/errors/cpp_using_not.stderr new file mode 100644 index 000000000..1b8be79ac --- /dev/null +++ b/Examples/test-suite/errors/cpp_using_not.stderr @@ -0,0 +1 @@ +cpp_using_not.i:4: Error: 'blah' is not a namespace. diff --git a/Examples/test-suite/errors/cpp_using_undef.stderr b/Examples/test-suite/errors/cpp_using_undef.stderr new file mode 100644 index 000000000..f4e5020d5 --- /dev/null +++ b/Examples/test-suite/errors/cpp_using_undef.stderr @@ -0,0 +1,2 @@ +cpp_using_undef.i:4: Error: Nothing known about namespace 'foo' +cpp_using_undef.i:3: Warning 315: Nothing known about 'foo::bar'. diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log deleted file mode 100644 index da0d59778..000000000 --- a/Examples/test-suite/errors/expected.log +++ /dev/null @@ -1,390 +0,0 @@ -SWIG error and warning test. opts= ------------------------------------------------------------ - -:::::::::::::::::::::::::::::::: c_bad_name.i ::::::::::::::::::::::::::::::::::: -c_bad_name.i:3: Warning 121: %name is deprecated. Use %rename instead. -c_bad_name.i:3: Error: Missing argument to %name directive. - -:::::::::::::::::::::::::::::::: c_bad_native.i ::::::::::::::::::::::::::::::::::: -c_bad_native.i:3: Error: %native declaration 'foo' is not a function. - -:::::::::::::::::::::::::::::::: c_class.i ::::::::::::::::::::::::::::::::::: -c_class.i:3: Warning 301: class keyword used, but not in C++ mode. -c_class.i:3: Warning 314: 'class' is a python keyword, renaming to '_class' - -:::::::::::::::::::::::::::::::: c_default_error.i ::::::::::::::::::::::::::::::::::: - -:::::::::::::::::::::::::::::::: c_deprecated.i ::::::::::::::::::::::::::::::::::: -c_deprecated.i:3: Warning 102: %val directive deprecated (ignored). -c_deprecated.i:3: Warning 103: %out directive deprecated (ignored). - -:::::::::::::::::::::::::::::::: c_empty_char.i ::::::::::::::::::::::::::::::::::: -c_empty_char.i:3: Error: Empty character constant -0 - -:::::::::::::::::::::::::::::::: c_enum_badvalue.i ::::::::::::::::::::::::::::::::::: -c_enum_badvalue.i:6: Error: Type error. Expecting an integral type - -:::::::::::::::::::::::::::::::: c_extra_rblock.i ::::::::::::::::::::::::::::::::::: -c_extra_rblock.i:5: Error: Syntax error in input(1). - -:::::::::::::::::::::::::::::::: c_extra_rbrace.i ::::::::::::::::::::::::::::::::::: -c_extra_rbrace.i:5: Error: Syntax error. Extraneous '}' - -:::::::::::::::::::::::::::::::: c_extra_unsigned.i ::::::::::::::::::::::::::::::::::: -c_extra_unsigned.i:3: Error: Extra unsigned specifier. -c_extra_unsigned.i:4: Error: Extra signed specifier. -c_extra_unsigned.i:5: Error: Extra signed specifier. - -:::::::::::::::::::::::::::::::: c_insert_missing.i ::::::::::::::::::::::::::::::::::: -c_insert_missing.i:3: Error: Couldn't find 'missing_file.i'. - -:::::::::::::::::::::::::::::::: c_long_short.i ::::::::::::::::::::::::::::::::::: -c_long_short.i:3: Error: Extra long specifier. -c_long_short.i:4: Error: Extra short specifier. -c_long_short.i:5: Error: Extra long specifier. -c_long_short.i:6: Error: Extra short specifier. - -:::::::::::::::::::::::::::::::: c_missing_rbrace.i ::::::::::::::::::::::::::::::::::: -c_missing_rbrace.i:3: Error: Missing '}'. Reached end of input. -c_missing_rbrace.i:3: Error: Syntax error in input(1). - -:::::::::::::::::::::::::::::::: c_missing_semi.i ::::::::::::::::::::::::::::::::::: -c_missing_semi.i:3: Error: Syntax error in input(1). - -:::::::::::::::::::::::::::::::: c_redefine.i ::::::::::::::::::::::::::::::::::: -c_redefine.i:4: Warning 302: Identifier 'foo' redefined (ignored), -c_redefine.i:3: Warning 302: previous definition of 'foo'. -c_redefine.i:8: Warning 302: Identifier 'bar' redefined (ignored), -c_redefine.i:6: Warning 302: previous definition of 'bar'. -c_redefine.i:14: Warning 322: Redundant redeclaration of 'bar' (Renamed from 'spam'), -c_redefine.i:6: Warning 322: previous declaration of 'bar'. - -:::::::::::::::::::::::::::::::: c_varargs.i ::::::::::::::::::::::::::::::::::: - -:::::::::::::::::::::::::::::::: c_varargs_neg.i ::::::::::::::::::::::::::::::::::: -c_varargs_neg.i:3: Error: Argument count in %varargs must be positive. - -:::::::::::::::::::::::::::::::: nomodule.i ::::::::::::::::::::::::::::::::::: -No module name specified using %module or -module. - -:::::::::::::::::::::::::::::::: pp_badeval.i ::::::::::::::::::::::::::::::::::: -pp_badeval.i:4: Warning 202: Could not evaluate expression 'FOO==4+' -pp_badeval.i:4: Warning 202: Error: 'Expected an expression' - -:::::::::::::::::::::::::::::::: pp_constant.i ::::::::::::::::::::::::::::::::::: -pp_constant.i:9: Warning 305: Bad constant value (ignored). -pp_constant.i:15: Warning 305: Bad constant value (ignored). -pp_constant.i:23: Warning 305: Bad constant value (ignored). -pp_constant.i:29: Warning 305: Bad constant value (ignored). -pp_constant.i:35: Warning 305: Bad constant value (ignored). -pp_constant.i:42: Warning 305: Bad constant value (ignored). -pp_constant.i:46: Warning 305: Bad constant value (ignored). -pp_constant.i:49: Warning 305: Bad constant value (ignored). - -:::::::::::::::::::::::::::::::: pp_defined.i ::::::::::::::::::::::::::::::::::: -pp_defined.i:6: Error: No arguments given to defined() -pp_defined.i:6: Error: Missing expression for #if. - -:::::::::::::::::::::::::::::::: pp_deprecated.i ::::::::::::::::::::::::::::::::::: -pp_deprecated.i:4: Warning 101: %extern is deprecated. Use %import instead. -pp_deprecated.i:4: Error: Unable to find 'ext;' -pp_deprecated.i:6: Warning 204: CPP #warning, "Print this warning". -pp_deprecated.i:8: Error: CPP #error "This is an error". Use the -cpperraswarn option to continue swig processing. - -:::::::::::::::::::::::::::::::: pp_illegal_argument.i ::::::::::::::::::::::::::::::::::: -pp_illegal_argument.i:6: Error: Illegal macro argument name '..' -pp_illegal_argument.i:10: Error: Illegal macro argument name '..' -pp_illegal_argument.i:16: Error: Illegal character in macro argument name - -:::::::::::::::::::::::::::::::: pp_macro_args.i ::::::::::::::::::::::::::::::::::: - -:::::::::::::::::::::::::::::::: pp_macro_badchar.i ::::::::::::::::::::::::::::::::::: -pp_macro_badchar.i:4: Error: Illegal character in macro argument name - -:::::::::::::::::::::::::::::::: pp_macro_defined_unterminated.i ::::::::::::::::::::::::::::::::::: -pp_macro_defined_unterminated.i:4: Error: Unterminated call to 'defined' - -:::::::::::::::::::::::::::::::: pp_macro_expansion.i ::::::::::::::::::::::::::::::::::: -pp_macro_expansion.i:9: Error: Macro 'MACRO2' expects 2 arguments - -:::::::::::::::::::::::::::::::: pp_macro_expansion_multiline.i ::::::::::::::::::::::::::::::::::: -pp_macro_expansion_multiline.i:13: Warning 509: Overloaded method foo(int const *) effectively ignored, -pp_macro_expansion_multiline.i:12: Warning 509: as it is shadowed by foo(int *). -pp_macro_expansion_multiline.i:31: Warning 509: Overloaded method bar(int const *) effectively ignored, -pp_macro_expansion_multiline.i:30: Warning 509: as it is shadowed by bar(int *). - -:::::::::::::::::::::::::::::::: pp_macro_inline_unterminated.i ::::::::::::::::::::::::::::::::::: -pp_macro_inline_unterminated.i:9: Error: Unterminated call invoking macro 'foo' -pp_macro_inline_unterminated.i:12: Error: Syntax error in input(3). - -:::::::::::::::::::::::::::::::: pp_macro_missing_expression.i ::::::::::::::::::::::::::::::::::: -pp_macro_missing_expression.i:4: Error: Missing identifier for #ifdef. -pp_macro_missing_expression.i:7: Error: Missing identifier for #ifndef. -pp_macro_missing_expression.i:10: Error: Missing expression for #if. -pp_macro_missing_expression.i:14: Error: Missing expression for #elif. -pp_macro_missing_expression.i:21: Error: Missing expression for #elif. - -:::::::::::::::::::::::::::::::: pp_macro_unexpected_tokens.i ::::::::::::::::::::::::::::::::::: -pp_macro_unexpected_tokens.i:5: Warning 206: Unexpected tokens after #endif directive. -pp_macro_unexpected_tokens.i:8: Warning 206: Unexpected tokens after #endif directive. -pp_macro_unexpected_tokens.i:11: Warning 206: Unexpected tokens after #else directive. -pp_macro_unexpected_tokens.i:18: Warning 206: Unexpected tokens after #endif directive. -pp_macro_unexpected_tokens.i:21: Warning 206: Unexpected tokens after #else directive. - -:::::::::::::::::::::::::::::::: pp_macro_nargs.i ::::::::::::::::::::::::::::::::::: -pp_macro_nargs.i:7: Error: Macro 'foo' expects 2 arguments -pp_macro_nargs.i:8: Error: Macro 'foo' expects 2 arguments -pp_macro_nargs.i:10: Error: Macro 'bar' expects 1 argument -pp_macro_nargs.i:11: Error: Macro 'spam' expects no arguments - -:::::::::::::::::::::::::::::::: pp_macro_redef.i ::::::::::::::::::::::::::::::::::: -pp_macro_redef.i:4: Error: Macro 'foo' redefined, -pp_macro_redef.i:3: Error: previous definition of 'foo'. -pp_macro_redef.i:7: Error: Macro 'foo' redefined, -pp_macro_redef.i:3: Error: previous definition of 'foo'. - -:::::::::::::::::::::::::::::::: pp_macro_rparen.i ::::::::::::::::::::::::::::::::::: -pp_macro_rparen.i:3: Error: Missing ')' in macro parameters - -:::::::::::::::::::::::::::::::: pp_macro_unterminated.i ::::::::::::::::::::::::::::::::::: -pp_macro_unterminated.i:5: Error: Unterminated call invoking macro 'foo' - -:::::::::::::::::::::::::::::::: pp_misplaced_elif.i ::::::::::::::::::::::::::::::::::: -pp_misplaced_elif.i:4: Error: Misplaced #elif. -pp_misplaced_elif.i:6: Error: Extraneous #endif. - -:::::::::::::::::::::::::::::::: pp_misplaced_else.i ::::::::::::::::::::::::::::::::::: -pp_misplaced_else.i:4: Error: Misplaced #else. -pp_misplaced_else.i:6: Error: Extraneous #endif. - -:::::::::::::::::::::::::::::::: pp_missing_enddef.i ::::::::::::::::::::::::::::::::::: -pp_missing_enddef.i:EOF: Error: Missing %enddef for macro starting on line 3 - -:::::::::::::::::::::::::::::::: pp_missing_endif.i ::::::::::::::::::::::::::::::::::: -pp_missing_endif.i:EOF: Error: Missing #endif for conditional starting on line 3 - -:::::::::::::::::::::::::::::::: pp_missing_file.i ::::::::::::::::::::::::::::::::::: -pp_missing_file.i:3: Error: Unable to find 'missing_filename.i' - -:::::::::::::::::::::::::::::::: pp_missing_rblock.i ::::::::::::::::::::::::::::::::::: -pp_missing_rblock.i:EOF: Error: Unterminated %{ ... %} block starting on line 3 - -:::::::::::::::::::::::::::::::: pp_pragma.i ::::::::::::::::::::::::::::::::::: -pp_pragma.i:4: Error: Unknown SWIG pragma: rubbish() - -:::::::::::::::::::::::::::::::: pp_unterm_char.i ::::::::::::::::::::::::::::::::::: -pp_unterm_char.i:EOF: Error: Unterminated character constant starting at line 4 - -:::::::::::::::::::::::::::::::: pp_unterm_comment.i ::::::::::::::::::::::::::::::::::: -pp_unterm_comment.i:EOF: Error: Unterminated comment starting on line 3 - -:::::::::::::::::::::::::::::::: pp_unterm_string.i ::::::::::::::::::::::::::::::::::: -pp_unterm_string.i:EOF: Error: Unterminated string constant starting at line 4 - -:::::::::::::::::::::::::::::::: pp_variable_args.i ::::::::::::::::::::::::::::::::::: -pp_variable_args.i:6: Error: Variable length macro argument must be last parameter - -:::::::::::::::::::::::::::::::: swig_apply_nargs.i ::::::::::::::::::::::::::::::::::: -swig_apply_nargs.i:6: Error: Can't apply (char *str,int len) to (int x). Number of arguments don't match. - -:::::::::::::::::::::::::::::::: swig_extend.i ::::::::::::::::::::::::::::::::::: -swig_extend.i:19: Warning 326: Deprecated %extend name used - the struct name 'StructBName' should be used instead of the typedef name 'StructB'. -swig_extend.i:45: Warning 326: Deprecated %extend name used - the struct name 'stru_struct' should be used instead of the typedef name 'stru'. -swig_extend.i:56: Warning 326: Deprecated %extend name used - the union name 'uni_union' should be used instead of the typedef name 'uni'. -swig_extend.i:34: Warning 303: %extend defined for an undeclared class StructDName. -swig_extend.i:50: Warning 522: Use of an illegal constructor name 'stru' in %extend is deprecated, the constructor name should be 'stru_struct'. -swig_extend.i:53: Warning 523: Use of an illegal destructor name 'stru' in %extend is deprecated, the destructor name should be 'stru_struct'. -swig_extend.i:57: Warning 522: Use of an illegal constructor name 'uni' in %extend is deprecated, the constructor name should be 'uni_union'. -swig_extend.i:58: Warning 523: Use of an illegal destructor name 'uni' in %extend is deprecated, the destructor name should be 'uni_union'. - -:::::::::::::::::::::::::::::::: swig_identifier.i ::::::::::::::::::::::::::::::::::: -swig_identifier.i:5: Warning 503: Can't wrap 'foo bar' unless renamed to a valid identifier. - -:::::::::::::::::::::::::::::::: swig_insert_bad.i ::::::::::::::::::::::::::::::::::: -swig_insert_bad.i:5: Error: Unknown target 'foobar' for %insert directive. - -:::::::::::::::::::::::::::::::: swig_typemap_copy.i ::::::::::::::::::::::::::::::::::: -swig_typemap_copy.i:3: Error: Can't copy typemap (in) blah = int - -:::::::::::::::::::::::::::::::: swig_typemap_old.i ::::::::::::::::::::::::::::::::::: -swig_typemap_old.i:6: Warning 450: Deprecated typemap feature ($source/$target). -swig_typemap_old.i:6: Warning 450: The use of $source and $target in a typemap declaration is deprecated. -For typemaps related to argument input (in,ignore,default,arginit,check), replace -$source by $input and $target by $1. For typemaps related to return values (out, -argout,ret,except), replace $source by $1 and $target by $result. See the file -Doc/Manual/Typemaps.html for complete details. - -:::::::::::::::::::::::::::::::: swig_typemap_warn.i ::::::::::::::::::::::::::::::::::: -swig_typemap_warn.i:7: Warning 1000: Test warning for 'in' typemap for int abc (arg1) - argnum: 1 &1_ltype: int * descriptor: SWIGTYPE_int -swig_typemap_warn.i:7: Warning 1000: Test warning for 'in' typemap for int arg3 (arg3) - argnum: 3 &1_ltype: int * descriptor: SWIGTYPE_int -swig_typemap_warn.i:7: Warning 1001: Test warning for 'out' typemap for double mmm (result) - name: mmm symname: mmm &1_ltype: double * descriptor: SWIGTYPE_double -swig_typemap_warn.i:7: Warning 1000: Test warning for 'in' typemap for int abc (arg1) - argnum: 1 &1_ltype: int * descriptor: SWIGTYPE_int -swig_typemap_warn.i:7: Warning 1000: Test warning for 'in' typemap for int arg3 (arg3) - argnum: 3 &1_ltype: int * descriptor: SWIGTYPE_int -swig_typemap_warn.i:7: Warning 1000: Test warning for 'in' typemap for int abc (arg1) - argnum: 1 &1_ltype: int * descriptor: SWIGTYPE_int -swig_typemap_warn.i:7: Warning 1000: Test warning for 'in' typemap for int arg3 (arg3) - argnum: 3 &1_ltype: int * descriptor: SWIGTYPE_int - -:::::::::::::::::::::::::::::::: cpp_bad_extern.i ::::::::::::::::::::::::::::::::::: -cpp_bad_extern.i:5: Warning 313: Unrecognized extern type "INTERCAL". -cpp_bad_extern.i:7: Warning 313: Unrecognized extern type "INTERCAL". - -:::::::::::::::::::::::::::::::: cpp_extend_destructors.i ::::::::::::::::::::::::::::::::::: -cpp_extend_destructors.i:8: Warning 302: Identifier '~AStruct' redefined by %extend (ignored), -cpp_extend_destructors.i:5: Warning 302: %extend definition of '~AStruct'. -cpp_extend_destructors.i:14: Warning 302: Identifier '~BStruct' redefined (ignored), -cpp_extend_destructors.i:13: Warning 302: previous definition of '~BStruct'. -cpp_extend_destructors.i:87: Warning 302: Identifier '~JStruct' redefined (ignored), -cpp_extend_destructors.i:85: Warning 302: previous definition of '~JStruct'. -cpp_extend_destructors.i:100: Warning 302: Identifier '~LStruct' redefined (ignored), -cpp_extend_destructors.i:98: Warning 302: previous definition of '~LStruct'. -cpp_extend_destructors.i:24: Warning 521: Illegal destructor name CStruct::~NOT_CStruct(). Ignored. -cpp_extend_destructors.i:30: Warning 521: Illegal destructor name DStruct::~NOT_DStruct(). Ignored. -cpp_extend_destructors.i:44: Warning 521: Illegal destructor name EStruct::~NOT_EStruct(). Ignored. -cpp_extend_destructors.i:50: Warning 521: Illegal destructor name FStruct::~NOT_FStruct(). Ignored. -cpp_extend_destructors.i:65: Warning 521: Illegal destructor name GStruct::~NOT_GStruct(). Ignored. -cpp_extend_destructors.i:72: Warning 521: Illegal destructor name HStruct::~NOT_HStruct(). Ignored. -cpp_extend_destructors.i:81: Warning 521: Illegal destructor name IStruct::~NOT_IStruct(). Ignored. -cpp_extend_destructors.i:86: Warning 521: Illegal destructor name JStruct::~NOT_JStruct(). Ignored. -cpp_extend_destructors.i:92: Warning 521: Illegal destructor name KStruct::~NOT_KStruct(). Ignored. -cpp_extend_destructors.i:99: Warning 521: Illegal destructor name LStruct< int >::~NOT_LStruct(). Ignored. -cpp_extend_destructors.i:99: Warning 521: Illegal destructor name LStruct< short >::~NOT_LStruct(). Ignored. - -:::::::::::::::::::::::::::::::: cpp_extend_redefine.i ::::::::::::::::::::::::::::::::::: -cpp_extend_redefine.i:9: Warning 302: Identifier 'bar' redefined by %extend (ignored), -cpp_extend_redefine.i:5: Warning 302: %extend definition of 'bar'. -cpp_extend_redefine.i:14: Warning 322: Redundant redeclaration of 'spam', -cpp_extend_redefine.i:10: Warning 322: previous declaration of 'spam'. - -:::::::::::::::::::::::::::::::: cpp_extend_undefined.i ::::::::::::::::::::::::::::::::::: -cpp_extend_undefined.i:6: Warning 303: %extend defined for an undeclared class foo. - -:::::::::::::::::::::::::::::::: cpp_inline_namespace.i ::::::::::::::::::::::::::::::::::: -cpp_inline_namespace.i:4: Error: %inline directive inside a namespace is disallowed. - -:::::::::::::::::::::::::::::::: cpp_inherit.i ::::::::::::::::::::::::::::::::::: -cpp_inherit.i:18: Warning 309: private inheritance from base 'A3' (ignored). -cpp_inherit.i:20: Warning 309: private inheritance from base 'A4' (ignored). -cpp_inherit.i:28: Warning 309: protected inheritance from base 'A8< double >' (ignored). -cpp_inherit.i:39: Warning 319: No access specifier given for base class 'B1' (ignored). -cpp_inherit.i:40: Warning 319: No access specifier given for base class 'B2< int >' (ignored). -cpp_inherit.i:15: Warning 401: Base class 'A1' undefined. -cpp_inherit.i:33: Warning 401: 'A1' must be defined before it is used as a base class. -cpp_inherit.i:17: Warning 401: Nothing known about base class 'A2'. Ignored. -cpp_inherit.i:22: Warning 402: Base class 'A5' is incomplete. -cpp_inherit.i:4: Warning 402: Only forward declaration 'A5' was found. -cpp_inherit.i:24: Error: 'A6' is not a valid base class. -cpp_inherit.i:5: Error: See definition of 'A6'. -cpp_inherit.i:24: Warning 401: Nothing known about base class 'A6'. Ignored. -cpp_inherit.i:26: Warning 401: Nothing known about base class 'A7< int >'. Ignored. -cpp_inherit.i:26: Warning 401: Maybe you forgot to instantiate 'A7< int >' using %template. -cpp_inherit.i:45: Warning 323: Recursive scope inheritance of 'Recursive'. -cpp_inherit.i:52: Warning 401: Base class 'Base< int >' has no name as it is an empty template instantiated with '%template()'. Ignored. -cpp_inherit.i:51: Warning 401: The %template directive must be written before 'Base< int >' is used as a base class and be declared with a name. -cpp_inherit.i:53: Warning 401: Base class 'Base< double >' undefined. -cpp_inherit.i:54: Warning 401: 'Base< double >' must be defined before it is used as a base class. - -:::::::::::::::::::::::::::::::: cpp_macro_locator.i ::::::::::::::::::::::::::::::::::: -cpp_macro_locator.i:66: Warning 204: CPP #warning, "inline warning message one". -cpp_macro_locator.i:96: Warning 204: CPP #warning, "an inline warning message 2". -cpp_macro_locator.i:53: Warning 509: Overloaded method overload1(int const *) effectively ignored, -cpp_macro_locator.i:52: Warning 509: as it is shadowed by overload1(int *). -cpp_macro_locator.i:61: Warning 509: Overloaded method overload2(int const *) effectively ignored, -cpp_macro_locator.i:60: Warning 509: as it is shadowed by overload2(int *). -cpp_macro_locator.i:64: Warning 509: Overloaded method Klass1::methodX(int const *) effectively ignored, -cpp_macro_locator.i:64: Warning 509: as it is shadowed by Klass1::methodX(int *). -cpp_macro_locator.i:68: Warning 509: Overloaded method overload3(int const *) effectively ignored, -cpp_macro_locator.i:67: Warning 509: as it is shadowed by overload3(int *). -cpp_macro_locator.i:90: Warning 509: Overloaded method overload4(int const *) effectively ignored, -cpp_macro_locator.i:89: Warning 509: as it is shadowed by overload4(int *). -cpp_macro_locator.i:94: Warning 509: Overloaded method overloadinline1(int const *) effectively ignored, -cpp_macro_locator.i:93: Warning 509: as it is shadowed by overloadinline1(int *). -cpp_macro_locator.i:95: Warning 509: Overloaded method Klass2::methodX(int const *) effectively ignored, -cpp_macro_locator.i:95: Warning 509: as it is shadowed by Klass2::methodX(int *). -cpp_macro_locator.i:98: Warning 509: Overloaded method overloadinline2(int const *) effectively ignored, -cpp_macro_locator.i:97: Warning 509: as it is shadowed by overloadinline2(int *). -cpp_macro_locator.i:101: Warning 509: Overloaded method overload5(int const *) effectively ignored, -cpp_macro_locator.i:100: Warning 509: as it is shadowed by overload5(int *). - -:::::::::::::::::::::::::::::::: cpp_missing_rparenthesis.i ::::::::::::::::::::::::::::::::::: -cpp_missing_rparenthesis.i:5: Error: Missing ')'. Reached end of input. -cpp_missing_rparenthesis.i:5: Error: Syntax error in input(3). - -:::::::::::::::::::::::::::::::: cpp_missing_rtemplate.i ::::::::::::::::::::::::::::::::::: -cpp_missing_rtemplate.i:4: Error: Syntax error in input(1). - -:::::::::::::::::::::::::::::::: cpp_namespace_alias.i ::::::::::::::::::::::::::::::::::: -cpp_namespace_alias.i:8: Warning 308: Namespace alias 'B' not allowed here. Assuming 'blah' - -:::::::::::::::::::::::::::::::: cpp_namespace_aliasnot.i ::::::::::::::::::::::::::::::::::: -cpp_namespace_aliasnot.i:4: Error: 'blah' is not a namespace - -:::::::::::::::::::::::::::::::: cpp_namespace_aliasundef.i ::::::::::::::::::::::::::::::::::: -cpp_namespace_aliasundef.i:3: Error: Unknown namespace 'blah' - -:::::::::::::::::::::::::::::::: cpp_nested_template.i ::::::::::::::::::::::::::::::::::: -cpp_nested_template.i:9: Warning 324: Named nested template instantiations not supported. Processing as if no name was given to %template(). -cpp_nested_template.i:18: Warning 324: Named nested template instantiations not supported. Processing as if no name was given to %template(). - -:::::::::::::::::::::::::::::::: cpp_no_access.i ::::::::::::::::::::::::::::::::::: -cpp_no_access.i:3: Warning 319: No access specifier given for base class 'foo' (ignored). - -:::::::::::::::::::::::::::::::: cpp_no_return_type.i ::::::::::::::::::::::::::::::::::: -cpp_no_return_type.i:6: Warning 504: Function S::R() must have a return type. Ignored. -cpp_no_return_type.i:10: Warning 504: Function U::UU() must have a return type. Ignored. - -:::::::::::::::::::::::::::::::: cpp_nobase.i ::::::::::::::::::::::::::::::::::: -cpp_nobase.i:3: Warning 401: Nothing known about base class 'Bar'. Ignored. -cpp_nobase.i:6: Warning 401: Nothing known about base class 'Bar< int >'. Ignored. -cpp_nobase.i:6: Warning 401: Maybe you forgot to instantiate 'Bar< int >' using %template. - -:::::::::::::::::::::::::::::::: cpp_overload.i ::::::::::::::::::::::::::::::::::: - -:::::::::::::::::::::::::::::::: cpp_overload_const.i ::::::::::::::::::::::::::::::::::: -cpp_overload_const.i:4: Warning 509: Overloaded method check(int *) effectively ignored, -cpp_overload_const.i:3: Warning 509: as it is shadowed by check(int const *). -cpp_overload_const.i:5: Warning 509: Overloaded method check(int &) effectively ignored, -cpp_overload_const.i:3: Warning 509: as it is shadowed by check(int const *). -cpp_overload_const.i:10: Warning 509: Overloaded method check(OverStruct *) effectively ignored, -cpp_overload_const.i:9: Warning 509: as it is shadowed by check(OverStruct const *). -cpp_overload_const.i:11: Warning 509: Overloaded method check(OverStruct &) effectively ignored, -cpp_overload_const.i:9: Warning 509: as it is shadowed by check(OverStruct const *). -cpp_overload_const.i:12: Warning 509: Overloaded method check(OverStruct const &) effectively ignored, -cpp_overload_const.i:9: Warning 509: as it is shadowed by check(OverStruct const *). - -:::::::::::::::::::::::::::::::: cpp_private_defvalue.i ::::::::::::::::::::::::::::::::::: - -:::::::::::::::::::::::::::::::: cpp_private_inherit.i ::::::::::::::::::::::::::::::::::: -cpp_private_inherit.i:6: Warning 309: private inheritance from base 'Foo' (ignored). -cpp_private_inherit.i:9: Warning 309: protected inheritance from base 'Foo' (ignored). - -:::::::::::::::::::::::::::::::: cpp_recursive_typedef.i ::::::::::::::::::::::::::::::::::: -:1: Error: Recursive typedef detected resolving 'pds *' to 'std::set< pds > *' to 'std::set< std::set< pds > > *' and so on... - -:::::::::::::::::::::::::::::::: cpp_shared_ptr.i ::::::::::::::::::::::::::::::::::: -cpp_shared_ptr.i:20: Warning 520: Base class 'A' of 'C' is not similarly marked as a smart pointer. -cpp_shared_ptr.i:24: Warning 520: Derived class 'D' of 'C' is not similarly marked as a smart pointer. -cpp_shared_ptr.i:24: Warning 520: Derived class 'D' of 'B' is not similarly marked as a smart pointer. - -:::::::::::::::::::::::::::::::: cpp_template_argname.i ::::::::::::::::::::::::::::::::::: - -:::::::::::::::::::::::::::::::: cpp_template_nargs.i ::::::::::::::::::::::::::::::::::: -cpp_template_nargs.i:5: Error: Template 'blah' undefined. -cpp_template_nargs.i:6: Error: Template 'blah' undefined. - -:::::::::::::::::::::::::::::::: cpp_template_not.i ::::::::::::::::::::::::::::::::::: -cpp_template_not.i:5: Error: 'blah' is not defined as a template. (cdecl) - -:::::::::::::::::::::::::::::::: cpp_template_partial.i ::::::::::::::::::::::::::::::::::: -cpp_template_partial.i:3: Warning 317: Specialization of non-template 'vector'. - -:::::::::::::::::::::::::::::::: cpp_template_repeat.i ::::::::::::::::::::::::::::::::::: - -:::::::::::::::::::::::::::::::: cpp_template_undef.i ::::::::::::::::::::::::::::::::::: -cpp_template_undef.i:3: Error: Template 'blah' undefined. - -:::::::::::::::::::::::::::::::: cpp_using_not.i ::::::::::::::::::::::::::::::::::: -cpp_using_not.i:4: Error: 'blah' is not a namespace. - -:::::::::::::::::::::::::::::::: cpp_using_undef.i ::::::::::::::::::::::::::::::::::: -cpp_using_undef.i:4: Error: Nothing known about namespace 'foo' -cpp_using_undef.i:3: Warning 315: Nothing known about 'foo::bar'. diff --git a/Examples/test-suite/errors/make.sh b/Examples/test-suite/errors/make.sh deleted file mode 100755 index 5f96897d9..000000000 --- a/Examples/test-suite/errors/make.sh +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/sh -echo "---------------------------------------" -echo "Testing SWIG error and warning messages" -echo "---------------------------------------" - -SWIG='../../../preinst-swig' - -# Files run in C mode -CFILES=' -c_bad_name -c_bad_native -c_class -c_default_error -c_deprecated -c_empty_char -c_enum_badvalue -c_extra_rblock -c_extra_rbrace -c_extra_unsigned -c_insert_missing -c_long_short -c_missing_rbrace -c_missing_semi -c_redefine -c_varargs -c_varargs_neg -nomodule -pp_badeval -pp_constant -pp_defined -pp_deprecated -pp_illegal_argument -pp_macro_args -pp_macro_badchar -pp_macro_defined_unterminated -pp_macro_expansion -pp_macro_expansion_multiline -pp_macro_inline_unterminated -pp_macro_missing_expression -pp_macro_unexpected_tokens -pp_macro_nargs -pp_macro_redef -pp_macro_rparen -pp_macro_unterminated -pp_misplaced_elif -pp_misplaced_else -pp_missing_enddef -pp_missing_endif -pp_missing_file -pp_missing_rblock -pp_pragma -pp_unterm_char -pp_unterm_comment -pp_unterm_string -pp_variable_args -swig_apply_nargs -swig_extend -swig_identifier -swig_insert_bad -swig_typemap_copy -swig_typemap_old -swig_typemap_warn -' - -# Files run in C++ mode -CPPFILES=' -cpp_bad_extern -cpp_extend_destructors -cpp_extend_redefine -cpp_extend_undefined -cpp_inline_namespace -cpp_inherit -cpp_macro_locator -cpp_missing_rparenthesis -cpp_missing_rtemplate -cpp_namespace_alias -cpp_namespace_aliasnot -cpp_namespace_aliasundef -cpp_nested_template -cpp_no_access -cpp_no_return_type -cpp_nobase -cpp_overload -cpp_overload_const -cpp_private_defvalue -cpp_private_inherit -cpp_recursive_typedef -cpp_shared_ptr -cpp_template_argname -cpp_template_nargs -cpp_template_not -cpp_template_partial -cpp_template_repeat -cpp_template_undef -cpp_using_not -cpp_using_undef -' - -LOGFILE='test.log' -SWIGOPT=$* - -rm -f ${LOGFILE} - -echo "SWIG error and warning test. opts=${SWIGOPT}" >> ${LOGFILE} -echo "-----------------------------------------------------------" >> ${LOGFILE} - -for i in ${CFILES}; do - echo " Testing : ${i}.i"; - echo "" >> ${LOGFILE}; - echo ":::::::::::::::::::::::::::::::: ${i}.i :::::::::::::::::::::::::::::::::::" >> ${LOGFILE}; - ${SWIG} -python -Wall ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1 -done - -for i in ${CPPFILES}; do - echo " Testing : ${i}.i"; - echo "" >> ${LOGFILE} - echo ":::::::::::::::::::::::::::::::: ${i}.i :::::::::::::::::::::::::::::::::::" >> ${LOGFILE}; - ${SWIG} -python -Wall -c++ ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1 -done - -echo "" -echo "Results written to '${LOGFILE}'" - - diff --git a/Examples/test-suite/errors/nomodule.stderr b/Examples/test-suite/errors/nomodule.stderr new file mode 100644 index 000000000..5f0bcbf7c --- /dev/null +++ b/Examples/test-suite/errors/nomodule.stderr @@ -0,0 +1 @@ +No module name specified using %module or -module. diff --git a/Examples/test-suite/errors/pp_badeval.stderr b/Examples/test-suite/errors/pp_badeval.stderr new file mode 100644 index 000000000..80f5037ea --- /dev/null +++ b/Examples/test-suite/errors/pp_badeval.stderr @@ -0,0 +1,2 @@ +pp_badeval.i:4: Warning 202: Could not evaluate expression 'FOO==4+' +pp_badeval.i:4: Warning 202: Error: 'Expected an expression' diff --git a/Examples/test-suite/errors/pp_constant.stderr b/Examples/test-suite/errors/pp_constant.stderr new file mode 100644 index 000000000..9c79ec2be --- /dev/null +++ b/Examples/test-suite/errors/pp_constant.stderr @@ -0,0 +1,8 @@ +pp_constant.i:9: Warning 305: Bad constant value (ignored). +pp_constant.i:15: Warning 305: Bad constant value (ignored). +pp_constant.i:23: Warning 305: Bad constant value (ignored). +pp_constant.i:29: Warning 305: Bad constant value (ignored). +pp_constant.i:35: Warning 305: Bad constant value (ignored). +pp_constant.i:42: Warning 305: Bad constant value (ignored). +pp_constant.i:46: Warning 305: Bad constant value (ignored). +pp_constant.i:49: Warning 305: Bad constant value (ignored). diff --git a/Examples/test-suite/errors/pp_defined.stderr b/Examples/test-suite/errors/pp_defined.stderr new file mode 100644 index 000000000..b707084e9 --- /dev/null +++ b/Examples/test-suite/errors/pp_defined.stderr @@ -0,0 +1,2 @@ +pp_defined.i:6: Error: No arguments given to defined() +pp_defined.i:6: Error: Missing expression for #if. diff --git a/Examples/test-suite/errors/pp_deprecated.stderr b/Examples/test-suite/errors/pp_deprecated.stderr new file mode 100644 index 000000000..6eff001ac --- /dev/null +++ b/Examples/test-suite/errors/pp_deprecated.stderr @@ -0,0 +1,4 @@ +pp_deprecated.i:4: Warning 101: %extern is deprecated. Use %import instead. +pp_deprecated.i:4: Error: Unable to find 'ext;' +pp_deprecated.i:6: Warning 204: CPP #warning, "Print this warning". +pp_deprecated.i:8: Error: CPP #error "This is an error". Use the -cpperraswarn option to continue swig processing. diff --git a/Examples/test-suite/errors/pp_illegal_argument.stderr b/Examples/test-suite/errors/pp_illegal_argument.stderr new file mode 100644 index 000000000..78995d805 --- /dev/null +++ b/Examples/test-suite/errors/pp_illegal_argument.stderr @@ -0,0 +1,3 @@ +pp_illegal_argument.i:6: Error: Illegal macro argument name '..' +pp_illegal_argument.i:10: Error: Illegal macro argument name '..' +pp_illegal_argument.i:16: Error: Illegal character in macro argument name diff --git a/Examples/test-suite/errors/pp_macro_args.stderr b/Examples/test-suite/errors/pp_macro_args.stderr new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/test-suite/errors/pp_macro_badchar.stderr b/Examples/test-suite/errors/pp_macro_badchar.stderr new file mode 100644 index 000000000..3c00583af --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_badchar.stderr @@ -0,0 +1 @@ +pp_macro_badchar.i:4: Error: Illegal character in macro argument name diff --git a/Examples/test-suite/errors/pp_macro_defined_unterminated.stderr b/Examples/test-suite/errors/pp_macro_defined_unterminated.stderr new file mode 100644 index 000000000..230175bf8 --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_defined_unterminated.stderr @@ -0,0 +1 @@ +pp_macro_defined_unterminated.i:4: Error: Unterminated call to 'defined' diff --git a/Examples/test-suite/errors/pp_macro_expansion.stderr b/Examples/test-suite/errors/pp_macro_expansion.stderr new file mode 100644 index 000000000..b8e718919 --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_expansion.stderr @@ -0,0 +1 @@ +pp_macro_expansion.i:9: Error: Macro 'MACRO2' expects 2 arguments diff --git a/Examples/test-suite/errors/pp_macro_expansion_multiline.stderr b/Examples/test-suite/errors/pp_macro_expansion_multiline.stderr new file mode 100644 index 000000000..bf5fbfbbf --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_expansion_multiline.stderr @@ -0,0 +1,4 @@ +pp_macro_expansion_multiline.i:13: Warning 509: Overloaded method foo(int const *) effectively ignored, +pp_macro_expansion_multiline.i:12: Warning 509: as it is shadowed by foo(int *). +pp_macro_expansion_multiline.i:31: Warning 509: Overloaded method bar(int const *) effectively ignored, +pp_macro_expansion_multiline.i:30: Warning 509: as it is shadowed by bar(int *). diff --git a/Examples/test-suite/errors/pp_macro_inline_unterminated.stderr b/Examples/test-suite/errors/pp_macro_inline_unterminated.stderr new file mode 100644 index 000000000..f7452de14 --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_inline_unterminated.stderr @@ -0,0 +1,2 @@ +pp_macro_inline_unterminated.i:9: Error: Unterminated call invoking macro 'foo' +pp_macro_inline_unterminated.i:12: Error: Syntax error in input(3). diff --git a/Examples/test-suite/errors/pp_macro_missing_expression.stderr b/Examples/test-suite/errors/pp_macro_missing_expression.stderr new file mode 100644 index 000000000..1e07b6542 --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_missing_expression.stderr @@ -0,0 +1,5 @@ +pp_macro_missing_expression.i:4: Error: Missing identifier for #ifdef. +pp_macro_missing_expression.i:7: Error: Missing identifier for #ifndef. +pp_macro_missing_expression.i:10: Error: Missing expression for #if. +pp_macro_missing_expression.i:14: Error: Missing expression for #elif. +pp_macro_missing_expression.i:21: Error: Missing expression for #elif. diff --git a/Examples/test-suite/errors/pp_macro_nargs.stderr b/Examples/test-suite/errors/pp_macro_nargs.stderr new file mode 100644 index 000000000..23e1bf439 --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_nargs.stderr @@ -0,0 +1,4 @@ +pp_macro_nargs.i:7: Error: Macro 'foo' expects 2 arguments +pp_macro_nargs.i:8: Error: Macro 'foo' expects 2 arguments +pp_macro_nargs.i:10: Error: Macro 'bar' expects 1 argument +pp_macro_nargs.i:11: Error: Macro 'spam' expects no arguments diff --git a/Examples/test-suite/errors/pp_macro_redef.stderr b/Examples/test-suite/errors/pp_macro_redef.stderr new file mode 100644 index 000000000..6de0ca4bc --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_redef.stderr @@ -0,0 +1,4 @@ +pp_macro_redef.i:4: Error: Macro 'foo' redefined, +pp_macro_redef.i:3: Error: previous definition of 'foo'. +pp_macro_redef.i:7: Error: Macro 'foo' redefined, +pp_macro_redef.i:3: Error: previous definition of 'foo'. diff --git a/Examples/test-suite/errors/pp_macro_rparen.stderr b/Examples/test-suite/errors/pp_macro_rparen.stderr new file mode 100644 index 000000000..755aeba48 --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_rparen.stderr @@ -0,0 +1 @@ +pp_macro_rparen.i:3: Error: Missing ')' in macro parameters diff --git a/Examples/test-suite/errors/pp_macro_unexpected_tokens.stderr b/Examples/test-suite/errors/pp_macro_unexpected_tokens.stderr new file mode 100644 index 000000000..d0efd9f12 --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_unexpected_tokens.stderr @@ -0,0 +1,5 @@ +pp_macro_unexpected_tokens.i:5: Warning 206: Unexpected tokens after #endif directive. +pp_macro_unexpected_tokens.i:8: Warning 206: Unexpected tokens after #endif directive. +pp_macro_unexpected_tokens.i:11: Warning 206: Unexpected tokens after #else directive. +pp_macro_unexpected_tokens.i:18: Warning 206: Unexpected tokens after #endif directive. +pp_macro_unexpected_tokens.i:21: Warning 206: Unexpected tokens after #else directive. diff --git a/Examples/test-suite/errors/pp_macro_unterminated.stderr b/Examples/test-suite/errors/pp_macro_unterminated.stderr new file mode 100644 index 000000000..a3ba264f5 --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_unterminated.stderr @@ -0,0 +1 @@ +pp_macro_unterminated.i:5: Error: Unterminated call invoking macro 'foo' diff --git a/Examples/test-suite/errors/pp_misplaced_elif.stderr b/Examples/test-suite/errors/pp_misplaced_elif.stderr new file mode 100644 index 000000000..06f1c457e --- /dev/null +++ b/Examples/test-suite/errors/pp_misplaced_elif.stderr @@ -0,0 +1,2 @@ +pp_misplaced_elif.i:4: Error: Misplaced #elif. +pp_misplaced_elif.i:6: Error: Extraneous #endif. diff --git a/Examples/test-suite/errors/pp_misplaced_else.stderr b/Examples/test-suite/errors/pp_misplaced_else.stderr new file mode 100644 index 000000000..455d90f0f --- /dev/null +++ b/Examples/test-suite/errors/pp_misplaced_else.stderr @@ -0,0 +1,2 @@ +pp_misplaced_else.i:4: Error: Misplaced #else. +pp_misplaced_else.i:6: Error: Extraneous #endif. diff --git a/Examples/test-suite/errors/pp_missing_enddef.stderr b/Examples/test-suite/errors/pp_missing_enddef.stderr new file mode 100644 index 000000000..bb4ea3c75 --- /dev/null +++ b/Examples/test-suite/errors/pp_missing_enddef.stderr @@ -0,0 +1 @@ +pp_missing_enddef.i:EOF: Error: Missing %enddef for macro starting on line 3 diff --git a/Examples/test-suite/errors/pp_missing_endif.stderr b/Examples/test-suite/errors/pp_missing_endif.stderr new file mode 100644 index 000000000..0bbfad7f2 --- /dev/null +++ b/Examples/test-suite/errors/pp_missing_endif.stderr @@ -0,0 +1 @@ +pp_missing_endif.i:EOF: Error: Missing #endif for conditional starting on line 3 diff --git a/Examples/test-suite/errors/pp_missing_file.stderr b/Examples/test-suite/errors/pp_missing_file.stderr new file mode 100644 index 000000000..2325a33fa --- /dev/null +++ b/Examples/test-suite/errors/pp_missing_file.stderr @@ -0,0 +1 @@ +pp_missing_file.i:3: Error: Unable to find 'missing_filename.i' diff --git a/Examples/test-suite/errors/pp_missing_rblock.stderr b/Examples/test-suite/errors/pp_missing_rblock.stderr new file mode 100644 index 000000000..8f4a54c0a --- /dev/null +++ b/Examples/test-suite/errors/pp_missing_rblock.stderr @@ -0,0 +1 @@ +pp_missing_rblock.i:EOF: Error: Unterminated %{ ... %} block starting on line 3 diff --git a/Examples/test-suite/errors/pp_pragma.stderr b/Examples/test-suite/errors/pp_pragma.stderr new file mode 100644 index 000000000..5f4526c42 --- /dev/null +++ b/Examples/test-suite/errors/pp_pragma.stderr @@ -0,0 +1 @@ +pp_pragma.i:4: Error: Unknown SWIG pragma: rubbish() diff --git a/Examples/test-suite/errors/pp_unterm_char.stderr b/Examples/test-suite/errors/pp_unterm_char.stderr new file mode 100644 index 000000000..4386e933d --- /dev/null +++ b/Examples/test-suite/errors/pp_unterm_char.stderr @@ -0,0 +1 @@ +pp_unterm_char.i:EOF: Error: Unterminated character constant starting at line 4 diff --git a/Examples/test-suite/errors/pp_unterm_comment.stderr b/Examples/test-suite/errors/pp_unterm_comment.stderr new file mode 100644 index 000000000..4ff34230c --- /dev/null +++ b/Examples/test-suite/errors/pp_unterm_comment.stderr @@ -0,0 +1 @@ +pp_unterm_comment.i:EOF: Error: Unterminated comment starting on line 3 diff --git a/Examples/test-suite/errors/pp_unterm_string.stderr b/Examples/test-suite/errors/pp_unterm_string.stderr new file mode 100644 index 000000000..16b4034f3 --- /dev/null +++ b/Examples/test-suite/errors/pp_unterm_string.stderr @@ -0,0 +1 @@ +pp_unterm_string.i:EOF: Error: Unterminated string constant starting at line 4 diff --git a/Examples/test-suite/errors/pp_variable_args.stderr b/Examples/test-suite/errors/pp_variable_args.stderr new file mode 100644 index 000000000..68d3fe580 --- /dev/null +++ b/Examples/test-suite/errors/pp_variable_args.stderr @@ -0,0 +1 @@ +pp_variable_args.i:6: Error: Variable length macro argument must be last parameter diff --git a/Examples/test-suite/errors/swig_apply_nargs.stderr b/Examples/test-suite/errors/swig_apply_nargs.stderr new file mode 100644 index 000000000..e0eff6d6a --- /dev/null +++ b/Examples/test-suite/errors/swig_apply_nargs.stderr @@ -0,0 +1 @@ +swig_apply_nargs.i:6: Error: Can't apply (char *str,int len) to (int x). Number of arguments don't match. diff --git a/Examples/test-suite/errors/swig_extend.stderr b/Examples/test-suite/errors/swig_extend.stderr new file mode 100644 index 000000000..aa42d7828 --- /dev/null +++ b/Examples/test-suite/errors/swig_extend.stderr @@ -0,0 +1,8 @@ +swig_extend.i:19: Warning 326: Deprecated %extend name used - the struct name 'StructBName' should be used instead of the typedef name 'StructB'. +swig_extend.i:45: Warning 326: Deprecated %extend name used - the struct name 'stru_struct' should be used instead of the typedef name 'stru'. +swig_extend.i:56: Warning 326: Deprecated %extend name used - the union name 'uni_union' should be used instead of the typedef name 'uni'. +swig_extend.i:34: Warning 303: %extend defined for an undeclared class StructDName. +swig_extend.i:50: Warning 522: Use of an illegal constructor name 'stru' in %extend is deprecated, the constructor name should be 'stru_struct'. +swig_extend.i:53: Warning 523: Use of an illegal destructor name 'stru' in %extend is deprecated, the destructor name should be 'stru_struct'. +swig_extend.i:57: Warning 522: Use of an illegal constructor name 'uni' in %extend is deprecated, the constructor name should be 'uni_union'. +swig_extend.i:58: Warning 523: Use of an illegal destructor name 'uni' in %extend is deprecated, the destructor name should be 'uni_union'. diff --git a/Examples/test-suite/errors/swig_identifier.stderr b/Examples/test-suite/errors/swig_identifier.stderr new file mode 100644 index 000000000..60ea5451b --- /dev/null +++ b/Examples/test-suite/errors/swig_identifier.stderr @@ -0,0 +1 @@ +swig_identifier.i:5: Warning 503: Can't wrap 'foo bar' unless renamed to a valid identifier. diff --git a/Examples/test-suite/errors/swig_insert_bad.stderr b/Examples/test-suite/errors/swig_insert_bad.stderr new file mode 100644 index 000000000..cb65c356d --- /dev/null +++ b/Examples/test-suite/errors/swig_insert_bad.stderr @@ -0,0 +1 @@ +swig_insert_bad.i:5: Error: Unknown target 'foobar' for %insert directive. diff --git a/Examples/test-suite/errors/swig_typemap_copy.stderr b/Examples/test-suite/errors/swig_typemap_copy.stderr new file mode 100644 index 000000000..a849e3162 --- /dev/null +++ b/Examples/test-suite/errors/swig_typemap_copy.stderr @@ -0,0 +1 @@ +swig_typemap_copy.i:3: Error: Can't copy typemap (in) blah = int diff --git a/Examples/test-suite/errors/swig_typemap_old.stderr b/Examples/test-suite/errors/swig_typemap_old.stderr new file mode 100644 index 000000000..23741164e --- /dev/null +++ b/Examples/test-suite/errors/swig_typemap_old.stderr @@ -0,0 +1,6 @@ +swig_typemap_old.i:6: Warning 450: Deprecated typemap feature ($source/$target). +swig_typemap_old.i:6: Warning 450: The use of $source and $target in a typemap declaration is deprecated. +For typemaps related to argument input (in,ignore,default,arginit,check), replace +$source by $input and $target by $1. For typemaps related to return values (out, +argout,ret,except), replace $source by $1 and $target by $result. See the file +Doc/Manual/Typemaps.html for complete details. diff --git a/Examples/test-suite/errors/swig_typemap_warn.stderr b/Examples/test-suite/errors/swig_typemap_warn.stderr new file mode 100644 index 000000000..5116dbc91 --- /dev/null +++ b/Examples/test-suite/errors/swig_typemap_warn.stderr @@ -0,0 +1,7 @@ +swig_typemap_warn.i:7: Warning 1000: Test warning for 'in' typemap for int abc (arg1) - argnum: 1 &1_ltype: int * descriptor: SWIGTYPE_int +swig_typemap_warn.i:7: Warning 1000: Test warning for 'in' typemap for int arg3 (arg3) - argnum: 3 &1_ltype: int * descriptor: SWIGTYPE_int +swig_typemap_warn.i:7: Warning 1001: Test warning for 'out' typemap for double mmm (result) - name: mmm symname: mmm &1_ltype: double * descriptor: SWIGTYPE_double +swig_typemap_warn.i:7: Warning 1000: Test warning for 'in' typemap for int abc (arg1) - argnum: 1 &1_ltype: int * descriptor: SWIGTYPE_int +swig_typemap_warn.i:7: Warning 1000: Test warning for 'in' typemap for int arg3 (arg3) - argnum: 3 &1_ltype: int * descriptor: SWIGTYPE_int +swig_typemap_warn.i:7: Warning 1000: Test warning for 'in' typemap for int abc (arg1) - argnum: 1 &1_ltype: int * descriptor: SWIGTYPE_int +swig_typemap_warn.i:7: Warning 1000: Test warning for 'in' typemap for int arg3 (arg3) - argnum: 3 &1_ltype: int * descriptor: SWIGTYPE_int diff --git a/Makefile.in b/Makefile.in index aa1c3d63f..ea7814242 100644 --- a/Makefile.in +++ b/Makefile.in @@ -89,6 +89,9 @@ skip-d = test -n "@SKIP_D@" skip-gcj = test -n "@SKIP_GCJ@" skip-android = test -n "@SKIP_ANDROID@" +# Special errors test-case +skip-errors = test -n "" + ##################################################################### # CHECK ##################################################################### @@ -249,6 +252,7 @@ java.actionexample: # Checks testcases in the test-suite excluding those which are known to be broken check-test-suite: \ + check-errors-test-suite \ check-tcl-test-suite \ check-perl5-test-suite \ check-python-test-suite \ diff --git a/configure.ac b/configure.ac index 3acc2aa9e..f048ccda5 100644 --- a/configure.ac +++ b/configure.ac @@ -2388,6 +2388,7 @@ AC_CONFIG_FILES([ \ Source/Makefile \ Examples/Makefile \ Examples/xml/Makefile \ + Examples/test-suite/errors/Makefile \ Examples/test-suite/chicken/Makefile \ Examples/test-suite/csharp/Makefile \ Examples/test-suite/d/Makefile \ From d7e614f71654d1ca744b96ce553e58bd447fbef7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 19 Jan 2014 00:23:42 +0000 Subject: [PATCH 0873/1160] Remove debug output on 'Empty character constant' error --- Source/CParse/cscanner.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index 4e02b4b62..de00e2b1f 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -315,7 +315,6 @@ static int yylook(void) { yylval.str = NewString(Scanner_text(scan)); if (Len(yylval.str) == 0) { Swig_error(cparse_file, cparse_line, "Empty character constant\n"); - Printf(stdout,"%d\n", Len(Scanner_text(scan))); } return CHARCONST; @@ -323,7 +322,6 @@ static int yylook(void) { yylval.str = NewString(Scanner_text(scan)); if (Len(yylval.str) == 0) { Swig_error(cparse_file, cparse_line, "Empty character constant\n"); - Printf(stdout,"%d\n", Len(Scanner_text(scan))); } return WCHARCONST; From e323d9d7b391e4a48fb15a5d8a089a293c7b3742 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 19 Jan 2014 20:45:22 +0000 Subject: [PATCH 0874/1160] Add 'make install' to Travis testing --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ad771df9c..46ffb9fd8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,6 +52,7 @@ script: - ./swig -version - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-ccache; fi - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-errors-test-suite; fi + - if test -z "$SWIGLANG"; then make -s install && swig -version && ccache-swig -version; fi - if test -n "$SWIGLANG"; then make -s check-$SWIGLANG-version; fi - if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-examples; fi - if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-test-suite; fi From af6bee1e8c39eb80ad54a021380f2af32902f99b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 19 Jan 2014 22:09:52 +0000 Subject: [PATCH 0875/1160] Travis build fixes for checking 'make install' --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 46ffb9fd8..fd0a95b94 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,6 +38,7 @@ before_install: - uname -a - sudo apt-get -qq update - time sudo apt-get -qq install libboost-dev + - if test -z "$SWIGLANG"; then sudo apt-get -qq install yodl; fi - if test "$SWIGLANG" = "csharp"; then sudo apt-get -qq install mono-devel; fi - if test "$SWIGLANG" = "go"; then go env | sed -e 's/^/export /' > goenvsetup && source goenvsetup && rm -f goenvsetup; fi # Until configure.ac is fixed - if test "$SWIGLANG" = "guile"; then sudo apt-get -qq install guile-2.0-dev; fi @@ -52,7 +53,7 @@ script: - ./swig -version - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-ccache; fi - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-errors-test-suite; fi - - if test -z "$SWIGLANG"; then make -s install && swig -version && ccache-swig -version; fi + - if test -z "$SWIGLANG"; then sudo make -s install && swig -version && ccache-swig -V; fi - if test -n "$SWIGLANG"; then make -s check-$SWIGLANG-version; fi - if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-examples; fi - if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-test-suite; fi From cc650e692e3e1201092d99a34a04e3af11ee2347 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 20 Jan 2014 19:40:52 +0000 Subject: [PATCH 0876/1160] Director exceptions now derive from std::exception --- CHANGES.current | 5 +++++ Lib/csharp/director.swg | 11 ++++++----- Lib/d/director.swg | 16 +++++++--------- Lib/java/director.swg | 4 ++-- Lib/ocaml/director.swg | 33 +++++++++++++++++---------------- Lib/octave/director.swg | 2 ++ Lib/perl5/director.swg | 29 +++++++++++++++-------------- Lib/php/director.swg | 19 ++++++++++++++----- Lib/python/director.swg | 28 ++++++++++++++++++---------- Lib/ruby/director.swg | 30 ++++++++++++++++++------------ 10 files changed, 104 insertions(+), 73 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 5dd602f35..68b34270a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-01-20: wsfulton + Director exceptions (Swig::DirectorException) now derive from std::exception + and hence provide the what() method. In Python and Ruby, this replaces the now + deprecated DirectorException::getMessage() method. + 2014-01-16: wsfulton [PHP] Fix compilation error in ZTS mode (64 bit windows) due to incorrect placement of TSRMLS_FETCH() in SWIG_Php_GetModule() as reported by Mark Dawson-Butterworth. diff --git a/Lib/csharp/director.swg b/Lib/csharp/director.swg index 403a0ac34..3438f2bf0 100644 --- a/Lib/csharp/director.swg +++ b/Lib/csharp/director.swg @@ -9,6 +9,7 @@ #include #endif #include +#include namespace Swig { /* Director base class - not currently used in C# directors */ @@ -16,7 +17,7 @@ namespace Swig { }; /* Base class for director exceptions */ - class DirectorException { + class DirectorException : public std::exception { protected: std::string swig_msg; @@ -27,16 +28,16 @@ namespace Swig { DirectorException(const std::string &msg) : swig_msg(msg) { } - const std::string& what() const { - return swig_msg; + virtual ~DirectorException() throw() { } - virtual ~DirectorException() { + const char *what() const throw() { + return swig_msg.c_str(); } }; /* Pure virtual method exception */ - class DirectorPureVirtualException : public Swig::DirectorException { + class DirectorPureVirtualException : public DirectorException { public: DirectorPureVirtualException(const char *msg) : DirectorException(std::string("Attempt to invoke pure virtual method ") + msg) { } diff --git a/Lib/d/director.swg b/Lib/d/director.swg index 6b6537103..a7d9c7688 100644 --- a/Lib/d/director.swg +++ b/Lib/d/director.swg @@ -9,6 +9,7 @@ #include #endif #include +#include namespace Swig { @@ -17,28 +18,25 @@ namespace Swig { }; // Base class for director exceptions. - class DirectorException { + class DirectorException : public std::exception { protected: std::string swig_msg; public: - DirectorException(const char *msg) : swig_msg(msg) { - } - DirectorException(const std::string &msg) : swig_msg(msg) { } - const std::string& what() const { - return swig_msg; + virtual ~DirectorException() throw() { } - virtual ~DirectorException() { + const char *what() const throw() { + return swig_msg.c_str(); } }; // Exception which is thrown when attempting to call a pure virtual method - // from D code thorugh the director layer. - class DirectorPureVirtualException : public Swig::DirectorException { + // from D code through the director layer. + class DirectorPureVirtualException : public DirectorException { public: DirectorPureVirtualException(const char *msg) : DirectorException(std::string("Attempted to invoke pure virtual method ") + msg) { } diff --git a/Lib/java/director.swg b/Lib/java/director.swg index 72f166406..819ad903d 100644 --- a/Lib/java/director.swg +++ b/Lib/java/director.swg @@ -1,8 +1,8 @@ /* ----------------------------------------------------------------------------- * director.swg * - * This file contains support for director classes that proxy - * method calls from C++ to Java extensions. + * This file contains support for director classes so that Java proxy + * methods can be called from C++. * ----------------------------------------------------------------------------- */ #if defined(DEBUG_DIRECTOR_OWNED) || defined(DEBUG_DIRECTOR_EXCEPTION) diff --git a/Lib/ocaml/director.swg b/Lib/ocaml/director.swg index 0f997acd0..fea0cada6 100644 --- a/Lib/ocaml/director.swg +++ b/Lib/ocaml/director.swg @@ -1,46 +1,47 @@ /* ----------------------------------------------------------------------------- * director.swg * - * This file contains support for director classes that proxy - * method calls from C++ to Ocaml extensions. - * + * This file contains support for director classes so that Ocaml proxy + * methods can be called from C++. * ----------------------------------------------------------------------------- */ #include +#include # define SWIG_DIRECTOR_CAST(ARG) dynamic_cast(ARG) namespace Swig { /* base class for director exceptions */ - class DirectorException { + class DirectorException : public std::exception { protected: std::string swig_msg; + public: - DirectorException(const char *msg="") { + DirectorException(const char *msg="") : swig_msg(msg) { } - const char *getMessage() const { + virtual ~DirectorException() throw() { + } + + const char *what() const throw() { return swig_msg.c_str(); } - - virtual ~DirectorException() { - } }; - /* type mismatch in the return value from a python method call */ - class DirectorTypeMismatchException : public Swig::DirectorException { + /* type mismatch in the return value from a Ocaml method call */ + class DirectorTypeMismatchException : public DirectorException { public: - DirectorTypeMismatchException(const char *msg="") { + DirectorTypeMismatchException(const char *msg="") : DirectorException(msg) { } }; - /* any python exception that occurs during a director method call */ - class DirectorMethodException : public Swig::DirectorException {}; + /* any Ocaml exception that occurs during a director method call */ + class DirectorMethodException : public DirectorException {}; /* attempt to call a pure virtual method via a director method */ - class DirectorPureVirtualException : public Swig::DirectorException { + class DirectorPureVirtualException : public DirectorException { public: - DirectorPureVirtualException(const char *msg="") { + DirectorPureVirtualException(const char *msg="") : DirectorException(msg) { } static void raise(const char *msg) { diff --git a/Lib/octave/director.swg b/Lib/octave/director.swg index 96bbf03cc..c399a6a89 100644 --- a/Lib/octave/director.swg +++ b/Lib/octave/director.swg @@ -7,6 +7,8 @@ # define SWIG_DIRECTOR_CAST(ARG) dynamic_cast(ARG) +#include + namespace Swig { class Director { diff --git a/Lib/perl5/director.swg b/Lib/perl5/director.swg index 9fa64e147..a66869725 100644 --- a/Lib/perl5/director.swg +++ b/Lib/perl5/director.swg @@ -1,8 +1,8 @@ /* ----------------------------------------------------------------------------- * director.swg * - * This file contains support for director classes that proxy - * method calls from C++ to Perl extensions. + * This file contains support for director classes so that Perl proxy + * methods can be called from C++. * ----------------------------------------------------------------------------- */ #ifndef SWIG_DIRECTOR_PERL_HEADER_ @@ -138,14 +138,13 @@ namespace Swig { }; /* base class for director exceptions */ - class DirectorException { + class DirectorException : public std::exception { public: - virtual const char *getMessage() const = 0; virtual SV *getNative() const = 0; }; /* exceptions emitted by Perl */ - class DirectorMethodException : public Swig::DirectorException { + class DirectorMethodException : public DirectorException { protected: SV *err; public: @@ -153,11 +152,7 @@ namespace Swig { SvREFCNT_inc(err); } - ~DirectorMethodException() { - SvREFCNT_dec(err); - } - - const char *getMessage() const { + const char *what() const throw() { return SvPV_nolen(err); } @@ -169,15 +164,19 @@ namespace Swig { throw DirectorMethodException(sv); } }; + /* exceptions emitted by wrap code */ - class DirectorWrapException : public Swig::DirectorException { + class DirectorWrapException : public DirectorException { protected: std::string msg; DirectorWrapException(const char *str) : msg(str) { } public: - virtual const char *getMessage() const { + virtual ~DirectorWrapException() throw() { + } + + const char *what() const throw() { return msg.c_str(); } @@ -186,10 +185,11 @@ namespace Swig { } }; - class DirectorTypeMismatchException : public Swig::DirectorWrapException { + class DirectorTypeMismatchException : public DirectorWrapException { public: DirectorTypeMismatchException(const char *str) : DirectorWrapException(str) { } + static void raise(const char *type, const char *msg) { std::string err = std::string(type); err += ": "; @@ -198,12 +198,13 @@ namespace Swig { } }; - class DirectorPureVirtualException : public Swig::DirectorWrapException { + class DirectorPureVirtualException : public DirectorWrapException { public: DirectorPureVirtualException(const char *name) : DirectorWrapException("SWIG director pure virtual method called: ") { msg += name; } + static void raise(const char *name) { throw DirectorPureVirtualException(name); } diff --git a/Lib/php/director.swg b/Lib/php/director.swg index 2b176ed09..50b433e47 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -1,14 +1,15 @@ /* ----------------------------------------------------------------------------- * director.swg * - * This file contains support for director classes that proxy - * method calls from C++ to PHP extensions. + * This file contains support for director classes so that PHP proxy + * methods can be called from C++. * ----------------------------------------------------------------------------- */ #ifndef SWIG_DIRECTOR_PHP_HEADER_ #define SWIG_DIRECTOR_PHP_HEADER_ #include +#include #include /* @@ -122,7 +123,7 @@ namespace Swig { }; /* base class for director exceptions */ - class DirectorException { + class DirectorException : public std::exception { protected: std::string swig_msg; public: @@ -135,13 +136,20 @@ namespace Swig { SWIG_ErrorMsg() = swig_msg.c_str(); } + virtual ~DirectorException() throw() { + } + + const char *what() const throw() { + return swig_msg.c_str(); + } + static void raise(int code, const char *hdr, const char *msg TSRMLS_DC) { throw DirectorException(code, hdr, msg TSRMLS_CC); } }; /* attempt to call a pure virtual method via a director method */ - class DirectorPureVirtualException : public Swig::DirectorException { + class DirectorPureVirtualException : public DirectorException { public: DirectorPureVirtualException(const char *msg TSRMLS_DC) : DirectorException(E_ERROR, "SWIG director pure virtual method called", msg TSRMLS_CC) { @@ -151,8 +159,9 @@ namespace Swig { throw DirectorPureVirtualException(msg TSRMLS_CC); } }; + /* any php exception that occurs during a director method call */ - class DirectorMethodException : public Swig::DirectorException + class DirectorMethodException : public DirectorException { public: DirectorMethodException(const char *msg TSRMLS_DC) diff --git a/Lib/python/director.swg b/Lib/python/director.swg index 3eac683f9..bca22af4e 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -1,8 +1,8 @@ /* ----------------------------------------------------------------------------- * director.swg * - * This file contains support for director classes that proxy - * method calls from C++ to Python extensions. + * This file contains support for director classes so that Python proxy + * methods can be called from C++. * ----------------------------------------------------------------------------- */ #ifndef SWIG_DIRECTOR_PYTHON_HEADER_ @@ -173,7 +173,7 @@ namespace Swig { }; /* base class for director exceptions */ - class DirectorException { + class DirectorException : public std::exception { protected: std::string swig_msg; public: @@ -184,12 +184,20 @@ namespace Swig { swig_msg += msg; } if (!PyErr_Occurred()) { - PyErr_SetString(error, getMessage()); + PyErr_SetString(error, what()); } SWIG_PYTHON_THREAD_END_BLOCK; } + virtual ~DirectorException() throw() { + } + + /* Deprecated, use what() instead */ const char *getMessage() const { + return what(); + } + + const char *what() const throw() { return swig_msg.c_str(); } @@ -210,7 +218,7 @@ namespace Swig { throw; } catch (DirectorException& e) { std::cerr << "SWIG Director exception caught:" << std::endl - << e.getMessage() << std::endl; + << e.what() << std::endl; } catch (std::exception& e) { std::cerr << "std::exception caught: "<< e.what() << std::endl; } catch (...) { @@ -243,14 +251,14 @@ namespace Swig { }; /* type mismatch in the return value from a python method call */ - class DirectorTypeMismatchException : public Swig::DirectorException { + class DirectorTypeMismatchException : public DirectorException { public: DirectorTypeMismatchException(PyObject *error, const char *msg="") - : Swig::DirectorException(error, "SWIG director type mismatch", msg) { + : DirectorException(error, "SWIG director type mismatch", msg) { } DirectorTypeMismatchException(const char *msg="") - : Swig::DirectorException(PyExc_TypeError, "SWIG director type mismatch", msg) { + : DirectorException(PyExc_TypeError, "SWIG director type mismatch", msg) { } static void raise(PyObject *error, const char *msg) { @@ -263,7 +271,7 @@ namespace Swig { }; /* any python exception that occurs during a director method call */ - class DirectorMethodException : public Swig::DirectorException { + class DirectorMethodException : public DirectorException { public: DirectorMethodException(const char *msg = "") : DirectorException(PyExc_RuntimeError, "SWIG director method error.", msg) { @@ -275,7 +283,7 @@ namespace Swig { }; /* attempt to call a pure virtual method via a director method */ - class DirectorPureVirtualException : public Swig::DirectorException { + class DirectorPureVirtualException : public DirectorException { public: DirectorPureVirtualException(const char *msg = "") : DirectorException(PyExc_RuntimeError, "SWIG director pure virtual method called", msg) { diff --git a/Lib/ruby/director.swg b/Lib/ruby/director.swg index 23aa6da48..3b1837374 100644 --- a/Lib/ruby/director.swg +++ b/Lib/ruby/director.swg @@ -1,8 +1,8 @@ /* ----------------------------------------------------------------------------- * director.swg * - * This file contains support for director classes that proxy - * method calls from C++ to Ruby extensions. + * This file contains support for director classes so that Ruby proxy + * methods can be called from C++. * ----------------------------------------------------------------------------- */ /* @@ -17,6 +17,7 @@ #include #include +#include #include # define SWIG_DIRECTOR_CAST(ARG) dynamic_cast(ARG) @@ -108,7 +109,7 @@ namespace Swig { }; /* Base class for director exceptions */ - class DirectorException { + class DirectorException : public std::exception { protected: VALUE swig_error; std::string swig_msg; @@ -130,6 +131,9 @@ namespace Swig { } public: + virtual ~DirectorException() throw() { + } + VALUE getType() const { return CLASS_OF(swig_error); } @@ -138,11 +142,13 @@ namespace Swig { return swig_error; } + /* Deprecated, use what() instead */ const std::string& getMessage() const { return swig_msg; } - virtual ~DirectorException() { + const char *what() const throw() { + return swig_msg.c_str(); } }; @@ -154,7 +160,7 @@ namespace Swig { throw; } catch (DirectorException& e) { std::cerr << "SWIG Director exception caught:" << std::endl - << e.getMessage() << std::endl; + << e.what() << std::endl; } catch (std::exception& e) { std::cerr << "std::exception caught: "<< e.what() << std::endl; } catch (...) { @@ -184,14 +190,14 @@ namespace Swig { /* Type mismatch in the return value from a Ruby method call */ - class DirectorTypeMismatchException : public Swig::DirectorException { + class DirectorTypeMismatchException : public DirectorException { public: DirectorTypeMismatchException(VALUE error, const char *msg="") - : Swig::DirectorException(error, "SWIG director type mismatch", msg) { + : DirectorException(error, "SWIG director type mismatch", msg) { } DirectorTypeMismatchException(const char *msg="") - : Swig::DirectorException(rb_eTypeError, "SWIG director type mismatch", msg) { + : DirectorException(rb_eTypeError, "SWIG director type mismatch", msg) { } static void raise(VALUE error, const char *msg) { @@ -204,14 +210,14 @@ namespace Swig { }; /* Any Ruby exception that occurs during a director method call */ - class DirectorMethodException : public Swig::DirectorException { + class DirectorMethodException : public DirectorException { public: DirectorMethodException(VALUE error) - : Swig::DirectorException(error) { + : DirectorException(error) { } DirectorMethodException(const char *msg = "") - : Swig::DirectorException(rb_eRuntimeError, "SWIG director method error.", msg) { + : DirectorException(rb_eRuntimeError, "SWIG director method error.", msg) { } static void raise(VALUE error) { @@ -220,7 +226,7 @@ namespace Swig { }; /* Attempted to call a pure virtual method via a director method */ - class DirectorPureVirtualException : public Swig::DirectorException + class DirectorPureVirtualException : public DirectorException { public: DirectorPureVirtualException(const char *msg = "") From 3785454a87eb2d4eaafcf0439cdc3da10efcbc02 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 21 Jan 2014 11:18:55 -0800 Subject: [PATCH 0877/1160] [Go] Add support for Go 1.3, not yet released. --- CHANGES.current | 3 +++ Examples/Makefile.in | 21 ++++++++++++++------- Examples/test-suite/go/Makefile.in | 7 ++++--- configure.ac | 10 ++++++++-- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 68b34270a..1945e9292 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-01-21: ianlancetaylor + [Go] Add support for Go 1.3, not yet released. + 2014-01-20: wsfulton Director exceptions (Swig::DirectorException) now derive from std::exception and hence provide the what() method. In Python and Ruby, this replaces the now diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 4c1a11ca4..fc17d8784 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1556,12 +1556,13 @@ GO = @GO@ GOGCC = @GOGCC@ GO1 = @GO1@ GO12 = @GO12@ +GO13 = @GO13@ GOC = @GOC@ GOOPT = @GOOPT@ GOVERSIONOPTION = @GOVERSIONOPTION@ GOSWIGARG = `if $(GOGCC) ; then echo -gccgo; fi` -GOCOMPILEARG = `if $(GOGCC) ; then echo -c -g; elif $(GO1) ; then echo tool $(GOC:c=g) ; fi` +GOCOMPILEARG = `if $(GOGCC) ; then echo -c -g; elif $(GO1) ; then echo tool $(GOC:c=g) ; fi` `if $(GO13) ; then echo -pack ; fi` GOSRCS = $(INTERFACE:.i=.go) GOCSRCS = $(INTERFACE:.i=_gc.c) @@ -1582,7 +1583,7 @@ GOGCCOBJS = $(GOSRCS:.go=.@OBJEXT@) go: $(SRCS) $(SWIG) -go $(GOOPT) $(GOSWIGARG) $(SWIGOPT) $(INTERFACEPATH) - if $(GO12) || $(GOGCC); then \ + if $(GO12) || $(GO13) || $(GOGCC); then \ $(CC) -g -c $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES); \ else \ $(CC) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES); \ @@ -1592,7 +1593,10 @@ go: $(SRCS) if ! $(GOGCC) ; then \ $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`} $(GOCSRCS); \ rm -f $(GOPACKAGE); \ - if $(GO12); then \ + if $(GO13); then \ + cp $(GOGCOBJS) $(GOPACKAGE); \ + $(COMPILETOOL) $(GOPACK) r $(GOPACKAGE) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \ + elif $(GO12); then \ $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \ else \ $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ @@ -1602,7 +1606,7 @@ go: $(SRCS) $(GO) $(GOCOMPILEARG) $(RUNME).go; \ if $(GOGCC) ; then \ $(COMPILETOOL) $(GO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS); \ - elif $(GO12); then \ + elif $(GO12) || $(GO13); then \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CC) -extldflags "$(CFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \ else \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \ @@ -1615,7 +1619,7 @@ go: $(SRCS) go_cpp: $(SRCS) $(SWIG) -go -c++ $(GOOPT) $(GOSWIGARG) $(SWIGOPT) $(INTERFACEPATH) - if $(GO12) || $(GOGCC); then \ + if $(GO12) || $(GO13) || $(GOGCC); then \ $(CXX) -g -c $(CXXFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES); \ else \ $(CXX) -g -c $(CCSHARED) $(CXXFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES); \ @@ -1625,7 +1629,10 @@ go_cpp: $(SRCS) if ! $(GOGCC) ; then \ $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`} $(GOCSRCS); \ rm -f $(GOPACKAGE); \ - if $(GO12); then \ + if $(GO13); then \ + cp $(GOGCOBJS) $(GOPACKAGE); \ + $(COMPILETOOL) $(GOPACK) r $(GOPACKAGE) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \ + elif $(GO12); then \ $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \ else \ $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ @@ -1635,7 +1642,7 @@ go_cpp: $(SRCS) $(GO) $(GOCOMPILEARG) $(RUNME).go; \ if $(GOGCC) ; then \ $(COMPILETOOL) $(GO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS) -lstdc++; \ - elif $(GO12); then \ + elif $(GO12) || $(GO13); then \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \ else \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \ diff --git a/Examples/test-suite/go/Makefile.in b/Examples/test-suite/go/Makefile.in index 35937bcdb..535d05a6e 100644 --- a/Examples/test-suite/go/Makefile.in +++ b/Examples/test-suite/go/Makefile.in @@ -7,6 +7,7 @@ GO = @GO@ GOGCC = @GOGCC@ GO1 = @GO1@ GO12 = @GO12@ +GO13 = @GO13@ GOC = @GOC@ SCRIPTSUFFIX = _runme.go @@ -60,7 +61,7 @@ run_testcase = \ $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ if $(GOGCC) ; then \ $(COMPILETOOL) $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.@OBJEXT@ $*_wrap.@OBJEXT@; \ - elif $(GO12); then \ + elif $(GO12) || $(GO13); then \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CC) -extldflags "$(CFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ else \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ @@ -73,7 +74,7 @@ run_testcase_cpp = \ $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ if $(GOGCC) ; then \ $(COMPILETOOL) $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.@OBJEXT@ $*_wrap.@OBJEXT@ -lstdc++; \ - elif $(GO12); then \ + elif $(GO12) || $(GO13); then \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ else \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ @@ -87,7 +88,7 @@ run_multi_testcase = \ if $(GOGCC) ; then \ files=`cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list`; \ $(COMPILETOOL) $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ `for f in $$files; do echo $$f.@OBJEXT@ $${f}_wrap.@OBJEXT@; done` -lstdc++; \ - elif $(GO12); then \ + elif $(GO12) || $(GO13); then \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ else \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ diff --git a/configure.ac b/configure.ac index f048ccda5..03677f90d 100644 --- a/configure.ac +++ b/configure.ac @@ -1997,6 +1997,7 @@ if test x"${GOBIN}" = xno -o x"${with_alllang}" = xno ; then GOC= GO1=false GO12=false + GO13=false GOGCC=false GOOPT= GOVERSIONOPTION= @@ -2011,6 +2012,7 @@ else GOGCC=false GO1=false GO12=false + GO13=false GOOPT= GOVERSIONOPTION= if test -n "$GO" ; then @@ -2050,12 +2052,14 @@ else esac case $go_version in go1.0* | go1.1*) - GO12=false GOOPT="$GOOPT -use-shlib" ;; - *) + go1.2*) GO12=true ;; + *) + GO13=true + ;; esac else GOC=`echo $GO | sed -e 's/g/c/'` @@ -2071,6 +2075,7 @@ else fi GOOPT="-intgosize 32" GO12=false + GO13=false fi fi fi @@ -2080,6 +2085,7 @@ AC_SUBST(GO) AC_SUBST(GOC) AC_SUBST(GO1) AC_SUBST(GO12) +AC_SUBST(GO13) AC_SUBST(GOOPT) AC_SUBST(GOVERSIONOPTION) From f2dc3a9c1f1e2ef5242be594c5cee6502b3e2547 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 21 Jan 2014 11:27:09 -0800 Subject: [PATCH 0878/1160] [Go] Add %go_import directive. --- CHANGES.current | 3 +++ Doc/Manual/Go.html | 30 +++++++++++++++++++++++++---- Lib/go/go.swg | 3 +++ Lib/go/goruntime.swg | 22 +++++++++------------ Source/Modules/go.cxx | 45 +++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 84 insertions(+), 19 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 1945e9292..ca7503d41 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-01-21: ianlancetaylor + [Go] Add %go_import directive. + 2014-01-21: ianlancetaylor [Go] Add support for Go 1.3, not yet released. diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 43bfc6971..240db2b61 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -666,9 +666,31 @@ func (arg SwigcptrWrapped_MyClass) GetAValue() (int, bool) { few, then you might as well define your own struct that includes the swig-wrapped object, instead of adding methods to the swig-generated object.

    -

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

    +

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

    +
    +
    +%go_import("fmt", _ "unusedPackage", rp "renamed/package")
    +
    +%insert(go_wrapper) %{
    +
    +func foo() {
    +  fmt.Println("Some string:", rp.GetString())
    +}
    +
    +// Importing the same package twice is permitted,
    +// Go code will be generated with only the first instance of the import.
    +%go_import("fmt")
    +
    +%insert(go_wrapper) %{
    +
    +func bar() {
    +  fmt.Println("Hello world!")
    +}
    +
    +%}
    +
    +
    + diff --git a/Lib/go/go.swg b/Lib/go/go.swg index b9086caac..c9dc34361 100644 --- a/Lib/go/go.swg +++ b/Lib/go/go.swg @@ -4,6 +4,9 @@ * Go configuration module. * ------------------------------------------------------------ */ +/* Code insertion directives */ +#define %go_import(...) %insert(go_imports) %{__VA_ARGS__%} + /* Basic types */ %typemap(gotype) bool, const bool & "bool" diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index 3e639cdc2..612f83086 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -192,30 +192,26 @@ static _gostring_ _swig_makegostring(const char *p, size_t l) { #ifndef SWIGGO_GCCGO -%insert(go_header) %{ - -import _ "runtime/cgo" -import "unsafe" - -type _ unsafe.Pointer - -%} +%go_import("unsafe", _ "runtime/cgo") #else +%go_import("syscall", "unsafe") + %insert(go_header) %{ -import "syscall" -import "unsafe" - type _ syscall.Sockaddr -type _ unsafe.Pointer - %} #endif +%insert(go_header) %{ + +type _ unsafe.Pointer + +%} + /* Function pointers are translated by the code in go.cxx into _swig_fnptr. Member pointers are translated to _swig_memberptr. */ diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 36e5d11d3..77c5418d2 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -45,6 +45,7 @@ class GO:public Language { File *f_c_init; File *f_c_directors; File *f_c_directors_h; + File *f_go_imports; File *f_go_runtime; File *f_go_header; File *f_go_wrappers; @@ -84,6 +85,9 @@ class GO:public Language { // A hash table of classes which were defined. The index is a Go // type name. Hash *defined_types; + // A hash table of all the go_imports already imported. The index is a full + // import name e.g. '"runtime"' or '_ "runtime/cgo"' or 'sc "syscall"'. + Hash *go_imports; public: GO():package(NULL), @@ -104,6 +108,7 @@ public: f_c_init(NULL), f_c_directors(NULL), f_c_directors_h(NULL), + f_go_imports(NULL), f_go_runtime(NULL), f_go_header(NULL), f_go_wrappers(NULL), @@ -120,7 +125,8 @@ public: making_variable_wrappers(false), is_static_member_function(false), undefined_types(NULL), - defined_types(NULL) { + defined_types(NULL), + go_imports(NULL) { director_multiple_inheritance = 1; director_language = 1; director_prot_ctor_code = NewString("_swig_gopanic(\"accessing abstract class or protected constructor\");"); @@ -362,6 +368,7 @@ private: f_c_wrappers = NewString(""); f_c_init = NewString(""); f_c_directors = NewString(""); + f_go_imports = NewString(""); f_go_runtime = NewString(""); f_go_header = NewString(""); f_go_wrappers = NewString(""); @@ -379,6 +386,7 @@ private: 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_imports", f_go_imports); Swig_register_filebyname("go_runtime", f_go_runtime); Swig_register_filebyname("go_header", f_go_header); Swig_register_filebyname("go_wrapper", f_go_wrappers); @@ -445,11 +453,14 @@ private: undefined_types = NewHash(); defined_types = NewHash(); + go_imports = NewHash(); // Emit code. Language::top(n); + Delete(go_imports); + // Write out definitions for the types not defined by SWIG. Printv(f_go_wrappers, "\n", NULL); @@ -493,6 +504,7 @@ private: Dump(f_c_runtime, f_c_begin); Dump(f_c_wrappers, f_c_begin); Dump(f_c_init, f_c_begin); + Dump(f_go_imports, f_go_begin); Dump(f_go_header, f_go_begin); Dump(f_go_runtime, f_go_begin); Dump(f_go_wrappers, f_go_begin); @@ -506,6 +518,7 @@ private: Delete(f_c_header); Delete(f_c_wrappers); Delete(f_c_init); + Delete(f_go_imports); Delete(f_go_runtime); Delete(f_go_header); Delete(f_go_wrappers); @@ -535,7 +548,10 @@ private: String *hold_import = imported_package; String *modname = Getattr(n, "module"); if (modname) { - Printv(f_go_begin, "import \"", modname, "\"\n", NULL); + if (!Getattr(go_imports, modname)) { + Setattr(go_imports, modname, modname); + Printv(f_go_imports, "import \"", modname, "\"\n", NULL); + } imported_package = modname; saw_import = true; } @@ -544,6 +560,31 @@ private: return r; } + /* ---------------------------------------------------------------------- + * Language::insertDirective() + * + * If the section is go_imports, store them for later. + * ---------------------------------------------------------------------- */ + virtual int insertDirective(Node *n) { + char *section = Char(Getattr(n, "section")); + if ((ImportMode && !Getattr(n, "generated")) || + !section || (strcmp(section, "go_imports") != 0)) { + return Language::insertDirective(n); + } + + char *code = Char(Getattr(n, "code")); + char *pch = strtok(code, ","); + while (pch != NULL) { + // Do not import same thing more than once. + if (!Getattr(go_imports, pch)) { + Setattr(go_imports, pch, pch); + Printv(f_go_imports, "import ", pch, "\n", NULL); + } + pch = strtok(NULL, ","); + } + return SWIG_OK; + } + /* ---------------------------------------------------------------------- * functionWrapper() * From fa9a6d58ede53813c981c941e2c51a792a239a6d Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 27 Jan 2014 17:49:35 -0800 Subject: [PATCH 0879/1160] [Go] Fix handling of C type "long" on 32-bit systems. It was broken for C++ long& and for big-endian systems in general. --- Lib/go/go.swg | 7 +++++-- Source/Modules/go.cxx | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Lib/go/go.swg b/Lib/go/go.swg index c9dc34361..0c03ae576 100644 --- a/Lib/go/go.swg +++ b/Lib/go/go.swg @@ -48,14 +48,17 @@ 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(in) const long & ($*1_ltype temp), + const unsigned long & ($*1_ltype temp) +%{ temp = ($*1_ltype)$input; + $1 = ($1_ltype)&temp; %} + %typemap(out) bool, char, signed char, diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 77c5418d2..2f28fcb03 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -4794,6 +4794,9 @@ private: if (is_int) { ret = NewString("intgo "); Append(ret, name); + } else if (is_int64) { + ret = NewString("long long "); + Append(ret, name); } else { ret = SwigType_lstr(t, name); } From 7c5275a0f146faa2127526eba9ecb58ea1935ced Mon Sep 17 00:00:00 2001 From: Marvin Greenberg Date: Thu, 30 Jan 2014 16:17:30 -0500 Subject: [PATCH 0880/1160] Make sure tests are built with same stdlib flag as used to configure swig --- Examples/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index fc17d8784..7680908ab 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -25,7 +25,7 @@ TARGET = CC = @CC@ CXX = @CXX@ CFLAGS = @PLATCFLAGS@ -CXXFLAGS = @BOOST_CPPFLAGS@ @PLATCXXFLAGS@ +CXXFLAGS = @BOOST_CPPFLAGS@ @PLATCXXFLAGS@ $(filter -stdlib%,@CXXFLAGS@) prefix = @prefix@ exec_prefix= @exec_prefix@ SRCS = From 9fd42e0e67701795e3b9017084e36298158ef39b Mon Sep 17 00:00:00 2001 From: Marvin Greenberg Date: Thu, 30 Jan 2014 16:18:21 -0500 Subject: [PATCH 0881/1160] Work around clang bugs with symbol resolution --- Examples/test-suite/nested_scope.i | 12 +++- ..._using_directive_and_declaration_forward.i | 58 ++++++++++++++++++ .../using_directive_and_declaration_forward.i | 60 +++++++++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/nested_scope.i b/Examples/test-suite/nested_scope.i index 358dbbb61..04945a7b6 100644 --- a/Examples/test-suite/nested_scope.i +++ b/Examples/test-suite/nested_scope.i @@ -3,12 +3,22 @@ %inline %{ namespace ns { struct Global { +#ifdef __clang__ + struct Outer { + struct Nested; + struct Nested { + int data; + }; + }; + struct Outer::Nested instance; +#else struct Outer { struct Nested; }; struct Outer::Nested { int data; } instance; +#endif }; } -%} \ No newline at end of file +%} diff --git a/Examples/test-suite/template_using_directive_and_declaration_forward.i b/Examples/test-suite/template_using_directive_and_declaration_forward.i index a5a7fbf31..dcc1d6ab4 100644 --- a/Examples/test-suite/template_using_directive_and_declaration_forward.i +++ b/Examples/test-suite/template_using_directive_and_declaration_forward.i @@ -9,7 +9,15 @@ namespace Outer1 { } using namespace Outer1::Space1; using Outer1::Space1::Thing1; +#ifdef __clang__ +namespace Outer1 { + namespace Space1 { + template class Thing1 {}; + } +} +#else template class Thing1 {}; +#endif void useit1(Thing1 t) {} void useit1a(Outer1::Space1::Thing1 t) {} void useit1b(::Outer1::Space1::Thing1 t) {} @@ -25,7 +33,15 @@ namespace Outer2 { } using namespace Outer2; using Space2::Thing2; +#ifdef __clang__ +namespace Outer2 { + namespace Space2 { + template class Thing2 {}; + } +} +#else template class Thing2 {}; +#endif void useit2(Thing2 t) {} void useit2a(Outer2::Space2::Thing2 t) {} void useit2b(::Outer2::Space2::Thing2 t) {} @@ -45,7 +61,17 @@ namespace Outer3 { using namespace Outer3; using namespace Space3; using Middle3::Thing3; +#ifdef __clang__ +namespace Outer3 { + namespace Space3 { + namespace Middle3 { + template class Thing3 {}; + } + } +} +#else template class Thing3 {}; +#endif void useit3(Thing3 t) {} void useit3a(Outer3::Space3::Middle3::Thing3 t) {} void useit3b(::Outer3::Space3::Middle3::Thing3 t) {} @@ -66,7 +92,17 @@ namespace Outer4 { } using namespace Outer4::Space4; using Middle4::Thing4; +#ifdef __clang__ +namespace Outer4 { + namespace Space4 { + namespace Middle4 { + template class Thing4 {}; + } + } +} +#else template class Thing4 {}; +#endif void useit4(Thing4 t) {} void useit4a(Outer4::Space4::Middle4::Thing4 t) {} void useit4b(::Outer4::Space4::Middle4::Thing4 t) {} @@ -90,7 +126,19 @@ namespace Outer5 { using namespace ::Outer5::Space5; using namespace Middle5; using More5::Thing5; +#ifdef __clang__ +namespace Outer5 { + namespace Space5 { + namespace Middle5 { + namespace More5 { + template class Thing5 {}; + } + } + } +} +#else template class Thing5 {}; +#endif void useit5(Thing5 t) {} void useit5a(Outer5::Space5::Middle5::More5::Thing5 t) {} void useit5b(::Outer5::Space5::Middle5::More5::Thing5 t) {} @@ -109,7 +157,17 @@ namespace Outer7 { } } using namespace Outer7::Space7; +#ifdef __clang__ +namespace Outer7 { + namespace Space7 { + namespace Middle7 { + template class Thing7 {}; + } + } +} +#else template class Middle7::Thing7 {}; +#endif using Middle7::Thing7; void useit7(Thing7 t) {} void useit7a(Outer7::Space7::Middle7::Thing7 t) {} diff --git a/Examples/test-suite/using_directive_and_declaration_forward.i b/Examples/test-suite/using_directive_and_declaration_forward.i index 238b3b77f..1f219e671 100644 --- a/Examples/test-suite/using_directive_and_declaration_forward.i +++ b/Examples/test-suite/using_directive_and_declaration_forward.i @@ -9,7 +9,15 @@ namespace Outer1 { } using namespace Outer1::Space1; using Outer1::Space1::Thing1; +#ifdef __clang__ +namespace Outer1 { + namespace Space1 { + class Thing1 {}; + } +} +#else class Thing1 {}; +#endif void useit1(Thing1 t) {} void useit1a(Outer1::Space1::Thing1 t) {} void useit1b(::Outer1::Space1::Thing1 t) {} @@ -25,7 +33,17 @@ namespace Outer2 { } using namespace Outer2; using Space2::Thing2; +using namespace Outer1::Space1; +using Outer1::Space1::Thing1; +#ifdef __clang__ +namespace Outer2 { + namespace Space2 { + class Thing2 {}; + } +} +#else class Thing2 {}; +#endif void useit2(Thing2 t) {} void useit2a(Outer2::Space2::Thing2 t) {} void useit2b(::Outer2::Space2::Thing2 t) {} @@ -45,7 +63,17 @@ namespace Outer3 { using namespace Outer3; using namespace Space3; using Middle3::Thing3; +#ifdef __clang__ +namespace Outer3 { + namespace Space3 { + namespace Middle3 { + class Thing3 {}; + } + } +} +#else class Thing3 {}; +#endif void useit3(Thing3 t) {} void useit3a(Outer3::Space3::Middle3::Thing3 t) {} void useit3b(::Outer3::Space3::Middle3::Thing3 t) {} @@ -66,7 +94,17 @@ namespace Outer4 { } using namespace Outer4::Space4; using Middle4::Thing4; +#ifdef __clang__ +namespace Outer4 { + namespace Space4 { + namespace Middle4 { + class Thing4 {}; + } + } +} +#else class Thing4 {}; +#endif void useit4(Thing4 t) {} void useit4a(Outer4::Space4::Middle4::Thing4 t) {} void useit4b(::Outer4::Space4::Middle4::Thing4 t) {} @@ -90,7 +128,19 @@ namespace Outer5 { using namespace ::Outer5::Space5; using namespace Middle5; using More5::Thing5; +#ifdef __clang__ +namespace Outer5 { + namespace Space5 { + namespace Middle5 { + namespace More5 { + class Thing5 {}; + } + } + } +} +#else class Thing5 {}; +#endif void useit5(Thing5 t) {} void useit5a(Outer5::Space5::Middle5::More5::Thing5 t) {} void useit5b(::Outer5::Space5::Middle5::More5::Thing5 t) {} @@ -109,7 +159,17 @@ namespace Outer7 { } } using namespace Outer7::Space7; +#ifdef __clang__ +namespace Outer7 { + namespace Space7 { + namespace Middle7 { + class Thing7 {}; + } + } +} +#else class Middle7::Thing7 {}; +#endif using Middle7::Thing7; void useit7(Thing7 t) {} void useit7a(Outer7::Space7::Middle7::Thing7 t) {} From a1fe8a6501abb2f9592681a035bc3a8b22b9738c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 1 Feb 2014 15:00:15 +0100 Subject: [PATCH 0882/1160] Fix gcc strict aliasing warnings with function pointers too. The commit 40bf877 fixed warnings about converting between function and object pointers but introduced warnings about breaking strict-aliasing rules which appear with -Wstrict-aliasing which is implicitly enabled by -O2. Avoid these warnings as well by using an intermediate union for conversion instead of casts trickery. --- Source/DOH/base.c | 9 +++++---- Source/DOH/doh.h | 6 ++++++ Source/DOH/fio.c | 13 +++++++++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Source/DOH/base.c b/Source/DOH/base.c index e84731cd0..4034e5626 100644 --- a/Source/DOH/base.c +++ b/Source/DOH/base.c @@ -947,11 +947,12 @@ int DohGetmark(DOH *ho) { DOH *DohCall(DOH *func, DOH *args) { DOH *result; - DOH *(*builtin) (DOH *); + DohFuncPtr_t builtin; - *(void **)(&builtin) = GetVoid(func, "builtin"); - if (!builtin) + builtin.p = GetVoid(func, "builtin"); + + if (!builtin.p) return 0; - result = (*builtin) (args); + result = (*builtin.func) (args); return result; } diff --git a/Source/DOH/doh.h b/Source/DOH/doh.h index 8071edd4d..5a9bae2b3 100644 --- a/Source/DOH/doh.h +++ b/Source/DOH/doh.h @@ -336,6 +336,12 @@ extern DOHList *DohSplit(DOHFile * input, char ch, int nsplits); extern DOHList *DohSplitLines(DOHFile * input); extern DOH *DohNone; +/* Helper union for converting between function and object pointers. */ +typedef union DohFuncPtr { + void* p; + DOH *(*func)(DOH *); +} DohFuncPtr_t; + extern void DohMemoryDebug(void); #ifndef DOH_LONG_NAMES diff --git a/Source/DOH/fio.c b/Source/DOH/fio.c index 71ce30149..7055ffc85 100644 --- a/Source/DOH/fio.c +++ b/Source/DOH/fio.c @@ -46,15 +46,19 @@ static int Writen(DOH *out, void *buffer, int len) { * ----------------------------------------------------------------------------- */ void DohEncoding(const char *name, DOH *(*fn) (DOH *s)) { + DohFuncPtr_t fp; + if (!encodings) encodings = NewHash(); - Setattr(encodings, (void *) name, NewVoid(*(void **)&fn, 0)); + + fp.func = fn; + Setattr(encodings, (void *) name, NewVoid(fp.p, 0)); } /* internal function for processing an encoding */ static DOH *encode(char *name, DOH *s) { DOH *handle, *ns; - DOH *(*fn) (DOH *); + DohFuncPtr_t fp; long pos; char *cfmt = strchr(name, ':'); DOH *tmp = 0; @@ -72,8 +76,9 @@ static DOH *encode(char *name, DOH *s) { s = tmp; pos = Tell(s); Seek(s, 0, SEEK_SET); - *(void **)(&fn) = Data(handle); - ns = (*fn) (s); + + fp.p = Data(handle); + ns = (*fp.func) (s); assert(pos != -1); (void)Seek(s, pos, SEEK_SET); if (tmp) From 2f3d93e93afaa9bf68ac83cb5614511000433247 Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Sun, 2 Feb 2014 22:38:13 +0400 Subject: [PATCH 0883/1160] Nested classes support is diversified, depending on the language capability. If the language cannot support nested classes, they will be unconditionally moved to the global namespace. If language module does not override Language::nestedClassesSupport() function, nested classes will be ignored, unless "feature:flatnested" is used. --- Source/CParse/parser.y | 48 +++++++++++++++++++++++++------------ Source/Include/swigwarn.h | 1 + Source/Modules/csharp.cxx | 4 ++-- Source/Modules/java.cxx | 4 ++-- Source/Modules/lang.cxx | 4 ++-- Source/Modules/main.cxx | 13 ++++------ Source/Modules/nested.cxx | 4 ++-- Source/Modules/swigmod.h | 18 +++++++++----- Source/Modules/typepass.cxx | 3 ++- 9 files changed, 60 insertions(+), 39 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index fe8b7f97f..0f2cfdec9 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -59,7 +59,7 @@ static int extendmode = 0; static int compact_default_args = 0; static int template_reduce = 0; static int cparse_externc = 0; - +int ignore_nested_classes = 0; /* ----------------------------------------------------------------------------- * Assist Functions * ----------------------------------------------------------------------------- */ @@ -3564,19 +3564,26 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Namespaceprefix = Swig_symbol_qualifiedscopename(0); yyrename = Copy(Getattr($$, "class_rename")); add_symbols($$); - Delattr($$, "class_rename"); - /* but the variable definition in the current scope */ - Swig_symbol_setscope(cscope); - Delete(Namespaceprefix); - Namespaceprefix = Swig_symbol_qualifiedscopename(0); - add_symbols($9); - if (nscope) { - $$ = nscope; /* here we return recreated namespace tower instead of the class itself */ - if ($9) - appendSibling($$, $9); + if (currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) { + SetFlag($$,"feature:ignore"); + Swig_warning(WARN_PARSE_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", Getattr($$, "name")); + $$ = 0; + } else { + Delattr($$, "class_rename"); + /* but the variable definition in the current scope */ + Swig_symbol_setscope(cscope); + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); + add_symbols($9); + if (nscope) { + $$ = nscope; /* here we return recreated namespace tower instead of the class itself */ + if ($9) { + appendSibling($$, $9); + } + } else if (!SwigType_istemplate(ty) && template_parameters == 0) { /* for tempalte we need the class itself */ + $$ = $9; + } } - else if (!SwigType_istemplate(ty) && template_parameters == 0) /* for tempalte we need the class itself */ - $$ = $9; } else { Delete(yyrename); yyrename = 0; @@ -3600,8 +3607,14 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { } else { yyrename = Copy(Getattr($$, "class_rename")); add_symbols($$); - add_symbols($9); - Delattr($$, "class_rename"); + if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) { + SetFlag($$,"feature:ignore"); + Swig_warning(WARN_PARSE_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", Getattr($$, "name")); + $$ = 0; + } else { + add_symbols($9); + Delattr($$, "class_rename"); + } } } Delete(ty); @@ -3734,6 +3747,11 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { add_symbols($$); add_symbols(n); Delattr($$, "class_rename"); + if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) { + SetFlag($$,"feature:ignore"); + Swig_warning(WARN_PARSE_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", name); + $$ = 0; + } }else if (cparse_cplusplus) $$ = 0; /* ignore unnamed structs for C++ */ Delete(unnamed); diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index ea1cf7fe4..7ae067da1 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -76,6 +76,7 @@ #define WARN_PARSE_PRIVATE_INHERIT 309 #define WARN_PARSE_TEMPLATE_REPEAT 310 #define WARN_PARSE_TEMPLATE_PARTIAL 311 +#define WARN_PARSE_NESTED_CLASS 312 #define WARN_PARSE_UNDEFINED_EXTERN 313 #define WARN_PARSE_KEYWORD 314 #define WARN_PARSE_USING_UNDEF 315 diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 1713e6f3f..4a105aa16 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -4288,8 +4288,8 @@ public: Delete(dirclassname); } - bool nestedClassesSupported() const { - return true; + NestedClassSupport nestedClassesSupport() const { + return NCS_Full; } }; /* class CSHARP */ diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index c47dd3e48..601cbb20e 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -4607,8 +4607,8 @@ public: Setattr(n, "director:ctor", class_ctor); } - bool nestedClassesSupported() const { - return true; + NestedClassSupport nestedClassesSupport() const { + return NCS_Full; } }; /* class JAVA */ diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index a547e2bd4..3940a3001 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -3441,8 +3441,8 @@ bool Language::extraDirectorProtectedCPPMethodsRequired() const { return true; } -bool Language::nestedClassesSupported() const { - return false; +Language::NestedClassSupport Language::nestedClassesSupport() const { + return NCS_Unknown; } /* ----------------------------------------------------------------------------- * Language::is_wrapping_class() diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index 786763441..66e2548dc 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -49,6 +49,7 @@ int SwigRuntime = 0; // 0 = no option, 1 = -runtime, 2 = -noruntime extern "C" { extern String *ModuleName; + extern int ignore_nested_classes; } /* usage string split into multiple parts otherwise string is too big for some compilers */ @@ -856,11 +857,6 @@ void SWIG_getoptions(int argc, char *argv[]) { } } -static void flatten_nested() { - Swig_feature_set(Swig_cparse_features(), "", 0, "feature:flatnested", "1", 0); -} - - int SWIG_main(int argc, char *argv[], Language *l) { char *c; @@ -905,6 +901,9 @@ int SWIG_main(int argc, char *argv[], Language *l) { Wrapper_director_mode_set(0); Wrapper_director_protected_mode_set(1); + // Inform the parser if the nested classes should be ignored unless explicitly told otherwise via feature:flatnested + ignore_nested_classes = l->nestedClassesSupport() == Language::NCS_Unknown ? 1 : 0; + // Create Library search directories // Check for SWIG_LIB environment variable @@ -1158,10 +1157,6 @@ int SWIG_main(int argc, char *argv[], Language *l) { fflush(stdout); } - // add "ignore" directive if nested classes are not supported - if (!lang->nestedClassesSupported()) - flatten_nested(); - Node *top = Swig_cparse(cpps); if (dump_top & STAGE1) { diff --git a/Source/Modules/nested.cxx b/Source/Modules/nested.cxx index 37248608c..3b45e9f90 100644 --- a/Source/Modules/nested.cxx +++ b/Source/Modules/nested.cxx @@ -416,7 +416,7 @@ void Swig_nested_name_unnamed_c_structs(Node *n) { static void remove_outer_class_reference(Node *n) { for (Node *c = firstChild(n); c; c = nextSibling(c)) { - if (GetFlag(c, "feature:flatnested")) { + if (GetFlag(c, "feature:flatnested") || Language::instance()->nestedClassesSupport() == Language::NCS_None) { Delattr(c, "nested:outer"); remove_outer_class_reference(c); } @@ -428,7 +428,7 @@ void Swig_nested_process_classes(Node *n) { while (c) { Node *next = nextSibling(c); if (!Getattr(c, "templatetype")) { - if (GetFlag(c, "nested") && GetFlag(c, "feature:flatnested")) { + if (GetFlag(c, "nested") && (GetFlag(c, "feature:flatnested") || Language::instance()->nestedClassesSupport() == Language::NCS_None)) { removeNode(c); if (!checkAttribute(c, "access", "public")) SetFlag(c, "feature:ignore"); diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 7ebcfeee1..2929993b3 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -298,13 +298,19 @@ protected: virtual bool extraDirectorProtectedCPPMethodsRequired() const; public: - /* Does target language support nested classes? Default is 'false'. If 'false' is returned, then - %rename("$ignore", %$isnested) statement will be issued at the top, and the nested classes - will be ignored. Note that even if the target language does not support the notion of class - nesting, the language module may nevertheless return true from this function, and use - %feature "flatnested" to move nested classes to the global scope, instead of ignoring them. + enum NestedClassSupport { + NCS_None, // Target language does not have an equivalent to nested classes + NCS_Full, // Target language does have an equivalent to nested classes and is fully implemented + NCS_Unknown // Target language may or may not have an equivalent to nested classes. If it does, it has not been implemented yet. + }; + /* Does target language support nested classes? Default is NCS_Unknown. + If NCS_Unknown is returned, then the nested classes will be ignored unless + %feature "flatnested" is applied to them, in which case they will appear in global space. + If the target language does not support the notion of class + nesting, the language module should return NCS_None from this function, and + the nested classes will be moved to the global scope (like implicit global %feature "flatnested"). */ - virtual bool nestedClassesSupported() const; + virtual NestedClassSupport nestedClassesSupport() const; protected: /* Identifies if a protected members that are generated when the allprotected option is used. diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index e918c0770..49f95090d 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -504,7 +504,8 @@ class TypePass:private Dispatcher { SwigType_attach_symtab(Getattr(n, "symtab")); /* Inherit type definitions into the class */ - if (name && !(GetFlag(n, "nested") && GetFlag(n, "feature:flatnested") && !checkAttribute(n, "access", "public"))) { + if (name && !(GetFlag(n, "nested") && !checkAttribute(n, "access", "public") && + (GetFlag(n, "feature:flatnested") || Language::instance()->nestedClassesSupport() == Language::NCS_None))) { cplus_inherit_types(n, 0, nname ? nname : (fname ? fname : name)); } From 69d849b56ca6507326ad4ed802a98c32dc17403f Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Sun, 2 Feb 2014 23:38:23 +0400 Subject: [PATCH 0884/1160] filtered warnings, turned on "flatnested" for nested template test --- Examples/test-suite/derived_nested.i | 5 +++++ Examples/test-suite/namespace_class.i | 2 ++ Examples/test-suite/nested_class.i | 20 ++++++++++++++++++++ Examples/test-suite/template_nested.i | 11 +++++++++++ 4 files changed, 38 insertions(+) diff --git a/Examples/test-suite/derived_nested.i b/Examples/test-suite/derived_nested.i index e374cf70f..2b3698045 100644 --- a/Examples/test-suite/derived_nested.i +++ b/Examples/test-suite/derived_nested.i @@ -3,6 +3,11 @@ This was reported in bug #909389 */ %module derived_nested +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::CC; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::DD; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::EE; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::FF; + %inline %{ class A { diff --git a/Examples/test-suite/namespace_class.i b/Examples/test-suite/namespace_class.i index 113bbeb35..cc9940d13 100644 --- a/Examples/test-suite/namespace_class.i +++ b/Examples/test-suite/namespace_class.i @@ -1,6 +1,8 @@ %module namespace_class +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Ala::Ola; + #ifdef SWIGD %warnfilter(SWIGWARN_IGNORE_OPERATOR_LT); #endif diff --git a/Examples/test-suite/nested_class.i b/Examples/test-suite/nested_class.i index 282875531..ccb7ecac1 100644 --- a/Examples/test-suite/nested_class.i +++ b/Examples/test-suite/nested_class.i @@ -1,5 +1,25 @@ %module nested_class +#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct1; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass1; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion1; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass2; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct2; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion2; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass4Typedef; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct4Typedef; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion4Typedef; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass5; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct5; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion5; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultiple; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleDerived; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleAnonTypedef1; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleNamedTypedef; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerSameName; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer2::IgnoreMe; + %inline %{ struct Outer { typedef int Integer; diff --git a/Examples/test-suite/template_nested.i b/Examples/test-suite/template_nested.i index c33018e0f..f9b070270 100644 --- a/Examples/test-suite/template_nested.i +++ b/Examples/test-suite/template_nested.i @@ -1,7 +1,18 @@ %module template_nested +#if !defined(SWIGCSHARP) && !defined(SWIGJAVA) +%feature ("flatnested"); +#endif + // Test nested templates - that is template classes and template methods within a class. +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterClass::Inner1; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterClass::Inner2; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate1; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate2; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate3; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedStruct; + namespace ns { template struct ForwardTemplate; } From 4744ea8903f300e5afd1030922a7be62e4cb1c9b Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Mon, 3 Feb 2014 01:03:37 +0400 Subject: [PATCH 0885/1160] added forward declaration instead of ignored nested class (resurrected old code) --- Source/CParse/parser.y | 123 +++++++++++++++++++++++++++----------- Source/Include/swigwarn.h | 3 +- 2 files changed, 91 insertions(+), 35 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 0f2cfdec9..102cba368 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1069,6 +1069,71 @@ static void update_nested_classes(Node *n) } } +/* ----------------------------------------------------------------------------- + * nested_forward_declaration() + * + * Nested struct handling for C++ code if the nested classes are diasbled. + * Create the nested class/struct/union as a forward declaration. + * ----------------------------------------------------------------------------- */ + +static Node *nested_forward_declaration(const char *storage, const char *kind, String *sname, String *name, Node *cpp_opt_declarators) { + Node *nn = 0; + int warned = 0; + + if (sname) { + /* Add forward declaration of the nested type */ + Node *n = new_node("classforward"); + Setattr(n, "kind", kind); + Setattr(n, "name", sname); + Setattr(n, "storage", storage); + Setattr(n, "sym:weak", "1"); + add_symbols(n); + nn = n; + } + + /* Add any variable instances. Also add in any further typedefs of the nested type. + Note that anonymous typedefs (eg typedef struct {...} a, b;) are treated as class forward declarations */ + if (cpp_opt_declarators) { + int storage_typedef = (storage && (strcmp(storage, "typedef") == 0)); + int variable_of_anonymous_type = !sname && !storage_typedef; + if (!variable_of_anonymous_type) { + int anonymous_typedef = !sname && (storage && (strcmp(storage, "typedef") == 0)); + Node *n = cpp_opt_declarators; + SwigType *type = name; + while (n) { + Setattr(n, "type", type); + Setattr(n, "storage", storage); + if (anonymous_typedef) { + Setattr(n, "nodeType", "classforward"); + Setattr(n, "sym:weak", "1"); + } + n = nextSibling(n); + } + add_symbols(cpp_opt_declarators); + + if (nn) { + set_nextSibling(nn, cpp_opt_declarators); + } else { + nn = cpp_opt_declarators; + } + } + } + + if (nn && Equal(nodeType(nn), "classforward")) { + Node *n = nn; + SWIG_WARN_NODE_BEGIN(n); + Swig_warning(WARN_PARSE_NAMED_NESTED_CLASS, cparse_file, cparse_line,"Nested %s not currently supported (%s ignored)\n", kind, sname ? sname : name); + SWIG_WARN_NODE_END(n); + warned = 1; + } + + if (!warned) + Swig_warning(WARN_PARSE_UNNAMED_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", kind); + + return nn; +} + + Node *Swig_cparse(File *f) { scanner_file(f); top = 0; @@ -3553,8 +3618,13 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Setattr($$, "symtab", Swig_symbol_popscope()); Classprefix = Getattr($$, "Classprefix"); Delattr($$, "Classprefix"); + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); + Swig_features_get(Swig_cparse_features(), Namespaceprefix, Getattr($$, "name"), 0, $$); if (cplus_mode == CPLUS_PRIVATE) { $$ = 0; /* skip private nested classes */ + } else if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) { + $$ = nested_forward_declaration($1, $2, $3, Copy($3), $9); } else if (nscope_inner) { /* this is tricky */ /* we add the declaration in the original namespace */ @@ -3564,31 +3634,23 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Namespaceprefix = Swig_symbol_qualifiedscopename(0); yyrename = Copy(Getattr($$, "class_rename")); add_symbols($$); - if (currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) { - SetFlag($$,"feature:ignore"); - Swig_warning(WARN_PARSE_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", Getattr($$, "name")); - $$ = 0; - } else { - Delattr($$, "class_rename"); - /* but the variable definition in the current scope */ - Swig_symbol_setscope(cscope); - Delete(Namespaceprefix); - Namespaceprefix = Swig_symbol_qualifiedscopename(0); - add_symbols($9); - if (nscope) { - $$ = nscope; /* here we return recreated namespace tower instead of the class itself */ - if ($9) { - appendSibling($$, $9); - } - } else if (!SwigType_istemplate(ty) && template_parameters == 0) { /* for tempalte we need the class itself */ - $$ = $9; + Delattr($$, "class_rename"); + /* but the variable definition in the current scope */ + Swig_symbol_setscope(cscope); + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); + add_symbols($9); + if (nscope) { + $$ = nscope; /* here we return recreated namespace tower instead of the class itself */ + if ($9) { + appendSibling($$, $9); } + } else if (!SwigType_istemplate(ty) && template_parameters == 0) { /* for tempalte we need the class itself */ + $$ = $9; } } else { Delete(yyrename); yyrename = 0; - Delete(Namespaceprefix); - Namespaceprefix = Swig_symbol_qualifiedscopename(0); if (!cparse_cplusplus && currentOuterClass) { /* nested C structs go into global scope*/ Node *outer = currentOuterClass; while (Getattr(outer, "nested:outer")) @@ -3607,14 +3669,8 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { } else { yyrename = Copy(Getattr($$, "class_rename")); add_symbols($$); - if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) { - SetFlag($$,"feature:ignore"); - Swig_warning(WARN_PARSE_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", Getattr($$, "name")); - $$ = 0; - } else { - add_symbols($9); - Delattr($$, "class_rename"); - } + add_symbols($9); + Delattr($$, "class_rename"); } } Delete(ty); @@ -3678,7 +3734,11 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { /* Check for pure-abstract class */ Setattr($$,"abstracts", pure_abstracts($6)); n = $8; - if (n) { + Swig_features_get(Swig_cparse_features(), Namespaceprefix, 0, 0, $$); + if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) { + String *name = n ? Copy(Getattr(n, "name")) : 0; + $$ = nested_forward_declaration($1, $2, 0, name, n); + } else if (n) { appendSibling($$,n); /* If a proper typedef name was given, we'll use it to set the scope name */ name = try_to_find_a_name_for_unnamed_structure($1, n); @@ -3747,11 +3807,6 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { add_symbols($$); add_symbols(n); Delattr($$, "class_rename"); - if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) { - SetFlag($$,"feature:ignore"); - Swig_warning(WARN_PARSE_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", name); - $$ = 0; - } }else if (cparse_cplusplus) $$ = 0; /* ignore unnamed structs for C++ */ Delete(unnamed); diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index 7ae067da1..1210d64a6 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -76,7 +76,7 @@ #define WARN_PARSE_PRIVATE_INHERIT 309 #define WARN_PARSE_TEMPLATE_REPEAT 310 #define WARN_PARSE_TEMPLATE_PARTIAL 311 -#define WARN_PARSE_NESTED_CLASS 312 +#define WARN_PARSE_UNNAMED_NESTED_CLASS 312 #define WARN_PARSE_UNDEFINED_EXTERN 313 #define WARN_PARSE_KEYWORD 314 #define WARN_PARSE_USING_UNDEF 315 @@ -89,6 +89,7 @@ #define WARN_PARSE_REDUNDANT 322 #define WARN_PARSE_REC_INHERITANCE 323 #define WARN_PARSE_NESTED_TEMPLATE 324 +#define WARN_PARSE_NAMED_NESTED_CLASS 325 #define WARN_PARSE_EXTEND_NAME 326 #define WARN_CPP11_LAMBDA 340 From 8fc4fd2893111f7e35c00632bb51dd26a96951e4 Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Mon, 3 Feb 2014 01:15:05 +0400 Subject: [PATCH 0886/1160] %feature ("flatnested") is set for nested scope test --- Examples/test-suite/nested_scope.i | 4 ++++ Examples/test-suite/template_nested.i | 7 ------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Examples/test-suite/nested_scope.i b/Examples/test-suite/nested_scope.i index 358dbbb61..be93ad8c6 100644 --- a/Examples/test-suite/nested_scope.i +++ b/Examples/test-suite/nested_scope.i @@ -1,5 +1,9 @@ %module nested_scope +#if !defined(SWIGCSHARP) && !defined(SWIGJAVA) +%feature ("flatnested"); +#endif + %inline %{ namespace ns { struct Global { diff --git a/Examples/test-suite/template_nested.i b/Examples/test-suite/template_nested.i index f9b070270..81a551a41 100644 --- a/Examples/test-suite/template_nested.i +++ b/Examples/test-suite/template_nested.i @@ -6,13 +6,6 @@ // Test nested templates - that is template classes and template methods within a class. -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterClass::Inner1; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterClass::Inner2; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate1; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate2; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate3; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedStruct; - namespace ns { template struct ForwardTemplate; } From bda9c90e2bea477f03be4715c9f92fcf856bff69 Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Mon, 3 Feb 2014 02:21:44 +0400 Subject: [PATCH 0887/1160] warnfilter fixed scoping for "anonymous forward declaration" fixed --- Examples/test-suite/namespace_union.i | 2 ++ Examples/test-suite/nested_class.i | 1 + Examples/test-suite/nested_comment.i | 2 ++ Source/CParse/parser.y | 17 ++++++++++++----- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Examples/test-suite/namespace_union.i b/Examples/test-suite/namespace_union.i index 84e38b4d5..85885f399 100644 --- a/Examples/test-suite/namespace_union.i +++ b/Examples/test-suite/namespace_union.i @@ -1,5 +1,7 @@ %module namespace_union +#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS + %inline %{ namespace SpatialIndex { diff --git a/Examples/test-suite/nested_class.i b/Examples/test-suite/nested_class.i index ccb7ecac1..1cdfaade6 100644 --- a/Examples/test-suite/nested_class.i +++ b/Examples/test-suite/nested_class.i @@ -19,6 +19,7 @@ %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleNamedTypedef; %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerSameName; %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer2::IgnoreMe; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerSameName2; %inline %{ struct Outer { diff --git a/Examples/test-suite/nested_comment.i b/Examples/test-suite/nested_comment.i index df160b157..99d0ffb43 100644 --- a/Examples/test-suite/nested_comment.i +++ b/Examples/test-suite/nested_comment.i @@ -1,5 +1,7 @@ %module nested_comment +#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS + // this example shows a problem with 'dump_nested' (parser.y). // bug #949654 diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 102cba368..77d253299 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1076,7 +1076,7 @@ static void update_nested_classes(Node *n) * Create the nested class/struct/union as a forward declaration. * ----------------------------------------------------------------------------- */ -static Node *nested_forward_declaration(const char *storage, const char *kind, String *sname, String *name, Node *cpp_opt_declarators) { +static Node *nested_forward_declaration(const char *storage, const char *kind, String *sname, String *name, Node *cpp_opt_declarators, Node* nested) { Node *nn = 0; int warned = 0; @@ -1120,15 +1120,19 @@ static Node *nested_forward_declaration(const char *storage, const char *kind, S } if (nn && Equal(nodeType(nn), "classforward")) { - Node *n = nn; + Node *n = nested; SWIG_WARN_NODE_BEGIN(n); Swig_warning(WARN_PARSE_NAMED_NESTED_CLASS, cparse_file, cparse_line,"Nested %s not currently supported (%s ignored)\n", kind, sname ? sname : name); SWIG_WARN_NODE_END(n); warned = 1; } - if (!warned) + if (!warned) { + Node *n = nested; + SWIG_WARN_NODE_BEGIN(n); Swig_warning(WARN_PARSE_UNNAMED_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", kind); + SWIG_WARN_NODE_END(n); + } return nn; } @@ -3624,7 +3628,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { if (cplus_mode == CPLUS_PRIVATE) { $$ = 0; /* skip private nested classes */ } else if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) { - $$ = nested_forward_declaration($1, $2, $3, Copy($3), $9); + $$ = nested_forward_declaration($1, $2, $3, Copy($3), $9, $$); } else if (nscope_inner) { /* this is tricky */ /* we add the declaration in the original namespace */ @@ -3737,7 +3741,10 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Swig_features_get(Swig_cparse_features(), Namespaceprefix, 0, 0, $$); if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) { String *name = n ? Copy(Getattr(n, "name")) : 0; - $$ = nested_forward_declaration($1, $2, 0, name, n); + $$ = nested_forward_declaration($1, $2, 0, name, n, $$); + Swig_symbol_popscope(); + Delete(Namespaceprefix); + Namespaceprefix = Swig_symbol_qualifiedscopename(0); } else if (n) { appendSibling($$,n); /* If a proper typedef name was given, we'll use it to set the scope name */ From 03203783878bf818056031865789d25ba0606629 Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Mon, 3 Feb 2014 02:31:17 +0400 Subject: [PATCH 0888/1160] more warnings removed --- Examples/test-suite/nested_class.i | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/Examples/test-suite/nested_class.i b/Examples/test-suite/nested_class.i index 1cdfaade6..73bf89eb0 100644 --- a/Examples/test-suite/nested_class.i +++ b/Examples/test-suite/nested_class.i @@ -1,25 +1,7 @@ %module nested_class #pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct1; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass1; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion1; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass2; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct2; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion2; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass4Typedef; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct4Typedef; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion4Typedef; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass5; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct5; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion5; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultiple; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleDerived; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleAnonTypedef1; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleNamedTypedef; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerSameName; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer2::IgnoreMe; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerSameName2; +#pragma SWIG nowarn=SWIGWARN_PARSE_NAMED_NESTED_CLASS %inline %{ struct Outer { From b7fd1eacb223950ae93ebdf9f4e119ac9b7df105 Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Mon, 3 Feb 2014 02:50:19 +0400 Subject: [PATCH 0889/1160] WARN_PARSE_UNNAMED_NESTED_CLASS check fixed --- Examples/test-suite/errors/cpp_macro_locator.stderr | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/test-suite/errors/cpp_macro_locator.stderr b/Examples/test-suite/errors/cpp_macro_locator.stderr index 8a78d46af..f4fc2c7d0 100644 --- a/Examples/test-suite/errors/cpp_macro_locator.stderr +++ b/Examples/test-suite/errors/cpp_macro_locator.stderr @@ -1,3 +1,4 @@ +cpp_macro_locator.i:50: Warning 325: Nested struct not currently supported (Inner ignored) cpp_macro_locator.i:66: Warning 204: CPP #warning, "inline warning message one". cpp_macro_locator.i:96: Warning 204: CPP #warning, "an inline warning message 2". cpp_macro_locator.i:53: Warning 509: Overloaded method overload1(int const *) effectively ignored, From 87c1e093eef273b2a278169d72d899d79e68058a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 24 Jan 2014 01:09:04 +0000 Subject: [PATCH 0890/1160] Travis display pcre version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fd0a95b94..9cf525f6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,7 +50,7 @@ before_install: script: - ./autogen.sh && ./configure - make -s $SWIGJOBS - - ./swig -version + - ./swig -version && ./swig -pcreversion - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-ccache; fi - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-errors-test-suite; fi - if test -z "$SWIGLANG"; then sudo make -s install && swig -version && ccache-swig -V; fi From 0383d08444eed8fa7e4476fe421c9ed14f92fba0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 31 Jan 2014 22:47:12 +0000 Subject: [PATCH 0891/1160] Add new swigtype_inout.i library containing SWIGTYPE *& OUTPUT typemaps. --- CHANGES.current | 14 +++++ Examples/test-suite/common.mk | 1 + .../csharp/li_swigtype_inout_runme.cs | 56 +++++++++++++++++++ Examples/test-suite/li_swigtype_inout.i | 53 ++++++++++++++++++ Lib/csharp/swigtype_inout.i | 34 +++++++++++ 5 files changed, 158 insertions(+) create mode 100644 Examples/test-suite/csharp/li_swigtype_inout_runme.cs create mode 100644 Examples/test-suite/li_swigtype_inout.i create mode 100644 Lib/csharp/swigtype_inout.i diff --git a/CHANGES.current b/CHANGES.current index ca7503d41..c76a0c19f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,20 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-01-30: wsfulton + [C#] Add new swigtype_inout.i library containing SWIGTYPE *& OUTPUT typemaps. + + Example usage wrapping: + + void f(XXX *& x) { x = new XXX(111); } + + would be: + + XXX x = null; + f(out x); + // use x + x.Dispose(); // manually clear memory or otherwise leave out and leave it to the garbage collector + 2014-01-21: ianlancetaylor [Go] Add %go_import directive. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index dc18852f7..5ce9a7031 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -251,6 +251,7 @@ CPP_TEST_CASES += \ li_cpointer \ li_std_auto_ptr \ li_stdint \ + li_swigtype_inout \ li_typemaps \ li_typemaps_apply \ li_windows \ diff --git a/Examples/test-suite/csharp/li_swigtype_inout_runme.cs b/Examples/test-suite/csharp/li_swigtype_inout_runme.cs new file mode 100644 index 000000000..0f9520d48 --- /dev/null +++ b/Examples/test-suite/csharp/li_swigtype_inout_runme.cs @@ -0,0 +1,56 @@ + +using System; +using li_swigtype_inoutNamespace; + +public class li_swigtype_inout_runme { + + public static void Main() { + XXX xxx = new XXX(999); + check_count(1); + XXX x1 = null; + XXX x2 = null; + XXX x3 = null; + XXX x4 = null; + li_swigtype_inout.ptr_ref_out(out x1, out x2, out x3, out x4); + check_value(111, x1.value); + check_value(222, x2.value); + check_value(333, x3.value); + check_value(444, x4.value); + check_count(5); + x1.Dispose(); + x2.Dispose(); + x3.Dispose(); + x4.Dispose(); + xxx.Dispose(); + check_count(0); + + x1 = null; + x2 = null; + x3 = null; + x4 = null; + new ConstructorTest(out x1, out x2, out x3, out x4); + check_count(4); + check_value(111, x1.value); + check_value(222, x2.value); + check_value(333, x3.value); + check_value(444, x4.value); + x1.Dispose(); + x2.Dispose(); + x3.Dispose(); + x4.Dispose(); + check_count(0); + } + + public static void check_count(int count) { + int actual = XXX.count; + if( count != actual ) { + throw new Exception(String.Format("Count wrong. Expected: {0} Got: {1}", count, actual)); + } + } + + public static void check_value(int expected, int actual) { + if( expected != actual ) { + throw new Exception(String.Format("Wrong value. Expected: {0} Got: {1}", expected, actual)); + } + } +} diff --git a/Examples/test-suite/li_swigtype_inout.i b/Examples/test-suite/li_swigtype_inout.i new file mode 100644 index 000000000..8b695a925 --- /dev/null +++ b/Examples/test-suite/li_swigtype_inout.i @@ -0,0 +1,53 @@ +%module li_swigtype_inout + +// Test SWIGTYPE *& typemaps in swigtype_inout.i library + +#ifdef SWIGCSHARP +%include +%apply SWIGTYPE *& OUTPUT { SWIGTYPE *& } +#endif + +%ignore XXX::operator=; + +%inline %{ +#include +struct XXX { + XXX(int value) : value(value) { + if (debug) std::cout << "Default Constructor " << value << " " << this << std::endl; + count++; + } + XXX(const XXX &other) { + value = other.value; + if (debug) std::cout << "Copy Constructor " << value << " " << this << std::endl; + count++; + } + XXX& operator=(const XXX &other) { + value = other.value; + if (debug) std::cout << "Assignment operator " << value << " " << this << std::endl; + return *this; + } + ~XXX() { + if (debug) std::cout << "Destructor " << value << " " << this << std::endl; + count--; + } + void showInfo() { + if (debug) std::cout << "Info " << value << " " << this << std::endl; + } + int value; + static const bool debug = false; + static int count; +}; +int XXX::count = 0; + +void ptr_ref_out(XXX *& x1, XXX *& x2, XXX const*& x3, XXX const*& x4) { + x1 = new XXX(111); + x2 = new XXX(222); + x3 = new XXX(333); + x4 = new XXX(444); +} +struct ConstructorTest { + ConstructorTest(XXX *& x1, XXX *& x2, XXX const*& x3, XXX const*& x4) { + ptr_ref_out(x1, x2, x3, x4); + } +}; +%} diff --git a/Lib/csharp/swigtype_inout.i b/Lib/csharp/swigtype_inout.i new file mode 100644 index 000000000..e7312e8fe --- /dev/null +++ b/Lib/csharp/swigtype_inout.i @@ -0,0 +1,34 @@ +/* ----------------------------------------------------------------------------- + * swigtype_inout.i + * + * Pointer pointer and pointer reference handling typemap library for non-primitive types + * + * These mappings provide support for input/output arguments and common + * uses for C/C++ pointer references and pointer to pointers. + * + * These are named typemaps (OUTPUT) and can be used like any named typemap. + * Alternatively they can be made the default by using %apply: + * %apply SWIGTYPE *& OUTPUT { SWIGTYPE *& } + * ----------------------------------------------------------------------------- */ + +/* + * OUTPUT typemaps. Example usage wrapping: + * + * void f(XXX *& x) { x = new XXX(111); } + * + * would be: + * + * XXX x = null; + * f(out x); + * // use x + * x.Dispose(); // manually clear memory or otherwise leave out and leave it to the garbage collector + */ +%typemap(ctype) SWIGTYPE *& OUTPUT "void **" +%typemap(imtype, out="global::System.IntPtr") SWIGTYPE *& OUTPUT "out global::System.IntPtr" +%typemap(cstype) SWIGTYPE *& OUTPUT "out $*csclassname" +%typemap(csin, + pre=" global::System.IntPtr cPtr_$csinput = global::System.IntPtr.Zero;", + post=" $csinput = (cPtr_$csinput == global::System.IntPtr.Zero) ? null : new $*csclassname(cPtr_$csinput, true);", + cshin="out $csinput") SWIGTYPE *& OUTPUT "out cPtr_$csinput" +%typemap(in) SWIGTYPE *& OUTPUT %{ $1 = ($1_ltype)$input; %} +%typemap(freearg) SWIGTYPE *& OUTPUT "" From c3eff9234c5aaca49be12758bb6b2cc4dc18623f Mon Sep 17 00:00:00 2001 From: Marvin Greenberg Date: Fri, 31 Jan 2014 16:03:14 -0500 Subject: [PATCH 0892/1160] Workaround for clang 3.2 libc++ empty struct bug. Certain tests have empty structs or classes. This encounters a bug with clang: http://llvm.org/bugs/show_bug.cgi?id=16764 This is fixed in later versions of clang, but not the version currently bundled with Mavericks and XCode 5 --- Examples/test-suite/constructor_copy.i | 6 ++++-- Examples/test-suite/ignore_template_constructor.i | 10 ++++++---- Examples/test-suite/smart_pointer_inherit.i | 1 + Examples/test-suite/std_containers.i | 3 ++- Examples/test-suite/template_matrix.i | 1 + Examples/test-suite/template_opaque.i | 1 + 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Examples/test-suite/constructor_copy.i b/Examples/test-suite/constructor_copy.i index f6bdcb240..bfbd706f4 100644 --- a/Examples/test-suite/constructor_copy.i +++ b/Examples/test-suite/constructor_copy.i @@ -94,14 +94,16 @@ public: namespace Space { class Flow { +int x; public: - Flow(int i) {} + Flow(int i) : x(i) {} }; class FlowFlow { +int x; public: - FlowFlow(int i) {} + FlowFlow(int i) : x(i) {} }; } diff --git a/Examples/test-suite/ignore_template_constructor.i b/Examples/test-suite/ignore_template_constructor.i index ffd541986..31a5505fb 100644 --- a/Examples/test-suite/ignore_template_constructor.i +++ b/Examples/test-suite/ignore_template_constructor.i @@ -17,9 +17,10 @@ #if defined(SWIG_GOOD_VECTOR) %inline %{ class Flow { - Flow() {} +double x; + Flow():x(0.0) {} public: - Flow(double d) {} + Flow(double d) : x(d) {} }; %} @@ -28,9 +29,10 @@ public: %inline %{ class Flow { +double x; public: - Flow() {} - Flow(double d) {} + Flow(): x(0.0) {} + Flow(double d) : x(d) {} }; %} diff --git a/Examples/test-suite/smart_pointer_inherit.i b/Examples/test-suite/smart_pointer_inherit.i index a81d72268..52df5a92b 100644 --- a/Examples/test-suite/smart_pointer_inherit.i +++ b/Examples/test-suite/smart_pointer_inherit.i @@ -47,6 +47,7 @@ %inline %{ class ItkLevelSetNodeUS2 { + int x; }; %} diff --git a/Examples/test-suite/std_containers.i b/Examples/test-suite/std_containers.i index 0955226ad..ae69b6418 100644 --- a/Examples/test-suite/std_containers.i +++ b/Examples/test-suite/std_containers.i @@ -191,7 +191,8 @@ template struct Param struct Foo { - Foo(int i) { + int x; + Foo(int i) : x(i) { } }; diff --git a/Examples/test-suite/template_matrix.i b/Examples/test-suite/template_matrix.i index 27696542a..535193819 100644 --- a/Examples/test-suite/template_matrix.i +++ b/Examples/test-suite/template_matrix.i @@ -21,6 +21,7 @@ namespace simuPOP template class Operator { + int x; }; } diff --git a/Examples/test-suite/template_opaque.i b/Examples/test-suite/template_opaque.i index 5918fe069..b910e47e3 100644 --- a/Examples/test-suite/template_opaque.i +++ b/Examples/test-suite/template_opaque.i @@ -6,6 +6,7 @@ { struct OpaqueStruct { + int x; }; } From 213774e0b63810b318bbaaa577e10a3de02263d5 Mon Sep 17 00:00:00 2001 From: Marvin Greenberg Date: Mon, 3 Feb 2014 11:34:55 -0500 Subject: [PATCH 0893/1160] Fix issue on clang about implicit instantiation of undefined template Generated code does not include , which is referenced in templates. Clang may be incorrectly or aggresively instantiating some template. E.g., import_stl_b_wrap.cxx:3199:51: error: implicit instantiation of undefined template 'std::__1::basic_string --- Lib/std/std_common.i | 8 +++++++- Lib/typemaps/traits.swg | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Lib/std/std_common.i b/Lib/std/std_common.i index 7c52880e9..cb91bc632 100644 --- a/Lib/std/std_common.i +++ b/Lib/std/std_common.i @@ -73,7 +73,13 @@ namespace std { #endif %} -%fragment("StdTraitsCommon","header") %{ +%fragment("StdStringInclude","header") %{ +#ifdef __clang__ +#include +#endif +%} + +%fragment("StdTraitsCommon","header",fragment="StdStringInclude") %{ namespace swig { template struct noconst_traits { diff --git a/Lib/typemaps/traits.swg b/Lib/typemaps/traits.swg index b39eb3946..584d480c2 100644 --- a/Lib/typemaps/traits.swg +++ b/Lib/typemaps/traits.swg @@ -26,7 +26,13 @@ #include %} -%fragment("Traits","header") +%fragment("StdStringInclude","header") %{ +#ifdef __clang__ +#include +#endif +%} + +%fragment("Traits","header",fragment="StdStringInclude") { namespace swig { /* From 843aa7cd65985319a64d4f1297778f93f96a5008 Mon Sep 17 00:00:00 2001 From: Marvin Greenberg Date: Thu, 30 Jan 2014 16:37:07 -0500 Subject: [PATCH 0894/1160] Work around differences in clang libc++ std::vector::const_reference clang++ using -stdlib=libc++ defines const_reference as a class, to map boolean vectors onto a bit set. Because swig does not "see" the type as "const &" it generates incorrect code for this case, generating a declaration like: const_reference result; When const_reference is a typedef to 'bool' as is the case with stdlibc++ this works. When this is actually a constant reference, this is clearly invalid since it is not initialized. For libc++, this is a class which cannot be default constructed, resulting in an error. The fix is to explicitly define the various accessor extensions as having a bool return type for this specialization. --- Lib/csharp/std_vector.i | 2 +- Lib/d/std_vector.i | 12 ++++++------ Lib/go/std_vector.i | 2 +- Lib/java/std_vector.i | 2 +- Lib/php/std_vector.i | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index 9d52a962b..467a2ade8 100644 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -217,7 +217,7 @@ else throw std::out_of_range("index"); } - const_reference getitem(int index) throw (std::out_of_range) { + CONST_REFERENCE getitem(int index) throw (std::out_of_range) { if (index>=0 && index<(int)$self->size()) return (*$self)[index]; else diff --git a/Lib/d/std_vector.i b/Lib/d/std_vector.i index b7d4e223f..50942f289 100644 --- a/Lib/d/std_vector.i +++ b/Lib/d/std_vector.i @@ -128,7 +128,7 @@ public void capacity(size_t value) { return $self->capacity() - $self->size(); } - const_reference remove() throw (std::out_of_range) { + CONST_REFERENCE remove() throw (std::out_of_range) { if ($self->empty()) { throw std::out_of_range("Tried to remove last element from empty vector."); } @@ -138,7 +138,7 @@ public void capacity(size_t value) { return value; } - const_reference remove(size_type index) throw (std::out_of_range) { + CONST_REFERENCE remove(size_type index) throw (std::out_of_range) { if (index >= $self->size()) { throw std::out_of_range("Tried to remove element with invalid index."); } @@ -153,7 +153,7 @@ public void capacity(size_t value) { // Wrappers for setting/getting items with the possibly thrown exception // specified (important for SWIG wrapper generation). %extend { - const_reference getElement(size_type index) throw (std::out_of_range) { + CONST_REFERENCE getElement(size_type index) throw (std::out_of_range) { if ((index < 0) || ($self->size() <= index)) { throw std::out_of_range("Tried to get value of element with invalid index."); } @@ -464,7 +464,7 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg) return pv; } - const_reference remove() throw (std::out_of_range) { + CONST_REFERENCE remove() throw (std::out_of_range) { if ($self->empty()) { throw std::out_of_range("Tried to remove last element from empty vector."); } @@ -474,7 +474,7 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg) return value; } - const_reference remove(size_type index) throw (std::out_of_range) { + CONST_REFERENCE remove(size_type index) throw (std::out_of_range) { if (index >= $self->size()) { throw std::out_of_range("Tried to remove element with invalid index."); } @@ -506,7 +506,7 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg) // Wrappers for setting/getting items with the possibly thrown exception // specified (important for SWIG wrapper generation). %extend { - const_reference getElement(size_type index) throw (std::out_of_range) { + CONST_REFERENCE getElement(size_type index) throw (std::out_of_range) { if ((index < 0) || ($self->size() <= index)) { throw std::out_of_range("Tried to get value of element with invalid index."); } diff --git a/Lib/go/std_vector.i b/Lib/go/std_vector.i index f4ce8431c..29bcd1391 100644 --- a/Lib/go/std_vector.i +++ b/Lib/go/std_vector.i @@ -59,7 +59,7 @@ namespace std { %rename(add) push_back; void push_back(const value_type& x); %extend { - const_reference get(int i) throw (std::out_of_range) { + bool get(int i) throw (std::out_of_range) { int size = int(self->size()); if (i>=0 && isize()); if (i>=0 && ipop_back(); return x; } - const_reference get(int i) throw (std::out_of_range) { + bool get(int i) throw (std::out_of_range) { int size = int(self->size()); if (i>=0 && i Date: Wed, 5 Feb 2014 02:30:48 +0400 Subject: [PATCH 0895/1160] error order foxed --- Examples/test-suite/errors/cpp_macro_locator.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/errors/cpp_macro_locator.stderr b/Examples/test-suite/errors/cpp_macro_locator.stderr index f4fc2c7d0..0d91ba5ae 100644 --- a/Examples/test-suite/errors/cpp_macro_locator.stderr +++ b/Examples/test-suite/errors/cpp_macro_locator.stderr @@ -1,6 +1,6 @@ -cpp_macro_locator.i:50: Warning 325: Nested struct not currently supported (Inner ignored) cpp_macro_locator.i:66: Warning 204: CPP #warning, "inline warning message one". cpp_macro_locator.i:96: Warning 204: CPP #warning, "an inline warning message 2". +cpp_macro_locator.i:50: Warning 325: Nested struct not currently supported (Inner ignored) cpp_macro_locator.i:53: Warning 509: Overloaded method overload1(int const *) effectively ignored, cpp_macro_locator.i:52: Warning 509: as it is shadowed by overload1(int *). cpp_macro_locator.i:61: Warning 509: Overloaded method overload2(int const *) effectively ignored, From a54674eeca8c5173b915e6bd21de4ccd4298fcf5 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Wed, 5 Feb 2014 11:52:26 +0100 Subject: [PATCH 0896/1160] Guile: illustrate bug in non-ascii string handling --- Examples/test-suite/schemerunme/li_std_string.scm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/schemerunme/li_std_string.scm b/Examples/test-suite/schemerunme/li_std_string.scm index e77c32870..343b9b8e8 100644 --- a/Examples/test-suite/schemerunme/li_std_string.scm +++ b/Examples/test-suite/schemerunme/li_std_string.scm @@ -1,4 +1,6 @@ -(define x "hello") +; The test string has some non-ascii characters added +; because our guile wrappers had bugs in that area +(define x "hello - æææ") (if (not (string=? (test-value x) x)) (begin (error "Error 1") (exit 1))) From c6d03a6a9fd4af3bd22b9754f82abe0bd5555e84 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Fri, 13 Dec 2013 17:48:26 +0100 Subject: [PATCH 0897/1160] Guile: make scm to string conversion work with non-ascii strings --- .../test-suite/guile/li_std_string_runme.scm | 4 ++++ Lib/guile/guile_scm_run.swg | 22 ++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Examples/test-suite/guile/li_std_string_runme.scm b/Examples/test-suite/guile/li_std_string_runme.scm index 5dde68f8d..5b5563281 100644 --- a/Examples/test-suite/guile/li_std_string_runme.scm +++ b/Examples/test-suite/guile/li_std_string_runme.scm @@ -2,4 +2,8 @@ ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. (dynamic-call "scm_init_li_std_string_module" (dynamic-link "./libli_std_string")) +; Note: when working with non-ascii strings in guile 2 +; locale must be set explicitly +; The setlocale call below takes care of that +(setlocale LC_ALL "") (load "../schemerunme/li_std_string.scm") diff --git a/Lib/guile/guile_scm_run.swg b/Lib/guile/guile_scm_run.swg index 2f8f3ae98..322d660c5 100644 --- a/Lib/guile/guile_scm_run.swg +++ b/Lib/guile/guile_scm_run.swg @@ -41,10 +41,14 @@ typedef struct swig_guile_clientdata { SCM goops_class; } swig_guile_clientdata; +#if SCM_MAJOR_VERSION <= 2 +#define scm_to_utf8_string scm_to_locale_string +#define scm_from_utf8_string scm_from_locale_string +#endif #define SWIG_scm2str(s) \ SWIG_Guile_scm2newstr(s, NULL) #define SWIG_str02scm(str) \ - str ? scm_from_locale_string(str) : SCM_BOOL_F + str ? scm_from_utf8_string(str) : SCM_BOOL_F # define SWIG_malloc(size) \ scm_malloc(size) # define SWIG_free(mem) \ @@ -84,21 +88,13 @@ SWIGINTERN char * SWIG_Guile_scm2newstr(SCM str, size_t *len) { #define FUNC_NAME "SWIG_Guile_scm2newstr" char *ret; - char *tmp; - size_t l; SCM_ASSERT (scm_is_string(str), str, 1, FUNC_NAME); - l = scm_c_string_length(str); - ret = (char *) SWIG_malloc( (l + 1) * sizeof(char)); + ret = scm_to_utf8_string(str); if (!ret) return NULL; - tmp = scm_to_locale_string(str); - memcpy(ret, tmp, l); - free(tmp); - - ret[l] = '\0'; - if (len) *len = l; + if (len) *len = strlen(ret) - 1; return ret; #undef FUNC_NAME } @@ -473,7 +469,7 @@ SWIG_Guile_GetArgs (SCM *dest, SCM rest, int num_args_passed = 0; for (i = 0; i Date: Wed, 5 Feb 2014 15:18:51 -0800 Subject: [PATCH 0898/1160] Move setting required -stdlib argument into configure.ac --- Examples/Makefile.in | 2 +- configure.ac | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 7680908ab..fc17d8784 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -25,7 +25,7 @@ TARGET = CC = @CC@ CXX = @CXX@ CFLAGS = @PLATCFLAGS@ -CXXFLAGS = @BOOST_CPPFLAGS@ @PLATCXXFLAGS@ $(filter -stdlib%,@CXXFLAGS@) +CXXFLAGS = @BOOST_CPPFLAGS@ @PLATCXXFLAGS@ prefix = @prefix@ exec_prefix= @exec_prefix@ SRCS = diff --git a/configure.ac b/configure.ac index 03677f90d..d05eb1802 100644 --- a/configure.ac +++ b/configure.ac @@ -352,6 +352,15 @@ if test x"$enable_cpp11_testing" = xyes; then fi fi +# On darwin before Mavericks when using clang, need to ensure using +# libc++ for tests and examples to run under mono +case $host in + *-*-darwin*) if test "$CXX" = "clang++"; + then PLATCXXFLAGS="$PLATCXXFLAGS -stdlib=libc++" + fi;; + *) ;; +esac + # Set info about shared libraries. AC_SUBST(SO) AC_SUBST(LDSHARED) From fd85d12a2cd5dc31e6f9a0d0a29bfd61bd8865f4 Mon Sep 17 00:00:00 2001 From: Marvin Greenberg Date: Wed, 5 Feb 2014 15:31:57 -0800 Subject: [PATCH 0899/1160] Allow csharp examples to run under mono --- Examples/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index fc17d8784..dac3f2c37 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1205,7 +1205,7 @@ CSHARPCOMPILER = @CSHARPCOMPILER@ CSHARPCILINTERPRETER = @CSHARPCILINTERPRETER@ CSHARPCFLAGS = @CSHARPCFLAGS@ CSHARPSO = @CSHARPSO@ -CSHARP_RUNME = ./$(RUNME).exe +CSHARP_RUNME = $(CSHARPCILINTERPRETER) ./$(RUNME).exe # ---------------------------------------------------------------- # Build a CSharp dynamically loadable module (C) From 844695b674d67e2c3bb0b1db48286a7dcea40423 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 6 Feb 2014 19:28:28 +0000 Subject: [PATCH 0900/1160] Fix typedef_typedef test --- Examples/test-suite/python/typedef_typedef_runme.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/python/typedef_typedef_runme.py b/Examples/test-suite/python/typedef_typedef_runme.py index 51a823def..1d83065a6 100644 --- a/Examples/test-suite/python/typedef_typedef_runme.py +++ b/Examples/test-suite/python/typedef_typedef_runme.py @@ -1,5 +1,5 @@ import typedef_typedef b = typedef_typedef.B() -if b.getValue(123) == 1234: - print "Failed !!!" +if b.getValue(123) != 1234: + raise Exception("Failed") From 56cea1821d2df2a4c0931bde072bbeba90b13ec5 Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Thu, 6 Feb 2014 23:47:01 +0400 Subject: [PATCH 0901/1160] warning filter fixed --- Examples/test-suite/nested_class.i | 20 +++++++++++++++++++- Source/CParse/parser.y | 11 ++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Examples/test-suite/nested_class.i b/Examples/test-suite/nested_class.i index 73bf89eb0..1cdfaade6 100644 --- a/Examples/test-suite/nested_class.i +++ b/Examples/test-suite/nested_class.i @@ -1,7 +1,25 @@ %module nested_class #pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS -#pragma SWIG nowarn=SWIGWARN_PARSE_NAMED_NESTED_CLASS +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct1; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass1; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion1; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass2; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct2; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion2; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass4Typedef; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct4Typedef; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion4Typedef; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass5; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct5; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion5; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultiple; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleDerived; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleAnonTypedef1; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleNamedTypedef; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerSameName; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer2::IgnoreMe; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerSameName2; %inline %{ struct Outer { diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 77d253299..b8ff59f0b 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1076,7 +1076,7 @@ static void update_nested_classes(Node *n) * Create the nested class/struct/union as a forward declaration. * ----------------------------------------------------------------------------- */ -static Node *nested_forward_declaration(const char *storage, const char *kind, String *sname, String *name, Node *cpp_opt_declarators, Node* nested) { +static Node *nested_forward_declaration(const char *storage, const char *kind, String *sname, String *name, Node *cpp_opt_declarators) { Node *nn = 0; int warned = 0; @@ -1120,7 +1120,7 @@ static Node *nested_forward_declaration(const char *storage, const char *kind, S } if (nn && Equal(nodeType(nn), "classforward")) { - Node *n = nested; + Node *n = nn; SWIG_WARN_NODE_BEGIN(n); Swig_warning(WARN_PARSE_NAMED_NESTED_CLASS, cparse_file, cparse_line,"Nested %s not currently supported (%s ignored)\n", kind, sname ? sname : name); SWIG_WARN_NODE_END(n); @@ -1128,10 +1128,7 @@ static Node *nested_forward_declaration(const char *storage, const char *kind, S } if (!warned) { - Node *n = nested; - SWIG_WARN_NODE_BEGIN(n); Swig_warning(WARN_PARSE_UNNAMED_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", kind); - SWIG_WARN_NODE_END(n); } return nn; @@ -3628,7 +3625,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { if (cplus_mode == CPLUS_PRIVATE) { $$ = 0; /* skip private nested classes */ } else if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) { - $$ = nested_forward_declaration($1, $2, $3, Copy($3), $9, $$); + $$ = nested_forward_declaration($1, $2, $3, Copy($3), $9); } else if (nscope_inner) { /* this is tricky */ /* we add the declaration in the original namespace */ @@ -3741,7 +3738,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Swig_features_get(Swig_cparse_features(), Namespaceprefix, 0, 0, $$); if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) { String *name = n ? Copy(Getattr(n, "name")) : 0; - $$ = nested_forward_declaration($1, $2, 0, name, n, $$); + $$ = nested_forward_declaration($1, $2, 0, name, n); Swig_symbol_popscope(); Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); From 6b5e3665677327479c4a1181a2bf82984f211656 Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Thu, 6 Feb 2014 23:53:33 +0400 Subject: [PATCH 0902/1160] nested nested class warning filtered --- Examples/test-suite/nested_class.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/nested_class.i b/Examples/test-suite/nested_class.i index 1cdfaade6..b95db40cd 100644 --- a/Examples/test-suite/nested_class.i +++ b/Examples/test-suite/nested_class.i @@ -19,7 +19,7 @@ %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleNamedTypedef; %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerSameName; %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer2::IgnoreMe; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerSameName2; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerSameName::InnerSameName2; %inline %{ struct Outer { From b457f8f290528368b21ef8e3ab28528446ef280c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 6 Feb 2014 20:02:05 +0000 Subject: [PATCH 0903/1160] Changes entry for guile non-ascii strings fix --- CHANGES.current | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index c76a0c19f..7c257dfde 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-02-06: gjanssens + [Guile] Patch #133. Make scm to string conversion work with non-ascii strings. + Guile 2 has a completely rewritten string implementation. SWIG made some assumptions + that are no longer valid as to the internals of guile's string representation. + 2014-01-30: wsfulton [C#] Add new swigtype_inout.i library containing SWIGTYPE *& OUTPUT typemaps. From e9ecac929842033de4dc1149a4cb2aaba28afdbf Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Fri, 7 Feb 2014 07:39:07 +0400 Subject: [PATCH 0904/1160] warnings suppressed for deeply nested classes --- Examples/test-suite/nested_class.i | 1 - Source/CParse/parser.y | 20 +++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Examples/test-suite/nested_class.i b/Examples/test-suite/nested_class.i index b95db40cd..ccb7ecac1 100644 --- a/Examples/test-suite/nested_class.i +++ b/Examples/test-suite/nested_class.i @@ -19,7 +19,6 @@ %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleNamedTypedef; %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerSameName; %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer2::IgnoreMe; -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerSameName::InnerSameName2; %inline %{ struct Outer { diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index b8ff59f0b..231b51cb3 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1119,16 +1119,18 @@ static Node *nested_forward_declaration(const char *storage, const char *kind, S } } - if (nn && Equal(nodeType(nn), "classforward")) { - Node *n = nn; - SWIG_WARN_NODE_BEGIN(n); - Swig_warning(WARN_PARSE_NAMED_NESTED_CLASS, cparse_file, cparse_line,"Nested %s not currently supported (%s ignored)\n", kind, sname ? sname : name); - SWIG_WARN_NODE_END(n); - warned = 1; - } + if (!GetFlag(currentOuterClass, "nested")) { + if (nn && Equal(nodeType(nn), "classforward")) { + Node *n = nn; + SWIG_WARN_NODE_BEGIN(n); + Swig_warning(WARN_PARSE_NAMED_NESTED_CLASS, cparse_file, cparse_line,"Nested %s not currently supported (%s ignored)\n", kind, sname ? sname : name); + SWIG_WARN_NODE_END(n); + warned = 1; + } - if (!warned) { - Swig_warning(WARN_PARSE_UNNAMED_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", kind); + if (!warned) { + Swig_warning(WARN_PARSE_UNNAMED_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", kind); + } } return nn; From 3518cbfd333945981bd98454c80be11975c965f0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Feb 2014 09:00:52 +0000 Subject: [PATCH 0905/1160] Typo in comment fix --- 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 231b51cb3..4c6d11e64 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1072,7 +1072,7 @@ static void update_nested_classes(Node *n) /* ----------------------------------------------------------------------------- * nested_forward_declaration() * - * Nested struct handling for C++ code if the nested classes are diasbled. + * Nested struct handling for C++ code if the nested classes are disabled. * Create the nested class/struct/union as a forward declaration. * ----------------------------------------------------------------------------- */ From 88de9f16101cb0fd8806b0a7b55ee80f24c1c04f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Feb 2014 09:45:20 +0000 Subject: [PATCH 0906/1160] Restore warning suppression in testcase --- Examples/test-suite/union_scope.i | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/test-suite/union_scope.i b/Examples/test-suite/union_scope.i index 67093eff6..b7307cb29 100644 --- a/Examples/test-suite/union_scope.i +++ b/Examples/test-suite/union_scope.i @@ -2,6 +2,7 @@ %warnfilter(SWIGWARN_RUBY_WRONG_NAME) nRState; // Ruby, wrong class name %warnfilter(SWIGWARN_RUBY_WRONG_NAME) nRState_rstate; // Ruby, wrong class name +#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS %inline %{ class nRState { From 3cf3be24abd8f5cf696c9eaf2d9d58785f05cf8a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Feb 2014 11:08:56 +0000 Subject: [PATCH 0907/1160] mkdist script tweaks to support releasing from any named branch --- Tools/mkdist.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Tools/mkdist.py b/Tools/mkdist.py index 234c768f2..2e69dbece 100755 --- a/Tools/mkdist.py +++ b/Tools/mkdist.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # This script builds a swig-x.y.z distribution. -# Usage : mkdist.py version, where version should be x.y.z +# Usage: mkdist.py version branch, where version should be x.y.z and branch is normally 'master' import sys import string @@ -16,10 +16,16 @@ def failed(): try: version = sys.argv[1] dirname = "swig-" + version + branch = sys.argv[2] except: - print "Usage: mkdist.py version, where version should be x.y.z" + print "Usage: mkdist.py version branch, where version should be x.y.z and branch is normally 'master'" sys.exit(1) +if sys.version_info[0:2] < (2, 7): + print "Error: Python 2.7 is required" + sys.exit(3) + + # Check name matches normal unix conventions if string.lower(dirname) != dirname: print "directory name ("+dirname+") should be in lowercase" @@ -38,7 +44,7 @@ os.system("rm -f "+dirname+".tar") # Grab the code from git print "Checking git repository is in sync with remote repository" -os.system("git remote update") == 0 or failed() +os.system("git remote update origin") == 0 or failed() command = ["git", "status", "--porcelain", "-uno"] out = subprocess.check_output(command) if out.strip() != "": @@ -47,7 +53,7 @@ if out.strip() != "": print out sys.exit(3) -command = ["git", "log", "--oneline", "master..origin/master"] +command = ["git", "log", "--oneline", branch + "..origin/" + branch] out = subprocess.check_output(command) if out.strip() != "": print "Remote repository has additional modifications to local repository" @@ -55,7 +61,7 @@ if out.strip() != "": print out sys.exit(3) -command = ["git", "log", "--oneline", "origin/master..master"] +command = ["git", "log", "--oneline", "origin/" + branch + ".." + branch] out = subprocess.check_output(command) if out.strip() != "": print "Local repository has modifications not pushed to the remote repository" From 4e9ee78d3eace3f234a3fd5e08e410bb3ca092a5 Mon Sep 17 00:00:00 2001 From: Atri Date: Tue, 1 Oct 2013 01:28:26 +0530 Subject: [PATCH 0908/1160] Lua: Fix void return for non-void functions Commit #c3f3880d caused the functions SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* ns) and SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns) to return void when int returns were expected resulting in the build failures for plplot's lua bindings for example. This commit fixes the issue. Closes #92 --- Lib/lua/luarun.swg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 4d851bdb1..8485ed499 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -524,7 +524,7 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* /* clear stack - remove metatble */ lua_pop(L,1); - + return 0; } /* helper function. creates namespace table and add it to module table */ @@ -555,6 +555,7 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns) lua_setmetatable(L,-2); /* set metatable */ lua_rawset(L,-3); /* add namespace to module table */ + return 0; } /* ----------------------------------------------------------------------------- * global variable support code: classes From f0b60d0ec9fc46cdb17c1f84b2d42231a7313572 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Feb 2014 14:36:10 +0000 Subject: [PATCH 0909/1160] Bump version to 2.0.12 --- ANNOUNCE | 8 +-- CHANGES | 137 ++++++++++++++++++++++++++++++++++++++ CHANGES.current | 138 +-------------------------------------- Doc/Manual/Sections.html | 2 +- README | 2 +- configure.ac | 2 +- 6 files changed, 146 insertions(+), 143 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index caaa55d8c..06a24ccb7 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,8 +1,8 @@ -*** ANNOUNCE: SWIG 2.0.11 (15 Sep 2013) *** +*** ANNOUNCE: SWIG 2.0.12 (9 Feb 2014) *** http://www.swig.org -We're pleased to announce SWIG-2.0.11, the latest SWIG release. +We're pleased to announce SWIG-2.0.12, 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.11.tar.gz + http://prdownloads.sourceforge.net/swig/swig-2.0.12.tar.gz A Windows version is also available at - http://prdownloads.sourceforge.net/swig/swigwin-2.0.11.zip + http://prdownloads.sourceforge.net/swig/swigwin-2.0.12.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 488bf7286..b40597e26 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,143 @@ SWIG (Simplified Wrapper and Interface Generator) See the CHANGES.current file for changes in the current version. See the RELEASENOTES file for a summary of changes in each release. +Version 2.0.11 (15 Sep 2013) +============================ + +2013-09-15: wsfulton + [R] Fix attempt to free a non-heap object in OUTPUT typemaps for: + unsigned short *OUTPUT + unsigned long *OUTPUT + signed long long *OUTPUT + char *OUTPUT + signed char*OUTPUT + unsigned char*OUTPUT + +2013-09-12: wsfulton + [Lua] Pull Git patch #62. + 1) Static members and static functions inside class can be accessed as + ModuleName.ClassName.FunctionName (MemberName respectively). Old way such as + ModuleName.ClassName_FunctionName still works. + 2) Same goes for enums inside classes: ModuleName.ClassName.EnumValue1 etc. + +2013-09-12: wsfulton + [UTL] Infinity is now by default an acceptable value for type 'float'. This fix makes + the handling of type 'float' and 'double' the same. The implementation requires the + C99 isfinite() macro, or otherwise some platform dependent equivalents, to be available. + + Users requiring the old behaviour of not accepting infinity, can define a 'check' typemap + wherever a float is used, such as: + + %typemap(check,fragment="") float, const float & %{ + if ($1 < -FLT_MAX || $1 > FLT_MAX) { + SWIG_exception_fail(SWIG_TypeError, "Overflow in type float"); + } + %} + + *** POTENTIAL INCOMPATIBILITY *** + +2013-08-30: wsfulton + [Lua] Pull Git patch #81: Include Lua error locus in SWIG error messages. + This is standard information in Lua error messages, and makes it much + easier to find bugs. + +2013-08-29: wsfulton + Pull Git patch #75: Handle UTF-8 files with BOM at beginning of file. Was giving an + 'Illegal token' syntax error. + +2013-08-29: wsfulton + [C#] Pull Git patch #77: Allow exporting std::map using non-default comparison function. + +2013-08-28: wsfulton + [Python] %implicitconv is improved for overloaded functions. Like in C++, the methods + with the actual types are considered before trying implicit conversions. Example: + + %implicitconv A; + struct A { + A(int i); + }; + class CCC { + public: + int xx(int i) { return 11; } + int xx(const A& i) { return 22; } + }; + + The following python code: + + CCC().xx(-1) + + will now return 11 instead of 22 - the implicit conversion is not done. + +2013-08-23: olly + [Python] Fix clang++ warning in generated wrapper code. + +2013-08-16: wsfulton + [Python] %implicitconv will now accept None where the implicit conversion takes a C/C++ pointer. + Problem highlighted by Bo Peng. Closes SF patch #230. + +2013-08-07: wsfulton + [Python] SF Patch #326 from Kris Thielemans - Remove SwigPyObject_print and SwigPyObject_str and + make the generated wrapper use the default python implementations, which will fall back to repr + (for -builtin option). + + Advantages: + - it avoids the swig user having to jump through hoops to get print to work as expected when + redefining repr/str slots. + - typing the name of a variable on the python prompt now prints the result of a (possibly redefined) + repr, without the swig user having to do any extra work. + - when redefining repr, the swig user doesn't necessarily have to redefine str as it will call the + redefined repr + - the behaviour is exactly the same as without the -builtin option while requiring no extra work + by the user (aside from adding the %feature("python:slot...) statements of course) + + Disadvantage: + - default str() will give different (but clearer?) output on swigged classes + +2013-07-30: wsfulton + [Python, Ruby] Fix #64 #65: Missing code in std::multimap wrappers. Previously an instantiation + of a std::map was erroneously required in addition to an instantiation of std::multimap with the + same template parameters to prevent compilation errors for the wrappers of a std::multimap. + +2013-07-14: joequant + [R] Change types file to allow for SEXP return values + +2013-07-05: wsfulton + [Python] Add %pythonbegin directive which works like %pythoncode, except the specified code is + added at the beginning of the generated .py file. This is primarily needed for importing from + __future__ statements required to be at the very beginning of the file. Example: + + %pythonbegin %{ + from __future__ import print_function + print("Loading", "Whizz", "Bang", sep=' ... ') + %} + +2013-07-01: wsfulton + [Python] Apply SF patch #340 - Uninitialized variable fix in SWIG_Python_NonDynamicSetAttr + when using -builtin. + +2013-07-01: wsfulton + [Python, Ruby, Ocaml] Apply SF patch #341 - fix a const_cast in generated code that was generating + a <:: digraph when using the unary scope operator (::) (global scope) in a template type. + +2013-07-01: wsfulton + [Python] Add SF patch #342 from Christian Delbaere to fix some director classes crashing on + object deletion when using -builtin. Fixes SF bug #1301. + +2013-06-11: wsfulton + [Python] Add SWIG_PYTHON_INTERPRETER_NO_DEBUG macro which can be defined to use the Release version + of the Python interpreter in Debug builds of the wrappers. The Visual Studio .dsp example + files have been modified to use this so that Debug builds will now work without having + to install or build a Debug build of the interpreter. + +2013-06-07: wsfulton + [Ruby] Git issue #52. Fix regression with missing rb_complex_new function for Ruby + versions prior to 1.9 using std::complex wrappers if just using std::complex as an output type. + Also fix the Complex helper functions external visibility (to static by default). + +2013-06-04: olly + [PHP] Fix SWIG_ZTS_ConvertResourcePtr() not to dereference NULL + if the type lookup fails. + Version 2.0.10 (27 May 2013) ============================ diff --git a/CHANGES.current b/CHANGES.current index 1727ecb2c..f2dfaea26 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,140 +2,6 @@ Below are the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.11 (15 Sep 2013) -============================ - -2013-09-15: wsfulton - [R] Fix attempt to free a non-heap object in OUTPUT typemaps for: - unsigned short *OUTPUT - unsigned long *OUTPUT - signed long long *OUTPUT - char *OUTPUT - signed char*OUTPUT - unsigned char*OUTPUT - -2013-09-12: wsfulton - [Lua] Pull Git patch #62. - 1) Static members and static functions inside class can be accessed as - ModuleName.ClassName.FunctionName (MemberName respectively). Old way such as - ModuleName.ClassName_FunctionName still works. - 2) Same goes for enums inside classes: ModuleName.ClassName.EnumValue1 etc. - -2013-09-12: wsfulton - [UTL] Infinity is now by default an acceptable value for type 'float'. This fix makes - the handling of type 'float' and 'double' the same. The implementation requires the - C99 isfinite() macro, or otherwise some platform dependent equivalents, to be available. - - Users requiring the old behaviour of not accepting infinity, can define a 'check' typemap - wherever a float is used, such as: - - %typemap(check,fragment="") float, const float & %{ - if ($1 < -FLT_MAX || $1 > FLT_MAX) { - SWIG_exception_fail(SWIG_TypeError, "Overflow in type float"); - } - %} - - *** POTENTIAL INCOMPATIBILITY *** - -2013-08-30: wsfulton - [Lua] Pull Git patch #81: Include Lua error locus in SWIG error messages. - This is standard information in Lua error messages, and makes it much - easier to find bugs. - -2013-08-29: wsfulton - Pull Git patch #75: Handle UTF-8 files with BOM at beginning of file. Was giving an - 'Illegal token' syntax error. - -2013-08-29: wsfulton - [C#] Pull Git patch #77: Allow exporting std::map using non-default comparison function. - -2013-08-28: wsfulton - [Python] %implicitconv is improved for overloaded functions. Like in C++, the methods - with the actual types are considered before trying implicit conversions. Example: - - %implicitconv A; - struct A { - A(int i); - }; - class CCC { - public: - int xx(int i) { return 11; } - int xx(const A& i) { return 22; } - }; - - The following python code: - - CCC().xx(-1) - - will now return 11 instead of 22 - the implicit conversion is not done. - -2013-08-23: olly - [Python] Fix clang++ warning in generated wrapper code. - -2013-08-16: wsfulton - [Python] %implicitconv will now accept None where the implicit conversion takes a C/C++ pointer. - Problem highlighted by Bo Peng. Closes SF patch #230. - -2013-08-07: wsfulton - [Python] SF Patch #326 from Kris Thielemans - Remove SwigPyObject_print and SwigPyObject_str and - make the generated wrapper use the default python implementations, which will fall back to repr - (for -builtin option). - - Advantages: - - it avoids the swig user having to jump through hoops to get print to work as expected when - redefining repr/str slots. - - typing the name of a variable on the python prompt now prints the result of a (possibly redefined) - repr, without the swig user having to do any extra work. - - when redefining repr, the swig user doesn't necessarily have to redefine str as it will call the - redefined repr - - the behaviour is exactly the same as without the -builtin option while requiring no extra work - by the user (aside from adding the %feature("python:slot...) statements of course) - - Disadvantage: - - default str() will give different (but clearer?) output on swigged classes - -2013-07-30: wsfulton - [Python, Ruby] Fix #64 #65: Missing code in std::multimap wrappers. Previously an instantiation - of a std::map was erroneously required in addition to an instantiation of std::multimap with the - same template parameters to prevent compilation errors for the wrappers of a std::multimap. - -2013-07-14: joequant - [R] Change types file to allow for SEXP return values - -2013-07-05: wsfulton - [Python] Add %pythonbegin directive which works like %pythoncode, except the specified code is - added at the beginning of the generated .py file. This is primarily needed for importing from - __future__ statements required to be at the very beginning of the file. Example: - - %pythonbegin %{ - from __future__ import print_function - print("Loading", "Whizz", "Bang", sep=' ... ') - %} - -2013-07-01: wsfulton - [Python] Apply SF patch #340 - Uninitialized variable fix in SWIG_Python_NonDynamicSetAttr - when using -builtin. - -2013-07-01: wsfulton - [Python, Ruby, Ocaml] Apply SF patch #341 - fix a const_cast in generated code that was generating - a <:: digraph when using the unary scope operator (::) (global scope) in a template type. - -2013-07-01: wsfulton - [Python] Add SF patch #342 from Christian Delbaere to fix some director classes crashing on - object deletion when using -builtin. Fixes SF bug #1301. - -2013-06-11: wsfulton - [Python] Add SWIG_PYTHON_INTERPRETER_NO_DEBUG macro which can be defined to use the Release version - of the Python interpreter in Debug builds of the wrappers. The Visual Studio .dsp example - files have been modified to use this so that Debug builds will now work without having - to install or build a Debug build of the interpreter. - -2013-06-07: wsfulton - [Ruby] Git issue #52. Fix regression with missing rb_complex_new function for Ruby - versions prior to 1.9 using std::complex wrappers if just using std::complex as an output type. - Also fix the Complex helper functions external visibility (to static by default). - -2013-06-04: olly - [PHP] Fix SWIG_ZTS_ConvertResourcePtr() not to dereference NULL - if the type lookup fails. +Version 2.0.12 (9 Feb 2014) +=========================== diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 2dfb438f8..9a9c0cc68 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

    SWIG-2.0 Documentation

    -Last update : SWIG-2.0.11 (15 Sep 2013) +Last update : SWIG-2.0.12 (9 Feb 2014)

    Sections

    diff --git a/README b/README index 946bd9a8f..664e78046 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.11 (15 Sep 2013) +Version: 2.0.12 (9 Feb 2014) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, C#, D, Go, Lua, diff --git a/configure.ac b/configure.ac index c4db3ce98..0c984b70b 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. dnl The macros which aren't shipped with the autotools are stored in the dnl Tools/config directory in .m4 files. -AC_INIT([swig],[2.0.11],[http://www.swig.org]) +AC_INIT([swig],[2.0.12],[http://www.swig.org]) dnl NB: When this requirement is increased to 2.60 or later, AC_PROG_SED dnl definition below can be removed From d94924a5c45237ce6cfa1104538f3cdd837680bd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 12 Oct 2013 17:50:29 +0100 Subject: [PATCH 0910/1160] Add change note for missing Lua return statements Conflicts: CHANGES.current --- CHANGES.current | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index f2dfaea26..41d02270c 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,3 +5,7 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.12 (9 Feb 2014) =========================== +2013-10-12: wsfulton + [Lua] Apply #92 - missing return statements for SWIG_Lua_add_namespace_details() + and SWIG_Lua_namespace_register(). + From c2f5813ffaf92e098b4fbc980b3e102744fcd4b9 Mon Sep 17 00:00:00 2001 From: Robert Stone Date: Thu, 14 Nov 2013 11:19:11 -0800 Subject: [PATCH 0911/1160] fix "long long" tests for perl v5.6 --- Examples/test-suite/perl5/li_typemaps_runme.pl | 18 +++++++++++------- .../perl5/reference_global_vars_runme.pl | 11 ++++++----- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Examples/test-suite/perl5/li_typemaps_runme.pl b/Examples/test-suite/perl5/li_typemaps_runme.pl index c182cdbb1..a573b89a0 100644 --- a/Examples/test-suite/perl5/li_typemaps_runme.pl +++ b/Examples/test-suite/perl5/li_typemaps_runme.pl @@ -41,8 +41,8 @@ batch('schar', -0x80, 0, 1, 12, 0x7f); use Math::BigInt qw(); # the pack dance is to get plain old NVs out of the # Math::BigInt objects. - my $inf = unpack 'd', pack 'd', Math::BigInt->binf(); - my $nan = unpack 'd', pack 'd', Math::BigInt->bnan(); + my $inf = unpack 'd', pack 'd', Math::BigInt->new('Inf'); + my $nan = unpack 'd', pack 'd', Math::BigInt->new('NaN'); batch('float', -(2 - 2 ** -23) * 2 ** 127, -1, -2 ** -149, 0, 2 ** -149, 1, @@ -63,12 +63,16 @@ batch('schar', -0x80, 0, 1, 12, 0x7f); batch('longlong', -1, 0, 1, 12); batch('ulonglong', 0, 1, 12); SKIP: { - my $a = "8000000000000000"; - my $b = "7fffffffffffffff"; - my $c = "ffffffffffffffff"; + use Math::BigInt qw(); skip "not a 64bit Perl", 18 unless eval { pack 'q', 1 }; - batch('longlong', -hex($a), hex($b)); - batch('ulonglong', hex($c)); + my $a = unpack 'q', pack 'q', + Math::BigInt->new('-9223372036854775808'); + my $b = unpack 'q', pack 'q', + Math::BigInt->new('9223372036854775807'); + my $c = unpack 'Q', pack 'Q', + Math::BigInt->new('18446744073709551615'); + batch('longlong', $a, $b); + batch('ulonglong', $c); } my($foo, $int) = li_typemaps::out_foo(10); diff --git a/Examples/test-suite/perl5/reference_global_vars_runme.pl b/Examples/test-suite/perl5/reference_global_vars_runme.pl index dfbcf15bb..89d73b03d 100755 --- a/Examples/test-suite/perl5/reference_global_vars_runme.pl +++ b/Examples/test-suite/perl5/reference_global_vars_runme.pl @@ -53,12 +53,13 @@ $cvar->{var_unsigned_long} = createref_unsigned_long(10); is(value_unsigned_long($cvar->{var_unsigned_long}), 10); SKIP: { - my $a = "6FFFFFFFFFFFFFF8"; + use Math::BigInt qw(); skip "64 bit int support", 1 unless eval { pack 'q', 1 }; - # using hex() here instead of a literal because non 64bit Perls will - # be noisy about big constants. - $cvar->{var_long_long} = createref_long_long(hex $a); - is(value_long_long($cvar->{var_long_long}), hex $a); + # the pack dance is to get plain old IVs out of the + # Math::BigInt objects. + my $a = unpack 'q', pack 'q', Math::BigInt->new('8070450532247928824'); + $cvar->{var_long_long} = createref_long_long($a); + is(value_long_long($cvar->{var_long_long}), $a); } #ull = abs(0xFFFFFFF2FFFFFFF0) From 5602a61bb6fa2b6de419c251fceb2e5cd499893d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 17 Oct 2013 19:56:18 +0100 Subject: [PATCH 0912/1160] Add missing #include for offsetof when using -builtin. Fixes SF #1345 Conflicts: CHANGES.current --- CHANGES.current | 3 +++ Lib/python/pyinit.swg | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 41d02270c..bde32009e 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.12 (9 Feb 2014) =========================== +2013-10-17: wsfulton + [Python] Fix SF #1345 - Missing #include for offsetof when using -builtin. + 2013-10-12: wsfulton [Lua] Apply #92 - missing return statements for SWIG_Lua_add_namespace_details() and SWIG_Lua_namespace_register(). diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 6a6de0963..79df023de 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -4,6 +4,10 @@ %insert(init) "swiginit.swg" +#if defined(SWIGPYTHON_BUILTIN) +%fragment(""); // For offsetof +#endif + %init %{ #ifdef __cplusplus From 122f61cb0bcedb15db0612f9519de4d396f75efc Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 17 Oct 2013 21:54:58 +0100 Subject: [PATCH 0913/1160] Fix Visual Studio compile error in C++ wrappers due to #include within extern "C" block. Fixes SF #1340 --- CHANGES.current | 4 ++++ Lib/r/rrun.swg | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index bde32009e..0507350cd 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.12 (9 Feb 2014) =========================== +2013-10-17: wsfulton + [R] Fix SF #1340 - Visual Studio compile error in C++ wrappers due to #include + within extern "C" block. + 2013-10-17: wsfulton [Python] Fix SF #1345 - Missing #include for offsetof when using -builtin. diff --git a/Lib/r/rrun.swg b/Lib/r/rrun.swg index f8bc9f497..990443e23 100644 --- a/Lib/r/rrun.swg +++ b/Lib/r/rrun.swg @@ -1,5 +1,6 @@ #ifdef __cplusplus +#include extern "C" { #endif @@ -369,7 +370,6 @@ SWIG_R_ConvertPacked(SEXP obj, void *ptr, size_t sz, swig_type_info *ty) { } #ifdef __cplusplus -#include #define SWIG_exception_noreturn(code, msg) do { throw std::runtime_error(msg); } while(0) #else #define SWIG_exception_noreturn(code, msg) do { return result; } while(0) From 7b5eb19ca98be89440c661944b53211096542bda Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 18 Oct 2013 06:49:20 +0100 Subject: [PATCH 0914/1160] Fix unused variable warning in Ruby wrappers when using gcc -Wall --- Lib/ruby/rubyprimtypes.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/ruby/rubyprimtypes.swg b/Lib/ruby/rubyprimtypes.swg index df72e97f4..aa4f7ad37 100644 --- a/Lib/ruby/rubyprimtypes.swg +++ b/Lib/ruby/rubyprimtypes.swg @@ -193,7 +193,7 @@ SWIG_AsVal_dec(unsigned long long)(VALUE obj, unsigned long long *val) } %fragment(SWIG_AsVal_frag(double),"header",fragment="SWIG_ruby_failed") { -%ruby_aux_method(double, NUM2DBL, NUM2DBL(obj)) +%ruby_aux_method(double, NUM2DBL, NUM2DBL(obj); (void)type) SWIGINTERN int SWIG_AsVal_dec(double)(VALUE obj, double *val) From acc5a5eb2d9ba7ab95cf5bb22221ba503c249de1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 22 Dec 2013 19:39:21 +0000 Subject: [PATCH 0915/1160] C++11 support for new versions of erase and insert in the STL containers. The erase and insert methods in the containers use const_iterator instead of iterator in C++11. There are times when the methods wrapped must match the parameters exactly. Specifically when full type information for template types is missing or SWIG fails to look up the type correctly, for example: %include typedef float Real; %template(RealVector) std::vector; SWIG does not find std::vector::iterator because %template using typedefs does not always work and so SWIG doesn't know if the type is copyable and so uses SwigValueWrapper which does not support conversion to another type (const_iterator). This resulted in compilation errors when using the C++11 version of the containers. Closes #73 Conflicts: CHANGES.current Lib/std/std_unordered_map.i Lib/std/std_unordered_set.i --- CHANGES.current | 21 +++++++++++++++++++++ Lib/std/std_container.i | 21 +++++++++++++++------ Lib/std/std_map.i | 8 +++++--- Lib/std/std_set.i | 7 +++++-- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 0507350cd..d23246f6c 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,27 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.12 (9 Feb 2014) =========================== +2013-12-22: wsfulton + C++11 support for new versions of erase and insert in the STL containers. + + The erase and insert methods in the containers use const_iterator instead + of iterator in C++11. There are times when the methods wrapped must match + the parameters exactly. Specifically when full type information for + template types is missing or SWIG fails to look up the type correctly, + for example: + + %include + typedef float Real; + %template(RealVector) std::vector; + + SWIG does not find std::vector::iterator because %template using + typedefs does not always work and so SWIG doesn't know if the type is + copyable and so uses SwigValueWrapper which does + not support conversion to another type (const_iterator). This resulted + in compilation errors when using the C++11 version of the containers. + + Closes #73 + 2013-10-17: wsfulton [R] Fix SF #1340 - Visual Studio compile error in C++ wrappers due to #include within extern "C" block. diff --git a/Lib/std/std_container.i b/Lib/std/std_container.i index 73d0c6ad9..8ed327bbe 100644 --- a/Lib/std/std_container.i +++ b/Lib/std/std_container.i @@ -46,8 +46,11 @@ void resize(size_type new_size); #ifdef SWIG_EXPORT_ITERATOR_METHODS - iterator erase(iterator pos); - iterator erase(iterator first, iterator last); +%extend { + // %extend wrapper used for differing definitions of these methods introduced in C++11 + iterator erase(iterator pos) { return $self->erase(pos); } + iterator erase(iterator first, iterator last) { return $self->erase(first, last); } +} #endif %enddef @@ -68,8 +71,11 @@ void resize(size_type new_size, const value_type& x); #ifdef SWIG_EXPORT_ITERATOR_METHODS - iterator insert(iterator pos, const value_type& x); - void insert(iterator pos, size_type n, const value_type& x); +%extend { + // %extend wrapper used for differing definitions of these methods introduced in C++11 + iterator insert(iterator pos, const value_type& x) { return $self->insert(pos, x); } + void insert(iterator pos, size_type n, const value_type& x) { $self->insert(pos, n, x); } +} #endif %enddef @@ -89,8 +95,11 @@ void resize(size_type new_size, value_type x); #ifdef SWIG_EXPORT_ITERATOR_METHODS - iterator insert(iterator pos, value_type x); - void insert(iterator pos, size_type n, value_type x); +%extend { + // %extend wrapper used for differing definitions of these methods introduced in C++11 + iterator insert(iterator pos, value_type x) { return $self->insert(pos, x); } + void insert(iterator pos, size_type n, value_type x) { $self->insert(pos, n, x); } +} #endif %enddef diff --git a/Lib/std/std_map.i b/Lib/std/std_map.i index 05208418f..e523c3deb 100644 --- a/Lib/std/std_map.i +++ b/Lib/std/std_map.i @@ -12,9 +12,11 @@ size_type count(const key_type& x) const; #ifdef SWIG_EXPORT_ITERATOR_METHODS -// iterator insert(iterator position, const value_type& x); - void erase(iterator position); - void erase(iterator first, iterator last); +%extend { + // %extend wrapper used for differing definitions of these methods introduced in C++11 + void erase(iterator position) { $self->erase(position); } + void erase(iterator first, iterator last) { $self->erase(first, last); } +} iterator find(const key_type& x); iterator lower_bound(const key_type& x); diff --git a/Lib/std/std_set.i b/Lib/std/std_set.i index 16f0f1482..f96ddd9f1 100644 --- a/Lib/std/std_set.i +++ b/Lib/std/std_set.i @@ -29,8 +29,11 @@ reverse_iterator rbegin(); reverse_iterator rend(); - void erase(iterator pos); - void erase(iterator first, iterator last); +%extend { + // %extend wrapper used for differing definitions of these methods introduced in C++11 + void erase(iterator pos) { $self->erase(pos); } + void erase(iterator first, iterator last) { $self->erase(first, last); } +} iterator find(const key_type& x); iterator lower_bound(const key_type& x); From 78f92962e207c152a40783181aaf0c77e506cb3b Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 13 Jan 2014 18:24:17 +1300 Subject: [PATCH 0916/1160] octave: update support to Octave version 3.8.0 Conflicts: CHANGES.current --- CHANGES.current | 26 ++++++++++ Doc/Manual/Octave.html | 7 +-- Lib/octave/octrun.swg | 102 ++++++++++++++++++++++++++++++++------ Lib/octave/octruntime.swg | 14 +++--- 4 files changed, 121 insertions(+), 28 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index d23246f6c..28b403a6d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,32 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.12 (9 Feb 2014) =========================== +2014-01-13: kwwette + [Octave] update support to Octave version 3.8.0 + + - Octave 3.8.0 no longer defines OCTAVE_API_VERSION_NUMBER, but 3.8.1 + will define OCTAVE_{MAJOR,MINOR,PATCH}_VERSION instead: see + http://hg.savannah.gnu.org/hgweb/octave/rev/b6b6e0dc700e + So we now use a new macro SWIG_OCTAVE_PREREQ(major,minor,patch) to + enable features requiring Octave version major.minor.patch or later. + + For Octave versions prior to 3.8.1, we reconstruct values for + OCTAVE_{MAJOR,MINOR,PATCH}_VERSION based on OCTAVE_API_VERSION_NUMBER, + extracted from Octave's ChangeLogs. An additional hack is needed to + distinguish between Octave <= 3.2.x and 3.8.0, neither of which define + OCTAVE_API_VERSION_NUMBER. + + - Octave 3.8.0 deprecates symbol_table::varref(), so remove its use + for this and future versions of Octave. + + - Octave 3.8.0 removes octave_value::is_real_nd_array(), used in + octave_swig_type::dims(). Its use is not required here, so remove it. + + - Retested against Octave versions 3.0.5, 3.2.4, 3.4.3, 3.6.4, and 3.8.0. + + - Updated Octave documentation with tested Octave versions, and added a + warning against using versions <= 3.x.x, which are no longer tested. + 2013-12-22: wsfulton C++11 support for new versions of erase and insert in the STL containers. diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 84c0a0f46..3e12ce668 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -59,11 +59,8 @@ Also, there are a dozen or so examples in the Examples/octave directory, and hun

    -The SWIG implemention was first based on Octave 2.9.12, so this is the minimum version required. Testing has only been done on Linux. -

    - -

    -As of SWIG 2.0.7, the Octave module has been tested with Octave versions 3.0.5, 3.2.4, 3.4.3, and 3.6.1. +As of SWIG 3.0.0, the Octave module has been tested with Octave versions 3.0.5, 3.2.4, 3.4.3, 3.6.4, and 3.8.0. +Use of Octave versions older than 3.x.x is not recommended, as these versions are no longer tested with SWIG.

    30.2 Running SWIG

    diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 41d1c7afa..2174a0f7f 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -1,20 +1,88 @@ #include -#ifndef OCTAVE_API_VERSION_NUMBER - // Hack to distinguish between Octave 3.2 and earlier versions before OCTAVE_API_VERSION_NUMBER existed - #define ComplexLU __ignore - #include - #undef ComplexLU - #ifdef octave_Complex_LU_h - # define OCTAVE_API_VERSION_NUMBER 36 - #else - # define OCTAVE_API_VERSION_NUMBER 37 - #endif +// Macro for enabling features which require Octave version >= major.minor.patch +#define SWIG_OCTAVE_PREREQ(major, minor, patch) \ + ( (OCTAVE_MAJOR_VERSION<<16) + (OCTAVE_MINOR_VERSION<<8) + OCTAVE_PATCH_VERSION >= ((major)<<16) + ((minor)<<8) + (patch) ) -#endif +// Reconstruct Octave major, minor, and patch versions for releases prior to 3.8.1 +#if !defined(OCTAVE_MAJOR_VERSION) -#if OCTAVE_API_VERSION_NUMBER < 37 +# if !defined(OCTAVE_API_VERSION_NUMBER) + +// Hack to distinguish between Octave 3.8.0, which removed OCTAVE_API_VERSION_NUMBER but did not yet +// introduce OCTAVE_MAJOR_VERSION, and Octave <= 3.2, which did not define OCTAVE_API_VERSION_NUMBER +# include +# if defined(octave_ov_h) +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 8 +# define OCTAVE_PATCH_VERSION 0 +# else + +// Hack to distinguish between Octave 3.2 and earlier versions, before OCTAVE_API_VERSION_NUMBER existed +# define ComplexLU __ignore +# include +# undef ComplexLU +# if defined(octave_Complex_LU_h) + +// We know only that this version is prior to Octave 3.2, i.e. OCTAVE_API_VERSION_NUMBER < 37 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 1 +# define OCTAVE_PATCH_VERSION 99 + +# else + +// OCTAVE_API_VERSION_NUMBER == 37 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 2 +# define OCTAVE_PATCH_VERSION 0 + +# endif // defined(octave_Complex_LU_h) + +# endif // defined(octave_ov_h) + +// Correlation between Octave API and version numbers extracted from Octave's +// ChangeLogs; version is the *earliest* released Octave with that API number +# elif OCTAVE_API_VERSION_NUMBER >= 48 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 6 +# define OCTAVE_PATCH_VERSION 0 + +# elif OCTAVE_API_VERSION_NUMBER >= 45 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 4 +# define OCTAVE_PATCH_VERSION 1 + +# elif OCTAVE_API_VERSION_NUMBER >= 42 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 54 + +# elif OCTAVE_API_VERSION_NUMBER >= 41 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 53 + +# elif OCTAVE_API_VERSION_NUMBER >= 40 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 52 + +# elif OCTAVE_API_VERSION_NUMBER >= 39 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 51 + +# else // OCTAVE_API_VERSION_NUMBER == 38 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 50 + +# endif // !defined(OCTAVE_API_VERSION_NUMBER) + +#endif // !defined(OCTAVE_MAJOR_VERSION) + +#if !SWIG_OCTAVE_PREREQ(3,2,0) #define SWIG_DEFUN(cname, wname, doc) DEFUNX_DLD(#cname, wname, FS ## cname, args, nargout, doc) #else #define SWIG_DEFUN(cname, wname, doc) DEFUNX_DLD(#cname, wname, G ## cname, args, nargout, doc) @@ -427,7 +495,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); if (error_state) return dim_vector(1,1); } return d; - } else if (out.is_matrix_type() || out.is_real_nd_array() || out.is_numeric_type() ) { + } else if (out.is_matrix_type() || out.is_numeric_type() ) { if (out.rows()==1 || out.columns()==1) { Array a = out.int_vector_value(); if (error_state) return dim_vector(1,1); @@ -746,7 +814,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); return outarg(0).string_value(); } -#if OCTAVE_API_VERSION_NUMBER >= 40 +#if SWIG_OCTAVE_PREREQ(3,3,52) virtual octave_map map_value() const { return octave_map(); } @@ -982,7 +1050,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); virtual std::string string_value(bool force = false) const { return ptr->string_value(force); } -#if OCTAVE_API_VERSION_NUMBER >= 40 +#if SWIG_OCTAVE_PREREQ(3,3,52) virtual octave_map map_value() const { return ptr->map_value(); } #else @@ -1293,10 +1361,12 @@ SWIGRUNTIME void SWIG_Octave_SetGlobalValue(std::string name, const octave_value } SWIGRUNTIME void SWIG_Octave_LinkGlobalValue(std::string name) { -#if OCTAVE_API_VERSION_NUMBER < 37 +#if !SWIG_OCTAVE_PREREQ(3,2,0) link_to_global_variable(curr_sym_tab->lookup(name, true)); #else +#if !SWIG_OCTAVE_PREREQ(3,8,0) symbol_table::varref(name); +#endif symbol_table::mark_global(name); #endif } diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index 43313c3d4..fbf2007f6 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -25,7 +25,7 @@ static bool SWIG_init_user(octave_swig_type* module_ns); SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) { bool retn; { -#if OCTAVE_API_VERSION_NUMBER < 38 +#if !SWIG_OCTAVE_PREREQ(3,3,50) unwind_protect::begin_frame("SWIG_Octave_LoadModule"); unwind_protect_int(error_state); unwind_protect_int(warning_state); @@ -44,7 +44,7 @@ SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) { discard_warning_messages = true; feval(name, octave_value_list(), 0); retn = (error_state == 0); -#if OCTAVE_API_VERSION_NUMBER < 38 +#if !SWIG_OCTAVE_PREREQ(3,3,50) unwind_protect::run_frame("SWIG_Octave_LoadModule"); #endif } @@ -57,7 +57,7 @@ SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) { SWIGINTERN bool SWIG_Octave_InstallFunction(octave_function *octloadfcn, std::string name) { bool retn; { -#if OCTAVE_API_VERSION_NUMBER < 38 +#if !SWIG_OCTAVE_PREREQ(3,3,50) unwind_protect::begin_frame("SWIG_Octave_InstallFunction"); unwind_protect_int(error_state); unwind_protect_int(warning_state); @@ -80,7 +80,7 @@ SWIGINTERN bool SWIG_Octave_InstallFunction(octave_function *octloadfcn, std::st error_state = 0; feval("autoload", args, 0); retn = (error_state == 0); -#if OCTAVE_API_VERSION_NUMBER < 38 +#if !SWIG_OCTAVE_PREREQ(3,3,50) unwind_protect::run_frame("SWIG_Octave_InstallFunction"); #endif } @@ -196,7 +196,7 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { // definitely affects version 3.2.*, not sure about 3.3.*, seems to be fixed in // version 3.4.* and above. can be turned off with macro definition. #ifndef SWIG_OCTAVE_NO_SEGFAULT_HACK -#if 36 < OCTAVE_API_VERSION_NUMBER && OCTAVE_API_VERSION_NUMBER < 45 +#if SWIG_OCTAVE_PREREQ(3,2,0) && !SWIG_OCTAVE_PREREQ(3,4,1) octave_exit = ::_Exit; #endif #endif @@ -212,7 +212,7 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { // workaround bug in octave where installing global variable of custom type and then // exiting without explicitly clearing the variable causes octave to segfault. -#if OCTAVE_API_VERSION_NUMBER > 36 +#if SWIG_OCTAVE_PREREQ(3,2,0) octave_value_list eval_args; eval_args.append("base"); eval_args.append("function __swig_atexit__; " @@ -297,7 +297,7 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { } } -#if OCTAVE_API_VERSION_NUMBER < 37 +#if !SWIG_OCTAVE_PREREQ(3,2,0) mlock(me->name()); #else mlock(); From c569210dd59e252be5176cb3224cc7e354bb97c1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 16 Jan 2014 06:42:34 +0000 Subject: [PATCH 0917/1160] Fix PHP compilation error in ZTS mode (64 bit windows) due to TSRMLS_FETCH() expansion Conflicts: CHANGES.current --- CHANGES.current | 4 ++++ Lib/php/phprun.swg | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 28b403a6d..d55bb9716 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.12 (9 Feb 2014) =========================== +2014-01-16: wsfulton + [PHP] Fix compilation error in ZTS mode (64 bit windows) due to incorrect placement + of TSRMLS_FETCH() in SWIG_Php_GetModule() as reported by Mark Dawson-Butterworth. + 2014-01-13: kwwette [Octave] update support to Octave version 3.8.0 diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index a4188cc7c..063b84227 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -255,11 +255,10 @@ static char const_name[] = "swig_runtime_data_type_pointer"; static swig_module_info *SWIG_Php_GetModule(void *SWIGUNUSEDPARM(clientdata)) { zval *pointer; swig_module_info *ret = 0; + TSRMLS_FETCH(); MAKE_STD_ZVAL(pointer); - TSRMLS_FETCH(); - if (zend_get_constant(const_name, sizeof(const_name) - 1, pointer TSRMLS_CC)) { if (pointer->type == IS_LONG) { ret = (swig_module_info *) pointer->value.lval; From 36f5117b25fd6689e76bb0e2854e9df696631a2c Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Fri, 13 Dec 2013 17:48:26 +0100 Subject: [PATCH 0918/1160] Guile: make scm to string conversion work with non-ascii strings --- .../test-suite/guile/li_std_string_runme.scm | 4 ++++ Lib/guile/guile_scm_run.swg | 22 ++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Examples/test-suite/guile/li_std_string_runme.scm b/Examples/test-suite/guile/li_std_string_runme.scm index 5dde68f8d..5b5563281 100644 --- a/Examples/test-suite/guile/li_std_string_runme.scm +++ b/Examples/test-suite/guile/li_std_string_runme.scm @@ -2,4 +2,8 @@ ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. (dynamic-call "scm_init_li_std_string_module" (dynamic-link "./libli_std_string")) +; Note: when working with non-ascii strings in guile 2 +; locale must be set explicitly +; The setlocale call below takes care of that +(setlocale LC_ALL "") (load "../schemerunme/li_std_string.scm") diff --git a/Lib/guile/guile_scm_run.swg b/Lib/guile/guile_scm_run.swg index 0ac51f919..4978ab114 100644 --- a/Lib/guile/guile_scm_run.swg +++ b/Lib/guile/guile_scm_run.swg @@ -41,10 +41,14 @@ typedef struct swig_guile_clientdata { SCM goops_class; } swig_guile_clientdata; +#if SCM_MAJOR_VERSION <= 2 +#define scm_to_utf8_string scm_to_locale_string +#define scm_from_utf8_string scm_from_locale_string +#endif #define SWIG_scm2str(s) \ SWIG_Guile_scm2newstr(s, NULL) #define SWIG_str02scm(str) \ - str ? scm_from_locale_string(str) : SCM_BOOL_F + str ? scm_from_utf8_string(str) : SCM_BOOL_F # define SWIG_malloc(size) \ scm_malloc(size) # define SWIG_free(mem) \ @@ -84,21 +88,13 @@ SWIGINTERN char * SWIG_Guile_scm2newstr(SCM str, size_t *len) { #define FUNC_NAME "SWIG_Guile_scm2newstr" char *ret; - char *tmp; - size_t l; SCM_ASSERT (scm_is_string(str), str, 1, FUNC_NAME); - l = scm_c_string_length(str); - ret = (char *) SWIG_malloc( (l + 1) * sizeof(char)); + ret = scm_to_utf8_string(str); if (!ret) return NULL; - tmp = scm_to_locale_string(str); - memcpy(ret, tmp, l); - free(tmp); - - ret[l] = '\0'; - if (len) *len = l; + if (len) *len = strlen(ret) - 1; return ret; #undef FUNC_NAME } @@ -482,7 +478,7 @@ SWIG_Guile_GetArgs (SCM *dest, SCM rest, int num_args_passed = 0; for (i = 0; i Date: Wed, 5 Feb 2014 11:52:26 +0100 Subject: [PATCH 0919/1160] Guile: illustrate bug in non-ascii string handling --- Examples/test-suite/schemerunme/li_std_string.scm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/schemerunme/li_std_string.scm b/Examples/test-suite/schemerunme/li_std_string.scm index e77c32870..343b9b8e8 100644 --- a/Examples/test-suite/schemerunme/li_std_string.scm +++ b/Examples/test-suite/schemerunme/li_std_string.scm @@ -1,4 +1,6 @@ -(define x "hello") +; The test string has some non-ascii characters added +; because our guile wrappers had bugs in that area +(define x "hello - æææ") (if (not (string=? (test-value x) x)) (begin (error "Error 1") (exit 1))) From 7f8cb93092640ead96b3da60a6fb8c42eb0c13d9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Feb 2014 11:08:56 +0000 Subject: [PATCH 0920/1160] mkdist script tweaks to support releasing from any named branch --- Tools/mkdist.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Tools/mkdist.py b/Tools/mkdist.py index 234c768f2..2e69dbece 100755 --- a/Tools/mkdist.py +++ b/Tools/mkdist.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # This script builds a swig-x.y.z distribution. -# Usage : mkdist.py version, where version should be x.y.z +# Usage: mkdist.py version branch, where version should be x.y.z and branch is normally 'master' import sys import string @@ -16,10 +16,16 @@ def failed(): try: version = sys.argv[1] dirname = "swig-" + version + branch = sys.argv[2] except: - print "Usage: mkdist.py version, where version should be x.y.z" + print "Usage: mkdist.py version branch, where version should be x.y.z and branch is normally 'master'" sys.exit(1) +if sys.version_info[0:2] < (2, 7): + print "Error: Python 2.7 is required" + sys.exit(3) + + # Check name matches normal unix conventions if string.lower(dirname) != dirname: print "directory name ("+dirname+") should be in lowercase" @@ -38,7 +44,7 @@ os.system("rm -f "+dirname+".tar") # Grab the code from git print "Checking git repository is in sync with remote repository" -os.system("git remote update") == 0 or failed() +os.system("git remote update origin") == 0 or failed() command = ["git", "status", "--porcelain", "-uno"] out = subprocess.check_output(command) if out.strip() != "": @@ -47,7 +53,7 @@ if out.strip() != "": print out sys.exit(3) -command = ["git", "log", "--oneline", "master..origin/master"] +command = ["git", "log", "--oneline", branch + "..origin/" + branch] out = subprocess.check_output(command) if out.strip() != "": print "Remote repository has additional modifications to local repository" @@ -55,7 +61,7 @@ if out.strip() != "": print out sys.exit(3) -command = ["git", "log", "--oneline", "origin/master..master"] +command = ["git", "log", "--oneline", "origin/" + branch + ".." + branch] out = subprocess.check_output(command) if out.strip() != "": print "Local repository has modifications not pushed to the remote repository" From 3cd7055895c396701ca574de7cd46329728c26a5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Feb 2014 16:24:15 +0000 Subject: [PATCH 0921/1160] Temporary workaround for bug in Travis build environment --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 26758304f..e3d345972 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,6 +46,7 @@ before_install: - if test "$SWIGLANG" = "python" -a "$PY3"; then sudo apt-get install python3-dev; fi - if test "$SWIGLANG" = "tcl"; then sudo apt-get -qq install tcl8.4-dev; fi script: + - export PS4="+ " #Temporary workaround bug in Travis build environment - ./autogen.sh && ./configure - make -s $SWIGJOBS - if test -z "$SWIGLANG"; then make -s check-ccache; fi From 3c5de3457341f5eba0ddfc462df066c7974593e2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Feb 2014 19:13:43 +0000 Subject: [PATCH 0922/1160] Turn on Travis testing for maintenance-2.0 branch --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e3d345972..50fd3b66b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,3 +57,4 @@ script: branches: only: - master + - maintenance-2.0 From 885a7002835f447e87350e7601ea1518e31c8759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= Date: Fri, 29 Nov 2013 13:48:07 +0100 Subject: [PATCH 0923/1160] Make string encoding explitic Ruby 2.0 enforces explicit string encodings. The char_constant testcase fails because the internal (SWIG_FromCharPtrAndSize, using rb_str_new) defaults to ASCII-8BIT while the test-suite file defaults to the current shell LOCALE setting. This patch sets the char_constant_runme.rb encoding to ASCII-8BIT. --- Examples/test-suite/ruby/char_constant_runme.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/ruby/char_constant_runme.rb b/Examples/test-suite/ruby/char_constant_runme.rb index 4e9d9d59c..4c56ecbf7 100644 --- a/Examples/test-suite/ruby/char_constant_runme.rb +++ b/Examples/test-suite/ruby/char_constant_runme.rb @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -# +#Encoding: ASCII-8BIT # Put description here # # From 08639f7f248c5e0a7621750452ef53a6f6834378 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 9 Feb 2014 09:34:18 +0000 Subject: [PATCH 0924/1160] Add release summary for 2.0.12 --- RELEASENOTES | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/RELEASENOTES b/RELEASENOTES index 720dc9d34..756df81ff 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -4,6 +4,14 @@ and CHANGES files. Release Notes ============= +SWIG-2.0.12 summary: +- This is a maintenance release backporting some fixes from the pending + 3.0.0 release. +- Octave 3.8 support added. +- C++11 support for new versions of erase/insert in the STL containers. +- Compilation fixes on some systems for the generated Lua, PHP, Python + and R wrappers. + SWIG-2.0.11 summary: - Minor bug fixes and enhancements mostly in Python, but also C#, Lua, Ocaml, Octave, Perl, PHP, Python, R, Ruby, Tcl. From 1c4213594a6d12484553506b1f81c67e5a84d904 Mon Sep 17 00:00:00 2001 From: William Fulton Date: Sun, 9 Feb 2014 22:09:05 +0000 Subject: [PATCH 0925/1160] Release scripts to release from any branch --- Tools/mkrelease.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tools/mkrelease.py b/Tools/mkrelease.py index 9eceba07e..3f49ffd9d 100755 --- a/Tools/mkrelease.py +++ b/Tools/mkrelease.py @@ -15,9 +15,10 @@ def failed(message): try: version = sys.argv[1] - username = sys.argv[2] + branch = sys.argv[2] + username = sys.argv[3] except: - print "Usage: python mkrelease.py version username" + print "Usage: python mkrelease.py version branch username" print "where version should be x.y.z and username is your SF username" sys.exit(1) @@ -25,7 +26,7 @@ print "Looking for rsync" os.system("which rsync") and failed("rsync not installed/found. Please install.") print "Making source tarball" -os.system("python ./mkdist.py " + version) and failed("") +os.system("python ./mkdist.py " + version + " " + branch) and failed("") print "Build Windows package" os.system("./mkwindows.sh " + version) and failed("") From 05f92e9fbd5718a8b6e9698aa467e6c047256da2 Mon Sep 17 00:00:00 2001 From: William Fulton Date: Sun, 9 Feb 2014 22:09:05 +0000 Subject: [PATCH 0926/1160] Release scripts to release from any branch --- Tools/mkrelease.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tools/mkrelease.py b/Tools/mkrelease.py index 0623fe786..ec9a2b76a 100755 --- a/Tools/mkrelease.py +++ b/Tools/mkrelease.py @@ -15,9 +15,10 @@ def failed(message): try: version = sys.argv[1] - username = sys.argv[2] + branch = sys.argv[2] + username = sys.argv[3] except: - print "Usage: python mkrelease.py version username" + print "Usage: python mkrelease.py version branch username" print "where version should be x.y.z and username is your SF username" sys.exit(1) @@ -25,7 +26,7 @@ print "Looking for rsync" os.system("which rsync") and failed("rsync not installed/found. Please install.") print "Making source tarball" -os.system("python ./mkdist.py " + version) and failed("") +os.system("python ./mkdist.py " + version + " " + branch) and failed("") print "Build Windows package" os.system("./mkwindows.sh " + version) and failed("") From d35af986468da6f61d5a660f13b260810323fb55 Mon Sep 17 00:00:00 2001 From: Marvin Greenberg Date: Wed, 12 Feb 2014 14:16:43 -0500 Subject: [PATCH 0927/1160] Change to only add -stdlib on OSX versions that have libc++ Use better test for clang --- configure.ac | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index d05eb1802..aead05c21 100644 --- a/configure.ac +++ b/configure.ac @@ -352,10 +352,14 @@ if test x"$enable_cpp11_testing" = xyes; then fi fi -# On darwin before Mavericks when using clang, need to ensure using -# libc++ for tests and examples to run under mono +# On darwin 10.7,10.8,10.9 using clang++, need to ensure using +# libc++ for tests and examples to run under mono. May affect +# other language targets as well - problem is an OSX incompatibility +# between libraries depending on libstdc++ and libc++. +CLANGXX= +$CXX -v 2>&1 | grep -i clang >/dev/null && CLANGXX=yes case $host in - *-*-darwin*) if test "$CXX" = "clang++"; + *-*-darwin11* | *-*-darwin12* |*-*-darwin13* ) if test "$CLANGXX" = "yes"; then PLATCXXFLAGS="$PLATCXXFLAGS -stdlib=libc++" fi;; *) ;; From b83d285793be072a6e6088a5c16f59b24cd68d5d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 13 Feb 2014 22:05:10 +0000 Subject: [PATCH 0928/1160] Compiler flags for Octave tests/examples change The Octave examples and test-suite were picking up any CXXFLAGS and CPPFLAGS exported into the environment creating way too many warnings running the Octave tests if the compiler flags for building SWIG were exported rather than passed to configure. --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 03677f90d..549ac1390 100644 --- a/configure.ac +++ b/configure.ac @@ -912,13 +912,13 @@ if test -n "$OCTAVE"; then AC_MSG_CHECKING([for Octave preprocessor flags]) OCTAVE_CPPFLAGS= for n in CPPFLAGS INCFLAGS; do - OCTAVE_CPPFLAGS="${OCTAVE_CPPFLAGS} "`${mkoctfile} -p $n` + OCTAVE_CPPFLAGS="${OCTAVE_CPPFLAGS} "`unset CPPFLAGS; ${mkoctfile} -p $n` done AC_MSG_RESULT([$OCTAVE_CPPFLAGS]) AC_MSG_CHECKING([for Octave compiler flags]) OCTAVE_CXXFLAGS= for n in ALL_CXXFLAGS; do - OCTAVE_CXXFLAGS="${OCTAVE_CXXFLAGS} "`${mkoctfile} -p $n` + OCTAVE_CXXFLAGS="${OCTAVE_CXXFLAGS} "`unset CXXFLAGS; ${mkoctfile} -p $n` done AC_MSG_RESULT([$OCTAVE_CXXFLAGS]) AC_MSG_CHECKING([for Octave linker flags]) From ead4d695f007fd6835d2f5d62e8c28ddfc1f7d29 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 13 Feb 2014 23:56:01 +0000 Subject: [PATCH 0929/1160] Add openSUSE Build Service script For updating SWIG tarball on OBS to latest from master. Slightly modified from script received from Karl Kaempf. --- Tools/obs-update | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 Tools/obs-update diff --git a/Tools/obs-update b/Tools/obs-update new file mode 100755 index 000000000..2a7a48cf7 --- /dev/null +++ b/Tools/obs-update @@ -0,0 +1,26 @@ +#!/bin/bash + +# Update SWIG tarball on openSUSE Build Service to contain the latest from master +# Requires the openSUSE Build Service command-line tool (osc) +# See http://openbuildservice.org/download/ +# And these packages: obs-service-tar_scm obs-service-recompress obs-service-set_version + +# Results appear at https://build.opensuse.org/package/show/home:kwk:swig/swig-raw + +set -e +set -x + +rm -rf home-kwk-swig/swig-raw +mkdir -p home-kwk-swig +cd home-kwk-swig +# check out 'swig-raw' +osc co -o swig-raw home:kwk:swig swig-raw +cd swig-raw +# remove existing tarball +osc rm swig*tar.bz2 +# fetch latest master branch from git and create tarball +osc service disabledrun +# add new tarball +osc addremove +# check changes into build service, triggers build +osc ci From 49da10eca77ec1eec5c2a6a1711db9610cbc9e39 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 14 Feb 2014 18:57:12 +0000 Subject: [PATCH 0930/1160] Don't run perl examples/tests if Test::More is not available The test-suite requires Test::More and the local versions of Test::More were removed in 1d1e8650a31ae90ca44564565a7c5fa680bc1cba. They are not always distributed with Perl, such as Perl 5.16 in Fedora. --- Examples/test-suite/perl5/README | 32 +++++++++----------------------- configure.ac | 9 ++++++++- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/Examples/test-suite/perl5/README b/Examples/test-suite/perl5/README index 14eb5277e..804dec8e8 100644 --- a/Examples/test-suite/perl5/README +++ b/Examples/test-suite/perl5/README @@ -5,28 +5,14 @@ Any testcases which have _runme.pl appended after the testcase name will be dete Test::More Support == -Test::More and Test::Harness are two of the standard perl test harness -tools. Support has been added for these modules as of 1.3.28. If -adding a new test to this suite, please use Test::More. +Test::More is a standard perl test harness tool. +Support was added for for using Test::More in 1.3.28. +If adding a new test to this suite, please use Test::More. -Currently converted test cases include: +There are a few legacy test cases which do not use Test::More and these ought to be converted: -* operator_overload -* operator_overload_break -* package -* overload_simple -* apply_strings -* char_strings -* default_args -* enum_thorough -* global_vars -* import_nomodule -* inherit -* li_cdata_carrays -* li_std_string -* member_pointer -* multiple_inheritance -* primitive_ref -* template_default_arg -* unions -* voidtest +disown +imports +overload_copy +profiletest +template_ref_type diff --git a/configure.ac b/configure.ac index 549ac1390..02775b0f0 100644 --- a/configure.ac +++ b/configure.ac @@ -850,6 +850,13 @@ if test -n "$PERL"; then AC_MSG_RESULT(not found) else AC_MSG_RESULT($PERL5LDFLAGS) + fi + AC_MSG_CHECKING(for Perl5 Test::More module) # For test-suite + PERL5TESTMORE=`($PERL -e 'use Test::More; print "good";') 2>/dev/null` + if test -z "$PERL5TESTMORE" ; then + AC_MSG_RESULT(not found) + else + AC_MSG_RESULT(found) fi else AC_MSG_RESULT(unable to determine perl5 configuration) @@ -2185,7 +2192,7 @@ AC_SUBST(SKIP_TCL) SKIP_PERL5= -if test -z "$PERL" || test -z "$PERL5EXT" ; then +if test -z "$PERL" || test -z "$PERL5EXT" || test -z "$PERL5TESTMORE"; then SKIP_PERL5="1" fi AC_SUBST(SKIP_PERL5) From c063bb838488a01d1cddc850cd9eab8545a6e8db Mon Sep 17 00:00:00 2001 From: Harvey Falcic Date: Fri, 14 Feb 2014 19:19:09 -0500 Subject: [PATCH 0931/1160] Fix shadow instance creation failure in Python 3 I managed to trace a very nasty Python interpreter segfault to an allocation failure here. Adding this after the tp_new call: if (PyErr_Occurred()) { PyErr_Print(); } results in output of 'TypeError: object() takes no parameters', followed by a segfault that takes down the Python interpeter. The 'object' constructor doesn't seem to be suitable for instantiating SWIG shadow instances in this way, so simply use the constructor function in the PyTypeObject 'tp_new' slot of data->newargs. The 'if (inst)' check after this doesn't hurt in as much as it prevented a segfault immediately after this failed allocation, but it doesn't help much since the null pointer dereference will probably happen sooner or later anyway. --- Lib/python/pyrun.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index b077fad32..53fc3a75b 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1310,7 +1310,7 @@ SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this) } } else { #if PY_VERSION_HEX >= 0x03000000 - inst = PyBaseObject_Type.tp_new((PyTypeObject*) data->newargs, Py_None, Py_None); + inst = ((PyTypeObject*) data->newargs)->tp_new((PyTypeObject*) data->newargs, Py_None, Py_None); if (inst) { PyObject_SetAttr(inst, SWIG_This(), swig_this); Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG; From 44670c2b969ed80742b938217b800e1d16850c08 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Feb 2014 12:01:40 +0000 Subject: [PATCH 0932/1160] Only enable Ruby testing if Ruby header files are found --- configure.ac | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/configure.ac b/configure.ac index 02775b0f0..41c1026f0 100644 --- a/configure.ac +++ b/configure.ac @@ -1274,7 +1274,7 @@ fi AC_MSG_CHECKING(for Ruby header files) if test -n "$RUBY"; then - # Try Ruby1.9 first + # Try Ruby1.9+ first RUBYDIR=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["rubyhdrdir"]] || $rubyhdrdir') 2>/dev/null` if test x"$RUBYDIR" = x"" || test x"$RUBYDIR" = x"nil"; then RUBYDIR=`($RUBY -rmkmf -e 'print Config::CONFIG[["archdir"]] || $archdir') 2>/dev/null` @@ -1283,20 +1283,20 @@ if test -n "$RUBY"; then fi if test x"$RUBYDIR" != x""; then dirs="$RUBYDIR" - RUBYINCLUDE=none + RUBYINCLUDE= for i in $dirs; do if test -r $i/ruby.h; then - AC_MSG_RESULT($i) - RUBYINCLUDE="-I$i" + if test x"$RUBYARCH" = x""; then + RUBYINCLUDE="-I$i" + else + RUBYINCLUDE="-I$i -I$i/$RUBYARCH" + fi + AC_MSG_RESULT($RUBYINCLUDE) break fi done - if test x"$RUBYARCH" != x""; then - RUBYINCLUDE="-I$RUBYDIR -I$RUBYDIR/$RUBYARCH" - fi - if test "$RUBYINCLUDE" = none; then - RUBYINCLUDE="-I$RUBYDIR" - AC_MSG_RESULT(could not locate ruby.h...using $RUBYINCLUDE) + if test x"$RUBYINCLUDE" = x""; then + AC_MSG_RESULT(could not locate ruby.h) fi # Find library and path for linking. @@ -1350,8 +1350,6 @@ if test -n "$RUBY"; then fi else AC_MSG_RESULT(unable to determine ruby configuration) - RUBYINCLUDE="-I$RUBYDIR" - RUBYLIB="$RUBYDIR" fi case $host in @@ -1363,9 +1361,6 @@ if test -n "$RUBY"; then RUBYSO=.`($RUBY -rrbconfig -e 'print Config::CONFIG[["DLEXT"]]') 2>/dev/null` else AC_MSG_RESULT(could not figure out how to run ruby) - RUBYINCLUDE="-I/usr/local/lib/ruby/1.4/arch" - RUBYLIB="/usr/local/lib/ruby/1.4/arch" - RUBYLINK="-lruby -lm" fi case $host in From 85f91128ffd692a1b5691e59caf70b3c85550ee0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Feb 2014 14:31:05 +0000 Subject: [PATCH 0933/1160] Locate tclConfig.sh on 64 bit openSUSE - /usr/lib64/tclConfig.sh --- configure.ac | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 41c1026f0..b41d2ace7 100644 --- a/configure.ac +++ b/configure.ac @@ -481,10 +481,10 @@ if test x"${with_tclconfig}" != x ; then fi # check in a few common install locations if test x"${TCLCONFIG}" = x ; then - for i in `ls -d /usr/lib/ 2>/dev/null` \ - `ls -d -r /usr/lib/tcl*/ 2>/dev/null` \ - `ls -d /usr/local/lib/ 2>/dev/null` \ - `ls -d -r /usr/local/lib/tcl*/ 2>/dev/null` ; do + for i in `ls -d -r /usr/lib*/ 2>/dev/null` \ + `ls -d -r /usr/lib*/tcl*/ 2>/dev/null` \ + `ls -d -r /usr/local/lib*/ 2>/dev/null` \ + `ls -d -r /usr/local/lib*/tcl*/ 2>/dev/null` ; do if test -f $i"tclConfig.sh" ; then TCLCONFIG=`(cd $i; pwd)` break From 1ff6301fdca38574cfc126aede5b6d0a3bed8e0b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Feb 2014 15:19:04 +0000 Subject: [PATCH 0934/1160] Look for jni.h under /usr/lib64/jvm --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index b41d2ace7..b99245222 100644 --- a/configure.ac +++ b/configure.ac @@ -982,7 +982,7 @@ AC_MSG_CHECKING(for java include file jni.h) AC_ARG_WITH(javaincl, [ --with-javaincl=path Set location of Java include directory], [JAVAINCDIR="$withval"], [JAVAINCDIR=]) if test -z "$JAVAINCDIR" ; then - JAVAINCDIR="/usr/j2sdk*/include /usr/local/j2sdk*/include /usr/jdk*/include /usr/local/jdk*/include /opt/j2sdk*/include /opt/jdk*/include /usr/java/include /usr/java/j2sdk*/include /usr/java/jdk*/include /usr/local/java/include /opt/java/include /usr/include/java /usr/local/include/java /usr/lib/java/include /usr/lib/jvm/java*/include /usr/include/kaffe /usr/local/include/kaffe /usr/include" + JAVAINCDIR="/usr/j2sdk*/include /usr/local/j2sdk*/include /usr/jdk*/include /usr/local/jdk*/include /opt/j2sdk*/include /opt/jdk*/include /usr/java/include /usr/java/j2sdk*/include /usr/java/jdk*/include /usr/local/java/include /opt/java/include /usr/include/java /usr/local/include/java /usr/lib/java/include /usr/lib/jvm/java*/include /usr/lib64/jvm/java*/include /usr/include/kaffe /usr/local/include/kaffe /usr/include" # Add in default installation directory on Windows for Cygwin case $host in From 4ba4a02e93521821aba8591343fdb3a5c9e5e1a3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Feb 2014 18:36:01 +0000 Subject: [PATCH 0935/1160] Fix unused method warning in Octave --- Lib/octave/octrun.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 2174a0f7f..dc9b6b6e6 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -1171,7 +1171,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); DEFINE_OCTAVE_ALLOCATOR(octave_swig_packed); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_swig_packed, "swig_packed", "swig_packed"); - static octave_value_list octave_set_immutable(const octave_value_list &args, int nargout) { + SWIGRUNTIME octave_value_list octave_set_immutable(const octave_value_list &args, int nargout) { error("attempt to set immutable member variable"); return octave_value_list(); } From cd2e301ea425ffb16ef5f12e926e6f35981a7ebf Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Feb 2014 18:54:28 +0000 Subject: [PATCH 0936/1160] Remove nspace feature not yet supported warning --- Examples/test-suite/csharp_namespace_system_collision.i | 2 +- Examples/test-suite/director_nspace.i | 2 +- Examples/test-suite/director_nspace_director_name_collision.i | 2 +- Examples/test-suite/nspace.i | 2 +- Examples/test-suite/nspace_extend.i | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Examples/test-suite/csharp_namespace_system_collision.i b/Examples/test-suite/csharp_namespace_system_collision.i index 6f94f8471..675aefb4e 100644 --- a/Examples/test-suite/csharp_namespace_system_collision.i +++ b/Examples/test-suite/csharp_namespace_system_collision.i @@ -23,7 +23,7 @@ namespace TopLevel #if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) %nspace; #else -#warning nspace feature not yet supported in this target language +//#warning nspace feature not yet supported in this target language #endif namespace TopLevel diff --git a/Examples/test-suite/director_nspace.i b/Examples/test-suite/director_nspace.i index 121a06f1f..512077e8b 100644 --- a/Examples/test-suite/director_nspace.i +++ b/Examples/test-suite/director_nspace.i @@ -44,7 +44,7 @@ namespace TopLevel %nspace TopLevel::Bar::Foo; %nspace TopLevel::Bar::FooBar; #else -#warning nspace feature not yet supported in this target language +//#warning nspace feature not yet supported in this target language #endif %feature("director") TopLevel::Bar::Foo; diff --git a/Examples/test-suite/director_nspace_director_name_collision.i b/Examples/test-suite/director_nspace_director_name_collision.i index e7abffcb1..c6f13b451 100644 --- a/Examples/test-suite/director_nspace_director_name_collision.i +++ b/Examples/test-suite/director_nspace_director_name_collision.i @@ -38,7 +38,7 @@ namespace TopLevel %nspace TopLevel::A::Foo; %nspace TopLevel::B::Foo; #else -#warning nspace feature not yet supported in this target language +//#warning nspace feature not yet supported in this target language %ignore TopLevel::B::Foo; #endif diff --git a/Examples/test-suite/nspace.i b/Examples/test-suite/nspace.i index 2e10542d3..c60a45df5 100644 --- a/Examples/test-suite/nspace.i +++ b/Examples/test-suite/nspace.i @@ -104,6 +104,6 @@ void test_classes(Outer::SomeClass c, Outer::Inner2::Color cc) {} %} #else -#warning nspace feature not yet supported in this target language +//#warning nspace feature not yet supported in this target language #endif diff --git a/Examples/test-suite/nspace_extend.i b/Examples/test-suite/nspace_extend.i index 1965ef8f6..782ce90ca 100644 --- a/Examples/test-suite/nspace_extend.i +++ b/Examples/test-suite/nspace_extend.i @@ -50,6 +50,6 @@ namespace Outer { } #else -#warning nspace feature not yet supported in this target language +//#warning nspace feature not yet supported in this target language #endif From 8e6a539d89bc44e47ec75f8cf5d47f824e35c869 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Feb 2014 19:34:42 +0000 Subject: [PATCH 0937/1160] Fix crash in php example Declaration and definition of the add function were different --- Examples/php/cpointer/example.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/php/cpointer/example.c b/Examples/php/cpointer/example.c index 3326dec3e..04dd08df0 100644 --- a/Examples/php/cpointer/example.c +++ b/Examples/php/cpointer/example.c @@ -1,6 +1,6 @@ /* File : example.c */ -void add(double *x, double *y, double *result) { +void add(int *x, int *y, int *result) { *result = *x + *y; } From 90a9d750c9e6ee67cdde95e5c76c18e15379cebe Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Feb 2014 22:05:40 +0000 Subject: [PATCH 0938/1160] Add support for cdata library for Java --- CHANGES.current | 3 ++ Examples/test-suite/java/li_cdata_runme.java | 24 ++++++++++++++ Lib/cdata.i | 33 ++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 Examples/test-suite/java/li_cdata_runme.java diff --git a/CHANGES.current b/CHANGES.current index 7c257dfde..63f575a9d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-02-15: wsfulton + [Java] Add support for the cdata library. + 2014-02-06: gjanssens [Guile] Patch #133. Make scm to string conversion work with non-ascii strings. Guile 2 has a completely rewritten string implementation. SWIG made some assumptions diff --git a/Examples/test-suite/java/li_cdata_runme.java b/Examples/test-suite/java/li_cdata_runme.java new file mode 100644 index 000000000..c0ea8ecc7 --- /dev/null +++ b/Examples/test-suite/java/li_cdata_runme.java @@ -0,0 +1,24 @@ +import li_cdata.*; + +public class li_cdata_runme { + + static { + try { + System.loadLibrary("li_cdata"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) throws Throwable + { + byte[] s = "ABC abc".getBytes(); + SWIGTYPE_p_void m = li_cdata.malloc(256); + li_cdata.memmove(m, s); + byte[] ss = li_cdata.cdata(m, 7); + String ss_string = new String(ss); + if (!ss_string.equals("ABC abc")) + throw new RuntimeException("failed got: " + ss_string); + } +} diff --git a/Lib/cdata.i b/Lib/cdata.i index 22a6d9de8..b9b8e1887 100644 --- a/Lib/cdata.i +++ b/Lib/cdata.i @@ -20,17 +20,50 @@ typedef struct SWIGCDATA { $result = scm_from_locale_stringn($1.data,$1.len); } %typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH); + #elif SWIGCHICKEN + %typemap(out) SWIGCDATA { C_word *string_space = C_alloc(C_SIZEOF_STRING($1.len)); $result = C_string(&string_space, $1.len, $1.data); } %typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH); + #elif SWIGPHP + %typemap(out) SWIGCDATA { ZVAL_STRINGL($result, $1.data, $1.len, 1); } %typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH); + +#elif SWIGJAVA + +%apply (char *STRING, int LENGTH) { (const void *indata, int inlen) } +%typemap(jni) SWIGCDATA "jbyteArray" +%typemap(jtype) SWIGCDATA "byte[]" +%typemap(jstype) SWIGCDATA "byte[]" +%fragment("SWIG_JavaArrayOutCDATA", "header") { +static jbyteArray SWIG_JavaArrayOutCDATA(JNIEnv *jenv, char *result, jsize sz) { + jbyte *arr; + int i; + jbyteArray jresult = JCALL1(NewByteArray, jenv, sz); + if (!jresult) + return NULL; + arr = JCALL2(GetByteArrayElements, jenv, jresult, 0); + if (!arr) + return NULL; + for (i=0; i Date: Sat, 15 Feb 2014 23:30:14 +0000 Subject: [PATCH 0939/1160] Add fragment Removes include specifically for clang Cuts down on duplicate #include in general --- Lib/perl5/std_common.i | 3 +-- Lib/python/pystdcommon.swg | 3 +-- Lib/std/std_basic_string.i | 5 +---- Lib/std/std_common.i | 10 ++-------- Lib/tcl/std_vector.i | 2 +- Lib/typemaps/fragments.swg | 8 ++++++-- Lib/typemaps/std_string.swg | 6 ++---- Lib/typemaps/std_wstring.swg | 2 +- Lib/typemaps/traits.swg | 10 ++-------- 9 files changed, 17 insertions(+), 32 deletions(-) diff --git a/Lib/perl5/std_common.i b/Lib/perl5/std_common.i index c36513912..bb280688e 100644 --- a/Lib/perl5/std_common.i +++ b/Lib/perl5/std_common.i @@ -8,9 +8,8 @@ %apply size_t { std::size_t }; +%fragment(""); %{ -#include - double SwigSvToNumber(SV* sv) { return SvIOK(sv) ? double(SvIVX(sv)) : SvNVX(sv); } diff --git a/Lib/python/pystdcommon.swg b/Lib/python/pystdcommon.swg index 4e2ae56f4..2af22e2a4 100644 --- a/Lib/python/pystdcommon.swg +++ b/Lib/python/pystdcommon.swg @@ -195,9 +195,8 @@ namespace swig { // #ifdef SWIG_PYTHON_BACKWARD_COMP +%fragment(""); %{ -#include - PyObject* SwigInt_FromBool(bool b) { return PyInt_FromLong(b ? 1L : 0L); } diff --git a/Lib/std/std_basic_string.i b/Lib/std/std_basic_string.i index 7b0898a3e..1aa5721c9 100644 --- a/Lib/std/std_basic_string.i +++ b/Lib/std/std_basic_string.i @@ -3,10 +3,7 @@ %include %include - -%{ -#include -%} +%fragment(""); namespace std { diff --git a/Lib/std/std_common.i b/Lib/std/std_common.i index cb91bc632..35baf2206 100644 --- a/Lib/std/std_common.i +++ b/Lib/std/std_common.i @@ -23,8 +23,8 @@ // Common code for supporting the C++ std namespace // +%fragment(""); %{ -#include #include #include %} @@ -73,13 +73,7 @@ namespace std { #endif %} -%fragment("StdStringInclude","header") %{ -#ifdef __clang__ -#include -#endif -%} - -%fragment("StdTraitsCommon","header",fragment="StdStringInclude") %{ +%fragment("StdTraitsCommon","header",fragment="") %{ namespace swig { template struct noconst_traits { diff --git a/Lib/tcl/std_vector.i b/Lib/tcl/std_vector.i index de99a36d0..37e23ba71 100644 --- a/Lib/tcl/std_vector.i +++ b/Lib/tcl/std_vector.i @@ -28,11 +28,11 @@ // is returned // ------------------------------------------------------------------------ +%fragment(""); %{ #include #include #include -#include Tcl_Obj* SwigString_FromString(const std::string &s) { return Tcl_NewStringObj(s.data(), (int)s.length()); diff --git a/Lib/typemaps/fragments.swg b/Lib/typemaps/fragments.swg index 8f887e34e..ce87c8cc0 100644 --- a/Lib/typemaps/fragments.swg +++ b/Lib/typemaps/fragments.swg @@ -149,8 +149,12 @@ #endif %} -%fragment("", "header") %{ - #include +%fragment("", "header") %{ +#include +%} + +%fragment("", "header") %{ +#include %} %fragment("SWIG_isfinite","header",fragment=",") %{ diff --git a/Lib/typemaps/std_string.swg b/Lib/typemaps/std_string.swg index 691bf2ccf..5b57beab5 100644 --- a/Lib/typemaps/std_string.swg +++ b/Lib/typemaps/std_string.swg @@ -8,10 +8,8 @@ %include -%{ -#include -%} - +%fragment(""); + namespace std { %naturalvar string; diff --git a/Lib/typemaps/std_wstring.swg b/Lib/typemaps/std_wstring.swg index 670685fca..4a2830bb9 100644 --- a/Lib/typemaps/std_wstring.swg +++ b/Lib/typemaps/std_wstring.swg @@ -7,8 +7,8 @@ %{ #include -#include %} +%fragment(""); namespace std { diff --git a/Lib/typemaps/traits.swg b/Lib/typemaps/traits.swg index 584d480c2..09cc7e295 100644 --- a/Lib/typemaps/traits.swg +++ b/Lib/typemaps/traits.swg @@ -21,18 +21,12 @@ // Common code for supporting the STD C++ namespace // +%fragment(""); %{ -#include #include %} -%fragment("StdStringInclude","header") %{ -#ifdef __clang__ -#include -#endif -%} - -%fragment("Traits","header",fragment="StdStringInclude") +%fragment("Traits","header",fragment="") { namespace swig { /* From 8a5fb0fe7be4471512e27b5fe0d3c6057546df16 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Feb 2014 09:33:51 +0000 Subject: [PATCH 0940/1160] brew install workarounds on Travis 'brew install guile' does not complete within 10 minutes and the build is then killed by Travis Suggestion and original script from travis-ci/travis-ci#1961 --- Tools/brew-install | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 Tools/brew-install diff --git a/Tools/brew-install b/Tools/brew-install new file mode 100755 index 000000000..408ae13bb --- /dev/null +++ b/Tools/brew-install @@ -0,0 +1,25 @@ +#!/bin/bash + +# Wrapper around 'brew install' emitting a message every minute if the command is still running. +# This is used on Travis to ensure the install isn't killed when there is no output over a long period (10 minutes). +# Usage: brew-install package, where package is the name of the package for brew to install. + +seconds=0 +minutes=0 +brew install $1 & +while true; do + ps -p$! 2>& 1>/dev/null + if [ $? = 0 ]; then + if [ $seconds = 60 ]; then + let seconds=0 + let minutes=minutes+1 + echo "brew install $1 still running ($minutes min)" + fi + sleep 1 + let seconds=seconds+1 + else + break + fi +done +wait $! +exit $? From 60501fe077815568a7124906f360841b8e9be8d0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Feb 2014 21:41:44 +0000 Subject: [PATCH 0941/1160] Errors tests more visibly show failures as the output of diff diff -u would be better, but it is not posix, so diff -e is chosen as second best choice. --- Examples/test-suite/errors/Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/errors/Makefile.in b/Examples/test-suite/errors/Makefile.in index cbfe1c29e..fe6aff534 100644 --- a/Examples/test-suite/errors/Makefile.in +++ b/Examples/test-suite/errors/Makefile.in @@ -35,12 +35,12 @@ include $(srcdir)/../common.mk %.cpptest: echo "$(ACTION)ing errors testcase $*" -$(SWIG) -c++ -python -Wall $(SWIGOPT) $*.i 2> $*.$(ERROR_EXT) - $(COMPILETOOL) diff $*.stderr $*.newerr + $(COMPILETOOL) diff -c $*.stderr $*.newerr %.ctest: echo "$(ACTION)ing errors testcase $*" -$(SWIG) -python -Wall $(SWIGOPT) $*.i 2> $*.$(ERROR_EXT) - $(COMPILETOOL) diff $*.stderr $*.newerr + $(COMPILETOOL) diff -c $*.stderr $*.newerr %.clean: From 0e4f2dad0f52d3397d971c511ec7b258ffe5bf49 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 10 Feb 2014 20:50:00 +0000 Subject: [PATCH 0942/1160] C# examples to use debug flags when using mono interpreter --- Examples/Makefile.in | 3 ++- Examples/test-suite/csharp/Makefile.in | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index dac3f2c37..5c7884a8f 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1203,9 +1203,10 @@ CSHARP_DLNK = @CSHARPDYNAMICLINKING@ CSHARP_LIBPREFIX = @CSHARPLIBRARYPREFIX@ CSHARPCOMPILER = @CSHARPCOMPILER@ CSHARPCILINTERPRETER = @CSHARPCILINTERPRETER@ +CSHARPCILINTERPRETER_FLAGS = @CSHARPCILINTERPRETER_FLAGS@ CSHARPCFLAGS = @CSHARPCFLAGS@ CSHARPSO = @CSHARPSO@ -CSHARP_RUNME = $(CSHARPCILINTERPRETER) ./$(RUNME).exe +CSHARP_RUNME = $(CSHARPCILINTERPRETER) $(CSHARPCILINTERPRETER_FLAGS) ./$(RUNME).exe # ---------------------------------------------------------------- # Build a CSharp dynamically loadable module (C) diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index 22d78ee1c..4284a775d 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -4,8 +4,8 @@ LANGUAGE = csharp SCRIPTSUFFIX = _runme.cs -INTERPRETER = @CSHARPCILINTERPRETER@ -INTERPRETER_FLAGS = @CSHARPCILINTERPRETER_FLAGS@ +CSHARPCILINTERPRETER = @CSHARPCILINTERPRETER@ +CSHARPCILINTERPRETER_FLAGS = @CSHARPCILINTERPRETER_FLAGS@ CSHARPPATHSEPARATOR = "@CSHARPPATHSEPARATOR@" CSHARPCYGPATH_W = @CSHARPCYGPATH_W@ srcdir = @srcdir@ @@ -75,7 +75,7 @@ run_testcase = \ $(MAKE) -f $*/$(top_builddir)/$(EXAMPLES)/Makefile \ CSHARPFLAGS='-nologo -debug+ $(CSHARPFLAGSSPECIAL) -out:$*_runme.exe' \ 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" DYLD_FALLBACK_LIBRARY_PATH= $(RUNTOOL) $(INTERPRETER) $(INTERPRETER_FLAGS) ./$*_runme.exe; \ + env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" DYLD_FALLBACK_LIBRARY_PATH= $(RUNTOOL) $(CSHARPCILINTERPRETER) $(CSHARPCILINTERPRETER_FLAGS) ./$*_runme.exe; \ else \ cd $* && \ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ From d73513cb7ad5fcdab4fbaa9dd4c2e5fd96faf091 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Feb 2014 15:40:02 +0000 Subject: [PATCH 0943/1160] Travis testing of Python 3.3 added --- .travis.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9cf525f6e..7c61dc299 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,12 +26,15 @@ matrix: env: SWIGLANG=python - compiler: gcc env: SWIGLANG=python PY3=1 + - compiler: gcc + env: SWIGLANG=python PY3=1 VER=3.3 - compiler: gcc env: SWIGLANG=ruby - compiler: gcc env: SWIGLANG=tcl allow_failures: - # None + env: SWIGLANG=python PY3=1 VER=3.3 + - compiler: gcc before_install: - date -u - lsb_release -a @@ -45,7 +48,8 @@ before_install: - if test "$SWIGLANG" = "lua"; then sudo apt-get -qq install lua5.1 liblua5.1-dev; fi - if test "$SWIGLANG" = "octave"; then sudo apt-get -qq install octave3.2 octave3.2-headers; fi - if test "$SWIGLANG" = "php"; then sudo apt-get install php5-cli php5-dev; fi - - if test "$SWIGLANG" = "python" -a "$PY3"; then sudo apt-get install python3-dev; fi + - if test "$SWIGLANG" = "python" -a "$PY3" -a -z "$VER"; then sudo apt-get install -qq python3-dev; fi + - if test "$SWIGLANG" = "python" -a "$VER"; then sudo add-apt-repository -y ppa:fkrull/deadsnakes && sudo apt-get -qq update && sudo apt-get -qq install python${VER}-dev; fi - if test "$SWIGLANG" = "tcl"; then sudo apt-get -qq install tcl8.4-dev; fi script: - ./autogen.sh && ./configure From 53a3d12227ba4146d57c208389d28c3f3e6c5ca3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Feb 2014 17:13:54 +0000 Subject: [PATCH 0944/1160] Fix typo in .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7c61dc299..51c24e0e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,8 +33,8 @@ matrix: - compiler: gcc env: SWIGLANG=tcl allow_failures: - env: SWIGLANG=python PY3=1 VER=3.3 - compiler: gcc + env: SWIGLANG=python PY3=1 VER=3.3 before_install: - date -u - lsb_release -a From b1707884592807e89a133035c1571e1b75746ece Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Feb 2014 14:52:45 +0000 Subject: [PATCH 0945/1160] Executable bits and shebang fixes --- Examples/python/performance/constructor/runme.py | 2 -- Examples/python/performance/func/runme.py | 2 -- Examples/python/performance/harness.py | 2 -- Examples/python/performance/hierarchy/runme.py | 2 -- Examples/python/performance/hierarchy_operator/runme.py | 2 -- Examples/python/performance/operator/runme.py | 2 -- Examples/ruby/constants/runme.rb | 0 Examples/ruby/hashargs/runme.rb | 0 Examples/ruby/multimap/runme.rb | 0 Examples/ruby/simple/runme.rb | 0 10 files changed, 12 deletions(-) mode change 100755 => 100644 Examples/ruby/constants/runme.rb mode change 100755 => 100644 Examples/ruby/hashargs/runme.rb mode change 100755 => 100644 Examples/ruby/multimap/runme.rb mode change 100755 => 100644 Examples/ruby/simple/runme.rb diff --git a/Examples/python/performance/constructor/runme.py b/Examples/python/performance/constructor/runme.py index 23577a14d..274cbf85e 100644 --- a/Examples/python/performance/constructor/runme.py +++ b/Examples/python/performance/constructor/runme.py @@ -1,5 +1,3 @@ -#!/usr/bin/env - import sys sys.path.append('..') import harness diff --git a/Examples/python/performance/func/runme.py b/Examples/python/performance/func/runme.py index fd2fb175b..f9032b9d2 100644 --- a/Examples/python/performance/func/runme.py +++ b/Examples/python/performance/func/runme.py @@ -1,5 +1,3 @@ -#!/usr/bin/env - import sys sys.path.append('..') import harness diff --git a/Examples/python/performance/harness.py b/Examples/python/performance/harness.py index 8e9b6041b..00f48e66a 100644 --- a/Examples/python/performance/harness.py +++ b/Examples/python/performance/harness.py @@ -1,5 +1,3 @@ -#!/usr/bin/env - import sys import time import imp diff --git a/Examples/python/performance/hierarchy/runme.py b/Examples/python/performance/hierarchy/runme.py index 8a57da05e..9b22586a1 100644 --- a/Examples/python/performance/hierarchy/runme.py +++ b/Examples/python/performance/hierarchy/runme.py @@ -1,5 +1,3 @@ -#!/usr/bin/env - import sys sys.path.append('..') import harness diff --git a/Examples/python/performance/hierarchy_operator/runme.py b/Examples/python/performance/hierarchy_operator/runme.py index cf200362f..5a8c52557 100644 --- a/Examples/python/performance/hierarchy_operator/runme.py +++ b/Examples/python/performance/hierarchy_operator/runme.py @@ -1,5 +1,3 @@ -#!/usr/bin/env - import sys sys.path.append('..') import harness diff --git a/Examples/python/performance/operator/runme.py b/Examples/python/performance/operator/runme.py index 61a0e8edc..4a6031f48 100644 --- a/Examples/python/performance/operator/runme.py +++ b/Examples/python/performance/operator/runme.py @@ -1,5 +1,3 @@ -#!/usr/bin/env - import sys sys.path.append('..') import harness diff --git a/Examples/ruby/constants/runme.rb b/Examples/ruby/constants/runme.rb old mode 100755 new mode 100644 diff --git a/Examples/ruby/hashargs/runme.rb b/Examples/ruby/hashargs/runme.rb old mode 100755 new mode 100644 diff --git a/Examples/ruby/multimap/runme.rb b/Examples/ruby/multimap/runme.rb old mode 100755 new mode 100644 diff --git a/Examples/ruby/simple/runme.rb b/Examples/ruby/simple/runme.rb old mode 100755 new mode 100644 From a161e5ab4ef310d0639f10cf75a490b5106bfe0a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Feb 2014 15:53:08 +0000 Subject: [PATCH 0946/1160] Fix configure for binary specified by --with-python3 --- configure.ac | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 736395ac7..bb62068ae 100644 --- a/configure.ac +++ b/configure.ac @@ -707,15 +707,21 @@ AS_HELP_STRING([--with-python3=path], [Set location of Python 3.x executable]),[ if test x"${PY3BIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling Python 3.x support]) else - for py_ver in 3 3.6 3.5 3.4 3.3 3.2 3.1 3.0; do - AC_CHECK_PROGS(PYTHON3, [python$py_ver]) - if test -n "$PYTHON3"; then - AC_CHECK_PROGS(PY3CONFIG, [$PYTHON3-config]) - if test -n "$PY3CONFIG"; then - break + if test "x$PY3BIN" = xyes; then + for py_ver in 3 3.6 3.5 3.4 3.3 3.2 3.1 3.0; do + AC_CHECK_PROGS(PYTHON3, [python$py_ver]) + if test -n "$PYTHON3"; then + AC_CHECK_PROGS(PY3CONFIG, [$PYTHON3-config]) + if test -n "$PY3CONFIG"; then + break + fi fi - fi - done + done + else + PYTHON3="$PY3BIN" + AC_CHECK_PROGS(PY3CONFIG, [$PYTHON3-config]) + fi + if test -n "$PYTHON3" -a -n "$PY3CONFIG"; then AC_MSG_CHECKING([for Python 3.x prefix]) From 8cdae65ee9de33436ca2cd44744fdee2c9870590 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Feb 2014 17:17:50 +0000 Subject: [PATCH 0947/1160] C++ exception (wrapped by a Python exception as a shadow instance) segfaulting Python Patch #137 --- CHANGES.current | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 63f575a9d..3248541c4 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-02-16: hfalcic + [Python] Patch #133 - fix crashes/exceptions in exception handling in Python 3.3 + 2014-02-15: wsfulton [Java] Add support for the cdata library. From 81cc95155ea3c542f18ba32758c48e2b46577f76 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Feb 2014 18:11:17 +0000 Subject: [PATCH 0948/1160] Python 3.3 should now work on Travis --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 51c24e0e4..5d47074e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,8 +33,7 @@ matrix: - compiler: gcc env: SWIGLANG=tcl allow_failures: - - compiler: gcc - env: SWIGLANG=python PY3=1 VER=3.3 + # None before_install: - date -u - lsb_release -a From c7187c6a2d453e59222eb41ca31f93099053cedd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 9 Feb 2014 09:34:18 +0000 Subject: [PATCH 0949/1160] Add release summary for 2.0.12 --- RELEASENOTES | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/RELEASENOTES b/RELEASENOTES index 720dc9d34..756df81ff 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -4,6 +4,14 @@ and CHANGES files. Release Notes ============= +SWIG-2.0.12 summary: +- This is a maintenance release backporting some fixes from the pending + 3.0.0 release. +- Octave 3.8 support added. +- C++11 support for new versions of erase/insert in the STL containers. +- Compilation fixes on some systems for the generated Lua, PHP, Python + and R wrappers. + SWIG-2.0.11 summary: - Minor bug fixes and enhancements mostly in Python, but also C#, Lua, Ocaml, Octave, Perl, PHP, Python, R, Ruby, Tcl. From d7f91bc47a98f5b2afa71315e8c7636c3a029be5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Feb 2014 22:28:57 +0000 Subject: [PATCH 0950/1160] CHANGES files corrections since 2.0.12 release A number of fixes committed since 2.0.11 release were intended for the 3.0.0 release were backported to the maintenance-2.0 branch for 2.0.12. --- CHANGES | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ CHANGES.current | 62 ---------------------------------------------- 2 files changed, 65 insertions(+), 62 deletions(-) diff --git a/CHANGES b/CHANGES index da5fb1f07..988f0fb5e 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,71 @@ 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.12 (9 Feb 2014) +=========================== + +2014-01-16: wsfulton + [PHP] Fix compilation error in ZTS mode (64 bit windows) due to incorrect placement + of TSRMLS_FETCH() in SWIG_Php_GetModule() as reported by Mark Dawson-Butterworth. + +2014-01-13: kwwette + [Octave] update support to Octave version 3.8.0 + + - Octave 3.8.0 no longer defines OCTAVE_API_VERSION_NUMBER, but 3.8.1 + will define OCTAVE_{MAJOR,MINOR,PATCH}_VERSION instead: see + http://hg.savannah.gnu.org/hgweb/octave/rev/b6b6e0dc700e + So we now use a new macro SWIG_OCTAVE_PREREQ(major,minor,patch) to + enable features requiring Octave version major.minor.patch or later. + + For Octave versions prior to 3.8.1, we reconstruct values for + OCTAVE_{MAJOR,MINOR,PATCH}_VERSION based on OCTAVE_API_VERSION_NUMBER, + extracted from Octave's ChangeLogs. An additional hack is needed to + distinguish between Octave <= 3.2.x and 3.8.0, neither of which define + OCTAVE_API_VERSION_NUMBER. + + - Octave 3.8.0 deprecates symbol_table::varref(), so remove its use + for this and future versions of Octave. + + - Octave 3.8.0 removes octave_value::is_real_nd_array(), used in + octave_swig_type::dims(). Its use is not required here, so remove it. + + - Retested against Octave versions 3.0.5, 3.2.4, 3.4.3, 3.6.4, and 3.8.0. + + - Updated Octave documentation with tested Octave versions, and added a + warning against using versions <= 3.x.x, which are no longer tested. + +2013-12-22: wsfulton + C++11 support for new versions of erase and insert in the STL containers. + + The erase and insert methods in the containers use const_iterator instead + of iterator in C++11. There are times when the methods wrapped must match + the parameters exactly. Specifically when full type information for + template types is missing or SWIG fails to look up the type correctly, + for example: + + %include + typedef float Real; + %template(RealVector) std::vector; + + SWIG does not find std::vector::iterator because %template using + typedefs does not always work and so SWIG doesn't know if the type is + copyable and so uses SwigValueWrapper which does + not support conversion to another type (const_iterator). This resulted + in compilation errors when using the C++11 version of the containers. + + Closes #73 + +2013-10-17: wsfulton + [R] Fix SF #1340 - Visual Studio compile error in C++ wrappers due to #include + within extern "C" block. + +2013-10-17: wsfulton + [Python] Fix SF #1345 - Missing #include for offsetof when using -builtin. + +2013-10-12: wsfulton + [Lua] Apply #92 - missing return statements for SWIG_Lua_add_namespace_details() + and SWIG_Lua_namespace_register(). + Version 2.0.11 (15 Sep 2013) ============================ diff --git a/CHANGES.current b/CHANGES.current index 3248541c4..013bf6257 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -40,41 +40,10 @@ Version 3.0.0 (in progress) Director exceptions (Swig::DirectorException) now derive from std::exception and hence provide the what() method. In Python and Ruby, this replaces the now deprecated DirectorException::getMessage() method. - -2014-01-16: wsfulton - [PHP] Fix compilation error in ZTS mode (64 bit windows) due to incorrect placement - of TSRMLS_FETCH() in SWIG_Php_GetModule() as reported by Mark Dawson-Butterworth. - 2014-01-14: diorcety Patch #112 - Fix symbol resolution involving scopes that have multiple levels of typedefs - fixes some template resolutions as well as some typemap searches. -2014-01-13: kwwette - [Octave] update support to Octave version 3.8.0 - - - Octave 3.8.0 no longer defines OCTAVE_API_VERSION_NUMBER, but 3.8.1 - will define OCTAVE_{MAJOR,MINOR,PATCH}_VERSION instead: see - http://hg.savannah.gnu.org/hgweb/octave/rev/b6b6e0dc700e - So we now use a new macro SWIG_OCTAVE_PREREQ(major,minor,patch) to - enable features requiring Octave version major.minor.patch or later. - - For Octave versions prior to 3.8.1, we reconstruct values for - OCTAVE_{MAJOR,MINOR,PATCH}_VERSION based on OCTAVE_API_VERSION_NUMBER, - extracted from Octave's ChangeLogs. An additional hack is needed to - distinguish between Octave <= 3.2.x and 3.8.0, neither of which define - OCTAVE_API_VERSION_NUMBER. - - - Octave 3.8.0 deprecates symbol_table::varref(), so remove its use - for this and future versions of Octave. - - - Octave 3.8.0 removes octave_value::is_real_nd_array(), used in - octave_swig_type::dims(). Its use is not required here, so remove it. - - - Retested against Octave versions 3.0.5, 3.2.4, 3.4.3, 3.6.4, and 3.8.0. - - - Updated Octave documentation with tested Octave versions, and added a - warning against using versions <= 3.x.x, which are no longer tested. - 2014-01-11: wsfulton Fix and document the naturalvar feature override behaviour - the naturalvar feature attached to a variable name has precedence over the naturalvar @@ -126,27 +95,6 @@ Version 3.0.0 (in progress) 2013-12-23: talby [Perl] Add support for directors. -2013-12-22: wsfulton - C++11 support for new versions of erase and insert in the STL containers. - - The erase and insert methods in the containers use const_iterator instead - of iterator in C++11. There are times when the methods wrapped must match - the parameters exactly. Specifically when full type information for - template types is missing or SWIG fails to look up the type correctly, - for example: - - %include - typedef float Real; - %template(RealVector) std::vector; - - SWIG does not find std::vector::iterator because %template using - typedefs does not always work and so SWIG doesn't know if the type is - copyable and so uses SwigValueWrapper which does - not support conversion to another type (const_iterator). This resulted - in compilation errors when using the C++11 version of the containers. - - Closes #73 - 2013-12-18: ianlancetaylor [Go] Don't require that Go environment variables be set when running examples or testsuite when using Go 1 or @@ -217,20 +165,10 @@ Version 3.0.0 (in progress) [Java] Apply patch #91 from Marvin Greenberg - Add director:except feature for improved exception handling in director methods for Java. -2013-10-17: wsfulton - [R] Fix SF #1340 - Visual Studio compile error in C++ wrappers due to #include - within extern "C" block. - -2013-10-17: wsfulton - [Python] Fix SF #1345 - Missing #include for offsetof when using -builtin. - 2013-10-15: vadz Allow using \l, \L, \u, \U and \E in the substitution part of %(regex:/pattern/subst/) inside %rename to change the case of the text being replaced. -2013-10-12: wsfulton - [Lua] Apply #92 - missing return statements for SWIG_Lua_add_namespace_details() - and SWIG_Lua_namespace_register(). 2013-10-12: wsfulton [CFFI] Apply #96 - superclass not lispify From 052d0057c2d96f013dbc3a477a46a10672db9094 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Feb 2014 16:24:04 +1300 Subject: [PATCH 0951/1160] Only call strlen(lc_fname) if we are going to use the result --- Lib/php/director.swg | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/php/director.swg b/Lib/php/director.swg index 50b433e47..6671f5580 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -102,12 +102,11 @@ namespace Swig { TSRMLS_FETCH_FROM_CTX(swig_zts_ctx); zend_class_entry **ce; zend_function *mptr; - int name_len = strlen(lc_fname); if (zend_lookup_class(cname, strlen(cname), &ce TSRMLS_CC) != SUCCESS) { return false; } - if (zend_hash_find(&(*ce)->function_table, lc_fname, name_len + 1, (void **) &mptr) != SUCCESS) { + if (zend_hash_find(&(*ce)->function_table, lc_fname, strlen(lc_fname) + 1, (void **) &mptr) != SUCCESS) { return false; } // common.scope points to the declaring class From 7af8b13ef7f9120988c1cbff9d72f2236d971089 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Feb 2014 16:25:29 +1300 Subject: [PATCH 0952/1160] Just call strcmp() rather than strlen() twice plus zend_binary_strcmp() --- Lib/php/globalvar.i | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Lib/php/globalvar.i b/Lib/php/globalvar.i index 1378ae60b..988559857 100644 --- a/Lib/php/globalvar.i +++ b/Lib/php/globalvar.i @@ -164,7 +164,7 @@ zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var); convert_to_string_ex(z_var); s1 = Z_STRVAL_PP(z_var); - if ((s1 == NULL) || ($1 == NULL) || zend_binary_strcmp(s1, strlen(s1), $1, strlen($1))) { + if ((s1 == NULL) || ($1 == NULL) || strcmp(s1, $1)) { if (s1) $1 = estrdup(s1); else @@ -190,9 +190,9 @@ zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var); s1 = Z_STRVAL_PP(z_var); - if((s1 == NULL) || ($1 == NULL) || zend_binary_strcmp(s1, strlen(s1), $1, strlen($1))) { - if(s1) - strncpy($1, s1, $1_dim0); + if ((s1 == NULL) || ($1 == NULL) || strcmp(s1, $1)) { + if (s1) + strncpy($1, s1, $1_dim0); } } @@ -288,7 +288,7 @@ zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var); s1 = Z_STRVAL_PP(z_var); - if((s1 == NULL) || ($1 == NULL) || zend_binary_strcmp(s1, strlen(s1), $1, strlen($1) )) { + if((s1 == NULL) || ($1 == NULL) || strcmp(s1, $1)) { if(s1) efree(s1); if($1) { @@ -325,7 +325,7 @@ deliberate error cos this code looks bogus to me zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var); s1 = Z_STRVAL_PP(z_var); - if((s1 == NULL) || zend_binary_strcmp(s1, strlen(s1), $1, strlen($1))) { + if((s1 == NULL) || strcmp(s1, $1)) { if($1) { (*z_var)->value.str.val = estrdup($1); (*z_var)->value.str.len = strlen($1)+1; From b761131fecf82634e925e63898d8d5bc3c5e860f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Feb 2014 16:26:48 +1300 Subject: [PATCH 0953/1160] "if (strlen(msg))" -> "if (msg[0])" --- Lib/php/director.swg | 2 +- Lib/python/director.swg | 2 +- Lib/ruby/director.swg | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/php/director.swg b/Lib/php/director.swg index 6671f5580..06eeb73b0 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -127,7 +127,7 @@ namespace Swig { std::string swig_msg; public: DirectorException(int code, const char *hdr, const char *msg TSRMLS_DC) : swig_msg(hdr) { - if (strlen(msg)) { + if (msg[0]) { swig_msg += " "; swig_msg += msg; } diff --git a/Lib/python/director.swg b/Lib/python/director.swg index bca22af4e..50f735a89 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -179,7 +179,7 @@ namespace Swig { public: DirectorException(PyObject *error, const char *hdr ="", const char *msg ="") : swig_msg(hdr) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; - if (strlen(msg)) { + if (msg[0]) { swig_msg += " "; swig_msg += msg; } diff --git a/Lib/ruby/director.swg b/Lib/ruby/director.swg index 3b1837374..c2c4150e6 100644 --- a/Lib/ruby/director.swg +++ b/Lib/ruby/director.swg @@ -118,7 +118,7 @@ namespace Swig { } DirectorException(VALUE error, const char *hdr, const char *msg ="") : swig_error(error), swig_msg(hdr) { - if (strlen(msg)) { + if (msg[0]) { swig_msg += " "; swig_msg += msg; } From fcf818075111d06936f0bd5541152f006ef30ba2 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Feb 2014 16:27:39 +1300 Subject: [PATCH 0954/1160] Whitespace tweaks --- Lib/php/globalvar.i | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/php/globalvar.i b/Lib/php/globalvar.i index 988559857..56f921434 100644 --- a/Lib/php/globalvar.i +++ b/Lib/php/globalvar.i @@ -216,7 +216,7 @@ $1_ltype _temp; zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var); - if (SWIG_ConvertPtr(*z_var, (void **)&_temp, $1_descriptor, 0) < 0) { + if (SWIG_ConvertPtr(*z_var, (void **)&_temp, $1_descriptor, 0) < 0) { SWIG_PHP_Error(E_ERROR,"Type error in value of $symname. Expected $&1_descriptor"); } @@ -293,7 +293,7 @@ efree(s1); if($1) { (*z_var)->value.str.val = estrdup($1); - (*z_var)->value.str.len = strlen($1) +1; + (*z_var)->value.str.len = strlen($1) + 1; } else { (*z_var)->value.str.val = 0; (*z_var)->value.str.len = 0; @@ -314,7 +314,7 @@ zval **z_var; zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var); - if($1) + if($1) SWIG_SetPointerZval(*z_var, (void*)$1, $1_descriptor, 0); } @@ -328,7 +328,7 @@ deliberate error cos this code looks bogus to me if((s1 == NULL) || strcmp(s1, $1)) { if($1) { (*z_var)->value.str.val = estrdup($1); - (*z_var)->value.str.len = strlen($1)+1; + (*z_var)->value.str.len = strlen($1) + 1; } else { (*z_var)->value.str.val = 0; (*z_var)->value.str.len = 0; From fcda732437c556927470adf5f116fda6d32532cf Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Feb 2014 19:44:20 +1300 Subject: [PATCH 0955/1160] fix typo --- Doc/Manual/Go.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 240db2b61..226acaabf 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -55,7 +55,7 @@ there is no convenient way to call C++ code. SWIG fills this gap.

    There are (at least) two different Go compilers. One is the gc -compiler, normally invoked under via the go tool. The other +compiler, normally invoked via the go tool. The other is the gccgo compiler, which is a frontend to the gcc compiler suite. The interface to C/C++ code is completely different for the two Go compilers. SWIG supports both, selected by a command line option. From 9cbd742b66b839d110af9b85ee210d60c7023f68 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 18 Feb 2014 07:30:55 +0000 Subject: [PATCH 0956/1160] Fix %$ismember %rename predicate for members added via %extend Bug reported was incorrect renaming of PHP built-in functions, such as next. See PHPFN in phpkw.swg. Add some tests for the %rename predicates. --- CHANGES.current | 3 ++ Examples/test-suite/common.mk | 2 + .../python/rename_predicates_runme.py | 35 +++++++++++++ Examples/test-suite/rename_predicates.i | 50 +++++++++++++++++++ Source/CParse/parser.y | 7 ++- 5 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/python/rename_predicates_runme.py create mode 100644 Examples/test-suite/rename_predicates.i diff --git a/CHANGES.current b/CHANGES.current index 013bf6257..770187d5e 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-02-15: wsfulton + Fix the %$ismember %rename predicates to also apply to members added via %extend. + 2014-02-16: hfalcic [Python] Patch #133 - fix crashes/exceptions in exception handling in Python 3.3 diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 5ce9a7031..836984476 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -86,6 +86,7 @@ CPP_TEST_BROKEN += \ li_boost_shared_ptr_template \ nested_private \ overload_complicated \ + rename_camel \ template_default_pointer \ template_private_assignment \ template_expr \ @@ -323,6 +324,7 @@ CPP_TEST_CASES += \ rename_strip_encoder \ rename_pcre_encoder \ rename_pcre_enum \ + rename_predicates \ restrict_cplusplus \ return_const_value \ return_value_scope \ diff --git a/Examples/test-suite/python/rename_predicates_runme.py b/Examples/test-suite/python/rename_predicates_runme.py new file mode 100644 index 000000000..f21f32348 --- /dev/null +++ b/Examples/test-suite/python/rename_predicates_runme.py @@ -0,0 +1,35 @@ +from rename_predicates import * + +r = RenamePredicates(123) +r.MF_member_function() +r.MF_static_member_function() +r.MF_extend_function_before() +r.MF_extend_function_after() +GF_global_function() + +if r.MV_member_variable != 123: + raise RuntimeError("variable wrong") +r.MV_member_variable = 1234; +if r.MV_member_variable != 1234: + raise RuntimeError("variable wrong") + +if cvar.RenamePredicates_MV_static_member_variable != 456: + raise RuntimeError("variable wrong") +cvar.RenamePredicates_MV_static_member_variable = 4567; +if cvar.RenamePredicates_MV_static_member_variable != 4567: + raise RuntimeError("variable wrong") + +if cvar.GV_global_variable != 789: + raise RuntimeError("variable wrong") +cvar.GV_global_variable = 7890; +if cvar.GV_global_variable != 7890: + raise RuntimeError("variable wrong") + +UC_UPPERCASE() +LC_lowercase() +TI_Title() +FU_FirstUpperCase() +FL_firstLowerCase() +CA_CamelCase() +LC_lowerCamelCase() +UC_under_case_it() diff --git a/Examples/test-suite/rename_predicates.i b/Examples/test-suite/rename_predicates.i new file mode 100644 index 000000000..a80f3c565 --- /dev/null +++ b/Examples/test-suite/rename_predicates.i @@ -0,0 +1,50 @@ +%module rename_predicates + +%rename("AF_%(utitle)s", %$isfunction) ""; +%rename("MF_%(utitle)s", %$isfunction, %$ismember) ""; +%rename("GF_%(utitle)s", %$isfunction, %$not %$ismember) ""; +%rename("MV_%(utitle)s", %$isvariable) ""; +%rename("GV_%(utitle)s", %$isvariable, %$isglobal) ""; + + +%extend RenamePredicates { + void extend_function_before() {} +} + +%inline %{ +struct RenamePredicates { + RenamePredicates(int v = 0) : member_variable(v) {} + void member_function() {} + static void static_member_function() {} + int member_variable; + static int static_member_variable; +}; +int RenamePredicates::static_member_variable = 456; +int global_variable = 789; +void global_function() {} +%} + +%extend RenamePredicates { + void extend_function_after() {} +} + +%rename("UC_%(upper)s") "uppercase"; +%rename("LC_%(lower)s") "LOWERcase"; +%rename("TI_%(title)s") "title"; +%rename("FU_%(firstuppercase)s") "firstUpperCase"; +%rename("FL_%(firstlowercase)s") "FirstLowerCase"; +%rename("CA_%(camelcase)s") "camel_Case"; +%rename("LC_%(lowercamelcase)s") "Lower_camel_Case"; +%rename("UC_%(undercase)s") "UnderCaseIt"; + +%inline %{ +void uppercase() {} +void LOWERcase() {} +void title() {} +void firstUpperCase() {} +void FirstLowerCase() {} +void camel_Case() {} +void Lower_camel_Case() {} +void UnderCaseIt() {} +%} + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 4c6d11e64..467f78587 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -356,10 +356,13 @@ static void add_symbols(Node *n) { } Delete(prefix); } - - Setattr(n,"ismember","1"); } } + + if (!isfriend && (inclass || extendmode)) { + Setattr(n,"ismember","1"); + } + if (!isfriend && inclass) { if ((cplus_mode != CPLUS_PUBLIC)) { only_csymbol = 1; From 43c8f2351c90574b02bff07c339e5cd530712f9b Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Tue, 18 Feb 2014 16:35:58 +0100 Subject: [PATCH 0957/1160] guile std_string test: run test in utf8 locale Guile can't properly handle non-ascii strings in the default C locale --- Examples/test-suite/guile/li_std_string_runme.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/guile/li_std_string_runme.scm b/Examples/test-suite/guile/li_std_string_runme.scm index 5b5563281..237caccbe 100644 --- a/Examples/test-suite/guile/li_std_string_runme.scm +++ b/Examples/test-suite/guile/li_std_string_runme.scm @@ -5,5 +5,5 @@ ; Note: when working with non-ascii strings in guile 2 ; locale must be set explicitly ; The setlocale call below takes care of that -(setlocale LC_ALL "") +(setlocale LC_ALL "en_US.utf8") (load "../schemerunme/li_std_string.scm") From c5911cc08da116482ddb3a498cc8deffd7f3f6ce Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 18 Feb 2014 20:36:24 +0000 Subject: [PATCH 0958/1160] Add %$isextendmember for %rename of members added via %extend --- CHANGES.current | 6 +++++ .../python/rename_predicates_runme.py | 7 ++++++ Examples/test-suite/rename_predicates.i | 23 ++++++++++++++++++- Lib/swig.swg | 1 + Source/CParse/parser.y | 18 +++++++++++---- 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 770187d5e..0ac740062 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -8,6 +8,12 @@ Version 3.0.0 (in progress) 2014-02-15: wsfulton Fix the %$ismember %rename predicates to also apply to members added via %extend. + Add %$isextendmember for %rename of members added via %extend. This can be used to + distinguish between normal class/struct members and %extend members. For example + '%$ismember, %$not %$isextendmember' will now identify just class/struct members. + + *** POTENTIAL INCOMPATIBILITY *** + 2014-02-16: hfalcic [Python] Patch #133 - fix crashes/exceptions in exception handling in Python 3.3 diff --git a/Examples/test-suite/python/rename_predicates_runme.py b/Examples/test-suite/python/rename_predicates_runme.py index f21f32348..2ce097737 100644 --- a/Examples/test-suite/python/rename_predicates_runme.py +++ b/Examples/test-suite/python/rename_predicates_runme.py @@ -33,3 +33,10 @@ FL_firstLowerCase() CA_CamelCase() LC_lowerCamelCase() UC_under_case_it() + +ex = ExtendCheck() +ex.MF_real_member1() +ex.MF_real_member2() +ex.EX_EXTENDMETHOD1() +ex.EX_EXTENDMETHOD2() +ex.EX_EXTENDMETHOD3() diff --git a/Examples/test-suite/rename_predicates.i b/Examples/test-suite/rename_predicates.i index a80f3c565..13fb3e1e4 100644 --- a/Examples/test-suite/rename_predicates.i +++ b/Examples/test-suite/rename_predicates.i @@ -1,12 +1,12 @@ %module rename_predicates +// Test a few of the predicates - %$isfunction etc %rename("AF_%(utitle)s", %$isfunction) ""; %rename("MF_%(utitle)s", %$isfunction, %$ismember) ""; %rename("GF_%(utitle)s", %$isfunction, %$not %$ismember) ""; %rename("MV_%(utitle)s", %$isvariable) ""; %rename("GV_%(utitle)s", %$isvariable, %$isglobal) ""; - %extend RenamePredicates { void extend_function_before() {} } @@ -28,6 +28,7 @@ void global_function() {} void extend_function_after() {} } +// Test the various %rename functions - %(upper) etc %rename("UC_%(upper)s") "uppercase"; %rename("LC_%(lower)s") "LOWERcase"; %rename("TI_%(title)s") "title"; @@ -48,3 +49,23 @@ void Lower_camel_Case() {} void UnderCaseIt() {} %} +// Test renaming only member functions in %extend +%rename("EX_%(upper)s", %$isfunction, %$isextendmember) ""; +%extend ExtendCheck { + void ExtendMethod1() {} +} +%inline %{ +struct ExtendCheck { + void RealMember1() {} +#ifdef SWIG + %extend { + void ExtendMethod2() {} + } +#endif + void RealMember2() {} +}; +%} +%extend ExtendCheck { + void ExtendMethod3() {} +} + diff --git a/Lib/swig.swg b/Lib/swig.swg index edadf036d..3ddbb85a0 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -297,6 +297,7 @@ static int NAME(TYPE x) { %define %$ismember "match$ismember"="1" %enddef %define %$isglobal %$not %$ismember %enddef +%define %$isextendmember "match$isextendmember"="1" %enddef %define %$innamespace "match$parentNode$nodeType"="namespace" %enddef %define %$ispublic "match$access"="public" %enddef diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 467f78587..dd8de45ff 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -363,6 +363,10 @@ static void add_symbols(Node *n) { Setattr(n,"ismember","1"); } + if (extendmode) { + Setattr(n,"isextendmember","1"); + } + if (!isfriend && inclass) { if ((cplus_mode != CPLUS_PUBLIC)) { only_csymbol = 1; @@ -1392,6 +1396,7 @@ static void mark_nodes_as_extend(Node *n) { for (; n; n = nextSibling(n)) { if (Getattr(n, "template") && Strcmp(nodeType(n), "class") == 0) continue; + /* Fix me: extend is not a feature. Replace with isextendmember? */ Setattr(n, "feature:extend", "1"); mark_nodes_as_extend(firstChild(n)); } @@ -4350,14 +4355,17 @@ cpp_members : cpp_member cpp_members { } } | EXTEND LBRACE { - if (cplus_mode != CPLUS_PUBLIC) { - Swig_error(cparse_file,cparse_line,"%%extend can only be used in a public section\n"); - } - } cpp_members RBRACE cpp_members { + extendmode = 1; + if (cplus_mode != CPLUS_PUBLIC) { + Swig_error(cparse_file,cparse_line,"%%extend can only be used in a public section\n"); + } + } cpp_members RBRACE { + extendmode = 0; + } cpp_members { $$ = new_node("extend"); mark_nodes_as_extend($4); appendChild($$,$4); - set_nextSibling($$,$6); + set_nextSibling($$,$7); } | include_directive { $$ = $1; } | empty { $$ = 0;} From f8a028517dbe21170bef7c2b951ed091e87d16ce Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 19 Feb 2014 00:12:55 +1300 Subject: [PATCH 0959/1160] Fix comment typos --- Lib/allkw.swg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/allkw.swg b/Lib/allkw.swg index 2e0dad6cf..b85b64579 100644 --- a/Lib/allkw.swg +++ b/Lib/allkw.swg @@ -4,14 +4,14 @@ /* Include all the known keyword warnings. Very useful for adding test - files to the test-suite, or check if your own library is ok for all + files to the test-suite, or checking if your own library is ok for all the swig supported languages. Use as swig -Wallkw ... - If you add a new language, remember to create a separete languagekw.swg + If you add a new language, remember to create a separate languagekw.swg file, and add it here. */ From 36c22b70bd37170c024bb742125a7647ab437754 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 19 Feb 2014 16:51:31 +1300 Subject: [PATCH 0960/1160] Make PHP %keywordwarn message wording consistent with other languages --- Examples/test-suite/wallkw.i | 2 +- Lib/php/phpkw.swg | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/wallkw.i b/Examples/test-suite/wallkw.i index 1a5866088..345aeeb0a 100644 --- a/Examples/test-suite/wallkw.i +++ b/Examples/test-suite/wallkw.i @@ -2,7 +2,7 @@ // test the -Wallkw option -%warnfilter(SWIGWARN_PARSE_KEYWORD) clone; // 'clone' is a php keyword, renamed as 'c_clone' +%warnfilter(SWIGWARN_PARSE_KEYWORD) clone; // 'clone' is a PHP keyword, renaming to 'c_clone' %warnfilter(SWIGWARN_PARSE_KEYWORD) delegate; // 'delegate' is a C# keyword, renaming to '_delegate' %warnfilter(SWIGWARN_PARSE_KEYWORD) pass; // 'pass' is a python keyword, renaming to '_pass' %warnfilter(SWIGWARN_PARSE_KEYWORD) alias; // 'alias' is a D keyword, renaming to '_alias' diff --git a/Lib/php/phpkw.swg b/Lib/php/phpkw.swg index 78a93369f..032559504 100644 --- a/Lib/php/phpkw.swg +++ b/Lib/php/phpkw.swg @@ -2,9 +2,9 @@ * phpkw.swg * ----------------------------------------------------------------------------- */ -#define PHPKW(x) %keywordwarn("'" `x` "' is a PHP keyword, renamed as 'c_" `x` "'",sourcefmt="%(lower)s",rename="c_%s") `x` +#define PHPKW(x) %keywordwarn("'" `x` "' is a PHP keyword, renaming to 'c_" `x` "'",sourcefmt="%(lower)s",rename="c_%s") `x` -#define PHPCN(x) %keywordwarn("'" `x` "' is a PHP reserved class name, class renamed as 'c_" `x` "'",%$isclass,sourcefmt="%(lower)s",rename="c_%s") `x` +#define PHPCN(x) %keywordwarn("'" `x` "' is a PHP reserved class name, renaming to 'c_" `x` "'",%$isclass,sourcefmt="%(lower)s",rename="c_%s") `x` #define PHPBN1(x) %builtinwarn("'" `x` "' conflicts with a built-in name in PHP",sourcefmt="%(lower)s") `x` #define PHPBN2(x) %builtinwarn("'" `x` "' conflicts with a built-in name in PHP") "::" `x` From 06e5a5fb0da2383a7e5405b3fbdc53e0494f7aed Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 19 Feb 2014 17:21:34 +1300 Subject: [PATCH 0961/1160] [PHP] Update the lists of PHP keywords with new ones from PHP 5.4 and newer (and some missing ones from 5.3). Reserved PHP constants names are now checked against enum values and constants, instead of against function and method names. Built-in PHP function names no longer match methods added by %extend. Functions and methods named '__sleep', '__wakeup', 'not', 'parent', or 'virtual' are no longer needlessly renamed. --- CHANGES.current | 9 ++ Lib/php/phpkw.swg | 296 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 232 insertions(+), 73 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 0ac740062..58efd5e5d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,15 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-02-19: olly + [PHP] Update the lists of PHP keywords with new ones from PHP 5.4 + and newer (and some missing ones from 5.3). Reserved PHP constants + names are now checked against enum values and constants, instead + of against function and method names. Built-in PHP function names + no longer match methods added by %extend. Functions and methods + named '__sleep', '__wakeup', 'not', 'parent', or 'virtual' are no + longer needlessly renamed. + 2014-02-15: wsfulton Fix the %$ismember %rename predicates to also apply to members added via %extend. diff --git a/Lib/php/phpkw.swg b/Lib/php/phpkw.swg index 032559504..14f37d2ff 100644 --- a/Lib/php/phpkw.swg +++ b/Lib/php/phpkw.swg @@ -2,37 +2,41 @@ * phpkw.swg * ----------------------------------------------------------------------------- */ +/* Keyword (case insensitive) */ #define PHPKW(x) %keywordwarn("'" `x` "' is a PHP keyword, renaming to 'c_" `x` "'",sourcefmt="%(lower)s",rename="c_%s") `x` +/* Class (case insensitive) */ #define PHPCN(x) %keywordwarn("'" `x` "' is a PHP reserved class name, renaming to 'c_" `x` "'",%$isclass,sourcefmt="%(lower)s",rename="c_%s") `x` -#define PHPBN1(x) %builtinwarn("'" `x` "' conflicts with a built-in name in PHP",sourcefmt="%(lower)s") `x` -#define PHPBN2(x) %builtinwarn("'" `x` "' conflicts with a built-in name in PHP") "::" `x` -#define PHPFN(x) %keywordwarn("'" `x` "' is a PHP built-in function, renamed as 'c_" `x` "'",sourcefmt="%(lower)s",%$isfunction,%$not %$ismember,rename="c_%s") `x` +/* Constant (case insensitive) */ +#define PHPBN1a(x) %namewarn(%warningmsg(SWIGWARN_PARSE_BUILTIN_NAME, "enum conflicts with a built-in constant '"`x`"' in PHP"),%$isenumitem,sourcefmt="%(lower)s") `x` +#define PHPBN1b(x) %namewarn(%warningmsg(SWIGWARN_PARSE_BUILTIN_NAME, "constant conflicts with a built-in constant '"`x`"' in PHP"),%$isconstant,sourcefmt="%(lower)s") `x` +%define PHPBN1(X) + PHPBN1a(X); PHPBN1b(X) +%enddef -/* - From +/* Constant (case sensitive) */ +#define PHPBN2a(x) %namewarn(%warningmsg(SWIGWARN_PARSE_BUILTIN_NAME, "enum conflicts with a built-in constant '"`x`"' in PHP"),%$isenumitem) `x` +#define PHPBN2b(x) %namewarn(%warningmsg(SWIGWARN_PARSE_BUILTIN_NAME, "constant conflicts with a built-in constant '"`x`"' in PHP"),%$isconstant) `x` +%define PHPBN2(X) + PHPBN2a(X); PHPBN2b(X) +%enddef - http://aspn.activestate.com/ASPN/docs/PHP/reserved.html - http://php.net/manual/en/reserved.keywords.php +#define PHPFN(x) %keywordwarn("'" `x` "' is a PHP built-in function, renaming to 'c_" `x` "'",sourcefmt="%(lower)s",%$isfunction,%$not %$ismember,rename="c_%s") `x` - and reviewed by Olly Betts. - - Further updates from the PHP manual on php.net. -*/ - -/* We classify these as kw since PHP will not run if used globally. */ -/* "You cannot use any of the following words as constants, class names, +/* From: http://php.net/manual/en/reserved.keywords.php + * "You cannot use any of the following words as constants, class names, * function or method names. Using them as variable names is generally OK, but * could lead to confusion." */ -/* case insensitive */ +/* Check is case insensitive - these *MUST* be listed in lower case here */ PHPKW(__halt_compiler); PHPKW(abstract); PHPKW(and); PHPKW(array); PHPKW(as); PHPKW(break); +PHPKW(callable); // As of PHP 5.4 PHPKW(case); PHPKW(catch); PHPKW(class); @@ -57,20 +61,22 @@ PHPKW(eval); // "Language construct" PHPKW(exit); // "Language construct" PHPKW(extends); PHPKW(final); +PHPKW(finally); // As of PHP 5.5 PHPKW(for); PHPKW(foreach); PHPKW(function); PHPKW(global); -PHPKW(goto); // As of PHP5.3 +PHPKW(goto); // As of PHP 5.3 PHPKW(if); PHPKW(implements); PHPKW(include); // "Language construct" PHPKW(include_once); // "Language construct" PHPKW(instanceof); +PHPKW(insteadof); // As of PHP 5.4 PHPKW(interface); PHPKW(isset); // "Language construct" PHPKW(list); // "Language construct" -PHPKW(namespace); // As of PHP5.3 +PHPKW(namespace); // As of PHP 5.3 PHPKW(new); PHPKW(or); PHPKW(print); // "Language construct" @@ -83,39 +89,70 @@ PHPKW(return); // "Language construct" PHPKW(static); PHPKW(switch); PHPKW(throw); +PHPKW(trait); // As of PHP 5.4 PHPKW(try); PHPKW(unset); // "Language construct" PHPKW(use); PHPKW(var); PHPKW(while); PHPKW(xor); -// Compile-time constants -PHPKW(__CLASS__); -PHPKW(__DIR__); // As of PHP5.3 -PHPKW(__FILE__); -PHPKW(__FUNCTION__); -PHPKW(__METHOD__); -PHPKW(__NAMESPACE__); // As of PHP5.3 -PHPKW(__LINE__); +PHPKW(yield); // As of PHP 5.5 + +// Compile-time "magic" constants +// From: http://php.net/manual/en/reserved.keywords.php +// also at: http://php.net/manual/en/language.constants.predefined.php +/* These *MUST* be listed in lower case here */ +PHPKW(__class__); +PHPKW(__dir__); // As of PHP 5.3 +PHPKW(__file__); +PHPKW(__function__); +PHPKW(__line__); +PHPKW(__method__); +PHPKW(__namespace__); // As of PHP 5.3 +PHPKW(__trait__); // As of PHP 5.4 /* We classify these as built-in names since they conflict, but PHP still runs */ -/* Type 1: case insensitive */ -PHPBN1(__sleep); -PHPBN1(__wakeup); -PHPBN1(not); -PHPBN1(parent); -PHPBN1(virtual); -PHPBN1(NULL); -PHPBN1(TRUE); -PHPBN1(FALSE); +/* Predefined case-insensitive constants */ +/* These *MUST* be listed in lower case here */ +PHPBN1(null); +PHPBN1(true); +PHPBN1(false); -/* Type 2: case sensitive */ -/* "Core Predefined Constants" from http://uk2.php.net/manual/en/reserved.constants.php */ -PHPBN2(E_ALL); +/* "Core Predefined Constants" from http://php.net/manual/en/reserved.constants.php */ +/* These are case sensitive */ +PHPBN2(PHP_VERSION); +PHPBN2(PHP_MAJOR_VERSION); // As of PHP 5.2.7 +PHPBN2(PHP_MINOR_VERSION); // As of PHP 5.2.7 +PHPBN2(PHP_RELEASE_VERSION); // As of PHP 5.2.7 +PHPBN2(PHP_VERSION_ID); // As of PHP 5.2.7 +PHPBN2(PHP_EXTRA_VERSION); // As of PHP 5.2.7 +PHPBN2(PHP_ZTS); // As of PHP 5.2.7 +PHPBN2(PHP_DEBUG); // As of PHP 5.2.7 +PHPBN2(PHP_MAXPATHLEN); // As of PHP 5.3.0 +PHPBN2(PHP_OS); +PHPBN2(PHP_SAPI); +PHPBN2(PHP_EOL); // As of PHP 5.0.2 +PHPBN2(PHP_INT_MAX); // As of PHP 5.0.5 +PHPBN2(PHP_INT_SIZE); // As of PHP 5.0.5 +PHPBN2(DEFAULT_INCLUDE_PATH); +PHPBN2(PEAR_INSTALL_DIR); +PHPBN2(PEAR_EXTENSION_DIR); +PHPBN2(PHP_EXTENSION_DIR); +PHPBN2(PHP_PREFIX); +PHPBN2(PHP_BINDIR); +PHPBN2(PHP_BINARY); // As of PHP 5.4 +PHPBN2(PHP_MANDIR); // As of PHP 5.3.7 +PHPBN2(PHP_LIBDIR); +PHPBN2(PHP_DATADIR); +PHPBN2(PHP_SYSCONFDIR); +PHPBN2(PHP_LOCALSTATEDIR); +PHPBN2(PHP_CONFIG_FILE_PATH); +PHPBN2(PHP_CONFIG_FILE_SCAN_DIR); +PHPBN2(PHP_SHLIB_SUFFIX); PHPBN2(E_ERROR); -PHPBN2(E_PARSE); PHPBN2(E_WARNING); +PHPBN2(E_PARSE); PHPBN2(E_NOTICE); PHPBN2(E_CORE_ERROR); PHPBN2(E_CORE_WARNING); @@ -124,31 +161,17 @@ PHPBN2(E_COMPILE_WARNING); PHPBN2(E_USER_ERROR); PHPBN2(E_USER_WARNING); PHPBN2(E_USER_NOTICE); -PHPBN2(E_DEPRECATED); // As of PHP 5.3 -PHPBN2(E_USER_DEPRECATED); // As of PHP 5.3 -PHPBN2(PHP_OS); -PHPBN2(PHP_VERSION); -PHPBN2(PHP_SAPI); -PHPBN2(PHP_EOL); -PHPBN2(PHP_INT_MAX); -PHPBN2(PHP_INT_SIZE); -PHPBN2(DEFAULT_INCLUDE_PATH); -PHPBN2(PEAR_INSTALL_DIR); -PHPBN2(PEAR_EXTENSION_DIR); -PHPBN2(PHP_EXTENSION_DIR); -PHPBN2(PHP_PREFIX); -PHPBN2(PHP_BINDIR); -PHPBN2(PHP_LIBDIR); -PHPBN2(PHP_DATADIR); -PHPBN2(PHP_SYSCONFDIR); -PHPBN2(PHP_LOCALSTATEDIR); -PHPBN2(PHP_CONFIG_FILE_PATH); -PHPBN2(PHP_CONFIG_FILE_SCAN_DIR); -PHPBN2(PHP_SHLIB_SUFFIX); +PHPBN2(E_DEPRECATED); // As of PHP 5.3.0 +PHPBN2(E_USER_DEPRECATED); // As of PHP 5.3.0 +PHPBN2(E_ALL); +PHPBN2(E_STRICT); +PHPBN2(__COMPILER_HALT_OFFSET__); // As of PHP 5.1.0 +// TRUE, FALSE, NULL are listed on the same page, but are actually +// case-insensitive, whereas all the other constants listed there seem to be +// case-sensitive, so we handle TRUE, FALSE, NULL in PHPBN1. PHPBN2(PHP_OUTPUT_HANDLER_START); PHPBN2(PHP_OUTPUT_HANDLER_CONT); PHPBN2(PHP_OUTPUT_HANDLER_END); -PHPBN2(PHP_MAXPATHLEN); // As of PHP 5.3 /* These don't actually seem to be set (tested on Linux, I guess they're * Windows only?) */ PHPBN2(PHP_WINDOWS_NT_DOMAIN_CONTROLLER); // As of PHP 5.3 @@ -162,7 +185,7 @@ PHPBN2(PHP_WINDOWS_VERSION_PRODUCTTYPE); // As of PHP 5.3 PHPBN2(PHP_WINDOWS_VERSION_SP_MAJOR); // As of PHP 5.3 PHPBN2(PHP_WINDOWS_VERSION_SP_MINOR); // As of PHP 5.3 PHPBN2(PHP_WINDOWS_VERSION_SUITEMASK); // As of PHP 5.3 -/* "Standard Predefined Constants" from http://uk2.php.net/manual/en/reserved.constants.php */ +/* "Standard Predefined Constants" from http://php.net/manual/en/reserved.constants.php */ PHPBN2(EXTR_OVERWRITE); PHPBN2(EXTR_SKIP); PHPBN2(EXTR_PREFIX_SAME); @@ -370,10 +393,6 @@ PHPBN2(LOG_NDELAY); PHPBN2(LOG_NOWAIT); PHPBN2(LOG_PERROR); -/* Added in PHP5 */ -PHPBN2(E_STRICT); -PHPBN2(__COMPILER_HALT_OFFSET__); - /* Added in PHP 5.2 */ PHPBN2(PREG_BACKTRACK_LIMIT_ERROR); PHPBN2(PREG_BAD_UTF8_ERROR); @@ -485,17 +504,143 @@ PHPBN2(SIG_UNBLOCK); PHPBN2(TRAP_BRKPT); PHPBN2(TRAP_TRACE); -/* Class names reserved by PHP */ -/* case insensitive */ +/* Added in PHP 5.4 */ +PHPBN2(ENT_DISALLOWED); +PHPBN2(ENT_HTML401); +PHPBN2(ENT_HTML5); +PHPBN2(ENT_SUBSTITUTE); +PHPBN2(ENT_XML1); +PHPBN2(ENT_XHTML); +PHPBN2(IPPROTO_IP); +PHPBN2(IPPROTO_IPV6); +PHPBN2(IPV6_MULTICAST_HOPS); +PHPBN2(IPV6_MULTICAST_IF); +PHPBN2(IPV6_MULTICAST_LOOP); +PHPBN2(IP_MULTICAST_IF); +PHPBN2(IP_MULTICAST_LOOP); +PHPBN2(IP_MULTICAST_TTL); +PHPBN2(MCAST_JOIN_GROUP); +PHPBN2(MCAST_LEAVE_GROUP); +PHPBN2(MCAST_BLOCK_SOURCE); +PHPBN2(MCAST_UNBLOCK_SOURCE); +PHPBN2(MCAST_JOIN_SOURCE_GROUP); +PHPBN2(MCAST_LEAVE_SOURCE_GROUP); +PHPBN2(CURLOPT_MAX_RECV_SPEED_LARGE); +PHPBN2(CURLOPT_MAX_SEND_SPEED_LARGE); +PHPBN2(LIBXML_HTML_NODEFDTD); +PHPBN2(LIBXML_HTML_NOIMPLIED); +PHPBN2(LIBXML_PEDANTIC); +PHPBN2(OPENSSL_CIPHER_AES_128_CBC); +PHPBN2(OPENSSL_CIPHER_AES_192_CBC); +PHPBN2(OPENSSL_CIPHER_AES_256_CBC); +PHPBN2(OPENSSL_RAW_DATA); +PHPBN2(OPENSSL_ZERO_PADDING); +PHPBN2(PHP_OUTPUT_HANDLER_CLEAN); +PHPBN2(PHP_OUTPUT_HANDLER_CLEANABLE); +PHPBN2(PHP_OUTPUT_HANDLER_DISABLED); +PHPBN2(PHP_OUTPUT_HANDLER_FINAL); +PHPBN2(PHP_OUTPUT_HANDLER_FLUSH); +PHPBN2(PHP_OUTPUT_HANDLER_FLUSHABLE); +PHPBN2(PHP_OUTPUT_HANDLER_REMOVABLE); +PHPBN2(PHP_OUTPUT_HANDLER_STARTED); +PHPBN2(PHP_OUTPUT_HANDLER_STDFLAGS); +PHPBN2(PHP_OUTPUT_HANDLER_WRITE); +PHPBN2(PHP_SESSION_ACTIVE); +PHPBN2(PHP_SESSION_DISABLED); +PHPBN2(PHP_SESSION_NONE); +PHPBN2(STREAM_META_ACCESS); +PHPBN2(STREAM_META_GROUP); +PHPBN2(STREAM_META_GROUP_NAME); +PHPBN2(STREAM_META_OWNER); +PHPBN2(STREAM_META_OWNER_NAME); +PHPBN2(STREAM_META_TOUCH); +PHPBN2(ZLIB_ENCODING_DEFLATE); +PHPBN2(ZLIB_ENCODING_GZIP); +PHPBN2(ZLIB_ENCODING_RAW); +PHPBN2(U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR); +PHPBN2(IDNA_CHECK_BIDI); +PHPBN2(IDNA_CHECK_CONTEXTJ); +PHPBN2(IDNA_NONTRANSITIONAL_TO_ASCII); +PHPBN2(IDNA_NONTRANSITIONAL_TO_UNICODE); +PHPBN2(INTL_IDNA_VARIANT_2003); +PHPBN2(INTL_IDNA_VARIANT_UTS46); +PHPBN2(IDNA_ERROR_EMPTY_LABEL); +PHPBN2(IDNA_ERROR_LABEL_TOO_LONG); +PHPBN2(IDNA_ERROR_DOMAIN_NAME_TOO_LONG); +PHPBN2(IDNA_ERROR_LEADING_HYPHEN); +PHPBN2(IDNA_ERROR_TRAILING_HYPHEN); +PHPBN2(IDNA_ERROR_HYPHEN_3_4); +PHPBN2(IDNA_ERROR_LEADING_COMBINING_MARK); +PHPBN2(IDNA_ERROR_DISALLOWED); +PHPBN2(IDNA_ERROR_PUNYCODE); +PHPBN2(IDNA_ERROR_LABEL_HAS_DOT); +PHPBN2(IDNA_ERROR_INVALID_ACE_LABEL); +PHPBN2(IDNA_ERROR_BIDI); +PHPBN2(IDNA_ERROR_CONTEXTJ); +PHPBN2(JSON_PRETTY_PRINT); +PHPBN2(JSON_UNESCAPED_SLASHES); +PHPBN2(JSON_NUMERIC_CHECK); +PHPBN2(JSON_UNESCAPED_UNICODE); +PHPBN2(JSON_BIGINT_AS_STRING); + +/* Added in PHP 5.5 */ +PHPBN2(IMG_AFFINE_TRANSLATE); +PHPBN2(IMG_AFFINE_SCALE); +PHPBN2(IMG_AFFINE_ROTATE); +PHPBN2(IMG_AFFINE_SHEAR_HORIZONTAL); +PHPBN2(IMG_AFFINE_SHEAR_VERTICAL); +PHPBN2(IMG_CROP_DEFAULT); +PHPBN2(IMG_CROP_TRANSPARENT); +PHPBN2(IMG_CROP_BLACK); +PHPBN2(IMG_CROP_WHITE); +PHPBN2(IMG_CROP_SIDES); +PHPBN2(IMG_FLIP_BOTH); +PHPBN2(IMG_FLIP_HORIZONTAL); +PHPBN2(IMG_FLIP_VERTICAL); +PHPBN2(IMG_BELL); +PHPBN2(IMG_BESSEL); +PHPBN2(IMG_BICUBIC); +PHPBN2(IMG_BICUBIC_FIXED); +PHPBN2(IMG_BLACKMAN); +PHPBN2(IMG_BOX); +PHPBN2(IMG_BSPLINE); +PHPBN2(IMG_CATMULLROM); +PHPBN2(IMG_GAUSSIAN); +PHPBN2(IMG_GENERALIZED_CUBIC); +PHPBN2(IMG_HERMITE); +PHPBN2(IMG_HAMMING); +PHPBN2(IMG_HANNING); +PHPBN2(IMG_MITCHELL); +PHPBN2(IMG_POWER); +PHPBN2(IMG_QUADRATIC); +PHPBN2(IMG_SINC); +PHPBN2(IMG_NEAREST_NEIGHBOUR); +PHPBN2(IMG_WEIGHTED4); +PHPBN2(IMG_TRIANGLE); +PHPBN2(JSON_ERROR_RECURSION); +PHPBN2(JSON_ERROR_INF_OR_NAN); +PHPBN2(JSON_ERROR_UNSUPPORTED_TYPE); +PHPBN2(MYSQLI_SERVER_PUBLIC_KEY); + +/* Added in PHP 5.6 */ +PHPBN2(LDAP_ESCAPE_DN); +PHPBN2(LDAP_ESCAPE_FILTER); + +/* Class names reserved by PHP (case insensitive) */ +PHPCN(directory); PHPCN(stdclass); PHPCN(__php_incomplete_class); -PHPCN(directory); -/* Added in PHP5 (this list apparently depends which extensions you load by default). */ -PHPCN(parent); -PHPCN(self); +/* Added in PHP5. */ PHPCN(exception); +PHPCN(errorexception); // As of PHP 5.1 PHPCN(php_user_filter); -PHPCN(errorexception); +PHPCN(closure); // As of PHP 5.3 +PHPCN(generator); // As of PHP 5.5 +PHPCN(self); +PHPCN(static); +PHPCN(parent); +/* From extensions (which of these are actually predefined depends which + * extensions are loaded by default). */ PHPCN(xmlwriter); PHPCN(libxmlerror); PHPCN(simplexmlelement); @@ -588,7 +733,8 @@ PHPCN(sqliteexception); PHPCN(datetime); /* Built-in PHP functions (incomplete). */ -/* Includes Array Functions - http://us3.php.net/manual/en/ref.array.php */ +/* Includes Array Functions - http://php.net/manual/en/ref.array.php */ +/* Check is case insensitive - these *MUST* be listed in lower case here */ PHPFN(acos); PHPFN(array_change_key_case); PHPFN(array_chunk); @@ -688,7 +834,11 @@ PHPFN(uksort); PHPFN(usort); #undef PHPKW +#undef PHPBN1a +#undef PHPBN1b #undef PHPBN1 +#undef PHPBN2a +#undef PHPBN2b #undef PHPBN2 #undef PHPCN #undef PHPFN From 1aa6220041567e4260b60cde3238be3e3228dfac Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 19 Feb 2014 17:22:28 +1300 Subject: [PATCH 0962/1160] Fix incorrect patch number --- CHANGES.current | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 58efd5e5d..9f6d40689 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -24,7 +24,7 @@ Version 3.0.0 (in progress) *** POTENTIAL INCOMPATIBILITY *** 2014-02-16: hfalcic - [Python] Patch #133 - fix crashes/exceptions in exception handling in Python 3.3 + [Python] Patch #137 - fix crashes/exceptions in exception handling in Python 3.3 2014-02-15: wsfulton [Java] Add support for the cdata library. From ae14ad0c4ab934379dc035b5aa763ea6adc1157b Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 19 Feb 2014 18:26:07 +1300 Subject: [PATCH 0963/1160] Rename "struct Global" to "struct Global_" to avoid PHP keyword --- Examples/test-suite/nested_scope.i | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/nested_scope.i b/Examples/test-suite/nested_scope.i index 08871f182..789478361 100644 --- a/Examples/test-suite/nested_scope.i +++ b/Examples/test-suite/nested_scope.i @@ -6,7 +6,8 @@ %inline %{ namespace ns { - struct Global { + // "global" is a case-insensitive keyword in PHP. + struct Global_ { #ifdef __clang__ struct Outer { struct Nested; From 6d08992945cc5c34698330c7b17659fae2592b12 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 19 Feb 2014 18:26:40 +1300 Subject: [PATCH 0964/1160] Add expected functions which get generated to silence testsuite warning --- Examples/test-suite/php/director_protected_runme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/php/director_protected_runme.php b/Examples/test-suite/php/director_protected_runme.php index 9d47ef658..226f28a0b 100644 --- a/Examples/test-suite/php/director_protected_runme.php +++ b/Examples/test-suite/php/director_protected_runme.php @@ -4,7 +4,7 @@ require "tests.php"; require "director_protected.php"; // No new functions -check::functions(array(foo_pong,foo_s,foo_q,foo_ping,foo_pang,foo_used,bar_create,bar_pong,bar_used,bar_ping,bar_pang,a_draw,b_draw)); +check::functions(array(foo_pong,foo_s,foo_q,foo_ping,foo_pang,foo_used,foo_cheer,bar_create,bar_callping,bar_callcheer,bar_cheer,bar_pong,bar_used,bar_ping,bar_pang,a_draw,b_draw)); // No new classes check::classes(array(Foo,Bar,PrivateFoo,A,B,AA,BB)); // now new vars From 7df6c832c3370ce51c16b8c37e06ee80a961da0d Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 19 Feb 2014 18:27:14 +1300 Subject: [PATCH 0965/1160] Remove incorrect comments --- Examples/test-suite/php/director_protected_runme.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/Examples/test-suite/php/director_protected_runme.php b/Examples/test-suite/php/director_protected_runme.php index 226f28a0b..18586ca62 100644 --- a/Examples/test-suite/php/director_protected_runme.php +++ b/Examples/test-suite/php/director_protected_runme.php @@ -3,11 +3,8 @@ require "tests.php"; require "director_protected.php"; -// No new functions check::functions(array(foo_pong,foo_s,foo_q,foo_ping,foo_pang,foo_used,foo_cheer,bar_create,bar_callping,bar_callcheer,bar_cheer,bar_pong,bar_used,bar_ping,bar_pang,a_draw,b_draw)); -// No new classes check::classes(array(Foo,Bar,PrivateFoo,A,B,AA,BB)); -// now new vars check::globals(array(bar_a)); class FooBar extends Bar { From 5b957278a8500e9dfadbb9d1ebc7bf33f5b7c5f5 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 19 Feb 2014 22:07:26 +1300 Subject: [PATCH 0966/1160] -Wallkw now includes keywords for all languages with keyword warnings (previously Go and R were missing). --- CHANGES.current | 4 ++++ Lib/allkw.swg | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 9f6d40689..6595c248e 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-02-19: olly + -Wallkw now includes keywords for all languages with keyword + warnings (previously Go and R were missing). + 2014-02-19: olly [PHP] Update the lists of PHP keywords with new ones from PHP 5.4 and newer (and some missing ones from 5.3). Reserved PHP constants diff --git a/Lib/allkw.swg b/Lib/allkw.swg index b85b64579..99c2969e4 100644 --- a/Lib/allkw.swg +++ b/Lib/allkw.swg @@ -19,14 +19,16 @@ %include %include %include +%include %include +%include +%include %include %include %include -%include +%include %include %include -%include #endif //__Lib_allkw_swg__ From 91461647486b79b055e11b4a15b75e90a0783da1 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 19 Feb 2014 22:09:39 +1300 Subject: [PATCH 0967/1160] Extend php_namewarn_rename to act as a regression test for the warning about built-in function names used in %extend --- Examples/test-suite/php_namewarn_rename.i | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Examples/test-suite/php_namewarn_rename.i b/Examples/test-suite/php_namewarn_rename.i index e3447a9c4..de8a62501 100644 --- a/Examples/test-suite/php_namewarn_rename.i +++ b/Examples/test-suite/php_namewarn_rename.i @@ -7,6 +7,11 @@ %warnfilter(SWIGWARN_PARSE_KEYWORD) Hello::empty(); #endif +%ignore prev::operator++; +%extend prev { + void next() { ++(*self); } +} + %inline %{ int Exception() { return 13; } @@ -26,4 +31,9 @@ void empty() {} }; + struct prev { + prev & operator++() { } + prev operator++(int) { } + }; + %} From 1c5a0f8b9cb3f413df92a87fbb4d65895b954434 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Mon, 28 Oct 2013 13:18:15 +0400 Subject: [PATCH 0968/1160] Initial implementation - everything compiles but might not work --- Examples/test-suite/nspace.i | 2 +- Lib/lua/luarun.swg | 78 +++- Lib/lua/luaruntime.swg | 23 +- Source/Modules/lang.cxx | 8 + Source/Modules/lua.cxx | 720 ++++++++++++++++++++++++++++------- Source/Modules/swigmod.h | 1 + 6 files changed, 655 insertions(+), 177 deletions(-) diff --git a/Examples/test-suite/nspace.i b/Examples/test-suite/nspace.i index c60a45df5..58c560412 100644 --- a/Examples/test-suite/nspace.i +++ b/Examples/test-suite/nspace.i @@ -2,7 +2,7 @@ %module nspace // nspace feature only supported by these languages -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGLUA) #if defined(SWIGJAVA) SWIG_JAVABODY_PROXY(public, public, SWIGTYPE) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 8485ed499..04d18fdb7 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -129,10 +129,13 @@ typedef struct { swig_type_info **ptype; } swig_lua_const_info; +/* TODO:REMOVE typedef struct { const char *name; lua_CFunction method; } swig_lua_method; +*/ +typedef luaL_Reg swig_lua_method; typedef struct { const char *name; @@ -140,16 +143,20 @@ typedef struct { lua_CFunction setmethod; } swig_lua_attribute; + +struct swig_lua_class; // Can be used to create namespaces. Currently used to // wrap class static methods/variables/constants -typedef struct { +struct swig_lua_namespace { const char *name; swig_lua_method *ns_methods; swig_lua_attribute *ns_attributes; swig_lua_const_info *ns_constants; -} swig_lua_namespace; + swig_lua_class **ns_classes; + swig_lua_namespace **ns_namespaces; +}; -typedef struct swig_lua_class { +struct swig_lua_class { const char *name; swig_type_info **type; lua_CFunction constructor; @@ -159,7 +166,7 @@ typedef struct swig_lua_class { swig_lua_namespace cls_static; struct swig_lua_class **bases; const char **base_names; -} swig_lua_class; +}; /* this is the struct for wrapping all pointers in SwigLua */ @@ -497,28 +504,29 @@ SWIGINTERN int SWIG_Lua_namespace_set(lua_State* L) } SWIGINTERN void SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]); // forward declaration -SWIGINTERN void SWIG_Lua_add_class_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn); // forward declaration +SWIGINTERN void SWIG_Lua_add_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn); // forward declaration +SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss); /* helper function - register namespace methods and attributes into namespace */ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* ns) { int i = 0; - assert(lua_istable(L,-1)); /* There must be table at the top of the stack */ + assert(lua_istable(L,-1)); SWIG_Lua_InstallConstants(L, ns->ns_constants); lua_getmetatable(L,-1); /* add fns */ for(i=0;ns->ns_attributes[i].name;i++){ - SWIG_Lua_add_class_variable(L,ns->ns_attributes[i].name,ns->ns_attributes[i].getmethod,ns->ns_attributes[i].setmethod); + SWIG_Lua_add_variable(L,ns->ns_attributes[i].name,ns->ns_attributes[i].getmethod,ns->ns_attributes[i].setmethod); } /* add methods to the metatable */ SWIG_Lua_get_table(L,".fn"); /* find the .fn table */ assert(lua_istable(L,-1)); /* just in case */ for(i=0;ns->ns_methods[i].name;i++){ - SWIG_Lua_add_function(L,ns->ns_methods[i].name,ns->ns_methods[i].method); + SWIG_Lua_add_function(L,ns->ns_methods[i].name,ns->ns_methods[i].func); } lua_pop(L,1); @@ -527,12 +535,29 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* return 0; } -/* helper function. creates namespace table and add it to module table */ -SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns) +/* Register all classes in the namespace + */ +SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State* L, swig_lua_namespace* ns) { - assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table */ + swig_lua_class** classes = ns->ns_classes; + + if( classes != 0 ) { + while((*classes)->name != 0) { + SWIG_Lua_class_register(L, *classes); + classes++; + } + } +} + +/* helper function. creates namespace table and add it to module table + if 'reg' is true, then will register namespace table to parent one (must be on top of the stack + when function is called) + Function always returns newly registered table on top of the stack +*/ +SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns, bool reg) +{ + assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table or parent namespace table */ lua_checkstack(L,5); - lua_pushstring(L, ns->name); lua_newtable(L); /* namespace itself */ lua_newtable(L); /* metatable for namespace */ @@ -554,8 +579,23 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns) SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_namespace_set); lua_setmetatable(L,-2); /* set metatable */ - lua_rawset(L,-3); /* add namespace to module table */ - return 0; + + // Register all functions, variables etc + SWIG_Lua_add_namespace_details(L,ns); + + swig_lua_namespace** sub_namespace = ns->ns_namespaces; + if( sub_namespace != 0) { + while((*sub_namespace)->name != 0) { + SWIG_Lua_namespace_register(L, *sub_namespace, true); + sub_namespace++; + } + } + + if (reg) { + lua_pushstring(L,ns->name); + lua_pushvalue(L,-2); + lua_rawset(L,-4); /* add namespace to module table */ + } } /* ----------------------------------------------------------------------------- * global variable support code: classes @@ -757,7 +797,7 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State* L,const char* cname) } /* helper add a variable to a registered class */ -SWIGINTERN void SWIG_Lua_add_class_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn) +SWIGINTERN void SWIG_Lua_add_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn) { assert(lua_istable(L,-1)); /* just in case */ SWIG_Lua_get_table(L,".get"); /* find the .get table */ @@ -799,13 +839,13 @@ SWIGINTERN void SWIG_Lua_add_class_details(lua_State* L,swig_lua_class* clss) } /* add fns */ for(i=0;clss->attributes[i].name;i++){ - SWIG_Lua_add_class_variable(L,clss->attributes[i].name,clss->attributes[i].getmethod,clss->attributes[i].setmethod); + SWIG_Lua_add_variable(L,clss->attributes[i].name,clss->attributes[i].getmethod,clss->attributes[i].setmethod); } /* add methods to the metatable */ SWIG_Lua_get_table(L,".fn"); /* find the .fn table */ assert(lua_istable(L,-1)); /* just in case */ for(i=0;clss->methods[i].name;i++){ - SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].method); + SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].func); } lua_pop(L,1); /* tidy stack (remove table) */ /* add operator overloads @@ -814,7 +854,7 @@ SWIGINTERN void SWIG_Lua_add_class_details(lua_State* L,swig_lua_class* clss) (this might mess up is someone defines a method __gc (the destructor)*/ for(i=0;clss->methods[i].name;i++){ if (clss->methods[i].name[0]=='_' && clss->methods[i].name[1]=='_'){ - SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].method); + SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].func); } } } @@ -848,7 +888,7 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* cls assert(lua_istable(L,-1)); /* just in case */ assert(strcmp(clss->name, clss->cls_static.name) == 0); /* in class those 2 must be equal */ - SWIG_Lua_namespace_register(L,&clss->cls_static); + SWIG_Lua_namespace_register(L,&clss->cls_static, false); SWIG_Lua_get_table(L,clss->name); // Get namespace table back assert(lua_istable(L,-1)); /* just in case */ diff --git a/Lib/lua/luaruntime.swg b/Lib/lua/luaruntime.swg index 423c7190b..0011c9d52 100644 --- a/Lib/lua/luaruntime.swg +++ b/Lib/lua/luaruntime.swg @@ -40,16 +40,6 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */ /* add a global fn */ SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type); SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_equal); - /* begin the module (its a table with the same name as the module) */ - SWIG_Lua_module_begin(L,SWIG_name); - /* add commands/functions */ - for (i = 0; swig_commands[i].name; i++){ - SWIG_Lua_module_add_function(L,swig_commands[i].name,swig_commands[i].func); - } - /* add variables */ - for (i = 0; swig_variables[i].name; i++){ - SWIG_Lua_module_add_variable(L,swig_variables[i].name,swig_variables[i].get,swig_variables[i].set); - } #endif #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) @@ -59,17 +49,16 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */ SWIG_Lua_init_base_class(L,(swig_lua_class*)(swig_types[i]->clientdata)); } } - /* additional registration structs & classes in lua */ - for (i = 0; swig_types[i]; i++){ - if (swig_types[i]->clientdata){ - SWIG_Lua_class_register(L,(swig_lua_class*)(swig_types[i]->clientdata)); - } - } + bool globalRegister = false; +#ifdef SWIG_LUA_MODULE_GLOBAL + globalRegister = true; +#endif + SWIG_Lua_namespace_register(L,&swig___Global, globalRegister); #endif #if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)) /* constants */ - SWIG_Lua_InstallConstants(L,swig_constants); + /* TODO: REMOVE */ #endif #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 3940a3001..97ed295c9 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -3049,6 +3049,7 @@ void Language::main(int argc, char *argv[]) { * ----------------------------------------------------------------------------- */ int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr scope) { + //Printf( stdout, "addSymbol: %s %s\n", s, scope ); Hash *symbols = Getattr(symtabs, scope ? scope : ""); if (!symbols) { // New scope which has not been added by the target language - lazily created. @@ -3468,6 +3469,13 @@ String *Language::getNSpace() const { return NSpace; } +/* ----------------------------------------------------------------------------- + * Language::setNSpace() + * ----------------------------------------------------------------------------- */ +void Language::setNSpace(String *nspace) { + NSpace = nspace; +} + /* ----------------------------------------------------------------------------- * Language::getClassName() * ----------------------------------------------------------------------------- */ diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index b76945b95..10d9592cd 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -105,25 +105,27 @@ private: File *f_runtime; File *f_header; File *f_wrappers; + File *f_wrappersForward; // forward declarations for wrappers, TODO: REMOVE File *f_init; File *f_initbeforefunc; - String *s_cmd_tab; // table of command names - String *s_var_tab; // table of global variables - String *s_const_tab; // table of global constants + /* + String *s_ns_methods_tab; // table of namespace methods + String *s_ns_var_tab; // Lua only:table of namespace variables + String *s_ns_dot_get; // eLua only:table of variable 'get' functions + String *s_ns_dot_set; // eLua only:table of variable 'set' functions + String *s_ns_const_tab; // table of namespace constants + */ String *s_methods_tab; // table of class methods String *s_attr_tab; // table of class attributes - String *s_cls_attr_tab; // table of class static attributes - String *s_cls_methods_tab; // table of class static methods - String *s_cls_const_tab; // tables of class constants(including enums) String *s_luacode; // luacode to be called during init - String *s_dot_get; // table of variable 'get' functions - String *s_dot_set; // table of variable 'set' functions - String *s_vars_meta_tab; // metatable for variables + String *module; //name of the module + //String *s_vars_meta_tab; // metatable for variables + Hash* namespaces_hash; int have_constructor; int have_destructor; String *destructor_action; - String *class_name; + String *class_symname; String *constructor_name; enum { @@ -151,26 +153,35 @@ public: f_runtime(0), f_header(0), f_wrappers(0), + f_wrappersForward(0), f_init(0), f_initbeforefunc(0), + /* s_cmd_tab(0), s_var_tab(0), s_const_tab(0), - s_methods_tab(0), - s_attr_tab(0), s_cls_attr_tab(0), s_cls_methods_tab(0), s_cls_const_tab(0), + */ + s_methods_tab(0), + s_attr_tab(0), s_luacode(0), - s_dot_get(0), - s_dot_set(0), - s_vars_meta_tab(0), + module(0), + //s_dot_get(0), + //s_dot_set(0), + //s_vars_meta_tab(0), have_constructor(0), have_destructor(0), destructor_action(0), - class_name(0), + class_symname(0), constructor_name(0), current(NO_CPP) { + namespaces_hash = NewHash(); + } + ~LUA() { + if(namespaces_hash) + Delete(namespaces_hash); } /* NEW LANGUAGE NOTE:*********************************************** @@ -246,7 +257,7 @@ public: virtual int top(Node *n) { /* Get the module name */ - String *module = Getattr(n, "name"); + module = Getattr(n, "name"); /* Get the output file name */ String *outfile = Getattr(n, "outfile"); @@ -260,6 +271,7 @@ public: f_runtime = NewString(""); f_init = NewString(""); f_header = NewString(""); + f_wrappersForward = NewString(""); f_wrappers = NewString(""); f_initbeforefunc = NewString(""); @@ -279,6 +291,8 @@ public: just before it is written to file NEW LANGUAGE NOTE:END ************************************************/ // Initialize some variables for the object interface + // TODO: Replace with call to getNamespaceHash(0) + /* s_cmd_tab = NewString(""); s_var_tab = NewString(""); // s_methods_tab = NewString(""); @@ -287,6 +301,7 @@ public: s_dot_get = NewString(""); s_dot_set = NewString(""); s_vars_meta_tab = NewString(""); + */ s_luacode = NewString(""); Swig_register_filebyname("luacode", s_luacode); @@ -323,28 +338,34 @@ public: Printf(f_header, "#define SWIG_init_user luaopen_%s_user\n\n", module); Printf(f_header, "#define SWIG_LUACODE luaopen_%s_luacode\n", module); + /* if (elua_ltr || eluac_ltr) Printf(f_header, "#define swig_commands %s_map\n\n", module); + */ if (elua_ltr || eluac_ltr) { - Printf(s_cmd_tab, "\n#define MIN_OPT_LEVEL 2\n#include \"lrodefs.h\"\n"); - Printf(s_cmd_tab, "#include \"lrotable.h\"\n"); - Printf(s_cmd_tab, "\nconst LUA_REG_TYPE swig_constants[];\n"); - if (elua_ltr) - Printf(s_cmd_tab, "const LUA_REG_TYPE mt[];\n"); + Printf(f_header, "\n#define MIN_OPT_LEVEL 2\n#include \"lrodefs.h\"\n"); + Printf(f_header, "#include \"lrotable.h\"\n"); + //Printf(s_cmd_tab, "\nconst LUA_REG_TYPE swig_constants[];\n"); + /*if (elua_ltr) + Printf(s_cmd_tab, "const LUA_REG_TYPE mt[];\n");*/ - Printf(s_cmd_tab, "\nconst LUA_REG_TYPE swig_commands[] = {\n"); - Printf(s_const_tab, "\nconst LUA_REG_TYPE swig_constants[] = {\n"); + //Printf(s_cmd_tab, "\nconst LUA_REG_TYPE swig_commands[] = {\n"); + //Printf(s_const_tab, "\nconst LUA_REG_TYPE swig_constants[] = {\n"); Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); - if (elua_ltr) { + Printf(f_wrappersForward, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); + /*if (elua_ltr) { Printf(s_dot_get, "\nconst LUA_REG_TYPE dot_get[] = {\n"); Printf(s_dot_set, "\nconst LUA_REG_TYPE dot_set[] = {\n"); - } + }*/ } else { + /* Printf(s_cmd_tab, "\nstatic const struct luaL_Reg swig_commands[] = {\n"); Printf(s_var_tab, "\nstatic swig_lua_var_info swig_variables[] = {\n"); Printf(s_const_tab, "\nstatic swig_lua_const_info swig_constants[] = {\n"); + */ Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); + Printf(f_wrappersForward, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); } /* %init code inclusion, effectively in the SWIG_init function */ @@ -354,8 +375,10 @@ public: Printf(f_init, "}\n"); Printf(f_wrappers, "#ifdef __cplusplus\n}\n#endif\n"); + Printf(f_wrappersForward, "#ifdef __cplusplus\n}\n#endif\n"); // Done. Close up the module & write to the wrappers +#if 0 if (elua_ltr || eluac_ltr) { Printv(s_cmd_tab, tab4, "{LSTRKEY(\"const\"), LROVAL(swig_constants)},\n", NIL); if (elua_ltr) @@ -367,7 +390,9 @@ public: Printv(s_var_tab, tab4, "{0,0,0}\n", "};\n", NIL); Printv(s_const_tab, tab4, "{0,0,0,0,0,0}\n", "};\n", NIL); } +#endif +#if 0 if (elua_ltr) { /* Generate the metatable */ Printf(s_vars_meta_tab, "\nconst LUA_REG_TYPE mt[] = {\n"); @@ -380,13 +405,16 @@ public: Printv(s_dot_get, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); Printv(s_dot_set, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); } +#endif if (elua_ltr || eluac_ltr) { /* Final close up of wrappers */ - Printv(f_wrappers, s_cmd_tab, s_dot_get, s_dot_set, s_vars_meta_tab, s_var_tab, s_const_tab, NIL); + //Printv(f_wrappers, s_cmd_tab, s_dot_get, s_dot_set, s_vars_meta_tab, s_var_tab, s_const_tab, NIL); + closeNamespaces(f_wrappers, f_wrappersForward); SwigType_emit_type_table(f_runtime, f_wrappers); } else { - Printv(f_wrappers, s_cmd_tab, s_var_tab, s_const_tab, NIL); + //Printv(f_wrappers, s_cmd_tab, s_var_tab, s_const_tab, NIL); + closeNamespaces(f_wrappers, f_wrappersForward); SwigType_emit_type_table(f_runtime, f_wrappers); } @@ -396,6 +424,7 @@ public: NEW LANGUAGE NOTE:END ************************************************/ Dump(f_runtime, f_begin); Dump(f_header, f_begin); + Dump(f_wrappersForward, f_begin); Dump(f_wrappers, f_begin); Dump(f_initbeforefunc, f_begin); /* for the Lua code it needs to be properly excaped to be added into the C/C++ code */ @@ -404,18 +433,19 @@ public: Wrapper_pretty_print(f_init, f_begin); /* Close all of the files */ Delete(s_luacode); - Delete(s_cmd_tab); - Delete(s_var_tab); - Delete(s_const_tab); + //Delete(s_cmd_tab); + //Delete(s_var_tab); + //Delete(s_const_tab); Delete(f_header); Delete(f_wrappers); + Delete(f_wrappersForward); Delete(f_init); Delete(f_initbeforefunc); Delete(f_runtime); Delete(f_begin); - Delete(s_dot_get); - Delete(s_dot_set); - Delete(s_vars_meta_tab); + //Delete(s_dot_get); + //Delete(s_dot_set); + //Delete(s_vars_meta_tab); /* Done */ return SWIG_OK; @@ -461,7 +491,7 @@ public: if (Getattr(n, "sym:overloaded")) { overname = Getattr(n, "sym:overname"); } else { - if (!addSymbol(iname, n)) { + if (!addSymbol(iname, n, getNSpace())) { Printf(stderr,"addSymbol(%s) failed\n",iname); return SWIG_ERROR; } @@ -479,6 +509,12 @@ public: if (overname) { Append(wname, overname); } + if (current == CONSTRUCTOR) { + if( constructor_name != 0) + Delete(constructor_name); + constructor_name = Copy(wname); + } + //Printf(stdout , "Function wrapper, name %s\n", wname); // TODO:REMOVE /* NEW LANGUAGE NOTE:*********************************************** the format of a lua fn is: @@ -656,7 +692,15 @@ public: } } + // Remember C name of the wrapping function Setattr(n, "wrap:name", wname); + // If it is getter/setter, then write wname under + // wrap:memberset/wrap:memberget accordingly + if( Getattr(n, "memberset") ) + Setattr(n, "memberset:wrap:name", wname); + if( Getattr(n, "memberget") ) + Setattr(n, "memberget:wrap:name", wname); + /* Emit the function call */ String *actioncode = emit_action(n); @@ -746,14 +790,15 @@ public: //REPORT("dispatchFunction", n); // add_method(n, iname, wname, description); if (current==NO_CPP || current==STATIC_FUNC) { // emit normal fns & static fns - String *wrapname = Swig_name_wrapper(iname); + Hash* nspaceHash = getNamespaceHash( getNSpace() ); + String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); if(elua_ltr || eluac_ltr) - Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", iname, "\")", ", LFUNCVAL(", Swig_name_wrapper(iname), ")", "},\n", NIL); + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", iname, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); else - Printv(s_cmd_tab, tab4, "{ \"", iname, "\", ", Swig_name_wrapper(iname), "},\n", NIL); + Printv(s_ns_methods_tab, tab4, "{ \"", iname, "\", ", wname, "},\n", NIL); // Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", Swig_name_wrapper(iname), "},\n", NIL); if (getCurrentClass()) { - Setattr(n,"luaclassobj:wrap:name", wrapname); + Setattr(n,"luaclassobj:wrap:name", wname); } } } else { @@ -832,13 +877,24 @@ public: Printv(f->code, "}\n", NIL); Wrapper_print(f, f_wrappers); //add_method(symname,wname,0); - if (current==NO_CPP || current==STATIC_FUNC) // emit normal fns & static fns - Printv(s_cmd_tab, tab4, "{ \"", symname, "\",", wname, "},\n", NIL); + if (current==NO_CPP || current==STATIC_FUNC) { // emit normal fns & static fns + Hash* nspaceHash = getNamespaceHash( getNSpace() ); + String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); + Printv(s_ns_methods_tab, tab4, "{ \"", symname, "\",", wname, "},\n", NIL); + } + if (current == CONSTRUCTOR) { + if( constructor_name != 0 ) + Delete(constructor_name); + constructor_name = Copy(wname); + } - if (getCurrentClass()) - Setattr(n,"luaclassobj:wrap:name", wname); - else - Delete(wname); + Setattr(n, "wrap:name", wname); + // If it is getter/setter, then write wname under + // wrap:memberset/wrap:memberget accordingly + if( Getattr(n, "memberset") ) + Setattr(n, "memberset:wrap:name", wname); + if( Getattr(n, "memberget") ) + Setattr(n, "memberget:wrap:name", wname); DelWrapper(f); Delete(dispatch); @@ -866,7 +922,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(NSPACE_TODO, iname)); + String *getName = Swig_name_wrapper(Swig_name_get(getNSpace(), iname)); String *setName = 0; // checking whether it can be set to or not appears to be a very error prone issue // I referred to the Language::variableWrapper() to find this out @@ -878,7 +934,7 @@ public: Delete(tm); if (assignable) { - setName = Swig_name_wrapper(Swig_name_set(NSPACE_TODO, iname)); + setName = Swig_name_wrapper(Swig_name_set(getNSpace(), iname)); } else { // how about calling a 'this is not settable' error message? setName = NewString("SWIG_Lua_set_immutable"); // error message @@ -886,14 +942,19 @@ public: } // register the variable + Hash* nspaceHash = getNamespaceHash( getNSpace() ); + String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); + String* s_ns_var_tab = Getattr(nspaceHash, "attributes"); if (elua_ltr) { - Printf(s_dot_get, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, iname, getName); - Printf(s_dot_set, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, iname, setName); + String* s_ns_dot_get = Getattr(nspaceHash, "get"); + String* s_ns_dot_set = Getattr(nspaceHash, "set"); + Printf(s_ns_dot_get, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, iname, getName); + Printf(s_ns_dot_set, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, iname, setName); } else if (eluac_ltr) { - Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", iname, "_get", "\")", ", LFUNCVAL(", getName, ")", "},\n", NIL); - Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", iname, "_set", "\")", ", LFUNCVAL(", setName, ")", "},\n", NIL); + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", iname, "_get", "\")", ", LFUNCVAL(", getName, ")", "},\n", NIL); + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", iname, "_set", "\")", ", LFUNCVAL(", setName, ")", "},\n", NIL); } else { - Printf(s_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, iname, getName, setName); + Printf(s_ns_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, iname, getName, setName); } if (getCurrentClass()) { Setattr(n, "luaclassobj:wrap:get", getName); @@ -918,7 +979,7 @@ public: String *value = rawval ? rawval : Getattr(n, "value"); String *tm; - if (!addSymbol(iname, n)) + if (!addSymbol(iname, n, getNSpace())) return SWIG_ERROR; /* Special hook for member pointer */ @@ -933,6 +994,8 @@ public: Replaceall(tm, "$target", name); Replaceall(tm, "$value", value); Replaceall(tm, "$nsname", nsname); + Hash *nspaceHash = getNamespaceHash( getNSpace() ); + String *s_const_tab = Getattr(nspaceHash, "constants"); Printf(s_const_tab, " %s,\n", tm); } else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) { Replaceall(tm, "$source", value); @@ -945,6 +1008,7 @@ public: Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); return SWIG_NOWRAP; } + /* TODO: Fix if (cparse_cplusplus && getCurrentClass()) { // Additionally add to class constants Swig_require("luaclassobj_constantWrapper", n, "*sym:name", "luaclassobj:symname", NIL); @@ -958,7 +1022,7 @@ public: Printf(s_cls_const_tab, " %s,\n", tm); } Swig_restore(n); - } + }*/ Delete(nsname); return SWIG_OK; } @@ -971,10 +1035,12 @@ public: // REPORT("nativeWrapper", n); String *symname = Getattr(n, "sym:name"); String *wrapname = Getattr(n, "wrap:name"); - if (!addSymbol(wrapname, n)) + if (!addSymbol(wrapname, n, getNSpace())) return SWIG_ERROR; - Printv(s_cmd_tab, tab4, "{ \"", symname, "\",", wrapname, "},\n", NIL); + Hash *nspaceHash = getNamespaceHash( getNSpace() ); + String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); + Printv(s_ns_methods_tab, tab4, "{ \"", symname, "\",", wrapname, "},\n", NIL); // return Language::nativeWrapper(n); // this does nothing... return SWIG_OK; } @@ -1010,20 +1076,28 @@ public: virtual int classHandler(Node *n) { //REPORT("classHandler", n); - String *mangled_classname = 0; - String *real_classname = 0; + String *mangled_full_class_symname = 0; + String *full_class_symname = 0; + String* nspace = getNSpace(); + String* destructor_name = 0; constructor_name = 0; have_constructor = 0; have_destructor = 0; destructor_action = 0; - class_name = Getattr(n, "sym:name"); - if (!addSymbol(class_name, n)) + class_symname = Getattr(n, "sym:name"); + if (!addSymbol(class_symname, n, nspace)) return SWIG_ERROR; - real_classname = Getattr(n, "name"); - mangled_classname = Swig_name_mangle(real_classname); + if (nspace == 0) + full_class_symname = NewStringf("%s", class_symname); + else + full_class_symname = NewStringf("%s.%s", nspace, class_symname); + + assert(full_class_symname != 0); + mangled_full_class_symname = Swig_name_mangle(full_class_symname); + Printf( stdout, "Mangled class symname %s\n", mangled_full_class_symname ); // not sure exactly how this works, // but tcl has a static hashtable of all classes emitted and then only emits code for them once. @@ -1033,50 +1107,88 @@ public: // * consider effect on template_specialization_defarg static Hash *emitted = NewHash(); - if (Getattr(emitted, mangled_classname)) + if (Getattr(emitted, mangled_full_class_symname)) return SWIG_NOWRAP; - Setattr(emitted, mangled_classname, "1"); + Setattr(emitted, mangled_full_class_symname, "1"); - s_attr_tab = NewString(""); - Printf(s_attr_tab, "static swig_lua_attribute swig_"); - Printv(s_attr_tab, mangled_classname, "_attributes[] = {\n", NIL); + // We treat class T as both 'class' and 'namespace'. All static members, attributes + // and constants are considered part of namespace T, all members - part of the 'class' + // Now, here is a trick. Static methods, attributes and non-static methods and attributes + // are described with same structures - swig_lua_attribute/swig_lua_method. Instead of calling + // getNamespaceHash(class name) to initialize things for static methods/attributes and then + // manually doing same initialization for non-static methods, we call getNamespaceHash 2 times: + // 1) With name "class name" + "." + "__Static" to initialize static things + // 2) With "class name" to initialize non-static things + // And we can guarantee that there will not be any name collision because names starting with 2 underscores + // and capital letter are forbiden to use in C++. So, under know circumstances could our class contain + // any member or subclass with name "__Static". Thus, never any name clash. + Hash* non_static_cls = getNamespaceHash(full_class_symname, false); + assert(non_static_cls != 0); + s_attr_tab = Getattr(non_static_cls, "attributes"); + s_methods_tab = Getattr(non_static_cls, "methods"); + String* s_attr_tab_name = Getattr(non_static_cls, "attributes:name"); + String* s_methods_tab_name = Getattr(non_static_cls, "methods:name"); + Setattr(non_static_cls, "lua:no_namespaces", "1"); + Setattr(non_static_cls, "lua:no_classes", "1"); - s_methods_tab = NewString(""); - Printf(s_methods_tab, "static swig_lua_method swig_"); - Printv(s_methods_tab, mangled_classname, "_methods[] = {\n", NIL); + /* There is no use for "constants", "classes" and "namespaces" arrays. + * All constants are considered part of static part of class. + */ - s_cls_methods_tab = NewString(""); - Printf(s_cls_methods_tab, "static swig_lua_method swig_"); - Printv(s_cls_methods_tab, mangled_classname, "_cls_methods[] = {\n", NIL); - - s_cls_attr_tab = NewString(""); - Printf(s_cls_attr_tab, "static swig_lua_attribute swig_"); - Printv(s_cls_attr_tab, mangled_classname, "_cls_attributes[] = {\n", NIL); - - s_cls_const_tab = NewString(""); - Printf(s_cls_const_tab, "static swig_lua_const_info swig_"); - Printv(s_cls_const_tab, mangled_classname, "_cls_constants[] = {\n", NIL); + String *static_cls_key = NewStringf("%s%s__Static", full_class_symname, NSPACE_SEPARATOR); + Hash *static_cls = getNamespaceHash(static_cls_key, false); + if (static_cls == 0) { + return SWIG_ERROR; // This cant be, so it is internal, implementation error + } + Setattr(static_cls, "lua:no_namespaces", "1"); + /* TODO: REMOVE + s_cls_methods_tab = Getattr(static_cls, "methods"); + s_cls_attr_tab = Getattr(static_cls, "attributes"); + s_cls_const_tab = Getattr(static_cls, "constants"); + */ + /* There is no use for "classes" and "namespaces" arrays. Subclasses are not supported + * by SWIG and namespaces couldn't be nested inside classes (C++ Standard) + */ + assert(s_attr_tab != 0); + assert(s_methods_tab != 0); + /* + assert(s_cls_methods_tab != 0); + assert(s_cls_attr_tab != 0); + assert(s_cls_const_tab != 0); + */ + // Replacing namespace with namespace + class in order to static + // member be put inside class static area + setNSpace(static_cls_key); // Generate normal wrappers Language::classHandler(n); + // Restore correct nspace + setNSpace(nspace); SwigType *t = Copy(Getattr(n, "name")); SwigType_add_pointer(t); // Catch all: eg. a class with only static functions and/or variables will not have 'remembered' - String *wrap_class = NewStringf("&_wrap_class_%s", mangled_classname); + String *wrap_class = NewStringf("&_wrap_class_%s", mangled_full_class_symname); SwigType_remember_clientdata(t, wrap_class); String *rt = Copy(getClassType()); SwigType_add_pointer(rt); + // Adding class to apropriate namespace + Hash *nspaceHash = getNamespaceHash(nspace); + String *ns_classes = Getattr(nspaceHash, "classes"); + Printv( ns_classes, wrap_class, ",\n", NIL ); + // Register the class structure with the type checker - // Printf(f_init,"SWIG_TypeClientData(SWIGTYPE%s, (void *) &_wrap_class_%s);\n", SwigType_manglestr(t), mangled_classname); + // Printf(f_init,"SWIG_TypeClientData(SWIGTYPE%s, (void *) &_wrap_class_%s);\n", SwigType_manglestr(t), mangled_full_class_symname); // emit a function to be called to delete the object + // TODO: class_name -> full_class_name || mangled full_class_name if (have_destructor) { - Printv(f_wrappers, "static void swig_delete_", class_name, "(void *obj) {\n", NIL); + destructor_name = NewStringf("swig_delete_%s", mangled_full_class_symname); + Printv(f_wrappers, "static void ", destructor_name, "(void *obj) {\n", NIL); if (destructor_action) { Printv(f_wrappers, SwigType_str(rt, "arg1"), " = (", SwigType_str(rt, 0), ") obj;\n", NIL); Printv(f_wrappers, destructor_action, "\n", NIL); @@ -1090,27 +1202,17 @@ public: Printf(f_wrappers, "}\n"); } - Printf(s_methods_tab, " {0,0}\n};\n"); - Printv(f_wrappers, s_methods_tab, NIL); - - Printf(s_attr_tab, " {0,0,0}\n};\n"); - Printv(f_wrappers, s_attr_tab, NIL); - - Printf(s_cls_attr_tab, " {0,0,0}\n};\n"); - Printv(f_wrappers, s_cls_attr_tab, NIL); - - Printf(s_cls_methods_tab, " {0,0}\n};\n"); - Printv(f_wrappers, s_cls_methods_tab, NIL); - - Printf(s_cls_const_tab, " {0,0,0,0,0,0}\n};\n"); - Printv(f_wrappers, s_cls_const_tab, NIL); + closeNamespaceHash(full_class_symname, f_wrappers); + closeNamespaceHash(static_cls_key, f_wrappers); + /* TODO: REMOVE Delete(s_methods_tab); Delete(s_attr_tab); Delete(s_cls_methods_tab); Delete(s_cls_attr_tab); Delete(s_cls_const_tab); + */ // Handle inheritance // note: with the idea of class hierarchies spread over multiple modules @@ -1135,7 +1237,7 @@ public: b = Next(b); continue; } - // old code: (used the pointer to the base class) + // old code: (used the pointer to the base class) TODO:REMOVE //String *bmangle = Swig_name_mangle(bname); //Printf(base_class, "&_wrap_class_%s", bmangle); //Putc(',', base_class); @@ -1149,24 +1251,30 @@ public: } } - Printv(f_wrappers, "static swig_lua_class *swig_", mangled_classname, "_bases[] = {", base_class, "0};\n", NIL); + Printv(f_wrappers, "static swig_lua_class *swig_", mangled_full_class_symname, "_bases[] = {", base_class, "0};\n", NIL); Delete(base_class); - Printv(f_wrappers, "static const char *swig_", mangled_classname, "_base_names[] = {", base_class_names, "0};\n", NIL); + Printv(f_wrappers, "static const char *swig_", mangled_full_class_symname, "_base_names[] = {", base_class_names, "0};\n", NIL); Delete(base_class_names); - Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_classname, " = { \"", class_name, "\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); + Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_full_class_symname, " = { \"", class_symname, "\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); + // TODO: Replace with constructor_name if (have_constructor) { if (elua_ltr) { - Printf(s_cmd_tab, " {LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", class_name, \ - Swig_name_wrapper(Swig_name_construct(NSPACE_TODO, constructor_name))); - Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(NSPACE_TODO, constructor_name))); + String* ns_methods_tab = Getattr(nspaceHash, "methods"); + // TODO: Contructor should be moved to __call method of static part of class + Printf(ns_methods_tab, " {LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", class_symname, \ + Swig_name_wrapper(Swig_name_construct(nspace, constructor_name))); + Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(nspace, constructor_name))); } else if (eluac_ltr) { - Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", "new_", class_name, "\")", ", LFUNCVAL(", \ - Swig_name_wrapper(Swig_name_construct(NSPACE_TODO, constructor_name)), ")", "},\n", NIL); - Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(NSPACE_TODO, constructor_name))); + String* ns_methods_tab = Getattr(nspaceHash, "methods"); + Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "new_", class_symname, "\")", ", LFUNCVAL(", \ + Swig_name_wrapper(Swig_name_construct(nspace, constructor_name)), ")", "},\n", NIL); + Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(nspace, constructor_name))); } else { - Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(NSPACE_TODO, constructor_name))); + //Printf( stdout, "Constructor.name %s declaration: %s\n", constructor_name, Swig_name_wrapper(Swig_name_construct(nspace, constructor_name))); + //Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(nspace, constructor_name))); + Printv(f_wrappers, constructor_name, NIL); } Delete(constructor_name); constructor_name = 0; @@ -1176,23 +1284,26 @@ public: if (have_destructor) { if (eluac_ltr) { - Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", "free_", class_name, "\")", ", LFUNCVAL(", "swig_delete_", class_name, ")", "},\n", NIL); - Printv(f_wrappers, ", swig_delete_", class_name, NIL); + String* ns_methods_tab = Getattr(nspaceHash, "methods"); + Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_full_class_symname, "\")", ", LFUNCVAL(", destructor_name, ")", "},\n", NIL); + Printv(f_wrappers, ", ", destructor_name, NIL); } else { - Printv(f_wrappers, ", swig_delete_", class_name, NIL); + Printv(f_wrappers, ", ", destructor_name, NIL); } } else { Printf(f_wrappers, ",0"); } - Printf(f_wrappers, ", swig_%s_methods, swig_%s_attributes, { \"%s\", swig_%s_cls_methods, swig_%s_cls_attributes, swig_%s_cls_constants }, swig_%s_bases, swig_%s_base_names };\n\n", - mangled_classname, mangled_classname, - class_name, mangled_classname, mangled_classname, mangled_classname, - mangled_classname, mangled_classname); + Printf(f_wrappers, ", %s, %s, ", s_methods_tab_name, s_attr_tab_name ); + // TODO: Replace class_symname with class_name + printNamespaceDefinition(static_cls_key, class_symname, f_wrappers); + Printf(f_wrappers, ", swig_%s_bases, swig_%s_base_names };\n\n", + mangled_full_class_symname, mangled_full_class_symname); - // Printv(f_wrappers, ", swig_", mangled_classname, "_methods, swig_", mangled_classname, "_attributes, swig_", mangled_classname, "_bases };\n\n", NIL); - // Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, &_wrap_class_", mangled_classname, "},\n", NIL); + // Printv(f_wrappers, ", swig_", mangled_full_class_symname, "_methods, swig_", mangled_full_class_symname, "_attributes, swig_", mangled_full_class_symname, "_bases };\n\n", NIL); + // Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, &_wrap_class_", mangled_full_class_symname, "},\n", NIL); Delete(t); - Delete(mangled_classname); + Delete(mangled_full_class_symname); + Delete(static_cls_key); return SWIG_OK; } @@ -1221,7 +1332,8 @@ public: current = NO_CPP; realname = iname ? iname : name; - rname = Swig_name_wrapper(Swig_name_member(NSPACE_TODO, class_name, realname)); + rname = Getattr(n, "wrap:name"); + assert(rname != 0); if (!Getattr(n, "sym:nextSibling")) { Printv(s_methods_tab, tab4, "{\"", realname, "\", ", rname, "}, \n", NIL); } @@ -1236,27 +1348,29 @@ public: virtual int membervariableHandler(Node *n) { // REPORT("membervariableHandler",n); String *symname = Getattr(n, "sym:name"); - String *gname, *sname; + String *getter_name, *setter_name; current = MEMBER_VAR; Language::membervariableHandler(n); current = NO_CPP; - gname = Swig_name_wrapper(Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname))); + getter_name = Getattr(n, "memberget:wrap:name"); + assert(getter_name != 0); if (!GetFlag(n, "feature:immutable")) { - sname = Swig_name_wrapper(Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname))); + setter_name = Getattr(n, "memberset:wrap:name"); + assert(setter_name != 0); } else { - //sname = NewString("0"); - sname = NewString("SWIG_Lua_set_immutable"); // error message + //setter_name = NewString("0"); + setter_name = NewString("SWIG_Lua_set_immutable"); // error message } - Printf(s_attr_tab,"%s{ \"%s\", %s, %s},\n",tab4,symname,gname,sname); - if (eluac_ltr) { + Printf(s_attr_tab,"%s{ \"%s\", %s, %s},\n",tab4,symname,getter_name,setter_name); + /*if (eluac_ltr) { TODO: FIX for eluac and uncomments Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", class_name, "_", symname, "_get", "\")", \ - ", LFUNCVAL(", gname, ")", "},\n", NIL); + ", LFUNCVAL(", getter_name, ")", "},\n", NIL); Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", class_name, "_", symname, "_set", "\")", \ - ", LFUNCVAL(", sname, ")", "},\n", NIL); - } - Delete(gname); - Delete(sname); + ", LFUNCVAL(", setter_name, ")", "},\n", NIL); + }*/ + Delete(getter_name); + Delete(setter_name); return SWIG_OK; } @@ -1271,8 +1385,9 @@ public: current = CONSTRUCTOR; Language::constructorHandler(n); current = NO_CPP; - constructor_name = NewString(Getattr(n, "sym:name")); + //constructor_name = NewString(Getattr(n, "sym:name")); have_constructor = 1; + //Printf( stdout, "Constructor %s\n", constructor_name); TODO: REMOVE return SWIG_OK; } @@ -1299,7 +1414,7 @@ public: virtual int staticmemberfunctionHandler(Node *n) { REPORT("staticmemberfunctionHandler", n); current = STATIC_FUNC; - String *symname = Getattr(n, "sym:name"); + //String *symname = Getattr(n, "sym:name"); int result = Language::staticmemberfunctionHandler(n); if (cparse_cplusplus && getCurrentClass()) { @@ -1313,11 +1428,12 @@ public: return SWIG_OK; Swig_require("luaclassobj_staticmemberfunctionHandler", n, "luaclassobj:wrap:name", NIL); - String *name = Getattr(n, "name"); - String *rname, *realname; - realname = symname ? symname : name; - rname = Getattr(n, "luaclassobj:wrap:name"); - Printv(s_cls_methods_tab, tab4, "{\"", realname, "\", ", rname, "}, \n", NIL); + //String *name = Getattr(n, "name"); + //String *rname, *realname; + //realname = symname ? symname : name; + //rname = Getattr(n, "luaclassobj:wrap:name"); + // TODO: Add backward compatibility here: add "ClassName_FuncName" to global table + //Printv(s_cls_methods_tab, tab4, "{\"", realname, "\", ", rname, "}, \n", NIL); Swig_restore(n); return SWIG_OK; @@ -1350,7 +1466,7 @@ public: virtual int staticmembervariableHandler(Node *n) { REPORT("staticmembervariableHandler",n); current = STATIC_VAR; - String *symname = Getattr(n, "sym:name"); + //String *symname = Getattr(n, "sym:name"); int result = Language::staticmembervariableHandler(n); if (result != SWIG_OK) @@ -1360,12 +1476,35 @@ public: if (Getattr(n, "wrappedasconstant")) return SWIG_OK; + /* TODO: Add backward compatibility here: add "ClassName_AttributeName" to class scope Swig_require("luaclassobj_staticmembervariableHandler", n, "luaclassobj:wrap:get", "luaclassobj:wrap:set", NIL); Printf(s_cls_attr_tab,"%s{ \"%s\", %s, %s},\n",tab4,symname,Getattr(n,"luaclassobj:wrap:get"), Getattr(n,"luaclassobj:wrap:set")); Swig_restore(n); + */ return SWIG_OK; } + /* TODO: REMOVE + virtual int namespaceDeclaration(Node *n) { + // Register namespace + String* name = Getattr(n, "sym:name"); + Hash* parent = getNamespaceHash( getNSpace() ); + String *parent_namespaces_tab = Getattr(parent, "namespaces"); + String *mangled_name = Swig_name_mangle(name); + String *full_name = NewString(""); + if (getNSpace() == 0) + Printv(full_name, name); + else + Printv(full_name, getNSpace(), NSPACE_SEPARATOR, name); + Hash *nspace = getNamespaceHash(full_name); + Setattr(nspace, "name", Copy(name)); + Printv(parent_namespaces_tab, mangled_name, ",\n", NIL); + Printf(stdout, "NamespaceDeclaration %s, Parent %s, FQN %s\n", name, getNSpace(), full_name); + Delete(mangled_name); + Delete(full_name); + return Language::namespaceDeclaration(n); + } + */ /* --------------------------------------------------------------------- * external runtime generation * --------------------------------------------------------------------- */ @@ -1428,6 +1567,307 @@ public: Replace(str,"\n","\\n\"\n \"",DOH_REPLACE_ANY); // \n to \n"\n" (ie quoting every line) //Printf(f_runtime,"/* hacked luacode:[[[\n%s\n]]]\n*/\n",str); } + + /* Each namespace can be described with hash that stores C arrays + where members of the namespace should be added. All these hashes are stored + inside namespaces_hash. + nspace could be NULL (NSPACE_TODO), that means functions and variables and classes + that are not in any namespace (this is default for SWIG unless %nspace feature is used) + You can later set some attributes that will affect behaviour of functions that use this hash: + "lua:no_namespaces" will disable "namespaces" array. + "lua:no_classes" will disable "classes" array. + For every component ("attributes", "methods", etc) there are subcomponents: + * XXX:name - name of the C array that stores data for component + * XXX:decl - statement with forward declaration of this array; + */ + Hash* getNamespaceHash(String *nspace, bool reg = true) + { + //Printf( stdout, "Request for %s. register: %d\n", nspace?nspace:"", int(reg)); + Hash* nspace_hash = Getattr(namespaces_hash, nspace?nspace:"" ); + if (nspace_hash != 0) + return nspace_hash; + nspace_hash = NewHash(); + String* mangled_name = 0; + if (nspace == 0 || Len(nspace) == 0) + mangled_name = NewString("__Global"); // C++ names can't start with "__ + capital letter" + else + mangled_name = Swig_name_mangle(nspace); + String* cname = NewStringf("swig_%s", mangled_name); + + if (reg && nspace != 0 && Len(nspace) != 0 && Getattr(nspace_hash, "lua:no_reg") == 0) { + // Split names into components + List* components = Split(nspace, '.', -1); + String *parent_path = NewString(""); + int len = Len(components); + String* name = Copy(Getitem(components, len-1)); + for( int i = 0; i < len-1; i++ ) { + if (i > 0) + Printv(parent_path, NSPACE_SEPARATOR, NIL); + String* item = Getitem(components, i); + Printv(parent_path, item, NIL); + } + Printf(stdout, "Registering %s. User name %s. C-name %s, Parent is %s\n", mangled_name, name, cname, parent_path); + Hash* parent = getNamespaceHash(parent_path, true); + String* namespaces_tab = Getattr(parent, "namespaces"); + Printv(namespaces_tab, "&", cname, ",\n", NIL); + Setattr(nspace_hash, "name", name); + + Delete(components); + Delete(parent_path); + } else if (!reg) // This namespace shouldn't be registered. Lets remember it + Setattr(nspace_hash, "lua:no_reg", "1"); + + + Setattr(nspace_hash, "cname", cname); + + String *attr_tab = NewString(""); + String *attr_tab_name = NewStringf("swig_%s_attributes", mangled_name ); + String *attr_tab_decl = NewString(""); + Printv(attr_tab, "static swig_lua_attribute ", NIL); + Printv(attr_tab, attr_tab_name, "[]", NIL); + Printv(attr_tab_decl, attr_tab, ";\n", NIL); + Printv(attr_tab, " = {\n", NIL); + Setattr(nspace_hash, "attributes", attr_tab); + Setattr(nspace_hash, "attributes:name", attr_tab_name); + Setattr(nspace_hash, "attributes:decl", attr_tab_decl); + + String *methods_tab = NewString(""); + String *methods_tab_name = NewStringf("swig_%s_methods", mangled_name ); + String *methods_tab_decl = NewString(""); + if (elua_ltr || eluac_ltr) // In this case methods array also acts as namespace rotable + Printf(methods_tab, "static LUA_REG_TYPE "); + else + Printf(methods_tab, "static swig_lua_method "); + Printv(methods_tab, methods_tab_name, "[]"); + Printv(methods_tab_decl, methods_tab, ";\n", NIL); + Printv(methods_tab, "= {\n", NIL); + Setattr(nspace_hash, "methods", methods_tab ); + Setattr(nspace_hash, "methods:name", methods_tab_name ); + Setattr(nspace_hash, "methods:decl", methods_tab_decl ); + + String *const_tab = NewString(""); + String *const_tab_name = NewStringf("swig_%s_constants", mangled_name ); + String *const_tab_decl = NewString(""); + if (elua_ltr || eluac_ltr) // In this case const array holds rotable with namespace constants + Printf(const_tab, "static LUA_REG_TYPE "); + else + Printf(const_tab, "static swig_lua_const_info "); + Printv(const_tab, const_tab_name, "[]", NIL); + Printv(const_tab_decl, const_tab, ";", NIL); + Printv(const_tab, "= {\n", NIL); + Setattr(nspace_hash, "constants", const_tab ); + Setattr(nspace_hash, "constants:name", const_tab_name ); + Setattr(nspace_hash, "constants:decl", const_tab_decl ); + + String *classes_tab = NewString(""); + String *classes_tab_name = NewStringf("swig_%s_classes", mangled_name ); + String *classes_tab_decl = NewString(""); + Printf(classes_tab, "static swig_lua_class* "); + Printv(classes_tab, classes_tab_name, "[]"); + Printv(classes_tab_decl, classes_tab, ";", NIL); + Printv(classes_tab, "= {\n", NIL); + Setattr(nspace_hash, "classes", classes_tab ); + Setattr(nspace_hash, "classes:name", classes_tab_name ); + Setattr(nspace_hash, "classes:decl", classes_tab_decl ); + + String* namespaces_tab = NewString(""); + String* namespaces_tab_name = NewStringf("swig_%s_namespaces", mangled_name ); + String* namespaces_tab_decl = NewString(""); + Printf(namespaces_tab, "static swig_lua_namespace* "); + Printv(namespaces_tab, namespaces_tab_name, "[]"); + Printv(namespaces_tab_decl, namespaces_tab, ";", NIL); + Printv(namespaces_tab, " = {\n", NIL); + Setattr(nspace_hash, "namespaces", namespaces_tab ); + Setattr(nspace_hash, "namespaces:name", namespaces_tab_name ); + Setattr(nspace_hash, "namespaces:decl", namespaces_tab_decl ); + + if (elua_ltr) { + // TODO: add xxx:decl here too + String *get_tab = NewString(""); + String *get_tab_name = NewStringf("swig_%s_get", mangled_name); + Printv(get_tab, "const LUA_REG_TYPE ", get_tab_name, "[] = {\n", NIL); + Setattr(nspace_hash, "get", get_tab); + Setattr(nspace_hash, "get:name", get_tab_name); + + String *set_tab = NewString(""); + String *set_tab_name = NewStringf("swig_%s_set", mangled_name); + Printv(set_tab, "const LUA_REG_TYPE ", set_tab_name, "[] = {\n", NIL); + Setattr(nspace_hash, "set", set_tab); + Setattr(nspace_hash, "set:name", set_tab_name); + + if (!eluac_ltr) { + String* metatable_tab = NewString(""); + String* metatable_tab_name = NewStringf("swig_%s_meta", mangled_name); + Printv(metatable_tab, "const LUA_REG_TYPE ", metatable_tab_name, "[] = {\n"); + Setattr(nspace_hash, "metatable", metatable_tab); + Setattr(nspace_hash, "metatable:name", metatable_tab_name); + } + } + String* key = 0; + if (nspace != 0) + key = Copy(nspace); + Setattr(namespaces_hash, key?key:"", nspace_hash); + + Delete(mangled_name); + return nspace_hash; + } + + /* Functions add end markers {0,0,...,0} to all arrays, prints them to + * output and marks hash as closed (lua:closed). Consequent attempts to + * close same hash will result in error + * closeNamespaceHash DOES NOT print structure that describes namespace, it only + * prints array. You can use printNamespaceDefinition to print structure. + * if "lua:no_namespaces" is set, then array for "namespaces" won't be printed + * if "lua:no_classes" is set, then array for "classes" won't be printed + * */ + void closeNamespaceHash(String *nspace, File *output) + { + Hash* nspace_hash = Getattr(namespaces_hash, nspace ); + assert(nspace_hash != 0); + assert(Getattr(nspace_hash, "lua:closed") == 0); + + Setattr(nspace_hash, "lua:closed", "1"); + + String* attr_tab = Getattr(nspace_hash, "attributes"); + Printf(attr_tab, " {0,0,0}\n};\n"); + Printv(output, attr_tab, NIL); + + String* const_tab = Getattr(nspace_hash, "constants"); + String* const_tab_name = Getattr(nspace_hash, "constants:name"); + if (elua_ltr || eluac_ltr) + Printv(const_tab, tab4, "{LNILKEY, LNILVAL}\n", "};\n", NIL); + else + Printf(const_tab, " {0,0,0,0,0,0}\n};\n"); + Printv(output, const_tab, NIL); + + String* methods_tab = Getattr(nspace_hash, "methods"); + String* metatable_tab_name = Getattr(nspace_hash, "metatable:name"); + if (elua_ltr || eluac_ltr) { + Printv(methods_tab, tab4, "{LSTRKEY(\"const\"), LROVAL(", const_tab_name, ")},\n", NIL); + if (elua_ltr) + Printv(methods_tab, tab4, "{LSTRKEY(\"__metatable\"), LROVAL(", metatable_tab_name, ")},\n", NIL); + } else + Printf(methods_tab, " {0,0}\n};\n"); + Printv(output, methods_tab, NIL); + + if (!Getattr(nspace_hash, "lua:no_classes") ) { + String* classes_tab = Getattr(nspace_hash, "classes"); + Printf(classes_tab, " 0\n};\n"); + Printv(output, classes_tab, NIL); + } + + if (!Getattr(nspace_hash, "lua:no_namespaces") ) { + String* namespaces_tab = Getattr(nspace_hash, "namespaces"); + Printf(namespaces_tab, " 0\n};\n"); + Printv(output, namespaces_tab, NIL); + } + if (elua_ltr) { + String *get_tab = Getattr(nspace_hash, "get"); + String *get_tab_name = Getattr(nspace_hash, "get:name"); + String *set_tab = Getattr(nspace_hash, "set"); + String *set_tab_name = Getattr(nspace_hash, "set:name"); + Printv(get_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); + Printv(set_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); + Printv(output, get_tab, NIL); + Printv(output, set_tab, NIL); + + String *metatable_tab = Getattr(nspace_hash, "metatable"); + assert(metatable_tab != 0); + Printv(metatable_tab, tab4, "{LSTRKEY(\"__index\"), LFUNCVAL(SWIG_Lua_module_get)},\n", NIL); + Printv(metatable_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_module_set)},\n", NIL); + Printv(metatable_tab, tab4, "{LSTRKEY(\".get\"), LROVAL(", get_tab_name, ")},\n", NIL); + Printv(metatable_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(", set_tab_name, ")},\n", NIL); + Printv(metatable_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); + Printv(output, metatable_tab, NIL); + } + Printv(output, "\n", NIL); + } + + static int compareByLen( const DOH* f, const DOH* s) { return Len(s) - Len(f); } + // Recursively close all non-closed namespaces. Prints data to dataOutput, + // forward declaration to declOutput + void closeNamespaces(File *dataOutput, File *declOutput) + { + Iterator ki = First(namespaces_hash); + List* to_close = NewList(); + while (ki.key) { + if (Getattr(ki.item, "lua:closed") == 0) + Append(to_close, ki.key); + ki = Next(ki); + } + SortList(to_close, &compareByLen); + int len = Len(to_close); + for( int i = 0; i < len; i++ ) { + String* key = Getitem(to_close,i); + closeNamespaceHash(key, dataOutput); + Hash* nspace = Getattr(namespaces_hash, key); + String* cname = Getattr(nspace, "cname"); // cname - name of the C structure that describes namespace + assert(cname != 0); + Printf( stdout, "Closing namespace %s\n", cname ); + //printNamespaceForwardDeclaration( ki.key, declOutput ); TODO: REMOVE + Printv(dataOutput, "static swig_lua_namespace ", cname, " = ", NIL); + String *name = 0; // name - name of the namespace as it should be visible in Lua + if (DohLen(key) == 0) // This is global module + name = module; + else + name = Getattr(nspace, "name"); + assert(name != 0); + printNamespaceDefinition( key, name, dataOutput ); + Printv(dataOutput, ";\n\n", NIL); + } + Delete(to_close); + } + + // This function prints to output a definition of namespace in + // form of swig_lua_namespace: { attr_array, methods_array, ... , namespaces_array }. + // You can call this function as many times as necessary. + // 'name' is a user-visible name that this namespace will have in Lua. It shouldn't + // be fully qualified name, just it's own name. + void printNamespaceDefinition(String *nspace, String* name, File *output) + { + // TODO: Fix for get_tab/set_tab things (elua_ltr) + Hash *nspace_hash = getNamespaceHash(nspace, false); + String *null_string = NewString("0"); + String *attr_tab_name = Getattr(nspace_hash, "attributes:name"); + String *methods_tab_name = Getattr(nspace_hash, "methods:name"); + String *const_tab_name = Getattr(nspace_hash, "constants:name"); + String *classes_tab_name = Getattr(nspace_hash, "classes:name"); + String *namespaces_tab_name = Getattr(nspace_hash, "namespaces:name"); + bool has_classes = Getattr(nspace_hash, "lua:no_classes") == 0; + bool has_namespaces = Getattr(nspace_hash, "lua:no_namespaces") == 0; + + Printf(output, "{\"%s\", %s, %s, %s, %s, %s}", + name, + methods_tab_name, + attr_tab_name, + const_tab_name, + (has_classes)?classes_tab_name:null_string, + (has_namespaces)?namespaces_tab_name:null_string + ); + } + + // This function prints forward declaration of namespace itself and all its arrays + // TODO: REMOVE + void printNamespaceForwardDeclaration(String* nspace, File* output) + { + Hash *nspace_hash = getNamespaceHash(nspace, false); + String *attr_tab_decl = Getattr(nspace_hash, "attributes:decl"); + String *methods_tab_decl = Getattr(nspace_hash, "methods:decl"); + String *const_tab_decl = Getattr(nspace_hash, "constants:decl"); + String *classes_tab_decl = Getattr(nspace_hash, "classes:decl"); + String *namespaces_tab_decl = Getattr(nspace_hash, "declspaces:decl"); + bool has_classes = Getattr(nspace_hash, "lua:no_classes") == 0; + bool has_namespaces = Getattr(nspace_hash, "lua:no_namespaces") == 0; + Printv( output, attr_tab_decl, "\n", NIL ); + Printv( output, methods_tab_decl, "\n", NIL ); + Printv( output, const_tab_decl, "\n", NIL ); + if( has_classes ) + Printv( output, classes_tab_decl, "\n", NIL ); + if( has_namespaces ) + Printv( output, namespaces_tab_decl, "\n", NIL ); + + Printf( output, "static swig_lua_namespace %s;\n", Getattr(nspace_hash, "cname") ); + } }; /* NEW LANGUAGE NOTE:*********************************************** diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 2929993b3..09fc37c87 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -278,6 +278,7 @@ protected: /* Return the namespace for the class/enum - the nspace feature */ String *getNSpace() const; + void setNSpace(String *nspace); /* Return the real name of the current class */ String *getClassName() const; From 295788c8a0002fe228d2e884cb370a525fb66a38 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Tue, 29 Oct 2013 21:14:34 +0400 Subject: [PATCH 0969/1160] nspace.i example is working --- Lib/lua/luarun.swg | 297 +++++++++++++++++++++++++++++-------- Source/Modules/lang.cxx | 10 +- Source/Modules/lua.cxx | 317 ++++++++++++++++++++++++++++------------ 3 files changed, 468 insertions(+), 156 deletions(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 04d18fdb7..ec33ea601 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -157,7 +157,8 @@ struct swig_lua_namespace { }; struct swig_lua_class { - const char *name; + const char *name; // Name that this class has in Lua + const char *fqname; // Fully qualified name - Scope + class name swig_type_info **type; lua_CFunction constructor; void (*destructor)(void *); @@ -511,7 +512,7 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss); SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* ns) { int i = 0; - /* There must be table at the top of the stack */ + /* There must be namespace table (not metatable) at the top of the stack */ assert(lua_istable(L,-1)); SWIG_Lua_InstallConstants(L, ns->ns_constants); @@ -539,10 +540,13 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* */ SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State* L, swig_lua_namespace* ns) { + // There must be module/namespace table at the top of the stack + assert(lua_istable(L,-1)); + swig_lua_class** classes = ns->ns_classes; if( classes != 0 ) { - while((*classes)->name != 0) { + while(*classes != 0) { SWIG_Lua_class_register(L, *classes); classes++; } @@ -556,6 +560,7 @@ SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State* L, swig_lua_namespace* */ SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns, bool reg) { + int begin = lua_gettop(L); assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table or parent namespace table */ lua_checkstack(L,5); lua_newtable(L); /* namespace itself */ @@ -582,11 +587,14 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns, // Register all functions, variables etc SWIG_Lua_add_namespace_details(L,ns); + // Register classes + SWIG_Lua_add_namespace_classes(L,ns); swig_lua_namespace** sub_namespace = ns->ns_namespaces; if( sub_namespace != 0) { - while((*sub_namespace)->name != 0) { + while(*sub_namespace != 0) { SWIG_Lua_namespace_register(L, *sub_namespace, true); + lua_pop(L,1); // removing sub-namespace table sub_namespace++; } } @@ -596,39 +604,45 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns, lua_pushvalue(L,-2); lua_rawset(L,-4); /* add namespace to module table */ } + assert(lua_gettop(L) == begin+1); } /* ----------------------------------------------------------------------------- * global variable support code: classes * ----------------------------------------------------------------------------- */ -/* the class.get method, performs the lookup of class attributes */ +/* the class.get method, performs the lookup of class attributes + * Method can be called from Lua directly and recursively from itself. Thats why + * we can't use absolute stack positions + */ SWIGINTERN int SWIG_Lua_class_get(lua_State* L) { /* there should be 2 params passed in (1) userdata (not the meta table) (2) string name of the attribute */ + int base = lua_gettop(L)-2; + lua_checkstack(L,5); assert(lua_isuserdata(L,-2)); /* just in case */ lua_getmetatable(L,-2); /* get the meta table */ assert(lua_istable(L,-1)); /* just in case */ SWIG_Lua_get_table(L,".get"); /* find the .get table */ assert(lua_istable(L,-1)); /* just in case */ /* look for the key in the .get table */ - lua_pushvalue(L,2); /* key */ + lua_pushvalue(L,base+2); /* key */ lua_rawget(L,-2); lua_remove(L,-2); /* stack tidy, remove .get table */ if (lua_iscfunction(L,-1)) { /* found it so call the fn & return its value */ - lua_pushvalue(L,1); /* the userdata */ + lua_pushvalue(L,base+1); /* the userdata */ lua_call(L,1,1); /* 1 value in (userdata),1 out (result) */ lua_remove(L,-2); /* stack tidy, remove metatable */ return 1; } lua_pop(L,1); /* remove whatever was there */ /* ok, so try the .fn table */ - SWIG_Lua_get_table(L,".fn"); /* find the .get table */ + SWIG_Lua_get_table(L,".fn"); /* find the .fn table */ assert(lua_istable(L,-1)); /* just in case */ - lua_pushvalue(L,2); /* key */ + lua_pushvalue(L,base+2); /* key */ lua_rawget(L,-2); /* look for the fn */ lua_remove(L,-2); /* stack tidy, remove .fn table */ if (lua_isfunction(L,-1)) /* note: if its a C function or lua function */ @@ -642,60 +656,197 @@ SWIGINTERN int SWIG_Lua_class_get(lua_State* L) SWIG_Lua_get_table(L,"__getitem"); /* find the __getitem fn */ if (lua_iscfunction(L,-1)) /* if its there */ { /* found it so call the fn & return its value */ - lua_pushvalue(L,1); /* the userdata */ - lua_pushvalue(L,2); /* the parameter */ + lua_pushvalue(L,base+1); /* the userdata */ + lua_pushvalue(L,base+2); /* the parameter */ lua_call(L,2,1); /* 2 value in (userdata),1 out (result) */ lua_remove(L,-2); /* stack tidy, remove metatable */ return 1; } + lua_pop(L,1); + // Search in base classes + // TODO: Different for elua_ltr + SWIG_Lua_get_table(L,".bases"); + assert(lua_istable(L,-1)); + int bases_count = lua_rawlen(L,-1); + if(bases_count>0) + { + int original_metatable = lua_absindex(L,-2); + int i; + int ret = 0; // Number of returned values + lua_pushvalue(L,base+1); // push userdata + lua_pushvalue(L,base+2); // Push key again + // Trick: temporaly replacing original metatable + // with metatable for base class and call getter + for(i=0;i0) + break; + } + // Return original metatable back + lua_pushvalue(L,original_metatable); + lua_setmetatable(L,base+1); + if(ret>0) + { + // tidy stack. Stack currently is: + // --base-- + // userdata + // key + // metatable + // .bases table + // userdata + // key : -2 + // return value : -1 + lua_remove(L,-2); // remove key + lua_remove(L,-2); // remove userdata + lua_remove(L,-2); // remove .bases + lua_remove(L,-2); // remove metatable + return 1; + } else { + lua_pop(L,2); // remove key and userdata + } + } + // Tidy stack: + // --base-- + // userdata + // key + // metatable + // .bases table + lua_pop(L,2); + assert(lua_gettop(L)==base+2); return 0; /* sorry not known */ } -/* the class.set method, performs the lookup of class attributes */ -SWIGINTERN int SWIG_Lua_class_set(lua_State* L) +/* helper for the class.set method, performs the lookup of class attributes + * Method can be called from SWIG_Lua_class_set or recursively from itself + */ +SWIGINTERN int SWIG_Lua_class_do_set(lua_State* L) { /* there should be 3 params passed in (1) table (not the meta table) (2) string name of the attribute (3) any for the new value printf("SWIG_Lua_class_set %p(%s) '%s' %p(%s)\n", - lua_topointer(L,1),lua_typename(L,lua_type(L,1)), - lua_tostring(L,2), - lua_topointer(L,3),lua_typename(L,lua_type(L,3)));*/ + lua_topointer(L,-3),lua_typename(L,lua_type(L,-3)), + lua_tostring(L,-2), + lua_topointer(L,-1),lua_typename(L,lua_type(L,-1)));*/ - assert(lua_isuserdata(L,1)); /* just in case */ - lua_getmetatable(L,1); /* get the meta table */ + int base = lua_gettop(L) - 3; + lua_checkstack(L,5); + assert(lua_isuserdata(L,base+1)); /* just in case */ + lua_getmetatable(L,base+1); /* get the meta table */ assert(lua_istable(L,-1)); /* just in case */ SWIG_Lua_get_table(L,".set"); /* find the .set table */ if (lua_istable(L,-1)) { /* look for the key in the .set table */ - lua_pushvalue(L,2); /* key */ + lua_pushvalue(L,base+2); /* key */ lua_rawget(L,-2); + lua_remove(L,-2); /* tidy stack, remove .set table */ if (lua_iscfunction(L,-1)) { /* found it so call the fn & return its value */ - lua_pushvalue(L,1); /* userdata */ - lua_pushvalue(L,3); /* value */ + lua_pushvalue(L,base+1); /* userdata */ + lua_pushvalue(L,base+3); /* value */ lua_call(L,2,0); + lua_remove(L,base+4); /*remove metatable*/ + assert(lua_gettop(L) == base+3); // TODO:REMOVE return 0; } lua_pop(L,1); /* remove the value */ + } else { + lua_pop(L,1); /* remove the answer for .set table request*/ } - lua_pop(L,1); /* remove the value .set table */ + assert(lua_gettop(L) == base + 4); // TODO: REMOVE /* NEW: looks for the __setitem() fn this is a user provided set fn */ SWIG_Lua_get_table(L,"__setitem"); /* find the fn */ if (lua_iscfunction(L,-1)) /* if its there */ { /* found it so call the fn & return its value */ - lua_pushvalue(L,1); /* the userdata */ - lua_pushvalue(L,2); /* the parameter */ - lua_pushvalue(L,3); /* the value */ + lua_pushvalue(L,base+1); /* the userdata */ + lua_pushvalue(L,base+2); /* the parameter */ + lua_pushvalue(L,base+3); /* the value */ lua_call(L,3,0); /* 3 values in ,0 out */ lua_remove(L,-2); /* stack tidy, remove metatable */ - return 1; + return 0; + } + lua_pop(L,1); // remove value + assert(lua_gettop(L) == base + 4); // TODO: REMOVE + + // Search among bases + int original_metatable = base+4; + assert(lua_gettop(L) == original_metatable); // Check that stack is correct + SWIG_Lua_get_table(L,".bases"); + assert(lua_istable(L,-1)); + int bases_count = lua_rawlen(L,-1); + if(bases_count>0) + { + int i = 0; + int ret = 0; + lua_pushvalue(L,base+1); // push userdata + lua_pushvalue(L,base+2); // Push key again + lua_pushvalue(L,base+3); // Push value again + // Trick: temporaly replacing original metatable + // with metatable for base class and call getter + for(i=0;ibases[i];i++) { - SWIG_Lua_add_class_details(L,clss->bases[i]); + SWIG_Lua_get_class_metatable(L,clss->bases[i]->fqname); + // Base class must be already registered + assert(lua_istable(L,-1)); + lua_rawseti(L,-2,i+1); // In lua indexing starts from 1 + bases_count++; } - /* add fns */ + assert(lua_rawlen(L,-1) == bases_count); + lua_pop(L,1); // remove .bases table + /* add attributes */ for(i=0;clss->attributes[i].name;i++){ SWIG_Lua_add_variable(L,clss->attributes[i].name,clss->attributes[i].getmethod,clss->attributes[i].setmethod); } @@ -851,7 +994,7 @@ SWIGINTERN void SWIG_Lua_add_class_details(lua_State* L,swig_lua_class* clss) /* add operator overloads these look ANY method which start with "__" and assume they are operator overloads & add them to the metatable - (this might mess up is someone defines a method __gc (the destructor)*/ + (this might mess up if someone defines a method __gc (the destructor)*/ for(i=0;clss->methods[i].name;i++){ if (clss->methods[i].name[0]=='_' && clss->methods[i].name[1]=='_'){ SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].func); @@ -884,13 +1027,13 @@ SWIGINTERN void SWIG_Lua_init_base_class(lua_State* L,swig_lua_class* clss) /* Register class static methods,attributes etc as well as constructor proxy */ SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* clss) { + int begin = lua_gettop(L); lua_checkstack(L,5); /* just in case */ assert(lua_istable(L,-1)); /* just in case */ assert(strcmp(clss->name, clss->cls_static.name) == 0); /* in class those 2 must be equal */ - SWIG_Lua_namespace_register(L,&clss->cls_static, false); + SWIG_Lua_namespace_register(L,&clss->cls_static, true); - SWIG_Lua_get_table(L,clss->name); // Get namespace table back assert(lua_istable(L,-1)); /* just in case */ /* add its constructor to module with the name of the class @@ -899,10 +1042,9 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* cls (this overcomes the problem of pure virtual classes without constructors)*/ if (clss->constructor) { - SWIG_Lua_add_function(L,".constructor", clss->constructor); lua_getmetatable(L,-1); assert(lua_istable(L,-1)); /* just in case */ - SWIG_Lua_add_function(L,"__call", SWIG_Lua_constructor_proxy); + SWIG_Lua_add_function(L,"__call", clss->constructor); lua_pop(L,1); } @@ -911,19 +1053,42 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* cls /* clear stack */ lua_pop(L,1); + assert( lua_gettop(L) == begin ); } -/* performs the entire class registration process */ -SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss) +/* performs the instance(non-static) class registration process. Metatable for class is created + * and added to the class registry. + */ +SWIGINTERN void SWIG_Lua_class_register_instance(lua_State* L,swig_lua_class* clss) { - SWIG_Lua_class_register_static(L,clss); - + int begin = lua_gettop(L); + // if name already there (class is already registered) then do nothing SWIG_Lua_get_class_registry(L); /* get the registry */ - lua_pushstring(L,clss->name); /* get the name */ + lua_pushstring(L,clss->fqname); /* get the name */ + lua_rawget(L,-2); + if(!lua_isnil(L,-1)) { + lua_pop(L,2); + assert(lua_gettop(L)==begin); + return; + } + lua_pop(L,2); // tidy stack + // Recursively initialize all bases + int i = 0; + for(i=0;clss->bases[i];i++) + { + SWIG_Lua_class_register_instance(L,clss->bases[i]); + } + // Again, get registry and push name + SWIG_Lua_get_class_registry(L); /* get the registry */ + lua_pushstring(L,clss->fqname); /* get the name */ lua_newtable(L); /* create the metatable */ /* add string of class name called ".type" */ lua_pushstring(L,".type"); - lua_pushstring(L,clss->name); + lua_pushstring(L,clss->fqname); + lua_rawset(L,-3); + /* add a table called bases */ + lua_pushstring(L,".bases"); + lua_newtable(L); lua_rawset(L,-3); /* add a table called ".get" */ lua_pushstring(L,".get"); @@ -948,10 +1113,18 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss) /* add it */ lua_rawset(L,-3); /* metatable into registry */ lua_pop(L,1); /* tidy stack (remove registry) */ + assert(lua_gettop(L)==begin); - SWIG_Lua_get_class_metatable(L,clss->name); - SWIG_Lua_add_class_details(L,clss); /* recursive adding of details (atts & ops) */ + SWIG_Lua_get_class_metatable(L,clss->fqname); + SWIG_Lua_add_class_instance_details(L,clss); /* recursive adding of details (atts & ops) */ lua_pop(L,1); /* tidy stack (remove class metatable) */ + assert( lua_gettop(L) == begin ); +} + +SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss) +{ + SWIG_Lua_class_register_instance(L,clss); + SWIG_Lua_class_register_static(L,clss); } /* ----------------------------------------------------------------------------- @@ -963,7 +1136,7 @@ SWIGINTERN void _SWIG_Lua_AddMetatable(lua_State* L,swig_type_info *type) { if (type->clientdata) /* there is clientdata: so add the metatable */ { - SWIG_Lua_get_class_metatable(L,((swig_lua_class*)(type->clientdata))->name); + SWIG_Lua_get_class_metatable(L,((swig_lua_class*)(type->clientdata))->fqname); if (lua_istable(L,-1)) { lua_setmetatable(L,-2); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 97ed295c9..195da18d6 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1490,6 +1490,7 @@ int Language::membervariableHandler(Node *n) { Setattr(n, "type", type); Setattr(n, "name", name); Setattr(n, "sym:name", symname); + Delattr(n, "memberset"); /* Delete all attached typemaps and typemap attributes */ Iterator ki; @@ -1507,6 +1508,7 @@ int Language::membervariableHandler(Node *n) { Setattr(n, "sym:name", mrename_get); Setattr(n, "memberget", "1"); functionWrapper(n); + Delattr(n, "memberget"); } Delete(mrename_get); Delete(mrename_set); @@ -2951,11 +2953,14 @@ int Language::constantWrapper(Node *n) { * ---------------------------------------------------------------------- */ int Language::variableWrapper(Node *n) { - Swig_require("variableWrapper", n, "*name", "*sym:name", "*type", "?parms", NIL); + Swig_require("variableWrapper", n, "*name", "*sym:name", "*type", "?parms", "?varset", "?varget", NIL); String *symname = Getattr(n, "sym:name"); SwigType *type = Getattr(n, "type"); String *name = Getattr(n, "name"); + Delattr(n,"varset"); + Delattr(n,"varget"); + /* If no way to set variables. We simply create functions */ int assignable = is_assignable(n); int flags = use_naturalvar_mode(n); @@ -2986,12 +2991,14 @@ int Language::variableWrapper(Node *n) { Delete(pname0); } if (make_set_wrapper) { + Setattr(n, "varset", "1"); functionWrapper(n); } /* Restore parameters */ Setattr(n, "sym:name", symname); Setattr(n, "type", type); Setattr(n, "name", name); + Delattr(n, "varset"); /* Delete all attached typemaps and typemap attributes */ Iterator ki; @@ -3005,6 +3012,7 @@ int Language::variableWrapper(Node *n) { String *gname = Swig_name_get(NSpace, symname); Setattr(n, "sym:name", gname); Delete(gname); + Setattr(n, "varget", "1"); functionWrapper(n); Swig_restore(n); return SWIG_OK; diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 10d9592cd..7a4f3229c 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -122,13 +122,20 @@ private: //String *s_vars_meta_tab; // metatable for variables Hash* namespaces_hash; + // Parameters for current class. NIL if not parsing class int have_constructor; int have_destructor; String *destructor_action; String *class_symname; + String *class_fq_symname; // Fully qualified symname - NSpace + '.' + class_symname + String *class_static_nspace; String *constructor_name; - enum { + // Many wrappers forward calls to each other, for example staticmembervariableHandler + // forwards call to variableHandler, which, in turn, makes to call to functionWrapper. + // In order to access information about whether it is static member of class or just + // plain old variable an array current is kept and used as 'log' of call stack. + enum TState { NO_CPP, VARIABLE, MEMBER_FUNC, @@ -137,8 +144,12 @@ private: MEMBER_VAR, CLASS_CONST, STATIC_FUNC, - STATIC_VAR - }current; + STATIC_VAR, + STATIC_CONST, // enums and things like static const int x = 5; + + STATES_COUNT + }; + bool current[STATES_COUNT]; public: @@ -175,10 +186,14 @@ public: have_destructor(0), destructor_action(0), class_symname(0), - constructor_name(0), - current(NO_CPP) { + class_fq_symname(0), + class_static_nspace(0), + constructor_name(0) { namespaces_hash = NewHash(); + for(int i = 0; i < STATES_COUNT; i++ ) + current[i] = false; } + ~LUA() { if(namespaces_hash) Delete(namespaces_hash); @@ -306,7 +321,9 @@ public: s_luacode = NewString(""); Swig_register_filebyname("luacode", s_luacode); - current=NO_CPP; + current[NO_CPP] = true; + // Registering names schemes + Swig_name_register("member", "%m"); /* Standard stuff for the SWIG runtime section */ Swig_banner(f_begin); @@ -473,6 +490,21 @@ public: * Create a function declaration and register it with the interpreter. * --------------------------------------------------------------------- */ + // Helper function. Remembers wrap name + void rememberWrapName(Node *n, String *wrapname) { + Setattr(n, "wrap:name", wrapname); + // If it is getter/setter, then write wrapname under + // wrap:memberset/wrap:memberget accordingly + if( Getattr(n, "memberset") ) + Setattr(n, "memberset:wrap:name", wrapname); + if( Getattr(n, "varset") ) + Setattr(n, "varset:wrap:name", wrapname); + if( Getattr(n, "memberget") ) + Setattr(n, "memberget:wrap:name", wrapname); + if( Getattr(n, "varget") ) + Setattr(n, "varget:wrap:name", wrapname); + } + virtual int functionWrapper(Node *n) { REPORT("functionWrapper",n); @@ -491,7 +523,7 @@ public: if (Getattr(n, "sym:overloaded")) { overname = Getattr(n, "sym:overname"); } else { - if (!addSymbol(iname, n, getNSpace())) { + if (!luaAddSymbol(iname, n)) { Printf(stderr,"addSymbol(%s) failed\n",iname); return SWIG_ERROR; } @@ -505,11 +537,13 @@ public: Wrapper_add_local(f, "SWIG_arg", "int SWIG_arg = 0"); - String *wname = Swig_name_wrapper(iname); + String* fqname = fully_qualified_name(iname); + String *wname = Swig_name_wrapper(fqname); + Delete(fqname); if (overname) { Append(wname, overname); } - if (current == CONSTRUCTOR) { + if (current[CONSTRUCTOR]) { if( constructor_name != 0) Delete(constructor_name); constructor_name = Copy(wname); @@ -552,12 +586,6 @@ public: } - /* Which input argument to start with? */ - // int start = (current == MEMBER_FUNC || current == MEMBER_VAR || current == DESTRUCTOR) ? 1 : 0; - - /* Offset to skip over the attribute name */ - // int offset = (current == MEMBER_VAR) ? 1 : 0; - /* NEW LANGUAGE NOTE:*********************************************** from here on in, it gets rather hairy this is the code to convert from the scripting language to C/C++ @@ -693,14 +721,7 @@ public: } // Remember C name of the wrapping function - Setattr(n, "wrap:name", wname); - // If it is getter/setter, then write wname under - // wrap:memberset/wrap:memberget accordingly - if( Getattr(n, "memberset") ) - Setattr(n, "memberset:wrap:name", wname); - if( Getattr(n, "memberget") ) - Setattr(n, "memberget:wrap:name", wname); - + rememberWrapName(n, wname); /* Emit the function call */ String *actioncode = emit_action(n); @@ -777,7 +798,7 @@ public: Therefore we go though the whole function, but do not write the code into the wrapper */ - if(current!=DESTRUCTOR) { + if(!current[DESTRUCTOR]) { Wrapper_print(f, f_wrappers); } @@ -789,7 +810,7 @@ public: if (!Getattr(n, "sym:overloaded")) { //REPORT("dispatchFunction", n); // add_method(n, iname, wname, description); - if (current==NO_CPP || current==STATIC_FUNC) { // emit normal fns & static fns + if (current[NO_CPP] || current[STATIC_FUNC]) { // emit normal fns & static fns Hash* nspaceHash = getNamespaceHash( getNSpace() ); String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); if(elua_ltr || eluac_ltr) @@ -877,24 +898,19 @@ public: Printv(f->code, "}\n", NIL); Wrapper_print(f, f_wrappers); //add_method(symname,wname,0); - if (current==NO_CPP || current==STATIC_FUNC) { // emit normal fns & static fns + if (current[NO_CPP] || current[STATIC_FUNC]) { // emit normal fns & static fns Hash* nspaceHash = getNamespaceHash( getNSpace() ); String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); Printv(s_ns_methods_tab, tab4, "{ \"", symname, "\",", wname, "},\n", NIL); } - if (current == CONSTRUCTOR) { + if (current[CONSTRUCTOR]) { if( constructor_name != 0 ) Delete(constructor_name); constructor_name = Copy(wname); } - Setattr(n, "wrap:name", wname); - // If it is getter/setter, then write wname under - // wrap:memberset/wrap:memberget accordingly - if( Getattr(n, "memberset") ) - Setattr(n, "memberset:wrap:name", wname); - if( Getattr(n, "memberget") ) - Setattr(n, "memberget:wrap:name", wname); + // Remember C name of the wrapping function + rememberWrapName(n, wname); DelWrapper(f); Delete(dispatch); @@ -916,13 +932,14 @@ public: NEW LANGUAGE NOTE:END ************************************************/ // REPORT("variableWrapper", n); String *iname = Getattr(n, "sym:name"); - current=VARIABLE; + String *unassignable = NewString("SWIG_Lua_set_immutable"); + current[VARIABLE] = true; // let SWIG generate the wrappers int result = Language::variableWrapper(n); - current=NO_CPP; + current[VARIABLE] = false; // 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(getNSpace(), iname)); + String *getName = Getattr(n,"varget:wrap:name"); String *setName = 0; // checking whether it can be set to or not appears to be a very error prone issue // I referred to the Language::variableWrapper() to find this out @@ -934,14 +951,15 @@ public: Delete(tm); if (assignable) { - setName = Swig_name_wrapper(Swig_name_set(getNSpace(), iname)); + setName = Getattr(n,"varset:wrap:name"); } else { // how about calling a 'this is not settable' error message? - setName = NewString("SWIG_Lua_set_immutable"); // error message - //setName = NewString("0"); + setName = unassignable;// error message } // register the variable + assert(setName != 0); + assert(getName != 0); Hash* nspaceHash = getNamespaceHash( getNSpace() ); String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); String* s_ns_var_tab = Getattr(nspaceHash, "attributes"); @@ -956,12 +974,11 @@ public: } else { Printf(s_ns_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, iname, getName, setName); } - if (getCurrentClass()) { + if (getCurrentClass()) { // TODO: REMOVE Setattr(n, "luaclassobj:wrap:get", getName); Setattr(n, "luaclassobj:wrap:set", setName); } else { - Delete(getName); - Delete(setName); + Delete(unassignable); } return result; } @@ -978,8 +995,9 @@ public: String *rawval = Getattr(n, "rawval"); String *value = rawval ? rawval : Getattr(n, "value"); String *tm; + //Printf( stdout, "Add constant %s, ns %s\n", iname, getNSpace() );// TODO: REMOVE - if (!addSymbol(iname, n, getNSpace())) + if (!luaAddSymbol(iname, n)) return SWIG_ERROR; /* Special hook for member pointer */ @@ -1035,7 +1053,7 @@ public: // REPORT("nativeWrapper", n); String *symname = Getattr(n, "sym:name"); String *wrapname = Getattr(n, "wrap:name"); - if (!addSymbol(wrapname, n, getNSpace())) + if (!luaAddSymbol(wrapname, n)) return SWIG_ERROR; Hash *nspaceHash = getNamespaceHash( getNSpace() ); @@ -1050,7 +1068,23 @@ public: * ------------------------------------------------------------ */ virtual int enumDeclaration(Node *n) { - return Language::enumDeclaration(n); + // enumDeclaration supplied by Language is messing with NSpace. + // So this is the exact copy of function from Language with + // correct handling of namespaces + String *oldNSpace = getNSpace(); + if( getCurrentClass() == 0 ) { + setNSpace(Getattr(n, "sym:nspace")); + } + + if (!ImportMode) { + current[STATIC_CONST] = true; + emit_children(n); + current[STATIC_CONST] = false; + } + + setNSpace(oldNSpace); + + return SWIG_OK; } /* ------------------------------------------------------------ @@ -1058,7 +1092,27 @@ public: * ------------------------------------------------------------ */ virtual int enumvalueDeclaration(Node *n) { - return Language::enumvalueDeclaration(n); + if (getCurrentClass() && (cplus_mode != PUBLIC)) + return SWIG_NOWRAP; + + Swig_require("enumvalueDeclaration", n, "*name", "?value", NIL); + String *value = Getattr(n, "value"); + String *name = Getattr(n, "name"); + String *tmpValue; + + if (value) + tmpValue = NewString(value); + else + tmpValue = NewString(name); + Setattr(n, "value", tmpValue); + + Setattr(n, "name", tmpValue); /* for wrapping of enums in a namespace when emit_action is used */ + constantWrapper(n); + + Delete(tmpValue); + Swig_restore(n); + // TODO: Backward compatibility: add ClassName_ConstantName member + return SWIG_OK; } /* ------------------------------------------------------------ @@ -1076,8 +1130,7 @@ public: virtual int classHandler(Node *n) { //REPORT("classHandler", n); - String *mangled_full_class_symname = 0; - String *full_class_symname = 0; + String *mangled_class_fq_symname = 0; String* nspace = getNSpace(); String* destructor_name = 0; @@ -1085,19 +1138,27 @@ public: have_constructor = 0; have_destructor = 0; destructor_action = 0; + assert(class_static_nspace == 0); + assert(class_fq_symname == 0); + assert(class_symname == 0); + + current[NO_CPP] = false; class_symname = Getattr(n, "sym:name"); - if (!addSymbol(class_symname, n, nspace)) + // We have to enforce nspace here, because technically we are already + // inside class parsing (getCurrentClass != 0), but we should register + // class in the it's parent namespace + if (!luaAddSymbol(class_symname, n, nspace)) return SWIG_ERROR; if (nspace == 0) - full_class_symname = NewStringf("%s", class_symname); + class_fq_symname = NewStringf("%s", class_symname); else - full_class_symname = NewStringf("%s.%s", nspace, class_symname); + class_fq_symname = NewStringf("%s.%s", nspace, class_symname); - assert(full_class_symname != 0); - mangled_full_class_symname = Swig_name_mangle(full_class_symname); - Printf( stdout, "Mangled class symname %s\n", mangled_full_class_symname ); + assert(class_fq_symname != 0); + mangled_class_fq_symname = Swig_name_mangle(class_fq_symname); + Printf( stdout, "Mangled class symname %s\n", mangled_class_fq_symname ); // not sure exactly how this works, // but tcl has a static hashtable of all classes emitted and then only emits code for them once. @@ -1107,9 +1168,9 @@ public: // * consider effect on template_specialization_defarg static Hash *emitted = NewHash(); - if (Getattr(emitted, mangled_full_class_symname)) + if (Getattr(emitted, mangled_class_fq_symname)) return SWIG_NOWRAP; - Setattr(emitted, mangled_full_class_symname, "1"); + Setattr(emitted, mangled_class_fq_symname, "1"); // We treat class T as both 'class' and 'namespace'. All static members, attributes // and constants are considered part of namespace T, all members - part of the 'class' @@ -1122,7 +1183,7 @@ public: // And we can guarantee that there will not be any name collision because names starting with 2 underscores // and capital letter are forbiden to use in C++. So, under know circumstances could our class contain // any member or subclass with name "__Static". Thus, never any name clash. - Hash* non_static_cls = getNamespaceHash(full_class_symname, false); + Hash* non_static_cls = getNamespaceHash(class_fq_symname, false); assert(non_static_cls != 0); s_attr_tab = Getattr(non_static_cls, "attributes"); s_methods_tab = Getattr(non_static_cls, "methods"); @@ -1135,11 +1196,9 @@ public: * All constants are considered part of static part of class. */ - String *static_cls_key = NewStringf("%s%s__Static", full_class_symname, NSPACE_SEPARATOR); - Hash *static_cls = getNamespaceHash(static_cls_key, false); - if (static_cls == 0) { - return SWIG_ERROR; // This cant be, so it is internal, implementation error - } + class_static_nspace = NewStringf("%s%s__Static", class_fq_symname, NSPACE_SEPARATOR); + Hash *static_cls = getNamespaceHash(class_static_nspace, false); + assert(static_cls != 0); Setattr(static_cls, "lua:no_namespaces", "1"); /* TODO: REMOVE s_cls_methods_tab = Getattr(static_cls, "methods"); @@ -1160,17 +1219,18 @@ public: // Replacing namespace with namespace + class in order to static // member be put inside class static area - setNSpace(static_cls_key); + setNSpace(class_static_nspace); // Generate normal wrappers Language::classHandler(n); // Restore correct nspace setNSpace(nspace); + //Printf( stdout, "Class finished\n" ); TODO:REMOVE SwigType *t = Copy(Getattr(n, "name")); SwigType_add_pointer(t); // Catch all: eg. a class with only static functions and/or variables will not have 'remembered' - String *wrap_class = NewStringf("&_wrap_class_%s", mangled_full_class_symname); + String *wrap_class = NewStringf("&_wrap_class_%s", mangled_class_fq_symname); SwigType_remember_clientdata(t, wrap_class); String *rt = Copy(getClassType()); @@ -1182,12 +1242,12 @@ public: Printv( ns_classes, wrap_class, ",\n", NIL ); // Register the class structure with the type checker - // Printf(f_init,"SWIG_TypeClientData(SWIGTYPE%s, (void *) &_wrap_class_%s);\n", SwigType_manglestr(t), mangled_full_class_symname); + // Printf(f_init,"SWIG_TypeClientData(SWIGTYPE%s, (void *) &_wrap_class_%s);\n", SwigType_manglestr(t), mangled_class_fq_symname); // emit a function to be called to delete the object // TODO: class_name -> full_class_name || mangled full_class_name if (have_destructor) { - destructor_name = NewStringf("swig_delete_%s", mangled_full_class_symname); + destructor_name = NewStringf("swig_delete_%s", mangled_class_fq_symname); Printv(f_wrappers, "static void ", destructor_name, "(void *obj) {\n", NIL); if (destructor_action) { Printv(f_wrappers, SwigType_str(rt, "arg1"), " = (", SwigType_str(rt, 0), ") obj;\n", NIL); @@ -1201,9 +1261,26 @@ public: } Printf(f_wrappers, "}\n"); } + // Wrap constructor wrapper into one more proxy function. It will be used as class namespace __call method, thus + // allowing both + // Module.ClassName.StaticMethod to access static method/variable/constant + // Module.ClassName() to create new object + if (have_constructor) { + String* constructor_proxy_name = NewStringf("_proxy_%s", constructor_name); + Printv(f_wrappers, "static int ", constructor_proxy_name, "(lua_State *L) {\n", NIL); + Printv(f_wrappers, + tab4, "assert(lua_istable(L,1));\n", + tab4, "lua_pushcfunction(L,", constructor_name, ");\n", + tab4, "assert(!lua_isnil(L,-1));\n", + tab4, "lua_replace(L,1); /* replace our table with real constructor */\n", + tab4, "lua_call(L,lua_gettop(L)-1,1);\n", + tab4, "return 1;\n}\n", NIL); + Delete(constructor_name); + constructor_name = constructor_proxy_name; + } - closeNamespaceHash(full_class_symname, f_wrappers); - closeNamespaceHash(static_cls_key, f_wrappers); + closeNamespaceHash(class_fq_symname, f_wrappers); + closeNamespaceHash(class_static_nspace, f_wrappers); /* TODO: REMOVE @@ -1251,12 +1328,12 @@ public: } } - Printv(f_wrappers, "static swig_lua_class *swig_", mangled_full_class_symname, "_bases[] = {", base_class, "0};\n", NIL); + Printv(f_wrappers, "static swig_lua_class *swig_", mangled_class_fq_symname, "_bases[] = {", base_class, "0};\n", NIL); Delete(base_class); - Printv(f_wrappers, "static const char *swig_", mangled_full_class_symname, "_base_names[] = {", base_class_names, "0};\n", NIL); + Printv(f_wrappers, "static const char *swig_", mangled_class_fq_symname, "_base_names[] = {", base_class_names, "0};\n", NIL); Delete(base_class_names); - Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_full_class_symname, " = { \"", class_symname, "\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); + Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_class_fq_symname, " = { \"", class_symname, "\", \"", class_fq_symname,"\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); // TODO: Replace with constructor_name if (have_constructor) { @@ -1285,7 +1362,7 @@ public: if (have_destructor) { if (eluac_ltr) { String* ns_methods_tab = Getattr(nspaceHash, "methods"); - Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_full_class_symname, "\")", ", LFUNCVAL(", destructor_name, ")", "},\n", NIL); + Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_class_fq_symname, "\")", ", LFUNCVAL(", destructor_name, ")", "},\n", NIL); Printv(f_wrappers, ", ", destructor_name, NIL); } else { Printv(f_wrappers, ", ", destructor_name, NIL); @@ -1295,15 +1372,21 @@ public: } Printf(f_wrappers, ", %s, %s, ", s_methods_tab_name, s_attr_tab_name ); // TODO: Replace class_symname with class_name - printNamespaceDefinition(static_cls_key, class_symname, f_wrappers); + printNamespaceDefinition(class_static_nspace, class_symname, f_wrappers); Printf(f_wrappers, ", swig_%s_bases, swig_%s_base_names };\n\n", - mangled_full_class_symname, mangled_full_class_symname); + mangled_class_fq_symname, mangled_class_fq_symname); - // Printv(f_wrappers, ", swig_", mangled_full_class_symname, "_methods, swig_", mangled_full_class_symname, "_attributes, swig_", mangled_full_class_symname, "_bases };\n\n", NIL); - // Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, &_wrap_class_", mangled_full_class_symname, "},\n", NIL); + // Printv(f_wrappers, ", swig_", mangled_class_fq_symname, "_methods, swig_", mangled_class_fq_symname, "_attributes, swig_", mangled_class_fq_symname, "_bases };\n\n", NIL); + // Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, &_wrap_class_", mangled_class_fq_symname, "},\n", NIL); + + current[NO_CPP] = true; Delete(t); - Delete(mangled_full_class_symname); - Delete(static_cls_key); + Delete(mangled_class_fq_symname); + Delete(class_static_nspace); + class_static_nspace = 0; + Delete(class_fq_symname); + class_fq_symname = 0; + class_symname = 0; return SWIG_OK; } @@ -1327,9 +1410,9 @@ public: String *realname, *rname; - current = MEMBER_FUNC; + current[MEMBER_FUNC] = true; Language::memberfunctionHandler(n); - current = NO_CPP; + current[MEMBER_FUNC] = false; realname = iname ? iname : name; rname = Getattr(n, "wrap:name"); @@ -1350,9 +1433,9 @@ public: String *symname = Getattr(n, "sym:name"); String *getter_name, *setter_name; - current = MEMBER_VAR; + current[MEMBER_VAR] = true; Language::membervariableHandler(n); - current = NO_CPP; + current[MEMBER_VAR] = false; getter_name = Getattr(n, "memberget:wrap:name"); assert(getter_name != 0); if (!GetFlag(n, "feature:immutable")) { @@ -1382,9 +1465,9 @@ public: virtual int constructorHandler(Node *n) { // REPORT("constructorHandler", n); - current = CONSTRUCTOR; + current[CONSTRUCTOR] = true; Language::constructorHandler(n); - current = NO_CPP; + current[CONSTRUCTOR] = false; //constructor_name = NewString(Getattr(n, "sym:name")); have_constructor = 1; //Printf( stdout, "Constructor %s\n", constructor_name); TODO: REMOVE @@ -1397,9 +1480,9 @@ public: virtual int destructorHandler(Node *n) { REPORT("destructorHandler", n); - current = DESTRUCTOR; + current[DESTRUCTOR] = true; Language::destructorHandler(n); - current = NO_CPP; + current[DESTRUCTOR] = false; have_destructor = 1; destructor_action = Getattr(n, "wrap:action"); return SWIG_OK; @@ -1413,28 +1496,28 @@ public: virtual int staticmemberfunctionHandler(Node *n) { REPORT("staticmemberfunctionHandler", n); - current = STATIC_FUNC; + current[STATIC_FUNC] = true; //String *symname = Getattr(n, "sym:name"); int result = Language::staticmemberfunctionHandler(n); if (cparse_cplusplus && getCurrentClass()) { Swig_restore(n); } - current = NO_CPP; + current[STATIC_FUNC] = false;; if (result != SWIG_OK) return result; if (Getattr(n, "sym:nextSibling")) return SWIG_OK; - Swig_require("luaclassobj_staticmemberfunctionHandler", n, "luaclassobj:wrap:name", NIL); + //Swig_require("luaclassobj_staticmemberfunctionHandler", n, "luaclassobj:wrap:name", NIL); //String *name = Getattr(n, "name"); //String *rname, *realname; //realname = symname ? symname : name; //rname = Getattr(n, "luaclassobj:wrap:name"); // TODO: Add backward compatibility here: add "ClassName_FuncName" to global table //Printv(s_cls_methods_tab, tab4, "{\"", realname, "\", ", rname, "}, \n", NIL); - Swig_restore(n); + //Swig_restore(n); return SWIG_OK; } @@ -1454,7 +1537,7 @@ public: } int result = Language::memberconstantHandler(n); if (cparse_cplusplus && getCurrentClass()) - Swig_restore(n); + Swig_restore(n); // TODO: WTF ? return result; } @@ -1465,9 +1548,10 @@ public: virtual int staticmembervariableHandler(Node *n) { REPORT("staticmembervariableHandler",n); - current = STATIC_VAR; + current[STATIC_VAR] = true; //String *symname = Getattr(n, "sym:name"); int result = Language::staticmembervariableHandler(n); + current[STATIC_VAR] = false; if (result != SWIG_OK) return result; @@ -1868,6 +1952,53 @@ public: Printf( output, "static swig_lua_namespace %s;\n", Getattr(nspace_hash, "cname") ); } + + // Our implementation of addSymbol. Determines scope correctly, then calls Language::addSymbol + int luaAddSymbol(const String *s, const Node *n) { + String* scope = 0; + // If ouside class, than NSpace is used. + if( !getCurrentClass()) + scope = getNSpace(); + else { + // If inside class, then either class static namespace or class fully qualified name is used + assert(!current[NO_CPP]); + if(current[STATIC_FUNC] || current[STATIC_VAR] || current[STATIC_CONST] ) { + scope = class_static_nspace; + } else if(current[MEMBER_VAR] || current[CLASS_CONST] || current[CONSTRUCTOR] || current[DESTRUCTOR] + || current[MEMBER_FUNC] ) { + scope = class_fq_symname; + } else { + assert(0); // Can't be. Implementation error + } + assert(scope != 0); + } + return Language::addSymbol(s,n,scope); + } + + // Overload. Enforces given scope. Actually, it simply forwards call to Language::addSymbol + int luaAddSymbol(const String*s, const Node*n, const_String_or_char_ptr scope) { + return Language::addSymbol(s,n,scope); + } + + // Function creates fully qualified name of given symbol. Current NSpace and current class + // are used + String* fully_qualified_name(const_String_or_char_ptr name) + { + assert(name != 0); + String* scope= 0; + if( getCurrentClass() ) + scope = class_fq_symname; + else + scope = getNSpace(); + + String *fqname = 0; + if( scope ) + fqname = NewStringf("%s::%s",scope,name); + else + fqname = Copy(name); + + return fqname; + } }; /* NEW LANGUAGE NOTE:*********************************************** From 602cf3a797fcc405b84fc1f462cc5cb1d864226d Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Thu, 31 Oct 2013 18:03:06 +0400 Subject: [PATCH 0970/1160] Bugfixes --- Source/Modules/lua.cxx | 316 ++++++++++++++++++++++++++++-------- Source/Modules/overload.cxx | 2 + Source/Swig/typesys.c | 2 +- 3 files changed, 253 insertions(+), 67 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 7a4f3229c..72d8fe8d1 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -73,7 +73,55 @@ void display_mapping(DOH *d) { } } +// Holds the pointer. Call's Delete in destructor, assignment etc +// TODO: REVIEW +template // T is ignored because everything is DOH* +class DohPointer { + public: + /* + DohPointer( DOH* _ptr ): + p_ptr(_ptr) + { + assert( p_ptr != 0 ); + } + */ + DohPointer(): + p_ptr(0) {} + DohPointer( const DohPointer& rhs ) { + AttachExisting( rhs.p_ptr ); + } + + const DohPointer& operator=( const DohPointer& rhs ) { + AttachExisting(rhs.p_ptr); + } + + DOH* ptr() { return p_ptr; } + const DOH* ptr() const { return p_ptr; } + operator DOH* () { return p_ptr; } + operator DOH* () const { return p_ptr; } + + // Attaches existing pointer. Refcount will be increased + void AttachExisting( DOH* obj ) { + AttachNew(obj); + if( p_ptr != 0 ) + DohIncref(p_ptr); + } + + // Attaches new pointer. As refcount is set to 1 at the creation, it won't be + // increased + void AttachNew( DOH *obj ) { + DOH* old_ptr = p_ptr; + p_ptr = obj; + if( old_ptr != 0 ) + Delete(old_ptr); + } + + private: + DOH* p_ptr; +}; + +#define Pointer DohPointer /* NEW LANGUAGE NOTE:*********************************************** most of the default options are handled by SWIG @@ -91,6 +139,7 @@ Lua Options (available with -lua)\n\ static int nomoduleglobal = 0; static int elua_ltr = 0; static int eluac_ltr = 0; +static int v2_compatibility = 1; /* NEW LANGUAGE NOTE:*********************************************** To add a new language, you need to derive your class from @@ -129,6 +178,7 @@ private: String *class_symname; String *class_fq_symname; // Fully qualified symname - NSpace + '.' + class_symname String *class_static_nspace; + String *class_parent_nspace; String *constructor_name; // Many wrappers forward calls to each other, for example staticmembervariableHandler @@ -322,8 +372,9 @@ public: Swig_register_filebyname("luacode", s_luacode); current[NO_CPP] = true; - // Registering names schemes - Swig_name_register("member", "%m"); + // Registering names schemes: TODO: REMOVE + //Swig_name_register("member", "%m"); + //Swig_name_register("construct", "new_%c"); /* Standard stuff for the SWIG runtime section */ Swig_banner(f_begin); @@ -476,6 +527,27 @@ public: return Language::importDirective(n); } + virtual int cDeclaration(Node *n) { + // Language is messing with symname in a really heavy way. + // Although documentation states that sym:name is a name in + // the target language space, it is not true. sym:name and + // it's derivatives are used in various places, including + // behind-the-scene C code generation. The best way is not to + // touch it at all. + // But we need to know what was the name of function/variable + // etc that user desired, that's why we store correct symname + // as lua:name + Setattr(n, "lua:name", Getattr(n, "sym:name") ); + return Language::cDeclaration(n); + } + virtual int constructorDeclaration(Node *n) { + Setattr(n, "lua:name", Getattr(n, "sym:name") ); + return Language::constructorDeclaration(n); + } + virtual int destructorDeclaration(Node *n) { + Setattr(n, "lua:name", Getattr(n, "sym:name") ); + return Language::destructorDeclaration(n); + } /* NEW LANGUAGE NOTE:*********************************************** This is it! you get this one right, and most of your work is done @@ -510,6 +582,8 @@ public: String *name = Getattr(n, "name"); String *iname = Getattr(n, "sym:name"); + String *target_name = Getattr(n, "lua:name"); + assert(target_name != 0); SwigType *d = Getattr(n, "type"); ParmList *l = Getattr(n, "parms"); //Printf(stdout,"functionWrapper %s %s\n",name,iname); @@ -523,8 +597,8 @@ public: if (Getattr(n, "sym:overloaded")) { overname = Getattr(n, "sym:overname"); } else { - if (!luaAddSymbol(iname, n)) { - Printf(stderr,"addSymbol(%s) failed\n",iname); + if (!luaAddSymbol(target_name, n)) { + Printf(stderr,"addSymbol(%s) failed\n",target_name); return SWIG_ERROR; } } @@ -537,9 +611,7 @@ public: Wrapper_add_local(f, "SWIG_arg", "int SWIG_arg = 0"); - String* fqname = fully_qualified_name(iname); - String *wname = Swig_name_wrapper(fqname); - Delete(fqname); + String *wname = symname_wrapper(iname); if (overname) { Append(wname, overname); } @@ -548,7 +620,7 @@ public: Delete(constructor_name); constructor_name = Copy(wname); } - //Printf(stdout , "Function wrapper, name %s\n", wname); // TODO:REMOVE + //Printf(stdout , "Function wrapper, name %s wrapname %s\n", iname, wname); // TODO:REMOVE /* NEW LANGUAGE NOTE:*********************************************** the format of a lua fn is: @@ -807,20 +879,10 @@ public: different language mappings seem to use different ideas NEW LANGUAGE NOTE:END ************************************************/ /* Now register the function with the interpreter. */ + //TODO: iname -> lua:name if (!Getattr(n, "sym:overloaded")) { - //REPORT("dispatchFunction", n); - // add_method(n, iname, wname, description); if (current[NO_CPP] || current[STATIC_FUNC]) { // emit normal fns & static fns - Hash* nspaceHash = getNamespaceHash( getNSpace() ); - String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); - if(elua_ltr || eluac_ltr) - Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", iname, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); - else - Printv(s_ns_methods_tab, tab4, "{ \"", iname, "\", ", wname, "},\n", NIL); - // Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", Swig_name_wrapper(iname), "},\n", NIL); - if (getCurrentClass()) { - Setattr(n,"luaclassobj:wrap:name", wname); - } + registerMethod(getNSpace(), n); } } else { if (!Getattr(n, "sym:nextSibling")) { @@ -834,7 +896,7 @@ public: Delete(cleanup); Delete(outarg); // Delete(description); - Delete(wname); + //Delete(wname); // TODO: Reference count seems not working DelWrapper(f); return SWIG_OK; @@ -856,6 +918,7 @@ public: //REPORT("dispatchFunction", n); /* Last node in overloaded chain */ + //Printf(stdout , "Dispatch, wrapname %s\n", Getattr(n,"wrap:name")); // TODO:REMOVE int maxargs; String *tmp = NewString(""); String *dispatch = Swig_overload_dispatch(n, "return %s(L);", &maxargs); @@ -864,7 +927,9 @@ public: Wrapper *f = NewWrapper(); String *symname = Getattr(n, "sym:name"); - String *wname = Swig_name_wrapper(symname); + String *target_name = Getattr(n, "lua:name"); + assert(target_name != 0); + String *wname = symname_wrapper(symname); //Printf(stdout,"Swig_overload_dispatch %s %s '%s' %d\n",symname,wname,dispatch,maxargs); @@ -897,11 +962,11 @@ public: Printf(f->code, "lua_error(L);return 0;\n"); Printv(f->code, "}\n", NIL); Wrapper_print(f, f_wrappers); - //add_method(symname,wname,0); if (current[NO_CPP] || current[STATIC_FUNC]) { // emit normal fns & static fns + // TODO: elua_ltr ? Hash* nspaceHash = getNamespaceHash( getNSpace() ); String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); - Printv(s_ns_methods_tab, tab4, "{ \"", symname, "\",", wname, "},\n", NIL); + Printv(s_ns_methods_tab, tab4, "{ \"", target_name, "\",", wname, "},\n", NIL); } if (current[CONSTRUCTOR]) { if( constructor_name != 0 ) @@ -932,17 +997,20 @@ public: NEW LANGUAGE NOTE:END ************************************************/ // REPORT("variableWrapper", n); String *iname = Getattr(n, "sym:name"); - String *unassignable = NewString("SWIG_Lua_set_immutable"); + String *target_name = Getattr(n, "lua:name"); + assert(target_name != 0); current[VARIABLE] = true; // let SWIG generate the wrappers int result = Language::variableWrapper(n); current[VARIABLE] = false; // 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 = Getattr(n,"varget:wrap:name"); - String *setName = 0; + //String *getName = Getattr(n,"varget:wrap:name"); + //String *setName = 0; // checking whether it can be set to or not appears to be a very error prone issue // I referred to the Language::variableWrapper() to find this out + // TODO: REMOVE? + /* bool assignable=is_assignable(n) ? true : false; SwigType *type = Getattr(n, "type"); String *tm = Swig_typemap_lookup("globalin", n, iname, 0); @@ -955,31 +1023,20 @@ public: } else { // how about calling a 'this is not settable' error message? setName = unassignable;// error message - } + }*/ // register the variable - assert(setName != 0); - assert(getName != 0); - Hash* nspaceHash = getNamespaceHash( getNSpace() ); - String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); - String* s_ns_var_tab = Getattr(nspaceHash, "attributes"); - if (elua_ltr) { - String* s_ns_dot_get = Getattr(nspaceHash, "get"); - String* s_ns_dot_set = Getattr(nspaceHash, "set"); - Printf(s_ns_dot_get, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, iname, getName); - Printf(s_ns_dot_set, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, iname, setName); - } else if (eluac_ltr) { - Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", iname, "_get", "\")", ", LFUNCVAL(", getName, ")", "},\n", NIL); - Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", iname, "_set", "\")", ", LFUNCVAL(", setName, ")", "},\n", NIL); - } else { - Printf(s_ns_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, iname, getName, setName); - } - if (getCurrentClass()) { // TODO: REMOVE + //assert(setName != 0); + //assert(getName != 0); + // TODO: CHeck. It seems to register everything in namespaces + // What about class variables ? + registerVariable( getNSpace(), n, "varget:wrap:name", "varset:wrap:name" ); + /*if (getCurrentClass()) { // TODO: REMOVE Setattr(n, "luaclassobj:wrap:get", getName); Setattr(n, "luaclassobj:wrap:set", setName); } else { Delete(unassignable); - } + }*/ return result; } @@ -990,6 +1047,9 @@ public: REPORT("constantWrapper", n); String *name = Getattr(n, "name"); String *iname = Getattr(n, "sym:name"); + String *target_name = Getattr(n, "lua:name"); + if(target_name == 0) + target_name = iname; String *nsname = Copy(iname); SwigType *type = Getattr(n, "type"); String *rawval = Getattr(n, "rawval"); @@ -997,12 +1057,14 @@ public: String *tm; //Printf( stdout, "Add constant %s, ns %s\n", iname, getNSpace() );// TODO: REMOVE - if (!luaAddSymbol(iname, n)) + if (!luaAddSymbol(target_name, n)) return SWIG_ERROR; + Swig_save("lua_constantMember", n, "sym:name", NIL); + Setattr(n, "sym:name", target_name); /* Special hook for member pointer */ if (SwigType_type(type) == T_MPOINTER) { - String *wname = Swig_name_wrapper(iname); + String *wname = symname_wrapper(iname); Printf(f_wrappers, "static %s = %s;\n", SwigType_str(type, wname), value); value = Char(wname); } @@ -1024,8 +1086,37 @@ public: } else { Delete(nsname); Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); + Swig_restore(n); return SWIG_NOWRAP; } + /* TODO: Review + if( v2_compatibility && getCurrentClass() ) { + if (!luaAddSymbol(iname, n, class_parent_nspace)) + return SWIG_ERROR; + + Setattr(n, "sym:name", iname); + if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) { + Replaceall(tm, "$source", value); + Replaceall(tm, "$target", name); + Replaceall(tm, "$value", value); + Replaceall(tm, "$nsname", nsname); + Hash *nspaceHash = getNamespaceHash( class_parent_nspace ); + String *s_const_tab = Getattr(nspaceHash, "constants"); + Printf(s_const_tab, " %s,\n", tm); + } else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) { + Replaceall(tm, "$source", value); + Replaceall(tm, "$target", name); + Replaceall(tm, "$value", value); + Replaceall(tm, "$nsname", nsname); + Printf(f_init, "%s\n", tm); + } else { + Delete(nsname); + Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); + Swig_restore(n); + return SWIG_NOWRAP; + } + } + */ /* TODO: Fix if (cparse_cplusplus && getCurrentClass()) { // Additionally add to class constants @@ -1041,6 +1132,7 @@ public: } Swig_restore(n); }*/ + Swig_restore(n); Delete(nsname); return SWIG_OK; } @@ -1053,6 +1145,7 @@ public: // REPORT("nativeWrapper", n); String *symname = Getattr(n, "sym:name"); String *wrapname = Getattr(n, "wrap:name"); + //String *target_name = Getattr(n, "lua:name"); TODO: REMOVE if (!luaAddSymbol(wrapname, n)) return SWIG_ERROR; @@ -1158,8 +1251,15 @@ public: assert(class_fq_symname != 0); mangled_class_fq_symname = Swig_name_mangle(class_fq_symname); - Printf( stdout, "Mangled class symname %s\n", mangled_class_fq_symname ); + SwigType *t = Copy(Getattr(n, "name")); + SwigType *fr_t = SwigType_typedef_resolve_all(t); /* Create fully resolved type */ + SwigType *t_tmp = SwigType_typedef_qualified(fr_t); // Temporal variable + Delete(fr_t); + fr_t = SwigType_strip_qualifiers(t_tmp); + Delete(t_tmp); + String *mangled_fr_t = SwigType_manglestr(fr_t); + //Printf( stdout, "Mangled class symname %s fr type%s\n", mangled_class_fq_symname, mangled_fr_t ); // TODO: REMOVE // not sure exactly how this works, // but tcl has a static hashtable of all classes emitted and then only emits code for them once. // this fixes issues in test suites: template_default2 & template_specialization @@ -1168,9 +1268,13 @@ public: // * consider effect on template_specialization_defarg static Hash *emitted = NewHash(); - if (Getattr(emitted, mangled_class_fq_symname)) + if (Getattr(emitted, mangled_fr_t)) { + class_fq_symname = 0; + class_symname = 0; + // TODO: Memory leak here return SWIG_NOWRAP; - Setattr(emitted, mangled_class_fq_symname, "1"); + } + Setattr(emitted, mangled_fr_t, "1"); // We treat class T as both 'class' and 'namespace'. All static members, attributes // and constants are considered part of namespace T, all members - part of the 'class' @@ -1219,14 +1323,15 @@ public: // Replacing namespace with namespace + class in order to static // member be put inside class static area + class_parent_nspace = getNSpace(); setNSpace(class_static_nspace); // Generate normal wrappers Language::classHandler(n); // Restore correct nspace setNSpace(nspace); + class_parent_nspace = 0; //Printf( stdout, "Class finished\n" ); TODO:REMOVE - SwigType *t = Copy(Getattr(n, "name")); SwigType_add_pointer(t); // Catch all: eg. a class with only static functions and/or variables will not have 'remembered' @@ -1341,16 +1446,16 @@ public: String* ns_methods_tab = Getattr(nspaceHash, "methods"); // TODO: Contructor should be moved to __call method of static part of class Printf(ns_methods_tab, " {LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", class_symname, \ - Swig_name_wrapper(Swig_name_construct(nspace, constructor_name))); - Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(nspace, constructor_name))); + symname_wrapper(Swig_name_construct(nspace, constructor_name))); + Printf(f_wrappers, "%s", symname_wrapper(Swig_name_construct(nspace, constructor_name))); } else if (eluac_ltr) { String* ns_methods_tab = Getattr(nspaceHash, "methods"); Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "new_", class_symname, "\")", ", LFUNCVAL(", \ - Swig_name_wrapper(Swig_name_construct(nspace, constructor_name)), ")", "},\n", NIL); - Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(nspace, constructor_name))); + symname_wrapper(Swig_name_construct(nspace, constructor_name)), ")", "},\n", NIL); + Printf(f_wrappers, "%s", symname_wrapper(Swig_name_construct(nspace, constructor_name))); } else { - //Printf( stdout, "Constructor.name %s declaration: %s\n", constructor_name, Swig_name_wrapper(Swig_name_construct(nspace, constructor_name))); - //Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(nspace, constructor_name))); + //Printf( stdout, "Constructor.name %s declaration: %s\n", constructor_name, symname_wrapper(Swig_name_construct(nspace, constructor_name))); + //Printf(f_wrappers, "%s", symname_wrapper(Swig_name_construct(nspace, constructor_name))); Printv(f_wrappers, constructor_name, NIL); } Delete(constructor_name); @@ -1501,12 +1606,16 @@ public: int result = Language::staticmemberfunctionHandler(n); if (cparse_cplusplus && getCurrentClass()) { - Swig_restore(n); + Swig_restore(n); // TODO: WTF ? } current[STATIC_FUNC] = false;; if (result != SWIG_OK) return result; + if(v2_compatibility) { + registerMethod( class_parent_nspace, n ); + } + if (Getattr(n, "sym:nextSibling")) return SWIG_OK; @@ -1531,13 +1640,16 @@ public: virtual int memberconstantHandler(Node *n) { REPORT("memberconstantHandler",n); String *symname = Getattr(n, "sym:name"); + /* TODO:REMOVE if (cparse_cplusplus && getCurrentClass()) { Swig_save("luaclassobj_memberconstantHandler", n, "luaclassobj:symname", NIL); Setattr(n, "luaclassobj:symname", symname); - } + }*/ int result = Language::memberconstantHandler(n); + /* TODO:REMOVE if (cparse_cplusplus && getCurrentClass()) Swig_restore(n); // TODO: WTF ? + */ return result; } @@ -1556,9 +1668,25 @@ public: if (result != SWIG_OK) return result; - - if (Getattr(n, "wrappedasconstant")) - return SWIG_OK; + // This will add static member variable to the class namespace with name ClassName_VarName + if(v2_compatibility) { + Swig_save("lua_staticmembervariableHandler",n,"lua:name"); + String *target_name = Getattr(n, "lua:name"); + String *v2_name = Swig_name_member(NIL, class_symname, target_name); + //Printf( stdout, "Name %s, class %s, compt. name %s\n", target_name, class_symname, v2_name ); // TODO: REMOVE + if( !GetFlag(n,"wrappedasconstant") ) { + Setattr(n, "lua:name", v2_name); + registerVariable( class_parent_nspace, n, "varget:wrap:name", "varset:wrap:name"); + } else { + Setattr(n, "lua:name", v2_name); + String* oldNSpace = getNSpace(); + setNSpace(class_parent_nspace); + constantWrapper(n); + setNSpace(oldNSpace); + } + Delete(v2_name); + Swig_restore(n); + } /* TODO: Add backward compatibility here: add "ClassName_AttributeName" to class scope Swig_require("luaclassobj_staticmembervariableHandler", n, "luaclassobj:wrap:get", "luaclassobj:wrap:set", NIL); @@ -1887,7 +2015,7 @@ public: Hash* nspace = Getattr(namespaces_hash, key); String* cname = Getattr(nspace, "cname"); // cname - name of the C structure that describes namespace assert(cname != 0); - Printf( stdout, "Closing namespace %s\n", cname ); + //Printf( stdout, "Closing namespace %s\n", cname ); TODO: REMOVE //printNamespaceForwardDeclaration( ki.key, declOutput ); TODO: REMOVE Printv(dataOutput, "static swig_lua_namespace ", cname, " = ", NIL); String *name = 0; // name - name of the namespace as it should be visible in Lua @@ -1930,6 +2058,50 @@ public: ); } + // Add method to the "methods" C array of given namespace/class + void registerMethod(String *nspace_or_class_name, Node* n) { + Hash* nspaceHash = getNamespaceHash( nspace_or_class_name ); + String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); + String *wname = Getattr(n, "wrap:name"); + String *iname = Getattr(n, "sym:name"); + String *target_name = Getattr(n, "lua:name"); + if(elua_ltr || eluac_ltr) + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", iname, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); + else + Printv(s_ns_methods_tab, tab4, "{ \"", target_name, "\", ", wname, "},\n", NIL); + // Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", symname_wrapper(iname), "},\n", NIL); + if (getCurrentClass()) { + Setattr(n,"luaclassobj:wrap:name", wname); // TODO: REMOVE + } + } + + // Add variable to the "attributes" (or "get"/"set" in + // case of elua_ltr) C arrays of given namespace or class + void registerVariable(String *nspace_or_class_name, Node* n, const char *getAttrName, const char *setAttrName) { + String *unassignable = NewString("SWIG_Lua_set_immutable"); + String *getName = Getattr(n,getAttrName); + String *setName = Getattr(n,setAttrName); + if(setName == 0) { + setName = unassignable; + } + Hash* nspaceHash = getNamespaceHash( nspace_or_class_name ); + String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); + String* s_ns_var_tab = Getattr(nspaceHash, "attributes"); + String *target_name = Getattr(n, "lua:name"); + if (elua_ltr) { + String* s_ns_dot_get = Getattr(nspaceHash, "get"); + String* s_ns_dot_set = Getattr(nspaceHash, "set"); + Printf(s_ns_dot_get, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, target_name, getName); + Printf(s_ns_dot_set, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, target_name, setName); + } else if (eluac_ltr) { + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", target_name, "_get", "\")", ", LFUNCVAL(", getName, ")", "},\n", NIL); + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", target_name, "_set", "\")", ", LFUNCVAL(", setName, ")", "},\n", NIL); + } else { + Printf(s_ns_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, target_name, getName, setName); + } + } + + // This function prints forward declaration of namespace itself and all its arrays // TODO: REMOVE void printNamespaceForwardDeclaration(String* nspace, File* output) @@ -1955,6 +2127,7 @@ public: // Our implementation of addSymbol. Determines scope correctly, then calls Language::addSymbol int luaAddSymbol(const String *s, const Node *n) { + //Printf(stdout, "addSymbol: %s", s); // TODO:REMOVE String* scope = 0; // If ouside class, than NSpace is used. if( !getCurrentClass()) @@ -1967,11 +2140,12 @@ public: } else if(current[MEMBER_VAR] || current[CLASS_CONST] || current[CONSTRUCTOR] || current[DESTRUCTOR] || current[MEMBER_FUNC] ) { scope = class_fq_symname; - } else { - assert(0); // Can't be. Implementation error + } else { // Friend functions are handled this way + scope = class_static_nspace; } assert(scope != 0); } + //Printf( stdout, " scope: %s\n", scope ); // TODO:REMOVE return Language::addSymbol(s,n,scope); } @@ -1999,6 +2173,16 @@ public: return fqname; } + + // Input: symname + // Output - wrapper around fully qualified form of symname + String* symname_wrapper( String *symname) + { + String *fqname = fully_qualified_name(symname); + String* wname = Swig_name_wrapper(fqname); + Delete(fqname); + return wname; + } }; /* NEW LANGUAGE NOTE:*********************************************** diff --git a/Source/Modules/overload.cxx b/Source/Modules/overload.cxx index e95ef557f..4c0d06702 100644 --- a/Source/Modules/overload.cxx +++ b/Source/Modules/overload.cxx @@ -765,6 +765,7 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar for (i = 0; i < nfunc; i++) { Node *ni = Getitem(dispatch, i); Parm *pi = Getattr(ni, "wrap:parms"); + //Printf(stdout , "Dispatch, wrapname %s\n", Getattr(ni,"wrap:name")); // TODO:REMOVE bool implicitconvtypecheckoff = GetFlag(ni, "implicitconvtypecheckoff") != 0; int num_required = emit_num_required(pi); int num_arguments = emit_num_arguments(pi); @@ -818,6 +819,7 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar j++; } String *lfmt = ReplaceFormat(fmt, num_arguments); + //Printf(stdout , "Dispatch, wrapname %s\n", Getattr(ni,"wrap:name")); // TODO:REMOVE Printf(f, Char(lfmt), Getattr(ni, "wrap:name")); Delete(lfmt); /* close braces */ diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index e11fc781a..a7060ca54 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -1594,7 +1594,7 @@ void SwigType_remember_clientdata(const SwigType *t, const_String_or_char_ptr cl Delete(qr); /*Printf(stdout,"t = '%s'\n", t); - Printf(stdout,"fr= '%s'\n\n", fr); */ + Printf(stdout,"fr= '%s'\n\n", fr); TODO: COmment back*/ if (t) { char *ct = Char(t); From aec439128429d594090d6872e710ded4fdb386ed Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Thu, 31 Oct 2013 20:48:38 +0400 Subject: [PATCH 0971/1160] Add runtime test --- Examples/test-suite/lua/nspace_runme.lua | 67 ++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Examples/test-suite/lua/nspace_runme.lua diff --git a/Examples/test-suite/lua/nspace_runme.lua b/Examples/test-suite/lua/nspace_runme.lua new file mode 100644 index 000000000..4eb0ffaf6 --- /dev/null +++ b/Examples/test-suite/lua/nspace_runme.lua @@ -0,0 +1,67 @@ +require("import") -- the import fn +import("nspace") -- import lib + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +ns = nspace + +-- Inheritance +blue1 = ns.Outer.Inner3.Blue() +debug.debug() +-- blue1:blueInstanceMethod() +blue1:colorInstanceMethod(60.0) +blue1.instanceMemberVariable = 4 +assert( blue1.instanceMemberVariable == 4 ) + +-- Constructors +color1 = ns.Outer.Inner1.Color() +color2 = ns.Outer.Inner1.Color.create() +color = ns.Outer.Inner1.Color(color1) +color3 = ns.Outer.Inner2.Color.create() +color4 = ns.Outer.Inner2.Color.create() +color5 = ns.Outer.Inner2.Color.create() +mwp2 = ns.Outer.MyWorldPart2() +gc = ns.GlobalClass() + +nnsp = ns.NoNSpacePlease() + +-- Class methods +color:colorInstanceMethod(20.0) +ns.Outer.Inner1.Color.colorStaticMethod(30.0) +color3:colorInstanceMethod(40.0) +ns.Outer.Inner2.Color.colorStaticMethod(50.0) +color3:colors(color1, color2, color3, color4, color5) + +gc:gmethod() + +-- Class variables +color.instanceMemberVariable = 5 +color1.instanceMemberVariable = 7 +assert( color.instanceMemberVariable == 5 ) +assert( color1.instanceMemberVariable == 7 ) +assert(ns.Outer.Inner1.Color.staticMemberVariable == 0 ) +assert(ns.Outer.Inner2.Color.staticMemberVariable == 0 ) +ns.Outer.Inner1.Color.staticMemberVariable = 9 +ns.Outer.Inner2.Color.staticMemberVariable = 11 +assert(ns.Outer.Inner1.Color.staticMemberVariable == 9) +assert(ns.Outer.Inner2.Color.staticMemberVariable == 11) + +-- Class constants +assert( ns.Outer.Inner1.Color.Specular == 0x20 ) +assert( ns.Outer.Inner2.Color.Specular == 0x40 ) +assert( ns.Outer.Inner1.Color.staticConstMemberVariable == 222 ) +assert( ns.Outer.Inner2.Color.staticConstMemberVariable == 333 ) +assert( ns.Outer.Inner1.Color.staticConstEnumMemberVariable ~= ns.Outer.Inner2.Color.staticConstEnumMemberVariable ) + + +-- Aggregation +sc = ns.Outer.SomeClass() +assert( sc:GetInner1ColorChannel() ~= sc:GetInner2Channel() ) +assert( sc:GetInner1Channel() ~= sc:GetInner2Channel() ) + + + + From ad375d9526e6b99c93394771339cdcb4e52c0896 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Fri, 1 Nov 2013 17:47:12 +0400 Subject: [PATCH 0972/1160] Add pointer guard --- Source/Modules/lua.cxx | 106 +++++++++++++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 20 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 72d8fe8d1..0a7dd1041 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -75,6 +75,7 @@ void display_mapping(DOH *d) { // Holds the pointer. Call's Delete in destructor, assignment etc // TODO: REVIEW +// Class won't work, TODO: REMOVE template // T is ignored because everything is DOH* class DohPointer { public: @@ -123,6 +124,74 @@ class DohPointer { #define Pointer DohPointer +template // T is ignored because everything is DOH* +class DohPtrGuard { + public: + DohPtrGuard( DOH* _ptr ): + p_ptr(_ptr) + { + assert( p_ptr != 0 ); + } + DohPtrGuard(): + p_ptr(0) {} + + ~DohPtrGuard() { + release(); + } + + // Guard is empty, ptr - any: assigns new value for guard + // Guard is holding pointer, ptr == 0 - releases value that guard holds + // Any other combination - assert + void operator=( DOH* ptr ) { + attach(ptr); + } + + DOH* ptr() { return p_ptr; } + const DOH* ptr() const { return p_ptr; } + operator DOH* () { return p_ptr; } + operator DOH* () const { return p_ptr; } + + private: + DOH* p_ptr; // pointer to actual object + + void attach(DOH* ptr) { + if( p_ptr != 0 ) { // If some object already attached, then we can't attach another one + assert(ptr == 0); + if( ptr == 0 ) { + release(); + } + } else { + p_ptr = ptr; + } + } + + void release() { + if( p_ptr != 0 ) { + Delete(p_ptr); + p_ptr = 0; + } + } + // Copying is forbiden + DohPtrGuard( const DohPtrGuard& rhs ); + void operator=( const DohPtrGuard& rhs ); + +}; + +// Overloading DohDelete for DohPtrGuard. You might not call DohDelete on DohPtrGuard instances, +// as it is supposed to manage underlying pointer by itself + +void DohDelete(const DohPtrGuard& guard) { + Printf( stderr, "ERROR: Attempt to delete guarded pointer without deleting it's guardian\n" ); + assert(false); +} +void DohDelete(DohPtrGuard& guard) { + Printf( stderr, "ERROR: Attempt to delete guarded pointer without deleting it's guardian\n" ); + assert(false); +} + + +#define PtrGuard DohPtrGuard + /* NEW LANGUAGE NOTE:*********************************************** most of the default options are handled by SWIG you can add new ones here @@ -1223,9 +1292,9 @@ public: virtual int classHandler(Node *n) { //REPORT("classHandler", n); - String *mangled_class_fq_symname = 0; + PtrGuard mangled_class_fq_symname; + PtrGuard destructor_name; String* nspace = getNSpace(); - String* destructor_name = 0; constructor_name = 0; have_constructor = 0; @@ -1252,13 +1321,12 @@ public: assert(class_fq_symname != 0); mangled_class_fq_symname = Swig_name_mangle(class_fq_symname); - SwigType *t = Copy(Getattr(n, "name")); - SwigType *fr_t = SwigType_typedef_resolve_all(t); /* Create fully resolved type */ - SwigType *t_tmp = SwigType_typedef_qualified(fr_t); // Temporal variable - Delete(fr_t); + PtrGuard t = Copy(Getattr(n, "name")); + PtrGuard fr_t = SwigType_typedef_resolve_all(t); /* Create fully resolved type */ + PtrGuard t_tmp = SwigType_typedef_qualified(fr_t); // Temporal variable + fr_t = 0; fr_t = SwigType_strip_qualifiers(t_tmp); - Delete(t_tmp); - String *mangled_fr_t = SwigType_manglestr(fr_t); + PtrGuard mangled_fr_t = SwigType_manglestr(fr_t); //Printf( stdout, "Mangled class symname %s fr type%s\n", mangled_class_fq_symname, mangled_fr_t ); // TODO: REMOVE // not sure exactly how this works, // but tcl has a static hashtable of all classes emitted and then only emits code for them once. @@ -1335,7 +1403,7 @@ public: SwigType_add_pointer(t); // Catch all: eg. a class with only static functions and/or variables will not have 'remembered' - String *wrap_class = NewStringf("&_wrap_class_%s", mangled_class_fq_symname); + String *wrap_class = NewStringf("&_wrap_class_%s", mangled_class_fq_symname.ptr()); SwigType_remember_clientdata(t, wrap_class); String *rt = Copy(getClassType()); @@ -1352,8 +1420,8 @@ public: // emit a function to be called to delete the object // TODO: class_name -> full_class_name || mangled full_class_name if (have_destructor) { - destructor_name = NewStringf("swig_delete_%s", mangled_class_fq_symname); - Printv(f_wrappers, "static void ", destructor_name, "(void *obj) {\n", NIL); + destructor_name = NewStringf("swig_delete_%s", mangled_class_fq_symname.ptr()); + Printv(f_wrappers, "static void ", destructor_name.ptr(), "(void *obj) {\n", NIL); if (destructor_action) { Printv(f_wrappers, SwigType_str(rt, "arg1"), " = (", SwigType_str(rt, 0), ") obj;\n", NIL); Printv(f_wrappers, destructor_action, "\n", NIL); @@ -1433,12 +1501,12 @@ public: } } - Printv(f_wrappers, "static swig_lua_class *swig_", mangled_class_fq_symname, "_bases[] = {", base_class, "0};\n", NIL); + Printv(f_wrappers, "static swig_lua_class *swig_", mangled_class_fq_symname.ptr(), "_bases[] = {", base_class, "0};\n", NIL); Delete(base_class); - Printv(f_wrappers, "static const char *swig_", mangled_class_fq_symname, "_base_names[] = {", base_class_names, "0};\n", NIL); + Printv(f_wrappers, "static const char *swig_", mangled_class_fq_symname.ptr(), "_base_names[] = {", base_class_names, "0};\n", NIL); Delete(base_class_names); - Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_class_fq_symname, " = { \"", class_symname, "\", \"", class_fq_symname,"\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); + Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_class_fq_symname.ptr(), " = { \"", class_symname, "\", \"", class_fq_symname,"\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); // TODO: SwigType_manglestr(t) - memory leak // TODO: Replace with constructor_name if (have_constructor) { @@ -1467,10 +1535,10 @@ public: if (have_destructor) { if (eluac_ltr) { String* ns_methods_tab = Getattr(nspaceHash, "methods"); - Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_class_fq_symname, "\")", ", LFUNCVAL(", destructor_name, ")", "},\n", NIL); - Printv(f_wrappers, ", ", destructor_name, NIL); + Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_class_fq_symname.ptr(), "\")", ", LFUNCVAL(", destructor_name.ptr(), ")", "},\n", NIL); + Printv(f_wrappers, ", ", destructor_name.ptr(), NIL); } else { - Printv(f_wrappers, ", ", destructor_name, NIL); + Printv(f_wrappers, ", ", destructor_name.ptr(), NIL); } } else { Printf(f_wrappers, ",0"); @@ -1479,14 +1547,12 @@ public: // TODO: Replace class_symname with class_name printNamespaceDefinition(class_static_nspace, class_symname, f_wrappers); Printf(f_wrappers, ", swig_%s_bases, swig_%s_base_names };\n\n", - mangled_class_fq_symname, mangled_class_fq_symname); + mangled_class_fq_symname.ptr(), mangled_class_fq_symname.ptr()); // Printv(f_wrappers, ", swig_", mangled_class_fq_symname, "_methods, swig_", mangled_class_fq_symname, "_attributes, swig_", mangled_class_fq_symname, "_bases };\n\n", NIL); // Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, &_wrap_class_", mangled_class_fq_symname, "},\n", NIL); current[NO_CPP] = true; - Delete(t); - Delete(mangled_class_fq_symname); Delete(class_static_nspace); class_static_nspace = 0; Delete(class_fq_symname); From 577f20c9904c5e25a1be57ec38fbe9163d7a314d Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Fri, 1 Nov 2013 19:57:47 +0400 Subject: [PATCH 0973/1160] Fixing issuse with v2-compatible static function names --- Source/Modules/lua.cxx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 0a7dd1041..413c30b32 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -1321,12 +1321,14 @@ public: assert(class_fq_symname != 0); mangled_class_fq_symname = Swig_name_mangle(class_fq_symname); - PtrGuard t = Copy(Getattr(n, "name")); - PtrGuard fr_t = SwigType_typedef_resolve_all(t); /* Create fully resolved type */ - PtrGuard t_tmp = SwigType_typedef_qualified(fr_t); // Temporal variable + PtrGuard t( Copy(Getattr(n, "name")) ); + PtrGuard fr_t( SwigType_typedef_resolve_all(t) ); /* Create fully resolved type */ + PtrGuard t_tmp; + t_tmp = SwigType_typedef_qualified(fr_t); // Temporal variable fr_t = 0; fr_t = SwigType_strip_qualifiers(t_tmp); - PtrGuard mangled_fr_t = SwigType_manglestr(fr_t); + PtrGuard mangled_fr_t; + mangled_fr_t = SwigType_manglestr(fr_t); //Printf( stdout, "Mangled class symname %s fr type%s\n", mangled_class_fq_symname, mangled_fr_t ); // TODO: REMOVE // not sure exactly how this works, // but tcl has a static hashtable of all classes emitted and then only emits code for them once. @@ -1671,15 +1673,18 @@ public: //String *symname = Getattr(n, "sym:name"); int result = Language::staticmemberfunctionHandler(n); - if (cparse_cplusplus && getCurrentClass()) { - Swig_restore(n); // TODO: WTF ? - } current[STATIC_FUNC] = false;; if (result != SWIG_OK) return result; if(v2_compatibility) { + Swig_require("lua_staticmemberfunctionHandler", n, "*lua:name", NIL); + String *target_name = Getattr(n, "lua:name"); + PtrGuard compat_name; + compat_name = Swig_name_member(0, class_symname, target_name); + Setattr(n, "lua:name", compat_name); registerMethod( class_parent_nspace, n ); + Swig_restore(n); } if (Getattr(n, "sym:nextSibling")) From 63a26c6dbe0f1ae722219fb6f035ce305bf34075 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Tue, 5 Nov 2013 16:37:58 +0400 Subject: [PATCH 0974/1160] More changes. Mostly to the would-be class library --- Lib/lua/luarun.swg | 180 +++++++++++++++- Lib/lua/luaruntime.swg | 2 + Source/Modules/lua.cxx | 463 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 641 insertions(+), 4 deletions(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index ec33ea601..c398c7925 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -879,13 +879,13 @@ SWIGINTERN int SWIG_Lua_class_tostring(lua_State* L) unsigned long userData = (unsigned long)lua_touserdata(L,1); /* get the userdata address for later */ lua_getmetatable(L,1); /* get the meta table */ assert(lua_istable(L,-1)); /* just in case */ - + lua_getfield(L, -1, ".type"); const char* className = lua_tostring(L, -1); - + char output[256]; - sprintf(output, "<%s userdata: %lX>", className, userData); - + snprintf(output, 255, "<%s userdata: %lX>", className, userData); + lua_pushstring(L, (const char*)output); return 1; } @@ -1123,8 +1123,37 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State* L,swig_lua_class* c SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss) { + assert(lua_istable(L,-1)); /* This is table(module or namespace) where class will be added */ SWIG_Lua_class_register_instance(L,clss); SWIG_Lua_class_register_static(L,clss); + + /* Add links from static part to instance part and vice versa */ + /* [SWIG registry] [Module] + * "MyClass" ----> [MyClass metatable] <===== "MyClass" -+> [static part] + * ".get" ----> ... | | getmetatable()----| + * ".set" ----> ... | | | + * ".static" --------------)----------------/ [static part metatable] + * | ".get" --> ... + * | ".set" --> .... + * |=============================== ".instance" + */ + int begin = lua_gettop(L); + lua_pushstring(L,clss->cls_static.name); + lua_rawget(L,-2); /* get class static table */ + assert(lua_istable(L,-1)); + lua_getmetatable(L,-1); + assert(lua_istable(L,-1)); /* get class static metatable */ + lua_pushstring(L,".instance"); /* prepare key */ + + SWIG_Lua_get_class_metatable(L,clss->fqname); /* get class metatable */ + assert(lua_istable(L,-1)); + lua_pushstring(L,".static"); /* prepare key */ + lua_pushvalue(L, -4); /* push static class TABLE */ + assert(lua_istable(L,-1)); + lua_rawset(L,-3); /* assign static class table(!NOT metatable) as ".static" member of class metatable */ + lua_rawset(L,-3); /* assign class metatable as ".instance" member of class static METATABLE */ + lua_pop(L,2); + assert(lua_gettop(L) == begin); } /* ----------------------------------------------------------------------------- @@ -1351,4 +1380,147 @@ SWIG_Lua_dostring(lua_State *L, const char* str) { } #endif +/* ----------------------------------------------------------------------------- + * runtime class manipulation + * ----------------------------------------------------------------------------- */ + +#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)) +/* Set of functions that allow manipulating class bindings from C/C++ and from lua + */ + +SWIGINTERN bool +SWIG_Lua_metaclass_add_table(lua_State *L, int metatable_index, const char *class_name, const char *metatable_name, + const char *metaclass_name) +{ + /* Table to add new field must be on to of the stack */ + assert(lua_istable(L,-1)); + lua_pushstring(L,metaclass_name); + lua_pushvalue(L,metatable_index); + lua_pushstring(L,metatable_name); + lua_rawget(L,-2); + if(!lua_istable(L,-1)) { + SWIG_Lua_pushferrstring(L,"Class %s metatable is corrupt. Table %s is missing or not a table", class_name, metatable_name); + return false; + } + lua_rawset(L,-2); + return true; +} + +SWIGRUNTIME int +SWIG_Lua_get_class_metaclass(lua_State *L) +{ + /* One argument: + * - SWIG name of class as string + * - or instance of class + * - or class entry point in module + * metaclass( "MyClass" ) + * metaclass( myvar_of_type_MyClass_int_double ) + * metaclass( module.MyClass_int_double ) + */ + const char *class_name = 0; + int metatable_index = 0; + int static_metatable_index = 0; + int static_table_index = 0; + int answer_index = 0; + SWIG_check_num_args("SWIG_Lua_metaclass", 1, 1); + lua_checkstack(L,15); + if(lua_type(L,1) == LUA_TSTRING) { // class name is given + class_name = lua_tostring(L,1); + SWIG_Lua_get_class_registry(L); /* get the registry */ + assert(lua_istable(L,-1)); + lua_pushvalue(L,1); + lua_rawget(L,-2); /* get class metatable */ + if(!lua_istable(L,-1)) { + SWIG_Lua_pushferrstring(L,"There is no registered class with name %s", class_name ); + SWIG_fail + } + metatable_index = lua_gettop(L); + } else if(lua_isuserdata(L,1)) { // class instance is given + /* We don't check that class is registered in SWIG because it can be user-created-in-lua class */ + lua_getmetatable(L,1); + if(!lua_istable(L,-1)) { + SWIG_Lua_pushferrstring(L,"Userdata is passed, but it is not SWIG-wrapped class. There is no metatable."); + SWIG_fail; + } + metatable_index = lua_gettop(L); + lua_getfield(L,-1,".type"); + if(lua_type(L,-1) != LUA_TSTRING) { + SWIG_Lua_pushferrstring(L,"Userdata is passed, but it is not SWIG-wrapped class. Metatable has different structure."); + SWIG_fail; + } + class_name = lua_tostring(L,-1); + } else { // class entry is given. Well, it is supposed to be a class entry :) + lua_getmetatable(L,1); /* get metatable */ + if(!lua_istable(L,-1)) { + SWIG_Lua_pushferrstring(L, "Table is passed but it is not SWIG class entry point. There is no metatable"); + SWIG_fail; + } + lua_getfield(L,-1, ".instance"); /* get class metatable */ + if(lua_isnil(L,-1)) { + SWIG_Lua_pushferrstring(L, "Table is passed but it is not SWIG class entry point. Metatable has different structure."); + SWIG_fail; + } + metatable_index = lua_gettop(L); + lua_getfield(L,-1,".type"); + if(lua_type(L,-1) != LUA_TSTRING) { + SWIG_Lua_pushferrstring(L,"Userdata is passed, but it is not SWIG-wrapped class. Metatable has different structure."); + SWIG_fail; + } + class_name = lua_tostring(L,-1); + } + + /* Get static table */ + lua_getfield(L,metatable_index,".static"); + assert(!lua_isnil(L,-1)); + static_table_index = lua_gettop(L); + /* Get static metatable */ + lua_getmetatable(L,-1); + assert(!lua_isnil(L,-1)); + static_metatable_index = lua_gettop(L); + /* This will be our answer */ + lua_newtable(L); + answer_index = lua_gettop(L); + /* Adding instance member manipulators + * .bases can't be edited + */ + if(!SWIG_Lua_metaclass_add_table(L,metatable_index,class_name, ".fn", "methods") ) + SWIG_fail; + if(!SWIG_Lua_metaclass_add_table(L,metatable_index,class_name, ".get", "getters") ) + SWIG_fail; + if(!SWIG_Lua_metaclass_add_table(L,metatable_index,class_name, ".set", "setters") ) + SWIG_fail; + /* Adding static members manipulators */ + if(!SWIG_Lua_metaclass_add_table(L,static_metatable_index,class_name, ".get", "static_getters") ) + SWIG_fail; + if(!SWIG_Lua_metaclass_add_table(L,static_metatable_index,class_name, ".set", "static_setters") ) + SWIG_fail; + lua_pushstring(L, "static_methods"); + lua_pushvalue(L, static_table_index); + lua_rawset(L,-3); + + lua_pushstring(L, "static_constants"); + lua_pushvalue(L, static_table_index); + lua_rawset(L,-3); + + assert(lua_gettop(L) == answer_index); + return 1; + +fail: + lua_error(L); + return 0; +} + +/* Creates new class in lua. Must inherit existing SWIG class */ +SWIGRUNTIME int +SWIG_Lua_new_class(lua_State *L) { + SWIG_check_num_args("SWIG_Lua_new_class", 1, 1); + return 0; + +fail: + lua_error(L); + return 0; + +} +#endif + /* ------------------------------ end luarun.swg ------------------------------ */ diff --git a/Lib/lua/luaruntime.swg b/Lib/lua/luaruntime.swg index 0011c9d52..f510a0832 100644 --- a/Lib/lua/luaruntime.swg +++ b/Lib/lua/luaruntime.swg @@ -40,6 +40,8 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */ /* add a global fn */ SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type); SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_equal); + SWIG_Lua_add_function(L,"swig_new_class",SWIG_Lua_new_class); + SWIG_Lua_add_function(L,"swig_metaclass",SWIG_Lua_get_class_metaclass); #endif #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 413c30b32..3e976c373 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -393,6 +393,8 @@ public: /* Get the module name */ module = Getattr(n, "name"); + /* Some global settings */ + director_language = 1; /* Get the output file name */ String *outfile = Getattr(n, "outfile"); @@ -1767,6 +1769,467 @@ public: return SWIG_OK; } +#if 0 + virtual int classDirectorMethod(Node *n, Node *parent, String *super) { + int is_void = 0; + int is_pointer = 0; + String *decl = Getattr(n, "decl"); + String *name = Getattr(n, "name"); + String *classname = Getattr(parent, "sym:name"); + String *c_classname = Getattr(parent, "name"); + String *symname = Getattr(n, "sym:name"); + String *declaration = NewString(""); + ParmList *l = Getattr(n, "parms"); + Wrapper *w = NewWrapper(); + String *tm; + String *wrap_args = NewString(""); + String *returntype = Getattr(n, "type"); + String *value = Getattr(n, "value"); + String *storage = Getattr(n, "storage"); + bool pure_virtual = false; + int status = SWIG_OK; + int idx; + bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; + + if (Cmp(storage, "virtual") == 0) { + if (Cmp(value, "0") == 0) { + pure_virtual = true; + } + } + + /* determine if the method returns a pointer */ + is_pointer = SwigType_ispointer_return(decl); + is_void = (!Cmp(returntype, "void") && !is_pointer); + + /* virtual method definition */ + String *target; + String *pclassname = NewStringf("SwigDirector_%s", classname); + String *qualified_name = NewStringf("%s::%s", pclassname, name); + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type"); + target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); + Printf(w->def, "%s", target); + Delete(qualified_name); + Delete(target); + /* header declaration */ + target = Swig_method_decl(rtype, decl, name, l, 0, 1); + Printf(declaration, " virtual %s", target); + Delete(target); + + // Get any exception classes in the throws typemap + ParmList *throw_parm_list = 0; + + if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) { + Parm *p; + int gencomma = 0; + + Append(w->def, " throw("); + Append(declaration, " throw("); + + if (throw_parm_list) + Swig_typemap_attach_parms("throws", throw_parm_list, 0); + for (p = throw_parm_list; p; p = nextSibling(p)) { + if (Getattr(p, "tmap:throws")) { + if (gencomma++) { + Append(w->def, ", "); + Append(declaration, ", "); + } + String *str = SwigType_str(Getattr(p, "type"), 0); + Append(w->def, str); + Append(declaration, str); + Delete(str); + } + } + + Append(w->def, ")"); + Append(declaration, ")"); + } + + Append(w->def, " {"); + Append(declaration, ";\n"); + + /* declare method return value + * if the return value is a reference or const reference, a specialized typemap must + * handle it, including declaration of c_result ($result). + */ + if (!is_void) { + if (!(ignored_method && !pure_virtual)) { + String *cres = SwigType_lstr(returntype, "c_result"); + Printf(w->code, "%s;\n", cres); + Delete(cres); + } + } + + if (builtin) { + Printv(w->code, "PyObject *self = NULL;\n", NIL); + Printv(w->code, "(void)self;\n", NIL); + } + + if (ignored_method) { + if (!pure_virtual) { + if (!is_void) + Printf(w->code, "return "); + String *super_call = Swig_method_call(super, l); + Printf(w->code, "%s;\n", super_call); + Delete(super_call); + } else { + Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), + SwigType_namestr(name)); + } + } else { + /* attach typemaps to arguments (C/C++ -> Python) */ + String *arglist = NewString(""); + String *parse_args = NewString(""); + + Swig_director_parms_fixup(l); + + /* remove the wrapper 'w' since it was producing spurious temps */ + Swig_typemap_attach_parms("in", l, 0); + Swig_typemap_attach_parms("directorin", l, 0); + Swig_typemap_attach_parms("directorargout", l, w); + + Parm *p; + char source[256]; + + int outputs = 0; + if (!is_void) + outputs++; + + /* build argument list and type conversion string */ + idx = 0; + p = l; + int use_parse = 0; + while (p) { + if (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); + continue; + } + + /* old style? caused segfaults without the p!=0 check + in the for() condition, and seems dangerous in the + while loop as well. + while (Getattr(p, "tmap:ignore")) { + p = Getattr(p, "tmap:ignore:next"); + } + */ + + if (Getattr(p, "tmap:directorargout") != 0) + outputs++; + + String *pname = Getattr(p, "name"); + String *ptype = Getattr(p, "type"); + + Putc(',', arglist); + if ((tm = Getattr(p, "tmap:directorin")) != 0) { + String *parse = Getattr(p, "tmap:directorin:parse"); + if (!parse) { + sprintf(source, "obj%d", idx++); + String *input = NewString(source); + Setattr(p, "emit:directorinput", input); + Replaceall(tm, "$input", input); + Delete(input); + Replaceall(tm, "$owner", "0"); + /* Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); */ + Printv(wrap_args, "swig::SwigVar_PyObject ", source, ";\n", NIL); + + Printv(wrap_args, tm, "\n", NIL); + Printv(arglist, "(PyObject *)", source, NIL); + Putc('O', parse_args); + } else { + use_parse = 1; + Append(parse_args, parse); + Setattr(p, "emit:directorinput", pname); + Replaceall(tm, "$input", pname); + Replaceall(tm, "$owner", "0"); + if (Len(tm) == 0) + Append(tm, pname); + Append(arglist, tm); + } + p = Getattr(p, "tmap:directorin:next"); + continue; + } else if (Cmp(ptype, "void")) { + /* special handling for pointers to other C++ director classes. + * ideally this would be left to a typemap, but there is currently no + * way to selectively apply the dynamic_cast<> to classes that have + * directors. in other words, the type "SwigDirector_$1_lname" only exists + * for classes with directors. we avoid the problem here by checking + * module.wrap::directormap, but it's not clear how to get a typemap to + * do something similar. perhaps a new default typemap (in addition + * to SWIGTYPE) called DIRECTORTYPE? + */ + if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) { + Node *module = Getattr(parent, "module"); + Node *target = Swig_directormap(module, ptype); + sprintf(source, "obj%d", idx++); + String *nonconst = 0; + /* strip pointer/reference --- should move to Swig/stype.c */ + String *nptype = NewString(Char(ptype) + 2); + /* name as pointer */ + String *ppname = Copy(pname); + if (SwigType_isreference(ptype)) { + Insert(ppname, 0, "&"); + } + /* if necessary, cast away const since Python doesn't support it! */ + if (SwigType_isconst(nptype)) { + nonconst = NewStringf("nc_tmp_%s", pname); + String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname); + Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); + Delete(nonconst_i); + Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, + "Target language argument '%s' discards const in director method %s::%s.\n", + SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name)); + } else { + nonconst = Copy(ppname); + } + Delete(nptype); + Delete(ppname); + String *mangle = SwigType_manglestr(ptype); + if (target) { + String *director = NewStringf("director_%s", mangle); + Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL); + Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); + Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst); + Printf(wrap_args, "if (!%s) {\n", director); + Printf(wrap_args, "%s = SWIG_InternalNewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); + Append(wrap_args, "} else {\n"); + Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director); + Printf(wrap_args, "Py_INCREF((PyObject *)%s);\n", source); + Append(wrap_args, "}\n"); + Delete(director); + Printv(arglist, source, NIL); + } else { + Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); + Printf(wrap_args, "%s = SWIG_InternalNewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); + //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n", + // source, nonconst, base); + Printv(arglist, source, NIL); + } + Putc('O', parse_args); + Delete(mangle); + Delete(nonconst); + } else { + Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, + "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0), + SwigType_namestr(c_classname), SwigType_namestr(name)); + status = SWIG_NOWRAP; + break; + } + } + p = nextSibling(p); + } + + /* add the method name as a PyString */ + String *pyname = Getattr(n, "sym:name"); + + int allow_thread = threads_enable(n); + + if (allow_thread) { + thread_begin_block(n, w->code); + Append(w->code, "{\n"); + } + + /* wrap complex arguments to PyObjects */ + Printv(w->code, wrap_args, NIL); + + /* pass the method call on to the Python object */ + if (dirprot_mode() && !is_public(n)) { + Printf(w->code, "swig_set_inner(\"%s\", true);\n", name); + } + + + Append(w->code, "if (!swig_get_self()) {\n"); + Printf(w->code, " Swig::DirectorException::raise(\"'self' uninitialized, maybe you forgot to call %s.__init__.\");\n", classname); + Append(w->code, "}\n"); + Append(w->code, "#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n"); + Printf(w->code, "const size_t swig_method_index = %d;\n", director_method_index++); + Printf(w->code, "const char * const swig_method_name = \"%s\";\n", pyname); + + Append(w->code, "PyObject* method = swig_get_method(swig_method_index, swig_method_name);\n"); + if (Len(parse_args) > 0) { + if (use_parse || !modernargs) { + Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", Swig_cresult_name(), parse_args, arglist); + } else { + Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallFunctionObjArgs(method %s, NULL);\n", Swig_cresult_name(), arglist); + } + } else { + if (modernargs) { + Append(w->code, "swig::SwigVar_PyObject args = PyTuple_New(0);\n"); + Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_Call(method, (PyObject*) args, NULL);\n", Swig_cresult_name()); + } else { + Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallFunction(method, NULL, NULL);\n", Swig_cresult_name()); + } + } + Append(w->code, "#else\n"); + if (Len(parse_args) > 0) { + if (use_parse || !modernargs) { + Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n", Swig_cresult_name(), pyname, parse_args, arglist); + } else { + Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname); + Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", Swig_cresult_name(), arglist); + } + } else { + if (!modernargs) { + Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", Swig_cresult_name(), pyname); + } else { + Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname); + Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n", Swig_cresult_name()); + } + } + Append(w->code, "#endif\n"); + + if (dirprot_mode() && !is_public(n)) + Printf(w->code, "swig_set_inner(\"%s\", false);\n", name); + + /* exception handling */ + tm = Swig_typemap_lookup("director:except", n, Swig_cresult_name(), 0); + if (!tm) { + tm = Getattr(n, "feature:director:except"); + if (tm) + tm = Copy(tm); + } + Printf(w->code, "if (!%s) {\n", Swig_cresult_name()); + 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) {\n"); + Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n", classname, pyname); + Append(w->code, " }\n"); + } + Append(w->code, "}\n"); + Delete(tm); + + /* + * Python method may return a simple object, or a tuple. + * for in/out aruments, we have to extract the appropriate PyObjects from the tuple, + * then marshal everything back to C/C++ (return value and output arguments). + * + */ + + /* marshal return value and other outputs (if any) from PyObject to C/C++ type */ + + String *cleanup = NewString(""); + String *outarg = NewString(""); + + if (outputs > 1) { + Wrapper_add_local(w, "output", "PyObject *output"); + Printf(w->code, "if (!PyTuple_Check(%s)) {\n", Swig_cresult_name()); + Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", classname, pyname); + Append(w->code, "}\n"); + } + + idx = 0; + + /* marshal return value */ + if (!is_void) { + tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); + if (tm != 0) { + if (outputs > 1) { + Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++); + Replaceall(tm, "$input", "output"); + } else { + Replaceall(tm, "$input", Swig_cresult_name()); + } + char temp[24]; + sprintf(temp, "%d", idx); + Replaceall(tm, "$argnum", temp); + + /* TODO check this */ + if (Getattr(n, "wrap:disown")) { + Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); + } else { + Replaceall(tm, "$disown", "0"); + } + if (Getattr(n, "tmap:directorout:implicitconv")) { + Replaceall(tm, "$implicitconv", get_implicitconv_flag(n)); + } + Replaceall(tm, "$result", "c_result"); + Printv(w->code, tm, "\n", NIL); + Delete(tm); + } else { + Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, + "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname), + SwigType_namestr(name)); + status = SWIG_ERROR; + } + } + + /* marshal outputs */ + for (p = l; p;) { + if ((tm = Getattr(p, "tmap:directorargout")) != 0) { + if (outputs > 1) { + Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++); + Replaceall(tm, "$result", "output"); + } else { + Replaceall(tm, "$result", Swig_cresult_name()); + } + Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); + Printv(w->code, tm, "\n", NIL); + p = Getattr(p, "tmap:directorargout:next"); + } else { + p = nextSibling(p); + } + } + + /* any existing helper functions to handle this? */ + if (allow_thread) { + Append(w->code, "}\n"); + thread_end_block(n, w->code); + } + + Delete(parse_args); + Delete(arglist); + Delete(cleanup); + Delete(outarg); + } + + if (!is_void) { + if (!(ignored_method && !pure_virtual)) { + String *rettype = SwigType_str(returntype, 0); + if (!SwigType_isreference(returntype)) { + Printf(w->code, "return (%s) c_result;\n", rettype); + } else { + Printf(w->code, "return (%s) *c_result;\n", rettype); + } + Delete(rettype); + } + } + + Append(w->code, "}\n"); + + // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method + String *inline_extra_method = NewString(""); + if (dirprot_mode() && !is_public(n) && !pure_virtual) { + Printv(inline_extra_method, declaration, NIL); + String *extra_method_name = NewStringf("%sSwigPublic", name); + Replaceall(inline_extra_method, name, extra_method_name); + Replaceall(inline_extra_method, ";\n", " {\n "); + if (!is_void) + Printf(inline_extra_method, "return "); + String *methodcall = Swig_method_call(super, l); + Printv(inline_extra_method, methodcall, ";\n }\n", NIL); + Delete(methodcall); + Delete(extra_method_name); + } + + /* emit the director method */ + if (status == SWIG_OK) { + if (!Getattr(n, "defaultargs")) { + Replaceall(w->code, "$symname", symname); + Wrapper_print(w, f_directors); + Printv(f_directors_h, declaration, NIL); + Printv(f_directors_h, inline_extra_method, NIL); + } + } + + /* clean up */ + Delete(wrap_args); + Delete(pclassname); + DelWrapper(w); + return status; + } +#endif + /* TODO: REMOVE virtual int namespaceDeclaration(Node *n) { // Register namespace From aa1b8298cac25867995e97d8d7d5116d63ba0d62 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Thu, 7 Nov 2013 18:56:34 +0400 Subject: [PATCH 0975/1160] Preparations before pull request - part 1 --- Lib/lua/luarun.swg | 320 +-------------- Lib/lua/luaruntime.swg | 2 - Source/Modules/lua.cxx | 901 ++++------------------------------------- 3 files changed, 79 insertions(+), 1144 deletions(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index c398c7925..764ec5fe4 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -129,12 +129,6 @@ typedef struct { swig_type_info **ptype; } swig_lua_const_info; -/* TODO:REMOVE -typedef struct { - const char *name; - lua_CFunction method; -} swig_lua_method; -*/ typedef luaL_Reg swig_lua_method; typedef struct { @@ -164,7 +158,7 @@ struct swig_lua_class { void (*destructor)(void *); swig_lua_method *methods; swig_lua_attribute *attributes; - swig_lua_namespace cls_static; + swig_lua_namespace *cls_static; struct swig_lua_class **bases; const char **base_names; }; @@ -274,167 +268,8 @@ SWIGINTERN int SWIG_Lua_set_immutable(lua_State* L) return 0; /* should not return anything */ } -/* the module.get method used for getting linked data */ -SWIGINTERN int SWIG_Lua_module_get(lua_State* L) -{ -/* there should be 2 params passed in - (1) table (not the meta table) - (2) string name of the attribute - printf("SWIG_Lua_module_get %p(%s) '%s'\n", - lua_topointer(L,1),lua_typename(L,lua_type(L,1)), - lua_tostring(L,2)); -*/ - /* get the metatable */ -#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)) - assert(lua_isrotable(L,1)); /* just in case */ -#else - assert(lua_istable(L,1)); /* default Lua action */ -#endif - lua_getmetatable(L,1); /* get the metatable */ -#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)) - assert(lua_isrotable(L,-1)); /* just in case */ -#else - assert(lua_istable(L,-1)); -#endif - SWIG_Lua_get_table(L,".get"); /* get the .get table */ - lua_remove(L,3); /* remove metatable */ -#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)) - if (lua_isrotable(L,-1)) -#else - if (lua_istable(L,-1)) -#endif - { - /* look for the key in the .get table */ - lua_pushvalue(L,2); /* key */ - lua_rawget(L,-2); - lua_remove(L,3); /* remove .get */ - if (lua_iscfunction(L,-1)) - { /* found it so call the fn & return its value */ - lua_call(L,0,1); - return 1; - } - lua_pop(L,1); /* remove the top */ - } - lua_pop(L,1); /* remove the .get */ - lua_pushnil(L); /* return a nil */ - return 1; -} - -/* the module.set method used for setting linked data */ -SWIGINTERN int SWIG_Lua_module_set(lua_State* L) -{ -/* there should be 3 params passed in - (1) table (not the meta table) - (2) string name of the attribute - (3) any for the new value -*/ - /* get the metatable */ -#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)) - assert(lua_isrotable(L,1)); /* just in case */ -#else - assert(lua_istable(L,1)); /* default Lua action */ -#endif - lua_getmetatable(L,1); /* get the metatable */ -#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)) - assert(lua_isrotable(L,-1)); /* just in case */ -#else - assert(lua_istable(L,-1)); -#endif - SWIG_Lua_get_table(L,".set"); /* get the .set table */ - lua_remove(L,4); /* remove metatable */ -#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)) - if (lua_isrotable(L,-1)) -#else - if (lua_istable(L,-1)) -#endif - { - /* look for the key in the .set table */ - lua_pushvalue(L,2); /* key */ - lua_rawget(L,-2); - lua_remove(L,4); /* remove .set */ - if (lua_iscfunction(L,-1)) - { /* found it so call the fn & return its value */ - lua_pushvalue(L,3); /* value */ - lua_call(L,1,0); - return 0; - } -#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) - else { - return 0; // Exits stoically if an invalid key is initialized. - } -#endif - } - lua_settop(L,3); /* reset back to start */ - /* we now have the table, key & new value, so just set directly */ - lua_rawset(L,1); /* add direct */ - return 0; -} - -#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)) -/* registering a module in lua. Pushes the module table on the stack. */ -SWIGINTERN void SWIG_Lua_module_begin(lua_State* L,const char* name) -{ - assert(lua_istable(L,-1)); /* just in case */ - lua_pushstring(L,name); - lua_newtable(L); /* the table */ - /* add meta table */ - lua_newtable(L); /* the meta table */ - SWIG_Lua_add_function(L,"__index",SWIG_Lua_module_get); - SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_module_set); - lua_pushstring(L,".get"); - lua_newtable(L); /* the .get table */ - lua_rawset(L,-3); /* add .get into metatable */ - lua_pushstring(L,".set"); - lua_newtable(L); /* the .set table */ - lua_rawset(L,-3); /* add .set into metatable */ - lua_setmetatable(L,-2); /* sets meta table in module */ -#ifdef SWIG_LUA_MODULE_GLOBAL - /* If requested, install the module directly into the global namespace. */ - lua_rawset(L,-3); /* add module into parent */ - SWIG_Lua_get_table(L,name); /* get the table back out */ -#else - /* Do not install the module table as global name. The stack top has - the module table with the name below. We pop the top and replace - the name with it. */ - lua_replace(L,-2); -#endif -} - -/* ending the register */ -SWIGINTERN void SWIG_Lua_module_end(lua_State* L) -{ - lua_pop(L,1); /* tidy stack (remove module) */ -} - -/* adding a linked variable to the module */ -SWIGINTERN void SWIG_Lua_module_add_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn) -{ - assert(lua_istable(L,-1)); /* just in case */ - lua_getmetatable(L,-1); /* get the metatable */ - assert(lua_istable(L,-1)); /* just in case */ - SWIG_Lua_get_table(L,".get"); /* find the .get table */ - assert(lua_istable(L,-1)); /* should be a table: */ - SWIG_Lua_add_function(L,name,getFn); - lua_pop(L,1); /* tidy stack (remove table) */ - if (setFn) /* if there is a set fn */ - { - SWIG_Lua_get_table(L,".set"); /* find the .set table */ - assert(lua_istable(L,-1)); /* should be a table: */ - SWIG_Lua_add_function(L,name,setFn); - lua_pop(L,1); /* tidy stack (remove table) */ - } - lua_pop(L,1); /* tidy stack (remove meta) */ -} -#endif - -/* adding a function module */ -SWIGINTERN void SWIG_Lua_module_add_function(lua_State* L,const char* name,lua_CFunction fn) -{ - SWIG_Lua_add_function(L,name,fn); -} - /* ----------------------------------------------------------------------------- - * global variable support code: namespaces + * global variable support code: namespaces and modules (which are the same thing) * ----------------------------------------------------------------------------- */ SWIGINTERN int SWIG_Lua_namespace_get(lua_State* L) @@ -959,7 +794,7 @@ SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State* L, swig_lua_class* SWIG_Lua_add_class_static_details(L,clss->bases[i]); } - SWIG_Lua_add_namespace_details(L, &clss->cls_static); + SWIG_Lua_add_namespace_details(L, clss->cls_static); } /* helper to recursively add class details (attributes & operations) */ @@ -1030,9 +865,9 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* cls int begin = lua_gettop(L); lua_checkstack(L,5); /* just in case */ assert(lua_istable(L,-1)); /* just in case */ - assert(strcmp(clss->name, clss->cls_static.name) == 0); /* in class those 2 must be equal */ + assert(strcmp(clss->name, clss->cls_static->name) == 0); /* in class those 2 must be equal */ - SWIG_Lua_namespace_register(L,&clss->cls_static, true); + SWIG_Lua_namespace_register(L,clss->cls_static, true); assert(lua_istable(L,-1)); /* just in case */ @@ -1138,7 +973,7 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss) * |=============================== ".instance" */ int begin = lua_gettop(L); - lua_pushstring(L,clss->cls_static.name); + lua_pushstring(L,clss->cls_static->name); lua_rawget(L,-2); /* get class static table */ assert(lua_istable(L,-1)); lua_getmetatable(L,-1); @@ -1380,147 +1215,4 @@ SWIG_Lua_dostring(lua_State *L, const char* str) { } #endif -/* ----------------------------------------------------------------------------- - * runtime class manipulation - * ----------------------------------------------------------------------------- */ - -#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)) -/* Set of functions that allow manipulating class bindings from C/C++ and from lua - */ - -SWIGINTERN bool -SWIG_Lua_metaclass_add_table(lua_State *L, int metatable_index, const char *class_name, const char *metatable_name, - const char *metaclass_name) -{ - /* Table to add new field must be on to of the stack */ - assert(lua_istable(L,-1)); - lua_pushstring(L,metaclass_name); - lua_pushvalue(L,metatable_index); - lua_pushstring(L,metatable_name); - lua_rawget(L,-2); - if(!lua_istable(L,-1)) { - SWIG_Lua_pushferrstring(L,"Class %s metatable is corrupt. Table %s is missing or not a table", class_name, metatable_name); - return false; - } - lua_rawset(L,-2); - return true; -} - -SWIGRUNTIME int -SWIG_Lua_get_class_metaclass(lua_State *L) -{ - /* One argument: - * - SWIG name of class as string - * - or instance of class - * - or class entry point in module - * metaclass( "MyClass" ) - * metaclass( myvar_of_type_MyClass_int_double ) - * metaclass( module.MyClass_int_double ) - */ - const char *class_name = 0; - int metatable_index = 0; - int static_metatable_index = 0; - int static_table_index = 0; - int answer_index = 0; - SWIG_check_num_args("SWIG_Lua_metaclass", 1, 1); - lua_checkstack(L,15); - if(lua_type(L,1) == LUA_TSTRING) { // class name is given - class_name = lua_tostring(L,1); - SWIG_Lua_get_class_registry(L); /* get the registry */ - assert(lua_istable(L,-1)); - lua_pushvalue(L,1); - lua_rawget(L,-2); /* get class metatable */ - if(!lua_istable(L,-1)) { - SWIG_Lua_pushferrstring(L,"There is no registered class with name %s", class_name ); - SWIG_fail - } - metatable_index = lua_gettop(L); - } else if(lua_isuserdata(L,1)) { // class instance is given - /* We don't check that class is registered in SWIG because it can be user-created-in-lua class */ - lua_getmetatable(L,1); - if(!lua_istable(L,-1)) { - SWIG_Lua_pushferrstring(L,"Userdata is passed, but it is not SWIG-wrapped class. There is no metatable."); - SWIG_fail; - } - metatable_index = lua_gettop(L); - lua_getfield(L,-1,".type"); - if(lua_type(L,-1) != LUA_TSTRING) { - SWIG_Lua_pushferrstring(L,"Userdata is passed, but it is not SWIG-wrapped class. Metatable has different structure."); - SWIG_fail; - } - class_name = lua_tostring(L,-1); - } else { // class entry is given. Well, it is supposed to be a class entry :) - lua_getmetatable(L,1); /* get metatable */ - if(!lua_istable(L,-1)) { - SWIG_Lua_pushferrstring(L, "Table is passed but it is not SWIG class entry point. There is no metatable"); - SWIG_fail; - } - lua_getfield(L,-1, ".instance"); /* get class metatable */ - if(lua_isnil(L,-1)) { - SWIG_Lua_pushferrstring(L, "Table is passed but it is not SWIG class entry point. Metatable has different structure."); - SWIG_fail; - } - metatable_index = lua_gettop(L); - lua_getfield(L,-1,".type"); - if(lua_type(L,-1) != LUA_TSTRING) { - SWIG_Lua_pushferrstring(L,"Userdata is passed, but it is not SWIG-wrapped class. Metatable has different structure."); - SWIG_fail; - } - class_name = lua_tostring(L,-1); - } - - /* Get static table */ - lua_getfield(L,metatable_index,".static"); - assert(!lua_isnil(L,-1)); - static_table_index = lua_gettop(L); - /* Get static metatable */ - lua_getmetatable(L,-1); - assert(!lua_isnil(L,-1)); - static_metatable_index = lua_gettop(L); - /* This will be our answer */ - lua_newtable(L); - answer_index = lua_gettop(L); - /* Adding instance member manipulators - * .bases can't be edited - */ - if(!SWIG_Lua_metaclass_add_table(L,metatable_index,class_name, ".fn", "methods") ) - SWIG_fail; - if(!SWIG_Lua_metaclass_add_table(L,metatable_index,class_name, ".get", "getters") ) - SWIG_fail; - if(!SWIG_Lua_metaclass_add_table(L,metatable_index,class_name, ".set", "setters") ) - SWIG_fail; - /* Adding static members manipulators */ - if(!SWIG_Lua_metaclass_add_table(L,static_metatable_index,class_name, ".get", "static_getters") ) - SWIG_fail; - if(!SWIG_Lua_metaclass_add_table(L,static_metatable_index,class_name, ".set", "static_setters") ) - SWIG_fail; - lua_pushstring(L, "static_methods"); - lua_pushvalue(L, static_table_index); - lua_rawset(L,-3); - - lua_pushstring(L, "static_constants"); - lua_pushvalue(L, static_table_index); - lua_rawset(L,-3); - - assert(lua_gettop(L) == answer_index); - return 1; - -fail: - lua_error(L); - return 0; -} - -/* Creates new class in lua. Must inherit existing SWIG class */ -SWIGRUNTIME int -SWIG_Lua_new_class(lua_State *L) { - SWIG_check_num_args("SWIG_Lua_new_class", 1, 1); - return 0; - -fail: - lua_error(L); - return 0; - -} -#endif - /* ------------------------------ end luarun.swg ------------------------------ */ diff --git a/Lib/lua/luaruntime.swg b/Lib/lua/luaruntime.swg index f510a0832..0011c9d52 100644 --- a/Lib/lua/luaruntime.swg +++ b/Lib/lua/luaruntime.swg @@ -40,8 +40,6 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */ /* add a global fn */ SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type); SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_equal); - SWIG_Lua_add_function(L,"swig_new_class",SWIG_Lua_new_class); - SWIG_Lua_add_function(L,"swig_metaclass",SWIG_Lua_get_class_metaclass); #endif #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 3e976c373..c719bad66 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -73,57 +73,6 @@ void display_mapping(DOH *d) { } } -// Holds the pointer. Call's Delete in destructor, assignment etc -// TODO: REVIEW -// Class won't work, TODO: REMOVE -template // T is ignored because everything is DOH* -class DohPointer { - public: - /* - DohPointer( DOH* _ptr ): - p_ptr(_ptr) - { - assert( p_ptr != 0 ); - } - */ - DohPointer(): - p_ptr(0) {} - - DohPointer( const DohPointer& rhs ) { - AttachExisting( rhs.p_ptr ); - } - - const DohPointer& operator=( const DohPointer& rhs ) { - AttachExisting(rhs.p_ptr); - } - - DOH* ptr() { return p_ptr; } - const DOH* ptr() const { return p_ptr; } - operator DOH* () { return p_ptr; } - operator DOH* () const { return p_ptr; } - - // Attaches existing pointer. Refcount will be increased - void AttachExisting( DOH* obj ) { - AttachNew(obj); - if( p_ptr != 0 ) - DohIncref(p_ptr); - } - - // Attaches new pointer. As refcount is set to 1 at the creation, it won't be - // increased - void AttachNew( DOH *obj ) { - DOH* old_ptr = p_ptr; - p_ptr = obj; - if( old_ptr != 0 ) - Delete(old_ptr); - } - - private: - DOH* p_ptr; -}; - -#define Pointer DohPointer - template // T is ignored because everything is DOH* class DohPtrGuard { public: @@ -223,21 +172,12 @@ private: File *f_runtime; File *f_header; File *f_wrappers; - File *f_wrappersForward; // forward declarations for wrappers, TODO: REMOVE File *f_init; File *f_initbeforefunc; - /* - String *s_ns_methods_tab; // table of namespace methods - String *s_ns_var_tab; // Lua only:table of namespace variables - String *s_ns_dot_get; // eLua only:table of variable 'get' functions - String *s_ns_dot_set; // eLua only:table of variable 'set' functions - String *s_ns_const_tab; // table of namespace constants - */ String *s_methods_tab; // table of class methods String *s_attr_tab; // table of class attributes String *s_luacode; // luacode to be called during init String *module; //name of the module - //String *s_vars_meta_tab; // metatable for variables Hash* namespaces_hash; // Parameters for current class. NIL if not parsing class @@ -261,7 +201,7 @@ private: CONSTRUCTOR, DESTRUCTOR, MEMBER_VAR, - CLASS_CONST, + CLASS_CONST, // TODO: What is this ? STATIC_FUNC, STATIC_VAR, STATIC_CONST, // enums and things like static const int x = 5; @@ -283,24 +223,12 @@ public: f_runtime(0), f_header(0), f_wrappers(0), - f_wrappersForward(0), f_init(0), f_initbeforefunc(0), - /* - s_cmd_tab(0), - s_var_tab(0), - s_const_tab(0), - s_cls_attr_tab(0), - s_cls_methods_tab(0), - s_cls_const_tab(0), - */ s_methods_tab(0), s_attr_tab(0), s_luacode(0), module(0), - //s_dot_get(0), - //s_dot_set(0), - //s_vars_meta_tab(0), have_constructor(0), have_destructor(0), destructor_action(0), @@ -407,7 +335,6 @@ public: f_runtime = NewString(""); f_init = NewString(""); f_header = NewString(""); - f_wrappersForward = NewString(""); f_wrappers = NewString(""); f_initbeforefunc = NewString(""); @@ -419,33 +346,11 @@ public: Swig_register_filebyname("init", f_init); Swig_register_filebyname("initbeforefunc", f_initbeforefunc); - /* NEW LANGUAGE NOTE:*********************************************** - s_cmd_tab,s_var_tab & s_const_tab hold the names of the fns for - registering with SWIG. - These will be filled in when the functions/variables are wrapped & - then added to the end of the wrappering code - just before it is written to file - NEW LANGUAGE NOTE:END ************************************************/ - // Initialize some variables for the object interface - // TODO: Replace with call to getNamespaceHash(0) - /* - s_cmd_tab = NewString(""); - s_var_tab = NewString(""); - // s_methods_tab = NewString(""); - s_const_tab = NewString(""); - - s_dot_get = NewString(""); - s_dot_set = NewString(""); - s_vars_meta_tab = NewString(""); - */ s_luacode = NewString(""); Swig_register_filebyname("luacode", s_luacode); current[NO_CPP] = true; - // Registering names schemes: TODO: REMOVE - //Swig_name_register("member", "%m"); - //Swig_name_register("construct", "new_%c"); /* Standard stuff for the SWIG runtime section */ Swig_banner(f_begin); @@ -477,34 +382,12 @@ public: Printf(f_header, "#define SWIG_init_user luaopen_%s_user\n\n", module); Printf(f_header, "#define SWIG_LUACODE luaopen_%s_luacode\n", module); - /* - if (elua_ltr || eluac_ltr) - Printf(f_header, "#define swig_commands %s_map\n\n", module); - */ - if (elua_ltr || eluac_ltr) { Printf(f_header, "\n#define MIN_OPT_LEVEL 2\n#include \"lrodefs.h\"\n"); Printf(f_header, "#include \"lrotable.h\"\n"); - //Printf(s_cmd_tab, "\nconst LUA_REG_TYPE swig_constants[];\n"); - /*if (elua_ltr) - Printf(s_cmd_tab, "const LUA_REG_TYPE mt[];\n");*/ - - //Printf(s_cmd_tab, "\nconst LUA_REG_TYPE swig_commands[] = {\n"); - //Printf(s_const_tab, "\nconst LUA_REG_TYPE swig_constants[] = {\n"); Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); - Printf(f_wrappersForward, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); - /*if (elua_ltr) { - Printf(s_dot_get, "\nconst LUA_REG_TYPE dot_get[] = {\n"); - Printf(s_dot_set, "\nconst LUA_REG_TYPE dot_set[] = {\n"); - }*/ } else { - /* - Printf(s_cmd_tab, "\nstatic const struct luaL_Reg swig_commands[] = {\n"); - Printf(s_var_tab, "\nstatic swig_lua_var_info swig_variables[] = {\n"); - Printf(s_const_tab, "\nstatic swig_lua_const_info swig_constants[] = {\n"); - */ Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); - Printf(f_wrappersForward, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); } /* %init code inclusion, effectively in the SWIG_init function */ @@ -514,46 +397,16 @@ public: Printf(f_init, "}\n"); Printf(f_wrappers, "#ifdef __cplusplus\n}\n#endif\n"); - Printf(f_wrappersForward, "#ifdef __cplusplus\n}\n#endif\n"); // Done. Close up the module & write to the wrappers -#if 0 - if (elua_ltr || eluac_ltr) { - Printv(s_cmd_tab, tab4, "{LSTRKEY(\"const\"), LROVAL(swig_constants)},\n", NIL); - if (elua_ltr) - Printv(s_cmd_tab, tab4, "{LSTRKEY(\"__metatable\"), LROVAL(mt)},\n", NIL); - Printv(s_cmd_tab, tab4, "{LNILKEY, LNILVAL}\n", "};\n", NIL); - Printv(s_const_tab, tab4, "{LNILKEY, LNILVAL}\n", "};\n", NIL); - } else { - Printv(s_cmd_tab, tab4, "{0,0}\n", "};\n", NIL); - Printv(s_var_tab, tab4, "{0,0,0}\n", "};\n", NIL); - Printv(s_const_tab, tab4, "{0,0,0,0,0,0}\n", "};\n", NIL); - } -#endif - -#if 0 - if (elua_ltr) { - /* Generate the metatable */ - Printf(s_vars_meta_tab, "\nconst LUA_REG_TYPE mt[] = {\n"); - Printv(s_vars_meta_tab, tab4, "{LSTRKEY(\"__index\"), LFUNCVAL(SWIG_Lua_module_get)},\n", NIL); - Printv(s_vars_meta_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_module_set)},\n", NIL); - Printv(s_vars_meta_tab, tab4, "{LSTRKEY(\".get\"), LROVAL(dot_get)},\n", NIL); - Printv(s_vars_meta_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(dot_set)},\n", NIL); - Printv(s_vars_meta_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); - - Printv(s_dot_get, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); - Printv(s_dot_set, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); - } -#endif if (elua_ltr || eluac_ltr) { /* Final close up of wrappers */ - //Printv(f_wrappers, s_cmd_tab, s_dot_get, s_dot_set, s_vars_meta_tab, s_var_tab, s_const_tab, NIL); - closeNamespaces(f_wrappers, f_wrappersForward); + closeNamespaces(f_wrappers, 0); // TODO: Remove last parameter SwigType_emit_type_table(f_runtime, f_wrappers); } else { //Printv(f_wrappers, s_cmd_tab, s_var_tab, s_const_tab, NIL); - closeNamespaces(f_wrappers, f_wrappersForward); + closeNamespaces(f_wrappers, 0); SwigType_emit_type_table(f_runtime, f_wrappers); } @@ -563,7 +416,6 @@ public: NEW LANGUAGE NOTE:END ************************************************/ Dump(f_runtime, f_begin); Dump(f_header, f_begin); - Dump(f_wrappersForward, f_begin); Dump(f_wrappers, f_begin); Dump(f_initbeforefunc, f_begin); /* for the Lua code it needs to be properly excaped to be added into the C/C++ code */ @@ -572,19 +424,12 @@ public: Wrapper_pretty_print(f_init, f_begin); /* Close all of the files */ Delete(s_luacode); - //Delete(s_cmd_tab); - //Delete(s_var_tab); - //Delete(s_const_tab); Delete(f_header); Delete(f_wrappers); - Delete(f_wrappersForward); Delete(f_init); Delete(f_initbeforefunc); Delete(f_runtime); Delete(f_begin); - //Delete(s_dot_get); - //Delete(s_dot_set); - //Delete(s_vars_meta_tab); /* Done */ return SWIG_OK; @@ -599,7 +444,7 @@ public: } virtual int cDeclaration(Node *n) { - // Language is messing with symname in a really heavy way. + // class 'Language' is messing with symname in a really heavy way. // Although documentation states that sym:name is a name in // the target language space, it is not true. sym:name and // it's derivatives are used in various places, including @@ -657,12 +502,10 @@ public: assert(target_name != 0); SwigType *d = Getattr(n, "type"); ParmList *l = Getattr(n, "parms"); - //Printf(stdout,"functionWrapper %s %s\n",name,iname); Parm *p; String *tm; int i; //Printf(stdout,"functionWrapper %s %s %d\n",name,iname,current); - // int returnval=0; // number of arguments returned String *overname = 0; if (Getattr(n, "sym:overloaded")) { @@ -691,7 +534,6 @@ public: Delete(constructor_name); constructor_name = Copy(wname); } - //Printf(stdout , "Function wrapper, name %s wrapname %s\n", iname, wname); // TODO:REMOVE /* NEW LANGUAGE NOTE:*********************************************** the format of a lua fn is: @@ -950,7 +792,6 @@ public: different language mappings seem to use different ideas NEW LANGUAGE NOTE:END ************************************************/ /* Now register the function with the interpreter. */ - //TODO: iname -> lua:name if (!Getattr(n, "sym:overloaded")) { if (current[NO_CPP] || current[STATIC_FUNC]) { // emit normal fns & static fns registerMethod(getNSpace(), n); @@ -967,7 +808,6 @@ public: Delete(cleanup); Delete(outarg); // Delete(description); - //Delete(wname); // TODO: Reference count seems not working DelWrapper(f); return SWIG_OK; @@ -989,7 +829,6 @@ public: //REPORT("dispatchFunction", n); /* Last node in overloaded chain */ - //Printf(stdout , "Dispatch, wrapname %s\n", Getattr(n,"wrap:name")); // TODO:REMOVE int maxargs; String *tmp = NewString(""); String *dispatch = Swig_overload_dispatch(n, "return %s(L);", &maxargs); @@ -1034,10 +873,7 @@ public: Printv(f->code, "}\n", NIL); Wrapper_print(f, f_wrappers); if (current[NO_CPP] || current[STATIC_FUNC]) { // emit normal fns & static fns - // TODO: elua_ltr ? - Hash* nspaceHash = getNamespaceHash( getNSpace() ); - String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); - Printv(s_ns_methods_tab, tab4, "{ \"", target_name, "\",", wname, "},\n", NIL); + registerMethod(getNSpace(), n); } if (current[CONSTRUCTOR]) { if( constructor_name != 0 ) @@ -1067,47 +903,13 @@ public: only WRT this variable will look into this later. NEW LANGUAGE NOTE:END ************************************************/ // REPORT("variableWrapper", n); - String *iname = Getattr(n, "sym:name"); String *target_name = Getattr(n, "lua:name"); assert(target_name != 0); current[VARIABLE] = true; // let SWIG generate the wrappers int result = Language::variableWrapper(n); current[VARIABLE] = false; - // 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 = Getattr(n,"varget:wrap:name"); - //String *setName = 0; - // checking whether it can be set to or not appears to be a very error prone issue - // I referred to the Language::variableWrapper() to find this out - // TODO: REMOVE? - /* - bool assignable=is_assignable(n) ? true : false; - SwigType *type = Getattr(n, "type"); - String *tm = Swig_typemap_lookup("globalin", n, iname, 0); - if (!tm && SwigType_isarray(type)) - assignable=false; - Delete(tm); - - if (assignable) { - setName = Getattr(n,"varset:wrap:name"); - } else { - // how about calling a 'this is not settable' error message? - setName = unassignable;// error message - }*/ - - // register the variable - //assert(setName != 0); - //assert(getName != 0); - // TODO: CHeck. It seems to register everything in namespaces - // What about class variables ? registerVariable( getNSpace(), n, "varget:wrap:name", "varset:wrap:name" ); - /*if (getCurrentClass()) { // TODO: REMOVE - Setattr(n, "luaclassobj:wrap:get", getName); - Setattr(n, "luaclassobj:wrap:set", setName); - } else { - Delete(unassignable); - }*/ return result; } @@ -1126,7 +928,6 @@ public: String *rawval = Getattr(n, "rawval"); String *value = rawval ? rawval : Getattr(n, "value"); String *tm; - //Printf( stdout, "Add constant %s, ns %s\n", iname, getNSpace() );// TODO: REMOVE if (!luaAddSymbol(target_name, n)) return SWIG_ERROR; @@ -1188,21 +989,6 @@ public: } } */ - /* TODO: Fix - if (cparse_cplusplus && getCurrentClass()) { - // Additionally add to class constants - Swig_require("luaclassobj_constantWrapper", n, "*sym:name", "luaclassobj:symname", NIL); - Setattr(n, "sym:name", Getattr(n, "luaclassobj:symname")); - String *cls_nsname = Getattr(n, "sym:name"); - if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) { - Replaceall(tm, "$source", value); - Replaceall(tm, "$target", name); - Replaceall(tm, "$value", value); - Replaceall(tm, "$nsname", cls_nsname); - Printf(s_cls_const_tab, " %s,\n", tm); - } - Swig_restore(n); - }*/ Swig_restore(n); Delete(nsname); return SWIG_OK; @@ -1216,7 +1002,6 @@ public: // REPORT("nativeWrapper", n); String *symname = Getattr(n, "sym:name"); String *wrapname = Getattr(n, "wrap:name"); - //String *target_name = Getattr(n, "lua:name"); TODO: REMOVE if (!luaAddSymbol(wrapname, n)) return SWIG_ERROR; @@ -1331,7 +1116,6 @@ public: fr_t = SwigType_strip_qualifiers(t_tmp); PtrGuard mangled_fr_t; mangled_fr_t = SwigType_manglestr(fr_t); - //Printf( stdout, "Mangled class symname %s fr type%s\n", mangled_class_fq_symname, mangled_fr_t ); // TODO: REMOVE // not sure exactly how this works, // but tcl has a static hashtable of all classes emitted and then only emits code for them once. // this fixes issues in test suites: template_default2 & template_specialization @@ -1343,7 +1127,6 @@ public: if (Getattr(emitted, mangled_fr_t)) { class_fq_symname = 0; class_symname = 0; - // TODO: Memory leak here return SWIG_NOWRAP; } Setattr(emitted, mangled_fr_t, "1"); @@ -1359,14 +1142,15 @@ public: // And we can guarantee that there will not be any name collision because names starting with 2 underscores // and capital letter are forbiden to use in C++. So, under know circumstances could our class contain // any member or subclass with name "__Static". Thus, never any name clash. - Hash* non_static_cls = getNamespaceHash(class_fq_symname, false); - assert(non_static_cls != 0); - s_attr_tab = Getattr(non_static_cls, "attributes"); - s_methods_tab = Getattr(non_static_cls, "methods"); - String* s_attr_tab_name = Getattr(non_static_cls, "attributes:name"); - String* s_methods_tab_name = Getattr(non_static_cls, "methods:name"); - Setattr(non_static_cls, "lua:no_namespaces", "1"); - Setattr(non_static_cls, "lua:no_classes", "1"); + Hash* instance_cls = getNamespaceHash(class_fq_symname, false); + assert(instance_cls != 0); + s_attr_tab = Getattr(instance_cls, "attributes"); + s_methods_tab = Getattr(instance_cls, "methods"); + String* s_attr_tab_name = Getattr(instance_cls, "attributes:name"); + String* s_methods_tab_name = Getattr(instance_cls, "methods:name"); + Setattr(instance_cls, "lua:no_namespaces", "1"); + Setattr(instance_cls, "lua:no_classes", "1"); + Setattr(instance_cls, "lua:class_instance", "1"); /* There is no use for "constants", "classes" and "namespaces" arrays. * All constants are considered part of static part of class. @@ -1376,22 +1160,17 @@ public: Hash *static_cls = getNamespaceHash(class_static_nspace, false); assert(static_cls != 0); Setattr(static_cls, "lua:no_namespaces", "1"); - /* TODO: REMOVE - s_cls_methods_tab = Getattr(static_cls, "methods"); - s_cls_attr_tab = Getattr(static_cls, "attributes"); - s_cls_const_tab = Getattr(static_cls, "constants"); - */ + Setattr(static_cls, "lua:class_static", "1"); + + // Notifying instance_cls and static_cls hashes about each other + Setattr(instance_cls, "lua:class_instance:static_hash", static_cls); + Setattr(static_cls, "lua:class_static:instance_hash", instance_cls); /* There is no use for "classes" and "namespaces" arrays. Subclasses are not supported * by SWIG and namespaces couldn't be nested inside classes (C++ Standard) */ assert(s_attr_tab != 0); assert(s_methods_tab != 0); - /* - assert(s_cls_methods_tab != 0); - assert(s_cls_attr_tab != 0); - assert(s_cls_const_tab != 0); - */ // Replacing namespace with namespace + class in order to static // member be put inside class static area @@ -1402,7 +1181,6 @@ public: // Restore correct nspace setNSpace(nspace); class_parent_nspace = 0; - //Printf( stdout, "Class finished\n" ); TODO:REMOVE SwigType_add_pointer(t); @@ -1422,7 +1200,6 @@ public: // Printf(f_init,"SWIG_TypeClientData(SWIGTYPE%s, (void *) &_wrap_class_%s);\n", SwigType_manglestr(t), mangled_class_fq_symname); // emit a function to be called to delete the object - // TODO: class_name -> full_class_name || mangled full_class_name if (have_destructor) { destructor_name = NewStringf("swig_delete_%s", mangled_class_fq_symname.ptr()); Printv(f_wrappers, "static void ", destructor_name.ptr(), "(void *obj) {\n", NIL); @@ -1454,20 +1231,26 @@ public: tab4, "return 1;\n}\n", NIL); Delete(constructor_name); constructor_name = constructor_proxy_name; + if (elua_ltr) { + String* static_cls_metatable_tab = Getattr(static_cls, "metatable"); + Printf(static_cls_metatable_tab, " {LSTRKEY(\"__call\"), LFUNCVAL(%s)},\n", constructor_name); + } else if (eluac_ltr) { + String* ns_methods_tab = Getattr(nspaceHash, "methods"); + Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "new_", class_symname, "\")", ", LFUNCVAL(", \ + constructor_name, ")", "},\n", NIL); + } + } + if (have_destructor) { + if (eluac_ltr) { + String* ns_methods_tab = Getattr(nspaceHash, "methods"); + Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_class_fq_symname.ptr(), "\")", ", LFUNCVAL(", destructor_name.ptr(), ")", "},\n", NIL); + } } closeNamespaceHash(class_fq_symname, f_wrappers); closeNamespaceHash(class_static_nspace, f_wrappers); - /* TODO: REMOVE - Delete(s_methods_tab); - Delete(s_attr_tab); - Delete(s_cls_methods_tab); - Delete(s_cls_attr_tab); - Delete(s_cls_const_tab); - */ - // Handle inheritance // note: with the idea of class hierarchies spread over multiple modules // cf test-suite: imports.i @@ -1491,12 +1274,7 @@ public: b = Next(b); continue; } - // old code: (used the pointer to the base class) TODO:REMOVE - //String *bmangle = Swig_name_mangle(bname); - //Printf(base_class, "&_wrap_class_%s", bmangle); - //Putc(',', base_class); - //Delete(bmangle); - // new code: stores a null pointer & the name + // stores a null pointer & the name Printf(base_class, "0,"); Printf(base_class_names, "\"%s *\",", SwigType_namestr(bname)); @@ -1505,31 +1283,19 @@ public: } } + // First, print class static part + printNamespaceDefinition(class_static_nspace, class_symname, f_wrappers); + + // Then print class isntance part Printv(f_wrappers, "static swig_lua_class *swig_", mangled_class_fq_symname.ptr(), "_bases[] = {", base_class, "0};\n", NIL); Delete(base_class); Printv(f_wrappers, "static const char *swig_", mangled_class_fq_symname.ptr(), "_base_names[] = {", base_class_names, "0};\n", NIL); Delete(base_class_names); - Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_class_fq_symname.ptr(), " = { \"", class_symname, "\", \"", class_fq_symname,"\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); // TODO: SwigType_manglestr(t) - memory leak + Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_class_fq_symname.ptr(), " = { \"", class_symname, "\", \"", class_fq_symname,"\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); - // TODO: Replace with constructor_name if (have_constructor) { - if (elua_ltr) { - String* ns_methods_tab = Getattr(nspaceHash, "methods"); - // TODO: Contructor should be moved to __call method of static part of class - Printf(ns_methods_tab, " {LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", class_symname, \ - symname_wrapper(Swig_name_construct(nspace, constructor_name))); - Printf(f_wrappers, "%s", symname_wrapper(Swig_name_construct(nspace, constructor_name))); - } else if (eluac_ltr) { - String* ns_methods_tab = Getattr(nspaceHash, "methods"); - Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "new_", class_symname, "\")", ", LFUNCVAL(", \ - symname_wrapper(Swig_name_construct(nspace, constructor_name)), ")", "},\n", NIL); - Printf(f_wrappers, "%s", symname_wrapper(Swig_name_construct(nspace, constructor_name))); - } else { - //Printf( stdout, "Constructor.name %s declaration: %s\n", constructor_name, symname_wrapper(Swig_name_construct(nspace, constructor_name))); - //Printf(f_wrappers, "%s", symname_wrapper(Swig_name_construct(nspace, constructor_name))); - Printv(f_wrappers, constructor_name, NIL); - } + Printv(f_wrappers, constructor_name, NIL); Delete(constructor_name); constructor_name = 0; } else { @@ -1537,25 +1303,14 @@ public: } if (have_destructor) { - if (eluac_ltr) { - String* ns_methods_tab = Getattr(nspaceHash, "methods"); - Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_class_fq_symname.ptr(), "\")", ", LFUNCVAL(", destructor_name.ptr(), ")", "},\n", NIL); - Printv(f_wrappers, ", ", destructor_name.ptr(), NIL); - } else { - Printv(f_wrappers, ", ", destructor_name.ptr(), NIL); - } + Printv(f_wrappers, ", ", destructor_name.ptr(), NIL); } else { Printf(f_wrappers, ",0"); } - Printf(f_wrappers, ", %s, %s, ", s_methods_tab_name, s_attr_tab_name ); - // TODO: Replace class_symname with class_name - printNamespaceDefinition(class_static_nspace, class_symname, f_wrappers); + Printf(f_wrappers, ", %s, %s, &%s", s_methods_tab_name, s_attr_tab_name, Getattr(static_cls, "cname") ); Printf(f_wrappers, ", swig_%s_bases, swig_%s_base_names };\n\n", mangled_class_fq_symname.ptr(), mangled_class_fq_symname.ptr()); - // Printv(f_wrappers, ", swig_", mangled_class_fq_symname, "_methods, swig_", mangled_class_fq_symname, "_attributes, swig_", mangled_class_fq_symname, "_bases };\n\n", NIL); - // Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, &_wrap_class_", mangled_class_fq_symname, "},\n", NIL); - current[NO_CPP] = true; Delete(class_static_nspace); class_static_nspace = 0; @@ -1712,17 +1467,7 @@ public: virtual int memberconstantHandler(Node *n) { REPORT("memberconstantHandler",n); - String *symname = Getattr(n, "sym:name"); - /* TODO:REMOVE - if (cparse_cplusplus && getCurrentClass()) { - Swig_save("luaclassobj_memberconstantHandler", n, "luaclassobj:symname", NIL); - Setattr(n, "luaclassobj:symname", symname); - }*/ int result = Language::memberconstantHandler(n); - /* TODO:REMOVE - if (cparse_cplusplus && getCurrentClass()) - Swig_restore(n); // TODO: WTF ? - */ return result; } @@ -1761,496 +1506,10 @@ public: Swig_restore(n); } - /* TODO: Add backward compatibility here: add "ClassName_AttributeName" to class scope - Swig_require("luaclassobj_staticmembervariableHandler", n, "luaclassobj:wrap:get", "luaclassobj:wrap:set", NIL); - Printf(s_cls_attr_tab,"%s{ \"%s\", %s, %s},\n",tab4,symname,Getattr(n,"luaclassobj:wrap:get"), Getattr(n,"luaclassobj:wrap:set")); - Swig_restore(n); - */ return SWIG_OK; } -#if 0 - virtual int classDirectorMethod(Node *n, Node *parent, String *super) { - int is_void = 0; - int is_pointer = 0; - String *decl = Getattr(n, "decl"); - String *name = Getattr(n, "name"); - String *classname = Getattr(parent, "sym:name"); - String *c_classname = Getattr(parent, "name"); - String *symname = Getattr(n, "sym:name"); - String *declaration = NewString(""); - ParmList *l = Getattr(n, "parms"); - Wrapper *w = NewWrapper(); - String *tm; - String *wrap_args = NewString(""); - String *returntype = Getattr(n, "type"); - String *value = Getattr(n, "value"); - String *storage = Getattr(n, "storage"); - bool pure_virtual = false; - int status = SWIG_OK; - int idx; - bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; - if (Cmp(storage, "virtual") == 0) { - if (Cmp(value, "0") == 0) { - pure_virtual = true; - } - } - - /* determine if the method returns a pointer */ - is_pointer = SwigType_ispointer_return(decl); - is_void = (!Cmp(returntype, "void") && !is_pointer); - - /* virtual method definition */ - String *target; - String *pclassname = NewStringf("SwigDirector_%s", classname); - String *qualified_name = NewStringf("%s::%s", pclassname, name); - SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type"); - target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); - Printf(w->def, "%s", target); - Delete(qualified_name); - Delete(target); - /* header declaration */ - target = Swig_method_decl(rtype, decl, name, l, 0, 1); - Printf(declaration, " virtual %s", target); - Delete(target); - - // Get any exception classes in the throws typemap - ParmList *throw_parm_list = 0; - - if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) { - Parm *p; - int gencomma = 0; - - Append(w->def, " throw("); - Append(declaration, " throw("); - - if (throw_parm_list) - Swig_typemap_attach_parms("throws", throw_parm_list, 0); - for (p = throw_parm_list; p; p = nextSibling(p)) { - if (Getattr(p, "tmap:throws")) { - if (gencomma++) { - Append(w->def, ", "); - Append(declaration, ", "); - } - String *str = SwigType_str(Getattr(p, "type"), 0); - Append(w->def, str); - Append(declaration, str); - Delete(str); - } - } - - Append(w->def, ")"); - Append(declaration, ")"); - } - - Append(w->def, " {"); - Append(declaration, ";\n"); - - /* declare method return value - * if the return value is a reference or const reference, a specialized typemap must - * handle it, including declaration of c_result ($result). - */ - if (!is_void) { - if (!(ignored_method && !pure_virtual)) { - String *cres = SwigType_lstr(returntype, "c_result"); - Printf(w->code, "%s;\n", cres); - Delete(cres); - } - } - - if (builtin) { - Printv(w->code, "PyObject *self = NULL;\n", NIL); - Printv(w->code, "(void)self;\n", NIL); - } - - if (ignored_method) { - if (!pure_virtual) { - if (!is_void) - Printf(w->code, "return "); - String *super_call = Swig_method_call(super, l); - Printf(w->code, "%s;\n", super_call); - Delete(super_call); - } else { - Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), - SwigType_namestr(name)); - } - } else { - /* attach typemaps to arguments (C/C++ -> Python) */ - String *arglist = NewString(""); - String *parse_args = NewString(""); - - Swig_director_parms_fixup(l); - - /* remove the wrapper 'w' since it was producing spurious temps */ - Swig_typemap_attach_parms("in", l, 0); - Swig_typemap_attach_parms("directorin", l, 0); - Swig_typemap_attach_parms("directorargout", l, w); - - Parm *p; - char source[256]; - - int outputs = 0; - if (!is_void) - outputs++; - - /* build argument list and type conversion string */ - idx = 0; - p = l; - int use_parse = 0; - while (p) { - if (checkAttribute(p, "tmap:in:numinputs", "0")) { - p = Getattr(p, "tmap:in:next"); - continue; - } - - /* old style? caused segfaults without the p!=0 check - in the for() condition, and seems dangerous in the - while loop as well. - while (Getattr(p, "tmap:ignore")) { - p = Getattr(p, "tmap:ignore:next"); - } - */ - - if (Getattr(p, "tmap:directorargout") != 0) - outputs++; - - String *pname = Getattr(p, "name"); - String *ptype = Getattr(p, "type"); - - Putc(',', arglist); - if ((tm = Getattr(p, "tmap:directorin")) != 0) { - String *parse = Getattr(p, "tmap:directorin:parse"); - if (!parse) { - sprintf(source, "obj%d", idx++); - String *input = NewString(source); - Setattr(p, "emit:directorinput", input); - Replaceall(tm, "$input", input); - Delete(input); - Replaceall(tm, "$owner", "0"); - /* Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); */ - Printv(wrap_args, "swig::SwigVar_PyObject ", source, ";\n", NIL); - - Printv(wrap_args, tm, "\n", NIL); - Printv(arglist, "(PyObject *)", source, NIL); - Putc('O', parse_args); - } else { - use_parse = 1; - Append(parse_args, parse); - Setattr(p, "emit:directorinput", pname); - Replaceall(tm, "$input", pname); - Replaceall(tm, "$owner", "0"); - if (Len(tm) == 0) - Append(tm, pname); - Append(arglist, tm); - } - p = Getattr(p, "tmap:directorin:next"); - continue; - } else if (Cmp(ptype, "void")) { - /* special handling for pointers to other C++ director classes. - * ideally this would be left to a typemap, but there is currently no - * way to selectively apply the dynamic_cast<> to classes that have - * directors. in other words, the type "SwigDirector_$1_lname" only exists - * for classes with directors. we avoid the problem here by checking - * module.wrap::directormap, but it's not clear how to get a typemap to - * do something similar. perhaps a new default typemap (in addition - * to SWIGTYPE) called DIRECTORTYPE? - */ - if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) { - Node *module = Getattr(parent, "module"); - Node *target = Swig_directormap(module, ptype); - sprintf(source, "obj%d", idx++); - String *nonconst = 0; - /* strip pointer/reference --- should move to Swig/stype.c */ - String *nptype = NewString(Char(ptype) + 2); - /* name as pointer */ - String *ppname = Copy(pname); - if (SwigType_isreference(ptype)) { - Insert(ppname, 0, "&"); - } - /* if necessary, cast away const since Python doesn't support it! */ - if (SwigType_isconst(nptype)) { - nonconst = NewStringf("nc_tmp_%s", pname); - String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname); - Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); - Delete(nonconst_i); - Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, - "Target language argument '%s' discards const in director method %s::%s.\n", - SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name)); - } else { - nonconst = Copy(ppname); - } - Delete(nptype); - Delete(ppname); - String *mangle = SwigType_manglestr(ptype); - if (target) { - String *director = NewStringf("director_%s", mangle); - Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL); - Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); - Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst); - Printf(wrap_args, "if (!%s) {\n", director); - Printf(wrap_args, "%s = SWIG_InternalNewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); - Append(wrap_args, "} else {\n"); - Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director); - Printf(wrap_args, "Py_INCREF((PyObject *)%s);\n", source); - Append(wrap_args, "}\n"); - Delete(director); - Printv(arglist, source, NIL); - } else { - Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); - Printf(wrap_args, "%s = SWIG_InternalNewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); - //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n", - // source, nonconst, base); - Printv(arglist, source, NIL); - } - Putc('O', parse_args); - Delete(mangle); - Delete(nonconst); - } else { - Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0), - SwigType_namestr(c_classname), SwigType_namestr(name)); - status = SWIG_NOWRAP; - break; - } - } - p = nextSibling(p); - } - - /* add the method name as a PyString */ - String *pyname = Getattr(n, "sym:name"); - - int allow_thread = threads_enable(n); - - if (allow_thread) { - thread_begin_block(n, w->code); - Append(w->code, "{\n"); - } - - /* wrap complex arguments to PyObjects */ - Printv(w->code, wrap_args, NIL); - - /* pass the method call on to the Python object */ - if (dirprot_mode() && !is_public(n)) { - Printf(w->code, "swig_set_inner(\"%s\", true);\n", name); - } - - - Append(w->code, "if (!swig_get_self()) {\n"); - Printf(w->code, " Swig::DirectorException::raise(\"'self' uninitialized, maybe you forgot to call %s.__init__.\");\n", classname); - Append(w->code, "}\n"); - Append(w->code, "#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n"); - Printf(w->code, "const size_t swig_method_index = %d;\n", director_method_index++); - Printf(w->code, "const char * const swig_method_name = \"%s\";\n", pyname); - - Append(w->code, "PyObject* method = swig_get_method(swig_method_index, swig_method_name);\n"); - if (Len(parse_args) > 0) { - if (use_parse || !modernargs) { - Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", Swig_cresult_name(), parse_args, arglist); - } else { - Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallFunctionObjArgs(method %s, NULL);\n", Swig_cresult_name(), arglist); - } - } else { - if (modernargs) { - Append(w->code, "swig::SwigVar_PyObject args = PyTuple_New(0);\n"); - Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_Call(method, (PyObject*) args, NULL);\n", Swig_cresult_name()); - } else { - Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallFunction(method, NULL, NULL);\n", Swig_cresult_name()); - } - } - Append(w->code, "#else\n"); - if (Len(parse_args) > 0) { - if (use_parse || !modernargs) { - Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n", Swig_cresult_name(), pyname, parse_args, arglist); - } else { - Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname); - Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", Swig_cresult_name(), arglist); - } - } else { - if (!modernargs) { - Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", Swig_cresult_name(), pyname); - } else { - Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname); - Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n", Swig_cresult_name()); - } - } - Append(w->code, "#endif\n"); - - if (dirprot_mode() && !is_public(n)) - Printf(w->code, "swig_set_inner(\"%s\", false);\n", name); - - /* exception handling */ - tm = Swig_typemap_lookup("director:except", n, Swig_cresult_name(), 0); - if (!tm) { - tm = Getattr(n, "feature:director:except"); - if (tm) - tm = Copy(tm); - } - Printf(w->code, "if (!%s) {\n", Swig_cresult_name()); - 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) {\n"); - Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n", classname, pyname); - Append(w->code, " }\n"); - } - Append(w->code, "}\n"); - Delete(tm); - - /* - * Python method may return a simple object, or a tuple. - * for in/out aruments, we have to extract the appropriate PyObjects from the tuple, - * then marshal everything back to C/C++ (return value and output arguments). - * - */ - - /* marshal return value and other outputs (if any) from PyObject to C/C++ type */ - - String *cleanup = NewString(""); - String *outarg = NewString(""); - - if (outputs > 1) { - Wrapper_add_local(w, "output", "PyObject *output"); - Printf(w->code, "if (!PyTuple_Check(%s)) {\n", Swig_cresult_name()); - Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", classname, pyname); - Append(w->code, "}\n"); - } - - idx = 0; - - /* marshal return value */ - if (!is_void) { - tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); - if (tm != 0) { - if (outputs > 1) { - Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++); - Replaceall(tm, "$input", "output"); - } else { - Replaceall(tm, "$input", Swig_cresult_name()); - } - char temp[24]; - sprintf(temp, "%d", idx); - Replaceall(tm, "$argnum", temp); - - /* TODO check this */ - if (Getattr(n, "wrap:disown")) { - Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); - } else { - Replaceall(tm, "$disown", "0"); - } - if (Getattr(n, "tmap:directorout:implicitconv")) { - Replaceall(tm, "$implicitconv", get_implicitconv_flag(n)); - } - Replaceall(tm, "$result", "c_result"); - Printv(w->code, tm, "\n", NIL); - Delete(tm); - } else { - Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname), - SwigType_namestr(name)); - status = SWIG_ERROR; - } - } - - /* marshal outputs */ - for (p = l; p;) { - if ((tm = Getattr(p, "tmap:directorargout")) != 0) { - if (outputs > 1) { - Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++); - Replaceall(tm, "$result", "output"); - } else { - Replaceall(tm, "$result", Swig_cresult_name()); - } - Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); - Printv(w->code, tm, "\n", NIL); - p = Getattr(p, "tmap:directorargout:next"); - } else { - p = nextSibling(p); - } - } - - /* any existing helper functions to handle this? */ - if (allow_thread) { - Append(w->code, "}\n"); - thread_end_block(n, w->code); - } - - Delete(parse_args); - Delete(arglist); - Delete(cleanup); - Delete(outarg); - } - - if (!is_void) { - if (!(ignored_method && !pure_virtual)) { - String *rettype = SwigType_str(returntype, 0); - if (!SwigType_isreference(returntype)) { - Printf(w->code, "return (%s) c_result;\n", rettype); - } else { - Printf(w->code, "return (%s) *c_result;\n", rettype); - } - Delete(rettype); - } - } - - Append(w->code, "}\n"); - - // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method - String *inline_extra_method = NewString(""); - if (dirprot_mode() && !is_public(n) && !pure_virtual) { - Printv(inline_extra_method, declaration, NIL); - String *extra_method_name = NewStringf("%sSwigPublic", name); - Replaceall(inline_extra_method, name, extra_method_name); - Replaceall(inline_extra_method, ";\n", " {\n "); - if (!is_void) - Printf(inline_extra_method, "return "); - String *methodcall = Swig_method_call(super, l); - Printv(inline_extra_method, methodcall, ";\n }\n", NIL); - Delete(methodcall); - Delete(extra_method_name); - } - - /* emit the director method */ - if (status == SWIG_OK) { - if (!Getattr(n, "defaultargs")) { - Replaceall(w->code, "$symname", symname); - Wrapper_print(w, f_directors); - Printv(f_directors_h, declaration, NIL); - Printv(f_directors_h, inline_extra_method, NIL); - } - } - - /* clean up */ - Delete(wrap_args); - Delete(pclassname); - DelWrapper(w); - return status; - } -#endif - - /* TODO: REMOVE - virtual int namespaceDeclaration(Node *n) { - // Register namespace - String* name = Getattr(n, "sym:name"); - Hash* parent = getNamespaceHash( getNSpace() ); - String *parent_namespaces_tab = Getattr(parent, "namespaces"); - String *mangled_name = Swig_name_mangle(name); - String *full_name = NewString(""); - if (getNSpace() == 0) - Printv(full_name, name); - else - Printv(full_name, getNSpace(), NSPACE_SEPARATOR, name); - Hash *nspace = getNamespaceHash(full_name); - Setattr(nspace, "name", Copy(name)); - Printv(parent_namespaces_tab, mangled_name, ",\n", NIL); - Printf(stdout, "NamespaceDeclaration %s, Parent %s, FQN %s\n", name, getNSpace(), full_name); - Delete(mangled_name); - Delete(full_name); - return Language::namespaceDeclaration(n); - } - */ /* --------------------------------------------------------------------- * external runtime generation * --------------------------------------------------------------------- */ @@ -2328,7 +1587,6 @@ public: */ Hash* getNamespaceHash(String *nspace, bool reg = true) { - //Printf( stdout, "Request for %s. register: %d\n", nspace?nspace:"", int(reg)); Hash* nspace_hash = Getattr(namespaces_hash, nspace?nspace:"" ); if (nspace_hash != 0) return nspace_hash; @@ -2352,7 +1610,7 @@ public: String* item = Getitem(components, i); Printv(parent_path, item, NIL); } - Printf(stdout, "Registering %s. User name %s. C-name %s, Parent is %s\n", mangled_name, name, cname, parent_path); + //Printf(stdout, "Registering %s. User name %s. C-name %s, Parent is %s\n", mangled_name, name, cname, parent_path); Hash* parent = getNamespaceHash(parent_path, true); String* namespaces_tab = Getattr(parent, "namespaces"); Printv(namespaces_tab, "&", cname, ",\n", NIL); @@ -2523,6 +1781,20 @@ public: Printv(metatable_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_module_set)},\n", NIL); Printv(metatable_tab, tab4, "{LSTRKEY(\".get\"), LROVAL(", get_tab_name, ")},\n", NIL); Printv(metatable_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(", set_tab_name, ")},\n", NIL); + if (Getattr(nspace_hash, "lua:class")) { + String *static_cls = Getattr(nspace_hash, "lua:class_instance:static_hash"); + assert(static_cls != 0); + String *static_cls_cname = Getattr(static_cls, "cname"); + assert(static_cls_cname != 0); + Printv(metatable_tab, tab4, "LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n"); + } else if (Getattr(nspace_hash, "lua:class_static") ) { + Hash *instance_cls = Getattr(nspace_hash, "lua:class_static:instance_hash"); + assert(instance_cls != 0); + String *instance_cls_metatable_name = Getattr(instance_cls, "metatable:name"); + assert(instance_cls_metatable_name != 0); + Printv(metatable_tab, tab4, "LSTRKEY(\".static\"), LROVAL(", instance_cls_metatable_name, ")},\n"); + } + Printv(metatable_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); Printv(output, metatable_tab, NIL); } @@ -2547,11 +1819,6 @@ public: String* key = Getitem(to_close,i); closeNamespaceHash(key, dataOutput); Hash* nspace = Getattr(namespaces_hash, key); - String* cname = Getattr(nspace, "cname"); // cname - name of the C structure that describes namespace - assert(cname != 0); - //Printf( stdout, "Closing namespace %s\n", cname ); TODO: REMOVE - //printNamespaceForwardDeclaration( ki.key, declOutput ); TODO: REMOVE - Printv(dataOutput, "static swig_lua_namespace ", cname, " = ", NIL); String *name = 0; // name - name of the namespace as it should be visible in Lua if (DohLen(key) == 0) // This is global module name = module; @@ -2559,7 +1826,6 @@ public: name = Getattr(nspace, "name"); assert(name != 0); printNamespaceDefinition( key, name, dataOutput ); - Printv(dataOutput, ";\n\n", NIL); } Delete(to_close); } @@ -2573,7 +1839,13 @@ public: { // TODO: Fix for get_tab/set_tab things (elua_ltr) Hash *nspace_hash = getNamespaceHash(nspace, false); - String *null_string = NewString("0"); + + String* cname = Getattr(nspace_hash, "cname"); // cname - name of the C structure that describes namespace + assert(cname != 0); + Printv(output, "static swig_lua_namespace ", cname, " = ", NIL); + + PtrGuard null_string; + null_string = NewString("0"); String *attr_tab_name = Getattr(nspace_hash, "attributes:name"); String *methods_tab_name = Getattr(nspace_hash, "methods:name"); String *const_tab_name = Getattr(nspace_hash, "constants:name"); @@ -2582,13 +1854,14 @@ public: bool has_classes = Getattr(nspace_hash, "lua:no_classes") == 0; bool has_namespaces = Getattr(nspace_hash, "lua:no_namespaces") == 0; - Printf(output, "{\"%s\", %s, %s, %s, %s, %s}", - name, - methods_tab_name, - attr_tab_name, - const_tab_name, - (has_classes)?classes_tab_name:null_string, - (has_namespaces)?namespaces_tab_name:null_string + Printv(output, "{\n", + tab4, "\"", name, "\",\n", + tab4, methods_tab_name, ",\n", + tab4, attr_tab_name, ",\n", + tab4, const_tab_name, ",\n", + tab4, (has_classes)?classes_tab_name:null_string.ptr(), ",\n", + tab4, (has_namespaces)?namespaces_tab_name:null_string.ptr(), "};\n", + NIL ); } @@ -2603,10 +1876,6 @@ public: Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", iname, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); else Printv(s_ns_methods_tab, tab4, "{ \"", target_name, "\", ", wname, "},\n", NIL); - // Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", symname_wrapper(iname), "},\n", NIL); - if (getCurrentClass()) { - Setattr(n,"luaclassobj:wrap:name", wname); // TODO: REMOVE - } } // Add variable to the "attributes" (or "get"/"set" in @@ -2636,32 +1905,8 @@ public: } - // This function prints forward declaration of namespace itself and all its arrays - // TODO: REMOVE - void printNamespaceForwardDeclaration(String* nspace, File* output) - { - Hash *nspace_hash = getNamespaceHash(nspace, false); - String *attr_tab_decl = Getattr(nspace_hash, "attributes:decl"); - String *methods_tab_decl = Getattr(nspace_hash, "methods:decl"); - String *const_tab_decl = Getattr(nspace_hash, "constants:decl"); - String *classes_tab_decl = Getattr(nspace_hash, "classes:decl"); - String *namespaces_tab_decl = Getattr(nspace_hash, "declspaces:decl"); - bool has_classes = Getattr(nspace_hash, "lua:no_classes") == 0; - bool has_namespaces = Getattr(nspace_hash, "lua:no_namespaces") == 0; - Printv( output, attr_tab_decl, "\n", NIL ); - Printv( output, methods_tab_decl, "\n", NIL ); - Printv( output, const_tab_decl, "\n", NIL ); - if( has_classes ) - Printv( output, classes_tab_decl, "\n", NIL ); - if( has_namespaces ) - Printv( output, namespaces_tab_decl, "\n", NIL ); - - Printf( output, "static swig_lua_namespace %s;\n", Getattr(nspace_hash, "cname") ); - } - // Our implementation of addSymbol. Determines scope correctly, then calls Language::addSymbol int luaAddSymbol(const String *s, const Node *n) { - //Printf(stdout, "addSymbol: %s", s); // TODO:REMOVE String* scope = 0; // If ouside class, than NSpace is used. if( !getCurrentClass()) @@ -2679,7 +1924,7 @@ public: } assert(scope != 0); } - //Printf( stdout, " scope: %s\n", scope ); // TODO:REMOVE + //Printf(stdout, "addSymbol: %s scope: %s'n", s, scope); return Language::addSymbol(s,n,scope); } From 7e052c18736eba09f70dec8b9191e3d8d98b9f81 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Thu, 7 Nov 2013 19:59:38 +0400 Subject: [PATCH 0976/1160] Bugfixes --- Source/Modules/lua.cxx | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index c719bad66..0c5821326 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -321,8 +321,6 @@ public: /* Get the module name */ module = Getattr(n, "name"); - /* Some global settings */ - director_language = 1; /* Get the output file name */ String *outfile = Getattr(n, "outfile"); @@ -402,11 +400,11 @@ public: if (elua_ltr || eluac_ltr) { /* Final close up of wrappers */ - closeNamespaces(f_wrappers, 0); // TODO: Remove last parameter + closeNamespaces(f_wrappers); // TODO: Remove last parameter SwigType_emit_type_table(f_runtime, f_wrappers); } else { //Printv(f_wrappers, s_cmd_tab, s_var_tab, s_const_tab, NIL); - closeNamespaces(f_wrappers, 0); + closeNamespaces(f_wrappers); SwigType_emit_type_table(f_runtime, f_wrappers); } @@ -1233,9 +1231,11 @@ public: constructor_name = constructor_proxy_name; if (elua_ltr) { String* static_cls_metatable_tab = Getattr(static_cls, "metatable"); + assert(static_cls_metatable_tab != 0); Printf(static_cls_metatable_tab, " {LSTRKEY(\"__call\"), LFUNCVAL(%s)},\n", constructor_name); } else if (eluac_ltr) { String* ns_methods_tab = Getattr(nspaceHash, "methods"); + assert(ns_methods_tab != 0); Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "new_", class_symname, "\")", ", LFUNCVAL(", \ constructor_name, ")", "},\n", NIL); } @@ -1243,6 +1243,7 @@ public: if (have_destructor) { if (eluac_ltr) { String* ns_methods_tab = Getattr(nspaceHash, "methods"); + assert(ns_methods_tab != 0); Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_class_fq_symname.ptr(), "\")", ", LFUNCVAL(", destructor_name.ptr(), ")", "},\n", NIL); } } @@ -1400,7 +1401,6 @@ public: current[CONSTRUCTOR] = false; //constructor_name = NewString(Getattr(n, "sym:name")); have_constructor = 1; - //Printf( stdout, "Constructor %s\n", constructor_name); TODO: REMOVE return SWIG_OK; } @@ -1781,18 +1781,18 @@ public: Printv(metatable_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_module_set)},\n", NIL); Printv(metatable_tab, tab4, "{LSTRKEY(\".get\"), LROVAL(", get_tab_name, ")},\n", NIL); Printv(metatable_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(", set_tab_name, ")},\n", NIL); - if (Getattr(nspace_hash, "lua:class")) { + if (Getattr(nspace_hash, "lua:class_instance")) { String *static_cls = Getattr(nspace_hash, "lua:class_instance:static_hash"); assert(static_cls != 0); String *static_cls_cname = Getattr(static_cls, "cname"); assert(static_cls_cname != 0); - Printv(metatable_tab, tab4, "LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n"); + Printv(metatable_tab, tab4, "LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL); } else if (Getattr(nspace_hash, "lua:class_static") ) { Hash *instance_cls = Getattr(nspace_hash, "lua:class_static:instance_hash"); assert(instance_cls != 0); String *instance_cls_metatable_name = Getattr(instance_cls, "metatable:name"); assert(instance_cls_metatable_name != 0); - Printv(metatable_tab, tab4, "LSTRKEY(\".static\"), LROVAL(", instance_cls_metatable_name, ")},\n"); + Printv(metatable_tab, tab4, "LSTRKEY(\".static\"), LROVAL(", instance_cls_metatable_name, ")},\n", NIL); } Printv(metatable_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); @@ -1803,8 +1803,7 @@ public: static int compareByLen( const DOH* f, const DOH* s) { return Len(s) - Len(f); } // Recursively close all non-closed namespaces. Prints data to dataOutput, - // forward declaration to declOutput - void closeNamespaces(File *dataOutput, File *declOutput) + void closeNamespaces(File *dataOutput) { Iterator ki = First(namespaces_hash); List* to_close = NewList(); @@ -1867,15 +1866,16 @@ public: // Add method to the "methods" C array of given namespace/class void registerMethod(String *nspace_or_class_name, Node* n) { - Hash* nspaceHash = getNamespaceHash( nspace_or_class_name ); - String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); - String *wname = Getattr(n, "wrap:name"); - String *iname = Getattr(n, "sym:name"); - String *target_name = Getattr(n, "lua:name"); - if(elua_ltr || eluac_ltr) - Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", iname, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); - else - Printv(s_ns_methods_tab, tab4, "{ \"", target_name, "\", ", wname, "},\n", NIL); + assert(n != 0); + Hash* nspaceHash = getNamespaceHash( nspace_or_class_name ); + String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); + String *wname = Getattr(n, "wrap:name"); + String *iname = Getattr(n, "sym:name"); + String *target_name = Getattr(n, "lua:name"); + if(elua_ltr || eluac_ltr) + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", iname, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); + else + Printv(s_ns_methods_tab, tab4, "{ \"", target_name, "\", ", wname, "},\n", NIL); } // Add variable to the "attributes" (or "get"/"set" in @@ -1924,7 +1924,7 @@ public: } assert(scope != 0); } - //Printf(stdout, "addSymbol: %s scope: %s'n", s, scope); + //Printf(stdout, "addSymbol: %s scope: %s\n", s, scope); return Language::addSymbol(s,n,scope); } From da0510376c4d29bcf5f08ce734b0dcfbd3264849 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Fri, 8 Nov 2013 12:28:45 +0400 Subject: [PATCH 0977/1160] Bugfixes. CMD args handling. Code cleanup --- Examples/test-suite/lua/li_carrays_runme.lua | 20 +- .../test-suite/lua/member_pointer_runme.lua | 39 +-- Lib/lua/luarun.swg | 29 ++- Lib/lua/luaruntime.swg | 4 +- Source/Modules/lua.cxx | 246 ++++++++++++------ 5 files changed, 220 insertions(+), 118 deletions(-) diff --git a/Examples/test-suite/lua/li_carrays_runme.lua b/Examples/test-suite/lua/li_carrays_runme.lua index 285d7b32a..d007fae36 100644 --- a/Examples/test-suite/lua/li_carrays_runme.lua +++ b/Examples/test-suite/lua/li_carrays_runme.lua @@ -1,8 +1,6 @@ require("import") -- the import fn import("li_carrays") -- import code - --- moving to global -for k,v in pairs(li_carrays) do _G[k]=v end +lc = li_carrays -- catch "undefined" global variables local env = _ENV -- Lua 5.2 @@ -10,22 +8,22 @@ if not env then env = getfenv () end -- Lua 5.1 setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) -- Testing for %array_functions(int,intArray) -ary = new_intArray(2) -intArray_setitem(ary, 0, 0) -intArray_setitem(ary, 1, 1) -assert(intArray_getitem(ary, 0)==0) -assert(intArray_getitem(ary, 1)==1) -delete_intArray(ary) +ary = lc.new_intArray(2) +lc.intArray_setitem(ary, 0, 0) +lc.intArray_setitem(ary, 1, 1) +assert(lc.intArray_getitem(ary, 0)==0) +assert(lc.intArray_getitem(ary, 1)==1) +lc.delete_intArray(ary) -- Testing for %array_class(double, doubleArray) -d = doubleArray(10) +d = lc.doubleArray(10) d[0] = 7 d[5] = d[0] + 3 assert(d[5] + d[0] == 17) --print(d[5] + d[0]) ptr = d:cast() -- to ptr -d2 = doubleArray_frompointer(ptr) -- and back to array +d2 = lc.doubleArray_frompointer(ptr) -- and back to array assert(d2[5] + d2[0] == 17) --print(d2[5] + d2[0]) diff --git a/Examples/test-suite/lua/member_pointer_runme.lua b/Examples/test-suite/lua/member_pointer_runme.lua index 8dddab295..1240d92a0 100644 --- a/Examples/test-suite/lua/member_pointer_runme.lua +++ b/Examples/test-suite/lua/member_pointer_runme.lua @@ -1,43 +1,46 @@ --Example using pointers to member functions - require("import") -- the import fn import("member_pointer") -- import code +mp = member_pointer -for k,v in pairs(member_pointer) do _G[k]=v end +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) function check(what, expected, actual) assert(expected == actual,"Failed: "..what.." Expected: "..expected.." Actual: "..actual) end -- Get the pointers -area_pt = areapt() -perim_pt = perimeterpt() +area_pt = mp.areapt() +perim_pt = mp.perimeterpt() -- Create some objects -s = Square(10) +s = mp.Square(10) -- Do some calculations -check ("Square area ", 100.0, do_op(s,area_pt)) -check ("Square perim", 40.0, do_op(s,perim_pt)) +check ("Square area ", 100.0, mp.do_op(s,area_pt)) +check ("Square perim", 40.0, mp.do_op(s,perim_pt)) -- Try the variables -- these have to still be part of the 'member_pointer' table -memberPtr = member_pointer.areavar -memberPtr = member_pointer.perimetervar +memberPtr = mp.areavar +memberPtr = mp.perimetervar -check ("Square area ", 100.0, do_op(s,member_pointer.areavar)) -check ("Square perim", 40.0, do_op(s,member_pointer.perimetervar)) +check ("Square area ", 100.0, mp.do_op(s,mp.areavar)) +check ("Square perim", 40.0, mp.do_op(s,mp.perimetervar)) -- Modify one of the variables -member_pointer.areavar = perim_pt +mp.areavar = perim_pt -check ("Square perimeter", 40.0, do_op(s,member_pointer.areavar)) +check ("Square perimeter", 40.0, mp.do_op(s,mp.areavar)) -- Try the constants -memberPtr = AREAPT -memberPtr = PERIMPT -memberPtr = NULLPT +memberPtr = mp.AREAPT +memberPtr = mp.PERIMPT +memberPtr = mp.NULLPT -check ("Square area ", 100.0, do_op(s,AREAPT)) -check ("Square perim", 40.0, do_op(s,PERIMPT)) +check ("Square area ", 100.0, mp.do_op(s,mp.AREAPT)) +check ("Square perim", 40.0, mp.do_op(s,mp.PERIMPT)) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 764ec5fe4..4ed260774 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -138,19 +138,19 @@ typedef struct { } swig_lua_attribute; -struct swig_lua_class; +struct _swig_lua_class; // Can be used to create namespaces. Currently used to // wrap class static methods/variables/constants -struct swig_lua_namespace { +typedef struct _swig_lua_namespace { const char *name; swig_lua_method *ns_methods; swig_lua_attribute *ns_attributes; swig_lua_const_info *ns_constants; - swig_lua_class **ns_classes; - swig_lua_namespace **ns_namespaces; -}; + struct _swig_lua_class **ns_classes; + struct _swig_lua_namespace **ns_namespaces; +} swig_lua_namespace; -struct swig_lua_class { +typedef struct _swig_lua_class { const char *name; // Name that this class has in Lua const char *fqname; // Fully qualified name - Scope + class name swig_type_info **type; @@ -159,9 +159,9 @@ struct swig_lua_class { swig_lua_method *methods; swig_lua_attribute *attributes; swig_lua_namespace *cls_static; - struct swig_lua_class **bases; + struct _swig_lua_class **bases; const char **base_names; -}; +} swig_lua_class; /* this is the struct for wrapping all pointers in SwigLua */ @@ -351,6 +351,10 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* assert(lua_istable(L,-1)); SWIG_Lua_InstallConstants(L, ns->ns_constants); + /* add methods to the namespace/module table */ + for(i=0;ns->ns_methods[i].name;i++){ + SWIG_Lua_add_function(L,ns->ns_methods[i].name,ns->ns_methods[i].func); + } lua_getmetatable(L,-1); /* add fns */ @@ -358,6 +362,8 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* SWIG_Lua_add_variable(L,ns->ns_attributes[i].name,ns->ns_attributes[i].getmethod,ns->ns_attributes[i].setmethod); } +#if 0 + // TODO: REMOVE. .fn table is unused /* add methods to the metatable */ SWIG_Lua_get_table(L,".fn"); /* find the .fn table */ assert(lua_istable(L,-1)); /* just in case */ @@ -365,6 +371,7 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* SWIG_Lua_add_function(L,ns->ns_methods[i].name,ns->ns_methods[i].func); } lua_pop(L,1); +#endif /* clear stack - remove metatble */ lua_pop(L,1); @@ -393,7 +400,7 @@ SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State* L, swig_lua_namespace* when function is called) Function always returns newly registered table on top of the stack */ -SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns, bool reg) +SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns, int reg) { int begin = lua_gettop(L); assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table or parent namespace table */ @@ -428,7 +435,7 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns, swig_lua_namespace** sub_namespace = ns->ns_namespaces; if( sub_namespace != 0) { while(*sub_namespace != 0) { - SWIG_Lua_namespace_register(L, *sub_namespace, true); + SWIG_Lua_namespace_register(L, *sub_namespace, 1); lua_pop(L,1); // removing sub-namespace table sub_namespace++; } @@ -867,7 +874,7 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* cls assert(lua_istable(L,-1)); /* just in case */ assert(strcmp(clss->name, clss->cls_static->name) == 0); /* in class those 2 must be equal */ - SWIG_Lua_namespace_register(L,clss->cls_static, true); + SWIG_Lua_namespace_register(L,clss->cls_static, 1); assert(lua_istable(L,-1)); /* just in case */ diff --git a/Lib/lua/luaruntime.swg b/Lib/lua/luaruntime.swg index 0011c9d52..5e4ba9fd9 100644 --- a/Lib/lua/luaruntime.swg +++ b/Lib/lua/luaruntime.swg @@ -49,9 +49,9 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */ SWIG_Lua_init_base_class(L,(swig_lua_class*)(swig_types[i]->clientdata)); } } - bool globalRegister = false; + int globalRegister = 0; #ifdef SWIG_LUA_MODULE_GLOBAL - globalRegister = true; + globalRegister = 1; #endif SWIG_Lua_namespace_register(L,&swig___Global, globalRegister); #endif diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 0c5821326..824590b3a 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -91,14 +91,16 @@ class DohPtrGuard { // Guard is empty, ptr - any: assigns new value for guard // Guard is holding pointer, ptr == 0 - releases value that guard holds // Any other combination - assert - void operator=( DOH* ptr ) { + DOH* operator=( DOH* ptr ) { attach(ptr); + return ptr; } DOH* ptr() { return p_ptr; } const DOH* ptr() const { return p_ptr; } operator DOH* () { return p_ptr; } operator DOH* () const { return p_ptr; } + operator bool() const { return ptr != 0; } private: DOH* p_ptr; // pointer to actual object @@ -129,11 +131,11 @@ class DohPtrGuard { // Overloading DohDelete for DohPtrGuard. You might not call DohDelete on DohPtrGuard instances, // as it is supposed to manage underlying pointer by itself -void DohDelete(const DohPtrGuard& guard) { +void DohDelete(const DohPtrGuard& /*guard*/) { Printf( stderr, "ERROR: Attempt to delete guarded pointer without deleting it's guardian\n" ); assert(false); } -void DohDelete(DohPtrGuard& guard) { +void DohDelete(DohPtrGuard& /*guard*/) { Printf( stderr, "ERROR: Attempt to delete guarded pointer without deleting it's guardian\n" ); assert(false); } @@ -152,12 +154,23 @@ Lua Options (available with -lua)\n\ -eluac - LTR compatible wrappers in \"crass compress\" mode for elua\n\ -nomoduleglobal - Do not register the module name as a global variable \n\ but return the module table from calls to require.\n\ + -api-lvl-from NUM\n\ + - Force support for old-style bindings. All old-style bindings\n\ + from NUM to current new-style bindings will be supported. For example,\n\ + if current lua bindings API version is 10 and NUM==7 then SWIG will\n\ + generate bindings compatible with lua bindings versions 7,8,9 and,\n\ + of course current version of bindings, 10.\n\ + API levels:\n\ + 2 - SWIG 2.*\n\ + 3 - SWIG 3.*\n\ + Default NUM is 2.\n\ \n"; static int nomoduleglobal = 0; static int elua_ltr = 0; static int eluac_ltr = 0; -static int v2_compatibility = 1; +static int v2_compatibility = 0; +static const int default_api_level = 2; /* NEW LANGUAGE NOTE:*********************************************** To add a new language, you need to derive your class from @@ -260,6 +273,7 @@ public: virtual void main(int argc, char *argv[]) { + int api_level = default_api_level; // Default api level /* Set location of SWIG library */ SWIG_library_directory("lua"); @@ -277,10 +291,30 @@ public: } else if(strcmp(argv[i], "-eluac") == 0) { eluac_ltr = 1; Swig_mark_arg(i); + } else if(strcmp(argv[i], "-api-lvl-from") == 0) { + if(argv[i+1]) { + api_level = atoi(argv[i+1]); + if(api_level == 0) + Swig_arg_error(); + Swig_mark_arg(i+1); + i++; + } else { + Swig_arg_error(); + } } } } + // Set API-compatibility options + if(api_level <= 2) // Must be compatible with SWIG 2.* + v2_compatibility = 1; + // template for further API breaks + //if(api_level <= 3) + // v3_compatibility = 1; + //if(api_level <= 4) + // v4_compatibility = 1; + + /* NEW LANGUAGE NOTE:*********************************************** This is the boilerplate code, setting a few #defines and which lib directory to use @@ -400,7 +434,7 @@ public: if (elua_ltr || eluac_ltr) { /* Final close up of wrappers */ - closeNamespaces(f_wrappers); // TODO: Remove last parameter + closeNamespaces(f_wrappers); SwigType_emit_type_table(f_runtime, f_wrappers); } else { //Printv(f_wrappers, s_cmd_tab, s_var_tab, s_const_tab, NIL); @@ -491,6 +525,16 @@ public: Setattr(n, "varget:wrap:name", wrapname); } + // Helper for functionWrapper - determines whether we should + // register method in the appropriate class/namespace/module + // table or not. + // (not => it is variable wrapper or something similar) + bool functionWrapperRegisterNow() const { + if (current[VARIABLE]) + return false; + return (current[NO_CPP] || current[STATIC_FUNC]); + } + virtual int functionWrapper(Node *n) { REPORT("functionWrapper",n); @@ -503,14 +547,13 @@ public: Parm *p; String *tm; int i; - //Printf(stdout,"functionWrapper %s %s %d\n",name,iname,current); + //Printf(stdout,"functionWrapper %s %s %d\n",name,iname,current); // TODO: COMMENT BACK String *overname = 0; if (Getattr(n, "sym:overloaded")) { overname = Getattr(n, "sym:overname"); } else { if (!luaAddSymbol(target_name, n)) { - Printf(stderr,"addSymbol(%s) failed\n",target_name); return SWIG_ERROR; } } @@ -790,13 +833,14 @@ public: different language mappings seem to use different ideas NEW LANGUAGE NOTE:END ************************************************/ /* Now register the function with the interpreter. */ + int result = SWIG_OK; if (!Getattr(n, "sym:overloaded")) { - if (current[NO_CPP] || current[STATIC_FUNC]) { // emit normal fns & static fns - registerMethod(getNSpace(), n); + if (functionWrapperRegisterNow()) { // emit normal fns & static fns + registerMethod(luaCurrentSymbolNSpace(), n); } } else { if (!Getattr(n, "sym:nextSibling")) { - dispatchFunction(n); + result = dispatchFunction(n); } } @@ -808,7 +852,7 @@ public: // Delete(description); DelWrapper(f); - return SWIG_OK; + return result; } /* ------------------------------------------------------------ @@ -823,7 +867,7 @@ public: nost of the real work in again typemaps: look for %typecheck(SWIG_TYPECHECK_*) in the .swg file NEW LANGUAGE NOTE:END ************************************************/ - void dispatchFunction(Node *n) { + int dispatchFunction(Node *n) { //REPORT("dispatchFunction", n); /* Last node in overloaded chain */ @@ -841,6 +885,10 @@ public: //Printf(stdout,"Swig_overload_dispatch %s %s '%s' %d\n",symname,wname,dispatch,maxargs); + if (!luaAddSymbol(target_name, n)) { + return SWIG_ERROR; + } + Printv(f->def, "static int ", wname, "(lua_State* L) {", NIL); Wrapper_add_local(f, "argc", "int argc"); Printf(tmp, "int argv[%d]={1", maxargs + 1); @@ -870,8 +918,12 @@ public: Printf(f->code, "lua_error(L);return 0;\n"); Printv(f->code, "}\n", NIL); Wrapper_print(f, f_wrappers); - if (current[NO_CPP] || current[STATIC_FUNC]) { // emit normal fns & static fns - registerMethod(getNSpace(), n); + + // Remember C name of the wrapping function + rememberWrapName(n, wname); + + if (functionWrapperRegisterNow()) { // emit normal fns & static fns + registerMethod(luaCurrentSymbolNSpace(), n); } if (current[CONSTRUCTOR]) { if( constructor_name != 0 ) @@ -879,12 +931,11 @@ public: constructor_name = Copy(wname); } - // Remember C name of the wrapping function - rememberWrapName(n, wname); - DelWrapper(f); Delete(dispatch); Delete(tmp); + + return SWIG_OK; } @@ -906,8 +957,8 @@ public: current[VARIABLE] = true; // let SWIG generate the wrappers int result = Language::variableWrapper(n); + registerVariable( luaCurrentSymbolNSpace(), n, "varget:wrap:name", "varset:wrap:name" ); current[VARIABLE] = false; - registerVariable( getNSpace(), n, "varget:wrap:name", "varset:wrap:name" ); return result; } @@ -926,10 +977,26 @@ public: String *rawval = Getattr(n, "rawval"); String *value = rawval ? rawval : Getattr(n, "value"); String *tm; + PtrGuard target_name_v2; + PtrGuard tm_v2; + PtrGuard iname_v2; + PtrGuard n_v2; if (!luaAddSymbol(target_name, n)) return SWIG_ERROR; + bool make_v2_compatible = v2_compatibility && getCurrentClass() != 0; + //Printf( stdout, "V2 compatible: %d\n", int(make_v2_compatible) ); // TODO: REMOVE + if( make_v2_compatible ) { + target_name_v2 = Swig_name_member(0, class_symname, target_name); + iname_v2 = Swig_name_member(0, class_symname, iname); + n_v2 = Copy(n); + //Printf( stdout, "target name v2: %s, symname v2 %s\n", target_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE + if (!luaAddSymbol(iname_v2, n, class_parent_nspace)) { + return SWIG_ERROR; + } + } + Swig_save("lua_constantMember", n, "sym:name", NIL); Setattr(n, "sym:name", target_name); /* Special hook for member pointer */ @@ -940,16 +1007,17 @@ public: } if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) { + //Printf(stdout, "tm v1: %s\n", tm); // TODO:REMOVE Replaceall(tm, "$source", value); - Replaceall(tm, "$target", name); + Replaceall(tm, "$target", target_name); Replaceall(tm, "$value", value); Replaceall(tm, "$nsname", nsname); - Hash *nspaceHash = getNamespaceHash( getNSpace() ); + Hash *nspaceHash = getNamespaceHash( luaCurrentSymbolNSpace() ); String *s_const_tab = Getattr(nspaceHash, "constants"); Printf(s_const_tab, " %s,\n", tm); } else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) { Replaceall(tm, "$source", value); - Replaceall(tm, "$target", name); + Replaceall(tm, "$target", target_name); Replaceall(tm, "$value", value); Replaceall(tm, "$nsname", nsname); Printf(f_init, "%s\n", tm); @@ -959,34 +1027,35 @@ public: Swig_restore(n); return SWIG_NOWRAP; } - /* TODO: Review - if( v2_compatibility && getCurrentClass() ) { - if (!luaAddSymbol(iname, n, class_parent_nspace)) - return SWIG_ERROR; - Setattr(n, "sym:name", iname); - if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) { - Replaceall(tm, "$source", value); - Replaceall(tm, "$target", name); - Replaceall(tm, "$value", value); - Replaceall(tm, "$nsname", nsname); + if( make_v2_compatible ) { + Setattr(n_v2, "sym:name", target_name_v2); + tm_v2 = Swig_typemap_lookup("consttab", n_v2, name, 0); + if (tm_v2) { + //Printf(stdout, "tm v2: %s\n", tm_v2.ptr()); // TODO:REMOVE + Replaceall(tm_v2, "$source", value); + Replaceall(tm_v2, "$target", target_name_v2); + Replaceall(tm_v2, "$value", value); + Replaceall(tm_v2, "$nsname", nsname); Hash *nspaceHash = getNamespaceHash( class_parent_nspace ); String *s_const_tab = Getattr(nspaceHash, "constants"); - Printf(s_const_tab, " %s,\n", tm); - } else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) { - Replaceall(tm, "$source", value); - Replaceall(tm, "$target", name); - Replaceall(tm, "$value", value); - Replaceall(tm, "$nsname", nsname); - Printf(f_init, "%s\n", tm); + Printf(s_const_tab, " %s,\n", tm_v2.ptr()); } else { - Delete(nsname); - Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); - Swig_restore(n); - return SWIG_NOWRAP; + tm_v2 = Swig_typemap_lookup("constcode", n_v2, name, 0); + if( !tm_v2) { + // This can't be. + assert(false); + Swig_restore(n); + return SWIG_ERROR; + } + Replaceall(tm_v2, "$source", value); + Replaceall(tm_v2, "$target", target_name_v2); + Replaceall(tm_v2, "$value", value); + Replaceall(tm_v2, "$nsname", nsname); + Printf(f_init, "%s\n", tm_v2.ptr()); } } - */ + Swig_restore(n); Delete(nsname); return SWIG_OK; @@ -1019,9 +1088,11 @@ public: // So this is the exact copy of function from Language with // correct handling of namespaces String *oldNSpace = getNSpace(); + /* TODO: REVIEW/REMOVE_and_replace_with_Language::enumDeclaration if( getCurrentClass() == 0 ) { setNSpace(Getattr(n, "sym:nspace")); - } + }*/ + setNSpace(Getattr(n, "sym:nspace")); if (!ImportMode) { current[STATIC_CONST] = true; @@ -1054,12 +1125,11 @@ public: Setattr(n, "value", tmpValue); Setattr(n, "name", tmpValue); /* for wrapping of enums in a namespace when emit_action is used */ - constantWrapper(n); + int result = constantWrapper(n); Delete(tmpValue); Swig_restore(n); - // TODO: Backward compatibility: add ClassName_ConstantName member - return SWIG_OK; + return result; } /* ------------------------------------------------------------ @@ -1173,11 +1243,11 @@ public: // Replacing namespace with namespace + class in order to static // member be put inside class static area class_parent_nspace = getNSpace(); - setNSpace(class_static_nspace); + //setNSpace(class_static_nspace); TODO: REMOVE // Generate normal wrappers Language::classHandler(n); // Restore correct nspace - setNSpace(nspace); + //setNSpace(nspace); // TODO: REMOVE if remove above class_parent_nspace = 0; SwigType_add_pointer(t); @@ -1418,6 +1488,22 @@ public: return SWIG_OK; } + /* ---------------------------------------------------------------------- + * globalfunctionHandler() + * It can be called: + * 1. Usual C/C++ global function. + * 2. During class parsing for functions declared/defined as friend + * 3. During class parsing from staticmemberfunctionHandler + * ---------------------------------------------------------------------- */ + int globalfunctionHandler(Node *n) { + bool oldVal = current[NO_CPP]; + if(!current[STATIC_FUNC]) // If static funct, don't switch to NO_CPP + current[NO_CPP] = true; + int result = Language::globalfunctionHandler(n); + current[NO_CPP] = oldVal; + return result; + } + /* ----------------------------------------------------------------------- * staticmemberfunctionHandler() * @@ -1427,7 +1513,6 @@ public: virtual int staticmemberfunctionHandler(Node *n) { REPORT("staticmemberfunctionHandler", n); current[STATIC_FUNC] = true; - //String *symname = Getattr(n, "sym:name"); int result = Language::staticmemberfunctionHandler(n); current[STATIC_FUNC] = false;; @@ -1444,18 +1529,6 @@ public: Swig_restore(n); } - if (Getattr(n, "sym:nextSibling")) - return SWIG_OK; - - //Swig_require("luaclassobj_staticmemberfunctionHandler", n, "luaclassobj:wrap:name", NIL); - //String *name = Getattr(n, "name"); - //String *rname, *realname; - //realname = symname ? symname : name; - //rname = Getattr(n, "luaclassobj:wrap:name"); - // TODO: Add backward compatibility here: add "ClassName_FuncName" to global table - //Printv(s_cls_methods_tab, tab4, "{\"", realname, "\", ", rname, "}, \n", NIL); - //Swig_restore(n); - return SWIG_OK; } @@ -1495,13 +1568,10 @@ public: if( !GetFlag(n,"wrappedasconstant") ) { Setattr(n, "lua:name", v2_name); registerVariable( class_parent_nspace, n, "varget:wrap:name", "varset:wrap:name"); - } else { - Setattr(n, "lua:name", v2_name); - String* oldNSpace = getNSpace(); - setNSpace(class_parent_nspace); - constantWrapper(n); - setNSpace(oldNSpace); } + // If static member variable was wrapped as constant, then + // constant wrapper has already performed all actions + // necessary for v2_compatibility Delete(v2_name); Swig_restore(n); } @@ -1805,6 +1875,12 @@ public: // Recursively close all non-closed namespaces. Prints data to dataOutput, void closeNamespaces(File *dataOutput) { + // Special handling for empty module. + if( Getattr(namespaces_hash, "") == 0 ) { + // Module is empty. Create hash for global scope in order to have swig__Global + // variable in resulting file + getNamespaceHash(0); + } Iterator ki = First(namespaces_hash); List* to_close = NewList(); while (ki.key) { @@ -1904,14 +1980,19 @@ public: } } - - // Our implementation of addSymbol. Determines scope correctly, then calls Language::addSymbol - int luaAddSymbol(const String *s, const Node *n) { + // This function determines actual namespace/scope where any symbol at the + // current moment should be placed. It looks at the 'current' array + // and depending on where are we - static class member/function, + // instance class member/function or just global functions decides + // where symbol should be put. + // The namespace/scope doesn't depend from symbol, only from 'current' + String* luaCurrentSymbolNSpace() { String* scope = 0; // If ouside class, than NSpace is used. - if( !getCurrentClass()) + // If inside class, but current[NO_CPP], then this is friend function. It belongs to NSpace + if( !getCurrentClass() || current[NO_CPP]) { scope = getNSpace(); - else { + } else { // If inside class, then either class static namespace or class fully qualified name is used assert(!current[NO_CPP]); if(current[STATIC_FUNC] || current[STATIC_VAR] || current[STATIC_CONST] ) { @@ -1924,13 +2005,26 @@ public: } assert(scope != 0); } - //Printf(stdout, "addSymbol: %s scope: %s\n", s, scope); - return Language::addSymbol(s,n,scope); + return scope; + } + + // Our implementation of addSymbol. Determines scope correctly, then calls Language::addSymbol + int luaAddSymbol(const String *s, const Node *n) { + String *scope = luaCurrentSymbolNSpace(); + //Printf(stdout, "luaAddSymbol: %s scope: %s\n", s, scope); + int result = Language::addSymbol(s,n,scope); + if( !result ) + Printf(stderr,"addSymbol(%s to scope %s) failed\n",s, scope); + return result; } // Overload. Enforces given scope. Actually, it simply forwards call to Language::addSymbol int luaAddSymbol(const String*s, const Node*n, const_String_or_char_ptr scope) { - return Language::addSymbol(s,n,scope); + //Printf(stdout, "luaAddSymbol: %s scope: %s\n", s, scope); + int result = Language::addSymbol(s,n,scope); + if( !result ) + Printf(stderr,"addSymbol(%s to scope %s) failed\n",s, scope); + return result; } // Function creates fully qualified name of given symbol. Current NSpace and current class From 9d6cd75c7324397f866e0704deb6ed93ffdcf032 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Fri, 8 Nov 2013 13:20:20 +0400 Subject: [PATCH 0978/1160] Bugfixes --- Examples/test-suite/director_nspace.i | 2 +- .../test-suite/director_nspace_director_name_collision.i | 2 +- Examples/test-suite/lua/nspace_runme.lua | 2 +- Examples/test-suite/nspace_extend.i | 2 +- Lib/lua/luarun.swg | 4 ++++ Source/Modules/lua.cxx | 8 ++++---- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Examples/test-suite/director_nspace.i b/Examples/test-suite/director_nspace.i index 512077e8b..fdea75e2f 100644 --- a/Examples/test-suite/director_nspace.i +++ b/Examples/test-suite/director_nspace.i @@ -40,7 +40,7 @@ namespace TopLevel %include // nspace feature only supported by these languages -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGLUA) %nspace TopLevel::Bar::Foo; %nspace TopLevel::Bar::FooBar; #else diff --git a/Examples/test-suite/director_nspace_director_name_collision.i b/Examples/test-suite/director_nspace_director_name_collision.i index c6f13b451..8fd27c968 100644 --- a/Examples/test-suite/director_nspace_director_name_collision.i +++ b/Examples/test-suite/director_nspace_director_name_collision.i @@ -34,7 +34,7 @@ namespace TopLevel %include // nspace feature only supported by these languages -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGLUA) %nspace TopLevel::A::Foo; %nspace TopLevel::B::Foo; #else diff --git a/Examples/test-suite/lua/nspace_runme.lua b/Examples/test-suite/lua/nspace_runme.lua index 4eb0ffaf6..2ed8a86b7 100644 --- a/Examples/test-suite/lua/nspace_runme.lua +++ b/Examples/test-suite/lua/nspace_runme.lua @@ -10,7 +10,7 @@ ns = nspace -- Inheritance blue1 = ns.Outer.Inner3.Blue() -debug.debug() + -- blue1:blueInstanceMethod() blue1:colorInstanceMethod(60.0) blue1.instanceMemberVariable = 4 diff --git a/Examples/test-suite/nspace_extend.i b/Examples/test-suite/nspace_extend.i index 782ce90ca..e92ff8c1d 100644 --- a/Examples/test-suite/nspace_extend.i +++ b/Examples/test-suite/nspace_extend.i @@ -2,7 +2,7 @@ %module nspace_extend // nspace feature only supported by these languages -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGLUA) #if defined(SWIGJAVA) SWIG_JAVABODY_PROXY(public, public, SWIGTYPE) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 4ed260774..da8b8d3a7 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -70,6 +70,10 @@ extern "C" { # define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX) #endif +/* lua_absindex was introduced in Lua 5.2 */ +#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502 +# define lua_absindex(L,i) ((i)>0 || (i) <= LUA_REGISTRYINDEX ? (i) : lua_gettop(L) + (i) + 1) +#endif /* -------------------------------------------------------------------------- * Helper functions for error handling diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 824590b3a..4cfaca6ed 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -1712,7 +1712,7 @@ public: Printf(methods_tab, "static LUA_REG_TYPE "); else Printf(methods_tab, "static swig_lua_method "); - Printv(methods_tab, methods_tab_name, "[]"); + Printv(methods_tab, methods_tab_name, "[]", NIL); Printv(methods_tab_decl, methods_tab, ";\n", NIL); Printv(methods_tab, "= {\n", NIL); Setattr(nspace_hash, "methods", methods_tab ); @@ -1737,7 +1737,7 @@ public: String *classes_tab_name = NewStringf("swig_%s_classes", mangled_name ); String *classes_tab_decl = NewString(""); Printf(classes_tab, "static swig_lua_class* "); - Printv(classes_tab, classes_tab_name, "[]"); + Printv(classes_tab, classes_tab_name, "[]", NIL); Printv(classes_tab_decl, classes_tab, ";", NIL); Printv(classes_tab, "= {\n", NIL); Setattr(nspace_hash, "classes", classes_tab ); @@ -1748,7 +1748,7 @@ public: String* namespaces_tab_name = NewStringf("swig_%s_namespaces", mangled_name ); String* namespaces_tab_decl = NewString(""); Printf(namespaces_tab, "static swig_lua_namespace* "); - Printv(namespaces_tab, namespaces_tab_name, "[]"); + Printv(namespaces_tab, namespaces_tab_name, "[]", NIL); Printv(namespaces_tab_decl, namespaces_tab, ";", NIL); Printv(namespaces_tab, " = {\n", NIL); Setattr(nspace_hash, "namespaces", namespaces_tab ); @@ -1772,7 +1772,7 @@ public: if (!eluac_ltr) { String* metatable_tab = NewString(""); String* metatable_tab_name = NewStringf("swig_%s_meta", mangled_name); - Printv(metatable_tab, "const LUA_REG_TYPE ", metatable_tab_name, "[] = {\n"); + Printv(metatable_tab, "const LUA_REG_TYPE ", metatable_tab_name, "[] = {\n", NIL); Setattr(nspace_hash, "metatable", metatable_tab); Setattr(nspace_hash, "metatable:name", metatable_tab_name); } From c775e660480d76a7d067e04e5c620f142896e0e7 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sat, 9 Nov 2013 22:38:03 +0400 Subject: [PATCH 0979/1160] Fixes for elua --- Lib/lua/lua.swg | 8 +- Lib/lua/luarun.swg | 80 +++++++------ Lib/lua/luaruntime.swg | 5 + Source/Modules/lua.cxx | 247 ++++++++++++++++++++++++----------------- 4 files changed, 198 insertions(+), 142 deletions(-) diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg index 80c4c04c1..c470d9298 100644 --- a/Lib/lua/lua.swg +++ b/Lib/lua/lua.swg @@ -40,12 +40,14 @@ %typemap(consttab) long long, unsigned long long {SWIG_LUA_CONSTTAB_STRING("$symname", "$value")} -%typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] - { SWIG_LUA_POINTER, (char *)"$symname", 0, 0, (void *)$value, &$1_descriptor} +%typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE [] + { SWIG_LUA_CONSTTAB_POINTER("$symname",$value, $1_descriptor) } + //{ SWIG_LUA_POINTER, (char *)"$symname", 0, 0, (void *)$value, &$1_descriptor}// TODO: REMOVE // member function pointers %typemap(consttab) SWIGTYPE (CLASS::*) - { SWIG_LUA_BINARY, (char *)"$symname", sizeof($type), 0, (void *)&$value, &$1_descriptor} + { SWIG_LUA_CONSTTAB_BINARY("$symname", sizeof($type),&$value, $1_descriptor) } + //{ SWIG_LUA_BINARY, (char *)"$symname", sizeof($type), 0, (void *)&$value, &$1_descriptor}// TODO:REMOVE /* ----------------------------------------------------------------------------- diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index da8b8d3a7..04d4e93c3 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -32,11 +32,18 @@ extern "C" { # define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C) # define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C) # define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C) + // Those two types of constants are not supported in elua +# define SWIG_LUA_CONSTTAB_POINTER(B,C,D) LSTRKEY(B), LNILVAL +# define SWIG_LUA_CONSTTAB_BINARY(B, S, C, D) LSTRKEY(B), LNILVAL #else /* SWIG_LUA_FLAVOR_LUA */ # define SWIG_LUA_CONSTTAB_INT(B, C) SWIG_LUA_INT, (char *)B, (long)C, 0, 0, 0 # define SWIG_LUA_CONSTTAB_FLOAT(B, C) SWIG_LUA_FLOAT, (char *)B, 0, (double)C, 0, 0 # define SWIG_LUA_CONSTTAB_STRING(B, C) SWIG_LUA_STRING, (char *)B, 0, 0, (void *)C, 0 # define SWIG_LUA_CONSTTAB_CHAR(B, C) SWIG_LUA_CHAR, (char *)B, (long)C, 0, 0, 0 +# define SWIG_LUA_CONSTTAB_POINTER(B,C,D)\ + SWIG_LUA_POINTER, (char *)B, 0, 0, (void *)C, &D +# define SWIG_LUA_CONSTTAB_BINARY(B, S, C, D)\ + SWIG_LUA_BINARY, (char *)B, S, 0, (void *)C, &D #endif #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC) @@ -44,6 +51,10 @@ extern "C" { # define LSTRVAL LRO_STRVAL #endif +#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC) +#include "lrodefs.h" +#include "lrotable.h" +#endif /* ----------------------------------------------------------------------------- * compatibility defines * ----------------------------------------------------------------------------- */ @@ -123,6 +134,12 @@ typedef struct { lua_CFunction set; } swig_lua_var_info; +#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC) +typedef const LUA_REG_TYPE swig_lua_method; +typedef const LUA_REG_TYPE swig_lua_const_info; +#else // Normal lua +typedef luaL_Reg swig_lua_method; + /* Constant information structure */ typedef struct { int type; @@ -133,7 +150,7 @@ typedef struct { swig_type_info **ptype; } swig_lua_const_info; -typedef luaL_Reg swig_lua_method; +#endif typedef struct { const char *name; @@ -343,6 +360,7 @@ SWIGINTERN int SWIG_Lua_namespace_set(lua_State* L) return 0; } +#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) // In elua this is useless SWIGINTERN void SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]); // forward declaration SWIGINTERN void SWIG_Lua_add_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn); // forward declaration SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss); @@ -366,17 +384,6 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* SWIG_Lua_add_variable(L,ns->ns_attributes[i].name,ns->ns_attributes[i].getmethod,ns->ns_attributes[i].setmethod); } -#if 0 - // TODO: REMOVE. .fn table is unused - /* add methods to the metatable */ - SWIG_Lua_get_table(L,".fn"); /* find the .fn table */ - assert(lua_istable(L,-1)); /* just in case */ - for(i=0;ns->ns_methods[i].name;i++){ - SWIG_Lua_add_function(L,ns->ns_methods[i].name,ns->ns_methods[i].func); - } - lua_pop(L,1); -#endif - /* clear stack - remove metatble */ lua_pop(L,1); return 0; @@ -452,6 +459,7 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns, } assert(lua_gettop(L) == begin+1); } +#endif // SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA /* ----------------------------------------------------------------------------- * global variable support code: classes * ----------------------------------------------------------------------------- */ @@ -601,7 +609,6 @@ printf("SWIG_Lua_class_set %p(%s) '%s' %p(%s)\n", lua_pushvalue(L,base+3); /* value */ lua_call(L,2,0); lua_remove(L,base+4); /*remove metatable*/ - assert(lua_gettop(L) == base+3); // TODO:REMOVE return 0; } lua_pop(L,1); /* remove the value */ @@ -776,6 +783,29 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State* L,const char* cname) lua_remove(L,-2); /* tidy up (remove registry) */ } +/* set up the base classes pointers. +Each class structure has a list of pointers to the base class structures. +This function fills them. +It cannot be done at compile time, as this will not work with hireachies +spread over more than one swig file. +Therefore it must be done at runtime, querying the SWIG type system. +*/ +SWIGINTERN void SWIG_Lua_init_base_class(lua_State* L,swig_lua_class* clss) +{ + int i=0; + swig_module_info* module=SWIG_GetModule(L); + for(i=0;clss->base_names[i];i++) + { + if (clss->bases[i]==0) /* not found yet */ + { + /* lookup and cache the base class */ + swig_type_info *info = SWIG_TypeQueryModule(module,module,clss->base_names[i]); + if (info) clss->bases[i] = (swig_lua_class *) info->clientdata; + } + } +} + +#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) // In elua this is useless /* helper add a variable to a registered class */ SWIGINTERN void SWIG_Lua_add_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn) { @@ -848,28 +878,6 @@ SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State* L,swig_lua_class } } -/* set up the base classes pointers. -Each class structure has a list of pointers to the base class structures. -This function fills them. -It cannot be done at compile time, as this will not work with hireachies -spread over more than one swig file. -Therefore it must be done at runtime, querying the SWIG type system. -*/ -SWIGINTERN void SWIG_Lua_init_base_class(lua_State* L,swig_lua_class* clss) -{ - int i=0; - swig_module_info* module=SWIG_GetModule(L); - for(i=0;clss->base_names[i];i++) - { - if (clss->bases[i]==0) /* not found yet */ - { - /* lookup and cache the base class */ - swig_type_info *info = SWIG_TypeQueryModule(module,module,clss->base_names[i]); - if (info) clss->bases[i] = (swig_lua_class *) info->clientdata; - } - } -} - /* Register class static methods,attributes etc as well as constructor proxy */ SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* clss) { @@ -1001,7 +1009,7 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss) lua_pop(L,2); assert(lua_gettop(L) == begin); } - +#endif // SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA /* ----------------------------------------------------------------------------- * Class/structure conversion fns * ----------------------------------------------------------------------------- */ diff --git a/Lib/lua/luaruntime.swg b/Lib/lua/luaruntime.swg index 5e4ba9fd9..758544185 100644 --- a/Lib/lua/luaruntime.swg +++ b/Lib/lua/luaruntime.swg @@ -53,9 +53,14 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */ #ifdef SWIG_LUA_MODULE_GLOBAL globalRegister = 1; #endif + + +#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) SWIG_Lua_namespace_register(L,&swig___Global, globalRegister); #endif +#endif + #if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)) /* constants */ /* TODO: REMOVE */ diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 4cfaca6ed..3a8822ccd 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -150,8 +150,10 @@ void DohDelete(DohPtrGuard& /*guard*/) { NEW LANGUAGE NOTE:END ************************************************/ static const char *usage = (char *) "\ Lua Options (available with -lua)\n\ - -elua - Generates LTR compatible wrappers for smaller devices running elua\n\ - -eluac - LTR compatible wrappers in \"crass compress\" mode for elua\n\ + -elua [NUM] - Generates LTR compatible wrappers for smaller devices running elua\n\ + Optional NUM is default value for MIN_OPT_LEVEL\n\ + -eluac [NUM] - LTR compatible wrappers in \"crass compress\" mode for elua\n\ + Optional NUM is default value for MIN_OPT_LEVEL\n\ -nomoduleglobal - Do not register the module name as a global variable \n\ but return the module table from calls to require.\n\ -api-lvl-from NUM\n\ @@ -168,6 +170,7 @@ Lua Options (available with -lua)\n\ static int nomoduleglobal = 0; static int elua_ltr = 0; +static int elua_opt_lvl = 2; static int eluac_ltr = 0; static int v2_compatibility = 0; static const int default_api_level = 2; @@ -187,8 +190,6 @@ private: File *f_wrappers; File *f_init; File *f_initbeforefunc; - String *s_methods_tab; // table of class methods - String *s_attr_tab; // table of class attributes String *s_luacode; // luacode to be called during init String *module; //name of the module Hash* namespaces_hash; @@ -238,8 +239,6 @@ public: f_wrappers(0), f_init(0), f_initbeforefunc(0), - s_methods_tab(0), - s_attr_tab(0), s_luacode(0), module(0), have_constructor(0), @@ -265,6 +264,17 @@ public: which depends upon what args your code supports NEW LANGUAGE NOTE:END ************************************************/ + bool strToInt(const char* string, int& value) { + long int tmp; + char *p_end = 0; + if(string == 0) + return false; + tmp = strtol(string,&p_end,10); + if( p_end == 0 || *p_end != 0 ) + return false; + value = tmp; + return true; + } /* --------------------------------------------------------------------- * main() * @@ -288,13 +298,20 @@ public: } else if(strcmp(argv[i], "-elua") == 0) { elua_ltr = 1; Swig_mark_arg(i); + if(strToInt(argv[i+1],elua_opt_lvl)) { + Swig_mark_arg(i+1); + i++; + } } else if(strcmp(argv[i], "-eluac") == 0) { eluac_ltr = 1; Swig_mark_arg(i); + if(strToInt(argv[i+1],elua_opt_lvl)) { + Swig_mark_arg(i+1); + i++; + } } else if(strcmp(argv[i], "-api-lvl-from") == 0) { if(argv[i+1]) { - api_level = atoi(argv[i+1]); - if(api_level == 0) + if(!strToInt(argv[i+1], api_level)) Swig_arg_error(); Swig_mark_arg(i+1); i++; @@ -392,6 +409,12 @@ public: emitLuaFlavor(f_runtime); + if (elua_ltr || eluac_ltr) + Printf(f_runtime, + "#ifndef MIN_OPT_LEVEL\n"\ + "#define MIN_OPT_LEVEL %d\n"\ + "#endif\n", elua_opt_lvl); + if (nomoduleglobal) { Printf(f_runtime, "#define SWIG_LUA_NO_MODULE_GLOBAL\n"); } else { @@ -415,8 +438,14 @@ public: Printf(f_header, "#define SWIG_LUACODE luaopen_%s_luacode\n", module); if (elua_ltr || eluac_ltr) { - Printf(f_header, "\n#define MIN_OPT_LEVEL 2\n#include \"lrodefs.h\"\n"); + /* TODO: REMOVE + Printf(f_header, + "#ifndef MIN_OPT_LEVEL\n"\ + "#define MIN_OPT_LEVEL %d\n"\ + "#endif\n", elua_opt_lvl); + Printf(f_header, "#include \"lrodefs.h\"\n"); Printf(f_header, "#include \"lrotable.h\"\n"); + */ Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); } else { Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); @@ -525,6 +554,20 @@ public: Setattr(n, "varget:wrap:name", wrapname); } + // Add method to the "methods" C array of given namespace/class + void registerMethod(String *nspace_or_class_name, Node* n) { + assert(n != 0); + Hash* nspaceHash = getNamespaceHash( nspace_or_class_name ); + String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); + String *wname = Getattr(n, "wrap:name"); + String *iname = Getattr(n, "sym:name"); + String *target_name = Getattr(n, "lua:name"); + if(elua_ltr || eluac_ltr) + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", iname, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); + else + Printv(s_ns_methods_tab, tab4, "{ \"", target_name, "\", ", wname, "},\n", NIL); + } + // Helper for functionWrapper - determines whether we should // register method in the appropriate class/namespace/module // table or not. @@ -943,6 +986,32 @@ public: * variableWrapper() * ------------------------------------------------------------ */ + // Add variable to the "attributes" (or "get"/"set" in + // case of elua_ltr) C arrays of given namespace or class + void registerVariable(String *nspace_or_class_name, Node* n, const char *getAttrName, const char *setAttrName) { + String *unassignable = NewString("SWIG_Lua_set_immutable"); + String *getName = Getattr(n,getAttrName); + String *setName = Getattr(n,setAttrName); + if(setName == 0 || GetFlag(n, "feature:immutable")) { + setName = unassignable; + } + Hash* nspaceHash = getNamespaceHash( nspace_or_class_name ); + String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); + String* s_ns_var_tab = Getattr(nspaceHash, "attributes"); + String *target_name = Getattr(n, "lua:name"); + if (elua_ltr) { + String* s_ns_dot_get = Getattr(nspaceHash, "get"); + String* s_ns_dot_set = Getattr(nspaceHash, "set"); + Printf(s_ns_dot_get, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, target_name, getName); + Printf(s_ns_dot_set, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, target_name, setName); + } else if (eluac_ltr) { + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", target_name, "_get", "\")", ", LFUNCVAL(", getName, ")", "},\n", NIL); + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", target_name, "_set", "\")", ", LFUNCVAL(", setName, ")", "},\n", NIL); + } else { + Printf(s_ns_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, target_name, getName, setName); + } + } + virtual int variableWrapper(Node *n) { /* NEW LANGUAGE NOTE:*********************************************** Language::variableWrapper(n) will generate two wrapper fns @@ -962,9 +1031,34 @@ public: return result; } + /* ------------------------------------------------------------ * constantWrapper() * ------------------------------------------------------------ */ + + /* Add constant to appropriate C array. constantRecord is an array record. + * Actually, in current implementation it is resolved consttab typemap + */ + void registerConstant( String *nspace, String *constantRecord ) { + Hash *nspaceHash = getNamespaceHash( nspace ); + String *s_const_tab = 0; + if( eluac_ltr || elua_ltr ) + // In elua everything goes to "methods" tab + s_const_tab = Getattr(nspaceHash, "methods"); + else + s_const_tab = Getattr(nspaceHash, "constants"); + + assert(s_const_tab != 0); + Printf(s_const_tab, " %s,\n", constantRecord); + + if( ( eluac_ltr || elua_ltr ) && v2_compatibility ) { + s_const_tab = Getattr(nspaceHash, "constants"); + assert(s_const_tab != 0); + Printf(s_const_tab, " %s,\n", constantRecord); + } + + } + virtual int constantWrapper(Node *n) { REPORT("constantWrapper", n); String *name = Getattr(n, "name"); @@ -1012,9 +1106,7 @@ public: Replaceall(tm, "$target", target_name); Replaceall(tm, "$value", value); Replaceall(tm, "$nsname", nsname); - Hash *nspaceHash = getNamespaceHash( luaCurrentSymbolNSpace() ); - String *s_const_tab = Getattr(nspaceHash, "constants"); - Printf(s_const_tab, " %s,\n", tm); + registerConstant( luaCurrentSymbolNSpace(), tm); } else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) { Replaceall(tm, "$source", value); Replaceall(tm, "$target", target_name); @@ -1037,9 +1129,7 @@ public: Replaceall(tm_v2, "$target", target_name_v2); Replaceall(tm_v2, "$value", value); Replaceall(tm_v2, "$nsname", nsname); - Hash *nspaceHash = getNamespaceHash( class_parent_nspace ); - String *s_const_tab = Getattr(nspaceHash, "constants"); - Printf(s_const_tab, " %s,\n", tm_v2.ptr()); + registerConstant( class_parent_nspace, tm); } else { tm_v2 = Swig_typemap_lookup("constcode", n_v2, name, 0); if( !tm_v2) { @@ -1212,8 +1302,6 @@ public: // any member or subclass with name "__Static". Thus, never any name clash. Hash* instance_cls = getNamespaceHash(class_fq_symname, false); assert(instance_cls != 0); - s_attr_tab = Getattr(instance_cls, "attributes"); - s_methods_tab = Getattr(instance_cls, "methods"); String* s_attr_tab_name = Getattr(instance_cls, "attributes:name"); String* s_methods_tab_name = Getattr(instance_cls, "methods:name"); Setattr(instance_cls, "lua:no_namespaces", "1"); @@ -1237,9 +1325,6 @@ public: /* There is no use for "classes" and "namespaces" arrays. Subclasses are not supported * by SWIG and namespaces couldn't be nested inside classes (C++ Standard) */ - assert(s_attr_tab != 0); - assert(s_methods_tab != 0); - // Replacing namespace with namespace + class in order to static // member be put inside class static area class_parent_nspace = getNSpace(); @@ -1396,32 +1481,25 @@ public: * ------------------------------------------------------------ */ virtual int memberfunctionHandler(Node *n) { - String *name = Getattr(n, "name"); - String *iname = GetChar(n, "sym:name"); + String *symname = GetChar(n, "sym:name"); //Printf(stdout,"memberfunctionHandler %s %s\n",name,iname); // Special case unary minus: LUA passes two parameters for the // wrapper function while we want only one. Tell our // functionWrapper to ignore a parameter. - if (Cmp(Getattr(n, "sym:name"), "__unm") == 0) { + if (Cmp(symname, "__unm") == 0) { //Printf(stdout, "unary minus: ignore one argument\n"); SetInt(n, "lua:ignore_args", 1); } - String *realname, *rname; - current[MEMBER_FUNC] = true; Language::memberfunctionHandler(n); current[MEMBER_FUNC] = false; - realname = iname ? iname : name; - rname = Getattr(n, "wrap:name"); - assert(rname != 0); if (!Getattr(n, "sym:nextSibling")) { - Printv(s_methods_tab, tab4, "{\"", realname, "\", ", rname, "}, \n", NIL); + registerMethod( luaCurrentSymbolNSpace(), n); } - Delete(rname); return SWIG_OK; } @@ -1431,30 +1509,10 @@ public: virtual int membervariableHandler(Node *n) { // REPORT("membervariableHandler",n); - String *symname = Getattr(n, "sym:name"); - String *getter_name, *setter_name; - current[MEMBER_VAR] = true; Language::membervariableHandler(n); current[MEMBER_VAR] = false; - getter_name = Getattr(n, "memberget:wrap:name"); - assert(getter_name != 0); - if (!GetFlag(n, "feature:immutable")) { - setter_name = Getattr(n, "memberset:wrap:name"); - assert(setter_name != 0); - } else { - //setter_name = NewString("0"); - setter_name = NewString("SWIG_Lua_set_immutable"); // error message - } - Printf(s_attr_tab,"%s{ \"%s\", %s, %s},\n",tab4,symname,getter_name,setter_name); - /*if (eluac_ltr) { TODO: FIX for eluac and uncomments - Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", class_name, "_", symname, "_get", "\")", \ - ", LFUNCVAL(", getter_name, ")", "},\n", NIL); - Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", class_name, "_", symname, "_set", "\")", \ - ", LFUNCVAL(", setter_name, ")", "},\n", NIL); - }*/ - Delete(getter_name); - Delete(setter_name); + registerVariable( luaCurrentSymbolNSpace(), n, "memberget:wrap:name", "memberset:wrap:name" ); return SWIG_OK; } @@ -1709,7 +1767,7 @@ public: String *methods_tab_name = NewStringf("swig_%s_methods", mangled_name ); String *methods_tab_decl = NewString(""); if (elua_ltr || eluac_ltr) // In this case methods array also acts as namespace rotable - Printf(methods_tab, "static LUA_REG_TYPE "); + Printf(methods_tab, "const LUA_REG_TYPE "); else Printf(methods_tab, "static swig_lua_method "); Printv(methods_tab, methods_tab_name, "[]", NIL); @@ -1723,7 +1781,7 @@ public: String *const_tab_name = NewStringf("swig_%s_constants", mangled_name ); String *const_tab_decl = NewString(""); if (elua_ltr || eluac_ltr) // In this case const array holds rotable with namespace constants - Printf(const_tab, "static LUA_REG_TYPE "); + Printf(const_tab, "const LUA_REG_TYPE "); else Printf(const_tab, "static swig_lua_const_info "); Printv(const_tab, const_tab_name, "[]", NIL); @@ -1759,22 +1817,34 @@ public: // TODO: add xxx:decl here too String *get_tab = NewString(""); String *get_tab_name = NewStringf("swig_%s_get", mangled_name); - Printv(get_tab, "const LUA_REG_TYPE ", get_tab_name, "[] = {\n", NIL); + String *get_tab_decl = NewString(""); + Printv(get_tab, "const LUA_REG_TYPE ", get_tab_name, "[]", NIL); + Printv(get_tab_decl, get_tab, ";", NIL); + Printv(get_tab, " = {\n", NIL); Setattr(nspace_hash, "get", get_tab); Setattr(nspace_hash, "get:name", get_tab_name); + Setattr(nspace_hash, "get:decl", get_tab_decl); String *set_tab = NewString(""); String *set_tab_name = NewStringf("swig_%s_set", mangled_name); - Printv(set_tab, "const LUA_REG_TYPE ", set_tab_name, "[] = {\n", NIL); + String *set_tab_decl = NewString(""); + Printv(set_tab, "const LUA_REG_TYPE ", set_tab_name, "[]", NIL); + Printv(set_tab_decl, set_tab, ";", NIL); + Printv(set_tab, " = {\n", NIL); Setattr(nspace_hash, "set", set_tab); Setattr(nspace_hash, "set:name", set_tab_name); + Setattr(nspace_hash, "set:decl", set_tab_decl); if (!eluac_ltr) { String* metatable_tab = NewString(""); String* metatable_tab_name = NewStringf("swig_%s_meta", mangled_name); - Printv(metatable_tab, "const LUA_REG_TYPE ", metatable_tab_name, "[] = {\n", NIL); + String *metatable_tab_decl = NewString(""); + Printv(metatable_tab, "const LUA_REG_TYPE ", metatable_tab_name, "[]", NIL); + Printv(metatable_tab_decl, metatable_tab, ";", NIL); + Printv(metatable_tab, " = {\n", NIL); Setattr(nspace_hash, "metatable", metatable_tab); Setattr(nspace_hash, "metatable:name", metatable_tab_name); + Setattr(nspace_hash, "metatable:decl", metatable_tab_decl); } } String* key = 0; @@ -1814,12 +1884,19 @@ public: Printf(const_tab, " {0,0,0,0,0,0}\n};\n"); Printv(output, const_tab, NIL); + if (elua_ltr) { + // Put forward declaration of metatable array + Printv(output, "extern ", Getattr(nspace_hash, "metatable:decl"), "\n", NIL); + } String* methods_tab = Getattr(nspace_hash, "methods"); String* metatable_tab_name = Getattr(nspace_hash, "metatable:name"); if (elua_ltr || eluac_ltr) { - Printv(methods_tab, tab4, "{LSTRKEY(\"const\"), LROVAL(", const_tab_name, ")},\n", NIL); + if( v2_compatibility ) + Printv(methods_tab, tab4, "{LSTRKEY(\"const\"), LROVAL(", const_tab_name, ")},\n", NIL); if (elua_ltr) Printv(methods_tab, tab4, "{LSTRKEY(\"__metatable\"), LROVAL(", metatable_tab_name, ")},\n", NIL); + + Printv(methods_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); } else Printf(methods_tab, " {0,0}\n};\n"); Printv(output, methods_tab, NIL); @@ -1847,22 +1924,26 @@ public: String *metatable_tab = Getattr(nspace_hash, "metatable"); assert(metatable_tab != 0); - Printv(metatable_tab, tab4, "{LSTRKEY(\"__index\"), LFUNCVAL(SWIG_Lua_module_get)},\n", NIL); - Printv(metatable_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_module_set)},\n", NIL); + Printv(metatable_tab, tab4, "{LSTRKEY(\"__index\"), LFUNCVAL(SWIG_Lua_namespace_get)},\n", NIL); + Printv(metatable_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_namespace_set)},\n", NIL); Printv(metatable_tab, tab4, "{LSTRKEY(\".get\"), LROVAL(", get_tab_name, ")},\n", NIL); Printv(metatable_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(", set_tab_name, ")},\n", NIL); if (Getattr(nspace_hash, "lua:class_instance")) { String *static_cls = Getattr(nspace_hash, "lua:class_instance:static_hash"); assert(static_cls != 0); - String *static_cls_cname = Getattr(static_cls, "cname"); + // static_cls is swig_lua_namespace. This structure can't be use with eLua(LTR) + // Instead structure describing its methods isused + String *static_cls_cname = Getattr(static_cls, "methods:name"); assert(static_cls_cname != 0); - Printv(metatable_tab, tab4, "LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL); + Printv(metatable_tab, tab4, "{LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL); + // Put forward declaration of this array + Printv(output, "extern ", Getattr(static_cls, "methods:decl"), "\n", NIL); } else if (Getattr(nspace_hash, "lua:class_static") ) { Hash *instance_cls = Getattr(nspace_hash, "lua:class_static:instance_hash"); assert(instance_cls != 0); String *instance_cls_metatable_name = Getattr(instance_cls, "metatable:name"); assert(instance_cls_metatable_name != 0); - Printv(metatable_tab, tab4, "LSTRKEY(\".static\"), LROVAL(", instance_cls_metatable_name, ")},\n", NIL); + Printv(metatable_tab, tab4, "{LSTRKEY(\".instance\"), LROVAL(", instance_cls_metatable_name, ")},\n", NIL); } Printv(metatable_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); @@ -1935,51 +2016,11 @@ public: tab4, attr_tab_name, ",\n", tab4, const_tab_name, ",\n", tab4, (has_classes)?classes_tab_name:null_string.ptr(), ",\n", - tab4, (has_namespaces)?namespaces_tab_name:null_string.ptr(), "};\n", + tab4, (has_namespaces)?namespaces_tab_name:null_string.ptr(), "\n};\n", NIL ); } - // Add method to the "methods" C array of given namespace/class - void registerMethod(String *nspace_or_class_name, Node* n) { - assert(n != 0); - Hash* nspaceHash = getNamespaceHash( nspace_or_class_name ); - String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); - String *wname = Getattr(n, "wrap:name"); - String *iname = Getattr(n, "sym:name"); - String *target_name = Getattr(n, "lua:name"); - if(elua_ltr || eluac_ltr) - Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", iname, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); - else - Printv(s_ns_methods_tab, tab4, "{ \"", target_name, "\", ", wname, "},\n", NIL); - } - - // Add variable to the "attributes" (or "get"/"set" in - // case of elua_ltr) C arrays of given namespace or class - void registerVariable(String *nspace_or_class_name, Node* n, const char *getAttrName, const char *setAttrName) { - String *unassignable = NewString("SWIG_Lua_set_immutable"); - String *getName = Getattr(n,getAttrName); - String *setName = Getattr(n,setAttrName); - if(setName == 0) { - setName = unassignable; - } - Hash* nspaceHash = getNamespaceHash( nspace_or_class_name ); - String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); - String* s_ns_var_tab = Getattr(nspaceHash, "attributes"); - String *target_name = Getattr(n, "lua:name"); - if (elua_ltr) { - String* s_ns_dot_get = Getattr(nspaceHash, "get"); - String* s_ns_dot_set = Getattr(nspaceHash, "set"); - Printf(s_ns_dot_get, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, target_name, getName); - Printf(s_ns_dot_set, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, target_name, setName); - } else if (eluac_ltr) { - Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", target_name, "_get", "\")", ", LFUNCVAL(", getName, ")", "},\n", NIL); - Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", target_name, "_set", "\")", ", LFUNCVAL(", setName, ")", "},\n", NIL); - } else { - Printf(s_ns_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, target_name, getName, setName); - } - } - // This function determines actual namespace/scope where any symbol at the // current moment should be placed. It looks at the 'current' array // and depending on where are we - static class member/function, From afd269f9b619eeecd6d8557d3f3ef19cd20069bb Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Mon, 11 Nov 2013 00:11:13 +0400 Subject: [PATCH 0980/1160] Some class bases iteration improvements --- Lib/lua/luarun.swg | 311 ++++++++++++++++++++++++--------------------- 1 file changed, 166 insertions(+), 145 deletions(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 04d4e93c3..632dbd512 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -464,17 +464,108 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns, * global variable support code: classes * ----------------------------------------------------------------------------- */ -/* the class.get method, performs the lookup of class attributes - * Method can be called from Lua directly and recursively from itself. Thats why - * we can't use absolute stack positions +SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State* L,const char* cname); + +/* Macroses for iteration among class bases */ +#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) +#define SWIG_LUA_INIT_BASE_SEARCH(bases_count)\ + SWIG_Lua_get_table(L,".bases");\ + assert(lua_istable(L,-1));\ + bases_count = lua_rawlen(L,-1);\ + int bases_table = lua_gettop(L); +#define SWIG_LUA_GET_BASE_METATABLE(i,base_swig_type, valid)\ + lua_rawgeti(L,bases_table,i+1);\ + base_swig_type = 0;\ + if(lua_isnil(L,-1)) {\ + valid = false;\ + lua_pop(L,1);\ + } else\ + valid = true; + +#else // en elua .bases table doesn't exist. Use table from swig_lua_class + +#define SWIG_LUA_INIT_BASE_SEARCH(bases_count)\ + swig_module_info* module=SWIG_GetModule(L);\ + swig_lua_class **bases= ((swig_lua_class*)(swig_type->clientdata))->bases;\ + const char **base_names= ((swig_lua_class*)(swig_type->clientdata))->base_names;\ + bases_count = 0;\ + for(;base_names[bases_count];bases_count++);// get length of bases + +#define SWIG_LUA_GET_BASE_METATABLE(i,base_swig_type, valid)\ + swig_lua_class *base_class = bases[i];\ + if(!base_class)\ + valid = false;\ + else {\ + valid = true;\ + SWIG_Lua_get_class_metatable(L,base_class->fqname);\ + base_swig_type = SWIG_TypeQueryModule(module,module,base_class->fqname);\ + } + +#endif + +typedef int (*swig_lua_base_iterator_func)(lua_State*,swig_type_info*, int, int& ret); + +int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info* swig_type, int first_arg, swig_lua_base_iterator_func func, int& ret) +{ + // first_arg - position of the object in stack. Everything that is above are arguments + // and is passed to every evocation of the func + int last_argument = lua_gettop(L);// position of last argument + lua_getmetatable(L,first_arg); + int original_metatable = last_argument + 1; + int bases_count; + SWIG_LUA_INIT_BASE_SEARCH(bases_count); + int result = SWIG_OK; + ret = 0; + if(bases_count>0) + { + int i; + int j; + int subcall_start = lua_gettop(L) + 1;// Here a copy of first_arg and arguments begin + bool valid = true; + for(j=first_arg;j<=last_argument;j++) + lua_pushvalue(L,j); + int subcall_end = lua_gettop(L); + swig_type_info *base_swig_type = 0; + + // Trick: temporaly replacing original metatable + // with metatable for base class and call getter + for(i=0;i0) - { - int original_metatable = lua_absindex(L,-2); - int i; - int ret = 0; // Number of returned values - lua_pushvalue(L,base+1); // push userdata - lua_pushvalue(L,base+2); // Push key again - // Trick: temporaly replacing original metatable - // with metatable for base class and call getter - for(i=0;i0) - break; - } - // Return original metatable back - lua_pushvalue(L,original_metatable); - lua_setmetatable(L,base+1); - if(ret>0) - { - // tidy stack. Stack currently is: - // --base-- - // userdata - // key - // metatable - // .bases table - // userdata - // key : -2 - // return value : -1 - lua_remove(L,-2); // remove key - lua_remove(L,-2); // remove userdata - lua_remove(L,-2); // remove .bases - lua_remove(L,-2); // remove metatable - return 1; - } else { - lua_pop(L,2); // remove key and userdata - } - } - // Tidy stack: - // --base-- - // userdata - // key - // metatable - // .bases table - lua_pop(L,2); - assert(lua_gettop(L)==base+2); - return 0; /* sorry not known */ + int bases_search_result = SWIG_Lua_iterate_bases(L,type,substack_start+1,SWIG_Lua_class_do_get,ret); + return bases_search_result; /* sorry not known */ +} + +/* the class.get method, performs the lookup of class attributes + */ +SWIGINTERN int SWIG_Lua_class_get(lua_State* L) +{ +/* there should be 2 params passed in + (1) userdata (not the meta table) + (2) string name of the attribute +*/ + assert(lua_isuserdata(L,1)); + swig_lua_userdata *usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */ + swig_type_info *type = usr->type; + int ret = 0; + int result = SWIG_Lua_class_do_get(L,type,1,ret); + if(result == SWIG_OK) + return ret; + + return 0; } /* helper for the class.set method, performs the lookup of class attributes - * Method can be called from SWIG_Lua_class_set or recursively from itself + * It returns error code. Number of function return values is passed inside 'ret' */ -SWIGINTERN int SWIG_Lua_class_do_set(lua_State* L) +SWIGINTERN int SWIG_Lua_class_do_set(lua_State* L, swig_type_info *type, int first_arg, int& ret) { /* there should be 3 params passed in (1) table (not the meta table) (2) string name of the attribute (3) any for the new value -printf("SWIG_Lua_class_set %p(%s) '%s' %p(%s)\n", - lua_topointer(L,-3),lua_typename(L,lua_type(L,-3)), - lua_tostring(L,-2), - lua_topointer(L,-1),lua_typename(L,lua_type(L,-1)));*/ + */ - int base = lua_gettop(L) - 3; + int substack_start = lua_gettop(L) - 3; lua_checkstack(L,5); - assert(lua_isuserdata(L,base+1)); /* just in case */ - lua_getmetatable(L,base+1); /* get the meta table */ + assert(lua_isuserdata(L,substack_start+1)); /* just in case */ + lua_getmetatable(L,substack_start+1); /* get the meta table */ assert(lua_istable(L,-1)); /* just in case */ + ret = 0; // it is setter - number of return values is always 0 SWIG_Lua_get_table(L,".set"); /* find the .set table */ if (lua_istable(L,-1)) { /* look for the key in the .set table */ - lua_pushvalue(L,base+2); /* key */ + lua_pushvalue(L,substack_start+2); /* key */ lua_rawget(L,-2); lua_remove(L,-2); /* tidy stack, remove .set table */ if (lua_iscfunction(L,-1)) { /* found it so call the fn & return its value */ - lua_pushvalue(L,base+1); /* userdata */ - lua_pushvalue(L,base+3); /* value */ + lua_pushvalue(L,substack_start+1); /* userdata */ + lua_pushvalue(L,substack_start+3); /* value */ lua_call(L,2,0); - lua_remove(L,base+4); /*remove metatable*/ - return 0; + lua_remove(L,substack_start+4); /*remove metatable*/ + return SWIG_OK; } lua_pop(L,1); /* remove the value */ } else { lua_pop(L,1); /* remove the answer for .set table request*/ } - assert(lua_gettop(L) == base + 4); // TODO: REMOVE + assert(lua_gettop(L) == substack_start + 4); // TODO: REMOVE /* NEW: looks for the __setitem() fn this is a user provided set fn */ SWIG_Lua_get_table(L,"__setitem"); /* find the fn */ if (lua_iscfunction(L,-1)) /* if its there */ { /* found it so call the fn & return its value */ - lua_pushvalue(L,base+1); /* the userdata */ - lua_pushvalue(L,base+2); /* the parameter */ - lua_pushvalue(L,base+3); /* the value */ + lua_pushvalue(L,substack_start+1); /* the userdata */ + lua_pushvalue(L,substack_start+2); /* the parameter */ + lua_pushvalue(L,substack_start+3); /* the value */ lua_call(L,3,0); /* 3 values in ,0 out */ lua_remove(L,-2); /* stack tidy, remove metatable */ - return 0; + return SWIG_OK; } lua_pop(L,1); // remove value - assert(lua_gettop(L) == base + 4); // TODO: REMOVE - - // Search among bases - int original_metatable = base+4; - assert(lua_gettop(L) == original_metatable); // Check that stack is correct - SWIG_Lua_get_table(L,".bases"); - assert(lua_istable(L,-1)); - int bases_count = lua_rawlen(L,-1); - if(bases_count>0) - { - int i = 0; - int ret = 0; - lua_pushvalue(L,base+1); // push userdata - lua_pushvalue(L,base+2); // Push key again - lua_pushvalue(L,base+3); // Push value again - // Trick: temporaly replacing original metatable - // with metatable for base class and call getter - for(i=0;itype; + int ret = 0; + int result = SWIG_Lua_class_do_set(L,type,1,ret); + if(result != SWIG_OK) { SWIG_Lua_pushferrstring(L,"Assignment not possible. No setter/member with this name. For custom assignments implement __setitem method"); lua_error(L); } else { - assert(0); // Internal implementation error + assert(ret==0); return 0; } } From dcbcac42b762ee5f07197a75435684822bf00ef1 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Mon, 11 Nov 2013 11:33:27 +0400 Subject: [PATCH 0981/1160] A few bugfixes --- Lib/lua/luarun.swg | 48 +++++++++++++++++++++++++++++------------- Source/Modules/lua.cxx | 46 ++++++++++++++++++++-------------------- 2 files changed, 56 insertions(+), 38 deletions(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 632dbd512..9f669cae6 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -509,22 +509,22 @@ int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info* swig_type, int first_ar { // first_arg - position of the object in stack. Everything that is above are arguments // and is passed to every evocation of the func - int last_argument = lua_gettop(L);// position of last argument + int last_arg = lua_gettop(L);// position of last argument lua_getmetatable(L,first_arg); - int original_metatable = last_argument + 1; + int original_metatable = last_arg + 1; int bases_count; SWIG_LUA_INIT_BASE_SEARCH(bases_count); - int result = SWIG_OK; + int result = SWIG_ERROR; ret = 0; if(bases_count>0) { int i; int j; - int subcall_start = lua_gettop(L) + 1;// Here a copy of first_arg and arguments begin + int subcall_first_arg = lua_gettop(L) + 1;// Here a copy of first_arg and arguments begin bool valid = true; - for(j=first_arg;j<=last_argument;j++) + for(j=first_arg;j<=last_arg;j++) lua_pushvalue(L,j); - int subcall_end = lua_gettop(L); + int subcall_last_arg = lua_gettop(L); swig_type_info *base_swig_type = 0; // Trick: temporaly replacing original metatable @@ -533,11 +533,12 @@ int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info* swig_type, int first_ar SWIG_LUA_GET_BASE_METATABLE(i,base_swig_type,valid); if(!valid) continue; + assert(lua_isuserdata(L, subcall_first_arg)); assert(lua_istable(L,-1)); - assert(lua_isuserdata(L, subcall_start)); - lua_setmetatable(L,subcall_start); // Set new metatable - result = func(L, base_swig_type,subcall_start, ret); // Forward call - assert(lua_gettop(L) == subcall_end + ret); // + lua_setmetatable(L,subcall_first_arg); // Set new metatable + assert(lua_gettop(L) == subcall_last_arg); + result = func(L, base_swig_type,subcall_first_arg, ret); // Forward call + assert(lua_gettop(L) == subcall_last_arg + ret); // TODO: REMOVE if(result != SWIG_ERROR) { break; } @@ -545,12 +546,16 @@ int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info* swig_type, int first_ar // Return original metatable back lua_pushvalue(L,original_metatable); lua_setmetatable(L,first_arg); - // Clear - remove everything between last_argument and subcall_end including - const int to_remove = subcall_end - last_argument - 1; + // Clear - remove everything between last_arg and subcall_last_arg including + const int to_remove = subcall_last_arg - last_arg; for(j=0;j Date: Mon, 11 Nov 2013 15:23:50 +0400 Subject: [PATCH 0982/1160] Bugfixes --- .../lua/template_default_arg_runme.lua | 1 + Lib/lua/luarun.swg | 46 +++++++++---------- Source/Modules/lua.cxx | 2 +- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Examples/test-suite/lua/template_default_arg_runme.lua b/Examples/test-suite/lua/template_default_arg_runme.lua index ebb22ed63..853f57882 100644 --- a/Examples/test-suite/lua/template_default_arg_runme.lua +++ b/Examples/test-suite/lua/template_default_arg_runme.lua @@ -3,6 +3,7 @@ import("template_default_arg") -- import code --for k,v in pairs(template_default_arg) do _G[k]=v end -- move to global helloInt = template_default_arg.Hello_int() +assert(template_default_arg.Hello_int_hi ~= nil) helloInt:foo(template_default_arg.Hello_int_hi) x = template_default_arg.X_int() diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 9f669cae6..fb8b0c89f 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -477,10 +477,10 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State* L,const char* cname); lua_rawgeti(L,bases_table,i+1);\ base_swig_type = 0;\ if(lua_isnil(L,-1)) {\ - valid = false;\ + valid = 0;\ lua_pop(L,1);\ } else\ - valid = true; + valid = 1; #else // en elua .bases table doesn't exist. Use table from swig_lua_class @@ -494,18 +494,18 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State* L,const char* cname); #define SWIG_LUA_GET_BASE_METATABLE(i,base_swig_type, valid)\ swig_lua_class *base_class = bases[i];\ if(!base_class)\ - valid = false;\ + valid = 0;\ else {\ - valid = true;\ + valid = 1;\ SWIG_Lua_get_class_metatable(L,base_class->fqname);\ base_swig_type = SWIG_TypeQueryModule(module,module,base_class->fqname);\ } #endif -typedef int (*swig_lua_base_iterator_func)(lua_State*,swig_type_info*, int, int& ret); +typedef int (*swig_lua_base_iterator_func)(lua_State*,swig_type_info*, int, int *ret); -int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info* swig_type, int first_arg, swig_lua_base_iterator_func func, int& ret) +int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info* swig_type, int first_arg, swig_lua_base_iterator_func func, int * const ret) { // first_arg - position of the object in stack. Everything that is above are arguments // and is passed to every evocation of the func @@ -515,13 +515,13 @@ int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info* swig_type, int first_ar int bases_count; SWIG_LUA_INIT_BASE_SEARCH(bases_count); int result = SWIG_ERROR; - ret = 0; + if(ret) *ret = 0; if(bases_count>0) { int i; int j; int subcall_first_arg = lua_gettop(L) + 1;// Here a copy of first_arg and arguments begin - bool valid = true; + int valid = 1; for(j=first_arg;j<=last_arg;j++) lua_pushvalue(L,j); int subcall_last_arg = lua_gettop(L); @@ -538,7 +538,7 @@ int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info* swig_type, int first_ar lua_setmetatable(L,subcall_first_arg); // Set new metatable assert(lua_gettop(L) == subcall_last_arg); result = func(L, base_swig_type,subcall_first_arg, ret); // Forward call - assert(lua_gettop(L) == subcall_last_arg + ret); // TODO: REMOVE + if(ret) assert(lua_gettop(L) == subcall_last_arg + *ret); // TODO: REMOVE if(result != SWIG_ERROR) { break; } @@ -550,12 +550,12 @@ int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info* swig_type, int first_ar const int to_remove = subcall_last_arg - last_arg; for(j=0;jtype; int ret = 0; - int result = SWIG_Lua_class_do_get(L,type,1,ret); + int result = SWIG_Lua_class_do_get(L,type,1,&ret); if(result == SWIG_OK) return ret; @@ -658,7 +658,7 @@ SWIGINTERN int SWIG_Lua_class_get(lua_State* L) /* helper for the class.set method, performs the lookup of class attributes * It returns error code. Number of function return values is passed inside 'ret' */ -SWIGINTERN int SWIG_Lua_class_do_set(lua_State* L, swig_type_info *type, int first_arg, int& ret) +SWIGINTERN int SWIG_Lua_class_do_set(lua_State* L, swig_type_info *type, int first_arg, int *ret) { /* there should be 3 params passed in (1) table (not the meta table) @@ -671,7 +671,7 @@ SWIGINTERN int SWIG_Lua_class_do_set(lua_State* L, swig_type_info *type, int fi assert(lua_isuserdata(L,substack_start+1)); /* just in case */ lua_getmetatable(L,substack_start+1); /* get the meta table */ assert(lua_istable(L,-1)); /* just in case */ - ret = 0; // it is setter - number of return values is always 0 + if(ret) *ret = 0; // it is setter - number of return values is always 0 SWIG_Lua_get_table(L,".set"); /* find the .set table */ if (lua_istable(L,-1)) @@ -712,7 +712,7 @@ SWIGINTERN int SWIG_Lua_class_do_set(lua_State* L, swig_type_info *type, int fi // Search among bases assert(lua_gettop(L) == first_arg+2); // TODO: REMOVE int bases_search_result = SWIG_Lua_iterate_bases(L,type,first_arg,SWIG_Lua_class_do_set,ret); - assert(ret == 0); + if(ret) assert(*ret == 0); assert(lua_gettop(L) == substack_start + 3); return bases_search_result; } @@ -731,7 +731,7 @@ SWIGINTERN int SWIG_Lua_class_set(lua_State* L) swig_lua_userdata *usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */ swig_type_info *type = usr->type; int ret = 0; - int result = SWIG_Lua_class_do_set(L,type,1,ret); + int result = SWIG_Lua_class_do_set(L,type,1,&ret); if(result != SWIG_OK) { SWIG_Lua_pushferrstring(L,"Assignment not possible. No setter/member with this name. For custom assignments implement __setitem method"); lua_error(L); diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 2683cb88a..b741bce7a 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -1129,7 +1129,7 @@ public: Replaceall(tm_v2, "$target", target_name_v2); Replaceall(tm_v2, "$value", value); Replaceall(tm_v2, "$nsname", nsname); - registerConstant( class_parent_nspace, tm); + registerConstant( class_parent_nspace, tm_v2.ptr()); } else { tm_v2 = Swig_typemap_lookup("constcode", n_v2, name, 0); if( !tm_v2) { From a3515ca450644189661839f1ba2f3b444fba324d Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Mon, 11 Nov 2013 17:30:40 +0400 Subject: [PATCH 0983/1160] Removing obsolete debug code --- Source/Modules/lang.cxx | 8 +- Source/Modules/lua.cxx | 210 +++++++++--------------------------- Source/Modules/overload.cxx | 2 - Source/Swig/typesys.c | 2 +- 4 files changed, 54 insertions(+), 168 deletions(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 195da18d6..6e0e88507 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -3014,6 +3014,7 @@ int Language::variableWrapper(Node *n) { Delete(gname); Setattr(n, "varget", "1"); functionWrapper(n); + Delattr(n, "varget"); Swig_restore(n); return SWIG_OK; } @@ -3477,13 +3478,6 @@ String *Language::getNSpace() const { return NSpace; } -/* ----------------------------------------------------------------------------- - * Language::setNSpace() - * ----------------------------------------------------------------------------- */ -void Language::setNSpace(String *nspace) { - NSpace = nspace; -} - /* ----------------------------------------------------------------------------- * Language::getClassName() * ----------------------------------------------------------------------------- */ diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index b741bce7a..91f6aeb8d 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -73,76 +73,6 @@ void display_mapping(DOH *d) { } } -template // T is ignored because everything is DOH* -class DohPtrGuard { - public: - DohPtrGuard( DOH* _ptr ): - p_ptr(_ptr) - { - assert( p_ptr != 0 ); - } - DohPtrGuard(): - p_ptr(0) {} - - ~DohPtrGuard() { - release(); - } - - // Guard is empty, ptr - any: assigns new value for guard - // Guard is holding pointer, ptr == 0 - releases value that guard holds - // Any other combination - assert - DOH* operator=( DOH* ptr ) { - attach(ptr); - return ptr; - } - - DOH* ptr() { return p_ptr; } - const DOH* ptr() const { return p_ptr; } - operator DOH* () { return p_ptr; } - operator DOH* () const { return p_ptr; } - operator bool() const { return ptr != 0; } - - private: - DOH* p_ptr; // pointer to actual object - - void attach(DOH* ptr) { - if( p_ptr != 0 ) { // If some object already attached, then we can't attach another one - assert(ptr == 0); - if( ptr == 0 ) { - release(); - } - } else { - p_ptr = ptr; - } - } - - void release() { - if( p_ptr != 0 ) { - Delete(p_ptr); - p_ptr = 0; - } - } - // Copying is forbiden - DohPtrGuard( const DohPtrGuard& rhs ); - void operator=( const DohPtrGuard& rhs ); - -}; - -// Overloading DohDelete for DohPtrGuard. You might not call DohDelete on DohPtrGuard instances, -// as it is supposed to manage underlying pointer by itself - -void DohDelete(const DohPtrGuard& /*guard*/) { - Printf( stderr, "ERROR: Attempt to delete guarded pointer without deleting it's guardian\n" ); - assert(false); -} -void DohDelete(DohPtrGuard& /*guard*/) { - Printf( stderr, "ERROR: Attempt to delete guarded pointer without deleting it's guardian\n" ); - assert(false); -} - - -#define PtrGuard DohPtrGuard - /* NEW LANGUAGE NOTE:*********************************************** most of the default options are handled by SWIG you can add new ones here @@ -215,7 +145,6 @@ private: CONSTRUCTOR, DESTRUCTOR, MEMBER_VAR, - CLASS_CONST, // TODO: What is this ? STATIC_FUNC, STATIC_VAR, STATIC_CONST, // enums and things like static const int x = 5; @@ -437,19 +366,7 @@ public: Printf(f_header, "#define SWIG_init_user luaopen_%s_user\n\n", module); Printf(f_header, "#define SWIG_LUACODE luaopen_%s_luacode\n", module); - if (elua_ltr || eluac_ltr) { - /* TODO: REMOVE - Printf(f_header, - "#ifndef MIN_OPT_LEVEL\n"\ - "#define MIN_OPT_LEVEL %d\n"\ - "#endif\n", elua_opt_lvl); - Printf(f_header, "#include \"lrodefs.h\"\n"); - Printf(f_header, "#include \"lrotable.h\"\n"); - */ - Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); - } else { - Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); - } + Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); /* %init code inclusion, effectively in the SWIG_init function */ Printf(f_init, "void SWIG_init_user(lua_State* L)\n{\n"); @@ -461,15 +378,9 @@ public: // Done. Close up the module & write to the wrappers - if (elua_ltr || eluac_ltr) { - /* Final close up of wrappers */ - closeNamespaces(f_wrappers); - SwigType_emit_type_table(f_runtime, f_wrappers); - } else { - //Printv(f_wrappers, s_cmd_tab, s_var_tab, s_const_tab, NIL); - closeNamespaces(f_wrappers); - SwigType_emit_type_table(f_runtime, f_wrappers); - } + //Printv(f_wrappers, s_cmd_tab, s_var_tab, s_const_tab, NIL); + closeNamespaces(f_wrappers); + SwigType_emit_type_table(f_runtime, f_wrappers); /* NEW LANGUAGE NOTE:*********************************************** this basically combines several of the strings together @@ -590,7 +501,7 @@ public: Parm *p; String *tm; int i; - //Printf(stdout,"functionWrapper %s %s %d\n",name,iname,current); // TODO: COMMENT BACK + //Printf(stdout,"functionWrapper %s %s %d\n",name,iname,current); String *overname = 0; if (Getattr(n, "sym:overloaded")) { @@ -1071,26 +982,14 @@ public: String *rawval = Getattr(n, "rawval"); String *value = rawval ? rawval : Getattr(n, "value"); String *tm; - PtrGuard target_name_v2; - PtrGuard tm_v2; - PtrGuard iname_v2; - PtrGuard n_v2; + String *target_name_v2 = 0; + String *tm_v2 = 0; + String *iname_v2 = 0; + Node *n_v2 = 0; if (!luaAddSymbol(target_name, n)) return SWIG_ERROR; - bool make_v2_compatible = v2_compatibility && getCurrentClass() != 0; - //Printf( stdout, "V2 compatible: %d\n", int(make_v2_compatible) ); // TODO: REMOVE - if( make_v2_compatible ) { - target_name_v2 = Swig_name_member(0, class_symname, target_name); - iname_v2 = Swig_name_member(0, class_symname, iname); - n_v2 = Copy(n); - //Printf( stdout, "target name v2: %s, symname v2 %s\n", target_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE - if (!luaAddSymbol(iname_v2, n, class_parent_nspace)) { - return SWIG_ERROR; - } - } - Swig_save("lua_constantMember", n, "sym:name", NIL); Setattr(n, "sym:name", target_name); /* Special hook for member pointer */ @@ -1120,7 +1019,17 @@ public: return SWIG_NOWRAP; } + bool make_v2_compatible = v2_compatibility && getCurrentClass() != 0; + if( make_v2_compatible ) { + target_name_v2 = Swig_name_member(0, class_symname, target_name); + iname_v2 = Swig_name_member(0, class_symname, iname); + n_v2 = Copy(n); + //Printf( stdout, "target name v2: %s, symname v2 %s\n", target_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE + if (!luaAddSymbol(iname_v2, n, class_parent_nspace)) { + return SWIG_ERROR; + } + Setattr(n_v2, "sym:name", target_name_v2); tm_v2 = Swig_typemap_lookup("consttab", n_v2, name, 0); if (tm_v2) { @@ -1129,7 +1038,7 @@ public: Replaceall(tm_v2, "$target", target_name_v2); Replaceall(tm_v2, "$value", value); Replaceall(tm_v2, "$nsname", nsname); - registerConstant( class_parent_nspace, tm_v2.ptr()); + registerConstant( class_parent_nspace, tm_v2); } else { tm_v2 = Swig_typemap_lookup("constcode", n_v2, name, 0); if( !tm_v2) { @@ -1142,8 +1051,9 @@ public: Replaceall(tm_v2, "$target", target_name_v2); Replaceall(tm_v2, "$value", value); Replaceall(tm_v2, "$nsname", nsname); - Printf(f_init, "%s\n", tm_v2.ptr()); + Printf(f_init, "%s\n", tm_v2); } + Delete(n_v2); } Swig_restore(n); @@ -1174,25 +1084,10 @@ public: * ------------------------------------------------------------ */ virtual int enumDeclaration(Node *n) { - // enumDeclaration supplied by Language is messing with NSpace. - // So this is the exact copy of function from Language with - // correct handling of namespaces - String *oldNSpace = getNSpace(); - /* TODO: REVIEW/REMOVE_and_replace_with_Language::enumDeclaration - if( getCurrentClass() == 0 ) { - setNSpace(Getattr(n, "sym:nspace")); - }*/ - setNSpace(Getattr(n, "sym:nspace")); - - if (!ImportMode) { - current[STATIC_CONST] = true; - emit_children(n); - current[STATIC_CONST] = false; - } - - setNSpace(oldNSpace); - - return SWIG_OK; + current[STATIC_CONST] = true; + int result = Language::enumDeclaration(n); + current[STATIC_CONST] = false; + return result; } /* ------------------------------------------------------------ @@ -1237,8 +1132,8 @@ public: virtual int classHandler(Node *n) { //REPORT("classHandler", n); - PtrGuard mangled_class_fq_symname; - PtrGuard destructor_name; + String *mangled_class_fq_symname; + String *destructor_name; String* nspace = getNSpace(); constructor_name = 0; @@ -1266,13 +1161,13 @@ public: assert(class_fq_symname != 0); mangled_class_fq_symname = Swig_name_mangle(class_fq_symname); - PtrGuard t( Copy(Getattr(n, "name")) ); - PtrGuard fr_t( SwigType_typedef_resolve_all(t) ); /* Create fully resolved type */ - PtrGuard t_tmp; + SwigType *t( Copy(Getattr(n, "name")) ); + SwigType *fr_t( SwigType_typedef_resolve_all(t) ); /* Create fully resolved type */ + SwigType *t_tmp = 0; t_tmp = SwigType_typedef_qualified(fr_t); // Temporal variable - fr_t = 0; + Delete(fr_t); fr_t = SwigType_strip_qualifiers(t_tmp); - PtrGuard mangled_fr_t; + String *mangled_fr_t = 0; mangled_fr_t = SwigType_manglestr(fr_t); // not sure exactly how this works, // but tcl has a static hashtable of all classes emitted and then only emits code for them once. @@ -1328,17 +1223,15 @@ public: // Replacing namespace with namespace + class in order to static // member be put inside class static area class_parent_nspace = getNSpace(); - //setNSpace(class_static_nspace); TODO: REMOVE // Generate normal wrappers Language::classHandler(n); // Restore correct nspace - //setNSpace(nspace); // TODO: REMOVE if remove above class_parent_nspace = 0; SwigType_add_pointer(t); // Catch all: eg. a class with only static functions and/or variables will not have 'remembered' - String *wrap_class = NewStringf("&_wrap_class_%s", mangled_class_fq_symname.ptr()); + String *wrap_class = NewStringf("&_wrap_class_%s", mangled_class_fq_symname); SwigType_remember_clientdata(t, wrap_class); String *rt = Copy(getClassType()); @@ -1354,8 +1247,8 @@ public: // emit a function to be called to delete the object if (have_destructor) { - destructor_name = NewStringf("swig_delete_%s", mangled_class_fq_symname.ptr()); - Printv(f_wrappers, "static void ", destructor_name.ptr(), "(void *obj) {\n", NIL); + destructor_name = NewStringf("swig_delete_%s", mangled_class_fq_symname); + Printv(f_wrappers, "static void ", destructor_name, "(void *obj) {\n", NIL); if (destructor_action) { Printv(f_wrappers, SwigType_str(rt, "arg1"), " = (", SwigType_str(rt, 0), ") obj;\n", NIL); Printv(f_wrappers, destructor_action, "\n", NIL); @@ -1399,7 +1292,7 @@ public: if (eluac_ltr) { String* ns_methods_tab = Getattr(nspaceHash, "methods"); assert(ns_methods_tab != 0); - Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_class_fq_symname.ptr(), "\")", ", LFUNCVAL(", destructor_name.ptr(), ")", "},\n", NIL); + Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_class_fq_symname, "\")", ", LFUNCVAL(", destructor_name, ")", "},\n", NIL); } } @@ -1443,12 +1336,12 @@ public: printNamespaceDefinition(class_static_nspace, class_symname, f_wrappers); // Then print class isntance part - Printv(f_wrappers, "static swig_lua_class *swig_", mangled_class_fq_symname.ptr(), "_bases[] = {", base_class, "0};\n", NIL); + Printv(f_wrappers, "static swig_lua_class *swig_", mangled_class_fq_symname, "_bases[] = {", base_class, "0};\n", NIL); Delete(base_class); - Printv(f_wrappers, "static const char *swig_", mangled_class_fq_symname.ptr(), "_base_names[] = {", base_class_names, "0};\n", NIL); + Printv(f_wrappers, "static const char *swig_", mangled_class_fq_symname, "_base_names[] = {", base_class_names, "0};\n", NIL); Delete(base_class_names); - Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_class_fq_symname.ptr(), " = { \"", class_symname, "\", \"", class_fq_symname,"\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); + Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_class_fq_symname, " = { \"", class_symname, "\", \"", class_fq_symname,"\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); if (have_constructor) { Printv(f_wrappers, constructor_name, NIL); @@ -1459,16 +1352,18 @@ public: } if (have_destructor) { - Printv(f_wrappers, ", ", destructor_name.ptr(), NIL); + Printv(f_wrappers, ", ", destructor_name, NIL); } else { Printf(f_wrappers, ",0"); } Printf(f_wrappers, ", %s, %s, &%s", s_methods_tab_name, s_attr_tab_name, Getattr(static_cls, "cname") ); Printf(f_wrappers, ", swig_%s_bases, swig_%s_base_names };\n\n", - mangled_class_fq_symname.ptr(), mangled_class_fq_symname.ptr()); + mangled_class_fq_symname, mangled_class_fq_symname); current[NO_CPP] = true; Delete(class_static_nspace); + Delete(mangled_class_fq_symname); + Delete(destructor_name); class_static_nspace = 0; Delete(class_fq_symname); class_fq_symname = 0; @@ -1581,10 +1476,10 @@ public: if(v2_compatibility) { Swig_require("lua_staticmemberfunctionHandler", n, "*lua:name", NIL); String *target_name = Getattr(n, "lua:name"); - PtrGuard compat_name; - compat_name = Swig_name_member(0, class_symname, target_name); + String *compat_name = Swig_name_member(0, class_symname, target_name); Setattr(n, "lua:name", compat_name); registerMethod( class_parent_nspace, n ); + Delete(compat_name); Swig_restore(n); } @@ -1738,7 +1633,7 @@ public: String* item = Getitem(components, i); Printv(parent_path, item, NIL); } - //Printf(stdout, "Registering %s. User name %s. C-name %s, Parent is %s\n", mangled_name, name, cname, parent_path); + //Printf(stdout, "Registering %s. User name %s. C-name %s, Parent is %s\n", mangled_name, name, cname, parent_path); // TODO: REMOVE Hash* parent = getNamespaceHash(parent_path, true); String* namespaces_tab = Getattr(parent, "namespaces"); Printv(namespaces_tab, "&", cname, ",\n", NIL); @@ -1814,7 +1709,6 @@ public: Setattr(nspace_hash, "namespaces:decl", namespaces_tab_decl ); if (elua_ltr) { - // TODO: add xxx:decl here too String *get_tab = NewString(""); String *get_tab_name = NewStringf("swig_%s_get", mangled_name); String *get_tab_decl = NewString(""); @@ -1993,14 +1887,13 @@ public: // be fully qualified name, just it's own name. void printNamespaceDefinition(String *nspace, String* name, File *output) { - // TODO: Fix for get_tab/set_tab things (elua_ltr) Hash *nspace_hash = getNamespaceHash(nspace, false); String* cname = Getattr(nspace_hash, "cname"); // cname - name of the C structure that describes namespace assert(cname != 0); Printv(output, "static swig_lua_namespace ", cname, " = ", NIL); - PtrGuard null_string; + String *null_string; null_string = NewString("0"); String *attr_tab_name = Getattr(nspace_hash, "attributes:name"); String *methods_tab_name = Getattr(nspace_hash, "methods:name"); @@ -2015,10 +1908,11 @@ public: tab4, methods_tab_name, ",\n", tab4, attr_tab_name, ",\n", tab4, const_tab_name, ",\n", - tab4, (has_classes)?classes_tab_name:null_string.ptr(), ",\n", - tab4, (has_namespaces)?namespaces_tab_name:null_string.ptr(), "\n};\n", + tab4, (has_classes)?classes_tab_name:null_string, ",\n", + tab4, (has_namespaces)?namespaces_tab_name:null_string, "\n};\n", NIL ); + Delete(null_string); } // This function determines actual namespace/scope where any symbol at the @@ -2038,7 +1932,7 @@ public: assert(!current[NO_CPP]); if(current[STATIC_FUNC] || current[STATIC_VAR] || current[STATIC_CONST] ) { scope = class_static_nspace; - } else if(current[MEMBER_VAR] || current[CLASS_CONST] || current[CONSTRUCTOR] || current[DESTRUCTOR] + } else if(current[MEMBER_VAR] || current[CONSTRUCTOR] || current[DESTRUCTOR] || current[MEMBER_FUNC] ) { scope = class_fq_symname; } else { // Friend functions are handled this way diff --git a/Source/Modules/overload.cxx b/Source/Modules/overload.cxx index 4c0d06702..e95ef557f 100644 --- a/Source/Modules/overload.cxx +++ b/Source/Modules/overload.cxx @@ -765,7 +765,6 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar for (i = 0; i < nfunc; i++) { Node *ni = Getitem(dispatch, i); Parm *pi = Getattr(ni, "wrap:parms"); - //Printf(stdout , "Dispatch, wrapname %s\n", Getattr(ni,"wrap:name")); // TODO:REMOVE bool implicitconvtypecheckoff = GetFlag(ni, "implicitconvtypecheckoff") != 0; int num_required = emit_num_required(pi); int num_arguments = emit_num_arguments(pi); @@ -819,7 +818,6 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar j++; } String *lfmt = ReplaceFormat(fmt, num_arguments); - //Printf(stdout , "Dispatch, wrapname %s\n", Getattr(ni,"wrap:name")); // TODO:REMOVE Printf(f, Char(lfmt), Getattr(ni, "wrap:name")); Delete(lfmt); /* close braces */ diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index a7060ca54..c5ddb56f6 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -1594,7 +1594,7 @@ void SwigType_remember_clientdata(const SwigType *t, const_String_or_char_ptr cl Delete(qr); /*Printf(stdout,"t = '%s'\n", t); - Printf(stdout,"fr= '%s'\n\n", fr); TODO: COmment back*/ + Printf(stdout,"fr= '%s'\n\n", fr);*/ if (t) { char *ct = Char(t); From 9bd39fe4fa80307167fbc26290aaa188d57f5485 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Mon, 11 Nov 2013 17:37:39 +0400 Subject: [PATCH 0984/1160] Valuewrapper test --- Examples/test-suite/lua/valuewrapper_runme.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Examples/test-suite/lua/valuewrapper_runme.lua diff --git a/Examples/test-suite/lua/valuewrapper_runme.lua b/Examples/test-suite/lua/valuewrapper_runme.lua new file mode 100644 index 000000000..94d49c7cc --- /dev/null +++ b/Examples/test-suite/lua/valuewrapper_runme.lua @@ -0,0 +1,17 @@ +require("import") -- the import fn +import("valuewrapper") -- import code +v=valuewrapper -- renaming import + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +assert(v.Xi ~= nil) +assert(v.YXi ~= nil) + +x1 = v.Xi(5) + +y1 =v.YXi() +assert(y1:spam(x1) == 0) +assert(y1:spam() == 0) From 1e282e39817880e6e94dbcaeaf71c2c25ce812ee Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Mon, 11 Nov 2013 18:02:27 +0400 Subject: [PATCH 0985/1160] Code beautifier --- Source/Modules/lua.cxx | 1041 ++++++++++++++++++++-------------------- 1 file changed, 511 insertions(+), 530 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 91f6aeb8d..f1803e068 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -54,7 +54,7 @@ */ #define REPORT(T,D) // no info: //#define REPORT(T,D) {Printf(stdout,T"\n");} // only title -//#define REPORT(T,D) {Printf(stdout,T" %p\n",n);} // title & pointer +//#define REPORT(T,D) {Printf(stdout,T" %p\n",n);} // title & pointer //#define REPORT(T,D) {Printf(stdout,T"\n");display_mapping(D);} // the works //#define REPORT(T,D) {Printf(stdout,T"\n");if(D)Swig_print_node(D);} // the works @@ -122,14 +122,14 @@ private: File *f_initbeforefunc; String *s_luacode; // luacode to be called during init String *module; //name of the module - Hash* namespaces_hash; + Hash *namespaces_hash; // Parameters for current class. NIL if not parsing class int have_constructor; int have_destructor; String *destructor_action; String *class_symname; - String *class_fq_symname; // Fully qualified symname - NSpace + '.' + class_symname + String *class_fq_symname; // Fully qualified symname - NSpace + '.' + class_symname String *class_static_nspace; String *class_parent_nspace; String *constructor_name; @@ -147,7 +147,7 @@ private: MEMBER_VAR, STATIC_FUNC, STATIC_VAR, - STATIC_CONST, // enums and things like static const int x = 5; + STATIC_CONST, // enums and things like static const int x = 5; STATES_COUNT }; @@ -161,29 +161,22 @@ public: * Initialize member data * --------------------------------------------------------------------- */ - LUA() : - f_begin(0), - f_runtime(0), - f_header(0), - f_wrappers(0), - f_init(0), - f_initbeforefunc(0), - s_luacode(0), - module(0), - have_constructor(0), - have_destructor(0), - destructor_action(0), - class_symname(0), - class_fq_symname(0), - class_static_nspace(0), - constructor_name(0) { - namespaces_hash = NewHash(); - for(int i = 0; i < STATES_COUNT; i++ ) - current[i] = false; + LUA(): + f_begin(0), + f_runtime(0), + f_header(0), + f_wrappers(0), + f_init(0), + f_initbeforefunc(0), + s_luacode(0), + module(0), + have_constructor(0), have_destructor(0), destructor_action(0), class_symname(0), class_fq_symname(0), class_static_nspace(0), constructor_name(0) { + namespaces_hash = NewHash(); + for (int i = 0; i < STATES_COUNT; i++) + current[i] = false; } - ~LUA() { - if(namespaces_hash) + if (namespaces_hash) Delete(namespaces_hash); } @@ -191,82 +184,82 @@ public: This is called to initalise the system & read any command line args most of this is boilerplate code, except the command line args which depends upon what args your code supports - NEW LANGUAGE NOTE:END ************************************************/ + NEW LANGUAGE NOTE:END *********************************************** */ - bool strToInt(const char* string, int& value) { - long int tmp; - char *p_end = 0; - if(string == 0) - return false; - tmp = strtol(string,&p_end,10); - if( p_end == 0 || *p_end != 0 ) - return false; - value = tmp; - return true; + bool strToInt(const char *string, int &value) { + long int tmp; + char *p_end = 0; + if (string == 0) + return false; + tmp = strtol(string, &p_end, 10); + if (p_end == 0 || *p_end != 0) + return false; + value = tmp; + return true; } /* --------------------------------------------------------------------- - * main() - * - * Parse command line options and initializes variables. - * --------------------------------------------------------------------- */ + * main() + * + * Parse command line options and initializes variables. + * --------------------------------------------------------------------- */ virtual void main(int argc, char *argv[]) { - int api_level = default_api_level; // Default api level + int api_level = default_api_level; // Default api level /* Set location of SWIG library */ SWIG_library_directory("lua"); /* Look for certain command line options */ for (int i = 1; i < argc; i++) { if (argv[i]) { - if (strcmp(argv[i], "-help") == 0) { // usage flags - fputs(usage, stdout); - } else if (strcmp(argv[i], "-nomoduleglobal") == 0) { - nomoduleglobal = 1; - Swig_mark_arg(i); - } else if(strcmp(argv[i], "-elua") == 0) { - elua_ltr = 1; - Swig_mark_arg(i); - if(strToInt(argv[i+1],elua_opt_lvl)) { - Swig_mark_arg(i+1); - i++; - } - } else if(strcmp(argv[i], "-eluac") == 0) { - eluac_ltr = 1; - Swig_mark_arg(i); - if(strToInt(argv[i+1],elua_opt_lvl)) { - Swig_mark_arg(i+1); - i++; - } - } else if(strcmp(argv[i], "-api-lvl-from") == 0) { - if(argv[i+1]) { - if(!strToInt(argv[i+1], api_level)) - Swig_arg_error(); - Swig_mark_arg(i+1); - i++; - } else { - Swig_arg_error(); - } - } + if (strcmp(argv[i], "-help") == 0) { // usage flags + fputs(usage, stdout); + } else if (strcmp(argv[i], "-nomoduleglobal") == 0) { + nomoduleglobal = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-elua") == 0) { + elua_ltr = 1; + Swig_mark_arg(i); + if (strToInt(argv[i + 1], elua_opt_lvl)) { + Swig_mark_arg(i + 1); + i++; + } + } else if (strcmp(argv[i], "-eluac") == 0) { + eluac_ltr = 1; + Swig_mark_arg(i); + if (strToInt(argv[i + 1], elua_opt_lvl)) { + Swig_mark_arg(i + 1); + i++; + } + } else if (strcmp(argv[i], "-api-lvl-from") == 0) { + if (argv[i + 1]) { + if (!strToInt(argv[i + 1], api_level)) + Swig_arg_error(); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } } } // Set API-compatibility options - if(api_level <= 2) // Must be compatible with SWIG 2.* + if (api_level <= 2) // Must be compatible with SWIG 2.* v2_compatibility = 1; - // template for further API breaks - //if(api_level <= 3) - // v3_compatibility = 1; - //if(api_level <= 4) - // v4_compatibility = 1; - + // template for further API breaks + //if(api_level <= 3) + // v3_compatibility = 1; + //if(api_level <= 4) + // v4_compatibility = 1; + /* NEW LANGUAGE NOTE:*********************************************** - This is the boilerplate code, setting a few #defines - and which lib directory to use - the SWIG_library_directory() is also boilerplate code - but it always seems to be the first line of code - NEW LANGUAGE NOTE:END ************************************************/ + This is the boilerplate code, setting a few #defines + and which lib directory to use + the SWIG_library_directory() is also boilerplate code + but it always seems to be the first line of code + NEW LANGUAGE NOTE:END *********************************************** */ /* Add a symbol to the parser for conditional compilation */ Preprocessor_define("SWIGLUA 1", 0); @@ -284,15 +277,15 @@ public: /* NEW LANGUAGE NOTE:*********************************************** - After calling main, SWIG parses the code to wrap (I believe) - then calls top() - in this is more boilerplate code to set everything up - and a call to Language::top() - which begins the code generations by calling the member fns - after all that is more boilerplate code to close all down - (overall there is virtually nothing here that needs to be edited - just use as is) - NEW LANGUAGE NOTE:END ************************************************/ + After calling main, SWIG parses the code to wrap (I believe) + then calls top() + in this is more boilerplate code to set everything up + and a call to Language::top() + which begins the code generations by calling the member fns + after all that is more boilerplate code to close all down + (overall there is virtually nothing here that needs to be edited + just use as is) + NEW LANGUAGE NOTE:END *********************************************** */ /* --------------------------------------------------------------------- * top() * --------------------------------------------------------------------- */ @@ -324,10 +317,10 @@ public: Swig_register_filebyname("init", f_init); Swig_register_filebyname("initbeforefunc", f_initbeforefunc); - + s_luacode = NewString(""); Swig_register_filebyname("luacode", s_luacode); - + current[NO_CPP] = true; /* Standard stuff for the SWIG runtime section */ @@ -339,11 +332,8 @@ public: emitLuaFlavor(f_runtime); if (elua_ltr || eluac_ltr) - Printf(f_runtime, - "#ifndef MIN_OPT_LEVEL\n"\ - "#define MIN_OPT_LEVEL %d\n"\ - "#endif\n", elua_opt_lvl); - + Printf(f_runtime, "#ifndef MIN_OPT_LEVEL\n" "#define MIN_OPT_LEVEL %d\n" "#endif\n", elua_opt_lvl); + if (nomoduleglobal) { Printf(f_runtime, "#define SWIG_LUA_NO_MODULE_GLOBAL\n"); } else { @@ -371,7 +361,7 @@ public: /* %init code inclusion, effectively in the SWIG_init function */ Printf(f_init, "void SWIG_init_user(lua_State* L)\n{\n"); Language::top(n); - Printf(f_init,"/* exec Lua code if applicable */\nSWIG_Lua_dostring(L,SWIG_LUACODE);\n"); + Printf(f_init, "/* exec Lua code if applicable */\nSWIG_Lua_dostring(L,SWIG_LUACODE);\n"); Printf(f_init, "}\n"); Printf(f_wrappers, "#ifdef __cplusplus\n}\n#endif\n"); @@ -383,16 +373,16 @@ public: SwigType_emit_type_table(f_runtime, f_wrappers); /* NEW LANGUAGE NOTE:*********************************************** - this basically combines several of the strings together - and then writes it all to a file - NEW LANGUAGE NOTE:END ************************************************/ + this basically combines several of the strings together + and then writes it all to a file + NEW LANGUAGE NOTE:END *********************************************** */ Dump(f_runtime, f_begin); Dump(f_header, f_begin); Dump(f_wrappers, f_begin); Dump(f_initbeforefunc, f_begin); /* for the Lua code it needs to be properly excaped to be added into the C/C++ code */ EscapeCode(s_luacode); - Printf(f_begin, "const char* SWIG_LUACODE=\n \"%s\";\n\n",s_luacode); + Printf(f_begin, "const char* SWIG_LUACODE=\n \"%s\";\n\n", s_luacode); Wrapper_pretty_print(f_init, f_begin); /* Close all of the files */ Delete(s_luacode); @@ -425,25 +415,25 @@ public: // But we need to know what was the name of function/variable // etc that user desired, that's why we store correct symname // as lua:name - Setattr(n, "lua:name", Getattr(n, "sym:name") ); + Setattr(n, "lua:name", Getattr(n, "sym:name")); return Language::cDeclaration(n); } virtual int constructorDeclaration(Node *n) { - Setattr(n, "lua:name", Getattr(n, "sym:name") ); + Setattr(n, "lua:name", Getattr(n, "sym:name")); return Language::constructorDeclaration(n); } virtual int destructorDeclaration(Node *n) { - Setattr(n, "lua:name", Getattr(n, "sym:name") ); + Setattr(n, "lua:name", Getattr(n, "sym:name")); return Language::destructorDeclaration(n); } /* NEW LANGUAGE NOTE:*********************************************** - This is it! - you get this one right, and most of your work is done - but its going to take soem file to get it working right - quite a bit of this is generally boilerplate code - (or stuff I dont understand) - that which matters will have extra added comments - NEW LANGUAGE NOTE:END ************************************************/ + This is it! + you get this one right, and most of your work is done + but its going to take soem file to get it working right + quite a bit of this is generally boilerplate code + (or stuff I dont understand) + that which matters will have extra added comments + NEW LANGUAGE NOTE:END *********************************************** */ /* --------------------------------------------------------------------- * functionWrapper() * @@ -455,25 +445,25 @@ public: Setattr(n, "wrap:name", wrapname); // If it is getter/setter, then write wrapname under // wrap:memberset/wrap:memberget accordingly - if( Getattr(n, "memberset") ) + if (Getattr(n, "memberset")) Setattr(n, "memberset:wrap:name", wrapname); - if( Getattr(n, "varset") ) + if (Getattr(n, "varset")) Setattr(n, "varset:wrap:name", wrapname); - if( Getattr(n, "memberget") ) + if (Getattr(n, "memberget")) Setattr(n, "memberget:wrap:name", wrapname); - if( Getattr(n, "varget") ) + if (Getattr(n, "varget")) Setattr(n, "varget:wrap:name", wrapname); } // Add method to the "methods" C array of given namespace/class - void registerMethod(String *nspace_or_class_name, Node* n) { + void registerMethod(String *nspace_or_class_name, Node *n) { assert(n != 0); - Hash* nspaceHash = getNamespaceHash( nspace_or_class_name ); - String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); + Hash *nspaceHash = getNamespaceHash(nspace_or_class_name); + String *s_ns_methods_tab = Getattr(nspaceHash, "methods"); String *wname = Getattr(n, "wrap:name"); String *iname = Getattr(n, "sym:name"); String *target_name = Getattr(n, "lua:name"); - if(elua_ltr || eluac_ltr) + if (elua_ltr || eluac_ltr) Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", iname, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); else Printv(s_ns_methods_tab, tab4, "{ \"", target_name, "\", ", wname, "},\n", NIL); @@ -487,10 +477,10 @@ public: if (current[VARIABLE]) return false; return (current[NO_CPP] || current[STATIC_FUNC]); - } - + } + virtual int functionWrapper(Node *n) { - REPORT("functionWrapper",n); + REPORT("functionWrapper", n); String *name = Getattr(n, "name"); String *iname = Getattr(n, "sym:name"); @@ -508,14 +498,14 @@ public: overname = Getattr(n, "sym:overname"); } else { if (!luaAddSymbol(target_name, n)) { - return SWIG_ERROR; + return SWIG_ERROR; } } /* NEW LANGUAGE NOTE:*********************************************** the wrapper object holds all the wrappering code - we need to add a couple of local variables - NEW LANGUAGE NOTE:END ************************************************/ + we need to add a couple of local variables + NEW LANGUAGE NOTE:END *********************************************** */ Wrapper *f = NewWrapper(); Wrapper_add_local(f, "SWIG_arg", "int SWIG_arg = 0"); @@ -525,25 +515,25 @@ public: Append(wname, overname); } if (current[CONSTRUCTOR]) { - if( constructor_name != 0) - Delete(constructor_name); + if (constructor_name != 0) + Delete(constructor_name); constructor_name = Copy(wname); } /* NEW LANGUAGE NOTE:*********************************************** the format of a lua fn is: - static int wrap_XXX(lua_State* L){...} + static int wrap_XXX(lua_State* L){...} this line adds this into the wrappering code - NEW LANGUAGE NOTE:END ************************************************/ + NEW LANGUAGE NOTE:END *********************************************** */ Printv(f->def, "static int ", wname, "(lua_State* L) {", NIL); /* NEW LANGUAGE NOTE:*********************************************** this prints the list of args, eg for a C fn int gcd(int x,int y); it will print - int arg1; - int arg2; - NEW LANGUAGE NOTE:END ************************************************/ + int arg1; + int arg2; + NEW LANGUAGE NOTE:END *********************************************** */ /* Write code to extract function parameters. */ emit_parameter_variables(l, f); @@ -572,24 +562,24 @@ public: some of the stuff will refer to the typemaps code written in your swig file (lua.swg), and some is done in the code here I suppose you could do all the conversion on C, but it would be a nightmare to do - NEW LANGUAGE NOTE:END ************************************************/ + NEW LANGUAGE NOTE:END *********************************************** */ /* Generate code for argument marshalling */ // String *description = NewString(""); /* NEW LANGUAGE NOTE:*********************************************** argument_check is a new feature I added to check types of arguments: eg for int gcd(int,int) I want to check that arg1 & arg2 really are integers - NEW LANGUAGE NOTE:END ************************************************/ + NEW LANGUAGE NOTE:END *********************************************** */ String *argument_check = NewString(""); String *argument_parse = NewString(""); String *checkfn = NULL; char source[64]; - Printf(argument_check, "SWIG_check_num_args(\"%s\",%d,%d)\n",Swig_name_str(n),num_required+args_to_ignore,num_arguments+args_to_ignore); + Printf(argument_check, "SWIG_check_num_args(\"%s\",%d,%d)\n", Swig_name_str(n), num_required + args_to_ignore, num_arguments + args_to_ignore); for (i = 0, p = l; i < num_arguments; i++) { while (checkAttribute(p, "tmap:in:numinputs", "0")) { - p = Getattr(p, "tmap:in:next"); + p = Getattr(p, "tmap:in:next"); } SwigType *pt = Getattr(p, "type"); @@ -598,49 +588,49 @@ public: /* Look for an input typemap */ sprintf(source, "%d", i + 1); if ((tm = Getattr(p, "tmap:in"))) { - Replaceall(tm, "$source", source); - Replaceall(tm, "$target", ln); - Replaceall(tm, "$input", source); - Setattr(p, "emit:input", source); - if (Getattr(p, "wrap:disown") || (Getattr(p, "tmap:in:disown"))) { - Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); - } else { - Replaceall(tm, "$disown", "0"); - } - /* NEW LANGUAGE NOTE:*********************************************** - look for a 'checkfn' typemap - this an additional parameter added to the in typemap - if found the type will be tested for - this will result in code either in the - argument_check or argument_parse string - NEW LANGUAGE NOTE:END ************************************************/ - if ((checkfn = Getattr(p, "tmap:in:checkfn"))) { - if (i < num_required) { - Printf(argument_check, "if(!%s(L,%s))", checkfn, source); - } else { - Printf(argument_check, "if(lua_gettop(L)>=%s && !%s(L,%s))", source, checkfn, source); - } - Printf(argument_check, " SWIG_fail_arg(\"%s\",%s,\"%s\");\n", Swig_name_str(n), source, SwigType_str(pt, 0)); - } - /* NEW LANGUAGE NOTE:*********************************************** - lua states the number of arguments passed to a function using the fn - lua_gettop() - we can use this to deal with default arguments - NEW LANGUAGE NOTE:END ************************************************/ - if (i < num_required) { - Printf(argument_parse, "%s\n", tm); - } else { - Printf(argument_parse, "if(lua_gettop(L)>=%s){%s}\n", source, tm); - } - p = Getattr(p, "tmap:in:next"); - continue; + Replaceall(tm, "$source", source); + Replaceall(tm, "$target", ln); + Replaceall(tm, "$input", source); + Setattr(p, "emit:input", source); + if (Getattr(p, "wrap:disown") || (Getattr(p, "tmap:in:disown"))) { + Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); + } else { + Replaceall(tm, "$disown", "0"); + } + /* NEW LANGUAGE NOTE:*********************************************** + look for a 'checkfn' typemap + this an additional parameter added to the in typemap + if found the type will be tested for + this will result in code either in the + argument_check or argument_parse string + NEW LANGUAGE NOTE:END *********************************************** */ + if ((checkfn = Getattr(p, "tmap:in:checkfn"))) { + if (i < num_required) { + Printf(argument_check, "if(!%s(L,%s))", checkfn, source); + } else { + Printf(argument_check, "if(lua_gettop(L)>=%s && !%s(L,%s))", source, checkfn, source); + } + Printf(argument_check, " SWIG_fail_arg(\"%s\",%s,\"%s\");\n", Swig_name_str(n), source, SwigType_str(pt, 0)); + } + /* NEW LANGUAGE NOTE:*********************************************** + lua states the number of arguments passed to a function using the fn + lua_gettop() + we can use this to deal with default arguments + NEW LANGUAGE NOTE:END *********************************************** */ + if (i < num_required) { + Printf(argument_parse, "%s\n", tm); + } else { + Printf(argument_parse, "if(lua_gettop(L)>=%s){%s}\n", source, tm); + } + p = Getattr(p, "tmap:in:next"); + continue; } else { - /* NEW LANGUAGE NOTE:*********************************************** - // why is this code not called when I dont have a typemap? - // instead of giving a warning, no code is generated - NEW LANGUAGE NOTE:END ************************************************/ - Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0)); - break; + /* NEW LANGUAGE NOTE:*********************************************** + // why is this code not called when I dont have a typemap? + // instead of giving a warning, no code is generated + NEW LANGUAGE NOTE:END *********************************************** */ + Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0)); + break; } } @@ -650,19 +640,19 @@ public: /* Check for trailing varargs */ if (varargs) { if (p && (tm = Getattr(p, "tmap:in"))) { - Replaceall(tm, "$input", "varargs"); - Printv(f->code, tm, "\n", NIL); + Replaceall(tm, "$input", "varargs"); + Printv(f->code, tm, "\n", NIL); } } /* Insert constraint checking code */ for (p = l; p;) { if ((tm = Getattr(p, "tmap:check"))) { - Replaceall(tm, "$target", Getattr(p, "lname")); - Printv(f->code, tm, "\n", NIL); - p = Getattr(p, "tmap:check:next"); + Replaceall(tm, "$target", Getattr(p, "lname")); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:check:next"); } else { - p = nextSibling(p); + p = nextSibling(p); } } @@ -670,11 +660,11 @@ public: String *cleanup = NewString(""); for (p = l; p;) { if ((tm = Getattr(p, "tmap:freearg"))) { - Replaceall(tm, "$source", Getattr(p, "lname")); - Printv(cleanup, tm, "\n", NIL); - p = Getattr(p, "tmap:freearg:next"); + Replaceall(tm, "$source", Getattr(p, "lname")); + Printv(cleanup, tm, "\n", NIL); + p = Getattr(p, "tmap:freearg:next"); } else { - p = nextSibling(p); + p = nextSibling(p); } } @@ -682,21 +672,21 @@ public: String *outarg = NewString(""); for (p = l; p;) { if ((tm = Getattr(p, "tmap:argout"))) { - // // managing the number of returning variables - // if (numoutputs=Getattr(p,"tmap:argout:numoutputs")){ - // int i=GetInt(p,"tmap:argout:numoutputs"); - // printf("got argout:numoutputs of %d\n",i); - // returnval+=GetInt(p,"tmap:argout:numoutputs"); - // } - // else returnval++; - Replaceall(tm, "$source", Getattr(p, "lname")); - Replaceall(tm, "$target", Swig_cresult_name()); - Replaceall(tm, "$arg", Getattr(p, "emit:input")); - Replaceall(tm, "$input", Getattr(p, "emit:input")); - Printv(outarg, tm, "\n", NIL); - p = Getattr(p, "tmap:argout:next"); + // // managing the number of returning variables + // if (numoutputs=Getattr(p,"tmap:argout:numoutputs")){ + // int i=GetInt(p,"tmap:argout:numoutputs"); + // printf("got argout:numoutputs of %d\n",i); + // returnval+=GetInt(p,"tmap:argout:numoutputs"); + // } + // else returnval++; + Replaceall(tm, "$source", Getattr(p, "lname")); + Replaceall(tm, "$target", Swig_cresult_name()); + Replaceall(tm, "$arg", Getattr(p, "emit:input")); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(outarg, tm, "\n", NIL); + p = Getattr(p, "tmap:argout:next"); } else { - p = nextSibling(p); + p = nextSibling(p); } } @@ -707,10 +697,10 @@ public: String *actioncode = emit_action(n); /* NEW LANGUAGE NOTE:*********************************************** - FIXME: - returns 1 if there is a void return type - this is because there is a typemap for void - NEW LANGUAGE NOTE:END ************************************************/ + FIXME: + returns 1 if there is a void return type + this is because there is a typemap for void + NEW LANGUAGE NOTE:END *********************************************** */ // Return value if necessary if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) { // managing the number of returning variables @@ -722,9 +712,9 @@ public: // else returnval++; Replaceall(tm, "$source", Swig_cresult_name()); if (GetFlag(n, "feature:new")) { - Replaceall(tm, "$owner", "1"); + Replaceall(tm, "$owner", "1"); } else { - Replaceall(tm, "$owner", "0"); + Replaceall(tm, "$owner", "0"); } Printf(f->code, "%s\n", tm); // returnval++; @@ -742,8 +732,8 @@ public: /* Look to see if there is any newfree cleanup code */ if (GetFlag(n, "feature:new")) { if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) { - Replaceall(tm, "$source", Swig_cresult_name()); - Printf(f->code, "%s\n", tm); + Replaceall(tm, "$source", Swig_cresult_name()); + Printf(f->code, "%s\n", tm); } } @@ -772,29 +762,29 @@ public: /* Dump the function out */ /* in Lua we will not emit the destructor as a wrappered function, - Lua will automatically call the destructor when the object is free'd - However: you cannot just skip this function as it will not emit - any custom destructor (using %extend), as you need to call emit_action() - Therefore we go though the whole function, - but do not write the code into the wrapper - */ - if(!current[DESTRUCTOR]) { - Wrapper_print(f, f_wrappers); + Lua will automatically call the destructor when the object is free'd + However: you cannot just skip this function as it will not emit + any custom destructor (using %extend), as you need to call emit_action() + Therefore we go though the whole function, + but do not write the code into the wrapper + */ + if (!current[DESTRUCTOR]) { + Wrapper_print(f, f_wrappers); } - + /* NEW LANGUAGE NOTE:*********************************************** - register the function in SWIG - different language mappings seem to use different ideas - NEW LANGUAGE NOTE:END ************************************************/ + register the function in SWIG + different language mappings seem to use different ideas + NEW LANGUAGE NOTE:END *********************************************** */ /* Now register the function with the interpreter. */ int result = SWIG_OK; if (!Getattr(n, "sym:overloaded")) { - if (functionWrapperRegisterNow()) { // emit normal fns & static fns - registerMethod(luaCurrentSymbolNSpace(), n); + if (functionWrapperRegisterNow()) { // emit normal fns & static fns + registerMethod(luaCurrentSymbolNSpace(), n); } } else { if (!Getattr(n, "sym:nextSibling")) { - result = dispatchFunction(n); + result = dispatchFunction(n); } } @@ -816,11 +806,11 @@ public: * ------------------------------------------------------------ */ /* NEW LANGUAGE NOTE:*********************************************** - This is an extra function used for overloading of functions - it checks the args & then calls the relevant fn - nost of the real work in again typemaps: - look for %typecheck(SWIG_TYPECHECK_*) in the .swg file - NEW LANGUAGE NOTE:END ************************************************/ + This is an extra function used for overloading of functions + it checks the args & then calls the relevant fn + nost of the real work in again typemaps: + look for %typecheck(SWIG_TYPECHECK_*) in the .swg file + NEW LANGUAGE NOTE:END *********************************************** */ int dispatchFunction(Node *n) { //REPORT("dispatchFunction", n); /* Last node in overloaded chain */ @@ -855,7 +845,7 @@ public: Replaceall(dispatch, "$args", "self,args"); Printv(f->code, dispatch, "\n", NIL); - + Node *sibl = n; while (Getattr(sibl, "sym:previousSibling")) sibl = Getattr(sibl, "sym:previousSibling"); // go all the way up @@ -866,7 +856,7 @@ public: Delete(fulldecl); } while ((sibl = Getattr(sibl, "sym:nextSibling"))); Printf(f->code, "SWIG_Lua_pusherrstring(L,\"Wrong arguments for overloaded function '%s'\\n\"\n" - "\" Possible C/C++ prototypes are:\\n\"%s);\n",symname,protoTypes); + "\" Possible C/C++ prototypes are:\\n\"%s);\n", symname, protoTypes); Delete(protoTypes); Printf(f->code, "lua_error(L);return 0;\n"); @@ -876,12 +866,12 @@ public: // Remember C name of the wrapping function rememberWrapName(n, wname); - if (functionWrapperRegisterNow()) { // emit normal fns & static fns + if (functionWrapperRegisterNow()) { // emit normal fns & static fns registerMethod(luaCurrentSymbolNSpace(), n); } if (current[CONSTRUCTOR]) { - if( constructor_name != 0 ) - Delete(constructor_name); + if (constructor_name != 0) + Delete(constructor_name); constructor_name = Copy(wname); } @@ -899,45 +889,45 @@ public: // Add variable to the "attributes" (or "get"/"set" in // case of elua_ltr) C arrays of given namespace or class - void registerVariable(String *nspace_or_class_name, Node* n, const char *getAttrName, const char *setAttrName) { - String *unassignable = NewString("SWIG_Lua_set_immutable"); - String *getName = Getattr(n,getAttrName); - String *setName = Getattr(n,setAttrName); - if(setName == 0 || GetFlag(n, "feature:immutable")) { - setName = unassignable; - } - Hash* nspaceHash = getNamespaceHash( nspace_or_class_name ); - String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); - String* s_ns_var_tab = Getattr(nspaceHash, "attributes"); - String *target_name = Getattr(n, "lua:name"); - if (elua_ltr) { - String* s_ns_dot_get = Getattr(nspaceHash, "get"); - String* s_ns_dot_set = Getattr(nspaceHash, "set"); - Printf(s_ns_dot_get, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, target_name, getName); - Printf(s_ns_dot_set, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, target_name, setName); - } else if (eluac_ltr) { - Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", target_name, "_get", "\")", ", LFUNCVAL(", getName, ")", "},\n", NIL); - Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", target_name, "_set", "\")", ", LFUNCVAL(", setName, ")", "},\n", NIL); - } else { - Printf(s_ns_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, target_name, getName, setName); - } + void registerVariable(String *nspace_or_class_name, Node *n, const char *getAttrName, const char *setAttrName) { + String *unassignable = NewString("SWIG_Lua_set_immutable"); + String *getName = Getattr(n, getAttrName); + String *setName = Getattr(n, setAttrName); + if (setName == 0 || GetFlag(n, "feature:immutable")) { + setName = unassignable; + } + Hash *nspaceHash = getNamespaceHash(nspace_or_class_name); + String *s_ns_methods_tab = Getattr(nspaceHash, "methods"); + String *s_ns_var_tab = Getattr(nspaceHash, "attributes"); + String *target_name = Getattr(n, "lua:name"); + if (elua_ltr) { + String *s_ns_dot_get = Getattr(nspaceHash, "get"); + String *s_ns_dot_set = Getattr(nspaceHash, "set"); + Printf(s_ns_dot_get, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, target_name, getName); + Printf(s_ns_dot_set, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, target_name, setName); + } else if (eluac_ltr) { + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", target_name, "_get", "\")", ", LFUNCVAL(", getName, ")", "},\n", NIL); + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", target_name, "_set", "\")", ", LFUNCVAL(", setName, ")", "},\n", NIL); + } else { + Printf(s_ns_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, target_name, getName, setName); + } } virtual int variableWrapper(Node *n) { /* NEW LANGUAGE NOTE:*********************************************** - Language::variableWrapper(n) will generate two wrapper fns - Foo_get & Foo_set by calling functionWrapper() - so we will just add these into the variable lists - ideally we should not have registered these as functions, - only WRT this variable will look into this later. - NEW LANGUAGE NOTE:END ************************************************/ + Language::variableWrapper(n) will generate two wrapper fns + Foo_get & Foo_set by calling functionWrapper() + so we will just add these into the variable lists + ideally we should not have registered these as functions, + only WRT this variable will look into this later. + NEW LANGUAGE NOTE:END *********************************************** */ // REPORT("variableWrapper", n); String *target_name = Getattr(n, "lua:name"); assert(target_name != 0); current[VARIABLE] = true; // let SWIG generate the wrappers int result = Language::variableWrapper(n); - registerVariable( luaCurrentSymbolNSpace(), n, "varget:wrap:name", "varset:wrap:name" ); + registerVariable(luaCurrentSymbolNSpace(), n, "varget:wrap:name", "varset:wrap:name"); current[VARIABLE] = false; return result; } @@ -950,24 +940,24 @@ public: /* Add constant to appropriate C array. constantRecord is an array record. * Actually, in current implementation it is resolved consttab typemap */ - void registerConstant( String *nspace, String *constantRecord ) { - Hash *nspaceHash = getNamespaceHash( nspace ); - String *s_const_tab = 0; - if( eluac_ltr || elua_ltr ) - // In elua everything goes to "methods" tab - s_const_tab = Getattr(nspaceHash, "methods"); - else - s_const_tab = Getattr(nspaceHash, "constants"); + void registerConstant(String *nspace, String *constantRecord) { + Hash *nspaceHash = getNamespaceHash(nspace); + String *s_const_tab = 0; + if (eluac_ltr || elua_ltr) + // In elua everything goes to "methods" tab + s_const_tab = Getattr(nspaceHash, "methods"); + else + s_const_tab = Getattr(nspaceHash, "constants"); + assert(s_const_tab != 0); + Printf(s_const_tab, " %s,\n", constantRecord); + + if ((eluac_ltr || elua_ltr) && v2_compatibility) { + s_const_tab = Getattr(nspaceHash, "constants"); assert(s_const_tab != 0); Printf(s_const_tab, " %s,\n", constantRecord); + } - if( ( eluac_ltr || elua_ltr ) && v2_compatibility ) { - s_const_tab = Getattr(nspaceHash, "constants"); - assert(s_const_tab != 0); - Printf(s_const_tab, " %s,\n", constantRecord); - } - } virtual int constantWrapper(Node *n) { @@ -975,7 +965,7 @@ public: String *name = Getattr(n, "name"); String *iname = Getattr(n, "sym:name"); String *target_name = Getattr(n, "lua:name"); - if(target_name == 0) + if (target_name == 0) target_name = iname; String *nsname = Copy(iname); SwigType *type = Getattr(n, "type"); @@ -1005,7 +995,7 @@ public: Replaceall(tm, "$target", target_name); Replaceall(tm, "$value", value); Replaceall(tm, "$nsname", nsname); - registerConstant( luaCurrentSymbolNSpace(), tm); + registerConstant(luaCurrentSymbolNSpace(), tm); } else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) { Replaceall(tm, "$source", value); Replaceall(tm, "$target", target_name); @@ -1021,37 +1011,37 @@ public: bool make_v2_compatible = v2_compatibility && getCurrentClass() != 0; - if( make_v2_compatible ) { + if (make_v2_compatible) { target_name_v2 = Swig_name_member(0, class_symname, target_name); iname_v2 = Swig_name_member(0, class_symname, iname); n_v2 = Copy(n); //Printf( stdout, "target name v2: %s, symname v2 %s\n", target_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE if (!luaAddSymbol(iname_v2, n, class_parent_nspace)) { - return SWIG_ERROR; + return SWIG_ERROR; } Setattr(n_v2, "sym:name", target_name_v2); tm_v2 = Swig_typemap_lookup("consttab", n_v2, name, 0); if (tm_v2) { - //Printf(stdout, "tm v2: %s\n", tm_v2.ptr()); // TODO:REMOVE - Replaceall(tm_v2, "$source", value); - Replaceall(tm_v2, "$target", target_name_v2); - Replaceall(tm_v2, "$value", value); - Replaceall(tm_v2, "$nsname", nsname); - registerConstant( class_parent_nspace, tm_v2); + //Printf(stdout, "tm v2: %s\n", tm_v2.ptr()); // TODO:REMOVE + Replaceall(tm_v2, "$source", value); + Replaceall(tm_v2, "$target", target_name_v2); + Replaceall(tm_v2, "$value", value); + Replaceall(tm_v2, "$nsname", nsname); + registerConstant(class_parent_nspace, tm_v2); } else { - tm_v2 = Swig_typemap_lookup("constcode", n_v2, name, 0); - if( !tm_v2) { - // This can't be. - assert(false); - Swig_restore(n); - return SWIG_ERROR; - } - Replaceall(tm_v2, "$source", value); - Replaceall(tm_v2, "$target", target_name_v2); - Replaceall(tm_v2, "$value", value); - Replaceall(tm_v2, "$nsname", nsname); - Printf(f_init, "%s\n", tm_v2); + tm_v2 = Swig_typemap_lookup("constcode", n_v2, name, 0); + if (!tm_v2) { + // This can't be. + assert(false); + Swig_restore(n); + return SWIG_ERROR; + } + Replaceall(tm_v2, "$source", value); + Replaceall(tm_v2, "$target", target_name_v2); + Replaceall(tm_v2, "$value", value); + Replaceall(tm_v2, "$nsname", nsname); + Printf(f_init, "%s\n", tm_v2); } Delete(n_v2); } @@ -1072,8 +1062,8 @@ public: if (!luaAddSymbol(wrapname, n)) return SWIG_ERROR; - Hash *nspaceHash = getNamespaceHash( getNSpace() ); - String* s_ns_methods_tab = Getattr(nspaceHash, "methods"); + Hash *nspaceHash = getNamespaceHash(getNSpace()); + String *s_ns_methods_tab = Getattr(nspaceHash, "methods"); Printv(s_ns_methods_tab, tab4, "{ \"", symname, "\",", wrapname, "},\n", NIL); // return Language::nativeWrapper(n); // this does nothing... return SWIG_OK; @@ -1084,10 +1074,10 @@ public: * ------------------------------------------------------------ */ virtual int enumDeclaration(Node *n) { - current[STATIC_CONST] = true; - int result = Language::enumDeclaration(n); - current[STATIC_CONST] = false; - return result; + current[STATIC_CONST] = true; + int result = Language::enumDeclaration(n); + current[STATIC_CONST] = false; + return result; } /* ------------------------------------------------------------ @@ -1134,7 +1124,7 @@ public: String *mangled_class_fq_symname; String *destructor_name; - String* nspace = getNSpace(); + String *nspace = getNSpace(); constructor_name = 0; have_constructor = 0; @@ -1161,10 +1151,10 @@ public: assert(class_fq_symname != 0); mangled_class_fq_symname = Swig_name_mangle(class_fq_symname); - SwigType *t( Copy(Getattr(n, "name")) ); - SwigType *fr_t( SwigType_typedef_resolve_all(t) ); /* Create fully resolved type */ + SwigType *t(Copy(Getattr(n, "name"))); + SwigType *fr_t(SwigType_typedef_resolve_all(t)); /* Create fully resolved type */ SwigType *t_tmp = 0; - t_tmp = SwigType_typedef_qualified(fr_t); // Temporal variable + t_tmp = SwigType_typedef_qualified(fr_t); // Temporal variable Delete(fr_t); fr_t = SwigType_strip_qualifiers(t_tmp); String *mangled_fr_t = 0; @@ -1195,10 +1185,10 @@ public: // And we can guarantee that there will not be any name collision because names starting with 2 underscores // and capital letter are forbiden to use in C++. So, under know circumstances could our class contain // any member or subclass with name "__Static". Thus, never any name clash. - Hash* instance_cls = getNamespaceHash(class_fq_symname, false); + Hash *instance_cls = getNamespaceHash(class_fq_symname, false); assert(instance_cls != 0); - String* s_attr_tab_name = Getattr(instance_cls, "attributes:name"); - String* s_methods_tab_name = Getattr(instance_cls, "methods:name"); + String *s_attr_tab_name = Getattr(instance_cls, "attributes:name"); + String *s_methods_tab_name = Getattr(instance_cls, "methods:name"); Setattr(instance_cls, "lua:no_namespaces", "1"); Setattr(instance_cls, "lua:no_classes", "1"); Setattr(instance_cls, "lua:class_instance", "1"); @@ -1240,24 +1230,24 @@ public: // Adding class to apropriate namespace Hash *nspaceHash = getNamespaceHash(nspace); String *ns_classes = Getattr(nspaceHash, "classes"); - Printv( ns_classes, wrap_class, ",\n", NIL ); + Printv(ns_classes, wrap_class, ",\n", NIL); // Register the class structure with the type checker // Printf(f_init,"SWIG_TypeClientData(SWIGTYPE%s, (void *) &_wrap_class_%s);\n", SwigType_manglestr(t), mangled_class_fq_symname); - + // emit a function to be called to delete the object if (have_destructor) { destructor_name = NewStringf("swig_delete_%s", mangled_class_fq_symname); Printv(f_wrappers, "static void ", destructor_name, "(void *obj) {\n", NIL); if (destructor_action) { - Printv(f_wrappers, SwigType_str(rt, "arg1"), " = (", SwigType_str(rt, 0), ") obj;\n", NIL); - Printv(f_wrappers, destructor_action, "\n", NIL); + Printv(f_wrappers, SwigType_str(rt, "arg1"), " = (", SwigType_str(rt, 0), ") obj;\n", NIL); + Printv(f_wrappers, destructor_action, "\n", NIL); } else { - if (CPlusPlus) { - Printv(f_wrappers, " delete (", SwigType_str(rt, 0), ") obj;\n", NIL); - } else { - Printv(f_wrappers, " free((char *) obj);\n", NIL); - } + if (CPlusPlus) { + Printv(f_wrappers, " delete (", SwigType_str(rt, 0), ") obj;\n", NIL); + } else { + Printv(f_wrappers, " free((char *) obj);\n", NIL); + } } Printf(f_wrappers, "}\n"); } @@ -1266,33 +1256,32 @@ public: // Module.ClassName.StaticMethod to access static method/variable/constant // Module.ClassName() to create new object if (have_constructor) { - String* constructor_proxy_name = NewStringf("_proxy_%s", constructor_name); + String *constructor_proxy_name = NewStringf("_proxy_%s", constructor_name); Printv(f_wrappers, "static int ", constructor_proxy_name, "(lua_State *L) {\n", NIL); Printv(f_wrappers, - tab4, "assert(lua_istable(L,1));\n", - tab4, "lua_pushcfunction(L,", constructor_name, ");\n", - tab4, "assert(!lua_isnil(L,-1));\n", - tab4, "lua_replace(L,1); /* replace our table with real constructor */\n", - tab4, "lua_call(L,lua_gettop(L)-1,1);\n", - tab4, "return 1;\n}\n", NIL); + tab4, "assert(lua_istable(L,1));\n", + tab4, "lua_pushcfunction(L,", constructor_name, ");\n", + tab4, "assert(!lua_isnil(L,-1));\n", + tab4, "lua_replace(L,1); /* replace our table with real constructor */\n", + tab4, "lua_call(L,lua_gettop(L)-1,1);\n", + tab4, "return 1;\n}\n", NIL); Delete(constructor_name); constructor_name = constructor_proxy_name; if (elua_ltr) { - String* static_cls_metatable_tab = Getattr(static_cls, "metatable"); - assert(static_cls_metatable_tab != 0); - Printf(static_cls_metatable_tab, " {LSTRKEY(\"__call\"), LFUNCVAL(%s)},\n", constructor_name); + String *static_cls_metatable_tab = Getattr(static_cls, "metatable"); + assert(static_cls_metatable_tab != 0); + Printf(static_cls_metatable_tab, " {LSTRKEY(\"__call\"), LFUNCVAL(%s)},\n", constructor_name); } else if (eluac_ltr) { - String* ns_methods_tab = Getattr(nspaceHash, "methods"); - assert(ns_methods_tab != 0); - Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "new_", class_symname, "\")", ", LFUNCVAL(", \ - constructor_name, ")", "},\n", NIL); + String *ns_methods_tab = Getattr(nspaceHash, "methods"); + assert(ns_methods_tab != 0); + Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "new_", class_symname, "\")", ", LFUNCVAL(", constructor_name, ")", "},\n", NIL); } } if (have_destructor) { if (eluac_ltr) { - String* ns_methods_tab = Getattr(nspaceHash, "methods"); - assert(ns_methods_tab != 0); - Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_class_fq_symname, "\")", ", LFUNCVAL(", destructor_name, ")", "},\n", NIL); + String *ns_methods_tab = Getattr(nspaceHash, "methods"); + assert(ns_methods_tab != 0); + Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_class_fq_symname, "\")", ", LFUNCVAL(", destructor_name, ")", "},\n", NIL); } } @@ -1318,20 +1307,19 @@ public: int index = 0; b = First(baselist); while (b.item) { - String *bname = Getattr(b.item, "name"); - if ((!bname) || GetFlag(b.item, "feature:ignore") || (!Getattr(b.item, "module"))) { - b = Next(b); - continue; - } - // stores a null pointer & the name - Printf(base_class, "0,"); - Printf(base_class_names, "\"%s *\",", SwigType_namestr(bname)); + String *bname = Getattr(b.item, "name"); + if ((!bname) || GetFlag(b.item, "feature:ignore") || (!Getattr(b.item, "module"))) { + b = Next(b); + continue; + } + // stores a null pointer & the name + Printf(base_class, "0,"); + Printf(base_class_names, "\"%s *\",", SwigType_namestr(bname)); - b = Next(b); - index++; + b = Next(b); + index++; } } - // First, print class static part printNamespaceDefinition(class_static_nspace, class_symname, f_wrappers); @@ -1341,7 +1329,8 @@ public: Printv(f_wrappers, "static const char *swig_", mangled_class_fq_symname, "_base_names[] = {", base_class_names, "0};\n", NIL); Delete(base_class_names); - Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_class_fq_symname, " = { \"", class_symname, "\", \"", class_fq_symname,"\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); + Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_class_fq_symname, " = { \"", class_symname, "\", \"", class_fq_symname, "\", &SWIGTYPE", + SwigType_manglestr(t), ",", NIL); if (have_constructor) { Printv(f_wrappers, constructor_name, NIL); @@ -1352,13 +1341,12 @@ public: } if (have_destructor) { - Printv(f_wrappers, ", ", destructor_name, NIL); + Printv(f_wrappers, ", ", destructor_name, NIL); } else { Printf(f_wrappers, ",0"); } - Printf(f_wrappers, ", %s, %s, &%s", s_methods_tab_name, s_attr_tab_name, Getattr(static_cls, "cname") ); - Printf(f_wrappers, ", swig_%s_bases, swig_%s_base_names };\n\n", - mangled_class_fq_symname, mangled_class_fq_symname); + Printf(f_wrappers, ", %s, %s, &%s", s_methods_tab_name, s_attr_tab_name, Getattr(static_cls, "cname")); + Printf(f_wrappers, ", swig_%s_bases, swig_%s_base_names };\n\n", mangled_class_fq_symname, mangled_class_fq_symname); current[NO_CPP] = true; Delete(class_static_nspace); @@ -1393,7 +1381,7 @@ public: if (!Getattr(n, "sym:nextSibling")) { //Printf( stdout, "add member function: %s to %s\n", symname, luaCurrentSymbolNSpace());// TODO: REMOVE - registerMethod( luaCurrentSymbolNSpace(), n); + registerMethod(luaCurrentSymbolNSpace(), n); } current[MEMBER_FUNC] = false; return SWIG_OK; @@ -1407,7 +1395,7 @@ public: // REPORT("membervariableHandler",n); current[MEMBER_VAR] = true; Language::membervariableHandler(n); - registerVariable( luaCurrentSymbolNSpace(), n, "memberget:wrap:name", "memberset:wrap:name" ); + registerVariable(luaCurrentSymbolNSpace(), n, "memberget:wrap:name", "memberset:wrap:name"); current[MEMBER_VAR] = false; return SWIG_OK; } @@ -1451,7 +1439,7 @@ public: * ---------------------------------------------------------------------- */ int globalfunctionHandler(Node *n) { bool oldVal = current[NO_CPP]; - if(!current[STATIC_FUNC]) // If static funct, don't switch to NO_CPP + if (!current[STATIC_FUNC]) // If static funct, don't switch to NO_CPP current[NO_CPP] = true; int result = Language::globalfunctionHandler(n); current[NO_CPP] = oldVal; @@ -1473,12 +1461,12 @@ public: if (result != SWIG_OK) return result; - if(v2_compatibility) { + if (v2_compatibility) { Swig_require("lua_staticmemberfunctionHandler", n, "*lua:name", NIL); String *target_name = Getattr(n, "lua:name"); String *compat_name = Swig_name_member(0, class_symname, target_name); Setattr(n, "lua:name", compat_name); - registerMethod( class_parent_nspace, n ); + registerMethod(class_parent_nspace, n); Delete(compat_name); Swig_restore(n); } @@ -1493,7 +1481,7 @@ public: * ------------------------------------------------------------ */ virtual int memberconstantHandler(Node *n) { - REPORT("memberconstantHandler",n); + REPORT("memberconstantHandler", n); int result = Language::memberconstantHandler(n); return result; @@ -1504,27 +1492,27 @@ public: * --------------------------------------------------------------------- */ virtual int staticmembervariableHandler(Node *n) { - REPORT("staticmembervariableHandler",n); + REPORT("staticmembervariableHandler", n); current[STATIC_VAR] = true; //String *symname = Getattr(n, "sym:name"); int result = Language::staticmembervariableHandler(n); if (result == SWIG_OK) { // This will add static member variable to the class namespace with name ClassName_VarName - if(v2_compatibility) { - Swig_save("lua_staticmembervariableHandler",n,"lua:name"); - String *target_name = Getattr(n, "lua:name"); - String *v2_name = Swig_name_member(NIL, class_symname, target_name); - //Printf( stdout, "Name %s, class %s, compt. name %s\n", target_name, class_symname, v2_name ); // TODO: REMOVE - if( !GetFlag(n,"wrappedasconstant") ) { - Setattr(n, "lua:name", v2_name); - registerVariable( class_parent_nspace, n, "varget:wrap:name", "varset:wrap:name"); - } - // If static member variable was wrapped as constant, then - // constant wrapper has already performed all actions - // necessary for v2_compatibility - Delete(v2_name); - Swig_restore(n); + if (v2_compatibility) { + Swig_save("lua_staticmembervariableHandler", n, "lua:name"); + String *target_name = Getattr(n, "lua:name"); + String *v2_name = Swig_name_member(NIL, class_symname, target_name); + //Printf( stdout, "Name %s, class %s, compt. name %s\n", target_name, class_symname, v2_name ); // TODO: REMOVE + if (!GetFlag(n, "wrappedasconstant")) { + Setattr(n, "lua:name", v2_name); + registerVariable(class_parent_nspace, n, "varget:wrap:name", "varset:wrap:name"); + } + // If static member variable was wrapped as constant, then + // constant wrapper has already performed all actions + // necessary for v2_compatibility + Delete(v2_name); + Swig_restore(n); } } current[STATIC_VAR] = false; @@ -1546,7 +1534,7 @@ public: */ String *runtimeCode() { String *s = NewString(""); - const char *filenames[] = { "luarun.swg", 0 } ; // must be 0 terminated + const char *filenames[] = { "luarun.swg", 0 }; // must be 0 terminated emitLuaFlavor(s); @@ -1554,10 +1542,10 @@ public: for (int i = 0; filenames[i] != 0; i++) { sfile = Swig_include_sys(filenames[i]); if (!sfile) { - Printf(stderr, "*** Unable to open '%s'\n", filenames[i]); + Printf(stderr, "*** Unable to open '%s'\n", filenames[i]); } else { - Append(s, sfile); - Delete(sfile); + Append(s, sfile); + Delete(sfile); } } @@ -1567,7 +1555,7 @@ public: String *defaultExternalRuntimeFilename() { return NewString("swigluarun.h"); } - + /* --------------------------------------------------------------------- * helpers * --------------------------------------------------------------------- */ @@ -1580,75 +1568,73 @@ public: else Printf(s, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_LUA\n"); } - + /* This is to convert the string of Lua code into a proper string, which can then be emitted into the C/C++ code. Basically is is a lot of search & replacing of odd sequences */ - void EscapeCode(String* str) - { + void EscapeCode(String *str) { //Printf(f_runtime,"/* original luacode:[[[\n%s\n]]]\n*/\n",str); - Chop(str); // trim - Replace(str,"\\","\\\\",DOH_REPLACE_ANY); // \ to \\ (this must be done first) - Replace(str,"\"","\\\"",DOH_REPLACE_ANY); // " to \" - Replace(str,"\n","\\n\"\n \"",DOH_REPLACE_ANY); // \n to \n"\n" (ie quoting every line) + Chop(str); // trim + Replace(str, "\\", "\\\\", DOH_REPLACE_ANY); // \ to \\ (this must be done first) + Replace(str, "\"", "\\\"", DOH_REPLACE_ANY); // " to \" + Replace(str, "\n", "\\n\"\n \"", DOH_REPLACE_ANY); // \n to \n"\n" (ie quoting every line) //Printf(f_runtime,"/* hacked luacode:[[[\n%s\n]]]\n*/\n",str); - } + } /* Each namespace can be described with hash that stores C arrays - where members of the namespace should be added. All these hashes are stored - inside namespaces_hash. - nspace could be NULL (NSPACE_TODO), that means functions and variables and classes - that are not in any namespace (this is default for SWIG unless %nspace feature is used) - You can later set some attributes that will affect behaviour of functions that use this hash: - "lua:no_namespaces" will disable "namespaces" array. - "lua:no_classes" will disable "classes" array. - For every component ("attributes", "methods", etc) there are subcomponents: - * XXX:name - name of the C array that stores data for component - * XXX:decl - statement with forward declaration of this array; + where members of the namespace should be added. All these hashes are stored + inside namespaces_hash. + nspace could be NULL (NSPACE_TODO), that means functions and variables and classes + that are not in any namespace (this is default for SWIG unless %nspace feature is used) + You can later set some attributes that will affect behaviour of functions that use this hash: + "lua:no_namespaces" will disable "namespaces" array. + "lua:no_classes" will disable "classes" array. + For every component ("attributes", "methods", etc) there are subcomponents: + * XXX:name - name of the C array that stores data for component + * XXX:decl - statement with forward declaration of this array; */ - Hash* getNamespaceHash(String *nspace, bool reg = true) - { - Hash* nspace_hash = Getattr(namespaces_hash, nspace?nspace:"" ); + Hash *getNamespaceHash(String *nspace, bool reg = true) { + Hash *nspace_hash = Getattr(namespaces_hash, nspace ? nspace : ""); if (nspace_hash != 0) return nspace_hash; nspace_hash = NewHash(); - String* mangled_name = 0; + String *mangled_name = 0; if (nspace == 0 || Len(nspace) == 0) - mangled_name = NewString("__Global"); // C++ names can't start with "__ + capital letter" + mangled_name = NewString("__Global"); // C++ names can't start with "__ + capital letter" else mangled_name = Swig_name_mangle(nspace); - String* cname = NewStringf("swig_%s", mangled_name); + String *cname = NewStringf("swig_%s", mangled_name); if (reg && nspace != 0 && Len(nspace) != 0 && Getattr(nspace_hash, "lua:no_reg") == 0) { // Split names into components - List* components = Split(nspace, '.', -1); + List *components = Split(nspace, '.', -1); String *parent_path = NewString(""); int len = Len(components); - String* name = Copy(Getitem(components, len-1)); - for( int i = 0; i < len-1; i++ ) { - if (i > 0) - Printv(parent_path, NSPACE_SEPARATOR, NIL); - String* item = Getitem(components, i); - Printv(parent_path, item, NIL); + String *name = Copy(Getitem(components, len - 1)); + for (int i = 0; i < len - 1; i++) { + if (i > 0) + Printv(parent_path, NSPACE_SEPARATOR, NIL); + String *item = Getitem(components, i); + Printv(parent_path, item, NIL); } //Printf(stdout, "Registering %s. User name %s. C-name %s, Parent is %s\n", mangled_name, name, cname, parent_path); // TODO: REMOVE - Hash* parent = getNamespaceHash(parent_path, true); - String* namespaces_tab = Getattr(parent, "namespaces"); + Hash *parent = getNamespaceHash(parent_path, true); + String *namespaces_tab = Getattr(parent, "namespaces"); Printv(namespaces_tab, "&", cname, ",\n", NIL); Setattr(nspace_hash, "name", name); Delete(components); Delete(parent_path); - } else if (!reg) // This namespace shouldn't be registered. Lets remember it + } else if (!reg) // This namespace shouldn't be registered. Lets remember it Setattr(nspace_hash, "lua:no_reg", "1"); Setattr(nspace_hash, "cname", cname); String *attr_tab = NewString(""); - String *attr_tab_name = NewStringf("swig_%s_attributes", mangled_name ); + String *attr_tab_name = NewStringf("swig_%s_attributes", mangled_name); String *attr_tab_decl = NewString(""); Printv(attr_tab, "static swig_lua_attribute ", NIL); Printv(attr_tab, attr_tab_name, "[]", NIL); @@ -1659,54 +1645,54 @@ public: Setattr(nspace_hash, "attributes:decl", attr_tab_decl); String *methods_tab = NewString(""); - String *methods_tab_name = NewStringf("swig_%s_methods", mangled_name ); + String *methods_tab_name = NewStringf("swig_%s_methods", mangled_name); String *methods_tab_decl = NewString(""); - if (elua_ltr || eluac_ltr) // In this case methods array also acts as namespace rotable + if (elua_ltr || eluac_ltr) // In this case methods array also acts as namespace rotable Printf(methods_tab, "const LUA_REG_TYPE "); else Printf(methods_tab, "static swig_lua_method "); Printv(methods_tab, methods_tab_name, "[]", NIL); Printv(methods_tab_decl, methods_tab, ";\n", NIL); Printv(methods_tab, "= {\n", NIL); - Setattr(nspace_hash, "methods", methods_tab ); - Setattr(nspace_hash, "methods:name", methods_tab_name ); - Setattr(nspace_hash, "methods:decl", methods_tab_decl ); + Setattr(nspace_hash, "methods", methods_tab); + Setattr(nspace_hash, "methods:name", methods_tab_name); + Setattr(nspace_hash, "methods:decl", methods_tab_decl); String *const_tab = NewString(""); - String *const_tab_name = NewStringf("swig_%s_constants", mangled_name ); + String *const_tab_name = NewStringf("swig_%s_constants", mangled_name); String *const_tab_decl = NewString(""); - if (elua_ltr || eluac_ltr) // In this case const array holds rotable with namespace constants + if (elua_ltr || eluac_ltr) // In this case const array holds rotable with namespace constants Printf(const_tab, "const LUA_REG_TYPE "); else Printf(const_tab, "static swig_lua_const_info "); Printv(const_tab, const_tab_name, "[]", NIL); Printv(const_tab_decl, const_tab, ";", NIL); Printv(const_tab, "= {\n", NIL); - Setattr(nspace_hash, "constants", const_tab ); - Setattr(nspace_hash, "constants:name", const_tab_name ); - Setattr(nspace_hash, "constants:decl", const_tab_decl ); + Setattr(nspace_hash, "constants", const_tab); + Setattr(nspace_hash, "constants:name", const_tab_name); + Setattr(nspace_hash, "constants:decl", const_tab_decl); String *classes_tab = NewString(""); - String *classes_tab_name = NewStringf("swig_%s_classes", mangled_name ); + String *classes_tab_name = NewStringf("swig_%s_classes", mangled_name); String *classes_tab_decl = NewString(""); Printf(classes_tab, "static swig_lua_class* "); Printv(classes_tab, classes_tab_name, "[]", NIL); Printv(classes_tab_decl, classes_tab, ";", NIL); Printv(classes_tab, "= {\n", NIL); - Setattr(nspace_hash, "classes", classes_tab ); - Setattr(nspace_hash, "classes:name", classes_tab_name ); - Setattr(nspace_hash, "classes:decl", classes_tab_decl ); + Setattr(nspace_hash, "classes", classes_tab); + Setattr(nspace_hash, "classes:name", classes_tab_name); + Setattr(nspace_hash, "classes:decl", classes_tab_decl); - String* namespaces_tab = NewString(""); - String* namespaces_tab_name = NewStringf("swig_%s_namespaces", mangled_name ); - String* namespaces_tab_decl = NewString(""); + String *namespaces_tab = NewString(""); + String *namespaces_tab_name = NewStringf("swig_%s_namespaces", mangled_name); + String *namespaces_tab_decl = NewString(""); Printf(namespaces_tab, "static swig_lua_namespace* "); Printv(namespaces_tab, namespaces_tab_name, "[]", NIL); Printv(namespaces_tab_decl, namespaces_tab, ";", NIL); Printv(namespaces_tab, " = {\n", NIL); - Setattr(nspace_hash, "namespaces", namespaces_tab ); - Setattr(nspace_hash, "namespaces:name", namespaces_tab_name ); - Setattr(nspace_hash, "namespaces:decl", namespaces_tab_decl ); + Setattr(nspace_hash, "namespaces", namespaces_tab); + Setattr(nspace_hash, "namespaces:name", namespaces_tab_name); + Setattr(nspace_hash, "namespaces:decl", namespaces_tab_decl); if (elua_ltr) { String *get_tab = NewString(""); @@ -1730,21 +1716,21 @@ public: Setattr(nspace_hash, "set:decl", set_tab_decl); if (!eluac_ltr) { - String* metatable_tab = NewString(""); - String* metatable_tab_name = NewStringf("swig_%s_meta", mangled_name); - String *metatable_tab_decl = NewString(""); - Printv(metatable_tab, "const LUA_REG_TYPE ", metatable_tab_name, "[]", NIL); - Printv(metatable_tab_decl, metatable_tab, ";", NIL); - Printv(metatable_tab, " = {\n", NIL); - Setattr(nspace_hash, "metatable", metatable_tab); - Setattr(nspace_hash, "metatable:name", metatable_tab_name); - Setattr(nspace_hash, "metatable:decl", metatable_tab_decl); + String *metatable_tab = NewString(""); + String *metatable_tab_name = NewStringf("swig_%s_meta", mangled_name); + String *metatable_tab_decl = NewString(""); + Printv(metatable_tab, "const LUA_REG_TYPE ", metatable_tab_name, "[]", NIL); + Printv(metatable_tab_decl, metatable_tab, ";", NIL); + Printv(metatable_tab, " = {\n", NIL); + Setattr(nspace_hash, "metatable", metatable_tab); + Setattr(nspace_hash, "metatable:name", metatable_tab_name); + Setattr(nspace_hash, "metatable:decl", metatable_tab_decl); } } - String* key = 0; + String *key = 0; if (nspace != 0) key = Copy(nspace); - Setattr(namespaces_hash, key?key:"", nspace_hash); + Setattr(namespaces_hash, key ? key : "", nspace_hash); Delete(mangled_name); return nspace_hash; @@ -1758,20 +1744,19 @@ public: * if "lua:no_namespaces" is set, then array for "namespaces" won't be printed * if "lua:no_classes" is set, then array for "classes" won't be printed * */ - void closeNamespaceHash(String *nspace, File *output) - { - Hash* nspace_hash = Getattr(namespaces_hash, nspace ); + void closeNamespaceHash(String *nspace, File *output) { + Hash *nspace_hash = Getattr(namespaces_hash, nspace); assert(nspace_hash != 0); assert(Getattr(nspace_hash, "lua:closed") == 0); Setattr(nspace_hash, "lua:closed", "1"); - String* attr_tab = Getattr(nspace_hash, "attributes"); + String *attr_tab = Getattr(nspace_hash, "attributes"); Printf(attr_tab, " {0,0,0}\n};\n"); Printv(output, attr_tab, NIL); - String* const_tab = Getattr(nspace_hash, "constants"); - String* const_tab_name = Getattr(nspace_hash, "constants:name"); + String *const_tab = Getattr(nspace_hash, "constants"); + String *const_tab_name = Getattr(nspace_hash, "constants:name"); if (elua_ltr || eluac_ltr) Printv(const_tab, tab4, "{LNILKEY, LNILVAL}\n", "};\n", NIL); else @@ -1782,27 +1767,27 @@ public: // Put forward declaration of metatable array Printv(output, "extern ", Getattr(nspace_hash, "metatable:decl"), "\n", NIL); } - String* methods_tab = Getattr(nspace_hash, "methods"); - String* metatable_tab_name = Getattr(nspace_hash, "metatable:name"); + String *methods_tab = Getattr(nspace_hash, "methods"); + String *metatable_tab_name = Getattr(nspace_hash, "metatable:name"); if (elua_ltr || eluac_ltr) { - if( v2_compatibility ) - Printv(methods_tab, tab4, "{LSTRKEY(\"const\"), LROVAL(", const_tab_name, ")},\n", NIL); + if (v2_compatibility) + Printv(methods_tab, tab4, "{LSTRKEY(\"const\"), LROVAL(", const_tab_name, ")},\n", NIL); if (elua_ltr) - Printv(methods_tab, tab4, "{LSTRKEY(\"__metatable\"), LROVAL(", metatable_tab_name, ")},\n", NIL); + Printv(methods_tab, tab4, "{LSTRKEY(\"__metatable\"), LROVAL(", metatable_tab_name, ")},\n", NIL); Printv(methods_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); } else Printf(methods_tab, " {0,0}\n};\n"); Printv(output, methods_tab, NIL); - if (!Getattr(nspace_hash, "lua:no_classes") ) { - String* classes_tab = Getattr(nspace_hash, "classes"); + if (!Getattr(nspace_hash, "lua:no_classes")) { + String *classes_tab = Getattr(nspace_hash, "classes"); Printf(classes_tab, " 0\n};\n"); Printv(output, classes_tab, NIL); } - if (!Getattr(nspace_hash, "lua:no_namespaces") ) { - String* namespaces_tab = Getattr(nspace_hash, "namespaces"); + if (!Getattr(nspace_hash, "lua:no_namespaces")) { + String *namespaces_tab = Getattr(nspace_hash, "namespaces"); Printf(namespaces_tab, " 0\n};\n"); Printv(output, namespaces_tab, NIL); } @@ -1823,21 +1808,21 @@ public: Printv(metatable_tab, tab4, "{LSTRKEY(\".get\"), LROVAL(", get_tab_name, ")},\n", NIL); Printv(metatable_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(", set_tab_name, ")},\n", NIL); if (Getattr(nspace_hash, "lua:class_instance")) { - String *static_cls = Getattr(nspace_hash, "lua:class_instance:static_hash"); - assert(static_cls != 0); - // static_cls is swig_lua_namespace. This structure can't be use with eLua(LTR) - // Instead structure describing its methods isused - String *static_cls_cname = Getattr(static_cls, "methods:name"); - assert(static_cls_cname != 0); - Printv(metatable_tab, tab4, "{LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL); - // Put forward declaration of this array - Printv(output, "extern ", Getattr(static_cls, "methods:decl"), "\n", NIL); - } else if (Getattr(nspace_hash, "lua:class_static") ) { - Hash *instance_cls = Getattr(nspace_hash, "lua:class_static:instance_hash"); - assert(instance_cls != 0); - String *instance_cls_metatable_name = Getattr(instance_cls, "metatable:name"); - assert(instance_cls_metatable_name != 0); - Printv(metatable_tab, tab4, "{LSTRKEY(\".instance\"), LROVAL(", instance_cls_metatable_name, ")},\n", NIL); + String *static_cls = Getattr(nspace_hash, "lua:class_instance:static_hash"); + assert(static_cls != 0); + // static_cls is swig_lua_namespace. This structure can't be use with eLua(LTR) + // Instead structure describing its methods isused + String *static_cls_cname = Getattr(static_cls, "methods:name"); + assert(static_cls_cname != 0); + Printv(metatable_tab, tab4, "{LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL); + // Put forward declaration of this array + Printv(output, "extern ", Getattr(static_cls, "methods:decl"), "\n", NIL); + } else if (Getattr(nspace_hash, "lua:class_static")) { + Hash *instance_cls = Getattr(nspace_hash, "lua:class_static:instance_hash"); + assert(instance_cls != 0); + String *instance_cls_metatable_name = Getattr(instance_cls, "metatable:name"); + assert(instance_cls_metatable_name != 0); + Printv(metatable_tab, tab4, "{LSTRKEY(\".instance\"), LROVAL(", instance_cls_metatable_name, ")},\n", NIL); } Printv(metatable_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); @@ -1846,36 +1831,37 @@ public: Printv(output, "\n", NIL); } - static int compareByLen( const DOH* f, const DOH* s) { return Len(s) - Len(f); } + static int compareByLen(const DOH *f, const DOH *s) { + return Len(s) - Len(f); + } // Recursively close all non-closed namespaces. Prints data to dataOutput, - void closeNamespaces(File *dataOutput) - { + void closeNamespaces(File *dataOutput) { // Special handling for empty module. - if( Getattr(namespaces_hash, "") == 0 ) { + if (Getattr(namespaces_hash, "") == 0) { // Module is empty. Create hash for global scope in order to have swig__Global // variable in resulting file getNamespaceHash(0); } Iterator ki = First(namespaces_hash); - List* to_close = NewList(); + List *to_close = NewList(); while (ki.key) { if (Getattr(ki.item, "lua:closed") == 0) - Append(to_close, ki.key); + Append(to_close, ki.key); ki = Next(ki); } SortList(to_close, &compareByLen); int len = Len(to_close); - for( int i = 0; i < len; i++ ) { - String* key = Getitem(to_close,i); + for (int i = 0; i < len; i++) { + String *key = Getitem(to_close, i); closeNamespaceHash(key, dataOutput); - Hash* nspace = Getattr(namespaces_hash, key); - String *name = 0; // name - name of the namespace as it should be visible in Lua - if (DohLen(key) == 0) // This is global module - name = module; + Hash *nspace = Getattr(namespaces_hash, key); + String *name = 0; // name - name of the namespace as it should be visible in Lua + if (DohLen(key) == 0) // This is global module + name = module; else - name = Getattr(nspace, "name"); + name = Getattr(nspace, "name"); assert(name != 0); - printNamespaceDefinition( key, name, dataOutput ); + printNamespaceDefinition(key, name, dataOutput); } Delete(to_close); } @@ -1885,11 +1871,10 @@ public: // You can call this function as many times as necessary. // 'name' is a user-visible name that this namespace will have in Lua. It shouldn't // be fully qualified name, just it's own name. - void printNamespaceDefinition(String *nspace, String* name, File *output) - { + void printNamespaceDefinition(String *nspace, String *name, File *output) { Hash *nspace_hash = getNamespaceHash(nspace, false); - String* cname = Getattr(nspace_hash, "cname"); // cname - name of the C structure that describes namespace + String *cname = Getattr(nspace_hash, "cname"); // cname - name of the C structure that describes namespace assert(cname != 0); Printv(output, "static swig_lua_namespace ", cname, " = ", NIL); @@ -1904,14 +1889,12 @@ public: bool has_namespaces = Getattr(nspace_hash, "lua:no_namespaces") == 0; Printv(output, "{\n", - tab4, "\"", name, "\",\n", - tab4, methods_tab_name, ",\n", - tab4, attr_tab_name, ",\n", - tab4, const_tab_name, ",\n", - tab4, (has_classes)?classes_tab_name:null_string, ",\n", - tab4, (has_namespaces)?namespaces_tab_name:null_string, "\n};\n", - NIL - ); + tab4, "\"", name, "\",\n", + tab4, methods_tab_name, ",\n", + tab4, attr_tab_name, ",\n", + tab4, const_tab_name, ",\n", + tab4, (has_classes) ? classes_tab_name : null_string, ",\n", + tab4, (has_namespaces) ? namespaces_tab_name : null_string, "\n};\n", NIL); Delete(null_string); } @@ -1921,22 +1904,22 @@ public: // instance class member/function or just global functions decides // where symbol should be put. // The namespace/scope doesn't depend from symbol, only from 'current' - String* luaCurrentSymbolNSpace() { - String* scope = 0; + String *luaCurrentSymbolNSpace() { + String *scope = 0; // If ouside class, than NSpace is used. // If inside class, but current[NO_CPP], then this is friend function. It belongs to NSpace - if( !getCurrentClass() || current[NO_CPP]) { + if (!getCurrentClass() || current[NO_CPP]) { scope = getNSpace(); } else { // If inside class, then either class static namespace or class fully qualified name is used assert(!current[NO_CPP]); - if(current[STATIC_FUNC] || current[STATIC_VAR] || current[STATIC_CONST] ) { - scope = class_static_nspace; - } else if(current[MEMBER_VAR] || current[CONSTRUCTOR] || current[DESTRUCTOR] - || current[MEMBER_FUNC] ) { - scope = class_fq_symname; - } else { // Friend functions are handled this way - scope = class_static_nspace; + if (current[STATIC_FUNC] || current[STATIC_VAR] || current[STATIC_CONST]) { + scope = class_static_nspace; + } else if (current[MEMBER_VAR] || current[CONSTRUCTOR] || current[DESTRUCTOR] + || current[MEMBER_FUNC]) { + scope = class_fq_symname; + } else { // Friend functions are handled this way + scope = class_static_nspace; } assert(scope != 0); } @@ -1947,35 +1930,34 @@ public: int luaAddSymbol(const String *s, const Node *n) { String *scope = luaCurrentSymbolNSpace(); //Printf(stdout, "luaAddSymbol: %s scope: %s\n", s, scope); - int result = Language::addSymbol(s,n,scope); - if( !result ) - Printf(stderr,"addSymbol(%s to scope %s) failed\n",s, scope); + int result = Language::addSymbol(s, n, scope); + if (!result) + Printf(stderr, "addSymbol(%s to scope %s) failed\n", s, scope); return result; } // Overload. Enforces given scope. Actually, it simply forwards call to Language::addSymbol - int luaAddSymbol(const String*s, const Node*n, const_String_or_char_ptr scope) { + int luaAddSymbol(const String *s, const Node *n, const_String_or_char_ptr scope) { //Printf(stdout, "luaAddSymbol: %s scope: %s\n", s, scope); - int result = Language::addSymbol(s,n,scope); - if( !result ) - Printf(stderr,"addSymbol(%s to scope %s) failed\n",s, scope); + int result = Language::addSymbol(s, n, scope); + if (!result) + Printf(stderr, "addSymbol(%s to scope %s) failed\n", s, scope); return result; } // Function creates fully qualified name of given symbol. Current NSpace and current class // are used - String* fully_qualified_name(const_String_or_char_ptr name) - { + String *fully_qualified_name(const_String_or_char_ptr name) { assert(name != 0); - String* scope= 0; - if( getCurrentClass() ) + String *scope = 0; + if (getCurrentClass()) scope = class_fq_symname; else scope = getNSpace(); String *fqname = 0; - if( scope ) - fqname = NewStringf("%s::%s",scope,name); + if (scope) + fqname = NewStringf("%s::%s", scope, name); else fqname = Copy(name); @@ -1984,10 +1966,9 @@ public: // Input: symname // Output - wrapper around fully qualified form of symname - String* symname_wrapper( String *symname) - { + String *symname_wrapper(String *symname) { String *fqname = fully_qualified_name(symname); - String* wname = Swig_name_wrapper(fqname); + String *wname = Swig_name_wrapper(fqname); Delete(fqname); return wname; } From eb7c0f011b173728f928163d5a1f2812aaf7119f Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Mon, 11 Nov 2013 18:19:12 +0400 Subject: [PATCH 0986/1160] Manually beautifying luarun.swg --- Lib/lua/luarun.swg | 106 ++++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index fb8b0c89f..ff807a785 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -254,7 +254,7 @@ it gets the address, casts it, then dereferences it */ /* storing/access of swig_module_info */ SWIGRUNTIME swig_module_info * -SWIG_Lua_GetModule(lua_State* L) { +SWIG_Lua_GetModule(lua_State *L) { swig_module_info *ret = 0; lua_pushstring(L,"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME); lua_rawget(L,LUA_REGISTRYINDEX); @@ -265,7 +265,7 @@ SWIG_Lua_GetModule(lua_State* L) { } SWIGRUNTIME void -SWIG_Lua_SetModule(lua_State* L, swig_module_info *module) { +SWIG_Lua_SetModule(lua_State *L, swig_module_info *module) { /* add this all into the Lua registry: */ lua_pushstring(L,"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME); lua_pushlightuserdata(L,(void*)module); @@ -279,7 +279,7 @@ SWIG_Lua_SetModule(lua_State* L, swig_module_info *module) { /* this function is called when trying to set an immutable. default action is to print an error. This can removed with a compile flag SWIGLUA_IGNORE_SET_IMMUTABLE */ -SWIGINTERN int SWIG_Lua_set_immutable(lua_State* L) +SWIGINTERN int SWIG_Lua_set_immutable(lua_State *L) { /* there should be 1 param passed in: the new value */ #ifndef SWIGLUA_IGNORE_SET_IMMUTABLE @@ -293,7 +293,7 @@ SWIGINTERN int SWIG_Lua_set_immutable(lua_State* L) * global variable support code: namespaces and modules (which are the same thing) * ----------------------------------------------------------------------------- */ -SWIGINTERN int SWIG_Lua_namespace_get(lua_State* L) +SWIGINTERN int SWIG_Lua_namespace_get(lua_State *L) { /* there should be 2 params passed in (1) table (not the meta table) @@ -330,7 +330,7 @@ SWIGINTERN int SWIG_Lua_namespace_get(lua_State* L) return 0; } -SWIGINTERN int SWIG_Lua_namespace_set(lua_State* L) +SWIGINTERN int SWIG_Lua_namespace_set(lua_State *L) { /* there should be 3 params passed in (1) table (not the meta table) @@ -361,12 +361,12 @@ SWIGINTERN int SWIG_Lua_namespace_set(lua_State* L) } #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) // In elua this is useless -SWIGINTERN void SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]); // forward declaration -SWIGINTERN void SWIG_Lua_add_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn); // forward declaration -SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss); +SWIGINTERN void SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]); // forward declaration +SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn); // forward declaration +SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss); /* helper function - register namespace methods and attributes into namespace */ -SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* ns) +SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State *L, swig_lua_namespace *ns) { int i = 0; /* There must be namespace table (not metatable) at the top of the stack */ @@ -391,12 +391,12 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* /* Register all classes in the namespace */ -SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State* L, swig_lua_namespace* ns) +SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace *ns) { // There must be module/namespace table at the top of the stack assert(lua_istable(L,-1)); - swig_lua_class** classes = ns->ns_classes; + swig_lua_class **classes = ns->ns_classes; if( classes != 0 ) { while(*classes != 0) { @@ -411,7 +411,7 @@ SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State* L, swig_lua_namespace* when function is called) Function always returns newly registered table on top of the stack */ -SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns, int reg) +SWIGINTERN int SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, int reg) { int begin = lua_gettop(L); assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table or parent namespace table */ @@ -443,7 +443,7 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns, // Register classes SWIG_Lua_add_namespace_classes(L,ns); - swig_lua_namespace** sub_namespace = ns->ns_namespaces; + swig_lua_namespace **sub_namespace = ns->ns_namespaces; if( sub_namespace != 0) { while(*sub_namespace != 0) { SWIG_Lua_namespace_register(L, *sub_namespace, 1); @@ -464,7 +464,7 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns, * global variable support code: classes * ----------------------------------------------------------------------------- */ -SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State* L,const char* cname); +SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname); /* Macroses for iteration among class bases */ #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) @@ -485,7 +485,7 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State* L,const char* cname); #else // en elua .bases table doesn't exist. Use table from swig_lua_class #define SWIG_LUA_INIT_BASE_SEARCH(bases_count)\ - swig_module_info* module=SWIG_GetModule(L);\ + swig_module_info *module=SWIG_GetModule(L);\ swig_lua_class **bases= ((swig_lua_class*)(swig_type->clientdata))->bases;\ const char **base_names= ((swig_lua_class*)(swig_type->clientdata))->base_names;\ bases_count = 0;\ @@ -505,7 +505,7 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State* L,const char* cname); typedef int (*swig_lua_base_iterator_func)(lua_State*,swig_type_info*, int, int *ret); -int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info* swig_type, int first_arg, swig_lua_base_iterator_func func, int * const ret) +int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, int first_arg, swig_lua_base_iterator_func func, int *const ret) { // first_arg - position of the object in stack. Everything that is above are arguments // and is passed to every evocation of the func @@ -638,7 +638,7 @@ SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int fi /* the class.get method, performs the lookup of class attributes */ -SWIGINTERN int SWIG_Lua_class_get(lua_State* L) +SWIGINTERN int SWIG_Lua_class_get(lua_State *L) { /* there should be 2 params passed in (1) userdata (not the meta table) @@ -658,7 +658,7 @@ SWIGINTERN int SWIG_Lua_class_get(lua_State* L) /* helper for the class.set method, performs the lookup of class attributes * It returns error code. Number of function return values is passed inside 'ret' */ -SWIGINTERN int SWIG_Lua_class_do_set(lua_State* L, swig_type_info *type, int first_arg, int *ret) +SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int first_arg, int *ret) { /* there should be 3 params passed in (1) table (not the meta table) @@ -720,7 +720,7 @@ SWIGINTERN int SWIG_Lua_class_do_set(lua_State* L, swig_type_info *type, int fi /* This is actuall method exported to Lua. It calls SWIG_Lua_class_do_set and correctly * handlers return value */ -SWIGINTERN int SWIG_Lua_class_set(lua_State* L) +SWIGINTERN int SWIG_Lua_class_set(lua_State *L) { /* there should be 3 params passed in (1) table (not the meta table) @@ -742,12 +742,12 @@ SWIGINTERN int SWIG_Lua_class_set(lua_State* L) } /* the class.destruct method called by the interpreter */ -SWIGINTERN int SWIG_Lua_class_destruct(lua_State* L) +SWIGINTERN int SWIG_Lua_class_destruct(lua_State *L) { /* there should be 1 params passed in (1) userdata (not the meta table) */ - swig_lua_userdata* usr; - swig_lua_class* clss; + swig_lua_userdata *usr; + swig_lua_class *clss; assert(lua_isuserdata(L,-1)); /* just in case */ usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */ /* if must be destroyed & has a destructor */ @@ -763,7 +763,7 @@ SWIGINTERN int SWIG_Lua_class_destruct(lua_State* L) } /* the class.__tostring method called by the interpreter and print */ -SWIGINTERN int SWIG_Lua_class_tostring(lua_State* L) +SWIGINTERN int SWIG_Lua_class_tostring(lua_State *L) { /* there should be 1 param passed in (1) userdata (not the metatable) */ @@ -773,7 +773,7 @@ SWIGINTERN int SWIG_Lua_class_tostring(lua_State* L) assert(lua_istable(L,-1)); /* just in case */ lua_getfield(L, -1, ".type"); - const char* className = lua_tostring(L, -1); + const char *className = lua_tostring(L, -1); char output[256]; snprintf(output, 255, "<%s userdata: %lX>", className, userData); @@ -783,11 +783,11 @@ SWIGINTERN int SWIG_Lua_class_tostring(lua_State* L) } /* to manually disown some userdata */ -SWIGINTERN int SWIG_Lua_class_disown(lua_State* L) +SWIGINTERN int SWIG_Lua_class_disown(lua_State *L) { /* there should be 1 params passed in (1) userdata (not the meta table) */ - swig_lua_userdata* usr; + swig_lua_userdata *usr; assert(lua_isuserdata(L,-1)); /* just in case */ usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */ @@ -796,7 +796,7 @@ SWIGINTERN int SWIG_Lua_class_disown(lua_State* L) } /* gets the swig class registry (or creates it) */ -SWIGINTERN void SWIG_Lua_get_class_registry(lua_State* L) +SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L) { /* add this all into the swig registry: */ lua_pushstring(L,"SWIG"); @@ -814,7 +814,7 @@ SWIGINTERN void SWIG_Lua_get_class_registry(lua_State* L) } /* helper fn to get the classes metatable from the register */ -SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State* L,const char* cname) +SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname) { SWIG_Lua_get_class_registry(L); /* get the registry */ lua_pushstring(L,cname); /* get the name */ @@ -829,10 +829,10 @@ It cannot be done at compile time, as this will not work with hireachies spread over more than one swig file. Therefore it must be done at runtime, querying the SWIG type system. */ -SWIGINTERN void SWIG_Lua_init_base_class(lua_State* L,swig_lua_class* clss) +SWIGINTERN void SWIG_Lua_init_base_class(lua_State *L,swig_lua_class *clss) { int i=0; - swig_module_info* module=SWIG_GetModule(L); + swig_module_info *module=SWIG_GetModule(L); for(i=0;clss->base_names[i];i++) { if (clss->bases[i]==0) /* not found yet */ @@ -846,7 +846,7 @@ SWIGINTERN void SWIG_Lua_init_base_class(lua_State* L,swig_lua_class* clss) #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) // In elua this is useless /* helper add a variable to a registered class */ -SWIGINTERN void SWIG_Lua_add_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn) +SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn) { assert(lua_istable(L,-1)); /* just in case */ SWIG_Lua_get_table(L,".get"); /* find the .get table */ @@ -863,7 +863,7 @@ SWIGINTERN void SWIG_Lua_add_variable(lua_State* L,const char* name,lua_CFuncti } /* helper to recursively add class static details (static attributes, operations and constants) */ -SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State* L, swig_lua_class* clss) +SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State *L, swig_lua_class *clss) { int i = 0; /* The class namespace table must be on the top of the stack */ @@ -878,7 +878,7 @@ SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State* L, swig_lua_class* } /* helper to recursively add class details (attributes & operations) */ -SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State* L,swig_lua_class* clss) +SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L,swig_lua_class *clss) { int i; // Add bases to .bases table @@ -918,7 +918,7 @@ SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State* L,swig_lua_class } /* Register class static methods,attributes etc as well as constructor proxy */ -SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* clss) +SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *clss) { int begin = lua_gettop(L); lua_checkstack(L,5); /* just in case */ @@ -952,7 +952,7 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* cls /* performs the instance(non-static) class registration process. Metatable for class is created * and added to the class registry. */ -SWIGINTERN void SWIG_Lua_class_register_instance(lua_State* L,swig_lua_class* clss) +SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *clss) { int begin = lua_gettop(L); // if name already there (class is already registered) then do nothing @@ -1014,7 +1014,7 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State* L,swig_lua_class* c assert( lua_gettop(L) == begin ); } -SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss) +SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss) { assert(lua_istable(L,-1)); /* This is table(module or namespace) where class will be added */ SWIG_Lua_class_register_instance(L,clss); @@ -1054,7 +1054,7 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss) * ----------------------------------------------------------------------------- */ /* helper to add metatable to new lua object */ -SWIGINTERN void _SWIG_Lua_AddMetatable(lua_State* L,swig_type_info *type) +SWIGINTERN void _SWIG_Lua_AddMetatable(lua_State *L,swig_type_info *type) { if (type->clientdata) /* there is clientdata: so add the metatable */ { @@ -1071,9 +1071,9 @@ SWIGINTERN void _SWIG_Lua_AddMetatable(lua_State* L,swig_type_info *type) } /* pushes a new object into the lua stack */ -SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State* L,void* ptr,swig_type_info *type, int own) +SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *type, int own) { - swig_lua_userdata* usr; + swig_lua_userdata *usr; if (!ptr){ lua_pushnil(L); return; @@ -1089,9 +1089,9 @@ SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State* L,void* ptr,swig_type_info *t /* takes a object from the lua stack & converts it into an object of the correct type (if possible) */ -SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State* L,int index,void** ptr,swig_type_info *type,int flags) +SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L,int index,void **ptr,swig_type_info *type,int flags) { - swig_lua_userdata* usr; + swig_lua_userdata *usr; swig_cast_info *cast; if (lua_isnil(L,index)){*ptr=0; return SWIG_OK;} /* special case: lua nil => NULL pointer */ usr=(swig_lua_userdata*)lua_touserdata(L,index); /* get data */ @@ -1118,9 +1118,9 @@ SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State* L,int index,void** ptr,swig_type return SWIG_ERROR; /* error */ } -SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_State* L,int index,swig_type_info *type,int flags, - int argnum,const char* func_name){ - void* result; +SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_State *L,int index,swig_type_info *type,int flags, + int argnum,const char *func_name){ + void *result; if (!SWIG_IsOK(SWIG_ConvertPtr(L,index,&result,type,flags))){ luaL_error (L,"Error in %s, expected a %s at argument number %d\n", func_name,(type && type->str)?type->str:"void*",argnum); @@ -1129,9 +1129,9 @@ SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_State* L,int index,swig_type_info *typ } /* pushes a packed userdata. user for member fn pointers only */ -SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State* L,void* ptr,size_t size,swig_type_info *type) +SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_type_info *type) { - swig_lua_rawdata* raw; + swig_lua_rawdata *raw; assert(ptr); /* not acceptable to pass in a NULL value */ raw=(swig_lua_rawdata*)lua_newuserdata(L,sizeof(swig_lua_rawdata)-1+size); /* alloc data */ raw->type=type; @@ -1141,9 +1141,9 @@ SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State* L,void* ptr,size_t size,swig_t } /* converts a packed userdata. user for member fn pointers only */ -SWIGRUNTIME int SWIG_Lua_ConvertPacked(lua_State* L,int index,void* ptr,size_t size,swig_type_info *type) +SWIGRUNTIME int SWIG_Lua_ConvertPacked(lua_State *L,int index,void *ptr,size_t size,swig_type_info *type) { - swig_lua_rawdata* raw; + swig_lua_rawdata *raw; raw=(swig_lua_rawdata*)lua_touserdata(L,index); /* get data */ if (!raw) return SWIG_ERROR; /* error */ if (type==0 || type==raw->type) /* void* or identical type */ @@ -1157,7 +1157,7 @@ SWIGRUNTIME int SWIG_Lua_ConvertPacked(lua_State* L,int index,void* ptr,size_t /* a function to get the typestring of a piece of data */ SWIGRUNTIME const char *SWIG_Lua_typename(lua_State *L, int tp) { - swig_lua_userdata* usr; + swig_lua_userdata *usr; if (lua_isuserdata(L,tp)) { usr=(swig_lua_userdata*)lua_touserdata(L,tp); /* get data */ @@ -1169,7 +1169,7 @@ SWIGRUNTIME const char *SWIG_Lua_typename(lua_State *L, int tp) } /* lua callable function to get the userdata's type */ -SWIGRUNTIME int SWIG_Lua_type(lua_State* L) +SWIGRUNTIME int SWIG_Lua_type(lua_State *L) { lua_pushstring(L,SWIG_Lua_typename(L,1)); return 1; @@ -1178,7 +1178,7 @@ SWIGRUNTIME int SWIG_Lua_type(lua_State* L) /* lua callable function to compare userdata's value the issue is that two userdata may point to the same thing but to lua, they are different objects */ -SWIGRUNTIME int SWIG_Lua_equal(lua_State* L) +SWIGRUNTIME int SWIG_Lua_equal(lua_State *L) { int result; swig_lua_userdata *usr1,*usr2; @@ -1199,7 +1199,7 @@ SWIGRUNTIME int SWIG_Lua_equal(lua_State* L) #if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)) /* Install Constants */ SWIGINTERN void -SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]) { +SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]) { int i; for (i = 0; constants[i].type; i++) { switch(constants[i].type) { @@ -1253,7 +1253,7 @@ In lua 5.0.X its lua_dostring() In lua 5.1.X its luaL_dostring() */ SWIGINTERN int -SWIG_Lua_dostring(lua_State *L, const char* str) { +SWIG_Lua_dostring(lua_State *L, const char *str) { int ok,top; if (str==0 || str[0]==0) return 0; /* nothing to do */ top=lua_gettop(L); /* save stack */ From 02c4a8e39c30ec972da4d5bf0dc8d34519b24b27 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Mon, 11 Nov 2013 18:29:49 +0400 Subject: [PATCH 0987/1160] Remove some obsolete code --- Lib/lua/lua.swg | 2 -- Lib/lua/luaruntime.swg | 5 ----- 2 files changed, 7 deletions(-) diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg index c470d9298..4ea1ac98a 100644 --- a/Lib/lua/lua.swg +++ b/Lib/lua/lua.swg @@ -42,12 +42,10 @@ %typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE [] { SWIG_LUA_CONSTTAB_POINTER("$symname",$value, $1_descriptor) } - //{ SWIG_LUA_POINTER, (char *)"$symname", 0, 0, (void *)$value, &$1_descriptor}// TODO: REMOVE // member function pointers %typemap(consttab) SWIGTYPE (CLASS::*) { SWIG_LUA_CONSTTAB_BINARY("$symname", sizeof($type),&$value, $1_descriptor) } - //{ SWIG_LUA_BINARY, (char *)"$symname", sizeof($type), 0, (void *)&$value, &$1_descriptor}// TODO:REMOVE /* ----------------------------------------------------------------------------- diff --git a/Lib/lua/luaruntime.swg b/Lib/lua/luaruntime.swg index 758544185..52b698051 100644 --- a/Lib/lua/luaruntime.swg +++ b/Lib/lua/luaruntime.swg @@ -61,11 +61,6 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */ #endif -#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)) - /* constants */ - /* TODO: REMOVE */ -#endif - #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) /* invoke user-specific initialization */ SWIG_init_user(L); From 7e09b6687ed3624094bcf4f24602a25ede4e11e5 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Mon, 11 Nov 2013 19:29:48 +0400 Subject: [PATCH 0988/1160] Remove some typos --- Source/Modules/swigmod.h | 1 - Source/Swig/typesys.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 09fc37c87..2929993b3 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -278,7 +278,6 @@ protected: /* Return the namespace for the class/enum - the nspace feature */ String *getNSpace() const; - void setNSpace(String *nspace); /* Return the real name of the current class */ String *getClassName() const; diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index c5ddb56f6..e11fc781a 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -1594,7 +1594,7 @@ void SwigType_remember_clientdata(const SwigType *t, const_String_or_char_ptr cl Delete(qr); /*Printf(stdout,"t = '%s'\n", t); - Printf(stdout,"fr= '%s'\n\n", fr);*/ + Printf(stdout,"fr= '%s'\n\n", fr); */ if (t) { char *ct = Char(t); From ce2760f77e9ab04ce276244ee4329aeba7ddea54 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Mon, 11 Nov 2013 21:58:07 +0400 Subject: [PATCH 0989/1160] Fixes for examples. Wrapped keywords into guardian in keyword_rename test --- Examples/lua/dual/dual.cpp | 4 ++++ Examples/lua/embed/Makefile | 3 ++- Examples/lua/embed/embed.c | 4 ++++ Examples/lua/embed2/Makefile | 3 ++- Examples/test-suite/keyword_rename.i | 2 ++ Lib/lua/luarun.swg | 5 ++++- 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Examples/lua/dual/dual.cpp b/Examples/lua/dual/dual.cpp index d2a9ecaa9..ad7897953 100644 --- a/Examples/lua/dual/dual.cpp +++ b/Examples/lua/dual/dual.cpp @@ -36,6 +36,10 @@ extern "C" int luaopen_example2(lua_State*L); #define DEBUG2(X,Y) {printf(X,Y);fflush(stdout);} #define DEBUG3(X,Y,Z) {printf(X,Y,Z);fflush(stdout);} +#if LUA_VERSION_NUM > 501 +#define lua_open luaL_newstate +#endif + void testModule(lua_State *L) { swig_type_info *pTypeInfo=0,*pTypeInfo2=0; diff --git a/Examples/lua/embed/Makefile b/Examples/lua/embed/Makefile index df1f8fa04..57979c061 100644 --- a/Examples/lua/embed/Makefile +++ b/Examples/lua/embed/Makefile @@ -4,6 +4,7 @@ TARGET = embed SRCS = example.c INTERFACE = example.i LUA_INTERP = embed.c +LIBS = -lm # this is a little different to normal as we have our own special interpreter # which we want to static link @@ -12,7 +13,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' LIBS='$(LIBS)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static clean: $(MAKE) -f $(TOP)/Makefile lua_clean diff --git a/Examples/lua/embed/embed.c b/Examples/lua/embed/embed.c index 9df168f94..f21c933a5 100644 --- a/Examples/lua/embed/embed.c +++ b/Examples/lua/embed/embed.c @@ -18,6 +18,10 @@ We will be using the luaL_dostring()/lua_dostring() function to call into lua #include #include +#if LUA_VERSION_NUM > 501 +#define lua_open luaL_newstate +#endif + /* the SWIG wrappered library */ extern int luaopen_example(lua_State*L); diff --git a/Examples/lua/embed2/Makefile b/Examples/lua/embed2/Makefile index fc309ac7e..ec22bdcae 100644 --- a/Examples/lua/embed2/Makefile +++ b/Examples/lua/embed2/Makefile @@ -4,6 +4,7 @@ TARGET = embed2 SRCS = example.c INTERFACE = example.i LUA_INTERP = embed2.c +LIBS = -lm # this is a little different to normal as we have our own special interpreter # which we want to static link @@ -12,7 +13,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' LIBS='$(LIBS)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static clean: $(MAKE) -f $(TOP)/Makefile lua_clean diff --git a/Examples/test-suite/keyword_rename.i b/Examples/test-suite/keyword_rename.i index 46c3338b3..a9f58ebef 100644 --- a/Examples/test-suite/keyword_rename.i +++ b/Examples/test-suite/keyword_rename.i @@ -32,8 +32,10 @@ KW(go, defer) KW(chan, fallthrough) /* Lua keywords */ +#ifdef SWIGLUA KW(end, function) KW(nil,local) +#endif %} diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index ff807a785..5ae08f5d0 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -357,6 +357,9 @@ SWIGINTERN int SWIG_Lua_namespace_set(lua_State *L) lua_pop(L,1); /* remove the value */ } lua_pop(L,1); /* remove the value .set table */ + lua_pop(L,1); /* remote metatable */ + assert(lua_gettop(L) == 3); // TODO: REMOVE + lua_rawset(L,-3); return 0; } @@ -505,7 +508,7 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname); typedef int (*swig_lua_base_iterator_func)(lua_State*,swig_type_info*, int, int *ret); -int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, int first_arg, swig_lua_base_iterator_func func, int *const ret) +SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, int first_arg, swig_lua_base_iterator_func func, int *const ret) { // first_arg - position of the object in stack. Everything that is above are arguments // and is passed to every evocation of the func From 89c6fbb780dfaacc840a84bcb64a9d684e6dd72c Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Mon, 11 Nov 2013 22:30:29 +0400 Subject: [PATCH 0990/1160] Attempt to fix unreproducable bug (from Travis CI build) --- Source/Modules/lua.cxx | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index f1803e068..e5e6e7ab0 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -170,7 +170,13 @@ public: f_initbeforefunc(0), s_luacode(0), module(0), - have_constructor(0), have_destructor(0), destructor_action(0), class_symname(0), class_fq_symname(0), class_static_nspace(0), constructor_name(0) { + have_constructor(0), + have_destructor(0), + destructor_action(0), + class_symname(0), + class_fq_symname(0), + class_static_nspace(0), + constructor_name(0) { namespaces_hash = NewHash(); for (int i = 0; i < STATES_COUNT; i++) current[i] = false; @@ -415,7 +421,9 @@ public: // But we need to know what was the name of function/variable // etc that user desired, that's why we store correct symname // as lua:name - Setattr(n, "lua:name", Getattr(n, "sym:name")); + String *symname = Getattr(n, "sym:name"); + if (symname) + Setattr(n, "lua:name", symname); return Language::cDeclaration(n); } virtual int constructorDeclaration(Node *n) { @@ -1004,6 +1012,7 @@ public: Printf(f_init, "%s\n", tm); } else { Delete(nsname); + nsname = 0; Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); Swig_restore(n); return SWIG_NOWRAP; @@ -1017,6 +1026,7 @@ public: n_v2 = Copy(n); //Printf( stdout, "target name v2: %s, symname v2 %s\n", target_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE if (!luaAddSymbol(iname_v2, n, class_parent_nspace)) { + Swig_restore(n); return SWIG_ERROR; } @@ -1122,8 +1132,8 @@ public: virtual int classHandler(Node *n) { //REPORT("classHandler", n); - String *mangled_class_fq_symname; - String *destructor_name; + String *mangled_class_fq_symname = 0; + String *destructor_name = 0; String *nspace = getNSpace(); constructor_name = 0; @@ -1151,8 +1161,8 @@ public: assert(class_fq_symname != 0); mangled_class_fq_symname = Swig_name_mangle(class_fq_symname); - SwigType *t(Copy(Getattr(n, "name"))); - SwigType *fr_t(SwigType_typedef_resolve_all(t)); /* Create fully resolved type */ + SwigType *t = Copy(Getattr(n, "name")); + SwigType *fr_t = SwigType_typedef_resolve_all(t); /* Create fully resolved type */ SwigType *t_tmp = 0; t_tmp = SwigType_typedef_qualified(fr_t); // Temporal variable Delete(fr_t); @@ -1350,9 +1360,11 @@ public: current[NO_CPP] = true; Delete(class_static_nspace); - Delete(mangled_class_fq_symname); - Delete(destructor_name); class_static_nspace = 0; + Delete(mangled_class_fq_symname); + mangled_class_fq_symname = 0; + Delete(destructor_name); + destructor_name = 0; Delete(class_fq_symname); class_fq_symname = 0; class_symname = 0; @@ -1538,7 +1550,7 @@ public: emitLuaFlavor(s); - String *sfile; + String *sfile = 0; for (int i = 0; filenames[i] != 0; i++) { sfile = Swig_include_sys(filenames[i]); if (!sfile) { @@ -1733,6 +1745,7 @@ public: Setattr(namespaces_hash, key ? key : "", nspace_hash); Delete(mangled_name); + mangled_name = 0; return nspace_hash; } @@ -1878,8 +1891,7 @@ public: assert(cname != 0); Printv(output, "static swig_lua_namespace ", cname, " = ", NIL); - String *null_string; - null_string = NewString("0"); + String *null_string = NewString("0"); String *attr_tab_name = Getattr(nspace_hash, "attributes:name"); String *methods_tab_name = Getattr(nspace_hash, "methods:name"); String *const_tab_name = Getattr(nspace_hash, "constants:name"); From a87710275df70e6a1c6690713b851f0050e1a698 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Tue, 12 Nov 2013 16:41:20 +0400 Subject: [PATCH 0991/1160] Some fixes for elua --- Source/Modules/lua.cxx | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index e5e6e7ab0..eda5589fc 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -370,12 +370,10 @@ public: Printf(f_init, "/* exec Lua code if applicable */\nSWIG_Lua_dostring(L,SWIG_LUACODE);\n"); Printf(f_init, "}\n"); + // Done. Close up the module & write to the wrappers + closeNamespaces(f_wrappers); Printf(f_wrappers, "#ifdef __cplusplus\n}\n#endif\n"); - // Done. Close up the module & write to the wrappers - - //Printv(f_wrappers, s_cmd_tab, s_var_tab, s_const_tab, NIL); - closeNamespaces(f_wrappers); SwigType_emit_type_table(f_runtime, f_wrappers); /* NEW LANGUAGE NOTE:*********************************************** @@ -1129,6 +1127,24 @@ public: * classHandler() * ------------------------------------------------------------ */ + /* Helper function that adds record to appropriate + * C arrays + */ + void registerClass(String *scope, Node *n) { + String *wrap_class = Getattr(n,"wrap:class_name"); + assert(wrap_class != 0); + Hash *nspaceHash = getNamespaceHash(scope); + String *ns_classes = Getattr(nspaceHash, "classes"); + Printv(ns_classes, "&", wrap_class, ",\n", NIL); + if (elua_ltr || eluac_ltr) { + String *ns_methods = Getattr(nspaceHash, "methods"); + Hash *class_hash = getNamespaceHash(class_fq_symname); + assert(class_hash != 0); + String *cls_methods = Getattr(class_hash, "methods:name"); + assert(cls_methods != 0); + Printv(ns_methods, tab4, "{LSTRKEY(\"", class_symname, "\")", ", LROVAL(", cls_methods, ")", "},\n", NIL); + } + } virtual int classHandler(Node *n) { //REPORT("classHandler", n); @@ -1231,16 +1247,17 @@ public: SwigType_add_pointer(t); // Catch all: eg. a class with only static functions and/or variables will not have 'remembered' - String *wrap_class = NewStringf("&_wrap_class_%s", mangled_class_fq_symname); + String *wrap_class_name = NewStringf("_wrap_class_%s", mangled_class_fq_symname); + String *wrap_class = NewStringf("&%s", wrap_class_name); + Setattr(n, "wrap:class_name", wrap_class_name); SwigType_remember_clientdata(t, wrap_class); String *rt = Copy(getClassType()); SwigType_add_pointer(rt); // Adding class to apropriate namespace + registerClass(nspace, n); Hash *nspaceHash = getNamespaceHash(nspace); - String *ns_classes = Getattr(nspaceHash, "classes"); - Printv(ns_classes, wrap_class, ",\n", NIL); // Register the class structure with the type checker // Printf(f_init,"SWIG_TypeClientData(SWIGTYPE%s, (void *) &_wrap_class_%s);\n", SwigType_manglestr(t), mangled_class_fq_symname); @@ -1635,6 +1652,10 @@ public: Hash *parent = getNamespaceHash(parent_path, true); String *namespaces_tab = Getattr(parent, "namespaces"); Printv(namespaces_tab, "&", cname, ",\n", NIL); + if (elua_ltr || eluac_ltr) { + String *methods_tab = Getattr(parent, "methods"); + Printv(methods_tab, tab4, "{LSTRKEY(\"", name, "\")", ", LROVAL(", cname, ")", "},\n", NIL); + } Setattr(nspace_hash, "name", name); Delete(components); From 4b0ed733172c410103cb7bcc74b13243e10b06aa Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Wed, 13 Nov 2013 14:52:04 +0400 Subject: [PATCH 0992/1160] Style fixes. Comments fixes. Fixing cmd options. etc --- Lib/lua/luarun.swg | 99 +++++++++-------- Source/Modules/lua.cxx | 241 ++++++++++++++++++++++------------------- 2 files changed, 179 insertions(+), 161 deletions(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 5ae08f5d0..bb1cbb444 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -32,7 +32,7 @@ extern "C" { # define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C) # define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C) # define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C) - // Those two types of constants are not supported in elua + /* Those two types of constants are not supported in elua */ # define SWIG_LUA_CONSTTAB_POINTER(B,C,D) LSTRKEY(B), LNILVAL # define SWIG_LUA_CONSTTAB_BINARY(B, S, C, D) LSTRKEY(B), LNILVAL #else /* SWIG_LUA_FLAVOR_LUA */ @@ -137,7 +137,7 @@ typedef struct { #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC) typedef const LUA_REG_TYPE swig_lua_method; typedef const LUA_REG_TYPE swig_lua_const_info; -#else // Normal lua +#else /* Normal lua */ typedef luaL_Reg swig_lua_method; /* Constant information structure */ @@ -159,28 +159,27 @@ typedef struct { } swig_lua_attribute; -struct _swig_lua_class; -// Can be used to create namespaces. Currently used to -// wrap class static methods/variables/constants -typedef struct _swig_lua_namespace { +struct swig_lua_class; +/* Can be used to create namespaces. Currently used to wrap class static methods/variables/constants */ +typedef struct swig_lua_namespace { const char *name; swig_lua_method *ns_methods; swig_lua_attribute *ns_attributes; swig_lua_const_info *ns_constants; - struct _swig_lua_class **ns_classes; - struct _swig_lua_namespace **ns_namespaces; + struct swig_lua_class **ns_classes; + struct swig_lua_namespace **ns_namespaces; } swig_lua_namespace; -typedef struct _swig_lua_class { - const char *name; // Name that this class has in Lua - const char *fqname; // Fully qualified name - Scope + class name +typedef struct swig_lua_class { + const char *name; /* Name that this class has in Lua */ + const char *fqname; /* Fully qualified name - Scope + class name */ swig_type_info **type; lua_CFunction constructor; void (*destructor)(void *); swig_lua_method *methods; swig_lua_attribute *attributes; swig_lua_namespace *cls_static; - struct _swig_lua_class **bases; + struct swig_lua_class **bases; const char **base_names; } swig_lua_class; @@ -249,7 +248,7 @@ typedef struct { #ifdef __cplusplus /* Special helper for member function pointers it gets the address, casts it, then dereferences it */ -//#define SWIG_mem_fn_as_voidptr(a) (*((char**)&(a))) +/*#define SWIG_mem_fn_as_voidptr(a) (*((char**)&(a))) */ #endif /* storing/access of swig_module_info */ @@ -363,9 +362,9 @@ SWIGINTERN int SWIG_Lua_namespace_set(lua_State *L) return 0; } -#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) // In elua this is useless -SWIGINTERN void SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]); // forward declaration -SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn); // forward declaration +#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) /* In elua this is useless */ +SWIGINTERN void SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]); /* forward declaration */ +SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn); /* forward declaration */ SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss); /* helper function - register namespace methods and attributes into namespace */ @@ -396,7 +395,7 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State *L, swig_lua_namespace * */ SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace *ns) { - // There must be module/namespace table at the top of the stack + /* There must be module/namespace table at the top of the stack */ assert(lua_istable(L,-1)); swig_lua_class **classes = ns->ns_classes; @@ -441,16 +440,16 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, lua_setmetatable(L,-2); /* set metatable */ - // Register all functions, variables etc + /* Register all functions, variables etc */ SWIG_Lua_add_namespace_details(L,ns); - // Register classes + /* Register classes */ SWIG_Lua_add_namespace_classes(L,ns); swig_lua_namespace **sub_namespace = ns->ns_namespaces; if( sub_namespace != 0) { while(*sub_namespace != 0) { SWIG_Lua_namespace_register(L, *sub_namespace, 1); - lua_pop(L,1); // removing sub-namespace table + lua_pop(L,1); /* removing sub-namespace table */ sub_namespace++; } } @@ -462,7 +461,7 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, } assert(lua_gettop(L) == begin+1); } -#endif // SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA +#endif /* SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA */ /* ----------------------------------------------------------------------------- * global variable support code: classes * ----------------------------------------------------------------------------- */ @@ -485,14 +484,14 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname); } else\ valid = 1; -#else // en elua .bases table doesn't exist. Use table from swig_lua_class +#else /* en elua .bases table doesn't exist. Use table from swig_lua_class */ #define SWIG_LUA_INIT_BASE_SEARCH(bases_count)\ swig_module_info *module=SWIG_GetModule(L);\ swig_lua_class **bases= ((swig_lua_class*)(swig_type->clientdata))->bases;\ const char **base_names= ((swig_lua_class*)(swig_type->clientdata))->base_names;\ bases_count = 0;\ - for(;base_names[bases_count];bases_count++);// get length of bases + for(;base_names[bases_count];bases_count++);/* get length of bases */ #define SWIG_LUA_GET_BASE_METATABLE(i,base_swig_type, valid)\ swig_lua_class *base_class = bases[i];\ @@ -510,9 +509,9 @@ typedef int (*swig_lua_base_iterator_func)(lua_State*,swig_type_info*, int, int SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, int first_arg, swig_lua_base_iterator_func func, int *const ret) { - // first_arg - position of the object in stack. Everything that is above are arguments - // and is passed to every evocation of the func - int last_arg = lua_gettop(L);// position of last argument + /* first_arg - position of the object in stack. Everything that is above are arguments + * and is passed to every evocation of the func */ + int last_arg = lua_gettop(L);/* position of last argument */ lua_getmetatable(L,first_arg); int original_metatable = last_arg + 1; int bases_count; @@ -523,39 +522,39 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, i { int i; int j; - int subcall_first_arg = lua_gettop(L) + 1;// Here a copy of first_arg and arguments begin + int subcall_first_arg = lua_gettop(L) + 1;/* Here a copy of first_arg and arguments begin */ int valid = 1; for(j=first_arg;j<=last_arg;j++) lua_pushvalue(L,j); int subcall_last_arg = lua_gettop(L); swig_type_info *base_swig_type = 0; - // Trick: temporaly replacing original metatable - // with metatable for base class and call getter + /* Trick: temporaly replacing original metatable + * with metatable for base class and call getter */ for(i=0;ibases[i];i++) { SWIG_Lua_get_class_metatable(L,clss->bases[i]->fqname); - // Base class must be already registered + /* Base class must be already registered */ assert(lua_istable(L,-1)); - lua_rawseti(L,-2,i+1); // In lua indexing starts from 1 + lua_rawseti(L,-2,i+1); /* In lua indexing starts from 1 */ bases_count++; } assert(lua_rawlen(L,-1) == bases_count); - lua_pop(L,1); // remove .bases table + lua_pop(L,1); /* remove .bases table */ /* add attributes */ for(i=0;clss->attributes[i].name;i++){ SWIG_Lua_add_variable(L,clss->attributes[i].name,clss->attributes[i].getmethod,clss->attributes[i].setmethod); @@ -958,7 +957,7 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *cls SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *clss) { int begin = lua_gettop(L); - // if name already there (class is already registered) then do nothing + /* if name already there (class is already registered) then do nothing */ SWIG_Lua_get_class_registry(L); /* get the registry */ lua_pushstring(L,clss->fqname); /* get the name */ lua_rawget(L,-2); @@ -967,14 +966,14 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c assert(lua_gettop(L)==begin); return; } - lua_pop(L,2); // tidy stack - // Recursively initialize all bases + lua_pop(L,2); /* tidy stack */ + /* Recursively initialize all bases */ int i = 0; for(i=0;clss->bases[i];i++) { SWIG_Lua_class_register_instance(L,clss->bases[i]); } - // Again, get registry and push name + /* Again, get registry and push name */ SWIG_Lua_get_class_registry(L); /* get the registry */ lua_pushstring(L,clss->fqname); /* get the name */ lua_newtable(L); /* create the metatable */ @@ -1051,7 +1050,7 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss) lua_pop(L,2); assert(lua_gettop(L) == begin); } -#endif // SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA +#endif /* SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA */ /* ----------------------------------------------------------------------------- * Class/structure conversion fns * ----------------------------------------------------------------------------- */ diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index eda5589fc..75c94cc6b 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -86,16 +86,7 @@ Lua Options (available with -lua)\n\ Optional NUM is default value for MIN_OPT_LEVEL\n\ -nomoduleglobal - Do not register the module name as a global variable \n\ but return the module table from calls to require.\n\ - -api-lvl-from NUM\n\ - - Force support for old-style bindings. All old-style bindings\n\ - from NUM to current new-style bindings will be supported. For example,\n\ - if current lua bindings API version is 10 and NUM==7 then SWIG will\n\ - generate bindings compatible with lua bindings versions 7,8,9 and,\n\ - of course current version of bindings, 10.\n\ - API levels:\n\ - 2 - SWIG 2.*\n\ - 3 - SWIG 3.*\n\ - Default NUM is 2.\n\ + -swig3 - Disable support for old-style bindings name generation.\n\ \n"; static int nomoduleglobal = 0; @@ -186,12 +177,6 @@ public: Delete(namespaces_hash); } - /* NEW LANGUAGE NOTE:*********************************************** - This is called to initalise the system & read any command line args - most of this is boilerplate code, except the command line args - which depends upon what args your code supports - NEW LANGUAGE NOTE:END *********************************************** */ - bool strToInt(const char *string, int &value) { long int tmp; char *p_end = 0; @@ -203,6 +188,12 @@ public: value = tmp; return true; } + /* NEW LANGUAGE NOTE:*********************************************** + This is called to initalise the system & read any command line args + most of this is boilerplate code, except the command line args + which depends upon what args your code supports + NEW LANGUAGE NOTE:END *********************************************** */ + /* --------------------------------------------------------------------- * main() * @@ -237,15 +228,9 @@ public: Swig_mark_arg(i + 1); i++; } - } else if (strcmp(argv[i], "-api-lvl-from") == 0) { - if (argv[i + 1]) { - if (!strToInt(argv[i + 1], api_level)) - Swig_arg_error(); - Swig_mark_arg(i + 1); - i++; - } else { - Swig_arg_error(); - } + } else if (strcmp(argv[i], "-swig3") == 0) { + Swig_mark_arg(i); + api_level = 3; } } } @@ -409,6 +394,10 @@ public: return Language::importDirective(n); } + /* ------------------------------------------------------------ + * cDeclaration() + * It copies sym:name to lua:name to preserve it's original value + * ------------------------------------------------------------ */ virtual int cDeclaration(Node *n) { // class 'Language' is messing with symname in a really heavy way. // Although documentation states that sym:name is a name in @@ -463,7 +452,7 @@ public: // Add method to the "methods" C array of given namespace/class void registerMethod(String *nspace_or_class_name, Node *n) { - assert(n != 0); + assert(n); Hash *nspaceHash = getNamespaceHash(nspace_or_class_name); String *s_ns_methods_tab = Getattr(nspaceHash, "methods"); String *wname = Getattr(n, "wrap:name"); @@ -491,7 +480,7 @@ public: String *name = Getattr(n, "name"); String *iname = Getattr(n, "sym:name"); String *target_name = Getattr(n, "lua:name"); - assert(target_name != 0); + assert(target_name); SwigType *d = Getattr(n, "type"); ParmList *l = Getattr(n, "parms"); Parm *p; @@ -516,7 +505,7 @@ public: Wrapper_add_local(f, "SWIG_arg", "int SWIG_arg = 0"); - String *wname = symname_wrapper(iname); + String *wname = symnameWrapper(iname); if (overname) { Append(wname, overname); } @@ -830,8 +819,8 @@ public: Wrapper *f = NewWrapper(); String *symname = Getattr(n, "sym:name"); String *target_name = Getattr(n, "lua:name"); - assert(target_name != 0); - String *wname = symname_wrapper(symname); + assert(target_name); + String *wname = symnameWrapper(symname); //Printf(stdout,"Swig_overload_dispatch %s %s '%s' %d\n",symname,wname,dispatch,maxargs); @@ -890,11 +879,9 @@ public: /* ------------------------------------------------------------ - * variableWrapper() + * Add variable to the "attributes" (or "get"/"set" in + * case of elua_ltr) C arrays of given namespace or class * ------------------------------------------------------------ */ - - // Add variable to the "attributes" (or "get"/"set" in - // case of elua_ltr) C arrays of given namespace or class void registerVariable(String *nspace_or_class_name, Node *n, const char *getAttrName, const char *setAttrName) { String *unassignable = NewString("SWIG_Lua_set_immutable"); String *getName = Getattr(n, getAttrName); @@ -919,6 +906,10 @@ public: } } + /* ------------------------------------------------------------ + * variableWrapper() + * ------------------------------------------------------------ */ + virtual int variableWrapper(Node *n) { /* NEW LANGUAGE NOTE:*********************************************** Language::variableWrapper(n) will generate two wrapper fns @@ -929,7 +920,7 @@ public: NEW LANGUAGE NOTE:END *********************************************** */ // REPORT("variableWrapper", n); String *target_name = Getattr(n, "lua:name"); - assert(target_name != 0); + assert(target_name); current[VARIABLE] = true; // let SWIG generate the wrappers int result = Language::variableWrapper(n); @@ -940,12 +931,9 @@ public: /* ------------------------------------------------------------ - * constantWrapper() - * ------------------------------------------------------------ */ - - /* Add constant to appropriate C array. constantRecord is an array record. + * Add constant to appropriate C array. constantRecord is an array record. * Actually, in current implementation it is resolved consttab typemap - */ + * ------------------------------------------------------------ */ void registerConstant(String *nspace, String *constantRecord) { Hash *nspaceHash = getNamespaceHash(nspace); String *s_const_tab = 0; @@ -955,17 +943,20 @@ public: else s_const_tab = Getattr(nspaceHash, "constants"); - assert(s_const_tab != 0); + assert(s_const_tab); Printf(s_const_tab, " %s,\n", constantRecord); if ((eluac_ltr || elua_ltr) && v2_compatibility) { s_const_tab = Getattr(nspaceHash, "constants"); - assert(s_const_tab != 0); + assert(s_const_tab); Printf(s_const_tab, " %s,\n", constantRecord); } } + /* ------------------------------------------------------------ + * constantWrapper() + * ------------------------------------------------------------ */ virtual int constantWrapper(Node *n) { REPORT("constantWrapper", n); String *name = Getattr(n, "name"); @@ -990,7 +981,7 @@ public: Setattr(n, "sym:name", target_name); /* Special hook for member pointer */ if (SwigType_type(type) == T_MPOINTER) { - String *wname = symname_wrapper(iname); + String *wname = symnameWrapper(iname); Printf(f_wrappers, "static %s = %s;\n", SwigType_str(type, wname), value); value = Char(wname); } @@ -1123,28 +1114,29 @@ public: return Language::classDeclaration(n); } - /* ------------------------------------------------------------ - * classHandler() - * ------------------------------------------------------------ */ - /* Helper function that adds record to appropriate + /* ------------------------------------------------------------ + * Helper function that adds record to appropriate * C arrays - */ + * ------------------------------------------------------------ */ void registerClass(String *scope, Node *n) { String *wrap_class = Getattr(n,"wrap:class_name"); - assert(wrap_class != 0); + assert(wrap_class); Hash *nspaceHash = getNamespaceHash(scope); String *ns_classes = Getattr(nspaceHash, "classes"); Printv(ns_classes, "&", wrap_class, ",\n", NIL); if (elua_ltr || eluac_ltr) { String *ns_methods = Getattr(nspaceHash, "methods"); Hash *class_hash = getNamespaceHash(class_fq_symname); - assert(class_hash != 0); + assert(class_hash); String *cls_methods = Getattr(class_hash, "methods:name"); - assert(cls_methods != 0); + assert(cls_methods); Printv(ns_methods, tab4, "{LSTRKEY(\"", class_symname, "\")", ", LROVAL(", cls_methods, ")", "},\n", NIL); } } + /* ------------------------------------------------------------ + * classHandler() + * ------------------------------------------------------------ */ virtual int classHandler(Node *n) { //REPORT("classHandler", n); @@ -1174,7 +1166,7 @@ public: else class_fq_symname = NewStringf("%s.%s", nspace, class_symname); - assert(class_fq_symname != 0); + assert(class_fq_symname); mangled_class_fq_symname = Swig_name_mangle(class_fq_symname); SwigType *t = Copy(Getattr(n, "name")); @@ -1212,7 +1204,7 @@ public: // and capital letter are forbiden to use in C++. So, under know circumstances could our class contain // any member or subclass with name "__Static". Thus, never any name clash. Hash *instance_cls = getNamespaceHash(class_fq_symname, false); - assert(instance_cls != 0); + assert(instance_cls); String *s_attr_tab_name = Getattr(instance_cls, "attributes:name"); String *s_methods_tab_name = Getattr(instance_cls, "methods:name"); Setattr(instance_cls, "lua:no_namespaces", "1"); @@ -1225,7 +1217,7 @@ public: class_static_nspace = NewStringf("%s%s__Static", class_fq_symname, NSPACE_SEPARATOR); Hash *static_cls = getNamespaceHash(class_static_nspace, false); - assert(static_cls != 0); + assert(static_cls); Setattr(static_cls, "lua:no_namespaces", "1"); Setattr(static_cls, "lua:class_static", "1"); @@ -1296,18 +1288,18 @@ public: constructor_name = constructor_proxy_name; if (elua_ltr) { String *static_cls_metatable_tab = Getattr(static_cls, "metatable"); - assert(static_cls_metatable_tab != 0); + assert(static_cls_metatable_tab); Printf(static_cls_metatable_tab, " {LSTRKEY(\"__call\"), LFUNCVAL(%s)},\n", constructor_name); } else if (eluac_ltr) { String *ns_methods_tab = Getattr(nspaceHash, "methods"); - assert(ns_methods_tab != 0); + assert(ns_methods_tab); Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "new_", class_symname, "\")", ", LFUNCVAL(", constructor_name, ")", "},\n", NIL); } } if (have_destructor) { if (eluac_ltr) { String *ns_methods_tab = Getattr(nspaceHash, "methods"); - assert(ns_methods_tab != 0); + assert(ns_methods_tab); Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_class_fq_symname, "\")", ", LFUNCVAL(", destructor_name, ")", "},\n", NIL); } } @@ -1599,10 +1591,12 @@ public: } - /* This is to convert the string of Lua code into a proper string, which can then be - emitted into the C/C++ code. - Basically is is a lot of search & replacing of odd sequences - */ + /* ----------------------------------------------------------------------------- + * EscapeCode() + * This is to convert the string of Lua code into a proper string, which can then be + * emitted into the C/C++ code. + * Basically is is a lot of search & replacing of odd sequences + * ---------------------------------------------------------------------------- */ void EscapeCode(String *str) { //Printf(f_runtime,"/* original luacode:[[[\n%s\n]]]\n*/\n",str); Chop(str); // trim @@ -1612,18 +1606,22 @@ public: //Printf(f_runtime,"/* hacked luacode:[[[\n%s\n]]]\n*/\n",str); } - /* Each namespace can be described with hash that stores C arrays - where members of the namespace should be added. All these hashes are stored - inside namespaces_hash. - nspace could be NULL (NSPACE_TODO), that means functions and variables and classes - that are not in any namespace (this is default for SWIG unless %nspace feature is used) - You can later set some attributes that will affect behaviour of functions that use this hash: - "lua:no_namespaces" will disable "namespaces" array. - "lua:no_classes" will disable "classes" array. - For every component ("attributes", "methods", etc) there are subcomponents: - * XXX:name - name of the C array that stores data for component - * XXX:decl - statement with forward declaration of this array; - */ + /* ----------------------------------------------------------------------------- + * getNamespaceHash() + * Each namespace can be described with hash that stores C arrays + * where members of the namespace should be added. All these hashes are stored + * inside namespaces_hash. + * nspace could be NULL (NSPACE_TODO), that means functions and variables and classes + * that are not in any namespace (this is default for SWIG unless %nspace feature is used) + * You can later set some attributes that will affect behaviour of functions that use this hash: + * "lua:no_namespaces" will disable "namespaces" array. + * "lua:no_classes" will disable "classes" array. + * For every component ("attributes", "methods", etc) there are subcomponents: + * XXX:name - name of the C array that stores data for component + * XXX:decl - statement with forward declaration of this array; + * Namespace could be automatically registered to it's parent if 'reg' == true. It can be done + * only at first call (a.k.a when nspace is created). + * ---------------------------------------------------------------------------- */ Hash *getNamespaceHash(String *nspace, bool reg = true) { Hash *nspace_hash = Getattr(namespaces_hash, nspace ? nspace : ""); if (nspace_hash != 0) @@ -1770,17 +1768,19 @@ public: return nspace_hash; } - /* Functions add end markers {0,0,...,0} to all arrays, prints them to + /* ----------------------------------------------------------------------------- + * closeNamespaceHash() + * Functions add end markers {0,0,...,0} to all arrays, prints them to * output and marks hash as closed (lua:closed). Consequent attempts to * close same hash will result in error * closeNamespaceHash DOES NOT print structure that describes namespace, it only * prints array. You can use printNamespaceDefinition to print structure. * if "lua:no_namespaces" is set, then array for "namespaces" won't be printed * if "lua:no_classes" is set, then array for "classes" won't be printed - * */ + * ----------------------------------------------------------------------------- */ void closeNamespaceHash(String *nspace, File *output) { Hash *nspace_hash = Getattr(namespaces_hash, nspace); - assert(nspace_hash != 0); + assert(nspace_hash); assert(Getattr(nspace_hash, "lua:closed") == 0); Setattr(nspace_hash, "lua:closed", "1"); @@ -1836,26 +1836,26 @@ public: Printv(output, set_tab, NIL); String *metatable_tab = Getattr(nspace_hash, "metatable"); - assert(metatable_tab != 0); + assert(metatable_tab); Printv(metatable_tab, tab4, "{LSTRKEY(\"__index\"), LFUNCVAL(SWIG_Lua_namespace_get)},\n", NIL); Printv(metatable_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_namespace_set)},\n", NIL); Printv(metatable_tab, tab4, "{LSTRKEY(\".get\"), LROVAL(", get_tab_name, ")},\n", NIL); Printv(metatable_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(", set_tab_name, ")},\n", NIL); if (Getattr(nspace_hash, "lua:class_instance")) { String *static_cls = Getattr(nspace_hash, "lua:class_instance:static_hash"); - assert(static_cls != 0); + assert(static_cls); // static_cls is swig_lua_namespace. This structure can't be use with eLua(LTR) // Instead structure describing its methods isused String *static_cls_cname = Getattr(static_cls, "methods:name"); - assert(static_cls_cname != 0); + assert(static_cls_cname); Printv(metatable_tab, tab4, "{LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL); // Put forward declaration of this array Printv(output, "extern ", Getattr(static_cls, "methods:decl"), "\n", NIL); } else if (Getattr(nspace_hash, "lua:class_static")) { Hash *instance_cls = Getattr(nspace_hash, "lua:class_static:instance_hash"); - assert(instance_cls != 0); + assert(instance_cls); String *instance_cls_metatable_name = Getattr(instance_cls, "metatable:name"); - assert(instance_cls_metatable_name != 0); + assert(instance_cls_metatable_name); Printv(metatable_tab, tab4, "{LSTRKEY(\".instance\"), LROVAL(", instance_cls_metatable_name, ")},\n", NIL); } @@ -1868,7 +1868,11 @@ public: static int compareByLen(const DOH *f, const DOH *s) { return Len(s) - Len(f); } - // Recursively close all non-closed namespaces. Prints data to dataOutput, + + /* ----------------------------------------------------------------------------- + * closeNamespaceHash() + * Recursively close all non-closed namespaces. Prints data to dataOutput. + * ----------------------------------------------------------------------------- */ void closeNamespaces(File *dataOutput) { // Special handling for empty module. if (Getattr(namespaces_hash, "") == 0) { @@ -1894,22 +1898,26 @@ public: name = module; else name = Getattr(nspace, "name"); - assert(name != 0); + assert(name); printNamespaceDefinition(key, name, dataOutput); } Delete(to_close); } - // This function prints to output a definition of namespace in - // form of swig_lua_namespace: { attr_array, methods_array, ... , namespaces_array }. - // You can call this function as many times as necessary. - // 'name' is a user-visible name that this namespace will have in Lua. It shouldn't - // be fully qualified name, just it's own name. + /* ----------------------------------------------------------------------------- + * printNamespaceDefinition() + * This function prints to output a definition of namespace in + * form + * swig_lua_namespace $cname = { attr_array, methods_array, ... , namespaces_array }; + * You can call this function as many times as necessary. + * 'name' is a user-visible name that this namespace will have in Lua. It shouldn't + * be fully qualified name, just it's own name. + * ----------------------------------------------------------------------------- */ void printNamespaceDefinition(String *nspace, String *name, File *output) { Hash *nspace_hash = getNamespaceHash(nspace, false); String *cname = Getattr(nspace_hash, "cname"); // cname - name of the C structure that describes namespace - assert(cname != 0); + assert(cname); Printv(output, "static swig_lua_namespace ", cname, " = ", NIL); String *null_string = NewString("0"); @@ -1931,12 +1939,15 @@ public: Delete(null_string); } - // This function determines actual namespace/scope where any symbol at the - // current moment should be placed. It looks at the 'current' array - // and depending on where are we - static class member/function, - // instance class member/function or just global functions decides - // where symbol should be put. - // The namespace/scope doesn't depend from symbol, only from 'current' + /* ----------------------------------------------------------------------------- + * luaCurrentSymbolNSpace() + * This function determines actual namespace/scope where any symbol at the + * current moment should be placed. It looks at the 'current' array + * and depending on where are we - static class member/function, + * instance class member/function or just global functions decides + * where symbol should be put. + * The namespace/scope doesn't depend from symbol, only from 'current' + * ----------------------------------------------------------------------------- */ String *luaCurrentSymbolNSpace() { String *scope = 0; // If ouside class, than NSpace is used. @@ -1954,12 +1965,15 @@ public: } else { // Friend functions are handled this way scope = class_static_nspace; } - assert(scope != 0); + assert(scope); } return scope; } - // Our implementation of addSymbol. Determines scope correctly, then calls Language::addSymbol + /* ----------------------------------------------------------------------------- + * luaAddSymbol() + * Our implementation of addSymbol. Determines scope correctly, then calls Language::addSymbol + * ----------------------------------------------------------------------------- */ int luaAddSymbol(const String *s, const Node *n) { String *scope = luaCurrentSymbolNSpace(); //Printf(stdout, "luaAddSymbol: %s scope: %s\n", s, scope); @@ -1969,7 +1983,10 @@ public: return result; } - // Overload. Enforces given scope. Actually, it simply forwards call to Language::addSymbol + /* ----------------------------------------------------------------------------- + * luaAddSymbol() + * Overload. Enforces given scope. Actually, it simply forwards call to Language::addSymbol + * ----------------------------------------------------------------------------- */ int luaAddSymbol(const String *s, const Node *n, const_String_or_char_ptr scope) { //Printf(stdout, "luaAddSymbol: %s scope: %s\n", s, scope); int result = Language::addSymbol(s, n, scope); @@ -1978,15 +1995,14 @@ public: return result; } - // Function creates fully qualified name of given symbol. Current NSpace and current class - // are used - String *fully_qualified_name(const_String_or_char_ptr name) { - assert(name != 0); - String *scope = 0; - if (getCurrentClass()) - scope = class_fq_symname; - else - scope = getNSpace(); + /* ----------------------------------------------------------------------------- + * fullyQualifiedName() + * Function creates fully qualified name of given symbol. The scope is deremined + * automatically based on luaCurrentSymbolNSpace() + * ----------------------------------------------------------------------------- */ + String *fullyQualifiedName(const_String_or_char_ptr name) { + assert(name); + String *scope = luaCurrentSymbolNSpace(); String *fqname = 0; if (scope) @@ -1997,10 +2013,13 @@ public: return fqname; } - // Input: symname - // Output - wrapper around fully qualified form of symname - String *symname_wrapper(String *symname) { - String *fqname = fully_qualified_name(symname); + /* ----------------------------------------------------------------------------- + * symnameWrapper() + * Input: symname + * Output - Swig_name_wrapper around fully qualified form of symname + * ----------------------------------------------------------------------------- */ + String *symnameWrapper(String *symname) { + String *fqname = fullyQualifiedName(symname); String *wname = Swig_name_wrapper(fqname); Delete(fqname); return wname; From 6d49a57b535a0a9cc479b2cd8367371c64808d39 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Wed, 13 Nov 2013 15:16:09 +0400 Subject: [PATCH 0993/1160] Add support for C-style enums in C mode. And tests. In backward compatible mode C style enums binding are correctly generated --- Examples/test-suite/lua/enums_runme.lua | 8 ++++++++ Source/Modules/lua.cxx | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/lua/enums_runme.lua b/Examples/test-suite/lua/enums_runme.lua index 6211581fe..998f01cfc 100644 --- a/Examples/test-suite/lua/enums_runme.lua +++ b/Examples/test-suite/lua/enums_runme.lua @@ -19,4 +19,12 @@ assert(enums.globalinstance3==30) assert(enums.AnonEnum1==0) assert(enums.AnonEnum2==100) +-- In C enums from struct are exported without prefixing with struct name +-- In C++ they are prefixed. +-- We are emulating xor :) +assert(enums.BAR1 ~= enums.Foo_BAR1) -- It is either C style, or C++ style, but not both +assert((enums.BAR1 ~= nil ) or (enums.Foo_BAR1 ~= nil)) + +assert(enums.Phoo ~= enums.iFoo_Phoo) +assert((enums.Phoo == 50) or (enums.iFoo_Phoo == 50)) -- no point in checking fns, C will allow any value diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 75c94cc6b..116e6a26a 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -139,6 +139,7 @@ private: STATIC_FUNC, STATIC_VAR, STATIC_CONST, // enums and things like static const int x = 5; + ENUM_CONST, // This is only needed for backward compatibility in C mode STATES_COUNT }; @@ -1010,8 +1011,16 @@ public: bool make_v2_compatible = v2_compatibility && getCurrentClass() != 0; if (make_v2_compatible) { - target_name_v2 = Swig_name_member(0, class_symname, target_name); - iname_v2 = Swig_name_member(0, class_symname, iname); + // Special handling for enums in C mode - they are not prefixed with structure name + if(!CPlusPlus && current[ENUM_CONST]) { + target_name_v2 = target_name; + DohIncref(target_name_v2); + iname_v2 = iname; + DohIncref(iname_v2); + } else { + target_name_v2 = Swig_name_member(0, class_symname, target_name); + iname_v2 = Swig_name_member(0, class_symname, iname); + } n_v2 = Copy(n); //Printf( stdout, "target name v2: %s, symname v2 %s\n", target_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE if (!luaAddSymbol(iname_v2, n, class_parent_nspace)) { @@ -1074,8 +1083,10 @@ public: virtual int enumDeclaration(Node *n) { current[STATIC_CONST] = true; + current[ENUM_CONST] = true; int result = Language::enumDeclaration(n); current[STATIC_CONST] = false; + current[ENUM_CONST] = false; return result; } From 0ee724ca80ac8f47c9365fbb729c52b03959ad06 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Wed, 13 Nov 2013 19:51:20 +0400 Subject: [PATCH 0994/1160] Add compatibility option for old-style inheritance --- Lib/lua/luarun.swg | 101 +++++++++++++++++++++++++++++++++++++++++ Source/Modules/lua.cxx | 11 ++++- 2 files changed, 111 insertions(+), 1 deletion(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index bb1cbb444..9f5bf5869 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -627,6 +627,15 @@ SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int fi lua_pop(L,1); /* Search in base classes */ assert(lua_gettop(L) == substack_start + 2); // TODO: REMOVE + + /* TODO: REMOVE +#ifdef SWIG_LUA_SQUASH_BASES + if(ret) *ret = 0; + return SWIG_ERROR; // TODO:ERROR:FIX:REMOVE!!!! +//#warning REMOVE REMOVE REMOVE +#endif + END OF REMOVE */ + //printf("failed, searching bases\n"); // TODO: REMOVE int bases_search_result = SWIG_Lua_iterate_bases(L,type,substack_start+1,SWIG_Lua_class_do_get,ret); if(ret) assert(lua_gettop(L) == substack_start + 2 + *ret); // TODO: REMOVE @@ -846,6 +855,77 @@ SWIGINTERN void SWIG_Lua_init_base_class(lua_State *L,swig_lua_class *clss) } } +#if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) +/* Merges two tables */ +SWIGINTERN int SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int source) +{ + /* iterating */ + lua_pushnil(L); + while (lua_next(L,source) != 0) { + /* -1 - value, -2 - index */ + /* have to copy to assign */ + lua_pushvalue(L,-2); /* copy of index */ + lua_pushvalue(L,-2); /* copy of value */ + lua_rawset(L, target); + lua_pop(L,1); + /* only key is left */ + } +} + +/* Merges two tables with given name. original - index of target metatable, base - index of source metatable */ +SWIGINTERN int SWIG_Lua_merge_tables(lua_State *L, const char* name, int original, int base) +{ + int begin = lua_gettop(L); // TODO:REMOVE + /* push original[name], then base[name] */ + lua_pushstring(L,name); + lua_rawget(L,original); + int original_table = lua_gettop(L); + lua_pushstring(L,name); + lua_rawget(L,base); + int base_table = lua_gettop(L); + SWIG_Lua_merge_tables_by_index(L, original_table, base_table); + /* clearing stack */ + lua_pop(L,2); + assert(lua_gettop(L) == begin); // TODO: REMOVE +} + +/* Function takes all symbols from base and adds it to derived class. It's just a helper*/ +SWIGINTERN int SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls) +{ + int begin = lua_gettop(L); // TODO:REMOVE + /* There is one parameter - original, i.e. 'derived' class metatable */ + assert(lua_istable(L,-1)); + int original = lua_gettop(L); + SWIG_Lua_get_class_metatable(L,base_cls->fqname); + int base = lua_gettop(L); + SWIG_Lua_merge_tables(L, ".fn", original, base ); + SWIG_Lua_merge_tables(L, ".set", original, base ); + SWIG_Lua_merge_tables(L, ".get", original, base ); + lua_pop(L,1); + assert(lua_gettop(L) == begin); // TODO: REMOVE +} + +/* Function squashes all symbols from 'clss' bases into itself */ +SWIGINTERN int SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss) +{ + int begin = lua_gettop(L); // TODO: REMOVE + int i; + SWIG_Lua_get_class_metatable(L,clss->fqname); + for(i=0;clss->base_names[i];i++) + { + if (clss->bases[i]==0) /* Somehow it's not found. Skip it */ + continue; + /* Thing is: all bases are already registered. Thus they have already executed + * this function. So we just need to squash them into us, because their bases + * are already squashed into them. No need for recursion here! + */ + SWIG_Lua_class_squash_base(L, clss->bases[i]); + } + lua_pop(L,1); /*tidy stack*/ + assert(lua_gettop(L) == begin); // TODO: REMOVE +} +#endif + #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) /* In elua this is useless */ /* helper add a variable to a registered class */ SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn) @@ -977,6 +1057,23 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c SWIG_Lua_get_class_registry(L); /* get the registry */ lua_pushstring(L,clss->fqname); /* get the name */ lua_newtable(L); /* create the metatable */ +#if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) + /* If squashing is requested, then merges all bases metatable into this one. + * It would get us all special methods: __getitem, __add etc. + * This would set .fn, .type, and other .xxx incorrectly, but we will overwrite it right away + */ + int squash_begin = lua_gettop(L); // TODO:REMOVE + int new_metatable_index = lua_absindex(L,-1); + for(i=0;clss->bases[i];i++) + { + SWIG_Lua_get_class_metatable(L,clss->bases[i]->fqname); + int base_metatable = lua_absindex(L,-1); + SWIG_Lua_merge_tables_by_index(L,new_metatable_index, base_metatable); + lua_pop(L,1); + } + assert(lua_gettop(L) == squash_begin); // TODO: REMOVE + /* And now we will overwrite all incorrectly set data */ +#endif /* add string of class name called ".type" */ lua_pushstring(L,".type"); lua_pushstring(L,clss->fqname); @@ -1010,6 +1107,10 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c lua_pop(L,1); /* tidy stack (remove registry) */ assert(lua_gettop(L)==begin); +#if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) + /* Now merge all symbols from .fn, .set, .get etc from bases to our tables */ + SWIG_Lua_class_squash_bases(L,clss); +#endif SWIG_Lua_get_class_metatable(L,clss->fqname); SWIG_Lua_add_class_instance_details(L,clss); /* recursive adding of details (atts & ops) */ lua_pop(L,1); /* tidy stack (remove class metatable) */ diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 116e6a26a..1d7b831b1 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -86,13 +86,17 @@ Lua Options (available with -lua)\n\ Optional NUM is default value for MIN_OPT_LEVEL\n\ -nomoduleglobal - Do not register the module name as a global variable \n\ but return the module table from calls to require.\n\ - -swig3 - Disable support for old-style bindings name generation.\n\ + -swig3 - Disable support for old-style bindings name generation.\n\ + -squash-bases - Squashes symbols from all inheritance tree of a given class\n\ + into itself. Emulates pre-SWIG3.0 inheritance. Insignificantly\n\ + speeds things up, but increases memory consumption.\n\ \n"; static int nomoduleglobal = 0; static int elua_ltr = 0; static int elua_opt_lvl = 2; static int eluac_ltr = 0; +static int squash_bases = 0; static int v2_compatibility = 0; static const int default_api_level = 2; @@ -232,6 +236,9 @@ public: } else if (strcmp(argv[i], "-swig3") == 0) { Swig_mark_arg(i); api_level = 3; + } else if (strcmp(argv[i], "-squash-bases") == 0) { + Swig_mark_arg(i); + squash_bases = 1; } } } @@ -331,6 +338,8 @@ public: } else { Printf(f_runtime, "#define SWIG_LUA_MODULE_GLOBAL\n"); } + if (squash_bases) + Printf(f_runtime, "#define SWIG_LUA_SQUASH_BASES\n"); // if (NoInclude) { // Printf(f_runtime, "#define SWIG_NOINCLUDE\n"); From 705beb67530f6bbbdd85a776831dbd48be675262 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sun, 17 Nov 2013 01:11:50 +0400 Subject: [PATCH 0995/1160] Bugfixes for eLua. eLua emulation mode --- Examples/test-suite/lua/grouping_runme.lua | 1 + Examples/test-suite/lua/newobject1_runme.lua | 4 +- Lib/lua/luarun.swg | 311 ++++++++++++++++++- Lib/lua/luaruntime.swg | 23 +- Source/Modules/lua.cxx | 189 +++++++---- 5 files changed, 445 insertions(+), 83 deletions(-) diff --git a/Examples/test-suite/lua/grouping_runme.lua b/Examples/test-suite/lua/grouping_runme.lua index 7ab08499f..b13409514 100644 --- a/Examples/test-suite/lua/grouping_runme.lua +++ b/Examples/test-suite/lua/grouping_runme.lua @@ -14,4 +14,5 @@ assert(g.test3 == 37) g.test3 = 42 assert(g.test3 == 42) +assert(g.NEGATE ~= nil) assert(g.do_unary(5, g.NEGATE) == -5) diff --git a/Examples/test-suite/lua/newobject1_runme.lua b/Examples/test-suite/lua/newobject1_runme.lua index 5de8276db..55d04eeb7 100644 --- a/Examples/test-suite/lua/newobject1_runme.lua +++ b/Examples/test-suite/lua/newobject1_runme.lua @@ -1,8 +1,8 @@ require("import") -- the import fn import("newobject1") -- import code -foo1 = newobject1.Foo_makeFoo() -- lua doesnt yet support static fns properly -assert(newobject1.Foo_fooCount() == 1) -- lua doesnt yet support static fns properly +foo1 = newobject1.Foo_makeFoo() +assert(newobject1.Foo_fooCount() == 1) foo2 = foo1:makeMore() assert(newobject1.Foo_fooCount() == 2) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 9f5bf5869..9f8f69476 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -27,14 +27,80 @@ extern "C" { # error SWIG_LUA_TARGET not defined #endif +#if defined(SWIG_LUA_ELUA_EMULATE) + +struct swig_elua_entry; + +typedef struct swig_elua_key { + int type; + union { + const char* strkey; + lua_Number numkey; + } key; +} swig_elua_key; + +typedef struct swig_elua_val { + int type; + union { + lua_Number number; + const struct swig_elua_entry *table; + const char *string; + lua_CFunction function; + struct { + char member; + long lvalue; + void *pvalue; + swig_type_info **ptype; + } userdata; + } value; +} swig_elua_val; + +typedef struct swig_elua_entry { + swig_elua_key key; + swig_elua_val value; +} swig_elua_entry; + +#define LSTRKEY(x) {LUA_TSTRING, {.strkey = x} } +#define LNUMKEY(x) {LUA_TNUMBER, {.numkey = x} } +#define LNILKEY {LUA_TNIL, {.strkey = 0} } + +#define LNUMVAL(x) {LUA_TNUMBER, {.number = x} } +#define LFUNCVAL(x) {LUA_TFUNCTION, {.function = x} } +#define LROVAL(x) {LUA_TTABLE, {.table = x} } +#define LNILVAL {LUA_TNIL, {.string = 0} } +#define LSTRVAL(x) {LUA_TSTRING, {.string = x} } + +#define LUA_REG_TYPE swig_elua_entry + +#define SWIG_LUA_ELUA_EMUL_METATABLE_KEY "__metatable" + +#define lua_pushrotable(L,p)\ + lua_newtable(L);\ + SWIG_Lua_elua_emulate_register(L,p); + +#define SWIG_LUA_CONSTTAB_POINTER(B,C,D)\ + LSTRKEY(B), {LUA_TUSERDATA, { .userdata={0,0,(void*)(C),&D} } } + +#define SWIG_LUA_CONSTTAB_BINARY(B,S,C,D)\ + LSTRKEY(B), {LUA_TUSERDATA, { .userdata={1,S,(void*)(C),&D} } } +#endif + #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC) # define SWIG_LUA_CONSTTAB_INT(B, C) LSTRKEY(B), LNUMVAL(C) # define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C) # define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C) # define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C) /* Those two types of constants are not supported in elua */ -# define SWIG_LUA_CONSTTAB_POINTER(B,C,D) LSTRKEY(B), LNILVAL -# define SWIG_LUA_CONSTTAB_BINARY(B, S, C, D) LSTRKEY(B), LNILVAL + +#ifndef SWIG_LUA_CONSTTAB_POINTER +#warning eLua does not support pointers as constants. By default, nil will be used as value +#define SWIG_LUA_CONSTTAB_POINTER(B,C,D) LSTRKEY(B), LNILVAL +#endif + +#ifndef SWIG_LUA_CONSTTAB_BINARY +#warning eLua does not support pointers to member as constants. By default, nil will be used as value +#define SWIG_LUA_CONSTTAB_BINARY(B, S, C, D) LSTRKEY(B), LNILVAL +#endif #else /* SWIG_LUA_FLAVOR_LUA */ # define SWIG_LUA_CONSTTAB_INT(B, C) SWIG_LUA_INT, (char *)B, (long)C, 0, 0, 0 # define SWIG_LUA_CONSTTAB_FLOAT(B, C) SWIG_LUA_FLOAT, (char *)B, 0, (double)C, 0, 0 @@ -46,15 +112,19 @@ extern "C" { SWIG_LUA_BINARY, (char *)B, S, 0, (void *)C, &D #endif +#ifndef SWIG_LUA_ELUA_EMULATE #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC) # define LRO_STRVAL(v) {{.p = (char *) v}, LUA_TSTRING} # define LSTRVAL LRO_STRVAL #endif +#endif /* SWIG_LUA_ELUA_EMULATE*/ +#ifndef SWIG_LUA_ELUA_EMULATE #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC) #include "lrodefs.h" #include "lrotable.h" #endif +#endif /* SWIG_LUA_ELUA_EMULATE*/ /* ----------------------------------------------------------------------------- * compatibility defines * ----------------------------------------------------------------------------- */ @@ -86,6 +156,19 @@ extern "C" { # define lua_absindex(L,i) ((i)>0 || (i) <= LUA_REGISTRYINDEX ? (i) : lua_gettop(L) + (i) + 1) #endif +/* lua_rawsetp was introduced in Lua 5.2 */ +#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502 +#define lua_rawsetp(L,index,ptr)\ + lua_pushlightuserdata(L,(void*)(ptr));\ + lua_insert(L,-2);\ + lua_rawset(L,index); + +#define lua_rawgetp(L,index,ptr)\ + lua_pushlightuserdata(L,(void*)(ptr));\ + lua_rawget(L,index); + +#endif + /* -------------------------------------------------------------------------- * Helper functions for error handling * -------------------------------------------------------------------------- */ @@ -179,6 +262,7 @@ typedef struct swig_lua_class { swig_lua_method *methods; swig_lua_attribute *attributes; swig_lua_namespace *cls_static; + swig_lua_method *metatable; // only for eLua struct swig_lua_class **bases; const char **base_names; } swig_lua_class; @@ -288,6 +372,179 @@ SWIGINTERN int SWIG_Lua_set_immutable(lua_State *L) return 0; /* should not return anything */ } +#ifdef SWIG_LUA_ELUA_EMULATE +//#define report(...) printf(__VA_ARGS__) // TODO: REMOVE +#define report(...) // TODO : REMOVE + +SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *type, int own); +SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_type_info *type); +static int swig_lua_elua_emulate_unique_key; +/* This is function that emulates eLua rotables behaviour. It loads rotable definition + * into the usual lua table. + */ +SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_entry *table) +{ + assert(lua_istable(L,-1)); + int target_table = lua_gettop(L); + /* Get the registry where we put all parsed tables to avoid loops */ + lua_rawgetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key); + if(lua_isnil(L,-1)) { + lua_pop(L,1); + lua_newtable(L); + lua_pushvalue(L,-1); + lua_rawsetp(L,LUA_REGISTRYINDEX,(void*)(&swig_lua_elua_emulate_unique_key)); + } + int parsed_tables_array = lua_gettop(L); + lua_pushvalue(L,target_table); + lua_rawsetp(L, parsed_tables_array, table); + int i; + int table_parsed = 0; + int pairs_start = lua_gettop(L); + static int tabs_count = 0; // TODO: REMOVE + for(i = 0;table[i].key.type != LUA_TNIL || table[i].value.type != LUA_TNIL;i++) + { + /* TODO: REMOVE */ + int j = 0; + for(j=0;jkey.type) { + case LUA_TSTRING: + lua_pushstring(L,entry->key.key.strkey); + report(" %s :", entry->key.key.strkey); // TODO: REMOVE + if(strcmp(entry->key.key.strkey, SWIG_LUA_ELUA_EMUL_METATABLE_KEY) == 0) + is_metatable = 1; + break; + case LUA_TNUMBER: + lua_pushnumber(L,entry->key.key.numkey); + report(" %f :", (double)(entry->key.key.numkey)); // TODO: REMOVE + break; + case LUA_TNIL: + report(" nil :"); // TODO: REMOVE + lua_pushnil(L); + break; + default: + assert(0); + } + switch(entry->value.type) { + case LUA_TSTRING: + lua_pushstring(L,entry->value.value.string); + report(" %s", entry->value.value.string); // TODO: REMOVE + break; + case LUA_TNUMBER: + lua_pushnumber(L,entry->value.value.number); + report(" %f", (double)(entry->value.value.number)); // TODO: REMOVE + break; + case LUA_TFUNCTION: + report(" %p", (void*)(entry->value.value.function)); // TODO: REMOVE + lua_pushcfunction(L,entry->value.value.function); + break; + case LUA_TTABLE: + /* TODO: REMOVE */ + report(" table"); + tabs_count++; + /* END OF REMOVE */ + lua_rawgetp(L,parsed_tables_array, entry->value.value.table); + table_parsed = !lua_isnil(L,-1); + if(!table_parsed) { + lua_pop(L,1); /*remove nil */ + report("\n"); // TODO: REMOVE + lua_newtable(L); + SWIG_Lua_elua_emulate_register(L,entry->value.value.table); + } else { + report(" already parsed"); // TODO: REMOVE + } + if(is_metatable) { + report(" (registering metatable)"); // TODO: REMOVE + assert(lua_istable(L,-1)); + lua_pushvalue(L,-1); + lua_setmetatable(L,target_table); + } + + tabs_count--; /*TODO: REMOVE*/ + break; + case LUA_TUSERDATA: + if(entry->value.value.userdata.member) + SWIG_NewMemberObj(L,entry->value.value.userdata.pvalue, + entry->value.value.userdata.lvalue, + *(entry->value.value.userdata.ptype)); + else + SWIG_NewPointerObj(L,entry->value.value.userdata.pvalue, + *(entry->value.value.userdata.ptype),0); + break; + case LUA_TNIL: + report(" nil"); // TODO: REMOVE + lua_pushnil(L); + break; + default: + assert(0); + } + assert(lua_gettop(L) == pairs_start + 2); + lua_rawset(L,target_table); + report("\n"); // TODO: REMOVE + } + lua_pop(L,1); /* Removing parsed tables storage */ + assert(lua_gettop(L) == target_table); +} + +SWIGINTERN void SWIG_Lua_elua_emulate_register_clear(lua_State *L) +{ + lua_pushnil(L); + lua_rawsetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key); +} + +/* TODO: REMOVE */ +SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L); + +SWIGINTERN int SWIG_Lua_emulate_elua_getmetatable(lua_State *L) +{ + SWIG_check_num_args("getmetatable(SWIG eLua emulation)", 1, 1); + SWIG_Lua_get_class_registry(L); + lua_getfield(L,-1,"lua_getmetatable"); + lua_remove(L,-2); /* remove the registry*/ + assert(!lua_isnil(L,-1)); + lua_pushvalue(L,1); + assert(lua_gettop(L) == 3); /* object | function | object again */ + lua_call(L,1,1); + if(!lua_isnil(L,-1)) /*There is an ordinary metatable */ + return 1; + /*if it is a table, then emulate elua behaviour - check for __metatable attribute of a table*/ + assert(lua_gettop(L) == 2); + if(lua_istable(L,-2)) { + printf("getmetatable: elua emulation part\n"); // TODO: REMOVE + lua_pop(L,1); /*remove the nil*/ + lua_getfield(L,-1, SWIG_LUA_ELUA_EMUL_METATABLE_KEY); + } + assert(lua_gettop(L) == 2); + return 1; + +fail: + lua_error(L); + return 0; +} + +SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L) +{ + int begin = lua_gettop(L); // TODO: REMOVE + SWIG_Lua_get_class_registry(L); + lua_pushglobaltable(L); + lua_pushstring(L,"lua_getmetatable"); + lua_getfield(L,-2,"getmetatable"); + assert(!lua_isnil(L,-1)); + lua_rawset(L,-4); + lua_pushstring(L, "getmetatable"); + lua_pushcfunction(L, SWIG_Lua_emulate_elua_getmetatable); + lua_rawset(L,-3); + lua_pop(L,2); + assert(lua_gettop(L) == begin); // TODO: REMOVE + +} +/* END OF REMOVE */ + +#endif /* ----------------------------------------------------------------------------- * global variable support code: namespaces and modules (which are the same thing) * ----------------------------------------------------------------------------- */ @@ -415,6 +672,7 @@ SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace */ SWIGINTERN int SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, int reg) { + /* 1 argument - table on the top of the stack */ int begin = lua_gettop(L); assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table or parent namespace table */ lua_checkstack(L,5); @@ -487,6 +745,7 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname); #else /* en elua .bases table doesn't exist. Use table from swig_lua_class */ #define SWIG_LUA_INIT_BASE_SEARCH(bases_count)\ + assert(swig_type!=0);\ swig_module_info *module=SWIG_GetModule(L);\ swig_lua_class **bases= ((swig_lua_class*)(swig_type->clientdata))->bases;\ const char **base_names= ((swig_lua_class*)(swig_type->clientdata))->base_names;\ @@ -500,7 +759,8 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname); else {\ valid = 1;\ SWIG_Lua_get_class_metatable(L,base_class->fqname);\ - base_swig_type = SWIG_TypeQueryModule(module,module,base_class->fqname);\ + base_swig_type = SWIG_TypeQueryModule(module,module,base_names[i]);\ + assert(base_swig_type != 0);\ } #endif @@ -989,14 +1249,11 @@ SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L,swig_lua_class } lua_pop(L,1); /* tidy stack (remove table) */ /* add operator overloads - these look ANY method which start with "__" and assume they - are operator overloads & add them to the metatable - (this might mess up if someone defines a method __gc (the destructor)*/ - for(i=0;clss->methods[i].name;i++){ - if (clss->methods[i].name[0]=='_' && clss->methods[i].name[1]=='_'){ - SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].func); - } - } + This adds methods from metatable array to metatable. Can mess up garbage + collectind if someone defines __gc method + */ + for(i=0;clss->metatable[i].name;i++) + SWIG_Lua_add_function(L,clss->metatable[i].name,clss->metatable[i].func); } /* Register class static methods,attributes etc as well as constructor proxy */ @@ -1152,6 +1409,38 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss) assert(lua_gettop(L) == begin); } #endif /* SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA */ + +#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC) +SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_class *clss) +{ + int begin = lua_gettop(L); + /* if name already there (class is already registered) then do nothing */ + SWIG_Lua_get_class_registry(L); /* get the registry */ + lua_pushstring(L,clss->fqname); /* get the name */ + lua_rawget(L,-2); + if(!lua_isnil(L,-1)) { + lua_pop(L,2); + assert(lua_gettop(L)==begin); + return; + } + lua_pop(L,2); /* tidy stack */ + /* Recursively initialize all bases */ + int i = 0; + for(i=0;clss->bases[i];i++) + { + SWIG_Lua_elua_class_register_instance(L,clss->bases[i]); + } + /* Again, get registry and push name */ + SWIG_Lua_get_class_registry(L); /* get the registry */ + lua_pushstring(L,clss->fqname); /* get the name */ + assert(clss->metatable); + lua_pushrotable(L, (void*)(clss->metatable)); /* create the metatable */ + lua_rawset(L,-3); + lua_pop(L,1); + assert(lua_gettop(L) == begin); +} +#endif // elua && eluac + /* ----------------------------------------------------------------------------- * Class/structure conversion fns * ----------------------------------------------------------------------------- */ diff --git a/Lib/lua/luaruntime.swg b/Lib/lua/luaruntime.swg index 52b698051..0f0cd5501 100644 --- a/Lib/lua/luaruntime.swg +++ b/Lib/lua/luaruntime.swg @@ -36,7 +36,7 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */ SWIG_PropagateClientData(); #endif -#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)) +#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)) || defined(SWIG_LUA_ELUA_EMULATE) /* add a global fn */ SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type); SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_equal); @@ -56,7 +56,26 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */ #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) - SWIG_Lua_namespace_register(L,&swig___Global, globalRegister); + SWIG_Lua_namespace_register(L,&swig___Module, globalRegister); +#endif + +#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC) + for (i = 0; swig_types[i]; i++){ + if (swig_types[i]->clientdata){ + SWIG_Lua_elua_class_register_instance(L,(swig_lua_class*)(swig_types[i]->clientdata)); + } + } +#endif + +#if defined(SWIG_LUA_ELUA_EMULATE) + lua_newtable(L); + SWIG_Lua_elua_emulate_register(L,swig___Module.ns_methods); + SWIG_Lua_elua_emulate_register_clear(L); + if(globalRegister) { + lua_pushstring(L,swig___Module.name); + lua_pushvalue(L,-2); + lua_rawset(L,-4); + } #endif #endif diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 1d7b831b1..c68782e75 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -90,12 +90,15 @@ Lua Options (available with -lua)\n\ -squash-bases - Squashes symbols from all inheritance tree of a given class\n\ into itself. Emulates pre-SWIG3.0 inheritance. Insignificantly\n\ speeds things up, but increases memory consumption.\n\ + -elua-emulate - Emulates behaviour of eLua. Usefull only for testing.\n\ + Incompatible with -elua/-eluac options.\n\ \n"; static int nomoduleglobal = 0; static int elua_ltr = 0; static int elua_opt_lvl = 2; static int eluac_ltr = 0; +static int elua_emulate = 0; static int squash_bases = 0; static int v2_compatibility = 0; static const int default_api_level = 2; @@ -239,10 +242,18 @@ public: } else if (strcmp(argv[i], "-squash-bases") == 0) { Swig_mark_arg(i); squash_bases = 1; + } else if (strcmp(argv[i], "-elua-emulate") == 0) { + Swig_mark_arg(i); + elua_emulate = 1; } } } + if (elua_emulate && (eluac_ltr || elua_ltr )) { + Printf(stderr, "Can't have -elua-emulate and -eluac/-elua at the same time\n"); + Swig_arg_error(); + } + // Set API-compatibility options if (api_level <= 2) // Must be compatible with SWIG 2.* v2_compatibility = 1; @@ -252,6 +263,9 @@ public: //if(api_level <= 4) // v4_compatibility = 1; + // Set elua_ltr if elua_emulate is requested + if(elua_emulate) + elua_ltr = 1; /* NEW LANGUAGE NOTE:*********************************************** This is the boilerplate code, setting a few #defines @@ -466,12 +480,21 @@ public: Hash *nspaceHash = getNamespaceHash(nspace_or_class_name); String *s_ns_methods_tab = Getattr(nspaceHash, "methods"); String *wname = Getattr(n, "wrap:name"); - String *iname = Getattr(n, "sym:name"); String *target_name = Getattr(n, "lua:name"); if (elua_ltr || eluac_ltr) - Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", iname, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", target_name, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); else Printv(s_ns_methods_tab, tab4, "{ \"", target_name, "\", ", wname, "},\n", NIL); + // Add to the metatable if method starts with '__' + const char * tn = Char(target_name); + if (tn[0]=='_' && tn[1] == '_' && !eluac_ltr) { + String *metatable_tab = Getattr(nspaceHash, "metatable"); + assert(metatable_tab); + if (elua_ltr) + Printv(metatable_tab, tab4, "{LSTRKEY(\"", target_name, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); + else + Printv(metatable_tab, tab4, "{ \"", target_name, "\", ", wname, "},\n", NIL); + } } // Helper for functionWrapper - determines whether we should @@ -1147,7 +1170,7 @@ public: Printv(ns_classes, "&", wrap_class, ",\n", NIL); if (elua_ltr || eluac_ltr) { String *ns_methods = Getattr(nspaceHash, "methods"); - Hash *class_hash = getNamespaceHash(class_fq_symname); + Hash *class_hash = getNamespaceHash(class_static_nspace); assert(class_hash); String *cls_methods = Getattr(class_hash, "methods:name"); assert(cls_methods); @@ -1385,6 +1408,12 @@ public: Printf(f_wrappers, ",0"); } Printf(f_wrappers, ", %s, %s, &%s", s_methods_tab_name, s_attr_tab_name, Getattr(static_cls, "cname")); + + if (!eluac_ltr) + Printf(f_wrappers, ", %s", Getattr(instance_cls,"metatable:name")); + else + Printf(f_wrappers, ", 0"); + Printf(f_wrappers, ", swig_%s_bases, swig_%s_base_names };\n\n", mangled_class_fq_symname, mangled_class_fq_symname); current[NO_CPP] = true; @@ -1602,7 +1631,11 @@ public: * --------------------------------------------------------------------- */ void emitLuaFlavor(String *s) { - if (elua_ltr) + if (elua_emulate) { + Printf(s, "/*This is only emulation!*/\n"); + Printf(s, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_ELUA\n"); + Printf(s, "#define SWIG_LUA_ELUA_EMULATE\n"); + } else if (elua_ltr) Printf(s, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_ELUA\n"); else if (eluac_ltr) Printf(s, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_ELUAC\n"); @@ -1649,39 +1682,11 @@ public: nspace_hash = NewHash(); String *mangled_name = 0; if (nspace == 0 || Len(nspace) == 0) - mangled_name = NewString("__Global"); // C++ names can't start with "__ + capital letter" + mangled_name = NewString("__Module"); // C++ names can't start with "__ + capital letter" else mangled_name = Swig_name_mangle(nspace); String *cname = NewStringf("swig_%s", mangled_name); - if (reg && nspace != 0 && Len(nspace) != 0 && Getattr(nspace_hash, "lua:no_reg") == 0) { - // Split names into components - List *components = Split(nspace, '.', -1); - String *parent_path = NewString(""); - int len = Len(components); - String *name = Copy(Getitem(components, len - 1)); - for (int i = 0; i < len - 1; i++) { - if (i > 0) - Printv(parent_path, NSPACE_SEPARATOR, NIL); - String *item = Getitem(components, i); - Printv(parent_path, item, NIL); - } - //Printf(stdout, "Registering %s. User name %s. C-name %s, Parent is %s\n", mangled_name, name, cname, parent_path); // TODO: REMOVE - Hash *parent = getNamespaceHash(parent_path, true); - String *namespaces_tab = Getattr(parent, "namespaces"); - Printv(namespaces_tab, "&", cname, ",\n", NIL); - if (elua_ltr || eluac_ltr) { - String *methods_tab = Getattr(parent, "methods"); - Printv(methods_tab, tab4, "{LSTRKEY(\"", name, "\")", ", LROVAL(", cname, ")", "},\n", NIL); - } - Setattr(nspace_hash, "name", name); - - Delete(components); - Delete(parent_path); - } else if (!reg) // This namespace shouldn't be registered. Lets remember it - Setattr(nspace_hash, "lua:no_reg", "1"); - - Setattr(nspace_hash, "cname", cname); String *attr_tab = NewString(""); @@ -1766,23 +1771,52 @@ public: Setattr(nspace_hash, "set:name", set_tab_name); Setattr(nspace_hash, "set:decl", set_tab_decl); - if (!eluac_ltr) { - String *metatable_tab = NewString(""); - String *metatable_tab_name = NewStringf("swig_%s_meta", mangled_name); - String *metatable_tab_decl = NewString(""); - Printv(metatable_tab, "const LUA_REG_TYPE ", metatable_tab_name, "[]", NIL); - Printv(metatable_tab_decl, metatable_tab, ";", NIL); - Printv(metatable_tab, " = {\n", NIL); - Setattr(nspace_hash, "metatable", metatable_tab); - Setattr(nspace_hash, "metatable:name", metatable_tab_name); - Setattr(nspace_hash, "metatable:decl", metatable_tab_decl); - } + } + if (!eluac_ltr) { + String *metatable_tab = NewString(""); + String *metatable_tab_name = NewStringf("swig_%s_meta", mangled_name); + String *metatable_tab_decl = NewString(""); + Printv(metatable_tab, "swig_lua_method ", metatable_tab_name, "[]", NIL); + Printv(metatable_tab_decl, metatable_tab, ";", NIL); + Printv(metatable_tab, " = {\n", NIL); + Setattr(nspace_hash, "metatable", metatable_tab); + Setattr(nspace_hash, "metatable:name", metatable_tab_name); + Setattr(nspace_hash, "metatable:decl", metatable_tab_decl); } String *key = 0; if (nspace != 0) key = Copy(nspace); Setattr(namespaces_hash, key ? key : "", nspace_hash); + if (reg && nspace != 0 && Len(nspace) != 0 && Getattr(nspace_hash, "lua:no_reg") == 0) { + // Split names into components + List *components = Split(nspace, '.', -1); + String *parent_path = NewString(""); + int len = Len(components); + String *name = Copy(Getitem(components, len - 1)); + for (int i = 0; i < len - 1; i++) { + if (i > 0) + Printv(parent_path, NSPACE_SEPARATOR, NIL); + String *item = Getitem(components, i); + Printv(parent_path, item, NIL); + } + //Printf(stdout, "Registering %s. User name %s. C-name %s, Parent is %s\n", mangled_name, name, cname, parent_path); // TODO: REMOVE + Hash *parent = getNamespaceHash(parent_path, true); + String *namespaces_tab = Getattr(parent, "namespaces"); + Printv(namespaces_tab, "&", cname, ",\n", NIL); + if (elua_ltr || eluac_ltr) { + String *methods_tab = Getattr(parent, "methods"); + Printv(methods_tab, tab4, "{LSTRKEY(\"", name, "\")", ", LROVAL(", methods_tab_name, ")", "},\n", NIL); + } + Setattr(nspace_hash, "name", name); + + Delete(components); + Delete(parent_path); + } else if (!reg) // This namespace shouldn't be registered. Lets remember it + Setattr(nspace_hash, "lua:no_reg", "1"); + + + Delete(mangled_name); mangled_name = 0; return nspace_hash; @@ -1829,6 +1863,7 @@ public: if (elua_ltr) Printv(methods_tab, tab4, "{LSTRKEY(\"__metatable\"), LROVAL(", metatable_tab_name, ")},\n", NIL); + Printv(methods_tab, tab4, "{LSTRKEY(\"__disown\"), LFUNCVAL(SWIG_Lua_class_disown)},\n", NIL); Printv(methods_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); } else Printf(methods_tab, " {0,0}\n};\n"); @@ -1847,41 +1882,59 @@ public: } if (elua_ltr) { String *get_tab = Getattr(nspace_hash, "get"); - String *get_tab_name = Getattr(nspace_hash, "get:name"); String *set_tab = Getattr(nspace_hash, "set"); - String *set_tab_name = Getattr(nspace_hash, "set:name"); Printv(get_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); Printv(set_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); Printv(output, get_tab, NIL); Printv(output, set_tab, NIL); + } + if (!eluac_ltr) { String *metatable_tab = Getattr(nspace_hash, "metatable"); assert(metatable_tab); - Printv(metatable_tab, tab4, "{LSTRKEY(\"__index\"), LFUNCVAL(SWIG_Lua_namespace_get)},\n", NIL); - Printv(metatable_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_namespace_set)},\n", NIL); - Printv(metatable_tab, tab4, "{LSTRKEY(\".get\"), LROVAL(", get_tab_name, ")},\n", NIL); - Printv(metatable_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(", set_tab_name, ")},\n", NIL); - if (Getattr(nspace_hash, "lua:class_instance")) { - String *static_cls = Getattr(nspace_hash, "lua:class_instance:static_hash"); - assert(static_cls); - // static_cls is swig_lua_namespace. This structure can't be use with eLua(LTR) - // Instead structure describing its methods isused - String *static_cls_cname = Getattr(static_cls, "methods:name"); - assert(static_cls_cname); - Printv(metatable_tab, tab4, "{LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL); - // Put forward declaration of this array - Printv(output, "extern ", Getattr(static_cls, "methods:decl"), "\n", NIL); - } else if (Getattr(nspace_hash, "lua:class_static")) { - Hash *instance_cls = Getattr(nspace_hash, "lua:class_static:instance_hash"); - assert(instance_cls); - String *instance_cls_metatable_name = Getattr(instance_cls, "metatable:name"); - assert(instance_cls_metatable_name); - Printv(metatable_tab, tab4, "{LSTRKEY(\".instance\"), LROVAL(", instance_cls_metatable_name, ")},\n", NIL); + if (elua_ltr) { + String *get_tab_name = Getattr(nspace_hash, "get:name"); + String *set_tab_name = Getattr(nspace_hash, "set:name"); + + if (Getattr(nspace_hash, "lua:class_instance")) { + Printv(metatable_tab, tab4, "{LSTRKEY(\"__index\"), LFUNCVAL(SWIG_Lua_class_get)},\n", NIL); + Printv(metatable_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_class_set)},\n", NIL); + } else { + Printv(metatable_tab, tab4, "{LSTRKEY(\"__index\"), LFUNCVAL(SWIG_Lua_namespace_get)},\n", NIL); + Printv(metatable_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_namespace_set)},\n", NIL); + } + + Printv(metatable_tab, tab4, "{LSTRKEY(\"__gc\"), LFUNCVAL(SWIG_Lua_class_destruct)},\n", NIL); + Printv(metatable_tab, tab4, "{LSTRKEY(\".get\"), LROVAL(", get_tab_name, ")},\n", NIL); + Printv(metatable_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(", set_tab_name, ")},\n", NIL); + Printv(metatable_tab, tab4, "{LSTRKEY(\".fn\"), LROVAL(", Getattr(nspace_hash, "methods:name"), ")},\n", NIL); + + if (Getattr(nspace_hash, "lua:class_instance")) { + String *static_cls = Getattr(nspace_hash, "lua:class_instance:static_hash"); + assert(static_cls); + // static_cls is swig_lua_namespace. This structure can't be use with eLua(LTR) + // Instead structure describing its methods isused + String *static_cls_cname = Getattr(static_cls, "methods:name"); + assert(static_cls_cname); + Printv(metatable_tab, tab4, "{LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL); + // Put forward declaration of this array + Printv(output, "extern ", Getattr(static_cls, "methods:decl"), "\n", NIL); + } else if (Getattr(nspace_hash, "lua:class_static")) { + Hash *instance_cls = Getattr(nspace_hash, "lua:class_static:instance_hash"); + assert(instance_cls); + String *instance_cls_metatable_name = Getattr(instance_cls, "metatable:name"); + assert(instance_cls_metatable_name); + Printv(metatable_tab, tab4, "{LSTRKEY(\".instance\"), LROVAL(", instance_cls_metatable_name, ")},\n", NIL); + } + + Printv(metatable_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); + } else { + Printf(metatable_tab, " {0,0}\n};\n"); } - Printv(metatable_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); Printv(output, metatable_tab, NIL); } + Printv(output, "\n", NIL); } @@ -1896,7 +1949,7 @@ public: void closeNamespaces(File *dataOutput) { // Special handling for empty module. if (Getattr(namespaces_hash, "") == 0) { - // Module is empty. Create hash for global scope in order to have swig__Global + // Module is empty. Create hash for global scope in order to have swig__Module // variable in resulting file getNamespaceHash(0); } From 0c6263a0c2f6c5794c6a2c943493579ea95eb72e Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sun, 17 Nov 2013 04:08:58 +0400 Subject: [PATCH 0996/1160] Small bugfixes --- Lib/lua/luarun.swg | 2 +- Source/Modules/lua.cxx | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 9f8f69476..a20b20806 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -76,7 +76,7 @@ typedef struct swig_elua_entry { #define lua_pushrotable(L,p)\ lua_newtable(L);\ - SWIG_Lua_elua_emulate_register(L,p); + SWIG_Lua_elua_emulate_register(L,(swig_elua_entry*)(p)); #define SWIG_LUA_CONSTTAB_POINTER(B,C,D)\ LSTRKEY(B), {LUA_TUSERDATA, { .userdata={0,0,(void*)(C),&D} } } diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index c68782e75..7e598517d 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -1776,7 +1776,11 @@ public: String *metatable_tab = NewString(""); String *metatable_tab_name = NewStringf("swig_%s_meta", mangled_name); String *metatable_tab_decl = NewString(""); - Printv(metatable_tab, "swig_lua_method ", metatable_tab_name, "[]", NIL); + if (elua_ltr || eluac_ltr) // In this case const array holds rotable with namespace constants + Printf(metatable_tab, "const LUA_REG_TYPE "); + else + Printf(metatable_tab, "static swig_lua_method "); + Printv(metatable_tab, metatable_tab_name, "[]", NIL); Printv(metatable_tab_decl, metatable_tab, ";", NIL); Printv(metatable_tab, " = {\n", NIL); Setattr(nspace_hash, "metatable", metatable_tab); From 14452cad031b464d9d1d4b4c06dd36c67b121dc6 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sun, 17 Nov 2013 05:26:23 +0400 Subject: [PATCH 0997/1160] Attempt to catch unreproducable bug from Travis CI build --- Lib/lua/luarun.swg | 11 ++++++++--- Source/Modules/lua.cxx | 21 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index a20b20806..4aaa6eee7 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -76,6 +76,7 @@ typedef struct swig_elua_entry { #define lua_pushrotable(L,p)\ lua_newtable(L);\ + assert(p);\ SWIG_Lua_elua_emulate_register(L,(swig_elua_entry*)(p)); #define SWIG_LUA_CONSTTAB_POINTER(B,C,D)\ @@ -262,7 +263,7 @@ typedef struct swig_lua_class { swig_lua_method *methods; swig_lua_attribute *attributes; swig_lua_namespace *cls_static; - swig_lua_method *metatable; // only for eLua + swig_lua_method *metatable; // 0 for -eluac struct swig_lua_class **bases; const char **base_names; } swig_lua_class; @@ -1252,8 +1253,12 @@ SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L,swig_lua_class This adds methods from metatable array to metatable. Can mess up garbage collectind if someone defines __gc method */ - for(i=0;clss->metatable[i].name;i++) - SWIG_Lua_add_function(L,clss->metatable[i].name,clss->metatable[i].func); + if(clss->metatable) { + for(i=0;clss->metatable[i].name;i++) { + assert(clss->metatable[i].func != 0); // TODO: REMOVE + SWIG_Lua_add_function(L,clss->metatable[i].name,clss->metatable[i].func); + } + } } /* Register class static methods,attributes etc as well as constructor proxy */ diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 7e598517d..7349ce662 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -1194,6 +1194,7 @@ public: assert(class_static_nspace == 0); assert(class_fq_symname == 0); assert(class_symname == 0); + assert(class_parent_nspace == 0); current[NO_CPP] = false; @@ -1318,6 +1319,7 @@ public: // Module.ClassName.StaticMethod to access static method/variable/constant // Module.ClassName() to create new object if (have_constructor) { + assert(constructor_name); String *constructor_proxy_name = NewStringf("_proxy_%s", constructor_name); Printv(f_wrappers, "static int ", constructor_proxy_name, "(lua_State *L) {\n", NIL); Printv(f_wrappers, @@ -1385,6 +1387,12 @@ public: // First, print class static part printNamespaceDefinition(class_static_nspace, class_symname, f_wrappers); + assert(mangled_class_fq_symname); + assert(base_class); + assert(base_class_names); + assert(class_symname); + assert(class_fq_symname); + // Then print class isntance part Printv(f_wrappers, "static swig_lua_class *swig_", mangled_class_fq_symname, "_bases[] = {", base_class, "0};\n", NIL); Delete(base_class); @@ -1409,8 +1417,10 @@ public: } Printf(f_wrappers, ", %s, %s, &%s", s_methods_tab_name, s_attr_tab_name, Getattr(static_cls, "cname")); - if (!eluac_ltr) + if (!eluac_ltr) { + assert(Getattr(instance_cls, "metatable:name")); // TODO: REMOVE Printf(f_wrappers, ", %s", Getattr(instance_cls,"metatable:name")); + } else Printf(f_wrappers, ", 0"); @@ -1776,10 +1786,12 @@ public: String *metatable_tab = NewString(""); String *metatable_tab_name = NewStringf("swig_%s_meta", mangled_name); String *metatable_tab_decl = NewString(""); - if (elua_ltr || eluac_ltr) // In this case const array holds rotable with namespace constants + if (elua_ltr) // In this case const array holds rotable with namespace constants Printf(metatable_tab, "const LUA_REG_TYPE "); else Printf(metatable_tab, "static swig_lua_method "); + assert(metatable_tab); // TODO: REMOVE + assert(metatable_tab_name); // TODO: REMOVE Printv(metatable_tab, metatable_tab_name, "[]", NIL); Printv(metatable_tab_decl, metatable_tab, ";", NIL); Printv(metatable_tab, " = {\n", NIL); @@ -1861,11 +1873,14 @@ public: } String *methods_tab = Getattr(nspace_hash, "methods"); String *metatable_tab_name = Getattr(nspace_hash, "metatable:name"); + assert(methods_tab); // TODO: REMOVE if (elua_ltr || eluac_ltr) { if (v2_compatibility) Printv(methods_tab, tab4, "{LSTRKEY(\"const\"), LROVAL(", const_tab_name, ")},\n", NIL); - if (elua_ltr) + if (elua_ltr) { + assert(metatable_tab_name); // TODO: REMOVE Printv(methods_tab, tab4, "{LSTRKEY(\"__metatable\"), LROVAL(", metatable_tab_name, ")},\n", NIL); + } Printv(methods_tab, tab4, "{LSTRKEY(\"__disown\"), LFUNCVAL(SWIG_Lua_class_disown)},\n", NIL); Printv(methods_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); From e6d0f1327bea9917332e23e3653ef7f341f8bf9e Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Wed, 25 Dec 2013 17:50:22 +0400 Subject: [PATCH 0998/1160] Eliminating namespaces_hash and using symbols table instead --- Source/Modules/lang.cxx | 72 ++++++++++- Source/Modules/lua.cxx | 257 +++++++++++++++++++++------------------ Source/Modules/swigmod.h | 5 +- 3 files changed, 209 insertions(+), 125 deletions(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 6e0e88507..92781c043 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -319,8 +319,7 @@ overloading(0), multiinput(0), cplus_runtime(0), directors(0) { - Hash *symbols = NewHash(); - Setattr(symtabs, "", symbols); // create top level/global symbol table scope + addScope(""); // create top level/global symbol table scope argc_template_string = NewString("argc"); argv_template_string = NewString("argv[%d]"); @@ -3061,9 +3060,7 @@ int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr //Printf( stdout, "addSymbol: %s %s\n", s, scope ); Hash *symbols = Getattr(symtabs, scope ? scope : ""); if (!symbols) { - // New scope which has not been added by the target language - lazily created. - symbols = NewHash(); - Setattr(symtabs, scope, symbols); + symbols = addScope(scope); } else { Node *c = Getattr(symbols, s); if (c && (c != n)) { @@ -3079,6 +3076,71 @@ int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr return 1; } +/* ----------------------------------------------------------------------------- + * Lanugage::addScope( const_String_or_char_ptr scopeName ) + * + * Creates a scope (symbols Hash) for given name. This method is auxilary, + * you don't have to call it - addSymbols will lazily create scopes automatically. + * If scope with given name already exists, then do nothing. + * Returns newly created (or already existing) scope. + * ----------------------------------------------------------------------------- */ +Hash* Language::addScope(const_String_or_char_ptr scope) { + Hash *symbols = scopeLookup(scope); + if(!symbols) { + // Order in which to following parts are executed is important. In Lanugage + // constructor addScope("") is called to create a top level scope itself. + // Thus we must first add symbols hash to symtab and only then add pseudo + // symbol to top-level scope + + // New scope which has not been added by the target language - lazily created. + symbols = NewHash(); + Setattr(symtabs, scope, symbols); + + // Add the new scope as a symbol in the top level scope. + // Alternatively the target language must add it in before attempting to add symbols into the scope. + const_String_or_char_ptr top_scope = ""; + Hash *topscope_symbols = Getattr(symtabs, top_scope); + Hash *pseudo_symbol = NewHash(); + Setattr(pseudo_symbol, "sym:is_scope", "1"); + Setattr(topscope_symbols, scope, pseudo_symbol); + } + return symbols; +} + +/* ----------------------------------------------------------------------------- + * Lanugage::scopeLookup( const_String_or_char_ptr scope ) + * + * Lookup and returns a symtable (hash) representing given scope. Hash contains + * all symbols in this scope. + * ----------------------------------------------------------------------------- */ +Hash* Language::scopeLookup( const_String_or_char_ptr scope ) { + Hash *symbols = Getattr(symtabs, scope ? scope : ""); + return symbols; +} + +/* ----------------------------------------------------------------------------- + * Lanugage::scopeSymbolLookup( const_String_or_char_ptr scope ) + * + * For every scope there is a special pseudo-symbol in the top scope (""). It + * exists solely to detect name clashes. This pseudo symbol may contain a few properties, + * but you can more if you need to. This is also true fro top level scope (""). + * It contains a pseudo symbol with name "" (empty). Pseudo symbol contains the + * following properties: + * sym:scope = "1" - a flag that this is scope pseudo symbol + * + * Pseudo symbols are a Hash*, not a Node* (not that there is a difference + * in DOH) + * There is no difference from symbolLookup() method except for signature + * and return type. + * ----------------------------------------------------------------------------- */ +Hash* Language::scopeSymbolLookup( const_String_or_char_ptr scope ) +{ + /* Getting top scope */ + const_String_or_char_ptr top_scope = ""; + Hash *symbols = Getattr(symtabs, top_scope); + return Getattr(symbols, scope); +} + /* ----------------------------------------------------------------------------- * Language::dumpSymbols() * ----------------------------------------------------------------------------- */ diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 7349ce662..6317f0910 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -120,7 +120,6 @@ private: File *f_initbeforefunc; String *s_luacode; // luacode to be called during init String *module; //name of the module - Hash *namespaces_hash; // Parameters for current class. NIL if not parsing class int have_constructor; @@ -176,13 +175,10 @@ public: class_fq_symname(0), class_static_nspace(0), constructor_name(0) { - namespaces_hash = NewHash(); for (int i = 0; i < STATES_COUNT; i++) current[i] = false; } ~LUA() { - if (namespaces_hash) - Delete(namespaces_hash); } bool strToInt(const char *string, int &value) { @@ -477,7 +473,7 @@ public: // Add method to the "methods" C array of given namespace/class void registerMethod(String *nspace_or_class_name, Node *n) { assert(n); - Hash *nspaceHash = getNamespaceHash(nspace_or_class_name); + Hash *nspaceHash = getCArraysHash(nspace_or_class_name); String *s_ns_methods_tab = Getattr(nspaceHash, "methods"); String *wname = Getattr(n, "wrap:name"); String *target_name = Getattr(n, "lua:name"); @@ -922,7 +918,7 @@ public: if (setName == 0 || GetFlag(n, "feature:immutable")) { setName = unassignable; } - Hash *nspaceHash = getNamespaceHash(nspace_or_class_name); + Hash *nspaceHash = getCArraysHash(nspace_or_class_name); String *s_ns_methods_tab = Getattr(nspaceHash, "methods"); String *s_ns_var_tab = Getattr(nspaceHash, "attributes"); String *target_name = Getattr(n, "lua:name"); @@ -968,7 +964,7 @@ public: * Actually, in current implementation it is resolved consttab typemap * ------------------------------------------------------------ */ void registerConstant(String *nspace, String *constantRecord) { - Hash *nspaceHash = getNamespaceHash(nspace); + Hash *nspaceHash = getCArraysHash(nspace); String *s_const_tab = 0; if (eluac_ltr || elua_ltr) // In elua everything goes to "methods" tab @@ -1102,7 +1098,7 @@ public: if (!luaAddSymbol(wrapname, n)) return SWIG_ERROR; - Hash *nspaceHash = getNamespaceHash(getNSpace()); + Hash *nspaceHash = getCArraysHash(getNSpace()); String *s_ns_methods_tab = Getattr(nspaceHash, "methods"); Printv(s_ns_methods_tab, tab4, "{ \"", symname, "\",", wrapname, "},\n", NIL); // return Language::nativeWrapper(n); // this does nothing... @@ -1165,12 +1161,12 @@ public: void registerClass(String *scope, Node *n) { String *wrap_class = Getattr(n,"wrap:class_name"); assert(wrap_class); - Hash *nspaceHash = getNamespaceHash(scope); + Hash *nspaceHash = getCArraysHash(scope); String *ns_classes = Getattr(nspaceHash, "classes"); Printv(ns_classes, "&", wrap_class, ",\n", NIL); if (elua_ltr || eluac_ltr) { String *ns_methods = Getattr(nspaceHash, "methods"); - Hash *class_hash = getNamespaceHash(class_static_nspace); + Hash *class_hash = getCArraysHash(class_static_nspace); assert(class_hash); String *cls_methods = Getattr(class_hash, "methods:name"); assert(cls_methods); @@ -1240,14 +1236,14 @@ public: // and constants are considered part of namespace T, all members - part of the 'class' // Now, here is a trick. Static methods, attributes and non-static methods and attributes // are described with same structures - swig_lua_attribute/swig_lua_method. Instead of calling - // getNamespaceHash(class name) to initialize things for static methods/attributes and then - // manually doing same initialization for non-static methods, we call getNamespaceHash 2 times: + // getCArraysHash(class name) to initialize things for static methods/attributes and then + // manually doing same initialization for non-static methods, we call getCArraysHash 2 times: // 1) With name "class name" + "." + "__Static" to initialize static things // 2) With "class name" to initialize non-static things // And we can guarantee that there will not be any name collision because names starting with 2 underscores // and capital letter are forbiden to use in C++. So, under know circumstances could our class contain // any member or subclass with name "__Static". Thus, never any name clash. - Hash *instance_cls = getNamespaceHash(class_fq_symname, false); + Hash *instance_cls = getCArraysHash(class_fq_symname, false); assert(instance_cls); String *s_attr_tab_name = Getattr(instance_cls, "attributes:name"); String *s_methods_tab_name = Getattr(instance_cls, "methods:name"); @@ -1260,7 +1256,7 @@ public: */ class_static_nspace = NewStringf("%s%s__Static", class_fq_symname, NSPACE_SEPARATOR); - Hash *static_cls = getNamespaceHash(class_static_nspace, false); + Hash *static_cls = getCArraysHash(class_static_nspace, false); assert(static_cls); Setattr(static_cls, "lua:no_namespaces", "1"); Setattr(static_cls, "lua:class_static", "1"); @@ -1272,8 +1268,6 @@ public: /* There is no use for "classes" and "namespaces" arrays. Subclasses are not supported * by SWIG and namespaces couldn't be nested inside classes (C++ Standard) */ - // Replacing namespace with namespace + class in order to static - // member be put inside class static area class_parent_nspace = getNSpace(); // Generate normal wrappers Language::classHandler(n); @@ -1293,7 +1287,7 @@ public: // Adding class to apropriate namespace registerClass(nspace, n); - Hash *nspaceHash = getNamespaceHash(nspace); + Hash *nspaceHash = getCArraysHash(nspace); // Register the class structure with the type checker // Printf(f_init,"SWIG_TypeClientData(SWIGTYPE%s, (void *) &_wrap_class_%s);\n", SwigType_manglestr(t), mangled_class_fq_symname); @@ -1349,8 +1343,8 @@ public: } } - closeNamespaceHash(class_fq_symname, f_wrappers); - closeNamespaceHash(class_static_nspace, f_wrappers); + closeCArraysHash(class_fq_symname, f_wrappers); + closeCArraysHash(class_static_nspace, f_wrappers); // Handle inheritance @@ -1385,7 +1379,7 @@ public: } } // First, print class static part - printNamespaceDefinition(class_static_nspace, class_symname, f_wrappers); + printCArraysDefinition(class_static_nspace, class_symname, f_wrappers); assert(mangled_class_fq_symname); assert(base_class); @@ -1670,10 +1664,24 @@ public: } /* ----------------------------------------------------------------------------- - * getNamespaceHash() + * rawGetCArraysHash(String *name) + * + * A small helper to hide impelementation of how CArrays hashes are stored + * ---------------------------------------------------------------------------- */ + Hash *rawGetCArraysHash(const_String_or_char_ptr name) { + Hash *scope = scopeLookup( name ? name : "" ); + if(!scope) + return 0; + + Hash *carrays_hash = Getattr(scope, "lua:cdata"); + return carrays_hash; + } + + /* ----------------------------------------------------------------------------- + * getCArraysHash() * Each namespace can be described with hash that stores C arrays * where members of the namespace should be added. All these hashes are stored - * inside namespaces_hash. + * inside symbols table, in pseudo-symbol for every namespace. * nspace could be NULL (NSPACE_TODO), that means functions and variables and classes * that are not in any namespace (this is default for SWIG unless %nspace feature is used) * You can later set some attributes that will affect behaviour of functions that use this hash: @@ -1685,11 +1693,17 @@ public: * Namespace could be automatically registered to it's parent if 'reg' == true. It can be done * only at first call (a.k.a when nspace is created). * ---------------------------------------------------------------------------- */ - Hash *getNamespaceHash(String *nspace, bool reg = true) { - Hash *nspace_hash = Getattr(namespaces_hash, nspace ? nspace : ""); - if (nspace_hash != 0) - return nspace_hash; - nspace_hash = NewHash(); + Hash *getCArraysHash(String *nspace, bool reg = true) { + Hash *scope = scopeLookup(nspace ? nspace : ""); + if(!scope) { + addScope( nspace ? nspace : "" ); + scope = scopeLookup(nspace ? nspace : ""); + assert(scope); + } + Hash *carrays_hash = Getattr(scope, "lua:cdata"); + if (carrays_hash != 0) + return carrays_hash; + carrays_hash = NewHash(); String *mangled_name = 0; if (nspace == 0 || Len(nspace) == 0) mangled_name = NewString("__Module"); // C++ names can't start with "__ + capital letter" @@ -1697,7 +1711,7 @@ public: mangled_name = Swig_name_mangle(nspace); String *cname = NewStringf("swig_%s", mangled_name); - Setattr(nspace_hash, "cname", cname); + Setattr(carrays_hash, "cname", cname); String *attr_tab = NewString(""); String *attr_tab_name = NewStringf("swig_%s_attributes", mangled_name); @@ -1706,9 +1720,9 @@ public: Printv(attr_tab, attr_tab_name, "[]", NIL); Printv(attr_tab_decl, attr_tab, ";\n", NIL); Printv(attr_tab, " = {\n", NIL); - Setattr(nspace_hash, "attributes", attr_tab); - Setattr(nspace_hash, "attributes:name", attr_tab_name); - Setattr(nspace_hash, "attributes:decl", attr_tab_decl); + Setattr(carrays_hash, "attributes", attr_tab); + Setattr(carrays_hash, "attributes:name", attr_tab_name); + Setattr(carrays_hash, "attributes:decl", attr_tab_decl); String *methods_tab = NewString(""); String *methods_tab_name = NewStringf("swig_%s_methods", mangled_name); @@ -1720,9 +1734,9 @@ public: Printv(methods_tab, methods_tab_name, "[]", NIL); Printv(methods_tab_decl, methods_tab, ";\n", NIL); Printv(methods_tab, "= {\n", NIL); - Setattr(nspace_hash, "methods", methods_tab); - Setattr(nspace_hash, "methods:name", methods_tab_name); - Setattr(nspace_hash, "methods:decl", methods_tab_decl); + Setattr(carrays_hash, "methods", methods_tab); + Setattr(carrays_hash, "methods:name", methods_tab_name); + Setattr(carrays_hash, "methods:decl", methods_tab_decl); String *const_tab = NewString(""); String *const_tab_name = NewStringf("swig_%s_constants", mangled_name); @@ -1734,9 +1748,9 @@ public: Printv(const_tab, const_tab_name, "[]", NIL); Printv(const_tab_decl, const_tab, ";", NIL); Printv(const_tab, "= {\n", NIL); - Setattr(nspace_hash, "constants", const_tab); - Setattr(nspace_hash, "constants:name", const_tab_name); - Setattr(nspace_hash, "constants:decl", const_tab_decl); + Setattr(carrays_hash, "constants", const_tab); + Setattr(carrays_hash, "constants:name", const_tab_name); + Setattr(carrays_hash, "constants:decl", const_tab_decl); String *classes_tab = NewString(""); String *classes_tab_name = NewStringf("swig_%s_classes", mangled_name); @@ -1745,9 +1759,9 @@ public: Printv(classes_tab, classes_tab_name, "[]", NIL); Printv(classes_tab_decl, classes_tab, ";", NIL); Printv(classes_tab, "= {\n", NIL); - Setattr(nspace_hash, "classes", classes_tab); - Setattr(nspace_hash, "classes:name", classes_tab_name); - Setattr(nspace_hash, "classes:decl", classes_tab_decl); + Setattr(carrays_hash, "classes", classes_tab); + Setattr(carrays_hash, "classes:name", classes_tab_name); + Setattr(carrays_hash, "classes:decl", classes_tab_decl); String *namespaces_tab = NewString(""); String *namespaces_tab_name = NewStringf("swig_%s_namespaces", mangled_name); @@ -1756,9 +1770,9 @@ public: Printv(namespaces_tab, namespaces_tab_name, "[]", NIL); Printv(namespaces_tab_decl, namespaces_tab, ";", NIL); Printv(namespaces_tab, " = {\n", NIL); - Setattr(nspace_hash, "namespaces", namespaces_tab); - Setattr(nspace_hash, "namespaces:name", namespaces_tab_name); - Setattr(nspace_hash, "namespaces:decl", namespaces_tab_decl); + Setattr(carrays_hash, "namespaces", namespaces_tab); + Setattr(carrays_hash, "namespaces:name", namespaces_tab_name); + Setattr(carrays_hash, "namespaces:decl", namespaces_tab_decl); if (elua_ltr) { String *get_tab = NewString(""); @@ -1767,9 +1781,9 @@ public: Printv(get_tab, "const LUA_REG_TYPE ", get_tab_name, "[]", NIL); Printv(get_tab_decl, get_tab, ";", NIL); Printv(get_tab, " = {\n", NIL); - Setattr(nspace_hash, "get", get_tab); - Setattr(nspace_hash, "get:name", get_tab_name); - Setattr(nspace_hash, "get:decl", get_tab_decl); + Setattr(carrays_hash, "get", get_tab); + Setattr(carrays_hash, "get:name", get_tab_name); + Setattr(carrays_hash, "get:decl", get_tab_decl); String *set_tab = NewString(""); String *set_tab_name = NewStringf("swig_%s_set", mangled_name); @@ -1777,9 +1791,9 @@ public: Printv(set_tab, "const LUA_REG_TYPE ", set_tab_name, "[]", NIL); Printv(set_tab_decl, set_tab, ";", NIL); Printv(set_tab, " = {\n", NIL); - Setattr(nspace_hash, "set", set_tab); - Setattr(nspace_hash, "set:name", set_tab_name); - Setattr(nspace_hash, "set:decl", set_tab_decl); + Setattr(carrays_hash, "set", set_tab); + Setattr(carrays_hash, "set:name", set_tab_name); + Setattr(carrays_hash, "set:decl", set_tab_decl); } if (!eluac_ltr) { @@ -1795,16 +1809,15 @@ public: Printv(metatable_tab, metatable_tab_name, "[]", NIL); Printv(metatable_tab_decl, metatable_tab, ";", NIL); Printv(metatable_tab, " = {\n", NIL); - Setattr(nspace_hash, "metatable", metatable_tab); - Setattr(nspace_hash, "metatable:name", metatable_tab_name); - Setattr(nspace_hash, "metatable:decl", metatable_tab_decl); + Setattr(carrays_hash, "metatable", metatable_tab); + Setattr(carrays_hash, "metatable:name", metatable_tab_name); + Setattr(carrays_hash, "metatable:decl", metatable_tab_decl); } - String *key = 0; - if (nspace != 0) - key = Copy(nspace); - Setattr(namespaces_hash, key ? key : "", nspace_hash); - if (reg && nspace != 0 && Len(nspace) != 0 && Getattr(nspace_hash, "lua:no_reg") == 0) { + Setattr(scope, "lua:cdata", carrays_hash); + assert(rawGetCArraysHash(nspace)); + + if (reg && nspace != 0 && Len(nspace) != 0 && Getattr(carrays_hash, "lua:no_reg") == 0) { // Split names into components List *components = Split(nspace, '.', -1); String *parent_path = NewString(""); @@ -1817,50 +1830,49 @@ public: Printv(parent_path, item, NIL); } //Printf(stdout, "Registering %s. User name %s. C-name %s, Parent is %s\n", mangled_name, name, cname, parent_path); // TODO: REMOVE - Hash *parent = getNamespaceHash(parent_path, true); + Hash *parent = getCArraysHash(parent_path, true); String *namespaces_tab = Getattr(parent, "namespaces"); Printv(namespaces_tab, "&", cname, ",\n", NIL); if (elua_ltr || eluac_ltr) { String *methods_tab = Getattr(parent, "methods"); Printv(methods_tab, tab4, "{LSTRKEY(\"", name, "\")", ", LROVAL(", methods_tab_name, ")", "},\n", NIL); } - Setattr(nspace_hash, "name", name); + Setattr(carrays_hash, "name", name); Delete(components); Delete(parent_path); } else if (!reg) // This namespace shouldn't be registered. Lets remember it - Setattr(nspace_hash, "lua:no_reg", "1"); - + Setattr(carrays_hash, "lua:no_reg", "1"); Delete(mangled_name); mangled_name = 0; - return nspace_hash; + return carrays_hash; } /* ----------------------------------------------------------------------------- - * closeNamespaceHash() + * closeCArraysHash() * Functions add end markers {0,0,...,0} to all arrays, prints them to * output and marks hash as closed (lua:closed). Consequent attempts to * close same hash will result in error - * closeNamespaceHash DOES NOT print structure that describes namespace, it only - * prints array. You can use printNamespaceDefinition to print structure. + * closeCArraysHash DOES NOT print structure that describes namespace, it only + * prints array. You can use printCArraysDefinition to print structure. * if "lua:no_namespaces" is set, then array for "namespaces" won't be printed * if "lua:no_classes" is set, then array for "classes" won't be printed * ----------------------------------------------------------------------------- */ - void closeNamespaceHash(String *nspace, File *output) { - Hash *nspace_hash = Getattr(namespaces_hash, nspace); - assert(nspace_hash); - assert(Getattr(nspace_hash, "lua:closed") == 0); + void closeCArraysHash(String *nspace, File *output) { + Hash *carrays_hash = rawGetCArraysHash(nspace); + assert(carrays_hash); + assert(Getattr(carrays_hash, "lua:closed") == 0); - Setattr(nspace_hash, "lua:closed", "1"); + Setattr(carrays_hash, "lua:closed", "1"); - String *attr_tab = Getattr(nspace_hash, "attributes"); + String *attr_tab = Getattr(carrays_hash, "attributes"); Printf(attr_tab, " {0,0,0}\n};\n"); Printv(output, attr_tab, NIL); - String *const_tab = Getattr(nspace_hash, "constants"); - String *const_tab_name = Getattr(nspace_hash, "constants:name"); + String *const_tab = Getattr(carrays_hash, "constants"); + String *const_tab_name = Getattr(carrays_hash, "constants:name"); if (elua_ltr || eluac_ltr) Printv(const_tab, tab4, "{LNILKEY, LNILVAL}\n", "};\n", NIL); else @@ -1869,10 +1881,10 @@ public: if (elua_ltr) { // Put forward declaration of metatable array - Printv(output, "extern ", Getattr(nspace_hash, "metatable:decl"), "\n", NIL); + Printv(output, "extern ", Getattr(carrays_hash, "metatable:decl"), "\n", NIL); } - String *methods_tab = Getattr(nspace_hash, "methods"); - String *metatable_tab_name = Getattr(nspace_hash, "metatable:name"); + String *methods_tab = Getattr(carrays_hash, "methods"); + String *metatable_tab_name = Getattr(carrays_hash, "metatable:name"); assert(methods_tab); // TODO: REMOVE if (elua_ltr || eluac_ltr) { if (v2_compatibility) @@ -1888,20 +1900,20 @@ public: Printf(methods_tab, " {0,0}\n};\n"); Printv(output, methods_tab, NIL); - if (!Getattr(nspace_hash, "lua:no_classes")) { - String *classes_tab = Getattr(nspace_hash, "classes"); + if (!Getattr(carrays_hash, "lua:no_classes")) { + String *classes_tab = Getattr(carrays_hash, "classes"); Printf(classes_tab, " 0\n};\n"); Printv(output, classes_tab, NIL); } - if (!Getattr(nspace_hash, "lua:no_namespaces")) { - String *namespaces_tab = Getattr(nspace_hash, "namespaces"); + if (!Getattr(carrays_hash, "lua:no_namespaces")) { + String *namespaces_tab = Getattr(carrays_hash, "namespaces"); Printf(namespaces_tab, " 0\n};\n"); Printv(output, namespaces_tab, NIL); } if (elua_ltr) { - String *get_tab = Getattr(nspace_hash, "get"); - String *set_tab = Getattr(nspace_hash, "set"); + String *get_tab = Getattr(carrays_hash, "get"); + String *set_tab = Getattr(carrays_hash, "set"); Printv(get_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); Printv(set_tab, tab4, "{LNILKEY, LNILVAL}\n};\n", NIL); Printv(output, get_tab, NIL); @@ -1909,13 +1921,13 @@ public: } if (!eluac_ltr) { - String *metatable_tab = Getattr(nspace_hash, "metatable"); + String *metatable_tab = Getattr(carrays_hash, "metatable"); assert(metatable_tab); if (elua_ltr) { - String *get_tab_name = Getattr(nspace_hash, "get:name"); - String *set_tab_name = Getattr(nspace_hash, "set:name"); + String *get_tab_name = Getattr(carrays_hash, "get:name"); + String *set_tab_name = Getattr(carrays_hash, "set:name"); - if (Getattr(nspace_hash, "lua:class_instance")) { + if (Getattr(carrays_hash, "lua:class_instance")) { Printv(metatable_tab, tab4, "{LSTRKEY(\"__index\"), LFUNCVAL(SWIG_Lua_class_get)},\n", NIL); Printv(metatable_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_class_set)},\n", NIL); } else { @@ -1926,10 +1938,10 @@ public: Printv(metatable_tab, tab4, "{LSTRKEY(\"__gc\"), LFUNCVAL(SWIG_Lua_class_destruct)},\n", NIL); Printv(metatable_tab, tab4, "{LSTRKEY(\".get\"), LROVAL(", get_tab_name, ")},\n", NIL); Printv(metatable_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(", set_tab_name, ")},\n", NIL); - Printv(metatable_tab, tab4, "{LSTRKEY(\".fn\"), LROVAL(", Getattr(nspace_hash, "methods:name"), ")},\n", NIL); + Printv(metatable_tab, tab4, "{LSTRKEY(\".fn\"), LROVAL(", Getattr(carrays_hash, "methods:name"), ")},\n", NIL); - if (Getattr(nspace_hash, "lua:class_instance")) { - String *static_cls = Getattr(nspace_hash, "lua:class_instance:static_hash"); + if (Getattr(carrays_hash, "lua:class_instance")) { + String *static_cls = Getattr(carrays_hash, "lua:class_instance:static_hash"); assert(static_cls); // static_cls is swig_lua_namespace. This structure can't be use with eLua(LTR) // Instead structure describing its methods isused @@ -1938,8 +1950,8 @@ public: Printv(metatable_tab, tab4, "{LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL); // Put forward declaration of this array Printv(output, "extern ", Getattr(static_cls, "methods:decl"), "\n", NIL); - } else if (Getattr(nspace_hash, "lua:class_static")) { - Hash *instance_cls = Getattr(nspace_hash, "lua:class_static:instance_hash"); + } else if (Getattr(carrays_hash, "lua:class_static")) { + Hash *instance_cls = Getattr(carrays_hash, "lua:class_static:instance_hash"); assert(instance_cls); String *instance_cls_metatable_name = Getattr(instance_cls, "metatable:name"); assert(instance_cls_metatable_name); @@ -1962,42 +1974,53 @@ public: } /* ----------------------------------------------------------------------------- - * closeNamespaceHash() + * closeCArraysHash() * Recursively close all non-closed namespaces. Prints data to dataOutput. * ----------------------------------------------------------------------------- */ void closeNamespaces(File *dataOutput) { // Special handling for empty module. - if (Getattr(namespaces_hash, "") == 0) { + if (scopeLookup("") == 0 || rawGetCArraysHash("") == 0) { // Module is empty. Create hash for global scope in order to have swig__Module // variable in resulting file - getNamespaceHash(0); + getCArraysHash(0); } - Iterator ki = First(namespaces_hash); + // Because we cant access directly 'symtabs', instead we access + // top-level scope and look on all scope pseudo-symbols in it. + Hash *top_scope = scopeLookup(""); + assert(top_scope); + Iterator ki = First(top_scope); List *to_close = NewList(); while (ki.key) { - if (Getattr(ki.item, "lua:closed") == 0) - Append(to_close, ki.key); + assert(ki.item); + if (Getattr(ki.item, "sym:is_scope")) { + // We have a pseudo symbol. Lets get actuall scope for this + // pseudo symbol + Hash *carrays_hash = rawGetCArraysHash(ki.key); + assert(carrays_hash); + if (Getattr(carrays_hash, "lua:closed") == 0) + Append(to_close, ki.key); + } ki = Next(ki); } SortList(to_close, &compareByLen); int len = Len(to_close); for (int i = 0; i < len; i++) { String *key = Getitem(to_close, i); - closeNamespaceHash(key, dataOutput); - Hash *nspace = Getattr(namespaces_hash, key); + closeCArraysHash(key, dataOutput); + Hash *carrays_hash = rawGetCArraysHash(key); String *name = 0; // name - name of the namespace as it should be visible in Lua if (DohLen(key) == 0) // This is global module name = module; else - name = Getattr(nspace, "name"); + name = Getattr(carrays_hash, "name"); assert(name); - printNamespaceDefinition(key, name, dataOutput); + printCArraysDefinition(key, name, dataOutput); } Delete(to_close); } /* ----------------------------------------------------------------------------- - * printNamespaceDefinition() + * printCArraysDefinition() * This function prints to output a definition of namespace in * form * swig_lua_namespace $cname = { attr_array, methods_array, ... , namespaces_array }; @@ -2005,21 +2028,21 @@ public: * 'name' is a user-visible name that this namespace will have in Lua. It shouldn't * be fully qualified name, just it's own name. * ----------------------------------------------------------------------------- */ - void printNamespaceDefinition(String *nspace, String *name, File *output) { - Hash *nspace_hash = getNamespaceHash(nspace, false); + void printCArraysDefinition(String *nspace, String *name, File *output) { + Hash *carrays_hash = getCArraysHash(nspace, false); - String *cname = Getattr(nspace_hash, "cname"); // cname - name of the C structure that describes namespace + String *cname = Getattr(carrays_hash, "cname"); // cname - name of the C structure that describes namespace assert(cname); Printv(output, "static swig_lua_namespace ", cname, " = ", NIL); String *null_string = NewString("0"); - String *attr_tab_name = Getattr(nspace_hash, "attributes:name"); - String *methods_tab_name = Getattr(nspace_hash, "methods:name"); - String *const_tab_name = Getattr(nspace_hash, "constants:name"); - String *classes_tab_name = Getattr(nspace_hash, "classes:name"); - String *namespaces_tab_name = Getattr(nspace_hash, "namespaces:name"); - bool has_classes = Getattr(nspace_hash, "lua:no_classes") == 0; - bool has_namespaces = Getattr(nspace_hash, "lua:no_namespaces") == 0; + String *attr_tab_name = Getattr(carrays_hash, "attributes:name"); + String *methods_tab_name = Getattr(carrays_hash, "methods:name"); + String *const_tab_name = Getattr(carrays_hash, "constants:name"); + String *classes_tab_name = Getattr(carrays_hash, "classes:name"); + String *namespaces_tab_name = Getattr(carrays_hash, "namespaces:name"); + bool has_classes = Getattr(carrays_hash, "lua:no_classes") == 0; + bool has_namespaces = Getattr(carrays_hash, "lua:no_namespaces") == 0; Printv(output, "{\n", tab4, "\"", name, "\",\n", @@ -2064,15 +2087,12 @@ public: /* ----------------------------------------------------------------------------- * luaAddSymbol() - * Our implementation of addSymbol. Determines scope correctly, then calls Language::addSymbol + * Our implementation of addSymbol. Determines scope correctly, then + * forwards to Language::addSymbol * ----------------------------------------------------------------------------- */ int luaAddSymbol(const String *s, const Node *n) { String *scope = luaCurrentSymbolNSpace(); - //Printf(stdout, "luaAddSymbol: %s scope: %s\n", s, scope); - int result = Language::addSymbol(s, n, scope); - if (!result) - Printf(stderr, "addSymbol(%s to scope %s) failed\n", s, scope); - return result; + return luaAddSymbol(s, n, scope); } /* ----------------------------------------------------------------------------- @@ -2080,7 +2100,6 @@ public: * Overload. Enforces given scope. Actually, it simply forwards call to Language::addSymbol * ----------------------------------------------------------------------------- */ int luaAddSymbol(const String *s, const Node *n, const_String_or_char_ptr scope) { - //Printf(stdout, "luaAddSymbol: %s scope: %s\n", s, scope); int result = Language::addSymbol(s, n, scope); if (!result) Printf(stderr, "addSymbol(%s to scope %s) failed\n", s, scope); diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 2929993b3..40064ea38 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -215,7 +215,10 @@ public: virtual int validIdentifier(String *s); /* valid identifier? */ virtual int addSymbol(const String *s, const Node *n, const_String_or_char_ptr scope = ""); /* Add symbol */ virtual void dumpSymbols(); - virtual Node *symbolLookup(String *s, const_String_or_char_ptr scope = ""); /* Symbol lookup */ + virtual Node *symbolLookup(String *s, const_String_or_char_ptr scope = ""); /* Symbol lookup */ + virtual Hash* addScope(const_String_or_char_ptr scope); + virtual Hash* scopeLookup( const_String_or_char_ptr scope ); + virtual Hash* scopeSymbolLookup( const_String_or_char_ptr scope ); virtual Node *classLookup(const SwigType *s) const; /* Class lookup */ virtual Node *enumLookup(SwigType *s); /* Enum lookup */ virtual int abstractClassTest(Node *n); /* Is class really abstract? */ From 3d36a69d81bd47b43163a49c65c3c7b1e0edd133 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Wed, 13 Nov 2013 18:10:43 +0400 Subject: [PATCH 0999/1160] Updating Lua documentation --- Doc/Manual/Lua.html | 207 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 202 insertions(+), 5 deletions(-) diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index 88d26f385..b890a7138 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -70,6 +70,7 @@ 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++). It's 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

    +TODO: Fix if elua disabled eLua stands for Embedded Lua (can be thought of as a flavor of Lua) and offers the full implementation of the Lua programming language to the embedded world, extending it with specific features for efficient and portable software embedded development. eLua runs on smaller devices like microcontrollers and provides the full features of the regular Lua desktop version. More information on eLua can be found here: http://www.eluaproject.net

    @@ -77,6 +78,7 @@ eLua stands for Embedded Lua (can be thought of as a flavor of Lua) and offers t

    +TODO: Fix if elua disabled The current SWIG implementation is designed to work with Lua 5.0.x, 5.1.x and 5.2.x. It should work with later versions of Lua, but certainly not with Lua 4.0 due to substantial API changes. It is possible to either static link or dynamic link a Lua module into the interpreter (normally Lua static links its libraries, as dynamic linking is not available on all platforms). SWIG also supports eLua and works with eLua 0.8. SWIG generated code for eLua has been tested on Stellaris ARM Cortex-M3 LM3S and Infineon TriCore.

    @@ -159,6 +161,10 @@ swig -lua -help Do not register the module name as a global variable but return the module table from calls to require. + + -swig3 + Disable backward compatibility: old-style binding names generations and a few other things. Explanations are included into appropriate sections. +

    26.2.2 Compiling and Linking and Interpreter

    @@ -349,7 +355,8 @@ creates a built-in function example.fact(n) that works exactly like you >

    -To avoid name collisions, SWIG create a Lua table which it keeps all the functions and global variables in. It is possible to copy the functions out of this and into the global environment with the following code. This can easily overwrite existing functions, so this must be used with care. +To avoid name collisions, SWIG create a Lua table which it keeps all the functions, constants, classes and global variables in. It is possible to copy the functions, constants and classes (but not variables) out of this and into the global environment with the following code. This can easily overwrite existing functions, so this must be used with care. +This option is considered deprecated and will be removed in near future.

     > for k,v in pairs(example) do _G[k]=v end
    @@ -490,6 +497,52 @@ If you're using eLua and have used -elua or -eluac to generate
     > print(example.const.SCONST)
     Hello World
     
    + +

    Constants/enums and classes/structures

    +

    +Unlike previous version of bindings, enums are now exported into class table. For example, given some enums: +

    +
    %module example
    +enum Days{SUNDAY = 0,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY};
    +class Test {
    +    enum { TEST1 = 10, TEST2 = 10 }
    +    static const int ICONST = 12;
    +};
    +
    +

    +This is 'effectively' converted into the following Lua code: +

    +
    +> print(example.const.SUNDAY)
    +0
    +> print(example.Test.TEST1)
    +10
    +> print(example.Test.ICONST)
    +12
    +
    +

    Backward compatibility

    +

    +If -swig3 option is not given, then in addition to previously described bindings, the old-style ones are generated: +

    +
    +> print(example.Test_TEST1)
    +10
    +> print(example.Test_ICONST)
    +12
    +
    +

    +However, in C mode, names of enums are not prefixed with names of structure. This is the due to C Standard. +

    +
    +> print(example.TEST1)
    +10
    +> print(example.ICONST)
    +12
    +
    +

    +It worth mentioning, that example.Test.TEST1 and example.Test_TEST1 are different entities and changind one wouldn't change another. +Given the fact, that these are constantes and they are not supposed to be changed, it is up to you to avoid such issues. +

    26.3.5 Pointers

    @@ -551,7 +604,7 @@ is used as follows:

    Similar access is provided for unions and the data members of C++ classes.
    -C structures are created using a function new_Point(), but for C++ classes are created using just the name Point(). +C structures can be created using a function new_Point(), and both C structures and C++ classes can be created using just the name Point().

    If you print out the value of p in the above example, you will see something like this: @@ -679,9 +732,9 @@ public: In Lua, the static members can be accessed as follows:

    -> example.Spam_foo()            -- calling Spam::foo()
    -> a=example.Spam_bar            -- reading Spam::bar 
    -> example.Spam_bar=b            -- writing to Spam::bar
    +> example.Spam.foo()            -- calling Spam::foo()
    +> a=example.Spam.bar            -- reading Spam::bar 
    +> example.Spam.bar=b            -- writing to Spam::bar
     

    It is not (currently) possible to access static members of an instance: @@ -692,6 +745,13 @@ It is not (currently) possible to access static members of an instance: -- does NOT work

    +

    Backward compatibility

    +

    If -swig3 option is not given, then backward compatible names are generated in addition to ordinary ones:

    +
    +> example.Spam_foo()            -- calling Spam::foo()
    +> a=example.Spam_bar            -- reading Spam::bar 
    +> example.Spam_bar=b            -- writing to Spam::bar
    +

    26.3.8 C++ inheritance

    @@ -1256,6 +1316,143 @@ and the "Exception handling add exception specification to functions or globally (respectively).

    +

    26.3.17 Namespaces

    +

    +Since SWIG 3.0 C++ namespaces are supported. You can enabled handling namespaces with %nspace feature. Everything below is valid only after you enabled %nspace. +

    +

    Namespaces are mapped into lua tables. Each of those tables contains names that were defined within appropriate namespace. Namespaces structure (a.k.a nested namespaces is preserved). Consider the following C++ code: +

    +
    %module example
    +%nspace MyWorld::Nested::Dweller;
    +%nspace MyWorld::World;
    +/* and so on */
    +int module_function() { return 7;}
    +int module_variable; // = 9
    +namespace MyWorld {
    +  class World {
    +  public:
    +    int create_world() { return 17;}
    +    const int world_max_count = 9;
    +  };
    +  namespace Nested {
    +    class Dweller {
    +      enum Gender {MALE, FEMALE;
    +      static int populate_cave() { return 19; }
    +      int create_cave() { return 13;}
    +      int food_count; // = 11
    +    }
    +  }
    +}
    +
    +Now, in Lua it could be used like this: +
    +> example.module_function()
    +7
    +> print(example.module_variable)
    +8
    +> print(example.MyWorld.World():create_world())
    +17
    +> print(example.MyWorld.World.world_max_count)
    +9
    +> print(example.MyWordl.Nested.Dweller.MALE)
    +0
    +> print(example.MyWordl.Nested.Dweller().food_count)
    +11
    +>
    +
    +

    Backward compatibility

    +

    +If SWIG is running in backward compatible way, i.e. without -swig3 option, then additional old-style names are generated(notice the underscore): +

    +
    +9
    +> print(example.MyWorld.Nested.Dweller_MALE)
    +0
    +> print(example.MyWorld.Nested.Dweller_populate_cave())
    +11
    +>
    +
    +

    Backward compatibility

    +

    Names

    +

    If SWIG is launched without -swig3 option, then it enters backward-compatible mode. While in this mode, it tries +to generate additional names for static functions, class static constants and class enums. +Those names are in a form $classname_$symbolname and are added to the scope surrounding the class. +If %nspace is enabled, then class namespace is taken as scope. If there is no namespace, or %nspace is disabled, +then module is considered a class namespace.

    +

    Consider the following C++ code

    +
    %module example
    +%nspace MyWorld::Test;
    +namespace MyWorld {
    +class Test {
    +  public:
    +  enum { TEST1 = 10, TEST2 }
    +  static const int ICONST = 12;
    +};
    +class Test2 {
    +  public:
    +  enum { TEST3 = 20, TEST4 }
    +  static const int ICONST2 = 23;
    +}
    +
    +

    When in backward compatible mode, in addition to usual names, the following ones will be generated (notice the underscore):

    +
    +9
    +> print(example.MyWorld.Test_TEST1) -- Test has %nspace enabled
    +10
    +> print(example.MyWorld.Test_ICONST) -- Test has %nspace enabled
    +12
    +> print(example.Test2_TEST3) -- Test2 doesn't have %nspace enabled
    +20
    +> print(example.Test2_ICONST2) -- Test2 doesn't have %nspace enabled
    +23
    +>
    +
    +

    There is a slight difference with enums when in C mode. As per C standard, enums from C structures are exported to +surrounding scope without any prefixing. Pretending that Test2 is a struct, not class, that would be:

    +
    +> print(example.TEST3) -- NOT Test2_TEST3
    +20
    +>
    +
    + +

    Inheritance

    +

    There internal organization of inheritance has changed. +Consider the following C++ code:

    +
    %module example
    +class Base {
    +  public:
    +  int base_func()
    +};
    +class Derived : public Base {
    +  public:
    +  int derived_func()
    +}
    +
    +

    Lets assume for a moment that class member functions are stored in .fn table. Previously, when classes +were exported to Lua during module initialization, for every derived class all service tables ST(i.e. ".fn") +were squashed and added to corresponding derived class ST: Everything from .fn table of class Base +was copied to .fn table of class Derived and so on. This was a recursive procedure, so in the end the whole +inheritance tree of derived class was squashed into derived class.

    +

    That means that any changes done to class Base after module initialization wouldn't affect class Derived:

    +
    +base = example.Base()
    +der = example.Derived()
    +> print(base.base_func)
    +function: 0x1367940
    +> getmetatable(base)[".fn"].new_func = function (x) return x -- Adding new function to class Base (to class, not to an instance!)
    +> print(base.new_func) -- Checking this function
    +function
    +> print(der.new_func) -- Wouldn't work. Derived doesn't check Base any more.
    +nil
    +>
    +
    +

    This has been fixed. Now Derived store a list of it's bases and if some symbol is not found in it's own service tables +then its bases are searched for it. +

    +> print(der.new_func) -- Now it works
    +function
    +>
    +

    26.4 Typemaps

    From 00f59ac497c5a6e4fa4a3b3eddcfdbc727f13771 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Wed, 25 Dec 2013 18:24:17 +0400 Subject: [PATCH 1000/1160] Small documenation fixes --- Doc/Manual/Lua.html | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index b890a7138..31c9dd564 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -70,7 +70,6 @@ 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++). It's 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

    -TODO: Fix if elua disabled eLua stands for Embedded Lua (can be thought of as a flavor of Lua) and offers the full implementation of the Lua programming language to the embedded world, extending it with specific features for efficient and portable software embedded development. eLua runs on smaller devices like microcontrollers and provides the full features of the regular Lua desktop version. More information on eLua can be found here: http://www.eluaproject.net

    @@ -78,8 +77,7 @@ eLua stands for Embedded Lua (can be thought of as a flavor of Lua) and offers t

    -TODO: Fix if elua disabled -The current SWIG implementation is designed to work with Lua 5.0.x, 5.1.x and 5.2.x. It should work with later versions of Lua, but certainly not with Lua 4.0 due to substantial API changes. It is possible to either static link or dynamic link a Lua module into the interpreter (normally Lua static links its libraries, as dynamic linking is not available on all platforms). SWIG also supports eLua and works with eLua 0.8. SWIG generated code for eLua has been tested on Stellaris ARM Cortex-M3 LM3S and Infineon TriCore. +The current SWIG implementation is designed to work with Lua 5.0.x, 5.1.x and 5.2.x. It should work with later versions of Lua, but certainly not with Lua 4.0 due to substantial API changes. It is possible to either static link or dynamic link a Lua module into the interpreter (normally Lua static links its libraries, as dynamic linking is not available on all platforms). SWIG also has support for eLua starting from eLua 0.8. Due to substantial changes between SWIG 2.x and SWIG 3.0 and unavailability of testing platform, eLua status was downgraded to 'experimental'.

    26.2 Running SWIG

    @@ -165,6 +163,10 @@ swig -lua -help -swig3 Disable backward compatibility: old-style binding names generations and a few other things. Explanations are included into appropriate sections. + + -squash-bases + Squashes symbols from all inheritance tree of a given class into itself. Emulates pre-SWIG3.0 inheritance. Insignificantly speeds things up, but increases memory consumption. +

    26.2.2 Compiling and Linking and Interpreter

    @@ -1320,7 +1322,7 @@ add exception specification to functions or globally (respectively).

    Since SWIG 3.0 C++ namespaces are supported. You can enabled handling namespaces with %nspace feature. Everything below is valid only after you enabled %nspace.

    -

    Namespaces are mapped into lua tables. Each of those tables contains names that were defined within appropriate namespace. Namespaces structure (a.k.a nested namespaces is preserved). Consider the following C++ code: +

    Namespaces are mapped into lua tables. Each of those tables contains names that were defined within appropriate namespace. Namespaces structure (a.k.a nested namespaces) is preserved. Consider the following C++ code:

    %module example
     %nspace MyWorld::Nested::Dweller;
    @@ -1416,7 +1418,7 @@ surrounding scope without any prefixing. Pretending that Test2 is a struct, not
     

    Inheritance

    -

    There internal organization of inheritance has changed. +

    The internal organization of inheritance has changed. Consider the following C++ code:

    %module example
     class Base {
    @@ -1446,8 +1448,8 @@ function
     nil
     >
     
    -

    This has been fixed. Now Derived store a list of it's bases and if some symbol is not found in it's own service tables -then its bases are searched for it. +

    This behaviour was changed. Now unless -squash-bases option is provided, Derived store a list of it's bases and if some symbol is not found in it's own service tables +then its bases are searched for it. Option -squash-bases will effectively return old behaviour.

     > print(der.new_func) -- Now it works
     function
    
    From 4eef510e33e2381c515af199127842ff84d6e8f1 Mon Sep 17 00:00:00 2001
    From: Artem Serebriyskiy 
    Date: Thu, 26 Dec 2013 16:32:45 +0400
    Subject: [PATCH 1001/1160] Rename methods to make it clear what 'symbols
     table' they operate on.
    
    ---
     Source/Modules/lang.cxx  | 18 +++++++++---------
     Source/Modules/lua.cxx   | 12 ++++++------
     Source/Modules/swigmod.h |  6 +++---
     3 files changed, 18 insertions(+), 18 deletions(-)
    
    diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx
    index 92781c043..7933d5a49 100644
    --- a/Source/Modules/lang.cxx
    +++ b/Source/Modules/lang.cxx
    @@ -319,7 +319,7 @@ overloading(0),
     multiinput(0),
     cplus_runtime(0),
     directors(0) {
    -  addScope(""); // create top level/global symbol table scope
    +  symbolAddScope(""); // create top level/global symbol table scope
       argc_template_string = NewString("argc");
       argv_template_string = NewString("argv[%d]");
     
    @@ -3060,7 +3060,7 @@ int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr
       //Printf( stdout, "addSymbol: %s %s\n", s, scope );
       Hash *symbols = Getattr(symtabs, scope ? scope : "");
       if (!symbols) {
    -    symbols = addScope(scope);
    +    symbols = symbolAddScope(scope);
       } else {
         Node *c = Getattr(symbols, s);
         if (c && (c != n)) {
    @@ -3077,15 +3077,15 @@ int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr
     }
     
     /* -----------------------------------------------------------------------------
    - * Lanugage::addScope( const_String_or_char_ptr scopeName )
    + * Lanugage::symbolAddScope( const_String_or_char_ptr scopeName )
      *
      * Creates a scope (symbols Hash) for given name. This method is auxilary,
      * you don't have to call it - addSymbols will lazily create scopes automatically.
      * If scope with given name already exists, then do nothing.
      * Returns newly created (or already existing) scope.
      * ----------------------------------------------------------------------------- */
    -Hash* Language::addScope(const_String_or_char_ptr scope) {
    -  Hash *symbols = scopeLookup(scope);
    +Hash* Language::symbolAddScope(const_String_or_char_ptr scope) {
    +  Hash *symbols = symbolScopeLookup(scope);
       if(!symbols) {
         // Order in which to following parts are executed is important. In Lanugage
         // constructor addScope("") is called to create a top level scope itself.
    @@ -3108,18 +3108,18 @@ Hash* Language::addScope(const_String_or_char_ptr scope) {
     }
     
     /* -----------------------------------------------------------------------------
    - * Lanugage::scopeLookup( const_String_or_char_ptr scope )
    + * Lanugage::symbolSscopeLookup( const_String_or_char_ptr scope )
      *
      * Lookup and returns a symtable (hash) representing given scope. Hash contains
      * all symbols in this scope.
      * ----------------------------------------------------------------------------- */
    -Hash* Language::scopeLookup( const_String_or_char_ptr scope ) {
    +Hash* Language::symbolScopeLookup( const_String_or_char_ptr scope ) {
       Hash *symbols = Getattr(symtabs, scope ? scope : "");
       return symbols;
     }
     
     /* -----------------------------------------------------------------------------
    - * Lanugage::scopeSymbolLookup( const_String_or_char_ptr scope )
    + * Lanugage::symbolScopeSymbolLookup( const_String_or_char_ptr scope )
      *
      * For every scope there is a special pseudo-symbol in the top scope (""). It
      * exists solely to detect name clashes. This pseudo symbol may contain a few properties,
    @@ -3133,7 +3133,7 @@ Hash* Language::scopeLookup( const_String_or_char_ptr scope ) {
      * There is no difference from symbolLookup() method except for signature
      * and return type.
      * ----------------------------------------------------------------------------- */
    -Hash* Language::scopeSymbolLookup( const_String_or_char_ptr scope )
    +Hash* Language::symbolScopePseudoSymbolLookup( const_String_or_char_ptr scope )
     {
       /* Getting top scope */
       const_String_or_char_ptr top_scope = "";
    diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx
    index 6317f0910..b60490918 100644
    --- a/Source/Modules/lua.cxx
    +++ b/Source/Modules/lua.cxx
    @@ -1669,7 +1669,7 @@ public:
        * A small helper to hide impelementation of how CArrays hashes are stored
        * ---------------------------------------------------------------------------- */
       Hash *rawGetCArraysHash(const_String_or_char_ptr name) {
    -    Hash *scope = scopeLookup( name ? name : "" );
    +    Hash *scope = symbolScopeLookup( name ? name : "" );
         if(!scope)
           return 0;
     
    @@ -1694,10 +1694,10 @@ public:
        * only at first call (a.k.a when nspace is created).
        * ---------------------------------------------------------------------------- */
       Hash *getCArraysHash(String *nspace, bool reg = true) {
    -    Hash *scope = scopeLookup(nspace ? nspace : "");
    +    Hash *scope = symbolScopeLookup(nspace ? nspace : "");
         if(!scope) {
    -      addScope( nspace ? nspace : "" );
    -      scope = scopeLookup(nspace ? nspace : "");
    +      symbolAddScope( nspace ? nspace : "" );
    +      scope = symbolScopeLookup(nspace ? nspace : "");
           assert(scope);
         }
         Hash *carrays_hash = Getattr(scope, "lua:cdata");
    @@ -1979,14 +1979,14 @@ public:
        * ----------------------------------------------------------------------------- */
       void closeNamespaces(File *dataOutput) {
         // Special handling for empty module.
    -    if (scopeLookup("") == 0 || rawGetCArraysHash("") == 0) {
    +    if (symbolScopeLookup("") == 0 || rawGetCArraysHash("") == 0) {
           // Module is empty. Create hash for global scope in order to have swig__Module
           // variable in resulting file
           getCArraysHash(0);
         }
         // Because we cant access directly 'symtabs', instead we access
         // top-level scope and look on all scope pseudo-symbols in it.
    -    Hash *top_scope = scopeLookup("");
    +    Hash *top_scope = symbolScopeLookup("");
         assert(top_scope);
         Iterator ki = First(top_scope);
         List *to_close = NewList();
    diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h
    index 40064ea38..afffebef9 100644
    --- a/Source/Modules/swigmod.h
    +++ b/Source/Modules/swigmod.h
    @@ -216,9 +216,9 @@ public:
       virtual int addSymbol(const String *s, const Node *n, const_String_or_char_ptr scope = "");	/* Add symbol        */
       virtual void dumpSymbols();
       virtual Node *symbolLookup(String *s, const_String_or_char_ptr scope = ""); /* Symbol lookup */
    -  virtual Hash* addScope(const_String_or_char_ptr scope);
    -  virtual Hash* scopeLookup( const_String_or_char_ptr scope );
    -  virtual Hash* scopeSymbolLookup( const_String_or_char_ptr scope );
    +  virtual Hash* symbolAddScope(const_String_or_char_ptr scope);
    +  virtual Hash* symbolScopeLookup( const_String_or_char_ptr scope );
    +  virtual Hash* symbolScopePseudoSymbolLookup( const_String_or_char_ptr scope );
       virtual Node *classLookup(const SwigType *s) const; /* Class lookup      */
       virtual Node *enumLookup(SwigType *s);	/* Enum lookup       */
       virtual int abstractClassTest(Node *n);	/* Is class really abstract? */
    
    From dcf121f534a5c06d5ccc47bc0b04de982c1df3b2 Mon Sep 17 00:00:00 2001
    From: Olly Betts 
    Date: Wed, 19 Feb 2014 22:35:45 +1300
    Subject: [PATCH 1002/1160] Make Lib/ocaml/swigp4.ml a non-generated file.
    
    We used to have configure substitute values into it, but that's not been
    the case for just over 3 years, since patch #3151788 was applied.
    ---
     .gitignore                            |  1 -
     Lib/ocaml/{swigp4.ml.in => swigp4.ml} |  0
     Makefile.in                           |  2 +-
     configure.ac                          | 57 +++++++++++++--------------
     4 files changed, 29 insertions(+), 31 deletions(-)
     rename Lib/ocaml/{swigp4.ml.in => swigp4.ml} (100%)
    
    diff --git a/.gitignore b/.gitignore
    index eb3aa012c..67a6ee936 100644
    --- a/.gitignore
    +++ b/.gitignore
    @@ -67,7 +67,6 @@ Examples/Makefile
     Examples/guile/Makefile
     Examples/test-suite/*/Makefile
     Examples/xml/Makefile
    -Lib/ocaml/swigp4.ml
     /Makefile
     Source/Include/stamp-h1
     Source/Include/swigconfig.h
    diff --git a/Lib/ocaml/swigp4.ml.in b/Lib/ocaml/swigp4.ml
    similarity index 100%
    rename from Lib/ocaml/swigp4.ml.in
    rename to Lib/ocaml/swigp4.ml
    diff --git a/Makefile.in b/Makefile.in
    index ea7814242..4407d1316 100644
    --- a/Makefile.in
    +++ b/Makefile.in
    @@ -391,7 +391,7 @@ clean-ccache:
     # 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-DEAD = config.status config.log config.cache swig.spec Makefile mkmf.log libtool preinst-swig
     
     distclean-helper: distclean-test-suite distclean-examples distclean-dead
     
    diff --git a/configure.ac b/configure.ac
    index bb62068ae..be4e6e3c9 100644
    --- a/configure.ac
    +++ b/configure.ac
    @@ -2409,35 +2409,34 @@ case $build in
     esac
     AC_DEFINE_UNQUOTED(SWIG_LIB_WIN_UNIX, ["$SWIG_LIB_WIN_UNIX"], [Directory for SWIG system-independent libraries (Unix install on native Windows)])
     
    -AC_CONFIG_FILES([			        \
    -    Makefile				        \
    -    swig.spec				        \
    -    Source/Makefile			        \
    -    Examples/Makefile			        \
    -    Examples/xml/Makefile		        \
    -    Examples/test-suite/errors/Makefile		\
    -    Examples/test-suite/chicken/Makefile	\
    -    Examples/test-suite/csharp/Makefile	        \
    -    Examples/test-suite/d/Makefile	        \
    -    Examples/test-suite/guile/Makefile	        \
    -    Examples/test-suite/java/Makefile	        \
    -    Examples/test-suite/mzscheme/Makefile	\
    -    Examples/test-suite/ocaml/Makefile	        \
    -    Examples/test-suite/octave/Makefile	        \
    -    Examples/test-suite/perl5/Makefile	        \
    -    Examples/test-suite/php/Makefile	        \
    -    Examples/test-suite/pike/Makefile	        \
    -    Examples/test-suite/python/Makefile	        \
    -    Examples/test-suite/ruby/Makefile	        \
    -    Examples/test-suite/tcl/Makefile	        \
    -    Examples/test-suite/lua/Makefile	        \
    -    Examples/test-suite/allegrocl/Makefile	\
    -    Examples/test-suite/clisp/Makefile		\
    -    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([
    +    Makefile
    +    swig.spec
    +    Source/Makefile
    +    Examples/Makefile
    +    Examples/xml/Makefile
    +    Examples/test-suite/errors/Makefile
    +    Examples/test-suite/chicken/Makefile
    +    Examples/test-suite/csharp/Makefile
    +    Examples/test-suite/d/Makefile
    +    Examples/test-suite/guile/Makefile
    +    Examples/test-suite/java/Makefile
    +    Examples/test-suite/mzscheme/Makefile
    +    Examples/test-suite/ocaml/Makefile
    +    Examples/test-suite/octave/Makefile
    +    Examples/test-suite/perl5/Makefile
    +    Examples/test-suite/php/Makefile
    +    Examples/test-suite/pike/Makefile
    +    Examples/test-suite/python/Makefile
    +    Examples/test-suite/ruby/Makefile
    +    Examples/test-suite/tcl/Makefile
    +    Examples/test-suite/lua/Makefile
    +    Examples/test-suite/allegrocl/Makefile
    +    Examples/test-suite/clisp/Makefile
    +    Examples/test-suite/cffi/Makefile
    +    Examples/test-suite/uffi/Makefile
    +    Examples/test-suite/r/Makefile
    +    Examples/test-suite/go/Makefile
     ])
     AC_CONFIG_FILES([preinst-swig], [chmod +x preinst-swig])
     AC_CONFIG_FILES([CCache/ccache_swig_config.h])
    
    From 1097fc99ff7463c4535e84f50706a292e94147e0 Mon Sep 17 00:00:00 2001
    From: Olly Betts 
    Date: Wed, 19 Feb 2014 23:04:40 +1300
    Subject: [PATCH 1003/1160] [Lua] Add keyword warnings for Lua keywords and
     Basic Functions.
    
    ---
     CHANGES.current                               |  3 +
     .../test-suite/lua/keyword_rename_runme.lua   | 10 +--
     Lib/allkw.swg                                 |  1 +
     Lib/lua/lua.swg                               |  3 +-
     Lib/lua/luakw.swg                             | 67 +++++++++++++++++++
     5 files changed, 76 insertions(+), 8 deletions(-)
     create mode 100644 Lib/lua/luakw.swg
    
    diff --git a/CHANGES.current b/CHANGES.current
    index 6595c248e..897ff53c4 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
     Version 3.0.0 (in progress)
     ============================
     
    +2014-02-19: olly
    +	    [Lua] Add keyword warnings for Lua keywords and Basic Functions.
    +
     2014-02-19: olly
     	    -Wallkw now includes keywords for all languages with keyword
     	    warnings (previously Go and R were missing).
    diff --git a/Examples/test-suite/lua/keyword_rename_runme.lua b/Examples/test-suite/lua/keyword_rename_runme.lua
    index a9dea466a..1fe5b5756 100644
    --- a/Examples/test-suite/lua/keyword_rename_runme.lua
    +++ b/Examples/test-suite/lua/keyword_rename_runme.lua
    @@ -7,10 +7,6 @@ local env = _ENV -- Lua 5.2
     if not env then env = getfenv () end -- Lua 5.1
     setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
     
    -
    --- assert(kn.end(5) == 5) -- Curretly  SWIG/Lua doesn't rename keywords
    --- assert(kn.nil(7) == 7)
    -
    --- But you can always access wrongly named members using string constants
    -assert(kn["end"](5) == 5)
    -assert(kn["nil"](7) == 7)
    +-- Check renaming of Lua keywords
    +assert(kn.c_end(5) == 5)
    +assert(kn.c_nil(7) == 7)
    diff --git a/Lib/allkw.swg b/Lib/allkw.swg
    index 99c2969e4..563190e19 100644
    --- a/Lib/allkw.swg
    +++ b/Lib/allkw.swg
    @@ -21,6 +21,7 @@
     %include 
     %include 
     %include 
    +%include 
     %include 
     %include 
     %include 
    diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg
    index 80c4c04c1..ee83d11b7 100644
    --- a/Lib/lua/lua.swg
    +++ b/Lib/lua/lua.swg
    @@ -9,8 +9,9 @@
      *                          includes
      * ----------------------------------------------------------------------------- */
     
    -%include           /* The typemaps */
    +%include          /* The typemaps */
     %include           /* The runtime stuff */
    +%include                /* Warnings for Lua keywords */
     
     //%include 
     /* -----------------------------------------------------------------------------
    diff --git a/Lib/lua/luakw.swg b/Lib/lua/luakw.swg
    new file mode 100644
    index 000000000..fc2f92bfe
    --- /dev/null
    +++ b/Lib/lua/luakw.swg
    @@ -0,0 +1,67 @@
    +/*
    +  Warnings for Lua keywords, built-in names and bad names.
    +*/
    +
    +#define LUAKW(x) %keywordwarn("'" `x` "' is a Lua keyword, renaming to 'c_" `x` "'", rename="c_%s")  `x`
    +#define LUABN(x) %namewarn(%warningmsg(SWIGWARN_PARSE_BUILTIN_NAME, "'" `x` "' conflicts with a basic function in Lua"), %$not %$ismember)  `x`
    +
    +/*
    +  Warnings for Lua keywords 
    +  http://www.lua.org/manual/5.2/manual.html#3.1
    +*/
    +
    +LUAKW(and);
    +LUAKW(break);
    +LUAKW(do);
    +LUAKW(else);
    +LUAKW(elseif);
    +LUAKW(end);
    +LUAKW(false);
    +LUAKW(for);
    +LUAKW(function);
    +LUAKW(goto);
    +LUAKW(if);
    +LUAKW(in);
    +LUAKW(local);
    +LUAKW(nil);
    +LUAKW(not);
    +LUAKW(or);
    +LUAKW(repeat);
    +LUAKW(return);
    +LUAKW(then);
    +LUAKW(true);
    +LUAKW(until);
    +LUAKW(while);
    +
    +/*
    +  Basic functions
    +  http://www.lua.org/manual/5.2/manual.html#6.1
    +*/ 
    +
    +LUABN(assert);
    +LUABN(collectgarbage);
    +LUABN(dofile);
    +LUABN(error);
    +LUABN(_G); // Not actually a function
    +LUABN(getmetatable);
    +LUABN(ipairs);
    +LUABN(load);
    +LUABN(loadfile);
    +LUABN(next);
    +LUABN(pairs);
    +LUABN(pcall);
    +LUABN(print);
    +LUABN(rawequal);
    +LUABN(rawget);
    +LUABN(rawlen);
    +LUABN(rawset);
    +LUABN(select);
    +LUABN(setmetatable);
    +LUABN(tonumber);
    +LUABN(tostring);
    +LUABN(type);
    +LUABN(_VERSION); // Not actually a function
    +LUABN(xpcall);
    +
    +#undef LUABN
    +#undef LUAKW
    
    From 66b22e617820e6305b5176f828546e78ebaec907 Mon Sep 17 00:00:00 2001
    From: Olly Betts 
    Date: Wed, 19 Feb 2014 23:05:15 +1300
    Subject: [PATCH 1004/1160] Improve ignore pattern for vim swap files to not
     match SWIG *.swg files
    
    ---
     .gitignore | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/.gitignore b/.gitignore
    index 67a6ee936..48826d914 100644
    --- a/.gitignore
    +++ b/.gitignore
    @@ -3,7 +3,7 @@
     *.class
     
     # Editor files and various other junk
    -*.sw?
    +.*.sw?
     *.bak
     
     # Local PCRE
    
    From 2767f2a55e2453781031f4bab1f8fd67c9f28f7a Mon Sep 17 00:00:00 2001
    From: Artem Serebriyskiy 
    Date: Wed, 19 Feb 2014 14:05:29 +0400
    Subject: [PATCH 1005/1160] Fixes to module options
    
    ---
     Source/Modules/lua.cxx | 28 ++++++++--------------------
     1 file changed, 8 insertions(+), 20 deletions(-)
    
    diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx
    index b60490918..04241ec21 100644
    --- a/Source/Modules/lua.cxx
    +++ b/Source/Modules/lua.cxx
    @@ -80,23 +80,22 @@ void display_mapping(DOH *d) {
     NEW LANGUAGE NOTE:END ************************************************/
     static const char *usage = (char *) "\
     Lua Options (available with -lua)\n\
    -     -elua [NUM]     - Generates LTR compatible wrappers for smaller devices running elua\n\
    -                       Optional NUM is default value for MIN_OPT_LEVEL\n\
    -     -eluac  [NUM]   - LTR compatible wrappers in \"crass compress\" mode for elua\n\
    -                       Optional NUM is default value for MIN_OPT_LEVEL\n\
    +     -drop-old-scheme\n\
    +                     - Disable support for old-style bindings name generation, some\n\
    +                       old-style members scheme etc.\n\
    +     -elua           - Generates LTR compatible wrappers for smaller devices running elua\n\
    +     -eluac          - LTR compatible wrappers in \"crass compress\" mode for elua\n\
    +     -elua-emulate   - Emulates behaviour of eLua. Usefull only for testing.\n\
    +                       Incompatible with -elua/-eluac options.\n\
          -nomoduleglobal - Do not register the module name as a global variable \n\
                            but return the module table from calls to require.\n\
    -     -swig3          - Disable support for old-style bindings name generation.\n\
          -squash-bases   - Squashes symbols from all inheritance tree of a given class\n\
                            into itself. Emulates pre-SWIG3.0 inheritance. Insignificantly\n\
                            speeds things up, but increases memory consumption.\n\
    -     -elua-emulate   - Emulates behaviour of eLua. Usefull only for testing.\n\
    -                       Incompatible with -elua/-eluac options.\n\
     \n";
     
     static int nomoduleglobal = 0;
     static int elua_ltr = 0;
    -static int elua_opt_lvl = 2;
     static int eluac_ltr = 0;
     static int elua_emulate = 0;
     static int squash_bases = 0;
    @@ -221,18 +220,10 @@ public:
     	} else if (strcmp(argv[i], "-elua") == 0) {
     	  elua_ltr = 1;
     	  Swig_mark_arg(i);
    -	  if (strToInt(argv[i + 1], elua_opt_lvl)) {
    -	    Swig_mark_arg(i + 1);
    -	    i++;
    -	  }
     	} else if (strcmp(argv[i], "-eluac") == 0) {
     	  eluac_ltr = 1;
     	  Swig_mark_arg(i);
    -	  if (strToInt(argv[i + 1], elua_opt_lvl)) {
    -	    Swig_mark_arg(i + 1);
    -	    i++;
    -	  }
    -	} else if (strcmp(argv[i], "-swig3") == 0) {
    +	} else if (strcmp(argv[i], "-drop-old-scheme") == 0) {
     	  Swig_mark_arg(i);
     	  api_level = 3;
     	} else if (strcmp(argv[i], "-squash-bases") == 0) {
    @@ -340,9 +331,6 @@ public:
     
         emitLuaFlavor(f_runtime);
     
    -    if (elua_ltr || eluac_ltr)
    -      Printf(f_runtime, "#ifndef MIN_OPT_LEVEL\n" "#define MIN_OPT_LEVEL %d\n" "#endif\n", elua_opt_lvl);
    -
         if (nomoduleglobal) {
           Printf(f_runtime, "#define SWIG_LUA_NO_MODULE_GLOBAL\n");
         } else {
    
    From b30aa53709c138913bca9cb68096540f0a101b02 Mon Sep 17 00:00:00 2001
    From: Artem Serebriyskiy 
    Date: Wed, 19 Feb 2014 16:02:49 +0400
    Subject: [PATCH 1006/1160] Removed class_parent_nspace
    
    ---
     Source/Modules/lua.cxx | 13 ++++---------
     1 file changed, 4 insertions(+), 9 deletions(-)
    
    diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx
    index 04241ec21..f521824a0 100644
    --- a/Source/Modules/lua.cxx
    +++ b/Source/Modules/lua.cxx
    @@ -127,7 +127,6 @@ private:
       String *class_symname;
       String *class_fq_symname;	// Fully qualified symname - NSpace + '.' + class_symname
       String *class_static_nspace;
    -  String *class_parent_nspace;
       String *constructor_name;
     
       // Many wrappers forward calls to each other, for example staticmembervariableHandler
    @@ -1039,7 +1038,7 @@ public:
           }
           n_v2 = Copy(n);
           //Printf( stdout, "target name v2: %s, symname v2 %s\n", target_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE
    -      if (!luaAddSymbol(iname_v2, n, class_parent_nspace)) {
    +      if (!luaAddSymbol(iname_v2, n, getNSpace())) {
     	Swig_restore(n);
     	return SWIG_ERROR;
           }
    @@ -1052,7 +1051,7 @@ public:
     	Replaceall(tm_v2, "$target", target_name_v2);
     	Replaceall(tm_v2, "$value", value);
     	Replaceall(tm_v2, "$nsname", nsname);
    -	registerConstant(class_parent_nspace, tm_v2);
    +	registerConstant(getNSpace(), tm_v2);
           } else {
     	tm_v2 = Swig_typemap_lookup("constcode", n_v2, name, 0);
     	if (!tm_v2) {
    @@ -1178,7 +1177,6 @@ public:
         assert(class_static_nspace == 0);
         assert(class_fq_symname == 0);
         assert(class_symname == 0);
    -    assert(class_parent_nspace == 0);
     
         current[NO_CPP] = false;
     
    @@ -1256,11 +1254,8 @@ public:
         /* There is no use for "classes" and "namespaces" arrays. Subclasses are not supported
          * by SWIG and namespaces couldn't be nested inside classes (C++ Standard)
          */
    -    class_parent_nspace = getNSpace();
         // Generate normal wrappers
         Language::classHandler(n);
    -    // Restore correct nspace
    -    class_parent_nspace = 0;
     
         SwigType_add_pointer(t);
     
    @@ -1528,7 +1523,7 @@ public:
           String *target_name = Getattr(n, "lua:name");
           String *compat_name = Swig_name_member(0, class_symname, target_name);
           Setattr(n, "lua:name", compat_name);
    -      registerMethod(class_parent_nspace, n);
    +      registerMethod(getNSpace(), n);
           Delete(compat_name);
           Swig_restore(n);
         }
    @@ -1568,7 +1563,7 @@ public:
     	//Printf( stdout, "Name %s, class %s, compt. name %s\n", target_name, class_symname, v2_name ); // TODO: REMOVE
     	if (!GetFlag(n, "wrappedasconstant")) {
     	  Setattr(n, "lua:name", v2_name);
    -	  registerVariable(class_parent_nspace, n, "varget:wrap:name", "varset:wrap:name");
    +	  registerVariable(getNSpace(), n, "varget:wrap:name", "varset:wrap:name");
     	}
     	// If static member variable was wrapped as constant, then
     	// constant wrapper has already performed all actions
    
    From fe91d6449f33a57d0168fcbb50a0d5ceeac014a0 Mon Sep 17 00:00:00 2001
    From: Curtis Dunham 
    Date: Wed, 19 Feb 2014 11:58:27 -0600
    Subject: [PATCH 1007/1160] Remove register storage class declarations
    
    They're unnecessary, anacronistic, deprecated in modern
    standards, generally ignored, useless, and (most importantly)
    clang complains about them.
    ---
     Lib/csharp/csharp.swg             | 14 +++++++-------
     Lib/d/dmemberfunctionpointers.swg | 14 +++++++-------
     Lib/java/java.swg                 | 14 +++++++-------
     Lib/python/pyrun.swg              |  6 +++---
     Lib/swigrun.swg                   | 24 ++++++++++++------------
     5 files changed, 36 insertions(+), 36 deletions(-)
    
    diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg
    index 70e9fd4b4..94a0771ba 100644
    --- a/Lib/csharp/csharp.swg
    +++ b/Lib/csharp/csharp.swg
    @@ -35,10 +35,10 @@ using global::System.Runtime.InteropServices;
     /* 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;
    +  const unsigned char *u = (unsigned char *) ptr;
    +  const unsigned char *eu =  u + sz;
       for (; u != eu; ++u) {
    -    register unsigned char uu = *u;
    +    unsigned char uu = *u;
         *(c++) = hex[(uu & 0xf0) >> 4];
         *(c++) = hex[uu & 0xf];
       }
    @@ -49,11 +49,11 @@ SWIGINTERN char * SWIG_PackData(char *c, void *ptr, size_t sz) {
     %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;
    +  unsigned char *u = (unsigned char *) ptr;
    +  const unsigned char *eu = u + sz;
       for (; u != eu; ++u) {
    -    register char d = *(c++);
    -    register unsigned char uu;
    +    char d = *(c++);
    +    unsigned char uu;
         if ((d >= '0') && (d <= '9'))
           uu = ((d - '0') << 4);
         else if ((d >= 'a') && (d <= 'f'))
    diff --git a/Lib/d/dmemberfunctionpointers.swg b/Lib/d/dmemberfunctionpointers.swg
    index c33ff3840..c63eca23e 100644
    --- a/Lib/d/dmemberfunctionpointers.swg
    +++ b/Lib/d/dmemberfunctionpointers.swg
    @@ -53,10 +53,10 @@
     /* 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;
    +  const unsigned char *u = (unsigned char *) ptr;
    +  const unsigned char *eu =  u + sz;
       for (; u != eu; ++u) {
    -    register unsigned char uu = *u;
    +    unsigned char uu = *u;
         *(c++) = hex[(uu & 0xf0) >> 4];
         *(c++) = hex[uu & 0xf];
       }
    @@ -67,11 +67,11 @@ SWIGINTERN char * SWIG_PackData(char *c, void *ptr, size_t sz) {
     %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;
    +  unsigned char *u = (unsigned char *) ptr;
    +  const unsigned char *eu = u + sz;
       for (; u != eu; ++u) {
    -    register char d = *(c++);
    -    register unsigned char uu;
    +    char d = *(c++);
    +    unsigned char uu;
         if ((d >= '0') && (d <= '9'))
           uu = ((d - '0') << 4);
         else if ((d >= 'a') && (d <= 'f'))
    diff --git a/Lib/java/java.swg b/Lib/java/java.swg
    index 84d018083..3d4d83730 100644
    --- a/Lib/java/java.swg
    +++ b/Lib/java/java.swg
    @@ -16,10 +16,10 @@
     /* 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;
    +  const unsigned char *u = (unsigned char *) ptr;
    +  const unsigned char *eu =  u + sz;
       for (; u != eu; ++u) {
    -    register unsigned char uu = *u;
    +    unsigned char uu = *u;
         *(c++) = hex[(uu & 0xf0) >> 4];
         *(c++) = hex[uu & 0xf];
       }
    @@ -30,11 +30,11 @@ SWIGINTERN char * SWIG_PackData(char *c, void *ptr, size_t sz) {
     %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;
    +  unsigned char *u = (unsigned char *) ptr;
    +  const unsigned char *eu = u + sz;
       for (; u != eu; ++u) {
    -    register char d = *(c++);
    -    register unsigned char uu;
    +    char d = *(c++);
    +    unsigned char uu;
         if ((d >= '0') && (d <= '9'))
           uu = ((d - '0') << 4);
         else if ((d >= 'a') && (d <= 'f'))
    diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg
    index 53fc3a75b..a713486d1 100644
    --- a/Lib/python/pyrun.swg
    +++ b/Lib/python/pyrun.swg
    @@ -175,7 +175,7 @@ SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssi
       }  
       if (!PyTuple_Check(args)) {
         if (min <= 1 && max >= 1) {
    -      register int i;
    +      int i;
           objs[0] = args;
           for (i = 1; i < max; ++i) {
     	objs[i] = 0;
    @@ -185,7 +185,7 @@ SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssi
         PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple");
         return 0;
       } else {
    -    register Py_ssize_t l = PyTuple_GET_SIZE(args);
    +    Py_ssize_t l = PyTuple_GET_SIZE(args);
         if (l < min) {
           PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", 
     		   name, (min == max ? "" : "at least "), (int)min, (int)l);
    @@ -195,7 +195,7 @@ SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssi
     		   name, (min == max ? "" : "at most "), (int)max, (int)l);
           return 0;
         } else {
    -      register int i;
    +      int i;
           for (i = 0; i < l; ++i) {
     	objs[i] = PyTuple_GET_ITEM(args, i);
           }
    diff --git a/Lib/swigrun.swg b/Lib/swigrun.swg
    index 7066e670e..a314bf239 100644
    --- a/Lib/swigrun.swg
    +++ b/Lib/swigrun.swg
    @@ -404,14 +404,14 @@ SWIG_MangledTypeQueryModule(swig_module_info *start,
       swig_module_info *iter = start;
       do {
         if (iter->size) {
    -      register size_t l = 0;
    -      register size_t r = iter->size - 1;
    +      size_t l = 0;
    +      size_t r = iter->size - 1;
           do {
     	/* since l+r >= 0, we can (>> 1) instead (/ 2) */
    -	register size_t i = (l + r) >> 1;
    +	size_t i = (l + r) >> 1;
     	const char *iname = iter->types[i]->name;
     	if (iname) {
    -	  register int compare = strcmp(name, iname);
    +	  int compare = strcmp(name, iname);
     	  if (compare == 0) {
     	    return iter->types[i];
     	  } else if (compare < 0) {
    @@ -455,7 +455,7 @@ SWIG_TypeQueryModule(swig_module_info *start,
            of the str field (the human readable name) */
         swig_module_info *iter = start;
         do {
    -      register size_t i = 0;
    +      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];
    @@ -474,10 +474,10 @@ SWIG_TypeQueryModule(swig_module_info *start,
     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;
    +  const unsigned char *u = (unsigned char *) ptr;
    +  const unsigned char *eu =  u + sz;
       for (; u != eu; ++u) {
    -    register unsigned char uu = *u;
    +    unsigned char uu = *u;
         *(c++) = hex[(uu & 0xf0) >> 4];
         *(c++) = hex[uu & 0xf];
       }
    @@ -489,11 +489,11 @@ SWIG_PackData(char *c, void *ptr, size_t sz) {
     */
     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;
    +  unsigned char *u = (unsigned char *) ptr;
    +  const unsigned char *eu = u + sz;
       for (; u != eu; ++u) {
    -    register char d = *(c++);
    -    register unsigned char uu;
    +    char d = *(c++);
    +    unsigned char uu;
         if ((d >= '0') && (d <= '9'))
           uu = ((d - '0') << 4);
         else if ((d >= 'a') && (d <= 'f'))
    
    From de7ed84f77d2e27b5fdea1ad0774994df2720caa Mon Sep 17 00:00:00 2001
    From: Olly Betts 
    Date: Fri, 21 Feb 2014 08:09:58 +1300
    Subject: [PATCH 1008/1160] Recommend compiling with PIC consistently.
    
    While shared objects with non-PIC code work on some architectures
    (notably x86), unless code is always PIC on that arch (not true for x86)
    doing so requires runtime relocations, which prevents the object
    actually being shared, and means such segments can't be marked as
    read-only.
    ---
     Doc/Manual/Java.html      |  7 +++----
     Doc/Manual/Lua.html       |  4 ++--
     Doc/Manual/Perl5.html     |  4 ++--
     Doc/Manual/Ruby.html      | 20 ++++++++++++++------
     Doc/Manual/SWIGPlus.html  |  2 +-
     Doc/Manual/Scripting.html |  7 +------
     Doc/Manual/Tcl.html       | 12 ++++++------
     7 files changed, 29 insertions(+), 27 deletions(-)
    
    diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html
    index 08c80c83a..c1b42f605 100644
    --- a/Doc/Manual/Java.html
    +++ b/Doc/Manual/Java.html
    @@ -332,8 +332,8 @@ Assuming you have code you need to link to in a file called example.c,
     
     
     $ swig -java example.i
    -$ gcc -c example_wrap.c  -I/usr/java/include -I/usr/java/include/solaris
    -$ gcc -c example.c
    +$ gcc -fPIC -c example_wrap.c -I/usr/java/include -I/usr/java/include/solaris
    +$ gcc -fPIC -c example.c
     $ ld -G example_wrap.o example.o -o libexample.so
     
    @@ -493,8 +493,7 @@ compiler. For example:
     % swig -c++ -java example.i
     % g++ -c -fpic example.cxx
    -% g++ -c -fpic example_wrap.cxx -I/usr/java/j2sdk1.4.1/include -I/usr/java/
    -j2sdk1.4.1/include/linux
    +% g++ -c -fpic example_wrap.cxx -I/usr/java/j2sdk1.4.1/include -I/usr/java/j2sdk1.4.1/include/linux
     % g++ -shared example.o example_wrap.o -o libexample.so
     
    diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index 88d26f385..aab6a2ceb 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -240,8 +240,8 @@ Most, but not all platforms support the dynamic loading of modules (Windows &

     $ swig -lua example.i -o example_wrap.c
    -$ gcc -I/usr/include/lua -c example_wrap.c -o example_wrap.o
    -$ gcc -c example.c -o example.o
    +$ gcc -fPIC -I/usr/include/lua -c example_wrap.c -o example_wrap.o
    +$ gcc -fPIC -c example.c -o example.o
     $ gcc -shared -I/usr/include/lua -L/usr/lib/lua example_wrap.o example.o -o example.so
     

    diff --git a/Doc/Manual/Perl5.html b/Doc/Manual/Perl5.html index db8c0e602..9e577b08b 100644 --- a/Doc/Manual/Perl5.html +++ b/Doc/Manual/Perl5.html @@ -493,8 +493,8 @@ Solaris, you often need to add an extra library -lCrun like this:

     $ swig -c++ -perl example.i
    -$ CC -c example.cxx
    -$ CC -c example_wrap.cxx -I/usr/lib/perl/5.14/i386-linux/CORE
    +$ CC -Kpic -c example.cxx
    +$ CC -Kpic -c example_wrap.cxx -I/usr/lib/perl/5.14/i386-linux/CORE
     $ CC -shared example.o example_wrap.o -o example.so -lCrun
     
    diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index 301631a20..6ff98ca23 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -259,14 +259,22 @@ operating system would look something like this:

    $ swig -ruby example.i
    -$ gcc -c example.c
    -$ gcc -c example_wrap.c -I/usr/local/lib/ruby/1.6/i686-linux
    +$ gcc -O2 -fPIC -c example.c
    +$ gcc -O2 -fPIC -c example_wrap.c -I/usr/local/lib/ruby/1.6/i686-linux
     $ gcc -shared example.o example_wrap.o -o example.so
     
    -

    For other platforms it may be necessary to compile with the -fPIC -option to generate position-independent code. If in doubt, consult the +

    +The -fPIC option tells GCC to generate position-independent code (PIC) +which is required for most architectures (it's not vital on x86, but +still a good idea as it allows code pages from the library to be shared between +processes). Other compilers may need a different option specified instead of +-fPIC. +

    + +

    +If in doubt, consult the manual pages for your compiler and linker to determine the correct set of options. You might also check the SWIG Wiki for additional information.

    @@ -325,8 +333,8 @@ using the C++ compiler. For example:

     $ swig -c++ -ruby example.i
    -$ g++ -c example.cxx
    -$ g++ -c example_wrap.cxx -I/usr/local/lib/ruby/1.6/i686-linux
    +$ g++ -fPIC -c example.cxx
    +$ g++ -fPIC -c example_wrap.cxx -I/usr/local/lib/ruby/1.6/i686-linux
     $ g++ -shared example.o example_wrap.o -o example.so
     
    diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index e0e7dbcaf..aa02b2dee 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -216,7 +216,7 @@ to use the C++ compiler. For example:
     $ swig -c++ -tcl example.i
    -$ c++ -c example_wrap.cxx 
    +$ c++ -fPIC -c example_wrap.cxx 
     $ c++ example_wrap.o $(OBJS) -o example.so
     
    diff --git a/Doc/Manual/Scripting.html b/Doc/Manual/Scripting.html index 26a8dd017..c714fa0d7 100644 --- a/Doc/Manual/Scripting.html +++ b/Doc/Manual/Scripting.html @@ -368,17 +368,12 @@ for a few common platforms is shown below:

     # Build a shared library for Solaris
    -gcc -c example.c example_wrap.c -I/usr/local/include
    +gcc -fpic -c example.c example_wrap.c -I/usr/local/include
     ld -G example.o example_wrap.o -o example.so
     
     # Build a shared library for Linux
     gcc -fpic -c example.c example_wrap.c -I/usr/local/include
     gcc -shared example.o example_wrap.o -o example.so
    -
    -# Build a shared library for Irix
    -gcc -c example.c example_wrap.c -I/usr/local/include
    -ld -shared example.o example_wrap.o -o example.so
    -
     

    diff --git a/Doc/Manual/Tcl.html b/Doc/Manual/Tcl.html index e6b3b4a43..9b9cd7218 100644 --- a/Doc/Manual/Tcl.html +++ b/Doc/Manual/Tcl.html @@ -139,8 +139,8 @@ using commands like this (shown for Linux):

     $ swig -tcl example.i
    -$ gcc -c example.c
    -$ gcc -c example_wrap.c -I/usr/local/include
    +$ gcc -fPIC -c example.c
    +$ gcc -fPIC -c example_wrap.c -I/usr/local/include
     $ gcc -shared example.o example_wrap.o -o example.so
     
    @@ -374,8 +374,8 @@ compiler. For example:
     % swig -c++ -tcl example.i
    -% g++ -c example.cxx
    -% g++ -c example_wrap.cxx -I/usr/local/include
    +% g++ -fPIC -c example.cxx
    +% g++ -fPIC -c example_wrap.cxx -I/usr/local/include
     % g++ -shared example.o example_wrap.o -o example.so
     
    @@ -387,8 +387,8 @@ Solaris, you often need to add an extra library -lCrun like this:
     % swig -c++ -tcl example.i
    -% CC -c example.cxx
    -% CC -c example_wrap.cxx -I/usr/local/include
    +% CC -KPIC -c example.cxx
    +% CC -KPIC -c example_wrap.cxx -I/usr/local/include
     % CC -G example.o example_wrap.o -L/opt/SUNWspro/lib -o example.so -lCrun
     
    From c5bc0aa47283efc71a4ccab40334df9225b727ca Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 21 Feb 2014 08:14:24 +1300 Subject: [PATCH 1009/1160] Improve Examples/README --- Examples/README | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Examples/README b/Examples/README index 4dda3222d..eff0f2c98 100644 --- a/Examples/README +++ b/Examples/README @@ -1,24 +1,18 @@ SWIG Examples -The "perl5", "python", "tcl", "guile", "java", "mzscheme", "ruby", and -"chicken" directories contain a number of simple examples that are -primarily used for testing. +The subdirectories of "Examples" named after SWIG's language backends +contain a number of simple examples that are primarily used for testing. The file 'index.html' is the top of a hyperlinked document that contains information about all of the examples along with various notes related to each example. -The Examples directory is currently quite incomplete because it -is being reorganized. A more complete set of examples can be found -in the SWIG1.1p5 distribution (most of which should still work with -SWIG1.3). - Note: All of the examples rely upon the Makefile in this directory. You may need to edit it to reflect the configuration of your machine in case the configure script guesses incorrect settings. -*** Special note concering C++ *** +*** Special note concerning C++ *** The configure script is currently unable to handle all of the possible options for producing dynamically loadable C++ extensions. Here are From d55692c31e72f8a5f99bf78eb2f37f4ba52479a7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 21 Feb 2014 08:27:42 +0000 Subject: [PATCH 1010/1160] Fix warning suppression using %warnfilter for PHP reserved class names. The features need to be merged in before issuing a warning as %warnfilter is a %feature. --- CHANGES.current | 3 +++ Source/CParse/parser.y | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 897ff53c4..50f3decd1 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-02-21: wsfulton + [PHP] Fix warning suppression using %warnfilter for PHP reserved class names. + 2014-02-19: olly [Lua] Add keyword warnings for Lua keywords and Basic Functions. diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index dd8de45ff..1bd351560 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3488,6 +3488,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Setattr($$, "nested:outer", currentOuterClass); set_access_mode($$); } + Swig_features_get(Swig_cparse_features(), Namespaceprefix, Getattr($$, "name"), 0, $$); /* save yyrename to the class attribute, to be used later in add_symbols()*/ Setattr($$, "class_rename", make_name($$, $3, 0)); Setattr($$, "Classprefix", $3); @@ -3631,7 +3632,6 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Delattr($$, "Classprefix"); Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); - Swig_features_get(Swig_cparse_features(), Namespaceprefix, Getattr($$, "name"), 0, $$); if (cplus_mode == CPLUS_PRIVATE) { $$ = 0; /* skip private nested classes */ } else if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) { @@ -3712,6 +3712,8 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Setattr($$, "nested:outer", currentOuterClass); set_access_mode($$); } + Swig_features_get(Swig_cparse_features(), Namespaceprefix, 0, 0, $$); + /* save yyrename to the class attribute, to be used later in add_symbols()*/ Setattr($$, "class_rename", make_name($$,0,0)); if (strcmp($2,"class") == 0) { cplus_mode = CPLUS_PRIVATE; @@ -3745,7 +3747,6 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { /* Check for pure-abstract class */ Setattr($$,"abstracts", pure_abstracts($6)); n = $8; - Swig_features_get(Swig_cparse_features(), Namespaceprefix, 0, 0, $$); if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) { String *name = n ? Copy(Getattr(n, "name")) : 0; $$ = nested_forward_declaration($1, $2, 0, name, n); From 0d9a8721f46a7ab0ca168edb97c410566ead026d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 21 Feb 2014 19:02:14 +0000 Subject: [PATCH 1011/1160] Move some header file includes into fragments for UTL languages --- Lib/octave/octcontainer.swg | 4 +--- Lib/perl5/std_list.i | 4 ++-- Lib/perl5/std_map.i | 4 ++-- Lib/perl5/std_vector.i | 4 ++-- Lib/python/pycontainer.swg | 4 +--- Lib/ruby/rubycontainer.swg | 4 +--- Lib/std/_std_deque.i | 2 +- Lib/std/std_common.i | 6 ++---- Lib/std/std_except.i | 4 +--- Lib/std/std_map.i | 4 ++-- Lib/std/std_unordered_map.i | 4 ++-- Lib/tcl/std_map.i | 4 ++-- Lib/tcl/std_vector.i | 4 ++-- Lib/typemaps/exception.swg | 6 +++--- Lib/typemaps/fragments.swg | 8 ++++++++ Lib/typemaps/traits.swg | 4 +--- 16 files changed, 33 insertions(+), 37 deletions(-) diff --git a/Lib/octave/octcontainer.swg b/Lib/octave/octcontainer.swg index b14b8c194..723256ca0 100644 --- a/Lib/octave/octcontainer.swg +++ b/Lib/octave/octcontainer.swg @@ -26,9 +26,7 @@ // The Octave C++ Wrap -%insert(header) %{ -#include -%} +%fragment(""); %include diff --git a/Lib/perl5/std_list.i b/Lib/perl5/std_list.i index ea264d6a1..8248ca679 100644 --- a/Lib/perl5/std_list.i +++ b/Lib/perl5/std_list.i @@ -36,9 +36,9 @@ %{ #include -#include -#include %} +%fragment(""); +%fragment(""); // exported class diff --git a/Lib/perl5/std_map.i b/Lib/perl5/std_map.i index e7812f38a..493307dd9 100644 --- a/Lib/perl5/std_map.i +++ b/Lib/perl5/std_map.i @@ -12,9 +12,9 @@ %{ #include -#include -#include %} +%fragment(""); +%fragment(""); // exported class diff --git a/Lib/perl5/std_vector.i b/Lib/perl5/std_vector.i index a3998ff92..860cdba7e 100644 --- a/Lib/perl5/std_vector.i +++ b/Lib/perl5/std_vector.i @@ -32,9 +32,9 @@ %{ #include -#include -#include %} +%fragment(""); +%fragment(""); // exported class diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index d4386622e..dcada87c7 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -32,9 +32,7 @@ /**** The PySequence C++ Wrap ***/ -%insert(header) %{ -#include -%} +%fragment(""); %include diff --git a/Lib/ruby/rubycontainer.swg b/Lib/ruby/rubycontainer.swg index dd6389ce4..69db367d9 100644 --- a/Lib/ruby/rubycontainer.swg +++ b/Lib/ruby/rubycontainer.swg @@ -26,9 +26,7 @@ /**** The RubySequence C++ Wrap ***/ -%insert(header) %{ -#include -%} +%fragment(""); %include diff --git a/Lib/std/_std_deque.i b/Lib/std/_std_deque.i index 7dd3552db..8e701668e 100644 --- a/Lib/std/_std_deque.i +++ b/Lib/std/_std_deque.i @@ -10,8 +10,8 @@ %{ #include -#include %} +%fragment(""); /* This macro defines all of the standard methods for a deque. This diff --git a/Lib/std/std_common.i b/Lib/std/std_common.i index 35baf2206..6e93e29f6 100644 --- a/Lib/std/std_common.i +++ b/Lib/std/std_common.i @@ -24,10 +24,8 @@ // %fragment(""); -%{ -#include -#include -%} +%fragment(""); +%fragment(""); %fragment("StdIteratorTraits","header",fragment="") %{ diff --git a/Lib/std/std_except.i b/Lib/std/std_except.i index 75b8d0fd6..18bbd4ef1 100644 --- a/Lib/std/std_except.i +++ b/Lib/std/std_except.i @@ -2,9 +2,7 @@ #error "do not use this version of std_except.i" #endif -%{ -#include -%} +%fragment(""); #if defined(SWIG_STD_EXCEPTIONS_AS_CLASSES) diff --git a/Lib/std/std_map.i b/Lib/std/std_map.i index e523c3deb..d1f6b3a16 100644 --- a/Lib/std/std_map.i +++ b/Lib/std/std_map.i @@ -57,9 +57,9 @@ %{ #include -#include -#include %} +%fragment(""); +%fragment(""); // exported class diff --git a/Lib/std/std_unordered_map.i b/Lib/std/std_unordered_map.i index 3d80788e2..8c276172a 100644 --- a/Lib/std/std_unordered_map.i +++ b/Lib/std/std_unordered_map.i @@ -60,9 +60,9 @@ %{ #include -#include -#include %} +%fragment(""); +%fragment(""); // exported class diff --git a/Lib/tcl/std_map.i b/Lib/tcl/std_map.i index 1b7e7696c..78f6e3276 100644 --- a/Lib/tcl/std_map.i +++ b/Lib/tcl/std_map.i @@ -13,9 +13,9 @@ %{ #include -#include -#include %} +%fragment(""); +%fragment(""); // exported class diff --git a/Lib/tcl/std_vector.i b/Lib/tcl/std_vector.i index 37e23ba71..3fc0fd61d 100644 --- a/Lib/tcl/std_vector.i +++ b/Lib/tcl/std_vector.i @@ -29,10 +29,10 @@ // ------------------------------------------------------------------------ %fragment(""); +%fragment(""); +%fragment(""); %{ #include -#include -#include Tcl_Obj* SwigString_FromString(const std::string &s) { return Tcl_NewStringObj(s.data(), (int)s.length()); diff --git a/Lib/typemaps/exception.swg b/Lib/typemaps/exception.swg index 12c4ea658..b60a32996 100644 --- a/Lib/typemaps/exception.swg +++ b/Lib/typemaps/exception.swg @@ -52,9 +52,9 @@ } } */ -%{ -#include -%} + +%fragment(""); + %define SWIG_CATCH_STDEXCEPT /* catching std::exception */ catch (std::invalid_argument& e) { diff --git a/Lib/typemaps/fragments.swg b/Lib/typemaps/fragments.swg index ce87c8cc0..447df6e2e 100644 --- a/Lib/typemaps/fragments.swg +++ b/Lib/typemaps/fragments.swg @@ -157,6 +157,14 @@ #include %} +%fragment("", "header") %{ +#include +%} + +%fragment("", "header") %{ +#include +%} + %fragment("SWIG_isfinite","header",fragment=",") %{ /* Getting isfinite working pre C99 across multiple platforms is non-trivial. Users can provide SWIG_isfinite on older platforms. */ #ifndef SWIG_isfinite diff --git a/Lib/typemaps/traits.swg b/Lib/typemaps/traits.swg index 09cc7e295..406f16066 100644 --- a/Lib/typemaps/traits.swg +++ b/Lib/typemaps/traits.swg @@ -22,9 +22,7 @@ // %fragment(""); -%{ -#include -%} +%fragment(""); %fragment("Traits","header",fragment="") { From ae7b34ce0363c351a0b84f8a65707113f49a7acd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 21 Feb 2014 19:07:35 +0000 Subject: [PATCH 1012/1160] Remove duplicate header includes in director.swg --- Lib/perl5/director.swg | 1 - Lib/python/director.swg | 1 - 2 files changed, 2 deletions(-) diff --git a/Lib/perl5/director.swg b/Lib/perl5/director.swg index a66869725..714a87877 100644 --- a/Lib/perl5/director.swg +++ b/Lib/perl5/director.swg @@ -27,7 +27,6 @@ */ # ifndef SWIG_DIRECTOR_RTDIR # define SWIG_DIRECTOR_RTDIR -#include namespace Swig { class Director; diff --git a/Lib/python/director.swg b/Lib/python/director.swg index 50f735a89..90c58c107 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -62,7 +62,6 @@ */ # ifndef SWIG_DIRECTOR_RTDIR # define SWIG_DIRECTOR_RTDIR -#include namespace Swig { class Director; From 0ed98c0606d2a46660902437b9fa4cdef14dfc97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Tue, 24 Dec 2013 22:30:12 +0100 Subject: [PATCH 1013/1160] added example with %pythonbegin This was requested in PR #7 but overlooked. Contains an example where one does: from __future__ import absolute_import using %pythonbegin directive. --- Doc/Manual/Python.html | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index c6cc2f40f..4584ff726 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -5551,7 +5551,15 @@ from __future__ import absolute_import

    at the very beginning of his proxy *.py file. In SWIG, it may be -accomplished with %pythonbegin directive.

    +accomplished with %pythonbegin directive as follows:

    + +
    +
    +%pythonbegin %{
    +from __future__ import absolute_import
    +%}
    +
    +

    34.11.4 Importing from __init__.py

    From bf313809ae8a441e71b3cfafa29e905df0882a56 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 22 Feb 2014 00:43:18 +0000 Subject: [PATCH 1014/1160] Fix Lua examples for running under Lua 5.2 Includes cherry picking parts of https://github.com/v-for-vandal/swig/commit/ce2760f77e9ab04ce276244ee4329aeba7ddea54 --- Examples/lua/dual/dual.cpp | 4 ++++ Examples/lua/embed/Makefile | 3 ++- Examples/lua/embed/embed.c | 4 ++++ Examples/lua/embed2/Makefile | 3 ++- Examples/lua/embed2/embed2.c | 6 ++++-- Examples/lua/embed3/embed3.cpp | 17 ++++++++++------- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Examples/lua/dual/dual.cpp b/Examples/lua/dual/dual.cpp index d2a9ecaa9..ad7897953 100644 --- a/Examples/lua/dual/dual.cpp +++ b/Examples/lua/dual/dual.cpp @@ -36,6 +36,10 @@ extern "C" int luaopen_example2(lua_State*L); #define DEBUG2(X,Y) {printf(X,Y);fflush(stdout);} #define DEBUG3(X,Y,Z) {printf(X,Y,Z);fflush(stdout);} +#if LUA_VERSION_NUM > 501 +#define lua_open luaL_newstate +#endif + void testModule(lua_State *L) { swig_type_info *pTypeInfo=0,*pTypeInfo2=0; diff --git a/Examples/lua/embed/Makefile b/Examples/lua/embed/Makefile index df1f8fa04..57979c061 100644 --- a/Examples/lua/embed/Makefile +++ b/Examples/lua/embed/Makefile @@ -4,6 +4,7 @@ TARGET = embed SRCS = example.c INTERFACE = example.i LUA_INTERP = embed.c +LIBS = -lm # this is a little different to normal as we have our own special interpreter # which we want to static link @@ -12,7 +13,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' LIBS='$(LIBS)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static clean: $(MAKE) -f $(TOP)/Makefile lua_clean diff --git a/Examples/lua/embed/embed.c b/Examples/lua/embed/embed.c index 9df168f94..f21c933a5 100644 --- a/Examples/lua/embed/embed.c +++ b/Examples/lua/embed/embed.c @@ -18,6 +18,10 @@ We will be using the luaL_dostring()/lua_dostring() function to call into lua #include #include +#if LUA_VERSION_NUM > 501 +#define lua_open luaL_newstate +#endif + /* the SWIG wrappered library */ extern int luaopen_example(lua_State*L); diff --git a/Examples/lua/embed2/Makefile b/Examples/lua/embed2/Makefile index fc309ac7e..ec22bdcae 100644 --- a/Examples/lua/embed2/Makefile +++ b/Examples/lua/embed2/Makefile @@ -4,6 +4,7 @@ TARGET = embed2 SRCS = example.c INTERFACE = example.i LUA_INTERP = embed2.c +LIBS = -lm # this is a little different to normal as we have our own special interpreter # which we want to static link @@ -12,7 +13,7 @@ check: build build: $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' LIBS='$(LIBS)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static clean: $(MAKE) -f $(TOP)/Makefile lua_clean diff --git a/Examples/lua/embed2/embed2.c b/Examples/lua/embed2/embed2.c index 8d28ee6ea..3145d3b10 100644 --- a/Examples/lua/embed2/embed2.c +++ b/Examples/lua/embed2/embed2.c @@ -31,6 +31,9 @@ We will be using the luaL_dostring()/lua_dostring() function to call into lua #include #include +#if LUA_VERSION_NUM > 501 +#define lua_open luaL_newstate +#endif /* the SWIG wrappered library */ extern int luaopen_example(lua_State*L); @@ -46,8 +49,7 @@ int call_add(lua_State *L,int a,int b,int* res) { push a, push b, call 'add' check & return res */ top=lua_gettop(L); /* for later */ - lua_pushstring(L, "add"); /* function name */ - lua_gettable(L, LUA_GLOBALSINDEX); /* function to be called */ + lua_getglobal(L, "add"); /* function to be called */ if (!lua_isfunction(L,-1)) { printf("[C] error: cannot find function 'add'\n"); lua_settop(L,top); // reset diff --git a/Examples/lua/embed3/embed3.cpp b/Examples/lua/embed3/embed3.cpp index e5e0e0a7d..cdf56268d 100644 --- a/Examples/lua/embed3/embed3.cpp +++ b/Examples/lua/embed3/embed3.cpp @@ -26,11 +26,15 @@ extern "C" { #include #include } - -/* The SWIG external runtime is generated by using. -swig -lua -externalruntime swigluarun.h -It contains useful function used by SWIG in its wrappering -SWIG_TypeQuery() SWIG_NewPointerObj() + +#if LUA_VERSION_NUM > 501 +#define lua_open luaL_newstate +#endif + +/* The SWIG external runtime is generated by using. +swig -lua -externalruntime swigluarun.h +It contains useful function used by SWIG in its wrappering +SWIG_TypeQuery() SWIG_NewPointerObj() */ #include "swigluarun.h" // the SWIG external runtime @@ -65,8 +69,7 @@ int call_onEvent(lua_State *L, Event e) { push a, push b, call 'add' check & return res */ top = lua_gettop(L); /* for later */ - lua_pushstring(L, "onEvent"); /* function name */ - lua_gettable(L, LUA_GLOBALSINDEX); /* function to be called */ + lua_getglobal(L, "onEvent"); /* function to be called */ if (!lua_isfunction(L, -1)) { printf("[C++] error: cannot find function 'OnEvent'\n"); lua_settop(L, top); // reset From 91f4828a4aa0cf53155ace45e3f33f9ac76c4bed Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 22 Feb 2014 01:04:50 +0000 Subject: [PATCH 1015/1160] Fix missing fragment name in warning message about missing fragment --- Examples/test-suite/errors/swig_fragment_missing.i | 4 ++++ .../test-suite/errors/swig_fragment_missing.stderr | 1 + Source/Swig/fragment.c | 10 +++++----- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 Examples/test-suite/errors/swig_fragment_missing.i create mode 100644 Examples/test-suite/errors/swig_fragment_missing.stderr diff --git a/Examples/test-suite/errors/swig_fragment_missing.i b/Examples/test-suite/errors/swig_fragment_missing.i new file mode 100644 index 000000000..e1e83350b --- /dev/null +++ b/Examples/test-suite/errors/swig_fragment_missing.i @@ -0,0 +1,4 @@ +%module xxx + +%fragment("awol"); + diff --git a/Examples/test-suite/errors/swig_fragment_missing.stderr b/Examples/test-suite/errors/swig_fragment_missing.stderr new file mode 100644 index 000000000..1debb0090 --- /dev/null +++ b/Examples/test-suite/errors/swig_fragment_missing.stderr @@ -0,0 +1 @@ +swig_fragment_missing.i:3: Warning 490: Fragment 'awol' not found. diff --git a/Source/Swig/fragment.c b/Source/Swig/fragment.c index 927c772b8..5b30e86e0 100644 --- a/Source/Swig/fragment.c +++ b/Source/Swig/fragment.c @@ -94,16 +94,16 @@ void Swig_fragment_emit(Node *n) { String *name = 0; String *type = 0; + name = Getattr(n, "value"); + if (!name) { + name = n; + } + if (!fragments) { Swig_warning(WARN_FRAGMENT_NOT_FOUND, Getfile(n), Getline(n), "Fragment '%s' not found.\n", name); return; } - - name = Getattr(n, "value"); - if (!name) { - name = n; - } type = Getattr(n, "type"); if (type) { mangle = Swig_string_mangle(type); From 2feb2e6fc600f8663911c36d362f9764c2ccee0e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 22 Feb 2014 01:11:40 +0000 Subject: [PATCH 1016/1160] Revert fragment for non-UTL languages --- Lib/std/std_except.i | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/std/std_except.i b/Lib/std/std_except.i index 18bbd4ef1..75b8d0fd6 100644 --- a/Lib/std/std_except.i +++ b/Lib/std/std_except.i @@ -2,7 +2,9 @@ #error "do not use this version of std_except.i" #endif -%fragment(""); +%{ +#include +%} #if defined(SWIG_STD_EXCEPTIONS_AS_CLASSES) From ec629beb3145302e96ac6d8844a4dc29d011dbc8 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sat, 22 Feb 2014 15:46:22 +0400 Subject: [PATCH 1017/1160] Fixing segfault --- Source/Modules/lua.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index f521824a0..a516b5eb0 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -1557,7 +1557,7 @@ public: if (result == SWIG_OK) { // This will add static member variable to the class namespace with name ClassName_VarName if (v2_compatibility) { - Swig_save("lua_staticmembervariableHandler", n, "lua:name"); + Swig_save("lua_staticmembervariableHandler", n, "lua:name", NIL); String *target_name = Getattr(n, "lua:name"); String *v2_name = Swig_name_member(NIL, class_symname, target_name); //Printf( stdout, "Name %s, class %s, compt. name %s\n", target_name, class_symname, v2_name ); // TODO: REMOVE From 77a7069f9eb128a671968d4c9a20cd5fc2561939 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sat, 22 Feb 2014 17:56:21 +0400 Subject: [PATCH 1018/1160] Fixing cmd options, again --- Source/Modules/lua.cxx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index a516b5eb0..58424d16d 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -80,7 +80,7 @@ void display_mapping(DOH *d) { NEW LANGUAGE NOTE:END ************************************************/ static const char *usage = (char *) "\ Lua Options (available with -lua)\n\ - -drop-old-scheme\n\ + -no-old-metatable-bindings\n\ - Disable support for old-style bindings name generation, some\n\ old-style members scheme etc.\n\ -elua - Generates LTR compatible wrappers for smaller devices running elua\n\ @@ -99,6 +99,16 @@ static int elua_ltr = 0; static int eluac_ltr = 0; static int elua_emulate = 0; static int squash_bases = 0; +/* This variable defines internal(!) module API level and compatibility options. + * This variable is controled by -no-old-metatable-bindings option. + * v2_compatibility - + * 1. static methods will be put into the scope their respective class + * belongs to as well as into the class scope itself. + * 2. The layout in elua mode is somewhat different + * 3. C enums defined inside struct will oblige to C Standard and + * will be defined in the scope surrounding the struct, not scope + * associated with it/ + */ static int v2_compatibility = 0; static const int default_api_level = 2; @@ -222,7 +232,7 @@ public: } else if (strcmp(argv[i], "-eluac") == 0) { eluac_ltr = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i], "-drop-old-scheme") == 0) { + } else if (strcmp(argv[i], "-no-old-metatable-bindings") == 0) { Swig_mark_arg(i); api_level = 3; } else if (strcmp(argv[i], "-squash-bases") == 0) { From f12d8aa174c430cbfb313e1aa83b6d3950022b4b Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sat, 22 Feb 2014 18:06:47 +0400 Subject: [PATCH 1019/1160] target_name -> lua_name --- Source/Modules/lua.cxx | 80 +++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 58424d16d..b4fb7bed1 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -473,20 +473,20 @@ public: Hash *nspaceHash = getCArraysHash(nspace_or_class_name); String *s_ns_methods_tab = Getattr(nspaceHash, "methods"); String *wname = Getattr(n, "wrap:name"); - String *target_name = Getattr(n, "lua:name"); + String *lua_name = Getattr(n, "lua:name"); if (elua_ltr || eluac_ltr) - Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", target_name, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", lua_name, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); else - Printv(s_ns_methods_tab, tab4, "{ \"", target_name, "\", ", wname, "},\n", NIL); + Printv(s_ns_methods_tab, tab4, "{ \"", lua_name, "\", ", wname, "},\n", NIL); // Add to the metatable if method starts with '__' - const char * tn = Char(target_name); + const char * tn = Char(lua_name); if (tn[0]=='_' && tn[1] == '_' && !eluac_ltr) { String *metatable_tab = Getattr(nspaceHash, "metatable"); assert(metatable_tab); if (elua_ltr) - Printv(metatable_tab, tab4, "{LSTRKEY(\"", target_name, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); + Printv(metatable_tab, tab4, "{LSTRKEY(\"", lua_name, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); else - Printv(metatable_tab, tab4, "{ \"", target_name, "\", ", wname, "},\n", NIL); + Printv(metatable_tab, tab4, "{ \"", lua_name, "\", ", wname, "},\n", NIL); } } @@ -505,8 +505,8 @@ public: String *name = Getattr(n, "name"); String *iname = Getattr(n, "sym:name"); - String *target_name = Getattr(n, "lua:name"); - assert(target_name); + String *lua_name = Getattr(n, "lua:name"); + assert(lua_name); SwigType *d = Getattr(n, "type"); ParmList *l = Getattr(n, "parms"); Parm *p; @@ -518,7 +518,7 @@ public: if (Getattr(n, "sym:overloaded")) { overname = Getattr(n, "sym:overname"); } else { - if (!luaAddSymbol(target_name, n)) { + if (!luaAddSymbol(lua_name, n)) { return SWIG_ERROR; } } @@ -844,13 +844,13 @@ public: Wrapper *f = NewWrapper(); String *symname = Getattr(n, "sym:name"); - String *target_name = Getattr(n, "lua:name"); - assert(target_name); + String *lua_name = Getattr(n, "lua:name"); + assert(lua_name); String *wname = symnameWrapper(symname); //Printf(stdout,"Swig_overload_dispatch %s %s '%s' %d\n",symname,wname,dispatch,maxargs); - if (!luaAddSymbol(target_name, n)) { + if (!luaAddSymbol(lua_name, n)) { return SWIG_ERROR; } @@ -918,17 +918,17 @@ public: Hash *nspaceHash = getCArraysHash(nspace_or_class_name); String *s_ns_methods_tab = Getattr(nspaceHash, "methods"); String *s_ns_var_tab = Getattr(nspaceHash, "attributes"); - String *target_name = Getattr(n, "lua:name"); + String *lua_name = Getattr(n, "lua:name"); if (elua_ltr) { String *s_ns_dot_get = Getattr(nspaceHash, "get"); String *s_ns_dot_set = Getattr(nspaceHash, "set"); - Printf(s_ns_dot_get, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, target_name, getName); - Printf(s_ns_dot_set, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, target_name, setName); + Printf(s_ns_dot_get, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, lua_name, getName); + Printf(s_ns_dot_set, "%s{LSTRKEY(\"%s\"), LFUNCVAL(%s)},\n", tab4, lua_name, setName); } else if (eluac_ltr) { - Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", target_name, "_get", "\")", ", LFUNCVAL(", getName, ")", "},\n", NIL); - Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", target_name, "_set", "\")", ", LFUNCVAL(", setName, ")", "},\n", NIL); + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", lua_name, "_get", "\")", ", LFUNCVAL(", getName, ")", "},\n", NIL); + Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", lua_name, "_set", "\")", ", LFUNCVAL(", setName, ")", "},\n", NIL); } else { - Printf(s_ns_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, target_name, getName, setName); + Printf(s_ns_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, lua_name, getName, setName); } } @@ -945,8 +945,8 @@ public: only WRT this variable will look into this later. NEW LANGUAGE NOTE:END *********************************************** */ // REPORT("variableWrapper", n); - String *target_name = Getattr(n, "lua:name"); - assert(target_name); + String *lua_name = Getattr(n, "lua:name"); + assert(lua_name); current[VARIABLE] = true; // let SWIG generate the wrappers int result = Language::variableWrapper(n); @@ -987,24 +987,24 @@ public: REPORT("constantWrapper", n); String *name = Getattr(n, "name"); String *iname = Getattr(n, "sym:name"); - String *target_name = Getattr(n, "lua:name"); - if (target_name == 0) - target_name = iname; + String *lua_name = Getattr(n, "lua:name"); + if (lua_name == 0) + lua_name = iname; String *nsname = Copy(iname); SwigType *type = Getattr(n, "type"); String *rawval = Getattr(n, "rawval"); String *value = rawval ? rawval : Getattr(n, "value"); String *tm; - String *target_name_v2 = 0; + String *lua_name_v2 = 0; String *tm_v2 = 0; String *iname_v2 = 0; Node *n_v2 = 0; - if (!luaAddSymbol(target_name, n)) + if (!luaAddSymbol(lua_name, n)) return SWIG_ERROR; Swig_save("lua_constantMember", n, "sym:name", NIL); - Setattr(n, "sym:name", target_name); + Setattr(n, "sym:name", lua_name); /* Special hook for member pointer */ if (SwigType_type(type) == T_MPOINTER) { String *wname = symnameWrapper(iname); @@ -1015,13 +1015,13 @@ public: if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) { //Printf(stdout, "tm v1: %s\n", tm); // TODO:REMOVE Replaceall(tm, "$source", value); - Replaceall(tm, "$target", target_name); + Replaceall(tm, "$target", lua_name); Replaceall(tm, "$value", value); Replaceall(tm, "$nsname", nsname); registerConstant(luaCurrentSymbolNSpace(), tm); } else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) { Replaceall(tm, "$source", value); - Replaceall(tm, "$target", target_name); + Replaceall(tm, "$target", lua_name); Replaceall(tm, "$value", value); Replaceall(tm, "$nsname", nsname); Printf(f_init, "%s\n", tm); @@ -1038,27 +1038,27 @@ public: if (make_v2_compatible) { // Special handling for enums in C mode - they are not prefixed with structure name if(!CPlusPlus && current[ENUM_CONST]) { - target_name_v2 = target_name; - DohIncref(target_name_v2); + lua_name_v2 = lua_name; + DohIncref(lua_name_v2); iname_v2 = iname; DohIncref(iname_v2); } else { - target_name_v2 = Swig_name_member(0, class_symname, target_name); + lua_name_v2 = Swig_name_member(0, class_symname, lua_name); iname_v2 = Swig_name_member(0, class_symname, iname); } n_v2 = Copy(n); - //Printf( stdout, "target name v2: %s, symname v2 %s\n", target_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE + //Printf( stdout, "target name v2: %s, symname v2 %s\n", lua_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE if (!luaAddSymbol(iname_v2, n, getNSpace())) { Swig_restore(n); return SWIG_ERROR; } - Setattr(n_v2, "sym:name", target_name_v2); + Setattr(n_v2, "sym:name", lua_name_v2); tm_v2 = Swig_typemap_lookup("consttab", n_v2, name, 0); if (tm_v2) { //Printf(stdout, "tm v2: %s\n", tm_v2.ptr()); // TODO:REMOVE Replaceall(tm_v2, "$source", value); - Replaceall(tm_v2, "$target", target_name_v2); + Replaceall(tm_v2, "$target", lua_name_v2); Replaceall(tm_v2, "$value", value); Replaceall(tm_v2, "$nsname", nsname); registerConstant(getNSpace(), tm_v2); @@ -1071,7 +1071,7 @@ public: return SWIG_ERROR; } Replaceall(tm_v2, "$source", value); - Replaceall(tm_v2, "$target", target_name_v2); + Replaceall(tm_v2, "$target", lua_name_v2); Replaceall(tm_v2, "$value", value); Replaceall(tm_v2, "$nsname", nsname); Printf(f_init, "%s\n", tm_v2); @@ -1530,8 +1530,8 @@ public: if (v2_compatibility) { Swig_require("lua_staticmemberfunctionHandler", n, "*lua:name", NIL); - String *target_name = Getattr(n, "lua:name"); - String *compat_name = Swig_name_member(0, class_symname, target_name); + String *lua_name = Getattr(n, "lua:name"); + String *compat_name = Swig_name_member(0, class_symname, lua_name); Setattr(n, "lua:name", compat_name); registerMethod(getNSpace(), n); Delete(compat_name); @@ -1568,9 +1568,9 @@ public: // This will add static member variable to the class namespace with name ClassName_VarName if (v2_compatibility) { Swig_save("lua_staticmembervariableHandler", n, "lua:name", NIL); - String *target_name = Getattr(n, "lua:name"); - String *v2_name = Swig_name_member(NIL, class_symname, target_name); - //Printf( stdout, "Name %s, class %s, compt. name %s\n", target_name, class_symname, v2_name ); // TODO: REMOVE + String *lua_name = Getattr(n, "lua:name"); + String *v2_name = Swig_name_member(NIL, class_symname, lua_name); + //Printf( stdout, "Name %s, class %s, compt. name %s\n", lua_name, class_symname, v2_name ); // TODO: REMOVE if (!GetFlag(n, "wrappedasconstant")) { Setattr(n, "lua:name", v2_name); registerVariable(getNSpace(), n, "varget:wrap:name", "varset:wrap:name"); From 166b19e860573f8f9cfa5bbaf6c1e7d66e630c8b Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sat, 22 Feb 2014 18:26:46 +0400 Subject: [PATCH 1020/1160] Members renaming --- Source/Modules/lua.cxx | 97 +++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 43 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index b4fb7bed1..31418cb8e 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -134,9 +134,20 @@ private: int have_constructor; int have_destructor; String *destructor_action; - String *class_symname; - String *class_fq_symname; // Fully qualified symname - NSpace + '.' + class_symname + // This variable holds the name of the current class in Lua. Usually it is + // the same as C++ class name, but rename directives can change it. + String *proxy_class_name; + // This is a so calld fully qualified symname - the above proxy class name + // prepended with class namespace. If class Lua name is the same as class C++ name, + // then it is basically C++ fully qualified name with colons replaced with dots. + String *full_proxy_class_name; + // All static methods and/or variables are treated as if they were in the + // special C++ namespace $(classname).__Static. This is internal mechanism only + // and is not visible to user in any manner. This variable holds the name + // of such pseudo-namespace a.k.a the result of above expression evaluation String *class_static_nspace; + // This variable holds the name of generated C function that acts as constructor + // for currently parsed class. String *constructor_name; // Many wrappers forward calls to each other, for example staticmembervariableHandler @@ -179,8 +190,8 @@ public: have_constructor(0), have_destructor(0), destructor_action(0), - class_symname(0), - class_fq_symname(0), + proxy_class_name(0), + full_proxy_class_name(0), class_static_nspace(0), constructor_name(0) { for (int i = 0; i < STATES_COUNT; i++) @@ -1043,8 +1054,8 @@ public: iname_v2 = iname; DohIncref(iname_v2); } else { - lua_name_v2 = Swig_name_member(0, class_symname, lua_name); - iname_v2 = Swig_name_member(0, class_symname, iname); + lua_name_v2 = Swig_name_member(0, proxy_class_name, lua_name); + iname_v2 = Swig_name_member(0, proxy_class_name, iname); } n_v2 = Copy(n); //Printf( stdout, "target name v2: %s, symname v2 %s\n", lua_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE @@ -1167,7 +1178,7 @@ public: assert(class_hash); String *cls_methods = Getattr(class_hash, "methods:name"); assert(cls_methods); - Printv(ns_methods, tab4, "{LSTRKEY(\"", class_symname, "\")", ", LROVAL(", cls_methods, ")", "},\n", NIL); + Printv(ns_methods, tab4, "{LSTRKEY(\"", proxy_class_name, "\")", ", LROVAL(", cls_methods, ")", "},\n", NIL); } } /* ------------------------------------------------------------ @@ -1176,7 +1187,7 @@ public: virtual int classHandler(Node *n) { //REPORT("classHandler", n); - String *mangled_class_fq_symname = 0; + String *mangled_full_proxy_class_name = 0; String *destructor_name = 0; String *nspace = getNSpace(); @@ -1185,25 +1196,25 @@ public: have_destructor = 0; destructor_action = 0; assert(class_static_nspace == 0); - assert(class_fq_symname == 0); - assert(class_symname == 0); + assert(full_proxy_class_name == 0); + assert(proxy_class_name == 0); current[NO_CPP] = false; - class_symname = Getattr(n, "sym:name"); + proxy_class_name = Getattr(n, "sym:name"); // We have to enforce nspace here, because technically we are already // inside class parsing (getCurrentClass != 0), but we should register // class in the it's parent namespace - if (!luaAddSymbol(class_symname, n, nspace)) + if (!luaAddSymbol(proxy_class_name, n, nspace)) return SWIG_ERROR; if (nspace == 0) - class_fq_symname = NewStringf("%s", class_symname); + full_proxy_class_name = NewStringf("%s", proxy_class_name); else - class_fq_symname = NewStringf("%s.%s", nspace, class_symname); + full_proxy_class_name = NewStringf("%s.%s", nspace, proxy_class_name); - assert(class_fq_symname); - mangled_class_fq_symname = Swig_name_mangle(class_fq_symname); + assert(full_proxy_class_name); + mangled_full_proxy_class_name = Swig_name_mangle(full_proxy_class_name); SwigType *t = Copy(Getattr(n, "name")); SwigType *fr_t = SwigType_typedef_resolve_all(t); /* Create fully resolved type */ @@ -1222,8 +1233,8 @@ public: static Hash *emitted = NewHash(); if (Getattr(emitted, mangled_fr_t)) { - class_fq_symname = 0; - class_symname = 0; + full_proxy_class_name = 0; + proxy_class_name = 0; return SWIG_NOWRAP; } Setattr(emitted, mangled_fr_t, "1"); @@ -1239,7 +1250,7 @@ public: // And we can guarantee that there will not be any name collision because names starting with 2 underscores // and capital letter are forbiden to use in C++. So, under know circumstances could our class contain // any member or subclass with name "__Static". Thus, never any name clash. - Hash *instance_cls = getCArraysHash(class_fq_symname, false); + Hash *instance_cls = getCArraysHash(full_proxy_class_name, false); assert(instance_cls); String *s_attr_tab_name = Getattr(instance_cls, "attributes:name"); String *s_methods_tab_name = Getattr(instance_cls, "methods:name"); @@ -1251,7 +1262,7 @@ public: * All constants are considered part of static part of class. */ - class_static_nspace = NewStringf("%s%s__Static", class_fq_symname, NSPACE_SEPARATOR); + class_static_nspace = NewStringf("%s%s__Static", full_proxy_class_name, NSPACE_SEPARATOR); Hash *static_cls = getCArraysHash(class_static_nspace, false); assert(static_cls); Setattr(static_cls, "lua:no_namespaces", "1"); @@ -1270,7 +1281,7 @@ public: SwigType_add_pointer(t); // Catch all: eg. a class with only static functions and/or variables will not have 'remembered' - String *wrap_class_name = NewStringf("_wrap_class_%s", mangled_class_fq_symname); + String *wrap_class_name = NewStringf("_wrap_class_%s", mangled_full_proxy_class_name); String *wrap_class = NewStringf("&%s", wrap_class_name); Setattr(n, "wrap:class_name", wrap_class_name); SwigType_remember_clientdata(t, wrap_class); @@ -1283,11 +1294,11 @@ public: Hash *nspaceHash = getCArraysHash(nspace); // Register the class structure with the type checker - // Printf(f_init,"SWIG_TypeClientData(SWIGTYPE%s, (void *) &_wrap_class_%s);\n", SwigType_manglestr(t), mangled_class_fq_symname); + // Printf(f_init,"SWIG_TypeClientData(SWIGTYPE%s, (void *) &_wrap_class_%s);\n", SwigType_manglestr(t), mangled_full_proxy_class_name); // emit a function to be called to delete the object if (have_destructor) { - destructor_name = NewStringf("swig_delete_%s", mangled_class_fq_symname); + destructor_name = NewStringf("swig_delete_%s", mangled_full_proxy_class_name); Printv(f_wrappers, "static void ", destructor_name, "(void *obj) {\n", NIL); if (destructor_action) { Printv(f_wrappers, SwigType_str(rt, "arg1"), " = (", SwigType_str(rt, 0), ") obj;\n", NIL); @@ -1325,18 +1336,18 @@ public: } else if (eluac_ltr) { String *ns_methods_tab = Getattr(nspaceHash, "methods"); assert(ns_methods_tab); - Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "new_", class_symname, "\")", ", LFUNCVAL(", constructor_name, ")", "},\n", NIL); + Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "new_", proxy_class_name, "\")", ", LFUNCVAL(", constructor_name, ")", "},\n", NIL); } } if (have_destructor) { if (eluac_ltr) { String *ns_methods_tab = Getattr(nspaceHash, "methods"); assert(ns_methods_tab); - Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_class_fq_symname, "\")", ", LFUNCVAL(", destructor_name, ")", "},\n", NIL); + Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_full_proxy_class_name, "\")", ", LFUNCVAL(", destructor_name, ")", "},\n", NIL); } } - closeCArraysHash(class_fq_symname, f_wrappers); + closeCArraysHash(full_proxy_class_name, f_wrappers); closeCArraysHash(class_static_nspace, f_wrappers); @@ -1372,21 +1383,21 @@ public: } } // First, print class static part - printCArraysDefinition(class_static_nspace, class_symname, f_wrappers); + printCArraysDefinition(class_static_nspace, proxy_class_name, f_wrappers); - assert(mangled_class_fq_symname); + assert(mangled_full_proxy_class_name); assert(base_class); assert(base_class_names); - assert(class_symname); - assert(class_fq_symname); + assert(proxy_class_name); + assert(full_proxy_class_name); // Then print class isntance part - Printv(f_wrappers, "static swig_lua_class *swig_", mangled_class_fq_symname, "_bases[] = {", base_class, "0};\n", NIL); + Printv(f_wrappers, "static swig_lua_class *swig_", mangled_full_proxy_class_name, "_bases[] = {", base_class, "0};\n", NIL); Delete(base_class); - Printv(f_wrappers, "static const char *swig_", mangled_class_fq_symname, "_base_names[] = {", base_class_names, "0};\n", NIL); + Printv(f_wrappers, "static const char *swig_", mangled_full_proxy_class_name, "_base_names[] = {", base_class_names, "0};\n", NIL); Delete(base_class_names); - Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_class_fq_symname, " = { \"", class_symname, "\", \"", class_fq_symname, "\", &SWIGTYPE", + Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_full_proxy_class_name, " = { \"", proxy_class_name, "\", \"", full_proxy_class_name, "\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); if (have_constructor) { @@ -1411,18 +1422,18 @@ public: else Printf(f_wrappers, ", 0"); - Printf(f_wrappers, ", swig_%s_bases, swig_%s_base_names };\n\n", mangled_class_fq_symname, mangled_class_fq_symname); + Printf(f_wrappers, ", swig_%s_bases, swig_%s_base_names };\n\n", mangled_full_proxy_class_name, mangled_full_proxy_class_name); current[NO_CPP] = true; Delete(class_static_nspace); class_static_nspace = 0; - Delete(mangled_class_fq_symname); - mangled_class_fq_symname = 0; + Delete(mangled_full_proxy_class_name); + mangled_full_proxy_class_name = 0; Delete(destructor_name); destructor_name = 0; - Delete(class_fq_symname); - class_fq_symname = 0; - class_symname = 0; + Delete(full_proxy_class_name); + full_proxy_class_name = 0; + proxy_class_name = 0; return SWIG_OK; } @@ -1531,7 +1542,7 @@ public: if (v2_compatibility) { Swig_require("lua_staticmemberfunctionHandler", n, "*lua:name", NIL); String *lua_name = Getattr(n, "lua:name"); - String *compat_name = Swig_name_member(0, class_symname, lua_name); + String *compat_name = Swig_name_member(0, proxy_class_name, lua_name); Setattr(n, "lua:name", compat_name); registerMethod(getNSpace(), n); Delete(compat_name); @@ -1569,8 +1580,8 @@ public: if (v2_compatibility) { Swig_save("lua_staticmembervariableHandler", n, "lua:name", NIL); String *lua_name = Getattr(n, "lua:name"); - String *v2_name = Swig_name_member(NIL, class_symname, lua_name); - //Printf( stdout, "Name %s, class %s, compt. name %s\n", lua_name, class_symname, v2_name ); // TODO: REMOVE + String *v2_name = Swig_name_member(NIL, proxy_class_name, lua_name); + //Printf( stdout, "Name %s, class %s, compt. name %s\n", lua_name, proxy_class_name, v2_name ); // TODO: REMOVE if (!GetFlag(n, "wrappedasconstant")) { Setattr(n, "lua:name", v2_name); registerVariable(getNSpace(), n, "varget:wrap:name", "varset:wrap:name"); @@ -2069,7 +2080,7 @@ public: scope = class_static_nspace; } else if (current[MEMBER_VAR] || current[CONSTRUCTOR] || current[DESTRUCTOR] || current[MEMBER_FUNC]) { - scope = class_fq_symname; + scope = full_proxy_class_name; } else { // Friend functions are handled this way scope = class_static_nspace; } From dac0e989e3c7603e6da6f67e5258665b8abb5aa5 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sat, 22 Feb 2014 19:01:48 +0400 Subject: [PATCH 1021/1160] Options in alphabetical order --- Source/Modules/lua.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 31418cb8e..e2bba5bea 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -80,15 +80,15 @@ void display_mapping(DOH *d) { NEW LANGUAGE NOTE:END ************************************************/ static const char *usage = (char *) "\ Lua Options (available with -lua)\n\ - -no-old-metatable-bindings\n\ - - Disable support for old-style bindings name generation, some\n\ - old-style members scheme etc.\n\ -elua - Generates LTR compatible wrappers for smaller devices running elua\n\ -eluac - LTR compatible wrappers in \"crass compress\" mode for elua\n\ -elua-emulate - Emulates behaviour of eLua. Usefull only for testing.\n\ Incompatible with -elua/-eluac options.\n\ -nomoduleglobal - Do not register the module name as a global variable \n\ but return the module table from calls to require.\n\ + -no-old-metatable-bindings\n\ + - Disable support for old-style bindings name generation, some\n\ + old-style members scheme etc.\n\ -squash-bases - Squashes symbols from all inheritance tree of a given class\n\ into itself. Emulates pre-SWIG3.0 inheritance. Insignificantly\n\ speeds things up, but increases memory consumption.\n\ From 4f3c77051f5aff194dfea70574dfcf00b48c0ace Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 22 Feb 2014 20:51:27 +0000 Subject: [PATCH 1022/1160] Slight wording change when running test-suite Should be easier to parse 'by eye' --- Doc/Manual/Extending.html | 8 ++++---- Examples/test-suite/chicken/Makefile.in | 6 +++--- Examples/test-suite/common.mk | 4 ++-- Examples/test-suite/csharp/Makefile.in | 4 ++-- Examples/test-suite/d/Makefile.in | 4 ++-- Examples/test-suite/java/Makefile.in | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index 1fc65d0e1..c757bc289 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -3350,10 +3350,10 @@ Note that if a runtime test is available, a message "(with run test)" is display
     $ make check-python-test-suite
     checking python test-suite
    -checking testcase argcargvtest (with run test) under python
    -checking testcase python_autodoc under python
    -checking testcase python_append (with run test) under python
    -checking testcase callback (with run test) under python
    +checking python testcase argcargvtest (with run test)
    +checking python testcase python_autodoc
    +checking python testcase python_append (with run test)
    +checking python testcase callback (with run test)
     

    diff --git a/Examples/test-suite/chicken/Makefile.in b/Examples/test-suite/chicken/Makefile.in index 42fe6100a..3c2f3de54 100644 --- a/Examples/test-suite/chicken/Makefile.in +++ b/Examples/test-suite/chicken/Makefile.in @@ -69,17 +69,17 @@ SWIGOPT += -nounit $(run_testcase) %.cppproxy: - echo "$(ACTION)ing testcase $* (with run test) under chicken with -proxy" + echo "$(ACTION)ing $(LANGUAGE) testcase $* (with run test) with -proxy" +$(swig_and_compile_cpp) $(run_testcase) %.cproxy: - echo "$(ACTION)ing testcase $* (with run test) under chicken with -proxy" + echo "$(ACTION)ing $(LANGUAGE) testcase $* (with run test) with -proxy" +$(swig_and_compile_c) $(run_testcase) %.multiproxy: - echo "$(ACTION)ing testcase $* (with run test) under chicken with -proxy" + echo "$(ACTION)ing $(LANGUAGE) testcase $* (with run test) with -proxy" +$(swig_and_compile_multi_cpp) $(run_testcase) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 836984476..6ea80670d 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -708,9 +708,9 @@ swig_and_compile_runtime = \ setup = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \ + echo "$(ACTION)ing $(LANGUAGE) testcase $* (with run test)" ; \ else \ - echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \ + echo "$(ACTION)ing $(LANGUAGE) testcase $*" ; \ fi; diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index 4284a775d..993699bc8 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -58,9 +58,9 @@ csharp_swig2_compatibility.cpptest: SWIGOPT += -DSWIG2_CSHARP # Makes a directory for the testcase if it does not exist setup = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \ + echo "$(ACTION)ing $(LANGUAGE) testcase $* (with run test)" ; \ else \ - echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \ + echo "$(ACTION)ing $(LANGUAGE) testcase $*" ; \ fi; \ if [ ! -d $* ]; then \ mkdir $*; \ diff --git a/Examples/test-suite/d/Makefile.in b/Examples/test-suite/d/Makefile.in index 8128e4f7a..61c2749dc 100644 --- a/Examples/test-suite/d/Makefile.in +++ b/Examples/test-suite/d/Makefile.in @@ -46,9 +46,9 @@ SWIGOPT+=-splitproxy -package $* # Makes a directory for the testcase if it does not exist setup = \ if [ -f $(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) ]; then \ - echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \ + echo "$(ACTION)ing $(LANGUAGE) testcase $* (with run test)" ; \ else \ - echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \ + echo "$(ACTION)ing $(LANGUAGE) testcase $*" ; \ fi; \ if [ ! -d $*$(VERSIONSUFFIX) ]; then \ mkdir $*$(VERSIONSUFFIX); \ diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 1bd4b0261..ee0e13fba 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -73,9 +73,9 @@ director_nspace_director_name_collision.%: JAVA_PACKAGE = $*Package # Makes a directory for the testcase if it does not exist setup = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \ + echo "$(ACTION)ing $(LANGUAGE) testcase $* (with run test)" ; \ else \ - echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \ + echo "$(ACTION)ing $(LANGUAGE) testcase $* $(LANGUAGE)" ; \ fi; \ if [ ! -d $(JAVA_PACKAGE) ]; then \ mkdir $(JAVA_PACKAGE); \ From be49f5caeed5fe421a631a2e8724ca4ba38ed342 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 22 Feb 2014 20:53:26 +0000 Subject: [PATCH 1023/1160] Another revert fragment for non-UTL languages --- Lib/std/_std_deque.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/std/_std_deque.i b/Lib/std/_std_deque.i index 8e701668e..7dd3552db 100644 --- a/Lib/std/_std_deque.i +++ b/Lib/std/_std_deque.i @@ -10,8 +10,8 @@ %{ #include +#include %} -%fragment(""); /* This macro defines all of the standard methods for a deque. This From 894de07c3d676268cbfc83cf92e0bd6e7850e2dc Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 22 Feb 2014 21:24:55 +0000 Subject: [PATCH 1024/1160] Add missing executable bit --- Examples/guile/matrix/runme.scm | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 Examples/guile/matrix/runme.scm diff --git a/Examples/guile/matrix/runme.scm b/Examples/guile/matrix/runme.scm old mode 100644 new mode 100755 From 087a66a6587a5b34d167a5c8b98b0ba7014dbd80 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sun, 23 Feb 2014 02:08:34 +0400 Subject: [PATCH 1025/1160] updated documentation following comd options renaming --- Doc/Manual/Lua.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index 31c9dd564..44384b1a3 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -160,7 +160,7 @@ swig -lua -help - -swig3 + -no-old-metatable-bindings Disable backward compatibility: old-style binding names generations and a few other things. Explanations are included into appropriate sections. @@ -524,7 +524,7 @@ This is 'effectively' converted into the following Lua code:

    Backward compatibility

    -If -swig3 option is not given, then in addition to previously described bindings, the old-style ones are generated: +If -no-old-metatable-bindings option is not given, then in addition to previously described bindings, the old-style ones are generated:

     > print(example.Test_TEST1)
    @@ -748,7 +748,7 @@ It is not (currently) possible to access static members of an instance:
     

    Backward compatibility

    -

    If -swig3 option is not given, then backward compatible names are generated in addition to ordinary ones:

    +

    If -no-old-metatable-bindings option is not given, then backward compatible names are generated in addition to ordinary ones:

     > example.Spam_foo()            -- calling Spam::foo()
     > a=example.Spam_bar            -- reading Spam::bar 
    @@ -1364,7 +1364,7 @@ Now, in Lua it could be used like this:
     

    Backward compatibility

    -If SWIG is running in backward compatible way, i.e. without -swig3 option, then additional old-style names are generated(notice the underscore): +If SWIG is running in backward compatible way, i.e. without -no-old-metatable-bindings option, then additional old-style names are generated(notice the underscore):

     9
    @@ -1376,7 +1376,7 @@ If SWIG is running in backward compatible way, i.e. without -swig3 opti
     

    Backward compatibility

    Names

    -

    If SWIG is launched without -swig3 option, then it enters backward-compatible mode. While in this mode, it tries +

    If SWIG is launched without -no-old-metatable-bindings option, then it enters backward-compatible mode. While in this mode, it tries to generate additional names for static functions, class static constants and class enums. Those names are in a form $classname_$symbolname and are added to the scope surrounding the class. If %nspace is enabled, then class namespace is taken as scope. If there is no namespace, or %nspace is disabled, From 2f3bf144c685585dab7d4d8ae1ae805dda0edab8 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 23 Feb 2014 16:52:08 +1300 Subject: [PATCH 1026/1160] Fix assorted comment and documentation typos --- CHANGES | 6 +++--- Doc/Devel/internals.html | 4 ++-- Doc/Devel/tree.html | 2 +- Doc/Manual/Allegrocl.html | 18 +++++++++--------- Doc/Manual/CSharp.html | 2 +- Doc/Manual/Extending.html | 6 +++--- Doc/Manual/Introduction.html | 2 +- Doc/Manual/Lisp.html | 2 +- Doc/Manual/Modula3.html | 8 ++++---- Doc/Manual/Modules.html | 2 +- Doc/Manual/Ocaml.html | 4 ++-- Doc/Manual/Octave.html | 2 +- Examples/Makefile.in | 2 +- Examples/go/template/index.html | 2 +- Examples/java/template/index.html | 2 +- Examples/lua/import.lua | 8 ++++---- Examples/python/callback/runme.py | 2 +- Examples/python/multimap/example.i | 2 +- Examples/ruby/index.html | 2 +- Examples/test-suite/java/README | 2 +- Examples/test-suite/lua/import.lua | 6 +++--- Lib/chicken/chickenrun.swg | 4 ++-- Lib/lua/luaruntime.swg | 2 +- Lib/octave/octtypemaps.swg | 2 +- Lib/perl5/Makefile.in | 2 +- Lib/perl5/perltypemaps.swg | 2 +- Lib/ruby/rubytypemaps.swg | 2 +- Lib/swig.swg | 2 +- Lib/swiginit.swg | 2 +- Source/CParse/templ.c | 2 +- Source/Modules/typepass.cxx | 2 +- Source/Swig/typeobj.c | 2 +- configure.ac | 2 +- 33 files changed, 56 insertions(+), 56 deletions(-) diff --git a/CHANGES b/CHANGES index 988f0fb5e..db9adab03 100644 --- a/CHANGES +++ b/CHANGES @@ -5684,7 +5684,7 @@ Version 1.3.28 (February 12, 2006) %rename("%(utitle)s",%$isfunction,%$ismember) ""; - to avoid clashings with other swig macros/directives. + to avoid clashes with other swig macros/directives. 01/14/2006: cfisavage [Ruby] @@ -11787,7 +11787,7 @@ Version 1.3.20 (December 17, 2003) 11/30/2003: cheetah (William Fulton) [Java] Fixed [ 766409 ] missing symbol SWIG_JavaThrowException during module load - SWIGs internal functions are all static as there is no need for different SWIG + SWIG's internal functions are all static as there is no need for different SWIG generated modules to share any code at runtime. 11/30/2003: beazley @@ -21368,7 +21368,7 @@ Version 1.1 Patch 4 (January 4, 1998) 12/29/97: Fixed configure script and a few makefiles to support Python 1.5 12/29/97: Added 'embed15.i' library file. This file should be used to - staticly link versions of Python 1.5. To make it the default, + statically link versions of Python 1.5. To make it the default, simply copy 'swig_lib/python/embed15.i' to 'swig_lib/python/embed.i' Version 1.1 Patch 3 (November 24, 1997) diff --git a/Doc/Devel/internals.html b/Doc/Devel/internals.html index 94a82519d..c9082d3f6 100644 --- a/Doc/Devel/internals.html +++ b/Doc/Devel/internals.html @@ -347,7 +347,7 @@ Delete(a); /* Destroy a */ All objects are referenced counted and given a reference count of 1 when initially created. The Delete() function only destroys an object when the reference count reaches zero. When -an object is placed in a list or hash table, it's reference count is automatically increased. For example: +an object is placed in a list or hash table, its reference count is automatically increased. For example:

    @@ -844,7 +844,7 @@ Returns a type object corresponding to the type string produced by the Swig_cloc
     
  • char *Swig_clocal_deref(DataType *t, char *name)
    This function is the inverse of the clocal() function. Given a type and a name, it produces a string containing the code needed to cast/convert the type produced by -Swig_clocal() back into it's original type. +Swig_clocal() back into its original type.

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

    Constants, as declared by the preprocessor #define macro or SWIG - %constant directive, are included in SWIGs parse tree + %constant directive, are included in SWIG's parse tree when it can be determined that they are, or could be reduced to, a literal value. Such values are translated into defconstant forms in the generated lisp wrapper when the -nocwrap command-line @@ -887,7 +887,7 @@ globalvar> (globalvar.nnn::glob_float)

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

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

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

    @@ -1735,7 +1735,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) The out typemap is used to generate code to form the return value of the wrapper from the return value of the wrapped function. This code is placed in the <convert and bind result to lresult> - section of the above code diagram. It's default mapping is as follows: + section of the above code diagram. Its default mapping is as follows:

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

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

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

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

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

    diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index 764a1a6c3..6ee33ac68 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -881,7 +881,7 @@ set so should only be used when a C# exception is not created.

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

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

    @@ -3005,7 +3005,7 @@ virtual int functionWrapper(Node *n) { /* write typemaps(in) */ .... - /* write constriants */ + /* write constraints */ .... /* Emit the function call */ diff --git a/Doc/Manual/Introduction.html b/Doc/Manual/Introduction.html index d5dc778bd..19d59a4df 100644 --- a/Doc/Manual/Introduction.html +++ b/Doc/Manual/Introduction.html @@ -449,7 +449,7 @@ to work with complicated and unusual C/C++ applications.

    Ironically, the freedom that SWIG provides is countered by an -extremely conservative approach to code generation. At it's core, SWIG +extremely conservative approach to code generation. At its core, SWIG tries to distill even the most advanced C++ code down to a small well-defined set of interface building techniques based on ANSI C programming. Because of this, you will find that SWIG interfaces can diff --git a/Doc/Manual/Lisp.html b/Doc/Manual/Lisp.html index 01ff3a3ec..09e410185 100644 --- a/Doc/Manual/Lisp.html +++ b/Doc/Manual/Lisp.html @@ -122,7 +122,7 @@ swig -cffi -help As we mentioned earlier the ideal way to use SWIG is to use interface - files. To illustrate the use of it, lets assume that we have a + files. To illustrate the use of it, let's assume that we have a file named test.h with the following C code:

    diff --git a/Doc/Manual/Modula3.html b/Doc/Manual/Modula3.html
    index 065313fa2..329127a0f 100644
    --- a/Doc/Manual/Modula3.html
    +++ b/Doc/Manual/Modula3.html
    @@ -45,7 +45,7 @@
     
     
     

    -This chapter describes SWIG's support of +This chapter describes SWIG's support for Modula-3. You should be familiar with the basics @@ -109,7 +109,7 @@ into exceptions.

    If the library API is ill designed -writing appropriate typemaps can be still time-consuming. +writing appropriate typemaps can still be time-consuming. E.g. C programmers are very creative to work-around missing data types like (real) enumerations and sets. You should turn such work-arounds back to the Modula-3 way @@ -120,14 +120,14 @@ otherwise you lose static safety and consistency. Without SWIG you would probably never consider trying to call C++ libraries from Modula-3, but with SWIG this is becomes feasible. SWIG can generate C wrappers to C++ functions and object methods -that may throw exceptions, and then wrap these C wrappers for Module-3. +that may throw exceptions, and then wrap these C wrappers for Modula-3. To make it complete you can then hide the C interface with Modula-3 classes and exceptions.

    SWIG allows you to call C and C++ libraries from Modula-3 (even with call back -functions), but it doesn't allow you to easily integrate a Module-3 module into +functions), but it doesn't allow you to easily integrate a Modula-3 module into a C/C++ project.

    diff --git a/Doc/Manual/Modules.html b/Doc/Manual/Modules.html index 70b0f1181..c44341e56 100644 --- a/Doc/Manual/Modules.html +++ b/Doc/Manual/Modules.html @@ -130,7 +130,7 @@ public:

    To create the wrapper properly, module derived_module needs to know about the base class and that its interface is covered in another module. The -line %import "base_module.i" lets SWIG know exactly that. Oftentimes +line %import "base_module.i" lets SWIG know exactly that. Often the .h file is passed to %import instead of the .i, which unfortunately doesn't work for all language modules. For example, Python requires the name of module that the base class exists in so that the proxy classes can fully inherit the diff --git a/Doc/Manual/Ocaml.html b/Doc/Manual/Ocaml.html index 127be904d..2eef3ad4d 100644 --- a/Doc/Manual/Ocaml.html +++ b/Doc/Manual/Ocaml.html @@ -163,7 +163,7 @@ the user more freedom with respect to custom typing.

    The camlp4 module (swigp4.ml -> swigp4.cmo) contains a simple rewriter which -makes C++ code blend more seamlessly with objective caml code. It's use is +makes C++ code blend more seamlessly with objective caml code. Its use is optional, but encouraged. The source file is included in the Lib/ocaml directory of the SWIG source distribution. You can checkout this file with "swig -ocaml -co swigp4.ml". You should compile the file with @@ -310,7 +310,7 @@ type c_obj =

  • caml_val_ptr receives a void * and returns a c_obj.
  • caml_val_bool receives a C int and returns a c_obj representing - it's bool value.
  • + its bool value.
  • caml_val_(u)?(char|short|int|long|float|double) receives an appropriate C value and returns a c_obj representing it.
  • caml_val_string receives a char * and returns a string value.
  • diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 3e12ce668..42c6526b7 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -329,7 +329,7 @@ octave:4> swigexample.fclose(f);

    - Simply printing the value of a wrapped C++ type will print it's typename. E.g., + Simply printing the value of a wrapped C++ type will print its typename. E.g.,

    octave:1> swigexample;
    diff --git a/Examples/Makefile.in b/Examples/Makefile.in
    index 5c7884a8f..218d8eca5 100644
    --- a/Examples/Makefile.in
    +++ b/Examples/Makefile.in
    @@ -1098,7 +1098,7 @@ CHICKEN_GENERATED_SCHEME = $(INTERFACE:.i=.scm)
     CHICKEN_COMPILED_SCHEME = $(INTERFACE:.i=_chicken.c)
     CHICKEN_COMPILED_OBJECT = $(CHICKEN_COMPILED_SCHEME:.c=.@OBJEXT@)
     
    -# flags for the main chicken sources (only used when compiling staticly)
    +# flags for the main chicken sources (only used when compiling statically)
     CHICKEN_COMPILED_MAIN = $(CHICKEN_MAIN:.scm=_chicken.c)
     CHICKEN_COMPILED_MAIN_OBJECT = $(CHICKEN_COMPILED_MAIN:.c=.@OBJEXT@)
     
    diff --git a/Examples/go/template/index.html b/Examples/go/template/index.html
    index a14e3b29a..cf2b1337b 100644
    --- a/Examples/go/template/index.html
    +++ b/Examples/go/template/index.html
    @@ -17,7 +17,7 @@ SWIG.
     
     

    The C++ Code

    -Lets take a templated function and a templated class as follows: +Let's take a templated function and a templated class as follows:
    diff --git a/Examples/java/template/index.html b/Examples/java/template/index.html
    index f4408e568..31dba6d8e 100644
    --- a/Examples/java/template/index.html
    +++ b/Examples/java/template/index.html
    @@ -16,7 +16,7 @@ This example illustrates how C++ templates can be used from Java using SWIG.
     
     

    The C++ Code

    -Lets take a templated function and a templated class as follows: +Let's take a templated function and a templated class as follows:
    diff --git a/Examples/lua/import.lua b/Examples/lua/import.lua
    index b2a40b017..4a0f0d3da 100644
    --- a/Examples/lua/import.lua
    +++ b/Examples/lua/import.lua
    @@ -1,7 +1,7 @@
     -- import
     -- the lua 5.0 loading mechanism is rather poor & relies upon the loadlib() fn
     -- the lua 5.1 loading mechanism is simplicity itself
    --- for now we need a bridge which will use the correct verion
    +-- for now we need a bridge which will use the correct version
     
     function import_5_0(module)
     	-- imports the file into the program
    @@ -10,7 +10,7 @@ function import_5_0(module)
     	-- and look for the fn 'Example_Init()' (note the capitalisation)
     	if rawget(_G,module)~=nil then return end -- module appears to be loaded
     		
    -	-- capitialising the first letter
    +	-- capitalising the first letter
     	local c=string.upper(string.sub(module,1,1))
     	local fnname=c..string.sub(module,2).."_Init"
     	
    @@ -26,7 +26,7 @@ function import_5_0(module)
     	end
     	assert(lib,"error loading module:"..module)
     	
    -	lib() -- execute the function: initalising the lib
    +	lib() -- execute the function: initialising the lib
     	local m=rawget(_G,module)	-- gets the module object
     	assert(m~=nil,"no module table found")
     end
    @@ -39,4 +39,4 @@ if string.sub(_VERSION,1,7)=='Lua 5.0' then
     	import=import_5_0
     else
     	import=import_5_1
    -end
    \ No newline at end of file
    +end
    diff --git a/Examples/python/callback/runme.py b/Examples/python/callback/runme.py
    index 026e9520b..ddb668407 100644
    --- a/Examples/python/callback/runme.py
    +++ b/Examples/python/callback/runme.py
    @@ -42,7 +42,7 @@ print
     print "Adding and calling another Python callback"
     print "------------------------------------------"
     
    -# Lets do the same but use the weak reference this time.
    +# Let's do the same but use the weak reference this time.
     
     callback = PyCallback().__disown__()
     caller.setCallback(callback)
    diff --git a/Examples/python/multimap/example.i b/Examples/python/multimap/example.i
    index 3f6fc3db3..cc2482cc8 100644
    --- a/Examples/python/multimap/example.i
    +++ b/Examples/python/multimap/example.i
    @@ -98,7 +98,7 @@ extern int count(char *bytes, int len, char c);
     /* This example shows how to wrap a function that mutates a string */
     
     /* Since str is modified, we make a copy of the Python object
    -   so that we don't violate it's mutability */
    +   so that we don't violate its mutability */
     
     %typemap(in) (char *str, int len) {
     %#if PY_VERSION_HEX >= 0x03000000
    diff --git a/Examples/ruby/index.html b/Examples/ruby/index.html
    index f04146e56..4f4aa0ad2 100644
    --- a/Examples/ruby/index.html
    +++ b/Examples/ruby/index.html
    @@ -1,4 +1,4 @@
    -
    +
     
     SWIG:Examples:ruby
     
    diff --git a/Examples/test-suite/java/README b/Examples/test-suite/java/README
    index b8b7416d9..b4123a840 100644
    --- a/Examples/test-suite/java/README
    +++ b/Examples/test-suite/java/README
    @@ -1,6 +1,6 @@
     See ../README for common README file.
     
    -The Java implementation of the test-suite is a little different to the other languages in that all of SWIGs output goes into a subdirectory named after the individual test case. This is so that all the shadow classes can be compiled as Java classes have to go into separate files. Otherwise the Makefile wouldn't know which .java files would be relevant to the testcase. For this to work the testcase must go into a Java package.
    +The Java implementation of the test-suite is a little different to the other languages in that all of SWIG's output goes into a subdirectory named after the individual test case. This is so that all the shadow classes can be compiled as Java classes which have to go into separate files. Otherwise the Makefile wouldn't know which .java files would be relevant to the testcase. For this to work the testcase must go into a Java package.
     
     Any testcases which have _runme.java appended after the testcase name will be detected and run.
     
    diff --git a/Examples/test-suite/lua/import.lua b/Examples/test-suite/lua/import.lua
    index eaab3b400..2ab2555e7 100644
    --- a/Examples/test-suite/lua/import.lua
    +++ b/Examples/test-suite/lua/import.lua
    @@ -1,7 +1,7 @@
     -- import
     -- the lua 5.0 loading mechanism is rather poor & relies upon the loadlib() fn
     -- the lua 5.1 loading mechanism is simplicity itself
    --- for now we need a bridge which will use the correct verion
    +-- for now we need a bridge which will use the correct version
     
     function import_5_0(name)
     	-- imports the file into the program
    @@ -13,7 +13,7 @@ function import_5_0(name)
     	local lib=loadlib(name..'.dll','luaopen_'..name) or loadlib(name..'.so','luaopen_'..name)
     	assert(lib,"error loading module:"..name)
     	
    -	lib() -- execute the function: initalising the lib
    +	lib() -- execute the function: initialising the lib
     	assert(rawget(_G,name)~=nil,"no module table found")
     end
     
    @@ -25,4 +25,4 @@ if string.sub(_VERSION,1,7)=='Lua 5.0' then
     	import=import_5_0
     else
     	import=import_5_1
    -end
    \ No newline at end of file
    +end
    diff --git a/Lib/chicken/chickenrun.swg b/Lib/chicken/chickenrun.swg
    index 07db41945..f13400181 100644
    --- a/Lib/chicken/chickenrun.swg
    +++ b/Lib/chicken/chickenrun.swg
    @@ -313,7 +313,7 @@ SWIG_Chicken_GetModule(void *SWIGUNUSEDPARM(clientdata)) {
         swig_module_info *ret = 0;
         C_word sym;
     
    -    /* lookup the type pointer... it is stored in it's own symbol table */
    +    /* lookup the type pointer... it is stored in its own symbol table */
         C_SYMBOL_TABLE *stable = C_find_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION);
         if (stable != NULL) {
           sym = SWIG_Chicken_LookupSymbol(chicken_runtimevar_name, stable);
    @@ -333,7 +333,7 @@ SWIG_Chicken_SetModule(swig_module_info *module) {
         C_word pointer;
         static C_word *space = 0;
         
    -    /* type pointer is stored in it's own symbol table */
    +    /* type pointer is stored in its own symbol table */
         stable = C_find_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION);
         if (stable == NULL) {
           stable = C_new_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION, 16);
    diff --git a/Lib/lua/luaruntime.swg b/Lib/lua/luaruntime.swg
    index 423c7190b..3ca489ffa 100644
    --- a/Lib/lua/luaruntime.swg
    +++ b/Lib/lua/luaruntime.swg
    @@ -31,7 +31,7 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
       int i;
       /* start with global table */
       lua_pushglobaltable (L);
    -  /* SWIG's internal initalisation */
    +  /* SWIG's internal initialisation */
       SWIG_InitializeModule((void*)L);
       SWIG_PropagateClientData();
     #endif
    diff --git a/Lib/octave/octtypemaps.swg b/Lib/octave/octtypemaps.swg
    index e331cf4b3..4acf8e076 100644
    --- a/Lib/octave/octtypemaps.swg
    +++ b/Lib/octave/octtypemaps.swg
    @@ -1,5 +1,5 @@
     
    -// Include fundamental fragemt definitions
    +// Include fundamental fragment definitions
     %include 
     
     // Look for user fragments file.
    diff --git a/Lib/perl5/Makefile.in b/Lib/perl5/Makefile.in
    index f11ad2bdf..1fee86ccc 100644
    --- a/Lib/perl5/Makefile.in
    +++ b/Lib/perl5/Makefile.in
    @@ -46,7 +46,7 @@ SWIG          = $(exec_prefix)/bin/swig
     SWIGOPT       = -perl5 
     SWIGCC        = $(CC) 
     
    -# SWIG Library files.  Uncomment this to staticly rebuild Perl
    +# SWIG Library files.  Uncomment this to statically rebuild Perl
     #SWIGLIBS      = -static -lperlmain.i
     
     # Rules for creating .o files from source.
    diff --git a/Lib/perl5/perltypemaps.swg b/Lib/perl5/perltypemaps.swg
    index f47a5ef82..ffec5eaf1 100644
    --- a/Lib/perl5/perltypemaps.swg
    +++ b/Lib/perl5/perltypemaps.swg
    @@ -18,7 +18,7 @@
     #define SWIG_FROM_CALL_ARGS  SWIG_PERL_CALL_ARGS_1
     
     
    -/* Include fundamental fragemt definitions */
    +/* Include fundamental fragment definitions */
     %include 
     
     /* Look for user fragments file. */
    diff --git a/Lib/ruby/rubytypemaps.swg b/Lib/ruby/rubytypemaps.swg
    index 336ee977a..3837df078 100644
    --- a/Lib/ruby/rubytypemaps.swg
    +++ b/Lib/ruby/rubytypemaps.swg
    @@ -8,7 +8,7 @@
     #undef SWIG_TYPECHECK_BOOL
     %define SWIG_TYPECHECK_BOOL             10000 %enddef
     
    -/* Include fundamental fragemt definitions */
    +/* Include fundamental fragment definitions */
     %include 
     
     /* Look for user fragments file. */
    diff --git a/Lib/swig.swg b/Lib/swig.swg
    index 3ddbb85a0..c33ae3854 100644
    --- a/Lib/swig.swg
    +++ b/Lib/swig.swg
    @@ -321,7 +321,7 @@ static int NAME(TYPE x) {
     
     /*
      * Function/method overloading support.   This is done through typemaps,
    - * but also involve a precedence level. 
    + * but also involves a precedence level.
      */
     
     /* Macro for overload resolution */
    diff --git a/Lib/swiginit.swg b/Lib/swiginit.swg
    index f321181eb..69e368ac1 100644
    --- a/Lib/swiginit.swg
    +++ b/Lib/swiginit.swg
    @@ -11,7 +11,7 @@
      * array with the correct data and linking the correct swig_cast_info
      * structures together.
      *
    - * The generated swig_type_info structures are assigned staticly to an initial
    + * The generated swig_type_info structures are assigned statically to an initial
      * array. We just loop through that array, and handle each type individually.
      * First we lookup if this type has been already loaded, and if so, use the
      * loaded structure instead of the generated one. Then we have to fill in the
    diff --git a/Source/CParse/templ.c b/Source/CParse/templ.c
    index 48bdf4faa..fe8fc2800 100644
    --- a/Source/CParse/templ.c
    +++ b/Source/CParse/templ.c
    @@ -825,7 +825,7 @@ Node *Swig_cparse_template_locate(String *name, Parm *tparms, Symtab *tscope) {
           /* If not a templated class we must have a templated function.
              The template found is not necessarily the one we want when dealing with templated
              functions. We don't want any specialized templated functions as they won't have
    -         the default parameters. Lets look for the unspecialized template. Also make sure
    +         the default parameters. Let's look for the unspecialized template. Also make sure
              the number of template parameters is correct as it is possible to overload a
              templated function with different numbers of template parameters. */
     
    diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx
    index 49f95090d..329a601a8 100644
    --- a/Source/Modules/typepass.cxx
    +++ b/Source/Modules/typepass.cxx
    @@ -476,7 +476,7 @@ class TypePass:private Dispatcher {
         if (unnamed && tdname && (Cmp(storage, "typedef") == 0)) {
           SwigType_typedef(unnamed, tdname);
         }
    -    // name of the outer class should already be patched to contain it's outer classes names, but not to contain namespaces
    +    // name of the outer class should already be patched to contain its outer classes names, but not to contain namespaces
         // namespace name (if present) is added after processing child nodes
         if (Getattr(n, "nested:outer") && name) {
           String *outerName = Getattr(Getattr(n, "nested:outer"), "name");
    diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c
    index 903d1357c..622eac118 100644
    --- a/Source/Swig/typeobj.c
    +++ b/Source/Swig/typeobj.c
    @@ -240,7 +240,7 @@ String *SwigType_parm(const SwigType *t) {
     /* -----------------------------------------------------------------------------
      * SwigType_split()
      *
    - * Splits a type into it's component parts and returns a list of string.
    + * Splits a type into its component parts and returns a list of string.
      * ----------------------------------------------------------------------------- */
     
     List *SwigType_split(const SwigType *t) {
    diff --git a/configure.ac b/configure.ac
    index be4e6e3c9..f3414969e 100644
    --- a/configure.ac
    +++ b/configure.ac
    @@ -19,7 +19,7 @@ AH_BOTTOM([
     /* Default language */
     #define SWIG_LANG               "-tcl"
     
    -/* Deal with Microsofts attempt at deprecating C standard runtime functions */
    +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
     #if defined(_MSC_VER)
     # define _CRT_SECURE_NO_DEPRECATE
     #endif
    
    From 34c97ffdbd528f4c53873ccc8f60238579c2a22d Mon Sep 17 00:00:00 2001
    From: Olly Betts 
    Date: Sun, 23 Feb 2014 18:05:50 +1300
    Subject: [PATCH 1027/1160] Improve the class example for several languages.
    
    Fix numerous inaccuracies in index.html (where it exists) and eliminate
    unnecessary differences between the example code being wrapped.
    ---
     Examples/java/class/example.cxx   | 10 ++--
     Examples/java/class/example.h     | 25 ++++-----
     Examples/java/class/index.html    | 49 +++--------------
     Examples/perl5/class/example.cxx  | 10 ++--
     Examples/perl5/class/example.h    | 29 +++++------
     Examples/perl5/class/example.i    |  1 -
     Examples/perl5/class/index.html   | 87 +++++++------------------------
     Examples/perl5/class/runme.pl     |  2 +-
     Examples/php/class/example.cxx    | 23 +++-----
     Examples/php/class/example.h      | 16 +++---
     Examples/php/class/runme.php      |  4 +-
     Examples/python/class/example.cxx | 10 ++--
     Examples/python/class/example.h   | 25 ++++-----
     Examples/python/class/index.html  | 87 +++++--------------------------
     Examples/python/class/runme.py    |  4 +-
     Examples/ruby/class/example.cxx   | 10 ++--
     Examples/ruby/class/example.h     | 25 ++++-----
     Examples/ruby/class/index.html    | 61 ++++------------------
     Examples/ruby/class/runme.rb      |  4 ++
     Examples/tcl/class/example.cxx    | 10 ++--
     Examples/tcl/class/example.h      | 25 ++++-----
     Examples/tcl/class/example.i      |  1 -
     Examples/tcl/class/index.html     | 48 +++--------------
     23 files changed, 154 insertions(+), 412 deletions(-)
    
    diff --git a/Examples/java/class/example.cxx b/Examples/java/class/example.cxx
    index 1e8e203dd..046304519 100644
    --- a/Examples/java/class/example.cxx
    +++ b/Examples/java/class/example.cxx
    @@ -1,4 +1,4 @@
    -/* File : example.c */
    +/* File : example.cxx */
     
     #include "example.h"
     #define M_PI 3.14159265358979323846
    @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) {
     
     int Shape::nshapes = 0;
     
    -double Circle::area(void) {
    +double Circle::area() {
       return M_PI*radius*radius;
     }
     
    -double Circle::perimeter(void) {
    +double Circle::perimeter() {
       return 2*M_PI*radius;
     }
     
    -double Square::area(void) {
    +double Square::area() {
       return width*width;
     }
     
    -double Square::perimeter(void) {
    +double Square::perimeter() {
       return 4*width;
     }
    diff --git a/Examples/java/class/example.h b/Examples/java/class/example.h
    index 46d901361..0dff185b2 100644
    --- a/Examples/java/class/example.h
    +++ b/Examples/java/class/example.h
    @@ -7,11 +7,11 @@ public:
       }
       virtual ~Shape() {
         nshapes--;
    -  };
    -  double  x, y;   
    +  }
    +  double  x, y;
       void    move(double dx, double dy);
    -  virtual double area(void) = 0;
    -  virtual double perimeter(void) = 0;
    +  virtual double area() = 0;
    +  virtual double perimeter() = 0;
       static  int nshapes;
     };
     
    @@ -19,21 +19,16 @@ class Circle : public Shape {
     private:
       double radius;
     public:
    -  Circle(double r) : radius(r) { };
    -  virtual double area(void);
    -  virtual double perimeter(void);
    +  Circle(double r) : radius(r) { }
    +  virtual double area();
    +  virtual double perimeter();
     };
     
     class Square : public Shape {
     private:
       double width;
     public:
    -  Square(double w) : width(w) { };
    -  virtual double area(void);
    -  virtual double perimeter(void);
    +  Square(double w) : width(w) { }
    +  virtual double area();
    +  virtual double perimeter();
     };
    -
    -
    -
    -
    -  
    diff --git a/Examples/java/class/index.html b/Examples/java/class/index.html
    index cf9130c62..b0a5e221d 100644
    --- a/Examples/java/class/index.html
    +++ b/Examples/java/class/index.html
    @@ -32,8 +32,8 @@ public:
       }
       virtual ~Shape() {
         nshapes--;
    -  };
    -  double  x, y;   
    +  }
    +  double  x, y;
       void    move(double dx, double dy);
       virtual double area() = 0;
       virtual double perimeter() = 0;
    @@ -44,7 +44,7 @@ class Circle : public Shape {
     private:
       double radius;
     public:
    -  Circle(double r) : radius(r) { };
    +  Circle(double r) : radius(r) { }
       virtual double area();
       virtual double perimeter();
     };
    @@ -53,7 +53,7 @@ class Square : public Shape {
     private:
       double width;
     public:
    -  Square(double w) : width(w) { };
    +  Square(double w) : width(w) { }
       virtual double area();
       virtual double perimeter();
     };
    @@ -146,50 +146,15 @@ Shape.setNshapes(13);       // Set a static data member
     
     
    • This high-level interface using proxy classes is not the only way to handle C++ code. -A low level interface using c functions to access member variables and member functions is the alternative SWIG -approach. This entails passing around the c pointer or c++ 'this' pointer and as such it is not difficult to crash the JVM. +A low level interface using C functions to access member variables and member functions is the alternative SWIG +approach. This entails passing around the C pointer or C++ 'this' pointer and as such it is not difficult to crash the JVM. The abstraction of the underlying pointer by the java proxy classes far better fits the java programming paradigm.

      -

    • SWIG *does* know how to properly perform upcasting of objects in an inheritance +
    • SWIG does know how to properly perform upcasting of objects in an inheritance hierarchy (including multiple inheritance). However Java classes can only derive from one base class so multiple inheritance is not implemented. Java classes can implement more than one interface so there is scope for improvement in the future. -

      -

    • A wide variety of C++ features are not currently supported by SWIG. Here is the -short and incomplete list: - -

      -

        -
      • Overloaded methods and functions. SWIG wrappers don't know how to resolve name -conflicts so you must give an alternative name to any overloaded method name using the -%name directive like this: - -
        -
        -void foo(int a);  
        -%name(foo2) void foo(double a, double b);
        -
        -
        - -

        -

      • Overloaded operators. Not supported at all. The only workaround for this is -to write a helper function. For example: - -
        -
        -%inline %{
        -    Vector *vector_add(Vector *a, Vector *b) {
        -          ... whatever ...
        -    }
        -%}
        -
        -
        - -

        -

      • Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all). - -

    diff --git a/Examples/perl5/class/example.cxx b/Examples/perl5/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/perl5/class/example.cxx +++ b/Examples/perl5/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/perl5/class/example.h b/Examples/perl5/class/example.h index b0671d583..fd6943541 100644 --- a/Examples/perl5/class/example.h +++ b/Examples/perl5/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,29 +19,24 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; - virtual double area(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; typedef Square TSquare; class CFoo { public: - static Square MakeSquare(void) {return Square(4.0);}; - static TSquare MakeTSquare(void) {return Square(4.0);}; + static Square MakeSquare(void) {return Square(4.0);} + static TSquare MakeTSquare(void) {return Square(4.0);} }; - - - - - diff --git a/Examples/perl5/class/example.i b/Examples/perl5/class/example.i index 23ee8a822..75700b305 100644 --- a/Examples/perl5/class/example.i +++ b/Examples/perl5/class/example.i @@ -6,6 +6,5 @@ %} /* Let's just grab the original header file here */ - %include "example.h" diff --git a/Examples/perl5/class/index.html b/Examples/perl5/class/index.html index 58a50ad2e..b4f923b5a 100644 --- a/Examples/perl5/class/index.html +++ b/Examples/perl5/class/index.html @@ -32,8 +32,8 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); virtual double area() = 0; virtual double perimeter() = 0; @@ -44,7 +44,7 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; + Circle(double r) : radius(r) { } virtual double area(); virtual double perimeter(); }; @@ -53,7 +53,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } virtual double area(); virtual double perimeter(); }; @@ -82,7 +82,7 @@ like this: Note: when creating a C++ extension, you must run SWIG with the -c++ option like this:
    -% swig -c++ -python example.i
    +% swig -c++ -perl example.i
     
    @@ -97,60 +97,45 @@ Click here to see a script that calls the C++ functions f
    -$c = example::new_Circle(10.0);
    +$c = new example::Circle(10.0);
     

    -

  • To access member data, a pair of accessor functions are used. -For example: +
  • You can access member data like so:
    -example::Shape_x_set($c,15);    # Set member data
    -$x = example::Shape_x_get($c);   # Get member data
    -
    -
    - -Note: when accessing member data, the name of the class in which -the data member is defined is used. For example Shape_x_get(). - -

    -

  • To invoke a member function, you simply do this - -
    -
    -print "The area is ", example::Shape_area($c);
    +$c->{x} = 15;    # Set member data
    +$x = $c->{x};    # Get member data
     

    -

  • Type checking knows about the inheritance structure of C++. For example: +
  • To invoke a member function, you simply do this:
    -example::Shape_area($c);       # Works (c is a Shape)
    -example::Circle_area($c);      # Works (c is a Circle)
    -example::Square_area($c);      # Fails (c is definitely not a Square)
    +print "The area is ", $c->area();
     

    -

  • To invoke a destructor, simply do this +
  • To invoke a destructor, simply do this:
    -example::delete_Shape($c);     # Deletes a shape
    +$c->DESTROY();   # Deletes a shape
     

    -

  • Static member variables are wrapped as C global variables. For example: +
  • Static member variables are wrapped like so:
    -$n = $example::Shape_nshapes;     # Get a static data member
    -$example::Shapes_nshapes = 13;   # Set a static data member
    +$n = $example::Shape::nshapes;    # Get a static data member
    +$example::Shapes::nshapes = 13;   # Set a static data member
     
    @@ -159,47 +144,11 @@ $example::Shapes_nshapes = 13; # Set a static data member

    General Comments

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

      -

    • SWIG *does* know how to properly perform upcasting of objects in an inheritance +
    • SWIG does know how to properly perform upcasting of objects in an inheritance hierarchy (including multiple inheritance). Therefore it is perfectly safe to pass an object of a derived class to any function involving a base class. -

      -

    • A wide variety of C++ features are not currently supported by SWIG. Here is the -short and incomplete list: - -

      -

        -
      • Overloaded methods and functions. SWIG wrappers don't know how to resolve name -conflicts so you must give an alternative name to any overloaded method name using the -%name directive like this: - -
        -
        -void foo(int a);  
        -%name(foo2) void foo(double a, double b);
        -
        -
        - -

        -

      • Overloaded operators. Not supported at all. The only workaround for this is -to write a helper function. For example: - -
        -
        -%inline %{
        -    Vector *vector_add(Vector *a, Vector *b) {
        -          ... whatever ...
        -    }
        -%}
        -
        -
        - -

        -

      • Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all). +
      • C++ Namespaces - %nspace isn't yet supported for Perl.
      diff --git a/Examples/perl5/class/runme.pl b/Examples/perl5/class/runme.pl index 076e1437b..e45e2b8ce 100644 --- a/Examples/perl5/class/runme.pl +++ b/Examples/perl5/class/runme.pl @@ -40,7 +40,7 @@ foreach $o ($c,$s) { print " $o\n"; print " area = ", $o->area(), "\n"; print " perimeter = ", $o->perimeter(), "\n"; - } +} # ----- Delete everything ----- diff --git a/Examples/php/class/example.cxx b/Examples/php/class/example.cxx index f171f10e9..046304519 100644 --- a/Examples/php/class/example.cxx +++ b/Examples/php/class/example.cxx @@ -1,14 +1,7 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" -#include -#ifndef M_PI -# define M_PI 3.14159265358979323846 -#endif - -int Shape::get_nshapes() { - return nshapes; -} +#define M_PI 3.14159265358979323846 /* Move the shape to a new location */ void Shape::move(double dx, double dy) { @@ -18,22 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -void Circle::set_radius( double r ) { - radius = r; -} - -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/php/class/example.h b/Examples/php/class/example.h index 02eaf7232..0dff185b2 100644 --- a/Examples/php/class/example.h +++ b/Examples/php/class/example.h @@ -10,10 +10,9 @@ public: } double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; - static int get_nshapes(); }; class Circle : public Shape { @@ -21,10 +20,8 @@ private: double radius; public: Circle(double r) : radius(r) { } - ~Circle() { } - void set_radius( double r ); - virtual double area(void); - virtual double perimeter(void); + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { @@ -32,7 +29,6 @@ private: double width; public: Square(double w) : width(w) { } - ~Square() { } - virtual double area(void); - virtual double perimeter(void); + virtual double area(); + virtual double perimeter(); }; diff --git a/Examples/php/class/runme.php b/Examples/php/class/runme.php index 12b686052..99c253b46 100644 --- a/Examples/php/class/runme.php +++ b/Examples/php/class/runme.php @@ -14,7 +14,7 @@ print " Created square\n"; # ----- Access a static member ----- -print "\nA total of " . Shape::get_nshapes() . " shapes were created\n"; +print "\nA total of " . Shape::nshapes() . " shapes were created\n"; # ----- Member data access ----- @@ -54,7 +54,7 @@ $s = NULL; # the square. $o = NULL; -print Shape::get_nshapes() . " shapes remain\n"; +print Shape::nshapes() . " shapes remain\n"; print "Goodbye\n"; ?> diff --git a/Examples/python/class/example.cxx b/Examples/python/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/python/class/example.cxx +++ b/Examples/python/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/python/class/example.h b/Examples/python/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/python/class/example.h +++ b/Examples/python/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; - virtual double area(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/python/class/index.html b/Examples/python/class/index.html index 12c5eded1..2e1baa395 100644 --- a/Examples/python/class/index.html +++ b/Examples/python/class/index.html @@ -12,9 +12,7 @@

      Wrapping a simple C++ class

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

      The C++ Code

      @@ -32,8 +30,8 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); virtual double area() = 0; virtual double perimeter() = 0; @@ -44,7 +42,7 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; + Circle(double r) : radius(r) { } virtual double area(); virtual double perimeter(); }; @@ -53,7 +51,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } virtual double area(); virtual double perimeter(); }; @@ -102,51 +100,34 @@ c = example.new_Circle(10.0)
  • -

  • To access member data, a pair of accessor functions are used. +
  • Member variables of the C++ class are wrapped as attributes of the Python class. For example:
    -example.Shape_x_set(c,15)    # Set member data
    -x = example.Shape_x_get(c)    # Get member data
    -
    -
    - -Note: when accessing member data, the name of the class in which -the member data was must be used. In this case, Shape_x_get() -and Shape_x_set() are used since 'x' was defined in Shape. - -

    -

  • To invoke a member function, you simply do this - -
    -
    -print "The area is ", example.Shape_area(c)
    +c.x = 15   # Set member data
    +x = c.x    # Get member data
     

    -

  • Type checking knows about the inheritance structure of C++. For example: +
  • Member function are invoked as you would expect:
    -example.Shape_area(c)       # Works (c is a Shape)
    -example.Circle_area(c)      # Works (c is a Circle)
    -example.Square_area(c)      # Fails (c is definitely not a Square)
    +print "The area is ", c.area()
     

    -

  • To invoke a destructor, simply do this +
  • To invoke a destructor, simply call del on the object:
    -example.delete_Shape(c)     # Deletes a shape
    +del c    # Deletes a shape
     
    -(Note: destructors are currently not inherited. This might change later). -

  • Static member variables are wrapped as C global variables. For example: @@ -162,52 +143,12 @@ example.cvar.Shapes_nshapes = 13 # Set a static data member

    General Comments

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

      -

    • SWIG *does* know how to properly perform upcasting of objects in +
    • SWIG does know how to properly perform upcasting of objects in an inheritance hierarchy (including multiple inheritance). Therefore it is perfectly safe to pass an object of a derived class to any function involving a base class. -

      -

    • A wide variety of C++ features are not currently supported by SWIG. Here is the -short and incomplete list: - -

      -

        -
      • Overloaded methods and functions. SWIG wrappers don't know how to resolve name -conflicts so you must give an alternative name to any overloaded method name using the -%name directive like this: - -
        -
        -void foo(int a);  
        -%name(foo2) void foo(double a, double b);
        -
        -
        - -

        -

      • Overloaded operators. Not supported at all. The only workaround for this is -to write a helper function. For example: - -
        -
        -%inline %{
        -    Vector *vector_add(Vector *a, Vector *b) {
        -          ... whatever ...
        -    }
        -%}
        -
        -
        - -

        -

      • Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all). - -

        -

      • Dave's snide remark: Like a large bottle of strong Tequilla, it's better to -use C++ in moderation. +
      • C++ Namespaces - %nspace isn't yet supported for Python.
      diff --git a/Examples/python/class/runme.py b/Examples/python/class/runme.py index f1272ae81..8f4f27eb9 100644 --- a/Examples/python/class/runme.py +++ b/Examples/python/class/runme.py @@ -38,6 +38,8 @@ for o in [c,s]: print " ", o print " area = ", o.area() print " perimeter = ", o.perimeter() +# prevent o from holding a reference to the last object looked at +o = None print "\nGuess I'll clean up now" @@ -45,7 +47,5 @@ print "\nGuess I'll clean up now" del c del s -s = 3 print example.cvar.Shape_nshapes,"shapes remain" print "Goodbye" - diff --git a/Examples/ruby/class/example.cxx b/Examples/ruby/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/ruby/class/example.cxx +++ b/Examples/ruby/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/ruby/class/example.h b/Examples/ruby/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/ruby/class/example.h +++ b/Examples/ruby/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; - virtual double area(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/ruby/class/index.html b/Examples/ruby/class/index.html index 67eeac9ad..1e227342d 100644 --- a/Examples/ruby/class/index.html +++ b/Examples/ruby/class/index.html @@ -12,9 +12,7 @@

      Wrapping a simple C++ class

      -This example illustrates C++ class wrapping performed by SWIG. -C++ classes are simply transformed into Ruby classes that provide methods to -access class members. +This example illustrates wrapping a simple C++ class to give a Python class.

      The C++ Code

      @@ -32,8 +30,8 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); virtual double area() = 0; virtual double perimeter() = 0; @@ -44,7 +42,7 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; + Circle(double r) : radius(r) { } virtual double area(); virtual double perimeter(); }; @@ -53,7 +51,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } virtual double area(); virtual double perimeter(); }; @@ -122,10 +120,8 @@ print "The area is ", c.area, "\n"
  • -

  • When a instance of Ruby level wrapper class is garbage collected by +
  • When a instance of Ruby level wrapper class is garbage collected by the Ruby interpreter, the corresponding C++ destructor is automatically invoked. -(Note: destructors are currently not inherited. This might change later. -Until then, use -make_default).

  • Static member variables are wrapped as Ruby class accessor methods. @@ -144,53 +140,14 @@ Shapes.nshapes = 13 # Set a static data member
    • Ruby module of SWIG differs from other language modules in wrapping C++ -interfaces. They provides lower-level interfaces and optional higher-level +interfaces. They provide lower-level interfaces and optional higher-level interfaces know as proxy classes. Ruby module needs no such redundancy due to Ruby's sophisticated extension API. -

      -

    • SWIG *does* know how to properly perform upcasting of objects in +
    • SWIG does know how to properly perform upcasting of objects in an inheritance hierarchy except for multiple inheritance. -

      -

    • A wide variety of C++ features are not currently supported by SWIG. Here is the -short and incomplete list: - -

      -

        -
      • Overloaded methods and functions. SWIG wrappers don't know how to resolve name -conflicts so you must give an alternative name to any overloaded method name using the -%name directive like this: - -
        -
        -void foo(int a);  
        -%name(foo2) void foo(double a, double b);
        -
        -
        - -

        -

      • Overloaded operators. Not supported at all. The only workaround for this is -to write a helper function. For example: - -
        -
        -%inline %{
        -    Vector *vector_add(Vector *a, Vector *b) {
        -          ... whatever ...
        -    }
        -%}
        -
        -
        - -

        -

      • Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all). - -
      -

      - -

    • Dave's snide remark: Like a large bottle of strong Tequilla, it's better to -use C++ in moderation. +
    • C++ Namespaces - %nspace isn't yet supported for Python.
    diff --git a/Examples/ruby/class/runme.rb b/Examples/ruby/class/runme.rb index de73bcd46..971e149d5 100644 --- a/Examples/ruby/class/runme.rb +++ b/Examples/ruby/class/runme.rb @@ -45,5 +45,9 @@ end # Notice how the Shape#area() and Shape#perimeter() functions really # invoke the appropriate virtual method on each object. +# Remove references to the object and force a garbage collection run. +c = s = o = nil +GC.start() + print "\n", Example::Shape.nshapes," shapes remain\n" print "Goodbye\n" diff --git a/Examples/tcl/class/example.cxx b/Examples/tcl/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/tcl/class/example.cxx +++ b/Examples/tcl/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/tcl/class/example.h b/Examples/tcl/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/tcl/class/example.h +++ b/Examples/tcl/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; - virtual double area(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/tcl/class/example.i b/Examples/tcl/class/example.i index 23ee8a822..75700b305 100644 --- a/Examples/tcl/class/example.i +++ b/Examples/tcl/class/example.i @@ -6,6 +6,5 @@ %} /* Let's just grab the original header file here */ - %include "example.h" diff --git a/Examples/tcl/class/index.html b/Examples/tcl/class/index.html index fd8cfe502..5b09b7a9d 100644 --- a/Examples/tcl/class/index.html +++ b/Examples/tcl/class/index.html @@ -32,8 +32,8 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); virtual double area() = 0; virtual double perimeter() = 0; @@ -44,7 +44,7 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; + Circle(double r) : radius(r) { } virtual double area(); virtual double perimeter(); }; @@ -53,7 +53,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } virtual double area(); virtual double perimeter(); }; @@ -91,10 +91,10 @@ Note: when creating a C++ extension, you must run SWIG with the -c++ op SWIG performs two forms of C++ wrapping-- a low level interface and a high level widget-like interface.
    • -Click here to see a script that calls the C++ functions using the +Click here to see a script that calls the C++ functions using the low-level interface.
    • -Click here to see a the same script written with the high-level +Click here to see the same script written with the high-level interface.
    @@ -225,47 +225,15 @@ set Shapes_nshapes 13 # Set a static data member

    General Comments

      +
    • The low-level function interface is much faster than the high-level interface. In fact, all the higher level interface does is call functions in the low-level interface. -

    • SWIG *does* know how to properly perform upcasting of objects in an inheritance hierarchy (including multiple inheritance). Therefore it is perfectly safe to pass an object of a derived class to any function involving a base class. -

      -

    • A wide variety of C++ features are not currently supported by SWIG. Here is the -short and incomplete list: - -

      -

        -
      • Overloaded methods and functions. SWIG wrappers don't know how to resolve name -conflicts so you must give an alternative name to any overloaded method name using the -%name directive like this: - -
        -
        -void foo(int a);  
        -%name(foo2) void foo(double a, double b);
        -
        -
        - -

        -

      • Overloaded operators. Not supported at all. The only workaround for this is -to write a helper function. For example: - -
        -
        -%inline %{
        -    Vector *vector_add(Vector *a, Vector *b) {
        -          ... whatever ...
        -    }
        -%}
        -
        -
        - -

        -

      • Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all). +
      • C++ Namespaces - %nspace isn't yet supported for Python.
      From d1bfd8a5175cd5cf6ea673a682780055be359477 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sun, 23 Feb 2014 14:23:55 +0400 Subject: [PATCH 1028/1160] add nspace_extend test case --- .../test-suite/lua/nspace_extend_runme.lua | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Examples/test-suite/lua/nspace_extend_runme.lua diff --git a/Examples/test-suite/lua/nspace_extend_runme.lua b/Examples/test-suite/lua/nspace_extend_runme.lua new file mode 100644 index 000000000..d942b7b9d --- /dev/null +++ b/Examples/test-suite/lua/nspace_extend_runme.lua @@ -0,0 +1,39 @@ +require("import") -- the import fn +import("nspace_extend") -- import lib + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +ne = nspace_extend + +-- Inner1 + +-- Constructors +in1_clr1 = ne.Outer.Inner1.Color() +in1_clr2 = ne.Outer.Inner1.Color.create() +in1_clr3 = ne.Outer.Inner1.Color(in1_clr2) + +-- methods +in1_clr1:colorInstanceMethod(1.0) +ne.Outer.Inner1.Color.colorStaticMethod(2.0) + +-- Inner2 + +-- Constructors +in2_clr1 = ne.Outer.Inner2.Color() +in2_clr2 = ne.Outer.Inner2.Color.create() +in2_clr3 = ne.Outer.Inner2.Color(in2_clr2) + +assert(pcall(ne.Outer.Inner2.Color, in1_clr1) == false) + +-- methods +in2_clr1:colorInstanceMethod(1.0) +ne.Outer.Inner2.Color.colorStaticMethod(2.0) + +in2_clr3:colors(in1_clr1, in1_clr2, in2_clr2, in2_clr2, in2_clr3) + +assert(pcall(in2_clr3.colors, in2_clr3, + in2_clr1, in2_clr2, in1_clr2, in2_clr2, in2_clr3) == false) + From be6723df1e2fb4b54ad3df111b19d3b9f5e597ca Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sun, 23 Feb 2014 16:30:23 +0400 Subject: [PATCH 1029/1160] Return MIN_OPT_LEVEL for elua --- Lib/lua/luarun.swg | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 4aaa6eee7..547231815 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -122,6 +122,11 @@ typedef struct swig_elua_entry { #ifndef SWIG_LUA_ELUA_EMULATE #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC) + +#ifndef MIN_OPT_LEVEL +#define MIN_OPT_LEVEL 2 +#endif + #include "lrodefs.h" #include "lrotable.h" #endif From 7f40ae357016709f499ffcc0f55ff87627f56d5d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 23 Feb 2014 15:47:42 +0000 Subject: [PATCH 1030/1160] C# project files update - Update project files to use Visual Studio 2005 (minimum supported .NET is now 2.0 which is what VS 2005 supports). - Add project files for arrays example (requires /unsafe) - Fix support so that the project files work straight out the box on 64 bit systems (32 bit compile is the default). - Fix support for 64 bit builds - use the x64 platform. --- Examples/csharp/arrays/example-cs.csproj | 90 +++++ Examples/csharp/arrays/example-vc.vcproj | 415 ++++++++++++++++++++ Examples/csharp/arrays/example.sln | 38 ++ Examples/csharp/callback/example-cs.csproj | 187 +++++---- Examples/csharp/callback/example-vc.vcproj | 387 +++++++++++++++--- Examples/csharp/callback/example.sln | 44 ++- Examples/csharp/class/example-cs.csproj | 193 +++++---- Examples/csharp/class/example-vc.vcproj | 383 +++++++++++++++--- Examples/csharp/class/example.sln | 44 ++- Examples/csharp/enum/example-cs.csproj | 187 +++++---- Examples/csharp/enum/example-vc.vcproj | 383 +++++++++++++++--- Examples/csharp/enum/example.sln | 44 ++- Examples/csharp/extend/example-cs.csproj | 193 +++++---- Examples/csharp/extend/example-vc.vcproj | 387 +++++++++++++++--- Examples/csharp/extend/example.sln | 44 ++- Examples/csharp/funcptr/example-cs.csproj | 181 ++++----- Examples/csharp/funcptr/example-vc.vcproj | 385 +++++++++++++++--- Examples/csharp/funcptr/example.sln | 44 ++- Examples/csharp/reference/example-cs.csproj | 187 +++++---- Examples/csharp/reference/example-vc.vcproj | 383 +++++++++++++++--- Examples/csharp/reference/example.sln | 44 ++- Examples/csharp/simple/example-cs.csproj | 175 ++++----- Examples/csharp/simple/example-vc.vcproj | 211 +++++++++- Examples/csharp/simple/example.sln | 18 +- Examples/csharp/template/example-cs.csproj | 199 +++++----- Examples/csharp/template/example-vc.vcproj | 382 +++++++++++++++--- Examples/csharp/template/example.sln | 44 ++- Examples/csharp/variables/example-cs.csproj | 187 +++++---- Examples/csharp/variables/example-vc.vcproj | 386 +++++++++++++++--- Examples/csharp/variables/example.sln | 44 ++- 30 files changed, 4327 insertions(+), 1562 deletions(-) create mode 100644 Examples/csharp/arrays/example-cs.csproj create mode 100644 Examples/csharp/arrays/example-vc.vcproj create mode 100644 Examples/csharp/arrays/example.sln diff --git a/Examples/csharp/arrays/example-cs.csproj b/Examples/csharp/arrays/example-cs.csproj new file mode 100644 index 000000000..422c76be3 --- /dev/null +++ b/Examples/csharp/arrays/example-cs.csproj @@ -0,0 +1,90 @@ + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + true + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + true + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + true + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + true + + + + Code + + + Code + + + Code + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/arrays/example-vc.vcproj b/Examples/csharp/arrays/example-vc.vcproj new file mode 100644 index 000000000..d3ee58ec4 --- /dev/null +++ b/Examples/csharp/arrays/example-vc.vcproj @@ -0,0 +1,415 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Examples/csharp/arrays/example.sln b/Examples/csharp/arrays/example.sln new file mode 100644 index 000000000..234bd64d3 --- /dev/null +++ b/Examples/csharp/arrays/example.sln @@ -0,0 +1,38 @@ +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" + ProjectSection(ProjectDependencies) = postProject + {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Examples/csharp/callback/example-cs.csproj b/Examples/csharp/callback/example-cs.csproj index ce5ccfd9a..14d43dcb2 100644 --- a/Examples/csharp/callback/example-cs.csproj +++ b/Examples/csharp/callback/example-cs.csproj @@ -1,99 +1,88 @@ - - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + + + Code + + + Code + + + Code + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/callback/example-vc.vcproj b/Examples/csharp/callback/example-vc.vcproj index 5788bc9c7..5958945e9 100644 --- a/Examples/csharp/callback/example-vc.vcproj +++ b/Examples/csharp/callback/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,43 +348,69 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example.cxx" + > + RelativePath="example_wrap.cxx" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + RelativePath="example.h" + > + + + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + + + + + + diff --git a/Examples/csharp/callback/example.sln b/Examples/csharp/callback/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/callback/example.sln +++ b/Examples/csharp/callback/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/Examples/csharp/class/example-cs.csproj b/Examples/csharp/class/example-cs.csproj index 8b105d7fc..4f6d66ae1 100644 --- a/Examples/csharp/class/example-cs.csproj +++ b/Examples/csharp/class/example-cs.csproj @@ -1,104 +1,89 @@ - - - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + + Code + + + Code + + + Code + + + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/class/example-vc.vcproj b/Examples/csharp/class/example-vc.vcproj index 5788bc9c7..ef870959e 100644 --- a/Examples/csharp/class/example-vc.vcproj +++ b/Examples/csharp/class/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,43 +348,65 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example.cxx" + > + RelativePath="example_wrap.cxx" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + RelativePath="example.h" + > + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + + + + + + diff --git a/Examples/csharp/class/example.sln b/Examples/csharp/class/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/class/example.sln +++ b/Examples/csharp/class/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/Examples/csharp/enum/example-cs.csproj b/Examples/csharp/enum/example-cs.csproj index 44face8ed..5c8bd3cc4 100644 --- a/Examples/csharp/enum/example-cs.csproj +++ b/Examples/csharp/enum/example-cs.csproj @@ -1,99 +1,88 @@ - - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + + Code + + + Code + + + + Code + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/enum/example-vc.vcproj b/Examples/csharp/enum/example-vc.vcproj index 5788bc9c7..ef870959e 100644 --- a/Examples/csharp/enum/example-vc.vcproj +++ b/Examples/csharp/enum/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,43 +348,65 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example.cxx" + > + RelativePath="example_wrap.cxx" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + RelativePath="example.h" + > + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + + + + + + diff --git a/Examples/csharp/enum/example.sln b/Examples/csharp/enum/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/enum/example.sln +++ b/Examples/csharp/enum/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/Examples/csharp/extend/example-cs.csproj b/Examples/csharp/extend/example-cs.csproj index 95923991b..68d202c58 100644 --- a/Examples/csharp/extend/example-cs.csproj +++ b/Examples/csharp/extend/example-cs.csproj @@ -1,104 +1,89 @@ - - - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + + + Code + + + Code + + + + Code + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/extend/example-vc.vcproj b/Examples/csharp/extend/example-vc.vcproj index 5788bc9c7..5958945e9 100644 --- a/Examples/csharp/extend/example-vc.vcproj +++ b/Examples/csharp/extend/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,43 +348,69 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example.cxx" + > + RelativePath="example_wrap.cxx" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + RelativePath="example.h" + > + + + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + + + + + + diff --git a/Examples/csharp/extend/example.sln b/Examples/csharp/extend/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/extend/example.sln +++ b/Examples/csharp/extend/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/Examples/csharp/funcptr/example-cs.csproj b/Examples/csharp/funcptr/example-cs.csproj index 5a107c528..d8c455927 100644 --- a/Examples/csharp/funcptr/example-cs.csproj +++ b/Examples/csharp/funcptr/example-cs.csproj @@ -1,94 +1,87 @@ - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + Code + + + Code + + + Code + + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/funcptr/example-vc.vcproj b/Examples/csharp/funcptr/example-vc.vcproj index 7ba8cbde1..d3ee58ec4 100644 --- a/Examples/csharp/funcptr/example-vc.vcproj +++ b/Examples/csharp/funcptr/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,45 +348,65 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example.c" + > + RelativePath="example_wrap.c" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + RelativePath="example.h" + > + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.c" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.c" + /> + + + + + + diff --git a/Examples/csharp/funcptr/example.sln b/Examples/csharp/funcptr/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/funcptr/example.sln +++ b/Examples/csharp/funcptr/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/Examples/csharp/reference/example-cs.csproj b/Examples/csharp/reference/example-cs.csproj index a3efbe036..c8ad31839 100644 --- a/Examples/csharp/reference/example-cs.csproj +++ b/Examples/csharp/reference/example-cs.csproj @@ -1,99 +1,88 @@ - - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + Code + + + Code + + + Code + + + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/reference/example-vc.vcproj b/Examples/csharp/reference/example-vc.vcproj index 5788bc9c7..ef870959e 100644 --- a/Examples/csharp/reference/example-vc.vcproj +++ b/Examples/csharp/reference/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,43 +348,65 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example.cxx" + > + RelativePath="example_wrap.cxx" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + RelativePath="example.h" + > + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + + + + + + diff --git a/Examples/csharp/reference/example.sln b/Examples/csharp/reference/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/reference/example.sln +++ b/Examples/csharp/reference/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/Examples/csharp/simple/example-cs.csproj b/Examples/csharp/simple/example-cs.csproj index 3d91f9a47..6138dd0ec 100644 --- a/Examples/csharp/simple/example-cs.csproj +++ b/Examples/csharp/simple/example-cs.csproj @@ -1,89 +1,86 @@ - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + Code + + + Code + + + Code + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/simple/example-vc.vcproj b/Examples/csharp/simple/example-vc.vcproj index ec289c6eb..74b504671 100644 --- a/Examples/csharp/simple/example-vc.vcproj +++ b/Examples/csharp/simple/example-vc.vcproj @@ -10,14 +10,17 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -180,11 +351,11 @@ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > @@ -206,6 +377,15 @@ Outputs="$(InputName)_wrap.c" /> + + + @@ -215,6 +395,15 @@ Outputs="$(InputName)_wrap.c" /> + + + diff --git a/Examples/csharp/simple/example.sln b/Examples/csharp/simple/example.sln index 3ebbba5c6..234bd64d3 100644 --- a/Examples/csharp/simple/example.sln +++ b/Examples/csharp/simple/example.sln @@ -1,5 +1,5 @@ Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual C++ Express 2005 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} @@ -10,15 +10,27 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|Any CPU - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|Any CPU + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Examples/csharp/template/example-cs.csproj b/Examples/csharp/template/example-cs.csproj index bf17c141f..782aeacae 100644 --- a/Examples/csharp/template/example-cs.csproj +++ b/Examples/csharp/template/example-cs.csproj @@ -1,109 +1,90 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + Code + + + Code + + + Code + + + + + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/template/example-vc.vcproj b/Examples/csharp/template/example-vc.vcproj index f7bbbcb62..f8a900096 100644 --- a/Examples/csharp/template/example-vc.vcproj +++ b/Examples/csharp/template/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,42 +348,61 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example_wrap.cxx" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + RelativePath="example.h" + > + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + + + + + + diff --git a/Examples/csharp/template/example.sln b/Examples/csharp/template/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/template/example.sln +++ b/Examples/csharp/template/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/Examples/csharp/variables/example-cs.csproj b/Examples/csharp/variables/example-cs.csproj index a73c879fb..d2ce17a6a 100644 --- a/Examples/csharp/variables/example-cs.csproj +++ b/Examples/csharp/variables/example-cs.csproj @@ -1,99 +1,88 @@ - - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + Code + + + Code + + + Code + + + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/variables/example-vc.vcproj b/Examples/csharp/variables/example-vc.vcproj index acd55a379..d3ee58ec4 100644 --- a/Examples/csharp/variables/example-vc.vcproj +++ b/Examples/csharp/variables/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,42 +348,65 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example.c" + > + RelativePath="example_wrap.c" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + + + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.c" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.c" + /> + + + + + + diff --git a/Examples/csharp/variables/example.sln b/Examples/csharp/variables/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/variables/example.sln +++ b/Examples/csharp/variables/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal From 0de4cf13a8aa4612ddead85b2680694fa1bf585e Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 24 Feb 2014 10:10:24 +1300 Subject: [PATCH 1031/1160] Further cleaning up of class examples --- Doc/Manual/Android.html | 26 +++++++-------- Examples/android/class/jni/example.cpp | 8 ++--- Examples/android/class/jni/example.h | 20 ++++++------ Examples/chicken/class/example.h | 25 ++++++--------- Examples/chicken/class/example.i | 1 - Examples/csharp/class/example.h | 25 ++++++--------- Examples/csharp/class/example.i | 1 - Examples/d/class/example.h | 18 +++++------ Examples/d/class/example.i | 1 - Examples/go/class/example.h | 25 ++++++--------- Examples/go/class/example.i | 1 - Examples/guile/class/example.h | 18 +++++------ Examples/java/class/example.i | 1 - Examples/lua/class/example.h | 25 ++++++--------- Examples/lua/class/example.i | 1 - Examples/modula3/class/example.h | 44 ++++++++++---------------- Examples/octave/class/example.h | 18 +++++------ Examples/perl5/class/example.i | 1 - Examples/php/class/example.i | 1 - Examples/pike/class/example.cxx | 32 ++++--------------- Examples/pike/class/example.h | 31 +++++++++--------- Examples/pike/class/example.i | 1 - Examples/python/class/example.i | 1 - Examples/r/class/example.h | 25 ++++++--------- Examples/r/class/example.i | 6 ++-- Examples/ruby/class/example.i | 1 - Examples/ruby/class/index.html | 4 +-- Examples/tcl/class/example.i | 1 - Examples/tcl/class/index.html | 4 +-- 29 files changed, 150 insertions(+), 216 deletions(-) diff --git a/Doc/Manual/Android.html b/Doc/Manual/Android.html index 4d1be3944..e02271169 100644 --- a/Doc/Manual/Android.html +++ b/Doc/Manual/Android.html @@ -435,11 +435,11 @@ public: } virtual ~Shape() { nshapes--; - }; + } double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -447,18 +447,18 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; - virtual double area(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); };
  • @@ -482,19 +482,19 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; }
    diff --git a/Examples/android/class/jni/example.cpp b/Examples/android/class/jni/example.cpp index d59cc7c32..7686159fa 100644 --- a/Examples/android/class/jni/example.cpp +++ b/Examples/android/class/jni/example.cpp @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/android/class/jni/example.h b/Examples/android/class/jni/example.h index 64b7684fa..0dff185b2 100644 --- a/Examples/android/class/jni/example.h +++ b/Examples/android/class/jni/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,16 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; - virtual double area(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; diff --git a/Examples/chicken/class/example.h b/Examples/chicken/class/example.h index 210ba989f..5bad31693 100644 --- a/Examples/chicken/class/example.h +++ b/Examples/chicken/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; enum SomeEnum { @@ -26,21 +26,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; - virtual double area(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/chicken/class/example.i b/Examples/chicken/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/chicken/class/example.i +++ b/Examples/chicken/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/csharp/class/example.h b/Examples/csharp/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/csharp/class/example.h +++ b/Examples/csharp/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; - virtual double area(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/csharp/class/example.i b/Examples/csharp/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/csharp/class/example.i +++ b/Examples/csharp/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/d/class/example.h b/Examples/d/class/example.h index 0d4527e92..0dff185b2 100644 --- a/Examples/d/class/example.h +++ b/Examples/d/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; + } double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,16 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; - virtual double area(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; diff --git a/Examples/d/class/example.i b/Examples/d/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/d/class/example.i +++ b/Examples/d/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/go/class/example.h b/Examples/go/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/go/class/example.h +++ b/Examples/go/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; - virtual double area(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/go/class/example.i b/Examples/go/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/go/class/example.i +++ b/Examples/go/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/guile/class/example.h b/Examples/guile/class/example.h index 0d4527e92..0dff185b2 100644 --- a/Examples/guile/class/example.h +++ b/Examples/guile/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; + } double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,16 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; - virtual double area(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; diff --git a/Examples/java/class/example.i b/Examples/java/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/java/class/example.i +++ b/Examples/java/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/lua/class/example.h b/Examples/lua/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/lua/class/example.h +++ b/Examples/lua/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; - virtual double area(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/lua/class/example.i b/Examples/lua/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/lua/class/example.i +++ b/Examples/lua/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/modula3/class/example.h b/Examples/modula3/class/example.h index 9c1f47995..0dff185b2 100644 --- a/Examples/modula3/class/example.h +++ b/Examples/modula3/class/example.h @@ -1,44 +1,34 @@ /* File : example.h */ -class Shape -{ +class Shape { public: - Shape () - { + Shape() { nshapes++; } - virtual ~ Shape () - { + virtual ~Shape() { nshapes--; - }; - double x, y; - void move (double dx, double dy); - virtual double area (void) const = 0; - virtual double perimeter (void) const = 0; -protected: - static int nshapes; + } + double x, y; + void move(double dx, double dy); + virtual double area() = 0; + virtual double perimeter() = 0; + static int nshapes; }; -class Circle:public Shape -{ +class Circle : public Shape { private: double radius; public: - Circle (double r):radius (r) - { - }; - virtual double area (void) const; - virtual double perimeter (void) const; + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; -class Square:public Shape -{ +class Square : public Shape { private: double width; public: - Square (double w):width (w) - { - }; - virtual double area (void) const; - virtual double perimeter (void) const; + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; diff --git a/Examples/octave/class/example.h b/Examples/octave/class/example.h index 0d4527e92..0dff185b2 100644 --- a/Examples/octave/class/example.h +++ b/Examples/octave/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; + } double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,16 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; - virtual double area(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; diff --git a/Examples/perl5/class/example.i b/Examples/perl5/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/perl5/class/example.i +++ b/Examples/perl5/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/php/class/example.i b/Examples/php/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/php/class/example.i +++ b/Examples/php/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/pike/class/example.cxx b/Examples/pike/class/example.cxx index c7a3194a4..046304519 100644 --- a/Examples/pike/class/example.cxx +++ b/Examples/pike/class/example.cxx @@ -1,46 +1,28 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" - -#include - #define M_PI 3.14159265358979323846 -// Static member initializer -int Shape::nshapes = 0; - -// Constructor -Shape::Shape() { - nshapes++; -} - -// Move the shape to a new location +/* Move the shape to a new location */ void Shape::move(double dx, double dy) { x += dx; y += dy; } -// Destructor -Shape::~Shape() { - nshapes--; -} +int Shape::nshapes = 0; -// Circle area -double Circle::area() const { +double Circle::area() { return M_PI*radius*radius; } -// Circle perimeter -double Circle::perimeter() const { +double Circle::perimeter() { return 2*M_PI*radius; } -// Square area -double Square::area() const { +double Square::area() { return width*width; } -// Square perimeter -double Square::perimeter() const { +double Square::perimeter() { return 4*width; } diff --git a/Examples/pike/class/example.h b/Examples/pike/class/example.h index f74a4fefc..0dff185b2 100644 --- a/Examples/pike/class/example.h +++ b/Examples/pike/class/example.h @@ -2,12 +2,16 @@ class Shape { public: - Shape(); - virtual ~Shape(); - double x, y; + Shape() { + nshapes++; + } + virtual ~Shape() { + nshapes--; + } + double x, y; void move(double dx, double dy); - virtual double area() const = 0; - virtual double perimeter() const = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -15,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area() const; - virtual double perimeter() const; + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; - virtual double area() const; - virtual double perimeter() const; + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/pike/class/example.i b/Examples/pike/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/pike/class/example.i +++ b/Examples/pike/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/python/class/example.i b/Examples/python/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/python/class/example.i +++ b/Examples/python/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/r/class/example.h b/Examples/r/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/r/class/example.h +++ b/Examples/r/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; - virtual double area(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/r/class/example.i b/Examples/r/class/example.i index 4654d269f..fbdf7249f 100644 --- a/Examples/r/class/example.i +++ b/Examples/r/class/example.i @@ -1,9 +1,9 @@ /* File : example.i */ %module example -%inline %{ +%{ #include "example.h" %} + +/* Let's just grab the original header file here */ %include "example.h" - - diff --git a/Examples/ruby/class/example.i b/Examples/ruby/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/ruby/class/example.i +++ b/Examples/ruby/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/ruby/class/index.html b/Examples/ruby/class/index.html index 1e227342d..927c00190 100644 --- a/Examples/ruby/class/index.html +++ b/Examples/ruby/class/index.html @@ -12,7 +12,7 @@

    Wrapping a simple C++ class

    -This example illustrates wrapping a simple C++ class to give a Python class. +This example illustrates wrapping a simple C++ class to give a Ruby class.

    The C++ Code

    @@ -147,7 +147,7 @@ due to Ruby's sophisticated extension API.
  • SWIG does know how to properly perform upcasting of objects in an inheritance hierarchy except for multiple inheritance. -
  • C++ Namespaces - %nspace isn't yet supported for Python. +
  • C++ Namespaces - %nspace isn't yet supported for Ruby. diff --git a/Examples/tcl/class/example.i b/Examples/tcl/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/tcl/class/example.i +++ b/Examples/tcl/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/tcl/class/index.html b/Examples/tcl/class/index.html index 5b09b7a9d..16dbeea4f 100644 --- a/Examples/tcl/class/index.html +++ b/Examples/tcl/class/index.html @@ -229,11 +229,11 @@ set Shapes_nshapes 13 # Set a static data member
  • The low-level function interface is much faster than the high-level interface. In fact, all the higher level interface does is call functions in the low-level interface. -
  • SWIG *does* know how to properly perform upcasting of objects in an inheritance +
  • SWIG does know how to properly perform upcasting of objects in an inheritance hierarchy (including multiple inheritance). Therefore it is perfectly safe to pass an object of a derived class to any function involving a base class. -
  • C++ Namespaces - %nspace isn't yet supported for Python. +
  • C++ Namespaces - %nspace isn't yet supported for Tcl. From 431b9b16e7f8fc36758ac88f29dd9c1a77052984 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 24 Feb 2014 10:11:11 +1300 Subject: [PATCH 1032/1160] Update one dead link and remove another --- Examples/python/index.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Examples/python/index.html b/Examples/python/index.html index 37f4b55af..3bbdd66e8 100644 --- a/Examples/python/index.html +++ b/Examples/python/index.html @@ -56,8 +56,7 @@ Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
  • The politically "correct" way to compile a Python extension is to follow the steps -described at www.python.org -or in the most excellent (and shamelessly plugged) Python Essential Reference: +described at www.python.org:

      From 48476af609a4667b475d4cfaf64d0edd1282956a Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 24 Feb 2014 10:13:11 +1300 Subject: [PATCH 1033/1160] Remove semicolons after function definitions --- Doc/Manual/Java.html | 2 +- Doc/Manual/Python.html | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index c1b42f605..3144341e1 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -6868,7 +6868,7 @@ int spam(double a, double b, double *out1, double *out2) { *out1 = a*10.0; *out2 = b*100.0; return status; -}; +} %} /* diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 4584ff726..522412fc8 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -4688,8 +4688,7 @@ int spam(double a, double b, double *out1, double *out2) { *out1 = result1; *out2 = result2; return status; -}; - +}
  • From 4a94345c9ab9e5b9fd7545ba057ea0cf62985236 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Tue, 25 Feb 2014 12:51:28 +0400 Subject: [PATCH 1034/1160] Switched to Swig_name_* functions --- Source/Modules/lang.cxx | 2 + Source/Modules/lua.cxx | 108 +++++++++++++++++++++++++++++++++++----- 2 files changed, 98 insertions(+), 12 deletions(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 7933d5a49..9420ea719 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2992,6 +2992,8 @@ int Language::variableWrapper(Node *n) { if (make_set_wrapper) { Setattr(n, "varset", "1"); functionWrapper(n); + } else { + Setattr(n, "feature:immutable", "1"); } /* Restore parameters */ Setattr(n, "sym:name", symname); diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index e2bba5bea..000e79a59 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -157,6 +157,8 @@ private: enum TState { NO_CPP, VARIABLE, + GLOBAL_FUNC, + GLOBAL_VAR, MEMBER_FUNC, CONSTRUCTOR, DESTRUCTOR, @@ -464,6 +466,7 @@ public: * --------------------------------------------------------------------- */ // Helper function. Remembers wrap name + // TODO: REMOVE void rememberWrapName(Node *n, String *wrapname) { Setattr(n, "wrap:name", wrapname); // If it is getter/setter, then write wrapname under @@ -542,7 +545,7 @@ public: Wrapper_add_local(f, "SWIG_arg", "int SWIG_arg = 0"); - String *wname = symnameWrapper(iname); + String *wname = Swig_name_wrapper(iname); if (overname) { Append(wname, overname); } @@ -857,7 +860,7 @@ public: String *symname = Getattr(n, "sym:name"); String *lua_name = Getattr(n, "lua:name"); assert(lua_name); - String *wname = symnameWrapper(symname); + String *wname = Swig_name_wrapper(symname); //Printf(stdout,"Swig_overload_dispatch %s %s '%s' %d\n",symname,wname,dispatch,maxargs); @@ -914,19 +917,68 @@ public: return SWIG_OK; } + /* ------------------------------------------------------------ + * Add variable to "attributes" C arrays of given namespace or class. + * Input is node. Base on the state of "current" array it determines + * the name of getter function, setter function etc and calls + * registeVariable overload with necessary params + * Lua scope could be overwritten. (Used only for backward compatibility) + * ------------------------------------------------------------ */ + void registerVariable(Node *n, bool overwrite = false, String *overwriteLuaScope = 0) { + int assignable = is_assignable(n); + String *symname = Getattr(n, "sym:name"); + assert(symname); + + // Lua scope. It is not symbol NSpace, it is actuall key to revrieve + // getCArraysHash. + String *luaScope = luaCurrentSymbolNSpace(); + if (overwrite) + luaScope = overwriteLuaScope; + + // Getter and setter + String *getName = 0; + String *setName = 0; + String *mrename = 0; + if (current[NO_CPP] || !getCurrentClass()) { + // Global variable + getName = Swig_name_get(getNSpace(), symname); + if (assignable) + setName = Swig_name_set(getNSpace(), symname); + } else { + assert(!current[NO_CPP]); + if (current[STATIC_VAR] ) { + mrename = Swig_name_member(getNSpace(), getClassPrefix(), symname); + getName = Swig_name_get(0, mrename); + if (assignable) + setName = Swig_name_set(0, mrename); + } else if (current[MEMBER_VAR]) { + mrename = Swig_name_member(0, getClassPrefix(), symname); + getName = Swig_name_get(getNSpace(), mrename); + if (assignable) + setName = Swig_name_set(getNSpace(), mrename); + } else { + assert(false); + } + } + + getName = Swig_name_wrapper(getName); + if (setName) + setName = Swig_name_wrapper(setName); + //Printf(stdout, "luaname %s, symname %s mrename %s getName %s\n\tscope %s\n\tassignable %d\n", + // Getattr(n, "lua:name"), symname, mrename, getName, luaScope, assignable ); // TODO: REMOVE + registerVariable(luaScope, n, getName, setName); + } /* ------------------------------------------------------------ * Add variable to the "attributes" (or "get"/"set" in * case of elua_ltr) C arrays of given namespace or class * ------------------------------------------------------------ */ - void registerVariable(String *nspace_or_class_name, Node *n, const char *getAttrName, const char *setAttrName) { + void registerVariable(String *lua_nspace_or_class_name, Node *n, String *getName, String *setName) { String *unassignable = NewString("SWIG_Lua_set_immutable"); - String *getName = Getattr(n, getAttrName); - String *setName = Getattr(n, setAttrName); if (setName == 0 || GetFlag(n, "feature:immutable")) { setName = unassignable; } - Hash *nspaceHash = getCArraysHash(nspace_or_class_name); + Hash *nspaceHash = getCArraysHash(lua_nspace_or_class_name); String *s_ns_methods_tab = Getattr(nspaceHash, "methods"); String *s_ns_var_tab = Getattr(nspaceHash, "attributes"); String *lua_name = Getattr(n, "lua:name"); @@ -961,7 +1013,12 @@ public: current[VARIABLE] = true; // let SWIG generate the wrappers int result = Language::variableWrapper(n); - registerVariable(luaCurrentSymbolNSpace(), n, "varget:wrap:name", "varset:wrap:name"); + // TODO: REMOVE + //registerVariable(luaCurrentSymbolNSpace(), n, "varget:wrap:name", "varset:wrap:name"); + + // It is impossible to use registerVariable, because sym:name of the Node is currenly + // in undefined states - the callees of this function may have modified it. + // registerVariable should be used from respective callees.* current[VARIABLE] = false; return result; } @@ -1473,7 +1530,7 @@ public: // REPORT("membervariableHandler",n); current[MEMBER_VAR] = true; Language::membervariableHandler(n); - registerVariable(luaCurrentSymbolNSpace(), n, "memberget:wrap:name", "memberset:wrap:name"); + registerVariable(n); current[MEMBER_VAR] = false; return SWIG_OK; } @@ -1515,15 +1572,35 @@ public: * 2. During class parsing for functions declared/defined as friend * 3. During class parsing from staticmemberfunctionHandler * ---------------------------------------------------------------------- */ - int globalfunctionHandler(Node *n) { + virtual int globalfunctionHandler(Node *n) { bool oldVal = current[NO_CPP]; if (!current[STATIC_FUNC]) // If static funct, don't switch to NO_CPP current[NO_CPP] = true; - int result = Language::globalfunctionHandler(n); + const int result = Language::globalfunctionHandler(n); current[NO_CPP] = oldVal; return result; } + /* ---------------------------------------------------------------------- + * globalvariableHandler() + * globalfunctionHandler() + * Sets "current" array correctly and calls + * Language::globalvariableHandler() + * ---------------------------------------------------------------------- */ + virtual int globalvariableHandler(Node *n) { + bool oldVal = current[NO_CPP]; + current[GLOBAL_VAR] = true; + current[NO_CPP] = true; + + const int result = Language::globalvariableHandler(n); + registerVariable(n); + + current[GLOBAL_VAR] = false; + current[NO_CPP] = oldVal; + return result; + } + + /* ----------------------------------------------------------------------- * staticmemberfunctionHandler() * @@ -1533,7 +1610,7 @@ public: virtual int staticmemberfunctionHandler(Node *n) { REPORT("staticmemberfunctionHandler", n); current[STATIC_FUNC] = true; - int result = Language::staticmemberfunctionHandler(n); + const int result = Language::staticmemberfunctionHandler(n); current[STATIC_FUNC] = false;; if (result != SWIG_OK) @@ -1574,17 +1651,24 @@ public: current[STATIC_VAR] = true; //String *symname = Getattr(n, "sym:name"); int result = Language::staticmembervariableHandler(n); + if (!GetFlag(n, "wrappedasconstant")) { + registerVariable(n); + } if (result == SWIG_OK) { // This will add static member variable to the class namespace with name ClassName_VarName if (v2_compatibility) { Swig_save("lua_staticmembervariableHandler", n, "lua:name", NIL); String *lua_name = Getattr(n, "lua:name"); + // Although this function uses Swig_name_member, it actually generateds Lua name, + // not C++ name. It is because previous version used such scheme for static vars + // name generation and we have to maintain backward compatibility String *v2_name = Swig_name_member(NIL, proxy_class_name, lua_name); //Printf( stdout, "Name %s, class %s, compt. name %s\n", lua_name, proxy_class_name, v2_name ); // TODO: REMOVE if (!GetFlag(n, "wrappedasconstant")) { Setattr(n, "lua:name", v2_name); - registerVariable(getNSpace(), n, "varget:wrap:name", "varset:wrap:name"); + // Registering static var in the class parent nspace + registerVariable(n, true, getNSpace()); } // If static member variable was wrapped as constant, then // constant wrapper has already performed all actions From fadc9c8f313bf95e4effcc5e2cafd494d60c27ad Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Tue, 25 Feb 2014 14:11:53 +0400 Subject: [PATCH 1035/1160] Fixed registerMethod to work like registerVariable --- Source/Modules/lua.cxx | 136 +++++++++++++++++++---------------------- 1 file changed, 63 insertions(+), 73 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 000e79a59..105d1a1b4 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -465,28 +465,49 @@ public: * Create a function declaration and register it with the interpreter. * --------------------------------------------------------------------- */ - // Helper function. Remembers wrap name - // TODO: REMOVE - void rememberWrapName(Node *n, String *wrapname) { - Setattr(n, "wrap:name", wrapname); - // If it is getter/setter, then write wrapname under - // wrap:memberset/wrap:memberget accordingly - if (Getattr(n, "memberset")) - Setattr(n, "memberset:wrap:name", wrapname); - if (Getattr(n, "varset")) - Setattr(n, "varset:wrap:name", wrapname); - if (Getattr(n, "memberget")) - Setattr(n, "memberget:wrap:name", wrapname); - if (Getattr(n, "varget")) - Setattr(n, "varget:wrap:name", wrapname); + /* ----------------------------------------------------------------------- + * registerMethod() + * + * Determines wrap name of a method, it's scope etc and calls + * registerMethod overload with correct arguments + * Overloaded variant adds method to the "methods" array of specified lua scope/class + * ---------------------------------------------------------------------- */ + void registerMethod(Node *n, bool overwrite = false, String *overwriteLuaScope = 0) { + String *symname = Getattr(n, "sym:name"); + assert(symname); + + if (Getattr(n, "sym:nextSibling")) + return; + + // Lua scope. It is not symbol NSpace, it is actuall key to revrieve + // getCArraysHash. + String *luaScope = luaCurrentSymbolNSpace(); + if (overwrite) + luaScope = overwriteLuaScope; + + String *wrapname = 0; + String *mrename; + if (current[NO_CPP] || !getCurrentClass()) { + mrename = symname; + } else { + assert(!current[NO_CPP]); + if (current[STATIC_FUNC] || current[MEMBER_FUNC]) { + mrename = Swig_name_member(getNSpace(), getClassPrefix(), symname); + } else { + mrename = symname; + } + } + wrapname = Swig_name_wrapper(mrename); + //Printf(stdout, "luaname %s, symname %s mrename %s wrapname %s\n\tscope %s\n", + // Getattr(n, "lua:name"), symname, mrename, wrapname, luaScope ); // TODO: REMOVE + registerMethod(n, wrapname, luaScope); } // Add method to the "methods" C array of given namespace/class - void registerMethod(String *nspace_or_class_name, Node *n) { + void registerMethod(Node *n, String* wname, String *luaScope) { assert(n); - Hash *nspaceHash = getCArraysHash(nspace_or_class_name); + Hash *nspaceHash = getCArraysHash(luaScope); String *s_ns_methods_tab = Getattr(nspaceHash, "methods"); - String *wname = Getattr(n, "wrap:name"); String *lua_name = Getattr(n, "lua:name"); if (elua_ltr || eluac_ltr) Printv(s_ns_methods_tab, tab4, "{LSTRKEY(\"", lua_name, "\")", ", LFUNCVAL(", wname, ")", "},\n", NIL); @@ -504,16 +525,6 @@ public: } } - // Helper for functionWrapper - determines whether we should - // register method in the appropriate class/namespace/module - // table or not. - // (not => it is variable wrapper or something similar) - bool functionWrapperRegisterNow() const { - if (current[VARIABLE]) - return false; - return (current[NO_CPP] || current[STATIC_FUNC]); - } - virtual int functionWrapper(Node *n) { REPORT("functionWrapper", n); @@ -726,7 +737,7 @@ public: } // Remember C name of the wrapping function - rememberWrapName(n, wname); + Setattr(n, "wrap:name", wname); /* Emit the function call */ String *actioncode = emit_action(n); @@ -814,9 +825,11 @@ public: /* Now register the function with the interpreter. */ int result = SWIG_OK; if (!Getattr(n, "sym:overloaded")) { + /* TODO: REMOVE if (functionWrapperRegisterNow()) { // emit normal fns & static fns - registerMethod(luaCurrentSymbolNSpace(), n); + registerMethod(n); } + */ } else { if (!Getattr(n, "sym:nextSibling")) { result = dispatchFunction(n); @@ -899,11 +912,12 @@ public: Wrapper_print(f, f_wrappers); // Remember C name of the wrapping function - rememberWrapName(n, wname); + Setattr(n, "wrap:name", wname); + /* TODO: REMOVE if (functionWrapperRegisterNow()) { // emit normal fns & static fns - registerMethod(luaCurrentSymbolNSpace(), n); - } + registerMethod(n); + }*/ if (current[CONSTRUCTOR]) { if (constructor_name != 0) Delete(constructor_name); @@ -970,6 +984,8 @@ public: } /* ------------------------------------------------------------ + * registerVariable() + * * Add variable to the "attributes" (or "get"/"set" in * case of elua_ltr) C arrays of given namespace or class * ------------------------------------------------------------ */ @@ -1075,7 +1091,7 @@ public: Setattr(n, "sym:name", lua_name); /* Special hook for member pointer */ if (SwigType_type(type) == T_MPOINTER) { - String *wname = symnameWrapper(iname); + String *wname = Swig_name_wrapper(iname); Printf(f_wrappers, "static %s = %s;\n", SwigType_str(type, wname), value); value = Char(wname); } @@ -1514,10 +1530,8 @@ public: current[MEMBER_FUNC] = true; Language::memberfunctionHandler(n); - if (!Getattr(n, "sym:nextSibling")) { - //Printf( stdout, "add member function: %s to %s\n", symname, luaCurrentSymbolNSpace());// TODO: REMOVE - registerMethod(luaCurrentSymbolNSpace(), n); - } + //Printf( stdout, "add member function: %s to %s\n", symname, luaCurrentSymbolNSpace());// TODO: REMOVE + registerMethod(n); current[MEMBER_FUNC] = false; return SWIG_OK; } @@ -1577,6 +1591,9 @@ public: if (!current[STATIC_FUNC]) // If static funct, don't switch to NO_CPP current[NO_CPP] = true; const int result = Language::globalfunctionHandler(n); + + if (!current[STATIC_FUNC]) // Register only if not called from static funct handler + registerMethod(n); current[NO_CPP] = oldVal; return result; } @@ -1610,23 +1627,25 @@ public: virtual int staticmemberfunctionHandler(Node *n) { REPORT("staticmemberfunctionHandler", n); current[STATIC_FUNC] = true; + const int result = Language::staticmemberfunctionHandler(n); + registerMethod(n); - current[STATIC_FUNC] = false;; - if (result != SWIG_OK) - return result; - - if (v2_compatibility) { + if (v2_compatibility && result == SWIG_OK) { Swig_require("lua_staticmemberfunctionHandler", n, "*lua:name", NIL); String *lua_name = Getattr(n, "lua:name"); + // Although this function uses Swig_name_member, it actually generateds Lua name, + // not C++ name. It is because previous version used such scheme for static func + // name generation and we have to maintain backward compatibility String *compat_name = Swig_name_member(0, proxy_class_name, lua_name); Setattr(n, "lua:name", compat_name); - registerMethod(getNSpace(), n); + registerMethod(n, true, getNSpace()); Delete(compat_name); Swig_restore(n); } - return SWIG_OK; + current[STATIC_FUNC] = false;; + return result; } /* ------------------------------------------------------------ @@ -2194,35 +2213,6 @@ public: return result; } - /* ----------------------------------------------------------------------------- - * fullyQualifiedName() - * Function creates fully qualified name of given symbol. The scope is deremined - * automatically based on luaCurrentSymbolNSpace() - * ----------------------------------------------------------------------------- */ - String *fullyQualifiedName(const_String_or_char_ptr name) { - assert(name); - String *scope = luaCurrentSymbolNSpace(); - - String *fqname = 0; - if (scope) - fqname = NewStringf("%s::%s", scope, name); - else - fqname = Copy(name); - - return fqname; - } - - /* ----------------------------------------------------------------------------- - * symnameWrapper() - * Input: symname - * Output - Swig_name_wrapper around fully qualified form of symname - * ----------------------------------------------------------------------------- */ - String *symnameWrapper(String *symname) { - String *fqname = fullyQualifiedName(symname); - String *wname = Swig_name_wrapper(fqname); - Delete(fqname); - return wname; - } }; /* NEW LANGUAGE NOTE:*********************************************** From c6dd6b0726342b32579a0b6467128804581b9f92 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Tue, 25 Feb 2014 14:36:03 +0400 Subject: [PATCH 1036/1160] Fixing registerClass. No more wrap: unnecessary attributes --- Source/Modules/lua.cxx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 105d1a1b4..6c9e69050 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -1014,7 +1014,6 @@ public: /* ------------------------------------------------------------ * variableWrapper() * ------------------------------------------------------------ */ - virtual int variableWrapper(Node *n) { /* NEW LANGUAGE NOTE:*********************************************** Language::variableWrapper(n) will generate two wrapper fns @@ -1239,8 +1238,7 @@ public: * Helper function that adds record to appropriate * C arrays * ------------------------------------------------------------ */ - void registerClass(String *scope, Node *n) { - String *wrap_class = Getattr(n,"wrap:class_name"); + void registerClass(String *scope, String *wrap_class) { assert(wrap_class); Hash *nspaceHash = getCArraysHash(scope); String *ns_classes = Getattr(nspaceHash, "classes"); @@ -1354,16 +1352,15 @@ public: SwigType_add_pointer(t); // Catch all: eg. a class with only static functions and/or variables will not have 'remembered' - String *wrap_class_name = NewStringf("_wrap_class_%s", mangled_full_proxy_class_name); + String *wrap_class_name = Swig_name_wrapper(NewStringf("class_%s", mangled_full_proxy_class_name)); String *wrap_class = NewStringf("&%s", wrap_class_name); - Setattr(n, "wrap:class_name", wrap_class_name); SwigType_remember_clientdata(t, wrap_class); String *rt = Copy(getClassType()); SwigType_add_pointer(rt); // Adding class to apropriate namespace - registerClass(nspace, n); + registerClass(nspace, wrap_class_name); Hash *nspaceHash = getCArraysHash(nspace); // Register the class structure with the type checker From 3aa689d276158fc89921d98ee928cfb68465b943 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 26 Feb 2014 00:13:18 +0000 Subject: [PATCH 1037/1160] Add summary about nested class support added over the last few months --- CHANGES.current | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 50f3decd1..791665901 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -39,6 +39,29 @@ Version 3.0.0 (in progress) 2014-02-15: wsfulton [Java] Add support for the cdata library. +2014-02-08: vkalinin + Nested class support added. This primarily allows SWIG to properly parse nested + classes and keep the nested class information in the parse tree. Java and C# + have utilised this information wrapping the C++ nested classes as Java/C# + nested classes. The remaining target languages ignore nested classes as in + previous versions. Help is needed by users of these remaining languages to + design how C++ nested classes can be best wrapped. Please talk to us on the + swig-devel mailing list if you think you can help. + + Previously, there was limited nested class support. Nested classes were treated + as opaque pointers. However, the "nestedworkaround" feature provided a way to + wrap a nested class as if it was a global class. This feature no longer exists + and is replaced by the new "flatnested" feature. This effectively does the same + thing with less manual code to be written. Please see the 'Nested classes' + section in the documentation in SWIGPlus.html if you were previously using this + feature. + + SWIG now parses the contents of nested classes where previously it did not. You + may find that you will need to make adjustments to your interface file as + effectively extra code is being wrapped. + + *** POTENTIAL INCOMPATIBILITY *** + 2014-02-06: gjanssens [Guile] Patch #133. Make scm to string conversion work with non-ascii strings. Guile 2 has a completely rewritten string implementation. SWIG made some assumptions From c36800713bf3803c335af15550fdcfd21fc77224 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 27 Feb 2014 20:12:53 +0000 Subject: [PATCH 1038/1160] Use unix fileformat --- Examples/test-suite/lua/nspace_runme.lua | 134 +++++++++++------------ 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/Examples/test-suite/lua/nspace_runme.lua b/Examples/test-suite/lua/nspace_runme.lua index 2ed8a86b7..5d55357c0 100644 --- a/Examples/test-suite/lua/nspace_runme.lua +++ b/Examples/test-suite/lua/nspace_runme.lua @@ -1,67 +1,67 @@ -require("import") -- the import fn -import("nspace") -- import lib - --- catch "undefined" global variables -local env = _ENV -- Lua 5.2 -if not env then env = getfenv () end -- Lua 5.1 -setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) - -ns = nspace - --- Inheritance -blue1 = ns.Outer.Inner3.Blue() - --- blue1:blueInstanceMethod() -blue1:colorInstanceMethod(60.0) -blue1.instanceMemberVariable = 4 -assert( blue1.instanceMemberVariable == 4 ) - --- Constructors -color1 = ns.Outer.Inner1.Color() -color2 = ns.Outer.Inner1.Color.create() -color = ns.Outer.Inner1.Color(color1) -color3 = ns.Outer.Inner2.Color.create() -color4 = ns.Outer.Inner2.Color.create() -color5 = ns.Outer.Inner2.Color.create() -mwp2 = ns.Outer.MyWorldPart2() -gc = ns.GlobalClass() - -nnsp = ns.NoNSpacePlease() - --- Class methods -color:colorInstanceMethod(20.0) -ns.Outer.Inner1.Color.colorStaticMethod(30.0) -color3:colorInstanceMethod(40.0) -ns.Outer.Inner2.Color.colorStaticMethod(50.0) -color3:colors(color1, color2, color3, color4, color5) - -gc:gmethod() - --- Class variables -color.instanceMemberVariable = 5 -color1.instanceMemberVariable = 7 -assert( color.instanceMemberVariable == 5 ) -assert( color1.instanceMemberVariable == 7 ) -assert(ns.Outer.Inner1.Color.staticMemberVariable == 0 ) -assert(ns.Outer.Inner2.Color.staticMemberVariable == 0 ) -ns.Outer.Inner1.Color.staticMemberVariable = 9 -ns.Outer.Inner2.Color.staticMemberVariable = 11 -assert(ns.Outer.Inner1.Color.staticMemberVariable == 9) -assert(ns.Outer.Inner2.Color.staticMemberVariable == 11) - --- Class constants -assert( ns.Outer.Inner1.Color.Specular == 0x20 ) -assert( ns.Outer.Inner2.Color.Specular == 0x40 ) -assert( ns.Outer.Inner1.Color.staticConstMemberVariable == 222 ) -assert( ns.Outer.Inner2.Color.staticConstMemberVariable == 333 ) -assert( ns.Outer.Inner1.Color.staticConstEnumMemberVariable ~= ns.Outer.Inner2.Color.staticConstEnumMemberVariable ) - - --- Aggregation -sc = ns.Outer.SomeClass() -assert( sc:GetInner1ColorChannel() ~= sc:GetInner2Channel() ) -assert( sc:GetInner1Channel() ~= sc:GetInner2Channel() ) - - - - +require("import") -- the import fn +import("nspace") -- import lib + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +ns = nspace + +-- Inheritance +blue1 = ns.Outer.Inner3.Blue() + +-- blue1:blueInstanceMethod() +blue1:colorInstanceMethod(60.0) +blue1.instanceMemberVariable = 4 +assert( blue1.instanceMemberVariable == 4 ) + +-- Constructors +color1 = ns.Outer.Inner1.Color() +color2 = ns.Outer.Inner1.Color.create() +color = ns.Outer.Inner1.Color(color1) +color3 = ns.Outer.Inner2.Color.create() +color4 = ns.Outer.Inner2.Color.create() +color5 = ns.Outer.Inner2.Color.create() +mwp2 = ns.Outer.MyWorldPart2() +gc = ns.GlobalClass() + +nnsp = ns.NoNSpacePlease() + +-- Class methods +color:colorInstanceMethod(20.0) +ns.Outer.Inner1.Color.colorStaticMethod(30.0) +color3:colorInstanceMethod(40.0) +ns.Outer.Inner2.Color.colorStaticMethod(50.0) +color3:colors(color1, color2, color3, color4, color5) + +gc:gmethod() + +-- Class variables +color.instanceMemberVariable = 5 +color1.instanceMemberVariable = 7 +assert( color.instanceMemberVariable == 5 ) +assert( color1.instanceMemberVariable == 7 ) +assert(ns.Outer.Inner1.Color.staticMemberVariable == 0 ) +assert(ns.Outer.Inner2.Color.staticMemberVariable == 0 ) +ns.Outer.Inner1.Color.staticMemberVariable = 9 +ns.Outer.Inner2.Color.staticMemberVariable = 11 +assert(ns.Outer.Inner1.Color.staticMemberVariable == 9) +assert(ns.Outer.Inner2.Color.staticMemberVariable == 11) + +-- Class constants +assert( ns.Outer.Inner1.Color.Specular == 0x20 ) +assert( ns.Outer.Inner2.Color.Specular == 0x40 ) +assert( ns.Outer.Inner1.Color.staticConstMemberVariable == 222 ) +assert( ns.Outer.Inner2.Color.staticConstMemberVariable == 333 ) +assert( ns.Outer.Inner1.Color.staticConstEnumMemberVariable ~= ns.Outer.Inner2.Color.staticConstEnumMemberVariable ) + + +-- Aggregation +sc = ns.Outer.SomeClass() +assert( sc:GetInner1ColorChannel() ~= sc:GetInner2Channel() ) +assert( sc:GetInner1Channel() ~= sc:GetInner2Channel() ) + + + + From 52c106d27fe4659d213ba69de3ea3a4e369da4d3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 27 Feb 2014 20:23:32 +0000 Subject: [PATCH 1039/1160] Revert unnecessary changes in keyword_rename test --- Examples/test-suite/keyword_rename.i | 2 -- 1 file changed, 2 deletions(-) diff --git a/Examples/test-suite/keyword_rename.i b/Examples/test-suite/keyword_rename.i index a9f58ebef..46c3338b3 100644 --- a/Examples/test-suite/keyword_rename.i +++ b/Examples/test-suite/keyword_rename.i @@ -32,10 +32,8 @@ KW(go, defer) KW(chan, fallthrough) /* Lua keywords */ -#ifdef SWIGLUA KW(end, function) KW(nil,local) -#endif %} From e208f85beaac946c5e8536e088b148a880856f37 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 28 Feb 2014 07:49:11 +0000 Subject: [PATCH 1040/1160] Lua html documentation fixes/improvements. --- Doc/Manual/Lua.html | 65 +++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index 379fdfc94..f2dd45197 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -357,8 +357,10 @@ creates a built-in function example.fact(n) that works exactly like you >

    -To avoid name collisions, SWIG create a Lua table which it keeps all the functions, constants, classes and global variables in. It is possible to copy the functions, constants and classes (but not variables) out of this and into the global environment with the following code. This can easily overwrite existing functions, so this must be used with care. -This option is considered deprecated and will be removed in near future. +To avoid name collisions, SWIG create a Lua table which keeps all the functions, constants, classes and global variables in. +It is possible to copy the functions, constants and classes (but not variables) out of this and into the global environment with the following code. +This can easily overwrite existing functions, so this must be used with care. +This option is considered deprecated and will be removed in the near future.

     > for k,v in pairs(example) do _G[k]=v end
    @@ -502,12 +504,12 @@ Hello World
     
     

    Constants/enums and classes/structures

    -Unlike previous version of bindings, enums are now exported into class table. For example, given some enums: +Enums are exported into a class table. For example, given some enums:

    %module example
    -enum Days{SUNDAY = 0,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY};
    -class Test {
    -    enum { TEST1 = 10, TEST2 = 10 }
    +enum Days { SUNDAY = 0, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY };
    +struct Test {
    +    enum { TEST1 = 10, TEST2 = 20 };
         static const int ICONST = 12;
     };
     
    @@ -522,9 +524,10 @@ This is 'effectively' converted into the following Lua code: > print(example.Test.ICONST) 12
    -

    Backward compatibility

    +

    -If -no-old-metatable-bindings option is not given, then in addition to previously described bindings, the old-style ones are generated: +Compatibility Note: Versions of SWIG prior to SWIG-3.0.0 did not generate the class table members above. +The following code was the only way to access these constants/enums:

     > print(example.Test_TEST1)
    @@ -533,7 +536,11 @@ If -no-old-metatable-bindings option is not given, then in addition to
     12
     

    -However, in C mode, names of enums are not prefixed with names of structure. This is the due to C Standard. +The old-style bindings are still generated in addition to the new ones. +If the -no-old-metatable-bindings option is used, then these old-style bindings are not generated. +

    +

    +However, in C mode, names of enums are not prefixed with names of structure. This is the due to the C Standard.

     > print(example.TEST1)
    @@ -542,7 +549,7 @@ However, in C mode, names of enums are not prefixed with names of structure. Thi
     12
     

    -It worth mentioning, that example.Test.TEST1 and example.Test_TEST1 are different entities and changind one wouldn't change another. +It is worth mentioning, that example.Test.TEST1 and example.Test_TEST1 are different entities and changing one does not change the other. Given the fact, that these are constantes and they are not supposed to be changed, it is up to you to avoid such issues.

    26.3.5 Pointers

    @@ -747,13 +754,18 @@ It is not (currently) possible to access static members of an instance: -- does NOT work -

    Backward compatibility

    -

    If -no-old-metatable-bindings option is not given, then backward compatible names are generated in addition to ordinary ones:

    +Compatibility Note: In versions prior to SWIG-3.0.0 only the following names would work:
     > example.Spam_foo()            -- calling Spam::foo()
     > a=example.Spam_bar            -- reading Spam::bar 
     > example.Spam_bar=b            -- writing to Spam::bar
     
    + +

    +Both style names are generated by default now. +However, if the -no-old-metatable-bindings option is used, then the backward compatible names are not generated in addition to ordinary ones. +

    +

    26.3.8 C++ inheritance

    @@ -1318,37 +1330,38 @@ and the "Exception handling add exception specification to functions or globally (respectively).

    -

    26.3.17 Namespaces

    +

    26.3.17 Namespaces

    -Since SWIG 3.0 C++ namespaces are supported. You can enabled handling namespaces with %nspace feature. Everything below is valid only after you enabled %nspace. +Since SWIG-3.0.0 C++ namespaces are supported via the %nspace feature.

    -

    Namespaces are mapped into lua tables. Each of those tables contains names that were defined within appropriate namespace. Namespaces structure (a.k.a nested namespaces) is preserved. Consider the following C++ code: +

    Namespaces are mapped into Lua tables. Each of those tables contains names that were defined within appropriate namespace. Namespaces structure (a.k.a nested namespaces) is preserved. Consider the following C++ code:

    %module example
     %nspace MyWorld::Nested::Dweller;
     %nspace MyWorld::World;
    -/* and so on */
    -int module_function() { return 7;}
    -int module_variable; // = 9
    +
    +int module_function() { return 7; }
    +int module_variable = 9;
    +
     namespace MyWorld {
       class World {
       public:
    -    int create_world() { return 17;}
    +    int create_world() { return 17; }
         const int world_max_count = 9;
       };
       namespace Nested {
         class Dweller {
    -      enum Gender {MALE, FEMALE;
    +      enum Gender { MALE, FEMALE };
           static int populate_cave() { return 19; }
    -      int create_cave() { return 13;}
    +      int create_cave() { return 13; }
           int food_count; // = 11
    -    }
    +    };
       }
     }
     
    -Now, in Lua it could be used like this: +Now, from Lua usage is as follows:
    -> example.module_function()
    +> print(example.module_function())
     7
     > print(example.module_variable)
     8
    @@ -1356,9 +1369,9 @@ Now, in Lua it could be used like this:
     17
     > print(example.MyWorld.World.world_max_count)
     9
    -> print(example.MyWordl.Nested.Dweller.MALE)
    +> print(example.MyWorld.Nested.Dweller.MALE)
     0
    -> print(example.MyWordl.Nested.Dweller().food_count)
    +> print(example.MyWorld.Nested.Dweller().food_count)
     11
     >
     
    From 58caa386167a8817a9d158be9fd51b6c214ab26d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 28 Feb 2014 18:19:43 +0000 Subject: [PATCH 1041/1160] Restore Lua C++11 rvalue reference --- Lib/lua/lua.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg index 40087236b..60e418596 100644 --- a/Lib/lua/lua.swg +++ b/Lib/lua/lua.swg @@ -41,7 +41,7 @@ %typemap(consttab) long long, unsigned long long {SWIG_LUA_CONSTTAB_STRING("$symname", "$value")} -%typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE [] +%typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { SWIG_LUA_CONSTTAB_POINTER("$symname",$value, $1_descriptor) } // member function pointers From f011481f2b120960720f628ebcc4332ae069ef0f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 28 Feb 2014 19:15:23 +0000 Subject: [PATCH 1042/1160] Cosmetic tweaks to lua runtime --- Lib/lua/luarun.swg | 65 ++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 547231815..b3ecb374b 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -385,9 +385,8 @@ SWIGINTERN int SWIG_Lua_set_immutable(lua_State *L) SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *type, int own); SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_type_info *type); static int swig_lua_elua_emulate_unique_key; -/* This is function that emulates eLua rotables behaviour. It loads rotable definition - * into the usual lua table. - */ + +/* This function emulates eLua rotables behaviour. It loads a rotable definition into the usual lua table. */ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_entry *table) { assert(lua_istable(L,-1)); @@ -654,11 +653,10 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State *L, swig_lua_namespace * return 0; } -/* Register all classes in the namespace - */ +/* Register all classes in the namespace */ SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace *ns) { - /* There must be module/namespace table at the top of the stack */ + /* There must be a module/namespace table at the top of the stack */ assert(lua_istable(L,-1)); swig_lua_class **classes = ns->ns_classes; @@ -671,10 +669,10 @@ SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace } } -/* helper function. creates namespace table and add it to module table +/* Helper function. Creates namespace table and adds it to module table if 'reg' is true, then will register namespace table to parent one (must be on top of the stack - when function is called) - Function always returns newly registered table on top of the stack + when function is called). + Function always returns newly registered table on top of the stack. */ SWIGINTERN int SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, int reg) { @@ -726,13 +724,14 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, assert(lua_gettop(L) == begin+1); } #endif /* SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA */ + /* ----------------------------------------------------------------------------- * global variable support code: classes * ----------------------------------------------------------------------------- */ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname); -/* Macroses for iteration among class bases */ +/* Macros for iteration among class bases */ #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) #define SWIG_LUA_INIT_BASE_SEARCH(bases_count)\ SWIG_Lua_get_table(L,".bases");\ @@ -783,7 +782,8 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, i int bases_count; SWIG_LUA_INIT_BASE_SEARCH(bases_count); int result = SWIG_ERROR; - if(ret) *ret = 0; + if(ret) + *ret = 0; if(bases_count>0) { int i; @@ -795,8 +795,7 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, i int subcall_last_arg = lua_gettop(L); swig_type_info *base_swig_type = 0; - /* Trick: temporaly replacing original metatable - * with metatable for base class and call getter */ + /* Trick: temporarily replacing original metatable with metatable for base class and call getter */ for(i=0;imethods[i].name,clss->methods[i].func); } lua_pop(L,1); /* tidy stack (remove table) */ - /* add operator overloads + /* add operator overloads This adds methods from metatable array to metatable. Can mess up garbage collectind if someone defines __gc method */ @@ -1298,7 +1301,7 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *cls assert( lua_gettop(L) == begin ); } -/* performs the instance(non-static) class registration process. Metatable for class is created +/* Performs the instance (non-static) class registration process. Metatable for class is created * and added to the class registry. */ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *clss) @@ -1386,7 +1389,7 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss) { - assert(lua_istable(L,-1)); /* This is table(module or namespace) where class will be added */ + assert(lua_istable(L,-1)); /* This is a table (module or namespace) where classes will be added */ SWIG_Lua_class_register_instance(L,clss); SWIG_Lua_class_register_static(L,clss); From 0da97a9d3ed6dc8fede5f7693b43fd5fac96e1fb Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 28 Feb 2014 19:19:44 +0000 Subject: [PATCH 1043/1160] Fix illegal C++ symbols --- Lib/lua/luarun.swg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index b3ecb374b..ec6052fe5 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -1459,7 +1459,7 @@ SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_cla * ----------------------------------------------------------------------------- */ /* helper to add metatable to new lua object */ -SWIGINTERN void _SWIG_Lua_AddMetatable(lua_State *L,swig_type_info *type) +SWIGINTERN void SWIG_Lua_AddMetatable(lua_State *L,swig_type_info *type) { if (type->clientdata) /* there is clientdata: so add the metatable */ { @@ -1488,7 +1488,7 @@ SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *t usr->type=type; usr->own=own; #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) - _SWIG_Lua_AddMetatable(L,type); /* add metatable */ + SWIG_Lua_AddMetatable(L,type); /* add metatable */ #endif } @@ -1542,7 +1542,7 @@ SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_t raw->type=type; raw->own=0; memcpy(raw->data,ptr,size); /* copy the data */ - _SWIG_Lua_AddMetatable(L,type); /* add metatable */ + SWIG_Lua_AddMetatable(L,type); /* add metatable */ } /* converts a packed userdata. user for member fn pointers only */ From d957d3763612f7de5796ff7ae378d8eb6090b216 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 28 Feb 2014 19:49:53 +0000 Subject: [PATCH 1044/1160] Minor code improvements after Lua changes. --- Source/Modules/lang.cxx | 27 +++++++++++++-------------- Source/Modules/lua.cxx | 5 ++--- Source/Modules/swigmod.h | 4 ++-- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 9420ea719..04304744c 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2993,7 +2993,7 @@ int Language::variableWrapper(Node *n) { Setattr(n, "varset", "1"); functionWrapper(n); } else { - Setattr(n, "feature:immutable", "1"); + SetFlag(n, "feature:immutable"); } /* Restore parameters */ Setattr(n, "sym:name", symname); @@ -3079,9 +3079,9 @@ int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr } /* ----------------------------------------------------------------------------- - * Lanugage::symbolAddScope( const_String_or_char_ptr scopeName ) + * Language::symbolAddScope() * - * Creates a scope (symbols Hash) for given name. This method is auxilary, + * Creates a scope (symbols Hash) for given name. This method is auxiliary, * you don't have to call it - addSymbols will lazily create scopes automatically. * If scope with given name already exists, then do nothing. * Returns newly created (or already existing) scope. @@ -3089,10 +3089,10 @@ int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr Hash* Language::symbolAddScope(const_String_or_char_ptr scope) { Hash *symbols = symbolScopeLookup(scope); if(!symbols) { - // Order in which to following parts are executed is important. In Lanugage - // constructor addScope("") is called to create a top level scope itself. - // Thus we must first add symbols hash to symtab and only then add pseudo - // symbol to top-level scope + // The order in which the following code is executed is important. In the Language + // constructor addScope("") is called to create a top level scope. + // Thus we must first add a symbols hash to symtab and only then add pseudo + // symbols to the top-level scope. // New scope which has not been added by the target language - lazily created. symbols = NewHash(); @@ -3103,14 +3103,14 @@ Hash* Language::symbolAddScope(const_String_or_char_ptr scope) { const_String_or_char_ptr top_scope = ""; Hash *topscope_symbols = Getattr(symtabs, top_scope); Hash *pseudo_symbol = NewHash(); - Setattr(pseudo_symbol, "sym:is_scope", "1"); + Setattr(pseudo_symbol, "sym:scope", "1"); Setattr(topscope_symbols, scope, pseudo_symbol); } return symbols; } /* ----------------------------------------------------------------------------- - * Lanugage::symbolSscopeLookup( const_String_or_char_ptr scope ) + * Language::symbolScopeLookup() * * Lookup and returns a symtable (hash) representing given scope. Hash contains * all symbols in this scope. @@ -3121,17 +3121,16 @@ Hash* Language::symbolScopeLookup( const_String_or_char_ptr scope ) { } /* ----------------------------------------------------------------------------- - * Lanugage::symbolScopeSymbolLookup( const_String_or_char_ptr scope ) + * Language::symbolScopePseudoSymbolLookup() * * For every scope there is a special pseudo-symbol in the top scope (""). It * exists solely to detect name clashes. This pseudo symbol may contain a few properties, - * but you can more if you need to. This is also true fro top level scope (""). + * but more could be added. This is also true for the top level scope (""). * It contains a pseudo symbol with name "" (empty). Pseudo symbol contains the * following properties: - * sym:scope = "1" - a flag that this is scope pseudo symbol + * sym:scope = "1" - a flag that this is a scope pseudo symbol * - * Pseudo symbols are a Hash*, not a Node* (not that there is a difference - * in DOH) + * Pseudo symbols are a Hash*, not a Node*. * There is no difference from symbolLookup() method except for signature * and return type. * ----------------------------------------------------------------------------- */ diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 6c9e69050..c2f58cdf4 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -2096,9 +2096,8 @@ public: List *to_close = NewList(); while (ki.key) { assert(ki.item); - if (Getattr(ki.item, "sym:is_scope")) { - // We have a pseudo symbol. Lets get actuall scope for this - // pseudo symbol + if (Getattr(ki.item, "sym:scope")) { + // We have a pseudo symbol. Lets get actual scope for this pseudo symbol Hash *carrays_hash = rawGetCArraysHash(ki.key); assert(carrays_hash); if (Getattr(carrays_hash, "lua:closed") == 0) diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index afffebef9..63b91bae5 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -217,8 +217,8 @@ public: virtual void dumpSymbols(); virtual Node *symbolLookup(String *s, const_String_or_char_ptr scope = ""); /* Symbol lookup */ virtual Hash* symbolAddScope(const_String_or_char_ptr scope); - virtual Hash* symbolScopeLookup( const_String_or_char_ptr scope ); - virtual Hash* symbolScopePseudoSymbolLookup( const_String_or_char_ptr scope ); + virtual Hash* symbolScopeLookup(const_String_or_char_ptr scope); + virtual Hash* symbolScopePseudoSymbolLookup(const_String_or_char_ptr scope); virtual Node *classLookup(const SwigType *s) const; /* Class lookup */ virtual Node *enumLookup(SwigType *s); /* Enum lookup */ virtual int abstractClassTest(Node *n); /* Is class really abstract? */ From aaa71288b13ccb81d5d1c1a33d393b5e695ae7cc Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 28 Feb 2014 23:13:36 +0000 Subject: [PATCH 1045/1160] Cosmetic changes to lua.cxx after recent changes --- Source/Modules/lua.cxx | 173 ++++++++++++++++++++++------------------- 1 file changed, 91 insertions(+), 82 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index c2f58cdf4..4ed13127a 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -146,14 +146,14 @@ private: // and is not visible to user in any manner. This variable holds the name // of such pseudo-namespace a.k.a the result of above expression evaluation String *class_static_nspace; - // This variable holds the name of generated C function that acts as constructor - // for currently parsed class. + // This variable holds the name of generated C function that acts as a constructor + // for the currently parsed class. String *constructor_name; // Many wrappers forward calls to each other, for example staticmembervariableHandler - // forwards call to variableHandler, which, in turn, makes to call to functionWrapper. - // In order to access information about whether it is static member of class or just - // plain old variable an array current is kept and used as 'log' of call stack. + // forwards calls to variableHandler, which, in turn, makes to call to functionWrapper. + // In order to access information about whether it is a static member of class or just + // a plain old variable, the current array is kept and used as a 'log' of the call stack. enum TState { NO_CPP, VARIABLE, @@ -199,20 +199,7 @@ public: for (int i = 0; i < STATES_COUNT; i++) current[i] = false; } - ~LUA() { - } - bool strToInt(const char *string, int &value) { - long int tmp; - char *p_end = 0; - if (string == 0) - return false; - tmp = strtol(string, &p_end, 10); - if (p_end == 0 || *p_end != 0) - return false; - value = tmp; - return true; - } /* NEW LANGUAGE NOTE:*********************************************** This is called to initalise the system & read any command line args most of this is boilerplate code, except the command line args @@ -259,7 +246,7 @@ public: } if (elua_emulate && (eluac_ltr || elua_ltr )) { - Printf(stderr, "Can't have -elua-emulate and -eluac/-elua at the same time\n"); + Printf(stderr, "Cannot have -elua-emulate with either -eluac or -elua\n"); Swig_arg_error(); } @@ -400,7 +387,7 @@ public: Dump(f_wrappers, f_begin); Dump(f_initbeforefunc, f_begin); /* for the Lua code it needs to be properly excaped to be added into the C/C++ code */ - EscapeCode(s_luacode); + escapeCode(s_luacode); Printf(f_begin, "const char* SWIG_LUACODE=\n \"%s\";\n\n", s_luacode); Wrapper_pretty_print(f_init, f_begin); /* Close all of the files */ @@ -426,13 +413,14 @@ public: /* ------------------------------------------------------------ * cDeclaration() - * It copies sym:name to lua:name to preserve it's original value + * It copies sym:name to lua:name to preserve its original value * ------------------------------------------------------------ */ + virtual int cDeclaration(Node *n) { // class 'Language' is messing with symname in a really heavy way. // Although documentation states that sym:name is a name in // the target language space, it is not true. sym:name and - // it's derivatives are used in various places, including + // its derivatives are used in various places, including // behind-the-scene C code generation. The best way is not to // touch it at all. // But we need to know what was the name of function/variable @@ -468,10 +456,11 @@ public: /* ----------------------------------------------------------------------- * registerMethod() * - * Determines wrap name of a method, it's scope etc and calls + * Determines wrap name of a method, its scope etc and calls * registerMethod overload with correct arguments - * Overloaded variant adds method to the "methods" array of specified lua scope/class + * Overloaded variant adds method to the "methods" array of specified lua scope/class * ---------------------------------------------------------------------- */ + void registerMethod(Node *n, bool overwrite = false, String *overwriteLuaScope = 0) { String *symname = Getattr(n, "sym:name"); assert(symname); @@ -479,8 +468,7 @@ public: if (Getattr(n, "sym:nextSibling")) return; - // Lua scope. It is not symbol NSpace, it is actuall key to revrieve - // getCArraysHash. + // Lua scope. It is not symbol NSpace, it is the actual key to retrieve getCArraysHash. String *luaScope = luaCurrentSymbolNSpace(); if (overwrite) luaScope = overwriteLuaScope; @@ -490,12 +478,12 @@ public: if (current[NO_CPP] || !getCurrentClass()) { mrename = symname; } else { - assert(!current[NO_CPP]); - if (current[STATIC_FUNC] || current[MEMBER_FUNC]) { - mrename = Swig_name_member(getNSpace(), getClassPrefix(), symname); - } else { - mrename = symname; - } + assert(!current[NO_CPP]); + if (current[STATIC_FUNC] || current[MEMBER_FUNC]) { + mrename = Swig_name_member(getNSpace(), getClassPrefix(), symname); + } else { + mrename = symname; + } } wrapname = Swig_name_wrapper(mrename); //Printf(stdout, "luaname %s, symname %s mrename %s wrapname %s\n\tscope %s\n", @@ -503,7 +491,12 @@ public: registerMethod(n, wrapname, luaScope); } - // Add method to the "methods" C array of given namespace/class + /* ----------------------------------------------------------------------- + * registerMethod() + * + * Add method to the "methods" C array of given namespace/class + * ---------------------------------------------------------------------- */ + void registerMethod(Node *n, String* wname, String *luaScope) { assert(n); Hash *nspaceHash = getCArraysHash(luaScope); @@ -607,7 +600,7 @@ public: this is the code to convert from the scripting language to C/C++ some of the stuff will refer to the typemaps code written in your swig file (lua.swg), and some is done in the code here - I suppose you could do all the conversion on C, but it would be a nightmare to do + I suppose you could do all the conversion in C, but it would be a nightmare to do NEW LANGUAGE NOTE:END *********************************************** */ /* Generate code for argument marshalling */ // String *description = NewString(""); @@ -824,13 +817,7 @@ public: NEW LANGUAGE NOTE:END *********************************************** */ /* Now register the function with the interpreter. */ int result = SWIG_OK; - if (!Getattr(n, "sym:overloaded")) { - /* TODO: REMOVE - if (functionWrapperRegisterNow()) { // emit normal fns & static fns - registerMethod(n); - } - */ - } else { + if (Getattr(n, "sym:overloaded")) { if (!Getattr(n, "sym:nextSibling")) { result = dispatchFunction(n); } @@ -933,18 +920,18 @@ public: /* ------------------------------------------------------------ * Add variable to "attributes" C arrays of given namespace or class. - * Input is node. Base on the state of "current" array it determines - * the name of getter function, setter function etc and calls - * registeVariable overload with necessary params + * Input is node. Based on the state of "current" array it determines + * the name of the getter function, setter function etc and calls + * registerVariable overload with necessary params. * Lua scope could be overwritten. (Used only for backward compatibility) * ------------------------------------------------------------ */ + void registerVariable(Node *n, bool overwrite = false, String *overwriteLuaScope = 0) { int assignable = is_assignable(n); String *symname = Getattr(n, "sym:name"); assert(symname); - // Lua scope. It is not symbol NSpace, it is actuall key to revrieve - // getCArraysHash. + // Lua scope. It is not symbol NSpace, it is the actual key to retrieve getCArraysHash. String *luaScope = luaCurrentSymbolNSpace(); if (overwrite) luaScope = overwriteLuaScope; @@ -986,9 +973,10 @@ public: /* ------------------------------------------------------------ * registerVariable() * - * Add variable to the "attributes" (or "get"/"set" in + * Add variable to the "attributes" (or "get"/"set" in * case of elua_ltr) C arrays of given namespace or class * ------------------------------------------------------------ */ + void registerVariable(String *lua_nspace_or_class_name, Node *n, String *getName, String *setName) { String *unassignable = NewString("SWIG_Lua_set_immutable"); if (setName == 0 || GetFlag(n, "feature:immutable")) { @@ -1014,6 +1002,7 @@ public: /* ------------------------------------------------------------ * variableWrapper() * ------------------------------------------------------------ */ + virtual int variableWrapper(Node *n) { /* NEW LANGUAGE NOTE:*********************************************** Language::variableWrapper(n) will generate two wrapper fns @@ -1031,8 +1020,8 @@ public: // TODO: REMOVE //registerVariable(luaCurrentSymbolNSpace(), n, "varget:wrap:name", "varset:wrap:name"); - // It is impossible to use registerVariable, because sym:name of the Node is currenly - // in undefined states - the callees of this function may have modified it. + // It is impossible to use registerVariable, because sym:name of the Node is currently + // in an undefined state - the callees of this function may have modified it. // registerVariable should be used from respective callees.* current[VARIABLE] = false; return result; @@ -1043,6 +1032,7 @@ public: * Add constant to appropriate C array. constantRecord is an array record. * Actually, in current implementation it is resolved consttab typemap * ------------------------------------------------------------ */ + void registerConstant(String *nspace, String *constantRecord) { Hash *nspaceHash = getCArraysHash(nspace); String *s_const_tab = 0; @@ -1066,6 +1056,7 @@ public: /* ------------------------------------------------------------ * constantWrapper() * ------------------------------------------------------------ */ + virtual int constantWrapper(Node *n) { REPORT("constantWrapper", n); String *name = Getattr(n, "name"); @@ -1235,9 +1226,9 @@ public: /* ------------------------------------------------------------ - * Helper function that adds record to appropriate - * C arrays + * Helper function that adds record to appropriate C arrays * ------------------------------------------------------------ */ + void registerClass(String *scope, String *wrap_class) { assert(wrap_class); Hash *nspaceHash = getCArraysHash(scope); @@ -1252,9 +1243,11 @@ public: Printv(ns_methods, tab4, "{LSTRKEY(\"", proxy_class_name, "\")", ", LROVAL(", cls_methods, ")", "},\n", NIL); } } + /* ------------------------------------------------------------ * classHandler() * ------------------------------------------------------------ */ + virtual int classHandler(Node *n) { //REPORT("classHandler", n); @@ -1275,7 +1268,7 @@ public: proxy_class_name = Getattr(n, "sym:name"); // We have to enforce nspace here, because technically we are already // inside class parsing (getCurrentClass != 0), but we should register - // class in the it's parent namespace + // class in its parent namespace if (!luaAddSymbol(proxy_class_name, n, nspace)) return SWIG_ERROR; @@ -1578,18 +1571,20 @@ public: /* ---------------------------------------------------------------------- * globalfunctionHandler() + * * It can be called: * 1. Usual C/C++ global function. * 2. During class parsing for functions declared/defined as friend * 3. During class parsing from staticmemberfunctionHandler * ---------------------------------------------------------------------- */ + virtual int globalfunctionHandler(Node *n) { bool oldVal = current[NO_CPP]; - if (!current[STATIC_FUNC]) // If static funct, don't switch to NO_CPP + if (!current[STATIC_FUNC]) // If static function, don't switch to NO_CPP current[NO_CPP] = true; const int result = Language::globalfunctionHandler(n); - if (!current[STATIC_FUNC]) // Register only if not called from static funct handler + if (!current[STATIC_FUNC]) // Register only if not called from static function handler registerMethod(n); current[NO_CPP] = oldVal; return result; @@ -1597,10 +1592,10 @@ public: /* ---------------------------------------------------------------------- * globalvariableHandler() - * globalfunctionHandler() - * Sets "current" array correctly and calls - * Language::globalvariableHandler() + * + * Sets "current" array correctly * ---------------------------------------------------------------------- */ + virtual int globalvariableHandler(Node *n) { bool oldVal = current[NO_CPP]; current[GLOBAL_VAR] = true; @@ -1631,9 +1626,9 @@ public: if (v2_compatibility && result == SWIG_OK) { Swig_require("lua_staticmemberfunctionHandler", n, "*lua:name", NIL); String *lua_name = Getattr(n, "lua:name"); - // Although this function uses Swig_name_member, it actually generateds Lua name, - // not C++ name. It is because previous version used such scheme for static func - // name generation and we have to maintain backward compatibility + // Although this function uses Swig_name_member, it actually generates the Lua name, + // not the C++ name. This is because an earlier version used such a scheme for static function + // name generation and we have to maintain backward compatibility. String *compat_name = Swig_name_member(0, proxy_class_name, lua_name); Setattr(n, "lua:name", compat_name); registerMethod(n, true, getNSpace()); @@ -1676,9 +1671,9 @@ public: if (v2_compatibility) { Swig_save("lua_staticmembervariableHandler", n, "lua:name", NIL); String *lua_name = Getattr(n, "lua:name"); - // Although this function uses Swig_name_member, it actually generateds Lua name, - // not C++ name. It is because previous version used such scheme for static vars - // name generation and we have to maintain backward compatibility + // Although this function uses Swig_name_member, it actually generates the Lua name, + // not the C++ name. This is because an earlier version used such a scheme for static function + // name generation and we have to maintain backward compatibility. String *v2_name = Swig_name_member(NIL, proxy_class_name, lua_name); //Printf( stdout, "Name %s, class %s, compt. name %s\n", lua_name, proxy_class_name, v2_name ); // TODO: REMOVE if (!GetFlag(n, "wrappedasconstant")) { @@ -1686,9 +1681,8 @@ public: // Registering static var in the class parent nspace registerVariable(n, true, getNSpace()); } - // If static member variable was wrapped as constant, then - // constant wrapper has already performed all actions - // necessary for v2_compatibility + // If static member variable was wrapped as a constant, then + // constant wrapper has already performed all actions necessary for v2_compatibility Delete(v2_name); Swig_restore(n); } @@ -1753,12 +1747,14 @@ public: /* ----------------------------------------------------------------------------- - * EscapeCode() + * escapeCode() + * * This is to convert the string of Lua code into a proper string, which can then be * emitted into the C/C++ code. * Basically is is a lot of search & replacing of odd sequences * ---------------------------------------------------------------------------- */ - void EscapeCode(String *str) { + + void escapeCode(String *str) { //Printf(f_runtime,"/* original luacode:[[[\n%s\n]]]\n*/\n",str); Chop(str); // trim Replace(str, "\\", "\\\\", DOH_REPLACE_ANY); // \ to \\ (this must be done first) @@ -1772,6 +1768,7 @@ public: * * A small helper to hide impelementation of how CArrays hashes are stored * ---------------------------------------------------------------------------- */ + Hash *rawGetCArraysHash(const_String_or_char_ptr name) { Hash *scope = symbolScopeLookup( name ? name : "" ); if(!scope) @@ -1783,20 +1780,22 @@ public: /* ----------------------------------------------------------------------------- * getCArraysHash() - * Each namespace can be described with hash that stores C arrays + * + * Each namespace can be described with a hash that stores C arrays * where members of the namespace should be added. All these hashes are stored - * inside symbols table, in pseudo-symbol for every namespace. + * inside the symbols table, in pseudo-symbol for every namespace. * nspace could be NULL (NSPACE_TODO), that means functions and variables and classes - * that are not in any namespace (this is default for SWIG unless %nspace feature is used) + * that are not in any namespace (this is default for SWIG unless %nspace feature is used). * You can later set some attributes that will affect behaviour of functions that use this hash: * "lua:no_namespaces" will disable "namespaces" array. * "lua:no_classes" will disable "classes" array. * For every component ("attributes", "methods", etc) there are subcomponents: * XXX:name - name of the C array that stores data for component * XXX:decl - statement with forward declaration of this array; - * Namespace could be automatically registered to it's parent if 'reg' == true. It can be done - * only at first call (a.k.a when nspace is created). + * Namespace could be automatically registered to its parent if 'reg' == true. This can only be + * done during the first call (a.k.a when nspace is created). * ---------------------------------------------------------------------------- */ + Hash *getCArraysHash(String *nspace, bool reg = true) { Hash *scope = symbolScopeLookup(nspace ? nspace : ""); if(!scope) { @@ -1945,10 +1944,9 @@ public: Delete(components); Delete(parent_path); - } else if (!reg) // This namespace shouldn't be registered. Lets remember it + } else if (!reg) // This namespace shouldn't be registered. Lets remember it. Setattr(carrays_hash, "lua:no_reg", "1"); - Delete(mangled_name); mangled_name = 0; return carrays_hash; @@ -1956,14 +1954,16 @@ public: /* ----------------------------------------------------------------------------- * closeCArraysHash() + * * Functions add end markers {0,0,...,0} to all arrays, prints them to * output and marks hash as closed (lua:closed). Consequent attempts to - * close same hash will result in error + * close the same hash will result in an error. * closeCArraysHash DOES NOT print structure that describes namespace, it only * prints array. You can use printCArraysDefinition to print structure. * if "lua:no_namespaces" is set, then array for "namespaces" won't be printed * if "lua:no_classes" is set, then array for "classes" won't be printed * ----------------------------------------------------------------------------- */ + void closeCArraysHash(String *nspace, File *output) { Hash *carrays_hash = rawGetCArraysHash(nspace); assert(carrays_hash); @@ -2078,9 +2078,11 @@ public: } /* ----------------------------------------------------------------------------- - * closeCArraysHash() + * closeNamespaces() + * * Recursively close all non-closed namespaces. Prints data to dataOutput. * ----------------------------------------------------------------------------- */ + void closeNamespaces(File *dataOutput) { // Special handling for empty module. if (symbolScopeLookup("") == 0 || rawGetCArraysHash("") == 0) { @@ -2124,13 +2126,14 @@ public: /* ----------------------------------------------------------------------------- * printCArraysDefinition() - * This function prints to output a definition of namespace in - * form - * swig_lua_namespace $cname = { attr_array, methods_array, ... , namespaces_array }; - * You can call this function as many times as necessary. + * + * This function prints to output a definition of namespace in form + * swig_lua_namespace $cname = { attr_array, methods_array, ... , namespaces_array }; + * You can call this function as many times as is necessary. * 'name' is a user-visible name that this namespace will have in Lua. It shouldn't - * be fully qualified name, just it's own name. + * be a fully qualified name, just its own name. * ----------------------------------------------------------------------------- */ + void printCArraysDefinition(String *nspace, String *name, File *output) { Hash *carrays_hash = getCArraysHash(nspace, false); @@ -2159,6 +2162,7 @@ public: /* ----------------------------------------------------------------------------- * luaCurrentSymbolNSpace() + * * This function determines actual namespace/scope where any symbol at the * current moment should be placed. It looks at the 'current' array * and depending on where are we - static class member/function, @@ -2166,6 +2170,7 @@ public: * where symbol should be put. * The namespace/scope doesn't depend from symbol, only from 'current' * ----------------------------------------------------------------------------- */ + String *luaCurrentSymbolNSpace() { String *scope = 0; // If ouside class, than NSpace is used. @@ -2190,9 +2195,11 @@ public: /* ----------------------------------------------------------------------------- * luaAddSymbol() + * * Our implementation of addSymbol. Determines scope correctly, then * forwards to Language::addSymbol * ----------------------------------------------------------------------------- */ + int luaAddSymbol(const String *s, const Node *n) { String *scope = luaCurrentSymbolNSpace(); return luaAddSymbol(s, n, scope); @@ -2200,8 +2207,10 @@ public: /* ----------------------------------------------------------------------------- * luaAddSymbol() + * * Overload. Enforces given scope. Actually, it simply forwards call to Language::addSymbol * ----------------------------------------------------------------------------- */ + int luaAddSymbol(const String *s, const Node *n, const_String_or_char_ptr scope) { int result = Language::addSymbol(s, n, scope); if (!result) From 736c6b953e07141d04fd277544fb50198b02aff5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 1 Mar 2014 04:35:00 -0800 Subject: [PATCH 1046/1160] C# project files update - Update project files to use Visual Studio 2005 (minimum supported .NET is now 2.0 which is what VS 2005 supports). - Add project files for arrays example (requires /unsafe) - Fix support so that the project files work straight out the box on 64 bit systems (32 bit compile is the default). - Fix support for 64 bit builds - use the x64 platform. --- Examples/csharp/nested/example-cs.csproj | 181 +++++------ Examples/csharp/nested/example-vc.vcproj | 383 +++++++++++++++++++---- Examples/csharp/nested/example.sln | 44 +-- 3 files changed, 433 insertions(+), 175 deletions(-) diff --git a/Examples/csharp/nested/example-cs.csproj b/Examples/csharp/nested/example-cs.csproj index 8004780fb..b20ff231a 100644 --- a/Examples/csharp/nested/example-cs.csproj +++ b/Examples/csharp/nested/example-cs.csproj @@ -1,94 +1,87 @@ - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + Code + + + Code + + + Code + + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/nested/example-vc.vcproj b/Examples/csharp/nested/example-vc.vcproj index 5788bc9c7..ef870959e 100644 --- a/Examples/csharp/nested/example-vc.vcproj +++ b/Examples/csharp/nested/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,43 +348,65 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example.cxx" + > + RelativePath="example_wrap.cxx" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + RelativePath="example.h" + > + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + + + + + + diff --git a/Examples/csharp/nested/example.sln b/Examples/csharp/nested/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/nested/example.sln +++ b/Examples/csharp/nested/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal From 09cfc53bdf0264ca7aa69a3a3cf9bde3bb375efd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 1 Mar 2014 16:14:36 +0000 Subject: [PATCH 1047/1160] Better error detection in some java testcases --- .../test-suite/java/dynamic_cast_runme.java | 3 +- .../java/ignore_parameter_runme.java | 16 +++++------ .../test-suite/java/java_jnitypes_runme.java | 3 +- Examples/test-suite/java/long_long_runme.java | 6 ++-- .../test-suite/java/primitive_ref_runme.java | 28 +++++++++---------- Examples/test-suite/java/unions_runme.java | 15 ++++------ 6 files changed, 31 insertions(+), 40 deletions(-) diff --git a/Examples/test-suite/java/dynamic_cast_runme.java b/Examples/test-suite/java/dynamic_cast_runme.java index be1f97b35..e13c73dda 100644 --- a/Examples/test-suite/java/dynamic_cast_runme.java +++ b/Examples/test-suite/java/dynamic_cast_runme.java @@ -22,8 +22,7 @@ public class dynamic_cast_runme { // Note it is possible to downcast y with a Java cast. String a = dynamic_cast.do_test((Bar)y); if (!a.equals("Bar::test")) { - System.err.println("Failed!"); - System.exit(1); + throw new RuntimeException("Failed!"); } } } diff --git a/Examples/test-suite/java/ignore_parameter_runme.java b/Examples/test-suite/java/ignore_parameter_runme.java index 7dbcb06db..57ff360fb 100644 --- a/Examples/test-suite/java/ignore_parameter_runme.java +++ b/Examples/test-suite/java/ignore_parameter_runme.java @@ -16,16 +16,16 @@ public class ignore_parameter_runme { { // Compilation will ensure the number of arguments and type are correct. // Then check the return value is the same as the value given to the ignored parameter. - if (!ignore_parameter.jaguar(200, 0.0).equals("hello")) { System.err.println("Runtime Error in jaguar()");} - if (ignore_parameter.lotus("fast", 0.0) != 101) { System.err.println("Runtime Error in lotus()");} - if (ignore_parameter.tvr("fast", 200) != 8.8) { System.err.println("Runtime Error in tvr()");} - if (ignore_parameter.ferrari() != 101) { System.err.println("Runtime Error in ferrari()");} + if (!ignore_parameter.jaguar(200, 0.0).equals("hello")) { throw new RuntimeException("Runtime Error in jaguar()");} + if (ignore_parameter.lotus("fast", 0.0) != 101) { throw new RuntimeException("Runtime Error in lotus()");} + if (ignore_parameter.tvr("fast", 200) != 8.8) { throw new RuntimeException("Runtime Error in tvr()");} + if (ignore_parameter.ferrari() != 101) { throw new RuntimeException("Runtime Error in ferrari()");} SportsCars sc = new SportsCars(); - if (!sc.daimler(200, 0.0).equals("hello")) { System.err.println("Runtime Error in daimler()");} - if (sc.astonmartin("fast", 0.0) != 101) { System.err.println("Runtime Error in astonmartin()");} - if (sc.bugatti("fast", 200) != 8.8) { System.err.println("Runtime Error in bugatti()");} - if (sc.lamborghini() != 101) { System.err.println("Runtime Error in lamborghini()");} + if (!sc.daimler(200, 0.0).equals("hello")) { throw new RuntimeException("Runtime Error in daimler()");} + if (sc.astonmartin("fast", 0.0) != 101) { throw new RuntimeException("Runtime Error in astonmartin()");} + if (sc.bugatti("fast", 200) != 8.8) { throw new RuntimeException("Runtime Error in bugatti()");} + if (sc.lamborghini() != 101) { throw new RuntimeException("Runtime Error in lamborghini()");} // Check constructors are also generated correctly MiniCooper mc = new MiniCooper(200, 0.0); diff --git a/Examples/test-suite/java/java_jnitypes_runme.java b/Examples/test-suite/java/java_jnitypes_runme.java index 3e9d9e4c5..b2816c017 100644 --- a/Examples/test-suite/java/java_jnitypes_runme.java +++ b/Examples/test-suite/java/java_jnitypes_runme.java @@ -51,7 +51,6 @@ public class java_jnitypes_runme { } public static void testFailed(String str) { - System.err.println(str + " test failed"); - System.exit(1); + throw new RuntimeException(str + " test failed"); } } diff --git a/Examples/test-suite/java/long_long_runme.java b/Examples/test-suite/java/long_long_runme.java index d3092b326..3a967f7a7 100644 --- a/Examples/test-suite/java/long_long_runme.java +++ b/Examples/test-suite/java/long_long_runme.java @@ -66,8 +66,7 @@ public class long_long_runme { long_long.setLl(ll); long ll_check = long_long.getLl(); if (ll != ll_check) { - System.err.println("Runtime test using long long failed. ll=" + ll + " ll_check=" + ll_check); - System.exit(1); + throw new RuntimeException("Runtime test using long long failed. ll=" + ll + " ll_check=" + ll_check); } } @@ -75,8 +74,7 @@ public class long_long_runme { long_long.setUll(ull); BigInteger ull_check = long_long.getUll(); if (ull.compareTo(ull_check) != 0) { - System.err.println("Runtime test using unsigned long long failed. ull=" + ull.toString() + " ull_check=" + ull_check.toString()); - System.exit(1); + throw new RuntimeException("Runtime test using unsigned long long failed. ull=" + ull.toString() + " ull_check=" + ull_check.toString()); } } } diff --git a/Examples/test-suite/java/primitive_ref_runme.java b/Examples/test-suite/java/primitive_ref_runme.java index 2955004db..0307eb782 100644 --- a/Examples/test-suite/java/primitive_ref_runme.java +++ b/Examples/test-suite/java/primitive_ref_runme.java @@ -18,47 +18,47 @@ public class primitive_ref_runme { public static void main(String argv[]) { if (primitive_ref.ref_int(3) != 3) { - System.err.println( "ref_int failed!" ); + throw new RuntimeException( "ref_int failed!" ); } if (primitive_ref.ref_uint(3) != 3) { - System.err.println( "ref_uint failed!" ); + throw new RuntimeException( "ref_uint failed!" ); } if (primitive_ref.ref_short((short)3) != 3) { - System.err.println( "ref_short failed!" ); + throw new RuntimeException( "ref_short failed!" ); } if (primitive_ref.ref_ushort(3) != 3) { - System.err.println( "ref_ushort failed!" ); + throw new RuntimeException( "ref_ushort failed!" ); } if (primitive_ref.ref_long(3) != 3) { - System.err.println( "ref_long failed!" ); + throw new RuntimeException( "ref_long failed!" ); } if (primitive_ref.ref_ulong(3) != 3) { - System.err.println( "ref_ulong failed!" ); + throw new RuntimeException( "ref_ulong failed!" ); } if (primitive_ref.ref_schar((byte)3) != 3) { - System.err.println( "ref_schar failed!" ); + throw new RuntimeException( "ref_schar failed!" ); } if (primitive_ref.ref_uchar((short)3) != 3) { - System.err.println( "ref_uchar failed!" ); + throw new RuntimeException( "ref_uchar failed!" ); } if (primitive_ref.ref_bool(true) != true) { - System.err.println( "ref_bool failed!" ); + throw new RuntimeException( "ref_bool failed!" ); } if (primitive_ref.ref_float((float)3.5) != 3.5) { - System.err.println( "ref_float failed!" ); + throw new RuntimeException( "ref_float failed!" ); } if (primitive_ref.ref_double(3.5) != 3.5) { - System.err.println( "ref_double failed!" ); + throw new RuntimeException( "ref_double failed!" ); } if (primitive_ref.ref_char('x') != 'x') { - System.err.println( "ref_char failed!" ); + throw new RuntimeException( "ref_char failed!" ); } if (primitive_ref.ref_longlong(0x123456789ABCDEF0L) != 0x123456789ABCDEF0L) { - System.err.println( "ref_longlong failed!" ); + throw new RuntimeException( "ref_longlong failed!" ); } BigInteger bi = new BigInteger("18446744073709551615"); //0xFFFFFFFFFFFFFFFFL if (bi.compareTo(primitive_ref.ref_ulonglong(bi)) != 0) { - System.err.println( "ref_ulonglong failed!" ); + throw new RuntimeException( "ref_ulonglong failed!" ); } } } diff --git a/Examples/test-suite/java/unions_runme.java b/Examples/test-suite/java/unions_runme.java index 16a5b3b87..6a073a0f5 100644 --- a/Examples/test-suite/java/unions_runme.java +++ b/Examples/test-suite/java/unions_runme.java @@ -34,14 +34,12 @@ public class unions_runme { eut.getUni().setSmall(small); short Jill1 = eut.getUni().getSmall().getJill(); if (Jill1 != 200) { - System.err.println("Runtime test1 failed. eut.uni.small.jill=" + Jill1); - System.exit(1); + throw new RuntimeException("Runtime test1 failed. eut.uni.small.jill=" + Jill1); } int Num1 = eut.getNumber(); if (Num1 != 1) { - System.err.println("Runtime test2 failed. eut.number=" + Num1); - System.exit(1); + throw new RuntimeException("Runtime test2 failed. eut.number=" + Num1); } // Secondly check the BigStruct in EmbeddedUnionTest @@ -49,20 +47,17 @@ public class unions_runme { eut.getUni().setBig(big); int Jack1 = eut.getUni().getBig().getJack(); if (Jack1 != 300) { - System.err.println("Runtime test3 failed. eut.uni.big.jack=" + Jack1); - System.exit(1); + throw new RuntimeException("Runtime test3 failed. eut.uni.big.jack=" + Jack1); } short Jill2 = eut.getUni().getBig().getSmallstruct().getJill(); if (Jill2 != 200) { - System.err.println("Runtime test4 failed. eut.uni.big.smallstruct.jill=" + Jill2); - System.exit(1); + throw new RuntimeException("Runtime test4 failed. eut.uni.big.smallstruct.jill=" + Jill2); } int Num2 = eut.getNumber(); if (Num2 != 2) { - System.err.println("Runtime test5 failed. eut.number=" + Num2); - System.exit(1); + throw new RuntimeException("Runtime test5 failed. eut.number=" + Num2); } } } From 8998f11ca39d60ae4593a3fab2fc86ab92439003 Mon Sep 17 00:00:00 2001 From: Arnaud Diederen Date: Sat, 1 Mar 2014 16:30:22 +0000 Subject: [PATCH 1048/1160] Fix Python argument count checking when using -modern SF bug: https://sourceforge.net/p/swig/mailman/message/31957171/ SF Patch: 3471 --- Source/Modules/python.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 039623e62..d570ebd31 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -2565,7 +2565,7 @@ public: Printf(parse_args, "if (!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,0)) SWIG_fail;\n", iname, num_fixed_arguments, tuple_arguments); } } - } else if (tuple_arguments > 0) { + } else { Printf(parse_args, "if(!PyArg_UnpackTuple(args,(char *)\"%s\",%d,%d", iname, num_fixed_arguments, tuple_arguments); Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL); } From a3a053522911f6a6a9767b05e4bd61b0426a1ea3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 1 Mar 2014 16:41:22 +0000 Subject: [PATCH 1049/1160] Add testcase and info on python -builtin missing argument count check --- CHANGES.current | 4 ++ Examples/test-suite/common.mk | 1 + Examples/test-suite/global_functions.i | 8 +++ .../python/global_functions_runme.py | 52 +++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 Examples/test-suite/global_functions.i create mode 100644 Examples/test-suite/python/global_functions_runme.py diff --git a/CHANGES.current b/CHANGES.current index 791665901..d02337781 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-03-01: wsfulton + [Python] SF patch #347 Fix missing argument count checking with -modern. + Fixes regression introduced when builtin changes were introduced in SWIG-2.0.3. + 2014-02-21: wsfulton [PHP] Fix warning suppression using %warnfilter for PHP reserved class names. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 6ea80670d..b9239315a 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -577,6 +577,7 @@ C_TEST_CASES += \ extern_declaration \ funcptr \ function_typedef \ + global_functions \ immutable_values \ inctest \ integers \ diff --git a/Examples/test-suite/global_functions.i b/Examples/test-suite/global_functions.i new file mode 100644 index 000000000..3c8780b61 --- /dev/null +++ b/Examples/test-suite/global_functions.i @@ -0,0 +1,8 @@ +%module global_functions + +%inline %{ +void global_void(void) {} +int global_one(int i) { return i; } +int global_two(int i, int j) { return i+j; } +%} + diff --git a/Examples/test-suite/python/global_functions_runme.py b/Examples/test-suite/python/global_functions_runme.py new file mode 100644 index 000000000..17b70b725 --- /dev/null +++ b/Examples/test-suite/python/global_functions_runme.py @@ -0,0 +1,52 @@ +from global_functions import * + +def check(a, b): + if a != b: + raise RuntimeError("Failed: " + str(a) + " != " + str(b)) +global_void() +check(global_one(1), 1) +check(global_two(2, 2), 4) + +fail = True +try: + global_void(1) +except TypeError, e: + fail = False +if fail: + raise RuntimeError("argument count check failed") + +fail = True +try: + global_one() +except TypeError, e: + fail = False +if fail: + raise RuntimeError("argument count check failed") + +fail = True +try: + global_one(2, 2) +except TypeError, e: + fail = False + +if fail: + raise RuntimeError("argument count check failed") + +fail = True +try: + global_two(1) +except TypeError, e: + fail = False + +if fail: + raise RuntimeError("argument count check failed") + +fail = True +try: + global_two(3, 3, 3) +except TypeError, e: + fail = False + +if fail: + raise RuntimeError("argument count check failed") + From d8bfe00e250719c9a8cad258e241acdf58614753 Mon Sep 17 00:00:00 2001 From: Soeren Sonnenburg Date: Fri, 28 Feb 2014 08:11:28 +0100 Subject: [PATCH 1050/1160] Include module name if non NULL in tp_name --- Source/Modules/python.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index d570ebd31..7c1595da2 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -3592,7 +3592,12 @@ public: if (GetFlag(n, "feature:python:nondynamic")) Setattr(n, "feature:python:tp_setattro", "SWIG_Python_NonDynamicSetAttr"); - String *quoted_symname = NewStringf("\"%s\"", symname); + String *quoted_symname; + if (package) { + quoted_symname = NewStringf("\"%s.%s\"", package, symname); + } else { + quoted_symname = NewStringf("\"%s\"", symname); + } String *quoted_rname = NewStringf("\"%s\"", rname); char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : Swig_directorclass(n) ? "0" : "SwigPyBuiltin_BadInit"; String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES"); From 4fb940d9134ebd47ec32f7cc9b59bc5c4410cc8a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 1 Mar 2014 23:24:59 +0000 Subject: [PATCH 1051/1160] Further fixes when using type() when using -builtin to include module name Using type() on a builtin type should include the package and module name, see http://docs.python.org/2/c-api/typeobj.html --- CHANGES.current | 4 ++++ .../python/import_packages/same_modnames1/runme.py | 2 ++ .../python/import_packages/same_modnames2/runme.py | 3 +++ Examples/test-suite/python/namespace_class_runme.py | 4 ++++ Source/Modules/python.cxx | 12 ++++++++++-- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index d02337781..e1dafdc34 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-03-01: wsfulton + [Python] Patch #143 Fix type shown when using type() to include the module and package + name when using -builtin. + 2014-03-01: wsfulton [Python] SF patch #347 Fix missing argument count checking with -modern. Fixes regression introduced when builtin changes were introduced in SWIG-2.0.3. diff --git a/Examples/python/import_packages/same_modnames1/runme.py b/Examples/python/import_packages/same_modnames1/runme.py index 9cdb95caf..923f0e0bb 100644 --- a/Examples/python/import_packages/same_modnames1/runme.py +++ b/Examples/python/import_packages/same_modnames1/runme.py @@ -4,4 +4,6 @@ import pkg2.foo print " Finished importing pkg2.foo" var2 = pkg2.foo.Pkg2_Foo() +if str(type(var2)).find("'pkg2.foo.Pkg2_Foo'") == -1: + raise RuntimeError("failed type checking: " + str(type(var2))) print " Successfully created object pkg2.foo.Pkg2_Foo" diff --git a/Examples/python/import_packages/same_modnames2/runme.py b/Examples/python/import_packages/same_modnames2/runme.py index bde4305c4..af8f78194 100644 --- a/Examples/python/import_packages/same_modnames2/runme.py +++ b/Examples/python/import_packages/same_modnames2/runme.py @@ -1,4 +1,7 @@ import pkg1.pkg2.foo print " Finished importing pkg1.pkg2.foo" + var2 = pkg1.pkg2.foo.Pkg2_Foo(); +if str(type(var2)).find("'pkg1.pkg2.foo.Pkg2_Foo'") == -1: + raise RuntimeError("failed type checking: " + str(type(var2))) print " Successfully created object pkg1.pkg2.foo.Pkg2_Foo" diff --git a/Examples/test-suite/python/namespace_class_runme.py b/Examples/test-suite/python/namespace_class_runme.py index 84d3b00ed..d139527b7 100644 --- a/Examples/test-suite/python/namespace_class_runme.py +++ b/Examples/test-suite/python/namespace_class_runme.py @@ -32,3 +32,7 @@ f.moo(1) f = FooT_H() f.foo(Hi) + +f_type = str(type(f)) +if f_type.find("'namespace_class.FooT_H'") == -1: + raise RuntimeError("Incorrect type: " + f_type) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 7c1595da2..13ddbfb61 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -3592,11 +3592,19 @@ public: if (GetFlag(n, "feature:python:nondynamic")) Setattr(n, "feature:python:tp_setattro", "SWIG_Python_NonDynamicSetAttr"); + Node *mod = Getattr(n, "module"); + String *modname = mod ? Getattr(mod, "name") : 0; String *quoted_symname; if (package) { - quoted_symname = NewStringf("\"%s.%s\"", package, symname); + if (modname) + quoted_symname = NewStringf("\"%s.%s.%s\"", package, modname, symname); + else + quoted_symname = NewStringf("\"%s.%s\"", package, symname); } else { - quoted_symname = NewStringf("\"%s\"", symname); + if (modname) + quoted_symname = NewStringf("\"%s.%s\"", modname, symname); + else + quoted_symname = NewStringf("\"%s\"", symname); } String *quoted_rname = NewStringf("\"%s\"", rname); char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : Swig_directorclass(n) ? "0" : "SwigPyBuiltin_BadInit"; From da44064d6ccaab31006fed60b03a22b11c385a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Kr=C3=BCger?= Date: Thu, 30 Jan 2014 08:59:42 +0100 Subject: [PATCH 1052/1160] 'swig_varlink_getattr' throws a wrong exception If the attribute of a python object could not found a AttributeException should be thrown instead of a NameException. --- Lib/python/pyinit.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 79df023de..585fcaa27 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -116,7 +116,7 @@ swig_varlink_getattr(swig_varlinkobject *v, char *n) { var = var->next; } if (res == NULL && !PyErr_Occurred()) { - PyErr_SetString(PyExc_NameError,"Unknown C global variable"); + PyErr_SetString(PyExc_AttributeError,"Unknown C global variable"); } return res; } From 7a96fba836558f592dc5b37b32d1845f606e2efe Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 2 Mar 2014 01:28:51 +0000 Subject: [PATCH 1053/1160] Correct exception thrown attempting to access a non-existent C/C++ global variable on the 'cvar' object. The exception thrown used to be a NameError. However, as this access is via a primary, an AttributeError is more correct and so the exception thrown now is an AttributeError. Reference: http://docs.python.org/2/reference/expressions.html#attribute-references SF Patch #346. --- CHANGES.current | 9 +++++++++ Examples/test-suite/global_vars.i | 5 +++++ Lib/python/pyinit.swg | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index e1dafdc34..8e388dee5 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,15 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-03-02: wsfulton + [Python] SF Patch #346 from Jens Krueger. Correct exception thrown attempting to + access a non-existent C/C++ global variable on the 'cvar' object. The exception thrown + used to be a NameError. However, as this access is via a primary, an AttributeError + is more correct and so the exception thrown now is an AttributeError. Reference: + http://docs.python.org/2/reference/expressions.html#attribute-references + + *** POTENTIAL INCOMPATIBILITY *** + 2014-03-01: wsfulton [Python] Patch #143 Fix type shown when using type() to include the module and package name when using -builtin. diff --git a/Examples/test-suite/global_vars.i b/Examples/test-suite/global_vars.i index 8c18bbd34..d562d1eaa 100644 --- a/Examples/test-suite/global_vars.i +++ b/Examples/test-suite/global_vars.i @@ -28,4 +28,9 @@ Hello h; Hello *hp; Hello &hr = h; + + void init() { + b = "string b"; + x = 1234; + } %} diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 585fcaa27..b44c2c893 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -116,7 +116,7 @@ swig_varlink_getattr(swig_varlinkobject *v, char *n) { var = var->next; } if (res == NULL && !PyErr_Occurred()) { - PyErr_SetString(PyExc_AttributeError,"Unknown C global variable"); + PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); } return res; } @@ -133,7 +133,7 @@ swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { var = var->next; } if (res == 1 && !PyErr_Occurred()) { - PyErr_SetString(PyExc_NameError,"Unknown C global variable"); + PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); } return res; } From 6b18d20979f5ae0e0202db247d1de6ced76bfd41 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sun, 2 Mar 2014 19:10:11 +0400 Subject: [PATCH 1054/1160] Fixing documentation. Adding an example. --- Doc/Manual/Lua.html | 19 +++++++++------- Examples/lua/check.list | 1 + Examples/lua/nspace/Makefile | 19 ++++++++++++++++ Examples/lua/nspace/example.h | 28 ++++++++++++++++++++++++ Examples/lua/nspace/example.i | 10 +++++++++ Examples/lua/nspace/runme.lua | 41 +++++++++++++++++++++++++++++++++++ 6 files changed, 110 insertions(+), 8 deletions(-) create mode 100644 Examples/lua/nspace/Makefile create mode 100644 Examples/lua/nspace/example.h create mode 100644 Examples/lua/nspace/example.i create mode 100644 Examples/lua/nspace/runme.lua diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index f2dd45197..e7b9d5c35 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -1346,15 +1346,20 @@ int module_variable = 9; namespace MyWorld { class World { public: + World(): + world_max_count(9) {} int create_world() { return 17; } - const int world_max_count = 9; + const int world_max_count; // = 9 }; namespace Nested { class Dweller { - enum Gender { MALE, FEMALE }; - static int populate_cave() { return 19; } - int create_cave() { return 13; } - int food_count; // = 11 + public: + Dweller(): + food_count(11) {} + enum Gender { MALE = 0, FEMALE = 1 }; + static int populate_cave() { return 19; } + int create_cave() { return 13; } + int food_count; // = 11 }; } } @@ -1364,15 +1369,13 @@ Now, from Lua usage is as follows: > print(example.module_function()) 7 > print(example.module_variable) -8 +9 > print(example.MyWorld.World():create_world()) 17 > print(example.MyWorld.World.world_max_count) 9 > print(example.MyWorld.Nested.Dweller.MALE) 0 -> print(example.MyWorld.Nested.Dweller().food_count) -11 >

    Backward compatibility

    diff --git a/Examples/lua/check.list b/Examples/lua/check.list index 6862e4478..87dfdcd08 100644 --- a/Examples/lua/check.list +++ b/Examples/lua/check.list @@ -11,6 +11,7 @@ funcptr3 functest functor import +nspace owner pointer simple diff --git a/Examples/lua/nspace/Makefile b/Examples/lua/nspace/Makefile new file mode 100644 index 000000000..72129b1d6 --- /dev/null +++ b/Examples/lua/nspace/Makefile @@ -0,0 +1,19 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile lua_run + +build: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp + +static: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile lua_clean diff --git a/Examples/lua/nspace/example.h b/Examples/lua/nspace/example.h new file mode 100644 index 000000000..8c528bfc6 --- /dev/null +++ b/Examples/lua/nspace/example.h @@ -0,0 +1,28 @@ +#ifndef _example_guardian_ +#define _example_guardian_ + +int module_function() { return 7; } +int module_variable = 9; + +namespace MyWorld { + class World { + public: + World(): + world_max_count(9) {} + int create_world() { return 17; } + const int world_max_count; // = 9 + }; + namespace Nested { + class Dweller { + public: + Dweller(): + food_count(11) {} + enum Gender { MALE = 0, FEMALE = 1 }; + static int populate_cave() { return 19; } + int create_cave() { return 13; } + int food_count; // = 11 + }; + } +} + +#endif diff --git a/Examples/lua/nspace/example.i b/Examples/lua/nspace/example.i new file mode 100644 index 000000000..04a906fab --- /dev/null +++ b/Examples/lua/nspace/example.i @@ -0,0 +1,10 @@ +%module example + +%{ +#include "example.h" +%} + + %nspace MyWorld::Nested::Dweller; + %nspace MyWorld::World; + +%include "example.h" diff --git a/Examples/lua/nspace/runme.lua b/Examples/lua/nspace/runme.lua new file mode 100644 index 000000000..ad5816d36 --- /dev/null +++ b/Examples/lua/nspace/runme.lua @@ -0,0 +1,41 @@ +-- file: runme.lua + +-- This file illustrates class C++ interface generated +-- by SWIG. + +---- importing ---- +if string.sub(_VERSION,1,7)=='Lua 5.0' then + -- lua5.0 doesnt have a nice way to do this + lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example') + assert(lib)() +else + -- lua 5.1 does + require('example') +end + +ex = example + +-- Calling a module function ( aka global function ) +assert( ex.module_function() == 7 ) +print("example.module_function(): ", ex.module_function()) + +-- Accessing a module (aka global) variable +assert( ex.module_variable == 9 ) +print("example.module_variable: ", ex.module_variable) + +-- Creating an instance of the class +w1 = ex.MyWorld.World() +print("Creating class instance: w1 = ex.MyWorld.World(): ", w1) + +-- Accessing class members +assert( ex.MyWorld.World():create_world() == 17 ) +print( "w1:create_world() = ", w1:create_world() ) +assert( w1:create_world() == 17 ) +print( "w1:world_max_count = ", w1.world_max_count ) +assert( w1.world_max_count == 9 ) + +-- Accessing enums from class within namespace +print( "Accessing enums: ex.MyWorld.Nested.Dweller.MALE = ", ex.MyWorld.Nested.Dweller.MALE ) +assert( ex.MyWorld.Nested.Dweller.MALE == 0 ) +assert( ex.MyWorld.Nested.Dweller.FEMALE == 1 ) + From e48c2ce35e9460e86e889251c868f4caaed6895b Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sun, 2 Mar 2014 19:33:25 +0400 Subject: [PATCH 1055/1160] Backward compatibility -> Compatibility Note --- Doc/Manual/Lua.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index e7b9d5c35..655ee2204 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -1378,7 +1378,7 @@ Now, from Lua usage is as follows: 0 > -

    Backward compatibility

    +

    Compatibility Note

    If SWIG is running in backward compatible way, i.e. without -no-old-metatable-bindings option, then additional old-style names are generated(notice the underscore):

    @@ -1390,7 +1390,7 @@ If SWIG is running in backward compatible way, i.e. without -no-old-metatabl 11 > -

    Backward compatibility

    +

    Compatibility Note

    Names

    If SWIG is launched without -no-old-metatable-bindings option, then it enters backward-compatible mode. While in this mode, it tries to generate additional names for static functions, class static constants and class enums. From 23f0df2c0ea3d2f04a8dc7ba1b89f41ae61da41b Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Sun, 2 Mar 2014 20:15:09 +0400 Subject: [PATCH 1056/1160] Setattr -> SetFlag --- Source/Modules/lua.cxx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 4ed13127a..b94ab4a22 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -1301,7 +1301,7 @@ public: proxy_class_name = 0; return SWIG_NOWRAP; } - Setattr(emitted, mangled_fr_t, "1"); + SetFlag(emitted, mangled_fr_t); // We treat class T as both 'class' and 'namespace'. All static members, attributes // and constants are considered part of namespace T, all members - part of the 'class' @@ -1318,9 +1318,9 @@ public: assert(instance_cls); String *s_attr_tab_name = Getattr(instance_cls, "attributes:name"); String *s_methods_tab_name = Getattr(instance_cls, "methods:name"); - Setattr(instance_cls, "lua:no_namespaces", "1"); - Setattr(instance_cls, "lua:no_classes", "1"); - Setattr(instance_cls, "lua:class_instance", "1"); + SetFlag(instance_cls, "lua:no_namespaces"); + SetFlag(instance_cls, "lua:no_classes"); + SetFlag(instance_cls, "lua:class_instance"); /* There is no use for "constants", "classes" and "namespaces" arrays. * All constants are considered part of static part of class. @@ -1329,8 +1329,8 @@ public: class_static_nspace = NewStringf("%s%s__Static", full_proxy_class_name, NSPACE_SEPARATOR); Hash *static_cls = getCArraysHash(class_static_nspace, false); assert(static_cls); - Setattr(static_cls, "lua:no_namespaces", "1"); - Setattr(static_cls, "lua:class_static", "1"); + SetFlag(static_cls, "lua:no_namespaces"); + SetFlag(static_cls, "lua:class_static"); // Notifying instance_cls and static_cls hashes about each other Setattr(instance_cls, "lua:class_instance:static_hash", static_cls); @@ -1945,7 +1945,7 @@ public: Delete(components); Delete(parent_path); } else if (!reg) // This namespace shouldn't be registered. Lets remember it. - Setattr(carrays_hash, "lua:no_reg", "1"); + SetFlag(carrays_hash, "lua:no_reg"); Delete(mangled_name); mangled_name = 0; @@ -1969,7 +1969,7 @@ public: assert(carrays_hash); assert(Getattr(carrays_hash, "lua:closed") == 0); - Setattr(carrays_hash, "lua:closed", "1"); + SetFlag(carrays_hash, "lua:closed"); String *attr_tab = Getattr(carrays_hash, "attributes"); Printf(attr_tab, " {0,0,0}\n};\n"); From cad7f86112c9eaa17d32531a1e32c9d29a9ebbcc Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Mon, 3 Mar 2014 09:27:16 +0400 Subject: [PATCH 1057/1160] __Static -> SwigStatig, __Module -> SwigModule --- Lib/lua/luaruntime.swg | 2 +- Source/Modules/lua.cxx | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Lib/lua/luaruntime.swg b/Lib/lua/luaruntime.swg index ebb997897..5c70b8b7a 100644 --- a/Lib/lua/luaruntime.swg +++ b/Lib/lua/luaruntime.swg @@ -56,7 +56,7 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */ #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) - SWIG_Lua_namespace_register(L,&swig___Module, globalRegister); + SWIG_Lua_namespace_register(L,&swig_SwigModule, globalRegister); #endif #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index b94ab4a22..19811d6cb 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -142,7 +142,7 @@ private: // then it is basically C++ fully qualified name with colons replaced with dots. String *full_proxy_class_name; // All static methods and/or variables are treated as if they were in the - // special C++ namespace $(classname).__Static. This is internal mechanism only + // special C++ namespace $(classname).SwigStatic. This is internal mechanism only // and is not visible to user in any manner. This variable holds the name // of such pseudo-namespace a.k.a the result of above expression evaluation String *class_static_nspace; @@ -1309,11 +1309,8 @@ public: // are described with same structures - swig_lua_attribute/swig_lua_method. Instead of calling // getCArraysHash(class name) to initialize things for static methods/attributes and then // manually doing same initialization for non-static methods, we call getCArraysHash 2 times: - // 1) With name "class name" + "." + "__Static" to initialize static things + // 1) With name "class name" + "." + "SwigStatic" to initialize static things // 2) With "class name" to initialize non-static things - // And we can guarantee that there will not be any name collision because names starting with 2 underscores - // and capital letter are forbiden to use in C++. So, under know circumstances could our class contain - // any member or subclass with name "__Static". Thus, never any name clash. Hash *instance_cls = getCArraysHash(full_proxy_class_name, false); assert(instance_cls); String *s_attr_tab_name = Getattr(instance_cls, "attributes:name"); @@ -1326,7 +1323,7 @@ public: * All constants are considered part of static part of class. */ - class_static_nspace = NewStringf("%s%s__Static", full_proxy_class_name, NSPACE_SEPARATOR); + class_static_nspace = NewStringf("%s%sSwigStatic", full_proxy_class_name, NSPACE_SEPARATOR); Hash *static_cls = getCArraysHash(class_static_nspace, false); assert(static_cls); SetFlag(static_cls, "lua:no_namespaces"); @@ -1809,7 +1806,7 @@ public: carrays_hash = NewHash(); String *mangled_name = 0; if (nspace == 0 || Len(nspace) == 0) - mangled_name = NewString("__Module"); // C++ names can't start with "__ + capital letter" + mangled_name = NewString("SwigModule"); else mangled_name = Swig_name_mangle(nspace); String *cname = NewStringf("swig_%s", mangled_name); @@ -2086,7 +2083,7 @@ public: void closeNamespaces(File *dataOutput) { // Special handling for empty module. if (symbolScopeLookup("") == 0 || rawGetCArraysHash("") == 0) { - // Module is empty. Create hash for global scope in order to have swig__Module + // Module is empty. Create hash for global scope in order to have swig_SwigModule // variable in resulting file getCArraysHash(0); } From 18980996208d0f9e02f62e1b8350227e9ea633a3 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Mon, 3 Mar 2014 09:54:13 +0400 Subject: [PATCH 1058/1160] Fixing enums --- Doc/Manual/Lua.html | 23 ++++++-- Examples/test-suite/lua/enums_runme.lua | 4 +- Source/Modules/lua.cxx | 73 ++++++++++++------------- 3 files changed, 55 insertions(+), 45 deletions(-) diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index 655ee2204..c38afb31d 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -510,14 +510,16 @@ Enums are exported into a class table. For example, given some enums: enum Days { SUNDAY = 0, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }; struct Test { enum { TEST1 = 10, TEST2 = 20 }; +#ifdef __cplusplus // There are no static members in C language static const int ICONST = 12; +#endif };

    -This is 'effectively' converted into the following Lua code: +There is a slight difference in behaviour in C mode and C++ model. In C++ mode this is 'effectively' converted into the following Lua code:

    -> print(example.const.SUNDAY)
    +> print(example.SUNDAY)
     0
     > print(example.Test.TEST1)
     10
    @@ -525,6 +527,15 @@ This is 'effectively' converted into the following Lua code:
     12
     
    +

    In C mode enums from structs are exported into global namespace (due to C Standard). See below:

    +
    +> print(example.SUNDAY)
    +0
    +> -- See the difference here
    +> print(example.TEST1)
    +10
    +
    +

    Compatibility Note: Versions of SWIG prior to SWIG-3.0.0 did not generate the class table members above. The following code was the only way to access these constants/enums: @@ -540,17 +551,17 @@ The old-style bindings are still generated in addition to the new ones. If the -no-old-metatable-bindings option is used, then these old-style bindings are not generated.

    -However, in C mode, names of enums are not prefixed with names of structure. This is the due to the C Standard. +However, in C mode, prefixed names of enums are not exported. There is no sense in having both Test_TEST1 and TEST1 in global namespace.

     > print(example.TEST1)
     10
    -> print(example.ICONST)
    -12
    +> print(example.Test_TEST1)
    +nil
     

    It is worth mentioning, that example.Test.TEST1 and example.Test_TEST1 are different entities and changing one does not change the other. -Given the fact, that these are constantes and they are not supposed to be changed, it is up to you to avoid such issues. +Given the fact that these are constantes and they are not supposed to be changed, it is up to you to avoid such issues.

    26.3.5 Pointers

    diff --git a/Examples/test-suite/lua/enums_runme.lua b/Examples/test-suite/lua/enums_runme.lua index 998f01cfc..dfe0256ee 100644 --- a/Examples/test-suite/lua/enums_runme.lua +++ b/Examples/test-suite/lua/enums_runme.lua @@ -19,8 +19,8 @@ assert(enums.globalinstance3==30) assert(enums.AnonEnum1==0) assert(enums.AnonEnum2==100) --- In C enums from struct are exported without prefixing with struct name --- In C++ they are prefixed. +-- In C enums from struct are exported into global namespace (without prefixing with struct name) +-- In C++ they are prefixed (as compatibility thing). -- We are emulating xor :) assert(enums.BAR1 ~= enums.Foo_BAR1) -- It is either C style, or C++ style, but not both assert((enums.BAR1 ~= nil ) or (enums.Foo_BAR1 ~= nil)) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 19811d6cb..e25376aaa 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -1110,47 +1110,43 @@ public: bool make_v2_compatible = v2_compatibility && getCurrentClass() != 0; if (make_v2_compatible) { - // Special handling for enums in C mode - they are not prefixed with structure name - if(!CPlusPlus && current[ENUM_CONST]) { - lua_name_v2 = lua_name; - DohIncref(lua_name_v2); - iname_v2 = iname; - DohIncref(iname_v2); - } else { + // Don't do anything for enums in C mode - they are already + // wrapped correctly + if (CPlusPlus || !current[ENUM_CONST]) { lua_name_v2 = Swig_name_member(0, proxy_class_name, lua_name); iname_v2 = Swig_name_member(0, proxy_class_name, iname); - } - n_v2 = Copy(n); - //Printf( stdout, "target name v2: %s, symname v2 %s\n", lua_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE - if (!luaAddSymbol(iname_v2, n, getNSpace())) { - Swig_restore(n); - return SWIG_ERROR; - } + n_v2 = Copy(n); + //Printf( stdout, "target name v2: %s, symname v2 %s\n", lua_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE + if (!luaAddSymbol(iname_v2, n, getNSpace())) { + Swig_restore(n); + return SWIG_ERROR; + } - Setattr(n_v2, "sym:name", lua_name_v2); - tm_v2 = Swig_typemap_lookup("consttab", n_v2, name, 0); - if (tm_v2) { - //Printf(stdout, "tm v2: %s\n", tm_v2.ptr()); // TODO:REMOVE - Replaceall(tm_v2, "$source", value); - Replaceall(tm_v2, "$target", lua_name_v2); - Replaceall(tm_v2, "$value", value); - Replaceall(tm_v2, "$nsname", nsname); - registerConstant(getNSpace(), tm_v2); - } else { - tm_v2 = Swig_typemap_lookup("constcode", n_v2, name, 0); - if (!tm_v2) { - // This can't be. - assert(false); - Swig_restore(n); - return SWIG_ERROR; - } - Replaceall(tm_v2, "$source", value); - Replaceall(tm_v2, "$target", lua_name_v2); - Replaceall(tm_v2, "$value", value); - Replaceall(tm_v2, "$nsname", nsname); - Printf(f_init, "%s\n", tm_v2); + Setattr(n_v2, "sym:name", lua_name_v2); + tm_v2 = Swig_typemap_lookup("consttab", n_v2, name, 0); + if (tm_v2) { + //Printf(stdout, "tm v2: %s\n", tm_v2.ptr()); // TODO:REMOVE + Replaceall(tm_v2, "$source", value); + Replaceall(tm_v2, "$target", lua_name_v2); + Replaceall(tm_v2, "$value", value); + Replaceall(tm_v2, "$nsname", nsname); + registerConstant(getNSpace(), tm_v2); + } else { + tm_v2 = Swig_typemap_lookup("constcode", n_v2, name, 0); + if (!tm_v2) { + // This can't be. + assert(false); + Swig_restore(n); + return SWIG_ERROR; + } + Replaceall(tm_v2, "$source", value); + Replaceall(tm_v2, "$target", lua_name_v2); + Replaceall(tm_v2, "$value", value); + Replaceall(tm_v2, "$nsname", nsname); + Printf(f_init, "%s\n", tm_v2); + } + Delete(n_v2); } - Delete(n_v2); } Swig_restore(n); @@ -2174,6 +2170,9 @@ public: // If inside class, but current[NO_CPP], then this is friend function. It belongs to NSpace if (!getCurrentClass() || current[NO_CPP]) { scope = getNSpace(); + } else if (current[ENUM_CONST] && !CPlusPlus ) { + // Enums in C mode go to NSpace + scope = getNSpace(); } else { // If inside class, then either class static namespace or class fully qualified name is used assert(!current[NO_CPP]); From 1da65de2b7eb6b78b68151d77d88542189e27dab Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Mon, 3 Mar 2014 11:29:04 +0400 Subject: [PATCH 1059/1160] Removing all TODO:REMOVE --- Lib/lua/luarun.swg | 68 +----------------------------------------- Source/Modules/lua.cxx | 21 ------------- 2 files changed, 1 insertion(+), 88 deletions(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index ec6052fe5..1d75ccb34 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -379,8 +379,6 @@ SWIGINTERN int SWIG_Lua_set_immutable(lua_State *L) } #ifdef SWIG_LUA_ELUA_EMULATE -//#define report(...) printf(__VA_ARGS__) // TODO: REMOVE -#define report(...) // TODO : REMOVE SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *type, int own); SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_type_info *type); @@ -405,30 +403,20 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent int i; int table_parsed = 0; int pairs_start = lua_gettop(L); - static int tabs_count = 0; // TODO: REMOVE for(i = 0;table[i].key.type != LUA_TNIL || table[i].value.type != LUA_TNIL;i++) { - /* TODO: REMOVE */ - int j = 0; - for(j=0;jkey.type) { case LUA_TSTRING: lua_pushstring(L,entry->key.key.strkey); - report(" %s :", entry->key.key.strkey); // TODO: REMOVE if(strcmp(entry->key.key.strkey, SWIG_LUA_ELUA_EMUL_METATABLE_KEY) == 0) is_metatable = 1; break; case LUA_TNUMBER: lua_pushnumber(L,entry->key.key.numkey); - report(" %f :", (double)(entry->key.key.numkey)); // TODO: REMOVE break; case LUA_TNIL: - report(" nil :"); // TODO: REMOVE lua_pushnil(L); break; default: @@ -437,39 +425,27 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent switch(entry->value.type) { case LUA_TSTRING: lua_pushstring(L,entry->value.value.string); - report(" %s", entry->value.value.string); // TODO: REMOVE break; case LUA_TNUMBER: lua_pushnumber(L,entry->value.value.number); - report(" %f", (double)(entry->value.value.number)); // TODO: REMOVE break; case LUA_TFUNCTION: - report(" %p", (void*)(entry->value.value.function)); // TODO: REMOVE lua_pushcfunction(L,entry->value.value.function); break; case LUA_TTABLE: - /* TODO: REMOVE */ - report(" table"); - tabs_count++; - /* END OF REMOVE */ lua_rawgetp(L,parsed_tables_array, entry->value.value.table); table_parsed = !lua_isnil(L,-1); if(!table_parsed) { lua_pop(L,1); /*remove nil */ - report("\n"); // TODO: REMOVE lua_newtable(L); SWIG_Lua_elua_emulate_register(L,entry->value.value.table); - } else { - report(" already parsed"); // TODO: REMOVE - } + } if(is_metatable) { - report(" (registering metatable)"); // TODO: REMOVE assert(lua_istable(L,-1)); lua_pushvalue(L,-1); lua_setmetatable(L,target_table); } - tabs_count--; /*TODO: REMOVE*/ break; case LUA_TUSERDATA: if(entry->value.value.userdata.member) @@ -481,7 +457,6 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent *(entry->value.value.userdata.ptype),0); break; case LUA_TNIL: - report(" nil"); // TODO: REMOVE lua_pushnil(L); break; default: @@ -489,7 +464,6 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent } assert(lua_gettop(L) == pairs_start + 2); lua_rawset(L,target_table); - report("\n"); // TODO: REMOVE } lua_pop(L,1); /* Removing parsed tables storage */ assert(lua_gettop(L) == target_table); @@ -501,7 +475,6 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register_clear(lua_State *L) lua_rawsetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key); } -/* TODO: REMOVE */ SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L); SWIGINTERN int SWIG_Lua_emulate_elua_getmetatable(lua_State *L) @@ -519,7 +492,6 @@ SWIGINTERN int SWIG_Lua_emulate_elua_getmetatable(lua_State *L) /*if it is a table, then emulate elua behaviour - check for __metatable attribute of a table*/ assert(lua_gettop(L) == 2); if(lua_istable(L,-2)) { - printf("getmetatable: elua emulation part\n"); // TODO: REMOVE lua_pop(L,1); /*remove the nil*/ lua_getfield(L,-1, SWIG_LUA_ELUA_EMUL_METATABLE_KEY); } @@ -533,7 +505,6 @@ fail: SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L) { - int begin = lua_gettop(L); // TODO: REMOVE SWIG_Lua_get_class_registry(L); lua_pushglobaltable(L); lua_pushstring(L,"lua_getmetatable"); @@ -544,7 +515,6 @@ SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L) lua_pushcfunction(L, SWIG_Lua_emulate_elua_getmetatable); lua_rawset(L,-3); lua_pop(L,2); - assert(lua_gettop(L) == begin); // TODO: REMOVE } /* END OF REMOVE */ @@ -619,7 +589,6 @@ SWIGINTERN int SWIG_Lua_namespace_set(lua_State *L) } lua_pop(L,1); /* remove the value .set table */ lua_pop(L,1); /* remote metatable */ - assert(lua_gettop(L) == 3); // TODO: REMOVE lua_rawset(L,-3); return 0; } @@ -805,7 +774,6 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, i lua_setmetatable(L,subcall_first_arg); /* Set new metatable */ assert(lua_gettop(L) == subcall_last_arg); result = func(L, base_swig_type,subcall_first_arg, ret); /* Forward call */ - if(ret) assert(lua_gettop(L) == subcall_last_arg + *ret); // TODO: REMOVE if(result != SWIG_ERROR) { break; } @@ -817,7 +785,6 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, i const int to_remove = subcall_last_arg - last_arg; for(j=0;jfqname); for(i=0;clss->base_names[i];i++) @@ -1191,7 +1129,6 @@ SWIGINTERN int SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss) SWIG_Lua_class_squash_base(L, clss->bases[i]); } lua_pop(L,1); /*tidy stack*/ - assert(lua_gettop(L) == begin); // TODO: REMOVE } #endif @@ -1263,7 +1200,6 @@ SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L,swig_lua_class */ if(clss->metatable) { for(i=0;clss->metatable[i].name;i++) { - assert(clss->metatable[i].func != 0); // TODO: REMOVE SWIG_Lua_add_function(L,clss->metatable[i].name,clss->metatable[i].func); } } @@ -1332,7 +1268,6 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c * It would get us all special methods: __getitem, __add etc. * This would set .fn, .type, and other .xxx incorrectly, but we will overwrite it right away */ - int squash_begin = lua_gettop(L); // TODO:REMOVE int new_metatable_index = lua_absindex(L,-1); for(i=0;clss->bases[i];i++) { @@ -1341,7 +1276,6 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c SWIG_Lua_merge_tables_by_index(L,new_metatable_index, base_metatable); lua_pop(L,1); } - assert(lua_gettop(L) == squash_begin); // TODO: REMOVE /* And now we will overwrite all incorrectly set data */ #endif /* add string of class name called ".type" */ diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index e25376aaa..2f06b8668 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -486,8 +486,6 @@ public: } } wrapname = Swig_name_wrapper(mrename); - //Printf(stdout, "luaname %s, symname %s mrename %s wrapname %s\n\tscope %s\n", - // Getattr(n, "lua:name"), symname, mrename, wrapname, luaScope ); // TODO: REMOVE registerMethod(n, wrapname, luaScope); } @@ -901,10 +899,6 @@ public: // Remember C name of the wrapping function Setattr(n, "wrap:name", wname); - /* TODO: REMOVE - if (functionWrapperRegisterNow()) { // emit normal fns & static fns - registerMethod(n); - }*/ if (current[CONSTRUCTOR]) { if (constructor_name != 0) Delete(constructor_name); @@ -965,8 +959,6 @@ public: getName = Swig_name_wrapper(getName); if (setName) setName = Swig_name_wrapper(setName); - //Printf(stdout, "luaname %s, symname %s mrename %s getName %s\n\tscope %s\n\tassignable %d\n", - // Getattr(n, "lua:name"), symname, mrename, getName, luaScope, assignable ); // TODO: REMOVE registerVariable(luaScope, n, getName, setName); } @@ -1017,8 +1009,6 @@ public: current[VARIABLE] = true; // let SWIG generate the wrappers int result = Language::variableWrapper(n); - // TODO: REMOVE - //registerVariable(luaCurrentSymbolNSpace(), n, "varget:wrap:name", "varset:wrap:name"); // It is impossible to use registerVariable, because sym:name of the Node is currently // in an undefined state - the callees of this function may have modified it. @@ -1087,7 +1077,6 @@ public: } if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) { - //Printf(stdout, "tm v1: %s\n", tm); // TODO:REMOVE Replaceall(tm, "$source", value); Replaceall(tm, "$target", lua_name); Replaceall(tm, "$value", value); @@ -1116,7 +1105,6 @@ public: lua_name_v2 = Swig_name_member(0, proxy_class_name, lua_name); iname_v2 = Swig_name_member(0, proxy_class_name, iname); n_v2 = Copy(n); - //Printf( stdout, "target name v2: %s, symname v2 %s\n", lua_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE if (!luaAddSymbol(iname_v2, n, getNSpace())) { Swig_restore(n); return SWIG_ERROR; @@ -1125,7 +1113,6 @@ public: Setattr(n_v2, "sym:name", lua_name_v2); tm_v2 = Swig_typemap_lookup("consttab", n_v2, name, 0); if (tm_v2) { - //Printf(stdout, "tm v2: %s\n", tm_v2.ptr()); // TODO:REMOVE Replaceall(tm_v2, "$source", value); Replaceall(tm_v2, "$target", lua_name_v2); Replaceall(tm_v2, "$value", value); @@ -1472,7 +1459,6 @@ public: Printf(f_wrappers, ", %s, %s, &%s", s_methods_tab_name, s_attr_tab_name, Getattr(static_cls, "cname")); if (!eluac_ltr) { - assert(Getattr(instance_cls, "metatable:name")); // TODO: REMOVE Printf(f_wrappers, ", %s", Getattr(instance_cls,"metatable:name")); } else @@ -1513,7 +1499,6 @@ public: current[MEMBER_FUNC] = true; Language::memberfunctionHandler(n); - //Printf( stdout, "add member function: %s to %s\n", symname, luaCurrentSymbolNSpace());// TODO: REMOVE registerMethod(n); current[MEMBER_FUNC] = false; return SWIG_OK; @@ -1668,7 +1653,6 @@ public: // not the C++ name. This is because an earlier version used such a scheme for static function // name generation and we have to maintain backward compatibility. String *v2_name = Swig_name_member(NIL, proxy_class_name, lua_name); - //Printf( stdout, "Name %s, class %s, compt. name %s\n", lua_name, proxy_class_name, v2_name ); // TODO: REMOVE if (!GetFlag(n, "wrappedasconstant")) { Setattr(n, "lua:name", v2_name); // Registering static var in the class parent nspace @@ -1900,8 +1884,6 @@ public: Printf(metatable_tab, "const LUA_REG_TYPE "); else Printf(metatable_tab, "static swig_lua_method "); - assert(metatable_tab); // TODO: REMOVE - assert(metatable_tab_name); // TODO: REMOVE Printv(metatable_tab, metatable_tab_name, "[]", NIL); Printv(metatable_tab_decl, metatable_tab, ";", NIL); Printv(metatable_tab, " = {\n", NIL); @@ -1925,7 +1907,6 @@ public: String *item = Getitem(components, i); Printv(parent_path, item, NIL); } - //Printf(stdout, "Registering %s. User name %s. C-name %s, Parent is %s\n", mangled_name, name, cname, parent_path); // TODO: REMOVE Hash *parent = getCArraysHash(parent_path, true); String *namespaces_tab = Getattr(parent, "namespaces"); Printv(namespaces_tab, "&", cname, ",\n", NIL); @@ -1982,12 +1963,10 @@ public: } String *methods_tab = Getattr(carrays_hash, "methods"); String *metatable_tab_name = Getattr(carrays_hash, "metatable:name"); - assert(methods_tab); // TODO: REMOVE if (elua_ltr || eluac_ltr) { if (v2_compatibility) Printv(methods_tab, tab4, "{LSTRKEY(\"const\"), LROVAL(", const_tab_name, ")},\n", NIL); if (elua_ltr) { - assert(metatable_tab_name); // TODO: REMOVE Printv(methods_tab, tab4, "{LSTRKEY(\"__metatable\"), LROVAL(", metatable_tab_name, ")},\n", NIL); } From 5f7f8f17eb15007c6d9ca66531c131991ccca560 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 3 Mar 2014 19:12:12 +0000 Subject: [PATCH 1060/1160] C++11 rvalue reference docs updated. --- Doc/Manual/CPlusPlus11.html | 81 +++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 26 deletions(-) diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index 9d315d8e3..86a042d78 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -62,12 +62,15 @@

    This chapter gives you a brief overview about the SWIG implementation of the C++11 standard. This part of SWIG is still a work in -progress. Initial C++11 support for SWIG was written during the -Google Summer of Code 2009 period.

    -

    SWIG supports all the new C++ syntax changes with some minor limitations +progress. +

    +

    SWIG supports the new C++ syntax changes with some minor limitations (decltype expressions, variadic templates number). Wrappers for the -new STL types (unordered_ containers, result_of, tuples) are not supported -yet.

    +new STL types (unordered_ containers, result_of, tuples) are incomplete. +The wrappers for the new containers would work much like the C++03 containers and +users are welcome to help by adapting the existing container interface files and submitting them +as a patch for inclusion in future versions of SWIG. +

    7.2 Core language changes

    @@ -75,19 +78,45 @@ yet.

    7.2.1 Rvalue reference and move semantics

    -

    SWIG correctly parses the new operator && the same as the reference operator &.

    +

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

    -

    The wrapper for the following code is correctly produced:

     class MyClass {
    -  MyClass(MyClass&& p) : ptr(p.ptr) {p.ptr = 0;}
    -  MyClass& operator=(MyClass&& p) {
    -    std::swap(ptr, p.ptr);
    +...
    +  std::vector numbers;
    +public:
    +  MyClass(MyClass &&other) : numbers(std::move(other.numbers)) {}
    +  MyClass & operator=(MyClass &&other) {
    +    numbers = std::move(other.numbers);
         return *this;
       }
     };
     
    +

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

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

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

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

    7.2.2 Generalized constant expressions

    @@ -387,7 +416,7 @@ public: int b; int c; - A() : A( 10 ) {} + A() : A(10) {} A(int aa) : A(aa, 20) {} A(int aa, int bb) : A(aa, bb, 30) {} A(int aa, int bb, int cc) { a=aa; b=bb; c=cc; } @@ -524,9 +553,9 @@ public: class TestClass { public: //implicit converting constructor - TestClass( U const &val ) { t=val.u; } + TestClass(U const &val) { t=val.u; } // explicit constructor - explicit TestClass( V const &val ) { t=val.v; } + explicit TestClass(V const &val) { t=val.v; } int t; }; @@ -629,7 +658,7 @@ initializers) with some limitations. The following code is correctly parsed:

     template <typename... BaseClasses> class ClassName : public BaseClasses... {
     public:
    -   ClassName (BaseClasses&&... baseClasses) : BaseClasses(baseClasses)... {}
    +   ClassName (BaseClasses &&... baseClasses) : BaseClasses(baseClasses)... {}
     }
     
    @@ -773,8 +802,8 @@ For example:

     struct NonCopyable {
    -  NonCopyable& operator=(const NonCopyable&) = delete; /* Removes operator= */
    -  NonCopyable(const NonCopyable&) = delete;                /* Removed copy constructor */
    +  NonCopyable & operator=(const NonCopyable &) = delete; /* Removes operator= */
    +  NonCopyable(const NonCopyable &) = delete;                /* Removed copy constructor */
       NonCopyable() = default;                                     /* Explicitly allows the empty constructor */
       void *operator new(std::size_t) = delete;                    /* Removes new NonCopyable */
     };
    @@ -881,19 +910,19 @@ There is no special smart pointer handling available for std::weak_ptr
     

    The new ref and cref classes are used to instantiate a parameter as a reference of a template function. For example:

    -void f( int &r )  { r++; }
    +void f(int &r)  { r++; }
      
     // Template function.
    -template< class F, class P > void g( F f, P t )  { f(t); }
    +template< class F, class P > void g(F f, P t)  { f(t); }
      
     int main() {
       int i = 0 ;
    -  g( f, i ) ;  // 'g<void ( int &r ), int>' is instantiated
    -               // then 'i' will not be modified.
    +  g(f, i) ;  // 'g<void (int &r), int>' is instantiated
    +             // then 'i' will not be modified.
       cout << i << endl ;  // Output -> 0
      
    -  g( f, ref(i) ) ;  // 'g<void(int &r),reference_wrapper<int>>' is instantiated
    -                    // then 'i' will be modified.
    +  g(f, ref(i)) ;  // 'g<void(int &r),reference_wrapper<int>>' is instantiated
    +                  // then 'i' will be modified.
       cout << i << endl ;  // Output -> 1
     }
     
    @@ -939,17 +968,17 @@ b = t(1,2) # invoke C++ function object
     // First way of operating.
     template< bool B > struct algorithm {
    -  template< class T1, class T2 > int do_it( T1&, T2& )  { /*...*/ }
    +  template< class T1, class T2 > int do_it(T1 &, T2 &)  { /*...*/ }
     };
     // Second way of operating.
     template<> struct algorithm<true> {
    -  template< class T1, class T2 > int do_it( T1, T2 )  { /*...*/ }
    +  template< class T1, class T2 > int do_it(T1, T2)  { /*...*/ }
     };
     // Instantiating 'elaborate' will automatically instantiate the correct way to operate.
    -template< class T1, class T2 > int elaborate( T1 A, T2 B ) {
    +template< class T1, class T2 > int elaborate(T1 A, T2 B) {
       // Use the second way only if 'T1' is an integer and if 'T2' is
       // in floating point, otherwise use the first way.
    -  return algorithm< is_integral<T1>::value && is_floating_point<T2>::value >::do_it( A, B );
    +  return algorithm< is_integral<T1>::value && is_floating_point<T2>::value >::do_it(A, B);
     }
     
    From c99417ab136ed643c437065c88368b67b4e77fa3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 4 Mar 2014 07:54:37 +0000 Subject: [PATCH 1061/1160] Lua documentation tweaks and make nspace example more concise. --- Doc/Manual/Lua.html | 34 ++++++++++++---------------------- Examples/lua/nspace/example.h | 9 ++------- Examples/lua/nspace/example.i | 4 ++-- Examples/lua/nspace/runme.lua | 5 +++++ 4 files changed, 21 insertions(+), 31 deletions(-) diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index c38afb31d..e7d1a5b1b 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -510,13 +510,14 @@ Enums are exported into a class table. For example, given some enums: enum Days { SUNDAY = 0, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }; struct Test { enum { TEST1 = 10, TEST2 = 20 }; -#ifdef __cplusplus // There are no static members in C language +#ifdef __cplusplus // There are no static members in C static const int ICONST = 12; #endif };

    -There is a slight difference in behaviour in C mode and C++ model. In C++ mode this is 'effectively' converted into the following Lua code: +There is a slight difference in behaviour wrapping C and C++ code due to the different scoping rules of C and C++. +The wrapped C++ code is used as follows from Lua code:

     > print(example.SUNDAY)
    @@ -527,7 +528,7 @@ There is a slight difference in behaviour in C mode and C++ model. In C++ mode t
     12
     
    -

    In C mode enums from structs are exported into global namespace (due to C Standard). See below:

    +

    Enums within a C struct are in the global namespace and are used as follows from Lua

     > print(example.SUNDAY)
     0
    @@ -538,7 +539,8 @@ There is a slight difference in behaviour in C mode and C++ model. In C++ mode t
     
     

    Compatibility Note: Versions of SWIG prior to SWIG-3.0.0 did not generate the class table members above. -The following code was the only way to access these constants/enums: +There is no change in the C wrappers, but +the following code was the only way to access these constants/enums when wrapping C++ member constants:

     > print(example.Test_TEST1)
    @@ -551,15 +553,6 @@ The old-style bindings are still generated in addition to the new ones.
     If the -no-old-metatable-bindings option is used, then these old-style bindings are not generated.
     

    -However, in C mode, prefixed names of enums are not exported. There is no sense in having both Test_TEST1 and TEST1 in global namespace. -

    -
    -> print(example.TEST1)
    -10
    -> print(example.Test_TEST1)
    -nil
    -
    -

    It is worth mentioning, that example.Test.TEST1 and example.Test_TEST1 are different entities and changing one does not change the other. Given the fact that these are constantes and they are not supposed to be changed, it is up to you to avoid such issues.

    @@ -749,7 +742,7 @@ public: };

    -In Lua, the static members can be accessed as follows: +In Lua, C++ static members can be accessed as follows:

     > example.Spam.foo()            -- calling Spam::foo()
    @@ -1357,20 +1350,15 @@ int module_variable = 9;
     namespace MyWorld {
       class World {
       public:
    -    World():
    -      world_max_count(9) {}
    +    World() : world_max_count(9) {}
         int create_world() { return 17; }
         const int world_max_count; // = 9
       };
       namespace Nested {
         class Dweller {
           public:
    -        Dweller():
    -          food_count(11) {}
             enum Gender { MALE = 0, FEMALE = 1 };
    -        static int populate_cave() { return 19; }
    -        int create_cave() { return 13; }
    -        int food_count; // = 11
    +        static int count() { return 19; }
         };
       }
     }
    @@ -1387,6 +1375,8 @@ Now, from Lua usage is as follows:
     9
     > print(example.MyWorld.Nested.Dweller.MALE)
     0
    +> print(example.MyWorld.Nested.Dweller.count())
    +19
     >
     

    Compatibility Note

    @@ -1397,7 +1387,7 @@ If SWIG is running in backward compatible way, i.e. without -no-old-metatabl 9 > print(example.MyWorld.Nested.Dweller_MALE) 0 -> print(example.MyWorld.Nested.Dweller_populate_cave()) +> print(example.MyWorld.Nested.Dweller_count()) 11 >
    diff --git a/Examples/lua/nspace/example.h b/Examples/lua/nspace/example.h index 8c528bfc6..53066980a 100644 --- a/Examples/lua/nspace/example.h +++ b/Examples/lua/nspace/example.h @@ -7,20 +7,15 @@ int module_variable = 9; namespace MyWorld { class World { public: - World(): - world_max_count(9) {} + World() : world_max_count(9) {} int create_world() { return 17; } const int world_max_count; // = 9 }; namespace Nested { class Dweller { public: - Dweller(): - food_count(11) {} enum Gender { MALE = 0, FEMALE = 1 }; - static int populate_cave() { return 19; } - int create_cave() { return 13; } - int food_count; // = 11 + static int count() { return 19; } }; } } diff --git a/Examples/lua/nspace/example.i b/Examples/lua/nspace/example.i index 04a906fab..c30f87fec 100644 --- a/Examples/lua/nspace/example.i +++ b/Examples/lua/nspace/example.i @@ -4,7 +4,7 @@ #include "example.h" %} - %nspace MyWorld::Nested::Dweller; - %nspace MyWorld::World; +%nspace MyWorld::Nested::Dweller; +%nspace MyWorld::World; %include "example.h" diff --git a/Examples/lua/nspace/runme.lua b/Examples/lua/nspace/runme.lua index ad5816d36..876814052 100644 --- a/Examples/lua/nspace/runme.lua +++ b/Examples/lua/nspace/runme.lua @@ -37,5 +37,10 @@ assert( w1.world_max_count == 9 ) -- Accessing enums from class within namespace print( "Accessing enums: ex.MyWorld.Nested.Dweller.MALE = ", ex.MyWorld.Nested.Dweller.MALE ) assert( ex.MyWorld.Nested.Dweller.MALE == 0 ) +print( "Accessing enums: ex.MyWorld.Nested.Dweller.FEMALE = ", ex.MyWorld.Nested.Dweller.FEMALE ) assert( ex.MyWorld.Nested.Dweller.FEMALE == 1 ) +-- Accessing static member function +print( "Accessing static member function: ex.MyWorld.Nested.Dweller.count() = ", ex.MyWorld.Nested.Dweller.count() ) +assert( ex.MyWorld.Nested.Dweller.count() == 19 ) + From e48dee81eaa1db588ba5c1818eeca1f7982930ae Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Tue, 4 Mar 2014 13:54:38 +0400 Subject: [PATCH 1062/1160] Disable old-names generation for enums in class in namespace --- Source/Modules/lua.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 2f06b8668..4a9676611 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -1166,9 +1166,15 @@ public: virtual int enumDeclaration(Node *n) { current[STATIC_CONST] = true; current[ENUM_CONST] = true; + // Drop v2_compatibility if NSpace is given + int old_v2_compatibility = v2_compatibility; + if (getNSpace()) { + v2_compatibility = 0; + } int result = Language::enumDeclaration(n); current[STATIC_CONST] = false; current[ENUM_CONST] = false; + v2_compatibility = old_v2_compatibility; return result; } From 869de3e7614814bcbf827d6796ef44d4c7047855 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Tue, 4 Mar 2014 14:30:10 +0400 Subject: [PATCH 1063/1160] Getattribute->GetFlag --- Source/Modules/lua.cxx | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 4a9676611..0a5a00515 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -1285,7 +1285,7 @@ public: // * consider effect on template_specialization_defarg static Hash *emitted = NewHash(); - if (Getattr(emitted, mangled_fr_t)) { + if (GetFlag(emitted, mangled_fr_t)) { full_proxy_class_name = 0; proxy_class_name = 0; return SWIG_NOWRAP; @@ -1901,7 +1901,7 @@ public: Setattr(scope, "lua:cdata", carrays_hash); assert(rawGetCArraysHash(nspace)); - if (reg && nspace != 0 && Len(nspace) != 0 && Getattr(carrays_hash, "lua:no_reg") == 0) { + if (reg && nspace != 0 && Len(nspace) != 0 && GetFlag(carrays_hash, "lua:no_reg") == 0) { // Split names into components List *components = Split(nspace, '.', -1); String *parent_path = NewString(""); @@ -1947,7 +1947,7 @@ public: void closeCArraysHash(String *nspace, File *output) { Hash *carrays_hash = rawGetCArraysHash(nspace); assert(carrays_hash); - assert(Getattr(carrays_hash, "lua:closed") == 0); + assert(GetFlag(carrays_hash, "lua:closed") == 0); SetFlag(carrays_hash, "lua:closed"); @@ -1982,13 +1982,13 @@ public: Printf(methods_tab, " {0,0}\n};\n"); Printv(output, methods_tab, NIL); - if (!Getattr(carrays_hash, "lua:no_classes")) { + if (!GetFlag(carrays_hash, "lua:no_classes")) { String *classes_tab = Getattr(carrays_hash, "classes"); Printf(classes_tab, " 0\n};\n"); Printv(output, classes_tab, NIL); } - if (!Getattr(carrays_hash, "lua:no_namespaces")) { + if (!GetFlag(carrays_hash, "lua:no_namespaces")) { String *namespaces_tab = Getattr(carrays_hash, "namespaces"); Printf(namespaces_tab, " 0\n};\n"); Printv(output, namespaces_tab, NIL); @@ -2009,7 +2009,7 @@ public: String *get_tab_name = Getattr(carrays_hash, "get:name"); String *set_tab_name = Getattr(carrays_hash, "set:name"); - if (Getattr(carrays_hash, "lua:class_instance")) { + if (GetFlag(carrays_hash, "lua:class_instance")) { Printv(metatable_tab, tab4, "{LSTRKEY(\"__index\"), LFUNCVAL(SWIG_Lua_class_get)},\n", NIL); Printv(metatable_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_class_set)},\n", NIL); } else { @@ -2022,7 +2022,7 @@ public: Printv(metatable_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(", set_tab_name, ")},\n", NIL); Printv(metatable_tab, tab4, "{LSTRKEY(\".fn\"), LROVAL(", Getattr(carrays_hash, "methods:name"), ")},\n", NIL); - if (Getattr(carrays_hash, "lua:class_instance")) { + if (GetFlag(carrays_hash, "lua:class_instance")) { String *static_cls = Getattr(carrays_hash, "lua:class_instance:static_hash"); assert(static_cls); // static_cls is swig_lua_namespace. This structure can't be use with eLua(LTR) @@ -2032,7 +2032,7 @@ public: Printv(metatable_tab, tab4, "{LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL); // Put forward declaration of this array Printv(output, "extern ", Getattr(static_cls, "methods:decl"), "\n", NIL); - } else if (Getattr(carrays_hash, "lua:class_static")) { + } else if (GetFlag(carrays_hash, "lua:class_static")) { Hash *instance_cls = Getattr(carrays_hash, "lua:class_static:instance_hash"); assert(instance_cls); String *instance_cls_metatable_name = Getattr(instance_cls, "metatable:name"); @@ -2080,7 +2080,7 @@ public: // We have a pseudo symbol. Lets get actual scope for this pseudo symbol Hash *carrays_hash = rawGetCArraysHash(ki.key); assert(carrays_hash); - if (Getattr(carrays_hash, "lua:closed") == 0) + if (GetFlag(carrays_hash, "lua:closed") == 0) Append(to_close, ki.key); } ki = Next(ki); @@ -2125,8 +2125,8 @@ public: String *const_tab_name = Getattr(carrays_hash, "constants:name"); String *classes_tab_name = Getattr(carrays_hash, "classes:name"); String *namespaces_tab_name = Getattr(carrays_hash, "namespaces:name"); - bool has_classes = Getattr(carrays_hash, "lua:no_classes") == 0; - bool has_namespaces = Getattr(carrays_hash, "lua:no_namespaces") == 0; + bool has_classes = GetFlag(carrays_hash, "lua:no_classes") == 0; + bool has_namespaces = GetFlag(carrays_hash, "lua:no_namespaces") == 0; Printv(output, "{\n", tab4, "\"", name, "\",\n", From 3028b16cee672a796ed0fb4226b127e7a8c493c5 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Thu, 6 Mar 2014 15:24:17 +0400 Subject: [PATCH 1064/1160] Partially disabling old names generation for classes with nspace --- Examples/test-suite/lua/nspace_runme.lua | 10 ++++++++- Examples/test-suite/nspace.i | 6 ++++- Source/Modules/lua.cxx | 28 +++++++++++++----------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Examples/test-suite/lua/nspace_runme.lua b/Examples/test-suite/lua/nspace_runme.lua index 5d55357c0..049d4ff00 100644 --- a/Examples/test-suite/lua/nspace_runme.lua +++ b/Examples/test-suite/lua/nspace_runme.lua @@ -62,6 +62,14 @@ sc = ns.Outer.SomeClass() assert( sc:GetInner1ColorChannel() ~= sc:GetInner2Channel() ) assert( sc:GetInner1Channel() ~= sc:GetInner2Channel() ) +-- Backward compatibility +assert(ns.Outer.Inner1.Diffuse ~= nil) +-- Enums within class within namespace shouldn't have backward compatible name. Same for static methods +assert(ns.Outer.Inner1.Color_Diffuse == nil) +assert(ns.Outer.Inner1.Color_colorStaticMethod == nil) - +-- Enums and static methods of class marked as %nonspace should have backward compatible name +assert(ns.NoNSpacePlease_noNspaceStaticFunc() == 10) +-- assert(ns.NoNSpacePlease_NoNspace1 == 1) +-- assert(ns.NoNSpacePlease.NoNspace2 == 10) diff --git a/Examples/test-suite/nspace.i b/Examples/test-suite/nspace.i index 58c560412..c595322a7 100644 --- a/Examples/test-suite/nspace.i +++ b/Examples/test-suite/nspace.i @@ -67,7 +67,11 @@ namespace Outer { const Outer::Inner2::Color& col2c) {} }; // Color int Color::staticMemberVariable = 0; - class NoNSpacePlease {}; + class NoNSpacePlease { + public: + enum NoNSpaceEnum { NoNspace1 = 1, NoNspace2 = 10 }; + static int noNspaceStaticFunc() { return 10; } + }; } // Inner2 // Derived class diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 0a5a00515..e0fb2c2a0 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -103,13 +103,11 @@ static int squash_bases = 0; * This variable is controled by -no-old-metatable-bindings option. * v2_compatibility - * 1. static methods will be put into the scope their respective class - * belongs to as well as into the class scope itself. + * belongs to as well as into the class scope itself. (only for classes without %nspace given) * 2. The layout in elua mode is somewhat different - * 3. C enums defined inside struct will oblige to C Standard and - * will be defined in the scope surrounding the struct, not scope - * associated with it/ */ static int v2_compatibility = 0; +static int v2_compat_names_generation = 1; // This flag can temporaraly disable backward compatible names generation if v2_compatibiliti is enabled static const int default_api_level = 2; /* NEW LANGUAGE NOTE:*********************************************** @@ -1096,7 +1094,8 @@ public: return SWIG_NOWRAP; } - bool make_v2_compatible = v2_compatibility && getCurrentClass() != 0; + bool make_v2_compatible = v2_compatibility && getCurrentClass() != 0 + && v2_compat_names_generation; if (make_v2_compatible) { // Don't do anything for enums in C mode - they are already @@ -1166,15 +1165,9 @@ public: virtual int enumDeclaration(Node *n) { current[STATIC_CONST] = true; current[ENUM_CONST] = true; - // Drop v2_compatibility if NSpace is given - int old_v2_compatibility = v2_compatibility; - if (getNSpace()) { - v2_compatibility = 0; - } int result = Language::enumDeclaration(n); current[STATIC_CONST] = false; current[ENUM_CONST] = false; - v2_compatibility = old_v2_compatibility; return result; } @@ -1322,12 +1315,21 @@ public: Setattr(instance_cls, "lua:class_instance:static_hash", static_cls); Setattr(static_cls, "lua:class_static:instance_hash", instance_cls); + const int v2_compat_names_generation_old = v2_compat_names_generation; + // If class has %nspace enabled, then generation of backward compatible names + // should be disabled + if (getNSpace()) { + v2_compat_names_generation = 0; + } + /* There is no use for "classes" and "namespaces" arrays. Subclasses are not supported * by SWIG and namespaces couldn't be nested inside classes (C++ Standard) */ // Generate normal wrappers Language::classHandler(n); + v2_compat_names_generation = v2_compat_names_generation_old; + SwigType_add_pointer(t); // Catch all: eg. a class with only static functions and/or variables will not have 'remembered' @@ -1607,7 +1609,7 @@ public: const int result = Language::staticmemberfunctionHandler(n); registerMethod(n); - if (v2_compatibility && result == SWIG_OK) { + if (v2_compatibility && result == SWIG_OK && v2_compat_names_generation) { Swig_require("lua_staticmemberfunctionHandler", n, "*lua:name", NIL); String *lua_name = Getattr(n, "lua:name"); // Although this function uses Swig_name_member, it actually generates the Lua name, @@ -1652,7 +1654,7 @@ public: if (result == SWIG_OK) { // This will add static member variable to the class namespace with name ClassName_VarName - if (v2_compatibility) { + if (v2_compatibility && v2_compat_names_generation) { Swig_save("lua_staticmembervariableHandler", n, "lua:name", NIL); String *lua_name = Getattr(n, "lua:name"); // Although this function uses Swig_name_member, it actually generates the Lua name, From dbf44fc181b880039c20ba8dd3064e3ae7ee0e97 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 6 Mar 2014 19:42:57 +0000 Subject: [PATCH 1065/1160] Fix std::map and smart pointers. Fixes problem with method overloading when some methods are added by %extend and others are real methods and using template default parameters with smart pointers. This is noticeable as a regression since 2.0.12 when using the default smart pointer handling for some languages when the smart pointer wraps std::map and other STL containers. Fixes SF Bug 1363 --- CHANGES.current | 6 ++ Examples/test-suite/common.mk | 1 + ...smart_pointer_template_defaults_overload.i | 56 +++++++++++++++++++ Source/Modules/allocate.cxx | 4 +- Source/Modules/lang.cxx | 6 +- Source/Swig/cwrap.c | 4 +- 6 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 Examples/test-suite/smart_pointer_template_defaults_overload.i diff --git a/CHANGES.current b/CHANGES.current index 8e388dee5..529680e7c 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,12 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-03-06: wsfulton + Fix SF Bug #1363 - Problem with method overloading when some methods are added by %extend + and others are real methods and using template default parameters with smart pointers. + This is noticeable as a regression since 2.0.12 when using the default smart pointer + handling for some languages when the smart pointer wraps std::map and other STL containers. + 2014-03-02: wsfulton [Python] SF Patch #346 from Jens Krueger. Correct exception thrown attempting to access a non-existent C/C++ global variable on the 'cvar' object. The exception thrown diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index b9239315a..e5b61d757 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -347,6 +347,7 @@ CPP_TEST_CASES += \ smart_pointer_simple \ smart_pointer_static \ smart_pointer_template_const_overload \ + smart_pointer_template_defaults_overload \ smart_pointer_templatemethods \ smart_pointer_templatevariables \ smart_pointer_typedef \ diff --git a/Examples/test-suite/smart_pointer_template_defaults_overload.i b/Examples/test-suite/smart_pointer_template_defaults_overload.i new file mode 100644 index 000000000..a1f559ae8 --- /dev/null +++ b/Examples/test-suite/smart_pointer_template_defaults_overload.i @@ -0,0 +1,56 @@ +%module smart_pointer_template_defaults_overload + +// SF Bug #1363 +// Problem with method overloading when some methods are added by %extend and others are real methods +// and using template default parameters with smart pointers. + +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) Wrap::operator->; +%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) Container::rubout; + +%include +%include + +%inline %{ +template +class Wrap { +T *ptr; +public: + Wrap(T *p) : ptr(p) {} + T const* operator->(void) const { return ptr; } + T* operator->(void) { return ptr; } +}; +%} + +%template(StringDoubleMap) std::map; // erase is generated okay +%template(WrappedMap) Wrap< std::map >; // erase wrappers lead to compile error + +// Above only affects some languages depending on how std::map is implemented. +// Below is a cutdown language independent demonstration of the bug + +%extend Container { + void rubout(int, int) {} +} + +%inline %{ +template class Container { +public: + int rubout() { return 0; } + void rubout(T const &element) {} + static Container* factory() { return new Container(); } + static Container* factory(bool b) { return new Container(); } + static void staticstuff(bool) {} +#ifdef SWIG + %extend { + void rubout(bool) {} + } +#endif +}; +%} + +%extend Container { + void rubout(int) {} +} + +%template(ContainerInt) Container; +%template(WrapContainerInt) Wrap< Container >; + diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index d3384e1ba..d3618634b 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -421,7 +421,7 @@ class Allocate:public Dispatcher { while (cc) { Node *cp = cc; if (classname) { - Setattr(cp, "classname", classname); + Setattr(cp, "extendsmartclassname", classname); } Setattr(cp, "allocate:smartpointeraccess", "1"); /* If constant, we have to be careful */ @@ -827,7 +827,7 @@ Allocate(): } List *methods = smart_pointer_methods(sc, 0, isconst); Setattr(inclass, "allocate:smartpointer", methods); - Setattr(inclass, "allocate:smartpointerbase", base); + Setattr(inclass, "allocate:smartpointerpointeeclassname", Getattr(sc, "name")); } else { /* Hmmm. The return value is not a pointer. If the type is a value or reference. We're going to chase it to see if another operator->() diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 04304744c..a7b088f00 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1242,8 +1242,8 @@ int Language::memberfunctionHandler(Node *n) { String *fname = Swig_name_member(NSpace, ClassPrefix, symname); if (Extend && SmartPointer) { - if (!Getattr(n, "classname")) { - Setattr(n, "classname", Getattr(CurrentClass, "allocate:smartpointerbase")); + if (!Getattr(n, "extendsmartclassname")) { + Setattr(n, "extendsmartclassname", Getattr(CurrentClass, "allocate:smartpointerpointeeclassname")); } } // Set up the type for the cast to this class for use when wrapping const director (virtual) methods. @@ -1562,7 +1562,7 @@ int Language::membervariableHandler(Node *n) { int Language::staticmembervariableHandler(Node *n) { Swig_require("staticmembervariableHandler", n, "*name", "*sym:name", "*type", "?value", NIL); String *value = Getattr(n, "value"); - String *classname = !SmartPointer ? (isNonVirtualProtectedAccess(n) ? DirectorClassName : ClassName) : Getattr(CurrentClass, "allocate:smartpointerbase"); + String *classname = !SmartPointer ? (isNonVirtualProtectedAccess(n) ? DirectorClassName : ClassName) : Getattr(CurrentClass, "allocate:smartpointerpointeeclassname"); if (!value || !Getattr(n, "hasconsttype")) { String *name = Getattr(n, "name"); diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 04845f3cf..27eef0ef0 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -941,7 +941,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas is_smart_pointer_overload = 1; } else if (Swig_storage_isstatic(n)) { - String *cname = Getattr(n, "classname") ? Getattr(n, "classname") : classname; + String *cname = Getattr(n, "extendsmartclassname") ? Getattr(n, "extendsmartclassname") : classname; String *ctname = SwigType_namestr(cname); self = NewStringf("(*(%s const *)this)->", ctname); is_smart_pointer_overload = 1; @@ -1058,7 +1058,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas String *defaultargs = Getattr(n, "defaultargs"); String *code = Getattr(n, "code"); - String *cname = Getattr(n, "classname") ? Getattr(n, "classname") : classname; + String *cname = Getattr(n, "extendsmartclassname") ? Getattr(n, "extendsmartclassname") : classname; String *membername = Swig_name_member(nspace, cname, name); String *mangled = Swig_name_mangle(membername); int is_smart_pointer = flags & CWRAP_SMART_POINTER; From b31507a657c6c791e35d3845c4b79a7f08f790ae Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 7 Mar 2014 12:32:07 +0000 Subject: [PATCH 1066/1160] Use proxy class for rvalue reference parameters --- Source/Modules/lang.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index a7b088f00..6873b0875 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -3237,6 +3237,7 @@ Node *Language::classLookup(const SwigType *s) const { (Len(prefix) == 0) || // simple type (pass by value) (Strcmp(prefix, "p.") == 0) || // pointer (Strcmp(prefix, "r.") == 0) || // reference + (Strcmp(prefix, "z.") == 0) || // rvalue 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)) { From e897733b081d920c893b53dce8b37e937f86cde3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 7 Mar 2014 13:15:53 +0000 Subject: [PATCH 1067/1160] Fix missing fragments in Ruby wstring typemaps --- Lib/ruby/rubywstrings.swg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/ruby/rubywstrings.swg b/Lib/ruby/rubywstrings.swg index bb44fbc6e..b6dd937a5 100644 --- a/Lib/ruby/rubywstrings.swg +++ b/Lib/ruby/rubywstrings.swg @@ -11,7 +11,7 @@ * utility methods for wchar_t strings * ------------------------------------------------------------ */ -%fragment("SWIG_AsWCharPtrAndSize","header",fragment="",fragment="SWIG_pwchar_descriptor") { +%fragment("SWIG_AsWCharPtrAndSize","header",fragment="",fragment="SWIG_pwchar_descriptor",fragment="SWIG_AsCharPtrAndSize") { SWIGINTERN int SWIG_AsWCharPtrAndSize(VALUE obj, wchar_t **cptr, size_t *psize, int *alloc) { @@ -50,7 +50,7 @@ SWIG_AsWCharPtrAndSize(VALUE obj, wchar_t **cptr, size_t *psize, int *alloc) } } -%fragment("SWIG_FromWCharPtrAndSize","header",fragment="",fragment="SWIG_pwchar_descriptor") { +%fragment("SWIG_FromWCharPtrAndSize","header",fragment="",fragment="SWIG_pwchar_descriptor",fragment="SWIG_FromCharPtrAndSize") { SWIGINTERNINLINE VALUE SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size) { From 7f45cbd1783e204a49bba0a4ee7e75a15bd8ec5b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Mar 2014 12:02:08 +0000 Subject: [PATCH 1068/1160] Reorganise broken C++11 testcases --- Examples/test-suite/common.mk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index e5b61d757..1d8a4f04f 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -493,7 +493,7 @@ CPP_TEST_CASES += \ # C++11 test cases. CPP11_TEST_CASES = \ - cpp11_alternate_function_syntax \ + cpp11_alternate_function_syntax \ cpp11_constexpr \ cpp11_decltype \ cpp11_default_delete \ @@ -517,17 +517,17 @@ CPP11_TEST_CASES = \ cpp11_template_double_brackets \ cpp11_template_explicit \ cpp11_template_typedefs \ - cpp11_uniform_initialization \ + cpp11_uniform_initialization \ cpp11_unrestricted_unions \ cpp11_userdefined_literals \ - cpp11_variadic_templates +# Broken C++11 test cases. +CPP11_TEST_BROKEN = \ # cpp11_hash_tables \ # not fully implemented yet # cpp11_result_of \ # SWIG does not support # cpp11_strongly_typed_enumerations \ # SWIG not quite getting this right yet in all langs +# cpp11_variadic_templates \ # Broken for some languages (such as Java) -# Broken C++11 test cases. -CPP11_TEST_BROKEN = # # Put all the heavy STD/STL cases here, where they can be skipped if needed From 504c2030bb03198281df1597aaee177ae5d68b38 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Mar 2014 12:04:19 +0000 Subject: [PATCH 1069/1160] Change in default behaviour wrapping C++ bool for Python. Only a Python True or False will now work for C++ bool parameters. This fixes overloading bool with other types. --- CHANGES.current | 56 ++++++++++++ Examples/test-suite/common.mk | 1 + Examples/test-suite/overload_bool.i | 19 ++++ .../python/li_std_vector_extra_runme.py | 8 +- .../test-suite/python/overload_bool_runme.py | 55 ++++++++++++ .../test-suite/python/primitive_ref_runme.py | 2 +- .../python/reference_global_vars_runme.py | 8 +- .../test-suite/python/std_containers_runme.py | 2 +- .../test-suite/ruby/overload_bool_runme.rb | 88 +++++++++++++++++++ Lib/python/pyprimtypes.swg | 19 ++++ Lib/python/pytypemaps.swg | 4 +- 11 files changed, 251 insertions(+), 11 deletions(-) create mode 100644 Examples/test-suite/overload_bool.i create mode 100644 Examples/test-suite/python/overload_bool_runme.py create mode 100755 Examples/test-suite/ruby/overload_bool_runme.rb diff --git a/CHANGES.current b/CHANGES.current index 529680e7c..9b0642ef4 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,62 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-03-06: wsfulton + [Python] Change in default behaviour wrapping C++ bool. Only a Python True or False + will now work for C++ bool parameters. This fixes overloading bool with other types. + Python 2.3 minimum is now required for wrapping bool. + + When wrapping: + + const char* overloaded(bool value) { return "bool"; } + const char* overloaded(int value) { return "int"; } + + Previous behaviour: + >>> overloaded(False) + 'int' + >>> overloaded(True) + 'int' + >>> overloaded(0) + 'int' + + Now we get the expected behaviour: + >>> overloaded(False) + 'bool' + >>> overloaded(0) + 'int' + + The consequence is when wrapping bool in non-overloaded functions: + + const char* boolfunction(bool value) { return value ? "true" : "false"; } + + The previous behaviour was very Pythonic: + >>> boolfunction("") + 'false' + >>> boolfunction("hi") + 'true' + >>> boolfunction(12.34) + 'true' + >>> boolfunction(0) + 'false' + >>> boolfunction(1) + 'true' + + Now the new behaviour more along the lines of C++ due to stricter type checking. The + above calls result in an exception and need to be explicitly converted into a bool as + follows: + >>> boolfunction(0) + Traceback (most recent call last): + File "", line 1, in + TypeError: in method 'boolfunction', argument 1 of type 'bool' + >>> boolfunction(bool(0)) + 'false' + + The old behaviour can be resurrected by passing the -DSWIG_PYTHON_LEGACY_BOOL command line + parameter when executing SWIG. Typemaps can of course be written to customise the behaviour + for specific parameters. + + *** POTENTIAL INCOMPATIBILITY *** + 2014-03-06: wsfulton Fix SF Bug #1363 - Problem with method overloading when some methods are added by %extend and others are real methods and using template default parameters with smart pointers. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 1d8a4f04f..4466558fb 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -294,6 +294,7 @@ CPP_TEST_CASES += \ operator_pointer_ref \ operbool \ ordering \ + overload_bool \ overload_copy \ overload_extend \ overload_method \ diff --git a/Examples/test-suite/overload_bool.i b/Examples/test-suite/overload_bool.i new file mode 100644 index 000000000..d48bfc299 --- /dev/null +++ b/Examples/test-suite/overload_bool.i @@ -0,0 +1,19 @@ +%module overload_bool + +%inline %{ +const char* overloaded(bool value) { return "bool"; } +const char* overloaded(int value) { return "int"; } +const char* overloaded(const char *value) { return "string"; } + +const char* boolfunction(bool value) { return value ? "true" : "false"; } +const char* intfunction(int value) { return "int"; } + + +// Const references +const char* overloaded_ref(bool const& value) { return "bool"; } +const char* overloaded_ref(int const& value) { return "int"; } +const char* overloaded_ref(const char *value) { return "string"; } + +const char* boolfunction_ref(bool const& value) { return value ? "true" : "false"; } +const char* intfunction_ref(int const& value) { return "int"; } +%} diff --git a/Examples/test-suite/python/li_std_vector_extra_runme.py b/Examples/test-suite/python/li_std_vector_extra_runme.py index 8900d7298..d24d36cb6 100644 --- a/Examples/test-suite/python/li_std_vector_extra_runme.py +++ b/Examples/test-suite/python/li_std_vector_extra_runme.py @@ -17,10 +17,10 @@ halve_in_place(dv) bv = BoolVector(4) -bv[0]= 1 -bv[1]= 0 -bv[2]= 4 -bv[3]= 0 +bv[0]= bool(1) +bv[1]= bool(0) +bv[2]= bool(4) +bv[3]= bool(0) if bv[0] != bv[2]: raise RuntimeError,"bad std::vector mapping" diff --git a/Examples/test-suite/python/overload_bool_runme.py b/Examples/test-suite/python/overload_bool_runme.py new file mode 100644 index 000000000..ed7d1b5a1 --- /dev/null +++ b/Examples/test-suite/python/overload_bool_runme.py @@ -0,0 +1,55 @@ +import overload_bool + +# Overloading bool, int, string +if overload_bool.overloaded(True) != "bool": + raise RuntimeError("wrong!") +if overload_bool.overloaded(False) != "bool": + raise RuntimeError("wrong!") + +if overload_bool.overloaded(0) != "int": + raise RuntimeError("wrong!") +if overload_bool.overloaded(1) != "int": + raise RuntimeError("wrong!") +if overload_bool.overloaded(2) != "int": + raise RuntimeError("wrong!") + +if overload_bool.overloaded("1234") != "string": + raise RuntimeError("wrong!") + +# Test bool masquerading as int +if overload_bool.intfunction(True) != "int": + raise RuntimeError("wrong!") +if overload_bool.intfunction(False) != "int": + raise RuntimeError("wrong!") + +# Test int masquerading as bool +# Not possible + + +############################################# + +# Overloading bool, int, string +if overload_bool.overloaded_ref(True) != "bool": + raise RuntimeError("wrong!") +if overload_bool.overloaded_ref(False) != "bool": + raise RuntimeError("wrong!") + +if overload_bool.overloaded_ref(0) != "int": + raise RuntimeError("wrong!") +if overload_bool.overloaded_ref(1) != "int": + raise RuntimeError("wrong!") +if overload_bool.overloaded_ref(2) != "int": + raise RuntimeError("wrong!") + +if overload_bool.overloaded_ref("1234") != "string": + raise RuntimeError("wrong!") + +# Test bool masquerading as int +if overload_bool.intfunction_ref(True) != "int": + raise RuntimeError("wrong!") +if overload_bool.intfunction_ref(False) != "int": + raise RuntimeError("wrong!") + +# Test int masquerading as bool +# Not possible + diff --git a/Examples/test-suite/python/primitive_ref_runme.py b/Examples/test-suite/python/primitive_ref_runme.py index 7ce872a62..f3a640389 100644 --- a/Examples/test-suite/python/primitive_ref_runme.py +++ b/Examples/test-suite/python/primitive_ref_runme.py @@ -30,7 +30,7 @@ if ref_float(3.5) != 3.5: if ref_double(3.5) != 3.5: raise RuntimeError -if ref_bool(1) != 1: +if ref_bool(True) != True: raise RuntimeError if ref_char('x') != 'x': diff --git a/Examples/test-suite/python/reference_global_vars_runme.py b/Examples/test-suite/python/reference_global_vars_runme.py index aa42ff50b..98aaec5fe 100644 --- a/Examples/test-suite/python/reference_global_vars_runme.py +++ b/Examples/test-suite/python/reference_global_vars_runme.py @@ -5,12 +5,12 @@ if getconstTC().num != 33: raise RuntimeError # primitive reference variables -cvar.var_bool = createref_bool(0) -if value_bool(cvar.var_bool) != 0: +cvar.var_bool = createref_bool(False) +if value_bool(cvar.var_bool) != False: raise RuntimeError -cvar.var_bool = createref_bool(1) -if value_bool(cvar.var_bool) != 1: +cvar.var_bool = createref_bool(True) +if value_bool(cvar.var_bool) != True: raise RuntimeError cvar.var_char = createref_char('w') diff --git a/Examples/test-suite/python/std_containers_runme.py b/Examples/test-suite/python/std_containers_runme.py index bed59bb29..f90c98405 100644 --- a/Examples/test-suite/python/std_containers_runme.py +++ b/Examples/test-suite/python/std_containers_runme.py @@ -46,7 +46,7 @@ for i in range(0,len(m)): if m[i][j] != im[i][j]: raise RuntimeError, "bad getslice" -m = ((1,0,1),(1,1),(1,1)) +m = ((True,False,True),(True,True),(True,True)) im = std_containers.midentb(m) for i in range(0,len(m)): for j in range(0,len(m[i])): diff --git a/Examples/test-suite/ruby/overload_bool_runme.rb b/Examples/test-suite/ruby/overload_bool_runme.rb new file mode 100755 index 000000000..8b7568e94 --- /dev/null +++ b/Examples/test-suite/ruby/overload_bool_runme.rb @@ -0,0 +1,88 @@ +#!/usr/bin/env ruby +# +# Put description here +# +# +# +# +# + +require 'swig_assert' + +require 'overload_bool' + +include Overload_bool + +# Overloading bool, int, string +if overloaded(true) != "bool" + raise RuntimeError, "wrong!" +end +if overloaded(false) != "bool" + raise RuntimeError, "wrong!" +end + +if overloaded(0) != "int" + raise RuntimeError, "wrong!" +end +if overloaded(1) != "int" + raise RuntimeError, "wrong!" +end +if overloaded(2) != "int" + raise RuntimeError, "wrong!" +end + +if overloaded("1234") != "string" + raise RuntimeError, "wrong!" +end + +# Test bool masquerading as integer +# Not possible + +# Test int masquerading as bool +if boolfunction(0) != "false" + raise RuntimeError, "wrong!" +end +if boolfunction(1) != "true" + raise RuntimeError, "wrong!" +end +if boolfunction(2) != "true" + raise RuntimeError, "wrong!" +end + +############################################# + +# Overloading bool, int, string +if overloaded_ref(true) != "bool" + raise RuntimeError, "wrong!" +end +if overloaded_ref(false) != "bool" + raise RuntimeError, "wrong!" +end + +if overloaded_ref(0) != "int" + raise RuntimeError, "wrong!" +end +if overloaded_ref(1) != "int" + raise RuntimeError, "wrong!" +end +if overloaded_ref(2) != "int" + raise RuntimeError, "wrong!" +end + +if overloaded_ref("1234") != "string" + raise RuntimeError, "wrong!" +end + +# Test bool masquerading as integer +# Not possible + +# Test int masquerading as bool +if boolfunction_ref(0) != "false" + raise RuntimeError, "wrong!" +end +if boolfunction_ref(1) != "true" + raise RuntimeError, "wrong!" +end +if boolfunction_ref(2) != "true" + raise RuntimeError, "wrong!" +end diff --git a/Lib/python/pyprimtypes.swg b/Lib/python/pyprimtypes.swg index 66ff104a6..30bb64f66 100644 --- a/Lib/python/pyprimtypes.swg +++ b/Lib/python/pyprimtypes.swg @@ -12,6 +12,8 @@ SWIGINTERNINLINE PyObject* } } +#ifdef SWIG_PYTHON_LEGACY_BOOL +// Default prior to SWIG 3.0.0 %fragment(SWIG_AsVal_frag(bool),"header", fragment=SWIG_AsVal_frag(long)) { SWIGINTERN int @@ -24,6 +26,23 @@ SWIG_AsVal_dec(bool)(PyObject *obj, bool *val) return SWIG_OK; } } +#else +%fragment(SWIG_AsVal_frag(bool),"header", + fragment=SWIG_AsVal_frag(long)) { +SWIGINTERN int +SWIG_AsVal_dec(bool)(PyObject *obj, bool *val) +{ + int r; + if (!PyBool_Check(obj)) + return SWIG_ERROR; + r = PyObject_IsTrue(obj); + if (r == -1) + return SWIG_ERROR; + if (val) *val = r ? true : false; + return SWIG_OK; +} +} +#endif /* int */ diff --git a/Lib/python/pytypemaps.swg b/Lib/python/pytypemaps.swg index 5c6abb01e..2341980f2 100644 --- a/Lib/python/pytypemaps.swg +++ b/Lib/python/pytypemaps.swg @@ -5,9 +5,11 @@ /* ------------------------------------------------------------ * Fragment section * ------------------------------------------------------------ */ -/* bool is dangerous in Python, change precedence */ +#ifdef SWIG_PYTHON_LEGACY_BOOL +// Default prior to SWIG 3.0.0 #undef SWIG_TYPECHECK_BOOL %define SWIG_TYPECHECK_BOOL 10000 %enddef +#endif /* Include fundamental fragment definitions */ %include From ddbf439db9e65ec4243fa71f1c036bd7d56f1624 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Wed, 12 Mar 2014 18:00:15 +0400 Subject: [PATCH 1070/1160] Working around some of the SWIG internal issues with enums --- Examples/test-suite/lua/nspace_runme.lua | 8 ++++++-- Examples/test-suite/nspace.i | 2 ++ Source/Modules/lua.cxx | 11 +++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/lua/nspace_runme.lua b/Examples/test-suite/lua/nspace_runme.lua index 049d4ff00..21f88e2af 100644 --- a/Examples/test-suite/lua/nspace_runme.lua +++ b/Examples/test-suite/lua/nspace_runme.lua @@ -70,6 +70,10 @@ assert(ns.Outer.Inner1.Color_colorStaticMethod == nil) -- Enums and static methods of class marked as %nonspace should have backward compatible name assert(ns.NoNSpacePlease_noNspaceStaticFunc() == 10) --- assert(ns.NoNSpacePlease_NoNspace1 == 1) --- assert(ns.NoNSpacePlease.NoNspace2 == 10) +assert(ns.Outer.Inner2.NoNSpacePlease_NoNspace == nil) +-- ReallyNoNSpaceEnum is wrapped into %nonspace and thus handled correctly. +-- NoNSpaceEnum is not (although both of them are in %nonspace-wrapped class) and thus +-- handled rather unexpectedly +assert(ns.NoNSpacePlease_ReallyNoNspace1 == 1) +assert(ns.NoNSpacePlease.ReallyNoNspace2 == 10) diff --git a/Examples/test-suite/nspace.i b/Examples/test-suite/nspace.i index c595322a7..1520b3652 100644 --- a/Examples/test-suite/nspace.i +++ b/Examples/test-suite/nspace.i @@ -10,6 +10,7 @@ SWIG_JAVABODY_PROXY(public, public, SWIGTYPE) %nspace; %nonspace Outer::Inner2::NoNSpacePlease; +%nonspace Outer::Inner2::NoNSpacePlease::ReallyNoNSpaceEnum; %copyctor; %ignore Outer::Inner2::Color::Color(); @@ -70,6 +71,7 @@ namespace Outer { class NoNSpacePlease { public: enum NoNSpaceEnum { NoNspace1 = 1, NoNspace2 = 10 }; + enum ReallyNoNSpaceEnum { ReallyNoNspace1 = 1, ReallyNoNspace2 = 10 }; static int noNspaceStaticFunc() { return 10; } }; } // Inner2 diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index e0fb2c2a0..002c6eb3a 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -1165,9 +1165,20 @@ public: virtual int enumDeclaration(Node *n) { current[STATIC_CONST] = true; current[ENUM_CONST] = true; + // There is some slightly specific behaviour with enums. Basically, + // their NSpace may be tracked separately. The code below tries to work around + // this issue to some degree. + // The idea is the same as in classHandler - to drop old names generation if + // enum is in class in namespace. + const int v2_compat_names_generation_old = v2_compat_names_generation; + if (getNSpace() || + ( Getattr(n, "sym:nspace") != 0 && Len(Getattr(n, "sym:nspace")) > 0 ) ) { + v2_compat_names_generation = 0; + } int result = Language::enumDeclaration(n); current[STATIC_CONST] = false; current[ENUM_CONST] = false; + v2_compat_names_generation = v2_compat_names_generation_old; return result; } From e18044185e152a5f634ecb146312b20baf7b273e Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Thu, 13 Mar 2014 14:57:17 +0400 Subject: [PATCH 1071/1160] fixes for director class naming when nested classes are used --- Examples/test-suite/common.mk | 1 + .../csharp/nested_directors_runme.cs | 20 +++++++++++ Examples/test-suite/nested_directors.i | 35 +++++++++++++++++++ Source/Modules/csharp.cxx | 20 ----------- Source/Modules/lang.cxx | 10 +++--- Source/Swig/cwrap.c | 26 +++----------- Source/Swig/swig.h | 2 +- 7 files changed, 67 insertions(+), 47 deletions(-) create mode 100644 Examples/test-suite/csharp/nested_directors_runme.cs create mode 100644 Examples/test-suite/nested_directors.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 4466558fb..f2a2242b7 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -284,6 +284,7 @@ CPP_TEST_CASES += \ naturalvar_more \ naturalvar_onoff \ nested_class \ + nested_directors \ nested_comment \ nested_scope \ nested_workaround \ diff --git a/Examples/test-suite/csharp/nested_directors_runme.cs b/Examples/test-suite/csharp/nested_directors_runme.cs new file mode 100644 index 000000000..32a8df953 --- /dev/null +++ b/Examples/test-suite/csharp/nested_directors_runme.cs @@ -0,0 +1,20 @@ +using System; +using nested_directorsNamespace; +#pragma warning disable 219 + +public class CNested : Base.Nest { + public override bool GetValue() {return true;} +} +public class CSub : Sub { + protected override bool GetValue() { return base.GetValue(); } + public bool Test(){ return GetValue(); } +} + +public class runme { + static void Main() { + CNested n = new CNested(); + CSub s = new CSub(); + if (!s.Test()) + throw new Exception("Sub.GetValue"); + } +} diff --git a/Examples/test-suite/nested_directors.i b/Examples/test-suite/nested_directors.i new file mode 100644 index 000000000..a25d85d46 --- /dev/null +++ b/Examples/test-suite/nested_directors.i @@ -0,0 +1,35 @@ +%module(directors="1", allprotected="1") nested_directors + +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Base::Nest; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Sub::IListener; + +%feature("director") Base; +%feature("director") Sub; +%feature("director") Base::Nest; + +%inline %{ +namespace NN { +class Base { +public: + virtual ~Base(){} + class Nest { + public: + virtual ~Nest(){} + virtual bool GetValue(){ return false; } + }; +protected: + virtual bool DoNothing() = 0; +}; + +class Sub : public Base { +public: + class IListener { + }; +public: + virtual ~Sub(){} +protected: + void DoSomething(){} + virtual bool GetValue() const { return true; } +}; +} +%} diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 4a105aa16..298056b7b 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -203,26 +203,6 @@ public: return proxyname; } - /* ----------------------------------------------------------------------------- - * directorClassName() - * ----------------------------------------------------------------------------- */ - - String *directorClassName(Node *n) { - String *dirclassname; - const char *attrib = "director:classname"; - - if (!(dirclassname = Getattr(n, attrib))) { - String *classname = getClassPrefix(); - - dirclassname = NewStringf("SwigDirector_%s", classname); - Setattr(n, attrib, dirclassname); - } - else - dirclassname = Copy(dirclassname); - - return dirclassname; - } - /* ------------------------------------------------------------ * main() * ------------------------------------------------------------ */ diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 6873b0875..5ea79f0ab 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2373,6 +2373,7 @@ int Language::classDeclaration(Node *n) { String *oldDirectorClassName = DirectorClassName; String *oldNSpace = NSpace; Node *oldCurrentClass = CurrentClass; + int dir = 0; String *kind = Getattr(n, "kind"); String *name = Getattr(n, "name"); @@ -2424,7 +2425,6 @@ int Language::classDeclaration(Node *n) { /* Call classHandler() here */ if (!ImportMode) { - int dir = 0; if (directorsEnabled()) { int ndir = GetFlag(n, "feature:director"); int nndir = GetFlag(n, "feature:nodirector"); @@ -2481,7 +2481,9 @@ int Language::classDeclaration(Node *n) { ClassPrefix = oldClassPrefix; Delete(ClassName); ClassName = oldClassName; - Delete(DirectorClassName); + if (dir) { + Delete(DirectorClassName); + } DirectorClassName = oldDirectorClassName; return SWIG_OK; } @@ -2749,7 +2751,7 @@ int Language::constructorHandler(Node *n) { Setattr(n, "handled_as_constructor", "1"); } - Swig_ConstructorToFunction(n, NSpace, 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, DirectorClassName); Setattr(n, "sym:name", mrename); functionWrapper(n); Delete(mrename); @@ -2771,7 +2773,7 @@ int Language::copyconstructorHandler(Node *n) { String *director_ctor = get_director_ctor_code(n, director_ctor_code, director_prot_ctor_code, abstracts); - Swig_ConstructorToFunction(n, NSpace, 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, DirectorClassName); Setattr(n, "sym:name", mrename); functionWrapper(n); Delete(mrename); diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 27eef0ef0..ec0acfa77 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -1181,23 +1181,14 @@ Node *Swig_directormap(Node *module, String *type) { * This function creates a C wrapper for a C constructor function. * ----------------------------------------------------------------------------- */ -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; +int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags, String *directorname) { Parm *p; ParmList *directorparms; SwigType *type; - int use_director; - String *directorScope = NewString(nspace); - - Replace(directorScope, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY); - - use_director = Swig_directorclass(n); - - parms = CopyParmList(nonvoid_parms(Getattr(n, "parms"))); - + int use_director = Swig_directorclass(n); + ParmList *parms = CopyParmList(nonvoid_parms(Getattr(n, "parms"))); /* Prepend the list of prefix_args (if any) */ - prefix_args = Getattr(n, "director:prefix_args"); + Parm *prefix_args = Getattr(n, "director:prefix_args"); if (prefix_args != NIL) { Parm *p2, *p3; @@ -1250,18 +1241,11 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String if (use_director) { Node *parent = Swig_methodclass(n); int abstract = Getattr(parent, "abstracts") != 0; - String *name = Getattr(parent, "sym:name"); - String *directorname; String *action = NewStringEmpty(); String *tmp_none_comparison = Copy(none_comparison); String *director_call; String *nodirector_call; - if (Len(directorScope) > 0) - directorname = NewStringf("SwigDirector_%s_%s", directorScope, name); - else - directorname = NewStringf("SwigDirector_%s", name); - Replaceall(tmp_none_comparison, "$arg", "arg1"); director_call = Swig_cppconstructor_director_call(directorname, directorparms); @@ -1300,7 +1284,6 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String Setattr(n, "wrap:action", action); Delete(tmp_none_comparison); Delete(action); - Delete(directorname); } else { String *call = Swig_cppconstructor_call(classname, parms); String *cres = Swig_cresult(type, Swig_cresult_name(), call); @@ -1322,7 +1305,6 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String if (directorparms != parms) Delete(directorparms); Delete(parms); - Delete(directorScope); return SWIG_OK; } diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 95d9189b3..5334a29f0 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -374,7 +374,7 @@ extern int ParmList_is_compactdefargs(ParmList *p); /* --- Transformations --- */ 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_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags, String *directorname); 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); From 348caba6e5d77d72d6f588f65deed9cfb9988a4f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Mar 2014 21:52:38 +0000 Subject: [PATCH 1072/1160] Add note about cplusplusout for nested_struct testcase --- Examples/test-suite/nested_structs.i | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/test-suite/nested_structs.i b/Examples/test-suite/nested_structs.i index 44ff994ba..f4f7a275a 100644 --- a/Examples/test-suite/nested_structs.i +++ b/Examples/test-suite/nested_structs.i @@ -33,6 +33,7 @@ int getInside1Val(struct Outer *n) { return n->inside1.val; } Below was causing problems in Octave as wrappers were compiled as C++. Solution requires regenerating the inner struct into the global C++ namespace (which is where it is intended to be in C). +See cparse_cplusplusout / Swig_cparse_cplusplusout in the Source. */ %inline %{ int nestedByVal(struct Named s); From e186dc13b7a2c31eeea8e4918504ff85b7244765 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 10 Mar 2014 07:07:39 +0000 Subject: [PATCH 1073/1160] C++11 constexpr variables support added --- Doc/Manual/CPlusPlus11.html | 21 ++++++++++---------- Examples/test-suite/cpp11_constexpr.i | 28 ++++++++++++++++++++++++--- Source/CParse/parser.y | 2 +- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index 86a042d78..585a70e63 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -107,7 +107,7 @@ For example, ignore the move constructor:

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

    @@ -120,20 +120,19 @@ example.i:18: Warning 503: Can't wrap 'operator =' unless renamed to a valid ide

    7.2.2 Generalized constant expressions

    -

    SWIG correctly parses the keyword constexpr, but ignores its functionality. Constant functions cannot be used as constants.

    +

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

    -constexpr int myConstFunc() { return 10; }
    -const int a = myConstFunc(); // results in error
    +constexpr int XXX() { return 10; }
    +constexpr int YYY = XXX() + 100;
     
    -

    Users needs to use values or predefined constants when defining the new constant value:

    - -
    -#define MY_CONST 10
    -constexpr int myConstFunc() { return MY_CONST; }
    -const int a = MY_CONST; // ok
    -
    +

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

    7.2.3 Extern template

    diff --git a/Examples/test-suite/cpp11_constexpr.i b/Examples/test-suite/cpp11_constexpr.i index 95fe5fa2b..412b8132a 100644 --- a/Examples/test-suite/cpp11_constexpr.i +++ b/Examples/test-suite/cpp11_constexpr.i @@ -4,9 +4,31 @@ %module cpp11_constexpr %inline %{ -class TestClass { -public: - constexpr int func() { return 10; } +constexpr int AAA = 10; +constexpr const int BBB = 20; +constexpr int CCC() { return 30; } +constexpr const int DDD() { return 40; } + +constexpr int XXX() { return 10; } +constexpr int YYY = XXX() + 100; + +struct ConstExpressions { + static constexpr const int JJJ = 100; + static constexpr int KKK = 200; + static const int LLL = 300; + constexpr int MMM() { return 400; } + constexpr const int NNN() { return 500; } }; %} +%{ +int Array10[AAA]; +int Array20[BBB]; +int Array30[CCC()]; +int Array40[DDD()]; +int Array100[ConstExpressions::JJJ]; +int Array200[ConstExpressions::KKK]; +int Array300[ConstExpressions::LLL]; +//int Array400[ConstExpressions::MMM()]; +//int Array500[ConstExpressions::NNN()]; +%} diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 1bd351560..0ed438e90 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -412,7 +412,7 @@ static void add_symbols(Node *n) { } else { ty = type; } - if (!SwigType_ismutable(ty)) { + if (!SwigType_ismutable(ty) || (storage && Strstr(storage, "constexpr"))) { SetFlag(n,"hasconsttype"); SetFlag(n,"feature:immutable"); } From 3fb973644eaf939ef6100a03d926aafe93a7a7de Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 10 Mar 2014 07:19:16 +0000 Subject: [PATCH 1074/1160] More C++11 doc tweaks --- Doc/Manual/CPlusPlus11.html | 42 +++++++++---------- Examples/test-suite/cpp11_template_explicit.i | 4 ++ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index 585a70e63..4317c189e 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -137,19 +137,14 @@ When either of these is used from a target language, a runtime call is made to o

    7.2.3 Extern template

    -

    SWIG correctly parses the keywords extern template. However, the explicit template instantiation is not used by SWIG, a %template is still required.

    - +

    SWIG correctly parses the keywords extern template. +However, this template instantiation suppression in a translation unit has no relevance for SWIG. +SWIG only uses %template for instantiating and wrapping templates.

    -extern template class std::vector<MyClass>; // explicit instantiation
    -
    -...
    -
    -class MyClass {
    -public:
    -  int a;
    -  int b;
    -};
    +template class std::vector<int>; // C++03 explicit instantiation in C++
    +extern template class std::vector<int>; // C++11 explicit instantiation suppression in C++
    +%template(VectorInt) std::vector<int>; // SWIG instantiation
     

    7.2.4 Initializer lists

    @@ -272,7 +267,7 @@ public:

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

    7.2.11 Null pointer constant

    -

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

    +

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

    7.2.12 Strongly typed enumerations

    @@ -479,7 +474,8 @@ enum class MyEnum : unsigned int;

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

    @@ -521,6 +517,10 @@ class AllColors {
     };
     
    +

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

    +

    7.2.13 Double angle brackets

    @@ -541,22 +541,22 @@ For example:

     class U {
     public:
    -        int u;
    +  int u;
     };
     
     class V {
     public:
    -        int v;
    +  int v;
     };
     
     class TestClass {
     public:
    -        //implicit converting constructor
    -        TestClass(U const &val) { t=val.u; }
    -        // explicit constructor
    -        explicit TestClass(V const &val) { t=val.v; }
    +  //implicit converting constructor
    +  TestClass(U const &val) { t=val.u; }
    +  // explicit constructor
    +  explicit TestClass(V const &val) { t=val.v; }
     
    -        int t;
    +  int t;
     };
     
    diff --git a/Examples/test-suite/cpp11_template_explicit.i b/Examples/test-suite/cpp11_template_explicit.i index 80a30d283..83b16583c 100644 --- a/Examples/test-suite/cpp11_template_explicit.i +++ b/Examples/test-suite/cpp11_template_explicit.i @@ -20,5 +20,9 @@ extern template class std::vector; template class std::vector; extern template class std::vector; + +template class std::vector; +extern template class std::vector; %} +%template(VectorInt) std::vector; From adc3cfeb571f8dd6d072bbab52eebda0bf612656 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 10 Mar 2014 18:55:57 +0000 Subject: [PATCH 1075/1160] More C++11 doc and test improvements --- Doc/Manual/CPlusPlus11.html | 32 ++++++++++++++++--- .../cpp11_inheriting_constructors.i | 11 +++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index 4317c189e..d79c3172e 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -138,13 +138,13 @@ When either of these is used from a target language, a runtime call is made to o

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

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

    7.2.4 Initializer lists

    @@ -400,7 +400,8 @@ auto square(float a, float b) -> decltype(a);

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

    @@ -418,7 +419,13 @@ public:
     

    -Constructor inheritance is parsed correctly, but the additional constructors are not currently added to the derived proxy class in the target language. Example is shown below: +where peer constructors can be called. SWIG handles this without any issue. +

    + +

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

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

      -

      17.1 Basics

      +

      18.1 Basics

      -

      17.1.1 Running SWIG

      +

      18.1.1 Running SWIG

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

      -

      17.1.2 Command Line Options

      +

      18.1.2 Command Line Options

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

      -

      17.1.3 Inserting user code into generated files

      +

      18.1.3 Inserting user code into generated files

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

      -

      17.2 Wrapping Overview

      +

      18.2 Wrapping Overview

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

      -

      17.2.1 Function Wrapping

      +

      18.2.1 Function Wrapping

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

    -

    17.2.2 Foreign Wrappers

    +

    18.2.2 Foreign Wrappers

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

    -

    17.2.3 FFI Wrappers

    +

    18.2.3 FFI Wrappers

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

    -

    17.2.4 Non-overloaded Defuns

    +

    18.2.4 Non-overloaded Defuns

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

    -

    17.2.5 Overloaded Defuns

    +

    18.2.5 Overloaded Defuns

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

    -

    17.2.6 What about constant and variable access?

    +

    18.2.6 What about constant and variable access?

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

    -

    17.2.7 Object Wrapping

    +

    18.2.7 Object Wrapping

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

    -

    17.3 Wrapping Details

    +

    18.3 Wrapping Details

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

    -

    17.3.1 Namespaces

    +

    18.3.1 Namespaces

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

    -

    17.3.2 Constants

    +

    18.3.2 Constants

    @@ -803,7 +803,7 @@ namespace car { not use the -nocwrap command-line option.

    -

    17.3.3 Variables

    +

    18.3.3 Variables

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

    17.3.4 Enumerations

    +

    18.3.4 Enumerations

    @@ -957,7 +957,7 @@ EXPORT const int ACL_ENUM___FOO3__SWIG_0 = FOO3; -

    17.3.5 Arrays

    +

    18.3.5 Arrays

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

    17.3.6 Classes and Structs and Unions (oh my!)

    +

    18.3.6 Classes and Structs and Unions (oh my!)

    -

    17.3.6.1 CLOS wrapping of

    +

    18.3.6.1 CLOS wrapping of

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

    -

    17.3.6.2 CLOS Inheritance

    +

    18.3.6.2 CLOS Inheritance

    @@ -1136,7 +1136,7 @@ namespace BAR { parameter.

    -

    17.3.6.3 Member fields and functions

    +

    18.3.6.3 Member fields and functions

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

    -

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

    +

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

    @@ -1170,11 +1170,11 @@ namespace BAR { use the more robust wrapper functions.

    -

    17.3.7 Templates

    +

    18.3.7 Templates

    -

    17.3.7.1 Generating wrapper code for templates

    +

    18.3.7.1 Generating wrapper code for templates

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

    -

    17.3.7.2 Implicit Template instantiation

    +

    18.3.7.2 Implicit Template instantiation

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

    -

    17.3.8 Typedef, Templates, and Synonym Types

    +

    18.3.8 Typedef, Templates, and Synonym Types

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

    17.3.8.1 Choosing a primary type

    +

    18.3.8.1 Choosing a primary type

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

  • -

    17.3.9 Function overloading/Parameter defaulting

    +

    18.3.9 Function overloading/Parameter defaulting

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

    17.3.10 Operator wrapping and Operator overloading

    +

    18.3.10 Operator wrapping and Operator overloading

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

    17.3.11 Varargs

    +

    18.3.11 Varargs

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

    -

    17.3.12 C++ Exceptions

    +

    18.3.12 C++ Exceptions

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

    -

    17.3.13 Pass by value, pass by reference

    +

    18.3.13 Pass by value, pass by reference

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

    -

    17.4 Typemaps

    +

    18.4 Typemaps

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

    -

    17.4.1 Code Generation in the C++ Wrapper

    +

    18.4.1 Code Generation in the C++ Wrapper

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

    17.4.1.1 IN Typemap

    +

    18.4.1.1 IN Typemap

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

    17.4.1.2 OUT Typemap

    +

    18.4.1.2 OUT Typemap

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

    17.4.1.3 CTYPE Typemap

    +

    18.4.1.3 CTYPE Typemap

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

    -

    17.4.2 Code generation in Lisp wrappers

    +

    18.4.2 Code generation in Lisp wrappers

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

    -

    17.4.2.1 LIN Typemap

    +

    18.4.2.1 LIN Typemap

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

    17.4.2.2 LOUT Typemap

    +

    18.4.2.2 LOUT Typemap

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

    17.4.2.3 FFITYPE Typemap

    +

    18.4.2.3 FFITYPE Typemap

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

    17.4.2.4 LISPTYPE Typemap

    +

    18.4.2.4 LISPTYPE Typemap

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

    17.4.2.5 LISPCLASS Typemap

    +

    18.4.2.5 LISPCLASS Typemap

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

    17.4.3 Modifying SWIG behavior using typemaps

    +

    18.4.3 Modifying SWIG behavior using typemaps

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

    17.5 Identifier Converter functions

    +

    18.5 Identifier Converter functions

    -

    17.5.1 Creating symbols in the lisp environment

    +

    18.5.1 Creating symbols in the lisp environment

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

    -

    17.5.2 Existing identifier-converter functions

    +

    18.5.2 Existing identifier-converter functions

    Two basic identifier routines have been defined. -

    17.5.2.1 identifier-convert-null

    +

    18.5.2.1 identifier-convert-null

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

    -

    17.5.2.2 identifier-convert-lispify

    +

    18.5.2.2 identifier-convert-lispify

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

    -

    17.5.2.3 Default identifier to symbol conversions

    +

    18.5.2.3 Default identifier to symbol conversions

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

    -

    17.5.3 Defining your own identifier-converter

    +

    18.5.3 Defining your own identifier-converter

    @@ -2128,7 +2128,7 @@ indicating the number of arguments passed to the routine indicated by this identifier.

    -

    17.5.4 Instructing SWIG to use a particular identifier-converter

    +

    18.5.4 Instructing SWIG to use a particular identifier-converter

    diff --git a/Doc/Manual/Android.html b/Doc/Manual/Android.html index e02271169..e62139797 100644 --- a/Doc/Manual/Android.html +++ b/Doc/Manual/Android.html @@ -5,7 +5,7 @@ -

    18 SWIG and Android

    +

    19 SWIG and Android

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

      18.1 Overview

      +

      19.1 Overview

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

      -

      18.2 Android examples

      +

      19.2 Android examples

      -

      18.2.1 Examples introduction

      +

      19.2.1 Examples introduction

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

      -

      18.2.2 Simple C example

      +

      19.2.2 Simple C example

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

      Android screenshot of SwigSimple example
      -

      18.2.3 C++ class example

      +

      19.2.3 C++ class example

      @@ -746,7 +746,7 @@ Run the app to see the result of calling the C++ code from Java:

      Android screenshot of SwigClass example
      -

      18.2.4 Other examples

      +

      19.2.4 Other examples

      @@ -758,7 +758,7 @@ Note that the 'extend' example is demonstrates the directors feature. Normally C++ exception handling and the STL is not available by default in the version of g++ shipped with Android, but this example turns these features on as described in the next section.

      -

      18.3 C++ STL

      +

      19.3 C++ STL

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

      9 Argument Handling

      +

      10 Argument Handling

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

        -

        9.1 The typemaps.i library

        +

        10.1 The typemaps.i library

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

        -

        9.1.1 Introduction

        +

        10.1.1 Introduction

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

      -

      9.1.2 Input parameters

      +

      10.1.2 Input parameters

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

    -

    9.1.3 Output parameters

    +

    10.1.3 Output parameters

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

    9.1.4 Input/Output parameters

    +

    10.1.4 Input/Output parameters

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

    -

    9.1.5 Using different names

    +

    10.1.5 Using different names

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

    -

    9.2 Applying constraints to input values

    +

    10.2 Applying constraints to input values

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

    -

    9.2.1 Simple constraint example

    +

    10.2.1 Simple constraint example

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

    -

    9.2.2 Constraint methods

    +

    10.2.2 Constraint methods

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

    9.2.3 Applying constraints to new datatypes

    +

    10.2.3 Applying constraints to new datatypes

    diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index ed2edd630..ce9174254 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -23,6 +23,7 @@

  • Lambda functions and expressions
  • Alternate function syntax
  • Object construction improvement +
  • Explicit overrides and final
  • Null pointer constant
  • Strongly typed enumerations
  • Double angle brackets @@ -36,13 +37,16 @@
  • Explicitly defaulted functions and deleted functions
  • Type long long int
  • Static assertions -
  • Allow sizeof to work on members of classes without an explicit object +
  • Allow sizeof to work on members of classes without an explicit object
  • Exception specifications and noexcept +
  • Control and query object alignment +
  • Attributes
  • Standard library changes
    • Threading facilities -
    • Tuple types and hash tables +
    • Tuple types +
    • Hash tables
    • Regular expressions
    • General-purpose smart pointers
    • Extensible random number facility @@ -86,7 +90,7 @@ for example the typical usage of it in the move constructor and move assignment
       class MyClass {
       ...
      -  std::vector numbers;
      +  std::vector<int> numbers;
       public:
         MyClass(MyClass &&other) : numbers(std::move(other.numbers)) {}
         MyClass & operator=(MyClass &&other) {
      @@ -459,7 +463,8 @@ public:
       };
       
      -

      Explicit overrides and final

      +

      7.2.11 Explicit overrides and final

      +

      The special identifiers final and override can be used on methods and destructors, @@ -482,12 +487,12 @@ struct DerivedStruct : BaseStruct { -

      7.2.11 Null pointer constant

      +

      7.2.12 Null pointer constant

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

      -

      7.2.12 Strongly typed enumerations

      +

      7.2.13 Strongly typed enumerations

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

      @@ -543,7 +548,7 @@ class AllColors { Expect to see this improved in a future version of SWIG.

      -

      7.2.13 Double angle brackets

      +

      7.2.14 Double angle brackets

      SWIG correctly parses the symbols >> as closing the @@ -554,7 +559,7 @@ shift operator >> otherwise.

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

      7.2.14 Explicit conversion operators

      +

      7.2.15 Explicit conversion operators

      SWIG correctly parses the keyword explicit for operators in addition to constructors now. @@ -597,7 +602,7 @@ Conversion operators either with or without explicit need renaming to a them available as a normal proxy method.

      -

      7.2.15 Alias templates

      +

      7.2.16 Alias templates

      @@ -650,7 +655,7 @@ example.i:17: Warning 341: The 'using' keyword in type aliasing is not fully sup typedef void (*PFD)(double); // The old style -

      7.2.16 Unrestricted unions

      +

      7.2.17 Unrestricted unions

      SWIG fully supports any type inside a union even if it does not @@ -676,7 +681,7 @@ union P { } p1; -

      7.2.17 Variadic templates

      +

      7.2.18 Variadic templates

      SWIG supports the variadic templates syntax (inside the <> @@ -711,7 +716,7 @@ const int SIZE = sizeof...(ClassName<int, int>); In the above example SIZE is of course wrapped as a constant.

      -

      7.2.18 New string literals

      +

      7.2.19 New string literals

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

      @@ -741,7 +746,7 @@ Note: There is a bug currently where SWIG's preprocessor incorrectly parses an o inside raw string literals.

      -

      7.2.19 User-defined literals

      +

      7.2.20 User-defined literals

      @@ -808,7 +813,7 @@ OutputType var2 = 1234_suffix; OutputType var3 = 3.1416_suffix; -

      7.2.20 Thread-local storage

      +

      7.2.21 Thread-local storage

      SWIG correctly parses the thread_local keyword. For example, variables @@ -828,7 +833,7 @@ A variable will be thread local if accessed from different threads from the targ same way that it will be thread local if accessed from C++ code.

      -

      7.2.21 Explicitly defaulted functions and deleted functions

      +

      7.2.22 Explicitly defaulted functions and deleted functions

      SWIG handles explicitly defaulted functions, that is, = default added to a function declaration. Deleted definitions, which are also called deleted functions, have = delete added to the function declaration. @@ -866,12 +871,12 @@ This is a C++ compile time check and SWIG does not make any attempt to detect if so in this case it is entirely possible to pass an int instead of a double to f from Java, Python etc.

      -

      7.2.22 Type long long int

      +

      7.2.23 Type long long int

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

      -

      7.2.23 Static assertions

      +

      7.2.24 Static assertions

      @@ -886,7 +891,7 @@ struct Check { }; -

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

      +

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

      @@ -907,7 +912,7 @@ const int SIZE = sizeof(A::member); // does not work with C++03. Okay with C++11 8 -

      7.2.25 Exception specifications and noexcept

      +

      7.2.26 Exception specifications and noexcept

      @@ -923,7 +928,8 @@ int noex2(int) noexcept(true); int noex3(int, bool) noexcept(false); -

      Control and query object alignment

      +

      7.2.27 Control and query object alignment

      +

      An alignof operator is used mostly within C++ to return alignment in number of bytes, but could be used to initialize a variable as shown below. @@ -954,7 +960,8 @@ Use the preprocessor to work around this for now: -

      Attributes

      +

      7.2.28 Attributes

      +

      Attributes such as those shown below, are not yet supported and will give a syntax error. @@ -979,26 +986,28 @@ SWIG target languages offer their own threading facilities so there is limited u

      7.3.2 Tuple types

      +

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

      -

      7.3.2 Hash tables

      +

      7.3.3 Hash tables

      +

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

      -

      7.3.3 Regular expressions

      +

      7.3.4 Regular expressions

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

      -

      7.3.4 General-purpose smart pointers

      +

      7.3.5 General-purpose smart pointers

      @@ -1007,12 +1016,12 @@ Please see the shared_ptr smart po There is no special smart pointer handling available for std::weak_ptr and std::unique_ptr yet.

      -

      7.3.5 Extensible random number facility

      +

      7.3.6 Extensible random number facility

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

      -

      7.3.6 Wrapper reference

      +

      7.3.7 Wrapper reference

      @@ -1023,7 +1032,7 @@ Users would need to write their own typemaps if wrapper references are being use

      -

      7.3.7 Polymorphous wrappers for function objects

      +

      7.3.8 Polymorphous wrappers for function objects

      @@ -1054,7 +1063,7 @@ t = Test() b = t(1,2) # invoke C++ function object -

      7.3.8 Type traits for metaprogramming

      +

      7.3.9 Type traits for metaprogramming

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

      @@ -1104,7 +1113,7 @@ Then the appropriate algorithm can be called for the subset of types given by th 2 -

      7.3.9 Uniform method for computing return type of function objects

      +

      7.3.10 Uniform method for computing return type of function objects

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

      19 SWIG and C#

      +

      20 SWIG and C#

        @@ -52,7 +52,7 @@ -

        19.1 Introduction

        +

        20.1 Introduction

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

        -

        19.1.1 SWIG 2 Compatibility

        +

        20.1.1 SWIG 2 Compatibility

        +

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

        -

        19.2 Differences to the Java module

        +

        20.2 Differences to the Java module

        @@ -491,7 +492,7 @@ Windows users can also get the examples working using a Cygwin or MinGW environment for automatic configuration of the example makefiles. Any one of the three C# compilers (Portable.NET, Mono or Microsoft) can be detected from within a Cygwin or Mingw environment if installed in your path. -

        19.3 Void pointers

        +

        20.3 Void pointers

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

      -

      19.4 C# Arrays

      +

      20.4 C# Arrays

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

      -

      19.4.1 The SWIG C arrays library

      +

      20.4.1 The SWIG C arrays library

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

      19.4.2 Managed arrays using P/Invoke default array marshalling

      +

      20.4.2 Managed arrays using P/Invoke default array marshalling

      @@ -685,7 +686,7 @@ and intermediary class method -

      19.4.3 Managed arrays using pinning

      +

      20.4.3 Managed arrays using pinning

      @@ -780,7 +781,7 @@ public static extern void myArrayCopy(global::System.IntPtr jarg1, global::Syste -

      19.5 C# Exceptions

      +

      20.5 C# Exceptions

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

      -

      19.5.1 C# exception example using "check" typemap

      +

      20.5.1 C# exception example using "check" typemap

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

      -

      19.5.2 C# exception example using %exception

      +

      20.5.2 C# exception example using %exception

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

      19.5.3 C# exception example using exception specifications

      +

      20.5.3 C# exception example using exception specifications

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

      -

      19.5.4 Custom C# ApplicationException example

      +

      20.5.4 Custom C# ApplicationException example

      @@ -1315,7 +1316,7 @@ try { -

      19.6 C# Directors

      +

      20.6 C# Directors

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

      -

      19.6.1 Directors example

      +

      20.6.1 Directors example

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

      19.6.2 Directors implementation

      +

      20.6.2 Directors implementation

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

      19.6.3 Director caveats

      +

      20.6.3 Director caveats

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

      -

      19.7 Multiples modules

      +

      20.7 Multiples modules

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

      -

      19.8 C# Typemap examples

      +

      20.8 C# Typemap examples

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

      19.8.1 Memory management when returning references to member variables

      +

      20.8.1 Memory management when returning references to member variables

      @@ -1847,7 +1848,7 @@ public class Bike : global::System.IDisposable { Note the addReference call.

      -

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

      +

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

      @@ -1966,7 +1967,7 @@ The 'cscode' typemap simply adds in the specified code into the C# proxy class. -

      19.8.3 Date marshalling using the csin typemap and associated attributes

      +

      20.8.3 Date marshalling using the csin typemap and associated attributes

      @@ -2252,7 +2253,7 @@ public class example { -

      19.8.4 A date example demonstrating marshalling of C# properties

      +

      20.8.4 A date example demonstrating marshalling of C# properties

      @@ -2352,7 +2353,7 @@ Some points to note:

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

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

    +

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

    @@ -2414,7 +2415,7 @@ Pay special attention to the memory management issues, using these attributes.

    -

    19.8.6 Turning wrapped classes into partial classes

    +

    20.8.6 Turning wrapped classes into partial classes

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

    -

    19.8.7 Extending proxy classes with additional C# code

    +

    20.8.7 Extending proxy classes with additional C# code

    @@ -2553,7 +2554,7 @@ public class ExtendMe : global::System.IDisposable { -

    19.8.8 Underlying type for enums

    +

    20.8.8 Underlying type for enums

    diff --git a/Doc/Manual/Chicken.html b/Doc/Manual/Chicken.html index 4e43b9b90..82861c31c 100644 --- a/Doc/Manual/Chicken.html +++ b/Doc/Manual/Chicken.html @@ -8,7 +8,7 @@ -

    20 SWIG and Chicken

    +

    21 SWIG and Chicken

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

      -

      20.1 Preliminaries

      +

      21.1 Preliminaries

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

      -

      20.1.1 Running SWIG in C mode

      +

      21.1.1 Running SWIG in C mode

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

      -

      20.1.2 Running SWIG in C++ mode

      +

      21.1.2 Running SWIG in C++ mode

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

      -

      20.2 Code Generation

      +

      21.2 Code Generation

      -

      20.2.1 Naming Conventions

      +

      21.2.1 Naming Conventions

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

      -

      20.2.2 Modules

      +

      21.2.2 Modules

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

      -

      20.2.3 Constants and Variables

      +

      21.2.3 Constants and Variables

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

      -

      20.2.4 Functions

      +

      21.2.4 Functions

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

      -

      20.2.5 Exceptions

      +

      21.2.5 Exceptions

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

    -

    20.3 TinyCLOS

    +

    21.3 TinyCLOS

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

    -

    20.4 Linkage

    +

    21.4 Linkage

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

    -

    20.4.1 Static binary or shared library linked at compile time

    +

    21.4.1 Static binary or shared library linked at compile time

    We can easily use csc to build a static binary.

    @@ -395,7 +395,7 @@ in which case the test script does not need to be linked with example.so. The t be run with csi.

    -

    20.4.2 Building chicken extension libraries

    +

    21.4.2 Building chicken extension libraries

    Building a shared library like in the above section only works if the library @@ -453,7 +453,7 @@ distributed and used by anyone, even if SWIG is not installed.

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

    -

    20.4.3 Linking multiple SWIG modules with TinyCLOS

    +

    21.4.3 Linking multiple SWIG modules with TinyCLOS

    Linking together multiple modules that share type information using the %import @@ -477,7 +477,7 @@ with (declare (uses ...)). To create an extension library or an egg, just create a module_load.scm file that (declare (uses ...)) all the modules.

    -

    20.5 Typemaps

    +

    21.5 Typemaps

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

    Lib/chicken/chicken.swg.

    -

    20.6 Pointers

    +

    21.6 Pointers

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

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

    -

    20.6.1 Garbage collection

    +

    21.6.1 Garbage collection

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

    must be called manually.

    -

    20.7 Unsupported features and known problems

    +

    21.7 Unsupported features and known problems

    -

    20.7.1 TinyCLOS problems with Chicken version <= 1.92

    +

    21.7.1 TinyCLOS problems with Chicken version <= 1.92

    In Chicken versions equal to or below 1.92, TinyCLOS has a limitation such that generic methods do not properly work on methods diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 77280c8bc..de64429cb 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -262,7 +262,61 @@ -

    7 Preprocessing

    +

    7 SWIG and C++11

    + + + + + +

    8 Preprocessing

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

    8 SWIG library

    +

    9 SWIG library

    @@ -311,6 +365,7 @@
  • std::vector
  • STL exceptions
  • shared_ptr smart pointer +
  • auto_ptr smart pointer
  • Utility Libraries
  • Accessing protected members
  • Common customization features @@ -987,7 +1046,7 @@ -

    25 SWIG and Common Lisp

    +

    26 SWIG and Common Lisp

    @@ -1010,7 +1069,7 @@
    -

    26 SWIG and Lua

    +

    27 SWIG and Lua

    @@ -1029,8 +1088,11 @@
  • Functions
  • Global variables
  • Constants and enums +
  • Pointers -
  • Structures +
  • Structures
  • C++ classes
  • C++ inheritance
  • Pointers, references, values, and arrays @@ -1041,17 +1103,26 @@
  • C++ templates
  • C++ Smart Pointers
  • C++ Exceptions +
  • Namespaces + +
  • Compatibility Note +
  • Typemaps -
  • Writing typemaps +
  • Writing typemaps
  • Customization of your Bindings @@ -1069,7 +1140,7 @@ -

    27 SWIG and Modula-3

    +

    28 SWIG and Modula-3

    @@ -1107,7 +1178,7 @@
    -

    28 SWIG and MzScheme/Racket

    +

    29 SWIG and MzScheme/Racket

    @@ -1119,7 +1190,7 @@
    -

    29 SWIG and Ocaml

    +

    30 SWIG and Ocaml

    @@ -1170,7 +1241,7 @@
    -

    30 SWIG and Octave

    +

    31 SWIG and Octave

    @@ -1206,7 +1277,7 @@
    -

    31 SWIG and Perl5

    +

    32 SWIG and Perl5

    @@ -1269,11 +1340,20 @@
  • Modifying the proxy methods
  • Adding additional Perl code +
  • Cross language polymorphism + -

    32 SWIG and PHP

    +

    33 SWIG and PHP

    @@ -1313,7 +1393,7 @@
    -

    33 SWIG and Pike

    +

    34 SWIG and Pike

    @@ -1337,7 +1417,7 @@
    -

    34 SWIG and Python

    +

    35 SWIG and Python

    @@ -1437,6 +1517,12 @@
  • %feature("docstring")
  • Python Packages +
  • Python 3 Support
    • Function annotation @@ -1447,7 +1533,7 @@ -

      35 SWIG and R

      +

      36 SWIG and R

      @@ -1463,7 +1549,7 @@
      -

      36 SWIG and Ruby

      +

      37 SWIG and Ruby

      @@ -1597,7 +1683,7 @@
      -

      37 SWIG and Tcl

      +

      38 SWIG and Tcl

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

      38 Extending SWIG to support new languages

      +

      39 Extending SWIG to support new languages

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

      12 Contracts

      +

      13 Contracts

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

        -

        12.1 The %contract directive

        +

        13.1 The %contract directive

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

      -

      12.2 %contract and classes

      +

      13.2 %contract and classes

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

      -

      12.3 Constant aggregation and %aggregate_check

      +

      13.3 Constant aggregation and %aggregate_check

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

      -

      12.4 Notes

      +

      13.4 Notes

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

      11 Customization Features

      +

      12 Customization Features

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

        -

        11.1 Exception handling with %exception

        +

        12.1 Exception handling with %exception

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

        -

        11.1.1 Handling exceptions in C code

        +

        12.1.1 Handling exceptions in C code

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

        -

        11.1.2 Exception handling with longjmp()

        +

        12.1.2 Exception handling with longjmp()

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

        -

        11.1.3 Handling C++ exceptions

        +

        12.1.3 Handling C++ exceptions

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

      -

      11.1.4 Exception handlers for variables

      +

      12.1.4 Exception handlers for variables

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

      -

      11.1.5 Defining different exception handlers

      +

      12.1.5 Defining different exception handlers

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

      -

      11.1.6 Special variables for %exception

      +

      12.1.6 Special variables for %exception

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

      11.1.7 Using The SWIG exception library

      +

      12.1.7 Using The SWIG exception library

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

      -

      11.2 Object ownership and %newobject

      +

      12.2 Object ownership and %newobject

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

      -

      11.3 Features and the %feature directive

      +

      12.3 Features and the %feature directive

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

      -

      11.3.1 Feature attributes

      +

      12.3.1 Feature attributes

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

      -

      11.3.2 Feature flags

      +

      12.3.2 Feature flags

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

      -

      11.3.3 Clearing features

      +

      12.3.3 Clearing features

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

      11.3.4 Features and default arguments

      +

      12.3.4 Features and default arguments

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

      -

      11.3.5 Feature example

      +

      12.3.5 Feature example

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

      21 SWIG and D

      +

      22 SWIG and D

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

        21.1 Introduction

        +

        22.1 Introduction

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

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

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

        -

        21.2 Command line invocation

        +

        22.2 Command line invocation

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

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

        21.3 Typemaps

        +

        22.3 Typemaps

        -

        21.3.1 C# <-> D name comparison

        +

        22.3.1 C# <-> D name comparison

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

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

      21.3.2 ctype, imtype, dtype

      +

      22.3.2 ctype, imtype, dtype

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

      @@ -120,7 +120,7 @@

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

      -

      21.3.3 in, out, directorin, directorout

      +

      22.3.3 in, out, directorin, directorout

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

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

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

      -

      21.3.4 din, dout, ddirectorin, ddirectorout

      +

      22.3.4 din, dout, ddirectorin, ddirectorout

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

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

      21.3.5 typecheck typemaps

      +

      22.3.5 typecheck typemaps

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

      -

      21.3.6 Code injection typemaps

      +

      22.3.6 Code injection typemaps

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

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

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

      -

      21.3.7 Special variable macros

      +

      22.3.7 Special variable macros

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

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

      21.4 %features

      +

      22.4 %features

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

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

      21.5 Pragmas

      +

      22.5 Pragmas

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

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

      21.6 D Exceptions

      +

      22.6 D Exceptions

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

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

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

      -

      21.7 D Directors

      +

      22.7 D Directors

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

      @@ -383,16 +383,16 @@ struct A {

      -

      21.8 Other features

      +

      22.8 Other features

      -

      21.8.1 Extended namespace support (nspace)

      +

      22.8.1 Extended namespace support (nspace)

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

      -

      21.8.2 Native pointer support

      +

      22.8.2 Native pointer support

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

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

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

      -

      21.8.3 Operator overloading

      +

      22.8.3 Operator overloading

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

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

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

      -

      21.8.4 Running the test-suite

      +

      22.8.4 Running the test-suite

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

      @@ -424,14 +424,14 @@ struct A {

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

      -

      21.9 D Typemap examples

      +

      22.9 D Typemap examples

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

      -

      21.10 Work in progress and planned features

      +

      22.10 Work in progress and planned features

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

      diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index a8c15fe03..5cd89a280 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -6,7 +6,7 @@ -

      38 Extending SWIG to support new languages

      +

      39 Extending SWIG to support new languages

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

        38.1 Introduction

        +

        39.1 Introduction

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

        -

        38.2 Prerequisites

        +

        39.2 Prerequisites

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

        -

        38.3 The Big Picture

        +

        39.3 The Big Picture

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

        -

        38.4 Execution Model

        +

        39.4 Execution Model

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

        -

        38.4.1 Preprocessing

        +

        39.4.1 Preprocessing

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

        -

        38.4.2 Parsing

        +

        39.4.2 Parsing

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

        -

        38.4.3 Parse Trees

        +

        39.4.3 Parse Trees

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

      -

      38.4.4 Attribute namespaces

      +

      39.4.4 Attribute namespaces

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

      -

      38.4.5 Symbol Tables

      +

      39.4.5 Symbol Tables

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

      38.4.6 The %feature directive

      +

      39.4.6 The %feature directive

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

      -

      38.4.7 Code Generation

      +

      39.4.7 Code Generation

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

      -

      38.4.8 SWIG and XML

      +

      39.4.8 SWIG and XML

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

      -

      38.5 Primitive Data Structures

      +

      39.5 Primitive Data Structures

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

      38.5.1 Strings

      +

      39.5.1 Strings

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

      38.5.2 Hashes

      +

      39.5.2 Hashes

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

      38.5.3 Lists

      +

      39.5.3 Lists

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

      38.5.4 Common operations

      +

      39.5.4 Common operations

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

      38.5.5 Iterating over Lists and Hashes

      +

      39.5.5 Iterating over Lists and Hashes

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

      38.5.6 I/O

      +

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

      38.6 Navigating and manipulating parse trees

      +

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

      38.7 Working with attributes

      +

      39.7 Working with attributes

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

      38.8 Type system

      +

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

      -

      38.8.1 String encoding of types

      +

      39.8.1 String encoding of types

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

      -

      38.8.2 Type construction

      +

      39.8.2 Type construction

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

      38.8.3 Type tests

      +

      39.8.3 Type tests

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

      38.8.4 Typedef and inheritance

      +

      39.8.4 Typedef and inheritance

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

      38.8.5 Lvalues

      +

      39.8.5 Lvalues

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

      38.8.6 Output functions

      +

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

      38.9 Parameters

      +

      39.9 Parameters

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

      38.10 Writing a Language Module

      +

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

      -

      38.10.1 Execution model

      +

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

      -

      38.10.2 Starting out

      +

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

      -

      38.10.3 Command line options

      +

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

      -

      38.10.4 Configuration and preprocessing

      +

      39.10.4 Configuration and preprocessing

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

      -

      38.10.5 Entry point to code generation

      +

      39.10.5 Entry point to code generation

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

      38.10.6 Module I/O and wrapper skeleton

      +

      39.10.6 Module I/O and wrapper skeleton

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

      38.10.7 Low-level code generators

      +

      39.10.7 Low-level code generators

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

      -

      38.10.8 Configuration files

      +

      39.10.8 Configuration files

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

      38.10.9 Runtime support

      +

      39.10.9 Runtime support

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

      -

      38.10.10 Standard library files

      +

      39.10.10 Standard library files

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

      -

      38.10.11 User examples

      +

      39.10.11 User examples

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

      -

      38.10.12 Test driven development and the test-suite

      +

      39.10.12 Test driven development and the test-suite

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

      -

      38.10.12.1 Running the test-suite

      +

      39.10.12.1 Running the test-suite

      @@ -3502,7 +3502,7 @@ It can be run in the same way as the other language test-suites, replacing [lang The test cases used and the way it works is described in Examples/test-suite/errors/Makefile.in.

      -

      38.10.13 Documentation

      +

      39.10.13 Documentation

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

    -

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

    +

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

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

    -

    38.10.15 Coding style guidelines

    +

    39.10.15 Coding style guidelines

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

    -

    38.11 Debugging Options

    +

    39.11 Debugging Options

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

    -

    38.12 Guide to parse tree nodes

    +

    39.12 Guide to parse tree nodes

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

    38.13 Further Development Information

    +

    39.13 Further Development Information

    diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 226acaabf..f970b02e8 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -5,7 +5,7 @@ -

    22 SWIG and Go

    +

    23 SWIG and Go

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

      -

      22.1 Overview

      +

      23.1 Overview

      @@ -67,7 +67,7 @@ checking and runtime library are not used with Go. This should be borne in mind when reading the rest of the SWIG documentation.

      -

      22.2 Running SWIG with Go

      +

      23.2 Running SWIG with Go

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

      -

      22.2.1 Additional Commandline Options

      +

      23.2.1 Additional Commandline Options

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

      22.2.2 Go Output Files

      +

      23.2.2 Go Output Files

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

    -

    22.3 A tour of basic C/C++ wrapping

    +

    23.3 A tour of basic C/C++ wrapping

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

    -

    22.3.1 Go Package Name

    +

    23.3.1 Go Package Name

    @@ -246,7 +246,7 @@ directive. You may override this by using SWIG's -package command line option.

    -

    22.3.2 Go Names

    +

    23.3.2 Go Names

    @@ -278,7 +278,7 @@ followed by that name, and the destructor will be named Delete followed by that name.

    -

    22.3.3 Go Constants

    +

    23.3.3 Go Constants

    @@ -286,7 +286,7 @@ C/C++ constants created via #define or the %constant directive become Go constants, declared with a const declaration. -

    22.3.4 Go Enumerations

    +

    23.3.4 Go Enumerations

    @@ -296,7 +296,7 @@ usual). The values of the enumeration will become variables in Go; code should avoid modifying those variables.

    -

    22.3.5 Go Classes

    +

    23.3.5 Go Classes

    @@ -374,7 +374,7 @@ returns a go interface. If the returned pointer can be null, you can check for this by calling the Swigcptr() method.

    -

    22.3.5.1 Go Class Inheritance

    +

    23.3.5.1 Go Class Inheritance

    @@ -386,7 +386,7 @@ Doing the reverse will require an explicit type assertion, which will be checked dynamically.

    -

    22.3.6 Go Templates

    +

    23.3.6 Go Templates

    @@ -394,7 +394,7 @@ In order to use C++ templates in Go, you must tell SWIG to create wrappers for a particular template instantation. To do this, use the %template directive. -

    22.3.7 Go Director Classes

    +

    23.3.7 Go Director Classes

    @@ -437,7 +437,7 @@ method defined in Go. The Go code may of course call other methods on itself, and those methods may be defined either in Go or in C++.

    -

    22.3.8 Default Go primitive type mappings

    +

    23.3.8 Default Go primitive type mappings

    @@ -544,7 +544,7 @@ that typemap, or add new values, to control how C/C++ types are mapped into Go types.

    -

    22.3.9 Output arguments

    +

    23.3.9 Output arguments

    Because of limitations in the way output arguments are processed in swig, @@ -597,7 +597,7 @@ void f(char *output); -

    22.3.10 Adding additional go code

    +

    23.3.10 Adding additional go code

    Often the APIs generated by swig are not very natural in go, especially if diff --git a/Doc/Manual/Guile.html b/Doc/Manual/Guile.html index 17e3a3fab..4c1126c7f 100644 --- a/Doc/Manual/Guile.html +++ b/Doc/Manual/Guile.html @@ -8,7 +8,7 @@ -

    23 SWIG and Guile

    +

    24 SWIG and Guile

      @@ -47,7 +47,7 @@

      This section details guile-specific support in SWIG. -

      23.1 Supported Guile Versions

      +

      24.1 Supported Guile Versions

      @@ -61,7 +61,7 @@ improved performance. This is currently not tested with swig so your mileage may vary. To be safe set environment variable GUILE_AUTO_COMPILE to 0 when using swig generated guile code. -

      23.2 Meaning of "Module"

      +

      24.2 Meaning of "Module"

      @@ -69,7 +69,7 @@ There are three different concepts of "module" involved, defined separately for SWIG, Guile, and Libtool. To avoid horrible confusion, we explicitly prefix the context, e.g., "guile-module". -

      23.3 Old GH Guile API

      +

      24.3 Old GH Guile API

      Guile 1.8 and older could be interfaced using two different api's, the SCM @@ -80,7 +80,7 @@ or the GH API. The GH interface to guile is deprecated. Read more about why in version of SWIG that can still generate guile GH wrapper code is 2.0.9. Please use that version if you really need the GH wrapper code. -

      23.4 Linkage

      +

      24.4 Linkage

      @@ -88,7 +88,7 @@ Guile support is complicated by a lack of user community cohesiveness, which manifests in multiple shared-library usage conventions. A set of policies implementing a usage convention is called a linkage. -

      23.4.1 Simple Linkage

      +

      24.4.1 Simple Linkage

      @@ -193,7 +193,7 @@ placed between the define-module form and the SWIG_init via a preprocessor define to avoid symbol clashes. For this case, however, passive linkage is available. -

      23.4.2 Passive Linkage

      +

      24.4.2 Passive Linkage

      Passive linkage is just like simple linkage, but it generates an @@ -203,7 +203,7 @@ package name (see below).

      You should use passive linkage rather than simple linkage when you are using multiple modules. -

      23.4.3 Native Guile Module Linkage

      +

      24.4.3 Native Guile Module Linkage

      SWIG can also generate wrapper code that does all the Guile module @@ -244,7 +244,7 @@ Newer Guile versions have a shorthand procedure for this:

    -

    23.4.4 Old Auto-Loading Guile Module Linkage

    +

    24.4.4 Old Auto-Loading Guile Module Linkage

    Guile used to support an autoloading facility for object-code @@ -270,7 +270,7 @@ option, SWIG generates an exported module initialization function with an appropriate name. -

    23.4.5 Hobbit4D Linkage

    +

    24.4.5 Hobbit4D Linkage

    @@ -295,7 +295,7 @@ my/lib/libfoo.so.X.Y.Z and friends. This scheme is still very experimental; the (hobbit4d link) conventions are not well understood.

    -

    23.5 Underscore Folding

    +

    24.5 Underscore Folding

    @@ -307,7 +307,7 @@ complained so far. %rename to specify the Guile name of the wrapped functions and variables (see CHANGES). -

    23.6 Typemaps

    +

    24.6 Typemaps

    @@ -399,7 +399,7 @@ constant will appear as a scheme variable. See Features and the %feature directive for info on how to apply the %feature.

    -

    23.7 Representation of pointers as smobs

    +

    24.7 Representation of pointers as smobs

    @@ -420,7 +420,7 @@ representing the expected pointer type. See also If the Scheme object passed was not a SWIG smob representing a compatible pointer, a wrong-type-arg exception is raised. -

    23.7.1 Smobs

    +

    24.7.1 Smobs

    @@ -439,7 +439,7 @@ structure describing this type. If a generated GOOPS module has been loaded, sm the corresponding GOOPS class.

    -

    23.7.2 Garbage Collection

    +

    24.7.2 Garbage Collection

    Garbage collection is a feature of Guile since version 1.6. As SWIG now requires Guile > 1.8, @@ -453,7 +453,7 @@ is exactly like described in 23.8 Exception Handling +

    24.8 Exception Handling

    @@ -479,7 +479,7 @@ mapping: The default when not specified here is to use "swig-error". See Lib/exception.i for details. -

    23.9 Procedure documentation

    +

    24.9 Procedure documentation

    If invoked with the command-line option -procdoc @@ -514,7 +514,7 @@ like this: typemap argument doc. See Lib/guile/typemaps.i for details. -

    23.10 Procedures with setters

    +

    24.10 Procedures with setters

    For global variables, SWIG creates a single wrapper procedure @@ -542,7 +542,7 @@ struct members, the procedures (struct-member-get pointer) and (struct-member-set pointer value) are not generated. -

    23.11 GOOPS Proxy Classes

    +

    24.11 GOOPS Proxy Classes

    SWIG can also generate classes and generic functions for use with @@ -688,7 +688,7 @@ Notice that <Foo> is used before it is defined. The fix is to just put th %import "foo.h" before the %inline block.

    -

    23.11.1 Naming Issues

    +

    24.11.1 Naming Issues

    As you can see in the example above, there are potential naming conflicts. The default exported @@ -725,7 +725,7 @@ guile-modules. For example,

    (use-modules ((Test) #:renamer (symbol-prefix-proc 'goops:))) -

    23.11.2 Linking

    +

    24.11.2 Linking

    The guile-modules generated above all need to be linked together. GOOPS support requires diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 3144341e1..fb8e5d694 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -5,7 +5,7 @@ -

    24 SWIG and Java

    +

    25 SWIG and Java

  • Accessing protected members
  • Common customization features @@ -157,7 +157,7 @@ It covers most SWIG features, but certain low-level details are covered in less

    -

    24.1 Overview

    +

    25.1 Overview

    @@ -192,7 +192,7 @@ Various customisation tips and techniques using SWIG directives are covered. The latter sections cover the advanced techniques of using typemaps for complete control of the wrapping process.

    -

    24.2 Preliminaries

    +

    25.2 Preliminaries

    @@ -212,7 +212,7 @@ This is the commonly used method to load JNI code so your system will more than Android uses Java JNI and also works with SWIG. Please read the Android chapter in conjunction with this one if you are targeting Android.

    -

    24.2.1 Running SWIG

    +

    25.2.1 Running SWIG

    @@ -271,7 +271,7 @@ The following sections have further practical examples and details on how you mi compiling and using the generated files.

    -

    24.2.2 Additional Commandline Options

    +

    25.2.2 Additional Commandline Options

    @@ -308,7 +308,7 @@ swig -java -help Their use will become clearer by the time you have finished reading this section on SWIG and Java.

    -

    24.2.3 Getting the right header files

    +

    25.2.3 Getting the right header files

    @@ -323,7 +323,7 @@ They are usually in directories like this:

    The exact location may vary on your machine, but the above locations are typical.

    -

    24.2.4 Compiling a dynamic module

    +

    25.2.4 Compiling a dynamic module

    @@ -360,7 +360,7 @@ The name of the shared library output file is important. If the name of your SWIG module is "example", the name of the corresponding shared library file should be "libexample.so" (or equivalent depending on your machine, see Dynamic linking problems for more information). The name of the module is specified using the %module directive or -module command line option.

    -

    24.2.5 Using your module

    +

    25.2.5 Using your module

    @@ -395,7 +395,7 @@ $ If it doesn't work have a look at the following section which discusses problems loading the shared library.

    -

    24.2.6 Dynamic linking problems

    +

    25.2.6 Dynamic linking problems

    @@ -482,7 +482,7 @@ The following section also contains some C++ specific linking problems and solut

    -

    24.2.7 Compilation problems and compiling with C++

    +

    25.2.7 Compilation problems and compiling with C++

    @@ -534,7 +534,7 @@ Finally make sure the version of JDK header files matches the version of Java th

    -

    24.2.8 Building on Windows

    +

    25.2.8 Building on Windows

    @@ -543,7 +543,7 @@ You will want to produce a DLL that can be loaded by the Java Virtual Machine. This section covers the process of using SWIG with Microsoft Visual C++ 6 although the procedure may be similar with other compilers. In order for everything to work, you will need to have a JDK installed on your machine in order to read the JNI header files.

    -

    24.2.8.1 Running SWIG from Visual Studio

    +

    25.2.8.1 Running SWIG from Visual Studio

    @@ -582,7 +582,7 @@ To run the native code in the DLL (example.dll), make sure that it is in your pa If the library fails to load have a look at Dynamic linking problems.

    -

    24.2.8.2 Using NMAKE

    +

    25.2.8.2 Using NMAKE

    @@ -641,7 +641,7 @@ Of course you may want to make changes for it to work for C++ by adding in the -

    -

    24.3 A tour of basic C/C++ wrapping

    +

    25.3 A tour of basic C/C++ wrapping

    @@ -651,7 +651,7 @@ variables are wrapped with JavaBean type getters and setters and so forth. This section briefly covers the essential aspects of this wrapping.

    -

    24.3.1 Modules, packages and generated Java classes

    +

    25.3.1 Modules, packages and generated Java classes

    @@ -687,7 +687,7 @@ swig -java -package com.bloggs.swig -outdir com/bloggs/swig example.i SWIG won't create the directory, so make sure it exists beforehand.

    -

    24.3.2 Functions

    +

    25.3.2 Functions

    @@ -721,7 +721,7 @@ System.out.println(example.fact(4)); -

    24.3.3 Global variables

    +

    25.3.3 Global variables

    @@ -808,7 +808,7 @@ extern char *path; // Read-only (due to %immutable) -

    24.3.4 Constants

    +

    25.3.4 Constants

    @@ -948,7 +948,7 @@ Or if you decide this practice isn't so bad and your own class implements ex

    -

    24.3.5 Enumerations

    +

    25.3.5 Enumerations

    @@ -962,7 +962,7 @@ The final two approaches use simple integers for each enum item. Before looking at the various approaches for wrapping named C/C++ enums, anonymous enums are considered.

    -

    24.3.5.1 Anonymous enums

    +

    25.3.5.1 Anonymous enums

    @@ -1025,7 +1025,7 @@ As in the case of constants, you can access them through either the module class

    -

    24.3.5.2 Typesafe enums

    +

    25.3.5.2 Typesafe enums

    @@ -1119,7 +1119,7 @@ When upgrading to JDK 1.5 or later, proper Java enums could be used instead, wit The following section details proper Java enum generation.

    -

    24.3.5.3 Proper Java enums

    +

    25.3.5.3 Proper Java enums

    @@ -1172,7 +1172,7 @@ The additional support methods need not be generated if none of the enum items h Simpler Java enums for enums without initializers section.

    -

    24.3.5.4 Type unsafe enums

    +

    25.3.5.4 Type unsafe enums

    @@ -1220,7 +1220,7 @@ Note that unlike typesafe enums, this approach requires users to mostly use diff Thus the upgrade path to proper enums provided in JDK 1.5 is more painful.

    -

    24.3.5.5 Simple enums

    +

    25.3.5.5 Simple enums

    @@ -1239,7 +1239,7 @@ SWIG-1.3.21 and earlier versions wrapped all enums using this approach. The type unsafe approach is preferable to this one and this simple approach is only included for backwards compatibility with these earlier versions of SWIG.

    -

    24.3.6 Pointers

    +

    25.3.6 Pointers

    @@ -1327,7 +1327,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return a NULL pointer if the conversion can't be performed.

    -

    24.3.7 Structures

    +

    25.3.7 Structures

    @@ -1495,7 +1495,7 @@ x.setA(3); // Modify x.a - this is the same as b.f.a -

    24.3.8 C++ classes

    +

    25.3.8 C++ classes

    @@ -1558,7 +1558,7 @@ int bar = Spam.getBar(); -

    24.3.9 C++ inheritance

    +

    25.3.9 C++ inheritance

    @@ -1619,7 +1619,7 @@ Note that Java does not support multiple inheritance so any multiple inheritance A warning is given when multiple inheritance is detected and only the first base class is used.

    -

    24.3.10 Pointers, references, arrays and pass by value

    +

    25.3.10 Pointers, references, arrays and pass by value

    @@ -1674,7 +1674,7 @@ to hold the result and a pointer is returned (Java will release this memory when the returned object's finalizer is run by the garbage collector).

    -

    24.3.10.1 Null pointers

    +

    25.3.10.1 Null pointers

    @@ -1698,7 +1698,7 @@ For spam1 and spam4 above the Java null gets translat The converse also occurs, that is, NULL pointers are translated into null Java objects when returned from a C/C++ function.

    -

    24.3.11 C++ overloaded functions

    +

    25.3.11 C++ overloaded functions

    @@ -1813,7 +1813,7 @@ void spam(unsigned short); // Ignored -

    24.3.12 C++ default arguments

    +

    25.3.12 C++ default arguments

    @@ -1856,7 +1856,7 @@ Further details on default arguments and how to restore this approach are given

    -

    24.3.13 C++ namespaces

    +

    25.3.13 C++ namespaces

    @@ -1946,7 +1946,7 @@ If the resulting use of the nspace feature and hence packages results in a proxy you will need to open up the visibility for the pointer constructor and getCPtr method from the default 'protected' to 'public' with the SWIG_JAVABODY_PROXY macro. See Java code typemaps.

    -

    24.3.14 C++ templates

    +

    25.3.14 C++ templates

    @@ -1995,7 +1995,7 @@ Obviously, there is more to template wrapping than shown in this example. More details can be found in the SWIG and C++ chapter.

    -

    24.3.15 C++ Smart Pointers

    +

    25.3.15 C++ Smart Pointers

    @@ -2079,7 +2079,7 @@ Foo f = p.__deref__(); // Returns underlying Foo * -

    24.4 Further details on the generated Java classes

    +

    25.4 Further details on the generated Java classes

    @@ -2094,7 +2094,7 @@ Finally enum classes are covered. First, the crucial intermediary JNI class is considered.

    -

    24.4.1 The intermediary JNI class

    +

    25.4.1 The intermediary JNI class

    @@ -2214,7 +2214,7 @@ If name is the same as modulename then the module class name g from modulename to modulenameModule.

    -

    24.4.1.1 The intermediary JNI class pragmas

    +

    25.4.1.1 The intermediary JNI class pragmas

    @@ -2296,7 +2296,7 @@ For example, let's change the intermediary JNI class access to just the default All the methods in the intermediary JNI class will then not be callable outside of the package as the method modifiers have been changed from public access to default access. This is useful if you want to prevent users calling these low level functions.

    -

    24.4.2 The Java module class

    +

    25.4.2 The Java module class

    @@ -2327,7 +2327,7 @@ example.egg(new Foo()); The primary reason for having the module class wrapping the calls in the intermediary JNI class is to implement static type checking. In this case only a Foo can be passed to the egg function, whereas any long can be passed to the egg function in the intermediary JNI class.

    -

    24.4.2.1 The Java module class pragmas

    +

    25.4.2.1 The Java module class pragmas

    @@ -2378,7 +2378,7 @@ See The intermediary JNI class pragmas secti

    -

    24.4.3 Java proxy classes

    +

    25.4.3 Java proxy classes

    @@ -2454,7 +2454,7 @@ int y = f.spam(5, new Foo()); -

    24.4.3.1 Memory management

    +

    25.4.3.1 Memory management

    @@ -2616,7 +2616,7 @@ and

    -

    24.4.3.2 Inheritance

    +

    25.4.3.2 Inheritance

    @@ -2732,7 +2732,7 @@ However, true cross language polymorphism can be achieved using the 24.4.3.3 Proxy classes and garbage collection +

    25.4.3.3 Proxy classes and garbage collection

    @@ -2815,7 +2815,7 @@ The section on Java typemaps details how to specify See the How to Handle Java Finalization's Memory-Retention Issues article for alternative approaches to managing memory by avoiding finalizers altogether.

    -

    24.4.3.4 The premature garbage collection prevention parameter for proxy class marshalling

    +

    25.4.3.4 The premature garbage collection prevention parameter for proxy class marshalling

    @@ -2937,7 +2937,7 @@ For example: Compatibility note: The generation of this additional parameter did not occur in versions prior to SWIG-1.3.30.

    -

    24.4.3.5 Single threaded applications and thread safety

    +

    25.4.3.5 Single threaded applications and thread safety

    @@ -3025,7 +3025,7 @@ for (int i=0; i<100000; i++) { -

    24.4.4 Type wrapper classes

    +

    25.4.4 Type wrapper classes

    @@ -3112,7 +3112,7 @@ public static void spam(SWIGTYPE_p_int x, SWIGTYPE_p_int y, int z) { ... } -

    24.4.5 Enum classes

    +

    25.4.5 Enum classes

    @@ -3121,7 +3121,7 @@ The Enumerations section discussed these but om The following sub-sections detail the various types of enum classes that can be generated.

    -

    24.4.5.1 Typesafe enum classes

    +

    25.4.5.1 Typesafe enum classes

    @@ -3205,7 +3205,7 @@ The swigValue method is used for marshalling in the other direction. The toString method is overridden so that the enum name is available.

    -

    24.4.5.2 Proper Java enum classes

    +

    25.4.5.2 Proper Java enum classes

    @@ -3283,7 +3283,7 @@ These needn't be generated if the enum being wrapped does not have any initializ Simpler Java enums for enums without initializers section describes how typemaps can be used to achieve this.

    -

    24.4.5.3 Type unsafe enum classes

    +

    25.4.5.3 Type unsafe enum classes

    @@ -3314,7 +3314,7 @@ public final class Beverage { -

    24.5 Cross language polymorphism using directors

    +

    25.5 Cross language polymorphism using directors

    @@ -3336,7 +3336,7 @@ The upshot is that C++ classes can be extended in Java and from C++ these extens Neither C++ code nor Java code needs to know where a particular method is implemented: the combination of proxy classes, director classes, and C wrapper functions transparently takes care of all the cross-language method routing.

    -

    24.5.1 Enabling directors

    +

    25.5.1 Enabling directors

    @@ -3404,7 +3404,7 @@ public: -

    24.5.2 Director classes

    +

    25.5.2 Director classes

    @@ -3431,7 +3431,7 @@ If the correct implementation is in Java, the Java API is used to call the metho

    -

    24.5.3 Overhead and code bloat

    +

    25.5.3 Overhead and code bloat

    @@ -3449,7 +3449,7 @@ This situation can be optimized by selectively enabling director methods (using

    -

    24.5.4 Simple directors example

    +

    25.5.4 Simple directors example

    @@ -3514,7 +3514,7 @@ DirectorDerived::upcall_method() invoked. -

    24.5.5 Director threading issues

    +

    25.5.5 Director threading issues

    @@ -3534,7 +3534,7 @@ Macros can be defined on the commandline when compiling your C++ code, or altern -

    24.5.6 Director performance tuning

    +

    25.5.6 Director performance tuning

    @@ -3555,7 +3555,8 @@ However, if all director methods are expected to usually be overridden by Java s The disadvantage is that invocation of director methods from C++ when Java doesn't actually override the method will require an additional call up into Java and back to C++. As such, this option is only useful when overrides are extremely common and instantiation is frequent enough that its performance is critical.

    -

    24.5.7 Java exceptions from directors

    +

    25.5.7 Java exceptions from directors

    +

    With directors routing method calls to Java, and proxies routing them @@ -3716,6 +3717,7 @@ this potential fate. Swig::DirectorException, any director methods that have exception specifications may cause program termination. To simply ignore unexpected exceptions, the default handling can be changed with: +

    @@ -3729,7 +3731,6 @@ unexpected exceptions, the default handling can be changed with:
     %}
     
    -

    Alternatively an exception compatible with the existing director method exception specifications can be thrown. Assuming that all @@ -3862,7 +3863,7 @@ See the Exception handling with %exception an section for more on converting C++ exceptions to Java exceptions.

    -

    24.6 Accessing protected members

    +

    25.6 Accessing protected members

    @@ -3958,7 +3959,7 @@ class MyProtectedBase extends ProtectedBase -

    24.7 Common customization features

    +

    25.7 Common customization features

    @@ -3970,7 +3971,7 @@ be awkward. This section describes some common SWIG features that are used to improve the interface to existing C/C++ code.

    -

    24.7.1 C/C++ helper functions

    +

    25.7.1 C/C++ helper functions

    @@ -4036,7 +4037,7 @@ hard to implement. It is possible to improve on this using Java code, typemaps, customization features as covered in later sections, but sometimes helper functions are a quick and easy solution to difficult cases.

    -

    24.7.2 Class extension with %extend

    +

    25.7.2 Class extension with %extend

    @@ -4099,7 +4100,7 @@ Vector(2,3,4) in any way---the extensions only show up in the Java interface.

    -

    24.7.3 Exception handling with %exception and %javaexception

    +

    25.7.3 Exception handling with %exception and %javaexception

    @@ -4258,7 +4259,7 @@ to raise exceptions. See the SWIG Library ch The typemap example Handling C++ exception specifications as Java exceptions provides further exception handling capabilities.

    -

    24.7.4 Method access with %javamethodmodifiers

    +

    25.7.4 Method access with %javamethodmodifiers

    @@ -4284,7 +4285,7 @@ protected static void protect_me() { -

    24.8 Tips and techniques

    +

    25.8 Tips and techniques

    @@ -4294,7 +4295,7 @@ strings and arrays. This chapter discusses the common techniques for solving these problems.

    -

    24.8.1 Input and output parameters using primitive pointers and references

    +

    25.8.1 Input and output parameters using primitive pointers and references

    @@ -4468,7 +4469,7 @@ void foo(Bar *OUTPUT); will not have the intended effect since typemaps.i does not define an OUTPUT rule for Bar.

    -

    24.8.2 Simple pointers

    +

    25.8.2 Simple pointers

    @@ -4534,7 +4535,7 @@ System.out.println("3 + 4 = " + result); See the SWIG Library chapter for further details.

    -

    24.8.3 Wrapping C arrays with Java arrays

    +

    25.8.3 Wrapping C arrays with Java arrays

    @@ -4601,7 +4602,7 @@ Please be aware that the typemaps in this library are not efficient as all the e There is an alternative approach using the SWIG array library and this is covered in the next section.

    -

    24.8.4 Unbounded C Arrays

    +

    25.8.4 Unbounded C Arrays

    @@ -4746,7 +4747,7 @@ well suited for applications in which you need to create buffers, package binary data, etc.

    -

    24.8.5 Binary data vs Strings

    +

    25.8.5 Binary data vs Strings

    @@ -4790,7 +4791,7 @@ len: 5 data: 68 69 0 6a 6b -

    24.8.6 Overriding new and delete to allocate from Java heap

    +

    25.8.6 Overriding new and delete to allocate from Java heap

    @@ -4907,7 +4908,7 @@ model and use these functions in place of malloc and free in your own code.

    -

    24.9 Java typemaps

    +

    25.9 Java typemaps

    @@ -4928,7 +4929,7 @@ Before proceeding, it should be stressed that typemaps are not a required part of using SWIG---the default wrapping behavior is enough in most cases. Typemaps are only used if you want to change some aspect of the generated code. -

    24.9.1 Default primitive type mappings

    +

    25.9.1 Default primitive type mappings

    @@ -5080,7 +5081,7 @@ However, the mappings allow the full range of values for each C type from Java.

    -

    24.9.2 Default typemaps for non-primitive types

    +

    25.9.2 Default typemaps for non-primitive types

    @@ -5095,7 +5096,7 @@ So in summary, the C/C++ pointer to non-primitive types is cast into the 64 bit The Java type is either the proxy class or type wrapper class.

    -

    24.9.3 Sixty four bit JVMs

    +

    25.9.3 Sixty four bit JVMs

    @@ -5108,7 +5109,7 @@ Unfortunately it won't of course hold true for JNI code.

    -

    24.9.4 What is a typemap?

    +

    25.9.4 What is a typemap?

    @@ -5231,7 +5232,7 @@ int c = example.count('e',"Hello World"); -

    24.9.5 Typemaps for mapping C/C++ types to Java types

    +

    25.9.5 Typemaps for mapping C/C++ types to Java types

    @@ -5491,7 +5492,7 @@ These are listed below: -

    24.9.6 Java typemap attributes

    +

    25.9.6 Java typemap attributes

    @@ -5537,7 +5538,7 @@ The "javain" typemap has the optional 'pre', 'post' and 'pgcppname' attributes. Note that when the 'pre' or 'post' attributes are specified and the associated type is used in a constructor, a constructor helper function is generated. This is necessary as the Java proxy constructor wrapper makes a call to a support constructor using a this call. In Java the this call must be the first statement in the constructor body. The constructor body thus calls the helper function and the helper function instead makes the JNI call, ensuring the 'pre' code is called before the JNI call is made. There is a Date marshalling example showing 'pre', 'post' and 'pgcppname' attributes in action.

    -

    24.9.7 Java special variables

    +

    25.9.7 Java special variables

    @@ -5688,7 +5689,7 @@ This special variable expands to the intermediary class name. Usually this is th unless the jniclassname attribute is specified in the %module directive.

    -

    24.9.8 Typemaps for both C and C++ compilation

    +

    25.9.8 Typemaps for both C and C++ compilation

    @@ -5725,7 +5726,7 @@ If you do not intend your code to be targeting both C and C++ then your typemaps

    -

    24.9.9 Java code typemaps

    +

    25.9.9 Java code typemaps

    @@ -5963,7 +5964,7 @@ to make the method and constructor public: -

    24.9.10 Director specific typemaps

    +

    25.9.10 Director specific typemaps

    @@ -6227,7 +6228,7 @@ The basic strategy here is to provide a default package typemap for the majority -

    24.10 Typemap Examples

    +

    25.10 Typemap Examples

    @@ -6237,7 +6238,7 @@ the SWIG library.

    -

    24.10.1 Simpler Java enums for enums without initializers

    +

    25.10.1 Simpler Java enums for enums without initializers

    @@ -6316,7 +6317,7 @@ This would be done by using the original versions of these typemaps in "enums.sw

    -

    24.10.2 Handling C++ exception specifications as Java exceptions

    +

    25.10.2 Handling C++ exception specifications as Java exceptions

    @@ -6441,7 +6442,7 @@ We could alternatively have used %rename to rename what() into

    -

    24.10.3 NaN Exception - exception handling for a particular type

    +

    25.10.3 NaN Exception - exception handling for a particular type

    @@ -6596,7 +6597,7 @@ If we were a martyr to the JNI cause, we could replace the succinct code within If we had, we would have put it in the "in" typemap which, like all JNI and Java typemaps, also supports the 'throws' attribute.

    -

    24.10.4 Converting Java String arrays to char **

    +

    25.10.4 Converting Java String arrays to char **

    @@ -6740,7 +6741,7 @@ Lastly the "jni", "jtype" and "jstype" typemaps are also required to specify what Java types to use.

    -

    24.10.5 Expanding a Java object to multiple arguments

    +

    25.10.5 Expanding a Java object to multiple arguments

    @@ -6822,7 +6823,7 @@ example.foo(new String[]{"red", "green", "blue", "white"}); -

    24.10.6 Using typemaps to return arguments

    +

    25.10.6 Using typemaps to return arguments

    @@ -6940,7 +6941,7 @@ $ java runme 1 12.0 340.0 -

    24.10.7 Adding Java downcasts to polymorphic return types

    +

    25.10.7 Adding Java downcasts to polymorphic return types

    @@ -7146,7 +7147,7 @@ SWIG usually generates code which constructs the proxy classes using Java code a Note that the JNI code above uses a number of string lookups to call a constructor, whereas this would not occur using byte compiled Java code.

    -

    24.10.8 Adding an equals method to the Java classes

    +

    25.10.8 Adding an equals method to the Java classes

    @@ -7190,7 +7191,7 @@ System.out.println("foo1? " + foo1.equals(foo2)); -

    24.10.9 Void pointers and a common Java base class

    +

    25.10.9 Void pointers and a common Java base class

    @@ -7249,7 +7250,7 @@ This example contains some useful functionality which you may want in your code.

  • It also has a function which effectively implements a cast from the type of the proxy/type wrapper class to a void pointer. This is necessary for passing a proxy class or a type wrapper class to a function that takes a void pointer. -

    24.10.10 Struct pointer to pointer

    +

    25.10.10 Struct pointer to pointer

    @@ -7429,7 +7430,7 @@ The C functional interface has been completely morphed into an object-oriented i the Butler class would behave much like any pure Java class and feel more natural to Java users.

    -

    24.10.11 Memory management when returning references to member variables

    +

    25.10.11 Memory management when returning references to member variables

    @@ -7552,7 +7553,7 @@ public class Bike { Note the addReference call.

    -

    24.10.12 Memory management for objects passed to the C++ layer

    +

    25.10.12 Memory management for objects passed to the C++ layer

    @@ -7668,7 +7669,7 @@ The 'javacode' typemap simply adds in the specified code into the Java proxy cla -

    24.10.13 Date marshalling using the javain typemap and associated attributes

    +

    25.10.13 Date marshalling using the javain typemap and associated attributes

    @@ -7845,7 +7846,7 @@ A few things to note: -

    24.11 Living with Java Directors

    +

    25.11 Living with Java Directors

    @@ -8026,10 +8027,10 @@ public abstract class UserVisibleFoo extends Foo {

  • -

    24.12 Odds and ends

    +

    25.12 Odds and ends

    -

    24.12.1 JavaDoc comments

    +

    25.12.1 JavaDoc comments

    @@ -8085,7 +8086,7 @@ public class Barmy { -

    24.12.2 Functional interface without proxy classes

    +

    25.12.2 Functional interface without proxy classes

    @@ -8146,7 +8147,7 @@ All destructors have to be called manually for example the delete_Foo(foo) -

    24.12.3 Using your own JNI functions

    +

    25.12.3 Using your own JNI functions

    @@ -8196,7 +8197,7 @@ This directive is only really useful if you want to mix your own hand crafted JN

    -

    24.12.4 Performance concerns and hints

    +

    25.12.4 Performance concerns and hints

    @@ -8217,7 +8218,7 @@ However, you will have to be careful about memory management and make sure that This method normally calls the C++ destructor or free() for C code.

    -

    24.12.5 Debugging

    +

    25.12.5 Debugging

    @@ -8239,7 +8240,7 @@ The -verbose:jni and -verbose:gc are also useful options for monitoring code beh

    -

    24.13 Java Examples

    +

    25.13 Java Examples

    diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html index 7510c8686..740988e71 100644 --- a/Doc/Manual/Library.html +++ b/Doc/Manual/Library.html @@ -6,7 +6,7 @@ -

    8 SWIG library

    +

    9 SWIG library

      @@ -59,7 +59,7 @@ Alternative libraries provide similar functionality. Please read this chapter carefully if you used the old libraries.

      -

      8.1 The %include directive and library search path

      +

      9.1 The %include directive and library search path

      @@ -91,7 +91,7 @@ Set the environment variable to hold an alternative library directory. The directories that are searched are displayed when using -verbose commandline option.

      -

      8.2 C Arrays and Pointers

      +

      9.2 C Arrays and Pointers

      @@ -103,7 +103,7 @@ pointers as class-like objects. Since these functions provide direct access to memory, their use is potentially unsafe and you should exercise caution.

      -

      8.2.1 cpointer.i

      +

      9.2.1 cpointer.i

      @@ -319,7 +319,7 @@ In this example, the function int_to_uint() would be used to cast type Note: When working with simple pointers, typemaps can often be used to provide more seamless operation.

      -

      8.2.2 carrays.i

      +

      9.2.2 carrays.i

      @@ -497,7 +497,7 @@ you should consider using a special array object rather than a bare pointer. used with types of char or char *.

      -

      8.2.3 cmalloc.i

      +

      9.2.3 cmalloc.i

      @@ -658,7 +658,7 @@ Now, in a script:

    -

    8.2.4 cdata.i

    +

    9.2.4 cdata.i

    @@ -760,7 +760,7 @@ char *cdata_name(type* ptr, int nitems) Clearly they are unsafe.

    -

    8.3 C String Handling

    +

    9.3 C String Handling

    @@ -780,7 +780,7 @@ morality. The modules in this section provide basic functionality for manipulating raw C strings.

    -

    8.3.1 Default string handling

    +

    9.3.1 Default string handling

    @@ -821,7 +821,7 @@ interpreter and lead to a crash). Furthermore, the default behavior does not work well with binary data. Instead, strings are assumed to be NULL-terminated.

    -

    8.3.2 Passing binary data

    +

    9.3.2 Passing binary data

    @@ -863,7 +863,7 @@ In the wrapper function, the passed string will be expanded to a pointer and len The (char *STRING, int LENGTH) multi-argument typemap is also available in addition to (char *STRING, size_t LENGTH).

    -

    8.3.3 Using %newobject to release memory

    +

    9.3.3 Using %newobject to release memory

    @@ -904,7 +904,7 @@ however, you may need to provide your own "newfree" typemap for other types. See Object ownership and %newobject for more details.

    -

    8.3.4 cstring.i

    +

    9.3.4 cstring.i

    @@ -1364,7 +1364,7 @@ structure or class instead. -

    8.4 STL/C++ Library

    +

    9.4 STL/C++ Library

    @@ -1402,7 +1402,7 @@ Please look for the library files in the appropriate language library directory.

    -

    8.4.1 std::string

    +

    9.4.1 std::string

    @@ -1486,7 +1486,7 @@ void foo(string s, const String &t); // std_string typemaps still applie -

    8.4.2 std::vector

    +

    9.4.2 std::vector

    @@ -1665,7 +1665,7 @@ if you want to make their head explode. details and the public API exposed to the interpreter vary.

    -

    8.4.3 STL exceptions

    +

    9.4.3 STL exceptions

    @@ -1715,7 +1715,7 @@ The %exception directive can be used by placing the following code befo Any thrown STL exceptions will then be gracefully handled instead of causing a crash.

    -

    8.4.4 shared_ptr smart pointer

    +

    9.4.4 shared_ptr smart pointer

    @@ -1904,7 +1904,8 @@ Adding the missing %shared_ptr macros will fix this:

    -

    8.4.5 auto_ptr smart pointer

    +

    9.4.5 auto_ptr smart pointer

    +

    While std::auto_ptr is deprecated in C++11, some existing code may @@ -1952,10 +1953,10 @@ int value = k.getValue(); -

    8.5 Utility Libraries

    +

    9.5 Utility Libraries

    -

    8.5.1 exception.i

    +

    9.5.1 exception.i

    diff --git a/Doc/Manual/Lisp.html b/Doc/Manual/Lisp.html index 09e410185..7ea9139ac 100644 --- a/Doc/Manual/Lisp.html +++ b/Doc/Manual/Lisp.html @@ -6,7 +6,7 @@ -

    25 SWIG and Common Lisp

    +

    26 SWIG and Common Lisp

      @@ -41,7 +41,7 @@ Lisp, Common Foreign Function Interface(CFFI), CLisp and UFFI foreign function interfaces.

      -

      25.1 Allegro Common Lisp

      +

      26.1 Allegro Common Lisp

      @@ -50,7 +50,7 @@ here

      -

      25.2 Common Foreign Function Interface(CFFI)

      +

      26.2 Common Foreign Function Interface(CFFI)

      @@ -77,7 +77,7 @@ swig -cffi -module module-name file-name files and the various things which you can do with them.

      -

      25.2.1 Additional Commandline Options

      +

      26.2.1 Additional Commandline Options

      @@ -118,7 +118,7 @@ swig -cffi -help -

      25.2.2 Generating CFFI bindings

      +

      26.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
    -

    25.2.3 Generating CFFI bindings for C++ code

    +

    26.2.3 Generating CFFI bindings for C++ code

    This feature to SWIG (for CFFI) is very new and still far from @@ -568,7 +568,7 @@ If you have any questions, suggestions, patches, etc., related to CFFI module feel free to contact us on the SWIG mailing list, and also please add a "[CFFI]" tag in the subject line. -

    25.2.4 Inserting user code into generated files

    +

    26.2.4 Inserting user code into generated files

    @@ -608,7 +608,7 @@ Note that the block %{ ... %} is effectively a shortcut for

    -

    25.3 CLISP

    +

    26.3 CLISP

    @@ -638,7 +638,7 @@ swig -clisp -module module-name file-name interface file for the CLISP module. The CLISP module tries to produce code which is both human readable and easily modifyable.

    -

    25.3.1 Additional Commandline Options

    +

    26.3.1 Additional Commandline Options

    @@ -671,7 +671,7 @@ and global variables will be created otherwise only definitions for
    -

    25.3.2 Details on CLISP bindings

    +

    26.3.2 Details on CLISP bindings

    @@ -795,7 +795,7 @@ struct bar { -

    25.4 UFFI

    +

    26.4 UFFI

    diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index e7d1a5b1b..f0415d8d6 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -6,7 +6,7 @@ -

    26 SWIG and Lua

    +

    27 SWIG and Lua

  • Typemaps -
  • Writing typemaps +
  • Writing typemaps
  • Customization of your Bindings @@ -73,14 +85,14 @@ Lua is an extension programming language designed to support general procedural eLua stands for Embedded Lua (can be thought of as a flavor of Lua) and offers the full implementation of the Lua programming language to the embedded world, extending it with specific features for efficient and portable software embedded development. eLua runs on smaller devices like microcontrollers and provides the full features of the regular Lua desktop version. More information on eLua can be found here: http://www.eluaproject.net

    -

    26.1 Preliminaries

    +

    27.1 Preliminaries

    The current SWIG implementation is designed to work with Lua 5.0.x, 5.1.x and 5.2.x. It should work with later versions of Lua, but certainly not with Lua 4.0 due to substantial API changes. It is possible to either static link or dynamic link a Lua module into the interpreter (normally Lua static links its libraries, as dynamic linking is not available on all platforms). SWIG also has support for eLua starting from eLua 0.8. Due to substantial changes between SWIG 2.x and SWIG 3.0 and unavailability of testing platform, eLua status was downgraded to 'experimental'.

    -

    26.2 Running SWIG

    +

    27.2 Running SWIG

    @@ -128,7 +140,7 @@ $ swig -lua -eluac example.i The -elua option puts all the C function wrappers and variable get/set wrappers in rotables. It also generates a metatable which will control the access to these variables from eLua. It also offers a significant amount of module size compression. On the other hand, the -eluac option puts all the wrappers in a single rotable. With this option, no matter how huge the module, it will consume no additional microcontroller SRAM (crass compression). There is a catch though: Metatables are not generated with -eluac. To access any value from eLua, one must directly call the wrapper function associated with that value.

    -

    26.2.1 Additional command line options

    +

    27.2.1 Additional command line options

    @@ -169,7 +181,7 @@ swig -lua -help -

    26.2.2 Compiling and Linking and Interpreter

    +

    27.2.2 Compiling and Linking and Interpreter

    @@ -240,7 +252,7 @@ LUALIB_API int ( luaopen_mod )(lua_State *L ); More information on building and configuring eLua can be found here: http://www.eluaproject.net/doc/v0.8/en_building.html

    -

    26.2.3 Compiling a dynamic module

    +

    27.2.3 Compiling a dynamic module

    @@ -308,7 +320,7 @@ Is quite obvious (Go back and consult the Lua documents on how to enable loadlib -

    26.2.4 Using your module

    +

    27.2.4 Using your module

    @@ -326,19 +338,19 @@ $ ./my_lua >

  • -

    26.3 A tour of basic C/C++ wrapping

    +

    27.3 A tour of basic C/C++ wrapping

    By default, SWIG tries to build a very natural Lua interface to your C/C++ code. This section briefly covers the essential aspects of this wrapping.

    -

    26.3.1 Modules

    +

    27.3.1 Modules

    The SWIG module directive specifies the name of the Lua module. If you specify `module example', then everything is wrapped into a Lua table 'example' containing all the functions and variables. When choosing a module name, make sure you don't use the same name as a built-in Lua command or standard module name.

    -

    26.3.2 Functions

    +

    27.3.2 Functions

    @@ -379,7 +391,7 @@ It is also possible to rename the module with an assignment. 24 -

    26.3.3 Global variables

    +

    27.3.3 Global variables

    @@ -467,7 +479,7 @@ If you have used the -eluac option for your eLua module, you will have In general, functions of the form "variable_get()" and "variable_set()" are automatically generated by SWIG for use with -eluac.

    -

    26.3.4 Constants and enums

    +

    27.3.4 Constants and enums

    @@ -502,7 +514,9 @@ If you're using eLua and have used -elua or -eluac to generate Hello World -

    Constants/enums and classes/structures

    +

    27.3.4.1 Constants/enums and classes/structures

    + +

    Enums are exported into a class table. For example, given some enums:

    @@ -556,7 +570,7 @@ If the -no-old-metatable-bindings option is used, then these old-style It is worth mentioning, that example.Test.TEST1 and example.Test_TEST1 are different entities and changing one does not change the other. Given the fact that these are constantes and they are not supposed to be changed, it is up to you to avoid such issues.

    -

    26.3.5 Pointers

    +

    27.3.5 Pointers

    @@ -594,7 +608,7 @@ Lua enforces the integrity of its userdata, so it is virtually impossible to cor nil -

    26.3.6 Structures

    +

    27.3.6 Structures

    @@ -698,7 +712,7 @@ For eLua with the -eluac option, structure manipulation has to be perfo In general, functions of the form "new_struct()", "struct_member_get()", "struct_member_set()" and "free_struct()" are automatically generated by SWIG for each structure defined in C. (Please note: This doesn't apply for modules generated with the -elua option)

    -

    26.3.7 C++ classes

    +

    27.3.7 C++ classes

    @@ -770,7 +784,7 @@ Both style names are generated by default now. However, if the -no-old-metatable-bindings option is used, then the backward compatible names are not generated in addition to ordinary ones.

    -

    26.3.8 C++ inheritance

    +

    27.3.8 C++ inheritance

    @@ -795,7 +809,7 @@ then the function spam() accepts a Foo pointer or a pointer to any clas

    It is safe to use multiple inheritance with SWIG.

    -

    26.3.9 Pointers, references, values, and arrays

    +

    27.3.9 Pointers, references, values, and arrays

    @@ -826,7 +840,7 @@ Foo spam7();

    then all three functions will return a pointer to some Foo object. Since the third function (spam7) returns a value, newly allocated memory is used to hold the result and a pointer is returned (Lua will release this memory when the return value is garbage collected). The other two are pointers which are assumed to be managed by the C code and so will not be garbage collected.

    -

    26.3.10 C++ overloaded functions

    +

    27.3.10 C++ overloaded functions

    @@ -912,7 +926,7 @@ Please refer to the "SWIG and C++" chapter for more information about overloadin

    Dealing with the Lua coercion mechanism, the priority is roughly (integers, floats, strings, userdata). But it is better to rename the functions rather than rely upon the ordering.

    -

    26.3.11 C++ operators

    +

    27.3.11 C++ operators

    @@ -1024,7 +1038,7 @@ It is also possible to overload the operator[], but currently this cann }; -

    26.3.12 Class extension with %extend

    +

    27.3.12 Class extension with %extend

    @@ -1080,7 +1094,7 @@ true Extend works with both C and C++ code, on classes and structs. It does not modify the underlying object in any way---the extensions only show up in the Lua interface. The only item to take note of is the code has to use the '$self' instead of 'this', and that you cannot access protected/private members of the code (as you are not officially part of the class).

    -

    26.3.13 Using %newobject to release memory

    +

    27.3.13 Using %newobject to release memory

    If you have a function that allocates memory like this,

    @@ -1104,7 +1118,7 @@ char *foo();

    This will release the allocated memory.

    -

    26.3.14 C++ templates

    +

    27.3.14 C++ templates

    @@ -1139,7 +1153,7 @@ In Lua:

    Obviously, there is more to template wrapping than shown in this example. More details can be found in the SWIG and C++ chapter. Some more complicated examples will appear later.

    -

    26.3.15 C++ Smart Pointers

    +

    27.3.15 C++ Smart Pointers

    @@ -1191,7 +1205,7 @@ If you ever need to access the underlying pointer returned by operator->( > f = p:__deref__() -- Returns underlying Foo * -

    26.3.16 C++ Exceptions

    +

    27.3.16 C++ Exceptions

    @@ -1334,7 +1348,9 @@ and the "Exception handling add exception specification to functions or globally (respectively).

    -

    26.3.17 Namespaces

    +

    27.3.17 Namespaces

    + +

    Since SWIG-3.0.0 C++ namespaces are supported via the %nspace feature.

    @@ -1379,7 +1395,9 @@ Now, from Lua usage is as follows: 19 > -

    Compatibility Note

    +

    27.3.17.1 Compatibility Note

    + +

    If SWIG is running in backward compatible way, i.e. without -no-old-metatable-bindings option, then additional old-style names are generated(notice the underscore):

    @@ -1391,8 +1409,12 @@ If SWIG is running in backward compatible way, i.e. without -no-old-metatabl 11 > -

    Compatibility Note

    -

    Names

    +

    27.3.18 Compatibility Note

    + + +

    27.3.18.1 Names

    + +

    If SWIG is launched without -no-old-metatable-bindings option, then it enters backward-compatible mode. While in this mode, it tries to generate additional names for static functions, class static constants and class enums. Those names are in a form $classname_$symbolname and are added to the scope surrounding the class. @@ -1434,7 +1456,9 @@ surrounding scope without any prefixing. Pretending that Test2 is a struct, not > -

    Inheritance

    +

    27.3.18.2 Inheritance

    + +

    The internal organization of inheritance has changed. Consider the following C++ code:

    %module example
    @@ -1473,12 +1497,12 @@ function
     >
     
    -

    26.4 Typemaps

    +

    27.4 Typemaps

    This section explains what typemaps are and how to use them. The default wrapping behaviour of SWIG is enough in most cases. However sometimes SWIG may need a little additional assistance to know which typemap to apply to provide the best wrapping. This section will be explaining how to use typemaps to best effect

    -

    26.4.1 What is a typemap?

    +

    27.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:

    @@ -1506,7 +1530,7 @@ Received an integer : 6 720 -

    26.4.2 Using typemaps

    +

    27.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.

    @@ -1559,7 +1583,7 @@ void swap(int *sx, int *sy);

    Note: C++ references must be handled exactly the same way. However SWIG will automatically wrap a const int& as an input parameter (since that it obviously input).

    -

    26.4.3 Typemaps and arrays

    +

    27.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 @@ -1623,7 +1647,7 @@ and Lua tables to be 1..N, (the indexing follows the norm for the language). In

    Note: SWIG also can support arrays of pointers in a similar manner.

    -

    26.4.4 Typemaps and pointer-pointer functions

    +

    27.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:

    @@ -1657,7 +1681,7 @@ int Create_Math(iMath** pptr); // its creator (assume it mallocs) ptr=nil -- the iMath* will be GC'ed as normal -

    26.5 Writing typemaps

    +

    27.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.

    @@ -1666,7 +1690,7 @@ ptr=nil -- the iMath* will be GC'ed as normal

    Before proceeding, you should read the previous section on using typemaps, and look at the existing typemaps found in luatypemaps.swg and typemaps.i. These are both well documented and fairly easy to read. You should not attempt to write your own typemaps until you have read and can understand both of these files (they may well also give you an idea to base your work on).

    -

    26.5.1 Typemaps you can write

    +

    27.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.

    @@ -1679,7 +1703,7 @@ ptr=nil -- the iMath* will be GC'ed as normal (the syntax for the typecheck is different from the typemap, see typemaps for details). -

    26.5.2 SWIG's Lua-C API

    +

    27.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.

    @@ -1728,7 +1752,7 @@ This macro, when called within the context of a SWIG wrapped function, will disp
    Similar to SWIG_fail_arg, except that it will display the swig_type_info information instead.
    -

    26.6 Customization of your Bindings

    +

    27.6 Customization of your Bindings

    @@ -1737,7 +1761,7 @@ This section covers adding of some small extra bits to your module to add the la -

    26.6.1 Writing your own custom wrappers

    +

    27.6.1 Writing your own custom wrappers

    @@ -1756,7 +1780,7 @@ int native_function(lua_State*L) // my native code The %native directive in the above example, tells SWIG that there is a function int native_function(lua_State*L); which is to be added into the module under the name 'my_func'. SWIG will not add any wrapper for this function, beyond adding it into the function table. How you write your code is entirely up to you.

    -

    26.6.2 Adding additional Lua code

    +

    27.6.2 Adding additional Lua code

    @@ -1794,7 +1818,7 @@ Good uses for this feature is adding of new code, or writing helper functions to See Examples/lua/arrays for an example of this code.

    -

    26.7 Details on the Lua binding

    +

    27.7 Details on the Lua binding

    @@ -1805,7 +1829,7 @@ See Examples/lua/arrays for an example of this code.

    -

    26.7.1 Binding global data into the module.

    +

    27.7.1 Binding global data into the module.

    @@ -1865,7 +1889,7 @@ end

    That way when you call 'a=example.Foo', the interpreter looks at the table 'example' sees that there is no field 'Foo' and calls __index. This will in turn check in '.get' table and find the existence of 'Foo' and then return the value of the C function call 'Foo_get()'. Similarly for the code 'example.Foo=10', the interpreter will check the table, then call the __newindex which will then check the '.set' table and call the C function 'Foo_set(10)'.

    -

    26.7.2 Userdata and Metatables

    +

    27.7.2 Userdata and Metatables

    @@ -1945,7 +1969,7 @@ Note: Both the opaque structures (like the FILE*) and normal wrapped classes/str

    Note: Operator overloads are basically done in the same way, by adding functions such as '__add' & '__call' to the class' metatable. The current implementation is a bit rough as it will add any member function beginning with '__' into the metatable too, assuming its an operator overload.

    -

    26.7.3 Memory management

    +

    27.7.3 Memory management

    diff --git a/Doc/Manual/Modula3.html b/Doc/Manual/Modula3.html index 329127a0f..0bf9f2995 100644 --- a/Doc/Manual/Modula3.html +++ b/Doc/Manual/Modula3.html @@ -5,7 +5,7 @@ -

    27 SWIG and Modula-3

    +

    28 SWIG and Modula-3

      @@ -54,7 +54,7 @@ especially typemaps.

      -

      27.1 Overview

      +

      28.1 Overview

      @@ -84,7 +84,7 @@ FFTW -

      27.1.1 Motivation

      +

      28.1.1 Motivation

      @@ -131,10 +131,10 @@ functions), but it doesn't allow you to easily integrate a Modula-3 module into a C/C++ project.

      -

      27.2 Conception

      +

      28.2 Conception

      -

      27.2.1 Interfaces to C libraries

      +

      28.2.1 Interfaces to C libraries

      @@ -283,7 +283,7 @@ and the principal type must be renamed (%typemap).

      -

      27.2.2 Interfaces to C++ libraries

      +

      28.2.2 Interfaces to C++ libraries

      @@ -384,10 +384,10 @@ There is no C++ library I wrote a SWIG interface for, so I'm not sure if this is possible or sensible, yet.

      -

      27.3 Preliminaries

      +

      28.3 Preliminaries

      -

      27.3.1 Compilers

      +

      28.3.1 Compilers

      @@ -400,7 +400,7 @@ For testing examples I use Critical Mass cm3.

      -

      27.3.2 Additional Commandline Options

      +

      28.3.2 Additional Commandline Options

      @@ -477,10 +477,10 @@ Instead generate templates for some basic typemaps. -

      27.4 Modula-3 typemaps

      +

      28.4 Modula-3 typemaps

      -

      27.4.1 Inputs and outputs

      +

      28.4.1 Inputs and outputs

      @@ -694,7 +694,7 @@ consist of the following parts: -

      27.4.2 Subranges, Enumerations, Sets

      +

      28.4.2 Subranges, Enumerations, Sets

      @@ -746,7 +746,7 @@ that I'd like to automate.

      -

      27.4.3 Objects

      +

      28.4.3 Objects

      @@ -759,7 +759,7 @@ is not really useful, yet.

      -

      27.4.4 Imports

      +

      28.4.4 Imports

      @@ -792,7 +792,7 @@ IMPORT M3toC;

    -

    27.4.5 Exceptions

    +

    28.4.5 Exceptions

    @@ -816,7 +816,7 @@ you should declare %typemap("m3wrapinconv:throws") blah * %{OSError.E%}.

    -

    27.4.6 Example

    +

    28.4.6 Example

    @@ -863,10 +863,10 @@ where almost everything is generated by a typemap: -

    27.5 More hints to the generator

    +

    28.5 More hints to the generator

    -

    27.5.1 Features

    +

    28.5.1 Features

    @@ -903,7 +903,7 @@ where almost everything is generated by a typemap:
    -

    27.5.2 Pragmas

    +

    28.5.2 Pragmas

    @@ -926,7 +926,7 @@ where almost everything is generated by a typemap:
    -

    27.6 Remarks

    +

    28.6 Remarks

      diff --git a/Doc/Manual/Modules.html b/Doc/Manual/Modules.html index c44341e56..551fd0750 100644 --- a/Doc/Manual/Modules.html +++ b/Doc/Manual/Modules.html @@ -6,7 +6,7 @@ -

      15 Working with Modules

      +

      16 Working with Modules

        @@ -23,7 +23,7 @@ -

        15.1 Modules Introduction

        +

        16.1 Modules Introduction

        @@ -77,7 +77,7 @@ where you want to create a collection of modules. Each module in the collection is created via separate invocations of SWIG.

        -

        15.2 Basics

        +

        16.2 Basics

        @@ -176,7 +176,7 @@ in parallel from multiple threads as SWIG provides no locking - for more on that issue, read on.

        -

        15.3 The SWIG runtime code

        +

        16.3 The SWIG runtime code

        @@ -242,7 +242,7 @@ can peacefully coexist. So the type structures are separated by the is empty. Only modules compiled with the same pair will share type information.

        -

        15.4 External access to the runtime

        +

        16.4 External access to the runtime

        As described in The run-time type checker, @@ -279,7 +279,7 @@ SWIG_TYPE_TABLE to be the same as the module whose types you are trying to access.

        -

        15.5 A word of caution about static libraries

        +

        16.5 A word of caution about static libraries

        @@ -290,7 +290,7 @@ into it. This is very often NOT what you want and it can lead to unexpect behavior. When working with dynamically loadable modules, you should try to work exclusively with shared libraries.

        -

        15.6 References

        +

        16.6 References

        @@ -298,7 +298,7 @@ Due to the complexity of working with shared libraries and multiple modules, it an outside reference. John Levine's "Linkers and Loaders" is highly recommended.

        -

        15.7 Reducing the wrapper file size

        +

        16.7 Reducing the wrapper file size

        diff --git a/Doc/Manual/Mzscheme.html b/Doc/Manual/Mzscheme.html index 3b49a2974..40173d720 100644 --- a/Doc/Manual/Mzscheme.html +++ b/Doc/Manual/Mzscheme.html @@ -8,7 +8,7 @@ -

        28 SWIG and MzScheme/Racket

        +

        29 SWIG and MzScheme/Racket

          @@ -24,7 +24,7 @@

          This section contains information on SWIG's support of Racket, formally known as MzScheme. -

          28.1 Creating native structures

          +

          29.1 Creating native structures

          @@ -65,7 +65,7 @@ Then in scheme, you can use regular struct access procedures like

        -

        28.2 Simple example

        +

        29.2 Simple example

        @@ -166,7 +166,7 @@ Some points of interest:

      • The above requests mzc to create an extension using the CGC garbage-collector. The alternative -- the 3m collector -- has generally better performance, but work is still required for SWIG to emit code which is compatible with it.
      -

      28.3 External documentation

      +

      29.3 External documentation

      diff --git a/Doc/Manual/Ocaml.html b/Doc/Manual/Ocaml.html index 2eef3ad4d..ec46d6e50 100644 --- a/Doc/Manual/Ocaml.html +++ b/Doc/Manual/Ocaml.html @@ -6,7 +6,7 @@ -

      29 SWIG and Ocaml

      +

      30 SWIG and Ocaml

        @@ -80,7 +80,7 @@ If you're not familiar with the Objective Caml language, you can visit The Ocaml Website.

        -

        29.1 Preliminaries

        +

        30.1 Preliminaries

        @@ -99,7 +99,7 @@ file Examples/Makefile illustrate how to compile and link SWIG modules that will be loaded dynamically. This has only been tested on Linux so far.

        -

        29.1.1 Running SWIG

        +

        30.1.1 Running SWIG

        @@ -122,7 +122,7 @@ you will compile the file example_wrap.c with ocamlc or the resulting .ml and .mli files as well, and do the final link with -custom (not needed for native link).

        -

        29.1.2 Compiling the code

        +

        30.1.2 Compiling the code

        @@ -158,7 +158,7 @@ the user more freedom with respect to custom typing.

      -

      29.1.3 The camlp4 module

      +

      30.1.3 The camlp4 module

      @@ -234,7 +234,7 @@ let b = C_string (getenv "PATH") -

      29.1.4 Using your module

      +

      30.1.4 Using your module

      @@ -248,7 +248,7 @@ When linking any ocaml bytecode with your module, use the -custom option is not needed when you build native code.

      -

      29.1.5 Compilation problems and compiling with C++

      +

      30.1.5 Compilation problems and compiling with C++

      @@ -259,7 +259,7 @@ liberal with pointer types may not compile under the C++ compiler. Most code meant to be compiled as C++ will not have problems.

      -

      29.2 The low-level Ocaml/C interface

      +

      30.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.

      -

      29.2.1 The generated module

      +

      30.2.1 The generated module

      @@ -394,7 +394,7 @@ it describes the output SWIG will generate for class definitions. -

      29.2.2 Enums

      +

      30.2.2 Enums

      @@ -457,7 +457,7 @@ val x : Enum_test.c_obj = C_enum `a

      -

      29.2.2.1 Enum typing in Ocaml

      +

      30.2.2.1 Enum typing in Ocaml

      @@ -470,10 +470,10 @@ functions imported from different modules. You must convert values to master values using the swig_val function before sharing them with another module.

      -

      29.2.3 Arrays

      +

      30.2.3 Arrays

      -

      29.2.3.1 Simple types of bounded arrays

      +

      30.2.3.1 Simple types of bounded arrays

      @@ -494,7 +494,7 @@ arrays of simple types with known bounds in your code, but this only works for arrays whose bounds are completely specified.

      -

      29.2.3.2 Complex and unbounded arrays

      +

      30.2.3.2 Complex and unbounded arrays

      @@ -507,7 +507,7 @@ SWIG can't predict which of these methods will be used in the array, so you have to specify it for yourself in the form of a typemap.

      -

      29.2.3.3 Using an object

      +

      30.2.3.3 Using an object

      @@ -521,7 +521,7 @@ Consider writing an object when the ending condition of your array is complex, such as using a required sentinel, etc.

      -

      29.2.3.4 Example typemap for a function taking float * and int

      +

      30.2.3.4 Example typemap for a function taking float * and int

      @@ -572,7 +572,7 @@ void printfloats( float *tab, int len ); -

      29.2.4 C++ Classes

      +

      30.2.4 C++ Classes

      @@ -615,7 +615,7 @@ the underlying pointer, so using create_[x]_from_ptr alters the returned value for the same object.

      -

      29.2.4.1 STL vector and string Example

      +

      30.2.4.1 STL vector and string Example

      @@ -695,7 +695,7 @@ baz # -

      29.2.4.2 C++ Class Example

      +

      30.2.4.2 C++ Class Example

      @@ -725,7 +725,7 @@ public: }; -

      29.2.4.3 Compiling the example

      +

      30.2.4.3 Compiling the example

      @@ -743,7 +743,7 @@ bash-2.05a$ ocamlmktop -custom swig.cmo -I `camlp4 -where` \
         -L$QTPATH/lib -cclib -lqt
       
      -

      29.2.4.4 Sample Session

      +

      30.2.4.4 Sample Session

      @@ -770,10 +770,10 @@ Assuming you have a working installation of QT, you will see a window
       containing the string "hi" in a button.  
       

      -

      29.2.5 Director Classes

      +

      30.2.5 Director Classes

      -

      29.2.5.1 Director Introduction

      +

      30.2.5.1 Director Introduction

      @@ -800,7 +800,7 @@ class foo { };

      -

      29.2.5.2 Overriding Methods in Ocaml

      +

      30.2.5.2 Overriding Methods in Ocaml

      @@ -828,7 +828,7 @@ In this example, I'll examine the objective caml code involved in providing an overloaded class. This example is contained in Examples/ocaml/shapes.

      -

      29.2.5.3 Director Usage Example

      +

      30.2.5.3 Director Usage Example

      @@ -887,7 +887,7 @@ in a more effortless style in ocaml, while leaving the "engine" part of the program in C++.

      -

      29.2.5.4 Creating director objects

      +

      30.2.5.4 Creating director objects

      @@ -928,7 +928,7 @@ object from causing a core dump, as long as the object is destroyed properly.

      -

      29.2.5.5 Typemaps for directors, directorin, directorout, directorargout

      +

      30.2.5.5 Typemaps for directors, directorin, directorout, directorargout

      @@ -939,7 +939,7 @@ well as a function return value in the same way you provide function arguments, and to receive arguments the same way you normally receive function returns.

      -

      29.2.5.6 directorin typemap

      +

      30.2.5.6 directorin typemap

      @@ -950,7 +950,7 @@ code receives when you are called. In general, a simple directorin typ can use the same body as a simple out typemap.

      -

      29.2.5.7 directorout typemap

      +

      30.2.5.7 directorout typemap

      @@ -961,7 +961,7 @@ for the same type, except when there are special requirements for object ownership, etc.

      -

      29.2.5.8 directorargout typemap

      +

      30.2.5.8 directorargout typemap

      @@ -978,7 +978,7 @@ In the event that you don't specify all of the necessary values, integral values will read zero, and struct or object returns have undefined results.

      -

      29.2.6 Exceptions

      +

      30.2.6 Exceptions

      diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 42c6526b7..bc6873c4b 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -8,7 +8,7 @@ -

      30 SWIG and Octave

      +

      31 SWIG and Octave

        @@ -55,7 +55,7 @@ More information can be found at O Also, there are a dozen or so examples in the Examples/octave directory, and hundreds in the test suite (Examples/test-suite and Examples/test-suite/octave).

        -

        30.1 Preliminaries

        +

        31.1 Preliminaries

        @@ -63,7 +63,7 @@ As of SWIG 3.0.0, the Octave module has been tested with Octave versions 3.0.5, Use of Octave versions older than 3.x.x is not recommended, as these versions are no longer tested with SWIG.

        -

        30.2 Running SWIG

        +

        31.2 Running SWIG

        @@ -95,7 +95,7 @@ The -c++ option is also required when wrapping C++ code: This creates a C++ source file "example_wrap.cpp". A C++ file is generated even when wrapping C code as Octave is itself written in C++ and requires wrapper code to be in the same language. The generated C++ source file contains the low-level wrappers that need to be compiled and linked with the rest of your C/C++ application (in this case, the gcd implementation) to create an extension module.

        -

        30.2.1 Command-line options

        +

        31.2.1 Command-line options

        @@ -118,7 +118,7 @@ The special name "." loads C global variables into the module namespace, i.e. al The -opprefix options sets the prefix of the names of global/friend operator functions.

        -

        30.2.2 Compiling a dynamic module

        +

        31.2.2 Compiling a dynamic module

        @@ -145,7 +145,7 @@ $ mkoctfile example_wrap.cpp example.c

        octave:1> swigexample
        -

        30.2.3 Using your module

        +

        31.2.3 Using your module

        @@ -163,10 +163,10 @@ octave:4> swigexample.cvar.Foo=4; octave:5> swigexample.cvar.Foo ans = 4

      -

      30.3 A tour of basic C/C++ wrapping

      +

      31.3 A tour of basic C/C++ wrapping

      -

      30.3.1 Modules

      +

      31.3.1 Modules

      @@ -211,7 +211,7 @@ octave:4> swigexample.gcd(4,6) ans = 2 -

      30.3.2 Functions

      +

      31.3.2 Functions

      @@ -228,7 +228,7 @@ int fact(int n);

      octave:1> swigexample.fact(4)
       24 
      -

      30.3.3 Global variables

      +

      31.3.3 Global variables

      @@ -281,7 +281,7 @@ octave:2> swigexample.PI=3.142; octave:3> swigexample.PI ans = 3.1420 -

      30.3.4 Constants and enums

      +

      31.3.4 Constants and enums

      @@ -303,7 +303,7 @@ swigexample.SCONST="Hello World" swigexample.SUNDAY=0 .... -

      30.3.5 Pointers

      +

      31.3.5 Pointers

      @@ -350,7 +350,7 @@ octave:2> f=swigexample.fopen("not there","r"); error: value on right hand side of assignment is undefined error: evaluating assignment expression near line 2, column 2 -

      30.3.6 Structures and C++ classes

      +

      31.3.6 Structures and C++ classes

      @@ -485,7 +485,7 @@ ans = 1 Depending on the ownership setting of a swig_ref, it may call C++ destructors when its reference count goes to zero. See the section on memory management below for details.

      -

      30.3.7 C++ inheritance

      +

      31.3.7 C++ inheritance

      @@ -494,7 +494,7 @@ This information contains the full class hierarchy. When an indexing operation ( the tree is walked to find a match in the current class as well as any of its bases. The lookup is then cached in the swig_ref.

      -

      30.3.8 C++ overloaded functions

      +

      31.3.8 C++ overloaded functions

      @@ -504,7 +504,7 @@ The dispatch function selects which overload to call (if any) based on the passe typecheck typemaps are used to analyze each argument, as well as assign precedence. See the chapter on typemaps for details.

      -

      30.3.9 C++ operators

      +

      31.3.9 C++ operators

      @@ -608,7 +608,7 @@ On the C++ side, the default mappings are as follows: Octave can also utilise friend (i.e. non-member) operators with a simple %rename: see the example in the Examples/octave/operator directory.

      -

      30.3.10 Class extension with %extend

      +

      31.3.10 Class extension with %extend

      @@ -638,7 +638,7 @@ octave:3> printf("%s\n",a); octave:4> a.__str() 4 -

      30.3.11 C++ templates

      +

      31.3.11 C++ templates

      @@ -715,14 +715,14 @@ ans = -

      30.3.12 C++ Smart Pointers

      +

      31.3.12 C++ Smart Pointers

      C++ smart pointers are fully supported as in other modules.

      -

      30.3.13 Directors (calling Octave from C++ code)

      +

      31.3.13 Directors (calling Octave from C++ code)

      @@ -803,14 +803,14 @@ c-side routine called octave-side routine called -

      30.3.14 Threads

      +

      31.3.14 Threads

      The use of threads in wrapped Director code is not supported; i.e., an Octave-side implementation of a C++ class must be called from the Octave interpreter's thread. Anything fancier (apartment/queue model, whatever) is left to the user. Without anything fancier, this amounts to the limitation that Octave must drive the module... like, for example, an optimization package that calls Octave to evaluate an objective function.

      -

      30.3.15 Memory management

      +

      31.3.15 Memory management

      @@ -844,14 +844,14 @@ The %newobject directive may be used to control this behavior for pointers retur In the case where one wishes for the C++ side to own an object that was created in Octave (especially a Director object), one can use the __disown() method to invert this logic. Then letting the Octave reference count go to zero will not destroy the object, but destroying the object will invalidate the Octave-side object if it still exists (and call destructors of other C++ bases in the case of multiple inheritance/subclass()'ing).

      -

      30.3.16 STL support

      +

      31.3.16 STL support

      Various STL library files are provided for wrapping STL containers.

      -

      30.3.17 Matrix typemaps

      +

      31.3.17 Matrix typemaps

      diff --git a/Doc/Manual/Perl5.html b/Doc/Manual/Perl5.html index 9e577b08b..010eb48df 100644 --- a/Doc/Manual/Perl5.html +++ b/Doc/Manual/Perl5.html @@ -6,7 +6,7 @@ -

      31 SWIG and Perl5

      +

      32 SWIG and Perl5

        @@ -96,7 +96,7 @@ later. We're no longer testing regularly with older versions, but Perl 5.6 seems to mostly work, while older versions don't.

        -

        31.1 Overview

        +

        32.1 Overview

        @@ -117,7 +117,7 @@ described. Advanced customization features, typemaps, and other options are found near the end of the chapter.

        -

        31.2 Preliminaries

        +

        32.2 Preliminaries

        @@ -142,7 +142,7 @@ To build the module, you will need to compile the file example_wrap.c and link it with the rest of your program.

        -

        31.2.1 Getting the right header files

        +

        32.2.1 Getting the right header files

        @@ -174,7 +174,7 @@ $ perl -e 'use Config; print "$Config{archlib}\n";'

      -

      31.2.2 Compiling a dynamic module

      +

      32.2.2 Compiling a dynamic module

      @@ -207,7 +207,7 @@ the target should be named `example.so', `example.sl', or the appropriate dynamic module name on your system.

      -

      31.2.3 Building a dynamic module with MakeMaker

      +

      32.2.3 Building a dynamic module with MakeMaker

      @@ -241,7 +241,7 @@ the preferred approach to compilation. More information about MakeMaker can be found in "Programming Perl, 2nd ed." by Larry Wall, Tom Christiansen, and Randal Schwartz.

      -

      31.2.4 Building a static version of Perl

      +

      32.2.4 Building a static version of Perl

      @@ -310,7 +310,7 @@ added to it. Depending on your machine, you may need to link with additional libraries such as -lsocket, -lnsl, -ldl, etc.

      -

      31.2.5 Using the module

      +

      32.2.5 Using the module

      @@ -463,7 +463,7 @@ system configuration (this requires root access and you will need to read the man pages).

      -

      31.2.6 Compilation problems and compiling with C++

      +

      32.2.6 Compilation problems and compiling with C++

      @@ -606,7 +606,7 @@ have to find the macro that conflicts and add an #undef into the .i file. Pleas any conflicting macros you find to swig-user mailing list.

      -

      31.2.7 Compiling for 64-bit platforms

      +

      32.2.7 Compiling for 64-bit platforms

      @@ -633,7 +633,7 @@ also introduce problems on platforms that support more than one linking standard (e.g., -o32 and -n32 on Irix).

      -

      31.3 Building Perl Extensions under Windows

      +

      32.3 Building Perl Extensions under Windows

      @@ -644,7 +644,7 @@ section assumes you are using SWIG with Microsoft Visual C++ although the procedure may be similar with other compilers.

      -

      31.3.1 Running SWIG from Developer Studio

      +

      32.3.1 Running SWIG from Developer Studio

      @@ -707,7 +707,7 @@ print "$a\n"; -

      31.3.2 Using other compilers

      +

      32.3.2 Using other compilers

      @@ -715,7 +715,7 @@ SWIG is known to work with Cygwin and may work with other compilers on Windows. For general hints and suggestions refer to the Windows chapter.

      -

      31.4 The low-level interface

      +

      32.4 The low-level interface

      @@ -725,7 +725,7 @@ can be used to control your application. However, it is also used to construct more user-friendly proxy classes as described in the next section.

      -

      31.4.1 Functions

      +

      32.4.1 Functions

      @@ -748,7 +748,7 @@ use example; $a = &example::fact(2); -

      31.4.2 Global variables

      +

      32.4.2 Global variables

      @@ -818,7 +818,7 @@ extern char *path; // Declared later in the input -

      31.4.3 Constants

      +

      32.4.3 Constants

      @@ -858,7 +858,7 @@ print example::FOO,"\n"; -

      31.4.4 Pointers

      +

      32.4.4 Pointers

      @@ -967,7 +967,7 @@ as XS and xsubpp. Given the advancement of the SWIG typesystem and the SWIG and XS, this is no longer supported.

      -

      31.4.5 Structures

      +

      32.4.5 Structures

      @@ -1101,7 +1101,7 @@ void Bar_f_set(Bar *b, Foo *val) { -

      31.4.6 C++ classes

      +

      32.4.6 C++ classes

      @@ -1166,7 +1166,7 @@ provides direct access to C++ objects. A higher level interface using Perl prox can be built using these low-level accessors. This is described shortly.

      -

      31.4.7 C++ classes and type-checking

      +

      32.4.7 C++ classes and type-checking

      @@ -1202,7 +1202,7 @@ If necessary, the type-checker also adjusts the value of the pointer (as is nece multiple inheritance is used).

      -

      31.4.8 C++ overloaded functions

      +

      32.4.8 C++ overloaded functions

      @@ -1246,7 +1246,7 @@ example::Spam_foo_d($s,3.14); Please refer to the "SWIG Basics" chapter for more information.

      -

      31.4.9 Operators

      +

      32.4.9 Operators

      @@ -1273,7 +1273,7 @@ The following C++ operators are currently supported by the Perl module:

    • operator or
    • -

      31.4.10 Modules and packages

      +

      32.4.10 Modules and packages

      @@ -1368,7 +1368,7 @@ print Foo::fact(4),"\n"; # Call a function in package FooBar --> -

      31.5 Input and output parameters

      +

      32.5 Input and output parameters

      @@ -1587,7 +1587,7 @@ print "$c\n"; Note: The REFERENCE feature is only currently supported for numeric types (integers and floating point).

      -

      31.6 Exception handling

      +

      32.6 Exception handling

      @@ -1752,7 +1752,7 @@ This is still supported, but it is deprecated. The newer %exception di functionality, but it has additional capabilities that make it more powerful.

      -

      31.7 Remapping datatypes with typemaps

      +

      32.7 Remapping datatypes with typemaps

      @@ -1769,7 +1769,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Perl interface.

      -

      31.7.1 A simple typemap example

      +

      32.7.1 A simple typemap example

      @@ -1873,7 +1873,7 @@ example::count("e","Hello World"); -

      31.7.2 Perl5 typemaps

      +

      32.7.2 Perl5 typemaps

      @@ -1978,7 +1978,7 @@ Return of C++ member data (all languages). Check value of input parameter. -

      31.7.3 Typemap variables

      +

      32.7.3 Typemap variables

      @@ -2049,7 +2049,7 @@ properly assigned. The Perl name of the wrapper function being created. -

      31.7.4 Useful functions

      +

      32.7.4 Useful functions

      @@ -2118,7 +2118,7 @@ int sv_isa(SV *, char *0; -

      31.8 Typemap Examples

      +

      32.8 Typemap Examples

      @@ -2127,7 +2127,7 @@ might look at the files "perl5.swg" and "typemaps.i" in the SWIG library.

      -

      31.8.1 Converting a Perl5 array to a char **

      +

      32.8.1 Converting a Perl5 array to a char **

      @@ -2219,7 +2219,7 @@ print @$b,"\n"; # Print it out -

      31.8.2 Return values

      +

      32.8.2 Return values

      @@ -2248,7 +2248,7 @@ can be done using the EXTEND() macro as in: } -

      31.8.3 Returning values from arguments

      +

      32.8.3 Returning values from arguments

      @@ -2302,7 +2302,7 @@ print "multout(7,13) = @r\n"; ($x,$y) = multout(7,13); -

      31.8.4 Accessing array structure members

      +

      32.8.4 Accessing array structure members

      @@ -2365,7 +2365,7 @@ the "in" typemap in the previous section would be used to convert an to copy the converted array into a C data structure.

      -

      31.8.5 Turning Perl references into C pointers

      +

      32.8.5 Turning Perl references into C pointers

      @@ -2430,7 +2430,7 @@ print "$c\n"; -

      31.8.6 Pointer handling

      +

      32.8.6 Pointer handling

      @@ -2509,7 +2509,7 @@ For example: -

      31.9 Proxy classes

      +

      32.9 Proxy classes

      @@ -2525,7 +2525,7 @@ to the underlying code. This section describes the implementation details of the proxy interface.

      -

      31.9.1 Preliminaries

      +

      32.9.1 Preliminaries

      @@ -2547,7 +2547,7 @@ SWIG creates a collection of high-level Perl wrappers. In your scripts, you wil high level wrappers. The wrappers, in turn, interact with the low-level procedural module.

      -

      31.9.2 Structure and class wrappers

      +

      32.9.2 Structure and class wrappers

      @@ -2673,7 +2673,7 @@ $v->DESTROY(); -

      31.9.3 Object Ownership

      +

      32.9.3 Object Ownership

      @@ -2760,7 +2760,7 @@ counting, garbage collection, or advanced features one might find in sophisticated languages.

      -

      31.9.4 Nested Objects

      +

      32.9.4 Nested Objects

      @@ -2813,7 +2813,7 @@ $p->{f}->{x} = 0.0; %${$p->{v}} = ( x=>0, y=>0, z=>0); -

      31.9.5 Proxy Functions

      +

      32.9.5 Proxy Functions

      @@ -2847,7 +2847,7 @@ This function replaces the original function, but operates in an identical manner.

      -

      31.9.6 Inheritance

      +

      32.9.6 Inheritance

      @@ -2923,7 +2923,7 @@ particular, inheritance of data members is extremely tricky (and I'm not even sure if it really works).

      -

      31.9.7 Modifying the proxy methods

      +

      32.9.7 Modifying the proxy methods

      @@ -2951,7 +2951,7 @@ public: }; -

      31.10 Adding additional Perl code

      +

      32.10 Adding additional Perl code

      @@ -3002,7 +3002,7 @@ set_transform($im, $a); -

      31.11 Cross language polymorphism

      +

      32.11 Cross language polymorphism

      @@ -3036,7 +3036,7 @@ proxy classes, director classes, and C wrapper functions takes care of all the cross-language method routing transparently.

      -

      31.11.1 Enabling directors

      +

      32.11.1 Enabling directors

      @@ -3126,7 +3126,7 @@ sub one { -

      31.11.2 Director classes

      +

      32.11.2 Director classes

      @@ -3206,7 +3206,7 @@ so there is no need for the extra overhead involved with routing the calls through Perl.

      -

      31.11.3 Ownership and object destruction

      +

      32.11.3 Ownership and object destruction

      @@ -3255,7 +3255,7 @@ sub DESTROY { -

      31.11.4 Exception unrolling

      +

      32.11.4 Exception unrolling

      @@ -3311,7 +3311,7 @@ Swig::DirectorMethodException is thrown, Perl will register the exception as soon as the C wrapper function returns.

      -

      31.11.5 Overhead and code bloat

      +

      32.11.5 Overhead and code bloat

      @@ -3345,7 +3345,7 @@ directive) for only those methods that are likely to be extended in Perl.

      -

      31.11.6 Typemaps

      +

      32.11.6 Typemaps

      diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 19bfab6ba..493c861f8 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -7,7 +7,7 @@ -

      32 SWIG and PHP

      +

      33 SWIG and PHP

        @@ -79,7 +79,7 @@ your extension into php directly, you will need the complete PHP source tree available.

        -

        32.1 Generating PHP Extensions

        +

        33.1 Generating PHP Extensions

        @@ -126,7 +126,7 @@ and it doesn't play nicely with package system. We don't recommend this approach, or provide explicit support for it.

        -

        32.1.1 Building a loadable extension

        +

        33.1.1 Building a loadable extension

        @@ -141,7 +141,7 @@ least work for Linux though): gcc -shared example_wrap.o -o example.so

      -

      32.1.2 Using PHP Extensions

      +

      33.1.2 Using PHP Extensions

      @@ -172,7 +172,7 @@ attempts to do the dl() call for you: include("example.php"); -

      32.2 Basic PHP interface

      +

      33.2 Basic PHP interface

      @@ -183,7 +183,7 @@ other symbols unless care is taken to %rename them. At present SWIG doesn't have support for the namespace feature added in PHP 5.3.

      -

      32.2.1 Constants

      +

      33.2.1 Constants

      @@ -260,7 +260,7 @@ is treated as true by the if test, when the value of the intended constant would be treated as false!

      -

      32.2.2 Global Variables

      +

      33.2.2 Global Variables

      @@ -309,7 +309,7 @@ undefined. At this time SWIG does not support custom accessor methods.

      -

      32.2.3 Functions

      +

      33.2.3 Functions

      @@ -362,7 +362,7 @@ print $s; # The value of $s was not changed. --> -

      32.2.4 Overloading

      +

      33.2.4 Overloading

      @@ -418,7 +418,7 @@ taking the integer argument.

      --> -

      32.2.5 Pointers and References

      +

      33.2.5 Pointers and References

      @@ -563,7 +563,7 @@ PHP in a number of ways: by using unset on an existing variable, or assigning NULL to a variable.

      -

      32.2.6 Structures and C++ classes

      +

      33.2.6 Structures and C++ classes

      @@ -624,7 +624,7 @@ Would be used in the following way from PHP5: Member variables and methods are accessed using the -> operator.

      -

      32.2.6.1 Using -noproxy

      +

      33.2.6.1 Using -noproxy

      @@ -650,7 +650,7 @@ Complex_im_set($obj,$d); Complex_im_get($obj); -

      32.2.6.2 Constructors and Destructors

      +

      33.2.6.2 Constructors and Destructors

      @@ -691,7 +691,7 @@ the programmer can either reassign the variable or call unset($v)

      -

      32.2.6.3 Static Member Variables

      +

      33.2.6.3 Static Member Variables

      @@ -734,7 +734,7 @@ Ko::threats(10); echo "There have now been " . Ko::threats() . " threats\n"; -

      32.2.6.4 Static Member Functions

      +

      33.2.6.4 Static Member Functions

      @@ -756,7 +756,7 @@ Ko::threats(); -

      32.2.7 PHP Pragmas, Startup and Shutdown code

      +

      33.2.7 PHP Pragmas, Startup and Shutdown code

      @@ -844,7 +844,7 @@ The %rinit and %rshutdown statements are very similar but inse into the request init (PHP_RINIT_FUNCTION) and request shutdown (PHP_RSHUTDOWN_FUNCTION) code respectively.

      -

      32.3 Cross language polymorphism

      +

      33.3 Cross language polymorphism

      @@ -879,7 +879,7 @@ wrapper functions takes care of all the cross-language method routing transparently.

      -

      32.3.1 Enabling directors

      +

      33.3.1 Enabling directors

      @@ -968,7 +968,7 @@ class MyFoo extends Foo { -

      32.3.2 Director classes

      +

      33.3.2 Director classes

      @@ -1048,7 +1048,7 @@ so there is no need for the extra overhead involved with routing the calls through PHP.

      -

      32.3.3 Ownership and object destruction

      +

      33.3.3 Ownership and object destruction

      @@ -1104,7 +1104,7 @@ In this example, we are assuming that FooContainer will take care of deleting all the Foo pointers it contains at some point.

      -

      32.3.4 Exception unrolling

      +

      33.3.4 Exception unrolling

      @@ -1163,7 +1163,7 @@ Swig::DirectorMethodException is thrown, PHP will register the exception as soon as the C wrapper function returns.

      -

      32.3.5 Overhead and code bloat

      +

      33.3.5 Overhead and code bloat

      @@ -1196,7 +1196,7 @@ optimized by selectively enabling director methods (using the %feature directive) for only those methods that are likely to be extended in PHP.

      -

      32.3.6 Typemaps

      +

      33.3.6 Typemaps

      @@ -1210,7 +1210,7 @@ need to be supported.

      -

      32.3.7 Miscellaneous

      +

      33.3.7 Miscellaneous

      Director typemaps for STL classes are mostly in place, and hence you diff --git a/Doc/Manual/Pike.html b/Doc/Manual/Pike.html index 8c1eb2d36..3ede1a992 100644 --- a/Doc/Manual/Pike.html +++ b/Doc/Manual/Pike.html @@ -6,7 +6,7 @@ -

      33 SWIG and Pike

      +

      34 SWIG and Pike

        @@ -46,10 +46,10 @@ least, make sure you read the "SWIG Basics" chapter.

        -

        33.1 Preliminaries

        +

        34.1 Preliminaries

        -

        33.1.1 Running SWIG

        +

        34.1.1 Running SWIG

        @@ -94,7 +94,7 @@ can use the -o option:

        $ swig -pike -o pseudonym.c example.i
        -

        33.1.2 Getting the right header files

        +

        34.1.2 Getting the right header files

        @@ -114,7 +114,7 @@ You're looking for files with the names global.h, program.h and so on.

        -

        33.1.3 Using your module

        +

        34.1.3 Using your module

        @@ -129,10 +129,10 @@ Pike v7.4 release 10 running Hilfe v3.5 (Incremental Pike Frontend) (1) Result: 24

      -

      33.2 Basic C/C++ Mapping

      +

      34.2 Basic C/C++ Mapping

      -

      33.2.1 Modules

      +

      34.2.1 Modules

      @@ -143,7 +143,7 @@ concerned), SWIG's %module directive doesn't really have any significance.

      -

      33.2.2 Functions

      +

      34.2.2 Functions

      @@ -168,7 +168,7 @@ exactly as you'd expect it to: (1) Result: 24 -

      33.2.3 Global variables

      +

      34.2.3 Global variables

      @@ -197,7 +197,7 @@ will result in two functions, Foo_get() and Foo_set(): (3) Result: 3.141590 -

      33.2.4 Constants and enumerated types

      +

      34.2.4 Constants and enumerated types

      @@ -205,7 +205,7 @@ Enumerated types in C/C++ declarations are wrapped as Pike constants, not as Pike enums.

      -

      33.2.5 Constructors and Destructors

      +

      34.2.5 Constructors and Destructors

      @@ -213,7 +213,7 @@ Constructors are wrapped as create() methods, and destructors are wrapped as destroy() methods, for Pike classes.

      -

      33.2.6 Static Members

      +

      34.2.6 Static Members

      diff --git a/Doc/Manual/Preprocessor.html b/Doc/Manual/Preprocessor.html index 8fcbe9206..d5c41dde7 100644 --- a/Doc/Manual/Preprocessor.html +++ b/Doc/Manual/Preprocessor.html @@ -6,7 +6,7 @@ -

      7 Preprocessing

      +

      8 Preprocessing

        @@ -37,7 +37,7 @@ However, a number of modifications and enhancements have been made. This chapter describes some of these modifications.

        -

        7.1 File inclusion

        +

        8.1 File inclusion

        @@ -63,7 +63,7 @@ By default, the #include is ignored unless you run SWIG with the is that you often don't want SWIG to try and wrap everything included in standard header system headers and auxiliary files. -

        7.2 File imports

        +

        8.2 File imports

        @@ -92,7 +92,7 @@ The -importall directive tells SWIG to follow all #include sta as imports. This might be useful if you want to extract type definitions from system header files without generating any wrappers. -

        7.3 Conditional Compilation

        +

        8.3 Conditional Compilation

        @@ -152,7 +152,7 @@ SWIG (except for the symbol `SWIG' which is only defined within the SWIG compiler).

        -

        7.4 Macro Expansion

        +

        8.4 Macro Expansion

        @@ -207,7 +207,7 @@ like #x. This is a non-standard SWIG extension.

      -

      7.5 SWIG Macros

      +

      8.5 SWIG Macros

      @@ -253,7 +253,7 @@ many of SWIG's advanced features and libraries are built using this mechanism (s support).

      -

      7.6 C99 and GNU Extensions

      +

      8.6 C99 and GNU Extensions

      @@ -309,14 +309,14 @@ interface building. However, they are used internally to implement a number of SWIG directives and are provided to make SWIG more compatible with C99 code.

      -

      7.7 Preprocessing and delimiters

      +

      8.7 Preprocessing and delimiters

      The preprocessor handles { }, " " and %{ %} delimiters differently.

      -

      7.7.1 Preprocessing and %{ ... %} & " ... " delimiters

      +

      8.7.1 Preprocessing and %{ ... %} & " ... " delimiters

      @@ -341,7 +341,7 @@ the contents of the %{ ... %} block are copied without modification to the output (including all preprocessor directives).

      -

      7.7.2 Preprocessing and { ... } delimiters

      +

      8.7.2 Preprocessing and { ... } delimiters

      @@ -383,7 +383,7 @@ to actually go into the wrapper file, prefix the preprocessor directives with % and leave the preprocessor directive in the code.

      -

      7.8 Preprocessor and Typemaps

      +

      8.8 Preprocessor and Typemaps

      @@ -454,7 +454,7 @@ would generate

      -

      7.9 Viewing preprocessor output

      +

      8.9 Viewing preprocessor output

      @@ -464,7 +464,7 @@ Instead the results after the preprocessor has run are displayed. This might be useful as an aid to debugging and viewing the results of macro expansions.

      -

      7.10 The #error and #warning directives

      +

      8.10 The #error and #warning directives

      diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 522412fc8..dcfd7427e 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -6,7 +6,7 @@ -

      34 SWIG and Python

      +

      35 SWIG and Python

        @@ -106,10 +106,10 @@
    • Python Packages
    • Python 3 Support
        @@ -141,7 +141,7 @@ very least, make sure you read the "SWIG Basics" chapter.

        -

        34.1 Overview

        +

        35.1 Overview

        @@ -168,10 +168,10 @@ described followed by a discussion of low-level implementation details.

        -

        34.2 Preliminaries

        +

        35.2 Preliminaries

        -

        34.2.1 Running SWIG

        +

        35.2.1 Running SWIG

        @@ -269,7 +269,7 @@ The following sections have further practical examples and details on how you might go about compiling and using the generated files.

        -

        34.2.2 Using distutils

        +

        35.2.2 Using distutils

        @@ -361,7 +361,7 @@ This same approach works on all platforms if the appropriate compiler is install can even build extensions to the standard Windows Python using MingGW)

        -

        34.2.3 Hand compiling a dynamic module

        +

        35.2.3 Hand compiling a dynamic module

        @@ -409,7 +409,7 @@ module actually consists of two files; socket.py and

        -

        34.2.4 Static linking

        +

        35.2.4 Static linking

        @@ -488,7 +488,7 @@ If using static linking, you might want to rely on a different approach (perhaps using distutils).

        -

        34.2.5 Using your module

        +

        35.2.5 Using your module

        @@ -645,7 +645,7 @@ system configuration (this requires root access and you will need to read the man pages).

        -

        34.2.6 Compilation of C++ extensions

        +

        35.2.6 Compilation of C++ extensions

        @@ -737,7 +737,7 @@ erratic program behavior. If working with lots of software components, you might want to investigate using a more formal standard such as COM.

        -

        34.2.7 Compiling for 64-bit platforms

        +

        35.2.7 Compiling for 64-bit platforms

        @@ -774,7 +774,7 @@ and -m64 allow you to choose the desired binary format for your python extension.

        -

        34.2.8 Building Python Extensions under Windows

        +

        35.2.8 Building Python Extensions under Windows

        @@ -903,7 +903,7 @@ SWIG Wiki.

        -

        34.3 A tour of basic C/C++ wrapping

        +

        35.3 A tour of basic C/C++ wrapping

        @@ -912,7 +912,7 @@ to your C/C++ code. Functions are wrapped as functions, classes are wrapped as This section briefly covers the essential aspects of this wrapping.

        -

        34.3.1 Modules

        +

        35.3.1 Modules

        @@ -925,7 +925,7 @@ module name, make sure you don't use the same name as a built-in Python command or standard module name.

        -

        34.3.2 Functions

        +

        35.3.2 Functions

        @@ -949,7 +949,7 @@ like you think it does: >>>

    • -

      34.3.3 Global variables

      +

      35.3.3 Global variables

      @@ -1087,7 +1087,7 @@ that starts with a leading underscore. SWIG does not create cvar if there are no global variables in a module.

      -

      34.3.4 Constants and enums

      +

      35.3.4 Constants and enums

      @@ -1127,7 +1127,7 @@ other object. Unfortunately, there is no easy way for SWIG to generate code that prevents this. You will just have to be careful.

      -

      34.3.5 Pointers

      +

      35.3.5 Pointers

      @@ -1268,7 +1268,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return None if the conversion can't be performed.

      -

      34.3.6 Structures

      +

      35.3.6 Structures

      @@ -1457,7 +1457,7 @@ everything works just like you would expect. For example: -

      34.3.7 C++ classes

      +

      35.3.7 C++ classes

      @@ -1546,7 +1546,7 @@ they are accessed through cvar like this: -

      34.3.8 C++ inheritance

      +

      35.3.8 C++ inheritance

      @@ -1601,7 +1601,7 @@ then the function spam() accepts Foo * or a pointer to any cla It is safe to use multiple inheritance with SWIG.

      -

      34.3.9 Pointers, references, values, and arrays

      +

      35.3.9 Pointers, references, values, and arrays

      @@ -1662,7 +1662,7 @@ treated as a returning value, and it will follow the same allocation/deallocation process.

      -

      34.3.10 C++ overloaded functions

      +

      35.3.10 C++ overloaded functions

      @@ -1785,7 +1785,7 @@ first declaration takes precedence. Please refer to the "SWIG and C++" chapter for more information about overloading.

      -

      34.3.11 C++ operators

      +

      35.3.11 C++ operators

      @@ -1874,7 +1874,7 @@ Also, be aware that certain operators don't map cleanly to Python. For instance overloaded assignment operators don't map to Python semantics and will be ignored.

      -

      34.3.12 C++ namespaces

      +

      35.3.12 C++ namespaces

      @@ -1941,7 +1941,7 @@ utilizes thousands of small deeply nested namespaces each with identical symbol names, well, then you get what you deserve.

      -

      34.3.13 C++ templates

      +

      35.3.13 C++ templates

      @@ -1995,7 +1995,7 @@ Some more complicated examples will appear later.

      -

      34.3.14 C++ Smart Pointers

      +

      35.3.14 C++ Smart Pointers

      @@ -2079,7 +2079,7 @@ simply use the __deref__() method. For example: -

      34.3.15 C++ reference counted objects

      +

      35.3.15 C++ reference counted objects

      @@ -2088,7 +2088,7 @@ Python examples of memory management using referencing counting.

      -

      34.4 Further details on the Python class interface

      +

      35.4 Further details on the Python class interface

      @@ -2111,7 +2111,7 @@ the -builtin option are in the Built-in section.

      -

      34.4.1 Proxy classes

      +

      35.4.1 Proxy classes

      @@ -2200,7 +2200,7 @@ you can attach new Python methods to the class and you can even inherit from it by Python built-in types until Python 2.2).

      -

      34.4.2 Built-in Types

      +

      35.4.2 Built-in Types

      @@ -2244,7 +2244,7 @@ please refer to the python documentation:

      http://docs.python.org/extending/newtypes.html

      -

      34.4.2.1 Limitations

      +

      35.4.2.1 Limitations

      Use of the -builtin option implies a couple of limitations: @@ -2412,7 +2412,7 @@ assert(issubclass(B.Derived, A.Base)) -

      34.4.2.2 Operator overloads -- use them!

      +

      35.4.2.2 Operator overloads -- use them!

      The entire justification for the -builtin option is improved @@ -2513,7 +2513,7 @@ structs.

      -

      34.4.3 Memory management

      +

      35.4.3 Memory management

      NOTE: Although this section refers to proxy objects, everything here also applies @@ -2708,7 +2708,7 @@ It is also possible to deal with situations like this using typemaps--an advanced topic discussed later.

      -

      34.4.4 Python 2.2 and classic classes

      +

      35.4.4 Python 2.2 and classic classes

      @@ -2745,7 +2745,7 @@ class itself. In Python-2.1 and earlier, they have to be accessed as a global function or through an instance (see the earlier section).

      -

      34.5 Cross language polymorphism

      +

      35.5 Cross language polymorphism

      @@ -2779,7 +2779,7 @@ proxy classes, director classes, and C wrapper functions takes care of all the cross-language method routing transparently.

      -

      34.5.1 Enabling directors

      +

      35.5.1 Enabling directors

      @@ -2869,7 +2869,7 @@ class MyFoo(mymodule.Foo): -

      34.5.2 Director classes

      +

      35.5.2 Director classes

      @@ -2951,7 +2951,7 @@ so there is no need for the extra overhead involved with routing the calls through Python.

      -

      34.5.3 Ownership and object destruction

      +

      35.5.3 Ownership and object destruction

      @@ -3018,7 +3018,7 @@ deleting all the Foo pointers it contains at some point. Note that no hard references to the Foo objects remain in Python.

      -

      34.5.4 Exception unrolling

      +

      35.5.4 Exception unrolling

      @@ -3077,7 +3077,7 @@ Swig::DirectorMethodException is thrown, Python will register the exception as soon as the C wrapper function returns.

      -

      34.5.5 Overhead and code bloat

      +

      35.5.5 Overhead and code bloat

      @@ -3111,7 +3111,7 @@ directive) for only those methods that are likely to be extended in Python.

      -

      34.5.6 Typemaps

      +

      35.5.6 Typemaps

      @@ -3125,7 +3125,7 @@ need to be supported.

      -

      34.5.7 Miscellaneous

      +

      35.5.7 Miscellaneous

      @@ -3172,7 +3172,7 @@ methods that return const references.

      -

      34.6 Common customization features

      +

      35.6 Common customization features

      @@ -3185,7 +3185,7 @@ This section describes some common SWIG features that are used to improve your the interface to an extension module.

      -

      34.6.1 C/C++ helper functions

      +

      35.6.1 C/C++ helper functions

      @@ -3266,7 +3266,7 @@ hard to implement. It is possible to clean this up using Python code, typemaps, customization features as covered in later sections.

      -

      34.6.2 Adding additional Python code

      +

      35.6.2 Adding additional Python code

      @@ -3494,7 +3494,7 @@ The same applies for overloaded constructors.

      -

      34.6.3 Class extension with %extend

      +

      35.6.3 Class extension with %extend

      @@ -3583,7 +3583,7 @@ Vector(12,14,16) in any way---the extensions only show up in the Python interface.

      -

      34.6.4 Exception handling with %exception

      +

      35.6.4 Exception handling with %exception

      @@ -3709,7 +3709,7 @@ The language-independent exception.i library file can also be used to raise exceptions. See the SWIG Library chapter.

      -

      34.7 Tips and techniques

      +

      35.7 Tips and techniques

      @@ -3719,7 +3719,7 @@ strings, binary data, and arrays. This chapter discusses the common techniques solving these problems.

      -

      34.7.1 Input and output parameters

      +

      35.7.1 Input and output parameters

      @@ -3932,7 +3932,7 @@ void foo(Bar *OUTPUT); may not have the intended effect since typemaps.i does not define an OUTPUT rule for Bar.

      -

      34.7.2 Simple pointers

      +

      35.7.2 Simple pointers

      @@ -4001,7 +4001,7 @@ If you replace %pointer_functions() by %pointer_class(type,name)SWIG Library chapter for further details.

      -

      34.7.3 Unbounded C Arrays

      +

      35.7.3 Unbounded C Arrays

      @@ -4063,7 +4063,7 @@ well suited for applications in which you need to create buffers, package binary data, etc.

      -

      34.7.4 String handling

      +

      35.7.4 String handling

      @@ -4132,7 +4132,7 @@ If you need to return binary data, you might use the also be used to extra binary data from arbitrary pointers.

      -

      34.8 Typemaps

      +

      35.8 Typemaps

      @@ -4149,7 +4149,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Python interface or if you want to elevate your guru status.

      -

      34.8.1 What is a typemap?

      +

      35.8.1 What is a typemap?

      @@ -4265,7 +4265,7 @@ parameter is omitted): -

      34.8.2 Python typemaps

      +

      35.8.2 Python typemaps

      @@ -4306,7 +4306,7 @@ a look at the SWIG library version 1.3.20 or so.

      -

      34.8.3 Typemap variables

      +

      35.8.3 Typemap variables

      @@ -4377,7 +4377,7 @@ properly assigned. The Python name of the wrapper function being created. -

      34.8.4 Useful Python Functions

      +

      35.8.4 Useful Python Functions

      @@ -4505,7 +4505,7 @@ write me -

      34.9 Typemap Examples

      +

      35.9 Typemap Examples

      @@ -4514,7 +4514,7 @@ might look at the files "python.swg" and "typemaps.i" in the SWIG library.

      -

      34.9.1 Converting Python list to a char **

      +

      35.9.1 Converting Python list to a char **

      @@ -4594,7 +4594,7 @@ memory allocation is used to allocate memory for the array, the the C function.

      -

      34.9.2 Expanding a Python object into multiple arguments

      +

      35.9.2 Expanding a Python object into multiple arguments

      @@ -4673,7 +4673,7 @@ to supply the argument count. This is automatically set by the typemap code. F -

      34.9.3 Using typemaps to return arguments

      +

      35.9.3 Using typemaps to return arguments

      @@ -4761,7 +4761,7 @@ function can now be used as follows: >>> -

      34.9.4 Mapping Python tuples into small arrays

      +

      35.9.4 Mapping Python tuples into small arrays

      @@ -4810,7 +4810,7 @@ array, such an approach would not be recommended for huge arrays, but for small structures, this approach works fine.

      -

      34.9.5 Mapping sequences to C arrays

      +

      35.9.5 Mapping sequences to C arrays

      @@ -4899,7 +4899,7 @@ static int convert_darray(PyObject *input, double *ptr, int size) { -

      34.9.6 Pointer handling

      +

      35.9.6 Pointer handling

      @@ -4996,7 +4996,7 @@ class object (if applicable). -

      34.10 Docstring Features

      +

      35.10 Docstring Features

      @@ -5024,7 +5024,7 @@ of your users much simpler.

      -

      34.10.1 Module docstring

      +

      35.10.1 Module docstring

      @@ -5058,7 +5058,7 @@ layout of controls on a panel, etc. to be loaded from an XML file." -

      34.10.2 %feature("autodoc")

      +

      35.10.2 %feature("autodoc")

      @@ -5086,7 +5086,7 @@ four levels for autodoc controlled by the value given to the feature, %feature("autodoc", "level"). The four values for level are covered in the following sub-sections. -

      34.10.2.1 %feature("autodoc", "0")

      +

      35.10.2.1 %feature("autodoc", "0")

      @@ -5115,7 +5115,7 @@ def function_name(*args, **kwargs): -

      34.10.2.2 %feature("autodoc", "1")

      +

      35.10.2.2 %feature("autodoc", "1")

      @@ -5140,7 +5140,7 @@ def function_name(*args, **kwargs): -

      34.10.2.3 %feature("autodoc", "2")

      +

      35.10.2.3 %feature("autodoc", "2")

      @@ -5200,7 +5200,7 @@ def function_name(*args, **kwargs): -

      34.10.2.4 %feature("autodoc", "3")

      +

      35.10.2.4 %feature("autodoc", "3")

      @@ -5225,7 +5225,7 @@ def function_name(*args, **kwargs): -

      34.10.2.5 %feature("autodoc", "docstring")

      +

      35.10.2.5 %feature("autodoc", "docstring")

      @@ -5244,7 +5244,7 @@ void GetPosition(int* OUTPUT, int* OUTPUT); -

      34.10.3 %feature("docstring")

      +

      35.10.3 %feature("docstring")

      @@ -5276,7 +5276,8 @@ with more than one line. -

      34.11 Python Packages

      +

      35.11 Python Packages

      +

      Python has concepts of modules and packages. Modules are separate units of code and may be grouped together to form a package. Packages may be nested, @@ -5333,7 +5334,8 @@ users may need to use special features such as the package option in th %module directive or import related command line options. These are explained in the following sections.

      -

      34.11.1 Setting the Python package

      +

      35.11.1 Setting the Python package

      +

      Using the package option in the %module directive allows you @@ -5386,7 +5388,8 @@ pkg1/pkg2/_foo.so # (shared library built from C/C++ code generated by SWI -

      34.11.2 Absolute and relative imports

      +

      35.11.2 Absolute and relative imports

      +

      Suppose, we have the following hierarchy of files:

      @@ -5524,7 +5527,8 @@ uses relative imports. Second case is, when one puts import directives in __init__.py to import symbols from submodules or subpackages and the submodule depends on other submodules (discussed later).

      -

      34.11.3 Enforcing absolute import semantics

      +

      35.11.3 Enforcing absolute import semantics

      +

      As you may know, there is an incompatibility in import semantics (for the import <> syntax) between Python 2 and 3. In Python 2.4 and @@ -5560,7 +5564,8 @@ from __future__ import absolute_import -

      34.11.4 Importing from __init__.py

      +

      35.11.4 Importing from __init__.py

      +

      Imports in __init__.py are handy when you want to populate a package's namespace with names imported from other modules. In SWIG based @@ -5670,7 +5675,7 @@ effect (note, that the Python 2 case also needs the -relativeimport workaround).

      -

      34.12 Python 3 Support

      +

      35.12 Python 3 Support

      @@ -5697,7 +5702,7 @@ The following are Python 3.0 new features that are currently supported by SWIG.

      -

      34.12.1 Function annotation

      +

      35.12.1 Function annotation

      @@ -5730,7 +5735,7 @@ For detailed usage of function annotation, see PEP 3107.

      -

      34.12.2 Buffer interface

      +

      35.12.2 Buffer interface

      @@ -5882,7 +5887,7 @@ modify the buffer. -

      34.12.3 Abstract base classes

      +

      35.12.3 Abstract base classes

      diff --git a/Doc/Manual/R.html b/Doc/Manual/R.html index ceea32146..ce9523ced 100644 --- a/Doc/Manual/R.html +++ b/Doc/Manual/R.html @@ -6,7 +6,7 @@ -

      35 SWIG and R

      +

      36 SWIG and R

        @@ -33,7 +33,7 @@ compile and run an R interface to QuantLib running on Mandriva Linux with gcc. The R bindings also work on Microsoft Windows using Visual C++.

        -

        35.1 Bugs

        +

        36.1 Bugs

        @@ -45,7 +45,7 @@ Currently the following features are not implemented or broken:

      • C Array wrappings
      -

      35.2 Using R and SWIG

      +

      36.2 Using R and SWIG

      @@ -119,7 +119,7 @@ Without it, inheritance of wrapped objects may fail. These two files can be loaded in any order

      -

      35.3 Precompiling large R files

      +

      36.3 Precompiling large R files

      In cases where the R file is large, one make save a lot of loading @@ -137,7 +137,7 @@ will save a large amount of loading time. -

      35.4 General policy

      +

      36.4 General policy

      @@ -146,7 +146,7 @@ wrapping over the underlying functions and rely on the R type system to provide R syntax.

      -

      35.5 Language conventions

      +

      36.5 Language conventions

      @@ -155,7 +155,7 @@ and [ are overloaded to allow for R syntax (one based indices and slices)

      -

      35.6 C++ classes

      +

      36.6 C++ classes

      @@ -167,7 +167,7 @@ keep track of the pointer object which removes the necessity for a lot of the proxy class baggage you see in other languages.

      -

      35.7 Enumerations

      +

      36.7 Enumerations

      diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index 6ff98ca23..3fc45834d 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -7,7 +7,7 @@ -

      36 SWIG and Ruby

      +

      37 SWIG and Ruby

        @@ -144,7 +144,7 @@

        This chapter describes SWIG's support of Ruby.

        -

        36.1 Preliminaries

        +

        37.1 Preliminaries

        SWIG 1.3 is known to work with Ruby versions 1.6 and later. @@ -159,7 +159,7 @@ read the "SWIG Basics" chapter. It is also assumed that the reader has a basic understanding of Ruby.

        -

        36.1.1 Running SWIG

        +

        37.1.1 Running SWIG

        To build a Ruby module, run SWIG using the -ruby @@ -183,7 +183,7 @@ if compiling a C++ extension) that contains all of the code needed to build a Ruby extension module. To finish building the module, you need to compile this file and link it with the rest of your program.

        -

        36.1.2 Getting the right header files

        +

        37.1.2 Getting the right header files

        In order to compile the wrapper code, the compiler needs the ruby.h @@ -206,7 +206,7 @@ installed, you can run Ruby to find out. For example:

      -

      36.1.3 Compiling a dynamic module

      +

      37.1.3 Compiling a dynamic module

      Ruby extension modules are typically compiled into shared @@ -279,7 +279,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.

      -

      36.1.4 Using your module

      +

      37.1.4 Using your module

      Ruby module names must be capitalized, @@ -309,7 +309,7 @@ begins with:

      will result in an extension module using the feature name "example" and Ruby module name "Example".

      -

      36.1.5 Static linking

      +

      37.1.5 Static linking

      An alternative approach to dynamic linking is to rebuild the @@ -324,7 +324,7 @@ finding the Ruby source, adding an entry to the ext/Setup file, adding your directory to the list of extensions in the file, and finally rebuilding Ruby.

      -

      36.1.6 Compilation of C++ extensions

      +

      37.1.6 Compilation of C++ extensions

      On most machines, C++ extension modules should be linked @@ -356,7 +356,7 @@ $libs = append_library($libs, "supc++") create_makefile('example')

      -

      36.2 Building Ruby Extensions under Windows 95/NT

      +

      37.2 Building Ruby Extensions under Windows 95/NT

      Building a SWIG extension to Ruby under Windows 95/NT is @@ -381,7 +381,7 @@ order to build extensions, you may need to download the source distribution to the Ruby package, as you will need the Ruby header files.

      -

      36.2.1 Running SWIG from Developer Studio

      +

      37.2.1 Running SWIG from Developer Studio

      If you are developing your application within Microsoft @@ -445,13 +445,13 @@ Foo = 3.0 -

      36.3 The Ruby-to-C/C++ Mapping

      +

      37.3 The Ruby-to-C/C++ Mapping

      This section describes the basics of how SWIG maps C or C++ declarations in your SWIG interface files to Ruby constructs.

      -

      36.3.1 Modules

      +

      37.3.1 Modules

      The SWIG %module directive specifies @@ -523,7 +523,7 @@ option to wrap everything into the global module, take care that the names of your constants, classes and methods don't conflict with any of Ruby's built-in names.

      -

      36.3.2 Functions

      +

      37.3.2 Functions

      Global functions are wrapped as Ruby module methods. For @@ -557,7 +557,7 @@ irb(main):002:0> Example.fact(4) 24 -

      36.3.3 Variable Linking

      +

      37.3.3 Variable Linking

      C/C++ global variables are wrapped as a pair of singleton @@ -619,7 +619,7 @@ directive. For example:

      effect until it is explicitly disabled using %mutable.

      -

      36.3.4 Constants

      +

      37.3.4 Constants

      C/C++ constants are wrapped as module constants initialized @@ -647,7 +647,7 @@ irb(main):002:0> Example::PI 3.14159 -

      36.3.5 Pointers

      +

      37.3.5 Pointers

      "Opaque" pointers to arbitrary C/C++ types (i.e. types that @@ -671,7 +671,7 @@ returns an instance of an internally generated Ruby class:

      A NULL pointer is always represented by the Ruby nil object.

      -

      36.3.6 Structures

      +

      37.3.6 Structures

      C/C++ structs are wrapped as Ruby classes, with accessor @@ -776,7 +776,7 @@ void Bar_f_set(Bar *b, Foo *val) { } -

      36.3.7 C++ classes

      +

      37.3.7 C++ classes

      Like structs, C++ classes are wrapped by creating a new Ruby @@ -831,7 +831,7 @@ Ale 3 -

      36.3.8 C++ Inheritance

      +

      37.3.8 C++ Inheritance

      The SWIG type-checker is fully aware of C++ inheritance. @@ -984,7 +984,7 @@ inherit from both Base1 and Base2 (i.e. they exhibit "Duck Typing").

      -

      36.3.9 C++ Overloaded Functions

      +

      37.3.9 C++ Overloaded Functions

      C++ overloaded functions, methods, and constructors are @@ -1074,7 +1074,7 @@ arises--in this case, the first declaration takes precedence.

      Please refer to the "SWIG and C++" chapter for more information about overloading.

      -

      36.3.10 C++ Operators

      +

      37.3.10 C++ Operators

      For the most part, overloaded operators are handled @@ -1116,7 +1116,7 @@ c = Example.add_complex(a, b) is discussed in the section on operator overloading.

      -

      36.3.11 C++ namespaces

      +

      37.3.11 C++ namespaces

      SWIG is aware of C++ namespaces, but namespace names do not @@ -1173,7 +1173,7 @@ and create extension modules for each namespace separately. If your program utilizes thousands of small deeply nested namespaces each with identical symbol names, well, then you get what you deserve.

      -

      36.3.12 C++ templates

      +

      37.3.12 C++ templates

      C++ templates don't present a huge problem for SWIG. However, @@ -1215,7 +1215,7 @@ irb(main):004:0> p.second 4 -

      36.3.13 C++ Standard Template Library (STL)

      +

      37.3.13 C++ Standard Template Library (STL)

      On a related note, the standard SWIG library contains a @@ -1308,7 +1308,7 @@ puts v shown in these examples. More details can be found in the SWIG and C++ chapter.

      -

      36.3.14 C++ STL Functors

      +

      37.3.14 C++ STL Functors

      Some containers in the STL allow you to modify their default @@ -1369,7 +1369,7 @@ b -

      36.3.15 C++ STL Iterators

      +

      37.3.15 C++ STL Iterators

      The STL is well known for the use of iterators. There @@ -1452,7 +1452,7 @@ i

      If you'd rather have STL classes without any iterators, you should define -DSWIG_NO_EXPORT_ITERATOR_METHODS when running swig.

      -

      36.3.16 C++ Smart Pointers

      +

      37.3.16 C++ Smart Pointers

      In certain C++ programs, it is common to use classes that @@ -1517,7 +1517,7 @@ method. For example:

      irb(main):004:0> f = p.__deref__() # Returns underlying Foo *
      -

      36.3.17 Cross-Language Polymorphism

      +

      37.3.17 Cross-Language Polymorphism

      SWIG's Ruby module supports cross-language polymorphism @@ -1526,7 +1526,7 @@ module. Rather than duplicate the information presented in the 36.3.17.1 Exception Unrolling +

      37.3.17.1 Exception Unrolling

      Whenever a C++ director class routes one of its virtual @@ -1549,7 +1549,7 @@ method is "wrapped" using the rb_rescue2() function from Ruby's C API. If any Ruby exception is raised, it will be caught here and a C++ exception is raised in its place.

      -

      36.4 Naming

      +

      37.4 Naming

      Ruby has several common naming conventions. Constants are @@ -1587,7 +1587,7 @@ generated by SWIG, it is turned off by default in SWIG 1.3.28. However, it is planned to become the default option in future releases.

      -

      36.4.1 Defining Aliases

      +

      37.4.1 Defining Aliases

      It's a fairly common practice in the Ruby built-ins and @@ -1657,7 +1657,7 @@ matching rules used for other kinds of features apply (see the chapter on "Customization Features") for more details).

      -

      36.4.2 Predicate Methods

      +

      37.4.2 Predicate Methods

      Ruby methods that return a boolean value and end in a @@ -1706,7 +1706,7 @@ using SWIG's "features" mechanism and so the same name matching rules used for other kinds of features apply (see the chapter on "Customization Features") for more details).

      -

      36.4.3 Bang Methods

      +

      37.4.3 Bang Methods

      Ruby methods that modify an object in-place and end in an @@ -1738,7 +1738,7 @@ using SWIG's "features" mechanism and so the same name matching rules used for other kinds of features apply (see the chapter on "Customization Features") for more details).

      -

      36.4.4 Getters and Setters

      +

      37.4.4 Getters and Setters

      Often times a C++ library will expose properties through @@ -1773,7 +1773,7 @@ irb(main):003:0> puts foo.value %rename("value=") Foo::setValue(int value); -

      36.5 Input and output parameters

      +

      37.5 Input and output parameters

      A common problem in some C programs is handling parameters @@ -1912,10 +1912,10 @@ void get_dimensions(Matrix *m, int *rows, int*columns);

      r, c = Example.get_dimensions(m)
      -

      36.6 Exception handling

      +

      37.6 Exception handling

      -

      36.6.1 Using the %exception directive

      +

      37.6.1 Using the %exception directive

      The SWIG %exception directive can be @@ -2024,7 +2024,7 @@ methods and functions named getitem and setitem. limited to C++ exception handling. See the chapter on Customization Features for more examples.

      -

      36.6.2 Handling Ruby Blocks

      +

      37.6.2 Handling Ruby Blocks

      One of the highlights of Ruby and most of its standard library @@ -2091,7 +2091,7 @@ a special in typemap, like:

      For more information on typemaps, see Typemaps.

      -

      36.6.3 Raising exceptions

      +

      37.6.3 Raising exceptions

      There are three ways to raise exceptions from C++ code to @@ -2248,7 +2248,7 @@ function. The first argument passed to rb_raise() is the exception type. You can raise a custom exception type or one of the built-in Ruby exception types.

      -

      36.6.4 Exception classes

      +

      37.6.4 Exception classes

      Starting with SWIG 1.3.28, the Ruby module supports the %exceptionclass @@ -2285,7 +2285,7 @@ end

      For another example look at swig/Examples/ruby/exception_class.

      -

      36.7 Typemaps

      +

      37.7 Typemaps

      This section describes how you can modify SWIG's default @@ -2300,7 +2300,7 @@ a required part of using SWIG---the default wrapping behavior is enough in most cases. Typemaps are only used if you want to change some aspect of the primitive C-Ruby interface.

      -

      36.7.1 What is a typemap?

      +

      37.7.1 What is a typemap?

      A typemap is nothing more than a code generation rule that is @@ -2457,7 +2457,7 @@ to be used as follows (notice how the length parameter is omitted):

      2 -

      36.7.2 Typemap scope

      +

      37.7.2 Typemap scope

      Once defined, a typemap remains in effect for all of the @@ -2503,7 +2503,7 @@ where the class itself is defined. For example:

      }; -

      36.7.3 Copying a typemap

      +

      37.7.3 Copying a typemap

      A typemap is copied by using assignment. For example:

      @@ -2545,7 +2545,7 @@ rules as for %apply (char *buf, int len) { (char *buffer, int size) }; // Multiple arguments -

      36.7.4 Deleting a typemap

      +

      37.7.4 Deleting a typemap

      A typemap can be deleted by simply defining no code. For @@ -2570,7 +2570,7 @@ defined by typemaps, clearing a fundamental type like int will make that type unusable unless you also define a new set of typemaps immediately after the clear operation.

      -

      36.7.5 Placement of typemaps

      +

      37.7.5 Placement of typemaps

      Typemap declarations can be declared in the global scope, @@ -2641,13 +2641,13 @@ In this example, this is done using the class declaration class string .

      -

      36.7.6 Ruby typemaps

      +

      37.7.6 Ruby typemaps

      The following list details all of the typemap methods that can be used by the Ruby module:

      -

      36.7.6.1 "in" typemap

      +

      37.7.6.1 "in" typemap

      Converts Ruby objects to input @@ -2714,7 +2714,7 @@ arguments to be specified. For example:

      At this time, only zero or one arguments may be converted.

      -

      36.7.6.2 "typecheck" typemap

      +

      37.7.6.2 "typecheck" typemap

      The "typecheck" typemap is used to support overloaded @@ -2736,7 +2736,7 @@ program uses overloaded methods, you should also define a collection of "typecheck" typemaps. More details about this follow in a later section on "Typemaps and Overloading."

      -

      36.7.6.3 "out" typemap

      +

      37.7.6.3 "out" typemap

      Converts return value of a C function @@ -2787,7 +2787,7 @@ version of the C datatype matched by the typemap.

      -

      36.7.6.4 "arginit" typemap

      +

      37.7.6.4 "arginit" typemap

      The "arginit" typemap is used to set the initial value of a @@ -2802,7 +2802,7 @@ applications. For example:

      } -

      36.7.6.5 "default" typemap

      +

      37.7.6.5 "default" typemap

      The "default" typemap is used to turn an argument into a @@ -2827,7 +2827,7 @@ arguments that follow must have default values. See the 36.7.6.6 "check" typemap +

      37.7.6.6 "check" typemap

      The "check" typemap is used to supply value checking code @@ -2842,7 +2842,7 @@ arguments have been converted. For example:

      } -

      36.7.6.7 "argout" typemap

      +

      37.7.6.7 "argout" typemap

      The "argout" typemap is used to return values from arguments. @@ -2896,7 +2896,7 @@ some function like SWIG_Ruby_AppendOutput.

      See the typemaps.i library for examples.

      -

      36.7.6.8 "freearg" typemap

      +

      37.7.6.8 "freearg" typemap

      The "freearg" typemap is used to cleanup argument data. It is @@ -2923,7 +2923,7 @@ This code is also placed into a special variable $cleanup that may be used in other typemaps whenever a wrapper function needs to abort prematurely.

      -

      36.7.6.9 "newfree" typemap

      +

      37.7.6.9 "newfree" typemap

      The "newfree" typemap is used in conjunction with the %newobject @@ -2947,7 +2947,7 @@ string *foo();

      See Object ownership and %newobject for further details.

      -

      36.7.6.10 "memberin" typemap

      +

      37.7.6.10 "memberin" typemap

      The "memberin" typemap is used to copy data from an @@ -2965,21 +2965,21 @@ example:

      already provides a default implementation for arrays, strings, and other objects.

      -

      36.7.6.11 "varin" typemap

      +

      37.7.6.11 "varin" typemap

      The "varin" typemap is used to convert objects in the target language to C for the purposes of assigning to a C/C++ global variable. This is implementation specific.

      -

      36.7.6.12 "varout" typemap

      +

      37.7.6.12 "varout" typemap

      The "varout" typemap is used to convert a C/C++ object to an object in the target language when reading a C/C++ global variable. This is implementation specific.

      -

      36.7.6.13 "throws" typemap

      +

      37.7.6.13 "throws" typemap

      The "throws" typemap is only used when SWIG parses a C++ @@ -3020,7 +3020,7 @@ specification yet they do throw exceptions, SWIG cannot know how to deal with them. For a neat way to handle these, see the Exception handling with %exception section.

      -

      36.7.6.14 directorin typemap

      +

      37.7.6.14 directorin typemap

      Converts C++ objects in director @@ -3079,7 +3079,7 @@ referring to the class itself. -

      36.7.6.15 directorout typemap

      +

      37.7.6.15 directorout typemap

      Converts Ruby objects in director @@ -3152,7 +3152,7 @@ exception.

      -

      36.7.6.16 directorargout typemap

      +

      37.7.6.16 directorargout typemap

      Output argument processing in director @@ -3210,19 +3210,19 @@ referring to the instance of the class itself -

      36.7.6.17 ret typemap

      +

      37.7.6.17 ret typemap

      Cleanup of function return values

      -

      36.7.6.18 globalin typemap

      +

      37.7.6.18 globalin typemap

      Setting of C global variables

      -

      36.7.7 Typemap variables

      +

      37.7.7 Typemap variables

      @@ -3272,7 +3272,7 @@ so that their values can be properly assigned.

      The Ruby name of the wrapper function being created.
      -

      36.7.8 Useful Functions

      +

      37.7.8 Useful Functions

      When you write a typemap, you usually have to work directly @@ -3287,7 +3287,7 @@ stick to the swig functions instead of the native Ruby functions. That should help you avoid having to rewrite a lot of typemaps across multiple languages.

      -

      36.7.8.1 C Datatypes to Ruby Objects

      +

      37.7.8.1 C Datatypes to Ruby Objects

      @@ -3329,7 +3329,7 @@ SWIG_From_float(float)
      -

      36.7.8.2 Ruby Objects to C Datatypes

      +

      37.7.8.2 Ruby Objects to C Datatypes

      Here, while the Ruby versions return the value directly, the SWIG @@ -3397,7 +3397,7 @@ versions do not, but return a status value to indicate success (SWIG_OK -

      36.7.8.3 Macros for VALUE

      +

      37.7.8.3 Macros for VALUE

      RSTRING_LEN(str)

      @@ -3420,7 +3420,7 @@ versions do not, but return a status value to indicate success (SWIG_OK
      pointer to array storage
      -

      36.7.8.4 Exceptions

      +

      37.7.8.4 Exceptions

      void rb_raise(VALUE exception, const char *fmt, @@ -3499,7 +3499,7 @@ message to standard error if Ruby was invoked with the -w flag. The given format string fmt and remaining arguments are interpreted as with printf(). -

      36.7.8.5 Iterators

      +

      37.7.8.5 Iterators

      void rb_iter_break()

      @@ -3545,14 +3545,14 @@ VALUE), VALUE value)

      Equivalent to Ruby's throw.
      -

      36.7.9 Typemap Examples

      +

      37.7.9 Typemap Examples

      This section includes a few examples of typemaps. For more examples, you might look at the examples in the Example/ruby directory.

      -

      36.7.10 Converting a Ruby array to a char **

      +

      37.7.10 Converting a Ruby array to a char **

      A common problem in many C programs is the processing of @@ -3617,7 +3617,7 @@ array. Since dynamic memory allocation is used to allocate memory for the array, the "freearg" typemap is used to later release this memory after the execution of the C function.

      -

      36.7.11 Collecting arguments in a hash

      +

      37.7.11 Collecting arguments in a hash

      Ruby's solution to the "keyword arguments" capability of some @@ -3831,7 +3831,7 @@ memory leak. Fortunately, this typemap is a lot easier to write:

      program that uses the extension, can be found in the Examples/ruby/hashargs directory of the SWIG distribution.

      -

      36.7.12 Pointer handling

      +

      37.7.12 Pointer handling

      Occasionally, it might be necessary to convert pointer values @@ -3890,7 +3890,7 @@ For example:

      } -

      36.7.12.1 Ruby Datatype Wrapping

      +

      37.7.12.1 Ruby Datatype Wrapping

      VALUE Data_Wrap_Struct(VALUE class, void @@ -3917,7 +3917,7 @@ as above. type c-type from the data object obj and assigns that pointer to ptr. -

      36.7.13 Example: STL Vector to Ruby Array

      +

      37.7.13 Example: STL Vector to Ruby Array

      Another use for macros and type maps is to create a Ruby array @@ -4009,7 +4009,7 @@ STL with ruby, you are advised to use the standard swig STL library, which does much more than this. Refer to the section called the C++ Standard Template Library. -

      36.8 Docstring Features

      +

      37.8 Docstring Features

      @@ -4043,7 +4043,7 @@ generate ri documentation from a c wrap file, you could do:

      $ rdoc -r file_wrap.c -

      36.8.1 Module docstring

      +

      37.8.1 Module docstring

      @@ -4073,7 +4073,7 @@ layout of controls on a panel, etc. to be loaded from an XML file." %module(docstring=DOCSTRING) xrc -

      36.8.2 %feature("autodoc")

      +

      37.8.2 %feature("autodoc")

      Since SWIG does know everything about the function it wraps, @@ -4094,7 +4094,7 @@ several options for autodoc controlled by the value given to the feature, described below.

      -

      36.8.2.1 %feature("autodoc", "0")

      +

      37.8.2.1 %feature("autodoc", "0")

      @@ -4118,7 +4118,7 @@ Then Ruby code like this will be generated: ... -

      36.8.2.2 %feature("autodoc", "1")

      +

      37.8.2.2 %feature("autodoc", "1")

      @@ -4138,7 +4138,7 @@ this: ... -

      36.8.2.3 %feature("autodoc", "2")

      +

      37.8.2.3 %feature("autodoc", "2")

      @@ -4150,7 +4150,7 @@ parameter types with the "2" option will result in Ruby code like this:

      -

      36.8.2.4 %feature("autodoc", "3")

      +

      37.8.2.4 %feature("autodoc", "3")

      @@ -4171,7 +4171,7 @@ Parameters: bar - Bar -

      36.8.2.5 %feature("autodoc", "docstring")

      +

      37.8.2.5 %feature("autodoc", "docstring")

      @@ -4187,7 +4187,7 @@ generated string. For example: void GetPosition(int* OUTPUT, int* OUTPUT); -

      36.8.3 %feature("docstring")

      +

      37.8.3 %feature("docstring")

      @@ -4198,10 +4198,10 @@ docstring associated with classes, function or methods are output. If an item already has an autodoc string then it is combined with the docstring and they are output together.

      -

      36.9 Advanced Topics

      +

      37.9 Advanced Topics

      -

      36.9.1 Operator overloading

      +

      37.9.1 Operator overloading

      SWIG allows operator overloading with, by using the %extend @@ -4382,7 +4382,7 @@ separate method for handling inequality since Ruby parses the expression a != b as !(a == b).

      -

      36.9.2 Creating Multi-Module Packages

      +

      37.9.2 Creating Multi-Module Packages

      The chapter on Working @@ -4508,7 +4508,7 @@ irb(main):005:0> c.getX() 5.0 -

      36.9.3 Specifying Mixin Modules

      +

      37.9.3 Specifying Mixin Modules

      The Ruby language doesn't support multiple inheritance, but @@ -4575,7 +4575,7 @@ matching rules used for other kinds of features apply (see the chapter on "Customization Features") for more details).

      -

      36.10 Memory Management

      +

      37.10 Memory Management

      One of the most common issues in generating SWIG bindings for @@ -4598,7 +4598,7 @@ to C++ (or vice versa) depending on what function or methods are invoked. Clearly, developing a SWIG wrapper requires a thorough understanding of how the underlying library manages memory.

      -

      36.10.1 Mark and Sweep Garbage Collector

      +

      37.10.1 Mark and Sweep Garbage Collector

      Ruby uses a mark and sweep garbage collector. When the garbage @@ -4630,7 +4630,7 @@ any memory has been allocated in creating the underlying C struct or C++ struct, then a "free" function must be defined that deallocates this memory.

      -

      36.10.2 Object Ownership

      +

      37.10.2 Object Ownership

      As described above, memory management depends on clearly @@ -4775,7 +4775,7 @@ public:

      This code can be seen in swig/examples/ruby/tracking.

      -

      36.10.3 Object Tracking

      +

      37.10.3 Object Tracking

      The remaining parts of this section will use the class library @@ -5000,7 +5000,7 @@ However, if you implement your own free functions (see below) you may also have to call the SWIG_RubyRemoveTracking and RubyUnlinkObjects methods.

      -

      36.10.4 Mark Functions

      +

      37.10.4 Mark Functions

      With a bit more testing, we see that our class library still @@ -5129,7 +5129,7 @@ irb(main):016:0>

      This code can be seen in swig/examples/ruby/mark_function.

      -

      36.10.5 Free Functions

      +

      37.10.5 Free Functions

      By default, SWIG creates a "free" function that is called when @@ -5296,7 +5296,7 @@ been freed, and thus raises a runtime exception.

      This code can be seen in swig/examples/ruby/free_function.

      -

      36.10.6 Embedded Ruby and the C++ Stack

      +

      37.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/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index aa02b2dee..f9558994b 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -4972,6 +4972,7 @@ public:

      6.27 Nested classes

      +

      If the target language supports the nested classes concept (like Java), the nested C++ classes are wrapped as nested target language proxy classes. (In case of Java - "static" nested classes.) diff --git a/Doc/Manual/Tcl.html b/Doc/Manual/Tcl.html index 9b9cd7218..45eebbf5e 100644 --- a/Doc/Manual/Tcl.html +++ b/Doc/Manual/Tcl.html @@ -6,7 +6,7 @@ -

      37 SWIG and Tcl

      +

      38 SWIG and Tcl

        @@ -83,7 +83,7 @@ Tcl 8.0 or a later release. Earlier releases of SWIG supported Tcl 7.x, but this is no longer supported.

        -

        37.1 Preliminaries

        +

        38.1 Preliminaries

        @@ -109,7 +109,7 @@ build a Tcl extension module. To finish building the module, you need to compile this file and link it with the rest of your program.

        -

        37.1.1 Getting the right header files

        +

        38.1.1 Getting the right header files

        @@ -127,7 +127,7 @@ this is the case, you should probably make a symbolic link so that tcl.h -

        37.1.2 Compiling a dynamic module

        +

        38.1.2 Compiling a dynamic module

        @@ -163,7 +163,7 @@ The name of the module is specified using the %module directive or the -module command line option.

        -

        37.1.3 Static linking

        +

        38.1.3 Static linking

        @@ -229,7 +229,7 @@ minimal in most situations (and quite frankly not worth the extra hassle in the opinion of this author).

        -

        37.1.4 Using your module

        +

        38.1.4 Using your module

        @@ -357,7 +357,7 @@ to the default system configuration (this requires root access and you will need the man pages).

        -

        37.1.5 Compilation of C++ extensions

        +

        38.1.5 Compilation of C++ extensions

        @@ -440,7 +440,7 @@ erratic program behavior. If working with lots of software components, you might want to investigate using a more formal standard such as COM.

        -

        37.1.6 Compiling for 64-bit platforms

        +

        38.1.6 Compiling for 64-bit platforms

        @@ -467,7 +467,7 @@ also introduce problems on platforms that support more than one linking standard (e.g., -o32 and -n32 on Irix).

        -

        37.1.7 Setting a package prefix

        +

        38.1.7 Setting a package prefix

        @@ -486,7 +486,7 @@ option will append the prefix to the name when creating a command and call it "Foo_bar".

        -

        37.1.8 Using namespaces

        +

        38.1.8 Using namespaces

        @@ -508,7 +508,7 @@ When the -namespace option is used, objects in the module are always accessed with the namespace name such as Foo::bar.

        -

        37.2 Building Tcl/Tk Extensions under Windows 95/NT

        +

        38.2 Building Tcl/Tk Extensions under Windows 95/NT

        @@ -519,7 +519,7 @@ covers the process of using SWIG with Microsoft Visual C++. although the procedure may be similar with other compilers.

        -

        37.2.1 Running SWIG from Developer Studio

        +

        38.2.1 Running SWIG from Developer Studio

        @@ -577,7 +577,7 @@ MSDOS > tclsh80 %

      -

      37.2.2 Using NMAKE

      +

      38.2.2 Using NMAKE

      @@ -640,7 +640,7 @@ to get you started. With a little practice, you'll be making lots of Tcl extensions.

      -

      37.3 A tour of basic C/C++ wrapping

      +

      38.3 A tour of basic C/C++ wrapping

      @@ -651,7 +651,7 @@ classes. This section briefly covers the essential aspects of this wrapping.

      -

      37.3.1 Modules

      +

      38.3.1 Modules

      @@ -685,7 +685,7 @@ To fix this, supply an extra argument to load like this: -

      37.3.2 Functions

      +

      38.3.2 Functions

      @@ -710,7 +710,7 @@ like you think it does: % -

      37.3.3 Global variables

      +

      38.3.3 Global variables

      @@ -790,7 +790,7 @@ extern char *path; // Read-only (due to %immutable) -

      37.3.4 Constants and enums

      +

      38.3.4 Constants and enums

      @@ -874,7 +874,7 @@ When an identifier name is given, it is used to perform an implicit hash-table l conversion. This allows the global statement to be omitted.

      -

      37.3.5 Pointers

      +

      38.3.5 Pointers

      @@ -970,7 +970,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return None if the conversion can't be performed.

      -

      37.3.6 Structures

      +

      38.3.6 Structures

      @@ -1252,7 +1252,7 @@ Note: Tcl only destroys the underlying object if it has ownership. See the memory management section that appears shortly.

      -

      37.3.7 C++ classes

      +

      38.3.7 C++ classes

      @@ -1319,7 +1319,7 @@ In Tcl, the static member is accessed as follows: -

      37.3.8 C++ inheritance

      +

      38.3.8 C++ inheritance

      @@ -1368,7 +1368,7 @@ For instance: It is safe to use multiple inheritance with SWIG.

      -

      37.3.9 Pointers, references, values, and arrays

      +

      38.3.9 Pointers, references, values, and arrays

      @@ -1422,7 +1422,7 @@ to hold the result and a pointer is returned (Tcl will release this memory when the return value is garbage collected).

      -

      37.3.10 C++ overloaded functions

      +

      38.3.10 C++ overloaded functions

      @@ -1545,7 +1545,7 @@ first declaration takes precedence. Please refer to the "SWIG and C++" chapter for more information about overloading.

      -

      37.3.11 C++ operators

      +

      38.3.11 C++ operators

      @@ -1647,7 +1647,7 @@ There are ways to make this operator appear as part of the class using the % Keep reading.

      -

      37.3.12 C++ namespaces

      +

      38.3.12 C++ namespaces

      @@ -1711,7 +1711,7 @@ utilizes thousands of small deeply nested namespaces each with identical symbol names, well, then you get what you deserve.

      -

      37.3.13 C++ templates

      +

      38.3.13 C++ templates

      @@ -1763,7 +1763,7 @@ More details can be found in the SWIG and C++ -

      37.3.14 C++ Smart Pointers

      +

      38.3.14 C++ Smart Pointers

      @@ -1847,7 +1847,7 @@ simply use the __deref__() method. For example: -

      37.4 Further details on the Tcl class interface

      +

      38.4 Further details on the Tcl class interface

      @@ -1860,7 +1860,7 @@ of low-level details were omitted. This section provides a brief overview of how the proxy classes work.

      -

      37.4.1 Proxy classes

      +

      38.4.1 Proxy classes

      @@ -1925,7 +1925,7 @@ function. This allows objects to be encapsulated objects that look a lot like as shown in the last section.

      -

      37.4.2 Memory management

      +

      38.4.2 Memory management

      @@ -2113,7 +2113,7 @@ typemaps--an advanced topic discussed later.

      -

      37.5 Input and output parameters

      +

      38.5 Input and output parameters

      @@ -2301,7 +2301,7 @@ set c [lindex $dim 1] -

      37.6 Exception handling

      +

      38.6 Exception handling

      @@ -2435,7 +2435,7 @@ Since SWIG's exception handling is user-definable, you are not limited to C++ ex See the chapter on "Customization Features" for more examples.

      -

      37.7 Typemaps

      +

      38.7 Typemaps

      @@ -2452,7 +2452,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Tcl interface.

      -

      37.7.1 What is a typemap?

      +

      38.7.1 What is a typemap?

      @@ -2569,7 +2569,7 @@ parameter is omitted): -

      37.7.2 Tcl typemaps

      +

      38.7.2 Tcl typemaps

      @@ -2707,7 +2707,7 @@ Initialize an argument to a value before any conversions occur. Examples of these methods will appear shortly.

      -

      37.7.3 Typemap variables

      +

      38.7.3 Typemap variables

      @@ -2778,7 +2778,7 @@ properly assigned. The Tcl name of the wrapper function being created. -

      37.7.4 Converting a Tcl list to a char **

      +

      38.7.4 Converting a Tcl list to a char **

      @@ -2840,7 +2840,7 @@ argv[2] = Larry 3 -

      37.7.5 Returning values in arguments

      +

      38.7.5 Returning values in arguments

      @@ -2882,7 +2882,7 @@ result, a Tcl function using these typemaps will work like this : % -

      37.7.6 Useful functions

      +

      38.7.6 Useful functions

      @@ -2959,7 +2959,7 @@ int Tcl_IsShared(Tcl_Obj *obj); -

      37.7.7 Standard typemaps

      +

      38.7.7 Standard typemaps

      @@ -3043,7 +3043,7 @@ work) -

      37.7.8 Pointer handling

      +

      38.7.8 Pointer handling

      @@ -3119,7 +3119,7 @@ For example: -

      37.8 Turning a SWIG module into a Tcl Package.

      +

      38.8 Turning a SWIG module into a Tcl Package.

      @@ -3191,7 +3191,7 @@ As a final note, most SWIG examples do not yet use the to use the load command instead.

      -

      37.9 Building new kinds of Tcl interfaces (in Tcl)

      +

      38.9 Building new kinds of Tcl interfaces (in Tcl)

      @@ -3290,7 +3290,7 @@ danger of blowing something up (although it is easily accomplished with an out of bounds array access).

      -

      37.9.1 Proxy classes

      +

      38.9.1 Proxy classes

      @@ -3411,7 +3411,7 @@ short, but clever Tcl script can be combined with SWIG to do many interesting things.

      -

      37.10 Tcl/Tk Stubs

      +

      38.10 Tcl/Tk Stubs

      diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index 20ad085f8..cba524149 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -6,7 +6,7 @@ -

      10 Typemaps

      +

      11 Typemaps

        @@ -95,7 +95,7 @@ -

        10.1 Introduction

        +

        11.1 Introduction

        @@ -112,7 +112,7 @@ to re-read the earlier chapters if you have found your way to this chapter with only a vague idea of what SWIG already does by default.

        -

        10.1.1 Type conversion

        +

        11.1.1 Type conversion

        @@ -205,7 +205,7 @@ to read the extension documentation for your favorite language to know how it works (an exercise left to the reader).

        -

        10.1.2 Typemaps

        +

        11.1.2 Typemaps

        @@ -306,7 +306,7 @@ parts of the generated wrapper functions. Because arbitrary code can be insert possible to completely change the way in which values are converted.

        -

        10.1.3 Pattern matching

        +

        11.1.3 Pattern matching

        @@ -408,7 +408,7 @@ In this case, a single input object is expanded into a pair of C arguments. Thi provides a hint to the unusual variable naming scheme involving $1, $2, and so forth.

        -

        10.1.4 Reusing typemaps

        +

        11.1.4 Reusing typemaps

        @@ -464,7 +464,7 @@ typedef int size_t; then SWIG already knows that the int typemaps apply. You don't have to do anything.

        -

        10.1.5 What can be done with typemaps?

        +

        11.1.5 What can be done with typemaps?

        @@ -576,7 +576,7 @@ typemaps that expand upon this list. For example, the Java module defines a var aspects of the Java bindings. Consult language specific documentation for further details.

        -

        10.1.6 What can't be done with typemaps?

        +

        11.1.6 What can't be done with typemaps?

        @@ -639,7 +639,7 @@ void wrap_foo(char *s, int x) {

      -

      10.1.7 Similarities to Aspect Oriented Programming

      +

      11.1.7 Similarities to Aspect Oriented Programming

      @@ -657,7 +657,7 @@ SWIG can also be viewed as has having a second set of aspects based around %exception are also cross-cutting concerns as they encapsulate code that can be used to add logging or exception handling to any function.

      -

      10.1.8 The rest of this chapter

      +

      11.1.8 The rest of this chapter

      @@ -677,14 +677,14 @@ of "The C Programming Language" by Kernighan and Ritchie or "The C++ Programming Language" by Stroustrup before going any further.

      -

      10.2 Typemap specifications

      +

      11.2 Typemap specifications

      This section describes the behavior of the %typemap directive itself.

      -

      10.2.1 Defining a typemap

      +

      11.2.1 Defining a typemap

      @@ -797,7 +797,7 @@ Admittedly, it's not the most readable syntax at first glance. However, the pur individual pieces will become clear.

      -

      10.2.2 Typemap scope

      +

      11.2.2 Typemap scope

      @@ -847,7 +847,7 @@ class Foo { -

      10.2.3 Copying a typemap

      +

      11.2.3 Copying a typemap

      @@ -905,7 +905,7 @@ The patterns for %apply follow the same rules as for %typemap. -

      10.2.4 Deleting a typemap

      +

      11.2.4 Deleting a typemap

      @@ -938,7 +938,7 @@ For example: after the clear operation.

      -

      10.2.5 Placement of typemaps

      +

      11.2.5 Placement of typemaps

      @@ -1018,7 +1018,7 @@ It should be noted that for scoping to work, SWIG has to know that stringclass string.

      -

      10.3 Pattern matching rules

      +

      11.3 Pattern matching rules

      @@ -1026,7 +1026,7 @@ The section describes the pattern matching rules by which C/C++ datatypes are as The matching rules can be observed in practice by using the debugging options also described.

      -

      10.3.1 Basic matching rules

      +

      11.3.1 Basic matching rules

      @@ -1125,7 +1125,7 @@ void F(int x[1000]); // int [ANY] rule (typemap 5) stripped all qualifiers in one step.

      -

      10.3.2 Typedef reductions matching

      +

      11.3.2 Typedef reductions matching

      @@ -1300,7 +1300,7 @@ void go(Struct aStruct); -

      10.3.3 Default typemap matching rules

      +

      11.3.3 Default typemap matching rules

      @@ -1438,7 +1438,7 @@ Finally the best way to view the typemap matching rules in action is via the -

      10.3.4 Multi-arguments typemaps

      +

      11.3.4 Multi-arguments typemaps

      @@ -1468,7 +1468,7 @@ but all subsequent arguments must match exactly.

      -

      10.3.5 Matching rules compared to C++ templates

      +

      11.3.5 Matching rules compared to C++ templates

      @@ -1627,7 +1627,7 @@ are similar to those for specialized template handling.

      -

      10.3.6 Debugging typemap pattern matching

      +

      11.3.6 Debugging typemap pattern matching

      @@ -1840,7 +1840,7 @@ Also the types may be displayed slightly differently - char const * and

    -

    10.4 Code generation rules

    +

    11.4 Code generation rules

    @@ -1848,7 +1848,7 @@ This section describes rules by which typemap code is inserted into the generated wrapper code.

    -

    10.4.1 Scope

    +

    11.4.1 Scope

    @@ -1926,7 +1926,7 @@ a block scope when it is emitted. This sometimes results in a less complicated Note that only the third of the three typemaps have the typemap code passed through the SWIG preprocessor.

    -

    10.4.2 Declaring new local variables

    +

    11.4.2 Declaring new local variables

    @@ -2077,7 +2077,7 @@ each type must have its own local variable declaration. -

    10.4.3 Special variables

    +

    11.4.3 Special variables

    @@ -2329,7 +2329,7 @@ Another approach, which only works for arrays is to use the $1_basetype -

    10.4.4 Special variable macros

    +

    11.4.4 Special variable macros

    @@ -2341,7 +2341,7 @@ it is done during the SWIG parsing/compilation stages. The following special variable macros are available across all language modules.

    -

    10.4.4.1 $descriptor(type)

    +

    11.4.4.1 $descriptor(type)

    @@ -2352,7 +2352,7 @@ For example, $descriptor(std::vector<int> *) will expand into Run-time type checker usage section.

    -

    10.4.4.2 $typemap(method, typepattern)

    +

    11.4.4.2 $typemap(method, typepattern)

    @@ -2409,7 +2409,7 @@ The result is the following expansion -

    10.5 Common typemap methods

    +

    11.5 Common typemap methods

    @@ -2417,7 +2417,7 @@ The set of typemaps recognized by a language module may vary. However, the following typemap methods are nearly universal:

    -

    10.5.1 "in" typemap

    +

    11.5.1 "in" typemap

    @@ -2477,7 +2477,7 @@ Usually numinputs is not specified, whereupon the default value is 1, t is the same as the old "ignore" typemap.

    -

    10.5.2 "typecheck" typemap

    +

    11.5.2 "typecheck" typemap

    @@ -2503,7 +2503,7 @@ If you define new "in" typemaps and your program uses overloaded method "typecheck" typemaps. More details about this follow in the Typemaps and overloading section.

    -

    10.5.3 "out" typemap

    +

    11.5.3 "out" typemap

    @@ -2534,7 +2534,7 @@ $symname - Name of function/method being wrapped The "out" typemap supports an optional attribute flag called "optimal". This is for code optimisation and is detailed in the Optimal code generation when returning by value section.

    -

    10.5.4 "arginit" typemap

    +

    11.5.4 "arginit" typemap

    @@ -2553,7 +2553,7 @@ For example: -

    10.5.5 "default" typemap

    +

    11.5.5 "default" typemap

    @@ -2586,7 +2586,7 @@ See the Default/optional arguments sec for further information on default argument wrapping.

    -

    10.5.6 "check" typemap

    +

    11.5.6 "check" typemap

    @@ -2605,7 +2605,7 @@ converted. For example: -

    10.5.7 "argout" typemap

    +

    11.5.7 "argout" typemap

    @@ -2651,7 +2651,7 @@ return values are often appended to return value of the function. See the typemaps.i library file for examples.

    -

    10.5.8 "freearg" typemap

    +

    11.5.8 "freearg" typemap

    @@ -2684,7 +2684,7 @@ be used in other typemaps whenever a wrapper function needs to abort prematurely.

    -

    10.5.9 "newfree" typemap

    +

    11.5.9 "newfree" typemap

    @@ -2713,7 +2713,7 @@ string *foo(); See Object ownership and %newobject for further details.

    -

    10.5.10 "memberin" typemap

    +

    11.5.10 "memberin" typemap

    @@ -2735,7 +2735,7 @@ It is rarely necessary to write "memberin" typemaps---SWIG already provides a default implementation for arrays, strings, and other objects.

    -

    10.5.11 "varin" typemap

    +

    11.5.11 "varin" typemap

    @@ -2743,7 +2743,7 @@ The "varin" typemap is used to convert objects in the target language to C for t purposes of assigning to a C/C++ global variable. This is implementation specific.

    -

    10.5.12 "varout" typemap

    +

    11.5.12 "varout" typemap

    @@ -2751,7 +2751,7 @@ The "varout" typemap is used to convert a C/C++ object to an object in the targe language when reading a C/C++ global variable. This is implementation specific.

    -

    10.5.13 "throws" typemap

    +

    11.5.13 "throws" typemap

    @@ -2797,7 +2797,7 @@ Note that if your methods do not have an exception specification yet they do thr For a neat way to handle these, see the Exception handling with %exception section.

    -

    10.6 Some typemap examples

    +

    11.6 Some typemap examples

    @@ -2805,7 +2805,7 @@ This section contains a few examples. Consult language module documentation for more examples.

    -

    10.6.1 Typemaps for arrays

    +

    11.6.1 Typemaps for arrays

    @@ -3064,7 +3064,7 @@ Now, you will find that member access is quite nice: useless and has since been eliminated. To return structure members, simply use the "out" typemap.

    -

    10.6.2 Implementing constraints with typemaps

    +

    11.6.2 Implementing constraints with typemaps

    @@ -3112,7 +3112,7 @@ a NULL pointer. As a result, SWIG can often prevent a potential segmentation faults or other run-time problems by raising an exception rather than blindly passing values to the underlying C/C++ program.

    -

    10.7 Typemaps for multiple target languages

    +

    11.7 Typemaps for multiple target languages

    @@ -3142,7 +3142,7 @@ The example above also shows a common approach of issuing a warning for an as ye %typemap(ruby,in) int "$1 = NUM2INT($input);".

    -

    10.8 Optimal code generation when returning by value

    +

    11.8 Optimal code generation when returning by value

    @@ -3331,7 +3331,7 @@ example.i:7: Warning 475: optimal attribute usage in the out typemap. However, it doesn't always get it right, for example when $1 is within some commented out code.

    -

    10.9 Multi-argument typemaps

    +

    11.9 Multi-argument typemaps

    @@ -3598,7 +3598,7 @@ with non-consecutive C/C++ arguments; a workaround such as a helper function re- the arguments to make them consecutive will need to be written.

    -

    10.10 Typemap warnings

    +

    11.10 Typemap warnings

    @@ -3607,7 +3607,7 @@ See the information in the issuing warnings

    -

    10.11 Typemap fragments

    +

    11.11 Typemap fragments

    @@ -3860,7 +3860,7 @@ fragment usage unless a desire to really get to grips with some powerful but tricky macro and fragment usage that is used in parts of the SWIG typemap library.

    -

    10.11.1 Fragment type specialization

    +

    11.11.1 Fragment type specialization

    @@ -3893,7 +3893,7 @@ struct A { -

    10.11.2 Fragments and automatic typemap specialization

    +

    11.11.2 Fragments and automatic typemap specialization

    @@ -3939,7 +3939,7 @@ The interested (or very brave) reader can take a look at the fragments.swg file

    -

    10.12 The run-time type checker

    +

    11.12 The run-time type checker

    @@ -3965,7 +3965,7 @@ language modules.

  • Modules can be unloaded from the type system.
  • -

    10.12.1 Implementation

    +

    11.12.1 Implementation

    @@ -4151,7 +4151,7 @@ structures rather than creating new ones. These swig_module_info structures are chained together in a circularly linked list.

    -

    10.12.2 Usage

    +

    11.12.2 Usage

    This section covers how to use these functions from typemaps. To learn how to @@ -4245,7 +4245,7 @@ probably just look at the output of SWIG to get a better sense for how types are managed.

    -

    10.13 Typemaps and overloading

    +

    11.13 Typemaps and overloading

    @@ -4556,7 +4556,7 @@ Subsequent "in" typemaps would then perform more extensive type-checking. -

    10.14 More about %apply and %clear

    +

    11.14 More about %apply and %clear

    @@ -4642,7 +4642,7 @@ example: -

    10.15 Passing data between typemaps

    +

    11.15 Passing data between typemaps

    @@ -4679,7 +4679,7 @@ sure that the typemaps sharing information have exactly the same types and names

    -

    10.16 C++ "this" pointer

    +

    11.16 C++ "this" pointer

    @@ -4739,7 +4739,7 @@ will also match the typemap. One work around is to create an interface file tha the method, but gives the argument a name other than self.

    -

    10.17 Where to go for more information?

    +

    11.17 Where to go for more information?

    diff --git a/Doc/Manual/Varargs.html b/Doc/Manual/Varargs.html index 9564fe00b..dac1ad7bc 100644 --- a/Doc/Manual/Varargs.html +++ b/Doc/Manual/Varargs.html @@ -6,7 +6,7 @@ -

    13 Variable Length Arguments

    +

    14 Variable Length Arguments

      @@ -42,7 +42,7 @@ added in SWIG-1.3.12. Most other wrapper generation tools have wisely chosen to avoid this issue.

      -

      13.1 Introduction

      +

      14.1 Introduction

      @@ -139,7 +139,7 @@ List make_list(const char *s, ...) {

    -

    13.2 The Problem

    +

    14.2 The Problem

    @@ -232,7 +232,7 @@ can also support real varargs wrapping (with stack-frame manipulation) if you are willing to get hands dirty. Keep reading.

    -

    13.3 Default varargs support

    +

    14.3 Default varargs support

    @@ -301,7 +301,7 @@ Read on for further solutions.

    -

    13.4 Argument replacement using %varargs

    +

    14.4 Argument replacement using %varargs

    @@ -412,7 +412,7 @@ mixed argument types such as printf(). Providing general purpose wrappers to such functions presents special problems (covered shortly).

    -

    13.5 Varargs and typemaps

    +

    14.5 Varargs and typemaps

    @@ -589,7 +589,7 @@ really want to elevate your guru status and increase your job security, continue to the next section.

    -

    13.6 Varargs wrapping with libffi

    +

    14.6 Varargs wrapping with libffi

    @@ -841,7 +841,7 @@ provide an argument number for the first extra argument. This can be used to in values. Please consult the chapter on each language module for more details.

    -

    13.7 Wrapping of va_list

    +

    14.7 Wrapping of va_list

    @@ -895,7 +895,7 @@ int my_vprintf(const char *fmt, ...) { -

    13.8 C++ Issues

    +

    14.8 C++ Issues

    @@ -964,7 +964,7 @@ design or to provide an alternative interface using a helper function than it is fully general wrapper to a varargs C++ member function.

    -

    13.9 Discussion

    +

    14.9 Discussion

    diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index b4d27872c..99b89c425 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -6,7 +6,7 @@ -

    14 Warning Messages

    +

    15 Warning Messages

      @@ -35,7 +35,7 @@ -

      14.1 Introduction

      +

      15.1 Introduction

      @@ -55,7 +55,7 @@ where the generated wrapper code will probably compile, but it may not work like you expect.

      -

      14.2 Warning message suppression

      +

      15.2 Warning message suppression

      @@ -147,7 +147,7 @@ your interface. Ignore the warning messages at your own peril.

      -

      14.3 Enabling extra warnings

      +

      15.3 Enabling extra warnings

      @@ -220,7 +220,7 @@ that is, any warnings suppressed or added in %warnfilter, #pragma S or the -w option.

      -

      14.4 Issuing a warning message

      +

      15.4 Issuing a warning message

      @@ -274,7 +274,7 @@ example.i:24: Warning 901: You are really going to regret this usage of blah * s

    -

    14.5 Symbolic symbols

    +

    15.5 Symbolic symbols

    @@ -309,7 +309,7 @@ or -

    14.6 Commentary

    +

    15.6 Commentary

    @@ -326,7 +326,7 @@ no obvious recovery. There is no mechanism for suppressing error messages.

    -

    14.7 Warnings as errors

    +

    15.7 Warnings as errors

    @@ -335,7 +335,7 @@ option. This will cause SWIG to exit with a non successful exit code if a warning is encountered.

    -

    14.8 Message output format

    +

    15.8 Message output format

    @@ -354,10 +354,10 @@ $ swig -python -Fmicrosoft example.i example.i(4) : Syntax error in input. -

    14.9 Warning number reference

    +

    15.9 Warning number reference

    -

    14.9.1 Deprecated features (100-199)

    +

    15.9.1 Deprecated features (100-199)

      @@ -385,7 +385,7 @@ example.i(4) : Syntax error in input.
    • 126. The 'nestedworkaround' feature is deprecated.
    -

    14.9.2 Preprocessor (200-299)

    +

    15.9.2 Preprocessor (200-299)

      @@ -397,7 +397,7 @@ example.i(4) : Syntax error in input.
    • 206. Unexpected tokens after #directive directive.
    -

    14.9.3 C/C++ Parser (300-399)

    +

    15.9.3 C/C++ Parser (300-399)

      @@ -474,7 +474,7 @@ example.i(4) : Syntax error in input.
    • 395. operator delete[] ignored.
    -

    14.9.4 Types and typemaps (400-499)

    +

    15.9.4 Types and typemaps (400-499)

      @@ -505,7 +505,7 @@ example.i(4) : Syntax error in input. -

      14.9.5 Code generation (500-599)

      +

      15.9.5 Code generation (500-599)

        @@ -534,7 +534,7 @@ example.i(4) : Syntax error in input.
      • 523. Use of an illegal destructor name 'name' in %extend is deprecated, the destructor name should be 'name'.
      -

      14.9.6 Language module specific (700-899)

      +

      15.9.6 Language module specific (700-899)

        @@ -585,14 +585,14 @@ example.i(4) : Syntax error in input.
      • 871. Unrecognized pragma pragma. (Php).
      -

      14.9.7 User defined (900-999)

      +

      15.9.7 User defined (900-999)

      These numbers can be used by your own application.

      -

      14.10 History

      +

      15.10 History

      From 87963d2e685bdd96a765ab9418f536055437045c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Mar 2014 23:39:37 +0000 Subject: [PATCH 1096/1160] Java/C# smart pointer tests: Give GC more time to collect objects --- .../csharp/li_boost_shared_ptr_runme.cs | 35 ++++++++++------- .../csharp/li_std_auto_ptr_runme.cs | 36 +++++++++++++---- .../test-suite/java/java_director_runme.java | 39 +++++++++++-------- .../java/li_boost_intrusive_ptr_runme.java | 19 +++++---- .../java/li_boost_shared_ptr_runme.java | 37 +++++++++++------- .../java/li_std_auto_ptr_runme.java | 38 +++++++++++++----- 6 files changed, 137 insertions(+), 67 deletions(-) diff --git a/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs b/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs index 6ded989b5..625542751 100644 --- a/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs +++ b/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs @@ -6,6 +6,13 @@ public class runme // Debugging flag public static bool debug = false; + private static void WaitForGC() + { + System.GC.Collect(); + System.GC.WaitForPendingFinalizers(); + System.Threading.Thread.Sleep(10); + } + static void Main() { if (debug) @@ -27,22 +34,24 @@ public class runme if (debug) Console.WriteLine("Nearly finished"); - int countdown = 100; - while (true) { - System.GC.Collect(); - System.GC.WaitForPendingFinalizers(); - System.Threading.Thread.Sleep(10); - if (--countdown == 0) - break; - if (Klass.getTotal_count() == 1) // Expect 1 instance - the one global variable (GlobalValue) - break; - }; - if (Klass.getTotal_count() != 1) - throw new ApplicationException("Klass.total_count=" + Klass.getTotal_count()); + { + int countdown = 500; + int expectedCount = 1; + while (true) { + WaitForGC(); + if (--countdown == 0) + break; + if (Klass.getTotal_count() == expectedCount) // Expect the one global variable (GlobalValue) + break; + } + int actualCount = Klass.getTotal_count(); + if (actualCount != expectedCount) + throw new ApplicationException("Expected count: " + expectedCount + " Actual count: " + actualCount); + } int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count(); if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING) - if (wrapper_count != 1) // Expect 1 instance - the one global variable (GlobalSmartValue) + if (wrapper_count != 1) // Expect the one global variable (GlobalSmartValue) throw new ApplicationException("shared_ptr wrapper count=" + wrapper_count); if (debug) diff --git a/Examples/test-suite/csharp/li_std_auto_ptr_runme.cs b/Examples/test-suite/csharp/li_std_auto_ptr_runme.cs index bea92d2f4..387d50400 100644 --- a/Examples/test-suite/csharp/li_std_auto_ptr_runme.cs +++ b/Examples/test-suite/csharp/li_std_auto_ptr_runme.cs @@ -20,18 +20,38 @@ public class li_std_auto_ptr_runme { throw new Exception("number of objects should be 2"); k1 = null; - WaitForGC(); - - if (Klass.getTotal_count() != 1) - throw new Exception("number of objects should be 1"); + { + int countdown = 500; + int expectedCount = 1; + while (true) { + WaitForGC(); + if (--countdown == 0) + break; + if (Klass.getTotal_count() == expectedCount) + break; + }; + int actualCount = Klass.getTotal_count(); + if (actualCount != expectedCount) + throw new ApplicationException("Expected count: " + expectedCount + " Actual count: " + actualCount); + } if (k2.getLabel() != "second") throw new Exception("wrong object label"); k2 = null; - WaitForGC(); - - if (Klass.getTotal_count() != 0) - throw new Exception("no objects should be left"); + { + int countdown = 500; + int expectedCount = 0; + while (true) { + WaitForGC(); + if (--countdown == 0) + break; + if (Klass.getTotal_count() == expectedCount) + break; + } + int actualCount = Klass.getTotal_count(); + if (actualCount != expectedCount) + throw new ApplicationException("Expected count: " + expectedCount + " Actual count: " + actualCount); + } } } diff --git a/Examples/test-suite/java/java_director_runme.java b/Examples/test-suite/java/java_director_runme.java index 86c92d49a..812e791f4 100644 --- a/Examples/test-suite/java/java_director_runme.java +++ b/Examples/test-suite/java/java_director_runme.java @@ -13,6 +13,16 @@ public class java_director_runme { } } + private static void WaitForGC() + { + System.gc(); + System.runFinalization(); + try { + java.lang.Thread.sleep(10); + } catch (java.lang.InterruptedException e) { + } + } + public static void main(String argv[]) { QuuxContainer qc = createContainer(); @@ -31,24 +41,21 @@ public class java_director_runme { qc = null; /* Watch qc get reaped, which causes the C++ object to delete objects from the internal vector */ - System.gc(); - System.runFinalization(); - - // Give the finalizers a chance to run - try { - Thread.sleep(50); - } catch (InterruptedException e) { + { + int countdown = 500; + int expectedCount = 0; + while (true) { + WaitForGC(); + if (--countdown == 0) + break; + if (Quux.instances() == expectedCount) + break; + }; + int actualCount = Quux.instances(); + if (actualCount != expectedCount) + throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount); } - /* Watch the Quux objects formerly in the QuuxContainer object - get reaped */ - System.gc(); - System.runFinalization(); - - instances = Quux.instances(); - if (instances != 0) - throw new RuntimeException("Quux instances should be 0, actually " + instances); - /* Test Quux1's director disconnect method rename */ Quux1 quux1 = new Quux1("quux1"); if (quux1.disconnectMethodCalled) diff --git a/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java b/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java index 9b480e7e0..530008a87 100644 --- a/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java +++ b/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java @@ -13,6 +13,16 @@ public class li_boost_intrusive_ptr_runme { // Debugging flag public final static boolean debug = false; + private static void WaitForGC() + { + System.gc(); + System.runFinalization(); + try { + java.lang.Thread.sleep(10); + } catch (java.lang.InterruptedException e) { + } + } + public static void main(String argv[]) { if (debug) @@ -39,12 +49,7 @@ public class li_boost_intrusive_ptr_runme { int countdown = 50; while (true) { - System.gc(); - System.runFinalization(); - try { - java.lang.Thread.sleep(100); - } catch (java.lang.InterruptedException e) { - } + WaitForGC(); if (--countdown == 0) break; if (Klass.getTotal_count() == 1 && KlassWithoutRefCount.getTotal_count() == 0 && @@ -52,7 +57,7 @@ public class li_boost_intrusive_ptr_runme { KlassDerived.getTotal_count() == 0 && KlassDerivedDerived.getTotal_count() == 1) // Expect 1 Klass instance - the one global variable (GlobalValue) break; - }; + } if (Klass.getTotal_count() != 1) throw new RuntimeException("Klass.total_count=" + Klass.getTotal_count()); if (KlassWithoutRefCount.getTotal_count() != 0) diff --git a/Examples/test-suite/java/li_boost_shared_ptr_runme.java b/Examples/test-suite/java/li_boost_shared_ptr_runme.java index 02d6d6502..aa355c86a 100644 --- a/Examples/test-suite/java/li_boost_shared_ptr_runme.java +++ b/Examples/test-suite/java/li_boost_shared_ptr_runme.java @@ -13,6 +13,16 @@ public class li_boost_shared_ptr_runme { // Debugging flag public final static boolean debug = false; + private static void WaitForGC() + { + System.gc(); + System.runFinalization(); + try { + java.lang.Thread.sleep(10); + } catch (java.lang.InterruptedException e) { + } + } + public static void main(String argv[]) { if (debug) @@ -37,21 +47,20 @@ public class li_boost_shared_ptr_runme { if (debug) System.out.println("Nearly finished"); - int countdown = 100; - while (true) { - System.gc(); - System.runFinalization(); - try { - java.lang.Thread.sleep(10); - } catch (java.lang.InterruptedException e) { + { + int countdown = 500; + int expectedCount = 1; + while (true) { + WaitForGC(); + if (--countdown == 0) + break; + if (Klass.getTotal_count() == expectedCount) // Expect the one global variable (GlobalValue) + break; } - if (--countdown == 0) - break; - if (Klass.getTotal_count() == 1) // Expect 1 instance - the one global variable (GlobalValue) - break; - }; - if (Klass.getTotal_count() != 1) - throw new RuntimeException("Klass.total_count=" + Klass.getTotal_count()); + int actualCount = Klass.getTotal_count(); + if (actualCount != expectedCount) + throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount); + } int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count(); if (wrapper_count != li_boost_shared_ptr.getNOT_COUNTING()) diff --git a/Examples/test-suite/java/li_std_auto_ptr_runme.java b/Examples/test-suite/java/li_std_auto_ptr_runme.java index eac7cacfc..db34fb529 100644 --- a/Examples/test-suite/java/li_std_auto_ptr_runme.java +++ b/Examples/test-suite/java/li_std_auto_ptr_runme.java @@ -15,7 +15,7 @@ public class li_std_auto_ptr_runme { System.gc(); System.runFinalization(); try { - java.lang.Thread.sleep(1); + java.lang.Thread.sleep(10); } catch (java.lang.InterruptedException e) { } } @@ -31,18 +31,38 @@ public class li_std_auto_ptr_runme { throw new RuntimeException("number of objects should be 2"); k1 = null; - WaitForGC(); - - if (Klass.getTotal_count() != 1) - throw new RuntimeException("number of objects should be 1"); + { + int countdown = 500; + int expectedCount = 1; + while (true) { + WaitForGC(); + if (--countdown == 0) + break; + if (Klass.getTotal_count() == expectedCount) + break; + } + int actualCount = Klass.getTotal_count(); + if (actualCount != expectedCount) + throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount); + } if (!k2.getLabel().equals("second")) throw new RuntimeException("wrong object label"); k2 = null; - WaitForGC(); - - if (Klass.getTotal_count() != 0) - throw new RuntimeException("no objects should be left"); + { + int countdown = 500; + int expectedCount = 0; + while (true) { + WaitForGC(); + if (--countdown == 0) + break; + if (Klass.getTotal_count() == expectedCount) + break; + }; + int actualCount = Klass.getTotal_count(); + if (actualCount != expectedCount) + throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount); + } } } From f999c4864e0b6ac748da8306911c36d941287dfb Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Mar 2014 15:20:13 +0000 Subject: [PATCH 1097/1160] Fix errors test-suite on Mac OSX --- Examples/test-suite/errors/Makefile.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/errors/Makefile.in b/Examples/test-suite/errors/Makefile.in index f8627ef1a..601dcd303 100644 --- a/Examples/test-suite/errors/Makefile.in +++ b/Examples/test-suite/errors/Makefile.in @@ -16,7 +16,8 @@ LANGUAGE = python ERROR_EXT = newerr # Portable dos2unix / todos for stripping CR -TODOS = sed -e 's/\r$$//' +TODOS = tr -d '\r' +#TODOS = sed -e 's/\r$$//' # On OSX behaves as if written 's/r$$//' srcdir = @srcdir@ top_srcdir = @top_srcdir@ From 98a5569e1b5c4449166e56f38b50cbe62ea34628 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Mar 2014 18:37:05 +0000 Subject: [PATCH 1098/1160] Few tweaks to Lua html docs --- Doc/Manual/Contents.html | 3 --- Doc/Manual/Lua.html | 21 ++++++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index de64429cb..7cf40b95d 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -1106,9 +1106,6 @@

    • Namespaces -
    • Compatibility Note - diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index f0415d8d6..e6cf11b9f 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -42,9 +42,6 @@
    • Namespaces -
    • Compatibility Note - @@ -173,7 +170,7 @@ swig -lua -help -no-old-metatable-bindings - Disable backward compatibility: old-style binding names generations and a few other things. Explanations are included into appropriate sections. + Disable backward compatibility: old-style binding names generations and a few other things. Explanations are included in appropriate later sections. -squash-bases @@ -772,7 +769,10 @@ It is not (currently) possible to access static members of an instance: -- does NOT work +

      Compatibility Note: In versions prior to SWIG-3.0.0 only the following names would work: +

      +
       > example.Spam_foo()            -- calling Spam::foo()
       > a=example.Spam_bar            -- reading Spam::bar 
      @@ -1379,7 +1379,11 @@ namespace MyWorld {
         }
       }
       
      + +

      Now, from Lua usage is as follows: +

      +
       > print(example.module_function())
       7
      @@ -1399,7 +1403,7 @@ Now, from Lua usage is as follows:
       
       
       

      -If SWIG is running in backward compatible way, i.e. without -no-old-metatable-bindings option, then additional old-style names are generated(notice the underscore): +If SWIG is running in a backwards compatible way, i.e. without the -no-old-metatable-bindings option, then additional old-style names are generated (notice the underscore):

       9
      @@ -1409,10 +1413,9 @@ If SWIG is running in backward compatible way, i.e. without -no-old-metatabl
       11
       >
       
      -

      27.3.18 Compatibility Note

      -

      27.3.18.1 Names

      +

      27.3.17.2 Names

      If SWIG is launched without -no-old-metatable-bindings option, then it enters backward-compatible mode. While in this mode, it tries @@ -1435,7 +1438,7 @@ class Test2 { static const int ICONST2 = 23; }

      -

      When in backward compatible mode, in addition to usual names, the following ones will be generated (notice the underscore):

      +

      When in backward compatible mode, in addition to the usual names, the following ones will be generated (notice the underscore):

       9
       > print(example.MyWorld.Test_TEST1) -- Test has %nspace enabled
      @@ -1456,7 +1459,7 @@ surrounding scope without any prefixing. Pretending that Test2 is a struct, not
       >
       
      -

      27.3.18.2 Inheritance

      +

      27.3.17.3 Inheritance

      The internal organization of inheritance has changed. From f3593a4d35e7fab2e0745422dc1d625d4d43937e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Mar 2014 20:36:29 +0000 Subject: [PATCH 1099/1160] Add release note summary --- RELEASENOTES | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/RELEASENOTES b/RELEASENOTES index 756df81ff..949f58e38 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -4,6 +4,29 @@ and CHANGES files. Release Notes ============= +SWIG-3.0.0 summary: +- This is a major new release focusing primarily on C++ improvements. +- C++11 support added. Please see documentation for details of supported + features: http://www.swig.org/Doc3.0/CPlusPlus11.html +- Nested class support added. This has been taken full advantage of in + Java and C#. Other languages can use the nested classes, but require + further work for a more natural integration into the target language. + We urge folk knowledgeable in the other target languages to step + forward and help with this effort. +- Lua: improved metatables and support for %nspace. +- Go 1.3 support added. +- Python import improvements including relative imports. +- Python 3.3 support completed. +- Perl director support added. +- C# .NET 2 support is now the minimum. Generated using statements are + replaced by fully qualified names. +- Bug fixes and improvements to the following languages: + C#, Go, Guile, Java, Lua, Perl, PHP, Python, Octave, R, Ruby, Tcl +- Various other bug fixes and improvements affecting all languages. +- Note that this release contains some backwards incompatible changes + in some languages. +- Full detailed release notes are in the changes file. + SWIG-2.0.12 summary: - This is a maintenance release backporting some fixes from the pending 3.0.0 release. From 778aed5a085753cc4ac3509cad5088f2370a2b1b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Mar 2014 18:49:09 +0000 Subject: [PATCH 1100/1160] CHANGES file updates --- CHANGES.current | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 9b0642ef4..bbdbcbfd6 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,13 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2014-03-16: wsfulton + C++11 support initially developed as C++0x support by Matevz Jekovec as a Google Summer of Code + project has been further extended. The C++11 support is comprehensive, but by no means complete + or without limitations. Full details for each new feature in C++11 is covered in the + CPlusPlus11.html chapter in the documentation which is included in SWIG and also available + online at http://www.swig.org/Doc3.0/CPlusPlus11.html. + 2014-03-06: wsfulton [Python] Change in default behaviour wrapping C++ bool. Only a Python True or False will now work for C++ bool parameters. This fixes overloading bool with other types. @@ -170,6 +177,7 @@ Version 3.0.0 (in progress) Director exceptions (Swig::DirectorException) now derive from std::exception and hence provide the what() method. In Python and Ruby, this replaces the now deprecated DirectorException::getMessage() method. + 2014-01-14: diorcety Patch #112 - Fix symbol resolution involving scopes that have multiple levels of typedefs - fixes some template resolutions as well as some typemap searches. @@ -299,7 +307,6 @@ Version 3.0.0 (in progress) Allow using \l, \L, \u, \U and \E in the substitution part of %(regex:/pattern/subst/) inside %rename to change the case of the text being replaced. - 2013-10-12: wsfulton [CFFI] Apply #96 - superclass not lispify From e1b649998b7de43a002b60b9dcc369c1b24ce359 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Mar 2014 21:09:52 +0000 Subject: [PATCH 1101/1160] Add changes notes for Lua changes --- CHANGES.current | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index bbdbcbfd6..63f545fc0 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -12,6 +12,45 @@ Version 3.0.0 (in progress) CPlusPlus11.html chapter in the documentation which is included in SWIG and also available online at http://www.swig.org/Doc3.0/CPlusPlus11.html. +2014-03-14: v-for-vandal + [Lua] Numerous Lua improvements: + 1. %nspace support has been added. Namespaces are mapped to tables in the module, with the same + name as the C++ namespace. + 2. Inheritance is now handled differently. Each class metatable keeps a list of class bases instead + of merging all members of all bases into the derived class. + 3. The new metatables result in differences in accessing class members. For example: + + %module example + struct Test { + enum { TEST1 = 10, TEST2 = 20 }; + static const int ICONST = 12; + }; + + Now this can be used as follows: + print(example.Test.TEST1) + print(example.Test.ICONST) + The old way was: + print(example.Test_TEST1) + print(example.Test_ICONST) + + 4. The special class metatable member ".constructor" was removed. Now SWIG generates the proxy + function by itself and assigns it directly to the class table "__call" method. + 5. eLua should also now support inheritance. + 6. 'const' subtable in eLua is considered deprecated. + + Changes in behaviour: + a. You can no longer assign to non-existing class members in classes without a __setitem__ method. + It will cause a Lua error. + b. You can no longer iterate over a module table and copy everything into the global namespace. + Actually, this was never the case, but it is now explicitly prohibited. + c. Now changing a base class will immediately affect all derived classes. + d. There might be some issues with inheritance. Although the bases iteration scheme is the same + as was used for merging base classes into derived one, some unknown issues may arise. + + The old metatable behaviour can be restored by using the -no-old-metatable-bindings option. + + *** POTENTIAL INCOMPATIBILITY *** + 2014-03-06: wsfulton [Python] Change in default behaviour wrapping C++ bool. Only a Python True or False will now work for C++ bool parameters. This fixes overloading bool with other types. From 08b783113da0902dccf542e7efa7f54dba07376d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Mar 2014 17:54:10 +0000 Subject: [PATCH 1102/1160] Add release date --- ANNOUNCE | 2 +- CHANGES.current | 4 ++-- Doc/Manual/Sections.html | 2 +- README | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 90cc9ba24..c5108035a 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,4 +1,4 @@ -*** ANNOUNCE: SWIG 3.0.0 (in progress) *** +*** ANNOUNCE: SWIG 3.0.0 (16 Mar 2014) *** http://www.swig.org diff --git a/CHANGES.current b/CHANGES.current index 63f545fc0..b87e6c577 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,8 +2,8 @@ Below are the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 3.0.0 (in progress) -============================ +Version 3.0.0 (16 Mar 2014) +=========================== 2014-03-16: wsfulton C++11 support initially developed as C++0x support by Matevz Jekovec as a Google Summer of Code diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 195111424..3c5a2ac7e 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

      SWIG-3.0 Documentation

      -Last update : SWIG-3.0.0 (in progress) +Last update : SWIG-3.0.0 (16 Mar 2014)

      Sections

      diff --git a/README b/README index b6080a4fd..83dc31773 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 3.0.0 (in progress) +Version: 3.0.0 (16 Mar 2014) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, C#, D, Go, Lua, From ade79e2e9446470d64e37c5d54bf7239a15a2556 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Mar 2014 21:30:19 +0000 Subject: [PATCH 1103/1160] SWIG 3 doc updates --- Doc/Manual/Sections.html | 1 + Doc/Manual/index.html | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 3c5a2ac7e..d769c2792 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -18,6 +18,7 @@ Last update : SWIG-3.0.0 (16 Mar 2014)
    • Scripting
    • SWIG Basics (Read this!)
    • SWIG and C++
    • +
    • SWIG and C++11
    • The SWIG preprocessor
    • The SWIG library
    • Argument handling
    • diff --git a/Doc/Manual/index.html b/Doc/Manual/index.html index 30c69578f..fbe105a7e 100644 --- a/Doc/Manual/index.html +++ b/Doc/Manual/index.html @@ -1,10 +1,10 @@ -SWIG-2.0 Documentation +SWIG-3.0 Documentation -

      SWIG-2.0 Documentation

      +

      SWIG-3.0 Documentation

      The SWIG documentation is available in one of the following formats.

      No other lua metafunction is inherited. For example, __gc is not inherited and must be redefined in every class. __tostring is subject to a special handling. If absent in class and in class bases, a default one will be provided by SWIG

      diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index 3fc45834d..9719239a9 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -4690,7 +4690,7 @@ public: C++ constructor, thus creating a new foo object. By default, SWIG will assign the new Ruby object a "free" function. When the Ruby object is garbage collected, the "free" function will be -called. It in turn will call Foo's destructor.

      +called. It in turn will call Foo's destructor.

      Next, consider this code:

      diff --git a/Examples/lua/arrays/runme.lua b/Examples/lua/arrays/runme.lua index 7ab6dc42b..d0aa99813 100644 --- a/Examples/lua/arrays/runme.lua +++ b/Examples/lua/arrays/runme.lua @@ -25,7 +25,7 @@ math.randomseed(0) -- init random --[[ version 1: passing a C array to the code -lets test call sort_int() +let's test call sort_int() this requires a C array, so is the hardest to use]] ARRAY_SIZE=10 arr=example.new_int(ARRAY_SIZE) diff --git a/Examples/lua/dual/dual.cpp b/Examples/lua/dual/dual.cpp index ad7897953..b54e44de1 100644 --- a/Examples/lua/dual/dual.cpp +++ b/Examples/lua/dual/dual.cpp @@ -1,7 +1,7 @@ /* -dual.cpp a test for multiple modules and multiple intrepreters staticly linked together. +dual.cpp a test for multiple modules and multiple interpreters statically linked together. -Earlier version of lua bindings for SWIG would fail if staticly linked. +Earlier version of lua bindings for SWIG would fail if statically linked. What is happening is as follows: example.i declares a type Foo @@ -28,7 +28,7 @@ both Foo and Bar. #include #include -// the 2 libraries which are wrappered via SWIG +// the 2 libraries which are wrapped via SWIG extern "C" int luaopen_example(lua_State*L); extern "C" int luaopen_example2(lua_State*L); diff --git a/Examples/lua/embed/embed.c b/Examples/lua/embed/embed.c index f21c933a5..507567489 100644 --- a/Examples/lua/embed/embed.c +++ b/Examples/lua/embed/embed.c @@ -1,9 +1,9 @@ -/* embed.c a simple test for an embeded interpreter +/* embed.c a simple test for an embedded interpreter The idea is that we wrapper a few simple function (example.c) and write our own app to call it. -What it will do is load the wrappered lib, load runme.lua and then call some functions. +What it will do is load the wrapped lib, load runme.lua and then call some functions. To make life easier, all the printf's have either [C] or [Lua] at the start so you can see where they are coming from. @@ -28,8 +28,8 @@ extern int luaopen_example(lua_State*L); /* a really simple way of calling lua from C just give it a lua state & a string to execute Unfortunately lua keeps changing its API's. -In lua 5.0.X its lua_dostring() -In lua 5.1.X its luaL_dostring() +In lua 5.0.X it's lua_dostring() +In lua 5.1.X it's luaL_dostring() so we have a few extra compiles */ int dostring(lua_State *L, char* str) { @@ -58,11 +58,11 @@ int main(int argc,char* argv[]) { luaopen_base(L); luaopen_string(L); luaopen_math(L); - printf("[C] now loading the SWIG wrappered library\n"); + printf("[C] now loading the SWIG wrapped library\n"); luaopen_example(L); printf("[C] all looks ok\n"); printf("\n"); - printf("[C] lets load the file 'runme.lua'\n"); + printf("[C] let's load the file 'runme.lua'\n"); printf("[C] any lua code in this file will be executed\n"); if (luaL_loadfile(L, "runme.lua") || lua_pcall(L, 0, 0, 0)) { printf("[C] ERROR: cannot run lua file: %s",lua_tostring(L, -1)); @@ -70,16 +70,16 @@ int main(int argc,char* argv[]) { } printf("[C] We are now back in C, all looks ok\n"); printf("\n"); - printf("[C] lets call the function 'do_tests()'\n"); + printf("[C] let's call the function 'do_tests()'\n"); ok=dostring(L,"do_tests()"); printf("[C] We are back in C, the dostring() function returned %d\n",ok); printf("\n"); - printf("[C] Lets call lua again, but create an error\n"); + printf("[C] Let's call lua again, but create an error\n"); ok=dostring(L,"no_such_function()"); printf("[C] We are back in C, the dostring() function returned %d\n",ok); printf("[C] it should also have returned 1 and printed an error message\n"); printf("\n"); - printf("[C] Lets call lua again, calling the greeting function\n"); + printf("[C] Let's call lua again, calling the greeting function\n"); ok=dostring(L,"call_greeting()"); printf("[C] This was C=>Lua=>C (getting a bit complex)\n"); printf("\n"); diff --git a/Examples/lua/embed/runme.lua b/Examples/lua/embed/runme.lua index e02fd1d55..a75f74000 100644 --- a/Examples/lua/embed/runme.lua +++ b/Examples/lua/embed/runme.lua @@ -1,7 +1,7 @@ print "[lua] This is runme.lua" --- test program for embeded lua --- we do not need to load the library, as it was already in the intrepreter --- but lets check anyway +-- test program for embedded lua +-- we do not need to load the library, as it was already in the interpreter +-- but let's check anyway assert(type(example)=='table',"Don't appear to have loaded the example module") -- a test function to run the tests diff --git a/Examples/lua/embed2/embed2.c b/Examples/lua/embed2/embed2.c index 3145d3b10..100a1fb33 100644 --- a/Examples/lua/embed2/embed2.c +++ b/Examples/lua/embed2/embed2.c @@ -1,9 +1,9 @@ -/* embed2.c some more test for an embeded interpreter +/* embed2.c some more tests for an embedded interpreter This will go a bit further as it will pass values to and from the lua code. It uses less of the SWIG code, and more of the raw lua API's -What it will do is load the wrappered lib, load runme.lua and then call some functions. +What it will do is load the wrapped lib, load runme.lua and then call some functions. To make life easier, all the printf's have either [C] or [Lua] at the start so you can see where they are coming from. @@ -35,12 +35,12 @@ We will be using the luaL_dostring()/lua_dostring() function to call into lua #define lua_open luaL_newstate #endif -/* the SWIG wrappered library */ +/* the SWIG wrapped library */ extern int luaopen_example(lua_State*L); /* This is an example of how to call the Lua function int add(int,int) - its very tedious, but gives you an idea of the issues involded. + its very tedious, but gives you an idea of the issues involved. (look below for a better idea) */ int call_add(lua_State *L,int a,int b,int* res) { @@ -78,7 +78,7 @@ int call_add(lua_State *L,int a,int b,int* res) { Original Code from Programming in Lua (PIL) by Roberto Ierusalimschy ISBN 85-903798-1-7 http://www.lua.org/pil/25.3.html -This has been modified slightly to make it compile, and its still a bit rough. +This has been modified slightly to make it compile, and it's still a bit rough. But it gives the idea of how to make it work. */ int call_va (lua_State *L,const char *func, const char *sig, ...) { @@ -189,7 +189,7 @@ int main(int argc,char* argv[]) { luaopen_example(L); printf("[C] all looks ok\n"); printf("\n"); - printf("[C] lets load the file 'runme.lua'\n"); + printf("[C] let's load the file 'runme.lua'\n"); printf("[C] any lua code in this file will be executed\n"); if (luaL_loadfile(L, "runme.lua") || lua_pcall(L, 0, 0, 0)) { printf("[C] ERROR: cannot run lua file: %s",lua_tostring(L, -1)); @@ -197,12 +197,12 @@ int main(int argc,char* argv[]) { } printf("[C] We are now back in C, all looks ok\n"); printf("\n"); - printf("[C] lets call the Lua function 'add(1,1)'\n"); + printf("[C] let's call the Lua function 'add(1,1)'\n"); printf("[C] using the C function 'call_add'\n"); ok=call_add(L,1,1,&res); printf("[C] the function returned %d with value %d\n",ok,res); printf("\n"); - printf("[C] lets do this rather easier\n"); + printf("[C] let's do this rather easier\n"); printf("[C] we will call the same Lua function using a generic C function 'call_va'\n"); ok=call_va(L,"add","ii>i",1,1,&res); printf("[C] the function returned %d with value %d\n",ok,res); diff --git a/Examples/lua/embed2/runme.lua b/Examples/lua/embed2/runme.lua index 73af9c5f2..9e7ab616c 100644 --- a/Examples/lua/embed2/runme.lua +++ b/Examples/lua/embed2/runme.lua @@ -1,7 +1,7 @@ print "[lua] This is runme.lua" --- test program for embeded lua --- we do not need to load the library, as it was already in the intrepreter --- but lets check anyway +-- test program for embedded lua +-- we do not need to load the library, as it was already in the interpreter +-- but let's check anyway assert(type(example)=='table',"Don't appear to have loaded the example module") -- note: we will copy the functions from example table into global diff --git a/Examples/lua/embed3/embed3.cpp b/Examples/lua/embed3/embed3.cpp index cdf56268d..d559167d1 100644 --- a/Examples/lua/embed3/embed3.cpp +++ b/Examples/lua/embed3/embed3.cpp @@ -1,4 +1,4 @@ -/* embed3.cpp A C++ embeded interpreter +/* embed3.cpp A C++ embedded interpreter This will register a C++ class with Lua, and then call a Lua function passing C++ objects to this function. @@ -33,12 +33,12 @@ extern "C" { /* The SWIG external runtime is generated by using. swig -lua -externalruntime swigluarun.h -It contains useful function used by SWIG in its wrappering +It contains useful function used by SWIG in its wrapper SWIG_TypeQuery() SWIG_NewPointerObj() */ #include "swigluarun.h" // the SWIG external runtime -/* the SWIG wrappered library */ +/* the SWIG wrapped library */ extern "C" int luaopen_example(lua_State*L); // the code itself @@ -100,10 +100,10 @@ int main(int argc, char* argv[]) { luaopen_example(L); printf("[C++] all looks ok\n"); printf("\n"); - printf("[C++] lets create an Engine and pass a pointer to Lua\n"); + printf("[C++] let's create an Engine and pass a pointer to Lua\n"); Engine engine; /* this code will pass a pointer into lua, but C++ still owns the object - this is a little tedious, to do, but lets do it + this is a little tedious, to do, but let's do it we need to pass the pointer (obviously), the type name and a flag which states if Lua should delete the pointer once its finished with it The type name is a class name string which is registered with SWIG @@ -113,7 +113,7 @@ int main(int argc, char* argv[]) { push_pointer(L,&engine,"Engine *",0); lua_setglobal(L, "pEngine"); // set as global variable - printf("[C++] now lets load the file 'runme.lua'\n"); + printf("[C++] now let's load the file 'runme.lua'\n"); printf("[C++] any lua code in this file will be executed\n"); if (luaL_loadfile(L, "runme.lua") || lua_pcall(L, 0, 0, 0)) { printf("[C++] ERROR: cannot run lua file: %s", lua_tostring(L, -1)); @@ -122,7 +122,7 @@ int main(int argc, char* argv[]) { printf("[C++] We are now back in C++, all looks ok\n"); printf("\n"); - printf("[C++] Lets call the Lua function onEvent(e)\n"); + printf("[C++] Let's call the Lua function onEvent(e)\n"); printf("[C++] We will give it different events, as we wish\n"); printf("[C++] Starting with STARTUP\n"); Event ev; diff --git a/Examples/lua/embed3/example.h b/Examples/lua/embed3/example.h index 41c13e9c1..df189e34b 100644 --- a/Examples/lua/embed3/example.h +++ b/Examples/lua/embed3/example.h @@ -13,7 +13,7 @@ public: }; -/* We also want to pass some events to Lua, so lets have a few classes +/* We also want to pass some events to Lua, so let's have a few classes to do this. */ class Event diff --git a/Examples/lua/embed3/runme.lua b/Examples/lua/embed3/runme.lua index 3a44bd2fc..8d5b1eada 100644 --- a/Examples/lua/embed3/runme.lua +++ b/Examples/lua/embed3/runme.lua @@ -1,7 +1,7 @@ print "[lua] This is runme.lua" --- test program for embeded lua --- we do not need to load the library, as it was already in the intrepreter --- but lets check anyway +-- test program for embedded lua +-- we do not need to load the library, as it was already in the interpreter +-- but let's check anyway assert(type(example)=='table',"Don't appear to have loaded the example module. Do not run this file directly, run the embed3 executable") @@ -13,12 +13,12 @@ else end --- the embed program expects a function void onEvent(Event) +-- the embedded program expects a function void onEvent(Event) -- this is it function onEvent(e) print("[Lua] onEvent with event",e.mType) - -- lets do something with the Engine + -- let's do something with the Engine -- nothing clever, but ... if e.mType==example.Event_STARTUP then pEngine:start() diff --git a/Examples/lua/exception/runme.lua b/Examples/lua/exception/runme.lua index d8125caec..a798efca7 100644 --- a/Examples/lua/exception/runme.lua +++ b/Examples/lua/exception/runme.lua @@ -70,7 +70,7 @@ function b() t:message() end print [[ -Now lets call function a() +Now let's call function a() which calls b() which calls into C++ which will throw an exception!]] @@ -80,7 +80,7 @@ if ok then else print(" call failed with error:",res) end -print "Now lets do the same using xpcall(a,debug.traceback)" +print "Now let's do the same using xpcall(a,debug.traceback)" ok,res=xpcall(a,debug.traceback) if ok then print " that worked! Funny" diff --git a/Examples/lua/owner/runme.lua b/Examples/lua/owner/runme.lua index ed745f7b2..847645448 100644 --- a/Examples/lua/owner/runme.lua +++ b/Examples/lua/owner/runme.lua @@ -9,15 +9,15 @@ else require('example') end -print "ok, lets test Lua's ownership of C++ objects" +print "ok, let's test Lua's ownership of C++ objects" print("Currently there are",example.Shape_nshapes,"shapes (there should be 0)") -print "\nLets make a couple" +print "\nLet's make a couple" a=example.Square(10) b=example.Circle(1) print("Currently there are",example.Shape_nshapes,"shapes (there should be 2)") -print "\nNote lets use the createX functions" +print "\nNote let's use the createX functions" c=example.createCircle(5) d=example.createSquare(3) print("Currently there are",example.Shape_nshapes,"shapes (there should be 4)") @@ -26,12 +26,12 @@ print "\nWe will run the garbage collector & see if they are till here" collectgarbage() print("Currently there are",example.Shape_nshapes,"shapes (there should be 4)") -print "\nLets get rid of them all, collect garbage & see if they are till here" +print "\nLet's get rid of them all, collect garbage & see if they are till here" a,b,c,d=nil,nil,nil,nil collectgarbage() print("Currently there are",example.Shape_nshapes,"shapes (there should be 0)") -print "\nLets start putting stuff into the ShapeOwner" +print "\nLet's start putting stuff into the ShapeOwner" print "The ShapeOwner now owns the shapes, but Lua still has pointers to them" o=example.ShapeOwner() a=example.Square(10) @@ -41,7 +41,7 @@ o:add(b) o:add(example.createSquare(5)) print("Currently there are",example.Shape_nshapes,"shapes (there should be 3)") -print "\nWe will nil our references,run the garbage collector & see if they are till here" +print "\nWe will nil our references,run the garbage collector & see if they are still here" print "they should be, as the ShapeOwner owns them" a,b=nil,nil collectgarbage() @@ -101,4 +101,4 @@ print "done" o,sh=nil,nil collectgarbage() print("Currently there are",example.Shape_nshapes,"shapes (there should be 0)") -print "thats all folks!" +print "that's all folks!" diff --git a/Examples/test-suite/d/operator_overload_runme.2.d b/Examples/test-suite/d/operator_overload_runme.2.d index 2ff61cd56..d05265e58 100644 --- a/Examples/test-suite/d/operator_overload_runme.2.d +++ b/Examples/test-suite/d/operator_overload_runme.2.d @@ -53,7 +53,7 @@ void main() { assert(-a == a); assert(-b == new Op(-5)); - // Unfortunaly, there is no way to override conversion to boolean for + // Unfortunately, there is no way to override conversion to boolean for // classes in D, opCast!("bool") is only used for structs. // test [] diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 1e99205bc..ad4ba1925 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -205,7 +205,7 @@ public: } /* NEW LANGUAGE NOTE:*********************************************** - This is called to initalise the system & read any command line args + This is called to initialise the system & read any command line args most of this is boilerplate code, except the command line args which depends upon what args your code supports NEW LANGUAGE NOTE:END *********************************************** */ @@ -380,7 +380,7 @@ public: Dump(f_header, f_begin); Dump(f_wrappers, f_begin); Dump(f_initbeforefunc, f_begin); - /* for the Lua code it needs to be properly excaped to be added into the C/C++ code */ + /* for the Lua code it needs to be properly escaped to be added into the C/C++ code */ escapeCode(s_luacode); Printf(f_begin, "const char* SWIG_LUACODE=\n \"%s\";\n\n", s_luacode); Wrapper_pretty_print(f_init, f_begin); @@ -436,9 +436,9 @@ public: /* NEW LANGUAGE NOTE:*********************************************** This is it! you get this one right, and most of your work is done - but its going to take soem file to get it working right + but its going to take some file to get it working right quite a bit of this is generally boilerplate code - (or stuff I dont understand) + (or stuff I don't understand) that which matters will have extra added comments NEW LANGUAGE NOTE:END *********************************************** */ /* --------------------------------------------------------------------- @@ -534,7 +534,7 @@ public: } /* NEW LANGUAGE NOTE:*********************************************** - the wrapper object holds all the wrappering code + the wrapper object holds all the wrapper code we need to add a couple of local variables NEW LANGUAGE NOTE:END *********************************************** */ Wrapper *f = NewWrapper(); @@ -554,7 +554,7 @@ public: /* NEW LANGUAGE NOTE:*********************************************** the format of a lua fn is: static int wrap_XXX(lua_State* L){...} - this line adds this into the wrappering code + this line adds this into the wrapper code NEW LANGUAGE NOTE:END *********************************************** */ Printv(f->def, "static int ", wname, "(lua_State* L) {", NIL); @@ -657,7 +657,7 @@ public: continue; } else { /* NEW LANGUAGE NOTE:*********************************************** - // why is this code not called when I dont have a typemap? + // why is this code not called when I don't have a typemap? // instead of giving a warning, no code is generated NEW LANGUAGE NOTE:END *********************************************** */ Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0)); @@ -792,7 +792,7 @@ public: Replaceall(f->code, "$result", Swig_cresult_name()); /* Dump the function out */ - /* in Lua we will not emit the destructor as a wrappered function, + /* in Lua we will not emit the destructor as a wrapper function, Lua will automatically call the destructor when the object is free'd However: you cannot just skip this function as it will not emit any custom destructor (using %extend), as you need to call emit_action() @@ -835,7 +835,7 @@ public: /* NEW LANGUAGE NOTE:*********************************************** This is an extra function used for overloading of functions it checks the args & then calls the relevant fn - nost of the real work in again typemaps: + most of the real work in again typemaps: look for %typecheck(SWIG_TYPECHECK_*) in the .swg file NEW LANGUAGE NOTE:END *********************************************** */ int dispatchFunction(Node *n) { diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index ca8577375..0a3fb722b 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -2160,7 +2160,7 @@ int R::functionWrapper(Node *n) { /* If we are dealing with a method in an C++ class, then add the name of the R function and its definition. XXX need to figure out how to store the Wrapper if possible in the hash/list. - Would like to be able to do this so that we can potentialy insert + Would like to be able to do this so that we can potentially insert */ if(processing_member_access_function || processing_class_member_function) { addAccessor(member_name, sfun, iname); From 36be36d6185cf75c91532f9aa50fb2f77bc55465 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 30 Apr 2014 12:00:23 +1200 Subject: [PATCH 1160/1160] Eliminate needless casting away const from string constants --- Source/CParse/parser.y | 16 ++++++++-------- Source/Modules/allegrocl.cxx | 2 +- Source/Modules/allocate.cxx | 4 ++-- Source/Modules/cffi.cxx | 2 +- Source/Modules/chicken.cxx | 12 ++++++------ Source/Modules/clisp.cxx | 2 +- Source/Modules/csharp.cxx | 2 +- Source/Modules/d.cxx | 2 +- Source/Modules/go.cxx | 2 +- Source/Modules/guile.cxx | 6 +++--- Source/Modules/java.cxx | 2 +- Source/Modules/lua.cxx | 2 +- Source/Modules/main.cxx | 10 +++++----- Source/Modules/modula3.cxx | 2 +- Source/Modules/mzscheme.cxx | 4 ++-- Source/Modules/ocaml.cxx | 4 ++-- Source/Modules/octave.cxx | 2 +- Source/Modules/perl5.cxx | 2 +- Source/Modules/php.cxx | 2 +- Source/Modules/pike.cxx | 2 +- Source/Modules/python.cxx | 6 +++--- Source/Modules/r.cxx | 2 +- Source/Modules/ruby.cxx | 4 ++-- Source/Modules/tcl8.cxx | 2 +- Source/Modules/uffi.cxx | 2 +- Source/Swig/cwrap.c | 2 +- 26 files changed, 50 insertions(+), 50 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 0ed438e90..7e7e5633f 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1418,7 +1418,7 @@ static void mark_nodes_as_extend(Node *n) { String *nexcept; } dtype; struct { - char *type; + const char *type; String *filename; int line; } loc; @@ -2002,8 +2002,8 @@ include_directive: includetype options string BEGINFILE { } ; -includetype : INCLUDE { $$.type = (char *) "include"; } - | IMPORT { $$.type = (char *) "import"; ++import_mode;} +includetype : INCLUDE { $$.type = "include"; } + | IMPORT { $$.type = "import"; ++import_mode;} ; /* ------------------------------------------------------------ @@ -4292,7 +4292,7 @@ cpp_namespace_decl : NAMESPACE idcolon LBRACE { | NAMESPACE LBRACE { Hash *h; $1 = Swig_symbol_current(); - h = Swig_symbol_clookup((char *)" ",0); + h = Swig_symbol_clookup(" ",0); if (h && (Strcmp(nodeType(h),"namespace") == 0)) { Swig_symbol_setscope(Getattr(h,"symtab")); } else { @@ -5271,7 +5271,7 @@ notso_direct_declarator : idcolon { SwigType *t; $$ = $1; t = NewStringEmpty(); - SwigType_add_array(t,(char*)""); + SwigType_add_array(t,""); if ($$.type) { SwigType_push(t,$$.type); Delete($$.type); @@ -5370,7 +5370,7 @@ direct_declarator : idcolon { SwigType *t; $$ = $1; t = NewStringEmpty(); - SwigType_add_array(t,(char*)""); + SwigType_add_array(t,""); if ($$.type) { SwigType_push(t,$$.type); Delete($$.type); @@ -5540,7 +5540,7 @@ direct_abstract_declarator : direct_abstract_declarator LBRACKET RBRACKET { SwigType *t; $$ = $1; t = NewStringEmpty(); - SwigType_add_array(t,(char*)""); + SwigType_add_array(t,""); if ($$.type) { SwigType_push(t,$$.type); Delete($$.type); @@ -5563,7 +5563,7 @@ direct_abstract_declarator : direct_abstract_declarator LBRACKET RBRACKET { $$.id = 0; $$.parms = 0; $$.have_parms = 0; - SwigType_add_array($$.type,(char*)""); + SwigType_add_array($$.type,""); } | LBRACKET expr RBRACKET { $$.type = NewStringEmpty(); diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index 93477057f..c7d9ff21b 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -20,7 +20,7 @@ // #define ALLEGROCL_TYPE_DEBUG // #define ALLEGROCL_CLASS_DEBUG -static const char *usage = (char *) "\ +static const char *usage = "\ Allegro CL Options (available with -allegrocl)\n\ -identifier-converter - \n\ Specifies the type of conversion to do on C identifiers to convert\n\ diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index d3618634b..dc3820766 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -714,7 +714,7 @@ Allocate(): /* Check if base classes allow smart pointers, but might be hidden */ if (!Getattr(n, "allocate:smartpointer")) { - Node *sp = Swig_symbol_clookup((char *) "operator ->", 0); + Node *sp = Swig_symbol_clookup("operator ->", 0); if (sp) { /* Look for parent */ Node *p = parentNode(sp); @@ -833,7 +833,7 @@ Allocate(): or reference. We're going to chase it to see if another operator->() can be found */ if ((SwigType_check_decl(type, "")) || (SwigType_check_decl(type, "r."))) { - Node *nn = Swig_symbol_clookup((char *) "operator ->", Getattr(sc, "symtab")); + Node *nn = Swig_symbol_clookup("operator ->", Getattr(sc, "symtab")); if (nn) { Delete(base); Delete(type); diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx index 6b331ad19..a1be00100 100644 --- a/Source/Modules/cffi.cxx +++ b/Source/Modules/cffi.cxx @@ -18,7 +18,7 @@ //#define CFFI_DEBUG //#define CFFI_WRAP_DEBUG -static const char *usage = (char *) "\ +static const char *usage = "\ CFFI Options (available with -cffi)\n\ -generate-typedef - Use defctype to generate shortcuts according to the\n\ typedefs in the input.\n\ diff --git a/Source/Modules/chicken.cxx b/Source/Modules/chicken.cxx index 89e583d18..986638cf3 100644 --- a/Source/Modules/chicken.cxx +++ b/Source/Modules/chicken.cxx @@ -15,7 +15,7 @@ #include -static const char *usage = (char *) "\ +static const char *usage = "\ \ CHICKEN Options (available with -chicken)\n\ -closprefix - Prepend to all clos identifiers\n\ @@ -29,7 +29,7 @@ CHICKEN Options (available with -chicken)\n\ \n"; static char *module = 0; -static char *chicken_path = (char *) "chicken"; +static const char *chicken_path = "chicken"; static int num_methods = 0; static File *f_begin = 0; @@ -620,7 +620,7 @@ int CHICKEN::functionWrapper(Node *n) { if (in_class) clos_name = NewString(member_name); else - clos_name = chickenNameMapping(scmname, (char *) ""); + clos_name = chickenNameMapping(scmname, ""); if (!any_specialized_arg) { method_def = NewString(""); @@ -775,7 +775,7 @@ int CHICKEN::variableWrapper(Node *n) { if (in_class) clos_name = NewString(member_name); else - clos_name = chickenNameMapping(scmname, (char *) ""); + clos_name = chickenNameMapping(scmname, ""); Node *class_node = classLookup(t); String *clos_code = Getattr(n, "tmap:varin:closcode"); @@ -942,7 +942,7 @@ int CHICKEN::constantWrapper(Node *n) { if (in_class) clos_name = NewString(member_name); else - clos_name = chickenNameMapping(scmname, (char *) ""); + clos_name = chickenNameMapping(scmname, ""); if (GetFlag(n, "feature:constasvar")) { Printv(clos_methods, "(define ", clos_name, " (", chickenPrimitiveName(scmname), "))\n", NIL); Printv(scm_const_defs, "(set! ", scmname, " (", scmname, "))\n", NIL); @@ -1372,7 +1372,7 @@ void CHICKEN::dispatchFunction(Node *n) { } else if (in_class) clos_name = NewString(member_name); else - clos_name = chickenNameMapping(scmname, (char *) ""); + clos_name = chickenNameMapping(scmname, ""); Iterator f; List *prev = 0; diff --git a/Source/Modules/clisp.cxx b/Source/Modules/clisp.cxx index e7d971faa..7d7c69a50 100644 --- a/Source/Modules/clisp.cxx +++ b/Source/Modules/clisp.cxx @@ -13,7 +13,7 @@ #include "swigmod.h" -static const char *usage = (char *) "\ +static const char *usage = "\ CLISP Options (available with -clisp)\n\ -extern-all - Create clisp definitions for all the functions and\n\ global variables otherwise only definitions for\n\ diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 3e34e7f91..d30bd18c5 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -4303,7 +4303,7 @@ extern "C" Language *swig_csharp(void) { * Static member variables * ----------------------------------------------------------------------------- */ -const char *CSHARP::usage = (char *) "\ +const char *CSHARP::usage = "\ C# Options (available with -csharp)\n\ -dllimport
      - Override DllImport attribute name to
      \n\ -namespace - Generate wrappers into C# namespace \n\ diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 3387dd755..419828ea1 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -4649,7 +4649,7 @@ extern "C" Language *swig_d(void) { /* ----------------------------------------------------------------------------- * Usage information displayed at the command line. * ----------------------------------------------------------------------------- */ -const char *D::usage = (char *) "\ +const char *D::usage = "\ D Options (available with -d)\n\ -d2 - Generate code for D2/Phobos (default: D1/Tango)\n\ -package - Write generated D modules into package \n\ diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index c2d3948d4..e84109faf 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -5019,7 +5019,7 @@ extern "C" Language *swig_go(void) { * ----------------------------------------------------------------------------- */ // Usage message. -const char * const GO::usage = (char *) "\ +const char * const GO::usage = "\ Go Options (available with -go)\n\ -gccgo - Generate code for gccgo rather than 6g/8g\n\ -go-pkgpath

      - Like gccgo -fgo-pkgpath option\n\ diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index 3a82d67d8..a9e51fd1b 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -16,7 +16,7 @@ #include // Note string broken in half for compilers that can't handle long strings -static const char *usage = (char *) "\ +static const char *usage = "\ Guile Options (available with -guile)\n\ -emitsetters - Emit procedures-with-setters for variables\n\ and structure slots.\n\ @@ -1018,7 +1018,7 @@ public: if (in_class) goops_name = NewString(memberfunction_name); else - goops_name = goopsNameMapping(proc_name, (char *) ""); + goops_name = goopsNameMapping(proc_name, ""); String *primitive_name = NewString(""); if (primRenamer) Printv(primitive_name, "primitive:", proc_name, NIL); @@ -1204,7 +1204,7 @@ public: // export wrapper into goops file if (!in_class) { // only if the variable is not part of a class String *class_name = SwigType_typedef_resolve_all(SwigType_base(t)); - String *goops_name = goopsNameMapping(proc_name, (char *) ""); + String *goops_name = goopsNameMapping(proc_name, ""); String *primitive_name = NewString(""); if (primRenamer) Printv(primitive_name, "primitive:", NIL); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index eda3ba7c8..9e16bb422 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -4643,7 +4643,7 @@ extern "C" Language *swig_java(void) { * Static member variables * ----------------------------------------------------------------------------- */ -const char *JAVA::usage = (char *) "\ +const char *JAVA::usage = "\ Java Options (available with -java)\n\ -nopgcpp - Suppress premature garbage collection prevention parameter\n\ -noproxy - Generate the low-level functional interface instead\n\ diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index ad4ba1925..46e21fb91 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -86,7 +86,7 @@ extern "C" you can add new ones here (though for now I have not bothered) NEW LANGUAGE NOTE:END ************************************************/ -static const char *usage = (char *) "\ +static const char *usage = "\ Lua Options (available with -lua)\n\ -elua - Generates LTR compatible wrappers for smaller devices running elua\n\ -eluac - LTR compatible wrappers in \"crass compress\" mode for elua\n\ diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index 66e2548dc..833394b9c 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -160,9 +160,9 @@ static String *SwigLib = 0; // Library directory static String *SwigLibWinUnix = 0; // Extra library directory on Windows static int freeze = 0; static String *lang_config = 0; -static char *hpp_extension = (char *) "h"; -static char *cpp_extension = (char *) "cxx"; -static char *depends_extension = (char *) "d"; +static const char *hpp_extension = "h"; +static const char *cpp_extension = "cxx"; +static const char *depends_extension = "d"; static String *outdir = 0; static String *xmlout = 0; static int outcurrentdir = 0; @@ -324,7 +324,7 @@ const String *SWIG_output_directory() { } void SWIG_config_cppext(const char *ext) { - cpp_extension = (char *) ext; + cpp_extension = ext; } List *SWIG_output_files() { @@ -465,7 +465,7 @@ void SWIG_getoptions(int argc, char *argv[]) { Swig_mark_arg(i); } else if (strncmp(argv[i], "-D", 2) == 0) { String *d = NewString(argv[i] + 2); - Replace(d, (char *) "=", (char *) " ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST); + Replace(d, "=", " ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST); Preprocessor_define((DOH *) d, 0); Delete(d); // Create a symbol diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index 4c56d0664..db5d0981b 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -3956,7 +3956,7 @@ extern "C" Language *swig_modula3(void) { * Static member variables * ----------------------------------------------------------------------------- */ -const char *MODULA3::usage = (char *) "\ +const char *MODULA3::usage = "\ Modula 3 Options (available with -modula3)\n\ -generateconst - Generate code for computing numeric values of constants\n\ -generaterename - Generate suggestions for %rename\n\ diff --git a/Source/Modules/mzscheme.cxx b/Source/Modules/mzscheme.cxx index a147dd9c4..ed9641b30 100644 --- a/Source/Modules/mzscheme.cxx +++ b/Source/Modules/mzscheme.cxx @@ -15,7 +15,7 @@ #include -static const char *usage = (char *) "\ +static const char *usage = "\ Mzscheme Options (available with -mzscheme)\n\ -declaremodule - Create extension that declares a module\n\ -dynamic-load ,[library,...] - Do not link with these libraries, dynamic load\n\ @@ -36,7 +36,7 @@ static bool declaremodule = false; static bool noinit = false; static String *load_libraries = NULL; static String *module = 0; -static char *mzscheme_path = (char *) "mzscheme"; +static const char *mzscheme_path = "mzscheme"; static String *init_func_def = 0; static File *f_begin = 0; diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index f60c13ed3..f1ec8a8cf 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -15,7 +15,7 @@ #include -static const char *usage = (char *) "\ +static const char *usage = "\ Ocaml Options (available with -ocaml)\n\ -oldvarnames - Old intermediary method names for variable wrappers\n\ -prefix - Set a prefix to be prepended to all names\n\ @@ -29,7 +29,7 @@ static int const_enum = 0; static int static_member_function = 0; static int generate_sizeof = 0; static String *prefix = 0; -static char *ocaml_path = (char *) "ocaml"; +static const char *ocaml_path = "ocaml"; static bool old_variable_names = false; static String *classname = 0; static String *module = 0; diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 14118972d..103b59194 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -17,7 +17,7 @@ static String *global_name = 0; static String *op_prefix = 0; -static const char *usage = (char *) "\ +static const char *usage = "\ Octave Options (available with -octave)\n\ -globals - Set used to access C global variables [default: 'cvar']\n\ Use '.' to load C global variables into module namespace\n\ diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 28f4a3f3d..ff504d461 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -17,7 +17,7 @@ static int treduce = SWIG_cparse_template_reduce(0); #include -static const char *usage = (char *) "\ +static const char *usage = "\ Perl5 Options (available with -perl5)\n\ -compat - Compatibility mode\n\ -const - Wrap constants as constants and not variables (implies -proxy)\n\ diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index d497302db..86e1274a8 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -42,7 +42,7 @@ #include #include -static const char *usage = (char *) "\ +static const char *usage = "\ PHP Options (available with -php)\n\ -cppext - Change C++ file extension to (default is cpp)\n\ -noproxy - Don't generate proxy classes.\n\ diff --git a/Source/Modules/pike.cxx b/Source/Modules/pike.cxx index cdbddc15d..22c5a638b 100644 --- a/Source/Modules/pike.cxx +++ b/Source/Modules/pike.cxx @@ -33,7 +33,7 @@ #include // for isalnum() -static const char *usage = (char *) "\ +static const char *usage = "\ Pike Options (available with -pike)\n\ [no additional options]\n\ \n"; diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 13ddbfb61..06c1c4868 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -107,7 +107,7 @@ enum autodoc_t { }; -static const char *usage1 = (char *) "\ +static const char *usage1 = "\ Python Options (available with -python)\n\ -aliasobj0 - Alias obj0 when using fastunpack, needed for some old typemaps \n\ -buildnone - Use Py_BuildValue(" ") to obtain Py_None (default in Windows)\n\ @@ -127,7 +127,7 @@ Python Options (available with -python)\n\ -keyword - Use keyword arguments\n\ -modern - Use modern python features only, without compatibility code\n\ -modernargs - Use \"modern\" args mechanism to pack/unpack the function arguments\n"; -static const char *usage2 = (char *) "\ +static const char *usage2 = "\ -newrepr - Use more informative version of __repr__ in proxy classes (default) \n\ -newvwm - New value wrapper mode, use only when everything else fails \n\ -noaliasobj0 - Don't generate an obj0 alias when using fastunpack (default) \n\ @@ -144,7 +144,7 @@ static const char *usage2 = (char *) "\ -noh - Don't generate the output header file\n\ -nomodern - Don't use modern python features which are not backwards compatible \n\ -nomodernargs - Use classic ParseTuple/CallFunction methods to pack/unpack the function arguments (default) \n"; -static const char *usage3 = (char *) "\ +static const char *usage3 = "\ -noolddefs - Don't emit the old method definitions even when using fastproxy (default) \n\ -nooutputtuple - Use a PyList for appending output values (default) \n\ -noproxy - Don't generate proxy classes \n\ diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 0a3fb722b..3befcfbdd 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -205,7 +205,7 @@ static void writeListByLine(List *l, File *out, bool quote = 0) { } -static const char *usage = (char *)"\ +static const char *usage = "\ R Options (available with -r)\n\ -copystruct - Emit R code to copy C structs (on by default)\n\ -cppcast - Enable C++ casting operators (default) \n\ diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 5ff599d54..6aeaae5a1 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -130,7 +130,7 @@ enum autodoc_t { AUTODOC_NONE }; -static const char *usage = (char *) "\ +static const char *usage = "\ Ruby Options (available with -ruby)\n\ -autorename - Enable renaming of classes and methods to follow Ruby coding standards\n\ -cppcast - Enable C++ casting operators (default)\n\ @@ -1111,7 +1111,7 @@ public: /* typedef void *VALUE */ SwigType *value = NewSwigType(T_VOID); SwigType_add_pointer(value); - SwigType_typedef(value, (char *) "VALUE"); + SwigType_typedef(value, "VALUE"); Delete(value); /* Set module name */ diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx index e61071167..ac356098b 100644 --- a/Source/Modules/tcl8.cxx +++ b/Source/Modules/tcl8.cxx @@ -15,7 +15,7 @@ #include "cparse.h" static int treduce = SWIG_cparse_template_reduce(0); -static const char *usage = (char *) "\ +static const char *usage = "\ Tcl 8 Options (available with -tcl)\n\ -itcl - Enable ITcl support\n\ -nosafe - Leave out SafeInit module function.\n\ diff --git a/Source/Modules/uffi.cxx b/Source/Modules/uffi.cxx index b0136a361..d56ed3b1f 100644 --- a/Source/Modules/uffi.cxx +++ b/Source/Modules/uffi.cxx @@ -15,7 +15,7 @@ #include "swigmod.h" -static const char *usage = (char *) "\ +static const char *usage = "\ UFFI Options (available with -uffi)\n\ -identifier-converter - \n\ Specifies the type of conversion to do on C identifiers\n\ diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index ec0acfa77..d15c2e12f 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -467,7 +467,7 @@ static String *Swig_cmethod_call(const_String_or_char_ptr name, ParmList *parms, return func; if (!self) - self = (char *) "(this)->"; + self = "(this)->"; Append(func, self); if (SwigType_istemplate(name) && (strncmp(Char(name), "operator ", 9) == 0)) {