diff options
author | Robb Matzke <matzke@llnl.gov> | 1999-01-07 11:41:25 (GMT) |
---|---|---|
committer | Robb Matzke <matzke@llnl.gov> | 1999-01-07 11:41:25 (GMT) |
commit | 504aa95bd92511ccb80e6321dd79f7dc525310d5 (patch) | |
tree | 43b1c89316ea8ef44db0fe05a6f33cba0006d4b0 | |
parent | 04bec43fa2e962fc4bf5deef67879b5ebf573c8f (diff) | |
download | hdf5-504aa95bd92511ccb80e6321dd79f7dc525310d5.zip hdf5-504aa95bd92511ccb80e6321dd79f7dc525310d5.tar.gz hdf5-504aa95bd92511ccb80e6321dd79f7dc525310d5.tar.bz2 |
[svn-r1010] Changes since 19981217
----------------------
./src/H5.c
./src/H5private.h
Renamed `library_initialize_g' to `H5_libinit_g' to make it
conform to our naming scheme.
./src/H5I.c
Fixed a bug in H5I_dec_ref() that caused the return value to
always be zero instead of the new reference count.
./src/H5.c
./src/H5Odtype.c
./src/H5T.c
./src/H5Tconv.c
./src/H5Tpkg.h
./src/H5Tprivate.h
./src/H5Tpublic.h
Added support for enumeration data types.
./src/H5RA.c
Renamed H5T_insert() to H5T_struct_insert() and added
H5T_enum_insert().
./src/H5RA.c
./src/H5Shyper.c
Added casts to size_t for the third argument of memcpy() to
shut up a warning message from insure++.
./src/H5T.c
Changed "can't" to "unable to" in some error messages to be
more consistent.
./src/H5detect.c
If fork() or waitpid() are unavailable then we assume no
alignment constraints. Hopefully this is the case only on NT
and Intel CPU's don't have alignment constraints.
./src/H5public.h
Include <limits.h> because the H5T_NATIVE_CHAR macro needs the
definition for CHAR_MIN.
-rw-r--r-- | src/H5.c | 31 | ||||
-rw-r--r-- | src/H5I.c | 5 | ||||
-rw-r--r-- | src/H5Odtype.c | 1173 | ||||
-rw-r--r-- | src/H5RA.c | 14 | ||||
-rw-r--r-- | src/H5Shyper.c | 4 | ||||
-rw-r--r-- | src/H5T.c | 1782 | ||||
-rw-r--r-- | src/H5Tconv.c | 317 | ||||
-rw-r--r-- | src/H5Tpkg.h | 29 | ||||
-rw-r--r-- | src/H5Tprivate.h | 44 | ||||
-rw-r--r-- | src/H5Tpublic.h | 55 | ||||
-rw-r--r-- | src/H5detect.c | 9 | ||||
-rw-r--r-- | src/H5private.h | 656 | ||||
-rw-r--r-- | src/H5public.h | 4 |
13 files changed, 2902 insertions, 1221 deletions
@@ -34,13 +34,13 @@ FILE *fdopen(int fd, const char *mode); #define PABLO_MASK H5_mask -hbool_t library_initialize_g = FALSE; +hbool_t H5_libinit_g = FALSE; hbool_t dont_atexit_g = FALSE; H5_debug_t H5_debug_g; /*debugging info */ static void H5_debug_mask(const char*); /* Interface initialization */ -static intn interface_initialize_g = 0; +static intn interface_initialize_g = 0; #define INTERFACE_INIT NULL /*-------------------------------------------------------------------------- @@ -131,7 +131,7 @@ void H5_term_library(void) { /* Don't do anything if the library is already closed */ - if (!library_initialize_g) return; + if (!H5_libinit_g) return; /* * Close interfaces in a well-defined order based on dependencies. The @@ -179,7 +179,7 @@ H5_term_library(void) H5Z_term_interface(0); /* Mark library as closed */ - library_initialize_g = FALSE; + H5_libinit_g = FALSE; } @@ -2191,34 +2191,37 @@ H5_trace (hbool_t returning, const char *func, const char *type, ...) fprintf(out, "NULL"); } } else { - H5T_class_t type_class = va_arg (ap, H5T_class_t); + H5T_class_t type_class = va_arg(ap, H5T_class_t); switch (type_class) { case H5T_NO_CLASS: - fprintf (out, "H5T_NO_CLASS"); + fprintf(out, "H5T_NO_CLASS"); break; case H5T_INTEGER: - fprintf (out, "H5T_INTEGER"); + fprintf(out, "H5T_INTEGER"); break; case H5T_FLOAT: - fprintf (out, "H5T_FLOAT"); + fprintf(out, "H5T_FLOAT"); break; case H5T_TIME: - fprintf (out, "H5T_TIME"); + fprintf(out, "H5T_TIME"); break; case H5T_STRING: - fprintf (out, "H5T_STRING"); + fprintf(out, "H5T_STRING"); break; case H5T_BITFIELD: - fprintf (out, "H5T_BITFIELD"); + fprintf(out, "H5T_BITFIELD"); break; case H5T_OPAQUE: - fprintf (out, "H5T_OPAQUE"); + fprintf(out, "H5T_OPAQUE"); break; case H5T_COMPOUND: - fprintf (out, "H5T_COMPOUND"); + fprintf(out, "H5T_COMPOUND"); + break; + case H5T_ENUM: + fprintf(out, "H5T_ENUM"); break; default: - fprintf (out, "%ld", (long)type_class); + fprintf(out, "%ld", (long)type_class); break; } } @@ -706,6 +706,10 @@ H5I_remove(hid_t id) * zero and no `free' function has been defined. The object is still * removed from the list. * + * Robb Matzke, 30 Dec 1998 + * Fixed a bug where the return value was always zero instead of the new + * reference count. + * *------------------------------------------------------------------------- */ intn @@ -742,7 +746,6 @@ H5I_dec_ref(hid_t id) } } } - ret_value = SUCCEED; } FUNC_LEAVE(ret_value); } diff --git a/src/H5Odtype.c b/src/H5Odtype.c index 84de73c..2a5d7f3 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -1,22 +1,22 @@ /**************************************************************************** -* NCSA HDF * -* Software Development Group * -* National Center for Supercomputing Applications * -* University of Illinois at Urbana-Champaign * -* 605 E. Springfield, Champaign IL 61820 * -* * -* For conditions of distribution and use, see the accompanying * -* hdf/COPYING file. * -* * +* NCSA HDF * +* Software Development Group * +* National Center for Supercomputing Applications * +* University of Illinois at Urbana-Champaign * +* 605 E. Springfield, Champaign IL 61820 * +* * +* For conditions of distribution and use, see the accompanying * +* hdf/COPYING file. * +* * ****************************************************************************/ #ifdef RCSID -static char RcsId[] = "@(#)$Revision$"; +static char RcsId[] = "@(#)$Revision$"; #endif /* $Id$ */ -#define H5T_PACKAGE /*prevent warning from including H5Tpkg.h */ +#define H5T_PACKAGE /*prevent warning from including H5Tpkg.h */ #include <H5private.h> #include <H5Eprivate.h> @@ -25,7 +25,7 @@ static char RcsId[] = "@(#)$Revision$"; #include <H5Oprivate.h> #include <H5Tpkg.h> -#define PABLO_MASK H5O_dtype_mask +#define PABLO_MASK H5O_dtype_mask /* PRIVATE PROTOTYPES */ static herr_t H5O_dtype_encode (H5F_t *f, uint8_t *p, const void *mesg); @@ -42,34 +42,34 @@ static herr_t H5O_dtype_debug (H5F_t *f, const void *_mesg, /* This message derives from H5O */ const H5O_class_t H5O_DTYPE[1] = {{ - H5O_DTYPE_ID, /* message id number */ - "data_type", /* message name for debugging */ - sizeof(H5T_t), /* native message size */ - H5O_dtype_decode, /* decode message */ - H5O_dtype_encode, /* encode message */ - H5O_dtype_copy, /* copy the native value */ - H5O_dtype_size, /* size of raw message */ - H5O_dtype_reset, /* reset method */ + H5O_DTYPE_ID, /* message id number */ + "data_type", /* message name for debugging */ + sizeof(H5T_t), /* native message size */ + H5O_dtype_decode, /* decode message */ + H5O_dtype_encode, /* encode message */ + H5O_dtype_copy, /* copy the native value */ + H5O_dtype_size, /* size of raw message */ + H5O_dtype_reset, /* reset method */ H5O_dtype_get_share, /* get share method */ H5O_dtype_set_share, /* set share method */ - H5O_dtype_debug, /* debug the message */ + H5O_dtype_debug, /* debug the message */ }}; #define H5O_DTYPE_VERSION 1 /* Interface initialization */ static intn interface_initialize_g = 0; -#define INTERFACE_INIT NULL +#define INTERFACE_INIT NULL /*------------------------------------------------------------------------- - * Function: H5O_dtype_decode_helper + * Function: H5O_dtype_decode_helper * - * Purpose: Decodes a data type + * Purpose: Decodes a data type * - * Return: Non-negative on success/Negative on failure + * Return: Non-negative on success/Negative on failure * - * Programmer: Robb Matzke - * Monday, December 8, 1997 + * Programmer: Robb Matzke + * Monday, December 8, 1997 * * Modifications: * @@ -78,8 +78,8 @@ static intn interface_initialize_g = 0; static herr_t H5O_dtype_decode_helper(const uint8_t **pp, H5T_t *dt) { - uintn flags, perm_word, version; - intn i, j; + uintn flags, perm_word, version; + intn i, j; FUNC_ENTER(H5O_dtype_decode_helper, FAIL); @@ -100,16 +100,16 @@ H5O_dtype_decode_helper(const uint8_t **pp, H5T_t *dt) switch (dt->type) { case H5T_INTEGER: - /* - * Integer types... - */ - dt->u.atomic.order = (flags & 0x1) ? H5T_ORDER_BE : H5T_ORDER_LE; - dt->u.atomic.lsb_pad = (flags & 0x2) ? H5T_PAD_ONE : H5T_PAD_ZERO; - dt->u.atomic.msb_pad = (flags & 0x4) ? H5T_PAD_ONE : H5T_PAD_ZERO; - dt->u.atomic.u.i.sign = (flags & 0x8) ? H5T_SGN_2 : H5T_SGN_NONE; - UINT16DECODE(*pp, dt->u.atomic.offset); - UINT16DECODE(*pp, dt->u.atomic.prec); - break; + /* + * Integer types... + */ + dt->u.atomic.order = (flags & 0x1) ? H5T_ORDER_BE : H5T_ORDER_LE; + dt->u.atomic.lsb_pad = (flags & 0x2) ? H5T_PAD_ONE : H5T_PAD_ZERO; + dt->u.atomic.msb_pad = (flags & 0x4) ? H5T_PAD_ONE : H5T_PAD_ZERO; + dt->u.atomic.u.i.sign = (flags & 0x8) ? H5T_SGN_2 : H5T_SGN_NONE; + UINT16DECODE(*pp, dt->u.atomic.offset); + UINT16DECODE(*pp, dt->u.atomic.prec); + break; case H5T_STRING: /* @@ -126,125 +126,159 @@ H5O_dtype_decode_helper(const uint8_t **pp, H5T_t *dt) break; case H5T_FLOAT: - /* - * Floating-point types... - */ - dt->u.atomic.order = (flags & 0x1) ? H5T_ORDER_BE : H5T_ORDER_LE; - dt->u.atomic.lsb_pad = (flags & 0x2) ? H5T_PAD_ONE : H5T_PAD_ZERO; - dt->u.atomic.msb_pad = (flags & 0x4) ? H5T_PAD_ONE : H5T_PAD_ZERO; - dt->u.atomic.u.f.pad = (flags & 0x8) ? H5T_PAD_ONE : H5T_PAD_ZERO; - switch ((flags >> 4) & 0x03) { - case 0: - dt->u.atomic.u.f.norm = H5T_NORM_NONE; - break; - case 1: - dt->u.atomic.u.f.norm = H5T_NORM_MSBSET; - break; - case 2: - dt->u.atomic.u.f.norm = H5T_NORM_IMPLIED; - break; - default: - HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "unknown floating-point normalization"); - } - dt->u.atomic.u.f.sign = (flags >> 8) & 0xff; - UINT16DECODE(*pp, dt->u.atomic.offset); - UINT16DECODE(*pp, dt->u.atomic.prec); - dt->u.atomic.u.f.epos = *(*pp)++; - dt->u.atomic.u.f.esize = *(*pp)++; - assert(dt->u.atomic.u.f.esize > 0); - dt->u.atomic.u.f.mpos = *(*pp)++; - dt->u.atomic.u.f.msize = *(*pp)++; - assert(dt->u.atomic.u.f.msize > 0); - UINT32DECODE(*pp, dt->u.atomic.u.f.ebias); - break; + /* + * Floating-point types... + */ + dt->u.atomic.order = (flags & 0x1) ? H5T_ORDER_BE : H5T_ORDER_LE; + dt->u.atomic.lsb_pad = (flags & 0x2) ? H5T_PAD_ONE : H5T_PAD_ZERO; + dt->u.atomic.msb_pad = (flags & 0x4) ? H5T_PAD_ONE : H5T_PAD_ZERO; + dt->u.atomic.u.f.pad = (flags & 0x8) ? H5T_PAD_ONE : H5T_PAD_ZERO; + switch ((flags >> 4) & 0x03) { + case 0: + dt->u.atomic.u.f.norm = H5T_NORM_NONE; + break; + case 1: + dt->u.atomic.u.f.norm = H5T_NORM_MSBSET; + break; + case 2: + dt->u.atomic.u.f.norm = H5T_NORM_IMPLIED; + break; + default: + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "unknown floating-point normalization"); + } + dt->u.atomic.u.f.sign = (flags >> 8) & 0xff; + UINT16DECODE(*pp, dt->u.atomic.offset); + UINT16DECODE(*pp, dt->u.atomic.prec); + dt->u.atomic.u.f.epos = *(*pp)++; + dt->u.atomic.u.f.esize = *(*pp)++; + assert(dt->u.atomic.u.f.esize > 0); + dt->u.atomic.u.f.mpos = *(*pp)++; + dt->u.atomic.u.f.msize = *(*pp)++; + assert(dt->u.atomic.u.f.msize > 0); + UINT32DECODE(*pp, dt->u.atomic.u.f.ebias); + break; case H5T_COMPOUND: - /* - * Compound data types... - */ - dt->u.compnd.nmembs = flags & 0xffff; - assert(dt->u.compnd.nmembs > 0); - dt->u.compnd.nalloc = dt->u.compnd.nmembs; - dt->u.compnd.memb = H5MM_calloc(dt->u.compnd.nalloc* - sizeof(H5T_member_t)); + /* + * Compound data types... + */ + dt->u.compnd.nmembs = flags & 0xffff; + assert(dt->u.compnd.nmembs > 0); + dt->u.compnd.nalloc = dt->u.compnd.nmembs; + dt->u.compnd.memb = H5MM_calloc(dt->u.compnd.nalloc* + sizeof(H5T_cmemb_t)); if (NULL==dt->u.compnd.memb) { HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); } - for (i = 0; i < dt->u.compnd.nmembs; i++) { - dt->u.compnd.memb[i].name = H5MM_xstrdup((const char *)*pp); + for (i = 0; i < dt->u.compnd.nmembs; i++) { + dt->u.compnd.memb[i].name = H5MM_xstrdup((const char *)*pp); /*multiple of 8 w/ null terminator */ - *pp += ((HDstrlen((const char *)*pp) + 8) / 8) * 8; - UINT32DECODE(*pp, dt->u.compnd.memb[i].offset); - dt->u.compnd.memb[i].ndims = *(*pp)++; - assert(dt->u.compnd.memb[i].ndims <= 4); - *pp += 3; /*reserved bytes */ + *pp += ((HDstrlen((const char *)*pp) + 8) / 8) * 8; + UINT32DECODE(*pp, dt->u.compnd.memb[i].offset); + dt->u.compnd.memb[i].ndims = *(*pp)++; + assert(dt->u.compnd.memb[i].ndims <= 4); + *pp += 3; /*reserved bytes */ /* Dimension permutation */ - UINT32DECODE(*pp, perm_word); - dt->u.compnd.memb[i].perm[0] = (perm_word >> 0) & 0xff; - dt->u.compnd.memb[i].perm[1] = (perm_word >> 8) & 0xff; - dt->u.compnd.memb[i].perm[2] = (perm_word >> 16) & 0xff; - dt->u.compnd.memb[i].perm[3] = (perm_word >> 24) & 0xff; + UINT32DECODE(*pp, perm_word); + dt->u.compnd.memb[i].perm[0] = (perm_word >> 0) & 0xff; + dt->u.compnd.memb[i].perm[1] = (perm_word >> 8) & 0xff; + dt->u.compnd.memb[i].perm[2] = (perm_word >> 16) & 0xff; + dt->u.compnd.memb[i].perm[3] = (perm_word >> 24) & 0xff; dt->u.compnd.memb[i].type = H5MM_calloc (sizeof(H5T_t)); /* Reserved */ *pp += 4; /* Dimension sizes */ - for (j=0; j<4; j++) { - UINT32DECODE(*pp, dt->u.compnd.memb[i].dim[j]); - } + for (j=0; j<4; j++) { + UINT32DECODE(*pp, dt->u.compnd.memb[i].dim[j]); + } if (NULL==dt->u.compnd.memb[i].type) { HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); } H5F_addr_undef (&(dt->u.compnd.memb[i].type->ent.header)); - if (H5O_dtype_decode_helper(pp, dt->u.compnd.memb[i].type)<0) { - for (j=0; j<=i; j++) H5MM_xfree(dt->u.compnd.memb[j].name); - H5MM_xfree(dt->u.compnd.memb); - HRETURN_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, - "can't decode member type"); - } + if (H5O_dtype_decode_helper(pp, dt->u.compnd.memb[i].type)<0) { + for (j=0; j<=i; j++) H5MM_xfree(dt->u.compnd.memb[j].name); + H5MM_xfree(dt->u.compnd.memb); + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, + "unable to decode member type"); + } /* Total member size */ dt->u.compnd.memb[i].size = dt->u.compnd.memb[i].type->size; for (j=0; j<dt->u.compnd.memb[i].ndims; j++) { dt->u.compnd.memb[i].size *= dt->u.compnd.memb[i].dim[j]; } - } - break; + } + break; + + case H5T_ENUM: + /* + * Enumeration data types... + */ + dt->u.enumer.nmembs = dt->u.enumer.nalloc = flags & 0xffff; + assert(dt->u.enumer.nmembs>=0); + if (NULL==(dt->parent=H5MM_calloc(sizeof(H5T_t)))) { + HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, + "memory allocation failed"); + } + H5F_addr_undef(&(dt->parent->ent.header)); + if (H5O_dtype_decode_helper(pp, dt->parent)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, + "unable to decode parent data type"); + } + if (NULL==(dt->u.enumer.name=H5MM_calloc(dt->u.enumer.nalloc * + sizeof(char*))) || + NULL==(dt->u.enumer.value=H5MM_calloc(dt->u.enumer.nalloc * + dt->parent->size))) { + HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, + "memory allocation failed"); + } + + /* Names, each a multiple of 8 with null termination */ + for (i=0; i<dt->u.enumer.nmembs; i++) { + dt->u.enumer.name[i] = H5MM_xstrdup((const char*)*pp); + *pp += ((HDstrlen((const char*)*pp)+8)/8)*8; + } + + /* Values */ + HDmemcpy(dt->u.enumer.value, *pp, + dt->u.enumer.nmembs * dt->parent->size); + break; case H5T_REFERENCE: - dt->u.atomic.order = H5T_ORDER_NONE; - dt->u.atomic.prec = 8 * dt->size; - dt->u.atomic.offset = 0; - dt->u.atomic.lsb_pad = H5T_PAD_ZERO; - dt->u.atomic.msb_pad = H5T_PAD_ZERO; - dt->u.atomic.u.r.rtype = flags & 0x0f; - break; + dt->u.atomic.order = H5T_ORDER_NONE; + dt->u.atomic.prec = 8 * dt->size; + dt->u.atomic.offset = 0; + dt->u.atomic.lsb_pad = H5T_PAD_ZERO; + dt->u.atomic.msb_pad = H5T_PAD_ZERO; + dt->u.atomic.u.r.rtype = flags & 0x0f; + break; default: - if (flags) { - HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "class flags are non-zero"); - } - break; + if (flags) { + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "class flags are non-zero"); + } + break; } FUNC_LEAVE(SUCCEED); } /*------------------------------------------------------------------------- - * Function: H5O_dtype_encode_helper + * Function: H5O_dtype_encode_helper * - * Purpose: Encodes a data type. + * Purpose: Encodes a data type. * - * Return: Non-negative on success/Negative on failure + * Return: Non-negative on success/Negative on failure * - * Programmer: Robb Matzke - * Monday, December 8, 1997 + * Programmer: Robb Matzke + * Monday, December 8, 1997 * * Modifications: * @@ -253,10 +287,10 @@ H5O_dtype_decode_helper(const uint8_t **pp, H5T_t *dt) static herr_t H5O_dtype_encode_helper(uint8_t **pp, const H5T_t *dt) { - uintn flags = 0; - uintn perm_word; - char *hdr = (char *)*pp; - intn i, j; + uintn flags = 0; + uintn perm_word; + char *hdr = (char *)*pp; + intn i, j; size_t n, z; FUNC_ENTER(H5O_dtype_encode_helper, FAIL); @@ -271,56 +305,56 @@ H5O_dtype_encode_helper(uint8_t **pp, const H5T_t *dt) switch (dt->type) { case H5T_INTEGER: - /* - * Integer data types... - */ - switch (dt->u.atomic.order) { - case H5T_ORDER_LE: - break; /*nothing */ - case H5T_ORDER_BE: - flags |= 0x01; - break; - default: - HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "byte order is not supported in file format yet"); - } - - switch (dt->u.atomic.lsb_pad) { - case H5T_PAD_ZERO: - break; /*nothing */ - case H5T_PAD_ONE: - flags |= 0x02; - break; - default: - HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "bit padding is not supported in file format yet"); - } - - switch (dt->u.atomic.msb_pad) { - case H5T_PAD_ZERO: - break; /*nothing */ - case H5T_PAD_ONE: - flags |= 0x04; - break; - default: - HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "bit padding is not supported in file format yet"); - } - - switch (dt->u.atomic.u.i.sign) { - case H5T_SGN_NONE: - break; /*nothing */ - case H5T_SGN_2: - flags |= 0x08; - break; - default: - HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "sign scheme is not supported in file format yet"); - } - - UINT16ENCODE(*pp, dt->u.atomic.offset); - UINT16ENCODE(*pp, dt->u.atomic.prec); - break; + /* + * Integer data types... + */ + switch (dt->u.atomic.order) { + case H5T_ORDER_LE: + break; /*nothing */ + case H5T_ORDER_BE: + flags |= 0x01; + break; + default: + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "byte order is not supported in file format yet"); + } + + switch (dt->u.atomic.lsb_pad) { + case H5T_PAD_ZERO: + break; /*nothing */ + case H5T_PAD_ONE: + flags |= 0x02; + break; + default: + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "bit padding is not supported in file format yet"); + } + + switch (dt->u.atomic.msb_pad) { + case H5T_PAD_ZERO: + break; /*nothing */ + case H5T_PAD_ONE: + flags |= 0x04; + break; + default: + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "bit padding is not supported in file format yet"); + } + + switch (dt->u.atomic.u.i.sign) { + case H5T_SGN_NONE: + break; /*nothing */ + case H5T_SGN_2: + flags |= 0x08; + break; + default: + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "sign scheme is not supported in file format yet"); + } + + UINT16ENCODE(*pp, dt->u.atomic.offset); + UINT16ENCODE(*pp, dt->u.atomic.prec); + break; case H5T_STRING: /* @@ -337,138 +371,164 @@ H5O_dtype_encode_helper(uint8_t **pp, const H5T_t *dt) break; case H5T_FLOAT: - /* - * Floating-point types... - */ - switch (dt->u.atomic.order) { - case H5T_ORDER_LE: - break; /*nothing */ - case H5T_ORDER_BE: - flags |= 0x01; - break; - default: - HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "byte order is not supported in file format yet"); - } - - switch (dt->u.atomic.lsb_pad) { - case H5T_PAD_ZERO: - break; /*nothing */ - case H5T_PAD_ONE: - flags |= 0x02; - break; - default: - HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "bit padding is not supported in file format yet"); - } - - switch (dt->u.atomic.msb_pad) { - case H5T_PAD_ZERO: - break; /*nothing */ - case H5T_PAD_ONE: - flags |= 0x04; - break; - default: - HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "bit padding is not supported in file format yet"); - } - - switch (dt->u.atomic.u.f.pad) { - case H5T_PAD_ZERO: - break; /*nothing */ - case H5T_PAD_ONE: - flags |= 0x08; - break; - default: - HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "bit padding is not supported in file format yet"); - } - - switch (dt->u.atomic.u.f.norm) { - case H5T_NORM_NONE: - break; /*nothing */ - case H5T_NORM_MSBSET: - flags |= 0x10; - break; - case H5T_NORM_IMPLIED: - flags |= 0x20; - break; - default: - HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, - "normalization scheme is not supported in file " - "format yet"); - } - - flags |= (dt->u.atomic.u.f.sign << 8) & 0xff00; - UINT16ENCODE(*pp, dt->u.atomic.offset); - UINT16ENCODE(*pp, dt->u.atomic.prec); + /* + * Floating-point types... + */ + switch (dt->u.atomic.order) { + case H5T_ORDER_LE: + break; /*nothing */ + case H5T_ORDER_BE: + flags |= 0x01; + break; + default: + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "byte order is not supported in file format yet"); + } + + switch (dt->u.atomic.lsb_pad) { + case H5T_PAD_ZERO: + break; /*nothing */ + case H5T_PAD_ONE: + flags |= 0x02; + break; + default: + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "bit padding is not supported in file format yet"); + } + + switch (dt->u.atomic.msb_pad) { + case H5T_PAD_ZERO: + break; /*nothing */ + case H5T_PAD_ONE: + flags |= 0x04; + break; + default: + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "bit padding is not supported in file format yet"); + } + + switch (dt->u.atomic.u.f.pad) { + case H5T_PAD_ZERO: + break; /*nothing */ + case H5T_PAD_ONE: + flags |= 0x08; + break; + default: + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "bit padding is not supported in file format yet"); + } + + switch (dt->u.atomic.u.f.norm) { + case H5T_NORM_NONE: + break; /*nothing */ + case H5T_NORM_MSBSET: + flags |= 0x10; + break; + case H5T_NORM_IMPLIED: + flags |= 0x20; + break; + default: + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "normalization scheme is not supported in file " + "format yet"); + } + + flags |= (dt->u.atomic.u.f.sign << 8) & 0xff00; + UINT16ENCODE(*pp, dt->u.atomic.offset); + UINT16ENCODE(*pp, dt->u.atomic.prec); assert (dt->u.atomic.u.f.epos<=255); - *(*pp)++ = (uint8_t)(dt->u.atomic.u.f.epos); + *(*pp)++ = (uint8_t)(dt->u.atomic.u.f.epos); assert (dt->u.atomic.u.f.esize<=255); - *(*pp)++ = (uint8_t)(dt->u.atomic.u.f.esize); + *(*pp)++ = (uint8_t)(dt->u.atomic.u.f.esize); assert (dt->u.atomic.u.f.mpos<=255); - *(*pp)++ = (uint8_t)(dt->u.atomic.u.f.mpos); + *(*pp)++ = (uint8_t)(dt->u.atomic.u.f.mpos); assert (dt->u.atomic.u.f.msize<=255); - *(*pp)++ = (uint8_t)(dt->u.atomic.u.f.msize); - UINT32ENCODE(*pp, dt->u.atomic.u.f.ebias); - break; + *(*pp)++ = (uint8_t)(dt->u.atomic.u.f.msize); + UINT32ENCODE(*pp, dt->u.atomic.u.f.ebias); + break; case H5T_COMPOUND: - /* - * Compound data types... - */ - flags = dt->u.compnd.nmembs & 0xffff; - for (i = 0; i < dt->u.compnd.nmembs; i++) { + /* + * Compound data types... + */ + flags = dt->u.compnd.nmembs & 0xffff; + for (i=0; i<dt->u.compnd.nmembs; i++) { /* Name, multiple of eight bytes */ - HDstrcpy ((char*)(*pp), dt->u.compnd.memb[i].name); - n = HDstrlen(dt->u.compnd.memb[i].name); + HDstrcpy((char*)(*pp), dt->u.compnd.memb[i].name); + n = HDstrlen(dt->u.compnd.memb[i].name); for (z=n+1; z%8; z++) (*pp)[z] = '\0'; *pp += z; /* Member offset */ - UINT32ENCODE(*pp, dt->u.compnd.memb[i].offset); + UINT32ENCODE(*pp, dt->u.compnd.memb[i].offset); /* Dimensionality */ - *(*pp)++ = dt->u.compnd.memb[i].ndims; - assert(dt->u.compnd.memb[i].ndims <= 4); + *(*pp)++ = dt->u.compnd.memb[i].ndims; + assert(dt->u.compnd.memb[i].ndims <= 4); /* Reserved */ - *(*pp)++ = '\0'; - *(*pp)++ = '\0'; - *(*pp)++ = '\0'; + *(*pp)++ = '\0'; + *(*pp)++ = '\0'; + *(*pp)++ = '\0'; /* Dimension permutation */ - for (j = 0, perm_word = 0; j < dt->u.compnd.memb[i].ndims; j++) { - perm_word |= dt->u.compnd.memb[i].perm[j] << (8 * j); - } - UINT32ENCODE(*pp, perm_word); + for (j = 0, perm_word = 0; j < dt->u.compnd.memb[i].ndims; j++) { + perm_word |= dt->u.compnd.memb[i].perm[j] << (8 * j); + } + UINT32ENCODE(*pp, perm_word); /* Reserved */ UINT32ENCODE(*pp, 0); /* Dimensions */ - for (j=0; j<dt->u.compnd.memb[i].ndims; j++) { - UINT32ENCODE(*pp, dt->u.compnd.memb[i].dim[j]); - } + for (j=0; j<dt->u.compnd.memb[i].ndims; j++) { + UINT32ENCODE(*pp, dt->u.compnd.memb[i].dim[j]); + } for (/*void*/; j<4; j++) { UINT32ENCODE(*pp, 0); } /* Subtype */ - if (H5O_dtype_encode_helper(pp, dt->u.compnd.memb[i].type)<0) { - HRETURN_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, - "can't encode member type"); - } - } - break; + if (H5O_dtype_encode_helper(pp, dt->u.compnd.memb[i].type)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, + "unable to encode member type"); + } + } + break; + + case H5T_ENUM: + /* + * Enumeration data types... + */ + flags = dt->u.enumer.nmembs & 0xffff; + /* Parent type */ + if (H5O_dtype_encode_helper(pp, dt->parent)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, + "unable to encode parent data type"); + } + + /* Names, each a multiple of eight bytes */ + for (i=0; i<dt->u.enumer.nmembs; i++) { + HDstrcpy((char*)(*pp), dt->u.enumer.name[i]); + n = HDstrlen(dt->u.enumer.name[i]); + for (z=n+1; z%8; z++) (*pp)[z] = '\0'; + *pp += z; + } + + /* Values */ + HDmemcpy(*pp, dt->u.enumer.value, + dt->u.enumer.nmembs * dt->parent->size); + *pp += dt->u.enumer.nmembs * dt->parent->size; + break; + case H5T_REFERENCE: - flags |= (dt->u.atomic.u.r.rtype & 0x0f); - break; - + flags |= (dt->u.atomic.u.r.rtype & 0x0f); + break; + default: - /*nothing */ - break; + /*nothing */ + break; } *hdr++ = ((uintn)(dt->type) & 0x0f) | (H5O_DTYPE_VERSION<<4); @@ -484,16 +544,16 @@ H5O_dtype_encode_helper(uint8_t **pp, const H5T_t *dt) H5O_dtype_decode PURPOSE Decode a datatype message and return a pointer to a memory struct - with the decoded information + with the decoded information USAGE void *H5O_dtype_decode(f, raw_size, p) - H5F_t *f; IN: pointer to the HDF5 file struct - size_t raw_size; IN: size of the raw information buffer - const uint8 *p; IN: the raw information buffer + H5F_t *f; IN: pointer to the HDF5 file struct + size_t raw_size; IN: size of the raw information buffer + const uint8 *p; IN: the raw information buffer RETURNS Pointer to the new message in native order on success, NULL on failure DESCRIPTION - This function decodes the "raw" disk form of a simple datatype message + This function decodes the "raw" disk form of a simple datatype message into a struct in memory native format. The struct is allocated within this function using malloc() and is returned to the caller. --------------------------------------------------------------------------*/ @@ -501,7 +561,7 @@ static void * H5O_dtype_decode(H5F_t __unused__ *f, const uint8_t *p, H5O_shared_t __unused__ *sh) { - H5T_t *dt = NULL; + H5T_t *dt = NULL; FUNC_ENTER(H5O_dtype_decode, NULL); @@ -515,9 +575,9 @@ H5O_dtype_decode(H5F_t __unused__ *f, const uint8_t *p, H5F_addr_undef (&(dt->ent.header)); if (H5O_dtype_decode_helper(&p, dt) < 0) { - H5MM_xfree(dt); - HRETURN_ERROR(H5E_DATATYPE, H5E_CANTDECODE, NULL, - "can't decode type"); + H5MM_xfree(dt); + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTDECODE, NULL, + "can't decode type"); } FUNC_LEAVE(dt); } @@ -529,20 +589,20 @@ H5O_dtype_decode(H5F_t __unused__ *f, const uint8_t *p, Encode a simple datatype message USAGE herr_t H5O_dtype_encode(f, raw_size, p, mesg) - H5F_t *f; IN: pointer to the HDF5 file struct - size_t raw_size; IN: size of the raw information buffer - const uint8 *p; IN: the raw information buffer - const void *mesg; IN: Pointer to the simple datatype struct + H5F_t *f; IN: pointer to the HDF5 file struct + size_t raw_size; IN: size of the raw information buffer + const uint8 *p; IN: the raw information buffer + const void *mesg; IN: Pointer to the simple datatype struct RETURNS Non-negative on success/Negative on failure DESCRIPTION - This function encodes the native memory form of the simple datatype + This function encodes the native memory form of the simple datatype message in the "raw" disk form. --------------------------------------------------------------------------*/ static herr_t H5O_dtype_encode(H5F_t __unused__ *f, uint8_t *p, const void *mesg) { - const H5T_t *dt = (const H5T_t *) mesg; + const H5T_t *dt = (const H5T_t *) mesg; FUNC_ENTER(H5O_dtype_encode, FAIL); @@ -553,8 +613,8 @@ H5O_dtype_encode(H5F_t __unused__ *f, uint8_t *p, const void *mesg) /* encode */ if (H5O_dtype_encode_helper(&p, dt) < 0) { - HRETURN_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, - "can't encode type"); + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, + "can't encode type"); } FUNC_LEAVE(SUCCEED); } @@ -566,21 +626,21 @@ H5O_dtype_encode(H5F_t __unused__ *f, uint8_t *p, const void *mesg) Copies a message from MESG to DEST, allocating DEST if necessary. USAGE void *H5O_dtype_copy(mesg, dest) - const void *mesg; IN: Pointer to the source simple datatype - struct - const void *dest; IN: Pointer to the destination simple - datatype struct + const void *mesg; IN: Pointer to the source simple datatype + struct + const void *dest; IN: Pointer to the destination simple + datatype struct RETURNS Pointer to DEST on success, NULL on failure DESCRIPTION - This function copies a native (memory) simple datatype message, + This function copies a native (memory) simple datatype message, allocating the destination structure if necessary. --------------------------------------------------------------------------*/ static void * H5O_dtype_copy(const void *_src, void *_dst) { - const H5T_t *src = (const H5T_t *) _src; - H5T_t *dst = NULL; + const H5T_t *src = (const H5T_t *) _src; + H5T_t *dst = NULL; FUNC_ENTER(H5O_dtype_copy, NULL); @@ -589,13 +649,13 @@ H5O_dtype_copy(const void *_src, void *_dst) /* copy */ if (NULL == (dst = H5T_copy(src, H5T_COPY_ALL))) { - HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "can't copy type"); + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "can't copy type"); } /* was result already allocated? */ if (_dst) { - *((H5T_t *) _dst) = *dst; - H5MM_xfree(dst); - dst = (H5T_t *) _dst; + *((H5T_t *) _dst) = *dst; + H5MM_xfree(dst); + dst = (H5T_t *) _dst; } FUNC_LEAVE((void *) dst); } @@ -607,21 +667,21 @@ H5O_dtype_copy(const void *_src, void *_dst) Return the raw message size in bytes USAGE void *H5O_dtype_size(f, mesg) - H5F_t *f; IN: pointer to the HDF5 file struct - const void *mesg; IN: Pointer to the source simple datatype struct + H5F_t *f; IN: pointer to the HDF5 file struct + const void *mesg; IN: Pointer to the source simple datatype struct RETURNS Size of message on success, 0 on failure DESCRIPTION - This function returns the size of the raw simple datatype message on + This function returns the size of the raw simple datatype message on success. (Not counting the message type or size fields, only the data portion of the message). It doesn't take into account alignment. --------------------------------------------------------------------------*/ static size_t H5O_dtype_size(H5F_t *f, const void *mesg) { - intn i; - size_t ret_value = 8; - const H5T_t *dt = (const H5T_t *) mesg; + intn i; + size_t ret_value = 8; + const H5T_t *dt = (const H5T_t *) mesg; FUNC_ENTER(H5O_dtype_size, 0); @@ -629,44 +689,52 @@ H5O_dtype_size(H5F_t *f, const void *mesg) switch (dt->type) { case H5T_INTEGER: - ret_value += 4; - break; + ret_value += 4; + break; case H5T_FLOAT: - ret_value += 12; - break; + ret_value += 12; + break; case H5T_COMPOUND: - for (i = 0; i < dt->u.compnd.nmembs; i++) { - ret_value += ((HDstrlen(dt->u.compnd.memb[i].name) + 8) / 8) * 8; + for (i=0; i<dt->u.compnd.nmembs; i++) { + ret_value += ((HDstrlen(dt->u.compnd.memb[i].name) + 8) / 8) * 8; ret_value += 4 + /*member offset*/ 1 + /*dimensionality*/ 3 + /*reserved*/ 4 + /*permutation*/ 4 + /*reserved*/ 16; /*dimensions*/ - ret_value += H5O_dtype_size(f, dt->u.compnd.memb[i].type); - } - break; + ret_value += H5O_dtype_size(f, dt->u.compnd.memb[i].type); + } + break; + + case H5T_ENUM: + ret_value += H5O_dtype_size(f, dt->parent); + for (i=0; i<dt->u.enumer.nmembs; i++) { + ret_value += ((HDstrlen(dt->u.enumer.name[i])+8)/8)*8; + } + ret_value += dt->u.enumer.nmembs * dt->parent->size; + break; default: - /*no properties */ - break; + /*no properties */ + break; } FUNC_LEAVE(ret_value); } /*------------------------------------------------------------------------- - * Function: H5O_dtype_reset + * Function: H5O_dtype_reset * - * Purpose: Frees resources within a data type message, but doesn't free - * the message itself. + * Purpose: Frees resources within a data type message, but doesn't free + * the message itself. * - * Return: Non-negative on success/Negative on failure + * Return: Non-negative on success/Negative on failure * - * Programmer: Robb Matzke - * Tuesday, December 9, 1997 + * Programmer: Robb Matzke + * Tuesday, December 9, 1997 * * Modifications: * @@ -675,19 +743,19 @@ H5O_dtype_size(H5F_t *f, const void *mesg) static herr_t H5O_dtype_reset(void *_mesg) { - H5T_t *dt = (H5T_t *) _mesg; - H5T_t *tmp = NULL; + H5T_t *dt = (H5T_t *) _mesg; + H5T_t *tmp = NULL; FUNC_ENTER(H5O_dtype_reset, FAIL); if (dt) { - if (NULL==(tmp = H5MM_malloc(sizeof(H5T_t)))) { + if (NULL==(tmp = H5MM_malloc(sizeof(H5T_t)))) { HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); } - *tmp = *dt; - H5T_close(tmp); - HDmemset(dt, 0, sizeof(H5T_t)); + *tmp = *dt; + H5T_close(tmp); + HDmemset(dt, 0, sizeof(H5T_t)); } FUNC_LEAVE(SUCCEED); } @@ -702,7 +770,7 @@ H5O_dtype_reset(void *_mesg) * Return: Non-negative on success/Negative on failure * * Programmer: Robb Matzke - * Monday, June 1, 1998 + * Monday, June 1, 1998 * * Modifications: * @@ -739,7 +807,7 @@ H5O_dtype_get_share (H5F_t __unused__ *f, const void *_mesg, * Return: Non-negative on success/Negative on failure * * Programmer: Robb Matzke - * Thursday, June 4, 1998 + * Thursday, June 4, 1998 * * Modifications: * @@ -769,26 +837,28 @@ H5O_dtype_set_share (H5F_t __unused__ *f, void *_mesg/*in,out*/, Prints debugging information for a data type message USAGE void *H5O_dtype_debug(f, mesg, stream, indent, fwidth) - H5F_t *f; IN: pointer to the HDF5 file struct - const void *mesg; IN: Pointer to the source simple datatype - struct - FILE *stream; IN: Pointer to the stream for output data - intn indent; IN: Amount to indent information by - intn fwidth; IN: Field width (?) + H5F_t *f; IN: pointer to the HDF5 file struct + const void *mesg; IN: Pointer to the source simple datatype + struct + FILE *stream; IN: Pointer to the stream for output data + intn indent; IN: Amount to indent information by + intn fwidth; IN: Field width (?) RETURNS Non-negative on success/Negative on failure DESCRIPTION - This function prints debugging output to the stream passed as a + This function prints debugging output to the stream passed as a parameter. --------------------------------------------------------------------------*/ static herr_t -H5O_dtype_debug(H5F_t *f, const void *mesg, FILE * stream, - intn indent, intn fwidth) +H5O_dtype_debug(H5F_t *f, const void *mesg, FILE *stream, + intn indent, intn fwidth) { - const H5T_t *dt = (const H5T_t *) mesg; - const char *s; - char buf[256]; - intn i, j; + const H5T_t *dt = (const H5T_t*)mesg; + const char *s; + char buf[256]; + intn i, j; + size_t k; + FUNC_ENTER(H5O_dtype_debug, FAIL); @@ -801,213 +871,236 @@ H5O_dtype_debug(H5F_t *f, const void *mesg, FILE * stream, switch (dt->type) { case H5T_INTEGER: - s = "integer"; - break; + s = "integer"; + break; case H5T_FLOAT: - s = "floating-point"; - break; + s = "floating-point"; + break; case H5T_TIME: - s = "date and time"; - break; + s = "date and time"; + break; case H5T_STRING: - s = "text string"; - break; + s = "text string"; + break; case H5T_BITFIELD: - s = "bit field"; - break; + s = "bit field"; + break; case H5T_OPAQUE: - s = "opaque"; - break; + s = "opaque"; + break; case H5T_COMPOUND: - s = "compound"; - break; + s = "compound"; + break; + case H5T_ENUM: + s = "enum"; + break; default: - sprintf(buf, "H5T_CLASS_%d", (int) (dt->type)); - s = buf; - break; + sprintf(buf, "H5T_CLASS_%d", (int) (dt->type)); + s = buf; + break; } fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, - "Type class:", - s); + "Type class:", + s); fprintf(stream, "%*s%-*s %lu byte%s\n", indent, "", fwidth, - "Size:", - (unsigned long) (dt->size), 1 == dt->size ? "" : "s"); + "Size:", + (unsigned long)(dt->size), 1==dt->size?"":"s"); if (H5T_COMPOUND == dt->type) { - fprintf(stream, "%*s%-*s %d\n", indent, "", fwidth, - "Number of members:", - dt->u.compnd.nmembs); - for (i = 0; i < dt->u.compnd.nmembs; i++) { - sprintf(buf, "Member %d:", i); - fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, - buf, - dt->u.compnd.memb[i].name); - fprintf(stream, "%*s%-*s %lu\n", indent + 3, "", MAX(0, fwidth-3), - "Byte offset:", - (unsigned long) (dt->u.compnd.memb[i].offset)); - fprintf(stream, "%*s%-*s %d%s\n", indent + 3, "", MAX(0, fwidth-3), - "Dimensionality:", - dt->u.compnd.memb[i].ndims, - 0 == dt->u.compnd.memb[i].ndims ? " (scalar)" : ""); - if (dt->u.compnd.memb[i].ndims > 0) { - fprintf(stream, "%*s%-*s {", indent + 3, "", MAX(0, fwidth-3), - "Size:"); - for (j = 0; j < dt->u.compnd.memb[i].ndims; j++) { - fprintf(stream, "%s%lu", j ? ", " : "", - (unsigned long) (dt->u.compnd.memb[i].dim[j])); - } - fprintf(stream, "}\n"); - fprintf(stream, "%*s%-*s {", indent + 3, "", MAX(0, fwidth-3), - "Permutation:"); - for (j = 0; j < dt->u.compnd.memb[i].ndims; j++) { - fprintf(stream, "%s%lu", j ? ", " : "", - (unsigned long) (dt->u.compnd.memb[i].perm[j])); - } - fprintf(stream, "}\n"); - } - H5O_dtype_debug(f, dt->u.compnd.memb[i].type, stream, - indent + 3, MAX(0, fwidth - 3)); - } + fprintf(stream, "%*s%-*s %d\n", indent, "", fwidth, + "Number of members:", + dt->u.compnd.nmembs); + for (i=0; i<dt->u.compnd.nmembs; i++) { + sprintf(buf, "Member %d:", i); + fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, + buf, + dt->u.compnd.memb[i].name); + fprintf(stream, "%*s%-*s %lu\n", indent+3, "", MAX(0, fwidth-3), + "Byte offset:", + (unsigned long) (dt->u.compnd.memb[i].offset)); + fprintf(stream, "%*s%-*s %d%s\n", indent+3, "", MAX(0, fwidth-3), + "Dimensionality:", + dt->u.compnd.memb[i].ndims, + 0==dt->u.compnd.memb[i].ndims?" (scalar)":""); + if (dt->u.compnd.memb[i].ndims>0) { + fprintf(stream, "%*s%-*s {", indent+3, "", MAX(0, fwidth-3), + "Size:"); + for (j=0; j<dt->u.compnd.memb[i].ndims; j++) { + fprintf(stream, "%s%lu", j?", ":"", + (unsigned long)(dt->u.compnd.memb[i].dim[j])); + } + fprintf(stream, "}\n"); + fprintf(stream, "%*s%-*s {", indent+3, "", MAX(0, fwidth-3), + "Permutation:"); + for (j=0; j<dt->u.compnd.memb[i].ndims; j++) { + fprintf(stream, "%s%lu", j?", ":"", + (unsigned long)(dt->u.compnd.memb[i].perm[j])); + } + fprintf(stream, "}\n"); + } + H5O_dtype_debug(f, dt->u.compnd.memb[i].type, stream, + indent+3, MAX(0, fwidth - 3)); + } + } else if (H5T_ENUM==dt->type) { + fprintf(stream, "%*s%s\n", indent, "", "Base type:"); + H5O_dtype_debug(f, dt->parent, stream, indent+3, MAX(0, fwidth-3)); + fprintf(stream, "%*s%-*s %d\n", indent, "", fwidth, + "Number of members:", + dt->u.enumer.nmembs); + for (i=0; i<dt->u.enumer.nmembs; i++) { + sprintf(buf, "Member %d:", i); + fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, + buf, + dt->u.enumer.name[i]); + fprintf(stream, "%*s%-*s 0x", indent, "", fwidth, + "Raw bytes of value:"); + for (k=0; k<dt->parent->size; k++) { + fprintf(stream, "%02x", + dt->u.enumer.value[i*dt->parent->size+k]); + } + fprintf(stream, "\n"); + } + } else { - switch (dt->u.atomic.order) { - case H5T_ORDER_LE: - s = "little endian"; - break; - case H5T_ORDER_BE: - s = "big endian"; - break; - case H5T_ORDER_VAX: - s = "VAX"; - break; - case H5T_ORDER_NONE: - s = "none"; - break; - default: - sprintf(buf, "H5T_ORDER_%d", dt->u.atomic.order); - s = buf; - break; - } - fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, - "Byte order:", - s); - - fprintf(stream, "%*s%-*s %lu bit%s\n", indent, "", fwidth, - "Precision:", - (unsigned long) (dt->u.atomic.prec), - 1 == dt->u.atomic.prec ? "" : "s"); - - fprintf(stream, "%*s%-*s %lu bit%s\n", indent, "", fwidth, - "Offset:", - (unsigned long) (dt->u.atomic.offset), - 1 == dt->u.atomic.offset ? "" : "s"); - - switch (dt->u.atomic.lsb_pad) { - case H5T_PAD_ZERO: - s = "zero"; - break; - case H5T_PAD_ONE: - s = "one"; - break; - default: - s = "pad?"; - break; - } - fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, - "Low pad type:", s); - - switch (dt->u.atomic.msb_pad) { - case H5T_PAD_ZERO: - s = "zero"; - break; - case H5T_PAD_ONE: - s = "one"; - break; - default: - s = "pad?"; - break; - } - fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, - "High pad type:", s); - - if (H5T_FLOAT == dt->type) { - switch (dt->u.atomic.u.f.pad) { - case H5T_PAD_ZERO: - s = "zero"; - break; - case H5T_PAD_ONE: - s = "one"; - break; - default: - if (dt->u.atomic.u.f.pad < 0) { - sprintf(buf, "H5T_PAD_%d", -(dt->u.atomic.u.f.pad)); - } else { - sprintf(buf, "bit-%d", dt->u.atomic.u.f.pad); - } - s = buf; - break; - } - fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, - "Internal pad type:", s); - - switch (dt->u.atomic.u.f.norm) { - case H5T_NORM_IMPLIED: - s = "implied"; - break; - case H5T_NORM_MSBSET: - s = "msb set"; - break; - case H5T_NORM_NONE: - s = "none"; - break; - default: - sprintf(buf, "H5T_NORM_%d", (int) (dt->u.atomic.u.f.norm)); - s = buf; - } - fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, - "Normalization:", s); - - fprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, - "Sign bit location:", - (unsigned long) (dt->u.atomic.u.f.sign)); - - fprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, - "Exponent location:", - (unsigned long) (dt->u.atomic.u.f.epos)); - - fprintf(stream, "%*s%-*s 0x%08lx\n", indent, "", fwidth, - "Exponent bias:", - (unsigned long) (dt->u.atomic.u.f.ebias)); - - fprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, - "Exponent size:", - (unsigned long) (dt->u.atomic.u.f.esize)); - - fprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, - "Mantissa location:", - (unsigned long) (dt->u.atomic.u.f.mpos)); - - fprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, - "Mantissa size:", - (unsigned long) (dt->u.atomic.u.f.msize)); - - } else if (H5T_INTEGER == dt->type) { - switch (dt->u.atomic.u.i.sign) { - case H5T_SGN_NONE: - s = "none"; - break; - case H5T_SGN_2: - s = "2's comp"; - break; - default: - sprintf(buf, "H5T_SGN_%d", (int) (dt->u.atomic.u.i.sign)); - s = buf; - break; - } - fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, - "Sign scheme:", s); - - } + switch (dt->u.atomic.order) { + case H5T_ORDER_LE: + s = "little endian"; + break; + case H5T_ORDER_BE: + s = "big endian"; + break; + case H5T_ORDER_VAX: + s = "VAX"; + break; + case H5T_ORDER_NONE: + s = "none"; + break; + default: + sprintf(buf, "H5T_ORDER_%d", dt->u.atomic.order); + s = buf; + break; + } + fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, + "Byte order:", + s); + + fprintf(stream, "%*s%-*s %lu bit%s\n", indent, "", fwidth, + "Precision:", + (unsigned long)(dt->u.atomic.prec), + 1==dt->u.atomic.prec?"":"s"); + + fprintf(stream, "%*s%-*s %lu bit%s\n", indent, "", fwidth, + "Offset:", + (unsigned long)(dt->u.atomic.offset), + 1==dt->u.atomic.offset?"":"s"); + + switch (dt->u.atomic.lsb_pad) { + case H5T_PAD_ZERO: + s = "zero"; + break; + case H5T_PAD_ONE: + s = "one"; + break; + default: + s = "pad?"; + break; + } + fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, + "Low pad type:", s); + + switch (dt->u.atomic.msb_pad) { + case H5T_PAD_ZERO: + s = "zero"; + break; + case H5T_PAD_ONE: + s = "one"; + break; + default: + s = "pad?"; + break; + } + fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, + "High pad type:", s); + + if (H5T_FLOAT == dt->type) { + switch (dt->u.atomic.u.f.pad) { + case H5T_PAD_ZERO: + s = "zero"; + break; + case H5T_PAD_ONE: + s = "one"; + break; + default: + if (dt->u.atomic.u.f.pad < 0) { + sprintf(buf, "H5T_PAD_%d", -(dt->u.atomic.u.f.pad)); + } else { + sprintf(buf, "bit-%d", dt->u.atomic.u.f.pad); + } + s = buf; + break; + } + fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, + "Internal pad type:", s); + + switch (dt->u.atomic.u.f.norm) { + case H5T_NORM_IMPLIED: + s = "implied"; + break; + case H5T_NORM_MSBSET: + s = "msb set"; + break; + case H5T_NORM_NONE: + s = "none"; + break; + default: + sprintf(buf, "H5T_NORM_%d", (int) (dt->u.atomic.u.f.norm)); + s = buf; + } + fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, + "Normalization:", s); + + fprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, + "Sign bit location:", + (unsigned long) (dt->u.atomic.u.f.sign)); + + fprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, + "Exponent location:", + (unsigned long) (dt->u.atomic.u.f.epos)); + + fprintf(stream, "%*s%-*s 0x%08lx\n", indent, "", fwidth, + "Exponent bias:", + (unsigned long) (dt->u.atomic.u.f.ebias)); + + fprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, + "Exponent size:", + (unsigned long) (dt->u.atomic.u.f.esize)); + + fprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, + "Mantissa location:", + (unsigned long) (dt->u.atomic.u.f.mpos)); + + fprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, + "Mantissa size:", + (unsigned long) (dt->u.atomic.u.f.msize)); + + } else if (H5T_INTEGER == dt->type) { + switch (dt->u.atomic.u.i.sign) { + case H5T_SGN_NONE: + s = "none"; + break; + case H5T_SGN_2: + s = "2's comp"; + break; + default: + sprintf(buf, "H5T_SGN_%d", (int) (dt->u.atomic.u.i.sign)); + s = buf; + break; + } + fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, + "Sign scheme:", s); + + } } FUNC_LEAVE(SUCCEED); @@ -86,12 +86,12 @@ H5RA_init_interface(void) /* The meta dataset type */ if (NULL==(type=H5T_create(H5T_COMPOUND, sizeof(H5RA_meta_t))) || - H5T_insert(type, "nelmts", HOFFSET(H5RA_meta_t, nelmts), - 0, NULL, NULL, H5I_object(H5T_NATIVE_HSIZE_g))<0 || - H5T_insert(type, "offset", HOFFSET(H5RA_meta_t, offset), - 0, NULL, NULL, H5I_object(H5T_NATIVE_HSSIZE_g))<0 || - H5T_insert(type, "nover", HOFFSET(H5RA_meta_t, nover), - 0, NULL, NULL, H5I_object(H5T_NATIVE_HSIZE_g))) { + H5T_struct_insert(type, "nelmts", HOFFSET(H5RA_meta_t, nelmts), + 0, NULL, NULL, H5I_object(H5T_NATIVE_HSIZE_g))<0 || + H5T_struct_insert(type, "offset", HOFFSET(H5RA_meta_t, offset), + 0, NULL, NULL, H5I_object(H5T_NATIVE_HSSIZE_g))<0 || + H5T_struct_insert(type, "nover", HOFFSET(H5RA_meta_t, nover), + 0, NULL, NULL, H5I_object(H5T_NATIVE_HSIZE_g))) { HRETURN_ERROR(H5E_RAGGED, H5E_CANTINIT, FAIL, "unable to define ragged array meta type"); } @@ -1154,7 +1154,7 @@ H5RA_read(H5RA_t *ra, hssize_t start_row, hsize_t nrows, H5T_t *type, /* Copy the part of the row from the raw dataset */ HDmemcpy(buf_out[i], raw_buf+i*raw_read_size[1]*type_size, - MIN(size[i], raw_read_size[1])*type_size); + (size_t)(MIN(size[i], raw_read_size[1])*type_size)); /* Copy the part of the row from the overflow dataset */ if (size[i]>raw_read_size[1]) { diff --git a/src/H5Shyper.c b/src/H5Shyper.c index 690c032..5c1863f 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -503,7 +503,7 @@ H5S_hyper_block_read (H5S_hyper_node_t *node, H5S_hyper_fhyper_info_t *fhyper_in */ HDmemcpy(fhyper_info->dst, node->cinfo.pos, - region_size*fhyper_info->elmt_size); + (size_t)(region_size*fhyper_info->elmt_size)); /* * Decrement the number of elements left in block to read & move the @@ -559,7 +559,7 @@ H5S_hyper_block_write (H5S_hyper_node_t *node, */ HDmemcpy(node->cinfo.pos, fhyper_info->src, - region_size*fhyper_info->elmt_size); + (size_t)(region_size*fhyper_info->elmt_size)); /* * Decrement the number of elements left in block to read & move the @@ -175,7 +175,7 @@ static herr_t H5T_init_interface(void) { H5T_t *dt = NULL; - hid_t fixedpt=-1, floatpt=-1, string=-1, compound=-1; + hid_t fixedpt=-1, floatpt=-1, string=-1, compound=-1, enum_type=-1; herr_t status; herr_t ret_value=FAIL; @@ -627,7 +627,7 @@ H5T_init_interface(void) dt->u.atomic.u.s.pad = H5T_STR_NULLTERM; if ((H5T_C_S1_g = H5I_register(H5I_DATATYPE, dt)) < 0) { HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, - "can't initialize H5T layer"); + "unable to initialize H5T layer"); } /*------------------------------------------------------------ @@ -653,7 +653,7 @@ H5T_init_interface(void) dt->u.atomic.u.s.pad = H5T_STR_SPACEPAD; if ((H5T_FORTRAN_S1_g = H5I_register(H5I_DATATYPE, dt)) < 0) { HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, - "can't initialize H5T layer"); + "unable to initialize H5T layer"); } /*------------------------------------------------------------ @@ -703,6 +703,7 @@ H5T_init_interface(void) floatpt = H5T_NATIVE_FLOAT; string = H5T_C_S1; compound = H5Tcreate(H5T_COMPOUND, 1); + enum_type = H5Tcreate(H5T_ENUM, 1); status = 0; /* * Register conversion functions beginning with the most general and @@ -726,6 +727,9 @@ H5T_init_interface(void) status |= H5Tregister(H5T_PERS_SOFT, "struct", compound, compound, H5T_conv_struct); + status |= H5Tregister(H5T_PERS_SOFT, "enum", + enum_type, enum_type, + H5T_conv_enum); status |= H5Tregister(H5T_PERS_HARD, "u32le_f64le", H5T_STD_U32LE_g, H5T_IEEE_F64LE_g, @@ -1047,6 +1051,7 @@ H5T_init_interface(void) ret_value = SUCCEED; done: if (compound>=0) H5Tclose(compound); + if (enum_type>=0) H5Tclose(enum_type); FUNC_LEAVE(ret_value); } @@ -1185,13 +1190,14 @@ H5Tcreate(H5T_class_t type, size_t size) /* create the type */ if (NULL == (dt = H5T_create(type, size))) { - HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't create type"); + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to create type"); } /* Make it an atom */ if ((ret_value = H5I_register(H5I_DATATYPE, dt)) < 0) { HRETURN_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, - "can't register data type atom"); + "unable to register data type atom"); } FUNC_LEAVE(ret_value); @@ -1390,14 +1396,14 @@ H5Tcopy(hid_t type_id) /* Copy */ if (NULL == (new_dt = H5T_copy(dt, H5T_COPY_TRANSIENT))) { - HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't copy"); + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy"); } /* Atomize result */ if ((ret_value = H5I_register(H5I_DATATYPE, new_dt)) < 0) { H5T_close(new_dt); HRETURN_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, - "can't register data type atom"); + "unable to register data type atom"); } FUNC_LEAVE(ret_value); @@ -1613,14 +1619,14 @@ H5Tget_size(hid_t type_id) /*------------------------------------------------------------------------- * Function: H5Tset_size * - * Purpose: Sets the total size in bytes for an atomic data type (this - * operation is not permitted on compound data types). If the - * size is decreased so that the significant bits of the data - * type extend beyond the edge of the new size, then the - * `offset' property is decreased toward zero. If the `offset' - * becomes zero and the significant bits of the data type still - * hang over the edge of the new size, then the number of - * significant bits is decreased. + * Purpose: Sets the total size in bytes for a data type (this operation + * is not permitted on compound data types). If the size is + * decreased so that the significant bits of the data type + * extend beyond the edge of the new size, then the `offset' + * property is decreased toward zero. If the `offset' becomes + * zero and the significant bits of the data type still hang + * over the edge of the new size, then the number of significant + * bits is decreased. * * Adjusting the size of an H5T_STRING automatically sets the * precision to 8*size. @@ -1633,6 +1639,8 @@ H5Tget_size(hid_t type_id) * Wednesday, January 7, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Moved the real work into a private function. * *------------------------------------------------------------------------- */ @@ -1640,16 +1648,14 @@ herr_t H5Tset_size(hid_t type_id, size_t size) { H5T_t *dt = NULL; - size_t prec, offset; FUNC_ENTER(H5Tset_size, FAIL); H5TRACE2("e","iz",type_id,size); /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - !H5T_is_atomic(dt)) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an atomic data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); } if (H5T_STATE_TRANSIENT!=dt->state) { HRETURN_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "data type is read-only"); @@ -1657,62 +1663,16 @@ H5Tset_size(hid_t type_id, size_t size) if (size <= 0) { HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "size must be positive"); } - offset = dt->u.atomic.offset; - prec = dt->u.atomic.prec; - - /* Decrement the offset and precision if necessary */ - if (prec > 8 * size) - offset = 0; - else if (offset + prec > 8 * size) - offset = 8 * size - prec; - if (prec > 8 * size) - prec = 8 * size; - - /* Make sure that other values are still okay */ - switch (dt->type) { - case H5T_INTEGER: - case H5T_TIME: - case H5T_BITFIELD: - /* nothing to check */ - break; - - case H5T_STRING: - prec = 8 * size; - offset = 0; - break; - - case H5T_FLOAT: - /* - * The sign, mantissa, and exponent fields should be adjusted first - * when decreasing the size of a floating point type. - */ - if (dt->u.atomic.u.f.sign >= prec || - dt->u.atomic.u.f.epos + dt->u.atomic.u.f.esize > prec || - dt->u.atomic.u.f.mpos + dt->u.atomic.u.f.msize > prec) { - HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, - "adjust sign, mantissa, and exponent fields first"); - } - break; - - case H5T_OPAQUE: - /* - * The significant bits of an opaque type are not allowed to change - * implicitly. - */ - if (prec != dt->u.atomic.prec) { - HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, - "unable to change precision of an opaque type"); - } - break; - - default: - assert("not implemented yet" && 0); + if (H5T_ENUM==dt->type && dt->u.enumer.nmembs>0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not allowed after members are defined"); } - /* Commit */ - dt->size = size; - dt->u.atomic.offset = offset; - dt->u.atomic.prec = prec; + /* Do the work */ + if (H5T_set_size(dt, size)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to set size for data type"); + } FUNC_LEAVE(SUCCEED); } @@ -1721,7 +1681,7 @@ H5Tset_size(hid_t type_id, size_t size) /*------------------------------------------------------------------------- * Function: H5Tget_order * - * Purpose: Returns the byte order of an atomic data type. + * Purpose: Returns the byte order of a data type. * * Return: Success: A byte order constant * @@ -1731,6 +1691,8 @@ H5Tset_size(hid_t type_id, size_t size) * Wednesday, January 7, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works for derived data types. * *------------------------------------------------------------------------- */ @@ -1745,13 +1707,18 @@ H5Tget_order(hid_t type_id) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - !H5T_is_atomic(dt)) { + NULL == (dt = H5I_object(type_id))) { HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_ORDER_ERROR, - "not an atomic data type"); + "not a data type"); + } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_COMPOUND==dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5T_ORDER_ERROR, + "operation not defined for compound data types"); } /* Order */ + assert(H5T_is_atomic(dt)); order = dt->u.atomic.order; FUNC_LEAVE(order); @@ -1761,7 +1728,7 @@ H5Tget_order(hid_t type_id) /*------------------------------------------------------------------------- * Function: H5Tset_order * - * Purpose: Sets the byte order for an atomic data type. + * Purpose: Sets the byte order for a data type. * * Return: Non-negative on success/Negative on failure * @@ -1769,6 +1736,8 @@ H5Tget_order(hid_t type_id) * Wednesday, January 7, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works for derived data types. * *------------------------------------------------------------------------- */ @@ -1782,9 +1751,8 @@ H5Tset_order(hid_t type_id, H5T_order_t order) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - !H5T_is_atomic(dt)) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an atomic data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); } if (H5T_STATE_TRANSIENT!=dt->state) { HRETURN_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "data type is read-only"); @@ -1792,8 +1760,18 @@ H5Tset_order(hid_t type_id, H5T_order_t order) if (order < 0 || order > H5T_ORDER_NONE) { HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal byte order"); } + if (H5T_ENUM==dt->type && dt->u.enumer.nmembs>0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not allowed after members are defined"); + } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_COMPOUND==dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5T_ORDER_ERROR, + "operation not defined for compound data types"); + } /* Commit */ + assert(H5T_is_atomic(dt)); dt->u.atomic.order = order; FUNC_LEAVE(SUCCEED); } @@ -1802,7 +1780,7 @@ H5Tset_order(hid_t type_id, H5T_order_t order) /*------------------------------------------------------------------------- * Function: H5Tget_precision * - * Purpose: Gets the precision of an atomic data type. The precision is + * Purpose: Gets the precision of a data type. The precision is * the number of significant bits which, unless padding is * present, is 8 times larger than the value returned by * H5Tget_size(). @@ -1816,6 +1794,8 @@ H5Tset_order(hid_t type_id, H5T_order_t order) * Wednesday, January 7, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works for derived data types. * *------------------------------------------------------------------------- */ @@ -1830,12 +1810,17 @@ H5Tget_precision(hid_t type_id) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - !H5T_is_atomic(dt)) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not an atomic data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not a data type"); + } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_COMPOUND==dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5T_ORDER_ERROR, + "operation not defined for compound data types"); } /* Precision */ + assert(H5T_is_atomic(dt)); prec = dt->u.atomic.prec; FUNC_LEAVE(prec); @@ -1845,7 +1830,7 @@ H5Tget_precision(hid_t type_id) /*------------------------------------------------------------------------- * Function: H5Tset_precision * - * Purpose: Sets the precision of an atomic data type. The precision is + * Purpose: Sets the precision of a data type. The precision is * the number of significant bits which, unless padding is * present, is 8 times larger than the value returned by * H5Tget_size(). @@ -1866,6 +1851,8 @@ H5Tget_precision(hid_t type_id) * Wednesday, January 7, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Moved real work to a private function. * *------------------------------------------------------------------------- */ @@ -1873,16 +1860,14 @@ herr_t H5Tset_precision(hid_t type_id, size_t prec) { H5T_t *dt = NULL; - size_t offset, size; - FUNC_ENTER(H5Tset_prec, FAIL); + FUNC_ENTER(H5Tset_precision, FAIL); H5TRACE2("e","iz",type_id,prec); /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - !H5T_is_atomic(dt)) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an atomic data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); } if (H5T_STATE_TRANSIENT!=dt->state) { HRETURN_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "data type is read-only"); @@ -1891,51 +1876,16 @@ H5Tset_precision(hid_t type_id, size_t prec) HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "precision must be positive"); } - - /* Adjust the offset and size */ - offset = dt->u.atomic.offset; - size = dt->size; - if (prec > 8 * size) - offset = 0; - else if (offset + prec > 8 * size) - offset = 8 * size - prec; - if (prec > 8 * size) - size = (prec + 7) / 8; - - /* Check that things are still kosher */ - switch (dt->type) { - case H5T_INTEGER: - case H5T_TIME: - case H5T_BITFIELD: - case H5T_OPAQUE: - /* nothing to check */ - break; - - case H5T_STRING: - HRETURN_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, - "precision for this type is read-only"); - - case H5T_FLOAT: - /* - * The sign, mantissa, and exponent fields should be adjusted first - * when decreasing the precision of a floating point type. - */ - if (dt->u.atomic.u.f.sign >= prec || - dt->u.atomic.u.f.epos + dt->u.atomic.u.f.esize > prec || - dt->u.atomic.u.f.mpos + dt->u.atomic.u.f.msize > prec) { - HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, - "adjust sign, mantissa, and exponent fields first"); - } - break; - - default: - assert("not implemented yet" && 0); + if (H5T_ENUM==dt->type && dt->u.enumer.nmembs>0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not allowed after members are defined"); } - /* Commit */ - dt->size = size; - dt->u.atomic.offset = offset; - dt->u.atomic.prec = prec; + /* Do the work */ + if (H5T_set_precision(dt, prec)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to set precision"); + } FUNC_LEAVE(SUCCEED); } @@ -1970,6 +1920,8 @@ H5Tset_precision(hid_t type_id, size_t prec) * Wednesday, January 7, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works for derived data types. * *------------------------------------------------------------------------- */ @@ -1984,12 +1936,17 @@ H5Tget_offset(hid_t type_id) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - !H5T_is_atomic(dt)) { + NULL == (dt = H5I_object(type_id))) { HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not an atomic data type"); } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_COMPOUND==dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for compound data types"); + } /* Offset */ + assert(H5T_is_atomic(dt)); offset = dt->u.atomic.offset; FUNC_LEAVE(offset); @@ -2030,6 +1987,8 @@ H5Tget_offset(hid_t type_id) * Wednesday, January 7, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Moved real work to a private function. * *------------------------------------------------------------------------- */ @@ -2043,8 +2002,7 @@ H5Tset_offset(hid_t type_id, size_t offset) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - !H5T_is_atomic(dt)) { + NULL == (dt = H5I_object(type_id))) { HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an atomic data type"); } if (H5T_STATE_TRANSIENT!=dt->state) { @@ -2054,14 +2012,16 @@ H5Tset_offset(hid_t type_id, size_t offset) HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "offset must be zero for this type"); } - - /* Adjust the size */ - if (offset + dt->u.atomic.prec > 8 * dt->size) { - dt->size = (offset + dt->u.atomic.prec + 7) / 8; + if (H5T_ENUM==dt->type && dt->u.enumer.nmembs>0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not allowed after members are defined"); + } + + /* Do the real work */ + if (H5T_set_offset(dt, offset)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to set offset"); } - - /* Commit */ - dt->u.atomic.offset = offset; FUNC_LEAVE(SUCCEED); } @@ -2080,6 +2040,8 @@ H5Tset_offset(hid_t type_id, size_t offset) * Friday, January 9, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works with derived data types. * *------------------------------------------------------------------------- */ @@ -2093,12 +2055,17 @@ H5Tget_pad(hid_t type_id, H5T_pad_t *lsb/*out*/, H5T_pad_t *msb/*out*/) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - !H5T_is_atomic(dt)) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an atomic data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); + } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_COMPOUND==dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for compound data types"); } /* Get values */ + assert(H5T_is_atomic(dt)); if (lsb) *lsb = dt->u.atomic.lsb_pad; if (msb) *msb = dt->u.atomic.msb_pad; @@ -2117,7 +2084,9 @@ H5Tget_pad(hid_t type_id, H5T_pad_t *lsb/*out*/, H5T_pad_t *msb/*out*/) * Friday, January 9, 1998 * * Modifications: - * + * Robb Matzke, 22 Dec 1998 + * Also works with derived data types. + * *------------------------------------------------------------------------- */ herr_t @@ -2130,9 +2099,8 @@ H5Tset_pad(hid_t type_id, H5T_pad_t lsb, H5T_pad_t msb) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - !H5T_is_atomic(dt)) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an atomic data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); } if (H5T_STATE_TRANSIENT!=dt->state) { HRETURN_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "data type is read-only"); @@ -2140,8 +2108,18 @@ H5Tset_pad(hid_t type_id, H5T_pad_t lsb, H5T_pad_t msb) if (lsb < 0 || lsb >= H5T_NPAD || msb < 0 || msb >= H5T_NPAD) { HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid pad type"); } + if (H5T_ENUM==dt->type && dt->u.enumer.nmembs>0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not allowed after members are defined"); + } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_COMPOUND==dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for compound data types"); + } /* Commit */ + assert(H5T_is_atomic(dt)); dt->u.atomic.lsb_pad = lsb; dt->u.atomic.msb_pad = msb; @@ -2162,7 +2140,8 @@ H5Tset_pad(hid_t type_id, H5T_pad_t lsb, H5T_pad_t msb) * Wednesday, January 7, 1998 * * Modifications: - * + * Robb Matzke, 22 Dec 1998 + * Also works with derived data types. *------------------------------------------------------------------------- */ H5T_sign_t @@ -2176,11 +2155,15 @@ H5Tget_sign(hid_t type_id) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_INTEGER != dt->type) { + NULL == (dt = H5I_object(type_id))) { HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_SGN_ERROR, "not an integer data type"); } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_INTEGER!=dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for data type class"); + } /* Sign */ sign = dt->u.atomic.u.i.sign; @@ -2200,6 +2183,8 @@ H5Tget_sign(hid_t type_id) * Wednesday, January 7, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works with derived data types. * *------------------------------------------------------------------------- */ @@ -2213,8 +2198,7 @@ H5Tset_sign(hid_t type_id, H5T_sign_t sign) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_INTEGER != dt->type) { + NULL == (dt = H5I_object(type_id))) { HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an integer data type"); } if (H5T_STATE_TRANSIENT!=dt->state) { @@ -2223,6 +2207,15 @@ H5Tset_sign(hid_t type_id, H5T_sign_t sign) if (sign < 0 || sign >= H5T_NSGN) { HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal sign type"); } + if (H5T_ENUM==dt->type && dt->u.enumer.nmembs>0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not allowed after members are defined"); + } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_INTEGER!=dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for data type class"); + } /* Commit */ dt->u.atomic.u.i.sign = sign; @@ -2249,7 +2242,8 @@ H5Tset_sign(hid_t type_id, H5T_sign_t sign) * Wednesday, January 7, 1998 * * Modifications: - * + * Robb Matzke, 22 Dec 1998 + * Also works with derived data types. *------------------------------------------------------------------------- */ herr_t @@ -2264,10 +2258,13 @@ H5Tget_fields(hid_t type_id, size_t *spos/*out*/, /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_FLOAT != dt->type) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, - "not a floating-point data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); + } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_FLOAT != dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for data type class"); } /* Get values */ @@ -2298,7 +2295,9 @@ H5Tget_fields(hid_t type_id, size_t *spos/*out*/, * Wednesday, January 7, 1998 * * Modifications: - * + * Robb Matzke, 22 Dec 1998 + * Also works for derived data types. + * *------------------------------------------------------------------------- */ herr_t @@ -2312,14 +2311,17 @@ H5Tset_fields(hid_t type_id, size_t spos, size_t epos, size_t esize, /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_FLOAT != dt->type) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, - "not a floating-point data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); } if (H5T_STATE_TRANSIENT!=dt->state) { HRETURN_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "data type is read-only"); } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_FLOAT != dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for data type class"); + } if (epos + esize > dt->u.atomic.prec) { HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "exponent bit field size/location is invalid"); @@ -2372,7 +2374,8 @@ H5Tset_fields(hid_t type_id, size_t spos, size_t epos, size_t esize, * Wednesday, January 7, 1998 * * Modifications: - * + * Robb Matzke, 22 Dec 1998 + * Also works with derived data types. *------------------------------------------------------------------------- */ size_t @@ -2386,10 +2389,13 @@ H5Tget_ebias(hid_t type_id) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_FLOAT != dt->type) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, 0, - "not a floating-point data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not a data type"); + } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_FLOAT != dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, 0, + "operation not defined for data type class"); } /* bias */ @@ -2410,6 +2416,8 @@ H5Tget_ebias(hid_t type_id) * Wednesday, January 7, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works with derived data types. * *------------------------------------------------------------------------- */ @@ -2423,14 +2431,17 @@ H5Tset_ebias(hid_t type_id, size_t ebias) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_FLOAT != dt->type) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, - "not a floating-point data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); } if (H5T_STATE_TRANSIENT!=dt->state) { HRETURN_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "data type is read-only"); } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_FLOAT != dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for data type class"); + } /* Commit */ dt->u.atomic.u.f.ebias = ebias; @@ -2453,6 +2464,8 @@ H5Tset_ebias(hid_t type_id, size_t ebias) * Wednesday, January 7, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works with derived data types. * *------------------------------------------------------------------------- */ @@ -2467,10 +2480,14 @@ H5Tget_norm(hid_t type_id) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_FLOAT != dt->type) { + NULL == (dt = H5I_object(type_id))) { HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_NORM_ERROR, - "not a floating-point data type"); + "not a data type"); + } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_FLOAT != dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for data type class"); } /* norm */ @@ -2492,6 +2509,8 @@ H5Tget_norm(hid_t type_id) * Wednesday, January 7, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works for derived data types. * *------------------------------------------------------------------------- */ @@ -2505,10 +2524,8 @@ H5Tset_norm(hid_t type_id, H5T_norm_t norm) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_FLOAT != dt->type) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, - "not a floating-point data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); } if (H5T_STATE_TRANSIENT!=dt->state) { HRETURN_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "data type is read-only"); @@ -2516,6 +2533,11 @@ H5Tset_norm(hid_t type_id, H5T_norm_t norm) if (norm < 0 || norm > H5T_NORM_NONE) { HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal normalization"); } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_FLOAT != dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for data type class"); + } /* Commit */ dt->u.atomic.u.f.norm = norm; @@ -2539,6 +2561,8 @@ H5Tset_norm(hid_t type_id, H5T_norm_t norm) * Friday, January 9, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works for derived data types. * *------------------------------------------------------------------------- */ @@ -2553,10 +2577,14 @@ H5Tget_inpad(hid_t type_id) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_FLOAT != dt->type) { + NULL == (dt = H5I_object(type_id))) { HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_PAD_ERROR, - "not a floating-point data type"); + "not a data type"); + } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_FLOAT != dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5T_PAD_ERROR, + "operation not defined for data type class"); } /* pad */ @@ -2580,6 +2608,8 @@ H5Tget_inpad(hid_t type_id) * Friday, January 9, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works for derived data types. * *------------------------------------------------------------------------- */ @@ -2593,10 +2623,8 @@ H5Tset_inpad(hid_t type_id, H5T_pad_t pad) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_FLOAT != dt->type) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, - "not a floating-point data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); } if (H5T_STATE_TRANSIENT!=dt->state) { HRETURN_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "data type is read-only"); @@ -2605,6 +2633,11 @@ H5Tset_inpad(hid_t type_id, H5T_pad_t pad) HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal internal pad type"); } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_FLOAT != dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for data type class"); + } /* Commit */ dt->u.atomic.u.f.pad = pad; @@ -2627,6 +2660,8 @@ H5Tset_inpad(hid_t type_id, H5T_pad_t pad) * Friday, January 9, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works for derived data types. * *------------------------------------------------------------------------- */ @@ -2641,10 +2676,14 @@ H5Tget_cset(hid_t type_id) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_STRING != dt->type) { + NULL == (dt = H5I_object(type_id))) { HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_CSET_ERROR, - "not a string data type"); + "not a data type"); + } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_STRING != dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5T_CSET_ERROR, + "operation not defined for data type class"); } /* result */ @@ -2667,6 +2706,8 @@ H5Tget_cset(hid_t type_id) * Friday, January 9, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works with derived data types. * *------------------------------------------------------------------------- */ @@ -2680,9 +2721,8 @@ H5Tset_cset(hid_t type_id, H5T_cset_t cset) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_STRING != dt->type) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a string data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); } if (H5T_STATE_TRANSIENT!=dt->state) { HRETURN_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "data type is read-only"); @@ -2691,6 +2731,11 @@ H5Tset_cset(hid_t type_id, H5T_cset_t cset) HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal character set type"); } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_STRING != dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for data type class"); + } /* Commit */ dt->u.atomic.u.s.cset = cset; @@ -2714,6 +2759,8 @@ H5Tset_cset(hid_t type_id, H5T_cset_t cset) * Friday, January 9, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works for derived data types. * *------------------------------------------------------------------------- */ @@ -2728,10 +2775,13 @@ H5Tget_strpad(hid_t type_id) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_STRING != dt->type) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_STR_ERROR, - "not a string data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_STR_ERROR, "not a data type"); + } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_STRING != dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5T_STR_ERROR, + "operation not defined for data type class"); } /* result */ @@ -2765,6 +2815,8 @@ H5Tget_strpad(hid_t type_id) * Friday, January 9, 1998 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works for derived data types. * *------------------------------------------------------------------------- */ @@ -2778,9 +2830,8 @@ H5Tset_strpad(hid_t type_id, H5T_str_t strpad) /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_STRING != dt->type) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a string data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); } if (H5T_STATE_TRANSIENT!=dt->state) { HRETURN_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "data type is read-only"); @@ -2788,6 +2839,11 @@ H5Tset_strpad(hid_t type_id, H5T_str_t strpad) if (strpad < 0 || strpad >= H5T_NSTR) { HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal string pad type"); } + if (dt->parent) dt = dt->parent; /*defer to parent*/ + if (H5T_STRING != dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for data type class"); + } /* Commit */ dt->u.atomic.u.s.pad = strpad; @@ -2798,10 +2854,10 @@ H5Tset_strpad(hid_t type_id, H5T_str_t strpad) /*------------------------------------------------------------------------- * Function: H5Tget_nmembers * - * Purpose: Determines how many members compound data type TYPE_ID has. + * Purpose: Determines how many members TYPE_ID has. The type must be + * either a compound data type or an enumeration data type. * - * Return: Success: Number of members defined in a compound data - * type. + * Return: Success: Number of members defined in the data type. * * Failure: Negative * @@ -2811,35 +2867,44 @@ H5Tset_strpad(hid_t type_id, H5T_str_t strpad) * Monday, December 8, 1997 * * Modifications: - * + * Robb Matzke, 22 Dec 1998 + * Also works with enumeration data types. *------------------------------------------------------------------------- */ int H5Tget_nmembers(hid_t type_id) { - H5T_t *dt = NULL; + intn ret_value = FAIL; FUNC_ENTER(H5Tget_num_members, FAIL); H5TRACE1("Is","i",type_id); /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_COMPOUND != dt->type) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a compound data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); + } + + if (H5T_COMPOUND==dt->type) { + ret_value = dt->u.compnd.nmembs; + } else if (H5T_ENUM==dt->type) { + ret_value = dt->u.enumer.nmembs; + } else { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, + "operation not supported for type class"); } - FUNC_LEAVE(dt->u.compnd.nmembs); + FUNC_LEAVE(ret_value); } /*------------------------------------------------------------------------- * Function: H5Tget_member_name * - * Purpose: Returns the name of a member of a compound data type. - * Members are stored in no particular order with numbers 0 - * through N-1 where N is the value returned by + * Purpose: Returns the name of a member of a compound or enumeration + * data type. Members are stored in no particular order with + * numbers 0 through N-1 where N is the value returned by * H5Tget_nmembers(). * * Return: Success: Ptr to a string allocated with malloc(). The @@ -2851,30 +2916,48 @@ H5Tget_nmembers(hid_t type_id) * Wednesday, January 7, 1998 * * Modifications: - * + * Robb Matzke, 22 Dec 1998 + * Also works with enumeration data types. *------------------------------------------------------------------------- */ char * H5Tget_member_name(hid_t type_id, int membno) { H5T_t *dt = NULL; - char *s = NULL; + char *ret_value = NULL; FUNC_ENTER(H5Tget_member_name, NULL); /* Check args */ if (H5I_DATATYPE != H5I_get_type(type_id) || - NULL == (dt = H5I_object(type_id)) || - H5T_COMPOUND != dt->type) { - HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a compound data type"); + NULL == (dt = H5I_object(type_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data type"); } - if (membno < 0 || membno >= dt->u.compnd.nmembs) { - HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid member number"); + + switch (dt->type) { + case H5T_COMPOUND: + if (membno<0 || membno>=dt->u.compnd.nmembs) { + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, + "invalid member number"); + } + ret_value = H5MM_xstrdup(dt->u.compnd.memb[membno].name); + break; + + case H5T_ENUM: + if (membno<0 || membno>=dt->u.enumer.nmembs) { + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, + "invalid member number"); + } + ret_value = H5MM_xstrdup(dt->u.enumer.name[membno]); + break; + + default: + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, + "operation not supported for type class"); } /* Value */ - s = H5MM_xstrdup(dt->u.compnd.memb[membno].name); - FUNC_LEAVE(s); + FUNC_LEAVE(ret_value); } @@ -3026,7 +3109,7 @@ H5Tget_member_type(hid_t type_id, int membno) if ((memb_type_id = H5I_register(H5I_DATATYPE, memb_dt)) < 0) { H5T_close(memb_dt); HRETURN_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, - "can't register data type atom"); + "unable register data type atom"); } FUNC_LEAVE(memb_type_id); @@ -3046,9 +3129,9 @@ H5Tget_member_type(hid_t type_id, int membno) * compound data type cannot have a member which is a compound * data type. * - * Return: Success: Non-negative, the PARENT_ID compound data type is - * modified to include a copy of the member type - * MEMBER_ID. + * Return: Success: Non-negative, the PARENT_ID compound data + * type is modified to include a copy of the + * member type MEMBER_ID. * * Failure: Negative * @@ -3088,9 +3171,9 @@ H5Tinsert(hid_t parent_id, const char *name, size_t offset, hid_t member_id) } /* Insert */ - if (H5T_insert(parent, name, offset, 0, NULL, NULL, member) < 0) { + if (H5T_struct_insert(parent, name, offset, 0, NULL, NULL, member) < 0) { HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, - "can't insert member"); + "unable to insert member"); } FUNC_LEAVE(SUCCEED); @@ -3159,9 +3242,9 @@ H5Tinsert_array(hid_t parent_id, const char *name, size_t offset, } /* Insert */ - if (H5T_insert(parent, name, offset, ndims, dim, perm, member) < 0) { + if (H5T_struct_insert(parent, name, offset, ndims, dim, perm, member)<0) { HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, - "can't insert member"); + "unable to insert member"); } FUNC_LEAVE(SUCCEED); @@ -3212,6 +3295,311 @@ H5Tpack(hid_t type_id) /*------------------------------------------------------------------------- + * Function: H5Tenum_create + * + * Purpose: Create a new enumeration data type based on the specified + * TYPE, which must be an integer type. + * + * Return: Success: ID of new enumeration data type + * + * Failure: Negative + * + * Programmer: Robb Matzke + * Tuesday, December 22, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +hid_t +H5Tenum_create(hid_t parent_id) +{ + H5T_t *parent = NULL; /*base integer data type */ + H5T_t *dt = NULL; /*new enumeration data type */ + hid_t ret_value = FAIL; /*return value */ + + FUNC_ENTER(H5Tenum_create, FAIL); + H5TRACE1("i","i",parent_id); + + /* Check args */ + if (H5I_DATATYPE!=H5I_get_type(parent_id) || + NULL==(parent=H5I_object(parent_id)) || + H5T_INTEGER!=parent->type) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an integer data type"); + } + + /* Build new type */ + if (NULL==(dt=H5MM_calloc(sizeof(H5T_t)))) { + HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, + "memory allocation failed"); + } + dt->type = H5T_ENUM; + dt->parent = H5T_copy(parent, H5T_COPY_ALL); + dt->size = dt->parent->size; + + /* Atomize the type */ + if ((ret_value=H5I_register(H5I_DATATYPE, dt))<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, + "unable to register data type atom"); + } + + FUNC_LEAVE(ret_value); +} + + +/*------------------------------------------------------------------------- + * Function: H5Tenum_insert + * + * Purpose: Insert a new enumeration data type member into an enumeration + * type. TYPE is the enumeration type, NAME is the name of the + * new member, and VALUE points to the value of the new member. + * The NAME and VALUE must both be unique within the TYPE. VALUE + * points to data which is of the data type defined when the + * enumeration type was created. + * + * Return: Success: non-negative + * + * Failure: negative + * + * Programmer: Robb Matzke + * Wednesday, December 23, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5Tenum_insert(hid_t type, const char *name, void *value) +{ + H5T_t *dt=NULL; + + FUNC_ENTER(H5Tenum_insert, FAIL); + H5TRACE3("e","isx",type,name,value); + + /* Check args */ + if (H5I_DATATYPE!=H5I_get_type(type) || + NULL==(dt=H5I_object(type))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); + } + if (H5T_ENUM!=dt->type) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, + "not an enumeration data type"); + } + if (!name || !*name) { + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name specified"); + } + if (!value) { + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value specified"); + } + + /* Do work */ + if (H5T_enum_insert(dt, name, value)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to insert new enumeration member"); + } + + FUNC_LEAVE(SUCCEED); +} + + +/*------------------------------------------------------------------------- + * Function: H5Tget_super + * + * Purpose: Returns the type from which TYPE is derived. In the case of + * an enumeration type the return value is an integer type. + * + * Return: Success: Type ID for base data type. + * + * Failure: negative + * + * Programmer: Robb Matzke + * Wednesday, December 23, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +hid_t +H5Tget_super(hid_t type) +{ + H5T_t *dt=NULL, *super=NULL; + hid_t ret_value=FAIL; + + FUNC_ENTER(H5Tget_super, FAIL); + H5TRACE1("i","i",type); + + if (H5I_DATATYPE!=H5I_get_type(type) || + NULL==(dt=H5I_object(type))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); + } + if (!dt->parent) { + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a derived data type"); + } + if (NULL==(super=H5T_copy(dt->parent, H5T_COPY_ALL))) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to copy parent data type"); + } + if ((ret_value=H5I_register(H5I_DATATYPE, super))<0) { + H5T_close(super); + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, + "unable to register parent data type"); + } + + FUNC_LEAVE(ret_value); +} + + +/*------------------------------------------------------------------------- + * Function: H5Tget_member_value + * + * Purpose: Return the value for an enumeration data type member. + * + * Return: Success: non-negative with the member value copied + * into the memory pointed to by VALUE. + * + * Failure: negative, VALUE memory is undefined. + * + * Programmer: Robb Matzke + * Wednesday, December 23, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +hid_t +H5Tget_member_value(hid_t type, int membno, void *value/*out*/) +{ + H5T_t *dt=NULL; + + FUNC_ENTER(H5Tget_member_value, FAIL); + H5TRACE3("i","iIsx",type,membno,value); + + if (H5I_DATATYPE!=H5I_get_type(type) || + NULL==(dt=H5I_object(type))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); + } + if (H5T_ENUM!=dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for data type class"); + } + if (membno<0 || membno>=dt->u.enumer.nmembs) { + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid member number"); + } + if (!value) { + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "null value buffer"); + } + + HDmemcpy(value, dt->u.enumer.value + membno*dt->size, dt->size); + + FUNC_LEAVE(SUCCEED); +} + + +/*------------------------------------------------------------------------- + * Function: H5Tenum_nameof + * + * Purpose: Finds the symbol name that corresponds to the specified VALUE + * of an enumeration data type TYPE. At most SIZE characters of + * the symbol name are copied into the NAME buffer. If the + * entire symbol anem and null terminator do not fit in the NAME + * buffer then as many characters as possible are copied (not + * null terminated) and the function fails. + * + * Return: Success: Non-negative. + * + * Failure: Negative, first character of NAME is set to + * null if SIZE allows it. + * + * Programmer: Robb Matzke + * Monday, January 4, 1999 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +hid_t +H5Tenum_nameof(hid_t type, void *value, char *name/*out*/, size_t size) +{ + H5T_t *dt = NULL; + + FUNC_ENTER(H5Tenum_nameof, FAIL); + H5TRACE4("i","ixxz",type,value,name,size); + + /* Check args */ + if (H5I_DATATYPE!=H5I_get_type(type) || + NULL==(dt=H5I_object(type))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); + } + if (H5T_ENUM!=dt->type) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, + "not an enumeration data type"); + } + if (!value) { + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value supplied"); + } + if (!name) { + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name buffer supplied"); + } + + if (NULL==H5T_enum_nameof(dt, value, name, size)) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "nameof query failed"); + } + FUNC_LEAVE(SUCCEED); +} + + +/*------------------------------------------------------------------------- + * Function: H5Tenum_valueof + * + * Purpose: Finds the value that corresponds to the specified NAME f an + * enumeration TYPE. The VALUE argument should be at least as + * large as the value of H5Tget_size(type) in order to hold the + * result. + * + * Return: Success: Non-negative + * + * Failure: Negative + * + * Programmer: Robb Matzke + * Monday, January 4, 1999 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +hid_t +H5Tenum_valueof(hid_t type, const char *name, void *value/*out*/) +{ + H5T_t *dt = NULL; + + FUNC_ENTER(H5Tenum_valueof, FAIL); + H5TRACE3("i","isx",type,name,value); + + /* Check args */ + if (H5I_DATATYPE!=H5I_get_type(type) || + NULL==(dt=H5I_object(type))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); + } + if (H5T_ENUM!=dt->type) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, + "not an enumeration data type"); + } + if (!name || !*name) { + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name"); + } + if (!value) { + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value buffer"); + } + + if (H5T_enum_valueof(dt, name, value)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "valueof query failed"); + } + FUNC_LEAVE(SUCCEED); +} + + +/*------------------------------------------------------------------------- * Function: H5Tregister * * Purpose: Register a hard or soft conversion function for a data type @@ -3698,6 +4086,7 @@ H5T_t * H5T_create(H5T_class_t type, size_t size) { H5T_t *dt = NULL; + hid_t subtype; FUNC_ENTER(H5T_create, NULL); @@ -3721,6 +4110,34 @@ H5T_create(H5T_class_t type, size_t size) dt->type = type; break; + case H5T_ENUM: + if (sizeof(char)==size) { + subtype = H5T_NATIVE_SCHAR_g; + } else if (sizeof(short)==size) { + subtype = H5T_NATIVE_SHORT_g; + } else if (sizeof(int)==size) { + subtype = H5T_NATIVE_INT_g; + } else if (sizeof(long)==size) { + subtype = H5T_NATIVE_LONG_g; + } else if (sizeof(long_long)==size) { + subtype = H5T_NATIVE_LLONG_g; + } else { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, + "no applicable native integer type"); + } + if (NULL==(dt = H5MM_calloc(sizeof(H5T_t)))) { + HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, + "memory allocation failed"); + } + dt->type = type; + if (NULL==(dt->parent=H5T_copy(H5I_object(subtype), + H5T_COPY_ALL))) { + H5MM_xfree(dt); + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, + "unable to copy base data type"); + } + break; + default: HRETURN_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, NULL, "unknown data type class"); @@ -3843,6 +4260,9 @@ H5T_open (H5G_entry_t *loc, const char *name) * H5T_COPY_REOPEN method is used when returning a named type to the * application. * + * Robb Matzke, 22 Dec 1998 + * Now able to copy enumeration data types. + * *------------------------------------------------------------------------- */ H5T_t * @@ -3864,6 +4284,11 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method) } *new_dt = *old_dt; + /* copy parent */ + if (new_dt->parent) { + new_dt->parent = H5T_copy(new_dt->parent, method); + } + switch (method) { case H5T_COPY_TRANSIENT: /* @@ -3908,21 +4333,42 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method) * name and type fields of each new member with copied values. * That is, H5T_copy() is a deep copy. */ - new_dt->u.compnd.memb = H5MM_malloc(new_dt->u.compnd.nmembs * - sizeof(H5T_member_t)); + new_dt->u.compnd.memb = H5MM_malloc(new_dt->u.compnd.nalloc * + sizeof(H5T_cmemb_t)); if (NULL==new_dt->u.compnd.memb) { HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); } HDmemcpy(new_dt->u.compnd.memb, old_dt->u.compnd.memb, - new_dt->u.compnd.nmembs * sizeof(H5T_member_t)); + new_dt->u.compnd.nmembs * sizeof(H5T_cmemb_t)); - for (i = 0; i < new_dt->u.compnd.nmembs; i++) { + for (i=0; i<new_dt->u.compnd.nmembs; i++) { s = new_dt->u.compnd.memb[i].name; new_dt->u.compnd.memb[i].name = H5MM_xstrdup(s); tmp = H5T_copy (old_dt->u.compnd.memb[i].type, method); new_dt->u.compnd.memb[i].type = tmp; } + + } else if (H5T_ENUM == new_dt->type) { + /* + * Copy all member fields to new type, then overwrite the name fields + * of each new member with copied values. That is, H5T_copy() is a + * deep copy. + */ + new_dt->u.enumer.name = H5MM_malloc(new_dt->u.enumer.nalloc * + sizeof(char*)); + new_dt->u.enumer.value = H5MM_malloc(new_dt->u.enumer.nalloc * + new_dt->size); + if (NULL==new_dt->u.enumer.value) { + HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, + "memory allocation failed"); + } + HDmemcpy(new_dt->u.enumer.value, old_dt->u.enumer.value, + new_dt->u.enumer.nmembs * new_dt->size); + for (i=0; i<new_dt->u.enumer.nmembs; i++) { + s = old_dt->u.enumer.name[i]; + new_dt->u.enumer.name[i] = H5MM_xstrdup(s); + } } FUNC_LEAVE(new_dt); @@ -4077,31 +4523,48 @@ H5T_close(H5T_t *dt) */ if (H5T_STATE_OPEN==dt->state) { assert (H5F_addr_defined (&(dt->ent.header))); - if (H5O_close (&(dt->ent))<0) { - HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, - "unable to close data type object header"); + if (H5O_close(&(dt->ent))<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to close data type object header"); } dt->state = H5T_STATE_NAMED; } + /* Close the parent */ + if (dt->parent && H5T_close(dt->parent)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to close parent data type"); + } + /* * Don't free locked datatypes unless we are shutting down the * interface. */ if (H5T_STATE_IMMUTABLE!=dt->state) { - if (dt && H5T_COMPOUND == dt->type) { - for (i = 0; i < dt->u.compnd.nmembs; i++) { + switch (dt->type) { + case H5T_COMPOUND: + for (i=0; i<dt->u.compnd.nmembs; i++) { H5MM_xfree(dt->u.compnd.memb[i].name); - H5T_close (dt->u.compnd.memb[i].type); + H5T_close(dt->u.compnd.memb[i].type); } H5MM_xfree(dt->u.compnd.memb); H5MM_xfree(dt); + break; + + case H5T_ENUM: + for (i=0; i<dt->u.enumer.nmembs; i++) { + H5MM_xfree(dt->u.enumer.name[i]); + } + H5MM_xfree(dt->u.enumer.name); + H5MM_xfree(dt->u.enumer.value); + H5MM_xfree(dt); + break; - } else if (dt) { + default: H5MM_xfree(dt); } } - + FUNC_LEAVE(SUCCEED); } @@ -4125,11 +4588,136 @@ H5T_close(H5T_t *dt) htri_t H5T_is_atomic(const H5T_t *dt) { + htri_t ret_value = FAIL; + FUNC_ENTER(H5T_is_atomic, FAIL); assert(dt); + if (H5T_COMPOUND!=dt->type && H5T_ENUM!=dt->type) { + ret_value = TRUE; + } else { + ret_value = FALSE; + } + + FUNC_LEAVE(ret_value); +} + + +/*------------------------------------------------------------------------- + * Function: H5T_set_size + * + * Purpose: Sets the total size in bytes for a data type (this operation + * is not permitted on compound data types). If the size is + * decreased so that the significant bits of the data type + * extend beyond the edge of the new size, then the `offset' + * property is decreased toward zero. If the `offset' becomes + * zero and the significant bits of the data type still hang + * over the edge of the new size, then the number of significant + * bits is decreased. + * + * Adjusting the size of an H5T_STRING automatically sets the + * precision to 8*size. + * + * All data types have a positive size. + * + * Return: Success: non-negative + * + * Failure: nagative + * + * Programmer: Robb Matzke + * Tuesday, December 22, 1998 + * + * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works with derived data types. + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_set_size(H5T_t *dt, size_t size) +{ + size_t prec, offset; + + FUNC_ENTER(H5T_set_size, FAIL); + + /* Check args */ + assert(dt); + assert(size>0); + assert(H5T_ENUM!=dt->type || 0==dt->u.enumer.nmembs); + + if (dt->parent) { + if (H5T_set_size(dt->parent, size)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to set size for parent data type"); + } + dt->size = dt->parent->size; + } else { + if (H5T_is_atomic(dt)) { + offset = dt->u.atomic.offset; + prec = dt->u.atomic.prec; + /* Decrement the offset and precision if necessary */ + if (prec > 8*size) offset = 0; + else if (offset+prec > 8*size) offset = 8 * size - prec; + if (prec > 8*size) prec = 8 * size; + } else { + prec = offset = 0; + } + + switch (dt->type) { + case H5T_COMPOUND: + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to set size of a compound data type"); + + case H5T_INTEGER: + case H5T_TIME: + case H5T_BITFIELD: + case H5T_ENUM: + /* nothing to check */ + break; + + case H5T_STRING: + prec = 8 * size; + offset = 0; + break; - FUNC_LEAVE(H5T_COMPOUND == dt->type ? FALSE : TRUE); + case H5T_FLOAT: + /* + * The sign, mantissa, and exponent fields should be adjusted + * first when decreasing the size of a floating point type. + */ + if (dt->u.atomic.u.f.sign >= prec || + dt->u.atomic.u.f.epos + dt->u.atomic.u.f.esize > prec || + dt->u.atomic.u.f.mpos + dt->u.atomic.u.f.msize > prec) { + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, + "adjust sign, mantissa, and exponent fields " + "first"); + } + break; + + case H5T_OPAQUE: + /* + * The significant bits of an opaque type are not allowed to + * change implicitly. + */ + if (prec != dt->u.atomic.prec) { + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, + "unable to change precision of an opaque type"); + } + break; + + default: + assert("not implemented yet" && 0); + } + + /* Commit */ + dt->size = size; + if (H5T_is_atomic(dt)) { + dt->u.atomic.offset = offset; + dt->u.atomic.prec = prec; + } + } + + FUNC_LEAVE(SUCCEED); } @@ -4164,7 +4752,188 @@ H5T_get_size(const H5T_t *dt) /*------------------------------------------------------------------------- - * Function: H5T_insert + * Function: H5T_set_precision + * + * Purpose: Sets the precision of a data type. The precision is + * the number of significant bits which, unless padding is + * present, is 8 times larger than the value returned by + * H5Tget_size(). + * + * If the precision is increased then the offset is decreased + * and then the size is increased to insure that significant + * bits do not "hang over" the edge of the data type. + * + * The precision property of strings is read-only. + * + * When decreasing the precision of a floating point type, set + * the locations and sizes of the sign, mantissa, and exponent + * fields first. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Robb Matzke + * Wednesday, January 7, 1998 + * + * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works for derived data types. + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_set_precision(H5T_t *dt, size_t prec) +{ + size_t offset, size; + + FUNC_ENTER(H5T_set_precision, FAIL); + + /* Check args */ + assert(dt); + assert(prec>0); + assert(H5T_ENUM!=dt->type || 0==dt->u.enumer.nmembs); + + if (dt->parent) { + if (H5T_set_precision(dt->parent, prec)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to set precision for base type"); + } + dt->size = dt->parent->size; + } else { + if (H5T_COMPOUND==dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for compound data types"); + + } else if (H5T_ENUM==dt->type) { + /*nothing*/ + + } else if (H5T_is_atomic(dt)) { + /* Adjust the offset and size */ + offset = dt->u.atomic.offset; + size = dt->size; + if (prec > 8*size) offset = 0; + else if (offset+prec > 8 * size) offset = 8 * size - prec; + if (prec > 8*size) size = (prec+7) / 8; + + /* Check that things are still kosher */ + switch (dt->type) { + case H5T_INTEGER: + case H5T_TIME: + case H5T_BITFIELD: + case H5T_OPAQUE: + /* nothing to check */ + break; + + case H5T_STRING: + HRETURN_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, + "precision for this type is read-only"); + + case H5T_FLOAT: + /* + * The sign, mantissa, and exponent fields should be adjusted + * first when decreasing the precision of a floating point + * type. + */ + if (dt->u.atomic.u.f.sign >= prec || + dt->u.atomic.u.f.epos + dt->u.atomic.u.f.esize > prec || + dt->u.atomic.u.f.mpos + dt->u.atomic.u.f.msize > prec) { + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, + "adjust sign, mantissa, and exponent fields " + "first"); + } + break; + + default: + assert("not implemented yet" && 0); + } + + /* Commit */ + dt->size = size; + if (H5T_is_atomic(dt)) { + dt->u.atomic.offset = offset; + dt->u.atomic.prec = prec; + } + } + } + + FUNC_LEAVE(SUCCEED); +} + + +/*------------------------------------------------------------------------- + * Function: H5T_set_offset + * + * Purpose: Sets the bit offset of the first significant bit. The + * signficant bits of an atomic datum can be offset from the + * beginning of the memory for that datum by an amount of + * padding. The `offset' property specifies the number of bits + * of padding that appear to the "right of" the value. That is, + * if we have a 32-bit datum with 16-bits of precision having + * the value 0x1122 then it will be layed out in memory as (from + * small byte address toward larger byte addresses): + * + * Big Big Little Little + * Endian Endian Endian Endian + * offset=0 offset=16 offset=0 offset=16 + * + * 0: [ pad] [0x11] [0x22] [ pad] + * 1: [ pad] [0x22] [0x11] [ pad] + * 2: [0x11] [ pad] [ pad] [0x22] + * 3: [0x22] [ pad] [ pad] [0x11] + * + * If the offset is incremented then the total size is + * incremented also if necessary to prevent significant bits of + * the value from hanging over the edge of the data type. + * + * The offset of an H5T_STRING cannot be set to anything but + * zero. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Robb Matzke + * Wednesday, January 7, 1998 + * + * Modifications: + * Robb Matzke, 22 Dec 1998 + * Also works for derived data types. + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_set_offset(H5T_t *dt, size_t offset) +{ + FUNC_ENTER(H5T_set_offset, FAIL); + + /* Check args */ + assert(dt); + assert(H5T_STRING!=dt->type || 0==offset); + assert(H5T_ENUM!=dt->type || 0==dt->u.enumer.nmembs); + + if (dt->parent) { + if (H5T_set_offset(dt->parent, offset)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to set offset for base type"); + } + dt->size = dt->parent->size; + } else { + if (H5T_COMPOUND==dt->type) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "operation not defined for compound data types"); + } else if (H5T_ENUM==dt->type) { + /*nothing*/ + } else { + if (offset+dt->u.atomic.prec > 8*dt->size) { + dt->size = (offset + dt->u.atomic.prec + 7) / 8; + } + dt->u.atomic.offset = offset; + } + } + + FUNC_LEAVE(SUCCEED); +} + + +/*------------------------------------------------------------------------- + * Function: H5T_struct_insert * * Purpose: Adds a new MEMBER to the compound data type PARENT. The new * member will have a NAME that is unique within PARENT and an @@ -4181,14 +4950,14 @@ H5T_get_size(const H5T_t *dt) *------------------------------------------------------------------------- */ herr_t -H5T_insert(H5T_t *parent, const char *name, size_t offset, intn ndims, - const size_t *dim, const intn *perm, const H5T_t *member) +H5T_struct_insert(H5T_t *parent, const char *name, size_t offset, intn ndims, + const size_t *dim, const intn *perm, const H5T_t *member) { intn idx, i; size_t total_size; + hbool_t *perm_check=NULL; - - FUNC_ENTER(H5T_insert, FAIL); + FUNC_ENTER(H5T_struct_insert, FAIL); /* check args */ assert(parent && H5T_COMPOUND == parent->type); @@ -4217,11 +4986,33 @@ H5T_insert(H5T_t *parent, const char *name, size_t offset, intn ndims, } } + /* Are permutations correct? */ + if (ndims>0 && perm) { + if (NULL==(perm_check=H5MM_calloc(ndims*sizeof(hbool_t)))) { + HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, + "memory allocation failed"); + } + for (i=0; i<ndims; i++) { + if (perm[i]<0 || perm[i]>=ndims) { + H5MM_xfree(perm_check); + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, + "invalid permutation vector (out of range)"); + } + if (perm_check[perm[i]]) { + H5MM_xfree(perm_check); + HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, + "invalid permutation vector (duplicate value)"); + } + perm_check[perm[i]] = TRUE; + } + perm_check = H5MM_xfree(perm_check); + } + /* Increase member array if necessary */ if (parent->u.compnd.nmembs >= parent->u.compnd.nalloc) { size_t na = parent->u.compnd.nalloc + H5T_COMPND_INC; - H5T_member_t *x = H5MM_realloc (parent->u.compnd.memb, - na * sizeof(H5T_member_t)); + H5T_cmemb_t *x = H5MM_realloc (parent->u.compnd.memb, + na * sizeof(H5T_cmemb_t)); if (!x) { HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); @@ -4242,6 +5033,7 @@ H5T_insert(H5T_t *parent, const char *name, size_t offset, intn ndims, parent->u.compnd.memb[idx].perm[i] = perm?perm[i]:i; } + parent->u.compnd.sorted = H5T_SORT_NONE; parent->u.compnd.nmembs++; FUNC_LEAVE(SUCCEED); } @@ -4283,7 +5075,7 @@ H5T_pack(H5T_t *dt) } /* Remove padding between members */ - H5T_sort_by_offset(dt); + H5T_sort_value(dt); for (i=0, offset=0; i<dt->u.compnd.nmembs; i++) { dt->u.compnd.memb[i].offset = offset; offset += dt->u.compnd.memb[i].size; @@ -4298,11 +5090,12 @@ H5T_pack(H5T_t *dt) /*------------------------------------------------------------------------- - * Function: H5T_sort_by_offset + * Function: H5T_sort_value * - * Purpose: Sorts the members of a compound data type by their offsets. - * This even works for locked data types since it doesn't change - * the value of the type. + * Purpose: Sorts the members of a compound data type by their offsets; + * sorts the members of an enum type by their values. This even + * works for locked data types since it doesn't change the value + * of the type. * * Return: Non-negative on success/Negative on failure * @@ -4314,42 +5107,384 @@ H5T_pack(H5T_t *dt) *------------------------------------------------------------------------- */ herr_t -H5T_sort_by_offset(H5T_t *dt) +H5T_sort_value(H5T_t *dt) { int i, j, nmembs; + size_t size; hbool_t swapped; + uint8_t tbuf[32]; - FUNC_ENTER(H5T_sort_by_offset, FAIL); + FUNC_ENTER(H5T_sort_value, FAIL); /* Check args */ assert(dt); - assert(H5T_COMPOUND == dt->type); + assert(H5T_COMPOUND==dt->type || H5T_ENUM==dt->type); /* Use a bubble sort because we can short circuit */ - nmembs = dt->u.compnd.nmembs; - for (i=nmembs-1, swapped=TRUE; i>0 && swapped; --i) { - for (j=0, swapped=FALSE; j<i; j++) { - if (dt->u.compnd.memb[j].offset > dt->u.compnd.memb[j+1].offset) { - H5T_member_t tmp = dt->u.compnd.memb[j]; - dt->u.compnd.memb[j] = dt->u.compnd.memb[j+1]; - dt->u.compnd.memb[j+1] = tmp; - swapped = TRUE; + if (H5T_COMPOUND==dt->type) { + if (H5T_SORT_VALUE!=dt->u.compnd.sorted) { + dt->u.compnd.sorted = H5T_SORT_VALUE; + nmembs = dt->u.compnd.nmembs; + for (i=nmembs-1, swapped=TRUE; i>0 && swapped; --i) { + for (j=0, swapped=FALSE; j<i; j++) { + if (dt->u.compnd.memb[j].offset > + dt->u.compnd.memb[j+1].offset) { + H5T_cmemb_t tmp = dt->u.compnd.memb[j]; + dt->u.compnd.memb[j] = dt->u.compnd.memb[j+1]; + dt->u.compnd.memb[j+1] = tmp; + swapped = TRUE; + } + } + } +#ifndef NDEBUG + /* I never trust a sort :-) -RPM */ + for (i=0; i<nmembs-1; i++) { + assert(dt->u.compnd.memb[i].offset < + dt->u.compnd.memb[i+1].offset); } +#endif + } + } else if (H5T_ENUM==dt->type) { + if (H5T_SORT_VALUE!=dt->u.enumer.sorted) { + dt->u.enumer.sorted = H5T_SORT_VALUE; + nmembs = dt->u.enumer.nmembs; + size = dt->size; + assert(size<=sizeof(tbuf)); + for (i=nmembs-1, swapped=TRUE; i>0 && swapped; --i) { + for (j=0, swapped=FALSE; j<i; j++) { + if (HDmemcmp(dt->u.enumer.value+j*size, + dt->u.enumer.value+(j+1)*size, + size)>0) { + /* Swap names */ + char *tmp = dt->u.enumer.name[j]; + dt->u.enumer.name[j] = dt->u.enumer.name[j+1]; + dt->u.enumer.name[j+1] = tmp; + + /* Swap values */ + HDmemcpy(tbuf, dt->u.enumer.value+j*size, size); + HDmemcpy(dt->u.enumer.value+j*size, + dt->u.enumer.value+(j+1)*size, size); + HDmemcpy(dt->u.enumer.value+(j+1)*size, tbuf, size); + + swapped = TRUE; + } + } + } +#ifndef NDEBUG + /* I never trust a sort :-) -RPM */ + for (i=0; i<nmembs-1; i++) { + assert(HDmemcmp(dt->u.enumer.value+i*size, + dt->u.enumer.value+(i+1)*size, + size)<0); + } +#endif } } + + FUNC_LEAVE(SUCCEED); +} + +/*------------------------------------------------------------------------- + * Function: H5T_sort_name + * + * Purpose: Sorts members of a compound or enumeration data type by their + * names. This even works for locked data types since it doesn't + * change the value of the types. + * + * Return: Success: Non-negative + * + * Failure: Negative + * + * Programmer: Robb Matzke + * Monday, January 4, 1999 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_sort_name(H5T_t *dt) +{ + int i, j, nmembs; + size_t size; + hbool_t swapped; + uint8_t tbuf[32]; + + FUNC_ENTER(H5T_sort_name, FAIL); + + /* Check args */ + assert(dt); + assert(H5T_COMPOUND==dt->type || H5T_ENUM==dt->type); + + /* Use a bubble sort because we can short circuit */ + if (H5T_COMPOUND==dt->type) { + if (H5T_SORT_NAME!=dt->u.compnd.sorted) { + dt->u.compnd.sorted = H5T_SORT_NAME; + nmembs = dt->u.compnd.nmembs; + for (i=nmembs-1, swapped=TRUE; i>0 && swapped; --i) { + for (j=0, swapped=FALSE; j<i; j++) { + if (HDstrcmp(dt->u.compnd.memb[j].name, + dt->u.compnd.memb[j+1].name)>0) { + H5T_cmemb_t tmp = dt->u.compnd.memb[j]; + dt->u.compnd.memb[j] = dt->u.compnd.memb[j+1]; + dt->u.compnd.memb[j+1] = tmp; + swapped = TRUE; + } + } + } #ifndef NDEBUG - /* I never trust a sort :-) */ - for (i = 0; i < dt->u.compnd.nmembs - 1; i++) { - assert(dt->u.compnd.memb[i].offset < dt->u.compnd.memb[i + 1].offset); - } + /* I never trust a sort :-) -RPM */ + for (i=0; i<nmembs-1; i++) { + assert(HDstrcmp(dt->u.compnd.memb[i].name, + dt->u.compnd.memb[i+1].name)<0); + } #endif + } + } else if (H5T_ENUM==dt->type) { + if (H5T_SORT_NAME!=dt->u.enumer.sorted) { + dt->u.enumer.sorted = H5T_SORT_NAME; + nmembs = dt->u.enumer.nmembs; + size = dt->size; + assert(size<=sizeof(tbuf)); + for (i=nmembs-1, swapped=TRUE; i>0 && swapped; --i) { + for (j=0, swapped=FALSE; j<i; j++) { + if (HDstrcmp(dt->u.enumer.name[j], + dt->u.enumer.name[j+1])>0) { + /* Swap names */ + char *tmp = dt->u.enumer.name[j]; + dt->u.enumer.name[j] = dt->u.enumer.name[j+1]; + dt->u.enumer.name[j+1] = tmp; + + /* Swap values */ + HDmemcpy(tbuf, dt->u.enumer.value+j*size, size); + HDmemcpy(dt->u.enumer.value+j*size, + dt->u.enumer.value+(j+1)*size, size); + HDmemcpy(dt->u.enumer.value+(j+1)*size, tbuf, size); + + swapped = TRUE; + } + } + } +#ifndef NDEBUG + /* I never trust a sort :-) -RPM */ + for (i=0; i<nmembs-1; i++) { + assert(HDstrcmp(dt->u.enumer.name[i], + dt->u.enumer.name[i+1])<0); + } +#endif + } + } + + FUNC_LEAVE(SUCCEED); +} + + +/*------------------------------------------------------------------------- + * Function: H5T_enum_insert + * + * Purpose: Insert a new member having a NAME and VALUE into an + * enumeration data TYPE. The NAME and VALUE must both be + * unique. The VALUE points to data of the data type defined for + * the enumeration base type. + * + * Return: Success: non-negative + * + * Failure: negative + * + * Programmer: Robb Matzke + * Wednesday, December 23, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_enum_insert(H5T_t *dt, const char *name, void *value) +{ + int i; + char **names=NULL; + uint8_t *values=NULL; + + FUNC_ENTER(H5T_enum_insert, FAIL); + assert(dt); + assert(name && *name); + assert(value); + + /* The name and value had better not already exist */ + for (i=0; i<dt->u.enumer.nmembs; i++) { + if (!HDstrcmp(dt->u.enumer.name[i], name)) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "name redefinition"); + } + if (!HDmemcmp(dt->u.enumer.value+i*dt->size, value, dt->size)) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "value redefinition"); + } + } + + /* Increase table sizes */ + if (dt->u.enumer.nmembs >= dt->u.enumer.nalloc) { + intn n = MAX(32, 2*dt->u.enumer.nalloc); + if (NULL==(names=H5MM_realloc(dt->u.enumer.name, n*sizeof(char*)))) { + HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, + "memory allocation failed"); + } + dt->u.enumer.name = names; + + if (NULL==(values=H5MM_realloc(dt->u.enumer.value, n*dt->size))) { + HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, + "memory allocation failed"); + } + dt->u.enumer.value = values; + dt->u.enumer.nalloc = n; + } + + /* Insert new member at end of member arrays */ + dt->u.enumer.sorted = H5T_SORT_NONE; + i = dt->u.enumer.nmembs++; + dt->u.enumer.name[i] = H5MM_xstrdup(name); + HDmemcpy(dt->u.enumer.value+i*dt->size, value, dt->size); FUNC_LEAVE(SUCCEED); } /*------------------------------------------------------------------------- + * Function: H5T_enum_nameof + * + * Purpose: Finds the symbol name that corresponds the the specified + * VALUE of an enumeration data type DT. At most SIZE characters + * of the symbol name are copied into the NAME buffer. If the + * entire symbol name and null terminator do not fit in the NAME + * buffer then as many characters as possible are copied and the + * function returns failure. + * + * If NAME is the null pointer and SIZE is zero then enough + * space is allocated to hold the result and a pointer to that + * memory is returned. + * + * Return: Success: Pointer to NAME + * + * Failure: NULL, name[0] is set to null. + * + * Programmer: Robb Matzke + * Monday, January 4, 1999 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +char * +H5T_enum_nameof(H5T_t *dt, void *value, char *name/*out*/, size_t size) +{ + intn lt, md, rt; /*indices for binary search */ + intn cmp; /*comparison result */ + + FUNC_ENTER(H5T_enum_nameof, NULL); + + /* Check args */ + assert(dt && H5T_ENUM==dt->type); + assert(value); + assert(name || 0==size); + if (name && size>0) *name = '\0'; + + /* Do a binary search over the values to find the correct one */ + H5T_sort_value(dt); + lt = 0; + rt = dt->u.enumer.nmembs; + md = -1; + + while (lt<rt) { + md = (lt+rt)/2; + cmp = HDmemcmp(value, dt->u.enumer.value+md*dt->size, dt->size); + if (cmp<0) { + rt = md; + } else if (cmp>0) { + lt = md+1; + } else { + break; + } + } + if (md<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_NOTFOUND, NULL, + "value is not in the domain of the enumeration type"); + } + + /* Save result name */ + if (!name && NULL==(name=H5MM_malloc(strlen(dt->u.enumer.name[md])+1))) { + HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, + "memory allocation failed"); + } + HDstrncpy(name, dt->u.enumer.name[md], size); + if (HDstrlen(dt->u.enumer.name[md])>=size) { + HRETURN_ERROR(H5E_DATATYPE, H5E_NOSPACE, NULL, + "name has been truncated"); + } + FUNC_LEAVE(name); +} + + +/*------------------------------------------------------------------------- + * Function: H5T_enum_valueof + * + * Purpose: Finds the value that corresponds the the specified symbol + * NAME of an enumeration data type DT and copy it to the VALUE + * result buffer. The VALUE should be allocated by the caller to + * be large enough for the result. + * + * Return: Success: Non-negative, value stored in VALUE. + * + * Failure: Negative, VALUE is undefined. + * + * Programmer: Robb Matzke + * Monday, January 4, 1999 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_enum_valueof(H5T_t *dt, const char *name, void *value/*out*/) +{ + intn lt, md, rt; /*indices for binary search */ + intn cmp; /*comparison result */ + + FUNC_ENTER(H5T_enum_nameof, FAIL); + + /* Check args */ + assert(dt && H5T_ENUM==dt->type); + assert(name && *name); + assert(value); + + /* Do a binary search over the names to find the correct one */ + H5T_sort_name(dt); + lt = 0; + rt = dt->u.enumer.nmembs; + md = -1; + + while (lt<rt) { + md = (lt+rt)/2; + cmp = HDstrcmp(name, dt->u.enumer.name[md]); + if (cmp<0) { + rt = md; + } else if (cmp>0) { + lt = md+1; + } else { + break; + } + } + if (md<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_NOTFOUND, FAIL, + "string is not in the domain of the enumeration type"); + } + + HDmemcpy(value, dt->u.enumer.value+md*dt->size, dt->size); + FUNC_LEAVE(SUCCEED); +} + + +/*------------------------------------------------------------------------- * Function: H5T_cmp * * Purpose: Compares two data types. @@ -4364,6 +5499,8 @@ H5T_sort_by_offset(H5T_t *dt) * Wednesday, December 10, 1997 * * Modifications: + * Robb Matzke, 22 Dec 1998 + * Able to compare enumeration data types. * *------------------------------------------------------------------------- */ @@ -4374,6 +5511,7 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2) intn ret_value = 0; intn i, j, tmp; hbool_t swapped; + size_t base_size; FUNC_ENTER(H5T_cmp, 0); @@ -4389,6 +5527,14 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2) if (dt1->size < dt2->size) HGOTO_DONE(-1); if (dt1->size > dt2->size) HGOTO_DONE(1); + if (dt1->parent && !dt2->parent) HGOTO_DONE(-1); + if (!dt1->parent && dt2->parent) HGOTO_DONE(1); + if (dt1->parent) { + tmp = H5T_cmp(dt1->parent, dt2->parent); + if (tmp<0) HGOTO_DONE(-1); + if (tmp>0) HGOTO_DONE(1); + } + if (H5T_COMPOUND == dt1->type) { /* * Compound data types... @@ -4477,7 +5623,69 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2) if (tmp < 0) HGOTO_DONE(-1); if (tmp > 0) HGOTO_DONE(1); } + + } else if (H5T_ENUM==dt1->type) { + /* + * Enumeration data types... + */ + if (dt1->u.enumer.nmembs < dt2->u.enumer.nmembs) HGOTO_DONE(-1); + if (dt1->u.enumer.nmembs > dt2->u.enumer.nmembs) HGOTO_DONE(1); + + /* Build an index for each type so the names are sorted */ + if (NULL==(idx1 = H5MM_malloc(dt1->u.enumer.nmembs * sizeof(intn))) || + NULL==(idx2 = H5MM_malloc(dt1->u.enumer.nmembs * sizeof(intn)))) { + HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, 0, + "memory allocation failed"); + } + for (i=0; i<dt1->u.enumer.nmembs; i++) idx1[i] = idx2[i] = i; + for (i=dt1->u.enumer.nmembs-1, swapped=TRUE; swapped && i>=0; --i) { + for (j=0, swapped=FALSE; j<i; j++) { + if (HDstrcmp(dt1->u.enumer.name[idx1[j]], + dt1->u.enumer.name[idx1[j+1]]) > 0) { + tmp = idx1[j]; + idx1[j] = idx1[j+1]; + idx1[j+1] = tmp; + swapped = TRUE; + } + } + } + for (i=dt2->u.enumer.nmembs-1, swapped=TRUE; swapped && i>=0; --i) { + for (j=0, swapped=FALSE; j<i; j++) { + if (HDstrcmp(dt2->u.enumer.name[idx2[j]], + dt2->u.enumer.name[idx2[j+1]]) > 0) { + tmp = idx2[j]; + idx2[j] = idx2[j+1]; + idx2[j+1] = tmp; + swapped = TRUE; + } + } + } +#ifdef H5T_DEBUG + /* I don't quite trust the code above yet :-) --RPM */ + for (i=0; i<dt1->u.enumer.nmembs-1; i++) { + assert(HDstrcmp(dt1->u.enumer.name[idx1[i]], + dt1->u.enumer.name[idx1[i+1]])); + assert(HDstrcmp(dt2->u.enumer.name[idx2[i]], + dt2->u.enumer.name[idx2[i+1]])); + } +#endif + + /* Compare the members */ + base_size = dt1->parent->size; + for (i=0; i<dt1->u.enumer.nmembs; i++) { + tmp = HDstrcmp(dt1->u.enumer.name[idx1[i]], + dt2->u.enumer.name[idx2[i]]); + if (tmp<0) HGOTO_DONE(-1); + if (tmp>0) HGOTO_DONE(1); + + tmp = HDmemcmp(dt1->u.enumer.value+idx1[i]*base_size, + dt2->u.enumer.value+idx2[i]*base_size, + base_size); + if (tmp<0) HGOTO_DONE(-1); + if (tmp>0) HGOTO_DONE(1); + } + } else { /* * Atomic data types... @@ -5041,10 +6249,11 @@ H5T_print_stats(H5T_path_t __unused__ *path, intn *nprint/*in,out*/) *------------------------------------------------------------------------- */ herr_t -H5T_debug(H5T_t *dt, FILE * stream) +H5T_debug(H5T_t *dt, FILE *stream) { const char *s1="", *s2=""; int i, j; + size_t k, base_size; uint64_t tmp; FUNC_ENTER(H5T_debug, FAIL); @@ -5075,6 +6284,9 @@ H5T_debug(H5T_t *dt, FILE * stream) case H5T_COMPOUND: s1 = "struct"; break; + case H5T_ENUM: + s1 = "enum"; + break; default: s1 = ""; break; @@ -5184,8 +6396,10 @@ H5T_debug(H5T_t *dt, FILE * stream) /* No additional info */ break; } - } else { - for (i = 0; i < dt->u.compnd.nmembs; i++) { + + } else if (H5T_COMPOUND==dt->type) { + /* Compound data type */ + for (i=0; i<dt->u.compnd.nmembs; i++) { fprintf(stream, "\n\"%s\" @%lu", dt->u.compnd.memb[i].name, (unsigned long) (dt->u.compnd.memb[i].offset)); @@ -5201,6 +6415,24 @@ H5T_debug(H5T_t *dt, FILE * stream) H5T_debug(dt->u.compnd.memb[i].type, stream); } fprintf(stream, "\n"); + + } else if (H5T_ENUM==dt->type) { + /* Enumeration data type */ + fprintf(stream, " "); + H5T_debug(dt->parent, stream); + base_size = dt->parent->size; + for (i=0; i<dt->u.enumer.nmembs; i++) { + fprintf(stream, "\n\"%s\" = 0x", dt->u.enumer.name[i]); + for (k=0; k<base_size; k++) { + fprintf(stream, "%02x", + (unsigned)(dt->u.enumer.value+i*base_size+k)); + } + } + fprintf(stream, "\n"); + + } else { + /* Unknown */ + fprintf(stream, "unknown class %d\n", (int)(dt->type)); } fprintf(stream, "}"); diff --git a/src/H5Tconv.c b/src/H5Tconv.c index 2ba0e32..4915b22 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -24,6 +24,13 @@ typedef struct H5T_conv_struct_t { size_t *memb_nelmts; /*member element count */ } H5T_conv_struct_t; +/* Conversion data for H5T_conv_enum() */ +typedef struct H5T_enum_struct_t { + intn base; /*lowest `in' value */ + intn length; /*num elements in arrays */ + intn *src2dst; /*map from src to dst index */ +} H5T_enum_struct_t; + /* Conversion data for the hardware conversion functions */ typedef struct H5T_conv_hw_t { hsize_t s_aligned; /*number source elements aligned */ @@ -336,7 +343,7 @@ static intn interface_initialize_g = 0; } \ } #else -# define CI_PRINT_STATS /*void*/ +# define CI_PRINT_STATS(STYPE,DTYPE) /*void*/ #endif /*------------------------------------------------------------------------- @@ -543,8 +550,8 @@ H5T_conv_struct_init (H5T_t *src, H5T_t *dst, H5T_cdata_t *cdata) /* * Insure that members are sorted. */ - H5T_sort_by_offset (src); - H5T_sort_by_offset (dst); + H5T_sort_value(src); + H5T_sort_value(dst); /* * Build a mapping from source member number to destination member @@ -582,8 +589,8 @@ H5T_conv_struct_init (H5T_t *src, H5T_t *dst, H5T_cdata_t *cdata) */ for (i=0; i<src->u.compnd.nmembs; i++) { if (src2dst[i]>=0) { - H5T_member_t *src_memb = src->u.compnd.memb + i; - H5T_member_t *dst_memb = dst->u.compnd.memb + src2dst[i]; + H5T_cmemb_t *src_memb = src->u.compnd.memb + i; + H5T_cmemb_t *dst_memb = dst->u.compnd.memb + src2dst[i]; if (src_memb->ndims != dst_memb->ndims) { HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "source and dest members have incompatible " @@ -687,8 +694,8 @@ H5T_conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, H5T_t *src = NULL; /*source data type */ H5T_t *dst = NULL; /*destination data type */ intn *src2dst = NULL; /*maps src member to dst member */ - H5T_member_t *src_memb = NULL; /*source struct member descript.*/ - H5T_member_t *dst_memb = NULL; /*destination struct memb desc. */ + H5T_cmemb_t *src_memb = NULL; /*source struct member descript.*/ + H5T_cmemb_t *dst_memb = NULL; /*destination struct memb desc. */ size_t offset; /*byte offset wrt struct */ size_t src_delta, dst_delta; /*source & destination stride */ uintn elmtno; @@ -754,8 +761,8 @@ H5T_conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, /* * Insure that members are sorted. */ - H5T_sort_by_offset (src); - H5T_sort_by_offset (dst); + H5T_sort_value(src); + H5T_sort_value(dst); src2dst = priv->src2dst; /* @@ -861,6 +868,298 @@ H5T_conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, /*------------------------------------------------------------------------- + * Function: H5T_conv_enum_init + * + * Purpose: Initialize information for H5T_conv_enum(). + * + * Return: Success: Non-negative + * + * Failure: Negative + * + * Programmer: Robb Matzke + * Monday, January 4, 1999 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +H5T_conv_enum_init(H5T_t *src, H5T_t *dst, H5T_cdata_t *cdata) +{ + H5T_enum_struct_t *priv=NULL; /*private conversion data */ + intn n; /*src value cast as native int */ + intn domain[2]; /*min and max source values */ + intn *map=NULL; /*map from src value to dst idx */ + intn length; /*nelmts in map array */ + herr_t ret_value=FAIL; /*return value */ + intn i, j; /*counters */ + + FUNC_ENTER(H5T_conv_enum_init, FAIL); + + cdata->need_bkg = H5T_BKG_NO; + if (NULL==(priv=cdata->priv=H5MM_calloc(sizeof(*priv)))) { + HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, + "memory allocation failed"); + } + if (0==src->u.enumer.nmembs) { + HRETURN(SUCCEED); + } + + /* + * Check that the source symbol names are a subset of the destination + * symbol names and build a map from source member index to destination + * member index. + */ + H5T_sort_name(src); + H5T_sort_name(dst); + if (NULL==(priv->src2dst=H5MM_malloc(src->u.enumer.nmembs*sizeof(int)))) { + HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, + "memory allocation failed");; + } + for (i=0, j=0; + i<src->u.enumer.nmembs && j<dst->u.enumer.nmembs; + i++, j++) { + while (j<dst->u.enumer.nmembs && + HDstrcmp(src->u.enumer.name[i], dst->u.enumer.name[j])) j++; + if (j>=dst->u.enumer.nmembs) { + HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "source type is not a subset of destination type"); + } + priv->src2dst[i] = j; + } + + /* + * The conversion function will use an O(log N) lookup method for each + * value converted. However, if all of the following constraints are met + * then we can build a perfect hash table and use an O(1) lookup method. + * + * A: The source data type size matches one of our native data type + * sizes. + * + * B: After casting the source value bit pattern to a native type + * the size of the range of values is less than 20% larger than + * the number of values. + * + * If this special case is met then we use the source bit pattern cast as + * a native integer type as an index into the `val2dst'. The values of + * that array are the index numbers in the destination type or negative + * if the entry is unused. + */ + if (1==src->size || sizeof(short)==src->size || sizeof(int)==src->size) { + for (i=0; i<src->u.enumer.nmembs; i++) { + if (1==src->size) { + n = *((signed char*)(src->u.enumer.value+i)); + } else if (sizeof(short)==src->size) { + n = *((short*)(src->u.enumer.value+i*src->size)); + } else { + n = *((int*)(src->u.enumer.value+i*src->size)); + } + if (0==i) { + domain[0] = domain[1] = n; + } else { + domain[0] = MIN(domain[0], n); + domain[1] = MAX(domain[1], n); + } + } + + length = (domain[1]-domain[0])+1; + if (src->u.enumer.nmembs<2 || + (double)length/src->u.enumer.nmembs<1.2) { + priv->base = domain[0]; + priv->length = length; + if (NULL==(map=H5MM_malloc(length*sizeof(int)))) { + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, + "memory allocation failed"); + } + for (i=0; i<length; i++) map[i] = -1; /*entry unused*/ + for (i=0; i<src->u.enumer.nmembs; i++) { + if (1==src->size) { + n = *((signed char*)(src->u.enumer.value+i)); + } else if (sizeof(short)==src->size) { + n = *((short*)(src->u.enumer.value+i*src->size)); + } else { + n = *((int*)(src->u.enumer.value+i*src->size)); + } + n -= priv->base; + assert(n>=0 && n<priv->length); + assert(map[n]<0); + map[n] = priv->src2dst[i]; + } + + /* + * Replace original src2dst array with our new one. The original + * was indexed by source member number while the new one is + * indexed by source values. + */ + H5MM_xfree(priv->src2dst); + priv->src2dst = map; + HGOTO_DONE(SUCCEED); + } + } + ret_value = SUCCEED; + + done: + if (ret_value<0 && priv) { + H5MM_xfree(priv->src2dst); + H5MM_xfree(priv); + cdata->priv = NULL; + } + FUNC_LEAVE(ret_value); +} + + +/*------------------------------------------------------------------------- + * Function: H5T_conv_enum + * + * Purpose: Converts one type of enumerated data to another. + * + * Return: Success: Non-negative + * + * Failure: negative + * + * Programmer: Robb Matzke + * Monday, January 4, 1999 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, + size_t nelmts, void *_buf, void __unused__ *bkg) +{ + uint8_t *buf = (uint8_t*)_buf; /*cast for pointer arithmetic */ + H5T_t *src=NULL, *dst=NULL; /*src and dst data types */ + uint8_t *s=NULL, *d=NULL; /*src and dst BUF pointers */ + intn src_delta, dst_delta; /*conversion strides */ + intn n; /*src value cast as native int */ + size_t i; /*counters */ + H5T_enum_struct_t *priv = (H5T_enum_struct_t*)(cdata->priv); + + FUNC_ENTER(H5T_conv_enum, FAIL); + switch (cdata->command) { + case H5T_CONV_INIT: + /* + * Determine if this conversion function applies to the conversion + * path SRC_ID->DST_ID. If not return failure; otherwise initialize + * the `priv' field of `cdata' with information about the underlying + * integer conversion. + */ + if (H5I_DATATYPE != H5I_get_type(src_id) || + NULL == (src = H5I_object(src_id)) || + H5I_DATATYPE != H5I_get_type(dst_id) || + NULL == (dst = H5I_object(dst_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); + } + assert (H5T_ENUM==src->type); + assert (H5T_ENUM==dst->type); + if (H5T_conv_enum_init(src, dst, cdata)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to initialize private data"); + } + break; + + case H5T_CONV_FREE: +#ifdef H5T_DEBUG + if (H5DEBUG(T)) { + fprintf(H5DEBUG(T), " Using %s mapping function (%s)\n", + priv->length?"O(N)":"O(N log N)", "N==nelmts"); + } +#endif + if (priv) { + H5MM_xfree(priv->src2dst); + H5MM_xfree(priv); + } + cdata->priv = NULL; + break; + + case H5T_CONV_CONV: + if (H5I_DATATYPE != H5I_get_type(src_id) || + NULL == (src = H5I_object(src_id)) || + H5I_DATATYPE != H5I_get_type(dst_id) || + NULL == (dst = H5I_object(dst_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); + } + assert (H5T_ENUM==src->type); + assert (H5T_ENUM==dst->type); + H5T_sort_name(src); + H5T_sort_name(dst); + + /* + * Direction of conversion. + */ + if (dst->size <= src->size) { + src_delta = src->size; + dst_delta = dst->size; + s = d = buf; + } else { + src_delta = -(src->size); + dst_delta = -(dst->size); + s = buf + (nelmts-1) * src->size; + d = buf + (nelmts-1) * dst->size; + } + + for (i=0; i<nelmts; i++, s+=src_delta, d+=dst_delta) { + if (priv->length) { + /* Use O(1) lookup */ + if (1==src->size) { + n = *((signed char*)s); + } else if (sizeof(short)==src->size) { + n = *((short*)s); + } else { + n = *((int*)s); + } + if (n<0 || n>=priv->length || priv->src2dst[n]<0) { + if (!H5T_overflow_g || + (H5T_overflow_g)(src_id, dst_id, s, d)<0) { + HDmemset(d, 0xff, dst->size); + } + } else { + HDmemcpy(d, + dst->u.enumer.value+priv->src2dst[n]*dst->size, + dst->size); + } + } else { + /* Use O(log N) lookup */ + int lt = 0; + int rt = src->u.enumer.nmembs; + int md, cmp; + while (lt<rt) { + md = (lt+rt)/2; + cmp = HDmemcmp(s, src->u.enumer.value+md*src->size, + src->size); + if (cmp<0) { + rt = md; + } else if (cmp>0) { + lt = md+1; + } else { + break; + } + } + if (lt>=rt) { + if (!H5T_overflow_g || + (H5T_overflow_g)(src_id, dst_id, s, d)<0) { + HDmemset(d, 0xff, dst->size); + } + } else { + HDmemcpy(d, + dst->u.enumer.value+priv->src2dst[md]*dst->size, + dst->size); + } + } + } + break; + + default: + /* Some other command we don't know about yet.*/ + HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, + "unknown conversion command"); + } + FUNC_LEAVE(SUCCEED); +} + + +/*------------------------------------------------------------------------- * Function: H5T_conv_i_i * * Purpose: Convert one integer type to another. This is the catch-all diff --git a/src/H5Tpkg.h b/src/H5Tpkg.h index a390897..2e8bf1f 100644 --- a/src/H5Tpkg.h +++ b/src/H5Tpkg.h @@ -61,12 +61,30 @@ typedef struct H5T_atomic_t { } u; } H5T_atomic_t; +/* How members are sorted for compound or enum data types */ +typedef enum H5T_sort_t { + H5T_SORT_NONE = 0, /*not sorted */ + H5T_SORT_NAME = 1, /*sorted by member name */ + H5T_SORT_VALUE = 2 /*sorted by memb offset or enum value*/ +} H5T_sort_t; + +/* A compound data type */ typedef struct H5T_compnd_t { intn nalloc; /*num entries allocated in MEMB array*/ intn nmembs; /*number of members defined in struct*/ - struct H5T_member_t *memb; /*array of struct members */ + H5T_sort_t sorted; /*how are members sorted? */ + struct H5T_cmemb_t *memb; /*array of struct members */ } H5T_compnd_t; +/* An enumeration data type */ +typedef struct H5T_enum_t { + intn nalloc; /*num entries allocated */ + intn nmembs; /*number of members defined in enum */ + H5T_sort_t sorted; /*how are members sorted? */ + uint8_t *value; /*array of values */ + char **name; /*array of symbol names */ +} H5T_enum_t; + typedef enum H5T_state_t { H5T_STATE_TRANSIENT, /*type is a modifiable transient */ H5T_STATE_RDONLY, /*transient, not modifiable, closable*/ @@ -81,13 +99,16 @@ struct H5T_t { H5F_t *sh_file;/*file pointer if this is a shared type */ H5T_class_t type; /*which class of type is this? */ size_t size; /*total size of an instance of this type */ + struct H5T_t *parent;/*parent type for derived data types */ union { H5T_atomic_t atomic; /*an atomic data type */ H5T_compnd_t compnd; /*a compound data type (struct) */ + H5T_enum_t enumer; /*an enumeration type (enum) */ } u; }; -typedef struct H5T_member_t { +/* A compound data type member */ +typedef struct H5T_cmemb_t { char *name; /*name of this member */ size_t offset; /*offset from beginning of struct */ size_t size; /*total size: dims * type_size */ @@ -95,7 +116,7 @@ typedef struct H5T_member_t { size_t dim[4]; /*size in each dimension */ intn perm[4]; /*index permutation */ struct H5T_t *type; /*type of this member */ -} H5T_member_t; +} H5T_cmemb_t; /* The master list of soft conversion functions */ typedef struct H5T_soft_t { @@ -142,6 +163,8 @@ herr_t H5T_conv_order (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, void *_buf, void *bkg); herr_t H5T_conv_struct (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, void *_buf, void *bkg); +herr_t H5T_conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, + size_t nelmts, void *buf, void __unused__ *bkg); herr_t H5T_conv_i_i (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, void *_buf, void *bkg); herr_t H5T_conv_f_f (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, diff --git a/src/H5Tprivate.h b/src/H5Tprivate.h index a78d303..6056a43 100644 --- a/src/H5Tprivate.h +++ b/src/H5Tprivate.h @@ -64,25 +64,33 @@ typedef struct H5T_path_t { herr_t H5T_native_open(void); herr_t H5T_init(void); htri_t H5T_isa(H5G_entry_t *ent); -H5T_t *H5T_open (H5G_entry_t *loc, const char *name); -H5T_t *H5T_create (H5T_class_t type, size_t size); -H5T_t *H5T_copy (const H5T_t *old_dt, H5T_copy_t method); -herr_t H5T_commit (H5G_entry_t *loc, const char *name, H5T_t *type); -herr_t H5T_lock (H5T_t *dt, hbool_t immutable); -herr_t H5T_close (H5T_t *dt); -size_t H5T_get_size (const H5T_t *dt); -intn H5T_cmp (const H5T_t *dt1, const H5T_t *dt2); -htri_t H5T_is_atomic (const H5T_t *dt); -herr_t H5T_insert (H5T_t *parent, const char *name, size_t offset, - intn ndims, const size_t *dim, const intn *perm, - const H5T_t *member); -herr_t H5T_sort_by_offset (H5T_t *dt); -herr_t H5T_pack (H5T_t *dt); -herr_t H5T_debug (H5T_t *dt, FILE * stream); -H5G_entry_t *H5T_entof (H5T_t *dt); -H5T_path_t *H5T_path_find (const H5T_t *src, const H5T_t *dst, - const char *name, H5T_conv_t func); +H5T_t *H5T_open(H5G_entry_t *loc, const char *name); +H5T_t *H5T_create(H5T_class_t type, size_t size); +H5T_t *H5T_copy(const H5T_t *old_dt, H5T_copy_t method); +herr_t H5T_commit(H5G_entry_t *loc, const char *name, H5T_t *type); +herr_t H5T_lock(H5T_t *dt, hbool_t immutable); +herr_t H5T_close(H5T_t *dt); +size_t H5T_get_size(const H5T_t *dt); +intn H5T_cmp(const H5T_t *dt1, const H5T_t *dt2); +htri_t H5T_is_atomic(const H5T_t *dt); +herr_t H5T_struct_insert(H5T_t *parent, const char *name, size_t offset, + intn ndims, const size_t *dim, const intn *perm, + const H5T_t *member); +herr_t H5T_enum_insert(H5T_t *dt, const char *name, void *value); +herr_t H5T_sort_value(H5T_t *dt); +herr_t H5T_pack(H5T_t *dt); +herr_t H5T_debug(H5T_t *dt, FILE * stream); +H5G_entry_t *H5T_entof(H5T_t *dt); +H5T_path_t *H5T_path_find(const H5T_t *src, const H5T_t *dst, + const char *name, H5T_conv_t func); +herr_t H5T_sort_vaue(H5T_t *dt); +herr_t H5T_sort_name(H5T_t *dt); herr_t H5T_convert(H5T_path_t *tpath, hid_t src_id, hid_t dst_id, size_t nelmts, void *buf, void *bkg); +herr_t H5T_set_size(H5T_t *dt, size_t size); +herr_t H5T_set_precision(H5T_t *dt, size_t prec); +herr_t H5T_set_offset(H5T_t *dt, size_t offset); +char *H5T_enum_nameof(H5T_t *dt, void *value, char *name/*out*/, size_t size); +herr_t H5T_enum_valueof(H5T_t *dt, const char *name, void *value/*out*/); #endif diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h index 2f3048f..cab2531 100644 --- a/src/H5Tpublic.h +++ b/src/H5Tpublic.h @@ -33,8 +33,9 @@ typedef enum H5T_class_t { H5T_OPAQUE = 5, /*opaque types */ H5T_COMPOUND = 6, /*compound types */ H5T_REFERENCE = 7, /*reference types */ + H5T_ENUM = 8, /*enumeration types */ - H5T_NCLASSES = 8 /*this must be last */ + H5T_NCLASSES = 9 /*this must be last */ } H5T_class_t; /* Byte orders */ @@ -399,29 +400,37 @@ herr_t H5Tinsert_array (hid_t parent_id, const char *name, size_t offset, hid_t member_id); herr_t H5Tpack (hid_t type_id); +/* Operations defined on enumeration data types */ +hid_t H5Tenum_create(hid_t base_id); +herr_t H5Tenum_insert(hid_t type, const char *name, void *value); +hid_t H5Tenum_nameof(hid_t type, void *value, char *name/*out*/, size_t size); +hid_t H5Tenum_valueof(hid_t type, const char *name, void *value/*out*/); + /* Querying property values */ -H5T_class_t H5Tget_class (hid_t type_id); -size_t H5Tget_size (hid_t type_id); -H5T_order_t H5Tget_order (hid_t type_id); -size_t H5Tget_precision (hid_t type_id); -size_t H5Tget_offset (hid_t type_id); -herr_t H5Tget_pad (hid_t type_id, H5T_pad_t *lsb/*out*/, - H5T_pad_t *msb/*out*/); -H5T_sign_t H5Tget_sign (hid_t type_id); -herr_t H5Tget_fields (hid_t type_id, size_t *spos/*out*/, - size_t *epos/*out*/, size_t *esize/*out*/, - size_t *mpos/*out*/, size_t *msize/*out*/); -size_t H5Tget_ebias (hid_t type_id); -H5T_norm_t H5Tget_norm (hid_t type_id); -H5T_pad_t H5Tget_inpad (hid_t type_id); -H5T_str_t H5Tget_strpad (hid_t type_id); -int H5Tget_nmembers (hid_t type_id); -char *H5Tget_member_name (hid_t type_id, int membno); -size_t H5Tget_member_offset (hid_t type_id, int membno); -int H5Tget_member_dims (hid_t type_id, int membno, size_t dims[]/*out*/, - int perm[]/*out*/); -hid_t H5Tget_member_type (hid_t type_id, int membno); -H5T_cset_t H5Tget_cset (hid_t type_id); +hid_t H5Tget_super(hid_t type); +H5T_class_t H5Tget_class(hid_t type_id); +size_t H5Tget_size(hid_t type_id); +H5T_order_t H5Tget_order(hid_t type_id); +size_t H5Tget_precision(hid_t type_id); +size_t H5Tget_offset(hid_t type_id); +herr_t H5Tget_pad(hid_t type_id, H5T_pad_t *lsb/*out*/, + H5T_pad_t *msb/*out*/); +H5T_sign_t H5Tget_sign(hid_t type_id); +herr_t H5Tget_fields(hid_t type_id, size_t *spos/*out*/, + size_t *epos/*out*/, size_t *esize/*out*/, + size_t *mpos/*out*/, size_t *msize/*out*/); +size_t H5Tget_ebias(hid_t type_id); +H5T_norm_t H5Tget_norm(hid_t type_id); +H5T_pad_t H5Tget_inpad(hid_t type_id); +H5T_str_t H5Tget_strpad(hid_t type_id); +int H5Tget_nmembers(hid_t type_id); +char *H5Tget_member_name(hid_t type_id, int membno); +size_t H5Tget_member_offset(hid_t type_id, int membno); +int H5Tget_member_dims(hid_t type_id, int membno, size_t dims[]/*out*/, + int perm[]/*out*/); +hid_t H5Tget_member_type(hid_t type_id, int membno); +herr_t H5Tget_member_value(hid_t type_id, int membno, void *value/*out*/); +H5T_cset_t H5Tget_cset(hid_t type_id); /* Setting property values */ herr_t H5Tset_size (hid_t type_id, size_t size); diff --git a/src/H5detect.c b/src/H5detect.c index 9220915..92fe3ae 100644 --- a/src/H5detect.c +++ b/src/H5detect.c @@ -241,8 +241,9 @@ precision (detected_t *d) precision (&(INFO)); \ } +#if defined(HAVE_FORK) && defined(HAVE_WAITPID) #define ALIGNMENT(TYPE,ALIGN) { \ - char *_buf=malloc(sizeof(TYPE)+align_g[NELMTS(align_g)-1]); \ + char *_buf; \ TYPE _val=0; \ size_t _ano; \ pid_t _child; \ @@ -252,7 +253,9 @@ precision (detected_t *d) fflush(stdout); \ fflush(stderr); \ if (0==(_child=fork())) { \ + _buf = malloc(sizeof(TYPE)+align_g[NELMTS(align_g)-1]); \ _val = *((TYPE*)(_buf+align_g[_ano])); \ + free(_buf); \ exit(0); \ } else if (_child<0) { \ perror("fork"); \ @@ -277,6 +280,10 @@ precision (detected_t *d) fprintf(stderr, "unable to calculate alignment for %s\n", #TYPE); \ } \ } +#else +#define ALIGNMENT(TYPE,ALIGN) (ALIGN)=0 +#endif + /*------------------------------------------------------------------------- diff --git a/src/H5private.h b/src/H5private.h index 1a4afd6..746ddda 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1,9 +1,9 @@ /* * Copyright (C) 1998 NCSA - * All rights reserved. + * All rights reserved. * - * Programmer: Robb Matzke <matzke@llnl.gov> - * Friday, October 30, 1998 + * Programmer: Robb Matzke <matzke@llnl.gov> + * Friday, October 30, 1998 * * Purpose: This file is included by all HDF5 library source files to * define common things which are not defined in the HDF5 API. @@ -12,7 +12,7 @@ */ #ifndef _H5private_H #define _H5private_H -#include <H5public.h> /* Include Public Definitions */ +#include <H5public.h> /* Include Public Definitions */ /* * Include ANSI-C header files. @@ -47,7 +47,7 @@ /* * The `struct stat' data type for stat() and fstat(). This is a Posix file - * but often apears on non-Posix systems also. The `struct stat' is required + * but often apears on non-Posix systems also. The `struct stat' is required * for hdf5 to compile, although only a few fields are actually used. */ #ifdef HAVE_SYS_STAT_H @@ -82,7 +82,7 @@ #endif /* - * Unix ioctls. These are used by h5ls (and perhaps others) to determine a + * Unix ioctls. These are used by h5ls (and perhaps others) to determine a * resonable output width. */ #ifdef HAVE_SYS_IOCTL_H @@ -116,7 +116,7 @@ /* * Does the compiler support the __attribute__(()) syntax? This is how gcc - * suppresses warnings about unused function arguments. It's no big deal if + * suppresses warnings about unused function arguments. It's no big deal if * we don't. */ #ifdef HAVE_ATTRIBUTE @@ -132,14 +132,14 @@ * string. */ #ifndef HAVE_FUNCTION -# define __FUNCTION__ "NoFunctionName" +# define __FUNCTION__ "NoFunctionName" #endif /* Version #'s of the major components of the file format */ -#define HDF5_BOOTBLOCK_VERSION 0 /* of the boot block format */ -#define HDF5_FREESPACE_VERSION 0 /* of the Free-Space Info */ -#define HDF5_OBJECTDIR_VERSION 0 /* of the Object Directory format */ -#define HDF5_SHAREDHEADER_VERSION 0 /* of the Shared-Header Info */ +#define HDF5_BOOTBLOCK_VERSION 0 /* of the boot block format */ +#define HDF5_FREESPACE_VERSION 0 /* of the Free-Space Info */ +#define HDF5_OBJECTDIR_VERSION 0 /* of the Object Directory format */ +#define HDF5_SHAREDHEADER_VERSION 0 /* of the Shared-Header Info */ /* * Status return values for the `herr_t' type. @@ -150,9 +150,9 @@ * function, remember to compare against zero and not one of these two * values. */ -#define SUCCEED 0 -#define FAIL (-1) -#define UFAIL (unsigned)(-1) +#define SUCCEED 0 +#define FAIL (-1) +#define UFAIL (unsigned)(-1) /* number of members in an array */ #ifndef NELMTS @@ -168,7 +168,7 @@ /* maximum of two, three, or four values */ #undef MAX -#define MAX(a,b) (((a)>(b)) ? (a) : (b)) +#define MAX(a,b) (((a)>(b)) ? (a) : (b)) #define MAX2(a,b) MAX(a,b) #define MAX3(a,b,c) MAX(a,MAX(b,c)) #define MAX4(a,b,c,d) MAX(MAX(a,b),MAX(c,d)) @@ -199,7 +199,7 @@ /* * Although `long long' is part of the revised ANSI-C some compilers don't * support it yet. We define `long_long' as the longest integral integer type - * supported by the compiler, usually 64 bits. It must be legal to qualify + * supported by the compiler, usually 64 bits. It must be legal to qualify * `long_long' with `unsigned'. */ #if SIZEOF_LONG_LONG>0 @@ -215,7 +215,7 @@ #endif /* - * Numeric data types. Some of these might be defined in Posix.1g, otherwise + * Numeric data types. Some of these might be defined in Posix.1g, otherwise * we define them with the closest available type which is at least as large * as the number of bits indicated in the type name. The `int8' types *must* * be exactly one byte wide because we use it for pointer calculations to @@ -353,7 +353,7 @@ typedef double float64; #endif /* - * Define a type for generic integers. Use this instead of `int' to + * Define a type for generic integers. Use this instead of `int' to * show that some thought went into the algorithm. */ typedef int intn; @@ -363,13 +363,13 @@ typedef unsigned uintn; * File addresses. */ typedef struct { - uint64_t offset; /*offset within an HDF5 file */ + uint64_t offset; /*offset within an HDF5 file */ } haddr_t; #define H5F_ADDR_UNDEF {((uint64_t)(-1L))} /* - * Maximum and minimum values. These should be defined in <limits.h> for the + * Maximum and minimum values. These should be defined in <limits.h> for the * most part. */ #ifndef LLONG_MAX @@ -386,7 +386,7 @@ typedef struct { /* * Some compilers have problems declaring auto variables that point - * to string constants. Use the CONSTR() macro so it's easy to fix + * to string constants. Use the CONSTR() macro so it's easy to fix * those compilers. */ #ifndef CONSTR @@ -411,263 +411,263 @@ void H5_bandwidth(char *buf/*out*/, double nbytes, double nseconds); * Redefine all the POSIX functions. We should never see a POSIX * function (or any other non-HDF5 function) in the source! */ -#define HDabort() abort() -#define HDabs(X) abs(X) -#define HDaccess(F,M) access(F, M) -#define HDacos(X) acos(X) -#define HDalarm(N) alarm(N) -#define HDasctime(T) asctime(T) -#define HDasin(X) asin(X) -#define HDassert(X) assert(X) -#define HDatan(X) atan(X) -#define HDatan2(X,Y) atan2(X,Y) -#define HDatexit(F) atexit(F) -#define HDatof(S) atof(S) -#define HDatoi(S) atoi(S) -#define HDatol(S) atol(S) -#define HDbsearch(K,B,N,Z,F) bsearch(K,B,N,Z,F) -#define HDcalloc(N,Z) calloc(N,Z) -#define HDceil(X) ceil(X) -#define HDcfgetispeed(T) cfgetispeed(T) -#define HDcfgetospeed(T) cfgetospeed(T) -#define HDcfsetispeed(T,S) cfsetispeed(T,S) -#define HDcfsetospeed(T,S) cfsetospeed(T,S) -#define HDchdir(S) chdir(S) -#define HDchmod(S,M) chmod(S,M) -#define HDchown(S,O,G) chown(S,O,G) -#define HDclearerr(F) clearerr(F) -#define HDclock() clock() -#define HDclose(F) close(F) -#define HDclosedir(D) closedir(D) -#define HDcos(X) cos(X) -#define HDcosh(X) cosh(X) -#define HDcreat(S,M) creat(S,M) -#define HDctermid(S) ctermid(S) -#define HDctime(T) ctime(T) -#define HDcuserid(S) cuserid(S) +#define HDabort() abort() +#define HDabs(X) abs(X) +#define HDaccess(F,M) access(F, M) +#define HDacos(X) acos(X) +#define HDalarm(N) alarm(N) +#define HDasctime(T) asctime(T) +#define HDasin(X) asin(X) +#define HDassert(X) assert(X) +#define HDatan(X) atan(X) +#define HDatan2(X,Y) atan2(X,Y) +#define HDatexit(F) atexit(F) +#define HDatof(S) atof(S) +#define HDatoi(S) atoi(S) +#define HDatol(S) atol(S) +#define HDbsearch(K,B,N,Z,F) bsearch(K,B,N,Z,F) +#define HDcalloc(N,Z) calloc(N,Z) +#define HDceil(X) ceil(X) +#define HDcfgetispeed(T) cfgetispeed(T) +#define HDcfgetospeed(T) cfgetospeed(T) +#define HDcfsetispeed(T,S) cfsetispeed(T,S) +#define HDcfsetospeed(T,S) cfsetospeed(T,S) +#define HDchdir(S) chdir(S) +#define HDchmod(S,M) chmod(S,M) +#define HDchown(S,O,G) chown(S,O,G) +#define HDclearerr(F) clearerr(F) +#define HDclock() clock() +#define HDclose(F) close(F) +#define HDclosedir(D) closedir(D) +#define HDcos(X) cos(X) +#define HDcosh(X) cosh(X) +#define HDcreat(S,M) creat(S,M) +#define HDctermid(S) ctermid(S) +#define HDctime(T) ctime(T) +#define HDcuserid(S) cuserid(S) #ifdef HAVE_DIFFTIME -#define HDdifftime(X,Y) difftime(X,Y) +#define HDdifftime(X,Y) difftime(X,Y) #else #define HDdifftime(X,Y) ((double)(X)-(double)(Y)) #endif -#define HDdiv(X,Y) div(X,Y) -#define HDdup(F) dup(F) -#define HDdup2(F,I) dup2(F,I) +#define HDdiv(X,Y) div(X,Y) +#define HDdup(F) dup(F) +#define HDdup2(F,I) dup2(F,I) /* execl() variable arguments */ /* execle() variable arguments */ /* execlp() variable arguments */ -#define HDexecv(S,AV) execv(S,AV) -#define HDexecve(S,AV,E) execve(S,AV,E) -#define HDexecvp(S,AV) execvp(S,AV) -#define HDexit(N) exit(N) -#define HD_exit(N) _exit(N) -#define HDexp(X) exp(X) -#define HDfabs(X) fabs(X) -#define HDfclose(F) fclose(F) +#define HDexecv(S,AV) execv(S,AV) +#define HDexecve(S,AV,E) execve(S,AV,E) +#define HDexecvp(S,AV) execvp(S,AV) +#define HDexit(N) exit(N) +#define HD_exit(N) _exit(N) +#define HDexp(X) exp(X) +#define HDfabs(X) fabs(X) +#define HDfclose(F) fclose(F) /* fcntl() variable arguments */ -#define HDfdopen(N,S) fdopen(N,S) -#define HDfeof(F) feof(F) -#define HDferror(F) ferror(F) -#define HDfflush(F) fflush(F) -#define HDfgetc(F) fgetc(F) -#define HDfgetpos(F,P) fgetpos(F,P) -#define HDfgets(S,N,F) fgets(S,N,F) -#define HDfileno(F) fileno(F) -#define HDfloor(X) floor(X) -#define HDfmod(X,Y) fmod(X,Y) -#define HDfopen(S,M) fopen(S,M) -#define HDfork() fork() -#define HDfpathconf(F,N) fpathconf(F,N) +#define HDfdopen(N,S) fdopen(N,S) +#define HDfeof(F) feof(F) +#define HDferror(F) ferror(F) +#define HDfflush(F) fflush(F) +#define HDfgetc(F) fgetc(F) +#define HDfgetpos(F,P) fgetpos(F,P) +#define HDfgets(S,N,F) fgets(S,N,F) +#define HDfileno(F) fileno(F) +#define HDfloor(X) floor(X) +#define HDfmod(X,Y) fmod(X,Y) +#define HDfopen(S,M) fopen(S,M) +#define HDfork() fork() +#define HDfpathconf(F,N) fpathconf(F,N) int HDfprintf (FILE *stream, const char *fmt, ...); -#define HDfputc(C,F) fputc(C,F) -#define HDfputs(S,F) fputs(S,F) -#define HDfread(M,Z,N,F) fread(M,Z,N,F) -#define HDfree(M) free(M) -#define HDfreopen(S,M,F) freopen(S,M,F) -#define HDfrexp(X,N) frexp(X,N) +#define HDfputc(C,F) fputc(C,F) +#define HDfputs(S,F) fputs(S,F) +#define HDfread(M,Z,N,F) fread(M,Z,N,F) +#define HDfree(M) free(M) +#define HDfreopen(S,M,F) freopen(S,M,F) +#define HDfrexp(X,N) frexp(X,N) /* fscanf() variable arguments */ -#define HDfseek(F,O,W) fseek(F,O,W) -#define HDfsetpos(F,P) fsetpos(F,P) -#define HDfstat(F,B) fstat(F,B) -#define HDftell(F) ftell(F) -#define HDfwrite(M,Z,N,F) fwrite(M,Z,N,F) -#define HDgetc(F) getc(F) -#define HDgetchar() getchar() -#define HDgetcwd(S,Z) getcwd(S,Z) -#define HDgetegid() getegid() -#define HDgetenv(S) getenv(S) -#define HDgeteuid() geteuid() -#define HDgetgid() getgid() -#define HDgetgrgid(G) getgrgid(G) -#define HDgetgrnam(S) getgrnam(S) -#define HDgetgroups(Z,G) getgroups(Z,G) -#define HDgetlogin() getlogin() -#define HDgetpgrp() getpgrp() -#define HDgetpid() getpid() -#define HDgetppid() getppid() -#define HDgetpwnam(S) getpwnam(S) -#define HDgetpwuid(U) getpwuid(U) -#define HDgets(S) gets(S) -#define HDgetuid() getuid() -#define HDgmtime(T) gmtime(T) -#define HDisalnum(C) isalnum(C) -#define HDisalpha(C) isalpha(C) -#define HDisatty(F) isatty(F) -#define HDiscntrl(C) iscntrl(C) -#define HDisdigit(C) isdigit(C) -#define HDisgraph(C) isgraph(C) -#define HDislower(C) islower(C) -#define HDisprint(C) isprint(C) -#define HDispunct(C) ispunct(C) -#define HDisspace(C) isspace(C) -#define HDisupper(C) isupper(C) -#define HDisxdigit(C) isxdigit(C) -#define HDkill(P,S) kill(P,S) -#define HDlabs(X) labs(X) -#define HDldexp(X,N) ldexp(X,N) -#define HDldiv(X,Y) ldiv(X,Y) -#define HDlink(OLD,NEW) link(OLD,NEW) -#define HDlocaleconv() localeconv() -#define HDlocaltime(T) localtime(T) -#define HDlog(X) log(X) -#define HDlog10(X) log10(X) -#define HDlongjmp(J,N) longjmp(J,N) -#define HDlseek(F,O,W) lseek(F,O,W) -#define HDmalloc(Z) malloc(Z) -#define HDmblen(S,N) mblen(S,N) -#define HDmbstowcs(P,S,Z) mbstowcs(P,S,Z) -#define HDmbtowc(P,S,Z) mbtowc(P,S,Z) -#define HDmemchr(S,C,Z) memchr(S,C,Z) -#define HDmemcmp(X,Y,Z) memcmp(X,Y,Z) -#define HDmemcpy(X,Y,Z) memcpy(X,Y,Z) -#define HDmemmove(X,Y,Z) memmove(X,Y,Z) -#define HDmemset(X,C,Z) memset(X,C,Z) -#define HDmkdir(S,M) mkdir(S,M) -#define HDmkfifo(S,M) mkfifo(S,M) -#define HDmktime(T) mktime(T) -#define HDmodf(X,Y) modf(X,Y) +#define HDfseek(F,O,W) fseek(F,O,W) +#define HDfsetpos(F,P) fsetpos(F,P) +#define HDfstat(F,B) fstat(F,B) +#define HDftell(F) ftell(F) +#define HDfwrite(M,Z,N,F) fwrite(M,Z,N,F) +#define HDgetc(F) getc(F) +#define HDgetchar() getchar() +#define HDgetcwd(S,Z) getcwd(S,Z) +#define HDgetegid() getegid() +#define HDgetenv(S) getenv(S) +#define HDgeteuid() geteuid() +#define HDgetgid() getgid() +#define HDgetgrgid(G) getgrgid(G) +#define HDgetgrnam(S) getgrnam(S) +#define HDgetgroups(Z,G) getgroups(Z,G) +#define HDgetlogin() getlogin() +#define HDgetpgrp() getpgrp() +#define HDgetpid() getpid() +#define HDgetppid() getppid() +#define HDgetpwnam(S) getpwnam(S) +#define HDgetpwuid(U) getpwuid(U) +#define HDgets(S) gets(S) +#define HDgetuid() getuid() +#define HDgmtime(T) gmtime(T) +#define HDisalnum(C) isalnum(C) +#define HDisalpha(C) isalpha(C) +#define HDisatty(F) isatty(F) +#define HDiscntrl(C) iscntrl(C) +#define HDisdigit(C) isdigit(C) +#define HDisgraph(C) isgraph(C) +#define HDislower(C) islower(C) +#define HDisprint(C) isprint(C) +#define HDispunct(C) ispunct(C) +#define HDisspace(C) isspace(C) +#define HDisupper(C) isupper(C) +#define HDisxdigit(C) isxdigit(C) +#define HDkill(P,S) kill(P,S) +#define HDlabs(X) labs(X) +#define HDldexp(X,N) ldexp(X,N) +#define HDldiv(X,Y) ldiv(X,Y) +#define HDlink(OLD,NEW) link(OLD,NEW) +#define HDlocaleconv() localeconv() +#define HDlocaltime(T) localtime(T) +#define HDlog(X) log(X) +#define HDlog10(X) log10(X) +#define HDlongjmp(J,N) longjmp(J,N) +#define HDlseek(F,O,W) lseek(F,O,W) +#define HDmalloc(Z) malloc(Z) +#define HDmblen(S,N) mblen(S,N) +#define HDmbstowcs(P,S,Z) mbstowcs(P,S,Z) +#define HDmbtowc(P,S,Z) mbtowc(P,S,Z) +#define HDmemchr(S,C,Z) memchr(S,C,Z) +#define HDmemcmp(X,Y,Z) memcmp(X,Y,Z) +#define HDmemcpy(X,Y,Z) memcpy(X,Y,Z) +#define HDmemmove(X,Y,Z) memmove(X,Y,Z) +#define HDmemset(X,C,Z) memset(X,C,Z) +#define HDmkdir(S,M) mkdir(S,M) +#define HDmkfifo(S,M) mkfifo(S,M) +#define HDmktime(T) mktime(T) +#define HDmodf(X,Y) modf(X,Y) #ifdef HAVE__O_BINARY #define HDopen(S,F,M) open(S,F|_O_BINARY,M) #else #define HDopen(S,F,M) open(S,F,M) #endif -#define HDopendir(S) opendir(S) -#define HDpathconf(S,N) pathconf(S,N) -#define HDpause() pause() -#define HDperror(S) perror(S) -#define HDpipe(F) pipe(F) -#define HDpow(X,Y) pow(X,Y) +#define HDopendir(S) opendir(S) +#define HDpathconf(S,N) pathconf(S,N) +#define HDpause() pause() +#define HDperror(S) perror(S) +#define HDpipe(F) pipe(F) +#define HDpow(X,Y) pow(X,Y) /* printf() variable arguments */ -#define HDputc(C,F) putc(C,F) -#define HDputchar(C) putchar(C) -#define HDputs(S) puts(S) -#define HDqsort(M,N,Z,F) qsort(M,N,Z,F) -#define HDraise(N) raise(N) -#define HDrand() rand() -#define HDread(F,M,Z) read(F,M,Z) -#define HDreaddir(D) readdir(D) -#define HDrealloc(M,Z) realloc(M,Z) -#define HDremove(S) remove(S) -#define HDrename(OLD,NEW) rename(OLD,NEW) -#define HDrewind(F) rewind(F) -#define HDrewinddir(D) rewinddir(D) -#define HDrmdir(S) rmdir(S) +#define HDputc(C,F) putc(C,F) +#define HDputchar(C) putchar(C) +#define HDputs(S) puts(S) +#define HDqsort(M,N,Z,F) qsort(M,N,Z,F) +#define HDraise(N) raise(N) +#define HDrand() rand() +#define HDread(F,M,Z) read(F,M,Z) +#define HDreaddir(D) readdir(D) +#define HDrealloc(M,Z) realloc(M,Z) +#define HDremove(S) remove(S) +#define HDrename(OLD,NEW) rename(OLD,NEW) +#define HDrewind(F) rewind(F) +#define HDrewinddir(D) rewinddir(D) +#define HDrmdir(S) rmdir(S) /* scanf() variable arguments */ -#define HDsetbuf(F,S) setbuf(F,S) -#define HDsetgid(G) setgid(G) -#define HDsetjmp(J) setjmp(J) -#define HDsetlocale(N,S) setlocale(N,S) -#define HDsetpgid(P,PG) setpgid(P,PG) -#define HDsetsid() setsid() -#define HDsetuid(U) setuid(U) -#define HDsetvbuf(F,S,M,Z) setvbuf(F,S,M,Z) -#define HDsigaction(N,A) sigaction(N,A) -#define HDsigaddset(S,N) sigaddset(S,N) -#define HDsigdelset(S,N) sigdelset(S,N) -#define HDsigemptyset(S) sigemptyset(S) -#define HDsigfillset(S) sigfillset(S) -#define HDsigismember(S,N) sigismember(S,N) -#define HDsiglongjmp(J,N) siglongjmp(J,N) -#define HDsignal(N,F) signal(N,F) -#define HDsigpending(S) sigpending(S) -#define HDsigprocmask(H,S,O) sigprocmask(H,S,O) -#define HDsigsetjmp(J,N) sigsetjmp(J,N) -#define HDsigsuspend(S) sigsuspend(S) -#define HDsin(X) sin(X) -#define HDsinh(X) sinh(X) -#define HDsleep(N) sleep(N) +#define HDsetbuf(F,S) setbuf(F,S) +#define HDsetgid(G) setgid(G) +#define HDsetjmp(J) setjmp(J) +#define HDsetlocale(N,S) setlocale(N,S) +#define HDsetpgid(P,PG) setpgid(P,PG) +#define HDsetsid() setsid() +#define HDsetuid(U) setuid(U) +#define HDsetvbuf(F,S,M,Z) setvbuf(F,S,M,Z) +#define HDsigaction(N,A) sigaction(N,A) +#define HDsigaddset(S,N) sigaddset(S,N) +#define HDsigdelset(S,N) sigdelset(S,N) +#define HDsigemptyset(S) sigemptyset(S) +#define HDsigfillset(S) sigfillset(S) +#define HDsigismember(S,N) sigismember(S,N) +#define HDsiglongjmp(J,N) siglongjmp(J,N) +#define HDsignal(N,F) signal(N,F) +#define HDsigpending(S) sigpending(S) +#define HDsigprocmask(H,S,O) sigprocmask(H,S,O) +#define HDsigsetjmp(J,N) sigsetjmp(J,N) +#define HDsigsuspend(S) sigsuspend(S) +#define HDsin(X) sin(X) +#define HDsinh(X) sinh(X) +#define HDsleep(N) sleep(N) #ifdef HAVE_SNPRINTF # define HDsnprintf snprintf /*varargs*/ #endif /* sprintf() variable arguments */ -#define HDsqrt(X) sqrt(X) -#define HDsrand(N) srand(N) +#define HDsqrt(X) sqrt(X) +#define HDsrand(N) srand(N) /* sscanf() variable arguments */ -#define HDstat(S,B) stat(S,B) -#define HDstrcat(X,Y) strcat(X,Y) -#define HDstrchr(S,C) strchr(S,C) -#define HDstrcmp(X,Y) strcmp(X,Y) -#define HDstrcoll(X,Y) strcoll(X,Y) -#define HDstrcpy(X,Y) strcpy(X,Y) -#define HDstrcspn(X,Y) strcspn(X,Y) -#define HDstrerror(N) strerror(N) -#define HDstrftime(S,Z,F,T) strftime(S,Z,F,T) -#define HDstrlen(S) strlen(S) -#define HDstrncat(X,Y,Z) strncat(X,Y,Z) -#define HDstrncmp(X,Y,Z) strncmp(X,Y,Z) -#define HDstrncpy(X,Y,Z) strncpy(X,Y,Z) -#define HDstrpbrk(X,Y) strpbrk(X,Y) -#define HDstrrchr(S,C) strrchr(S,C) -#define HDstrspn(X,Y) strspn(X,Y) -#define HDstrstr(X,Y) strstr(X,Y) -#define HDstrtod(S,R) strtod(S,R) -#define HDstrtok(X,Y) strtok(X,Y) -#define HDstrtol(S,R,N) strtol(S,R,N) +#define HDstat(S,B) stat(S,B) +#define HDstrcat(X,Y) strcat(X,Y) +#define HDstrchr(S,C) strchr(S,C) +#define HDstrcmp(X,Y) strcmp(X,Y) +#define HDstrcoll(X,Y) strcoll(X,Y) +#define HDstrcpy(X,Y) strcpy(X,Y) +#define HDstrcspn(X,Y) strcspn(X,Y) +#define HDstrerror(N) strerror(N) +#define HDstrftime(S,Z,F,T) strftime(S,Z,F,T) +#define HDstrlen(S) strlen(S) +#define HDstrncat(X,Y,Z) strncat(X,Y,Z) +#define HDstrncmp(X,Y,Z) strncmp(X,Y,Z) +#define HDstrncpy(X,Y,Z) strncpy(X,Y,Z) +#define HDstrpbrk(X,Y) strpbrk(X,Y) +#define HDstrrchr(S,C) strrchr(S,C) +#define HDstrspn(X,Y) strspn(X,Y) +#define HDstrstr(X,Y) strstr(X,Y) +#define HDstrtod(S,R) strtod(S,R) +#define HDstrtok(X,Y) strtok(X,Y) +#define HDstrtol(S,R,N) strtol(S,R,N) int64_t HDstrtoll (const char *s, const char **rest, int base); -#define HDstrtoul(S,R,N) strtoul(S,R,N) -#define HDstrxfrm(X,Y,Z) strxfrm(X,Y,Z) -#define HDsysconf(N) sysconf(N) -#define HDsystem(S) system(S) -#define HDtan(X) tan(X) -#define HDtanh(X) tanh(X) -#define HDtcdrain(F) tcdrain(F) -#define HDtcflow(F,A) tcflow(F,A) -#define HDtcflush(F,N) tcflush(F,N) -#define HDtcgetattr(F,T) tcgetattr(F,T) -#define HDtcgetpgrp(F) tcgetpgrp(F) -#define HDtcsendbreak(F,N) tcsendbreak(F,N) -#define HDtcsetattr(F,O,T) tcsetattr(F,O,T) -#define HDtcsetpgrp(F,N) tcsetpgrp(F,N) -#define HDtime(T) time(T) -#define HDtimes(T) times(T) -#define HDtmpfile() tmpfile() -#define HDtmpnam(S) tmpnam(S) -#define HDtolower(C) tolower(C) -#define HDtoupper(C) toupper(C) -#define HDttyname(F) ttyname(F) -#define HDtzset() tzset() -#define HDumask(N) umask(N) -#define HDuname(S) uname(S) -#define HDungetc(C,F) ungetc(C,F) -#define HDunlink(S) unlink(S) -#define HDutime(S,T) utime(S,T) -#define HDva_arg(A,T) va_arg(A,T) -#define HDva_end(A) va_end(A) -#define HDva_start(A,P) va_start(A,P) -#define HDvfprintf(F,FMT,A) vfprintf(F,FMT,A) -#define HDvprintf(FMT,A) vprintf(FMT,A) -#define HDvsprintf(S,FMT,A) vsprintf(S,FMT,A) -#define HDwait(W) wait(W) -#define HDwaitpid(P,W,O) waitpid(P,W,O) -#define HDwcstombs(S,P,Z) wcstombs(S,P,Z) -#define HDwctomb(S,C) wctomb(S,C) -#define HDwrite(F,M,Z) write(F,M,Z) +#define HDstrtoul(S,R,N) strtoul(S,R,N) +#define HDstrxfrm(X,Y,Z) strxfrm(X,Y,Z) +#define HDsysconf(N) sysconf(N) +#define HDsystem(S) system(S) +#define HDtan(X) tan(X) +#define HDtanh(X) tanh(X) +#define HDtcdrain(F) tcdrain(F) +#define HDtcflow(F,A) tcflow(F,A) +#define HDtcflush(F,N) tcflush(F,N) +#define HDtcgetattr(F,T) tcgetattr(F,T) +#define HDtcgetpgrp(F) tcgetpgrp(F) +#define HDtcsendbreak(F,N) tcsendbreak(F,N) +#define HDtcsetattr(F,O,T) tcsetattr(F,O,T) +#define HDtcsetpgrp(F,N) tcsetpgrp(F,N) +#define HDtime(T) time(T) +#define HDtimes(T) times(T) +#define HDtmpfile() tmpfile() +#define HDtmpnam(S) tmpnam(S) +#define HDtolower(C) tolower(C) +#define HDtoupper(C) toupper(C) +#define HDttyname(F) ttyname(F) +#define HDtzset() tzset() +#define HDumask(N) umask(N) +#define HDuname(S) uname(S) +#define HDungetc(C,F) ungetc(C,F) +#define HDunlink(S) unlink(S) +#define HDutime(S,T) utime(S,T) +#define HDva_arg(A,T) va_arg(A,T) +#define HDva_end(A) va_end(A) +#define HDva_start(A,P) va_start(A,P) +#define HDvfprintf(F,FMT,A) vfprintf(F,FMT,A) +#define HDvprintf(FMT,A) vprintf(FMT,A) +#define HDvsprintf(S,FMT,A) vsprintf(S,FMT,A) +#define HDwait(W) wait(W) +#define HDwaitpid(P,W,O) waitpid(P,W,O) +#define HDwcstombs(S,P,Z) wcstombs(S,P,Z) +#define HDwctomb(S,C) wctomb(S,C) +#define HDwrite(F,M,Z) write(F,M,Z) /* * And now for a couple non-Posix functions... */ char *strdup(const char *s); -#define HDstrdup(S) strdup(S) +#define HDstrdup(S) strdup(S) #ifndef HAVE_SNPRINTF int HDsnprintf(char *buf, size_t size, const char *fmt, ...); @@ -675,8 +675,8 @@ int HDsnprintf(char *buf, size_t size, const char *fmt, ...); /* * These macros check whether debugging has been requested for a certain - * package at run-time. Code for debugging is conditionally compiled by - * defining constants like `H5X_DEBUG'. In order to see the output though + * package at run-time. Code for debugging is conditionally compiled by + * defining constants like `H5X_DEBUG'. In order to see the output though * the code must be enabled at run-time with an environment variable * HDF5_DEBUG which is a list of packages to debug. * @@ -695,7 +695,7 @@ typedef enum { H5_PKG_HL, /*Local heap */ H5_PKG_I, /*Interface */ H5_PKG_MF, /*File memory management */ - H5_PKG_MM, /*Core memory management */ + H5_PKG_MM, /*Core memory management */ H5_PKG_O, /*Object headers */ H5_PKG_P, /*Property lists */ H5_PKG_S, /*Data spaces */ @@ -725,7 +725,7 @@ extern H5_debug_t H5_debug_g; * Arguments: R - Return type encoded as a string * T - Argument types encoded as a string * A0-An - Arguments. The number at the end of the macro name - * indicates the number of arguments. + * indicates the number of arguments. * * Programmer: Robb Matzke * @@ -735,32 +735,32 @@ extern H5_debug_t H5_debug_g; #ifdef H5_DEBUG_API #define H5TRACE_DECL const char *RTYPE=NULL #define H5TRACE0(R,T) RTYPE=R; \ - H5_trace(0,FUNC,T) + H5_trace(0,FUNC,T) #define H5TRACE1(R,T,A0) RTYPE=R; \ - H5_trace(0,FUNC,T,#A0,A0) + H5_trace(0,FUNC,T,#A0,A0) #define H5TRACE2(R,T,A0,A1) RTYPE=R; \ - H5_trace(0,FUNC,T,#A0,A0,#A1,A1) -#define H5TRACE3(R,T,A0,A1,A2) RTYPE=R; \ - H5_trace(0,FUNC,T,#A0,A0,#A1,A1, \ - #A2,A2) + H5_trace(0,FUNC,T,#A0,A0,#A1,A1) +#define H5TRACE3(R,T,A0,A1,A2) RTYPE=R; \ + H5_trace(0,FUNC,T,#A0,A0,#A1,A1, \ + #A2,A2) #define H5TRACE4(R,T,A0,A1,A2,A3) RTYPE=R; \ - H5_trace(0,FUNC,T,#A0,A0,#A1,A1, \ - #A2,A2,#A3,A3) + H5_trace(0,FUNC,T,#A0,A0,#A1,A1, \ + #A2,A2,#A3,A3) #define H5TRACE5(R,T,A0,A1,A2,A3,A4) RTYPE=R; \ - H5_trace(0,FUNC,T,#A0,A0,#A1,A1, \ - #A2,A2,#A3,A3,#A4,A4) + H5_trace(0,FUNC,T,#A0,A0,#A1,A1, \ + #A2,A2,#A3,A3,#A4,A4) #define H5TRACE6(R,T,A0,A1,A2,A3,A4,A5) RTYPE=R; \ - H5_trace(0,FUNC,T,#A0,A0,#A1,A1, \ - #A2,A2,#A3,A3,#A4,A4, \ - #A5,A5) + H5_trace(0,FUNC,T,#A0,A0,#A1,A1, \ + #A2,A2,#A3,A3,#A4,A4, \ + #A5,A5) #define H5TRACE7(R,T,A0,A1,A2,A3,A4,A5,A6) RTYPE=R; \ - H5_trace(0,FUNC,T,#A0,A0,#A1,A1, \ - #A2,A2,#A3,A3,#A4,A4, \ - #A5,A5,#A6,A6) + H5_trace(0,FUNC,T,#A0,A0,#A1,A1, \ + #A2,A2,#A3,A3,#A4,A4, \ + #A5,A5,#A6,A6) #define H5TRACE_RETURN(V) if (RTYPE) { \ - H5_trace(1,NULL,RTYPE,NULL,V); \ - RTYPE=NULL; \ - } + H5_trace(1,NULL,RTYPE,NULL,V); \ + RTYPE=NULL; \ + } #else #define H5TRACE_DECL /*void*/ #define H5TRACE0(R,T) /*void*/ @@ -778,54 +778,54 @@ void H5_trace (hbool_t returning, const char *func, const char *type, ...); /*------------------------------------------------------------------------- - * Purpose: Register function entry for library initialization and code - * profiling. + * Purpose: Register function entry for library initialization and code + * profiling. * - * Notes: Every file must have a file-scope variable called - * `initialize_interface_g' of type hbool_t which is initialized - * to FALSE. + * Notes: Every file must have a file-scope variable called + * `initialize_interface_g' of type hbool_t which is initialized + * to FALSE. * - * Don't use local variable initializers which contain - * calls to other library functions since the initializer - * would happen before the FUNC_ENTER() gets called. Don't - * use initializers that require special cleanup code to - * execute if FUNC_ENTER() fails since a failing FUNC_ENTER() - * returns immediately without branching to the `done' label. + * Don't use local variable initializers which contain + * calls to other library functions since the initializer + * would happen before the FUNC_ENTER() gets called. Don't + * use initializers that require special cleanup code to + * execute if FUNC_ENTER() fails since a failing FUNC_ENTER() + * returns immediately without branching to the `done' label. * - * Programmer: Quincey Koziol + * Programmer: Quincey Koziol * * Modifications: * - * Robb Matzke, 4 Aug 1997 - * The `interface_init_func' can be the null pointer. Changed - * HGOTO_ERROR() to HRETURN_ERROR() since no clean-up needs to occur - * when an error is detected at this point since this must be the - * first executable statement in a function. This allows functions - * to omit the `done:' label when convenient to do so. + * Robb Matzke, 4 Aug 1997 + * The `interface_init_func' can be the null pointer. Changed + * HGOTO_ERROR() to HRETURN_ERROR() since no clean-up needs to occur + * when an error is detected at this point since this must be the + * first executable statement in a function. This allows functions + * to omit the `done:' label when convenient to do so. * - * Robb Matzke, 4 Aug 1997 - * The pablo mask comes from the constant PABLO_MASK defined on - * a per-file basis. The `pablo_func_id' is generated from the - * `func_name' argument by prepending an `ID_' to the name. The - * pablo function identifier should be saved in a local variable - * so FUNC_LEAVE() can access it. + * Robb Matzke, 4 Aug 1997 + * The pablo mask comes from the constant PABLO_MASK defined on + * a per-file basis. The `pablo_func_id' is generated from the + * `func_name' argument by prepending an `ID_' to the name. The + * pablo function identifier should be saved in a local variable + * so FUNC_LEAVE() can access it. * - * Robb Matzke, 4 Aug 1997 - * It is safe to call this function even inside various library - * initializing functions. Infinite recursion is no longer a - * danger. + * Robb Matzke, 4 Aug 1997 + * It is safe to call this function even inside various library + * initializing functions. Infinite recursion is no longer a + * danger. * - * Robb Matzke, 3 Dec 1997 - * The interface initialization function is no longer passed as an - * argument unless the `FUNC_ENTER_INIT' form is called. Instead, the - * function comes from the `INTERFACE_INIT' constant which must be - * defined in every source file. + * Robb Matzke, 3 Dec 1997 + * The interface initialization function is no longer passed as an + * argument unless the `FUNC_ENTER_INIT' form is called. Instead, the + * function comes from the `INTERFACE_INIT' constant which must be + * defined in every source file. * - * Robb Matzke, 17 Jun 1998 + * Robb Matzke, 17 Jun 1998 * Added auto variable RTYPE which is initialized by the tracing macros. *------------------------------------------------------------------------- */ -extern hbool_t library_initialize_g; /*good thing C's lazy about extern! */ +extern hbool_t H5_libinit_g; /*good thing C's lazy about extern! */ /* Is `S' the name of an API function? */ #define H5_IS_API(S) ('_'!=S[2] && '_'!=S[3] && (!S[4] || '_'!=S[4])) @@ -840,21 +840,21 @@ extern hbool_t library_initialize_g; /*good thing C's lazy about extern! */ PABLO_TRACE_ON (PABLO_MASK, pablo_func_id); \ \ /* Initialize the library */ \ - if (!library_initialize_g) { \ - library_initialize_g = TRUE; \ + if (!H5_libinit_g) { \ + H5_libinit_g = TRUE; \ if (H5_init_library()<0) { \ - HRETURN_ERROR (H5E_FUNC, H5E_CANTINIT, err, \ - "library initialization failed"); \ + HRETURN_ERROR (H5E_FUNC, H5E_CANTINIT, err, \ + "library initialization failed"); \ } \ - } \ + } \ \ /* Initialize this interface or bust */ \ if (!interface_initialize_g) { \ interface_initialize_g = 1; \ if (interface_init_func && \ - ((herr_t(*)(void))interface_init_func)()<0) { \ - HRETURN_ERROR (H5E_FUNC, H5E_CANTINIT, err, \ - "interface initialization failed"); \ + ((herr_t(*)(void))interface_init_func)()<0) { \ + HRETURN_ERROR (H5E_FUNC, H5E_CANTINIT, err, \ + "interface initialization failed"); \ } \ } else if (interface_initialize_g<0) { \ HRETURN_ERROR(H5E_FUNC, H5E_CANTINIT, err, \ @@ -869,17 +869,17 @@ extern hbool_t library_initialize_g; /*good thing C's lazy about extern! */ { /*------------------------------------------------------------------------- - * Purpose: Register function exit for code profiling. This should be - * the last statement executed by a function. + * Purpose: Register function exit for code profiling. This should be + * the last statement executed by a function. * - * Programmer: Quincey Koziol + * Programmer: Quincey Koziol * * Modifications: * - * Robb Matzke, 4 Aug 1997 - * The pablo mask comes from the constant PABLO_MASK defined on a - * per-file basis. The pablo_func_id comes from an auto variable - * defined by FUNC_ENTER. + * Robb Matzke, 4 Aug 1997 + * The pablo mask comes from the constant PABLO_MASK defined on a + * per-file basis. The pablo_func_id comes from an auto variable + * defined by FUNC_ENTER. * *------------------------------------------------------------------------- */ @@ -891,12 +891,12 @@ extern hbool_t library_initialize_g; /*good thing C's lazy about extern! */ * through one of these two sets of macros. */ #ifdef HAVE_PABLO -# define PABLO_SAVE(func_id) intn pablo_func_id = func_id -# define PABLO_TRACE_ON(m, f) TRACE_ON(m,f) +# define PABLO_SAVE(func_id) intn pablo_func_id = func_id +# define PABLO_TRACE_ON(m, f) TRACE_ON(m,f) # define PABLO_TRACE_OFF(m, f) TRACE_OFF(m,f) #else -# define PABLO_SAVE(func_id) /*void */ -# define PABLO_TRACE_ON(m, f) /*void */ +# define PABLO_SAVE(func_id) /*void */ +# define PABLO_TRACE_ON(m, f) /*void */ # define PABLO_TRACE_OFF(m, f) /*void */ #endif diff --git a/src/H5public.h b/src/H5public.h index d3f6ba3..9404cae 100644 --- a/src/H5public.h +++ b/src/H5public.h @@ -18,6 +18,10 @@ #include <H5config.h> /*from configure */ #include <sys/types.h> +#ifdef STDC_HEADERS +# include <limits.h> /*for H5T_NATIVE_CHAR defn in H5Tpublic.h */ +#endif + #include <stddef.h> #ifdef HAVE_PARALLEL # include <mpi.h> |