diff options
Diffstat (limited to 'src/H5Pencdec.c')
-rw-r--r-- | src/H5Pencdec.c | 228 |
1 files changed, 103 insertions, 125 deletions
diff --git a/src/H5Pencdec.c b/src/H5Pencdec.c index 5f35a7e..1cb7e4b 100644 --- a/src/H5Pencdec.c +++ b/src/H5Pencdec.c @@ -20,28 +20,25 @@ /* Module Setup */ /****************/ -#include "H5Pmodule.h" /* This source code file is part of the H5P module */ - +#include "H5Pmodule.h" /* This source code file is part of the H5P module */ /***********/ /* Headers */ /***********/ -#include "H5private.h" /* Generic Functions */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5Fprivate.h" /* Files */ -#include "H5Iprivate.h" /* IDs */ -#include "H5MMprivate.h" /* Memory management */ -#include "H5Ppkg.h" /* Property lists */ -#include "H5VMprivate.h" /* Vector functions */ - +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Fprivate.h" /* Files */ +#include "H5Iprivate.h" /* IDs */ +#include "H5MMprivate.h" /* Memory management */ +#include "H5Ppkg.h" /* Property lists */ +#include "H5VMprivate.h" /* Vector functions */ /****************/ /* Local Macros */ /****************/ /* Version # of encoded property lists */ -#define H5P_ENCODE_VERS 0 - +#define H5P_ENCODE_VERS 0 /******************/ /* Local Typedefs */ @@ -49,33 +46,27 @@ /* Typedef for iterator when encoding a property list */ typedef struct { - hbool_t encode; /* Whether the property list should be encoded */ - size_t *enc_size_ptr; /* Pointer to size of encoded buffer */ - void **pp; /* Pointer to encoding buffer pointer */ + hbool_t encode; /* Whether the property list should be encoded */ + size_t *enc_size_ptr; /* Pointer to size of encoded buffer */ + void ** pp; /* Pointer to encoding buffer pointer */ } H5P_enc_iter_ud_t; - /********************/ /* Local Prototypes */ /********************/ - /*********************/ /* Package Variables */ /*********************/ - /*****************************/ /* Library Private Variables */ /*****************************/ - /*******************/ /* Local Variables */ /*******************/ - - /*------------------------------------------------------------------------- * Function: H5P__encode_size_t * @@ -92,9 +83,9 @@ typedef struct { herr_t H5P__encode_size_t(const void *value, void **_pp, size_t *size) { - uint64_t enc_value = (uint64_t)*(const size_t *)value; /* Property value to encode */ - uint8_t **pp = (uint8_t **)_pp; - unsigned enc_size = H5VM_limit_enc_size(enc_value); /* Size of encoded property */ + uint64_t enc_value = (uint64_t) * (const size_t *)value; /* Property value to encode */ + uint8_t **pp = (uint8_t **)_pp; + unsigned enc_size = H5VM_limit_enc_size(enc_value); /* Size of encoded property */ FUNC_ENTER_PACKAGE_NOERR @@ -103,7 +94,7 @@ H5P__encode_size_t(const void *value, void **_pp, size_t *size) HDassert(enc_size < 256); HDassert(size); - if(NULL != *pp) { + if (NULL != *pp) { /* Encode the size */ *(*pp)++ = (uint8_t)enc_size; @@ -117,7 +108,6 @@ H5P__encode_size_t(const void *value, void **_pp, size_t *size) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5P__encode_size_t() */ - /*------------------------------------------------------------------------- * Function: H5P__encode_hsize_t * @@ -134,9 +124,9 @@ H5P__encode_size_t(const void *value, void **_pp, size_t *size) herr_t H5P__encode_hsize_t(const void *value, void **_pp, size_t *size) { - uint64_t enc_value = (uint64_t)*(const hsize_t *)value; /* Property value to encode */ - unsigned enc_size = H5VM_limit_enc_size(enc_value); /* Size of encoded property */ - uint8_t **pp = (uint8_t **)_pp; + uint64_t enc_value = (uint64_t) * (const hsize_t *)value; /* Property value to encode */ + unsigned enc_size = H5VM_limit_enc_size(enc_value); /* Size of encoded property */ + uint8_t **pp = (uint8_t **)_pp; FUNC_ENTER_PACKAGE_NOERR @@ -145,7 +135,7 @@ H5P__encode_hsize_t(const void *value, void **_pp, size_t *size) HDassert(enc_size < 256); HDassert(size); - if(NULL != *pp) { + if (NULL != *pp) { *(*pp)++ = (uint8_t)enc_size; /* Encode the value */ @@ -158,7 +148,6 @@ H5P__encode_hsize_t(const void *value, void **_pp, size_t *size) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5P__encode_hsize_t() */ - /*------------------------------------------------------------------------- * Function: H5P__encode_unsigned * @@ -183,7 +172,7 @@ H5P__encode_unsigned(const void *value, void **_pp, size_t *size) HDassert(value); HDassert(size); - if(NULL != *pp) { + if (NULL != *pp) { /* Encode the size */ *(*pp)++ = (uint8_t)sizeof(unsigned); @@ -197,7 +186,6 @@ H5P__encode_unsigned(const void *value, void **_pp, size_t *size) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5P__encode_unsigned() */ - /*------------------------------------------------------------------------- * Function: H5P__encode_uint8_t * @@ -222,7 +210,7 @@ H5P__encode_uint8_t(const void *value, void **_pp, size_t *size) HDassert(value); HDassert(size); - if(NULL != *pp) { + if (NULL != *pp) { /* Encode the value */ *(*pp)++ = *(const uint8_t *)value; } /* end if */ @@ -233,7 +221,6 @@ H5P__encode_uint8_t(const void *value, void **_pp, size_t *size) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5P__encode_uint8_t() */ - /*------------------------------------------------------------------------- * Function: H5P__encode_hbool_t * @@ -258,9 +245,9 @@ H5P__encode_hbool_t(const void *value, void **_pp, size_t *size) HDassert(value); HDassert(size); - if(NULL != *pp) + if (NULL != *pp) /* Encode the value */ - *(*pp)++ = (uint8_t)*(const hbool_t *)value; + *(*pp)++ = (uint8_t) * (const hbool_t *)value; /* Set size needed for encoding */ *size += 1; @@ -268,7 +255,6 @@ H5P__encode_hbool_t(const void *value, void **_pp, size_t *size) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5P__encode_hbool_t() */ - /*------------------------------------------------------------------------- * Function: H5P__encode_double * @@ -293,7 +279,7 @@ H5P__encode_double(const void *value, void **_pp, size_t *size) HDassert(value); HDassert(size); - if(NULL != *pp) { + if (NULL != *pp) { /* Encode the size */ *(*pp)++ = (uint8_t)sizeof(double); @@ -307,7 +293,6 @@ H5P__encode_double(const void *value, void **_pp, size_t *size) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5P__encode_double() */ - /*-------------------------------------------------------------------------- NAME H5P__encode_cb @@ -331,8 +316,8 @@ H5P__encode_double(const void *value, void **_pp, size_t *size) static int H5P__encode_cb(H5P_genprop_t *prop, void *_udata) { - H5P_enc_iter_ud_t *udata = (H5P_enc_iter_ud_t *)_udata; /* Pointer to user data */ - int ret_value = H5_ITER_CONT; /* Return value */ + H5P_enc_iter_ud_t *udata = (H5P_enc_iter_ud_t *)_udata; /* Pointer to user data */ + int ret_value = H5_ITER_CONT; /* Return value */ FUNC_ENTER_STATIC @@ -341,13 +326,13 @@ H5P__encode_cb(H5P_genprop_t *prop, void *_udata) HDassert(udata); /* Check if this property can be encoded */ - if(prop->encode) { - size_t prop_name_len; /* Length of property's name */ - size_t prop_value_len; /* Encoded size of property's value */ + if (prop->encode) { + size_t prop_name_len; /* Length of property's name */ + size_t prop_value_len; /* Encoded size of property's value */ /* Encode (or not, if the 'encode' flag is off) the property's name */ prop_name_len = HDstrlen(prop->name) + 1; - if(udata->encode) { + if (udata->encode) { HDstrncpy((char *)*(udata->pp), prop->name, prop_name_len); *(uint8_t **)(udata->pp) += prop_name_len; } /* end if */ @@ -355,7 +340,7 @@ H5P__encode_cb(H5P_genprop_t *prop, void *_udata) /* Encode (or not, if *(udata->pp) is NULL) the property value */ prop_value_len = 0; - if((prop->encode)(prop->value, udata->pp, &prop_value_len) < 0) + if ((prop->encode)(prop->value, udata->pp, &prop_value_len) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTENCODE, H5_ITER_ERROR, "property encoding routine failed") *(udata->enc_size_ptr) += prop_value_len; } /* end if */ @@ -364,7 +349,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P__encode_cb() */ - /*------------------------------------------------------------------------- NAME H5P__encode @@ -389,30 +373,29 @@ done: REVISION LOG --------------------------------------------------------------------------*/ herr_t -H5P__encode(const H5P_genplist_t *plist, hbool_t enc_all_prop, void *buf, - size_t *nalloc) +H5P__encode(const H5P_genplist_t *plist, hbool_t enc_all_prop, void *buf, size_t *nalloc) { - H5P_enc_iter_ud_t udata; /* User data for property iteration callback */ - uint8_t *p = (uint8_t *)buf; /* Temporary pointer to encoding buffer */ - int idx; /* Index of property to start at */ - size_t encode_size = 0; /* Size of buffer needed to encode properties */ - hbool_t encode = TRUE; /* Whether the property list should be encoded */ - herr_t ret_value = SUCCEED; /* Return value */ + H5P_enc_iter_ud_t udata; /* User data for property iteration callback */ + uint8_t * p = (uint8_t *)buf; /* Temporary pointer to encoding buffer */ + int idx; /* Index of property to start at */ + size_t encode_size = 0; /* Size of buffer needed to encode properties */ + hbool_t encode = TRUE; /* Whether the property list should be encoded */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE /* Sanity check */ - if(NULL == nalloc) + if (NULL == nalloc) HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "bad allocation size pointer") /* If the buffer is NULL, then this call to H5P__encode will return how much * space is needed to encode a property. */ - if(NULL == p) + if (NULL == p) encode = FALSE; /* Encode property list description info */ - if(encode) { + if (encode) { /* Version # of property list encoding */ *p++ = (uint8_t)H5P_ENCODE_VERS; @@ -422,17 +405,17 @@ H5P__encode(const H5P_genplist_t *plist, hbool_t enc_all_prop, void *buf, encode_size += 2; /* Initialize user data for iteration callback */ - udata.encode = encode; + udata.encode = encode; udata.enc_size_ptr = &encode_size; - udata.pp = (void **)&p; + udata.pp = (void **)&p; /* Iterate over all properties in property list, encoding them */ idx = 0; - if(H5P__iterate_plist(plist, enc_all_prop, &idx, H5P__encode_cb, &udata) < 0) + if (H5P__iterate_plist(plist, enc_all_prop, &idx, H5P__encode_cb, &udata) < 0) HGOTO_ERROR(H5E_PLIST, H5E_BADITER, FAIL, "can't iterate over properties") /* Encode a terminator for list of properties */ - if(encode) + if (encode) *p++ = 0; encode_size++; @@ -443,7 +426,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P__encode() */ - /*------------------------------------------------------------------------- * Function: H5P__decode_size_t * @@ -460,10 +442,10 @@ done: herr_t H5P__decode_size_t(const void **_pp, void *_value) { - size_t *value = (size_t *)_value; /* Property value to return */ - const uint8_t **pp = (const uint8_t **)_pp; - uint64_t enc_value; /* Decoded property value */ - unsigned enc_size; /* Size of encoded property */ + size_t * value = (size_t *)_value; /* Property value to return */ + const uint8_t **pp = (const uint8_t **)_pp; + uint64_t enc_value; /* Decoded property value */ + unsigned enc_size; /* Size of encoded property */ FUNC_ENTER_PACKAGE_NOERR @@ -484,7 +466,6 @@ H5P__decode_size_t(const void **_pp, void *_value) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5P__decode_size_t() */ - /*------------------------------------------------------------------------- * Function: H5P__decode_hsize_t * @@ -501,10 +482,10 @@ H5P__decode_size_t(const void **_pp, void *_value) herr_t H5P__decode_hsize_t(const void **_pp, void *_value) { - hsize_t *value = (hsize_t *)_value; /* Property value to return */ - const uint8_t **pp = (const uint8_t **)_pp; - uint64_t enc_value; /* Decoded property value */ - unsigned enc_size; /* Size of encoded property */ + hsize_t * value = (hsize_t *)_value; /* Property value to return */ + const uint8_t **pp = (const uint8_t **)_pp; + uint64_t enc_value; /* Decoded property value */ + unsigned enc_size; /* Size of encoded property */ FUNC_ENTER_PACKAGE_NOERR @@ -525,7 +506,6 @@ H5P__decode_hsize_t(const void **_pp, void *_value) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5P__decode_hsize_t() */ - /*------------------------------------------------------------------------- * Function: H5P__decode_unsigned * @@ -542,10 +522,10 @@ H5P__decode_hsize_t(const void **_pp, void *_value) herr_t H5P__decode_unsigned(const void **_pp, void *_value) { - unsigned *value = (unsigned *)_value; /* Property value to return */ - const uint8_t **pp = (const uint8_t **)_pp; - unsigned enc_size; /* Size of encoded property */ - herr_t ret_value = SUCCEED; /* Return value */ + unsigned * value = (unsigned *)_value; /* Property value to return */ + const uint8_t **pp = (const uint8_t **)_pp; + unsigned enc_size; /* Size of encoded property */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -556,7 +536,7 @@ H5P__decode_unsigned(const void **_pp, void *_value) /* Decode the size */ enc_size = *(*pp)++; - if(enc_size != sizeof(unsigned)) + if (enc_size != sizeof(unsigned)) HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "unsigned value can't be decoded") H5_DECODE_UNSIGNED(*pp, *value) @@ -565,7 +545,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P__decode_unsigned() */ - /*------------------------------------------------------------------------- * Function: H5P__decode_uint8_t * @@ -582,9 +561,9 @@ done: herr_t H5P__decode_uint8_t(const void **_pp, void *_value) { - uint8_t *value = (uint8_t *)_value; /* Property value to return */ - const uint8_t **pp = (const uint8_t **)_pp; - herr_t ret_value = SUCCEED; /* Return value */ + uint8_t * value = (uint8_t *)_value; /* Property value to return */ + const uint8_t **pp = (const uint8_t **)_pp; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE_NOERR @@ -599,7 +578,6 @@ H5P__decode_uint8_t(const void **_pp, void *_value) FUNC_LEAVE_NOAPI(ret_value) } /* end H5P__decode_uint8_t() */ - /*------------------------------------------------------------------------- * Function: H5P__decode_hbool_t * @@ -616,9 +594,9 @@ H5P__decode_uint8_t(const void **_pp, void *_value) herr_t H5P__decode_hbool_t(const void **_pp, void *_value) { - hbool_t *value = (hbool_t *)_value; /* Property value to return */ - const uint8_t **pp = (const uint8_t **)_pp; - herr_t ret_value = SUCCEED; /* Return value */ + hbool_t * value = (hbool_t *)_value; /* Property value to return */ + const uint8_t **pp = (const uint8_t **)_pp; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE_NOERR @@ -628,12 +606,11 @@ H5P__decode_hbool_t(const void **_pp, void *_value) HDassert(value); /* Decode the value */ - *value = (hbool_t)*(*pp)++; + *value = (hbool_t) * (*pp)++; FUNC_LEAVE_NOAPI(ret_value) } /* end H5P__decode_hbool_t() */ - /*------------------------------------------------------------------------- * Function: H5P__decode_double * @@ -650,10 +627,10 @@ H5P__decode_hbool_t(const void **_pp, void *_value) herr_t H5P__decode_double(const void **_pp, void *_value) { - double *value = (double *)_value; /* Property value to return */ - const uint8_t **pp = (const uint8_t **)_pp; - unsigned enc_size; /* Size of encoded property */ - herr_t ret_value = SUCCEED; /* Return value */ + double * value = (double *)_value; /* Property value to return */ + const uint8_t **pp = (const uint8_t **)_pp; + unsigned enc_size; /* Size of encoded property */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -664,7 +641,7 @@ H5P__decode_double(const void **_pp, void *_value) /* Decode the size */ enc_size = *(*pp)++; - if(enc_size != sizeof(double)) + if (enc_size != sizeof(double)) HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "double value can't be decoded") H5_DECODE_DOUBLE(*pp, *value) @@ -673,7 +650,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P__decode_double() */ - /*------------------------------------------------------------------------- NAME H5P__decode @@ -700,46 +676,47 @@ done: hid_t H5P__decode(const void *buf) { - H5P_genplist_t *plist; /* Property list to decode into */ - void *value_buf = NULL; /* Pointer to buffer to use when decoding values */ - const uint8_t *p = (const uint8_t *)buf; /* Current pointer into buffer */ - H5P_plist_type_t type; /* Type of encoded property list */ - hid_t plist_id = -1; /* ID of new property list */ - size_t value_buf_size = 0; /* Size of current value buffer */ - uint8_t vers; /* Version of encoded property list */ - hid_t ret_value = H5I_INVALID_HID; /* Return value */ + H5P_genplist_t * plist; /* Property list to decode into */ + void * value_buf = NULL; /* Pointer to buffer to use when decoding values */ + const uint8_t * p = (const uint8_t *)buf; /* Current pointer into buffer */ + H5P_plist_type_t type; /* Type of encoded property list */ + hid_t plist_id = -1; /* ID of new property list */ + size_t value_buf_size = 0; /* Size of current value buffer */ + uint8_t vers; /* Version of encoded property list */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ FUNC_ENTER_PACKAGE /* Sanity check */ - if(NULL == p) + if (NULL == p) HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "decode buffer is NULL") /* Get the version number of the encoded property list */ vers = (uint8_t)*p++; - if((uint8_t)H5P_ENCODE_VERS != vers) - HGOTO_ERROR(H5E_PLIST, H5E_VERSION, FAIL, "bad version # of encoded information, expected %u, got %u", (unsigned)H5P_ENCODE_VERS, (unsigned)vers) + if ((uint8_t)H5P_ENCODE_VERS != vers) + HGOTO_ERROR(H5E_PLIST, H5E_VERSION, FAIL, "bad version # of encoded information, expected %u, got %u", + (unsigned)H5P_ENCODE_VERS, (unsigned)vers) /* Get the type of the property list */ type = (H5P_plist_type_t)*p++; - if(type <= H5P_TYPE_USER || type >= H5P_TYPE_MAX_TYPE) + if (type <= H5P_TYPE_USER || type >= H5P_TYPE_MAX_TYPE) HGOTO_ERROR(H5E_PLIST, H5E_BADRANGE, FAIL, "bad type of encoded information: %u", (unsigned)type) /* Create new property list of the specified type */ - if((plist_id = H5P__new_plist_of_type(type)) < 0) + if ((plist_id = H5P__new_plist_of_type(type)) < 0) HGOTO_ERROR(H5E_PLIST, H5E_VERSION, FAIL, "can't create property list of type: %u\n", (unsigned)type); /* Get the property list object */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(plist_id))) + if (NULL == (plist = (H5P_genplist_t *)H5I_object(plist_id))) HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a property class") /* Loop over encoded properties, deserializing their values */ - while(p) { - H5P_genprop_t *prop; /* Pointer to property with same name */ - const char *name; /* Pointer to property list name */ + while (p) { + H5P_genprop_t *prop; /* Pointer to property with same name */ + const char * name; /* Pointer to property list name */ /* Check for end of serialized list of properties */ - if(0 == *p) + if (0 == *p) break; /* Get property list name */ @@ -747,26 +724,27 @@ H5P__decode(const void *buf) p += HDstrlen(name) + 1; /* Find property with name */ - if(NULL == (prop = H5P__find_prop_plist(plist, name))) + if (NULL == (prop = H5P__find_prop_plist(plist, name))) HGOTO_ERROR(H5E_PLIST, H5E_NOTFOUND, FAIL, "property doesn't exist: '%s'", name) /* Check if we should increase the size of the value buffer */ - if(prop->size > value_buf_size) { - if(NULL == (value_buf = H5MM_realloc(value_buf, prop->size))) + if (prop->size > value_buf_size) { + if (NULL == (value_buf = H5MM_realloc(value_buf, prop->size))) HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "decoding buffer allocation failed") value_buf_size = prop->size; } /* end if */ /* Decode serialized value */ - if(prop->decode) { - if((prop->decode)((const void **)&p, value_buf) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTDECODE, FAIL, "property decoding routine failed, property: '%s'", name) + if (prop->decode) { + if ((prop->decode)((const void **)&p, value_buf) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTDECODE, FAIL, + "property decoding routine failed, property: '%s'", name) } /* end if */ else HGOTO_ERROR(H5E_PLIST, H5E_NOTFOUND, FAIL, "no decode callback for property: '%s'", name) /* Set the value for the property */ - if(H5P_poke(plist, name, value_buf) < 0) + if (H5P_poke(plist, name, value_buf) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set value for property: '%s'", name) } /* end while */ @@ -775,15 +753,15 @@ H5P__decode(const void *buf) done: /* Release resources */ - if(value_buf) + if (value_buf) value_buf = H5MM_xfree(value_buf); /* Cleanup on error */ - if(ret_value < 0) { - if(plist_id > 0 && H5I_dec_ref(plist_id) < 0) - HDONE_ERROR(H5E_PLIST, H5E_CANTCLOSEOBJ, FAIL, "unable to close partially initialized property list") + if (ret_value < 0) { + if (plist_id > 0 && H5I_dec_ref(plist_id) < 0) + HDONE_ERROR(H5E_PLIST, H5E_CANTCLOSEOBJ, FAIL, + "unable to close partially initialized property list") } /* end if */ FUNC_LEAVE_NOAPI(ret_value) } /* end H5P__decode() */ - |