summaryrefslogtreecommitdiffstats
path: root/src/H5T.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5T.c')
-rw-r--r--src/H5T.c63
1 files changed, 48 insertions, 15 deletions
diff --git a/src/H5T.c b/src/H5T.c
index a372a27..ea77f8a 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -440,13 +440,8 @@ static H5T_t *H5T_decode(const unsigned char *buf);
#define H5T_INIT_TYPE_ALLOC_CREATE(BASE) { \
/* Allocate new datatype info */ \
- if (NULL==(dt = H5FL_CALLOC(H5T_t))) \
+ if (NULL==(dt = H5T_alloc())) \
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") \
- dt->ent.header = HADDR_UNDEF; \
- if (NULL==(dt->shared = H5FL_CALLOC(H5T_shared_t))) { \
- H5FL_FREE(H5T_t, dt); \
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") \
- } \
}
@@ -2976,10 +2971,7 @@ H5T_create(H5T_class_t type, size_t size)
case H5T_OPAQUE:
case H5T_COMPOUND:
- if (NULL==(dt = H5FL_CALLOC(H5T_t)))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
- dt->ent.header = HADDR_UNDEF;
- if (NULL==(dt->shared = H5FL_CALLOC(H5T_shared_t)))
+ if(NULL == (dt = H5T_alloc()))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
dt->shared->type = type;
@@ -3005,11 +2997,8 @@ H5T_create(H5T_class_t type, size_t size)
} else {
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "no applicable native integer type");
}
- if (NULL==(dt = H5FL_CALLOC(H5T_t)))
+ if(NULL == (dt = H5T_alloc()))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
- dt->ent.header = HADDR_UNDEF;
- if (NULL==(dt->shared = H5FL_CALLOC(H5T_shared_t)))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
dt->shared->type = type;
if (NULL==(dt->shared->parent=H5T_copy(H5I_object(subtype), H5T_COPY_ALL)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy base data type");
@@ -3025,7 +3014,6 @@ H5T_create(H5T_class_t type, size_t size)
HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, NULL, "unknown data type class");
}
- dt->ent.header = HADDR_UNDEF;
dt->shared->size = size;
/* Set return value */
@@ -3505,6 +3493,51 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5T_alloc
+ *
+ * Purpose: Allocates a new H5T_t structure, initializing it correctly.
+ *
+ * Return: Pointer to new H5T_t on success/NULL on failure
+ *
+ * Programmer: Quincey Koziol
+ * Monday, August 29, 2005
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+H5T_t *
+H5T_alloc(void)
+{
+ H5T_t *dt; /* Pointer to datatype allocated */
+ H5T_t *ret_value; /* Return value */
+
+ FUNC_ENTER_NOAPI(H5T_alloc, NULL)
+
+ /* Allocate & initialize new datatype info */
+ if(NULL == (dt = H5FL_CALLOC(H5T_t)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
+ H5G_ent_reset(&(dt->ent));
+ if(NULL == (dt->shared = H5FL_CALLOC(H5T_shared_t)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
+
+ /* Assign return value */
+ ret_value = dt;
+
+done:
+ if(ret_value == NULL) {
+ if(dt != NULL) {
+ if(dt->shared != NULL)
+ H5FL_FREE(H5T_shared_t, dt->shared);
+ H5FL_FREE(H5T_t, dt);
+ } /* end if */
+ } /* end if */
+
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5T_alloc() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5T_free
*
* Purpose: Frees all memory associated with a datatype, but does not