From 20fc167624bc550f051f9f9cc502aefa16338d48 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Thu, 16 Oct 2014 16:00:51 +0200 Subject: [PATCH] scilab: support typed constants (U UL L) in scilabconst(1) --- .../test-suite/scilab/scilab_consts_runme.sci | 51 ++++++++++--------- Examples/test-suite/scilab_consts.i | 10 ++++ Lib/scilab/scitypemaps.swg | 22 +++++++- Lib/scilab/sciunsignedint.swg | 13 +++++ 4 files changed, 70 insertions(+), 26 deletions(-) diff --git a/Examples/test-suite/scilab/scilab_consts_runme.sci b/Examples/test-suite/scilab/scilab_consts_runme.sci index 5c56bb177..d33b45743 100644 --- a/Examples/test-suite/scilab/scilab_consts_runme.sci +++ b/Examples/test-suite/scilab/scilab_consts_runme.sci @@ -1,32 +1,35 @@ exec("swigtest.start", -1); -function checkConst(const_val, expected_type, expected_const_val) - if typeof(const_val) <> expected_type then swigtesterror(); end - if const_val <> expected_const_val then swigtesterror(); end -endfunction +checkequal(ICONST0_get(), 42, "ICONST0_get()"); +checkequal(FCONST0_get(), 2.1828, "FCONST0_get()"); +checkequal(CCONST0_get(), "x", "CCONST0_get()"); +//checkequal(CCONST0_2_get(), "\n", "CCONST0_2_get()"); +checkequal(SCONST0_get(), "Hello World", "SCONST0_get()"); +checkequal(SCONST0_2_get(), """Hello World""", "SCONST0_2_get()"); +checkequal(EXPR0_get(), 48.5484, "EXPR0_get()"); +checkequal(iconst0_get(), 37, "iconst0_get()"); +checkequal(fconst0_get(), 42.2, "fconst0_get()"); -checkConst(ICONST0_get(), "constant", 42); -checkConst(FCONST0_get(), "constant", 2.1828); -checkConst(CCONST0_get(), "string", "x"); -//checkConst(CCONST0_2_get(), "string", "\n"); -checkConst(SCONST0_get(), "string", "Hello World"); -checkConst(SCONST0_2_get(), "string", """Hello World"""); -checkConst(EXPR0_get(), "constant", 48.5484); -checkConst(iconst0_get(), "constant", 37); -checkConst(fconst0_get(), "constant", 42.2); +checkequal(UNSIGNED0_get(), hex2dec("5FFF"), "UNSIGNED0_get()"); +checkequal(LONG0_get(), hex2dec("3FFF0000"), "LONG0_get()"); +checkequal(ULONG0_get(), hex2dec("5FF0000"), "ULONG0_get()"); -if isdef('BAR0') then swigtesterror(); end +if isdef('BAR0') then swigtesterror("BAR0"); end -checkConst(ICONST1, "int32", 42); -checkConst(FCONST1, "constant", 2.1828); -checkConst(CCONST1, "string", "x"); -//checkConst(CCONST1_2, "string", "\n"); -checkConst(SCONST1, "string", "Hello World"); -checkConst(SCONST1_2, "string", """Hello World"""); -checkConst(EXPR1, "constant", 48.5484); -checkConst(iconst0_get(), "constant", 37); -checkConst(fconst0_get(), "constant", 42.2); +checkequal(ICONST1, int32(42), "ICONST1"); +checkequal(FCONST1, 2.1828, "FCONST1"); +checkequal(CCONST1, "x", "CCONST1"); +//checkequal(CCONST1_2, "\n", "CCONST1_2"); +checkequal(SCONST1, "Hello World", "SCONST1"); +checkequal(SCONST1_2, """Hello World""", "SCONST1_2"); +checkequal(EXPR1, 48.5484, "EXPR1"); +checkequal(iconst1, int32(37), "iconst1"); +checkequal(fconst1, 42.2, "fconst1"); -if isdef('BAR1') then swigtesterror(); end +checkequal(UNSIGNED1, uint32(hex2dec("5FFF")), "UNSIGNED1"); +checkequal(LONG1, int32(hex2dec("3FFF0000")), "LONG1"); +checkequal(ULONG1, uint32(hex2dec("5FF0000")), "ULONG1"); + +if isdef('BAR1') then swigtesterror("BAR1"); end exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab_consts.i b/Examples/test-suite/scilab_consts.i index a61116136..11f2504b7 100644 --- a/Examples/test-suite/scilab_consts.i +++ b/Examples/test-suite/scilab_consts.i @@ -10,6 +10,11 @@ #define SCONST0 "Hello World" #define SCONST0_2 "\"Hello World\"" +/* Constants with type */ +#define UNSIGNED0 0x5FFFU +#define LONG0 0x3FFF0000L +#define ULONG0 0x5FF0000UL + /* Expressions should work too */ #define EXPR0 ICONST0 + 3*FCONST0 @@ -31,6 +36,11 @@ #define SCONST1 "Hello World" #define SCONST1_2 "\"Hello World\"" +/* Constants with type */ +#define UNSIGNED1 0x5FFFU +#define LONG1 0x3FFF0000L +#define ULONG1 0x5FF0000UL + /* Expressions should work too */ #define EXPR1 ICONST1 + 3*FCONST1 diff --git a/Lib/scilab/scitypemaps.swg b/Lib/scilab/scitypemaps.swg index 4fbab07c4..7d3aaca59 100644 --- a/Lib/scilab/scitypemaps.swg +++ b/Lib/scilab/scitypemaps.swg @@ -174,15 +174,33 @@ /* %scilabconstcode() feature typemaps */ /* ---------------------------------------------------------------------------*/ +%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(int)) int %{ if (SWIG_CreateScilabVariable_int(pvApiCtx, "$result", $value) != SWIG_OK) return SWIG_ERROR; %} -%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(double)) double +%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(uint)) unsigned int %{ - if (SWIG_CreateScilabVariable_double(pvApiCtx, "$result", $value) != SWIG_OK) + if (SWIG_CreateScilabVariable_uint(pvApiCtx, "$result", $value) != SWIG_OK) + return SWIG_ERROR; +%} + +%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(int)) long +%{ + if (SWIG_CreateScilabVariable_int(pvApiCtx, "$result", $value) != SWIG_OK) + return SWIG_ERROR; +%} + +%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(uint)) unsigned long +%{ + if (SWIG_CreateScilabVariable_uint(pvApiCtx, "$result", $value) != SWIG_OK) return SWIG_ERROR; %} diff --git a/Lib/scilab/sciunsignedint.swg b/Lib/scilab/sciunsignedint.swg index 3e112d8f1..021b0ea90 100644 --- a/Lib/scilab/sciunsignedint.swg +++ b/Lib/scilab/sciunsignedint.swg @@ -189,3 +189,16 @@ SWIG_SciDouble_FromUnsignedIntArrayAndSize(void *pvApiCtx, int iVarOut, int iRow } } +%fragment(SWIG_CreateScilabVariable_frag(uint), "wrapper") { +SWIGINTERN int +SWIG_CreateScilabVariable_dec(uint)(void *pvApiCtx, const char* psVariableName, const unsigned int uiVariableValue) { + SciErr sciErr; + sciErr = createNamedMatrixOfUnsignedInteger32(pvApiCtx, psVariableName, 1, 1, &uiVariableValue); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + return SWIG_OK; +} +} +