diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2007-07-24 19:10:00 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2007-07-24 19:10:00 (GMT) |
commit | 492e5ca2b48782bb4759ee1d0a59b0210f011528 (patch) | |
tree | f2c334cd5e2afb9ca40492340efe57d1f3af1ae6 /src/H5Odtype.c | |
parent | 05973a4e8610a7f6893d0eaed9c3eee3b008ba60 (diff) | |
download | hdf5-492e5ca2b48782bb4759ee1d0a59b0210f011528.zip hdf5-492e5ca2b48782bb4759ee1d0a59b0210f011528.tar.gz hdf5-492e5ca2b48782bb4759ee1d0a59b0210f011528.tar.bz2 |
[svn-r14004] Description:
Fix problem with datatype messages where the version of the format
for a datatype message could depend on the "use the latest format" flag from
the file after it was initially created.
Tested on:
FreeBSD/32 6.2 (duty)
FreeBSD/64 6.2 (liberty)
Linux/32 2.6 (kagiso)
Mac OS X/32 10.4.10 (amazon)
Diffstat (limited to 'src/H5Odtype.c')
-rw-r--r-- | src/H5Odtype.c | 101 |
1 files changed, 26 insertions, 75 deletions
diff --git a/src/H5Odtype.c b/src/H5Odtype.c index 2bfaccf..1e97687 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -89,31 +89,6 @@ const H5O_msg_class_t H5O_MSG_DTYPE[1] = {{ H5O_dtype_shared_debug /* debug the message */ }}; -/* This is the version to create all datatypes which don't contain - * array datatypes (atomic types, compound datatypes without array fields, - * vlen sequences of objects which aren't arrays, etc.) or VAX byte-ordered - * objects. - */ -#define H5O_DTYPE_VERSION_1 1 - -/* This is the version to create all datatypes which contain H5T_ARRAY - * class objects (array definitely, potentially compound & vlen sequences also), - * but not VAX byte-ordered objects. - */ -#define H5O_DTYPE_VERSION_2 2 - -/* This is the version to create all datatypes which contain VAX byte-ordered - * objects (floating-point types, currently) (can also also H5T_ARRAY types - * also). - */ -/* This version also packs compound & enum field names without padding */ -/* This version also encodes the member offset of compound fields more efficiently */ -#define H5O_DTYPE_VERSION_3 3 - -/* The latest version of the format. Look through the 'encode helper' routine - * and 'size' callback for places to change when updating this. */ -#define H5O_DTYPE_VERSION_LATEST H5O_DTYPE_VERSION_3 - /*------------------------------------------------------------------------- * Function: H5O_dtype_decode_helper @@ -146,6 +121,7 @@ H5O_dtype_decode_helper(H5F_t *f, const uint8_t **pp, H5T_t *dt) version = (flags>>4) & 0x0f; if(version < H5O_DTYPE_VERSION_1 || version > H5O_DTYPE_VERSION_3) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTLOAD, FAIL, "bad version number for datatype message") + dt->shared->version = version; dt->shared->type = (H5T_class_t)(flags & 0x0f); flags >>= 8; @@ -515,6 +491,10 @@ done: * * Purpose: Encodes a datatype. * + * Note: When changing the format of a datatype (or adding a new one), + * remember to change the upgrade version callback + * (H5T_upgrade_version_cb). + * * Return: Non-negative on success/Negative on failure * * Programmer: Robb Matzke @@ -525,14 +505,10 @@ done: static herr_t H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) { - htri_t has_array = FALSE; /* Whether a compound datatype has an array inside it */ - hbool_t has_vax = FALSE; /* Whether VAX floating number exists */ unsigned flags = 0; char *hdr = (char *)*pp; unsigned i; size_t n, z; - uint8_t version; /* version number */ - hbool_t use_latest_format; /* Flag indicating the newest file format should be used */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5O_dtype_encode_helper) @@ -541,9 +517,6 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) HDassert(pp && *pp); HDassert(dt); - /* Get the file's 'use the latest version of the format' flag */ - use_latest_format = H5F_USE_LATEST_FORMAT(f); - /* skip the type and class bit-field for now */ *pp += 4; UINT32ENCODE(*pp, dt->shared->size); @@ -666,7 +639,7 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) break; case H5T_ORDER_VAX: /*turn on 1st and 6th (reserved before adding VAX) bits*/ flags |= 0x41; - has_vax = TRUE; + HDassert(dt->shared->version >= H5O_DTYPE_VERSION_3); break; default: HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "byte order is not supported in file format yet") @@ -733,10 +706,6 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) { unsigned offset_nbytes; /* Size needed to encode member offsets */ - /* Check for an array datatype somewhere within the compound type */ - if((has_array = H5T_detect_class(dt, H5T_ARRAY)) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't detect array class") - /* Compute the # of bytes required to store a member offset */ offset_nbytes = (H5V_log2_gen((uint64_t)dt->shared->size) + 7) / 8; @@ -745,12 +714,16 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) */ flags = dt->shared->u.compnd.nmembs & 0xffff; for(i = 0; i < dt->shared->u.compnd.nmembs; i++) { + /* Sanity check */ + /* (compound datatypes w/array members must be encoded w/version >= 2) */ + HDassert(dt->shared->u.compnd.memb[i].type->shared->type != H5T_ARRAY || dt->shared->version >= H5O_DTYPE_VERSION_2); + /* Name */ HDstrcpy((char*)(*pp), dt->shared->u.compnd.memb[i].name); /* Version 3 of the datatype message removed the padding to multiple of 8 bytes */ n = HDstrlen(dt->shared->u.compnd.memb[i].name); - if(use_latest_format) + if(dt->shared->version >= H5O_DTYPE_VERSION_3) *pp += n + 1; else { /* Pad name to multiple of 8 bytes */ @@ -761,7 +734,7 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) /* Member offset */ /* (starting with version 3 of the datatype message, use the minimum # of bytes required) */ - if(use_latest_format) + if(dt->shared->version >= H5O_DTYPE_VERSION_3) UINT32ENCODE_VAR(*pp, dt->shared->u.compnd.memb[i].offset, offset_nbytes) else UINT32ENCODE(*pp, dt->shared->u.compnd.memb[i].offset) @@ -770,7 +743,7 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) * member information, for better backward compatibility * Write out all zeros for the array information, though... */ - if(!has_array && !use_latest_format) { + if(dt->shared->version == H5O_DTYPE_VERSION_1) { unsigned j; /* Dimensionality */ @@ -810,13 +783,13 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "unable to encode parent datatype") /* Names, each a multiple of eight bytes */ - for(i=0; i<dt->shared->u.enumer.nmembs; i++) { + for(i = 0; i < dt->shared->u.enumer.nmembs; i++) { /* Name */ HDstrcpy((char*)(*pp), dt->shared->u.enumer.name[i]); /* Version 3 of the datatype message removed the padding to multiple of 8 bytes */ n = HDstrlen(dt->shared->u.enumer.name[i]); - if(use_latest_format) + if(dt->shared->version >= H5O_DTYPE_VERSION_3) *pp += n + 1; else { /* Pad to multiple of 8 bytes */ @@ -882,7 +855,7 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) *(*pp)++ = dt->shared->u.array.ndims; /* Drop this information for Version 3 of the format */ - if(!use_latest_format) { + if(dt->shared->version < H5O_DTYPE_VERSION_3) { /* Reserved */ *(*pp)++ = '\0'; *(*pp)++ = '\0'; @@ -894,7 +867,7 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) UINT32ENCODE(*pp, dt->shared->u.array.dim[i]); /* Drop this information for Version 3 of the format */ - if(!use_latest_format) { + if(dt->shared->version < H5O_DTYPE_VERSION_3) { /* Encode 'fake' array dimension permutations */ for(i = 0; i < (unsigned)dt->shared->u.array.ndims; i++) UINT32ENCODE(*pp, i); @@ -910,21 +883,8 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) break; } /* end switch */ - /* Set version #, based on actual features used for datatype */ - /* (unless the "use the latest format" flag is set, which can "upgrade" the - * format of certain encodings) - */ - if(use_latest_format) - version = H5O_DTYPE_VERSION_LATEST; - else if(has_vax) - version = H5O_DTYPE_VERSION_3; - else if(has_array) - version = H5O_DTYPE_VERSION_2; - else - version = H5O_DTYPE_VERSION_1; - /* Encode the type's class, version and bit field */ - *hdr++ = ((unsigned)(dt->shared->type) & 0x0f) | (version << 4); + *hdr++ = ((unsigned)(dt->shared->type) & 0x0f) | (dt->shared->version << 4); *hdr++ = (flags >> 0) & 0xff; *hdr++ = (flags >> 8) & 0xff; *hdr++ = (flags >> 16) & 0xff; @@ -1098,7 +1058,6 @@ static size_t H5O_dtype_size(const H5F_t *f, const void *_mesg) { const H5T_t *dt = (const H5T_t *)_mesg; - hbool_t use_latest_format; /* Flag indicating the newest file format should be used */ unsigned u; /* Local index variable */ size_t ret_value; @@ -1107,9 +1066,6 @@ H5O_dtype_size(const H5F_t *f, const void *_mesg) HDassert(f); HDassert(dt); - /* Get the file's 'use the latest version of the format' flag */ - use_latest_format = H5F_USE_LATEST_FORMAT(f); - /* Set the common size information */ ret_value = 4 + /* Type, class & flags */ 4; /* Size of datatype */ @@ -1134,13 +1090,8 @@ H5O_dtype_size(const H5F_t *f, const void *_mesg) case H5T_COMPOUND: { - htri_t has_array; /* Whether a compound datatype has an array inside it */ unsigned offset_nbytes; /* Size needed to encode member offsets */ - /* Check for an array datatype somewhere within the compound type */ - has_array = H5T_detect_class(dt, H5T_ARRAY); - HDassert(has_array >= 0); - /* Compute the # of bytes required to store a member offset */ offset_nbytes = (H5V_log2_gen((uint64_t)dt->shared->size) + 7) / 8; @@ -1151,17 +1102,17 @@ H5O_dtype_size(const H5F_t *f, const void *_mesg) /* Get length of field's name */ name_len = HDstrlen(dt->shared->u.compnd.memb[u].name); - /* Newer versions of the format don't pad out the name */ - if(use_latest_format) + /* Versions of the format >= 3 don't pad out the name */ + if(dt->shared->version >= H5O_DTYPE_VERSION_3) ret_value += name_len + 1; else ret_value += ((name_len + 8) / 8) * 8; /* Check for encoding array datatype or using the latest file format */ /* (starting with version 3 of the datatype message, use the minimum # of bytes required) */ - if(use_latest_format) + if(dt->shared->version >= H5O_DTYPE_VERSION_3) ret_value += offset_nbytes; /*member offset*/ - else if(has_array) + if(dt->shared->version >= H5O_DTYPE_VERSION_2) ret_value += 4; /*member offset*/ else ret_value += 4 + /*member offset*/ @@ -1183,8 +1134,8 @@ H5O_dtype_size(const H5F_t *f, const void *_mesg) /* Get length of field's name */ name_len = HDstrlen(dt->shared->u.enumer.name[u]); - /* Newer versions of the format don't pad out the name */ - if(use_latest_format) + /* Versions of the format >= 3 don't pad out the name */ + if(dt->shared->version >= H5O_DTYPE_VERSION_3) ret_value += name_len + 1; else ret_value += ((name_len + 8) / 8) * 8; @@ -1202,10 +1153,10 @@ H5O_dtype_size(const H5F_t *f, const void *_mesg) case H5T_ARRAY: ret_value += 1; /* ndims */ - if(!use_latest_format) + if(dt->shared->version < H5O_DTYPE_VERSION_3) ret_value += 3; /* reserved bytes*/ ret_value += 4 * dt->shared->u.array.ndims; /* dimensions */ - if(!use_latest_format) + if(dt->shared->version < H5O_DTYPE_VERSION_3) ret_value += 4 * dt->shared->u.array.ndims; /* dimension permutations */ ret_value += H5O_dtype_size(f, dt->shared->parent); break; |