diff options
author | Jonathan Kim <jkm@hdfgroup.org> | 2011-08-31 20:56:05 (GMT) |
---|---|---|
committer | Jonathan Kim <jkm@hdfgroup.org> | 2011-08-31 20:56:05 (GMT) |
commit | b8b0b709457bceb2bf1ef73cd9b1b686c332dc8a (patch) | |
tree | c79f08b368b0fef3bd1963eb6d178210c0fc337f /tools/h5repack | |
parent | e3b66f853aeafe2260117c23f1d56746738289e4 (diff) | |
download | hdf5-b8b0b709457bceb2bf1ef73cd9b1b686c332dc8a.zip hdf5-b8b0b709457bceb2bf1ef73cd9b1b686c332dc8a.tar.gz hdf5-b8b0b709457bceb2bf1ef73cd9b1b686c332dc8a.tar.bz2 |
[svn-r21344] Purpose:
HDFFV-2511 - GMQS: h5repack: some tests failed in -q32 AIX
Description:
- Merged from HDF5 trunk r21265
- Added macro to handle failure in H5Dread/write when memory allocation
failed inside the library (XCAO)
Tested:
jam (linux32-LE), koala (linux64-LE), heiwa (linuxppc64-BE)
Diffstat (limited to 'tools/h5repack')
-rw-r--r-- | tools/h5repack/h5repack_copy.c | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c index 56371cc..01a7ba2 100644 --- a/tools/h5repack/h5repack_copy.c +++ b/tools/h5repack/h5repack_copy.c @@ -31,8 +31,27 @@ * macros *------------------------------------------------------------------------- */ -#define USERBLOCK_XFER_SIZE 512 /* size of buffer/# of bytes to xfer at a time when copying userblock */ +/* size of buffer/# of bytes to xfer at a time when copying userblock */ +#define USERBLOCK_XFER_SIZE 512 + +/* check H5Dread()/H5Dwrite() error, e.g. memory allocation error inside the library. */ +#define CHECK_H5DRW_ERROR(_fun, _did, _mtid, _msid, _fsid, _pid, _buf) { \ + H5E_BEGIN_TRY { \ + if(_fun(_did, _mtid, _msid, _fsid, _pid, _buf) < 0) { \ + int _err_num = 0; \ + char *_msg = NULL; \ + H5Ewalk2(H5E_DEFAULT, H5E_WALK_DOWNWARD, walk_error_callback, &_err_num); \ + _msg = H5Eget_major(_err_num); \ + if (_msg) { \ + error_msg("%s %s -- %s\n", #_fun, "failed", _msg); \ + free(_msg); \ + } \ + goto error; \ + } \ + } H5E_END_TRY; \ +} + /*------------------------------------------------------------------------- * local functions *------------------------------------------------------------------------- @@ -43,6 +62,16 @@ static int copy_user_block(const char *infile, const char *outfile, hsize_t si #if defined (H5REPACK_DEBUG_USER_BLOCK) static void print_user_block(const char *filename, hid_t fid); #endif +static herr_t walk_error_callback(unsigned n, const H5E_error2_t *err_desc, void *udata); + +/* get the major number from the error stack. */ +static herr_t walk_error_callback(UNUSED unsigned n, const H5E_error2_t *err_desc, void *udata) +{ + if (err_desc) + *((int *)udata) = err_desc->maj_num; + + return 0; +} /*------------------------------------------------------------------------- * Function: copy_objects @@ -803,11 +832,10 @@ int do_copy_objects(hid_t fidin, buf = HDmalloc(need); if(buf != NULL) { - if(H5Dread(dset_in, wtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) - goto error; - if(H5Dwrite(dset_out, wtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) - goto error; - + /* read/write: use the macro to check error, e.g. memory allocation error inside the library. */ + CHECK_H5DRW_ERROR(H5Dread, dset_in, wtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); + CHECK_H5DRW_ERROR(H5Dwrite, dset_out, wtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); + /* Check if we have VL data in the dataset's * datatype that must be reclaimed */ if(TRUE == H5Tdetect_class(wtype_id, H5T_VLEN)) @@ -886,11 +914,9 @@ int do_copy_objects(hid_t fidin, hs_nelmts = 1; } /* rank */ - /* read/write */ - if (H5Dread(dset_in, wtype_id, sm_space, f_space_id, H5P_DEFAULT, sm_buf) < 0) - goto error; - if (H5Dwrite(dset_out, wtype_id, sm_space, f_space_id, H5P_DEFAULT, sm_buf) < 0) - goto error; + /* read/write: use the macro to check error, e.g. memory allocation error inside the library. */ + CHECK_H5DRW_ERROR(H5Dread, dset_in, wtype_id, sm_space, f_space_id, H5P_DEFAULT, sm_buf); + CHECK_H5DRW_ERROR(H5Dwrite, dset_out, wtype_id, sm_space, f_space_id, H5P_DEFAULT, sm_buf); /* reclaim any VL memory, if necessary */ if(vl_data) |