diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2015-09-16 22:27:49 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2015-09-16 22:27:49 (GMT) |
commit | ee7612be44b3797a903e21433558a52331515ce1 (patch) | |
tree | cce28a3a6e169f1668ad1a0356e907f0dddbfde6 /src/H5Pdxpl.c | |
parent | 222e7186ea78e49b387284cbb9997677c933c368 (diff) | |
download | hdf5-ee7612be44b3797a903e21433558a52331515ce1.zip hdf5-ee7612be44b3797a903e21433558a52331515ce1.tar.gz hdf5-ee7612be44b3797a903e21433558a52331515ce1.tar.bz2 |
[svn-r27811] Description:
Refactor property list code to "deep copy" properties in the correct way,
retraining the rest of the library to copy & release things correctly. This
cleans up another batch of memory leaks, etc. within the library.
Tested on:
MacOSX/64 10.10.5 (amazon) w/serial & parallel
Linux/32 2.6.x (jam) w/serial & parallel
(h5committest forthcoming)
Diffstat (limited to 'src/H5Pdxpl.c')
-rw-r--r-- | src/H5Pdxpl.c | 93 |
1 files changed, 80 insertions, 13 deletions
diff --git a/src/H5Pdxpl.c b/src/H5Pdxpl.c index 33423f1..9ab3580 100644 --- a/src/H5Pdxpl.c +++ b/src/H5Pdxpl.c @@ -153,6 +153,8 @@ /* Definitions for data transform property */ #define H5D_XFER_XFORM_SIZE sizeof(void *) #define H5D_XFER_XFORM_DEF NULL +#define H5D_XFER_XFORM_SET H5P__dxfr_xform_set +#define H5D_XFER_XFORM_GET H5P__dxfr_xform_get #define H5D_XFER_XFORM_ENC H5P__dxfr_xform_enc #define H5D_XFER_XFORM_DEC H5P__dxfr_xform_dec #define H5D_XFER_XFORM_DEL H5P__dxfr_xform_del @@ -204,6 +206,8 @@ static herr_t H5P__dxfr_mpio_chunk_opt_hard_enc(const void *value, void **pp, si static herr_t H5P__dxfr_mpio_chunk_opt_hard_dec(const void **pp, void *value); static herr_t H5P__dxfr_edc_enc(const void *value, void **pp, size_t *size); static herr_t H5P__dxfr_edc_dec(const void **pp, void *value); +static herr_t H5P__dxfr_xform_set(hid_t prop_id, const char* name, size_t size, void* value); +static herr_t H5P__dxfr_xform_get(hid_t prop_id, const char* name, size_t size, void* value); static herr_t H5P__dxfr_xform_enc(const void *value, void **pp, size_t *size); static herr_t H5P__dxfr_xform_dec(const void **pp, void *value); static herr_t H5P__dxfr_xform_del(hid_t prop_id, const char* name, size_t size, void* value); @@ -444,7 +448,7 @@ H5P__dxfr_reg_prop(H5P_genclass_t *pclass) /* Register the data transform property */ if(H5P_register_real(pclass, H5D_XFER_XFORM_NAME, H5D_XFER_XFORM_SIZE, &H5D_def_xfer_xform_g, - NULL, NULL, NULL, H5D_XFER_XFORM_ENC, H5D_XFER_XFORM_DEC, + NULL, H5D_XFER_XFORM_SET, H5D_XFER_XFORM_GET, H5D_XFER_XFORM_ENC, H5D_XFER_XFORM_DEC, H5D_XFER_XFORM_DEL, H5D_XFER_XFORM_COPY, H5D_XFER_XFORM_CMP, H5D_XFER_XFORM_CLOSE) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") @@ -652,6 +656,72 @@ done: /*------------------------------------------------------------------------- + * Function: H5P__dxfr_xform_set + * + * Purpose: Copies a data transform property when it's set for a property list + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Quincey Koziol + * Tuesday, Sept 1, 2015 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5P__dxfr_xform_set(hid_t H5_ATTR_UNUSED prop_id, const char H5_ATTR_UNUSED *name, + size_t H5_ATTR_UNUSED size, void *value) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Sanity check */ + HDassert(value); + + /* Make copy of data transform */ + if(H5Z_xform_copy((H5Z_data_xform_t **)value) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "error copying the data transform info") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P__dxfr_xform_set() */ + + +/*------------------------------------------------------------------------- + * Function: H5P__dxfr_xform_get + * + * Purpose: Copies a data transform property when it's retrieved for a property list + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Quincey Koziol + * Tuesday, Sept 1, 2015 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5P__dxfr_xform_get(hid_t H5_ATTR_UNUSED prop_id, const char H5_ATTR_UNUSED *name, + size_t H5_ATTR_UNUSED size, void *value) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Sanity check */ + HDassert(value); + + /* Make copy of data transform */ + if(H5Z_xform_copy((H5Z_data_xform_t **)value) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "error copying the data transform info") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P__dxfr_xform_get() */ + + +/*------------------------------------------------------------------------- * Function: H5P__dxfr_xform_enc * * Purpose: Callback routine which is called whenever the data transform @@ -828,10 +898,12 @@ H5P__dxfr_xform_copy(const char H5_ATTR_UNUSED *name, size_t H5_ATTR_UNUSED size FUNC_ENTER_STATIC + /* Sanity check */ HDassert(value); + /* Make copy of data transform */ if(H5Z_xform_copy((H5Z_data_xform_t **)value) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTCLOSEOBJ, FAIL, "error copying the data transform info") + HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "error copying the data transform info") done: FUNC_LEAVE_NOAPI(ret_value) @@ -954,7 +1026,7 @@ H5Pset_data_transform(hid_t plist_id, const char *expression) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* See if a data transform is already set, and free it if it is */ - if(H5P_get(plist, H5D_XFER_XFORM_NAME, &data_xform_prop) < 0) + if(H5P_peek(plist, H5D_XFER_XFORM_NAME, &data_xform_prop) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "error getting data transform expression") /* Destroy previous data transform property */ @@ -965,15 +1037,14 @@ H5Pset_data_transform(hid_t plist_id, const char *expression) if(NULL == (data_xform_prop = H5Z_xform_create(expression))) HGOTO_ERROR(H5E_PLINE, H5E_NOSPACE, FAIL, "unable to create data transform info") - /* Update property list */ - if(H5P_set(plist, H5D_XFER_XFORM_NAME, &data_xform_prop) < 0) + /* Update property list (takes ownership of transform) */ + if(H5P_poke(plist, H5D_XFER_XFORM_NAME, &data_xform_prop) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "Error setting data transform expression") done: - if(ret_value < 0) { + if(ret_value < 0) if(data_xform_prop && H5Z_xform_destroy(data_xform_prop) < 0) HDONE_ERROR(H5E_PLINE, H5E_CLOSEERROR, FAIL, "unable to release data transform expression") - } /* end if */ FUNC_LEAVE_API(ret_value) } /* end H5Pset_data_transform() */ @@ -1017,7 +1088,7 @@ H5Pget_data_transform(hid_t plist_id, char *expression /*out*/, size_t size) 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) + if(H5P_peek(plist, H5D_XFER_XFORM_NAME, &data_xform_prop) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "error getting data transform expression") if(NULL == data_xform_prop) @@ -1027,6 +1098,7 @@ H5Pget_data_transform(hid_t plist_id, char *expression /*out*/, size_t size) if(NULL == (pexp = H5Z_xform_extract_xform_str(data_xform_prop))) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "failed to retrieve transform expression") + /* Copy into application buffer */ len = HDstrlen(pexp); if(expression) { HDstrncpy(expression, pexp, MIN(len + 1, size)); @@ -1037,11 +1109,6 @@ H5Pget_data_transform(hid_t plist_id, char *expression /*out*/, size_t size) ret_value = (ssize_t)len; done: - if(ret_value < 0) { - if(data_xform_prop && H5Z_xform_destroy(data_xform_prop) < 0) - HDONE_ERROR(H5E_PLINE, H5E_CLOSEERROR, FAIL, "unable to release data transform expression") - } /* end if */ - FUNC_LEAVE_API(ret_value) } /* end H5Pget_data_transform() */ |