# client\_data with H5Eset\_auto2

**URL:** <https://forum.hdfgroup.org/t/client-data-with-h5eset-auto2/1424>\
**Category:** Hdf-forum archives\
**Created:** [September 8, 2009, 12:09pm UTC](https://forum.hdfgroup.org/t/client-data-with-h5eset-auto2/1424 "2009-09-08T12:09:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Mitchell](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/k/91b2a8/32.png) [@Kevin\_Mitchell](https://forum.hdfgroup.org/u/Kevin_Mitchell)\
**Post date:** [September 8, 2009, 12:09pm UTC](https://forum.hdfgroup.org/t/client-data-with-h5eset-auto2/1424/1 "2009-09-08T12:09:53Z")

</div>

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](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](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)  
{  
&nbsp;&nbsp;const char\* msg = (const char\*) cldata;  
&nbsp;&nbsp;printf("\*\*%p:%s\*\*\n",cldata,msg);  
&nbsp;&nbsp;return 0;  
}

int main(int argc,char\* argv[])  
{  
&nbsp;&nbsp;const char\* msg="an error has occured\n";  
&nbsp;&nbsp;H5Eset\_auto2(H5E\_DEFAULT,(H5E\_auto2\_t)print\_msg,(void\*)msg);  
&nbsp;&nbsp;hid\_t fid = H5Fopen("notafile",H5F\_ACC\_RDONLY,H5P\_DEFAULT);  
&nbsp;&nbsp;if(fid\<0){  
&nbsp;&nbsp;&nbsp;&nbsp;printf("you should have seen:\n");  
&nbsp;&nbsp;&nbsp;&nbsp;print\_msg((void\*)msg);  
&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT\_FAILURE);  
&nbsp;&nbsp;}else{  
&nbsp;&nbsp;&nbsp;&nbsp;H5Fclose(fid);  
&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT\_SUCCESS);  
&nbsp;&nbsp;}  
}

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

---

<div class="post-metadata">

**Author:** ![Quincey\_Koziol](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/q/dbc845/32.png) [@Quincey\_Koziol](https://forum.hdfgroup.org/u/Quincey_Koziol)\
**Post date:** [September 8, 2009, 12:50pm UTC](https://forum.hdfgroup.org/t/client-data-with-h5eset-auto2/1424/2 "2009-09-08T12:50:55Z")

</div>

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](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](http://www.hdfgroup.org/HDF5/doc/UG/13_ErrorHandling.html#BasicErrorHandling)

&nbsp;&nbsp;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);

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

&nbsp;&nbsp;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){  
> > &nbsp;&nbsp;&nbsp;printf("you should have seen:\n");  
> > &nbsp;&nbsp;&nbsp;print\_msg((void\*)msg);  
> > &nbsp;&nbsp;&nbsp;exit(EXIT\_FAILURE);  
> > }else{  
> > &nbsp;&nbsp;&nbsp;H5Fclose(fid);  
> > &nbsp;&nbsp;&nbsp;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](http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org)

---

<div class="post-metadata">

**Author:** ![Kevin\_Mitchell](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/k/91b2a8/32.png) [@Kevin\_Mitchell](https://forum.hdfgroup.org/u/Kevin_Mitchell)\
**Post date:** [September 9, 2009, 6:12pm UTC](https://forum.hdfgroup.org/t/client-data-with-h5eset-auto2/1424/3 "2009-09-09T18:12:54Z")

</div>

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](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](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](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](http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org)
