From bc25347bdc3005b046af4cab9b2e2e18ea1dd411 Mon Sep 17 00:00:00 2001 From: aka Date: Mon, 28 Aug 2017 13:23:50 +0300 Subject: [PATCH] more modifications to avoid exceptions --- src/Interface/Interface_CheckTool.cxx | 8 +++++--- src/Interface/Interface_CheckTool.hxx | 2 ++ src/Message/Message_Msg.cxx | 16 ++++++++++++++++ src/Message/Message_MsgFile.cxx | 8 +++----- src/STEPControl/STEPControl_Controller.cxx | 19 ++++++++++++------- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/Interface/Interface_CheckTool.cxx b/src/Interface/Interface_CheckTool.cxx index cdf279620e..5298d69378 100644 --- a/src/Interface/Interface_CheckTool.cxx +++ b/src/Interface/Interface_CheckTool.cxx @@ -39,10 +39,8 @@ #endif #include -//static int errh = 1; - -static void raisecheck (Standard_Failure& theException,Handle(Interface_Check)& ach) +void Interface_CheckTool::raisecheck (Standard_Failure& theException,Handle(Interface_Check)& ach) { char mess[100]; sprintf (mess,"** Exception Raised during Check : %s **", @@ -75,6 +73,7 @@ Interface_CheckTool::Interface_CheckTool(const Handle(Interface_InterfaceModel)& theshare (model,protocol) { thestat = 0; + errh = 1; } @@ -88,6 +87,7 @@ Interface_CheckTool::Interface_CheckTool(const Handle(Interface_InterfaceModel)& { thestat = 0; thegtool->Reservate(model->NbEntities()); + errh = 1; } @@ -99,6 +99,7 @@ Interface_CheckTool::Interface_CheckTool(const Handle(Interface_InterfaceModel)& Interface_CheckTool::Interface_CheckTool(const Interface_Graph& graph) : thegtool(graph.Model()->GTool()) , theshare (graph) { + errh = 1; } @@ -110,6 +111,7 @@ Interface_CheckTool::Interface_CheckTool(const Interface_Graph& graph) Interface_CheckTool::Interface_CheckTool(const Handle(Interface_HGraph)& hgraph) : thegtool(hgraph->Graph().Model()->GTool()) , theshare (hgraph) { + errh = 1; } diff --git a/src/Interface/Interface_CheckTool.hxx b/src/Interface/Interface_CheckTool.hxx index 663f628f08..101f8c5f01 100644 --- a/src/Interface/Interface_CheckTool.hxx +++ b/src/Interface/Interface_CheckTool.hxx @@ -131,10 +131,12 @@ protected: private: + Standard_EXPORT void raisecheck(Standard_Failure& theException, Handle(Interface_Check)& ach); Handle(Interface_GTool) thegtool; Interface_ShareTool theshare; Standard_Integer thestat; + Standard_Integer errh; }; diff --git a/src/Message/Message_Msg.cxx b/src/Message/Message_Msg.cxx index bbb6f3885f..9a821d6422 100644 --- a/src/Message/Message_Msg.cxx +++ b/src/Message/Message_Msg.cxx @@ -17,6 +17,7 @@ #include #include #include +#include typedef enum { @@ -26,6 +27,9 @@ typedef enum Msg_IndefiniteType } FormatType; +// mutex used to prevent concurrent access to message registry +static Standard_Mutex theMutex; + //======================================================================= //function : Message_Msg() //purpose : Constructor @@ -42,6 +46,7 @@ Message_Msg::Message_Msg () Message_Msg::Message_Msg (const Message_Msg& theMsg) { + Standard_Mutex::Sentry aSentry(theMutex); myMessageBody = theMsg.myMessageBody; myOriginal = theMsg.myOriginal; for ( Standard_Integer i = 1, n = theMsg.mySeqOfFormats.Length(); i <=n; i++ ) @@ -55,6 +60,7 @@ Message_Msg::Message_Msg (const Message_Msg& theMsg) Message_Msg::Message_Msg (const Standard_CString theMsgCode) { + Standard_Mutex::Sentry aSentry(theMutex); TCollection_AsciiString aKey((char*)theMsgCode); Set ( Message_MsgFile::Msg(aKey) ); } @@ -66,6 +72,7 @@ Message_Msg::Message_Msg (const Standard_CString theMsgCode) Message_Msg::Message_Msg (const TCollection_ExtendedString& theMsgCode) { + Standard_Mutex::Sentry aSentry(theMutex); Set ( Message_MsgFile::Msg(theMsgCode) ); } @@ -76,6 +83,7 @@ Message_Msg::Message_Msg (const TCollection_ExtendedString& theMsgCode) void Message_Msg::Set (const Standard_CString theMsg) { + Standard_Mutex::Sentry aSentry(theMutex); TCollection_AsciiString aMsg((char*)theMsg); Set ( aMsg ); } @@ -87,6 +95,7 @@ void Message_Msg::Set (const Standard_CString theMsg) void Message_Msg::Set (const TCollection_ExtendedString& theMsg) { + Standard_Mutex::Sentry aSentry(theMutex); myMessageBody = theMsg; const Standard_ExtString anExtString = myMessageBody.ToExtString(); @@ -157,6 +166,7 @@ void Message_Msg::Set (const TCollection_ExtendedString& theMsg) Message_Msg& Message_Msg::Arg (const Standard_CString theString) { + Standard_Mutex::Sentry aSentry(theMutex); // get location and format TCollection_AsciiString aFormat; Standard_Integer aFirst = getFormat ( Msg_StringType, aFormat ); @@ -184,6 +194,7 @@ Message_Msg& Message_Msg::Arg (const Standard_CString theString) Message_Msg& Message_Msg::Arg (const TCollection_ExtendedString& theString) { + Standard_Mutex::Sentry aSentry(theMutex); // get location and format TCollection_AsciiString aFormat; Standard_Integer aFirst = getFormat ( Msg_StringType, aFormat ); @@ -203,6 +214,7 @@ Message_Msg& Message_Msg::Arg (const TCollection_ExtendedString& theString) Message_Msg& Message_Msg::Arg (const Standard_Integer theValue) { + Standard_Mutex::Sentry aSentry(theMutex); // get location and format TCollection_AsciiString aFormat; Standard_Integer aFirst = getFormat ( Msg_IntegerType, aFormat ); @@ -227,6 +239,7 @@ Message_Msg& Message_Msg::Arg (const Standard_Integer theValue) Message_Msg& Message_Msg::Arg (const Standard_Real theValue) { + Standard_Mutex::Sentry aSentry(theMutex); // get location and format TCollection_AsciiString aFormat; Standard_Integer aFirst = getFormat ( Msg_RealType, aFormat ); @@ -251,6 +264,7 @@ Message_Msg& Message_Msg::Arg (const Standard_Real theValue) const TCollection_ExtendedString& Message_Msg::Get () { + Standard_Mutex::Sentry aSentry(theMutex); // remove all non-initialised format specifications Standard_Integer i, anIncrement = 0; static const TCollection_ExtendedString anUnknown ("UNKNOWN"); @@ -279,6 +293,7 @@ const TCollection_ExtendedString& Message_Msg::Get () Standard_Integer Message_Msg::getFormat (const Standard_Integer theType, TCollection_AsciiString &theFormat) { + Standard_Mutex::Sentry aSentry(theMutex); for (Standard_Integer i = 1; i <= mySeqOfFormats.Length(); i += 3) if (mySeqOfFormats(i) == theType) { @@ -307,6 +322,7 @@ void Message_Msg::replaceText (const Standard_Integer theFirst, const Standard_Integer theNb, const TCollection_ExtendedString &theStr) { + Standard_Mutex::Sentry aSentry(theMutex); myMessageBody.Remove ( theFirst, theNb ); myMessageBody.Insert ( theFirst, theStr ); diff --git a/src/Message/Message_MsgFile.cxx b/src/Message/Message_MsgFile.cxx index 31ff7f28d2..f753deeba5 100644 --- a/src/Message/Message_MsgFile.cxx +++ b/src/Message/Message_MsgFile.cxx @@ -213,6 +213,7 @@ static Standard_Integer GetFileSize (FILE *theFile) Standard_Boolean Message_MsgFile::LoadFile (const Standard_CString theFileName) { + Standard_Mutex::Sentry aSentry(theMutex); if (theFileName == NULL || * theFileName == '\0') return Standard_False; // Open the file @@ -321,6 +322,7 @@ Standard_Boolean Message_MsgFile::LoadFromEnv (const Standard_CString theEnvName Standard_Boolean Message_MsgFile::LoadFromString (const Standard_CString theContent, const Standard_Integer theLength) { + Standard_Mutex::Sentry aSentry(theMutex); Standard_Integer aStringSize = theLength >= 0 ? theLength : (Standard_Integer )strlen (theContent); NCollection_Buffer aBuffer (NCollection_BaseAllocator::CommonBaseAllocator()); if (aStringSize <= 0 || !aBuffer.Allocate (aStringSize + 2)) @@ -345,10 +347,7 @@ Standard_Boolean Message_MsgFile::AddMsg (const TCollection_AsciiString& theKeyw const TCollection_ExtendedString& theMessage) { Standard_Mutex::Sentry aSentry(theMutex); - Message_DataMapOfExtendedString& aDataMap = ::msgsDataMap(); - - - aDataMap.Bind (theKeyword, theMessage); + Message_DataMapOfExtendedString& aDataMap = ::msgsDataMap(); aDataMap.Bind (theKeyword, theMessage); return Standard_True; } @@ -385,7 +384,6 @@ const TCollection_ExtendedString &Message_MsgFile::Msg (const TCollection_AsciiS Standard_Mutex::Sentry aSentry(theMutex); // find message in the map Message_DataMapOfExtendedString& aDataMap = ::msgsDataMap(); - // if message is not found, generate error message and add it to the map to minimize overhead // on consequent calls with the same key diff --git a/src/STEPControl/STEPControl_Controller.cxx b/src/STEPControl/STEPControl_Controller.cxx index ab60b0e272..7f11ee7235 100644 --- a/src/STEPControl/STEPControl_Controller.cxx +++ b/src/STEPControl/STEPControl_Controller.cxx @@ -70,6 +70,12 @@ STEPControl_Controller::STEPControl_Controller() Standard_Mutex::Sentry aLock(aPars); RWHeaderSection::Init(); RWStepAP214::Init(Handle(StepAP214_Protocol)::DownCast(myAdaptorProtocol)); + + // initialization of Standard Shape Healing + ShapeExtend::Init(); + + // init Standard Shape Processing operators + ShapeProcess_OperLibrary::Init(); } Handle(STEPControl_ActorWrite) ActWrite = new STEPControl_ActorWrite; @@ -163,12 +169,6 @@ STEPControl_Controller::STEPControl_Controller() Handle(IFSelect_EditForm) edsdrf = new IFSelect_EditForm (edsdr,Standard_False,Standard_True,"STEP Product Data (SDR)"); AddSessionItem (edsdr,"step-SDR-edit"); AddSessionItem (edsdrf,"step-SDR-data"); - - // initialization of Standard Shape Healing - ShapeExtend::Init(); - - // init Standard Shape Processing operators - ShapeProcess_OperLibrary::Init(); } Handle(Interface_InterfaceModel) STEPControl_Controller::NewModel () const @@ -252,7 +252,12 @@ void STEPControl_Controller::Customise(Handle(XSControl_WorkSession)& WS) //pdn S4133 18.02.99 WS->AddNamedItem ("xst-derived",new IFSelect_SignAncestor()); Handle(STEPSelections_SelectDerived) stdvar = new STEPSelections_SelectDerived(); - stdvar->SetProtocol(myAdaptorProtocol); + + static Standard_Mutex aPars; + { + Standard_Mutex::Sentry aLock(aPars); + stdvar->SetProtocol(myAdaptorProtocol); + } WS->AddNamedItem ("step-derived",stdvar); //Creates a Selection for ShapeDefinitionRepresentation -- 2.39.5