Merge pull request #83 from smarchetto/gsoc2012-scilab

Scilab const & enums improvements, parallelization of test-suite
This commit is contained in:
Sylvestre Ledru 2013-09-04 07:09:03 -07:00
commit 213d67943a
37 changed files with 392 additions and 124 deletions

View file

@ -9,7 +9,7 @@ matrix:
- compiler: gcc - compiler: gcc
env: SWIGLANG=python env: SWIGLANG=python
- compiler: gcc - compiler: gcc
env: SWIGLANG=scilab env: SWIGLANG=scilab SWIGJOBS=-j4
allow_failures: allow_failures:
# None # None
before_install: before_install:

View file

@ -1578,26 +1578,43 @@ SCILAB = @SCILAB@
SCILABOPT = SCILABOPT =
SCILAB_STARTOPT = @SCILABSTARTOPT@ SCILAB_STARTOPT = @SCILABSTARTOPT@
# Returns the Swig Scilab command line args
define get_swig_scilab_args
SWIG_SCILAB_ARGS := -scilab $(SCILABOPT)
ifdef SRCS
SWIG_SCILAB_ARGS += -addsrc "$(SRCS)"
endif
ifdef INCLUDES
SWIG_SCILAB_ARGS += -addcflag "$(INCLUDES)"
endif
ifdef OUTDIR
SWIG_SCILAB_ARGS += -outdir "$(OUTDIR)"
endif
ifdef TARGET
SWIG_SCILAB_ARGS += -o "$(TARGET)"
endif
endef
# Returns the output dir
define get_output_dir
ifdef OUTDIR
OUTPUT_DIR := $(OUTDIR)
else
OUTPUT_DIR := .
endif
endef
# ---------------------------------------------------------------- # ----------------------------------------------------------------
# Build a C dynamically loadable module # Build a C dynamically loadable module
# ---------------------------------------------------------------- # ----------------------------------------------------------------
scilab: $(SRCS) scilab: $(SRCS)
if test ! -z "$(SRCS)"; then \ $(eval $(call get_swig_scilab_args))
if test ! -z "$(INCLUDES)"; then \ $(SWIG) $(SWIGOPT) $(SWIG_SCILAB_ARGS) $(INTERFACEPATH)
$(SWIG) -scilab $(SWIGOPT) $(SCILABOPT) -addsrc $(SRCS) -addcflag $(INCLUDES) $(INTERFACEPATH); \ $(eval $(call get_output_dir))
else \ if [ -f $(OUTPUT_DIR)/builder.sce ]; then \
$(SWIG) -scilab $(SWIGOPT) $(SCILABOPT) -addsrc $(SRCS) $(INTERFACEPATH); \ env LD_LIBRARY_PATH=$(OUTPUT_DIR):$$LD_LIBRARY_PATH MAKEFLAGS="-j1" $(RUNTOOL) $(SCILAB) $(SCILAB_STARTOPT) -f $(OUTPUT_DIR)/builder.sce; \
fi \
else \
if test ! -z "$(INCLUDES)"; then \
$(SWIG) -scilab $(SWIGOPT) $(SCILABOPT) -addcflag $(INCLUDES) $(INTERFACEPATH); \
else \
$(SWIG) -scilab $(SWIGOPT) $(SCILABOPT) $(INTERFACEPATH); \
fi \
fi
if [ -f builder.sce ]; then \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH SCILABPATH=$(srcdir):$$SCILABPATH echo 'exit(1)' | $(RUNTOOL) $(SCILAB) $(SCILAB_STARTOPT) -f builder.sce; \
fi fi
# ---------------------------------------------------------------- # ----------------------------------------------------------------
@ -1605,21 +1622,11 @@ scilab: $(SRCS)
# ---------------------------------------------------------------- # ----------------------------------------------------------------
scilab_cpp: $(SRCS) scilab_cpp: $(SRCS)
if test ! -z "$(SRCS)"; then \ $(eval $(call get_swig_scilab_args))
if test ! -z "$(INCLUDES)"; then \ $(SWIG) $(SWIGOPT) -c++ $(SWIG_SCILAB_ARGS) $(INTERFACEPATH)
$(SWIG) -scilab -c++ $(SWIGOPT) $(SCILABOPT) -addsrc $(SRCS) -addcflag $(INCLUDES) $(INTERFACEPATH); \ $(eval $(call get_output_dir))
else \ if [ -f $(OUTPUT_DIR)/builder.sce ]; then \
$(SWIG) -scilab -c++ $(SWIGOPT) $(SCILABOPT) -addsrc $(SRCS) $(INTERFACEPATH); \ env LD_LIBRARY_PATH=$(OUTPUT_DIR):$$LD_LIBRARY_PATH MAKEFLAGS="-j1" $(RUNTOOL) $(SCILAB) $(SCILAB_STARTOPT) -f $(OUTPUT_DIR)/builder.sce; \
fi \
else \
if test ! -z "$(INCLUDES)"; then \
$(SWIG) -scilab -c++ $(SWIGOPT) $(SCILABOPT) -addcflag $(INCLUDES) $(INTERFACEPATH); \
else \
$(SWIG) -scilab -c++ $(SWIGOPT) $(SCILABOPT) $(INTERFACEPATH); \
fi \
fi
if [ -f builder.sce ]; then \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH SCILABPATH=$(srcdir):$$SCILABPATH echo 'exit(1)' | $(RUNTOOL) $(SCILAB) $(SCILAB_STARTOPT) -f builder.sce; \
fi fi
# ----------------------------------------------------------------- # -----------------------------------------------------------------
@ -1627,7 +1634,8 @@ scilab_cpp: $(SRCS)
# ----------------------------------------------------------------- # -----------------------------------------------------------------
scilab_run: scilab_run:
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH SCILABPATH=$(srcdir):$$SCILABPATH $(RUNTOOL) $(SCILAB) $(SCILAB_STARTOPT) -f $(RUNME).sci $(RUNPIPE) $(eval $(call get_output_dir))
env LD_LIBRARY_PATH=$(OUTPUT_DIR):$$LD_LIBRARY_PATH $(RUNTOOL) $(SCILAB) $(SCILAB_STARTOPT) -f $(RUNME).sci $(RUNPIPE)
# ----------------------------------------------------------------- # -----------------------------------------------------------------
# Scilab version # Scilab version

View file

@ -1,7 +1,7 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.cxx SRCS = example.cxx
TARGET = example TARGET = example_wrap.cxx
INTERFACE = example.i INTERFACE = example.i
check: build check: build

View file

@ -1,7 +1,7 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.i SRCS =
TARGET = example TARGET = example_wrap.c
INTERFACE = example.i INTERFACE = example.i
check: build check: build

View file

@ -24,5 +24,17 @@
%constant int iconst = 37; %constant int iconst = 37;
%constant double fconst = 3.14; %constant double fconst = 3.14;
/* Now constants are wrapped to Scilab variables */
%scilabconst(1);
#define ICONST2 12
#define FCONST2 4.60
#define CCONST3 'a'
#define CCONST4 '\n'
#define SCONST3 "Hello World"
#define SCONST4 "\"Hello World\""
%constant int iconst2 = 73;
%constant double fconst2 = 6.28;

View file

@ -1,15 +1,17 @@
lines(0); lines(0);
exec loader.sce; exec loader.sce;
SWIG_Init();
printf("ICONST = %i (should be 42)\n", ICONST_get()); printf("\nConstants are wrapped by functions:\n");
printf("FCONST = %f (should be 2.1828)\n", FCONST_get()); printf("ICONST_get() = %i (should be 42)\n", ICONST_get());
printf("CCONST = %c (should be ''x'')\n", CCONST_get()); printf("FCONST_get() = %5.4f (should be 2.1828)\n", FCONST_get());
printf("CCONST2 = %s (this should be on a new line)\n", CCONST2_get()); printf("CCONST_get() = ''%c'' (should be ''x'')\n", CCONST_get());
printf("SCONST = %s (should be ''Hello World'')\n", SCONST_get()); printf("CCONST2_get() = %s (this should be on a new line)\n", CCONST2_get());
printf("SCONST2 = %s (should be "'""Hello World"""')\n", SCONST2_get()); printf("SCONST_get() = ''%s'' (should be ''Hello World'')\n", SCONST_get());
printf("EXPR = %f (should be 48.5484)\n", EXPR_get()); printf("SCONST2_get() = ''%s'' (should be "'""Hello World"""')\n", SCONST2_get());
printf("iconst = %i (should be 37)\n", iconst_get()); printf("EXPR_get() = %5.4f (should be 48.5484)\n", EXPR_get());
printf("fconst = %f (should be 3.14)\n", fconst_get()); printf("iconst_get() = %i (should be 37)\n", iconst_get());
printf("fconst_get() = %3.2f (should be 3.14)\n", fconst_get());
try try
printf("EXTERN = %s (Arg! This should not printf(anything)\n", EXTERN_get()); printf("EXTERN = %s (Arg! This should not printf(anything)\n", EXTERN_get());
@ -22,4 +24,14 @@ catch
printf("FOO is not defined (good)\n"); printf("FOO is not defined (good)\n");
end end
printf("\nNow constants are wrapped by Scilab variables (feature scilab:const):\n");
printf("ICONST2 = %i (should be 12)\n", ICONST2);
printf("FCONST2 = %3.2f (should be 4.60)\n", FCONST2);
printf("CCONST3 = ''%c'' (should be ''a'')\n", CCONST3);
printf("CCONST4 = %s (this should be on a new line)\n", CCONST4);
printf("SCONST3 = ''%s'' (should be ''Hello World'')\n", SCONST3);
printf("SCONST4 = ''%s'' (should be "'""Hello World"""')\n", SCONST4);
printf("iconst2 = %i (should be 73)\n", iconst2);
printf("fconst2 = %3.2f (should be 6.28)\n", fconst2);
exit exit

View file

@ -1,7 +1,7 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.c SRCS = example.c
TARGET = example TARGET = example_wrap.c
INTERFACE = example.i INTERFACE = example.i
check: build check: build

View file

@ -1,7 +1,7 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.c SRCS = example.c
TARGET = example TARGET = example_wrap.c
INTERFACE = example.i INTERFACE = example.i
check: build check: build

View file

@ -1,6 +1,7 @@
/* File : example.c */ /* File : example.c */
#include "example.h" #include "example.h"
#include "scilabconst_example.h"
#include <stdio.h> #include <stdio.h>
void enum_test(color c) { void enum_test(color c) {
@ -14,3 +15,15 @@ void enum_test(color c) {
printf("color = Unknown color!\n"); printf("color = Unknown color!\n");
} }
} }
void scilabconst_enum_test(fruit f) {
if (f == APPLE) {
printf("fruit = APPLE\n");
} else if (f == ORANGE) {
printf("fruit = ORANGE\n");
} else if (f == LEMON) {
printf("fruit = LEMON\n");
} else {
printf("fruit = Unknown fruit!\n");
}
}

View file

@ -3,9 +3,11 @@
%{ %{
#include "example.h" #include "example.h"
#include "scilabconst_example.h"
%} %}
/* Let's just grab the original header file here */
%include "example.h" %include "example.h"
%scilabconst(1);
%include "scilabconst_example.h"

View file

@ -1,19 +1,29 @@
lines(0); lines(0);
exec loader.sce; exec loader.sce;
SWIG_Init();
printf("\nTesting use of enums wrapped as Scilab functions\n");
// Print out the value of some enums
printf("*** color ***\n"); printf("*** color ***\n");
printf(" RED = %i\n", RED_get()); printf(" RED = %i\n", RED_get());
printf(" BLUE = %i\n", BLUE_get()); printf(" BLUE = %i\n", BLUE_get());
printf(" GREEN = %i\n", GREEN_get()); printf(" GREEN = %i\n", GREEN_get());
printf("\nTesting use of enums with functions\n");
enum_test(RED_get()); enum_test(RED_get());
enum_test(BLUE_get()); enum_test(BLUE_get());
enum_test(GREEN_get()); enum_test(GREEN_get());
enum_test(int32(1234)); enum_test(int32(1234));
exit printf("\nTesting use of enums wrapped as Scilab variables\n");
printf("*** fruit ***\n");
printf(" APPLE = %i\n", APPLE);
printf(" ORANGE = %i\n", ORANGE);
printf(" LEMON = %i\n", LEMON);
scilabconst_enum_test(APPLE);
scilabconst_enum_test(ORANGE);
scilabconst_enum_test(LEMON);
scilabconst_enum_test(int32(1234));
exit

View file

@ -0,0 +1,3 @@
typedef enum { APPLE, ORANGE, LEMON } fruit;
void scilabconst_enum_test(fruit f);

View file

@ -1,7 +1,7 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.c SRCS = example.c
TARGET = example TARGET = example_wrap.c
INTERFACE = example.i INTERFACE = example.i
check: build check: build

View file

@ -1,7 +1,7 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.c SRCS = example.c
TARGET = example TARGET = example_wrap.c
INTERFACE = example.i INTERFACE = example.i
check: build check: build

View file

@ -1,7 +1,7 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = matrixlib.c SRCS = matrixlib.c
TARGET = matrixlib TARGET = matrixlib_wrap.c
INTERFACE = matrixlib.i INTERFACE = matrixlib.i
check: build check: build

View file

@ -1,7 +1,7 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.c SRCS = example.c
TARGET = example TARGET = example_wrap.c
INTERFACE = example.i INTERFACE = example.i
check: build check: build

View file

@ -1,7 +1,7 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.c SRCS = example.c
TARGET = example TARGET = example_wrap.c
INTERFACE = example.i INTERFACE = example.i
check: build check: build

View file

@ -1,7 +1,7 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.cpp SRCS = example.cpp
TARGET = example TARGET = example_wrap.cxx
INTERFACE = example.i INTERFACE = example.i
check: build check: build

View file

@ -1,7 +1,7 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.cpp SRCS = example.cpp
TARGET = example TARGET = example_wrap.cxx
INTERFACE = example.i INTERFACE = example.i
check: build check: build

View file

@ -1,7 +1,7 @@
TOP = ../../.. TOP = ../../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = SRCS =
TARGET = example TARGET = example_wrap.cxx
INTERFACE = example.i INTERFACE = example.i
check: build check: build

View file

@ -1,7 +1,7 @@
TOP = ../../.. TOP = ../../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.cpp SRCS = example.cpp
TARGET = example TARGET = example_wrap.cxx
INTERFACE = example.i INTERFACE = example.i
check: build check: build

View file

@ -1,7 +1,7 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.i SRCS = example.i
TARGET = example TARGET = example_wrap.c
INTERFACE = example.i INTERFACE = example.i
check: build check: build

View file

@ -1,7 +1,7 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.cxx SRCS = example.cxx
TARGET = example TARGET = example_wrap.cxx
INTERFACE = example.i INTERFACE = example.i
check: build check: build

View file

@ -1,7 +1,7 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.c SRCS = example.c
TARGET = example TARGET = example_wrap.c
INTERFACE = example.i INTERFACE = example.i
check: build check: build

View file

@ -4,69 +4,87 @@
LANGUAGE = scilab LANGUAGE = scilab
SCILAB = @SCILAB@ SCILAB = @SCILAB@
SCILAB_STARTOPT = @SCILABSTARTOPT@
SCRIPTSUFFIX = _runme.sci SCRIPTSUFFIX = _runme.sci
srcdir = @srcdir@ srcdir = @srcdir@
top_srcdir = @top_srcdir@ top_srcdir = @top_srcdir@
top_builddir = @top_builddir@ top_builddir = @top_builddir@
# Overridden variables here # Overridden variables here
# None! # None!
# - member_funcptr_galore (C++) # - member_funcptr_galore (C++)
# - member_pointer (C++) # - member_pointer (C++)
# - typemap_variables (C++) # - typemap_variables (C++)
# configure cache to speed up test run define get_output_dir
CONF_CACHE=$(CURDIR)/test-suite.config.cache OUTDIR := $(CURDIR)/$(1).build
CONFIG_SITE=$(CURDIR)/test-suite.config.site endef
export CONFIG_SITE
enable_config_cache = \ define get_runme_script
echo 'cache_file=$(CONF_CACHE)' > $(CONFIG_SITE) RUNME_SCRIPT := $(srcdir)/$(SCRIPTPREFIX)$(1)$(SCRIPTSUFFIX)
endef
disable_config_cache:
rm -f $(CONF_CACHE)
rm -f $(CONFIG_SITE)
CONFIG_SITE=
# need reset cache before multicpptest
reset_config_cache = \
rm -f $(CONF_CACHE)
# disable cache at the end of test-suite
# use trick for this: 'extra test cases' end target
EXTRA_TEST_CASES = disable_config_cache
include $(srcdir)/../common.mk include $(srcdir)/../common.mk
# Override make commands to specify OUTDIR
swig_and_compile_cpp = \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile CXXSRCS="$(CXXSRCS)" \
SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \
INCLUDES="$(INCLUDES)" SWIGOPT= OUTDIR="$(OUTDIR)" \
TARGET="$*_wrap.cxx" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$*.i" \
scilab_cpp
swig_and_compile_c = \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile CSRCS="$(CSRCS)" \
SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \
INCLUDES="$(INCLUDES)" SWIGOPT= OUTDIR="$(OUTDIR)" \
TARGET="$*_wrap.c" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$*.i" \
scilab
swig_and_compile_multi_cpp = \
for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list` ; do \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile CXXSRCS="$(CXXSRCS)" \
SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \
INCLUDES="$(INCLUDES)" SWIGOPT= OUTDIR="$(OUTDIR)" \
TARGET="$*_wrap.cxx" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$$f.i" \
scilab_cpp; \
done
# Rules for the different types of tests # Rules for the different types of tests
%.cpptest: %.cpptest:
$(setup) $(setup)
$(enable_config_cache) $(eval $(call get_output_dir,$*))
mkdir -p $(OUTDIR)
+$(swig_and_compile_cpp) +$(swig_and_compile_cpp)
$(run_testcase) $(run_testcase)
%.ctest: %.ctest:
$(setup) $(setup)
$(enable_config_cache) $(eval $(call get_output_dir,$*))
mkdir -p $(OUTDIR)
+$(swig_and_compile_c) +$(swig_and_compile_c)
$(run_testcase) $(run_testcase)
%.multicpptest: %.multicpptest:
$(setup) $(setup)
$(reset_config_cache) $(eval $(call get_output_dir,$*))
mkdir -p $(OUTDIR)
+$(swig_and_compile_multi_cpp) +$(swig_and_compile_multi_cpp)
$(run_testcase) $(run_testcase)
# Runs the testcase. A testcase is only run if # Runs the testcase. A testcase is only run if
# a file is found which has _runme.sci appended after the testcase name. # a file is found which has _runme.sci appended after the testcase name.
run_testcase = \ run_testcase = \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then ( \ $(eval $(call get_output_dir,$*)) \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) echo 'exit(1)' |$(SCILAB) -nwni -nb -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ; ) \ $(eval $(call get_runme_script,$*)) \
fi; if [ -f $(RUNME_SCRIPT) ]; then ( \
env LD_LIBRARY_PATH=$(OUTDIR):$$LD_LIBRARY_PATH $(RUNTOOL) $(SCILAB) $(SCILAB_STARTOPT) -f $(RUNME_SCRIPT); )\
fi
# Clean: remove the generated files # Clean: remove the generated files
%.clean: %.clean:
@rm -f builder.sce loader.sce cleaner.sce $*_wrap.c $*_wrap.cxx lib$*lib.* $(CONFIG_SITE) $(CONF_CACHE) @rm -rf $*.build
clean: clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile scilab_clean $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile scilab_clean

View file

@ -1,10 +1,13 @@
// Clean files // Clean files
exec("cleaner.sce", -1);
mdelete("builder.sce"); exec(fullfile(testbuilddir, "cleaner.sce"), -1);
mdelete("cleaner.sce");
mdelete(swigtestname + "_wrap.c"); mdelete(fullfile(testbuilddir, "builder.sce"));
mdelete(swigtestname + "_wrap.cxx"); mdelete(fullfile(testbuilddir, "cleaner.sce"));
mdelete(swigtestname + ".i"); mdelete(fullfile(testbuilddir, swigtestname + "_wrap.c"));
mdelete(fullfile(testbuilddir, swigtestname + "_wrap.cxx"));
mdelete(fullfile(testbuilddir, swigtestname + ".i"));
removedir(testbuilddir);
//mprintf("******************\n") //mprintf("******************\n")
//mprintf("* TEST SUCCEEDED *\n") //mprintf("* TEST SUCCEEDED *\n")

View file

@ -4,15 +4,19 @@ lines(0);
[units, typ, names] = file(1); [units, typ, names] = file(1);
swigtestname = strsubst(fileparts(names, "fname"), "_runme", ""); swigtestname = strsubst(fileparts(names, "fname"), "_runme", "");
// Test build dir
testbuilddir = swigtestname + ".build";
// Does the library exists? If not then exit! // Does the library exists? If not then exit!
if ~isfile("lib" + swigtestname + "lib" + getdynlibext()) then libname = "lib" + swigtestname + "lib" + getdynlibext();
if ~isfile(fullfile(testbuilddir, libname)) then
mprintf("*** LIBRARY NOT FOUND: %s ***\n", "lib" + swigtestname + "lib" + getdynlibext()); mprintf("*** LIBRARY NOT FOUND: %s ***\n", "lib" + swigtestname + "lib" + getdynlibext());
exit exit
end end
// Load library // Load library
try try
exec("loader.sce", -1); exec(fullfile(testbuilddir, "loader.sce"), -1);
catch catch
mprintf("*** LOADER EXECUTION FAILED ***\n"); mprintf("*** LOADER EXECUTION FAILED ***\n");
exit exit

View file

@ -252,3 +252,37 @@ SwigScilabStringFromCharPtrArray(void *_pvApiCtx, int _iVarOut, char **_charPtrA
return SWIG_NbInputArgument(pvApiCtx) + _iVarOut; return SWIG_NbInputArgument(pvApiCtx) + _iVarOut;
} }
} }
%fragment(SWIG_CreateScilabVariable_frag(char), "wrapper") {
SWIGINTERN int
SWIG_CreateScilabVariable_dec(char)(void *_pvApiCtx, const char* _psVariableName, const char _cVariableValue) {
SciErr sciErr;
char sValue[2];
const char* psStrings[1];
sValue[0] = _cVariableValue;
sValue[1] = '\0';
psStrings[0] = sValue;
sciErr = createNamedMatrixOfString(_pvApiCtx, _psVariableName, 1, 1, psStrings);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
return SWIG_OK;
}
}
%fragment(SWIG_CreateScilabVariable_frag(charptr), "wrapper") {
SWIGINTERN int
SWIG_CreateScilabVariable_dec(charptr)(void *_pvApiCtx, const char* _psVariableName, const char* _psVariableValue) {
SciErr sciErr;
const char* psStrings[1];
psStrings[0] = _psVariableValue;
sciErr = createNamedMatrixOfString(_pvApiCtx, _psVariableName, 1, 1, psStrings);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
return SWIG_OK;
}
}

View file

@ -118,3 +118,15 @@ SWIG_SciDouble_FromDoubleArrayAndSize(void *_pvApiCtx, int _iVarOut, int _iRows,
return Rhs + _iVarOut; return Rhs + _iVarOut;
} }
} }
%fragment(SWIG_CreateScilabVariable_frag(double), "wrapper") {
SWIGINTERN int
SWIG_CreateScilabVariable_dec(double)(void *_pvApiCtx, const char* _psVariableName, const double _dVariableValue) {
SciErr sciErr;
sciErr = createNamedMatrixOfDouble(_pvApiCtx, _psVariableName, 1, 1, &_dVariableValue);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
return SWIG_OK;
}
}

View file

@ -196,3 +196,15 @@ SWIG_SciInt32_FromIntArrayAndSize(void *_pvApiCtx, int _iVarOut, int _iRows, int
return Rhs + _iVarOut; return Rhs + _iVarOut;
} }
} }
%fragment(SWIG_CreateScilabVariable_frag(int), "wrapper") {
SWIGINTERN int
SWIG_CreateScilabVariable_dec(int)(void *_pvApiCtx, const char* _psVariableName, const int _iVariableValue) {
SciErr sciErr;
sciErr = createNamedMatrixOfInteger32(_pvApiCtx, _psVariableName, 1, 1, &_iVariableValue);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
return SWIG_OK;
}
}

View file

@ -1,5 +1,6 @@
%include <typemaps/swigmacros.swg> %include <typemaps/swigmacros.swg>
%include <typemaps/fragments.swg> %include <typemaps/fragments.swg>
%include <scimacros.swg>
%include <sciruntime.swg> %include <sciruntime.swg>
%include <scitypemaps.swg> %include <scitypemaps.swg>

View file

@ -43,6 +43,27 @@ SWIG_GetScilabListSize(SciObject _obj, int *_piListSize)
return SWIG_OK; return SWIG_OK;
} }
SWIGINTERN int
SWIG_GetScilabListAndSize(SciObject _obj, int **_piListAddr, int *_piListSize)
{
SciErr sciErr;
sciErr = getVarAddressFromPosition(pvApiCtx, _obj, _piListAddr);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
sciErr = getListItemNumber(pvApiCtx, *_piListAddr, _piListSize);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
return SWIG_OK;
}
SWIGINTERN int SWIGINTERN int
SWIG_CheckScilabList(SciObject _obj) SWIG_CheckScilabList(SciObject _obj)

5
Lib/scilab/scimacros.swg Normal file
View file

@ -0,0 +1,5 @@
#define %scilabconst(flag) %feature("scilab:const","flag")
// Create Scilab variable
#define SWIG_CreateScilabVariable_frag(Type...) %fragment_name(CreateScilabVariable, Type)
#define SWIG_CreateScilabVariable_dec(Type...) %symbol_name(CreateScilabVariable, Type)

View file

@ -78,7 +78,6 @@ SWIG_Scilab_ErrorMsg(int code, const char *mesg)
/* Used for C++ enums */ /* Used for C++ enums */
//#define SWIG_AsVal_int(scilabValue, valuePointer) SWIG_SciDouble_AsInt(pvApiCtx, scilabValue, valuePointer, fname) //#define SWIG_AsVal_int(scilabValue, valuePointer) SWIG_SciDouble_AsInt(pvApiCtx, scilabValue, valuePointer, fname)
#if SCILAB_VERSION_54_OR_HIGHER #if SCILAB_VERSION_54_OR_HIGHER
#define SWIG_CheckInputArgument(pvApiCtx, minInputArgument, maxInputArgument) CheckInputArgument(pvApiCtx, minInputArgument, maxInputArgument) #define SWIG_CheckInputArgument(pvApiCtx, minInputArgument, maxInputArgument) CheckInputArgument(pvApiCtx, minInputArgument, maxInputArgument)
#define SWIG_CheckOutputArgument(pvApiCtx, minOutputArgument, maxOutputArgument) CheckOutputArgument(pvApiCtx, minOutputArgument, maxOutputArgument) #define SWIG_CheckOutputArgument(pvApiCtx, minOutputArgument, maxOutputArgument) CheckOutputArgument(pvApiCtx, minOutputArgument, maxOutputArgument)
@ -272,6 +271,8 @@ SWIG_Scilab_SetModule(swig_module_info *swig_module)
%init %{ %init %{
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
#endif
int SWIG_Init(char *fname, unsigned long fname_len) { int SWIG_Init(char *fname, unsigned long fname_len) {
SWIG_InitializeModule(NULL); SWIG_InitializeModule(NULL);
SWIG_CreateScilabVariables();
%} %}

View file

@ -34,6 +34,11 @@
// //
%fragment(SWIG_Traits_Sequence_frag(ptr), "header", %fragment(SWIG_Traits_Sequence_frag(ptr), "header",
fragment=SWIG_AsCheck_Sequence_frag(int),
fragment=SWIG_AsGet_Sequence_frag(int),
fragment=SWIG_AsSize_Sequence_frag(int),
fragment=SWIG_FromCreate_Sequence_frag(int),
fragment=SWIG_FromSet_Sequence_frag(int),
fragment=SWIG_AsCheck_Sequence_frag(ptr), fragment=SWIG_AsCheck_Sequence_frag(ptr),
fragment=SWIG_AsGet_Sequence_frag(ptr), fragment=SWIG_AsGet_Sequence_frag(ptr),
fragment=SWIG_AsSize_Sequence_frag(ptr), fragment=SWIG_AsSize_Sequence_frag(ptr),
@ -42,29 +47,29 @@
fragment="StdTraits") { fragment="StdTraits") {
namespace swig { namespace swig {
// Returns an error for default (not specialized) value containers // For sequence of values, considers int as default type (so it works for enums)
template <typename T> struct traits_as_sequence { template <typename T> struct traits_as_sequence {
static int check(SciObject obj) { static int check(SciObject obj) {
SWIG_Error(SWIG_TypeError, type_name<T>()); return SWIG_AsCheck_Sequence_dec(int)(obj);
} }
static int get(SciObject obj, void **sequence) { static int get(SciObject obj, void **sequence) {
SWIG_Error(SWIG_TypeError, type_name<T>()); return SWIG_AsGet_Sequence_dec(int)(obj, (int **)sequence);
} }
static int size(SciObject obj, int *size) { static int size(SciObject obj, int *size) {
SWIG_Error(SWIG_TypeError, type_name<T>()); return SWIG_AsSize_Sequence_dec(int)(obj, size);
} }
}; };
template <typename T> struct traits_from_sequence { template <typename T> struct traits_from_sequence {
static int create(int size, void **sequence) { static int create(int size, void **sequence) {
SWIG_Error(SWIG_TypeError, type_name<T>()); return SWIG_FromCreate_Sequence_dec(int)(size, (int **)sequence);
} }
static SciObject set(int size, void *sequence) { static SciObject set(int size, void *sequence) {
SWIG_Error(SWIG_TypeError, type_name<T>()); return SWIG_FromSet_Sequence_dec(int)(size, (int *)sequence);
} }
}; };
// But supports containers of pointers // For sequence of pointers
template <typename T> struct traits_as_sequence<T*> { template <typename T> struct traits_as_sequence<T*> {
static int check(SciObject obj) { static int check(SciObject obj) {
@ -127,25 +132,27 @@ namespace swig {
// //
%fragment(SWIG_Traits_SequenceItem_frag(ptr), "header", %fragment(SWIG_Traits_SequenceItem_frag(ptr), "header",
fragment=SWIG_AsVal_SequenceItem_frag(int),
fragment=SWIG_From_SequenceItem_frag(int),
fragment=SWIG_AsVal_SequenceItem_frag(ptr), fragment=SWIG_AsVal_SequenceItem_frag(ptr),
fragment=SWIG_From_SequenceItem_frag(ptr), fragment=SWIG_From_SequenceItem_frag(ptr),
fragment="StdTraits") { fragment="StdTraits") {
namespace swig { namespace swig {
// Returns an error for default (not specialized) value containers // For sequence of values, considers int as default type (so it works for enums)
template <typename T> struct traits_asval_sequenceitem { template <typename T> struct traits_asval_sequenceitem {
static int asval(SciObject obj, void *pSequence, int iItemIndex, T *pItemValue) { static int asval(SciObject obj, void *pSequence, int iItemIndex, T *pItemValue) {
SWIG_Error(SWIG_TypeError, type_name<T>()); return SWIG_AsVal_SequenceItem_dec(int)(obj, (int *)pSequence, iItemIndex, (int *)pItemValue);
} }
}; };
template <typename T> struct traits_from_sequenceitem { template <typename T> struct traits_from_sequenceitem {
static int from(void *pSequence, int iItemIndex, T itemValue) { static int from(void *pSequence, int iItemIndex, T itemValue) {
SWIG_Error(SWIG_TypeError, type_name<T>()); return SWIG_From_SequenceItem_dec(int)((int *)pSequence, iItemIndex, (int)itemValue);
} }
}; };
// But supports containers of pointers // Sequence of pointers
template <typename T> struct traits_asval_sequenceitem<T*> { template <typename T> struct traits_asval_sequenceitem<T*> {
static int asval(SciObject obj, void *pSequence, int iItemIndex, T **pItemValue) { static int asval(SciObject obj, void *pSequence, int iItemIndex, T **pItemValue) {

View file

@ -376,3 +376,37 @@
%typecheck(SWIG_TYPECHECK_STRING_ARRAY) char ** { SCILAB_TYPECHECK(isStringType) } %typecheck(SWIG_TYPECHECK_STRING_ARRAY) char ** { SCILAB_TYPECHECK(isStringType) }
//%apply int { size_t }; //%apply int { size_t };
/* -----------------------------------------------------------------------------*/
/* Constants and enums to Scilab variables
/* -----------------------------------------------------------------------------*/
%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(int)) int
%{
if (SWIG_CreateScilabVariable_int(pvApiCtx, "$result", $value) != SWIG_OK)
return SWIG_ERROR;
%}
%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(double)) double
%{
if (SWIG_CreateScilabVariable_double(pvApiCtx, "$result", $value) != SWIG_OK)
return SWIG_ERROR;
%}
%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(char)) char
%{
if (SWIG_CreateScilabVariable_char(pvApiCtx, "$result", $value) != SWIG_OK)
return SWIG_ERROR;
%}
%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(charptr)) char *
%{
if (SWIG_CreateScilabVariable_charptr(pvApiCtx, "$result", $value) != SWIG_OK)
return SWIG_ERROR;
%}
%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(int)) enum SWIGTYPE
%{
if (SWIG_CreateScilabVariable_int(pvApiCtx, "$result", $value) != SWIG_OK)
return SWIG_ERROR;
%}

View file

@ -24,6 +24,7 @@ Scilab options\n\
-vbl <level> sets the build verbose level (default 0)\n\n"; -vbl <level> sets the build verbose level (default 0)\n\n";
const char *SWIG_INIT_FUNCTION_NAME = "SWIG_Init"; const char *SWIG_INIT_FUNCTION_NAME = "SWIG_Init";
const char *SWIG_CREATE_VARIABLES_FUNCTION_NAME = "SWIG_CreateScilabVariables";
class SCILAB:public Language { class SCILAB:public Language {
protected: protected:
@ -34,6 +35,8 @@ protected:
File *wrappersSection; File *wrappersSection;
File *initSection; File *initSection;
String *variablesCode;
File *builderFile; File *builderFile;
String *builderCode; String *builderCode;
int builderFunctionCount; int builderFunctionCount;
@ -43,7 +46,6 @@ protected:
String *ldflag; String *ldflag;
String *verboseBuildLevel; String *verboseBuildLevel;
public: public:
/* ------------------------------------------------------------------------ /* ------------------------------------------------------------------------
* main() * main()
@ -150,6 +152,11 @@ public:
Printf(builderCode, "mode(-1);\n"); Printf(builderCode, "mode(-1);\n");
Printf(builderCode, "lines(0);\n"); /* Useful for automatic tests */ Printf(builderCode, "lines(0);\n"); /* Useful for automatic tests */
// Scilab needs to be in the build directory
Printf(builderCode, "originaldir = pwd();\n");
Printf(builderCode, "builddir = get_absolute_file_path('builder.sce');\n");
Printf(builderCode, "cd(builddir);\n");
Printf(builderCode, "ilib_verbose(%s);\n", verboseBuildLevel); Printf(builderCode, "ilib_verbose(%s);\n", verboseBuildLevel);
Printf(builderCode, "ilib_name = \"%slib\";\n", moduleName); Printf(builderCode, "ilib_name = \"%slib\";\n", moduleName);
@ -161,7 +168,7 @@ public:
Printf(builderCode, "ldflags = \"\";\n"); Printf(builderCode, "ldflags = \"\";\n");
} }
Printf(builderCode, "cflags = [\"-g -I\" + get_absolute_file_path(\"builder.sce\")];\n"); Printf(builderCode, "cflags = [\"-g -I\" + builddir];\n");
if (cflag != NULL) { if (cflag != NULL) {
Printf(builderCode, "includepath = \"%s\";\n", cflag); Printf(builderCode, "includepath = \"%s\";\n", cflag);
Printf(builderCode, "includepath = fullpath(part(includepath, 3:length(includepath)));\n"); Printf(builderCode, "includepath = fullpath(part(includepath, 3:length(includepath)));\n");
@ -172,18 +179,20 @@ public:
for (int i = 0; i < Len(sourceFileList); i++) { for (int i = 0; i < Len(sourceFileList); i++) {
String *sourceFile = Getitem(sourceFileList, i); String *sourceFile = Getitem(sourceFileList, i);
if (i == 0) { if (i == 0) {
Printf(builderCode, "files = \"%s\";\n", sourceFile); Printf(builderCode, "files = \"%s\";\n", sourceFile);
} else { } else {
Printf(builderCode, "files($ + 1) = \"%s\";\n", sourceFile); Printf(builderCode, "files($ + 1) = \"%s\";\n", sourceFile);
} }
} }
Printf(builderCode, "table = ["); Printf(builderCode, "table = [");
/* In C++ mode, add initialization function to builder table */ /* add initialization function to builder table */
if (CPlusPlus) { addFunctionInBuilder(NewString(SWIG_INIT_FUNCTION_NAME), NewString(SWIG_INIT_FUNCTION_NAME));
Printf(builderCode, "\"%s\",\"%s\";", SWIG_INIT_FUNCTION_NAME, SWIG_INIT_FUNCTION_NAME);
} // Open Scilab wrapper variables creation function
variablesCode = NewString("");
Printf(variablesCode, "int %s() {\n", SWIG_CREATE_VARIABLES_FUNCTION_NAME);
/* Emit code for children */ /* Emit code for children */
if (CPlusPlus) { if (CPlusPlus) {
@ -196,11 +205,15 @@ public:
Printf(wrappersSection, "}\n"); Printf(wrappersSection, "}\n");
} }
// Close Scilab wrapper variables creation function
Printf(variablesCode, " return SWIG_OK;\n}\n");
/* Write all to the builder.sce file */ /* Write all to the builder.sce file */
Printf(builderCode, "];\n"); Printf(builderCode, "];\n");
Printf(builderCode, "if ~isempty(table) then\n"); Printf(builderCode, "if ~isempty(table) then\n");
Printf(builderCode, " ilib_build(ilib_name, table, files, libs, [], ldflags, cflags);\n"); Printf(builderCode, " ilib_build(ilib_name, table, files, libs, [], ldflags, cflags);\n");
Printf(builderCode, "end\n"); Printf(builderCode, "end\n");
Printf(builderCode, "cd(originaldir);\n");
Printf(builderCode, "exit"); Printf(builderCode, "exit");
builderFile = NewFile(NewStringf("%sbuilder.sce", SWIG_output_directory()), "w", SWIG_output_files()); builderFile = NewFile(NewStringf("%sbuilder.sce", SWIG_output_directory()), "w", SWIG_output_files());
@ -208,13 +221,14 @@ public:
Delete(builderFile); Delete(builderFile);
/* Close the init function (opened in sciinit.swg) */ /* Close the init function (opened in sciinit.swg) */
Printf(initSection, "return 0;\n}\n#endif\n"); Printf(initSection, "return 0;\n}\n");
/* Write all to the wrapper file */ /* Write all to the wrapper file */
SwigType_emit_type_table(runtimeSection, wrappersSection); // Declare pointer types, ... (Ex: SWIGTYPE_p_p_double) SwigType_emit_type_table(runtimeSection, wrappersSection); // Declare pointer types, ... (Ex: SWIGTYPE_p_p_double)
Dump(runtimeSection, beginSection); Dump(runtimeSection, beginSection);
Dump(headerSection, beginSection); Dump(headerSection, beginSection);
Dump(wrappersSection, beginSection); Dump(wrappersSection, beginSection);
Dump(variablesCode, beginSection);
Wrapper_pretty_print(initSection, beginSection); Wrapper_pretty_print(initSection, beginSection);
/* Cleanup files */ /* Cleanup files */
@ -556,6 +570,27 @@ public:
String *constantValue = rawValue ? rawValue : Getattr(node, "value"); String *constantValue = rawValue ? rawValue : Getattr(node, "value");
String *constantTypemap = NULL; String *constantTypemap = NULL;
// If feature scilab:const enabled, constants & enums are wrapped to Scilab variables
if (GetFlag(node, "feature:scilab:const")) {
bool isConstant = ((SwigType_issimple(type)) || (SwigType_type(type) == T_STRING));
bool isEnum = (Cmp(nodeType(node), "enumitem") == 0);
if (isConstant || isEnum) {
constantTypemap = Swig_typemap_lookup("scilabconstcode", node, nodeName, 0);
if (constantTypemap != NULL) {
Setattr(node, "wrap:name", constantName);
Replaceall(constantTypemap, "$result", constantName);
if (isEnum) {
constantValue = Getattr(node, "enumvalue");
}
Replaceall(constantTypemap, "$value", constantValue);
emit_action_code(node, variablesCode, constantTypemap);
Delete(constantTypemap);
return SWIG_OK;
}
}
}
/* Create variables for member pointer constants, not suppported by typemaps (like Python wrapper does) */ /* Create variables for member pointer constants, not suppported by typemaps (like Python wrapper does) */
if (SwigType_type(type) == T_MPOINTER) { if (SwigType_type(type) == T_MPOINTER) {
String *wname = Swig_name_wrapper(constantName); String *wname = Swig_name_wrapper(constantName);
@ -601,9 +636,30 @@ public:
* enumvalueDeclaration() * enumvalueDeclaration()
* --------------------------------------------------------------------- */ * --------------------------------------------------------------------- */
virtual int enumvalueDeclaration(Node *node) { virtual int enumvalueDeclaration(Node *node) {
static int iPreviousEnumValue = 0;
/* Force type to be an enum (See scitypemaps.swg) */ if (GetFlag(node, "feature:scilab:const")) {
Setattr(node, "type", "enum SWIG"); // Compute the "absolute" value of enum if needed
// (most of time enum values are a linked list of relative values)
String *enumValue = Getattr(node, "enumvalue");
if (!enumValue) {
String *enumValueEx = Getattr(node, "enumvalueex");
if (enumValueEx) {
String *firstenumitem = Getattr(node, "firstenumitem");
if (firstenumitem) {
// First node, value is in enumValueEx
Setattr(node, "enumvalue", enumValueEx);
iPreviousEnumValue = atoi(Char(enumValueEx));
}
else {
enumValue = NewString("");
iPreviousEnumValue = iPreviousEnumValue + 1;
Printf(enumValue, "%d", iPreviousEnumValue);
Setattr(node, "enumvalue", enumValue);
}
}
}
}
return Language::enumvalueDeclaration(node); return Language::enumvalueDeclaration(node);
} }