diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2004-06-14 19:33:08 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2004-06-14 19:33:08 (GMT) |
commit | ffbd43d88b496f1ee745aaeb5fd6d2117f510b82 (patch) | |
tree | c2c273eff29abf9a62be4ba9ceb48cedfa053719 /src/H5FDmulti.c | |
parent | 3247aa351eb300b408e64be3a0b81910374d1327 (diff) | |
download | hdf5-ffbd43d88b496f1ee745aaeb5fd6d2117f510b82.zip hdf5-ffbd43d88b496f1ee745aaeb5fd6d2117f510b82.tar.gz hdf5-ffbd43d88b496f1ee745aaeb5fd6d2117f510b82.tar.bz2 |
[svn-r8684] Purpose:
Code optimization
Description:
Use 'size_t' instead of 'hsize_t' to track the number of elements in
memory buffers, especially for type conversion.
Platforms tested:
Solaris 2.7 (arabica)
FreeBSD 4.10 (sleipnir) w/parallel
Too minor to require h5committest
Diffstat (limited to 'src/H5FDmulti.c')
-rw-r--r-- | src/H5FDmulti.c | 129 |
1 files changed, 65 insertions, 64 deletions
diff --git a/src/H5FDmulti.c b/src/H5FDmulti.c index 3f089a6..186d1af 100644 --- a/src/H5FDmulti.c +++ b/src/H5FDmulti.c @@ -26,6 +26,12 @@ #include <assert.h> #include <stdlib.h> +/* Disable certain warnings in PC-Lint: */ +/*lint --emacro( {534, 830}, H5P_DEFAULT, H5P_FILE_ACCESS, H5P_DATASET_XFER) */ +/*lint --emacro( {534, 830}, H5F_ACC_DEBUG, H5F_ACC_RDWR) */ +/*lint --emacro( {534, 830}, H5FD_MULTI) */ +/*lint -esym( 534, H5Eclear, H5Epush) */ + #include "hdf5.h" /* @@ -35,17 +41,15 @@ */ #define H5FD_MULTI_DEBUG -/* Our versions of MIN and MAX */ +/* Our version of MAX */ #undef MAX #define MAX(X,Y) ((X)>(Y)?(X):(Y)) -#undef MIN -#define MIN(X,Y) ((X)<(Y)?(X):(Y)) #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE -#define TRUE (!FALSE) +#define TRUE 1 #endif /* Loop through all mapped files */ @@ -60,6 +64,7 @@ assert(LOOPVAR>0 && LOOPVAR<H5FD_MEM_NTYPES); \ if (_seen[LOOPVAR]++) continue; +#ifdef LATER #define MAPPED_MEMBERS(MAP,LOOPVAR) { \ H5FD_mem_t _unmapped, LOOPVAR; \ \ @@ -67,6 +72,7 @@ LOOPVAR = MAP[_unmapped]; \ if (H5FD_MEM_DEFAULT==LOOPVAR) LOOPVAR=_unmapped; \ assert(LOOPVAR>0 && LOOPVAR<H5FD_MEM_NTYPES); +#endif /* LATER */ #define ALL_MEMBERS(LOOPVAR) { \ H5FD_mem_t LOOPVAR; \ @@ -312,8 +318,7 @@ H5Pset_fapl_split(hid_t fapl, const char *meta_ext, hid_t meta_plist_id, memb_addr[H5FD_MEM_SUPER] = 0; memb_addr[H5FD_MEM_DRAW] = HADDR_MAX/2; - return H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name, memb_addr, - TRUE); + return H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name, memb_addr, TRUE); } @@ -400,7 +405,7 @@ H5Pset_fapl_split(hid_t fapl, const char *meta_ext, hid_t meta_plist_id, */ herr_t H5Pset_fapl_multi(hid_t fapl_id, const H5FD_mem_t *memb_map, - const hid_t *memb_fapl, const char **memb_name, + const hid_t *memb_fapl, const char * const *memb_name, const haddr_t *memb_addr, hbool_t relax) { H5FD_multi_fapl_t fa; @@ -420,18 +425,16 @@ H5Pset_fapl_multi(hid_t fapl_id, const H5FD_mem_t *memb_map, /* Check arguments and supply default values */ if(H5I_GENPROP_LST != H5Iget_type(fapl_id) || - TRUE != H5Pisa_class(fapl_id, H5P_FILE_ACCESS)) + TRUE != H5Pisa_class(fapl_id, H5P_FILE_ACCESS)) H5Epush_ret(func, H5E_PLIST, H5E_BADVALUE, "not an access list", -1); if (!memb_map) { - for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; mt=(H5FD_mem_t)(mt+1)) { + for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; mt=(H5FD_mem_t)(mt+1)) _memb_map[mt] = H5FD_MEM_DEFAULT; - } memb_map = _memb_map; } if (!memb_fapl) { - for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; mt=(H5FD_mem_t)(mt+1)) { + for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; mt=(H5FD_mem_t)(mt+1)) _memb_fapl[mt] = H5Pcreate(H5P_FILE_ACCESS); - } memb_fapl = _memb_fapl; } if (!memb_name) { @@ -443,9 +446,8 @@ H5Pset_fapl_multi(hid_t fapl_id, const H5FD_mem_t *memb_map, memb_name = _memb_name_ptrs; } if (!memb_addr) { - for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; mt=(H5FD_mem_t)(mt+1)) { + for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; mt=(H5FD_mem_t)(mt+1)) _memb_addr[mt] = (mt?mt-1:0) * HADDR_MAX/H5FD_MEM_NTYPES; - } memb_addr = _memb_addr; } @@ -523,23 +525,21 @@ H5Pget_fapl_multi(hid_t fapl_id, H5FD_mem_t *memb_map/*out*/, H5Eclear(); if(H5I_GENPROP_LST != H5Iget_type(fapl_id) || - TRUE != H5Pisa_class(fapl_id, H5P_FILE_ACCESS)) + TRUE != H5Pisa_class(fapl_id, H5P_FILE_ACCESS)) H5Epush_ret(func, H5E_PLIST, H5E_BADTYPE, "not an access list", -1); if (H5FD_MULTI!=H5Pget_driver(fapl_id)) H5Epush_ret(func, H5E_PLIST, H5E_BADVALUE, "incorrect VFL driver", -1); if (NULL==(fa=H5Pget_driver_info(fapl_id))) H5Epush_ret(func, H5E_PLIST, H5E_BADVALUE, "bad VFL driver info", -1); - if (memb_map) { + if (memb_map) memcpy(memb_map, fa->memb_map, H5FD_MEM_NTYPES*sizeof(H5FD_mem_t)); - } if (memb_fapl) { for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; mt=(H5FD_mem_t)(mt+1)) { - if (fa->memb_fapl[mt]>=0) { + if (fa->memb_fapl[mt]>=0) memb_fapl[mt] = H5Pcopy(fa->memb_fapl[mt]); - } else { + else memb_fapl[mt] = fa->memb_fapl[mt]; /*default or bad ID*/ - } } } if (memb_name) { @@ -547,17 +547,14 @@ H5Pget_fapl_multi(hid_t fapl_id, H5FD_mem_t *memb_map/*out*/, if (fa->memb_name[mt]) { memb_name[mt] = malloc(strlen(fa->memb_name[mt])+1); strcpy(memb_name[mt], fa->memb_name[mt]); - } else { + } else memb_name[mt] = NULL; - } } } - if (memb_addr) { + if (memb_addr) memcpy(memb_addr, fa->memb_addr, H5FD_MEM_NTYPES*sizeof(haddr_t)); - } - if (relax) { + if (relax) *relax = fa->relax; - } return 0; } @@ -655,11 +652,10 @@ H5Pget_dxpl_multi(hid_t dxpl_id, hid_t *memb_dxpl/*out*/) if (memb_dxpl) { for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; mt=(H5FD_mem_t)(mt+1)) { - if (dx->memb_dxpl[mt]>=0) { + if (dx->memb_dxpl[mt]>=0) memb_dxpl[mt] = H5Pcopy(dx->memb_dxpl[mt]); - } else { + else memb_dxpl[mt] = dx->memb_dxpl[mt]; /*default or bad ID */ - } } } @@ -744,7 +740,7 @@ H5FD_multi_sb_encode(H5FD_t *_file, char *name/*out*/, H5FD_multi_t *file = (H5FD_multi_t*)_file; haddr_t memb_eoa; unsigned char *p; - hsize_t nseen; + size_t nseen; size_t i; H5FD_mem_t m; static const char *func="H5FD_multi_sb_encode"; /* Function Name for error reporting */ @@ -756,9 +752,8 @@ H5FD_multi_sb_encode(H5FD_t *_file, char *name/*out*/, strcpy(name, "NCSAmulti"); assert(7==H5FD_MEM_NTYPES); - for (m=H5FD_MEM_SUPER; m<H5FD_MEM_NTYPES; m=(H5FD_mem_t)(m+1)) { - buf[m-1] = file->fa.memb_map[m]; - } + for (m=H5FD_MEM_SUPER; m<H5FD_MEM_NTYPES; m=(H5FD_mem_t)(m+1)) + buf[m-1] = (unsigned char)file->fa.memb_map[m]; buf[7] = 0; buf[8] = 0; @@ -780,9 +775,8 @@ H5FD_multi_sb_encode(H5FD_t *_file, char *name/*out*/, nseen++; } END_MEMBERS; if (H5Tconvert(H5T_NATIVE_HADDR, H5T_STD_U64LE, nseen*2, buf+8, NULL, - H5P_DEFAULT)<0) { + H5P_DEFAULT)<0) H5Epush_ret(func, H5E_DATATYPE, H5E_CANTCONVERT, "can't convert superblock info", -1); - } /* Encode all name templates */ p = buf + 8 + nseen*2*8; @@ -826,7 +820,7 @@ H5FD_multi_sb_decode(H5FD_t *_file, const char *name, const unsigned char *buf) char x[2*H5FD_MEM_NTYPES*8]; H5FD_mem_t map[H5FD_MEM_NTYPES]; int i; - hsize_t nseen=0; + size_t nseen=0; hbool_t map_changed=FALSE; hbool_t in_use[H5FD_MEM_NTYPES]; const char *memb_name[H5FD_MEM_NTYPES]; @@ -865,8 +859,7 @@ H5FD_multi_sb_decode(H5FD_t *_file, const char *name, const unsigned char *buf) /* Decode Address and EOA values */ assert(sizeof(haddr_t)<=8); - assert((nseen*2*8)==(hsize_t)((size_t)(nseen*2*8))); /*check for overflow*/ - memcpy(x, buf, (size_t)(nseen*2*8)); + memcpy(x, buf, (nseen*2*8)); buf += nseen*2*8; if (H5Tconvert(H5T_STD_U64LE, H5T_NATIVE_HADDR, nseen*2, x, NULL, H5P_DEFAULT)<0) H5Epush_ret(func, H5E_DATATYPE, H5E_CANTCONVERT, "can't convert superblock info", -1); @@ -920,7 +913,7 @@ H5FD_multi_sb_decode(H5FD_t *_file, const char *name, const unsigned char *buf) fprintf(stderr, "H5FD_MULTI: close member %d\n", (int)mt); } #endif - H5FDclose(file->memb[mt]); + (void)H5FDclose(file->memb[mt]); file->memb[mt] = NULL; } file->fa.memb_map[mt] = map[mt]; @@ -945,9 +938,9 @@ H5FD_multi_sb_decode(H5FD_t *_file, const char *name, const unsigned char *buf) /* Set the EOA marker for all open files */ UNIQUE_MEMBERS(file->fa.memb_map, mt) { - if (file->memb[mt]) { - H5FDset_eoa(file->memb[mt], memb_eoa[mt]); - } + if (file->memb[mt]) + if(H5FDset_eoa(file->memb[mt], memb_eoa[mt])<0) + H5Epush_ret(func, H5E_INTERNAL, H5E_CANTSET, "set_eoa() failed", -1); } END_MEMBERS; return 0; @@ -1030,7 +1023,7 @@ H5FD_multi_fapl_copy(const void *_old_fa) if (nerrors) { for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; mt=(H5FD_mem_t)(mt+1)) { - if (new_fa->memb_fapl[mt]>=0) H5Pclose(new_fa->memb_fapl[mt]); + if (new_fa->memb_fapl[mt]>=0) (void)H5Pclose(new_fa->memb_fapl[mt]); if (new_fa->memb_name[mt]) free(new_fa->memb_name[mt]); } free(new_fa); @@ -1061,15 +1054,20 @@ H5FD_multi_fapl_free(void *_fa) { H5FD_multi_fapl_t *fa = (H5FD_multi_fapl_t*)_fa; H5FD_mem_t mt; + static const char *func="H5FD_multi_fapl_free"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear(); for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; mt=(H5FD_mem_t)(mt+1)) { - if (fa->memb_fapl[mt]>=0) H5Pclose(fa->memb_fapl[mt]); - if (fa->memb_name[mt]) free(fa->memb_name[mt]); + if (fa->memb_fapl[mt]>=0) + if(H5Pclose(fa->memb_fapl[mt])<0) + H5Epush_ret(func, H5E_FILE, H5E_CLOSEERROR, "can't close property list", -1); + if (fa->memb_name[mt]) + free(fa->memb_name[mt]); } free(fa); + return 0; } @@ -1114,7 +1112,7 @@ H5FD_multi_dxpl_copy(const void *_old_dx) if (nerrors) { for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; mt=(H5FD_mem_t)(mt+1)) - H5Pclose(new_dx->memb_dxpl[mt]); + (void)H5Pclose(new_dx->memb_dxpl[mt]); free(new_dx); H5Epush_ret(func, H5E_INTERNAL, H5E_BADVALUE, "invalid freespace objects", NULL); } @@ -1143,13 +1141,15 @@ H5FD_multi_dxpl_free(void *_dx) { H5FD_multi_dxpl_t *dx = (H5FD_multi_dxpl_t*)_dx; H5FD_mem_t mt; + static const char *func="H5FD_multi_dxpl_free"; /* Function Name for error reporting */ /* Clear the error stack */ H5Eclear(); for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; mt=(H5FD_mem_t)(mt+1)) if (dx->memb_dxpl[mt]>=0) - H5Pclose(dx->memb_dxpl[mt]); + if(H5Pclose(dx->memb_dxpl[mt])<0) + H5Epush_ret(func, H5E_FILE, H5E_CLOSEERROR, "can't close property list", -1); free(dx); return 0; } @@ -1200,29 +1200,29 @@ H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, H5Epush_ret(func, H5E_RESOURCE, H5E_NOSPACE, "memory allocation failed", NULL); if (H5P_FILE_ACCESS_DEFAULT==fapl_id || H5FD_MULTI!=H5Pget_driver(fapl_id)) { close_fapl = fapl_id = H5Pcreate(H5P_FILE_ACCESS); - H5Pset_fapl_multi(fapl_id, NULL, NULL, NULL, NULL, TRUE); + if(H5Pset_fapl_multi(fapl_id, NULL, NULL, NULL, NULL, TRUE)<0) + H5Epush_goto(func, H5E_FILE, H5E_CANTSET, "can't set property value", error); } fa = H5Pget_driver_info(fapl_id); assert(fa); ALL_MEMBERS(mt) { file->fa.memb_map[mt] = fa->memb_map[mt]; file->fa.memb_addr[mt] = fa->memb_addr[mt]; - if (fa->memb_fapl[mt]>=0) { + if (fa->memb_fapl[mt]>=0) file->fa.memb_fapl[mt] = H5Pcopy(fa->memb_fapl[mt]); - } else { + else file->fa.memb_fapl[mt] = fa->memb_fapl[mt]; - } - if (fa->memb_name[mt]) { + if (fa->memb_name[mt]) file->fa.memb_name[mt] = my_strdup(fa->memb_name[mt]); - } else { + else file->fa.memb_name[mt] = NULL; - } } END_MEMBERS; file->fa.relax = fa->relax; file->flags = flags; file->name = my_strdup(name); if (close_fapl>=0) - H5Pclose(close_fapl); + if(H5Pclose(close_fapl)<0) + H5Epush_goto(func, H5E_FILE, H5E_CLOSEERROR, "can't close property list", error); /* Compute derived properties and open member files */ if (compute_next(file)<0) @@ -1231,18 +1231,19 @@ H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, H5Epush_goto(func, H5E_INTERNAL, H5E_BADVALUE, "open_members() failed", error); /* We must have opened at least the superblock file */ - if (H5FD_MEM_DEFAULT==(m=file->fa.memb_map[H5FD_MEM_SUPER])) { + if (H5FD_MEM_DEFAULT==(m=file->fa.memb_map[H5FD_MEM_SUPER])) m = H5FD_MEM_SUPER; - } - if (NULL==file->memb[m]) goto error; + if (NULL==file->memb[m]) + goto error; + return (H5FD_t*)file; error: /* Cleanup and fail */ if (file) { ALL_MEMBERS(mt) { - if (file->memb[mt]) H5FDclose(file->memb[mt]); - if (file->fa.memb_fapl[mt]>=0) H5Pclose(file->fa.memb_fapl[mt]); + if (file->memb[mt]) (void)H5FDclose(file->memb[mt]); + if (file->fa.memb_fapl[mt]>=0) (void)H5Pclose(file->fa.memb_fapl[mt]); if (file->fa.memb_name[mt]) free(file->fa.memb_name[mt]); } END_MEMBERS; if (file->name) free(file->name); @@ -1305,7 +1306,7 @@ H5FD_multi_close(H5FD_t *_file) /* Clean up other stuff */ ALL_MEMBERS(mt) { - if (file->fa.memb_fapl[mt]>=0) H5Pclose(file->fa.memb_fapl[mt]); + if (file->fa.memb_fapl[mt]>=0) (void)H5Pclose(file->fa.memb_fapl[mt]); if (file->fa.memb_name[mt]) free(file->fa.memb_name[mt]); } END_MEMBERS; free(file->name); @@ -1800,9 +1801,9 @@ H5FD_multi_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing) if (HADDR_UNDEF!=file->memb_addr[mt]) { haddr_t eoa = H5FDget_eoa(file->memb[mt]); fprintf(stderr, " %6d %20llu %20llu %20llu %s\n", - (int)mt, (unsigned long long)(file->memb_addr[mt]), - (unsigned long long)eoa, - (unsigned long long)(file->memb_next[mt]), + (int)mt, (unsigned long_long)(file->memb_addr[mt]), + (unsigned long_long)eoa, + (unsigned long_long)(file->memb_next[mt]), file->memb_name[mt]); } } |