[svn-r12368] Purpose: Fixed bug

Description:
    Shanti compiler destroy unnamed objects later than others, which caused
    some reference counting test fail.  Revised the test so that destructors
    are called at the same time, regardless the differences of compiler
    implementation.

    Revised some constructors, close, operator=, and destructors to make
    sure that all the object ids are handled properly.

Platforms tested:
    Linux 2.4 (heping)
    SunOS 5.9 (shanti)
    HPUX 11.00 (kelgia)
    AIX 5.1 (copper)
This commit is contained in:
Binh-Minh Ribler
2006-05-23 12:59:40 -05:00
parent d0f565c5c0
commit deec486732
10 changed files with 164 additions and 161 deletions

View File

@@ -46,7 +46,7 @@ const DataSpace DataSpace::ALL( H5S_ALL );
///\exception H5::DataSpaceIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
DataSpace::DataSpace( H5S_class_t type ) : IdComponent()
DataSpace::DataSpace( H5S_class_t type ) : IdComponent(0)
{
id = H5Screate( type );
if( id < 0 )
@@ -64,7 +64,7 @@ DataSpace::DataSpace( H5S_class_t type ) : IdComponent()
///\exception H5::DataSpaceIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
DataSpace::DataSpace( int rank, const hsize_t * dims, const hsize_t * maxdims) : IdComponent()
DataSpace::DataSpace( int rank, const hsize_t * dims, const hsize_t * maxdims) : IdComponent(0)
{
id = H5Screate_simple( rank, dims, maxdims );
if( id < 0 )
@@ -103,16 +103,15 @@ DataSpace::DataSpace( const DataSpace& original ) : IdComponent( original ) {}
//--------------------------------------------------------------------------
void DataSpace::copy( const DataSpace& like_space )
{
// If this object has a valid id, appropriately decrement reference
// counter and close the id.
// If this object has an hdf5 valid id, close it
if( id != H5S_ALL ) {
try {
decRefCount();
close();
}
catch (Exception close_error) {
throw DataSpaceIException("DataSpace::copy", close_error.getDetailMsg());
}
} // if
} // end if
// call C routine to copy the dataspace
id = H5Scopy( like_space.getId() );
@@ -134,8 +133,11 @@ void DataSpace::copy( const DataSpace& like_space )
//--------------------------------------------------------------------------
DataSpace& DataSpace::operator=( const DataSpace& rhs )
{
copy(rhs);
return(*this);
if (this != &rhs)
{
copy(rhs);
return(*this);
}
}
//--------------------------------------------------------------------------
@@ -553,18 +555,17 @@ void DataSpace::selectHyperslab( H5S_seloper_t op, const hsize_t *count, const h
//--------------------------------------------------------------------------
void DataSpace::close()
{
if( id != H5S_ALL ) // not a constant, should call H5Sclose
{
herr_t ret_value = H5Sclose(id);
if( ret_value < 0 )
{
throw DataSpaceIException("DataSpace::close", "H5Sclose failed");
}
// reset the id because the dataspace that it represents is now closed
id = 0;
}
else // cannot close a constant
throw DataSpaceIException("DataSpace::close", "Cannot close a constant");
// check if id is a valid hdf5 object id before trying to close it
if (p_valid_id(id))
{
herr_t ret_value = H5Sclose(id);
if( ret_value < 0 )
{
throw DataSpaceIException("DataSpace::close", "H5Sclose failed");
}
// reset the id because the dataspace that it represents is now closed
id = 0;
}
}
//--------------------------------------------------------------------------
@@ -577,16 +578,12 @@ void DataSpace::close()
//--------------------------------------------------------------------------
DataSpace::~DataSpace()
{
// If this object has a valid id, appropriately decrement reference
// counter and close the id.
if( id != H5S_ALL ) {
try {
decRefCount();
}
catch (Exception close_error) {
cerr << "DataSpace::~DataSpace - " << close_error.getDetailMsg() << endl;
}
} // if
try {
close();
}
catch (Exception close_error) {
cerr << "DataSpace::~DataSpace - " << close_error.getDetailMsg() << endl;
}
}
#ifndef H5_NO_NAMESPACE