summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5Pdxpl.c45
-rw-r--r--src/H5Ppublic.h2
-rw-r--r--src/H5Ztrans.c13
3 files changed, 41 insertions, 19 deletions
diff --git a/src/H5Pdxpl.c b/src/H5Pdxpl.c
index 430c025..5941a19 100644
--- a/src/H5Pdxpl.c
+++ b/src/H5Pdxpl.c
@@ -85,40 +85,65 @@ done:
*
* Purpose:
* Gets data transform expression.
- *
*
* Return: Returns a non-negative value if successful; otherwise returns a negative value.
*
+ * Comments:
+ * If `expression' is non-NULL then write up to `size' bytes into that
+ * buffer and always return the length of the transform name.
+ * Otherwise `size' is ignored and the function does not store the expression,
+ * just returning the number of characters required to store the expression.
+ * If an error occurs then the buffer pointed to by `expression' (NULL or non-NULL)
+ * is unchanged and the function returns a negative value.
+ * If a zero is returned for the name's length, then there is no name
+ * associated with the ID.
*
* Programmer: Leon Arber
* August 27, 2004
*
* Modifications:
- *
+ * October 20, 2004 LA: Changed API to use size and return ssize_t
*-------------------------------------------------------------------------
*/
-herr_t H5Pget_data_transform(hid_t plist_id, char** expression)
+ssize_t H5Pget_data_transform(hid_t plist_id, char* expression /*out*/, size_t size)
{
H5P_genplist_t *plist; /* Property list pointer */
H5Z_data_xform_t *data_xform_prop=NULL; /* New data xform property */
- herr_t ret_value=SUCCEED; /* return value */
+ ssize_t ret_value; /* return value */
+
+ size_t len;
+ char* pexp;
FUNC_ENTER_API(H5Pget_data_transform, FAIL);
- /* Check arguments */
- if (expression == NULL)
- HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "expression cannot be NULL");
-
/* Get the plist structure */
if(NULL == (plist = H5P_object_verify(plist_id,H5P_DATASET_XFER)))
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID");
if(H5P_get(plist, H5D_XFER_XFORM_NAME, &data_xform_prop)<0)
- HGOTO_ERROR (H5E_PLIST, H5E_CANTSET, FAIL, "Error setting data transform expression");
+ HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "Error getting data transform expression");
+ if(NULL == data_xform_prop)
+ HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "Cannot get a data transform that has not been set");
+
/* Get the data transform string */
- *expression = H5Z_xform_extract_xform_str(data_xform_prop);
+ pexp = H5Z_xform_extract_xform_str(data_xform_prop);
+
+ if(!pexp)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Failed to retrieve transform expression");
+
+ len = HDstrlen(pexp);
+ if(expression)
+ {
+ /* sanity check */
+ if(size > len)
+ size = len;
+
+ HDstrncpy(expression, pexp, size);
+ }
+
+ ret_value = (ssize_t)len;
done:
if(ret_value<0) {
diff --git a/src/H5Ppublic.h b/src/H5Ppublic.h
index bd9518e..6df6d0a 100644
--- a/src/H5Ppublic.h
+++ b/src/H5Ppublic.h
@@ -198,7 +198,7 @@ H5_DLL H5D_layout_t H5Pget_layout(hid_t plist_id);
H5_DLL herr_t H5Pset_chunk(hid_t plist_id, int ndims, const hsize_t dim[]);
H5_DLL int H5Pget_chunk(hid_t plist_id, int max_ndims, hsize_t dim[]/*out*/);
H5_DLL herr_t H5Pset_data_transform(hid_t plist_id, const char* expression);
-H5_DLL herr_t H5Pget_data_transform(hid_t plist_id, char** expression);
+H5_DLL ssize_t H5Pget_data_transform(hid_t plist_id, char* expression /*out*/, size_t size);
H5_DLL herr_t H5Pset_external(hid_t plist_id, const char *name, off_t offset,
hsize_t size);
H5_DLL int H5Pget_external_count(hid_t plist_id);
diff --git a/src/H5Ztrans.c b/src/H5Ztrans.c
index 51ce454..437d79e 100644
--- a/src/H5Ztrans.c
+++ b/src/H5Ztrans.c
@@ -1005,11 +1005,9 @@ done:
static herr_t
H5Z_xform_eval_full(H5Z_node *tree, const size_t array_size, const hid_t array_type, H5Z_result* res)
{
-
H5Z_result resl, resr;
herr_t ret_value = SUCCEED;
-
FUNC_ENTER_NOAPI(H5Z_xform_eval_full, FAIL);
/* check args */
@@ -1048,6 +1046,7 @@ H5Z_xform_eval_full(H5Z_node *tree, const size_t array_size, const hid_t array_
* 2. Figure out what type of data we're going to be manipulating
* 3. Do the operation on the data. */
+
switch (tree->type) {
case H5Z_XFORM_PLUS:
H5Z_XFORM_TYPE_OP(resl, resr, array_type, +=, array_size)
@@ -1390,7 +1389,7 @@ H5Z_xform_create(const char *expr)
/* we generate the parse tree right here and store a poitner to its root in the property. */
if((data_xform_prop->parse_root = H5Z_xform_parse(expr, data_xform_prop->dat_val_pointers))==NULL)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate memory for data transform parse tree")
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to generate parse tree from expression")
/* Assign return value */
ret_value=data_xform_prop;
@@ -1590,18 +1589,16 @@ H5Z_xform_extract_xform_str(const H5Z_data_xform_t *data_xform_prop)
{
char* ret_value;
- FUNC_ENTER_NOAPI(H5Z_xform_extract_xform_str, NULL)
+ FUNC_ENTER_NOAPI_NOFUNC(H5Z_xform_extract_xform_str)
/* There should be no way that these can be NULL since the function
* that calls this one checks to make sure they aren't before
* pasing them */
assert(exp);
assert(data_xform_prop);
+
+ ret_value = data_xform_prop->xform_exp;
- if( (ret_value = H5MM_strdup(data_xform_prop->xform_exp)) == NULL)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate memory for data transform string")
-
-done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5Z_xform_extract_xform_str() */