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

Fixes stack size warnings in dtransform #1696

Merged
merged 4 commits into from
Apr 27, 2022
Merged
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
36 changes: 26 additions & 10 deletions test/dtransform.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ const int transformData[ROWS][COLS] = {{36, 31, 25, 19, 13, 7, 1, 5, 11, 16, 22,

#define TEST_TYPE_CONTIG(XFORM, TYPE, HDF_TYPE, TEST_STR, COMPARE_DATA, SIGNED) \
{ \
TYPE array[ROWS][COLS]; \
struct { \
TYPE arr[ROWS][COLS]; \
} *array = NULL; \
const char *f_to_c = "(5/9.0)*(x-32)"; \
/* utrans is a transform for char types: numbers are restricted from -128 to 127, fits into char */ \
const char *utrans = "(x/4+25)*3"; \
Expand All @@ -129,6 +131,10 @@ const int transformData[ROWS][COLS] = {{36, 31, 25, 19, 13, 7, 1, 5, 11, 16, 22,
H5T_order_t order; \
hsize_t dim[2] = {ROWS, COLS}; \
\
/* NOTE: If this macro encounters errors, this memory will leak */ \
if (NULL == (array = HDcalloc(1, sizeof(*array)))) \
TEST_ERROR; \
Copy link
Member Author

@derobins derobins Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the macros, cleaning the memory on errors (when the test is just going to die anyway) seems like it's not worth the extra code complexity, macros, and goto statements.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, seems fine in a limited way for the test code

\
if ((dataspace = H5Screate_simple(2, dim, NULL)) < 0) \
TEST_ERROR; \
if ((dset = H5Dcreate2(file_id, "/transformtest_" TEST_STR, HDF_TYPE, dataspace, H5P_DEFAULT, \
Expand Down Expand Up @@ -177,25 +183,25 @@ const int transformData[ROWS][COLS] = {{36, 31, 25, 19, 13, 7, 1, 5, 11, 16, 22,
if (H5Dread(dset, HDF_TYPE, H5S_ALL, H5S_ALL, XFORM, array) < 0) \
TEST_ERROR; \
if (SIGNED) \
COMPARE(TYPE, array, COMPARE_DATA, 2) \
COMPARE(TYPE, array->arr, COMPARE_DATA, 2) \
else \
UCOMPARE(TYPE, array, COMPARE_DATA, 4) \
UCOMPARE(TYPE, array->arr, COMPARE_DATA, 4) \
\
TESTING("contiguous, byte order conversion (" TEST_STR "->" TEST_STR ")") \
\
if (H5Dread(dset_nn, HDF_TYPE, H5S_ALL, H5S_ALL, XFORM, array) < 0) \
TEST_ERROR; \
if (SIGNED) \
COMPARE(TYPE, array, COMPARE_DATA, 2) \
COMPARE(TYPE, array->arr, COMPARE_DATA, 2) \
else \
UCOMPARE(TYPE, array, COMPARE_DATA, 4) \
UCOMPARE(TYPE, array->arr, COMPARE_DATA, 4) \
\
if (SIGNED) { \
TESTING("contiguous, with type conversion (float->" TEST_STR ")") \
\
if (H5Dread(dset_id_float, HDF_TYPE, H5S_ALL, H5S_ALL, XFORM, array) < 0) \
TEST_ERROR; \
COMPARE(TYPE, array, COMPARE_DATA, 2) \
COMPARE(TYPE, array->arr, COMPARE_DATA, 2) \
} \
\
if (H5Dclose(dset_nn) < 0) \
Expand All @@ -204,11 +210,15 @@ const int transformData[ROWS][COLS] = {{36, 31, 25, 19, 13, 7, 1, 5, 11, 16, 22,
TEST_ERROR; \
if (H5Sclose(dataspace) < 0) \
TEST_ERROR; \
\
HDfree(array); \
}

#define TEST_TYPE_CHUNK(XFORM, TYPE, HDF_TYPE, TEST_STR, COMPARE_DATA, SIGNED) \
{ \
TYPE array[ROWS][COLS]; \
struct { \
TYPE arr[ROWS][COLS]; \
} *array = NULL; \
const char *f_to_c = "(5/9.0)*(x-32)"; \
/* utrans is a transform for char types: numbers are restricted from -128 to 127, fits into char */ \
const char *utrans = "(x/4+25)*3"; \
Expand All @@ -217,6 +227,10 @@ const int transformData[ROWS][COLS] = {{36, 31, 25, 19, 13, 7, 1, 5, 11, 16, 22,
hsize_t dim[2] = {ROWS, COLS}; \
hsize_t offset[2] = {0, 0}; \
\
/* NOTE: If this macro encounters errors, this memory will leak */ \
if (NULL == (array = HDcalloc(1, sizeof(*array)))) \
TEST_ERROR; \
\
if ((dataspace = H5Screate_simple(2, dim, NULL)) < 0) \
TEST_ERROR; \
\
Expand Down Expand Up @@ -263,16 +277,16 @@ const int transformData[ROWS][COLS] = {{36, 31, 25, 19, 13, 7, 1, 5, 11, 16, 22,
if (H5Dread(dset_chunk, HDF_TYPE, memspace, filespace, XFORM, array) < 0) \
TEST_ERROR; \
if (SIGNED) \
COMPARE(TYPE, array, COMPARE_DATA, 2) \
COMPARE(TYPE, array->arr, COMPARE_DATA, 2) \
else \
UCOMPARE(TYPE, array, COMPARE_DATA, 4) \
UCOMPARE(TYPE, array->arr, COMPARE_DATA, 4) \
\
if (SIGNED) { \
TESTING("chunked, with type conversion (float->" TEST_STR ")") \
\
if (H5Dread(dset_id_float_chunk, HDF_TYPE, memspace, filespace, XFORM, array) < 0) \
TEST_ERROR; \
COMPARE(TYPE, array, COMPARE_DATA, 2) \
COMPARE(TYPE, array->arr, COMPARE_DATA, 2) \
} \
\
if (H5Pclose(cparms) < 0) \
Expand All @@ -283,6 +297,8 @@ const int transformData[ROWS][COLS] = {{36, 31, 25, 19, 13, 7, 1, 5, 11, 16, 22,
TEST_ERROR; \
if (H5Sclose(memspace) < 0) \
TEST_ERROR; \
\
HDfree(array); \
}

#define INVALID_SET_TEST(TRANSFORM) \
Expand Down