summaryrefslogtreecommitdiffstats
path: root/src/H5.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5.c')
-rw-r--r--src/H5.c722
1 files changed, 714 insertions, 8 deletions
diff --git a/src/H5.c b/src/H5.c
index aad036c..3372250 100644
--- a/src/H5.c
+++ b/src/H5.c
@@ -38,24 +38,27 @@ static char RcsId[] = "@(#)$Revision$";
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
+#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
/* private headers */
-#include <H5private.h> /*library */
-#include <H5ACprivate.h> /*cache */
-#include <H5Bprivate.h> /*B-link trees */
-#include <H5Eprivate.h> /*error handling */
-#include <H5MMprivate.h> /*memory management */
-#include <H5Tprivate.h> /*data types */
+#include <H5private.h> /*library */
+#include <H5ACprivate.h> /*cache */
+#include <H5Bprivate.h> /*B-link trees */
+#include <H5Eprivate.h> /*error handling */
+#include <H5Iprivate.h> /*atoms */
+#include <H5MMprivate.h> /*memory management */
+#include <H5Pprivate.h> /*property lists */
+#include <H5Tprivate.h> /*data types */
+#include <H5Zprivate.h> /*compression */
#define PABLO_MASK H5_mask
-/*--------------------- Locally scoped variables -----------------------------*/
-
hbool_t library_initialize_g = FALSE;
hbool_t thread_initialize_g = FALSE;
hbool_t install_atexit_g = TRUE;
+static FILE *H5_trace_g = NULL;
typedef struct H5_exit {
void (*func) (void); /* Interface function to call during exit */
@@ -86,6 +89,17 @@ H5_init_library(void)
{
FUNC_ENTER_INIT(H5_init_library, NULL, FAIL);
+#ifdef H5_DEBUG_API
+ {
+ /* Turn on tracing? */
+ const char *s = getenv ("HDF5_TRACE");
+ if (s && isdigit(*s)) {
+ int fd = HDstrtol (s, NULL, 0);
+ H5_trace_g = fdopen (fd, "w");
+ }
+ }
+#endif
+
/* Install atexit() library cleanup routine */
if (install_atexit_g == TRUE)
if (HDatexit(&H5_term_library) != 0)
@@ -908,3 +922,695 @@ H5_timer_end (H5_timer_t *sum/*in,out*/, H5_timer_t *timer/*in,out*/)
}
}
+
+/*-------------------------------------------------------------------------
+ * Function: H5_trace
+ *
+ * Purpose: This function is called whenever an API function is called
+ * and tracing is turned on. If RETURNING is non-zero then
+ * the caller is about to return. Otherwise we print the
+ * function name and the arguments.
+ *
+ * The TYPE argument is a string which gives the type of each of
+ * the following argument pairs. Each type is zero or more
+ * asterisks (one for each level of indirection, although some
+ * types have one level of indirection already implied) followed
+ * by either one letter (lower case) or two letters (first one
+ * uppercase).
+ *
+ * The variable argument list consists of pairs of values. Each
+ * pair is a string which is the formal argument name in the
+ * calling function, followed by the argument value. The type
+ * of the argument value is given by the TYPE string.
+ *
+ * Note: The TYPE string is meant to be terse and is generated by a
+ * separate perl script.
+ *
+ * Return: void
+ *
+ * Programmer: Robb Matzke
+ * Tuesday, June 16, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+void
+H5_trace (hbool_t returning, const char *func, const char *type, ...)
+{
+ va_list ap;
+ char buf[64];
+ const char *argname;
+ intn argno=0, ptr, n;
+ void *vp = NULL;
+ FILE *out = H5_trace_g;
+
+ if (!out) return; /*tracing is off*/
+ va_start (ap, type);
+
+ if (returning) {
+ fprintf (out, " = ");
+ } else {
+ fprintf (out, "%s(", func);
+ }
+
+ while (*type) {
+ /* Count levels of indirection */
+ for (ptr=0; '*'==*type; type++) ptr++;
+
+ /*
+ * The argument name. Leave off the `_id' part. If the argument
+ * name is the null pointer then don't print the argument or the
+ * following `='. This is used for return values.
+ */
+ argname = va_arg (ap, char*);
+ if (argname) {
+ n = MAX (0, (int)strlen(argname)-3);
+ if (!strcmp (argname+n, "_id")) {
+ strncpy (buf, argname, MIN ((int)sizeof(buf)-1, n));
+ buf[MIN((int)sizeof(buf)-1, n)] = '\0';
+ argname = buf;
+ }
+ fprintf (out, "%s%s=", argno++?", ":"", argname);
+ } else {
+ argname = "";
+ }
+
+ /* The value */
+ if (ptr) vp = va_arg (ap, void*);
+ switch (type[0]) {
+ case 'b':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ hbool_t bool = va_arg (ap, hbool_t);
+ if (TRUE==bool) fprintf (out, "TRUE");
+ else if (!bool) fprintf (out, "FALSE");
+ else fprintf (out, "TRUE(%u)", (unsigned)bool);
+ }
+ break;
+
+ case 'd':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ double dbl = va_arg (ap, double);
+ fprintf (out, "%g", dbl);
+ }
+ break;
+
+ case 'D':
+ switch (type[1]) {
+ case 'l':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ H5D_layout_t layout = va_arg (ap, H5D_layout_t);
+ switch (layout) {
+ case H5D_LAYOUT_ERROR:
+ fprintf (out, "H5D_LAYOUT_ERROR");
+ break;
+ case H5D_COMPACT:
+ fprintf (out, "H5D_COMPACT");
+ break;
+ case H5D_CONTIGUOUS:
+ fprintf (out, "H5D_CONTIGUOUS");
+ break;
+ case H5D_CHUNKED:
+ fprintf (out, "H5D_CHUNKED");
+ break;
+ default:
+ fprintf (out, "%ld", (long)layout);
+ break;
+ }
+ }
+ break;
+
+ case 't':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ H5D_transfer_t transfer = va_arg (ap, H5D_transfer_t);
+ switch (transfer) {
+ case H5D_XFER_INDEPENDENT:
+ fprintf (out, "H5D_XFER_INDEPENDENT");
+ break;
+ case H5D_XFER_COLLECTIVE:
+ fprintf (out, "H5D_XFER_COLLECTIVE");
+ break;
+ case H5D_XFER_DFLT:
+ fprintf (out, "H5D_XFER_DFLT");
+ break;
+ default:
+ fprintf (out, "%ld", (long)transfer);
+ break;
+ }
+ }
+ break;
+
+ default:
+ fprintf (out, "BADTYPE(D%c)", type[1]);
+ goto error;
+ }
+ break;
+
+ case 'e':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ herr_t status = va_arg (ap, herr_t);
+ if (SUCCEED==status) fprintf (out, "SUCCEED");
+ else if (FAIL==status) fprintf (out, "FAIL");
+ else fprintf (out, "%d", (int)status);
+ }
+ break;
+
+ case 'E':
+ switch (type[1]) {
+ case 'd':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ H5E_direction_t direction = va_arg (ap, H5E_direction_t);
+ switch (direction) {
+ case H5E_WALK_UPWARD:
+ fprintf (out, "H5E_WALK_UPWARD");
+ break;
+ case H5E_WALK_DOWNWARD:
+ fprintf (out, "H5E_WALK_DOWNWARD");
+ break;
+ default:
+ fprintf (out, "%ld", (long)direction);
+ break;
+ }
+ }
+ break;
+
+ case 'e':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ H5E_error_t *error = va_arg (ap, H5E_error_t*);
+ fprintf (out, "0x%lx", (unsigned long)error);
+ }
+ break;
+
+ default:
+ fprintf (out, "BADTYPE(E%c)", type[1]);
+ goto error;
+ }
+ break;
+
+ case 'G':
+ switch (type[1]) {
+ case 'l':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ H5G_link_t link_type = va_arg (ap, H5G_link_t);
+ switch (link_type) {
+ case H5G_LINK_ERROR:
+ fprintf (out, "H5G_LINK_ERROR");
+ break;
+ case H5G_LINK_HARD:
+ fprintf (out, "H5G_LINK_HARD");
+ break;
+ case H5G_LINK_SOFT:
+ fprintf (out, "H5G_LINK_SOFT");
+ break;
+ default:
+ fprintf (out, "%ld", (long)link_type);
+ break;
+ }
+ }
+ break;
+
+ case 's':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ H5G_stat_t *statbuf = va_arg (ap, H5G_stat_t*);
+ fprintf (out, "0x%lx", (unsigned long)statbuf);
+ }
+ break;
+
+ default:
+ fprintf (out, "BADTYPE(G%c)", type[1]);
+ goto error;
+ }
+ break;
+
+ case 'h':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ hsize_t hsize = va_arg (ap, hsize_t);
+ HDfprintf (out, "%Hu", hsize);
+ }
+ break;
+
+ case 'H':
+ switch (type[1]) {
+ case 's':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ hssize_t hssize = va_arg (ap, hssize_t);
+ HDfprintf (out, "%Hd", hssize);
+ }
+ break;
+
+ default:
+ fprintf (out, "BADTYPE(H%c)", type[1]);
+ goto error;
+ }
+ break;
+
+ case 'i':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ hid_t obj = va_arg (ap, hid_t);
+ if (-2 == obj) {
+ fprintf (out, "H5P_DEFAULT");
+ } else if (FAIL==obj) {
+ fprintf (out, "FAIL");
+ } else {
+ fprintf (out, "%ld", (long)obj);
+ switch (H5I_group (obj)) {
+ case BADGROUP:
+ fprintf (out, " (error)");
+ break;
+ case H5_FILE:
+ if (strcmp (argname, "file")) {
+ fprintf (out, " (file)");
+ }
+ break;
+ case H5_TEMPLATE_0:
+ case H5_TEMPLATE_1:
+ case H5_TEMPLATE_2:
+ case H5_TEMPLATE_3:
+ case H5_TEMPLATE_4:
+ case H5_TEMPLATE_5:
+ case H5_TEMPLATE_6:
+ case H5_TEMPLATE_7:
+ if (strcmp (argname, "plist")) {
+ fprintf (out, " (plist)");
+ }
+ break;
+ case H5_GROUP:
+ if (strcmp (argname, "group")) {
+ fprintf (out, " (group)");
+ }
+ break;
+ case H5_DATATYPE:
+ if (strcmp (argname, "type")) {
+ fprintf (out, " (type)");
+ }
+ break;
+ case H5_DATASPACE:
+ if (strcmp (argname, "space")) {
+ fprintf (out, " (space)");
+ }
+ break;
+ case H5_DATASET:
+ if (strcmp (argname, "dset")) {
+ fprintf (out, " (dset)");
+ }
+ break;
+ case H5_ATTR:
+ if (strcmp (argname, "attr")) {
+ fprintf (out, " (attr)");
+ }
+ break;
+ default:
+ fprintf (out, " (unknown class)");
+ break;
+ }
+ }
+ }
+ break;
+
+ case 'I':
+ switch (type[1]) {
+ case 's':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ int is = va_arg (ap, int);
+ fprintf (out, "%d", is);
+ }
+ break;
+
+ case 'u':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ unsigned iu = va_arg (ap, unsigned);
+ fprintf (out, "%u", iu);
+ }
+ break;
+
+ default:
+ fprintf (out, "BADTYPE(I%c)", type[1]);
+ goto error;
+ }
+ break;
+
+ case 'M':
+ switch (type[1]) {
+#ifdef HAVE_PARALLEL
+ case 'c':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ MPI_Comm comm = va_arg (ap, MPI_Comm);
+ fprintf (out, "%ld", (long)comm);
+ }
+ break;
+ case 'i':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ MPI_Info info = va_arg (ap, MPI_Info);
+ fprintf (out, "%ld", (long)info);
+ }
+ break;
+#endif
+ default:
+ goto error;
+ }
+ break;
+
+ case 'o':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ off_t offset = va_arg (ap, off_t);
+ fprintf (out, "%ld", (long)offset);
+ }
+ break;
+
+ case 'p':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ H5P_class_t plist_class = va_arg (ap, H5P_class_t);
+ switch (plist_class) {
+ case H5P_NO_CLASS:
+ fprintf (out, "H5P_NO_CLASS");
+ break;
+ case H5P_FILE_CREATE:
+ fprintf (out, "H5P_FILE_CREATE");
+ break;
+ case H5P_FILE_ACCESS:
+ fprintf (out, "H5P_FILE_ACCESS");
+ break;
+ case H5P_DATASET_CREATE:
+ fprintf (out, "H5P_DATASET_CREATE");
+ break;
+ case H5P_DATASET_XFER:
+ fprintf (out, "H5P_DATASET_XFER");
+ break;
+ default:
+ fprintf (out, "%ld", (long)plist_class);
+ break;
+ }
+ }
+ break;
+
+ case 's':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ const char *str = va_arg (ap, const char*);
+ fprintf (out, "\"%s\"", str);
+ }
+ break;
+
+ case 'T':
+ switch (type[1]) {
+ case 'c':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ H5T_cset_t cset = va_arg (ap, H5T_cset_t);
+ switch (cset) {
+ case H5T_CSET_ERROR:
+ fprintf (out, "H5T_CSET_ERROR");
+ break;
+ case H5T_CSET_ASCII:
+ fprintf (out, "H5T_CSET_ASCII");
+ break;
+ default:
+ fprintf (out, "%ld", (long)cset);
+ break;
+ }
+ }
+ break;
+
+ case 'n':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ H5T_norm_t norm = va_arg (ap, H5T_norm_t);
+ switch (norm) {
+ case H5T_NORM_ERROR:
+ fprintf (out, "H5T_NORM_ERROR");
+ break;
+ case H5T_NORM_IMPLIED:
+ fprintf (out, "H5T_NORM_IMPLIED");
+ break;
+ case H5T_NORM_MSBSET:
+ fprintf (out, "H5T_NORM_MSBSET");
+ break;
+ case H5T_NORM_NONE:
+ fprintf (out, "H5T_NORM_NONE");
+ break;
+ default:
+ fprintf (out, "%ld", (long)norm);
+ break;
+ }
+ }
+ break;
+
+ case 'o':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ H5T_order_t order = va_arg (ap, H5T_order_t);
+ switch (order) {
+ case H5T_ORDER_ERROR:
+ fprintf (out, "H5T_ORDER_ERROR");
+ break;
+ case H5T_ORDER_LE:
+ fprintf (out, "H5T_ORDER_LE");
+ break;
+ case H5T_ORDER_BE:
+ fprintf (out, "H5T_ORDER_BE");
+ break;
+ case H5T_ORDER_VAX:
+ fprintf (out, "H5T_ORDER_VAX");
+ break;
+ case H5T_ORDER_NONE:
+ fprintf (out, "H5T_ORDER_NONE");
+ break;
+ default:
+ fprintf (out, "%ld", (long)order);
+ break;
+ }
+ }
+ break;
+
+ case 'p':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ H5T_pad_t pad = va_arg (ap, H5T_pad_t);
+ switch (pad) {
+ case H5T_PAD_ERROR:
+ fprintf (out, "H5T_PAD_ERROR");
+ break;
+ case H5T_PAD_ZERO:
+ fprintf (out, "H5T_PAD_ZERO");
+ break;
+ case H5T_PAD_ONE:
+ fprintf (out, "H5T_PAD_ONE");
+ break;
+ case H5T_PAD_BACKGROUND:
+ fprintf (out, "H5T_PAD_BACKGROUND");
+ break;
+ default:
+ fprintf (out, "%ld", (long)pad);
+ break;
+ }
+ }
+ break;
+
+ case 's':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ H5T_sign_t sign = va_arg (ap, H5T_sign_t);
+ switch (sign) {
+ case H5T_SGN_ERROR:
+ fprintf (out, "H5T_SGN_ERROR");
+ break;
+ case H5T_SGN_NONE:
+ fprintf (out, "H5T_SGN_NONE");
+ break;
+ case H5T_SGN_2:
+ fprintf (out, "H5T_SGN_2");
+ break;
+ default:
+ fprintf (out, "%ld", (long)sign);
+ break;
+ }
+ }
+ break;
+
+ case 't':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ H5T_class_t type_class = va_arg (ap, H5T_class_t);
+ switch (type_class) {
+ case H5T_NO_CLASS:
+ fprintf (out, "H5T_NO_CLASS");
+ break;
+ case H5T_INTEGER:
+ fprintf (out, "H5T_INTEGER");
+ break;
+ case H5T_FLOAT:
+ fprintf (out, "H5T_FLOAT");
+ break;
+ case H5T_TIME:
+ fprintf (out, "H5T_TIME");
+ break;
+ case H5T_STRING:
+ fprintf (out, "H5T_STRING");
+ break;
+ case H5T_BITFIELD:
+ fprintf (out, "H5T_BITFIELD");
+ break;
+ case H5T_OPAQUE:
+ fprintf (out, "H5T_OPAQUE");
+ break;
+ case H5T_COMPOUND:
+ fprintf (out, "H5T_COMPOUND");
+ break;
+ default:
+ fprintf (out, "%ld", (long)type_class);
+ break;
+ }
+ }
+ break;
+
+ case 'z':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ H5T_str_t str = va_arg (ap, H5T_str_t);
+ switch (str) {
+ case H5T_STR_ERROR:
+ fprintf (out, "H5T_STR_ERROR");
+ break;
+ case H5T_STR_NULL:
+ fprintf (out, "H5T_STR_NULL");
+ break;
+ case H5T_STR_SPACE:
+ fprintf (out, "H5T_STR_SPACE");
+ break;
+ default:
+ fprintf (out, "%ld", (long)str);
+ break;
+ }
+ }
+ break;
+
+ default:
+ fprintf (out, "BADTYPE(T%c)", type[1]);
+ goto error;
+ }
+ break;
+
+ case 'x':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ vp = va_arg (ap, void*);
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ }
+ break;
+
+ case 'z':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ size_t size = va_arg (ap, size_t);
+ HDfprintf (out, "%Zu", size);
+ }
+ break;
+
+ case 'Z':
+ switch (type[1]) {
+ case 'm':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ H5Z_method_t zmeth = va_arg (ap, H5Z_method_t);
+ if (zmeth<0) {
+ fprintf (out, "%d (range)", (int)zmeth);
+ } else if (H5Z_NONE==zmeth) {
+ fprintf (out, "H5Z_NONE");
+ } else if (H5Z_DEFLATE==zmeth) {
+ fprintf (out, "H5Z_DEFLATE");
+ } else if (zmeth<H5Z_USERDEF_MIN) {
+ fprintf (out, "H5Z_RES_%d", (int)zmeth);
+ } else if (zmeth<=H5Z_USERDEF_MAX) {
+ fprintf (out, "%d", (int)zmeth);
+ } else {
+ fprintf (out, "%d (range)", (int)zmeth);
+ }
+ }
+ break;
+
+ case 's':
+ if (ptr) {
+ fprintf (out, "0x%lx", (unsigned long)vp);
+ } else {
+ ssize_t ssize = va_arg (ap, ssize_t);
+ HDfprintf (out, "%Zd", ssize);
+ }
+ break;
+
+ default:
+ fprintf (out, "BADTYPE(Z%c)", type[1]);
+ goto error;
+ }
+ break;
+
+ default:
+ if (isupper (type[0])) {
+ fprintf (out, "BADTYPE(%c%c)", type[0], type[1]);
+ } else {
+ fprintf (out, "BADTYPE(%c)", type[0]);
+ }
+ goto error;
+ }
+
+ type += isupper(*type)?2:1;
+ }
+
+ error:
+ va_end (ap);
+ if (returning) {
+ fprintf (out, ";\n");
+ } else {
+ fprintf (out, ")");
+ }
+ fflush (out);
+ return;
+}
+
+