summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Young <dyoung@hdfgroup.org>2022-04-20 21:02:36 (GMT)
committerDavid Young <dyoung@hdfgroup.org>2022-04-20 21:02:36 (GMT)
commit066f8241708e51f1c1edbc9a46f5b1fa2d295caa (patch)
tree1967bc808a34a6de39bf68d98ed2775260f0d7ca
parentcbaeb279ae62a24856e0e77c552c0767ef44de68 (diff)
downloadhdf5-066f8241708e51f1c1edbc9a46f5b1fa2d295caa.zip
hdf5-066f8241708e51f1c1edbc9a46f5b1fa2d295caa.tar.gz
hdf5-066f8241708e51f1c1edbc9a46f5b1fa2d295caa.tar.bz2
Move the alignment computation for miscellaneous types from
H5detect.c to H5Tnative.c and rename H5T__init_native_int() to H5T__init_native_internal() to try to match its more general purpose.
-rw-r--r--src/H5T.c2
-rw-r--r--src/H5Tnative.c31
-rw-r--r--src/H5Tpkg.h2
-rw-r--r--src/H5detect.c65
4 files changed, 36 insertions, 64 deletions
diff --git a/src/H5T.c b/src/H5T.c
index 7dae410..39d7b91 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -763,7 +763,7 @@ H5T_init(void)
if (H5T__init_native() < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize interface")
- if (H5T__init_native_int() < 0)
+ if (H5T__init_native_internal() < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize integers")
/* Get the atomic datatype structures needed by the initialization code below */
diff --git a/src/H5Tnative.c b/src/H5Tnative.c
index 8c94be4..1fc49e4 100644
--- a/src/H5Tnative.c
+++ b/src/H5Tnative.c
@@ -973,9 +973,12 @@ get_host_byte_order(void)
/* Establish `H5T_t`s for C99 integer types including fixed- and
* minimum-width types (uint16_t, uint_least16_t, uint_fast16_t, ...).
+ *
+ * Also establish alignment for some miscellaneous types: pointers,
+ * HDF5 references, and so on.
*/
herr_t
-H5T__init_native_int(void)
+H5T__init_native_internal(void)
{
/* Here we construct a type that lets us find alignment constraints
* without using the alignof operator, which is not available in C99.
@@ -1122,6 +1125,26 @@ H5T__init_native_int(void)
char c;
uint_fast64_t x;
} UINT_FAST64;
+ struct {
+ char c;
+ void *x;
+ } pointer;
+ struct {
+ char c;
+ hvl_t x;
+ } hvl;
+ struct {
+ char c;
+ hobj_ref_t x;
+ } hobjref;
+ struct {
+ char c;
+ hdset_reg_ref_t x;
+ } hdsetregref;
+ struct {
+ char c;
+ H5R_ref_t x;
+ } ref;
} alignments_t;
/* Describe a C99 type, `type`, and tell where to write its
@@ -1231,5 +1254,11 @@ H5T__init_native_int(void)
}
}
+ H5T_POINTER_ALIGN_g = TAG_ALIGNMENT(pointer);
+ H5T_HVL_ALIGN_g = TAG_ALIGNMENT(hvl);
+ H5T_HOBJREF_ALIGN_g = TAG_ALIGNMENT(hobjref);
+ H5T_HDSETREGREF_ALIGN_g = TAG_ALIGNMENT(hdsetregref);
+ H5T_REF_ALIGN_g = TAG_ALIGNMENT(ref);
+
return SUCCEED;
}
diff --git a/src/H5Tpkg.h b/src/H5Tpkg.h
index 6b05465..72afbeb 100644
--- a/src/H5Tpkg.h
+++ b/src/H5Tpkg.h
@@ -469,7 +469,7 @@ H5FL_EXTERN(H5T_shared_t);
/* Common functions */
H5_DLL herr_t H5T__init_native(void);
-H5_DLL herr_t H5T__init_native_int(void);
+H5_DLL herr_t H5T__init_native_internal(void);
H5_DLL H5T_t *H5T__create(H5T_class_t type, size_t size);
H5_DLL H5T_t *H5T__alloc(void);
H5_DLL herr_t H5T__free(H5T_t *dt);
diff --git a/src/H5detect.c b/src/H5detect.c
index 54435fb..4d131dc 100644
--- a/src/H5detect.c
+++ b/src/H5detect.c
@@ -80,23 +80,15 @@ typedef struct detected_t {
unsigned int comp_align; /* alignment for structure */
} detected_t;
-/* This structure holds structure alignment for pointers, vlen and reference
- * types. */
-typedef struct malign_t {
- const char * name;
- unsigned int comp_align; /* alignment for structure */
-} malign_t;
-
FILE *rawoutstream = NULL;
/* global variables types detection code */
H5_GCC_DIAG_OFF("larger-than=")
static detected_t d_g[MAXDETECT];
H5_GCC_DIAG_ON("larger-than=")
-static malign_t m_g[MAXDETECT];
-static volatile int nd_g = 0, na_g = 0;
+static volatile int nd_g = 0;
-static void print_results(int nd, detected_t *d, int na, malign_t *m);
+static void print_results(int nd, detected_t *d);
static void iprint(detected_t *);
static int byte_cmp(int, const void *, const void *, const unsigned char *);
static unsigned int bit_cmp(unsigned int, int *, void *, void *, const unsigned char *);
@@ -107,7 +99,6 @@ static void precision(detected_t *);
static void print_header(void);
static void detect_C89_floats(void);
static void detect_C99_floats(void);
-static void detect_alignments(void);
/*-------------------------------------------------------------------------
* Function: precision
@@ -257,21 +248,6 @@ precision(detected_t *d)
} \
}
-/*-------------------------------------------------------------------------
- * Function: DETECT_M
- *
- * Purpose: This macro takes only miscellaneous structures or pointer.
- * It constructs the names and decides the alignment in structure.
- *
- * Return: void
- *-------------------------------------------------------------------------
- */
-#define DETECT_M(TYPE, VAR, INFO) \
- { \
- INFO.name = #VAR; \
- COMP_ALIGNMENT(TYPE, INFO.comp_align); \
- }
-
/* Detect alignment for C structure */
#define COMP_ALIGNMENT(TYPE, COMP_ALIGN) \
{ \
@@ -292,7 +268,7 @@ precision(detected_t *d)
*-------------------------------------------------------------------------
*/
static void
-print_results(int nd, detected_t *d, int na, malign_t *misc_align)
+print_results(int nd, detected_t *d)
{
int byte_order = 0; /*byte order of data types*/
int i, j;
@@ -490,12 +466,6 @@ H5T__init_native(void)\n\
"BE");
}
- /* Structure alignment for pointers, vlen and reference types */
- fprintf(rawoutstream, "\n /* Structure alignment for pointers, vlen and reference types */\n");
- for (j = 0; j < na; j++)
- fprintf(rawoutstream, " H5T_%s_ALIGN_g = %lu;\n", misc_align[j].name,
- (unsigned long)(misc_align[j].comp_align));
-
fprintf(rawoutstream, "\
\n\
done:\n\
@@ -992,30 +962,6 @@ detect_C99_floats(void)
}
/*-------------------------------------------------------------------------
- * Function: detect_alignments
- *
- * Purpose: Detect structure alignments
- *
- * Return: void
- *-------------------------------------------------------------------------
- */
-static void HDF_NO_UBSAN
-detect_alignments(void)
-{
- /* Detect structure alignment for pointers, vlen and reference types */
- DETECT_M(void *, POINTER, m_g[na_g]);
- na_g++;
- DETECT_M(hvl_t, HVL, m_g[na_g]);
- na_g++;
- DETECT_M(hobj_ref_t, HOBJREF, m_g[na_g]);
- na_g++;
- DETECT_M(hdset_reg_ref_t, HDSETREGREF, m_g[na_g]);
- na_g++;
- DETECT_M(H5R_ref_t, REF, m_g[na_g]);
- na_g++;
-}
-
-/*-------------------------------------------------------------------------
* Function: main
*
* Purpose: Main entry point.
@@ -1051,10 +997,7 @@ main(int argc, char *argv[])
/* C99 floating point types */
detect_C99_floats();
- /* Detect structure alignment */
- detect_alignments();
-
- print_results(nd_g, d_g, na_g, m_g);
+ print_results(nd_g, d_g);
if (rawoutstream && rawoutstream != stdout) {
if (HDfclose(rawoutstream))