[svn-r26655] 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)
Platforms tested:
Linux/64 (platypus)
Linux/32 2.6 (jam gnu and Intel 15.0)
SunOS 5.11 (emu)
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "H5PropList.h"
|
||||
#include "H5Object.h"
|
||||
#include "H5AbstractDs.h"
|
||||
#include "H5DataSpace.h"
|
||||
#include "H5DcreatProp.h"
|
||||
#include "H5CommonFG.h"
|
||||
#include "H5Alltypes.h"
|
||||
@@ -124,8 +125,9 @@ DataType AbstractDs::getDataType() const
|
||||
// depending on which object invokes getDataType. Then, create and
|
||||
// return the DataType object
|
||||
try {
|
||||
DataType datatype(p_get_type());
|
||||
return(datatype);
|
||||
DataType datatype;
|
||||
f_DataType_setId(&datatype, p_get_type());
|
||||
return(datatype);
|
||||
}
|
||||
catch (DataSetIException E) {
|
||||
throw DataTypeIException("DataSet::getDataType", E.getDetailMsg());
|
||||
@@ -150,8 +152,9 @@ ArrayType AbstractDs::getArrayType() const
|
||||
// depending on which object invokes getArrayType. Then, create and
|
||||
// return the ArrayType object
|
||||
try {
|
||||
ArrayType arraytype(p_get_type());
|
||||
return(arraytype);
|
||||
ArrayType arraytype;
|
||||
f_DataType_setId(&arraytype, p_get_type());
|
||||
return(arraytype);
|
||||
}
|
||||
catch (DataSetIException E) {
|
||||
throw DataTypeIException("DataSet::getArrayType", E.getDetailMsg());
|
||||
@@ -176,8 +179,9 @@ CompType AbstractDs::getCompType() const
|
||||
// depending on which object invokes getCompType. Then, create and
|
||||
// return the CompType object
|
||||
try {
|
||||
CompType comptype(p_get_type());
|
||||
return(comptype);
|
||||
CompType comptype;
|
||||
f_DataType_setId(&comptype, p_get_type());
|
||||
return(comptype);
|
||||
}
|
||||
catch (DataSetIException E) {
|
||||
throw DataTypeIException("DataSet::getCompType", E.getDetailMsg());
|
||||
@@ -202,8 +206,9 @@ EnumType AbstractDs::getEnumType() const
|
||||
// depending on which object invokes getEnumType. Then, create and
|
||||
// return the EnumType object
|
||||
try {
|
||||
EnumType enumtype(p_get_type());
|
||||
return(enumtype);
|
||||
EnumType enumtype;
|
||||
f_DataType_setId(&enumtype, p_get_type());
|
||||
return(enumtype);
|
||||
}
|
||||
catch (DataSetIException E) {
|
||||
throw DataTypeIException("DataSet::getEnumType", E.getDetailMsg());
|
||||
@@ -228,8 +233,9 @@ IntType AbstractDs::getIntType() const
|
||||
// depending on which object invokes getIntType. Then, create and
|
||||
// return the IntType object
|
||||
try {
|
||||
IntType inttype(p_get_type());
|
||||
return(inttype);
|
||||
IntType inttype;
|
||||
f_DataType_setId(&inttype, p_get_type());
|
||||
return(inttype);
|
||||
}
|
||||
catch (DataSetIException E) {
|
||||
throw DataTypeIException("DataSet::getIntType", E.getDetailMsg());
|
||||
@@ -254,8 +260,9 @@ FloatType AbstractDs::getFloatType() const
|
||||
// depending on which object invokes getFloatType. Then, create and
|
||||
// return the FloatType object
|
||||
try {
|
||||
FloatType floatype(p_get_type());
|
||||
return(floatype);
|
||||
FloatType floatype;
|
||||
f_DataType_setId(&floatype, p_get_type());
|
||||
return(floatype);
|
||||
}
|
||||
catch (DataSetIException E) {
|
||||
throw DataTypeIException("DataSet::getFloatType", E.getDetailMsg());
|
||||
@@ -280,8 +287,9 @@ StrType AbstractDs::getStrType() const
|
||||
// depending on which object invokes getStrType. Then, create and
|
||||
// return the StrType object
|
||||
try {
|
||||
StrType strtype(p_get_type());
|
||||
return(strtype);
|
||||
StrType strtype;
|
||||
f_DataType_setId(&strtype, p_get_type());
|
||||
return(strtype);
|
||||
}
|
||||
catch (DataSetIException E) {
|
||||
throw DataTypeIException("DataSet::getStrType", E.getDetailMsg());
|
||||
@@ -306,8 +314,9 @@ VarLenType AbstractDs::getVarLenType() const
|
||||
// depending on which object invokes getVarLenType. Then, create and
|
||||
// return the VarLenType object
|
||||
try {
|
||||
VarLenType varlentype(p_get_type());
|
||||
return(varlentype);
|
||||
VarLenType varlentype;
|
||||
f_DataType_setId(&varlentype, p_get_type());
|
||||
return(varlentype);
|
||||
}
|
||||
catch (DataSetIException E) {
|
||||
throw DataTypeIException("DataSet::getVarLenType", E.getDetailMsg());
|
||||
|
||||
Reference in New Issue
Block a user