call_scilab plugged. 36/16336/10
Cedric Delamarre [Wed, 8 Apr 2015 09:50:03 +0000 (11:50 +0200)]
Change-Id: I308dfa334ca52f90ea4901147559523805bb0917

29 files changed:
scilab/modules/ast/includes/symbol/variables.hxx
scilab/modules/ast/includes/system_env/configvariable_interface.h
scilab/modules/ast/src/cpp/system_env/configvariable.cpp
scilab/modules/ast/src/cpp/system_env/configvariable_interface.cpp
scilab/modules/call_scilab/Makefile.am
scilab/modules/call_scilab/Makefile.in
scilab/modules/call_scilab/call_scilab.vcxproj
scilab/modules/call_scilab/core_Import.def
scilab/modules/call_scilab/examples/call_scilab/c/visual_studio/CallSciVC.vcxproj
scilab/modules/call_scilab/examples/call_scilab/c/visual_studio/CallsciC.c
scilab/modules/call_scilab/includes/call_scilab.h
scilab/modules/call_scilab/src/c/SendScilabJobs.c
scilab/modules/call_scilab/src/c/call_scilab.c
scilab/modules/call_scilab/tests/nonreg_tests/Makefile [new file with mode: 0644]
scilab/modules/call_scilab/tests/nonreg_tests/bug_7601.c [new file with mode: 0644]
scilab/modules/call_scilab/tests/nonreg_tests/bug_7601.tst
scilab/modules/call_scilab/tests/nonreg_tests/bug_7602.c [new file with mode: 0644]
scilab/modules/call_scilab/tests/nonreg_tests/bug_7602.tst
scilab/modules/call_scilab/tests/nonreg_tests/bug_8115.c [new file with mode: 0644]
scilab/modules/call_scilab/tests/nonreg_tests/bug_8115.tst
scilab/modules/call_scilab/tests/nonreg_tests/bug_8830.c [new file with mode: 0644]
scilab/modules/call_scilab/tests/nonreg_tests/bug_8830.tst
scilab/modules/core/includes/InitScilab.h
scilab/modules/core/sci_gateway/cpp/sci_argn.cpp
scilab/modules/core/sci_gateway/cpp/sci_sciargs.cpp
scilab/modules/core/src/cpp/InitScilab.cpp
scilab/modules/core/src/cpp/runner.cpp
scilab/modules/fileio/includes/expandPathVariable.h
scilab/modules/fileio/src/cpp/expandPathVariable.cpp

index b0e4483..258d79a 100644 (file)
@@ -552,6 +552,8 @@ struct Variables
         {
             delete var.second;
         }
+
+        vars.clear();
     }
 
 private:
index b174a23..94b7bd8 100644 (file)
@@ -70,7 +70,7 @@ EXTERN_AST int checkReferenceModule(const wchar_t* _module);
 EXTERN_AST void addReferenceModule(const wchar_t* _module);
 EXTERN_AST void removeReferenceModule(const wchar_t* _module);
 
-
+EXTERN_AST int getForceQuit();
 
 EXTERN_AST int getEntryPointPosition(wchar_t* _pwstEntryPointName);
 typedef void(*dynlib_ptr)();
index c9875b7..58db82a 100644 (file)
@@ -221,7 +221,7 @@ int ConfigVariable::getConsoleLines(void)
 ** \{
 */
 
-int ConfigVariable::m_iScilabMode = 0;
+int ConfigVariable::m_iScilabMode = 1; //SCILAB_API = 1  Scilab is launch as an API
 
 void ConfigVariable::setScilabMode(int _iScilabMode)
 {
@@ -878,13 +878,16 @@ void ConfigVariable::setCommandLineArgs(int _iArgs, char** _pstArgs)
 
 wchar_t** ConfigVariable::getCommandLineArgs(int* _piCount)
 {
-    wchar_t** pwstArgs = (wchar_t**)MALLOC(m_Args.size() * sizeof(wchar_t*));
-    for (int i = 0 ; i < (int)m_Args.size() ; i++)
+    wchar_t** pwstArgs = NULL;
+    *_piCount = (int)m_Args.size();
+    if (*_piCount != 0)
     {
-        pwstArgs[i] = os_wcsdup(m_Args[i].c_str());
+        pwstArgs = (wchar_t**)MALLOC(*_piCount * sizeof(wchar_t*));
+        for (int i = 0; i < *_piCount; i++)
+        {
+            pwstArgs[i] = os_wcsdup(m_Args[i].c_str());
+        }
     }
-
-    *_piCount = (int)m_Args.size();
     return pwstArgs;
 }
 
index 5e50918..f309d4d 100644 (file)
@@ -191,3 +191,8 @@ dynlib_ptr getEntryPointFromPosition(int position)
 {
     return ConfigVariable::getEntryPointFromPosition(position);
 }
+
+int getForceQuit()
+{
+    return ConfigVariable::getForceQuit();
+}
index c293476..34d5c01 100644 (file)
@@ -36,6 +36,7 @@ libscicall_scilab_la_CPPFLAGS= \
     -I$(top_srcdir)/modules/core/src/c/ \
     -I$(top_srcdir)/modules/string/includes/ \
     -I$(top_srcdir)/modules/console/includes/ \
+    -I$(top_srcdir)/modules/threads/includes/ \
     $(AM_CPPFLAGS)
 
 pkglib_LTLIBRARIES = libscicall_scilab.la
index 63b373f..30d5e2b 100644 (file)
@@ -567,6 +567,7 @@ libscicall_scilab_la_CPPFLAGS = \
     -I$(top_srcdir)/modules/core/src/c/ \
     -I$(top_srcdir)/modules/string/includes/ \
     -I$(top_srcdir)/modules/console/includes/ \
+    -I$(top_srcdir)/modules/threads/includes/ \
     $(AM_CPPFLAGS)
 
 pkglib_LTLIBRARIES = libscicall_scilab.la
index 75b5dc4..c49a766 100644 (file)
@@ -80,7 +80,7 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>includes;src/c;../../libs/intl;../core/includes;../api_scilab/includes;../fileio/includes;../windows_tools/includes;../windows_tools/src/c/scilab_windows;../windows_tools/src/cpp/scilab_windows;../localization/includes;../action_binding/includes;../output_stream/includes;../graphics/includes../../libs/intl;../graphic_objects/includes;../string/includes;../console/includes;../ast/includes/types;../ast/includes/ast;../ast/includes/analysis;../ast/includes/exps;../ast/includes/operations;../ast/includes/symbol;../ast/includes/system_env;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>includes;src/c;../../libs/intl;../core/includes;../api_scilab/includes;../fileio/includes;../windows_tools/includes;../windows_tools/src/c/scilab_windows;../windows_tools/src/cpp/scilab_windows;../localization/includes;../action_binding/includes;../output_stream/includes;../graphics/includes../../libs/intl;../graphic_objects/includes;../string/includes;../console/includes;../ast/includes/types;../ast/includes/ast;../ast/includes/analysis;../ast/includes/exps;../ast/includes/operations;../ast/includes/symbol;../ast/includes/system_env;../threads/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>FORDLL;_DEBUG;_WINDOWS;_USRDLL;CALL_SCILAB_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
       <WarningLevel>Level3</WarningLevel>
@@ -112,7 +112,7 @@ lib /DEF:"$(ProjectDir)core_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform
     </Midl>
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>includes;src/c;../../libs/intl;../core/includes;../api_scilab/includes;../fileio/includes;../windows_tools/includes;../windows_tools/src/c/scilab_windows;../windows_tools/src/cpp/scilab_windows;../localization/includes;../action_binding/includes;../output_stream/includes;../graphics/includes../../libs/intl;../graphic_objects/includes;../string/includes;../console/includes;../ast/includes/types;../ast/includes/ast;../ast/includes/analysis;../ast/includes/exps;../ast/includes/operations;../ast/includes/symbol;../ast/includes/system_env;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>includes;src/c;../../libs/intl;../core/includes;../api_scilab/includes;../fileio/includes;../windows_tools/includes;../windows_tools/src/c/scilab_windows;../windows_tools/src/cpp/scilab_windows;../localization/includes;../action_binding/includes;../output_stream/includes;../graphics/includes../../libs/intl;../graphic_objects/includes;../string/includes;../console/includes;../ast/includes/types;../ast/includes/ast;../ast/includes/analysis;../ast/includes/exps;../ast/includes/operations;../ast/includes/symbol;../ast/includes/system_env;../threads/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>FORDLL;_DEBUG;_WINDOWS;_USRDLL;CALL_SCILAB_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
       <WarningLevel>Level3</WarningLevel>
@@ -142,7 +142,7 @@ lib /DEF:"$(ProjectDir)core_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform
     <ClCompile>
       <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
       <WholeProgramOptimization>false</WholeProgramOptimization>
-      <AdditionalIncludeDirectories>includes;src/c;../../libs/intl;../core/includes;../api_scilab/includes;../fileio/includes;../windows_tools/includes;../windows_tools/src/c/scilab_windows;../windows_tools/src/cpp/scilab_windows;../localization/includes;../action_binding/includes;../output_stream/includes;../graphics/includes../../libs/intl;../graphic_objects/includes;../string/includes;../console/includes;../ast/includes/types;../ast/includes/ast;../ast/includes/analysis;../ast/includes/exps;../ast/includes/operations;../ast/includes/symbol;../ast/includes/system_env;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>includes;src/c;../../libs/intl;../core/includes;../api_scilab/includes;../fileio/includes;../windows_tools/includes;../windows_tools/src/c/scilab_windows;../windows_tools/src/cpp/scilab_windows;../localization/includes;../action_binding/includes;../output_stream/includes;../graphics/includes../../libs/intl;../graphic_objects/includes;../string/includes;../console/includes;../ast/includes/types;../ast/includes/ast;../ast/includes/analysis;../ast/includes/exps;../ast/includes/operations;../ast/includes/symbol;../ast/includes/system_env;../threads/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>FORDLL;NDEBUG;_WINDOWS;_USRDLL;CALL_SCILAB_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <StringPooling>true</StringPooling>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
@@ -180,7 +180,7 @@ lib /DEF:"$(ProjectDir)core_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform
     <ClCompile>
       <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
       <WholeProgramOptimization>false</WholeProgramOptimization>
-      <AdditionalIncludeDirectories>includes;src/c;../../libs/intl;../core/includes;../api_scilab/includes;../fileio/includes;../windows_tools/includes;../windows_tools/src/c/scilab_windows;../windows_tools/src/cpp/scilab_windows;../localization/includes;../action_binding/includes;../output_stream/includes;../graphics/includes../../libs/intl;../graphic_objects/includes;../string/includes;../console/includes;../ast/includes/types;../ast/includes/ast;../ast/includes/analysis;../ast/includes/exps;../ast/includes/operations;../ast/includes/symbol;../ast/includes/system_env;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>includes;src/c;../../libs/intl;../core/includes;../api_scilab/includes;../fileio/includes;../windows_tools/includes;../windows_tools/src/c/scilab_windows;../windows_tools/src/cpp/scilab_windows;../localization/includes;../action_binding/includes;../output_stream/includes;../graphics/includes../../libs/intl;../graphic_objects/includes;../string/includes;../console/includes;../ast/includes/types;../ast/includes/ast;../ast/includes/analysis;../ast/includes/exps;../ast/includes/operations;../ast/includes/symbol;../ast/includes/system_env;../threads/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>FORDLL;NDEBUG;_WINDOWS;_USRDLL;CALL_SCILAB_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <StringPooling>true</StringPooling>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
@@ -275,6 +275,9 @@ lib /DEF:"$(ProjectDir)core_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform
       <Project>{a5911cd7-f8e8-440c-a23e-4843a0636f3a}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
     </ProjectReference>
+    <ProjectReference Include="..\threads\threads.vcxproj">
+      <Project>{50a1ffc8-adc2-4d9e-a2d0-5dcd63188ae9}</Project>
+    </ProjectReference>
     <ProjectReference Include="..\windows_tools\src\c\scilab_windows\scilab_windows.vcxproj">
       <Project>{8028f371-6a94-4a26-8804-6e7f05f1d1aa}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
index 68a346e..15094f5 100644 (file)
@@ -20,3 +20,5 @@ StartScilabEngine
 ExecExternalCommand
 StopScilabEngine
 InitScilabEngineInfo
+StoreConsoleCommand
+RunScilabEngine
index 103e3e9..f14d19d 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="Debug|Win32">
       <Configuration>Debug</Configuration>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v120</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v120</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v120</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v120</PlatformToolset>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
   <PropertyGroup Label="UserMacros" />
   <PropertyGroup>
     <_ProjectFileVersion>10.0.31118.1</_ProjectFileVersion>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug\</OutDir>
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../../../../../bin\</OutDir>
     <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug\</IntDir>
     <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</OutDir>
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">../../../../../../bin\</OutDir>
     <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir>
     <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</OutDir>
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../../../../../bin\</OutDir>
     <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</IntDir>
     <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
-    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</OutDir>
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">../../../../../../bin\</OutDir>
     <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</IntDir>
     <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
   </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <TargetName>CallSciVC</TargetName>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <TargetName>CallSciVC</TargetName>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <TargetName>CallSciVC</TargetName>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <TargetName>CallSciVC</TargetName>
+  </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
       <Optimization>Disabled</Optimization>
index dd365b7..8075d86 100644 (file)
@@ -9,7 +9,6 @@
 #include <string.h>
 #include "call_scilab.h"
 #include "api_scilab.h"
-#include "stack-c.h"
 /*--------------------------------------------------------------------------*/
 /* See SCI/modules/core/includes/call_scilab.h */
 /* See SCI/modules/core/includes/api_scilab.h */
@@ -25,14 +24,14 @@ static int example1(void)
     int mb = 2, nb = 1;
 
     /* Create Scilab matrices A and b */
-    sciErr = createNamedMatrixOfDouble(pvApiCtx, "A", mA, nA, A);
+    sciErr = createNamedMatrixOfDouble(NULL, "A", mA, nA, A);
     if (sciErr.iErr)
     {
         printError(&sciErr, 0);
         return -1;
     }
 
-    sciErr = createNamedMatrixOfDouble(pvApiCtx, "b", mb, nb, b);
+    sciErr = createNamedMatrixOfDouble(NULL, "b", mb, nb, b);
     if (sciErr.iErr)
     {
         printError(&sciErr, 0);
@@ -56,7 +55,7 @@ static int example1(void)
         int i = 0;
 
         /* Get m and n dimensions of x */
-        sciErr = readNamedMatrixOfDouble(pvApiCtx, "x", &m, &n , NULL);
+        sciErr = readNamedMatrixOfDouble(NULL, "x", &m, &n, NULL);
         if (sciErr.iErr)
         {
             printError(&sciErr, 0);
@@ -64,7 +63,7 @@ static int example1(void)
         }
 
         cxtmp = (double*)malloc((m * n) * sizeof(double));
-        sciErr = readNamedMatrixOfDouble(pvApiCtx, "x", &m, &n , cxtmp);
+        sciErr = readNamedMatrixOfDouble(NULL, "x", &m, &n, cxtmp);
         if (sciErr.iErr)
         {
             printError(&sciErr, 0);
@@ -89,10 +88,7 @@ static int example2(void)
 {
     SendScilabJob("plot3d();");
     printf("\nClose Graphical Windows to close this example.\n");
-    while ( ScilabHaveAGraph() )
-    {
-        ScilabDoOneEvent();
-    }
+    while (ScilabHaveAGraph());
     return 1;
 }
 /*--------------------------------------------------------------------------*/
@@ -152,10 +148,10 @@ int main(void)
     printf("\nexample 1\n");
     example1();
     system("pause");
-    printf("\nexample 2\n");
+    //printf("\nexample 2\n");
     example2();
     system("pause");
-    printf("\nexample 3\n");
+    //printf("\nexample 3\n");
     example3();
     system("pause");
 
index 8dde67a..723aef0 100644 (file)
 extern "C" {
 #endif
 
-    /*--------------------------------------------------------------------------*/
+/*--------------------------------------------------------------------------*/
 #include "machine.h"
 #include "BOOL.h"
 #include "sci_types.h"
-    /*--------------------------------------------------------------------------*/
-
-    /**
-     * Disable Tcl/Tk and graphic interfaces
-     * Scilab no GUI no Tcl/Tk "kernel mode"
-     */
-    void DisableInteractiveMode(void);
-
-    /**
-     * Initialize Scilab
-     * @param SCIpath define SCI environment variable : Default --> NULL
-     * @param ScilabStartup path & filename of scilab.start : Default --> NULL
-     * @param Stacksize : Default --> NULL
-     * @return TRUE if it is OK else FALSE
-    */
-    BOOL StartScilab(char *SCIpath, char *ScilabStartup, int Stacksize);
-
-    /**
-     * Start Scilab engine
-     * Function created in the context of javasci v2.
-     * This function is just like StartScilab but provides more error messages
-     * in case or error. For now, it is only used in javasci v2 but it might
-     * be public sooner or later.
-     * @return
-     * 0: success
-     * -1: already running
-     * -2: Could not find SCI
-     * -3: No existing directory
-     * Any other positive integer: A Scilab internal error
-     */
-    int Call_ScilabOpen(char* SCIpath, BOOL advancedMode, char *ScilabStartup, int Stacksize);
-
-    /**
-     * Terminate Scilab
-     * @param ScilabQuit path & filename of scilab.quit : Default --> NULL
-     * @return TRUE if it is OK else FALSE
-    */
-    BOOL TerminateScilab(char *ScilabQuit);
-
-    /**
-     * Send a job to scilab
-     * @param job the Scilab Job
-     * @return error code operation 0 : OK
-    */
-    int SendScilabJob(char *job);
-
-    /**
-     * Send jobs to scilab
-     * @code
-     *         jobs[0] : a = 1;
-     *         jobs[1] : b = 3;
-     * jobs[2] : c = a + b;
-     * SendScilabJobs(jobs,3);
-     * @endcode
-     * @return last error code operation 0 : OK
-    **/
-    int SendScilabJobs(char **jobs, int numberjobs);
-
-    /**
-     * Returns last job send to scilab by SendScilabJobs or SendScilabJob
-     * @param[out] JOB the last job
-     * @param[out] nbcharsJOB the size of JOB
-     * @code
-     * Example :
-     * jobs[0] : a = 1;
-     * jobs[1] : b = V_NOT_EXIST;
-     * jobs[2] : c = a + b;
-     * if (SendScilabJobs(jobs,3))
-     * {
-     *         char lastjob[4096]; // bsiz in scilab
-     * if (GetLastJob(lastjob,4096))
-     * {
-     *         printf("%s\n",lastjob);
-     * }
-     * }
-     * @endcode
-     * @return
-    **/
-    BOOL GetLastJob(char *JOB, int nbcharsJOB);
-
-    /**
-    * This procedure is the entry point to Scilab's event loop
-    */
-    void ScilabDoOneEvent(void);
-
-    /**
-     * Get the information is a graphic windows is opened or not
-     * @return Returns TRUE if a graphic windows is opened
-    */
-    int ScilabHaveAGraph(void);
-
-    /**
-     * Return the type of a variable
-     * This function is supposed to be used only in the call_scilab context
-     *
-     * @param varName the variable name
-     * @return the type of the variable (the enum is defined in sci_types)
-     * Returns -1 when an error occurs -2 when varName cannot be found
-     */
-    sci_types getVariableType(char *varName);
-
-    /**
-     * This function returns the last error code generated by Scilab
-     * It should be used to check if a previous command executed by SendScilabJob
-     * fail or not
-     * @return 0 if no error. Not 0 for an error.
-     */
-    int getLastErrorValue(void);
-
-    /**
-     * This function returns the last error message generated by Scilab
-     * It should be used to display the error which occurred
-     * @return the error message
-     */
-    char* getLastErrorMessageSingle(void);
-
-    /********************* DATATYPES MANAGEMENT FUNCTIONS ************/
-
-    /* See the API_scilab documentation See: http://help.scilab.org/api_scilab */
-    /* #include "api_scilab.h" */
+/*--------------------------------------------------------------------------*/
+
+/**
+ * Disable Tcl/Tk and graphic interfaces
+ * Scilab no GUI no Tcl/Tk "kernel mode"
+ */
+void DisableInteractiveMode(void);
+
+/**
+ * Initialize Scilab
+ * @param SCIpath define SCI environment variable : Default --> NULL
+ * @param ScilabStartup path & filename of scilab.start : Default --> NULL
+ * @param Stacksize : Default --> NULL
+ * @return TRUE if it is OK else FALSE
+*/
+BOOL StartScilab(char *SCIpath, char *ScilabStartup, int Stacksize);
+
+/**
+ * Start Scilab engine
+ * Function created in the context of javasci v2.
+ * This function is just like StartScilab but provides more error messages
+ * in case or error. For now, it is only used in javasci v2 but it might
+ * be public sooner or later.
+ * @return
+ * 0: success
+ * -1: already running
+ * -2: Could not find SCI
+ * -3: No existing directory
+ * Any other positive integer: A Scilab internal error
+ */
+int Call_ScilabOpen(char* SCIpath, BOOL advancedMode, char *ScilabStartup, int Stacksize);
+
+/**
+ * Terminate Scilab
+ * @param ScilabQuit path & filename of scilab.quit : Default --> NULL
+ * @return TRUE if it is OK else FALSE
+*/
+BOOL TerminateScilab(char *ScilabQuit);
+
+/**
+ * Send a job to scilab
+ * @param job the Scilab Job
+ * @return error code operation 0 : OK
+*/
+int SendScilabJob(char *job);
+
+/**
+ * Send jobs to scilab
+ * @code
+ *     jobs[0] : a = 1;
+ *     jobs[1] : b = 3;
+ *     jobs[2] : c = a + b;
+ *     SendScilabJobs(jobs,3);
+ * @endcode
+ * @return last error code operation 0 : OK
+**/
+int SendScilabJobs(char **jobs, int numberjobs);
+
+/**
+ * Returns last job send to scilab by SendScilabJobs or SendScilabJob
+ * @param[out] JOB the last job
+ * @param[out] nbcharsJOB the size of JOB
+ * @code
+ * Example :
+ * jobs[0] : a = 1;
+ * jobs[1] : b = V_NOT_EXIST;
+ * jobs[2] : c = a + b;
+ * if (SendScilabJobs(jobs,3))
+ * {
+ *     char lastjob[4096]; // bsiz in scilab
+ *     if (GetLastJob(lastjob,4096))
+ *     {
+ *             printf("%s\n",lastjob);
+ *     }
+ * }
+ * @endcode
+ * @return
+**/
+BOOL GetLastJob(char *JOB, int nbcharsJOB);
+
+/**
+* This procedure is the entry point to Scilab's event loop
+*/
+void ScilabDoOneEvent(void);
+
+/**
+ * Get the information is a graphic windows is opened or not
+ * @return Returns TRUE if a graphic windows is opened
+*/
+int ScilabHaveAGraph(void);
+
+/**
+ * Return the type of a variable
+ * This function is supposed to be used only in the call_scilab context
+ *
+ * @param varName the variable name
+ * @return the type of the variable (the enum is defined in sci_types)
+ * Returns -1 when an error occurs -2 when varName cannot be found
+ */
+sci_types getVariableType(char *varName);
+
+/**
+ * This function returns the last error code generated by Scilab
+ * It should be used to check if a previous command executed by SendScilabJob
+ * fail or not
+ * @return 0 if no error. Not 0 for an error.
+ */
+int getLastErrorValue(void);
+
+/**
+ * This function returns the last error message generated by Scilab
+ * It should be used to display the error which occurred
+ * @return the error message
+ */
+char* getLastErrorMessageSingle(void);
+
+/********************* DATATYPES MANAGEMENT FUNCTIONS ************/
 
+/* See the API_scilab documentation See: http://help.scilab.org/api_scilab */
+/* #include "api_scilab.h" */
 
 #ifdef __cplusplus
 }
index 1b01361..75ed4ba 100644 (file)
@@ -37,8 +37,8 @@ int SendScilabJob(char *job)
     int retCode = -1;
     char *command = NULL;
 
-#define COMMAND_EXECSTR  "Err_Job = execstr(TMP_EXEC_STRING,\"errcatch\",\"n\");quit;"
-#define COMMAND_CLEAR "clear TMP_EXEC_STRING;clear Err_Job;quit;"
+#define COMMAND_EXECSTR  "Err_Job = execstr(TMP_EXEC_STRING,\"errcatch\");"
+#define COMMAND_CLEAR "clear TMP_EXEC_STRING;clear Err_Job;"
 
     if (getCallScilabEngineState() == CALL_SCILAB_ENGINE_STOP)
     {
@@ -54,10 +54,6 @@ int SendScilabJob(char *job)
         int m = 0, n = 0;
         ScilabEngineInfo* pSEI = InitScilabEngineInfo();
 
-        /* clear prev. Err , TMP_EXEC_STRING scilab variables */
-        pSEI->pstExec = COMMAND_CLEAR;
-        ExecExternalCommand(pSEI);
-
         SetLastJob(command);
 
         /* Creation of a temp variable in Scilab which contains the command */
@@ -79,8 +75,6 @@ int SendScilabJob(char *job)
             return retCode;
         }
 
-
-
         /* Run the command within an execstr */
         pSEI->pstExec = COMMAND_EXECSTR;
         ExecExternalCommand(pSEI);
index 835bb8e..eac2b1d 100644 (file)
@@ -24,7 +24,7 @@
 #include "sci_path.h"
 #include "scilabDefaults.h"
 #include "sci_tmpdir.h"
-//#include "scirun.h"
+#include "Thread_Wrapper.h"
 #include "storeCommand.h"
 #include "FigureList.h"
 #include "api_scilab.h"
@@ -49,7 +49,8 @@ static void TermPrintf(const char *text)
     printf("%s", text);
 }
 
-
+static ScilabEngineInfo* pGlobalSEI = NULL;
+static __threadId threadIdScilab;
 
 /*--------------------------------------------------------------------------*/
 static CALL_SCILAB_ENGINE_STATE csEngineState = CALL_SCILAB_ENGINE_STOP;
@@ -77,19 +78,17 @@ BOOL StartScilab(char *SCIpath, char *ScilabStartup, int Stacksize)
 * -1: already running
 * -2: Could not find SCI
 * -3: No existing directory
-* 10001: Stacksize failed (not enought memory ?).
 * Any other positive integer: A Scilab internal error
 */
 
-#define FORMAT_SCRIPT_STARTUP "_errorCall_ScilabOpen = exec(\"%s\", \"errcatch\", -1); exit(_errorCall_ScilabOpen);"
+#define FORMAT_SCRIPT_STARTUP "_errorCall_ScilabOpen = exec(\"%s\", \"errcatch\", -1);"
 
 int Call_ScilabOpen(char *SCIpath, BOOL advancedMode, char *ScilabStartup, int Stacksize)
 {
+    __threadKey threadKeyScilab;
     char *InitStringToScilab = NULL;
     static int iflag = -1, ierr = 0;
-    ScilabEngineInfo* pSEI = NULL;
 
-    setScilabMode(SCILAB_API);
     if (advancedMode == FALSE)
     {
         DisableInteractiveMode();
@@ -120,24 +119,31 @@ int Call_ScilabOpen(char *SCIpath, BOOL advancedMode, char *ScilabStartup, int S
         }
     }
 
-    pSEI = InitScilabEngineInfo();
+    pGlobalSEI = InitScilabEngineInfo();
     if (ScilabStartup)
     {
         int lengthStringToScilab = (int)(strlen(FORMAT_SCRIPT_STARTUP) + strlen(ScilabStartup) + 1);
         InitStringToScilab = (char *)MALLOC(lengthStringToScilab * sizeof(char));
         sprintf(InitStringToScilab, FORMAT_SCRIPT_STARTUP, ScilabStartup);
-        pSEI->iNoStart = 1;
+        pGlobalSEI->iNoStart = 1;
     }
 
     setScilabInputMethod(&getCmdLine);
     setScilabOutputMethod(&TermPrintf);
 
     /* Scilab Initialization */
-    pSEI->pstFile = InitStringToScilab;
-    pSEI->iNoJvm = 1;
-    pSEI->iConsoleMode = 1;
-    ierr = StartScilabEngine(pSEI);
-    FREE(pSEI);
+    pGlobalSEI->pstFile = InitStringToScilab;
+    pGlobalSEI->iConsoleMode = 1;
+    pGlobalSEI->iStartConsoleThread = 0;
+
+    if (getScilabMode() != SCILAB_NWNI)
+    {
+        pGlobalSEI->iNoJvm = 1;
+    }
+
+    pGlobalSEI->iNoJvm = 0;
+
+    ierr = StartScilabEngine(pGlobalSEI);
 
     if (InitStringToScilab)
     {
@@ -147,9 +153,12 @@ int Call_ScilabOpen(char *SCIpath, BOOL advancedMode, char *ScilabStartup, int S
 
     if (ierr)
     {
+        FREE(pGlobalSEI);
         return ierr;
     }
 
+    __CreateThreadWithParams(&threadIdScilab, &threadKeyScilab, &RunScilabEngine, pGlobalSEI);
+
     setCallScilabEngineState(CALL_SCILAB_ENGINE_STARTED);
 
     return 0;
@@ -160,15 +169,30 @@ BOOL TerminateScilab(char *ScilabQuit)
 {
     if (getCallScilabEngineState() == CALL_SCILAB_ENGINE_STARTED)
     {
-        ScilabEngineInfo* pSEI = InitScilabEngineInfo();
-        pSEI->pstFile = ScilabQuit;
-        StopScilabEngine(pSEI);
+        if (getForceQuit() == 0)
+        {
+            if (pGlobalSEI->iNoStart)
+            {
+                StoreConsoleCommand("exit(_errorCall_ScilabOpen)");
+            }
+            else
+            {
+                StoreConsoleCommand("exit()");
+            }
+        }
+
+        __WaitThreadDie(threadIdScilab);
+        pGlobalSEI->pstFile = ScilabQuit;
+        StopScilabEngine(pGlobalSEI);
 
         setCallScilabEngineState(CALL_SCILAB_ENGINE_STOP);
 
         /* restore default mode */
         setScilabMode(SCILAB_API);
 
+        FREE(pGlobalSEI);
+        pGlobalSEI = NULL;
+
         return TRUE;
     }
     return FALSE;
@@ -249,8 +273,6 @@ char *getLastErrorMessageSingle(void)
 int getLastErrorValue(void)
 {
     /* defined in lasterror.h */
-    // FIXME : Call system_env function
-    //return getInternalLastErrorValue();
-    return 0;
+    return getLastErrorNumber();
 }
 /*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/call_scilab/tests/nonreg_tests/Makefile b/scilab/modules/call_scilab/tests/nonreg_tests/Makefile
new file mode 100644 (file)
index 0000000..67f3058
--- /dev/null
@@ -0,0 +1,53 @@
+#=============================================================================
+#Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+#Copyright (C) 2015 - Scilab-Enterprises - Cedric Delamarre
+#This file is distributed under the same license as the Scilab package.
+#=============================================================================
+
+# these two environment variables must be defined
+# export SCI=~/your/install/path/share/scilab
+# export LD_LIBRARY_PATH=~/your/install/path/lib/scilab/:~/your/install/path/lib/thirdparty/
+
+CC=gcc
+EXEC=  bug_7601 \
+               bug_7602 \
+               bug_8115 \
+               bug_8830
+
+SRC= $(EXEC:=.c)
+
+CFLAGS=        -W -Wall -Werror=implicit-function-declaration \
+               -I../../../../../../include/scilab/
+
+LDFLAGS=       -L../../../../../../lib/scilab/ \
+                       -L../../../../../../lib/thirdparty/ \
+                       -lscicall_scilab \
+                       -lscilocalization \
+                       -lstdc++ \
+                       -lscilab-cli
+
+
+all: $(EXEC)
+
+
+bug_7601: bug_7601.o
+       $(CC) -o $@ $^ $(LDFLAGS)
+
+bug_7602: bug_7602.o
+       $(CC) -o $@ $^ $(LDFLAGS)
+
+bug_8115: bug_8115.o
+       $(CC) -o $@ $^ $(LDFLAGS) -lsciast
+
+bug_8830: bug_8830.o
+       $(CC) -o $@ $^ $(LDFLAGS)
+
+
+%.o: %.c
+       $(CC) -o $@ -c $< $(CFLAGS)
+
+.PHONY: clean
+
+clean:
+       rm -rf *.o
+       rm -rf $(EXEC)
diff --git a/scilab/modules/call_scilab/tests/nonreg_tests/bug_7601.c b/scilab/modules/call_scilab/tests/nonreg_tests/bug_7601.c
new file mode 100644 (file)
index 0000000..d35720a
--- /dev/null
@@ -0,0 +1,36 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2010 - DIGITEO - Allan CORNET
+// Copyright (C) 2015 - Scilab-Enterprises - Cedric Delamarre
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- CLI SHELL MODE -->
+//
+// <-- INTERACTIVE TEST -->
+//
+// <-- Non-regression test for bug 7601 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=7601
+//
+// <-- Short Description -->
+// call_scilab C functions did not check if engine is started.
+
+// Create a C code to use call_scilab:
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "call_scilab.h"
+
+int main(void)
+{
+#ifdef _MSC_VER
+    StartScilab(NULL, NULL, 0);
+#else
+    StartScilab(getenv("SCI"), NULL, 0);
+#endif
+    SendScilabJob("disp([2,3]+[-44,39]);"); // Will display   - 42.    42.
+    TerminateScilab(NULL);
+    return SendScilabJob("disp([2,3]+[-44,39]);");
+}
index 78ec20f..ef96dde 100644 (file)
@@ -1,6 +1,7 @@
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2010 - DIGITEO - Allan CORNET
+// Copyright (C) 2015 - Scilab-Enterprises - Cedric Delamarre
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 // <-- Short Description -->
 // call_scilab C functions did not check if engine is started.
 
-// Create a C code to use call_scilab:
+// export SCI=/your/scilab/install/share/scilab
+// export LD_LIBRARY_PATH=/your/scilab/install/lib/scilab/:/your/scilab/install/lib/thirdparty/
+// make bug_7601
+// ./bug_7601
 
-int main(void)
-{
-#ifdef _MSC_VER
-        StartScilab(NULL, NULL, NULL);
-#else
-        StartScilab(getenv("SCI"), NULL, NULL);
-#endif
+// display   - 42.    42.
 
-        SendScilabJob("disp([2,3]+[-44,39]);"); // Will display   - 42.    42.  
-        TerminateScilab(NULL);
-        return SendScilabJob("disp([2,3]+[-44,39]);")
-        
-}
-
-default value returned by main will be -1
\ No newline at end of file
+// default value returned by main will be -1
diff --git a/scilab/modules/call_scilab/tests/nonreg_tests/bug_7602.c b/scilab/modules/call_scilab/tests/nonreg_tests/bug_7602.c
new file mode 100644 (file)
index 0000000..1ae8e03
--- /dev/null
@@ -0,0 +1,50 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2010 - DIGITEO - Allan CORNET
+// Copyright (C) 2015 - Scilab-Enterprises - Cedric Delamarre
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- CLI SHELL MODE -->
+//
+// <-- INTERACTIVE TEST -->
+//
+// <-- Non-regression test for bug 7602 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=7602
+//
+// <-- Short Description -->
+// it was not possible to start/close a Scilab engine at anytime.
+
+// Create a C code to use call_scilab:
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "call_scilab.h"
+
+int main(void)
+{
+#define NB_LOOPS 10
+    int i = 0;
+    for (i = 0; i < NB_LOOPS; i++)
+    {
+        DisableInteractiveMode();
+#ifdef _MSC_VER
+        StartScilab(NULL, NULL, 0);
+#else
+        StartScilab(getenv("SCI"), NULL, 0);
+#endif
+        TerminateScilab(NULL);
+
+        DisableInteractiveMode();
+#ifdef _MSC_VER
+        StartScilab(NULL, NULL, 0);
+#else
+        StartScilab(getenv("SCI"), NULL, 0);
+#endif
+        SendScilabJob("disp([2,3]+[-44,39]);"); // Will display   - 42.    42.
+        TerminateScilab(NULL);
+    }
+    return 0;
+}
index 3959e5b..dc578eb 100644 (file)
 // <-- Short Description -->
 // it was not possible to start/close a Scilab engine at anytime.
 
-// Create a C code to use call_scilab:
+// export SCI=/your/scilab/install/share/scilab
+// export LD_LIBRARY_PATH=/your/scilab/install/lib/scilab/:/your/scilab/install/lib/thirdparty/
+// make bug_7602
+// ./bug_7602
 
-int main(void)
-{
-    #define NB_LOOPS 10
-    int i = 0;
-    for (i = 0; i < NB_LOOPS; i++)
-    {
-        DisableInteractiveMode();
-#ifdef _MSC_VER
-        StartScilab(NULL, NULL, NULL);
-#else
-        StartScilab(getenv("SCI"), NULL, NULL);
-#endif
-
-        TerminateScilab(NULL);
-
-        DisableInteractiveMode();
-#ifdef _MSC_VER
-        StartScilab(NULL, NULL, NULL);
-#else
-        StartScilab(getenv("SCI"), NULL, NULL);
-#endif
-        SendScilabJob("disp([2,3]+[-44,39]);"); // Will display   - 42.    42.
-
-        TerminateScilab(NULL);
-    }
-    return 0;
-}
-
-// you must have 10 display of    - 42.    42.
\ No newline at end of file
+// you must have 10 display of    - 42.    42.
diff --git a/scilab/modules/call_scilab/tests/nonreg_tests/bug_8115.c b/scilab/modules/call_scilab/tests/nonreg_tests/bug_8115.c
new file mode 100644 (file)
index 0000000..50b4882
--- /dev/null
@@ -0,0 +1,88 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2010 - DIGITEO - Allan CORNET
+// Copyright (C) 2015 - Scilab-Enterprises - Cedric Delamarre
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- CLI SHELL MODE -->
+//
+// <-- INTERACTIVE TEST -->
+//
+// <-- Non-regression test for bug 8115 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=8115
+//
+// <-- Short Description -->
+// DisableInteractiveMode did not work
+
+// Create a C code to use call_scilab:
+
+#ifdef _MSC_VER
+#pragma comment(lib, "call_scilab.lib")
+#pragma comment(lib, "libscilab.lib")
+#endif
+/*--------------------------------------------------------------------------*/
+#include <stdio.h>
+#include <stdlib.h>
+#include "call_scilab.h"
+#include "configvariable_interface.h"
+/*--------------------------------------------------------------------------*/
+int main(void)
+{
+    int iErr = 0;
+    if (getScilabMode() != SCILAB_API)
+    {
+        fprintf(stderr, "BUG 8115 NOT FIXED. (1)\n");
+        iErr = 1;
+    }
+
+    DisableInteractiveMode();
+#ifdef _MSC_VER
+    StartScilab(NULL, NULL, 0);
+#else
+    StartScilab(getenv("SCI"), NULL, 0);
+#endif
+
+    /* check that it is NWNI mode */
+    if (getScilabMode() != SCILAB_NWNI)
+    {
+        fprintf(stderr, "BUG 8115 NOT FIXED. (2)\n");
+        iErr = 1;
+    }
+
+    TerminateScilab(NULL);
+
+    /* check that we returns to default mode */
+    if (getScilabMode() != SCILAB_API)
+    {
+        fprintf(stderr, "BUG 8115 NOT FIXED. (3)\n");
+        iErr = 1;
+    }
+
+#ifdef _MSC_VER
+    StartScilab(NULL, NULL, 0);
+#else
+    StartScilab(getenv("SCI"), NULL, 0);
+#endif
+
+    /* check that it is API mode */
+    if (getScilabMode() != SCILAB_API)
+    {
+        fprintf(stderr, "BUG 8115 NOT FIXED. (4)\n");
+        iErr = 1;
+    }
+
+    TerminateScilab(NULL);
+
+    /* check that we returns to default mode */
+    if (getScilabMode() != SCILAB_API)
+    {
+        fprintf(stderr, "BUG 8115 NOT FIXED. (5)\n");
+        iErr = 1;
+    }
+
+    return iErr;
+}
+/*--------------------------------------------------------------------------*/
index b7519d5..3a3652c 100644 (file)
 //
 // <-- Short Description -->
 // DisableInteractiveMode did not work
+// export SCI=/your/scilab/install/share/scilab
+// export LD_LIBRARY_PATH=/your/scilab/install/lib/scilab/:/your/scilab/install/lib/thirdparty/
+// make bug_8115
+// ./bug_8115
 
-// Create a C code to use call_scilab:
-
-#ifdef _MSC_VER
-#pragma comment(lib, "call_scilab.lib")
-#pragma comment(lib, "libscilab.lib")
-#endif
-/*--------------------------------------------------------------------------*/
-#include <stdio.h>
-#include <stdlib.h>
-#include "call_scilab.h"
-#include "sci_mode.h"
-/*--------------------------------------------------------------------------*/
-int main(void)
-{
-    int iErr = 0;
-    if (getScilabMode() != SCILAB_API)
-    {
-        fprintf(stderr, "BUG 8115 NOT FIXED.\n");
-        iErr = 1;
-    }
-
-    DisableInteractiveMode();
-#ifdef _MSC_VER
-    StartScilab(NULL, NULL, 0);
-#else
-    StartScilab(getenv("SCI"), NULL, 0);
-#endif
-
-    /* check that it is NWNI mode */
-    if (getScilabMode() != SCILAB_NWNI)
-    {
-        fprintf(stderr, "BUG 8115 NOT FIXED.\n");
-        iErr = 1;
-    }
-
-    TerminateScilab(NULL);
-
-    /* check that we returns to default mode */
-    if (getScilabMode() != SCILAB_API)
-    {
-        fprintf(stderr, "BUG 8115 NOT FIXED.\n");
-        iErr = 1;
-    }
-
-#ifdef _MSC_VER
-    StartScilab(NULL, NULL, 0);
-#else
-    StartScilab(getenv("SCI"), NULL, 0);
-#endif
-
-    /* check that it is API mode */
-    if (getScilabMode() != SCILAB_API)
-    {
-        fprintf(stderr, "BUG 8115 NOT FIXED.\n");
-        iErr = 1;
-    }
-
-    TerminateScilab(NULL);
-
-    /* check that we returns to default mode */
-    if (getScilabMode() != SCILAB_API)
-    {
-        fprintf(stderr, "BUG 8115 NOT FIXED.\n");
-        iErr = 1;
-    }
-
-    return iErr;
-}
-/*--------------------------------------------------------------------------*/
+// nothing must be displayed
diff --git a/scilab/modules/call_scilab/tests/nonreg_tests/bug_8830.c b/scilab/modules/call_scilab/tests/nonreg_tests/bug_8830.c
new file mode 100644 (file)
index 0000000..d04e040
--- /dev/null
@@ -0,0 +1,50 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU
+// Copyright (C) 2015 - Scilab-Enterprises - Cedric Delamarre
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- CLI SHELL MODE -->
+//
+// <-- INTERACTIVE TEST -->
+//
+// <-- Non-regression test for bug 8830 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=8830
+//
+// <-- Short Description -->
+// In call_scilab, TerminateScilab  did not clear the last error.
+
+// Create a C code to use call_scilab:
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "call_scilab.h" /* Provide functions to call Scilab engine */
+
+/*------------------------------------------------------------*/
+int main(void)
+{
+#ifdef _MSC_VER
+    if (StartScilab(NULL, NULL, 0) == FALSE)
+#else
+    if (StartScilab(getenv("SCI"), NULL, 0) == FALSE)
+#endif
+    {
+        fprintf(stderr, "Error while calling StartScilab\n");
+        return -1;
+    }
+
+    SendScilabJob("failedMyCurrentJob=%pi*3/0");
+
+    if (TerminateScilab(NULL) == FALSE)
+    {
+        fprintf(stderr, "Error while calling TerminateScilab\n");
+        return -2;
+    }
+
+    printf("getLastErrorValue %d\n", getLastErrorValue());
+    return 0;
+}
+/*------------------------------------------------------------*/
index dc7e297..d27cc4c 100644 (file)
 // <-- Short Description -->
 // In call_scilab, TerminateScilab  did not clear the last error.
 
-// Create a C code to use call_scilab:
+// export SCI=/your/scilab/install/share/scilab
+// export LD_LIBRARY_PATH=/your/scilab/install/lib/scilab/:/your/scilab/install/lib/thirdparty/
+// make bug_8830
+// ./bug_8830
 
-#include <stdio.h> 
-#include <string.h>
-#include "stack-c.h" /* Provide functions to access to the memory of Scilab */
-#include "call_scilab.h" /* Provide functions to call Scilab engine */
-
-/*------------------------------------------------------------*/
-int main(void)
-{
-#ifdef _MSC_VER
-       if ( StartScilab(NULL,NULL,NULL) == FALSE )
-#else
-       if ( StartScilab(getenv("SCI"),NULL,NULL) == FALSE )
-#endif
-               {
-                       fprintf(stderr,"Error while calling StartScilab\n");
-                       return -1;
-               }
-
-       
-       int code=SendScilabJob("failedMyCurrentJob=%pi*3/0");
-       
-       if ( TerminateScilab(NULL) == FALSE ) {
-               fprintf(stderr,"Error while calling TerminateScilab\n");
-               return -2;
-       }
-    printf("getLastErrorValue %d\n",getLastErrorValue());
-       return 0;
-}
-/*------------------------------------------------------------*/
+// "getLastErrorValue 0" must be displayed
index cc668ac..4ee3e08 100644 (file)
@@ -40,6 +40,7 @@ typedef struct
     int isInterruptible;
     int isPrioritary;
     int isConsoleCommand;
+    int iStartConsoleThread;
 } ScilabEngineInfo;
 
 ScilabEngineInfo* InitScilabEngineInfo();
index cf0a91d..647b556 100644 (file)
@@ -25,9 +25,6 @@ using namespace types;
 
 types::Function::ReturnValue sci_argn(types::typed_list &in, int _iRetCount, types::typed_list &out)
 {
-    static symbol::Variable* varIn = NULL;
-    static symbol::Variable* varOut = NULL;
-
     int iRhs = static_cast<int>(in.size());
     //check input arguments
     if (iRhs > 1)
@@ -71,29 +68,15 @@ types::Function::ReturnValue sci_argn(types::typed_list &in, int _iRetCount, typ
 
     symbol::Context* pContext = symbol::Context::getInstance();
 
-    InternalType *pIn = NULL;
-    InternalType *pOut = NULL;
-
-    if (varIn == NULL)
-    {
-        varIn = symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"nargin"));
-    }
-
-    if (varOut == NULL)
-    {
-        varOut = symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"nargout"));
-    }
-
-    pIn = pContext->get(varIn);
-    pOut = pContext->get(varOut);
+    InternalType* pIn = pContext->get(symbol::Symbol(L"nargin"));
+    InternalType* pOut = pContext->get(symbol::Symbol(L"nargout"));
 
     if (pIn == NULL || pOut == NULL)
     {
-        Double* pD = new Double(0);
-        out.push_back(pD);
+        out.push_back(types::Double::Empty());
         if (_iRetCount == 2)
         {
-            out.push_back(pD);
+            out.push_back(types::Double::Empty());
         }
     }
     else
index f605117..e29c367 100644 (file)
@@ -35,6 +35,13 @@ types::Function::ReturnValue sci_sciargs(types::typed_list &in, int _iRetCount,
 
     wchar_t** pwstCmdLineArgs = ConfigVariable::getCommandLineArgs(&iCount);
 
+    if (iCount == 0)
+    {
+        // call_scilab
+        out.push_back(new types::String(L""));
+        return types::Function::OK;
+    }
+
     types::String* pS = new types::String(iCount, 1);
     pS->set(pwstCmdLineArgs);
     out.push_back(pS);
index 7582d33..b2de71c 100644 (file)
@@ -31,6 +31,8 @@
 #include "operations.hxx"
 #include "threadmanagement.hxx"
 
+#include "expandPathVariable.h"
+
 extern "C"
 {
 #include "machine.h"
@@ -121,8 +123,9 @@ ScilabEngineInfo* InitScilabEngineInfo()
     pSEI->iNoBanner = 1;
 
     pSEI->iMultiLine = 0;
-    pSEI->isInterruptible = 1;  // by default all thread are interruptible
-    pSEI->isPrioritary = 0;     // by default all thread are non-prioritary
+    pSEI->isInterruptible = 1;      // by default all thread are interruptible
+    pSEI->isPrioritary = 0;         // by default all thread are non-prioritary
+    pSEI->iStartConsoleThread = 1;  // used in call_scilab to avoid "prompt" thread execution
 
     return pSEI;
 }
@@ -131,6 +134,7 @@ int StartScilabEngine(ScilabEngineInfo* _pSEI)
 {
     int iMainRet = 0;
     ConfigVariable::setStartProcessing(true);
+    ConfigVariable::setForceQuit(false);
 
     /* This bug only occurs under Linux 32 bits
      * See: http://wiki.scilab.org/Scilab_precision
@@ -159,7 +163,7 @@ int StartScilabEngine(ScilabEngineInfo* _pSEI)
 #ifdef _MSC_VER
     //get current console window and hide it
     int scilabMode = getScilabMode();
-    if (scilabMode == SCILAB_STD || scilabMode == SCILAB_NW)
+    if (scilabMode == SCILAB_STD || scilabMode == SCILAB_NW || scilabMode == SCILAB_API)
     {
         CreateScilabHiddenWndThread();
     }
@@ -404,6 +408,11 @@ void StopScilabEngine(ScilabEngineInfo* _pSEI)
         TerminateGraphics();
         TerminateJVM();
     }
+
+    // reset struct to prevent the use of deleted objects
+    // when we start scilab again without kill process (ie: call_scilab)
+    resetVariableValueDefinedInScilab();
+
     /* TerminateCorePart2 */
 
     //clear opened files
@@ -445,6 +454,8 @@ void StopScilabEngine(ScilabEngineInfo* _pSEI)
      */
     terminateMutexClosingScilab();
 #endif
+
+    ConfigVariable::clearLastError();
     ConfigVariable::setEndProcessing(false);
 }
 
@@ -679,7 +690,7 @@ static int interactiveMain(ScilabEngineInfo* _pSEI)
 
     InitializeHistoryManager();
 
-    if (getScilabMode() != SCILAB_NWNI)
+    if (getScilabMode() != SCILAB_NWNI && getScilabMode() != SCILAB_API)
     {
 
         char *cwd = NULL;
@@ -700,14 +711,17 @@ static int interactiveMain(ScilabEngineInfo* _pSEI)
     __threadId threadIdCommand;
     __threadKey threadKeyCommand;
 
-    ThreadManagement::LockStart();
-    // thread to manage console command
-    __CreateThreadWithParams(&threadIdConsole, &threadKeyConsole, &scilabReadAndStore, _pSEI);
+    if (_pSEI->iStartConsoleThread)
+    {
+        ThreadManagement::LockStart();
+        // thread to manage console command
+        __CreateThreadWithParams(&threadIdConsole, &threadKeyConsole, &scilabReadAndStore, _pSEI);
 
-    // scilabReadAndStore thread must be execute before scilabReadAndExecCommand
-    // to be such that the -f command stored is not removed
-    // from queue before scilabReadAndStore is waiting for.
-    ThreadManagement::WaitForStartPendingSignal();
+        // scilabReadAndStore thread must be execute before scilabReadAndExecCommand
+        // to be such that the -f command stored is not removed
+        // from queue before scilabReadAndStore is waiting for.
+        ThreadManagement::WaitForStartPendingSignal();
+    }
 
     // thread to manage command stored
     __CreateThreadWithParams(&threadIdCommand, &threadKeyCommand, &scilabReadAndExecCommand, _pSEI);
@@ -862,7 +876,7 @@ static void checkForLinkerErrors(void)
 #define LINKER_ERROR_1 "Scilab startup function detected that the function proposed to the engine is the wrong one. Usually, it comes from a linker problem in your distribution/OS.\n"
 #define LINKER_ERROR_2 "If you do not know what it means, please report a bug on http://bugzilla.scilab.org/. If you do, you probably know that you should change the link order in SCI/modules/Makefile.am\n"
 
-    if (getScilabMode() != SCILAB_NWNI)
+    if (getScilabMode() != SCILAB_NWNI && getScilabMode() != SCILAB_API)
     {
         if (isItTheDisabledLib())
         {
@@ -870,7 +884,6 @@ static void checkForLinkerErrors(void)
             fprintf(stderr, "Here, Scilab should have 'libscijvm' defined but gets 'libscijvm-disable' instead.\n");
             fprintf(stderr, LINKER_ERROR_2);
             exit(1);
-
         }
     }
     else
index c338e36..48c2964 100644 (file)
@@ -52,7 +52,7 @@ void *Runner::launch(void *args)
         ConfigVariable::resetWhereError();
     }
 
-    if (getScilabMode() != SCILAB_NWNI)
+    if (getScilabMode() != SCILAB_NWNI && getScilabMode() != SCILAB_API)
     {
         char *cwd = NULL;
         int err = 0;
index c7a5f55..f37f8b5 100644 (file)
 extern "C"
 {
 #endif
-    /**
-    * expand in_name to produce out_name
-    * @param[in] string where to find a variable and expand
-    * @return string with expanded variable
-    */
-    FILEIO_IMPEXP char *expandPathVariable(char* str);
+/**
+* expand in_name to produce out_name
+* @param[in] string where to find a variable and expand
+* @return string with expanded variable
+*/
+FILEIO_IMPEXP char *expandPathVariable(char* str);
 
-    /**
-    * expand in_name to produce out_name (wide string)
-    * @param[in] wide string where to find a variable and expand
-    * @return wide string with expanded variable
-    */
-    FILEIO_IMPEXP wchar_t *expandPathVariableW(wchar_t *wcstr);
+/**
+* expand in_name to produce out_name (wide string)
+* @param[in] wide string where to find a variable and expand
+* @return wide string with expanded variable
+*/
+FILEIO_IMPEXP wchar_t *expandPathVariableW(wchar_t *wcstr);
+
+/**
+* set NULL to all scilab "Variable" (ie: SCI, SCIHOME, ....)
+*/
+FILEIO_IMPEXP void resetVariableValueDefinedInScilab(void);
 
 #ifdef __cplusplus
 }
index 11fa000..448c8bc 100644 (file)
@@ -166,6 +166,14 @@ wchar_t *getVariableValueDefinedInScilab(VARIABLEALIAS* _var)
     return NULL;
 }
 /*--------------------------------------------------------------------------*/
+void resetVariableValueDefinedInScilab(void)
+{
+    for (int i = 0; i < NB_ALIAS; i++)
+    {
+        VARIABLES_words[i].var = NULL;
+    }
+}
+/*--------------------------------------------------------------------------*/
 wchar_t *convertFileSeparators(wchar_t *wcStr)
 {
     if (wcStr)