fix tcl freeze when an error occured at initialization 82/21282/3
Cedric Delamarre [Wed, 5 Feb 2020 14:05:56 +0000 (15:05 +0100)]
    to reproduce the problem: comment lines about
    TCL_LIBRARY and TK_LIBRARY in bin/scilab then
    launch scilab using ./bin/scilab-adv-cli

Change-Id: I3bcb96496217d6f12a549ece90f6a3a36f5de586

scilab/modules/core/src/cpp/InitScilab.cpp
scilab/modules/tclsci/src/c/InitTclTk.c
scilab/modules/tclsci/src/c/InitializeTclTk.c

index 467aaa1..b711739 100644 (file)
@@ -270,9 +270,10 @@ int StartScilabEngine(ScilabEngineInfo* _pSEI)
     InitializeWindows_tools();
 #endif
 
+    BOOL bRet = TRUE;
     if (_pSEI->iNoJvm == 0) // With JVM
     {
-        InitializeTclTk();
+        bRet = InitializeTclTk();
         InitializeJVM();
         InitializeGUI();
 
@@ -285,6 +286,12 @@ int StartScilabEngine(ScilabEngineInfo* _pSEI)
         Add_Boolean_Constant(L"%gui", true);
     }
 
+    if(bRet == FALSE)
+    {
+        std::wcerr << ConfigVariable::getLastErrorMessage() << std::endl;
+        return 1;
+    }
+
     // Make sure the default locale is applied at startup
     setlocale(LC_NUMERIC, "C");
 
index add308a..98381b3 100644 (file)
@@ -41,6 +41,13 @@ BOOL TK_Started = FALSE;
 
 /*--------------------------------------------------------------------------*/
 static char *GetSciPath(void);
+static char *releaseTclInterpOnError(void)
+{
+    __LockSignal(&InterpReadyLock);
+    __Signal(&InterpReady);
+    __UnLockSignal(&InterpReadyLock);
+    setTkStarted(FALSE);
+}
 /*--------------------------------------------------------------------------*/
 static void *DaemonOpenTCLsci(void* in)
 /* Checks if tcl/tk has already been initialised and if not */
@@ -68,6 +75,7 @@ static void *DaemonOpenTCLsci(void* in)
     if (SciPath == NULL)
     {
         sciprint(_("The SCI environment variable is not set.\nTCL initialisation failed !\n"));
+        releaseTclInterpOnError();
         return (0);
     }
 
@@ -115,6 +123,7 @@ static void *DaemonOpenTCLsci(void* in)
         SciPathShort = NULL;
         FREE(TkScriptpathShort);
         TkScriptpathShort = NULL;
+        releaseTclInterpOnError();
         return (0);
     }
     else
@@ -132,6 +141,7 @@ static void *DaemonOpenTCLsci(void* in)
         SciPathShort = NULL;
         FREE(TkScriptpathShort);
         TkScriptpathShort = NULL;
+        releaseTclInterpOnError();
         return (0);
     }
     else
@@ -153,11 +163,13 @@ static void *DaemonOpenTCLsci(void* in)
 
         if ( getTclInterp() == NULL )
         {
+            releaseTclInterp();
             Scierror(999, _("Tcl Error: Unable to create Tcl interpreter (Tcl_CreateInterp).\n"));
             FREE(SciPathShort);
             SciPathShort = NULL;
             FREE(TkScriptpathShort);
             TkScriptpathShort = NULL;
+            releaseTclInterpOnError();
             return (0);
         }
         releaseTclInterp();
@@ -166,10 +178,12 @@ static void *DaemonOpenTCLsci(void* in)
         {
             releaseTclInterp();
             Scierror(999, _("Tcl Error: Error during the Tcl initialization (Tcl_Init): %s\n"), Tcl_GetStringResult(getTclInterp()));
+            releaseTclInterp();
             FREE(SciPathShort);
             SciPathShort = NULL;
             FREE(TkScriptpathShort);
             TkScriptpathShort = NULL;
+            releaseTclInterpOnError();
             return (0);
         }
         releaseTclInterp();
@@ -181,7 +195,10 @@ static void *DaemonOpenTCLsci(void* in)
             if ( Tk_Init(getTclInterp()) == TCL_ERROR)
             {
                 releaseTclInterp();
+                releaseTclInterpOnError();
                 Scierror(999, _("Tcl Error: Error during the TK initialization (Tk_Init): %s\n"), Tcl_GetStringResult(getTclInterp()));
+                releaseTclInterp();
+                return (0);
             }
             else
             {
@@ -197,6 +214,7 @@ static void *DaemonOpenTCLsci(void* in)
         {
             releaseTclInterp();
             Scierror(999, _("Tcl Error: Error during the Scilab/Tcl init process. Could not set SciPath: %s\n"), Tcl_GetStringResult(getTclInterp()));
+            releaseTclInterp();
             FREE(SciPathShort);
             SciPathShort = NULL;
             FREE(TkScriptpathShort);
@@ -221,8 +239,10 @@ static void *DaemonOpenTCLsci(void* in)
         {
             releaseTclInterp();
             Scierror(999, _("Tcl Error: Error during the Scilab/TK init process. Error while loading %s: %s\n"), TkScriptpathShort, Tcl_GetStringResult(getTclInterp()));
+            releaseTclInterp();
             FREE(TkScriptpathShort);
             TkScriptpathShort = NULL;
+            releaseTclInterpOnError();
             return (0);
         }
         releaseTclInterp();
@@ -247,7 +267,6 @@ int OpenTCLsci(void)
     // Allows all Tcl application not to freeze nor decrease Scilab speed.
     // Causes also Scilab let those application live their own lifes.
 
-
     __CreateThread(&TclThread, &key, &DaemonOpenTCLsci);
     // Wait to be sure initialisation is complete.
     __LockSignal(&InterpReadyLock);
index 825c07e..dfa1b9e 100644 (file)
@@ -22,10 +22,7 @@ BOOL InitializeTclTk(void)
     if ( getScilabMode() != SCILAB_NWNI )
     {
         setTkStarted(TRUE);
-        if ( OpenTCLsci() != 0 )
-        {
-            setTkStarted(FALSE);
-        }
+        OpenTCLsci();
     }
     return isTkStarted();
 }