[svn-r20052] Description:

Clean up Coverity warnings, and fix some style issues:

r19735:
Fix for memory leak in test/mf found by valgrind.

r19736:
Fix memory leak in h5repack.  The buffer in copy_objects, when copying the
entire dataset at once, was not checked for the presence of a vlen, and vlen
storage was never reclaimed.  Added check and call to H5D_vlen_reclaim().

r19772:
Change H5assert() to
   if (H5T_VLEN != src->shared->type || H5T_VLEN != dst->shared->type)
          HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a H5T_VLEN datatype")

r19774:
removed unused priv.

r19775:
removed unused variables

r19778:
Fix memory leak comparing for variable length data types.

r19834:
Fixed memory leaks found by valgrind.  Memory errors remain for another day.

Tested on:
    Mac OS X/32 10.6.6 (amazon) w/debug & production
    (h5committested on branch)
This commit is contained in:
Quincey Koziol 2011-02-05 22:24:42 -05:00
parent 299ac26d98
commit ff845ed8b1
10 changed files with 614 additions and 564 deletions

View File

@ -115,7 +115,8 @@ static void test_compound_2()
const int nelmts = NTESTELEM;
const hsize_t four = 4;
int i;
unsigned char *buf=NULL, *orig=NULL, *bkg=NULL;
unsigned char *buf = NULL, *orig = NULL, *bkg = NULL;
ArrayType *array_dt = NULL;
// Output message about test being performed
SUBTEST("Compound Element Reordering");
@ -138,7 +139,7 @@ static void test_compound_2()
memcpy(buf, orig, nelmts*sizeof(src_typ_t));
// Build hdf5 datatypes
ArrayType* array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
// Create an empty compound datatype
CompType st(sizeof(src_typ_t));
@ -148,6 +149,7 @@ static void test_compound_2()
st.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_INT);
st.insertMember("e", HOFFSET(src_typ_t, e), PredType::NATIVE_INT);
array_dt->close();
delete array_dt;
array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
@ -202,6 +204,9 @@ static void test_compound_2()
cerr << "test_compound_2 in catch" << endl;
issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
}
if(array_dt)
delete array_dt;
} // test_compound_2()
@ -235,7 +240,8 @@ static void test_compound_3()
int i;
const int nelmts = NTESTELEM;
const hsize_t four = 4;
unsigned char *buf=NULL, *orig=NULL, *bkg=NULL;
unsigned char *buf = NULL, *orig = NULL, *bkg = NULL;
ArrayType* array_dt = NULL;
// Output message about test being performed
SUBTEST("Compound Datatype Subset Conversions");
@ -258,7 +264,7 @@ static void test_compound_3()
memcpy(buf, orig, nelmts*sizeof(src_typ_t));
/* Build hdf5 datatypes */
ArrayType* array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
// Create an empty compound datatype
CompType st(sizeof(src_typ_t));
@ -268,6 +274,7 @@ static void test_compound_3()
st.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_INT);
st.insertMember("e", HOFFSET(src_typ_t, e), PredType::NATIVE_INT);
array_dt->close();
delete array_dt;
array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
@ -319,6 +326,9 @@ static void test_compound_3()
cerr << "test_compound_3 in catch" << endl;
issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
}
if(array_dt)
delete array_dt;
} // test_compound_3()
@ -357,7 +367,8 @@ static void test_compound_4()
int i;
const int nelmts = NTESTELEM;
const hsize_t four = 4;
unsigned char *buf=NULL, *orig=NULL, *bkg=NULL;
unsigned char *buf = NULL, *orig = NULL, *bkg = NULL;
ArrayType* array_dt = NULL;
// Output message about test being performed
SUBTEST("Compound Element Shrinking & Reordering");
@ -380,7 +391,7 @@ static void test_compound_4()
memcpy(buf, orig, nelmts*sizeof(src_typ_t));
/* Build hdf5 datatypes */
ArrayType* array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
// Create an empty compound datatype
CompType st(sizeof(src_typ_t));
@ -390,6 +401,7 @@ static void test_compound_4()
st.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_INT);
st.insertMember("e", HOFFSET(src_typ_t, e), PredType::NATIVE_INT);
array_dt->close();
delete array_dt;
array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
@ -446,6 +458,9 @@ static void test_compound_4()
cerr << "test_compound_4 in catch" << endl;
issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
}
if(array_dt)
delete array_dt;
} // test_compound_4()
@ -486,16 +501,18 @@ static void test_compound_5()
dst_typ_t *dst;
void *buf = calloc(2, sizeof(dst_typ_t));
void *bkg = calloc(2, sizeof(dst_typ_t));
ArrayType* array_dt = NULL;
// Output message about test being performed
SUBTEST("Optimized Struct Converter");
try {
/* Build datatypes */
ArrayType* array_dt = new ArrayType(PredType::NATIVE_SHORT, 1, dims);
array_dt = new ArrayType(PredType::NATIVE_SHORT, 1, dims);
CompType short_array(4*sizeof(short));
short_array.insertMember("_", 0, *array_dt);
array_dt->close();
delete array_dt;
CompType int_array(4*sizeof(int));
array_dt = new ArrayType(PredType::NATIVE_INT, 1, dims);
@ -545,6 +562,9 @@ static void test_compound_5()
cerr << "test_compound_5 in catch" << endl;
issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
}
if(array_dt)
delete array_dt;
} // test_compound_5()

View File

@ -174,58 +174,61 @@ void test_szip_filter(H5File& file1)
SUBTEST("szip filter (with encoder)");
if ( h5_szip_can_encode() == 1) {
char* tconv_buf = new char [1000];
try {
const hsize_t size[2] = {DSET_DIM1, DSET_DIM2};
char* tconv_buf = new char [1000];
// Create the data space
DataSpace space1(2, size, NULL);
try {
const hsize_t size[2] = {DSET_DIM1, DSET_DIM2};
// Create a small conversion buffer to test strip mining (?)
DSetMemXferPropList xfer;
xfer.setBuffer (1000, tconv_buf, NULL);
// Create the data space
DataSpace space1(2, size, NULL);
// Prepare dataset create property list
DSetCreatPropList dsplist;
dsplist.setChunk(2, chunk_size);
// Create a small conversion buffer to test strip mining (?)
DSetMemXferPropList xfer;
xfer.setBuffer (1000, tconv_buf, NULL);
// Set up for szip compression
dsplist.setSzip(szip_options_mask, szip_pixels_per_block);
// Prepare dataset create property list
DSetCreatPropList dsplist;
dsplist.setChunk(2, chunk_size);
// Create a dataset with szip compression
DataSpace space2 (2, size, NULL);
DataSet dataset(file1.createDataSet (DSET_SZIP_NAME, PredType::NATIVE_INT, space2, dsplist));
// Set up for szip compression
dsplist.setSzip(szip_options_mask, szip_pixels_per_block);
hsize_t i, j, n;
for (i=n=0; i<size[0]; i++)
{
for (j=0; j<size[1]; j++)
// Create a dataset with szip compression
DataSpace space2 (2, size, NULL);
DataSet dataset(file1.createDataSet (DSET_SZIP_NAME, PredType::NATIVE_INT, space2, dsplist));
hsize_t i, j, n;
for (i=n=0; i<size[0]; i++)
{
points[i][j] = (int)n++;
for (j=0; j<size[1]; j++)
{
points[i][j] = (int)n++;
}
}
// Write to the dataset then read back the values
dataset.write ((void*)points, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
dataset.read ((void*)check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
// Check that the values read are the same as the values written
for (i = 0; i < size[0]; i++)
for (j = 0; j < size[1]; j++)
{
int status = check_values (i, j, points[i][j], check[i][j]);
if (status == -1)
throw Exception("test_szip_filter", "Failed in testing szip method");
}
dsplist.close();
PASSED();
} // end of try
// catch all other exceptions
catch (Exception E)
{
issue_fail_msg("test_szip_filter()", __LINE__, __FILE__, E.getCDetailMsg());
}
// Write to the dataset then read back the values
dataset.write ((void*)points, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
dataset.read ((void*)check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
// Check that the values read are the same as the values written
for (i = 0; i < size[0]; i++)
for (j = 0; j < size[1]; j++)
{
int status = check_values (i, j, points[i][j], check[i][j]);
if (status == -1)
throw Exception("test_szip_filter", "Failed in testing szip method");
}
dsplist.close();
PASSED();
} // end of try
// catch all other exceptions
catch (Exception E)
{
issue_fail_msg("test_szip_filter()", __LINE__, __FILE__, E.getCDetailMsg());
}
delete tconv_buf;
} // if szip presents
else {
SKIPPED();

View File

@ -403,7 +403,6 @@ static void test_basic_links(hid_t fapl_id, hbool_t new_format)
{
hsize_t size[1] = {1};
char filename[NAME_BUF_SIZE];
char* tconv_buf = new char [1000];
// Use the file access template id to create a file access prop. list.
FileAccPropList fapl(fapl_id);

View File

@ -326,6 +326,9 @@ static void test_reference_obj(void)
catch (Exception E) {
issue_fail_msg("test_reference_obj()", __LINE__, __FILE__, E.getCDetailMsg());
}
if(file1)
delete file1;
} // test_reference_obj()
/****************************************************************

View File

@ -387,6 +387,7 @@ static void test_named ()
static hsize_t ds_size[2] = {10, 20};
hsize_t i;
unsigned attr_data[10][20];
DataType *ds_type = NULL;
SUBTEST("Named datatypes");
try {
@ -462,12 +463,13 @@ now.
// 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);
DataType *ds_type = new DataType(dset.getDataType());
ds_type = new DataType(dset.getDataType());
iscommitted = ds_type->committed();
if (!iscommitted)
throw InvalidActionException("IntType::committed()", "1 Dataset type should be named type!");
dset.close();
ds_type->close();
delete ds_type;
// Reopen the dataset and its type, then make sure the type is
// a named type.
@ -483,6 +485,7 @@ now.
dset = file.createDataSet("dset2", *ds_type, space);
ds_type->close();
dset.close();
delete ds_type;
// Reopen the second dataset and make sure the type is shared
dset = file.openDataSet("dset2");
@ -509,6 +512,9 @@ now.
catch (Exception E) {
issue_fail_msg("test_named", __LINE__, __FILE__, E.getCDetailMsg());
}
if(ds_type)
delete ds_type;
} // test_named

View File

@ -129,7 +129,6 @@ void test_vlstr_free_custom(void *_mem, void *info)
*-------------------------------------------------------------------------
*/
// String for testing datasets
static char *dynstring_ds_write=NULL;
static char stastring_ds_write[1]={'A'};
// Info for a string dataset
@ -138,6 +137,9 @@ const H5std_string DSET1_DATA("String Dataset");
static void test_vlstring_dataset()
{
char *dynstring_ds_write = NULL;
char *string_ds_check = NULL;
// Output message about test being performed
SUBTEST("VL String on Datasets");
@ -161,12 +163,12 @@ static void test_vlstring_dataset()
dset1.write(DSET1_DATA, vlst);
// Read and verify the dataset string as a string of chars.
char *string_ds_check;
dset1.read(&string_ds_check, vlst);
if(HDstrcmp(string_ds_check, DSET1_DATA.c_str())!=0)
TestErrPrintf("Line %d: Attribute data different: DSET1_DATA=%s,string_ds_check=%s\n",__LINE__, DSET1_DATA.c_str(), string_ds_check);
HDfree(string_ds_check); // note: no need for std::string test
string_ds_check = NULL;
// Read and verify the dataset string as an std::string.
H5std_string read_str;
@ -191,6 +193,7 @@ static void test_vlstring_dataset()
if(HDstrcmp(string_ds_check,dynstring_ds_write)!=0)
TestErrPrintf("VL string datasets don't match!, dynstring_ds_write=%s, string_ds_check=%s\n",dynstring_ds_write,string_ds_check);
HDfree(string_ds_check);
string_ds_check = NULL;
dset1.close();
// Open dataset DSET1_NAME again.
@ -207,6 +210,11 @@ static void test_vlstring_dataset()
catch (Exception E) {
issue_fail_msg("test_vlstring_dataset()", __LINE__, __FILE__, E.getCDetailMsg());
}
if(dynstring_ds_write)
HDfree(dynstring_ds_write);
if(string_ds_check)
HDfree(string_ds_check);
} // test_vlstring_dataset()
/*-------------------------------------------------------------------------
@ -231,10 +239,10 @@ static void test_vlstring_array_dataset()
// Output message about test being performed
SUBTEST("VL String Array on Datasets");
H5File* file1;
H5File* file1 = NULL;
try {
// Create file.
file1 = new H5File (FILENAME, H5F_ACC_RDWR);
file1 = new H5File(FILENAME, H5F_ACC_RDWR);
// Create dataspace for datasets.
hsize_t dims1[] = {SPACE1_DIM1};
@ -278,8 +286,7 @@ static void test_vlstring_array_dataset()
HDmemset(wdata2, 'A', 65533);
dataset2.write(&wdata2, vlst);
char *rdata2 = (char*)HDcalloc(65534, sizeof(char));
HDmemset(rdata2, 0, 65533);
char *rdata2;
dataset2.read(&rdata2, vlst);
if (HDstrcmp(wdata2, rdata2)!=0)
TestErrPrintf("Line %d: Dataset data different: written=%s,read=%s\n",__LINE__, wdata2, rdata2);
@ -302,8 +309,10 @@ static void test_vlstring_array_dataset()
catch (Exception E)
{
issue_fail_msg("test_vlstring_array_dataset()", __LINE__, __FILE__, E.getCDetailMsg());
delete file1;
}
if(file1)
delete file1;
} // end test_vlstring_array_dataset()
/*-------------------------------------------------------------------------
@ -482,6 +491,7 @@ static void test_vlstring_type()
// Close datatype and file.
vlst.close();
file1->close();
delete file1;
// Open file.
file1 = new H5File(FILENAME, H5F_ACC_RDWR);
@ -506,8 +516,10 @@ static void test_vlstring_type()
catch (Exception E)
{
issue_fail_msg("test_vlstring_type()", __LINE__, __FILE__, E.getCDetailMsg());
delete file1;
}
if(file1)
delete file1;
} // end test_vlstring_type()
/*-------------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

132
test/mf.c
View File

@ -178,7 +178,7 @@ static unsigned
test_mf_eoa(const char *env_h5_drvr, hid_t fapl)
{
hid_t file = -1; /* File ID */
hid_t fapl_new; /* copy of fapl */
hid_t fapl_new = -1; /* copy of fapl */
char filename[FILENAME_LEN]; /* Filename to use */
H5F_t *f = NULL; /* Internal file object pointer */
h5_stat_size_t file_size, new_file_size; /* file size */
@ -277,9 +277,12 @@ test_mf_eoa(const char *env_h5_drvr, hid_t fapl)
TEST_ERROR
/* Verify the file is the correct size */
if (new_file_size != file_size)
if(new_file_size != file_size)
TEST_ERROR
if(H5Pclose(fapl_new) < 0)
FAIL_STACK_ERROR
PASSED()
} /* end if */
else {
@ -291,6 +294,7 @@ test_mf_eoa(const char *env_h5_drvr, hid_t fapl)
error:
H5E_BEGIN_TRY {
H5Pclose(fapl_new);
H5Fclose(file);
} H5E_END_TRY;
return(1);
@ -317,7 +321,7 @@ static unsigned
test_mf_eoa_shrink(const char *env_h5_drvr, hid_t fapl)
{
hid_t file = -1; /* File ID */
hid_t fapl_new; /* copy of fapl */
hid_t fapl_new = -1; /* copy of fapl */
char filename[FILENAME_LEN]; /* Filename to use */
H5F_t *f = NULL; /* Internal file object pointer */
h5_stat_size_t file_size, new_file_size; /* file size */
@ -403,8 +407,10 @@ test_mf_eoa_shrink(const char *env_h5_drvr, hid_t fapl)
/* nothing should be changed in meta_aggr */
H5MF_aggr_query(f, &(f->shared->meta_aggr), &new_ma_addr, &ma_size);
if (new_ma_addr != ma_addr) TEST_ERROR
if (new_ma_size != ma_size) TEST_ERROR
if(new_ma_addr != ma_addr)
TEST_ERROR
if(new_ma_size != ma_size)
TEST_ERROR
if(H5Fclose(file) < 0)
FAIL_STACK_ERROR
@ -414,7 +420,7 @@ test_mf_eoa_shrink(const char *env_h5_drvr, hid_t fapl)
TEST_ERROR
/* Verify the file is the correct size */
if (new_file_size != file_size)
if(new_file_size != file_size)
TEST_ERROR
PASSED()
@ -462,7 +468,7 @@ test_mf_eoa_shrink(const char *env_h5_drvr, hid_t fapl)
TEST_ERROR
/* Verify the file is the correct size */
if (new_file_size != (file_size+TEST_BLOCK_SIZE30))
if(new_file_size != (file_size + TEST_BLOCK_SIZE30))
TEST_ERROR
PASSED()
@ -506,7 +512,7 @@ test_mf_eoa_shrink(const char *env_h5_drvr, hid_t fapl)
TEST_ERROR
/* Verify the file is the correct size */
if (new_file_size != (file_size+TEST_BLOCK_SIZE30))
if(new_file_size != (file_size + TEST_BLOCK_SIZE30))
TEST_ERROR
PASSED()
@ -538,8 +544,10 @@ test_mf_eoa_shrink(const char *env_h5_drvr, hid_t fapl)
/* nothing should be changed in meta_aggr */
H5MF_aggr_query(f, &(f->shared->meta_aggr), &new_ma_addr, &ma_size);
if (new_ma_addr != ma_addr) TEST_ERROR
if (new_ma_size != ma_size) TEST_ERROR
if(new_ma_addr != ma_addr)
TEST_ERROR
if(new_ma_size != ma_size)
TEST_ERROR
if(H5Fclose(file) < 0)
FAIL_STACK_ERROR
@ -549,9 +557,12 @@ test_mf_eoa_shrink(const char *env_h5_drvr, hid_t fapl)
TEST_ERROR
/* Verify the file is the correct size */
if (new_file_size != (file_size+10))
if(new_file_size != (file_size + 10))
TEST_ERROR
if(H5Pclose(fapl_new) < 0)
FAIL_STACK_ERROR
PASSED()
} /* end if */
else {
@ -563,6 +574,7 @@ test_mf_eoa_shrink(const char *env_h5_drvr, hid_t fapl)
error:
H5E_BEGIN_TRY {
H5Pclose(fapl_new);
H5Fclose(file);
} H5E_END_TRY;
return(1);
@ -585,7 +597,7 @@ static unsigned
test_mf_eoa_extend(const char *env_h5_drvr, hid_t fapl)
{
hid_t file = -1; /* File ID */
hid_t fapl_new; /* copy of fapl */
hid_t fapl_new = -1; /* copy of fapl */
char filename[FILENAME_LEN]; /* Filename to use */
H5F_t *f = NULL; /* Internal file object pointer */
h5_stat_size_t file_size, new_file_size; /* File size */
@ -621,8 +633,10 @@ test_mf_eoa_extend(const char *env_h5_drvr, hid_t fapl)
TEST_ERROR
/* Turn off using meta/small data aggregator */
H5Pset_meta_block_size(fapl_new, (hsize_t)0);
H5Pset_small_data_block_size(fapl_new, (hsize_t)0);
if(H5Pset_meta_block_size(fapl_new, (hsize_t)0) < 0)
FAIL_STACK_ERROR
if(H5Pset_small_data_block_size(fapl_new, (hsize_t)0) < 0)
FAIL_STACK_ERROR
/* Re-open the file with meta/small data setting */
if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl_new)) < 0)
@ -652,7 +666,7 @@ test_mf_eoa_extend(const char *env_h5_drvr, hid_t fapl)
TEST_ERROR
/* Verify the file is the correct size */
if (new_file_size != (file_size+TEST_BLOCK_SIZE30))
if(new_file_size != (file_size + TEST_BLOCK_SIZE30))
TEST_ERROR
/* Re-open the file */
@ -682,7 +696,7 @@ test_mf_eoa_extend(const char *env_h5_drvr, hid_t fapl)
TEST_ERROR
/* Verify the file is the correct size */
if (new_file_size != (file_size+TEST_BLOCK_SIZE30+TEST_BLOCK_SIZE50))
if(new_file_size != (file_size + TEST_BLOCK_SIZE30 + TEST_BLOCK_SIZE50))
TEST_ERROR
PASSED()
@ -715,12 +729,12 @@ test_mf_eoa_extend(const char *env_h5_drvr, hid_t fapl)
type = H5FD_MEM_SUPER;
addr = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE30);
if (addr < (haddr_t)file_size)
if(addr < (haddr_t)file_size)
TEST_ERROR
/* nothing should be changed in meta_aggr */
H5MF_aggr_query(f, &(f->shared->meta_aggr), &new_ma_addr, &new_ma_size);
if (new_ma_addr != ma_addr)
if(new_ma_addr != ma_addr)
TEST_ERROR
extended = H5MF_try_extend(f, H5P_DATASET_XFER_DEFAULT, type, (haddr_t)addr, (hsize_t)(TEST_BLOCK_SIZE30-10), (hsize_t)(TEST_BLOCK_SIZE50));
@ -742,9 +756,12 @@ test_mf_eoa_extend(const char *env_h5_drvr, hid_t fapl)
TEST_ERROR
/* Verify the file is the correct size */
if (new_file_size != file_size+TEST_BLOCK_SIZE30)
if(new_file_size != file_size + TEST_BLOCK_SIZE30)
TEST_ERROR
if(H5Pclose(fapl_new) < 0)
FAIL_STACK_ERROR
PASSED()
} /* end if */
else {
@ -756,6 +773,7 @@ test_mf_eoa_extend(const char *env_h5_drvr, hid_t fapl)
error:
H5E_BEGIN_TRY {
H5Pclose(fapl_new);
H5Fclose(file);
} H5E_END_TRY;
return(1);
@ -947,7 +965,7 @@ static unsigned
test_mf_fs_start(hid_t fapl)
{
hid_t file = -1; /* File ID */
hid_t fapl_new; /* copy of fapl */
hid_t fapl_new = -1; /* copy of fapl */
char filename[FILENAME_LEN]; /* Filename to use */
H5F_t *f = NULL; /* Internal file object pointer */
h5_stat_size_t file_size, new_file_size; /* file size */
@ -1010,15 +1028,19 @@ test_mf_fs_start(hid_t fapl)
TEST_ERROR
/* Verify the file is the correct size */
if (new_file_size != file_size)
if(new_file_size != file_size)
TEST_ERROR
if(H5Pclose(fapl_new) < 0)
FAIL_STACK_ERROR
PASSED()
return(0);
error:
H5E_BEGIN_TRY {
H5Pclose(fapl_new);
H5Fclose(file);
} H5E_END_TRY;
return(1);
@ -1054,7 +1076,7 @@ static unsigned
test_mf_fs_alloc_free(hid_t fapl)
{
hid_t file = -1; /* File ID */
hid_t fapl_new; /* copy of fapl */
hid_t fapl_new = -1; /* copy of fapl */
char filename[FILENAME_LEN]; /* Filename to use */
H5F_t *f = NULL; /* Internal file object pointer */
h5_stat_size_t file_size, new_file_size; /* file size */
@ -1343,15 +1365,19 @@ test_mf_fs_alloc_free(hid_t fapl)
TEST_ERROR
/* Verify the file is the correct size */
if (new_file_size != file_size)
if(new_file_size != file_size)
TEST_ERROR
if(H5Pclose(fapl_new) < 0)
FAIL_STACK_ERROR
PASSED()
return(0);
error:
H5E_BEGIN_TRY {
H5Pclose(fapl_new);
H5Fclose(file);
} H5E_END_TRY;
return(1);
@ -1399,7 +1425,7 @@ static unsigned
test_mf_fs_extend(hid_t fapl)
{
hid_t file = -1; /* File ID */
hid_t fapl_new; /* copy of fapl */
hid_t fapl_new = -1; /* copy of fapl */
char filename[FILENAME_LEN]; /* Filename to use */
H5F_t *f = NULL; /* Internal file object pointer */
h5_stat_size_t file_size, new_file_size; /* file size */
@ -1889,15 +1915,19 @@ test_mf_fs_extend(hid_t fapl)
TEST_ERROR
/* Verify the file is the correct size */
if (new_file_size != file_size)
if(new_file_size != file_size)
TEST_ERROR
if(H5Pclose(fapl_new) < 0)
FAIL_STACK_ERROR
PASSED()
return(0);
error:
H5E_BEGIN_TRY {
H5Pclose(fapl_new);
H5Fclose(file);
} H5E_END_TRY;
return(1);
@ -6635,7 +6665,7 @@ error:
HDmemset(memb_name, 0, sizeof memb_name); \
HDmemset(memb_addr, 0, sizeof memb_addr); \
HDmemset(sv, 0, sizeof sv); \
for (mt = 0; mt < H5FD_MEM_NTYPES; mt++) { \
for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t, mt)) { \
memb_map[mt] = H5FD_MEM_SUPER; \
memb_fapl[mt] = H5P_DEFAULT; \
} \
@ -6670,20 +6700,21 @@ error:
static unsigned
test_mf_fs_drivers(hid_t fapl)
{
hid_t fcpl; /* file creation property list */
hid_t fapl_new; /* copy of file access property list */
hid_t fapl2; /* copy of file access property list */
hid_t fcpl = -1; /* file creation property list */
hid_t fapl_new = -1; /* copy of file access property list */
hid_t fapl2 = -1; /* copy of file access property list */
hbool_t new_format; /* To use new library format or not */
unsigned ret = 0; /* return value */
H5FD_mem_t memb_map[H5FD_MEM_NTYPES]; /* Memory usage map */
hid_t memb_fapl[H5FD_MEM_NTYPES]; /* Member access properties */
char sv[H5FD_MEM_NTYPES][500]; /* Name generators */
char sv[H5FD_MEM_NTYPES][64]; /* Name generators */
const char *memb_name[H5FD_MEM_NTYPES]; /* Name generators */
haddr_t memb_addr[H5FD_MEM_NTYPES]; /* Member starting address */
/* Create a non-standard file-creation template */
fcpl = H5Pcreate(H5P_FILE_CREATE);
if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0)
FAIL_STACK_ERROR
if(H5Pset_file_space(fcpl, H5F_FILE_SPACE_ALL_PERSIST, (hsize_t)0) < 0)
TEST_ERROR
@ -6784,14 +6815,19 @@ test_mf_fs_drivers(hid_t fapl)
} /* end for new_format */
if (H5Pclose(fcpl) < 0)
if(H5Pclose(fcpl) < 0)
FAIL_STACK_ERROR
if (H5Pclose(fapl2) < 0)
if(H5Pclose(fapl2) < 0)
FAIL_STACK_ERROR
return(ret);
error:
H5E_BEGIN_TRY {
H5Pclose(fcpl);
H5Pclose(fapl2);
H5Pclose(fapl_new);
} H5E_END_TRY;
return(1);
} /* test_mf_fs_drivers() */
@ -6804,7 +6840,7 @@ static unsigned
test_filespace_strategy_threshold(hid_t fapl_new)
{
hid_t file = -1; /* File ID */
hid_t fcpl; /* File creation property list template */
hid_t fcpl = -1; /* File creation property list template */
char filename[FILENAME_LEN]; /* Filename to use */
H5F_t *f = NULL; /* Internal file object pointer */
H5FD_mem_t type; /* File allocation type */
@ -6922,7 +6958,10 @@ test_filespace_strategy_threshold(hid_t fapl_new)
TEST_ERROR
break;
case H5F_FILE_SPACE_DEFAULT:
case H5F_FILE_SPACE_NTYPES:
default:
TEST_ERROR
break;
} /* end switch */
@ -6941,6 +6980,7 @@ test_filespace_strategy_threshold(hid_t fapl_new)
error:
H5E_BEGIN_TRY {
H5Pclose(fcpl);
H5Fclose(file);
} H5E_END_TRY;
return(1);
@ -6954,7 +6994,7 @@ static unsigned
test_filespace_gone(hid_t fapl_new)
{
hid_t file = -1; /* File ID */
hid_t fcpl; /* File creation propertly list template */
hid_t fcpl = -1; /* File creation propertly list template */
char filename[FILENAME_LEN]; /* Filename to use */
H5F_t *f = NULL; /* Internal file object pointer */
H5FD_mem_t type; /* File allocation type */
@ -7074,6 +7114,7 @@ test_filespace_gone(hid_t fapl_new)
error:
H5E_BEGIN_TRY {
H5Pclose(fcpl);
H5Fclose(file);
} H5E_END_TRY;
return(1);
@ -7085,14 +7126,14 @@ error:
static unsigned
test_filespace_drivers(hid_t fapl)
{
hid_t fapl_new; /* copy of file access property list */
hid_t fapl2; /* copy of file access property list */
hid_t fapl_new = -1; /* copy of file access property list */
hid_t fapl2 = -1; /* copy of file access property list */
hbool_t new_format; /* Using library new format or not */
unsigned ret = 0; /* return value */
H5FD_mem_t memb_map[H5FD_MEM_NTYPES]; /* Memory usage map */
hid_t memb_fapl[H5FD_MEM_NTYPES]; /* Member access properties */
char sv[H5FD_MEM_NTYPES][500]; /* Name generators */
char sv[H5FD_MEM_NTYPES][64]; /* Name generators */
const char *memb_name[H5FD_MEM_NTYPES]; /* Name generators */
haddr_t memb_addr[H5FD_MEM_NTYPES]; /* Member starting address */
@ -7201,6 +7242,10 @@ test_filespace_drivers(hid_t fapl)
return(ret);
error:
H5E_BEGIN_TRY {
H5Pclose(fapl_new);
H5Pclose(fapl2);
} H5E_END_TRY;
return(1);
} /* test_filespace_drivers() */
@ -7259,10 +7304,9 @@ main(void)
nerrors += test_mf_aggr_absorb(env_h5_drvr, fapl);
/* Tests for alignment */
for(curr_test = TEST_NORMAL; curr_test < TEST_NTESTS; curr_test++) {
for(curr_test = TEST_NORMAL; curr_test < TEST_NTESTS; H5_INC_ENUM(test_type_t, curr_test)) {
switch(curr_test) {
case TEST_NORMAL: /* set alignment = 1024 */
if(H5Pset_alignment(new_fapl, (hsize_t)0, (hsize_t)TEST_ALIGN1024) < 0)
TEST_ERROR
@ -7273,6 +7317,7 @@ main(void)
TEST_ERROR
break;
case TEST_NTESTS:
default:
TEST_ERROR;
break;
@ -7294,7 +7339,7 @@ main(void)
/* tests for file space management */
nerrors += test_filespace_drivers(fapl);
if (H5Pclose(new_fapl) < 0)
if(H5Pclose(new_fapl) < 0)
FAIL_STACK_ERROR
h5_cleanup(FILENAME, fapl);
@ -7302,13 +7347,14 @@ main(void)
goto error;
puts("All free-space manager tests for file memory passed.");
return (0);
return(0);
error:
puts("*** TESTS FAILED ***");
H5E_BEGIN_TRY {
H5Pclose(fapl);
H5Pclose(new_fapl);
} H5E_END_TRY;
return (1);
return(1);
} /* main() */

View File

@ -543,23 +543,23 @@ int do_copy_objects(hid_t fidin,
trav_table_t *travt,
pack_opt_t *options) /* repack options */
{
hid_t grp_in=-1; /* group ID */
hid_t grp_out=-1; /* group ID */
hid_t dset_in=-1; /* read dataset ID */
hid_t dset_out=-1; /* write dataset ID */
hid_t gcpl_in=-1; /* group creation property list */
hid_t gcpl_out=-1; /* group creation property list */
hid_t type_in=-1; /* named type ID */
hid_t type_out=-1; /* named type ID */
hid_t dcpl_id=-1; /* dataset creation property list ID */
hid_t dcpl_out=-1; /* dataset creation property list ID */
hid_t f_space_id=-1; /* file space ID */
hid_t ftype_id=-1; /* file type ID */
hid_t wtype_id=-1; /* read/write type ID */
named_dt_t *named_dt_head=NULL; /* Pointer to the stack of named datatypes copied */
hid_t grp_in = -1; /* group ID */
hid_t grp_out = -1; /* group ID */
hid_t dset_in = -1; /* read dataset ID */
hid_t dset_out = -1; /* write dataset ID */
hid_t gcpl_in = -1; /* group creation property list */
hid_t gcpl_out = -1; /* group creation property list */
hid_t type_in = -1; /* named type ID */
hid_t type_out = -1; /* named type ID */
hid_t dcpl_id = -1; /* dataset creation property list ID */
hid_t dcpl_out = -1; /* dataset creation property list ID */
hid_t f_space_id = -1; /* file space ID */
hid_t ftype_id = -1; /* file type ID */
hid_t wtype_id = -1; /* read/write type ID */
named_dt_t *named_dt_head = NULL; /* Pointer to the stack of named datatypes copied */
size_t msize; /* size of type */
hsize_t nelmts; /* number of elements in dataset */
H5D_space_status_t *space_status; /* determines whether space has been allocated for the dataset */
H5D_space_status_t space_status; /* determines whether space has been allocated for the dataset */
int rank; /* rank of dataset */
hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */
hsize_t dsize_in; /* input dataset size before filter */
@ -748,14 +748,12 @@ int do_copy_objects(hid_t fidin,
if(H5Sget_simple_extent_dims(f_space_id, dims, NULL) < 0)
goto error;
if(H5Dget_space_status(dset_in, &space_status) <0)
if(H5Dget_space_status(dset_in, &space_status) < 0)
goto error;
nelmts = 1;
for ( j = 0; j < rank; j++)
{
for(j = 0; j < rank; j++)
nelmts *= dims[j];
}
/* wtype_id will have already been set if using a named dtype */
if(!is_named) {
@ -839,20 +837,25 @@ int do_copy_objects(hid_t fidin,
* read/write
*-------------------------------------------------------------------------
*/
if (nelmts>0 && space_status!=H5D_SPACE_STATUS_NOT_ALLOCATED)
if(nelmts > 0 && space_status != H5D_SPACE_STATUS_NOT_ALLOCATED)
{
size_t need = (size_t)(nelmts*msize); /* bytes needed */
size_t need = (size_t)(nelmts * msize); /* bytes needed */
/* have to read the whole dataset if there is only one element in the dataset */
if ( need < H5TOOLS_MALLOCSIZE )
if(need < H5TOOLS_MALLOCSIZE)
buf = HDmalloc(need);
if (buf != NULL )
{
if (H5Dread(dset_in,wtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf) < 0)
if(buf != NULL) {
if(H5Dread(dset_in, wtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
goto error;
if (H5Dwrite(dset_out,wtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf) < 0)
if(H5Dwrite(dset_out, wtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
goto error;
/* Check if we have VL data in the dataset's
* datatype that must be reclaimed */
if(TRUE == H5Tdetect_class(wtype_id, H5T_VLEN))
if(H5Dvlen_reclaim(wtype_id, f_space_id, H5P_DEFAULT, buf) < 0)
goto error;
}
else /* possibly not enough memory, read/write by hyperslabs */
{
@ -1370,7 +1373,7 @@ copy_user_block(const char *infile, const char *outfile, hsize_t size)
} /* end while */
/* Update size of userblock left to transfer */
size -= nread;
size = size - (hsize_t)nread;
} /* end while */
done:

View File

@ -329,100 +329,88 @@ hsize_t diff_datasetid( hid_t did1,
* only attempt to compare if possible
*-------------------------------------------------------------------------
*/
if (can_compare ) /* it is possible to compare */
if(can_compare) /* it is possible to compare */
{
unsigned int vl_data = 0; /*contains VL datatypes */
/*-------------------------------------------------------------------------
* get number of elements
*-------------------------------------------------------------------------
*/
nelmts1 = 1;
for (i = 0; i < rank1; i++)
{
for(i = 0; i < rank1; i++)
nelmts1 *= dims1[i];
}
nelmts2 = 1;
for (i = 0; i < rank2; i++)
{
for(i = 0; i < rank2; i++)
nelmts2 *= dims2[i];
}
assert(nelmts1==nelmts2);
HDassert(nelmts1 == nelmts2);
/*-------------------------------------------------------------------------
* "upgrade" the smaller memory size
*-------------------------------------------------------------------------
*/
if ( m_size1 != m_size2 )
{
if ( m_size1 < m_size2 )
{
if(m_size1 != m_size2) {
if(m_size1 < m_size2) {
H5Tclose(m_tid1);
if ((m_tid1=h5tools_get_native_type(f_tid2)) < 0)
if((m_tid1 = h5tools_get_native_type(f_tid2)) < 0)
goto error;
m_size1 = H5Tget_size( m_tid1 );
}
else
{
m_size1 = H5Tget_size(m_tid1);
} /* end if */
else {
H5Tclose(m_tid2);
if ((m_tid2=h5tools_get_native_type(f_tid1)) < 0)
if((m_tid2 = h5tools_get_native_type(f_tid1)) < 0)
goto error;
m_size2 = H5Tget_size( m_tid2 );
}
}
assert(m_size1==m_size2);
m_size2 = H5Tget_size(m_tid2);
} /* end else */
} /* end if */
HDassert(m_size1 == m_size2);
/* print names */
if (obj1_name) {
name1=diff_basename(obj1_name);
}
if (obj2_name) {
name2=diff_basename(obj2_name);
}
if(obj1_name)
name1 = diff_basename(obj1_name);
if(obj2_name)
name2 = diff_basename(obj2_name);
/* check if we have VL data in the dataset's datatype */
if(TRUE == H5Tdetect_class(m_tid1, H5T_VLEN))
vl_data = TRUE;
/*-------------------------------------------------------------------------
* read/compare
*-------------------------------------------------------------------------
*/
need = (size_t)(nelmts1*m_size1); /* bytes needed */
if ( need < H5TOOLS_MALLOCSIZE)
{
need = (size_t)(nelmts1 * m_size1); /* bytes needed */
if(need < H5TOOLS_MALLOCSIZE) {
buf1 = HDmalloc(need);
buf2 = HDmalloc(need);
}
} /* end if */
if ( buf1!=NULL && buf2!=NULL)
{
if ( H5Dread(did1,m_tid1,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf1) < 0 )
if(buf1 != NULL && buf2 != NULL) {
if(H5Dread(did1, m_tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf1) < 0)
goto error;
if ( H5Dread(did2,m_tid2,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf2) < 0 )
if(H5Dread(did2, m_tid2, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf2) < 0)
goto error;
/* array diff */
nfound = diff_array(buf1,
buf2,
nelmts1,
(hsize_t)0,
rank1,
dims1,
options,
name1,
name2,
m_tid1,
did1,
did2);
}
nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1,
options, name1, name2, m_tid1, did1, did2);
/* reclaim any VL memory, if necessary */
if(vl_data) {
H5Dvlen_reclaim(m_tid1, sid1, H5P_DEFAULT, buf1);
H5Dvlen_reclaim(m_tid2, sid2, H5P_DEFAULT, buf2);
} /* end if */
} /* end if */
else /* possibly not enough memory, read/compare by hyperslabs */
{
size_t p_type_nbytes = m_size1; /*size of memory type */
hsize_t p_nelmts = nelmts1; /*total selected elmts */
@ -442,25 +430,21 @@ hsize_t diff_datasetid( hid_t did1,
hsize_t hs_nelmts; /*elements in request */
hsize_t zero[8]; /*vector of zeros */
/* check if we have VL data in the dataset's datatype */
if (H5Tdetect_class(m_tid1, H5T_VLEN) == TRUE)
vl_data = TRUE;
/*
* determine the strip mine size and allocate a buffer. The strip mine is
* a hyperslab whose size is manageable.
*/
/*
* determine the strip mine size and allocate a buffer. The strip mine is
* a hyperslab whose size is manageable.
*/
sm_nbytes = p_type_nbytes;
for (i = rank1; i > 0; --i)
{
for(i = rank1; i > 0; --i) {
hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes;
if ( size == 0) /* datum size > H5TOOLS_BUFSIZE */
if(size == 0) /* datum size > H5TOOLS_BUFSIZE */
size = 1;
sm_size[i - 1] = MIN(dims1[i - 1], size);
sm_nbytes *= sm_size[i - 1];
assert(sm_nbytes > 0);
}
} /* end for */
/* malloc return code should be verified.
* If fail, need to handle the error.
@ -481,63 +465,43 @@ hsize_t diff_datasetid( hid_t did1,
memset(hs_offset, 0, sizeof hs_offset);
memset(zero, 0, sizeof zero);
for (elmtno = 0; elmtno < p_nelmts; elmtno += hs_nelmts)
{
for(elmtno = 0; elmtno < p_nelmts; elmtno += hs_nelmts) {
/* calculate the hyperslab size */
if (rank1 > 0)
{
for (i = 0, hs_nelmts = 1; i < rank1; i++)
{
if(rank1 > 0) {
for(i = 0, hs_nelmts = 1; i < rank1; i++) {
hs_size[i] = MIN(dims1[i] - hs_offset[i], sm_size[i]);
hs_nelmts *= hs_size[i];
}
if (H5Sselect_hyperslab(sid1, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0)
} /* end for */
if(H5Sselect_hyperslab(sid1, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0)
goto error;
if (H5Sselect_hyperslab(sid2, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0)
if(H5Sselect_hyperslab(sid2, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0)
goto error;
if (H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, &hs_nelmts, NULL) < 0)
if(H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, &hs_nelmts, NULL) < 0)
goto error;
}
} /* end if */
else
{
H5Sselect_all(sid1);
H5Sselect_all(sid2);
H5Sselect_all(sm_space);
hs_nelmts = 1;
} /* rank */
if ( H5Dread(did1,m_tid1,sm_space,sid1,H5P_DEFAULT,sm_buf1) < 0 )
if(H5Dread(did1,m_tid1,sm_space,sid1,H5P_DEFAULT,sm_buf1) < 0)
goto error;
if ( H5Dread(did2,m_tid2,sm_space,sid2,H5P_DEFAULT,sm_buf2) < 0 )
if(H5Dread(did2,m_tid2,sm_space,sid2,H5P_DEFAULT,sm_buf2) < 0)
goto error;
/* get array differences. in the case of hyperslab read, increment the number of differences
found in each hyperslab and pass the position at the beggining for printing */
nfound += diff_array(sm_buf1,
sm_buf2,
hs_nelmts,
elmtno,
rank1,
dims1,
options,
name1,
name2,
m_tid1,
did1,
did2);
nfound += diff_array(sm_buf1, sm_buf2, hs_nelmts, elmtno, rank1,
dims1, options, name1, name2, m_tid1, did1, did2);
/* reclaim any VL memory, if necessary */
if(vl_data)
{
if(vl_data) {
H5Dvlen_reclaim(m_tid1, sm_space, H5P_DEFAULT, sm_buf1);
H5Dvlen_reclaim(m_tid1, sm_space, H5P_DEFAULT, sm_buf2);
}
} /* end if */
/* calculate the next hyperslab offset */
for (i = rank1, carry = 1; i > 0 && carry; --i)
{
for(i = rank1, carry = 1; i > 0 && carry; --i) {
hs_offset[i - 1] += hs_size[i - 1];
if (hs_offset[i - 1] == dims1[i - 1])
if(hs_offset[i - 1] == dims1[i - 1])
hs_offset[i - 1] = 0;
else
carry = 0;
@ -545,60 +509,53 @@ hsize_t diff_datasetid( hid_t did1,
} /* elmtno */
H5Sclose(sm_space);
} /* hyperslab read */
}/*can_compare*/
} /* hyperslab read */
} /*can_compare*/
/*-------------------------------------------------------------------------
* compare attributes
* the if condition refers to cases when the dataset is a referenced object
*-------------------------------------------------------------------------
*/
/*-------------------------------------------------------------------------
* compare attributes
* the if condition refers to cases when the dataset is a referenced object
*-------------------------------------------------------------------------
*/
if(obj1_name)
nfound += diff_attr(did1,did2,obj1_name,obj2_name,options);
if (obj1_name)
{
nfound += diff_attr(did1,did2,obj1_name,obj2_name,options);
}
/*-------------------------------------------------------------------------
* close
*-------------------------------------------------------------------------
*/
/*-------------------------------------------------------------------------
* close
*-------------------------------------------------------------------------
*/
/* free */
if(buf1 != NULL) {
free(buf1);
buf1 = NULL;
} /* end if */
if(buf2 != NULL) {
free(buf2);
buf2 = NULL;
} /* end if */
if(sm_buf1 != NULL) {
free(sm_buf1);
sm_buf1 = NULL;
} /* end if */
if(sm_buf2 != NULL) {
free(sm_buf2);
sm_buf2 = NULL;
} /* end if */
/* free */
if (buf1!=NULL)
{
free(buf1);
buf1=NULL;
}
if (buf2!=NULL)
{
free(buf2);
buf2=NULL;
}
if (sm_buf1!=NULL)
{
free(sm_buf1);
sm_buf1=NULL;
}
if (sm_buf2!=NULL)
{
free(sm_buf2);
sm_buf2=NULL;
}
H5E_BEGIN_TRY {
H5Sclose(sid1);
H5Sclose(sid2);
H5Tclose(f_tid1);
H5Tclose(f_tid2);
H5Tclose(m_tid1);
H5Tclose(m_tid2);
} H5E_END_TRY;
H5E_BEGIN_TRY {
H5Sclose(sid1);
H5Sclose(sid2);
H5Tclose(f_tid1);
H5Tclose(f_tid2);
H5Tclose(m_tid1);
H5Tclose(m_tid2);
} H5E_END_TRY;
return nfound;
return nfound;
error:
options->err_stat=1;
options->err_stat=1;
/* free */
if (buf1!=NULL)