From 768f8abb18a0b7d7233cfc1ea3da32efe83f56f1 Mon Sep 17 00:00:00 2001 From: Elena Date: Wed, 12 Aug 2020 08:40:11 -0500 Subject: The H5DSis_scale function was updated to return "not a dimension scale" (0) instead of failing (-1), when CLASS or DIMENSION_SCALE attributes are not written according to Dimension Scales Specification (HDFFV-10436). --- hl/src/H5DS.c | 89 ++++++++++++++++++++++++++---------------------- release_docs/RELEASE.txt | 8 +++-- 2 files changed, 55 insertions(+), 42 deletions(-) diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c index 12bcc93..31cbe13 100644 --- a/hl/src/H5DS.c +++ b/hl/src/H5DS.c @@ -1896,30 +1896,32 @@ out: } /*------------------------------------------------------------------------- - * Function: H5DSis_scale - * - * Purpose: check if the dataset DID is a dimension scale - * - * Return: 1, is, 0, not, FAIL, error - * - * Programmer: Pedro Vicente - * - * Date: January 04, 2005 - * - *------------------------------------------------------------------------- - */ -htri_t -H5DSis_scale(hid_t did) +* Function: H5DSis_scale +* +* Purpose: check if the dataset DID is a dimension scale +* +* Return: 1, is, 0, not, FAIL, error +* +* Programmer: pvn@ncsa.uiuc.edu +* +* Date: January 04, 2005 +* +*------------------------------------------------------------------------- +*/ + +htri_t H5DSis_scale(hid_t did) { - hid_t tid = -1; /* attribute type ID */ - hid_t aid = -1; /* attribute ID */ - herr_t has_class; /* has the "CLASS" attribute */ - htri_t is_ds; /* boolean return value */ - H5I_type_t it; /* ID type */ - char *buf; /* Name of attribute */ - hsize_t storage_size; /* Size of storage for attribute */ - - /*------------------------------------------------------------------------- + hid_t tid = -1; /* attribute type ID */ + hid_t aid = -1; /* attribute ID */ + herr_t attr_class; /* has the "CLASS" attribute */ + htri_t is_ds = 0; /* set to "not a dimension scale" */ + H5I_type_t it; /* type of identofier */ + char *buf; /* buffer to read a name of attribute */ + size_t string_size; /* Size of storage for the attribute */ + H5T_class_t type_class; + H5T_str_t strpad; + + /*------------------------------------------------------------------------ * parameter checking *------------------------------------------------------------------------- */ @@ -1931,11 +1933,11 @@ H5DSis_scale(hid_t did) return FAIL; /* try to find the attribute "CLASS" on the dataset */ - if((has_class = H5LT_find_attribute(did, "CLASS")) < 0) + if((attr_class = H5LT_find_attribute(did, "CLASS")) < 0) return FAIL; - if(has_class == 0) - is_ds = 0; + if(attr_class == 0) + return is_ds; else { @@ -1945,19 +1947,27 @@ H5DSis_scale(hid_t did) if((tid = H5Aget_type(aid)) < 0) goto out; - /* check to make sure attribute is a string */ - if(H5T_STRING != H5Tget_class(tid)) + /* check to make sure attribute is a string; + if not, then it is not dimension scale */ + if((type_class = H5Tget_class(tid)) < 0) goto out; + if(H5T_STRING != type_class) + goto out_success; - /* check to make sure string is null-terminated */ - if(H5T_STR_NULLTERM != H5Tget_strpad(tid)) + /* check to make sure string is null-terminated; + if not, then it is not dimension scale */ + if((strpad = H5Tget_strpad(tid)) < 0 ) goto out; + if(H5T_STR_NULLTERM != strpad) + goto out_success; - /* allocate buffer large enough to hold string */ - if((storage_size = H5Aget_storage_size(aid)) == 0) - goto out; + /* get string size should be 16 to hold "DIMENSION_SCALE" string */ + if((string_size = H5Tget_size(tid)) == 0) + return FAIL; + if(string_size != 16) + goto out_success; - buf = (char*)HDmalloc( (size_t)storage_size * sizeof(char) + 1); + buf = (char*)HDmalloc((size_t)string_size * sizeof(char)); if(buf == NULL) goto out; @@ -1966,10 +1976,9 @@ H5DSis_scale(hid_t did) goto out; /* compare strings */ - if(HDstrncmp(buf, DIMENSION_SCALE_CLASS, MIN(HDstrlen(DIMENSION_SCALE_CLASS),HDstrlen(buf)))==0) + if(HDstrncmp(buf, DIMENSION_SCALE_CLASS, + MIN(HDstrlen(DIMENSION_SCALE_CLASS),HDstrlen(buf)))==0) is_ds = 1; - else - is_ds = 0; HDfree(buf); @@ -1979,11 +1988,11 @@ H5DSis_scale(hid_t did) if (H5Aclose(aid) < 0) goto out; + goto out_success; } - - return is_ds; - +out_success: + return is_ds; /* error zone */ out: H5E_BEGIN_TRY { diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 7ccdbe9..5720c17 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -742,7 +742,7 @@ New Features High-Level APIs: --------------- - - + - C Packet Table API ------------------ @@ -1203,7 +1203,11 @@ Bug Fixes since HDF5-1.10.3 release High-Level APIs: ------ - - + - The H5DSis_scale function was updated to return "not a dimension scale" (0) + instead of failing (-1), when CLASS or DIMENSION_SCALE attributes are + not written according to Dimension Scales Specification. + + (EIP - 2020/08/12, HDFFV-10436) Fortran High-Level APIs: ------ -- cgit v0.12