summaryrefslogtreecommitdiffstats
path: root/src/H5Opline.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2006-10-23 20:40:14 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2006-10-23 20:40:14 (GMT)
commite40557304fcfc662bb1a445abca516ee4b246d94 (patch)
treec9f1692443a62e0c481c7c0278e39d7b83d1b419 /src/H5Opline.c
parent1062b4f9d7080a3e439df7d3d527aee43f96d085 (diff)
downloadhdf5-e40557304fcfc662bb1a445abca516ee4b246d94.zip
hdf5-e40557304fcfc662bb1a445abca516ee4b246d94.tar.gz
hdf5-e40557304fcfc662bb1a445abca516ee4b246d94.tar.bz2
[svn-r12803] Description:
Finish new version of the I/O pipeline message, which is much smaller than the previous version. This version is used with the "use the latest version of the format" flag. Closed several memory leaks/overruns (found with valgrind). Also, lots of compiler & formatting cleanups. Tested on: Linux/32 2.6 (chicago) Linux/64 2.6 (chicago2)
Diffstat (limited to 'src/H5Opline.c')
-rw-r--r--src/H5Opline.c577
1 files changed, 335 insertions, 242 deletions
diff --git a/src/H5Opline.c b/src/H5Opline.c
index 0a6bab0..86c8dd7 100644
--- a/src/H5Opline.c
+++ b/src/H5Opline.c
@@ -19,26 +19,25 @@
* Purpose: Data filter pipeline message.
*/
-#define H5O_PACKAGE /*suppress error about including H5Opkg */
-
-#include "H5private.h"
-#include "H5Eprivate.h"
-#include "H5FLprivate.h" /*Free Lists */
-#include "H5MMprivate.h"
-#include "H5Opkg.h" /* Object header functions */
-
-
-#define H5O_PLINE_VERSION 1
-
-static herr_t H5O_pline_encode (H5F_t *f, uint8_t *p, const void *mesg);
-static void *H5O_pline_decode (H5F_t *f, hid_t dxpl_id, const uint8_t *p);
-static void *H5O_pline_copy (const void *_mesg, void *_dest, unsigned update_flags);
-static size_t H5O_pline_size (const H5F_t *f, const void *_mesg);
-static herr_t H5O_pline_reset (void *_mesg);
-static herr_t H5O_pline_free (void *_mesg);
+#define H5O_PACKAGE /*suppress error about including H5Opkg */
+
+#include "H5private.h" /* Generic Functions */
+#include "H5Eprivate.h" /* Error handling */
+#include "H5FLprivate.h" /* Free Lists */
+#include "H5MMprivate.h" /* Memory management */
+#include "H5Opkg.h" /* Object headers */
+
+
+/* PRIVATE PROTOTYPES */
+static herr_t H5O_pline_encode(H5F_t *f, uint8_t *p, const void *mesg);
+static void *H5O_pline_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p);
+static void *H5O_pline_copy(const void *_mesg, void *_dest, unsigned update_flags);
+static size_t H5O_pline_size(const H5F_t *f, const void *_mesg);
+static herr_t H5O_pline_reset(void *_mesg);
+static herr_t H5O_pline_free(void *_mesg);
static herr_t H5O_pline_pre_copy_file(H5F_t *file_src, const H5O_msg_class_t *type,
void *mesg_src, hbool_t *deleted, const H5O_copy_t *cpy_info, void *_udata);
-static herr_t H5O_pline_debug (H5F_t *f, hid_t dxpl_id, const void *_mesg,
+static herr_t H5O_pline_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg,
FILE * stream, int indent, int fwidth);
/* This message derives from H5O message class */
@@ -63,6 +62,19 @@ const H5O_msg_class_t H5O_MSG_PLINE[1] = {{
}};
+/* The initial version of the format */
+#define H5O_PLINE_VERSION_1 1
+
+/* This version encodes the message fields more efficiently */
+/* (Drops the reserved bytes, doesn't align the name and doesn't encode the
+ * filter name at all if it's a filter provided by the library)
+ */
+#define H5O_PLINE_VERSION_2 2
+
+/* The latest version of the format. Look through the 'encode' and 'size'
+ * callbacks for places to change when updating this. */
+#define H5O_PLINE_VERSION_LATEST H5O_PLINE_VERSION_2
+
/* Declare a free list to manage the H5O_pline_t struct */
H5FL_DEFINE(H5O_pline_t);
@@ -73,92 +85,114 @@ H5FL_DEFINE(H5O_pline_t);
* Purpose: Decodes a filter pipeline message.
*
* Return: Success: Ptr to the native message.
- *
* Failure: NULL
*
* Programmer: Robb Matzke
* Wednesday, April 15, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static void *
H5O_pline_decode(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const uint8_t *p)
{
- H5O_pline_t *pline = NULL;
- void *ret_value;
- unsigned version;
- size_t i, j, n, name_length;
+ H5O_pline_t *pline = NULL; /* Pipeline message */
+ H5Z_filter_info_t *filter; /* Filter to decode */
+ unsigned version; /* Message version # */
+ size_t name_length; /* Length of filter name */
+ size_t i; /* Local index variable */
+ void *ret_value; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5O_pline_decode);
+ FUNC_ENTER_NOAPI_NOINIT(H5O_pline_decode)
/* check args */
- assert(p);
+ HDassert(p);
- /* Decode */
- if (NULL==(pline = H5FL_CALLOC(H5O_pline_t)))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ /* Allocate space for I/O pipeline message */
+ if(NULL == (pline = H5FL_CALLOC(H5O_pline_t)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
+
+ /* Version */
version = *p++;
- if (version!=H5O_PLINE_VERSION)
- HGOTO_ERROR(H5E_PLINE, H5E_CANTLOAD, NULL, "bad version number for filter pipeline message");
+ if(version < H5O_PLINE_VERSION_1 || version > H5O_PLINE_VERSION_LATEST)
+ HGOTO_ERROR(H5E_PLINE, H5E_CANTLOAD, NULL, "bad version number for filter pipeline message")
+
+ /* Number of filters */
pline->nused = *p++;
- if (pline->nused>H5Z_MAX_NFILTERS)
- HGOTO_ERROR(H5E_PLINE, H5E_CANTLOAD, NULL, "filter pipeline message has too many filters");
- p += 6; /*reserved*/
+ if(pline->nused > H5Z_MAX_NFILTERS)
+ HGOTO_ERROR(H5E_PLINE, H5E_CANTLOAD, NULL, "filter pipeline message has too many filters")
+
+ /* Reserved */
+ if(version == H5O_PLINE_VERSION_1)
+ p += 6;
+
+ /* Allocate array for filters */
pline->nalloc = pline->nused;
- pline->filter = H5MM_calloc(pline->nalloc*sizeof(pline->filter[0]));
- if (NULL==pline->filter)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
- for (i=0; i<pline->nused; i++) {
- UINT16DECODE(p, pline->filter[i].id);
- UINT16DECODE(p, name_length);
- if (name_length % 8)
- HGOTO_ERROR(H5E_PLINE, H5E_CANTLOAD, NULL, "filter name length is not a multiple of eight");
- UINT16DECODE(p, pline->filter[i].flags);
- UINT16DECODE(p, pline->filter[i].cd_nelmts);
- if (name_length) {
- /*
- * Get the name, allocating an extra byte for an extra null
- * terminator just in case there isn't one in the file (there
- * should be, but to be safe...)
- */
- pline->filter[i].name = H5MM_malloc(name_length+1);
- HDmemcpy(pline->filter[i].name, p, name_length);
- pline->filter[i].name[name_length] = '\0';
+ if(NULL == (pline->filter = H5MM_calloc(pline->nalloc * sizeof(pline->filter[0]))))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
+
+ /* Decode filters */
+ for(i = 0, filter = &pline->filter[0]; i < pline->nused; i++, filter++) {
+ /* Filter ID */
+ UINT16DECODE(p, filter->id);
+
+ /* Length of filter name */
+ if(version > H5O_PLINE_VERSION_1 && filter->id < H5Z_FILTER_RESERVED)
+ name_length = 0;
+ else {
+ UINT16DECODE(p, name_length);
+ if(version == H5O_PLINE_VERSION_1 && name_length % 8)
+ HGOTO_ERROR(H5E_PLINE, H5E_CANTLOAD, NULL, "filter name length is not a multiple of eight")
+ } /* end if */
+
+ /* Filter flags */
+ UINT16DECODE(p, filter->flags);
+
+ /* Number of filter parameters ("client data elements") */
+ UINT16DECODE(p, filter->cd_nelmts);
+
+ /* Filter name, if there is one */
+ if(name_length) {
+ filter->name = H5MM_malloc(name_length);
+ HDmemcpy(filter->name, p, name_length);
+ HDassert(filter->name[name_length - 1] == '\0');
p += name_length;
- }
- if ((n=pline->filter[i].cd_nelmts)) {
+ } /* end if */
+
+ /* Filter parameters */
+ if(filter->cd_nelmts) {
+ size_t j; /* Local index variable */
+
/*
* Read the client data values and the padding
*/
- pline->filter[i].cd_values = H5MM_malloc(n*sizeof(unsigned));
- if (NULL==pline->filter[i].cd_values)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for client data");
- for (j=0; j<pline->filter[i].cd_nelmts; j++)
- UINT32DECODE(p, pline->filter[i].cd_values[j]);
- if (pline->filter[i].cd_nelmts % 2)
- p += 4; /*padding*/
- }
- }
+ filter->cd_values = H5MM_malloc(filter->cd_nelmts * sizeof(unsigned));
+ if(NULL == filter->cd_values)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for client data")
+ for(j = 0; j < filter->cd_nelmts; j++)
+ UINT32DECODE(p, filter->cd_values[j]);
+ if(version == H5O_PLINE_VERSION_1)
+ if(filter->cd_nelmts % 2)
+ p += 4; /*padding*/
+ } /* end if */
+ } /* end for */
/* Set return value */
ret_value = pline;
done:
- if (NULL==ret_value && pline) {
- if (pline->filter) {
- for (i=0; i<pline->nused; i++) {
+ if(NULL == ret_value && pline) {
+ if(pline->filter) {
+ for(i = 0; i < pline->nused; i++) {
H5MM_xfree(pline->filter[i].name);
H5MM_xfree(pline->filter[i].cd_values);
- }
+ } /* end for */
H5MM_xfree(pline->filter);
- }
+ } /* end if */
H5FL_FREE(H5O_pline_t,pline);
- }
+ } /* end if */
- FUNC_LEAVE_NOAPI(ret_value);
-}
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5O_pline_decode() */
/*-------------------------------------------------------------------------
@@ -171,63 +205,99 @@ done:
* Programmer: Robb Matzke
* Wednesday, April 15, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
-H5O_pline_encode (H5F_t UNUSED *f, uint8_t *p/*out*/, const void *mesg)
+H5O_pline_encode(H5F_t UNUSED *f, uint8_t *p/*out*/, const void *mesg)
{
- const H5O_pline_t *pline = (const H5O_pline_t*)mesg;
- size_t i, j, name_length;
- const char *name=NULL;
- H5Z_class_t *cls=NULL;
+ const H5O_pline_t *pline = (const H5O_pline_t*)mesg; /* Pipeline message to encode */
+ const H5Z_filter_info_t *filter; /* Filter to encode */
+ unsigned version; /* Message version # */
+ size_t i, j; /* Local index variables */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_pline_encode);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_pline_encode)
/* Check args */
- assert (p);
- assert (mesg);
+ HDassert(p);
+ HDassert(mesg);
- *p++ = H5O_PLINE_VERSION;
+ /* Set the version of the message to encode */
+ if(H5F_USE_LATEST_FORMAT(f))
+ version = H5O_PLINE_VERSION_LATEST;
+ else
+ version = H5O_PLINE_VERSION_1;
+
+ /* Message header */
+ *p++ = version;
*p++ = (uint8_t)(pline->nused);
- *p++ = 0; /*reserved 1*/
- *p++ = 0; /*reserved 2*/
- *p++ = 0; /*reserved 3*/
- *p++ = 0; /*reserved 4*/
- *p++ = 0; /*reserved 5*/
- *p++ = 0; /*reserved 6*/
-
- for (i=0; i<pline->nused; i++) {
- /*
- * Get the filter name. If the pipeline message has a name in it then
- * use that one. Otherwise try to look up the filter and get the name
- * as it was registered.
- */
- if (NULL==(name=pline->filter[i].name) &&
- (cls=H5Z_find(pline->filter[i].id)))
- name = cls->name;
- name_length = name ? HDstrlen(name)+1 : 0;
-
- /* Encode the filter */
- UINT16ENCODE(p, pline->filter[i].id);
- UINT16ENCODE(p, H5O_ALIGN_OLD(name_length));
- UINT16ENCODE(p, pline->filter[i].flags);
- UINT16ENCODE(p, pline->filter[i].cd_nelmts);
- if (name_length>0) {
+ if(version == H5O_PLINE_VERSION_1) {
+ *p++ = 0; /*reserved 1*/
+ *p++ = 0; /*reserved 2*/
+ *p++ = 0; /*reserved 3*/
+ *p++ = 0; /*reserved 4*/
+ *p++ = 0; /*reserved 5*/
+ *p++ = 0; /*reserved 6*/
+ } /* end if */
+
+ /* Encode filters */
+ for(i = 0, filter = &pline->filter[0]; i < pline->nused; i++, filter++) {
+ const char *name; /* Filter name */
+ size_t name_length; /* Length of filter name */
+
+ /* Filter ID */
+ UINT16ENCODE(p, filter->id);
+
+ /* Skip writing the name length & name if the filter is an internal filter */
+ if(version > H5O_PLINE_VERSION_1 && filter->id < H5Z_FILTER_RESERVED) {
+ name_length = 0;
+ name = NULL;
+ } /* end if */
+ else {
+ H5Z_class_t *cls; /* Filter class */
+
+ /*
+ * Get the filter name. If the pipeline message has a name in it then
+ * use that one. Otherwise try to look up the filter and get the name
+ * as it was registered.
+ */
+ if(NULL == (name = filter->name) && (cls = H5Z_find(filter->id)))
+ name = cls->name;
+ name_length = name ? HDstrlen(name) + 1 : 0;
+
+ /* Filter name length */
+ UINT16ENCODE(p, version == H5O_PLINE_VERSION_1 ? H5O_ALIGN_OLD(name_length) : name_length);
+ } /* end else */
+
+ /* Filter flags */
+ UINT16ENCODE(p, filter->flags);
+
+ /* # of filter parameters */
+ UINT16ENCODE(p, filter->cd_nelmts);
+
+ /* Encode name, if there is one to encode */
+ if(name_length > 0) {
+ /* Store name, with null terminator */
HDmemcpy(p, name, name_length);
p += name_length;
- while (name_length++ % 8)
- *p++ = 0;
- }
- for (j=0; j<pline->filter[i].cd_nelmts; j++)
- UINT32ENCODE(p, pline->filter[i].cd_values[j]);
- if (pline->filter[i].cd_nelmts % 2)
- UINT32ENCODE(p, 0);
- }
-
- FUNC_LEAVE_NOAPI(SUCCEED);
-}
+
+ /* Pad out name to alignment, in older versions */
+ if(version == H5O_PLINE_VERSION_1)
+ while(name_length++ % 8)
+ *p++ = 0;
+ } /* end if */
+
+ /* Filter parameters */
+ for(j = 0; j < filter->cd_nelmts; j++)
+ UINT32ENCODE(p, filter->cd_values[j]);
+
+ /* Align the parameters for older versions of the format */
+ if(version == H5O_PLINE_VERSION_1)
+ if(filter->cd_nelmts % 2)
+ UINT32ENCODE(p, 0);
+ } /* end for */
+
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* end H5O_pline_encode() */
/*-------------------------------------------------------------------------
@@ -244,66 +314,72 @@ H5O_pline_encode (H5F_t UNUSED *f, uint8_t *p/*out*/, const void *mesg)
* Programmer: Robb Matzke
* Wednesday, April 15, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static void *
-H5O_pline_copy (const void *_src, void *_dst/*out*/, unsigned UNUSED update_flags)
+H5O_pline_copy(const void *_src, void *_dst/*out*/, unsigned UNUSED update_flags)
{
- const H5O_pline_t *src = (const H5O_pline_t *)_src;
- H5O_pline_t *dst = (H5O_pline_t *)_dst;
- size_t i;
- H5O_pline_t *ret_value;
+ const H5O_pline_t *src = (const H5O_pline_t *)_src; /* Source pipeline message */
+ H5O_pline_t *dst = (H5O_pline_t *)_dst; /* Destination pipeline message */
+ size_t i; /* Local index variable */
+ H5O_pline_t *ret_value; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5O_pline_copy);
+ FUNC_ENTER_NOAPI_NOINIT(H5O_pline_copy)
- if (!dst && NULL==(dst = H5FL_MALLOC (H5O_pline_t)))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ /* Allocate pipeline message, if not provided */
+ if(!dst && NULL == (dst = H5FL_MALLOC(H5O_pline_t)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
+ /* Shallow copy basic fields */
*dst = *src;
+
+ /* Copy over filters, if any */
dst->nalloc = dst->nused;
- if (dst->nalloc>0) {
- dst->filter = H5MM_calloc(dst->nalloc * sizeof(dst->filter[0]));
- if (NULL==dst->filter)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
- } else {
+ if(dst->nalloc) {
+ /* Allocate array to hold filters */
+ if(NULL == (dst->filter = H5MM_calloc(dst->nalloc * sizeof(dst->filter[0]))))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
+
+ /* Deep-copy filters */
+ for(i = 0; i < src->nused; i++) {
+ /* Basic filter information */
+ dst->filter[i] = src->filter[i];
+
+ /* Filter name */
+ if(src->filter[i].name)
+ if(NULL == (dst->filter[i].name = H5MM_xstrdup(src->filter[i].name)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
+
+ /* Filter parameters */
+ if(src->filter[i].cd_nelmts > 0) {
+ if(NULL == (dst->filter[i].cd_values = H5MM_malloc(src->filter[i].cd_nelmts* sizeof(unsigned))))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
+ HDmemcpy(dst->filter[i].cd_values, src->filter[i].cd_values,
+ src->filter[i].cd_nelmts * sizeof(unsigned));
+ } /* end if */
+ } /* end for */
+ } /* end if */
+ else
dst->filter = NULL;
- }
-
- for (i=0; i<src->nused; i++) {
- dst->filter[i] = src->filter[i];
- if (src->filter[i].name) {
- dst->filter[i].name = H5MM_xstrdup(src->filter[i].name);
- }
- if (src->filter[i].cd_nelmts>0) {
- dst->filter[i].cd_values = H5MM_malloc(src->filter[i].cd_nelmts*
- sizeof(unsigned));
- if (NULL==dst->filter[i].cd_values)
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
- HDmemcpy (dst->filter[i].cd_values, src->filter[i].cd_values,
- src->filter[i].cd_nelmts * sizeof(unsigned));
- }
- }
/* Set return value */
ret_value = dst;
done:
- if (!ret_value && dst) {
- if (dst->filter) {
- for (i=0; i<dst->nused; i++) {
+ if(!ret_value && dst) {
+ if(dst->filter) {
+ for(i = 0; i < dst->nused; i++) {
H5MM_xfree(dst->filter[i].name);
H5MM_xfree(dst->filter[i].cd_values);
- }
+ } /* end for */
H5MM_xfree(dst->filter);
- }
- if (!_dst)
+ } /* end if */
+ if(!_dst)
H5FL_FREE(H5O_pline_t,dst);
- }
+ } /* end if */
- FUNC_LEAVE_NOAPI(ret_value);
-}
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5O_pline_copy() */
/*-------------------------------------------------------------------------
@@ -318,47 +394,60 @@ done:
* Programmer: Robb Matzke
* Wednesday, April 15, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static size_t
-H5O_pline_size (const H5F_t UNUSED *f, const void *mesg)
+H5O_pline_size(const H5F_t *f, const void *mesg)
{
- const H5O_pline_t *pline = (const H5O_pline_t*)mesg;
- size_t i, name_len;
- const char *name = NULL;
- H5Z_class_t *cls = NULL;
+ const H5O_pline_t *pline = (const H5O_pline_t*)mesg; /* Pipeline message */
+ unsigned version; /* Message version # */
+ size_t i; /* Local index variable */
size_t ret_value; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_pline_size);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_pline_size)
+
+ /* Set the version of the message to encode */
+ if(H5F_USE_LATEST_FORMAT(f))
+ version = H5O_PLINE_VERSION_LATEST;
+ else
+ version = H5O_PLINE_VERSION_1;
/* Message header */
ret_value = 1 + /*version */
1 + /*number of filters */
- 6; /*reserved */
-
- for (i=0; i<pline->nused; i++) {
- /* Get the name of the filter, same as done with H5O_pline_encode() */
- if (NULL==(name=pline->filter[i].name) &&
- (cls=H5Z_find(pline->filter[i].id)))
- name = cls->name;
- name_len = name ? HDstrlen(name)+1 : 0;
-
-
- ret_value += 2 + /*filter identification number */
- 2 + /*name length */
- 2 + /*flags */
- 2 + /*number of client data values */
- H5O_ALIGN_OLD(name_len); /*length of the filter name */
+ (version == H5O_PLINE_VERSION_1 ? 6 : 0); /*reserved */
+
+ /* Calculate size of each filter in pipeline */
+ for(i = 0; i < pline->nused; i++) {
+ size_t name_len; /* Length of filter name */
+ const char *name; /* Filter name */
+
+ /* Don't write the name length & name if the filter is an internal filter */
+ if(version > H5O_PLINE_VERSION_1 && pline->filter[i].id < H5Z_FILTER_RESERVED)
+ name_len = 0;
+ else {
+ H5Z_class_t *cls; /* Filter class */
+
+ /* Get the name of the filter, same as done with H5O_pline_encode() */
+ if(NULL == (name = pline->filter[i].name) && (cls = H5Z_find(pline->filter[i].id)))
+ name = cls->name;
+ name_len = name ? HDstrlen(name) + 1 : 0;
+ } /* end else */
+
+ ret_value += 2 + /*filter identification number */
+ ((version == H5O_PLINE_VERSION_1 || pline->filter[i].id >= H5Z_FILTER_RESERVED) ? 2 : 0) + /*name length */
+ 2 + /*flags */
+ 2 + /*number of client data values */
+ (version == H5O_PLINE_VERSION_1 ? H5O_ALIGN_OLD(name_len) : name_len); /*length of the filter name */
ret_value += pline->filter[i].cd_nelmts * 4;
- if (pline->filter[i].cd_nelmts % 2)
- ret_value += 4;
- }
+ if(version == H5O_PLINE_VERSION_1)
+ if(pline->filter[i].cd_nelmts % 2)
+ ret_value += 4;
+ } /* end for */
- FUNC_LEAVE_NOAPI(ret_value);
-}
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5O_pline_size() */
/*-------------------------------------------------------------------------
@@ -372,30 +461,33 @@ H5O_pline_size (const H5F_t UNUSED *f, const void *mesg)
* Programmer: Robb Matzke
* Wednesday, April 15, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
-H5O_pline_reset (void *mesg)
+H5O_pline_reset(void *mesg)
{
- H5O_pline_t *pline = (H5O_pline_t*)mesg;
- size_t i;
+ H5O_pline_t *pline = (H5O_pline_t*)mesg; /* Pipeline message */
+ size_t i; /* Local index variable */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_pline_reset);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_pline_reset)
- assert (pline);
+ HDassert(pline);
- for (i=0; i<pline->nused; i++) {
+ /* Free information for each filter */
+ for(i = 0; i < pline->nused; i++) {
H5MM_xfree(pline->filter[i].name);
H5MM_xfree(pline->filter[i].cd_values);
- }
+ } /* end for */
+
+ /* Free filter array */
if(pline->filter)
- H5MM_xfree(pline->filter);
- HDmemset(pline, 0, sizeof *pline);
+ pline->filter = H5MM_xfree(pline->filter);
+
+ /* Reset # of filters */
+ pline->nused = pline->nalloc = 0;
- FUNC_LEAVE_NOAPI(SUCCEED);
-}
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* end H5O_pline_reset() */
/*-------------------------------------------------------------------------
@@ -413,16 +505,16 @@ H5O_pline_reset (void *mesg)
*-------------------------------------------------------------------------
*/
static herr_t
-H5O_pline_free (void *mesg)
+H5O_pline_free(void *mesg)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_pline_free);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_pline_free)
- assert (mesg);
+ HDassert (mesg);
- H5FL_FREE(H5O_pline_t,mesg);
+ H5FL_FREE(H5O_pline_t, mesg);
- FUNC_LEAVE_NOAPI(SUCCEED);
-}
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* end H5O_pline_free() */
/*-------------------------------------------------------------------------
@@ -458,16 +550,14 @@ H5O_pline_pre_copy_file(H5F_t UNUSED *file_src, const H5O_msg_class_t UNUSED *ty
* and make a copy of the filter pipeline for later in
* the object copying process.
*/
- if(udata) {
- if(NULL == (udata->src_pline = H5O_copy(H5O_PLINE_ID, pline_src, udata->src_pline)))
+ if(udata)
+ if(NULL == (udata->src_pline = H5O_pline_copy(pline_src, NULL, 0)))
HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to copy")
- } /* end if */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5O_pline_pre_copy_file() */
-
/*-------------------------------------------------------------------------
* Function: H5O_pline_debug
@@ -481,60 +571,63 @@ done:
* Programmer: Robb Matzke
* Wednesday, April 15, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
-H5O_pline_debug (H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const void *mesg, FILE *stream,
+H5O_pline_debug(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const void *mesg, FILE *stream,
int indent, int fwidth)
{
const H5O_pline_t *pline = (const H5O_pline_t *)mesg;
size_t i, j;
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_pline_debug);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_pline_debug)
/* check args */
- assert(f);
- assert(pline);
- assert(stream);
- assert(indent >= 0);
- assert(fwidth >= 0);
+ HDassert(f);
+ HDassert(pline);
+ HDassert(stream);
+ HDassert(indent >= 0);
+ HDassert(fwidth >= 0);
- fprintf(stream, "%*s%-*s %lu/%lu\n", indent, "", fwidth,
+ HDfprintf(stream, "%*s%-*s %Zu/%Zu\n", indent, "", fwidth,
"Number of filters:",
- (unsigned long)(pline->nused),
- (unsigned long)(pline->nalloc));
+ pline->nused,
+ pline->nalloc);
- for (i=0; i<pline->nused; i++) {
+ /* Loop over all the filters */
+ for(i = 0; i < pline->nused; i++) {
char name[32];
- sprintf(name, "Filter at position %lu", (unsigned long)i);
- fprintf(stream, "%*s%-*s\n", indent, "", fwidth, name);
- fprintf(stream, "%*s%-*s 0x%04x\n", indent+3, "", MAX(0, fwidth-3),
+
+ sprintf(name, "Filter at position %u", (unsigned)i);
+ HDfprintf(stream, "%*s%-*s\n", indent, "", fwidth, name);
+ HDfprintf(stream, "%*s%-*s 0x%04x\n", indent + 3, "", MAX(0, fwidth - 3),
"Filter identification:",
(unsigned)(pline->filter[i].id));
- if (pline->filter[i].name) {
- fprintf(stream, "%*s%-*s \"%s\"\n", indent+3, "", MAX(0, fwidth-3),
+ if(pline->filter[i].name)
+ HDfprintf(stream, "%*s%-*s \"%s\"\n", indent + 3, "", MAX(0, fwidth - 3),
"Filter name:",
pline->filter[i].name);
- } else {
- fprintf(stream, "%*s%-*s NONE\n", indent+3, "", MAX(0, fwidth-3),
+ else
+ HDfprintf(stream, "%*s%-*s NONE\n", indent + 3, "", MAX(0, fwidth - 3),
"Filter name:");
- }
- fprintf(stream, "%*s%-*s 0x%04x\n", indent+3, "", MAX(0, fwidth-3),
+ HDfprintf(stream, "%*s%-*s 0x%04x\n", indent + 3, "", MAX(0, fwidth - 3),
"Flags:",
- (unsigned)(pline->filter[i].flags));
- fprintf(stream, "%*s%-*s %lu\n", indent+3, "", MAX(0, fwidth-3),
+ pline->filter[i].flags);
+ HDfprintf(stream, "%*s%-*s %Zu\n", indent + 3, "", MAX(0, fwidth - 3),
"Num CD values:",
- (unsigned long)(pline->filter[i].cd_nelmts));
- for (j=0; j<pline->filter[i].cd_nelmts; j++) {
+ pline->filter[i].cd_nelmts);
+
+ /* Filter parameters */
+ for(j = 0; j < pline->filter[i].cd_nelmts; j++) {
char field_name[32];
+
sprintf(field_name, "CD value %lu", (unsigned long)j);
- fprintf(stream, "%*s%-*s %lu\n", indent+6, "", MAX(0, fwidth-6),
+ HDfprintf(stream, "%*s%-*s %u\n", indent + 6, "", MAX(0, fwidth - 6),
field_name,
- (unsigned long)(pline->filter[i].cd_values[j]));
- }
- }
+ pline->filter[i].cd_values[j]);
+ } /* end for */
+ } /* end for */
+
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* end H5O_pline_debug() */
- FUNC_LEAVE_NOAPI(SUCCEED);
-}