summaryrefslogtreecommitdiffstats
path: root/src/H5Z.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Z.c')
-rw-r--r--src/H5Z.c136
1 files changed, 84 insertions, 52 deletions
diff --git a/src/H5Z.c b/src/H5Z.c
index f11756b..b83377d 100644
--- a/src/H5Z.c
+++ b/src/H5Z.c
@@ -698,23 +698,22 @@ H5Z_modify(const H5O_pline_t *pline, H5Z_filter_t filter, unsigned flags,
size_t cd_nelmts, const unsigned int cd_values[/*cd_nelmts*/])
{
size_t idx; /* Index of filter in pipeline */
- size_t i; /* Local index variable */
- herr_t ret_value=SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5Z_modify, FAIL)
- assert(pline);
- assert(filter>=0 && filter<=H5Z_FILTER_MAX);
- assert(0==(flags & ~((unsigned)H5Z_FLAG_DEFMASK)));
- assert(0==cd_nelmts || cd_values);
+ HDassert(pline);
+ HDassert(filter >= 0 && filter <= H5Z_FILTER_MAX);
+ HDassert(0 == (flags & ~((unsigned)H5Z_FLAG_DEFMASK)));
+ HDassert(0 == cd_nelmts || cd_values);
/* Locate the filter in the pipeline */
- for(idx=0; idx<pline->nused; idx++)
- if(pline->filter[idx].id==filter)
+ for(idx = 0; idx < pline->nused; idx++)
+ if(pline->filter[idx].id == filter)
break;
/* Check if the filter was not already in the pipeline */
- if(idx>pline->nused)
+ if(idx > pline->nused)
HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, FAIL, "filter not in pipeline")
/* Change parameters for filter */
@@ -722,15 +721,24 @@ H5Z_modify(const H5O_pline_t *pline, H5Z_filter_t filter, unsigned flags,
pline->filter[idx].cd_nelmts = cd_nelmts;
/* Free any existing parameters */
- if(pline->filter[idx].cd_values!=NULL)
+ if(pline->filter[idx].cd_values != NULL && pline->filter[idx].cd_values != pline->filter[idx]._cd_values)
H5MM_xfree(pline->filter[idx].cd_values);
/* Set parameters */
- if (cd_nelmts>0) {
- pline->filter[idx].cd_values = H5MM_malloc(cd_nelmts*sizeof(unsigned));
- if (NULL==pline->filter[idx].cd_values)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for filter parameters")
- for (i=0; i<cd_nelmts; i++)
+ if(cd_nelmts > 0) {
+ size_t i; /* Local index variable */
+
+ /* Allocate memory or point at internal buffer */
+ if(cd_nelmts > H5Z_COMMON_CD_VALUES) {
+ pline->filter[idx].cd_values = H5MM_malloc(cd_nelmts * sizeof(unsigned));
+ if(NULL == pline->filter[idx].cd_values)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for filter parameters")
+ } /* end if */
+ else
+ pline->filter[idx].cd_values = pline->filter[idx]._cd_values;
+
+ /* Copy client data values */
+ for(i = 0; i < cd_nelmts; i++)
pline->filter[idx].cd_values[i] = cd_values[i];
} /* end if */
else
@@ -759,33 +767,34 @@ herr_t
H5Z_append(H5O_pline_t *pline, H5Z_filter_t filter, unsigned flags,
size_t cd_nelmts, const unsigned int cd_values[/*cd_nelmts*/])
{
- size_t idx, i;
- herr_t ret_value=SUCCEED; /* Return value */
+ size_t idx;
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5Z_append, FAIL)
- assert(pline);
- assert(filter>=0 && filter<=H5Z_FILTER_MAX);
- assert(0==(flags & ~((unsigned)H5Z_FLAG_DEFMASK)));
- assert(0==cd_nelmts || cd_values);
+ HDassert(pline);
+ HDassert(filter >= 0 && filter <= H5Z_FILTER_MAX);
+ HDassert(0 == (flags & ~((unsigned)H5Z_FLAG_DEFMASK)));
+ HDassert(0 == cd_nelmts || cd_values);
/*
* Check filter limit. We do it here for early warnings although we may
* decide to relax this restriction in the future.
*/
- if (pline->nused>=H5Z_MAX_NFILTERS)
+ if(pline->nused >= H5Z_MAX_NFILTERS)
HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "too many filters in pipeline")
/* Allocate additional space in the pipeline if it's full */
- if (pline->nused>=pline->nalloc) {
+ if(pline->nused >= pline->nalloc) {
H5O_pline_t x;
- x.nalloc = MAX(H5Z_MAX_NFILTERS, 2*pline->nalloc);
+
+ x.nalloc = MAX(H5Z_MAX_NFILTERS, 2 * pline->nalloc);
x.filter = H5MM_realloc(pline->filter, x.nalloc*sizeof(x.filter[0]));
- if (NULL==x.filter)
+ if(NULL == x.filter)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for filter pipeline")
pline->nalloc = x.nalloc;
pline->filter = x.filter;
- }
+ } /* end if */
/* Add the new filter to the pipeline */
idx = pline->nused;
@@ -793,20 +802,30 @@ H5Z_append(H5O_pline_t *pline, H5Z_filter_t filter, unsigned flags,
pline->filter[idx].flags = flags;
pline->filter[idx].name = NULL; /*we'll pick it up later*/
pline->filter[idx].cd_nelmts = cd_nelmts;
- if (cd_nelmts>0) {
- pline->filter[idx].cd_values = H5MM_malloc(cd_nelmts*sizeof(unsigned));
- if (NULL==pline->filter[idx].cd_values)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for filter")
- for (i=0; i<cd_nelmts; i++)
+ if(cd_nelmts > 0) {
+ size_t i; /* Local index variable */
+
+ /* Allocate memory or point at internal buffer */
+ if(cd_nelmts > H5Z_COMMON_CD_VALUES) {
+ pline->filter[idx].cd_values = H5MM_malloc(cd_nelmts * sizeof(unsigned));
+ if(NULL == pline->filter[idx].cd_values)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for filter")
+ } /* end if */
+ else
+ pline->filter[idx].cd_values = pline->filter[idx]._cd_values;
+
+ /* Copy client data values */
+ for(i = 0; i < cd_nelmts; i++)
pline->filter[idx].cd_values[i] = cd_values[i];
- } else {
+ } /* end if */
+ else
pline->filter[idx].cd_values = NULL;
- }
+
pline->nused++;
done:
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5Z_append() */
/*-------------------------------------------------------------------------
@@ -1129,58 +1148,71 @@ done:
herr_t
H5Z_delete(H5O_pline_t *pline, H5Z_filter_t filter)
{
- herr_t ret_value=SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5Z_delete, FAIL)
/* Check args */
- assert(pline);
- assert(filter>=0 && filter<=H5Z_FILTER_MAX);
+ HDassert(pline);
+ HDassert(filter >= 0 && filter <= H5Z_FILTER_MAX);
/* if the pipeline has no filters, just return */
if(pline->nused==0)
HGOTO_DONE(SUCCEED)
/* Delete all filters */
- if (H5Z_FILTER_ALL==filter) {
- if(H5O_reset(H5O_PLINE_ID, pline)<0)
+ if(H5Z_FILTER_ALL == filter) {
+ if(H5O_reset(H5O_PLINE_ID, pline) < 0)
HGOTO_ERROR(H5E_PLINE, H5E_CANTFREE, FAIL, "can't release pipeline info")
} /* end if */
/* Delete filter */
else {
size_t idx; /* Index of filter in pipeline */
- unsigned found=0; /* Indicate filter was found in pipeline */
+ hbool_t found = FALSE; /* Indicate filter was found in pipeline */
/* Locate the filter in the pipeline */
- for(idx=0; idx<pline->nused; idx++)
- if(pline->filter[idx].id==filter) {
- found=1;
+ for(idx = 0; idx < pline->nused; idx++)
+ if(pline->filter[idx].id == filter) {
+ found = TRUE;
break;
- }
+ } /* end if */
/* filter was not found in the pipeline */
- if (!found)
+ if(!found)
HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, FAIL, "filter not in pipeline")
/* Free information for deleted filter */
- H5MM_xfree(pline->filter[idx].name);
- H5MM_xfree(pline->filter[idx].cd_values);
+ if(pline->filter[idx].name && pline->filter[idx].name != pline->filter[idx]._name)
+ HDassert((HDstrlen(pline->filter[idx].name) + 1) > H5Z_COMMON_NAME_LEN);
+ if(pline->filter[idx].name != pline->filter[idx]._name)
+ pline->filter[idx].name = H5MM_xfree(pline->filter[idx].name);
+ if(pline->filter[idx].cd_values && pline->filter[idx].cd_values != pline->filter[idx]._cd_values)
+ HDassert(pline->filter[idx].cd_nelmts > H5Z_COMMON_CD_VALUES);
+ if(pline->filter[idx].cd_values != pline->filter[idx]._cd_values)
+ pline->filter[idx].cd_values = H5MM_xfree(pline->filter[idx].cd_values);
/* Remove filter from pipeline array */
- if((idx+1)<pline->nused)
- HDmemcpy(&pline->filter[idx], &pline->filter[idx+1],
- sizeof (H5Z_filter_info_t)*(pline->nused-(idx+1)));
+ if((idx + 1) < pline->nused) {
+ /* Copy filters down & fix up any client data value arrays using internal storage */
+ for(; (idx + 1) < pline->nused; idx++) {
+ pline->filter[idx] = pline->filter[idx + 1];
+ if(pline->filter[idx].name && (HDstrlen(pline->filter[idx].name) + 1) <= H5Z_COMMON_NAME_LEN)
+ pline->filter[idx].name = pline->filter[idx]._name;
+ if(pline->filter[idx].cd_nelmts <= H5Z_COMMON_CD_VALUES)
+ pline->filter[idx].cd_values = pline->filter[idx]._cd_values;
+ } /* end for */
+ } /* end if */
/* Decrement number of used filters */
pline->nused--;
/* Reset information for previous last filter in pipeline */
- HDmemset(&pline->filter[pline->nused], 0, sizeof (H5Z_filter_info_t));
+ HDmemset(&pline->filter[pline->nused], 0, sizeof(H5Z_filter_info_t));
} /* end else */
done:
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5Z_delete() */
/*-------------------------------------------------------------------------
* Function: H5Zget_filter_info