Coverage Report

Created: 2025-08-26 06:30

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