client_data with H5Eset_auto2

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

Hi Kevin,

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

  This looks like a doc bug for the User Guide - the prototype for the 'func' argument should be:

herr_t func(hid_t estack_id, void *client_data);

  I'll file a bug in our Bugzilla about updating it.

  Quincey

···

On Sep 8, 2009, at 7:09 AM, Kevin Mitchell wrote:

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

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Ok, good to know I wasn't brain-dead. Thanks for the quick response!
Kevin

···

On Tue, Sep 8, 2009 at 5:50 AM, Quincey Koziol <koziol@hdfgroup.org> wrote:

Hi Kevin,

On Sep 8, 2009, at 7:09 AM, Kevin Mitchell wrote:

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

   This looks like a doc bug for the User Guide \- the prototype for the

'func' argument should be:

herr_t func(hid_t estack_id, void *client_data);

   I&#39;ll file a bug in our Bugzilla about updating it\.

   Quincey

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

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org