Skip to content

Commit

Permalink
[svn-r1224] Changes since 19990426
Browse files Browse the repository at this point in the history
----------------------

./tools/h5tools.c
./tools/h5tools.h
	Finally fixed a long-standing bug that caused core dumps if
	a compound datum rendered to more than some number of
	characters (we kept bumping up the limit at the risk of
	violating stack size limits on some machines). The fix works
	only on systems that have the vsnprintf() function (otherwise
	a 4kB limit is imposed, which if violated probably dumps
	core). If vsnprintf() is present then the library dynamically
	allocates space for the output string.

	Also made it possible to control how compound data is rendered
	across multiple lines of output by allowing the caller to
	specify where optional line-breaks get inserted. The output
	functions split up the value at one or more optional
	line-breaks to prevent it from wrapping around the screen.

	If a datum doesn't fit on the current line but would fit on
	the next line then it is printed on the next line regardless
	of whether optional line-breaks would have prevent wrapping
	around the screen. This makes it easier to find the beginnings
	of compound data values.  This feature is disabled by default
	but can be enabled by the application.

	If a datum doesn't fit on the current line and the previous
	datum also occupied more than one line then we move to the
	next line before printing. This makes it easier to find the
	beginnings of compound data values but prevents the output
	from looking fragmented if there are only a few long values
	among mostly short values.  This feature is disabled by
	default but can be enabled by the application.

	The application can control the printf() formats used for all
	the native data types. The defaults are what the library used
	to use: %g, %ld, %lu, %d, and %u

./tools/h5ls.c
	Compound datatype values can now be split across multiple
	lines of output instead of just wrapping. Also, when lots of
	compound values are too long they all start at the beginning
	of a line. This only required about 10 lines of changes in the
	setup for tools library calls (I didn't modify the h5dump
	program because it uses its own version of the tools library
	that forked off long ago).

	Added code for Win32 which is unable to cast `unsigned long
	long' to `double'. If the dataset size exceeds (2^63)-1 then
	the percent utilization is not displayed (this is easily
	possible with chunked datasets). This is untested yet.

./configure.in
./src/H5config.h.in
./src/H5.c
./src/H5private.h
	Check for vsnprintf() and provide a simple, stupid definition
	if it isn't available. The stupid definition just calls
	vsprintf() and ignores the second argument. This can result in
	buffer overflows in h5ls and h5dump since vsprintf() is an
	unsafe function (and anyone can create an hdf5 file that runs
	an arbitrary command from h5ls and h5dump in that case)!

./config/conclude.in
	Remove more *.o files for `make clean'

./src/H5A.c
./src/H5D.c
./src/H5F.c
./src/H5I.c
./src/H5Iprivate.h
./src/H5P.c
./src/H5R.c
./src/H5RA.c
./src/H5S.c
./src/H5T.c
./src/H5TB.c
	Cleaned up a memory leak during H5_term_library() by allowing
	H5I_clear_group() to skip items that couldn't be freed. This
	allows the item to remain in the group until we can free it
	later.

./src/H5F.c
	The H5F_close_all() function fails if a file cannot be closed.
  • Loading branch information
matzke1 committed Apr 27, 1999
1 parent a66c628 commit 2dc738a
Show file tree
Hide file tree
Showing 21 changed files with 1,021 additions and 325 deletions.
3 changes: 2 additions & 1 deletion config/conclude.in
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ uninstall:
#
mostlyclean:
-$(RM) $(LIB_OBJ) $(LIB_OBJ:.lo=.o)
-$(RM) $(TEST_OBJ) $(PROG_OBJ) $(MOSTLYCLEAN)
-$(RM) $(TEST_OBJ) $(TEST_OBJ:.lo=.o)
-$(RM) $(PROG_OBJ) $(PROG_OBJ:.lo=.o) $(MOSTLYCLEAN)

# Like `mostlyclean' except it also removes the final targets: things like
# libraries and executables. This target doesn't remove any file that
Expand Down
4 changes: 2 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ case "$host" in
esac

# Actually configure libtool. ac_aux_dir is where install-sh is found.
AR="$AR" CC="$CC" CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" \
CC="$CC" CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" \
LD="$LD" NM="$NM" RANLIB="$RANLIB" LN_S="$LN_S" \
${CONFIG_SHELL-/bin/sh} $ac_aux_dir/ltconfig \
$libtool_flags --no-verify $ac_aux_dir/ltmain.sh $host \
Expand Down Expand Up @@ -4143,7 +4143,7 @@ else
fi
done

for ac_func in gettimeofday BSDgettimeofday difftime snprintf
for ac_func in gettimeofday BSDgettimeofday difftime snprintf vsnprintf
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:4150: checking for $ac_func" >&5
Expand Down
2 changes: 1 addition & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ dnl ----------------------------------------------------------------------
dnl Check for functions.
dnl
AC_CHECK_FUNCS(getpwuid gethostname system getrusage fork waitpid)
AC_CHECK_FUNCS(gettimeofday BSDgettimeofday difftime snprintf)
AC_CHECK_FUNCS(gettimeofday BSDgettimeofday difftime snprintf vsnprintf)
AC_CHECK_FUNCS(compress2 setsysinfo longjmp signal sigaction)
AC_TRY_COMPILE([#include<sys/types.h>],
[off64_t n = 0;],
Expand Down
35 changes: 35 additions & 0 deletions src/H5.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,41 @@ HDsnprintf(char *buf, size_t UNUSED size, const char *fmt, ...)
}
#endif /* HAVE_SNPRINTF */

#ifndef HAVE_VSNPRINTF


/*-------------------------------------------------------------------------
* Function: HDvsnprintf
*
* Purpose: The same as HDsnprintf() except the variable arguments are
* passed as a va_list.
*
* Note: This function is for compatibility on systems that don't have
* vsnprintf(3). It doesn't actually check for overflow like the
* real vsnprintf() would.
*
* Return: Success: Number of characters stored, not including
* the terminating null. If this value equals
* SIZE then there was not enough space in BUF
* for all the output.
*
* Failure: -1
*
* Programmer: Robb Matzke
* Monday, April 26, 1999
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
int
HDvsnprintf(char *buf, size_t size, const char *fmt, va_list ap)
{
return vsprintf(buf, fmt, ap);
}
#endif /* HAVE_VSNPRINTF */



/*-------------------------------------------------------------------------
* Function: HDfprintf
Expand Down
2 changes: 1 addition & 1 deletion src/H5A.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ H5A_term_interface(void)

if (interface_initialize_g) {
if ((n=H5I_nmembers(H5I_ATTR))) {
H5I_clear_group(H5I_ATTR);
H5I_clear_group(H5I_ATTR, FALSE);
} else {
H5I_destroy_group(H5I_ATTR);
interface_initialize_g = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/H5D.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ H5D_term_interface(void)

if (interface_initialize_g) {
if ((n=H5I_nmembers(H5I_DATASET))) {
H5I_clear_group(H5I_DATASET);
H5I_clear_group(H5I_DATASET, FALSE);
} else {
H5I_destroy_group(H5I_DATASET);
interface_initialize_g = 0;
Expand Down
5 changes: 4 additions & 1 deletion src/H5F.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ herr_t
H5F_close_all(void)
{
FUNC_ENTER(H5F_close_all, FAIL);
H5I_clear_group(H5I_FILE);
if (H5I_clear_group(H5I_FILE, FALSE)<0) {
HRETURN_ERROR(H5E_FILE, H5E_CLOSEERROR, FAIL,
"unable to close one or more files");
}
FUNC_LEAVE(SUCCEED);
}

Expand Down
2 changes: 1 addition & 1 deletion src/H5G.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ H5G_term_interface(void)

if (interface_initialize_g) {
if ((n=H5I_nmembers(H5I_GROUP))) {
H5I_clear_group(H5I_GROUP);
H5I_clear_group(H5I_GROUP, FALSE);
} else {
/* Empty the object type table */
for (i=0; i<H5G_ntypes_g; i++) {
Expand Down
42 changes: 28 additions & 14 deletions src/H5I.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,18 @@ H5I_nmembers(H5I_type_t grp)
* Wednesday, March 24, 1999
*
* Modifications:
* Robb Matzke, 1999-04-27
* If FORCE is zero then any item for which the free callback
* failed is not removed. This function returns failure if
* items could not be removed.
*
*-------------------------------------------------------------------------
*/
herr_t
H5I_clear_group(H5I_type_t grp)
H5I_clear_group(H5I_type_t grp, hbool_t force)
{
H5I_id_group_t *grp_ptr = NULL; /* ptr to the atomic group */
H5I_id_info_t *cur=NULL, *next=NULL;
H5I_id_info_t *cur=NULL, *next=NULL, *prev=NULL;
intn ret_value = SUCCEED;
uintn i;

Expand Down Expand Up @@ -401,26 +405,35 @@ H5I_clear_group(H5I_type_t grp)
/*
* Call free method for all objects in group regardless of their reference
* counts. Ignore the return value from from the free method and remove
* object from group regardless.
* object from group regardless if FORCE is non-zero.
*/
for (i=0; i<grp_ptr->hash_size; i++) {
for (cur=grp_ptr->id_list[i]; cur; cur=next) {
/* Free the object regardless of reference count */
if (grp_ptr->free_func && (grp_ptr->free_func)(cur->obj_ptr)<0) {
if (force) {
#if H5I_DEBUG
if (H5DEBUG(I)) {
fprintf(H5DEBUG(I), "H5I: free grp=%d obj=0x%08lx "
"failure ignored\n", (int)grp,
(unsigned long)(cur->obj_ptr));
}
if (H5DEBUG(I)) {
fprintf(H5DEBUG(I), "H5I: free grp=%d obj=0x%08lx "
"failure ignored\n", (int)grp,
(unsigned long)(cur->obj_ptr));
}
#endif /*H5I_DEBUG*/
/* Add ID struct to free list */
next = cur->next;
H5I_release_id_node(cur);
} else {
if (prev) prev->next = cur;
else grp_ptr->id_list[i] = cur;
prev = cur;
}
} else {
/* Add ID struct to free list */
next = cur->next;
H5I_release_id_node(cur);
}

/* Add ID struct to free list */
next = cur->next;
H5I_release_id_node(cur);
}
grp_ptr->id_list[i]=NULL;
if (!prev) grp_ptr->id_list[i]=NULL;
}

done:
Expand Down Expand Up @@ -472,7 +485,8 @@ H5I_destroy_group(H5I_type_t grp)
* free function is invoked for each atom being freed.
*/
if (1==grp_ptr->count) {
H5I_clear_group(grp);
H5I_clear_group(grp, TRUE);
H5E_clear(); /*don't care about errors*/
H5MM_xfree(grp_ptr->id_list);
HDmemset (grp_ptr, 0, sizeof(*grp_ptr));
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/H5Iprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ typedef struct {
__DLL__ intn H5I_init_group(H5I_type_t grp, size_t hash_size, uintn reserved,
H5I_free_t func);
__DLL__ intn H5I_nmembers(H5I_type_t grp);
__DLL__ herr_t H5I_clear_group(H5I_type_t grp);
__DLL__ herr_t H5I_clear_group(H5I_type_t grp, hbool_t force);
__DLL__ herr_t H5I_destroy_group(H5I_type_t grp);
__DLL__ hid_t H5I_register(H5I_type_t grp, void *object);
__DLL__ void *H5I_object(hid_t id);
Expand Down
2 changes: 1 addition & 1 deletion src/H5P.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ H5P_term_interface(void)
}
if (n) {
for (i=0; i<H5P_NCLASSES; i++) {
H5I_clear_group((H5I_type_t)(H5I_TEMPLATE_0+i));
H5I_clear_group((H5I_type_t)(H5I_TEMPLATE_0+i), FALSE);
}
} else {
for (i=0; i<H5P_NCLASSES; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/H5R.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ H5R_term_interface(void)

if (interface_initialize_g) {
if ((n=H5I_nmembers(H5I_REFERENCE))) {
H5I_clear_group(H5I_REFERENCE);
H5I_clear_group(H5I_REFERENCE, FALSE);
} else {
H5I_destroy_group(H5I_REFERENCE);
interface_initialize_g = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/H5RA.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ H5RA_term_interface(void)

if (interface_initialize_g) {
if ((n=H5I_nmembers(H5I_RAGGED))) {
H5I_clear_group(H5I_RAGGED);
H5I_clear_group(H5I_RAGGED, FALSE);
} else {
H5T_close(H5RA_meta_type_g);
H5RA_meta_type_g = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/H5S.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ H5S_term_interface(void)

if (interface_initialize_g) {
if ((n=H5I_nmembers(H5I_DATASPACE))) {
H5I_clear_group(H5I_DATASPACE);
H5I_clear_group(H5I_DATASPACE, FALSE);
} else {
#ifdef H5S_DEBUG
/*
Expand Down
Loading

0 comments on commit 2dc738a

Please sign in to comment.