From a60098af02a9342258f21a05370d91ae0fddf9a6 Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Tue, 21 Jul 2009 14:18:38 -0500 Subject: [PATCH] [svn-r17207] Fixed a small bug in the fractal heap code involving filtered fractal heaps. Tested: jam, linew, smirom (h5committest) --- src/H5HFcache.c | 2 +- test/fheap.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/H5HFcache.c b/src/H5HFcache.c index 6d250d1367..b5d7cb574c 100644 --- a/src/H5HFcache.c +++ b/src/H5HFcache.c @@ -1539,7 +1539,7 @@ H5HF_cache_dblock_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, if(hdr->filter_len > 0) { H5Z_cb_t filter_cb = {NULL, NULL}; /* Filter callback structure */ size_t nbytes; /* Number of bytes used */ - unsigned filter_mask; /* Filter mask for block */ + unsigned filter_mask = 0; /* Filter mask for block */ /* Allocate buffer to perform I/O filtering on */ write_size = dblock->size; diff --git a/test/fheap.c b/test/fheap.c index 953a8494a1..33614c2104 100644 --- a/test/fheap.c +++ b/test/fheap.c @@ -15377,6 +15377,18 @@ error: * *------------------------------------------------------------------------- */ +/* Custom filter used to verify that the filters are actually called and do not + * just silently fail */ +static hbool_t test_write_filter_called; +static size_t test_write_filter(unsigned int UNUSED flags, size_t UNUSED cd_nelmts, + const unsigned int UNUSED cd_values[], size_t nbytes, size_t UNUSED *buf_size, + void UNUSED **buf) +{ + test_write_filter_called = TRUE; + + return nbytes; +} /* end link_filter_filter */ + static unsigned test_write(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam) { @@ -15413,12 +15425,27 @@ test_write(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam) /* Check if we are compressing the blocks */ if(tparam->comp == FHEAP_TEST_COMPRESS) { + H5Z_class2_t filter_class; /* Custom filter */ unsigned deflate_level; /* Deflation level */ /* Set an I/O filter for heap data */ deflate_level = 6; if(H5Z_append(&tmp_cparam.pline, H5Z_FILTER_DEFLATE, H5Z_FLAG_OPTIONAL, (size_t)1, &deflate_level) < 0) FAIL_STACK_ERROR + + /* Register and append custom filter */ + filter_class.version = H5Z_CLASS_T_VERS; + filter_class.id = H5Z_FILTER_RESERVED + 43; + filter_class.encoder_present = TRUE; + filter_class.decoder_present = TRUE; + filter_class.name = "custom_fheap_filter"; + filter_class.can_apply = NULL; + filter_class.set_local = NULL; + filter_class.filter = test_write_filter; + if(H5Zregister(&filter_class) < 0) TEST_ERROR + if(H5Z_append(&tmp_cparam.pline, H5Z_FILTER_RESERVED + 43, 0, 0, NULL) < 0) + FAIL_STACK_ERROR + test_write_filter_called = FALSE; } /* end if */ /* Perform common file & heap open operations */ @@ -15466,6 +15493,35 @@ test_write(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam) if(ret >= 0) TEST_ERROR + /* Close the fractal heap */ + if(H5HF_close(fh, dxpl) < 0) + FAIL_STACK_ERROR + fh = NULL; + + /* Close the file */ + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + /* Verify that the custom filter has been applied for the huge object (if + * applicable) */ + if(tparam->comp == FHEAP_TEST_COMPRESS) { + if(!test_write_filter_called) TEST_ERROR + test_write_filter_called = FALSE; + } /* end if */ + + + /* Re-open the file */ + if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Re-open the heap */ + if(NULL == (fh = H5HF_open(f, H5P_DATASET_XFER_DEFAULT, fh_addr))) + FAIL_STACK_ERROR + /* Initialize data to overwrite with */ rewrite_obj = (unsigned char *)H5MM_malloc(shared_obj_size_g); for(u = 0; u < shared_obj_size_g; u++) @@ -15511,6 +15567,11 @@ test_write(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam) if(H5Fclose(file) < 0) FAIL_STACK_ERROR + /* Verify that the custom filter has been applied to the managed objects (if + * applicable) */ + if(tparam->comp == FHEAP_TEST_COMPRESS) + if(!test_write_filter_called) TEST_ERROR + /* Re-open the file */ if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)