1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /*-------------------------------------------------------------------------
15  *
16  * Created:	H5Edeprec.c
17  *		April 11 2007
18  *		Quincey Koziol <koziol@hdfgroup.org>
19  *
20  * Purpose:	Deprecated functions from the H5E interface.  These
21  *              functions are here for compatibility purposes and may be
22  *              removed in the future.  Applications should switch to the
23  *              newer APIs.
24  *
25  *-------------------------------------------------------------------------
26  */
27 
28 /****************/
29 /* Module Setup */
30 /****************/
31 
32 #include "H5Emodule.h"          /* This source code file is part of the H5E module */
33 
34 
35 /***********/
36 /* Headers */
37 /***********/
38 #include "H5private.h"		/* Generic Functions			*/
39 #include "H5Iprivate.h"		/* IDs                                  */
40 #include "H5Epkg.h"		/* Error handling		  	*/
41 #include "H5FLprivate.h"	/* Free lists                           */
42 #include "H5MMprivate.h"	/* Memory management			*/
43 
44 
45 /****************/
46 /* Local Macros */
47 /****************/
48 
49 
50 /******************/
51 /* Local Typedefs */
52 /******************/
53 
54 
55 /********************/
56 /* Package Typedefs */
57 /********************/
58 
59 
60 /********************/
61 /* Local Prototypes */
62 /********************/
63 
64 
65 /*********************/
66 /* Package Variables */
67 /*********************/
68 
69 
70 /*****************************/
71 /* Library Private Variables */
72 /*****************************/
73 
74 
75 /*******************/
76 /* Local Variables */
77 /*******************/
78 
79 
80 #ifndef H5_NO_DEPRECATED_SYMBOLS
81 
82 /*-------------------------------------------------------------------------
83  * Function:	H5Eget_major
84  *
85  * Purpose:	Retrieves a major error message.
86  *
87  * Return:      Returns message if succeeds.
88  *              otherwise returns NULL.
89  *
90  * Programmer:	Raymond Lu
91  *              Friday, July 14, 2003
92  *
93  *-------------------------------------------------------------------------
94  */
95 char *
H5Eget_major(H5E_major_t maj)96 H5Eget_major(H5E_major_t maj)
97 {
98     H5E_msg_t   *msg;           /* Pointer to error message */
99     ssize_t      size;
100     H5E_type_t  type;
101     char        *msg_str = NULL;
102     char        *ret_value;     /* Return value */
103 
104     FUNC_ENTER_API_NOCLEAR(NULL)
105     H5TRACE1("*s", "i", maj);
106 
107     /* Get the message object */
108     if(NULL == (msg = (H5E_msg_t *)H5I_object_verify(maj, H5I_ERROR_MSG)))
109 	HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a error message ID")
110 
111     /* Get the size & type of the message's text */
112     if((size = H5E_get_msg(msg, &type, NULL, (size_t)0)) < 0)
113 	HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "can't get error message text")
114     if(type != H5E_MAJOR)
115 	HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "Error message isn't a major one")
116 
117     /* Application will free this */
118     size++;
119     msg_str = (char *)H5MM_malloc((size_t)size);
120 
121     /* Get the text for the message */
122     if(H5E_get_msg(msg, NULL, msg_str, (size_t)size) < 0)
123 	HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "can't get error message text")
124 
125     ret_value = msg_str;
126 
127 done:
128     if(!ret_value)
129         msg_str = (char *)H5MM_xfree(msg_str);
130 
131     FUNC_LEAVE_API(ret_value)
132 } /* end H5Eget_major() */
133 
134 
135 /*-------------------------------------------------------------------------
136  * Function:	H5Eget_minor
137  *
138  * Purpose:	Retrieves a minor error message.
139  *
140  * Return:      Returns message if succeeds.
141  *              otherwise returns NULL.
142  *
143  * Programmer:	Raymond Lu
144  *              Friday, July 14, 2003
145  *
146  *-------------------------------------------------------------------------
147  */
148 char *
H5Eget_minor(H5E_minor_t min)149 H5Eget_minor(H5E_minor_t min)
150 {
151     H5E_msg_t   *msg;           /* Pointer to error message */
152     ssize_t      size;
153     H5E_type_t  type;
154     char        *msg_str = NULL;
155     char        *ret_value;     /* Return value */
156 
157     FUNC_ENTER_API_NOCLEAR(NULL)
158     H5TRACE1("*s", "i", min);
159 
160     /* Get the message object */
161     if(NULL == (msg = (H5E_msg_t *)H5I_object_verify(min, H5I_ERROR_MSG)))
162 	HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a error message ID")
163 
164     /* Get the size & type of the message's text */
165     if((size = H5E_get_msg(msg, &type, NULL, (size_t)0)) < 0)
166 	HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "can't get error message text")
167     if(type != H5E_MINOR)
168 	HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "Error message isn't a minor one")
169 
170     /* Application will free this */
171     size++;
172     msg_str = (char *)H5MM_malloc((size_t)size);
173 
174     /* Get the text for the message */
175     if(H5E_get_msg(msg, NULL, msg_str, (size_t)size) < 0)
176 	HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "can't get error message text")
177 
178     ret_value = msg_str;
179 
180 done:
181     if(!ret_value)
182         msg_str = (char *)H5MM_xfree(msg_str);
183 
184     FUNC_LEAVE_API(ret_value)
185 } /* end H5Eget_minor() */
186 
187 
188 /*-------------------------------------------------------------------------
189  * Function:	H5Epush1
190  *
191  * Purpose:	This function definition is for backward compatibility only.
192  *              It doesn't have error stack and error class as parameters.
193  *              The old definition of major and minor is casted as HID_T
194  *              in H5Epublic.h
195  *
196  * Notes: 	Basically a public API wrapper around the H5E_push2
197  *              function.  For backward compatibility, it maintains the
198  *              same parameter as the old function, in contrary to
199  *              H5Epush2.
200  *
201  * Return:	Non-negative on success/Negative on failure
202  *
203  * Programmer:	Raymond Lu
204  *		Tuesday, Sep 16, 2003
205  *
206  *-------------------------------------------------------------------------
207  */
208 herr_t
H5Epush1(const char * file,const char * func,unsigned line,H5E_major_t maj,H5E_minor_t min,const char * str)209 H5Epush1(const char *file, const char *func, unsigned line,
210         H5E_major_t maj, H5E_minor_t min, const char *str)
211 {
212     herr_t	ret_value = SUCCEED;    /* Return value */
213 
214     /* Don't clear the error stack! :-) */
215     FUNC_ENTER_API_NOCLEAR(FAIL)
216     H5TRACE6("e", "*s*sIuii*s", file, func, line, maj, min, str);
217 
218     /* Push the error on the default error stack */
219     if(H5E__push_stack(NULL, file, func, line, H5E_ERR_CLS_g, maj, min, str) < 0)
220         HGOTO_ERROR(H5E_ERROR, H5E_CANTSET, FAIL, "can't push error on stack")
221 
222 done:
223     FUNC_LEAVE_API(ret_value)
224 } /* end H5Epush1() */
225 
226 
227 /*-------------------------------------------------------------------------
228  * Function:	H5Eclear1
229  *
230  * Purpose:	This function is for backward compatibility.
231  *              Clears the error stack for the specified error stack.
232  *
233  * Return:	Non-negative on success/Negative on failure
234  *
235  * Programmer:	Raymond Lu
236  *              Wednesday, July 16, 2003
237  *
238  *-------------------------------------------------------------------------
239  */
240 herr_t
H5Eclear1(void)241 H5Eclear1(void)
242 {
243     herr_t ret_value = SUCCEED; /* Return value */
244 
245     /* Don't clear the error stack! :-) */
246     FUNC_ENTER_API_NOCLEAR(FAIL)
247     H5TRACE0("e","");
248 
249     /* Clear the default error stack */
250     if(H5E_clear_stack(NULL) < 0)
251         HGOTO_ERROR(H5E_ERROR, H5E_CANTSET, FAIL, "can't clear error stack")
252 
253 done:
254     FUNC_LEAVE_API(ret_value)
255 } /* end H5Eclear1() */
256 
257 
258 /*-------------------------------------------------------------------------
259  * Function:	H5Eprint1
260  *
261  * Purpose:	This function is for backward compatibility.
262  *              Prints the error stack in some default way.  This is just a
263  *		convenience function for H5Ewalk() with a function that
264  *		prints error messages.  Users are encouraged to write there
265  *		own more specific error handlers.
266  *
267  * Return:	Non-negative on success/Negative on failure
268  *
269  * Programmer:	Raymond Lu
270  *              Sep 16, 2003
271  *
272  *-------------------------------------------------------------------------
273  */
274 herr_t
H5Eprint1(FILE * stream)275 H5Eprint1(FILE *stream)
276 {
277     H5E_t   *estack;            /* Error stack to operate on */
278     herr_t ret_value = SUCCEED; /* Return value */
279 
280     /* Don't clear the error stack! :-) */
281     FUNC_ENTER_API_NOCLEAR(FAIL)
282     /*NO TRACE*/
283 
284     if(NULL == (estack = H5E_get_my_stack())) /*lint !e506 !e774 Make lint 'constant value Boolean' in non-threaded case */
285         HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "can't get current error stack")
286 
287     /* Print error stack */
288     if(H5E_print(estack, stream, TRUE) < 0)
289         HGOTO_ERROR(H5E_ERROR, H5E_CANTLIST, FAIL, "can't display error stack")
290 
291 done:
292     FUNC_LEAVE_API(ret_value)
293 } /* end H5Eprint1() */
294 
295 
296 /*-------------------------------------------------------------------------
297  * Function:	H5Ewalk1
298  *
299  * Purpose:	This function is for backward compatibility.
300  *              Walks the error stack for the current thread and calls some
301  *		function for each error along the way.
302  *
303  * Return:	Non-negative on success/Negative on failure
304  *
305  * Programmer:	Raymond Lu
306  *              Sep 16, 2003
307  *
308  *-------------------------------------------------------------------------
309  */
310 herr_t
H5Ewalk1(H5E_direction_t direction,H5E_walk1_t func,void * client_data)311 H5Ewalk1(H5E_direction_t direction, H5E_walk1_t func, void *client_data)
312 {
313     H5E_t   *estack;            /* Error stack to operate on */
314     H5E_walk_op_t walk_op;      /* Error stack walking callback */
315     herr_t ret_value = SUCCEED; /* Return value */
316 
317     /* Don't clear the error stack! :-) */
318     FUNC_ENTER_API_NOCLEAR(FAIL)
319     /*NO TRACE*/
320 
321     if(NULL == (estack = H5E_get_my_stack())) /*lint !e506 !e774 Make lint 'constant value Boolean' in non-threaded case */
322         HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "can't get current error stack")
323 
324     /* Walk the error stack */
325     walk_op.vers = 1;
326     walk_op.u.func1 = func;
327     if(H5E_walk(estack, direction, &walk_op, client_data) < 0)
328         HGOTO_ERROR(H5E_ERROR, H5E_CANTLIST, FAIL, "can't walk error stack")
329 
330 done:
331     FUNC_LEAVE_API(ret_value)
332 } /* end H5Ewalk1() */
333 
334 
335 /*-------------------------------------------------------------------------
336  * Function:	H5Eget_auto1
337  *
338  * Purpose:	This function is for backward compatibility.
339  *              Returns the current settings for the automatic error stack
340  *		traversal function and its data for specific error stack.
341  *		Either (or both) arguments may be null in which case the
342  *		value is not returned.
343  *
344  * Return:	Non-negative on success/Negative on failure
345  *
346  * Programmer:	Raymond Lu
347  *              Sep 16, 2003
348  *
349  * Modification:Raymond Lu
350  *              4 October 2010
351  *              If the printing function isn't the default H5Eprint1 or 2,
352  *              and H5Eset_auto2 has been called to set the new style
353  *              printing function, a call to H5Eget_auto1 should fail.
354  *-------------------------------------------------------------------------
355  */
356 herr_t
H5Eget_auto1(H5E_auto1_t * func,void ** client_data)357 H5Eget_auto1(H5E_auto1_t *func, void **client_data)
358 {
359     H5E_t   *estack;            /* Error stack to operate on */
360     H5E_auto_op_t auto_op;      /* Error stack operator */
361     herr_t ret_value = SUCCEED;   /* Return value */
362 
363     FUNC_ENTER_API(FAIL)
364     H5TRACE2("e", "*x**x", func, client_data);
365 
366     /* Retrieve default error stack */
367     if(NULL == (estack = H5E_get_my_stack())) /*lint !e506 !e774 Make lint 'constant value Boolean' in non-threaded case */
368         HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "can't get current error stack")
369 
370     /* Get the automatic error reporting information */
371     if(H5E_get_auto(estack, &auto_op, client_data) < 0)
372         HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "can't get automatic error info")
373 
374     /* Fail if the printing function isn't the default(user-set) and set through H5Eset_auto2 */
375     if(!auto_op.is_default && auto_op.vers == 2)
376         HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "wrong API function, H5Eset_auto2 has been called")
377 
378     if(func)
379         *func = auto_op.func1;
380 
381 done:
382     FUNC_LEAVE_API(ret_value)
383 } /* end H5Eget_auto1() */
384 
385 
386 /*-------------------------------------------------------------------------
387  * Function:	H5Eset_auto1
388  *
389  * Purpose:	This function is for backward compatibility.
390  *              Turns on or off automatic printing of errors for certain
391  *              error stack.  When turned on (non-null FUNC pointer) any
392  *              API function which returns an error indication will first
393  *              call FUNC passing it CLIENT_DATA as an argument.
394  *
395  *		The default values before this function is called are
396  *		H5Eprint1() with client data being the standard error stream,
397  *		stderr.
398  *
399  *		Automatic stack traversal is always in the H5E_WALK_DOWNWARD
400  *		direction.
401  *
402  * Return:	Non-negative on success/Negative on failure
403  *
404  * Programmer:	Raymond Lu
405  *              Sep 16, 2003
406  *
407  * Modification:Raymond Lu
408  *              4 October 2010
409  *              If the FUNC is H5Eprint2, put the IS_DEFAULT flag on.
410  *-------------------------------------------------------------------------
411  */
412 herr_t
H5Eset_auto1(H5E_auto1_t func,void * client_data)413 H5Eset_auto1(H5E_auto1_t func, void *client_data)
414 {
415     H5E_t   *estack;            /* Error stack to operate on */
416     H5E_auto_op_t auto_op;      /* Error stack operator */
417     herr_t ret_value = SUCCEED; /* Return value */
418 
419     /* Don't clear the error stack! :-) */
420     FUNC_ENTER_API_NOCLEAR(FAIL)
421     H5TRACE2("e", "x*x", func, client_data);
422 
423     if(NULL == (estack = H5E_get_my_stack())) /*lint !e506 !e774 Make lint 'constant value Boolean' in non-threaded case */
424         HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "can't get current error stack")
425 
426     /* Get the automatic error reporting information */
427     if(H5E_get_auto(estack, &auto_op, NULL) < 0)
428         HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, FAIL, "can't get automatic error info")
429 
430     /* Set the automatic error reporting information */
431     auto_op.vers = 1;
432     if(func != auto_op.func1_default)
433         auto_op.is_default = FALSE;
434     else
435         auto_op.is_default = TRUE;
436     auto_op.func1 = func;
437 
438     if(H5E_set_auto(estack, &auto_op, client_data) < 0)
439         HGOTO_ERROR(H5E_ERROR, H5E_CANTSET, FAIL, "can't set automatic error info")
440 
441 done:
442     FUNC_LEAVE_API(ret_value)
443 } /* end H5Eset_auto1() */
444 #endif /* H5_NO_DEPRECATED_SYMBOLS */
445 
446