Console: fix print issue in term after segfault and print the stack in this case 09/16909/3
Calixte DENIZET [Tue, 28 Jul 2015 09:56:43 +0000 (11:56 +0200)]
Change-Id: Ia1db001bab6125fdfe2a720b2b8f85edb34d169d

scilab/modules/console/src/c/windows/TermCommand.c
scilab/modules/core/src/c/signal_mgmt.c
scilab/modules/startup/src/cpp/scilab.cpp
scilab/modules/windows_tools/src/c/CScilex/CScilex.vcxproj
scilab/modules/windows_tools/src/c/WScilex/WScilex.vcxproj
scilab/modules/windows_tools/src/c/scilab_windows/scilab_main.c [deleted file]
scilab/modules/windows_tools/src/c/scilab_windows/scilab_main.h [deleted file]
scilab/modules/windows_tools/src/c/scilab_windows/scilab_windows.vcxproj
scilab/modules/windows_tools/src/c/scilab_windows/scilab_windows.vcxproj.filters

index a14c170..df6064f 100644 (file)
@@ -32,7 +32,7 @@ void ControlX_Command(void)
 /*--------------------------------------------------------------------------*/
 void F1_Command(void)
 {
-    StoreCommand(L"help");
+    StoreCommand("help");
 }
 /*--------------------------------------------------------------------------*/
 void F2_Command(void)
@@ -43,6 +43,6 @@ void F2_Command(void)
 /*--------------------------------------------------------------------------*/
 void ALTF4_Command(void)
 {
-    StoreCommand(L"quit");
+    StoreCommand("quit");
 }
 /*--------------------------------------------------------------------------*/
index 1d6ebde..7ddfdfe 100644 (file)
 #include "suspendProcess.h"
 #include "configvariable_interface.h"
 #include "backtrace_print.h"
-jmp_buf jmp_env;
+#include "cliDisplayManagement.h"
+#include "initConsoleMode.h"
+#include "exit_status.hxx"
+
+jmp_buf ScilabJmpEnv;
 
 /*----------------------------------------------------------------------------
  * Handle a fatal signal (such as SIGFPE or SIGSEGV)
@@ -406,7 +410,15 @@ static void sig_fatal(int signum, siginfo_t * info, void *p)
              PACKAGE_BUGREPORT, print_buffer, bt);
 
     free(bt);
-    longjmp(&jmp_env, 1);
+
+    if (getScilabMode() == SCILAB_NWNI || getScilabMode() == SCILAB_NW)
+    {
+        /* Reset termcaps and Characters display. */
+        setAttr(ATTR_RESET);
+        setCharDisplay(DISP_RESET);
+    }
+
+    longjmp(ScilabJmpEnv, HUGE_ERROR);
 }
 
 void base_error_init(void)
index 9205484..043d9db 100644 (file)
@@ -17,6 +17,7 @@
 #include <cstdio>
 #include <iostream>
 #include <string.h>
+#include <setjmp.h>
 
 extern "C"
 {
@@ -29,8 +30,14 @@ extern "C"
 #include "ConsoleRead.h"
 #include "version.h"
 #include "sci_malloc.h"
+#include "lasterror.h"
 
     extern char *getCmdLine(void);
+#ifdef _MSC_VER
+    jmp_buf ScilabJmpEnv;
+#else
+    extern jmp_buf ScilabJmpEnv;
+#endif
 }
 
 #include "configvariable.hxx"
@@ -302,9 +309,20 @@ int main(int argc, char *argv[])
         exit(0);
     }
 
-    StartScilabEngine(pSEI);
-    iRet = RunScilabEngine(pSEI);
-    StopScilabEngine(pSEI);
-    FREE(pSEI);
-    return iRet;
+    int val = setjmp(ScilabJmpEnv);
+    if (!val)
+    {
+        StartScilabEngine(pSEI);
+        iRet = RunScilabEngine(pSEI);
+        StopScilabEngine(pSEI);
+        FREE(pSEI);
+        return iRet;
+    }
+    else
+    {
+        // We probably had a segfault so print error
+        std::wcerr << getLastErrorMessage() << std::endl;
+        return val;
+    }
 }
+
index cd8595a..14b185a 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="Debug|Win32">
index 2f4d53d..62aa7af 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="Debug|Win32">
diff --git a/scilab/modules/windows_tools/src/c/scilab_windows/scilab_main.c b/scilab/modules/windows_tools/src/c/scilab_windows/scilab_main.c
deleted file mode 100644 (file)
index b868734..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
-* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) INRIA - Allan CORNET
-*
-* This file must be used under the terms of the CeCILL.
-* This source file is licensed as described in the file COPYING, which
-* you should have received as part of this distribution.  The terms
-* are also available at
-* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
-*
-*/
-
-/*--------------------------------------------------------------------------*/
-#include <Windows.h>
-#include <stdio.h>
-#include <setjmp.h>
-#include <signal.h>
-
-#include "scilab_main.h"
-#include "configvariable_interface.h"
-#include "realmain.h"
-#include "sciprint.h"
-/*--------------------------------------------------------------------------*/
-static void interrupt_setup (void);
-static void interrupt (int an_int);
-/*--------------------------------------------------------------------------*/
-jmp_buf env;
-/*--------------------------------------------------------------------------*/
-int sci_windows_main ( int *nos, char *path, InitScriptType pathtype, int *lpath, int memory)
-{
-    setbuf (stderr, (char *) NULL);
-    if (!setjmp (env))
-    {
-        /* first time */
-        interrupt_setup ();
-    }
-    /* take commands from stdin */
-    return 0;//realmain(*nos,path,pathtype,memory);
-}
-/*--------------------------------------------------------------------------*/
-/* Set up to catch interrupts */
-static void interrupt_setup (void)
-{
-    (void) signal (SIGINT, interrupt);
-}
-/*--------------------------------------------------------------------------*/
-void interrupt (int an_int)
-{
-    (void) signal (SIGINT, interrupt);
-    (void) signal (SIGFPE, SIG_DFL);   /* turn off FPE trapping */
-    (void) fflush (stdout);
-    sciprint ("\n");
-    longjmp (env, TRUE);               /* return to prompt  */
-}
-/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/windows_tools/src/c/scilab_windows/scilab_main.h b/scilab/modules/windows_tools/src/c/scilab_windows/scilab_main.h
deleted file mode 100644 (file)
index 43e23e7..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
-* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) INRIA - Allan CORNET
-*
-* This file must be used under the terms of the CeCILL.
-* This source file is licensed as described in the file COPYING, which
-* you should have received as part of this distribution.  The terms
-* are also available at
-* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
-*
-*/
-
-/*--------------------------------------------------------------------------*/
-#ifndef __SCILAB_MAIN__H__
-#define __SCILAB_MAIN__H__
-
-#include "dynlib_scilab_windows.h"
-#include "realmain.h" /* InitScriptType */
-
-/**
-* common main for windows
-* @param[in] no startup
-* @param[in] path script
-* @param[in] path type
-* @param[in] size path
-* @param[in] stacksize
-*/
-SCILAB_WINDOWS_IMPEXP int sci_windows_main ( int *nos, char *path, InitScriptType pathtype, int *lpath, int memory);
-
-#endif /* __SCILAB_MAIN__H__ */
-/*--------------------------------------------------------------------------*/
index b2abc1f..8efb847 100644 (file)
@@ -253,7 +253,6 @@ lib /DEF:"$(ProjectDir)Gui_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /
     <ClCompile Include="killScilabProcess.c" />
     <ClCompile Include="mmapWindows.c" />
     <ClCompile Include="MutexClosingScilab.c" />
-    <ClCompile Include="scilab_main.c" />
     <ClCompile Include="spawncommand.c" />
     <ClCompile Include="splashScreen.cpp" />
     <ClCompile Include="TextToPrint.c" />
@@ -279,7 +278,6 @@ lib /DEF:"$(ProjectDir)Gui_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /
     <ClInclude Include="mmapWindows.h" />
     <ClInclude Include="..\..\..\includes\MutexClosingScilab.h" />
     <ClInclude Include="resource.h" />
-    <ClInclude Include="scilab_main.h" />
     <ClInclude Include="SetHeapOptions.h" />
     <ClInclude Include="spawncommand.h" />
     <ClInclude Include="splashScreen.h" />
index f85e5e3..c8faf4a 100644 (file)
@@ -56,9 +56,6 @@
     <ClCompile Include="MutexClosingScilab.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="scilab_main.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="spawncommand.c">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClInclude Include="..\..\..\includes\MutexClosingScilab.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="scilab_main.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="SetHeapOptions.h">
       <Filter>Header Files</Filter>
     </ClInclude>