diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2003-02-24 20:19:01 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2003-02-24 20:19:01 (GMT) |
commit | eaa30bb6489521ee6178fbe909fe62bab767d24a (patch) | |
tree | af85961ec7a04f1e2fbaa4daa5ac45c50d52b411 | |
parent | 9005dfcdc281c692f1e3cafa1ec8fb8eece5b338 (diff) | |
download | hdf5-eaa30bb6489521ee6178fbe909fe62bab767d24a.zip hdf5-eaa30bb6489521ee6178fbe909fe62bab767d24a.tar.gz hdf5-eaa30bb6489521ee6178fbe909fe62bab767d24a.tar.bz2 |
[svn-r6433] Purpose:
Code/comment cleanup
Description:
Made more information about reference-counted strings private to the
H5RS package by trimming the typedef used in H5RSprivate.h and switching
from using macros for a couple of operations to using functions.
Updated copyright information for a few of these files.
Platforms tested:
Tested h5committest {arabica (fortran), eirene (fortran, C++)
modi4 (parallel, fortran)}
-rw-r--r-- | src/H5G.c | 26 | ||||
-rw-r--r-- | src/H5Gstab.c | 4 | ||||
-rw-r--r-- | src/H5I.c | 31 | ||||
-rw-r--r-- | src/H5RS.c | 108 | ||||
-rw-r--r-- | src/H5RSprivate.h | 51 | ||||
-rw-r--r-- | test/trefstr.c | 74 |
6 files changed, 194 insertions, 100 deletions
@@ -3162,11 +3162,11 @@ H5G_common_path(const H5RS_str_t *fullpath_r, const H5RS_str_t *prefix_r) FUNC_ENTER_NOINIT(H5G_common_path); /* Get component of each name */ - fullpath=H5RS_GET_STR(fullpath_r); + fullpath=H5RS_get_str(fullpath_r); assert(fullpath); fullpath=H5G_component(fullpath,&nchars1); assert(fullpath); - prefix=H5RS_GET_STR(prefix_r); + prefix=H5RS_get_str(prefix_r); assert(prefix); prefix=H5G_component(prefix,&nchars2); assert(prefix); @@ -3373,7 +3373,7 @@ H5G_replace_ent(void *obj_ptr, hid_t obj_id, const void *key) H5RS_str_t *canon_dst_path_r; /* Copy of canonical part of destination path */ /* Make certain that the source and destination names are full (not relative) paths */ - if(*(H5RS_GET_STR(names->src_name))!='/') { + if(*(H5RS_get_str(names->src_name))!='/') { const char *src_name; /* Pointer to raw string of src_name */ char *src_path; /* Full user path of source name */ const char *src_user_path; /* Pointer to raw string of src path */ @@ -3381,7 +3381,7 @@ H5G_replace_ent(void *obj_ptr, hid_t obj_id, const void *key) unsigned need_sep; /* Flag to indicate if separator is needed */ /* Get the pointer to the raw src user path */ - src_user_path=H5RS_GET_STR(names->src_loc->user_path_r); + src_user_path=H5RS_get_str(names->src_loc->user_path_r); /* Get the length of the name for the source group's user path */ src_path_len=HDstrlen(src_user_path); @@ -3393,7 +3393,7 @@ H5G_replace_ent(void *obj_ptr, hid_t obj_id, const void *key) need_sep=1; /* Get the pointer to the raw src user path */ - src_name=H5RS_GET_STR(names->src_name); + src_name=H5RS_get_str(names->src_name); /* Add in the length needed for the '/' separator and the relative path */ src_path_len+=HDstrlen(src_name)+need_sep; @@ -3412,7 +3412,7 @@ H5G_replace_ent(void *obj_ptr, hid_t obj_id, const void *key) } /* end if */ else src_path_r=H5RS_dup(names->src_name); - if(*(H5RS_GET_STR(names->dst_name))!='/') { + if(*(H5RS_get_str(names->dst_name))!='/') { const char *dst_name; /* Pointer to raw string of dst_name */ char *dst_path; /* Full user path of destination name */ const char *dst_user_path; /* Pointer to raw string of dst path */ @@ -3420,7 +3420,7 @@ H5G_replace_ent(void *obj_ptr, hid_t obj_id, const void *key) unsigned need_sep; /* Flag to indicate if separator is needed */ /* Get the pointer to the raw dst user path */ - dst_user_path=H5RS_GET_STR(names->dst_loc->user_path_r); + dst_user_path=H5RS_get_str(names->dst_loc->user_path_r); /* Get the length of the name for the destination group's user path */ dst_path_len=HDstrlen(dst_user_path); @@ -3432,7 +3432,7 @@ H5G_replace_ent(void *obj_ptr, hid_t obj_id, const void *key) need_sep=1; /* Get the pointer to the raw dst user path */ - dst_name=H5RS_GET_STR(names->dst_name); + dst_name=H5RS_get_str(names->dst_name); /* Add in the length needed for the '/' separator and the relative path */ dst_path_len+=HDstrlen(dst_name)+need_sep; @@ -3461,8 +3461,8 @@ H5G_replace_ent(void *obj_ptr, hid_t obj_id, const void *key) /* Get current string lengths */ non_canon_name_len=H5RS_len(names->loc->user_path_r)-H5RS_len(names->loc->canon_path_r); - canon_src_path_r=H5RS_create(H5RS_GET_STR(src_path_r)+non_canon_name_len); - canon_dst_path_r=H5RS_create(H5RS_GET_STR(dst_path_r)+non_canon_name_len); + canon_src_path_r=H5RS_create(H5RS_get_str(src_path_r)+non_canon_name_len); + canon_dst_path_r=H5RS_create(H5RS_get_str(dst_path_r)+non_canon_name_len); } /* end if */ else { canon_src_path_r=H5RS_dup(src_path_r); @@ -3490,8 +3490,8 @@ H5G_replace_ent(void *obj_ptr, hid_t obj_id, const void *key) const char *canon_dst_path; /* pointer to canonical part of destination path */ /* Get the pointers to the raw strings */ - canon_src_path=H5RS_GET_STR(canon_src_path_r); - canon_dst_path=H5RS_GET_STR(canon_dst_path_r); + canon_src_path=H5RS_get_str(canon_src_path_r); + canon_dst_path=H5RS_get_str(canon_dst_path_r); /* Get the source & destination components */ src_comp=HDstrrchr(canon_src_path,'/'); @@ -3513,7 +3513,7 @@ H5G_replace_ent(void *obj_ptr, hid_t obj_id, const void *key) dst_canon_prefix[dst_canon_prefix_len]='\0'; /* Hold this for later use */ - old_user_path=H5RS_GET_STR(ent->user_path_r); + old_user_path=H5RS_get_str(ent->user_path_r); /* Find the user prefix for the entry */ user_prefix_len=HDstrlen(old_user_path)-H5RS_len(ent->canon_path_r); diff --git a/src/H5Gstab.c b/src/H5Gstab.c index cf2fa28..ff5e735 100644 --- a/src/H5Gstab.c +++ b/src/H5Gstab.c @@ -352,7 +352,7 @@ H5G_insert_name(H5G_entry_t *loc, H5G_entry_t *obj, const char *name) /* Modify the object's user path */ /* Get the raw string for the user path */ - loc_user_path=H5RS_GET_STR(loc->user_path_r); + loc_user_path=H5RS_get_str(loc->user_path_r); assert(loc_user_path); /* The location's user path already ends in a '/' separator */ @@ -379,7 +379,7 @@ H5G_insert_name(H5G_entry_t *loc, H5G_entry_t *obj, const char *name) /* Modify the object's canonical path */ /* Get the raw string for the canonical path */ - loc_canon_path=H5RS_GET_STR(loc->canon_path_r); + loc_canon_path=H5RS_get_str(loc->canon_path_r); assert(loc_canon_path); /* The location's canonical path already ends in a '/' separator */ @@ -1,16 +1,16 @@ -/**************************************************************************** - * NCSA HDF * - * Software Development Group * - * National Center for Supercomputing Applications * - * University of Illinois at Urbana-Champaign * - * 605 E. Springfield, Champaign IL 61820 * - * * - * For conditions of distribution and use, see the accompanying * - * hdf/COPYING file. * - * * - ****************************************************************************/ - -/* $Id$ */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* * FILE: H5I.c - Internal storage routines for handling "IDs" @@ -31,10 +31,11 @@ * 1/7/96 - Finished coding prototype * 6/10/97 - Moved into HDF5 library */ + #include "H5private.h" -#include "H5Iprivate.h" #include "H5Eprivate.h" #include "H5FLprivate.h" /*Free Lists */ +#include "H5Iprivate.h" #include "H5MMprivate.h" /* Define this to compile in support for dumping ID information */ @@ -1162,7 +1163,7 @@ H5Iget_name(hid_t id, char *name/*out*/, size_t size) len = H5RS_len(ent->user_path_r); if(name) { - HDstrncpy(name, H5RS_GET_STR(ent->user_path_r), MIN(len+1,size)); + HDstrncpy(name, H5RS_get_str(ent->user_path_r), MIN(len+1,size)); if(len >= size) name[size-1]='\0'; } /* end if */ @@ -1,14 +1,16 @@ -/**************************************************************************** - * NCSA HDF * - * Software Development Group * - * National Center for Supercomputing Applications * - * University of Illinois at Urbana-Champaign * - * 605 E. Springfield, Champaign IL 61820 * - * * - * For conditions of distribution and use, see the accompanying * - * hdf/COPYING file. * - * * - ****************************************************************************/ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* * Reference counted string algorithms. @@ -21,12 +23,20 @@ #include "H5FLprivate.h" /* Free lists */ #include "H5RSprivate.h" /* Reference-counted strings */ +/* Pablo information */ #define PABLO_MASK H5RS_mask /* Interface initialization */ static int interface_initialize_g = 0; #define INTERFACE_INIT NULL +/* Private typedefs & structs */ +typedef struct H5RS_str_t { + char *s; /* String to be reference counted */ + unsigned wrapped; /* Indicates that the string to be ref-counted is not copied */ + unsigned n; /* Reference count of number of pointers sharing string */ +}; + /* Declare a free list to manage the H5RS_str_t struct */ H5FL_DEFINE_STATIC(H5RS_str_t); @@ -388,3 +398,79 @@ done: FUNC_LEAVE_NOAPI(ret_value); } /* end H5RS_len() */ + +/*-------------------------------------------------------------------------- + NAME + H5RS_get_str + PURPOSE + Get a pointer to the internal string contained in a ref-counted string + USAGE + char *H5RS_get_str(rs) + const H5RS_str_t *rs; IN: Ref-counted string to get internal string from + + RETURNS + Returns a pointer to the internal string being ref-counted on success, + NULL on failure. + DESCRIPTION + Gets a pointer to the internal string being reference counted. This + pointer is volatile and might be invalid is further calls to the H5RS + API are made. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +char * +H5RS_get_str(const H5RS_str_t *rs) +{ + char *ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5RS_get_str,NULL); + + /* Sanity check */ + assert(rs); + assert(rs->s); + + ret_value=rs->s; + +done: + FUNC_LEAVE_NOAPI(ret_value); +} /* end H5RS_get_str() */ + + +/*-------------------------------------------------------------------------- + NAME + H5RS_get_count + PURPOSE + Get the reference count for a ref-counted string + USAGE + unsigned H5RS_get_count(rs) + const H5RS_str_t *rs; IN: Ref-counted string to get internal count from + + RETURNS + Returns the number of references to the internal string being ref-counted on success, + 0 on failure. + DESCRIPTION + Gets the count of references to the reference counted string. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +unsigned +H5RS_get_count(const H5RS_str_t *rs) +{ + unsigned ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5RS_get_count,0); + + /* Sanity check */ + assert(rs); + assert(rs->n>0); + + ret_value=rs->n; + +done: + FUNC_LEAVE_NOAPI(ret_value); +} /* end H5RS_get_count() */ + diff --git a/src/H5RSprivate.h b/src/H5RSprivate.h index a473af0..a154d01 100644 --- a/src/H5RSprivate.h +++ b/src/H5RSprivate.h @@ -1,14 +1,16 @@ -/**************************************************************************** - * NCSA HDF * - * Software Development Group * - * National Center for Supercomputing Applications * - * University of Illinois at Urbana-Champaign * - * 605 E. Springfield, Champaign IL 61820 * - * * - * For conditions of distribution and use, see the accompanying * - * hdf/COPYING file. * - * * - ****************************************************************************/ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* * This file contains private information about the H5RS module @@ -16,29 +18,32 @@ #ifndef _H5RSprivate_H #define _H5RSprivate_H +/**************************************/ +/* Public headers needed by this file */ +/**************************************/ #ifdef LATER #include "H5RSpublic.h" #endif /* LATER */ +/***************************************/ /* Private headers needed by this file */ +/***************************************/ #include "H5private.h" +/************/ /* Typedefs */ +/************/ -/* Typedef for reference counted string */ -typedef struct { - char *s; /* String to be reference counted */ - unsigned wrapped; /* Indicates that the string to be ref-counted is not copied */ - unsigned n; /* Reference count of number of pointers sharing string */ -} H5RS_str_t; +/* Typedef for reference counted string (defined in H5RS.c) */ +typedef struct H5RS_str_t H5RS_str_t; +/**********/ /* Macros */ +/**********/ -/* Get the pointer to the actual string */ -#define H5RS_GET_STR(rs) ((rs)->s) -#define H5RS_GET_COUNT(rs) ((rs)->n) - +/********************/ /* Private routines */ +/********************/ H5_DLL H5RS_str_t *H5RS_create(const char *s); H5_DLL H5RS_str_t *H5RS_wrap(const char *s); H5_DLL H5RS_str_t *H5RS_own(char *s); @@ -47,6 +52,8 @@ H5_DLL herr_t H5RS_incr(H5RS_str_t *rs); H5_DLL H5RS_str_t *H5RS_dup(H5RS_str_t *s); H5_DLL int H5RS_cmp(const H5RS_str_t *rs1, const H5RS_str_t *rs2); H5_DLL ssize_t H5RS_len(const H5RS_str_t *rs); +H5_DLL char *H5RS_get_str(const H5RS_str_t *rs); +H5_DLL unsigned H5RS_get_count(const H5RS_str_t *rs); -#endif /* _H5STprivate_H */ +#endif /* _H5RSprivate_H */ diff --git a/test/trefstr.c b/test/trefstr.c index 374e954..5ba0371 100644 --- a/test/trefstr.c +++ b/test/trefstr.c @@ -1,16 +1,16 @@ -/**************************************************************************** - * NCSA HDF * - * Software Development Group * - * National Center for Supercomputing Applications * - * University of Illinois at Urbana-Champaign * - * 605 E. Springfield, Champaign IL 61820 * - * * - * For conditions of distribution and use, see the accompanying * - * hdf/COPYING file. * - * * - ****************************************************************************/ - -/* $Id$ */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* FILE @@ -71,8 +71,8 @@ test_refstr_create(void) CHECK(rs, NULL, "H5RS_create"); /* Get the reference count on the string */ - count=H5RS_GET_COUNT(rs); - VERIFY(count, 1, "H5RS_GET_COUNT"); + count=H5RS_get_count(rs); + VERIFY(count, 1, "H5RS_get_count"); /* Try closing a real ref-counted string */ ret=H5RS_decr(rs); @@ -101,24 +101,24 @@ test_refstr_count(void) CHECK(rs, NULL, "H5RS_create"); /* Get the reference count on the string */ - count=H5RS_GET_COUNT(rs); - VERIFY(count, 1, "H5RS_GET_COUNT"); + count=H5RS_get_count(rs); + VERIFY(count, 1, "H5RS_get_count"); /* Increment reference count */ ret=H5RS_incr(rs); CHECK(ret, FAIL, "H5RS_incr"); /* Get the reference count on the string */ - count=H5RS_GET_COUNT(rs); - VERIFY(count, 2, "H5RS_GET_COUNT"); + count=H5RS_get_count(rs); + VERIFY(count, 2, "H5RS_get_count"); /* Decrement reference count for string */ ret=H5RS_decr(rs); CHECK(ret, FAIL, "H5RS_decr"); /* Get the reference count on the string */ - count=H5RS_GET_COUNT(rs); - VERIFY(count, 1, "H5RS_GET_COUNT"); + count=H5RS_get_count(rs); + VERIFY(count, 1, "H5RS_get_count"); /* Decrement reference count for string */ ret=H5RS_decr(rs); @@ -148,26 +148,26 @@ test_refstr_dup(void) CHECK(rs1, NULL, "H5RS_create"); /* Get the reference count on the string */ - count=H5RS_GET_COUNT(rs1); - VERIFY(count, 1, "H5RS_GET_COUNT"); + count=H5RS_get_count(rs1); + VERIFY(count, 1, "H5RS_get_count"); /* Duplicate r-string */ rs2=H5RS_dup(rs1); CHECK(rs2, NULL, "H5RS_dup"); /* Get the reference count on the strings */ - count=H5RS_GET_COUNT(rs1); - VERIFY(count, 2, "H5RS_GET_COUNT"); - count=H5RS_GET_COUNT(rs2); - VERIFY(count, 2, "H5RS_GET_COUNT"); + count=H5RS_get_count(rs1); + VERIFY(count, 2, "H5RS_get_count"); + count=H5RS_get_count(rs2); + VERIFY(count, 2, "H5RS_get_count"); /* Decrement reference count for string */ ret=H5RS_decr(rs2); CHECK(ret, FAIL, "H5RS_decr"); /* Get the reference count on the string */ - count=H5RS_GET_COUNT(rs1); - VERIFY(count, 1, "H5RS_GET_COUNT"); + count=H5RS_get_count(rs1); + VERIFY(count, 1, "H5RS_get_count"); /* Decrement reference count for string */ ret=H5RS_decr(rs1); @@ -252,8 +252,8 @@ test_refstr_wrap(void) CHECK(rs, NULL, "H5RS_wrap"); /* Get pointer to raw string in ref-counted string */ - s=H5RS_GET_STR(rs); - CHECK(s, NULL, "H5RS_GET_STR"); + s=H5RS_get_str(rs); + CHECK(s, NULL, "H5RS_get_str"); VERIFY(s, buf, "wrapping"); cmp=HDstrcmp(s,buf); VERIFY(cmp, 0, "HDstrcmp"); @@ -266,8 +266,8 @@ test_refstr_wrap(void) buf[0]='F'; /* Get pointer to raw string in ref-counted string */ - s=H5RS_GET_STR(rs); - CHECK(s, NULL, "H5RS_GET_STR"); + s=H5RS_get_str(rs); + CHECK(s, NULL, "H5RS_get_str"); CHECK(s, buf, "wrapping"); cmp=HDstrcmp(s,buf); if(cmp<=0) { @@ -311,8 +311,8 @@ test_refstr_own(void) CHECK(rs, NULL, "H5RS_own"); /* Get pointer to raw string in ref-counted string */ - t=H5RS_GET_STR(rs); - CHECK(t, NULL, "H5RS_GET_STR"); + t=H5RS_get_str(rs); + CHECK(t, NULL, "H5RS_get_str"); VERIFY(t, s, "transferring"); cmp=HDstrcmp(s,t); VERIFY(cmp, 0, "HDstrcmp"); @@ -325,8 +325,8 @@ test_refstr_own(void) *s='F'; /* Get pointer to raw string in ref-counted string */ - t=H5RS_GET_STR(rs); - CHECK(t, NULL, "H5RS_GET_STR"); + t=H5RS_get_str(rs); + CHECK(t, NULL, "H5RS_get_str"); VERIFY(t, s, "transferring"); cmp=HDstrcmp(t,s); VERIFY(cmp, 0, "HDstrcmp"); |