From 4680293609078c0ba598f3f2e11f0672a4447b94 Mon Sep 17 00:00:00 2001 From: abv Date: Thu, 14 Apr 2016 15:41:59 +0300 Subject: [PATCH] 0027385: assertion in static initializer in a Windows GUI application Useless global pointer to cerr is removed from OSD_Error, along with methods supporting its customization (Windows-only). Global accessors to environment variables are replaced by locals in UnitsAPI.cxx. --- src/OSD/OSD_Environment.cxx | 11 +++----- src/OSD/OSD_Error.cxx | 52 ++++--------------------------------- src/OSD/OSD_WNT.hxx | 6 ----- src/UnitsAPI/UnitsAPI.cxx | 11 +++----- 4 files changed, 12 insertions(+), 68 deletions(-) diff --git a/src/OSD/OSD_Environment.cxx b/src/OSD/OSD_Environment.cxx index 1552ceff95..c34a52413d 100644 --- a/src/OSD/OSD_Environment.cxx +++ b/src/OSD/OSD_Environment.cxx @@ -344,14 +344,9 @@ void OSD_Environment :: Reset () { } // end OSD_Environment :: Reset -void OSD_Environment :: Perror () { - - if ( ErrorPrefix () ) - - ( *ErrorStream () ) << TEXT( '\'' ) << myName.ToCString () << TEXT( "' - " ); - - myError.Perror (); - +void OSD_Environment :: Perror () +{ + myError.Perror (); } // end OSD_Environment :: Perror Standard_Integer OSD_Environment :: Error () const { diff --git a/src/OSD/OSD_Error.cxx b/src/OSD/OSD_Error.cxx index d805237f85..e2d0ab9e60 100755 --- a/src/OSD/OSD_Error.cxx +++ b/src/OSD/OSD_Error.cxx @@ -457,9 +457,6 @@ typedef struct _error_table { } ERROR_TABLE; -static int fPrefix = 1; -static ostream* errorStream = &cerr; - static ERROR_TABLE commErrorTable [] = { { ERROR_INVALID_FUNCTION, ERR_INVAL }, @@ -573,14 +570,9 @@ OSD_Error :: OSD_Error () : void OSD_Error :: Perror () { - if (errorStream == NULL) - return; - Standard_Character buff[ 32 ]; Standard_CString ptr; - if ( fPrefix ) { - lstrcpy ( buff, "Error ( " ); switch ( myCode ) { @@ -653,12 +645,9 @@ void OSD_Error :: Perror () { lstrcat ( buff, ptr ); lstrcat ( buff, " )" ); - ( *errorStream ) << buff; + std::cerr << buff; - } // end if ( fPrefix . . . ) - - TCollection_ExtendedString aMessageW(myMessage); - ( *errorStream ) << L": " << (const wchar_t*)aMessageW.ToExtString () << endl << flush; + std::cerr << myMessage.ToCString() << std::endl << std::flush; } // end OSD_Error :: Perror @@ -741,42 +730,11 @@ Standard_Boolean OSD_Error :: Failed () const { } // end OSD_Error :: Failed -void OSD_Error :: Reset () { - - myErrno = ERROR_SUCCESS; - if (errorStream != NULL) - { - ( *errorStream ).clear (); - ( *errorStream ).seekp ( 0 ); - ( *errorStream ).clear (); - } - +void OSD_Error :: Reset () +{ + myErrno = ERROR_SUCCESS; } // end OSD_Error :: Reset -void SetErrorStream ( ostream* errStream ) { - - errorStream = errStream; - -} // end SetErrorStream - -void EnablePrefix ( int fEnable ) { - - fPrefix = fEnable; - -} // end EnablePrefix - -int ErrorPrefix ( void ) { - - return fPrefix; - -} // end ErrorPrefix - -ostream* ErrorStream ( void ) { - - return errorStream; - -} // end ErrorStream - static Standard_Integer _get_comm_error ( DWORD dwCode ) { int i; diff --git a/src/OSD/OSD_WNT.hxx b/src/OSD/OSD_WNT.hxx index 74c4ba4cdf..cd2e8e2a7f 100644 --- a/src/OSD/OSD_WNT.hxx +++ b/src/OSD/OSD_WNT.hxx @@ -29,10 +29,4 @@ # endif # endif // OSDAPI -void OSDAPI SetErrorStream ( ostream* ); -//ostream* OSDAPI ErrorStream ( void ); -ostream OSDAPI *ErrorStream ( void ); // for VisualAge -void OSDAPI EnablePrefix ( int ); -int OSDAPI ErrorPrefix ( void ); - #endif // __OSD_WNT_HXX diff --git a/src/UnitsAPI/UnitsAPI.cxx b/src/UnitsAPI/UnitsAPI.cxx index ee4da11a9a..8b00c3a88d 100644 --- a/src/UnitsAPI/UnitsAPI.cxx +++ b/src/UnitsAPI/UnitsAPI.cxx @@ -29,13 +29,6 @@ static Units_UnitsSystem LocalSystemUnits,SILocalSystemUnits,MDTVLocalSystemUnit static TCollection_AsciiString rstring; static UnitsAPI_SystemUnits localSystem = UnitsAPI_SI; static UnitsAPI_SystemUnits currentSystem = UnitsAPI_DEFAULT; -static OSD_Environment env1("CSF_UnitsLexicon"); -static OSD_Environment env2("CSF_UnitsDefinition"); -#ifdef _WIN32 -static OSD_Environment env3("CSF_CurrentUnits"); -static OSD_Environment env4("CSF_MDTVCurrentUnits"); -#endif - //======================================================================= //function : CheckLoading @@ -45,6 +38,7 @@ static OSD_Environment env4("CSF_MDTVCurrentUnits"); void UnitsAPI::CheckLoading (const UnitsAPI_SystemUnits aSystemUnits) { if( currentSystem != aSystemUnits || CurrentUnits.IsNull()) { + OSD_Environment env1("CSF_UnitsLexicon"); TCollection_AsciiString slexiconfile(env1.Value()); if( slexiconfile.Length() > 0 ) Units::LexiconFile(slexiconfile.ToCString()); @@ -59,6 +53,7 @@ void UnitsAPI::CheckLoading (const UnitsAPI_SystemUnits aSystemUnits) Standard_NoSuchObject::Raise("environment variable CSF_UnitsLexicon undefined"); } } + OSD_Environment env2("CSF_UnitsDefinition"); TCollection_AsciiString sunitsfile(env2.Value()); if( sunitsfile.Length() > 0 ) Units::UnitsFile(sunitsfile.ToCString()); @@ -80,6 +75,7 @@ void UnitsAPI::CheckLoading (const UnitsAPI_SystemUnits aSystemUnits) currentSystem = UnitsAPI_SI; if( SICurrentUnits.IsNull() ) { #ifdef _WIN32 + OSD_Environment env3("CSF_CurrentUnits"); TCollection_AsciiString csfcurrent (env3.Value()); if( csfcurrent.Length() > 0 ) SICurrentUnits = new Resource_Manager(csfcurrent.ToCString()); @@ -96,6 +92,7 @@ void UnitsAPI::CheckLoading (const UnitsAPI_SystemUnits aSystemUnits) currentSystem = UnitsAPI_MDTV; if( MDTVCurrentUnits.IsNull() ) { #ifdef _WIN32 + OSD_Environment env4("CSF_MDTVCurrentUnits"); TCollection_AsciiString csfmdtvcurrent (env4.Value()); if( csfmdtvcurrent.Length() > 0 ) MDTVCurrentUnits = new Resource_Manager(csfmdtvcurrent.ToCString()); -- 2.20.1