I am trying to register an error printing function with H5Eset_auto2
that makes use of its "client_data" argument. I am using library
version 1.8.3 from the Debian repositories. I have carefully read the
entry in the reference manual at
http://www.hdfgroup.org/HDF5/doc/RM/RM_H5E.html#Error-SetAuto2
as well as Section 4.4 and 4.5 of the "Error Handling" chapter at
http://www.hdfgroup.org/HDF5/doc/UG/13_ErrorHandling.html#BasicErrorHandling
for quick reference, the function is prototyped as follows:
herr_t H5Eset_auto2( hid_t estack_id, H5E_auto2_t func, void *client_data )
My understanding from reading the above is that you call H5Eset_auto2 to
set "func" and "client_data" for a given error stack (nominally
H5E_DEFAULT). Then, the next
time an error condition is reached, "func" will be called with the
argument "client_data". However, it appears that the argument passed to
"func" is not in fact "client_data", but a NULL pointer. This is
evidenced by the below code
#include <stdlib.h>
#include <stdio.h>
#include <hdf5.h>
herr_t print_msg(void *cldata)
{
const char* msg = (const char*) cldata;
printf("**%p:%s**\n",cldata,msg);
return 0;
}
int main(int argc,char* argv[])
{
const char* msg="an error has occured\n";
H5Eset_auto2(H5E_DEFAULT,(H5E_auto2_t)print_msg,(void*)msg);
hid_t fid = H5Fopen("notafile",H5F_ACC_RDONLY,H5P_DEFAULT);
if(fid<0){
printf("you should have seen:\n");
print_msg((void*)msg);
exit(EXIT_FAILURE);
}else{
H5Fclose(fid);
exit(EXIT_SUCCESS);
}
}
Which I run as follows:
$ gcc -lhdf5 testerr.c
$ a.out
**(nil):(null)**
you should have seen:
**0x400997:an error has occured
···
**
$
Is there something I am missing or is this a bug in the library and/or
documentation?
Kevin