summaryrefslogtreecommitdiffstats
path: root/c++/src/H5IdComponent.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/H5IdComponent.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/H5IdComponent.cpp')
-rw-r--r--c++/src/H5IdComponent.cpp75
1 files changed, 34 insertions, 41 deletions
diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp
index d0c60a4..5f56324 100644
--- a/c++/src/H5IdComponent.cpp
+++ b/c++/src/H5IdComponent.cpp
@@ -43,8 +43,8 @@ IdComponent::IdComponent(const hid_t h5_id) : id(h5_id) {}
//--------------------------------------------------------------------------
IdComponent::IdComponent( const IdComponent& original )
{
- id = original.id;
- incRefCount(); // increment number of references to this id
+ id = original.id;
+ incRefCount(); // increment number of references to this id
}
//--------------------------------------------------------------------------
@@ -80,6 +80,7 @@ void IdComponent::incRefCount() const
void IdComponent::decRefCount(const hid_t obj_id) const
{
if (p_valid_id(obj_id))
+ {
if (H5Idec_ref(obj_id) < 0)
if (H5Iget_ref(obj_id) <= 0)
throw IdComponentException(inMemFunc("decRefCount"),
@@ -87,6 +88,7 @@ void IdComponent::decRefCount(const hid_t obj_id) const
else
throw IdComponentException(inMemFunc("decRefCount"),
"decrementing object ref count failed");
+ }
}
//--------------------------------------------------------------------------
@@ -112,7 +114,7 @@ int IdComponent::getCounter(const hid_t obj_id) const
{
counter = H5Iget_ref(obj_id);
if (counter < 0)
- throw IdComponentException(inMemFunc("incRefCount"), "incrementing object ref count failed");
+ throw IdComponentException(inMemFunc("incRefCount"), "getting object ref count failed - negative");
}
return (counter);
}
@@ -168,16 +170,23 @@ H5I_type_t IdComponent::getHDFObjType(const hid_t obj_id)
//--------------------------------------------------------------------------
IdComponent& IdComponent::operator=( const IdComponent& rhs )
{
- // handling references to this id
- decRefCount();
-
- // copy the data members from the rhs object
- id = rhs.id;
-
- // increment the reference counter
- incRefCount();
-
- return( *this );
+ if (this != &rhs)
+ {
+ // handling references to this id
+ try {
+ close();
+ }
+ catch (Exception close_error) {
+ throw FileIException(inMemFunc("operator="), close_error.getDetailMsg());
+ }
+
+ // copy the data members from the rhs object
+ id = rhs.id;
+
+ // increment the reference counter
+ incRefCount();
+ }
+ return *this;
}
//--------------------------------------------------------------------------
@@ -194,11 +203,19 @@ IdComponent& IdComponent::operator=( const IdComponent& rhs )
//--------------------------------------------------------------------------
void IdComponent::setId(const hid_t new_id)
{
- // handling references to this id
- decRefCount();
+ // handling references to this old id
+ try {
+ close();
+ }
+ catch (Exception close_error) {
+ throw IdComponentException(inMemFunc("copy"), close_error.getDetailMsg());
+ }
// reset object's id to the given id
id = new_id;
+
+ // increment the reference counter of the new id
+ incRefCount();
}
//--------------------------------------------------------------------------
@@ -209,7 +226,7 @@ void IdComponent::setId(const hid_t new_id)
//--------------------------------------------------------------------------
hid_t IdComponent::getId () const
{
- return( id );
+ return(id);
}
//--------------------------------------------------------------------------
@@ -217,31 +234,7 @@ hid_t IdComponent::getId () const
///\brief Noop destructor.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-IdComponent::~IdComponent() {
-
-/* uncomment this block and complete it when deciding to use dontAtExit
- unless the atexit/global destructor problem is fixed, then
- remove it- BMR 11/14/00
-
- if( id == NOTATEXIT )
- {
- // Call H5Library::close to clean up - temporary solution to avoid the
- // trouble of atexit/global destructors
- try {
- if( H5Library::need_cleanup == true )
- {
- H5Library::close();
- H5Library::need_cleanup = false; // reset the boolean just in case
- }
- }
- // catch failure caused by the H5Library operations
- catch( LibraryIException error )
- {
- error.printError();
- }
- }
-*/
-}
+IdComponent::~IdComponent() {}
//
// Implementation of protected functions for HDF5 Reference Interface.