summaryrefslogtreecommitdiffstats
path: root/hl
diff options
context:
space:
mode:
authorDana Robinson <43805+derobins@users.noreply.github.com>2022-04-18 12:29:00 (GMT)
committerGitHub <noreply@github.com>2022-04-18 12:29:00 (GMT)
commit17be6c2574222bf146ddc01eb3c8e344b1efddd0 (patch)
treefe398ef17020d852fd3b13120f13733747426ac3 /hl
parenta80897ee4944ff6008bfb3b93619ebcb58a070d1 (diff)
downloadhdf5-17be6c2574222bf146ddc01eb3c8e344b1efddd0.zip
hdf5-17be6c2574222bf146ddc01eb3c8e344b1efddd0.tar.gz
hdf5-17be6c2574222bf146ddc01eb3c8e344b1efddd0.tar.bz2
Cleans up some HL library code that inappropriately returns htri_t values cast to herr_t (#1651)
* Cleans up some HL library code that inappropriately returns htri_t values cast to herr_t * Committing clang-format changes * Formatted source Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'hl')
-rw-r--r--hl/src/H5DS.c172
-rw-r--r--hl/src/H5IM.c56
-rw-r--r--hl/src/H5LT.c81
-rw-r--r--hl/src/H5LTprivate.h17
-rw-r--r--hl/src/H5TB.c14
5 files changed, 144 insertions, 196 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c
index 387419b..d55512f 100644
--- a/hl/src/H5DS.c
+++ b/hl/src/H5DS.c
@@ -17,7 +17,7 @@
#include "H5TBprivate.h"
/* Local routines */
-static herr_t H5DS_is_reserved(hid_t did);
+static herr_t H5DS_is_reserved(hid_t did, hbool_t *is_reserved);
/*-------------------------------------------------------------------------
* Function: H5DSwith_new_ref
@@ -73,7 +73,7 @@ H5DSwith_new_ref(hid_t obj_id, hbool_t *with_new_ref)
herr_t
H5DSset_scale(hid_t dsid, const char *dimname)
{
- int has_dimlist;
+ htri_t has_dimlist;
H5I_type_t it;
/*-------------------------------------------------------------------------
@@ -92,11 +92,10 @@ H5DSset_scale(hid_t dsid, const char *dimname)
*-------------------------------------------------------------------------
*/
- /* try to find the attribute "DIMENSION_LIST" */
- if ((has_dimlist = H5LT_find_attribute(dsid, DIMENSION_LIST)) < 0)
+ /* Try to find the attribute "DIMENSION_LIST" */
+ if ((has_dimlist = H5Aexists(dsid, DIMENSION_LIST)) < 0)
return FAIL;
-
- if (has_dimlist == 1)
+ if (has_dimlist > 0)
return FAIL;
/*-------------------------------------------------------------------------
@@ -139,8 +138,8 @@ H5DSset_scale(hid_t dsid, const char *dimname)
herr_t
H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
{
- int has_dimlist;
- int has_reflist;
+ htri_t has_dimlist;
+ htri_t has_reflist;
int is_ds;
hssize_t nelmts;
hid_t sid, sid_w; /* space ID */
@@ -173,6 +172,7 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
size_t len;
int found_ds = 0;
htri_t is_scale;
+ hbool_t is_reserved;
/*-------------------------------------------------------------------------
* parameter checking
@@ -221,12 +221,14 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
if (H5I_DATASET != it1 || H5I_DATASET != it2)
return FAIL;
- /* the DS dataset cannot have dimension scales */
- if (H5LT_find_attribute(dsid, DIMENSION_LIST) == 1)
+ /* The DS dataset cannot have dimension scales */
+ if (H5Aexists(dsid, DIMENSION_LIST) > 0)
return FAIL;
- /* check if the dataset is a "reserved" dataset (image, table) */
- if (H5DS_is_reserved(did) == 1)
+ /* Check if the dataset is a "reserved" dataset (image, table) */
+ if (H5DS_is_reserved(did, &is_reserved) < 0)
+ return FAIL;
+ if (is_reserved == TRUE)
return FAIL;
/*-------------------------------------------------------------------------
@@ -279,8 +281,8 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
if (H5Rcreate(&dsl.ref, did, ".", H5R_OBJECT, (hid_t)-1) < 0)
return FAIL;
}
- /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
- if ((has_dimlist = H5LT_find_attribute(did, DIMENSION_LIST)) < 0)
+ /* Try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
+ if ((has_dimlist = H5Aexists(did, DIMENSION_LIST)) < 0)
return FAIL;
/*-------------------------------------------------------------------------
@@ -354,7 +356,7 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
* and insert the new reference
*-------------------------------------------------------------------------
*/
- else if (has_dimlist == 1) {
+ else if (has_dimlist > 0) {
if ((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
goto out;
@@ -469,7 +471,7 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
*/
/* try to find the attribute "REFERENCE_LIST" on the >>DS<< dataset */
- if ((has_reflist = H5LT_find_attribute(dsid, REFERENCE_LIST)) < 0)
+ if ((has_reflist = H5Aexists(dsid, REFERENCE_LIST)) < 0)
goto out;
/*-------------------------------------------------------------------------
@@ -530,7 +532,7 @@ H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
* the "REFERENCE_LIST" array already exists, open it and extend it
*-------------------------------------------------------------------------
*/
- else if (has_reflist == 1) {
+ else if (has_reflist > 0) {
hid_t tmp_id; /* Temporary DS dataset ID to recreate reference */
int j;
@@ -727,8 +729,8 @@ out:
herr_t
H5DSdetach_scale(hid_t did, hid_t dsid, unsigned int idx)
{
- int has_dimlist;
- int has_reflist;
+ htri_t has_dimlist;
+ htri_t has_reflist;
hssize_t nelmts;
hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
hid_t did_i; /* dataset ID in REFERENCE_LIST */
@@ -804,10 +806,9 @@ H5DSdetach_scale(hid_t did, hid_t dsid, unsigned int idx)
*-------------------------------------------------------------------------
*/
- /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
- if ((has_dimlist = H5LT_find_attribute(did, DIMENSION_LIST)) < 0)
+ /* Try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
+ if ((has_dimlist = H5Aexists(did, DIMENSION_LIST)) < 0)
return FAIL;
-
if (has_dimlist == 0)
return FAIL;
@@ -833,9 +834,8 @@ H5DSdetach_scale(hid_t did, hid_t dsid, unsigned int idx)
*/
/* try to find the attribute "REFERENCE_LIST" on the >>DS<< dataset */
- if ((has_reflist = H5LT_find_attribute(dsid, REFERENCE_LIST)) < 0)
+ if ((has_reflist = H5Aexists(dsid, REFERENCE_LIST)) < 0)
return FAIL;
-
if (has_reflist == 0)
return FAIL;
@@ -1228,8 +1228,8 @@ out:
htri_t
H5DSis_attached(hid_t did, hid_t dsid, unsigned int idx)
{
- int has_dimlist;
- int has_reflist;
+ htri_t has_dimlist;
+ htri_t has_reflist;
hssize_t nelmts;
hid_t sid; /* space ID */
hid_t tid = H5I_INVALID_HID; /* attribute type ID */
@@ -1319,7 +1319,7 @@ H5DSis_attached(hid_t did, hid_t dsid, unsigned int idx)
return FAIL;
/* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
- if ((has_dimlist = H5LT_find_attribute(did, DIMENSION_LIST)) < 0)
+ if ((has_dimlist = H5Aexists(did, DIMENSION_LIST)) < 0)
return FAIL;
/*-------------------------------------------------------------------------
@@ -1327,7 +1327,7 @@ H5DSis_attached(hid_t did, hid_t dsid, unsigned int idx)
*-------------------------------------------------------------------------
*/
- if (has_dimlist == 1) {
+ if (has_dimlist > 0) {
if ((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
goto out;
@@ -1407,7 +1407,7 @@ H5DSis_attached(hid_t did, hid_t dsid, unsigned int idx)
*/
/* try to find the attribute "REFERENCE_LIST" on the >>DS<< dataset */
- if ((has_reflist = H5LT_find_attribute(dsid, REFERENCE_LIST)) < 0)
+ if ((has_reflist = H5Aexists(dsid, REFERENCE_LIST)) < 0)
goto out;
/*-------------------------------------------------------------------------
@@ -1415,7 +1415,7 @@ H5DSis_attached(hid_t did, hid_t dsid, unsigned int idx)
*-------------------------------------------------------------------------
*/
- if (has_reflist == 1) {
+ if (has_reflist > 0) {
if ((aid = H5Aopen(dsid, REFERENCE_LIST, H5P_DEFAULT)) < 0)
goto out;
@@ -1610,7 +1610,7 @@ H5DSiterate_scales(hid_t did, unsigned int dim, int *ds_idx, H5DS_iterate_t visi
herr_t ret_value = 0;
int j_idx;
int nscales;
- int has_dimlist;
+ htri_t has_dimlist;
int i;
hbool_t is_new_ref;
@@ -1658,14 +1658,13 @@ H5DSiterate_scales(hid_t did, unsigned int dim, int *ds_idx, H5DS_iterate_t visi
if (dim >= (unsigned)rank)
return FAIL;
- /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
- if ((has_dimlist = H5LT_find_attribute(did, DIMENSION_LIST)) < 0)
+ /* Try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
+ if ((has_dimlist = H5Aexists(did, DIMENSION_LIST)) < 0)
return FAIL;
-
if (has_dimlist == 0)
return SUCCEED;
- else if (has_dimlist == 1) {
+ else if (has_dimlist > 0) {
if ((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
goto out;
if ((tid = H5Aget_type(aid)) < 0)
@@ -1788,7 +1787,7 @@ out:
herr_t
H5DSset_label(hid_t did, unsigned int idx, const char *label)
{
- int has_labels;
+ htri_t has_labels;
hid_t sid = H5I_INVALID_HID; /* space ID */
hid_t tid = H5I_INVALID_HID; /* attribute type ID */
hid_t aid = H5I_INVALID_HID; /* attribute ID */
@@ -1838,7 +1837,7 @@ H5DSset_label(hid_t did, unsigned int idx, const char *label)
*/
/* try to find the attribute "DIMENSION_LABELS" on the >>data<< dataset */
- if ((has_labels = H5LT_find_attribute(did, DIMENSION_LABELS)) < 0)
+ if ((has_labels = H5Aexists(did, DIMENSION_LABELS)) < 0)
return FAIL;
/*-------------------------------------------------------------------------
@@ -1991,7 +1990,7 @@ out:
ssize_t
H5DSget_label(hid_t did, unsigned int idx, char *label, size_t size)
{
- int has_labels;
+ htri_t has_labels;
hid_t sid = H5I_INVALID_HID; /* space ID */
hid_t tid = H5I_INVALID_HID; /* attribute type ID */
hid_t aid = H5I_INVALID_HID; /* attribute ID */
@@ -2033,11 +2032,11 @@ H5DSget_label(hid_t did, unsigned int idx, char *label, size_t size)
*-------------------------------------------------------------------------
*/
- /* try to find the attribute "DIMENSION_LABELS" on the >>data<< dataset */
- if ((has_labels = H5LT_find_attribute(did, DIMENSION_LABELS)) < 0)
+ /* Try to find the attribute "DIMENSION_LABELS" on the >>data<< dataset */
+ if ((has_labels = H5Aexists(did, DIMENSION_LABELS)) < 0)
return FAIL;
- /* return 0 and NULL for label if no label found */
+ /* Return 0 and NULL for label if no label found */
if (has_labels == 0) {
if (label)
label[0] = 0;
@@ -2049,7 +2048,6 @@ H5DSget_label(hid_t did, unsigned int idx, char *label, size_t size)
*-------------------------------------------------------------------------
*/
- assert(has_labels == 1);
if ((aid = H5Aopen(did, DIMENSION_LABELS, H5P_DEFAULT)) < 0)
goto out;
@@ -2146,7 +2144,7 @@ H5DSget_scale_name(hid_t did, char *name, size_t size)
H5I_type_t it; /* ID type */
size_t nbytes;
size_t copy_len;
- int has_name;
+ htri_t has_name;
char * buf = NULL;
/*-------------------------------------------------------------------------
@@ -2169,9 +2167,8 @@ H5DSget_scale_name(hid_t did, char *name, size_t size)
*/
/* try to find the attribute "NAME" on the >>DS<< dataset */
- if ((has_name = H5LT_find_attribute(did, "NAME")) < 0)
+ if ((has_name = H5Aexists(did, "NAME")) < 0)
return FAIL;
-
if (has_name == 0)
return 0;
@@ -2259,7 +2256,7 @@ H5DSis_scale(hid_t did)
{
hid_t tid = H5I_INVALID_HID; /* attribute type ID */
hid_t aid = H5I_INVALID_HID; /* attribute ID */
- herr_t attr_class; /* has the "CLASS" attribute */
+ htri_t attr_class; /* has the "CLASS" attribute */
htri_t is_ds = -1; /* set to "not a dimension scale" */
H5I_type_t it; /* type of identifier */
char * buf = NULL; /* buffer to read name of attribute */
@@ -2279,7 +2276,7 @@ H5DSis_scale(hid_t did)
goto out;
/* try to find the attribute "CLASS" on the dataset */
- if ((attr_class = H5LT_find_attribute(did, "CLASS")) < 0)
+ if ((attr_class = H5Aexists(did, "CLASS")) < 0)
goto out;
if (attr_class == 0) {
@@ -2370,7 +2367,7 @@ out:
int
H5DSget_num_scales(hid_t did, unsigned int idx)
{
- int has_dimlist;
+ htri_t has_dimlist;
hid_t sid; /* space ID */
hid_t tid = H5I_INVALID_HID; /* attribute type ID */
hid_t aid = H5I_INVALID_HID; /* attribute ID */
@@ -2410,11 +2407,11 @@ H5DSget_num_scales(hid_t did, unsigned int idx)
if (idx >= (unsigned int)rank)
return FAIL;
- /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
- if ((has_dimlist = H5LT_find_attribute(did, DIMENSION_LIST)) < 0)
+ /* Try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
+ if ((has_dimlist = H5Aexists(did, DIMENSION_LIST)) < 0)
return FAIL;
- /* it does not exist */
+ /* No scales */
if (has_dimlist == 0)
return 0;
@@ -2475,86 +2472,77 @@ out:
/*-------------------------------------------------------------------------
* Function: H5DS_is_reserved
*
- * Purpose: Verify that a dataset's CLASS is either an image, palette or table
- *
- * Return: true, false, fail
- *
- * Programmer: Pedro Vicente
- *
- * Date: March 19, 2005
+ * Purpose: Verify that a dataset's CLASS is either an image, palette or
+ * table
*
+ * Return: SUCCEED/FAIL
*-------------------------------------------------------------------------
*/
static herr_t
-H5DS_is_reserved(hid_t did)
+H5DS_is_reserved(hid_t did, hbool_t *is_reserved)
{
- int has_class;
+ htri_t has_class;
hid_t tid = H5I_INVALID_HID;
hid_t aid = H5I_INVALID_HID;
char * buf = NULL; /* Name of attribute */
size_t string_size; /* Size of storage for attribute */
- herr_t ret;
-
- /* try to find the attribute "CLASS" on the dataset */
- if ((has_class = H5LT_find_attribute(did, "CLASS")) < 0)
- return -1;
- if (has_class == 0)
- return 0;
+ /* Try to find the attribute "CLASS" on the dataset */
+ if ((has_class = H5Aexists(did, "CLASS")) < 0)
+ return FAIL;
+ if (has_class == 0) {
+ *is_reserved = FALSE;
+ return SUCCEED;
+ }
- assert(has_class == 1);
if ((aid = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0)
- goto out;
-
+ goto error;
if ((tid = H5Aget_type(aid)) < 0)
- goto out;
+ goto error;
- /* check to make sure attribute is a string */
+ /* Check to make sure attribute is a string */
if (H5T_STRING != H5Tget_class(tid))
- goto out;
+ goto error;
- /* check to make sure string is null-terminated */
+ /* Check to make sure string is null-terminated */
if (H5T_STR_NULLTERM != H5Tget_strpad(tid))
- goto out;
+ goto error;
- /* allocate buffer large enough to hold string */
+ /* Allocate buffer large enough to hold string */
if ((string_size = H5Tget_size(tid)) == 0)
- goto out;
-
- buf = (char *)HDmalloc((size_t)string_size * sizeof(char));
- if (buf == NULL)
- goto out;
+ goto error;
+ if (NULL == (buf = HDmalloc(string_size * sizeof(char))))
+ goto error;
/* Read the attribute */
if (H5Aread(aid, tid, buf) < 0)
- goto out;
+ goto error;
if (HDstrncmp(buf, IMAGE_CLASS, MIN(HDstrlen(IMAGE_CLASS), HDstrlen(buf))) == 0 ||
HDstrncmp(buf, PALETTE_CLASS, MIN(HDstrlen(PALETTE_CLASS), HDstrlen(buf))) == 0 ||
HDstrncmp(buf, TABLE_CLASS, MIN(HDstrlen(TABLE_CLASS), HDstrlen(buf))) == 0)
- ret = 1;
+ *is_reserved = TRUE;
else
- ret = 0;
+ *is_reserved = FALSE;
HDfree(buf);
if (H5Tclose(tid) < 0)
- goto out;
-
+ goto error;
if (H5Aclose(aid) < 0)
- goto out;
+ goto error;
- return ret;
+ return SUCCEED;
- /* error zone */
-out:
+error:
H5E_BEGIN_TRY
{
- if (buf)
- HDfree(buf);
H5Tclose(tid);
H5Aclose(aid);
}
H5E_END_TRY;
+
+ HDfree(buf);
+
return FAIL;
}
diff --git a/hl/src/H5IM.c b/hl/src/H5IM.c
index ff10d57..75f2e28 100644
--- a/hl/src/H5IM.c
+++ b/hl/src/H5IM.c
@@ -228,7 +228,6 @@ H5IM_find_palette(hid_t loc_id)
*
*-------------------------------------------------------------------------
*/
-
herr_t
H5IMget_image_info(hid_t loc_id, const char *dset_name, hsize_t *width, hsize_t *height, hsize_t *planes,
char *interlace, hssize_t *npals)
@@ -241,7 +240,7 @@ H5IMget_image_info(hid_t loc_id, const char *dset_name, hsize_t *width, hsize_t
hid_t atid = -1;
H5T_class_t aclass;
int has_pal;
- int has_attr;
+ hid_t has_attr;
/* check the arguments */
if (dset_name == NULL)
@@ -257,11 +256,11 @@ H5IMget_image_info(hid_t loc_id, const char *dset_name, hsize_t *width, hsize_t
return -1;
/* Try to find the attribute "INTERLACE_MODE" on the >>image<< dataset */
- if ((has_attr = H5LT_find_attribute(did, "INTERLACE_MODE")) < 0)
+ if ((has_attr = H5Aexists(did, "INTERLACE_MODE")) < 0)
goto out;
/* It exists, get it */
- if (has_attr == 1) {
+ if (has_attr > 0) {
if ((aid = H5Aopen(did, "INTERLACE_MODE", H5P_DEFAULT)) < 0)
goto out;
@@ -289,9 +288,8 @@ H5IMget_image_info(hid_t loc_id, const char *dset_name, hsize_t *width, hsize_t
/* Initialize the image dimensions */
- if (has_attr == 1)
- /* This is a 24 bit image */
- {
+ if (has_attr > 0) {
+ /* This is a 24 bit image */
if (HDstrncmp(interlace, "INTERLACE_PIXEL", 15) == 0) {
/* Number of color planes is defined as the third dimension */
@@ -308,9 +306,8 @@ H5IMget_image_info(hid_t loc_id, const char *dset_name, hsize_t *width, hsize_t
else
return -1;
}
- else
- /* This is a 8 bit image */
- {
+ else {
+ /* This is a 8 bit image */
*height = dims[0];
*width = dims[1];
*planes = 1;
@@ -512,7 +509,7 @@ H5IMlink_palette(hid_t loc_id, const char *image_name, const char *pal_name)
hobj_ref_t *refbuf; /* buffer to read references */
hssize_t n_refs;
hsize_t dim_ref;
- int ok_pal;
+ htri_t ok_pal;
/* check the arguments */
if (image_name == NULL)
@@ -531,7 +528,8 @@ H5IMlink_palette(hid_t loc_id, const char *image_name, const char *pal_name)
return -1;
/* Try to find the attribute "PALETTE" on the >>image<< dataset */
- ok_pal = H5LT_find_attribute(did, "PALETTE");
+ if ((ok_pal = H5Aexists(did, "PALETTE")) < 0)
+ goto out;
/*-------------------------------------------------------------------------
* It does not exist. We create the attribute and one reference
@@ -570,7 +568,7 @@ H5IMlink_palette(hid_t loc_id, const char *image_name, const char *pal_name)
* The attribute already exists, open it
*-------------------------------------------------------------------------
*/
- else if (ok_pal == 1) {
+ else if (ok_pal > 0) {
if ((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0)
goto out;
@@ -631,7 +629,7 @@ H5IMlink_palette(hid_t loc_id, const char *image_name, const char *pal_name)
HDfree(refbuf);
- } /* ok_pal == 1 */
+ } /* ok_pal > 0 */
/* Close the image dataset. */
if (H5Dclose(did) < 0)
@@ -673,7 +671,8 @@ H5IMunlink_palette(hid_t loc_id, const char *image_name, const char *pal_name)
hid_t atid;
hid_t aid;
H5T_class_t aclass;
- int ok_pal, has_pal;
+ htri_t ok_pal;
+ int has_pal;
/* check the arguments */
if (image_name == NULL)
@@ -699,14 +698,14 @@ H5IMunlink_palette(hid_t loc_id, const char *image_name, const char *pal_name)
return -1;
/* Try to find the attribute "PALETTE" on the >>image<< dataset */
- ok_pal = H5LT_find_attribute(did, "PALETTE");
+ if ((ok_pal = H5Aexists(did, "PALETTE")) < 0)
+ goto out;
/* It does not exist. Nothing to do */
if (ok_pal == 0)
- return -1;
-
- /* The attribute exists, open it */
- else if (ok_pal == 1) {
+ goto out;
+ else if (ok_pal > 0) {
+ /* The attribute exists, open it */
if ((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0)
goto out;
@@ -730,8 +729,7 @@ H5IMunlink_palette(hid_t loc_id, const char *image_name, const char *pal_name)
/* Close the attribute. */
if (H5Aclose(aid) < 0)
goto out;
-
- } /* ok_pal */
+ }
/* Close the image dataset. */
if (H5Dclose(did) < 0)
@@ -1063,7 +1061,7 @@ herr_t
H5IMis_image(hid_t loc_id, const char *dset_name)
{
hid_t did;
- int has_class;
+ htri_t has_class;
hid_t atid;
hid_t aid = -1;
char * attr_data; /* Name of attribute */
@@ -1082,13 +1080,14 @@ H5IMis_image(hid_t loc_id, const char *dset_name)
return -1;
/* Try to find the attribute "CLASS" on the dataset */
- has_class = H5LT_find_attribute(did, "CLASS");
+ if ((has_class = H5Aexists(did, "CLASS")) < 0)
+ goto out;
if (has_class == 0) {
H5Dclose(did);
return 0;
}
- else if (has_class == 1) {
+ else {
if ((aid = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0)
goto out;
@@ -1163,7 +1162,7 @@ herr_t
H5IMis_palette(hid_t loc_id, const char *dset_name)
{
hid_t did;
- int has_class;
+ htri_t has_class;
hid_t atid;
hid_t aid = -1;
char * attr_data; /* Name of attribute */
@@ -1182,13 +1181,14 @@ H5IMis_palette(hid_t loc_id, const char *dset_name)
return -1;
/* Try to find the attribute "CLASS" on the dataset */
- has_class = H5LT_find_attribute(did, "CLASS");
+ if ((has_class = H5Aexists(did, "CLASS")) < 0)
+ goto out;
if (has_class == 0) {
H5Dclose(did);
return 0;
}
- else if (has_class == 1) {
+ else {
if ((aid = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0)
goto out;
diff --git a/hl/src/H5LT.c b/hl/src/H5LT.c
index 238bbf2..78cc301 100644
--- a/hl/src/H5LT.c
+++ b/hl/src/H5LT.c
@@ -1385,7 +1385,6 @@ H5_GCC_CLANG_DIAG_ON("cast-qual")
*
*-------------------------------------------------------------------------
*/
-
herr_t
H5LTset_attribute_string(hid_t loc_id, const char *obj_name, const char *attr_name, const char *attr_data)
{
@@ -1393,7 +1392,7 @@ H5LTset_attribute_string(hid_t loc_id, const char *obj_name, const char *attr_na
hid_t attr_space_id;
hid_t attr_id;
hid_t obj_id;
- int has_attr;
+ htri_t has_attr;
size_t attr_size;
/* check the arguments */
@@ -1423,11 +1422,10 @@ H5LTset_attribute_string(hid_t loc_id, const char *obj_name, const char *attr_na
if ((attr_space_id = H5Screate(H5S_SCALAR)) < 0)
goto out;
- /* Verify if the attribute already exists */
- has_attr = H5LT_find_attribute(obj_id, attr_name);
-
- /* The attribute already exists, delete it */
- if (has_attr == 1)
+ /* Delete the attribute if it already exists */
+ if ((has_attr = H5Aexists(obj_id, attr_name)) < 0)
+ goto out;
+ if (has_attr > 0)
if (H5Adelete(obj_id, attr_name) < 0)
goto out;
@@ -1483,7 +1481,7 @@ H5LT_set_attribute_numerical(hid_t loc_id, const char *obj_name, const char *att
hid_t obj_id, sid, attr_id;
hsize_t dim_size = size;
- int has_attr;
+ htri_t has_attr;
/* check the arguments */
if (obj_name == NULL)
@@ -1499,11 +1497,10 @@ H5LT_set_attribute_numerical(hid_t loc_id, const char *obj_name, const char *att
if ((sid = H5Screate_simple(1, &dim_size, NULL)) < 0)
goto out;
- /* Verify if the attribute already exists */
- has_attr = H5LT_find_attribute(obj_id, attr_name);
-
- /* The attribute already exists, delete it */
- if (has_attr == 1)
+ /* Delete the attribute if it already exists */
+ if ((has_attr = H5Aexists(obj_id, attr_name)) < 0)
+ goto out;
+ if (has_attr > 0)
if (H5Adelete(obj_id, attr_name) < 0)
goto out;
@@ -1858,49 +1855,24 @@ H5LTset_attribute_double(hid_t loc_id, const char *obj_name, const char *attr_na
/*-------------------------------------------------------------------------
* Function: H5LTfind_attribute
*
- * Purpose: Inquires if an attribute named attr_name exists attached to
- * the object loc_id.
- *
- * Programmer: Pedro Vicente
- *
- * Date: May 17, 2006
+ * Purpose: Checks if an attribute named attr_name exists attached to
+ * the object loc_id
*
- * Comments:
- * Calls the private version of the function
+ * TODO: Overloading herr_t is not a great idea. This function either
+ * needs to be rewritten to take a Boolean out parameter in
+ * HDF5 2.0 or possibly even eliminated entirely as it simply
+ * wraps H5Aexists.
*
+ * Return: An htri_t value cast to herr_t
+ * Exists: Positive
+ * Does not exist: 0
+ * Error: Negative
*-------------------------------------------------------------------------
*/
-
herr_t
H5LTfind_attribute(hid_t loc_id, const char *attr_name)
{
- return H5LT_find_attribute(loc_id, attr_name);
-}
-
-/*-------------------------------------------------------------------------
- * Function: H5LT_find_attribute
- *
- * Purpose: Inquires if an attribute named attr_name exists attached to the object loc_id.
- *
- * Programmer: Pedro Vicente
- *
- * Date: June 21, 2001
- *
- * Return:
- * Success: Positive if the attribute exists attached to the
- * object loc_id. Zero if the attribute does not
- * exist attached to the object loc_id.
- *
- * Failure: Negative if something goes wrong within the
- * library.
- *
- *-------------------------------------------------------------------------
- */
-herr_t
-H5LT_find_attribute(hid_t loc_id, const char *attr_name)
-{
- htri_t attr_exists = H5Aexists(loc_id, attr_name);
- return (attr_exists < 0) ? (herr_t)-1 : (attr_exists) ? (herr_t)1 : (herr_t)0;
+ return (herr_t)H5Aexists(loc_id, attr_name);
}
/*-------------------------------------------------------------------------
@@ -3539,14 +3511,13 @@ H5LT_set_attribute_string(hid_t dset_id, const char *name, const char *buf)
hid_t tid;
hid_t sid = -1;
hid_t aid = -1;
- int has_attr;
+ htri_t has_attr;
size_t size;
- /* verify if the attribute already exists */
- has_attr = H5LT_find_attribute(dset_id, name);
-
- /* the attribute already exists, delete it */
- if (has_attr == 1)
+ /* Delete the attribute if it already exists */
+ if ((has_attr = H5Aexists(dset_id, name)) < 0)
+ return FAIL;
+ if (has_attr > 0)
if (H5Adelete(dset_id, name) < 0)
return FAIL;
diff --git a/hl/src/H5LTprivate.h b/hl/src/H5LTprivate.h
index 5a97d9c..e5c4e4e 100644
--- a/hl/src/H5LTprivate.h
+++ b/hl/src/H5LTprivate.h
@@ -20,23 +20,12 @@
/* public LT prototypes */
#include "H5LTpublic.h"
-/*-------------------------------------------------------------------------
- * Private functions
- *-------------------------------------------------------------------------
- */
-
H5_HLDLL herr_t H5LT_get_attribute_disk(hid_t obj_id, const char *attr_name, void *data);
-
H5_HLDLL herr_t H5LT_set_attribute_numerical(hid_t loc_id, const char *obj_name, const char *attr_name,
size_t size, hid_t type_id, const void *data);
-
H5_HLDLL herr_t H5LT_set_attribute_string(hid_t dset_id, const char *name, const char *buf);
-
-H5_HLDLL herr_t H5LT_find_attribute(hid_t loc_id, const char *name);
-
-H5_HLDLL char *H5LT_dtype_to_text(hid_t dtype, char *dt_str, H5LT_lang_t lang, size_t *slen,
- hbool_t no_user_buf);
-
-H5_HLDLL hid_t H5LTyyparse(void);
+H5_HLDLL char * H5LT_dtype_to_text(hid_t dtype, char *dt_str, H5LT_lang_t lang, size_t *slen,
+ hbool_t no_user_buf);
+H5_HLDLL hid_t H5LTyyparse(void);
#endif
diff --git a/hl/src/H5TB.c b/hl/src/H5TB.c
index efa61a3..eda3a35 100644
--- a/hl/src/H5TB.c
+++ b/hl/src/H5TB.c
@@ -2585,11 +2585,11 @@ H5TBdelete_field(hid_t loc_id, const char *dset_name, const char *field_name)
HDsnprintf(attr_name, sizeof(attr_name), "FIELD_%d_FILL", (int)i);
/* check if we have the _FILL attribute */
- if ((has_fill = H5LT_find_attribute(did_1, attr_name)) < 0)
+ if ((has_fill = H5Aexists(did_1, attr_name)) < 0)
goto out;
/* get it */
- if (has_fill)
+ if (has_fill > 0)
if (H5LT_get_attribute_disk(did_1, attr_name, tmp_fill_buf + curr_offset) < 0)
goto out;
@@ -2747,7 +2747,7 @@ H5TBdelete_field(hid_t loc_id, const char *dset_name, const char *field_name)
* attach the fill attributes from previous table
*-------------------------------------------------------------------------
*/
- if (has_fill) {
+ if (has_fill > 0) {
if ((sid_1 = H5Screate(H5S_SCALAR)) < 0)
goto out;
@@ -2918,15 +2918,15 @@ H5TBAget_fill(hid_t loc_id, const char *dset_name, hid_t dset_id, unsigned char
for (i = 0; i < nfields; i++) {
HDsnprintf(attr_name, sizeof(attr_name), "FIELD_%d_FILL", (int)i);
- /* check if we have the _FILL attribute */
- if ((has_fill = H5LT_find_attribute(dset_id, attr_name)) < 0)
+ /* Check if we have the _FILL attribute */
+ if ((has_fill = H5Aexists(dset_id, attr_name)) < 0)
goto out;
/* get it */
- if (has_fill)
+ if (has_fill > 0)
if (H5LT_get_attribute_disk(dset_id, attr_name, dst_buf + src_offset[i]) < 0)
goto out;
- } /* end for */
+ }
ret_val = has_fill;