File Add-H5T_is_numeric_with_unusual_unused_bits.patch of Package hdf5.34857
From: Egbert Eich <eich@suse.com>
Date: Tue May 21 13:45:37 2024 +0200
Subject: Add H5T_is_numeric_with_unusual_unused_bits()
Patch-mainline: Upstream
Git-repo: https://github.com/HDFGroup/hdf5
Git-commit: efdc817f62e410f8f2167a1230290bc1b47f4b50
References: bsc#1224158
Signed-off-by: Egbert Eich <eich@suse.de>
---
src/H5T.c | 41 +++++++++++++++++++++++++++++++++++++++++
src/H5Tprivate.h | 1 +
2 files changed, 42 insertions(+)
diff --git a/src/H5T.c b/src/H5T.c
index 3c596127ae..9bc8e8bbbd 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -39,6 +39,7 @@
#include "H5MMprivate.h" /* Memory management */
#include "H5Pprivate.h" /* Property lists */
#include "H5Tpkg.h" /* Datatypes */
+#include "H5VMprivate.h" /* Vectors and arrays */
/****************/
/* Local Macros */
@@ -6066,3 +6067,43 @@ H5T_patch_vlen_file(H5T_t *dt, H5F_t *file)
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5T_patch_vlen_file() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_is_numeric_with_unusual_unused_bits
+ *
+ * Purpose: Detect if a datatype is a numeric datatype (int, float, or
+ * bitfield) with an unusual # of unused bits. This means
+ * that the precision (i.e. the # of bits used) is less than
+ * the size of the datatype, at power-of-two boundaries.
+ *
+ * Return: true/false on success, can't fail
+ *
+ *-------------------------------------------------------------------------
+ */
+bool
+H5T_is_numeric_with_unusual_unused_bits(const H5T_t *dt)
+{
+ bool ret_value = false;
+
+ FUNC_ENTER_NOAPI_NOINIT_NOERR
+
+ /* Sanity check */
+ assert(dt);
+ assert(dt->shared);
+
+ /* Is the correct type? */
+ if (H5T_INTEGER == dt->shared->type || H5T_FLOAT == dt->shared->type || H5T_BITFIELD == dt->shared->type)
+
+ /* Has unused bits? */
+ if (dt->shared->u.atomic.prec < (dt->shared->size * 8)) {
+ unsigned surround_bits =
+ 1U << (1 + H5VM_log2_gen((dt->shared->u.atomic.prec + dt->shared->u.atomic.offset) - 1));
+
+ /* Unused bits are unusually large? */
+ if (dt->shared->size > 1 && ((dt->shared->size * 8) > surround_bits))
+ HGOTO_DONE(true);
+ }
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5T_is_numeric_with_unusual_unused_bits() */
diff --git a/src/H5Tprivate.h b/src/H5Tprivate.h
index ebc506351c..4b29fa3382 100644
--- a/src/H5Tprivate.h
+++ b/src/H5Tprivate.h
@@ -136,6 +136,7 @@ H5_DLL herr_t H5T_patch_file(H5T_t *dt, H5F_t *f);
H5_DLL herr_t H5T_patch_vlen_file(H5T_t *dt, H5F_t *f);
H5_DLL htri_t H5T_is_variable_str(const H5T_t *dt);
H5_DLL htri_t H5T_is_vl_storage(const H5T_t *dt);
+H5_DLL bool H5T_is_numeric_with_unusual_unused_bits(const H5T_t *dt);
/* Reference specific functions */
H5_DLL H5R_type_t H5T_get_ref_type(const H5T_t *dt);