summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJerome Soumagne <jsoumagne@hdfgroup.org>2015-09-01 21:55:07 (GMT)
committerJerome Soumagne <jsoumagne@hdfgroup.org>2016-11-29 23:42:30 (GMT)
commit45c0818ef57893dbdde768270a7a5e7b2b028155 (patch)
tree348a95181b6d5ba16142be76c12980329b2e94bd
parent7fdc338700008408ad528034ec047c070ab5ebe5 (diff)
downloadhdf5-45c0818ef57893dbdde768270a7a5e7b2b028155.zip
hdf5-45c0818ef57893dbdde768270a7a5e7b2b028155.tar.gz
hdf5-45c0818ef57893dbdde768270a7a5e7b2b028155.tar.bz2
Use var args for H5Rcreate and make H5R_create private
-rw-r--r--src/H5R.c135
-rw-r--r--src/H5Rprivate.h4
-rw-r--r--src/H5Rpublic.h5
-rw-r--r--test/trefer.c16
4 files changed, 81 insertions, 79 deletions
diff --git a/src/H5R.c b/src/H5R.c
index 2c96bcf..51aff82 100644
--- a/src/H5R.c
+++ b/src/H5R.c
@@ -51,8 +51,6 @@
/* Local Prototypes */
/********************/
-static herr_t H5R_create(void *ref, H5G_loc_t *loc, const char *name,
- const char *attr_name, H5R_type_t ref_type, H5S_t *space, hid_t dxpl_id);
static H5S_t * H5R_get_region(H5F_t *file, hid_t dxpl_id, const void *_ref);
static ssize_t H5R_get_name(H5F_t *file, hid_t lapl_id, hid_t dxpl_id, hid_t id,
H5R_type_t ref_type, const void *_ref, char *name, size_t size);
@@ -217,8 +215,11 @@ H5R_term_package(void)
const char *attr_name; IN: Name of attribute at location LOC_ID
pointed to
H5R_type_t ref_type; IN: Type of reference to create
- H5S_t *space; IN: Dataspace ID with selection, used for Dataset
+ Additional arguments:
+ H5S_t *space; IN: Dataspace with selection, used for Dataset
Region references.
+ const char *attr_name; IN: Name of attribute pointed to, used for
+ Attribute references.
RETURNS
Non-negative on success/Negative on failure
@@ -233,15 +234,16 @@ H5R_term_package(void)
EXAMPLES
REVISION LOG
--------------------------------------------------------------------------*/
-static herr_t
-H5R_create(void *_ref, H5G_loc_t *loc, const char *name, const char *attr_name,
- H5R_type_t ref_type, H5S_t *space, hid_t dxpl_id)
+herr_t
+H5R_create(void *_ref, H5G_loc_t *loc, const char *name, hid_t dxpl_id,
+ H5R_type_t ref_type, ...)
{
H5G_loc_t obj_loc; /* Group hier. location of object */
H5G_name_t path; /* Object group hier. path */
H5O_loc_t oloc; /* Object object location */
uint8_t *buf = NULL; /* Buffer to store serialized selection in */
hbool_t obj_found = FALSE; /* Object location found */
+ va_list ap;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -251,6 +253,8 @@ H5R_create(void *_ref, H5G_loc_t *loc, const char *name, const char *attr_name,
HDassert(name);
HDassert(ref_type > H5R_BADTYPE && ref_type < H5R_MAXTYPE);
+ va_start(ap, ref_type);
+
/* Set up object location to fill in */
obj_loc.oloc = &oloc;
obj_loc.path = &path;
@@ -278,6 +282,9 @@ H5R_create(void *_ref, H5G_loc_t *loc, const char *name, const char *attr_name,
uint8_t *p; /* Pointer to OID to store */
hbool_t heapid_found; /* Flag for non-zero heap ID found */
unsigned u; /* local index */
+ H5S_t *space = va_arg(ap, H5S_t *);
+
+ HDassert(space);
/* Set up information for dataset region */
@@ -340,6 +347,9 @@ H5R_create(void *_ref, H5G_loc_t *loc, const char *name, const char *attr_name,
uint8_t *p; /* Pointer to OID to store */
hbool_t heapid_found; /* Flag for non-zero heap ID found */
unsigned u; /* local index */
+ const char *attr_name = va_arg(ap, const char *);
+
+ HDassert(attr_name);
/* Set up information for attribute */
@@ -404,6 +414,8 @@ H5R_create(void *_ref, H5G_loc_t *loc, const char *name, const char *attr_name,
HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "internal error (unknown reference type)")
} /* end switch */
+ va_end(ap);
+
done:
if(obj_found)
H5G_loc_free(&obj_loc);
@@ -426,8 +438,11 @@ done:
const char *name; IN: Name of object at location LOC_ID of object
pointed to
H5R_type_t ref_type; IN: Type of reference to create
- hid_t space_id; IN: Dataspace ID with selection, used for Dataset
+ Additional arguments:
+ hid_t space_id; IN: Dataspace ID with selection, used for Dataset
Region references.
+ const char *attr_name; IN: Name of attribute pointed to, used for
+ Attribute references.
RETURNS
Non-negative on success/Negative on failure
@@ -442,14 +457,17 @@ done:
REVISION LOG
--------------------------------------------------------------------------*/
herr_t
-H5Rcreate(void *ref, hid_t loc_id, const char *name, H5R_type_t ref_type, hid_t space_id)
+H5Rcreate(void *ref, hid_t loc_id, const char *name, H5R_type_t ref_type, ...)
{
H5G_loc_t loc; /* File location */
H5S_t *space = NULL; /* Pointer to dataspace containing region */
+ va_list ap;
herr_t ret_value; /* Return value */
FUNC_ENTER_API(FAIL)
- H5TRACE5("e", "*xi*sRti", ref, loc_id, name, ref_type, space_id);
+ H5TRACE4("e", "*xi*sRt", ref, loc_id, name, ref_type);
+
+ va_start(ap, ref_type);
/* Check args */
if(ref == NULL)
@@ -458,72 +476,51 @@ H5Rcreate(void *ref, hid_t loc_id, const char *name, H5R_type_t ref_type, hid_t
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
if(!name || !*name)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name given")
- if(ref_type <= H5R_BADTYPE || ref_type >= H5R_MAXTYPE)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference type")
- if(ref_type != H5R_OBJECT && ref_type != H5R_DATASET_REGION)
- HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "reference type not supported")
- if(space_id == (-1) && ref_type == H5R_DATASET_REGION)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "reference region dataspace id must be valid")
- if(space_id != (-1) && (NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))))
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace")
- /* Create reference */
- if((ret_value = H5R_create(ref, &loc, name, NULL, ref_type, space, H5AC_dxpl_id)) < 0)
- HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINIT, FAIL, "unable to create reference")
-
-done:
- FUNC_LEAVE_API(ret_value)
-} /* end H5Rcreate() */
+ switch (ref_type) {
+ case H5R_OBJECT:
+ if((ret_value = H5R_create(ref, &loc, name, H5AC_dxpl_id, ref_type)) < 0)
+ HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINIT, FAIL, "unable to create reference")
+ break;
+ case H5R_DATASET_REGION:
+ {
+ hid_t space_id;
-
-/*--------------------------------------------------------------------------
- NAME
- H5Rcreate_attr
- PURPOSE
- Creates an attribute reference for the user
- USAGE
- herr_t H5Rcreate_attr(ref, loc_id, name, attr_name)
- void *ref; OUT: Reference created
- hid_t loc_id; IN: Location ID used to locate object pointed to
- const char *name; IN: Name of object at location LOC_ID
- const char *attr_name; IN: Name of attribute pointed to
+ /* Get arguments */
+ space_id = va_arg(ap, hid_t);
- RETURNS
- Non-negative on success/Negative on failure
- DESCRIPTION
- Creates an attribute reference, in the space pointed to by REF. The LOC_ID,
- NAME and ATTR_NAME are used to locate the attribute pointed to.
- GLOBAL VARIABLES
- COMMENTS, BUGS, ASSUMPTIONS
- EXAMPLES
- REVISION LOG
---------------------------------------------------------------------------*/
-herr_t
-H5Rcreate_attr(void *ref, hid_t loc_id, const char *name, const char *attr_name)
-{
- H5G_loc_t loc; /* File location */
- herr_t ret_value; /* Return value */
+ if(space_id == H5I_BADID)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "reference region dataspace id must be valid")
+ if(space_id != H5I_BADID && (NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace")
+ if((ret_value = H5R_create(ref, &loc, name, H5AC_dxpl_id, ref_type, space)) < 0)
+ HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINIT, FAIL, "unable to create reference")
+ }
+ break;
+ case H5R_ATTR:
+ {
+ const char *attr_name;
- FUNC_ENTER_API(FAIL)
- H5TRACE4("e", "*xi*s*s", ref, loc_id, name, attr_name);
+ /* Get arguments */
+ attr_name = va_arg(ap, const char *);
- /* Check args */
- if(ref == NULL)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer")
- if(H5G_loc(loc_id, &loc) < 0)
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
- if(!name || !*name)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name given")
- if(!attr_name || !*attr_name)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name given")
+ if(!attr_name || !*attr_name)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name given")
+ if((ret_value = H5R_create(ref, &loc, name, H5AC_dxpl_id, ref_type, attr_name)) < 0)
+ HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINIT, FAIL, "unable to create reference")
+ }
+ break;
+ case H5R_MAXTYPE:
+ case H5R_BADTYPE:
+ default:
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference type")
+ }
- /* Create reference */
- if((ret_value = H5R_create(ref, &loc, name, attr_name, H5R_ATTR, NULL, H5AC_dxpl_id)) < 0)
- HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINIT, FAIL, "unable to create reference")
+ va_end(ap);
done:
FUNC_LEAVE_API(ret_value)
-} /* end H5Rcreate_attr() */
+} /* end H5Rcreate() */
/*--------------------------------------------------------------------------
@@ -1169,7 +1166,11 @@ H5R_get_name(H5F_t *f, hid_t lapl_id, hid_t dxpl_id, hid_t id, H5R_type_t ref_ty
H5MM_xfree(buf);
} /* end case */
break;
-
+ case H5R_ATTR:
+ {
+ /* TODO */
+ }
+ break;
case H5R_BADTYPE:
case H5R_MAXTYPE:
default:
diff --git a/src/H5Rprivate.h b/src/H5Rprivate.h
index 60df636..eed616c 100644
--- a/src/H5Rprivate.h
+++ b/src/H5Rprivate.h
@@ -19,13 +19,17 @@
#ifndef _H5Rprivate_H
#define _H5Rprivate_H
+/* Include package's public header */
#include "H5Rpublic.h"
/* Private headers needed by this file */
+#include "H5Gprivate.h"
/* Internal data structures */
/* Private functions */
+H5_DLL herr_t H5R_create(void *ref, H5G_loc_t *loc, const char *name,
+ hid_t dxpl_id, H5R_type_t ref_type, ...);
#endif /* _H5Rprivate_H */
diff --git a/src/H5Rpublic.h b/src/H5Rpublic.h
index 7cbfc57..bea1e3c 100644
--- a/src/H5Rpublic.h
+++ b/src/H5Rpublic.h
@@ -64,10 +64,7 @@ extern "C" {
#endif
/* Functions in H5R.c */
-H5_DLL herr_t H5Rcreate(void *ref, hid_t loc_id, const char *name,
- H5R_type_t ref_type, hid_t space_id);
-H5_DLL herr_t H5Rcreate_attr(void *ref, hid_t loc_id, const char *name,
- const char *attr_name);
+H5_DLL herr_t H5Rcreate(void *ref, hid_t loc_id, const char *name, H5R_type_t ref_type, ...);
H5_DLL hid_t H5Rdereference2(hid_t obj_id, hid_t oapl_id, H5R_type_t ref_type, const void *ref);
H5_DLL hid_t H5Rget_region(hid_t dataset, H5R_type_t ref_type, const void *ref);
H5_DLL herr_t H5Rget_obj_type2(hid_t id, H5R_type_t ref_type, const void *_ref,
diff --git a/test/trefer.c b/test/trefer.c
index 1822d3b..7a63538 100644
--- a/test/trefer.c
+++ b/test/trefer.c
@@ -1868,29 +1868,29 @@ test_reference_attr(void)
CHECK(ret, FAIL, "H5Dcreate2");
/* Create reference to attribute */
- ret = H5Rcreate_attr(&wbuf[0], fid, "/Group1/Dataset1", "Attr1");
- CHECK(ret, FAIL, "H5Rcreate_attr");
+ ret = H5Rcreate(&wbuf[0], fid, "/Group1/Dataset1", H5R_ATTR, "Attr1");
+ CHECK(ret, FAIL, "H5Rcreate");
ret = H5Rget_obj_type2(dataset, H5R_ATTR, &wbuf[0], &obj_type);
CHECK(ret, FAIL, "H5Rget_obj_type2");
VERIFY(obj_type, H5O_TYPE_DATASET, "H5Rget_obj_type2");
/* Create reference to dataset */
- ret = H5Rcreate_attr(&wbuf[1], fid, "/Group1/Dataset2", "Attr1");
- CHECK(ret, FAIL, "H5Rcreate_attr");
+ ret = H5Rcreate(&wbuf[1], fid, "/Group1/Dataset2", H5R_ATTR, "Attr1");
+ CHECK(ret, FAIL, "H5Rcreate");
ret = H5Rget_obj_type2(dataset, H5R_ATTR, &wbuf[1], &obj_type);
CHECK(ret, FAIL, "H5Rget_obj_type2");
VERIFY(obj_type, H5O_TYPE_DATASET, "H5Rget_obj_type2");
/* Create reference to group */
- ret = H5Rcreate_attr(&wbuf[2], fid, "/Group1", "Attr2");
- CHECK(ret, FAIL, "H5Rcreate_attr");
+ ret = H5Rcreate(&wbuf[2], fid, "/Group1", H5R_ATTR, "Attr2");
+ CHECK(ret, FAIL, "H5Rcreate");
ret = H5Rget_obj_type2(dataset, H5R_ATTR, &wbuf[2], &obj_type);
CHECK(ret, FAIL, "H5Rget_obj_type2");
VERIFY(obj_type, H5O_TYPE_GROUP, "H5Rget_obj_type2");
/* Create reference to named datatype */
- ret = H5Rcreate_attr(&wbuf[3], fid, "/Group1/Datatype1", "Attr3");
- CHECK(ret, FAIL, "H5Rcreate_attr");
+ ret = H5Rcreate(&wbuf[3], fid, "/Group1/Datatype1", H5R_ATTR, "Attr3");
+ CHECK(ret, FAIL, "H5Rcreate");
ret = H5Rget_obj_type2(dataset, H5R_ATTR, &wbuf[3], &obj_type);
CHECK(ret, FAIL, "H5Rget_obj_type2");
VERIFY(obj_type, H5O_TYPE_NAMED_DATATYPE, "H5Rget_obj_type2");