summaryrefslogtreecommitdiffstats
path: root/src/H5T.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2005-09-12 06:02:55 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2005-09-12 06:02:55 (GMT)
commit5ffde305cdf2c167234f1ffb38adf557380f2234 (patch)
treef211c5a72d7332885ab83eca1270bcb131e1c6c9 /src/H5T.c
parent966f5f42368663fb589807ae28b2887b98ed8067 (diff)
downloadhdf5-5ffde305cdf2c167234f1ffb38adf557380f2234.zip
hdf5-5ffde305cdf2c167234f1ffb38adf557380f2234.tar.gz
hdf5-5ffde305cdf2c167234f1ffb38adf557380f2234.tar.bz2
[svn-r11384] Purpose:
Code cleanup Description: Merge back changes from "compact group" work that improve the infrastructure of the library and may impact others. In this round of merging, that includes: - Move datatype allocation into single internal routine, instead of duplicated code that was spread out in a dozen or so places. - Clean up guts of object header routines (H5O_*) to allow for some of the fancieroperations that need to be performed on groups, along with some general improvements. - Added a new error code - Some minor cleanups in other code.... Platforms tested: FreeBSD 4.11 (sleipnir) Linux 2.4 Mac OS X
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