diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/H5.c | 2 | ||||
-rw-r--r-- | src/H5AC.c | 2 | ||||
-rw-r--r-- | src/H5B.c | 2 | ||||
-rw-r--r-- | src/H5E.c | 2 | ||||
-rw-r--r-- | src/H5F.c | 231 | ||||
-rw-r--r-- | src/H5G.c | 137 | ||||
-rw-r--r-- | src/H5H.c | 4 | ||||
-rw-r--r-- | src/H5M.c | 28 | ||||
-rw-r--r-- | src/H5MM.c | 2 | ||||
-rw-r--r-- | src/H5MMprivate.h | 2 | ||||
-rw-r--r-- | src/H5O.c | 38 | ||||
-rw-r--r-- | src/H5Oname.c | 8 | ||||
-rw-r--r-- | src/debug.c | 34 |
13 files changed, 357 insertions, 135 deletions
@@ -74,7 +74,7 @@ herr_t H5_init_library(void) /* Install atexit() library cleanup routine */ if(install_atexit_g==TRUE) - if (atexit(&H5_term_library) != 0) + if (HDatexit(&H5_term_library) != 0) HRETURN_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL); FUNC_LEAVE (SUCCEED); @@ -290,7 +290,7 @@ H5AC_flush (hdf5_file_t *f, const H5AC_class_t *type, haddr_t addr, for (i=0; i<H5AC_NSLOTS; i++) map[i] = i; assert (NULL==current_cache_g); current_cache_g = f->cache; - qsort (map, H5AC_NSLOTS, sizeof(intn), H5AC_compare); + HDqsort (map, H5AC_NSLOTS, sizeof(intn), H5AC_compare); current_cache_g = NULL; #endif @@ -260,7 +260,7 @@ H5B_load (hdf5_file_t *f, haddr_t addr, const void *_data) p = bt->page; /* magic number */ - if (memcmp (p, H5B_MAGIC, H5B_SIZEOF_MAGIC)) goto error; + if (HDmemcmp (p, H5B_MAGIC, H5B_SIZEOF_MAGIC)) goto error; p += 4; /* node type and level */ @@ -386,7 +386,7 @@ H5Epush(hdf_maj_err_code_t maj, hdf_min_err_code_t min, const char *function_nam if((err_stack=H5Aatom_object(thrderrid))==NULL) HGOTO_ERROR(H5E_BADATOM, H5E_BADATOM, FAIL); - err_stack->push(thrderrid, maj, min, function_name, file_name, line); + (err_stack->push)(thrderrid, maj, min, function_name, file_name, line); done: if(ret_value == FAIL) @@ -7,6 +7,10 @@ * * * For conditions of distribution and use, see the accompanying * * hdf/COPYING file. * +* +* MODIFICATIONS +* Robb Matzke, 30 Aug 1997 +* Added `ERRORS' fields to function prologues. * * ****************************************************************************/ @@ -66,6 +70,8 @@ RETURNS DESCRIPTION Initializes any interface-specific data or routines. +ERRORS + Modifications: Robb Matzke, 4 Aug 1997 Changed pablo mask from H5_mask to H5F_mask for the FUNC_LEAVE call. @@ -92,6 +98,9 @@ static herr_t H5F_init_interface(void) const hdf5_file_t *f; IN: pointer to the file record uint8 **p; IN: pointer to buffer pointer to encode length in uint8 *l; IN: pointer to length to encode + + ERRORS + RETURNS none DESCRIPTION @@ -130,6 +139,9 @@ done: const hdf5_file_t *f; IN: pointer to the file record uint8 **p; IN: pointer to buffer pointer to encode offset in uint8 *o; IN: pointer to offset to encode + +ERRORS + RETURNS none DESCRIPTION @@ -168,6 +180,9 @@ done: intn HPcompare_filename(obj, key) const VOIDP obj; IN: pointer to the file record const VOIDP key; IN: pointer to the name of file + + ERRORS + RETURNS TRUE if the key matches the obj, FALSE otherwise DESCRIPTION @@ -191,13 +206,22 @@ H5F_compare_filename (const VOIDP _obj, const VOIDP _key) /*-------------------------------------------------------------------------- NAME H5Fget_create_template + PURPOSE Get an atom for a copy of the file-creation template for this file + USAGE hatom_t H5Fget_create_template(fid) hatom_t fid; IN: File ID + + ERRORS + ATOM BADATOM Can't get file struct. + FUNC CANTCREATE Can't create template. + FUNC CANTINIT Can't init template. + RETURNS Returns template ID on success, FAIL on failure + DESCRIPTION This function returns an atom with a copy of the template parameters used to create a file. @@ -214,14 +238,14 @@ hatom_t H5Fget_create_template(hatom_t fid) /* Get the file structure */ if((file=H5Aatom_object(fid))==NULL) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); /*can't get file struct*/ /* Create the template object to return */ if((ret_value=H5Mcreate(fid,H5_TEMPLATE,NULL))==FAIL) - HGOTO_ERROR(H5E_FUNC, H5E_CANTCREATE, FAIL); + HGOTO_ERROR(H5E_FUNC, H5E_CANTCREATE, FAIL); /*can't create template*/ if(H5C_init(ret_value,&(file->file_create_parms))==FAIL) - HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL); + HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL); /*can't init template*/ done: if(ret_value == FAIL) @@ -237,13 +261,24 @@ done: /*-------------------------------------------------------------------------- NAME H5Fis_hdf5 + PURPOSE Check the file signature to detect an HDF5 file. + USAGE hbool_t H5Fis_hdf5(filename) const char *filename; IN: Name of the file to check + ERRORS + ARGS BADRANGE No filename specified. + FILE BADFILE Low-level file open failure. + IO READERROR Read error. + IO READERROR Seek error. + IO SEEKERROR Unable to determine length of file due to seek + failure. + RETURNS TRUE/FALSE/FAIL + DESCRIPTION This function determines if a file is an HDF5 format file. --------------------------------------------------------------------------*/ @@ -260,25 +295,29 @@ hbool_t H5Fis_hdf5(const char *filename) /* Clear errors and check args and all the boring stuff. */ H5ECLEAR; if(filename==NULL) - HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, BFAIL); + HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, BFAIL); /*no filename specified*/ /* Open the file */ f_handle=H5F_OPEN(filename,0); - if(H5F_OPENERR(f_handle)) - HGOTO_ERROR(H5E_FILE, H5E_BADFILE, BFAIL); + if(H5F_OPENERR(f_handle)) { + /* Low-level file open failure */ + HGOTO_ERROR(H5E_FILE, H5E_BADFILE, BFAIL); + } /* Get the length of the file */ - if(H5F_SEEKEND(f_handle)==FAIL) - HGOTO_ERROR(H5E_IO, H5E_SEEKERROR, BFAIL); + if(H5F_SEEKEND(f_handle)==FAIL) { + /* Unable to determine length of file due to seek failure */ + HGOTO_ERROR(H5E_IO, H5E_SEEKERROR, BFAIL); + } file_len=H5F_TELL(f_handle); /* Check the offsets where the file signature is possible */ while(curr_off<file_len) { if(H5F_SEEK(f_handle,curr_off)==FAIL) - HGOTO_ERROR(H5E_IO, H5E_READERROR, BFAIL); + HGOTO_ERROR(H5E_IO, H5E_READERROR, BFAIL); /*seek error*/ if(H5F_READ(f_handle,temp_buf, H5F_SIGNATURE_LEN)==FAIL) - HGOTO_ERROR(H5E_IO, H5E_READERROR, BFAIL); + HGOTO_ERROR(H5E_IO, H5E_READERROR, BFAIL); /*read error*/ if(HDmemcmp(temp_buf,H5F_SIGNATURE,H5F_SIGNATURE_LEN)==0) { ret_value=BTRUE; @@ -314,6 +353,8 @@ done: * H5Fopen and H5Fcreate functions then fill in various * fields. * + * Errors: + * * Return: Success: Ptr to a new file struct. * * Failure: NULL @@ -349,6 +390,8 @@ H5F_new (void) * the cache or anything else; it only frees memory associated * with the file struct. * + * Errors: + * * Return: Success: NULL * * Failure: NULL @@ -377,16 +420,34 @@ H5F_dest (hdf5_file_t *f) /*-------------------------------------------------------------------------- NAME H5Fcreate + PURPOSE Create a new HDF5 file. + USAGE int32 H5Fcreate(filename, flags, create_temp, access_temp) const char *filename; IN: Name of the file to create uintn flags; IN: Flags to indicate various options. hatom_t create_temp; IN: File-creation template ID hatom_t access_temp; IN: File-access template ID + + ERRORS + ARGS BADVALUE Invalid file name. + ARGS BADVALUE Invalid flags. + ATOM BADATOM Can't atomize template. + ATOM BADATOM Can't unatomize template. + ATOM CANTREGISTER Can't atomize file. + FILE CANTCREATE Unable to create the file due to low level create + failure. + FILE FILEEXISTS File already exists but overwrite permission + was not given. + FILE FILEOPEN File already open. + IO CANTINIT Can't write file boot block. + RESOURCE NOSPACE H5F_new() failed. + RETURNS Returns file ID on success, FAIL on failure + DESCRIPTION This is the primary function for creating HDF5 files . The flags parameter determines whether an existing file will be overwritten or not. @@ -402,16 +463,7 @@ H5F_dest (hdf5_file_t *f) values for the appropriate template. (Documented in the template module). [Access templates are currently unused in this routine, although they will be implemented in the future] - ERRORS - H5E_ARGS - H5E_BADVALUE - Argument checking - H5E_FILE - H5E_FILEOPEN - File already open - - H5E_FILEEXISTS - File exists and no overwrite permission is given - - H5E_CANTCREATE - Can't create new file - H5E_RESOURCE - H5E_NOSPACE - Can't allocate space - H5E_ATOM - H5E_BADATOM - Can't get the object for an atom - - H5E_CANTREGISTER - Can't register the new file atom - H5E_IO - H5E_SEEKERROR - Can't seek to correct offset for boot-block - - H5E_WRITEERROR - Can't write data to file + MODIFICATIONS: Robb Matzke, 18 Jul 1997 File struct creation and destruction is through H5F_new() H5F_dest(). @@ -432,14 +484,14 @@ hatom_t H5Fcreate(const char *filename, uintn flags, hatom_t create_temp, hatom_ /* Clear errors and check args and all the boring stuff. */ H5ECLEAR; - if(filename==NULL) /* check for valid filename */ - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL); - if((flags&~H5ACC_OVERWRITE)!=0) /* check for valid flags */ - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL); + if(filename==NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL); /*invalid file name*/ + if((flags&~H5ACC_OVERWRITE)!=0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL); /*invalid flags*/ /* See if this file is already open */ if(H5Asearch_atom(H5_FILE,H5F_compare_filename,(const VOIDP)filename)!=NULL) - HGOTO_ERROR(H5E_FILE, H5E_FILEOPEN, FAIL); + HGOTO_ERROR(H5E_FILE, H5E_FILEOPEN, FAIL); /*file already open*/ /* Check if the file already exists */ f_handle=H5F_OPEN(filename,0); @@ -450,18 +502,21 @@ hatom_t H5Fcreate(const char *filename, uintn flags, hatom_t create_temp, hatom_ f_handle=H5F_INVALID_FILE; } /* end if */ - /* throw an error if the file exists and we aren't allowed to overwrite it */ - if((flags&H5ACC_OVERWRITE)==0 && file_exists) - HGOTO_ERROR(H5E_FILE, H5E_FILEEXISTS, FAIL); + if((flags&H5ACC_OVERWRITE)==0 && file_exists) { + /* File already exists but overwrite permission was not given */ + HGOTO_ERROR(H5E_FILE, H5E_FILEEXISTS, FAIL); + } /* OK to create/overwrite the file */ f_handle=H5F_CREATE(filename); - if(H5F_OPENERR(f_handle)) - HGOTO_ERROR(H5E_FILE, H5E_CANTCREATE, FAIL); + if(H5F_OPENERR(f_handle)) { + /* Unable to create the file due to low level create failure */ + HGOTO_ERROR(H5E_FILE, H5E_CANTCREATE, FAIL); + } /* Create the file node */ if (NULL==(new_file=H5F_new())) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL); + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL); /*H5F_new() failed*/ /* Set the non-zero elements of the file structure */ new_file->dir=HDgetcwd(NULL,0); /* get the directory we just created the file within */ @@ -476,7 +531,7 @@ hatom_t H5Fcreate(const char *filename, uintn flags, hatom_t create_temp, hatom_ if(create_temp==0) create_temp=H5C_get_default_atom(H5_TEMPLATE); if((f_create_parms=H5Aatom_object(create_temp))==NULL) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); /*can't atomize template*/ HDmemcpy(&new_file->file_create_parms,f_create_parms,sizeof(file_create_temp_t)); #ifdef LATER @@ -484,7 +539,7 @@ hatom_t H5Fcreate(const char *filename, uintn flags, hatom_t create_temp, hatom_ if(access_temp==0) access_temp=H5CPget_default_atom(H5_TEMPLATE); if((f_access_parms=H5Aatom_object(access_temp))==NULL) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); /*can't unatomize template*/ HDmemcpy(&new_file->file_access_parms,f_access_parms,sizeof(file_access_temp_t)); #endif /* LATER */ @@ -495,7 +550,7 @@ hatom_t H5Fcreate(const char *filename, uintn flags, hatom_t create_temp, hatom_ /* Get an atom for the file */ if((ret_value=H5Aregister_atom(H5_FILE, new_file))==FAIL) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL); + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL); /*can't atomize file*/ done: if(ret_value == FAIL) @@ -519,15 +574,36 @@ done: /*-------------------------------------------------------------------------- NAME H5Fopen + PURPOSE Open an existing HDF5 file. + USAGE hatom_t H5Fopen(filename, flags, access_temp) const char *filename; IN: Name of the file to create uintn flags; IN: Flags to indicate various options. hatom_t access_temp; IN: File-access template + + ERRORS + ARGS BADRANGE Invalid file name. + ATOM BADATOM Can't atomize template. + ATOM BADATOM Can't unatomize template. + ATOM CANTREGISTER Can't atomize file. + ATOM CANTREGISTER Can't register new_file atom. + FILE CANTOPEN File doesn't exist. + FILE NOTHDF5 Not an HDF5 file. + FILE NOTHDF5 The file exists but doesn't appear to be an + HDF5 file. + IO READERROR Can't decode root symbol table entry. + IO READERROR Read boot block failed. + IO READERROR Read boot block signature failed. + IO READERROR Seek to boot block failed. + IO SEEKERROR Seek failed. + RESOURCE NOSPACE H5F_new() failed. + RETURNS Returns file ID on success, FAIL on failure + DESCRIPTION This is the primary function for accessing existing HDF5 files. The flags parameter determines whether writing to an existing file will be allowed @@ -560,7 +636,7 @@ hatom_t H5Fopen(const char *filename, uintn flags, hatom_t access_temp) /* Clear errors and check args and all the boring stuff. */ H5ECLEAR; if(filename==NULL) - HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL); + HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);/*invalid file name*/ /* See if this file is already open */ new_file=H5Asearch_atom(H5_FILE,H5F_compare_filename,(const VOIDP)filename); @@ -570,8 +646,10 @@ hatom_t H5Fopen(const char *filename, uintn flags, hatom_t access_temp) { /* Get an atom for the file */ new_file->ref_count++; /* increment the reference count for the file */ - if((ret_value=H5Aregister_atom(H5_FILE, new_file))==FAIL) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL); + if((ret_value=H5Aregister_atom(H5_FILE, new_file))==FAIL) { + /* Can't register new_file atom */ + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL); + } HGOTO_DONE(ret_value); } /* end if */ @@ -579,17 +657,19 @@ hatom_t H5Fopen(const char *filename, uintn flags, hatom_t access_temp) * If the file exists but has different permissions or if it's a new file, * start a new file handle for it, etc. */ - if(H5Fis_hdf5(filename)==BFALSE) - HGOTO_ERROR(H5E_FILE, H5E_NOTHDF5, FAIL); + if(H5Fis_hdf5(filename)==BFALSE) { + /* The file exists but doesn't appear to be an HDF5 file */ + HGOTO_ERROR(H5E_FILE, H5E_NOTHDF5, FAIL); + } /* Check if the file already exists */ f_handle=H5F_OPEN(filename,flags); if(H5F_OPENERR(f_handle)) - HGOTO_ERROR(H5E_FILE, H5E_CANTOPEN, FAIL); + HGOTO_ERROR(H5E_FILE, H5E_CANTOPEN, FAIL);/*file doesn't exist*/ /* Create the file node */ if (NULL==(new_file=H5F_new())) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL); + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL);/*H5F_new() failed*/ /* Set the non-zero elements of the file structure */ new_file->dir=HDgetcwd(NULL,0); /* get the directory we just created the file within */ @@ -599,14 +679,14 @@ hatom_t H5Fopen(const char *filename, uintn flags, hatom_t access_temp) new_file->ref_count=1; /* only 1 fid handed out so far */ create_temp=H5C_get_default_atom(H5_TEMPLATE); if((f_create_parms=H5Aatom_object(create_temp))==NULL) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);/*can't unatomize template*/ HDmemcpy(&new_file->file_create_parms,f_create_parms,sizeof(file_create_temp_t)); #ifdef LATER if(access_temp<=0) access_temp=H5CPget_default_atom(H5_TEMPLATE); if((f_access_parms=H5Aatom_object(access_temp))==NULL) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);/*can't atomize template*/ HDmemcpy(&new_file->file_access_parms,f_access_parms,sizeof(file_access_temp_t)); #endif /* LATER */ @@ -615,16 +695,20 @@ hatom_t H5Fopen(const char *filename, uintn flags, hatom_t access_temp) /* Seek to the correct offset to read in the file signature & boot-block */ /* Get the length of the file */ if(H5F_SEEKEND(new_file->file_handle)==FAIL) - HGOTO_ERROR(H5E_IO, H5E_SEEKERROR, BFAIL); + HGOTO_ERROR(H5E_IO, H5E_SEEKERROR, BFAIL);/*seek failed*/ file_len=H5F_TELL(new_file->file_handle); /* Check the offsets where the file signature is possible */ while(curr_off<file_len) { - if(H5F_SEEK(new_file->file_handle,curr_off)==FAIL) + if(H5F_SEEK(new_file->file_handle,curr_off)==FAIL) { + /*seek to boot block failed*/ HGOTO_ERROR(H5E_IO, H5E_READERROR, BFAIL); - if(H5F_READ(new_file->file_handle,temp_buf, H5F_SIGNATURE_LEN)==FAIL) + } + if(H5F_READ(new_file->file_handle,temp_buf, H5F_SIGNATURE_LEN)==FAIL) { + /*read boot block signature failed*/ HGOTO_ERROR(H5E_IO, H5E_READERROR, BFAIL); + } if(HDmemcmp(temp_buf,H5F_SIGNATURE,H5F_SIGNATURE_LEN)==0) { new_file->file_create_parms.userblock_size=curr_off; @@ -636,11 +720,11 @@ hatom_t H5Fopen(const char *filename, uintn flags, hatom_t access_temp) curr_off*=2; } /* end while */ if(curr_off>file_len) /* Why didn't H5Fis_hdf5 catch this? */ - HGOTO_ERROR(H5E_FILE, H5E_NOTHDF5, FAIL); + HGOTO_ERROR(H5E_FILE, H5E_NOTHDF5, FAIL); /*not an HDF5 file*/ /* Read in the fixed-size part of the boot-block */ if(H5F_READ(new_file->file_handle,temp_buf,16)==FAIL) - HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL); + HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL); /*read boot block failed*/ /* Decode fixed-size part of the boot block */ p=temp_buf; @@ -662,7 +746,7 @@ hatom_t H5Fopen(const char *filename, uintn flags, hatom_t access_temp) H5F_SIZEOF_SIZE(new_file) + /*logical size of HDF5 file*/ H5G_SIZEOF_ENTRY(new_file); /*root symbol table entry*/ if (H5F_READ(new_file->file_handle, temp_buf, variable_size)<0) - HGOTO_ERROR (H5E_IO, H5E_READERROR, FAIL); + HGOTO_ERROR (H5E_IO, H5E_READERROR, FAIL); /*read boot block failed*/ /* Decode the variable-size part of the boot block */ p = temp_buf; @@ -672,16 +756,13 @@ hatom_t H5Fopen(const char *filename, uintn flags, hatom_t access_temp) /* Decode the root symbol table entry */ if (H5G_decode (new_file, &p, new_file->root_sym)<0) { + /*can't decode root symbol table entry */ HGOTO_ERROR (H5E_IO, H5E_READERROR, FAIL); } - /* Set the initial type of the root symbol-entry */ -#ifdef QUINCEY - new_file->root_type= (new_file->root_sym->header>=0) ? H5F_ROOT_UNKNOWN : H5F_NONE; -#endif /* Get an atom for the file */ if((ret_value=H5Aregister_atom(H5_FILE, new_file))==FAIL) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL); + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL);/*can't atomize file*/ done: if(ret_value == FAIL) @@ -703,15 +784,24 @@ done: /*-------------------------------------------------------------------------- NAME H5Fflush + PURPOSE Flush all cached data to disk and optionally invalidates all cached data. + USAGE herr_t H5Fclose(fid, invalidate) hatom_t fid; IN: File ID of file to close. hbool_t invalidate; IN: Invalidate all of the cache? + + ERRORS + ARGS BADTYPE Not a file atom. + ATOM BADATOM Can't get file struct. + CACHE CANTFLUSH Flush failed. + RETURNS SUCCEED/FAIL + DESCRIPTION This function flushes all cached data to disk and, if INVALIDATE is non-zero, removes cached objects from the cache so they must be @@ -751,6 +841,10 @@ H5Fflush (hatom_t fid, hbool_t invalidate) * file boot block. If the logical file size field is zero * then it is updated to be the length of the boot block. * + * Errors: + * CACHE CANTFLUSH Can't flush cache. + * IO WRITEERROR Can't write header. + * * Return: Success: SUCCEED * * Failure: FAIL @@ -812,13 +906,22 @@ H5F_flush (hdf5_file_t *f, hbool_t invalidate) /*-------------------------------------------------------------------------- NAME H5Fclose + PURPOSE Close an open HDF5 file. + USAGE int32 H5Fclose(fid) int32 fid; IN: File ID of file to close + + ERRORS + ARGS BADTYPE Not a file atom. + ATOM BADATOM Can't remove atom. + ATOM BADATOM Can't unatomize file. + RETURNS SUCCEED/FAIL + DESCRIPTION This function terminates access to an HDF5 file. If this is the last file ID open for a file and if access IDs are still in use, this function @@ -842,11 +945,11 @@ herr_t H5Fclose(hatom_t fid) /* Clear errors and check args and all the boring stuff. */ H5ECLEAR; if(H5Aatom_group(fid)!=H5_FILE) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL); + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL);/*not a file atom*/ /* Get the file handle to close */ if((file=H5Aatom_object(fid))==NULL) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);/*can't unatomize file*/ /* Decrement the ref. count and recycle the file structure */ if((--file->ref_count)==0) @@ -857,7 +960,7 @@ herr_t H5Fclose(hatom_t fid) } H5F_dest (file); if(H5Aremove_atom(fid)==NULL) { - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);/*can't remove atom*/ } } /* end if */ @@ -878,6 +981,10 @@ done: * Purpose: Reads some data from a file/server/etc into a buffer. * The data is contiguous. * + * Errors: + * IO READERROR Low-level read failure. + * IO SEEKERROR Low-level seek failure. + * * Return: Success: SUCCEED * * Failure: FAIL @@ -899,9 +1006,11 @@ H5F_block_read (hdf5_file_t *f, haddr_t addr, size_t size, void *buf) addr += f->file_create_parms.userblock_size; if (H5F_SEEK (f->file_handle, addr)<0) { + /* low-level seek failure */ HRETURN_ERROR (H5E_IO, H5E_SEEKERROR, FAIL); } if (H5F_READ (f->file_handle, buf, size)<0) { + /* low-level read failure */ HRETURN_ERROR (H5E_IO, H5E_READERROR, FAIL); } @@ -915,6 +1024,10 @@ H5F_block_read (hdf5_file_t *f, haddr_t addr, size_t size, void *buf) * Purpose: Writes some data from memory to a file/server/etc. The * data is contiguous. * + * Errors: + * IO SEEKERROR Low-level seek failure. + * IO WRITEERROR Low-level write failure. + * * Return: Success: SUCCEED * * Failure: FAIL @@ -936,9 +1049,11 @@ H5F_block_write (hdf5_file_t *f, haddr_t addr, size_t size, void *buf) addr += f->file_create_parms.userblock_size; if (H5F_SEEK (f->file_handle, addr)<0) { + /* low-level seek failure */ HRETURN_ERROR (H5E_IO, H5E_SEEKERROR, FAIL); } if (H5F_WRITE (f->file_handle, buf, size)<0) { + /* low-level write failure */ HRETURN_ERROR (H5E_IO, H5E_WRITEERROR, FAIL); } @@ -953,6 +1068,8 @@ H5F_block_write (hdf5_file_t *f, haddr_t addr, size_t size, void *buf) * is indented and the field name occupies the specified width * number of characters. * + * Errors: + * * Return: Success: SUCCEED * * Failure: FAIL @@ -25,6 +25,9 @@ * Robb Matzke, 5 Aug 1997 * Added calls to H5E. * + * Robb Matzke, 30 Aug 1997 + * Added `Errors:' field to function prologues. + * *------------------------------------------------------------------------- */ @@ -54,6 +57,8 @@ static intn interface_initialize_g = FALSE; * the size in characters of the component through SIZE_P not * counting leading slashes or the null terminator. * + * Errors: + * * Return: Success: Ptr into NAME. * * Failure: Ptr to the null terminator of NAME. @@ -72,7 +77,7 @@ H5G_component (const char *name, size_t *size_p) assert (name); while ('/'==*name) name++; - if (size_p) *size_p = strcspn (name, "/"); + if (size_p) *size_p = HDstrcspn (name, "/"); return name; } @@ -85,6 +90,8 @@ H5G_component (const char *name, size_t *size_p) * initialized to point to the size of the base name not * counting trailing slashes or the null character. * + * Errors: + * * Return: Success: Ptr to base name within NAME with SIZE_P * pointing to the number of characters in the * base name. @@ -120,7 +127,7 @@ H5G_basename (const char *name, size_t *size_p) return s + HDstrlen(s); /*null terminator*/ } - if (size_p) *size_p = strcspn (s, "/"); + if (size_p) *size_p = HDstrcspn (s, "/"); return s; } #endif @@ -166,6 +173,11 @@ H5G_basename (const char *name, size_t *size_p) * is initialized with the contents of the root symbol table * entry. * + * Errors: + * DIRECTORY COMPLEN Component is too long. + * DIRECTORY NOTFOUND Component not found. + * DIRECTORY NOTFOUND Root not found. + * * Return: Success: SUCCEED if the name can be fully * resolved. * @@ -229,7 +241,7 @@ H5G_namei (hdf5_file_t *f, H5G_entry_t *cwd, const char *name, * we can pass it down to the other symbol table functions. */ if (nchars+1 > sizeof(comp)) { - /* component name is too long */ + /* component is too long */ if (dir_ent) *dir_ent = *dir; HRETURN_ERROR (H5E_DIRECTORY, H5E_COMPLEN, -2); } @@ -247,7 +259,7 @@ H5G_namei (hdf5_file_t *f, H5G_entry_t *cwd, const char *name, H5O_name_t mesg; if (!aside && dir->header==f->root_sym->header && H5O_read (f, dir->header, dir, H5O_NAME, 0, &mesg)) { - if (!strcmp (mesg.s, comp)) { + if (!HDstrcmp (mesg.s, comp)) { H5O_reset (H5O_NAME, &mesg); *base = *dir; aside = TRUE; @@ -295,6 +307,12 @@ H5G_namei (hdf5_file_t *f, H5G_entry_t *cwd, const char *name, * is removed). If the root object doesn't have a name message * then the name `Root Object' is used. * + * Errors: + * DIRECTORY CANTINIT Can't create root. + * DIRECTORY CANTINIT Can't insert old root object in + * new root directory. + * DIRECTORY EXISTS Root directory already exists. + * * Return: Success: SUCCEED * * Failure: FAIL @@ -305,7 +323,8 @@ H5G_namei (hdf5_file_t *f, H5G_entry_t *cwd, const char *name, * * Modifications: * - *------------------------------------------------------------------------- */ + *------------------------------------------------------------------------- + */ static herr_t H5G_mkroot (hdf5_file_t *f, size_t size_hint) { @@ -349,7 +368,7 @@ H5G_mkroot (hdf5_file_t *f, size_t size_hint) */ if (H5G_stab_new (f, f->root_sym, size_hint)<0) { H5O_reset (H5O_NAME, &name); - HRETURN_ERROR (H5E_DIRECTORY, H5E_CANTINIT, FAIL); /*can't create dir*/ + HRETURN_ERROR (H5E_DIRECTORY, H5E_CANTINIT, FAIL); /*can't create root*/ } /* @@ -396,6 +415,14 @@ H5G_mkroot (hdf5_file_t *f, size_t size_hint) * (or any equivalent name) will result in an H5E_EXISTS * failure. * + * Errors: + * DIRECTORY CANTINIT Can't create dir. + * DIRECTORY CANTINIT Can't insert. + * DIRECTORY CANTINIT Lookup failed. + * DIRECTORY COMPLEN Component is too long. + * DIRECTORY EXISTS Already exists. + * DIRECTORY NOTFOUND Missing component. + * * Return: Success: SUCCEED, if DIR_ENT is not the null pointer * then it will be initialized with the * symbol table entry for the new directory. @@ -451,7 +478,7 @@ H5G_new (hdf5_file_t *f, H5G_entry_t *cwd, H5G_entry_t *dir_ent, /* missing component */ HRETURN_ERROR (H5E_DIRECTORY, H5E_NOTFOUND, FAIL); } else if (nchars+1 > sizeof _comp) { - /* component name is too long */ + /* component is too long */ HRETURN_ERROR (H5E_DIRECTORY, H5E_COMPLEN, FAIL); } else { /* null terminate */ @@ -492,6 +519,9 @@ H5G_new (hdf5_file_t *f, H5G_entry_t *cwd, H5G_entry_t *dir_ent, * This function will fail if the root object is * requested and there is none. * + * Errors: + * DIRECTORY NOTFOUND Object not found. + * * Return: Success: SUCCEED with DIR_ENT and ENT initialized. * * Failure: FAIL @@ -502,7 +532,8 @@ H5G_new (hdf5_file_t *f, H5G_entry_t *cwd, H5G_entry_t *dir_ent, * * Modifications: * - *------------------------------------------------------------------------- */ + *------------------------------------------------------------------------- + */ herr_t H5G_find (hdf5_file_t *f, H5G_entry_t *cwd, H5G_entry_t *dir_ent, const char *name, H5G_entry_t *ent) @@ -543,6 +574,17 @@ H5G_find (hdf5_file_t *f, H5G_entry_t *cwd, H5G_entry_t *dir_ent, * Inserting an object entry into the symbol table increments * the link counter for that object. * + * Errors: + * DIRECTORY CANTINIT Can't insert. + * DIRECTORY CANTINIT Cannot add/change name message. + * DIRECTORY CANTINIT Lookup failed. + * DIRECTORY COMPLEN Component is too long. + * DIRECTORY EXISTS Already exists. + * DIRECTORY EXISTS Root exists. + * DIRECTORY LINK Bad link count. + * DIRECTORY LINK Link inc failure. + * DIRECTORY NOTFOUND Component not found. + * * Return: Success: SUCCEED with optional DIR_ENT initialized with * the symbol table entry for the directory * which contains the new ENT. @@ -555,7 +597,8 @@ H5G_find (hdf5_file_t *f, H5G_entry_t *cwd, H5G_entry_t *dir_ent, * * Modifications: * - *------------------------------------------------------------------------- */ + *------------------------------------------------------------------------- + */ herr_t H5G_insert (hdf5_file_t *f, H5G_entry_t *cwd, H5G_entry_t *dir_ent, const char *name, H5G_entry_t *ent) @@ -623,10 +666,10 @@ H5G_insert (hdf5_file_t *f, H5G_entry_t *cwd, H5G_entry_t *dir_ent, */ if (rest[nchars]) { if (H5G_component (rest+nchars, NULL)) { - /* name component not found */ + /* component not found */ HRETURN_ERROR (H5E_DIRECTORY, H5E_NOTFOUND, FAIL); } else if (nchars+1 > sizeof _comp) { - /* name component is too long */ + /* component is too long */ HRETURN_ERROR (H5E_DIRECTORY, H5E_COMPLEN, FAIL); } else { /* null terminate */ @@ -686,6 +729,10 @@ H5G_insert (hdf5_file_t *f, H5G_entry_t *cwd, H5G_entry_t *dir_ent, * symbol since that's a special case. This function returns * failure if that is attempted. * + * Errors: + * DIRECTORY CANTINIT Can't modify. + * DIRECTORY NOTFOUND Entry not found. + * * Return: Success: SUCCEED with optional DIR_ENT initialized with * the symbol table entry for the directory * which contains the new ENT. @@ -746,6 +793,16 @@ H5G_modify (hdf5_file_t *f, H5G_entry_t *cwd, H5G_entry_t *dir_ent, * item in the heap is the empty string, and must appear at * heap offset zero. * + * Errors: + * INTERNAL CANTINIT B-tree's won't work if the first + * name isn't at the beginning of the + * heap. + * SYM CANTINIT Can't create B-tree. + * SYM CANTINIT Can't create header. + * SYM CANTINIT Can't create heap. + * SYM CANTINIT Can't create message. + * SYM CANTINIT Can't initialize heap. + * * Return: Success: Address of new symbol table header. If * the caller supplies a symbol table entry * SELF then it will be initialized to point to @@ -778,10 +835,10 @@ H5G_stab_new (hdf5_file_t *f, H5G_entry_t *self, size_t init) /* Create symbol table private heap */ if ((stab.heap = H5H_new (f, H5H_LOCAL, init))<0) { - HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); + HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); /*can't create heap*/ } if ((name = H5H_insert (f, stab.heap, 1, "")<0)) { - HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); + HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); /*can't initialize heap*/ } if (0!=name) { /* @@ -793,7 +850,7 @@ H5G_stab_new (hdf5_file_t *f, H5G_entry_t *self, size_t init) /* Create the B-tree */ if ((stab.btree = H5B_new (f, H5B_SNODE))<0) { - HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); + HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); /*can't create B-tree*/ } /* @@ -802,7 +859,7 @@ H5G_stab_new (hdf5_file_t *f, H5G_entry_t *self, size_t init) * incremented if the object is added to the directory hierarchy. */ if ((addr = H5O_new (f, 0, 4+2*H5F_SIZEOF_OFFSET(f)))<0) { - HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); + HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); /*can't create header*/ } /* insert the symbol table message */ @@ -812,7 +869,7 @@ H5G_stab_new (hdf5_file_t *f, H5G_entry_t *self, size_t init) self->type = H5G_NOTHING_CACHED; } if (H5O_modify(f, addr, self, NULL, H5O_STAB, H5O_NEW_MESG, &stab)<0) { - HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); + HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); /*can't create message*/ } FUNC_LEAVE (addr); @@ -826,6 +883,10 @@ H5G_stab_new (hdf5_file_t *f, H5G_entry_t *self, size_t init) * description is stored in SELF in file F and returns a * copy of the symbol table entry through the ENT argument. * + * Errors: + * SYM BADMESG Can't read message. + * SYM NOTFOUND Not found. + * * Return: Success: Address corresponding to the name. * * Failure: FAIL @@ -854,7 +915,7 @@ H5G_stab_find (hdf5_file_t *f, H5G_entry_t *self, const char *name, /* set up the udata */ if (NULL==H5O_read (f, self->header, self, H5O_STAB, 0, &stab)) { - HRETURN_ERROR (H5E_SYM, H5E_BADMESG, FAIL); + HRETURN_ERROR (H5E_SYM, H5E_BADMESG, FAIL); /*can't read message*/ } udata.operation = H5G_OPER_FIND; udata.name = name; @@ -862,7 +923,7 @@ H5G_stab_find (hdf5_file_t *f, H5G_entry_t *self, const char *name, /* search the B-tree */ if (H5B_find (f, H5B_SNODE, stab.btree, &udata)<0) { - HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL); + HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL); /*not found*/ } /* return the result */ @@ -879,6 +940,10 @@ H5G_stab_find (hdf5_file_t *f, H5G_entry_t *self, const char *name, * file F. ENT is the new symbol table entry to use for the * symbol. * + * Errors: + * SYM BADMESG Can't read message. + * SYM NOTFOUND Not found. + * * Return: Success: SUCCEED * * Failure: FAIL @@ -908,7 +973,7 @@ H5G_stab_modify (hdf5_file_t *f, H5G_entry_t *self, const char *name, /* set up the udata */ if (NULL==H5O_read (f, self->header, self, H5O_STAB, 0, &stab)) { - HRETURN_ERROR (H5E_SYM, H5E_BADMESG, FAIL); + HRETURN_ERROR (H5E_SYM, H5E_BADMESG, FAIL); /*can't read message*/ } udata.operation = H5G_OPER_MODIFY; udata.name = name; @@ -917,7 +982,7 @@ H5G_stab_modify (hdf5_file_t *f, H5G_entry_t *self, const char *name, /* search and modify the B-tree */ if (H5B_find (f, H5B_SNODE, stab.btree, &udata)<0) { - HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL); + HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL); /*not found*/ } FUNC_LEAVE (SUCCEED); @@ -931,6 +996,10 @@ H5G_stab_modify (hdf5_file_t *f, H5G_entry_t *self, const char *name, * file F. The name of the new symbol is NAME and its symbol * table entry is ENT. * + * Errors: + * SYM BADMESG Can't read message. + * SYM CANTINSERT Can't insert entry. + * * Return: Success: SUCCEED * * Failure: FAIL @@ -960,7 +1029,7 @@ H5G_stab_insert (hdf5_file_t *f, H5G_entry_t *self, const char *name, /* initialize data to pass through B-tree */ if (NULL==H5O_read (f, self->header, self, H5O_STAB, 0, &stab)) { - HRETURN_ERROR (H5E_SYM, H5E_BADMESG, FAIL); + HRETURN_ERROR (H5E_SYM, H5E_BADMESG, FAIL); /*can't read message*/ } udata.name = name; udata.heap = stab.heap; @@ -968,7 +1037,7 @@ H5G_stab_insert (hdf5_file_t *f, H5G_entry_t *self, const char *name, /* insert */ if (H5B_insert (f, H5B_SNODE, stab.btree, &udata)<0) { - HRETURN_ERROR (H5E_SYM, H5E_CANTINSERT, FAIL); + HRETURN_ERROR (H5E_SYM, H5E_CANTINSERT, FAIL); /*can't insert entry*/ } /* update the name offset in the entry */ @@ -987,6 +1056,10 @@ H5G_stab_insert (hdf5_file_t *f, H5G_entry_t *self, const char *name, * be filled in with data from the symbol table. Each of these * arrays should have at least MAXENTRIES elements. * + * Errors: + * SYM BADMESG Not a symbol table. + * SYM CANTLIST B-tree list failure. + * * Return: Success: The total number of symbols in the * symbol table. This may exceed MAXENTRIES, * but at most MAXENTRIES values are copied @@ -1021,7 +1094,7 @@ H5G_stab_list (hdf5_file_t *f, H5G_entry_t *self, intn maxentries, /* initialize data to pass through B-tree */ if (NULL==H5O_read (f, self->header, self, H5O_STAB, 0, &stab)) { - HRETURN_ERROR (H5E_SYM, H5E_BADMESG, FAIL); + HRETURN_ERROR (H5E_SYM, H5E_BADMESG, FAIL); /*not a symbol table*/ } udata.entry = entries; udata.name = names; @@ -1035,7 +1108,7 @@ H5G_stab_list (hdf5_file_t *f, H5G_entry_t *self, intn maxentries, if (names) { for (i=0; i<maxentries; i++) H5MM_xfree (names[i]); } - HRETURN_ERROR (H5E_SYM, H5E_CANTLIST, FAIL); + HRETURN_ERROR (H5E_SYM, H5E_CANTLIST, FAIL); /*B-tree list failure*/ } FUNC_LEAVE (udata.nsyms); @@ -1048,6 +1121,9 @@ H5G_stab_list (hdf5_file_t *f, H5G_entry_t *self, intn maxentries, * Purpose: Same as H5G_decode() except it does it for an array of * symbol table entries. * + * Errors: + * SYM CANTDECODE Can't decode. + * * Return: Success: SUCCEED, with *pp pointing to the first byte * after the last symbol. * @@ -1077,7 +1153,7 @@ H5G_decode_vec (hdf5_file_t *f, uint8 **pp, H5G_entry_t *ent, intn n) /* decode entries */ for (i=0; i<n; i++) { if (H5G_decode (f, pp, ent+i)<0) { - HRETURN_ERROR (H5E_SYM, H5E_CANTDECODE, FAIL); + HRETURN_ERROR (H5E_SYM, H5E_CANTDECODE, FAIL); /*can't decode*/ } } @@ -1090,6 +1166,8 @@ H5G_decode_vec (hdf5_file_t *f, uint8 **pp, H5G_entry_t *ent, intn n) * * Purpose: Decodes a symbol table entry pointed to by `*pp'. * + * Errors: + * * Return: Success: SUCCEED with *pp pointing to the first byte * following the symbol table entry. * @@ -1156,6 +1234,9 @@ H5G_decode (hdf5_file_t *f, uint8 **pp, H5G_entry_t *ent) * Purpose: Same as H5G_encode() except it does it for an array of * symbol table entries. * + * Errors: + * SYM CANTENCODE Can't encode. + * * Return: Success: SUCCEED, with *pp pointing to the first byte * after the last symbol. * @@ -1185,7 +1266,7 @@ H5G_encode_vec (hdf5_file_t *f, uint8 **pp, H5G_entry_t *ent, intn n) /* encode entries */ for (i=0; i<n; i++) { if (H5G_encode (f, pp, ent+i)<0) { - HRETURN_ERROR (H5E_SYM, H5E_CANTENCODE, FAIL); + HRETURN_ERROR (H5E_SYM, H5E_CANTENCODE, FAIL); /*can't encode*/ } } @@ -1199,6 +1280,8 @@ H5G_encode_vec (hdf5_file_t *f, uint8 **pp, H5G_entry_t *ent, intn n) * Purpose: Encodes the specified symbol table entry into the buffer * pointed to by *pp. * + * Errors: + * * Return: Success: SUCCEED, with *pp pointing to the first byte * after the symbol table entry. * @@ -1271,6 +1354,8 @@ H5G_encode (hdf5_file_t *f, uint8 **pp, H5G_entry_t *ent) * * Purpose: Prints debugging information about a symbol table entry. * + * Errors: + * * Return: Success: SUCCEED * * Failure: FAIL @@ -923,7 +923,7 @@ H5H_debug (hdf5_file_t *f, haddr_t addr, FILE *stream, intn indent, } else { fprintf (stream, " "); } - if (7==j) fputc (' ', stream); + if (7==j) HDfputc (' ', stream); } for (j=0; j<16; j++) { @@ -938,7 +938,7 @@ H5H_debug (hdf5_file_t *f, haddr_t addr, FILE *stream, intn indent, } } - fputc ('\n', stream); + HDfputc ('\n', stream); } H5MM_xfree (marker); @@ -233,7 +233,7 @@ hatom_t H5Mcreate(hatom_t owner_id, hobjtype_t type, const char *name) i=H5M_find_type(type); if(meta_func_arr[i].create==NULL) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - ret_value=meta_func_arr[i].create(owner_id,type,name); + ret_value=(meta_func_arr[i].create)(owner_id,type,name); done: if(ret_value == FAIL) @@ -276,7 +276,7 @@ hatom_t H5Maccess(hatom_t oid) i=H5M_find_type(group); if(meta_func_arr[i].access==NULL) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - ret_value=meta_func_arr[i].access(oid); + ret_value=(meta_func_arr[i].access)(oid); done: if(ret_value == FAIL) @@ -319,7 +319,7 @@ hatom_t H5Mcopy(hatom_t oid) i=H5M_find_type(group); if(meta_func_arr[i].copy==NULL) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - ret_value=meta_func_arr[i].copy(oid); + ret_value=(meta_func_arr[i].copy)(oid); done: if(ret_value == FAIL) @@ -364,7 +364,7 @@ hatom_t H5Mfind_name(hatom_t owner_id, hobjtype_t type, const char *name) i=H5M_find_type(group); if(meta_func_arr[i].find_name==NULL) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - ret_value=meta_func_arr[i].find_name(owner_id,type,name); + ret_value=(meta_func_arr[i].find_name)(owner_id,type,name); done: if(ret_value == FAIL) @@ -407,7 +407,7 @@ uint32 H5Mname_len(hatom_t oid) i=H5M_find_type(group); if(meta_func_arr[i].name_len==NULL) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - ret_value=meta_func_arr[i].name_len(oid); + ret_value=(meta_func_arr[i].name_len)(oid); done: if(ret_value == FAIL) @@ -451,7 +451,7 @@ herr_t H5Mget_name(hatom_t oid, char *name) i=H5M_find_type(group); if(meta_func_arr[i].get_name==NULL) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - ret_value=meta_func_arr[i].get_name(oid,name); + ret_value=(meta_func_arr[i].get_name)(oid,name); done: if(ret_value == FAIL) @@ -495,7 +495,7 @@ herr_t H5Mset_name(hatom_t oid, const char *name) i=H5M_find_type(group); if(meta_func_arr[i].set_name==NULL) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - ret_value=meta_func_arr[i].set_name(oid,name); + ret_value=(meta_func_arr[i].set_name)(oid,name); done: if(ret_value == FAIL) @@ -540,7 +540,7 @@ hatom_t H5Msearch(hatom_t oid, hobjtype_t type, const char *name) i=H5M_find_type(group); if(meta_func_arr[i].search==NULL) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - ret_value=meta_func_arr[i].search(oid,type,name); + ret_value=(meta_func_arr[i].search)(oid,type,name); done: if(ret_value == FAIL) @@ -585,7 +585,7 @@ hatom_t H5Mindex(hatom_t oid, hobjtype_t type, uint32 idx) i=H5M_find_type(group); if(meta_func_arr[i].index==NULL) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - ret_value=meta_func_arr[i].index(oid,type,idx); + ret_value=(meta_func_arr[i].index)(oid,type,idx); done: if(ret_value == FAIL) @@ -628,7 +628,7 @@ hatom_t H5Mflush(hatom_t oid) i=H5M_find_type(group); if(meta_func_arr[i].flush==NULL) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - ret_value=meta_func_arr[i].flush(oid); + ret_value=(meta_func_arr[i].flush)(oid); done: if(ret_value == FAIL) @@ -672,7 +672,7 @@ herr_t H5Mdelete(hatom_t oid) i=H5M_find_type(group); if(meta_func_arr[i].delete==NULL) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - ret_value=meta_func_arr[i].delete(oid); + ret_value=(meta_func_arr[i].delete)(oid); done: if(ret_value == FAIL) @@ -715,7 +715,7 @@ hatom_t H5Mget_parent(hatom_t oid) i=H5M_find_type(group); if(meta_func_arr[i].get_parent==NULL) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - ret_value=meta_func_arr[i].get_parent(oid); + ret_value=(meta_func_arr[i].get_parent)(oid); done: if(ret_value == FAIL) @@ -758,7 +758,7 @@ hatom_t H5Mget_file(hatom_t oid) i=H5M_find_type(group); if(meta_func_arr[i].get_file==NULL) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - ret_value=meta_func_arr[i].get_file(oid); + ret_value=(meta_func_arr[i].get_file)(oid); done: if(ret_value == FAIL) @@ -801,7 +801,7 @@ herr_t H5Mrelease(hatom_t oid) i=H5M_find_type(group); if(meta_func_arr[i].release==NULL) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - ret_value=meta_func_arr[i].release(oid); + ret_value=(meta_func_arr[i].release)(oid); done: if(ret_value == FAIL) @@ -166,7 +166,7 @@ H5MM_xstrdup (const char *s) *------------------------------------------------------------------------- */ void * -H5MM_xfree (void *mem) +H5MM_xfree (const void *mem) { if (mem) HDfree (mem); return NULL; diff --git a/src/H5MMprivate.h b/src/H5MMprivate.h index 73ff121..7e95d70 100644 --- a/src/H5MMprivate.h +++ b/src/H5MMprivate.h @@ -28,7 +28,7 @@ void *H5MM_xmalloc (size_t size); void *H5MM_xcalloc (size_t n, size_t size); void *H5MM_xrealloc (void *mem, size_t size); char *H5MM_xstrdup (const char *s); -void *H5MM_xfree (void *mem); +void *H5MM_xfree (const void *mem); #endif @@ -160,12 +160,16 @@ H5O_new (hdf5_file_t *f, intn nlink, size_t size_hint) * * Modifications: * + * Robb Matzke, 30 Aug 1997 + * Plugged memory leaks that occur during error handling. + * *------------------------------------------------------------------------- */ static H5O_t * H5O_load (hdf5_file_t *f, haddr_t addr, const void *_data) { H5O_t *oh = NULL; + H5O_t *ret_value = (void*)SUCCEED; /*kludge for HGOTO_ERROR*/ uint8 buf[16], *p; size_t hdr_size, mesg_size; uintn id; @@ -173,7 +177,7 @@ H5O_load (hdf5_file_t *f, haddr_t addr, const void *_data) haddr_t chunk_addr; size_t chunk_size; H5O_cont_t *cont=NULL; - + FUNC_ENTER (H5O_load, NULL, NULL); /* check args */ @@ -187,20 +191,20 @@ H5O_load (hdf5_file_t *f, haddr_t addr, const void *_data) /* read fixed-lenth part of object header */ hdr_size = H5O_SIZEOF_HDR (f); if (H5F_block_read (f, addr, hdr_size, buf)<0) { - HRETURN_ERROR (H5E_OHDR, H5E_READERROR, NULL); + HGOTO_ERROR (H5E_OHDR, H5E_READERROR, NULL); } p = buf; /* decode version */ oh->version = *p++; if (H5O_VERSION!=oh->version) { - HRETURN_ERROR (H5E_OHDR, H5E_VERSION, NULL); + HGOTO_ERROR (H5E_OHDR, H5E_VERSION, NULL); } /* decode alignment */ oh->alignment = *p++; if (4!=oh->alignment) { - HRETURN_ERROR (H5E_OHDR, H5E_ALIGNMENT, NULL); + HGOTO_ERROR (H5E_OHDR, H5E_ALIGNMENT, NULL); } /* decode number of messages */ @@ -235,7 +239,7 @@ H5O_load (hdf5_file_t *f, haddr_t addr, const void *_data) oh->chunk[chunkno].image = H5MM_xmalloc (chunk_size); if (H5F_block_read (f, chunk_addr, chunk_size, oh->chunk[chunkno].image)<0) { - HRETURN_ERROR (H5E_OHDR, H5E_READERROR, NULL); + HGOTO_ERROR (H5E_OHDR, H5E_READERROR, NULL); } @@ -247,10 +251,10 @@ H5O_load (hdf5_file_t *f, haddr_t addr, const void *_data) UINT16DECODE (p, mesg_size); if (id>=NELMTS(message_type_g) || NULL==message_type_g[id]) { - HRETURN_ERROR (H5E_OHDR, H5E_BADMESG, NULL); + HGOTO_ERROR (H5E_OHDR, H5E_BADMESG, NULL); } if (p + mesg_size > oh->chunk[chunkno].image + chunk_size) { - HRETURN_ERROR (H5E_OHDR, H5E_CANTINIT, NULL); + HGOTO_ERROR (H5E_OHDR, H5E_CANTINIT, NULL); } if (H5O_NULL_ID==id && oh->nmesgs>0 && @@ -261,10 +265,10 @@ H5O_load (hdf5_file_t *f, haddr_t addr, const void *_data) oh->mesg[mesgno].raw_size += 4 + mesg_size; } else { /* new message */ - mesgno = oh->nmesgs++; - if (mesgno>=nmesgs) { - HRETURN_ERROR (H5E_OHDR, H5E_CANTLOAD, NULL); + if (oh->nmesgs>=nmesgs) { + HGOTO_ERROR (H5E_OHDR, H5E_CANTLOAD, NULL); } + mesgno = oh->nmesgs++; oh->mesg[mesgno].type = message_type_g[id]; oh->mesg[mesgno].dirty = FALSE; oh->mesg[mesgno].native = NULL; @@ -288,6 +292,20 @@ H5O_load (hdf5_file_t *f, haddr_t addr, const void *_data) } } +done: + if (!ret_value && oh) { + /* + * Free resources. + */ + int i; + for (i=0; i<oh->nchunks; i++) { + oh->chunk[i].image = H5MM_xfree (oh->chunk[i].image); + } + oh->chunk = H5MM_xfree (oh->chunk); + oh->mesg = H5MM_xfree (oh->mesg); + oh = H5MM_xfree (oh); + } + FUNC_LEAVE (oh); } diff --git a/src/H5Oname.c b/src/H5Oname.c index 47d5669..5631887 100644 --- a/src/H5Oname.c +++ b/src/H5Oname.c @@ -72,6 +72,7 @@ static void * H5O_name_decode (hdf5_file_t *f, size_t raw_size, const uint8 *p) { H5O_name_t *mesg; + char *s; FUNC_ENTER (H5O_name_decode, NULL, NULL); @@ -81,8 +82,9 @@ H5O_name_decode (hdf5_file_t *f, size_t raw_size, const uint8 *p) /* decode */ mesg = H5MM_xcalloc (1, sizeof(H5O_name_t)); - mesg->s = H5MM_xmalloc (raw_size); - HDmemcpy (mesg->s, p, raw_size); + s = H5MM_xmalloc (raw_size); + HDmemcpy (s, p, raw_size); + mesg->s = s; FUNC_LEAVE (mesg); } @@ -119,7 +121,7 @@ H5O_name_encode (hdf5_file_t *f, size_t raw_size, uint8 *p, const void *_mesg) assert (mesg && mesg->s); /* message size */ - size = strlen (mesg->s)+1; + size = HDstrlen (mesg->s)+1; assert (size<=raw_size); /* encode */ diff --git a/src/debug.c b/src/debug.c index b21a0c8..e6a0740 100644 --- a/src/debug.c +++ b/src/debug.c @@ -58,10 +58,10 @@ main (int argc, char *argv[]) */ if (argc>2) { printf ("New address: %s\n", argv[2]); - addr = strtol (argv[2], NULL, 0); + addr = HDstrtol (argv[2], NULL, 0); } if (argc>3) { - extra = strtol (argv[3], NULL, 0); + extra = HDstrtol (argv[3], NULL, 0); } /* @@ -69,11 +69,11 @@ main (int argc, char *argv[]) */ if ((fid = H5Fopen (argv[1], 0, 0))<0) { fprintf (stderr, "cannot open file\n"); - exit (1); + HDexit (1); } if (NULL==(f=H5Aatom_object (fid))) { fprintf (stderr, "cannot obtain hdf5_file_t pointer\n"); - exit (2); + HDexit (2); } /* @@ -82,28 +82,28 @@ main (int argc, char *argv[]) printf ("Reading signature at byte %lu\n", (unsigned long)addr); if (H5F_block_read (f, addr, sizeof(sig), sig)<0) { fprintf (stderr, "cannot read signature\n"); - exit (3); + HDexit (3); } - if (!memcmp (sig, H5F_SIGNATURE, H5F_SIGNATURE_LEN)) { + if (!HDmemcmp (sig, H5F_SIGNATURE, H5F_SIGNATURE_LEN)) { /* * Debug the boot block. */ status = H5F_debug (f, 0, stdout, 0, VCOL); - } else if (!memcmp (sig, H5H_MAGIC, H5H_SIZEOF_MAGIC)) { + } else if (!HDmemcmp (sig, H5H_MAGIC, H5H_SIZEOF_MAGIC)) { /* * Debug a heap. */ status = H5H_debug (f, addr, stdout, 0, VCOL); - } else if (!memcmp (sig, H5G_NODE_MAGIC, H5G_NODE_SIZEOF_MAGIC)) { + } else if (!HDmemcmp (sig, H5G_NODE_MAGIC, H5G_NODE_SIZEOF_MAGIC)) { /* * Debug a symbol table node. */ status = H5G_node_debug (f, addr, stdout, 0, VCOL, extra); - } else if (!memcmp (sig, H5B_MAGIC, H5B_SIZEOF_MAGIC)) { + } else if (!HDmemcmp (sig, H5B_MAGIC, H5B_SIZEOF_MAGIC)) { /* * Debug a B-tree. B-trees are debugged through the B-tree * subclass. The subclass identifier is the byte immediately @@ -117,7 +117,7 @@ main (int argc, char *argv[]) default: fprintf (stderr, "Unknown B-tree subtype %u\n", (unsigned)(subtype)); - exit (4); + HDexit (4); } } else if (sig[0]==H5O_VERSION && sig[1]==H5O_ALIGNMENT) { @@ -134,25 +134,25 @@ main (int argc, char *argv[]) printf ("%-*s ", VCOL, "Signature:"); for (i=0; i<8; i++) { if (sig[i]>' ' && sig[i]<='~' && '\\'!=sig[i]) { - putchar (sig[i]); + HDputchar (sig[i]); } else if ('\\'==sig[i]) { - putchar ('\\'); - putchar ('\\'); + HDputchar ('\\'); + HDputchar ('\\'); } else { printf ("\\%03o", sig[i]); } } - putchar ('\n'); + HDputchar ('\n'); fprintf (stderr, "unknown signature\n"); - exit (4); + HDexit (4); } if (status<0) { fprintf (stderr, "An error occurred\n"); - exit (5); + HDexit (5); } H5Fclose (fid); - exit (0); + HDexit (0); } |