diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2015-04-06 03:52:35 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2015-04-06 03:52:35 (GMT) |
commit | 2a2a79742dc2ee154b7571a518b97413599b29a6 (patch) | |
tree | cda2e53402608cdf22eb2be41d27c6bb63c32ad9 /c++/test | |
parent | 150b85cc44903c005009552d692da50a4aa6c86f (diff) | |
download | hdf5-2a2a79742dc2ee154b7571a518b97413599b29a6.zip hdf5-2a2a79742dc2ee154b7571a518b97413599b29a6.tar.gz hdf5-2a2a79742dc2ee154b7571a518b97413599b29a6.tar.bz2 |
[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)
Diffstat (limited to 'c++/test')
-rw-r--r-- | c++/test/tattr.cpp | 16 | ||||
-rw-r--r-- | c++/test/ttypes.cpp | 21 |
2 files changed, 25 insertions, 12 deletions
diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index c604637..275a287 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -741,12 +741,26 @@ static void test_attr_compound_read() // Verify name H5std_string attr_name = attr.getName(); verify_val(attr_name, ATTR4_NAME, "Attribute::getName", __LINE__, __FILE__); - PASSED(); } // end try block catch (Exception E) { issue_fail_msg("test_attr_compound_read()", __LINE__, __FILE__, E.getCDetailMsg()); } + + try + { + // Now, try truncating the file to make sure reference counting is good. + // If any references to ids in the previous block are left unterminated, + // the truncating will fail, because the file will not be closed in + // the file.close() above. + H5File file1(FILE_COMPOUND, H5F_ACC_TRUNC); + + PASSED(); + } // end try block + + catch (FileIException E) { + issue_fail_msg("test_attr_compound_read()", __LINE__, __FILE__, "Unable to truncate file, possibly because some objects are left opened"); + } } // test_attr_compound_read() /**************************************************************** diff --git a/c++/test/ttypes.cpp b/c++/test/ttypes.cpp index 39f14a4..9f85613 100644 --- a/c++/test/ttypes.cpp +++ b/c++/test/ttypes.cpp @@ -280,10 +280,16 @@ static void test_query() tid2.close(); file.close(); + // Try truncating the file to make sure reference counting is good. + // If any references to ids of tid1 and tid2 are left unterminated, + // the truncating will fail, because the file will not be closed in + // the file.close() above. + H5File file1(FILENAME[2], H5F_ACC_TRUNC); + PASSED(); } // end of try block catch (Exception E) { - issue_fail_msg("test_query", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_query", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_query @@ -464,27 +470,20 @@ static void test_named () trans_type.setPrecision(256); trans_type.close(); - /* - * Close the committed type and reopen it. It should return a named type. -* This had something to do with the way IntType was returned and assigned -and caused itype.committed not working correctly. So, use another_type for -now. + // Close the committed type and reopen it. It should be a named type. itype.close(); itype = file.openIntType("native-int"); iscommitted = itype.committed(); -*/ - IntType another_type = file.openIntType("native-int"); - iscommitted = another_type.committed(); if (!iscommitted) throw InvalidActionException("IntType::committed()", "Opened named types should be named types!"); // Create a dataset that uses the named type, then get the dataset's // datatype and make sure it's a named type. - DataSet dset = file.createDataSet("dset1", another_type, space); + DataSet dset = file.createDataSet("dset1", itype, space); ds_type = new DataType(dset.getDataType()); iscommitted = ds_type->committed(); if (!iscommitted) - throw InvalidActionException("IntType::committed()", "1 Dataset type should be named type!"); + throw InvalidActionException("IntType::committed()", "Dataset type should be named type!"); dset.close(); ds_type->close(); delete ds_type; |