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

0024489: Avoid type casts in call to Standard::Free()

Method Standard::Free() is converted to template, so that pointer is nullified using its proper type.
Unnecessary type cases in calls to Standard::Free(), Standard::Reallocate(), and NCollection_BaseAllocator::Free() eliminated throughout OCCT code.
This commit is contained in:
abv 2014-01-09 11:56:20 +04:00 committed by bugmaster
parent b24ac89262
commit 547702a15d
28 changed files with 105 additions and 123 deletions

View File

@ -107,12 +107,12 @@ int mcrcomm_(integer *kop,
static static
int mcrfree_(integer *ibyte, int mcrfree_(integer *ibyte,
void* *iadr, intptr_t iadr,
integer *ier); integer *ier);
static static
int mcrgetv_(integer *sz, int mcrgetv_(integer *sz,
void* *iad, intptr_t *iad,
integer *ier); integer *ier);
static static
@ -2351,7 +2351,7 @@ L1100:
} }
} else { } else {
/* DE-ALLOCATION SYSTEM */ /* DE-ALLOCATION SYSTEM */
mcrfree_(&ibyte, reinterpret_cast<void**> (&iaddr), &ier); mcrfree_(&ibyte, iaddr, &ier);
if (ier != 0) { if (ier != 0) {
goto L9002; goto L9002;
} }
@ -2510,14 +2510,12 @@ int AdvApp2Var_SysBase::mcrfill_(integer *size,
//purpose : //purpose :
//======================================================================= //=======================================================================
int mcrfree_(integer *,//ibyte, int mcrfree_(integer *,//ibyte,
void* *iadr, intptr_t iadr,
integer *ier) integer *ier)
{ {
*ier=0; *ier=0;
Standard::Free(*iadr); Standard::Free((void*)iadr);
//Standard::Free always nullifies address, so check becomes incorrect
//if ( !*iadr ) *ier = 1;
return 0; return 0;
} }
@ -2553,13 +2551,13 @@ int mcrfree_(integer *,//ibyte,
//purpose : //purpose :
//======================================================================= //=======================================================================
int mcrgetv_(integer *sz, int mcrgetv_(integer *sz,
void* *iad, intptr_t *iad,
integer *ier) integer *ier)
{ {
*ier = 0; *ier = 0;
*iad = Standard::Allocate(*sz); *iad = (intptr_t)Standard::Allocate(*sz);
if ( !*iad ) *ier = 1; if ( !*iad ) *ier = 1;
return 0; return 0;
} }
@ -2963,7 +2961,7 @@ int AdvApp2Var_SysBase::mcrrqst_(integer *iunit,
/* ELSE */ /* ELSE */
/* ALLOCATION SYSTEME */ /* ALLOCATION SYSTEME */
ksys = heap_allocation; ksys = heap_allocation;
mcrgetv_(&ibyte, reinterpret_cast<void**> (&iaddr), &ier); mcrgetv_(&ibyte, &iaddr, &ier);
if (ier != 0) { if (ier != 0) {
goto L9003; goto L9003;
} }

6
src/BOPCol/BOPCol_Array1.hxx Normal file → Executable file
View File

@ -68,7 +68,7 @@ template <class Type> class BOPCol_MemBlock {
for (i=0; i<mySize; ++i) { for (i=0; i<mySize; ++i) {
myData[i].~Type(); myData[i].~Type();
} }
myAllocator->Free((Standard_Address&)myData); myAllocator->Free(myData);
// //
myData=NULL; myData=NULL;
mySize=0; mySize=0;
@ -177,10 +177,8 @@ template <class Type> class BOPCol_Array1 {
while(pBlock) { while(pBlock) {
pNext=pBlock->Next(); pNext=pBlock->Next();
// //
//pBlock->~BOPCol_MemBlock<Type> ();
pBlock->~BOPCol_XMemBlock(); pBlock->~BOPCol_XMemBlock();
//pBlock->Clear(); myAllocator->Free(pBlock);
myAllocator->Free((Standard_Address&)pBlock);
// //
pBlock=pNext; pBlock=pNext;
} }

View File

@ -116,7 +116,7 @@ static
myNbIds=0; myNbIds=0;
mySum=0; mySum=0;
if (myPtr) { if (myPtr) {
myAllocator->Free((Standard_Address)myPtr); myAllocator->Free(myPtr);
myPtr=NULL; myPtr=NULL;
} }
} }

2
src/BOPDS/BOPDS_PaveBlock.cxx Normal file → Executable file
View File

@ -317,7 +317,7 @@ static
for (i=0; i<aNb; ++i) { for (i=0; i<aNb; ++i) {
pPaves[i].~BOPDS_Pave(); pPaves[i].~BOPDS_Pave();
} }
myAllocator->Free((Standard_Address&)pPaves); myAllocator->Free(pPaves);
} }
//======================================================================= //=======================================================================

4
src/BOPTools/BOPTools_Set.lxx Normal file → Executable file
View File

@ -162,7 +162,7 @@ static
for (i=0; i<aNb; ++i) { for (i=0; i<aNb; ++i) {
pShapes[i].~TopoDS_Shape(); pShapes[i].~TopoDS_Shape();
} }
myAllocator->Free((Standard_Address&)pShapes); myAllocator->Free(pShapes);
} }
//======================================================================= //=======================================================================
//function : AddEdges //function : AddEdges
@ -220,7 +220,7 @@ static
for (i=0; i<aNb; ++i) { for (i=0; i<aNb; ++i) {
pShapes[i].~TopoDS_Shape(); pShapes[i].~TopoDS_Shape();
} }
myAllocator->Free((Standard_Address&)pShapes); myAllocator->Free(pShapes);
} }
//======================================================================= //=======================================================================
//function : IsEqual //function : IsEqual

View File

@ -176,7 +176,7 @@ void DBC_VArray::Resize (const Standard_Integer NewSize)
ptrtmp->DBC_VArrayTNode::~DBC_VArrayTNode(); ptrtmp->DBC_VArrayTNode::~DBC_VArrayTNode();
ptrtmp++; ptrtmp++;
} }
Standard::Free((Standard_Address&)myData); Standard::Free(myData);
} else { } else {
for(i = 0; i < NewSize; i++) { for(i = 0; i < NewSize; i++) {
ptrtmp = new((Standard_Address)ptrtmp) DBC_VArrayTNode(); ptrtmp = new((Standard_Address)ptrtmp) DBC_VArrayTNode();
@ -291,7 +291,7 @@ void DBC_VArray::Destroy()
ptrtmp->DBC_VArrayTNode::~DBC_VArrayTNode(); ptrtmp->DBC_VArrayTNode::~DBC_VArrayTNode();
ptrtmp++; ptrtmp++;
} }
Standard::Free((Standard_Address&)myData); Standard::Free(myData);
myData = 0L; myData = 0L;
} }
#endif #endif

View File

@ -1077,7 +1077,7 @@ void FSD_BinaryFile::ReadString(TCollection_AsciiString& aString)
if (!fread(c,size,1,myStream)) Storage_StreamWriteError::Raise(); if (!fread(c,size,1,myStream)) Storage_StreamWriteError::Raise();
c[size] = '\0'; c[size] = '\0';
aString = c; aString = c;
Standard::Free((Standard_Address&)c); Standard::Free(c);
} }
else { else {
aString.Clear(); aString.Clear();
@ -1138,7 +1138,7 @@ void FSD_BinaryFile::ReadExtendedString(TCollection_ExtendedString& aString)
c[i] = InverseExtChar (c[i]); c[i] = InverseExtChar (c[i]);
#endif #endif
aString = c; aString = c;
Standard::Free((Standard_Address&)c); Standard::Free(c);
} }
else { else {
aString.Clear(); aString.Clear();

View File

@ -98,46 +98,46 @@ void Graphic3d_ArrayOfPrimitives::Destroy ()
{ {
if( myPrimitiveArray ) { if( myPrimitiveArray ) {
if( myPrimitiveArray->vertices ){ if( myPrimitiveArray->vertices ){
Standard::Free( (Standard_Address&)myPrimitiveArray->vertices ); Standard::Free (myPrimitiveArray->vertices);
myPrimitiveArray->vertices = 0; myPrimitiveArray->vertices = 0;
} }
if( myPrimitiveArray->vnormals ){ if( myPrimitiveArray->vnormals ){
Standard::Free( (Standard_Address&)myPrimitiveArray->vnormals ); Standard::Free (myPrimitiveArray->vnormals);
myPrimitiveArray->vnormals = 0; myPrimitiveArray->vnormals = 0;
} }
if( myPrimitiveArray->vcolours ){ if( myPrimitiveArray->vcolours ){
Standard::Free( (Standard_Address&)myPrimitiveArray->vcolours ); Standard::Free (myPrimitiveArray->vcolours);
myPrimitiveArray->vcolours = 0; myPrimitiveArray->vcolours = 0;
} }
if( myPrimitiveArray->vtexels ){ if( myPrimitiveArray->vtexels ){
Standard::Free( (Standard_Address&)myPrimitiveArray->vtexels ); Standard::Free (myPrimitiveArray->vtexels);
myPrimitiveArray->vtexels = 0; myPrimitiveArray->vtexels = 0;
} }
if( myPrimitiveArray->fcolours ){ if( myPrimitiveArray->fcolours ){
Standard::Free( (Standard_Address&)myPrimitiveArray->fcolours ); Standard::Free (myPrimitiveArray->fcolours);
myPrimitiveArray->fcolours = 0; myPrimitiveArray->fcolours = 0;
} }
if( myPrimitiveArray->bounds ){ if( myPrimitiveArray->bounds ){
Standard::Free( (Standard_Address&)myPrimitiveArray->bounds ); Standard::Free (myPrimitiveArray->bounds);
myPrimitiveArray->bounds = 0; myPrimitiveArray->bounds = 0;
} }
if( myPrimitiveArray->edges ){ if( myPrimitiveArray->edges ){
Standard::Free( (Standard_Address&)myPrimitiveArray->edges ); Standard::Free (myPrimitiveArray->edges);
myPrimitiveArray->edges = 0; myPrimitiveArray->edges = 0;
} }
if( myPrimitiveArray->edge_vis ){ if( myPrimitiveArray->edge_vis ){
Standard::Free( (Standard_Address&)myPrimitiveArray->edge_vis ); Standard::Free (myPrimitiveArray->edge_vis);
myPrimitiveArray->edge_vis = 0; myPrimitiveArray->edge_vis = 0;
} }
Standard::Free( (Standard_Address&)myPrimitiveArray ); Standard::Free (myPrimitiveArray);
#if TRACE > 0 #if TRACE > 0
cout << " Graphic3d_ArrayOfPrimitives::Destroy()" << endl; cout << " Graphic3d_ArrayOfPrimitives::Destroy()" << endl;
#endif #endif

View File

@ -245,10 +245,10 @@ to index it in the edges array */
while(edges[ivert] != NULL) { while(edges[ivert] != NULL) {
cedge = edges[ivert]; cedge = edges[ivert];
edges[ivert] = cedge->next; edges[ivert] = cedge->next;
Standard::Free((void*&)cedge); Standard::Free(cedge);
} }
} }
Standard::Free((void*&)edges); Standard::Free(edges);
} }
@ -302,7 +302,7 @@ void Graphic3d_Strips :: STRIPT_GET_STRIP ( Standard_Integer& NBTRIANGLES,
{ {
NBTRIANGLES = 0; NBTRIANGLES = 0;
current_stript.t = 0; current_stript.t = 0;
Standard::Free((void*&)trianglesptr); Standard::Free(trianglesptr);
return; return;
} }
@ -886,10 +886,10 @@ to index it in the edges array */
{ {
cedge = edges[ivert]; cedge = edges[ivert];
edges[ivert] = cedge->next; edges[ivert] = cedge->next;
Standard::Free((void*&)cedge); Standard::Free(cedge);
} }
} }
Standard::Free((void*&)edges); Standard::Free(edges);
} }
@ -943,7 +943,7 @@ void Graphic3d_Strips :: STRIPQ_GET_STRIP ( Standard_Integer& NBQUAD,Standard_In
{ {
NBQUAD = 0; NBQUAD = 0;
current_stripq.q = 0; current_stripq.q = 0;
Standard::Free((void*&)quadranglesptr); Standard::Free(quadranglesptr);
return; return;
} }
/* Now search the best strip from this quadrangle /* Now search the best strip from this quadrangle

View File

@ -43,7 +43,7 @@ void* NCollection_BaseAllocator::Allocate(const size_t size)
void NCollection_BaseAllocator::Free(void *anAddress) void NCollection_BaseAllocator::Free(void *anAddress)
{ {
if (anAddress) Standard::Free((Standard_Address&)anAddress); if (anAddress) Standard::Free(anAddress);
} }
//======================================================================= //=======================================================================

View File

@ -65,7 +65,7 @@ protected:
void Deallocate() void Deallocate()
{ {
if (myPtr != myBuffer) if (myPtr != myBuffer)
Standard::Free (*(Standard_Address*)&myPtr); Standard::Free (myPtr);
} }
protected: protected:

View File

@ -232,9 +232,7 @@ private: //! @name low-level methods
//! Release string buffer and nullify the pointer. //! Release string buffer and nullify the pointer.
static void strFree (Type*& thePtr) static void strFree (Type*& thePtr)
{ {
void* aPtr = thePtr; Standard::Free (thePtr);
Standard::Free (aPtr);
thePtr = NULL;
} }
//! Provides bytes interface to avoid incorrect pointer arithmetics. //! Provides bytes interface to avoid incorrect pointer arithmetics.

View File

@ -57,12 +57,12 @@ namespace
// ======================================================================= // =======================================================================
void OpenGl_PrimitiveArray::clearMemoryOwn() const void OpenGl_PrimitiveArray::clearMemoryOwn() const
{ {
Standard::Free ((Standard_Address& )myPArray->edges); Standard::Free (myPArray->edges);
Standard::Free ((Standard_Address& )myPArray->vertices); Standard::Free (myPArray->vertices);
Standard::Free ((Standard_Address& )myPArray->vcolours); Standard::Free (myPArray->vcolours);
Standard::Free ((Standard_Address& )myPArray->vnormals); Standard::Free (myPArray->vnormals);
Standard::Free ((Standard_Address& )myPArray->vtexels); Standard::Free (myPArray->vtexels);
Standard::Free ((Standard_Address& )myPArray->edge_vis); /// ??? Standard::Free (myPArray->edge_vis); /// ???
myPArray->edges = NULL; myPArray->edges = NULL;
myPArray->vertices = NULL; myPArray->vertices = NULL;

View File

@ -133,11 +133,13 @@ is
---Purpose: Allocates memory blocks ---Purpose: Allocates memory blocks
-- aSize - bytes to allocate -- aSize - bytes to allocate
Free (aStorage:in out Address from Standard); Free (aStorage: Address from Standard);
---Purpose: Deallocates memory blocks ---Purpose: Deallocates memory blocks
-- aStorage - previously allocated memory block to be freed -- aStorage - previously allocated memory block to be freed
Reallocate(aStorage: in out Address from Standard; ---C++: alias "template <typename T> static inline void Free (T*& thePtr) { Free ((void*)thePtr); thePtr = 0; }"
Reallocate(aStorage: Address from Standard;
aNewSize: Size from Standard) aNewSize: Size from Standard)
returns Address from Standard; returns Address from Standard;
---Purpose: Reallocates memory blocks ---Purpose: Reallocates memory blocks

View File

@ -183,13 +183,13 @@ Standard_Address Standard::Allocate(const Standard_Size size)
} }
//======================================================================= //=======================================================================
//function : Free //function : FreeAddress
//purpose : //purpose :
//======================================================================= //=======================================================================
void Standard::Free(Standard_Address& aStorage) void Standard::Free (Standard_Address theStorage)
{ {
GetMMgr()->Free(aStorage); GetMMgr()->Free(theStorage);
} }
//======================================================================= //=======================================================================
@ -197,10 +197,10 @@ void Standard::Free(Standard_Address& aStorage)
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Address Standard::Reallocate(Standard_Address& aStorage, Standard_Address Standard::Reallocate (Standard_Address theStorage,
const Standard_Size newSize) const Standard_Size theSize)
{ {
return GetMMgr()->Reallocate(aStorage, newSize); return GetMMgr()->Reallocate (theStorage, theSize);
} }
//======================================================================= //=======================================================================

View File

@ -61,7 +61,7 @@
} \ } \
void operator delete (void* theAddress) \ void operator delete (void* theAddress) \
{ \ { \
Standard::Free ((Standard_Address&)theAddress); \ Standard::Free (theAddress); \
} \ } \
DEFINE_STANDARD_ALLOC_ARRAY \ DEFINE_STANDARD_ALLOC_ARRAY \
DEFINE_STANDARD_ALLOC_PLACEMENT DEFINE_STANDARD_ALLOC_PLACEMENT

View File

@ -475,7 +475,7 @@ Standard_Address Standard_MMgrOpt::Allocate(const Standard_Size aSize)
//purpose : //purpose :
//======================================================================= //=======================================================================
void Standard_MMgrOpt::Free(Standard_Address& theStorage) void Standard_MMgrOpt::Free(Standard_Address theStorage)
{ {
// safely return if attempt to free null pointer // safely return if attempt to free null pointer
if ( ! theStorage ) if ( ! theStorage )
@ -510,8 +510,6 @@ void Standard_MMgrOpt::Free(Standard_Address& theStorage)
// otherwise, we have block of big size which shall be simply released // otherwise, we have block of big size which shall be simply released
else else
FreeMemory (aBlock, RoundSize); FreeMemory (aBlock, RoundSize);
theStorage = NULL;
} }
//======================================================================= //=======================================================================
@ -704,7 +702,7 @@ void Standard_MMgrOpt::FreePools()
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Address Standard_MMgrOpt::Reallocate(Standard_Address& theStorage, Standard_Address Standard_MMgrOpt::Reallocate(Standard_Address theStorage,
const Standard_Size theNewSize) const Standard_Size theNewSize)
{ {
// if theStorage == NULL, just allocate new memory block // if theStorage == NULL, just allocate new memory block
@ -732,7 +730,6 @@ Standard_Address Standard_MMgrOpt::Reallocate(Standard_Address& theStorage,
if ( myClear ) if ( myClear )
memset(((char*)newStorage) + OldSize, 0, theNewSize-OldSize); memset(((char*)newStorage) + OldSize, 0, theNewSize-OldSize);
} }
theStorage = NULL;
return newStorage; return newStorage;
} }

View File

@ -97,15 +97,15 @@ class Standard_MMgrOpt : public Standard_MMgrRoot
//! Allocate aSize bytes; see class description above //! Allocate aSize bytes; see class description above
Standard_EXPORT virtual Standard_Address Allocate(const Standard_Size aSize); Standard_EXPORT virtual Standard_Address Allocate(const Standard_Size aSize);
//! Reallocate previously allocated aPtr to a new size; aPtr is nullified. //! Reallocate previously allocated aPtr to a new size; new address is returned.
//! In case that aPtr is null, the function behaves exactly as Allocate. //! In case that aPtr is null, the function behaves exactly as Allocate.
Standard_EXPORT virtual Standard_Address Reallocate(Standard_Address& aPtr, Standard_EXPORT virtual Standard_Address Reallocate (Standard_Address thePtr,
const Standard_Size aSize); const Standard_Size theSize);
//! Free previously allocated block; aPtr is nullified. //! Free previously allocated block.
//! Note that block can not all blocks are released to the OS by this //! Note that block can not all blocks are released to the OS by this
//! method (see class description) //! method (see class description)
Standard_EXPORT virtual void Free(Standard_Address& aPtr); Standard_EXPORT virtual void Free (Standard_Address thePtr);
//! Release medium-sized blocks of memory in free lists to the system. //! Release medium-sized blocks of memory in free lists to the system.
//! Returns number of actually freed blocks //! Returns number of actually freed blocks

View File

@ -50,10 +50,9 @@ Standard_Address Standard_MMgrRaw::Allocate(const Standard_Size aSize)
//purpose : //purpose :
//======================================================================= //=======================================================================
void Standard_MMgrRaw::Free(Standard_Address& aStorage) void Standard_MMgrRaw::Free(Standard_Address theStorage)
{ {
free(aStorage); free(theStorage);
aStorage=NULL;
} }
//======================================================================= //=======================================================================
@ -61,18 +60,17 @@ void Standard_MMgrRaw::Free(Standard_Address& aStorage)
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Address Standard_MMgrRaw::Reallocate(Standard_Address& aStorage, Standard_Address Standard_MMgrRaw::Reallocate(Standard_Address theStorage,
const Standard_Size newSize) const Standard_Size theSize)
{ {
// the size is rounded up to 4 since some OCC classes // the size is rounded up to 4 since some OCC classes
// (e.g. TCollection_AsciiString) assume memory to be double word-aligned // (e.g. TCollection_AsciiString) assume memory to be double word-aligned
const Standard_Size aRoundSize = (newSize + 3) & ~0x3; const Standard_Size aRoundSize = (theSize + 3) & ~0x3;
Standard_Address newStorage = (Standard_Address)realloc(aStorage, aRoundSize); Standard_Address newStorage = (Standard_Address)realloc(theStorage, aRoundSize);
if ( ! newStorage ) if ( ! newStorage )
Standard_OutOfMemory::Raise("Standard_MMgrRaw::Reallocate(): realloc failed"); Standard_OutOfMemory::Raise("Standard_MMgrRaw::Reallocate(): realloc failed");
// Note that it is not possible to ensure that additional memory // Note that it is not possible to ensure that additional memory
// allocated by realloc will be cleared (so as to satisfy myClear mode); // allocated by realloc will be cleared (so as to satisfy myClear mode);
// in order to do that we would need using memset... // in order to do that we would need using memset...
aStorage = NULL;
return newStorage; return newStorage;
} }

View File

@ -46,12 +46,12 @@ class Standard_MMgrRaw : public Standard_MMgrRoot
Standard_EXPORT virtual Standard_Address Allocate(const Standard_Size aSize); Standard_EXPORT virtual Standard_Address Allocate(const Standard_Size aSize);
//! Reallocate aPtr to the size aSize. //! Reallocate aPtr to the size aSize.
//! The pointer aPtr is nullified; new pointer is returned. //! The new pointer is returned.
Standard_EXPORT virtual Standard_Address Reallocate(Standard_Address& aPtr, Standard_EXPORT virtual Standard_Address Reallocate(Standard_Address thePtr,
const Standard_Size aSize); const Standard_Size theSize);
//! Free allocated memory. The pointer is nullified. //! Free allocated memory. The pointer is nullified.
Standard_EXPORT virtual void Free(Standard_Address&); Standard_EXPORT virtual void Free (Standard_Address thePtr);
protected: protected:
Standard_Boolean myClear; //! Option to nullify allocated memory Standard_Boolean myClear; //! Option to nullify allocated memory

View File

@ -45,13 +45,12 @@ class Standard_MMgrRoot
Standard_EXPORT virtual Standard_Address Allocate (const Standard_Size theSize)=0; Standard_EXPORT virtual Standard_Address Allocate (const Standard_Size theSize)=0;
//! Reallocate previously allocated memory to contain at least theSize bytes. //! Reallocate previously allocated memory to contain at least theSize bytes.
//! In case of success, aPtr should be nullified and new pointer returned. //! In case of success, new pointer is returned.
Standard_EXPORT virtual Standard_Address Reallocate (Standard_Address& aPtr, Standard_EXPORT virtual Standard_Address Reallocate (Standard_Address thePtr,
const Standard_Size theSize)=0; const Standard_Size theSize)=0;
//! Frees previously allocated memory at specified address. //! Frees previously allocated memory at specified address.
//! The pointer is nullified. Standard_EXPORT virtual void Free(Standard_Address thePtr)=0;
Standard_EXPORT virtual void Free(Standard_Address& aPtr)=0;
//! Purge internally cached unused memory blocks (if any) //! Purge internally cached unused memory blocks (if any)
//! by releasing them to the operating system. //! by releasing them to the operating system.

View File

@ -65,10 +65,9 @@ Standard_Address Standard_MMgrTBBalloc::Allocate(const Standard_Size aSize)
//purpose : //purpose :
//======================================================================= //=======================================================================
void Standard_MMgrTBBalloc::Free(Standard_Address& aStorage) void Standard_MMgrTBBalloc::Free (Standard_Address theStorage)
{ {
scalable_free(aStorage); scalable_free (theStorage);
aStorage=NULL;
} }
//======================================================================= //=======================================================================
@ -76,18 +75,17 @@ void Standard_MMgrTBBalloc::Free(Standard_Address& aStorage)
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Address Standard_MMgrTBBalloc::Reallocate(Standard_Address& aStorage, Standard_Address Standard_MMgrTBBalloc::Reallocate (Standard_Address theStorage,
const Standard_Size newSize) const Standard_Size theSize)
{ {
// the size is rounded up to 4 since some OCC classes // the size is rounded up to 4 since some OCC classes
// (e.g. TCollection_AsciiString) assume memory to be double word-aligned // (e.g. TCollection_AsciiString) assume memory to be double word-aligned
const Standard_Size aRoundSize = (newSize + 3) & ~0x3; const Standard_Size aRoundSize = (theSize + 3) & ~0x3;
Standard_Address newStorage = (Standard_Address)scalable_realloc(aStorage, aRoundSize); Standard_Address newStorage = (Standard_Address)scalable_realloc(theStorage, aRoundSize);
if ( ! newStorage ) if ( ! newStorage )
Standard_OutOfMemory::Raise("Standard_MMgrTBBalloc::Reallocate(): realloc failed"); Standard_OutOfMemory::Raise("Standard_MMgrTBBalloc::Reallocate(): realloc failed");
// Note that it is not possible to ensure that additional memory // Note that it is not possible to ensure that additional memory
// allocated by realloc will be cleared (so as to satisfy myClear mode); // allocated by realloc will be cleared (so as to satisfy myClear mode);
// in order to do that we would need using memset... // in order to do that we would need using memset...
aStorage = NULL;
return newStorage; return newStorage;
} }

View File

@ -47,12 +47,12 @@ class Standard_MMgrTBBalloc : public Standard_MMgrRoot
Standard_EXPORT virtual Standard_Address Allocate(const Standard_Size aSize); Standard_EXPORT virtual Standard_Address Allocate(const Standard_Size aSize);
//! Reallocate aPtr to the size aSize. //! Reallocate aPtr to the size aSize.
//! The pointer aPtr is nullified; new pointer is returned. //! The new pointer is returned.
Standard_EXPORT virtual Standard_Address Reallocate(Standard_Address& aPtr, Standard_EXPORT virtual Standard_Address Reallocate (Standard_Address thePtr,
const Standard_Size aSize); const Standard_Size theSize);
//! Free allocated memory. The pointer is nullified. //! Free allocated memory
Standard_EXPORT virtual void Free(Standard_Address&); Standard_EXPORT virtual void Free (Standard_Address thePtr);
protected: protected:
Standard_Boolean myClear; //! Option to nullify allocated memory Standard_Boolean myClear; //! Option to nullify allocated memory

View File

@ -70,7 +70,7 @@ typedef NCollection_DataMap <TCollection_AsciiString,
// //
Storage_Bucket::~Storage_Bucket() Storage_Bucket::~Storage_Bucket()
{ {
Standard::Free((Standard_Address&)mySpace); Standard::Free (mySpace);
mySpace = 0L; mySpace = 0L;
mySpaceSize = 0; mySpaceSize = 0;
Clear(); Clear();
@ -150,7 +150,7 @@ Storage_BucketOfPersistent::~Storage_BucketOfPersistent()
{ {
Clear(); Clear();
delete myBuckets[0]; delete myBuckets[0];
Standard::Free((Standard_Address&)myBuckets); Standard::Free (myBuckets);
myBuckets = 0L; myBuckets = 0L;
} }
@ -191,7 +191,7 @@ void Storage_BucketOfPersistent::Append(const Handle(Standard_Persistent)& sp)
if (myNumberOfBucket > myNumberOfBucketAllocated) { if (myNumberOfBucket > myNumberOfBucketAllocated) {
Standard_Size e = sizeof(Storage_Bucket*) * myNumberOfBucketAllocated; Standard_Size e = sizeof(Storage_Bucket*) * myNumberOfBucketAllocated;
myBuckets = (Storage_Bucket**)Standard::Reallocate((Standard_Address&)myBuckets, e * 2); myBuckets = (Storage_Bucket**)Standard::Reallocate(myBuckets, e * 2);
myNumberOfBucketAllocated *= 2; myNumberOfBucketAllocated *= 2;
} }

View File

@ -120,7 +120,7 @@ void TCollection_Array2::Destroy ()
delete [] &ChangeValue(myLowerRow,myLowerColumn); delete [] &ChangeValue(myLowerRow,myLowerColumn);
// delete the indirection table // delete the indirection table
Standard::Free((void*&)anItemPtr); Standard::Free (anItemPtr);
} }
//======================================================================= //=======================================================================

View File

@ -288,7 +288,7 @@ void TCollection_ExtendedString::AssignCat
Standard_ExtString sother = other.mystring; Standard_ExtString sother = other.mystring;
Standard_Integer newlength = mylength + otherlength; Standard_Integer newlength = mylength + otherlength;
if (mystring) { if (mystring) {
mystring = Reallocate((void*&)mystring, (newlength+1)*2 ); mystring = Reallocate(mystring, (newlength+1)*2 );
memcpy( mystring + mylength, sother, (otherlength+1)*2 ); memcpy( mystring + mylength, sother, (otherlength+1)*2 );
} }
else { else {
@ -328,7 +328,7 @@ void TCollection_ExtendedString::ChangeAll(const Standard_ExtCharacter aChar,
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void TCollection_ExtendedString::Clear() void TCollection_ExtendedString::Clear()
{ {
if (mystring) Standard::Free((void*&)mystring); if (mystring) Standard::Free(mystring);
// mystring = 0L; // mystring = 0L;
mylength = 0; mylength = 0;
mystring = Allocate((mylength+1)*2); mystring = Allocate((mylength+1)*2);
@ -345,7 +345,7 @@ void TCollection_ExtendedString::Copy (const TCollection_ExtendedString& fromwhe
const Standard_Integer newlength = fromwhere.mylength; const Standard_Integer newlength = fromwhere.mylength;
const Standard_Integer size = (newlength + 1) * 2; const Standard_Integer size = (newlength + 1) * 2;
if (mystring) { if (mystring) {
mystring = Reallocate((void*&)mystring, size ); mystring = Reallocate(mystring, size );
} }
else { else {
mystring = Allocate( size ); mystring = Allocate( size );
@ -366,7 +366,7 @@ void TCollection_ExtendedString::Copy (const TCollection_ExtendedString& fromwhe
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void TCollection_ExtendedString::Destroy() void TCollection_ExtendedString::Destroy()
{ {
if (mystring) Standard::Free((void*&)mystring); if (mystring) Standard::Free(mystring);
mystring = 0L; mystring = 0L;
} }
@ -384,8 +384,7 @@ void TCollection_ExtendedString::Insert(const Standard_Integer where,
"Parameter where is negative"); "Parameter where is negative");
if (mystring) { if (mystring) {
mystring = Reallocate((void*&)mystring, mystring = Reallocate(mystring, (mylength+2)*2);
(mylength+2)*2);
} }
else { else {
mystring = Allocate((mylength+2)*2); mystring = Allocate((mylength+2)*2);
@ -412,8 +411,7 @@ void TCollection_ExtendedString::Insert(const Standard_Integer where,
Standard_Integer newlength = mylength + whatlength; Standard_Integer newlength = mylength + whatlength;
if (mystring) { if (mystring) {
mystring = Reallocate( mystring = Reallocate(mystring,(newlength+1)*2);
(void*&)mystring,(newlength+1)*2);
} }
else { else {
mystring = Allocate((newlength+1)*2); mystring = Allocate((newlength+1)*2);
@ -656,7 +654,7 @@ void TCollection_ExtendedString::SetValue
size += (where - 1); size += (where - 1);
if (size >= mylength){ if (size >= mylength){
if (mystring) { if (mystring) {
mystring = Reallocate ((void*&)mystring,(size+1)*2); mystring = Reallocate (mystring,(size+1)*2);
} }
else { else {
mystring = Allocate((size+1)*2); mystring = Allocate((size+1)*2);
@ -754,10 +752,10 @@ TCollection_ExtendedString TCollection_ExtendedString::Token
if (i < whichone) { if (i < whichone) {
buftmp[0] = 0; buftmp[0] = 0;
Standard::Free((void*&)buftmp); Standard::Free(buftmp);
} }
else { else {
Standard::Free((void*&)res.mystring); Standard::Free(res.mystring);
res.mystring = buftmp; res.mystring = buftmp;
for ( res.mylength=0; buftmp[res.mylength]; ++res.mylength ); for ( res.mylength=0; buftmp[res.mylength]; ++res.mylength );
} }
@ -914,9 +912,5 @@ Standard_PExtCharacter Allocate(const Standard_Size aLength)
Standard_PExtCharacter Reallocate(Standard_Address aAddr, Standard_PExtCharacter Reallocate(Standard_Address aAddr,
const Standard_Size aLength) const Standard_Size aLength)
{ {
Standard_PExtCharacter pChar; return (Standard_PExtCharacter)Standard::Reallocate(aAddr, aLength);
//
pChar= (Standard_PExtCharacter)Standard::Reallocate(aAddr, aLength);
//
return pChar;
} }

View File

@ -174,7 +174,7 @@ void TopExp_Explorer::Next()
new (&newStack[i]) TopoDS_Iterator(myStack[i]); new (&newStack[i]) TopoDS_Iterator(myStack[i]);
myStack[i].~TopoDS_Iterator(); myStack[i].~TopoDS_Iterator();
} }
Standard::Free((Standard_Address&)myStack); Standard::Free(myStack);
mySizeOfStack = NewSize; mySizeOfStack = NewSize;
myStack = newStack; myStack = newStack;
} }
@ -200,7 +200,7 @@ void TopExp_Explorer::Next()
new (&newStack[i]) TopoDS_Iterator(myStack[i]); new (&newStack[i]) TopoDS_Iterator(myStack[i]);
myStack[i].~TopoDS_Iterator(); myStack[i].~TopoDS_Iterator();
} }
Standard::Free((Standard_Address&)myStack); Standard::Free(myStack);
mySizeOfStack = NewSize; mySizeOfStack = NewSize;
myStack = newStack; myStack = newStack;
} }
@ -239,7 +239,7 @@ void TopExp_Explorer::Destroy()
if (myStack) if (myStack)
{ {
for(int i=0;i<= myTop; i++)myStack[i].~TopoDS_Iterator(); for(int i=0;i<= myTop; i++)myStack[i].~TopoDS_Iterator();
Standard::Free((Standard_Address&)myStack); Standard::Free(myStack);
} }
mySizeOfStack = 0; mySizeOfStack = 0;
myStack = 0L; myStack = 0L;

View File

@ -204,7 +204,7 @@ Standard_Boolean XmlObjMgt::GetTagEntryString
} }
aTagEntryPtr[0] = '\0'; aTagEntryPtr[0] = '\0';
theTagEntry = aTagEntry; theTagEntry = aTagEntry;
Standard::Free ((Standard_Address&)aTagEntry); Standard::Free (aTagEntry);
return Standard_True; return Standard_True;
} }
@ -259,7 +259,7 @@ void XmlObjMgt::SetTagEntryString (XmlObjMgt_DOMString& theTarget,
} }
* aTargetPtr = '\0'; * aTargetPtr = '\0';
theTarget = aTarget; theTarget = aTarget;
Standard::Free ((Standard_Address&)aTarget); Standard::Free (aTarget);
} }
//======================================================================= //=======================================================================