diff options
-rw-r--r-- | src/H5D.c | 148 | ||||
-rw-r--r-- | src/H5Dio.c | 67 | ||||
-rw-r--r-- | src/H5Dprivate.h | 12 | ||||
-rw-r--r-- | src/H5Pdxpl.c | 21 | ||||
-rw-r--r-- | src/H5Ppublic.h | 5 | ||||
-rw-r--r-- | src/H5Zprivate.h | 56 | ||||
-rw-r--r-- | src/H5Ztrans.c | 379 |
7 files changed, 395 insertions, 293 deletions
@@ -53,7 +53,6 @@ static herr_t H5D_extend(H5D_t *dataset, const hsize_t *size, hid_t dxpl_id); static herr_t H5D_set_extent(H5D_t *dataset, const hsize_t *size, hid_t dxpl_id); static herr_t H5D_close(H5D_t *dataset); -static herr_t H5D_xfer_xform_set(hid_t prop_id, const char* name, size_t size, void* value); static herr_t H5D_xfer_xform_del(hid_t prop_id, const char* name, size_t size, void* value); static herr_t H5D_xfer_xform_copy(const char* name, size_t size, void* value); static herr_t H5D_xfer_xform_close(const char* name, size_t size, void* value); @@ -158,7 +157,6 @@ H5D_init_interface(void) * - Default value for datatype conversion callback */ H5P_genclass_t *xfer_pclass; - void* def_xfer_xform = H5D_XFER_XFORM_DEF; size_t def_max_temp_buf = H5D_XFER_MAX_TEMP_BUF_DEF; void *def_tconv_buf = H5D_XFER_TCONV_BUF_DEF; void *def_bkgr_buf = H5D_XFER_BKGR_BUF_DEF; @@ -177,6 +175,7 @@ H5D_init_interface(void) H5Z_EDC_t enable_edc = H5D_XFER_EDC_DEF; H5Z_cb_t filter_cb = H5D_XFER_FILTER_CB_DEF; H5T_conv_cb_t conv_cb = H5D_XFER_CONV_CB_DEF; + void *def_xfer_xform = H5D_XFER_XFORM_DEF; /* Dataset creation property class variables. In sequence, they are, * - Creation property list class to modify @@ -221,10 +220,6 @@ H5D_init_interface(void) /* Assume that if there are properties in the class, they are the default ones */ if(nprops==0) { - /* Register the data transform property */ - if(H5P_register(xfer_pclass,H5D_XFER_XFORM,H5D_XFER_XFORM_SIZE,&def_xfer_xform,NULL,H5D_XFER_XFORM_SET,NULL,H5D_XFER_XFORM_DEL,H5D_XFER_XFORM_COPY,NULL,H5D_XFER_XFORM_CLOSE)<0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - /* Register the max. temp buffer size property */ if(H5P_register(xfer_pclass,H5D_XFER_MAX_TEMP_BUF_NAME,H5D_XFER_MAX_TEMP_BUF_SIZE,&def_max_temp_buf,NULL,NULL,NULL,NULL,NULL,NULL,NULL)<0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") @@ -290,6 +285,10 @@ H5D_init_interface(void) /* Register the type conversion callback property */ if(H5P_register(xfer_pclass,H5D_XFER_CONV_CB_NAME,H5D_XFER_CONV_CB_SIZE,&conv_cb,NULL,NULL,NULL,NULL,NULL,NULL,NULL)<0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") + + /* Register the data transform property */ + if(H5P_register(xfer_pclass,H5D_XFER_XFORM_NAME,H5D_XFER_XFORM_SIZE,&def_xfer_xform,NULL,NULL,NULL,H5D_XFER_XFORM_DEL,H5D_XFER_XFORM_COPY,NULL,H5D_XFER_XFORM_CLOSE)<0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") } /* end if */ /* Only register the default property list if it hasn't been created yet */ @@ -454,81 +453,7 @@ H5D_term_interface(void) FUNC_LEAVE_NOAPI(n) } - -/*------------------------------------------------------------------------- - * Function: H5D_xfer_xform_set - * - * Purpose: Callback for setting a data transform property. This generates - * the parse tree for the data transform, as well as saving the transform - * locally. - * - * Return: Success: SUCCEED, Failure: FAIL - * - * Programmer: Leon Arber, larber@uiuc.edu - * - * Date: April 9, 2004 - * - * Comments: private, calls H5Z_xform_parse and H5Z_xform_reduce_tree - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -static herr_t -H5D_xfer_xform_set(hid_t prop_id, const char UNUSED *name, size_t UNUSED size, void* value) -{ - H5P_genplist_t *new_plist; - void* parse_root; - H5Z_data_xform* data_xform_prop; - int exp_size; - herr_t ret_value=SUCCEED; - - exp_size = strlen(*(char**)value) + 1; - data_xform_prop = (H5Z_data_xform*) HDmalloc(sizeof(H5Z_data_xform)); - - FUNC_ENTER_NOAPI(H5D_xfer_xform_set, FAIL) - - /* Verify property list ID */ - if (NULL == (new_plist = H5I_object(prop_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data transform property list") - - if (value == NULL) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "cannot parse a null expression") - else - { -#ifdef H5Z_XFORM_DEBUG - printf("Adding a new dataset transfer prop. Parsing a new tree from %s\n",*(char**) value); -#endif - - /* copy the user's string into the property */ - data_xform_prop->xform_exp = HDmalloc(exp_size); - strncpy(data_xform_prop->xform_exp, *(char**)value, exp_size); - - - /* we generate the parse tree right here and store a poitner to its root in the property. */ - parse_root = H5Z_xform_parse(*(H5Z_node**)value); - H5Z_xform_reduce_tree((H5Z_node*)parse_root); - if(parse_root) - { - data_xform_prop->parse_root = parse_root; - HDmemcpy(value, &data_xform_prop, sizeof(void*)); - } - else - { - /* if we couldn't parse the user's string, we're not going to store it */ - data_xform_prop->parse_root = NULL; - free(data_xform_prop->xform_exp); - data_xform_prop->xform_exp = NULL; - free(data_xform_prop); - *(H5Z_data_xform**)value = NULL; - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "error parsing data transform expression") - } - } -done: - FUNC_LEAVE_NOAPI(ret_value) -} - - + /*------------------------------------------------------------------------- * Function: H5D_xfer_xform_del * @@ -541,7 +466,7 @@ done: * * Date: April 9, 2004 * - * Comments: Private function, calls private H5Z_xform_destroy_parse_tree + * Comments: Private function, calls private H5Z_xform_destroy * * Modifications: * @@ -550,29 +475,23 @@ done: static herr_t H5D_xfer_xform_del(hid_t UNUSED prop_id, const char UNUSED *name, size_t UNUSED size, void *value) { -#ifdef H5Z_XFORM_DEBUG - fprintf(stderr, "Freeing memory b/c of delete\n"); -#endif herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(H5D_xfer_xform_del, FAIL) assert(value); +#ifdef H5Z_XFORM_DEBUG + fprintf(stderr, "Freeing memory b/c of delete\n"); +#endif - - if( *(H5Z_data_xform**)value != NULL) - { - H5Z_xform_destroy_parse_tree(((*((H5Z_data_xform**)value)))->parse_root); - HDfree(((*((H5Z_data_xform**)value)))->xform_exp); - HDfree(*(H5Z_data_xform**)value); - *(H5Z_data_xform**)value = NULL; - } + if(H5Z_xform_destroy(*(H5Z_data_xform_t **)value)<0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTCLOSEOBJ, FAIL, "error closing the parse tree") done: FUNC_LEAVE_NOAPI(ret_value) - } + /*------------------------------------------------------------------------- * Function: H5D_xfer_xform_copy * @@ -595,31 +514,18 @@ done: static herr_t H5D_xfer_xform_copy(const char UNUSED *name, size_t UNUSED size, void *value) { - H5Z_node* new_tree; herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(H5D_xfer_xform_copy, FAIL) - /* this will involved generating a new parse tree by copying every single node in the old one */ - H5Z_data_xform* data_xform_prop; - data_xform_prop = (H5Z_data_xform*) HDmalloc(sizeof(H5Z_data_xform)); - - data_xform_prop->xform_exp = (char*) HDmalloc(strlen( ((*(H5Z_data_xform**)value))->xform_exp) + 1); - strcpy(data_xform_prop->xform_exp, ((*(H5Z_data_xform**)value))->xform_exp); - if( (new_tree = (H5Z_node*)H5Z_xform_copy_tree( ((*(H5Z_data_xform**)value))->parse_root)) == NULL) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "error copying the parse tree") - else - data_xform_prop->parse_root = new_tree; + if(H5Z_xform_copy((H5Z_data_xform_t **)value)<0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTCLOSEOBJ, FAIL, "error copying the data transform info") - *(H5Z_data_xform**)value = data_xform_prop; - done: -FUNC_LEAVE_NOAPI(ret_value) - - + FUNC_LEAVE_NOAPI(ret_value) } - + /*------------------------------------------------------------------------- * Function: H5D_xfer_xform_close * @@ -641,32 +547,22 @@ FUNC_LEAVE_NOAPI(ret_value) static herr_t H5D_xfer_xform_close(const char UNUSED *name, size_t UNUSED size, void *value) { -#ifdef H5Z_XFORM_DEBUG - fprintf(stderr, "Freeing memory b/c of close\n"); -#endif herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(H5D_xfer_xform_close, FAIL) assert(value); +#ifdef H5Z_XFORM_DEBUG + fprintf(stderr, "Freeing memory b/c of close\n"); +#endif - if( *(H5Z_data_xform**)value != NULL) - { - H5Z_xform_destroy_parse_tree(((*((H5Z_data_xform**)value)))->parse_root); - HDfree(((*((H5Z_data_xform**)value)))->xform_exp); - HDfree(*(H5Z_data_xform**)value); - *(H5Z_data_xform**)value = NULL; - } + if(H5Z_xform_destroy(*(H5Z_data_xform_t **)value)<0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTCLOSEOBJ, FAIL, "error closing the parse tree") - done: FUNC_LEAVE_NOAPI(ret_value) } - - - - /*------------------------------------------------------------------------- * Function: H5D_crt_copy diff --git a/src/H5Dio.c b/src/H5Dio.c index 48492b2..8fc2982 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -27,8 +27,6 @@ #include "H5Sprivate.h" /* Dataspace functions */ #include "H5TBprivate.h" /* Threaded, balanced, binary trees (TBBTs) */ #include "H5Vprivate.h" /* Vector and array functions */ -#include "H5Tpublic.h" -#include "H5Zprivate.h" /*#define H5D_DEBUG*/ @@ -44,7 +42,7 @@ /* Structure holding information about a chunk's selection for mapping */ typedef struct H5D_chunk_info_t { hsize_t index; /* "Index" of chunk in dataset (must be first for TBBT routines) */ - hsize_t chunk_points; /* Number of elements selected in chunk */ + size_t chunk_points; /* Number of elements selected in chunk */ H5S_t *fspace; /* Dataspace describing chunk & selection in it */ hssize_t coords[H5O_LAYOUT_NDIMS]; /* Coordinates of chunk in file dataset's dataspace */ H5S_t *mspace; /* Dataspace describing selection in memory corresponding to this chunk */ @@ -310,9 +308,6 @@ H5D_get_dxpl_cache_real(hid_t dxpl_id, H5D_dxpl_cache_t *cache) if (NULL == (dx_plist = H5I_object(dxpl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset transfer property list") - /* Get the data transform property */ - H5P_get(dx_plist, H5D_XFER_XFORM, &cache->data_xform_prop); - /* Get maximum temporary buffer size */ if(H5P_get(dx_plist, H5D_XFER_MAX_TEMP_BUF_NAME, &cache->max_temp_buf)<0) HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "Can't retrieve maximum temporary buffer size") @@ -355,6 +350,10 @@ H5D_get_dxpl_cache_real(hid_t dxpl_id, H5D_dxpl_cache_t *cache) if(H5P_get(dx_plist, H5D_XFER_FILTER_CB_NAME, &cache->filter_cb)<0) HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "Can't retrieve filter callback function") + /* Get the data transform property */ + if(H5P_get(dx_plist, H5D_XFER_XFORM_NAME, &cache->data_xform_prop)<0) + HGOTO_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "Can't retrieve data transform info") + done: FUNC_LEAVE_NOAPI(ret_value) } /* H5D_get_dxpl_cache_real() */ @@ -1069,20 +1068,15 @@ H5D_contig_read(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type, hsize_t smine_start; /*strip mine start loc */ hsize_t n, smine_nelmts; /*elements per strip */ herr_t ret_value = SUCCEED; /*return value */ - - hid_t array_type; FUNC_ENTER_NOAPI_NOINIT(H5D_contig_read) - /* Inits for data transforms, if needed */ - array_type = H5Z_xform_find_type(mem_type); - /* * If there is no type conversion then read directly into the * application's buffer. This saves at least one mem-to-mem copy. */ - if ( (dxpl_cache->data_xform_prop == NULL) && H5T_path_noop(tpath)) { + if ( H5Z_xform_noop(dxpl_cache->data_xform_prop) && H5T_path_noop(tpath)) { #ifdef H5S_DEBUG H5_timer_begin(&timer); #endif @@ -1221,13 +1215,10 @@ H5D_contig_read(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type, /* Added by LA to do data transforms */ - - if(dxpl_cache->data_xform_prop) - H5Z_xform_eval(dxpl_cache->data_xform_prop->parse_root, tconv_buf, smine_nelmts, array_type); - + if(!H5Z_xform_noop(dxpl_cache->data_xform_prop)) + H5Z_xform_eval(dxpl_cache->data_xform_prop, tconv_buf, smine_nelmts, mem_type); /* end of LA additions */ - /* * Scatter the data into memory. */ @@ -1318,20 +1309,14 @@ H5D_contig_write(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5 hsize_t n, smine_nelmts; /*elements per strip */ herr_t ret_value = SUCCEED; /*return value */ - hid_t array_type; - FUNC_ENTER_NOAPI_NOINIT(H5D_contig_write) - /*TODO: This should be the type of the destination file...not the memory source. Where do we get this? */ - /* Inits for the data transform, if needed */ - array_type = H5Z_xform_find_type(mem_type); - /* * If there is no type conversion then write directly from the * application's buffer. This saves at least one mem-to-mem copy. */ - if ( (dxpl_cache->data_xform_prop == NULL) && H5T_path_noop(tpath)) { + if ( H5Z_xform_noop(dxpl_cache->data_xform_prop) && H5T_path_noop(tpath)) { #ifdef H5S_DEBUG H5_timer_begin(&timer); #endif @@ -1473,10 +1458,11 @@ H5D_contig_write(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5 H5_timer_begin(&timer); #endif - /* LA additions for data transforms */ - if(dxpl_cache->data_xform_prop) - H5Z_xform_eval(dxpl_cache->data_xform_prop->parse_root, tconv_buf, smine_nelmts, array_type); + /* LA additions for data transforms */ + if(!H5Z_xform_noop(dxpl_cache->data_xform_prop)) + H5Z_xform_eval(dxpl_cache->data_xform_prop, tconv_buf, smine_nelmts, dataset->type); /* End of LA modifications */ + status = H5S_select_fscat(dataset->ent.file, &(dataset->layout), &dataset->dcpl_cache, (H5D_storage_t *)&(dataset->efl), file_space, &file_iter, smine_nelmts, dxpl_cache, dxpl_id, tconv_buf); @@ -1491,7 +1477,6 @@ H5D_contig_write(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5 } /* end for */ done: - /* Release selection iterators */ if(file_iter_init) { if(H5S_select_iter_release(&file_iter)<0) @@ -1568,7 +1553,6 @@ UNUSED uint8_t *bkg_buf = NULL; /*background buffer */ H5D_storage_t store; /*union of EFL and chunk pointer in file space */ herr_t ret_value = SUCCEED; /*return value */ - hid_t array_type; FUNC_ENTER_NOAPI_NOINIT(H5D_chunk_read) @@ -1576,13 +1560,11 @@ UNUSED if(H5D_create_chunk_map(dataset, mem_type, file_space, mem_space, &fm)<0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't build chunk mapping") - array_type = H5Z_xform_find_type(mem_type); - /* * If there is no type conversion then read directly into the * application's buffer. This saves at least one mem-to-mem copy. */ - if ( (dxpl_cache->data_xform_prop == NULL) && H5T_path_noop(tpath)) { + if ( H5Z_xform_noop(dxpl_cache->data_xform_prop) && H5T_path_noop(tpath)) { #ifdef H5S_DEBUG H5_timer_begin(&timer); #endif @@ -1753,12 +1735,9 @@ UNUSED HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "data type conversion failed") /* LA additions for data transforms */ - if(dxpl_cache->data_xform_prop) - H5Z_xform_eval(dxpl_cache->data_xform_prop->parse_root, tconv_buf, smine_nelmts, array_type); - + if(!H5Z_xform_noop(dxpl_cache->data_xform_prop)) + H5Z_xform_eval(dxpl_cache->data_xform_prop, tconv_buf, smine_nelmts, mem_type); - - /* * Scatter the data into memory. */ @@ -1877,12 +1856,9 @@ nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, uint8_t *bkg_buf = NULL; /*background buffer */ H5D_storage_t store; /*union of EFL and chunk pointer in file space */ herr_t ret_value = SUCCEED; /*return value */ - hid_t array_type; FUNC_ENTER_NOAPI_NOINIT(H5D_chunk_write) - array_type = H5Z_xform_find_type(mem_type); - #ifdef QAK { int mpi_rank; @@ -1909,7 +1885,7 @@ nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, * If there is no type conversion then write directly from the * application's buffer. This saves at least one mem-to-mem copy. */ - if ((dxpl_cache->data_xform_prop == NULL) && H5T_path_noop(tpath)) { + if ( H5Z_xform_noop(dxpl_cache->data_xform_prop) && H5T_path_noop(tpath)) { #ifdef H5S_DEBUG H5_timer_begin(&timer); #endif @@ -2103,12 +2079,9 @@ nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "data type conversion failed") /* LA additions for data transforms */ - if(dxpl_cache->data_xform_prop) - H5Z_xform_eval(dxpl_cache->data_xform_prop->parse_root, tconv_buf, smine_nelmts, array_type); - - + if(!H5Z_xform_noop(dxpl_cache->data_xform_prop)) + H5Z_xform_eval(dxpl_cache->data_xform_prop, tconv_buf, smine_nelmts, dataset->type); - /* * Scatter the data out to the file. */ @@ -2765,7 +2738,7 @@ H5D_create_chunk_file_map_hyper(const fm_map *fm) /* Get number of elements selected in chunk */ if((schunk_points=H5S_get_select_npoints(tmp_fchunk))<0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't get file selection # of elements") - H5_ASSIGN_OVERFLOW(new_chunk_info->chunk_points,schunk_points,hssize_t,hsize_t); + H5_ASSIGN_OVERFLOW(new_chunk_info->chunk_points,schunk_points,hssize_t,size_t); /* Decrement # of points left in file selection */ sel_points-=schunk_points; diff --git a/src/H5Dprivate.h b/src/H5Dprivate.h index 5489659..63532c8 100644 --- a/src/H5Dprivate.h +++ b/src/H5Dprivate.h @@ -24,6 +24,7 @@ /* Private headers needed by this file */ #include "H5FDprivate.h" /* File drivers */ #include "H5Oprivate.h" /* Object headers */ +#include "H5Zprivate.h" /* Data filters */ /* * Feature: Define H5D_DEBUG on the compiler command line if you want to @@ -75,13 +76,12 @@ /* ======== Data transfer properties ======== */ /* Definitions for data transform property */ -#define H5D_XFER_XFORM "data_transform" +#define H5D_XFER_XFORM_NAME "data_transform" #define H5D_XFER_XFORM_SIZE sizeof(void *) #define H5D_XFER_XFORM_DEF NULL -#define H5D_XFER_XFORM_SET H5D_xfer_xform_set -#define H5D_XFER_XFORM_DEL H5D_xfer_xform_del -#define H5D_XFER_XFORM_COPY H5D_xfer_xform_copy -#define H5D_XFER_XFORM_CLOSE H5D_xfer_xform_close +#define H5D_XFER_XFORM_DEL H5D_xfer_xform_del +#define H5D_XFER_XFORM_COPY H5D_xfer_xform_copy +#define H5D_XFER_XFORM_CLOSE H5D_xfer_xform_close /* Definitions for maximum temp buffer size property */ #define H5D_XFER_MAX_TEMP_BUF_NAME "max_temp_buf" @@ -180,7 +180,7 @@ typedef struct H5D_dxpl_cache_t { #endif /*H5_HAVE_PARALLEL*/ H5Z_EDC_t err_detect; /* Error detection info (H5D_XFER_EDC_NAME) */ H5Z_cb_t filter_cb; /* Filter callback function (H5D_XFER_FILTER_CB_NAME) */ - H5Z_data_xform* data_xform_prop; /* Data transform prop (H5D_XFER_XFORM) */ + H5Z_data_xform_t *data_xform_prop; /* Data transform prop (H5D_XFER_XFORM_NAME) */ } H5D_dxpl_cache_t; /* Typedef for cached dataset creation property list information */ diff --git a/src/H5Pdxpl.c b/src/H5Pdxpl.c index 36bf77e..94b115e 100644 --- a/src/H5Pdxpl.c +++ b/src/H5Pdxpl.c @@ -31,6 +31,7 @@ static int interface_initialize_g = 0; /* Static function prototypes */ + /*------------------------------------------------------------------------- * Function: H5Pset_data_transform * @@ -48,15 +49,14 @@ static int interface_initialize_g = 0; * *------------------------------------------------------------------------- */ -herr_t H5Pset_data_transform(hid_t plist_id, char* expression) +herr_t H5Pset_data_transform(hid_t plist_id, const char* expression) { H5P_genplist_t *plist; /* Property list pointer */ + H5Z_data_xform_t *data_xform_prop=NULL; /* New data xform property */ herr_t ret_value=SUCCEED; /* return value */ FUNC_ENTER_API(H5Pset_data_transform, FAIL); - /* H5TRACE4("e","izxx",plist_id,expression); */ - /* Check arguments */ if (expression == NULL) HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "expression cannot be NULL"); @@ -65,17 +65,24 @@ herr_t H5Pset_data_transform(hid_t plist_id, char* expression) if(NULL == (plist = H5P_object_verify(plist_id,H5P_DATASET_XFER))) 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) + HGOTO_ERROR (H5E_PLINE, H5E_NOSPACE, FAIL, "unable to create data transform info") + /* Update property list */ - if(H5P_set(plist, H5D_XFER_XFORM, &expression)<0) + if(H5P_set(plist, H5D_XFER_XFORM_NAME, &data_xform_prop)<0) HGOTO_ERROR (H5E_PLIST, H5E_CANTSET, FAIL, "Error setting data transform expression"); done: + if(ret_value<0) { + if(data_xform_prop) + if(H5Z_xform_destroy(data_xform_prop)<0) + HDONE_ERROR(H5E_PLINE, H5E_CLOSEERROR, FAIL, "unable to release data transform expression") + } /* end if */ + FUNC_LEAVE_API(ret_value); } - - - /*------------------------------------------------------------------------- * Function: H5Pset_buffer diff --git a/src/H5Ppublic.h b/src/H5Ppublic.h index 8368c84..4d1e027 100644 --- a/src/H5Ppublic.h +++ b/src/H5Ppublic.h @@ -27,9 +27,9 @@ #include "H5Ipublic.h" #include "H5Dpublic.h" #include "H5Fpublic.h" -#include "H5Tpublic.h" #include "H5FDpublic.h" #include "H5MMpublic.h" +#include "H5Tpublic.h" #include "H5Zpublic.h" /* Metroworks <sys/types.h> doesn't define off_t. */ @@ -197,7 +197,7 @@ H5_DLL herr_t H5Pset_layout(hid_t plist_id, H5D_layout_t layout); H5_DLL H5D_layout_t H5Pget_layout(hid_t plist_id); H5_DLL herr_t H5Pset_chunk(hid_t plist_id, int ndims, const hsize_t dim[]); H5_DLL int H5Pget_chunk(hid_t plist_id, int max_ndims, hsize_t dim[]/*out*/); -H5_DLL herr_t H5Pset_data_transform(hid_t plist_id, char* expression); +H5_DLL herr_t H5Pset_data_transform(hid_t plist_id, const char* expression); H5_DLL herr_t H5Pset_external(hid_t plist_id, const char *name, off_t offset, hsize_t size); H5_DLL int H5Pget_external_count(hid_t plist_id); @@ -218,7 +218,6 @@ H5_DLL herr_t H5Pset_family_offset(hid_t fapl_id, hsize_t offset); H5_DLL herr_t H5Pget_family_offset(hid_t fapl_id, hsize_t *offset); H5_DLL herr_t H5Pset_multi_type(hid_t fapl_id, H5FD_mem_t type); H5_DLL herr_t H5Pget_multi_type(hid_t fapl_id, H5FD_mem_t *type); - H5_DLL herr_t H5Pset_buffer(hid_t plist_id, size_t size, void *tconv, void *bkg); H5_DLL size_t H5Pget_buffer(hid_t plist_id, void **tconv/*out*/, diff --git a/src/H5Zprivate.h b/src/H5Zprivate.h index 48620be..33b7da9 100644 --- a/src/H5Zprivate.h +++ b/src/H5Zprivate.h @@ -19,12 +19,12 @@ #ifndef _H5Zprivate_H #define _H5Zprivate_H -#include "H5private.h" /* Generic Functions */ -#include "H5Tprivate.h" -#include "H5Eprivate.h" -#include "H5Iprivate.h" +/* Include package's public header */ #include "H5Zpublic.h" +/* Private headers needed by this file */ +#include "H5Tprivate.h" /* Datatypes */ + /* Structure to store information about each filter's parameters */ typedef struct { H5Z_filter_t id; /*filter identification number */ @@ -34,41 +34,6 @@ typedef struct { unsigned *cd_values; /*client data values */ } H5Z_filter_info_t; - -/* Token types */ -typedef enum { - ERROR, - H5Z_INTEGER, /* this represents an integer type in the data transform expression */ - H5Z_FLOAT, /* this represents a floating point type in the data transform expression */ - SYMBOL, - PLUS, - MINUS, - MULT, - DIVIDE, - LPAREN, - RPAREN, - END -} H5Z_token_type; - -typedef union { - char *sym_val; - long int_val; - double float_val; -} H5Z_num_val; - - -typedef struct H5Z_node { - struct H5Z_node *lchild; - struct H5Z_node *rchild; - H5Z_token_type type; - H5Z_num_val value; -} H5Z_node; - -typedef struct { - char* xform_exp; - H5Z_node* parse_root; -} H5Z_data_xform; - /* Special parameters for szip compression */ /* [These are aliases for the similar definitions in szlib.h, which we can't * include directly due to the duplication of various symbols with the zlib.h @@ -100,12 +65,11 @@ H5_DLL htri_t H5Z_all_filters_avail(const struct H5O_pline_t *pline); H5_DLL herr_t H5Z_delete(struct H5O_pline_t *pline, H5Z_filter_t filter); /* Data Transform Functions */ -H5_DLL void H5Z_xform_destroy_parse_tree(H5Z_node *tree); -H5_DLL void H5Z_xform_eval(H5Z_node *tree, void* array, hsize_t array_size, hid_t array_type); -H5_DLL void* H5Z_xform_parse(const char *expression); -H5_DLL hid_t H5Z_xform_find_type(H5T_t* type); -H5_DLL void H5Z_xform_reduce_tree(H5Z_node* tree); -H5_DLL void* H5Z_xform_copy_tree(H5Z_node* tree); - +typedef struct H5Z_data_xform_t H5Z_data_xform_t; /* Defined in H5Ztrans.c */ +H5_DLL H5Z_data_xform_t *H5Z_xform_create(const char *expr); +H5_DLL herr_t H5Z_xform_copy(H5Z_data_xform_t **data_xform_prop); +H5_DLL herr_t H5Z_xform_destroy(H5Z_data_xform_t *data_xform_prop); +H5_DLL void H5Z_xform_eval(const H5Z_data_xform_t *data_xform_prop, void* array, hsize_t array_size, const H5T_t *buf_type); +H5_DLL hbool_t H5Z_xform_noop(const H5Z_data_xform_t *data_xform_prop); #endif diff --git a/src/H5Ztrans.c b/src/H5Ztrans.c index 3aa4595..3d1ff41 100644 --- a/src/H5Ztrans.c +++ b/src/H5Ztrans.c @@ -12,7 +12,50 @@ * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "H5Zprivate.h" +#define H5Z_PACKAGE /*suppress error about including H5Zpkg */ + +/* Pablo information */ +/* (Put before include files to avoid problems with inline functions) */ +#define PABLO_MASK H5Z_deflate_mask + +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Iprivate.h" /* IDs */ +#include "H5MMprivate.h" /* Memory management */ +#include "H5Zpkg.h" /* Data filters */ + +/* Token types */ +typedef enum { + ERROR, + H5Z_INTEGER, /* this represents an integer type in the data transform expression */ + H5Z_FLOAT, /* this represents a floating point type in the data transform expression */ + SYMBOL, + PLUS, + MINUS, + MULT, + DIVIDE, + LPAREN, + RPAREN, + END +} H5Z_token_type; + +typedef union { + char *sym_val; + long int_val; + double float_val; +} H5Z_num_val; + +typedef struct H5Z_node { + struct H5Z_node *lchild; + struct H5Z_node *rchild; + H5Z_token_type type; + H5Z_num_val value; +} H5Z_node; + +struct H5Z_data_xform_t { + char* xform_exp; + struct H5Z_node* parse_root; +}; typedef struct result { H5Z_token_type type; @@ -36,22 +79,23 @@ typedef struct { const char *tok_last_end; /* The end of the last token */ } H5Z_token; - - - /* Interface initialization */ static int interface_initialize_g = 0; #define INTERFACE_INIT NULL +/* Local function prototypes */ static H5Z_token *H5Z_get_token(H5Z_token *current); static H5Z_node *H5Z_parse_expression(H5Z_token *current); static H5Z_node *H5Z_parse_term(H5Z_token *current); static H5Z_node *H5Z_parse_factor(H5Z_token *current); static H5Z_node *H5Z_new_node(H5Z_token_type type); static void H5Z_do_op(H5Z_node* tree); +static hid_t H5Z_xform_find_type(const H5T_t* type); static H5Z_result H5Z_eval_full(H5Z_node *tree, void* array, hsize_t array_size, hid_t array_type); - - +static void H5Z_xform_destroy_parse_tree(H5Z_node *tree); +static void* H5Z_xform_parse(const char *expression); +static void* H5Z_xform_copy_tree(H5Z_node* tree); +static void H5Z_xform_reduce_tree(H5Z_node* tree); #ifdef H5Z_XFORM_DEBUG static void H5Z_XFORM_DEBUG(H5Z_node *tree); static void H5Z_print(H5Z_node *tree, FILE *stream); @@ -78,6 +122,8 @@ static void H5Z_print(H5Z_node *tree, FILE *stream); * // H5Z_INTEGER is a C long int * // FLOAT is a C double */ + + /*------------------------------------------------------------------------- * Function: H5Z_unget_token * Purpose: Rollback the H5Z_token to the previous H5Z_token retrieved. There @@ -109,6 +155,7 @@ H5Z_unget_token(H5Z_token *current) } + /*------------------------------------------------------------------------- * Function: H5Z_get_token * Purpose: Determine what the next valid H5Z_token is in the expression @@ -246,6 +293,7 @@ done: } + /*------------------------------------------------------------------------- * Function: H5Z_xform_destroy_parse_tree * Purpose: Recursively destroys the expression tree. @@ -266,17 +314,18 @@ H5Z_xform_destroy_parse_tree(H5Z_node *tree) return; if (tree->type == SYMBOL) - HDfree(tree->value.sym_val); + H5MM_xfree(tree->value.sym_val); H5Z_xform_destroy_parse_tree(tree->lchild); H5Z_xform_destroy_parse_tree(tree->rchild); - HDfree(tree); + H5MM_xfree(tree); tree = NULL; FUNC_LEAVE_NOAPI_VOID } + /*------------------------------------------------------------------------- * Function: H5Z_parse * Purpose: Entry function for parsing the expression string. @@ -304,11 +353,14 @@ H5Z_xform_parse(const char *expression) tok.tok_expr = tok.tok_begin = tok.tok_end = expression; ret_value = (void*)H5Z_parse_expression(&tok); + + H5Z_xform_reduce_tree((H5Z_node*)ret_value); done: FUNC_LEAVE_NOAPI(ret_value) } + /*------------------------------------------------------------------------- * Function: H5Z_parse_expression * Purpose: Beginning of the recursive descent parser to parse the @@ -399,6 +451,7 @@ done: } + /*------------------------------------------------------------------------- * Function: H5Z_parse_term * Purpose: Parses a term in our expression language. A term is: @@ -486,6 +539,7 @@ done: } + /*------------------------------------------------------------------------- * Function: H5Z_parse_factor * Purpose: Parses a factor in our expression language. A factor is: @@ -539,9 +593,9 @@ H5Z_parse_factor(H5Z_token *current) if (!factor) HGOTO_DONE(factor) - factor->value.sym_val = HDcalloc(current->tok_end - current->tok_begin + 1, 1); + factor->value.sym_val = H5MM_calloc((size_t)(current->tok_end - current->tok_begin) + 1); HDstrncpy(factor->value.sym_val, current->tok_begin, - current->tok_end - current->tok_begin); + (size_t)(current->tok_end - current->tok_begin)); break; case LPAREN: factor = H5Z_parse_expression(current); @@ -634,6 +688,7 @@ done: FUNC_LEAVE_NOAPI(factor); } + /*------------------------------------------------------------------------- * Function: H5Z_new_node * Purpose: Create and initilize a new H5Z_node structure. @@ -654,7 +709,7 @@ H5Z_new_node(H5Z_token_type type) FUNC_ENTER_NOAPI(H5Z_new_node, NULL) - new_node = HDcalloc(1, sizeof(H5Z_node)); + new_node = H5MM_calloc(sizeof(H5Z_node)); if (new_node) new_node->type = type; @@ -667,6 +722,7 @@ done: } #ifdef H5Z_XFORM_DEBUG + /*------------------------------------------------------------------------- * Function: H5Z_XFORM_DEBUG * Purpose: Print out the expression in a nice format which displays @@ -700,6 +756,7 @@ H5Z_XFORM_DEBUG(H5Z_node *tree) printf("\n"); } + /*------------------------------------------------------------------------- * Function: H5Z_print * Purpose: Print out the expression in a nice format which displays @@ -746,14 +803,23 @@ H5Z_print(H5Z_node *tree, FILE *stream) #endif /* H5Z_XFORM_DEBUG */ -void H5Z_xform_eval(H5Z_node *tree, void* array, hsize_t array_size, hid_t array_type) + +void H5Z_xform_eval(const H5Z_data_xform_t *data_xform_prop, void* array, hsize_t array_size, const H5T_t *buf_type) { + H5Z_node *tree; + hid_t array_type; unsigned int i; int n; float f; FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5Z_xform_eval) + assert(data_xform_prop); + + tree=data_xform_prop->parse_root; + + /* Get the datatype ID for the buffer's type */ + array_type = H5Z_xform_find_type(buf_type); if( tree->type == H5Z_INTEGER) { @@ -798,6 +864,7 @@ void H5Z_xform_eval(H5Z_node *tree, void* array, hsize_t array_size, hid_t array + /*------------------------------------------------------------------------- * Function: H5Z_eval * Return: Nothing @@ -1187,17 +1254,14 @@ H5Z_eval_full(H5Z_node *tree, void* array, hsize_t array_size, hid_t array_type default: HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, ret_value, "Invalid expression tree") } - } done: - FUNC_LEAVE_NOAPI(res) - } - + /*------------------------------------------------------------------------- * Function: H5Z_find_type * Return: Native type of datatype that is passed in @@ -1207,11 +1271,11 @@ done: * *------------------------------------------------------------------------- */ -hid_t H5Z_xform_find_type(H5T_t* type) +static hid_t H5Z_xform_find_type(const H5T_t* type) { hid_t ret_value = SUCCEED; - FUNC_ENTER_NOAPI(H5Z_xform_find_type, FAIL); + FUNC_ENTER_NOAPI_NOINIT(H5Z_xform_find_type); assert(type); @@ -1289,6 +1353,7 @@ done: } + /*------------------------------------------------------------------------- * Function: H5Z_xform_copy_tree * Purpose: Makes a copy of the parse tree passed in. @@ -1310,7 +1375,7 @@ void* H5Z_xform_copy_tree(H5Z_node* tree) if(tree->type == H5Z_INTEGER) { - if ((ret_value = (H5Z_node*) HDmalloc(sizeof(H5Z_node))) == NULL) + if ((ret_value = (H5Z_node*) H5MM_malloc(sizeof(H5Z_node))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Ran out of memory trying to copy parse tree") else { @@ -1320,7 +1385,7 @@ void* H5Z_xform_copy_tree(H5Z_node* tree) } else if (tree->type == H5Z_FLOAT) { - if ((ret_value = (H5Z_node*) HDmalloc(sizeof(H5Z_node))) == NULL) + if ((ret_value = (H5Z_node*) H5MM_malloc(sizeof(H5Z_node))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Ran out of memory trying to copy parse tree") else { @@ -1330,12 +1395,12 @@ void* H5Z_xform_copy_tree(H5Z_node* tree) } else if(tree->type == SYMBOL) { - if ((ret_value = (H5Z_node*) HDmalloc(sizeof(H5Z_node))) == NULL) + if ((ret_value = (H5Z_node*) H5MM_malloc(sizeof(H5Z_node))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Ran out of memory trying to copy parse tree") else { ret_value -> type = SYMBOL; - if ((ret_value->value.sym_val = (char*) HDmalloc(strlen(tree->value.sym_val)+1)) == NULL) + if ((ret_value->value.sym_val = (char*) H5MM_malloc(strlen(tree->value.sym_val)+1)) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Ran out of memory trying to copy parse tree") else strcpy(ret_value ->value.sym_val, tree->value.sym_val); @@ -1343,7 +1408,7 @@ void* H5Z_xform_copy_tree(H5Z_node* tree) } else if(tree->type == MULT) { - if ((ret_value = (H5Z_node*) HDmalloc(sizeof(H5Z_node))) == NULL) + if ((ret_value = (H5Z_node*) H5MM_malloc(sizeof(H5Z_node))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Ran out of memory trying to copy parse tree") else { @@ -1354,7 +1419,7 @@ void* H5Z_xform_copy_tree(H5Z_node* tree) } else if(tree->type == PLUS) { - if ((ret_value = (H5Z_node*) HDmalloc(sizeof(H5Z_node))) == NULL) + if ((ret_value = (H5Z_node*) H5MM_malloc(sizeof(H5Z_node))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Ran out of memory trying to copy parse tree") else { @@ -1365,7 +1430,7 @@ void* H5Z_xform_copy_tree(H5Z_node* tree) } else if(tree->type == MINUS) { - if ((ret_value = (H5Z_node*) HDmalloc(sizeof(H5Z_node))) == NULL) + if ((ret_value = (H5Z_node*) H5MM_malloc(sizeof(H5Z_node))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Ran out of memory trying to copy parse tree") else { @@ -1376,7 +1441,7 @@ void* H5Z_xform_copy_tree(H5Z_node* tree) } else if(tree->type == DIVIDE) { - if ((ret_value = (H5Z_node*) HDmalloc(sizeof(H5Z_node))) == NULL) + if ((ret_value = (H5Z_node*) H5MM_malloc(sizeof(H5Z_node))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Ran out of memory trying to copy parse tree") else { @@ -1394,6 +1459,7 @@ void* H5Z_xform_copy_tree(H5Z_node* tree) FUNC_LEAVE_NOAPI(ret_value) } + /*------------------------------------------------------------------------- * Function: H5Z_xform_reduce_tree * Purpose: Simplifies parse tree passed in by performing any obvious @@ -1435,6 +1501,7 @@ done: FUNC_LEAVE_NOAPI_VOID; } + /*------------------------------------------------------------------------- * Function: H5Z_do_op * Purpose: If the root of the tree passed in points to a simple @@ -1461,8 +1528,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_INTEGER; tree->value.int_val = tree->lchild->value.int_val / tree->rchild->value.int_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1470,8 +1537,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_FLOAT; tree->value.float_val = tree->lchild->value.float_val / tree->rchild->value.float_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1479,8 +1546,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_FLOAT; tree->value.float_val = tree->lchild->value.float_val / tree->rchild->value.int_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1488,8 +1555,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_FLOAT; tree->value.float_val = tree->lchild->value.int_val / tree->rchild->value.float_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1503,8 +1570,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_INTEGER; tree->value.int_val = tree->lchild->value.int_val * tree->rchild->value.int_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1512,8 +1579,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_FLOAT; tree->value.float_val = tree->lchild->value.float_val * tree->rchild->value.float_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1521,8 +1588,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_FLOAT; tree->value.float_val = tree->lchild->value.float_val * tree->rchild->value.int_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1530,8 +1597,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_FLOAT; tree->value.float_val = tree->lchild->value.int_val * tree->rchild->value.float_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1545,8 +1612,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_INTEGER; tree->value.int_val = tree->lchild->value.int_val + tree->rchild->value.int_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1554,8 +1621,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_FLOAT; tree->value.float_val = tree->lchild->value.float_val + tree->rchild->value.float_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1563,8 +1630,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_FLOAT; tree->value.float_val = tree->lchild->value.float_val + tree->rchild->value.int_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1572,8 +1639,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_FLOAT; tree->value.float_val = tree->lchild->value.int_val + tree->rchild->value.float_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1587,8 +1654,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_INTEGER; tree->value.int_val = tree->lchild->value.int_val - tree->rchild->value.int_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1596,8 +1663,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_FLOAT; tree->value.float_val = tree->lchild->value.float_val - tree->rchild->value.float_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1605,8 +1672,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_FLOAT; tree->value.float_val = tree->lchild->value.float_val - tree->rchild->value.int_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1614,8 +1681,8 @@ static void H5Z_do_op(H5Z_node* tree) { tree->type = H5Z_FLOAT; tree->value.float_val = tree->lchild->value.int_val - tree->rchild->value.float_val; - HDfree(tree->lchild); - HDfree(tree->rchild); + H5MM_xfree(tree->lchild); + H5MM_xfree(tree->rchild); tree->lchild = NULL; tree->rchild = NULL; } @@ -1624,3 +1691,199 @@ static void H5Z_do_op(H5Z_node* tree) FUNC_LEAVE_NOAPI_VOID; } + + +/*------------------------------------------------------------------------- + * Function: H5D_xform_create + * + * Purpose: Create a new data transform object from a string. + * + * Return: + * Success: SUCCEED + * Failure: FAIL + * + * Programmer: Quincey Koziol, koziol@ncsa.uiuc.edu + * + * Date: May 4, 2004 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +H5Z_data_xform_t * +H5Z_xform_create(const char *expr) +{ + H5Z_data_xform_t *data_xform_prop=NULL; + H5Z_data_xform_t *ret_value; + + FUNC_ENTER_NOAPI(H5Z_xform_create, NULL) + + assert(expr); + + /* Allocate space for the data transform information */ + 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") + + /* copy the user's string into the property */ + if((data_xform_prop->xform_exp = H5MM_xstrdup(expr))==NULL) + HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate memory for data transform expression") + + /* we generate the parse tree right here and store a poitner to its root in the property. */ + if((data_xform_prop->parse_root = H5Z_xform_parse(expr))==NULL) + HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate memory for data transform parse tree") + + /* Assign return value */ + ret_value=data_xform_prop; + +done: + /* Clean up on error */ + if(ret_value==NULL) { + if(data_xform_prop) { + if(data_xform_prop->parse_root) + H5Z_xform_destroy_parse_tree(data_xform_prop->parse_root); + if(data_xform_prop->xform_exp) + H5MM_xfree(data_xform_prop->xform_exp); + H5MM_xfree(data_xform_prop); + } /* end if */ + } /* end if */ + + FUNC_LEAVE_NOAPI(ret_value) +} /* H5Z_xform_create() */ + + +/*------------------------------------------------------------------------- + * Function: H5Z_xform_destroy + * + * Purpose: Destroy a data transform object. + * + * Return: + * Success: SUCCEED + * Failure: FAIL + * + * Programmer: Quincey Koziol, koziol@ncsa.uiuc.edu + * + * Date: May 4, 2004 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5Z_xform_destroy(H5Z_data_xform_t *data_xform_prop) +{ + herr_t ret_value=SUCCEED; + + FUNC_ENTER_NOAPI(H5Z_xform_destroy, FAIL) + + if(data_xform_prop) { + /* Destroy the parse tree */ + H5Z_xform_destroy_parse_tree(data_xform_prop->parse_root); + + /* Free the expression */ + H5MM_xfree(data_xform_prop->xform_exp); + + /* Free the node */ + H5MM_xfree(data_xform_prop); + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5Z_xform_destroy() */ + + +/*------------------------------------------------------------------------- + * Function: H5Z_xform_copy + * + * Purpose: Clone a data transform object. + * + * Return: + * Success: SUCCEED + * Failure: FAIL + * + * Programmer: Quincey Koziol, koziol@ncsa.uiuc.edu + * + * Date: May 4, 2004 + * + * Comments: This is an "in-place" copy, since this routine gets called + * after the top-level copy has been performed and this routine finishes + * the "deep" part of the copy. + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5Z_xform_copy(H5Z_data_xform_t **data_xform_prop) +{ + H5Z_data_xform_t *new_data_xform_prop; + herr_t ret_value=SUCCEED; + + FUNC_ENTER_NOAPI(H5Z_xform_copy, FAIL) + + if(*data_xform_prop) { + /* Allocate new node */ + if((new_data_xform_prop = H5MM_calloc(sizeof(H5Z_data_xform_t)))==NULL) + HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate memory for data transform info") + + /* Copy string */ + 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") + + /* Copy parse tree */ + if((new_data_xform_prop->parse_root = (H5Z_node*)H5Z_xform_copy_tree((*data_xform_prop)->parse_root)) == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "error copying the parse tree") + + /* Copy new information on top of old information */ + *data_xform_prop=new_data_xform_prop; + } /* end if */ + +done: + /* Clean up on error */ + if(ret_value<0) { + if(new_data_xform_prop) { + if(new_data_xform_prop->parse_root) + H5Z_xform_destroy_parse_tree(new_data_xform_prop->parse_root); + if(new_data_xform_prop->xform_exp) + H5MM_xfree(new_data_xform_prop->xform_exp); + H5MM_xfree(new_data_xform_prop); + } /* end if */ + } /* end if */ + + FUNC_LEAVE_NOAPI(ret_value) +} /* H5Z_xform_copy() */ + + +/*------------------------------------------------------------------------- + * Function: H5Z_xform_noop + * + * Purpose: Checks if a data transform will be performed + * + * Return: TRUE for no data transform, FALSE for a data transform + * + * Programmer: Quincey Koziol, koziol@ncsa.uiuc.edu + * + * Date: May 4, 2004 + * + * Comments: Can't fail + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +hbool_t +H5Z_xform_noop(const H5Z_data_xform_t *data_xform_prop) +{ + hbool_t ret_value; + + FUNC_ENTER_NOAPI(H5Z_xform_noop, TRUE) + + ret_value=(data_xform_prop ? FALSE : TRUE); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5Z_xform_noop() */ + |