]> OCCT Git - occt.git/commitdiff
0024533: Use 0 to check null handle instead of UndefinedHandleAccess
authorRoman Lygin <roman.lygin@gmail.com>
Thu, 23 Jan 2014 09:37:50 +0000 (13:37 +0400)
committerbugmaster <bugmaster@opencascade.com>
Thu, 23 Jan 2014 09:38:45 +0000 (13:38 +0400)
Handle classes now use 0 as invalid value for pointer instead of custom (and platform-dependent) value like 0xfefd0000.
Compiler macros UndefinedHandleAddress and _OCC64 are eliminated.

CMakeLists.txt
src/LDOM/LDOM_XmlReader.cxx
src/OSD/OSD_signal.cxx
src/Standard/Handle_Standard_Persistent.hxx
src/Standard/Handle_Standard_Transient.cxx
src/Standard/Handle_Standard_Transient.hxx
src/Standard/Standard_MMgrOpt.cxx
src/Standard/Standard_Macro.hxx

index 682caf8e20454d873d4b9b94df88929aa8b6f919..1468ea73d9924e5d9e7a9bf963d69cf41c4e1e69 100644 (file)
@@ -69,10 +69,6 @@ else()
   SET(COMPILER ${CMAKE_GENERATOR})
 endif()
 
-if (${COMPILER_BITNESS} STREQUAL 64)
-  add_definitions(-D_OCC64)
-endif()
-
 add_definitions(-DCSFDB)
 if(WIN32)
   add_definitions(/DWNT -wd4996)
index 8ba8ce2f356cb18e8fc133a17600db17b86d1e01..7d074fb3867ee224ee5df9a676edbd97d4479291 100644 (file)
@@ -68,11 +68,7 @@ LDOM_XmlReader::LDOM_XmlReader (const int                       aFileDes,
                                 TCollection_AsciiString&        anErrorString)
      : myEOF            (Standard_False),
        myFileDes        (aFileDes),
-#ifdef WNT
-       myIStream        (cin),  // one quirk of MSVC6.0: can't initialise by 0
-#else
-       myIStream        (* (istream *) UndefinedHandleAddress),
-#endif
+       myIStream        (cin),  // just a placeholder, myIStream will never be used anyway
        myError          (anErrorString),
        myDocument       (aDocument),
           myElement        (NULL),
index e7d890511c62077c8c19ed3a4bdecd525ff3ad85..606ef1677993c301b842594d16398704f7f32e33 100644 (file)
@@ -34,7 +34,6 @@
 #include <OSD_SIGSYS.hxx>
 #include <OSD_Exception_CTRL_BREAK.hxx>
 #include <Standard_NumericError.hxx>
-#include <Standard_NullObject.hxx>
 #include <Standard_DivideByZero.hxx>
 #include <Standard_Overflow.hxx>
 
@@ -391,10 +390,7 @@ static void SegvHandler(const int theSignal,
      sigaddset(&set, SIGSEGV);
      sigprocmask (SIG_UNBLOCK, &set, NULL) ;
      void *address = ip->si_addr ;
-     if ( (((long) address )& ~0xffff) == (long) UndefinedHandleAddress ) {
-       Standard_NullObject::NewInstance("Attempt to access to null object")->Jump();
-     }
-     else {
+     {
        char Msg[100];
        sprintf(Msg,"SIGSEGV 'segmentation violation' detected. Address %lx",
          (long ) address ) ;
@@ -423,10 +419,7 @@ static void SegvHandler(const int theSignal,
     Space = ((struct sigcontext *)theContext)->sc_sl.sl_ss.ss_cr20 ;
     Offset = ((struct sigcontext *)theContext)->sc_sl.sl_ss.ss_cr21 ;
 //    cout << "Wrong address = " << hex(Offset) << endl ;
-    if ((Offset & ~0xffff) == (long)UndefinedHandleAddress) {
-      Standard_NullObject::Jump("Attempt to access to null object") ;
-    }
-    else {
+    {
       sprintf(Msg,"SIGSEGV 'segmentation violation' detected. Address %lx",Offset) ;
       OSD_SIGSEGV::Jump(Msg);
 //    scp->sc_pcoq_head = scp->sc_pcoq_tail ;       Permettrait de continuer a
index 4893f12a03d66b1a71f0cf602139738c5484d21b..efdabe405ac4176f7b37d8a4fa015a2a7c0b219b 100644 (file)
 #pragma warning (disable:4312)
 #endif
 
-#ifndef PUndefinedAddress 
-#ifdef _OCC64
-#define PUndefinedAddress ((Standard_Persistent *)0xfefdfefdfefd0000)
-#else
-#define PUndefinedAddress ((Standard_Persistent *)0xfefd0000)
-#endif
-#endif
-
 class Standard_Persistent;
 class Handle_Standard_Type;
 class Handle_Standard_Persistent;
@@ -64,17 +56,17 @@ class Handle(Standard_Persistent)
 
     void BeginScope() const
       {
-       if (entity != PUndefinedAddress) entity->count++;
+       if (entity != 0) entity->count++;
       }    
 
     void EndScope()
       {
-       if (entity != PUndefinedAddress
+       if (entity != 0
          {
           entity->count--;
           if (entity->count == 0) {
            entity->Delete();
-           entity = PUndefinedAddress ;
+           entity = 0 ;
          }
        }
       }
@@ -86,7 +78,7 @@ class Handle(Standard_Persistent)
 
     Handle(Standard_Persistent)()
       {
-       entity = PUndefinedAddress ;
+       entity = 0 ;
       }
 
     Handle(Standard_Persistent)(const Handle(Standard_Persistent)& aTid) 
@@ -98,7 +90,7 @@ class Handle(Standard_Persistent)
     Handle(Standard_Persistent)(const Standard_Persistent *anItem)
       {
        if (!anItem)
-           entity = PUndefinedAddress ;
+           entity = 0 ;
        else {
         entity = (Standard_Persistent *)anItem;
         BeginScope();
@@ -111,32 +103,32 @@ class Handle(Standard_Persistent)
 
      Standard_EXPORT void  ShallowDump(Standard_OStream&) const;
      
-    int operator==(const Handle(Standard_Persistent)& right) const
+    bool operator==(const Handle(Standard_Persistent)& right) const
       {
        return entity == right.entity;
       }
 
-    int operator==(const Standard_Persistent *right) const
+    bool operator==(const Standard_Persistent *right) const
       {
        return entity == right;
       }
 
-    friend int operator==(const Standard_Persistent *left, const Handle(Standard_Persistent)& right)
+    friend bool operator==(const Standard_Persistent *left, const Handle(Standard_Persistent)& right)
       {
        return left == right.entity;
       }
 
-    int operator!=(const Handle(Standard_Persistent)& right) const
+    bool operator!=(const Handle(Standard_Persistent)& right) const
       {
        return entity != right.entity;
       }
 
-    int operator!=(const Standard_Persistent *right) const
+    bool operator!=(const Standard_Persistent *right) const
       {
        return entity != right;
       }
 
-    friend int operator!=(const Standard_Persistent *left, const Handle(Standard_Persistent)& right)
+    friend bool operator!=(const Standard_Persistent *left, const Handle(Standard_Persistent)& right)
       {
        return left != right.entity;
       }
@@ -144,12 +136,12 @@ class Handle(Standard_Persistent)
     void Nullify()
       {
        EndScope();
-       entity =  PUndefinedAddress ;
+       entity =  0 ;
       }
 
     Standard_Boolean IsNull() const
       {
-       return entity == PUndefinedAddress ;
+       return entity == 0 ;
       } 
 
     Standard_Persistent* Access() const
@@ -168,7 +160,7 @@ class Handle(Standard_Persistent)
       {
        EndScope();
        if (!anItem)
-           entity = PUndefinedAddress ;
+           entity = 0 ;
        else {
         entity = (Standard_Persistent *)anItem;
         BeginScope();
index 55fb1d40f1260cd68336f2abe8423931aaefcf93..071ba643d861e8de07d0dbd65b72fc867066d7de 100644 (file)
@@ -26,7 +26,7 @@ void Handle(Standard_Transient)::Dump(Standard_OStream& out) const
 
 void Handle(Standard_Transient)::Assign (const Standard_Transient *anItem)
 {
-  Standard_Transient *anIt = ( anItem ? (Standard_Transient*)anItem : UndefinedHandleAddress );
+  Standard_Transient *anIt = (Standard_Transient*)anItem;
   if ( anIt == entity ) return;
   EndScope();
   entity = anIt;
@@ -37,7 +37,7 @@ void Handle(Standard_Transient)::Assign (const Standard_Transient *anItem)
 
 void Handle(Standard_Transient)::BeginScope()
 {
-  if (entity != UndefinedHandleAddress)
+  if (entity != 0)
   {
     Standard_Atomic_Increment (&entity->count);
   }
@@ -47,9 +47,9 @@ void Handle(Standard_Transient)::BeginScope()
 
 void Handle(Standard_Transient)::EndScope()
 {
-  if (entity == UndefinedHandleAddress)
+  if (entity == 0)
     return;
   if (Standard_Atomic_Decrement (&entity->count) == 0)
     entity->Delete();
-  entity = UndefinedHandleAddress;
+  entity = 0;
 }
index 54b84f79096548991ed50ea07521fa14cbfa5b70..6932aa775d252e265a46adea897fc58a36110890 100644 (file)
 #pragma warning (disable:4312)
 #endif
 
-#ifndef UndefinedHandleAddress 
-#ifdef _OCC64
-#define UndefinedHandleAddress ((Standard_Transient *)0xfefdfefdfefd0000)
-#else
-#define UndefinedHandleAddress ((Standard_Transient *)0xfefd0000)
-#endif
-#endif
-
 class Handle_Standard_Transient;
 
 Standard_EXPORT Standard_Integer HashCode(const Handle(Standard_Transient)& ,const Standard_Integer);
@@ -60,17 +52,18 @@ Standard_EXPORT Standard_Integer HashCode(const Handle(Standard_Transient)& ,con
 class Handle(Standard_Transient)
 {
 public:
+  
   // Public methods
   
   //! Empty constructor
   Handle(Standard_Transient) () 
-    : entity(UndefinedHandleAddress
+    : entity(0
   {
   }
 
   //! Constructor from pointer to new object
   Handle(Standard_Transient) (const Standard_Transient *anItem)
-    : entity ( anItem ? (Standard_Transient*)anItem : UndefinedHandleAddress )
+    : entity ( (Standard_Transient*)anItem )
   {
     BeginScope();
   }
@@ -83,7 +76,7 @@ public:
   } 
 
   //! Destructor
-  Standard_EXPORT ~Handle(Standard_Transient)()
+  ~Handle(Standard_Transient)()
   {
     EndScope();
   }
@@ -111,7 +104,7 @@ public:
   //! Check for being null
   Standard_Boolean IsNull() const
   {
-    return entity == UndefinedHandleAddress;
+    return entity == 0;
   } 
 
   //! Returns pointer to referred object
@@ -169,25 +162,25 @@ public:
   }
 
   //! Check for equality
-  friend int operator==(const Standard_Transient *left, const Handle(Standard_Transient)& right)
+  friend bool operator==(const Standard_Transient *left, const Handle(Standard_Transient)& right)
   {
     return left == right.entity;
   }
 
   //! Check for inequality
-  int operator!=(const Handle(Standard_Transient)& right) const
+  bool operator!=(const Handle(Standard_Transient)& right) const
   {
     return entity != right.entity;
   }
 
   //! Check for inequality
-  int operator!=(const Standard_Transient *right) const
+  bool operator!=(const Standard_Transient *right) const
   {
     return entity != right;
   }
 
   //! Check for inequality
-  friend int operator!=(const Standard_Transient *left, const Handle(Standard_Transient)& right)
+  friend bool operator!=(const Standard_Transient *left, const Handle(Standard_Transient)& right)
   {
     return left != right.entity;
   }
index 8542e245c0fa69c700bcd3dddf0e1425b26cf086..4a93c7b70256b90867f95a48ee1bccc9e84a351c 100644 (file)
@@ -134,24 +134,6 @@ extern "C" int getpagesize() ;
 #define ROUNDDOWN_CELL(size)           ROUNDDOWN8(size)
 #define INDEX_CELL(rsize)              ((rsize) >> 3)
 
-// Minimal granularity: 4 bytes (32-bit systems only)
-#ifndef _OCC64
-//#define ROUNDUP_CELL(size)             ROUNDUP4(size)
-//#define INDEX_CELL(rsize)              ((rsize) >> 2)
-#endif
-
-// Adaptive granularity, less for little blocks and greater for bigger ones: 
-/*
-#if _OCC64
-#define ROUNDUP_CELL(size) ((size)  <= 0x40 ? ROUNDUP8(size) : ROUNDUP16(size))
-#define INDEX_CELL(rsize)  ((rsize) <= 0x40 ? ((rsize) >> 3) : (4 + ((rsize) >> 4)))
-#else
-#define ROUNDUP_CELL(size) ((size)  <= 0x40 ? ROUNDUP4(size) : ROUNDUP8(size))
-#define INDEX_CELL(rsize)  ((rsize) <= 0x40 ? ((rsize) >> 2) : (8 + ((rsize) >> 3)))
-#endif
-*/
-
-
 /* In the allocated block, first bytes are used for storing of memory manager's data.
    (size of block). The minimal size of these data is sizeof(int).
    The memory allocated in system usually alligned by 16 bytes.Tthe aligment of the 
index b86317fe7b4b080c8ba52a9e50a96d9edc9f8466..ef6ea8692070b5f4621fd9bd0af2392772cb4443 100644 (file)
 //#  endif  // WNT
 # endif  // __Standard_API
 
-// Define _OCC64 variable (unless already defined) if platform is known to be 64-bit
-#ifndef _OCC64
-#if defined (__alpha) || defined(DECOSF1) || defined(_WIN64) || defined(__amd64) || defined(__x86_64)
-#define _OCC64 1
-#endif
-#endif
-
 #endif