diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2012-03-30 19:34:20 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2012-03-30 19:34:20 (GMT) |
commit | 56d950d3264aae3d935854470a9178a333614bff (patch) | |
tree | e74485f6148c1c598b9961556820f7ddec7444f3 | |
parent | 7f7b8bd9725854fc8b546bcde3252f2c8d5c5d32 (diff) | |
download | hdf5-56d950d3264aae3d935854470a9178a333614bff.zip hdf5-56d950d3264aae3d935854470a9178a333614bff.tar.gz hdf5-56d950d3264aae3d935854470a9178a333614bff.tar.bz2 |
[svn-r22209] Purpose: Fixed bugs HDFFV-2761 & HDFFV-7852
Description:
- Replaced PredType::NotAtexit() with PredType::AtExit(H5CPP_EXITED)
and used PredType::AtExit as a flag to detect when all predefined
types have been destroyed. Then, H5close will be called to terminate
the library after its being re-initiated when the PredType destructors
were activated. This change removed the memory leaks shown by the
user's sample program in HDFFV-2761.
- Added H5CPP_EXITED for PredType::AtExit to use as a flag
- Rearranged constructors in CompType to fix bug HDFFV-7852
- Updated some inaccurate comments
- Removed stream functions from FileAccPropList
- Replaced H5_VMS with appropriate macro in H5IdComponent.cpp
Platforms tested:
Linux/32 2.6 (jam)
Linux/64 2.6 (amani)
SunOS 5.10 (linew)
-rw-r--r-- | c++/src/H5CommonFG.cpp | 4 | ||||
-rw-r--r-- | c++/src/H5CompType.h | 18 | ||||
-rw-r--r-- | c++/src/H5DataType.cpp | 38 | ||||
-rw-r--r-- | c++/src/H5FaccProp.cpp | 47 | ||||
-rw-r--r-- | c++/src/H5File.cpp | 8 | ||||
-rw-r--r-- | c++/src/H5IdComponent.cpp | 8 | ||||
-rw-r--r-- | c++/src/H5Object.cpp | 8 | ||||
-rw-r--r-- | c++/src/H5PredType.cpp | 8 | ||||
-rw-r--r-- | c++/src/H5PredType.h | 15 |
9 files changed, 72 insertions, 82 deletions
diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp index 2c6951c..6a8609f 100644 --- a/c++/src/H5CommonFG.cpp +++ b/c++/src/H5CommonFG.cpp @@ -322,7 +322,7 @@ void CommonFG::unlink( const H5std_string& name ) const ///\note /// Exercise care in moving groups as it is possible to render /// data in a file inaccessible with Group::move. Please refer -/// to the Group Interface in the HDF5 User's Guide at: +/// to the Group Interface in the HDF5 User's Guide for details at: /// http://www.hdfgroup.org/HDF5/doc/UG/UG_frame09Groups.html // Programmer Binh-Minh Ribler - 2000 // Modification @@ -1073,7 +1073,7 @@ ssize_t CommonFG::getObjnameByIdx(hsize_t idx, char* name, size_t size) const // Function: CommonFG::getObjnameByIdx ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an -/// \c std::string for \a name. +/// \c H5std_string for \a name. // Programmer Binh-Minh Ribler - January, 2003 //-------------------------------------------------------------------------- ssize_t CommonFG::getObjnameByIdx(hsize_t idx, H5std_string& name, size_t size) const diff --git a/c++/src/H5CompType.h b/c++/src/H5CompType.h index 04b6b1f..2336bd1 100644 --- a/c++/src/H5CompType.h +++ b/c++/src/H5CompType.h @@ -26,12 +26,21 @@ namespace H5 { class H5_DLLCPP CompType : public DataType { public: + // Default constructor + CompType(); + + // Creates a compound datatype using an existing id + CompType( const hid_t existing_id ); + // Creates a new compound datatype, given the type's size CompType( size_t size ); // H5Tcreate // Gets the compound datatype of the specified dataset CompType( const DataSet& dataset ); // H5Dget_type + // Copy constructor - makes a copy of original object + CompType( const CompType& original ); + // Returns the type class of the specified member of this compound // datatype. It provides to the user a way of knowing what type // to create another datatype of the same class @@ -91,15 +100,6 @@ class H5_DLLCPP CompType : public DataType { ///\brief Returns this class name virtual H5std_string fromClass () const { return("CompType"); } - // Default constructor - CompType(); - - // Creates a compound datatype using an existing id - CompType( const hid_t existing_id ); - - // Copy constructor - makes a copy of original object - CompType( const CompType& original ); - // Noop destructor. virtual ~CompType(); diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index 6e894dc..3edb163 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -54,12 +54,12 @@ namespace H5 { ///\param existing_id - IN: Id of the existing datatype // Description // Constructor creates a copy of an existing DataType using -// its id. The argument "predefined" is default to false; -// when a default datatype is created, this argument is set -// to true so H5Tclose will not be called on it later. - need -// a reassessment after changing to the new ref counting mech. -// - BMR 5/2004 +// its id. // Programmer Binh-Minh Ribler - 2000 +// Modification +// Dec, 2005 +// Removed second argument, "predefined", after changing to the +// new ref counting mechanism that relies on C's ref counting. //-------------------------------------------------------------------------- DataType::DataType(const hid_t existing_id) : H5Object() { @@ -792,17 +792,33 @@ void DataType::close() // Programmer Binh-Minh Ribler - 2000 // Modification // - Replaced resetIdComponent() with decRefCount() to use C -// library ID reference counting mechanism - BMR, Jun 1, 2004 +// library ID reference counting mechanism - BMR, Jun 1, 2004 // - Replaced decRefCount with close() to let the C library -// handle the reference counting - BMR, Jun 1, 2006 +// handle the reference counting - BMR, Jun 1, 2006 +// - Added the use of H5CPP_EXITED to terminate the HDF5 library +// and elimiate previous memory leaks. See comments in the +// header file "H5PredType.h" for details. - BMR, Mar 30, 2012 //-------------------------------------------------------------------------- DataType::~DataType() { - try { - close(); - } catch (Exception close_error) { - cerr << inMemFunc("~DataType - ") << close_error.getDetailMsg() << endl; + try + { + /* If this is the object AtExit, terminate the HDF5 library. This is + to eliminate memory leaks due to the library being re-initiated + (after the program has ended) and not re-terminated. */ + if (id == H5CPP_EXITED) + { + herr_t ret_value = H5close(); + if (ret_value == FAIL) + throw DataTypeIException(inMemFunc("~DataType - "), "H5close failed"); } + // Close the HDF5 datatype + else + close(); + } + catch (Exception close_error) { + cerr << inMemFunc("~DataType - ") << close_error.getDetailMsg() << endl; + } } #ifndef H5_NO_NAMESPACE } // end namespace diff --git a/c++/src/H5FaccProp.cpp b/c++/src/H5FaccProp.cpp index 89e3315..4fb3836 100644 --- a/c++/src/H5FaccProp.cpp +++ b/c++/src/H5FaccProp.cpp @@ -292,50 +292,9 @@ void FileAccPropList::setSplit( FileAccPropList& meta_plist, FileAccPropList& ra setSplit( meta_plist, raw_plist, meta_ext.c_str(), raw_ext.c_str() ); } -#ifdef H5_HAVE_STREAM // for Stream Virtual File Driver -//-------------------------------------------------------------------------- -// Function: FileAccPropList::getStream -// Purpose: Retrieves the streaming I/O driver settings -// Return: The streaming I/O file access property list structure -// Exception: H5::PropListIException -// Description: -// This C API seems to be removed from the library; will remove -// this wrapper next time, only removed it from the RM in this -// release - Oct, 2008 -// Programmer: Binh-Minh Ribler - April, 2004 -//-------------------------------------------------------------------------- -H5FD_stream_fapl_t FileAccPropList::getStream() const -{ - H5FD_stream_fapl_t fapl; - herr_t ret_value = H5Pget_fapl_stream(id, &fapl); - if( ret_value < 0 ) - { - throw PropListIException("FileAccPropList::getStream", "H5Pget_fapl_stream failed"); - } - return(fapl); -} - -//-------------------------------------------------------------------------- -// Function: FileAccPropList::setStream -// Purpose: Modifies this file access property list to use the Stream -// driver. -// Param: fapl - IN: The streaming I/O file access property list -// Exception: H5::PropListIException -// Description: -// This C API seems to be removed from the library; will remove -// this wrapper next time, only removed it from the RM in this -// release - Oct, 2008 -// Programmer: Binh-Minh Ribler - April, 2004 -//-------------------------------------------------------------------------- -void FileAccPropList::setStream(H5FD_stream_fapl_t &fapl) const -{ - herr_t ret_value = H5Pset_fapl_stream (id, &fapl); - if( ret_value < 0 ) - { - throw PropListIException("FileAccPropList::setStream", "H5Pset_fapl_stream failed"); - } -} -#endif // Stream Virtual File Driver +// Stream Virtual File Driver had been removed from the main library. +// FileAccPropList::[s,g]etStream are now removed from the C++ API. +// -BMR, March, 2012 //-------------------------------------------------------------------------- // Function: FileAccPropList::getSieveBufSize diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp index e60d90d..da0241f 100644 --- a/c++/src/H5File.cpp +++ b/c++/src/H5File.cpp @@ -512,8 +512,8 @@ H5std_string H5File::getFileName() const ///\brief Retrieves the type of object that an object reference points to. ///\param ref - IN: Reference to query ///\param ref_type - IN: Type of reference, valid values are: -/// \li \c H5R_OBJECT - Reference is an object reference. -/// \li \c H5R_DATASET_REGION - Reference is a dataset region reference. +/// \li \c H5R_OBJECT - Reference is an object reference +/// \li \c H5R_DATASET_REGION - Reference is a dataset region reference ///\return Object type, which can be one of the following: /// \li \c H5G_LINK - Object is a symbolic link. /// \li \c H5G_GROUP - Object is a group. @@ -600,9 +600,9 @@ void H5File::p_reference(void* ref, const char* name, hid_t space_id, H5R_type_t ///\param name - IN: Name of the object to be referenced ///\param dataspace - IN: Dataspace with selection ///\param ref_type - IN: Type of reference to query, valid values are: -/// \li \c H5R_OBJECT - Reference is an object reference. +/// \li \c H5R_OBJECT - Reference is an object reference /// \li \c H5R_DATASET_REGION - Reference is a dataset region -/// reference. - this is the default +/// reference - this is the default ///\exception H5::IdComponentException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp index 8124ab0..9f96277 100644 --- a/c++/src/H5IdComponent.cpp +++ b/c++/src/H5IdComponent.cpp @@ -13,11 +13,13 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifdef H5_VMS +#ifdef OLD_HEADER_FILENAME +#include <iostream.h> +#else #include <iostream> -#endif /*H5_VMS*/ - +#endif #include <string> + #include "H5Include.h" #include "H5Exception.h" #include "H5Library.h" diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index d5fa62d..225975b 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -201,7 +201,7 @@ Attribute H5Object::openAttribute( const unsigned int idx ) const ///\exception H5::AttributeIException ///\par Description /// The signature of user_op is -/// void (*)(H5::H5Object&, std::string, void*). +/// void (*)(H5::H5Object&, H5std_string, void*). /// For information, please refer to the C layer Reference Manual /// at: /// http://www.hdfgroup.org/HDF5/doc/RM/RM_H5A.html#Annot-Iterate @@ -368,9 +368,9 @@ void H5Object::p_reference(void* ref, const char* name, hid_t space_id, H5R_type ///\param name - IN: Name of the object to be referenced ///\param dataspace - IN: Dataspace with selection ///\param ref_type - IN: Type of reference to query, valid values are: -/// \li \c H5R_OBJECT - Reference is an object reference. -/// \li \c H5R_DATASET_REGION - Reference is a dataset region -/// reference. - this is the default +/// \li \c H5R_OBJECT - Reference is an object reference. +/// \li \c H5R_DATASET_REGION - Reference is a dataset region +/// reference. - this is the default ///\exception H5::IdComponentException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- diff --git a/c++/src/H5PredType.cpp b/c++/src/H5PredType.cpp index 347f02f..9dfc760 100644 --- a/c++/src/H5PredType.cpp +++ b/c++/src/H5PredType.cpp @@ -44,7 +44,10 @@ namespace H5 { //-------------------------------------------------------------------------- PredType::PredType( const hid_t predtype_id ) : AtomType( predtype_id ) { - id = H5Tcopy(predtype_id); + if (predtype_id == H5CPP_EXITED) + id = predtype_id; + else + id = H5Tcopy(predtype_id); } //-------------------------------------------------------------------------- @@ -62,7 +65,8 @@ PredType::PredType() : AtomType() {} //-------------------------------------------------------------------------- PredType::PredType( const PredType& original ) : AtomType( original ) {} -const PredType PredType::NotAtexit; // only for atexit/global dest. problem +// Flag to terminate HDF5 library in DataType::~DataType +const PredType PredType::AtExit(H5CPP_EXITED); // Definition of pre-defined types const PredType PredType::C_S1( H5T_C_S1 ); diff --git a/c++/src/H5PredType.h b/c++/src/H5PredType.h index 5b2fffb..9cb1c65 100644 --- a/c++/src/H5PredType.h +++ b/c++/src/H5PredType.h @@ -26,6 +26,14 @@ namespace H5 { #endif +/* This constant is defined for a workaround to eliminate memory leaks due to + the library being re-initiated when PredType destructors are invoked. A + PredType instant with H5CPP_EXITED as the value of its "id" is constructed + before the other PredType objects are created. At exit, when this special + PredType object is to be destructed, no HDF5 library function will be called + and the library will be terminated. -BMR, Mar 30, 2012 */ +#define H5CPP_EXITED -3 // -3 is less likely to be used elsewhere + class H5_DLLCPP PredType : public AtomType { public: ///\brief Returns this class name @@ -229,9 +237,10 @@ class H5_DLLCPP PredType : public AtomType { #endif // DOXYGEN_SHOULD_SKIP_THIS private: - // added this to work around the atexit/global destructor problem - // temporarily - it'll prevent the use of atexit to clean up - static const PredType NotAtexit; // not working yet + // Added this to work around the atexit/global destructor problem. + // It'll help to terminate the library after other PredType instances + // are closed. -BMR, Mar 30, 2012 + static const PredType AtExit; protected: #ifndef DOXYGEN_SHOULD_SKIP_THIS |