summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2020-04-27 15:51:58 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2020-04-27 15:51:58 (GMT)
commit9a598477c6ccecef8e43dbda6b6828b9fcac8df6 (patch)
treed86b6cc76c01f4d47f3fc542589ec4666ca1e614 /test
parentf3d23046473916d497bdf7d14381e3ef24122882 (diff)
parentc03ee563f46013d22f36a1895664a9ba876558e9 (diff)
downloadhdf5-9a598477c6ccecef8e43dbda6b6828b9fcac8df6.zip
hdf5-9a598477c6ccecef8e43dbda6b6828b9fcac8df6.tar.gz
hdf5-9a598477c6ccecef8e43dbda6b6828b9fcac8df6.tar.bz2
Merge pull request #2541 in HDFFV/hdf5 from ~DEROBINS/hdf5_der:develop_minor to develop
* commit 'c03ee563f46013d22f36a1895664a9ba876558e9': Further updates to the tools warnings fixes from code review. Updates to tools warning PR from code review. Fixes for warnings in the tools code.
Diffstat (limited to 'test')
-rw-r--r--test/h5test.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/h5test.h b/test/h5test.h
index 39ec9d7..b1ddc58 100644
--- a/test/h5test.h
+++ b/test/h5test.h
@@ -125,6 +125,65 @@ H5TEST_DLLVAR MPI_Info h5_io_info_g; /* MPI INFO object for IO */
#define H5_FILEACCESS_VFD 0x01
#define H5_FILEACCESS_LIBVER 0x02
+/* Macros to create and fill 2D arrays with a single heap allocation.
+ * These can be used to replace large stack and global arrays which raise
+ * warnings.
+ *
+ * The macros make a single heap allocation large enough to hold all the
+ * pointers and the data elements. The first part of the allocation holds
+ * the pointers, and the second part holds the data as a contiguous block
+ * in row-major order.
+ *
+ * To pass the data block to calls like H5Dread(), pass a pointer to the
+ * first array element as the data pointer (e.g., array[0] in a 2D array).
+ *
+ * The fill macro just fills the array with an increasing count value.
+ *
+ * Usage:
+ *
+ * int **array;
+ *
+ * H5TEST_ALLOCATE_2D_ARRAY(array, int, 5, 10);
+ *
+ * H5TEST_FILL_2D_ARRAY(array, int, 5, 10);
+ *
+ * (do stuff)
+ *
+ * HDfree(array);
+ */
+#define H5TEST_ALLOCATE_2D_ARRAY(ARR, TYPE, DIMS_I, DIMS_J) \
+do { \
+ /* Prefix with h5taa to avoid shadow warnings */ \
+ size_t h5taa_pointers_size = 0; \
+ size_t h5taa_data_size = 0; \
+ int h5taa_i; \
+ \
+ h5taa_pointers_size = (DIMS_I) * sizeof(TYPE *); \
+ h5taa_data_size = (DIMS_I) * (DIMS_J) * sizeof(TYPE); \
+ \
+ ARR = (TYPE **)HDmalloc(h5taa_pointers_size + h5taa_data_size); \
+ \
+ ARR[0] = (TYPE *)(ARR + (DIMS_I)); \
+ \
+ for (h5taa_i = 1; h5taa_i < (DIMS_I); h5taa_i++) \
+ ARR[h5taa_i] = ARR[h5taa_i-1] + (DIMS_J); \
+} while(0)
+
+#define H5TEST_FILL_2D_ARRAY(ARR, TYPE, DIMS_I, DIMS_J) \
+do { \
+ /* Prefix with h5tfa to avoid shadow warnings */ \
+ int h5tfa_i = 0; \
+ int h5tfa_j = 0; \
+ TYPE h5tfa_count = 0; \
+ \
+ for (h5tfa_i = 0; h5tfa_i < (DIMS_I); h5tfa_i++) \
+ for (h5tfa_j = 0; h5tfa_j < (DIMS_J); h5tfa_j++) { \
+ ARR[h5tfa_i][h5tfa_j] = h5tfa_count; \
+ h5tfa_count++; \
+ } \
+} while(0)
+
+
#ifdef __cplusplus
extern "C" {
#endif