Coverage Report

Created: 2025-11-09 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hdf5/src/H5HLprfx.c
Line
Count
Source
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:     H5HLprfx.c
16
 *
17
 * Purpose:     Prefix routines for local heaps.
18
 *
19
 *-------------------------------------------------------------------------
20
 */
21
22
/****************/
23
/* Module Setup */
24
/****************/
25
26
#include "H5HLmodule.h" /* This source code file is part of the H5HL module */
27
28
/***********/
29
/* Headers */
30
/***********/
31
#include "H5private.h"   /* Generic Functions            */
32
#include "H5Eprivate.h"  /* Error handling               */
33
#include "H5FLprivate.h" /* Free lists                   */
34
#include "H5HLpkg.h"     /* Local Heaps                  */
35
36
/****************/
37
/* Local Macros */
38
/****************/
39
40
/******************/
41
/* Local Typedefs */
42
/******************/
43
44
/********************/
45
/* Package Typedefs */
46
/********************/
47
48
/********************/
49
/* Local Prototypes */
50
/********************/
51
52
/*********************/
53
/* Package Variables */
54
/*********************/
55
56
/*****************************/
57
/* Library Private Variables */
58
/*****************************/
59
60
/*******************/
61
/* Local Variables */
62
/*******************/
63
64
/* Declare a free list to manage the H5HL_prfx_t struct */
65
H5FL_DEFINE_STATIC(H5HL_prfx_t);
66
67
/*-------------------------------------------------------------------------
68
 * Function:    H5HL__prfx_new
69
 *
70
 * Purpose:     Create a new local heap prefix object
71
 *
72
 * Return:      Success:    non-NULL pointer to new local heap prefix
73
 *              Failure:    NULL
74
 *
75
 *-------------------------------------------------------------------------
76
 */
77
H5HL_prfx_t *
78
H5HL__prfx_new(H5HL_t *heap)
79
0
{
80
0
    H5HL_prfx_t *prfx      = NULL; /* New local heap prefix */
81
0
    H5HL_prfx_t *ret_value = NULL;
82
83
0
    FUNC_ENTER_PACKAGE
84
85
    /* check arguments */
86
0
    assert(heap);
87
88
    /* Allocate new local heap prefix */
89
0
    if (NULL == (prfx = H5FL_CALLOC(H5HL_prfx_t)))
90
0
        HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, NULL, "memory allocation failed for local heap prefix");
91
92
    /* Increment ref. count on heap data structure */
93
0
    if (FAIL == H5HL__inc_rc(heap))
94
0
        HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, NULL, "can't increment heap ref. count");
95
96
    /* Link the heap & the prefix */
97
0
    prfx->heap = heap;
98
0
    heap->prfx = prfx;
99
100
    /* Set the return value */
101
0
    ret_value = prfx;
102
103
0
done:
104
    /* Ensure that the prefix memory is deallocated on errors */
105
0
    if (!ret_value && prfx != NULL)
106
        /* H5FL_FREE always returns NULL so we can't check for errors */
107
0
        prfx = H5FL_FREE(H5HL_prfx_t, prfx);
108
109
0
    FUNC_LEAVE_NOAPI(ret_value)
110
0
} /* end H5HL__prfx_new() */
111
112
/*-------------------------------------------------------------------------
113
 * Function:    H5HL__prfx_dest
114
 *
115
 * Purpose:     Destroy a local heap prefix object
116
 *
117
 * Return:      SUCCEED/FAIL
118
 *
119
 *-------------------------------------------------------------------------
120
 */
121
herr_t
122
H5HL__prfx_dest(H5HL_prfx_t *prfx)
123
0
{
124
0
    herr_t ret_value = SUCCEED;
125
126
0
    FUNC_ENTER_PACKAGE
127
128
    /* check arguments */
129
0
    assert(prfx);
130
131
    /* Check if prefix was initialized */
132
0
    if (prfx->heap) {
133
        /* Unlink prefix from heap */
134
0
        prfx->heap->prfx = NULL;
135
136
        /* Decrement ref. count on heap data structure */
137
0
        if (FAIL == H5HL__dec_rc(prfx->heap))
138
0
            HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't decrement heap ref. count");
139
140
        /* Unlink heap from prefix */
141
0
        prfx->heap = NULL;
142
0
    }
143
144
0
done:
145
    /* Free prefix memory */
146
    /* H5FL_FREE always returns NULL so we can't check for errors */
147
0
    prfx = H5FL_FREE(H5HL_prfx_t, prfx);
148
149
0
    FUNC_LEAVE_NOAPI(ret_value)
150
0
} /* end H5HL__prfx_dest() */