diff --git a/src/H5.c b/src/H5.c index c810f99e3f..e40948965c 100644 --- a/src/H5.c +++ b/src/H5.c @@ -121,17 +121,17 @@ herr_t H5_add_exit(void (*func) (void)) { herr_t ret_value = SUCCEED; - H5_exit_t *new; + H5_exit_t *new_exit; FUNC_ENTER_INIT(H5_add_exit, NULL, FAIL); assert(func); - new = H5MM_xcalloc(1, sizeof(H5_exit_t)); + new_exit = H5MM_xcalloc(1, sizeof(H5_exit_t)); - new->func = func; - new->next = lib_exit_head; - lib_exit_head = new; + new_exit->func = func; + new_exit->next = lib_exit_head; + lib_exit_head = new_exit; FUNC_LEAVE(ret_value); } /* end H5_add_exit() */ diff --git a/src/H5B.c b/src/H5B.c index b2eeecdfaf..f7377985ae 100644 --- a/src/H5B.c +++ b/src/H5B.c @@ -1033,7 +1033,7 @@ H5B_insert_helper(H5F_t *f, const haddr_t *addr, const H5B_class_t *type, assert(type); assert(type->decode); assert(type->cmp3); - assert(type->new); + assert(type->new_node); assert(lt_key); assert(lt_key_changed); assert(rt_key); @@ -1076,8 +1076,8 @@ H5B_insert_helper(H5F_t *f, const haddr_t *addr, const H5B_class_t *type, assert(0 == bt->level); bt->key[0].nkey = bt->native; bt->key[1].nkey = bt->native + type->sizeof_nkey; - if ((type->new) (f, H5B_INS_FIRST, bt->key[0].nkey, udata, - bt->key[1].nkey, bt->child + 0 /*out */ ) < 0) { + if ((type->new_node) (f, H5B_INS_FIRST, bt->key[0].nkey, udata, + bt->key[1].nkey, bt->child + 0/*out*/) < 0) { bt->key[0].nkey = bt->key[1].nkey = NULL; HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, H5B_INS_ERROR, "unable to create leaf node"); @@ -1152,8 +1152,8 @@ H5B_insert_helper(H5F_t *f, const haddr_t *addr, const H5B_class_t *type, } my_ins = H5B_INS_LEFT; HDmemcpy(md_key, bt->key[idx].nkey, type->sizeof_nkey); - if ((type->new) (f, H5B_INS_LEFT, bt->key[idx].nkey, udata, md_key, - &child_addr /*out */ ) < 0) { + if ((type->new_node) (f, H5B_INS_LEFT, bt->key[idx].nkey, udata, + md_key, &child_addr/*out*/) < 0) { HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert minimum leaf node"); } @@ -1209,8 +1209,8 @@ H5B_insert_helper(H5F_t *f, const haddr_t *addr, const H5B_class_t *type, } my_ins = H5B_INS_RIGHT; HDmemcpy(md_key, bt->key[idx + 1].nkey, type->sizeof_nkey); - if ((type->new) (f, H5B_INS_RIGHT, md_key, udata, - bt->key[idx + 1].nkey, &child_addr /*out */ ) < 0) { + if ((type->new_node) (f, H5B_INS_RIGHT, md_key, udata, + bt->key[idx + 1].nkey, &child_addr/*out*/) < 0) { HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert maximum leaf node"); } diff --git a/src/H5Bprivate.h b/src/H5Bprivate.h index c8b57b086d..8a9420ab39 100644 --- a/src/H5Bprivate.h +++ b/src/H5Bprivate.h @@ -68,7 +68,7 @@ typedef struct H5B_class_t { H5B_subid_t id; /*id as found in file*/ size_t sizeof_nkey; /*size of native (memory) key*/ size_t (*get_sizeof_rkey) (H5F_t *, const void *); /*raw key size */ - herr_t (*new) (H5F_t *, H5B_ins_t, void *, void *, void *, haddr_t *); + herr_t (*new_node) (H5F_t*, H5B_ins_t, void*, void*, void*, haddr_t*); intn (*cmp2) (H5F_t *, void *, void *, void *); /*compare 2 keys */ intn (*cmp3) (H5F_t *, void *, void *, void *); /*compare 3 keys */ herr_t (*found) (H5F_t *, const haddr_t *, const void *, void *, diff --git a/src/H5T.c b/src/H5T.c index f64536ce8f..4ecc200184 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -174,6 +174,7 @@ H5T_init_interface(void) HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't initialize H5T layer"); } + /* STRING */ dt = H5MM_xcalloc(1, sizeof(H5T_t)); dt->locked = TRUE; @@ -190,6 +191,7 @@ H5T_init_interface(void) HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't initialize H5T layer"); } + /* BITFIELD */ dt = H5MM_xcalloc(1, sizeof(H5T_t)); dt->locked = TRUE; @@ -204,6 +206,7 @@ H5T_init_interface(void) HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize H5T layer"); } + /* OPAQUE */ dt = H5MM_xcalloc(1, sizeof(H5T_t)); dt->locked = TRUE; @@ -218,6 +221,7 @@ H5T_init_interface(void) HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize H5T layer"); } + /* * Define aliases. */ @@ -231,7 +235,6 @@ H5T_init_interface(void) * Register conversion functions beginning with the most general and * ending with the most specific. */ - if (H5Tregister_soft(H5T_INTEGER, H5T_INTEGER, H5T_conv_order) < 0) { HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to register conversion function"); @@ -240,6 +243,12 @@ H5T_init_interface(void) HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to register conversion function"); } + if (H5Tregister_soft (H5T_COMPOUND, H5T_COMPOUND, H5T_conv_struct)<0) { + HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, + "unable to register conversion function"); + } + + FUNC_LEAVE(ret_value); } @@ -2629,12 +2638,12 @@ H5T_sort_by_offset(H5T_t *dt) /* 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; + for (i=nmembs-1, swapped=TRUE; i>0 && swapped; --i) { + for (j=0, swapped=FALSE; ju.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 = 1; } } diff --git a/src/H5Tconv.c b/src/H5Tconv.c index d5ad0bb83c..ff612ba0f2 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -11,12 +11,13 @@ #include #include +#include #include /* Interface initialization */ -static intn interface_initialize_g = FALSE; +static intn interface_initialize_g = FALSE; #define INTERFACE_INIT NULL - + /*------------------------------------------------------------------------- * Function: H5T_conv_noop * @@ -41,7 +42,7 @@ H5T_conv_noop(hid_t src_id, hid_t dst_id, size_t nelmts, FUNC_ENTER(H5T_conv_noop, FAIL); FUNC_LEAVE(SUCCEED); } - + /*------------------------------------------------------------------------- * Function: H5T_conv_order * @@ -84,6 +85,7 @@ H5T_conv_order(hid_t src_id, hid_t dst_id, size_t nelmts, HRETURN_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "background values not supported in this conv path"); } + if (!buf) { /* Capability query */ if (src->size != dst->size || @@ -138,7 +140,19 @@ H5T_conv_order(hid_t src_id, hid_t dst_id, size_t nelmts, * Function: H5T_conv_struct * * Purpose: Converts between compound data types. This is a soft - * conversion function. + * conversion function. The algorithm is basically: + * + * For I=1..NUM_MEMBERS do + * If sizeof detination type <= sizeof source type then + * Convert member to destination type; + * Move member as far left as possible; + * + * For I=NUM_MEMBERS..1 do + * If not destination type then + * Convert member to destination type; + * Move member to correct position in BACKGROUND + * + * Copy BACKGROUND to BUF * * Return: Success: SUCCEED * @@ -155,10 +169,79 @@ herr_t H5T_conv_struct(hid_t src_id, hid_t dst_id, size_t nelmts, void *_buf, const void *background) { + uint8 *buf = (uint8 *)_buf; /*cast for pointer arithmetic */ + H5T_t *src = NULL; /*source data type */ + H5T_t *dst = NULL; /*destination data type */ + intn *dst2src_map = NULL; /*maps dst member to src member */ + intn i; + FUNC_ENTER (H5T_conv_struct, FAIL); - HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "not implemented yet"); + /* Check args */ + if (H5_DATATYPE != H5A_group(src_id) || + NULL == (src = H5A_object(src_id)) || + H5_DATATYPE != H5A_group(dst_id) || + NULL == (dst = H5A_object(dst_id))) { + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type"); + } + if (background) { + HRETURN_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, + "background values not supported in this conv path"); + } + /* Capability query? */ + if (!buf) { + assert (H5T_COMPOUND==src->type); + assert (H5T_COMPOUND==dst->type); + HRETURN (SUCCEED); + } + + /* + * Build a mapping from destination member number to source member number + */ + H5T_sort_by_offset (src); + H5T_sort_by_offset (dst); + dst2src_map = H5MM_xmalloc (dst->u.compnd.nmembs * sizeof(intn)); + for (i=0; iu.compnd.nmembs; i++) { + } + + + + /* + * For each source member which will be present in the destination, + * convert the member to the destination type unless it is larger than + * the source type. Then move the member to the left-most unoccupied + * position in the buffer. This makes the data point as small as + * possible with all the free space on the right side. + */ + for (i=0; iu.compnd.nmembs; i++) { + } + + + /* + * For each source member which will be present in the destination, + * convert the member to the destination type if it is larger than the + * source type (that is, has not been converted yet). Then copy the + * member to the destination offset in the background buffer. + */ + for (i=src->u.compnd.nmembs-1; i>=0; --i) { + } + + + /* + * Copy the background buffer back into the in-place conversion buffer. + */ + HDmemcpy (buf, background, dst->size); + + + + + + + + + + HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "not implemented yet"); FUNC_LEAVE (SUCCEED); }