Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove HD from memory allocate/free calls #3195

Merged
merged 6 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion c++/test/tattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ test_string_attr(FileAccPropList &fapl)
if (HDstrcmp(string_att_check, ATTRSTR_DATA.c_str()) != 0)
TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,string_att_check=%s\n",
__LINE__, ATTRSTR_DATA.c_str(), string_att_check);
HDfree(string_att_check);
free(string_att_check);

/* Test Attribute::read(...,H5std_string& strg) with VL string */
// Read and verify the attribute string as an std::string.
Expand Down
56 changes: 28 additions & 28 deletions c++/test/tcompound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ test_compound_2()
SUBTEST("Compound Element Reordering");
try {
// Sizes should be the same, but be careful just in case
buf = static_cast<unsigned char *>(HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))));
bkg = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(dst_typ_t)));
orig = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(src_typ_t)));
buf = static_cast<unsigned char *>(malloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))));
bkg = static_cast<unsigned char *>(malloc(nelmts * sizeof(dst_typ_t)));
orig = static_cast<unsigned char *>(malloc(nelmts * sizeof(src_typ_t)));
for (i = 0; i < nelmts; i++) {
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
s_ptr->a = i * 8 + 0;
Expand Down Expand Up @@ -161,9 +161,9 @@ test_compound_2()
}
}
// Release resources
HDfree(buf);
HDfree(bkg);
HDfree(orig);
free(buf);
free(bkg);
free(orig);
s_ptr = NULL;
d_ptr = NULL;
st.close();
Expand Down Expand Up @@ -213,9 +213,9 @@ test_compound_3()
SUBTEST("Compound Datatype Subset Conversions");
try {
/* Initialize */
buf = static_cast<unsigned char *>(HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))));
bkg = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(dst_typ_t)));
orig = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(src_typ_t)));
buf = static_cast<unsigned char *>(malloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))));
bkg = static_cast<unsigned char *>(malloc(nelmts * sizeof(dst_typ_t)));
orig = static_cast<unsigned char *>(malloc(nelmts * sizeof(src_typ_t)));
for (i = 0; i < nelmts; i++) {
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
s_ptr->a = i * 8 + 0;
Expand Down Expand Up @@ -271,9 +271,9 @@ test_compound_3()
}

/* Release resources */
HDfree(buf);
HDfree(bkg);
HDfree(orig);
free(buf);
free(bkg);
free(orig);
s_ptr = NULL;
d_ptr = NULL;
st.close();
Expand Down Expand Up @@ -328,9 +328,9 @@ test_compound_4()
SUBTEST("Compound Element Shrinking & Reordering");
try {
/* Sizes should be the same, but be careful just in case */
buf = static_cast<unsigned char *>(HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))));
bkg = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(dst_typ_t)));
orig = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(src_typ_t)));
buf = static_cast<unsigned char *>(malloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))));
bkg = static_cast<unsigned char *>(malloc(nelmts * sizeof(dst_typ_t)));
orig = static_cast<unsigned char *>(malloc(nelmts * sizeof(src_typ_t)));
for (i = 0; i < nelmts; i++) {
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
s_ptr->a = i * 8 + 0;
Expand Down Expand Up @@ -390,9 +390,9 @@ test_compound_4()
} // for

/* Release resources */
HDfree(buf);
HDfree(bkg);
HDfree(orig);
free(buf);
free(bkg);
free(orig);
s_ptr = NULL;
d_ptr = NULL;
st.close();
Expand Down Expand Up @@ -439,8 +439,8 @@ test_compound_5()
hsize_t dims[1] = {4};
src_typ_t src[2] = {{"one", 102, {104, 105, 106, 107}}, {"two", 202, {204, 205, 206, 207}}};
dst_typ_t *dst;
void *buf = HDcalloc(2, sizeof(dst_typ_t));
void *bkg = HDcalloc(2, sizeof(dst_typ_t));
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
Expand Down Expand Up @@ -490,8 +490,8 @@ test_compound_5()
}

/* Free memory buffers */
HDfree(buf);
HDfree(bkg);
free(buf);
free(bkg);
dst = NULL;
PASSED();
} // end of try block
Expand Down Expand Up @@ -539,9 +539,9 @@ test_compound_6()
SUBTEST("Compound Element Growing");
try {
/* Sizes should be the same, but be careful just in case */
buf = static_cast<unsigned char *>(HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))));
bkg = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(dst_typ_t)));
orig = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(src_typ_t)));
buf = static_cast<unsigned char *>(malloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))));
bkg = static_cast<unsigned char *>(malloc(nelmts * sizeof(dst_typ_t)));
orig = static_cast<unsigned char *>(malloc(nelmts * sizeof(src_typ_t)));
for (i = 0; i < nelmts; i++) {
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
s_ptr->b = (i * 8 + 1) & 0x7fff;
Expand Down Expand Up @@ -574,9 +574,9 @@ test_compound_6()
}

/* Release resources */
HDfree(buf);
HDfree(bkg);
HDfree(orig);
free(buf);
free(bkg);
free(orig);
s_ptr = NULL;
d_ptr = NULL;
st.close();
Expand Down
12 changes: 6 additions & 6 deletions c++/test/tdspl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ test_transfplist()
// Find out the length of the transform expression, allocate the buffer
// for it, then read and verify the expression from the copied plist
size_t tran_len = static_cast<size_t>(dxpl_c_to_f_copy.getDataTransform(NULL));
char *c_to_f_read = static_cast<char *>(HDmalloc(tran_len + 1));
char *c_to_f_read = static_cast<char *>(malloc(tran_len + 1));
HDmemset(c_to_f_read, 0, tran_len + 1);
dxpl_c_to_f_copy.getDataTransform(c_to_f_read, tran_len + 1);
verify_val(const_cast<const char *>(c_to_f_read), const_cast<const char *>(c_to_f),
"DSetMemXferPropList::getDataTransform", __LINE__, __FILE__);
HDfree(c_to_f_read);
free(c_to_f_read);

//
// Read the expression of each of the prop lists and verify the read
Expand All @@ -75,12 +75,12 @@ test_transfplist()
// Get and verify the expression with:
// ssize_t getDataTransform(char* exp, const size_t buf_size [default=0])
tran_len = static_cast<size_t>(dxpl_c_to_f.getDataTransform(NULL));
c_to_f_read = static_cast<char *>(HDmalloc(tran_len + 1));
c_to_f_read = static_cast<char *>(malloc(tran_len + 1));
HDmemset(c_to_f_read, 0, tran_len + 1);
dxpl_c_to_f.getDataTransform(c_to_f_read, tran_len + 1);
verify_val(const_cast<const char *>(c_to_f_read), const_cast<const char *>(c_to_f),
"DSetMemXferPropList::getDataTransform", __LINE__, __FILE__);
HDfree(c_to_f_read);
free(c_to_f_read);

// Get and verify the expression with:
// H5std_string DSetMemXferPropList::getDataTransform()
Expand All @@ -91,12 +91,12 @@ test_transfplist()
// Get and verify the expression with:
// ssize_t getDataTransform(char* exp, const size_t buf_size)
tran_len = static_cast<size_t>(dxpl_utrans_inv.getDataTransform(NULL, 0));
char *utrans_inv_read = static_cast<char *>(HDmalloc(tran_len + 1));
char *utrans_inv_read = static_cast<char *>(malloc(tran_len + 1));
HDmemset(utrans_inv_read, 0, tran_len + 1);
dxpl_utrans_inv.getDataTransform(utrans_inv_read, tran_len + 1);
verify_val(const_cast<const char *>(utrans_inv_read), const_cast<const char *>(utrans_inv),
"DSetMemXferPropList::getDataTransform", __LINE__, __FILE__);
HDfree(utrans_inv_read);
free(utrans_inv_read);

PASSED();
}
Expand Down
2 changes: 1 addition & 1 deletion c++/test/titerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ test_iter_group(FileAccPropList &fapl)

/* Free the dataset names */
for (int i = 0; i < NDATASETS + 2; i++)
HDfree(lnames[i]);
free(lnames[i]);

// Everything will be closed as they go out of scope

Expand Down
48 changes: 24 additions & 24 deletions c++/test/trefer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ test_reference_params()

// Allocate write & read buffers
size_t temp_size = MAX(sizeof(unsigned), sizeof(hobj_ref_t));
wbuf = static_cast<hobj_ref_t *>(HDmalloc(temp_size * SPACE1_DIM1));
rbuf = static_cast<hobj_ref_t *>(HDmalloc(temp_size * SPACE1_DIM1));
tbuf = static_cast<hobj_ref_t *>(HDmalloc(temp_size * SPACE1_DIM1));
wbuf = static_cast<hobj_ref_t *>(malloc(temp_size * SPACE1_DIM1));
rbuf = static_cast<hobj_ref_t *>(malloc(temp_size * SPACE1_DIM1));
tbuf = static_cast<hobj_ref_t *>(malloc(temp_size * SPACE1_DIM1));

// Create file FILE1
file1 = new H5File(FILE1, H5F_ACC_TRUNC);
Expand Down Expand Up @@ -168,9 +168,9 @@ test_reference_params()
// Let sid1 go out of scope

// Free memory buffers
HDfree(wbuf);
HDfree(rbuf);
HDfree(tbuf);
free(wbuf);
free(rbuf);
free(tbuf);

PASSED();
} // end try
Expand Down Expand Up @@ -206,9 +206,9 @@ test_reference_obj()

// Allocate write & read buffers
size_t temp_size = MAX(sizeof(unsigned), sizeof(hobj_ref_t));
wbuf = static_cast<hobj_ref_t *>(HDmalloc(temp_size * SPACE1_DIM1));
rbuf = static_cast<hobj_ref_t *>(HDmalloc(temp_size * SPACE1_DIM1));
tbuf = static_cast<hobj_ref_t *>(HDmalloc(temp_size * SPACE1_DIM1));
wbuf = static_cast<hobj_ref_t *>(malloc(temp_size * SPACE1_DIM1));
rbuf = static_cast<hobj_ref_t *>(malloc(temp_size * SPACE1_DIM1));
tbuf = static_cast<hobj_ref_t *>(malloc(temp_size * SPACE1_DIM1));

// Create file FILE1
file1 = new H5File(FILE1, H5F_ACC_TRUNC);
Expand Down Expand Up @@ -368,9 +368,9 @@ test_reference_obj()
file1->close();

// Free allocated buffers
HDfree(wbuf);
HDfree(rbuf);
HDfree(tbuf);
free(wbuf);
free(rbuf);
free(tbuf);

PASSED();
} // end try
Expand Down Expand Up @@ -555,10 +555,10 @@ test_reference_region_1D()
*drbuf; // Buffer for reading numeric data from disk

// Allocate write & read buffers
wbuf = static_cast<hdset_reg_ref_t *>(HDcalloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1));
rbuf = static_cast<hdset_reg_ref_t *>(HDmalloc(sizeof(hdset_reg_ref_t) * SPACE1_DIM1));
dwbuf = static_cast<uint8_t *>(HDmalloc(sizeof(uint8_t) * SPACE3_DIM1));
drbuf = static_cast<uint8_t *>(HDcalloc(sizeof(uint8_t), SPACE3_DIM1));
wbuf = static_cast<hdset_reg_ref_t *>(calloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1));
rbuf = static_cast<hdset_reg_ref_t *>(malloc(sizeof(hdset_reg_ref_t) * SPACE1_DIM1));
dwbuf = static_cast<uint8_t *>(malloc(sizeof(uint8_t) * SPACE3_DIM1));
drbuf = static_cast<uint8_t *>(calloc(sizeof(uint8_t), SPACE3_DIM1));

// Create file FILE1
H5File file1(FILE2, H5F_ACC_TRUNC);
Expand Down Expand Up @@ -714,7 +714,7 @@ test_reference_region_1D()

/* Allocate space for the hyperslab blocks */
coords =
static_cast<hsize_t *>(HDmalloc(static_cast<size_t>(nelms) * SPACE3_RANK * sizeof(hsize_t) * 2));
static_cast<hsize_t *>(malloc(static_cast<size_t>(nelms) * SPACE3_RANK * sizeof(hsize_t) * 2));

// Get the list of hyperslab blocks currently selected
reg_sp.getSelectHyperBlocklist(0, static_cast<hsize_t>(nelms), coords);
Expand Down Expand Up @@ -751,7 +751,7 @@ test_reference_region_1D()
verify_val(static_cast<long>(coords[28]), 72, "Hyperslab Coordinates", __LINE__, __FILE__);
verify_val(static_cast<long>(coords[29]), 73, "Hyperslab Coordinates", __LINE__, __FILE__);

HDfree(coords);
free(coords);

// Check boundaries
reg_sp.getSelectBounds(low, high);
Expand All @@ -774,7 +774,7 @@ test_reference_region_1D()

/* Allocate space for the hyperslab blocks */
coords =
static_cast<hsize_t *>(HDmalloc(static_cast<size_t>(nelmspts) * SPACE3_RANK * sizeof(hsize_t)));
static_cast<hsize_t *>(malloc(static_cast<size_t>(nelmspts) * SPACE3_RANK * sizeof(hsize_t)));

// Get the list of element points currently selected
elm_sp.getSelectElemPointlist(0, static_cast<hsize_t>(nelmspts), coords);
Expand All @@ -791,7 +791,7 @@ test_reference_region_1D()
verify_val(coords[8], coord1[8][0], "Element Coordinates", __LINE__, __FILE__);
verify_val(coords[9], coord1[9][0], "Element Coordinates", __LINE__, __FILE__);

HDfree(coords);
free(coords);

// Check boundaries
elm_sp.getSelectBounds(low, high);
Expand All @@ -808,10 +808,10 @@ test_reference_region_1D()
file1.close();

// Free memory buffers
HDfree(wbuf);
HDfree(rbuf);
HDfree(dwbuf);
HDfree(drbuf);
free(wbuf);
free(rbuf);
free(dwbuf);
free(drbuf);

PASSED();
} // end try
Expand Down
Loading