diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2004-07-22 14:27:37 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2004-07-22 14:27:37 (GMT) |
commit | 2e6374407848d3c3a7b6a572e62ee88f4f18e8d0 (patch) | |
tree | e7202aee3e87bf423bae3a008e0875e579e257fc | |
parent | 5bae554343a48a7c30d8d8908090e9f47ab72a14 (diff) | |
download | hdf5-2e6374407848d3c3a7b6a572e62ee88f4f18e8d0.zip hdf5-2e6374407848d3c3a7b6a572e62ee88f4f18e8d0.tar.gz hdf5-2e6374407848d3c3a7b6a572e62ee88f4f18e8d0.tar.bz2 |
[svn-r8927] Purpose:
Code cleanup
Description:
Clean up various recent changes a little.
Platforms tested:
FreeBSD 4.10 (sleipnir)
Too minor to require h5committest
-rw-r--r-- | src/H5O.c | 37 | ||||
-rw-r--r-- | src/H5Oprivate.h | 4 | ||||
-rw-r--r-- | src/H5Osdspace.c | 2 | ||||
-rw-r--r-- | src/H5S.c | 88 | ||||
-rw-r--r-- | src/H5T.c | 13 | ||||
-rw-r--r-- | src/H5Zszip.c | 16 |
6 files changed, 58 insertions, 102 deletions
@@ -3444,11 +3444,9 @@ done: *------------------------------------------------------------------------- */ herr_t -H5O_encode(unsigned char *buf, void *obj, hid_t type_id) +H5O_encode(H5F_t *f, unsigned char *buf, void *obj, unsigned type_id) { const H5O_class_t *type; /* Actual H5O class type for the ID */ - size_t extent_size; /* size of the message*/ - H5F_t f; /* fake file structure*/ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5O_encode,FAIL); @@ -3458,23 +3456,10 @@ H5O_encode(unsigned char *buf, void *obj, hid_t type_id) type=message_type_g[type_id]; /* map the type ID to the actual type object */ assert(type); - if(type_id == H5O_SDSPACE_ID) { - /* Fake file structure, needed for space encoding and decoding. */ - f.shared = (H5F_file_t*)H5MM_calloc(sizeof(H5F_file_t)); - f.shared->sizeof_size = H5F_CRT_OBJ_BYTE_NUM_DEF; - - /* Encode this "size of size" */ - *buf = H5F_CRT_OBJ_BYTE_NUM_DEF; - buf++; - } - /* Encode */ - if ((type->encode)(&f, buf, obj)<0) + if ((type->encode)(f, buf, obj)<0) HGOTO_ERROR (H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode message"); - if(type_id == H5O_SDSPACE_ID) - H5MM_free(f.shared); - done: FUNC_LEAVE_NOAPI(ret_value); } @@ -3499,10 +3484,9 @@ done: *------------------------------------------------------------------------- */ void* -H5O_decode(unsigned char *buf, unsigned type_id) +H5O_decode(H5F_t *f, unsigned char *buf, unsigned type_id) { const H5O_class_t *type; /* Actual H5O class type for the ID */ - H5F_t f; /* fake file structure*/ void *ret_value=NULL; /* Return value */ FUNC_ENTER_NOAPI(H5O_decode,NULL); @@ -3512,23 +3496,10 @@ H5O_decode(unsigned char *buf, unsigned type_id) type=message_type_g[type_id]; /* map the type ID to the actual type object */ assert(type); - if(type_id == H5O_SDSPACE_ID) { - /* Fake file structure, needed for space encoding and decoding. */ - f.shared = (H5F_file_t*)H5MM_calloc(sizeof(H5F_file_t)); - - /* Decode the "size of size", needed for space encoding and decoding */ - f.shared->sizeof_size = *buf; - buf++; - } - /* decode */ - if((ret_value = (type->decode)(&f, 0, buf, NULL))==NULL) + if((ret_value = (type->decode)(f, 0, buf, NULL))==NULL) HGOTO_ERROR (H5E_OHDR, H5E_CANTDECODE, NULL, "unable to decode message"); - if(type_id == H5O_SDSPACE_ID) { - H5MM_free(f.shared); - } - done: FUNC_LEAVE_NOAPI(ret_value); } diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h index 4eb3a3c..31017a4 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -249,8 +249,8 @@ H5_DLL herr_t H5O_remove(H5G_entry_t *ent, unsigned type_id, int sequence, hid_t dxpl_id); H5_DLL herr_t H5O_reset(unsigned type_id, void *native); H5_DLL void *H5O_free(unsigned type_id, void *mesg); -H5_DLL herr_t H5O_encode(unsigned char *buf, void *obj, hid_t type_id); -H5_DLL void* H5O_decode(unsigned char *buf, unsigned type_id); +H5_DLL herr_t H5O_encode(H5F_t *f, unsigned char *buf, void *obj, unsigned type_id); +H5_DLL void* H5O_decode(H5F_t *f, unsigned char *buf, unsigned type_id); H5_DLL void *H5O_copy(unsigned type_id, const void *mesg, void *dst); H5_DLL size_t H5O_raw_size(unsigned type_id, H5F_t *f, const void *mesg); H5_DLL herr_t H5O_get_share(unsigned type_id, H5F_t *f, const void *mesg, H5O_shared_t *share); diff --git a/src/H5Osdspace.c b/src/H5Osdspace.c index 8fff4b0..e130977 100644 --- a/src/H5Osdspace.c +++ b/src/H5Osdspace.c @@ -108,7 +108,7 @@ H5O_sdspace_decode(H5F_t *f, hid_t UNUSED dxpl_id, const uint8_t *p, H5O_shared_ FUNC_ENTER_NOAPI_NOINIT(H5O_sdspace_decode); /* check args */ - /*assert(f);*/ + assert(f); assert(p); assert (!sh); @@ -25,9 +25,9 @@ #define _H5S_IN_H5S_C #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ -#include "H5Iprivate.h" /* ID Functions */ -#include "H5FLprivate.h" /* Free Lists */ #include "H5Fpkg.h" /* Dataspace functions */ +#include "H5FLprivate.h" /* Free Lists */ +#include "H5Iprivate.h" /* ID Functions */ #include "H5MMprivate.h" /* Memory Management functions */ #include "H5Oprivate.h" /* object headers */ #include "H5Spkg.h" /* Dataspace functions */ @@ -1766,7 +1766,7 @@ herr_t H5Sencode(hid_t obj_id, unsigned char* buf, size_t* nalloc) { H5S_t *dspace; - herr_t ret_value; + herr_t ret_value=SUCCEED; FUNC_ENTER_API (H5Sencode, FAIL); @@ -1774,7 +1774,8 @@ H5Sencode(hid_t obj_id, unsigned char* buf, size_t* nalloc) if (NULL==(dspace=H5I_object_verify(obj_id, H5I_DATASPACE))) HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace") - ret_value = H5S_encode(dspace, buf, nalloc); + if(H5S_encode(dspace, buf, nalloc)<0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't encode datatype"); done: FUNC_LEAVE_API(ret_value); @@ -1803,12 +1804,9 @@ done: herr_t H5S_encode(H5S_t *obj, unsigned char *buf, size_t *nalloc) { - size_t extent_size = 0; - hssize_t select_size = 0; + size_t extent_size; + hssize_t select_size; H5S_class_t space_type; - uint8_t *size_buf; - uint8_t *extent_buf; - uint8_t *select_buf; H5F_t f; /* fake file structure*/ herr_t ret_value = SUCCEED; @@ -1822,43 +1820,38 @@ H5S_encode(H5S_t *obj, unsigned char *buf, size_t *nalloc) if((extent_size=H5O_raw_size(H5O_SDSPACE_ID, &f, obj))==0) HGOTO_ERROR(H5E_DATASPACE, H5E_BADSIZE, FAIL, "can't find dataspace size"); - H5MM_free(f.shared); - - /* Make it 1 byte bigger to encode the f.shared->sizeof_size(8 bytes). The - * actual encoding happens in the level below(H5O_encode). */ - extent_size++; - /* Get space type */ space_type = H5S_GET_EXTENT_TYPE(obj); - if((H5S_SIMPLE==space_type) && (select_size=H5S_SELECT_SERIAL_SIZE(obj))<0) + if((select_size=H5S_SELECT_SERIAL_SIZE(obj))<0) HGOTO_ERROR(H5E_DATASPACE, H5E_BADSIZE, FAIL, "can't find dataspace selection size"); /* Verify the size of buffer. If it's not big enough, simply return the * right size without filling the buffer. */ - if(!buf || *nalloc<(extent_size+select_size+2)) { - *nalloc = extent_size+select_size+2; + if(!buf || *nalloc<(extent_size+select_size+3)) { + *nalloc = extent_size+select_size+3; HGOTO_DONE(ret_value); } + /* Encode the "size of size" information */ + *buf++ = f.shared->sizeof_size; + /* Encode size of extent information. Pointer is actually moved in this macro. */ - size_buf = buf; - UINT16ENCODE(size_buf, (uint8_t)extent_size); + UINT16ENCODE(buf, extent_size); /* Encode the extent part of dataspace */ - extent_buf = buf + 2; /* This 2 bytes come from UINT16ENCODE above */ - if(H5O_encode(extent_buf, obj, H5O_SDSPACE_ID)<0) + if(H5O_encode(&f, buf, obj, H5O_SDSPACE_ID)<0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTENCODE, FAIL, "can't encode extent space"); + buf +=extent_size; - /* Encode the selection part of dataspace. I believe the size is always greater - * than 0 */ - if(space_type==H5S_SIMPLE && select_size>0) { - select_buf = buf + 2 + extent_size; - if(H5S_SELECT_SERIALIZE(obj, select_buf) <0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTENCODE, FAIL, "can't encode select space"); - } + /* Encode the selection part of dataspace. */ + if(H5S_SELECT_SERIALIZE(obj, buf) <0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTENCODE, FAIL, "can't encode select space"); done: + if(f.shared) + H5MM_free(f.shared); + FUNC_LEAVE_NOAPI(ret_value); } @@ -1928,44 +1921,41 @@ H5S_decode(unsigned char *buf) H5S_t *ds; H5S_extent_t *extent; size_t extent_size; /* size of the extent message*/ - uint8_t *size_buf; - uint8_t *extent_buf; - uint8_t *select_buf; + H5F_t f; /* fake file structure*/ H5S_t *ret_value; FUNC_ENTER_NOAPI(H5S_decode, NULL); + /* Fake file structure, used only for header message operation */ + f.shared = (H5F_file_t*)H5MM_calloc(sizeof(H5F_file_t)); + + /* Decode the "size of size" information */ + f.shared->sizeof_size = *buf++; + /* Decode size of extent information */ - size_buf = buf; - UINT16DECODE(size_buf, extent_size); + UINT16DECODE(buf, extent_size); /* Decode the extent part of dataspace */ - extent_buf = buf+2; /*2 bytes are from the UINT16DECODE above*/ - - if((extent = H5O_decode(extent_buf, H5O_SDSPACE_ID))==NULL) + if((extent = H5O_decode(&f, buf, H5O_SDSPACE_ID))==NULL) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDECODE, NULL, "can't decode object"); + buf += extent_size; /* Copy the extent into dataspace structure */ - ds = H5FL_CALLOC(H5S_t); + if((ds = H5FL_CALLOC(H5S_t))==NULL) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for data space conversion path table"); if(H5O_copy(H5O_SDSPACE_ID, extent, &(ds->extent))==NULL) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy object"); - - H5S_extent_release(extent); + if(H5S_extent_release(extent)<0) + HGOTO_ERROR(H5E_RESOURCE, H5E_CANTDELETE, NULL, "can't release previous dataspace"); H5FL_FREE(H5S_extent_t,extent); - /* Initialize to "all" selection. Deserialization seems relying on it. */ + /* Initialize to "all" selection. Deserialization relies on valid existing selection. */ if(H5S_select_all(ds,0)<0) HGOTO_ERROR (H5E_DATASPACE, H5E_CANTSET, NULL, "unable to set all selection"); - /* Reset common selection info pointer */ - ds->select.sel_info.hslab=NULL; - /* Decode the select part of dataspace. I believe this part always exists. */ - if(ds->extent.type == H5S_SIMPLE) { - select_buf = buf + 2 + extent_size; - if(H5S_SELECT_DESERIALIZE(ds, select_buf)<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDECODE, NULL, "can't decode space selection"); - } + if(H5S_SELECT_DESERIALIZE(ds, buf)<0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDECODE, NULL, "can't decode space selection"); /* Set return value */ ret_value=ds; @@ -32,13 +32,12 @@ #include "H5private.h" /*generic functions */ #include "H5Dprivate.h" /*datasets (for H5Tcopy) */ #include "H5Eprivate.h" /*error handling */ +#include "H5Fpkg.h" /* File */ #include "H5FLprivate.h" /* Free Lists */ -#include "H5Fprivate.h" /* File */ #include "H5Gprivate.h" /*groups */ #include "H5Iprivate.h" /*ID functions */ #include "H5MMprivate.h" /*memory management */ #include "H5Pprivate.h" /* Property Lists */ -#include "H5Fpkg.h" /*file functions */ #include "H5Tpkg.h" /*data-type functions */ /* Check for header needed for SGI floating-point code */ @@ -2661,7 +2660,7 @@ done: herr_t H5T_encode(H5T_t *obj, unsigned char *buf, size_t *nalloc) { - size_t buf_size = 0; + size_t buf_size; H5F_t f; herr_t ret_value = SUCCEED; @@ -2677,7 +2676,7 @@ H5T_encode(H5T_t *obj, unsigned char *buf, size_t *nalloc) HGOTO_DONE(ret_value); } - if(H5O_encode(buf, obj, H5O_DTYPE_ID)<0) + if(H5O_encode(&f, buf, obj, H5O_DTYPE_ID)<0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't encode object"); done: @@ -2706,17 +2705,13 @@ done: H5T_t* H5T_decode(unsigned char *buf) { - H5T_t *dt; H5T_t *ret_value; FUNC_ENTER_NOAPI(H5T_decode, NULL); - if((dt = H5O_decode(buf, H5O_DTYPE_ID))==NULL) + if((ret_value = H5O_decode(NULL, buf, H5O_DTYPE_ID))==NULL) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, NULL, "can't decode object"); - /* Set return value */ - ret_value=dt; - done: FUNC_LEAVE_NOAPI(ret_value); } diff --git a/src/H5Zszip.c b/src/H5Zszip.c index 0ea7423..71abb54 100644 --- a/src/H5Zszip.c +++ b/src/H5Zszip.c @@ -148,14 +148,14 @@ H5Z_can_apply_szip(hid_t dcpl_id, hid_t type_id, hid_t space_id) /* Check the pixels per block against the 'scanline' size */ if(scanline<cd_values[H5Z_SZIP_PARM_PPB]) { - /* Get number of elements for the dataspace; use - total number of elements in the chunk to define the new 'scanline' size */ - if ((npoints=H5Sget_simple_extent_npoints(space_id))<0) - HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "unable to get number of points in the dataspace") - if(npoints<cd_values[H5Z_SZIP_PARM_PPB]) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FALSE, "pixels per block greater than total number of elements in the chunk") - scanline = MIN((cd_values[H5Z_SZIP_PARM_PPB] * SZ_MAX_BLOCKS_PER_SCANLINE), npoints); - goto done; + /* Get number of elements for the dataspace; use + total number of elements in the chunk to define the new 'scanline' size */ + if ((npoints=H5Sget_simple_extent_npoints(space_id))<0) + HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "unable to get number of points in the dataspace") + if(npoints<cd_values[H5Z_SZIP_PARM_PPB]) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FALSE, "pixels per block greater than total number of elements in the chunk") + scanline = MIN((cd_values[H5Z_SZIP_PARM_PPB] * SZ_MAX_BLOCKS_PER_SCANLINE), npoints); + HGOTO_DONE(TRUE); } |