diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/H5Dcompact.c | 39 | ||||
-rw-r--r-- | src/H5Dcontig.c | 11 | ||||
-rw-r--r-- | src/H5Distore.c | 20 | ||||
-rw-r--r-- | src/H5E.c | 230 | ||||
-rw-r--r-- | src/H5Epublic.h | 12 | ||||
-rw-r--r-- | src/H5FDcore.c | 2 | ||||
-rw-r--r-- | src/H5FDlog.c | 2 | ||||
-rw-r--r-- | src/H5O.c | 11 | ||||
-rw-r--r-- | src/H5Odtype.c | 2 | ||||
-rw-r--r-- | src/H5Opline.c | 577 | ||||
-rw-r--r-- | src/H5P.c | 2 | ||||
-rw-r--r-- | src/H5Pdcpl.c | 404 | ||||
-rw-r--r-- | src/H5Pdxpl.c | 2 | ||||
-rw-r--r-- | src/H5Ppublic.h | 4 | ||||
-rw-r--r-- | src/H5T.c | 4 | ||||
-rw-r--r-- | src/H5Tconv.c | 2 | ||||
-rw-r--r-- | src/H5Tnative.c | 12 | ||||
-rw-r--r-- | src/H5Zfletcher32.c | 4 | ||||
-rw-r--r-- | src/H5Znbit.c | 29 | ||||
-rw-r--r-- | src/H5Zscaleoffset.c | 33 | ||||
-rw-r--r-- | src/H5Ztrans.c | 33 |
21 files changed, 790 insertions, 645 deletions
diff --git a/src/H5Dcompact.c b/src/H5Dcompact.c index 2d17a57..adc91eb 100644 --- a/src/H5Dcompact.c +++ b/src/H5Dcompact.c @@ -185,24 +185,33 @@ H5D_compact_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst, if(!dt_src) /* Type conversion not necessary */ HDmemcpy(layout_dst->u.compact.buf, layout_src->u.compact.buf, layout_src->u.compact.size); - else if(dt_src && (H5T_get_class(dt_src, FALSE) == H5T_REFERENCE) && (f_src != f_dst)) { - /* Check for expanding references */ - if(cpy_info->expand_ref) { - size_t ref_count; - - /* Determine # of reference elements to copy */ - ref_count = layout_src->u.compact.size / H5T_get_size(dt_src); - - /* Copy objects referenced in source buffer to destination file and set destination elements */ - if(H5O_copy_expand_ref(f_src, layout_src->u.compact.buf, dxpl_id, f_dst, - layout_dst->u.compact.buf, ref_count, H5T_get_ref_type(dt_src), cpy_info) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, FAIL, "unable to copy reference attribute") + else if(H5T_get_class(dt_src, FALSE) == H5T_REFERENCE) { + /* Create datatype ID for src datatype, so it gets freed */ + if((tid_src = H5I_register(H5I_DATATYPE, dt_src)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register source file datatype") + + if(f_src != f_dst) { + /* Check for expanding references */ + if(cpy_info->expand_ref) { + size_t ref_count; + + /* Determine # of reference elements to copy */ + ref_count = layout_src->u.compact.size / H5T_get_size(dt_src); + + /* Copy objects referenced in source buffer to destination file and set destination elements */ + if(H5O_copy_expand_ref(f_src, layout_src->u.compact.buf, dxpl_id, f_dst, + layout_dst->u.compact.buf, ref_count, H5T_get_ref_type(dt_src), cpy_info) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, FAIL, "unable to copy reference attribute") + } /* end if */ + else + /* Reset value to zero */ + HDmemset(layout_dst->u.compact.buf, 0, layout_src->u.compact.size); } /* end if */ else - /* Reset value to zero */ - HDmemset(layout_dst->u.compact.buf, 0, layout_src->u.compact.size); + /* Type conversion not necessary */ + HDmemcpy(layout_dst->u.compact.buf, layout_src->u.compact.buf, layout_src->u.compact.size); } /* end if */ - else if(dt_src && (H5T_detect_class(dt_src, H5T_VLEN) > 0) ) { + else if(H5T_detect_class(dt_src, H5T_VLEN) > 0) { H5T_path_t *tpath_src_mem, *tpath_mem_dst; /* Datatype conversion paths */ H5T_t *dt_dst; /* Destination datatype */ H5T_t *dt_mem; /* Memory datatype */ diff --git a/src/H5Dcontig.c b/src/H5Dcontig.c index 5b4b0d2..09b83ec 100644 --- a/src/H5Dcontig.c +++ b/src/H5Dcontig.c @@ -1110,9 +1110,14 @@ H5D_contig_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst, is_vlen = TRUE; } /* Check for reference datatype */ - else if((H5T_get_class(dt_src, FALSE) == H5T_REFERENCE) && (f_src != f_dst)) { - /* need to fix values of reference */ - fix_ref = TRUE; + else if(H5T_get_class(dt_src, FALSE) == H5T_REFERENCE) { + /* Create datatype ID for src datatype, so it gets freed */ + if((tid_src = H5I_register(H5I_DATATYPE, dt_src)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register source file datatype") + + /* Need to fix values of references when copying across files */ + if(f_src != f_dst) + fix_ref = TRUE; /* Set the number of bytes to read & write to the buffer size */ src_nbytes = dst_nbytes = mem_nbytes = buf_size; diff --git a/src/H5Distore.c b/src/H5Distore.c index 8518763..e4e9eee 100644 --- a/src/H5Distore.c +++ b/src/H5Distore.c @@ -1034,6 +1034,14 @@ H5D_istore_iter_copy(H5F_t *f_src, hid_t dxpl_id, const void *_lt_key, /* Re-allocate memory for copying the chunk */ if(NULL == (udata->buf = H5MM_realloc(udata->buf, nbytes))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5B_ITER_ERROR, "memory allocation failed for raw data chunk") + if(udata->bkg) { + if(NULL == (udata->bkg = H5MM_realloc(udata->bkg, nbytes))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5B_ITER_ERROR, "memory allocation failed for raw data chunk") + if(!udata->cpy_info->expand_ref) + HDmemset((uint8_t *)udata->bkg + buf_size, 0, (size_t)(nbytes - buf_size)); + + bkg = udata->bkg; + } /* end if */ buf = udata->buf; udata->buf_size = buf_size = nbytes; @@ -1044,7 +1052,7 @@ H5D_istore_iter_copy(H5F_t *f_src, hid_t dxpl_id, const void *_lt_key, HGOTO_ERROR(H5E_IO, H5E_READERROR, H5B_ITER_ERROR, "unable to read raw data chunk") /* Need to uncompress variable-length & reference data elements */ - if(is_compressed && (is_vlen | fix_ref)) { + if(is_compressed && (is_vlen || fix_ref)) { unsigned filter_mask = lt_key->filter_mask; if(H5Z_pipeline(pline, H5Z_FLAG_REVERSE, &filter_mask, edc_read, cb_struct, &nbytes, &buf_size, &buf) < 0) @@ -3651,6 +3659,13 @@ H5D_istore_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst, HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for raw data chunk") } /* end if */ else { + /* Create datatype ID for source datatype, so it gets freed */ + if(H5T_get_class(dt_src, FALSE) == H5T_REFERENCE) { + /* Create datatype ID for src datatype */ + if((tid_src = H5I_register(H5I_DATATYPE, dt_src)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register source file datatype") + } /* end if */ + buf_size = layout_src->u.chunk.size; reclaim_buf_size = 0; } /* end else */ @@ -3700,8 +3715,9 @@ H5D_istore_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst, if(H5B_iterate(f_src, dxpl_id, H5B_ISTORE, H5D_istore_iter_copy, layout_src->u.chunk.addr, &udata) < 0) HGOTO_ERROR(H5E_IO, H5E_CANTINIT, FAIL, "unable to iterate over chunk B-tree") - /* I/O buffer may have been re-allocated */ + /* I/O buffers may have been re-allocated */ buf = udata.buf; + bkg = udata.bkg; done: if(sid_buf > 0) @@ -84,6 +84,16 @@ H5E_t H5E_stack_g[1]; #endif /* H5_HAVE_THREADSAFE */ +/******************/ +/* Local Typedefs */ +/******************/ + +/* Some syntactic sugar to make the compiler happy with two different kinds of callbacks */ +typedef union { + H5E_auto_stack_t stack_efunc; /* New-style callback, with error stack param. */ + H5E_auto_t efunc; /* Old-style callback, NO error stack param. */ +} H5E_auto_op_t; + #ifdef H5_HAVE_PARALLEL /* * variables used for MPI error reporting @@ -112,8 +122,8 @@ static herr_t H5E_walk_stack(const H5E_t *estack, H5E_direction_t direction, H5 H5E_walk_stack_t stack_func, hbool_t bk_compatible, void *client_data); static herr_t H5E_walk_cb(unsigned n, const H5E_error_t *err_desc, void *client_data); static herr_t H5E_walk_stack_cb(unsigned n, const H5E_error_stack_t *err_desc, void *client_data); -static herr_t H5E_get_auto_stack(const H5E_t *estack, hbool_t new_api, void **func, void **client_data); -static herr_t H5E_set_auto_stack(H5E_t *estack, hbool_t new_api, void *func, void *client_data); +static herr_t H5E_get_auto_stack(const H5E_t *estack, hbool_t new_api, H5E_auto_op_t *func, void **client_data); +static herr_t H5E_set_auto_stack(H5E_t *estack, hbool_t new_api, H5E_auto_op_t *func, void *client_data); /* Declare a free list to manage the H5E_t struct */ H5FL_DEFINE_STATIC(H5E_t); @@ -204,7 +214,7 @@ H5E_init_interface(void) assert(H5E_ERR_CLS_g==(-1)); HDsnprintf(lib_vers,sizeof(lib_vers),"%u.%u.%u%s",H5_VERS_MAJOR,H5_VERS_MINOR,H5_VERS_RELEASE,(HDstrlen(H5_VERS_SUBRELEASE)>0 ? "-"H5_VERS_SUBRELEASE : "")); if((cls = H5E_register_class(H5E_CLS_NAME, H5E_CLS_LIB_NAME, lib_vers))==NULL) - HGOTO_ERROR (H5E_ERROR, H5E_CANTINIT, FAIL, "class initialization failed") + HGOTO_ERROR(H5E_ERROR, H5E_CANTINIT, FAIL, "class initialization failed") if((H5E_ERR_CLS_g = H5I_register(H5I_ERROR_CLASS, cls))<0) HGOTO_ERROR(H5E_ERROR, H5E_CANTREGISTER, FAIL, "can't register error class") @@ -408,15 +418,15 @@ H5E_register_class(const char *cls_name, const char *lib_name, const char *versi /* Allocate space for new error class */ if((cls = H5FL_MALLOC(H5E_cls_t))==NULL) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Duplicate string information */ - if((cls->cls_name = HDstrdup(cls_name))==NULL) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - if((cls->lib_name = HDstrdup(lib_name))==NULL) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - if((cls->lib_vers = HDstrdup(version))==NULL) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + if((cls->cls_name = H5MM_xstrdup(cls_name))==NULL) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + if((cls->lib_name = H5MM_xstrdup(lib_name))==NULL) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + if((cls->lib_vers = H5MM_xstrdup(version))==NULL) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Set the return value */ ret_value=cls; @@ -757,13 +767,13 @@ H5E_create_msg(H5E_cls_t *cls, H5E_type_t msg_type, const char *msg_str) /* Allocate new message object */ if((msg = H5FL_MALLOC(H5E_msg_t))==NULL) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Fill new message object */ msg->cls = cls; msg->type = msg_type; - if((msg->msg = HDstrdup(msg_str))==NULL) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + if((msg->msg = H5MM_xstrdup(msg_str))==NULL) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Set return value */ ret_value = msg; @@ -805,10 +815,10 @@ H5Eget_major(H5E_major_t maj) /* Get the message's text */ if((size = H5E_get_msg(msg, &type, NULL, (size_t)0)) < 0) - HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "can't get error message text"); + HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "can't get error message text") if(type != H5E_MAJOR) - HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "Error message isn't a major one"); + HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "Error message isn't a major one") /* Don't know who is going to free it */ msg_str = (char*)H5MM_malloc((size_t)(++size)*sizeof(char)); @@ -855,10 +865,10 @@ H5Eget_minor(H5E_minor_t min) /* Get the message's text */ if((size = H5E_get_msg(msg, &type, NULL, (size_t)0)) < 0) - HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "can't get error message text"); + HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "can't get error message text") if(type != H5E_MINOR) - HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "Error message isn't a minor one"); + HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "Error message isn't a minor one") /* Don't know who is going to free it */ msg_str = (char*)H5MM_malloc((size_t)(++size)*sizeof(char)); @@ -1022,7 +1032,7 @@ H5E_get_current_stack(void) /* Allocate a new error stack */ if((estack_copy = H5FL_MALLOC(H5E_t))==NULL) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Make a copy of current error stack */ estack_copy->nused = current_stack->nused; @@ -1043,13 +1053,13 @@ H5E_get_current_stack(void) if(H5I_inc_ref(current_error->min_num)<0) HGOTO_ERROR(H5E_ERROR, H5E_CANTINC, NULL, "unable to increment ref count on error message") new_error->min_num = current_error->min_num; - if((new_error->func_name = HDstrdup(current_error->func_name))==NULL) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - if((new_error->file_name = HDstrdup(current_error->file_name))==NULL) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + if((new_error->func_name = H5MM_xstrdup(current_error->func_name))==NULL) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + if((new_error->file_name = H5MM_xstrdup(current_error->file_name))==NULL) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") new_error->line = current_error->line; - if((new_error->desc = HDstrdup(current_error->desc))==NULL) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + if((new_error->desc = H5MM_xstrdup(current_error->desc))==NULL) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") } /* end for */ /* Empty current error stack */ @@ -1157,13 +1167,13 @@ H5E_set_current_stack(H5E_t *estack) if(H5I_inc_ref(new_error->min_num)<0) HGOTO_ERROR(H5E_ERROR, H5E_CANTINC, FAIL, "unable to decrement ref count on error class") current_error->min_num = new_error->min_num; - if((current_error->func_name = HDstrdup(new_error->func_name))==NULL) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - if((current_error->file_name = HDstrdup(new_error->file_name))==NULL) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + if((current_error->func_name = H5MM_xstrdup(new_error->func_name))==NULL) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + if((current_error->file_name = H5MM_xstrdup(new_error->file_name))==NULL) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") current_error->line = new_error->line; - if((current_error->desc = HDstrdup(new_error->desc))==NULL) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + if((current_error->desc = H5MM_xstrdup(new_error->desc))==NULL) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") } /* end for */ done: @@ -1521,12 +1531,12 @@ H5Epush_stack(hid_t err_stack, const char *file, const char *func, unsigned line #ifdef H5_HAVE_VASPRINTF /* Use the vasprintf() routine, since it does what we're trying to do below */ if(HDvasprintf(&tmp,fmt,ap)<0) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") #else /* H5_HAVE_VASPRINTF */ /* Allocate space for the formatted description buffer */ tmp_len=128; if((tmp=H5MM_malloc((size_t)tmp_len))==NULL) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* If the description doesn't fit into the initial buffer size, allocate more space and try again */ while((desc_len=HDvsnprintf(tmp, (size_t)tmp_len, fmt, ap)) @@ -1554,7 +1564,7 @@ H5Epush_stack(hid_t err_stack, const char *file, const char *func, unsigned line tmp_len = 2 * tmp_len; #endif /* H5_VSNPRINTF_WORKS */ if((tmp=H5MM_malloc((size_t)tmp_len))==NULL) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") } /* end while */ #endif /* H5_HAVE_VASPRINTF */ @@ -1649,12 +1659,12 @@ H5E_push_stack(H5E_t *estack, const char *file, const char *func, unsigned line, if(H5I_inc_ref(min_id)<0) HGOTO_DONE(FAIL) estack->slot[estack->nused].min_num = min_id; - if((estack->slot[estack->nused].func_name = HDstrdup(func))==NULL) + if((estack->slot[estack->nused].func_name = H5MM_xstrdup(func))==NULL) HGOTO_DONE(FAIL) - if((estack->slot[estack->nused].file_name = HDstrdup(file))==NULL) + if((estack->slot[estack->nused].file_name = H5MM_xstrdup(file))==NULL) HGOTO_DONE(FAIL) estack->slot[estack->nused].line = line; - if((estack->slot[estack->nused].desc = HDstrdup(desc))==NULL) + if((estack->slot[estack->nused].desc = H5MM_xstrdup(desc))==NULL) HGOTO_DONE(FAIL) estack->nused++; } @@ -1785,11 +1795,11 @@ H5E_clear_entries(H5E_t *estack, size_t nentries) /* Release strings */ if(error->func_name) - H5MM_xfree((void*)error->func_name); + H5MM_xfree((void*)error->func_name); /* Casting away const OK - QAK */ if(error->file_name) - H5MM_xfree((void*)error->file_name); + H5MM_xfree((void*)error->file_name); /* Casting away const OK - QAK */ if(error->desc) - H5MM_xfree((void*)error->desc); + H5MM_xfree((void*)error->desc); /* Casting away const OK - QAK */ } /* end for */ /* Decrement number of errors on stack */ @@ -2152,54 +2162,48 @@ H5E_walk_stack(const H5E_t *estack, H5E_direction_t direction, H5E_walk_t func, if(bk_compatible && func) { H5E_error_t old_err; - status=SUCCEED; - if (H5E_WALK_UPWARD==direction) { - for (i=0; i<(int)estack->nused && status>=0; i++) { + status = SUCCEED; + if(H5E_WALK_UPWARD == direction) { + for(i = 0; i < (int)estack->nused && status >= 0; i++) { /*Copy each error record on the stack and pass it to callback function.*/ old_err.maj_num = estack->slot[i].maj_num; old_err.min_num = estack->slot[i].min_num; - old_err.func_name = HDstrdup(estack->slot[i].func_name); - old_err.file_name = HDstrdup(estack->slot[i].file_name); - old_err.desc = HDstrdup(estack->slot[i].desc); + old_err.func_name = estack->slot[i].func_name; + old_err.file_name = estack->slot[i].file_name; + old_err.desc = estack->slot[i].desc; old_err.line = estack->slot[i].line; status = (func)((unsigned)i, &old_err, client_data); - - HDfree(old_err.func_name); - HDfree(old_err.file_name); - HDfree(old_err.desc); - } - } else { - H5_CHECK_OVERFLOW(estack->nused-1,size_t,int); - for (i=(int)(estack->nused-1); i>=0 && status>=0; i--) { + } /* end for */ + } /* end if */ + else { + H5_CHECK_OVERFLOW(estack->nused - 1, size_t, int); + for(i = (int)(estack->nused - 1); i >= 0 && status >= 0; i--) { /*Copy each error record on the stack and pass it to callback function.*/ old_err.maj_num = estack->slot[i].maj_num; old_err.min_num = estack->slot[i].min_num; - old_err.func_name = HDstrdup(estack->slot[i].func_name); - old_err.file_name = HDstrdup(estack->slot[i].file_name); - old_err.desc = HDstrdup(estack->slot[i].desc); + old_err.func_name = estack->slot[i].func_name; + old_err.file_name = estack->slot[i].file_name; + old_err.desc = estack->slot[i].desc; old_err.line = estack->slot[i].line; - status = (func)((unsigned)(estack->nused-(size_t)(i+1)), &old_err, client_data); - - HDfree(old_err.func_name); - HDfree(old_err.file_name); - HDfree(old_err.desc); - } - } + status = (func)((unsigned)(estack->nused - (size_t)(i + 1)), &old_err, client_data); + } /* end for */ + } /* end else */ if(status<0) HGOTO_ERROR(H5E_ERROR, H5E_CANTLIST, FAIL, "can't walk error stack") } else if(!bk_compatible && stack_func) { - status=SUCCEED; - if (H5E_WALK_UPWARD==direction) { - for (i=0; i<(int)estack->nused && status>=0; i++) + status = SUCCEED; + if(H5E_WALK_UPWARD == direction) { + for(i = 0; i < (int)estack->nused && status >= 0; i++) status = (stack_func)((unsigned)i, estack->slot+i, client_data); - } else { - H5_CHECK_OVERFLOW(estack->nused-1,size_t,int); - for (i=(int)(estack->nused-1); i>=0 && status>=0; i--) + } /* end if */ + else { + H5_CHECK_OVERFLOW(estack->nused - 1, size_t, int); + for(i = (int)(estack->nused - 1); i >= 0 && status >= 0; i--) status = (stack_func)((unsigned)(estack->nused-(size_t)(i+1)), estack->slot+i, client_data); - } + } /* end else */ if(status<0) HGOTO_ERROR(H5E_ERROR, H5E_CANTLIST, FAIL, "can't walk error stack") @@ -2452,30 +2456,31 @@ H5E_walk_cb(unsigned n, const H5E_error_t *err_desc, void *client_data) * Programmer: Raymond Lu * Sep 16, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ herr_t H5Eget_auto(H5E_auto_t *func, void **client_data) { H5E_t *estack; /* Error stack to operate on */ - herr_t ret_value=SUCCEED; /* Return value */ + H5E_auto_op_t f; /* Error stack function */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(H5Eget_auto, FAIL) H5TRACE2("e","*xx",func,client_data); /* Retrieve default error stack */ - if((estack = H5E_get_my_stack())==NULL) /*lint !e506 !e774 Make lint 'constant value Boolean' in non-threaded case */ + if(NULL == (estack = H5E_get_my_stack())) /*lint !e506 !e774 Make lint 'constant value Boolean' in non-threaded case */ HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "can't get current error stack") /* Get the automatic error reporting information */ - if(H5E_get_auto_stack(estack, FALSE, (void **)func, client_data)<0) + if(H5E_get_auto_stack(estack, FALSE, &f, client_data) < 0) HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "can't get automatic error info") + if(func) + *func = f.efunc; done: FUNC_LEAVE_API(ret_value) -} +} /* end H5Eget_auto() */ /*------------------------------------------------------------------------- @@ -2491,38 +2496,35 @@ done: * Programmer: Robb Matzke * Saturday, February 28, 1998 * - * Modifications: - * Raymond Lu - * July 18, 2003 - * Added error stack in the parameters. It returns the - * traversal function and data for that error stack. - * *------------------------------------------------------------------------- */ herr_t H5Eget_auto_stack(hid_t estack_id, H5E_auto_stack_t *func, void **client_data) { H5E_t *estack; /* Error stack to operate on */ - herr_t ret_value=SUCCEED; /* Return value */ + H5E_auto_op_t f; /* Error stack function */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(H5Eget_auto_stack, FAIL) H5TRACE3("e","i*xx",estack_id,func,client_data); if(estack_id == H5E_DEFAULT) { - if((estack = H5E_get_my_stack())==NULL) /*lint !e506 !e774 Make lint 'constant value Boolean' in non-threaded case */ + if(NULL == (estack = H5E_get_my_stack())) /*lint !e506 !e774 Make lint 'constant value Boolean' in non-threaded case */ HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "can't get current error stack") } /* end if */ else - if((estack = H5I_object_verify(estack_id, H5I_ERROR_STACK))==NULL) + if(NULL == (estack = H5I_object_verify(estack_id, H5I_ERROR_STACK))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a error stack ID") /* Get the automatic error reporting information */ - if(H5E_get_auto_stack(estack, TRUE, (void **)func, client_data)<0) + if(H5E_get_auto_stack(estack, TRUE, &f, client_data) < 0) HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "can't get automatic error info") + if(func) + *func = f.stack_efunc; done: FUNC_LEAVE_API(ret_value) -} +} /* end H5Eget_auto_stack() */ /*------------------------------------------------------------------------- @@ -2538,25 +2540,27 @@ done: * Programmer: Raymond Lu * July 18, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t -H5E_get_auto_stack(const H5E_t *estack, hbool_t new_api, void * *func, void **client_data) +H5E_get_auto_stack(const H5E_t *estack, hbool_t new_api, H5E_auto_op_t *func, void **client_data) { FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5E_get_auto_stack) - assert (estack); + HDassert(estack); /* Retrieve the requested information */ - if(func) - *func = new_api ? (void *)estack->u.func_stack : (void *)estack->u.func; + if(func) { + if(new_api) + func->stack_efunc = estack->u.func_stack; + else + func->efunc = estack->u.func; + } /* end if */ if(client_data) *client_data = estack->auto_data; FUNC_LEAVE_NOAPI(SUCCEED) -} +} /* end H5E_get_auto_stack() */ /*------------------------------------------------------------------------- @@ -2582,30 +2586,30 @@ H5E_get_auto_stack(const H5E_t *estack, hbool_t new_api, void * *func, void **cl * Programmer: Raymond Lu * Sep 16, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ herr_t H5Eset_auto(H5E_auto_t func, void *client_data) { H5E_t *estack; /* Error stack to operate on */ - herr_t ret_value=SUCCEED; /* Return value */ + H5E_auto_op_t f; /* Error stack function */ + herr_t ret_value = SUCCEED; /* Return value */ /* Don't clear the error stack! :-) */ FUNC_ENTER_API_NOCLEAR(H5Eset_auto, FAIL) H5TRACE2("e","xx",func,client_data); - if((estack = H5E_get_my_stack())==NULL) /*lint !e506 !e774 Make lint 'constant value Boolean' in non-threaded case */ + if(NULL == (estack = H5E_get_my_stack())) /*lint !e506 !e774 Make lint 'constant value Boolean' in non-threaded case */ HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "can't get current error stack") /* Set the automatic error reporting information */ - if(H5E_set_auto_stack(estack, FALSE, (void *)func, client_data)<0) + f.efunc = func; + if(H5E_set_auto_stack(estack, FALSE, &f, client_data) < 0) HGOTO_ERROR(H5E_ERROR, H5E_CANTSET, FAIL, "can't set automatic error info") done: FUNC_LEAVE_API(ret_value) -} +} /* end H5Eset_auto() */ /*------------------------------------------------------------------------- @@ -2630,35 +2634,35 @@ done: * Programmer: Robb Matzke * Friday, February 27, 1998 * - * Modifications: - * *------------------------------------------------------------------------- */ herr_t H5Eset_auto_stack(hid_t estack_id, H5E_auto_stack_t func, void *client_data) { H5E_t *estack; /* Error stack to operate on */ - herr_t ret_value=SUCCEED; /* Return value */ + H5E_auto_op_t f; /* Error stack function */ + herr_t ret_value = SUCCEED; /* Return value */ /* Don't clear the error stack! :-) */ FUNC_ENTER_API_NOCLEAR(H5Eset_auto_stack, FAIL) H5TRACE3("e","ixx",estack_id,func,client_data); if(estack_id == H5E_DEFAULT) { - if((estack = H5E_get_my_stack())==NULL) /*lint !e506 !e774 Make lint 'constant value Boolean' in non-threaded case */ + if(NULL == (estack = H5E_get_my_stack())) /*lint !e506 !e774 Make lint 'constant value Boolean' in non-threaded case */ HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "can't get current error stack") } /* end if */ else - if((estack = H5I_object_verify(estack_id, H5I_ERROR_STACK))==NULL) + if(NULL == (estack = H5I_object_verify(estack_id, H5I_ERROR_STACK))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a error stack ID") /* Set the automatic error reporting information */ - if(H5E_set_auto_stack(estack, TRUE, (void *)func, client_data)<0) + f.stack_efunc = func; + if(H5E_set_auto_stack(estack, TRUE, &f, client_data)<0) HGOTO_ERROR(H5E_ERROR, H5E_CANTSET, FAIL, "can't set automatic error info") done: FUNC_LEAVE_API(ret_value) -} +} /* end H5Eset_auto_stack() */ /*------------------------------------------------------------------------- @@ -2684,27 +2688,25 @@ done: * Programmer: Robb Matzke * Friday, February 27, 1998 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t -H5E_set_auto_stack(H5E_t *estack, hbool_t new_api, void *func, void *client_data) +H5E_set_auto_stack(H5E_t *estack, hbool_t new_api, H5E_auto_op_t *func, void *client_data) { FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5E_set_auto_stack) - assert(estack); + HDassert(estack); /* Set the automatic error reporting info */ estack->new_api = new_api; if(new_api) - estack->u.func_stack = (H5E_auto_stack_t)func; + estack->u.func_stack = func->stack_efunc; else - estack->u.func = (H5E_auto_t)func; + estack->u.func = func->efunc; estack->auto_data = client_data; FUNC_LEAVE_NOAPI(SUCCEED) -} +} /* end H5E_set_auto_stack() */ /*------------------------------------------------------------------------- diff --git a/src/H5Epublic.h b/src/H5Epublic.h index 8ba97c4..deb2541 100644 --- a/src/H5Epublic.h +++ b/src/H5Epublic.h @@ -39,12 +39,12 @@ typedef hid_t H5E_minor_t; /* Information about an error; element of error stack. For backward compatibility with v1.6. */ typedef struct H5E_error_t { - H5E_major_t maj_num; /*major error number */ - H5E_minor_t min_num; /*minor error number */ - const char *func_name; /*function in which error occurred */ - const char *file_name; /*file in which error occurred */ - unsigned line; /*line in file where error occurs */ - const char *desc; /*optional supplied description */ + H5E_major_t maj_num; /*major error number */ + H5E_minor_t min_num; /*minor error number */ + const char *func_name; /*function in which error occurred */ + const char *file_name; /*file in which error occurred */ + unsigned line; /*line in file where error occurs */ + const char *desc; /*optional supplied description */ } H5E_error_t; /* Information about an error; element of error stack */ diff --git a/src/H5FDcore.c b/src/H5FDcore.c index 713a3ff..cbbda53 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -405,7 +405,7 @@ H5FD_core_open(const char *name, unsigned UNUSED flags, hid_t fapl_id, HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate file struct") file->fd = fd; if (name && *name) - file->name = HDstrdup(name); + file->name = H5MM_xstrdup(name); /* * The increment comes from either the file access property list or the diff --git a/src/H5FDlog.c b/src/H5FDlog.c index 33a218a..7c2c3f2 100644 --- a/src/H5FDlog.c +++ b/src/H5FDlog.c @@ -430,7 +430,7 @@ H5FD_log_fapl_copy(const void *_old_fa) /* Deep copy the log file name */ if(old_fa->logfile!=NULL) - if (NULL==(new_fa->logfile=HDstrdup(old_fa->logfile))) + if (NULL==(new_fa->logfile=H5MM_xstrdup(old_fa->logfile))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate log file name") /* Set return value */ @@ -2836,7 +2836,7 @@ H5O_move_msgs_forward(H5O_t *oh) /* (We'll merge them together later, in another routine) */ if(H5O_NULL_ID != nonnull_msg->type->id) { /* Copy raw data for non-null message to new location */ - HDmemcpy(curr_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh), + HDmemmove(curr_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh), nonnull_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh), nonnull_msg->raw_size + H5O_SIZEOF_MSGHDR_OH(oh)); /* Adjust non-null message's offset in chunk */ @@ -2929,10 +2929,14 @@ H5O_move_msgs_forward(H5O_t *oh) null_msg->dirty = TRUE; /* Create new null message for previous location of non-null message */ - if(oh->nmesgs >= oh->alloc_nmesgs) + if(oh->nmesgs >= oh->alloc_nmesgs) { if(H5O_alloc_msgs(oh, (size_t)1) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate more space for messages") + /* "Retarget" 'curr_msg' pointer into newly re-allocated array of messages */ + curr_msg = &oh->mesg[u]; + } /* end if */ + /* Get message # for new null message */ new_null_msg = oh->nmesgs++; } /* end else */ @@ -3837,10 +3841,9 @@ H5O_add_gap(H5O_t *oh, unsigned chunkno, unsigned idx, H5O_mesg_t *null_msg; /* Pointer to new null message */ /* Check if we need to extend message table to hold the new null message */ - if(oh->nmesgs >= oh->alloc_nmesgs) { + if(oh->nmesgs >= oh->alloc_nmesgs) if(H5O_alloc_msgs(oh, (size_t)1) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, UFAIL, "can't allocate more space for messages") - } /* end if */ /* Increment new gap size */ oh->chunk[chunkno].gap += new_gap_size; diff --git a/src/H5Odtype.c b/src/H5Odtype.c index 73829c2..6314dfe 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -1361,7 +1361,7 @@ H5O_dtype_pre_copy_file(H5F_t *file_src, const H5O_msg_class_t UNUSED *type, /* If the user data is non-NULL, assume we are copying a dataset * and check if we need to make a copy of the datatype for later in * the object copying process. (We currently only need to make a copy - * of the datatype if it's a vlen datatype) + * of the datatype if it's a vlen or reference datatype) */ if(udata) { if((H5T_detect_class(dt_src, H5T_VLEN) > 0) || 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); -} @@ -5782,7 +5782,7 @@ H5P_open_class_path(const char *path) assert(path); /* Duplicate the path to use */ - tmp_path=HDstrdup(path); + tmp_path=H5MM_xstrdup(path); assert(tmp_path); /* Find the generic property class with this full path */ diff --git a/src/H5Pdcpl.c b/src/H5Pdcpl.c index b941908..51c20be 100644 --- a/src/H5Pdcpl.c +++ b/src/H5Pdcpl.c @@ -734,6 +734,82 @@ done: /*------------------------------------------------------------------------- + * Function: H5P_get_filter + * + * Purpose: Internal component of H5Pget_filter & H5Pget_filter_id + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Monday, October 23, 2006 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5P_get_filter(const H5Z_filter_info_t *filter, unsigned int *flags/*out*/, + size_t *cd_nelmts/*in_out*/, unsigned cd_values[]/*out*/, + size_t namelen, char name[]/*out*/, + unsigned *filter_config /*out*/) +{ + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5P_get_filter) + + /* Check arguments */ + HDassert(filter); + + /* Filter flags */ + if(flags) + *flags = filter->flags; + + /* Filter parameters */ + if(cd_values) { + size_t i; /* Local index variable */ + + for(i = 0; i < filter->cd_nelmts && i < *cd_nelmts; i++) + cd_values[i] = filter->cd_values[i]; + } /* end if */ + + /* Number of filter parameters */ + if(cd_nelmts) + *cd_nelmts = filter->cd_nelmts; + + /* Filter name */ + if(namelen > 0 && name) { + const char *s = filter->name; + + /* If there's no name on the filter, use the class's filter name */ + if(!s) { + H5Z_class_t *cls = H5Z_find(filter->id); + + if(cls) + s = cls->name; + } /* end if */ + + /* Check for actual name */ + if(s) { + HDstrncpy(name, s, namelen); + name[namelen] = '\0'; + } /* end if */ + else { + /* Check for unknown library filter */ + /* (probably from a future version of the library) */ + if(filter->id < 256) { + HDstrncpy(name, "Unknown library filter", namelen); + name[namelen] = '\0'; + } /* end if */ + else + name[0] = '\0'; + } /* end if */ + } /* end if */ + + /* Filter configuration (assume filter ID has already been checked) */ + if(filter_config) + H5Zget_filter_info(filter->id, filter_config); + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5P_get_filter() */ + + +/*------------------------------------------------------------------------- * Function: H5Pget_filter * * Purpose: This is the query counterpart of H5Pset_filter() and returns @@ -755,17 +831,6 @@ done: * Programmer: Robb Matzke * Wednesday, April 15, 1998 * - * Modifications: - * - * Raymond Lu - * Tuesday, October 2, 2001 - * Changed the way to check paramter and set property for - * generic property list. - * - * James Laird and Nat Furrer - * Tuesday, June 15, 2004 - * Function now retrieves filter_config flags. - * *------------------------------------------------------------------------- */ #ifdef H5_WANT_H5_V1_6_COMPAT @@ -778,97 +843,74 @@ H5Z_filter_t H5Pget_filter(hid_t plist_id, unsigned idx, unsigned int *flags/*out*/, size_t *cd_nelmts/*in_out*/, unsigned cd_values[]/*out*/, size_t namelen, char name[]/*out*/, - unsigned int *filter_config /*out*/) + unsigned *_filter_config /*out*/) #endif /* H5_WANT_H5_V1_6_COMPAT */ { H5O_pline_t pline; /* Filter pipeline */ - H5Z_filter_info_t *filter; /* Pointer to filter information */ + const H5Z_filter_info_t *filter; /* Pointer to filter information */ H5P_genplist_t *plist; /* Property list pointer */ - size_t i; /* Local index variable */ +#ifdef H5_WANT_H5_V1_6_COMPAT + unsigned *filter_config = NULL; /* Filter configuration */ +#else /* H5_WANT_H5_V1_6_COMPAT */ + unsigned *filter_config = _filter_config; /* Filter configuration */ +#endif /* H5_WANT_H5_V1_6_COMPAT */ H5Z_filter_t ret_value; /* return value */ - FUNC_ENTER_API(H5Pget_filter, H5Z_FILTER_ERROR); + FUNC_ENTER_API(H5Pget_filter, H5Z_FILTER_ERROR) #ifdef H5_WANT_H5_V1_6_COMPAT H5TRACE7("Zf","iIux*zxzx",plist_id,idx,flags,cd_nelmts,cd_values,namelen, name); #else /* H5_WANT_H5_V1_6_COMPAT */ - H5TRACE7("Zf","iIux*zxzx",plist_id,idx,flags,cd_nelmts,cd_values,namelen, - name); + H5TRACE8("Zf","iIux*zxzx*Iu",plist_id,idx,flags,cd_nelmts,cd_values,namelen, + name,_filter_config); #endif /* H5_WANT_H5_V1_6_COMPAT */ /* Check args */ - if (cd_nelmts || cd_values) -{ - if (cd_nelmts && *cd_nelmts>256) - /* - * It's likely that users forget to initialize this on input, so - * we'll check that it has a reasonable value. The actual number - * is unimportant because the H5O layer will detect when a message - * is too large. - */ - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5Z_FILTER_ERROR, "probable uninitialized *cd_nelmts argument"); - if (cd_nelmts && *cd_nelmts>0 && !cd_values) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5Z_FILTER_ERROR, "client data values not supplied"); + if(cd_nelmts || cd_values) { + /* + * It's likely that users forget to initialize this on input, so + * we'll check that it has a reasonable value. The actual number + * is unimportant because the H5O layer will detect when a message + * is too large. + */ + if(cd_nelmts && *cd_nelmts > 256) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5Z_FILTER_ERROR, "probable uninitialized *cd_nelmts argument") + if(cd_nelmts && *cd_nelmts > 0 && !cd_values) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5Z_FILTER_ERROR, "client data values not supplied") /* * If cd_nelmts is null but cd_values is non-null then just ignore * cd_values */ - if (!cd_nelmts) + if(!cd_nelmts) cd_values = NULL; - } + } /* end if */ /* Get the plist structure */ - if(NULL == (plist = H5P_object_verify(plist_id,H5P_DATASET_CREATE))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, H5Z_FILTER_ERROR, "can't find object for ID"); + if(NULL == (plist = H5P_object_verify(plist_id, H5P_DATASET_CREATE))) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, H5Z_FILTER_ERROR, "can't find object for ID") /* Get pipeline info */ if(H5P_get(plist, H5D_CRT_DATA_PIPELINE_NAME, &pline) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5Z_FILTER_ERROR, "can't get pipeline"); + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5Z_FILTER_ERROR, "can't get pipeline") /* Check more args */ - if (idx>=pline.nused) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5Z_FILTER_ERROR, "filter number is invalid"); + if(idx >= pline.nused) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5Z_FILTER_ERROR, "filter number is invalid") /* Set pointer to particular filter to query */ - filter=&pline.filter[idx]; - - if (flags) - *flags = filter->flags; - if (cd_values) { - for (i=0; i<filter->cd_nelmts && i<*cd_nelmts; i++) - cd_values[i] = filter->cd_values[i]; - } - if (cd_nelmts) - *cd_nelmts = filter->cd_nelmts; - - if (namelen>0 && name) { - const char *s = filter->name; - - if (!s) { - H5Z_class_t *cls = H5Z_find(filter->id); - - if (cls) - s = cls->name; - } - if (s) - HDstrncpy(name, s, namelen); - else - name[0] = '\0'; - } + filter = &pline.filter[idx]; -#ifndef H5_WANT_H5_V1_6_COMPAT - /* Get filter configuration, assume filter ID has already been checked */ - if(filter_config != NULL) - H5Zget_filter_info(filter->id, filter_config); -#endif + /* Get filter information */ + if(H5P_get_filter(filter, flags, cd_nelmts, cd_values, namelen, name, filter_config) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5Z_FILTER_ERROR, "can't get filter info") /* Set return value */ - ret_value=filter->id; + ret_value = filter->id; done: - FUNC_LEAVE_API(ret_value); -} + FUNC_LEAVE_API(ret_value) +} /* end H5Pget_filter() */ /*------------------------------------------------------------------------- @@ -891,106 +933,78 @@ done: * Programmer: Quincey Koziol * Friday, April 5, 2003 * - * Modifications: - * James Laird and Nat Furrer - * Tuesday, June 15, 2004 - * Function now retrieves filter_config flags. - * *------------------------------------------------------------------------- */ #ifdef H5_WANT_H5_V1_6_COMPAT herr_t H5Pget_filter_by_id(hid_t plist_id, H5Z_filter_t id, unsigned int *flags/*out*/, - size_t *cd_nelmts/*in_out*/, unsigned cd_values[]/*out*/, - size_t namelen, char name[]/*out*/) + size_t *cd_nelmts/*in_out*/, unsigned cd_values[]/*out*/, + size_t namelen, char name[]/*out*/) #else herr_t H5Pget_filter_by_id(hid_t plist_id, H5Z_filter_t id, unsigned int *flags/*out*/, - size_t *cd_nelmts/*in_out*/, unsigned cd_values[]/*out*/, - size_t namelen, char name[]/*out*/, unsigned int *filter_config) + size_t *cd_nelmts/*in_out*/, unsigned cd_values[]/*out*/, + size_t namelen, char name[]/*out*/, unsigned *_filter_config) #endif /* H5_WANT_H5_V1_6_COMPAT */ { H5O_pline_t pline; /* Filter pipeline */ H5Z_filter_info_t *filter; /* Pointer to filter information */ H5P_genplist_t *plist; /* Property list pointer */ - size_t i; /* Local index variable */ - herr_t ret_value=SUCCEED; /* Return value */ +#ifdef H5_WANT_H5_V1_6_COMPAT + unsigned *filter_config = NULL; /* Filter configuration */ +#else /* H5_WANT_H5_V1_6_COMPAT */ + unsigned *filter_config = _filter_config; /* Filter configuration */ +#endif /* H5_WANT_H5_V1_6_COMPAT */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_API(H5Pget_filter_by_id, FAIL); + FUNC_ENTER_API(H5Pget_filter_by_id, FAIL) #ifdef H5_WANT_H5_V1_6_COMPAT H5TRACE7("e","iZfx*zxzx",plist_id,id,flags,cd_nelmts,cd_values,namelen, name); #else H5TRACE8("e","iZfx*zxzx*Iu",plist_id,id,flags,cd_nelmts,cd_values,namelen, - name,filter_config); + name,_filter_config); #endif /* H5_WANT_H5_V1_6_COMPAT */ /* Check args */ - if (cd_nelmts || cd_values) -{ - if (cd_nelmts && *cd_nelmts>256) - /* - * It's likely that users forget to initialize this on input, so - * we'll check that it has a reasonable value. The actual number - * is unimportant because the H5O layer will detect when a message - * is too large. - */ - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "probable uninitialized *cd_nelmts argument"); - if (cd_nelmts && *cd_nelmts>0 && !cd_values) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "client data values not supplied"); + if(cd_nelmts || cd_values) { + /* + * It's likely that users forget to initialize this on input, so + * we'll check that it has a reasonable value. The actual number + * is unimportant because the H5O layer will detect when a message + * is too large. + */ + if(cd_nelmts && *cd_nelmts>256) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "probable uninitialized *cd_nelmts argument") + if(cd_nelmts && *cd_nelmts>0 && !cd_values) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "client data values not supplied") /* * If cd_nelmts is null but cd_values is non-null then just ignore * cd_values */ - if (!cd_nelmts) + if(!cd_nelmts) cd_values = NULL; - } + } /* end if */ /* Get the plist structure */ - if(NULL == (plist = H5P_object_verify(plist_id,H5P_DATASET_CREATE))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID"); + if(NULL == (plist = H5P_object_verify(plist_id, H5P_DATASET_CREATE))) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Get pipeline info */ if(H5P_get(plist, H5D_CRT_DATA_PIPELINE_NAME, &pline) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get pipeline"); + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get pipeline") /* Get pointer to filter in pipeline */ - if ((filter=H5Z_filter_info(&pline,id))==NULL) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "filter ID is invalid"); + if(NULL == (filter = H5Z_filter_info(&pline, id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "filter ID is invalid") - /* Copy filter information into user's parameters */ - if (flags) - *flags = filter->flags; - if (cd_values) { - for (i=0; i<filter->cd_nelmts && i<*cd_nelmts; i++) - cd_values[i] = filter->cd_values[i]; - } - if (cd_nelmts) - *cd_nelmts = filter->cd_nelmts; - if (namelen>0 && name) { - const char *s = filter->name; - - if (!s) { - H5Z_class_t *cls = H5Z_find(filter->id); - - if (cls) - s = cls->name; - } - if (s) - HDstrncpy(name, s, namelen); - else - name[0] = '\0'; - } - -#ifndef H5_WANT_H5_V1_6_COMPAT - /* Get filter configuration, assume filter ID has already been checked */ - if(filter_config != NULL) - H5Zget_filter_info(id, filter_config); -#endif + /* Get filter information */ + if(H5P_get_filter(filter, flags, cd_nelmts, cd_values, namelen, name, filter_config) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5Z_FILTER_ERROR, "can't get filter info") done: - FUNC_LEAVE_API(ret_value); + FUNC_LEAVE_API(ret_value) } /* end H5Pget_filter_by_id() */ @@ -1016,29 +1030,78 @@ H5Pall_filters_avail(hid_t plist_id) { H5O_pline_t pline; /* Filter pipeline */ H5P_genplist_t *plist; /* Property list pointer */ - hbool_t ret_value=TRUE; /* return value */ + hbool_t ret_value = TRUE; /* return value */ - FUNC_ENTER_API(H5Pall_filters_avail, UFAIL); + FUNC_ENTER_API(H5Pall_filters_avail, UFAIL) H5TRACE1("t","i",plist_id); /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(plist_id,H5P_DATASET_CREATE))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, UFAIL, "can't find object for ID"); + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, UFAIL, "can't find object for ID") /* Get pipeline info */ if(H5P_get(plist, H5D_CRT_DATA_PIPELINE_NAME, &pline) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, UFAIL, "can't get pipeline"); + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, UFAIL, "can't get pipeline") /* Set return value */ - if((ret_value=H5Z_all_filters_avail(&pline))==UFAIL) - HGOTO_ERROR(H5E_PLIST, H5E_NOTFOUND, UFAIL, "can't check pipeline information"); + if(UFAIL == (ret_value = H5Z_all_filters_avail(&pline))) + HGOTO_ERROR(H5E_PLIST, H5E_NOTFOUND, UFAIL, "can't check pipeline information") done: - FUNC_LEAVE_API(ret_value); + FUNC_LEAVE_API(ret_value) } /* end H5Pall_filters_avail() */ /*------------------------------------------------------------------------- + * Function: H5Premove_filter + * + * Purpose: Deletes a filter from the dataset creation property list; + * deletes all filters if FILTER is H5Z_FILTER_NONE + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Pedro Vicente + * January 26, 2004 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5Premove_filter(hid_t plist_id, H5Z_filter_t filter) +{ + H5P_genplist_t *plist; /* Property list pointer */ + H5O_pline_t pline; /* Filter pipeline */ + herr_t ret_value = SUCCEED; /* return value */ + + FUNC_ENTER_API(H5Premove_filter, FAIL) + H5TRACE2("e","iZf",plist_id,filter); + + /* Get the property list structure */ + if(NULL == (plist = H5P_object_verify(plist_id,H5P_DATASET_CREATE))) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") + + /* Get pipeline info */ + if(H5P_get(plist, H5D_CRT_DATA_PIPELINE_NAME, &pline) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5Z_FILTER_ERROR, "can't get pipeline") + + /* Check if there are any filters */ + if (pline.filter) { + /* Delete filter */ + if(H5Z_delete(&pline, filter) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5Z_FILTER_ERROR, "can't delete filter") + + /* Put the I/O pipeline information back into the property list */ + if(H5P_set(plist, H5D_CRT_DATA_PIPELINE_NAME, &pline) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set pipeline") + } /* end if */ + +done: + FUNC_LEAVE_API(ret_value); +} /* end H5Premove_filter() */ + + +/*------------------------------------------------------------------------- * Function: H5Pset_deflate * * Purpose: Sets the compression method for a permanent or transient @@ -1070,27 +1133,27 @@ H5Pset_deflate(hid_t plist_id, unsigned level) H5P_genplist_t *plist; /* Property list pointer */ herr_t ret_value=SUCCEED; /* return value */ - FUNC_ENTER_API(H5Pset_deflate, FAIL); + FUNC_ENTER_API(H5Pset_deflate, FAIL) H5TRACE2("e","iIu",plist_id,level); /* Check arguments */ - if (level>9) - HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid deflate level"); + if(level>9) + HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid deflate level") /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(plist_id,H5P_DATASET_CREATE))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID"); + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Add the filter */ if(H5P_get(plist, H5D_CRT_DATA_PIPELINE_NAME, &pline) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get pipeline"); + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get pipeline") if(H5Z_append(&pline, H5Z_FILTER_DEFLATE, H5Z_FLAG_OPTIONAL, (size_t)1, &level) < 0) - HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to add deflate filter to pipeline"); + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to add deflate filter to pipeline") if(H5P_set(plist, H5D_CRT_DATA_PIPELINE_NAME, &pline) < 0) - HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to set pipeline"); + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to set pipeline") done: - FUNC_LEAVE_API(ret_value); + FUNC_LEAVE_API(ret_value) } /* end H5Pset_deflate() */ @@ -1805,6 +1868,7 @@ done: FUNC_LEAVE_API(ret_value); } + /*------------------------------------------------------------------------- * Function: H5Pget_fill_time * @@ -1842,51 +1906,3 @@ done: FUNC_LEAVE_API(ret_value); } -/*------------------------------------------------------------------------- - * Function: H5Premove_filter - * - * Purpose: Deletes a filter from the dataset creation property list; - * deletes all filters if FILTER is H5Z_FILTER_NONE - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Pedro Vicente - * January 26, 2004 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ - -herr_t -H5Premove_filter(hid_t plist_id, H5Z_filter_t filter) -{ - H5P_genplist_t *plist; /* Property list pointer */ - H5O_pline_t pline; /* Filter pipeline */ - herr_t ret_value = SUCCEED; /* return value */ - - FUNC_ENTER_API(H5Premove_filter, FAIL) - H5TRACE2("e","iZf",plist_id,filter); - - /* Get the property list structure */ - if(NULL == (plist = H5P_object_verify(plist_id,H5P_DATASET_CREATE))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") - - /* Get pipeline info */ - if(H5P_get(plist, H5D_CRT_DATA_PIPELINE_NAME, &pline) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5Z_FILTER_ERROR, "can't get pipeline") - - /* Check if there are any filters */ - if (pline.filter) { - /* Delete filter */ - if(H5Z_delete(&pline, filter) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5Z_FILTER_ERROR, "can't delete filter") - - /* Put the I/O pipeline information back into the property list */ - if(H5P_set(plist, H5D_CRT_DATA_PIPELINE_NAME, &pline) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set pipeline") - } /* end if */ - -done: - FUNC_LEAVE_API(ret_value); -} diff --git a/src/H5Pdxpl.c b/src/H5Pdxpl.c index a9642ef..2a9b919 100644 --- a/src/H5Pdxpl.c +++ b/src/H5Pdxpl.c @@ -60,7 +60,7 @@ herr_t H5Pset_data_transform(hid_t plist_id, const char* expression) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID"); /* Create data transform info from expression */ - if((data_xform_prop=H5Z_xform_create(expression))==NULL) + 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 */ diff --git a/src/H5Ppublic.h b/src/H5Ppublic.h index c24b9d9..9681c55 100644 --- a/src/H5Ppublic.h +++ b/src/H5Ppublic.h @@ -288,7 +288,7 @@ H5_DLL H5Z_filter_t H5Pget_filter(hid_t plist_id, unsigned filter, size_t *cd_nelmts/*out*/, unsigned cd_values[]/*out*/, size_t namelen, char name[], - unsigned int *filter_config /*out*/); + unsigned *filter_config /*out*/); #endif /* H5_WANT_H5_V1_6_COMPAT */ #ifdef H5_WANT_H5_V1_6_COMPAT H5_DLL H5Z_filter_t H5Pget_filter_by_id(hid_t plist_id, H5Z_filter_t id, @@ -302,7 +302,7 @@ H5_DLL H5Z_filter_t H5Pget_filter_by_id(hid_t plist_id, H5Z_filter_t id, size_t *cd_nelmts/*out*/, unsigned cd_values[]/*out*/, size_t namelen, char name[]/*out*/, - unsigned int *filter_config/*out*/); + unsigned *filter_config/*out*/); #endif /* H5_WANT_H5_V1_6_COMPAT */ H5_DLL htri_t H5Pall_filters_avail(hid_t plist_id); H5_DLL herr_t H5Premove_filter(hid_t plist_id, H5Z_filter_t filter); @@ -412,7 +412,7 @@ static H5T_t *H5T_decode(const unsigned char *buf); /* Define the code templates for opaque for the "GUTS" in the H5T_INIT_TYPE macro */ #define H5T_INIT_TYPE_OPAQ_CORE { \ H5T_INIT_TYPE_ALLOC_COMMON(H5T_OPAQUE) \ - dt->shared->u.opaque.tag = H5MM_strdup(""); \ + dt->shared->u.opaque.tag = H5MM_xstrdup(""); \ } /* Define the code templates for strings for the "GUTS" in the H5T_INIT_TYPE macro */ @@ -3260,7 +3260,7 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method) /* * Copy the tag name. */ - new_dt->shared->u.opaque.tag = HDstrdup(new_dt->shared->u.opaque.tag); + new_dt->shared->u.opaque.tag = H5MM_xstrdup(new_dt->shared->u.opaque.tag); break; case H5T_ARRAY: diff --git a/src/H5Tconv.c b/src/H5Tconv.c index a40287a..183a3ee 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -2315,7 +2315,7 @@ H5T_conv_enum_init(H5T_t *src, H5T_t *dst, H5T_cdata_t *cdata) { H5T_enum_struct_t *priv=NULL; /*private conversion data */ int n; /*src value cast as native int */ - int domain[2]; /*min and max source values */ + int domain[2] = {0, 0}; /*min and max source values */ int *map=NULL; /*map from src value to dst idx */ unsigned length; /*nelmts in map array */ unsigned i, j; /*counters */ diff --git a/src/H5Tnative.c b/src/H5Tnative.c index fb525dc..13dbae1 100644 --- a/src/H5Tnative.c +++ b/src/H5Tnative.c @@ -200,7 +200,7 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig if(H5T_IS_VL_STRING(dtype->shared)) { /* Update size, offset and compound alignment for parent. */ - if(H5T_cmp_offset(comp_size, offset, sizeof(char *), 1, H5T_POINTER_COMP_ALIGN_g, struct_align)<0) + if(H5T_cmp_offset(comp_size, offset, sizeof(char *), (size_t)1, H5T_POINTER_COMP_ALIGN_g, struct_align)<0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot compute compound offset") } else { /* Update size, offset and compound alignment for parent. */ @@ -249,7 +249,7 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig ref_size = sizeof(hdset_reg_ref_t); } - if(H5T_cmp_offset(comp_size, offset, ref_size, 1, align, struct_align)<0) + if(H5T_cmp_offset(comp_size, offset, ref_size, (size_t)1, align, struct_align)<0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot compute compound offset") } break; @@ -368,7 +368,7 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot get member value") HDmemcpy(memb_value, tmp_memb_value, H5T_get_size(super_type)); - if(H5Tconvert(super_type_id, nat_super_type_id, 1, memb_value, NULL, H5P_DEFAULT)<0) + if(H5Tconvert(super_type_id, nat_super_type_id, (size_t)1, memb_value, NULL, H5P_DEFAULT)<0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot get member value") if(H5T_enum_insert(new_type, memb_name, memb_value)<0) @@ -468,7 +468,7 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig vl_align = H5T_HVL_COMP_ALIGN_g; vl_size = sizeof(hvl_t); - if(H5T_cmp_offset(comp_size, offset, vl_size, 1, vl_align, struct_align)<0) + if(H5T_cmp_offset(comp_size, offset, vl_size, (size_t)1, vl_align, struct_align)<0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot compute compound offset") ret_value = new_type; @@ -660,7 +660,7 @@ H5T_get_native_integer(size_t prec, H5T_sign_t sign, H5T_direction_t direction, HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot copy type") /* compute size and offset of compound type member. */ - if(H5T_cmp_offset(comp_size, offset, native_size, 1, align, struct_align)<0) + if(H5T_cmp_offset(comp_size, offset, native_size, (size_t)1, align, struct_align)<0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot compute compound offset") done: @@ -810,7 +810,7 @@ H5T_get_native_float(size_t size, H5T_direction_t direction, size_t *struct_alig HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve float type") /* compute offset of compound type member. */ - if(H5T_cmp_offset(comp_size, offset, native_size, 1, align, struct_align)<0) + if(H5T_cmp_offset(comp_size, offset, native_size, (size_t)1, align, struct_align)<0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot compute compound offset") done: diff --git a/src/H5Zfletcher32.c b/src/H5Zfletcher32.c index 139a7ad..67976f6 100644 --- a/src/H5Zfletcher32.c +++ b/src/H5Zfletcher32.c @@ -112,7 +112,7 @@ H5Z_filter_fletcher32 (unsigned flags, size_t UNUSED cd_nelmts, const unsigned U * system. We'll check both the correct checksum and the wrong * checksum to be consistent with Release 1.6.2 and before. */ - HDmemcpy(c, &fletcher, 4); + HDmemcpy(c, &fletcher, (size_t)4); tmp = c[1]; c[1] = c[0]; @@ -122,7 +122,7 @@ H5Z_filter_fletcher32 (unsigned flags, size_t UNUSED cd_nelmts, const unsigned U c[3] = c[2]; c[2] = tmp; - HDmemcpy(&reversed_fletcher, c, 4); + HDmemcpy(&reversed_fletcher, c, (size_t)4); /* Verify computed checksum matches stored checksum */ if(stored_fletcher != fletcher && stored_fletcher != reversed_fletcher) diff --git a/src/H5Znbit.c b/src/H5Znbit.c index 96c71d9..8a29400 100644 --- a/src/H5Znbit.c +++ b/src/H5Znbit.c @@ -106,7 +106,7 @@ H5Z_class_t H5Z_NBIT[1] = {{ * parms_index: index of array parms used by compression/decompression functions */ static unsigned cd_values_index = 0; -static unsigned cd_values_actual_nparms = 0; +static size_t cd_values_actual_nparms = 0; static unsigned char need_not_compress = FALSE; static unsigned parms_index = 0; @@ -717,26 +717,26 @@ H5Z_set_local_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "datatype needs too many nbit parameters") /* Allocate memory space for cd_values[] */ - if(NULL==(cd_values = H5MM_malloc(cd_values_actual_nparms*sizeof(unsigned)))) + if(NULL == (cd_values = H5MM_malloc(cd_values_actual_nparms * sizeof(unsigned)))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for cd_values[]") /* Get the filter's current parameters */ #ifdef H5_WANT_H5_V1_6_COMPAT - if(H5Pget_filter_by_id(dcpl_id,H5Z_FILTER_NBIT,&flags,&cd_nelmts, cd_values,0,NULL)<0) + if(H5Pget_filter_by_id(dcpl_id, H5Z_FILTER_NBIT, &flags, &cd_nelmts, cd_values, (size_t)0, NULL) < 0) #else - if(H5Pget_filter_by_id(dcpl_id,H5Z_FILTER_NBIT,&flags,&cd_nelmts, cd_values,0,NULL,NULL)<0) + if(H5Pget_filter_by_id(dcpl_id, H5Z_FILTER_NBIT, &flags, &cd_nelmts, cd_values, (size_t)0, NULL, NULL) < 0) #endif HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "can't get nbit parameters") /* Get total number of elements in the chunk */ - if ((npoints=H5Sget_simple_extent_npoints(space_id))<0) + if((npoints = H5Sget_simple_extent_npoints(space_id)) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "unable to get number of points in the dataspace") /* Initialize index for cd_values array starting from the third entry */ cd_values_index = 2; /* Set "local" parameter for number of elements in the chunk */ - H5_ASSIGN_OVERFLOW(cd_values[cd_values_index++],npoints,hssize_t,unsigned); + H5_ASSIGN_OVERFLOW(cd_values[cd_values_index++], npoints, hssize_t, unsigned); /* Assume no need to compress now, will be changed to FALSE later if not */ need_not_compress = TRUE; @@ -745,35 +745,40 @@ H5Z_set_local_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id) switch(dtype_class) { case H5T_INTEGER: case H5T_FLOAT: - if(H5Z_set_parms_atomic(type_id, cd_values)==FAIL) + if(H5Z_set_parms_atomic(type_id, cd_values) < 0) HGOTO_ERROR(H5E_PLINE,H5E_BADTYPE,FAIL,"nbit cannot set parameters for datatype") break; + case H5T_ARRAY: - if(H5Z_set_parms_array(type_id, cd_values)==FAIL) + if(H5Z_set_parms_array(type_id, cd_values) < 0) HGOTO_ERROR(H5E_PLINE,H5E_BADTYPE,FAIL,"nbit cannot set parameters for datatype") break; + case H5T_COMPOUND: - if(H5Z_set_parms_compound(type_id, cd_values)==FAIL) + if(H5Z_set_parms_compound(type_id, cd_values) < 0) HGOTO_ERROR(H5E_PLINE,H5E_BADTYPE,FAIL,"nbit cannot set parameters for datatype") break; + default: /* no need to set parameters for other datatypes at top level */ break; } /* end switch */ /* Check if calculation of parameters matches with setting of parameters */ - assert(cd_values_actual_nparms==cd_values_index); + HDassert(cd_values_actual_nparms == cd_values_index); /* Finally set the first two entries of cd_values[] */ cd_values[0] = cd_values_actual_nparms; cd_values[1] = need_not_compress; /* Modify the filter's parameters for this dataset */ - if(H5Pmodify_filter(dcpl_id, H5Z_FILTER_NBIT, flags, cd_values_actual_nparms, cd_values)<0) + if(H5Pmodify_filter(dcpl_id, H5Z_FILTER_NBIT, flags, cd_values_actual_nparms, cd_values) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTSET, FAIL, "can't set local nbit parameters") done: - FUNC_LEAVE_NOAPI(ret_value) + if(cd_values) + H5MM_xfree(cd_values); + FUNC_LEAVE_NOAPI(ret_value) } /* end H5Z_set_local_nbit() */ diff --git a/src/H5Zscaleoffset.c b/src/H5Zscaleoffset.c index 20f0c6e..fe82e9c 100644 --- a/src/H5Zscaleoffset.c +++ b/src/H5Zscaleoffset.c @@ -45,7 +45,7 @@ static herr_t H5Z_scaleoffset_set_parms_fillval(hid_t dcpl_id, hid_t type_id, static herr_t H5Z_set_local_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id); static size_t H5Z_filter_scaleoffset(unsigned flags, size_t cd_nelmts, const unsigned cd_values[], size_t nbytes, size_t *buf_size, void **buf); -static void H5Z_scaleoffset_convert(void *buf, unsigned d_nelmts, unsigned dtype_size); +static void H5Z_scaleoffset_convert(void *buf, unsigned d_nelmts, size_t dtype_size); static unsigned H5Z_scaleoffset_log2(unsigned long_long num); static void H5Z_scaleoffset_precompress_i(void *data, unsigned d_nelmts, enum H5Z_scaleoffset_type type, unsigned filavail, const void *filval_buf, @@ -632,7 +632,7 @@ done: static enum H5Z_scaleoffset_type H5Z_scaleoffset_get_type(unsigned dtype_class, unsigned dtype_size, unsigned dtype_sign) { - enum H5Z_scaleoffset_type type; /* integer type */ + enum H5Z_scaleoffset_type type = t_bad; /* integer type */ enum H5Z_scaleoffset_type ret_value; /* return value */ FUNC_ENTER_NOAPI_NOINIT(H5Z_scaleoffset_get_type) @@ -1182,21 +1182,22 @@ done: /* change byte order of input buffer either from little-endian to big-endian * or from big-endian to little-endian 2/21/2005 */ -static void H5Z_scaleoffset_convert(void *buf, unsigned d_nelmts, unsigned dtype_size) +static void +H5Z_scaleoffset_convert(void *buf, unsigned d_nelmts, size_t dtype_size) { - unsigned i, j; - unsigned char *buffer, temp; - - if(dtype_size == 1) return; - - buffer = buf; - for(i = 0; i < d_nelmts * dtype_size; i += dtype_size) - for(j = 0; j < dtype_size/2; j++) { - /* swap pair of bytes */ - temp = buffer[i+j]; - buffer[i+j] = buffer[i+dtype_size-1-j]; - buffer[i+dtype_size-1-j] = temp; - } + if(dtype_size > 1) { + unsigned i, j; + unsigned char *buffer, temp; + + buffer = buf; + for(i = 0; i < d_nelmts * dtype_size; i += dtype_size) + for(j = 0; j < dtype_size/2; j++) { + /* swap pair of bytes */ + temp = buffer[i+j]; + buffer[i+j] = buffer[i+dtype_size-1-j]; + buffer[i+dtype_size-1-j] = temp; + } + } /* end if */ } /* Round a floating-point value to the nearest integer value 4/19/05 */ diff --git a/src/H5Ztrans.c b/src/H5Ztrans.c index 79e69b8..5883058 100644 --- a/src/H5Ztrans.c +++ b/src/H5Ztrans.c @@ -908,7 +908,7 @@ H5Z_xform_eval(H5Z_data_xform_t *data_xform_prop, void* array, size_t array_size FUNC_ENTER_NOAPI(H5Z_xform_eval, FAIL) - assert(data_xform_prop); + HDassert(data_xform_prop); tree=data_xform_prop->parse_root; @@ -965,29 +965,24 @@ H5Z_xform_eval(H5Z_data_xform_t *data_xform_prop, void* array, size_t array_size { for(i=0; i<data_xform_prop->dat_val_pointers->num_ptrs; i++) { - if( (data_xform_prop->dat_val_pointers->ptr_dat_val[i] = (void*)HDmalloc(array_size*H5Tget_size(array_type))) == NULL) + if( (data_xform_prop->dat_val_pointers->ptr_dat_val[i] = (void*)H5MM_malloc(array_size*H5Tget_size(array_type))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "Ran out of memory trying to allocate space for data in data transform") - HDmemcpy(data_xform_prop->dat_val_pointers->ptr_dat_val[i], array, array_size*H5Tget_size(array_type)); + HDmemcpy(data_xform_prop->dat_val_pointers->ptr_dat_val[i], array, array_size*H5Tget_size(array_type)); } } + if(H5Z_xform_eval_full(tree, array_size, array_type, &res) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "error while performing data transform") - else - { - HDmemcpy(array, res.value.dat_val, array_size*H5Tget_size(array_type)); + + HDmemcpy(array, res.value.dat_val, array_size * H5Tget_size(array_type)); - /* Free the temporary arrays we used */ - - if(data_xform_prop->dat_val_pointers->num_ptrs > 1) - { - for(i=0; i<data_xform_prop->dat_val_pointers->num_ptrs; i++) - HDfree(data_xform_prop->dat_val_pointers->ptr_dat_val[i]); - } - } + /* Free the temporary arrays we used */ + if(data_xform_prop->dat_val_pointers->num_ptrs > 1) + for(i=0; i<data_xform_prop->dat_val_pointers->num_ptrs; i++) + HDfree(data_xform_prop->dat_val_pointers->ptr_dat_val[i]); } - done: if(ret_value < 0) { @@ -1375,7 +1370,7 @@ H5Z_xform_create(const char *expr) if((data_xform_prop = H5MM_calloc(sizeof(H5Z_data_xform_t)))==NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate memory for data transform info") - if((data_xform_prop->dat_val_pointers = HDmalloc(sizeof(H5Z_datval_ptrs))) == NULL) + if((data_xform_prop->dat_val_pointers = H5MM_malloc(sizeof(H5Z_datval_ptrs))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate memory for data transform array storage") /* copy the user's string into the property */ @@ -1393,7 +1388,7 @@ H5Z_xform_create(const char *expr) * we don't need to allocate any space since no array will have to be * stored */ if(count > 0) - if((data_xform_prop->dat_val_pointers->ptr_dat_val = (void**) HDcalloc(count, sizeof(void**))) == NULL) + if((data_xform_prop->dat_val_pointers->ptr_dat_val = (void**) H5MM_calloc(count * sizeof(void**))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate memory for pointers in transform array") /* Initialize the num_ptrs field, which will be used to keep track of the number of copies @@ -1515,7 +1510,7 @@ H5Z_xform_copy(H5Z_data_xform_t **data_xform_prop) if((new_data_xform_prop->xform_exp = H5MM_xstrdup((*data_xform_prop)->xform_exp))==NULL) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate memory for data transform expression") - if((new_data_xform_prop->dat_val_pointers = HDmalloc(sizeof(H5Z_datval_ptrs))) == NULL) + if((new_data_xform_prop->dat_val_pointers = H5MM_malloc(sizeof(H5Z_datval_ptrs))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate memory for data transform array storage") /* Find the number of times "x" is used in this equation, and allocate room for storing that many points */ @@ -1526,7 +1521,7 @@ H5Z_xform_copy(H5Z_data_xform_t **data_xform_prop) } if(count > 0) - if((new_data_xform_prop->dat_val_pointers->ptr_dat_val = (void**) HDcalloc(count, sizeof(void**))) == NULL) + if((new_data_xform_prop->dat_val_pointers->ptr_dat_val = (void**) H5MM_calloc(count * sizeof(void**))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate memory for pointers in transform array") /* Zero out num_pointers prior to H5Z_xform_cop_tree call; that call will increment it to the right amount */ |