diff options
Diffstat (limited to 'Examples')
46 files changed, 443 insertions, 146 deletions
diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 46193348d..5a4639076 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -687,20 +687,47 @@ JSINCLUDES = @JSCOREINC@ @JSV8INC@ JSDYNAMICLINKING = @JSCOREDYNAMICLINKING@ @JSV8DYNAMICLINKING@ NODEJS = @NODEJS@ NODEGYP = @NODEGYP@ +ifneq (, $(ENGINE)) + JSENGINE=$(ENGINE) +else +ifneq (, $(NODEJS)) + JSENGINE=node +else +ifneq (, @JSCENABLED@) + JSENGINE=jsc +else +ifneq (, @JSV8ENABLED@) + JSENGINE=v8 +else + # Shouldn't happen, but avoid empty value if it does. + JSENGINE=node +endif +endif +endif +endif # ---------------------------------------------------------------- # Creating and building Javascript wrappers # ---------------------------------------------------------------- javascript_wrapper: - $(SWIG) -javascript $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.c $(INTERFACEPATH) +ifeq (node,$(JSENGINE)) + $(SWIG) -javascript $(SWIGOPT) -$(JSENGINE) -o $(INTERFACEDIR)$(TARGET)_wrap.cxx $(INTERFACEPATH) +else + $(SWIG) -javascript $(SWIGOPT) -$(JSENGINE) -o $(INTERFACEDIR)$(TARGET)_wrap.c $(INTERFACEPATH) +endif javascript_wrapper_cpp: $(SRCDIR_SRCS) - $(SWIG) -javascript -c++ $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.cxx $(INTERFACEPATH) + $(SWIG) -javascript -c++ $(SWIGOPT) -$(JSENGINE) -o $(INTERFACEDIR)$(TARGET)_wrap.cxx $(INTERFACEPATH) javascript_build: $(SRCDIR_SRCS) +ifeq (node,$(JSENGINE)) + sed -e 's|$$srcdir|./$(SRCDIR)|g' $(SRCDIR)binding.gyp.in > binding.gyp + MAKEFLAGS= $(NODEGYP) --loglevel=silent configure build 1>>/dev/null +else $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(JSINCLUDES) - $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + $(LDSHARED) $(CCSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +endif javascript_build_cpp: $(SRCDIR_SRCS) ifeq (node,$(JSENGINE)) @@ -709,7 +736,6 @@ ifeq (node,$(JSENGINE)) else $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(JSINCLUDES) $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) - endif # These targets are used by the test-suite: @@ -967,7 +993,7 @@ ocaml_static_toplevel: $(SRCDIR_SRCS) ocaml_static_cpp: $(SRCDIR_SRCS) $(SWIG) -ocaml -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c) - $(OCC) -cc '$(CXX) $(CPPFLAGS)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" $(ICXXSRCS:%.cxx=%.c) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) + $(OCC) -cc '$(CXX) $(CPPFLAGS) $(CXXFLAGS)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" $(ICXXSRCS:%.cxx=%.c) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(OCC) -g -c $(INTERFACE:%.i=%.mli) $(OCC) -w -U -g -c $(INTERFACE:%.i=%.ml) test -z "$(PROGFILE)" || $(OCC_WITH_PP) -o $(PROGFILE:%.ml=%) $(OCAMLPP) -c $(SRCDIR)$(PROGFILE) @@ -976,7 +1002,7 @@ ocaml_static_cpp: $(SRCDIR_SRCS) ocaml_static_cpp_toplevel: $(SRCDIR_SRCS) $(SWIG) -ocaml -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c) - $(OCC) -cc '$(CXX) $(CPPFLAGS)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" $(ICXXSRCS:%.cxx=%.c) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) + $(OCC) -cc '$(CXX) $(CPPFLAGS) $(CXXFLAGS)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" $(ICXXSRCS:%.cxx=%.c) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(OCC) -g -c $(INTERFACE:%.i=%.mli) $(OCC) -w -U -g -c $(INTERFACE:%.i=%.ml) test -z "$(PROGFILE)" || $(OCC_WITH_PP) -o $(PROGFILE:%.ml=%) $(OCAMLPP) -c $(SRCDIR)$(PROGFILE) @@ -985,7 +1011,7 @@ ocaml_static_cpp_toplevel: $(SRCDIR_SRCS) ocaml_dynamic_cpp: $(SRCDIR_SRCS) $(SWIG) -ocaml -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c) - $(OCC) -cc '$(CXX) $(CPPFLAGS)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" $(ICXXSRCS:%.cxx=%.c) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) -ccopt -fPIC + $(OCC) -cc '$(CXX) $(CPPFLAGS) $(CXXFLAGS)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" $(ICXXSRCS:%.cxx=%.c) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) -ccopt -fPIC $(CXXSHARED) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $(INTERFACE:%.i=%@SO@) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) $(CPP_DLLIBS) $(LIBS) $(OCAMLDLGEN) $(INTERFACE:%.i=%.ml) $(INTERFACE:%.i=%@SO@) > $(INTERFACE:%.i=%_dynamic.ml) mv $(INTERFACE:%.i=%_dynamic.ml) $(INTERFACE:%.i=%.ml) diff --git a/Examples/javascript/class/Makefile b/Examples/javascript/class/Makefile index 54a8f7b03..b6805576e 100644 --- a/Examples/javascript/class/Makefile +++ b/Examples/javascript/class/Makefile @@ -1,3 +1,4 @@ -SRCS = example.cxx +CXXSRCS = example.cxx +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/constant/Makefile b/Examples/javascript/constant/Makefile index 0402f8d09..a80ecf16f 100644 --- a/Examples/javascript/constant/Makefile +++ b/Examples/javascript/constant/Makefile @@ -1,3 +1 @@ -SRCS = - include $(SRCDIR)../example.mk diff --git a/Examples/javascript/enum/Makefile b/Examples/javascript/enum/Makefile index 54a8f7b03..b6805576e 100644 --- a/Examples/javascript/enum/Makefile +++ b/Examples/javascript/enum/Makefile @@ -1,3 +1,4 @@ -SRCS = example.cxx +CXXSRCS = example.cxx +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/example.mk b/Examples/javascript/example.mk index 3ef012aa8..5a9ba8a99 100644 --- a/Examples/javascript/example.mk +++ b/Examples/javascript/example.mk @@ -1,12 +1,6 @@ # Note: as a convention an example must be in a child directory of this. # These paths are relative to such an example directory -ifneq (, $(ENGINE)) - JSENGINE=$(ENGINE) -else - JSENGINE=node -endif - ifneq (, $(V8_VERSION)) JSV8_VERSION=$(V8_VERSION) else @@ -19,18 +13,22 @@ SWIGEXE = $(SWIG_TOP)/swig SWIG_LIB_DIR = $(SWIG_TOP)/$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib TARGET = example INTERFACE = example.i -SWIGOPT = -$(JSENGINE) -DV8_VERSION=$(JSV8_VERSION) +SWIGOPT = + +ifneq (jsc, $(ENGINE)) +SWIGOPT += -DV8_VERSION=$(JSV8_VERSION) +endif check: build - $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' JSENGINE='$(JSENGINE)' TARGET='$(TARGET)' javascript_run + $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' javascript_run build: - $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(SRCS)' \ - SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp - $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(SRCS)' \ - SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' JSENGINE='$(JSENGINE)' javascript_build_cpp + $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SRCS='$(SRCS)' SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper$(_CPP) + $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SRCS='$(SRCS)' SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build$(_CPP) clean: $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' javascript_clean diff --git a/Examples/javascript/exception/Makefile b/Examples/javascript/exception/Makefile index 54a8f7b03..b6805576e 100644 --- a/Examples/javascript/exception/Makefile +++ b/Examples/javascript/exception/Makefile @@ -1,3 +1,4 @@ -SRCS = example.cxx +CXXSRCS = example.cxx +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/functor/Makefile b/Examples/javascript/functor/Makefile index 0402f8d09..8085356b1 100644 --- a/Examples/javascript/functor/Makefile +++ b/Examples/javascript/functor/Makefile @@ -1,3 +1,3 @@ -SRCS = +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/native/Makefile b/Examples/javascript/native/Makefile index 0402f8d09..8085356b1 100644 --- a/Examples/javascript/native/Makefile +++ b/Examples/javascript/native/Makefile @@ -1,3 +1,3 @@ -SRCS = +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/nspace/Makefile b/Examples/javascript/nspace/Makefile index 0402f8d09..8085356b1 100644 --- a/Examples/javascript/nspace/Makefile +++ b/Examples/javascript/nspace/Makefile @@ -1,3 +1,3 @@ -SRCS = +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/operator/Makefile b/Examples/javascript/operator/Makefile index 0402f8d09..8085356b1 100644 --- a/Examples/javascript/operator/Makefile +++ b/Examples/javascript/operator/Makefile @@ -1,3 +1,3 @@ -SRCS = +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/overload/Makefile b/Examples/javascript/overload/Makefile index 0402f8d09..8085356b1 100644 --- a/Examples/javascript/overload/Makefile +++ b/Examples/javascript/overload/Makefile @@ -1,3 +1,3 @@ -SRCS = +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/pointer/Makefile b/Examples/javascript/pointer/Makefile index 54a8f7b03..413b64bbd 100644 --- a/Examples/javascript/pointer/Makefile +++ b/Examples/javascript/pointer/Makefile @@ -1,3 +1,3 @@ -SRCS = example.cxx +SRCS = example.c include $(SRCDIR)../example.mk diff --git a/Examples/javascript/pointer/binding.gyp.in b/Examples/javascript/pointer/binding.gyp.in index cb2b45e8f..cfd4854b0 100644 --- a/Examples/javascript/pointer/binding.gyp.in +++ b/Examples/javascript/pointer/binding.gyp.in @@ -2,7 +2,7 @@ "targets": [ { "target_name": "example", - "sources": [ "<!(cp $srcdir/example.cxx example-gypcopy.cxx && echo example-gypcopy.cxx)", "example_wrap.cxx" ], + "sources": [ "<!(cp $srcdir/example.c example-gypcopy.cxx && echo example-gypcopy.cxx)", "example_wrap.cxx" ], "include_dirs": ["$srcdir"] } ] diff --git a/Examples/javascript/pointer/example.cxx b/Examples/javascript/pointer/example.c index 8762329fe..8762329fe 100644 --- a/Examples/javascript/pointer/example.cxx +++ b/Examples/javascript/pointer/example.c diff --git a/Examples/javascript/reference/Makefile b/Examples/javascript/reference/Makefile index 54a8f7b03..b6805576e 100644 --- a/Examples/javascript/reference/Makefile +++ b/Examples/javascript/reference/Makefile @@ -1,3 +1,4 @@ -SRCS = example.cxx +CXXSRCS = example.cxx +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/simple/Makefile b/Examples/javascript/simple/Makefile index 54a8f7b03..413b64bbd 100644 --- a/Examples/javascript/simple/Makefile +++ b/Examples/javascript/simple/Makefile @@ -1,3 +1,3 @@ -SRCS = example.cxx +SRCS = example.c include $(SRCDIR)../example.mk diff --git a/Examples/javascript/simple/binding.gyp.in b/Examples/javascript/simple/binding.gyp.in index cb2b45e8f..cfd4854b0 100644 --- a/Examples/javascript/simple/binding.gyp.in +++ b/Examples/javascript/simple/binding.gyp.in @@ -2,7 +2,7 @@ "targets": [ { "target_name": "example", - "sources": [ "<!(cp $srcdir/example.cxx example-gypcopy.cxx && echo example-gypcopy.cxx)", "example_wrap.cxx" ], + "sources": [ "<!(cp $srcdir/example.c example-gypcopy.cxx && echo example-gypcopy.cxx)", "example_wrap.cxx" ], "include_dirs": ["$srcdir"] } ] diff --git a/Examples/javascript/simple/example.cxx b/Examples/javascript/simple/example.c index 1c2af789c..1c2af789c 100644 --- a/Examples/javascript/simple/example.cxx +++ b/Examples/javascript/simple/example.c diff --git a/Examples/javascript/template/Makefile b/Examples/javascript/template/Makefile index 0402f8d09..8085356b1 100644 --- a/Examples/javascript/template/Makefile +++ b/Examples/javascript/template/Makefile @@ -1,3 +1,3 @@ -SRCS = +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/variables/Makefile b/Examples/javascript/variables/Makefile index 54a8f7b03..413b64bbd 100644 --- a/Examples/javascript/variables/Makefile +++ b/Examples/javascript/variables/Makefile @@ -1,3 +1,3 @@ -SRCS = example.cxx +SRCS = example.c include $(SRCDIR)../example.mk diff --git a/Examples/javascript/variables/binding.gyp.in b/Examples/javascript/variables/binding.gyp.in index cb2b45e8f..cfd4854b0 100644 --- a/Examples/javascript/variables/binding.gyp.in +++ b/Examples/javascript/variables/binding.gyp.in @@ -2,7 +2,7 @@ "targets": [ { "target_name": "example", - "sources": [ "<!(cp $srcdir/example.cxx example-gypcopy.cxx && echo example-gypcopy.cxx)", "example_wrap.cxx" ], + "sources": [ "<!(cp $srcdir/example.c example-gypcopy.cxx && echo example-gypcopy.cxx)", "example_wrap.cxx" ], "include_dirs": ["$srcdir"] } ] diff --git a/Examples/javascript/variables/example.cxx b/Examples/javascript/variables/example.c index 15314b383..15314b383 100644 --- a/Examples/javascript/variables/example.cxx +++ b/Examples/javascript/variables/example.c diff --git a/Examples/ocaml/strings_test/example.i b/Examples/ocaml/strings_test/example.i index d360715c1..e0697b061 100644 --- a/Examples/ocaml/strings_test/example.i +++ b/Examples/ocaml/strings_test/example.i @@ -12,4 +12,5 @@ using std::string; %} %include "std_string.i" +%apply std::string& INOUT { std::string &inout } %include example.h diff --git a/Examples/scilab/matrix2/example.c b/Examples/scilab/matrix2/example.c index 476067df9..232c88824 100644 --- a/Examples/scilab/matrix2/example.c +++ b/Examples/scilab/matrix2/example.c @@ -29,12 +29,12 @@ void squareDoubleMatrix(double *inputMatrix, int nbRow, int nbCol, double** resu } } -void getDoubleMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes) +void getDoubleMatrix(int nbRow, int nbCol, double **resultMatrix, int *nbRowRes, int *nbColRes) { int i; int size; - *nbRowRes = 5; - *nbColRes = 3; + *nbRowRes = nbRow; + *nbColRes = nbCol; size = (*nbRowRes) * (*nbColRes); *resultMatrix = (double*) malloc(size * sizeof(double)); for (i=0; i<size; i++) @@ -43,6 +43,30 @@ void getDoubleMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes) } } +void extractDoubleMatrix(double *inputMatrix, int nbRow, int nbCol, int* indexes, int nbIndexes, double **resultMatrix, int *nbRowRes, int *nbColRes) +{ + if (nbIndexes < 0) + { + int sz = nbRow * nbCol; + *nbRowRes = sz; + *nbColRes = 1; + + *resultMatrix = malloc(sz * sizeof(double)); + memcpy(*resultMatrix, inputMatrix, sz * sizeof(double)); + } else { + int i; + + *nbRowRes = nbIndexes; + *nbColRes = 1; + + *resultMatrix = malloc(nbIndexes * sizeof(double)); + for (i = 0; i < nbIndexes; i++) + { + (*resultMatrix)[i] = inputMatrix[indexes[i]]; + } + } +} + // Integer matrix functions int sumIntegerMatrix(int *inputMatrix, int nbRow, int nbCol) diff --git a/Examples/scilab/matrix2/example.i b/Examples/scilab/matrix2/example.i index e37cd116c..1584691cc 100644 --- a/Examples/scilab/matrix2/example.i +++ b/Examples/scilab/matrix2/example.i @@ -4,6 +4,7 @@ %apply (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (double *inputMatrix, int nbRow, int nbCol) } %apply (double **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) { (double **resultMatrix, int *nbRowRes, int *nbColRes) } +%apply (int *IN, int IN_SIZE) { (int* indexes, int nbIndexes) } %apply (int *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (int *inputMatrix, int nbRow, int nbCol) } %apply (int **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) { (int **resultMatrix, int *nbRowRes, int *nbColRes) } @@ -14,7 +15,8 @@ %inline %{ extern double sumDoubleMatrix(double *inputMatrix, int nbRow, int nbCol); extern void squareDoubleMatrix(double *inputMatrix, int nbRow, int nbCol, double **resultMatrix, int *nbRowRes, int *nbColRes); - extern void getDoubleMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes); + extern void getDoubleMatrix(int nbRow, int nbCol,double **resultMatrix, int *nbRowRes, int *nbColRes); + extern void extractDoubleMatrix(double *inputMatrix, int nbRow, int nbCol, int* indexes, int nbIndexes, double **resultMatrix, int *nbRowRes, int *nbColRes); extern int sumIntegerMatrix(int *inputMatrix, int nbRow, int nbCol); extern void squareIntegerMatrix(int *inputMatrix, int nbRow, int nbCol, int **resultMatrix, int *nbRowRes, int *nbColRes); diff --git a/Examples/scilab/matrix2/runme.sci b/Examples/scilab/matrix2/runme.sci index 0af7df4e7..4264991e8 100644 --- a/Examples/scilab/matrix2/runme.sci +++ b/Examples/scilab/matrix2/runme.sci @@ -8,7 +8,7 @@ end // Test lib double matrix functions disp("Call lib function getDoubleMatrix()"); -doubleMatrix = getDoubleMatrix(); +doubleMatrix = getDoubleMatrix(5, 3); disp(doubleMatrix); disp("Call lib function sumDoubleMatrix()"); @@ -19,6 +19,12 @@ disp("Call lib function squareDoubleMatrix()"); sqrd = squareDoubleMatrix(doubleMatrix); disp(sqrd); +disp("Extract various indexes"); +disp(extractDoubleMatrix(doubleMatrix, 2)); +disp(extractDoubleMatrix(doubleMatrix, 2:5)); +disp(extractDoubleMatrix(doubleMatrix, :)); + + // Test lib integer matrix functions diff --git a/Examples/test-suite/argcargvtest.i b/Examples/test-suite/argcargvtest.i index 5711441d9..e14e370d8 100644 --- a/Examples/test-suite/argcargvtest.i +++ b/Examples/test-suite/argcargvtest.i @@ -1,6 +1,6 @@ %module argcargvtest -#if !defined(SWIGCSHARP) && !defined(SWIGD) && !defined(SWIGGO) && !defined(SWIGGUILE) && !defined(SWIGJAVA) && !defined(SWIGJAVASCRIPT) && !defined(SWIGMZSCHEME) && !defined(SWIGOCAML) && !defined(SWIGR) && !defined(SWIGSCILAB) +#if !defined(SWIGCSHARP) && !defined(SWIGD) && !defined(SWIGGUILE) && !defined(SWIGJAVA) && !defined(SWIGJAVASCRIPT) && !defined(SWIGMZSCHEME) && !defined(SWIGOCAML) && !defined(SWIGR) && !defined(SWIGSCILAB) %include <argcargv.i> %apply (int ARGC, char **ARGV) { (size_t argc, const char **argv) } diff --git a/Examples/test-suite/arrays.i b/Examples/test-suite/arrays.i index 07162aa90..f98dd0718 100644 --- a/Examples/test-suite/arrays.i +++ b/Examples/test-suite/arrays.i @@ -73,4 +73,8 @@ typedef struct { cartPosition_t p; } CartPoseData_t; +/* Test left shift in array size doesn't trigger "Bad template type" error. + * Regression test for https://sourceforge.net/p/swig/bugs/983/ */ +char array_shifted_size[(1<<2)]; + %} diff --git a/Examples/test-suite/go/argcargvtest_runme.go b/Examples/test-suite/go/argcargvtest_runme.go new file mode 100644 index 000000000..3da3d76dd --- /dev/null +++ b/Examples/test-suite/go/argcargvtest_runme.go @@ -0,0 +1,22 @@ +package main + +import wrap "swigtests/argcargvtest" + +func main() { + largs := []string{"hi", "hola", "hello"} + if ri := wrap.Mainc(largs); ri != 3 { + panic(ri) + } + + targs := []string{"hi", "hola"} + if rs := wrap.Mainv(targs, 1); rs != "hola" { + panic(rs) + } + +// For dynamically typed languages we test this throws an exception or similar +// at runtime, but for Go this doesn't even compile (but we can't easily +// test for that here). +// wrap.Mainv("hello", 1) + + wrap.InitializeApp(largs) +} diff --git a/Examples/test-suite/javascript/Makefile.in b/Examples/test-suite/javascript/Makefile.in index 4835453cc..b2acbd8f2 100644 --- a/Examples/test-suite/javascript/Makefile.in +++ b/Examples/test-suite/javascript/Makefile.in @@ -25,9 +25,22 @@ SWIGEXE = $(top_builddir)/swig SWIG_LIB_DIR = $(top_srcdir)/Lib ifneq (, $(ENGINE)) - JSENGINE=$(ENGINE) + JSENGINE=$(ENGINE) else - JSENGINE=node +ifneq (, $(NODEJS)) + JSENGINE=node +else +ifneq (, @JSCENABLED@) + JSENGINE=jsc +else +ifneq (, @JSV8ENABLED@) + JSENGINE=v8 +else + # Shouldn't happen, but avoid empty value if it does. + JSENGINE=node +endif +endif +endif endif ifneq (, $(V8_VERSION)) @@ -47,9 +60,9 @@ _setup = \ echo "$(ACTION)ing $(LANGUAGE) ($(JSENGINE)) testcase $*" ; \ fi; -ifeq (node,$(JSENGINE)) +SWIGOPT += -$(JSENGINE) - SWIGOPT += -v8 -DBUILDING_NODE_EXTENSION=1 +ifeq (node,$(JSENGINE)) # shut up some warnings @@ -105,8 +118,6 @@ ifeq (node,$(JSENGINE)) else - SWIGOPT += -$(JSENGINE) - run_testcase = \ if [ -f $(srcdir)/$*$(SCRIPTSUFFIX) ]; then \ $(RUNTOOL) $(top_builddir)/Tools/javascript/javascript -$(JSENGINE) $(srcdir)/$*$(SCRIPTSUFFIX); \ diff --git a/Examples/test-suite/javascript/ignore_parameter_runme.js b/Examples/test-suite/javascript/ignore_parameter_runme.js new file mode 100644 index 000000000..07dcf2f7d --- /dev/null +++ b/Examples/test-suite/javascript/ignore_parameter_runme.js @@ -0,0 +1,24 @@ +const ignore_parameter = require('ignore_parameter'); + +function check(a, b) { + if (a !== b) throw new Error(`'${a}' != '${b}`); +} + +check(ignore_parameter.jaguar(200, 0), "hello"); +check(ignore_parameter.lotus("foo", 1), 101); +check(ignore_parameter.tvr("bar", 2), 8.8); +check(ignore_parameter.ferrari(), 101); +check(ignore_parameter.fiat(17), 17); + +car = new ignore_parameter.SportsCars(); +check(car.daimler(200, 0), "hello"); +check(car.astonmartin("foo", 1), 101); +check(car.bugatti("bar", 2), 8.8); +check(car.lamborghini(), 101); +check(car.maseratti(289), 289); +check(car.audi(), 8.8); + +new ignore_parameter.MiniCooper(200, 0); +new ignore_parameter.MorrisMinor("baz", 0); +new ignore_parameter.FordAnglia("quux", 200); +new ignore_parameter.AustinAllegro(); diff --git a/Examples/test-suite/li_std_string.i b/Examples/test-suite/li_std_string.i index 47a9090b7..6f8fec130 100644 --- a/Examples/test-suite/li_std_string.i +++ b/Examples/test-suite/li_std_string.i @@ -1,9 +1,10 @@ %module li_std_string %include <std_string.i> -#if defined(SWIGUTL) +#if defined(SWIGLUA) || defined(SWIGPHP) || defined(SWIGUTL) %apply std::string& INPUT { std::string &input } %apply std::string& INOUT { std::string &inout } +%apply std::string& OUTPUT { std::string &output } #endif // throw is invalid in C++17 and later, only SWIG to use it @@ -53,13 +54,28 @@ std::string& test_reference_out() { } std::string test_reference_input(std::string &input) { - return input; + // For PHP to allow checking that we haven't used the default string& + // typemap which wraps as a PHP pass-by-reference string parameter. + std::string copy = input; + input = "MODIFIED"; + return copy; } void test_reference_inout(std::string &inout) { inout += inout; } +void test_reference_output(std::string &output) { + output = "output"; +} + +#ifdef SWIGPHP +// Test PHP-specific default wrapping string& as pass-by-ref PHP string. +void test_reference_php(std::string &s) { + s += ".php"; +} +#endif + void test_throw() TESTCASE_THROW1(std::string){ static std::string x = "test_throw message"; throw x; diff --git a/Examples/test-suite/lua/li_std_string_runme.lua b/Examples/test-suite/lua/li_std_string_runme.lua index 40de81e44..4e6dbe7f1 100644 --- a/Examples/test-suite/lua/li_std_string_runme.lua +++ b/Examples/test-suite/lua/li_std_string_runme.lua @@ -44,6 +44,12 @@ test_reference(robj) test_reference(obj) -- object ptr is ok test_reference(cobj) -- obj const ptr is also ok +-- Test INPUT, INOUT and OUTPUT string& typemaps: +assert(test_reference_input("hello")=="hello") +s=test_reference_inout("hello") +assert(s=="hellohello") +assert(test_reference_output()=="output") + -- throwing string ok,ex=pcall(test_throw) assert(ok==false and type(ex)=="string") -- failed & threw string diff --git a/Examples/test-suite/ocaml/extend_template_method_runme.ml b/Examples/test-suite/ocaml/extend_template_method_runme.ml new file mode 100644 index 000000000..5f418c927 --- /dev/null +++ b/Examples/test-suite/ocaml/extend_template_method_runme.ml @@ -0,0 +1,20 @@ +open Swig +open Extend_template_method + +let _ = + let em = new_ExtendMe '() in + assert (em -> do_stuff_double (1, 1.1) as float = 1.1); + assert (em -> do_stuff_string (1, "hello there") as string = "hello there"); + assert (em -> do_overloaded_stuff (1.1) as float = 1.1); + assert (em -> do_overloaded_stuff ("hello there") as string = "hello there"); + + assert (_ExtendMe_static_method '(123) as int = 123); + ignore (new_ExtendMe '(123)); + let em = new_TemplateExtend '() in + assert (em -> do_template_stuff_double (1, 1.1) as float = 1.1); + assert (em -> do_template_stuff_string (1, "hello there") as string = "hello there"); + assert (em -> do_template_overloaded_stuff (1.1) as float = 1.1); + assert (em -> do_template_overloaded_stuff ("hello there") as string = "hello there"); + assert (_TemplateExtend_static_template_method '(123) as int = 123); + ignore (new_TemplateExtend '(123)) +;; diff --git a/Examples/test-suite/ocaml/li_std_string_runme.ml b/Examples/test-suite/ocaml/li_std_string_runme.ml new file mode 100644 index 000000000..5f8c98a6b --- /dev/null +++ b/Examples/test-suite/ocaml/li_std_string_runme.ml @@ -0,0 +1,44 @@ +open Swig +open Li_std_string + +let _ = + assert (_test_value '("Fee") as string = "Fee"); + try + ignore (_test_value '(None)); assert false + with Invalid_argument _ -> () + + assert (_test_const_reference '("Fee") as string = "Fee"); + try + ignore (_test_const_reference '(None)); assert false + with Invalid_argument _ -> () + + let stringPtr = _test_pointer_out '() in + ignore (_test_pointer '(stringPtr)); + let stringPtr = _test_const_pointer_out '() in + ignore (_test_const_pointer '(stringPtr)); + let stringPtr = _test_reference_out '() in + ignore (_test_reference '(stringPtr)); + + try + ignore (_test_throw '()); assert false + with Failure s -> assert (s = "test_throw message") + try + ignore (_test_const_reference_throw '()); assert false + with Failure s -> assert (s = "test_const_reference_throw message") + assert (_GlobalString2 '() as string = "global string 2"); + let s = C_string "initial string" in + ignore (_GlobalString2 '(s)); + assert (_GlobalString2 '() = s); + assert (_ConstGlobalString '() as string = "const global string"); + + let myStructure = new_Structure '() in + assert (myStructure -> "[MemberString2]" () as string = "member string 2"); + assert (myStructure -> "[MemberString2]" (s) = C_void); + assert (myStructure -> "[MemberString2]" () = s); + assert (myStructure -> "[ConstMemberString]" () as string = "const member string"); + + assert (_Structure_StaticMemberString2 '() as string = "static member string 2"); + ignore (_Structure_StaticMemberString2 '(s)); + assert (_Structure_StaticMemberString2 '() = s); + assert (_Structure_ConstStaticMemberString '() as string = "const static member string") +;; diff --git a/Examples/test-suite/ocaml/template_methods_runme.ml b/Examples/test-suite/ocaml/template_methods_runme.ml new file mode 100644 index 000000000..aaa5a3416 --- /dev/null +++ b/Examples/test-suite/ocaml/template_methods_runme.ml @@ -0,0 +1,25 @@ +open Swig +open Template_methods + +let _ = + let num = C_float 1. in + assert (_convolve1Bool '() as int = 0); + assert (_convolve1Bool '(true) = C_void); + assert (_convolve2Float '() as int = 0); + assert (_convolve3FloatRenamed '(num) = C_void); + assert (_convolve4Float '() as int = 0); + assert (_convolve4FloatRenamed '(num) = C_void); + assert (_convolve5FloatRenamed '() as int = 0); + assert (_convolve5FloatRenamed '(num) = C_void); + + let k = new_Klass '() in + assert (k -> KlassTMethodBoolRenamed (true) as bool = true); + assert (k -> KlassTMethodBool () = C_void); + assert (_Klass_KlassStaticTMethodBoolRenamed '(true) as bool = true); + assert (_Klass_KlassStaticTMethodBool '() = C_void); + + let cp = new_ComponentProperties '() in + assert (cp -> adda ("key1", "val1", "key2", 22.2) = C_void); + assert (cp -> adda ("key1", "val1", "key2", "val2", "key3", "val3") = C_void); + assert (cp -> adda ("key1", 1, "key2", 2, "key3", 3) = C_void) +;; diff --git a/Examples/test-suite/perl5/li_std_string_runme.pl b/Examples/test-suite/perl5/li_std_string_runme.pl index e6358ff1f..3c3f9d5b4 100644 --- a/Examples/test-suite/perl5/li_std_string_runme.pl +++ b/Examples/test-suite/perl5/li_std_string_runme.pl @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 30; +use Test::More tests => 31; BEGIN { use_ok('li_std_string') } require_ok('li_std_string'); @@ -77,6 +77,7 @@ is(li_std_string::test_reference_input("hello"), "hello", "reference_input"); is(li_std_string::test_reference_inout("hello"), "hellohello", "reference_inout"); +is(li_std_string::test_reference_output(), "output", "reference_output"); no strict; my $gen1 = new li_std_string::Foo(); diff --git a/Examples/test-suite/php/arrays_runme.php b/Examples/test-suite/php/arrays_runme.php index eb06fbfd8..1d9e44d76 100644 --- a/Examples/test-suite/php/arrays_runme.php +++ b/Examples/test-suite/php/arrays_runme.php @@ -4,7 +4,7 @@ require "tests.php"; check::functions(array('fn_taking_arrays','newintpointer','setintfrompointer','getintfrompointer','array_pointer_func')); check::classes(array('arrays','SimpleStruct','ArrayStruct','CartPoseData_t')); -check::globals(array()); +check::globals(array('array_shifted_size')); $ss=new simplestruct(); check::classname('simplestruct',$ss); diff --git a/Examples/test-suite/php/catches_strings_runme.php b/Examples/test-suite/php/catches_strings_runme.php index f727ea26a..758c3f618 100644 --- a/Examples/test-suite/php/catches_strings_runme.php +++ b/Examples/test-suite/php/catches_strings_runme.php @@ -6,7 +6,7 @@ $exception_thrown = false; try { StringsThrower::charstring(); } catch (Exception $e) { - check::str_contains($e->getMessage(), "charstring message", "incorrect exception message: {$e->getMessage()}"); + check::equal($e->getMessage(), "charstring message", "incorrect exception message: {$e->getMessage()}"); $exception_thrown = true; } check::equal($exception_thrown, true, "Should have thrown an exception"); @@ -15,7 +15,7 @@ $exception_thrown = false; try { StringsThrower::stdstring(); } catch (Exception $e) { - check::str_contains($e->getMessage(), "stdstring message", "incorrect exception message: {$e->getMessage()}"); + check::equal($e->getMessage(), "stdstring message", "incorrect exception message: {$e->getMessage()}"); $exception_thrown = true; } check::equal($exception_thrown, true, "Should have thrown an exception"); diff --git a/Examples/test-suite/php/default_args_runme.php b/Examples/test-suite/php/default_args_runme.php index 59350644f..cf4932209 100644 --- a/Examples/test-suite/php/default_args_runme.php +++ b/Examples/test-suite/php/default_args_runme.php @@ -42,19 +42,6 @@ check::equal($f->double_if_void_ptr_is_null(6, Null), 12, "\$f->double_if_void_p check::equal($f->double_if_void_ptr_is_null(7), 14, "\$f->double_if_void_ptr_is_null(7)"); -# For the testcases below, PHP 7 emits an error, while PHP 8 throws an -# exception. To simplify the testcases we install an error handler function -# for PHP7 which throws an ArgumentCountError exception (which we have to -# define ourselves for PHP 7.0). - -if (PHP_MAJOR_VERSION == 7) { - if (PHP_MINOR_VERSION == 0) { - # ArgumentCountError was added in PHP 7.1. - class ArgumentCountError extends Error {} - } - $old_error_handler = set_error_handler(function($n,$s,$f,$l){throw preg_match('/^Wrong parameter count/', $s) ? new ArgumentCountError($s) : new Error($s);}); -} - try { $f = new Foo(1); check::fail("Foo::Foo ignore is not working"); @@ -91,10 +78,6 @@ try { } catch (Error $e) { } -if (PHP_MAJOR_VERSION == 7) { - set_error_handler($old_error_handler); -} - check::equal(Klass::inc(100, new Klass(22))->val, 122, "Klass::inc failed"); check::equal(klass::inc(100)->val, 99, "klass::inc failed"); @@ -143,19 +126,17 @@ check::equal(chartest5(), "B", "chartest5()"); check::equal(chartest6(), "C", "chartest6()"); -if (PHP_MAJOR_VERSION >= 8) { - // Regression test for bug in initial implementation of PHP type declarations. - $p = (new ReflectionMethod('TrickyInPython', 'value_m1'))->getParameters(); - // empty array in buggy version - check::equal(count($p), 2, "Expected 2 parameters"); - check::equal((string)$p[0]->getType(), 'int', "Expected int parameter"); - check::equal((string)$p[1]->getType(), 'int', "Expected int parameter"); - - $p = (new ReflectionMethod('EnumClass', 'blah'))->getParameters(); - // empty array in buggy version - check::equal(count($p), 2, "Expected 2 parameters"); - check::equal((string)$p[0]->getType(), 'int', "Expected int parameter"); - check::equal((string)$p[1]->getType(), 'int', "Expected int parameter"); -} +// Regression test for bug in initial implementation of PHP type declarations. +$p = (new ReflectionMethod('TrickyInPython', 'value_m1'))->getParameters(); +// empty array in buggy version +check::equal(count($p), 2, "Expected 2 parameters"); +check::equal((string)$p[0]->getType(), 'int', "Expected int parameter"); +check::equal((string)$p[1]->getType(), 'int', "Expected int parameter"); + +$p = (new ReflectionMethod('EnumClass', 'blah'))->getParameters(); +// empty array in buggy version +check::equal(count($p), 2, "Expected 2 parameters"); +check::equal((string)$p[0]->getType(), 'int', "Expected int parameter"); +check::equal((string)$p[1]->getType(), 'int', "Expected int parameter"); check::done(); diff --git a/Examples/test-suite/php/director_classes_runme.php b/Examples/test-suite/php/director_classes_runme.php index d187ed82e..170e10f26 100644 --- a/Examples/test-suite/php/director_classes_runme.php +++ b/Examples/test-suite/php/director_classes_runme.php @@ -8,65 +8,30 @@ check::classes(array('director_classes', 'Base', 'BaseClass', 'Caller', 'Derived // New vars check::globals(array('PrintDebug')); -if (PHP_MAJOR_VERSION < 8) { - // Without type declarations since we don't generate them for PHP < 8 - // and we need to be compatible with method declarations in Base. - class PHPDerived extends Base { - function Val($x) { return $x; } - function Ref($x) { return $x; } - function Ptr($x) { return $x; } - function ConstPtrRef($x) { return $x; } - function FullyOverloaded($x) { - $rv = parent::FullyOverloaded($x); - $rv = preg_replace('/Base/', 'PHPDerived', $rv); - return $rv; - } - function SemiOverloaded($x) { - # this is going to be awkward because we can't really - # semi-overload in PHP, but we can sort of fake it. - if (!is_int($x)) { - return parent::SemiOverloaded($x); - } - $rv = parent::SemiOverloaded($x); - $rv = preg_replace('/Base/', 'PHPDerived', $rv); - return $rv; - } - function DefaultParms($x, $y = 1.1) { - $rv = parent::DefaultParms($x, $y); - $rv = preg_replace('/Base/', 'PHPDerived', $rv); - return $rv; - } +class PHPDerived extends Base { + function Val(DoubleHolder $x) { return $x; } + function Ref(DoubleHolder $x) { return $x; } + function Ptr(?DoubleHolder $x) { return $x; } + function ConstPtrRef(?DoubleHolder $x) { return $x; } + function FullyOverloaded($x) { + $rv = parent::FullyOverloaded($x); + $rv = preg_replace('/Base/', 'PHPDerived', $rv); + return $rv; } -} else { - class PHPDerived extends Base { - function Val(DoubleHolder $x) { return $x; } - function Ref(DoubleHolder $x) { return $x; } - // PHP 7.0 fails to parse the `?` - revert once we drop 7.0 support: - // function Ptr(?DoubleHolder $x) { return $x; } - function Ptr($x) { return $x; } - // PHP 7.0 fails to parse the `?` - revert once we drop 7.0 support: - // function ConstPtrRef(?DoubleHolder $x) { return $x; } - function ConstPtrRef($x) { return $x; } - function FullyOverloaded($x) { - $rv = parent::FullyOverloaded($x); - $rv = preg_replace('/Base/', 'PHPDerived', $rv); - return $rv; - } - function SemiOverloaded($x) { - # this is going to be awkward because we can't really - # semi-overload in PHP, but we can sort of fake it. - if (!is_int($x)) { - return parent::SemiOverloaded($x); - } - $rv = parent::SemiOverloaded($x); - $rv = preg_replace('/Base/', 'PHPDerived', $rv); - return $rv; - } - function DefaultParms(int $x, float $y = 1.1) { - $rv = parent::DefaultParms($x, $y); - $rv = preg_replace('/Base/', 'PHPDerived', $rv); - return $rv; + function SemiOverloaded($x) { + # this is going to be awkward because we can't really + # semi-overload in PHP, but we can sort of fake it. + if (!is_int($x)) { + return parent::SemiOverloaded($x); } + $rv = parent::SemiOverloaded($x); + $rv = preg_replace('/Base/', 'PHPDerived', $rv); + return $rv; + } + function DefaultParms(int $x, float $y = 1.1) { + $rv = parent::DefaultParms($x, $y); + $rv = preg_replace('/Base/', 'PHPDerived', $rv); + return $rv; } } diff --git a/Examples/test-suite/php/director_thread_runme.php b/Examples/test-suite/php/director_thread_runme.php index 190dbad71..e4eb3684a 100644 --- a/Examples/test-suite/php/director_thread_runme.php +++ b/Examples/test-suite/php/director_thread_runme.php @@ -3,7 +3,7 @@ require "tests.php"; # Fails in a ZTS-build of PHP5 - see: https://github.com/swig/swig/pull/155 -# FIXME: Does this still fail in a threaded build of PHP7? +# FIXME: Does this still fail in a threaded build of PHP8? exit(0); // New functions diff --git a/Examples/test-suite/php/li_std_string_runme.php b/Examples/test-suite/php/li_std_string_runme.php index 680b7ce98..390b7e17b 100644 --- a/Examples/test-suite/php/li_std_string_runme.php +++ b/Examples/test-suite/php/li_std_string_runme.php @@ -49,6 +49,50 @@ Structure::StaticMemberString2($s); check::equal(Structure::StaticMemberString2(), $s, "StaticMemberString2 test 2"); check::equal(Structure::ConstStaticMemberString(), "const static member string", "ConstStaticMemberString test"); +// Test INPUT, INOUT and OUTPUT string& typemaps: +$input = "hello"; +check::equal(li_std_string::test_reference_input($input), "hello"); +// $input should be unchanged - this check is to catch if we incorrectly used +// the default string& typemap: +check::equal($input, "hello"); +$s = li_std_string::test_reference_inout($input); +check::equal($s, "hellohello"); +// $input should be unchanged - this check is to catch if we incorrectly used +// the default string& typemap: +check::equal($input, "hello"); +check::equal(li_std_string::test_reference_output(), "output"); + +// Test default PHP wrapping of std::string& as a by-ref PHP string parameter: +$s = "byref"; +check::equal(li_std_string::test_reference_php($s), null); +check::equal($s, "byref.php"); + +// Test throwing strings: +try { + test_throw(); + check::fail("test_throw() didn't throw"); +} catch (Exception $s) { + check::equal($s->getMessage(), "test_throw message"); +} +try { + test_const_reference_throw(); + check::fail("test_const_reference_throw() didn't throw"); +} catch (Exception $s) { + check::equal($s->getMessage(), "test_const_reference_throw message"); +} +try { + test_pointer_throw(); + check::fail("test_pointer_throw() didn't throw"); +} catch (Exception $s) { + check::equal($s->getMessage(), "foo"); +} +try { + test_const_pointer_throw(); + check::fail("test_const_pointer_throw() didn't throw"); +} catch (Exception $s) { + check::equal($s->getMessage(), "foo"); +} + // This used to give "Undefined variable: r" li_std_string::test_const_reference_returning_void("foo"); diff --git a/Examples/test-suite/preproc_defined.i b/Examples/test-suite/preproc_defined.i index 5ebf0a099..f000446c4 100644 --- a/Examples/test-suite/preproc_defined.i +++ b/Examples/test-suite/preproc_defined.i @@ -123,3 +123,66 @@ void another_macro_checking(void) { #if 0 # wobble wobble #endif + +/* Regression test for https://sourceforge.net/p/swig/bugs/1163/ + * ONE(1)(2) should expand to `2` but SWIG was expanding it to `TWO(2)` + * which results in the generated C wrapper failing to compile. + */ +#define ONE(X) TWO +#define TWO(X) X +%constant int a = ONE(1)(2); +#define XXX TWO +%constant int b = XXX(42); +#undef ONE +#undef TWO + +/* + * The behaviour of Self-Referential Macros is defined + * https://gcc.gnu.org/onlinedocs/gcc-4.8.5/cpp/Self-Referential-Macros.html + */ +%inline %{ +const int y = 0; +%} + +#define x (4 + y) +#define y (2 * x) + +%constant int z = y; + +#undef y +#undef x + +/* Regression test for #ifdef and #ifndef not working inside a %define. + * https://github.com/swig/swig/issues/2183 + */ +#undef THISMACROISNOTDEFINED /* Make sure! */ +#define THISMACROISDEFINED + +%define %test() + +#ifdef THISMACROISNOTDEFINED +# error #ifdef inside percent-define failed +#endif +#ifndef THISMACROISDEFINED +# error #ifndef inside percent-define failed +#endif +/* Check pre-defined macro too. */ +#ifndef SWIG +# error #ifndef inside percent-define failed +#endif + +/* These cases already worked, but should still have test coverage. */ +#if defined THISMACROISNOTDEFINED +# error #if defined inside percent-define failed +#endif +#if !defined THISMACROISDEFINED +# error #if !defined inside percent-define failed +#endif +/* Check pre-defined macro too. */ +#if !defined SWIG +# error #if !defined inside percent-define failed +#endif + +%enddef + +%test() diff --git a/Examples/test-suite/python/preproc_defined_runme.py b/Examples/test-suite/python/preproc_defined_runme.py index af46816be..37441db52 100644 --- a/Examples/test-suite/python/preproc_defined_runme.py +++ b/Examples/test-suite/python/preproc_defined_runme.py @@ -9,3 +9,12 @@ d.defined = 10 preproc_defined.thing(10) preproc_defined.stuff(10) preproc_defined.bumpf(10) + +if preproc_defined.a != 2: + raise RuntimeError + +if preproc_defined.b != 42: + raise RuntimeError + +if preproc_defined.z != 8: + raise RuntimeError diff --git a/Examples/test-suite/ruby/li_std_string_runme.rb b/Examples/test-suite/ruby/li_std_string_runme.rb index dc85b5dab..c964808fa 100644 --- a/Examples/test-suite/ruby/li_std_string_runme.rb +++ b/Examples/test-suite/ruby/li_std_string_runme.rb @@ -122,6 +122,9 @@ s = test_reference_inout("hello") if (s != "hellohello") raise RuntimeError end +if (test_reference_output() != "output") + raise RuntimeError +end if (stdstring_empty() != "") |