[svn-r26731] Purpose: Fixed HDFFV-7947
Description:
When copy constructor or constructor that takes an existing id is invoked,
the C ref counter stays the same but there is an extra C++ object which
later is destroyed and may cause the HDF5 id to be closed prematurely. The
C++ library needs to increment the ref counter in these situations, so that
the C library will not close the id when it is still being referenced.
However, the incrementing of ref count left some objects opened at the end
of the program, perhaps, due to compiler's optimization on cons/destructors. The constructor, that takes an existing id, needs to increment the counter
but it seems that the matching destructor wasn't invoked. The workaround
is to have a function for each class that has "id" that only sets the id
and not increment the ref count for the library to use in these situations.
These functions are "friend" and not public.
The friend functions are:
void f_Attribute_setId(Attribute *, hid_t)
void f_DataSet_setId(DataSet *, hid_t)
void f_DataSpace_setId(DataSpace *, hid_t)
void f_DataType_setId(DataType *, hid_t)
Merged from trunk: r26655
Platforms tested:
Linux/64 (platypus)
Linux/32 2.6 (jam Intel 15.0)
SunOS 5.11 (emu)
This commit is contained in:
@@ -30,6 +30,7 @@ namespace H5 {
|
||||
*/
|
||||
class H5_DLLCPP DataSet : public H5Object, public AbstractDs {
|
||||
public:
|
||||
|
||||
// Close this dataset.
|
||||
virtual void close();
|
||||
|
||||
@@ -107,6 +108,12 @@ class H5_DLLCPP DataSet : public H5Object, public AbstractDs {
|
||||
// Destructor: properly terminates access to this dataset.
|
||||
virtual ~DataSet();
|
||||
|
||||
protected:
|
||||
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
||||
// Sets the dataset id.
|
||||
virtual void p_setId(const hid_t new_id);
|
||||
#endif // DOXYGEN_SHOULD_SKIP_THIS
|
||||
|
||||
private:
|
||||
hid_t id; // HDF5 dataset id
|
||||
|
||||
@@ -120,11 +127,9 @@ class H5_DLLCPP DataSet : public H5Object, public AbstractDs {
|
||||
void p_read_fixed_len(const hid_t mem_type_id, const hid_t mem_space_id, const hid_t file_space_id, const hid_t xfer_plist_id, H5std_string& strg) const;
|
||||
void p_read_variable_len(const hid_t mem_type_id, const hid_t mem_space_id, const hid_t file_space_id, const hid_t xfer_plist_id, H5std_string& strg) const;
|
||||
|
||||
protected:
|
||||
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
||||
// Sets the dataset id.
|
||||
virtual void p_setId(const hid_t new_id);
|
||||
#endif // DOXYGEN_SHOULD_SKIP_THIS
|
||||
// Friend function to set DataSet id. For library use only.
|
||||
friend void f_DataSet_setId(DataSet* dset, hid_t new_id);
|
||||
|
||||
};
|
||||
#ifndef H5_NO_NAMESPACE
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user