]> OCCT Git - occt.git/commitdiff
0026178: Coding rules - eliminate -Wtautological-pointer-compare CLang warnings in...
authorabv <abv@opencascade.com>
Fri, 6 Nov 2015 04:54:57 +0000 (07:54 +0300)
committerabv <abv@opencascade.com>
Fri, 6 Nov 2015 04:54:57 +0000 (07:54 +0300)
Tautological comparisons removed; buffer initialized by zeros; LXX files merged to HXX; descriptions added

src/Standard/FILES
src/Standard/Standard_ErrorHandler.cxx
src/Standard/Standard_ErrorHandler.hxx
src/Standard/Standard_ErrorHandler.lxx [deleted file]
src/Standard/Standard_ErrorHandlerCallback.hxx
src/Standard/Standard_ErrorHandlerCallback.lxx [deleted file]

index 7e701fae6b9565fca210ab40dc9ea596a128e231..7b437a03c089512b64317ddf282b6f85b28af729 100755 (executable)
@@ -22,10 +22,8 @@ Standard_DivideByZero.hxx
 Standard_DomainError.hxx
 Standard_ErrorHandler.cxx
 Standard_ErrorHandler.hxx
-Standard_ErrorHandler.lxx
 Standard_ErrorHandlerCallback.cxx
 Standard_ErrorHandlerCallback.hxx
-Standard_ErrorHandlerCallback.lxx
 Standard_ExtCharacter.hxx
 Standard_ExtString.cxx
 Standard_ExtString.hxx
index 7a4616cc97aa5db6b95d13f65dccc0def3d0d06c..491380bedc0140b40ee1b41ad3b92b98dcb528ec 100644 (file)
@@ -63,6 +63,7 @@ Standard_ErrorHandler::Standard_ErrorHandler () :
        myStatus(Standard_HandlerVoid), myCallbackPtr(0)
 {
   myThread   = GetThreadID();
+  memset (&myLabel, 0, sizeof(myLabel));
 
   theMutex.Lock();
   myPrevious = Top;
@@ -139,7 +140,7 @@ void Standard_ErrorHandler::Unlink()
 Standard_Boolean Standard_ErrorHandler::IsInTryBlock()
 {
   Standard_ErrorHandler* anActive = FindHandler(Standard_HandlerVoid, Standard_False);
-  return anActive != NULL && anActive->myLabel != NULL;
+  return anActive != NULL;
 }
 
 
@@ -153,7 +154,7 @@ void Standard_ErrorHandler::Abort (const Handle(Standard_Failure)& theError)
   Standard_ErrorHandler* anActive = FindHandler(Standard_HandlerVoid, Standard_True);
 
   //==== Check if can do the "longjmp" =======================================
-  if(anActive == NULL || anActive->myLabel == NULL) {
+  if(anActive == NULL) {
     cerr << "*** Abort *** an exception was raised, but no catch was found." << endl;
     if (!theError.IsNull())
       cerr << "\t... The exception is:" << theError->GetMessageString() << endl;
index cdd9ccba37516488d8ae07e774c8b2f8b656b53f..7df8240a579bbe51974cc64a3b43cec226478ea3 100644 (file)
 #define _Standard_ErrorHandler_HeaderFile
 
 #include <Standard.hxx>
-#include <Standard_DefineAlloc.hxx>
 #include <Standard_Handle.hxx>
 
 #include <Standard_PErrorHandler.hxx>
 #include <Standard_JmpBuf.hxx>
 #include <Standard_HandlerStatus.hxx>
 #include <Standard_ThreadId.hxx>
-#include <Standard_Address.hxx>
-#include <Standard_Boolean.hxx>
 #include <Standard_Type.hxx>
+
+//! @file
+//! Support of handling of C signals as C++-style exceptions, and implementation
+//! of C++ exception handling on platforms that do not implement these natively.
+//!
+//! The implementation is based on C long jumps.
+//!
+//! If macro NO_CXX_EXCEPTION is defined, "try" and "catch" are defined as
+//! macros that use jumps to implement exception handling. 
+//! See Standard_Failure::Reraise() for exception throwing code.
+//! Note that this option is obsolete and useless for modern platforms.
+//! 
+//! If macro OCC_CONVERT_SIGNALS is defined, this enables macro OCC_CATCH_SIGNALS
+//! that can be used in the code (often inside try {} blocks) to convert C-style 
+//! signals to standard C++ exceptions. This works only when OSD::SetSignal()
+//! is called to set appropriate signal handler. In the case of signal (like 
+//! access violation, division by zero, etc.) it will jump to the nearest 
+//! OCC_CATCH_SIGNALS in the call stack, which will then throw a C++ exception.
+//! This method is useful for Unix and Linux systems where C++ exceptions
+//! cannot be thrown from C signal handler.
+//! 
+//! On Windows with MSVC compiler, exceptions can be thrown directly from 
+//! signal handler, this OCC_CONVERT_SIGNALS is not needed. Note however that
+//! this requires that compiler option /EHa is used.
+
+#ifdef NO_CXX_EXCEPTION
+
+  // No CXX Exceeptions, only jumps in all the cases.
+  //
+  // Note: In the current version setjmp is used. The alternative solution is to
+  // use sigsetjmp that stores the signal mask (to be checked)
+  // In the original implementation sigsetjmp is tried to use for SUN and IRIX
+  // in the following way:
+  //    #ifdef SOLARIS
+  //      #define DoesNotAbort(aHandler) !sigsetjmp(aHandler.Label(),1)
+  //    #endif
+
+  #define try               Standard_ErrorHandler _Function; \
+                            if(!setjmp(_Function.Label()))
+  #define catch(Error)        else if(_Function.Catches(STANDARD_TYPE(Error)))
+  #define OCC_CATCH_SIGNALS 
+
+#elif defined(OCC_CONVERT_SIGNALS)
+
+  // Exceptions are raied as usual, signal cause jumps in the nearest 
+  // OCC_CATCH_SIGNALS and then thrown as exceptions.
+  #define OCC_CATCH_SIGNALS   Standard_ErrorHandler _aHandler; \
+                              if(setjmp(_aHandler.Label())) { \
+                               _aHandler.Catches(STANDARD_TYPE(Standard_Failure)); \
+                               _aHandler.Error()->Reraise(); \
+                             }
+
+#else
+
+  // Normal Exceptions (for example WNT with MSVC and option /GHa)
+  #define OCC_CATCH_SIGNALS
+
+#endif
+
 class Standard_Failure;
 class Standard_ErrorHandlerCallback;
 
-
+//! Class implementing mechanics of conversion of signals to exceptions.
+//!
+//! Each instance of it stores data for jump placement, thread id,
+//! and callbacks to be called during jump (for proper resource release).
+//!
+//! The active handlers are stored in the global stack, which is used
+//! to find appropriate handler when signal is raised.
 
 class Standard_ErrorHandler 
 {
@@ -46,10 +108,12 @@ public:
   
   //! Unlinks and checks if there is a raised exception.
   Standard_EXPORT void Destroy();
-~Standard_ErrorHandler()
-{
-  Destroy();
-}
+
+  //! Destructor
+  ~Standard_ErrorHandler()
+  {
+    Destroy();
+  }
   
   //! Removes handler from the handlers list
   Standard_EXPORT void Unlink();
@@ -59,7 +123,7 @@ public:
   Standard_EXPORT Standard_Boolean Catches (const Handle(Standard_Type)& aType);
   
   //! Returns label for jump
-    Standard_JmpBuf& Label();
+  Standard_JmpBuf& Label() { return myLabel; }
   
   //! Returns the current Error.
   Standard_EXPORT Handle(Standard_Failure) Error() const;
@@ -70,19 +134,7 @@ public:
   //! Test if the code is currently running in a try block
   Standard_EXPORT static Standard_Boolean IsInTryBlock();
 
-
-friend class Standard_Failure;
-friend class Standard_ErrorHandlerCallback;
-
-
-protected:
-
-
-
-
-
 private:
-
   
   //! A exception is raised but it is not yet caught.
   //! So Abort the current function and transmit the exception
@@ -94,9 +146,10 @@ private:
   //! Set the Error which will be transmitted to "calling routines".
   Standard_EXPORT static void Error (const Handle(Standard_Failure)& aError);
   
-  //! Returns the current handler (Top in former implemntations)
+  //! Returns the current handler (closest in the stack in the current execution thread)
   Standard_EXPORT static Standard_PErrorHandler FindHandler (const Standard_HandlerStatus theStatus, const Standard_Boolean theUnlink);
 
+private:
 
   Standard_PErrorHandler myPrevious;
   Handle(Standard_Failure) myCaughtError;
@@ -105,14 +158,8 @@ private:
   Standard_ThreadId myThread;
   Standard_Address myCallbackPtr;
 
-
+  friend class Standard_Failure;
+  friend class Standard_ErrorHandlerCallback;
 };
 
-
-#include <Standard_ErrorHandler.lxx>
-
-
-
-
-
 #endif // _Standard_ErrorHandler_HeaderFile
diff --git a/src/Standard/Standard_ErrorHandler.lxx b/src/Standard/Standard_ErrorHandler.lxx
deleted file mode 100644 (file)
index 7d1b135..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright (c) 1998-1999 Matra Datavision
-// Copyright (c) 1999-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <Standard_JmpBuf.hxx>
-
-inline Standard_JmpBuf& Standard_ErrorHandler::Label()
-{
-  return myLabel;
-}
-
-/*Common part for jumps*/
-// In the current version setjmp is used. The alternative solution is to
-// use sigsetjmp that stores the signal mask (to be checked)
-// In the original implementation sigsetjmp is tried to use for SUN and IRIX
-// in the following way:
-//    #ifdef SOLARIS
-//      #define DoesNotAbort(aHandler) !sigsetjmp(aHandler.Label(),1)
-//    #endif
-//
-
-#if defined(NO_CXX_EXCEPTION) || defined(OCC_CONVERT_SIGNALS)
-  #ifdef SOLARIS
-    #define DoesNotAbort(aHandler) !setjmp(aHandler.Label())
-  #elif IRIX
-    #define DoesNotAbort(aHandler) !setjmp(aHandler.Label())
-  #else
-    #define DoesNotAbort(aHandler) !setjmp(aHandler.Label())
-  #endif
-#endif
-
-
-#ifdef NO_CXX_EXCEPTION
-/* No CXX Exceeptions, only jumps in all the cases.*/
-  #define try               Standard_ErrorHandler _Function; \
-                            if(DoesNotAbort(_Function))
-  #define catch(Error)        else if(_Function.Catches(STANDARD_TYPE(Error)))
-  #define OCC_CATCH_SIGNALS 
-#elif defined(OCC_CONVERT_SIGNALS)
-/* Exceptions are raied as usual, signal are converted into jumps and 
-   raused in the proper point.*/
-  #define OCC_CATCH_SIGNALS   Standard_ErrorHandler _aHandler; \
-                              if(!DoesNotAbort(_aHandler)) { \
-                               _aHandler.Catches(STANDARD_TYPE(Standard_Failure)); \
-                               _aHandler.Error()->Reraise(); \
-                             }
-#else
-/*Normal Exceptions (for example WNT)*/
-  #define OCC_CATCH_SIGNALS
-#endif
index df4c5490cc022c9c9369fc191fa08ac323418404..4fd96d64841ddabfc03c783a3fbca51e25e5ef58 100644 (file)
 #define _Standard_ErrorHandlerCallback_HeaderFile
 
 #include <Standard.hxx>
-#include <Standard_DefineAlloc.hxx>
 #include <Standard_Handle.hxx>
 
-#include <Standard_Address.hxx>
 class Standard_ErrorHandler;
 
-
 //! Defines a base class for callback objects that can be registered
 //! in the OCC error handler (the class simulating C++ exceptions)
 //! so as to be correctly destroyed when error handler is activated.
@@ -46,50 +43,50 @@ class Standard_ErrorHandlerCallback
 public:
 
   DEFINE_STANDARD_ALLOC
-
   
-  //! Registers this callback object in the current error handler
-  //! (if found).
-    void RegisterCallback();
+  //! Registers this callback object in the current error handler (if found).
+  void RegisterCallback();
   
   //! Unregisters this callback object from the error handler.
-    void UnregisterCallback();
-virtual Standard_EXPORT ~Standard_ErrorHandlerCallback ();
+  void UnregisterCallback();
+
+  //! Destructor
+  virtual Standard_EXPORT ~Standard_ErrorHandlerCallback ();
   
   //! The callback function to perform necessary callback action.
   //! Called by the exception handler when it is being destroyed but
   //! still has this callback registered.
   Standard_EXPORT virtual void DestroyCallback() = 0;
 
-
 friend class Standard_ErrorHandler;
 
-
 protected:
-
   
   //! Empty constructor
-    Standard_ErrorHandlerCallback();
-
-
-
+  Standard_ErrorHandlerCallback();
 
 private:
-
-
-
   Standard_Address myHandler;
   Standard_Address myPrev;
   Standard_Address myNext;
-
-
 };
 
-
-#include <Standard_ErrorHandlerCallback.lxx>
-
-
-
-
+// If neither NO_CXX_EXCEPTION nor OCC_CONVERT_SIGNALS is defined,
+// provide empty inline implementation
+#if ! defined(NO_CXX_EXCEPTION) && ! defined(OCC_CONVERT_SIGNALS)
+inline Standard_ErrorHandlerCallback::Standard_ErrorHandlerCallback ()
+               : myHandler(0), myPrev(0), myNext(0) 
+{
+}
+inline Standard_ErrorHandlerCallback::~Standard_ErrorHandlerCallback () 
+{
+}
+inline void Standard_ErrorHandlerCallback::RegisterCallback () 
+{
+}
+inline void Standard_ErrorHandlerCallback::UnregisterCallback () 
+{
+}
+#endif
 
 #endif // _Standard_ErrorHandlerCallback_HeaderFile
diff --git a/src/Standard/Standard_ErrorHandlerCallback.lxx b/src/Standard/Standard_ErrorHandlerCallback.lxx
deleted file mode 100644 (file)
index f9fb538..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-// Created on: 2006-04-13
-// Created by: Andrey BETENEV
-// Copyright (c) 2006-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-// If neither NO_CXX_EXCEPTION nor OCC_CONVERT_SIGNALS is defined,
-// provide empty inline implementation
-
-#if ! defined(NO_CXX_EXCEPTION) && ! defined(OCC_CONVERT_SIGNALS)
-
-inline Standard_ErrorHandlerCallback::Standard_ErrorHandlerCallback ()
-               : myHandler(0), myPrev(0), myNext(0) 
-{
-}
-
-inline Standard_ErrorHandlerCallback::~Standard_ErrorHandlerCallback () 
-{
-}
-
-inline void Standard_ErrorHandlerCallback::RegisterCallback () 
-{
-}
-
-inline void Standard_ErrorHandlerCallback::UnregisterCallback () 
-{
-}
-
-#endif