Coverage Report

Created: 2024-06-18 06:29

/src/hdf5/src/H5SMbtree2.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 COPYING 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
/* Module Setup */
15
/****************/
16
17
#define H5O_FRIEND      /*suppress error about including H5Opkg   */
18
#include "H5SMmodule.h" /* This source code file is part of the H5SM module */
19
20
/***********/
21
/* Headers */
22
/***********/
23
#include "H5private.h"   /* Generic Functions     */
24
#include "H5Eprivate.h"  /* Error handling        */
25
#include "H5FLprivate.h" /* Free Lists                               */
26
#include "H5Opkg.h"      /* Object Headers                       */
27
#include "H5SMpkg.h"     /* Shared object header messages        */
28
29
/****************/
30
/* Local Macros */
31
/****************/
32
33
/******************/
34
/* Local Typedefs */
35
/******************/
36
37
/********************/
38
/* Local Prototypes */
39
/********************/
40
41
/* v2 B-tree callbacks */
42
static void  *H5SM__bt2_crt_context(void *udata);
43
static herr_t H5SM__bt2_dst_context(void *ctx);
44
static herr_t H5SM__bt2_store(void *native, const void *udata);
45
static herr_t H5SM__bt2_debug(FILE *stream, int indent, int fwidth, const void *record, const void *_udata);
46
47
/*****************************/
48
/* Library Private Variables */
49
/*****************************/
50
/* v2 B-tree class for SOHM indexes*/
51
const H5B2_class_t H5SM_INDEX[1] = {{
52
    /* B-tree class information */
53
    H5B2_SOHM_INDEX_ID,    /* Type of B-tree */
54
    "H5B2_SOHM_INDEX_ID",  /* Name of B-tree class */
55
    sizeof(H5SM_sohm_t),   /* Size of native record */
56
    H5SM__bt2_crt_context, /* Create client callback context */
57
    H5SM__bt2_dst_context, /* Destroy client callback context */
58
    H5SM__bt2_store,       /* Record storage callback */
59
    H5SM__message_compare, /* Record comparison callback */
60
    H5SM__message_encode,  /* Record encoding callback */
61
    H5SM__message_decode,  /* Record decoding callback */
62
    H5SM__bt2_debug        /* Record debugging callback */
63
}};
64
65
/*******************/
66
/* Local Variables */
67
/*******************/
68
69
/* Declare a free list to manage the H5SM_bt2_ctx_t struct */
70
H5FL_DEFINE_STATIC(H5SM_bt2_ctx_t);
71
72
/*-------------------------------------------------------------------------
73
 * Function:  H5SM__bt2_crt_context
74
 *
75
 * Purpose: Create client callback context
76
 *
77
 * Return:  Success:  non-NULL
78
 *    Failure:  NULL
79
 *
80
 *-------------------------------------------------------------------------
81
 */
82
static void *
83
H5SM__bt2_crt_context(void *_f)
84
0
{
85
0
    H5F_t          *f = (H5F_t *)_f;  /* User data for building callback context */
86
0
    H5SM_bt2_ctx_t *ctx;              /* Callback context structure */
87
0
    void           *ret_value = NULL; /* Return value */
88
89
0
    FUNC_ENTER_PACKAGE
90
91
    /* Sanity check */
92
0
    assert(f);
93
94
    /* Allocate callback context */
95
0
    if (NULL == (ctx = H5FL_MALLOC(H5SM_bt2_ctx_t)))
96
0
        HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, NULL, "can't allocate callback context");
97
98
    /* Determine the size of addresses & lengths in the file */
99
0
    ctx->sizeof_addr = H5F_SIZEOF_ADDR(f);
100
101
    /* Set return value */
102
0
    ret_value = ctx;
103
104
0
done:
105
0
    FUNC_LEAVE_NOAPI(ret_value)
106
0
} /* H5SM__bt2_crt_context() */
107
108
/*-------------------------------------------------------------------------
109
 * Function:  H5SM__bt2_dst_context
110
 *
111
 * Purpose: Destroy client callback context
112
 *
113
 * Return:  Success:  non-negative
114
 *    Failure:  negative
115
 *
116
 *-------------------------------------------------------------------------
117
 */
118
static herr_t
119
H5SM__bt2_dst_context(void *_ctx)
120
0
{
121
0
    H5SM_bt2_ctx_t *ctx = (H5SM_bt2_ctx_t *)_ctx; /* Callback context structure */
122
123
0
    FUNC_ENTER_PACKAGE_NOERR
124
125
    /* Sanity check */
126
0
    assert(ctx);
127
128
    /* Release callback context */
129
0
    ctx = H5FL_FREE(H5SM_bt2_ctx_t, ctx);
130
131
0
    FUNC_LEAVE_NOAPI(SUCCEED)
132
0
} /* H5SM__bt2_dst_context() */
133
134
/*-------------------------------------------------------------------------
135
 * Function:  H5SM__bt2_store
136
 *
137
 * Purpose: Store a H5SM_sohm_t SOHM message in the B-tree.  The message
138
 *              comes in UDATA as a H5SM_mesg_key_t* and is copied to
139
 *              NATIVE as a H5SM_sohm_t.
140
 *
141
 * Return:  Non-negative on success
142
 *              Negative on failure
143
 *
144
 *-------------------------------------------------------------------------
145
 */
146
static herr_t
147
H5SM__bt2_store(void *native, const void *udata)
148
0
{
149
0
    const H5SM_mesg_key_t *key = (const H5SM_mesg_key_t *)udata;
150
151
0
    FUNC_ENTER_PACKAGE_NOERR
152
153
    /* Copy the source message to the B-tree */
154
0
    *(H5SM_sohm_t *)native = key->message;
155
156
0
    FUNC_LEAVE_NOAPI(SUCCEED)
157
0
} /* end H5SM__bt2_store */
158
159
/*-------------------------------------------------------------------------
160
 * Function:  H5SM__bt2_debug
161
 *
162
 * Purpose: Print debugging information for a H5SM_sohm_t.
163
 *
164
 * Return:  Non-negative on success
165
 *              Negative on failure
166
 *
167
 *-------------------------------------------------------------------------
168
 */
169
static herr_t
170
H5SM__bt2_debug(FILE *stream, int indent, int fwidth, const void *record, const void H5_ATTR_UNUSED *_udata)
171
0
{
172
0
    const H5SM_sohm_t *sohm = (const H5SM_sohm_t *)record;
173
174
0
    FUNC_ENTER_PACKAGE_NOERR
175
176
0
    if (sohm->location == H5SM_IN_HEAP)
177
0
        fprintf(stream, "%*s%-*s {%" PRIu64 ", %" PRIo32 ", %" PRIxHSIZE "}\n", indent, "", fwidth,
178
0
                "Shared Message in heap:", sohm->u.heap_loc.fheap_id.val, sohm->hash,
179
0
                sohm->u.heap_loc.ref_count);
180
0
    else {
181
0
        assert(sohm->location == H5SM_IN_OH);
182
0
        fprintf(stream, "%*s%-*s {%" PRIuHADDR ", %" PRIo32 ", %x, %" PRIx32 "}\n", indent, "", fwidth,
183
0
                "Shared Message in OH:", sohm->u.mesg_loc.oh_addr, sohm->hash, sohm->msg_type_id,
184
0
                sohm->u.mesg_loc.index);
185
0
    } /* end else */
186
187
0
    FUNC_LEAVE_NOAPI(SUCCEED)
188
0
} /* end H5SM__bt2_debug */