fix non handled exception if error occurs in scilab.start 09/17409/2
Antoine ELIAS [Thu, 29 Oct 2015 09:23:52 +0000 (10:23 +0100)]
Change-Id: Id491d15fecc4dcf65b1d679f142891e6fb8eeec5

scilab/modules/core/includes/runner.hxx
scilab/modules/core/includes/tasks.hxx
scilab/modules/core/src/cpp/InitScilab.cpp
scilab/modules/core/src/cpp/runner.cpp
scilab/modules/core/src/cpp/tasks.cpp
scilab/modules/functions/sci_gateway/cpp/sci_exec.cpp
scilab/modules/startup/src/cpp/scilab.cpp

index dd70f5a..a2ee706 100644 (file)
@@ -80,7 +80,7 @@ public:
     static command_origin_t getCommandOrigin();
     static void execAndWait(ast::Exp* _theProgram, ast::RunVisitor *_visitor,
                             bool _isInterruptible, bool _isPrioritary, command_origin_t _iCommandOrigin);
-    static void exec(ast::Exp* _theProgram, ast::RunVisitor *_visitor);
+    static bool exec(ast::Exp* _theProgram, ast::RunVisitor *_visitor);
 
 private:
     static std::atomic<Runner*> m_RunMe;
index 6be99e2..4abfc13 100644 (file)
@@ -74,13 +74,13 @@ void dumpStackTask(bool timed);
 ** Execute scilab.start
 **
 */
-void execScilabStartTask(bool _bSerialize);
-void execScilabQuitTask(bool _bSerialize);
+int execScilabStartTask(bool _bSerialize);
+int execScilabQuitTask(bool _bSerialize);
 
 #ifdef __cplusplus
 extern "C"
 {
-    ast::Exp* parseCommand(std::wstring _command);
+ast::Exp* parseCommand(std::wstring _command);
 }
 #endif
 
index dd9052c..75d81e2 100644 (file)
@@ -283,7 +283,11 @@ int StartScilabEngine(ScilabEngineInfo* _pSEI)
     //execute scilab.start
     if (_pSEI->iNoStart == 0)
     {
-        execScilabStartTask(_pSEI->iSerialize != 0);
+        int ierr = execScilabStartTask(_pSEI->iSerialize != 0);
+        if (ierr)
+        {
+            return ierr;
+        }
     }
 
     //open console scope
@@ -907,54 +911,54 @@ static void stateShow(Parser::ControlStatus status)
 {
     switch (status)
     {
-            //case Parser::WithinFor:
-            //    SetTemporaryPrompt("-for       ->");
-            //    break;
-            //case Parser::WithinWhile:
-            //    SetTemporaryPrompt("-while     ->");
-            //    break;
-            //case Parser::WithinIf:
-            //    SetTemporaryPrompt("-if        ->");
-            //    break;
-            //case Parser::WithinElse:
-            //    SetTemporaryPrompt("-else      ->");
-            //    break;
-            //case Parser::WithinElseIf:
-            //    SetTemporaryPrompt("-elseif    ->");
-            //    break;
-            //case Parser::WithinTry:
-            //    SetTemporaryPrompt("-try       ->");
-            //    break;
-            //case Parser::WithinCatch:
-            //    SetTemporaryPrompt("-catch     ->");
-            //    break;
-            //case Parser::WithinFunction:
-            //    SetTemporaryPrompt("-function  ->");
-            //    break;
-            //case Parser::WithinSelect:
-            //    SetTemporaryPrompt("-select    ->");
-            //    break;
-            //case Parser::WithinCase:
-            //    SetTemporaryPrompt("-case      ->");
-            //    break;
-            //case Parser::WithinSwitch:
-            //    SetTemporaryPrompt("-switch    ->");
-            //    break;
-            //case Parser::WithinOtherwise:
-            //    SetTemporaryPrompt("-otherwise ->");
-            //    break;
-            //case Parser::WithinMatrix:
-            //    SetTemporaryPrompt("- [        ->");
-            //    break;
-            //case Parser::WithinCell:
-            //    SetTemporaryPrompt("- {        ->");
-            //    break;
-            //case Parser::WithinBlockComment:
-            //    SetTemporaryPrompt("- /*       ->");
-            //    break;
-            //case Parser::WithinDots:
-            //    SetTemporaryPrompt("- ...      ->");
-            //    break;
+        //case Parser::WithinFor:
+        //    SetTemporaryPrompt("-for       ->");
+        //    break;
+        //case Parser::WithinWhile:
+        //    SetTemporaryPrompt("-while     ->");
+        //    break;
+        //case Parser::WithinIf:
+        //    SetTemporaryPrompt("-if        ->");
+        //    break;
+        //case Parser::WithinElse:
+        //    SetTemporaryPrompt("-else      ->");
+        //    break;
+        //case Parser::WithinElseIf:
+        //    SetTemporaryPrompt("-elseif    ->");
+        //    break;
+        //case Parser::WithinTry:
+        //    SetTemporaryPrompt("-try       ->");
+        //    break;
+        //case Parser::WithinCatch:
+        //    SetTemporaryPrompt("-catch     ->");
+        //    break;
+        //case Parser::WithinFunction:
+        //    SetTemporaryPrompt("-function  ->");
+        //    break;
+        //case Parser::WithinSelect:
+        //    SetTemporaryPrompt("-select    ->");
+        //    break;
+        //case Parser::WithinCase:
+        //    SetTemporaryPrompt("-case      ->");
+        //    break;
+        //case Parser::WithinSwitch:
+        //    SetTemporaryPrompt("-switch    ->");
+        //    break;
+        //case Parser::WithinOtherwise:
+        //    SetTemporaryPrompt("-otherwise ->");
+        //    break;
+        //case Parser::WithinMatrix:
+        //    SetTemporaryPrompt("- [        ->");
+        //    break;
+        //case Parser::WithinCell:
+        //    SetTemporaryPrompt("- {        ->");
+        //    break;
+        //case Parser::WithinBlockComment:
+        //    SetTemporaryPrompt("- /*       ->");
+        //    break;
+        //case Parser::WithinDots:
+        //    SetTemporaryPrompt("- ...      ->");
+        //    break;
         default :
             SetTemporaryPrompt("  > ");
             break;
index 540f2bf..c37fe4b 100644 (file)
@@ -227,11 +227,22 @@ void StaticRunner::execAndWait(ast::Exp* _theProgram, ast::RunVisitor *_visitor,
     ThreadManagement::WaitForAwakeRunnerSignal();
 }
 
-void StaticRunner::exec(ast::Exp* _theProgram, ast::RunVisitor *_visitor)
+bool StaticRunner::exec(ast::Exp* _theProgram, ast::RunVisitor *_visitor)
 {
     Runner *runMe = new Runner(_theProgram, _visitor);
     setRunner(runMe);
-    launch();
+
+    try
+    {
+        launch();
+    }
+    catch (const ast::InternalAbort& /*ia*/)
+    {
+        //catch exit command in .start or .quit
+        return false;
+    }
+
+    return true;
 }
 
 void StaticRunner_launch(void)
index 91c8a67..f4835bf 100644 (file)
@@ -224,7 +224,7 @@ void dumpStackTask(bool timed)
 ** Execute scilab.start
 **
 */
-void execScilabStartTask(bool _bSerialize)
+int execScilabStartTask(bool _bSerialize)
 {
     Parser parse;
     std::wstring stSCI = ConfigVariable::getSCIPath();
@@ -237,7 +237,7 @@ void execScilabStartTask(bool _bSerialize)
         scilabWriteW(parse.getErrorMessage());
         scilabWriteW(L"Failed to parse scilab.start");
         ThreadManagement::UnlockParser();
-        return;
+        return 0;
     }
     ThreadManagement::UnlockParser();
 
@@ -246,14 +246,15 @@ void execScilabStartTask(bool _bSerialize)
     {
         newTree = callTyper(parse.getTree());
     }
-    StaticRunner::exec(newTree, new ast::ExecVisitor());
+
+    return StaticRunner::exec(newTree, new ast::ExecVisitor()) ? 0 : 1;
 }
 
 /*
 ** Execute scilab.quit
 **
 */
-void execScilabQuitTask(bool _bSerialize)
+int execScilabQuitTask(bool _bSerialize)
 {
     Parser parse;
     std::wstring stSCI = ConfigVariable::getSCIPath();
@@ -266,7 +267,7 @@ void execScilabQuitTask(bool _bSerialize)
         scilabWriteW(parse.getErrorMessage());
         scilabWriteW(L"Failed to parse scilab.quit");
         ThreadManagement::UnlockParser();
-        return;
+        return 0;
     }
     ThreadManagement::UnlockParser();
 
@@ -275,7 +276,8 @@ void execScilabQuitTask(bool _bSerialize)
     {
         newTree = callTyper(parse.getTree());
     }
-    StaticRunner::exec(newTree, new ast::ExecVisitor());
+
+    return StaticRunner::exec(newTree, new ast::ExecVisitor()) ? 0 : 1;
 }
 
 
index 684739e..6ac50ff 100644 (file)
@@ -454,6 +454,13 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
                     ConfigVariable::setLastErrorLine(ie.GetErrorLocation().first_line);
                 }
 
+                // avoid double delete on exps when "seqExp" is destryed and "LExp" too
+                ast::exps_t& protectExp = seqExp.getExps();
+                for (int i = 0; i < protectExp.size(); ++i)
+                {
+                    protectExp[i] = NULL;
+                }
+
                 //store message
                 iErr = ConfigVariable::getLastErrorNumber();
                 if (bErrCatch == false)
@@ -462,14 +469,6 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
 
                     //restore previous prompt mode
                     ConfigVariable::setPromptMode(oldVal);
-
-                    // avoid double delete on exps when "seqExp" is destryed and "LExp" too
-                    ast::exps_t& protectExp = seqExp.getExps();
-                    for (int i = 0; i < protectExp.size(); ++i)
-                    {
-                        protectExp[i] = NULL;
-                    }
-
                     throw ie;
                 }
 
index d1b4f7d..975fd4c 100644 (file)
@@ -321,8 +321,12 @@ int main(int argc, char *argv[])
     int val = setjmp(ScilabJmpEnv);
     if (!val)
     {
-        StartScilabEngine(pSEI);
-        iRet = RunScilabEngine(pSEI);
+        iRet = StartScilabEngine(pSEI);
+        if (iRet == 0)
+        {
+            iRet = RunScilabEngine(pSEI);
+        }
+
         StopScilabEngine(pSEI);
         FREE(pSEI);
         return iRet;