From f75ed67d2b624fa4b72207eba13c9f0a34605a47 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Tue, 20 Jul 2004 12:11:38 -0500 Subject: [svn-r8902] Purpose: Bug fix Description: Allow buffer parameter to H5Dread & H5Dwrite to be NULL if there are no elements to transfer. Platforms tested: FreeBSD 4.10 (sleipnir) w/parallel Too minor to require h5committest --- release_docs/RELEASE.txt | 3 + src/H5Dio.c | 9 +- test/tselect.c | 271 ++++++++++++++++++++++------------------------- 3 files changed, 135 insertions(+), 148 deletions(-) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 4b4ee3a..f0c6f7e 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -82,6 +82,9 @@ Bug Fixes since HDF5-1.6.2 release Library ------- + - Allow NULL pointer for buffer parameter to H5Dread & H5Dwrite + when not writing data ("none" selection or hyperslab or point + selection with no elements defined). QAK - 2004/07/20 - Calling H5Gcreate() on "/" or "." throws an error instead of failing quietly. JML - 2004/07/19 - Fixed bug where setting file address size to be very small could diff --git a/src/H5Dio.c b/src/H5Dio.c index a684329..e224fea 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -481,7 +481,7 @@ H5Dread(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, else if (TRUE!=H5P_isa_class(plist_id,H5P_DATASET_XFER)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms") - if (!buf) + if (!buf && H5S_GET_SELECT_NPOINTS(file_space)!=0) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no output buffer") /* read raw data */ @@ -569,7 +569,7 @@ H5Dwrite(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, else if (TRUE!=H5P_isa_class(plist_id,H5P_DATASET_XFER)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms") - if (!buf) + if (!buf && H5S_GET_SELECT_NPOINTS(file_space)!=0) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no output buffer") /* write raw data */ @@ -650,7 +650,6 @@ H5D_read(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, /* check args */ assert(dataset && dataset->ent.file); - assert(buf); /* Get memory datatype */ if (NULL == (mem_type = H5I_object_verify(mem_type_id, H5I_DATATYPE))) @@ -821,8 +820,7 @@ done: * Removed the must_convert parameter and move preconditions to * H5S__opt_possible() routine * - * Nat Furrer and James Laird - * June 17, 2004 + * Nat Furrer and James Laird, 2004/6/7 * Added check for filter encode capability *------------------------------------------------------------------------- */ @@ -848,7 +846,6 @@ H5D_write(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, /* check args */ assert(dataset && dataset->ent.file); - assert(buf); /* Get the memory datatype */ if (NULL == (mem_type = H5I_object_verify(mem_type_id, H5I_DATATYPE))) diff --git a/test/tselect.c b/test/tselect.c index bea1e89..c74b90a 100644 --- a/test/tselect.c +++ b/test/tselect.c @@ -12,8 +12,6 @@ * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* $Id$ */ - /*********************************************************** * * Test program: tselect @@ -255,6 +253,12 @@ test_select_hyper(hid_t xfer_plist) ret=H5Dwrite(dataset,H5T_NATIVE_UCHAR,sid2,sid1,xfer_plist,wbuf); CHECK(ret, FAIL, "H5Dwrite"); + /* Exercise check for NULL buffer and valid selection */ + H5E_BEGIN_TRY { + ret=H5Dwrite(dataset,H5T_NATIVE_UCHAR,sid2,sid1,xfer_plist,NULL); + } H5E_END_TRY; + VERIFY(ret, FAIL, "H5Dwrite"); + /* Close memory dataspace */ ret = H5Sclose(sid2); CHECK(ret, FAIL, "H5Sclose"); @@ -275,6 +279,12 @@ test_select_hyper(hid_t xfer_plist) ret=H5Dread(dataset,H5T_NATIVE_UCHAR,sid2,sid1,xfer_plist,rbuf); CHECK(ret, FAIL, "H5Dread"); + /* Exercise check for NULL buffer and valid selection */ + H5E_BEGIN_TRY { + ret=H5Dread(dataset,H5T_NATIVE_UCHAR,sid2,sid1,xfer_plist,NULL); + } H5E_END_TRY; + VERIFY(ret, FAIL, "H5Dread"); + /* Check that the values match with a dataset iterator */ tbuf=wbuf+(15*SPACE2_DIM2); ret = H5Diterate(rbuf,H5T_NATIVE_UCHAR,sid2,test_select_hyper_iter1,&tbuf); @@ -860,8 +870,8 @@ test_select_combo(void) MESSAGE(5, ("Testing Combination of Hyperslab & Element Selection Functions\n")); /* Allocate write & read buffers */ - wbuf=malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); - rbuf=calloc(sizeof(uint8_t),SPACE3_DIM1*SPACE3_DIM2); + wbuf=HDmalloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); + rbuf=HDcalloc(sizeof(uint8_t),SPACE3_DIM1*SPACE3_DIM2); /* Initialize write buffer */ for(i=0, tbuf=wbuf; i=10 && i<=14) && (j>=5 && j<=14)) || ((i>=5 && i<=9) && (j>=10 && j<=14))) { if(*tbuf!=*tbuf2) - printf("%d: hyperslab values don't match!, i=%d, j=%d, *tbuf=%d, *tbuf2=%d\n",__LINE__,i,j,(int)*tbuf,(int)*tbuf2); + TestErrPrintf("%d: hyperslab values don't match!, i=%d, j=%d, *tbuf=%d, *tbuf2=%d\n",__LINE__,i,j,(int)*tbuf,(int)*tbuf2); tbuf2++; } /* end if */ else { if(*tbuf!=0) - printf("%d: hyperslab element has wrong value!, i=%d, j=%d, *tbuf=%d\n",__LINE__,i,j,(int)*tbuf); + TestErrPrintf("%d: hyperslab element has wrong value!, i=%d, j=%d, *tbuf=%d\n",__LINE__,i,j,(int)*tbuf); } /* end else */ } /* end for */ @@ -3310,8 +3310,8 @@ test_select_hyper_nota_2d(void) CHECK(ret, FAIL, "H5Fclose"); /* Free memory buffers */ - free(wbuf); - free(rbuf); + HDfree(wbuf); + HDfree(rbuf); } /* test_select_hyper_nota_2d() */ /**************************************************************** @@ -3374,8 +3374,8 @@ test_select_hyper_union_random_5d(hid_t read_plist) MESSAGE(5, ("Testing Hyperslab Selection Functions with random unions of 5-D hyperslabs\n")); /* Allocate write & read buffers */ - wbuf=malloc(sizeof(int)*SPACE5_DIM1*SPACE5_DIM2*SPACE5_DIM3*SPACE5_DIM4*SPACE5_DIM5); - rbuf=calloc(sizeof(int),SPACE5_DIM1*SPACE5_DIM2*SPACE5_DIM3*SPACE5_DIM4*SPACE5_DIM5); + wbuf=HDmalloc(sizeof(int)*SPACE5_DIM1*SPACE5_DIM2*SPACE5_DIM3*SPACE5_DIM4*SPACE5_DIM5); + rbuf=HDcalloc(sizeof(int),SPACE5_DIM1*SPACE5_DIM2*SPACE5_DIM3*SPACE5_DIM4*SPACE5_DIM5); /* Initialize write buffer */ for(i=0, tbuf=wbuf; i=(int)(start[0]+real_offset[0]) && i<(int)(start[0]+count[0]+real_offset[0])) && (j>=(int)(start[1]+real_offset[1]) && j<(int)(start[1]+count[1]+real_offset[1]))) { - if(*tbuf!=(unsigned short)fill_value) { + if(*tbuf!=(unsigned short)fill_value) TestErrPrintf("Error! j=%d, i=%d, *tbuf=%u, fill_value=%u\n",j,i,(unsigned)*tbuf,(unsigned)fill_value); - } /* end if */ } /* end if */ else { - if(*tbuf!=((unsigned short)(i*SPACE7_DIM2)+j)) { + if(*tbuf!=((unsigned short)(i*SPACE7_DIM2)+j)) TestErrPrintf("Error! j=%d, i=%d, *tbuf=%u, should be: %u\n",j,i,(unsigned)*tbuf,(unsigned)((i*SPACE7_DIM2)+j)); - } /* end if */ } /* end else */ } /* end for */ @@ -4782,7 +4776,7 @@ test_select_fill_hyper_simple(hssize_t *offset) CHECK(ret, FAIL, "H5Sclose"); /* Free memory buffers */ - free(wbuf); + HDfree(wbuf); } /* test_select_fill_hyper_simple() */ /**************************************************************** @@ -4819,7 +4813,7 @@ test_select_fill_hyper_regular(hssize_t *offset) MESSAGE(5, ("Testing Filling Regular 'hyperslab' Selections\n")); /* Allocate memory buffer */ - wbuf=malloc(sizeof(unsigned short)*SPACE7_DIM1*SPACE7_DIM2); + wbuf=HDmalloc(sizeof(unsigned short)*SPACE7_DIM1*SPACE7_DIM2); /* Initialize memory buffer */ for(i=0, tbuf=wbuf; i=((2*SPACE10_CHUNK_SIZE)/3)) { - if(wbuf[i+j]!=rbuf[((SPACE10_DIM1-i)-SPACE10_CHUNK_SIZE)+j]) { + if(j<(SPACE10_CHUNK_SIZE/3) || j>=((2*SPACE10_CHUNK_SIZE)/3)) + if(wbuf[i+j]!=rbuf[((SPACE10_DIM1-i)-SPACE10_CHUNK_SIZE)+j]) TestErrPrintf("Line: %d - Error! i=%d, j=%d, rbuf=%d, wbuf=%d\n",__LINE__,i,j,rbuf[((SPACE10_DIM1-i)-SPACE10_CHUNK_SIZE)+j],wbuf[i+j]); - } /* end if */ - } /* end if */ - } /* end for */ - } /* end for */ /* Close the memory dataspace */ ret=H5Sclose (msid); -- cgit v0.12