summaryrefslogtreecommitdiffstats
path: root/c++/src/H5DataSpace.cpp
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2006-05-23 17:59:40 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2006-05-23 17:59:40 (GMT)
commitdeec486732b7c8646cc0a2614a62b85fff336fe0 (patch)
treee2c2b4e6a939ed9aabb75b684dfdd89b9f84e148 /c++/src/H5DataSpace.cpp
parentd0f565c5c0370424ac78a127f31a60396d280b95 (diff)
downloadhdf5-deec486732b7c8646cc0a2614a62b85fff336fe0.zip
hdf5-deec486732b7c8646cc0a2614a62b85fff336fe0.tar.gz
hdf5-deec486732b7c8646cc0a2614a62b85fff336fe0.tar.bz2
[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)
Diffstat (limited to 'c++/src/H5DataSpace.cpp')
-rw-r--r--c++/src/H5DataSpace.cpp57
1 files changed, 27 insertions, 30 deletions
diff --git a/c++/src/H5DataSpace.cpp b/c++/src/H5DataSpace.cpp
index c7a098f..e786144 100644
--- a/c++/src/H5DataSpace.cpp
+++ b/c++/src/H5DataSpace.cpp
@@ -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