1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-04 18:06:22 +03:00

0024533: Use 0 to check null handle instead of UndefinedHandleAccess

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.
This commit is contained in:
Roman Lygin 2014-01-23 13:37:50 +04:00 committed by bugmaster
parent 545ef510a7
commit 4d9421a970
8 changed files with 30 additions and 85 deletions

View 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)

View 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),

View 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

View File

@ -39,14 +39,6 @@
#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();

View 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;
}

View File

@ -36,14 +36,6 @@
#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;
}

View 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

View File

@ -141,11 +141,4 @@
//# 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