From 06612f25f93c0dc4523b274b7977d6c8f82573ef Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Wed, 20 Nov 2002 10:10:34 -0500 Subject: [svn-r6121] Purpose: Bug fix Description: Array testing routine is creatint huge arrays on the function stack which causes a segmentation fault on Linux & FreeBSD when threadsafe support is enabled. Solution: Allocate data for test dynamically instead of automatically. In general, this should be the preferred method for all data arrays. Platforms tested: FreeBSD 4.7 (sleipnir) w/threadsafe enabled. --- test/ntypes.c | 182 +++++++++++++++++++--------------------------------------- 1 file changed, 60 insertions(+), 122 deletions(-) diff --git a/test/ntypes.c b/test/ntypes.c index b4534fe..2afd283 100644 --- a/test/ntypes.c +++ b/test/ntypes.c @@ -132,7 +132,7 @@ test_atomic_dtype(hid_t file) /* Verify the datatype retrieved and converted */ if(H5Tget_order(native_type) != H5Tget_order(H5T_NATIVE_LLONG)) goto error; - if(sizeof(long long)!=H5Tget_size(native_type)) + if(sizeof(long_long)!=H5Tget_size(native_type)) goto error; if(H5T_INTEGER!=H5Tget_class(native_type)) goto error; @@ -220,7 +220,7 @@ test_compound_dtype_2(hid_t file) char c; int i; s2 st; - unsigned long long l; + unsigned long_long l; } s1; hid_t dataset, space; hid_t dtype, native_type, tid, tid2, tid_m, tid_m2; @@ -352,7 +352,7 @@ test_compound_dtype(hid_t file) typedef struct { char c; unsigned int i; - long long l; + long_long l; } s1; hid_t dataset, space; hid_t dtype, native_type, tid, tid2; @@ -474,7 +474,7 @@ test_enum_dtype(hid_t file) hsize_t dims[2]; short points[100][200], check[100][200]; short colors[8]; - char *mname[] = { "RED", + const char *mname[] = { "RED", "GREEN", "BLUE", "YELLOW", @@ -590,26 +590,31 @@ test_array_dtype(hid_t file) typedef struct { char c; int i; - long long l; + long_long l; } s1; - hid_t dataset, space, tmp_t; + hid_t dataset, space; hid_t dtype, native_type, tid, tid2, tid3, tid_m; int i, j, k, n; hsize_t space_dims[2], array_dims[1]={5}; - s1 points[100][200][5], check[100][200][5]; + s1 *temp_point, *temp_check; + s1 *points=NULL, *check=NULL; TESTING("array datatype"); + /* Allocate space for the points & check arrays */ + if((points=malloc(sizeof(s1)*100*200*5))==NULL) + goto error; + if((check=calloc(sizeof(s1),100*200*5))==NULL) + goto error; + /* Initialize the dataset */ - for (i = n = 0; i < 100; i++) { - for (j = 0; j < 200; j++) { + for(i = n = 0, temp_point=points; i < 100; i++) + for(j = 0; j < 200; j++) for(k = 0; k < 5; k++) { - (points[i][j][k]).c = 't'; - (points[i][j][k]).i = n++; - (points[i][j][k]).l = (i*10+j*100)*n; + temp_point->c= 't'; + temp_point->i= n++; + temp_point->l= (i*10+j*100)*n; } - } - } /* Create the data space */ space_dims[0] = 100; @@ -669,12 +674,12 @@ test_array_dtype(hid_t file) goto error; /* Check that the values read are the same as the values written */ - for (i = 0; i < 100; i++) { + for (i = 0, temp_point=points, temp_check=check; i < 100; i++) { for (j = 0; j < 200; j++) { for (k = 0; k < 5; k++) { - if ((points[i][j][k]).c != (check[i][j][k]).c || - (points[i][j][k]).i != (check[i][j][k]).i || - (points[i][j][k]).l != (check[i][j][k]).l ) { + if (temp_point->c != temp_check->c || + temp_point->i != temp_check->i || + temp_point->l != temp_check->l ) { H5_FAILED(); printf(" Read different values than written.\n"); printf(" At index %d,%d\n", i, j); @@ -684,76 +689,29 @@ test_array_dtype(hid_t file) } } + /* Close HDF5 objects */ if(H5Dclose(dataset)) goto error; if(H5Tclose(native_type)) goto error; if(H5Tclose(dtype)) goto error; if(H5Tclose(tid_m)<0) goto error; if(H5Tclose(tid3)<0) goto error; + + /* Free memory for test data */ + free(points); + free(check); + PASSED(); return 0; - error: +error: + if(points!=NULL) + free(points); + if(check!=NULL) + free(check); return -1; } -/**************************************************************** -** -** test_vl_alloc_custom(): Test VL datatype custom memory -** allocation routines. This routine just uses malloc to -** allocate the memory and increments the amount of memory -** allocated. -** -****************************************************************/ -static void *test_vl_alloc_custom(size_t size, void *info) -{ - void *ret_value=NULL; /* Pointer to return */ - size_t *mem_used=(size_t *)info; /* Get the pointer to the memory used */ - size_t extra; /* Extra space needed */ - - /* - * This weird contortion is required on the DEC Alpha to keep the - * alignment correct - QAK - */ - extra=MAX(sizeof(void *),sizeof(size_t)); - - if((ret_value=HDmalloc(extra+size))!=NULL) { - *(size_t *)ret_value=size; - *mem_used+=size; - } /* end if */ - ret_value=((unsigned char *)ret_value)+extra; - return(ret_value); -} - - -/**************************************************************** -** -** test_vl_free_custom(): Test VL datatype custom memory -** allocation routines. This routine just uses free to -** release the memory and decrements the amount of memory -** allocated. -** -****************************************************************/ -static void test_vl_free_custom(void *_mem, void *info) -{ - unsigned char *mem; - size_t *mem_used=(size_t *)info; /* Get the pointer to the memory used */ - size_t extra; /* Extra space needed */ - - /* - * This weird contortion is required on the DEC Alpha to keep the - * alignment correct - QAK - */ - extra=MAX(sizeof(void *),sizeof(size_t)); - - if(_mem!=NULL) { - mem=((unsigned char *)_mem)-extra; - *mem_used-=*(size_t *)mem; - HDfree(mem); - } /* end if */ -} - - /*------------------------------------------------------------------------- * Function: test_vl_dtype * @@ -776,13 +734,10 @@ test_vl_dtype(hid_t file) hvl_t wdata[SPACE1_DIM1]; /* Information to write */ hvl_t rdata[SPACE1_DIM1]; /* Information read in */ hvl_t *t1, *t2; /* Temporary pointer to VL information */ - hid_t xfer_pid; /* Dataset transfer property list ID */ hsize_t dims1[] = {SPACE1_DIM1}; - size_t mem_used=0; /* Memory used during allocation */ - hid_t dataset, space; hid_t dtype, native_type, tid, tid2, tid_m, tid_m2; - int i, j, k; + size_t i, j, k; TESTING("variable length datatype"); @@ -849,14 +804,8 @@ test_vl_dtype(hid_t file) if(!H5Tequal(native_type, tid_m)) goto error; - /* Change to the custom memory allocation routines for reading VL data */ - if((xfer_pid=H5Pcreate(H5P_DATASET_XFER))<0) goto error; - - if(H5Pset_vlen_mem_manager(xfer_pid,test_vl_alloc_custom,&mem_used,test_vl_free_custom,&mem_used)<0) - goto error; - /* Read dataset from disk */ - if(H5Dread(dataset,native_type,H5S_ALL,H5S_ALL,xfer_pid,rdata)<0) goto error; + if(H5Dread(dataset,native_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,rdata)<0) goto error; /* Compare data read in */ for(i=0; i