summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2023-04-20 07:35:34 +1200
committerOlly Betts <olly@survex.com>2023-04-20 07:35:34 +1200
commitb41107a215a2e9f1e25fed7d3928712d36bb88b5 (patch)
tree382fc0fd0d6338ef35be92108610de0ebc84ded1
parent58160ca4eb5915b3be7873968f362cc26e784407 (diff)
parente351d7faee228acacc6cad893521ae10885e2a6b (diff)
downloadswig-b41107a215a2e9f1e25fed7d3928712d36bb88b5.tar.gz
Merge branch 'scilab-2023'
Closes #2524
-rw-r--r--.github/workflows/ci.yml2
-rw-r--r--CHANGES.current5
-rw-r--r--Doc/Manual/Scilab.html24
-rw-r--r--Lib/scilab/scirun.swg33
-rw-r--r--Source/Modules/scilab.cxx65
-rw-r--r--Tools/CI-linux-install.sh9
-rw-r--r--configure.ac10
7 files changed, 117 insertions, 31 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a9ce5ea03..7b8d16faf 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -181,6 +181,8 @@ jobs:
VER: '6.0.2'
- SWIGLANG: scilab
os: ubuntu-22.04 # scilab 6.1.1
+ - SWIGLANG: scilab
+ VER: '2023.0.0'
- SWIGLANG: tcl
# c++11 testing
- SWIGLANG: csharp
diff --git a/CHANGES.current b/CHANGES.current
index cbfe89da9..f341d52b7 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.2.0 (in progress)
===========================
+2023-04-19: davidcl
+ [Scilab] Add support for Scilab 2023.x.
+ Introduce a `-gatewayxml6` options to generate an XML with full
+ function names.
+
2023-04-19: mmomtchev
https://sourceforge.net/p/swig/bugs/1163/ #2525 Fix preprocessor
expansion when a macro expands to the name of another macro which
diff --git a/Doc/Manual/Scilab.html b/Doc/Manual/Scilab.html
index 95eea340f..7d2c6a66e 100644
--- a/Doc/Manual/Scilab.html
+++ b/Doc/Manual/Scilab.html
@@ -96,8 +96,7 @@ SWIG for Scilab supports Linux. Other operating systems haven't been tested.
</p>
<p>
-Scilab is supported from version 5.3.3 onwards.
-The forthcoming version 6, as of January 2015, is also supported.
+Scilab is supported from version 5.3.3 onwards, the SWIG generated code is supported on both Scilab 5, Scilab 6 and more recent versions.
</p>
<p>
@@ -304,6 +303,11 @@ The following table lists the Scilab specific command line options in addition t
<td>Generate the gateway XML with the given &lt;gateway_id&gt;</td>
</tr>
+<tr>
+<td><tt>-gatewayxml6</tt></td>
+<td>Generate a gateway XML file compatible with Scilab 6</td>
+</tr>
+
</table>
<p>
@@ -2135,6 +2139,20 @@ clear get_file_path;
<li><tt><b>fcts</b></tt>: vector of character strings. The name of new Scilab function.</li>
</ul>
+<H3><a name="Scilab_generated_scripts_gateway">36.7.3 Gateway XML files</a></H3>
+
+<p>If you need to post-process the entry points, Scilab gateway files are XML files that can be used to retrieve all SWIG-generated entry points. With these XML files you can write your own <tt>builder_swig.sce</tt> file to add custom Scilab for building or linking the generated code. Documentation stubs can also be generated thanks to these function listings.</tt></p>
+<p>As an example, for a SWIG <a href="Modules.html">module</a> named <tt>fmuswig</tt> the Scilab code below can be used to store all SWIG-generated functions in a variable named <tt>funs</tt></tt>.</p>
+<div class="code"><pre>
+ // src_swig_path is a path to the directory containing the fmuswig.i file
+
+ doc = xmlRead(src_swig_path + "/fmuswig_gateway.xml");
+ names = xmlAsText(xmlXPath(doc, "//gateway/@name"));
+ funs = xmlAsText(xmlXPath(doc, "//gateway/@function"));
+ xmlDelete(doc);
+
+</pre></div>
+
<H2><a name="Scilab_other_resources">36.8 Other resources</a></H2>
@@ -2142,7 +2160,7 @@ clear get_file_path;
<ul>
<li>Example use cases can be found in the <tt>Examples/scilab</tt> directory.</li>
<li>The test suite in the <tt>Examples/test-suite/scilab</tt> can be another source of useful use cases.</li>
-<li>The <a href="https://help.scilab.org/docs/5.5.0/en_US/api_scilab.html">Scilab API</a> is used in the generated code and is a useful reference when examining the output.</li>
+<li>The <a href="https://help.scilab.org/api_scilab.html">Scilab API</a> is used in the generated code and is a useful reference when examining the output.</li>
<li>This <a href="https://wiki.scilab.org/howto/Create%20a%20toolbox">guide</a> describes the Scilab external modules structure and files, in particular the files that are generated by SWIG for Scilab.</li>
</ul>
diff --git a/Lib/scilab/scirun.swg b/Lib/scilab/scirun.swg
index 586d5f16f..481aac7ac 100644
--- a/Lib/scilab/scirun.swg
+++ b/Lib/scilab/scirun.swg
@@ -5,7 +5,6 @@
/* Scilab version macro */
#include "version.h"
-#define SWIG_SCILAB_VERSION (SCI_VERSION_MAJOR * 100) + (SCI_VERSION_MINOR * 10) + SCI_VERSION_MAINTENANCE
/* Scilab standard headers */
@@ -13,11 +12,11 @@
extern "C" {
#endif
#include "api_scilab.h"
-#if SWIG_SCILAB_VERSION < 540
+#if SCI_VERSION_MAJOR < 5 || SCI_VERSION_MAJOR == 5 && SCI_VERSION_MINOR < 4
#define __USE_DEPRECATED_STACK_FUNCTIONS__
#include "stack-c.h"
#endif
-#if SWIG_SCILAB_VERSION < 600
+#if SCI_VERSION_MAJOR < 6
#include "MALLOC.h"
#endif
#include "Scierror.h"
@@ -31,12 +30,12 @@ extern "C" {
/* Gateway signature */
-#if SWIG_SCILAB_VERSION >= 600
-#define SWIG_GatewayParameters char* fname, void *pvApiCtx
-#define SWIG_GatewayArguments fname, pvApiCtx
-#else
+#if SCI_VERSION_MAJOR < 6
#define SWIG_GatewayParameters char* fname, unsigned long fname_len
#define SWIG_GatewayArguments fname, fname_len
+# else
+#define SWIG_GatewayParameters char* fname, void *pvApiCtx
+#define SWIG_GatewayArguments fname, pvApiCtx
#endif
/* Function name management functions */
@@ -58,29 +57,29 @@ static void SWIG_Scilab_SetFuncName(char *funcName) {
/* Api context management functions */
-#if SWIG_SCILAB_VERSION >= 600
+#if SCI_VERSION_MAJOR < 6
+#define SWIG_Scilab_SetApiContext(apiCtx)
+#else
static void *pvApiCtx = NULL;
static void SWIG_Scilab_SetApiContext(void *apiCtx) {
pvApiCtx = apiCtx;
}
-#else
-#define SWIG_Scilab_SetApiContext(apiCtx)
#endif
/* Argument management functions */
-#if SWIG_SCILAB_VERSION >= 540
-#define SWIG_CheckInputArgument(pvApiCtx, minInputArgument, maxInputArgument) CheckInputArgument(pvApiCtx, minInputArgument, maxInputArgument)
-#define SWIG_CheckInputArgumentAtLeast(pvApiCtx, minInputArgument) CheckInputArgumentAtLeast(pvApiCtx, minInputArgument)
-#define SWIG_CheckOutputArgument(pvApiCtx, minOutputArgument, maxOutputArgument) CheckOutputArgument(pvApiCtx, minOutputArgument, maxOutputArgument)
-#define SWIG_NbInputArgument(pvApiCtx) nbInputArgument(pvApiCtx)
-#define SWIG_AssignOutputArgument(pvApiCtx, outputArgumentPos, argumentPos) AssignOutputVariable(pvApiCtx, outputArgumentPos) = argumentPos
-#else
+#if SCI_VERSION_MAJOR < 5 || SCI_VERSION_MAJOR == 5 && SCI_VERSION_MINOR < 4
#define SWIG_CheckInputArgument(pvApiCtx, minInputArgument, maxInputArgument) CheckRhs(minInputArgument, maxInputArgument)
#define SWIG_CheckInputArgumentAtLeast(pvApiCtx, minInputArgument) CheckRhs(minInputArgument, 256)
#define SWIG_CheckOutputArgument(pvApiCtx, minOutputArgument, maxOutputArgument) CheckLhs(minOutputArgument, maxOutputArgument)
#define SWIG_NbInputArgument(pvApiCtx) Rhs
#define SWIG_AssignOutputArgument(pvApiCtx, outputArgumentPos, argumentPos) LhsVar(outputArgumentPos) = argumentPos
+#else
+#define SWIG_CheckInputArgument(pvApiCtx, minInputArgument, maxInputArgument) CheckInputArgument(pvApiCtx, minInputArgument, maxInputArgument)
+#define SWIG_CheckInputArgumentAtLeast(pvApiCtx, minInputArgument) CheckInputArgumentAtLeast(pvApiCtx, minInputArgument)
+#define SWIG_CheckOutputArgument(pvApiCtx, minOutputArgument, maxOutputArgument) CheckOutputArgument(pvApiCtx, minOutputArgument, maxOutputArgument)
+#define SWIG_NbInputArgument(pvApiCtx) nbInputArgument(pvApiCtx)
+#define SWIG_AssignOutputArgument(pvApiCtx, outputArgumentPos, argumentPos) AssignOutputVariable(pvApiCtx, outputArgumentPos) = argumentPos
#endif
typedef int SwigSciObject;
diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx
index aabd2d842..fede06df2 100644
--- a/Source/Modules/scilab.cxx
+++ b/Source/Modules/scilab.cxx
@@ -26,6 +26,7 @@ Scilab options (available with -scilab)\n \
-buildersources <files> - Add the (comma separated) files <files> to the builder sources\n \
-builderverbositylevel <level> - Set the builder verbosity level to <level> (default 0: off, 2: high)\n \
-gatewayxml <gateway_id> - Generate gateway xml with the given <gateway_id>\n \
+ -gatewayxml6 - Generate gateway xml for Scilab 6\n \
\n";
@@ -64,6 +65,10 @@ protected:
String *gatewayID;
int primitiveID;
+ bool createGatewayXMLV6;
+ File *gatewayXMLFileV6;
+ String *gatewayXMLV6;
+
bool createLoader;
File *loaderFile;
String *loaderScript;
@@ -93,6 +98,10 @@ public:
gatewayXMLFile = NULL;
gatewayID = NULL;
+ createGatewayXMLV6 = false;
+ gatewayXMLV6 = NULL;
+ gatewayXMLFileV6 = NULL;
+
createLoader = true;
loaderFile = NULL;
loaderScript = NULL;
@@ -141,6 +150,9 @@ public:
createGatewayXML = true;
gatewayID = NewString(argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1);
+ } else if (strcmp(argv[argIndex], "-gatewayxml6") == 0) {
+ Swig_mark_arg(argIndex);
+ createGatewayXMLV6 = true;
}
}
}
@@ -216,6 +228,11 @@ public:
createGatewayXMLFile(gatewayName);
}
+ // Create gateway XML V6 if required
+ if (createGatewayXMLV6) {
+ createGatewayXMLFileV6(gatewayName);
+ }
+
// Create loader script if required
if (createLoader) {
createLoaderFile(gatewayLibraryName);
@@ -277,6 +294,9 @@ public:
if (createGatewayXML) {
saveGatewayXMLFile();
}
+ if (createGatewayXMLV6) {
+ saveGatewayXMLFileV6();
+ }
if (createLoader) {
saveLoaderFile(gatewayLibraryName);
@@ -360,7 +380,7 @@ public:
int maxInputArguments = emit_num_arguments(functionParamsList);
int minInputArguments = emit_num_required(functionParamsList);
int minOutputArguments = 0;
- int maxOutputArguments = 1;
+ int maxOutputArguments = 0;
if (!emit_isvarargs(functionParamsList)) {
Printf(wrapper->code, "SWIG_CheckInputArgument(pvApiCtx, $mininputarguments, $maxinputarguments);\n");
@@ -812,6 +832,10 @@ public:
if (gatewayXMLFile) {
Printf(gatewayXML, "<PRIMITIVE gatewayId=\"%s\" primitiveId=\"%d\" primitiveName=\"%s\"/>\n", gatewayID, primitiveID++, scilabSmallFunctionName);
}
+
+ if (gatewayXMLFileV6) {
+ Printf(gatewayXMLV6, "<gateway name=\"%s\" function=\"%s\" type=\"0\"/>\n", scilabFunctionName, scilabFunctionName);
+ }
}
@@ -942,6 +966,39 @@ public:
}
/* -----------------------------------------------------------------------
+ * createGatewayXMLFileV6()
+ * This XML file is used by Scilab 6 in the context of internal modules or
+ * to get the function list.
+ * ----------------------------------------------------------------------- */
+
+ void createGatewayXMLFileV6(String *gatewayName) {
+ String *gatewayXMLFilename = NewStringf("%s_gateway.xml", gatewayName);
+ gatewayXMLFileV6 = NewFile(gatewayXMLFilename, "w", SWIG_output_files());
+ if (!gatewayXMLFileV6) {
+ FileErrorDisplay(gatewayXMLFilename);
+ Exit(EXIT_FAILURE);
+ }
+ // Add a slightly modified SWIG banner to the gateway XML ("--modify" is illegal in XML)
+ gatewayXMLV6 = NewString("");
+ Printf(gatewayXMLV6, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
+ Printf(gatewayXMLV6, "<!DOCTYPE module SYSTEM \"../../functions/xml/gateway.dtd\">\n");
+ Printf(gatewayXMLV6, "<!--\n");
+ Swig_banner_target_lang(gatewayXMLV6, "");
+ Printf(gatewayXMLV6, "-->\n");
+ Printf(gatewayXMLV6, "<module name=\"%s\">\n", gatewayName);
+ }
+
+ /* -----------------------------------------------------------------------
+ * saveGatewayXMLFileV6()
+ * ----------------------------------------------------------------------- */
+
+ void saveGatewayXMLFileV6() {
+ Printf(gatewayXMLV6, "</module>\n");
+ Printv(gatewayXMLFileV6, gatewayXMLV6, NIL);
+ Delete(gatewayXMLFileV6);
+ }
+
+ /* -----------------------------------------------------------------------
* createGatewayXMLFile()
* This XML file is used by Scilab in the context of internal modules
* ----------------------------------------------------------------------- */
@@ -1046,10 +1103,10 @@ public:
Printf(gatewayHeaderV6, "return 1;\n");
Printf(gatewayHeaderV6, "};\n");
- Printf(gatewayHeader, "#if SWIG_SCILAB_VERSION >= 600\n");
- Printv(gatewayHeader, gatewayHeaderV6, NIL);
- Printf(gatewayHeader, "#else\n");
+ Printf(gatewayHeader, "#if SCI_VERSION_MAJOR < 6\n");
Printv(gatewayHeader, gatewayHeaderV5, NIL);
+ Printf(gatewayHeader, "#else\n");
+ Printv(gatewayHeader, gatewayHeaderV6, NIL);
Printf(gatewayHeader, "#endif\n");
}
diff --git a/Tools/CI-linux-install.sh b/Tools/CI-linux-install.sh
index 93bb46412..5352eb3fa 100644
--- a/Tools/CI-linux-install.sh
+++ b/Tools/CI-linux-install.sh
@@ -152,10 +152,15 @@ case "$SWIGLANG" in
if [[ -z "$VER" ]]; then
$RETRY sudo apt-get -qq install scilab
else
- $RETRY wget --progress=dot:giga "https://www.scilab.org/download/$VER/scilab-$VER.bin.linux-x86_64.tar.gz"
+ # Download was .gz but switched to .xz for version 2023.0.0.
+ case $VER in
+ 20*) scilab_tarball=scilab-$VER.bin.linux-x86_64.tar.xz ;;
+ *) scilab_tarball=scilab-$VER.bin.linux-x86_64.tar.gz ;;
+ esac
+ $RETRY wget --progress=dot:giga "https://www.scilab.org/download/$VER/$scilab_tarball"
# $HOME/.local/bin is in PATH and writeable
mkdir -p "$HOME/.local"
- tar -xzf "scilab-$VER.bin.linux-x86_64.tar.gz" --strip-components=1 -C "$HOME/.local"
+ tar -xzf "$scilab_tarball" --strip-components=1 -C "$HOME/.local"
fi
;;
"tcl")
diff --git a/configure.ac b/configure.ac
index c0f57571f..050d97533 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2404,13 +2404,13 @@ else
# Check for Scilab version (needs api_scilab so needs version 5.3.3 or higher)
SCILAB_VERSION=`$SCILAB -nwni -version | head -1 | sed -e 's|Scilab version \"\(.*\)\"|\1|g'`
- AC_MSG_CHECKING(Scilab version is 5.3.3 or higher)
+ AC_MSG_CHECKING(Scilab version is higher than 5.3.2)
SCILAB_MAJOR_VERSION=`echo $SCILAB_VERSION | cut -d. -f1`
SCILAB_MINOR_VERSION=`echo $SCILAB_VERSION | cut -d. -f2`
SCILAB_MAINTENANCE_VERSION=`echo $SCILAB_VERSION | cut -d. -f3`
- SCILAB_VERSION_NO_DOTS="$SCILAB_MAJOR_VERSION$SCILAB_MINOR_VERSION$SCILAB_MAINTENANCE_VERSION"
+ SCILAB_VERSION_NO_DOTS=`printf '%04d%02d%02d' "$SCILAB_MAJOR_VERSION" "$SCILAB_MINOR_VERSION" "$SCILAB_MAINTENANCE_VERSION"`
- if test -n "$SCILAB_VERSION_NO_DOTS" && test "$SCILAB_VERSION_NO_DOTS" -ge 533; then
+ if test "$SCILAB_VERSION_NO_DOTS" -ge 00050303; then
AC_MSG_RESULT(yes - $SCILAB_VERSION)
else
AC_MSG_RESULT(no - $SCILAB_VERSION)
@@ -2421,10 +2421,10 @@ else
# Set Scilab startup options depending on version
AC_MSG_CHECKING(for Scilab startup options)
SCILABOPT="-nwni -nb"
- if test $SCILAB_VERSION_NO_DOTS -ge 540; then
+ if test "$SCILAB_VERSION_NO_DOTS" -ge 00050400; then
SCILABOPT+=" -noatomsautoload"
fi
- if test $SCILAB_VERSION_NO_DOTS -ge 600; then
+ if test "$SCILAB_VERSION_NO_DOTS" -ge 00060000; then
SCILABOPT+=" -quit"
fi
AC_MSG_RESULT($SCILABOPT)