dead lock fixed when the parser fails to open file 09/17709/2
Cedric Delamarre [Thu, 21 Jan 2016 17:47:31 +0000 (18:47 +0100)]
Change-Id: Ib3a9aef35d914ecb413797a821cf05f3922267ee

scilab/modules/ast/src/cpp/parse/parser.cpp
scilab/modules/functions/sci_gateway/cpp/sci_exec.cpp

index 33c64ea..74e05af 100644 (file)
@@ -32,6 +32,7 @@ extern "C"
 #ifdef __APPLE__
 #include "PATH_MAX.h"
 #endif
+#include "os_wfopen.h"
 }
 
 extern FILE*    yyin;
@@ -57,7 +58,17 @@ void Parser::parseFile(const std::wstring& fileName, const std::wstring& progNam
     {
         ParserSingleInstance::disableParseTrace();
     }
-    ParserSingleInstance::parseFile(fileName, progName);
+
+    try
+    {
+        ParserSingleInstance::parseFile(fileName, progName);
+    }
+    catch (const ast::InternalError& ie)
+    {
+        ParserSingleInstance::setTree(nullptr);
+        ParserSingleInstance::setExitStatus(Parser::Failed);
+    }
+
     this->setExitStatus(ParserSingleInstance::getExitStatus());
     this->setControlStatus(ParserSingleInstance::getControlStatus());
     if (getExitStatus() == Parser::Succeded)
@@ -85,7 +96,7 @@ void ParserSingleInstance::parseFile(const std::wstring& fileName, const std::ws
     yylloc.first_line = yylloc.last_line = 1;
     yylloc.first_column = yylloc.last_column = 1;
 #ifdef _MSC_VER
-    _wfopen_s(&yyin, fileName.c_str(), L"r");
+    yyin = os_wfopen(fileName.c_str(), L"r");
 #else
     char* pstTemp = wide_string_to_UTF8(fileName.c_str());
     yyin = fopen(pstTemp, "r");
index 6be2a28..64baa8e 100644 (file)
@@ -193,8 +193,12 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
                 out.push_back(new types::Double(999));
                 //to lock last error information
                 ConfigVariable::setLastErrorCall();
-                ConfigVariable::setLastErrorMessage(parser.getErrorMessage());
-                ConfigVariable::setLastErrorNumber(999);
+                // when the parser can not open file the error is already set in lasterror.
+                if (wcscmp(parser.getErrorMessage(), L""))
+                {
+                    ConfigVariable::setLastErrorMessage(parser.getErrorMessage());
+                    ConfigVariable::setLastErrorNumber(999);
+                }
                 delete parser.getTree();
                 ThreadManagement::UnlockParser();
                 return types::Function::OK;